@withbuddi/buddi 0.1.0-pre.35 → 0.1.0-pre.36

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 (414) hide show
  1. package/extension/manifest.json +2 -2
  2. package/node_modules/@buddi/cli/dist/.tsbuildinfo +1 -1
  3. package/node_modules/@buddi/cli/dist/doctor-probes.d.ts.map +1 -1
  4. package/node_modules/@buddi/cli/dist/doctor-probes.js +8 -2
  5. package/node_modules/@buddi/cli/dist/doctor-probes.js.map +1 -1
  6. package/node_modules/@buddi/cli/dist/doctor.d.ts +12 -0
  7. package/node_modules/@buddi/cli/dist/doctor.d.ts.map +1 -1
  8. package/node_modules/@buddi/cli/dist/doctor.js +9 -0
  9. package/node_modules/@buddi/cli/dist/doctor.js.map +1 -1
  10. package/node_modules/@buddi/core/dist/.tsbuildinfo +1 -1
  11. package/node_modules/@buddi/core/dist/host/build.d.ts +14 -0
  12. package/node_modules/@buddi/core/dist/host/build.d.ts.map +1 -1
  13. package/node_modules/@buddi/core/dist/host/build.js +55 -5
  14. package/node_modules/@buddi/core/dist/host/build.js.map +1 -1
  15. package/node_modules/@buddi/core/dist/host/http.d.ts +62 -0
  16. package/node_modules/@buddi/core/dist/host/http.d.ts.map +1 -1
  17. package/node_modules/@buddi/core/dist/host/http.js +193 -2
  18. package/node_modules/@buddi/core/dist/host/http.js.map +1 -1
  19. package/node_modules/@buddi/core/dist/host/types.d.ts +43 -4
  20. package/node_modules/@buddi/core/dist/host/types.d.ts.map +1 -1
  21. package/node_modules/@buddi/core/dist/index.d.ts +1 -0
  22. package/node_modules/@buddi/core/dist/index.d.ts.map +1 -1
  23. package/node_modules/@buddi/core/dist/index.js +1 -0
  24. package/node_modules/@buddi/core/dist/index.js.map +1 -1
  25. package/node_modules/@buddi/core/dist/notifications/notify.d.ts.map +1 -1
  26. package/node_modules/@buddi/core/dist/notifications/notify.js +10 -6
  27. package/node_modules/@buddi/core/dist/notifications/notify.js.map +1 -1
  28. package/node_modules/@buddi/core/dist/notifications/store.d.ts.map +1 -1
  29. package/node_modules/@buddi/core/dist/notifications/store.js +2 -1
  30. package/node_modules/@buddi/core/dist/notifications/store.js.map +1 -1
  31. package/node_modules/@buddi/core/dist/notifications/types.d.ts +8 -0
  32. package/node_modules/@buddi/core/dist/notifications/types.d.ts.map +1 -1
  33. package/node_modules/@buddi/core/dist/notifications/types.js.map +1 -1
  34. package/node_modules/@buddi/core/dist/pages.d.ts +308 -13
  35. package/node_modules/@buddi/core/dist/pages.d.ts.map +1 -1
  36. package/node_modules/@buddi/core/dist/pages.js +111 -4
  37. package/node_modules/@buddi/core/dist/pages.js.map +1 -1
  38. package/node_modules/@buddi/core/dist/plugin/assets.d.ts +52 -0
  39. package/node_modules/@buddi/core/dist/plugin/assets.d.ts.map +1 -0
  40. package/node_modules/@buddi/core/dist/plugin/assets.js +59 -0
  41. package/node_modules/@buddi/core/dist/plugin/assets.js.map +1 -0
  42. package/node_modules/@buddi/core/dist/plugin/index.d.ts +6 -4
  43. package/node_modules/@buddi/core/dist/plugin/index.d.ts.map +1 -1
  44. package/node_modules/@buddi/core/dist/plugin/index.js +2 -1
  45. package/node_modules/@buddi/core/dist/plugin/index.js.map +1 -1
  46. package/node_modules/@buddi/core/dist/plugin/requires.d.ts +3 -1
  47. package/node_modules/@buddi/core/dist/plugin/requires.d.ts.map +1 -1
  48. package/node_modules/@buddi/core/dist/plugin/requires.js +5 -3
  49. package/node_modules/@buddi/core/dist/plugin/requires.js.map +1 -1
  50. package/node_modules/@buddi/core/dist/plugin/uses.d.ts +1 -1
  51. package/node_modules/@buddi/core/dist/plugin/uses.d.ts.map +1 -1
  52. package/node_modules/@buddi/core/dist/plugin/uses.js +2 -0
  53. package/node_modules/@buddi/core/dist/plugin/uses.js.map +1 -1
  54. package/node_modules/@buddi/core/dist/plugin/version.d.ts +1 -1
  55. package/node_modules/@buddi/core/dist/plugin/version.js +1 -1
  56. package/node_modules/@buddi/core/dist/plugin-assets.d.ts +21 -0
  57. package/node_modules/@buddi/core/dist/plugin-assets.d.ts.map +1 -0
  58. package/node_modules/@buddi/core/dist/plugin-assets.js +140 -0
  59. package/node_modules/@buddi/core/dist/plugin-assets.js.map +1 -0
  60. package/node_modules/@buddi/core/dist/registry.d.ts +9 -0
  61. package/node_modules/@buddi/core/dist/registry.d.ts.map +1 -1
  62. package/node_modules/@buddi/core/dist/registry.js +33 -2
  63. package/node_modules/@buddi/core/dist/registry.js.map +1 -1
  64. package/node_modules/@buddi/core/dist/scheduler/missions.d.ts +14 -0
  65. package/node_modules/@buddi/core/dist/scheduler/missions.d.ts.map +1 -1
  66. package/node_modules/@buddi/core/dist/scheduler/missions.js +17 -4
  67. package/node_modules/@buddi/core/dist/scheduler/missions.js.map +1 -1
  68. package/node_modules/@buddi/core/dist/scheduler/types.d.ts +13 -0
  69. package/node_modules/@buddi/core/dist/scheduler/types.d.ts.map +1 -1
  70. package/node_modules/@buddi/core/dist/scheduler/types.js +14 -0
  71. package/node_modules/@buddi/core/dist/scheduler/types.js.map +1 -1
  72. package/node_modules/@buddi/core/dist/surfaces.d.ts +10 -0
  73. package/node_modules/@buddi/core/dist/surfaces.d.ts.map +1 -1
  74. package/node_modules/@buddi/core/dist/surfaces.js +11 -0
  75. package/node_modules/@buddi/core/dist/surfaces.js.map +1 -1
  76. package/node_modules/@buddi/core/dist/tools.d.ts +43 -1
  77. package/node_modules/@buddi/core/dist/tools.d.ts.map +1 -1
  78. package/node_modules/@buddi/core/dist/tools.js +38 -0
  79. package/node_modules/@buddi/core/dist/tools.js.map +1 -1
  80. package/node_modules/@buddi/core/dist/views.d.ts +17 -0
  81. package/node_modules/@buddi/core/dist/views.d.ts.map +1 -1
  82. package/node_modules/@buddi/core/dist/views.js +1 -0
  83. package/node_modules/@buddi/core/dist/views.js.map +1 -1
  84. package/node_modules/@buddi/core/dist/widget-settings.d.ts +2 -1
  85. package/node_modules/@buddi/core/dist/widget-settings.d.ts.map +1 -1
  86. package/node_modules/@buddi/core/dist/widget-settings.js +8 -2
  87. package/node_modules/@buddi/core/dist/widget-settings.js.map +1 -1
  88. package/node_modules/@buddi/core/dist/widgets.d.ts +32 -2
  89. package/node_modules/@buddi/core/dist/widgets.d.ts.map +1 -1
  90. package/node_modules/@buddi/core/dist/widgets.js +38 -5
  91. package/node_modules/@buddi/core/dist/widgets.js.map +1 -1
  92. package/node_modules/@buddi/core/migrations/073_mission_report.sql +15 -0
  93. package/node_modules/@buddi/gateway/dist/.tsbuildinfo +1 -1
  94. package/node_modules/@buddi/gateway/dist/agents/catalogue-package.d.ts +68 -0
  95. package/node_modules/@buddi/gateway/dist/agents/catalogue-package.d.ts.map +1 -1
  96. package/node_modules/@buddi/gateway/dist/agents/catalogue-package.js +18 -1
  97. package/node_modules/@buddi/gateway/dist/agents/catalogue-package.js.map +1 -1
  98. package/node_modules/@buddi/gateway/dist/agents/owner-text.d.ts +19 -0
  99. package/node_modules/@buddi/gateway/dist/agents/owner-text.d.ts.map +1 -0
  100. package/node_modules/@buddi/gateway/dist/agents/owner-text.js +44 -0
  101. package/node_modules/@buddi/gateway/dist/agents/owner-text.js.map +1 -0
  102. package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.d.ts +49 -3
  103. package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.d.ts.map +1 -1
  104. package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.js +156 -32
  105. package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.js.map +1 -1
  106. package/node_modules/@buddi/gateway/dist/agents/platform.d.ts +7 -0
  107. package/node_modules/@buddi/gateway/dist/agents/platform.d.ts.map +1 -1
  108. package/node_modules/@buddi/gateway/dist/agents/platform.js +4 -0
  109. package/node_modules/@buddi/gateway/dist/agents/platform.js.map +1 -1
  110. package/node_modules/@buddi/gateway/dist/bootstrap.d.ts.map +1 -1
  111. package/node_modules/@buddi/gateway/dist/bootstrap.js +3 -0
  112. package/node_modules/@buddi/gateway/dist/bootstrap.js.map +1 -1
  113. package/node_modules/@buddi/gateway/dist/index.d.ts +1 -1
  114. package/node_modules/@buddi/gateway/dist/index.d.ts.map +1 -1
  115. package/node_modules/@buddi/gateway/dist/index.js +1 -1
  116. package/node_modules/@buddi/gateway/dist/index.js.map +1 -1
  117. package/node_modules/@buddi/gateway/dist/missions/agent-run.d.ts.map +1 -1
  118. package/node_modules/@buddi/gateway/dist/missions/agent-run.js +2 -0
  119. package/node_modules/@buddi/gateway/dist/missions/agent-run.js.map +1 -1
  120. package/node_modules/@buddi/gateway/dist/missions/defaults.d.ts.map +1 -1
  121. package/node_modules/@buddi/gateway/dist/missions/defaults.js +2 -0
  122. package/node_modules/@buddi/gateway/dist/missions/defaults.js.map +1 -1
  123. package/node_modules/@buddi/gateway/dist/missions/execute.d.ts +17 -1
  124. package/node_modules/@buddi/gateway/dist/missions/execute.d.ts.map +1 -1
  125. package/node_modules/@buddi/gateway/dist/missions/execute.js +64 -7
  126. package/node_modules/@buddi/gateway/dist/missions/execute.js.map +1 -1
  127. package/node_modules/@buddi/gateway/dist/missions/report.d.ts +25 -2
  128. package/node_modules/@buddi/gateway/dist/missions/report.d.ts.map +1 -1
  129. package/node_modules/@buddi/gateway/dist/missions/report.js +70 -11
  130. package/node_modules/@buddi/gateway/dist/missions/report.js.map +1 -1
  131. package/node_modules/@buddi/gateway/dist/owner-notify.d.ts.map +1 -1
  132. package/node_modules/@buddi/gateway/dist/owner-notify.js +7 -3
  133. package/node_modules/@buddi/gateway/dist/owner-notify.js.map +1 -1
  134. package/node_modules/@buddi/gateway/dist/plugins/asset-image-worker.d.ts +2 -0
  135. package/node_modules/@buddi/gateway/dist/plugins/asset-image-worker.d.ts.map +1 -0
  136. package/node_modules/@buddi/gateway/dist/plugins/asset-image-worker.js +18 -0
  137. package/node_modules/@buddi/gateway/dist/plugins/asset-image-worker.js.map +1 -0
  138. package/node_modules/@buddi/gateway/dist/plugins/asset-image.d.ts +31 -0
  139. package/node_modules/@buddi/gateway/dist/plugins/asset-image.d.ts.map +1 -0
  140. package/node_modules/@buddi/gateway/dist/plugins/asset-image.js +332 -0
  141. package/node_modules/@buddi/gateway/dist/plugins/asset-image.js.map +1 -0
  142. package/node_modules/@buddi/gateway/dist/plugins/load.d.ts.map +1 -1
  143. package/node_modules/@buddi/gateway/dist/plugins/load.js +14 -1
  144. package/node_modules/@buddi/gateway/dist/plugins/load.js.map +1 -1
  145. package/node_modules/@buddi/gateway/dist/plugins/stage.d.ts +6 -0
  146. package/node_modules/@buddi/gateway/dist/plugins/stage.d.ts.map +1 -1
  147. package/node_modules/@buddi/gateway/dist/plugins/stage.js +5 -0
  148. package/node_modules/@buddi/gateway/dist/plugins/stage.js.map +1 -1
  149. package/node_modules/@buddi/gateway/dist/plugins/uninstall.d.ts.map +1 -1
  150. package/node_modules/@buddi/gateway/dist/plugins/uninstall.js +8 -0
  151. package/node_modules/@buddi/gateway/dist/plugins/uninstall.js.map +1 -1
  152. package/node_modules/@buddi/gateway/dist/telegram/channel.d.ts +12 -0
  153. package/node_modules/@buddi/gateway/dist/telegram/channel.d.ts.map +1 -1
  154. package/node_modules/@buddi/gateway/dist/telegram/channel.js +43 -1
  155. package/node_modules/@buddi/gateway/dist/telegram/channel.js.map +1 -1
  156. package/node_modules/@buddi/gateway/dist/web/api-routes.d.ts.map +1 -1
  157. package/node_modules/@buddi/gateway/dist/web/api-routes.js +8 -2
  158. package/node_modules/@buddi/gateway/dist/web/api-routes.js.map +1 -1
  159. package/node_modules/@buddi/gateway/dist/web/catalogue.d.ts.map +1 -1
  160. package/node_modules/@buddi/gateway/dist/web/catalogue.js +7 -4
  161. package/node_modules/@buddi/gateway/dist/web/catalogue.js.map +1 -1
  162. package/node_modules/@buddi/gateway/dist/web/extension.d.ts +12 -0
  163. package/node_modules/@buddi/gateway/dist/web/extension.d.ts.map +1 -1
  164. package/node_modules/@buddi/gateway/dist/web/extension.js +11 -1
  165. package/node_modules/@buddi/gateway/dist/web/extension.js.map +1 -1
  166. package/node_modules/@buddi/gateway/dist/web/lock.d.ts +6 -0
  167. package/node_modules/@buddi/gateway/dist/web/lock.d.ts.map +1 -1
  168. package/node_modules/@buddi/gateway/dist/web/lock.js +33 -2
  169. package/node_modules/@buddi/gateway/dist/web/lock.js.map +1 -1
  170. package/node_modules/@buddi/gateway/dist/web/server.d.ts.map +1 -1
  171. package/node_modules/@buddi/gateway/dist/web/server.js +34 -2
  172. package/node_modules/@buddi/gateway/dist/web/server.js.map +1 -1
  173. package/node_modules/@buddi/gateway/dist/web/widgets.js +2 -2
  174. package/node_modules/@buddi/gateway/dist/web/widgets.js.map +1 -1
  175. package/node_modules/@buddi/install/dist/.tsbuildinfo +1 -1
  176. package/node_modules/@buddi/runtime/dist/.tsbuildinfo +1 -1
  177. package/node_modules/@buddi/runtime/dist/transport.d.ts +1 -1
  178. package/node_modules/@buddi/runtime/dist/transport.d.ts.map +1 -1
  179. package/node_modules/@buddi/runtime/dist/transport.js +6 -0
  180. package/node_modules/@buddi/runtime/dist/transport.js.map +1 -1
  181. package/node_modules/@buddi/tool-artifacts/dist/.tsbuildinfo +1 -1
  182. package/node_modules/@buddi/tool-browser/dist/.tsbuildinfo +1 -1
  183. package/node_modules/@buddi/tool-browser/dist/computer.d.ts +13 -0
  184. package/node_modules/@buddi/tool-browser/dist/computer.d.ts.map +1 -1
  185. package/node_modules/@buddi/tool-browser/dist/computer.js +22 -2
  186. package/node_modules/@buddi/tool-browser/dist/computer.js.map +1 -1
  187. package/node_modules/@buddi/tool-browser/dist/controller.d.ts +4 -0
  188. package/node_modules/@buddi/tool-browser/dist/controller.d.ts.map +1 -1
  189. package/node_modules/@buddi/tool-browser/dist/controller.js +8 -3
  190. package/node_modules/@buddi/tool-browser/dist/controller.js.map +1 -1
  191. package/node_modules/@buddi/tool-browser/dist/index.d.ts +1 -1
  192. package/node_modules/@buddi/tool-browser/dist/index.d.ts.map +1 -1
  193. package/node_modules/@buddi/tool-browser/dist/index.js +1 -1
  194. package/node_modules/@buddi/tool-browser/dist/index.js.map +1 -1
  195. package/node_modules/@buddi/tool-browser/dist/native/buddi-computer +0 -0
  196. package/node_modules/@buddi/tool-browser/dist/service.d.ts +5 -0
  197. package/node_modules/@buddi/tool-browser/dist/service.d.ts.map +1 -1
  198. package/node_modules/@buddi/tool-browser/dist/service.js.map +1 -1
  199. package/node_modules/@buddi/tool-email/dist/.tsbuildinfo +1 -1
  200. package/node_modules/@buddi/tool-host/dist/.tsbuildinfo +1 -1
  201. package/node_modules/@buddi/tool-mcp/dist/.tsbuildinfo +1 -1
  202. package/node_modules/@buddi/tool-memory/dist/.tsbuildinfo +1 -1
  203. package/node_modules/@buddi/tool-web/dist/.tsbuildinfo +1 -1
  204. package/package.json +2 -2
  205. package/packages/cli/dist/.tsbuildinfo +1 -1
  206. package/packages/cli/dist/doctor-probes.d.ts.map +1 -1
  207. package/packages/cli/dist/doctor-probes.js +8 -2
  208. package/packages/cli/dist/doctor-probes.js.map +1 -1
  209. package/packages/cli/dist/doctor.d.ts +12 -0
  210. package/packages/cli/dist/doctor.d.ts.map +1 -1
  211. package/packages/cli/dist/doctor.js +9 -0
  212. package/packages/cli/dist/doctor.js.map +1 -1
  213. package/packages/core/dist/.tsbuildinfo +1 -1
  214. package/packages/core/dist/host/build.d.ts +14 -0
  215. package/packages/core/dist/host/build.d.ts.map +1 -1
  216. package/packages/core/dist/host/build.js +55 -5
  217. package/packages/core/dist/host/build.js.map +1 -1
  218. package/packages/core/dist/host/http.d.ts +62 -0
  219. package/packages/core/dist/host/http.d.ts.map +1 -1
  220. package/packages/core/dist/host/http.js +193 -2
  221. package/packages/core/dist/host/http.js.map +1 -1
  222. package/packages/core/dist/host/types.d.ts +43 -4
  223. package/packages/core/dist/host/types.d.ts.map +1 -1
  224. package/packages/core/dist/index.d.ts +1 -0
  225. package/packages/core/dist/index.d.ts.map +1 -1
  226. package/packages/core/dist/index.js +1 -0
  227. package/packages/core/dist/index.js.map +1 -1
  228. package/packages/core/dist/notifications/notify.d.ts.map +1 -1
  229. package/packages/core/dist/notifications/notify.js +10 -6
  230. package/packages/core/dist/notifications/notify.js.map +1 -1
  231. package/packages/core/dist/notifications/store.d.ts.map +1 -1
  232. package/packages/core/dist/notifications/store.js +2 -1
  233. package/packages/core/dist/notifications/store.js.map +1 -1
  234. package/packages/core/dist/notifications/types.d.ts +8 -0
  235. package/packages/core/dist/notifications/types.d.ts.map +1 -1
  236. package/packages/core/dist/notifications/types.js.map +1 -1
  237. package/packages/core/dist/pages.d.ts +308 -13
  238. package/packages/core/dist/pages.d.ts.map +1 -1
  239. package/packages/core/dist/pages.js +111 -4
  240. package/packages/core/dist/pages.js.map +1 -1
  241. package/packages/core/dist/plugin/assets.d.ts +52 -0
  242. package/packages/core/dist/plugin/assets.d.ts.map +1 -0
  243. package/packages/core/dist/plugin/assets.js +59 -0
  244. package/packages/core/dist/plugin/assets.js.map +1 -0
  245. package/packages/core/dist/plugin/index.d.ts +6 -4
  246. package/packages/core/dist/plugin/index.d.ts.map +1 -1
  247. package/packages/core/dist/plugin/index.js +2 -1
  248. package/packages/core/dist/plugin/index.js.map +1 -1
  249. package/packages/core/dist/plugin/requires.d.ts +3 -1
  250. package/packages/core/dist/plugin/requires.d.ts.map +1 -1
  251. package/packages/core/dist/plugin/requires.js +5 -3
  252. package/packages/core/dist/plugin/requires.js.map +1 -1
  253. package/packages/core/dist/plugin/uses.d.ts +1 -1
  254. package/packages/core/dist/plugin/uses.d.ts.map +1 -1
  255. package/packages/core/dist/plugin/uses.js +2 -0
  256. package/packages/core/dist/plugin/uses.js.map +1 -1
  257. package/packages/core/dist/plugin/version.d.ts +1 -1
  258. package/packages/core/dist/plugin/version.js +1 -1
  259. package/packages/core/dist/plugin-assets.d.ts +21 -0
  260. package/packages/core/dist/plugin-assets.d.ts.map +1 -0
  261. package/packages/core/dist/plugin-assets.js +140 -0
  262. package/packages/core/dist/plugin-assets.js.map +1 -0
  263. package/packages/core/dist/registry.d.ts +9 -0
  264. package/packages/core/dist/registry.d.ts.map +1 -1
  265. package/packages/core/dist/registry.js +33 -2
  266. package/packages/core/dist/registry.js.map +1 -1
  267. package/packages/core/dist/scheduler/missions.d.ts +14 -0
  268. package/packages/core/dist/scheduler/missions.d.ts.map +1 -1
  269. package/packages/core/dist/scheduler/missions.js +17 -4
  270. package/packages/core/dist/scheduler/missions.js.map +1 -1
  271. package/packages/core/dist/scheduler/types.d.ts +13 -0
  272. package/packages/core/dist/scheduler/types.d.ts.map +1 -1
  273. package/packages/core/dist/scheduler/types.js +14 -0
  274. package/packages/core/dist/scheduler/types.js.map +1 -1
  275. package/packages/core/dist/surfaces.d.ts +10 -0
  276. package/packages/core/dist/surfaces.d.ts.map +1 -1
  277. package/packages/core/dist/surfaces.js +11 -0
  278. package/packages/core/dist/surfaces.js.map +1 -1
  279. package/packages/core/dist/tools.d.ts +43 -1
  280. package/packages/core/dist/tools.d.ts.map +1 -1
  281. package/packages/core/dist/tools.js +38 -0
  282. package/packages/core/dist/tools.js.map +1 -1
  283. package/packages/core/dist/views.d.ts +17 -0
  284. package/packages/core/dist/views.d.ts.map +1 -1
  285. package/packages/core/dist/views.js +1 -0
  286. package/packages/core/dist/views.js.map +1 -1
  287. package/packages/core/dist/widget-settings.d.ts +2 -1
  288. package/packages/core/dist/widget-settings.d.ts.map +1 -1
  289. package/packages/core/dist/widget-settings.js +8 -2
  290. package/packages/core/dist/widget-settings.js.map +1 -1
  291. package/packages/core/dist/widgets.d.ts +32 -2
  292. package/packages/core/dist/widgets.d.ts.map +1 -1
  293. package/packages/core/dist/widgets.js +38 -5
  294. package/packages/core/dist/widgets.js.map +1 -1
  295. package/packages/core/migrations/073_mission_report.sql +15 -0
  296. package/packages/gateway/dist/.tsbuildinfo +1 -1
  297. package/packages/gateway/dist/agents/catalogue-package.d.ts +68 -0
  298. package/packages/gateway/dist/agents/catalogue-package.d.ts.map +1 -1
  299. package/packages/gateway/dist/agents/catalogue-package.js +18 -1
  300. package/packages/gateway/dist/agents/catalogue-package.js.map +1 -1
  301. package/packages/gateway/dist/agents/owner-text.d.ts +19 -0
  302. package/packages/gateway/dist/agents/owner-text.d.ts.map +1 -0
  303. package/packages/gateway/dist/agents/owner-text.js +44 -0
  304. package/packages/gateway/dist/agents/owner-text.js.map +1 -0
  305. package/packages/gateway/dist/agents/platform-catalogue.d.ts +49 -3
  306. package/packages/gateway/dist/agents/platform-catalogue.d.ts.map +1 -1
  307. package/packages/gateway/dist/agents/platform-catalogue.js +156 -32
  308. package/packages/gateway/dist/agents/platform-catalogue.js.map +1 -1
  309. package/packages/gateway/dist/agents/platform.d.ts +7 -0
  310. package/packages/gateway/dist/agents/platform.d.ts.map +1 -1
  311. package/packages/gateway/dist/agents/platform.js +4 -0
  312. package/packages/gateway/dist/agents/platform.js.map +1 -1
  313. package/packages/gateway/dist/bootstrap.d.ts.map +1 -1
  314. package/packages/gateway/dist/bootstrap.js +3 -0
  315. package/packages/gateway/dist/bootstrap.js.map +1 -1
  316. package/packages/gateway/dist/index.d.ts +1 -1
  317. package/packages/gateway/dist/index.d.ts.map +1 -1
  318. package/packages/gateway/dist/index.js +1 -1
  319. package/packages/gateway/dist/index.js.map +1 -1
  320. package/packages/gateway/dist/missions/agent-run.d.ts.map +1 -1
  321. package/packages/gateway/dist/missions/agent-run.js +2 -0
  322. package/packages/gateway/dist/missions/agent-run.js.map +1 -1
  323. package/packages/gateway/dist/missions/defaults.d.ts.map +1 -1
  324. package/packages/gateway/dist/missions/defaults.js +2 -0
  325. package/packages/gateway/dist/missions/defaults.js.map +1 -1
  326. package/packages/gateway/dist/missions/execute.d.ts +17 -1
  327. package/packages/gateway/dist/missions/execute.d.ts.map +1 -1
  328. package/packages/gateway/dist/missions/execute.js +64 -7
  329. package/packages/gateway/dist/missions/execute.js.map +1 -1
  330. package/packages/gateway/dist/missions/report.d.ts +25 -2
  331. package/packages/gateway/dist/missions/report.d.ts.map +1 -1
  332. package/packages/gateway/dist/missions/report.js +70 -11
  333. package/packages/gateway/dist/missions/report.js.map +1 -1
  334. package/packages/gateway/dist/owner-notify.d.ts.map +1 -1
  335. package/packages/gateway/dist/owner-notify.js +7 -3
  336. package/packages/gateway/dist/owner-notify.js.map +1 -1
  337. package/packages/gateway/dist/plugins/asset-image-worker.d.ts +2 -0
  338. package/packages/gateway/dist/plugins/asset-image-worker.d.ts.map +1 -0
  339. package/packages/gateway/dist/plugins/asset-image-worker.js +18 -0
  340. package/packages/gateway/dist/plugins/asset-image-worker.js.map +1 -0
  341. package/packages/gateway/dist/plugins/asset-image.d.ts +31 -0
  342. package/packages/gateway/dist/plugins/asset-image.d.ts.map +1 -0
  343. package/packages/gateway/dist/plugins/asset-image.js +332 -0
  344. package/packages/gateway/dist/plugins/asset-image.js.map +1 -0
  345. package/packages/gateway/dist/plugins/load.d.ts.map +1 -1
  346. package/packages/gateway/dist/plugins/load.js +14 -1
  347. package/packages/gateway/dist/plugins/load.js.map +1 -1
  348. package/packages/gateway/dist/plugins/stage.d.ts +6 -0
  349. package/packages/gateway/dist/plugins/stage.d.ts.map +1 -1
  350. package/packages/gateway/dist/plugins/stage.js +5 -0
  351. package/packages/gateway/dist/plugins/stage.js.map +1 -1
  352. package/packages/gateway/dist/plugins/uninstall.d.ts.map +1 -1
  353. package/packages/gateway/dist/plugins/uninstall.js +8 -0
  354. package/packages/gateway/dist/plugins/uninstall.js.map +1 -1
  355. package/packages/gateway/dist/telegram/channel.d.ts +12 -0
  356. package/packages/gateway/dist/telegram/channel.d.ts.map +1 -1
  357. package/packages/gateway/dist/telegram/channel.js +43 -1
  358. package/packages/gateway/dist/telegram/channel.js.map +1 -1
  359. package/packages/gateway/dist/web/api-routes.d.ts.map +1 -1
  360. package/packages/gateway/dist/web/api-routes.js +8 -2
  361. package/packages/gateway/dist/web/api-routes.js.map +1 -1
  362. package/packages/gateway/dist/web/catalogue.d.ts.map +1 -1
  363. package/packages/gateway/dist/web/catalogue.js +7 -4
  364. package/packages/gateway/dist/web/catalogue.js.map +1 -1
  365. package/packages/gateway/dist/web/extension.d.ts +12 -0
  366. package/packages/gateway/dist/web/extension.d.ts.map +1 -1
  367. package/packages/gateway/dist/web/extension.js +11 -1
  368. package/packages/gateway/dist/web/extension.js.map +1 -1
  369. package/packages/gateway/dist/web/lock.d.ts +6 -0
  370. package/packages/gateway/dist/web/lock.d.ts.map +1 -1
  371. package/packages/gateway/dist/web/lock.js +33 -2
  372. package/packages/gateway/dist/web/lock.js.map +1 -1
  373. package/packages/gateway/dist/web/server.d.ts.map +1 -1
  374. package/packages/gateway/dist/web/server.js +34 -2
  375. package/packages/gateway/dist/web/server.js.map +1 -1
  376. package/packages/gateway/dist/web/widgets.js +2 -2
  377. package/packages/gateway/dist/web/widgets.js.map +1 -1
  378. package/packages/install/dist/.tsbuildinfo +1 -1
  379. package/packages/runtime/dist/.tsbuildinfo +1 -1
  380. package/packages/runtime/dist/transport.d.ts +1 -1
  381. package/packages/runtime/dist/transport.d.ts.map +1 -1
  382. package/packages/runtime/dist/transport.js +6 -0
  383. package/packages/runtime/dist/transport.js.map +1 -1
  384. package/packages/tools/artifacts/dist/.tsbuildinfo +1 -1
  385. package/packages/tools/browser/dist/.tsbuildinfo +1 -1
  386. package/packages/tools/browser/dist/computer.d.ts +13 -0
  387. package/packages/tools/browser/dist/computer.d.ts.map +1 -1
  388. package/packages/tools/browser/dist/computer.js +22 -2
  389. package/packages/tools/browser/dist/computer.js.map +1 -1
  390. package/packages/tools/browser/dist/controller.d.ts +4 -0
  391. package/packages/tools/browser/dist/controller.d.ts.map +1 -1
  392. package/packages/tools/browser/dist/controller.js +8 -3
  393. package/packages/tools/browser/dist/controller.js.map +1 -1
  394. package/packages/tools/browser/dist/index.d.ts +1 -1
  395. package/packages/tools/browser/dist/index.d.ts.map +1 -1
  396. package/packages/tools/browser/dist/index.js +1 -1
  397. package/packages/tools/browser/dist/index.js.map +1 -1
  398. package/packages/tools/browser/dist/native/buddi-computer +0 -0
  399. package/packages/tools/browser/dist/service.d.ts +5 -0
  400. package/packages/tools/browser/dist/service.d.ts.map +1 -1
  401. package/packages/tools/browser/dist/service.js.map +1 -1
  402. package/packages/tools/email/dist/.tsbuildinfo +1 -1
  403. package/packages/tools/host/dist/.tsbuildinfo +1 -1
  404. package/packages/tools/mcp/dist/.tsbuildinfo +1 -1
  405. package/packages/tools/memory/dist/.tsbuildinfo +1 -1
  406. package/packages/tools/web/dist/.tsbuildinfo +1 -1
  407. package/packages/web/dist/assets/index-B_P_ux2I.css +1 -0
  408. package/packages/web/dist/assets/index-CjOzIGL7.js +134 -0
  409. package/packages/web/dist/assets/{lottie_light-DYHnHRWL.js → lottie_light-Dj5SSwxs.js} +1 -1
  410. package/packages/web/dist/build.json +1 -1
  411. package/packages/web/dist/index.html +2 -2
  412. package/packages/web/dist/precache.json +4 -4
  413. package/packages/web/dist/assets/index-ZauRFo4G.js +0 -134
  414. package/packages/web/dist/assets/index-viBWQfeT.css +0 -1
@@ -0,0 +1,134 @@
1
+ var Dy=e=>{throw TypeError(e)};var Oy=(e,t,s)=>t.has(e)||Dy("Cannot "+s);var jn=(e,t,s)=>(Oy(e,t,"read from private field"),s?s.call(e):t.get(e)),Ly=(e,t,s)=>t.has(e)?Dy("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),qf=(e,t,s,r)=>(Oy(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s);function hP(e,t){for(var s=0;s<t.length;s++){const r=t[s];if(typeof r!="string"&&!Array.isArray(r)){for(const i in r)if(i!=="default"&&!(i in e)){const a=Object.getOwnPropertyDescriptor(r,i);a&&Object.defineProperty(e,i,a.get?a:{enumerable:!0,get:()=>r[i]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const a of i)if(a.type==="childList")for(const l of a.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&r(l)}).observe(document,{childList:!0,subtree:!0});function s(i){const a={};return i.integrity&&(a.integrity=i.integrity),i.referrerPolicy&&(a.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?a.credentials="include":i.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function r(i){if(i.ep)return;i.ep=!0;const a=s(i);fetch(i.href,a)}})();var SZ=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function fP(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var KN={exports:{}},$h={},VN={exports:{}},tt={};/**
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 Pc=Symbol.for("react.element"),mP=Symbol.for("react.portal"),pP=Symbol.for("react.fragment"),gP=Symbol.for("react.strict_mode"),xP=Symbol.for("react.profiler"),vP=Symbol.for("react.provider"),jP=Symbol.for("react.context"),wP=Symbol.for("react.forward_ref"),yP=Symbol.for("react.suspense"),bP=Symbol.for("react.memo"),kP=Symbol.for("react.lazy"),Fy=Symbol.iterator;function NP(e){return e===null||typeof e!="object"?null:(e=Fy&&e[Fy]||e["@@iterator"],typeof e=="function"?e:null)}var GN={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},qN=Object.assign,YN={};function Ll(e,t,s){this.props=e,this.context=t,this.refs=YN,this.updater=s||GN}Ll.prototype.isReactComponent={};Ll.prototype.setState=function(e,t){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,t,"setState")};Ll.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function JN(){}JN.prototype=Ll.prototype;function nv(e,t,s){this.props=e,this.context=t,this.refs=YN,this.updater=s||GN}var sv=nv.prototype=new JN;sv.constructor=nv;qN(sv,Ll.prototype);sv.isPureReactComponent=!0;var _y=Array.isArray,QN=Object.prototype.hasOwnProperty,rv={current:null},XN={key:!0,ref:!0,__self:!0,__source:!0};function ZN(e,t,s){var r,i={},a=null,l=null;if(t!=null)for(r in t.ref!==void 0&&(l=t.ref),t.key!==void 0&&(a=""+t.key),t)QN.call(t,r)&&!XN.hasOwnProperty(r)&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=s;else if(1<o){for(var c=Array(o),u=0;u<o;u++)c[u]=arguments[u+2];i.children=c}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return{$$typeof:Pc,type:e,key:a,ref:l,props:i,_owner:rv.current}}function SP(e,t){return{$$typeof:Pc,type:e.type,key:t,ref:e.ref,props:e.props,_owner:e._owner}}function iv(e){return typeof e=="object"&&e!==null&&e.$$typeof===Pc}function CP(e){var t={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(s){return t[s]})}var zy=/\/+/g;function Yf(e,t){return typeof e=="object"&&e!==null&&e.key!=null?CP(""+e.key):t.toString(36)}function Zu(e,t,s,r,i){var a=typeof e;(a==="undefined"||a==="boolean")&&(e=null);var l=!1;if(e===null)l=!0;else switch(a){case"string":case"number":l=!0;break;case"object":switch(e.$$typeof){case Pc:case mP:l=!0}}if(l)return l=e,i=i(l),e=r===""?"."+Yf(l,0):r,_y(i)?(s="",e!=null&&(s=e.replace(zy,"$&/")+"/"),Zu(i,t,s,"",function(u){return u})):i!=null&&(iv(i)&&(i=SP(i,s+(!i.key||l&&l.key===i.key?"":(""+i.key).replace(zy,"$&/")+"/")+e)),t.push(i)),1;if(l=0,r=r===""?".":r+":",_y(e))for(var o=0;o<e.length;o++){a=e[o];var c=r+Yf(a,o);l+=Zu(a,t,s,c,i)}else if(c=NP(e),typeof c=="function")for(e=c.call(e),o=0;!(a=e.next()).done;)a=a.value,c=r+Yf(a,o++),l+=Zu(a,t,s,c,i);else if(a==="object")throw t=String(e),Error("Objects are not valid as a React child (found: "+(t==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":t)+"). If you meant to render a collection of children, use an array instead.");return l}function uu(e,t,s){if(e==null)return e;var r=[],i=0;return Zu(e,r,"","",function(a){return t.call(s,a,i++)}),r}function EP(e){if(e._status===-1){var t=e._result;t=t(),t.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=t)}if(e._status===1)return e._result.default;throw e._result}var Mn={current:null},ed={transition:null},AP={ReactCurrentDispatcher:Mn,ReactCurrentBatchConfig:ed,ReactCurrentOwner:rv};function eS(){throw Error("act(...) is not supported in production builds of React.")}tt.Children={map:uu,forEach:function(e,t,s){uu(e,function(){t.apply(this,arguments)},s)},count:function(e){var t=0;return uu(e,function(){t++}),t},toArray:function(e){return uu(e,function(t){return t})||[]},only:function(e){if(!iv(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};tt.Component=Ll;tt.Fragment=pP;tt.Profiler=xP;tt.PureComponent=nv;tt.StrictMode=gP;tt.Suspense=yP;tt.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=AP;tt.act=eS;tt.cloneElement=function(e,t,s){if(e==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+e+".");var r=qN({},e.props),i=e.key,a=e.ref,l=e._owner;if(t!=null){if(t.ref!==void 0&&(a=t.ref,l=rv.current),t.key!==void 0&&(i=""+t.key),e.type&&e.type.defaultProps)var o=e.type.defaultProps;for(c in t)QN.call(t,c)&&!XN.hasOwnProperty(c)&&(r[c]=t[c]===void 0&&o!==void 0?o[c]:t[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:Pc,type:e.type,key:i,ref:a,props:r,_owner:l}};tt.createContext=function(e){return e={$$typeof:jP,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:vP,_context:e},e.Consumer=e};tt.createElement=ZN;tt.createFactory=function(e){var t=ZN.bind(null,e);return t.type=e,t};tt.createRef=function(){return{current:null}};tt.forwardRef=function(e){return{$$typeof:wP,render:e}};tt.isValidElement=iv;tt.lazy=function(e){return{$$typeof:kP,_payload:{_status:-1,_result:e},_init:EP}};tt.memo=function(e,t){return{$$typeof:bP,type:e,compare:t===void 0?null:t}};tt.startTransition=function(e){var t=ed.transition;ed.transition={};try{e()}finally{ed.transition=t}};tt.unstable_act=eS;tt.useCallback=function(e,t){return Mn.current.useCallback(e,t)};tt.useContext=function(e){return Mn.current.useContext(e)};tt.useDebugValue=function(){};tt.useDeferredValue=function(e){return Mn.current.useDeferredValue(e)};tt.useEffect=function(e,t){return Mn.current.useEffect(e,t)};tt.useId=function(){return Mn.current.useId()};tt.useImperativeHandle=function(e,t,s){return Mn.current.useImperativeHandle(e,t,s)};tt.useInsertionEffect=function(e,t){return Mn.current.useInsertionEffect(e,t)};tt.useLayoutEffect=function(e,t){return Mn.current.useLayoutEffect(e,t)};tt.useMemo=function(e,t){return Mn.current.useMemo(e,t)};tt.useReducer=function(e,t,s){return Mn.current.useReducer(e,t,s)};tt.useRef=function(e){return Mn.current.useRef(e)};tt.useState=function(e){return Mn.current.useState(e)};tt.useSyncExternalStore=function(e,t,s){return Mn.current.useSyncExternalStore(e,t,s)};tt.useTransition=function(){return Mn.current.useTransition()};tt.version="18.3.1";VN.exports=tt;var d=VN.exports;const TP=fP(d),Fl=hP({__proto__:null,default:TP},[d]);/**
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 $P=d,RP=Symbol.for("react.element"),IP=Symbol.for("react.fragment"),PP=Object.prototype.hasOwnProperty,MP=$P.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,DP={key:!0,ref:!0,__self:!0,__source:!0};function tS(e,t,s){var r,i={},a=null,l=null;s!==void 0&&(a=""+s),t.key!==void 0&&(a=""+t.key),t.ref!==void 0&&(l=t.ref);for(r in t)PP.call(t,r)&&!DP.hasOwnProperty(r)&&(i[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps,t)i[r]===void 0&&(i[r]=t[r]);return{$$typeof:RP,type:e,key:a,ref:l,props:i,_owner:MP.current}}$h.Fragment=IP;$h.jsx=tS;$h.jsxs=tS;KN.exports=$h;var n=KN.exports,nS={exports:{}},ls={},sS={exports:{}},rS={};/**
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 t(O,H){var B=O.length;O.push(H);e:for(;0<B;){var Y=B-1>>>1,W=O[Y];if(0<i(W,H))O[Y]=H,O[B]=W,B=Y;else break e}}function s(O){return O.length===0?null:O[0]}function r(O){if(O.length===0)return null;var H=O[0],B=O.pop();if(B!==H){O[0]=B;e:for(var Y=0,W=O.length,q=W>>>1;Y<q;){var _=2*(Y+1)-1,X=O[_],Q=_+1,ee=O[Q];if(0>i(X,B))Q<W&&0>i(ee,X)?(O[Y]=ee,O[Q]=B,Y=Q):(O[Y]=X,O[_]=B,Y=_);else if(Q<W&&0>i(ee,B))O[Y]=ee,O[Q]=B,Y=Q;else break e}}return H}function i(O,H){var B=O.sortIndex-H.sortIndex;return B!==0?B:O.id-H.id}if(typeof performance=="object"&&typeof performance.now=="function"){var a=performance;e.unstable_now=function(){return a.now()}}else{var l=Date,o=l.now();e.unstable_now=function(){return l.now()-o}}var c=[],u=[],h=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 w(O){for(var H=s(u);H!==null;){if(H.callback===null)r(u);else if(H.startTime<=O)r(u),H.sortIndex=H.expirationTime,t(c,H);else break;H=s(u)}}function y(O){if(v=!1,w(O),!g)if(s(c)!==null)g=!0,P(k);else{var H=s(u);H!==null&&D(y,H.startTime-O)}}function k(O,H){g=!1,v&&(v=!1,j(C),C=-1),p=!0;var B=m;try{for(w(H),f=s(c);f!==null&&(!(f.expirationTime>H)||O&&!I());){var Y=f.callback;if(typeof Y=="function"){f.callback=null,m=f.priorityLevel;var W=Y(f.expirationTime<=H);H=e.unstable_now(),typeof W=="function"?f.callback=W:f===s(c)&&r(c),w(H)}else r(c);f=s(c)}if(f!==null)var q=!0;else{var _=s(u);_!==null&&D(y,_.startTime-H),q=!1}return q}finally{f=null,m=B,p=!1}}var N=!1,S=null,C=-1,E=5,R=-1;function I(){return!(e.unstable_now()-R<E)}function L(){if(S!==null){var O=e.unstable_now();R=O;var H=!0;try{H=S(!0,O)}finally{H?F():(N=!1,S=null)}}else N=!1}var F;if(typeof x=="function")F=function(){x(L)};else if(typeof MessageChannel<"u"){var T=new MessageChannel,M=T.port2;T.port1.onmessage=L,F=function(){M.postMessage(null)}}else F=function(){b(L,0)};function P(O){S=O,N||(N=!0,F())}function D(O,H){C=b(function(){O(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(O){O.callback=null},e.unstable_continueExecution=function(){g||p||(g=!0,P(k))},e.unstable_forceFrameRate=function(O){0>O||125<O?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):E=0<O?Math.floor(1e3/O):5},e.unstable_getCurrentPriorityLevel=function(){return m},e.unstable_getFirstCallbackNode=function(){return s(c)},e.unstable_next=function(O){switch(m){case 1:case 2:case 3:var H=3;break;default:H=m}var B=m;m=H;try{return O()}finally{m=B}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(O,H){switch(O){case 1:case 2:case 3:case 4:case 5:break;default:O=3}var B=m;m=O;try{return H()}finally{m=B}},e.unstable_scheduleCallback=function(O,H,B){var Y=e.unstable_now();switch(typeof B=="object"&&B!==null?(B=B.delay,B=typeof B=="number"&&0<B?Y+B:Y):B=Y,O){case 1:var W=-1;break;case 2:W=250;break;case 5:W=1073741823;break;case 4:W=1e4;break;default:W=5e3}return W=B+W,O={id:h++,callback:H,priorityLevel:O,startTime:B,expirationTime:W,sortIndex:-1},B>Y?(O.sortIndex=B,t(u,O),s(c)===null&&O===s(u)&&(v?(j(C),C=-1):v=!0,D(y,B-Y))):(O.sortIndex=W,t(c,O),g||p||(g=!0,P(k))),O},e.unstable_shouldYield=I,e.unstable_wrapCallback=function(O){var H=m;return function(){var B=m;m=H;try{return O.apply(this,arguments)}finally{m=B}}}})(rS);sS.exports=rS;var OP=sS.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 LP=d,rs=OP;function xe(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,s=1;s<arguments.length;s++)t+="&args[]="+encodeURIComponent(arguments[s]);return"Minified React error #"+e+"; visit "+t+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var iS=new Set,Vo={};function xa(e,t){vl(e,t),vl(e+"Capture",t)}function vl(e,t){for(Vo[e]=t,e=0;e<t.length;e++)iS.add(t[e])}var Br=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Ep=Object.prototype.hasOwnProperty,FP=/^[: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]*$/,Uy={},By={};function _P(e){return Ep.call(By,e)?!0:Ep.call(Uy,e)?!1:FP.test(e)?By[e]=!0:(Uy[e]=!0,!1)}function zP(e,t,s,r){if(s!==null&&s.type===0)return!1;switch(typeof t){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 UP(e,t,s,r){if(t===null||typeof t>"u"||zP(e,t,s,r))return!0;if(r)return!1;if(s!==null)switch(s.type){case 3:return!t;case 4:return t===!1;case 5:return isNaN(t);case 6:return isNaN(t)||1>t}return!1}function Dn(e,t,s,r,i,a,l){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=r,this.attributeNamespace=i,this.mustUseProperty=s,this.propertyName=e,this.type=t,this.sanitizeURL=a,this.removeEmptyString=l}var pn={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){pn[e]=new Dn(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];pn[t]=new Dn(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){pn[e]=new Dn(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){pn[e]=new Dn(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){pn[e]=new Dn(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){pn[e]=new Dn(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){pn[e]=new Dn(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){pn[e]=new Dn(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){pn[e]=new Dn(e,5,!1,e.toLowerCase(),null,!1,!1)});var av=/[\-:]([a-z])/g;function lv(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 t=e.replace(av,lv);pn[t]=new Dn(t,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var t=e.replace(av,lv);pn[t]=new Dn(t,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var t=e.replace(av,lv);pn[t]=new Dn(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){pn[e]=new Dn(e,1,!1,e.toLowerCase(),null,!1,!1)});pn.xlinkHref=new Dn("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){pn[e]=new Dn(e,1,!1,e.toLowerCase(),null,!0,!0)});function ov(e,t,s,r){var i=pn.hasOwnProperty(t)?pn[t]:null;(i!==null?i.type!==0:r||!(2<t.length)||t[0]!=="o"&&t[0]!=="O"||t[1]!=="n"&&t[1]!=="N")&&(UP(t,s,i,r)&&(s=null),r||i===null?_P(t)&&(s===null?e.removeAttribute(t):e.setAttribute(t,""+s)):i.mustUseProperty?e[i.propertyName]=s===null?i.type===3?!1:"":s:(t=i.attributeName,r=i.attributeNamespace,s===null?e.removeAttribute(t):(i=i.type,s=i===3||i===4&&s===!0?"":""+s,r?e.setAttributeNS(r,t,s):e.setAttribute(t,s))))}var Jr=LP.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,du=Symbol.for("react.element"),Ha=Symbol.for("react.portal"),Ka=Symbol.for("react.fragment"),cv=Symbol.for("react.strict_mode"),Ap=Symbol.for("react.profiler"),aS=Symbol.for("react.provider"),lS=Symbol.for("react.context"),uv=Symbol.for("react.forward_ref"),Tp=Symbol.for("react.suspense"),$p=Symbol.for("react.suspense_list"),dv=Symbol.for("react.memo"),ri=Symbol.for("react.lazy"),oS=Symbol.for("react.offscreen"),Wy=Symbol.iterator;function lo(e){return e===null||typeof e!="object"?null:(e=Wy&&e[Wy]||e["@@iterator"],typeof e=="function"?e:null)}var Mt=Object.assign,Jf;function ko(e){if(Jf===void 0)try{throw Error()}catch(s){var t=s.stack.trim().match(/\n( *(at )?)/);Jf=t&&t[1]||""}return`
34
+ `+Jf+e}var Qf=!1;function Xf(e,t){if(!e||Qf)return"";Qf=!0;var s=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(t)if(t=function(){throw Error()},Object.defineProperty(t.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(t,[])}catch(u){var r=u}Reflect.construct(e,[],t)}else{try{t.call()}catch(u){r=u}e.call(t.prototype)}else{try{throw Error()}catch(u){r=u}e()}}catch(u){if(u&&r&&typeof u.stack=="string"){for(var i=u.stack.split(`
35
+ `),a=r.stack.split(`
36
+ `),l=i.length-1,o=a.length-1;1<=l&&0<=o&&i[l]!==a[o];)o--;for(;1<=l&&0<=o;l--,o--)if(i[l]!==a[o]){if(l!==1||o!==1)do if(l--,o--,0>o||i[l]!==a[o]){var c=`
37
+ `+i[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{Qf=!1,Error.prepareStackTrace=s}return(e=e?e.displayName||e.name:"")?ko(e):""}function BP(e){switch(e.tag){case 5:return ko(e.type);case 16:return ko("Lazy");case 13:return ko("Suspense");case 19:return ko("SuspenseList");case 0:case 2:case 15:return e=Xf(e.type,!1),e;case 11:return e=Xf(e.type.render,!1),e;case 1:return e=Xf(e.type,!0),e;default:return""}}function Rp(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 Ka:return"Fragment";case Ha:return"Portal";case Ap:return"Profiler";case cv:return"StrictMode";case Tp:return"Suspense";case $p:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case lS:return(e.displayName||"Context")+".Consumer";case aS:return(e._context.displayName||"Context")+".Provider";case uv:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case dv:return t=e.displayName||null,t!==null?t:Rp(e.type)||"Memo";case ri:t=e._payload,e=e._init;try{return Rp(e(t))}catch{}}return null}function WP(e){var t=e.type;switch(e.tag){case 24:return"Cache";case 9:return(t.displayName||"Context")+".Consumer";case 10:return(t._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=t.render,e=e.displayName||e.name||"",t.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return t;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return Rp(t);case 8:return t===cv?"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 t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t}return null}function ki(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function cS(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function HP(e){var t=cS(e)?"checked":"value",s=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=""+e[t];if(!e.hasOwnProperty(t)&&typeof s<"u"&&typeof s.get=="function"&&typeof s.set=="function"){var i=s.get,a=s.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return i.call(this)},set:function(l){r=""+l,a.call(this,l)}}),Object.defineProperty(e,t,{enumerable:s.enumerable}),{getValue:function(){return r},setValue:function(l){r=""+l},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function hu(e){e._valueTracker||(e._valueTracker=HP(e))}function uS(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var s=t.getValue(),r="";return e&&(r=cS(e)?e.checked?"true":"false":e.value),e=r,e!==s?(t.setValue(e),!0):!1}function Cd(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 Ip(e,t){var s=t.checked;return Mt({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:s??e._wrapperState.initialChecked})}function Hy(e,t){var s=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;s=ki(t.value!=null?t.value:s),e._wrapperState={initialChecked:r,initialValue:s,controlled:t.type==="checkbox"||t.type==="radio"?t.checked!=null:t.value!=null}}function dS(e,t){t=t.checked,t!=null&&ov(e,"checked",t,!1)}function Pp(e,t){dS(e,t);var s=ki(t.value),r=t.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}t.hasOwnProperty("value")?Mp(e,t.type,s):t.hasOwnProperty("defaultValue")&&Mp(e,t.type,ki(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function Ky(e,t,s){if(t.hasOwnProperty("value")||t.hasOwnProperty("defaultValue")){var r=t.type;if(!(r!=="submit"&&r!=="reset"||t.value!==void 0&&t.value!==null))return;t=""+e._wrapperState.initialValue,s||t===e.value||(e.value=t),e.defaultValue=t}s=e.name,s!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,s!==""&&(e.name=s)}function Mp(e,t,s){(t!=="number"||Cd(e.ownerDocument)!==e)&&(s==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+s&&(e.defaultValue=""+s))}var No=Array.isArray;function al(e,t,s,r){if(e=e.options,t){t={};for(var i=0;i<s.length;i++)t["$"+s[i]]=!0;for(s=0;s<e.length;s++)i=t.hasOwnProperty("$"+e[s].value),e[s].selected!==i&&(e[s].selected=i),i&&r&&(e[s].defaultSelected=!0)}else{for(s=""+ki(s),t=null,i=0;i<e.length;i++){if(e[i].value===s){e[i].selected=!0,r&&(e[i].defaultSelected=!0);return}t!==null||e[i].disabled||(t=e[i])}t!==null&&(t.selected=!0)}}function Dp(e,t){if(t.dangerouslySetInnerHTML!=null)throw Error(xe(91));return Mt({},t,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function Vy(e,t){var s=t.value;if(s==null){if(s=t.children,t=t.defaultValue,s!=null){if(t!=null)throw Error(xe(92));if(No(s)){if(1<s.length)throw Error(xe(93));s=s[0]}t=s}t==null&&(t=""),s=t}e._wrapperState={initialValue:ki(s)}}function hS(e,t){var s=ki(t.value),r=ki(t.defaultValue);s!=null&&(s=""+s,s!==e.value&&(e.value=s),t.defaultValue==null&&e.defaultValue!==s&&(e.defaultValue=s)),r!=null&&(e.defaultValue=""+r)}function Gy(e){var t=e.textContent;t===e._wrapperState.initialValue&&t!==""&&t!==null&&(e.value=t)}function fS(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 Op(e,t){return e==null||e==="http://www.w3.org/1999/xhtml"?fS(t):e==="http://www.w3.org/2000/svg"&&t==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var fu,mS=function(e){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(t,s,r,i){MSApp.execUnsafeLocalFunction(function(){return e(t,s,r,i)})}:e}(function(e,t){if(e.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in e)e.innerHTML=t;else{for(fu=fu||document.createElement("div"),fu.innerHTML="<svg>"+t.valueOf().toString()+"</svg>",t=fu.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Go(e,t){if(t){var s=e.firstChild;if(s&&s===e.lastChild&&s.nodeType===3){s.nodeValue=t;return}}e.textContent=t}var Ro={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},KP=["Webkit","ms","Moz","O"];Object.keys(Ro).forEach(function(e){KP.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Ro[t]=Ro[e]})});function pS(e,t,s){return t==null||typeof t=="boolean"||t===""?"":s||typeof t!="number"||t===0||Ro.hasOwnProperty(e)&&Ro[e]?(""+t).trim():t+"px"}function gS(e,t){e=e.style;for(var s in t)if(t.hasOwnProperty(s)){var r=s.indexOf("--")===0,i=pS(s,t[s],r);s==="float"&&(s="cssFloat"),r?e.setProperty(s,i):e[s]=i}}var VP=Mt({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 Lp(e,t){if(t){if(VP[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(xe(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(xe(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(xe(61))}if(t.style!=null&&typeof t.style!="object")throw Error(xe(62))}}function Fp(e,t){if(e.indexOf("-")===-1)return typeof t.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 _p=null;function hv(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var zp=null,ll=null,ol=null;function qy(e){if(e=Oc(e)){if(typeof zp!="function")throw Error(xe(280));var t=e.stateNode;t&&(t=Dh(t),zp(e.stateNode,e.type,t))}}function xS(e){ll?ol?ol.push(e):ol=[e]:ll=e}function vS(){if(ll){var e=ll,t=ol;if(ol=ll=null,qy(e),t)for(e=0;e<t.length;e++)qy(t[e])}}function jS(e,t){return e(t)}function wS(){}var Zf=!1;function yS(e,t,s){if(Zf)return e(t,s);Zf=!0;try{return jS(e,t,s)}finally{Zf=!1,(ll!==null||ol!==null)&&(wS(),vS())}}function qo(e,t){var s=e.stateNode;if(s===null)return null;var r=Dh(s);if(r===null)return null;s=r[t];e:switch(t){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(xe(231,t,typeof s));return s}var Up=!1;if(Br)try{var oo={};Object.defineProperty(oo,"passive",{get:function(){Up=!0}}),window.addEventListener("test",oo,oo),window.removeEventListener("test",oo,oo)}catch{Up=!1}function GP(e,t,s,r,i,a,l,o,c){var u=Array.prototype.slice.call(arguments,3);try{t.apply(s,u)}catch(h){this.onError(h)}}var Io=!1,Ed=null,Ad=!1,Bp=null,qP={onError:function(e){Io=!0,Ed=e}};function YP(e,t,s,r,i,a,l,o,c){Io=!1,Ed=null,GP.apply(qP,arguments)}function JP(e,t,s,r,i,a,l,o,c){if(YP.apply(this,arguments),Io){if(Io){var u=Ed;Io=!1,Ed=null}else throw Error(xe(198));Ad||(Ad=!0,Bp=u)}}function va(e){var t=e,s=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(s=t.return),e=t.return;while(e)}return t.tag===3?s:null}function bS(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function Yy(e){if(va(e)!==e)throw Error(xe(188))}function QP(e){var t=e.alternate;if(!t){if(t=va(e),t===null)throw Error(xe(188));return t!==e?null:e}for(var s=e,r=t;;){var i=s.return;if(i===null)break;var a=i.alternate;if(a===null){if(r=i.return,r!==null){s=r;continue}break}if(i.child===a.child){for(a=i.child;a;){if(a===s)return Yy(i),e;if(a===r)return Yy(i),t;a=a.sibling}throw Error(xe(188))}if(s.return!==r.return)s=i,r=a;else{for(var l=!1,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){for(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)throw Error(xe(189))}}if(s.alternate!==r)throw Error(xe(190))}if(s.tag!==3)throw Error(xe(188));return s.stateNode.current===s?e:t}function kS(e){return e=QP(e),e!==null?NS(e):null}function NS(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var t=NS(e);if(t!==null)return t;e=e.sibling}return null}var SS=rs.unstable_scheduleCallback,Jy=rs.unstable_cancelCallback,XP=rs.unstable_shouldYield,ZP=rs.unstable_requestPaint,_t=rs.unstable_now,eM=rs.unstable_getCurrentPriorityLevel,fv=rs.unstable_ImmediatePriority,CS=rs.unstable_UserBlockingPriority,Td=rs.unstable_NormalPriority,tM=rs.unstable_LowPriority,ES=rs.unstable_IdlePriority,Rh=null,dr=null;function nM(e){if(dr&&typeof dr.onCommitFiberRoot=="function")try{dr.onCommitFiberRoot(Rh,e,void 0,(e.current.flags&128)===128)}catch{}}var Ls=Math.clz32?Math.clz32:iM,sM=Math.log,rM=Math.LN2;function iM(e){return e>>>=0,e===0?32:31-(sM(e)/rM|0)|0}var mu=64,pu=4194304;function So(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 $d(e,t){var s=e.pendingLanes;if(s===0)return 0;var r=0,i=e.suspendedLanes,a=e.pingedLanes,l=s&268435455;if(l!==0){var o=l&~i;o!==0?r=So(o):(a&=l,a!==0&&(r=So(a)))}else l=s&~i,l!==0?r=So(l):a!==0&&(r=So(a));if(r===0)return 0;if(t!==0&&t!==r&&!(t&i)&&(i=r&-r,a=t&-t,i>=a||i===16&&(a&4194240)!==0))return t;if(r&4&&(r|=s&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=r;0<t;)s=31-Ls(t),i=1<<s,r|=e[s],t&=~i;return r}function aM(e,t){switch(e){case 1:case 2:case 4:return t+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 t+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 lM(e,t){for(var s=e.suspendedLanes,r=e.pingedLanes,i=e.expirationTimes,a=e.pendingLanes;0<a;){var l=31-Ls(a),o=1<<l,c=i[l];c===-1?(!(o&s)||o&r)&&(i[l]=aM(o,t)):c<=t&&(e.expiredLanes|=o),a&=~o}}function Wp(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function AS(){var e=mu;return mu<<=1,!(mu&4194240)&&(mu=64),e}function em(e){for(var t=[],s=0;31>s;s++)t.push(e);return t}function Mc(e,t,s){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-Ls(t),e[t]=s}function oM(e,t){var s=e.pendingLanes&~t;e.pendingLanes=t,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=t,e.mutableReadLanes&=t,e.entangledLanes&=t,t=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0<s;){var i=31-Ls(s),a=1<<i;t[i]=0,r[i]=-1,e[i]=-1,s&=~a}}function mv(e,t){var s=e.entangledLanes|=t;for(e=e.entanglements;s;){var r=31-Ls(s),i=1<<r;i&t|e[r]&t&&(e[r]|=t),s&=~i}}var xt=0;function TS(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var $S,pv,RS,IS,PS,Hp=!1,gu=[],hi=null,fi=null,mi=null,Yo=new Map,Jo=new Map,ai=[],cM="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 Qy(e,t){switch(e){case"focusin":case"focusout":hi=null;break;case"dragenter":case"dragleave":fi=null;break;case"mouseover":case"mouseout":mi=null;break;case"pointerover":case"pointerout":Yo.delete(t.pointerId);break;case"gotpointercapture":case"lostpointercapture":Jo.delete(t.pointerId)}}function co(e,t,s,r,i,a){return e===null||e.nativeEvent!==a?(e={blockedOn:t,domEventName:s,eventSystemFlags:r,nativeEvent:a,targetContainers:[i]},t!==null&&(t=Oc(t),t!==null&&pv(t)),e):(e.eventSystemFlags|=r,t=e.targetContainers,i!==null&&t.indexOf(i)===-1&&t.push(i),e)}function uM(e,t,s,r,i){switch(t){case"focusin":return hi=co(hi,e,t,s,r,i),!0;case"dragenter":return fi=co(fi,e,t,s,r,i),!0;case"mouseover":return mi=co(mi,e,t,s,r,i),!0;case"pointerover":var a=i.pointerId;return Yo.set(a,co(Yo.get(a)||null,e,t,s,r,i)),!0;case"gotpointercapture":return a=i.pointerId,Jo.set(a,co(Jo.get(a)||null,e,t,s,r,i)),!0}return!1}function MS(e){var t=Xi(e.target);if(t!==null){var s=va(t);if(s!==null){if(t=s.tag,t===13){if(t=bS(s),t!==null){e.blockedOn=t,PS(e.priority,function(){RS(s)});return}}else if(t===3&&s.stateNode.current.memoizedState.isDehydrated){e.blockedOn=s.tag===3?s.stateNode.containerInfo:null;return}}}e.blockedOn=null}function td(e){if(e.blockedOn!==null)return!1;for(var t=e.targetContainers;0<t.length;){var s=Kp(e.domEventName,e.eventSystemFlags,t[0],e.nativeEvent);if(s===null){s=e.nativeEvent;var r=new s.constructor(s.type,s);_p=r,s.target.dispatchEvent(r),_p=null}else return t=Oc(s),t!==null&&pv(t),e.blockedOn=s,!1;t.shift()}return!0}function Xy(e,t,s){td(e)&&s.delete(t)}function dM(){Hp=!1,hi!==null&&td(hi)&&(hi=null),fi!==null&&td(fi)&&(fi=null),mi!==null&&td(mi)&&(mi=null),Yo.forEach(Xy),Jo.forEach(Xy)}function uo(e,t){e.blockedOn===t&&(e.blockedOn=null,Hp||(Hp=!0,rs.unstable_scheduleCallback(rs.unstable_NormalPriority,dM)))}function Qo(e){function t(i){return uo(i,e)}if(0<gu.length){uo(gu[0],e);for(var s=1;s<gu.length;s++){var r=gu[s];r.blockedOn===e&&(r.blockedOn=null)}}for(hi!==null&&uo(hi,e),fi!==null&&uo(fi,e),mi!==null&&uo(mi,e),Yo.forEach(t),Jo.forEach(t),s=0;s<ai.length;s++)r=ai[s],r.blockedOn===e&&(r.blockedOn=null);for(;0<ai.length&&(s=ai[0],s.blockedOn===null);)MS(s),s.blockedOn===null&&ai.shift()}var cl=Jr.ReactCurrentBatchConfig,Rd=!0;function hM(e,t,s,r){var i=xt,a=cl.transition;cl.transition=null;try{xt=1,gv(e,t,s,r)}finally{xt=i,cl.transition=a}}function fM(e,t,s,r){var i=xt,a=cl.transition;cl.transition=null;try{xt=4,gv(e,t,s,r)}finally{xt=i,cl.transition=a}}function gv(e,t,s,r){if(Rd){var i=Kp(e,t,s,r);if(i===null)um(e,t,r,Id,s),Qy(e,r);else if(uM(i,e,t,s,r))r.stopPropagation();else if(Qy(e,r),t&4&&-1<cM.indexOf(e)){for(;i!==null;){var a=Oc(i);if(a!==null&&$S(a),a=Kp(e,t,s,r),a===null&&um(e,t,r,Id,s),a===i)break;i=a}i!==null&&r.stopPropagation()}else um(e,t,r,null,s)}}var Id=null;function Kp(e,t,s,r){if(Id=null,e=hv(r),e=Xi(e),e!==null)if(t=va(e),t===null)e=null;else if(s=t.tag,s===13){if(e=bS(t),e!==null)return e;e=null}else if(s===3){if(t.stateNode.current.memoizedState.isDehydrated)return t.tag===3?t.stateNode.containerInfo:null;e=null}else t!==e&&(e=null);return Id=e,null}function DS(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(eM()){case fv:return 1;case CS:return 4;case Td:case tM:return 16;case ES:return 536870912;default:return 16}default:return 16}}var oi=null,xv=null,nd=null;function OS(){if(nd)return nd;var e,t=xv,s=t.length,r,i="value"in oi?oi.value:oi.textContent,a=i.length;for(e=0;e<s&&t[e]===i[e];e++);var l=s-e;for(r=1;r<=l&&t[s-r]===i[a-r];r++);return nd=i.slice(e,1<r?1-r:void 0)}function sd(e){var t=e.keyCode;return"charCode"in e?(e=e.charCode,e===0&&t===13&&(e=13)):e=t,e===10&&(e=13),32<=e||e===13?e:0}function xu(){return!0}function Zy(){return!1}function os(e){function t(s,r,i,a,l){this._reactName=s,this._targetInst=i,this.type=r,this.nativeEvent=a,this.target=l,this.currentTarget=null;for(var o in e)e.hasOwnProperty(o)&&(s=e[o],this[o]=s?s(a):a[o]);return this.isDefaultPrevented=(a.defaultPrevented!=null?a.defaultPrevented:a.returnValue===!1)?xu:Zy,this.isPropagationStopped=Zy,this}return Mt(t.prototype,{preventDefault:function(){this.defaultPrevented=!0;var s=this.nativeEvent;s&&(s.preventDefault?s.preventDefault():typeof s.returnValue!="unknown"&&(s.returnValue=!1),this.isDefaultPrevented=xu)},stopPropagation:function(){var s=this.nativeEvent;s&&(s.stopPropagation?s.stopPropagation():typeof s.cancelBubble!="unknown"&&(s.cancelBubble=!0),this.isPropagationStopped=xu)},persist:function(){},isPersistent:xu}),t}var _l={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},vv=os(_l),Dc=Mt({},_l,{view:0,detail:0}),mM=os(Dc),tm,nm,ho,Ih=Mt({},Dc,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:jv,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!==ho&&(ho&&e.type==="mousemove"?(tm=e.screenX-ho.screenX,nm=e.screenY-ho.screenY):nm=tm=0,ho=e),tm)},movementY:function(e){return"movementY"in e?e.movementY:nm}}),eb=os(Ih),pM=Mt({},Ih,{dataTransfer:0}),gM=os(pM),xM=Mt({},Dc,{relatedTarget:0}),sm=os(xM),vM=Mt({},_l,{animationName:0,elapsedTime:0,pseudoElement:0}),jM=os(vM),wM=Mt({},_l,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),yM=os(wM),bM=Mt({},_l,{data:0}),tb=os(bM),kM={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},NM={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"},SM={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function CM(e){var t=this.nativeEvent;return t.getModifierState?t.getModifierState(e):(e=SM[e])?!!t[e]:!1}function jv(){return CM}var EM=Mt({},Dc,{key:function(e){if(e.key){var t=kM[e.key]||e.key;if(t!=="Unidentified")return t}return e.type==="keypress"?(e=sd(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?NM[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:jv,charCode:function(e){return e.type==="keypress"?sd(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?sd(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),AM=os(EM),TM=Mt({},Ih,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),nb=os(TM),$M=Mt({},Dc,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:jv}),RM=os($M),IM=Mt({},_l,{propertyName:0,elapsedTime:0,pseudoElement:0}),PM=os(IM),MM=Mt({},Ih,{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}),DM=os(MM),OM=[9,13,27,32],wv=Br&&"CompositionEvent"in window,Po=null;Br&&"documentMode"in document&&(Po=document.documentMode);var LM=Br&&"TextEvent"in window&&!Po,LS=Br&&(!wv||Po&&8<Po&&11>=Po),sb=" ",rb=!1;function FS(e,t){switch(e){case"keyup":return OM.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function _S(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Va=!1;function FM(e,t){switch(e){case"compositionend":return _S(t);case"keypress":return t.which!==32?null:(rb=!0,sb);case"textInput":return e=t.data,e===sb&&rb?null:e;default:return null}}function _M(e,t){if(Va)return e==="compositionend"||!wv&&FS(e,t)?(e=OS(),nd=xv=oi=null,Va=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1<t.char.length)return t.char;if(t.which)return String.fromCharCode(t.which)}return null;case"compositionend":return LS&&t.locale!=="ko"?null:t.data;default:return null}}var zM={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 ib(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t==="input"?!!zM[e.type]:t==="textarea"}function zS(e,t,s,r){xS(r),t=Pd(t,"onChange"),0<t.length&&(s=new vv("onChange","change",null,s,r),e.push({event:s,listeners:t}))}var Mo=null,Xo=null;function UM(e){QS(e,0)}function Ph(e){var t=Ya(e);if(uS(t))return e}function BM(e,t){if(e==="change")return t}var US=!1;if(Br){var rm;if(Br){var im="oninput"in document;if(!im){var ab=document.createElement("div");ab.setAttribute("oninput","return;"),im=typeof ab.oninput=="function"}rm=im}else rm=!1;US=rm&&(!document.documentMode||9<document.documentMode)}function lb(){Mo&&(Mo.detachEvent("onpropertychange",BS),Xo=Mo=null)}function BS(e){if(e.propertyName==="value"&&Ph(Xo)){var t=[];zS(t,Xo,e,hv(e)),yS(UM,t)}}function WM(e,t,s){e==="focusin"?(lb(),Mo=t,Xo=s,Mo.attachEvent("onpropertychange",BS)):e==="focusout"&&lb()}function HM(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return Ph(Xo)}function KM(e,t){if(e==="click")return Ph(t)}function VM(e,t){if(e==="input"||e==="change")return Ph(t)}function GM(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var Us=typeof Object.is=="function"?Object.is:GM;function Zo(e,t){if(Us(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;var s=Object.keys(e),r=Object.keys(t);if(s.length!==r.length)return!1;for(r=0;r<s.length;r++){var i=s[r];if(!Ep.call(t,i)||!Us(e[i],t[i]))return!1}return!0}function ob(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function cb(e,t){var s=ob(e);e=0;for(var r;s;){if(s.nodeType===3){if(r=e+s.textContent.length,e<=t&&r>=t)return{node:s,offset:t-e};e=r}e:{for(;s;){if(s.nextSibling){s=s.nextSibling;break e}s=s.parentNode}s=void 0}s=ob(s)}}function WS(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?WS(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function HS(){for(var e=window,t=Cd();t instanceof e.HTMLIFrameElement;){try{var s=typeof t.contentWindow.location.href=="string"}catch{s=!1}if(s)e=t.contentWindow;else break;t=Cd(e.document)}return t}function yv(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||t==="textarea"||e.contentEditable==="true")}function qM(e){var t=HS(),s=e.focusedElem,r=e.selectionRange;if(t!==s&&s&&s.ownerDocument&&WS(s.ownerDocument.documentElement,s)){if(r!==null&&yv(s)){if(t=r.start,e=r.end,e===void 0&&(e=t),"selectionStart"in s)s.selectionStart=t,s.selectionEnd=Math.min(e,s.value.length);else if(e=(t=s.ownerDocument||document)&&t.defaultView||window,e.getSelection){e=e.getSelection();var i=s.textContent.length,a=Math.min(r.start,i);r=r.end===void 0?a:Math.min(r.end,i),!e.extend&&a>r&&(i=r,r=a,a=i),i=cb(s,a);var l=cb(s,r);i&&l&&(e.rangeCount!==1||e.anchorNode!==i.node||e.anchorOffset!==i.offset||e.focusNode!==l.node||e.focusOffset!==l.offset)&&(t=t.createRange(),t.setStart(i.node,i.offset),e.removeAllRanges(),a>r?(e.addRange(t),e.extend(l.node,l.offset)):(t.setEnd(l.node,l.offset),e.addRange(t)))}}for(t=[],e=s;e=e.parentNode;)e.nodeType===1&&t.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof s.focus=="function"&&s.focus(),s=0;s<t.length;s++)e=t[s],e.element.scrollLeft=e.left,e.element.scrollTop=e.top}}var YM=Br&&"documentMode"in document&&11>=document.documentMode,Ga=null,Vp=null,Do=null,Gp=!1;function ub(e,t,s){var r=s.window===s?s.document:s.nodeType===9?s:s.ownerDocument;Gp||Ga==null||Ga!==Cd(r)||(r=Ga,"selectionStart"in r&&yv(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}),Do&&Zo(Do,r)||(Do=r,r=Pd(Vp,"onSelect"),0<r.length&&(t=new vv("onSelect","select",null,t,s),e.push({event:t,listeners:r}),t.target=Ga)))}function vu(e,t){var s={};return s[e.toLowerCase()]=t.toLowerCase(),s["Webkit"+e]="webkit"+t,s["Moz"+e]="moz"+t,s}var qa={animationend:vu("Animation","AnimationEnd"),animationiteration:vu("Animation","AnimationIteration"),animationstart:vu("Animation","AnimationStart"),transitionend:vu("Transition","TransitionEnd")},am={},KS={};Br&&(KS=document.createElement("div").style,"AnimationEvent"in window||(delete qa.animationend.animation,delete qa.animationiteration.animation,delete qa.animationstart.animation),"TransitionEvent"in window||delete qa.transitionend.transition);function Mh(e){if(am[e])return am[e];if(!qa[e])return e;var t=qa[e],s;for(s in t)if(t.hasOwnProperty(s)&&s in KS)return am[e]=t[s];return e}var VS=Mh("animationend"),GS=Mh("animationiteration"),qS=Mh("animationstart"),YS=Mh("transitionend"),JS=new Map,db="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 Ii(e,t){JS.set(e,t),xa(t,[e])}for(var lm=0;lm<db.length;lm++){var om=db[lm],JM=om.toLowerCase(),QM=om[0].toUpperCase()+om.slice(1);Ii(JM,"on"+QM)}Ii(VS,"onAnimationEnd");Ii(GS,"onAnimationIteration");Ii(qS,"onAnimationStart");Ii("dblclick","onDoubleClick");Ii("focusin","onFocus");Ii("focusout","onBlur");Ii(YS,"onTransitionEnd");vl("onMouseEnter",["mouseout","mouseover"]);vl("onMouseLeave",["mouseout","mouseover"]);vl("onPointerEnter",["pointerout","pointerover"]);vl("onPointerLeave",["pointerout","pointerover"]);xa("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));xa("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));xa("onBeforeInput",["compositionend","keypress","textInput","paste"]);xa("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));xa("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));xa("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var Co="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(" "),XM=new Set("cancel close invalid load scroll toggle".split(" ").concat(Co));function hb(e,t,s){var r=e.type||"unknown-event";e.currentTarget=s,JP(r,t,void 0,e),e.currentTarget=null}function QS(e,t){t=(t&4)!==0;for(var s=0;s<e.length;s++){var r=e[s],i=r.event;r=r.listeners;e:{var a=void 0;if(t)for(var l=r.length-1;0<=l;l--){var o=r[l],c=o.instance,u=o.currentTarget;if(o=o.listener,c!==a&&i.isPropagationStopped())break e;hb(i,o,u),a=c}else for(l=0;l<r.length;l++){if(o=r[l],c=o.instance,u=o.currentTarget,o=o.listener,c!==a&&i.isPropagationStopped())break e;hb(i,o,u),a=c}}}if(Ad)throw e=Bp,Ad=!1,Bp=null,e}function Ct(e,t){var s=t[Xp];s===void 0&&(s=t[Xp]=new Set);var r=e+"__bubble";s.has(r)||(XS(t,e,2,!1),s.add(r))}function cm(e,t,s){var r=0;t&&(r|=4),XS(s,e,r,t)}var ju="_reactListening"+Math.random().toString(36).slice(2);function ec(e){if(!e[ju]){e[ju]=!0,iS.forEach(function(s){s!=="selectionchange"&&(XM.has(s)||cm(s,!1,e),cm(s,!0,e))});var t=e.nodeType===9?e:e.ownerDocument;t===null||t[ju]||(t[ju]=!0,cm("selectionchange",!1,t))}}function XS(e,t,s,r){switch(DS(t)){case 1:var i=hM;break;case 4:i=fM;break;default:i=gv}s=i.bind(null,t,s,e),i=void 0,!Up||t!=="touchstart"&&t!=="touchmove"&&t!=="wheel"||(i=!0),r?i!==void 0?e.addEventListener(t,s,{capture:!0,passive:i}):e.addEventListener(t,s,!0):i!==void 0?e.addEventListener(t,s,{passive:i}):e.addEventListener(t,s,!1)}function um(e,t,s,r,i){var a=r;if(!(t&1)&&!(t&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===i||o.nodeType===8&&o.parentNode===i)break;if(l===4)for(l=r.return;l!==null;){var c=l.tag;if((c===3||c===4)&&(c=l.stateNode.containerInfo,c===i||c.nodeType===8&&c.parentNode===i))return;l=l.return}for(;o!==null;){if(l=Xi(o),l===null)return;if(c=l.tag,c===5||c===6){r=a=l;continue e}o=o.parentNode}}r=r.return}yS(function(){var u=a,h=hv(s),f=[];e:{var m=JS.get(e);if(m!==void 0){var p=vv,g=e;switch(e){case"keypress":if(sd(s)===0)break e;case"keydown":case"keyup":p=AM;break;case"focusin":g="focus",p=sm;break;case"focusout":g="blur",p=sm;break;case"beforeblur":case"afterblur":p=sm;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=eb;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":p=gM;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":p=RM;break;case VS:case GS:case qS:p=jM;break;case YS:p=PM;break;case"scroll":p=mM;break;case"wheel":p=DM;break;case"copy":case"cut":case"paste":p=yM;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":p=nb}var v=(t&4)!==0,b=!v&&e==="scroll",j=v?m!==null?m+"Capture":null:m;v=[];for(var x=u,w;x!==null;){w=x;var y=w.stateNode;if(w.tag===5&&y!==null&&(w=y,j!==null&&(y=qo(x,j),y!=null&&v.push(tc(x,y,w)))),b)break;x=x.return}0<v.length&&(m=new p(m,g,null,s,h),f.push({event:m,listeners:v}))}}if(!(t&7)){e:{if(m=e==="mouseover"||e==="pointerover",p=e==="mouseout"||e==="pointerout",m&&s!==_p&&(g=s.relatedTarget||s.fromElement)&&(Xi(g)||g[Wr]))break e;if((p||m)&&(m=h.window===h?h:(m=h.ownerDocument)?m.defaultView||m.parentWindow:window,p?(g=s.relatedTarget||s.toElement,p=u,g=g?Xi(g):null,g!==null&&(b=va(g),g!==b||g.tag!==5&&g.tag!==6)&&(g=null)):(p=null,g=u),p!==g)){if(v=eb,y="onMouseLeave",j="onMouseEnter",x="mouse",(e==="pointerout"||e==="pointerover")&&(v=nb,y="onPointerLeave",j="onPointerEnter",x="pointer"),b=p==null?m:Ya(p),w=g==null?m:Ya(g),m=new v(y,x+"leave",p,s,h),m.target=b,m.relatedTarget=w,y=null,Xi(h)===u&&(v=new v(j,x+"enter",g,s,h),v.target=w,v.relatedTarget=b,y=v),b=y,p&&g)t:{for(v=p,j=g,x=0,w=v;w;w=Pa(w))x++;for(w=0,y=j;y;y=Pa(y))w++;for(;0<x-w;)v=Pa(v),x--;for(;0<w-x;)j=Pa(j),w--;for(;x--;){if(v===j||j!==null&&v===j.alternate)break t;v=Pa(v),j=Pa(j)}v=null}else v=null;p!==null&&fb(f,m,p,v,!1),g!==null&&b!==null&&fb(f,b,g,v,!0)}}e:{if(m=u?Ya(u):window,p=m.nodeName&&m.nodeName.toLowerCase(),p==="select"||p==="input"&&m.type==="file")var k=BM;else if(ib(m))if(US)k=VM;else{k=HM;var N=WM}else(p=m.nodeName)&&p.toLowerCase()==="input"&&(m.type==="checkbox"||m.type==="radio")&&(k=KM);if(k&&(k=k(e,u))){zS(f,k,s,h);break e}N&&N(e,m,u),e==="focusout"&&(N=m._wrapperState)&&N.controlled&&m.type==="number"&&Mp(m,"number",m.value)}switch(N=u?Ya(u):window,e){case"focusin":(ib(N)||N.contentEditable==="true")&&(Ga=N,Vp=u,Do=null);break;case"focusout":Do=Vp=Ga=null;break;case"mousedown":Gp=!0;break;case"contextmenu":case"mouseup":case"dragend":Gp=!1,ub(f,s,h);break;case"selectionchange":if(YM)break;case"keydown":case"keyup":ub(f,s,h)}var S;if(wv)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 Va?FS(e,s)&&(C="onCompositionEnd"):e==="keydown"&&s.keyCode===229&&(C="onCompositionStart");C&&(LS&&s.locale!=="ko"&&(Va||C!=="onCompositionStart"?C==="onCompositionEnd"&&Va&&(S=OS()):(oi=h,xv="value"in oi?oi.value:oi.textContent,Va=!0)),N=Pd(u,C),0<N.length&&(C=new tb(C,e,null,s,h),f.push({event:C,listeners:N}),S?C.data=S:(S=_S(s),S!==null&&(C.data=S)))),(S=LM?FM(e,s):_M(e,s))&&(u=Pd(u,"onBeforeInput"),0<u.length&&(h=new tb("onBeforeInput","beforeinput",null,s,h),f.push({event:h,listeners:u}),h.data=S))}QS(f,t)})}function tc(e,t,s){return{instance:e,listener:t,currentTarget:s}}function Pd(e,t){for(var s=t+"Capture",r=[];e!==null;){var i=e,a=i.stateNode;i.tag===5&&a!==null&&(i=a,a=qo(e,s),a!=null&&r.unshift(tc(e,a,i)),a=qo(e,t),a!=null&&r.push(tc(e,a,i))),e=e.return}return r}function Pa(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function fb(e,t,s,r,i){for(var a=t._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,i?(c=qo(s,a),c!=null&&l.unshift(tc(s,c,o))):i||(c=qo(s,a),c!=null&&l.push(tc(s,c,o)))),s=s.return}l.length!==0&&e.push({event:t,listeners:l})}var ZM=/\r\n?/g,e2=/\u0000|\uFFFD/g;function mb(e){return(typeof e=="string"?e:""+e).replace(ZM,`
38
+ `).replace(e2,"")}function wu(e,t,s){if(t=mb(t),mb(e)!==t&&s)throw Error(xe(425))}function Md(){}var qp=null,Yp=null;function Jp(e,t){return e==="textarea"||e==="noscript"||typeof t.children=="string"||typeof t.children=="number"||typeof t.dangerouslySetInnerHTML=="object"&&t.dangerouslySetInnerHTML!==null&&t.dangerouslySetInnerHTML.__html!=null}var Qp=typeof setTimeout=="function"?setTimeout:void 0,t2=typeof clearTimeout=="function"?clearTimeout:void 0,pb=typeof Promise=="function"?Promise:void 0,n2=typeof queueMicrotask=="function"?queueMicrotask:typeof pb<"u"?function(e){return pb.resolve(null).then(e).catch(s2)}:Qp;function s2(e){setTimeout(function(){throw e})}function dm(e,t){var s=t,r=0;do{var i=s.nextSibling;if(e.removeChild(s),i&&i.nodeType===8)if(s=i.data,s==="/$"){if(r===0){e.removeChild(i),Qo(t);return}r--}else s!=="$"&&s!=="$?"&&s!=="$!"||r++;s=i}while(s);Qo(t)}function pi(e){for(;e!=null;e=e.nextSibling){var t=e.nodeType;if(t===1||t===3)break;if(t===8){if(t=e.data,t==="$"||t==="$!"||t==="$?")break;if(t==="/$")return null}}return e}function gb(e){e=e.previousSibling;for(var t=0;e;){if(e.nodeType===8){var s=e.data;if(s==="$"||s==="$!"||s==="$?"){if(t===0)return e;t--}else s==="/$"&&t++}e=e.previousSibling}return null}var zl=Math.random().toString(36).slice(2),lr="__reactFiber$"+zl,nc="__reactProps$"+zl,Wr="__reactContainer$"+zl,Xp="__reactEvents$"+zl,r2="__reactListeners$"+zl,i2="__reactHandles$"+zl;function Xi(e){var t=e[lr];if(t)return t;for(var s=e.parentNode;s;){if(t=s[Wr]||s[lr]){if(s=t.alternate,t.child!==null||s!==null&&s.child!==null)for(e=gb(e);e!==null;){if(s=e[lr])return s;e=gb(e)}return t}e=s,s=e.parentNode}return null}function Oc(e){return e=e[lr]||e[Wr],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function Ya(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(xe(33))}function Dh(e){return e[nc]||null}var Zp=[],Ja=-1;function Pi(e){return{current:e}}function At(e){0>Ja||(e.current=Zp[Ja],Zp[Ja]=null,Ja--)}function St(e,t){Ja++,Zp[Ja]=e.current,e.current=t}var Ni={},Nn=Pi(Ni),Wn=Pi(!1),la=Ni;function jl(e,t){var s=e.type.contextTypes;if(!s)return Ni;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var i={},a;for(a in s)i[a]=t[a];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=i),i}function Hn(e){return e=e.childContextTypes,e!=null}function Dd(){At(Wn),At(Nn)}function xb(e,t,s){if(Nn.current!==Ni)throw Error(xe(168));St(Nn,t),St(Wn,s)}function ZS(e,t,s){var r=e.stateNode;if(t=t.childContextTypes,typeof r.getChildContext!="function")return s;r=r.getChildContext();for(var i in r)if(!(i in t))throw Error(xe(108,WP(e)||"Unknown",i));return Mt({},s,r)}function Od(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Ni,la=Nn.current,St(Nn,e),St(Wn,Wn.current),!0}function vb(e,t,s){var r=e.stateNode;if(!r)throw Error(xe(169));s?(e=ZS(e,t,la),r.__reactInternalMemoizedMergedChildContext=e,At(Wn),At(Nn),St(Nn,e)):At(Wn),St(Wn,s)}var Tr=null,Oh=!1,hm=!1;function eC(e){Tr===null?Tr=[e]:Tr.push(e)}function a2(e){Oh=!0,eC(e)}function Mi(){if(!hm&&Tr!==null){hm=!0;var e=0,t=xt;try{var s=Tr;for(xt=1;e<s.length;e++){var r=s[e];do r=r(!0);while(r!==null)}Tr=null,Oh=!1}catch(i){throw Tr!==null&&(Tr=Tr.slice(e+1)),SS(fv,Mi),i}finally{xt=t,hm=!1}}return null}var Qa=[],Xa=0,Ld=null,Fd=0,xs=[],vs=0,oa=null,Pr=1,Mr="";function Gi(e,t){Qa[Xa++]=Fd,Qa[Xa++]=Ld,Ld=e,Fd=t}function tC(e,t,s){xs[vs++]=Pr,xs[vs++]=Mr,xs[vs++]=oa,oa=e;var r=Pr;e=Mr;var i=32-Ls(r)-1;r&=~(1<<i),s+=1;var a=32-Ls(t)+i;if(30<a){var l=i-i%5;a=(r&(1<<l)-1).toString(32),r>>=l,i-=l,Pr=1<<32-Ls(t)+i|s<<i|r,Mr=a+e}else Pr=1<<a|s<<i|r,Mr=e}function bv(e){e.return!==null&&(Gi(e,1),tC(e,1,0))}function kv(e){for(;e===Ld;)Ld=Qa[--Xa],Qa[Xa]=null,Fd=Qa[--Xa],Qa[Xa]=null;for(;e===oa;)oa=xs[--vs],xs[vs]=null,Mr=xs[--vs],xs[vs]=null,Pr=xs[--vs],xs[vs]=null}var ns=null,es=null,$t=!1,Ms=null;function nC(e,t){var s=bs(5,null,null,0);s.elementType="DELETED",s.stateNode=t,s.return=e,t=e.deletions,t===null?(e.deletions=[s],e.flags|=16):t.push(s)}function jb(e,t){switch(e.tag){case 5:var s=e.type;return t=t.nodeType!==1||s.toLowerCase()!==t.nodeName.toLowerCase()?null:t,t!==null?(e.stateNode=t,ns=e,es=pi(t.firstChild),!0):!1;case 6:return t=e.pendingProps===""||t.nodeType!==3?null:t,t!==null?(e.stateNode=t,ns=e,es=null,!0):!1;case 13:return t=t.nodeType!==8?null:t,t!==null?(s=oa!==null?{id:Pr,overflow:Mr}:null,e.memoizedState={dehydrated:t,treeContext:s,retryLane:1073741824},s=bs(18,null,null,0),s.stateNode=t,s.return=e,e.child=s,ns=e,es=null,!0):!1;default:return!1}}function eg(e){return(e.mode&1)!==0&&(e.flags&128)===0}function tg(e){if($t){var t=es;if(t){var s=t;if(!jb(e,t)){if(eg(e))throw Error(xe(418));t=pi(s.nextSibling);var r=ns;t&&jb(e,t)?nC(r,s):(e.flags=e.flags&-4097|2,$t=!1,ns=e)}}else{if(eg(e))throw Error(xe(418));e.flags=e.flags&-4097|2,$t=!1,ns=e}}}function wb(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;ns=e}function yu(e){if(e!==ns)return!1;if(!$t)return wb(e),$t=!0,!1;var t;if((t=e.tag!==3)&&!(t=e.tag!==5)&&(t=e.type,t=t!=="head"&&t!=="body"&&!Jp(e.type,e.memoizedProps)),t&&(t=es)){if(eg(e))throw sC(),Error(xe(418));for(;t;)nC(e,t),t=pi(t.nextSibling)}if(wb(e),e.tag===13){if(e=e.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(xe(317));e:{for(e=e.nextSibling,t=0;e;){if(e.nodeType===8){var s=e.data;if(s==="/$"){if(t===0){es=pi(e.nextSibling);break e}t--}else s!=="$"&&s!=="$!"&&s!=="$?"||t++}e=e.nextSibling}es=null}}else es=ns?pi(e.stateNode.nextSibling):null;return!0}function sC(){for(var e=es;e;)e=pi(e.nextSibling)}function wl(){es=ns=null,$t=!1}function Nv(e){Ms===null?Ms=[e]:Ms.push(e)}var l2=Jr.ReactCurrentBatchConfig;function fo(e,t,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(xe(309));var r=s.stateNode}if(!r)throw Error(xe(147,e));var i=r,a=""+e;return t!==null&&t.ref!==null&&typeof t.ref=="function"&&t.ref._stringRef===a?t.ref:(t=function(l){var o=i.refs;l===null?delete o[a]:o[a]=l},t._stringRef=a,t)}if(typeof e!="string")throw Error(xe(284));if(!s._owner)throw Error(xe(290,e))}return e}function bu(e,t){throw e=Object.prototype.toString.call(t),Error(xe(31,e==="[object Object]"?"object with keys {"+Object.keys(t).join(", ")+"}":e))}function yb(e){var t=e._init;return t(e._payload)}function rC(e){function t(j,x){if(e){var w=j.deletions;w===null?(j.deletions=[x],j.flags|=16):w.push(x)}}function s(j,x){if(!e)return null;for(;x!==null;)t(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 i(j,x){return j=ji(j,x),j.index=0,j.sibling=null,j}function a(j,x,w){return j.index=w,e?(w=j.alternate,w!==null?(w=w.index,w<x?(j.flags|=2,x):w):(j.flags|=2,x)):(j.flags|=1048576,x)}function l(j){return e&&j.alternate===null&&(j.flags|=2),j}function o(j,x,w,y){return x===null||x.tag!==6?(x=jm(w,j.mode,y),x.return=j,x):(x=i(x,w),x.return=j,x)}function c(j,x,w,y){var k=w.type;return k===Ka?h(j,x,w.props.children,y,w.key):x!==null&&(x.elementType===k||typeof k=="object"&&k!==null&&k.$$typeof===ri&&yb(k)===x.type)?(y=i(x,w.props),y.ref=fo(j,x,w),y.return=j,y):(y=ud(w.type,w.key,w.props,null,j.mode,y),y.ref=fo(j,x,w),y.return=j,y)}function u(j,x,w,y){return x===null||x.tag!==4||x.stateNode.containerInfo!==w.containerInfo||x.stateNode.implementation!==w.implementation?(x=wm(w,j.mode,y),x.return=j,x):(x=i(x,w.children||[]),x.return=j,x)}function h(j,x,w,y,k){return x===null||x.tag!==7?(x=ra(w,j.mode,y,k),x.return=j,x):(x=i(x,w),x.return=j,x)}function f(j,x,w){if(typeof x=="string"&&x!==""||typeof x=="number")return x=jm(""+x,j.mode,w),x.return=j,x;if(typeof x=="object"&&x!==null){switch(x.$$typeof){case du:return w=ud(x.type,x.key,x.props,null,j.mode,w),w.ref=fo(j,null,x),w.return=j,w;case Ha:return x=wm(x,j.mode,w),x.return=j,x;case ri:var y=x._init;return f(j,y(x._payload),w)}if(No(x)||lo(x))return x=ra(x,j.mode,w,null),x.return=j,x;bu(j,x)}return null}function m(j,x,w,y){var k=x!==null?x.key:null;if(typeof w=="string"&&w!==""||typeof w=="number")return k!==null?null:o(j,x,""+w,y);if(typeof w=="object"&&w!==null){switch(w.$$typeof){case du:return w.key===k?c(j,x,w,y):null;case Ha:return w.key===k?u(j,x,w,y):null;case ri:return k=w._init,m(j,x,k(w._payload),y)}if(No(w)||lo(w))return k!==null?null:h(j,x,w,y,null);bu(j,w)}return null}function p(j,x,w,y,k){if(typeof y=="string"&&y!==""||typeof y=="number")return j=j.get(w)||null,o(x,j,""+y,k);if(typeof y=="object"&&y!==null){switch(y.$$typeof){case du:return j=j.get(y.key===null?w:y.key)||null,c(x,j,y,k);case Ha:return j=j.get(y.key===null?w:y.key)||null,u(x,j,y,k);case ri:var N=y._init;return p(j,x,w,N(y._payload),k)}if(No(y)||lo(y))return j=j.get(w)||null,h(x,j,y,k,null);bu(x,y)}return null}function g(j,x,w,y){for(var k=null,N=null,S=x,C=x=0,E=null;S!==null&&C<w.length;C++){S.index>C?(E=S,S=null):E=S.sibling;var R=m(j,S,w[C],y);if(R===null){S===null&&(S=E);break}e&&S&&R.alternate===null&&t(j,S),x=a(R,x,C),N===null?k=R:N.sibling=R,N=R,S=E}if(C===w.length)return s(j,S),$t&&Gi(j,C),k;if(S===null){for(;C<w.length;C++)S=f(j,w[C],y),S!==null&&(x=a(S,x,C),N===null?k=S:N.sibling=S,N=S);return $t&&Gi(j,C),k}for(S=r(j,S);C<w.length;C++)E=p(S,j,C,w[C],y),E!==null&&(e&&E.alternate!==null&&S.delete(E.key===null?C:E.key),x=a(E,x,C),N===null?k=E:N.sibling=E,N=E);return e&&S.forEach(function(I){return t(j,I)}),$t&&Gi(j,C),k}function v(j,x,w,y){var k=lo(w);if(typeof k!="function")throw Error(xe(150));if(w=k.call(w),w==null)throw Error(xe(151));for(var N=k=null,S=x,C=x=0,E=null,R=w.next();S!==null&&!R.done;C++,R=w.next()){S.index>C?(E=S,S=null):E=S.sibling;var I=m(j,S,R.value,y);if(I===null){S===null&&(S=E);break}e&&S&&I.alternate===null&&t(j,S),x=a(I,x,C),N===null?k=I:N.sibling=I,N=I,S=E}if(R.done)return s(j,S),$t&&Gi(j,C),k;if(S===null){for(;!R.done;C++,R=w.next())R=f(j,R.value,y),R!==null&&(x=a(R,x,C),N===null?k=R:N.sibling=R,N=R);return $t&&Gi(j,C),k}for(S=r(j,S);!R.done;C++,R=w.next())R=p(S,j,C,R.value,y),R!==null&&(e&&R.alternate!==null&&S.delete(R.key===null?C:R.key),x=a(R,x,C),N===null?k=R:N.sibling=R,N=R);return e&&S.forEach(function(L){return t(j,L)}),$t&&Gi(j,C),k}function b(j,x,w,y){if(typeof w=="object"&&w!==null&&w.type===Ka&&w.key===null&&(w=w.props.children),typeof w=="object"&&w!==null){switch(w.$$typeof){case du:e:{for(var k=w.key,N=x;N!==null;){if(N.key===k){if(k=w.type,k===Ka){if(N.tag===7){s(j,N.sibling),x=i(N,w.props.children),x.return=j,j=x;break e}}else if(N.elementType===k||typeof k=="object"&&k!==null&&k.$$typeof===ri&&yb(k)===N.type){s(j,N.sibling),x=i(N,w.props),x.ref=fo(j,N,w),x.return=j,j=x;break e}s(j,N);break}else t(j,N);N=N.sibling}w.type===Ka?(x=ra(w.props.children,j.mode,y,w.key),x.return=j,j=x):(y=ud(w.type,w.key,w.props,null,j.mode,y),y.ref=fo(j,x,w),y.return=j,j=y)}return l(j);case Ha:e:{for(N=w.key;x!==null;){if(x.key===N)if(x.tag===4&&x.stateNode.containerInfo===w.containerInfo&&x.stateNode.implementation===w.implementation){s(j,x.sibling),x=i(x,w.children||[]),x.return=j,j=x;break e}else{s(j,x);break}else t(j,x);x=x.sibling}x=wm(w,j.mode,y),x.return=j,j=x}return l(j);case ri:return N=w._init,b(j,x,N(w._payload),y)}if(No(w))return g(j,x,w,y);if(lo(w))return v(j,x,w,y);bu(j,w)}return typeof w=="string"&&w!==""||typeof w=="number"?(w=""+w,x!==null&&x.tag===6?(s(j,x.sibling),x=i(x,w),x.return=j,j=x):(s(j,x),x=jm(w,j.mode,y),x.return=j,j=x),l(j)):s(j,x)}return b}var yl=rC(!0),iC=rC(!1),_d=Pi(null),zd=null,Za=null,Sv=null;function Cv(){Sv=Za=zd=null}function Ev(e){var t=_d.current;At(_d),e._currentValue=t}function ng(e,t,s){for(;e!==null;){var r=e.alternate;if((e.childLanes&t)!==t?(e.childLanes|=t,r!==null&&(r.childLanes|=t)):r!==null&&(r.childLanes&t)!==t&&(r.childLanes|=t),e===s)break;e=e.return}}function ul(e,t){zd=e,Sv=Za=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(Un=!0),e.firstContext=null)}function Ss(e){var t=e._currentValue;if(Sv!==e)if(e={context:e,memoizedValue:t,next:null},Za===null){if(zd===null)throw Error(xe(308));Za=e,zd.dependencies={lanes:0,firstContext:e}}else Za=Za.next=e;return t}var Zi=null;function Av(e){Zi===null?Zi=[e]:Zi.push(e)}function aC(e,t,s,r){var i=t.interleaved;return i===null?(s.next=s,Av(t)):(s.next=i.next,i.next=s),t.interleaved=s,Hr(e,r)}function Hr(e,t){e.lanes|=t;var s=e.alternate;for(s!==null&&(s.lanes|=t),s=e,e=e.return;e!==null;)e.childLanes|=t,s=e.alternate,s!==null&&(s.childLanes|=t),s=e,e=e.return;return s.tag===3?s.stateNode:null}var ii=!1;function Tv(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function lC(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function Or(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function gi(e,t,s){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,lt&2){var i=r.pending;return i===null?t.next=t:(t.next=i.next,i.next=t),r.pending=t,Hr(e,s)}return i=r.interleaved,i===null?(t.next=t,Av(r)):(t.next=i.next,i.next=t),r.interleaved=t,Hr(e,s)}function rd(e,t,s){if(t=t.updateQueue,t!==null&&(t=t.shared,(s&4194240)!==0)){var r=t.lanes;r&=e.pendingLanes,s|=r,t.lanes=s,mv(e,s)}}function bb(e,t){var s=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,s===r)){var i=null,a=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};a===null?i=a=l:a=a.next=l,s=s.next}while(s!==null);a===null?i=a=t:a=a.next=t}else i=a=t;s={baseState:r.baseState,firstBaseUpdate:i,lastBaseUpdate:a,shared:r.shared,effects:r.effects},e.updateQueue=s;return}e=s.lastBaseUpdate,e===null?s.firstBaseUpdate=t:e.next=t,s.lastBaseUpdate=t}function Ud(e,t,s,r){var i=e.updateQueue;ii=!1;var a=i.firstBaseUpdate,l=i.lastBaseUpdate,o=i.shared.pending;if(o!==null){i.shared.pending=null;var c=o,u=c.next;c.next=null,l===null?a=u:l.next=u,l=c;var h=e.alternate;h!==null&&(h=h.updateQueue,o=h.lastBaseUpdate,o!==l&&(o===null?h.firstBaseUpdate=u:o.next=u,h.lastBaseUpdate=c))}if(a!==null){var f=i.baseState;l=0,h=u=c=null,o=a;do{var m=o.lane,p=o.eventTime;if((r&m)===m){h!==null&&(h=h.next={eventTime:p,lane:0,tag:o.tag,payload:o.payload,callback:o.callback,next:null});e:{var g=e,v=o;switch(m=t,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=Mt({},f,m);break e;case 2:ii=!0}}o.callback!==null&&o.lane!==0&&(e.flags|=64,m=i.effects,m===null?i.effects=[o]:m.push(o))}else p={eventTime:p,lane:m,tag:o.tag,payload:o.payload,callback:o.callback,next:null},h===null?(u=h=p,c=f):h=h.next=p,l|=m;if(o=o.next,o===null){if(o=i.shared.pending,o===null)break;m=o,o=m.next,m.next=null,i.lastBaseUpdate=m,i.shared.pending=null}}while(!0);if(h===null&&(c=f),i.baseState=c,i.firstBaseUpdate=u,i.lastBaseUpdate=h,t=i.shared.interleaved,t!==null){i=t;do l|=i.lane,i=i.next;while(i!==t)}else a===null&&(i.shared.lanes=0);ua|=l,e.lanes=l,e.memoizedState=f}}function kb(e,t,s){if(e=t.effects,t.effects=null,e!==null)for(t=0;t<e.length;t++){var r=e[t],i=r.callback;if(i!==null){if(r.callback=null,r=s,typeof i!="function")throw Error(xe(191,i));i.call(r)}}}var Lc={},hr=Pi(Lc),sc=Pi(Lc),rc=Pi(Lc);function ea(e){if(e===Lc)throw Error(xe(174));return e}function $v(e,t){switch(St(rc,t),St(sc,e),St(hr,Lc),e=t.nodeType,e){case 9:case 11:t=(t=t.documentElement)?t.namespaceURI:Op(null,"");break;default:e=e===8?t.parentNode:t,t=e.namespaceURI||null,e=e.tagName,t=Op(t,e)}At(hr),St(hr,t)}function bl(){At(hr),At(sc),At(rc)}function oC(e){ea(rc.current);var t=ea(hr.current),s=Op(t,e.type);t!==s&&(St(sc,e),St(hr,s))}function Rv(e){sc.current===e&&(At(hr),At(sc))}var Rt=Pi(0);function Bd(e){for(var t=e;t!==null;){if(t.tag===13){var s=t.memoizedState;if(s!==null&&(s=s.dehydrated,s===null||s.data==="$?"||s.data==="$!"))return t}else if(t.tag===19&&t.memoizedProps.revealOrder!==void 0){if(t.flags&128)return t}else if(t.child!==null){t.child.return=t,t=t.child;continue}if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return null;t=t.return}t.sibling.return=t.return,t=t.sibling}return null}var fm=[];function Iv(){for(var e=0;e<fm.length;e++)fm[e]._workInProgressVersionPrimary=null;fm.length=0}var id=Jr.ReactCurrentDispatcher,mm=Jr.ReactCurrentBatchConfig,ca=0,It=null,Jt=null,rn=null,Wd=!1,Oo=!1,ic=0,o2=0;function wn(){throw Error(xe(321))}function Pv(e,t){if(t===null)return!1;for(var s=0;s<t.length&&s<e.length;s++)if(!Us(e[s],t[s]))return!1;return!0}function Mv(e,t,s,r,i,a){if(ca=a,It=t,t.memoizedState=null,t.updateQueue=null,t.lanes=0,id.current=e===null||e.memoizedState===null?h2:f2,e=s(r,i),Oo){a=0;do{if(Oo=!1,ic=0,25<=a)throw Error(xe(301));a+=1,rn=Jt=null,t.updateQueue=null,id.current=m2,e=s(r,i)}while(Oo)}if(id.current=Hd,t=Jt!==null&&Jt.next!==null,ca=0,rn=Jt=It=null,Wd=!1,t)throw Error(xe(300));return e}function Dv(){var e=ic!==0;return ic=0,e}function rr(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return rn===null?It.memoizedState=rn=e:rn=rn.next=e,rn}function Cs(){if(Jt===null){var e=It.alternate;e=e!==null?e.memoizedState:null}else e=Jt.next;var t=rn===null?It.memoizedState:rn.next;if(t!==null)rn=t,Jt=e;else{if(e===null)throw Error(xe(310));Jt=e,e={memoizedState:Jt.memoizedState,baseState:Jt.baseState,baseQueue:Jt.baseQueue,queue:Jt.queue,next:null},rn===null?It.memoizedState=rn=e:rn=rn.next=e}return rn}function ac(e,t){return typeof t=="function"?t(e):t}function pm(e){var t=Cs(),s=t.queue;if(s===null)throw Error(xe(311));s.lastRenderedReducer=e;var r=Jt,i=r.baseQueue,a=s.pending;if(a!==null){if(i!==null){var l=i.next;i.next=a.next,a.next=l}r.baseQueue=i=a,s.pending=null}if(i!==null){a=i.next,r=r.baseState;var o=l=null,c=null,u=a;do{var h=u.lane;if((ca&h)===h)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:h,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null};c===null?(o=c=f,l=r):c=c.next=f,It.lanes|=h,ua|=h}u=u.next}while(u!==null&&u!==a);c===null?l=r:c.next=o,Us(r,t.memoizedState)||(Un=!0),t.memoizedState=r,t.baseState=l,t.baseQueue=c,s.lastRenderedState=r}if(e=s.interleaved,e!==null){i=e;do a=i.lane,It.lanes|=a,ua|=a,i=i.next;while(i!==e)}else i===null&&(s.lanes=0);return[t.memoizedState,s.dispatch]}function gm(e){var t=Cs(),s=t.queue;if(s===null)throw Error(xe(311));s.lastRenderedReducer=e;var r=s.dispatch,i=s.pending,a=t.memoizedState;if(i!==null){s.pending=null;var l=i=i.next;do a=e(a,l.action),l=l.next;while(l!==i);Us(a,t.memoizedState)||(Un=!0),t.memoizedState=a,t.baseQueue===null&&(t.baseState=a),s.lastRenderedState=a}return[a,r]}function cC(){}function uC(e,t){var s=It,r=Cs(),i=t(),a=!Us(r.memoizedState,i);if(a&&(r.memoizedState=i,Un=!0),r=r.queue,Ov(fC.bind(null,s,r,e),[e]),r.getSnapshot!==t||a||rn!==null&&rn.memoizedState.tag&1){if(s.flags|=2048,lc(9,hC.bind(null,s,r,i,t),void 0,null),un===null)throw Error(xe(349));ca&30||dC(s,t,i)}return i}function dC(e,t,s){e.flags|=16384,e={getSnapshot:t,value:s},t=It.updateQueue,t===null?(t={lastEffect:null,stores:null},It.updateQueue=t,t.stores=[e]):(s=t.stores,s===null?t.stores=[e]:s.push(e))}function hC(e,t,s,r){t.value=s,t.getSnapshot=r,mC(t)&&pC(e)}function fC(e,t,s){return s(function(){mC(t)&&pC(e)})}function mC(e){var t=e.getSnapshot;e=e.value;try{var s=t();return!Us(e,s)}catch{return!0}}function pC(e){var t=Hr(e,1);t!==null&&Fs(t,e,1,-1)}function Nb(e){var t=rr();return typeof e=="function"&&(e=e()),t.memoizedState=t.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:ac,lastRenderedState:e},t.queue=e,e=e.dispatch=d2.bind(null,It,e),[t.memoizedState,e]}function lc(e,t,s,r){return e={tag:e,create:t,destroy:s,deps:r,next:null},t=It.updateQueue,t===null?(t={lastEffect:null,stores:null},It.updateQueue=t,t.lastEffect=e.next=e):(s=t.lastEffect,s===null?t.lastEffect=e.next=e:(r=s.next,s.next=e,e.next=r,t.lastEffect=e)),e}function gC(){return Cs().memoizedState}function ad(e,t,s,r){var i=rr();It.flags|=e,i.memoizedState=lc(1|t,s,void 0,r===void 0?null:r)}function Lh(e,t,s,r){var i=Cs();r=r===void 0?null:r;var a=void 0;if(Jt!==null){var l=Jt.memoizedState;if(a=l.destroy,r!==null&&Pv(r,l.deps)){i.memoizedState=lc(t,s,a,r);return}}It.flags|=e,i.memoizedState=lc(1|t,s,a,r)}function Sb(e,t){return ad(8390656,8,e,t)}function Ov(e,t){return Lh(2048,8,e,t)}function xC(e,t){return Lh(4,2,e,t)}function vC(e,t){return Lh(4,4,e,t)}function jC(e,t){if(typeof t=="function")return e=e(),t(e),function(){t(null)};if(t!=null)return e=e(),t.current=e,function(){t.current=null}}function wC(e,t,s){return s=s!=null?s.concat([e]):null,Lh(4,4,jC.bind(null,t,e),s)}function Lv(){}function yC(e,t){var s=Cs();t=t===void 0?null:t;var r=s.memoizedState;return r!==null&&t!==null&&Pv(t,r[1])?r[0]:(s.memoizedState=[e,t],e)}function bC(e,t){var s=Cs();t=t===void 0?null:t;var r=s.memoizedState;return r!==null&&t!==null&&Pv(t,r[1])?r[0]:(e=e(),s.memoizedState=[e,t],e)}function kC(e,t,s){return ca&21?(Us(s,t)||(s=AS(),It.lanes|=s,ua|=s,e.baseState=!0),t):(e.baseState&&(e.baseState=!1,Un=!0),e.memoizedState=s)}function c2(e,t){var s=xt;xt=s!==0&&4>s?s:4,e(!0);var r=mm.transition;mm.transition={};try{e(!1),t()}finally{xt=s,mm.transition=r}}function NC(){return Cs().memoizedState}function u2(e,t,s){var r=vi(e);if(s={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null},SC(e))CC(t,s);else if(s=aC(e,t,s,r),s!==null){var i=$n();Fs(s,e,r,i),EC(s,t,r)}}function d2(e,t,s){var r=vi(e),i={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null};if(SC(e))CC(t,i);else{var a=e.alternate;if(e.lanes===0&&(a===null||a.lanes===0)&&(a=t.lastRenderedReducer,a!==null))try{var l=t.lastRenderedState,o=a(l,s);if(i.hasEagerState=!0,i.eagerState=o,Us(o,l)){var c=t.interleaved;c===null?(i.next=i,Av(t)):(i.next=c.next,c.next=i),t.interleaved=i;return}}catch{}finally{}s=aC(e,t,i,r),s!==null&&(i=$n(),Fs(s,e,r,i),EC(s,t,r))}}function SC(e){var t=e.alternate;return e===It||t!==null&&t===It}function CC(e,t){Oo=Wd=!0;var s=e.pending;s===null?t.next=t:(t.next=s.next,s.next=t),e.pending=t}function EC(e,t,s){if(s&4194240){var r=t.lanes;r&=e.pendingLanes,s|=r,t.lanes=s,mv(e,s)}}var Hd={readContext:Ss,useCallback:wn,useContext:wn,useEffect:wn,useImperativeHandle:wn,useInsertionEffect:wn,useLayoutEffect:wn,useMemo:wn,useReducer:wn,useRef:wn,useState:wn,useDebugValue:wn,useDeferredValue:wn,useTransition:wn,useMutableSource:wn,useSyncExternalStore:wn,useId:wn,unstable_isNewReconciler:!1},h2={readContext:Ss,useCallback:function(e,t){return rr().memoizedState=[e,t===void 0?null:t],e},useContext:Ss,useEffect:Sb,useImperativeHandle:function(e,t,s){return s=s!=null?s.concat([e]):null,ad(4194308,4,jC.bind(null,t,e),s)},useLayoutEffect:function(e,t){return ad(4194308,4,e,t)},useInsertionEffect:function(e,t){return ad(4,2,e,t)},useMemo:function(e,t){var s=rr();return t=t===void 0?null:t,e=e(),s.memoizedState=[e,t],e},useReducer:function(e,t,s){var r=rr();return t=s!==void 0?s(t):t,r.memoizedState=r.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},r.queue=e,e=e.dispatch=u2.bind(null,It,e),[r.memoizedState,e]},useRef:function(e){var t=rr();return e={current:e},t.memoizedState=e},useState:Nb,useDebugValue:Lv,useDeferredValue:function(e){return rr().memoizedState=e},useTransition:function(){var e=Nb(!1),t=e[0];return e=c2.bind(null,e[1]),rr().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,s){var r=It,i=rr();if($t){if(s===void 0)throw Error(xe(407));s=s()}else{if(s=t(),un===null)throw Error(xe(349));ca&30||dC(r,t,s)}i.memoizedState=s;var a={value:s,getSnapshot:t};return i.queue=a,Sb(fC.bind(null,r,a,e),[e]),r.flags|=2048,lc(9,hC.bind(null,r,a,s,t),void 0,null),s},useId:function(){var e=rr(),t=un.identifierPrefix;if($t){var s=Mr,r=Pr;s=(r&~(1<<32-Ls(r)-1)).toString(32)+s,t=":"+t+"R"+s,s=ic++,0<s&&(t+="H"+s.toString(32)),t+=":"}else s=o2++,t=":"+t+"r"+s.toString(32)+":";return e.memoizedState=t},unstable_isNewReconciler:!1},f2={readContext:Ss,useCallback:yC,useContext:Ss,useEffect:Ov,useImperativeHandle:wC,useInsertionEffect:xC,useLayoutEffect:vC,useMemo:bC,useReducer:pm,useRef:gC,useState:function(){return pm(ac)},useDebugValue:Lv,useDeferredValue:function(e){var t=Cs();return kC(t,Jt.memoizedState,e)},useTransition:function(){var e=pm(ac)[0],t=Cs().memoizedState;return[e,t]},useMutableSource:cC,useSyncExternalStore:uC,useId:NC,unstable_isNewReconciler:!1},m2={readContext:Ss,useCallback:yC,useContext:Ss,useEffect:Ov,useImperativeHandle:wC,useInsertionEffect:xC,useLayoutEffect:vC,useMemo:bC,useReducer:gm,useRef:gC,useState:function(){return gm(ac)},useDebugValue:Lv,useDeferredValue:function(e){var t=Cs();return Jt===null?t.memoizedState=e:kC(t,Jt.memoizedState,e)},useTransition:function(){var e=gm(ac)[0],t=Cs().memoizedState;return[e,t]},useMutableSource:cC,useSyncExternalStore:uC,useId:NC,unstable_isNewReconciler:!1};function Is(e,t){if(e&&e.defaultProps){t=Mt({},t),e=e.defaultProps;for(var s in e)t[s]===void 0&&(t[s]=e[s]);return t}return t}function sg(e,t,s,r){t=e.memoizedState,s=s(r,t),s=s==null?t:Mt({},t,s),e.memoizedState=s,e.lanes===0&&(e.updateQueue.baseState=s)}var Fh={isMounted:function(e){return(e=e._reactInternals)?va(e)===e:!1},enqueueSetState:function(e,t,s){e=e._reactInternals;var r=$n(),i=vi(e),a=Or(r,i);a.payload=t,s!=null&&(a.callback=s),t=gi(e,a,i),t!==null&&(Fs(t,e,i,r),rd(t,e,i))},enqueueReplaceState:function(e,t,s){e=e._reactInternals;var r=$n(),i=vi(e),a=Or(r,i);a.tag=1,a.payload=t,s!=null&&(a.callback=s),t=gi(e,a,i),t!==null&&(Fs(t,e,i,r),rd(t,e,i))},enqueueForceUpdate:function(e,t){e=e._reactInternals;var s=$n(),r=vi(e),i=Or(s,r);i.tag=2,t!=null&&(i.callback=t),t=gi(e,i,r),t!==null&&(Fs(t,e,r,s),rd(t,e,r))}};function Cb(e,t,s,r,i,a,l){return e=e.stateNode,typeof e.shouldComponentUpdate=="function"?e.shouldComponentUpdate(r,a,l):t.prototype&&t.prototype.isPureReactComponent?!Zo(s,r)||!Zo(i,a):!0}function AC(e,t,s){var r=!1,i=Ni,a=t.contextType;return typeof a=="object"&&a!==null?a=Ss(a):(i=Hn(t)?la:Nn.current,r=t.contextTypes,a=(r=r!=null)?jl(e,i):Ni),t=new t(s,a),e.memoizedState=t.state!==null&&t.state!==void 0?t.state:null,t.updater=Fh,e.stateNode=t,t._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=i,e.__reactInternalMemoizedMaskedChildContext=a),t}function Eb(e,t,s,r){e=t.state,typeof t.componentWillReceiveProps=="function"&&t.componentWillReceiveProps(s,r),typeof t.UNSAFE_componentWillReceiveProps=="function"&&t.UNSAFE_componentWillReceiveProps(s,r),t.state!==e&&Fh.enqueueReplaceState(t,t.state,null)}function rg(e,t,s,r){var i=e.stateNode;i.props=s,i.state=e.memoizedState,i.refs={},Tv(e);var a=t.contextType;typeof a=="object"&&a!==null?i.context=Ss(a):(a=Hn(t)?la:Nn.current,i.context=jl(e,a)),i.state=e.memoizedState,a=t.getDerivedStateFromProps,typeof a=="function"&&(sg(e,t,a,s),i.state=e.memoizedState),typeof t.getDerivedStateFromProps=="function"||typeof i.getSnapshotBeforeUpdate=="function"||typeof i.UNSAFE_componentWillMount!="function"&&typeof i.componentWillMount!="function"||(t=i.state,typeof i.componentWillMount=="function"&&i.componentWillMount(),typeof i.UNSAFE_componentWillMount=="function"&&i.UNSAFE_componentWillMount(),t!==i.state&&Fh.enqueueReplaceState(i,i.state,null),Ud(e,s,i,r),i.state=e.memoizedState),typeof i.componentDidMount=="function"&&(e.flags|=4194308)}function kl(e,t){try{var s="",r=t;do s+=BP(r),r=r.return;while(r);var i=s}catch(a){i=`
39
+ Error generating stack: `+a.message+`
40
+ `+a.stack}return{value:e,source:t,stack:i,digest:null}}function xm(e,t,s){return{value:e,source:null,stack:s??null,digest:t??null}}function ig(e,t){try{console.error(t.value)}catch(s){setTimeout(function(){throw s})}}var p2=typeof WeakMap=="function"?WeakMap:Map;function TC(e,t,s){s=Or(-1,s),s.tag=3,s.payload={element:null};var r=t.value;return s.callback=function(){Vd||(Vd=!0,pg=r),ig(e,t)},s}function $C(e,t,s){s=Or(-1,s),s.tag=3;var r=e.type.getDerivedStateFromError;if(typeof r=="function"){var i=t.value;s.payload=function(){return r(i)},s.callback=function(){ig(e,t)}}var a=e.stateNode;return a!==null&&typeof a.componentDidCatch=="function"&&(s.callback=function(){ig(e,t),typeof r!="function"&&(xi===null?xi=new Set([this]):xi.add(this));var l=t.stack;this.componentDidCatch(t.value,{componentStack:l!==null?l:""})}),s}function Ab(e,t,s){var r=e.pingCache;if(r===null){r=e.pingCache=new p2;var i=new Set;r.set(t,i)}else i=r.get(t),i===void 0&&(i=new Set,r.set(t,i));i.has(s)||(i.add(s),e=T2.bind(null,e,t,s),t.then(e,e))}function Tb(e){do{var t;if((t=e.tag===13)&&(t=e.memoizedState,t=t!==null?t.dehydrated!==null:!0),t)return e;e=e.return}while(e!==null);return null}function $b(e,t,s,r,i){return e.mode&1?(e.flags|=65536,e.lanes=i,e):(e===t?e.flags|=65536:(e.flags|=128,s.flags|=131072,s.flags&=-52805,s.tag===1&&(s.alternate===null?s.tag=17:(t=Or(-1,1),t.tag=2,gi(s,t,1))),s.lanes|=1),e)}var g2=Jr.ReactCurrentOwner,Un=!1;function An(e,t,s,r){t.child=e===null?iC(t,null,s,r):yl(t,e.child,s,r)}function Rb(e,t,s,r,i){s=s.render;var a=t.ref;return ul(t,i),r=Mv(e,t,s,r,a,i),s=Dv(),e!==null&&!Un?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,Kr(e,t,i)):($t&&s&&bv(t),t.flags|=1,An(e,t,r,i),t.child)}function Ib(e,t,s,r,i){if(e===null){var a=s.type;return typeof a=="function"&&!Kv(a)&&a.defaultProps===void 0&&s.compare===null&&s.defaultProps===void 0?(t.tag=15,t.type=a,RC(e,t,a,r,i)):(e=ud(s.type,null,r,t,t.mode,i),e.ref=t.ref,e.return=t,t.child=e)}if(a=e.child,!(e.lanes&i)){var l=a.memoizedProps;if(s=s.compare,s=s!==null?s:Zo,s(l,r)&&e.ref===t.ref)return Kr(e,t,i)}return t.flags|=1,e=ji(a,r),e.ref=t.ref,e.return=t,t.child=e}function RC(e,t,s,r,i){if(e!==null){var a=e.memoizedProps;if(Zo(a,r)&&e.ref===t.ref)if(Un=!1,t.pendingProps=r=a,(e.lanes&i)!==0)e.flags&131072&&(Un=!0);else return t.lanes=e.lanes,Kr(e,t,i)}return ag(e,t,s,r,i)}function IC(e,t,s){var r=t.pendingProps,i=r.children,a=e!==null?e.memoizedState:null;if(r.mode==="hidden")if(!(t.mode&1))t.memoizedState={baseLanes:0,cachePool:null,transitions:null},St(tl,Xn),Xn|=s;else{if(!(s&1073741824))return e=a!==null?a.baseLanes|s:s,t.lanes=t.childLanes=1073741824,t.memoizedState={baseLanes:e,cachePool:null,transitions:null},t.updateQueue=null,St(tl,Xn),Xn|=e,null;t.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=a!==null?a.baseLanes:s,St(tl,Xn),Xn|=r}else a!==null?(r=a.baseLanes|s,t.memoizedState=null):r=s,St(tl,Xn),Xn|=r;return An(e,t,i,s),t.child}function PC(e,t){var s=t.ref;(e===null&&s!==null||e!==null&&e.ref!==s)&&(t.flags|=512,t.flags|=2097152)}function ag(e,t,s,r,i){var a=Hn(s)?la:Nn.current;return a=jl(t,a),ul(t,i),s=Mv(e,t,s,r,a,i),r=Dv(),e!==null&&!Un?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,Kr(e,t,i)):($t&&r&&bv(t),t.flags|=1,An(e,t,s,i),t.child)}function Pb(e,t,s,r,i){if(Hn(s)){var a=!0;Od(t)}else a=!1;if(ul(t,i),t.stateNode===null)ld(e,t),AC(t,s,r),rg(t,s,r,i),r=!0;else if(e===null){var l=t.stateNode,o=t.memoizedProps;l.props=o;var c=l.context,u=s.contextType;typeof u=="object"&&u!==null?u=Ss(u):(u=Hn(s)?la:Nn.current,u=jl(t,u));var h=s.getDerivedStateFromProps,f=typeof h=="function"||typeof l.getSnapshotBeforeUpdate=="function";f||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==r||c!==u)&&Eb(t,l,r,u),ii=!1;var m=t.memoizedState;l.state=m,Ud(t,r,l,i),c=t.memoizedState,o!==r||m!==c||Wn.current||ii?(typeof h=="function"&&(sg(t,s,h,r),c=t.memoizedState),(o=ii||Cb(t,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"&&(t.flags|=4194308)):(typeof l.componentDidMount=="function"&&(t.flags|=4194308),t.memoizedProps=r,t.memoizedState=c),l.props=r,l.state=c,l.context=u,r=o):(typeof l.componentDidMount=="function"&&(t.flags|=4194308),r=!1)}else{l=t.stateNode,lC(e,t),o=t.memoizedProps,u=t.type===t.elementType?o:Is(t.type,o),l.props=u,f=t.pendingProps,m=l.context,c=s.contextType,typeof c=="object"&&c!==null?c=Ss(c):(c=Hn(s)?la:Nn.current,c=jl(t,c));var p=s.getDerivedStateFromProps;(h=typeof p=="function"||typeof l.getSnapshotBeforeUpdate=="function")||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==f||m!==c)&&Eb(t,l,r,c),ii=!1,m=t.memoizedState,l.state=m,Ud(t,r,l,i);var g=t.memoizedState;o!==f||m!==g||Wn.current||ii?(typeof p=="function"&&(sg(t,s,p,r),g=t.memoizedState),(u=ii||Cb(t,s,u,r,m,g,c)||!1)?(h||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"&&(t.flags|=4),typeof l.getSnapshotBeforeUpdate=="function"&&(t.flags|=1024)):(typeof l.componentDidUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(t.flags|=4),typeof l.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(t.flags|=1024),t.memoizedProps=r,t.memoizedState=g),l.props=r,l.state=g,l.context=c,r=u):(typeof l.componentDidUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(t.flags|=4),typeof l.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(t.flags|=1024),r=!1)}return lg(e,t,s,r,a,i)}function lg(e,t,s,r,i,a){PC(e,t);var l=(t.flags&128)!==0;if(!r&&!l)return i&&vb(t,s,!1),Kr(e,t,a);r=t.stateNode,g2.current=t;var o=l&&typeof s.getDerivedStateFromError!="function"?null:r.render();return t.flags|=1,e!==null&&l?(t.child=yl(t,e.child,null,a),t.child=yl(t,null,o,a)):An(e,t,o,a),t.memoizedState=r.state,i&&vb(t,s,!0),t.child}function MC(e){var t=e.stateNode;t.pendingContext?xb(e,t.pendingContext,t.pendingContext!==t.context):t.context&&xb(e,t.context,!1),$v(e,t.containerInfo)}function Mb(e,t,s,r,i){return wl(),Nv(i),t.flags|=256,An(e,t,s,r),t.child}var og={dehydrated:null,treeContext:null,retryLane:0};function cg(e){return{baseLanes:e,cachePool:null,transitions:null}}function DC(e,t,s){var r=t.pendingProps,i=Rt.current,a=!1,l=(t.flags&128)!==0,o;if((o=l)||(o=e!==null&&e.memoizedState===null?!1:(i&2)!==0),o?(a=!0,t.flags&=-129):(e===null||e.memoizedState!==null)&&(i|=1),St(Rt,i&1),e===null)return tg(t),e=t.memoizedState,e!==null&&(e=e.dehydrated,e!==null)?(t.mode&1?e.data==="$!"?t.lanes=8:t.lanes=1073741824:t.lanes=1,null):(l=r.children,e=r.fallback,a?(r=t.mode,a=t.child,l={mode:"hidden",children:l},!(r&1)&&a!==null?(a.childLanes=0,a.pendingProps=l):a=Uh(l,r,0,null),e=ra(e,r,s,null),a.return=t,e.return=t,a.sibling=e,t.child=a,t.child.memoizedState=cg(s),t.memoizedState=og,e):Fv(t,l));if(i=e.memoizedState,i!==null&&(o=i.dehydrated,o!==null))return x2(e,t,l,r,o,i,s);if(a){a=r.fallback,l=t.mode,i=e.child,o=i.sibling;var c={mode:"hidden",children:r.children};return!(l&1)&&t.child!==i?(r=t.child,r.childLanes=0,r.pendingProps=c,t.deletions=null):(r=ji(i,c),r.subtreeFlags=i.subtreeFlags&14680064),o!==null?a=ji(o,a):(a=ra(a,l,s,null),a.flags|=2),a.return=t,r.return=t,r.sibling=a,t.child=r,r=a,a=t.child,l=e.child.memoizedState,l=l===null?cg(s):{baseLanes:l.baseLanes|s,cachePool:null,transitions:l.transitions},a.memoizedState=l,a.childLanes=e.childLanes&~s,t.memoizedState=og,r}return a=e.child,e=a.sibling,r=ji(a,{mode:"visible",children:r.children}),!(t.mode&1)&&(r.lanes=s),r.return=t,r.sibling=null,e!==null&&(s=t.deletions,s===null?(t.deletions=[e],t.flags|=16):s.push(e)),t.child=r,t.memoizedState=null,r}function Fv(e,t){return t=Uh({mode:"visible",children:t},e.mode,0,null),t.return=e,e.child=t}function ku(e,t,s,r){return r!==null&&Nv(r),yl(t,e.child,null,s),e=Fv(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function x2(e,t,s,r,i,a,l){if(s)return t.flags&256?(t.flags&=-257,r=xm(Error(xe(422))),ku(e,t,l,r)):t.memoizedState!==null?(t.child=e.child,t.flags|=128,null):(a=r.fallback,i=t.mode,r=Uh({mode:"visible",children:r.children},i,0,null),a=ra(a,i,l,null),a.flags|=2,r.return=t,a.return=t,r.sibling=a,t.child=r,t.mode&1&&yl(t,e.child,null,l),t.child.memoizedState=cg(l),t.memoizedState=og,a);if(!(t.mode&1))return ku(e,t,l,null);if(i.data==="$!"){if(r=i.nextSibling&&i.nextSibling.dataset,r)var o=r.dgst;return r=o,a=Error(xe(419)),r=xm(a,r,void 0),ku(e,t,l,r)}if(o=(l&e.childLanes)!==0,Un||o){if(r=un,r!==null){switch(l&-l){case 4:i=2;break;case 16:i=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:i=32;break;case 536870912:i=268435456;break;default:i=0}i=i&(r.suspendedLanes|l)?0:i,i!==0&&i!==a.retryLane&&(a.retryLane=i,Hr(e,i),Fs(r,e,i,-1))}return Hv(),r=xm(Error(xe(421))),ku(e,t,l,r)}return i.data==="$?"?(t.flags|=128,t.child=e.child,t=$2.bind(null,e),i._reactRetry=t,null):(e=a.treeContext,es=pi(i.nextSibling),ns=t,$t=!0,Ms=null,e!==null&&(xs[vs++]=Pr,xs[vs++]=Mr,xs[vs++]=oa,Pr=e.id,Mr=e.overflow,oa=t),t=Fv(t,r.children),t.flags|=4096,t)}function Db(e,t,s){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),ng(e.return,t,s)}function vm(e,t,s,r,i){var a=e.memoizedState;a===null?e.memoizedState={isBackwards:t,rendering:null,renderingStartTime:0,last:r,tail:s,tailMode:i}:(a.isBackwards=t,a.rendering=null,a.renderingStartTime=0,a.last=r,a.tail=s,a.tailMode=i)}function OC(e,t,s){var r=t.pendingProps,i=r.revealOrder,a=r.tail;if(An(e,t,r.children,s),r=Rt.current,r&2)r=r&1|2,t.flags|=128;else{if(e!==null&&e.flags&128)e:for(e=t.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&Db(e,s,t);else if(e.tag===19)Db(e,s,t);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break e;for(;e.sibling===null;){if(e.return===null||e.return===t)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}if(St(Rt,r),!(t.mode&1))t.memoizedState=null;else switch(i){case"forwards":for(s=t.child,i=null;s!==null;)e=s.alternate,e!==null&&Bd(e)===null&&(i=s),s=s.sibling;s=i,s===null?(i=t.child,t.child=null):(i=s.sibling,s.sibling=null),vm(t,!1,i,s,a);break;case"backwards":for(s=null,i=t.child,t.child=null;i!==null;){if(e=i.alternate,e!==null&&Bd(e)===null){t.child=i;break}e=i.sibling,i.sibling=s,s=i,i=e}vm(t,!0,s,null,a);break;case"together":vm(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function ld(e,t){!(t.mode&1)&&e!==null&&(e.alternate=null,t.alternate=null,t.flags|=2)}function Kr(e,t,s){if(e!==null&&(t.dependencies=e.dependencies),ua|=t.lanes,!(s&t.childLanes))return null;if(e!==null&&t.child!==e.child)throw Error(xe(153));if(t.child!==null){for(e=t.child,s=ji(e,e.pendingProps),t.child=s,s.return=t;e.sibling!==null;)e=e.sibling,s=s.sibling=ji(e,e.pendingProps),s.return=t;s.sibling=null}return t.child}function v2(e,t,s){switch(t.tag){case 3:MC(t),wl();break;case 5:oC(t);break;case 1:Hn(t.type)&&Od(t);break;case 4:$v(t,t.stateNode.containerInfo);break;case 10:var r=t.type._context,i=t.memoizedProps.value;St(_d,r._currentValue),r._currentValue=i;break;case 13:if(r=t.memoizedState,r!==null)return r.dehydrated!==null?(St(Rt,Rt.current&1),t.flags|=128,null):s&t.child.childLanes?DC(e,t,s):(St(Rt,Rt.current&1),e=Kr(e,t,s),e!==null?e.sibling:null);St(Rt,Rt.current&1);break;case 19:if(r=(s&t.childLanes)!==0,e.flags&128){if(r)return OC(e,t,s);t.flags|=128}if(i=t.memoizedState,i!==null&&(i.rendering=null,i.tail=null,i.lastEffect=null),St(Rt,Rt.current),r)break;return null;case 22:case 23:return t.lanes=0,IC(e,t,s)}return Kr(e,t,s)}var LC,ug,FC,_C;LC=function(e,t){for(var s=t.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===t)break;for(;s.sibling===null;){if(s.return===null||s.return===t)return;s=s.return}s.sibling.return=s.return,s=s.sibling}};ug=function(){};FC=function(e,t,s,r){var i=e.memoizedProps;if(i!==r){e=t.stateNode,ea(hr.current);var a=null;switch(s){case"input":i=Ip(e,i),r=Ip(e,r),a=[];break;case"select":i=Mt({},i,{value:void 0}),r=Mt({},r,{value:void 0}),a=[];break;case"textarea":i=Dp(e,i),r=Dp(e,r),a=[];break;default:typeof i.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=Md)}Lp(s,r);var l;s=null;for(u in i)if(!r.hasOwnProperty(u)&&i.hasOwnProperty(u)&&i[u]!=null)if(u==="style"){var o=i[u];for(l in o)o.hasOwnProperty(l)&&(s||(s={}),s[l]="")}else u!=="dangerouslySetInnerHTML"&&u!=="children"&&u!=="suppressContentEditableWarning"&&u!=="suppressHydrationWarning"&&u!=="autoFocus"&&(Vo.hasOwnProperty(u)?a||(a=[]):(a=a||[]).push(u,null));for(u in r){var c=r[u];if(o=i!=null?i[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||(a||(a=[]),a.push(u,s)),s=c;else u==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,o=o?o.__html:void 0,c!=null&&o!==c&&(a=a||[]).push(u,c)):u==="children"?typeof c!="string"&&typeof c!="number"||(a=a||[]).push(u,""+c):u!=="suppressContentEditableWarning"&&u!=="suppressHydrationWarning"&&(Vo.hasOwnProperty(u)?(c!=null&&u==="onScroll"&&Ct("scroll",e),a||o===c||(a=[])):(a=a||[]).push(u,c))}s&&(a=a||[]).push("style",s);var u=a;(t.updateQueue=u)&&(t.flags|=4)}};_C=function(e,t,s,r){s!==r&&(t.flags|=4)};function mo(e,t){if(!$t)switch(e.tailMode){case"hidden":t=e.tail;for(var s=null;t!==null;)t.alternate!==null&&(s=t),t=t.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?t||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function yn(e){var t=e.alternate!==null&&e.alternate.child===e.child,s=0,r=0;if(t)for(var i=e.child;i!==null;)s|=i.lanes|i.childLanes,r|=i.subtreeFlags&14680064,r|=i.flags&14680064,i.return=e,i=i.sibling;else for(i=e.child;i!==null;)s|=i.lanes|i.childLanes,r|=i.subtreeFlags,r|=i.flags,i.return=e,i=i.sibling;return e.subtreeFlags|=r,e.childLanes=s,t}function j2(e,t,s){var r=t.pendingProps;switch(kv(t),t.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return yn(t),null;case 1:return Hn(t.type)&&Dd(),yn(t),null;case 3:return r=t.stateNode,bl(),At(Wn),At(Nn),Iv(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(yu(t)?t.flags|=4:e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,Ms!==null&&(vg(Ms),Ms=null))),ug(e,t),yn(t),null;case 5:Rv(t);var i=ea(rc.current);if(s=t.type,e!==null&&t.stateNode!=null)FC(e,t,s,r,i),e.ref!==t.ref&&(t.flags|=512,t.flags|=2097152);else{if(!r){if(t.stateNode===null)throw Error(xe(166));return yn(t),null}if(e=ea(hr.current),yu(t)){r=t.stateNode,s=t.type;var a=t.memoizedProps;switch(r[lr]=t,r[nc]=a,e=(t.mode&1)!==0,s){case"dialog":Ct("cancel",r),Ct("close",r);break;case"iframe":case"object":case"embed":Ct("load",r);break;case"video":case"audio":for(i=0;i<Co.length;i++)Ct(Co[i],r);break;case"source":Ct("error",r);break;case"img":case"image":case"link":Ct("error",r),Ct("load",r);break;case"details":Ct("toggle",r);break;case"input":Hy(r,a),Ct("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!a.multiple},Ct("invalid",r);break;case"textarea":Vy(r,a),Ct("invalid",r)}Lp(s,a),i=null;for(var l in a)if(a.hasOwnProperty(l)){var o=a[l];l==="children"?typeof o=="string"?r.textContent!==o&&(a.suppressHydrationWarning!==!0&&wu(r.textContent,o,e),i=["children",o]):typeof o=="number"&&r.textContent!==""+o&&(a.suppressHydrationWarning!==!0&&wu(r.textContent,o,e),i=["children",""+o]):Vo.hasOwnProperty(l)&&o!=null&&l==="onScroll"&&Ct("scroll",r)}switch(s){case"input":hu(r),Ky(r,a,!0);break;case"textarea":hu(r),Gy(r);break;case"select":case"option":break;default:typeof a.onClick=="function"&&(r.onclick=Md)}r=i,t.updateQueue=r,r!==null&&(t.flags|=4)}else{l=i.nodeType===9?i:i.ownerDocument,e==="http://www.w3.org/1999/xhtml"&&(e=fS(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[lr]=t,e[nc]=r,LC(e,t,!1,!1),t.stateNode=e;e:{switch(l=Fp(s,r),s){case"dialog":Ct("cancel",e),Ct("close",e),i=r;break;case"iframe":case"object":case"embed":Ct("load",e),i=r;break;case"video":case"audio":for(i=0;i<Co.length;i++)Ct(Co[i],e);i=r;break;case"source":Ct("error",e),i=r;break;case"img":case"image":case"link":Ct("error",e),Ct("load",e),i=r;break;case"details":Ct("toggle",e),i=r;break;case"input":Hy(e,r),i=Ip(e,r),Ct("invalid",e);break;case"option":i=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},i=Mt({},r,{value:void 0}),Ct("invalid",e);break;case"textarea":Vy(e,r),i=Dp(e,r),Ct("invalid",e);break;default:i=r}Lp(s,i),o=i;for(a in o)if(o.hasOwnProperty(a)){var c=o[a];a==="style"?gS(e,c):a==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,c!=null&&mS(e,c)):a==="children"?typeof c=="string"?(s!=="textarea"||c!=="")&&Go(e,c):typeof c=="number"&&Go(e,""+c):a!=="suppressContentEditableWarning"&&a!=="suppressHydrationWarning"&&a!=="autoFocus"&&(Vo.hasOwnProperty(a)?c!=null&&a==="onScroll"&&Ct("scroll",e):c!=null&&ov(e,a,c,l))}switch(s){case"input":hu(e),Ky(e,r,!1);break;case"textarea":hu(e),Gy(e);break;case"option":r.value!=null&&e.setAttribute("value",""+ki(r.value));break;case"select":e.multiple=!!r.multiple,a=r.value,a!=null?al(e,!!r.multiple,a,!1):r.defaultValue!=null&&al(e,!!r.multiple,r.defaultValue,!0);break;default:typeof i.onClick=="function"&&(e.onclick=Md)}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&&(t.flags|=4)}t.ref!==null&&(t.flags|=512,t.flags|=2097152)}return yn(t),null;case 6:if(e&&t.stateNode!=null)_C(e,t,e.memoizedProps,r);else{if(typeof r!="string"&&t.stateNode===null)throw Error(xe(166));if(s=ea(rc.current),ea(hr.current),yu(t)){if(r=t.stateNode,s=t.memoizedProps,r[lr]=t,(a=r.nodeValue!==s)&&(e=ns,e!==null))switch(e.tag){case 3:wu(r.nodeValue,s,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&wu(r.nodeValue,s,(e.mode&1)!==0)}a&&(t.flags|=4)}else r=(s.nodeType===9?s:s.ownerDocument).createTextNode(r),r[lr]=t,t.stateNode=r}return yn(t),null;case 13:if(At(Rt),r=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if($t&&es!==null&&t.mode&1&&!(t.flags&128))sC(),wl(),t.flags|=98560,a=!1;else if(a=yu(t),r!==null&&r.dehydrated!==null){if(e===null){if(!a)throw Error(xe(318));if(a=t.memoizedState,a=a!==null?a.dehydrated:null,!a)throw Error(xe(317));a[lr]=t}else wl(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;yn(t),a=!1}else Ms!==null&&(vg(Ms),Ms=null),a=!0;if(!a)return t.flags&65536?t:null}return t.flags&128?(t.lanes=s,t):(r=r!==null,r!==(e!==null&&e.memoizedState!==null)&&r&&(t.child.flags|=8192,t.mode&1&&(e===null||Rt.current&1?Zt===0&&(Zt=3):Hv())),t.updateQueue!==null&&(t.flags|=4),yn(t),null);case 4:return bl(),ug(e,t),e===null&&ec(t.stateNode.containerInfo),yn(t),null;case 10:return Ev(t.type._context),yn(t),null;case 17:return Hn(t.type)&&Dd(),yn(t),null;case 19:if(At(Rt),a=t.memoizedState,a===null)return yn(t),null;if(r=(t.flags&128)!==0,l=a.rendering,l===null)if(r)mo(a,!1);else{if(Zt!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(l=Bd(e),l!==null){for(t.flags|=128,mo(a,!1),r=l.updateQueue,r!==null&&(t.updateQueue=r,t.flags|=4),t.subtreeFlags=0,r=s,s=t.child;s!==null;)a=s,e=r,a.flags&=14680066,l=a.alternate,l===null?(a.childLanes=0,a.lanes=e,a.child=null,a.subtreeFlags=0,a.memoizedProps=null,a.memoizedState=null,a.updateQueue=null,a.dependencies=null,a.stateNode=null):(a.childLanes=l.childLanes,a.lanes=l.lanes,a.child=l.child,a.subtreeFlags=0,a.deletions=null,a.memoizedProps=l.memoizedProps,a.memoizedState=l.memoizedState,a.updateQueue=l.updateQueue,a.type=l.type,e=l.dependencies,a.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext}),s=s.sibling;return St(Rt,Rt.current&1|2),t.child}e=e.sibling}a.tail!==null&&_t()>Nl&&(t.flags|=128,r=!0,mo(a,!1),t.lanes=4194304)}else{if(!r)if(e=Bd(l),e!==null){if(t.flags|=128,r=!0,s=e.updateQueue,s!==null&&(t.updateQueue=s,t.flags|=4),mo(a,!0),a.tail===null&&a.tailMode==="hidden"&&!l.alternate&&!$t)return yn(t),null}else 2*_t()-a.renderingStartTime>Nl&&s!==1073741824&&(t.flags|=128,r=!0,mo(a,!1),t.lanes=4194304);a.isBackwards?(l.sibling=t.child,t.child=l):(s=a.last,s!==null?s.sibling=l:t.child=l,a.last=l)}return a.tail!==null?(t=a.tail,a.rendering=t,a.tail=t.sibling,a.renderingStartTime=_t(),t.sibling=null,s=Rt.current,St(Rt,r?s&1|2:s&1),t):(yn(t),null);case 22:case 23:return Wv(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?Xn&1073741824&&(yn(t),t.subtreeFlags&6&&(t.flags|=8192)):yn(t),null;case 24:return null;case 25:return null}throw Error(xe(156,t.tag))}function w2(e,t){switch(kv(t),t.tag){case 1:return Hn(t.type)&&Dd(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return bl(),At(Wn),At(Nn),Iv(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return Rv(t),null;case 13:if(At(Rt),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(xe(340));wl()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return At(Rt),null;case 4:return bl(),null;case 10:return Ev(t.type._context),null;case 22:case 23:return Wv(),null;case 24:return null;default:return null}}var Nu=!1,bn=!1,y2=typeof WeakSet=="function"?WeakSet:Set,Te=null;function el(e,t){var s=e.ref;if(s!==null)if(typeof s=="function")try{s(null)}catch(r){Lt(e,t,r)}else s.current=null}function dg(e,t,s){try{s()}catch(r){Lt(e,t,r)}}var Ob=!1;function b2(e,t){if(qp=Rd,e=HS(),yv(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 i=r.anchorOffset,a=r.focusNode;r=r.focusOffset;try{s.nodeType,a.nodeType}catch{s=null;break e}var l=0,o=-1,c=-1,u=0,h=0,f=e,m=null;t:for(;;){for(var p;f!==s||i!==0&&f.nodeType!==3||(o=l+i),f!==a||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===i&&(o=l),m===a&&++h===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(Yp={focusedElem:e,selectionRange:s},Rd=!1,Te=t;Te!==null;)if(t=Te,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,Te=e;else for(;Te!==null;){t=Te;try{var g=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(g!==null){var v=g.memoizedProps,b=g.memoizedState,j=t.stateNode,x=j.getSnapshotBeforeUpdate(t.elementType===t.type?v:Is(t.type,v),b);j.__reactInternalSnapshotBeforeUpdate=x}break;case 3:var w=t.stateNode.containerInfo;w.nodeType===1?w.textContent="":w.nodeType===9&&w.documentElement&&w.removeChild(w.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(xe(163))}}catch(y){Lt(t,t.return,y)}if(e=t.sibling,e!==null){e.return=t.return,Te=e;break}Te=t.return}return g=Ob,Ob=!1,g}function Lo(e,t,s){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var i=r=r.next;do{if((i.tag&e)===e){var a=i.destroy;i.destroy=void 0,a!==void 0&&dg(t,s,a)}i=i.next}while(i!==r)}}function _h(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var s=t=t.next;do{if((s.tag&e)===e){var r=s.create;s.destroy=r()}s=s.next}while(s!==t)}}function hg(e){var t=e.ref;if(t!==null){var s=e.stateNode;switch(e.tag){case 5:e=s;break;default:e=s}typeof t=="function"?t(e):t.current=e}}function zC(e){var t=e.alternate;t!==null&&(e.alternate=null,zC(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[lr],delete t[nc],delete t[Xp],delete t[r2],delete t[i2])),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 UC(e){return e.tag===5||e.tag===3||e.tag===4}function Lb(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||UC(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 fg(e,t,s){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?s.nodeType===8?s.parentNode.insertBefore(e,t):s.insertBefore(e,t):(s.nodeType===8?(t=s.parentNode,t.insertBefore(e,s)):(t=s,t.appendChild(e)),s=s._reactRootContainer,s!=null||t.onclick!==null||(t.onclick=Md));else if(r!==4&&(e=e.child,e!==null))for(fg(e,t,s),e=e.sibling;e!==null;)fg(e,t,s),e=e.sibling}function mg(e,t,s){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?s.insertBefore(e,t):s.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(mg(e,t,s),e=e.sibling;e!==null;)mg(e,t,s),e=e.sibling}var fn=null,Ps=!1;function ni(e,t,s){for(s=s.child;s!==null;)BC(e,t,s),s=s.sibling}function BC(e,t,s){if(dr&&typeof dr.onCommitFiberUnmount=="function")try{dr.onCommitFiberUnmount(Rh,s)}catch{}switch(s.tag){case 5:bn||el(s,t);case 6:var r=fn,i=Ps;fn=null,ni(e,t,s),fn=r,Ps=i,fn!==null&&(Ps?(e=fn,s=s.stateNode,e.nodeType===8?e.parentNode.removeChild(s):e.removeChild(s)):fn.removeChild(s.stateNode));break;case 18:fn!==null&&(Ps?(e=fn,s=s.stateNode,e.nodeType===8?dm(e.parentNode,s):e.nodeType===1&&dm(e,s),Qo(e)):dm(fn,s.stateNode));break;case 4:r=fn,i=Ps,fn=s.stateNode.containerInfo,Ps=!0,ni(e,t,s),fn=r,Ps=i;break;case 0:case 11:case 14:case 15:if(!bn&&(r=s.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){i=r=r.next;do{var a=i,l=a.destroy;a=a.tag,l!==void 0&&(a&2||a&4)&&dg(s,t,l),i=i.next}while(i!==r)}ni(e,t,s);break;case 1:if(!bn&&(el(s,t),r=s.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=s.memoizedProps,r.state=s.memoizedState,r.componentWillUnmount()}catch(o){Lt(s,t,o)}ni(e,t,s);break;case 21:ni(e,t,s);break;case 22:s.mode&1?(bn=(r=bn)||s.memoizedState!==null,ni(e,t,s),bn=r):ni(e,t,s);break;default:ni(e,t,s)}}function Fb(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var s=e.stateNode;s===null&&(s=e.stateNode=new y2),t.forEach(function(r){var i=R2.bind(null,e,r);s.has(r)||(s.add(r),r.then(i,i))})}}function Rs(e,t){var s=t.deletions;if(s!==null)for(var r=0;r<s.length;r++){var i=s[r];try{var a=e,l=t,o=l;e:for(;o!==null;){switch(o.tag){case 5:fn=o.stateNode,Ps=!1;break e;case 3:fn=o.stateNode.containerInfo,Ps=!0;break e;case 4:fn=o.stateNode.containerInfo,Ps=!0;break e}o=o.return}if(fn===null)throw Error(xe(160));BC(a,l,i),fn=null,Ps=!1;var c=i.alternate;c!==null&&(c.return=null),i.return=null}catch(u){Lt(i,t,u)}}if(t.subtreeFlags&12854)for(t=t.child;t!==null;)WC(t,e),t=t.sibling}function WC(e,t){var s=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(Rs(t,e),er(e),r&4){try{Lo(3,e,e.return),_h(3,e)}catch(v){Lt(e,e.return,v)}try{Lo(5,e,e.return)}catch(v){Lt(e,e.return,v)}}break;case 1:Rs(t,e),er(e),r&512&&s!==null&&el(s,s.return);break;case 5:if(Rs(t,e),er(e),r&512&&s!==null&&el(s,s.return),e.flags&32){var i=e.stateNode;try{Go(i,"")}catch(v){Lt(e,e.return,v)}}if(r&4&&(i=e.stateNode,i!=null)){var a=e.memoizedProps,l=s!==null?s.memoizedProps:a,o=e.type,c=e.updateQueue;if(e.updateQueue=null,c!==null)try{o==="input"&&a.type==="radio"&&a.name!=null&&dS(i,a),Fp(o,l);var u=Fp(o,a);for(l=0;l<c.length;l+=2){var h=c[l],f=c[l+1];h==="style"?gS(i,f):h==="dangerouslySetInnerHTML"?mS(i,f):h==="children"?Go(i,f):ov(i,h,f,u)}switch(o){case"input":Pp(i,a);break;case"textarea":hS(i,a);break;case"select":var m=i._wrapperState.wasMultiple;i._wrapperState.wasMultiple=!!a.multiple;var p=a.value;p!=null?al(i,!!a.multiple,p,!1):m!==!!a.multiple&&(a.defaultValue!=null?al(i,!!a.multiple,a.defaultValue,!0):al(i,!!a.multiple,a.multiple?[]:"",!1))}i[nc]=a}catch(v){Lt(e,e.return,v)}}break;case 6:if(Rs(t,e),er(e),r&4){if(e.stateNode===null)throw Error(xe(162));i=e.stateNode,a=e.memoizedProps;try{i.nodeValue=a}catch(v){Lt(e,e.return,v)}}break;case 3:if(Rs(t,e),er(e),r&4&&s!==null&&s.memoizedState.isDehydrated)try{Qo(t.containerInfo)}catch(v){Lt(e,e.return,v)}break;case 4:Rs(t,e),er(e);break;case 13:Rs(t,e),er(e),i=e.child,i.flags&8192&&(a=i.memoizedState!==null,i.stateNode.isHidden=a,!a||i.alternate!==null&&i.alternate.memoizedState!==null||(Uv=_t())),r&4&&Fb(e);break;case 22:if(h=s!==null&&s.memoizedState!==null,e.mode&1?(bn=(u=bn)||h,Rs(t,e),bn=u):Rs(t,e),er(e),r&8192){if(u=e.memoizedState!==null,(e.stateNode.isHidden=u)&&!h&&e.mode&1)for(Te=e,h=e.child;h!==null;){for(f=Te=h;Te!==null;){switch(m=Te,p=m.child,m.tag){case 0:case 11:case 14:case 15:Lo(4,m,m.return);break;case 1:el(m,m.return);var g=m.stateNode;if(typeof g.componentWillUnmount=="function"){r=m,s=m.return;try{t=r,g.props=t.memoizedProps,g.state=t.memoizedState,g.componentWillUnmount()}catch(v){Lt(r,s,v)}}break;case 5:el(m,m.return);break;case 22:if(m.memoizedState!==null){zb(f);continue}}p!==null?(p.return=m,Te=p):zb(f)}h=h.sibling}e:for(h=null,f=e;;){if(f.tag===5){if(h===null){h=f;try{i=f.stateNode,u?(a=i.style,typeof a.setProperty=="function"?a.setProperty("display","none","important"):a.display="none"):(o=f.stateNode,c=f.memoizedProps.style,l=c!=null&&c.hasOwnProperty("display")?c.display:null,o.style.display=pS("display",l))}catch(v){Lt(e,e.return,v)}}}else if(f.tag===6){if(h===null)try{f.stateNode.nodeValue=u?"":f.memoizedProps}catch(v){Lt(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;h===f&&(h=null),f=f.return}h===f&&(h=null),f.sibling.return=f.return,f=f.sibling}}break;case 19:Rs(t,e),er(e),r&4&&Fb(e);break;case 21:break;default:Rs(t,e),er(e)}}function er(e){var t=e.flags;if(t&2){try{e:{for(var s=e.return;s!==null;){if(UC(s)){var r=s;break e}s=s.return}throw Error(xe(160))}switch(r.tag){case 5:var i=r.stateNode;r.flags&32&&(Go(i,""),r.flags&=-33);var a=Lb(e);mg(e,a,i);break;case 3:case 4:var l=r.stateNode.containerInfo,o=Lb(e);fg(e,o,l);break;default:throw Error(xe(161))}}catch(c){Lt(e,e.return,c)}e.flags&=-3}t&4096&&(e.flags&=-4097)}function k2(e,t,s){Te=e,HC(e)}function HC(e,t,s){for(var r=(e.mode&1)!==0;Te!==null;){var i=Te,a=i.child;if(i.tag===22&&r){var l=i.memoizedState!==null||Nu;if(!l){var o=i.alternate,c=o!==null&&o.memoizedState!==null||bn;o=Nu;var u=bn;if(Nu=l,(bn=c)&&!u)for(Te=i;Te!==null;)l=Te,c=l.child,l.tag===22&&l.memoizedState!==null?Ub(i):c!==null?(c.return=l,Te=c):Ub(i);for(;a!==null;)Te=a,HC(a),a=a.sibling;Te=i,Nu=o,bn=u}_b(e)}else i.subtreeFlags&8772&&a!==null?(a.return=i,Te=a):_b(e)}}function _b(e){for(;Te!==null;){var t=Te;if(t.flags&8772){var s=t.alternate;try{if(t.flags&8772)switch(t.tag){case 0:case 11:case 15:bn||_h(5,t);break;case 1:var r=t.stateNode;if(t.flags&4&&!bn)if(s===null)r.componentDidMount();else{var i=t.elementType===t.type?s.memoizedProps:Is(t.type,s.memoizedProps);r.componentDidUpdate(i,s.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var a=t.updateQueue;a!==null&&kb(t,a,r);break;case 3:var l=t.updateQueue;if(l!==null){if(s=null,t.child!==null)switch(t.child.tag){case 5:s=t.child.stateNode;break;case 1:s=t.child.stateNode}kb(t,l,s)}break;case 5:var o=t.stateNode;if(s===null&&t.flags&4){s=o;var c=t.memoizedProps;switch(t.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(t.memoizedState===null){var u=t.alternate;if(u!==null){var h=u.memoizedState;if(h!==null){var f=h.dehydrated;f!==null&&Qo(f)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(xe(163))}bn||t.flags&512&&hg(t)}catch(m){Lt(t,t.return,m)}}if(t===e){Te=null;break}if(s=t.sibling,s!==null){s.return=t.return,Te=s;break}Te=t.return}}function zb(e){for(;Te!==null;){var t=Te;if(t===e){Te=null;break}var s=t.sibling;if(s!==null){s.return=t.return,Te=s;break}Te=t.return}}function Ub(e){for(;Te!==null;){var t=Te;try{switch(t.tag){case 0:case 11:case 15:var s=t.return;try{_h(4,t)}catch(c){Lt(t,s,c)}break;case 1:var r=t.stateNode;if(typeof r.componentDidMount=="function"){var i=t.return;try{r.componentDidMount()}catch(c){Lt(t,i,c)}}var a=t.return;try{hg(t)}catch(c){Lt(t,a,c)}break;case 5:var l=t.return;try{hg(t)}catch(c){Lt(t,l,c)}}}catch(c){Lt(t,t.return,c)}if(t===e){Te=null;break}var o=t.sibling;if(o!==null){o.return=t.return,Te=o;break}Te=t.return}}var N2=Math.ceil,Kd=Jr.ReactCurrentDispatcher,_v=Jr.ReactCurrentOwner,ks=Jr.ReactCurrentBatchConfig,lt=0,un=null,Wt=null,mn=0,Xn=0,tl=Pi(0),Zt=0,oc=null,ua=0,zh=0,zv=0,Fo=null,zn=null,Uv=0,Nl=1/0,Er=null,Vd=!1,pg=null,xi=null,Su=!1,ci=null,Gd=0,_o=0,gg=null,od=-1,cd=0;function $n(){return lt&6?_t():od!==-1?od:od=_t()}function vi(e){return e.mode&1?lt&2&&mn!==0?mn&-mn:l2.transition!==null?(cd===0&&(cd=AS()),cd):(e=xt,e!==0||(e=window.event,e=e===void 0?16:DS(e.type)),e):1}function Fs(e,t,s,r){if(50<_o)throw _o=0,gg=null,Error(xe(185));Mc(e,s,r),(!(lt&2)||e!==un)&&(e===un&&(!(lt&2)&&(zh|=s),Zt===4&&li(e,mn)),Kn(e,r),s===1&&lt===0&&!(t.mode&1)&&(Nl=_t()+500,Oh&&Mi()))}function Kn(e,t){var s=e.callbackNode;lM(e,t);var r=$d(e,e===un?mn:0);if(r===0)s!==null&&Jy(s),e.callbackNode=null,e.callbackPriority=0;else if(t=r&-r,e.callbackPriority!==t){if(s!=null&&Jy(s),t===1)e.tag===0?a2(Bb.bind(null,e)):eC(Bb.bind(null,e)),n2(function(){!(lt&6)&&Mi()}),s=null;else{switch(TS(r)){case 1:s=fv;break;case 4:s=CS;break;case 16:s=Td;break;case 536870912:s=ES;break;default:s=Td}s=XC(s,KC.bind(null,e))}e.callbackPriority=t,e.callbackNode=s}}function KC(e,t){if(od=-1,cd=0,lt&6)throw Error(xe(327));var s=e.callbackNode;if(dl()&&e.callbackNode!==s)return null;var r=$d(e,e===un?mn:0);if(r===0)return null;if(r&30||r&e.expiredLanes||t)t=qd(e,r);else{t=r;var i=lt;lt|=2;var a=GC();(un!==e||mn!==t)&&(Er=null,Nl=_t()+500,sa(e,t));do try{E2();break}catch(o){VC(e,o)}while(!0);Cv(),Kd.current=a,lt=i,Wt!==null?t=0:(un=null,mn=0,t=Zt)}if(t!==0){if(t===2&&(i=Wp(e),i!==0&&(r=i,t=xg(e,i))),t===1)throw s=oc,sa(e,0),li(e,r),Kn(e,_t()),s;if(t===6)li(e,r);else{if(i=e.current.alternate,!(r&30)&&!S2(i)&&(t=qd(e,r),t===2&&(a=Wp(e),a!==0&&(r=a,t=xg(e,a))),t===1))throw s=oc,sa(e,0),li(e,r),Kn(e,_t()),s;switch(e.finishedWork=i,e.finishedLanes=r,t){case 0:case 1:throw Error(xe(345));case 2:qi(e,zn,Er);break;case 3:if(li(e,r),(r&130023424)===r&&(t=Uv+500-_t(),10<t)){if($d(e,0)!==0)break;if(i=e.suspendedLanes,(i&r)!==r){$n(),e.pingedLanes|=e.suspendedLanes&i;break}e.timeoutHandle=Qp(qi.bind(null,e,zn,Er),t);break}qi(e,zn,Er);break;case 4:if(li(e,r),(r&4194240)===r)break;for(t=e.eventTimes,i=-1;0<r;){var l=31-Ls(r);a=1<<l,l=t[l],l>i&&(i=l),r&=~a}if(r=i,r=_t()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*N2(r/1960))-r,10<r){e.timeoutHandle=Qp(qi.bind(null,e,zn,Er),r);break}qi(e,zn,Er);break;case 5:qi(e,zn,Er);break;default:throw Error(xe(329))}}}return Kn(e,_t()),e.callbackNode===s?KC.bind(null,e):null}function xg(e,t){var s=Fo;return e.current.memoizedState.isDehydrated&&(sa(e,t).flags|=256),e=qd(e,t),e!==2&&(t=zn,zn=s,t!==null&&vg(t)),e}function vg(e){zn===null?zn=e:zn.push.apply(zn,e)}function S2(e){for(var t=e;;){if(t.flags&16384){var s=t.updateQueue;if(s!==null&&(s=s.stores,s!==null))for(var r=0;r<s.length;r++){var i=s[r],a=i.getSnapshot;i=i.value;try{if(!Us(a(),i))return!1}catch{return!1}}}if(s=t.child,t.subtreeFlags&16384&&s!==null)s.return=t,t=s;else{if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return!0;t=t.return}t.sibling.return=t.return,t=t.sibling}}return!0}function li(e,t){for(t&=~zv,t&=~zh,e.suspendedLanes|=t,e.pingedLanes&=~t,e=e.expirationTimes;0<t;){var s=31-Ls(t),r=1<<s;e[s]=-1,t&=~r}}function Bb(e){if(lt&6)throw Error(xe(327));dl();var t=$d(e,0);if(!(t&1))return Kn(e,_t()),null;var s=qd(e,t);if(e.tag!==0&&s===2){var r=Wp(e);r!==0&&(t=r,s=xg(e,r))}if(s===1)throw s=oc,sa(e,0),li(e,t),Kn(e,_t()),s;if(s===6)throw Error(xe(345));return e.finishedWork=e.current.alternate,e.finishedLanes=t,qi(e,zn,Er),Kn(e,_t()),null}function Bv(e,t){var s=lt;lt|=1;try{return e(t)}finally{lt=s,lt===0&&(Nl=_t()+500,Oh&&Mi())}}function da(e){ci!==null&&ci.tag===0&&!(lt&6)&&dl();var t=lt;lt|=1;var s=ks.transition,r=xt;try{if(ks.transition=null,xt=1,e)return e()}finally{xt=r,ks.transition=s,lt=t,!(lt&6)&&Mi()}}function Wv(){Xn=tl.current,At(tl)}function sa(e,t){e.finishedWork=null,e.finishedLanes=0;var s=e.timeoutHandle;if(s!==-1&&(e.timeoutHandle=-1,t2(s)),Wt!==null)for(s=Wt.return;s!==null;){var r=s;switch(kv(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Dd();break;case 3:bl(),At(Wn),At(Nn),Iv();break;case 5:Rv(r);break;case 4:bl();break;case 13:At(Rt);break;case 19:At(Rt);break;case 10:Ev(r.type._context);break;case 22:case 23:Wv()}s=s.return}if(un=e,Wt=e=ji(e.current,null),mn=Xn=t,Zt=0,oc=null,zv=zh=ua=0,zn=Fo=null,Zi!==null){for(t=0;t<Zi.length;t++)if(s=Zi[t],r=s.interleaved,r!==null){s.interleaved=null;var i=r.next,a=s.pending;if(a!==null){var l=a.next;a.next=i,r.next=l}s.pending=r}Zi=null}return e}function VC(e,t){do{var s=Wt;try{if(Cv(),id.current=Hd,Wd){for(var r=It.memoizedState;r!==null;){var i=r.queue;i!==null&&(i.pending=null),r=r.next}Wd=!1}if(ca=0,rn=Jt=It=null,Oo=!1,ic=0,_v.current=null,s===null||s.return===null){Zt=1,oc=t,Wt=null;break}e:{var a=e,l=s.return,o=s,c=t;if(t=mn,o.flags|=32768,c!==null&&typeof c=="object"&&typeof c.then=="function"){var u=c,h=o,f=h.tag;if(!(h.mode&1)&&(f===0||f===11||f===15)){var m=h.alternate;m?(h.updateQueue=m.updateQueue,h.memoizedState=m.memoizedState,h.lanes=m.lanes):(h.updateQueue=null,h.memoizedState=null)}var p=Tb(l);if(p!==null){p.flags&=-257,$b(p,l,o,a,t),p.mode&1&&Ab(a,u,t),t=p,c=u;var g=t.updateQueue;if(g===null){var v=new Set;v.add(c),t.updateQueue=v}else g.add(c);break e}else{if(!(t&1)){Ab(a,u,t),Hv();break e}c=Error(xe(426))}}else if($t&&o.mode&1){var b=Tb(l);if(b!==null){!(b.flags&65536)&&(b.flags|=256),$b(b,l,o,a,t),Nv(kl(c,o));break e}}a=c=kl(c,o),Zt!==4&&(Zt=2),Fo===null?Fo=[a]:Fo.push(a),a=l;do{switch(a.tag){case 3:a.flags|=65536,t&=-t,a.lanes|=t;var j=TC(a,c,t);bb(a,j);break e;case 1:o=c;var x=a.type,w=a.stateNode;if(!(a.flags&128)&&(typeof x.getDerivedStateFromError=="function"||w!==null&&typeof w.componentDidCatch=="function"&&(xi===null||!xi.has(w)))){a.flags|=65536,t&=-t,a.lanes|=t;var y=$C(a,o,t);bb(a,y);break e}}a=a.return}while(a!==null)}YC(s)}catch(k){t=k,Wt===s&&s!==null&&(Wt=s=s.return);continue}break}while(!0)}function GC(){var e=Kd.current;return Kd.current=Hd,e===null?Hd:e}function Hv(){(Zt===0||Zt===3||Zt===2)&&(Zt=4),un===null||!(ua&268435455)&&!(zh&268435455)||li(un,mn)}function qd(e,t){var s=lt;lt|=2;var r=GC();(un!==e||mn!==t)&&(Er=null,sa(e,t));do try{C2();break}catch(i){VC(e,i)}while(!0);if(Cv(),lt=s,Kd.current=r,Wt!==null)throw Error(xe(261));return un=null,mn=0,Zt}function C2(){for(;Wt!==null;)qC(Wt)}function E2(){for(;Wt!==null&&!XP();)qC(Wt)}function qC(e){var t=QC(e.alternate,e,Xn);e.memoizedProps=e.pendingProps,t===null?YC(e):Wt=t,_v.current=null}function YC(e){var t=e;do{var s=t.alternate;if(e=t.return,t.flags&32768){if(s=w2(s,t),s!==null){s.flags&=32767,Wt=s;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{Zt=6,Wt=null;return}}else if(s=j2(s,t,Xn),s!==null){Wt=s;return}if(t=t.sibling,t!==null){Wt=t;return}Wt=t=e}while(t!==null);Zt===0&&(Zt=5)}function qi(e,t,s){var r=xt,i=ks.transition;try{ks.transition=null,xt=1,A2(e,t,s,r)}finally{ks.transition=i,xt=r}return null}function A2(e,t,s,r){do dl();while(ci!==null);if(lt&6)throw Error(xe(327));s=e.finishedWork;var i=e.finishedLanes;if(s===null)return null;if(e.finishedWork=null,e.finishedLanes=0,s===e.current)throw Error(xe(177));e.callbackNode=null,e.callbackPriority=0;var a=s.lanes|s.childLanes;if(oM(e,a),e===un&&(Wt=un=null,mn=0),!(s.subtreeFlags&2064)&&!(s.flags&2064)||Su||(Su=!0,XC(Td,function(){return dl(),null})),a=(s.flags&15990)!==0,s.subtreeFlags&15990||a){a=ks.transition,ks.transition=null;var l=xt;xt=1;var o=lt;lt|=4,_v.current=null,b2(e,s),WC(s,e),qM(Yp),Rd=!!qp,Yp=qp=null,e.current=s,k2(s),ZP(),lt=o,xt=l,ks.transition=a}else e.current=s;if(Su&&(Su=!1,ci=e,Gd=i),a=e.pendingLanes,a===0&&(xi=null),nM(s.stateNode),Kn(e,_t()),t!==null)for(r=e.onRecoverableError,s=0;s<t.length;s++)i=t[s],r(i.value,{componentStack:i.stack,digest:i.digest});if(Vd)throw Vd=!1,e=pg,pg=null,e;return Gd&1&&e.tag!==0&&dl(),a=e.pendingLanes,a&1?e===gg?_o++:(_o=0,gg=e):_o=0,Mi(),null}function dl(){if(ci!==null){var e=TS(Gd),t=ks.transition,s=xt;try{if(ks.transition=null,xt=16>e?16:e,ci===null)var r=!1;else{if(e=ci,ci=null,Gd=0,lt&6)throw Error(xe(331));var i=lt;for(lt|=4,Te=e.current;Te!==null;){var a=Te,l=a.child;if(Te.flags&16){var o=a.deletions;if(o!==null){for(var c=0;c<o.length;c++){var u=o[c];for(Te=u;Te!==null;){var h=Te;switch(h.tag){case 0:case 11:case 15:Lo(8,h,a)}var f=h.child;if(f!==null)f.return=h,Te=f;else for(;Te!==null;){h=Te;var m=h.sibling,p=h.return;if(zC(h),h===u){Te=null;break}if(m!==null){m.return=p,Te=m;break}Te=p}}}var g=a.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)}}Te=a}}if(a.subtreeFlags&2064&&l!==null)l.return=a,Te=l;else e:for(;Te!==null;){if(a=Te,a.flags&2048)switch(a.tag){case 0:case 11:case 15:Lo(9,a,a.return)}var j=a.sibling;if(j!==null){j.return=a.return,Te=j;break e}Te=a.return}}var x=e.current;for(Te=x;Te!==null;){l=Te;var w=l.child;if(l.subtreeFlags&2064&&w!==null)w.return=l,Te=w;else e:for(l=x;Te!==null;){if(o=Te,o.flags&2048)try{switch(o.tag){case 0:case 11:case 15:_h(9,o)}}catch(k){Lt(o,o.return,k)}if(o===l){Te=null;break e}var y=o.sibling;if(y!==null){y.return=o.return,Te=y;break e}Te=o.return}}if(lt=i,Mi(),dr&&typeof dr.onPostCommitFiberRoot=="function")try{dr.onPostCommitFiberRoot(Rh,e)}catch{}r=!0}return r}finally{xt=s,ks.transition=t}}return!1}function Wb(e,t,s){t=kl(s,t),t=TC(e,t,1),e=gi(e,t,1),t=$n(),e!==null&&(Mc(e,1,t),Kn(e,t))}function Lt(e,t,s){if(e.tag===3)Wb(e,e,s);else for(;t!==null;){if(t.tag===3){Wb(t,e,s);break}else if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(xi===null||!xi.has(r))){e=kl(s,e),e=$C(t,e,1),t=gi(t,e,1),e=$n(),t!==null&&(Mc(t,1,e),Kn(t,e));break}}t=t.return}}function T2(e,t,s){var r=e.pingCache;r!==null&&r.delete(t),t=$n(),e.pingedLanes|=e.suspendedLanes&s,un===e&&(mn&s)===s&&(Zt===4||Zt===3&&(mn&130023424)===mn&&500>_t()-Uv?sa(e,0):zv|=s),Kn(e,t)}function JC(e,t){t===0&&(e.mode&1?(t=pu,pu<<=1,!(pu&130023424)&&(pu=4194304)):t=1);var s=$n();e=Hr(e,t),e!==null&&(Mc(e,t,s),Kn(e,s))}function $2(e){var t=e.memoizedState,s=0;t!==null&&(s=t.retryLane),JC(e,s)}function R2(e,t){var s=0;switch(e.tag){case 13:var r=e.stateNode,i=e.memoizedState;i!==null&&(s=i.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(xe(314))}r!==null&&r.delete(t),JC(e,s)}var QC;QC=function(e,t,s){if(e!==null)if(e.memoizedProps!==t.pendingProps||Wn.current)Un=!0;else{if(!(e.lanes&s)&&!(t.flags&128))return Un=!1,v2(e,t,s);Un=!!(e.flags&131072)}else Un=!1,$t&&t.flags&1048576&&tC(t,Fd,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;ld(e,t),e=t.pendingProps;var i=jl(t,Nn.current);ul(t,s),i=Mv(null,t,r,e,i,s);var a=Dv();return t.flags|=1,typeof i=="object"&&i!==null&&typeof i.render=="function"&&i.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,Hn(r)?(a=!0,Od(t)):a=!1,t.memoizedState=i.state!==null&&i.state!==void 0?i.state:null,Tv(t),i.updater=Fh,t.stateNode=i,i._reactInternals=t,rg(t,r,e,s),t=lg(null,t,r,!0,a,s)):(t.tag=0,$t&&a&&bv(t),An(null,t,i,s),t=t.child),t;case 16:r=t.elementType;e:{switch(ld(e,t),e=t.pendingProps,i=r._init,r=i(r._payload),t.type=r,i=t.tag=P2(r),e=Is(r,e),i){case 0:t=ag(null,t,r,e,s);break e;case 1:t=Pb(null,t,r,e,s);break e;case 11:t=Rb(null,t,r,e,s);break e;case 14:t=Ib(null,t,r,Is(r.type,e),s);break e}throw Error(xe(306,r,""))}return t;case 0:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:Is(r,i),ag(e,t,r,i,s);case 1:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:Is(r,i),Pb(e,t,r,i,s);case 3:e:{if(MC(t),e===null)throw Error(xe(387));r=t.pendingProps,a=t.memoizedState,i=a.element,lC(e,t),Ud(t,r,null,s);var l=t.memoizedState;if(r=l.element,a.isDehydrated)if(a={element:r,isDehydrated:!1,cache:l.cache,pendingSuspenseBoundaries:l.pendingSuspenseBoundaries,transitions:l.transitions},t.updateQueue.baseState=a,t.memoizedState=a,t.flags&256){i=kl(Error(xe(423)),t),t=Mb(e,t,r,s,i);break e}else if(r!==i){i=kl(Error(xe(424)),t),t=Mb(e,t,r,s,i);break e}else for(es=pi(t.stateNode.containerInfo.firstChild),ns=t,$t=!0,Ms=null,s=iC(t,null,r,s),t.child=s;s;)s.flags=s.flags&-3|4096,s=s.sibling;else{if(wl(),r===i){t=Kr(e,t,s);break e}An(e,t,r,s)}t=t.child}return t;case 5:return oC(t),e===null&&tg(t),r=t.type,i=t.pendingProps,a=e!==null?e.memoizedProps:null,l=i.children,Jp(r,i)?l=null:a!==null&&Jp(r,a)&&(t.flags|=32),PC(e,t),An(e,t,l,s),t.child;case 6:return e===null&&tg(t),null;case 13:return DC(e,t,s);case 4:return $v(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=yl(t,null,r,s):An(e,t,r,s),t.child;case 11:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:Is(r,i),Rb(e,t,r,i,s);case 7:return An(e,t,t.pendingProps,s),t.child;case 8:return An(e,t,t.pendingProps.children,s),t.child;case 12:return An(e,t,t.pendingProps.children,s),t.child;case 10:e:{if(r=t.type._context,i=t.pendingProps,a=t.memoizedProps,l=i.value,St(_d,r._currentValue),r._currentValue=l,a!==null)if(Us(a.value,l)){if(a.children===i.children&&!Wn.current){t=Kr(e,t,s);break e}}else for(a=t.child,a!==null&&(a.return=t);a!==null;){var o=a.dependencies;if(o!==null){l=a.child;for(var c=o.firstContext;c!==null;){if(c.context===r){if(a.tag===1){c=Or(-1,s&-s),c.tag=2;var u=a.updateQueue;if(u!==null){u=u.shared;var h=u.pending;h===null?c.next=c:(c.next=h.next,h.next=c),u.pending=c}}a.lanes|=s,c=a.alternate,c!==null&&(c.lanes|=s),ng(a.return,s,t),o.lanes|=s;break}c=c.next}}else if(a.tag===10)l=a.type===t.type?null:a.child;else if(a.tag===18){if(l=a.return,l===null)throw Error(xe(341));l.lanes|=s,o=l.alternate,o!==null&&(o.lanes|=s),ng(l,s,t),l=a.sibling}else l=a.child;if(l!==null)l.return=a;else for(l=a;l!==null;){if(l===t){l=null;break}if(a=l.sibling,a!==null){a.return=l.return,l=a;break}l=l.return}a=l}An(e,t,i.children,s),t=t.child}return t;case 9:return i=t.type,r=t.pendingProps.children,ul(t,s),i=Ss(i),r=r(i),t.flags|=1,An(e,t,r,s),t.child;case 14:return r=t.type,i=Is(r,t.pendingProps),i=Is(r.type,i),Ib(e,t,r,i,s);case 15:return RC(e,t,t.type,t.pendingProps,s);case 17:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:Is(r,i),ld(e,t),t.tag=1,Hn(r)?(e=!0,Od(t)):e=!1,ul(t,s),AC(t,r,i),rg(t,r,i,s),lg(null,t,r,!0,e,s);case 19:return OC(e,t,s);case 22:return IC(e,t,s)}throw Error(xe(156,t.tag))};function XC(e,t){return SS(e,t)}function I2(e,t,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=t,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 bs(e,t,s,r){return new I2(e,t,s,r)}function Kv(e){return e=e.prototype,!(!e||!e.isReactComponent)}function P2(e){if(typeof e=="function")return Kv(e)?1:0;if(e!=null){if(e=e.$$typeof,e===uv)return 11;if(e===dv)return 14}return 2}function ji(e,t){var s=e.alternate;return s===null?(s=bs(e.tag,t,e.key,e.mode),s.elementType=e.elementType,s.type=e.type,s.stateNode=e.stateNode,s.alternate=e,e.alternate=s):(s.pendingProps=t,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,t=e.dependencies,s.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},s.sibling=e.sibling,s.index=e.index,s.ref=e.ref,s}function ud(e,t,s,r,i,a){var l=2;if(r=e,typeof e=="function")Kv(e)&&(l=1);else if(typeof e=="string")l=5;else e:switch(e){case Ka:return ra(s.children,i,a,t);case cv:l=8,i|=8;break;case Ap:return e=bs(12,s,t,i|2),e.elementType=Ap,e.lanes=a,e;case Tp:return e=bs(13,s,t,i),e.elementType=Tp,e.lanes=a,e;case $p:return e=bs(19,s,t,i),e.elementType=$p,e.lanes=a,e;case oS:return Uh(s,i,a,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case aS:l=10;break e;case lS:l=9;break e;case uv:l=11;break e;case dv:l=14;break e;case ri:l=16,r=null;break e}throw Error(xe(130,e==null?e:typeof e,""))}return t=bs(l,s,t,i),t.elementType=e,t.type=r,t.lanes=a,t}function ra(e,t,s,r){return e=bs(7,e,r,t),e.lanes=s,e}function Uh(e,t,s,r){return e=bs(22,e,r,t),e.elementType=oS,e.lanes=s,e.stateNode={isHidden:!1},e}function jm(e,t,s){return e=bs(6,e,null,t),e.lanes=s,e}function wm(e,t,s){return t=bs(4,e.children!==null?e.children:[],e.key,t),t.lanes=s,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function M2(e,t,s,r,i){this.tag=t,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=em(0),this.expirationTimes=em(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=em(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function Vv(e,t,s,r,i,a,l,o,c){return e=new M2(e,t,s,o,c),t===1?(t=1,a===!0&&(t|=8)):t=0,a=bs(3,null,null,t),e.current=a,a.stateNode=e,a.memoizedState={element:r,isDehydrated:s,cache:null,transitions:null,pendingSuspenseBoundaries:null},Tv(a),e}function D2(e,t,s){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:Ha,key:r==null?null:""+r,children:e,containerInfo:t,implementation:s}}function ZC(e){if(!e)return Ni;e=e._reactInternals;e:{if(va(e)!==e||e.tag!==1)throw Error(xe(170));var t=e;do{switch(t.tag){case 3:t=t.stateNode.context;break e;case 1:if(Hn(t.type)){t=t.stateNode.__reactInternalMemoizedMergedChildContext;break e}}t=t.return}while(t!==null);throw Error(xe(171))}if(e.tag===1){var s=e.type;if(Hn(s))return ZS(e,s,t)}return t}function e1(e,t,s,r,i,a,l,o,c){return e=Vv(s,r,!0,e,i,a,l,o,c),e.context=ZC(null),s=e.current,r=$n(),i=vi(s),a=Or(r,i),a.callback=t??null,gi(s,a,i),e.current.lanes=i,Mc(e,i,r),Kn(e,r),e}function Bh(e,t,s,r){var i=t.current,a=$n(),l=vi(i);return s=ZC(s),t.context===null?t.context=s:t.pendingContext=s,t=Or(a,l),t.payload={element:e},r=r===void 0?null:r,r!==null&&(t.callback=r),e=gi(i,t,l),e!==null&&(Fs(e,i,l,a),rd(e,i,l)),l}function Yd(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 Hb(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var s=e.retryLane;e.retryLane=s!==0&&s<t?s:t}}function Gv(e,t){Hb(e,t),(e=e.alternate)&&Hb(e,t)}function O2(){return null}var t1=typeof reportError=="function"?reportError:function(e){console.error(e)};function qv(e){this._internalRoot=e}Wh.prototype.render=qv.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(xe(409));Bh(e,t,null,null)};Wh.prototype.unmount=qv.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;da(function(){Bh(null,e,null,null)}),t[Wr]=null}};function Wh(e){this._internalRoot=e}Wh.prototype.unstable_scheduleHydration=function(e){if(e){var t=IS();e={blockedOn:null,target:e,priority:t};for(var s=0;s<ai.length&&t!==0&&t<ai[s].priority;s++);ai.splice(s,0,e),s===0&&MS(e)}};function Yv(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function Hh(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function Kb(){}function L2(e,t,s,r,i){if(i){if(typeof r=="function"){var a=r;r=function(){var u=Yd(l);a.call(u)}}var l=e1(t,r,e,0,null,!1,!1,"",Kb);return e._reactRootContainer=l,e[Wr]=l.current,ec(e.nodeType===8?e.parentNode:e),da(),l}for(;i=e.lastChild;)e.removeChild(i);if(typeof r=="function"){var o=r;r=function(){var u=Yd(c);o.call(u)}}var c=Vv(e,0,!1,null,null,!1,!1,"",Kb);return e._reactRootContainer=c,e[Wr]=c.current,ec(e.nodeType===8?e.parentNode:e),da(function(){Bh(t,c,s,r)}),c}function Kh(e,t,s,r,i){var a=s._reactRootContainer;if(a){var l=a;if(typeof i=="function"){var o=i;i=function(){var c=Yd(l);o.call(c)}}Bh(t,l,e,i)}else l=L2(s,t,e,i,r);return Yd(l)}$S=function(e){switch(e.tag){case 3:var t=e.stateNode;if(t.current.memoizedState.isDehydrated){var s=So(t.pendingLanes);s!==0&&(mv(t,s|1),Kn(t,_t()),!(lt&6)&&(Nl=_t()+500,Mi()))}break;case 13:da(function(){var r=Hr(e,1);if(r!==null){var i=$n();Fs(r,e,1,i)}}),Gv(e,1)}};pv=function(e){if(e.tag===13){var t=Hr(e,134217728);if(t!==null){var s=$n();Fs(t,e,134217728,s)}Gv(e,134217728)}};RS=function(e){if(e.tag===13){var t=vi(e),s=Hr(e,t);if(s!==null){var r=$n();Fs(s,e,t,r)}Gv(e,t)}};IS=function(){return xt};PS=function(e,t){var s=xt;try{return xt=e,t()}finally{xt=s}};zp=function(e,t,s){switch(t){case"input":if(Pp(e,s),t=s.name,s.type==="radio"&&t!=null){for(s=e;s.parentNode;)s=s.parentNode;for(s=s.querySelectorAll("input[name="+JSON.stringify(""+t)+'][type="radio"]'),t=0;t<s.length;t++){var r=s[t];if(r!==e&&r.form===e.form){var i=Dh(r);if(!i)throw Error(xe(90));uS(r),Pp(r,i)}}}break;case"textarea":hS(e,s);break;case"select":t=s.value,t!=null&&al(e,!!s.multiple,t,!1)}};jS=Bv;wS=da;var F2={usingClientEntryPoint:!1,Events:[Oc,Ya,Dh,xS,vS,Bv]},po={findFiberByHostInstance:Xi,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},_2={bundleType:po.bundleType,version:po.version,rendererPackageName:po.rendererPackageName,rendererConfig:po.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:Jr.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=kS(e),e===null?null:e.stateNode},findFiberByHostInstance:po.findFiberByHostInstance||O2,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 Cu=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Cu.isDisabled&&Cu.supportsFiber)try{Rh=Cu.inject(_2),dr=Cu}catch{}}ls.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=F2;ls.createPortal=function(e,t){var s=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!Yv(t))throw Error(xe(200));return D2(e,t,null,s)};ls.createRoot=function(e,t){if(!Yv(e))throw Error(xe(299));var s=!1,r="",i=t1;return t!=null&&(t.unstable_strictMode===!0&&(s=!0),t.identifierPrefix!==void 0&&(r=t.identifierPrefix),t.onRecoverableError!==void 0&&(i=t.onRecoverableError)),t=Vv(e,1,!1,null,null,s,!1,r,i),e[Wr]=t.current,ec(e.nodeType===8?e.parentNode:e),new qv(t)};ls.findDOMNode=function(e){if(e==null)return null;if(e.nodeType===1)return e;var t=e._reactInternals;if(t===void 0)throw typeof e.render=="function"?Error(xe(188)):(e=Object.keys(e).join(","),Error(xe(268,e)));return e=kS(t),e=e===null?null:e.stateNode,e};ls.flushSync=function(e){return da(e)};ls.hydrate=function(e,t,s){if(!Hh(t))throw Error(xe(200));return Kh(null,e,t,!0,s)};ls.hydrateRoot=function(e,t,s){if(!Yv(e))throw Error(xe(405));var r=s!=null&&s.hydratedSources||null,i=!1,a="",l=t1;if(s!=null&&(s.unstable_strictMode===!0&&(i=!0),s.identifierPrefix!==void 0&&(a=s.identifierPrefix),s.onRecoverableError!==void 0&&(l=s.onRecoverableError)),t=e1(t,null,e,1,s??null,i,!1,a,l),e[Wr]=t.current,ec(e),r)for(e=0;e<r.length;e++)s=r[e],i=s._getVersion,i=i(s._source),t.mutableSourceEagerHydrationData==null?t.mutableSourceEagerHydrationData=[s,i]:t.mutableSourceEagerHydrationData.push(s,i);return new Wh(t)};ls.render=function(e,t,s){if(!Hh(t))throw Error(xe(200));return Kh(null,e,t,!1,s)};ls.unmountComponentAtNode=function(e){if(!Hh(e))throw Error(xe(40));return e._reactRootContainer?(da(function(){Kh(null,null,e,!1,function(){e._reactRootContainer=null,e[Wr]=null})}),!0):!1};ls.unstable_batchedUpdates=Bv;ls.unstable_renderSubtreeIntoContainer=function(e,t,s,r){if(!Hh(s))throw Error(xe(200));if(e==null||e._reactInternals===void 0)throw Error(xe(38));return Kh(e,t,s,!1,r)};ls.version="18.3.1-next-f1338f8080-20240426";function n1(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n1)}catch(e){console.error(e)}}n1(),nS.exports=ls;var Ul=nS.exports,s1,Vb=Ul;s1=Vb.createRoot,Vb.hydrateRoot;var z2=Object.defineProperty,Bl=(e,t)=>z2(e,"name",{value:t,configurable:!0}),r1=!!(typeof window<"u"&&window.document&&window.document.createElement);function Me(e,t,{checkForDefaultPrevented:s=!0}={}){return Bl(function(i){if(e==null||e(i),s===!1||!i||!i.defaultPrevented)return t==null?void 0:t(i)},"handleEvent")}Bl(Me,"composeEventHandlers");function U2(e){var t;if(!r1)throw new Error("Cannot access window outside of the DOM");return((t=e==null?void 0:e.ownerDocument)==null?void 0:t.defaultView)??window}Bl(U2,"getOwnerWindow");function jg(e){if(!r1)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}Bl(jg,"getOwnerDocument");function i1(e,t=!1){const{activeElement:s}=jg(e);if(!(s!=null&&s.nodeName))return null;if(a1(s)&&s.contentDocument)return i1(s.contentDocument.body,t);if(t){const r=s.getAttribute("aria-activedescendant");if(r){const i=jg(s).getElementById(r);if(i)return i}}return s}Bl(i1,"getActiveElement");function a1(e){return e.tagName==="IFRAME"}Bl(a1,"isFrame");var B2=Object.defineProperty,Jv=(e,t)=>B2(e,"name",{value:t,configurable:!0});function wg(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}Jv(wg,"setRef");function l1(...e){return t=>{let s=!1;const r=e.map(i=>{const a=wg(i,t);return!s&&typeof a=="function"&&(s=!0),a});if(s)return()=>{for(let i=0;i<r.length;i++){const a=r[i];typeof a=="function"?a():wg(e[i],null)}}}}Jv(l1,"composeRefs");function bt(...e){return d.useCallback(l1(...e),e)}Jv(bt,"useComposedRefs");var W2=Object.defineProperty,ys=(e,t)=>W2(e,"name",{value:t,configurable:!0});function H2(e,t){const s=d.createContext(t);s.displayName=e+"Context";const r=ys(a=>{const{children:l,...o}=a,c=d.useMemo(()=>o,Object.values(o));return n.jsx(s.Provider,{value:c,children:l})},"Provider");r.displayName=e+"Provider";function i(a,l={}){const{optional:o=!1}=l,c=d.useContext(s);if(c)return c;if(t!==void 0)return t;if(!o)throw new Error(`\`${a}\` must be used within \`${e}\``)}return ys(i,"useContext"),[r,i]}ys(H2,"createContext");function Gs(e,t=[]){let s=[];function r(a,l){const o=d.createContext(l);o.displayName=a+"Context";const c=s.length;s=[...s,l];const u=ys(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=d.useMemo(()=>g,Object.values(g));return n.jsx(v.Provider,{value:b,children:p})},"Provider");u.displayName=a+"Provider";function h(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=d.useContext(v);if(b)return b;if(l!==void 0)return l;if(!g)throw new Error(`\`${f}\` must be used within \`${a}\``)}return ys(h,"useContext"),[u,h]}ys(r,"createContext");const i=ys(()=>{const a=s.map(l=>d.createContext(l));return ys(function(o){const c=(o==null?void 0:o[e])||a;return d.useMemo(()=>({[`__scope${e}`]:{...o,[e]:c}}),[o,c])},"useScope")},"createScope");return i.scopeName=e,[r,o1(i,...t)]}ys(Gs,"createContextScope");function o1(...e){const t=e[0];if(e.length===1)return t;const s=ys(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return ys(function(a){const l=r.reduce((o,{useScope:c,scopeName:u})=>{const f=c(a)[`__scope${u}`];return{...o,...f}},{});return d.useMemo(()=>({[`__scope${t.scopeName}`]:l}),[l])},"useComposedScopes")},"createScope");return s.scopeName=t.scopeName,s}ys(o1,"composeContextScopes");var K2=Object.defineProperty,qs=(e,t)=>K2(e,"name",{value:t,configurable:!0});function Si(e){const t=d.forwardRef((s,r)=>{let{children:i,...a}=s,l=null,o=!1;const c=[];yg(i)&&typeof Eu=="function"&&(i=Eu(i._payload)),d.Children.forEach(i,m=>{var p;if(f1(m)){o=!0;const g=m;let v="child"in g.props?g.props.child:g.props.children;yg(v)&&typeof Eu=="function"&&(v=Eu(v._payload)),l=V2(g,v),c.push((p=l==null?void 0:l.props)==null?void 0:p.children)}else c.push(m)}),l?l=d.cloneElement(l,void 0,c):!o&&d.Children.count(i)===1&&d.isValidElement(i)&&(l=i);const u=l?h1(l):void 0,h=bt(r,u);if(!l){if(i||i===0)throw new Error(o?Y2(e):q2(e));return i}const f=d1(a,l.props??{});return l.type!==d.Fragment&&(f.ref=r?h:u),d.cloneElement(l,f)});return t.displayName=`${e}.Slot`,t}qs(Si,"createSlot");var c1=Symbol.for("radix.slottable");function u1(e){const t=qs(s=>"child"in s?s.children(s.child):s.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=c1,t}qs(u1,"createSlottable");var V2=qs((e,t)=>{if("child"in e.props){const s=e.props.child;return d.isValidElement(s)?d.cloneElement(s,void 0,e.props.children(s.props.children)):null}return d.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function d1(e,t){const s={...t};for(const r in t){const i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?s[r]=(...o)=>{const c=a(...o);return i(...o),c}:i&&(s[r]=i):r==="style"?s[r]={...i,...a}:r==="className"&&(s[r]=[i,a].filter(Boolean).join(" "))}return{...e,...s}}qs(d1,"mergeProps");function h1(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,s=t&&"isReactWarning"in t&&t.isReactWarning;return s?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,s=t&&"isReactWarning"in t&&t.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}qs(h1,"getElementRef");function f1(e){return d.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===c1}qs(f1,"isSlottable");var G2=Symbol.for("react.lazy");function yg(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===G2&&"_payload"in e&&m1(e._payload)}qs(yg,"isLazyComponent");function m1(e){return typeof e=="object"&&e!==null&&"then"in e}qs(m1,"isPromiseLike");var q2=qs(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),Y2=qs(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Eu=Fl[" use ".trim().toString()],J2=Object.defineProperty,an=(e,t)=>J2(e,"name",{value:t,configurable:!0});function Vh(e){const t=e+"CollectionProvider",[s,r]=Gs(t),[i,a]=s(t,{collectionRef:{current:null},itemMap:new Map}),l=an(v=>{const{scope:b,children:j}=v,x=d.useRef(null),w=d.useRef(new Map).current;return n.jsx(i,{scope:b,itemMap:w,collectionRef:x,children:j})},"CollectionProvider");l.displayName=t;const o=e+"CollectionSlot",c=Si(o),u=d.forwardRef((v,b)=>{const{scope:j,children:x}=v,w=a(o,j),y=bt(b,w.collectionRef);return n.jsx(c,{ref:y,children:x})});u.displayName=o;const h=e+"CollectionItemSlot",f="data-radix-collection-item",m=Si(h),p=d.forwardRef((v,b)=>{const{scope:j,children:x,...w}=v,y=d.useRef(null),k=bt(b,y),N=a(h,j);return d.useEffect(()=>(N.itemMap.set(y,{ref:y,...w}),()=>void N.itemMap.delete(y))),n.jsx(m,{[f]:"",ref:k,children:x})});p.displayName=h;function g(v){const b=a(e+"CollectionConsumer",v);return d.useCallback(()=>{const x=b.collectionRef.current;if(!x)return[];const w=Array.from(x.querySelectorAll(`[${f}]`));return Array.from(b.itemMap.values()).sort((N,S)=>w.indexOf(N.ref.current)-w.indexOf(S.ref.current))},[b.collectionRef,b.itemMap])}return an(g,"useCollection"),[{Provider:l,Slot:u,ItemSlot:p},g,r]}an(Vh,"createCollection");var Gb=new WeakMap,Bt,Zn,ym=(Zn=class extends Map{constructor(s){super(s);Ly(this,Bt);qf(this,Bt,[...super.keys()]),Gb.set(this,!0)}set(s,r){return Gb.get(this)&&(this.has(s)?jn(this,Bt)[jn(this,Bt).indexOf(s)]=s:jn(this,Bt).push(s)),super.set(s,r),this}insert(s,r,i){const a=this.has(r),l=jn(this,Bt).length,o=Qv(s);let c=o>=0?o:l+o;const u=c<0||c>=l?-1:c;if(u===this.size||a&&u===this.size-1||u===-1)return this.set(r,i),this;const h=this.size+(a?0:1);o<0&&c++;const f=[...jn(this,Bt)];let m,p=!1;for(let g=c;g<h;g++)if(c===g){let v=f[g];f[g]===r&&(v=f[g+1]),a&&this.delete(r),m=this.get(v),this.set(r,i)}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,i){const a=new Zn(this);return a.insert(s,r,i),a}before(s){const r=jn(this,Bt).indexOf(s)-1;if(!(r<0))return this.entryAt(r)}setBefore(s,r,i){const a=jn(this,Bt).indexOf(s);return a===-1?this:this.insert(a,r,i)}after(s){let r=jn(this,Bt).indexOf(s);if(r=r===-1||r===this.size-1?-1:r+1,r!==-1)return this.entryAt(r)}setAfter(s,r,i){const a=jn(this,Bt).indexOf(s);return a===-1?this:this.insert(a+1,r,i)}first(){return this.entryAt(0)}last(){return this.entryAt(-1)}clear(){return qf(this,Bt,[]),super.clear()}delete(s){const r=super.delete(s);return r&&jn(this,Bt).splice(jn(this,Bt).indexOf(s),1),r}deleteAt(s){const r=this.keyAt(s);return r!==void 0?this.delete(r):!1}at(s){const r=dd(jn(this,Bt),s);if(r!==void 0)return this.get(r)}entryAt(s){const r=dd(jn(this,Bt),s);if(r!==void 0)return[r,this.get(r)]}indexOf(s){return jn(this,Bt).indexOf(s)}keyAt(s){return dd(jn(this,Bt),s)}from(s,r){const i=this.indexOf(s);if(i===-1)return;let a=i+r;return a<0&&(a=0),a>=this.size&&(a=this.size-1),this.at(a)}keyFrom(s,r){const i=this.indexOf(s);if(i===-1)return;let a=i+r;return a<0&&(a=0),a>=this.size&&(a=this.size-1),this.keyAt(a)}find(s,r){let i=0;for(const a of this){if(Reflect.apply(s,r,[a,i,this]))return a;i++}}findIndex(s,r){let i=0;for(const a of this){if(Reflect.apply(s,r,[a,i,this]))return i;i++}return-1}filter(s,r){const i=[];let a=0;for(const l of this)Reflect.apply(s,r,[l,a,this])&&i.push(l),a++;return new Zn(i)}map(s,r){const i=[];let a=0;for(const l of this)i.push([l[0],Reflect.apply(s,r,[l,a,this])]),a++;return new Zn(i)}reduce(...s){const[r,i]=s;let a=0,l=i??this.at(0);for(const o of this)a===0&&s.length===1?l=o:l=Reflect.apply(r,this,[l,o,a,this]),a++;return l}reduceRight(...s){const[r,i]=s;let a=i??this.at(-1);for(let l=this.size-1;l>=0;l--){const o=this.at(l);l===this.size-1&&s.length===1?a=o:a=Reflect.apply(r,this,[a,o,l,this])}return a}toSorted(s){const r=[...this.entries()].sort(s);return new Zn(r)}toReversed(){const s=new Zn;for(let r=this.size-1;r>=0;r--){const i=this.keyAt(r),a=this.get(i);s.set(i,a)}return s}toSpliced(...s){const r=[...this.entries()];return r.splice(...s),new Zn(r)}slice(s,r){const i=new Zn;let a=this.size-1;if(s===void 0)return i;s<0&&(s=s+this.size),r!==void 0&&r>0&&(a=r-1);for(let l=s;l<=a;l++){const o=this.keyAt(l),c=this.get(o);i.set(o,c)}return i}every(s,r){let i=0;for(const a of this){if(!Reflect.apply(s,r,[a,i,this]))return!1;i++}return!0}some(s,r){let i=0;for(const a of this){if(Reflect.apply(s,r,[a,i,this]))return!0;i++}return!1}},Bt=new WeakMap,an(Zn,"OrderedDict"),Zn);function dd(e,t){if("at"in Array.prototype)return Array.prototype.at.call(e,t);const s=p1(e,t);return s===-1?void 0:e[s]}an(dd,"at");function p1(e,t){const s=e.length,r=Qv(t),i=r>=0?r:s+r;return i<0||i>=s?-1:i}an(p1,"toSafeIndex");function Qv(e){return e!==e||e===0?0:Math.trunc(e)}an(Qv,"toSafeInteger");function Q2(e){const t=e+"CollectionProvider",[s,r]=Gs(t),[i,a]=s(t,{collectionElement:null,collectionRef:{current:null},collectionRefObject:{current:null},itemMap:new ym,setItemMap:an(()=>{},"setItemMap")}),l=an(({state:w,...y})=>w?n.jsx(c,{...y,state:w}):n.jsx(o,{...y}),"CollectionProvider");l.displayName=t;const o=an(w=>{const y=b();return n.jsx(c,{...w,state:y})},"CollectionInit");o.displayName=t+"Init";const c=an(w=>{const{scope:y,children:k,state:N}=w,S=d.useRef(null),[C,E]=d.useState(null),R=bt(S,E),[I,L]=N;return d.useEffect(()=>{if(!C)return;const F=v1(()=>{});return F.observe(C,{childList:!0,subtree:!0}),()=>{F.disconnect()}},[C]),n.jsx(i,{scope:y,itemMap:I,setItemMap:L,collectionRef:R,collectionRefObject:S,collectionElement:C,children:k})},"CollectionProviderImpl");c.displayName=t+"Impl";const u=e+"CollectionSlot",h=Si(u),f=d.forwardRef((w,y)=>{const{scope:k,children:N}=w,S=a(u,k),C=bt(y,S.collectionRef);return n.jsx(h,{ref:C,children:N})});f.displayName=u;const m=e+"CollectionItemSlot",p="data-radix-collection-item",g=Si(m),v=d.forwardRef((w,y)=>{const{scope:k,children:N,...S}=w,C=d.useRef(null),[E,R]=d.useState(null),I=bt(y,C,R),L=a(m,k),{setItemMap:F}=L,T=d.useRef(S);g1(T.current,S)||(T.current=S);const M=T.current;return d.useEffect(()=>{const P=M;return F(D=>E?D.has(E)?D.set(E,{...P,element:E}).toSorted(bg):(D.set(E,{...P,element:E}),D.toSorted(bg)):D),()=>{F(D=>!E||!D.has(E)?D:(D.delete(E),new ym(D)))}},[E,M,F]),n.jsx(g,{[p]:"",ref:I,children:N})});v.displayName=m;function b(){return d.useState(new ym)}an(b,"useInitCollection");function j(w){const{itemMap:y}=a(e+"CollectionConsumer",w);return y}return an(j,"useCollection"),[{Provider:l,Slot:f,ItemSlot:v},{createCollectionScope:r,useCollection:j,useInitCollection:b}]}an(Q2,"createCollection");function g1(e,t){if(e===t)return!0;if(typeof e!="object"||typeof t!="object"||e==null||t==null)return!1;const s=Object.keys(e),r=Object.keys(t);if(s.length!==r.length)return!1;for(const i of s)if(!Object.prototype.hasOwnProperty.call(t,i)||e[i]!==t[i])return!1;return!0}an(g1,"shallowEqual");function x1(e,t){return!!(t.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_PRECEDING)}an(x1,"isElementPreceding");function bg(e,t){return!e[1].element||!t[1].element?0:x1(e[1].element,t[1].element)?-1:1}an(bg,"sortByDocumentPosition");function v1(e){return new MutationObserver(s=>{for(const r of s)if(r.type==="childList"){e();return}})}an(v1,"getChildListObserver");var X2=Object.defineProperty,Z2=(e,t)=>X2(e,"name",{value:t,configurable:!0}),eD=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],vt=eD.reduce((e,t)=>{const s=Si(`Primitive.${t}`),r=d.forwardRef((i,a)=>{const{asChild:l,...o}=i,c=l?s:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),n.jsx(c,{...o,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Gh(e,t){e&&Ul.flushSync(()=>e.dispatchEvent(t))}Z2(Gh,"dispatchDiscreteCustomEvent");var tD=Object.defineProperty,nD=(e,t)=>tD(e,"name",{value:t,configurable:!0});function Rn(e){const t=d.useRef(e);return d.useEffect(()=>{t.current=e}),d.useMemo(()=>(...s)=>{var r;return(r=t.current)==null?void 0:r.call(t,...s)},[])}nD(Rn,"useCallbackRef");var sD=Object.defineProperty,Qt=(e,t)=>sD(e,"name",{value:t,configurable:!0}),kg="dismissableLayer.update",rD="dismissableLayer.pointerDownOutside",iD="dismissableLayer.focusOutside",qb,Xv=d.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),qh=d.forwardRef(Qt(function(t,s){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:i=!1,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:o,onInteractOutside:c,onDismiss:u,...h}=t,f=d.useContext(Xv),[m,p]=d.useState(null),g=(m==null?void 0:m.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,v]=d.useState({}),b=bt(s,p),j=Array.from(f.layers),[x]=[...f.layersWithOutsidePointerEventsDisabled].slice(-1),w=x?j.indexOf(x):-1,y=m?j.indexOf(m):-1,k=f.layersWithOutsidePointerEventsDisabled.size>0,N=y>=w,S=d.useRef(!1),C=w1(L=>{l==null||l(L),c==null||c(L),L.defaultPrevented||u==null||u()},{ownerDocument:g,deferPointerDownOutside:i,isDeferredPointerDownOutsideRef:S,dismissableSurfaces:f.dismissableSurfaces,shouldHandlePointerDownOutside:d.useCallback(L=>{if(!(L instanceof Node))return!1;const F=[...f.branches].some(T=>T.contains(L));return N&&!F},[f.branches,N])}),E=y1(L=>{if(i&&S.current)return;const F=L.target;[...f.branches].some(M=>M.contains(F))||(o==null||o(L),c==null||c(L),L.defaultPrevented||u==null||u())},g),R=m?y===j.length-1:!1,I=Rn(L=>{L.key==="Escape"&&(a==null||a(L),!L.defaultPrevented&&u&&(L.preventDefault(),u()))});return d.useEffect(()=>{if(R)return g.addEventListener("keydown",I,{capture:!0}),()=>g.removeEventListener("keydown",I,{capture:!0})},[g,R,I]),d.useEffect(()=>{if(m)return r&&(f.layersWithOutsidePointerEventsDisabled.size===0&&(qb=g.body.style.pointerEvents,g.body.style.pointerEvents="none"),f.layersWithOutsidePointerEventsDisabled.add(m)),f.layers.add(m),Ng(),()=>{r&&(f.layersWithOutsidePointerEventsDisabled.delete(m),f.layersWithOutsidePointerEventsDisabled.size===0&&(g.body.style.pointerEvents=qb))}},[m,g,r,f]),d.useEffect(()=>()=>{m&&(f.layers.delete(m),f.layersWithOutsidePointerEventsDisabled.delete(m),Ng())},[m,f]),d.useEffect(()=>{const L=Qt(()=>v({}),"handleUpdate");return document.addEventListener(kg,L),()=>document.removeEventListener(kg,L)},[]),n.jsx(vt.div,{...h,ref:b,style:{pointerEvents:k?N?"auto":"none":void 0,...t.style},onFocusCapture:Me(t.onFocusCapture,E.onFocusCapture),onBlurCapture:Me(t.onBlurCapture,E.onBlurCapture),onPointerDownCapture:Me(t.onPointerDownCapture,C.onPointerDownCapture)})},"DismissableLayer")),aD=d.forwardRef(Qt(function(t,s){const r=d.useContext(Xv),i=d.useRef(null),a=bt(s,i);return d.useEffect(()=>{const l=i.current;if(l)return r.branches.add(l),()=>{r.branches.delete(l)}},[r.branches]),n.jsx(vt.div,{...t,ref:a})},"DismissableLayerBranch"));function j1(){const e=d.useContext(Xv),[t,s]=d.useState(null);return d.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),s}Qt(j1,"useDismissableLayerSurface");var lD=Qt(()=>!0,"IS_TRUE");function w1(e,t){const{ownerDocument:s=globalThis==null?void 0:globalThis.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:i,dismissableSurfaces:a,shouldHandlePointerDownOutside:l=lD}=t,o=Rn(e),c=d.useRef(!1),u=d.useRef(!1),h=d.useRef(new Map),f=d.useRef(()=>{});return d.useEffect(()=>{function m(){u.current=!1,i.current=!1,h.current.clear()}Qt(m,"resetOutsideInteraction");function p(){return Array.from(h.current.values()).some(Boolean)}Qt(p,"isOutsideInteractionIntercepted");function g(w){if(!u.current)return;const y=w.target;y instanceof Node&&[...a].some(N=>N.contains(y))||h.current.set(w.type,!0),w.type==="click"&&window.setTimeout(()=>{u.current&&f.current()},0)}Qt(g,"handleInteractionCapture");function v(w){u.current&&h.current.set(w.type,!1)}Qt(v,"handleInteractionBubble");const b=Qt(w=>{if(w.target&&!c.current){let y=function(){s.removeEventListener("click",f.current);const N=p();m(),N||Zv(rD,o,k,{discrete:!0})};if(Qt(y,"handleAndDispatchPointerDownOutsideEvent"),!l(w.target)){s.removeEventListener("click",f.current),m(),c.current=!1;return}const k={originalEvent:w};u.current=!0,i.current=r&&w.button===0,h.current.clear(),!r||w.button!==0?y():(s.removeEventListener("click",f.current),f.current=y,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 w of j)s.addEventListener(w,g,!0),s.addEventListener(w,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 w of j)s.removeEventListener(w,g,!0),s.removeEventListener(w,v)}},[s,o,r,i,a,l]),{onPointerDownCapture:Qt(()=>c.current=!0,"onPointerDownCapture")}}Qt(w1,"usePointerDownOutside");function y1(e,t=globalThis==null?void 0:globalThis.document){const s=Rn(e),r=d.useRef(!1);return d.useEffect(()=>{const i=Qt(a=>{a.target&&!r.current&&Zv(iD,s,{originalEvent:a},{discrete:!1})},"handleFocus");return t.addEventListener("focusin",i),()=>t.removeEventListener("focusin",i)},[t,s]),{onFocusCapture:Qt(()=>r.current=!0,"onFocusCapture"),onBlurCapture:Qt(()=>r.current=!1,"onBlurCapture")}}Qt(y1,"useFocusOutside");function Ng(){const e=new CustomEvent(kg);document.dispatchEvent(e)}Qt(Ng,"dispatchUpdate");function Zv(e,t,s,{discrete:r}){const i=s.originalEvent.target,a=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:s});t&&i.addEventListener(e,t,{once:!0}),r?Gh(i,a):i.dispatchEvent(a)}Qt(Zv,"handleAndDispatchCustomEvent");var oD=qh,cD=aD,Vn=globalThis!=null&&globalThis.document?d.useLayoutEffect:()=>{},uD=Object.defineProperty,dD=(e,t)=>uD(e,"name",{value:t,configurable:!0}),Yh=d.forwardRef(dD(function(t,s){var c;const{container:r,...i}=t,[a,l]=d.useState(!1);Vn(()=>l(!0),[]);const o=r||a&&((c=globalThis==null?void 0:globalThis.document)==null?void 0:c.body);return o?Ul.createPortal(n.jsx(vt.div,{...i,ref:s}),o):null},"Portal")),hD=Object.defineProperty,Vr=(e,t)=>hD(e,"name",{value:t,configurable:!0});function b1(e,t){return d.useReducer((s,r)=>t[s][r]??s,e)}Vr(b1,"useStateMachine");var wr=Vr(e=>{const{present:t,children:s}=e,r=k1(t),i=typeof s=="function"?s({present:r.isPresent}):d.Children.only(s),a=N1(r.ref,S1(i));return typeof s=="function"||r.isPresent?d.cloneElement(i,{ref:a}):null},"Presence");function k1(e){const[t,s]=d.useState(),r=d.useRef(null),i=d.useRef(e),a=d.useRef("none"),l=d.useRef(void 0),o=e?"mounted":"unmounted",[c,u]=b1(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return d.useEffect(()=>{c==="mounted"?(a.current=l.current??Wa(r.current),l.current=void 0):a.current="none"},[c]),Vn(()=>{const h=r.current,f=i.current;if(f!==e){const p=a.current,g=Wa(h);e?(l.current=g,u("MOUNT")):g==="none"||(h==null?void 0:h.display)==="none"?u("UNMOUNT"):u(f&&p!==g?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,u]),Vn(()=>{if(t){let h;const f=t.ownerDocument.defaultView??window,m=Vr(g=>{const b=Wa(r.current).includes(CSS.escape(g.animationName));if(g.target===t&&b&&(u("ANIMATION_END"),!i.current)){const j=t.style.animationFillMode;t.style.animationFillMode="forwards",h=f.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=j)})}},"handleAnimationEnd"),p=Vr(g=>{g.target===t&&(a.current=Wa(r.current))},"handleAnimationStart");return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",m),t.addEventListener("animationend",m),()=>{f.clearTimeout(h),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",m),t.removeEventListener("animationend",m)}}else u("ANIMATION_END")},[t,u]),{isPresent:["mounted","unmountSuspended"].includes(c),ref:d.useCallback(h=>{if(h){const f=getComputedStyle(h);r.current=f,l.current=Wa(f)}else r.current=null;s(h)},[])}}Vr(k1,"usePresence");function Sg(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}Vr(Sg,"setRef");function N1(...e){const t=d.useRef(e);return t.current=e,d.useCallback(s=>{const r=t.current;let i=!1;const a=r.map(l=>{const o=Sg(l,s);return!i&&typeof o=="function"&&(i=!0),o});if(i)return()=>{for(let l=0;l<a.length;l++){const o=a[l];typeof o=="function"?o():Sg(r[l],null)}}},[])}Vr(N1,"useStableComposedRefs");function Wa(e){return(e==null?void 0:e.animationName)||"none"}Vr(Wa,"getAnimationName");function S1(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,s=t&&"isReactWarning"in t&&t.isReactWarning;return s?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,s=t&&"isReactWarning"in t&&t.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}Vr(S1,"getElementRef");var fD=Object.defineProperty,mD=(e,t)=>fD(e,"name",{value:t,configurable:!0}),Yb=Fl[" useEffectEvent ".trim().toString()],Jb=Fl[" useInsertionEffect ".trim().toString()];function C1(e){if(typeof Yb=="function")return Yb(e);const t=d.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof Jb=="function"?Jb(()=>{t.current=e}):Vn(()=>{t.current=e}),d.useMemo(()=>(...s)=>{var r;return(r=t.current)==null?void 0:r.call(t,...s)},[])}mD(C1,"useEffectEvent");var pD=Object.defineProperty,Fc=(e,t)=>pD(e,"name",{value:t,configurable:!0}),gD=Fl[" useInsertionEffect ".trim().toString()]||Vn;function Di({prop:e,defaultProp:t,onChange:s=Fc(()=>{},"onChange"),caller:r}){const[i,a,l]=E1({defaultProp:t,onChange:s}),o=e!==void 0,c=o?e:i,u=d.useCallback(h=>{var f;if(o){const m=A1(h)?h(e):h;m!==e&&((f=l.current)==null||f.call(l,m))}else a(h)},[o,e,a,l]);return[c,u]}Fc(Di,"useControllableState");function E1({defaultProp:e,onChange:t}){const[s,r]=d.useState(e),i=d.useRef(s),a=d.useRef(t);return gD(()=>{a.current=t},[t]),d.useEffect(()=>{var l;i.current!==s&&((l=a.current)==null||l.call(a,s),i.current=s)},[s,i]),[s,r,a]}Fc(E1,"useUncontrolledState");function A1(e){return typeof e=="function"}Fc(A1,"isFunction");var Qb=Symbol("RADIX:SYNC_STATE");function xD(e,t,s,r){const{prop:i,defaultProp:a,onChange:l,caller:o}=t,c=i!==void 0,u=C1(l),h=[{...s,state:a}];r&&h.push(r);const[f,m]=d.useReducer((b,j)=>{if(j.type===Qb)return{...b,state:j.state};const x=e(b,j);return c&&!Object.is(x.state,b.state)&&u(x.state),x},...h),p=f.state,g=d.useRef(p);d.useEffect(()=>{g.current!==p&&(g.current=p,c||u(p))},[p,g,c]);const v=d.useMemo(()=>i!==void 0?{...f,state:i}:f,[f,i]);return d.useEffect(()=>{c&&!Object.is(i,f.state)&&m({type:Qb,state:i})},[i,f.state,c]),[v,m]}Fc(xD,"useControllableStateReducer");var vD=Object.defineProperty,jD=(e,t)=>vD(e,"name",{value:t,configurable:!0}),wD=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"}),ej=d.forwardRef(jD(function(t,s){return n.jsx(vt.span,{...t,ref:s,style:{...wD,...t.style}})},"VisuallyHidden")),yD=ej,bD=Object.defineProperty,wt=(e,t)=>bD(e,"name",{value:t,configurable:!0}),T1="ToastProvider",[tj,$1,kD]=Vh("Toast"),[R1,CZ]=Gs("Toast",[kD]),[ND,Jh]=R1(T1),SD=wt(e=>{const{__scopeToast:t,label:s="Notification",duration:r=5e3,swipeDirection:i="right",swipeThreshold:a=50,announcerContainer:l,children:o}=e,[c,u]=d.useState(null),[h,f]=d.useState(0),m=d.useRef(!1);return s.trim()||console.error(`Invalid prop \`label\` supplied to \`${T1}\`. Expected non-empty \`string\`.`),n.jsx(tj.Provider,{scope:t,children:n.jsx(ND,{scope:t,label:s,duration:r,swipeDirection:i,swipeThreshold:a,toastCount:h,viewport:c,onViewportChange:u,onToastAdd:d.useCallback(()=>f(p=>p+1),[]),onToastRemove:d.useCallback(()=>f(p=>p-1),[]),isClosePausedRef:m,announcerContainer:l,children:o})})},"ToastProvider"),CD="ToastViewport",ED=["F8"],Cg="toast.viewportPause",Eg="toast.viewportResume",AD=d.forwardRef(wt(function(t,s){const{__scopeToast:r,hotkey:i=ED,label:a="Notifications ({hotkey})",...l}=t,o=Jh(CD,r),c=$1(r),u=d.useRef(null),h=d.useRef(null),f=d.useRef(null),m=d.useRef(null),p=bt(s,m,o.onViewportChange),g=i.join("+").replace(/Key/g,"").replace(/Digit/g,""),v=o.toastCount>0;d.useEffect(()=>{const j=wt(x=>{var y;i.length!==0&&i.every(k=>x[k]||x.code===k)&&((y=m.current)==null||y.focus())},"handleKeyDown");return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[i]),d.useEffect(()=>{const j=u.current,x=m.current;if(v&&j&&x){const w=wt(()=>{if(!o.isClosePausedRef.current){const S=new CustomEvent(Cg);x.dispatchEvent(S),o.isClosePausedRef.current=!0}},"handlePause"),y=wt(()=>{if(o.isClosePausedRef.current){const S=new CustomEvent(Eg);x.dispatchEvent(S),o.isClosePausedRef.current=!1}},"handleResume"),k=wt(S=>{!j.contains(S.relatedTarget)&&y()},"handleFocusOutResume"),N=wt(()=>{j.contains(document.activeElement)||y()},"handlePointerLeaveResume");return j.addEventListener("focusin",w),j.addEventListener("focusout",k),j.addEventListener("pointermove",w),j.addEventListener("pointerleave",N),window.addEventListener("blur",w),window.addEventListener("focus",y),()=>{j.removeEventListener("focusin",w),j.removeEventListener("focusout",k),j.removeEventListener("pointermove",w),j.removeEventListener("pointerleave",N),window.removeEventListener("blur",w),window.removeEventListener("focus",y)}}},[v,o.isClosePausedRef]);const b=d.useCallback(({tabbingDirection:j})=>{const w=c().map(y=>{const k=y.ref.current,N=[k,...D1(k)];return j==="forwards"?N:N.reverse()});return(j==="forwards"?w.reverse():w).flat()},[c]);return d.useEffect(()=>{const j=m.current;if(j){const x=wt(w=>{var N,S,C;const y=w.altKey||w.ctrlKey||w.metaKey;if(w.key==="Tab"&&!y){const E=document.activeElement,R=w.shiftKey;if(w.target===j&&R){(N=h.current)==null||N.focus();return}const F=b({tabbingDirection:R?"backwards":"forwards"}),T=F.findIndex(M=>M===E);hd(F.slice(T+1))?w.preventDefault():R?(S=h.current)==null||S.focus():(C=f.current)==null||C.focus()}},"handleKeyDown");return j.addEventListener("keydown",x),()=>j.removeEventListener("keydown",x)}},[c,b]),n.jsxs(cD,{ref:u,role:"region","aria-label":a.replace("{hotkey}",g),tabIndex:-1,style:{pointerEvents:v?void 0:"none"},children:[v&&n.jsx(Xb,{ref:h,onFocusFromOutsideViewport:()=>{const j=b({tabbingDirection:"forwards"});hd(j)}}),n.jsx(tj.Slot,{scope:r,children:n.jsx(vt.ol,{tabIndex:-1,...l,ref:p})}),v&&n.jsx(Xb,{ref:f,onFocusFromOutsideViewport:()=>{const j=b({tabbingDirection:"backwards"});hd(j)}})]})},"ToastViewport")),TD="ToastFocusProxy",Xb=d.forwardRef(wt(function(t,s){const{__scopeToast:r,onFocusFromOutsideViewport:i,...a}=t,l=Jh(TD,r);return n.jsx(ej,{tabIndex:0,...a,ref:s,style:{position:"fixed"},onFocus:o=>{var h;const c=o.relatedTarget;!((h=l.viewport)!=null&&h.contains(c))&&i()}})},"ToastFocusProxy")),Qh="Toast",$D="toast.swipeStart",RD="toast.swipeMove",ID="toast.swipeCancel",PD="toast.swipeEnd",MD=d.forwardRef(wt(function(t,s){const{forceMount:r,open:i,defaultOpen:a,onOpenChange:l,...o}=t,[c,u]=Di({prop:i,defaultProp:a??!0,onChange:l,caller:Qh});return n.jsx(wr,{present:r||c,children:n.jsx(LD,{open:c,...o,ref:s,onClose:()=>u(!1),onPause:Rn(t.onPause),onResume:Rn(t.onResume),onSwipeStart:Me(t.onSwipeStart,h=>{h.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:Me(t.onSwipeMove,h=>{const{x:f,y:m}=h.detail.delta;h.currentTarget.setAttribute("data-swipe","move"),h.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${f}px`),h.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${m}px`)}),onSwipeCancel:Me(t.onSwipeCancel,h=>{h.currentTarget.setAttribute("data-swipe","cancel"),h.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),h.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),h.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),h.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:Me(t.onSwipeEnd,h=>{const{x:f,y:m}=h.detail.delta;h.currentTarget.setAttribute("data-swipe","end"),h.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),h.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),h.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${f}px`),h.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${m}px`),u(!1)})})})},"Toast")),[DD,OD]=R1(Qh,{onClose(){}}),LD=d.forwardRef(wt(function(t,s){const{__scopeToast:r,type:i="foreground",duration:a,open:l,onClose:o,onEscapeKeyDown:c,onPause:u,onResume:h,onSwipeStart:f,onSwipeMove:m,onSwipeCancel:p,onSwipeEnd:g,...v}=t,b=Jh(Qh,r),j=$1(r),[x,w]=d.useState(null),y=bt(s,w),k=d.useRef(null),N=d.useRef(null),S=a||b.duration,C=d.useRef(0),E=d.useRef(S),R=d.useRef(0),{onToastAdd:I,onToastRemove:L}=b,F=Rn(()=>{var D;(x==null?void 0:x.contains(document.activeElement))&&((D=b.viewport)==null||D.focus()),o()}),T=d.useCallback(P=>{!P||P===1/0||(window.clearTimeout(R.current),C.current=new Date().getTime(),R.current=window.setTimeout(F,P))},[F]);d.useEffect(()=>{const P=b.viewport;if(P){const D=wt(()=>{T(E.current),h==null||h()},"handleResume"),O=wt(()=>{const H=new Date().getTime()-C.current;E.current=E.current-H,window.clearTimeout(R.current),u==null||u()},"handlePause");return P.addEventListener(Cg,O),P.addEventListener(Eg,D),()=>{P.removeEventListener(Cg,O),P.removeEventListener(Eg,D)}}},[b.viewport,S,u,h,T]),d.useEffect(()=>{l&&!b.isClosePausedRef.current&&T(S)},[l,S,b.isClosePausedRef,T]),d.useEffect(()=>()=>{window.clearTimeout(R.current)},[]),d.useEffect(()=>(I(),()=>L()),[I,L]);const M=d.useMemo(()=>x?nj(x):null,[x]);return b.viewport?n.jsxs(n.Fragment,{children:[M&&n.jsx(FD,{__scopeToast:r,role:"status","aria-live":i==="foreground"?"assertive":"polite",children:M}),n.jsx(DD,{scope:r,onClose:F,children:Ul.createPortal(n.jsx(tj.ItemSlot,{scope:r,children:n.jsx(oD,{asChild:!0,onEscapeKeyDown:Me(c,P=>{j().some(O=>{var H;return(H=O.ref.current)==null?void 0:H.contains(P.target)})||F()}),children:n.jsx(vt.li,{tabIndex:0,"data-state":l?"open":"closed","data-swipe-direction":b.swipeDirection,...v,ref:y,style:{userSelect:"none",touchAction:"none",...t.style},onKeyDown:Me(t.onKeyDown,P=>{P.key==="Escape"&&(c==null||c(P.nativeEvent),P.nativeEvent.defaultPrevented||F())}),onPointerDown:Me(t.onPointerDown,P=>{P.button===0&&(k.current={x:P.clientX,y:P.clientY})}),onPointerMove:Me(t.onPointerMove,P=>{if(!k.current)return;const D=P.clientX-k.current.x,O=P.clientY-k.current.y,H=!!N.current,B=["left","right"].includes(b.swipeDirection),Y=["left","up"].includes(b.swipeDirection)?Math.min:Math.max,W=B?Y(0,D):0,q=B?0:Y(0,O),_=P.pointerType==="touch"?10:2,X={x:W,y:q},Q={originalEvent:P,delta:X};H?(N.current=X,Eo(RD,m,Q,{discrete:!1})):Zb(X,b.swipeDirection,_)?(N.current=X,Eo($D,f,Q,{discrete:!1}),P.target.setPointerCapture(P.pointerId)):(Math.abs(D)>_||Math.abs(O)>_)&&(k.current=null)}),onPointerUp:Me(t.onPointerUp,P=>{const D=N.current,O=P.target;if(O.hasPointerCapture(P.pointerId)&&O.releasePointerCapture(P.pointerId),N.current=null,k.current=null,D){const H=P.currentTarget,B={originalEvent:P,delta:D};Zb(D,b.swipeDirection,b.swipeThreshold)?Eo(PD,g,B,{discrete:!0}):Eo(ID,p,B,{discrete:!0}),H.addEventListener("click",Y=>Y.preventDefault(),{once:!0})}})})})}),b.viewport)})]}):null},"ToastImpl")),FD=wt(e=>{const{__scopeToast:t,children:s,...r}=e,i=Jh(Qh,t),[a,l]=d.useState(!1),[o,c]=d.useState(!1);return P1(()=>l(!0)),d.useEffect(()=>{const u=window.setTimeout(()=>c(!0),1e3);return()=>window.clearTimeout(u)},[]),o?null:n.jsx(Yh,{asChild:!0,container:i.announcerContainer||void 0,children:n.jsx(ej,{...r,children:a&&n.jsxs(n.Fragment,{children:[i.label," ",s]})})})},"ToastAnnounce"),_D=d.forwardRef(wt(function(t,s){const{__scopeToast:r,...i}=t;return n.jsx(vt.div,{...i,ref:s})},"ToastTitle")),zD=d.forwardRef(wt(function(t,s){const{__scopeToast:r,...i}=t;return n.jsx(vt.div,{...i,ref:s})},"ToastDescription")),UD="ToastAction",BD=d.forwardRef(wt(function(t,s){const{altText:r,...i}=t;return r.trim()?n.jsx(I1,{altText:r,asChild:!0,children:n.jsx(HD,{...i,ref:s})}):(console.error(`Invalid prop \`altText\` supplied to \`${UD}\`. Expected non-empty \`string\`.`),null)},"ToastAction")),WD="ToastClose",HD=d.forwardRef(wt(function(t,s){const{__scopeToast:r,...i}=t,a=OD(WD,r);return n.jsx(I1,{asChild:!0,children:n.jsx(vt.button,{type:"button",...i,ref:s,onClick:Me(t.onClick,a.onClose)})})},"ToastClose")),I1=d.forwardRef(wt(function(t,s){const{__scopeToast:r,altText:i,...a}=t;return n.jsx(vt.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":i||void 0,...a,ref:s})},"ToastAnnounceExclude"));function nj(e){const t=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&t.push(r.textContent),M1(r)){const i=r.ariaHidden||r.hidden||r.style.display==="none",a=r.dataset.radixToastAnnounceExclude==="";if(!i)if(a){const l=r.dataset.radixToastAnnounceAlt;l&&t.push(l)}else t.push(...nj(r))}}),t}wt(nj,"getAnnounceTextContent");function Eo(e,t,s,{discrete:r}){const i=s.originalEvent.currentTarget,a=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:s});t&&i.addEventListener(e,t,{once:!0}),r?Gh(i,a):i.dispatchEvent(a)}wt(Eo,"handleAndDispatchCustomEvent");var Zb=wt((e,t,s=0)=>{const r=Math.abs(e.x),i=Math.abs(e.y),a=r>i;return t==="left"||t==="right"?a&&r>s:!a&&i>s},"isDeltaInDirection");function P1(e=()=>{}){const t=Rn(e);Vn(()=>{let s=0,r=0;return s=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(t)),()=>{window.cancelAnimationFrame(s),window.cancelAnimationFrame(r)}},[t])}wt(P1,"useNextFrame");function M1(e){return e.nodeType===e.ELEMENT_NODE}wt(M1,"isHTMLElement");function D1(e){const t=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:wt(r=>{const i=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||i?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;s.nextNode();)t.push(s.currentNode);return t}wt(D1,"getTabbableCandidates");function hd(e){const t=document.activeElement;return e.some(s=>s===t?!0:(s.focus(),document.activeElement!==t))}wt(hd,"focusFirst");var ek=SD,tk=AD,KD=MD,VD=_D,GD=zD,qD=BD,YD=Object.defineProperty,JD=(e,t)=>YD(e,"name",{value:t,configurable:!0}),QD=Fl[" useId ".trim().toString()]||(()=>{}),XD=0;function _s(e){const[t,s]=d.useState(QD());return Vn(()=>{e||s(r=>r??String(XD++))},[e]),e||(t?`radix-${t}`:"")}JD(_s,"useId");const ZD=["top","right","bottom","left"],Ci=Math.min,Lr=Math.max,Jd=Math.round,Au=Math.floor,Fr=e=>({x:e,y:e}),eO={left:"right",right:"left",bottom:"top",top:"bottom"};function O1(e,t,s){return Lr(e,Ci(t,s))}function Gr(e,t){return typeof e=="function"?e(t):e}function Ei(e){return e.split("-")[0]}function Wl(e){return e.split("-")[1]}function sj(e){return e==="x"?"y":"x"}function rj(e){return e==="y"?"height":"width"}function cr(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function ij(e){return sj(cr(e))}function tO(e,t,s){s===void 0&&(s=!1);const r=Wl(e),i=ij(e),a=rj(i);let l=i==="x"?r===(s?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[a]>t.floating[a]&&(l=Qd(l)),[l,Qd(l)]}function nO(e){const t=Qd(e);return[Ag(e),t,Ag(t)]}function Ag(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const nk=["left","right"],sk=["right","left"],sO=["top","bottom"],rO=["bottom","top"];function iO(e,t,s){switch(e){case"top":case"bottom":return s?t?sk:nk:t?nk:sk;case"left":case"right":return t?sO:rO;default:return[]}}function aO(e,t,s,r){const i=Wl(e);let a=iO(Ei(e),s==="start",r);return i&&(a=a.map(l=>l+"-"+i),t&&(a=a.concat(a.map(Ag)))),a}function Qd(e){const t=Ei(e);return eO[t]+e.slice(t.length)}function lO(e){var t,s,r,i;return{top:(t=e.top)!=null?t:0,right:(s=e.right)!=null?s:0,bottom:(r=e.bottom)!=null?r:0,left:(i=e.left)!=null?i:0}}function L1(e){return typeof e!="number"?lO(e):{top:e,right:e,bottom:e,left:e}}function Xd(e){const{x:t,y:s,width:r,height:i}=e;return{width:r,height:i,top:s,left:t,right:t+r,bottom:s+i,x:t,y:s}}function rk(e,t,s){let{reference:r,floating:i}=e;const a=cr(t),l=ij(t),o=rj(l),c=Ei(t),u=a==="y",h=r.x+r.width/2-i.width/2,f=r.y+r.height/2-i.height/2,m=r[o]/2-i[o]/2;let p;switch(c){case"top":p={x:h,y:r.y-i.height};break;case"bottom":p={x:h,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-i.width,y:f};break;default:p={x:r.x,y:r.y}}const g=Wl(t);return g&&(p[l]+=m*(g==="end"?1:-1)*(s&&u?-1:1)),p}async function oO(e,t){var s;t===void 0&&(t={});const{x:r,y:i,platform:a,rects:l,elements:o,strategy:c}=e,{boundary:u="clippingAncestors",rootBoundary:h="viewport",elementContext:f="floating",altBoundary:m=!1,padding:p=0}=Gr(t,e),g=L1(p),b=o[m?f==="floating"?"reference":"floating":f],j=Xd(await a.getClippingRect({element:(s=await(a.isElement==null?void 0:a.isElement(b)))==null||s?b:b.contextElement||await(a.getDocumentElement==null?void 0:a.getDocumentElement(o.floating)),boundary:u,rootBoundary:h,strategy:c})),x=f==="floating"?{x:r,y:i,width:l.floating.width,height:l.floating.height}:l.reference,w=await(a.getOffsetParent==null?void 0:a.getOffsetParent(o.floating)),y=await(a.isElement==null?void 0:a.isElement(w))&&await(a.getScale==null?void 0:a.getScale(w))||{x:1,y:1},k=Xd(a.convertOffsetParentRelativeRectToViewportRelativeRect?await a.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:x,offsetParent:w,strategy:c}):x);return{top:(j.top-k.top+g.top)/y.y,bottom:(k.bottom-j.bottom+g.bottom)/y.y,left:(j.left-k.left+g.left)/y.x,right:(k.right-j.right+g.right)/y.x}}const cO=50,uO=async(e,t,s)=>{const{placement:r="bottom",strategy:i="absolute",middleware:a=[],platform:l}=s,o=l.detectOverflow?l:{...l,detectOverflow:oO},c=await(l.isRTL==null?void 0:l.isRTL(t));let u=await l.getElementRects({reference:e,floating:t,strategy:i}),{x:h,y:f}=rk(u,r,c),m=r,p=0;const g={};for(let v=0;v<a.length;v++){const b=a[v];if(!b)continue;const{name:j,fn:x}=b,{x:w,y,data:k,reset:N}=await x({x:h,y:f,initialPlacement:r,placement:m,strategy:i,middlewareData:g,rects:u,platform:o,elements:{reference:e,floating:t}});h=w??h,f=y??f,g[j]={...g[j],...k},N&&p<cO&&(p++,typeof N=="object"&&(N.placement&&(m=N.placement),N.rects&&(u=N.rects===!0?await l.getElementRects({reference:e,floating:t,strategy:i}):N.rects),{x:h,y:f}=rk(u,m,c)),v=-1)}return{x:h,y:f,placement:m,strategy:i,middlewareData:g}},dO=e=>({name:"arrow",options:e,async fn(t){const{x:s,y:r,placement:i,rects:a,platform:l,elements:o,middlewareData:c}=t,{element:u,padding:h=0}=Gr(e,t)||{};if(u==null)return{};const f=L1(h),m={x:s,y:r},p=ij(i),g=rj(p),v=await l.getDimensions(u),b=p==="y",j=b?"top":"left",x=b?"bottom":"right",w=b?"clientHeight":"clientWidth",y=a.reference[g]+a.reference[p]-m[p]-a.floating[g],k=m[p]-a.reference[p],N=await(l.getOffsetParent==null?void 0:l.getOffsetParent(u));let S=N?N[w]:0;(!S||!await(l.isElement==null?void 0:l.isElement(N)))&&(S=o.floating[w]||a.floating[g]);const C=y/2-k/2,E=S/2-v[g]/2-1,R=Ci(f[j],E),I=Ci(f[x],E),L=S-v[g]-I,F=S/2-v[g]/2+C,T=O1(R,F,L),M=!c.arrow&&Wl(i)!=null&&F!==T&&a.reference[g]/2-(F<R?R:I)-v[g]/2<0,P=M?F<R?F-R:F-L:0;return{[p]:m[p]+P,data:{[p]:T,centerOffset:F-T-P,...M&&{alignmentOffset:P}},reset:M}}}),hO=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var s,r;const{placement:i,middlewareData:a,rects:l,initialPlacement:o,platform:c,elements:u}=t,{mainAxis:h=!0,crossAxis:f=!0,fallbackPlacements:m,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:v=!0,...b}=Gr(e,t);if((s=a.arrow)!=null&&s.alignmentOffset)return{};const j=Ei(i),x=cr(o),w=Ei(o)===o,y=await(c.isRTL==null?void 0:c.isRTL(u.floating)),k=m||(w||!v?[Qd(o)]:nO(o)),N=g!=="none";!m&&N&&k.push(...aO(o,v,g,y));const S=[o,...k],C=await c.detectOverflow(t,b),E=[];let R=((r=a.flip)==null?void 0:r.overflows)||[];if(h&&E.push(C[j]),f){const T=tO(i,l,y);E.push(C[T[0]],C[T[1]])}if(R=[...R,{placement:i,overflows:E}],!E.every(T=>T<=0)){var I,L;const T=(((I=a.flip)==null?void 0:I.index)||0)+1,M=S[T];if(M&&(!(f==="alignment"?x!==cr(M):!1)||R.every(O=>cr(O.placement)===x?O.overflows[0]>0:!0)))return{data:{index:T,overflows:R},reset:{placement:M}};let P=(L=R.filter(D=>D.overflows[0]<=0).sort((D,O)=>D.overflows[1]-O.overflows[1])[0])==null?void 0:L.placement;if(!P)switch(p){case"bestFit":{var F;const D=(F=R.filter(O=>{if(N){const H=cr(O.placement);return H===x||H==="y"}return!0}).map(O=>[O.placement,O.overflows.filter(H=>H>0).reduce((H,B)=>H+B,0)]).sort((O,H)=>O[1]-H[1])[0])==null?void 0:F[0];D&&(P=D);break}case"initialPlacement":P=o;break}if(i!==P)return{reset:{placement:P}}}return{}}}};function ik(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function ak(e){return ZD.some(t=>e[t]>=0)}const fO=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:s,platform:r}=t,{strategy:i="referenceHidden",...a}=Gr(e,t);switch(i){case"referenceHidden":{const l=await r.detectOverflow(t,{...a,elementContext:"reference"}),o=ik(l,s.reference);return{data:{referenceHiddenOffsets:o,referenceHidden:ak(o)}}}case"escaped":{const l=await r.detectOverflow(t,{...a,altBoundary:!0}),o=ik(l,s.floating);return{data:{escapedOffsets:o,escaped:ak(o)}}}default:return{}}}}},F1=new Set(["left","top"]);async function mO(e,t){const{placement:s,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),l=Ei(s),o=Wl(s),c=cr(s)==="y",u=F1.has(l)?-1:1,h=a&&c?-1:1,f=Gr(t,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*h,y:m*u}:{x:m*u,y:p*h}}const pO=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var s,r;const{x:i,y:a,placement:l,middlewareData:o}=t,c=await mO(t,e);return l===((s=o.offset)==null?void 0:s.placement)&&(r=o.arrow)!=null&&r.alignmentOffset?{}:{x:i+c.x,y:a+c.y,data:{...c,placement:l}}}}},gO=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:s,y:r,placement:i,platform:a}=t,{mainAxis:l=!0,crossAxis:o=!1,limiter:c={fn:x=>{let{x:w,y}=x;return{x:w,y}}},...u}=Gr(e,t),h={x:s,y:r},f=await a.detectOverflow(t,u),m=cr(i),p=sj(m);let g=h[p],v=h[m];const b=(x,w)=>O1(w+f[x==="y"?"top":"left"],w,w-f[x==="y"?"bottom":"right"]);l&&(g=b(p,g)),o&&(v=b(m,v));const j=c.fn({...t,[p]:g,[m]:v});return{...j,data:{x:j.x-s,y:j.y-r,enabled:{[p]:l,[m]:o}}}}}},xO=function(e){return e===void 0&&(e={}),{options:e,fn(t){var s,r;const{x:i,y:a,placement:l,rects:o,middlewareData:c}=t,{offset:u=0,mainAxis:h=!0,crossAxis:f=!0}=Gr(e,t),m={x:i,y:a},p=cr(l),g=sj(p);let v=m[g],b=m[p];const j=Gr(u,t),x=typeof j=="number"?{mainAxis:j,crossAxis:0}:{mainAxis:(s=j.mainAxis)!=null?s:0,crossAxis:(r=j.crossAxis)!=null?r:0};if(h){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 w,y;const k=g==="y"?"width":"height",N=F1.has(Ei(l)),S=o.reference[p]-o.floating[k]+(N&&((w=c.offset)==null?void 0:w[p])||0)+(N?0:x.crossAxis),C=o.reference[p]+o.reference[k]+(N?0:((y=c.offset)==null?void 0:y[p])||0)-(N?x.crossAxis:0);b<S?b=S:b>C&&(b=C)}return{[g]:v,[p]:b}}}},vO=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){const{placement:s,rects:r,platform:i,elements:a}=t,{apply:l=()=>{},...o}=Gr(e,t),c=await i.detectOverflow(t,o),u=Ei(s),h=Wl(s),f=cr(s)==="y",{width:m,height:p}=r.floating;let g,v;u==="top"||u==="bottom"?(g=u,v=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(v=u,g=h==="end"?"top":"bottom");const b=p-c.top-c.bottom,j=m-c.left-c.right,x=Ci(p-c[g],b),w=Ci(m-c[v],j),y=t.middlewareData.shift,k=!y;let N=x,S=w;y!=null&&y.enabled.x&&(S=j),y!=null&&y.enabled.y&&(N=b),k&&!h&&(f?S=m-2*Lr(c.left,c.right):N=p-2*Lr(c.top,c.bottom)),await l({...t,availableWidth:S,availableHeight:N});const C=await i.getDimensions(a.floating);return m!==C.width||p!==C.height?{reset:{rects:!0}}:{}}}};function Xh(){return typeof window<"u"}function Hl(e){return _1(e)?(e.nodeName||"").toLowerCase():"#document"}function Gn(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Qr(e){var t;return(t=(_1(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function _1(e){return Xh()?e instanceof Node||e instanceof Gn(e).Node:!1}function mr(e){return Xh()?e instanceof Element||e instanceof Gn(e).Element:!1}function Oi(e){return Xh()?e instanceof HTMLElement||e instanceof Gn(e).HTMLElement:!1}function lk(e){return!Xh()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Gn(e).ShadowRoot}function Zh(e){const{overflow:t,overflowX:s,overflowY:r,display:i}=pr(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+s)&&i!=="inline"&&i!=="contents"}function jO(e){return/^(table|td|th)$/.test(Hl(e))}function ef(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const wO=/transform|translate|scale|rotate|perspective|filter/,yO=/paint|layout|strict|content/,Hi=e=>!!e&&e!=="none";let bm;function aj(e){const t=mr(e)?pr(e):e;return Hi(t.transform)||Hi(t.translate)||Hi(t.scale)||Hi(t.rotate)||Hi(t.perspective)||!lj()&&(Hi(t.backdropFilter)||Hi(t.filter))||wO.test(t.willChange||"")||yO.test(t.contain||"")}function bO(e){let t=ha(e);for(;Oi(t)&&!cc(t);){if(aj(t))return t;if(ef(t))return null;t=ha(t)}return null}function lj(){return bm==null&&(bm=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),bm}function cc(e){return/^(html|body|#document)$/.test(Hl(e))}function pr(e){return Gn(e).getComputedStyle(e)}function tf(e){return mr(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function ha(e){if(Hl(e)==="html")return e;const t=e.assignedSlot||e.parentNode||lk(e)&&e.host||Qr(e);return lk(t)?t.host:t}function z1(e){const t=ha(e);return cc(t)?(e.ownerDocument||e).body:Oi(t)&&Zh(t)?t:z1(t)}function uc(e,t,s){var r;t===void 0&&(t=[]),s===void 0&&(s=!0);const i=z1(e),a=i===((r=e.ownerDocument)==null?void 0:r.body),l=Gn(i);if(a){const o=Tg(l);return t.concat(l,l.visualViewport||[],Zh(i)?i:[],o&&s?uc(o):[])}else return t.concat(i,uc(i,[],s))}function Tg(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function U1(e){const t=pr(e);let s=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Oi(e),a=i?e.offsetWidth:s,l=i?e.offsetHeight:r,o=Jd(s)!==a||Jd(r)!==l;return o&&(s=a,r=l),{width:s,height:r,$:o}}function oj(e){return mr(e)?e:e.contextElement}function hl(e){const t=oj(e);if(!Oi(t))return Fr(1);const s=t.getBoundingClientRect(),{width:r,height:i,$:a}=U1(t);let l=(a?Jd(s.width):s.width)/r,o=(a?Jd(s.height):s.height)/i;return(!l||!Number.isFinite(l))&&(l=1),(!o||!Number.isFinite(o))&&(o=1),{x:l,y:o}}const kO=Fr(0);function B1(e){const t=Gn(e);return!lj()||!t.visualViewport?kO:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function NO(e,t,s){return t===void 0&&(t=!1),!!s&&t&&s===Gn(e)}function fa(e,t,s,r){t===void 0&&(t=!1),s===void 0&&(s=!1);const i=e.getBoundingClientRect(),a=oj(e);let l=Fr(1);t&&(r?mr(r)&&(l=hl(r)):l=hl(e));const o=NO(a,s,r)?B1(a):Fr(0);let c=(i.left+o.x)/l.x,u=(i.top+o.y)/l.y,h=i.width/l.x,f=i.height/l.y;if(a&&r){const m=Gn(a),p=mr(r)?Gn(r):r;let g=m,v=Tg(g);for(;v&&p!==g;){const b=hl(v),j=v.getBoundingClientRect(),x=pr(v),w=j.left+(v.clientLeft+parseFloat(x.paddingLeft))*b.x,y=j.top+(v.clientTop+parseFloat(x.paddingTop))*b.y;c*=b.x,u*=b.y,h*=b.x,f*=b.y,c+=w,u+=y,g=Gn(v),v=Tg(g)}}return Xd({width:h,height:f,x:c,y:u})}function nf(e,t){const s=tf(e).scrollLeft;return t?t.left+s:fa(Qr(e)).left+s}function W1(e,t){const s=e.getBoundingClientRect(),r=s.left+t.scrollLeft-nf(e,s),i=s.top+t.scrollTop;return{x:r,y:i}}function SO(e){let{elements:t,rect:s,offsetParent:r,strategy:i}=e;const a=i==="fixed",l=Qr(r),o=t?ef(t.floating):!1;if(r===l||o&&a)return s;let c={scrollLeft:0,scrollTop:0},u=Fr(1);const h=Fr(0),f=Oi(r);if((f||!a)&&((Hl(r)!=="body"||Zh(l))&&(c=tf(r)),f)){const p=fa(r);u=hl(r),h.x=p.x+r.clientLeft,h.y=p.y+r.clientTop}const m=l&&!f&&!a?W1(l,c):Fr(0);return{width:s.width*u.x,height:s.height*u.y,x:s.x*u.x-c.scrollLeft*u.x+h.x+m.x,y:s.y*u.y-c.scrollTop*u.y+h.y+m.y}}function CO(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function EO(e){const t=tf(e),s=e.ownerDocument.body,r=Lr(e.scrollWidth,e.clientWidth,s.scrollWidth,s.clientWidth),i=Lr(e.scrollHeight,e.clientHeight,s.scrollHeight,s.clientHeight);let a=-t.scrollLeft+nf(e);const l=-t.scrollTop;return pr(s).direction==="rtl"&&(a+=Lr(e.clientWidth,s.clientWidth)-r),{width:r,height:i,x:a,y:l}}const AO=25;function TO(e,t,s){s===void 0&&(s="viewport");const r=s==="layoutViewport",i=Gn(e),a=Qr(e),l=i.visualViewport;let o=a.clientWidth,c=a.clientHeight,u=0,h=0;if(l){const m=!lj()||t==="fixed";r?m||(u=-l.offsetLeft,h=-l.offsetTop):(o=l.width,c=l.height,m&&(u=l.offsetLeft,h=l.offsetTop))}if(nf(a)<=0){const m=a.ownerDocument,p=m.body,g=getComputedStyle(p),v=m.compatMode==="CSS1Compat"&&parseFloat(g.marginLeft)+parseFloat(g.marginRight)||0,b=Math.abs(a.clientWidth-p.clientWidth-v),j=getComputedStyle(a).scrollbarGutter==="stable both-edges"?b/2:b;j<=AO&&(o-=j)}return{width:o,height:c,x:u,y:h}}function $O(e,t){const s=fa(e,!0,t==="fixed"),r=s.top+e.clientTop,i=s.left+e.clientLeft,a=hl(e),l=e.clientWidth*a.x,o=e.clientHeight*a.y,c=i*a.x,u=r*a.y;return{width:l,height:o,x:c,y:u}}function ok(e,t,s){let r;if(t==="viewport"||t==="layoutViewport")r=TO(e,s,t);else if(t==="document")r=EO(Qr(e));else if(mr(t))r=$O(t,s);else{const i=B1(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Xd(r)}function RO(e,t){const s=t.get(e);if(s)return s;let r=uc(e,[],!1).filter(o=>mr(o)&&Hl(o)!=="body"),i=null;const a=pr(e).position==="fixed";let l=a?ha(e):e;for(;mr(l)&&!cc(l);){const o=pr(l),c=aj(l),u=i?i.position:a?"fixed":"";!c&&(u==="fixed"||u==="absolute"&&o.position==="static")?r=r.filter(f=>f!==l):i=o,l=ha(l)}return t.set(e,r),r}function IO(e){let{element:t,boundary:s,rootBoundary:r,strategy:i}=e;const l=[...s==="clippingAncestors"?ef(t)?[]:RO(t,this._c):[].concat(s),r],o=ok(t,l[0],i);let c=o.top,u=o.right,h=o.bottom,f=o.left;for(let m=1;m<l.length;m++){const p=ok(t,l[m],i);c=Lr(p.top,c),u=Ci(p.right,u),h=Ci(p.bottom,h),f=Lr(p.left,f)}return{width:u-f,height:h-c,x:f,y:c}}function PO(e){const{width:t,height:s}=U1(e);return{width:t,height:s}}function MO(e,t,s){const r=Oi(t),i=Qr(t),a=s==="fixed",l=fa(e,!0,a,t);let o={scrollLeft:0,scrollTop:0};const c=Fr(0);if((r||!a)&&((Hl(t)!=="body"||Zh(i))&&(o=tf(t)),r)){const m=fa(t,!0,a,t);c.x=m.x+t.clientLeft,c.y=m.y+t.clientTop}!r&&i&&(c.x=nf(i));const u=i&&!r&&!a?W1(i,o):Fr(0),h=l.left+o.scrollLeft-c.x-u.x,f=l.top+o.scrollTop-c.y-u.y;return{x:h,y:f,width:l.width,height:l.height}}function km(e){return pr(e).position==="static"}function ck(e,t){if(!Oi(e)||pr(e).position==="fixed")return null;if(t)return t(e);let s=e.offsetParent;return Qr(e)===s&&(s=s.ownerDocument.body),s}function H1(e,t){const s=Gn(e);if(ef(e))return s;if(!Oi(e)){let i=ha(e);for(;i&&!cc(i);){if(mr(i)&&!km(i))return i;i=ha(i)}return s}let r=ck(e,t);for(;r&&jO(r)&&km(r);)r=ck(r,t);return r&&cc(r)&&km(r)&&!aj(r)?s:r||bO(e)||s}const DO=async function(e){const t=this.getOffsetParent||H1,s=this.getDimensions,r=await s(e.floating);return{reference:MO(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function OO(e){return pr(e).direction==="rtl"}const LO={convertOffsetParentRelativeRectToViewportRelativeRect:SO,getDocumentElement:Qr,getClippingRect:IO,getOffsetParent:H1,getElementRects:DO,getClientRects:CO,getDimensions:PO,getScale:hl,isElement:mr,isRTL:OO};function K1(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function FO(e,t,s){let r=null,i;const a=Qr(e);function l(){var h;clearTimeout(i),(h=r)==null||h.disconnect(),r=null}function o(h,f){h===void 0&&(h=!1),f===void 0&&(f=1),l();const m=e.getBoundingClientRect(),{left:p,top:g,width:v,height:b}=m;if(h||t(),!v||!b)return;const j=Au(g),x=Au(a.clientWidth-(p+v)),w=Au(a.clientHeight-(g+b)),y=Au(p),N={rootMargin:-j+"px "+-x+"px "+-w+"px "+-y+"px",threshold:Lr(0,Ci(1,f))||1};let S=!0;function C(E){const R=E[0].intersectionRatio;if(!K1(m,e.getBoundingClientRect()))return o();if(R!==f){if(!S)return o();R?o(!1,R):i=setTimeout(()=>{o(!1,1e-7)},1e3)}S=!1}try{r=new IntersectionObserver(C,{...N,root:a.ownerDocument})}catch{r=new IntersectionObserver(C,N)}r.observe(e)}const c=Gn(e),u=()=>o(s);return c.addEventListener("resize",u),o(!0),()=>{c.removeEventListener("resize",u),l()}}function _O(e,t,s,r){r===void 0&&(r={});const{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:l=typeof ResizeObserver=="function",layoutShift:o=typeof IntersectionObserver=="function",animationFrame:c=!1}=r,u=oj(e),h=i||a?[...u?uc(u):[],...t?uc(t):[]]:[];h.forEach(j=>{i&&j.addEventListener("scroll",s),a&&j.addEventListener("resize",s)});const f=u&&o?FO(u,s,a):null;let m=-1,p=null;l&&(p=new ResizeObserver(j=>{let[x]=j;x&&x.target===u&&p&&t&&(p.unobserve(t),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var w;(w=p)==null||w.observe(t)})),s()}),u&&!c&&p.observe(u),t&&p.observe(t));let g,v=c?fa(e):null;c&&b();function b(){const j=fa(e);v&&!K1(v,j)&&s(),v=j,g=requestAnimationFrame(b)}return s(),()=>{var j;h.forEach(x=>{i&&x.removeEventListener("scroll",s),a&&x.removeEventListener("resize",s)}),f==null||f(),(j=p)==null||j.disconnect(),p=null,c&&cancelAnimationFrame(g)}}const zO=pO,UO=gO,BO=hO,WO=vO,HO=fO,uk=dO,KO=xO,VO=(e,t,s)=>{const r=new Map,i=s??{},a={...LO,...i.platform,_c:r};return uO(e,t,{...i,platform:a})};var GO=typeof document<"u",qO=function(){},fd=GO?d.useLayoutEffect:qO;function Zd(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let s,r,i;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(s=e.length,s!==t.length)return!1;for(r=s;r--!==0;)if(!Zd(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),s=i.length,s!==Object.keys(t).length)return!1;for(r=s;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=s;r--!==0;){const a=i[r];if(!(a==="_owner"&&e.$$typeof)&&!Zd(e[a],t[a]))return!1}return!0}return e!==e&&t!==t}function V1(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function dk(e,t){const s=V1(e);return Math.round(t*s)/s}function Nm(e){const t=d.useRef(e);return fd(()=>{t.current=e}),t}function YO(e){e===void 0&&(e={});const{placement:t="bottom",strategy:s="absolute",middleware:r=[],platform:i,elements:{reference:a,floating:l}={},transform:o=!0,whileElementsMounted:c,open:u}=e,[h,f]=d.useState({x:0,y:0,strategy:s,placement:t,middlewareData:{},isPositioned:!1}),[m,p]=d.useState(r);Zd(m,r)||p(r);const[g,v]=d.useState(null),[b,j]=d.useState(null),x=d.useCallback(O=>{O!==N.current&&(N.current=O,v(O))},[]),w=d.useCallback(O=>{O!==S.current&&(S.current=O,j(O))},[]),y=a||g,k=l||b,N=d.useRef(null),S=d.useRef(null),C=d.useRef(h),E=c!=null,R=Nm(c),I=Nm(i),L=Nm(u),F=d.useCallback(()=>{if(!N.current||!S.current)return;const O={placement:t,strategy:s,middleware:m};I.current&&(O.platform=I.current),VO(N.current,S.current,O).then(H=>{const B={...H,isPositioned:L.current!==!1};T.current&&!Zd(C.current,B)&&(C.current=B,Ul.flushSync(()=>{f(B)}))})},[m,t,s,I,L]);fd(()=>{u===!1&&C.current.isPositioned&&(C.current.isPositioned=!1,f(O=>({...O,isPositioned:!1})))},[u]);const T=d.useRef(!1);fd(()=>(T.current=!0,()=>{T.current=!1}),[]),fd(()=>{if(y&&(N.current=y),k&&(S.current=k),y&&k){if(R.current)return R.current(y,k,F);F()}},[y,k,F,R,E]);const M=d.useMemo(()=>({reference:N,floating:S,setReference:x,setFloating:w}),[x,w]),P=d.useMemo(()=>({reference:y,floating:k}),[y,k]),D=d.useMemo(()=>{const O={position:s,left:0,top:0};if(!P.floating)return O;const H=dk(P.floating,h.x),B=dk(P.floating,h.y);return o?{...O,transform:"translate("+H+"px, "+B+"px)",...V1(P.floating)>=1.5&&{willChange:"transform"}}:{position:s,left:H,top:B}},[s,o,P.floating,h.x,h.y]);return d.useMemo(()=>({...h,update:F,refs:M,elements:P,floatingStyles:D}),[h,F,M,P,D])}const JO=e=>{function t(s){return{}.hasOwnProperty.call(s,"current")}return{name:"arrow",options:e,fn(s){const{element:r,padding:i}=typeof e=="function"?e(s):e;return r&&t(r)?r.current!=null?uk({element:r.current,padding:i}).fn(s):{}:r?uk({element:r,padding:i}).fn(s):{}}}},QO=(e,t)=>{const s=zO(e);return{name:s.name,fn:s.fn,options:[e,t]}},XO=(e,t)=>{const s=UO(e);return{name:s.name,fn:s.fn,options:[e,t]}},ZO=(e,t)=>({fn:KO(e).fn,options:[e,t]}),eL=(e,t)=>{const s=BO(e);return{name:s.name,fn:s.fn,options:[e,t]}},tL=(e,t)=>{const s=WO(e);return{name:s.name,fn:s.fn,options:[e,t]}},nL=(e,t)=>{const s=HO(e);return{name:s.name,fn:s.fn,options:[e,t]}},sL=(e,t)=>{const s=JO(e);return{name:s.name,fn:s.fn,options:[e,t]}};var rL=Object.defineProperty,iL=(e,t)=>rL(e,"name",{value:t,configurable:!0});function G1(e){const[t,s]=d.useState(void 0);return Vn(()=>{if(e){s({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(i=>{if(!Array.isArray(i)||!i.length)return;const a=i[0];let l,o;if("borderBoxSize"in a){const c=a.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]),t}iL(G1,"useSize");var aL=Object.defineProperty,wi=(e,t)=>aL(e,"name",{value:t,configurable:!0}),q1="Popper",[Y1,sf]=Gs(q1),[lL,J1]=Y1(q1),oL=wi(e=>{const{__scopePopper:t,children:s}=e,[r,i]=d.useState(null),[a,l]=d.useState(void 0);return n.jsx(lL,{scope:t,anchor:r,onAnchorChange:i,placementState:a,setPlacementState:l,children:s})},"Popper"),cL="PopperAnchor",uL=d.forwardRef(wi(function(t,s){const{__scopePopper:r,virtualRef:i,...a}=t,l=J1(cL,r),o=d.useRef(null),c=l.onAnchorChange,u=d.useCallback(v=>{o.current=v,v&&c(v)},[c]),h=bt(s,u),f=d.useRef(null);d.useEffect(()=>{if(!i)return;const v=f.current;f.current=i.current,v!==f.current&&c(f.current)});const m=l.placementState&&rf(l.placementState),p=m==null?void 0:m[0],g=m==null?void 0:m[1];return i?null:n.jsx(vt.div,{"data-radix-popper-side":p,"data-radix-popper-align":g,...a,ref:h})},"PopperAnchor")),Q1="PopperContent",[dL,EZ]=Y1(Q1),hL=d.forwardRef(wi(function(t,s){var Le,Ie,_e,U,ie,J,ye;const{__scopePopper:r,side:i="bottom",sideOffset:a=0,align:l="center",alignOffset:o=0,arrowPadding:c=0,avoidCollisions:u=!0,collisionBoundary:h=[],collisionPadding:f=0,sticky:m="partial",hideWhenDetached:p=!1,updatePositionStrategy:g="optimized",onPlaced:v,...b}=t,j=J1(Q1,r),[x,w]=d.useState(null),y=bt(s,w),[k,N]=d.useState(null),S=G1(k),C=(S==null?void 0:S.width)??0,E=(S==null?void 0:S.height)??0,R=i+(l!=="center"?"-"+l:""),I=typeof f=="number"?f:{top:0,right:0,bottom:0,left:0,...f},L=Array.isArray(h)?h:[h],F=L.length>0,T={padding:I,boundary:L.filter(X1),altBoundary:F},{refs:M,floatingStyles:P,placement:D,isPositioned:O,middlewareData:H}=YO({strategy:"fixed",placement:R,whileElementsMounted:wi((...ge)=>_O(...ge,{animationFrame:g==="always"}),"whileElementsMounted"),elements:{reference:j.anchor},middleware:[QO({mainAxis:a+E,alignmentAxis:o}),u&&XO({mainAxis:!0,crossAxis:!1,limiter:m==="partial"?ZO():void 0,...T}),u&&eL({...T}),tL({...T,apply:wi(({elements:ge,rects:$e,availableWidth:De,availableHeight:Je})=>{const{width:Ue,height:be}=$e.reference,Be=ge.floating.style;Be.setProperty("--radix-popper-available-width",`${De}px`),Be.setProperty("--radix-popper-available-height",`${Je}px`),Be.setProperty("--radix-popper-anchor-width",`${Ue}px`),Be.setProperty("--radix-popper-anchor-height",`${be}px`)},"apply")}),k&&sL({element:k,padding:c}),fL({arrowWidth:C,arrowHeight:E}),p&&nL({strategy:"referenceHidden",...T,boundary:F?T.boundary:void 0})]}),B=j.setPlacementState;Vn(()=>(B(D),()=>{B(void 0)}),[D,B]);const[Y,W]=rf(D),q=Rn(v);Vn(()=>{O&&(q==null||q())},[O,q]);const _=(Le=H.arrow)==null?void 0:Le.x,X=(Ie=H.arrow)==null?void 0:Ie.y,Q=((_e=H.arrow)==null?void 0:_e.centerOffset)!==0,[ee,fe]=d.useState();return Vn(()=>{x&&fe(window.getComputedStyle(x).zIndex)},[x]),n.jsx("div",{ref:M.setFloating,"data-radix-popper-content-wrapper":"",style:{...P,transform:O?P.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ee,"--radix-popper-transform-origin":[(U=H.transformOrigin)==null?void 0:U.x,(ie=H.transformOrigin)==null?void 0:ie.y].join(" "),...((J=H.hide)==null?void 0:J.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:n.jsx(dL,{scope:r,placedSide:Y,placedAlign:W,onArrowChange:N,arrowX:_,arrowY:X,shouldHideArrow:Q,children:n.jsx(vt.div,{"data-side":Y,"data-align":W,...b,ref:y,style:{...b.style,animation:O?(ye=b.style)==null?void 0:ye.animation:"none"}})})})},"PopperContent"));function X1(e){return e!==null}wi(X1,"isNotNull");var fL=wi(e=>({name:"transformOrigin",options:e,fn(t){var b,j,x;const{placement:s,rects:r,middlewareData:i}=t,l=((b=i.arrow)==null?void 0:b.centerOffset)!==0,o=l?0:e.arrowWidth,c=l?0:e.arrowHeight,[u,h]=rf(s),f={start:"0%",center:"50%",end:"100%"}[h],m=(((j=i.arrow)==null?void 0:j.x)??0)+o/2,p=(((x=i.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 rf(e){const[t,s="center"]=e.split("-");return[t,s]}wi(rf,"getSideAndAlignFromPlacement");var cj=oL,Z1=uL,eE=hL,mL=Object.defineProperty,on=(e,t)=>mL(e,"name",{value:t,configurable:!0}),[uj,AZ]=Gs("Tooltip",[sf]),dj=sf(),pL="TooltipProvider",gL=700,$g="tooltip.open",[xL,hj]=uj(pL),vL=on(e=>{const{__scopeTooltip:t,delayDuration:s=gL,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,l=d.useRef(!0),o=d.useRef(!1),c=d.useRef(0);return d.useEffect(()=>{const u=c.current;return()=>window.clearTimeout(u)},[]),n.jsx(xL,{scope:t,isOpenDelayedRef:l,delayDuration:s,onOpen:d.useCallback(()=>{r<=0||(window.clearTimeout(c.current),l.current=!1)},[r]),onClose:d.useCallback(()=>{r<=0||(window.clearTimeout(c.current),c.current=window.setTimeout(()=>l.current=!0,r))},[r]),isPointerInTransitRef:o,onPointerInTransitChange:d.useCallback(u=>{o.current=u},[]),disableHoverableContent:i,children:a})},"TooltipProvider"),Rg="Tooltip",[jL,_c]=uj(Rg),wL=on(e=>{const{__scopeTooltip:t,children:s,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:l,delayDuration:o}=e,c=hj(Rg,e.__scopeTooltip),u=dj(t),[h,f]=d.useState(null),[m,p]=d.useState(void 0),g=_s(),v=d.useRef(0),b=l??c.disableHoverableContent,j=o??c.delayDuration,x=d.useRef(!1),[w,y]=Di({prop:r,defaultProp:i??!1,onChange:on(R=>{R?(c.onOpen(),document.dispatchEvent(new CustomEvent($g))):c.onClose(),a==null||a(R)},"onChange"),caller:Rg}),k=d.useMemo(()=>w?x.current?"delayed-open":"instant-open":"closed",[w]),N=d.useCallback(()=>{window.clearTimeout(v.current),v.current=0,x.current=!1,y(!0)},[y]),S=d.useCallback(()=>{window.clearTimeout(v.current),v.current=0,y(!1)},[y]),C=d.useCallback(()=>{window.clearTimeout(v.current),v.current=window.setTimeout(()=>{x.current=!0,y(!0),v.current=0},j)},[j,y]);d.useEffect(()=>()=>{v.current&&(window.clearTimeout(v.current),v.current=0)},[]);const E=m??g;return n.jsx(cj,{...u,children:n.jsx(jL,{scope:t,contentId:E,setContentId:p,open:w,stateAttribute:k,trigger:h,onTriggerChange:f,onTriggerEnter:d.useCallback(()=>{c.isOpenDelayedRef.current?C():N()},[c.isOpenDelayedRef,C,N]),onTriggerLeave:d.useCallback(()=>{b?S():(window.clearTimeout(v.current),v.current=0)},[S,b]),onOpen:N,onClose:S,disableHoverableContent:b,children:s})})},"Tooltip"),hk="TooltipTrigger",yL=d.forwardRef(on(function(t,s){const{__scopeTooltip:r,...i}=t,a=_c(hk,r),l=hj(hk,r),o=dj(r),c=d.useRef(null),u=bt(s,c,a.onTriggerChange),h=d.useRef(!1),f=d.useRef(!1),m=d.useCallback(()=>h.current=!1,[]);return d.useEffect(()=>()=>document.removeEventListener("pointerup",m),[m]),n.jsx(Z1,{asChild:!0,...o,children:n.jsx(vt.button,{"aria-describedby":a.open?a.contentId:void 0,"data-state":a.stateAttribute,...i,ref:u,onPointerMove:Me(t.onPointerMove,p=>{p.pointerType!=="touch"&&!f.current&&!l.isPointerInTransitRef.current&&(a.onTriggerEnter(),f.current=!0)}),onPointerLeave:Me(t.onPointerLeave,()=>{a.onTriggerLeave(),f.current=!1}),onPointerDown:Me(t.onPointerDown,()=>{a.open&&a.onClose(),h.current=!0,document.addEventListener("pointerup",m,{once:!0})}),onFocus:Me(t.onFocus,()=>{h.current||a.onOpen()}),onBlur:Me(t.onBlur,a.onClose),onClick:Me(t.onClick,a.onClose)})})},"TooltipTrigger")),tE="TooltipPortal",[bL,kL]=uj(tE,{forceMount:void 0}),NL=on(e=>{const{__scopeTooltip:t,forceMount:s,children:r,container:i}=e,a=_c(tE,t);return n.jsx(bL,{scope:t,forceMount:s,children:n.jsx(wr,{present:s||a.open,children:n.jsx(Yh,{asChild:!0,container:i,children:r})})})},"TooltipPortal"),dc="TooltipContent",SL=d.forwardRef(on(function(t,s){const r=kL(dc,t.__scopeTooltip),{forceMount:i=r.forceMount,side:a="top",...l}=t,o=_c(dc,t.__scopeTooltip);return n.jsx(wr,{present:i||o.open,children:o.disableHoverableContent?n.jsx(nE,{side:a,...l,ref:s}):n.jsx(CL,{side:a,...l,ref:s})})},"TooltipContent")),CL=d.forwardRef(on(function(t,s){const r=_c(dc,t.__scopeTooltip),i=hj(dc,t.__scopeTooltip),a=d.useRef(null),l=bt(s,a),[o,c]=d.useState(null),{trigger:u,onClose:h}=r,f=a.current,{onPointerInTransitChange:m}=i,p=d.useCallback(()=>{c(null),m(!1)},[m]),g=d.useCallback((v,b)=>{const j=v.currentTarget,x={x:v.clientX,y:v.clientY},w=sE(x,j.getBoundingClientRect()),y=rE(x,w),k=iE(b.getBoundingClientRect()),N=lE([...y,...k]);c(N),m(!0)},[m]);return d.useEffect(()=>()=>p(),[p]),d.useEffect(()=>{if(u&&f){const v=on(j=>g(j,f),"handleTriggerLeave"),b=on(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]),d.useEffect(()=>{if(o){const v=on(b=>{const j=b.target,x={x:b.clientX,y:b.clientY},w=(u==null?void 0:u.contains(j))||(f==null?void 0:f.contains(j)),y=!aE(x,o);w?p():y&&(p(),h())},"handleTrackPointerGrace");return document.addEventListener("pointermove",v),()=>document.removeEventListener("pointermove",v)}},[u,f,o,h,p]),n.jsx(nE,{...t,ref:l})},"TooltipContentHoverable")),EL=u1("TooltipContent"),nE=d.forwardRef(on(function(t,s){const{__scopeTooltip:r,children:i,"aria-label":a,id:l,onEscapeKeyDown:o,onPointerDownOutside:c,...u}=t,h=_c(dc,r),f=dj(r),{onClose:m}=h;d.useEffect(()=>(document.addEventListener($g,m),()=>document.removeEventListener($g,m)),[m]),d.useEffect(()=>{if(h.trigger){const g=on(v=>{v.target instanceof Node&&v.target.contains(h.trigger)&&m()},"handleScroll");return window.addEventListener("scroll",g,{capture:!0}),()=>window.removeEventListener("scroll",g,{capture:!0})}},[h.trigger,m]);const{setContentId:p}=h;return Vn(()=>(p(l),()=>{p(void 0)}),[l,p]),n.jsx(qh,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:o,onPointerDownOutside:c,onFocusOutside:g=>g.preventDefault(),onDismiss:m,children:n.jsxs(eE,{"data-state":h.stateAttribute,role:a?void 0:"tooltip",id:a?void 0:h.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:[n.jsx(EL,{children:i}),a?n.jsx(yD,{id:h.contentId,role:"tooltip",children:a}):null]})})},"TooltipContentImpl"));function sE(e,t){const s=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),a=Math.abs(t.left-e.x);switch(Math.min(s,r,i,a)){case a:return"left";case i:return"right";case s:return"top";case r:return"bottom";default:throw new Error("unreachable")}}on(sE,"getExitSideFromRect");function rE(e,t,s=5){const r=[];switch(t){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}on(rE,"getPaddedExitPoints");function iE(e){const{top:t,right:s,bottom:r,left:i}=e;return[{x:i,y:t},{x:s,y:t},{x:s,y:r},{x:i,y:r}]}on(iE,"getPointsFromRect");function aE(e,t){const{x:s,y:r}=e;let i=!1;for(let a=0,l=t.length-1;a<t.length;l=a++){const o=t[a],c=t[l],u=o.x,h=o.y,f=c.x,m=c.y;h>r!=m>r&&s<(f-u)*(r-h)/(m-h)+u&&(i=!i)}return i}on(aE,"isPointInPolygon");function lE(e){const t=e.slice();return t.sort((s,r)=>s.x<r.x?-1:s.x>r.x?1:s.y<r.y?-1:s.y>r.y?1:0),oE(t)}on(lE,"getHull");function oE(e){if(e.length<=1)return e.slice();const t=[];for(let r=0;r<e.length;r++){const i=e[r];for(;t.length>=2;){const a=t[t.length-1],l=t[t.length-2];if((a.x-l.x)*(i.y-l.y)>=(a.y-l.y)*(i.x-l.x))t.pop();else break}t.push(i)}t.pop();const s=[];for(let r=e.length-1;r>=0;r--){const i=e[r];for(;s.length>=2;){const a=s[s.length-1],l=s[s.length-2];if((a.x-l.x)*(i.y-l.y)>=(a.y-l.y)*(i.x-l.x))s.pop();else break}s.push(i)}return s.pop(),t.length===1&&s.length===1&&t[0].x===s[0].x&&t[0].y===s[0].y?t:t.concat(s)}on(oE,"getHullPresorted");var fk=vL,hc=wL,fc=yL,mc=NL,pc=SL;let Vt={time:"auto",date:"auto",locale:void 0};function fj(e){const t=e.timeFormat===void 0?Vt.time:e.timeFormat==="12h"||e.timeFormat==="24h"?e.timeFormat:"auto",s=e.dateFormat===void 0?Vt.date:e.dateFormat==="short"||e.dateFormat==="long"||e.dateFormat==="iso"?e.dateFormat:"auto";Vt={time:t,date:s,locale:e.locale??Vt.locale}}function cE(){return{time:Vt.time,date:Vt.date}}function zc(e,t){const s=Vt;fj(e);try{return t()}finally{Vt=s}}const Ig="buddi:formats";function Uc(){if(Vt.locale)return Vt.locale;try{return typeof navigator<"u"&&navigator.language?navigator.language:"en-US"}catch{return"en-US"}}const mk=new Map;function Kl(e,t){const s=`${e}|${JSON.stringify(t)}`;let r=mk.get(s);if(!r){try{r=new Intl.DateTimeFormat(e,t)}catch{r=new Intl.DateTimeFormat(e,{...t,timeZone:"UTC"})}mk.set(s,r)}return r}function Sm(e,t,s,r){return Object.fromEntries(Kl(s,{timeZone:t,...r}).formatToParts(e).map(i=>[i.type,i.value]))}function AL(){return Vt.time==="12h"?{hour:"numeric",minute:"2-digit",hourCycle:"h12"}:Vt.time==="24h"?{hour:"2-digit",minute:"2-digit",hourCycle:"h23"}:{hour:af()?"numeric":"2-digit",minute:"2-digit"}}function TL(){return Vt.time==="auto"?Uc():"en-US"}function zt(e,t){return Number.isNaN(e.getTime())?"—":Kl(TL(),{timeZone:t,...AL()}).format(e)}function $L(e){return e>=1440&&!af()?"24:00":zt(new Date(Date.UTC(2026,0,1,Math.floor(e/60)%24,e%60)),"UTC")}function af(){var e;return Vt.time!=="auto"?Vt.time==="12h":((e=Kl(Uc(),{hour:"numeric"}).resolvedOptions().hourCycle)==null?void 0:e.startsWith("h1"))===!0}function uE(){return`Profile (${af()?"12-hour":"24-hour"})`}function RL(){if(Vt.date!=="auto")return Vt.date==="short";const e=Kl(Uc(),{month:"short",day:"numeric"}).formatToParts(new Date(Date.UTC(2026,9,1))).map(t=>t.type);return e.indexOf("month")<e.indexOf("day")}function yr(e,t,s={}){return IL(e,t,s).replace(/\bSept\b/g,"Sep")}function IL(e,t,s){if(Number.isNaN(e.getTime()))return"—";const{weekday:r=!1,year:i=!1,compact:a=!1}=s;switch(Vt.date){case"iso":{const l=Sm(e,t,"en-CA",{year:"numeric",month:"2-digit",day:"2-digit",...r?{weekday:a?"short":"long"}:{}}),o=`${l.year}-${l.month}-${l.day}`;return r?`${l.weekday} ${o}`:o}case"short":{const l=Sm(e,t,"en-US",{month:"short",day:"numeric",year:"numeric",weekday:"short"});return`${r?`${l.weekday}, `:""}${l.month} ${l.day}${i?`, ${l.year}`:""}`}case"long":{const l=Sm(e,t,"en-GB",{month:a?"short":"long",day:"numeric",year:"numeric",weekday:a?"short":"long"});return`${r?`${l.weekday}, `:""}${l.day} ${l.month}${i?` ${l.year}`:""}`}default:return Kl(Uc(),{timeZone:t,month:a?"short":"long",day:"numeric",...i?{year:"numeric"}:{},...r?{weekday:a?"short":"long"}:{}}).format(e)}}function dE(e,t){if(Vt.date==="iso")return`${e}-${String(t).padStart(2,"0")}`;const s=new Date(Date.UTC(e,t-1,15)),r=Vt.date==="auto"?Uc():"en-GB";return Kl(r,{timeZone:"UTC",month:"long",year:"numeric"}).format(s)}function Bc(e,t={}){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:yr(r,"UTC",t)}function nt(e,t){if(!e)return"—";const s=new Date(e);return Number.isNaN(s.getTime())?String(e):`${yr(s,t,{year:!0,compact:!0})}, ${zt(s,t)}`}function mj(e,t){return`${yr(e,t,{weekday:!0,compact:!0})}, ${zt(e,t)}`}function Fe(e,t=Date.now()){if(!e)return"";const s=new Date(e).getTime();if(Number.isNaN(s))return"";const r=Math.round((s-t)/1e3),i=Math.abs(r),[a,l]=i<60?[r,"second"]:i<3600?[Math.round(r/60),"minute"]:i<86400?[Math.round(r/3600),"hour"]:[Math.round(r/86400),"day"];return new Intl.RelativeTimeFormat("en",{numeric:"auto"}).format(a,l)}function pj(e,t=Date.now()){if(!e)return"";const s=new Date(e).getTime();if(Number.isNaN(s))return"";const r=Math.abs(Math.round((t-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 PL(e,t=Date.now()){const s=pj(e,t);return s===""?"":s==="now"||new Date(e).getTime()>t?"just now":s==="1 d"?"yesterday":`${s} ago`}function ML(e,t){if(e==null||!Number.isFinite(e))return"—";try{return new Intl.NumberFormat("en-US",{style:"currency",currency:t??"USD",maximumFractionDigits:0}).format(e)}catch{return e.toFixed(2)}}function Xt(e){return new Intl.NumberFormat("en-US").format(e)}function Pg(e){return[...e.cacheRead?[`cached ${Xt(e.cacheRead)}`]:[],...e.cacheWrite?[`cache write ${Xt(e.cacheWrite)}`]:[]].join(", ")}function DL(e){const t=Pg(e);return`${Xt(e.input)} in${t?` (${t})`:""} / ${Xt(e.output)} out`}function is(e){try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function gc(e,t=8){return e.length<=t?e:e.slice(0,t)}function Bs(e,t){return e.length<=t?e:`${e.slice(0,t-1)}…`}function xc(e){if(e.kind!=="agent")return e.title;const t=e.title.replace(/^@[^\s:]+:\s+/,"");return t.trim()===""?e.title:t}const pk="buddi_csrf",Vl="x-buddi-csrf",gr="buddi:agents-changed",ta="buddi:status-changed",go=e=>(window.dispatchEvent(new Event(ta)),e),Mg="buddi:locked",OL="This page's sign-in no longer matches its cookies. Reload the page and try again.";class ve extends Error{constructor(t,s,r){super(s),this.status=t,this.detail=r,this.name="ApiError"}}function ja(){var r;const e=Number(location.port)||(location.protocol==="https:"?443:80),t=document.cookie.match(new RegExp(`(?:^|; )${pk}_${e}=([^;]*)`));if(t!=null&&t[1])return decodeURIComponent(t[1]);const s=[...document.cookie.matchAll(new RegExp(`(?:^|; )${pk}(?:_\\d+)?=([^;]*)`,"g"))];return s.length===1&&((r=s[0])!=null&&r[1])?decodeURIComponent(s[0][1]):""}const eh="buddi isn't answering.";let Dg=null;const Og=new Set;function xo(e){if(e!==(Dg===null)){Dg=e?null:Date.now();for(const t of Og)t()}}function vc(){return Dg}function gj(e){return Og.add(e),()=>Og.delete(e)}function th(e){return e instanceof ve&&(e.status===0||e.status===502||e.status===503)&&e.message===eh}async function wa(e,t={}){var l;let s;try{s=await fetch(e,{...t,credentials:"same-origin",redirect:"error",headers:{Accept:"application/json",...t.headers??{}}})}catch(o){throw(o==null?void 0:o.name)==="AbortError"||(l=t.signal)!=null&&l.aborted?o:(xo(!1),new ve(0,eh,o))}if(s.status===401)throw xo(!0),new ve(401,"This session has expired. Run `buddi dashboard` for a fresh link.");if(s.status===423)throw xo(!0),window.dispatchEvent(new Event(Mg)),new ve(423,"This dashboard is locked.");const r=await s.text(),i=r===""?null:LL(r),a=i&&typeof i=="object"&&"error"in i?String(i.error):void 0;if((s.status===502||s.status===503)&&a===void 0)throw xo(!1),new ve(s.status,eh,i);if(xo(!0),!s.ok){const o=(t.method??"GET").toUpperCase(),c=a??(s.status===403&&o!=="GET"&&o!=="HEAD"?OL:`request failed (${s.status})`);throw new ve(s.status,c,i)}return i}function LL(e){try{return JSON.parse(e)}catch{return null}}function Cm(){return cE().time==="auto"?{hour:af()?"12":"24"}:{}}function je(e,t={}){const s=new URLSearchParams;for(const[i,a]of Object.entries(t))a!==void 0&&a!==""&&s.set(i,String(a));const r=s.toString();return wa(`/api${e}${r?`?${r}`:""}`)}function Lg(e,t){return wa(`/api${e}`,{method:"POST",headers:{[Vl]:ja()},body:t})}function ar(e){return wa(`/api${e}`,{method:"DELETE",headers:{[Vl]:ja()}})}function te(e,t={}){return wa(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/json",[Vl]:ja()},body:JSON.stringify(t??{})})}function hE(e,t,s,r={}){const i=t.name.replace(/[^\w.-]+/g,"_").slice(-120)||s;return wa(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/octet-stream",[Vl]:ja(),"X-Filename":i,...r},body:t})}function gk(e,t,s){return hE(e,t,"backup.tar.gz",{...s.passphrase?{"X-Backup-Passphrase":s.passphrase}:{},...s.confirm?{"X-Backup-Confirm":s.confirm}:{}})}function FL(e,t={}){return wa(`/api${e}`,{method:"PATCH",headers:{"Content-Type":"application/json",[Vl]:ja()},body:JSON.stringify(t??{})})}function tr(e,t={}){return wa(`/api${e}`,{method:"PUT",headers:{"Content-Type":"application/json",[Vl]:ja()},body:JSON.stringify(t??{})})}function _L(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 md="gpt-oss:120b",zL=["approval","question","watcher","reminder","failure","recap","plugin","agent"],Fg=["mon","tue","wed","thu","fri","sat","sun"],Ve={agents:()=>je("/chat/agents"),views:()=>je("/chat/views"),conversations:(e,t)=>je(`/chat/${encodeURIComponent(e)}/conversations`,{limit:t}),startConversation:e=>te(`/chat/${encodeURIComponent(e)}/conversations`),conversation:e=>je(`/chat/conversations/${encodeURIComponent(e)}`),deleteCarryOver:e=>ar(`/chat/conversations/${encodeURIComponent(e)}/carry-over`),send:(e,t)=>te(`/chat/${encodeURIComponent(e)}/messages`,t),answerQuestion:(e,t)=>te(`/chat/questions/${encodeURIComponent(e)}/answer`,t),cancel:e=>te(`/chat/conversations/${encodeURIComponent(e)}/cancel`),attach:e=>{const t=new FormData;return t.append("file",e,e.name),Lg("/chat/attachments",t)},transcribe:e=>te("/speech/transcribe",e),say:e=>te("/speech/say",e),discardAttachment:e=>ar(`/artifacts/${encodeURIComponent(e)}`),groups:()=>je("/groups"),group:e=>je(`/groups/${encodeURIComponent(e)}`),createGroup:e=>te("/groups",e),updateGroup:(e,t)=>FL(`/groups/${encodeURIComponent(e)}`,t),deleteGroup:e=>ar(`/groups/${encodeURIComponent(e)}`),restoreGroup:e=>te(`/groups/${encodeURIComponent(e)}/restore`),clearGroup:e=>te(`/groups/${encodeURIComponent(e)}/clear`),groupConversations:e=>je(`/groups/${encodeURIComponent(e)}/conversations`),startGroupConversation:e=>te(`/groups/${encodeURIComponent(e)}/conversations`),sendToGroup:(e,t)=>te(`/groups/${encodeURIComponent(e)}/messages`,t),streamUrl:e=>`/api/chat/conversations/${encodeURIComponent(e)}/stream`};function xj(e){return e.httpStatus===401||e.httpStatus===403||e.state==="authentication-error"||e.state==="access-denied"}const $={providers:()=>je("/providers"),providerAccounts:()=>je("/provider-accounts"),probeModels:e=>te("/provider-accounts/probe-models",e),accountModels:(e,t=!1)=>te(`/provider-accounts/${encodeURIComponent(e)}/models`,{refresh:t}),saveProviderAccount:e=>te("/provider-accounts/save",e),testProviderAccount:e=>te(`/provider-accounts/${encodeURIComponent(e)}/test`),removeProviderAccount:(e,t)=>te(`/provider-accounts/${encodeURIComponent(e)}/remove`,{revision:t}),codexAccountAction:(e,t,s)=>te(`/provider-accounts/${encodeURIComponent(e)}/${t}`,{revision:s}),ollamaConnect:(e,t)=>te(`/provider-accounts/${encodeURIComponent(e)}/ollama/connect`,{revision:t}),ollamaPoll:(e,t)=>te(`/provider-accounts/${encodeURIComponent(e)}/ollama/poll`,{attemptId:t}),ollamaDisconnect:(e,t)=>te(`/provider-accounts/${encodeURIComponent(e)}/ollama/disconnect`,{revision:t}),anthropicAccountAction:(e,t,s,r)=>te(`/provider-accounts/${encodeURIComponent(e)}/anthropic/${t}`,{revision:s,...r}),assignProviderAccount:(e,t,s)=>te(`/agents/${encodeURIComponent(e)}/account`,{accountId:t,model:s}),configureProvider:(e,t)=>te(`/providers/${encodeURIComponent(e)}/settings`,t),saveCredential:(e,t)=>te(`/providers/credentials/${encodeURIComponent(e)}/save`,{value:t}),removeCredential:e=>te(`/providers/credentials/${encodeURIComponent(e)}/remove`),testProvider:e=>te(`/providers/${encodeURIComponent(e)}/test`),browserProfiles:e=>je("/host/browser-profiles",{app:e}),installedApps:()=>je("/host/apps"),browser:e=>je(`/browser${e?`?agentId=${encodeURIComponent(e.agentId)}&conversationId=${encodeURIComponent(e.conversationId)}`:""}`),browserControl:(e,t)=>te(`/browser/${e}`,t===void 0?{}:{sessionId:t}),browserSettings:e=>te("/browser/settings",e),computerPermissions:(e=!1)=>te("/browser/permissions",{prompt:e}),browserInstall:()=>te("/browser/install",{}),browserCheck:()=>te("/browser/check",{}),previewLink:(e,t)=>je(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(t)}/link`),previewCheck:(e,t)=>je(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(t)}/check`),extension:()=>je("/extension"),pairExtension:e=>te("/extension/pair",{code:e}),forgetExtension:()=>ar("/extension/pair"),session:()=>je("/session"),overview:()=>je("/overview"),events:e=>je("/events",e),eventKinds:()=>je("/events/kinds"),conversations:()=>je("/conversations"),conversation:e=>je(`/conversations/${encodeURIComponent(e)}`),missions:()=>je("/missions"),jobs:(e={})=>je("/jobs",e),approvals:()=>je("/approvals"),approval:e=>je(`/approvals/${encodeURIComponent(e)}`).then(t=>t.action),offers:()=>je("/offers"),dismissOffer:e=>te(`/offers/${encodeURIComponent(e)}/dismiss`,{}),dismissOffers:e=>te("/offers/dismiss-all",{ids:e}),agentOffers:()=>je("/agent-offers"),catalogue:(e=!1)=>je(`/catalogue${e?"?refresh=1":""}`),cataloguePlan:(e,t={})=>te(`/catalogue/${encodeURIComponent(e)}/plan`,t),catalogueInstall:(e,t)=>te(`/catalogue/${encodeURIComponent(e)}/install`,t),catalogueJob:e=>je(`/catalogue/jobs/${encodeURIComponent(e)}`),catalogueConfirm:(e,t)=>te(`/catalogue/jobs/${encodeURIComponent(e)}/confirm`,{approve:t}),catalogueUpdatePlan:(e,t)=>te(`/catalogue/${encodeURIComponent(e)}/update/plan`,{agentId:t}),catalogueUpdate:(e,t,s,r=!1)=>te(`/catalogue/${encodeURIComponent(e)}/update`,{agentId:t,plan:s,...r?{replace:!0}:{}}),agentRemovePreview:e=>je(`/agents/${encodeURIComponent(e)}/remove`),removeAgent:e=>te(`/agents/${encodeURIComponent(e)}/remove`),dismissAgentOffer:(e,t)=>te(`/agent-offers/${encodeURIComponent(e)}/${encodeURIComponent(t)}/dismiss`,{}),proposals:()=>je("/proposals"),setDigestSchedule:(e,t)=>te("/proposals/digest-schedule",{day:e,hour:t}),keepProposal:(e,t)=>te(`/proposals/${encodeURIComponent(e)}/keep`,t===void 0?{}:{text:t}),keepAllProposals:e=>te("/proposals/keep-all",{ids:e}),discardProposal:(e,t)=>te(`/proposals/${encodeURIComponent(e)}/discard`,t?{reason:t}:{}),reminders:()=>je("/reminders"),sentinels:()=>je("/sentinels"),setSentinelEnabled:(e,t)=>te(`/sentinels/${encodeURIComponent(e)}/enabled`,{enabled:t}),widgets:(e="home")=>je("/widgets",{...e==="lock"?{surface:e}:{},...Cm()}),saveWidgets:(e,t)=>tr(`/widgets/${e}`,{placements:t.map(({key:s,widget:r,size:i,settings:a})=>({...s?{key:s}:{},widget:r,size:i,settings:a}))}),widgetSettings:e=>je(`/widgets/settings/${encodeURIComponent(e)}`),previewWidget:e=>te("/widgets/preview",{...e,...Cm()}),refreshWidget:(e,t="home")=>te(`/widgets/${encodeURIComponent(e)}/refresh${t==="lock"?"?surface=lock":""}`),homeDismiss:(e,t)=>te("/home/dismiss",{slot:e,token:t}),setGlanceHidden:(e,t)=>te(`/home/glances/${encodeURIComponent(e)}/hidden`,{hidden:t}),rail:()=>je("/rail"),setRailHidden:(e,t,s)=>te(`/rail/pages/${encodeURIComponent(e)}/${encodeURIComponent(t)}/hidden`,{hidden:s}),snoozeAlerts:(e,t,s)=>te("/alerts/snooze",{keys:e,snoozed:t,...s!==void 0?{days:s}:{}}),muteAlert:(e,t)=>te("/alerts/mute",{key:e,scope:t}),unmuteAlert:e=>te(`/alerts/mutes/${encodeURIComponent(e)}/remove`,{}),actOnAlerts:e=>te("/alerts/act",{entries:e}),askAboutAlerts:e=>te("/alerts/ask",{keys:e}),agents:()=>je("/agents"),library:e=>je("/artifacts",e),libraryEntry:(e,t=0)=>je(`/artifacts/${encodeURIComponent(e)}`,t?{contexts:t}:{}),onboarding:()=>je("/onboarding"),onboardingStep:(e,t={})=>te("/onboarding/step",{step:e,...t}),takeOn:e=>te("/onboarding/take-on",{tiles:e}),takeOnProgress:()=>je("/onboarding/take-on"),completeOnboarding:()=>te("/onboarding/complete"),skipOnboarding:()=>te("/onboarding/skip"),createFirstAgent:e=>te("/onboarding/agent",e),ollama:()=>je("/onboarding/ollama"),mlxh:()=>je("/onboarding/mlxh"),firstAgentPersona:()=>je("/onboarding/agent"),updateFirstAgent:e=>te("/onboarding/agent/update",e),bindBrain:e=>te("/onboarding/brain",e),pages:()=>je("/pages"),pageQuery:(e,t,s={})=>je(`/pages/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,s),pageFileUrl:(e,t,s={})=>{const r=new URLSearchParams(Object.entries(s).filter(([,i])=>i!=="")).toString();return`/api/pages/${encodeURIComponent(e)}/${encodeURIComponent(t)}${r?`?${r}`:""}`},pageAct:(e,t)=>te(`/pages/${encodeURIComponent(e)}/act`,t),telegram:()=>je("/telegram"),saveTelegramToken:e=>te("/telegram/token",{token:e}),telegramPairing:()=>te("/telegram/pairing"),telegramBot:()=>je("/telegram/bot"),telegramDevices:()=>je("/telegram/devices"),unpairTelegramDevice:e=>ar(`/telegram/devices/${encodeURIComponent(e)}`),notifications:(e=20)=>je("/notifications",{limit:e}),notificationsNeedingYou:()=>je("/notifications",{needs:1}),notificationSeen:e=>te(`/notifications/${encodeURIComponent(e)}/seen`),notificationSettings:()=>je("/notifications/settings"),saveNotificationSettings:e=>tr("/notifications/settings",e),focus:()=>je("/notifications/focus"),lockState:()=>je("/lock"),lockScreen:()=>je("/lock/screen",Cm()),lockNow:(e="owner",t)=>te("/lock",{reason:e,...e==="idle"&&t!==void 0?{idleForMs:Math.max(0,Math.round(t))}:{}}),unlock:e=>te("/lock/unlock",{pin:e}),lockActivity:()=>te("/lock/activity"),setPin:(e,t)=>tr("/lock/pin",t===void 0?{pin:e}:{pin:e,current:t}),removePin:e=>te("/lock/pin/remove",{current:e}),setLockSettings:e=>tr("/lock/settings",e),uploadLockBackground:e=>{const t=new FormData;return t.append("file",e),Lg("/lock/background",t)},removeLockBackground:()=>ar("/lock/background"),setFocus:(e,t)=>tr("/notifications/focus",t?{mode:e,duration:t}:{mode:e}).then(go),testChannel:e=>te("/notifications/test",{channel:e}),setAgentMuted:(e,t)=>te("/notifications/agent-mute",{agentId:e,muted:t}),currentTip:e=>je(e?`/tips/current?preview=${encodeURIComponent(e)}`:"/tips/current"),tips:()=>je("/tips"),restoreTip:e=>te(`/tips/${encodeURIComponent(e)}/restore`),dismissTip:e=>te(`/tips/${encodeURIComponent(e)}/dismiss`),laterTip:e=>te(`/tips/${encodeURIComponent(e)}/later`),tipsSeenPage:e=>te("/tips/seen-page",{page:e}),tipsSettings:()=>je("/tips/settings"),saveTipsSettings:e=>tr("/tips/settings",{enabled:e}),presence:e=>te("/presence",{state:e}),owner:()=>je("/owner"),setOwner:e=>te("/owner",e),findPlace:e=>te("/owner/places/find",{address:e}),savePlace:e=>te("/owner/places",e),removePlace:e=>te("/owner/places/remove",{id:e}),memory:e=>je(e?`/memory?agent=${encodeURIComponent(e)}`:"/memory"),setPreference:e=>te("/memory/preferences",e),forgetPreference:e=>te("/memory/preferences/forget",e),updateNote:(e,t)=>te(`/memory/notes/${encodeURIComponent(e)}`,t),forgetNote:e=>te(`/memory/notes/${encodeURIComponent(e)}/forget`),setDelegates:(e,t)=>te(`/agents/${encodeURIComponent(e)}/delegates`,{delegates:t}),agentProfile:e=>je(`/agents/${encodeURIComponent(e)}/profile`),agentSkills:e=>je(`/agents/${encodeURIComponent(e)}/skills`),removeSkill:(e,t)=>te(`/agents/${encodeURIComponent(e)}/skills/${encodeURIComponent(t)}/remove`,{}),host:(e,t)=>je("/host",{agentId:e,conversationId:t}),connections:()=>je("/connections"),connection:e=>je(`/connections/${e}`),addConnection:(e,t)=>te("/connections",{url:e,...t?{name:t}:{}}),addProgram:e=>te("/connections",{transport:"stdio",...e}),updateProgram:(e,t)=>te(`/connections/${e}/program`,t),connectionConsent:(e,t)=>te(`/connections/${e}/consent`,t?{clientId:t}:{}),connectionToken:(e,t)=>te(`/connections/${e}/token`,t),connectionDevice:e=>te(`/connections/${e}/device`,{}),connectionCallback:e=>te("/connections/callback",e),connectionReview:e=>je(`/connections/${e}/review`),saveConnectionReview:(e,t)=>te(`/connections/${e}/review`,t),grantConnection:(e,t,s=!1)=>te(`/connections/${e}/grant`,s?{agents:t,exact:!0}:{agents:t}),setConnectionHolder:(e,t,s)=>te(`/connections/${e}/holders/${encodeURIComponent(t)}`,{held:s}),disconnect:e=>ar(`/connections/${e}`),connectionSignals:()=>je("/connections/signals"),connectionTools:e=>je(`/connections/${e}/tools`),rememberedApprovals:e=>je(`/connections/remembered/${encodeURIComponent(e)}`),setRememberedApproval:(e,t,s)=>te("/connections/remembered",{agent:e,tool:t,remember:s}),secrets:()=>je("/secrets"),secretUses:(e,t)=>je("/secrets/uses",{name:e,limit:t}),secretsAct:(e,t)=>te("/secrets/act",{tool:e,args:t}),stopHost:(e,t)=>te("/host/stop",{agentId:e,conversationId:t}),revokeHost:e=>te("/host/revoke",{id:e}),decide:(e,t,s,r)=>te(`/approvals/${encodeURIComponent(e)}/${t}`,s||r?{...s?{permissionScope:s}:{},...r?{ownerChoices:r}:{}}:void 0),setPaused:e=>te("/pause",{paused:e}).then(go),service:()=>je("/service"),serviceAction:e=>te(`/service/${e}`),version:()=>je("/version"),checkVersion:()=>te("/version/check"),setVersionCheck:e=>tr("/version/check",{enabled:e}),tailscale:()=>je("/tailscale"),setTailscale:e=>tr("/tailscale",e),apiTokens:()=>je("/api-tokens"),createApiToken:e=>te("/api-tokens",{name:e}),revokeApiToken:e=>ar(`/api-tokens/${encodeURIComponent(e)}`),startUpgrade:e=>te("/upgrade",e===void 0?{}:{version:e}),upgradeJob:e=>je(`/upgrade/jobs/${encodeURIComponent(e)}`),backups:()=>je("/backups"),startBackup:e=>te("/backups",{encrypt:e}),verifyArchive:e=>te("/backups/verify",{name:e}),restoreArchive:e=>te("/backups/restore",e),restoreUpload:(e,t)=>gk("/backups/restore",e,t),backupJob:e=>je(`/backups/jobs/${encodeURIComponent(e)}`),backupSchedule:()=>je("/backups/schedule"),setBackupSchedule:e=>tr("/backups/schedule",e),backupPassphrase:()=>je("/backups/passphrase"),setBackupPassphrase:e=>tr("/backups/passphrase",{passphrase:e}),plugins:()=>je("/plugins"),market:(e=!1)=>je(`/market${e?"?refresh=1":""}`),marketAssetUrl:e=>`/api/market/asset?url=${encodeURIComponent(e)}`,pluginFolders:e=>je("/plugins/folders",e?{path:e}:{}),stagePlugin:e=>te("/plugins/stage",{spec:e}),uploadPlugin:e=>hE("/plugins/upload",e,"plugin.tgz"),pluginJob:e=>je(`/plugins/jobs/${encodeURIComponent(e)}`),approveStaged:(e,t)=>te(`/plugins/staged/${encodeURIComponent(e)}/approve`,t),rejectStaged:e=>te(`/plugins/staged/${encodeURIComponent(e)}/reject`),openedStaged:e=>te(`/plugins/staged/${encodeURIComponent(e)}/opened`),updatePlugin:(e,t,s)=>te(`/plugins/${encodeURIComponent(e)}/update`,{...t?{version:t}:{},...s?{from:s}:{}}),setPluginEnabled:(e,t)=>te(`/plugins/${encodeURIComponent(e)}/${t?"enable":"disable"}`,{}),uninstallPlugin:(e,t)=>te(`/plugins/${encodeURIComponent(e)}/uninstall`,t),acceptPluginAgent:(e,t)=>te(`/plugins/${encodeURIComponent(e)}/agents/${encodeURIComponent(t)}/accept`),recovery:()=>je("/recovery"),leaveRecovery:e=>te("/recovery/leave",e),firstRunRestore:(e,t)=>gk("/onboarding/restore",e,{passphrase:t}),setMissionEnabled:(e,t)=>te(`/missions/${encodeURIComponent(e)}/enabled`,{enabled:t}),keepMission:e=>te(`/missions/${encodeURIComponent(e)}/keep`,{}),answerStillUseful:(e,t)=>te(`/missions/${encodeURIComponent(e)}/still-useful`,{answer:t}),setMisfirePolicy:(e,t,s)=>te(`/missions/${encodeURIComponent(e)}/schedule`,{misfirePolicy:t,...s===void 0?{}:{deadlineMinutes:s}}),retryJob:e=>te(`/jobs/${encodeURIComponent(e)}/retry`),cancelJob:e=>te(`/jobs/${encodeURIComponent(e)}/cancel`),jobFailures:()=>je("/jobs/failures"),dismissJobs:e=>te("/jobs/dismiss",e).then(go),undismissJobs:e=>te("/jobs/undismiss",{ids:e}).then(go),retryJobs:e=>te("/jobs/retry",e).then(go),setDefaultAgent:e=>te("/agents/default",{agentId:e}),agentTools:e=>je(`/agents/${encodeURIComponent(e)}/tools`),agentFile:e=>je(`/agents/${encodeURIComponent(e)}/file`),uploadAgentPicture:(e,t)=>{const s=new FormData;return s.append("file",t,t.name),Lg(`/agents/${encodeURIComponent(e)}/avatar`,s)},removeAgentPicture:e=>ar(`/agents/${encodeURIComponent(e)}/avatar`),updateAgentFile:(e,t)=>te(`/agents/${encodeURIComponent(e)}/file`,t),setAgentEngine:(e,t)=>te(`/agents/${encodeURIComponent(e)}/engine`,t),takeOffer:(e,t)=>te(`/offers/${encodeURIComponent(e)}/take`,t?{conversationId:t}:{}),cancelReminder:e=>te(`/reminders/${encodeURIComponent(e)}/cancel`,{reason:"cancelled from the dashboard"})},_g="buddi.chatDraft";function vj(e,t){try{window.sessionStorage.setItem(_g,JSON.stringify({agentId:e,text:t}))}catch{}}function UL(e){try{const t=window.sessionStorage.getItem(_g);if(!t)return null;const s=JSON.parse(t);return s.agentId!==e||typeof s.text!="string"?null:(window.sessionStorage.removeItem(_g),s.text)}catch{return null}}function fE(e){return e==="anthropic"||e==="openai"}function mE(e,t){var i,a;if(!e)return null;const s=e.credentialEnv&&(t!=null&&t.accounts.some(l=>l.id===e.credentialEnv))?e.credentialEnv:(a=(i=t==null?void 0:t.bindings)==null?void 0:i.find(l=>l.agentId===e.id))==null?void 0:a.accountId,r=s?t==null?void 0:t.accounts.find(l=>l.id===s):void 0;return(r==null?void 0:r.kind)??e.provider}const BL="Thinking is up to this model. What it writes while thinking is shown apart and kept out of the answer.";var WL=Object.defineProperty,HL=(e,t)=>WL(e,"name",{value:t,configurable:!0}),KL=d.createContext(void 0);function lf(e){const t=d.useContext(KL);return e||t||"ltr"}HL(lf,"useDirection");var VL=Object.defineProperty,jj=(e,t)=>VL(e,"name",{value:t,configurable:!0}),Tu=0,nr=null;function GL(e){return of(),e.children}jj(GL,"FocusGuards");function of(){d.useEffect(()=>{nr||(nr={start:zg(),end:zg()});const{start:e,end:t}=nr;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),Tu++,()=>{Tu===1&&(nr==null||nr.start.remove(),nr==null||nr.end.remove(),nr=null),Tu=Math.max(0,Tu-1)}},[])}jj(of,"useFocusGuards");function zg(){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}jj(zg,"createFocusGuard");var qL=Object.defineProperty,Tn=(e,t)=>qL(e,"name",{value:t,configurable:!0}),Em="focusScope.autoFocusOnMount",Am="focusScope.autoFocusOnUnmount",xk={bubbles:!1,cancelable:!0},pE=d.forwardRef(Tn(function(t,s){const{loop:r=!1,trapped:i=!1,onMountAutoFocus:a,onUnmountAutoFocus:l,...o}=t,[c,u]=d.useState(null),h=Rn(a),f=Rn(l),m=d.useRef(null),p=bt(s,u),g=d.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;d.useEffect(()=>{if(i){let b=function(y){if(g.paused||!c)return;const k=y.target;c.contains(k)?m.current=k:Ar(m.current,{select:!0})},j=function(y){if(g.paused||!c)return;const k=y.relatedTarget;k!==null&&(c.contains(k)||Ar(m.current,{select:!0}))},x=function(y){if(document.activeElement===document.body)for(const N of y)N.removedNodes.length>0&&Ar(c)};Tn(b,"handleFocusIn"),Tn(j,"handleFocusOut"),Tn(x,"handleMutations"),document.addEventListener("focusin",b),document.addEventListener("focusout",j);const w=new MutationObserver(x);return c&&w.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",b),document.removeEventListener("focusout",j),w.disconnect()}}},[i,c,g.paused]),d.useEffect(()=>{if(c){vk.add(g);const b=document.activeElement;if(!c.contains(b)){const x=new CustomEvent(Em,xk);c.addEventListener(Em,h),c.dispatchEvent(x),x.defaultPrevented||(gE(yE(wj(c)),{select:!0}),document.activeElement===b&&Ar(c))}return()=>{c.removeEventListener(Em,h),setTimeout(()=>{const x=new CustomEvent(Am,xk);c.addEventListener(Am,f),c.dispatchEvent(x),x.defaultPrevented||Ar(b??document.body,{select:!0}),c.removeEventListener(Am,f),vk.remove(g)},0)}}},[c,h,f,g]);const v=d.useCallback(b=>{if(!r&&!i||g.paused)return;const j=b.key==="Tab"&&!b.altKey&&!b.ctrlKey&&!b.metaKey,x=document.activeElement;if(j&&x){const w=b.currentTarget,[y,k]=xE(w);y&&k?!b.shiftKey&&x===k?(b.preventDefault(),r&&Ar(y,{select:!0})):b.shiftKey&&x===y&&(b.preventDefault(),r&&Ar(k,{select:!0})):x===w&&b.preventDefault()}},[r,i,g.paused]);return n.jsx(vt.div,{tabIndex:-1,...o,ref:p,onKeyDown:v})},"FocusScope"));function gE(e,{select:t=!1}={}){const s=document.activeElement;for(const r of e)if(Ar(r,{select:t}),document.activeElement!==s)return}Tn(gE,"focusFirst");function xE(e){const t=wj(e),s=Ug(t,e),r=Ug(t.reverse(),e);return[s,r]}Tn(xE,"getTabbableEdges");function wj(e){const t=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:Tn(r=>{const i=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||i?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;s.nextNode();)t.push(s.currentNode);return t}Tn(wj,"getTabbableCandidates");function Ug(e,t){const s=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(s?!r.checkVisibility({checkVisibilityCSS:!0}):vE(r,{upTo:t})))return r}Tn(Ug,"findVisible");function vE(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}Tn(vE,"isHidden");function jE(e){return e instanceof HTMLInputElement&&"select"in e}Tn(jE,"isSelectableInput");function Ar(e,{select:t=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&jE(e)&&t&&e.select()}}Tn(Ar,"focus");var vk=wE();function wE(){let e=[];return{add(t){const s=e[0];t!==s&&(s==null||s.pause()),e=Bg(e,t),e.unshift(t)},remove(t){var s;e=Bg(e,t),(s=e[0])==null||s.resume()}}}Tn(wE,"createFocusScopesStack");function Bg(e,t){const s=[...e],r=s.indexOf(t);return r!==-1&&s.splice(r,1),s}Tn(Bg,"arrayRemove");function yE(e){return e.filter(t=>t.tagName!=="A")}Tn(yE,"removeLinks");var YL=Object.defineProperty,yj=(e,t)=>YL(e,"name",{value:t,configurable:!0}),Tm=!1;function bE(){const[e,t]=d.useState(Tm);return d.useEffect(()=>{Tm||(Tm=!0,t(!0))},[]),e}yj(bE,"useIsHydrated");var kE=Fl[" useSyncExternalStore ".trim().toString()];function NE(){return()=>{}}yj(NE,"subscribe");function SE(){return kE(NE,()=>!0,()=>!1)}yj(SE,"useIsHydratedModern");var JL=typeof kE=="function"?SE:bE,QL=Object.defineProperty,ya=(e,t)=>QL(e,"name",{value:t,configurable:!0}),$m="rovingFocusGroup.onEntryFocus",XL={bubbles:!1,cancelable:!0},cf="RovingFocusGroup",[Wg,CE,ZL]=Vh(cf),[eF,uf]=Gs(cf,[ZL]),[tF,nF]=eF(cf),sF=d.forwardRef(ya(function(t,s){return n.jsx(Wg.Provider,{scope:t.__scopeRovingFocusGroup,children:n.jsx(Wg.Slot,{scope:t.__scopeRovingFocusGroup,children:n.jsx(rF,{...t,ref:s})})})},"RovingFocusGroup")),rF=d.forwardRef(ya(function(t,s){const{__scopeRovingFocusGroup:r,orientation:i,loop:a=!1,dir:l,currentTabStopId:o,defaultCurrentTabStopId:c,onCurrentTabStopIdChange:u,onEntryFocus:h,preventScrollOnEntryFocus:f=!1,...m}=t,p=d.useRef(null),g=bt(s,p),v=lf(l),[b,j]=Di({prop:o,defaultProp:c??null,onChange:u,caller:cf}),[x,w]=d.useState(!1),y=Rn(h),k=CE(r),N=d.useRef(!1),[S,C]=d.useState(0);return d.useEffect(()=>{const E=p.current;if(E)return E.addEventListener($m,y),()=>E.removeEventListener($m,y)},[y]),n.jsx(tF,{scope:r,orientation:i,dir:v,loop:a,currentTabStopId:b,onItemFocus:d.useCallback(E=>j(E),[j]),onItemShiftTab:d.useCallback(()=>w(!0),[]),onFocusableItemAdd:d.useCallback(()=>C(E=>E+1),[]),onFocusableItemRemove:d.useCallback(()=>C(E=>E-1),[]),children:n.jsx(vt.div,{tabIndex:x||S===0?-1:0,"data-orientation":i,...m,ref:g,style:{outline:"none",...t.style},onMouseDown:Me(t.onMouseDown,()=>{N.current=!0}),onFocus:Me(t.onFocus,E=>{const R=!N.current;if(E.target===E.currentTarget&&R&&!x){const I=new CustomEvent($m,XL);if(E.currentTarget.dispatchEvent(I),!I.defaultPrevented){const L=k().filter(D=>D.focusable),F=L.find(D=>D.active),T=L.find(D=>D.id===b),P=[F,T,...L].filter(Boolean).map(D=>D.ref.current);bj(P,f)}}N.current=!1}),onBlur:Me(t.onBlur,()=>w(!1))})})},"RovingFocusGroupImpl")),iF="RovingFocusGroupItem",aF=d.forwardRef(ya(function(t,s){const{__scopeRovingFocusGroup:r,focusable:i=!0,active:a=!1,tabStopId:l,children:o,...c}=t,u=_s(),h=l||u,f=nF(iF,r),m=f.currentTabStopId===h,p=CE(r),{onFocusableItemAdd:g,onFocusableItemRemove:v,currentTabStopId:b}=f,j=JL();return Vn(()=>{if(!(!j||!i))return g(),()=>v()},[j,i,g,v]),d.useEffect(()=>{if(!(j||!i))return g(),()=>v()},[j,i,g,v]),n.jsx(Wg.ItemSlot,{scope:r,id:h,focusable:i,active:a,children:n.jsx(vt.span,{tabIndex:m?0:-1,"data-orientation":f.orientation,...c,ref:s,onMouseDown:Me(t.onMouseDown,x=>{i?f.onItemFocus(h):x.preventDefault()}),onFocus:Me(t.onFocus,()=>f.onItemFocus(h)),onKeyDown:Me(t.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){f.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const w=AE(x,f.orientation,f.dir);if(w!==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(w==="last")k.reverse();else if(w==="prev"||w==="next"){w==="prev"&&k.reverse();const N=k.indexOf(x.currentTarget);k=f.loop?TE(k,N+1):k.slice(N+1)}setTimeout(()=>bj(k))}}),children:typeof o=="function"?o({isCurrentTabStop:m,hasTabStop:b!=null}):o})})},"RovingFocusGroupItem")),lF={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function EE(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}ya(EE,"getDirectionAwareKey");function AE(e,t,s){const r=EE(e.key,s);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return lF[r]}ya(AE,"getFocusIntent");function bj(e,t=!1){const s=document.activeElement;for(const r of e)if(r===s||(r.focus({preventScroll:t}),document.activeElement!==s))return}ya(bj,"focusFirst");function TE(e,t){return e.map((s,r)=>e[(t+r)%e.length])}ya(TE,"wrapArray");var $E=sF,RE=aF,oF=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Ma=new WeakMap,$u=new WeakMap,Ru={},Rm=0,IE=function(e){return e&&(e.host||IE(e.parentNode))},cF=function(e,t){return t.map(function(s){if(e.contains(s))return s;var r=IE(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})},uF=function(e,t,s,r){var i=cF(t,Array.isArray(e)?e:[e]);Ru[s]||(Ru[s]=new WeakMap);var a=Ru[s],l=[],o=new Set,c=new Set(i),u=function(f){!f||o.has(f)||(o.add(f),u(f.parentNode))};i.forEach(u);var h=function(f){!f||c.has(f)||Array.prototype.forEach.call(f.children,function(m){if(o.has(m))h(m);else try{var p=m.getAttribute(r),g=p!==null&&p!=="false",v=(Ma.get(m)||0)+1,b=(a.get(m)||0)+1;Ma.set(m,v),a.set(m,b),l.push(m),v===1&&g&&$u.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 h(t),o.clear(),Rm++,function(){l.forEach(function(f){var m=Ma.get(f)-1,p=a.get(f)-1;Ma.set(f,m),a.set(f,p),m||($u.has(f)||f.removeAttribute(r),$u.delete(f)),p||f.removeAttribute(s)}),Rm--,Rm||(Ma=new WeakMap,Ma=new WeakMap,$u=new WeakMap,Ru={})}},PE=function(e,t,s){s===void 0&&(s="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),i=oF(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll("[aria-live], script"))),uF(r,i,s,"aria-hidden")):function(){return null}},or=function(){return or=Object.assign||function(t){for(var s,r=1,i=arguments.length;r<i;r++){s=arguments[r];for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(t[a]=s[a])}return t},or.apply(this,arguments)};function ME(e,t){var s={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(s[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(s[r[i]]=e[r[i]]);return s}function dF(e,t,s){if(s||arguments.length===2)for(var r=0,i=t.length,a;r<i;r++)(a||!(r in t))&&(a||(a=Array.prototype.slice.call(t,0,r)),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))}var pd="right-scroll-bar-position",gd="width-before-scroll-bar",hF="with-scroll-bars-hidden",fF="--removed-body-scroll-bar-size";function Im(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function mF(e,t){var s=d.useState(function(){return{value:e,callback:t,facade:{get current(){return s.value},set current(r){var i=s.value;i!==r&&(s.value=r,s.callback(r,i))}}}})[0];return s.callback=t,s.facade}var pF=typeof window<"u"?d.useLayoutEffect:d.useEffect,jk=new WeakMap;function gF(e,t){var s=mF(null,function(r){return e.forEach(function(i){return Im(i,r)})});return pF(function(){var r=jk.get(s);if(r){var i=new Set(r),a=new Set(e),l=s.current;i.forEach(function(o){a.has(o)||Im(o,null)}),a.forEach(function(o){i.has(o)||Im(o,l)})}jk.set(s,e)},[e]),s}function xF(e){return e}function vF(e,t){t===void 0&&(t=xF);var s=[],r=!1,i={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(a){var l=t(a,r);return s.push(l),function(){s=s.filter(function(o){return o!==l})}},assignSyncMedium:function(a){for(r=!0;s.length;){var l=s;s=[],l.forEach(a)}s={push:function(o){return a(o)},filter:function(){return s}}},assignMedium:function(a){r=!0;var l=[];if(s.length){var o=s;s=[],o.forEach(a),l=s}var c=function(){var h=l;l=[],h.forEach(a)},u=function(){return Promise.resolve().then(c)};u(),s={push:function(h){l.push(h),u()},filter:function(h){return l=l.filter(h),s}}}};return i}function jF(e){e===void 0&&(e={});var t=vF(null);return t.options=or({async:!0,ssr:!1},e),t}var DE=function(e){var t=e.sideCar,s=ME(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return d.createElement(r,or({},s))};DE.isSideCarExport=!0;function wF(e,t){return e.useMedium(t),DE}var OE=jF(),Pm=function(){},df=d.forwardRef(function(e,t){var s=d.useRef(null),r=d.useState({onScrollCapture:Pm,onWheelCapture:Pm,onTouchMoveCapture:Pm}),i=r[0],a=r[1],l=e.forwardProps,o=e.children,c=e.className,u=e.removeScrollBar,h=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,w=e.gapMode,y=ME(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=m,N=gF([s,t]),S=or(or({},y),i);return d.createElement(d.Fragment,null,h&&d.createElement(k,{sideCar:OE,removeScrollBar:u,shards:f,noRelative:p,noIsolation:g,inert:v,setCallbacks:a,allowPinchZoom:!!b,lockRef:s,gapMode:w}),l?d.cloneElement(d.Children.only(o),or(or({},S),{ref:N})):d.createElement(x,or({},S,{className:c,ref:N}),o))});df.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};df.classNames={fullWidth:gd,zeroRight:pd};var yF=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function bF(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=yF();return t&&e.setAttribute("nonce",t),e}function kF(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function NF(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var SF=function(){var e=0,t=null;return{add:function(s){e==0&&(t=bF())&&(kF(t,s),NF(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},CF=function(){var e=SF();return function(t,s){d.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&s])}},LE=function(){var e=CF(),t=function(s){var r=s.styles,i=s.dynamic;return e(r,i),null};return t},EF={left:0,top:0,right:0,gap:0},Mm=function(e){return parseInt(e||"",10)||0},AF=function(e){var t=window.getComputedStyle(document.body),s=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],i=t[e==="padding"?"paddingRight":"marginRight"];return[Mm(s),Mm(r),Mm(i)]},TF=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return EF;var t=AF(e),s=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-s+t[2]-t[0])}},$F=LE(),fl="data-scroll-locked",RF=function(e,t,s,r){var i=e.left,a=e.top,l=e.right,o=e.gap;return s===void 0&&(s="margin"),`
41
+ .`.concat(hF,` {
42
+ overflow: hidden `).concat(r,`;
43
+ padding-right: `).concat(o,"px ").concat(r,`;
44
+ }
45
+ body[`).concat(fl,`] {
46
+ overflow: hidden `).concat(r,`;
47
+ overscroll-behavior: contain;
48
+ `).concat([t&&"position: relative ".concat(r,";"),s==="margin"&&`
49
+ padding-left: `.concat(i,`px;
50
+ padding-top: `).concat(a,`px;
51
+ padding-right: `).concat(l,`px;
52
+ margin-left:0;
53
+ margin-top:0;
54
+ margin-right: `).concat(o,"px ").concat(r,`;
55
+ `),s==="padding"&&"padding-right: ".concat(o,"px ").concat(r,";")].filter(Boolean).join(""),`
56
+ }
57
+
58
+ .`).concat(pd,` {
59
+ right: `).concat(o,"px ").concat(r,`;
60
+ }
61
+
62
+ .`).concat(gd,` {
63
+ margin-right: `).concat(o,"px ").concat(r,`;
64
+ }
65
+
66
+ .`).concat(pd," .").concat(pd,` {
67
+ right: 0 `).concat(r,`;
68
+ }
69
+
70
+ .`).concat(gd," .").concat(gd,` {
71
+ margin-right: 0 `).concat(r,`;
72
+ }
73
+
74
+ body[`).concat(fl,`] {
75
+ `).concat(fF,": ").concat(o,`px;
76
+ }
77
+ `)},wk=function(){var e=parseInt(document.body.getAttribute(fl)||"0",10);return isFinite(e)?e:0},IF=function(){d.useEffect(function(){return document.body.setAttribute(fl,(wk()+1).toString()),function(){var e=wk()-1;e<=0?document.body.removeAttribute(fl):document.body.setAttribute(fl,e.toString())}},[])},PF=function(e){var t=e.noRelative,s=e.noImportant,r=e.gapMode,i=r===void 0?"margin":r;IF();var a=d.useMemo(function(){return TF(i)},[i]);return d.createElement($F,{styles:RF(a,!t,i,s?"":"!important")})},Hg=!1;if(typeof window<"u")try{var Iu=Object.defineProperty({},"passive",{get:function(){return Hg=!0,!0}});window.addEventListener("test",Iu,Iu),window.removeEventListener("test",Iu,Iu)}catch{Hg=!1}var Da=Hg?{passive:!1}:!1,MF=function(e){return e.tagName==="TEXTAREA"},FE=function(e,t){if(!(e instanceof Element))return!1;var s=window.getComputedStyle(e);return s[t]!=="hidden"&&!(s.overflowY===s.overflowX&&!MF(e)&&s[t]==="visible")},DF=function(e){return FE(e,"overflowY")},OF=function(e){return FE(e,"overflowX")},yk=function(e,t){var s=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var i=_E(e,r);if(i){var a=zE(e,r),l=a[1],o=a[2];if(l>o)return!0}r=r.parentNode}while(r&&r!==s.body);return!1},LF=function(e){var t=e.scrollTop,s=e.scrollHeight,r=e.clientHeight;return[t,s,r]},FF=function(e){var t=e.scrollLeft,s=e.scrollWidth,r=e.clientWidth;return[t,s,r]},_E=function(e,t){return e==="v"?DF(t):OF(t)},zE=function(e,t){return e==="v"?LF(t):FF(t)},_F=function(e,t){return e==="h"&&t==="rtl"?-1:1},zF=function(e,t,s,r,i){var a=_F(e,window.getComputedStyle(t).direction),l=a*r,o=s.target,c=t.contains(o),u=!1,h=l>0,f=0,m=0;do{if(!o)break;var p=zE(e,o),g=p[0],v=p[1],b=p[2],j=v-b-a*g;(g||j)&&_E(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&&(t.contains(o)||t===o));return(h&&Math.abs(f)<1||!h&&Math.abs(m)<1)&&(u=!0),u},Pu=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},bk=function(e){return[e.deltaX,e.deltaY]},kk=function(e){return e&&"current"in e?e.current:e},UF=function(e,t){return e[0]===t[0]&&e[1]===t[1]},BF=function(e){return`
78
+ .block-interactivity-`.concat(e,` {pointer-events: none;}
79
+ .allow-interactivity-`).concat(e,` {pointer-events: all;}
80
+ `)},WF=0,Oa=[];function HF(e){var t=d.useRef([]),s=d.useRef([0,0]),r=d.useRef(),i=d.useState(WF++)[0],a=d.useState(LE)[0],l=d.useRef(e);d.useEffect(function(){l.current=e},[e]),d.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var v=dF([e.lockRef.current],(e.shards||[]).map(kk),!0).filter(Boolean);return v.forEach(function(b){return b.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),v.forEach(function(b){return b.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var o=d.useCallback(function(v,b){if("touches"in v&&v.touches.length===2||v.type==="wheel"&&v.ctrlKey)return!l.current.allowPinchZoom;var j=Pu(v),x=s.current,w="deltaX"in v?v.deltaX:x[0]-j[0],y="deltaY"in v?v.deltaY:x[1]-j[1],k,N=v.target,S=Math.abs(w)>Math.abs(y)?"h":"v";if("touches"in v&&S==="h"&&N.type==="range")return!1;var C=window.getSelection(),E=C&&C.anchorNode,R=E?E===N||E.contains(N):!1;if(R)return!1;var I=yk(S,N);if(!I)return!0;if(I?k=S:(k=S==="v"?"h":"v",I=yk(S,N)),!I)return!1;if(!r.current&&"changedTouches"in v&&(w||y)&&(r.current=k),!k)return!0;var L=r.current||k;return zF(L,b,v,L==="h"?w:y)},[]),c=d.useCallback(function(v){var b=v;if(!(!Oa.length||Oa[Oa.length-1]!==a)){var j="deltaY"in b?bk(b):Pu(b),x=t.current.filter(function(k){return k.name===b.type&&(k.target===b.target||b.target===k.shadowParent)&&UF(k.delta,j)})[0];if(x&&x.should){b.cancelable&&b.preventDefault();return}if(!x){var w=(l.current.shards||[]).map(kk).filter(Boolean).filter(function(k){return k.contains(b.target)}),y=w.length>0?o(b,w[0]):!l.current.noIsolation;y&&b.cancelable&&b.preventDefault()}}},[]),u=d.useCallback(function(v,b,j,x){var w={name:v,delta:b,target:j,should:x,shadowParent:KF(j)};t.current.push(w),setTimeout(function(){t.current=t.current.filter(function(y){return y!==w})},1)},[]),h=d.useCallback(function(v){s.current=Pu(v),r.current=void 0},[]),f=d.useCallback(function(v){u(v.type,bk(v),v.target,o(v,e.lockRef.current))},[]),m=d.useCallback(function(v){u(v.type,Pu(v),v.target,o(v,e.lockRef.current))},[]);d.useEffect(function(){return Oa.push(a),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:m}),document.addEventListener("wheel",c,Da),document.addEventListener("touchmove",c,Da),document.addEventListener("touchstart",h,Da),function(){Oa=Oa.filter(function(v){return v!==a}),document.removeEventListener("wheel",c,Da),document.removeEventListener("touchmove",c,Da),document.removeEventListener("touchstart",h,Da)}},[]);var p=e.removeScrollBar,g=e.inert;return d.createElement(d.Fragment,null,g?d.createElement(a,{styles:BF(i)}):null,p?d.createElement(PF,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function KF(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const VF=wF(OE,HF);var kj=d.forwardRef(function(e,t){return d.createElement(df,or({},e,{ref:t,sideCar:VF}))});kj.classNames=df.classNames;var GF=Object.defineProperty,ot=(e,t)=>GF(e,"name",{value:t,configurable:!0}),Kg=["Enter"," "],qF=["ArrowDown","PageUp","Home"],UE=["ArrowUp","PageDown","End"],YF=[...qF,...UE],JF={ltr:[...Kg,"ArrowRight"],rtl:[...Kg,"ArrowLeft"]},QF={ltr:["ArrowLeft"],rtl:["ArrowRight"]},hf="Menu",[jc,XF,ZF]=Vh(hf),[ba,BE]=Gs(hf,[ZF,sf,uf]),ff=sf(),WE=uf(),[HE,Li]=ba(hf),[e_,Wc]=ba(hf),t_=ot(e=>{const{__scopeMenu:t,open:s=!1,children:r,dir:i,onOpenChange:a,modal:l=!0}=e,o=ff(t),[c,u]=d.useState(null),h=d.useRef(!1),f=Rn(a),m=lf(i);return d.useEffect(()=>{const p=ot(()=>{h.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},"handleKeyDown"),g=ot(()=>h.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})}},[]),d.useEffect(()=>{if(!s)return;const p=ot(()=>f(!1),"handleBlur");return window.addEventListener("blur",p),()=>window.removeEventListener("blur",p)},[s,f]),n.jsx(cj,{...o,children:n.jsx(HE,{scope:t,open:s,onOpenChange:f,content:c,onContentChange:u,children:n.jsx(e_,{scope:t,onClose:d.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:h,dir:m,modal:l,children:r})})})},"Menu"),KE=d.forwardRef(ot(function(t,s){const{__scopeMenu:r,...i}=t,a=ff(r);return n.jsx(Z1,{...a,...i,ref:s})},"MenuAnchor")),VE="MenuPortal",[n_,GE]=ba(VE,{forceMount:void 0}),s_=ot(e=>{const{__scopeMenu:t,forceMount:s,children:r,container:i}=e,a=Li(VE,t);return n.jsx(n_,{scope:t,forceMount:s,children:n.jsx(wr,{present:s||a.open,children:n.jsx(Yh,{asChild:!0,container:i,children:r})})})},"MenuPortal"),zs="MenuContent",[r_,Nj]=ba(zs),i_=d.forwardRef(ot(function(t,s){const r=GE(zs,t.__scopeMenu),{forceMount:i=r.forceMount,...a}=t,l=Li(zs,t.__scopeMenu),o=Wc(zs,t.__scopeMenu);return n.jsx(jc.Provider,{scope:t.__scopeMenu,children:n.jsx(wr,{present:i||l.open,children:n.jsx(jc.Slot,{scope:t.__scopeMenu,children:o.modal?n.jsx(a_,{...a,ref:s}):n.jsx(l_,{...a,ref:s})})})})},"MenuContent")),a_=d.forwardRef(ot(function(t,s){const r=Li(zs,t.__scopeMenu),i=d.useRef(null),a=bt(s,i);return d.useEffect(()=>{const l=i.current;if(l)return PE(l)},[]),n.jsx(Sj,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:r.open,disableOutsideScroll:!0,onFocusOutside:Me(t.onFocusOutside,l=>l.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentModal")),l_=d.forwardRef(ot(function(t,s){const r=Li(zs,t.__scopeMenu);return n.jsx(Sj,{...t,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentNonModal")),o_=Si("MenuContent.ScrollLock"),Sj=d.forwardRef(ot(function(t,s){const{__scopeMenu:r,loop:i=!1,trapFocus:a,onOpenAutoFocus:l,onCloseAutoFocus:o,disableOutsidePointerEvents:c,onEntryFocus:u,onEscapeKeyDown:h,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:p,onDismiss:g,disableOutsideScroll:v,...b}=t,j=Li(zs,r),x=Wc(zs,r),w=ff(r),y=WE(r),k=XF(r),[N,S]=d.useState(null),C=d.useRef(null),E=bt(s,C,j.onContentChange),R=d.useRef(0),I=d.useRef(""),L=d.useRef(0),F=d.useRef(null),T=d.useRef("right"),M=d.useRef(0),P=v?kj:d.Fragment,D=v?{as:o_,allowPinchZoom:!0}:void 0,O=ot(B=>{var fe,Le;const Y=I.current+B,W=k().filter(Ie=>!Ie.disabled),q=document.activeElement,_=(fe=W.find(Ie=>Ie.ref.current===q))==null?void 0:fe.textValue,X=W.map(Ie=>Ie.textValue),Q=sA(X,Y,_),ee=(Le=W.find(Ie=>Ie.textValue===Q))==null?void 0:Le.ref.current;ot(function Ie(_e){I.current=_e,window.clearTimeout(R.current),_e!==""&&(R.current=window.setTimeout(()=>Ie(""),1e3))},"updateSearch")(Y),ee&&setTimeout(()=>ee.focus())},"handleTypeaheadSearch");d.useEffect(()=>()=>window.clearTimeout(R.current),[]),of();const H=d.useCallback(B=>{var W,q;return T.current===((W=F.current)==null?void 0:W.side)&&iA(B,(q=F.current)==null?void 0:q.area)},[]);return n.jsx(r_,{scope:r,searchRef:I,onItemEnter:d.useCallback(B=>{H(B)&&B.preventDefault()},[H]),onItemLeave:d.useCallback(B=>{var Y;H(B)||((Y=C.current)==null||Y.focus(),S(null))},[H]),onTriggerLeave:d.useCallback(B=>{H(B)&&B.preventDefault()},[H]),pointerGraceTimerRef:L,onPointerGraceIntentChange:d.useCallback(B=>{F.current=B},[]),children:n.jsx(P,{...D,children:n.jsx(pE,{asChild:!0,trapped:a,onMountAutoFocus:Me(l,B=>{var Y;B.preventDefault(),(Y=C.current)==null||Y.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:n.jsx(qh,{asChild:!0,disableOutsidePointerEvents:c,onEscapeKeyDown:h,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:p,onDismiss:g,children:n.jsx($E,{asChild:!0,...y,dir:x.dir,orientation:"vertical",loop:i,currentTabStopId:N,onCurrentTabStopIdChange:S,onEntryFocus:Me(u,B=>{x.isUsingKeyboardRef.current||B.preventDefault()}),preventScrollOnEntryFocus:!0,children:n.jsx(eE,{role:"menu","aria-orientation":"vertical","data-state":Cj(j.open),"data-radix-menu-content":"",dir:x.dir,...w,...b,ref:E,style:{outline:"none",...b.style},onKeyDown:Me(b.onKeyDown,B=>{const W=B.target.closest("[data-radix-menu-content]")===B.currentTarget,q=B.ctrlKey||B.altKey||B.metaKey,_=B.key.length===1;W&&(B.key==="Tab"&&B.preventDefault(),!q&&_&&O(B.key));const X=C.current;if(B.target!==X||!YF.includes(B.key))return;B.preventDefault();const ee=k().filter(fe=>!fe.disabled).map(fe=>fe.ref.current);UE.includes(B.key)&&ee.reverse(),tA(ee)}),onBlur:Me(t.onBlur,B=>{B.currentTarget.contains(B.target)||(window.clearTimeout(R.current),I.current="")}),onPointerMove:Me(t.onPointerMove,Sl(B=>{const Y=B.target,W=M.current!==B.clientX;if(B.currentTarget.contains(Y)&&W){const q=B.clientX>M.current?"right":"left";T.current=q,M.current=B.clientX}}))})})})})})})},"MenuContentImpl")),qE=d.forwardRef(ot(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(vt.div,{role:"group",...i,ref:s})},"MenuGroup")),c_=d.forwardRef(ot(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(vt.div,{...i,ref:s})},"MenuLabel")),Vg="MenuItem",Nk="menu.itemSelect",YE=d.forwardRef(ot(function(t,s){const{disabled:r=!1,onSelect:i,...a}=t,l=d.useRef(null),o=Wc(Vg,t.__scopeMenu),c=Nj(Vg,t.__scopeMenu),u=bt(s,l),h=d.useRef(!1),f=ot(()=>{const m=l.current;if(!r&&m){const p=new CustomEvent(Nk,{bubbles:!0,cancelable:!0});m.addEventListener(Nk,g=>i==null?void 0:i(g),{once:!0}),Gh(m,p),p.defaultPrevented?h.current=!1:o.onClose()}},"handleSelect");return n.jsx(JE,{...a,ref:u,disabled:r,onClick:Me(t.onClick,f),onPointerDown:m=>{var p;(p=t.onPointerDown)==null||p.call(t,m),h.current=!0},onPointerUp:Me(t.onPointerUp,m=>{var p;h.current||(p=m.currentTarget)==null||p.click()}),onKeyDown:Me(t.onKeyDown,m=>{r||m.target!==m.currentTarget||c.searchRef.current!==""&&m.key===" "||Kg.includes(m.key)&&(m.currentTarget.click(),m.preventDefault())})})},"MenuItem")),JE=d.forwardRef(ot(function(t,s){const{__scopeMenu:r,disabled:i=!1,textValue:a,...l}=t,o=Nj(Vg,r),c=WE(r),u=d.useRef(null),h=bt(s,u),[f,m]=d.useState(!1),[p,g]=d.useState("");return d.useEffect(()=>{const v=u.current;v&&g((v.textContent??"").trim())},[l.children]),n.jsx(jc.ItemSlot,{scope:r,disabled:i,textValue:a??p,children:n.jsx(RE,{asChild:!0,...c,focusable:!i,children:n.jsx(vt.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":i||void 0,"data-disabled":i?"":void 0,...l,ref:h,onPointerMove:Me(t.onPointerMove,Sl(v=>{i?o.onItemLeave(v):(o.onItemEnter(v),v.defaultPrevented||v.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Me(t.onPointerLeave,Sl(v=>o.onItemLeave(v))),onFocus:Me(t.onFocus,()=>m(!0)),onBlur:Me(t.onBlur,()=>m(!1))})})})},"MenuItemImpl")),u_="MenuRadioGroup",[d_,h_]=ba(u_,{value:void 0,onValueChange:ot(()=>{},"onValueChange")}),f_=d.forwardRef(ot(function(t,s){const{value:r,onValueChange:i,...a}=t,l=Rn(i);return n.jsx(d_,{scope:t.__scopeMenu,value:r,onValueChange:l,children:n.jsx(qE,{...a,ref:s})})},"MenuRadioGroup")),m_="MenuRadioItem",p_=d.forwardRef(ot(function(t,s){const{value:r,...i}=t,a=h_(m_,t.__scopeMenu),l=r===a.value;return n.jsx(x_,{scope:t.__scopeMenu,checked:l,children:n.jsx(YE,{role:"menuitemradio","aria-checked":l,...i,ref:s,"data-state":eA(l),onSelect:Me(i.onSelect,()=>{var o;return(o=a.onValueChange)==null?void 0:o.call(a,r)},{checkForDefaultPrevented:!1})})})},"MenuRadioItem")),g_="MenuItemIndicator",[x_,TZ]=ba(g_,{checked:!1}),v_=d.forwardRef(ot(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(vt.div,{role:"separator","aria-orientation":"horizontal",...i,ref:s})},"MenuSeparator")),QE="MenuSub",[j_,XE]=ba(QE),w_=ot(e=>{const{__scopeMenu:t,children:s,open:r=!1,onOpenChange:i}=e,a=Li(QE,t),l=ff(t),[o,c]=d.useState(null),[u,h]=d.useState(null),f=Rn(i);return d.useEffect(()=>(a.open===!1&&f(!1),()=>f(!1)),[a.open,f]),n.jsx(cj,{...l,children:n.jsx(HE,{scope:t,open:r,onOpenChange:f,content:u,onContentChange:h,children:n.jsx(j_,{scope:t,contentId:_s(),triggerId:_s(),trigger:o,onTriggerChange:c,children:s})})})},"MenuSub"),Mu="MenuSubTrigger",y_=d.forwardRef(ot(function(t,s){const r=Li(Mu,t.__scopeMenu),i=Wc(Mu,t.__scopeMenu),a=XE(Mu,t.__scopeMenu),l=Nj(Mu,t.__scopeMenu),o=d.useRef(null),{pointerGraceTimerRef:c,onPointerGraceIntentChange:u}=l,h={__scopeMenu:t.__scopeMenu},f=d.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);d.useEffect(()=>f,[f]),d.useEffect(()=>{const p=c.current;return()=>{window.clearTimeout(p),u(null)}},[c,u]);const m=bt(s,a.onTriggerChange);return n.jsx(KE,{asChild:!0,...h,children:n.jsx(JE,{id:a.triggerId,"aria-haspopup":"menu","aria-expanded":r.open,"aria-controls":r.open?a.contentId:void 0,"data-state":Cj(r.open),...t,ref:m,onClick:p=>{var g;(g=t.onClick)==null||g.call(t,p),!(t.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),r.open||r.onOpenChange(!0))},onPointerMove:Me(t.onPointerMove,Sl(p=>{l.onItemEnter(p),!p.defaultPrevented&&!t.disabled&&!r.open&&!o.current&&(l.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{r.onOpenChange(!0),f()},100))})),onPointerLeave:Me(t.onPointerLeave,Sl(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",w=x?-5:5,y=g[x?"left":"right"],k=g[x?"right":"left"];l.onPointerGraceIntentChange({area:[{x:p.clientX+w,y:p.clientY},{x:y,y:g.top},{x:k,y:g.top},{x:k,y:g.bottom},{x:y,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:Me(t.onKeyDown,p=>{var v;t.disabled||p.target!==p.currentTarget||l.searchRef.current!==""&&p.key===" "||JF[i.dir].includes(p.key)&&(r.onOpenChange(!0),(v=r.content)==null||v.focus(),p.preventDefault())})})})},"MenuSubTrigger")),b_="MenuSubContent",k_=d.forwardRef(ot(function(t,s){const r=GE(zs,t.__scopeMenu),{forceMount:i=r.forceMount,align:a="start",...l}=t,o=Li(zs,t.__scopeMenu),c=Wc(zs,t.__scopeMenu),u=XE(b_,t.__scopeMenu),h=d.useRef(null),f=bt(s,h);return n.jsx(jc.Provider,{scope:t.__scopeMenu,children:n.jsx(wr,{present:i||o.open,children:n.jsx(jc.Slot,{scope:t.__scopeMenu,children:n.jsx(Sj,{id:u.contentId,"aria-labelledby":u.triggerId,...l,ref:f,align:a,side:c.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:m=>{var p;c.isUsingKeyboardRef.current&&((p=h.current)==null||p.focus()),m.preventDefault()},onCloseAutoFocus:m=>m.preventDefault(),onFocusOutside:Me(t.onFocusOutside,m=>{m.target!==u.trigger&&o.onOpenChange(!1)}),onEscapeKeyDown:Me(t.onEscapeKeyDown,m=>{c.onClose(),m.preventDefault()}),onKeyDown:Me(t.onKeyDown,m=>{var v;const p=m.currentTarget.contains(m.target),g=QF[c.dir].includes(m.key);p&&g&&(o.onOpenChange(!1),(v=u.trigger)==null||v.focus(),m.preventDefault())})})})})})},"MenuSubContent"));function Cj(e){return e?"open":"closed"}ot(Cj,"getOpenState");function ZE(e){return e==="indeterminate"}ot(ZE,"isIndeterminate");function eA(e){return ZE(e)?"indeterminate":e?"checked":"unchecked"}ot(eA,"getCheckedState");function tA(e){const t=document.activeElement;for(const s of e)if(s===t||(s.focus(),document.activeElement!==t))return}ot(tA,"focusFirst");function nA(e,t){return e.map((s,r)=>e[(t+r)%e.length])}ot(nA,"wrapArray");function sA(e,t,s){const i=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,a=s?e.indexOf(s):-1;let l=nA(e,Math.max(a,0));i.length===1&&(l=l.filter(u=>u!==s));const c=l.find(u=>u.toLowerCase().startsWith(i.toLowerCase()));return c!==s?c:void 0}ot(sA,"getNextMatch");function rA(e,t){const{x:s,y:r}=e;let i=!1;for(let a=0,l=t.length-1;a<t.length;l=a++){const o=t[a],c=t[l],u=o.x,h=o.y,f=c.x,m=c.y;h>r!=m>r&&s<(f-u)*(r-h)/(m-h)+u&&(i=!i)}return i}ot(rA,"isPointInPolygon");function iA(e,t){if(!t)return!1;const s={x:e.clientX,y:e.clientY};return rA(s,t)}ot(iA,"isPointerInGraceArea");function Sl(e){return t=>t.pointerType==="mouse"?e(t):void 0}ot(Sl,"whenMouse");var N_=t_,S_=KE,C_=s_,E_=i_,A_=qE,T_=c_,$_=YE,R_=f_,I_=p_,P_=v_,M_=w_,D_=y_,O_=k_,L_=Object.defineProperty,cs=(e,t)=>L_(e,"name",{value:t,configurable:!0}),Ej="DropdownMenu",[F_,$Z]=Gs(Ej,[BE]),us=BE(),[__,aA]=F_(Ej),z_=cs(e=>{const{__scopeDropdownMenu:t,children:s,dir:r,open:i,defaultOpen:a,onOpenChange:l,modal:o=!0}=e,c=us(t),u=d.useRef(null),[h,f]=Di({prop:i,defaultProp:a??!1,onChange:l,caller:Ej});return n.jsx(__,{scope:t,triggerId:_s(),triggerRef:u,contentId:_s(),open:h,onOpenChange:f,onOpenToggle:d.useCallback(()=>f(m=>!m),[f]),modal:o,children:n.jsx(N_,{...c,open:h,onOpenChange:f,dir:r,modal:o,children:s})})},"DropdownMenu"),U_="DropdownMenuTrigger",B_=d.forwardRef(cs(function(t,s){const{__scopeDropdownMenu:r,disabled:i=!1,...a}=t,l=aA(U_,r),o=us(r),c=bt(s,l.triggerRef);return n.jsx(S_,{asChild:!0,...o,children:n.jsx(vt.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":i?"":void 0,disabled:i,...a,ref:c,onPointerDown:Me(t.onPointerDown,u=>{!i&&u.button===0&&u.ctrlKey===!1&&(l.onOpenToggle(),l.open||u.preventDefault())}),onKeyDown:Me(t.onKeyDown,u=>{i||(["Enter"," "].includes(u.key)&&l.onOpenToggle(),u.key==="ArrowDown"&&l.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(u.key)&&u.preventDefault())})})})},"DropdownMenuTrigger")),W_=cs(e=>{const{__scopeDropdownMenu:t,...s}=e,r=us(t);return n.jsx(C_,{...r,...s})},"DropdownMenuPortal"),H_="DropdownMenuContent",K_=d.forwardRef(cs(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=aA(H_,r),l=us(r),o=d.useRef(!1);return n.jsx(E_,{id:a.contentId,"aria-labelledby":a.triggerId,...l,...i,ref:s,onCloseAutoFocus:Me(t.onCloseAutoFocus,c=>{var u;o.current||(u=a.triggerRef.current)==null||u.focus(),o.current=!1,c.preventDefault()}),onInteractOutside:Me(t.onInteractOutside,c=>{const u=c.detail.originalEvent,h=u.button===0&&u.ctrlKey===!0,f=u.button===2||h;(!a.modal||f)&&(o.current=!0)}),style:{...t.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")),V_=d.forwardRef(cs(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=us(r);return n.jsx(A_,{...a,...i,ref:s})},"DropdownMenuGroup")),G_=d.forwardRef(cs(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=us(r);return n.jsx(T_,{...a,...i,ref:s})},"DropdownMenuLabel")),q_=d.forwardRef(cs(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=us(r);return n.jsx($_,{...a,...i,ref:s})},"DropdownMenuItem")),Y_=d.forwardRef(cs(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=us(r);return n.jsx(R_,{...a,...i,ref:s})},"DropdownMenuRadioGroup")),J_=d.forwardRef(cs(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=us(r);return n.jsx(I_,{...a,...i,ref:s})},"DropdownMenuRadioItem")),Q_=d.forwardRef(cs(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=us(r);return n.jsx(P_,{...a,...i,ref:s})},"DropdownMenuSeparator")),X_=cs(e=>{const{__scopeDropdownMenu:t,children:s,open:r,onOpenChange:i,defaultOpen:a}=e,l=us(t),[o,c]=Di({prop:r,defaultProp:a??!1,onChange:i,caller:"DropdownMenuSub"});return n.jsx(M_,{...l,open:o,onOpenChange:c,children:s})},"DropdownMenuSub"),Z_=d.forwardRef(cs(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=us(r);return n.jsx(D_,{...a,...i,ref:s})},"DropdownMenuSubTrigger")),e4=d.forwardRef(cs(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=us(r);return n.jsx(O_,{...a,...i,ref:s,style:{...t.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")),Hc=z_,Kc=B_,Gl=W_,Vc=K_,lA=V_,ma=G_,js=q_,t4=Y_,n4=J_,Dr=Q_,s4=X_,r4=Z_,i4=e4,a4=Object.defineProperty,ql=(e,t)=>a4(e,"name",{value:t,configurable:!0}),Aj="Tabs",[l4,RZ]=Gs(Aj,[uf]),oA=uf(),[o4,Tj]=l4(Aj),c4=d.forwardRef(ql(function(t,s){const{__scopeTabs:r,value:i,onValueChange:a,defaultValue:l,orientation:o="horizontal",dir:c,activationMode:u="automatic",...h}=t,f=lf(c),[m,p]=Di({prop:i,onChange:a,defaultProp:l??"",caller:Aj});return n.jsx(o4,{scope:r,baseId:_s(),value:m,onValueChange:p,orientation:o,dir:f,activationMode:u,children:n.jsx(vt.div,{dir:f,"data-orientation":o,...h,ref:s})})},"Tabs")),u4="TabsList",d4=d.forwardRef(ql(function(t,s){const{__scopeTabs:r,loop:i=!0,...a}=t,l=Tj(u4,r),o=oA(r);return n.jsx($E,{asChild:!0,...o,orientation:l.orientation,dir:l.dir,loop:i,children:n.jsx(vt.div,{role:"tablist","aria-orientation":l.orientation,...a,ref:s})})},"TabsList")),h4="TabsTrigger",f4=d.forwardRef(ql(function(t,s){const{__scopeTabs:r,value:i,disabled:a=!1,...l}=t,o=Tj(h4,r),c=oA(r),u=$j(o.baseId,i),h=Rj(o.baseId,i),f=i===o.value;return n.jsx(RE,{asChild:!0,...c,focusable:!a,active:f,children:n.jsx(vt.button,{type:"button",role:"tab","aria-selected":f,"aria-controls":h,"data-state":f?"active":"inactive","data-disabled":a?"":void 0,disabled:a,id:u,...l,ref:s,onMouseDown:Me(t.onMouseDown,m=>{!a&&m.button===0&&m.ctrlKey===!1?o.onValueChange(i):m.preventDefault()}),onKeyDown:Me(t.onKeyDown,m=>{a||m.target!==m.currentTarget||[" ","Enter"].includes(m.key)&&o.onValueChange(i)}),onFocus:Me(t.onFocus,()=>{const m=o.activationMode!=="manual";!f&&!a&&m&&o.onValueChange(i)})})})},"TabsTrigger")),m4="TabsContent",p4=d.forwardRef(ql(function(t,s){const{__scopeTabs:r,value:i,forceMount:a,children:l,...o}=t,c=Tj(m4,r),u=$j(c.baseId,i),h=Rj(c.baseId,i),f=i===c.value,m=d.useRef(f);return d.useEffect(()=>{const p=requestAnimationFrame(()=>m.current=!1);return()=>cancelAnimationFrame(p)},[]),n.jsx(wr,{present:a||f,children:({present:p})=>n.jsx(vt.div,{"data-state":f?"active":"inactive","data-orientation":c.orientation,role:"tabpanel","aria-labelledby":u,hidden:!p,id:h,tabIndex:0,...o,ref:s,style:{...t.style,animationDuration:m.current?"0s":void 0},children:p&&l})})},"TabsContent"));function $j(e,t){return`${e}-trigger-${t}`}ql($j,"makeTriggerId");function Rj(e,t){return`${e}-content-${t}`}ql(Rj,"makeContentId");var g4=c4,x4=d4,v4=f4,j4=p4;function nn(e,t,s){if(e==null)return"—";switch(t){case"currency":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?w4(r,s):String(e)}case"percent":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?`${Sk(r)}%`:String(e)}case"number":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?Number.isInteger(r)?Xt(r):Sk(r):String(e)}case"date":return y4(String(e));default:return typeof e=="string"?e:typeof e=="number"?Xt(e):typeof e=="boolean"?e?"yes":"no":JSON.stringify(e)??String(e)}}function w4(e,t){if(!(Math.abs(e)<1e3&&!Number.isInteger(e)))return ML(e,t);try{return new Intl.NumberFormat("en-US",{style:"currency",currency:t??"USD",maximumFractionDigits:2}).format(e)}catch{return e.toFixed(2)}}function y4(e){const t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);return t?Bc(t[0],{year:!0,compact:!0}):e}function Gg(e){const t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);return t?Bc(t[0],{compact:!0}):e}function Sk(e){return String(Math.round(e*100)/100)}function nh(e,t,s=4){if(!Number.isFinite(e)||!Number.isFinite(t))return[];if(e===t)return[e];const r=(t-e)/Math.max(1,s),i=10**Math.floor(Math.log10(r)),a=[1,2,2.5,5,10].map(o=>o*i).find(o=>o>=r)??i*10,l=[];for(let o=Math.ceil(e/a)*a;o<=t+a/1e3;o+=a)l.push(Math.round(o*1e6)/1e6);return l.filter(o=>o>=e&&o<=t)}function b4({props:e}){if(e.bars.length===0)return n.jsx("p",{className:"wb-empty",children:"No categories came back."});const t=e.bars.map(a=>a.value),s=Math.max(0,...t),r=Math.min(0,...t),i=s-r||1;return n.jsx("div",{className:"wb-bars",children:e.bars.map(a=>{const l=Math.abs(a.value)/i;return n.jsxs("div",{className:"wb-bar-row",children:[n.jsx("div",{className:"wb-bar-cat",title:a.category,children:a.category}),n.jsx("div",{className:"wb-bar-track",children:n.jsx("div",{className:"wb-bar-fill",style:{width:`${Math.max(1,l*100)}%`,background:a.value<0?"var(--chart-bar-negative)":"var(--chart-bar)"}})}),n.jsx("div",{className:"wb-bar-val",children:nn(a.value,e.unit,e.currency)})]},a.category)})})}const k4=/^(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 )/,N4=/^(… |\.\.\. |\(no change\)$|\)/;function S4(e){return e.replace(/\n$/,"").split(`
81
+ `).map(s=>({kind:C4(s),text:s}))}function C4(e){return e.startsWith("@@")?"hunk":k4.test(e)||N4.test(e)?"meta":e.startsWith("+")?"add":e.startsWith("-")?"del":"context"}function E4({text:e,marks:t}){const s=e.toLowerCase(),r=[];for(const l of t){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 n.jsx(n.Fragment,{children:e===""?" ":e});r.sort((l,o)=>l[0]-o[0]);const i=[];let a=0;for(const[l,o]of r)l<a||(l>a&&i.push(n.jsx("span",{children:e.slice(a,l)},`t${a}`)),i.push(n.jsx("mark",{className:"wb-diff-mark",children:e.slice(l,o)},`m${l}`)),a=o);return a<e.length&&i.push(n.jsx("span",{children:e.slice(a)},`t${a}`)),n.jsx(n.Fragment,{children:i})}function sh({text:e,limit:t,more:s,label:r="Diff",marks:i}){const a=S4(e),l=t===void 0?a:a.slice(0,t),o=a.length-l.length;return n.jsxs("div",{className:"wb-diff-wrap",children:[n.jsx("pre",{className:"wb-diff","aria-label":r,"data-testid":"diff",children:l.map((c,u)=>n.jsx("span",{className:"wb-diff-line","data-kind":c.kind,children:i&&i.length>0?n.jsx(E4,{text:c.text,marks:i}):c.text===""?" ":c.text},u))}),o>0?n.jsxs("p",{className:"wb-diff-more",children:[o," more line",o===1?"":"s",s?n.jsxs(n.Fragment,{children:[" · ",n.jsx("button",{type:"button",className:"wb-diff-open",onClick:s.onClick,children:s.label})]}):null]}):null]})}function A4({props:e}){return n.jsxs("div",{children:[e.title?n.jsx("h4",{className:"wb-doc-title mono",children:e.title}):null,e.metadata.length>0?n.jsx("dl",{className:"ui-kv wb-block",children:e.metadata.map(t=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:t.label}),n.jsx("dd",{children:nn(t.value,t.unit,null)})]},t.label))}):null,e.diff?n.jsx(sh,{text:e.diff,label:e.title?`Diff of ${e.title}`:"Diff"}):n.jsx("p",{className:"wb-empty",children:"This change came back with no diff."})]})}const dn="#/",Cl="#/needs",yi="#/chat",pt="#/agents",yt="#/activity",ln="#/settings",qr="#/files",T4="#/welcome";function xd(e){const t=/^#\/welcome(?:\?(.*))?$/.exec(e);if(!t)return null;try{return{step:new URLSearchParams(t[1]??"").get("step")}}catch{return{step:null}}}function Du(e,t={}){const s=new URLSearchParams;t.q&&s.set("q",t.q),t.origin&&s.set("origin",t.origin),t.family&&s.set("family",t.family);const r=s.toString();return`${qr}${e?`/${encodeURIComponent(e)}`:""}${r?`?${r}`:""}`}function $4(e){const t=/^#\/files(?:\/([^/?]+))?(?:\?(.*))?$/.exec(e);if(!t)return null;try{const s=new URLSearchParams(t[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")),{...t[1]?{artifactId:decodeURIComponent(t[1])}:{},filters:r}}catch{return null}}function st(e,t,s){return`#/chat/${encodeURIComponent(e)}${t?`/${encodeURIComponent(t)}`:""}`}function R4(e){if(cA(e))return null;const t=/^#\/chat\/([^/?]+)(?:\/([^/?]+))?(?:\?(.*))?$/.exec(e);if(!t)return null;try{const s=new URLSearchParams(t[3]??"").get("tab");return{agentId:decodeURIComponent(t[1]),...t[2]?{conversationId:decodeURIComponent(t[2])}:{},...s?{tab:s}:{}}}catch{return null}}function Yi(e,t){return`#/chat/g/${encodeURIComponent(e)}${t?`/${encodeURIComponent(t)}`:""}`}function cA(e){const t=/^#\/chat\/g\/([^/?]+)(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(!t)return null;try{return{groupId:decodeURIComponent(t[1]),...t[2]?{conversationId:decodeURIComponent(t[2])}:{}}}catch{return null}}function Et(e,t,s){return`${pt}/${encodeURIComponent(e)}${t?`/${t}${s?`/${s}`:""}`:""}`}function I4(e){const t=/^#\/agents\/([^/]+)(?:\/([a-z-]+)(?:\/([a-z-]+))?)?$/.exec(e);if(!t||t[1]===uA)return null;try{return{agentId:decodeURIComponent(t[1]),...t[2]?{tab:t[2]}:{},...t[3]?{section:t[3]}:{}}}catch{return null}}const uA="catalogue",Ck=`${pt}/${uA}`;function Ht(e){return e?`${Ck}/${encodeURIComponent(e)}`:Ck}function P4(e){return`${Ht(e)}?add=1`}function M4(e,t){const s=/^#\/agents\/catalogue\/([a-z0-9-]+)\?(?:.*&)?add=1(?:&|$)/.exec(e);return(s==null?void 0:s[1])===t}function D4(e){const t=/^#\/agents\/catalogue(?:\/([a-z0-9-]+))?(?:\?.*)?$/.exec(e);return t?t[1]?{name:t[1]}:{}:null}function wc(e){return`${yt}/conversations/${encodeURIComponent(e)}`}const O4="#/p";function xr(e,t,s){const r=`${O4}/${encodeURIComponent(e)}/${encodeURIComponent(t)}`;return s?`${r}/${encodeURIComponent(s)}`:r}function Ij(e){const t=/^#\/p\/([^/?]+)\/([^/?]+)(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(!t)return null;try{return{plugin:decodeURIComponent(t[1]),page:decodeURIComponent(t[2]),...t[3]?{item:decodeURIComponent(t[3])}:{}}}catch{return null}}const L4="p.";function vr(e,t=e,s){const r=s?new URLSearchParams(s).toString():"";return`${ln}/${encodeURIComponent(hA(e,t))}${r?`?${r}`:""}`}function F4(e,t){const s=dA(e);if(!s)return null;const r=t.filter(a=>a.plugin===s.plugin);if(r.length===0||r.some(a=>a.id===s.page))return null;const i=Pj(e);return vr(s.plugin,r[0].id,Object.keys(i).length>0?i:void 0)}function Pj(e){const t=e.indexOf("?");if(t===-1)return{};try{const s={};for(const[r,i]of new URLSearchParams(e.slice(t+1)))i!==""&&(s[r]=i);return s}catch{return{}}}function dA(e){const t=/^#\/settings\/p\.([^/?.]+)(?:\.([^/?.]+))?(?:\?.*)?$/.exec(e);if(!t)return null;const s=decodeURIComponent(t[1]);return{plugin:s,page:t[2]?decodeURIComponent(t[2]):s}}function hA(e,t){return`${L4}${e}${t===e?"":`.${t}`}`}function Pe(e){return e?`${ln}/${e}`:ln}function fA(e){return`${Pe("accounts")}?account=${encodeURIComponent(e)}`}function _4(e){const t=/^#\/settings\/accounts\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1]).get("account")||null}catch{return null}}function Mj(e,t,s){const r=new RegExp(`^#/settings/${t}\\?(.*)$`).exec(e);if(!r)return null;try{return new URLSearchParams(r[1]).get(s)||null}catch{return null}}function mA(e){return`${Pe("connections")}?connection=${encodeURIComponent(e)}`}function z4(e){return Mj(e,"connections","connection")}function U4(e){return Mj(e,"secrets","secret")}const Ek=`${Pe("secrets")}?add=1`;function B4(e){return Mj(e,"secrets","add")==="1"}function W4(e){return`${Pe("plugins")}?install=${encodeURIComponent(e)}`}const H4=`${Pe("plugins")}?tab=browse`;function K4(e){return`${Pe("proposals")}${e?`?plugin=${encodeURIComponent(e)}`:""}`}function V4(e){const t=/^#\/settings\/proposals\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1]).get("plugin")||null}catch{return null}}function Dj(e){const t=/^#\/settings\/plugins\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1])}catch{return null}}function G4(e){var s,r;const t=(r=(s=Dj(e))==null?void 0:s.get("install"))==null?void 0:r.trim();return t||null}function Ak(e){var s;const t=(s=Dj(e))==null?void 0:s.get("kind");return t==="plugins"||t==="agents"?t:"all"}function Tk(e){const t=Dj(e);return t!=null&&t.get("install")?"installed":(t==null?void 0:t.get("tab"))==="browse"?"browse":"installed"}const q4=[{route:dn,label:"Home"},{route:yi,label:"Chat"},{route:pt,label:"Agents"},{route:yt,label:"Activity"},{route:qr,label:"Files"},{route:ln,label:"Settings"}],Y4=[{id:"you",label:"You"},{id:"access",label:"Models and access"},{id:"running",label:"Running"},{id:"plugins",label:"Plugins"}],J4=[{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 Q4(e){var t;return((t=/^#\/settings\/([a-z0-9.-]+)/.exec(e))==null?void 0:t[1])??"you"}const qg="#/settings/notifications/recent",Yg=Pe("backup");function X4(e){const t=/^#\/conversations\/(.+)$/.exec(e);if(t)return wc(decodeURIComponent(t[1]));const s=/^#\/email(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(s)try{return xr("email","mail",s[1]?decodeURIComponent(s[1]):null)}catch{return xr("email","mail")}return e==="#/settings/email"?vr("email","settings"):{"#/overview":dn,"#/approvals":dn,"#/events":`${yt}/events`,"#/jobs":`${yt}/jobs`,"#/conversations":yt,"#/missions":`${pt}?tab=missions`,"#/offers":`${pt}?tab=offers`,"#/reminders":`${pt}?tab=reminders`,"#/providers":Pe("accounts"),"#/browser":Pe("computer"),"#/sentinels":Pe("watchers"),"#/settings/sentinels":Pe("watchers")}[e]??null}function pA(e){if(e===""||e==="#"||e===dn)return dn;if(e.startsWith(yi))return yi;if(e.startsWith(pt))return pt;if(e.startsWith(yt))return yt;if(e.startsWith(qr))return qr;if(e.startsWith(ln))return ln;const t=Ij(e);return t?xr(t.plugin,t.page):dn}const Z4="#/chat?group=new";function ez(e){const t=e.replace(/^#\/?/,"").split("?")[0].toLowerCase();if(t==="")return"home";const[s,r]=t.split("/");return!s||!/^[a-z0-9-]+$/.test(s)?null:(s==="settings"||s==="p")&&r&&/^[a-z0-9.-]+$/.test(r)?`${s}/${r}`:s}const Gc="front-desk",Oj=[{id:Gc,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."}],gA=new Set(Oj.map(e=>e.id)),$k=e=>gA.has(e);function Rk(e,t){const s=t.filter(r=>!gA.has(r));return[...Oj.filter(r=>e.has(r.id)).map(r=>r.id),...s.filter((r,i)=>s.indexOf(r)===i)]}function tz(e,t){return e.find(s=>(s.roles??[]).includes(t))}const Ik=["coding","finance","mail","research","calendar","files","memory"],nz={developer:"coding",coding:"coding",finance:"finance",credit:"finance",mail:"mail",email:"mail",research:"research",calendar:"calendar",files:"files",memory:"memory",[Gc]:"buddi"},sz=[["mail",["email"]],["finance",["finance"]],["coding",["developer"]],["research",["web","browser"]],["art",["image"]]];function rz(e){const t=new Set(e.map(s=>s.split(".")[0]??s));for(const[s,r]of sz)if(r.some(i=>t.has(i)))return s;return t.size>0&&[...t].every(s=>s==="memory")?"memory":null}let Jg=null;function iz(e){Jg=e}function qc(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=nz[s];if(r)return{key:r}}const t=rz(e.tools??[]);return t?{key:t}:Jg!==null&&e.id===Jg?{key:"buddi"}:{key:Ik[az(e.id)%Ik.length]??"coding"}}function Yc(e){return e.key==="own"?{"data-agent":"own",style:{"--agent-fill":e.hex}}:{"data-agent":e.key}}function az(e){let t=0;for(const s of e)t=(t*31+s.charCodeAt(0))%997;return t}const lz=["run.started","tool.called","tool.result","message.appended","awaiting-approval","run.finished","reaction","live","live.settle","live.snapshot","attention","closing","ping"];function oz(e){const s=e.replace(/\r\n/g,`
82
+ `).split(`
83
+
84
+ `),r=s.pop()??"",i=[];for(const a of s){let l=null,o="message";const c=[];for(const u of a.split(`
85
+ `)){if(u===""||u.startsWith(":"))continue;const h=u.indexOf(":"),f=h===-1?u:u.slice(0,h),m=h===-1?"":u.slice(h+1).replace(/^ /,"");f==="id"?l=m:f==="event"?o=m:f==="data"&&c.push(m)}c.length===0&&o==="message"||i.push({id:l,name:lz.includes(o)?o:"ping",data:cz(c.join(`
86
+ `))})}return{events:i,rest:r}}function cz(e){if(e==="")return{};try{const t=JSON.parse(e);return t!==null&&typeof t=="object"?t:{value:t}}catch{return{value:e}}}function mf(e){const t=e.fetchImpl??globalThis.fetch.bind(globalThis),s=e.wait??(u=>new Promise(h=>setTimeout(h,u))),r=e.retryMs??1500;let i=e.lastEventId??null,a=!1,l=!1,o=null;return(async()=>{var u,h,f,m,p;for(;!a;){(u=e.onStatus)==null||u.call(e,"connecting"),o=new AbortController;try{const g=await t(e.url,{credentials:"same-origin",signal:o.signal,headers:{Accept:"text/event-stream",...i===null?{}:{"Last-Event-ID":i}}});if(!g.ok||!g.body)throw new Error(`stream ${g.status}`);(h=e.onStatus)==null||h.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:w}=await v.read();if(x)break;j+=b.decode(w,{stream:!0});const{events:y,rest:k}=oz(j);j=k;for(const N of y)e.onEvent(N),N.id!==null&&(i=N.id);if(a)break}}catch{}if(a)break;l=!0,(m=e.onStatus)==null||m.call(e,"closed"),await s(r)}(p=e.onStatus)==null||p.call(e,"closed")})(),{close:()=>{a=!0,o==null||o.abort()},lastEventId:()=>i}}const Lj="0.1.0+c3e905f";function Fj(e,t=Lj){return typeof e=="string"&&e!==""&&typeof t=="string"&&t!==""&&e!==t}function uz(){var e;try{if((e=window.matchMedia)!=null&&e.call(window,"(display-mode: standalone)").matches)return!0}catch{}return window.navigator.standalone===!0}const dz=5*6e4,hz=6e4,fz=5e3,yc="buddi:stream-reconnected",xA="buddi.autoReloadedFor";function mz(){window.dispatchEvent(new Event(yc))}const Pk=["keydown","pointerdown","pointermove","wheel","touchstart","input"];let _j=Date.now(),Ou=0;const Mk=()=>{_j=Date.now()};function pz(){if(Ou===0){_j=Date.now();for(const e of Pk)window.addEventListener(e,Mk,{capture:!0,passive:!0})}return Ou+=1,()=>{if(Ou-=1,Ou===0)for(const e of Pk)window.removeEventListener(e,Mk,{capture:!0})}}function gz(e=Date.now()){return e-_j}function vA(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 xz(e){return e.hidden?!0:e.idleMs>=hz&&!e.busy}function vz(e){try{return window.sessionStorage.getItem(xA)===e}catch{return!1}}function jz(e){try{window.sessionStorage.setItem(xA,e)}catch{}}function wz(e){const t=d.useRef(e);t.current=e,d.useEffect(()=>{const s=()=>t.current();return window.addEventListener(yc,s),()=>window.removeEventListener(yc,s)},[])}function yz(e,t=()=>window.location.reload(),s=Lj){const r=Fj(e,s),i=d.useRef(t);i.current=t,d.useEffect(()=>pz(),[]),d.useEffect(()=>{if(!r||e===void 0||vz(e))return;let a=!1;const l=()=>{if(a)return;const c=document.visibilityState==="hidden";xz({hidden:c,idleMs:gz(),busy:vA()})&&(a=!0,jz(e),i.current())};l();const o=window.setInterval(l,fz);return document.addEventListener("visibilitychange",l),()=>{window.clearInterval(o),document.removeEventListener("visibilitychange",l)}},[r,e])}const bz=9e4,jA=5*6e4,kz=500,Nz=2e3,Sz=3e3,Cz="/_buddi/ready",ml={reload:()=>window.location.reload(),now:()=>Date.now()};let Ai=null,nl=null,Ao=null;const Qg=new Set;function rh(e){Ai=e;for(const t of Qg)t()}function Dk(){return Ai}function Ez(e){return Qg.add(e),()=>Qg.delete(e)}function Az(){const e=new Uint8Array(32);return crypto.getRandomValues(e),[...e].map(t=>t.toString(16).padStart(2,"0")).join("")}async function zj(e=Sz){const t=new AbortController,s=setTimeout(()=>t.abort(),e);try{const r=await fetch(`${Cz}?challenge=${Az()}`,{cache:"no-store",credentials:"omit",redirect:"error",signal:t.signal,headers:{Accept:"application/json"}});if(r.status!==200)return null;const i=await r.json().catch(()=>null);return typeof(i==null?void 0:i.boot)=="string"?i.boot:""}catch{return null}finally{clearTimeout(s)}}async function Tz(){const e=await zj();e&&(nl=e)}function $z(){let e=nl,t=!1,s=!1,r=kz,i;const a=async()=>{if(t)return;const l=await zj();if(!t){if(l===null)s=!0;else if(e!==null?l!==e:s){t=!0,ml.reload();return}else e===null&&l!==""&&(e=l);r=Math.min(Math.round(r*1.5),Nz),i=setTimeout(()=>void a(),r)}};return i=setTimeout(()=>void a(),r),()=>{t=!0,clearTimeout(i)}}function pf(e){if(Ai){if(e.kind==="detected")return;rh({...Ai,...e});return}rh({...e,startedAt:ml.now()}),Ao=$z()}function wA(e){Ai&&rh({...Ai,...e})}function El(){Ao==null||Ao(),Ao=null,rh(null)}async function gf(e,t){pf(e);try{return await t()}catch(s){if(th(s))return;throw El(),s}}function Rz(e){pf({kind:e.for==="stop"?"stop":"detected"})}async function Ok(){if(Ai)return;const e=await zj();if(nl===null){e&&(nl=e);return}if(!(!e||e===nl||Ai)){if(vA()){nl=e;return}pf({kind:"detected"})}}function Iz(e){const[t,s]=e;if(!t)return null;const r=`${t.name} ${t.version}`;return s?e.length===2?`${r} and ${s.name} ${s.version}`:`${r} and ${e.length-1} more`:r}const Pz="/api/chat/attention/stream";function yA(e,t){const s=(a,l)=>a.name.localeCompare(l.name),r=a=>e.filter(l=>l.anchor===a).sort(s),i=e.filter(a=>a.anchor!=="top"&&a.anchor!=="bottom").sort((a,l)=>a.id===t?l.id===t?0:-1:l.id===t?1:s(a,l));return{top:r("top"),middle:i,bottom:r("bottom")}}function bA(e,t){const s=yA(e,t);return[...s.top,...s.middle,...s.bottom]}function xf(e){if(!e)return null;const t=[];return e.approvals>0&&t.push(e.approvals===1?"one approval is waiting for you":`${e.approvals} approvals are waiting for you`),e.question&&t.push("asked you a question and is holding for the answer"),t.length===0?null:t.join(", and ")}function Mz(e){if(!e)return null;const t=e.approvals,s=t===1?"1 approval":`${t} approvals`;return t>0&&e.question?`${s} and a question`:t>0?`${s} waiting`:e.question?"Has a question":null}function Dz(e,t){return e&&(e.approvals>0||e.question)?"needs":t?"working":null}function Oz(e){return new Map(((e==null?void 0:e.agents)??[]).map(t=>[t.agentId,t]))}function Lz(){const[e,t]=d.useState(null);return d.useEffect(()=>{let s=!1;const r=()=>{je("/chat/attention").then(a=>{s||t(a)}).catch(()=>{})};r();const i=mf({url:Pz,onEvent:a=>a.name==="closing"?Rz(a.data):r(),onReconnect:mz});return()=>{s=!0,i.close()}},[]),Oz(e)}const Jc="maker";function Uj(e){return e.filter(t=>t.available&&!t.roles.includes(Jc))}function kA(e){return Uj(e).length>=2}function Fz(e){var t;return((t=e.find(s=>s.roles.includes(Jc)))==null?void 0:t.name)??"the agent maker"}const _z="{{default}}";function zz(e,t){return e.split(_z).join(t??"your assistant")}function Uz(e,t){return((e==null?void 0:e.starters)??[]).slice(0,3).map(s=>zz(s,t))}function Bz(e){var s,r;const t=(s=e==null?void 0:e.intro)==null?void 0:s.trim();return t&&t!==""?t:((r=e==null?void 0:e.description)==null?void 0:r.trim())??""}function Wz(e){const t=(e??"·").trim().split(/\s+/).filter(Boolean);return t.length===0?"·":t.length===1?t[0].slice(0,2).toUpperCase():(t[0][0]+t[1][0]).toUpperCase()}function NA(e){var r,i;const t=(r=e.heldBack)==null?void 0:r.message.trim();if(t!==void 0&&t!=="")return`${e.name??"This agent"} is held back. ${t}`;const s=(i=e.unavailableReason)==null?void 0:i.trim();return s&&s!==""?`${e.name??"This agent"} cannot run: ${s}`:`${e.name??"This agent"} cannot run: it has no model account yet.`}const Hz="Settings → Model accounts",Kz="Install it in Settings → Plugins";function Xg(e){return e!=null&&e.heldBack?{section:"plugins",label:Kz}:{section:"accounts",label:Hz}}const Vz={home:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M3.5 9.2 10 3.6l6.5 5.6"}),n.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,n.jsxs(n.Fragment,{children:[n.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"}),n.jsx("path",{d:"M7 8.3h6M7 11.3h3.6"})]})],agents:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"7.5",cy:"7",r:"2.8"}),n.jsx("path",{d:"M2.8 16.2a4.7 4.7 0 0 1 9.4 0"}),n.jsx("circle",{cx:"14",cy:"7.8",r:"2.2"}),n.jsx("path",{d:"M13.2 12.5a3.9 3.9 0 0 1 4.3 3.7"})]})],activity:[20,1.6,n.jsx("path",{d:"M2.8 10.5h3.4l2-5.2 3.4 9.8 2.2-4.6h3.4"})],settings:[24,1.9,n.jsxs(n.Fragment,{children:[n.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"}),n.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),20],files:[20,1.6,n.jsxs(n.Fragment,{children:[n.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"}),n.jsx("path",{d:"M12.7 2.8v3.8h3.8"}),n.jsx("path",{d:"M4.4 6.2v9.4a1.6 1.6 0 0 0 1.6 1.6h6.6"})]})],mail:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"3",y:"5",width:"14",height:"10.5",rx:"1.4"}),n.jsx("path",{d:"M3.4 6 10 11l6.6-5"})]})],money:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.6",y:"5.2",width:"14.8",height:"9.6",rx:"1.6"}),n.jsx("circle",{cx:"10",cy:"10",r:"2.2"}),n.jsx("path",{d:"M5.4 10h.5M14.1 10h.5"})]})],calendar:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"3",y:"4.4",width:"14",height:"12.2",rx:"1.6"}),n.jsx("path",{d:"M3 8.2h14M6.8 2.9v2.6M13.2 2.9v2.6"})]})],chart:[20,1.6,n.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,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M5.4 13.6V9a4.6 4.6 0 0 1 9.2 0v4.6l1.2 1.7H4.2Z"}),n.jsx("path",{d:"M8.4 17.1a1.8 1.8 0 0 0 3.2 0"})]})],plug:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M7.4 2.8v3.4M12.6 2.8v3.4"}),n.jsx("path",{d:"M5 6.2h10v3.1a5 5 0 0 1-10 0Z"}),n.jsx("path",{d:"M10 14.3v3"})]})],key:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"6.6",cy:"10",r:"3.2"}),n.jsx("path",{d:"M9.8 10h7.2M14.4 10v2.6M16.6 10v1.8"})]})],globe:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"10",cy:"10",r:"7.1"}),n.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,n.jsxs(n.Fragment,{children:[n.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"}),n.jsx("path",{d:"M14 7h1.6a.8.8 0 0 1 .8.8v7.2a1.4 1.4 0 0 1-1.4 1.4"}),n.jsx("path",{d:"M6.4 6.8h4.4M6.4 9.8h4.4M6.4 12.8h2.8"})]})],terminal:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"12.8",rx:"1.6"}),n.jsx("path",{d:"M6.2 8l2.6 2.4-2.6 2.4M10.6 12.8h3.4"})]})],person:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"10",cy:"7",r:"3.2"}),n.jsx("path",{d:"M4 16.6a6 6 0 0 1 12 0"})]})],briefcase:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.8",y:"6",width:"14.4",height:"10.2",rx:"1.6"}),n.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,n.jsxs(n.Fragment,{children:[n.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"}),n.jsx("circle",{cx:"10",cy:"8.2",r:"1.9"})]})],sun:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"10",cy:"10",r:"3.2"}),n.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,n.jsxs(n.Fragment,{children:[n.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"}),n.jsx("path",{d:"M7.6 3.2v13.6M10 7h2.6M10 9.8h2.6"})]})],bulb:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M7.2 13.2a5 5 0 1 1 5.6 0v1.6H7.2Z"}),n.jsx("path",{d:"M8 17.2h4"})]})],monitor:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"10",rx:"1.4"}),n.jsx("path",{d:"M7.4 16.8h5.2M10 13.6v3.2"})]})],lock:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"4",y:"8.6",width:"12",height:"8.6",rx:"2.2"}),n.jsx("path",{d:"M6.8 8.6V6.2a3.2 3.2 0 0 1 6.4 0v2.4"})]})],eye:[20,1.6,n.jsxs(n.Fragment,{children:[n.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"}),n.jsx("circle",{cx:"10",cy:"10",r:"2.4"})]})],archive:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"3.6",rx:"1"}),n.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,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"5.4",y:"5.4",width:"9.2",height:"9.2",rx:"1.4"}),n.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,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"7.4",cy:"7.4",r:"2.4"}),n.jsx("path",{d:"M7.4 2.8v1M2.8 7.4h1M4.2 4.2l.7.7M10.6 4.2l-.7.7"}),n.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,n.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,n.jsxs(n.Fragment,{children:[n.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"}),n.jsx("path",{d:"M7.2 14.6l-.8 2M10.4 14.6l-.8 2M13.6 14.6l-.8 2"})]})],drizzle:[20,1.6,n.jsxs(n.Fragment,{children:[n.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"}),n.jsx("path",{d:"M7 15.2v.3M10 16.4v.3M13 15.2v.3"})]})],snow:[20,1.6,n.jsxs(n.Fragment,{children:[n.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"}),n.jsx("path",{d:"M7.4 14.4v2.4M6.2 15.6h2.4M12.6 14.4v2.4M11.4 15.6h2.4"})]})],storm:[20,1.6,n.jsxs(n.Fragment,{children:[n.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"}),n.jsx("path",{d:"M10.8 13.2 9 15.6h2.4l-1.8 2.6"})]})],fog:[20,1.6,n.jsx("path",{d:"M3.6 7.2h12.8M5.2 10.2h9.6M3.6 13.2h12.8M6.4 16.2h7.2"})],wind:[20,1.6,n.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,n.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,n.jsxs(n.Fragment,{children:[n.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"}),n.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,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"10",cy:"10",r:"7.1"}),n.jsx("path",{d:"M10 5.8V10l2.8 1.8"})]})],dot:[20,1.6,n.jsx("circle",{cx:"10",cy:"10",r:"2.2"})],camera:[17,1.5,n.jsxs(n.Fragment,{children:[n.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"}),n.jsx("circle",{cx:"8.5",cy:"9.2",r:"2.4"})]})],clip:[17,1.5,n.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,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"6.3",y:"2.4",width:"4.4",height:"7.6",rx:"2.2"}),n.jsx("path",{d:"M3.9 8.4a4.6 4.6 0 0 0 9.2 0M8.5 13v2"})]})],speaker:[17,1.5,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M2.8 6.6h2.4l3.4-2.8v9.4l-3.4-2.8H2.8z"}),n.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,n.jsx("path",{d:"M8 13V3.5M3.8 7.7 8 3.5l4.2 4.2"})],check:[16,1.8,n.jsx("path",{d:"M3.5 8.4 6.6 11.4 12.5 4.8"})],close:[16,1.8,n.jsx("path",{d:"M4.5 4.5l7 7M11.5 4.5l-7 7"})],search:[16,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"7",cy:"7",r:"4.5"}),n.jsx("path",{d:"M10.5 10.5L14 14"})]})],alert:[16,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"8",cy:"8",r:"6.2"}),n.jsx("path",{d:"M8 4.8v3.8M8 11.2v.01"})]})],thought:[13,1.4,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M4.2 9.6a3.6 3.6 0 1 1 4.6 0v1.2H4.2z"}),n.jsx("path",{d:"M5.2 12.2h2.6"})]})],chevron:[11,1.5,n.jsx("path",{d:"M2.8 4.2 5.5 6.9l2.7-2.7"})],arrow:[13,1.5,n.jsx("path",{d:"M4.8 2.6 9 6.5l-4.2 3.9"})],copy:[16,1.5,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"5.6",y:"5.6",width:"7.6",height:"7.6",rx:"1.4"}),n.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,n.jsx("path",{d:"M5.2 3.4v9.2L12.6 8z"})],pause:[16,1.5,n.jsx("path",{d:"M5.6 3.6v8.8M10.4 3.6v8.8"})],stop:[16,1.5,n.jsx("rect",{x:"4.2",y:"4.2",width:"7.6",height:"7.6",rx:"1.2"})],download:[16,1.5,n.jsx("path",{d:"M8 2.8v7.2M4.9 7 8 10.1 11.1 7M3 12.8h10"})],out:[12,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"6",cy:"6",r:"4.4"}),n.jsx("path",{d:"M3.4 8.6 8.6 3.4"})]}),11],"chevron-left":[14,1.6,n.jsx("path",{d:"M9 2.5 4.5 7 9 11.5"})],"chevron-right":[14,1.6,n.jsx("path",{d:"M5 2.5 9.5 7 5 11.5"})],plus:[14,1.6,n.jsx("path",{d:"M7 2.5v9M2.5 7h9"})],grip:[16,0,n.jsxs("g",{fill:"currentColor",stroke:"none",children:[n.jsx("circle",{cx:"6",cy:"4",r:"1.2"}),n.jsx("circle",{cx:"10",cy:"4",r:"1.2"}),n.jsx("circle",{cx:"6",cy:"8",r:"1.2"}),n.jsx("circle",{cx:"10",cy:"8",r:"1.2"}),n.jsx("circle",{cx:"6",cy:"12",r:"1.2"}),n.jsx("circle",{cx:"10",cy:"12",r:"1.2"})]})],more:[16,0,n.jsxs("g",{fill:"currentColor",stroke:"none",children:[n.jsx("circle",{cx:"8",cy:"3.4",r:"1.35"}),n.jsx("circle",{cx:"8",cy:"8",r:"1.35"}),n.jsx("circle",{cx:"8",cy:"12.6",r:"1.35"})]})],drop:[28,1.8,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M14 4v13M8.5 11.5 14 17l5.5-5.5"}),n.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,n.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,n.jsx("path",{d:"M4 5.5 7 8.5l3-3"}),12],frame:[22,1.3,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.6",y:"3.6",width:"16.8",height:"14.8",rx:"2"}),n.jsx("path",{d:"M2.6 14.2 7.4 9.6l3.4 3 3-2.6 3.6 3.2"}),n.jsx("circle",{cx:"7.4",cy:"7.6",r:"1.2"})]})],"shape-timeseries":[16,1.4,n.jsx("path",{d:"M2 11.5 5.4 7.2l2.6 2.2L14 3.5"})],"shape-table":[16,1.4,n.jsx("path",{d:"M2.2 3.5h11.6v9H2.2zM2.2 6.6h11.6M6.6 6.6v5.9"})],"shape-bars":[16,1.4,n.jsx("path",{d:"M3 13V8.2M7 13V3.6M11 13V6.4M2 13.6h12"})],"shape-keyvalue":[16,1.4,n.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,n.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,n.jsx("path",{d:"M4 2.4h5l3 3v8.2H4zM9 2.4v3h3M6 9h4M6 11.2h3"})],"shape-diff":[16,1.4,n.jsx("path",{d:"M8 2.6v5M5.5 5.1h5M5.5 11.6h5M3 14h10"})],"shape-terminal":[16,1.4,n.jsx("path",{d:"M2.2 3.4h11.6v9.2H2.2zM4.6 6.4l2 1.6-2 1.6M8 10h3"})],"shape-image":[16,1.4,n.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,n.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,n.jsx("path",{d:"M2.2 4h11.6v8H2.2zM2.2 4.4 8 8.8l5.8-4.4"})],moon:[16,1.5,n.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"})],"shape-structured":[16,1.4,n.jsx("path",{d:"M4 2.6h8v10.8H4zM6.2 5.6h3.6M6.2 8h3.6M6.2 10.4h2.2"})]};function ce({name:e,size:t,className:s,...r}){const[i,a,l,o]=Vz[e],c=t??o??i;return n.jsx("svg",{className:s,width:c,height:c,viewBox:`0 0 ${i} ${i}`,"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:a,strokeLinecap:"round",strokeLinejoin:"round","data-icon":e,...r,children:l})}const SA="buddi.rosterCollapsed";function Gz(){try{return window.localStorage.getItem(SA)==="1"}catch{return!1}}function qz(e){try{window.localStorage.setItem(SA,e?"1":"0")}catch{}}function CA({agents:e,currentId:t,attention:s,onSelect:r,orientation:i="vertical",lastActivity:a,working:l,groups:o=[],currentGroupId:c=null,onSelectGroup:u,onNewGroup:h}){const f=[...e.top,...e.middle,...e.bottom],m=i==="vertical"?"right":"bottom",[p,g]=d.useState(Gz),v=b=>n.jsx(Yz,{agent:b,active:b.id===t,attention:s.get(b.id),side:m,onSelect:r,lastAt:(a==null?void 0:a.get(b.id))??null,working:(l==null?void 0:l.has(b.id))??!1},b.id);return n.jsxs("nav",{className:i==="vertical"?"wb-agent-rail":"wb-agent-strip","aria-label":"Agents","data-testid":"agent-rail","data-collapsed":i==="vertical"&&p?"true":void 0,children:[e.top.map(v),e.top.length>0&&e.middle.length>0?n.jsx("span",{className:"wb-agent-sep","data-testid":"agent-rail-sep","aria-hidden":"true"}):null,i==="vertical"&&!p&&e.middle.length>0?n.jsx("span",{className:"wb-roster-label",children:"Your team"}):null,n.jsxs("div",{className:"wb-agent-scroll",children:[e.middle.map(v),u&&kA(f)?n.jsxs("div",{className:"wb-groups","data-testid":"group-rail",children:[n.jsx("span",{className:"wb-agent-sep","aria-hidden":"true"}),n.jsxs("div",{className:"wb-groups-head",children:[n.jsx("span",{className:"wb-groups-label",children:"Groups"}),h?n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"New group",title:"A team of agents in one conversation",onClick:h,children:n.jsx(ce,{name:"plus"})}):null]}),o.map(b=>n.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:[n.jsx("span",{className:"wb-group-stack","aria-hidden":"true",children:b.members.slice(0,2).map(j=>{const x=f.find(w=>w.id===j);return n.jsx(vf,{className:"wb-group-chip",id:j,name:(x==null?void 0:x.name)??"?",face:x,initials:1},j)})}),n.jsxs("span",{className:"wb-face-text",children:[n.jsx("span",{className:"wb-face-name",children:b.name}),n.jsx("span",{className:"wb-face-status",children:b.members.map(j=>{var x;return((x=f.find(w=>w.id===j))==null?void 0:x.name)??j}).join(", ")})]})]},b.id))]}):u?n.jsxs("div",{className:"wb-groups","data-testid":"group-rail-hint",children:[n.jsx("span",{className:"wb-agent-sep","aria-hidden":"true"}),n.jsx("div",{className:"wb-groups-head",children:n.jsx("span",{className:"wb-groups-label",children:"Groups"})}),n.jsxs("p",{className:"wb-groups-hint",children:["A group needs two agents; ",n.jsx("a",{href:pt,children:"add a teammate"}),"."]})]}):null]}),e.bottom.map(v),i==="vertical"?n.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=>(qz(!b),!b)),children:n.jsx(ce,{name:p?"chevron-right":"chevron-left"})}):null]})}function Yz({agent:e,active:t,attention:s,side:r,onSelect:i,lastAt:a=null,working:l=!1}){const o=xf(s),c=Mz(s)??(e.available?a?PL(a):e.description:e.unavailableReason??"Cannot run right now"),u=Dz(s,l&&e.available),h=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,t?"current":null].filter(m=>m!==null&&m!=="").join(" — ");return n.jsxs(hc,{children:[n.jsx(fc,{asChild:!0,children:n.jsxs("button",{className:"wb-face",...Yc(qc(e)),"data-active":t?"true":void 0,"data-unavailable":e.available?void 0:"true","data-testid":`agent-face-${e.id}`,"aria-label":f,"aria-current":t?"true":void 0,disabled:!e.available,onClick:()=>e.available&&i(e.id),children:[n.jsxs("span",{className:"wb-face-frame",children:[n.jsx(vf,{className:"wb-face-mark",id:e.id,name:e.name,face:e}),u?n.jsx("span",{className:"wb-face-dot","data-state":u,"data-testid":`agent-dot-${e.id}`,"aria-hidden":"true"}):null]}),n.jsxs("span",{className:"wb-face-text","aria-hidden":"true",children:[n.jsx("span",{className:"wb-face-name",children:e.name}),n.jsx("span",{className:"wb-face-status","data-tone":o?"critical":void 0,children:c})]}),e.available?null:n.jsx("span",{className:"wb-face-out","aria-hidden":"true",children:n.jsx(ce,{name:"out"})})]})}),n.jsx(mc,{children:n.jsxs(pc,{className:"ui-tip",side:r,sideOffset:8,children:[n.jsx("span",{className:"ui-tip-title",children:e.name}),n.jsx("span",{className:"ui-tip-hint",children:e.available?`@${e.handle} · ${e.model}`:h}),o?n.jsx("span",{className:"ui-tip-alert",children:Jz(o)}):null]})})]})}function Jz(e){return`${e.slice(0,1).toUpperCase()}${e.slice(1)}.`}function Qz(e){let t=0;for(const s of e)t=(t*31+s.charCodeAt(0))%997;return t%6+1}const Xz="modulepreload",Zz=function(e,t){return new URL(e,t).href},Lk={},eU=function(t,s,r){let i=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"));i=Promise.allSettled(s.map(u=>{if(u=Zz(u,r),u in Lk)return;Lk[u]=!0;const h=u.endsWith(".css"),f=h?'[rel="stylesheet"]':"";if(!!r)for(let g=l.length-1;g>=0;g--){const v=l[g];if(v.href===u&&(!h||v.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${u}"]${f}`))return;const p=document.createElement("link");if(p.rel=h?"stylesheet":Xz,h||(p.as="script"),p.crossOrigin="",p.href=u,c&&p.setAttribute("nonce",c),document.head.appendChild(p),h)return new Promise((g,v)=>{p.addEventListener("load",g),p.addEventListener("error",()=>v(new Error(`Unable to preload CSS for ${u}`)))})}))}function a(l){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=l,window.dispatchEvent(o),!o.defaultPrevented)throw l}return i.then(l=>{for(const o of l||[])o.status==="rejected"&&a(o.reason);return t().catch(a)})},tU="buddi",nU=["core","coding","finance","garage","mail","maker","playground","research"],ka=e=>`./mascot/${e}.png`,sU=["core"],Zg=(e,t)=>sU.includes(e)?`./mascot/anim/${e}-${t}.json`:null,rU=["🙂","📚","🧭","🦊","🛟","🌿","🛠️","🎧"],iU="Introduce yourself by name and say one thing you can do today.",aU=["Hello","A brain","What I take on","Reach me","Your assistant"],Lu=(e,t=!1)=>e.length<2?e.join(""):`${e.slice(0,-1).join(", ")}${t&&e.length>2?", and ":" and "}${e[e.length-1]}`,Dm=e=>e.charAt(0).toUpperCase()+e.slice(1),lU=["No","One","Two","Three","Four","Five","Six","Seven","Eight"],zo=[{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."}],oU=["days","mail"],Fk=[{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"}],z={tagline:"Setting up, on this Mac.",taglineElsewhere:"Setting up, on this computer.",chapters:aU,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,t)=>`${e} · ${t}`,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 t=r=>r===1?"one model":`${r} models`;return`Free and private. I found ${[e.ollama!==void 0?`Ollama with ${t(e.ollama)}`:null,e.mlxh!==void 0?`mlxh with ${t(e.mlxh)}`:null].filter(Boolean).join(" and ")}; the first answer takes a minute.`},missing:"Nothing local answered; Ollama or mlxh, once installed, shows here."},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"},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,t,s)=>`Fetching ${Lu(e)} from withbuddi.com and reading them. ${t} of ${s}.`,ready:e=>`${Lu(e)} ${e.length>1?"are":"is"} in, read and ready.`,failed:(e,t)=>`${e} did not come: ${t}.`,installing:(e,t)=>`Installing, ${e} of ${t} ready`,installed:"Installed",answer:e=>e.length===0?"Just an assistant":Dm(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":Dm(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: ${Lu(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(`
87
+ `),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=>`${lU[e]??String(e)} ${e===1?"thing":"things"} still waiting.`,waitingBody:e=>`${Dm(Lu(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 Fu=null;const _k=new Map;function cU(){return Fu??(Fu=eU(()=>import("./lottie_light-Dj5SSwxs.js").then(e=>e.l),[],import.meta.url).then(e=>e.default)),Fu.catch(()=>{Fu=null}),Fu}function uU(e){let t=_k.get(e);return t||(t=fetch(e).then(s=>s.ok?s.text():null).catch(()=>null),_k.set(e,t)),t}const zk="(prefers-reduced-motion: reduce)";function EA(){const[e,t]=d.useState(()=>typeof window.matchMedia=="function"&&!window.matchMedia(zk).matches);return d.useEffect(()=>{var i;if(typeof window.matchMedia!="function")return;const s=window.matchMedia(zk),r=()=>t(!s.matches);return(i=s.addEventListener)==null||i.call(s,"change",r),()=>{var a;return(a=s.removeEventListener)==null?void 0:a.call(s,"change",r)}},[]),e}function Qc({role:e="core",state:t,size:s,still:r,className:i,onStillError:a}){const l=d.useRef(null),o=EA(),[c,u]=d.useState(!1),h=s==="xs"?null:Zg(e,t);return d.useEffect(()=>{if(u(!1),!o||!h)return;let f=!1,m=null;return Promise.all([cU(),uU(h)]).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,h]),n.jsx("span",{ref:l,className:i?`ui-blob ${i}`:"ui-blob","data-size":s,"data-playing":c?"true":void 0,"data-testid":"blob","data-state":t,"aria-hidden":"true",children:c?null:n.jsx("img",{src:r??ka(e),alt:"",onError:a})})}async function Uk(e){const t=new Image;t.src=e,await t.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(t,0,0,8,8),Array.from(r.getImageData(0,0,8,8).data)):null}function AA(e,t="core"){const s=EA(),r=e!==null&&dU(e,t),[i,a]=d.useState(!1);return d.useEffect(()=>{if(a(!1),!e||r||!s||!Zg(t,"idle"))return;let l=!1;return Promise.all([Uk(e),Uk(ka(t))]).then(([o,c])=>{if(l||!o||!c||o.length!==c.length)return;const u=o.reduce((h,f,m)=>h+Math.abs(f-c[m]),0)/o.length;a(u<12)}).catch(()=>{}),()=>{l=!0}},[e,r,s,t]),s&&Zg(t,"idle")!==null&&(r||i)}function dU(e,t){const s=ka(t);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 vf({className:e,id:t,name:s,face:r,tint:i,size:a,unavailable:l,initials:o=2}){const[c,u]=d.useState(null),h=r!=null&&r.picture&&r.picture!==c?r.picture:void 0,f=r==null?void 0:r.avatar,m=h?"image":f==null?void 0:f.kind,p=t?Yc(qc({id:t,accent:r==null?void 0:r.accent,roles:r==null?void 0:r.roles,tools:r==null?void 0:r.tools})):void 0;return n.jsx("span",{className:e,"data-tint":p?void 0:i,"data-size":a,"data-kind":m,"data-unavailable":l?"true":void 0,...p,"aria-hidden":"true",children:h?n.jsx("img",{src:h,alt:"",onError:()=>u(h)}):(f==null?void 0:f.kind)==="image"?n.jsx("img",{src:f.url,alt:""}):(f==null?void 0:f.kind)==="emoji"?f.value:Wz(s).slice(0,o)})}function Sn({id:e,name:t,size:s,unavailable:r,face:i}){return n.jsx(vf,{className:"ui-avatar",id:e,tint:Qz(e),name:t,size:s,unavailable:r,face:i})}function cn({agents:e,id:t,size:s}){const r=e.find(i=>i.id===t);return n.jsx(Sn,{id:t,name:(r==null?void 0:r.name)??t,size:s,unavailable:r?!r.available:!1,face:r})}const TA=d.createContext(null);function hU({picture:e,children:t}){return n.jsx(TA.Provider,{value:e??null,children:t})}function $A({size:e,anim:t}){const s=d.useContext(TA),[r,i]=d.useState(null),a=AA(t?s:null);return!s||s===r?null:n.jsx("span",{className:"ui-mascot","data-size":e,"data-testid":"mascot","aria-hidden":"true",children:t&&a?n.jsx(Qc,{state:t,still:s,className:"ui-mascot-blob",onStillError:()=>i(s)}):n.jsx("img",{src:s,alt:"",onError:()=>i(s)})})}const RA=d.createContext([]);function Ws({text:e,className:t}){const s=ex(e.replace(/\r\n/g,`
88
+ `).split(`
89
+ `));return n.jsx("div",{className:t??"wb-md",children:s.map((r,i)=>n.jsx(tx,{block:r},i))})}const Bk=/^(\s*)(```|~~~)\s*([\w+-]*)\s*$/,Wk=/^(#{1,6})\s+(.*?)\s*#*\s*$/,Hk=/^\s*([-*_])(\s*\1){2,}\s*$/,_u=/^(\s*)([-*+])\s+(.*)$/,vo=/^(\s*)(\d{1,9})[.)]\s+(.*)$/,zu=/^\s*>\s?(.*)$/,Om=/^\s*\|.*\|\s*$/,Kk=/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/;function ex(e){const t=[];let s=0;for(;s<e.length;){const r=e[s];if(r.trim()===""){s+=1;continue}const i=Bk.exec(r);if(i){const o=i[2],c=[];for(s+=1;s<e.length&&!new RegExp(`^\\s*${o}\\s*$`).test(e[s]);)c.push(e[s]),s+=1;s+=1,t.push({type:"code",lang:i[3]||null,text:c.join(`
90
+ `)});continue}const a=Wk.exec(r);if(a){t.push({type:"h",level:a[1].length,text:a[2]}),s+=1;continue}if(Hk.test(r)){t.push({type:"hr"}),s+=1;continue}if(zu.test(r)){const o=[];for(;s<e.length&&zu.test(e[s]);)o.push(zu.exec(e[s])[1]),s+=1;t.push({type:"quote",blocks:ex(o),raw:o.join(`
91
+ `)});continue}if(Om.test(r)&&s+1<e.length&&Kk.test(e[s+1])){const o=Fm(r),c=Fm(e[s+1]).map(h=>{const f=h.startsWith(":"),m=h.endsWith(":");return f&&m?"center":m?"right":f?"left":null});s+=2;const u=[];for(;s<e.length&&Om.test(e[s]);)u.push(Fm(e[s])),s+=1;t.push({type:"table",head:o,rows:u,align:c});continue}if(_u.test(r)||vo.test(r)){const o=vo.exec(r)??_u.exec(r),c=vo.test(r),u=o[1].length,h=c?Number(o[2]):1,f=[];for(;s<e.length;){const m=c?vo.exec(e[s]):_u.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()!==""&&Lm(g)>u,b=g.trim()===""&&s+1<e.length&&e[s+1].trim()!==""&&Lm(e[s+1])>u;if(!v&&!b)break;p.push(g.trim()===""?"":g.slice(Math.min(Lm(g),u+2))),s+=1}f.push(ex(p))}t.push({type:"list",ordered:c,start:h,items:f});continue}const l=[];for(;s<e.length;){const o=e[s];if(o.trim()===""||Bk.test(o)||Wk.test(o)||Hk.test(o)||zu.test(o)||_u.test(o)||vo.test(o)||Om.test(o)&&s+1<e.length&&Kk.test(e[s+1]))break;l.push(o.trim()),s+=1}l.length>0&&t.push({type:"p",text:l.join(`
92
+ `)})}return t}function Lm(e){return e.length-e.trimStart().length}function Fm(e){const t=e.trim().replace(/^\|/,"").replace(/\|$/,""),s=[];let r="";for(let i=0;i<t.length;i+=1){const a=t[i];if(a==="\\"&&t[i+1]==="|"){r+="|",i+=1;continue}if(a==="|"){s.push(r.trim()),r="";continue}r+=a}return s.push(r.trim()),s}function tx({block:e}){switch(e.type){case"p":return n.jsx("p",{children:Ds(e.text)});case"h":{const t=Math.min(6,Math.max(1,e.level)),s=`h${Math.min(t+2,6)}`;return n.jsx(s,{className:"wb-md-h","data-level":t,children:Ds(e.text)})}case"code":return n.jsxs("div",{className:"wb-md-code-frame",children:[n.jsxs("div",{className:"wb-md-code-head",children:[n.jsx("span",{className:"wb-md-code-lang",children:e.lang??"text"}),n.jsx(Vk,{text:e.text,what:"code",always:!0})]}),n.jsx("pre",{className:"wb-md-code","data-lang":e.lang??void 0,children:n.jsx("code",{children:e.text})})]});case"quote":return n.jsxs("div",{className:"wb-md-copyable",children:[n.jsx("blockquote",{children:e.blocks.map((t,s)=>n.jsx(tx,{block:t},s))}),n.jsx(Vk,{text:e.raw,what:"quote"})]});case"hr":return n.jsx("hr",{});case"list":{const t=e.items.map((s,r)=>n.jsx("li",{children:s.map((i,a)=>i.type==="p"?n.jsx(d.Fragment,{children:Ds(i.text)},a):n.jsx(tx,{block:i},a))},r));return e.ordered?n.jsx("ol",{start:e.start,children:t}):n.jsx("ul",{children:t})}case"table":return n.jsx("div",{className:"ui-table-wrap",children:n.jsxs("table",{className:"ui-table wb-md-table",children:[n.jsx("thead",{children:n.jsx("tr",{children:e.head.map((t,s)=>n.jsx("th",{style:e.align[s]?{textAlign:e.align[s]}:void 0,children:Ds(t)},s))})}),n.jsx("tbody",{children:e.rows.map((t,s)=>n.jsx("tr",{children:t.map((r,i)=>n.jsx("td",{style:e.align[i]?{textAlign:e.align[i]}:void 0,children:Ds(r)},i))},s))})]})})}}function Vk({text:e,what:t,always:s=!1}){const[r,i]=d.useState("idle"),a=()=>{var l;if(!((l=navigator.clipboard)!=null&&l.writeText)){i("failed");return}navigator.clipboard.writeText(e).then(()=>i("done"),()=>i("failed")),window.setTimeout(()=>i("idle"),1500)};return n.jsx("button",{type:"button",className:"wb-md-copy","data-state":r,"data-always":s||void 0,"aria-label":`Copy ${t}`,title:`Copy ${t}`,onClick:a,children:r==="done"?"Copied":r==="failed"?"Select to copy":n.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:[n.jsx("rect",{x:"4.5",y:"4.5",width:"6.5",height:"6.5",rx:"1.2"}),n.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 fU({handle:e}){const s=d.useContext(RA).find(r=>r.handle.toLowerCase()===e.toLowerCase());return s?n.jsxs(hc,{children:[n.jsx(fc,{asChild:!0,children:n.jsxs("a",{className:"wb-mention-link",href:st(s.id),children:["@",s.handle]})}),n.jsx(mc,{children:n.jsxs(pc,{className:"wb-agent-card",sideOffset:6,children:[n.jsx(Sn,{id:s.id,name:s.name,face:s,unavailable:!s.available}),n.jsxs("span",{className:"wb-agent-card-text",children:[n.jsx("span",{className:"wb-agent-card-name",children:s.name}),n.jsx("span",{className:"wb-agent-card-desc",children:s.description}),n.jsxs("span",{className:"wb-agent-card-meta",children:[s.model,s.available?"":" · unavailable"]})]})]})})]}):n.jsxs(n.Fragment,{children:["@",e]})}const mU=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 Ds(e){const t=[];let s=e,r=0;for(;s!=="";){const i=mU.exec(s);if(!i){t.push(...Gk(s,r));break}i.index>0&&t.push(...Gk(s.slice(0,i.index),r)),r+=100,i[2]!==void 0?t.push(n.jsx("code",{children:i[2]},r)):i[3]!==void 0?t.push(n.jsx("strong",{children:Ds(i[3])},r)):i[4]!==void 0?t.push(n.jsx("strong",{children:Ds(i[4])},r)):i[5]!==void 0?t.push(n.jsx("s",{children:Ds(i[5])},r)):i[6]!==void 0?t.push(n.jsx("em",{children:Ds(i[6])},r)):i[7]!==void 0?t.push(n.jsx("em",{children:Ds(i[7])},r)):i[8]!==void 0&&i[9]!==void 0?t.push(n.jsx("a",{href:i[9],target:"_blank",rel:"noopener noreferrer",children:Ds(i[8])},r)):i[10]!==void 0?t.push(n.jsx("a",{href:i[10],target:"_blank",rel:"noopener noreferrer",children:i[10]},r)):i[11]!==void 0&&t.push(n.jsx(fU,{handle:i[11]},r)),s=s.slice(i.index+i[0].length)}return t}function Gk(e,t){return e.split(`
93
+ `).flatMap((r,i)=>i===0?[r]:[n.jsx("br",{},`${t}-br-${i}`),r])}function pU({props:e}){return n.jsxs("div",{children:[e.title?n.jsx("h4",{className:"wb-doc-title",children:e.title}):null,e.metadata.length>0?n.jsx("dl",{className:"ui-kv wb-block",children:e.metadata.map(t=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:t.label}),n.jsx("dd",{children:nn(t.value,t.unit,null)})]},t.label))}):null,e.kind==="image"&&e.src?n.jsx("img",{src:e.src,alt:e.title??"Attached image",className:"wb-doc-image"}):e.kind==="pdf"&&e.src?n.jsx("object",{data:e.src,type:"application/pdf",className:"wb-doc-pdf",children:n.jsx("a",{href:e.src,children:"Open the PDF"})}):e.text?n.jsx("div",{className:"wb-doc",children:n.jsx(Ws,{text:e.text})}):n.jsx("p",{className:"wb-empty",children:"This document came back with no body."})]})}const gU=["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 Ne(e,t){if(t===""||t==="$")return e;let s=e;for(const r of t.split(".")){const i=/^([^[\]]*)((?:\[\d+\])*)$/.exec(r);if(!i)return;const[,a="",l=""]=i;if(a!==""){if(s===null||typeof s!="object")return;s=s[a]}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 Oe(e,t){if(t)return"const"in t?t.const:Ne(e,t.path)}function ss(e){if(typeof e=="number")return Number.isFinite(e)?e:null;if(typeof e=="string"&&e.trim()!==""){const t=Number(e);return Number.isFinite(t)?t:null}return null}function gt(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):null}function bi(e){return Array.isArray(e)?e:[]}function xU(e,t){const s=bi(Ne(e,t.points)).map(i=>{const a=ss(Ne(i,t.y)),l=gt(Ne(i,t.x));return a===null||l===null?null:{x:l,y:a}}).filter(i=>i!==null),r=(t.referenceLines??[]).map(i=>{const a=ss(Oe(e,i.value));return a===null?null:{value:a,label:i.label,tone:i.tone??"neutral"}}).filter(i=>i!==null);return{points:s,unit:t.unit??"number",currency:gt(Oe(e,t.currency)),label:gt(Oe(e,t.label)),referenceLines:r,mark:t.mark??null,shadeBelow:ss(Oe(e,t.shadeBelow)),events:vU(e,t)}}function vU(e,t){const s=t.events;if(!s)return[];const r=[],i=(a,l)=>{const o=gt(Ne(a,s.label));if(o===null)return;const c=gt(Ne(a,s.at))??l;c!==null&&r.push({at:c,label:o,amount:s.amount?ss(Ne(a,s.amount)):null})};if(s.parent){for(const a of bi(Ne(e,t.points))){const l=gt(Ne(a,t.x));for(const o of bi(Ne(a,s.parent)))i(o,l)}return r}for(const a of bi(Ne(e,s.path??t.points)))i(a,null);return r}function jU(e,t){const s=(t.columns??[]).map(o=>({key:o.key,label:o.label,type:o.type??"text"})),r=o=>(t.columns??[]).map(c=>{const u=Ne(o,c.key);let h=null;if(c.bar){const f=ss(Oe(o,c.bar.max))??ss(Oe(e,c.bar.max)),m=ss(u);if(f!==null&&f>0&&m!==null){const p=Math.max(0,Math.min(1,m/f));h={fraction:p,tone:yU(p*100,c.bar.thresholds)}}}return{value:u,type:c.type??"text",currency:gt(Oe(o,c.currency))??gt(Oe(e,c.currency)),bar:h}}),i=bi(Ne(e,t.rows)),a=t.groupBy?wU(i,t.groupBy,r):[{label:null,rows:i.map(r)}],l=(t.summary??[]).map(o=>({label:o.label,value:Oe(e,o.value),unit:o.unit??"text",currency:gt(Oe(e,o.currency)),tone:o.tone??"neutral"}));return{columns:s,groups:a,summary:l,empty:t.empty??"Nothing to show."}}function wU(e,t,s){const r=new Map;for(const i of e){const a=String(Ne(i,t.key)??""),l=r.get(a);l?l.push(i):r.set(a,[i])}return[...r.entries()].map(([i,a])=>{var l;return{label:((l=t.labels)==null?void 0:l[i])??i,rows:a.map(s)}})}function yU(e,t){var r;return!t||t.length===0?"neutral":((r=[...t].sort((i,a)=>a.atLeast-i.atLeast).find(i=>e>=i.atLeast))==null?void 0:r.tone)??"neutral"}function bU(e,t){return{bars:bi(Ne(e,t.bars)).map(r=>{const i=ss(Ne(r,t.value)),a=gt(Ne(r,t.category));return i===null||a===null?null:{category:a,value:i}}).filter(r=>r!==null),unit:t.unit??"number",currency:gt(Oe(e,t.currency))}}function kU(e,t){if(t.pairs)return{pairs:t.pairs.map(r=>({label:r.label,value:Oe(e,r.value),unit:r.unit??"text",currency:gt(Oe(e,r.currency)),tone:r.tone??"neutral"}))};const s=Ne(e,t.from??"$");return s===null||typeof s!="object"||Array.isArray(s)?{pairs:[]}:{pairs:Object.entries(s).map(([r,i])=>({label:kn(r),value:i,unit:"text",currency:null,tone:"neutral"}))}}const NU=new Set(["good","warning","critical","neutral","accent"]),SU=new Set(gU);function nx(e){return typeof e=="string"&&SU.has(e)?e:null}function Bj(e,t,s=""){const r=t.empty??"Nothing to show.",i=s.split(".")[0]??"";if(t.notice){const l=gt(Ne(e,t.notice.text));if(l!==null&&l.trim()!==""){const o=t.notice.link&&i!==""?{plugin:i,page:t.notice.link.page}:null;return{tiles:[{icon:nx(t.notice.icon??"bell"),value:"",label:l.trim(),lines:[],tone:"neutral",link:o}],notice:!0,empty:r}}}return{tiles:bi(Ne(e,t.items)).map(l=>{const o=gt(Ne(l,t.value))??"",c=gt(Ne(l,t.label))??"";if(o===""&&c==="")return null;const u=t.tone?gt(Ne(l,t.tone)):null;return{icon:nx(Oe(l,t.icon)),value:o,label:c,lines:(t.lines??[]).slice(0,2).map(h=>gt(Ne(l,h))).filter(h=>h!==null&&h.trim()!==""),tone:u!==null&&NU.has(u)?u:"neutral",link:null}}).filter(l=>l!==null),notice:!1,empty:r}}function CU(e,t){const s=gt(Oe(e,t.kind)),r=s==="image"||s==="pdf"?s:"text",i=t.src?gt(Ne(e,t.src)):null;return{kind:r,text:t.text?gt(Ne(e,t.text)):null,src:i&&PA(i)?i:null,title:gt(Oe(e,t.title)),metadata:(t.metadata??[]).map(a=>({label:a.label,value:Oe(e,a.value),unit:a.unit??"text"}))}}function EU(e,t){const s=t.diff?Ne(e,t.diff):void 0;return{diff:typeof s=="string"&&s.trim()!==""?s:null,title:gt(Oe(e,t.title)),metadata:(t.metadata??[]).map(r=>({label:r.label,value:Oe(e,r.value),unit:r.unit??"text"}))}}function AU(e,t){const s=t.output?Ne(e,t.output):void 0,r=l=>{const o=l?Ne(e,l):void 0;return typeof o=="number"&&Number.isInteger(o)?o:null},i=r(t.omittedBytes),a=t.elapsedMs?Ne(e,t.elapsedMs):void 0;return{command:gt(Oe(e,t.command)),output:typeof s=="string"?s:null,exitCode:r(t.exitCode),elapsedMs:typeof a=="number"&&Number.isFinite(a)&&a>=0?a:null,omittedBytes:i!==null&&i>0?i:null,metadata:(t.metadata??[]).map(l=>({label:l.label,value:Oe(e,l.value),unit:l.unit??"text"}))}}const TU=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function IA(e){const t=e!==null&&typeof e=="object"&&!Array.isArray(e)?e.artifactId??e.id:e;return typeof t=="string"&&TU.test(t)?t.toLowerCase():null}function $U(e,t){return{artifactId:t.src?IA(Ne(e,t.src)):null,title:gt(Oe(e,t.title)),caption:gt(Oe(e,t.caption)),...t.captionLabel?{captionLabel:gt(Oe(e,t.captionLabel))}:{}}}function qk(e){if(!PA(e))return null;let t;try{t=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(t);return s?{plugin:s[1],name:s[2]}:null}function RU(e,t){const s=t.src?gt(Ne(e,t.src)):null,r=t.port?Ne(e,t.port):null,i=t.awaiting?gt(Ne(e,t.awaiting)):null;return{target:s?qk(s):null,title:gt(Oe(e,t.title)),output:t.output?gt(Ne(e,t.output)):null,port:typeof r=="number"&&Number.isInteger(r)&&r>0&&r<=65535?r:null,awaiting:i?qk(i):null,reloadsItself:t.reloadsItself?Ne(e,t.reloadsItself)===!0:!1,ports:t.ports?IU(Ne(e,t.ports)):[]}}function IU(e){const t=bi(e).filter(s=>typeof s=="number"&&Number.isInteger(s)&&s>0&&s<=65535);return[...new Set(t)].sort((s,r)=>s-r)}function PA(e){return e.startsWith("/")&&!e.startsWith("//")}function kn(e){const t=e.replace(/[_-]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").trim().toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)}function MA(e,t){const s=e.map??{};switch(e.renderer){case"timeseries":return{renderer:"timeseries",props:xU(t,s)};case"table":return{renderer:"table",props:jU(t,s)};case"bars":return{renderer:"bars",props:bU(t,s)};case"keyvalue":return{renderer:"keyvalue",props:kU(t,s)};case"tiles":return{renderer:"tiles",props:Bj(t,s,e.tool)};case"document":return{renderer:"document",props:CU(t,s)};case"diff":return{renderer:"diff",props:EU(t,s)};case"terminal":return{renderer:"terminal",props:AU(t,s)};case"image":return{renderer:"image",props:$U(t,s)};case"preview":return{renderer:"preview",props:RU(t,s)};default:return{renderer:"structured",props:{value:t}}}}var PU=Object.defineProperty,Es=(e,t)=>PU(e,"name",{value:t,configurable:!0}),Wj="Dialog",[DA,IZ]=Gs(Wj),[MU,br]=DA(Wj),jf=Es(e=>{const{__scopeDialog:t,children:s,open:r,defaultOpen:i,onOpenChange:a,modal:l=!0}=e,o=d.useRef(null),c=d.useRef(null),[u,h]=Di({prop:r,defaultProp:i??!1,onChange:a,caller:Wj}),[f,m]=d.useState(0),[p,g]=d.useState(0);return n.jsx(MU,{scope:t,triggerRef:o,contentRef:c,contentId:_s(),titleId:_s(),descriptionId:_s(),titlePresent:f>0,descriptionPresent:p>0,setTitleCount:m,setDescriptionCount:g,open:u,onOpenChange:h,onOpenToggle:d.useCallback(()=>h(v=>!v),[h]),modal:l,children:s})},"Dialog"),DU="DialogTrigger",OU=d.forwardRef(Es(function(t,s){const{__scopeDialog:r,...i}=t,a=br(DU,r),l=bt(s,a.triggerRef);return n.jsx(vt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":kf(a.open),...i,ref:l,onClick:Me(t.onClick,a.onOpenToggle)})},"DialogTrigger")),OA="DialogPortal",[LU,LA]=DA(OA,{forceMount:void 0}),wf=Es(e=>{const{__scopeDialog:t,forceMount:s,children:r,container:i}=e,a=br(OA,t);return n.jsx(LU,{scope:t,forceMount:s,children:d.Children.map(r,l=>n.jsx(wr,{present:s||a.open,children:n.jsx(Yh,{asChild:!0,container:i,children:l})}))})},"DialogPortal"),sx="DialogOverlay",Hj=d.forwardRef(Es(function(t,s){const r=LA(sx,t.__scopeDialog),{forceMount:i=r.forceMount,...a}=t,l=br(sx,t.__scopeDialog);return l.modal?n.jsx(wr,{present:i||l.open,children:n.jsx(_U,{...a,ref:s})}):null},"DialogOverlay")),FU=Si("DialogOverlay.RemoveScroll"),_U=d.forwardRef(Es(function(t,s){const{__scopeDialog:r,...i}=t,a=br(sx,r),l=j1(),o=bt(s,l);return n.jsx(kj,{as:FU,allowPinchZoom:!0,shards:[a.contentRef],children:n.jsx(vt.div,{"data-state":kf(a.open),...i,ref:o,style:{pointerEvents:"auto",...i.style}})})},"DialogOverlayImpl")),bc="DialogContent",yf=d.forwardRef(Es(function(t,s){const r=LA(bc,t.__scopeDialog),{forceMount:i=r.forceMount,...a}=t,l=br(bc,t.__scopeDialog);return n.jsx(wr,{present:i||l.open,children:l.modal?n.jsx(zU,{...a,ref:s}):n.jsx(UU,{...a,ref:s})})},"DialogContent")),zU=d.forwardRef(Es(function(t,s){const r=br(bc,t.__scopeDialog),i=d.useRef(null),a=bt(s,r.contentRef,i);return d.useEffect(()=>{const l=i.current;if(l)return PE(l)},[]),n.jsx(FA,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:r.open,onCloseAutoFocus:Me(t.onCloseAutoFocus,l=>{var o;l.preventDefault(),(o=r.triggerRef.current)==null||o.focus()}),onPointerDownOutside:Me(t.onPointerDownOutside,l=>{const o=l.detail.originalEvent,c=o.button===0&&o.ctrlKey===!0;(o.button===2||c)&&l.preventDefault()}),onFocusOutside:Me(t.onFocusOutside,l=>l.preventDefault())})},"DialogContentModal")),UU=d.forwardRef(Es(function(t,s){const r=br(bc,t.__scopeDialog),i=d.useRef(!1),a=d.useRef(!1);return n.jsx(FA,{...t,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:l=>{var o,c;(o=t.onCloseAutoFocus)==null||o.call(t,l),l.defaultPrevented||(i.current||(c=r.triggerRef.current)==null||c.focus(),l.preventDefault()),i.current=!1,a.current=!1},onInteractOutside:l=>{var u,h;(u=t.onInteractOutside)==null||u.call(t,l),l.defaultPrevented||(i.current=!0,l.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const o=l.target;((h=r.triggerRef.current)==null?void 0:h.contains(o))&&l.preventDefault(),l.detail.originalEvent.type==="focusin"&&a.current&&l.preventDefault()}})},"DialogContentNonModal")),FA=d.forwardRef(Es(function(t,s){const{__scopeDialog:r,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:l,...o}=t,c=br(bc,r);return of(),n.jsx(n.Fragment,{children:n.jsx(pE,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:a,onUnmountAutoFocus:l,children:n.jsx(qh,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionPresent?c.descriptionId:void 0,"aria-labelledby":c.titlePresent?c.titleId:void 0,"data-state":kf(c.open),...o,ref:s,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})},"DialogContentImpl")),BU="DialogTitle",bf=d.forwardRef(Es(function(t,s){const{__scopeDialog:r,...i}=t,a=br(BU,r),{setTitleCount:l}=a;return Vn(()=>(l(o=>o+1),()=>l(o=>o-1)),[l]),n.jsx(vt.h2,{id:a.titleId,...i,ref:s})},"DialogTitle")),WU="DialogClose",Kj=d.forwardRef(Es(function(t,s){const{__scopeDialog:r,...i}=t,a=br(WU,r);return n.jsx(vt.button,{type:"button",...i,ref:s,onClick:Me(t.onClick,()=>a.onOpenChange(!1))})},"DialogClose"));function kf(e){return e?"open":"closed"}Es(kf,"getState");const HU=5;function de(e,t,s){const[r,i]=d.useState(void 0),[a,l]=d.useState(null),[o,c]=d.useState(!0),[u,h]=d.useState(0),[f,m]=d.useState(0),p=d.useRef(e);return p.current=e,d.useEffect(()=>{let g=!1;return c(!0),p.current().then(v=>{g||(i(v),l(null),m(0))}).catch(v=>{g||(l(v instanceof ve?v.message:String(v)),m(b=>b+1))}).finally(()=>{g||c(!1)}),()=>{g=!0}},[...t,u]),d.useEffect(()=>{if(!s||f>=HU)return;const g=window.setTimeout(()=>h(v=>v+1),s*2**f);return()=>window.clearTimeout(g)},[s,f,u]),{data:r,error:a,loading:o,reload:()=>{m(0),h(g=>g+1)}}}const _A={width:480,height:160,top:10,right:10,bottom:22,left:40},zA={width:1200,height:180,top:10,right:40,bottom:22,left:40};function KU({xs:e,series:t}){const s=zA,r=s.width-s.left-s.right,i=s.height-s.top-s.bottom,a=F=>F.filter(T=>T!==null&&Number.isFinite(T)),l=t.filter(F=>F.type!=="bar"),o=t.filter(F=>F.type==="bar"),c=l.flatMap(F=>a(F.values)),u=c.length>0?Math.min(...c):0,h=c.length>0?Math.max(...c):1;let f=u,m=h;if(f===m)f-=1,m+=1;else{const F=(m-f)*.08;f-=F,m+=F}const p=F=>ws(s.top+i-(F-f)/(m-f)*i),g=o.length>0&&o.every(F=>F.unit==="percent"),v=g?100:Math.max(1,...o.flatMap(F=>a(F.values))),b=F=>ws(s.top+i-Math.max(0,F)/v*i),j=e.length,x=j>0?r/j:r,w=F=>ws(s.left+x*(F+.5)),y=t.map(F=>{if(F.type==="bar")return"";let T="M";const M=[];return F.values.forEach((P,D)=>{if(P===null||!Number.isFinite(P)){T="M";return}M.push(`${T}${w(D)},${p(P)}`),T="L"}),M.join(" ")}),k=[],N=x*.6/Math.max(1,o.length),S=s.height-s.bottom;let C=0;t.forEach((F,T)=>{if(F.type!=="bar")return;const M=C++;F.values.forEach((P,D)=>{if(P===null||!Number.isFinite(P)||P<=0)return;const O=b(P);k.push({series:T,index:D,x:ws(w(D)-x*.3+N*M),y:O,width:ws(N),height:ws(S-O)})})});const E=c.length>0?nh(u,h,2).map(F=>({value:F,y:p(F)})):[],R=o.length===0?[]:(g?[0,50,100]:nh(0,v,2)).map(F=>({value:F,y:b(F),percent:g})),I=Math.max(1,Math.ceil(j/8)),L=e.flatMap((F,T)=>T%I===0?[{index:T,x:w(T)}]:[]);return{lines:y,bars:k,targetY:null,ticks:E,xLabels:L,rightTicks:R}}function VU({xs:e,series:t,type:s="line",target:r=null}){const i=_A,a=i.width-i.left-i.right,l=i.height-i.top-i.bottom,o=t.flatMap(w=>w.values.filter(y=>y!==null&&Number.isFinite(y)));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 w=(u-c)*.08;c-=w,u+=w}const h=w=>ws(i.top+l-(w-c)/(u-c)*l),f=e.length,m=f>0?a/f:a,p=w=>ws(s==="bar"?i.left+m*(w+.5):i.left+(f<=1?a/2:w/(f-1)*a)),g=s==="line"?t.map(w=>{let y="M";const k=[];return w.values.forEach((N,S)=>{if(N===null||!Number.isFinite(N)){y="M";return}k.push(`${y}${p(S)},${h(N)}`),y="L"}),k.join(" ")}):[],v=[];if(s==="bar"&&f>0){const w=m*.7,y=w/Math.max(1,t.length),k=h(0);t.forEach((N,S)=>{N.values.forEach((C,E)=>{if(C===null||!Number.isFinite(C))return;const R=h(C);v.push({series:S,index:E,x:ws(i.left+m*E+(m-w)/2+y*S),y:Math.min(R,k),width:ws(y),height:ws(Math.abs(k-R))})})})}const j=(o.length>0?nh(Math.min(...o),Math.max(...o),2):[]).map(w=>({value:w,y:h(w)})),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)?h(r):null,ticks:j,xLabels:x.map(w=>({index:w,x:p(w)}))}}function GU(e){const t=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 i=r===1?`on ${t(e.xs[0])}`:`from ${t(e.xs[0])} to ${t(e.xs[r-1])}`,a=e.series.map(o=>{const c=o.values.filter(h=>h!==null&&Number.isFinite(h));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"} ${i}. ${a.join("; ")}.${l}`}function qU({xs:e,series:t,type:s="line",target:r=null,label:i,formatX:a=o=>o,formatY:l=o=>String(o)}){const o=s==="mixed",c=o?zA:_A,u=o?KU({xs:e,series:t}):VU({xs:e,series:t,type:s,target:r}),h=GU({xs:e,series:t,target:r,...i?{label:i}:{},formatX:a,formatY:l});return n.jsxs("figure",{className:"ui-chart","data-type":s,children:[n.jsxs("svg",{viewBox:`0 0 ${c.width} ${c.height}`,"aria-hidden":"true",focusable:"false","data-testid":"chart-svg",children:[u.ticks.map(f=>n.jsxs("g",{children:[n.jsx("line",{className:"ui-chart-grid",x1:c.left,x2:c.width-c.right,y1:f.y,y2:f.y}),n.jsx("text",{x:c.left-6,y:f.y,textAnchor:"end",dominantBaseline:"middle",children:l(f.value)})]},f.value)),(u.rightTicks??[]).map(f=>n.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}`)),n.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=>n.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?n.jsx("path",{className:"ui-chart-line","data-series":m,d:f},m):null),u.targetY!==null?n.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=>n.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:a(e[f.index])},f.index))]}),n.jsx("figcaption",{className:"sr-only",children:h}),t.length>1?n.jsx("ul",{className:"ui-chart-legend","aria-hidden":"true",children:t.map((f,m)=>n.jsx("li",{"data-series":m,"data-type":o?f.type??"line":void 0,children:f.label},f.label))}):null]})}function ws(e){return Math.round(e*10)/10}const Vj="(max-width: 900px)";function Ns(e){const[t,s]=d.useState(()=>{try{return window.matchMedia(e).matches}catch{return!1}});return d.useEffect(()=>{var a;let r;try{r=window.matchMedia(e)}catch{return}const i=l=>s(l.matches);return(a=r.addEventListener)==null||a.call(r,"change",i),()=>{var l;return(l=r.removeEventListener)==null?void 0:l.call(r,"change",i)}},[e]),t}function Fi(...e){return e.filter(Boolean).join(" ")}function A({variant:e,size:t,className:s,type:r="button",...i}){return n.jsx("button",{type:r,className:Fi("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":t,...i})}function dt({variant:e,size:t,className:s,...r}){return n.jsx("a",{className:Fi("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":t,...r})}function YU({checked:e,onChange:t,label:s,disabled:r}){return n.jsxs("label",{className:"ui-switch","data-disabled":r?"true":void 0,children:[n.jsx("input",{type:"checkbox",role:"switch",checked:e,disabled:r,"aria-label":s,onChange:i=>t(i.target.checked)}),n.jsx("i",{"aria-hidden":"true"})]})}function ae({children:e,align:t,valign:s,className:r}){return n.jsx("div",{className:Fi("ui-toolbar",r),"data-align":t,"data-valign":s,children:e})}function ht(){return n.jsx("span",{className:"ui-toolbar-spacer"})}function oe({label:e,hint:t,inline:s,grow:r,wide:i,group:a,action:l,after:o,children:c}){const u=d.useId();return n.jsxs("div",{className:"ui-field","data-inline":s?"true":void 0,"data-grow":r?"true":void 0,"data-wide":i?"true":void 0,children:[l?n.jsxs("div",{className:"ui-field-row",children:[n.jsxs("label",{className:"ui-field-control",children:[n.jsx("span",{className:"ui-field-label",children:e}),c]}),l]}):a?n.jsxs("div",{className:"ui-field-control",role:"group","aria-labelledby":u,children:[n.jsx("span",{className:"ui-field-label",id:u,children:e}),c]}):n.jsxs("label",{className:"ui-field-control",children:[n.jsx("span",{className:"ui-field-label",children:e}),c]}),t?n.jsx("span",{className:"ui-field-hint",children:t}):null,o]})}function Hs({children:e,dense:t,columns:s}){return n.jsx("div",{className:"ui-formgrid","data-dense":t?"true":void 0,"data-columns":s===3?"3":void 0,children:e})}function we({tone:e,mono:t,dot:s,children:r,className:i,title:a}){return n.jsxs("span",{className:Fi("ui-pill",t&&"mono",i),"data-tone":e,title:a,children:[s?n.jsx("span",{className:"ui-pill-dot","aria-hidden":"true"}):null,r]})}function kc({children:e}){return n.jsx("span",{className:"ui-tag",children:e})}function Xc({state:e}){const t=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 n.jsx(we,{tone:t,children:e})}function V({tone:e,title:t,children:s,role:r,action:i}){return i?n.jsx("div",{className:"ui-notice","data-tone":e,role:r,children:n.jsxs("div",{className:"ui-notice-row",children:[n.jsxs("div",{className:"ui-notice-body",children:[t?n.jsx("div",{className:"ui-notice-title",children:t}):null,s]}),i]})}):n.jsxs("div",{className:"ui-notice","data-tone":e,role:r,children:[t?n.jsx("div",{className:"ui-notice-title",children:t}):null,s]})}function re({message:e}){return e?n.jsx(V,{tone:"critical",role:"alert",children:e}):null}function pe({mascot:e,warm:t,title:s,action:r,children:i}){return t||s?n.jsxs("div",{className:"ui-empty","data-warm":t?"true":void 0,children:[s?n.jsx("div",{className:"ui-empty-title",children:s}):null,n.jsx("div",{children:i}),r]}):e?n.jsxs("div",{className:"ui-empty","data-mascot":"true",children:[n.jsx($A,{size:"sm"}),n.jsx("p",{children:i})]}):n.jsx("p",{className:"ui-empty",children:i})}function In({icon:e,title:t,action:s,children:r}){return n.jsxs("div",{className:"ui-empty-state",children:[e?n.jsx("span",{className:"ui-empty-state-icon",children:typeof e=="string"?n.jsx(ce,{name:e}):e}):null,n.jsx("div",{className:"ui-empty-state-title",children:t}),r?n.jsx("p",{className:"ui-empty-state-line",children:r}):null,s?n.jsx("div",{className:"ui-empty-state-action",children:s}):null]})}function Gj({children:e}){return n.jsx("div",{className:"ui-page",children:e})}function Al({title:e,lede:t,actions:s,before:r}){return n.jsxs("header",{className:"ui-page-head",children:[n.jsxs("div",{className:"ui-page-head-row",children:[n.jsxs("h2",{className:"ui-page-title",children:[r,n.jsx("span",{children:e})]}),s?n.jsx("div",{className:"ui-page-actions",children:s}):null]}),t?n.jsx("p",{className:"ui-page-lede",children:t}):null]})}function On({embedded:e,title:t,lede:s,actions:r,children:i}){return e?n.jsxs("div",{className:"ui-stack","data-gap":"lg",children:[r?n.jsx("div",{className:"ui-toolbar","data-align":"end",children:r}):null,i]}):n.jsxs(Gj,{children:[n.jsx(Al,{title:t,lede:s,actions:r}),i]})}function ue({title:e,aside:t,actions:s,panel:r,flush:i,foot:a,children:l}){const o=e||t||s?n.jsxs("div",{className:"ui-section-head",children:[e?n.jsx("h3",{className:"ui-section-title",children:e}):n.jsx("span",{}),t||s?n.jsxs("div",{className:"ui-section-side",children:[t?n.jsx("span",{className:"ui-section-aside",children:t}):null,s?n.jsx("div",{className:"ui-section-actions",children:s}):null]}):null]}):null;return n.jsxs("section",{className:"ui-section","data-panel":r?"true":void 0,children:[o,r?n.jsxs("div",{className:"ui-panel","data-flush":i?"true":void 0,children:[l,a?n.jsx("div",{className:"ui-panel-foot",children:a}):null]}):n.jsxs(n.Fragment,{children:[l,a?n.jsx("div",{className:"ui-toolbar","data-align":"end",children:a}):null]})]})}function qe({title:e,tool:t,actions:s,flush:r,children:i}){return n.jsxs("section",{className:"ui-panel","data-flush":r?"true":void 0,children:[e||t||s?n.jsxs("header",{className:"ui-panel-head",children:[e?n.jsx("h3",{className:"ui-panel-title",children:e}):n.jsx("span",{}),t?n.jsx("span",{className:"ui-panel-tool",children:t}):null,s?n.jsx("div",{className:"ui-panel-actions",children:s}):null]}):null,i]})}function ds({tone:e,title:t,meta:s,actions:r,children:i,foot:a,onClick:l,label:o,as:c="div"}){const u=l?{"data-interactive":"true",tabIndex:0,"aria-label":o,onClick:l,onKeyDown:h=>{h.target!==h.currentTarget||h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),l())}}:{};return n.jsxs(c,{className:"ui-card","data-tone":e,...u,children:[t||s||r?n.jsxs("div",{className:"ui-card-head",children:[t?n.jsx("h3",{className:"ui-card-title",children:t}):null,s,r?n.jsx("div",{className:"ui-card-actions",children:r}):null]}):null,i,a?n.jsx("div",{className:"ui-card-foot",children:a}):null]})}function le({gap:e,divided:t,children:s}){return n.jsx("div",{className:"ui-stack","data-gap":e,"data-divided":t?"true":void 0,children:s})}function JU({children:e}){return n.jsx("div",{className:"ui-row",children:e})}function Nf({inline:e,children:t}){return n.jsx("div",{className:"ui-stats","data-inline":e?"true":void 0,children:t})}function ur({label:e,value:t,note:s,tone:r,size:i}){return n.jsxs("div",{className:"ui-stat",children:[n.jsx("div",{className:"ui-stat-k",children:e}),n.jsx("div",{className:"ui-stat-v","data-tone":r,"data-size":i,children:t}),s?n.jsx("div",{className:"ui-stat-n",children:s}):null]})}function Gt({items:e}){return n.jsx("dl",{className:"ui-kv",children:e.map((t,s)=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:t.label}),n.jsx("dd",{children:t.value})]},t.key??s))})}function kr({children:e}){return n.jsx("div",{className:"ui-table-wrap",children:n.jsx("table",{className:"ui-table",children:e})})}function UA({value:e,label:t}){const s=Math.max(0,Math.min(100,Math.round(Number.isFinite(e)?e:0)));return n.jsx("div",{className:"ui-progress",role:"progressbar","aria-label":t,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":s,"aria-valuetext":`${s}%`,children:n.jsx("div",{className:"ui-progress-fill",style:{inlineSize:`${s}%`}})})}function Pt({children:e,label:t}){return n.jsx("pre",{className:"ui-code","aria-label":t,children:e})}function Tt({summary:e,boxed:t,open:s,className:r,onToggle:i,children:a}){return n.jsxs("details",{className:Fi("ui-details",r),"data-boxed":t?"true":void 0,open:s,onToggle:i?l=>i(l.currentTarget.open):void 0,children:[n.jsx("summary",{children:e}),a]})}function Ye({title:e,onClose:t,size:s,foot:r,children:i}){return n.jsx(jf,{open:!0,onOpenChange:a=>{a||t()},children:n.jsxs(wf,{children:[n.jsx(Hj,{className:"ui-sheet-overlay"}),n.jsxs(yf,{className:"ui-sheet","data-size":s,"aria-describedby":void 0,children:[n.jsxs("div",{className:"ui-sheet-head",children:[n.jsx(bf,{className:"ui-sheet-title",children:e}),n.jsx(Kj,{asChild:!0,children:n.jsx(A,{size:"sm",children:"Close"})})]}),i,r?n.jsx("div",{className:"ui-sheet-foot",children:r}):null]})]})})}function Dt({title:e,onClose:t,foot:s,children:r}){return n.jsx(jf,{open:!0,onOpenChange:i=>{i||t()},children:n.jsxs(wf,{children:[n.jsx(Hj,{className:"ui-sheet-overlay","data-layer":"modal"}),n.jsxs(yf,{className:"ui-modal",role:"alertdialog","aria-describedby":void 0,children:[n.jsx(bf,{className:"ui-modal-title",children:e}),r,s?n.jsx("div",{className:"ui-modal-foot",children:s}):null]})]})})}function Ys({label:e,items:t,note:s,trigger:r,sheet:i,stacked:a}){const l=Ns(QU);return i&&l&&!r?n.jsx(XU,{label:e,items:t,title:i.title,sub:i.sub}):n.jsx(ZU,{label:e,items:t,note:s,trigger:r,stacked:a})}const QU="(max-width: 720px)";function XU({label:e,items:t,title:s,sub:r}){const[i,a]=d.useState(!1);return n.jsxs(jf,{open:i,onOpenChange:a,children:[n.jsx(OU,{asChild:!0,children:n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":e,title:e,onClick:l=>l.stopPropagation(),children:n.jsx(ce,{name:"more"})})}),n.jsxs(wf,{children:[n.jsx(Hj,{className:"ui-sheet-overlay",onClick:l=>l.stopPropagation()}),n.jsxs(yf,{className:"ui-action-sheet","aria-describedby":void 0,onClick:l=>l.stopPropagation(),children:[n.jsxs("div",{className:"ui-action-sheet-head",children:[n.jsx(bf,{className:"ui-action-sheet-title",children:s}),r?n.jsx("span",{className:"ui-action-sheet-sub",children:r}):null]}),n.jsx("div",{className:"ui-menu ui-action-sheet-list",role:"menu",children:t.map((l,o)=>l?l==="separator"?n.jsx("div",{className:"ui-menu-sep",role:"separator"},`sep-${o}`):"heading"in l?n.jsx("div",{className:"ui-menu-label",children:l.heading},`head-${o}`):n.jsxs("button",{type:"button",role:"menuitem",className:"ui-menu-item","data-tone":l.tone,onClick:()=>{a(!1),l.onSelect()},children:[n.jsx("span",{children:l.label}),l.hint?n.jsx("span",{className:"ui-menu-item-hint",children:l.hint}):null]},o):null)}),n.jsx(Kj,{asChild:!0,children:n.jsx(A,{className:"ui-action-sheet-cancel",children:"Cancel"})})]})]})]})}function ZU({label:e,items:t,note:s,trigger:r,stacked:i}){const a=o=>o.stopPropagation(),l=d.useRef(!1);return n.jsxs(Hc,{modal:!1,onOpenChange:o=>{o&&(l.current=!1)},children:[n.jsx(Kc,{asChild:!0,children:r??n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":e,title:e,onClick:a,children:n.jsx(ce,{name:"more"})})}),n.jsx(Gl,{children:n.jsxs(Vc,{className:"ui-menu","data-stacked":i?"true":void 0,align:"end",sideOffset:4,onClick:a,onKeyDown:a,onCloseAutoFocus:o=>{l.current&&o.preventDefault()},children:[s?n.jsx(ma,{className:"ui-menu-label",children:s}):null,t.map((o,c)=>o?o==="separator"?n.jsx(Dr,{className:"ui-menu-sep"},`sep-${c}`):"heading"in o?n.jsx(ma,{className:"ui-menu-label",children:o.heading},`head-${c}`):n.jsxs(js,{className:"ui-menu-item","data-tone":o.tone,onSelect:()=>{l.current=!0,o.onSelect()},children:[n.jsx("span",{children:o.label}),o.hint?n.jsx("span",{className:"ui-menu-item-hint",children:o.hint}):null]},c):null)]})})]})}function e3({title:e,actions:t,onClose:s,onCloseAutoFocus:r,onOpenAutoFocus:i,label:a,children:l}){return n.jsx(jf,{open:!0,modal:!1,onOpenChange:o=>{o||s()},children:n.jsx(wf,{children:n.jsxs(yf,{className:"ui-dock","aria-describedby":void 0,...a?{"aria-label":a}:{},onInteractOutside:o=>o.preventDefault(),...r?{onCloseAutoFocus:r}:{},...i?{onOpenAutoFocus:i}:{},children:[n.jsxs("div",{className:"ui-dock-head",children:[n.jsx(bf,{className:"ui-dock-title",children:e}),n.jsxs("div",{className:"ui-dock-actions",children:[t,n.jsx(Kj,{asChild:!0,children:n.jsx(A,{size:"sm",variant:"ghost",children:"Close"})})]})]}),n.jsx("div",{className:"ui-dock-body",children:l})]})})})}function Zc({level:e,label:t,children:s}){return n.jsx("nav",{className:"ui-tabs","data-level":e,"aria-label":t,children:s})}function Tl({href:e,active:t,count:s,onClick:r,children:i}){return n.jsxs("a",{className:"ui-tab",href:e,"aria-current":t?"page":void 0,onClick:r,children:[i,s?n.jsx("span",{className:"ui-count",children:s}):null]})}function qt({label:e,options:t,value:s,onChange:r}){return n.jsx("div",{className:"ui-segment",role:"radiogroup","aria-label":e,children:t.map(i=>n.jsx("button",{type:"button",role:"radio",className:"ui-tab","aria-checked":i.value===s,onClick:()=>r(i.value),children:i.label},i.value))})}function rt({children:e}){return n.jsx("div",{className:"ui-list",children:e})}function et({href:e,onClick:t,lead:s,title:r,sub:i,side:a,dimmed:l,label:o}){const c=n.jsxs(n.Fragment,{children:[s,n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title",children:r}),i?n.jsx("span",{className:"ui-list-sub",children:i}):null]}),a?n.jsx("span",{className:"ui-list-side",children:a}):null]}),u=l?"true":void 0;return e?n.jsx("a",{className:"ui-list-row","data-dimmed":u,href:e,onClick:t?h=>{h.preventDefault(),t()}:void 0,children:c}):t?n.jsx("div",{className:"ui-list-row","data-interactive":"true","data-dimmed":u,tabIndex:0,"aria-label":o,onClick:t,onKeyDown:h=>{h.target!==h.currentTarget||h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),t())},children:c}):n.jsx("div",{className:"ui-list-row","data-dimmed":u,children:c})}function BA({href:e,onClick:t,current:s,lead:r,title:i,meta:a,sub:l,snippet:o,side:c}){return n.jsxs("a",{className:"ui-pick",href:e,"aria-current":s?"true":void 0,onClick:t?u=>{u.preventDefault(),t()}:void 0,children:[r?n.jsx("span",{className:"ui-pick-lead",children:r}):null,n.jsxs("span",{className:"ui-pick-main",children:[n.jsxs("span",{className:"ui-pick-top",children:[n.jsx("span",{className:"ui-pick-title",children:i}),a?n.jsx("span",{className:"ui-pick-meta",children:a}):null]}),l||c?n.jsxs("span",{className:"ui-pick-line",children:[l?n.jsx("span",{className:"ui-pick-sub",children:l}):null,c?n.jsx("span",{className:"ui-pick-side",children:c}):null]}):null,o?n.jsx("span",{className:"ui-pick-snippet",children:o}):null]})]})}function WA({list:e,detail:t,empty:s,label:r,className:i}){return n.jsxs("div",{className:Fi("ui-split",i),"data-open":t?"true":void 0,children:[n.jsx("section",{className:"ui-split-list","aria-label":r,children:e}),n.jsx("section",{className:"ui-split-detail","data-empty":t?void 0:"true",children:t??n.jsx("p",{className:"ui-empty ui-split-empty",children:s})})]})}function ih({children:e,onRemove:t,label:s,disabled:r}){return n.jsxs("span",{className:"ui-chip",children:[e,n.jsx("button",{type:"button",className:"ui-chip-x","aria-label":`Remove ${s}`,onClick:t,disabled:r,children:"×"})]})}const t3=8;function n3({label:e,options:t,value:s,onChange:r,max:i,disabled:a,id:l}){const[o,c]=d.useState(!1),[u,h]=d.useState(""),[f,m]=d.useState(0),p=d.useRef(null),g=d.useRef(null),v=d.useRef(null),b=d.useRef(null),j=d.useId(),x=T=>{var M;return((M=t.find(P=>P.value===T))==null?void 0:M.label)??T},w=i!==void 0&&s.length>=i,y=t.filter(T=>!s.includes(T.value)),k=t.length>t3,N=u.trim().toLowerCase(),S=N===""?y:y.filter(T=>T.label.toLowerCase().includes(N)),C=Math.min(f,Math.max(0,S.length-1)),E=T=>{var M;c(!1),h(""),m(0),T&&((M=g.current)==null||M.focus())};d.useEffect(()=>{var M;if(!o)return;(M=k?v.current:b.current)==null||M.focus();const T=P=>{p.current&&!p.current.contains(P.target)&&E(!1)};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[o,k]);const R=T=>{const M=[...s,T];r(M),h(""),m(0);const P=i!==void 0&&M.length>=i;(P||M.length>=t.length)&&E(!P)},I=T=>{if(T.key==="Escape")T.preventDefault(),E(!0);else if(T.key==="ArrowDown")T.preventDefault(),m(S.length===0?0:(C+1)%S.length);else if(T.key==="ArrowUp")T.preventDefault(),m(S.length===0?0:(C-1+S.length)%S.length);else if(T.key==="Enter"){T.preventDefault();const M=S[C];M&&R(M.value)}else T.key==="Backspace"&&u===""&&s.length>0&&(T.preventDefault(),r(s.slice(0,-1)))},L=T=>`${j}-${T}`,F=o&&S.length>0?L(C):void 0;return n.jsxs("div",{className:"ui-chippicker",ref:p,id:l,children:[s.map(T=>n.jsx(ih,{label:x(T),disabled:a,onRemove:()=>r(s.filter(M=>M!==T)),children:x(T)},T)),n.jsxs("div",{className:"ui-chippicker-add",children:[n.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:a||w||y.length===0,onClick:()=>o?E(!1):c(!0),children:"Add…"}),o?n.jsxs("div",{className:"ui-menu ui-chippicker-menu",onKeyDown:I,children:[k?n.jsx("input",{ref:v,type:"search",className:"ui-chippicker-filter","aria-label":`Filter ${e}`,"aria-controls":j,"aria-activedescendant":F,value:u,onChange:T=>{h(T.target.value),m(0)}}):null,n.jsxs("div",{ref:b,id:j,role:"listbox","aria-multiselectable":"true","aria-label":e,"aria-activedescendant":k?void 0:F,tabIndex:k?-1:0,className:"ui-chippicker-list",children:[S.map((T,M)=>n.jsx("div",{id:L(M),role:"option","aria-selected":"false",className:"ui-menu-item","data-highlighted":M===C?"":void 0,onMouseEnter:()=>m(M),onMouseDown:P=>P.preventDefault(),onClick:()=>R(T.value),children:T.label},T.value)),S.length===0?n.jsx("p",{className:"ui-menu-empty",children:"Nothing matches"}):null]})]}):null]})]})}function HA({label:e,options:t,value:s,onChange:r}){return n.jsx("div",{className:"ui-filter-chips",role:"group","aria-label":e,children:t.map(i=>n.jsx("button",{type:"button",className:"ui-btn ui-filter-chip","data-size":"sm","aria-pressed":i.value===s,onClick:()=>r(i.value),children:i.label},i.value))})}function Sf({label:e,value:t,onChange:s,placeholder:r,grow:i}){return n.jsx("span",{className:"ui-search","data-grow":i?"true":void 0,children:n.jsx("input",{type:"search","aria-label":e,value:t,placeholder:r,onChange:a=>s(a.target.value)})})}function Pn({svg:e,icon:t="plug",letter:s,size:r}){return n.jsx("span",{className:"ui-app-icon","data-size":r,"data-tone":e||s?"accent":void 0,"aria-hidden":"true",children:e?n.jsx("span",{className:"ui-app-icon-svg",dangerouslySetInnerHTML:{__html:e}}):s?n.jsx("span",{className:"ui-app-icon-letter",children:s}):n.jsx(ce,{name:t})})}function ah({items:e,label:t="Where this is",inline:s}){const r=e.map((i,a)=>{const l=i.key??String(a);if(i.current)return n.jsx("span",{className:"ui-crumb","aria-current":"page",children:i.label},l);const o=i.href?n.jsx("a",{className:"ui-crumb",href:i.href,onClick:i.onClick?c=>{var u;c.preventDefault(),(u=i.onClick)==null||u.call(i)}:void 0,children:i.label}):n.jsx("button",{type:"button",className:"ui-crumb",onClick:i.onClick,children:i.label});return n.jsxs("span",{className:"ui-crumb-step",children:[o,n.jsx(ce,{name:"chevron-right",size:12})]},l)});return s?n.jsx("span",{className:"ui-crumbs","aria-label":t,children:r}):n.jsx("nav",{className:"ui-crumbs","aria-label":t,children:r})}function KA({main:e,filters:t,filtersOpen:s,onToggleFilters:r,active:i,chips:a,actions:l,onSubmit:o,label:c}){return n.jsxs("form",{className:"ui-panel ui-searchbar",role:"search","aria-label":c,onSubmit:u=>{u.preventDefault(),o()},children:[n.jsxs("div",{className:"ui-searchbar-row",children:[e?n.jsx("div",{className:"ui-searchbar-main",children:e}):null,t&&r?n.jsxs(A,{"aria-expanded":s===!0,"aria-pressed":s===!0,onClick:r,children:["Filters",i?n.jsx("span",{className:"ui-count",children:i}):null]}):null,!r&&t?n.jsx("div",{className:"ui-searchbar-inline",children:t}):null,l?n.jsx("div",{className:"ui-searchbar-actions",children:l}):null]}),t&&r&&s?n.jsx("div",{className:"ui-searchbar-filters",children:t}):null,a?n.jsx("div",{className:"ui-searchbar-chips",children:a}):null]})}function Nc({size:e}){return n.jsx("span",{className:"ui-mark","data-size":e,"aria-hidden":"true",children:"b"})}function VA({quiet:e,still:t,className:s,children:r}){return n.jsx("div",{className:Fi("ui-fieldbg",s),"data-quiet":e?"true":void 0,"data-still":t?"true":void 0,children:r})}function s3({dock:e,className:t,children:s}){return n.jsxs("div",{className:Fi("ui-float",t),children:[n.jsx("div",{className:"ui-float-body",children:s}),e?n.jsx("div",{className:"ui-float-dock",children:e}):null]})}function r3(e){const t={};for(const s of e??[])t[s.key]=s.default;return t}function qj(e){const[t,s]=d.useState({}),r=e??[],i={...r3(r),...t};return r.length===0?{values:void 0,controls:null}:{values:i,controls:n.jsx("div",{className:"ui-choices",children:r.map(a=>n.jsx(oe,{label:a.label,inline:!0,children:n.jsx("select",{value:i[a.key],onChange:l=>s(o=>({...o,[a.key]:l.target.value})),children:a.options.map(l=>n.jsx("option",{value:l,children:l},l))})},a.key))})}}function i3({props:e,timezone:t="UTC",onDecided:s}){var w;const[r,i]=d.useState(null),[a,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(null);d.useEffect(()=>{let y=!1;return i(null),l(null),$.approval(e.approvalId).then(k=>{y||i(k)}).catch(k=>{y||l(k instanceof ve?k.message:String(k))}),()=>{y=!0}},[e.approvalId]);const{values:f,controls:m}=qj(r==null?void 0:r.choices),p=(y,k)=>{h(y),l(null),(f&&y==="approve"?$.decide(e.approvalId,y,k,f):$.decide(e.approvalId,y,k)).then(N=>{i(N.action),s==null||s(N.action)}).catch(N=>l(N instanceof ve?N.message:String(N))).finally(()=>h(null))};if(a&&!r)return n.jsx("p",{className:"wb-empty",children:a});if(!r)return n.jsx("p",{className:"wb-empty",children:"Loading the envelope…"});const g=r.state==="pending",v=(w=r.permissionScopes)==null?void 0:w.includes("always"),b=a3(r),j=(r.preview??"").split(`
94
+ `).length>12||(r.preview??"").length>900,x=[r.decidedBy?`by ${r.decidedBy}`:"",r.decidedVia?`via ${r.decidedVia}`:""].filter(Boolean).join(" ");return n.jsxs("div",{className:"wb-envelope",children:[n.jsxs("div",{className:"envelope",children:[n.jsxs("dl",{className:"envelope-head",children:[n.jsx("dt",{children:"Action"}),n.jsx("dd",{className:"wb-envelope-action",children:r.tool.split(".").map(y=>kn(y)).join(" · ")}),n.jsx("dt",{children:"Status"}),n.jsxs("dd",{children:[g?n.jsx(we,{tone:"warning",dot:!0,children:"waiting for you"}):n.jsx(Xc,{state:r.state}),!g&&x?n.jsxs("span",{className:"wb-envelope-note",children:[" ",x]}):null]}),n.jsx("dt",{children:g?"Expires":"Decided"}),n.jsx("dd",{children:nt(g?r.expiresAt:r.decidedAt,t)})]}),n.jsxs("div",{className:"envelope-body","data-clamp":j&&!o?"true":void 0,children:[r.preview||"(this tool wrote no preview)",j&&!o?n.jsx("button",{type:"button",className:"wb-doc-more",onClick:()=>c(!0),children:"Show the whole preview"}):null]})]}),n.jsx(re,{message:a}),g?m:null,g?n.jsxs("div",{className:"wb-envelope-decide",children:[n.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."}),n.jsxs("div",{className:"wb-envelope-buttons",children:[n.jsx("button",{className:"ui-btn","data-variant":"danger",disabled:u!==null,onClick:()=>p("reject"),children:u==="reject"?"Rejecting…":"Reject"}),v?n.jsxs(n.Fragment,{children:[n.jsx("button",{className:"ui-btn",disabled:u!==null,onClick:()=>p("approve","conversation"),children:"Auto: this conversation"}),n.jsx("button",{className:"ui-btn",disabled:u!==null,onClick:()=>p("approve","always"),children:"Always: this agent"})]}):null,n.jsx("button",{className:"ui-btn","data-variant":"good",disabled:u!==null,onClick:()=>p("approve"),children:u==="approve"?"Approving…":v?"Allow once":"Approve"})]})]}):null,n.jsxs("details",{className:"ui-details",children:[n.jsx("summary",{children:"The envelope, field by field"}),n.jsx("dl",{className:"ui-kv wb-envelope-fields",children:b.map(y=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:y.label}),y.block?n.jsx("dd",{className:"wb-envelope-block",children:n.jsx("pre",{className:"mono",children:y.value})}):n.jsx("dd",{className:y.mono?"mono":void 0,children:y.value})]},y.label))})]})]})}function a3(e){const t=[],s=e.envelope;if(s!==null&&typeof s=="object"&&!Array.isArray(s))for(const[i,a]of Object.entries(s))t.push(Yk(kn(i),a));else s!=null&&t.push({label:"Envelope",value:Yj(s)});const r=e.canonicalArgs;if(r!==null&&typeof r=="object"&&!Array.isArray(r))for(const[i,a]of Object.entries(r)){const l=`Argument · ${kn(i)}`;t.some(o=>o.label===l)||t.push(Yk(l,a))}return t.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&&t.push({label:"Conversation",value:e.conversationId,mono:!0}),e.jobId&&t.push({label:"Job",value:e.jobId,mono:!0}),t}function Yk(e,t){return t!==null&&typeof t=="object"&&(!Array.isArray(t)||t.some(r=>r!==null&&typeof r=="object"))?{label:e,value:JSON.stringify(t,null,2),block:!0}:{label:e,value:Yj(t)}}function Yj(e){return e==null?"—":Array.isArray(e)?e.map(t=>Yj(t)).join(", ")||"—":typeof e=="object"?JSON.stringify(e):nn(e,"text",null)}const l3=new Set(["image/png","image/jpeg","image/gif","image/webp"]),o3=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function lh(e){const t=e!==null&&typeof e=="object"?e.artifacts:null;return Array.isArray(t)?t.flatMap(s=>{if(s===null||typeof s!="object")return[];const r=s;return typeof r.id!="string"||!o3.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 Jj(e){return l3.has(e.toLowerCase())}function Yr(e){return`/api/artifacts/${encodeURIComponent(e)}/preview`}function Ti(e){return`/api/artifacts/${encodeURIComponent(e)}/download`}function qn(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 Qj(e,t){const s=e.toLowerCase(),r=(t??"").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 ia={image:"Image",pdf:"PDF",table:"Spreadsheet",text:"Document",code:"Code",audio:"Audio",video:"Video",archive:"Archive",file:"File"};function vd(e){return`artifact:${e}`}function c3(e){const t=Qj(e.mime,e.filename);return{id:vd(e.artifactId),tool:ia[t],title:e.filename??"Untitled file",renderer:"artifact",props:{attachment:e},at:null,source:"artifact",substantial:!1}}function u3({props:e}){const t=IA(e.artifactId),[s,r]=d.useState(null),[i,a]=d.useState(null),[l,o]=d.useState(!1);if(d.useEffect(()=>{if(t===null)return;let h=!0;return r(null),a(null),o(!1),$.libraryEntry(t).then(f=>{h&&r({filename:f.entry.filename,sizeBytes:f.entry.sizeBytes})}).catch(()=>{}),()=>{h=!1}},[t]),t===null)return n.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=[i?`${i.width} × ${i.height}`:null,s!=null&&s.sizeBytes?qn(s.sizeBytes):null].filter(h=>h!==null);return n.jsxs("figure",{className:"wb-image",children:[n.jsx("div",{className:"wb-image-frame",children:l?n.jsx("p",{className:"wb-empty",children:"This file cannot be shown here. Download it to open it."}):n.jsx("a",{href:Yr(t),className:"wb-image-link",title:"Open at full size",children:n.jsx("img",{src:Yr(t),alt:e.caption??c,onLoad:h=>{const f=h.currentTarget;f.naturalWidth>0&&a({width:f.naturalWidth,height:f.naturalHeight})},onError:()=>o(!0)})})}),n.jsxs("figcaption",{className:"wb-image-caption",children:[n.jsxs(ae,{children:[n.jsx("span",{className:"wb-image-name",children:c}),u.length>0?n.jsx("span",{className:"wb-image-facts",children:u.join(" · ")}):null,n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(dt,{size:"sm",href:Ti(t),download:(s==null?void 0:s.filename)??c,children:"Download"})]}),e.caption&&e.captionLabel?n.jsx(Tt,{summary:e.captionLabel,className:"wb-image-note",children:n.jsx("p",{className:"wb-image-note-body",children:e.caption})}):e.caption?n.jsx("p",{className:"wb-image-note",children:e.caption}):null]})]})}function d3({props:e}){return e.pairs.length===0?n.jsx("p",{className:"wb-empty",children:"Nothing to show."}):n.jsx("dl",{className:"ui-kv",children:e.pairs.map(t=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:t.label}),n.jsx("dd",{className:"tnum",style:t.tone==="neutral"?void 0:{color:`var(--${t.tone})`},children:nn(t.value,t.unit,t.currency)})]},t.label))})}const h3=8;function GA({text:e,label:t="Output",className:s}){const r=d.useRef(null),i=d.useRef(!0);return d.useLayoutEffect(()=>{const a=r.current;a&&i.current&&(a.scrollTop=a.scrollHeight)},[e]),n.jsx("pre",{ref:r,className:s?`wb-terminal-body ${s}`:"wb-terminal-body","aria-label":t,tabIndex:0,onScroll:a=>{const l=a.currentTarget;i.current=l.scrollHeight-l.scrollTop-l.clientHeight<=h3},children:e})}function f3(e){if(e<1e3)return`${Math.round(e)} ms`;const t=e/1e3;if(t<60)return`${t.toFixed(t<10?1:0)} s`;const s=Math.floor(t/60);return`${s} min ${Math.round(t-s*60)} s`}function m3({text:e}){const[t,s]=d.useState("");return n.jsxs(n.Fragment,{children:[t?n.jsx("span",{role:"status",className:"wb-hint",children:t}):null,n.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 p3({props:e}){const t=e.output??"";return n.jsxs("div",{className:"wb-terminal",children:[n.jsxs(ae,{className:"wb-terminal-head",children:[e.command!==null?n.jsx("code",{className:"wb-terminal-command",title:e.command,children:e.command}):null,e.exitCode!==null?n.jsxs(we,{tone:e.exitCode===0?"good":"critical",mono:!0,children:["exit ",e.exitCode]}):null,e.elapsedMs!==null?n.jsx("span",{className:"wb-terminal-fact",children:f3(e.elapsedMs)}):null,n.jsx("span",{className:"ui-toolbar-spacer"}),t!==""?n.jsx(m3,{text:t}):null]}),e.omittedBytes!==null?n.jsxs("p",{className:"wb-terminal-note",children:["First ",qn(e.omittedBytes)," not shown."]}):null,t!==""?n.jsx(GA,{text:t}):n.jsx("p",{className:"wb-empty",children:"No output."}),e.metadata.length>0?n.jsx("dl",{className:"ui-kv wb-terminal-facts",children:e.metadata.map(s=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:s.label}),n.jsx("dd",{children:nn(s.value,s.unit,null)})]},s.label))}):null]})}function g3(){const e=window.location.hostname.replace(/^\[|\]$/g,"").toLowerCase();return e==="127.0.0.1"||e==="::1"||e==="localhost"}function Jk(e){try{const t=new URL(e);return t.searchParams.delete("ticket"),t.toString()}catch{return e}}function x3(e){const t=new Set(e.ports??[]);return e.port!==null&&t.add(e.port),[...t].sort((s,r)=>s-r)}function v3({props:e}){var k;const[t,s]=d.useState(null),[r,i]=d.useState(null),[a,l]=d.useState(null),[o,c]=d.useState(!1),u=((k=e.target)==null?void 0:k.plugin)??null,h=x3(e),[f,m]=d.useState(null),p=f!==null&&h.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=d.useRef(v),[j,x]=d.useState(0);d.useEffect(()=>{v<=b.current||(b.current=v,e.reloadsItself||x(N=>N+1))},[v,e.reloadsItself]),d.useEffect(()=>{if(u===null||g===null)return;let N=!0;return s(null),i(null),l(null),x(0),$.previewLink(u,g).then(S=>{N&&(s(S.url),i(Jk(S.url)))}).catch(S=>{N&&l(S instanceof Error?S.message:"That preview could not be opened.")}),()=>{N=!1}},[u,g]);const w=()=>{u===null||g===null||$.previewLink(u,g).then(N=>i(N.url)).catch(()=>{})};if(e.target===null)return n.jsxs("p",{className:"wb-empty",children:["This panel names no preview. A preview is ",n.jsx("code",{children:"/preview/<plugin>/<name>/"}),", and nothing else is framed here."]});const y=!(e.output===null||e.output==="");return n.jsxs("div",{className:"wb-preview","data-output":o||void 0,children:[n.jsxs("div",{className:"wb-row wb-preview-head",children:[e.title?n.jsx("h4",{className:"wb-doc-title",children:e.title}):null,h.length>1?n.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:h.map(N=>n.jsxs("option",{value:N,children:[":",N]},N))}):null,y?n.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?n.jsx("a",{className:"wb-preview-open",href:r,target:"_blank",rel:"noreferrer noopener",onPointerEnter:w,onFocus:w,title:"Through buddi: works from anywhere the dashboard does, including the tailnet.",children:"Open in a tab"}):null,p!==null&&g3()?n.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]}),n.jsxs("div",{className:"wb-preview-body",children:[t?n.jsx("iframe",{className:"wb-preview-frame",src:j===0?t:Jk(t),title:e.title??"Preview",sandbox:"allow-scripts allow-forms allow-same-origin allow-modals allow-downloads"},j):n.jsx("p",{className:"wb-empty wb-preview-frame",children:a??"Opening the preview…"}),y&&o?n.jsx(GA,{text:e.output??"",className:"wb-preview-output"}):null]})]})}const j3=50,w3=9,y3=24,b3=.6,k3=48,N3=/(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,S3=/^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}|$)/,C3=/^id$|(^|[a-z0-9])Id$|_id$/;function sl(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function ts(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function qA(...e){for(const t of e)if(ts(t))for(const s of["currency","currencyCode"]){const r=t[s];if(typeof r=="string"&&/^[A-Za-z]{3}$/.test(r))return r.toUpperCase()}return null}function YA(e,t,s){const r=t.filter(i=>i!=null&&i!=="");return r.length===0?"text":r.every(i=>typeof i=="boolean")?"boolean":r.every(i=>typeof i=="number"&&Number.isFinite(i))?s!==null&&N3.test(e)?"currency":"number":r.every(i=>typeof i=="string"&&S3.test(i))?"date":"text"}function E3(e,t){if(!C3.test(e))return!1;const s=t.filter(r=>!Yl(r));return s.length<2?!1:new Set(s.map(r=>String(r))).size===s.length}function Yl(e){return e==null||e===""?!0:Array.isArray(e)?e.length===0:ts(e)?Object.keys(e).length===0:!1}function Qk(e,t){const s=e.filter(ts);if(s.length===0||s.length/e.length<.8)return null;const r=s.slice(0,j3),i=new Map,a=[];for(const h of r)for(const f of Object.keys(h))i.has(f)||a.push(f),i.set(f,(i.get(f)??0)+1);if(i.size===0||i.size>y3||[...i.values()].reduce((h,f)=>h+f,0)/(i.size*r.length)<b3)return null;const o=[...i.keys()].sort((h,f)=>{const m=(i.get(f)??0)-(i.get(h)??0);return m!==0?m:a.indexOf(h)-a.indexOf(f)}),c=[],u=[];for(const h of o){const f=r.map(v=>v[h]),m=f.filter(v=>!Yl(v));if(m.length===0||E3(h,f))continue;const p=qA(r[0],t),g=YA(h,f,p);if(r.length>=4&&m.length===f.length&&f.every(v=>sl(v)&&v===f[0])){u.push({label:kn(h),value:f[0],type:g,currency:p});continue}if(c.push({key:h,label:kn(h),type:g,currency:g==="currency"?p:null}),c.length===w3)break}return c.length===0?null:{columns:c,rows:s,constants:u}}function A3(e,t,s){const r=qA(s);return{label:kn(e),value:t,type:YA(e,[t],r),currency:r}}function JA(e){return typeof e=="string"&&e.length>k3}function T3(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.":ts(e)&&Object.keys(e).length===0?"This tool returned an empty result.":null}function rx(e){if(typeof e=="string"&&e.trim()!=="")return e;if(ts(e))for(const t of["message","error","reason","detail","description"]){const s=e[t];if(typeof s=="string"&&s.trim()!=="")return s;if(ts(s)){const r=rx(s);if(r!=="The call failed with no reason given.")return r}}return"The call failed with no reason given."}function Xj(e,t={}){if(t.failed){let f=e;if(typeof e=="string")try{const m=JSON.parse(e.replace(/^tool-error:\s*/,""));ts(m)&&(f=m)}catch{}return{kind:"error",summary:rx(f),detail:Xk(f)}}if(ts(e)){const f=e.error,m=e.ok;if(typeof f=="string"&&f.trim()!==""||m===!1)return{kind:"error",summary:rx(e),detail:Xk(e)}}const s=T3(e);if(s)return{kind:"empty",note:s,stats:[]};if(Array.isArray(e)){const f=Qk(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(!ts(e))return{kind:"tree",value:e};const r=Object.entries(e);let i=null,a=null;for(const[f,m]of r){if(!Array.isArray(m))continue;const p=Qk(m,e);if(p){(!i||p.rows.length>i.candidate.rows.length)&&(i={key:f,candidate:p});continue}m.length>0&&m.every(sl)&&(!a||m.length>a.items.length)&&(a={key:f,items:m})}const l=(i==null?void 0:i.key)??(a==null?void 0:a.key)??null,o=[],c=[],u=[];for(const[f,m]of r)if(f!==l){if(JA(m)){c.push(m);continue}if(sl(m)){if(m==="")continue;o.push(A3(f,m,e));continue}m!==void 0&&u.push({label:kn(f),value:m})}if(i)return{kind:"table",label:kn(i.key),columns:i.candidate.columns,rows:i.candidate.rows,total:i.candidate.rows.length,stats:[...o,...i.candidate.constants],notes:c,asides:u};if(a)return{kind:"list",label:kn(a.key),items:a.items,total:a.items.length,stats:o,notes:c,asides:u};const h=r.filter(([,f])=>Array.isArray(f)&&f.length===0);return h.length>0&&h.length===r.filter(([,f])=>Array.isArray(f)).length?{kind:"empty",note:`No ${h.map(([m])=>kn(m).toLowerCase()).join(", ")} to show.`,stats:o}:r.every(([,f])=>sl(f)||ts(f)||Array.isArray(f))?{kind:"record",pairs:o,notes:c,asides:u}:{kind:"tree",value:e}}function Xk(e){if(!ts(e))return null;const t=Object.entries(e).filter(([s])=>s!=="message"&&s!=="error");return t.length===0?null:Object.fromEntries(t)}const oh=25,$3=3,ix=8,QA=6;function ax(e,t=0){if(t>QA||Yl(e)||JA(e))return 0;if(sl(e))return 1;if(Array.isArray(e)){let s=0;for(const r of e)if(s+=ax(r,t+1),s>=ix)return s;return s}if(ts(e)){let s=0;for(const r of Object.values(e))if(s+=ax(r,t+1),s>=ix)return s;return s}return 0}function lx(e,t=0){if(t>QA)return!1;if(Array.isArray(e))return e.some(a=>lx(a,t+1));if(!ts(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,i=e.url??e.src??e.downloadUrl??e.path;return typeof r=="string"&&r.includes("/")&&typeof i=="string"&&i.trim()!==""?!0:Object.values(e).some(a=>lx(a,t+1))}function R3(e){if(lx(e))return!0;const t=Xj(e);switch(t.kind){case"table":return t.rows.length>0;case"list":return t.items.length>=$3;case"record":case"tree":return ax(e)>=ix;default:return!1}}function _m(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function Zj(e){const t=_m(e);if(!t)return null;const s=_m(t.output)??t;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===t?null:_m(t.input),i=(r==null?void 0:r.command)??s.command;return{command:typeof i=="string"?i:null,input:r,result:s}}function I3({text:e,label:t}){const[s,r]=d.useState("");return n.jsxs("span",{className:"wb-command-copy",children:[n.jsx("button",{className:"ui-btn",onClick:()=>{var i;if(r(""),!((i=navigator.clipboard)!=null&&i.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:t}),s&&n.jsx("span",{role:"status",className:"wb-hint",children:s})]})}function zm({title:e,text:t,error:s=!1}){return n.jsxs("section",{className:"wb-command-stream","data-error":s||void 0,children:[n.jsxs("div",{className:"wb-command-bar",children:[n.jsx("h4",{children:e}),n.jsx(I3,{text:t,label:`Copy ${e.toLowerCase()}`})]}),n.jsx("pre",{className:"wb-command-text","aria-label":e,tabIndex:0,children:t})]})}function P3({value:e,children:t}){const{result:s,command:r,input:i}=e,a=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(([h,f])=>!["stdout","stderr","state","exitCode","artifacts","outputErrors","command"].includes(h)&&f!==null&&f!==void 0&&f!=="")),u=Array.isArray(s.outputErrors)?s.outputErrors.filter(h=>typeof h=="string"):[];return n.jsxs("div",{className:"wb-command-result",children:[n.jsxs("div",{className:"wb-command-bar",children:[n.jsx("span",{className:"ui-pill","data-tone":o?"good":"critical",children:a?"Failed":s.state==="completed"&&l?"Terminated":s.state}),s.exitCode!==null&&n.jsxs("span",{className:"mono",children:["Exit code ",s.exitCode]}),l&&n.jsxs("span",{className:"mono",children:["Signal ",l]}),n.jsx("span",{className:"wb-hint",children:"Recorded command result"})]}),r!==null&&n.jsx(zm,{title:"Command",text:r}),s.state==="output-limit"&&n.jsx("p",{className:"wb-fail",children:"Output limit reached. The command was stopped and the captured output may be incomplete."}),s.state==="timed-out"&&n.jsx("p",{className:"wb-fail",children:"The command exceeded its time limit. Output below may be partial."}),s.state==="cancelled"&&n.jsx("p",{className:"wb-note",children:"The command was cancelled. Completed changes were not undone."}),s.stdout?n.jsx(zm,{title:"Output",text:s.stdout}):n.jsx("p",{className:"wb-note",children:"No standard output."}),s.stderr?n.jsx(zm,{title:"Standard error",text:s.stderr,error:!0}):null,u.length>0&&n.jsxs("section",{children:[n.jsx("h4",{children:"File export errors"}),u.map((h,f)=>n.jsx("p",{className:"wb-fail",children:h},f))]}),t,(Object.keys(c).length>0||i!==null)&&n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:"Execution details"}),n.jsx("pre",{children:is({...c,...i?{input:i}:{}})})]})]})}const Uu=2,Zk=64;function M3({props:e}){const[t,s]=d.useState(!1),r=Zj(e.value),i=D3((r==null?void 0:r.result)??e.value),a=d.useMemo(()=>Xj(e.value,{failed:e.failed??!1}),[e.value,e.failed]);return n.jsxs("div",{children:[!r&&n.jsx(e0,{files:i}),t?n.jsx("pre",{className:"ui-code",children:is(e.value)}):r?n.jsx(P3,{value:r,children:i.length>0&&n.jsxs("section",{children:[n.jsx("h4",{children:"Generated files"}),n.jsx(e0,{files:i})]})}):i.length?n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:"Tool details"}),n.jsx(t0,{shape:a})]}):n.jsx(t0,{shape:a}),n.jsx("div",{className:"wb-row-end wb-section",children:n.jsx("button",{className:"ui-btn","data-variant":"ghost","data-size":"sm",onClick:()=>s(l=>!l),"aria-pressed":t,children:t?"Readable":"Raw JSON"})})]})}function D3(e){const t=e&&typeof e=="object"&&"artifacts"in e?e.artifacts:null;return Array.isArray(t)?t.filter(s=>s&&typeof s.id=="string"&&/^[0-9a-f-]{36}$/i.test(s.id)&&typeof s.filename=="string"):[]}function e0({files:e}){return e.length?n.jsx("div",{className:"wb-artifacts",children:e.map(t=>{var s;return n.jsxs("div",{children:[["image/png","image/jpeg","image/gif","image/webp"].includes(t.mime??"")?n.jsx(O3,{file:t}):null,n.jsx("a",{className:"ui-btn",href:`/api/artifacts/${encodeURIComponent(t.id)}/download`,download:!0,children:(s=t.mime)!=null&&s.startsWith("image/")?`Download ${t.filename}`:t.filename})]},t.id)})}):null}function O3({file:e}){const[t,s]=d.useState(!1);return t?n.jsx("p",{className:"wb-note",children:"Preview unavailable. You can still download the file."}):n.jsx("img",{className:"wb-artifact-image",src:`/api/artifacts/${e.id}/preview`,alt:e.filename,onError:()=>s(!0)})}function t0({shape:e}){switch(e.kind){case"error":return n.jsxs("div",{children:[n.jsx("p",{className:"wb-fail",role:"status",children:e.summary}),e.detail===null?null:n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:"What came back with it"}),n.jsx("div",{className:"wb-tree",children:Sc(e.detail,1)})]})]});case"empty":return n.jsxs("div",{children:[n.jsx(Um,{stats:e.stats}),n.jsx("p",{className:"wb-note",children:e.note})]});case"table":{const t=B3(e.columns,e.rows);return n.jsxs("div",{children:[n.jsx(Um,{stats:e.stats}),n.jsx(Bm,{notes:e.notes}),t?n.jsx(W3,{label:e.label,plan:t,rows:e.rows,total:e.total}):n.jsx(F3,{label:e.label,columns:e.columns,rows:e.rows,total:e.total}),n.jsx(Wm,{asides:e.asides})]})}case"list":return n.jsxs("div",{children:[n.jsx(Um,{stats:e.stats}),n.jsx(Bm,{notes:e.notes}),e.label?n.jsx("h4",{className:"wb-sub",children:e.label}):null,n.jsx("ul",{className:"wb-list",children:e.items.slice(0,100).map((t,s)=>n.jsx("li",{children:nn(t,"text",null)},s))}),e.total>100?n.jsxs("p",{className:"wb-note",children:["Showing 100 of ",e.total,"."]}):null,n.jsx(Wm,{asides:e.asides})]});case"record":return n.jsxs("div",{children:[n.jsx(Bm,{notes:e.notes}),n.jsx(L3,{pairs:e.pairs}),n.jsx(Wm,{asides:e.asides})]});default:return n.jsx("div",{className:"wb-tree",children:Sc(e.value,0)})}}function Um({stats:e}){return e.length===0?null:n.jsx("div",{className:"ui-stats","data-inline":"true",children:e.map(t=>n.jsxs("div",{children:[n.jsx("div",{className:"ui-stat-k",children:t.label}),n.jsx("div",{className:"ui-stat-v",children:ew(t.value,t.type,t.currency)})]},t.label))})}const n0=200;function Bm({notes:e}){if(e.length===0)return null;const t=e.filter(r=>r.length<=n0),s=e.filter(r=>r.length>n0);return n.jsxs(n.Fragment,{children:[t.map(r=>n.jsx("p",{className:"wb-note",children:r},r)),s.length>0?n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:s.length===1?"A note that came with this result":`${s.length} notes that came with this result`}),s.map(r=>n.jsx("p",{className:"wb-note",children:r},r))]}):null]})}function L3({pairs:e}){return e.length===0?n.jsx("p",{className:"wb-note",children:"Nothing to show."}):n.jsx("dl",{className:"ui-kv",children:e.map(t=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:t.label}),n.jsx("dd",{className:t.type==="text"?void 0:"tnum",children:ew(t.value,t.type,t.currency)})]},t.label))})}function Wm({asides:e}){return e.length===0?null:n.jsx("div",{className:"wb-section",children:e.map(t=>n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:t.label}),n.jsx("div",{className:"wb-tree",children:Sc(t.value,1)})]},t.label))})}function F3({label:e,columns:t,rows:s,total:r}){const[i,a]=d.useState(!1),l=r<=oh+5?r:oh,o=i?s:s.slice(0,l);return n.jsxs("div",{children:[e?n.jsx("h4",{className:"wb-sub",children:e}):null,n.jsx("div",{className:"ui-table-wrap",children:n.jsxs("table",{className:"ui-table",children:[n.jsx("thead",{children:n.jsx("tr",{children:t.map(c=>n.jsx("th",{className:ZA(c.type)?"num":void 0,children:c.label},c.key))})}),n.jsx("tbody",{children:o.map((c,u)=>n.jsx("tr",{children:t.map(h=>n.jsx(H3,{value:c[h.key],column:h},h.key))},u))})]})}),r>o.length?n.jsxs("p",{className:"wb-note wb-note-row",children:[n.jsxs("span",{children:["Showing ",o.length," of ",r]}),n.jsxs("button",{className:"ui-btn",onClick:()=>a(!0),children:["Show all ",r]})]}):null]})}const _3=/^(title|name|headline|subject|label|heading)$/i,z3=/^(url|link|href|uri|permalink)$/i;function ch(e){return typeof e=="string"&&/^https?:\/\/[^\s]+$/i.test(e.trim())}function U3(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function XA(e,t=48){try{const s=new URL(e),r=s.pathname==="/"?"":s.pathname,i=`${s.hostname.replace(/^www\./,"")}${r}${s.search}`;return i.length>t?`${i.slice(0,t-1)}…`:i}catch{return e.length>t?`${e.slice(0,t-1)}…`:e}}function Bu(e,t){const s=e.map(r=>r[t]).filter(r=>typeof r=="string"&&r.trim()!=="");return s.length===0?0:s.reduce((r,i)=>r+i.length,0)/s.length}function B3(e,t){if(t.length===0)return null;const s=e.filter(h=>h.type==="text"),r=s.find(h=>z3.test(h.key)&&t.some(f=>ch(f[h.key])))??s.find(h=>{const f=t.map(m=>m[h.key]).filter(m=>!Yl(m));return f.length>0&&f.filter(ch).length/f.length>=.6});if(!r)return null;const i=s.filter(h=>h.key!==r.key),a=i.find(h=>_3.test(h.key))??i.find(h=>Bu(t,h.key)>0);if(!a)return null;const o=[...i.filter(h=>h.key!==a.key)].sort((h,f)=>Bu(t,f.key)-Bu(t,h.key)),c=o[0]&&Bu(t,o[0].key)>40?o[0]:null,u=e.filter(h=>h.key!==r.key&&h.key!==a.key&&h.key!==(c==null?void 0:c.key)).map(h=>h.key);return{url:r.key,title:a.key,description:(c==null?void 0:c.key)??null,meta:u}}function W3({label:e,plan:t,rows:s,total:r}){const[i,a]=d.useState(!1),l=r<=oh+5?r:oh,o=i?s:s.slice(0,l);return n.jsxs("div",{children:[e?n.jsx("h4",{className:"wb-sub",children:e}):null,n.jsx("ol",{className:"wb-records",children:o.map((c,u)=>{const h=c[t.url],f=ch(h)?h.trim():null,m=typeof c[t.title]=="string"&&c[t.title].trim()!==""?c[t.title]:f?XA(f):"Untitled",p=t.description&&typeof c[t.description]=="string"?c[t.description]:null,g=f?U3(f):null,v=t.meta.map(b=>c[b]).filter(b=>!Yl(b)&&typeof b!="object").map(b=>String(b)).filter(b=>g===null||b.replace(/^www\./,"")!==g);return n.jsxs("li",{className:"wb-record",children:[f?n.jsx("a",{className:"wb-record-title",href:f,target:"_blank",rel:"noopener noreferrer",children:m}):n.jsx("span",{className:"wb-record-title",children:m}),n.jsxs("div",{className:"wb-record-meta",children:[g?n.jsx("span",{className:"wb-record-host",title:f??void 0,children:g}):null,v.map((b,j)=>n.jsx("span",{children:b.length>60?`${b.slice(0,59)}…`:b},j))]}),p?n.jsx("p",{className:"wb-record-desc",children:p.length>280?`${p.slice(0,279)}…`:p}):null]},u)})}),r>o.length?n.jsxs("p",{className:"wb-note wb-note-row",children:[n.jsxs("span",{children:["Showing ",o.length," of ",r]}),n.jsxs("button",{className:"ui-btn",onClick:()=>a(!0),children:["Show all ",r]})]}):null]})}function H3({value:e,column:t}){if(Yl(e))return n.jsx("td",{className:"wb-cell-soft",children:"—"});if(ch(e)){const i=e.trim();return n.jsx("td",{className:"wb-cell-link",children:n.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",title:i,children:XA(i)})})}if(e!==null&&typeof e=="object"){const i=Array.isArray(e)?`${e.length} item${e.length===1?"":"s"}`:`${Object.keys(e).length} fields`;return n.jsx("td",{className:"wb-cell-soft",title:is(e),children:i})}const s=ew(e,t.type,t.currency),r=s.length>Zk?`${s.slice(0,Zk-1)}…`:s;return n.jsx("td",{className:ZA(t.type)?"num":"wb-cell-text",...r===s?{}:{title:s},children:r})}function ZA(e){return e==="number"||e==="currency"}function ew(e,t,s){return e==null?"—":t==="boolean"?e?"yes":"no":nn(e,t==="text"?"text":t,s)}function Sc(e,t){if(e===null)return n.jsx("span",{className:"wb-tree-null",children:"null"});if(e===void 0)return n.jsx("span",{className:"wb-tree-null",children:"—"});if(typeof e=="number")return n.jsx("span",{className:"wb-tree-num",children:e});if(typeof e=="boolean")return n.jsx("span",{className:"wb-tree-bool",children:e?"true":"false"});if(typeof e=="string")return n.jsx("span",{children:e===""?n.jsx("em",{className:"wb-tree-null",children:"empty"}):e});if(Array.isArray(e)){if(e.length===0)return n.jsx("span",{className:"wb-tree-null",children:"none"});const i=n.jsxs("div",{className:"wb-tree-branch",children:[e.slice(0,50).map((a,l)=>n.jsxs("div",{children:[n.jsxs("span",{className:"wb-tree-key",children:[l,". "]}),Sc(a,t+1)]},l)),e.length>50?n.jsxs("div",{className:"wb-tree-key",children:["…and ",e.length-50," more"]}):null]});return t>=Uu?n.jsx(s0,{summary:`${e.length} items`,open:t===Uu,children:i}):i}const s=Object.entries(e);if(s.length===0)return n.jsx("span",{className:"wb-tree-null",children:"empty"});const r=n.jsx("div",{className:t===0?void 0:"wb-tree-branch",children:s.map(([i,a])=>n.jsxs("div",{children:[n.jsxs("span",{className:"wb-tree-key",children:[kn(i),": "]}),Sc(a,t+1)]},i))});return t>=Uu?n.jsx(s0,{summary:`${s.length} fields`,open:t===Uu,children:r}):r}function s0({summary:e,open:t,children:s}){return n.jsxs("details",{open:t,children:[n.jsx("summary",{className:"wb-tree-key",children:e}),s]})}function K3({props:e}){const t=e.groups.every(s=>s.rows.length===0);return n.jsxs("div",{children:[e.summary.length>0?n.jsx("div",{className:"ui-stats","data-inline":"true",children:e.summary.map(s=>n.jsxs("div",{children:[n.jsx("div",{className:"ui-stat-k",children:s.label}),n.jsx("div",{className:"ui-stat-v","data-tone":s.tone,children:nn(s.value,s.unit,s.currency)})]},s.label))}):null,t?n.jsx("p",{className:"wb-empty",children:e.empty}):e.groups.map((s,r)=>n.jsxs("div",{className:r>0?"wb-section":void 0,children:[s.label?n.jsx("h4",{className:"ui-stat-k wb-label",children:s.label}):null,n.jsx("div",{className:"ui-table-wrap",children:n.jsxs("table",{className:"ui-table",children:[n.jsx("thead",{children:n.jsx("tr",{children:e.columns.map(i=>n.jsx("th",{className:eT(i.type)?"num":void 0,"data-type":i.type,children:i.label},i.key))})}),n.jsx("tbody",{children:s.rows.map((i,a)=>n.jsx("tr",{children:i.map((l,o)=>{var c;return n.jsx(V3,{cell:l},((c=e.columns[o])==null?void 0:c.key)??o)})},a))})]})})]},s.label??r))]})}function V3({cell:e}){const t=nn(e.value,e.type,e.currency);return e.bar?n.jsx("td",{className:"num",children:n.jsxs("div",{className:"wb-row wb-row-end",children:[n.jsx("div",{className:"ui-meter",role:"meter","aria-valuenow":Math.round(e.bar.fraction*100),"aria-valuemin":0,"aria-valuemax":100,"aria-label":t,children:n.jsx("div",{className:"ui-meter-fill","data-tone":e.bar.tone,style:{width:`${Math.round(e.bar.fraction*100)}%`}})}),n.jsx("span",{className:"tnum",children:t})]})}):n.jsx("td",{className:eT(e.type)?"num":void 0,"data-type":e.type,title:t.length>40?t:void 0,children:t})}function eT(e){return e==="number"||e==="currency"||e==="percent"}const r0={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 Jl(e){return(e&&Object.prototype.hasOwnProperty.call(r0,e)?r0[e]:void 0)??"dot"}function uh(e,t){return(e??[]).filter(s=>s.place===t).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 dh="buddi:plugin-pages-changed";function G3(){window.dispatchEvent(new Event(dh))}function tT(e=!1){const[t,s]=d.useState([]);return d.useEffect(()=>{if(e)return;let r=!1;const i=()=>{Promise.resolve().then(()=>$.pages()).then(l=>{r||s(Array.isArray(l==null?void 0:l.pages)?l.pages:[])}).catch(()=>{})};i();const a=()=>{document.visibilityState==="visible"&&i()};return window.addEventListener(dh,i),document.addEventListener("visibilitychange",a),()=>{r=!0,window.removeEventListener(dh,i),document.removeEventListener("visibilitychange",a)}},[e]),{all:t,rail:uh(t,"rail"),settings:uh(t,"settings"),find:(r,i)=>t.find(a=>a.plugin===r&&a.id===i)}}function nT(e,t){const s=(t??[]).filter(a=>a.plugin===e),r=uh(s,"rail")[0]??uh(s,"settings")[0];if(r!=null&&r.title.trim())return r.title.trim();const i=e.replace(/[-_]+/g," ").trim();return i?i.charAt(0).toUpperCase()+i.slice(1):e}let jd=null;typeof window<"u"&&window.addEventListener(dh,()=>{jd=null});function q3(){return jd??(jd=Promise.resolve().then(()=>$.pages()).then(e=>Array.isArray(e==null?void 0:e.pages)?e.pages:[]).catch(()=>(jd=null,[]))),jd}function tw(e,t,s){return s==="settings"?vr(e,t):xr(e,t)}function Y3(e){const[t,s]=d.useState(null),r=e==null?void 0:e.plugin,i=e==null?void 0:e.page;return d.useEffect(()=>{if(!r||!i)return;let a=!1;return q3().then(l=>{const o=l.find(c=>c.plugin===r&&c.id===i);a||s(o?{href:tw(r,i,o.place),label:o.place==="settings"?`Settings → ${o.title}`:o.title}:null)}),()=>{a=!0}},[r,i]),t}function sT({props:e,layout:t,selected:s,onPick:r}){return e.tiles.length===0?n.jsx("p",{className:"wb-empty",children:e.empty}):n.jsx("ul",{className:"wb-tiles","data-notice":e.notice?"true":void 0,"data-layout":t&&t!=="grid"?t:void 0,style:t==="row"?{"--tiles-n":e.tiles.length}:void 0,children:e.tiles.map((i,a)=>n.jsx(J3,{tile:i,...r?{picked:a===s,onPick:()=>r(a)}:{}},`${a}-${i.label}`))})}function J3({tile:e,picked:t,onPick:s}){const r=Y3(e.link),i=[e.label,e.value,...e.lines].filter(l=>l!=="").join(", "),a=n.jsxs("div",{className:"wb-tile-body","aria-hidden":"true",children:[n.jsx("span",{className:"wb-tile-icon","data-icon":e.icon??"dot",children:n.jsx(ce,{name:Jl(e.icon),size:22})}),e.value!==""?n.jsx("span",{className:"wb-tile-value tnum",children:e.value}):null,n.jsx("span",{className:"wb-tile-label",children:e.label}),e.lines.map((l,o)=>n.jsx("span",{className:"wb-tile-line",children:l},o))]});return s?n.jsx("li",{className:"wb-tile",children:n.jsx("button",{type:"button",className:"ui-card","data-tone":t?"accent":e.tone==="neutral"?void 0:e.tone,"data-selected":t?"true":void 0,"aria-pressed":t===!0,"aria-label":i,onClick:s,children:a})}):n.jsxs("li",{className:"wb-tile",children:[n.jsx("span",{className:"sr-only",children:i}),n.jsxs(ds,{tone:e.tone==="neutral"?void 0:e.tone,children:[a,r?n.jsx("a",{className:"wb-tile-link",href:r.href,children:r.label}):null]})]})}const La=760,Hm=400,Ft={top:18,right:18,bottom:36,left:66},Q3=5;function X3({props:e}){const{points:t,referenceLines:s,unit:r,currency:i}=e;if(t.length===0)return n.jsx("p",{className:"wb-empty",children:"This result carried no points to plot."});const a=[...t.map(y=>y.y),...s.map(y=>y.value)],l=Math.min(...a),o=Math.max(...a),c=o-l||Math.abs(o)||1,u=l-c*.08,h=o+c*.08,f=La-Ft.left-Ft.right,m=Hm-Ft.top-Ft.bottom,p=y=>Ft.left+(t.length===1?f/2:y/(t.length-1)*f),g=y=>Ft.top+m-(y-u)/(h-u)*m,v=nh(l,o,4),b=e6(t.map(y=>y.y),e.mark),j=e.shadeBelow===null?[]:t6(t.map(y=>y.y),e.shadeBelow),x=t.map((y,k)=>`${k===0?"M":"L"}${p(k)},${g(y.y)}`).join(" "),w=y=>nn(y,r,i);return n.jsxs("div",{children:[e.label?n.jsx("p",{className:"ui-panel-sub",children:e.label}):null,n.jsxs("div",{className:"wb-chart-layout",children:[n.jsx("div",{className:"wb-chart-plot",children:n.jsxs("svg",{className:"wb-chart",viewBox:`0 0 ${La} ${Hm}`,role:"img","aria-label":Z3(e,w),preserveAspectRatio:"xMidYMid meet",children:[j.map(y=>n.jsx("rect",{className:"wb-chart-breach",x:p(y.from),width:Math.max(2,p(y.to)-p(y.from)),y:Ft.top,height:m},`band-${y.from}`)),v.map(y=>n.jsxs("g",{children:[n.jsx("line",{className:"wb-chart-grid",x1:Ft.left,x2:La-Ft.right,y1:g(y),y2:g(y)}),n.jsx("text",{x:Ft.left-8,y:g(y)+4,textAnchor:"end",children:w(y)})]},`tick-${y}`)),s.map(y=>n.jsxs("g",{children:[n.jsx("line",{className:"wb-chart-floor",x1:Ft.left,x2:La-Ft.right,y1:g(y.value),y2:g(y.value)}),n.jsxs("text",{x:La-Ft.right,y:g(y.value)-6,textAnchor:"end",children:[y.label," ",w(y.value)]})]},`rule-${y.label}`)),n.jsx("line",{className:"wb-chart-axis",x1:Ft.left,x2:Ft.left,y1:Ft.top,y2:Ft.top+m}),n.jsx("line",{className:"wb-chart-axis",x1:Ft.left,x2:La-Ft.right,y1:Ft.top+m,y2:Ft.top+m}),n.jsx("path",{className:"wb-chart-series",d:x}),b!==null?n.jsxs("g",{children:[n.jsx("circle",{className:"wb-chart-min",cx:p(b),cy:g(t[b].y),r:4.5}),n.jsx("text",{x:p(b),y:g(t[b].y)+20,textAnchor:"middle",children:w(t[b].y)})]}):null,n6(t.length).map(y=>n.jsx("text",{x:p(y),y:Hm-10,textAnchor:"middle",children:Gg(t[y].x)},`x-${y}`))]})}),e.events.length>0?n.jsxs("aside",{className:"wb-chart-events",children:[n.jsx("h4",{className:"ui-stat-k wb-label",children:"What happens"}),n.jsx("ul",{className:"wb-chart-event-list",children:e.events.map((y,k)=>n.jsxs("li",{className:"wb-chart-event",children:[n.jsxs("span",{children:[n.jsx("span",{className:"wb-chart-event-day",children:Gg(y.at)}),y.label]}),y.amount===null?null:n.jsx("span",{className:y.amount<0?"tnum critical":"tnum good",children:nn(y.amount,r,i)})]},`${y.at}-${y.label}-${k}`))})]}):null]})]})}function Z3(e,t){const s=e.points.map(l=>l.y),r=e.points[0],i=e.points[e.points.length-1],a=e.referenceLines.map(l=>`${l.label} at ${t(l.value)}`).join(", ");return[`${e.points.length} points from ${r==null?void 0:r.x} to ${i==null?void 0:i.x}`,`low ${t(Math.min(...s))}, high ${t(Math.max(...s))}`,a].filter(Boolean).join("; ")}function e6(e,t){if(!t||e.length===0)return null;let s=0;for(let r=1;r<e.length;r+=1)(t==="min"?e[r]<e[s]:e[r]>e[s])&&(s=r);return s}function t6(e,t){const s=[];let r=null;return e.forEach((i,a)=>{i<t?r===null&&(r=a):r!==null&&(s.push({from:r,to:a}),r=null)}),r!==null&&s.push({from:r,to:e.length-1}),s}function n6(e,t=Q3){if(e<=0)return[];if(e<=t)return[...Array(e).keys()];const s=e-1,r=new Set;for(let i=0;i<t;i+=1)r.add(Math.round(i/(t-1)*s));return[...r].sort((i,a)=>i-a)}const ms=e=>e,ox={timeseries:ms(X3),table:ms(K3),bars:ms(b4),keyvalue:ms(d3),tiles:ms(sT),document:ms(pU),diff:ms(A4),terminal:ms(p3),image:ms(u3),preview:ms(v3),envelope:ms(i3),structured:ms(M3)},s6="structured";function r6(e){return(hh(e)?ox[e]:void 0)??ox[s6]}function hh(e){return Object.prototype.hasOwnProperty.call(ox,e)}function i6({renderer:e,props:t,timezone:s,onDecided:r}){const i=r6(e),l=hh(e)?t:{value:t};return n.jsx(i,{props:l,timezone:s,onDecided:r})}function a6({profile:e,onChange:t}){return n.jsxs("div",{className:"wb-prof","data-testid":"agent-profile",children:[n.jsx("p",{className:"wb-prof-lead",children:e.description}),n.jsxs("div",{className:"wb-prof-tags",children:[e.isDefault?n.jsx(Km,{children:"Opens by default"}):null,n.jsx(Km,{children:e.source==="example"?"Shipped with buddi":"Yours"}),e.roles.map(s=>n.jsx(Km,{title:`A surface command that asks for "${s}" lands on this agent.`,children:kn(s)},s))]}),e.available?null:n.jsxs("p",{className:"wb-prof-blocked","data-testid":"agent-profile-unavailable",children:[n.jsx("strong",{children:"This agent cannot run here."})," ",e.unavailableReason]}),(e.disabled??[]).map(s=>n.jsx("p",{className:"wb-prof-blocked","data-testid":"agent-profile-disabled",children:s},s)),n.jsx(jo,{title:"How it works with you",note:"Live decisions stay in the conversation; this page explains the standing rules.",children:n.jsxs("ul",{className:"wb-prof-list",children:[n.jsxs("li",{className:"wb-prof-row",children:[n.jsxs("span",{className:"wb-prof-row-main",children:[n.jsx("span",{className:"wb-prof-row-name",children:"Quick questions"}),n.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."})]}),n.jsx("span",{className:"wb-prof-auto",children:"Answers only"})]}),n.jsxs("li",{className:"wb-prof-row","data-gated":"true",children:[n.jsxs("span",{className:"wb-prof-row-main",children:[n.jsx("span",{className:"wb-prof-row-name",children:"Action approvals"}),n.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."})]}),n.jsxs("span",{className:"wb-prof-gate",children:[n.jsx(rT,{}),"Exact action"]})]})]})}),n.jsx(jo,{title:"What it can do",note:l6(e),tone:e.gatedCount>0?"warning":void 0,children:e.tools.length===0?n.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=>n.jsx(o6,{family:s},s.family))}),n.jsx(jo,{title:"What it runs on",children:n.jsxs("dl",{className:"wb-prof-kv",children:[n.jsx(wo,{label:"Provider",children:e.engine.provider}),n.jsx(wo,{label:"Model",children:n.jsx("span",{className:"mono",children:e.engine.model})}),n.jsxs(wo,{label:"Credential",children:[e.engine.credentialKind," from"," ",n.jsx("span",{className:"mono",children:e.engine.credentialEnv})]}),n.jsxs(wo,{label:"Turn budget",children:[e.engine.maxTurns," ",e.engine.maxTurns===1?"turn":"turns"," per message"]}),n.jsx(wo,{label:"Language",children:f6(e.engine.language)})]})}),e.skills.length>0?n.jsx(jo,{title:"What it has read",note:`${e.skills.length} ${e.skills.length===1?"skill":"skills"}, composed into every run`,children:n.jsx("ul",{className:"wb-prof-list",children:e.skills.map(s=>n.jsxs("li",{className:"wb-prof-row",children:[n.jsxs("span",{className:"wb-prof-row-main",children:[n.jsx("span",{className:"wb-prof-row-name mono",children:s.name}),s.description?n.jsx("span",{className:"wb-prof-row-desc",children:s.description}):null]}),n.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?n.jsx(jo,{title:"Who it can hand work to",note:"A colleague's tools are reached through the colleague, never held here",children:n.jsx("ul",{className:"wb-prof-list",children:e.delegates.map(s=>n.jsxs("li",{className:"wb-prof-row",children:[n.jsxs("span",{className:"wb-prof-row-main",children:[n.jsxs("span",{className:"wb-prof-row-name mono",children:["@",s.handle]}),n.jsx("span",{className:"wb-prof-row-desc",children:s.description})]}),n.jsx("span",{className:"wb-prof-row-side",children:s.available?s.name:`${s.name} · cannot run`})]},s.id))})}):null,n.jsxs("footer",{className:"wb-prof-foot",children:[n.jsx("p",{className:"wb-prof-note",children:e.note}),n.jsx("p",{className:"wb-prof-file mono",title:e.file,children:e.file}),e.changeVia&&t?n.jsxs("button",{className:"ui-btn","data-testid":"agent-profile-change",title:e.changeVia.prompt,onClick:()=>t({agentId:e.changeVia.agentId,prompt:e.changeVia.prompt}),children:["Ask @",e.changeVia.handle," to change this"]}):null]})]})}function l6(e){if(e.toolCount===0)return"Nothing. This agent holds no tools.";const t=`${e.toolCount} ${e.toolCount===1?"tool":"tools"}`;if(e.gatedCount===0)return`${t}, 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`${t}, and ${s}.`}function o6({family:e}){const t=[...e.tools].sort((s,r)=>Number(r.gated)-Number(s.gated));return n.jsxs("section",{className:"wb-prof-family",children:[n.jsxs("h4",{className:"wb-prof-family-head",children:[n.jsx("span",{className:"wb-prof-family-name",children:kn(e.family)}),n.jsxs("span",{className:"wb-prof-family-note",children:[e.tools.length," ",e.tools.length===1?"tool":"tools",e.gated>0?` · ${e.gated} needs you`:""]})]}),n.jsx("ul",{className:"wb-prof-list",children:t.map(s=>n.jsx(c6,{tool:s},s.name))})]})}function c6({tool:e}){return n.jsxs("li",{className:"wb-prof-row","data-gated":e.gated?"true":void 0,"data-testid":"agent-profile-tool",children:[n.jsxs("span",{className:"wb-prof-row-main",children:[n.jsx("span",{className:"wb-prof-row-name mono",children:h6(e.name)}),n.jsx("span",{className:"wb-prof-row-desc","data-clamp":"true",title:e.description,children:e.description})]}),e.gated?n.jsxs("span",{className:"wb-prof-gate",title:"The call is recorded and waits; nothing happens until you approve it.",children:[n.jsx(rT,{}),"Needs your approval"]}):n.jsx("span",{className:"wb-prof-auto",title:d6(e.tier),children:u6(e.tier)})]})}function u6(e){return e==="auto"?"Runs on its own":e==="gated"?"Needs your approval":"Not runnable here"}function d6(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 h6(e){const t=e.split(".");return(t[t.length-1]??e).replace(/_/g," ")}function f6(e){return e==="mirror"?"Mirrors whichever language you write in":e==="en"?"Always English":e==="fr"?"Always French":e}function jo({title:e,note:t,tone:s,children:r}){return n.jsxs("section",{className:"wb-prof-section",children:[n.jsx("h3",{className:"wb-prof-title",children:e}),t?n.jsx("p",{className:"wb-prof-note-lead","data-tone":s,children:t}):null,r]})}function wo({label:e,children:t}){return n.jsxs(n.Fragment,{children:[n.jsx("dt",{className:"wb-prof-k",children:e}),n.jsx("dd",{className:"wb-prof-v",children:t})]})}function Km({children:e,title:t}){return n.jsx("span",{className:"wb-prof-tag",title:t,children:e})}function rT(){return n.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:[n.jsx("rect",{x:"2.8",y:"6",width:"8.4",height:"6.2",rx:"1.4"}),n.jsx("path",{d:"M4.8 6V4.4a2.2 2.2 0 0 1 4.4 0V6"})]})}const i0=16e3,m6=10*6e4,p6="The microphone is blocked for this page: allow it in the browser’s site settings to talk.",iT="This browser cannot record here: talking needs a microphone and a secure page (https or localhost).";function g6(){const e=window;return e.AudioContext??e.webkitAudioContext}function x6(e){const t=e&&typeof e=="object"&&"name"in e?String(e.name):"";return t==="NotAllowedError"||t==="SecurityError"||t==="PermissionDeniedError"?p6:t==="NotFoundError"||t==="DevicesNotFoundError"?"No microphone was found on this computer.":t==="NotReadableError"?"The microphone is in use by another app.":iT}async function v6(e){var c;const t=g6();if(!((c=navigator.mediaDevices)!=null&&c.getUserMedia)||!t)throw Object.assign(new Error(iT),{name:"Unsupported"});const s=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),r=new t,i=r.createMediaStreamSource(s),a=r.createScriptProcessor(4096,1,1),l=[];a.onaudioprocess=u=>{const h=u.inputBuffer.getChannelData(0);l.push(new Float32Array(h));let f=0;for(let m=0;m<h.length;m++)f+=h[m]*h[m];e(Math.min(1,Math.sqrt(f/h.length)*6))},i.connect(a),a.connect(r.destination),r.state==="suspended"&&await r.resume().catch(()=>{});const o=()=>{a.onaudioprocess=null;try{i.disconnect(),a.disconnect()}catch{}s.getTracks().forEach(u=>u.stop()),r.close().catch(()=>{})};return{async stop(){const u=r.sampleRate;return o(),y6(w6(j6(l),u,i0),i0)},cancel:o}}function j6(e){const t=new Float32Array(e.reduce((r,i)=>r+i.length,0));let s=0;for(const r of e)t.set(r,s),s+=r.length;return t}function w6(e,t,s){if(t<=s)return e;const r=t/s,i=new Float32Array(Math.floor(e.length/r));for(let a=0;a<i.length;a++){const l=Math.floor(a*r),o=Math.min(e.length,Math.floor((a+1)*r));let c=0;for(let u=l;u<o;u++)c+=e[u];i[a]=o>l?c/(o-l):0}return i}function y6(e,t){const s=new ArrayBuffer(44+e.length*2),r=new DataView(s),i=(a,l)=>{for(let o=0;o<l.length;o++)r.setUint8(a+o,l.charCodeAt(o))};i(0,"RIFF"),r.setUint32(4,36+e.length*2,!0),i(8,"WAVEfmt "),r.setUint32(16,16,!0),r.setUint16(20,1,!0),r.setUint16(22,1,!0),r.setUint32(24,t,!0),r.setUint32(28,t*2,!0),r.setUint16(32,2,!0),r.setUint16(34,16,!0),i(36,"data"),r.setUint32(40,e.length*2,!0);for(let a=0;a<e.length;a++){const l=Math.max(-1,Math.min(1,e[a]));r.setInt16(44+a*2,Math.round(l<0?l*32768:l*32767),!0)}return new Blob([s],{type:"audio/wav"})}const cx="buddi.readAloud";function aT(){try{return window.localStorage.getItem(cx)==="on"}catch{return!1}}function lT(e){try{e?window.localStorage.setItem(cx,"on"):window.localStorage.removeItem(cx)}catch{}}let ir=null,Uo=null,Cc=0,ux=null;const dx=new Set;function fh(e){ux!==e&&(ux=e,dx.forEach(t=>t()))}function b6(){return ux}function k6(e){return dx.add(e),()=>dx.delete(e)}function oT(e){return Ql(),fh(e),Cc}function a0(e){return e===Cc}function Ql(){Cc++,ir&&(ir.pause(),ir.removeAttribute("src")),Uo&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(Uo),Uo=null,fh(null)}async function N6(e,t,s=null){var i;const r=oT(s);try{const a=await fetch(e,{credentials:"same-origin"});if(!a.ok)throw new Error(`The spoken reply could not be fetched (${a.status}).`);const l=new Blob([await a.arrayBuffer()],{type:t});if(r!==Cc)return;ir||(ir=new Audio,(i=ir.addEventListener)==null||i.call(ir,"ended",()=>fh(null))),Uo=URL.createObjectURL(l),ir.src=Uo,await ir.play()}catch(a){throw r===Cc&&fh(null),a}}const S6=new Set(["audio/ogg","audio/mpeg","audio/mp4","audio/wav","audio/x-wav","audio/webm"]);function nw(e){return S6.has(e.toLowerCase().split(";")[0].trim())}function l0(e){if(e===null||!Number.isFinite(e)||e<0)return"–:––";const t=Math.floor(e);return`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`}function sw({artifactId:e,name:t,mime:s,sizeBytes:r}){const i=d.useRef(null),a=d.useRef(null),[l,o]=d.useState(!1),[c,u]=d.useState(!1),[h,f]=d.useState(!1),[m,p]=d.useState(0),[g,v]=d.useState(null);d.useEffect(()=>()=>{var x;(x=i.current)==null||x.pause(),a.current&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(a.current)},[]);const b=async()=>{const x=i.current;if(x){if(l){x.pause();return}Ql(),f(!1);try{if(!a.current){u(!0);const w=await fetch(Ti(e),{credentials:"same-origin"});if(!w.ok)throw new Error(String(w.status));a.current=URL.createObjectURL(new Blob([await w.arrayBuffer()],{type:s})),x.src=a.current}await x.play()}catch{f(!0)}finally{u(!1)}}},j=h?"Could not play. Download it instead.":`${l0(m)} / ${l0(g)}`;return n.jsxs("span",{className:"wb-audio","data-testid":"audio-card","data-playing":l?"true":void 0,children:[n.jsx("button",{type:"button",className:"ui-icon-btn wb-audio-play","data-size":"sm","aria-label":l?`Pause ${t}`:`Play ${t}`,disabled:c,onClick:()=>void b(),children:n.jsx(ce,{name:l?"pause":"play",size:14})}),n.jsxs("span",{className:"wb-file-text",children:[n.jsx("span",{className:"wb-file-name",title:t,children:t}),n.jsxs("span",{className:"wb-file-meta","data-testid":"audio-time",children:[c?"Loading…":j,!h&&qn(r)?` · ${qn(r)}`:""]})]}),n.jsx("a",{className:"ui-icon-btn wb-audio-download","data-size":"sm",href:Ti(e),download:t,"aria-label":`Download ${t}`,title:"Download",children:n.jsx(ce,{name:"download",size:14})}),n.jsx("audio",{ref:i,preload:"none",onPlay:()=>o(!0),onPause:()=>o(!1),onEnded:()=>{o(!1),p(0)},onTimeUpdate:x=>p(x.currentTarget.currentTime),onLoadedMetadata:x=>v(Number.isFinite(x.currentTarget.duration)?x.currentTarget.duration:null),onDurationChange:x=>v(Number.isFinite(x.currentTarget.duration)?x.currentTarget.duration:null)})]})}const Vm=1e5,Gm=200,qm=30;function cT({artifactId:e,filename:t,mime:s,family:r,available:i=!0}){const[a,l]=d.useState(!1);return i?r==="image"&&!a?n.jsx("figure",{className:"file-preview file-preview-image",children:n.jsx("img",{src:Yr(e),alt:t??"Image",onError:()=>l(!0)})}):r==="audio"&&nw(s)?n.jsx("div",{className:"file-preview file-preview-audio",children:n.jsx(sw,{artifactId:e,name:t??"Audio",mime:s})}):r==="pdf"?n.jsx("div",{className:"file-preview file-preview-pdf",children:n.jsx("object",{data:Yr(e),type:"application/pdf","aria-label":t??"PDF",children:n.jsx(V,{children:"Your browser cannot show this PDF here. Download it to open it."})})}):r==="text"||r==="code"||r==="table"?n.jsx(C6,{artifactId:e,filename:t,mime:s,family:r}):n.jsx(V,{children:"Preview not supported for this kind of file. Download it to open it."}):n.jsx(V,{children:"The file is no longer available; its record is kept."})}function C6({artifactId:e,filename:t,mime:s,family:r}){const[i,a]=d.useState("loading");if(d.useEffect(()=>{let o=!1;return a("loading"),fetch(Yr(e),{credentials:"same-origin"}).then(async c=>{if(!c.ok)throw new Error(String(c.status));const u=await c.text();o||a({text:u.slice(0,Vm),truncated:c.headers.get("X-Preview-Truncated")==="1"||u.length>Vm})}).catch(()=>{o||a("failed")}),()=>{o=!0}},[e]),i==="loading")return n.jsx("div",{className:"file-preview",children:n.jsx(pe,{children:"Loading preview…"})});if(i==="failed")return n.jsx(V,{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(t??""));return n.jsxs("div",{className:"file-preview",children:[l?n.jsx(A6,{text:i.text,delimiter:/tab|\.tsv$/i.test(s+(t??""))?" ":","}):n.jsx("pre",{className:"file-preview-text",children:i.text}),i.truncated?n.jsxs("p",{className:"muted",children:["Showing the first ",Vm.toLocaleString()," characters. The download has the whole file."]}):null]})}function E6(e,t,s,r){const i=[];let a=[],l="",o=!1,c=!1,u=!1;const h=()=>{a.length<r?a.push(l):c=!0,l=""},f=()=>{h(),i.push(a),a=[]};let m=0;for(;m<e.length;m+=1){if(i.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===t){h();continue}if(p!=="\r"){if(p===`
95
+ `){f();continue}l+=p}}return i.length<s&&(l!==""||a.length>0)&&f(),{rows:i,truncatedRows:u,truncatedCols:c}}function A6({text:e,delimiter:t}){const s=d.useMemo(()=>E6(e,t,Gm+1,qm),[e,t]),[r,...i]=s.rows;if(!r)return n.jsx("p",{className:"muted",children:"The file is empty."});const a=Math.min(qm,s.rows.reduce((o,c)=>Math.max(o,c.length),0)),l=Array.from({length:a},(o,c)=>c);return n.jsxs("div",{className:"ui-table-wrap file-preview-table",children:[n.jsxs("table",{className:"ui-table",children:[n.jsx("thead",{children:n.jsx("tr",{children:l.map(o=>n.jsx("th",{children:r[o]??""},o))})}),n.jsx("tbody",{children:i.slice(0,Gm).map((o,c)=>n.jsx("tr",{children:l.map(u=>n.jsx("td",{children:o[u]??""},u))},c))})]}),s.truncatedRows||s.truncatedCols?n.jsxs("p",{className:"muted",children:["Showing the first ",Gm," rows",s.truncatedCols?` and ${qm} columns`:"",". The download has the whole file."]}):null]})}function T6(e,t){const s=e.toLowerCase().split(";")[0].trim(),r=(t??"").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 $6(e,t){return`/api/artifacts/${encodeURIComponent(e)}/export/${t}`}function R6(e,t){return`${(e??"document").replace(/\.[a-z0-9]{1,8}$/i,"")||"document"}.${t}`}function o0(e,t){const s=document.createElement("a");s.href=e,s.download=t,s.rel="noopener",document.body.appendChild(s),s.click(),s.remove()}function uT({artifactId:e,filename:t,mime:s,accent:r=!0}){const i=t??"download",a=T6(s,t),l=r?"accent":void 0;if(a.length===0)return n.jsx("a",{className:"ui-btn","data-variant":l,href:Ti(e),download:i,children:"Download"});const o=a.filter(h=>!h.asWritten),c=a.filter(h=>h.asWritten),u=h=>({label:h.label,hint:h.hint,onSelect:()=>h.asWritten?o0(Ti(e),i):o0($6(e,h.format),R6(t,h.format))});return n.jsx(Ys,{label:`Download ${i}`,note:"Download as",items:[...o.map(u),"separator",...c.map(u)],trigger:n.jsxs("button",{type:"button",className:"ui-btn","data-variant":l,"aria-label":`Download ${i}`,children:["Download ",n.jsx(ce,{name:"chevron-down"})]})})}function I6({attachment:e}){const t=Qj(e.mime,e.filename);return n.jsxs("div",{className:"wb-artifact","data-family":t,"data-testid":"artifact-view",children:[n.jsx(cT,{artifactId:e.artifactId,filename:e.filename??null,mime:e.mime,family:t}),n.jsxs("dl",{className:"ui-kv",children:[n.jsx("dt",{children:"Type"}),n.jsxs("dd",{children:[ia[t],n.jsx("span",{className:"wb-artifact-mime mono",children:e.mime})]}),e.sizeBytes?n.jsxs(n.Fragment,{children:[n.jsx("dt",{children:"Size"}),n.jsx("dd",{children:qn(e.sizeBytes)})]}):null,n.jsx("dt",{children:"Id"}),n.jsx("dd",{className:"mono",children:e.artifactId})]}),n.jsx("div",{className:"ui-toolbar","data-align":"end",children:n.jsx(uT,{artifactId:e.artifactId,filename:e.filename,mime:e.mime})})]})}const c0=80,P6=["query","path","url","dir"],M6=["message","task"];function rw(e,t){const s=D6(t);if(!s)return null;const r=Fa(s.command);if(r!==null){const l=Fa(s.name);return Wu(l===null?r:`${l}: ${r}`)}for(const l of P6){const o=Fa(s[l]);if(o!==null)return Wu(o)}const i=Fa(s.action);if(i!==null){const l=M6.map(o=>Fa(s[o])).find(o=>o!==null)??null;return Wu(l===null?i:`${i} · ${l}`)}const a=Object.values(s).filter(l=>typeof l=="string");return a.length===1?Wu(Fa(a[0])):null}function Fa(e){if(typeof e!="string")return null;const t=e.replace(/\s+/g," ").trim();return t===""?null:t}function Wu(e){return e===null?null:e.length>c0?`${e.slice(0,c0-1)}…`:e}function D6(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const dT="owner.notify",$r=e=>typeof e=="string"&&e.trim()!==""?e:null;function O6(e){const t=e!==null&&typeof e=="object"?e:{};return{title:$r(t.title)??"(no title)",text:$r(t.text),urgency:$r(t.urgency)??"now",key:$r(t.key),link:$r(t.link)}}function hT(e){if(e===null||typeof e!="object")return $r(e);const t=e;return $r(t.delivered)??$r(t.message)??$r(t.error)}function L6(e,t){if(!t||!e)return"critical";const s=e.toLowerCase();return/^(refused|not sent)/.test(s)?"critical":/^sent\b/.test(s)?"good":"warning"}const F6="mission.report",_a=e=>typeof e=="string"&&e.trim()!==""?e.trim():null,_6=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function z6(e,t){const s=e!==null&&typeof e=="object"?e:{},r=t!==null&&typeof t=="object"?t:{},i=_a(r.link),a=r.audio!==null&&typeof r.audio=="object"?r.audio:null,l=a?_a(a.fileId):null,o=a?_a(a.mime):null;return{text:_a(s.text),link:i&&i.startsWith("#/")?{route:i,label:_a(r.linkLabel)??"Open"}:null,audio:l&&_6.test(l)&&o&&nw(o)?{fileId:l,mime:o,filename:a?_a(a.filename):null,sizeBytes:a&&typeof a.sizeBytes=="number"?a.sizeBytes:null}:null}}function U6({view:e}){return!e.text&&!e.audio?null:n.jsxs("div",{className:"wb-report","data-testid":"mission-report",children:[e.audio?n.jsx(sw,{artifactId:e.audio.fileId,name:e.audio.filename??"Voice note",mime:e.audio.mime,sizeBytes:e.audio.sizeBytes}):null,e.text?n.jsx("div",{className:"wb-bubble","data-rich":"true",children:n.jsx(Ws,{text:e.text})}):null,e.link?n.jsx("a",{className:"ui-btn wb-report-link","data-size":"sm",href:e.link.route,children:e.link.label}):null]})}const $i="agent.delegate";function B6(e){if(e===null||typeof e!="object")return null;const t=e,s=t.conversationId;if(typeof s!="string"||s==="")return null;const r=t.agentId??t.agent;return{conversationId:s,agentId:typeof r=="string"?r:"",runId:typeof t.runId=="string"?t.runId:null}}function W6(e){if(typeof e=="string")return e;if(e===null||typeof e!="object")return null;const t=e.text;return typeof t=="string"?t:null}const hx="canvas.show",u0="canvas.clear",d0=12;function H6(e){return`sources:${e}`}function K6(e){return e.role==="user"&&(e.blocks??[]).some(t=>t.type==="text"&&t.text.trim()!=="")}function pl(e){return`${e.plugin}/${e.name}`}function V6(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;const t=e.diff;return typeof t=="string"&&t.trim()!==""}function G6({messages:e,descriptors:t}){const s=new Map(t.filter(a=>a.renderer==="preview").map(a=>[a.tool,a]));if(s.size===0)return[];const r=new Map,i=[];for(const a of e)for(const l of a.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=MA(o,fx(l.output)).props;c.target===null&&c.awaiting!==null&&i.push({...c.awaiting,at:a.at??null})}return i}function q6({messages:e,descriptors:t,awaiting:s,folded:r,served:i,gathered:a}){var m;const l=new Map(t.map(p=>[p.tool,p])),o=new Map;let c=[],u=0,h=null;const f=p=>{h||(h={id:H6(p.id),tool:p.tool,title:"Sources",renderer:"sources",source:"sources",props:{entries:[]},at:p.at,substantial:!1,count:0},c.push(h));const g=h.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))];h.props={entries:v},h.tool=b.join(" · "),h.count=v.length,h.substantial=v.some(j=>j.ok===!0),h.tone=v.every(j=>j.ok===!1)?"critical":void 0};for(const p of e){K6(p)&&(h=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}),a!=null&&a.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===hx){const S=J6(g.id,g.input,p.at??null);S&&c.push(S)}if(g.name===u0&&(c=[],h=null),g.name===$i){const S=B6(g.input);S&&c.push({id:g.id,tool:$i,title:"Delegation",renderer:"delegate",props:{...S,result:null},at:p.at??null,source:"delegate",substantial:!0})}continue}if(g.type!=="tool_result"||g.name===hx||g.name===u0)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:W6(g.ok?g.output:g.error??g.output),...g.ok&&lh(g.output).length>0?{files:lh(g.output)}:{}}},g.ok||(x.tone="critical");continue}const w=g.approval?px(g):(s==null?void 0:s.get(g.toolUseId))??px(g);if(w){c.push({id:g.toolUseId,tool:j,title:"Approval",renderer:"envelope",props:{approvalId:w},at:b,tone:"warning",source:"approval",substantial:!0});continue}if(r!=null&&r.has(j))continue;if(a!=null&&a.has(j)){f({id:g.toolUseId,tool:j,input:(v==null?void 0:v.input)??null,output:fx(g.output)??null,ok:g.ok!==!1,...g.error===void 0?{}:{error:g.error},at:b});continue}if(j===dT){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 y=fx(g.output);if(g.ok===!1){c.push({id:g.toolUseId,tool:j,title:fr(j),renderer:"structured",props:{value:g.error??y??null,failed:!0},at:b,tone:"critical",source:"fallback",substantial:!1});continue}V6(y)&&(u+=1);const k=l.get(j);if(k){const S=MA(k,y),{renderer:C}=S;let{props:E}=S;if(C==="preview"){const R=E,I=R.target??(R.awaiting&&(i!=null&&i.has(pl(R.awaiting)))?R.awaiting:null);if(I===null)continue;E={...R,target:I,awaiting:null};const L=pl(I);c=c.filter(F=>!(F.source==="descriptor"&&F.renderer==="preview"&&F.props.target!==null&&pl(F.props.target)===L))}c.push({id:g.toolUseId,tool:j,title:k.title??fr(j),renderer:C,props:E,at:b,source:"descriptor",substantial:mx(C,E)});continue}const N={value:Zj(y)?{input:v==null?void 0:v.input,output:y}:y};Q6("structured",N)&&c.push({id:g.toolUseId,tool:j,title:fr(j),renderer:"structured",props:N,at:b,source:"fallback",substantial:mx("structured",N)})}}for(const p of c)p.source==="descriptor"&&p.renderer==="preview"&&(p.props={...p.props,changes:u});return Y6(c)}const h0="forAgent";function fx(e){if(e===null||typeof e!="object"||Array.isArray(e)||!(h0 in e))return e;const{[h0]:t,...s}=e;return s}function Y6(e){if(e.length<=d0)return e;const t=e.length-d0;return[...e.slice(0,t).filter(r=>r.source==="approval"),...e.slice(t)]}function J6(e,t,s){if(t===null||typeof t!="object")return null;const{renderer:r,title:i,data:a}=t,l=typeof r=="string"&&hh(r)?r:"structured";return{id:e,tool:hx,title:typeof i=="string"&&i.trim()!==""?i:"Shown",renderer:l,props:l==="structured"&&!hh(String(r))?{value:a}:a,at:s,substantial:!0,source:"canvas"}}function Q6(e,t){const s=t??{};return!!(s.failed===!0||mx(e,t)||Xj(s.value).kind==="error")}function mx(e,t){const s=t??{};switch(e){case"timeseries":return yo(s.points)>0;case"bars":return yo(s.bars)>0;case"keyvalue":return yo(s.pairs)>0;case"tiles":return s.notice!==!0&&yo(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(i=>yo(i.rows)>0);default:return Zj(s.value)?!0:s.failed===!0?!1:R3(s.value)}}function yo(e){return Array.isArray(e)?e.length:0}function px(e){if(e.approval)return e.approval.state==="pending"?e.approval.id:null;for(const t of[e.error,e.output]){const s=mT(t,0);if(s)return s}return null}function X6(e,t,s={}){var o,c;const r=e.flatMap(u=>u.blocks),i=r.find(u=>u.type==="tool_use"&&u.id===t);if((i==null?void 0:i.type)!=="tool_use")return null;const a=r.find(u=>u.type==="tool_result"&&u.toolUseId===t),l=(o=s.redactInputOf)!=null&&o.has(i.name)?fT(i.input):i.input;return{id:t,tool:i.name,title:fr(i.name),renderer:"structured",props:{value:{input:l,...(a==null?void 0:a.type)==="tool_result"?{status:((c=a.approval)==null?void 0:c.state)??(a.ok?"completed":"failed"),output:a.output,...a.error?{error:a.error}:{}}:{status:"Awaiting result"}}},at:null,source:"fallback",substantial:!1}}const Z6=new Set(["value","text","password","secret","code"]);function fT(e){if(e===null||typeof e!="object"||Array.isArray(e))return e;const t={};for(const[s,r]of Object.entries(e))t[s]=Z6.has(s)&&typeof r=="string"?"— withheld —":fT(r);return t}function mT(e,t){if(t>3||e===null||typeof e!="object")return null;const s=e,r=s.reason,i=s.actionId??s.approvalId;if(typeof i=="string"&&i!==""&&(r===void 0||r==="approval-required"))return i;for(const a of Object.values(s)){const l=mT(a,t+1);if(l)return l}return null}function fr(e){const t=e.split(".");return t.length===1?kn(e):t.map(s=>kn(s)).join(" · ")}function f0(e,t){return e.find(s=>s.source==="sources"&&s.props.entries.some(r=>r.id===t))??null}function Cf({name:e,mime:t,sizeBytes:s,thumbnail:r,state:i,error:a,onOpen:l,onRemove:o,size:c="md"}){const u=Qj(t,e),h=[ia[u],qn(s)].filter(Boolean).join(" · "),f=n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"wb-file-visual","data-family":u,children:r?n.jsx("img",{src:r,alt:""}):n.jsx(iw,{family:u})}),n.jsxs("span",{className:"wb-file-text",children:[n.jsx("span",{className:"wb-file-name",title:e,children:e}),n.jsx("span",{className:"wb-file-meta",children:i==="uploading"?"Uploading…":i==="failed"?"Upload failed":h})]})]});return n.jsxs("span",{className:"wb-file","data-size":c,"data-state":i,"data-thumb":r?"true":void 0,title:i==="failed"?a:void 0,children:[l?n.jsx("button",{type:"button",className:"wb-file-open",onClick:l,"aria-label":`Open ${e}`,children:f}):n.jsx("span",{className:"wb-file-open",children:f}),o?n.jsx("button",{type:"button",className:"wb-file-x","aria-label":`Remove ${e}`,onClick:o,children:n.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:n.jsx("path",{d:"M2.5 2.5l5 5M7.5 2.5l-5 5"})})}):null]})}function iw({family:e}){const t={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 n.jsxs("svg",{...t,children:[n.jsx("rect",{x:"3",y:"4",width:"14",height:"12",rx:"2"}),n.jsx("circle",{cx:"7.5",cy:"8.5",r:"1.4"}),n.jsx("path",{d:"M17 13l-3.6-3.6a1 1 0 0 0-1.4 0L6 15.5"})]});case"pdf":return n.jsxs("svg",{...t,children:[n.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"}),n.jsx("path",{d:"M11.5 2.5V7H16"}),n.jsx("path",{d:"M7.5 13.5h5M7.5 11h5"})]});case"table":return n.jsxs("svg",{...t,children:[n.jsx("rect",{x:"3",y:"4",width:"14",height:"12",rx:"1.5"}),n.jsx("path",{d:"M3 8.5h14M3 12.5h14M8 4v12M13 4v12"})]});case"text":return n.jsxs("svg",{...t,children:[n.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"}),n.jsx("path",{d:"M11.5 2.5V7H16"}),n.jsx("path",{d:"M7.5 10.5h5M7.5 13.5h3.5"})]});case"code":return n.jsx("svg",{...t,children:n.jsx("path",{d:"M7 6l-4 4 4 4M13 6l4 4-4 4M11.5 4l-3 12"})});case"audio":return n.jsx("svg",{...t,children:n.jsx("path",{d:"M4 8v4M7.5 5.5v9M11 3.5v13M14.5 6.5v7M18 8.5v3"})});case"video":return n.jsxs("svg",{...t,children:[n.jsx("rect",{x:"3",y:"5",width:"10",height:"10",rx:"1.5"}),n.jsx("path",{d:"M13 9l4-2.5v7L13 11"})]});case"archive":return n.jsxs("svg",{...t,children:[n.jsx("rect",{x:"4",y:"3",width:"12",height:"14",rx:"1.5"}),n.jsx("path",{d:"M10 3v3M10 8v2M10 12v2M8.5 14h3"})]});default:return n.jsxs("svg",{...t,children:[n.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"}),n.jsx("path",{d:"M11.5 2.5V7H16"})]})}}function eB(e,t,s){const r=p0(e),i=p0(t==null?void 0:t.input),a=Ki(r==null?void 0:r.name)??iB(Ki(r==null?void 0:r.handle))??Ki(r==null?void 0:r.agent)??Ki(i==null?void 0:i.agent),l=typeof e=="string"?e.trim()||null:Ki(r==null?void 0:r.text)??Ki(r==null?void 0:r.note),o=m0(r==null?void 0:r.durationMs)??m0(r==null?void 0:r.elapsedMs),c=t!=null&&t.at?Date.parse(t.at):NaN,u=s?Date.parse(s):NaN,h=Number.isFinite(c)&&Number.isFinite(u)&&u>=c?u-c:null;return{who:a,question:Ki(i==null?void 0:i.task),answer:l,files:lh(e),durationMs:o??h}}function tB(e,t){var r;let s=null;for(const i of e)for(const a of i.blocks??[])a.type==="tool_result"&&a.name===$i&&((r=a.delegation)==null?void 0:r.approvalId)===t&&(s=a.toolUseId);if(s===null)return null;for(const i of e)for(const a of i.blocks??[])if(a.type==="tool_use"&&a.id===s)return{input:a.input,at:i.at||null};return null}function nB({block:e,messages:t,answeredAt:s}){const r=eB(e.output,tB(t,e.actionId),s),i=[r.who?`Asked ${r.who}`:null,r.durationMs===null?null:`took ${sB(r.durationMs)}`].filter(a=>a!==null);return n.jsxs("div",{className:"wb-delegation-result","data-testid":"delegation-result",children:[i.length>0?n.jsx("p",{className:"wb-delegation-facts",children:i.join(" · ")}):null,r.question?n.jsx("blockquote",{className:"wb-delegation-question",children:r.question}):null,r.answer?n.jsx("div",{className:"wb-delegation-answer","data-testid":"delegation-answer",children:n.jsx(Ws,{text:r.answer})}):n.jsx("p",{className:"wb-delegation-facts",children:"No answer came back."}),r.files.length>0?n.jsx("div",{className:"wb-msg-files",role:"list","aria-label":`Files ${r.who??"the colleague"} made`,children:r.files.map(a=>n.jsx("a",{role:"listitem",href:Ti(a.artifactId),download:!0,children:n.jsx(Cf,{name:a.filename??"Untitled file",mime:a.mime,sizeBytes:a.sizeBytes,thumbnail:Jj(a.mime)?Yr(a.artifactId):null,size:"sm"})},a.artifactId))}):null,n.jsx(Tt,{summary:"Raw JSON",children:n.jsx("pre",{className:"wb-approval-output mono",children:rB(e.output)})})]})}function sB(e){if(e<1e3)return`${Math.round(e)}ms`;const t=Math.round(e/1e3);if(t<60)return`${t}s`;const s=Math.floor(t/60);return s<60?`${s}m ${String(t%60).padStart(2,"0")}s`:`${Math.floor(s/60)}h ${String(s%60).padStart(2,"0")}m`}function rB(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function iB(e){return e===null?null:`@${e.replace(/^@/,"")}`}function Ki(e){return typeof e=="string"&&e.trim()!==""?e:null}function m0(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function p0(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const aB=1e3;function lB({messageId:e,text:t,onReadAloud:s}){const[r,i]=d.useState(!1),a=d.useRef(null),l=d.useSyncExternalStore(k6,b6)===e;d.useEffect(()=>()=>{a.current&&clearTimeout(a.current)},[]);const o=()=>{var c;(c=navigator.clipboard)==null||c.writeText(t).then(()=>{i(!0),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>i(!1),aB)},()=>{})};return n.jsxs("div",{className:"wb-reply-actions","data-testid":"reply-actions",children:[n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":r?"Copied":"Copy",title:r?"Copied":"Copy",onClick:o,children:n.jsx(ce,{name:r?"check":"copy",size:14})}),r?n.jsx("span",{className:"wb-reply-copied",role:"status",children:"Copied"}):null,s?n.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?Ql():s(e,t),children:n.jsx(ce,{name:l?"stop":"play",size:14})}):null]})}function oB(e){const t=cB(e);if(!t)return null;const s=Ym(t.diff);if(s!==null)return{kind:"diff",diff:s};const r=Ym(t.command),i=Ym(t.plain),a=Jm(t.exitCode);return r!==null&&(i!==null||a!==null||Jm(t.pid)!==null)?{kind:"command",command:r,output:i,exitCode:a,elapsedMs:Jm(t.elapsedMs)}:null}function Ym(e){return typeof e=="string"&&e.trim()!==""?e:null}function Jm(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function cB(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const g0="offer:",pT="owner:interjection";function uB(e){return e===pT}function dB(e){if(typeof e!="string"||!e.startsWith(g0))return null;const t=e.slice(g0.length).trim();return t===""?null:t}const x0="brief:";function hB(e){if(typeof e!="string"||!e.startsWith(x0))return null;const t=e.slice(x0.length).trim();return t===""?null:t}function aw({messages:e,live:t,now:s,onOpen:r,working:i=!1,partial:a=null,agents:l,agentId:o,speakers:c,coordinatorId:u,workingAs:h,onOpenFile:f,onReadAloud:m,children:p,agentName:g,emptyHint:v,empty:b,plain:j=!1,workingLine:x,runs:w,onContinue:y}){var _;const k=d.useRef(null);d.useEffect(()=>{var X;(X=k.current)==null||X.scrollIntoView({block:"end"})},[e.length,t.length,i,a==null?void 0:a.text.length,a==null?void 0:a.thinking.length,!!p]);const N=a&&!a.settled&&(a.text!==""||a.thinking!==""),S=e.filter(X=>(X.blocks??[]).some(NB)).map(gT),C=bB(S,w??[]),E=c??l??[],R=X=>(o&&!c?E.find(Q=>Q.id===o):void 0)??E.find(Q=>Q.name===X)??null,I=o?E.find(X=>X.id===o)??null:null,L=i||t.length>0,F=L||!!N,T=!!N&&a.text!=="",M=L&&!T,P=S.at(-1),D=(P==null?void 0:P.role)!=="assistant"||!!h,O=h??g??"Assistant",H=S.filter((X,Q)=>{var ee;return Q===0||(c?(((ee=S[Q-1])==null?void 0:ee.speaker)??null)!==(X.speaker??null):S[Q-1].role!==X.role)}),B=F&&!D?((_=H.at(-1))==null?void 0:_.id)??null:null,Y=(w??[]).reduce((X,Q)=>X===null||(Q.startedAt??"")>(X.startedAt??"")?Q:X,null),W=(w??[]).some(X=>X.finishedAt===null),q=y&&!F&&!W&&P&&(Y==null?void 0:Y.stopped)==="max_turns"&&C.get(P.id)===Y?P.id:null;return n.jsx(RA.Provider,{value:l??c??[],children:n.jsxs("div",{className:"wb-messages","data-testid":"messages",children:[S.length===0&&t.length===0?b??n.jsx("p",{className:"wb-chat-empty",children:v}):null,S.map((X,Q)=>{const ee=X.speaker??null,fe=c?ee==="owner"||ee===null&&X.role==="user":X.role==="user",Le=c&&ee==="room",Ie=c&&ee&&ee!=="owner"&&ee!=="room"?c.find(be=>be.id===ee)??null:null,_e=S[Q-1],U=Q===0||(c?((_e==null?void 0:_e.speaker)??null)!==ee:_e.role!==X.role);if(Le)return n.jsx("div",{className:"wb-msg wb-msg-room","data-role":"room",children:(X.blocks??[]).filter(be=>be.type==="text").map((be,Be)=>n.jsx("span",{children:be.text},Be))},X.id);const ie=(X.blocks??[]).filter(be=>be.type==="approval_result");if(ie.length>0)return n.jsx("div",{className:"wb-msg","data-role":"assistant","data-testid":"approval-result",children:ie.map((be,Be)=>n.jsx(SB,{block:be,messages:e,at:X.at||null},Be))},X.id);const J=X.role==="user"&&uB(ee),ye=X.role==="user"?hB(ee):null;if(ye)return n.jsx("div",{className:"wb-msg","data-role":"user","data-testid":"offer-turn",children:n.jsx("div",{className:"wb-bubble wb-bubble-offer",children:ye})},X.id);const ge=X.role==="user"?dB(ee):null;if(ge){const be=(X.blocks??[]).filter(Be=>Be.type==="text").map(Be=>Be.text).join(`
96
+ `);return n.jsx("div",{className:"wb-msg","data-role":"user","data-testid":"offer-turn",children:n.jsx("div",{className:"wb-bubble wb-bubble-offer",title:be,children:ge})},X.id)}const $e=c&&Ie&&X.role==="user"?vB(X):null;if($e){const be=S.slice(Q+1).find(at=>at.role==="assistant"&&at.speaker&&at.speaker!==Ie.id),Be=be!=null&&be.speaker?c.find(at=>at.id===be.speaker):void 0;return n.jsxs("details",{className:"wb-msg wb-msg-room wb-msg-ask","data-role":"room",children:[n.jsxs("summary",{children:[Ie.name," asked ",(Be==null?void 0:Be.name)??"a member",$e.request?`: ${$e.request.length>120?`${$e.request.slice(0,119)}…`:$e.request}`:""]}),$e.request?n.jsx("p",{children:$e.request}):null]},X.id)}const De=C.get(X.id)??null,Je=yB(X,e),Ue=!fe&&!J&&!j?wB(X):"";return n.jsxs("div",{className:"wb-msg","data-role":fe||J?"user":"assistant",children:[J?n.jsx("div",{className:"wb-msg-added","data-testid":"added-while-working",children:"added while working"}):null,U&&!fe&&!J?n.jsx(v0,{name:Ie?Ie.name:c&&ee&&ee!=="owner"&&ee!=="room"?ee:g??"Assistant",face:Ie??I??R(g),moving:M&&B===X.id,children:Ie&&u===Ie.id?n.jsx("span",{className:"wb-msg-role",children:"coordinator"}):null}):null,Je.length>0?n.jsx("div",{className:"wb-msg-files",role:"list","aria-label":"Files sent with this message",children:Je.map(be=>n.jsx("span",{role:"listitem",children:nw(be.mime)?n.jsx(sw,{artifactId:be.artifactId,name:be.filename??"Untitled file",mime:be.mime,sizeBytes:be.sizeBytes}):n.jsx(Cf,{name:be.filename??"Untitled file",mime:be.mime,sizeBytes:be.sizeBytes,thumbnail:Jj(be.mime)?Yr(be.artifactId):null,...f?{onOpen:()=>f(be)}:{}})},be.artifactId))}):null,(X.blocks??[]).map((be,Be)=>{const at=pB(X.blocks??[],Be,e);if(at==="inside")return null;if(at)return n.jsx(gB,{refusals:at.refusals},Be);if(be.type==="thinking")return j||be.text.trim()===""?null:n.jsx(gx,{text:be.text},Be);if(be.type==="text")return be.text.trim()===""?null:fe?n.jsx("div",{className:"wb-bubble",children:be.text},Be):n.jsx("div",{className:"wb-bubble","data-rich":"true",children:n.jsx(Ws,{text:be.text})},Be);if(be.type==="attachment")return null;if(be.type==="tool_use"){if(j)return null;const He=lw(e,be.id),kt=He?AB(He):null,Yt=!kt&&be.name===dT&&He?hT(He.output):null,ne=!kt&&be.name===F6&&(He!=null&&He.ok)?z6(be.input,He.output):null;return n.jsxs(d.Fragment,{children:[n.jsx(xx,{label:kt&&!(He!=null&&He.delegation)?`Approval · ${be.name}`:fr(be.name),tool:be.name,ok:(He==null?void 0:He.ok)??null,running:He===null,...kt?{status:kt.status,waiting:kt.waiting,approval:!0}:Yt?{status:Yt}:{},gist:rw(be.name,be.input),body:He?oB(He.output):null,opens:!0,onOpen:()=>r(be.id)},Be),ne?n.jsx(U6,{view:ne}):null]},Be)}return null}),De?n.jsxs("div",{className:"wb-msg-budget","data-testid":"budget-stop",children:[n.jsx("span",{children:kB(De)}),q===X.id?n.jsx(A,{size:"sm",className:"wb-msg-budget-continue","data-testid":"budget-continue",onClick:y,children:"Continue"}):null]}):null,X.feedback&&!fe&&!J?n.jsx(RB,{feedback:X.feedback}):null,Ue!==""?n.jsx(lB,{messageId:X.id,text:Ue,onReadAloud:m}):null]},X.id)}),F?n.jsxs("div",{className:"wb-msg","data-role":"assistant","data-testid":"live-turn",children:[D?n.jsx(v0,{name:O,face:R(O)??I,moving:M}):null,N&&a.thinking!==""&&!j?n.jsx(gx,{text:a.thinking,live:a.text==="",seconds:xB(a.thinkingStartedAt,a.textStartedAt??s)}):null,T?n.jsxs("div",{className:"wb-bubble","data-live":"true","data-rich":"true",children:[n.jsx(Ws,{text:a.text}),n.jsx("span",{className:"wb-caret","aria-hidden":"true"})]}):null,i&&t.length===0&&!N?n.jsxs("span",{className:"wb-working",role:"status","aria-live":"polite","data-testid":"working",children:[x??`${h??g??"The agent"} is working`,n.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]})]}):null,t.map(X=>n.jsx(xx,{label:fr(X.name),tool:X.name,ok:null,running:!0,elapsed:Math.max(0,Math.round((s-X.startedAt)/1e3)),opens:!1,onOpen:()=>r(X.toolUseId)},X.toolUseId))]}):null,p,n.jsx("div",{ref:k})]})})}function v0({name:e,face:t,moving:s=!1,children:r}){const i=(t==null?void 0:t.picture)??null,a=AA(s?i:null);return n.jsxs("div",{className:"wb-msg-who","data-testid":"turn-head",children:[n.jsx("span",{className:"wb-msg-mark","data-moving":s?a&&i?"blob":"ring":void 0,children:s&&a&&i?n.jsx(Qc,{state:"working",size:"sm",still:i,className:"wb-msg-blob"}):n.jsx(Sn,{id:(t==null?void 0:t.id)??e,name:(t==null?void 0:t.name)??e,unavailable:t?!t.available:!1,...t?{face:t}:{}})}),n.jsx("span",{children:e}),r]})}function fB(e){var t,s;return((s=(t=/ may delegate to ([^;]*);/.exec(e)??/\(allowed: ([^)]*)\)/.exec(e))==null?void 0:t[1])==null?void 0:s.trim())||null}const mB="delegation refused:";function pB(e,t,s){const r=a=>{const l=e[a];if(!l||l.type!=="tool_use"||l.name!==$i)return null;const o=lw(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(mB))return null;const u=l.input??{};return{target:typeof u.agent=="string"&&u.agent!==""?u.agent:"a colleague",message:c}};if(!r(t))return null;if(r(t-1))return"inside";const i=[];for(let a=t;;a+=1){const l=r(a);if(!l)break;i.push(l)}return i.length<2?null:{refusals:i}}function gB({refusals:e}){const[t,s]=d.useState(!1),r=e.map(o=>fB(o.message)).find(o=>o!==null)??null,i=e.map(o=>o.target),a=i.slice(0,3),l=`Delegation refused ${e.length} times: ${a.join(", ")}${i.length>a.length?", …":""}`+(r?` (allowed: ${r})`:"");return n.jsxs("div",{className:"wb-refusals","data-testid":"delegation-refusals","data-open":t||void 0,children:[n.jsxs("button",{type:"button",className:"wb-tool","data-ok":!1,"aria-expanded":t,onClick:()=>s(o=>!o),children:[n.jsx("span",{className:"wb-tool-mark","data-ok":"false","aria-hidden":"true"}),n.jsx("span",{className:"wb-tool-label",children:l}),n.jsx(ce,{name:"arrow",className:"wb-tool-arrow"})]}),t?n.jsx("div",{className:"wb-refusals-list",children:e.map((o,c)=>n.jsxs("div",{className:"wb-refusal",children:[n.jsxs("span",{className:"wb-tool","data-static":"true","data-ok":!1,children:[n.jsx("span",{className:"wb-tool-mark","data-ok":"false","aria-hidden":"true"}),n.jsxs("span",{className:"wb-tool-label",children:[fr($i)," · ",o.target]}),n.jsx("span",{className:"wb-tool-elapsed",children:"refused"})]}),n.jsx("p",{className:"wb-refusal-why",children:o.message})]},c))}):null]})}function xB(e,t){return e===null?null:Math.max(0,Math.round((t-e)/1e3))}function gx({text:e,live:t=!1,seconds:s=null}){const[r,i]=d.useState(!1),a=t?`Thinking${s!==null&&s>0?` · ${s}s`:""}`:s!==null&&s>0?`Thought for ${s}s`:"Thoughts";return n.jsxs("div",{className:"wb-thought","data-live":t||void 0,"data-open":r||void 0,children:[n.jsxs("button",{type:"button",className:"wb-thought-toggle","aria-expanded":r,onClick:()=>i(l=>!l),children:[t?n.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]}):n.jsx(ce,{name:"thought"}),n.jsx("span",{children:a}),n.jsx(ce,{name:"arrow",className:"wb-tool-arrow"})]}),r?n.jsx("div",{className:"wb-thought-text",children:n.jsx(Ws,{text:e})}):null]})}function vB(e){var r;const t=((r=(e.blocks??[]).find(i=>i.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(t);return s?{handle:s[1],request:s[2].trim()}:null}function gT(e){const t=e.blocks??[];if(e.role!=="assistant"||t.length<2)return e;const s=[];let r=!1;for(const i of t){const a=s[s.length-1];i.type==="text"&&(a==null?void 0:a.type)==="text"?(s[s.length-1]={...a,text:a.text+jB(a.text,i.text)+i.text},r=!0):s.push(i)}return r?{...e,blocks:s}:e}function jB(e,t){return e===""||t===""||/\s$/.test(e)||/^\s/.test(t)||/^[.,;:!?)\]}»”’'"]/.test(t)?"":/[.!?:…)"”»]$/.test(e)?`
97
+
98
+ `:""}function wB(e){return(gT(e).blocks??[]).filter(t=>t.type==="text").map(t=>t.text.trim()).filter(t=>t!=="").join(`
99
+
100
+ `)}function yB(e,t){const s=[],r=new Set,i=a=>{r.has(a.artifactId)||(r.add(a.artifactId),s.push(a))};for(const a of e.blocks??[])if(a.type==="attachment"&&i(a),a.type==="tool_use"&&a.name===$i){const l=lw(t,a.id);l!=null&&l.ok&&lh(l.output).forEach(i)}return s}function bB(e,t){const s=t.filter(l=>l.startedAt!==null&&l.finishedAt!==null),r=(l,o)=>o.at!==""&&o.at>=l.startedAt&&o.at<=l.finishedAt,i=(l,o)=>l!==o&&l.startedAt>=o.startedAt&&l.finishedAt<=o.finishedAt&&(l.startedAt>o.startedAt||l.finishedAt<o.finishedAt),a=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=>i(c,l)&&r(c,o))||a.has(o.id)||a.set(o.id,l)}return a}function kB(e){if(e.stopped==="max_tokens")return"Length limit reached · answer cut off";const t=e.turns;return t===null?"Turn budget reached":`Turn budget reached · ${t} ${t===1?"step":"steps"}`}function NB(e){return e.type==="text"||e.type==="thinking"?e.text.trim()!=="":e.type==="tool_use"||e.type==="attachment"||e.type==="approval_result"}function SB({block:e,messages:t,at:s}){const[r,i]=d.useState(!1),a=e.state==="succeeded";return n.jsxs("div",{className:"wb-approval","data-open":r||void 0,children:[n.jsxs("button",{type:"button",className:"wb-tool","data-ok":a,"aria-expanded":r,onClick:()=>i(l=>!l),children:[n.jsx("span",{className:"wb-tool-mark","data-ok":a?"true":"false","aria-hidden":"true"}),n.jsx("span",{className:"wb-tool-label",children:e.name===""?"Approved action":fr(e.name)}),n.jsx("span",{className:"wb-tool-elapsed",children:e.state}),n.jsx(ce,{name:"arrow",className:"wb-tool-arrow"})]}),r&&e.name===$i?n.jsx(nB,{block:e,messages:t,answeredAt:s}):null,r&&e.name!==$i?n.jsx("pre",{className:"wb-approval-output mono",children:CB(e.output)}):null]})}function CB(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}const EB=40;function AB(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(px(e))return{status:"waiting",waiting:!0};const t=(r=e.approval)==null?void 0:r.state;return t?t==="approved"||t==="executing"?{status:"approved",waiting:!0}:t==="succeeded"?{status:"approved",waiting:!1}:{status:t,waiting:!1}:null}function xx({label:e,tool:t,ok:s,running:r,elapsed:i,opens:a,onOpen:l,status:o,waiting:c=!1,approval:u=!1,gist:h=null,body:f=null}){const[m,p]=d.useState(!1),g=n.jsxs(n.Fragment,{children:[r?n.jsx("span",{className:"wb-pulse","aria-hidden":"true"}):n.jsx("span",{className:"wb-tool-mark","data-ok":c?"pending":s===!1?"false":"true","aria-hidden":"true"}),n.jsx("span",{className:"wb-tool-label",children:e}),h?n.jsx("span",{className:"wb-tool-gist mono","data-testid":"tool-gist",children:h}):null,i===void 0?null:n.jsxs("span",{className:"wb-tool-elapsed",children:[i,"s"]}),o||s===!1?n.jsx("span",{className:"wb-tool-elapsed",children:o??"failed"}):null]}),v={"data-ok":s===null?void 0:s,"data-running":r,"data-gist":h?!0:void 0,"data-approval":u||void 0};return f?n.jsxs("div",{className:"wb-toolcall","data-open":m||void 0,children:[n.jsxs("div",{className:"wb-tool","data-split":"true",...v,children:[n.jsxs("button",{type:"button",className:"wb-tool-toggle","aria-expanded":m,onClick:()=>p(b=>!b),children:[n.jsx(ce,{name:"chevron",className:"wb-tool-chevron"}),g]}),a?n.jsxs(hc,{children:[n.jsx(fc,{asChild:!0,children:n.jsx("button",{type:"button",className:"wb-tool-open","aria-label":"Open on the canvas",onClick:l,children:n.jsx(ce,{name:"arrow",className:"wb-tool-arrow"})})}),n.jsx(mc,{children:n.jsxs(pc,{className:"ui-tip",sideOffset:6,children:[n.jsx("span",{className:"ui-tip-title",children:"Open on the canvas"}),n.jsx("span",{className:"ui-tip-hint mono",children:t})]})})]}):null]}),m?n.jsx(TB,{body:f,onOpen:a?l:null}):null]}):a?n.jsxs(hc,{children:[n.jsx(fc,{asChild:!0,children:n.jsxs("button",{className:"wb-tool",...v,onClick:l,children:[g,n.jsx(ce,{name:"arrow",className:"wb-tool-arrow"})]})}),n.jsx(mc,{children:n.jsxs(pc,{className:"ui-tip",sideOffset:6,children:[n.jsx("span",{className:"ui-tip-title",children:"Open on the canvas"}),n.jsx("span",{className:"ui-tip-hint mono",children:t})]})})]}):n.jsx("span",{className:"wb-tool","data-static":"true",...v,children:g})}function TB({body:e,onOpen:t}){const s=t?{label:"Open on the canvas",onClick:t}:void 0;if(e.kind==="diff")return n.jsx("div",{className:"wb-tool-body","data-kind":"diff","data-testid":"tool-body",children:n.jsx(sh,{text:e.diff,limit:EB,...s?{more:s}:{}})});const r=[e.exitCode===null?null:`exit ${e.exitCode}`,e.elapsedMs===null?null:$B(e.elapsedMs)].filter(i=>i!==null);return n.jsxs("div",{className:"wb-tool-body","data-kind":"command","data-testid":"tool-body",children:[n.jsxs("div",{className:"wb-tool-command",children:[n.jsx("code",{className:"mono",children:e.command}),r.length>0?n.jsx("span",{className:"wb-tool-facts","data-failed":e.exitCode!==null&&e.exitCode!==0?!0:void 0,children:r.join(" · ")}):null]}),e.output?n.jsx("pre",{className:"wb-tool-output",children:e.output}):null]})}function $B(e){return e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(1)}s`}function lw(e,t){for(const s of e)for(const r of s.blocks??[])if(r.type==="tool_result"&&r.toolUseId===t)return r;return null}function RB({feedback:e}){const t=e.source==="telegram"?"on Telegram":`on ${e.source}`;return n.jsxs("div",{className:"wb-msg-feedback","data-value":e.value,"data-testid":"message-feedback",title:`You reacted ${e.emoji} ${t}`,children:[n.jsx("span",{className:"wb-msg-feedback-emoji","aria-label":`You reacted ${e.emoji} ${t}`,children:e.emoji}),n.jsx("span",{children:t}),e.note?n.jsxs("span",{className:"wb-msg-feedback-note",children:["“",e.note,"”"]}):null]})}const xT="approval-dock";function IB(){var t;const e=document.getElementById(xT);e&&((t=e.scrollIntoView)==null||t.call(e,{block:"nearest"}),e.focus())}const PB=["workspace","cwd","workdir","root"];function MB({approvals:e,timezone:t,now:s,version:r,onDecided:i,onSay:a,onOpenFull:l}){const[o,c]=d.useState([]),u=e.filter(m=>!o.includes(m.approvalId)),h=u[0];if(!h)return null;const f=m=>c(p=>p.includes(m)?p:[...p,m]);return n.jsx(DB,{item:h,count:u.length,timezone:t,now:s,version:r,onSettled:m=>{f(h.approvalId),m&&i(m)},onSay:a,onOpenFull:()=>l(h.toolUseId)},h.approvalId)}function DB({item:e,count:t,timezone:s,now:r,version:i,onSettled:a,onSay:l,onOpenFull:o}){var C;const[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(null),[g,v]=d.useState("");d.useEffect(()=>{let E=!1;return $.approval(e.approvalId).then(R=>{E||(u(R),R.state!=="pending"&&a(R))}).catch(R=>{E||f(R instanceof ve?R.message:String(R))}),()=>{E=!0}},[e.approvalId,i]);const b=c!==null&&c.state==="pending"&&Date.parse(c.expiresAt)<=r;d.useEffect(()=>{b&&c&&a({...c,state:"expired"})},[b]);const{values:j,controls:x}=qj(c==null?void 0:c.choices),w=(E,R)=>{const I=g.trim();p(E),f(null),(j&&E==="approve"?$.decide(e.approvalId,E,R,j):$.decide(e.approvalId,E,R)).then(L=>{a(L.action),I&&l(I)}).catch(L=>{f(L instanceof ve?L.message:String(L)),p(null)})},y=m!==null||c===null||c.state!=="pending",k=((C=c==null?void 0:c.permissionScopes)==null?void 0:C.includes("always"))??!1,N=c?rw(c.tool,c.canonicalArgs)??LB(c.preview):null,S=c?OB(c):null;return n.jsxs("section",{id:xT,tabIndex:-1,className:"wb-question","data-kind":"approval","aria-label":"Approval needed","data-testid":"approval-dock",children:[n.jsxs("div",{className:"wb-question-head",children:[n.jsx("span",{className:"wb-question-kicker",children:"Needs your OK"}),t>1?n.jsxs("span",{className:"wb-dock-count","data-testid":"approval-dock-count",children:["1 of ",t]}):null,n.jsx("strong",{children:c?fr(c.tool):"Loading the request…"}),e.askedBy?n.jsx("span",{className:"wb-dock-asker","data-testid":"approval-dock-asker",children:e.askedBy}):null]}),N||S?n.jsxs("div",{className:"wb-dock-section wb-dock-subject",children:[N?n.jsx("code",{className:"wb-dock-gist",children:N}):null,S?n.jsxs("span",{className:"wb-dock-where",children:["in ",n.jsx("span",{className:"mono",children:S})]}):null]}):null,x?n.jsx("div",{className:"wb-dock-section",children:x}):null,n.jsx(re,{message:h}),n.jsx("div",{className:"wb-dock-section",children:n.jsx("input",{className:"wb-dock-instead",value:g,onChange:E=>v(E.target.value),onKeyDown:E=>{E.key==="Enter"&&E.preventDefault()},placeholder:"Tell the agent what to do instead (optional)","aria-label":"Tell the agent what to do instead (optional)",disabled:m!==null})}),n.jsxs("div",{className:"wb-dock-section wb-dock-actions",children:[n.jsxs("span",{className:"wb-dock-meta",children:[c?n.jsxs(n.Fragment,{children:["Expires ",nt(c.expiresAt,s)," · "]}):null,n.jsx("button",{type:"button",className:"wb-link",onClick:o,children:"See the full request on the Canvas"})]}),n.jsx(A,{variant:"ghost",size:"sm",disabled:y,onClick:()=>w("reject"),children:m==="reject"?"Rejecting…":"Reject"}),k?n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",size:"sm",disabled:y,onClick:()=>w("approve","conversation"),children:"Auto: this conversation"}),n.jsx(A,{size:"sm",disabled:y,onClick:()=>w("approve","always"),children:"Always: this agent"})]}):null,n.jsx(A,{variant:"good",size:"sm",disabled:y,onClick:()=>w("approve"),children:m==="approve"?"Approving…":k?"Allow once":"Approve"})]})]})}function OB(e){for(const t of[e.canonicalArgs,e.envelope])if(!(t===null||typeof t!="object"||Array.isArray(t)))for(const s of PB){const r=t[s];if(typeof r=="string"&&r.trim()!=="")return r.trim()}return null}function LB(e){const t=(e??"").split(`
101
+ `).map(s=>s.trim()).find(Boolean);return t?t.length>160?`${t.slice(0,157)}…`:t:null}const FB=2e3;function _B({conversationId:e,agentId:t,runId:s=null,result:r=null,waiting:i=null,agents:a=[]}){const l=r!==null,[o,c]=d.useState(l),u=!o||i!==null,{data:h,error:f}=de(()=>Ve.conversation(e),[e,o,(i==null?void 0:i.approvalId)??null],u?FB:void 0),m=(h==null?void 0:h.runs)??[],p=s===null?null:m.find(y=>y.runId===s)??null,g=l||i===null&&(s!==null?p!==null&&p.finishedAt!==null:m.length>0&&m.every(y=>y.finishedAt!==null));d.useEffect(()=>{g&&c(!0)},[g]);const v=r?r.ok?"done":"failed":i!=null&&i.approvalId?"waiting":g?"done":"working",b=a.find(y=>y.id===t)??null,j=(b==null?void 0:b.name)??(h==null?void 0:h.agentId)??t,x=(h==null?void 0:h.messages)??[],w=(r==null?void 0:r.text)??zB(x);return n.jsxs("div",{className:"wb-delegate","data-testid":"delegate-view","data-status":v,children:[n.jsxs("header",{className:"wb-delegate-head",children:[n.jsx(cn,{agents:a,id:t}),n.jsxs("div",{className:"wb-delegate-who",children:[n.jsx("strong",{children:j}),n.jsx("span",{className:"wb-delegate-status","data-status":v,role:"status",children:v==="working"?n.jsxs(n.Fragment,{children:["Working",n.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]})]}):v==="waiting"?"Waiting for your approval":v==="failed"?"Failed":"Done"})]})]}),f?n.jsx("p",{className:"muted",children:f}):null,n.jsx("div",{className:"wb-delegate-work",children:x.map((y,k)=>n.jsx("div",{className:"wb-delegate-turn",children:(y.blocks??[]).map((N,S)=>{if(N.type==="thinking")return N.text.trim()===""?null:n.jsx(gx,{text:N.text},S);if(N.type==="tool_use"){const C=BB(UB(x,N.id));return n.jsx(xx,{label:fr(N.name),tool:N.name,ok:C.ok,running:C.running,waiting:C.waiting,status:C.status,gist:rw(N.name,N.input),opens:!1,onOpen:()=>{}},S)}return null})},y.id??k))}),w?n.jsx("div",{className:"wb-delegate-answer","data-testid":"delegate-answer",children:n.jsx(Ws,{text:w})}):v==="working"||v==="waiting"?n.jsxs("p",{className:"muted",children:[j," has not answered yet."]}):null,r!=null&&r.files&&r.files.length>0?n.jsx("div",{className:"wb-msg-files",role:"list","aria-label":`Files ${j} made`,"data-testid":"delegate-files",children:r.files.map(y=>n.jsx("a",{role:"listitem",href:Ti(y.artifactId),download:!0,children:n.jsx(Cf,{name:y.filename??"Untitled file",mime:y.mime,sizeBytes:y.sizeBytes,thumbnail:Jj(y.mime)?Yr(y.artifactId):null})},y.artifactId))}):null,n.jsxs("div",{className:"wb-delegate-actions",children:[v==="waiting"?n.jsx(A,{variant:"accent",onClick:()=>IB(),"data-testid":"delegate-to-approval",children:"Go to the approval"}):null,n.jsx("a",{className:"ui-btn",href:st(t||(h==null?void 0:h.agentId)||"",e),children:"Open this conversation"})]})]})}function zB(e){for(let t=e.length-1;t>=0;t-=1){const s=e[t];if(s.role!=="assistant")continue;const r=(s.blocks??[]).filter(i=>i.type==="text").map(i=>i.text.trim()).filter(i=>i!=="").join(`
102
+
103
+ `);if(r!=="")return r}return null}function UB(e,t){for(const s of e)for(const r of s.blocks??[])if(r.type==="tool_result"&&r.toolUseId===t)return r;return null}function BB(e){var s;if(e===null)return{running:!0,ok:null,waiting:!1,status:void 0};const t=(s=e.approval)==null?void 0:s.state;return t==="pending"?{running:!1,ok:null,waiting:!0,status:"waiting approval"}:t==="approved"||t==="executing"?{running:!0,ok:null,waiting:!1,status:"running"}:t==="succeeded"?{running:!1,ok:!0,waiting:!1,status:void 0}:t?{running:!1,ok:!1,waiting:!1,status:t}:{running:!1,ok:e.ok,waiting:!1,status:void 0}}const j0=1024*1024;function WB({files:e,agentId:t,root:s,revision:r}){const[i,a]=d.useState({kind:"dir",path:""});return d.useEffect(()=>a({kind:"dir",path:""}),[e.plugin,t]),n.jsx("div",{className:"wb-files","data-testid":"files-view",children:i.kind==="dir"?n.jsx(HB,{files:e,agentId:t,root:s,path:i.path,revision:r,go:a}):n.jsx(KB,{files:e,agentId:t,root:s,path:i.path,revision:r,go:a})})}function vT({root:e,path:t,go:s}){const r=t===""?[]:t.split("/"),i=[{label:e,path:""},...r.map((a,l)=>({label:a,path:r.slice(0,l+1).join("/")}))];return n.jsx("nav",{className:"wb-files-crumbs","aria-label":"Where you are in the workspace",children:i.map((a,l)=>{const o=l===i.length-1;return n.jsxs("span",{className:"wb-files-crumb",children:[l>0?n.jsx("span",{className:"wb-files-sep","aria-hidden":"true",children:"/"}):null,o?n.jsx("span",{className:"wb-files-here mono","aria-current":"location",children:a.label}):n.jsx("button",{type:"button",className:"wb-files-step mono",onClick:()=>s({kind:"dir",path:a.path}),children:a.label})]},a.path)})})}function HB({files:e,agentId:t,root:s,path:r,revision:i,go:a}){const[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(!1),[m,p]=d.useState(null);d.useEffect(()=>{let b=!1;return u(null),$.pageQuery(e.plugin,e.list,{agent:t,...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,t,r,i]),d.useEffect(()=>p(null),[r]);const g=async()=>{f(!0),p(null);try{const b=await fetch($.pageFileUrl(e.plugin,e.archive,{agent:t,...r?{path:r}:{}}),{credentials:"same-origin"});if(!b.ok){const y=await b.json().catch(()=>null);p((y==null?void 0:y.error)??"The archive could not be made.");return}const j=await b.blob(),x=URL.createObjectURL(j),w=document.createElement("a");w.href=x,w.download=`${r===""?s:r.split("/").at(-1)}.zip`,w.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 n.jsxs(n.Fragment,{children:[n.jsxs(ae,{children:[n.jsx(vT,{root:s,path:r,go:a}),n.jsx(ht,{}),n.jsx(A,{size:"sm",onClick:()=>void g(),disabled:h||v===null||v.length===0,children:h?"Packing…":"Download as archive"})]}),m?n.jsx(V,{tone:"warning",role:"alert",children:m}):null,c?n.jsx(V,{tone:"critical",role:"alert",children:c}):null,v===null?c?null:n.jsx(pe,{children:"Reading the folder…"}):v.length===0?n.jsx(pe,{children:r===""?n.jsxs(n.Fragment,{children:["Nothing in this workspace yet. To hand the agent a file, add it to the ",n.jsx("a",{href:qr,children:"Files library"})," and mention it here."]}):"This folder is empty."}):n.jsx(rt,{children:v.map(b=>n.jsx(et,{href:"#",onClick:()=>a({kind:b.kind,path:b.path}),lead:n.jsx(GB,{kind:b.kind}),title:n.jsxs("span",{className:"mono",children:[b.name,b.kind==="dir"?"/":""]}),side:b.kind==="file"?qn(b.bytes):void 0},b.path))}),l&&l.path===r&&(l.skipped>0||l.truncated)?n.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 KB({files:e,agentId:t,root:s,path:r,revision:i,go:a}){const[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(!1);d.useEffect(()=>{let j=!1;return u(null),$.pageQuery(e.plugin,e.stat,{agent:t,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,t,r,i]);const m=l&&l.path===r?l:null,p=m?`${m.bytes}-${Math.round(m.mtimeMs)}`:"",g=m?$.pageFileUrl(e.plugin,e.read,{agent:t,path:r,v:p}):"",v=$.pageFileUrl(e.plugin,e.read,{agent:t,path:r,download:"1"}),b=(m==null?void 0:m.type)==="text"&&m.bytes<=j0;return n.jsxs(n.Fragment,{children:[n.jsxs(ae,{children:[n.jsx(vT,{root:s,path:r,go:a}),n.jsx(ht,{}),b?n.jsx(A,{size:"sm","aria-pressed":h,onClick:()=>f(j=>!j),children:"Wrap"}):null,n.jsx(dt,{size:"sm",href:v,download:(m==null?void 0:m.name)??r.split("/").at(-1),children:"Download"})]}),c?n.jsx(V,{tone:"critical",role:"alert",children:c}):null,m===null?c?null:n.jsx(pe,{children:"Reading the file…"}):m.type==="image"?n.jsx("figure",{className:"wb-files-picture",children:n.jsx("img",{src:g,alt:m.name})}):m.type==="pdf"?n.jsx("div",{className:"file-preview file-preview-pdf",children:n.jsx("object",{data:g,type:"application/pdf","aria-label":m.name,children:n.jsx(V,{children:"Your browser cannot show this PDF here. Download it to open it."})})}):b?n.jsx(VB,{src:g,wrap:h}):n.jsxs(n.Fragment,{children:[n.jsx(V,{children:m.type==="text"?`This file is over ${qn(j0)}, too long to read here. Download it to open it.`:"This kind of file is not shown here. Download it to open it."}),n.jsx(Gt,{items:[{label:"Size",value:qn(m.bytes)},{label:"Type",value:n.jsx("span",{className:"mono",children:m.mime})}]})]})]})}function VB({src:e,wrap:t}){const[s,r]=d.useState(null),[i,a]=d.useState(!1);return d.useEffect(()=>{let l=!1;return a(!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||a(!0)}),()=>{l=!0}},[e]),i?n.jsx(V,{tone:"critical",children:"The file could not be read."}):s===null?n.jsx(pe,{children:"Reading the file…"}):s===""?n.jsx(pe,{children:"This file is empty."}):n.jsx("pre",{className:"wb-files-text","data-wrap":t?"true":void 0,"data-testid":"files-text",children:s})}function GB({kind:e}){return n.jsx("span",{className:"wb-files-icon","data-kind":e,"aria-hidden":"true",children:n.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"?n.jsx("path",{d:"M2 4.2h4.2l1.4 1.6H14v7H2z"}):n.jsx("path",{d:"M4 2.4h5l3 3v8.2H4zM9 2.4v3h3"})})})}function qB({input:e,output:t,ok:s}){const r=O6(e),i=hT(t)??(s?"sent":"not sent");return n.jsxs("div",{className:"wb-envelope",children:[n.jsxs("div",{className:"envelope",children:[n.jsxs("dl",{className:"envelope-head",children:[n.jsx("dt",{children:"To"}),n.jsx("dd",{className:"wb-envelope-action",children:"You"}),n.jsx("dt",{children:"Status"}),n.jsx("dd",{children:n.jsx(we,{tone:L6(i,s),dot:!0,children:i})})]}),n.jsxs("div",{className:"envelope-body",children:[n.jsx("strong",{children:r.title}),r.text?`
104
+
105
+ ${r.text}`:null]})]}),n.jsx(Tt,{summary:"The call",children:n.jsxs("dl",{className:"ui-kv wb-envelope-fields",children:[n.jsx("dt",{children:"Urgency"}),n.jsx("dd",{children:r.urgency}),r.link?n.jsxs(n.Fragment,{children:[n.jsx("dt",{children:"Link"}),n.jsx("dd",{className:"mono",children:r.link})]}):null,r.key?n.jsxs(n.Fragment,{children:[n.jsx("dt",{children:"Key"}),n.jsx("dd",{className:"mono",children:r.key})]}):null]})})]})}const To=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)?e:{},Ot=e=>typeof e=="string"&&e.trim()!==""?e:null,YB={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 JB(e){const t=e.slice(0,4e3);if(t.length<20)return!1;let s=0;for(const r of t){const i=r.codePointAt(0);(i===65533||i<32&&i!==9&&i!==10&&i!==13||i>=127&&i<160)&&(s+=1)}return s/t.length>.1}function Qm(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function QB(e){if(!e)return null;try{const t=new URL(e);return t.protocol==="http:"||t.protocol==="https:"?t.href:null}catch{return null}}function vx(e){try{const t=new URL(e);return`${t.hostname.replace(/^www\./,"")}${t.pathname.replace(/\/+$/,"")}${t.search}`}catch{return e}}function w0(e){var t;return((t=e.match(/[\p{L}\p{N}]/u))==null?void 0:t[0])??"?"}function jT(e){const t=To(e.input),s=To(e.output),r={input:e.input,...e.ok===null?{status:"Awaiting result"}:{output:e.output},...e.error===void 0?{}:{error:e.error}},i=e.ok===!1,a=Ot(e.error)??Ot(To(e.error).message);if(Array.isArray(s.results)||Ot(t.query)&&!Ot(t.url)){const f=(Array.isArray(s.results)?s.results:[]).map(p=>To(p)).flatMap(p=>{const g=Ot(p.url);return g?[{title:Ot(p.title)??Qm(g),url:g,host:Ot(p.source)??Qm(g),snippet:Ot(p.snippet)}]:[]}),m=s.available===!1;return{kind:"search",id:e.id,raw:r,query:Ot(s.query)??Ot(t.query)??"",state:e.ok===null?"pending":i||m?"failed":"ok",provider:Ot(s.provider),results:f,why:i?`The search failed${a?`: ${a}`:"."}`:m?Ot(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=Ot(s.url)??Ot(t.url)??"",o=!i&&s.ok!==!1&&JB(Ot(s.text)??""),c=i||s.ok===!1||o,u=o?"unreadable":Ot(s.problem),h=Ot(s.message);return{kind:"page",id:e.id,url:l,raw:r,host:Ot(s.source)??Qm(l),state:e.ok===null?"pending":c?"failed":"ok",title:Ot(s.title),text:o?null:Ot(s.text),truncated:s.truncated===!0,retrievedAt:Ot(s.retrievedAt)??e.at,why:c?(u&&YB[u])??(h?h.charAt(0).toUpperCase()+h.slice(1)+(/[.!?]$/.test(h)?"":"."):null)??`The read failed${a?`: ${a}`:"."}`:null}}function XB(e){const t=e.entries.map(jT),s=t.filter(i=>i.kind==="search").length,r=t.length-s;return[s?`${s} ${s===1?"search":"searches"}`:null,r?`${r} ${r===1?"page":"pages"}`:null].filter(Boolean).join(" · ")}function ZB(e){return e.split(/\s+/).filter(Boolean).length}function e5(e){return e>=1e3?`${(e/1e3).toFixed(1).replace(/\.0$/,"")}k words`:`${e} ${e===1?"word":"words"}`}function t5(e,t){if(!e)return null;const s=new Date(e);return Number.isNaN(s.getTime())?null:zt(s,t??Intl.DateTimeFormat().resolvedOptions().timeZone)}function wT({url:e,className:t,children:s}){const r=QB(e);return r?n.jsxs("a",{className:`wb-src-link ${t}`,href:r,target:"_blank",rel:"noopener noreferrer",children:[s,n.jsx("span",{className:"wb-src-out","aria-hidden":"true",children:"↗"})]}):n.jsx("span",{className:t,children:s})}function yT({value:e}){const[t,s]=d.useState(!1);return n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:"wb-src-quiet","data-raw":"","aria-expanded":t,onClick:()=>s(!t),children:t?"Hide JSON":"Raw JSON"}),t?n.jsx("pre",{className:"wb-src-raw",children:JSON.stringify(e,null,2)}):null]})}function n5({page:e,focused:t,timezone:s}){const[r,i]=d.useState(t),[a,l]=d.useState(!1),o=d.useRef(null);if(d.useEffect(()=>{var m,p;t&&(i(!0),(p=(m=o.current)==null?void 0:m.scrollIntoView)==null||p.call(m,{block:"nearest"}))},[t]),e.state==="pending")return n.jsx("li",{className:"wb-src-page","data-state":"pending",ref:o,children:n.jsxs("div",{className:"wb-src-row",children:[n.jsx("span",{className:"wb-src-tile","data-state":"pending","aria-hidden":"true",children:w0(e.host)}),n.jsxs("span",{className:"wb-src-head",children:[n.jsxs("span",{className:"wb-src-title",children:["Reading ",e.host,"…"]}),n.jsx("span",{className:"wb-src-meta",children:e.url})]}),n.jsx("span",{})]})});const c=e.state==="failed",u=e.text?ZB(e.text):0,h=t5(e.retrievedAt,s),f=[e.host,h?`read ${h}`:null,u?e5(u):null,u?`${Math.max(1,Math.round(u/230))} min read`:null].filter(Boolean).join(" · ");return n.jsxs("li",{className:"wb-src-page","data-open":r?"true":void 0,"data-state":e.state,ref:o,children:[n.jsxs("div",{className:"wb-src-row",children:[n.jsx("span",{className:"wb-src-tile","data-tone":c?"critical":void 0,"aria-hidden":"true",children:c?"!":w0(e.host)}),n.jsxs("span",{className:"wb-src-head",children:[c?n.jsxs("span",{className:"wb-src-title",children:["Couldn’t read ",e.host]}):n.jsx(wT,{url:e.url,className:"wb-src-title",children:e.title??e.host}),c?n.jsx("span",{className:"wb-src-why",children:e.why}):n.jsx("span",{className:"wb-src-meta",children:f})]}),n.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:()=>i(!r),children:n.jsx(ce,{name:"chevron"})})]}),r?n.jsxs("div",{className:"wb-src-body",children:[c?n.jsx("p",{className:"wb-src-note",children:e.url}):n.jsxs(n.Fragment,{children:[e.text?n.jsx("p",{className:"wb-src-text","data-clamped":a?void 0:"true",children:e.text}):n.jsx("p",{className:"wb-src-note",children:"The page had no text to read."}),e.truncated?n.jsx("p",{className:"wb-src-note",children:"Only the beginning of the page was read; it was longer than the limit."}):null]}),n.jsxs("div",{className:"wb-src-foot",children:[!c&&e.text?n.jsx("button",{type:"button",className:"wb-src-quiet",onClick:()=>l(!a),children:a?"Show less":"Show more"}):null,n.jsx(yT,{value:e.raw})]})]}):null]})}const y0=3;function s5({search:e,read:t,focused:s}){const[r,i]=d.useState(!1),a=d.useRef(null);d.useEffect(()=>{var c,u;s&&((u=(c=a.current)==null?void 0:c.scrollIntoView)==null||u.call(c,{block:"nearest"}))},[s]);const l=r?e.results:e.results.slice(0,y0),o=e.state==="pending"?"Searching…":[e.provider,e.state==="ok"?`${e.results.length} ${e.results.length===1?"result":"results"}`:null].filter(Boolean).join(" · ");return n.jsxs("div",{className:"wb-src-list","data-state":e.state,ref:a,children:[n.jsxs("div",{className:"wb-src-query",children:[n.jsxs("span",{className:"wb-src-query-text",children:["“",e.query,"”"]}),o?n.jsx("span",{className:"wb-src-query-meta",children:o}):null,n.jsx("span",{className:"wb-src-query-raw",children:n.jsx(yT,{value:e.raw})})]}),e.state==="failed"?n.jsx("p",{className:"wb-src-empty wb-src-why",children:e.why}):null,e.state==="ok"&&e.results.length===0?n.jsx("p",{className:"wb-src-empty",children:"No results."}):null,l.length>0?n.jsx("ol",{className:"wb-src-results",children:l.map(c=>n.jsxs("li",{className:"wb-src-result",children:[n.jsx(wT,{url:c.url,className:"wb-src-result-title",children:c.title}),n.jsx("span",{className:"wb-src-result-site",children:c.host}),c.snippet?n.jsx("p",{className:"wb-src-result-snippet",children:c.snippet}):null,t.has(vx(c.url))?n.jsx("span",{className:"wb-src-result-side",children:n.jsx(we,{tone:"good",children:"Read"})}):null]},c.url))}):null,e.results.length>y0?n.jsx("div",{className:"wb-src-more",children:n.jsx("button",{type:"button",className:"wb-src-quiet",onClick:()=>i(!r),children:r?"Show fewer":`Show all ${e.results.length}`})}):null]})}function r5({entries:e,focus:t,timezone:s}){const r=e.map(jT),i=r.filter(o=>o.kind==="page"),a=r.filter(o=>o.kind==="search"),l=new Set(i.filter(o=>o.state==="ok").flatMap(o=>{const c=e.find(h=>h.id===o.id),u=Ot(To(c==null?void 0:c.input).url);return[vx(o.url),...u?[vx(u)]:[]]}));return n.jsxs("div",{className:"wb-src",children:[i.length>0?n.jsxs("div",{className:"wb-src-group",children:[n.jsx("p",{className:"wb-src-kicker",children:"Read"}),n.jsx("ul",{className:"wb-src-list",children:i.map(o=>n.jsx(n5,{page:o,focused:t===o.id,timezone:s},o.id))})]}):null,a.length>0?n.jsxs("div",{className:"wb-src-group",children:[n.jsx("p",{className:"wb-src-kicker",children:"Searched"}),a.map(o=>n.jsx(s5,{search:o,read:l,focused:t===o.id},o.id))]}):null]})}const i5=3,a5=152,l5=104,o5=100,c5=2,b0=5;function u5({renderables:e,activeId:t,onActivate:s,timezone:r,onDecided:i,onChangeAgent:a,face:l,descriptors:o,grantedTools:c,agentName:u,maxTabs:h,browserPanel:f,agents:m,onClose:p,loading:g=!1}){const[v,b]=d5(h);if(e.length===0)return n.jsxs("div",{className:"wb-canvas","data-testid":"canvas",children:[n.jsx("div",{className:"wb-canvas-tabs",ref:v,"aria-hidden":"true",children:n.jsx("span",{className:"wb-canvas-label",children:"Canvas"})}),n.jsx("div",{className:"wb-canvas-body wb-canvas-body-empty",children:g?null:n.jsxs("div",{className:"wb-empty",children:[l?n.jsx("span",{className:"wb-empty-face",children:l}):null,n.jsx("p",{className:"ui-empty wb-empty-line",children:g5(u,x5(o??[],c??[]))})]})})]});const j=e.some(y=>y.id===t)?t:e[e.length-1].id,{shown:x,hidden:w}=h5(e,j,b);return n.jsx("div",{className:"wb-canvas","data-testid":"canvas",children:n.jsxs(g4,{value:j,onValueChange:s,className:"contents",children:[n.jsxs("div",{className:"wb-canvas-tabs",ref:v,children:[n.jsx("span",{className:"wb-canvas-label","aria-hidden":"true",children:"Canvas"}),n.jsx(x4,{className:"wb-tabstrip","aria-label":"Canvas",children:x.map(y=>n.jsxs("div",{className:"wb-tab-item",children:[n.jsxs(v4,{value:y.id,className:"wb-tab","data-tone":y.tone,onKeyDown:k=>{k.key==="Delete"&&p&&k0(y)&&(k.preventDefault(),p(y.id))},children:[y.tone==="warning"||y.tone==="critical"?n.jsx("span",{className:"wb-tab-dot","data-tone":y.tone,"aria-hidden":"true"}):null,n.jsx("span",{className:"wb-tab-text",children:y.title}),y.count?n.jsx("span",{className:"wb-tab-count",children:y.count}):null]}),p&&k0(y)?n.jsx("button",{className:"wb-tab-close","aria-label":`Close ${y.title} tab`,title:"Dismiss panel; keep conversation history",onClick:()=>p(y.id),children:"×"}):null]},y.id))}),n.jsx(f5,{items:w,onActivate:s,timezone:r})]}),e.map(y=>n.jsx(j4,{value:y.id,className:"wb-canvas-body","data-renderer":y.source==="descriptor"&&y.renderer==="preview"?"preview":void 0,"data-dense":j5.has(y.renderer)?"true":void 0,children:n.jsxs("section",{className:"ui-panel","data-flush":y.source==="descriptor"&&y.renderer==="preview"?"true":void 0,children:[y.source!=="browser"&&y.source!=="files"&&!(y.source==="descriptor"&&y.renderer==="preview")?n.jsxs("header",{className:"ui-panel-head",children:[n.jsx("h2",{className:"ui-panel-title",children:y.title}),n.jsx("span",{className:"ui-panel-tool mono",children:y.source==="sources"?XB(y.props):y.tool})]}):null,y.tone==="critical"?n.jsxs("p",{className:"muted",children:["Recorded tool failure",y.at?` · ${nt(y.at,Intl.DateTimeFormat().resolvedOptions().timeZone)}`:"",". This is history, not live session status."]}):null,y.source==="browser"?f:y.source==="profile"?n.jsx(a6,{...y.props,...a?{onChange:a}:{}}):y.source==="artifact"?n.jsx(I6,{...y.props}):y.source==="files"?n.jsx(WB,{...y.props}):y.source==="sources"?n.jsx(r5,{...y.props,timezone:r}):y.source==="notify"?n.jsx(qB,{...y.props}):y.source==="delegate"?n.jsx(_B,{...y.props,agents:m??[]}):n.jsx(i6,{renderer:y.renderer,props:y.props,timezone:r,onDecided:i})]})},y.id))]})})}function k0(e){return e.source==="approval"?!1:e.source==="browser"?e.pinned!==!0:e.source!=="files"}function d5(e){const[t,s]=d.useState(b0),r=d.useRef(null);return[d.useCallback(a=>{var o;if((o=r.current)==null||o.disconnect(),r.current=null,!a||e!==void 0||typeof ResizeObserver>"u")return;const l=()=>{const c=a.clientWidth;if(c===0)return;const u=Math.floor((c-o5-l5)/a5);s(Math.max(c5,Math.min(b0,u)))};l(),r.current=new ResizeObserver(l),r.current.observe(a)},[e]),e??t]}function h5(e,t,s){const r=new Set(e.filter(a=>a.id===t||a.source==="approval"||a.pinned===!0).map(a=>a.id)),i=new Set(r);for(let a=e.length-1;a>=0&&i.size<s;a-=1)i.add(e[a].id);return{shown:e.filter(a=>i.has(a.id)),hidden:e.filter(a=>!i.has(a.id))}}function f5({items:e,onActivate:t,timezone:s}){if(e.length===0)return null;const r=e.some(i=>i.tone==="critical")?"critical":e.some(i=>i.tone==="warning")?"warning":null;return n.jsxs(Hc,{modal:!1,children:[n.jsx(Kc,{asChild:!0,children:n.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?n.jsx("span",{className:"wb-tab-dot","data-tone":r,"aria-hidden":"true"}):null,n.jsxs("span",{className:"wb-tab-text",children:[e.length," more"]}),n.jsx(ce,{name:"chevron-down"})]})}),n.jsx(Gl,{children:n.jsxs(Vc,{className:"ui-menu","data-wide":"true",align:"end",sideOffset:6,children:[n.jsx(ma,{className:"ui-menu-label",children:"Earlier in this conversation"}),[...e].reverse().map(i=>n.jsxs(js,{className:"ui-menu-item",onSelect:()=>t(i.id),children:[n.jsxs("span",{className:"ui-menu-item-text",children:[i.tone==="warning"||i.tone==="critical"?n.jsx("span",{className:"wb-tab-dot","data-tone":i.tone,"aria-hidden":"true"}):null,i.title]}),n.jsx("span",{className:"ui-menu-note mono",children:m5(i.at,s)??i.tool})]},i.id))]})})]})}function m5(e,t){if(!e)return null;const s=new Date(e);return Number.isNaN(s.getTime())?null:zt(s,t)}const p5={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 g5(e,t){const s=e?`What ${e} shows you`:"What your agent shows you",r=[...new Set(t.map(i=>p5[i.renderer]??"results"))].slice(0,3);return r.length>0?`${s} lands here: ${r.join(", ")}.`:`${s} lands here.`}function x5(e,t){const s=new Set(t),r=new Set,i=e.filter(c=>{if(!s.has(c.tool))return!1;const u=v5(c);return r.has(u)?!1:(r.add(u),!0)}),a=new Set,l=i.filter(c=>a.has(c.renderer)?!1:(a.add(c.renderer),!0)),o=i.filter(c=>!l.includes(c));return[...l,...o].slice(0,i5)}function v5(e){return e.title&&e.title.trim()!==""?e.title:e.tool.split(".").map(t=>t.replace(/[_-]+/g," ")).join(" · ").replace(/\b\w/,t=>t.toUpperCase())}const j5=new Set(["table","diff","files"]),w5=3.5*6e4,y5=2e3;function b5(e,t,s={}){const[r,i]=d.useState({served:new Set,live:new Set,scope:t}),a=d.useRef(r.served);if(r.scope!==t){const u={served:new Set,live:new Set,scope:t};a.current=u.served,i(u)}const l=s.check??$.previewCheck,o=s.everyMs??y5,c=e.map(u=>`${pl(u)}@${u.at??""}`).join("|");return d.useEffect(()=>{const u=new Map;for(const p of e){const g=pl(p);if(a.current.has(g))continue;const v=p.at===null?Number.NaN:Date.parse(p.at),b=Number.isNaN(v)?0:v+w5,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 h=!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(h)return;const j=p<=v.until;b!=null&&b.ok?(u.delete(g),i(x=>{const w={served:new Set(x.served).add(g),live:j?new Set(x.live).add(g):x.live,scope:x.scope};return a.current=w.served,w})):j||u.delete(g)}!h&&u.size>0&&(f=setTimeout(()=>void m(),o))};return m(),()=>{h=!0,f!==void 0&&clearTimeout(f)}},[c,t,l,o]),r}const jx="workspace-files";function k5(e){let t=0;for(const s of e)for(const r of s.blocks??[]){if(r.type!=="tool_result"||r.ok===!1)continue;const i=r.output;if(i===null||typeof i!="object"||Array.isArray(i))continue;const{diff:a,path:l}=i;typeof a=="string"&&a.trim()!==""&&typeof l=="string"&&l!==""&&(t+=1)}return t}function N5(e){const[t,s]=d.useState(null);return d.useEffect(()=>{if(s(null),!e)return;let r=!1;return(async()=>{var a;const i=await $.pages();for(const l of Array.isArray(i==null?void 0:i.files)?i.files:[]){const o=await $.pageQuery(l.plugin,l.workspace,{agent:e}).catch(()=>null),c=(a=o==null?void 0:o.data)==null?void 0:a.workspace;if(c&&typeof c.name=="string")return{files:l,agentId:e,root:c.name}}return null})().then(i=>{r||s(i)}).catch(()=>{}),()=>{r=!0}},[e]),t&&t.agentId===e?t:null}function S5(e,t){return{id:jx,tool:"",title:"Files",renderer:"files",props:{files:e.files,agentId:e.agentId,root:e.root,revision:t},at:null,source:"files",pinned:!0,substantial:!1}}function wx(e){return`agent-properties:${e}`}function C5(e){return{id:wx(e.id),tool:`@${e.handle}`,title:"Properties",renderer:"profile",props:{profile:e},at:null,source:"profile",substantial:!1}}function E5(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 bT({progress:e}){return n.jsxs(le,{gap:"sm",children:[n.jsx("span",{role:"status",children:E5(e)}),n.jsx(UA,{value:(e==null?void 0:e.percent)??0,label:"Fetching the browser"})]})}function A5(e,t,s,r){const i=e.width||1,a=e.height||1,l=t.pageScaleFactor||1,o=(s-e.left)*(t.deviceWidth/i)/l,c=((r-e.top)*(t.deviceHeight/a)-t.offsetTop)/l,u=(h,f)=>Math.max(0,Math.min(Math.round(h),Math.round(f)));return{x:u(o,t.deviceWidth),y:u(c,t.deviceHeight)}}function Xm(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}function N0(e){return[...e].length===1&&e.codePointAt(0)>=32&&e.codePointAt(0)!==127}const T5=4e3;function $5(e){return e.replace(/\r\n?/g,`
106
+ `).replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g,"").slice(0,T5)}const R5=["left","middle","right"],I5=33;function P5(e,t){return e.deviceWidth===t.deviceWidth&&e.deviceHeight===t.deviceHeight&&e.pageScaleFactor===t.pageScaleFactor&&e.offsetTop===t.offsetTop}function M5(e){if(e.byteLength<3)return null;const t=new DataView(e);if(t.getUint8(0)!==1)return null;const s=t.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 D5(e=window.location){return`${e.protocol==="https:"?"wss":"ws"}://${e.host}/api/browser/hand`}function O5({sessionId:e,csrf:t,onGiveBack:s,connect:r}){const[i,a]=d.useState("connecting"),[l,o]=d.useState(null),[c,u]=d.useState(!1),[h,f]=d.useState(null),[m,p]=d.useState(!1),[g,v]=d.useState(0),b=d.useRef(null),j=d.useRef(null),x=d.useRef(null),w=d.useRef({at:0});d.useEffect(()=>{const T=r??(D=>new WebSocket(D));let M=!0,P;try{P=T(D5())}catch{a("lost");return}return P.binaryType="arraybuffer",b.current=P,P.onopen=()=>P.send(JSON.stringify({type:"hello",csrf:t,sessionId:e})),P.onmessage=D=>{if(!M)return;if(typeof D.data!="string"){const H=M5(D.data);if(!H||(f(B=>B&&P5(B,H.metadata)?B:H.metadata),u(!0),typeof createImageBitmap!="function"))return;createImageBitmap(H.jpeg).then(B=>{var W,q,_;const Y=j.current;if(!M||!Y){(W=B.close)==null||W.call(B);return}(Y.width!==B.width||Y.height!==B.height)&&(Y.width=B.width,Y.height=B.height),(q=Y.getContext("2d"))==null||q.drawImage(B,0,0),(_=B.close)==null||_.call(B)}).catch(()=>{});return}const O=JSON.parse(D.data);if(O.type==="driving"){a("driving"),o(null);return}(O.type==="refused"||O.type==="ended")&&(o(O.error??"The screen cannot be driven from here."),a("refused"))},P.onclose=()=>{M&&a(D=>D==="refused"?D:"lost")},P.onerror=()=>{M&&a(D=>D==="refused"?D:"lost")},()=>{M=!1,b.current=null;try{P.close()}catch{}}},[e,t,g,r]),d.useEffect(()=>()=>{clearTimeout(w.current.timer)},[]);const y=d.useCallback(T=>{const M=b.current;if(M)try{M.send(JSON.stringify({type:"input",input:T}))}catch{}},[]),k=T=>{var D;const M=j.current;if(!M||!h)return null;const P=(D=M.getBoundingClientRect)==null?void 0:D.call(M);return P?A5(P,h,T.clientX,T.clientY):null},N=T=>{const M=w.current,P=Date.now();clearTimeout(M.timer),M.timer=void 0;const D=M.at+I5-P;if(D<=0){M.at=P,M.pending=void 0,y(T);return}M.pending=T,M.timer=setTimeout(()=>{const O=w.current.pending;w.current.timer=void 0,w.current.pending=void 0,w.current.at=Date.now(),O&&y(O)},D)},S=()=>{const T=w.current;clearTimeout(T.timer),T.timer=void 0;const M=T.pending;T.pending=void 0,M&&(T.at=Date.now(),y(M))},C=T=>M=>{var O,H;const P=k(M);if(!P)return;T==="mousePressed"&&(M.preventDefault(),(H=(O=j.current)==null?void 0:O.focus)==null||H.call(O));const D={kind:"mouse",type:T,x:P.x,y:P.y,button:R5[M.button]??"left",clickCount:T==="mouseMoved"?0:Math.min(3,Math.max(1,M.detail||1)),modifiers:Xm(M)};if(T==="mouseMoved"){N(D);return}S(),y(D)},E=T=>{const M=k(T);M&&(S(),y({kind:"wheel",x:M.x,y:M.y,deltaX:Math.round(T.deltaX),deltaY:Math.round(T.deltaY)}))},R=T=>T.ctrlKey||T.metaKey||T.altKey,I=T=>{var P,D;if(T.key==="Escape"&&R(T)){p(!1),(D=(P=T.target).blur)==null||D.call(P);return}if(T.preventDefault(),(T.metaKey||T.ctrlKey)&&(T.key==="v"||T.key==="V"))return;const M=Xm(T);if(N0(T.key)&&!R(T)){y({kind:"key",type:"char",key:T.key,code:T.code,text:T.key,modifiers:M});return}y({kind:"key",type:"keyDown",key:T.key,code:T.code,modifiers:M})},L=T=>{T.key==="Escape"&&R(T)||(T.preventDefault(),!((T.metaKey||T.ctrlKey)&&(T.key==="v"||T.key==="V"))&&(N0(T.key)&&!R(T)||y({kind:"key",type:"keyUp",key:T.key,code:T.code,modifiers:Xm(T)})))},F=T=>{var P;T.preventDefault();const M=$5(((P=T.clipboardData)==null?void 0:P.getData("text/plain"))??"");M!==""&&y({kind:"text",text:M})};return n.jsxs("section",{className:"hand","data-testid":"remote-hand","data-phase":i,"aria-label":"Driving the host browser",children:[n.jsxs("div",{className:"hand-bar",children:[n.jsx("span",{className:"hand-said",role:"status",children:"You are driving. Nothing you type here is kept."}),n.jsxs(ae,{align:"end",children:[n.jsx(A,{size:"sm",variant:m?"accent":"ghost","aria-pressed":m,onClick:()=>{var M,P,D,O;const T=!m;p(T),T?(P=(M=x.current)==null?void 0:M.focus)==null||P.call(M):(O=(D=x.current)==null?void 0:D.blur)==null||O.call(D)},children:"Keyboard"}),n.jsx(A,{size:"sm",variant:"accent",onClick:s,children:"Give it back"})]})]}),i==="lost"?n.jsxs(V,{tone:"warning",role:"status",children:["Connection lost. The picture below is the last frame that arrived.",n.jsx(ae,{align:"end",children:n.jsx(A,{size:"sm",variant:"accent",onClick:()=>{a("connecting"),v(T=>T+1)},children:"Reconnect"})})]}):null,i==="refused"&&l?n.jsx(V,{tone:"warning",role:"status",children:l}):null,n.jsx("div",{className:"hand-screen",children:c?n.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:L,onPaste:F,onContextMenu:T=>T.preventDefault()}):n.jsx("p",{className:"muted hand-waiting",children:i==="lost"?"No picture arrived before the connection dropped.":"Waiting for the first frame…"})}),n.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:L,onPaste:F,onBlur:()=>p(!1)})]})}function L5(e){return e==="darwin"?"this Mac":"this computer"}let Zm=null;function Ef(){const[e,t]=d.useState(void 0);return d.useEffect(()=>{let s=!0;return Zm??(Zm=$.session().then(r=>r.platform,()=>{Zm=null})),Zm.then(r=>{s&&t(r)}),()=>{s=!1}},[]),L5(e)}function F5({embedded:e,timezone:t}={}){var c;const{data:s,error:r,reload:i}=de(()=>$.browser(),[],3e3),a=de(()=>$.session(),[]),l=(c=a.data)!=null&&c.platform?a.data.platform==="darwin":!0,o=!!a.data||!!a.error;return n.jsxs(On,{embedded:e,title:"Computer & browser",children:[n.jsx(re,{message:r}),!s||!o?n.jsx(pe,{children:"Checking the host…"}):n.jsx(_5,{data:s,macOS:l,reload:i,timezone:t},JSON.stringify(s.settings??null))]})}function _5({data:e,macOS:t,reload:s,timezone:r}){var E,R,I,L,F;const[i,a]=d.useState(!1),[l,o]=d.useState(null),[c,u]=d.useState(!1),h=e.settings&&!t&&e.settings.mode==="computer"?{...e.settings,mode:"playwright"}:e.settings,f=(h==null?void 0:h.mode)??(!t&&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 T=>{a(!0),o(null);try{await T()}catch(M){o(M instanceof Error?M.message:String(M))}finally{a(!1),s()}},b=T=>void v(()=>$.browserSettings(T)),j=e.permissions,x=f==="playwright"?e.browser:void 0,w=((R=x==null?void 0:x.install)==null?void 0:R.state)==="running",y=(x==null?void 0:x.engine)==="none",k=t&&((I=e.helper)==null?void 0:I.present)===!1,N=k?((L=e.helper)==null?void 0:L.message)??"The computer helper is missing from this install. Update buddi.":void 0,S=!!e.enabled&&!y&&!(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 n.jsxs(le,{gap:"lg",children:[n.jsx(re,{message:l}),n.jsx(ue,{title:"Status",panel:!0,actions:n.jsxs(n.Fragment,{children:[n.jsx(A,{size:"sm",disabled:i,onClick:()=>void v(()=>$.computerPermissions(!1)),children:"Check again"}),m&&!S&&(j!=null&&j.supported)?n.jsx(A,{size:"sm",variant:"accent",disabled:i||g,onClick:()=>void v(()=>$.computerPermissions(!0)),children:"Request macOS permissions"}):null,y||w?n.jsx(A,{size:"sm",variant:"accent",disabled:i||w,onClick:()=>void v(()=>$.browserInstall()),children:w?"Installing…":"Install Chromium"}):null]}),children:n.jsxs(le,{children:[e.enabled?y?n.jsxs(V,{tone:"warning",title:"No browser installed for the agents yet",children:["Install Chromium here (about 150 MB), or run ",n.jsx("code",{children:"buddi browser install"})," on this machine."]}):x!=null&&x.problem?n.jsx(V,{tone:"warning",children:x.message}):m&&k?n.jsx("p",{className:"muted",children:"“Use my apps” cannot run on this install; see its card below."}):S?n.jsx(V,{tone:"good",children:C}):n.jsx(V,{tone:"warning",children:"macOS has not granted everything yet. Grant the permissions below, then check again."}):n.jsx(V,{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?n.jsxs("ul",{className:"perm-list",children:[n.jsxs("li",{className:"perm-row",children:[n.jsx(we,{tone:j.accessibility?"good":"warning",children:j.accessibility?"Granted":"Needed"}),n.jsx("span",{className:"perm-name",children:"Accessibility"}),n.jsx("span",{className:"muted",children:"Lets agents click and type in the apps you allow."})]}),n.jsxs("li",{className:"perm-row",children:[n.jsx(we,{tone:j.screenRecording?"good":"warning",children:j.screenRecording?"Granted":"Needed"}),n.jsx("span",{className:"perm-name",children:"Screen Recording"}),n.jsx("span",{className:"muted",children:"Lets agents see the window they are working in."})]})]}):j?n.jsx("p",{className:"muted",children:"Computer control requires macOS 14 or later."}):null,((F=x==null?void 0:x.install)==null?void 0:F.state)==="running"?n.jsx(bT,{progress:x.install.progress}):x!=null&&x.install?n.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&&!y?n.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)?n.jsx("p",{className:"muted",children:j.message}):null,m&&(j!=null&&j.supported)&&!S?n.jsx("p",{className:"muted",children:"macOS may ask you to restart buddi after granting them."}):null]})}),n.jsx(ue,{title:"Who is driving",panel:!0,actions:p.length>0?n.jsx(A,{variant:"danger",size:"sm",disabled:i,onClick:()=>void v(()=>$.browserControl("stop")),children:m?"Stop computer control":"Stop all browsers"}):void 0,children:p.length===0?n.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."}):n.jsx("div",{className:"ui-list",children:p.map(T=>n.jsxs("a",{className:"ui-list-row",href:st(T.session.agentId,T.session.conversationId),children:[n.jsx(Sn,{id:T.session.agentId,name:T.session.agentId,size:"sm"}),n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title",children:T.session.task}),n.jsxs("span",{className:"ui-list-sub",children:[T.session.agentId,", ",T.busy?"working":T.state,", ",T.session.steps," of ",T.session.maxSteps," steps"]})]}),n.jsx("span",{className:"ui-list-side",children:"Open the Canvas"})]},T.session.id))})}),h?n.jsxs(n.Fragment,{children:[n.jsx(ue,{title:"How agents get a screen",panel:!0,children:n.jsxs(le,{divided:!0,children:[n.jsxs("div",{className:"mode-choice",role:"radiogroup","aria-label":"Control mode",children:[t?n.jsx(ep,{current:h.mode,value:"computer",disabled:i||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({...h,mode:"computer"})}):null,n.jsx(ep,{current:h.mode,value:"playwright",disabled:i||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({...h,mode:"playwright"})}),n.jsx(ep,{current:h.mode,value:"extension",disabled:i||g||!e.enabled,title:"Your browser",body:"Uses the Chrome you are signed in to, in background tabs, through the buddi extension.",onPick:()=>b({...h,mode:"extension"})})]}),t?null:n.jsx("p",{className:"muted",children:"Using your own apps is macOS-only."}),g?n.jsx("p",{className:"muted",children:"Finish or stop the current session before changing this."}):null,h.mode==="extension"?n.jsx(q5,{busy:i,timezone:r}):null]})}),t?n.jsx(ue,{title:"Apps agents may use",panel:!0,children:n.jsxs(le,{children:[h.mode!=="computer"?n.jsx("p",{className:"muted",children:"Only used by “Use my apps”. The list is kept for when you switch back."}):null,n.jsx(Y5,{settings:h,disabled:i||g||!e.enabled,onChange:b,onAdd:()=>u(!0)}),n.jsx(Tt,{summary:"Details",children:n.jsxs("div",{className:"ui-prose muted",children:[n.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."}),n.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."}),n.jsx("p",{children:"This is an allow list, not a sandbox: an allowed app’s own network traffic is not inspected."})]})})]})}):null,c?n.jsx(e8,{chosen:h.allowedApps,onClose:()=>u(!1),onPick:T=>{u(!1),h.allowedApps.includes(T)||b({...h,allowedApps:[...h.allowedApps,T]})}}):null]}):null]})}const z5="kmbckpnnjfggeffkkbmkggojnolkdokb",U5="pbfpjefkiijjgefblpnlnlpmeaddfbah",B5="https://chromewebstore.google.com/detail/pbfpjefkiijjgefblpnlnlpmeaddfbah",W5=[z5,U5].filter(Boolean);function H5(e,t){const s=a=>/^\d+(\.\d+){0,3}$/.test(a.trim())?a.trim().split(".").map(Number):null,r=s(e),i=s(t);if(!r||!i)return!1;for(let a=0;a<4;a++){const l=(r[a]??0)-(i[a]??0);if(l!==0)return l<0}return!1}async function K5(){var e;try{if(typeof chrome>"u"||!((e=chrome==null?void 0:chrome.runtime)!=null&&e.sendMessage))return null;for(const t of W5)try{const s=await chrome.runtime.sendMessage(t,{type:"buddi.status"});if(s!=null&&s.installed)return s}catch{}return null}catch{return null}}function V5(e=navigator){var s,r,i;const t=e.userAgent??"";return(s=e.userAgentData)!=null&&s.mobile||/Android|iPhone|iPad|iPod|Mobile/i.test(t)?"phone":(i=(r=e.userAgentData)==null?void 0:r.brands)!=null&&i.some(a=>/Chromium/i.test(a.brand))||/Chrome\/|Chromium\/|Edg\//.test(t)&&!/Firefox\/|OPR\//.test(t)?"chromium":"other"}function G5(e){try{return new URL(e).origin===window.location.origin}catch{return!1}}function q5({busy:e,timezone:t}){const{data:s,error:r,reload:i}=de(()=>$.extension(),[],3e3),a=Ef(),l=de(()=>K5(),[],3e3).data??null,[o,c]=d.useState(""),[u,h]=d.useState(!1),[f,m]=d.useState(null),p=(l==null?void 0:l.state)==="pairing"?l.code??"":"";d.useEffect(()=>{p&&c(p)},[p]);const g=async w=>{h(!0),m(null);try{await w()}catch(y){m(y instanceof Error?y.message:String(y))}finally{h(!1),i()}},v=e||u,b=t??Intl.DateTimeFormat().resolvedOptions().timeZone,j=V5(),x=j==="phone"?null:j==="other"?n.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."}):n.jsxs(le,{children:[n.jsxs(ae,{children:[n.jsx("span",{className:"muted",children:"Install the buddi extension from the Chrome Web Store, then pair it here."}),n.jsx(ht,{}),n.jsx(dt,{variant:"accent",href:B5,target:"_blank",rel:"noopener noreferrer",children:"Add to Chrome"})]}),n.jsx(Tt,{summary:"Developer install",children:n.jsxs("div",{className:"ui-prose muted",children:[n.jsx("p",{children:"Open chrome://extensions, turn on Developer mode, choose Load unpacked, and pick this folder."}),n.jsx(Pt,{label:"The unpacked extension",children:(s==null?void 0:s.path)??"…"})]})})]});return n.jsxs(le,{divided:!0,children:[n.jsx(re,{message:r??f}),n.jsxs(ae,{children:[n.jsx(we,{tone:s!=null&&s.connected?"good":"warning",children:s!=null&&s.connected?"Connected":"Not connected"}),n.jsxs("span",{className:"muted",children:[s!=null&&s.connected&&s.pairedAt?`Paired with Chrome on ${a} since ${nt(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}`:""]})]}),n.jsxs(le,{children:[n.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)&&H5(l.version,s.extensionMinimum)?n.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&&!G5(l.gateway)?n.jsx(V,{tone:"warning",children:`The extension is pointed at ${l.gateway}; set it to ${window.location.origin} in the popup.`}):null]}),s!=null&&s.pending?n.jsxs(ae,{valign:"end",children:[n.jsx(oe,{grow:!0,label:"Pair your browser",hint:"Type the six digits the buddi extension is showing.",children:n.jsx("input",{"aria-label":"Pairing code",inputMode:"numeric",placeholder:"482 913",value:o,onChange:w=>c(w.target.value)})}),n.jsx(ht,{}),n.jsx(A,{variant:"accent",disabled:v||o.replace(/[^0-9]/g,"").length!==6,onClick:()=>void g(async()=>{await $.pairExtension(o),c("")}),children:"Pair"})]}):null,x?s!=null&&s.connected?n.jsx(Tt,{summary:"Pair a different browser",children:x}):x:null,n.jsx(ae,{align:"end",children:n.jsx(A,{variant:"danger",disabled:v||!(s!=null&&s.pairedAt),onClick:()=>void g(()=>$.forgetExtension()),children:"Forget this browser"})})]})}function ep({current:e,value:t,title:s,body:r,health:i,disabled:a,onPick:l}){const o=e===t;return n.jsxs("button",{type:"button",role:"radio","aria-checked":o,className:"mode-option",disabled:a,onClick:()=>{o||l()},children:[n.jsx("span",{className:"mode-option-dot","aria-hidden":"true"}),n.jsxs("span",{className:"mode-option-text",children:[n.jsx("span",{className:"mode-option-title",children:s}),n.jsx("span",{className:"mode-option-body",children:r}),i?n.jsx("span",{className:"mode-option-health",role:"status",children:i}):null]})]})}function Y5({settings:e,disabled:t,onChange:s,onAdd:r}){const i=de(()=>$.installedApps(),[]),a=l=>{var o,c;return((c=(o=i.data)==null?void 0:o.apps.find(u=>u.id===l))==null?void 0:c.name)??l};return n.jsxs(n.Fragment,{children:[e.allowedApps.length===0?n.jsx(pe,{children:"No apps yet. Agents cannot touch anything until you add one."}):n.jsx("ul",{className:"ui-list","aria-label":"Allowed apps",children:e.allowedApps.map(l=>n.jsxs("li",{className:"ui-list-row",children:[n.jsx(Sn,{id:l,name:a(l),size:"sm"}),n.jsxs("span",{className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[a(l),l===e.browserApp?n.jsx(we,{tone:"accent",className:"app-role",children:"browser"}):null]}),n.jsx("span",{className:"ui-list-sub mono",children:l})]}),n.jsxs(ae,{children:[l!==e.browserApp&&Z5(l)?n.jsx(A,{size:"sm",variant:"ghost",disabled:t,onClick:()=>s({...e,browserApp:l}),children:"Use as browser"}):null,l===e.browserApp?n.jsx("span",{className:"muted",children:"In use as the browser"}):n.jsx(A,{size:"sm",variant:"ghost",disabled:t,onClick:()=>s({...e,allowedApps:e.allowedApps.filter(o=>o!==l)}),children:"Remove"})]})]},l))}),n.jsxs(ae,{children:[n.jsx(A,{variant:"accent",disabled:t,onClick:r,children:"Add an app"}),n.jsx("span",{className:"muted",children:"The app marked as browser is the one agents open websites in."})]}),e.mode==="computer"&&J5.includes(e.browserApp)?n.jsx(Q5,{settings:e,disabled:t,onChange:s}):null]})}const J5=["com.google.Chrome","org.chromium.Chromium","com.microsoft.edgemac","com.brave.Browser"];function Q5({settings:e,disabled:t,onChange:s}){var l;const i=((l=de(()=>$.browserProfiles(e.browserApp),[e.browserApp]).data)==null?void 0:l.profiles)??[],a=e.browserProfile?i.some(o=>o.directory===e.browserProfile):!0;return n.jsx(oe,{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:n.jsxs("select",{value:e.browserProfile??"",disabled:t,onChange:o=>{const{browserProfile:c,...u}=e;s(o.target.value?{...u,browserProfile:o.target.value}:u)},children:[n.jsx("option",{value:"",children:"Whichever is in front"}),!a&&e.browserProfile?n.jsxs("option",{value:e.browserProfile,children:[e.browserProfile," (not found)"]}):null,i.map(o=>n.jsxs("option",{value:o.directory,children:[o.name,o.directory==="Default"?"":` (${o.directory})`]},o.directory))]})})}const X5=["com.google.Chrome","com.apple.Safari","org.chromium.Chromium","com.microsoft.edgemac","com.brave.Browser","org.mozilla.firefox","company.thebrowser.Browser"];function Z5(e){return X5.includes(e)}function e8({chosen:e,onClose:t,onPick:s}){const r=de(()=>$.installedApps(),[]),[i,a]=d.useState(""),[l,o]=d.useState(""),c=d.useMemo(()=>{var f;const u=((f=r.data)==null?void 0:f.apps)??[],h=i.trim().toLowerCase();return u.filter(m=>!h||m.name.toLowerCase().includes(h)||m.id.toLowerCase().includes(h)).slice(0,60)},[r.data,i]);return n.jsxs(Ye,{title:"Add an app",onClose:t,children:[n.jsx("input",{autoFocus:!0,"aria-label":"Search apps",placeholder:"Search installed apps",value:i,onChange:u=>a(u.target.value)}),n.jsx(re,{message:r.error}),r.data?c.length===0?n.jsx(pe,{children:"No app matches."}):n.jsx("ul",{className:"ui-list","aria-label":"Installed apps",children:c.map(u=>{const h=e.includes(u.id);return n.jsxs("li",{className:"ui-list-row",children:[n.jsx(Sn,{id:u.id,name:u.name,size:"sm"}),n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title",children:u.name}),n.jsx("span",{className:"ui-list-sub mono",children:u.id})]}),n.jsx(A,{size:"sm",disabled:h,onClick:()=>s(u.id),children:h?"Allowed":"Allow"})]},u.id)})}):n.jsx(pe,{children:"Reading your Applications folder…"}),n.jsx(Tt,{summary:"Add by bundle identifier instead",children:n.jsxs(ae,{children:[n.jsx("input",{"aria-label":"Bundle identifier",placeholder:"com.apple.TextEdit",value:l,onChange:u=>o(u.target.value)}),n.jsx(A,{disabled:!l.trim(),onClick:()=>s(l.trim()),children:"Allow this identifier"})]})})]})}function t8({data:e,error:t,reload:s,compact:r=!1,refresh:i,screenshotSrc:a,onScreenshotError:l,onScreenshotLoad:o,controls:c=!0}){var F,T,M;const[u,h]=d.useState(!1),[f,m]=d.useState(null),[p,g]=d.useState(null),[v,b]=d.useState(null),[j,x]=d.useState(!1),w=Ef(),y=async P=>{h(!0),m(null),b(null),x(!1);try{const D=P!=="stop"&&(e!=null&&e.session)?await $.browserControl(P,e.session.id):await $.browserControl(P);P==="takeover"?D.hand&&D.session?g(D.session.id):D.handReason==="browser-offline"?x(!0):b(D.handMessage??null):g(null)}catch(D){m(D instanceof Error?D.message:String(D))}finally{h(!1),s()}},k=async()=>{if(e!=null&&e.settings){h(!0),m(null);try{e.session&&await $.browserControl("release",e.session.id),await $.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(P){m(P instanceof Error?P.message:String(P))}finally{h(!1),s()}}},N=p&&((F=e==null?void 0:e.session)==null?void 0:F.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",R=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",L=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 n.jsxs("section",{className:"browser-panel","data-compact":r?"true":void 0,"aria-label":"Host browser",children:[n.jsxs("div",{className:"browser-heading",children:[n.jsxs("div",{children:[r?null:n.jsx("p",{className:"browser-eyebrow",children:"On your host machine"}),n.jsx("h2",{className:"browser-title",children:C?"Computer":E?"Your browser":"Browser"})]}),n.jsx(we,{tone:L,children:n.jsx("span",{role:"status",children:I})})]}),r?n.jsx("a",{className:"browser-full-view",href:"#/browser",children:C?"Open computer view & settings ↗":"Open full browser view ↗"}):n.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."}),n.jsx(re,{message:t??f}),c?n.jsxs(ae,{children:[n.jsx(A,{variant:"danger",disabled:!S||(e==null?void 0:e.state)==="stopped",onClick:()=>void y("stop"),children:C?"Stop computer control":"Stop all browsers"}),n.jsx(A,{disabled:!S||!(e!=null&&e.session)||(e==null?void 0:e.state)==="paused",onClick:()=>void y("takeover"),children:"Take over"}),n.jsx(A,{disabled:!S||(e==null?void 0:e.busy)||!["stopped","paused"].includes((e==null?void 0:e.state)??""),onClick:()=>void y("resume"),children:"Resume access"}),n.jsx(A,{disabled:!S||!(e!=null&&e.session),onClick:()=>void y("release"),children:C?"Release control":"Close & release"})]}):null,c?r?n.jsx(Tt,{summary:"About these controls",children:n.jsx("p",{className:"muted",children:R})}):n.jsx("p",{className:"muted",children:R}):null,v?n.jsx(V,{tone:"warning",role:"status",children:v}):null,j&&E?n.jsx(V,{tone:"warning",role:"status",title:"Your browser isn’t connected.",action:n.jsxs(ae,{align:"end",children:[e!=null&&e.settings?n.jsx(A,{size:"sm",disabled:u,onClick:()=>void k(),children:"Switch to buddi’s browser"}):null,n.jsx(A,{size:"sm",variant:"accent",disabled:u,onClick:()=>void y("takeover"),children:"Try again"})]}),children:`There is no Chrome tab to show or drive. Open Chrome on ${w}: 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)?n.jsx(V,{tone:"warning",role:"status",children:e.message}):null,e!=null&&e.session?n.jsxs("div",{className:"browser-task",children:[n.jsxs("div",{className:"ui-row",children:[n.jsx("strong",{children:e.session.agentId}),n.jsxs("span",{className:"muted",children:[e.session.steps," / ",e.session.maxSteps," steps"]})]}),r?null:n.jsx("p",{children:e.session.task}),n.jsxs("p",{className:"muted",children:["Last action: ",e.lastAction??"None"," · Access expires ",zt(new Date(e.session.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone)]})]}):n.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?n.jsx(O5,{sessionId:N,csrf:ja(),onGiveBack:()=>void y("resume")}):null,n.jsxs("div",{className:"browser-window",hidden:!!N,children:[n.jsxs("div",{className:"browser-address",children:[n.jsx("span",{"aria-hidden":"true",children:"◉"}),n.jsx("span",{children:((T=e==null?void 0:e.page)==null?void 0:T.url)??(C?"Waiting for an application":"Waiting for a website")})]}),e!=null&&e.hasScreenshot&&e.page?n.jsxs("figure",{children:[n.jsx("img",{src:a??`/api/browser/screenshot?v=${encodeURIComponent(e.page.id)}${e.session?`&sessionId=${encodeURIComponent(e.session.id)}`:""}${i?`&tick=${i}`:""}`,alt:`Last browser observation: ${e.page.title||e.page.url}`,...l?{onError:l}:{},...o?{onLoad:o}:{}},a??e.page.id),n.jsxs("figcaption",{children:["Last observation · ",zt(new Date(e.page.capturedAt),Intl.DateTimeFormat().resolvedOptions().timeZone)," · ",e.page.title||"Untitled page"]})]}):n.jsxs("div",{className:"browser-empty",children:[n.jsx("strong",{children:C?"Your selected app will appear here":"Your browser activity will appear here"}),n.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."})]})]}),(((M=e==null?void 0:e.page)==null?void 0:M.tabs.length)??0)>1?n.jsx(Tt,{summary:`${e.page.tabs.length} open tabs`,children:n.jsx("ul",{className:"ui-prose",children:e.page.tabs.map(P=>n.jsxs("li",{children:[P.title||P.id," — ",P.url]},P.id))})}):null,n.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 n8=2e3,s8=5;function r8(e,t){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 i8({status:e,error:t,reload:s,steps:r,live:i,focusedStepId:a=null}){var w;const[l,o]=d.useState(0),[c,u]=d.useState(0),h=c>=s8;d.useEffect(()=>{if(!i||h)return;const y=window.setInterval(()=>{typeof document<"u"&&document.hidden||o(k=>k+1)},n8);return()=>window.clearInterval(y)},[i,h]);const f=d.useRef(null);i&&(e!=null&&e.session)&&(f.current=e);const[m,p]=d.useState(null),g=d.useRef(null),v=((w=e==null?void 0:e.page)==null?void 0:w.id)??null;d.useEffect(()=>{const y=i&&e?r8(e):null;if(!y||typeof fetch!="function"||typeof(URL==null?void 0:URL.createObjectURL)!="function")return;let k=!1;return(async()=>{try{const N=await fetch(y);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}},[i,v]),d.useEffect(()=>()=>{g.current&&typeof(URL==null?void 0:URL.revokeObjectURL)=="function"&&URL.revokeObjectURL(g.current)},[]);const b=f.current,j=i?e:b?m?b:{...b,hasScreenshot:!1}:e,x=r.at(-1)??null;return n.jsxs("div",{className:"wb-browser","data-testid":"browser-view","data-live":i?"true":"false",children:[n.jsx(t8,{data:j,error:t,reload:s,compact:!0,controls:i,...i?{refresh:l}:{},...!i&&m?{screenshotSrc:m}:{},onScreenshotError:()=>u(y=>y+1),onScreenshotLoad:()=>u(0)}),i?h?n.jsx("p",{className:"muted wb-browser-ended",role:"status",children:"The last observation could not be loaded. Showing what arrived before it."}):null:n.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."}),n.jsx(a8,{steps:r,newestId:(x==null?void 0:x.id)??null,focusedId:a??null,live:i})]})}function a8({steps:e,newestId:t,focusedId:s,live:r}){const i=d.useRef(null);return d.useEffect(()=>{var l;if(!s||!i.current)return;const a=i.current.querySelector(`[data-step="${CSS!=null&&CSS.escape?CSS.escape(s):s}"]`);(l=a==null?void 0:a.scrollIntoView)==null||l.call(a,{block:"nearest"})},[s]),e.length===0?n.jsx("p",{className:"muted wb-browser-empty",children:r?"No action taken on this screen yet.":"This conversation took no action on the screen."}):n.jsx("section",{className:"wb-browser-steps","aria-label":"Steps taken on this screen",children:n.jsx("ol",{className:"wb-browser-list",ref:i,children:e.map((a,l)=>{const o=a.awaiting?"awaiting":a.ok===null?"running":a.ok?"ok":"failed";return n.jsxs("li",{"data-step":a.id,className:"wb-browser-step","data-state":o,"data-newest":a.id===t?"true":void 0,"data-focused":a.id===s?"true":void 0,children:[n.jsx("span",{className:"wb-browser-index mono",children:l+1}),n.jsxs("span",{className:"wb-browser-what",children:[n.jsx("strong",{children:a.action}),a.target?n.jsx("span",{className:"muted wb-browser-target",children:a.target}):null,a.error?n.jsx("span",{className:"wb-browser-error",children:a.error}):null]}),n.jsx("span",{className:"wb-browser-outcome","data-state":o,children:o==="awaiting"?"Awaiting approval":o==="running"?"Working":o==="ok"?"Done":"Failed"})]},a.id)})})})}function l8({agentId:e,conversationId:t}){const{data:s,error:r,reload:i}=de(()=>$.host(e,t),[e,t],2e3),[a,l]=d.useState(null),[o,c]=d.useState(!1),u=async p=>{c(!0),l(null);try{await p(),i()}catch(g){l(g instanceof Error?g.message:String(g))}finally{c(!1)}},h=(s==null?void 0:s.permissions)??[],f=(s==null?void 0:s.runs)??[],m=h.some(p=>!p.conversationId)?"Always allowed":h.length?"Conversation auto-mode":"Ask each time";return n.jsx(Tt,{className:"host-controls",summary:`Host execution · ${r?"Status unavailable":m}${f.length?` · ${f.length} running`:""}`,children:n.jsxs(le,{gap:"sm",children:[n.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."}),n.jsx(re,{message:a??r}),h.map(p=>n.jsxs(ae,{children:[n.jsxs("span",{children:[p.agentId,": ",p.conversationId?"conversation auto-mode":"always allowed"]}),n.jsx(A,{size:"sm",disabled:o,onClick:()=>void u(()=>$.revokeHost(p.id)),children:"Revoke permission"})]},p.id)),h.length?null:n.jsx("p",{className:"muted",children:"The next command will ask for approval. Choose its permission scope there."}),f.map(p=>n.jsxs(le,{gap:"sm",children:[n.jsxs("p",{children:[p.agentId," · ",n.jsx("span",{className:"mono",children:p.cwd})]}),n.jsx(Pt,{children:p.command}),n.jsx(Pt,{label:"Command output",children:p.stdout||p.stderr?`${p.stdout}
107
+ ${p.stderr}`:"Waiting for output…"}),n.jsx(ae,{children:n.jsx(A,{size:"sm",variant:"danger",disabled:o,onClick:()=>void u(()=>$.stopHost(p.agentId,p.conversationId)),children:"Stop command"})})]},p.actionId))]})})}const kT="browser.act",o8="browser.status",wd=new Set([kT,o8]);function c8(e,t,s){const r=e==null?void 0:e.session;return!r||!t||!s||r.agentId!==t||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 u8(e,t){return{...e,title:`${t==="computer"?"Computer":"Browser"} (ended)`,pinned:!1}}function d8(e){var r;const t=[],s=new Map;for(const i of e)for(const a of i.blocks??[]){if(a.type==="tool_use"&&a.name===kT){const o={id:a.id,action:h8(a.input)??"act",target:f8(a.input),ok:null,awaiting:!1,error:null,at:i.at??null};t.push(o),s.set(a.id,o);continue}if(a.type!=="tool_result")continue;const l=s.get(a.toolUseId);if(l){if(((r=a.approval)==null?void 0:r.state)==="pending"){l.awaiting=!0,l.ok=null,l.error=null;continue}l.awaiting=!1,l.ok=a.ok,l.error=a.ok?null:m8(a)}}return t}function S0(e,t){var r;let s=!1;for(const i of e)for(const a of i.blocks??[])if(a.type==="tool_use"&&a.id===t&&(s=wd.has(a.name)),a.type==="tool_result"&&a.toolUseId===t&&((r=a.approval)==null?void 0:r.state)==="pending")return null;return s?t:null}function h8(e){if(e===null||typeof e!="object")return null;const t=e.action;return typeof t=="string"&&t!==""?t:null}function f8(e){if(e===null||typeof e!="object")return null;const t=e;for(const r of["url","appId","direction","key","tabId"]){const i=t[r];if(typeof i=="string"&&i!=="")return i}const s=t.target;if(s!==null&&typeof s=="object"){const r=s,i=r.name;if(typeof i=="string"&&i!=="")return i;const a=r.ref;if(typeof a=="string"&&a!=="")return a;if(typeof r.x=="number"&&typeof r.y=="number")return`${r.x}, ${r.y}`}return null}function m8(e){for(const t of[e.error,e.output]){if(typeof t=="string"&&t.trim()!=="")return t.trim();if(t!==null&&typeof t=="object")for(const s of["message","error","reason"]){const r=t[s];if(typeof r=="string"&&r.trim()!=="")return r.trim()}}return null}const p8="web.read",g8="web.search",x8=new Set([p8,g8]);function v8({agentId:e,groupId:t,currentId:s,timezone:r,onSelect:i,onNew:a}){const[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(0);return d.useEffect(()=>{let m=!1;return o(null),u(null),(t?Ve.groupConversations(t):Ve.conversations(e,100)).then(p=>{m||o(p.conversations)}).catch(p=>{m||u(p instanceof Error?p.message:String(p))}),()=>{m=!0}},[e,t,h]),n.jsxs("section",{className:"wb-history","aria-label":"Past conversations",children:[n.jsxs("div",{className:"ui-toolbar",children:[n.jsx("strong",{children:"Past conversations"}),n.jsx("button",{className:"ui-btn",onClick:a,children:"New conversation"})]}),c?n.jsxs("p",{role:"alert",children:[c," ",n.jsx("button",{className:"ui-btn",onClick:()=>f(m=>m+1),children:"Retry"})]}):l===null?n.jsx("p",{className:"muted",children:"Loading conversations…"}):l.length===0?n.jsx("p",{className:"muted",children:"No conversations yet."}):n.jsx("ul",{children:l.map(m=>n.jsx("li",{children:n.jsxs("a",{href:t?Yi(t,m.id):st(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(),i(m.id))},children:[n.jsx("span",{children:m.preview||m.opening||"Untitled conversation"}),n.jsxs("small",{children:[nt(m.lastMessageAt??m.startedAt??m.createdAt??null,r)," · ",m.messageCount," messages",m.id===s?" · Current":""]})]})},m.id))}),n.jsx("a",{href:"#/conversations",children:"View all agents’ conversation records ↗"}),(l==null?void 0:l.length)===100?n.jsx("p",{className:"muted",children:"Showing the 100 most recent conversations."}):null]})}const NT="buddi.dismissedTabs";function j8(){try{const e=JSON.parse(sessionStorage.getItem(NT)??"{}");return!e||typeof e!="object"||Array.isArray(e)?{}:Object.fromEntries(Object.entries(e).filter(([,t])=>Array.isArray(t)&&t.every(s=>typeof s=="string")))}catch{return{}}}function C0(e){try{sessionStorage.setItem(NT,JSON.stringify(Object.fromEntries(Object.entries(e).slice(-100))))}catch{}}const w8=350,y8=60;function b8({conversationId:e,onText:t,onNotice:s}){const[r,i]=d.useState("idle"),a=d.useRef("idle"),l=x=>{a.current=x,i(x)},o=d.useRef(null),c=d.useRef(null),u=d.useRef(null),h=d.useRef(null),f=d.useRef(null),m=d.useRef({onText:t,onNotice:s,conversationId:e});m.current={onText:t,onNotice:s,conversationId:e};const p=()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null)},g=async()=>{if(a.current!=="idle")return;m.current.onNotice(null),l("starting"),c.current=null;let x;try{x=await v6(k=>{var N;return(N=f.current)==null?void 0:N.call(f,k)})}catch(k){h.current=null,l("idle"),m.current.onNotice(x6(k));return}const w=c.current;c.current=null;const y=a.current;if(w==="discard"||y!=="starting"){x.cancel(),y==="starting"&&l("idle");return}o.current=x,l("recording"),u.current=window.setTimeout(()=>void v(!1),m6),w&&v(w.sendNow)},v=async x=>{h.current=null;const w=o.current;if(!w){a.current==="starting"&&(c.current={sendNow:x});return}o.current=null,p(),l("transcribing");try{const y=await w.stop();if(y.size<=44){m.current.onNotice("Nothing was recorded.");return}const k=new File([y],`recording-${new Date().toISOString().slice(0,19).replace(/[:T]/g,"-")}.wav`,{type:"audio/wav"}),N=await Ve.attach(k),S=m.current.conversationId,C=await Ve.transcribe({artifactId:N.artifactId,...S?{conversationId:S}:{}});m.current.onText(C.text,x)}catch(y){m.current.onNotice(y instanceof ve||y instanceof Error?y.message:String(y))}finally{l("idle")}},b=()=>{h.current=null;const x=o.current;if(!x){a.current==="starting"&&(c.current="discard");return}o.current=null,p(),x.cancel(),l("idle")};d.useEffect(()=>{const x=w=>{if(h.current===null)return;const y=Date.now()-h.current;h.current=null,y>=w8&&v(w.shiftKey)};return window.addEventListener("pointerup",x),()=>window.removeEventListener("pointerup",x)},[]);const j=r==="starting"||r==="recording";return d.useEffect(()=>{if(!j)return;const x=w=>{w.isComposing||w.repeat||(w.key==="Escape"?(w.preventDefault(),w.stopPropagation(),b()):w.key==="Enter"&&(w.preventDefault(),w.stopPropagation(),v(w.shiftKey)))};return window.addEventListener("keydown",x,!0),()=>window.removeEventListener("keydown",x,!0)},[j]),d.useEffect(()=>()=>{var x;(x=o.current)==null||x.cancel(),p()},[]),{state:r,hold:()=>{h.current=Date.now(),g()},start:()=>{h.current=null,g()},finish:x=>void v(x),discard:b,levels:f}}function k8({disabled:e,voice:t}){const s=i=>{e||i.button>0||t.state!=="idle"||(i.preventDefault(),t.hold())},r=i=>{i.detail!==0||e||t.state!=="idle"||t.start()};return n.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:i=>i.preventDefault(),children:n.jsx(ce,{name:"mic"})})}function N8({voice:e}){const t=d.useRef(null),s=e.state==="transcribing";return d.useEffect(()=>{var r;(r=t.current)==null||r.focus()},[]),n.jsxs("div",{className:"wb-listening",role:"group","aria-label":"Recording","data-phase":s?"transcribing":"listening",children:[n.jsx("p",{className:"wb-listening-label","aria-live":"polite",children:s?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"wb-listening-spinner","aria-hidden":"true"}),"Transcribing…"]}):"Listening…"}),n.jsxs("div",{className:"wb-listening-row",children:[n.jsx(S8,{sink:e.levels,frozen:s}),n.jsx("button",{type:"button",className:"wb-send","data-variant":"quiet","aria-label":"Discard recording",title:"Discard (Escape)",disabled:s,onClick:()=>e.discard(),children:n.jsx(ce,{name:"close"})}),n.jsx("button",{ref:t,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:n.jsx(ce,{name:"check"})})]})]})}function S8({sink:e,frozen:t}){const[s,r]=d.useState(()=>Array(y8).fill(0));return d.useEffect(()=>{if(!t)return e.current=i=>r(a=>[...a.slice(1),i]),()=>{e.current=null}},[t]),n.jsx("div",{className:"wb-wave","aria-hidden":"true","data-testid":"waveform",children:s.map((i,a)=>n.jsx("span",{className:"wb-wave-bar",style:{"--level":i.toFixed(3)}},a))})}const C8="This browser cannot capture a tab. Chrome, Safari and Firefox can, on a secure address.",Hu="The tab could not be captured. Try again, and pick the tab itself rather than the whole screen.",E8=e=>e instanceof Error&&(e.name==="NotAllowedError"||e.name==="AbortError");async function A8(e={}){var r;const t=e.media??(typeof navigator>"u"?void 0:navigator.mediaDevices);if(!t||typeof t.getDisplayMedia!="function")throw new Error(C8);let s;try{s=await t.getDisplayMedia({video:{displaySurface:"browser"},audio:!1,selfBrowserSurface:"exclude",surfaceSwitching:"exclude",preferCurrentTab:!1})}catch(i){if(E8(i))return null;throw new Error(Hu)}try{const i=e.document??document,a=i.createElement("video");a.muted=!0,a.playsInline=!0,a.srcObject=s,await new Promise((h,f)=>{a.onloadedmetadata=()=>h(),a.onerror=()=>f(new Error(Hu))}),await a.play(),await new Promise(h=>{const f=a.requestVideoFrameCallback;typeof f=="function"?f.call(a,()=>h()):setTimeout(h,120)});const l=i.createElement("canvas");l.width=a.videoWidth,l.height=a.videoHeight;const o=l.getContext("2d");if(!o||l.width===0)throw new Error(Hu);o.drawImage(a,0,0);const c=await new Promise(h=>l.toBlob(h,"image/png"));if(!c)throw new Error(Hu);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(i=>i.stop())}}const E0="Send files once the agent has answered.",yx="wb-composer-input",ow=d.forwardRef(function({disabled:t,running:s,onSend:r,onStop:i,agentName:a,draft:l,model:o,setupHref:c,thinking:u,onThinking:h,onOpenFile:f,mentions:m,history:p,threadKey:g,conversationId:v,readAloud:b,onReadAloud:j,placeholder:x,slim:w},y){var Yn;const k=g?`buddi.draft.${g}`:null,N=Z=>{if(!Z)return"";try{return window.localStorage.getItem(Z)??""}catch{return""}},[S,C]=d.useState(()=>N(k)),[E,R]=d.useState([]),[I,L]=d.useState(!1),[F,T]=d.useState(null),[M,P]=d.useState(!1),D=d.useRef(null),O=d.useRef(null),[H,B]=d.useState(null),[Y,W]=d.useState(0),q=H&&m?m.filter(Z=>Z.handle.toLowerCase().startsWith(H.query.toLowerCase())||Z.name.toLowerCase().startsWith(H.query.toLowerCase())).slice(0,6):[],_=(Z,Re)=>{if(!m||m.length===0){B(null);return}const Xe=Z.slice(0,Re),jt=/(^|\s)@([\w-]*)$/.exec(Xe);if(!jt){B(null);return}B({start:Re-jt[2].length-1,query:jt[2]}),W(0)},X=Z=>{if(!H)return;const Re=O.current,Xe=Re?Re.selectionStart:S.length,jt=`${S.slice(0,H.start)}@${Z} ${S.slice(Xe)}`;C(jt),ee<0&&_e(jt),B(null),window.requestAnimationFrame(()=>{if(!Re)return;const G=H.start+Z.length+2;Re.focus(),Re.setSelectionRange(G,G),kt()})},Q=p??[],[ee,fe]=d.useState(-1),Le=d.useRef(S),Ie=d.useRef(k);if(Ie.current!==k){Ie.current=k;const Z=N(k);Le.current=Z,Z!==S&&(C(Z),fe(-1),B(null))}const _e=Z=>{if(Le.current=Z,!!k)try{Z===""?window.localStorage.removeItem(k):window.localStorage.setItem(k,Z)}catch{}},U=Z=>{C(Z),B(null);const Re=O.current;Re&&(Re.value=Z,Re.setSelectionRange(Z.length,Z.length)),window.requestAnimationFrame(kt)},ie=Z=>!Z.value.slice(0,Z.selectionStart??Z.value.length).includes(`
108
+ `),J=()=>S===""||ee>=0&&S===Q[ee],ye=()=>{ee<0||(fe(-1),U(Le.current))},ge=E.some(Z=>Z.state==="uploading"),$e=E.length>0,De=s&&$e,Je=!t&&!ge&&!De&&S.trim()!=="",Ue=Z=>{for(const Re of Array.from(Z??[])){const Xe=`${Re.name}:${Re.size}:${Math.random().toString(36).slice(2,8)}`,jt=Re.type.startsWith("image/")&&typeof URL.createObjectURL=="function"?URL.createObjectURL(Re):null;R(G=>[...G,{key:Xe,filename:Re.name||"Pasted image",mime:Re.type||"application/octet-stream",sizeBytes:Re.size,thumbnail:jt,state:"uploading"}]),Ve.attach(Re).then(G=>R(he=>he.map(We=>We.key===Xe?{...We,state:"ready",uploaded:G}:We))).catch(G=>R(he=>he.map(We=>We.key===Xe?{...We,state:"failed",error:G instanceof ve?G.message:String(G)}:We)))}},be=Z=>{Z.thumbnail&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(Z.thumbnail)},Be=Z=>{const Re=E.find(Xe=>Xe.key===Z);Re&&(be(Re),Re.state==="ready"&&Re.uploaded&&Ve.discardAttachment(Re.uploaded.artifactId).catch(()=>{})),R(Xe=>Xe.filter(jt=>jt.key!==Z))};d.useImperativeHandle(y,()=>({addFiles:Z=>{var Re;Ue(Z),(Re=O.current)==null||Re.focus()},focus:()=>{var Z;return(Z=O.current)==null?void 0:Z.focus()}}));const at=d.useRef(E);at.current=E,d.useEffect(()=>()=>at.current.forEach(be),[]);const He=d.useRef(0);d.useEffect(()=>{if(!l||l.at===He.current)return;He.current=l.at,C(Re=>Re.trim()===""?l.text:Re),ee<0&&S.trim()===""&&_e(l.text);const Z=O.current;Z&&(Z.focus(),window.requestAnimationFrame(()=>{Z.style.height="auto",Z.style.height=`${Math.min(Z.scrollHeight,200)}px`,Z.setSelectionRange(Z.value.length,Z.value.length)}))},[l]);const kt=()=>{const Z=O.current;Z&&(Z.style.height="auto",Z.style.height=`${Math.min(Z.scrollHeight,200)}px`)},Yt=Z=>{const Re=(Z??S).trim();if(Z===void 0?!Je:t||ge||De||Re==="")return;const Xe=E.filter(jt=>jt.state==="ready"&&jt.uploaded).map(jt=>jt.uploaded);r(Re,Xe),E.forEach(be),fe(-1),_e(""),C(""),R([]),window.requestAnimationFrame(kt)},ne=Z=>{if(H&&q.length>0){if(Z.key==="ArrowDown"){Z.preventDefault(),W(Re=>(Re+1)%q.length);return}if(Z.key==="ArrowUp"){Z.preventDefault(),W(Re=>(Re-1+q.length)%q.length);return}if(Z.key==="Enter"||Z.key==="Tab"){Z.preventDefault(),X(q[Y].handle);return}if(Z.key==="Escape"){Z.preventDefault(),B(null);return}}if(Z.key==="ArrowUp"&&!Z.shiftKey&&!Z.altKey&&!Z.metaKey&&!Z.ctrlKey){const Re=Z.currentTarget;if(Q.length>0&&ee+1<Q.length&&ie(Re)&&J()){Z.preventDefault(),ee<0&&(Le.current=S),fe(ee+1),U(Q[ee+1]);return}}if(Z.key==="ArrowDown"&&!Z.shiftKey&&!Z.altKey&&!Z.metaKey&&!Z.ctrlKey&&ee>=0&&S===Q[ee]){if(Z.preventDefault(),ee===0){ye();return}fe(ee-1),U(Q[ee-1]);return}if(Z.key==="Escape"&&ee>=0){Z.preventDefault(),ye();return}Z.key==="Enter"&&!Z.shiftKey&&(Z.preventDefault(),Yt())},ke=Z=>{var Xe;const Re=Array.from(((Xe=Z.clipboardData)==null?void 0:Xe.files)??[]);Re.length!==0&&(Z.preventDefault(),Ue(Re))},Qe=E.filter(Z=>Z.state==="failed"),ct=Qe.length,Nt=b8({conversationId:v??null,onNotice:T,onText:(Z,Re)=>{const Xe=S.trim()===""?Z:`${S.replace(/\s+$/,"")} ${Z}`;if(Re){Yt(Xe);return}U(Xe),ee<0&&_e(Xe)}}),ut=Nt.state!=="idle",xn=d.useRef(!1);return d.useEffect(()=>{var Z;xn.current&&!ut&&((Z=O.current)==null||Z.focus(),window.requestAnimationFrame(kt)),xn.current=ut},[ut]),n.jsx("div",{className:"wb-composer","data-testid":"composer","data-slim":w||void 0,"data-busy":S.trim()!==""||$e||ut?"true":void 0,children:n.jsxs("div",{className:"wb-composer-box","data-focused":M||ut,"data-disabled":t,"data-listening":ut||void 0,children:[E.length>0?n.jsx("div",{className:"wb-composer-files",role:"list","aria-label":"Files to send",children:E.map(Z=>n.jsx("span",{role:"listitem",children:n.jsx(Cf,{name:Z.filename,mime:Z.mime,sizeBytes:Z.sizeBytes,thumbnail:Z.thumbnail,state:Z.state,error:Z.error,onRemove:()=>Be(Z.key),...f&&Z.state==="ready"&&Z.uploaded?{onOpen:()=>f(T8(Z.uploaded))}:{},size:"sm"})},Z.key))}):null,n.jsxs("label",{className:"sr-only",htmlFor:yx,children:["Message ",a]}),n.jsx("textarea",{id:yx,ref:O,value:S,rows:w?1:2,placeholder:s?`${a} is working…`:x??`Message ${a}`,onChange:Z=>{C(Z.target.value),ee<0&&_e(Z.target.value),_(Z.target.value,Z.target.selectionStart??Z.target.value.length),kt()},onFocus:()=>P(!0),onBlur:()=>P(!1),onKeyDown:ne,onPaste:ke,disabled:t,hidden:ut}),ut?n.jsx(N8,{voice:Nt}):null,!ut&&H&&q.length>0?n.jsx("div",{className:"wb-mentions",role:"listbox","aria-label":"Members",children:q.map((Z,Re)=>n.jsxs("button",{type:"button",role:"option","aria-selected":Re===Y,className:"wb-mention","data-active":Re===Y||void 0,onMouseDown:Xe=>{Xe.preventDefault(),X(Z.handle)},children:[n.jsxs("span",{className:"wb-mention-handle",children:["@",Z.handle]}),n.jsx("span",{className:"wb-mention-name",children:Z.name})]},Z.handle))}):null,n.jsxs("div",{className:"wb-composer-row",hidden:ut,children:[n.jsx("input",{ref:D,type:"file",multiple:!0,hidden:!0,"data-testid":"file-input",onChange:Z=>{Ue(Z.target.files),Z.target.value=""}}),n.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 Z;return(Z=D.current)==null?void 0:Z.click()},disabled:t,children:n.jsx(ce,{name:"clip"})}),n.jsx(k8,{disabled:t,voice:Nt}),n.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:()=>{T(null),L(!0),A8().then(Z=>{var Re;Z&&(Ue([Z]),(Re=O.current)==null||Re.focus())}).catch(Z=>T(Z instanceof Error?Z.message:String(Z))).finally(()=>L(!1))},disabled:t||I,children:n.jsx(ce,{name:"camera"})}),o?c?n.jsxs("a",{className:"wb-composer-model",href:c,title:"The model this agent runs on. Click to change it.",children:[n.jsx("span",{className:"wb-composer-model-dot","aria-hidden":"true"}),o]}):n.jsxs("span",{className:"wb-composer-model",title:"The model this agent runs on",children:[n.jsx("span",{className:"wb-composer-model-dot","aria-hidden":"true"}),o]}):null,h?n.jsxs("button",{type:"button",className:"wb-composer-think","aria-pressed":Ku(u),disabled:t||s,title:s?`Wait for ${a} to finish — this run started with thinking ${Ku(u)?"on":"off"}`:Ku(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:()=>h(Ku(u)?"off":"on"),children:[n.jsx("span",{className:"wb-composer-think-dot","aria-hidden":"true"}),"Thinking"]}):null,j?n.jsx("button",{type:"button",className:"ui-icon-btn wb-read-aloud","data-size":"sm","aria-label":"Read replies aloud","aria-pressed":!!b,title:b?"Replies are read aloud. Click to stop.":"Read replies aloud, through the voice chosen in Settings → Speech",onClick:()=>j(!b),children:n.jsx(ce,{name:"speaker"})}):null,n.jsx("span",{className:"wb-hint","data-shown":S!==""&&!s||ct>0||De||F!==null,"data-tone":ct>0||F!==null?"critical":void 0,children:ct>0?ct===1&&((Yn=Qe[0])!=null&&Yn.error)?Qe[0].error:`${ct} files failed to upload and will not be sent`:F!==null?F:De?E0:"Enter sends, Shift+Enter for a new line"}),s?n.jsx("button",{className:"ui-btn","data-variant":"stop",onClick:i,children:"Stop"}):null,n.jsx("button",{className:"wb-send","aria-label":"Send",title:De?E0:ge?"Waiting for the upload to finish":s?`Send — ${a} picks it up between steps`:"Send",onClick:()=>Yt(),disabled:!Je,children:n.jsx(ce,{name:"send"})})]})]})})});function Ku(e){return(e??"on")==="on"}function T8(e){return{type:"attachment",artifactId:e.artifactId,filename:e.filename,mime:e.mime,kind:e.kind,sizeBytes:e.sizeBytes}}function $8({question:e,disabled:t,onAnswer:s,onSkip:r}){const[i,a]=d.useState("");return d.useEffect(()=>{if(t)return;const l=o=>{o.key!=="Escape"||o.defaultPrevented||(o.preventDefault(),r())};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[t,r]),n.jsxs("section",{className:"wb-question","aria-label":"Question from agent","data-testid":"question-picker",children:[n.jsxs("div",{className:"wb-question-head",children:[n.jsx("span",{className:"wb-question-kicker",children:"Needs your input"}),n.jsx(A,{className:"wb-question-skip",variant:"ghost",size:"sm",disabled:t,onClick:r,title:"Skip this question (Esc). The agent carries on without an answer.",children:"Skip"}),n.jsx("strong",{children:R8(e.question)})]}),e.options.length>0?n.jsx("div",{className:"wb-question-options",children:e.options.map((l,o)=>n.jsxs("button",{className:"wb-question-option","data-recommended":l.recommended||void 0,disabled:t,onClick:()=>s(l.label,l.id),children:[n.jsx("span",{className:"wb-question-number",children:o+1}),n.jsxs("span",{children:[n.jsxs("span",{className:"wb-question-label",children:[l.label,l.recommended?n.jsx("em",{children:"Recommended"}):null]}),l.hint?n.jsx("small",{children:l.hint}):null]})]},l.id))}):null,e.allowOther?n.jsxs("form",{className:"wb-question-other",onSubmit:l=>{l.preventDefault(),i.trim()&&s(i.trim())},children:[n.jsx("input",{value:i,onChange:l=>a(l.target.value),placeholder:e.options.length?"Something else…":"Type your answer…",disabled:t}),n.jsx("button",{className:"ui-btn","data-variant":"accent",disabled:t||!i.trim(),children:"Answer"})]}):null,n.jsx("p",{className:"wb-question-note",children:"This answers a question. It does not approve an action. Esc skips it."})]})}function R8(e){const t=[];let s=0;for(const r of e.matchAll(/https:\/\/[^\s<>"']+/g)){const i=r[0].replace(/[.,;:!?)\]]+$/,""),a=r.index??0;a>s&&t.push(e.slice(s,a)),t.push(n.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",children:i},a)),s=a+i.length}return s<e.length&&t.push(e.slice(s)),t}function I8(e,t){return e.messages<=0?!1:e.chars>e.maxChars?!0:e.lastActivityAt===null||e.idleTimeoutMs===null?!1:t-Date.parse(e.lastActivityAt)>e.idleTimeoutMs}function P8(e){const t=e/864e5;if(t>=1&&Number.isInteger(t))return t===7?"1 week":`${t} day${t===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 M8(e){const{lifetime:t,startedAt:s,now:r,timezone:i}=e;if(!t||t.messages<=0)return{text:"New conversation",title:"Nothing has been said in this one yet.",tone:"quiet"};const a=`${Math.round(t.maxChars/1e3)}k characters`,l=(t.idleTimeoutMs===null?`A conversation ends once its transcript grows past ${a}. `:`A conversation ends after ${P8(t.idleTimeoutMs)} idle, or once its transcript grows past ${a}. `)+"What the agent remembers about you carries over.",o=`${t.messages} message${t.messages===1?"":"s"}`;if(I8(t,r))return{text:`${o} · your next message starts a fresh one`,title:l,tone:"note"};const c=s?Fe(s,r):"";return{text:c===""?o:`${o} · started ${c}`,title:s?`Started ${nt(s,i)}. ${l}`:l,tone:"quiet"}}function D8({text:e,onDelete:t}){const[s,r]=d.useState(!1),[i,a]=d.useState(null);return n.jsx("div",{className:"wb-carryover","data-testid":"chat-carryover",children:n.jsxs(Tt,{summary:"Carried over from the previous conversation",children:[n.jsx("p",{className:"wb-carryover-text",children:e}),n.jsxs(ae,{align:"end",children:[i?n.jsx("span",{className:"critical",role:"alert",children:i}):null,n.jsx(A,{size:"sm",variant:"danger-ghost",disabled:s,onClick:()=>{r(!0),a(null),t().catch(l=>{a(l instanceof Error?l.message:String(l)),r(!1)})},children:"Delete note"})]})]})})}function ST(e){return e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function CT(e,t){return e.members.map(s=>t.find(r=>r.id===s)).filter(s=>s!==void 0)}function O8(e,t){var i;const s=CT(e,t),r=e.members.filter(a=>!t.some(l=>l.id===a));if(!t.some(a=>a.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 a=r.length>0?`: ${r.join(", ")} ${r.length===1?"was":"were"} removed from buddi`:"";return{kind:"alone",text:`Only ${((i=s[0])==null?void 0:i.name)??e.coordinator} is left here${a}.`,action:"Add a member"}}return null}function L8(){return n.jsx("span",{className:"ui-avatar group-gone-face","aria-hidden":"true",children:"?"})}function F8({group:e,agents:t,onClose:s,onSaved:r}){const[i,a]=d.useState(!1),[l,o]=d.useState(null),c=[e.coordinator,...e.members.filter(g=>g!==e.coordinator)],u=e.members.length>2,h=Uj(t).filter(g=>!e.members.includes(g.id)),f=!t.some(g=>g.id===e.coordinator),m=async g=>{a(!0),o(null);try{r(await Ve.updateGroup(e.id,g))}catch(v){o(v instanceof ve?v.message:String(v))}finally{a(!1)}},p=g=>void m({members:e.members.filter(v=>v!==g)});return n.jsxs(Ye,{title:"Members",onClose:s,children:[n.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?n.jsxs(V,{tone:"warning",children:[e.coordinator," coordinated this group and is no longer in buddi. Pick who coordinates now."]}):null,l?n.jsx(V,{tone:"critical",children:l}):null,n.jsx(rt,{children:c.map(g=>{const v=t.find(j=>j.id===g),b=g===e.coordinator;return v?n.jsx(et,{lead:n.jsx(cn,{agents:t,id:g}),title:v.name,sub:v.description,side:n.jsxs(n.Fragment,{children:[b?n.jsx(we,{tone:"accent",children:"Coordinator"}):null,f&&v.available?n.jsx(A,{size:"sm",disabled:i,onClick:()=>void m({coordinator:g}),children:"Make coordinator"}):null,n.jsx(Ys,{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=Et(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):n.jsx(et,{lead:n.jsx(L8,{}),title:n.jsx("span",{className:"group-gone-id",children:g}),sub:n.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?n.jsx(A,{size:"sm",disabled:i,onClick:()=>p(g),children:"Remove"}):void 0},g)})}),n.jsxs("div",{className:"group-add",children:[n.jsx("h3",{className:"group-add-title",children:"Add a member"}),h.length>0?n.jsx(rt,{children:h.map(g=>n.jsx(et,{lead:n.jsx(cn,{agents:t,id:g.id,size:"sm"}),title:g.name,sub:g.description,side:n.jsx(A,{size:"sm",disabled:i,onClick:()=>void m({members:[...e.members,g.id]}),children:"Add"})},g.id))}):n.jsx("p",{className:"group-quiet",children:"Everyone who can join a group is here."})]}),n.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 _8({group:e,onClose:t,onSaved:s}){const[r,i]=d.useState(e.name),[a,l]=d.useState(!1),[o,c]=d.useState(null),u=r.trim()!==""&&r.trim()!==e.name&&!a,h=async()=>{if(u){l(!0),c(null);try{s(await Ve.updateGroup(e.id,{name:r.trim()}))}catch(f){c(f instanceof ve?f.message:String(f)),l(!1)}}};return n.jsx(Dt,{title:"Rename group",onClose:t,foot:n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(A,{variant:"accent",disabled:!u,onClick:()=>void h(),children:a?"Renaming…":"Rename"})]}),children:n.jsx("form",{onSubmit:f=>{f.preventDefault(),h()},children:n.jsxs(le,{children:[n.jsx(oe,{label:"Name",hint:"What this team is for: Household finances, The move, Tax season.",children:n.jsx("input",{value:r,autoFocus:!0,maxLength:80,onFocus:f=>f.currentTarget.select(),onChange:f=>i(f.target.value)})}),o?n.jsx(V,{tone:"critical",children:o}):null]})})})}function ET(e){const[t,s]=d.useState(null);return d.useEffect(()=>{let r=!0;return Ve.group(e).then(i=>{var a;r&&s(((a=i.history)==null?void 0:a.conversations)??null)}).catch(()=>{}),()=>{r=!1}},[e]),t}function z8(e){return e===null?"Its conversations":e===0?"Nothing has been said yet, and its next conversation":`Its ${e} ${e===1?"conversation":"conversations"}`}function U8({group:e,onClose:t,onCleared:s}){const r=ET(e.id),[i,a]=d.useState(!1),[l,o]=d.useState(null),c=async()=>{a(!0),o(null);try{await Ve.clearGroup(e.id),s()}catch(h){o(h instanceof ve?h.message:String(h)),a(!1)}},u=r===0;return n.jsxs(Dt,{title:`Clear the history of ${e.name}?`,onClose:t,foot:n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(A,{variant:"danger",disabled:i||u,"data-testid":"group-clear-confirm",onClick:()=>void c(),children:i?"Clearing…":"Clear history"})]}),children:[n.jsx("p",{className:"group-dialog-text",children:u?"Nothing has been said in this group yet, so there is nothing to clear.":`${z8(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?n.jsx(V,{tone:"critical",children:l}):null]})}function B8({group:e,agents:t,onClose:s,onDeleted:r}){const i=ET(e.id),[a,l]=d.useState(!1),[o,c]=d.useState(null),u=CT(e,t).map(m=>m.name),h=async()=>{l(!0),c(null);try{const{undoUntil:m}=await Ve.deleteGroup(e.id);r(m)}catch(m){c(m instanceof ve?m.message:String(m)),l(!1)}},f=i===null?"its conversations":i===0?"nothing said yet":`its ${i} ${i===1?"conversation":"conversations"}`;return n.jsxs(Dt,{title:`Delete ${e.name}?`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(A,{variant:"danger",disabled:a,"data-testid":"group-delete-confirm",onClick:()=>void h(),children:a?"Deleting…":"Delete group"})]}),children:[n.jsxs("p",{className:"group-dialog-text",children:["The group goes with ",f," and what it remembers."," ",u.length>0?`${ST(u)} ${u.length===1?"is":"are"} not touched, and files it made stay in Files.`:"Files it made stay in Files."]}),o?n.jsx(V,{tone:"critical",children:o}):null]})}const yd=320,AT="buddi.chatWidth";function W8({timezone:e,agents:t,agentId:s,defaultAgentId:r=null,group:i=null,onGroupAction:a,onSelectAgent:l,onWorking:o,attention:c,agentsInHeader:u,narrow:h,canvasOpen:f,onOpenCanvas:m,onCloseCanvas:p,newConversationSignal:g,requestedConversationId:v,requestedTab:b,onConversationOpened:j}){var Ay,Ty,$y,Ry,Iy,Py,My;const x=Ef(),[w,y]=d.useState([]),[k,N]=d.useState(null),[S,C]=d.useState(null),[E,R]=d.useState(null),[I,L]=d.useState([]),[F,T]=d.useState([]),[M,P]=d.useState(null),[D,O]=d.useState(!1),[H,B]=d.useState(new Map),[Y,W]=d.useState(null),[q,_]=d.useState(j8),[X,Q]=d.useState([]),[ee,fe]=d.useState(!1),Le=d.useRef(0),Ie=d.useRef(null),[_e,U]=d.useState(!1),ie=d.useRef(g??0),J=d.useRef(s),ye=d.useRef({agentId:s,conversationId:k});ye.current={agentId:s,conversationId:k};const ge=q[k??""]??[],[$e,De]=d.useState(null),[Je,Ue]=d.useState(null),[be,Be]=d.useState(null),[at,He]=d.useState([]),[kt,Yt]=d.useState(!1),[ne,ke]=d.useState(()=>Date.now()),[Qe,ct]=d.useState(H8),Nt=d.useRef(null),[ut,xn]=d.useState(null),[Yn,Z]=d.useState(!1),[Re,Xe]=d.useState(null),[jt,G]=d.useState(aT),he=d.useRef(jt);he.current=jt;const We=d.useRef(null),[ze,sn]=d.useState(null),As=d.useCallback(K=>{G(K),lT(K),K||Ql()},[]),[Cn,Ts]=d.useState(null),[$s,Se]=d.useState(null);d.useEffect(()=>{if(!s)return;const K=UL(s);K&&Xe({text:K,at:Date.now()})},[s]);const Ee=i?`group:${i.id}`:s??null,Ke=[...t.top,...t.middle,...t.bottom],me=Ke.find(K=>K.id===s)??null,Jn=de(()=>$.providerAccounts(),[]),Ln=i?i.members.map(K=>Ke.find(se=>se.id===K)).filter(K=>!!K):[],[Qs,so]=d.useState(null),Ui=D?Qs??s??null:null;d.useEffect(()=>{o==null||o(Ui)},[Ui,o]),d.useEffect(()=>()=>o==null?void 0:o(null),[o]),d.useEffect(()=>{let K=!1;return Ve.views().then(se=>{K||y(se.views??[])}).catch(()=>{}),()=>{K=!0}},[]),d.useEffect(()=>{if(!s)return;const K=J.current===s;if(J.current=s,K&&v&&v===ye.current.conversationId)return;let se=!1;return N(null),C(null),R(null),L([]),De(null),O(!1),W(null),Q([]),su(null),U(!1),xn(null),v?(v!=="new"?N(v):R(Ee),()=>{se=!0}):((i?Ve.groupConversations(i.id):Ve.conversations(s)).then(Ae=>{if(se)return;const Ce=[...Ae.conversations??[]].sort(K8)[0];Ce?(N(Ce.id),j==null||j(s,Ce.id)):R(Ee)}).catch(()=>{se||R(Ee)}),()=>{se=!0})},[s,i==null?void 0:i.id,Ee,v,j]);const Fn=d.useCallback(K=>Ve.conversation(K).then(se=>{if(ye.current.conversationId===K){if(se.agentId!==ye.current.agentId)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(se),L(Ae=>Ae.filter(Ce=>!tp(se,Ce)))}}).catch(se=>{ye.current.conversationId===K&&De(si(se))}),[]);d.useEffect(()=>{if(!k)return;let K=!1;return B(new Map),T([]),Ve.conversation(k).then(se=>{if(!K){if(se.agentId!==s)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(se),L(Ae=>Ae.filter(Ce=>!tp(se,Ce)))}}).catch(se=>{K||De(si(se))}),()=>{K=!0}},[k,s]),d.useEffect(()=>{if(!k)return;let K=!1;const se=window.setInterval(()=>{Ve.conversation(k).then(Ae=>{K||Ae.agentId!==ye.current.agentId||(C(Ae),L(Ce=>Ce.filter(Ze=>!tp(Ae,Ze))))}).catch(()=>{})},3e3);return()=>{K=!0,window.clearInterval(se)}},[k,s]),d.useEffect(()=>{if(!k)return;const K=mf({url:Ve.streamUrl(k),onEvent:se=>{var Ae;switch(se.name){case"run.started":We.current=null,O(!0),P(null),so(hn(se.data.agentId));break;case"live":{const Ce=hn(se.data.runId)??"",Ze=Number(se.data.turn??0),Ge=se.data.kind==="thinking"?"thinking":"text",En=hn(se.data.text)??"",Cr=Date.now();if(Ge==="text"){const Zs=We.current;We.current=Zs&&Zs.runId===Ce&&Zs.turn===Ze?{...Zs,text:Zs.text+En}:{runId:Ce,turn:Ze,text:En}}P(Zs=>{const Ia=Zs&&Zs.runId===Ce&&Zs.turn===Ze?Zs:{runId:Ce,turn:Ze,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return Ge==="thinking"?{...Ia,thinking:Ia.thinking+En,thinkingStartedAt:Ia.thinkingStartedAt??Cr}:{...Ia,text:Ia.text+En,textStartedAt:Ia.textStartedAt??Cr}});break}case"live.snapshot":{const Ce=hn(se.data.runId)??"",Ze=Number(se.data.turn??0),Ge=hn(se.data.text)??"",En=hn(se.data.thinking)??"",Cr=Number(se.data.startedAt??Date.now());We.current={runId:Ce,turn:Ze,text:Ge},P({runId:Ce,turn:Ze,text:Ge,thinking:En,thinkingStartedAt:En?Cr:null,textStartedAt:Ge?Cr:null,settled:!1});break}case"live.settle":{const Ce=hn(se.data.runId)??"",Ze=Number(se.data.turn??0);P(Ge=>Ge&&Ge.runId===Ce&&Ge.turn===Ze?{...Ge,settled:!0}:Ge);break}case"tool.called":{const Ce=hn(se.data.toolUseId)??hn(se.data.id),Ze=hn(se.data.name)??hn(se.data.tool)??"tool";Ce&&T(Ge=>[...Ge.filter(En=>En.toolUseId!==Ce),{toolUseId:Ce,name:Ze,startedAt:Date.now()}]);break}case"tool.result":{const Ce=hn(se.data.toolUseId)??hn(se.data.id);Ce&&T(Ze=>Ze.filter(Ge=>Ge.toolUseId!==Ce)),Fn(k);break}case"reaction":Fn(k);break;case"message.appended":Fn(k).then(()=>{P(Ce=>Ce!=null&&Ce.settled?null:Ce)});break;case"awaiting-approval":{const Ce=hn(se.data.approvalId)??hn(se.data.actionId),Ze=hn(se.data.toolUseId);Ce&&Ze&&B(Ge=>new Map(Ge).set(Ze,Ce)),T(Ge=>Ge.filter(En=>En.toolUseId!==Ze)),Fn(k);break}case"run.finished":{O(!1),T([]),P(null),so(null);const Ce=hn(se.data.message);De(Ce??null);const Ze=((Ae=We.current)==null?void 0:Ae.text.trim())??"";We.current=null,!Ce&&Ze!==""&&he.current&&mh(Ze,k).then(Ge=>{Ge&&sn(Ge)}),Fn(k);break}}}});return()=>K.close()},[k,Fn]),d.useEffect(()=>{const K=window.setInterval(()=>ke(Date.now()),F.length===0?6e4:1e3);return()=>window.clearInterval(K)},[F.length]);const Bi=de(()=>s&&k?$.browser({agentId:s,conversationId:k}):Promise.resolve(void 0),[s,k],1500),Sr=Bi.error?void 0:Bi.data,ti=Sr!=null&&Sr.session&&Sr.session.agentId===s&&Sr.session.conversationId===k?Sr:void 0,Ut=c8(ti,s,k),Xs=(Ut==null?void 0:Ut.id)??null,[ro,QI]=d.useState(null),dy=ti==null?void 0:ti.mode;d.useEffect(()=>{Ut&&s&&k&&QI({agentId:s,conversationId:k,tab:u8(Ut,dy)})},[Xs,dy,s,k]);const XI=ro&&ro.agentId===s&&ro.conversationId===k&&!ge.includes(ro.tab.id)?ro.tab:null,vn=Ut??XI,ZI=d.useMemo(()=>d8((S==null?void 0:S.messages)??[]),[S]),[eP,su]=d.useState(null),tP=d.useMemo(()=>G6({messages:(S==null?void 0:S.messages)??[],descriptors:w}),[S,w]),$a=b5(tP,k??null),Bf=N5(i?null:s),hy=d.useMemo(()=>k5((S==null?void 0:S.messages)??[]),[S]),_n=d.useMemo(()=>{const se=q6({messages:(S==null?void 0:S.messages)??[],descriptors:w,awaiting:H,served:$a.served,...vn?{folded:wd}:{},gathered:x8}).filter(Ce=>Ce.source==="approval"||!ge.includes(Ce.id)),Ae=Y?f0(se,Y):null;if(Ae&&(Ae.props={...Ae.props,focus:Y}),Y&&!Ae&&!ge.includes(Y)&&!se.some(Ce=>Ce.id===Y)){const Ce=X6((S==null?void 0:S.messages)??[],Y,{redactInputOf:wd});Ce&&!wd.has(Ce.tool)&&se.push(Ce)}vn&&se.push(vn);for(const Ce of X)se.push(c3(Ce));return Bf&&se.unshift(S5(Bf,hy)),ut?[...se,C5(ut)]:se},[S,w,H,ut,Xs,vn==null?void 0:vn.title,Y,q,k,X,$a.served,Bf,hy]),nP=d.useMemo(()=>{var se;const K=[];for(const Ae of(S==null?void 0:S.messages)??[]){if(Ae.role!=="user"||Ae.speaker&&Ae.speaker!=="owner")continue;const Ce=(se=Ae.blocks.find(Ze=>Ze.type==="text"))==null?void 0:se.text.trim();Ce&&K.unshift(Ce)}return K},[S]),Wf=d.useMemo(()=>_n.filter(K=>K.source==="approval"),[_n]),ru=Wf.at(-1)??null,iu=d.useMemo(()=>[...Wf.map(K=>({approvalId:K.props.approvalId,toolUseId:K.id})),...((S==null?void 0:S.delegatedApprovals)??[]).map(K=>({approvalId:K.approvalId,toolUseId:K.toolUseId??"",askedBy:Y8(K.chain,Ke)}))],[Wf,S==null?void 0:S.delegatedApprovals]),io=d.useMemo(()=>{for(let K=_n.length-1;K>=0;K-=1){const se=_n[K];if(se!=null&&se.substantial)return se.id}return null},[_n]),au=d.useRef(null),Hf=((Ay=_n.filter(K=>(K.source!=="browser"||K.pinned===!0)&&K.id!==jx).at(-1))==null?void 0:Ay.id)??((Ty=_n.filter(K=>K.id!==jx).at(-1))==null?void 0:Ty.id)??null;d.useEffect(()=>{if(io&&io!==au.current){au.current=io,W(io);return}Y===null&&Hf&&W(Hf)},[io,Y,Hf]);const fy=d.useRef($a.live);d.useEffect(()=>{const K=fy.current;fy.current=$a.live;const se=[...$a.live].filter(Ze=>!K.has(Ze));if(se.length===0||ru||Y!==null&&Y!==au.current)return;const Ce=[..._n].reverse().find(Ze=>Ze.source==="descriptor"&&Ze.renderer==="preview"&&Ze.props.target!==null&&se.includes(pl(Ze.props.target)));Ce&&W(Ce.id)},[$a.live,_n,ru,Y]);const my=d.useRef(null);d.useEffect(()=>{Xs!==my.current&&(my.current=Xs,Xs&&!ru&&W(Xs))},[Xs,ru]);const py=d.useRef(null),ao=b==="browser"?(vn==null?void 0:vn.id)??null:null;d.useEffect(()=>{!ao||py.current===ao||(py.current=ao,W(ao))},[ao]);const Kf=(vn==null?void 0:vn.id)??null;d.useEffect(()=>{!Kf||!Y||S0((S==null?void 0:S.messages)??[],Y)!==null&&(su(Y),W(Kf))},[Kf,Y,S]);const gy=K=>{Q(se=>se.some(Ae=>Ae.artifactId===K.artifactId)?se:[...se,K]),W(vd(K.artifactId)),h&&(m==null||m())},lu=!i&&me&&!me.available?NA(me):null,xy=i?n.jsx("span",{className:"wb-group-stack","aria-hidden":"true",children:i.members.slice(0,2).map(K=>{const se=Ke.find(Ae=>Ae.id===K);return n.jsx(vf,{className:"wb-group-chip",id:K,name:(se==null?void 0:se.name)??"?",face:se,initials:1},K)})}):null,Wi=i&&Ke.length>0?O8(i,Ke):null,vy=(Wi==null?void 0:Wi.kind)==="coordinator",jy=Xg(i?null:me),Vf=((S==null?void 0:S.offers)??[]).filter(K=>!at.includes(K.id)&&Date.parse(K.expiresAt)>ne),sP=me&&$s===me.id?Cn:(me==null?void 0:me.thinking)??null,rP=K=>{if(!me)return;const se=me.id;Se(se),Ts(K),$.setAgentEngine(se,{thinking:K}).catch(Ae=>{Se(null),De(Ae instanceof ve?Ae.message:String(Ae))})},Gf=(K,se)=>{if(!s)return;const Ae=se.map(Ge=>Ge.artifactId),Ce=D,Ze={id:`optimistic:${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:K},...se.map(Ge=>({type:"attachment",artifactId:Ge.artifactId,filename:Ge.filename,mime:Ge.mime,kind:Ge.kind,sizeBytes:Ge.sizeBytes}))],...Ce?{speaker:pT}:{}};L(Ge=>Ce?[...Ge,Ze]:[Ze]),De(null),Ue(null),O(!0),(i?Ve.sendToGroup(i.id,{...k?{conversationId:k}:{},text:K,attachmentIds:Ae}):Ve.send(s,{...k?{conversationId:k}:{},text:K,attachmentIds:Ae})).then(async Ge=>{ye.current.agentId!==s||ye.current.conversationId!==k||(Ue(Ge.rolledOver===!0?"(New thread — the room had grown long. Where it stopped carries over as a summary.)":null),Ge.conversationId!==k?(C(null),N(Ge.conversationId)):await Fn(Ge.conversationId),Ge.queued===!0&&L(En=>En.filter(Cr=>Cr.id!==Ze.id)),j==null||j(s,Ge.conversationId))}).catch(Ge=>{L(En=>En.filter(Cr=>Cr.id!==Ze.id)),De(si(Ge)),O(!1)})},iP=K=>{var Ae;const se=Vf.find(Ce=>Ce.id===K);if(((Ae=se==null?void 0:se.handoff)==null?void 0:Ae.kind)==="install"){window.location.hash=P4(se.handoff.package);return}De(null),Be(K),He(Ce=>[...Ce,K]),$.takeOffer(K,k??void 0).then(Ce=>{if(Ce.agentId&&Ce.agentId!==(me==null?void 0:me.id)){window.location.hash=st(Ce.agentId,Ce.conversationId??null);return}Ce.runId&&(Ue(null),O(!0)),k&&Fn(k)}).catch(Ce=>{He(Ze=>Ze.filter(Ge=>Ge!==K)),De(si(Ce)),k&&Fn(k)}).finally(()=>Be(null))},aP=(K,se)=>wy({answer:K,...se?{optionId:se}:{}}),lP=()=>wy({answer:"",skipped:!0}),wy=K=>{const se=S==null?void 0:S.question;se&&(De(null),Yt(!0),O(!0),Ve.answerQuestion(se.id,K).then(()=>{if(k)return Fn(k)}).catch(Ae=>{De(si(Ae)),O(!1)}).finally(()=>Yt(!1)))},oP=()=>{if(s){if(ut){xn(null);return}Z(!0),$.agentProfile(s).then(K=>{xn(K),W(wx(K.id)),h&&(m==null||m())}).catch(K=>De(si(K))).finally(()=>Z(!1))}},cP=K=>{Xe({text:K.prompt,at:Date.now()}),l(K.agentId),h&&(p==null||p())},uP=()=>{k&&Ve.cancel(k).catch(K=>De(si(K))).finally(()=>{O(!1),T([])})},ou=d.useCallback(()=>{if(N(null),C(null),L([]),O(!1),De(null),Ue(null),T([]),B(new Map),W(null),Q([]),su(null),au.current=null,i){Ve.startGroupConversation(i.id).then(({conversationId:K})=>{N(K),s&&(j==null||j(s,K))}).catch(K=>De(si(K)));return}R(Ee),s&&(j==null||j(s,"new"))},[s,i,Ee,j]);d.useEffect(()=>{g&&g!==ie.current&&(ie.current=g,ou())},[g,ou]);const yy=K=>{k&&Fn(k),$.overview().catch(()=>{}),K.state!=="pending"&&B(se=>new Map([...se].filter(([,Ae])=>Ae!==K.id)))},cu=d.useRef(!1);d.useEffect(()=>{const K=Ae=>{if(!cu.current)return;const Ce=Math.max(yd,Math.min(720,Ae.clientX-52));ct(Ce)},se=()=>{if(cu.current){cu.current=!1;try{Qe!==null&&window.localStorage.setItem(AT,String(Qe))}catch{}}};return window.addEventListener("pointermove",K),window.addEventListener("pointerup",se),()=>{window.removeEventListener("pointermove",K),window.removeEventListener("pointerup",se)}},[Qe]);const dP=(($y=Ke.find(K=>K.id===r))==null?void 0:$y.name)??null,by=i?[]:Uz(me,dP),ky=!(S&&S.conversationId===k)&&!(!k&&E!==null&&E===Ee),Ny=ky?n.jsx("div",{className:"wb-chat-loading","data-testid":"chat-loading","aria-busy":"true"}):!i&&me?n.jsx(VA,{quiet:!0,still:!0,className:"wb-chat-field",children:n.jsxs("div",{className:"wb-chat-opening","data-testid":"chat-opening",children:[n.jsx(cn,{agents:Ke,id:me.id,size:"xl"}),n.jsx("h2",{className:"wb-chat-hello",children:`Hi, I'm ${me.name}.`}),n.jsx("p",{className:"wb-chat-intro",children:Bz(me)}),by.length>0?n.jsx("div",{className:"wb-starters",role:"group","aria-label":`Things to ask ${me.name}`,children:by.map(K=>n.jsx("button",{type:"button",className:"wb-starter",onClick:()=>{var se;Xe({text:K,at:Date.now()}),(se=Ie.current)==null||se.focus()},children:K},K))}):null]})}):null,Sy=n.jsx(u5,{renderables:_n,activeId:(Y?(Ry=f0(_n,Y))==null?void 0:Ry.id:null)??Y,onActivate:W,onClose:K=>{ut&&K===wx(ut.id)?xn(null):X.some(se=>vd(se.artifactId)===K)?Q(se=>se.filter(Ae=>vd(Ae.artifactId)!==K)):k&&_(se=>{const Ae={...se,[k]:[...new Set([...se[k]??[],K])]};return C0(Ae),Ae}),Y===K&&W(null)},timezone:e,onDecided:yy,onChangeAgent:cP,agents:Ke,browserPanel:vn?n.jsx(i8,{status:ti,error:Bi.error,reload:Bi.reload,steps:ZI,live:Ut!==null,focusedStepId:eP},vn.id):null,descriptors:w,grantedTools:i?Ln.flatMap(K=>K.tools??[]):(me==null?void 0:me.tools)??[],...me?{agentName:me.name}:{},loading:ky,...!i&&me?{face:n.jsx(cn,{agents:Ke,id:me.id,size:"xl"})}:{}}),Cy=(Py=(Iy=[...(S==null?void 0:S.messages)??[],...I].find(K=>K.role==="user"))==null?void 0:Iy.blocks.find(K=>K.type==="text"))==null?void 0:Py.text.trim(),Ey=Cy?Cy.split(`
109
+ `)[0]:"New conversation",Ra=M8({lifetime:(S==null?void 0:S.lifetime)??null,startedAt:(S==null?void 0:S.startedAt)??null,now:ne,timezone:e});return n.jsxs(n.Fragment,{children:[n.jsxs("section",{className:"wb-chat",ref:Nt,style:h||Qe===null?void 0:{width:Qe},"data-sized":!h&&Qe!==null?"true":void 0,"data-testid":"chat-column","data-dropping":ee||void 0,onDragEnter:K=>{Vu(K)&&(K.preventDefault(),Le.current+=1,fe(!0))},onDragOver:K=>{Vu(K)&&(K.preventDefault(),K.dataTransfer.dropEffect="copy")},onDragLeave:K=>{Vu(K)&&(Le.current=Math.max(0,Le.current-1),Le.current===0&&fe(!1))},onDrop:K=>{var se;Vu(K)&&(K.preventDefault(),Le.current=0,fe(!1),s&&((se=Ie.current)==null||se.addFiles(K.dataTransfer.files)))},children:[ee?n.jsx("div",{className:"wb-drop","aria-hidden":"true",children:n.jsxs("div",{className:"wb-drop-card",children:[n.jsx(V8,{}),n.jsx("strong",{children:"Drop to attach"}),n.jsx("span",{children:me?`It goes with your next message to ${me.name}`:"Pick an agent first"})]})}):null,n.jsxs("header",{className:"wb-chat-head","data-testid":"chat-head",...!i&&me?Yc(qc(me)):{},children:[n.jsxs("div",{className:"wb-head-row",children:[i?n.jsx("span",{className:"wb-head-face","aria-hidden":"true",children:xy}):me?n.jsx("a",{className:"wb-head-face",href:Et(me.id),"aria-label":`${me.name}'s page`,children:n.jsx(cn,{agents:Ke,id:me.id})}):null,n.jsxs("div",{className:"wb-head-text",children:[i?n.jsx("span",{className:"wb-head-title",children:i.name}):n.jsx("span",{className:"wb-head-title",title:Ey,children:Ey}),n.jsx("span",{className:"wb-head-meta","data-tone":Ra.tone,title:i?`${Ln.map(K=>K.name).join(", ")}. Coordinator: ${(me==null?void 0:me.name)??i.coordinator}.`:Ra.title,children:i?`${Ln.map(K=>K.name).join(", ")} · ${Ra.text}`:me?n.jsxs(n.Fragment,{children:[n.jsx("a",{className:"wb-head-name",href:Et(me.id),title:`${me.name}'s page`,children:me.name})," ",n.jsxs("span",{className:"wb-head-handle",children:["@",me.handle]}),` · ${Ra.tone==="quiet"&&Ra.text==="New conversation"?`on ${x}`:Ra.text}`]}):"No agent"})]}),n.jsx("button",{className:"ui-icon-btn wb-head-more","data-size":"sm","aria-label":"New chat",title:"New chat",disabled:!s,onClick:()=>{U(!1),ou()},children:n.jsx(ce,{name:"plus",size:16})}),n.jsx("button",{className:"ui-icon-btn wb-head-more","aria-label":"History",title:"Earlier conversations","aria-expanded":_e,"data-open":_e?"true":void 0,disabled:!s,onClick:()=>U(K=>!K),children:n.jsx(G8,{})}),h?n.jsxs("button",{className:"ui-btn",onClick:m,disabled:_n.length===0,children:["Canvas",_n.length>0?` (${_n.length})`:""]}):null,i?n.jsx(A0,{disabled:!1,label:"More about this group",title:i.name,sub:ST(Ln.map(K=>K.name)),face:xy,items:[{label:"Members",hint:`${i.members.length} agents · ${me?`${me.name} coordinates`:"no coordinator"}`,testId:"group-members",onSelect:()=>a==null?void 0:a("members")},{label:"Rename…",hint:"What this team is for",testId:"group-rename",onSelect:()=>a==null?void 0:a("rename")},"separator",{label:"Clear history…",hint:"Keeps the group and its members",testId:"group-clear",onSelect:()=>a==null?void 0:a("clear")},{label:"Delete group…",hint:"With its history; the agents stay",tone:"critical",testId:"group-delete",onSelect:()=>a==null?void 0:a("delete")}]}):n.jsx(A0,{disabled:!s,label:"More about this agent",title:(me==null?void 0:me.name)??"Agent",...me?{sub:`@${me.handle}`,face:n.jsx(cn,{agents:Ke,id:me.id,size:"sm"})}:{},items:[{label:ut?"Close properties":"Properties",hint:"What this agent can do, on the Canvas",testId:"agent-properties",disabled:Yn,onSelect:oP},...me?[{label:"Set up",hint:"Identity, model and access",href:Et(me.id,"setup")},{label:"Open agent page",hint:"Profile, activity and setup",href:Et(me.id)}]:[]]})]}),u?n.jsx(CA,{agents:t,currentId:s,attention:c,onSelect:l,orientation:"horizontal",...Ui?{working:new Set([Ui])}:{}}):null]}),_e&&s?n.jsx(v8,{agentId:s,...i?{groupId:i.id}:{},currentId:k,timezone:e,onNew:()=>{U(!1),ou()},onSelect:K=>{if(K===k){U(!1);return}U(!1),C(null),L([]),O(!1),W(null),De(null),Ue(null),Q([]),N(K),j==null||j(s,K,!1)}}):null,s&&k?n.jsx(l8,{agentId:s,conversationId:k},`${s}:${k}`):null,$e?n.jsx("div",{className:"wb-chat-notice",children:n.jsx(re,{message:$e})}):null,Je?n.jsx("div",{className:"wb-chat-notice","data-testid":"chat-notice",children:Je}):null,S!=null&&S.carriedOver?n.jsx(D8,{text:S.carriedOver,onDelete:async()=>{const K=S.conversationId;await Ve.deleteCarryOver(K),C(se=>{if(!se||se.conversationId!==K)return se;const{carriedOver:Ae,...Ce}=se;return Ce})}},S.conversationId):null,n.jsx(aw,{messages:[...(S==null?void 0:S.messages)??[],...I],live:F,now:ne,working:D,partial:M,agents:Ke,...S!=null&&S.runs?{runs:S.runs}:{},...s&&k?{onContinue:()=>Gf("continue",[])}:{},...i?{speakers:Ke,coordinatorId:i.coordinator}:{},...Qs?{workingAs:((My=Ke.find(K=>K.id===Qs))==null?void 0:My.name)??Qs}:{},onOpenFile:gy,onReadAloud:(K,se)=>{sn(null),mh(se,k??void 0,K).then(Ae=>{Ae&&sn(Ae)})},onOpen:K=>{if(vn){const se=S0([...(S==null?void 0:S.messages)??[],...I],K);if(se){su(se),W(vn.id),h&&(m==null||m());return}}k&&_(se=>{const Ae={...se,[k]:(se[k]??[]).filter(Ce=>Ce!==K)};return C0(Ae),Ae}),W(K),h&&(m==null||m())},...me?{agentName:me.name,agentId:me.id}:{},...Ny?{empty:Ny}:{},emptyHint:i?`Give the team a task once; ${me?me.name:"the coordinator"} brings members in. @ addresses one of them.`:me?`Nothing here yet. Ask ${me.name} for something.`:"Loading agents…"}),Vf.length>0?n.jsx("div",{className:"wb-offers","data-testid":"chat-offers",children:Vf.map(K=>{var se,Ae;return n.jsx("button",{className:"ui-btn",disabled:be!==null,title:((se=K.handoff)==null?void 0:se.kind)==="install"?`Opens ${K.handoff.title}'s install sheet`:K.prompt,"data-handoff":(Ae=K.handoff)==null?void 0:Ae.kind,onClick:()=>iP(K.id),children:K.label},K.id)})}):null,Wi?n.jsx("div",{className:"wb-composer-blocked","data-testid":"group-problem","data-kind":Wi.kind,children:n.jsx(V,{tone:vy?"warning":void 0,role:"status",children:n.jsxs("span",{children:[Wi.text," ",n.jsx("button",{type:"button",className:"wb-link-btn",onClick:()=>a==null?void 0:a("members"),children:Wi.action})]})})}):null,lu?n.jsx("div",{className:"wb-composer-blocked","data-testid":"composer-blocked",children:n.jsxs(V,{tone:"warning",role:"status",children:[lu," ",n.jsx("a",{href:Pe(jy.section),children:jy.label})]})}):iu.length>0?n.jsx(MB,{approvals:iu,timezone:e,now:ne,version:S,onDecided:yy,onSay:K=>Gf(K,[]),onOpenFull:K=>{W(K),h&&(m==null||m())}}):null,lu||iu.length>0?null:S!=null&&S.question?n.jsx($8,{question:S.question,disabled:kt||D,onAnswer:aP,onSkip:lP},S.question.id):null,lu||vy?null:n.jsxs("div",{hidden:iu.length>0||!!(S!=null&&S.question),"data-testid":"composer-slot",children:[n.jsx(ow,{ref:Ie,disabled:!s,running:D,onSend:Gf,onStop:uP,agentName:i?i.name:(me==null?void 0:me.name)??"the agent",draft:Re,history:nP,threadKey:k??(i?`group:${i.id}`:s),model:i?null:(me==null?void 0:me.model)??null,setupHref:i?null:me?Et(me.id,"setup","brain"):null,thinking:sP,...!i&&me&&fE(mE(me,Jn.data))?{onThinking:rP}:{},...i?{mentions:Ln.map(K=>({handle:K.handle,name:K.name}))}:{},onOpenFile:gy,conversationId:k??null,readAloud:jt,onReadAloud:As}),ze?n.jsx("p",{className:"wb-voice-note",role:"status",children:ze}):null]})]}),h?f?n.jsxs("div",{className:"wb-sheet",role:"dialog","aria-label":"Canvas",children:[n.jsxs("div",{className:"wb-sheet-head",children:[n.jsx("strong",{children:"Canvas"}),n.jsx("button",{className:"ui-btn",onClick:p,children:"Close"})]}),Sy]}):null:n.jsxs(n.Fragment,{children:[n.jsx("button",{className:"wb-grip","aria-label":"Resize the conversation column",onPointerDown:K=>{var se,Ae;cu.current=!0,(Ae=(se=K.currentTarget).setPointerCapture)==null||Ae.call(se,K.pointerId)},onKeyDown:K=>{const se=Ae=>{var Ce;return Ae??((Ce=Nt.current)==null?void 0:Ce.offsetWidth)??yd};K.key==="ArrowLeft"&&ct(Ae=>Math.max(yd,se(Ae)-16)),K.key==="ArrowRight"&&ct(Ae=>Math.min(720,se(Ae)+16))}}),Sy]})]})}function H8(){try{const e=window.localStorage.getItem(AT),t=Number(e);return e!==null&&Number.isFinite(t)&&t>=yd?t:null}catch{return null}}function K8(e,t){return Date.parse(t.lastMessageAt??t.startedAt??t.createdAt??"")-Date.parse(e.lastMessageAt??e.startedAt??e.createdAt??"")}function hn(e){return typeof e=="string"&&e!==""?e:null}function si(e){return e instanceof ve||e instanceof Error?e.message:String(e)}function tp(e,t){var r;const s=(r=t.blocks.find(i=>i.type==="text"))==null?void 0:r.text.trim();if(!s)return!0;for(let i=e.messages.length-1;i>=0;i-=1){const a=e.messages[i];if(a.role!=="user")continue;const l=a.blocks.find(o=>o.type==="text");if(l)return l.text.trim()===s}return!1}function Vu(e){var s;const t=(s=e.dataTransfer)==null?void 0:s.types;return!!(t&&Array.from(t).includes("Files"))}function V8(){return n.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:[n.jsx("path",{d:"M14 4v13M8.5 11.5 14 17l5.5-5.5"}),n.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 G8(){return n.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:[n.jsx("path",{d:"M2.6 8a5.4 5.4 0 1 0 1.6-3.8"}),n.jsx("path",{d:"M2.4 2.6v2.6h2.6M8 5.2V8l2 1.3"})]})}function q8(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",fill:"currentColor",children:[n.jsx("circle",{cx:"8",cy:"3.4",r:"1.35"}),n.jsx("circle",{cx:"8",cy:"8",r:"1.35"}),n.jsx("circle",{cx:"8",cy:"12.6",r:"1.35"})]})}function A0({items:e,disabled:t,label:s,title:r,sub:i,face:a}){const[l,o]=d.useState(!1),c=d.useRef(null);d.useEffect(()=>{if(!l)return;const h=m=>{c.current&&!c.current.contains(m.target)&&o(!1)},f=m=>{m.key==="Escape"&&o(!1)};return window.addEventListener("mousedown",h),window.addEventListener("keydown",f),()=>{window.removeEventListener("mousedown",h),window.removeEventListener("keydown",f)}},[l]);const u=h=>{const f=n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"ui-menu-item-text",children:h.label}),h.hint?n.jsx("span",{className:"ui-menu-item-hint",children:h.hint}):null]});return h.href?n.jsx("a",{className:"ui-menu-item",role:"menuitem",href:h.href,"data-tone":h.tone,onClick:()=>o(!1),children:f},h.label):n.jsx("button",{className:"ui-menu-item",role:"menuitem","data-testid":h.testId,"data-tone":h.tone,disabled:h.disabled,onClick:()=>{var m;o(!1),(m=h.onSelect)==null||m.call(h)},children:f},h.label)};return n.jsxs("div",{className:"wb-head-menu",ref:c,children:[n.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:t,onClick:()=>o(h=>!h),children:n.jsx(q8,{})}),l?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"wb-head-menu-scrim","aria-hidden":"true",onClick:()=>o(!1)}),n.jsxs("div",{className:"ui-menu wb-head-menu-list",role:"menu","aria-label":r,children:[n.jsxs("div",{className:"wb-head-menu-head","aria-hidden":"true",children:[a,n.jsxs("span",{className:"wb-head-menu-heading",children:[n.jsx("span",{className:"wb-head-menu-title",children:r}),i?n.jsx("span",{className:"wb-head-menu-sub",children:i}):null]})]}),e.map((h,f)=>h==="separator"?n.jsx("div",{className:"ui-menu-sep",role:"separator"},`sep-${f}`):u(h)),n.jsx("button",{type:"button",className:"ui-btn wb-head-menu-cancel",onClick:()=>o(!1),children:"Cancel"})]})]}):null]})}function Y8(e,t){const s=a=>{var l;return`@${((l=t.find(o=>o.id===a))==null?void 0:l.handle)??a}`},[r,...i]=e;return r===void 0?"":[s(r),...i.map(a=>`asked by ${s(a)}`)].join(", ")}let T0=!1;const J8=new Set(["missing","unconfigured","not-english"]);async function mh(e,t,s=null){const r=oT(s);try{const i=await Ve.say({text:e,...t?{conversationId:t}:{}});return a0(r)&&await N6(i.audioUrl,i.mime,s),null}catch(i){a0(r)&&Ql();const a=i instanceof ve&&i.detail&&typeof i.detail=="object"?i.detail.reason:void 0;return typeof a=="string"&&J8.has(a)&&(s!==null||!T0)?(T0=!0,i.message):null}}let ps=null;function Q8(e){if(xd(e)!==null)return!1;const t=pA(e);return t!==dn&&t!==yi}function X8({agent:e,agents:t,open:s,onOpenChange:r,navigate:i}){const a=d.useRef(null),l=d.useRef(s),o=`Ask ${e.name}`,[c,u]=d.useState(!1);return d.useEffect(()=>{if(s||!c||!ps)return;const h=mf({url:Ve.streamUrl(ps.conversationId),lastEventId:ps.lastEventId??null,onEvent:f=>{f.name==="run.finished"&&u(!1)}});return()=>h.close()},[s,c]),d.useEffect(()=>{const h=f=>{!f.altKey||f.ctrlKey||f.metaKey||f.code!=="Slash"||(f.preventDefault(),r(!s))};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[s,r]),d.useEffect(()=>{var h;l.current&&!s&&((h=a.current)==null||h.focus()),l.current=s},[s]),s?n.jsx(eW,{agent:e,agents:t,navigate:i,onClose:()=>r(!1),onBusy:u}):n.jsxs(hc,{children:[n.jsx(fc,{asChild:!0,children:n.jsx("button",{ref:a,type:"button",className:"wb-ask-fab","data-busy":c?"true":void 0,"aria-label":o,onClick:()=>r(!0),children:n.jsx(Z8,{busy:c})})}),n.jsx(mc,{children:n.jsx(pc,{className:"ui-tip",side:"left",sideOffset:8,children:o})})]})}function Z8({busy:e}){const[t,s]=d.useState(!1);return t?n.jsx(Nc,{size:"lg"}):n.jsx(Qc,{state:e?"working":"idle",className:"wb-ask-fab-face",onStillError:()=>s(!0)})}function eW({agent:e,agents:t,navigate:s,onClose:r,onBusy:i}){const a=d.useRef(null),[l,o]=d.useState(ps&&ps.agentId===e.id?ps.conversationId:null),[c,u]=d.useState(null),[h,f]=d.useState([]),[m,p]=d.useState([]),[g,v]=d.useState(null),[b,j]=d.useState(!1),[x,w]=d.useState(!1),[y,k]=d.useState(null),[N,S]=d.useState(null),[C,E]=d.useState(Date.now()),[R,I]=d.useState(aT),L=d.useRef(R);L.current=R;const[F,T]=d.useState(null),M=d.useRef(null),P=d.useCallback(async q=>{try{const _=await Ve.conversation(q);u(_),f(X=>X.filter(Q=>!tW(_,Q)))}catch{}},[]);d.useEffect(()=>{l&&P(l)},[l,P]),d.useEffect(()=>{if(!l)return;const q=mf({url:Ve.streamUrl(l),onEvent:_=>{var X;switch(_.name){case"run.started":M.current=null,j(!0),v(null);break;case"live":{const Q=Qn(_.data.runId)??"",ee=Number(_.data.turn??0),fe=_.data.kind==="thinking"?"thinking":"text",Le=Qn(_.data.text)??"",Ie=Date.now();if(fe==="text"){const _e=M.current;M.current=_e&&_e.runId===Q&&_e.turn===ee?{..._e,text:_e.text+Le}:{runId:Q,turn:ee,text:Le}}v(_e=>{const U=_e&&_e.runId===Q&&_e.turn===ee?_e:{runId:Q,turn:ee,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return fe==="thinking"?{...U,thinking:U.thinking+Le,thinkingStartedAt:U.thinkingStartedAt??Ie}:{...U,text:U.text+Le,textStartedAt:U.textStartedAt??Ie}});break}case"live.snapshot":{const Q=Qn(_.data.runId)??"",ee=Number(_.data.turn??0),fe=Qn(_.data.text)??"",Le=Qn(_.data.thinking)??"",Ie=Number(_.data.startedAt??Date.now());M.current={runId:Q,turn:ee,text:fe},j(!0),v({runId:Q,turn:ee,text:fe,thinking:Le,thinkingStartedAt:Le?Ie:null,textStartedAt:fe?Ie:null,settled:!1});break}case"live.settle":{const Q=Qn(_.data.runId)??"",ee=Number(_.data.turn??0);v(fe=>fe&&fe.runId===Q&&fe.turn===ee?{...fe,settled:!0}:fe);break}case"tool.called":{const Q=Qn(_.data.toolUseId)??Qn(_.data.id),ee=Qn(_.data.name)??Qn(_.data.tool)??"tool";Q&&p(fe=>[...fe.filter(Le=>Le.toolUseId!==Q),{toolUseId:Q,name:ee,startedAt:Date.now()}]);break}case"tool.result":{const Q=Qn(_.data.toolUseId)??Qn(_.data.id);Q&&p(ee=>ee.filter(fe=>fe.toolUseId!==Q)),P(l);break}case"message.appended":case"awaiting-approval":P(l).then(()=>v(Q=>Q!=null&&Q.settled?null:Q));break;case"run.finished":{j(!1),p([]),v(null);const Q=Qn(_.data.message);k(Q??null);const ee=((X=M.current)==null?void 0:X.text.trim())??"";M.current=null,!Q&&ee!==""&&L.current&&mh(ee,l).then(fe=>{fe&&T(fe)}),P(l);break}}}});return()=>{ps&&ps.conversationId===l&&(ps.lastEventId=q.lastEventId()),q.close()}},[l,P]),d.useEffect(()=>{i(b||x)},[b,x,i]),d.useEffect(()=>{if(m.length===0)return;const q=window.setInterval(()=>E(Date.now()),1e3);return()=>window.clearInterval(q)},[m.length]);const D=(q,_)=>{w(!0),k(null);const X={id:`local-${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:q}]};f(Q=>[...Q,X]),(async()=>{try{const Q=l??(await Ve.startConversation(e.id)).conversationId;Q!==l&&(ps={agentId:e.id,conversationId:Q},o(Q));const ee=await Ve.send(e.id,{conversationId:Q,text:q,..._.length>0?{attachmentIds:_.map(fe=>fe.artifactId)}:{}});ee.conversationId!==Q&&(ps={agentId:e.id,conversationId:ee.conversationId},o(ee.conversationId)),j(!0),P(ee.conversationId)}catch(Q){f(ee=>ee.filter(fe=>fe.id!==X.id)),k(Q instanceof ve?Q.message:String(Q)),S({text:q,at:Date.now()})}finally{w(!1)}})()},O=()=>{l&&Ve.cancel(l).catch(q=>k(String(q))).finally(()=>j(!1))},H=()=>{var q;ps=null,o(null),u(null),f([]),p([]),v(null),j(!1),k(null),(q=a.current)==null||q.focus()},B=q=>{I(q),lT(q),q||Ql()},Y=l?st(e.id,l):st(e.id),W=[...(c==null?void 0:c.messages)??[],...h];return n.jsxs(e3,{title:e.name,label:`${e.name}, a quick chat`,onClose:r,onOpenAutoFocus:q=>{var _;q.preventDefault(),(_=a.current)==null||_.focus()},onCloseAutoFocus:q=>q.preventDefault(),actions:n.jsxs(n.Fragment,{children:[n.jsx(A,{size:"sm",variant:"ghost",onClick:H,disabled:l===null&&h.length===0,children:"New"}),n.jsx(dt,{size:"sm",variant:"ghost",href:Y,onClick:q=>{q.preventDefault(),s(Y)},children:"Open in Chat"})]}),children:[n.jsx("div",{className:"wb-ask-thread",children:n.jsx(aw,{messages:W,live:m,now:C,working:b||x,partial:g,agents:t,agentName:e.name,agentId:e.id,onOpen:()=>s(Y),onReadAloud:(q,_)=>{T(null),mh(_,l??void 0,q).then(X=>{X&&T(X)})},emptyHint:`Ask ${e.name} anything, without leaving this page.`})}),n.jsxs("div",{className:"wb-ask-compose",children:[y?n.jsx(re,{message:y}):null,n.jsx(ow,{ref:a,disabled:x||!e.available,running:b,onSend:D,onStop:O,agentName:e.name,placeholder:`Message ${e.name}…`,draft:N,threadKey:`dock.${l??e.id}`,conversationId:l,readAloud:R,onReadAloud:B}),F?n.jsx("p",{className:"wb-voice-note",role:"status",children:F}):null]})]})}function Qn(e){return typeof e=="string"?e:null}function tW(e,t){var r;const s=(r=t.blocks)==null?void 0:r.find(i=>i.type==="text");return!s||s.type!=="text"?!1:e.messages.some(i=>i.role==="user"&&(i.blocks??[]).some(a=>a.type==="text"&&a.text.includes(s.text)))}const TT=3;function nW(e){if(e==="approval"||e==="question")return"accent";if(e==="watcher"||e==="reminder")return"warm";if(e==="failure")return"critical"}function sW(e,t){return e?t?"above-dock":"above-button":"corner"}function rW({placement:e,children:t}){return n.jsx("div",{className:"wb-toast-stack","data-placement":e,children:t})}function iW(e){return e.state==="shown"&&e.seenAt===null}function aW(e){const[t,s]=d.useState([]),r=d.useRef(new Set),i=d.useRef(new Set),a=d.useCallback(()=>{e&&$.notifications(20).then(({notifications:o})=>{const c=o.filter(u=>iW(u)&&!r.current.has(u.id));s(u=>{const h=new Set(u.map(m=>m.id)),f=c.filter(m=>!h.has(m.id));return f.length===0?u:[...u,...f].sort((m,p)=>p.createdAt.localeCompare(m.createdAt))})}).catch(()=>{})},[e]);d.useEffect(()=>{for(const o of t.slice(0,TT))i.current.has(o.id)||(i.current.add(o.id),$.notificationSeen(o.id).catch(()=>{}))},[t]);const l=d.useCallback(o=>{r.current.add(o),s(c=>c.filter(u=>u.id!==o))},[]);return{queue:t,refresh:a,dismiss:l}}function lW({queue:e,agents:t,navigate:s,onDismiss:r}){if(e.length===0)return null;const i=e.slice(0,TT),a=e.length-i.length;return n.jsxs("section",{className:"nt-toasts","aria-label":"Notifications",children:[i.map(l=>n.jsxs("div",{className:"ui-toast nt-toast","data-tone":nW(l.kind),role:"status",children:[l.agentId?n.jsx(cn,{agents:t,id:l.agentId,size:"sm"}):null,n.jsxs("div",{className:"nt-toast-main",children:[n.jsx("div",{className:"ui-toast-title",children:xc(l)}),l.text?n.jsx("div",{className:"ui-toast-body nt-toast-line",children:oW(l.text)}):null,l.link?n.jsx("a",{className:"nt-toast-link",href:l.link,onClick:o=>{o.preventDefault(),r(l.id),s(l.link)},children:"See"}):null]}),n.jsx("button",{type:"button",className:"nt-toast-x","aria-label":`Dismiss ${xc(l)}`,onClick:()=>r(l.id),children:"×"})]},l.id)),a>0?n.jsxs("p",{className:"nt-toasts-more",children:["and ",a," more"]}):null]})}function oW(e){var t;return((t=e.split(`
110
+ `).find(s=>s.trim()!==""))==null?void 0:t.trim())??""}const cW=3e4,uW=1e3;function dW(e,t,s){const r=d.useRef(t);r.current=t;const i=d.useRef(s);i.current=s,d.useEffect(()=>{if(!e)return;let a=!1,l=-1/0,o=null,c=null,u=!0;const h=()=>document.visibilityState!=="hidden",f=j=>{var x;l=Date.now(),$.presence(j).catch(w=>{var y;w instanceof ve&&w.status===401&&(a=!0,(y=i.current)==null||y.call(i))}),j==="active"&&((x=r.current)==null||x.call(r))},m=j=>{if(a||(o=j,c!==null))return;const x=l+uW-Date.now();if(x<=0){o=null,f(j);return}c=window.setTimeout(()=>{if(c=null,a||o===null)return;const w=o;o=null,f(w)},x)},p=()=>{u=!0,h()&&m("active")},g=()=>{u=!1,m("away")},v=()=>m(h()?"active":"away");h()&&m("active");const b=window.setInterval(()=>{h()&&u&&m("active")},cW);return window.addEventListener("focus",p),window.addEventListener("blur",g),document.addEventListener("visibilitychange",v),()=>{a=!0,window.clearInterval(b),c!==null&&window.clearTimeout(c),window.removeEventListener("focus",p),window.removeEventListener("blur",g),document.removeEventListener("visibilitychange",v)}},[e])}function hW({agents:e,onClose:t,onCreated:s}){return kA(e)?n.jsx(fW,{agents:Uj(e),onClose:t,...s?{onCreated:s}:{}}):n.jsx(Ye,{title:"A new group",onClose:t,children:n.jsxs(V,{children:["A group needs two agents. Make another one with ",Fz(e)," first."]})})}function fW({agents:e,onClose:t,onCreated:s}){var j,x;const[r,i]=d.useState(""),[a,l]=d.useState([]),[o,c]=d.useState(((j=e.find(w=>w.roles.includes(Gc)))==null?void 0:j.id)??((x=e[0])==null?void 0:x.id)??""),[u,h]=d.useState(!1),[f,m]=d.useState(null),p=[...new Set([o,...a])].filter(Boolean),g=r.trim()!==""&&o!==""&&p.length>=2,v=w=>l(y=>y.includes(w)?y.filter(k=>k!==w):[...y,w]),b=async()=>{h(!0),m(null);try{s==null||s(await Ve.createGroup({name:r.trim(),coordinator:o,members:p.filter(w=>w!==o)}))}catch(w){m(w instanceof ve?w.message:String(w))}finally{h(!1)}};return n.jsx(Ye,{title:"A new group",onClose:t,children:n.jsxs(le,{children:[n.jsx(oe,{label:"Name",hint:"What this team is for: Household finances, The move, Tax season.",children:n.jsx("input",{value:r,autoFocus:!0,maxLength:80,onChange:w=>i(w.target.value),placeholder:"Household finances"})}),n.jsx(oe,{label:"Coordinator",hint:"Reads your request, brings members in, and answers for the group. Concierge by default.",children:n.jsx("select",{value:o,onChange:w=>c(w.target.value),children:e.map(w=>n.jsx("option",{value:w.id,children:w.name},w.id))})}),n.jsx(oe,{label:"Members",hint:"Each keeps its own account, tools and approvals. Membership grants nothing.",children:n.jsx("div",{className:"group-pick",role:"group","aria-label":"Members",children:e.filter(w=>w.id!==o).map(w=>n.jsxs("label",{className:"group-pick-row","data-on":a.includes(w.id)||void 0,children:[n.jsx("input",{type:"checkbox",checked:a.includes(w.id),onChange:()=>v(w.id)}),n.jsx(cn,{agents:e,id:w.id,size:"sm"}),n.jsxs("span",{className:"group-pick-text",children:[n.jsx("span",{className:"group-pick-name",children:w.name}),n.jsx("span",{className:"group-pick-desc",children:w.description})]})]},w.id))})}),n.jsx(V,{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?n.jsx(V,{tone:"critical",children:f}):null,n.jsxs(ae,{align:"end",children:[n.jsx(A,{onClick:t,children:"Cancel"}),n.jsx(A,{variant:"accent",disabled:!g||u,onClick:()=>void b(),children:u?"Creating…":"Create group"})]})]})})}const mW=1e4;function ph({title:e,body:t,duration:s,onUndo:r,onGone:i}){return n.jsxs(KD,{className:"ui-toast wb-undo-toast",duration:s,onOpenChange:a=>{a||i()},"data-testid":"undo-toast",children:[n.jsx("span",{className:"ui-toast-mark","aria-hidden":"true"}),n.jsxs("div",{className:"ui-toast-main",children:[n.jsx(VD,{className:"ui-toast-title",children:e}),t?n.jsx(GD,{className:"ui-toast-body",children:t}):null]}),r?n.jsx(qD,{altText:"Undo",asChild:!0,children:n.jsx("button",{type:"button",className:"ui-btn wb-undo-toast-action","data-variant":"ghost","data-size":"sm",onClick:r,children:"Undo"})}):null]})}function cw(e){const[t,s]=d.useState(null),[r,i]=d.useState(null),[a,l]=d.useState(null);return{busy:t,note:r,failure:a,decide:async(c,u,h,f)=>{var p,g,v,b;s(c),l(null),i(null);let m;try{const j=f?await $.decide(c,u,h,f):await $.decide(c,u,h);m={decision:u,...(p=j.execution)!=null&&p.state?{state:j.execution.state}:{},...j.execution&&"result"in j.execution?{result:j.execution.result}:{}},i(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 uw({action:e,timezone:t,busy:s,onDecide:r,agentName:i}){var h,f;const[a,l]=d.useState(!1),{values:o,controls:c}=qj(e.choices),u=m=>o?r(e.id,"approve",m,o):r(e.id,"approve",m);return n.jsxs(ds,{tone:"accent",title:e.tool,meta:n.jsxs(n.Fragment,{children:[n.jsxs(we,{children:["v",e.toolVersion]}),n.jsxs("span",{className:"muted",children:["asked by ",i??e.agentId]})]}),children:[n.jsx(Pt,{children:e.preview}),n.jsxs("p",{className:"ui-card-meta",children:["Expires ",nt(e.expiresAt,t)," (",Fe(e.expiresAt),"). Policy v",e.policyVersion,", args ",gc(e.argsHash,12),e.jobId?`, job ${gc(e.jobId)}`:"","."]}),c,n.jsxs(ae,{children:[n.jsx(A,{variant:"good",disabled:s,onClick:()=>u(),children:(h=e.permissionScopes)!=null&&h.length?"Allow once":"Approve"}),(f=e.permissionScopes)!=null&&f.length?n.jsxs(n.Fragment,{children:[n.jsx(A,{disabled:s,onClick:()=>u("conversation"),children:"Auto: this conversation"}),n.jsx(A,{disabled:s,onClick:()=>u("always"),children:"Always: this agent"})]}):null,n.jsx(A,{variant:"danger",disabled:s,onClick:()=>r(e.id,"reject"),children:"Reject"}),n.jsx(A,{variant:"ghost",onClick:()=>l(m=>!m),"aria-expanded":a,children:a?"Hide envelope":"Show envelope"})]}),a?n.jsxs("div",{className:"ui-card-foot",children:[n.jsx(ue,{title:"Envelope: everything that decides what the world will see",children:n.jsx(Pt,{children:is(e.envelope)})}),n.jsx(ue,{title:"Canonical arguments",children:n.jsx(Pt,{children:is(e.canonicalArgs)})})]}):null]})}function dw(e,t,s){const[r,i]=d.useState(!1),[a,l]=d.useState(null),[o,c]=d.useState(null);return{accept:()=>{e&&(i(!0),c(null),$.acceptPluginAgent(e,t).then(h=>{l(h.agent),s==null||s(h.agent)}).catch(h=>c(h instanceof ve?h.message:String(h))).finally(()=>i(!1)))},busy:r,created:a,failure:o}}function $T({agent:e}){return n.jsxs(V,{tone:"good",role:"status",children:["@",e.handle," is ready. ",n.jsxs("a",{href:st(e.id),children:["Talk to @",e.handle]})]})}function RT(e,t,s){const r=e.canonicalArgs;return e.tool==="platform.accept_plugin_agent"&&(r==null?void 0:r.plugin)===t&&typeof r.agent=="string"&&r.agent.toLowerCase()===s.toLowerCase()}function pW(e,t){var i;const s=de(()=>$.approvals(),[e,t],15e3);return{action:((i=s.data)==null?void 0:i.pending.find(a=>RT(a,e,t)))??null,reload:s.reload}}function gW({action:e,onDecided:t}){const{busy:s,failure:r,decide:i}=cw(a=>t(a));return n.jsxs(le,{gap:"sm",children:[n.jsx(uw,{action:e,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,busy:s===e.id,onDecide:(a,l,o,c)=>{i(a,l,o,c)}}),n.jsx(re,{message:r})]})}function hw({plugin:e,agent:t,text:s,label:r,handle:i,onDismiss:a}){var f;const l=dw(e,t),o=pW(e,t),[c,u]=d.useState(null),h=l.created??c;if(h)return n.jsx($T,{agent:h});if(o.action){const m=i??((f=/@(\S+)/.exec(r))==null?void 0:f[1])??t;return n.jsxs(le,{gap:"sm",children:[n.jsx("span",{children:s}),n.jsx(gW,{action:o.action,onDecided:p=>{(p==null?void 0:p.decision)==="approve"&&p.state==="succeeded"?u({id:t,handle:m,name:m}):o.reload()}})]})}return n.jsxs(le,{gap:"sm",children:[n.jsxs(ae,{children:[n.jsx("span",{children:s}),n.jsx(ht,{}),a?n.jsx(A,{variant:"ghost",disabled:l.busy,onClick:a,children:"Not now"}):null,n.jsx(A,{variant:"accent",disabled:l.busy,onClick:l.accept,children:r})]}),n.jsx(re,{message:l.failure})]})}function IT(){var t;const e=de(()=>$.agentOffers(),[],6e4);return{offers:((t=e.data)==null?void 0:t.offers)??[],reload:e.reload}}function PT({offers:e,reload:t}){return e.length===0?null:n.jsx(ue,{title:"From your plugins",aside:`${e.length} to decide`,panel:!0,children:n.jsx(le,{gap:"sm",divided:!0,children:e.map(s=>n.jsx(hw,{plugin:s.plugin,agent:s.agent,text:s.text,label:`Create @${s.handle}`,handle:s.handle,onDismiss:()=>{$.dismissAgentOffer(s.plugin,s.agent).then(t,t)}},`${s.plugin}/${s.agent}`))})})}const xW=512*1024,vW=/^[A-Za-z0-9+/]*={0,2}$/;function MT(e){const t=e==null?void 0:e.play;if(typeof t!="object"||t===null)return null;const{mime:s,data:r}=t;return typeof s!="string"||!/^audio\/[a-z0-9.+-]+$/i.test(s.split(";")[0].trim())||typeof r!="string"||r===""||!vW.test(r)||Math.floor(r.length*3/4)>xW+2?null:{mime:s,data:r}}function DT(e){const t=e==null?void 0:e.message;return typeof t=="string"&&t.trim()!==""?t:null}let Rr=null,Bo=null,Ec=null;const bx=new Set;function OT(){for(const e of bx)e()}function $o(){Rr&&(Rr.onended=null,Rr.onerror=null,Rr.pause()),Bo&&URL.revokeObjectURL(Bo),Bo=null,Ec!==null&&(Ec=null,OT())}async function LT(e,t){$o();const s=atob(e.data),r=new Uint8Array(s.length);for(let i=0;i<s.length;i+=1)r[i]=s.charCodeAt(i);Rr??(Rr=new Audio),Bo=URL.createObjectURL(new Blob([r],{type:e.mime})),Ec=t,Rr.onended=$o,Rr.onerror=$o,Rr.src=Bo,OT();try{await Rr.play()}catch{throw $o(),new Error("The browser would not play the sound.")}}function $0(e){e!==void 0&&Ec!==e||$o()}function jW(){return d.useSyncExternalStore(e=>(bx.add(e),()=>bx.delete(e)),()=>Ec,()=>null)}const wW=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],sr=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],R0=/^\d{4}-\d{2}-\d{2}$/;function aa(e){return e.split("-").map(Number)}function Na(e,t){const[s,r,i]=aa(e);return new Date(Date.UTC(s,r-1,i+t)).toISOString().slice(0,10)}function FT(e){const[t,s,r]=aa(e);return new Date(Date.UTC(t,s-1,r)).getUTCDay()}function _T(e){return wW[FT(e)]}function zT(e){return aa(e)[2]}function I0(e){return Na(e,-((FT(e)+6)%7))}function _r(e){return Bc(e,{weekday:!0,compact:!0})}function yW(e,t){return e===t?`Today · ${_r(e)}`:e===Na(t,1)?`Tomorrow · ${_r(e)}`:_r(e)}function Ji(e){return $L(e)}const P0=new Map;function kx(e,t){let s=P0.get(t);s||(s=new Intl.DateTimeFormat("en-GB",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}),P0.set(t,s));const r=Object.fromEntries(s.formatToParts(e).map(i=>[i.type,i.value]));return{date:`${r.year}-${r.month}-${r.day}`,minutes:Number(r.hour)*60+Number(r.minute)}}function bW(e,t=new Date){return kx(t,e).date}function kW(e,t){return e==="week"?{from:I0(t),days:7}:e==="month"?{from:I0(`${t.slice(0,8)}01`),days:42}:{from:t,days:7}}function NW(e,t,s){if(e!=="month")return Na(t,s*7);const[r,i]=aa(t);return new Date(Date.UTC(r,i-1+s,1)).toISOString().slice(0,10)}function SW(e,t,s,r){const[i,a]=aa(t);if(e==="month")return dE(i,a);const l=Na(s,r-1),[o,c,u]=aa(s),[h,f,m]=aa(l);return cE().date==="iso"?`${s} – ${l}`:RL()?c===f&&o===h?`${sr[c-1]} ${u} – ${m}, ${h}`:o===h?`${sr[c-1]} ${u} – ${sr[f-1]} ${m}, ${h}`:`${sr[c-1]} ${u}, ${o} – ${sr[f-1]} ${m}, ${h}`:c===f&&o===h?`${u} – ${m} ${sr[f-1]} ${h}`:o===h?`${u} ${sr[c-1]} – ${m} ${sr[f-1]} ${h}`:`${u} ${sr[c-1]} ${o} – ${m} ${sr[f-1]} ${h}`}function za(e){return e==null?"":String(e)}function CW(e,t,s,r){const i=[],a=new Set;return e.forEach((l,o)=>{const c=za(Ne(l,t.id)),u=za(Ne(l,t.title)),h=za(Ne(l,t.start)),f=za(Ne(l,t.end));if(c===""||a.has(c)||h===""){console.warn(`buddi: ${r}: event ${o} has no id, a repeated one, or no start — not drawn`);return}a.add(c);const m=t.allDay===void 0?void 0:Ne(l,t.allDay),p=m===void 0?R0.test(h):m===!0||m==="true",g=t.tone===void 0?0:Number(Ne(l,t.tone)),v=Number.isFinite(g)?(Math.trunc(g)%4+4)%4:0,b={id:c,title:u,calendar:t.calendar===void 0?"":za(Ne(l,t.calendar)),tone:v,location:t.location===void 0?"":za(Ne(l,t.location))};if(p){const k=h.slice(0,10),N=R0.test(f.slice(0,10))&&f.slice(0,10)>k?f.slice(0,10):Na(k,1);i.push({...b,allDay:!0,startDate:k,startMin:0,endDate:N,endMin:0});return}const j=new Date(h);if(Number.isNaN(j.getTime())){console.warn(`buddi: ${r}: event ${o} starts at "${h}", which is not a time — not drawn`);return}const x=new Date(f),w=kx(j,s),y=Number.isNaN(x.getTime())||x<j?w:kx(x,s);i.push({...b,allDay:!1,startDate:w.date,startMin:w.minutes,endDate:y.date,endMin:y.minutes})}),i}function EW(e,t){if(e.allDay)return t>=e.startDate&&t<e.endDate?{from:0,to:1440,allDay:!0}:null;if(t<e.startDate||t>e.endDate)return null;const s=t===e.startDate?e.startMin:0,r=t===e.endDate?e.endMin:1440,i=e.startDate===e.endDate&&e.startMin===e.endMin;return r<=s&&!(i&&t===e.startDate)?null:{from:s,to:r,allDay:s===0&&r===1440}}function fw(e,t){return e.map(s=>({event:s,part:EW(s,t)})).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 mw(e,t){if(t.allDay)return"All day";const s=e.startDate!==e.endDate;return s&&t.from===0?`until ${Ji(t.to)}`:s&&t.to===1440?`from ${Ji(t.from)}`:t.from===t.to?Ji(t.from):`${Ji(t.from)}–${Ji(t.to)}`}function Nx(e,t,s){return[mw(e,t),e.title,e.location,e.calendar,_r(s)].filter(Boolean).join(", ")}const UT=30;function AW(e){const t=[];let s=[],r=-1;const i=[],a=()=>{const l=Math.max(1,...s.map(o=>o.lane+1));for(const o of s)t.push({...o,lanes:l});s=[],i.length=0};for(const l of e){const o=Math.max(l.part.to,l.part.from+UT);s.length>0&&l.part.from>=r&&a();let c=i.findIndex(u=>u<=l.part.from);c===-1?(c=i.length,i.push(o)):i[c]=o,s.push({...l,lane:c,lanes:1}),r=Math.max(r,o)}return s.length>0&&a(),t}const TW={week:"Week",month:"Month",list:"List"},$W=["week","month","list"],RW="(max-width: 720px)";function IW(e){try{return window.localStorage.getItem(e)}catch{return null}}function PW(e,t){try{window.localStorage.setItem(e,t)}catch{}}function MW(e){const t=e.views&&e.views.length>0?e.views:$W,s=Ns(RW),[r,i]=d.useState(()=>{const p=IW(e.storageKey);return p!==null&&t.includes(p)?p:null}),a=s&&t.includes("list")?"list":e.default&&t.includes(e.default)?e.default:t[0],l=r??a,[o,c]=d.useState(e.today),[u,h]=d.useState(null),{from:f,days:m}=kW(l,o);return{views:t,view:l,setView:p=>{i(p),PW(e.storageKey,p),h(null)},anchor:o,today:e.today,go:p=>{c(p===0?e.today:NW(l,o,p)),h(null)},from:f,days:m,to:Na(f,m),selected:u,select:h}}function DW({state:e,events:t,hours:s,empty:r,label:i}){const{view:a,anchor:l,today:o,from:c,days:u}=e,h=d.useMemo(()=>Array.from({length:u},(v,b)=>Na(c,b)),[c,u]),f=a==="month"?"month":"week",m=e.selected??(l.slice(0,7)===o.slice(0,7)?o:`${l.slice(0,8)}01`),p=a==="month"?m:a==="week"?e.selected:null,g=v=>{if(!v.target.closest('input, textarea, select, [contenteditable="true"]')&&!(v.altKey||v.ctrlKey||v.metaKey)){if(v.key==="ArrowLeft")e.go(-1);else if(v.key==="ArrowRight")e.go(1);else if(v.key==="t"||v.key==="T")e.go(0);else return;v.preventDefault()}};return n.jsxs("div",{className:"cal",role:"region","aria-label":i,tabIndex:0,onKeyDown:g,children:[n.jsxs("div",{className:"cal-bar",children:[n.jsx(A,{size:"sm","aria-label":`Previous ${f}`,onClick:()=>e.go(-1),children:n.jsx(ce,{name:"chevron-left",size:14})}),n.jsx(A,{size:"sm",onClick:()=>e.go(0),children:"Today"}),n.jsx(A,{size:"sm","aria-label":`Next ${f}`,onClick:()=>e.go(1),children:n.jsx(ce,{name:"chevron-right",size:14})}),n.jsx("h3",{className:"cal-title","aria-live":"polite",children:SW(a,l,c,u)}),e.views.length>1?n.jsx(qt,{label:"View",options:e.views.map(v=>({value:v,label:TW[v]})),value:a,onChange:e.setView}):null]}),a==="week"?n.jsx(OW,{dates:h,today:o,events:t,hours:s??[7,21],onPick:e.select}):null,a==="month"?n.jsx(FW,{dates:h,month:l.slice(0,7),today:o,events:t,selected:m,onPick:e.select}):null,a==="list"?n.jsx("div",{className:"cal-list",children:h.map(v=>n.jsx(M0,{date:v,today:o,events:t,empty:r},v))}):null,p?n.jsx(M0,{date:p,today:o,events:t,empty:r}):null]})}function M0({date:e,today:t,events:s,empty:r}){const i=fw(s,e);return n.jsx(qe,{flush:!0,title:yW(e,t),children:n.jsx(rt,{children:i.length===0?n.jsx(et,{title:n.jsx("span",{className:"muted",children:r})}):i.map(({event:a,part:l})=>n.jsx(et,{lead:n.jsx("span",{className:"cal-dot","data-tone":a.tone,"aria-hidden":"true"}),title:a.title,sub:a.location||void 0,side:mw(a,l)},a.id))})})}function OW({dates:e,today:t,events:s,hours:r,onPick:i}){const a=d.useRef(null);d.useLayoutEffect(()=>{const c=a.current;c&&(c.scrollTop=c.scrollHeight/24*r[0])},[r[0]]);const l=e.map(c=>({date:c,items:fw(s,c)})),o=c=>c===t?"true":void 0;return n.jsx(qe,{flush:!0,children:n.jsxs("div",{className:"cal-week",role:"grid","aria-label":`Week of ${_r(e[0])}`,style:{"--cal-span":r[1]-r[0]},children:[n.jsxs("div",{className:"cal-row",role:"row",children:[n.jsx("span",{className:"cal-gutter","aria-hidden":"true"}),e.map(c=>n.jsxs("div",{className:"cal-day-head",role:"columnheader","data-today":o(c),"aria-label":_r(c),children:[n.jsx("span",{className:"cal-wd",children:_T(c)}),n.jsx("span",{className:"cal-num",children:zT(c)})]},c))]}),n.jsxs("div",{className:"cal-row cal-allday",role:"row",children:[n.jsx("span",{className:"cal-gutter cal-gutter-label",children:"All day"}),l.map(({date:c,items:u})=>n.jsx("div",{className:"cal-allday-cell",role:"gridcell","data-today":o(c),children:u.filter(h=>h.part.allDay).map(({event:h,part:f})=>n.jsx("button",{type:"button",className:"cal-chip","data-tone":h.tone,"aria-label":Nx(h,f,c),onClick:()=>i(c),children:h.title},h.id))},c))]}),n.jsx("div",{className:"cal-scroll",ref:a,children:n.jsxs("div",{className:"cal-row cal-times",role:"row",children:[n.jsx("div",{className:"cal-gutter cal-hours","aria-hidden":"true",children:Array.from({length:23},(c,u)=>u+1).map(c=>n.jsx("span",{className:"cal-hour-label",style:{top:`calc(var(--cal-hour) * ${c})`},children:Ji(c*60)},c))}),l.map(({date:c,items:u})=>n.jsx("div",{className:"cal-col",role:"gridcell","aria-label":_r(c),"data-today":o(c),children:AW(u.filter(h=>!h.part.allDay)).map(({event:h,part:f,lane:m,lanes:p})=>n.jsxs("button",{type:"button",className:"cal-event","data-tone":h.tone,"data-short":f.to-f.from<60?"true":void 0,"data-lane":m,"aria-label":Nx(h,f,c),onClick:()=>i(c),style:{top:`calc(var(--cal-hour) * ${f.from/60})`,height:`calc(var(--cal-hour) * ${Math.max(f.to-f.from,UT)/60})`,left:`calc((100% - var(--space-1)) * ${m/p} + var(--space-0))`,width:`calc((100% - var(--space-1)) / ${p} - var(--space-0))`},children:[n.jsx("span",{className:"cal-event-time",children:mw(h,f)}),n.jsx("span",{className:"cal-event-title",children:h.title})]},h.id))},c))]})})]})})}const LW=3;function FW({dates:e,month:t,today:s,events:r,selected:i,onPick:a}){const l=Array.from({length:6},(h,f)=>e.slice(f*7,f*7+7)),[o,c]=t.split("-").map(Number),u=dE(o,c);return n.jsx(qe,{flush:!0,children:n.jsxs("div",{className:"cal-month",role:"grid","aria-label":u,children:[n.jsx("div",{className:"cal-row",role:"row",children:e.slice(0,7).map(h=>n.jsx("div",{className:"cal-wd-head",role:"columnheader",children:_T(h)},h))}),l.map(h=>n.jsx("div",{className:"cal-row",role:"row",children:h.map(f=>{const m=fw(r,f),p=m.slice(0,LW),g=m.length-p.length,v=m.length===0?"nothing":m.length===1?"1 event":`${m.length} events`;return n.jsxs("div",{className:"cal-cell",role:"gridcell","aria-selected":f===i,"data-date":f,"data-today":f===s?"true":void 0,"data-outside":f.slice(0,7)!==t?"true":void 0,"data-selected":f===i?"true":void 0,onClick:()=>a(f),children:[n.jsx("button",{type:"button",className:"cal-num","aria-label":`${_r(f)}, ${v}`,"aria-pressed":f===i,children:zT(f)}),p.map(({event:b,part:j})=>n.jsx("button",{type:"button",className:"cal-chip","data-tone":b.tone,"data-timed":j.allDay?void 0:"true","aria-label":Nx(b,j,f),children:j.allDay?b.title:n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"cal-dot","data-tone":b.tone,"aria-hidden":"true"}),n.jsx("span",{className:"cal-chip-time",children:Ji(j.from)})," ",b.title]})},b.id)),g>0?n.jsxs("button",{type:"button",className:"cal-more","aria-label":`${g} more on ${_r(f)}`,children:["+",g]}):null]},f)})},h[0]))]})})}const BT={width:1200,height:200,top:28,right:12,bottom:24,left:36};function _W(e,t){if(t==="percent")return[0,50,100];let s=e.length>0?Math.min(...e):0,r=e.length>0?Math.max(...e):1;t!=="temp"&&(s=Math.min(0,s)),s===r&&(s-=1,r+=1);const i=10**Math.floor(Math.log10(Math.max(1,(r-s)/3))),a=c=>Math.ceil(r/c)-Math.floor(s/c);let l=[1,2,5,10].map(c=>c*i).find(c=>a(c)<=3)??i*10;a(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 Gu(e,t){return t==="temp"?`${e}°`:t==="percent"?`${e}%`:String(e)}function zW(e){const t=BT,s=e.values.length,r=t.width-t.left-t.right,i=t.height-t.top-t.bottom,a=t.height-t.bottom,l=s>0?r/s:r,o=j=>Qi(t.left+l*(j+.5)),c=e.values.filter(j=>j!==null&&Number.isFinite(j)),u=_W(c,e.unit),h=u[0],f=u[u.length-1],m=j=>Qi(t.top+i-(j-h)/(f-h)*i),p=e.values.map((j,x)=>{const w=j!==null&&Number.isFinite(j);return{index:x,x:o(x),y:w?m(j):null,value:w?j:null}}),g=[],v=[];if(e.kind==="area"){let j=[];const x=()=>{if(j.length===0)return;const w=j.map((y,k)=>`${k===0?"M":"L"}${y.x},${y.y}`).join(" ");g.push(w),v.push(`${w} L${j[j.length-1].x},${a} L${j[0].x},${a} Z`),j=[]};for(const w of p)w.y===null?x():j.push(w);x()}const b=e.kind==="bars"?p.flatMap(j=>j.y===null?[]:[{index:j.index,x:Qi(j.x-l*.28),y:j.y,width:Qi(l*.56),height:Qi(a-j.y)}]):[];return{ticks:u.map(j=>({value:j,y:m(j)})),lines:g,areas:v,bars:b,points:p,slot:l,floor:a}}function UW({title:e,note:t,xs:s,series:r,tiles:i,labelEvery:a=3}){var k;const[l,o]=d.useState(((k=r[0])==null?void 0:k.id)??""),[c,u]=d.useState(null),[h,f]=d.useState(null),m=d.useRef(null),p=s.length,g=c??h,v=r.find(N=>N.id===l)??r[0],b=zW(v),j=BT,x=N=>N%a===0||N===g,w=v.values.filter(N=>N!==null&&Number.isFinite(N));d.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 y=N=>{var E,R,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,(h??-S)+S));C!==null&&(N.preventDefault(),f(C),(I=(R=(E=m.current)==null?void 0:E.children[C])==null?void 0:R.querySelector("button"))==null||I.focus())};return n.jsxs(qe,{...e?{title:e}:{},children:[t?n.jsx("p",{className:"ui-panel-sub",children:t}):null,n.jsxs("div",{className:"pg-series",onMouseLeave:()=>u(null),children:[r.length>1?n.jsx("div",{className:"pg-series-tabs",role:"tablist","aria-label":"Series",children:r.map(N=>n.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,n.jsxs("figure",{className:"pg-series-chart","data-kind":v.kind,children:[n.jsxs("svg",{viewBox:`0 0 ${j.width} ${j.height}`,"aria-hidden":"true",focusable:"false","data-testid":"series-svg",children:[b.ticks.map(N=>n.jsxs("g",{children:[n.jsx("line",{className:"pg-series-grid",x1:j.left,x2:j.width-j.right,y1:N.y,y2:N.y}),n.jsx("text",{className:"pg-series-tick",x:j.left-8,y:N.y,textAnchor:"end",dominantBaseline:"middle",children:Gu(N.value,v.unit)})]},N.value)),b.areas.map((N,S)=>n.jsx("path",{className:"pg-series-area",d:N},`a${S}`)),b.lines.map((N,S)=>n.jsx("path",{className:"pg-series-line",d:N},`l${S}`)),b.bars.map(N=>n.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]?n.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)?n.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)?n.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:Gu(N.value,v.unit)},N.index):null),b.points.map(N=>N.index%a===0?n.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=>n.jsx("rect",{className:"pg-series-hit","data-index":N.index,x:Qi(j.left+b.slot*N.index),y:0,width:Qi(b.slot),height:j.height,onMouseEnter:()=>u(N.index),onClick:()=>f(N.index)},N.index))]}),n.jsx("figcaption",{className:"sr-only",children:w.length===0?`${v.label}: no values.`:`${v.label}, ${p} ${p===1?"point":"points"} from ${s[0]} to ${s[p-1]}: lowest ${Gu(Math.min(...w),v.unit)}, highest ${Gu(Math.max(...w),v.unit)}.`})]}),n.jsx("ul",{className:"wb-tiles","data-layout":"strip",ref:m,onKeyDown:y,children:i.map((N,S)=>n.jsx("li",{className:"wb-tile",children:n.jsx("button",{type:"button",className:"ui-card","data-index":S,"data-hover":S===g?"true":void 0,"aria-pressed":S===h,"aria-label":[N.label,N.value,...N.lines].filter(C=>C!=="").join(", "),onMouseEnter:()=>u(S),onClick:()=>f(S),children:n.jsxs("div",{className:"wb-tile-body","aria-hidden":"true",children:[n.jsx("span",{className:"wb-tile-icon","data-icon":N.icon??"dot",children:n.jsx(ce,{name:Jl(N.icon),size:22})}),N.value!==""?n.jsx("span",{className:"wb-tile-value tnum",children:N.value}):null,n.jsx("span",{className:"wb-tile-label",children:N.label}),N.lines.map((C,E)=>n.jsx("span",{className:"wb-tile-line",children:C},E))]})})},S))})]})]})}function Qi(e){return Math.round(e*10)/10}const BW=/^[a-z0-9](?:[a-z0-9._-]{0,94}[a-z0-9])?$/,WW=/^[a-z][a-z0-9_-]{0,63}$/;function Af(e,t,s=64){return!WW.test(e)||typeof t!="string"||!BW.test(t)||t.includes("..")?null:`/api/plugin-assets/${e}/${t}?size=${s}`}function WT(e){return typeof e=="string"&&/^\/api\/plugin-assets\/[a-z][a-z0-9_-]{0,63}\/[a-z0-9._-]+(\?size=(64|128))?$/.test(e)}function HW(e){var t,s;return((s=(t=e.match(/[\p{L}\p{N}]/u))==null?void 0:t[0])==null?void 0:s.toUpperCase())??"?"}function eu({src:e,label:t,className:s}){const[r,i]=d.useState(!1),a=e!==null&&WT(e)&&!r;return n.jsx("span",{className:["pl-logo",s].filter(Boolean).join(" "),"data-letter":a?void 0:"true","aria-hidden":"true",children:a?n.jsx("img",{src:e,alt:"",loading:"lazy",decoding:"async",onError:()=>i(!0)}):HW(t)})}const pw=d.createContext(null),gh=d.createContext(!1);function mt(){const e=d.useContext(pw);if(!e)throw new Error("a plugin page component outside a plugin page");return e}function Sx(e,t=new Set){if(Array.isArray(e))for(const s of e)Sx(s,t);else if(e&&typeof e=="object"){const s=e.query;typeof s=="string"&&t.add(s);for(const r of Object.values(e))Sx(r,t)}return t}function HT(e,t){if(t.size===0)return!1;for(const s of Sx(e))if(t.has(s))return!0;return!1}function KT(){const[e,t]=d.useState(!1);return d.useEffect(()=>{if(!e)return;const s=()=>{document.visibilityState==="hidden"&&t(!1)};return document.addEventListener("visibilitychange",s),window.addEventListener("blur",s),()=>{document.removeEventListener("visibilitychange",s),window.removeEventListener("blur",s)}},[e]),[e,()=>t(s=>!s)]}function VT({revealed:e,onToggle:t}){return n.jsx(A,{size:"sm",variant:"ghost","aria-pressed":e,onClick:t,children:e?"Hide":"Show"})}function GT(){return n.jsx("p",{className:"muted",children:"Hidden until you show it."})}function qT({children:e}){const[t,s]=KT();return n.jsxs(le,{gap:"sm",children:[n.jsx(ae,{align:"end",children:n.jsx(VT,{revealed:t,onToggle:s})}),t?n.jsx(gh.Provider,{value:!0,children:e}):n.jsx(GT,{})]})}function gw(e){return e===void 0||e==="neutral"?void 0:e}function Cx(e){return gw(e)}function KW(e){const t=gw(e);return t==="accent"?void 0:t}function en(e,t){if(!t)return!0;const s=Ne(e,t.path),r=t.in!==void 0?t.in.includes(s):s===t.equals;return t.not===!0?!r:r}function YT(e){if(typeof e!="string"||e.length>2048)return null;try{const t=new URL(e);return t.protocol==="https:"&&t.hostname!==""&&t.username===""&&t.password===""?t.href:null}catch{return null}}function VW({plugin:e,images:t,row:s}){const i=(Array.isArray(t)?t.map(l=>({asset:Oe(s,l.asset),label:String(Oe(s,l.label)??"").trim()})):(()=>{const l=Ne(s,t.from);return(Array.isArray(l)?l:[]).map(o=>({asset:Ne(o,t.asset),label:String(Ne(o,t.label)??"").trim()}))})()).filter(l=>l.label!=="");if(i.length===0)return null;const a=i.length===1?i[0].label:`${i[0].label} and ${i.length-1} more`;return n.jsxs("span",{className:"pl-stack","data-testid":"row-images",children:[n.jsx("span",{className:"pl-stack-logos",children:i.slice(0,3).map((l,o)=>n.jsx(eu,{src:Af(e,l.asset),label:l.label},o))}),n.jsx("span",{className:"pl-stack-words",children:a})]})}function Tf({href:e,children:t,className:s}){return n.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:s,onClick:r=>r.stopPropagation(),children:[t,n.jsx("span",{className:"wb-src-out","aria-hidden":"true",children:"↗"}),n.jsx("span",{className:"sr-only",children:" (opens in a new tab)"})]})}function Xr(e,t,s){if("href"in t)return YT(Oe(s,t.href))??"";if("chat"in t){const a=Oe(s,t.chat);return a==null?"":st(String(a))}if("proposals"in t)return K4(e.plugin);const r=e.pages.find(a=>a.id===t.page);if((r==null?void 0:r.place)==="settings")return vr(e.plugin,t.page);const i=t.item===void 0?null:Oe(s,t.item);return xr(e.plugin,t.page,i==null?null:String(i))}function Os(e,t){return e.replace(/\{count\}/g,String(t.count??0)).replace(/\{([^{}|]+)\|([^{}|]+)\}/g,(s,r,i)=>(t.count??0)===1?r:i).replace(/\{([A-Za-z_][A-Za-z0-9_.]*)\}/g,(s,r)=>{const i=Ne(t.row,r);return i==null?"":String(i)})}function xh(e,t){if(e===void 0)return;if(typeof e=="string")return e;const s=Oe(t,e);return s==="good"||s==="warning"||s==="critical"||s==="neutral"?s:void 0}function JT(e,t,s){const r={};for(const[i,a]of Object.entries(e??{})){let l;"param"in a?l=s.params[a.param]:"route"in a?l=a.route==="plugin"?s.plugin:a.route==="page"?s.page:s.item:l=Oe(t,a),!(l==null||l==="")&&(r[i]=String(l))}return r}function Zr(e,t){var r,i,a;const s={};for(const[l,o]of Object.entries(e??{}))if("row"in o)s[l]=Ne(t.row,o.row);else if("field"in o){if((r=t.omit)!=null&&r.has(o.field))continue;const c=(i=t.fields)==null?void 0:i[o.field],u=(a=t.shape)==null?void 0:a.find(h=>h.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]=t.selected??[]:"param"in o?s[l]=t.scope.params[o.param]:s[l]=Oe(t.data,o);return s}function gn(e,t,s,r){const i=mt(),a=e?{...JT(e.params,t,i),...r}:{},l=JSON.stringify([(e==null?void 0:e.query)??null,a,i.version]),o=de(()=>e?$.pageQuery(i.plugin,e.query,a).then(c=>c.data):Promise.resolve(void 0),[l],s);return{data:o.data,error:o.error,loading:o.loading}}function Sa(){const e=mt(),t=d.useId(),[s,r]=d.useState(null),[i,a]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(null),m=(j,x)=>{if(j.done===void 0)return null;if(typeof j.done=="string")return j.done;const w=Oe(x,j.done);return w==null?null:String(w)},p=(j,x,w)=>{const y=j??"refresh";if(typeof y=="object"){const k="href"in y.route?"":Xr(e,y.route,x);k===""?e.refresh():e.navigate(k);return}y==="close"&&(w==null||w()),e.refresh()},g=async(j,x,w)=>{r(j.tool),a(null),o(null);try{const y=await $.pageAct(e.plugin,{tool:j.tool,args:x});if(y.approvalId)return u(y.approvalId),f({then:j.then,ref:j,...w?{onDone:w}:{}}),!1;u(null),f(null);const k=MT(y.result);return o(m(j,y.result)??(k?DT(y.result):null)),k&&await LT(k,t),p(j.then,y.result,w),!0}catch(y){return a(y instanceof Error?y.message:String(y)),e.refresh(),!1}finally{r(null)}},v=j=>{if(!j){e.refresh();return}const x=h;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=()=>{a(null),o(null)};return{running:s,busy:s!==null,error:i,done:l,approvalId:c,waiting:(h==null?void 0:h.ref.pending)??null,settle:v,run:g,reset:b}}function Ca({action:e,args:t,disabled:s,running:r,count:i,row:a,onRun:l}){const[o,c]=d.useState(!1),u=f=>Os(f,{...i===void 0?{}:{count:i},row:a}),h=u(e.label);return o&&e.confirm?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"ui-toolbar-note",children:u(e.confirm)}),n.jsx(A,{variant:"ghost",onClick:()=>c(!1),children:"Cancel"}),n.jsxs(A,{variant:e.tone==="danger"?"danger":"accent",disabled:s,onClick:()=>{c(!1),l(e,t)},children:["Yes, ",h.toLowerCase()]})]}):n.jsx(A,{variant:e.tone==="danger"?"danger":e.tone==="accent"?"accent":void 0,disabled:s,onClick:()=>e.confirm?c(!0):l(e,t),children:r&&e.busy?e.busy:h})}function vh({id:e,onDecided:t}){const s=mt(),r=de(()=>$.approval(e),[e,s.version]),{busy:i,note:a,failure:l,decide:o}=cw(c=>{t?t(c):s.refresh()});return r.error?n.jsx(re,{message:r.error}):r.data?n.jsxs(le,{children:[n.jsx(uw,{action:r.data,timezone:s.timezone,busy:i===e,onDecide:(c,u,h,f)=>{o(c,u,h,f)}}),a?n.jsx(V,{tone:"good",role:"status",children:a}):null,n.jsx(re,{message:l})]}):n.jsx(pe,{children:"Loading the approval…"})}function Ea({act:e}){return e.error?n.jsx(re,{message:e.error}):e.approvalId?e.waiting?n.jsxs(le,{children:[n.jsx(V,{role:"status",children:e.waiting}),n.jsx(vh,{id:e.approvalId,onDecided:e.settle})]}):n.jsx(vh,{id:e.approvalId,onDecided:e.settle}):e.done?n.jsx(V,{tone:"good",role:"status",children:e.done}):null}function Ac(e,t){const s={};for(const r of e){const i=r.from===void 0?void 0:Ne(t,r.from);s[r.name]=r.multiple?Array.isArray(i)?i.map(String):[]:i!==void 0?i:r.type==="checkbox"?!1:""}return s}function QT(e,t,s){const r=mt(),i=e.optionsFrom,a=i?{...JT(i.query.params,s,r),...Object.fromEntries((i.dependsOn??[]).map(c=>[c,String(t[c]??"")]).filter(([,c])=>c!==""))}:{},l=JSON.stringify([(i==null?void 0:i.query.query)??null,a,r.version]),o=de(()=>i?$.pageQuery(r.plugin,i.query.query,a).then(c=>c.data):Promise.resolve(void 0),[l]);return i?{options:Ks(o.data,i.rows).map(c=>({value:String(Ne(c,i.value)??""),label:String(Ne(c,i.label)??"")})),loading:o.loading}:{options:e.options??[],loading:!1}}function GW({field:e,fields:t,value:s,values:r,data:i,disabled:a,compact:l,onChange:o}){const c=QT(e,r,i),u={id:`f-${e.name}`,required:e.required,name:e.name,disabled:a,...l&&e.hint?{title:e.hint}:{}},h=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 n.jsx(oe,{label:e.label,hint:l?void 0:[h,g].filter(Boolean).join(" ")||void 0,group:!0,children:n.jsx(n3,{id:u.id,label:e.label,options:c.options,value:m,max:e.max,disabled:a,onChange:o})})}if(e.type==="select"){const m=n.jsxs("select",{...u,value:String(s??""),onChange:p=>o(p.target.value),children:[n.jsx("option",{value:"",children:c.loading?"Loading…":"—"}),c.options.map(p=>n.jsx("option",{value:p.value,children:p.label},p.value))]});return e.action&&!l?n.jsx(qW,{field:e,action:e.action,fields:t??[e],values:r,data:i,disabled:a,hint:h,children:m}):n.jsx(oe,{label:e.label,hint:h,children:m})}if(e.type==="textarea")return n.jsx(oe,{label:e.label,hint:h,wide:!0,children:n.jsx("textarea",{...u,value:String(s??""),onChange:m=>o(m.target.value),rows:6})});if(e.type==="checkbox")return n.jsx(oe,{label:e.label,hint:h,inline:!0,wide:!l,children:n.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 n.jsx(oe,{label:e.label,hint:h,children:n.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"?YW(m.target.value):m.target.value)})})}function qW({field:e,action:t,fields:s,values:r,data:i,disabled:a,hint:l,children:o}){const c=mt(),u=d.useId(),h=jW()===u,[f,m]=d.useState(!1),[p,g]=d.useState(null),[v,b]=d.useState(null),[j,x]=d.useState(null);d.useEffect(()=>()=>$0(u),[u]);const w=xw(s,r,i),y=t.args!==void 0?Zr(t.args,{data:i,fields:r,shape:s,omit:w,scope:c}):Object.fromEntries(Object.entries(r).filter(([S,C])=>!w.has(S)&&C!=="")),k=async()=>{if(h){$0(u);return}m(!0),g(null),b(null),x(null);try{const S=await $.pageAct(c.plugin,{tool:t.tool,args:y});if(S.approvalId){x(S.approvalId);return}g(DT(S.result));const C=MT(S.result);C&&await LT(C,u)}catch(S){b(S instanceof Error?S.message:String(S))}finally{m(!1)}},N=h?"Stop":t.label;return n.jsx(oe,{label:e.label,hint:l,action:n.jsx(A,{"data-shape":"icon","aria-label":f?`${t.label}: working`:N,title:N,"aria-busy":f||void 0,"aria-pressed":t.icon==="play"?h:void 0,disabled:a===!0||f,onClick:()=>void k(),children:f?n.jsx("span",{className:"ui-spinner","aria-hidden":"true"}):n.jsx(ce,{name:h?"stop":t.icon??"arrow"})}),after:v?n.jsx(re,{message:v}):j?n.jsx(vh,{id:j,onDecided:()=>x(null)}):p?n.jsx("span",{className:"ui-field-hint",role:"status",children:p}):null,children:o})}function YW(e){if(e.trim()==="")return"";const t=Number(e);return Number.isFinite(t)?t:e}function XT(e,t){return{...typeof t=="object"&&t!==null?t:{},...e}}function xw(e,t,s){const r=XT(t,s);return new Set(e.filter(i=>i.when!==void 0&&!en(r,i.when)||i.disabledWhen!==void 0&&en(r,i.disabledWhen)).map(i=>i.name))}function $f({fields:e,values:t,data:s,disabled:r,compact:i,columns:a,onChange:l}){const o=XT(t,s);return n.jsx(Hs,{dense:i,columns:a,children:e.filter(c=>c.when===void 0||en(o,c.when)).map(c=>n.jsx(GW,{field:c,fields:e,compact:i,value:t[c.name],values:t,data:s,disabled:r===!0||c.disabledWhen!==void 0&&en(o,c.disabledWhen),onChange:u=>l(c.name,u)},c.name))})}const Tc=d.createContext(!1),ZT=d.createContext(!1),e$=d.createContext(!1);function hs({title:e,note:t,actions:s,children:r}){const i=d.useContext(Tc);return n.jsx(ue,{title:e,aside:t,actions:s,panel:i,children:n.jsx(Tc.Provider,{value:!1,children:n.jsx(ZT.Provider,{value:i,children:r})})})}function jr({component:e,data:t,choose:s,chosen:r}){const i=mt(),a=d.useContext(gh);if(!en(t,e.when))return null;if(e.kind!=="section"&&!a&&HT(e,i.sensitive))return n.jsx(qT,{children:n.jsx(jr,{component:e,data:t,...s?{choose:s}:{},...r===void 0?{}:{chosen:r}})});switch(e.kind){case"section":return n.jsx(JW,{component:e,data:t});case"notice":return n.jsx(QW,{component:e,data:t});case"link":return n.jsx(XW,{component:e,data:t});case"progress":return n.jsx(eH,{component:e,data:t});case"chart":return n.jsx(tH,{component:e,data:t});case"stats":return n.jsx(nH,{component:e,data:t});case"list":return n.jsx(rH,{component:e,data:t,...s?{onChoose:s}:{},...r===void 0?{}:{chosen:r}});case"table":return n.jsx(lH,{component:e,data:t});case"detail":return n.jsx(hH,{component:e,data:t});case"form":return n.jsx(fH,{component:e,data:t});case"search":return n.jsx(gH,{component:e,data:t});case"list-detail":return n.jsx(xH,{component:e,data:t});case"repeat":return n.jsx(vH,{component:e,data:t});case"calendar":return n.jsx(jH,{component:e,data:t});case"tiles":return n.jsx(wH,{component:e,data:t});case"series-panel":return n.jsx(yH,{component:e,data:t});case"hero":return n.jsx(bH,{component:e,data:t});case"tabs":return n.jsx(kH,{component:e,data:t});case"expand":return n.jsx(NH,{component:e,data:t});case"button":return n.jsx(a$,{component:e,data:t});case"approval":return n.jsx(DH,{component:e,data:t});case"artifact":return n.jsx(OH,{component:e,data:t});case"editor":return n.jsx(LH,{component:e,data:t});case"agent-offer":return n.jsx(SH,{component:e});case"stories":return n.jsx(AH,{component:e,data:t});default:return n.jsx(V,{children:"This page uses a part this dashboard does not know yet. Reload buddi to see it."})}}function JW({component:e,data:t}){const s=mt(),r=d.useContext(gh),[i,a]=KT(),l=!r&&HT(e.body,s.sensitive),o=l&&!i,c=d.useContext(Tc);let u=e.body.length;const h=p=>p.kind==="button"||p.kind==="link"||p.kind==="form"&&p.drawer!==void 0&&!p.title;for(;c&&u>0&&h(e.body[u-1]);)u-=1;const f=e.body.slice(0,u),m=[...e.actions??[],...e.body.slice(u)];return n.jsx(hs,{title:e.title,note:e.note,actions:m.length>0||l?n.jsxs(n.Fragment,{children:[m.map((p,g)=>n.jsx(jr,{component:p,data:t},g)),l?n.jsx(VT,{revealed:i,onToggle:a}):null]}):void 0,children:n.jsx(le,{gap:"lg",divided:c,children:o?n.jsx(GT,{}):n.jsx(gh.Provider,{value:r||l,children:f.map((p,g)=>n.jsx(jr,{component:p,data:t},g))})})})}function QW({component:e,data:t}){const s=mt(),r=Sa(),i=typeof e.text=="string"?e.text:String(Oe(t,e.text)??""),a=e.link&&en(t,e.link.when)?e.link:void 0,l=a?Xr(s,a.to,t):"",o=a?typeof a.label=="string"?a.label:String(Oe(t,a.label)??""):"",c=a&&l!==""&&o!==""?"href"in a.to?n.jsx(Tf,{href:l,children:o}):n.jsx("a",{href:l,onClick:h=>{h.preventDefault(),s.navigate(l)},children:o}):null;if(e.look==="quiet")return i===""&&!c?null:n.jsxs("p",{className:"pl-quiet","data-tone":e.tone,children:[e.icon?n.jsx(ce,{name:e.icon,size:14}):null,n.jsxs("span",{children:[i,c?n.jsxs(n.Fragment,{children:[i?" · ":null,c]}):null]})]});const u=e.action;return n.jsxs(n.Fragment,{children:[n.jsxs(V,{tone:gw(e.tone),title:e.title,action:u?n.jsx(Ca,{action:u,args:Zr(u.args,{data:t,scope:s}),disabled:r.busy,running:r.running===u.tool,onRun:(h,f)=>void r.run(h,f)}):void 0,children:[i,c?n.jsxs(n.Fragment,{children:[" ",c]}):null]}),n.jsx(l$,{act:r})]})}function XW({component:e,data:t}){const s=mt(),r=Xr(s,e.to,t);return r===""?null:"href"in e.to?n.jsx(ae,{children:n.jsxs(dt,{href:r,target:"_blank",rel:"noopener noreferrer",children:[e.label,n.jsx("span",{className:"wb-src-out","aria-hidden":"true",children:"↗"}),n.jsx("span",{className:"sr-only",children:" (opens in a new tab)"})]})}):n.jsx(ae,{children:n.jsx(dt,{href:r,variant:e.tone==="accent"?"accent":void 0,onClick:i=>{i.preventDefault(),s.navigate(r)},children:e.label})})}function D0(e){return Math.round(e/1e6)}function ZW(e,t){const s=ss(Oe(t,e.value))??0,r=e.total?ss(Oe(t,e.total)):null,i=e.total?r&&r>0?s/r:0:s,a=Math.max(0,Math.min(1,i)),l=Math.floor(a*100),o=i>=1,c=e.total&&r&&r>0?`${D0(s)} of ${Math.max(1,D0(r))} MB · ${l}%`:`${l}%`;return{percent:l,full:o,line:c}}function eH({component:e,data:t}){const s=c=>c===void 0?"":typeof c=="string"?c:String(Oe(t,c)??""),r=s(e.label),i=s(e.done),{percent:a,full:l,line:o}=ZW(e,t);return n.jsxs(le,{gap:"sm",children:[r?n.jsx("span",{children:r}):null,l&&i?n.jsx("span",{role:"status",children:i}):n.jsxs(n.Fragment,{children:[n.jsx(UA,{value:a,label:r||"Progress"}),n.jsx("span",{role:"status",children:o})]})]})}function tH({component:e,data:t}){const s=gn(e.query,t),r=e.rows===void 0?Array.isArray(s.data)?s.data:[]:Ks(s.data,e.rows),i=r.map(h=>String(Ne(h,e.x)??"")),a=h=>r.map(f=>ss(Ne(f,h))??null),l=e.series!==void 0,o=e.y===void 0?[]:Array.isArray(e.y)?e.y:[e.y],c=l?e.series.map(h=>({label:h.label,values:a(h.y),type:h.type,...h.unit?{unit:h.unit}:{}})):o.map(h=>({label:o.length===1?e.label??h:h,values:a(h)})),u=e.target?ss(Oe(s.data,e.target))??null:null;return n.jsxs(hs,{title:e.title,note:e.note,children:[n.jsx(re,{message:s.error}),r.length===0?s.loading||s.data===void 0?n.jsx(pe,{children:"Loading…"}):n.jsx(Aa,{text:e.empty??"Nothing recorded yet."}):n.jsx(qU,{xs:i,series:c,type:l?"mixed":e.type??"line",target:u,...e.label?{label:e.label}:{},formatX:h=>/^\d{4}-\d{2}-\d{2}/.test(h)?Gg(h):h,formatY:h=>nn(h,"number",null)})]})}function nH({component:e,data:t}){const s=gn(e.query,t);return n.jsxs(hs,{title:e.title,note:e.note,children:[n.jsx(re,{message:s.error}),s.data===void 0?n.jsx(pe,{children:e.empty??"Loading…"}):n.jsx(Nf,{children:e.items.map((r,i)=>n.jsx(ur,{label:r.label,value:nn(Oe(s.data,r.value),r.unit??"text",null),tone:KW(r.tone)},i))})]})}function t$(e,t,s,r){const i=(t.meta??[]).map(y=>String(Oe(s,y)??"")).filter(y=>y!==""),a=String(Oe(s,t.title)??""),l=t.to&&!r?Xr(e,t.to,s):null,o=l===""?null:l,c=o!==null&&t.to!==void 0&&"href"in t.to,u=t.images?n.jsx(VW,{plugin:e.plugin,images:t.images,row:s}):null,f=[...t.pill?[t.pill]:[],...t.pills??[]].map((y,k)=>{const N=Oe(s,y.value);if(N==null||N==="")return null;const S=sH(y,N,s);return n.jsx(we,{tone:Cx(S.tone),children:S.text},k)}),m=o&&c?n.jsx(Tf,{href:o,children:a}):o?n.jsx("a",{href:o,onClick:y=>{y.preventDefault(),e.navigate(o)},children:a}):a,p=t.tag?Oe(s,t.tag):void 0,g=p==null||p===""?null:n.jsx("span",{className:"pl-row-tag",children:String(p)}),v=t.status?Oe(s,t.status.text):void 0,b=t.status?xh(t.status.tone,s):void 0,j=v==null||v===""?null:n.jsx("span",{className:"pl-row-status","data-tone":b,children:String(v)}),x=t.sub?String(Oe(s,t.sub)??""):"",w=t.logo?n.jsx(eu,{className:"pl-logo-lg",src:Af(e.plugin,Oe(s,t.logo.asset)),label:String(Oe(s,t.logo.label)??"")}):null;return{text:a,href:o,outside:c,lead:w,pills:n.jsx(n.Fragment,{children:f}),meta:i.join(" · "),title:u?n.jsxs(n.Fragment,{children:[u,n.jsx("span",{className:"pl-row-title",children:m}),g]}):g?n.jsxs(n.Fragment,{children:[m,g]}):m,sub:j?n.jsxs(n.Fragment,{children:[x?n.jsx("span",{className:"pl-row-line",children:x}):null,j]}):t.sub?x:null,side:n.jsxs(n.Fragment,{children:[f,i.length>0?n.jsxs("span",{className:"muted",children:[" ",i.join(" · ")]}):null]})}}function sH(e,t,s){const r=String(t),i=e.labels??{},a=e.tones??{};return{text:Object.prototype.hasOwnProperty.call(i,r)?i[r]:r,tone:Object.prototype.hasOwnProperty.call(a,r)?a[r]:xh(e.tone,s)}}function Ks(e,t){const s=Ne(e,t);return Array.isArray(s)?s:[]}function n$(e,t,s){const r=[],i=new Set;return e.forEach((a,l)=>{const o=t===void 0?void 0:Ne(a,t),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 "${t??"(no key)"}" — not drawn`);return}if(i.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}i.add(c),r.push({key:c,row:a})}),r}function rH({component:e,data:t,onChoose:s,chosen:r}){var N;const i=mt(),a=d.useContext(e$),l=gn(e.query,t),o=Sa(),[c,u]=d.useState([]),h=a&&!e.select&&(e.actions??[]).length===0&&(e.bulk??[]).length===0,f=Ks(l.data,e.rows),m=e.collapsed?Ks(l.data,e.collapsed.rows):[],p=s$(e.actions,f,o),g={plugin:i.plugin,page:i.page,component:`list "${e.title??e.rows}"`},v=n$([...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||!en(S,e.select.disabledWhen)}).map(({key:S})=>S)),w=c.filter(S=>x.has(S)),y=d.useMemo(()=>{const S=f.filter(R=>j.has(R));if(!e.groupBy)return[{label:null,aside:null,rows:S}];const C=new Map;for(const R of S){const I=String(Ne(R,e.groupBy.key)??"");C.set(I,[...C.get(I)??[],R])}const E=(R,I)=>{var T,M,P;const L=(M=(T=e.groupBy)==null?void 0:T.labels)==null?void 0:M[R];if(L!==void 0)return L;const F=(P=e.groupBy)!=null&&P.label?Ne(I,e.groupBy.label):void 0;return F==null||F===""?R:String(F)};return[...C].map(([R,I])=>{var F;const L=(F=e.groupBy)!=null&&F.aside?Ne(I[0],e.groupBy.aside):void 0;return{label:E(R,I[0]),aside:L==null||L===""?null:String(L),rows:I}})},[f,e.groupBy,v.length]),k=S=>S.map(C=>{var M;const E=t$(i,e.item,C,s),R=b.get(C);if(h&&(s||E.href&&!E.outside))return n.jsx(BA,{href:E.href??"#",current:r===R,onClick:()=>s?s(R):i.navigate(E.href),title:E.text,meta:E.meta,sub:E.sub,side:E.pills},R);const I=((M=e.select)==null?void 0:M.disabledWhen)!==void 0&&en(C,e.select.disabledWhen),L=(e.actions??[]).filter(P=>en(C,P.when)),F=L.filter(P=>P.menu!==!0),T=L.filter(P=>P.menu===!0);return n.jsx(et,{lead:E.lead?E.lead:e.select?n.jsx("input",{type:"checkbox","aria-label":`Select ${E.text}`,disabled:I,checked:c.includes(R),onClick:P=>P.stopPropagation(),onChange:P=>u(D=>P.target.checked?[...D,R]:D.filter(O=>O!==R))}):void 0,title:s?n.jsx("a",{href:"#","aria-current":r===R?"true":void 0,onClick:P=>{P.preventDefault(),s(R)},children:E.text}):E.title,sub:E.sub,side:n.jsxs(n.Fragment,{children:[E.side,F.map((P,D)=>n.jsx(r$,{action:P,row:C,data:l.data,act:o,onForm:p.show},D)),T.length>0?n.jsx(aH,{actions:T,row:C,title:E.text,data:l.data,act:o,onForm:p.show}):null]})},R)});return n.jsxs(hs,{title:e.title,note:e.note,children:[n.jsx(re,{message:l.error}),p.open?null:n.jsx(Ea,{act:o}),p.open?n.jsx(i$,{open:p.open,data:l.data,act:o,onClose:p.close,onDone:p.finish}):null,y.every(S=>S.rows.length===0)?l.loading?n.jsx(pe,{children:"Loading…"}):n.jsx(Aa,{text:e.empty??"Nothing here yet."}):n.jsxs(rt,{children:[e.select?n.jsx(et,{lead:n.jsx("input",{type:"checkbox","aria-label":"Select every row",checked:x.size>0&&w.length===x.size,disabled:x.size===0,onChange:S=>u(S.target.checked?[...x]:[])}),title:n.jsxs("span",{className:"muted",children:[x.size," to choose from"]})}):null,y.map((S,C)=>n.jsxs("div",{children:[S.label?n.jsxs("div",{className:"ui-list-group","data-aside":S.aside?"true":void 0,children:[S.label,S.aside?n.jsx("span",{className:"pl-group-aside",children:S.aside}):null]}):null,k(S.rows)]},C))]}),e.collapsed&&m.some(S=>j.has(S))?n.jsx(Tt,{summary:`${e.collapsed.label} (${m.filter(S=>j.has(S)).length})`,children:n.jsx(rt,{children:k(m.filter(S=>j.has(S)))})}):null,e.bulk&&e.bulk.length>0?n.jsxs(ae,{align:"end",children:[n.jsxs("span",{className:"ui-toolbar-note",children:[w.length," selected"]}),e.bulk.map((S,C)=>{const E=w.length>0||S.all!==!0?w:[...x];return n.jsx(Ca,{action:S,args:Zr(S.args,{data:l.data,selected:E,scope:i}),count:E.length,disabled:o.busy||E.length===0,running:o.running===S.tool,onRun:(R,I)=>{u([]),o.run(R,I)}},C)})]}):null]})}function iH(e,t,s){return Object.entries(e).every(([r,i])=>{const a=typeof i=="string"?i:Ne(s,i.row);return a!=null&&t[r]===String(a)})}function s$(e,t,s){const r=mt(),[i,a]=d.useState(null);return d.useEffect(()=>{var l;if(!(i!==null||t.length===0))for(const o of e??[]){const c=(l=o.form)==null?void 0:l.openWhen;if(!c)continue;const u=t.find(h=>en(h,o.when)&&iH(c,r.params,h));if(u!==void 0){a({action:o,row:u}),r.setParams(Object.fromEntries(Object.keys(c).map(h=>[h,null])));return}}},[t.length,JSON.stringify(r.params)]),{open:i,show:(l,o)=>{s.reset(),a({action:l,row:o})},close:()=>{s.reset(),a(null)},finish:()=>a(null)}}function r$({action:e,row:t,data:s,act:r,onForm:i}){const a=mt();return e.form?n.jsx(A,{disabled:r.busy,onClick:()=>i(e,t),children:Os(e.label,{row:t})}):n.jsx(Ca,{action:e,args:Zr(e.args,{data:s,row:t,scope:a}),disabled:r.busy,running:r.running===e.tool,row:t,onRun:(l,o)=>void r.run(l,o)})}function aH({actions:e,row:t,title:s,data:r,act:i,onForm:a}){const l=mt(),[o,c]=d.useState(null),u=m=>void i.run(m,Zr(m.args,{data:r,row:t,scope:l})),h=[];let f;return e.forEach((m,p)=>{m.group!==f?(p>0&&h.push("separator"),m.group&&h.push({heading:m.group}),f=m.group):m.tone==="danger"&&p>0&&h.push("separator"),h.push({label:Os(m.label,{row:t}),...m.hint?{hint:Os(m.hint,{row:t})}:{},...m.tone==="danger"?{tone:"critical"}:{},onSelect:()=>m.form?a(m,t):m.confirm?c(m):u(m)})}),n.jsxs(n.Fragment,{children:[n.jsx(Ys,{label:`More for ${s}`,items:h,sheet:{title:s}}),o?n.jsx(Dt,{title:Os(o.confirm??o.label,{row:t}),onClose:()=>c(null),foot:n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",onClick:()=>c(null),children:"Cancel"}),n.jsx(A,{variant:o.tone==="danger"?"danger":"accent",onClick:()=>{const m=o;c(null),u(m)},children:Os(o.label,{row:t})})]})}):null]})}function i$({open:e,data:t,act:s,onClose:r,onDone:i}){const a=mt(),{action:l,row:o}=e,c=l.form,[u,h]=d.useState(()=>Ac(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 n.jsx(Ye,{title:Os(c.title,{row:o}),onClose:r,foot:n.jsxs(ae,{align:"end",children:[n.jsx(A,{variant:"ghost",onClick:r,children:"Cancel"}),n.jsx(Ca,{action:g,args:Zr(l.args,{data:t,row:o,fields:u,shape:c.fields,scope:a}),disabled:s.busy||f,running:s.running===l.tool,row:o,onRun:(v,b)=>void s.run(v,b,i)})]}),children:n.jsxs(le,{children:[n.jsx($f,{fields:c.fields,values:u,data:o,onChange:(v,b)=>h(j=>({...j,[v]:b}))}),n.jsx(re,{message:s.error})]})})}function lH({component:e,data:t}){const s=gn(e.query,t),r=Sa(),i=Ks(s.data,e.rows),a=s$(e.actions,i,r);return n.jsxs(hs,{title:e.title,note:e.note,children:[n.jsx(re,{message:s.error}),a.open?null:n.jsx(Ea,{act:r}),a.open?n.jsx(i$,{open:a.open,data:s.data,act:r,onClose:a.close,onDone:a.finish}):null,i.length===0?s.loading?n.jsx(pe,{children:"Loading…"}):n.jsx(Aa,{text:e.empty??"Nothing here yet."}):n.jsxs(kr,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[e.columns.map(l=>n.jsx("th",{children:l.label},l.key)),e.actions&&e.actions.length>0?n.jsx("th",{"aria-label":"Actions"}):null]})}),n.jsx("tbody",{children:i.map((l,o)=>n.jsxs("tr",{children:[e.columns.map(c=>{const u=c.pill?null:nn(Ne(l,c.key),c.type??"text",null);return n.jsxs("td",{"data-fit":c.fit,title:uH(c,l,u),children:[c.pill?null:n.jsx(cH,{column:c,row:l}),c.pill?n.jsx(dH,{column:c,row:l}):c.fit==="truncate"?n.jsx("span",{className:"ui-table-cut",children:u}):u]},c.key)}),e.actions&&e.actions.length>0?n.jsx("td",{children:n.jsx(ae,{align:"end",children:e.actions.filter(c=>en(l,c.when)).map((c,u)=>n.jsx(r$,{action:c,row:l,data:s.data,act:r,onForm:a.show},u))})}):null]},o))})]})]})}const oH=/^#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i;function cH({column:e,row:t}){if(!e.swatch)return null;const s=Ne(t,e.swatch);return typeof s!="string"||!oH.test(s)?null:n.jsx("span",{className:"ui-table-swatch","aria-hidden":"true",style:{"--swatch":s}})}function uH(e,t,s){if(e.hint){const r=Ne(t,e.hint);if(r!=null&&r!=="")return String(r)}return e.fit==="truncate"&&s?s:void 0}function dH({column:e,row:t}){var l,o;const s=Ne(t,e.key);if(Array.isArray(s))return n.jsx(n.Fragment,{children:s.map((c,u)=>{var v;const h=c,f=typeof h=="object"&&h!==null?h.value:c;if(f==null||f==="")return null;const m=typeof h=="object"&&h!==null?h.tone:void 0,p=(v=e.pill)==null?void 0:v.labels,g=p&&Object.prototype.hasOwnProperty.call(p,String(f))?p[String(f)]:nn(f,e.type??"text",null);return n.jsx(we,{tone:Cx(xh(typeof m=="string"?m:void 0,t)),children:g},u)})});const r=(l=e.pill)==null?void 0:l.labels,i=String(s),a=r&&Object.prototype.hasOwnProperty.call(r,i)?r[i]:nn(s,e.type??"text",null);return n.jsx(we,{tone:Cx(xh((o=e.pill)==null?void 0:o.tone,t)),children:a})}function hH({component:e,data:t}){const s=gn(e.query,t);return s.error?n.jsx(re,{message:s.error}):s.data===void 0?n.jsx(pe,{children:e.empty??"Loading…"}):n.jsx(hs,{title:e.title,note:e.note,children:n.jsxs(le,{gap:"lg",children:[e.fields.length>0?n.jsx(Gt,{items:e.fields.map(r=>({key:r.label,label:r.label,value:nn(Oe(s.data,r.value),r.unit??"text",null)}))}):null,e.body.map((r,i)=>n.jsx(jr,{component:r,data:s.data},i))]})})}function fH({component:e,data:t}){const s=mt(),r=gn(e.initial,t),i=Sa(),[a,l]=d.useState(!1),o=JSON.stringify([r.data??null,s.version]),c=n.jsx(mH,{component:e,data:t,initialData:r.data,act:i,onDone:()=>l(!1)},o);return e.drawer?n.jsxs(ue,{title:e.title,aside:e.note,actions:n.jsx(A,{variant:"accent",onClick:()=>l(!0),children:e.drawer.button}),children:[n.jsx(Ea,{act:i}),a?n.jsx(Ye,{title:e.drawer.title,onClose:()=>l(!1),children:c}):null]}):n.jsxs(hs,{title:e.title,note:e.note,children:[n.jsx(re,{message:r.error}),c]})}function mH({component:e,data:t,initialData:s,act:r,onDone:i}){const a=d.useContext(ZT),l=mt(),[o,c]=d.useState(()=>Ac(e.fields,s)),u=xw(e.fields,o,s),h=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 n.jsxs(le,{children:[n.jsx($f,{fields:e.fields,columns:e.columns,values:o,data:s,onChange:(f,m)=>c(p=>({...p,[f]:m}))}),e.drawer?null:n.jsx(Ea,{act:r}),n.jsx(ae,{align:"end",className:a?"ui-panel-foot":void 0,children:n.jsx(Ca,{action:e.submit,args:Zr(e.submit.args,{data:t,fields:o,shape:e.fields,omit:u,scope:l}),disabled:r.busy||h,running:r.running===e.submit.tool,onRun:(f,m)=>void r.run(f,m,i)})})]})}function pH(e,t){var r;if(e.type==="checkbox")return e.label;const s=(r=e.options)==null?void 0:r.find(i=>i.value===t);return`${e.label}: ${s?s.label:t}`}function O0(e){return e!=null&&e!==""&&e!==!1&&e!=="false"}function gH({component:e,data:t}){const s=mt(),[r,i]=d.useState(()=>Ac(e.fields,t)),[a,l]=d.useState(e.auto===!0),[o,c]=d.useState(!1),u=e.fields.every(C=>!C.required||String(r[C.name]??"")!==""),h=gn(a&&u?e.query:void 0,t),f=Ks(h.data,e.rows),m=e.count===void 0?void 0:Ne(h.data,e.count),p=e.note===void 0?void 0:Ne(h.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 R={...r,[C]:E};i(R),e.auto&&b(R)},x=()=>{const C=Ac(e.fields,null);i(C),e.auto?b(C):(s.setParams(Object.fromEntries(e.fields.map(E=>[E.name,null]))),l(!1))},w=a?v.filter(C=>O0(s.params[C.name])):[],y=g?w.map(C=>n.jsx(ih,{label:C.label,onRemove:()=>{const E={...r,[C.name]:C.type==="checkbox"?!1:""};i(E),b(E)},children:pH(C,String(s.params[C.name]))},C.name)):[],k=v.filter(C=>O0(r[C.name])).length,N=e.auto&&!e.reset?null:n.jsxs(n.Fragment,{children:[e.reset?n.jsx(A,{variant:"ghost",onClick:x,children:"Clear"}):null,e.auto?null:n.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 n.jsx(hs,{title:e.title,children:n.jsxs(le,{children:[n.jsx(KA,{label:e.title??"Search",onSubmit:()=>{!e.auto&&u&&b(r)},main:g?n.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?n.jsx($f,{fields:v,values:r,data:t,compact:!0,onChange:j}):void 0,...g&&v.length>0?{filtersOpen:o,onToggleFilters:()=>c(C=>!C),active:k}:{},chips:y.length>0?y:void 0,actions:N}),n.jsx(re,{message:h.error}),a&&(m!==void 0||p!==void 0)?n.jsxs("p",{className:"ui-card-meta",children:[m===void 0?"":`${nn(m,"number",null)} in all. `,p===void 0?"":String(p)]}):null,a?f.length===0?n.jsx(pe,{children:h.loading?"Searching…":e.empty??"Nothing matches."}):n.jsx("div",{className:"ui-panel","data-flush":"true",children:n.jsx(rt,{children:f.map((C,E)=>{const R=t$(s,S,C);return n.jsx(et,{title:R.title,sub:R.sub,side:R.side},E)})})}):null]})})}function xH({component:e,data:t}){const s=mt(),r=e.selection==="local",[i,a]=d.useState(null),l=r?i:s.params[e.param]??s.item,o=r&&i!==null?{...s,params:{...s.params,[e.param]:i}}:null,c=n.jsx(le,{gap:"lg",divided:!0,children:e.detail.map((u,h)=>n.jsx(jr,{component:u,data:t},h))});return n.jsx(Tc.Provider,{value:!1,children:n.jsx(WA,{list:n.jsx(e$.Provider,{value:!0,children:n.jsx(jr,{component:e.list,data:t,chosen:l??null,...r?{choose:a}:{}})}),detail:l?o?n.jsx(pw.Provider,{value:o,children:c}):c:void 0,empty:e.empty??"Choose one to see it here."})})}function vH({component:e,data:t}){const s=mt(),[r,i]=d.useState(!1),a=gn(e.query,t,r&&e.poll?e.poll.seconds*1e3:void 0),l=e.poll!==void 0&&a.data!==void 0&&en(a.data,e.poll.while);d.useEffect(()=>i(l),[l]);const o=Ks(a.data,e.rows);return n.jsxs(hs,{title:e.title,note:e.note,children:[n.jsx(re,{message:a.error}),o.length===0?a.loading?n.jsx(pe,{children:"Loading…"}):n.jsx(Aa,{text:e.empty??"Nothing here yet."}):n.jsx(le,{gap:"lg",divided:!0,children:n$(o,e.key,{plugin:s.plugin,page:s.page,component:`repeat "${e.title??e.rows}"`}).map(({key:c,row:u})=>n.jsx(ue,{children:n.jsx(le,{children:e.body.map((h,f)=>n.jsx(jr,{component:h,data:u},f))})},c))})]})}function jH({component:e,data:t}){const s=mt(),r=MW({...e.views?{views:e.views}:{},...e.default?{default:e.default}:{},today:bW(s.timezone),storageKey:`buddi.calendar-view:${s.plugin}/${s.page}`}),i=gn(e.query,t,void 0,{from:r.from,to:r.to}),a=d.useMemo(()=>CW(Ks(i.data,e.events),e.map,s.timezone,`plugin ${s.plugin}, page ${s.page}, calendar`),[i.data,e.events,e.map,s.timezone,s.plugin,s.page]);return n.jsxs(hs,{title:e.title,note:e.note,children:[n.jsx(re,{message:i.error}),n.jsx(DW,{state:r,events:a,hours:e.hours,empty:e.empty??"Nothing.",label:e.title??"Calendar"})]})}function wH({component:e,data:t}){var f;const s=mt(),r=gn(e.query,t),i={items:"$",icon:e.icon,value:e.value,label:e.label,...e.lines?{lines:e.lines}:{},...e.tone?{tone:e.tone}:{}},a=Ks(r.data,e.items).flatMap(m=>{const p=Bj([m],i).tiles[0];return p?[{tile:p,key:e.select?String(Ne(m,e.select.key)??""):""}]:[]}),l=e.select,o=l?Math.max(0,a.findIndex(m=>m.key===s.params[l.param])):null,c=((f=a[0])==null?void 0:f.key)??"",u=l?s.params[l.param]:void 0,h=a.some(m=>m.key===u);return d.useEffect(()=>{l&&c!==""&&!h&&s.setParams({[l.param]:c})},[l==null?void 0:l.param,c,h]),n.jsxs(hs,{title:e.title,note:e.note,children:[n.jsx(re,{message:r.error}),r.data===void 0?n.jsx(pe,{children:"Loading…"}):a.length===0?n.jsx(Aa,{text:e.empty??"Nothing to show."}):n.jsx(sT,{props:{tiles:a.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=a[m])==null?void 0:p.key)||null})}}:{}})]})}function yH({component:e,data:t}){const s=gn(e.query,t),r=Ks(s.data,e.points);if(s.data===void 0||r.length===0)return n.jsxs(hs,{title:e.title,note:e.note,children:[n.jsx(re,{message:s.error}),s.data===void 0?n.jsx(pe,{children:"Loading…"}):n.jsx(Aa,{text:e.empty??"Nothing to show."})]});const i=r.map(c=>String(Ne(c,e.x)??"")),a={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)=>Bj([c],a).tiles[0]??{icon:null,value:"",label:i[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=>ss(Ne(u,c.y))??null)}));return n.jsxs(n.Fragment,{children:[n.jsx(re,{message:s.error}),n.jsx(UW,{...e.title?{title:e.title}:{},...e.note?{note:e.note}:{},...e.labelEvery?{labelEvery:e.labelEvery}:{},xs:i,series:o,tiles:l})]})}function bH({component:e,data:t}){const s=gn(e.query,t),r=o=>{const c=Ne(s.data,o);return c==null?"":String(c)};if(s.data===void 0||s.data===null)return n.jsxs(n.Fragment,{children:[n.jsx(re,{message:s.error}),n.jsx(pe,{children:s.loading?"Loading…":e.empty??"Nothing to show."})]});const i=r(e.value),a=r(e.title),l=e.facts.map(o=>({label:o.label,value:r(o.path)})).filter(o=>o.value!=="");return n.jsxs("section",{className:"pg-hero","aria-label":[i,a,...l.map(o=>`${o.label} ${o.value}`)].filter(Boolean).join(", "),children:[n.jsxs("div",{className:"pg-hero-main","aria-hidden":"true",children:[n.jsx("span",{className:"pg-hero-icon",children:n.jsx(ce,{name:Jl(nx(Oe(s.data,e.icon))),size:44})}),n.jsx("span",{className:"pg-hero-value",children:i}),a?n.jsx("span",{className:"pg-hero-title",children:a}):null]}),l.length>0?n.jsx("dl",{className:"pg-hero-facts","aria-hidden":"true",children:l.map(o=>n.jsxs("div",{className:"pg-hero-fact",children:[n.jsx("dt",{children:o.label}),n.jsx("dd",{children:o.value})]},o.label))}):null]})}function kH({component:e,data:t}){var g;const s=mt(),[r,i]=d.useState(e.default??e.tabs[0].id),a=e.param,l=a?s.params[a]??e.default??e.tabs[0].id:r,o=v=>a?s.setParams({[a]:v}):i(v),c=e.pick,{options:u}=QT({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}:{}},{},t),h=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?Xr(s,c.add.to,t):"";return n.jsxs("div",{className:"pg-tabs",children:[n.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?n.jsxs("div",{className:"pl-chips",role:"group","aria-label":c.label,children:[u.map(v=>n.jsx(A,{size:"sm","aria-pressed":v.value===h,onClick:()=>s.setParams({[c.param]:v.value}),children:v.label},v.value)),c.add&&p!==""?n.jsxs(dt,{size:"sm",variant:"ghost",href:p,onClick:v=>{v.preventDefault(),s.navigate(p)},children:[n.jsx(ce,{name:"plus",size:12}),c.add.label]}):null]}):c&&u.length>1?n.jsx(qt,{label:c.label,options:u,value:h,onChange:v=>s.setParams({[c.param]:v})}):null,e.tabs.length>1?n.jsx("span",{className:"pg-tabs-switch",children:n.jsx(qt,{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)=>n.jsx(jr,{component:v,data:t},`${f.id}-${b}`))]})}function NH({component:e,data:t}){const[s,r]=d.useState(!1),i=gn(s?e.query:void 0,t),a=typeof e.label=="string"?e.label:String(Oe(t,e.label)??"");return n.jsxs(Tt,{summary:a,boxed:!0,onToggle:l=>r(l),children:[n.jsx(re,{message:i.error}),i.data===void 0?n.jsx(pe,{children:"Loading…"}):n.jsx(le,{children:e.body.map((l,o)=>n.jsx(jr,{component:l,data:i.data},o))})]})}function a$({component:e,data:t}){const s=mt(),r=Sa();return n.jsxs(n.Fragment,{children:[n.jsx(ae,{align:"end",children:n.jsx(Ca,{action:e.action,args:Zr(e.action.args,{data:t,row:t,scope:s}),disabled:r.busy,running:r.running===e.action.tool,row:t,onRun:(i,a)=>void r.run(i,a)})}),n.jsx(Ea,{act:r})]})}function SH({component:e}){const t=mt();return n.jsx(hw,{plugin:t.plugin,agent:e.agent,text:e.text,label:e.label})}function CH(e){if(!e||typeof e!="object")return null;const t=e;return typeof t.id!="string"||t.id===""||typeof t.title!="string"?null:{...t,outlets:Array.isArray(t.outlets)?t.outlets.filter(s=>s&&typeof s.name=="string"):[]}}function Ex(e){return e.length===0?"":e.length===1?e[0].name:`${e[0].name} and ${e.length-1} more`}function L0(e,t,s){const r={};for(const[i,a]of Object.entries(e))"row"in a?r[i]=Ne(t,a.row):"item"in a?r[i]=Ne(s,a.item):r[i]=Oe(t,a);return r}const EH=8e3;function F0(e,t,s){const r=[];let i=null;return e.forEach((a,l)=>{if(!en(t,a.when))return;const o=a.each?Array.isArray(Ne(t,a.each))?Ne(t,a.each).slice(0,4):[]:[void 0];if(o.length!==0){l>0&&r.length>0&&a.group!==i&&r.push("separator"),a.group&&a.group!==i&&r.push({heading:a.group}),i=a.group;for(const c of o)r.push({label:Os(a.label,{row:c===void 0?t:c}),...a.hint?{hint:Os(a.hint,{row:t})}:{},onSelect:()=>s(a,c)})}}),r}function AH({component:e,data:t}){var S,C;const s=mt(),r=gn(e.query,t),i=Sa(),a=e.param??"story",[l,o]=d.useState(null);d.useEffect(()=>{if(!l)return;const E=setTimeout(()=>o(null),EH);return()=>clearTimeout(E)},[l]);const c=Ks(r.data,e.rows).map(CH).filter(E=>E!==null),u=e.ways??[],h=s.params[a],f=h?c.find(E=>E.id===h)??null:null,m=async(E,R,I,L)=>{var P;const F=L0(E.args,R,I);if(!await i.run({tool:E.tool,label:E.label,...E.done!==void 0?{done:E.done}:{},...E.then?{then:E.then}:{}},F)||!E.hides)return;h===R.id&&s.setParams({[a]:null});const M=typeof E.done=="string"?Os(E.done,{row:I===void 0?R:I}):"Hidden.";o({id:R.id,group:((P=R.group)==null?void 0:P.id)??null,index:L,text:M,...E.undo?{undo:{tool:E.undo.tool,label:E.undo.label,args:L0(E.undo.args,R,I)}}:{}})},p=()=>{const E=l;o(null),E!=null&&E.undo&&i.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 R=e.groups&&E.group?E.group.id:null;let I=g.find(L=>L.id===R);I||(I={id:R,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,R)=>n.jsx(IH,{row:E,plugin:s.plugin,menu:F0(u,E,(I,L)=>void m(I,E,L,R)),onOpen:()=>s.setParams({[a]:E.id})},E.id),x=E=>n.jsxs("div",{className:"pl-story-gone",role:"status",children:[n.jsx("span",{children:E.text}),E.undo?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"pl-story-gone-sep","aria-hidden":"true",children:"·"}),n.jsx(A,{size:"sm",variant:"ghost",onClick:p,children:E.undo.label})]}):null]},`gone-${E.id}`),w=E=>{const R=E.rows.map(j);return l&&l.group===E.id&&R.splice(Math.min(l.index,R.length),0,x(l)),R};let y;if(r.data===void 0&&r.loading)y=n.jsx("div",{className:"pl-story-grid","aria-busy":"true","aria-label":"Fetching stories",children:Array.from({length:6},(E,R)=>n.jsxs("div",{className:"ui-card pl-story cat-skel pl-story-skel",children:[n.jsxs("span",{className:"pl-story-head",children:[n.jsx("i",{className:"cat-skel-face pl-story-skel-logo"}),n.jsx("i",{className:"cat-skel-line","data-w":"30"})]}),n.jsx("i",{className:"cat-skel-line","data-w":"90"}),n.jsx("i",{className:"cat-skel-line","data-w":"70"}),n.jsx("i",{className:"cat-skel-line","data-w":"40"})]},R))});else if(c.length===0&&!l){const E=(e.emptyStates??[]).find(R=>en(r.data,R.when));if(E){const R=L=>L===void 0?"":typeof L=="string"?L:String(Oe(r.data,L)??""),I=(E.actions??[]).map((L,F,T)=>{const M=F===T.length-1&&(T.length>1||E.warm===!0);if(L.set)return n.jsx(A,{size:"sm",variant:M?"accent":"ghost",onClick:()=>s.setParams(L.set),children:L.label},F);const P=L.to?Xr(s,L.to,r.data):"";return P===""?null:n.jsx(dt,{size:"sm",variant:M?"accent":"ghost",href:P,onClick:D=>{D.preventDefault(),s.navigate(P)},children:L.label},F)});y=n.jsx(pe,{warm:E.warm===!0,title:R(E.title),action:I.length>0?n.jsx(ae,{children:I}):void 0,children:R(E.text)})}else y=n.jsx(Aa,{text:e.empty??"Nothing here yet."})}else y=g.map(E=>{var R;return n.jsxs("section",{className:"pl-story-group","aria-label":E.name??e.title??"Stories",children:[b&&E.name?n.jsxs("header",{className:"pl-story-group-head",children:[n.jsx("h2",{className:"pl-story-group-title",children:E.name}),v&&E.id?n.jsxs("a",{href:"#",className:"pl-story-group-aside",onClick:I=>{I.preventDefault(),s.setParams({[v]:E.id})},children:[((R=e.groups)==null?void 0:R.label)??"See all",n.jsx(ce,{name:"arrow",size:12})]}):null]}):null,n.jsx("div",{className:"pl-story-grid",children:w(E)})]},E.id??"all")});const k=u.find(E=>E.hides&&!E.each&&en(f,E.when)),N=u.filter(E=>E!==k);return n.jsxs("div",{className:"pl-stories",children:[n.jsx(re,{message:r.error}),n.jsx(l$,{act:i}),y,f?n.jsx(Ye,{title:f.kicker??((C=f.group)==null?void 0:C.name)??e.title??"Story",onClose:()=>s.setParams({[a]:null}),foot:n.jsxs(ae,{children:[k?n.jsx(A,{variant:"ghost",disabled:i.busy,onClick:()=>void m(k,f,void 0,0),children:Os(k.label,{row:f})}):null,N.length>0?n.jsx(Ys,{label:`Less of this: ${f.title}`,trigger:n.jsx("button",{type:"button",className:"ui-btn","data-variant":"ghost",disabled:i.busy,children:"Less of this…"}),items:F0(N,f,(E,R)=>void m(E,f,R,0)),stacked:!0}):null,n.jsx(ht,{}),e.ask&&en(f,e.ask.when)?n.jsx(TH,{to:e.ask.to,row:f,label:e.ask.label,accent:!0}):null]}),children:n.jsx(PH,{row:f,plugin:s.plugin,edition:e.edition})}):null]})}function l$({act:e}){return e.error?n.jsx(re,{message:e.error}):e.approvalId?n.jsx(Ea,{act:e}):null}function TH({to:e,row:t,label:s,accent:r}){const i=mt(),a=Xr(i,e,t);return a===""?null:"href"in e?n.jsx(dt,{variant:r?"accent":"ghost",href:a,target:"_blank",rel:"noopener noreferrer",children:s}):n.jsx(dt,{variant:r?"accent":"ghost",href:a,onClick:l=>{l.preventDefault(),i.navigate(a)},children:s})}function $H({row:e}){var s;const t=((s=e.mark)==null?void 0:s.kind)==="told";return!e.opinion&&!e.languages&&!e.mark?null:n.jsxs("span",{className:"pl-story-marks",children:[e.opinion?n.jsx(kc,{children:"Opinion"}):null,e.languages?n.jsx("span",{className:"pl-story-lang",children:e.languages}):null,e.mark?t?n.jsxs("span",{className:"pl-story-told",children:[n.jsx(ce,{name:"check",size:12}),e.mark.text]}):n.jsx("span",{className:"pl-story-new",children:e.mark.text}):null]})}function RH({plugin:e,outlets:t}){return t.length===0?null:n.jsxs("span",{className:"pl-stack","aria-label":Ex(t),children:[n.jsx("span",{className:"pl-stack-logos",children:t.slice(0,3).map((s,r)=>n.jsx(eu,{src:Af(e,s.logo),label:s.name},r))}),n.jsx("span",{className:"pl-stack-words",children:Ex(t)})]})}function IH({row:e,plugin:t,menu:s,onOpen:r}){var a;const i=Ex(e.outlets);return n.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}.${i?` ${i}`:""}${e.ago?`, ${e.ago}`:""}.`,children:[n.jsxs("header",{className:"pl-story-head",children:[n.jsx(RH,{plugin:t,outlets:e.outlets}),e.ago?n.jsx("span",{className:"pl-story-time",children:e.ago}):null,s.length>0?n.jsx("span",{className:"pl-story-more",onClick:l=>l.stopPropagation(),onKeyDown:l=>l.stopPropagation(),children:n.jsx(Ys,{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??((a=e.group)==null?void 0:a.name),i].filter(Boolean).join(" · ")},stacked:!0})}):null]}),n.jsx("h3",{className:"pl-story-title",children:e.title}),e.lead?n.jsx("p",{className:"pl-story-lead",children:e.lead}):null,n.jsx($H,{row:e})]})}function PH({row:e,plugin:t,edition:s}){const r=Array.isArray(e.sources)?e.sources.filter(l=>l&&typeof l.title=="string"):[],i=Array.isArray(e.timeline)?e.timeline.filter(l=>l&&typeof l.text=="string"):[],a=s&&en(e,s.when)?s:void 0;return n.jsxs("div",{className:"pl-story-sheet",children:[n.jsxs("div",{className:"pl-story-sheet-lead",children:[e.opinion?n.jsx(kc,{children:"Opinion"}):null,n.jsx("h3",{className:"pl-story-sheet-title",children:e.title}),e.summary??e.lead?n.jsx("p",{className:"pl-story-sheet-summary",children:e.summary??e.lead}):null,e.update?n.jsxs("p",{className:"pl-story-sheet-update",children:[e.mark&&e.mark.kind==="new"?n.jsx("span",{className:"pl-story-new",children:e.mark.text}):null,e.update]}):null,e.meta||a?n.jsxs("p",{className:"pl-story-sheet-meta",children:[e.meta,a?n.jsxs(n.Fragment,{children:[e.meta?" · ":null,n.jsx(MH,{to:a.to,row:e,label:a.label})]}):null]}):null]}),r.length>0?n.jsxs("section",{className:"pl-story-sheet-block",children:[n.jsx("h4",{className:"pl-story-sheet-head",children:"Sources"}),n.jsx("ul",{className:"pl-story-sources",children:r.map((l,o)=>{const c=YT(l.url);return n.jsxs("li",{className:"pl-story-source",children:[n.jsx(eu,{className:"pl-logo-md",src:Af(t,l.logo),label:l.outlet}),n.jsxs("span",{className:"pl-story-source-text",children:[c?n.jsx(Tf,{href:c,className:"wb-src-link pl-story-source-title",children:l.title}):n.jsx("span",{className:"pl-story-source-title",children:l.title}),l.meta?n.jsx("span",{className:"pl-story-source-meta",children:l.meta}):null]})]},o)})})]}):null,i.length>0?n.jsxs("section",{className:"pl-story-sheet-block",children:[n.jsx("h4",{className:"pl-story-sheet-head",children:"How it moved"}),n.jsx("ol",{className:"pl-story-timeline",children:i.map((l,o)=>n.jsxs("li",{className:"pl-story-tl","data-told":l.told?"true":void 0,"data-last":o===i.length-1?"true":void 0,children:[n.jsx("span",{className:"pl-story-tl-at",children:l.at}),n.jsx("span",{className:"pl-story-tl-dot","aria-hidden":"true"}),n.jsx("span",{className:"pl-story-tl-what",children:l.text})]},o))})]}):null]})}function MH({to:e,row:t,label:s}){const r=mt(),i=Xr(r,e,t);return i===""?null:"href"in e?n.jsx(Tf,{href:i,children:s}):n.jsx("a",{href:i,onClick:a=>{a.preventDefault(),r.navigate(i)},children:s})}function DH({component:e,data:t}){const s=Ne(t,e.path);return typeof s!="string"||s===""?null:n.jsx(vh,{id:s})}function OH({component:e,data:t}){const s=Ne(t,e.path);return typeof s!="string"||s===""?null:n.jsx(ae,{children:n.jsx("a",{href:Ti(s),children:e.label})})}function LH({component:e,data:t}){const s=gn(e.query,t),r=Sa();return s.error?n.jsx(re,{message:s.error}):s.data===void 0?n.jsx(pe,{children:e.empty??"Loading…"}):n.jsxs(n.Fragment,{children:[n.jsx(Ea,{act:r}),n.jsx(FH,{component:e,data:t,loaded:s.data,act:r},JSON.stringify(s.data))]})}function FH({component:e,data:t,loaded:s,act:r}){const i=mt(),[a,l]=d.useState(()=>Ac(e.fields,s)),o={...a,version:Ne(s,e.version)},c=xw(e.fields,a,s),u=e.readOnlyWhen!==void 0&&en(s,e.readOnlyWhen),h=(e.actions??[]).filter(p=>p.placement==="leading"),f=(e.actions??[]).filter(p=>p.placement!=="leading"),m=(p,g)=>n.jsx(Ca,{action:p,args:Zr(p.args,{data:t,fields:o,shape:e.fields,omit:c,scope:i}),disabled:r.busy,running:r.running===p.tool,onRun:(v,b)=>void r.run(v,b)},`${p.tool}-${g}`);return n.jsx(hs,{title:e.title,note:e.note,children:n.jsxs(le,{children:[n.jsx($f,{fields:e.fields,values:a,data:s,disabled:u,onChange:(p,g)=>l(v=>({...v,[p]:g}))}),u?null:n.jsxs(ae,{align:"end",children:[h.map(m),h.length>0?n.jsx(ht,{}):null,m(e.save,-1),f.map(m)]}),e.footnote?n.jsx("p",{className:"ui-toolbar-note",children:e.footnote}):null]})})}function vw({page:e,item:t,navigate:s,timezone:r,embedded:i,siblings:a,params:l}){const[o,c]=d.useState(()=>({...l})),u=JSON.stringify(l??{});d.useEffect(()=>{l&&Object.keys(l).length>0&&c(b=>({...b,...l}))},[u]);const[h,f]=d.useState(0),m={plugin:e.plugin,page:e.id,pages:a??[e],item:t??null,params:{...o,...t?{item:t}:{},...BH(e,t)},setParams:b=>c(j=>{const x={...j};for(const[w,y]of Object.entries(b))y===null?delete x[w]:x[w]=y;return x}),navigate:s,timezone:r,version:h,refresh:()=>f(b=>b+1),sensitive:new Set(e.sensitive??[])},p=e.body[0],g=!i&&(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 n.jsx(pw.Provider,{value:m,children:n.jsx(_H,{page:v,embedded:i===!0,lede:g})})}function _H({page:e,embedded:t,lede:s}){const r=mt(),i=e.data!==void 0&&r.sensitive.has(e.data.query),a=gn(i?void 0:e.data,null),l=a.data??null,o=s===void 0||typeof s=="string"?s:Oe(l,s),c=o==null||o===""?void 0:String(o),u=!t&&e.actions&&e.actions.length>0?n.jsx(n.Fragment,{children:e.actions.map((h,f)=>n.jsx(zH,{component:h,data:l},f))}):void 0;return n.jsx(On,{embedded:t,title:e.title,lede:c,actions:u,children:n.jsx(UH,{page:e,boxed:t,root:i?void 0:a})})}function zH({component:e,data:t}){const s=mt();if(!en(t,e.when))return null;if(e.kind==="button")return n.jsx(a$,{component:e,data:t});const r=Xr(s,e.to,t);if(r==="")return null;const i=e.tone==="accent"?"accent":"ghost";return"href"in e.to?n.jsxs(dt,{variant:i,href:r,target:"_blank",rel:"noopener noreferrer",children:[e.label,n.jsx("span",{className:"wb-src-out","aria-hidden":"true",children:"↗"})]}):n.jsx(dt,{variant:i,href:r,onClick:a=>{a.preventDefault(),s.navigate(r)},children:e.label})}function UH({page:e,boxed:t,root:s}){const r=mt();return e.data&&r.sensitive.has(e.data.query)?n.jsx(qT,{children:n.jsx(_0,{page:e,boxed:t})}):n.jsx(_0,{page:e,boxed:t,root:s})}function _0({page:e,boxed:t,root:s}){const r=gn(s?void 0:e.data,null),i=s??r;return n.jsxs(le,{gap:"lg",divided:!t,children:[n.jsx(re,{message:i.error}),n.jsx(Tc.Provider,{value:t,children:e.body.map((a,l)=>n.jsx(jr,{component:a,data:i.data??null},l))})]})}function BH(e,t){if(!t)return{};const s=[],r=i=>{for(const a of i)if(a.kind==="list-detail")s.push(a.param),r(a.detail);else if(a.kind==="section"||a.kind==="detail"||a.kind==="expand")r(a.body);else if(a.kind==="tabs")for(const l of a.tabs)r(l.body)};return r(e.body),Object.fromEntries(s.map(i=>[i,t]))}function WH(e){return n.jsx(vw,{...e,embedded:!0})}function Aa({text:e}){const t=e.search(/[.!?]\s/),s=t===-1?e.replace(/[.]$/,""):e.slice(0,t+(e[t]==="."?0:1)),r=t===-1?"":e.slice(t+1).trim();return n.jsx(In,{title:s,children:r||null})}const z0=[{id:"",label:"All files"},{id:"produced",label:"Created by agents"},{id:"uploaded",label:"Uploaded by you"}],HH=["","image","pdf","table","text","code","audio","video","archive","file"];function KH({hash:e,timezone:t,navigate:s,agents:r}){var F;const i=$4(e),a=(i==null?void 0:i.artifactId)??null,l=(i==null?void 0:i.filters.origin)??"",o=(i==null?void 0:i.filters.family)??"",c=(i==null?void 0:i.filters.q)??"",[u,h]=d.useState(c);d.useEffect(()=>{h(c)},[c]);const f=(T,M=!1)=>s(Du(a,{q:c,origin:l,family:o,...T}),M);d.useEffect(()=>{if(u===c)return;const T=window.setTimeout(()=>f({q:u},!0),250);return()=>window.clearTimeout(T)},[u]);const[m,p]=d.useState(null),[g,v]=d.useState(null),[b,j]=d.useState(null),[x,w]=d.useState(!1),[y,k]=d.useState(!1),N=T=>{var M;return T?((M=r.find(P=>P.id===T))==null?void 0:M.name)??T:""},S=d.useRef(0);d.useEffect(()=>{const T=++S.current;p(null),v(null),w(!1),j(null),$.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{}}).then(M=>{S.current===T&&(p(M.entries),v(M.next))}).catch(M=>{S.current===T&&j(M instanceof ve?M.message:String(M))})},[c,l,o]);const C=()=>{if(!g||x)return;w(!0);const T=S.current;$.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{},cursor:g}).then(M=>{S.current===T&&(p(P=>{const D=new Set((P??[]).map(O=>O.id));return[...P??[],...M.entries.filter(O=>!D.has(O.id))]}),v(M.next))}).catch(M=>{S.current===T&&j(M instanceof ve?M.message:String(M))}).finally(()=>{S.current===T&&w(!1)})},E=(l?1:0)+(o?1:0),R=((F=z0.find(T=>T.id===l))==null?void 0:F.label)??l,I=n.jsxs(n.Fragment,{children:[m===null?n.jsx(pe,{children:"Loading…"}):m.length===0?n.jsx(pe,{children:"No file matches that."}):n.jsx(rt,{children:m.map(T=>n.jsx(BA,{href:Du(T.id,{q:c,origin:l,family:o}),current:T.id===a,onClick:()=>s(Du(T.id,{q:c,origin:l,family:o})),lead:n.jsx("span",{className:"files-row-visual","data-family":T.family,children:T.family==="image"&&!T.deleted?n.jsx("img",{src:Yr(T.id),alt:"",loading:"lazy"}):n.jsx(iw,{family:T.family})}),title:T.filename??"Untitled file",meta:n.jsx("span",{title:nt(T.createdAt,t),children:Fe(T.createdAt)}),sub:`${T.caption&&T.origin==="produced"?`${T.caption} · `:""}${ia[T.family]} · ${qn(T.sizeBytes)} · ${o$(T,N)}${VH(T,N)}`},T.id))}),g?n.jsx("div",{className:"files-more",children:n.jsx(A,{size:"sm",onClick:C,disabled:x,children:x?"Loading…":"Show more"})}):null]}),L=m!==null&&m.length===0&&!c&&!l&&!o&&!u;return n.jsxs("div",{className:"ui-page files","data-selected":a?"true":void 0,children:[n.jsxs("header",{className:"ui-page-head",children:[n.jsx("h2",{className:"ui-page-title",children:"Files"}),n.jsx("p",{className:"ui-page-lede",children:"What your agents made or were given."})]}),L?n.jsx(In,{icon:"files",title:"Nothing here yet",children:"Drop a file into any conversation and it shows up here too."}):n.jsxs(n.Fragment,{children:[n.jsx(KA,{label:"Files",onSubmit:()=>f({q:u},!0),main:n.jsx("input",{type:"search",value:u,placeholder:"Search by name or label","aria-label":"Search files by name or label",onChange:T=>h(T.target.value)}),filters:n.jsxs(Hs,{dense:!0,children:[n.jsx(oe,{label:"Origin",children:n.jsx("select",{value:l,"aria-label":"Origin",onChange:T=>f({origin:T.target.value}),children:z0.map(T=>n.jsx("option",{value:T.id,children:T.label},T.id))})}),n.jsx(oe,{label:"Kind",children:n.jsx("select",{value:o,"aria-label":"Kind",onChange:T=>f({family:T.target.value}),children:HH.map(T=>n.jsx("option",{value:T,children:T===""?"Any kind":ia[T]},T))})})]}),filtersOpen:y,onToggleFilters:()=>k(T=>!T),active:E,chips:E>0?n.jsxs(n.Fragment,{children:[l?n.jsx(ih,{label:"Origin",onRemove:()=>f({origin:""}),children:R}):null,o?n.jsx(ih,{label:"Kind",onRemove:()=>f({family:""}),children:ia[o]}):null]}):void 0}),n.jsx(re,{message:b}),n.jsx(WA,{className:"files-split",label:"Files",list:I,detail:a?n.jsx(GH,{id:a,timezone:t,agents:r,navigate:s,onBack:()=>s(Du(null,{q:c,origin:l,family:o}))},a):void 0,empty:"Choose a file to see it here."})]})]})}function VH(e,t){var i,a;const s=(i=e.context)!=null&&i.groupName?`in ${e.context.groupName}`:(a=e.context)!=null&&a.agentId&&e.context.agentId!==e.agentId?`with ${t(e.context.agentId)}`:"",r=e.contexts>1?`${e.contexts} conversations`:"";return[s,r].filter(Boolean).map(l=>` · ${l}`).join("")}function o$(e,t){return e.origin==="uploaded"?"You sent it":e.origin==="produced"?`Made by ${t(e.agentId)||"an agent"}`:e.agentId?`Saved by ${t(e.agentId)}`:"Origin unknown"}function GH({id:e,timezone:t,agents:s,navigate:r,onBack:i}){const[a,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(null);d.useEffect(()=>{let x=!1;return l(null),h(null),$.libraryEntry(e).then(w=>{x||l(w)}).catch(w=>{x||h(w instanceof ve&&w.status===404?"This file is no longer in the library.":w instanceof ve?w.message:String(w))}),()=>{x=!0}},[e]);const f=x=>{var w;return x?((w=s.find(y=>y.id===x))==null?void 0:w.name)??x:""};if(u)return n.jsxs("div",{className:"files-detail-body",children:[n.jsx(A,{size:"sm",onClick:i,className:"files-back",children:"Back to Files"}),n.jsx(V,{tone:"critical",children:u})]});if(!a)return n.jsx("div",{className:"files-detail-body",children:n.jsx(pe,{children:"Loading…"})});const{entry:m,contexts:p,contextsTotal:g,available:v}=a,b=m.filename??"Untitled file",j=()=>{c(!0),$.libraryEntry(e,p.length).then(x=>l(w=>w&&{...w,contexts:[...w.contexts,...x.contexts],contextsTotal:x.contextsTotal})).catch(()=>{}).finally(()=>c(!1))};return n.jsxs("div",{className:"files-detail-body",children:[n.jsx(A,{size:"sm",onClick:i,className:"files-back",children:"Back to Files"}),n.jsxs("header",{className:"files-detail-head",children:[n.jsx("span",{className:"files-detail-mark","data-family":m.family,"aria-hidden":"true",children:n.jsx(iw,{family:m.family})}),n.jsxs("div",{className:"files-detail-text",children:[n.jsx("h3",{className:"files-detail-name",children:b}),n.jsxs("p",{className:"files-detail-meta",children:[ia[m.family]," · ",qn(m.sizeBytes)," · ",nt(m.createdAt,t)]})]}),v?n.jsx(uT,{artifactId:m.id,filename:m.filename,mime:m.mime}):null]}),v?null:n.jsx(V,{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."}),n.jsx(cT,{artifactId:m.id,filename:m.filename,mime:m.mime,family:m.family,available:v}),n.jsx(Gt,{items:[{label:"Origin",value:o$(m,f)},...m.caption&&m.origin==="produced"?[{label:"Filed under",value:m.caption}]:[],...m.agentId&&m.origin==="produced"?[{label:"Made by",value:n.jsxs("span",{className:"files-agent",children:[n.jsx(cn,{agents:s,id:m.agentId,size:"sm"}),f(m.agentId)]})}]:[],{label:"Type",value:n.jsx("span",{className:"mono",children:m.mime})},{label:"Id",value:n.jsx("span",{className:"mono",children:m.id})}]}),n.jsxs("section",{className:"files-conversations",children:[n.jsx("h4",{className:"ui-section-title",children:"Conversations"}),p.length===0?n.jsx("p",{className:"muted",children:"No conversation is recorded for this file. It may date from before the library kept track."}):n.jsx("ul",{className:"files-ctx",role:"list",children:p.map(x=>{const w=x.groupId?Yi(x.groupId,x.conversationId):st(x.conversationAgentId,x.conversationId),y=x.groupId?x.groupName??"a group":f(x.conversationAgentId);return n.jsxs("li",{className:"files-ctx-row",children:[n.jsxs("span",{className:"files-ctx-text",children:[n.jsx("span",{children:x.groupId?`Group: ${y}`:y}),n.jsxs("span",{className:"muted",children:[" · ",x.kind==="produced"?`made by ${f(x.agentId)||"an agent"}`:x.kind==="reused"?"sent again":"sent by you"," · ",Fe(x.at)]})]}),n.jsx("a",{className:"ui-btn","data-size":"sm",href:w,onClick:k=>{k.preventDefault(),r(w)},children:"Open conversation"})]},`${x.conversationId}:${x.kind}`)})}),p.length<g?n.jsx(ae,{align:"end",children:n.jsx(A,{size:"sm",onClick:j,disabled:o,children:o?"Loading…":`Show ${g-p.length} more`})}):null]})]})}const qH={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 c$(e){return e&&qH[e]||"plug"}const u$="buddi.keepClose";let $l=null;const Ax=new Set;function Tx(){for(const e of Ax)e()}typeof window<"u"&&(window.addEventListener("beforeinstallprompt",e=>{e.preventDefault(),$l=e,Tx()}),window.addEventListener("appinstalled",()=>{$l=null,ww(),Tx()}));function Rf(){const[e,t]=d.useState($l);return d.useEffect(()=>{const s=()=>t($l);return Ax.add(s),s(),()=>{Ax.delete(s)}},[]),d$()?null:e}async function jw(e){try{await e.prompt();const t=await e.userChoice;$l===e&&($l=null);const s=(t==null?void 0:t.outcome)==="accepted";return s&&ww(),Tx(),s}catch{return!1}}function YH(){try{return window.localStorage.getItem(u$)!==null}catch{return!1}}function ww(){try{window.localStorage.setItem(u$,"dismissed")}catch{}}function d$(){var e;try{return((e=window.matchMedia)==null?void 0:e.call(window,"(display-mode: standalone)").matches)??!1}catch{return!1}}function JH(e=window.location.hostname){const t=e.replace(/^\[|\]$/g,"").toLowerCase();return t==="127.0.0.1"||t==="::1"||t==="localhost"}function h$(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 QH(e){return/Mac|iPhone|iPad/.test(e)}function XH(){const e=Rf(),[t,s]=d.useState(YH);if(t||!e)return null;const r=()=>{ww(),s(!0)};return n.jsxs("div",{className:"home-install",role:"region","aria-label":"Install buddi",children:[n.jsx("p",{className:"home-install-text",children:"Install buddi as an app, one click from your dock."}),n.jsxs(ae,{align:"end",children:[n.jsx(A,{size:"sm",variant:"ghost",onClick:r,children:"Not now"}),n.jsx(A,{size:"sm",variant:"accent",onClick:()=>{jw(e).then(i=>{i&&s(!0)})},children:"Install"})]})]})}function ZH(){const e=Rf(),[t,s]=d.useState(void 0),[r]=d.useState(d$);if(d.useEffect(()=>{if(r)return;let o=!0;return $.session().then(c=>{o&&s(c.platform)},()=>{}),()=>{o=!1}},[r]),r)return null;const i=typeof navigator>"u"?"":navigator.userAgent,a=JH(),l=e?null:h$(i);return n.jsx(ue,{title:"The dashboard as an app",panel:!0,foot:e?n.jsx(ae,{align:"end",children:n.jsx(A,{variant:"accent",onClick:()=>{jw(e)},children:"Install the app"})}):void 0,children:n.jsxs(le,{children:[n.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 ",QH(i)?"⌘D":"Ctrl+D",".",a?null:" This tailnet address installs as its own app, separate from the one on the machine buddi runs on."]}),a&&t==="darwin"?n.jsxs("p",{children:["On this Mac, ",n.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 eK=""+new URL("earth-2560-Ce3xs8Cb.webp",import.meta.url).href,tK=""+new URL("earth-phone-BqC7cDhk.webp",import.meta.url).href,nK="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=",$x={desk:eK,phone:tK,thumb:nK},np={author:"ActionVance",authorUrl:"https://unsplash.com/@actionvance",photoUrl:"https://unsplash.com/photos/outer-space-photography-of-earth-t7EL2iG3jMc"};function sK(e){return e?$x.phone:$x.desk}function f$(){const[e,t]=d.useState(()=>new Date);return d.useEffect(()=>{let s;const r=()=>{s=setTimeout(()=>{t(new Date),r()},6e4-Date.now()%6e4+50)};return r(),()=>clearTimeout(s)},[]),e}const rK=3,m$=8e3,iK={hiddenHere:new Set,restoredHere:new Set};function aK(e,t){return t.hiddenHere.has(e.id)?!0:e.hidden&&!t.restoredHere.has(e.id)}function lK(e,t=iK){return(e??[]).filter(s=>!aK(s,t)).slice(0,rK)}function p$(e){const[t,s]=d.useState(new Set),[r,i]=d.useState(new Set),[a,l]=d.useState(null),o=d.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 d.useEffect(()=>{if(!a)return;const m=window.setTimeout(()=>l(null),m$);return()=>window.clearTimeout(m)},[a]),{hiddenHere:t,restoredHere:r,justHidden:a,hide:(m,p)=>{s(g=>c(g,m.id)),i(g=>u(g,m.id)),l({glance:m,spot:p}),$.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(!a)return;const{glance:m}=a;l(null),s(p=>u(p,m.id)),i(p=>c(p,m.id)),$.setGlanceHidden(m.id,!1).then(()=>{var p;return(p=o.current)==null?void 0:p.call(o)},()=>{i(p=>u(p,m.id)),s(p=>c(p,m.id))})}}}function oK({hiding:e,spot:t}){const s=e.justHidden;return!s||s.spot!==t?null:n.jsxs("span",{className:"home-glance-undo",role:"status","aria-live":"polite","data-spot":t,children:[n.jsxs("span",{children:[s.glance.title," hidden"]}),n.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),n.jsx(A,{size:"sm",variant:"ghost",onClick:e.undo,children:"Undo"})]})}function cK(e){return e.link?tw(e.link.plugin,e.link.page,e.link.place):null}function uK({glances:e,navigate:t,onChanged:s,except:r,hiding:i}){var u,h;const a=p$(s),l=i??a,o=lK(e,l).filter(f=>!(r!=null&&r.has(f.id))),c=n.jsx(oK,{hiding:l,spot:"line"});return o.length===0&&((u=l.justHidden)==null?void 0:u.spot)!=="line"?null:n.jsxs("span",{className:"home-glances",children:[((h=l.justHidden)==null?void 0:h.spot)==="line"?n.jsxs("span",{className:"home-glance",children:[n.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),c]}):null,o.map(f=>{const m=cK(f),p=n.jsxs(n.Fragment,{children:[n.jsx(ce,{name:Jl(f.icon),size:14}),n.jsx("span",{children:f.text})]});return n.jsxs("span",{className:"home-glance",children:[n.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),m?n.jsx("a",{className:"home-glance-text",href:m,onClick:g=>{g.preventDefault(),t(m)},children:p}):n.jsx("span",{className:"home-glance-text",children:p}),n.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:n.jsx(ce,{name:"close",size:10})})]},f.id)})]})}function dK(e){const i=Math.min(...e),l=Math.max(...e)-i||1,o=Math.max(e.length-1,1);return e.map((c,u)=>[u/o*100,2+(1-(c-i)/l)*(24-2*2)])}function hK({points:e,className:t="wg-spark"}){const s=dK(e).map(([r,i])=>`${r.toFixed(1)},${i.toFixed(1)}`);return n.jsxs("svg",{className:t,viewBox:"0 0 100 24",preserveAspectRatio:"none","aria-hidden":"true","data-testid":"spark",children:[n.jsx("path",{d:`M0,24 L${s.join(" L")} L100,24 Z`,fill:"currentColor",opacity:"0.12",stroke:"none"}),n.jsx("polyline",{points:s.join(" "),fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",vectorEffect:"non-scaling-stroke"})]})}const Ua=Math.PI/180;function fK(e,t,s){const r=e.getTime()/864e5+24405875e-1-2451545,i=(357.529+.98560028*r)*Ua,l=(280.459+.98564736*r+1.915*Math.sin(i)+.02*Math.sin(2*i))*Ua,o=(23.439-36e-8*r)*Ua,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)*Ua-c,m=t*Ua,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)))/Ua}function mK(e,t,s){return fK(e,t,s)>-.833}const pK={small:2,medium:4},U0=new Map;function gK(e){let t=U0.get(e);return t||(t=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"}),U0.set(e,t)),t}function B0(e,t){const s=Object.fromEntries(gK(t).formatToParts(e).map(l=>[l.type,l.value])),r=Number(s.hour)%24,i=Number(s.minute),a=Date.UTC(Number(s.year),Number(s.month)-1,Number(s.day),r,i);return{date:`${s.year}-${s.month}-${s.day}`,h:r,m:i,s:Number(s.second),offset:Math.round((a-Math.floor(e.getTime()/6e4)*6e4)/6e4)}}function xK(e){if(e===0)return"Same time";const t=Math.floor(Math.abs(e)/60),s=Math.abs(e)%60;return`${e>0?"+":"−"}${t===0?`${s} min`:s===0?`${t} h`:`${t} h ${s}`}`}function vK(e){if(e===0)return"same time";const t=Math.floor(Math.abs(e)/60),s=Math.abs(e)%60;return`${[t?`${t} hour${t===1?"":"s"}`:"",s?`${s} minute${s===1?"":"s"}`:""].filter(Boolean).join(" ")} ${e>0?"ahead":"behind"}`}function jK(e,t,s,r,i){const a=B0(e,t.zone),l=B0(e,s),o=a.date===l.date?"Today":a.date>l.date?"Tomorrow":"Yesterday",c=a.offset-l.offset,u=zc(i?{timeFormat:i}:{},()=>zt(e,t.zone)),h=r?"your time":vK(c);return{...a,day:o,daytime:typeof t.latitude=="number"&&typeof t.longitude=="number"?mK(e,t.latitude,t.longitude):a.h>=6&&a.h<18,offsetText:r?"Here":xK(c),time:u,label:`${t.label}, ${u}${o==="Today"?"":` ${o.toLowerCase()}`}, ${h}`}}function wK(e,t){const s=t?e.s:0;return{hour:(e.h%12+e.m/60+s/3600)*30,minute:(e.m+s/60)*6,second:t?e.s*6:null}}function yK(e){const[t,s]=d.useState(()=>new Date);return d.useEffect(()=>{const r=e?1e3:6e4;let i;const a=()=>{i=setTimeout(()=>{s(new Date),a()},r-Date.now()%r+5)};return s(new Date),a(),()=>clearTimeout(i)},[e]),t}function W0({angle:e,length:t,width:s}){return n.jsxs("g",{className:"wg-clock-hand",transform:`rotate(${e} 50 50)`,children:[n.jsx("line",{x1:"50",y1:"50",x2:"50",y2:"42",strokeWidth:Math.min(s,1.8)}),n.jsx("line",{x1:"50",y1:"42",x2:"50",y2:50-t,strokeWidth:s})]})}const bK=Array.from({length:12},(e,t)=>t);function kK({time:e,seconds:t}){const s=wK(e,t);return n.jsxs("svg",{className:"wg-clock-face",viewBox:"0 0 100 100","aria-hidden":"true",focusable:"false",children:[n.jsx("circle",{className:"wg-clock-dial",cx:"50",cy:"50",r:"49.25"}),bK.map(r=>n.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)),n.jsx(W0,{angle:s.hour,length:24,width:4.6}),n.jsx(W0,{angle:s.minute,length:37,width:3.4}),s.second===null?null:n.jsx("g",{className:"wg-clock-second","data-testid":"second-hand",transform:`rotate(${s.second} 50 50)`,children:n.jsx("line",{x1:"50",y1:"59",x2:"50",y2:"9"})}),n.jsx("circle",{className:"wg-clock-pin",cx:"50",cy:"50",r:"2.8"}),s.second===null?null:n.jsx("circle",{className:"wg-clock-pin-second",cx:"50",cy:"50",r:"1.5"})]})}function NK({body:e,size:t}){const s=Ns("(prefers-reduced-motion: reduce)"),r=yK(!s),i=e.clocks.slice(0,pK[t]);return n.jsx("div",{className:"wg-clocks","data-count":i.length,children:i.map((a,l)=>{let o;try{o=jK(r,a,e.home,l===0&&a.zone===e.home,e.time)}catch{return null}return n.jsxs("div",{className:"wg-clock","data-night":o.daytime?void 0:"true",role:"img","aria-label":o.label,title:`${a.label} · ${o.time}`,children:[n.jsx(kK,{time:o,seconds:!s}),n.jsxs("span",{className:"wg-clock-words","aria-hidden":"true",children:[n.jsx("span",{className:"wg-clock-city",children:a.label}),n.jsx("span",{className:"wg-clock-day","data-today":o.day==="Today"?"true":void 0,children:o.day}),n.jsx("span",{className:"wg-clock-off",children:o.offsetText})]})]},`${a.label}-${a.zone}`)})})}const sp=3,SK={small:4,medium:6};function rp({icon:e,size:t}){return e?n.jsx("span",{className:"wg-icon",children:n.jsx(ce,{name:Jl(e),size:t})}):null}function yw({body:e,size:t}){switch(e.kind){case"stat":return n.jsxs(n.Fragment,{children:[n.jsxs("span",{className:"wg-stat-now",children:[n.jsx(rp,{icon:e.icon,size:24}),n.jsx("span",{className:"wg-value",children:e.value})]}),e.caption?n.jsx("span",{className:"wg-caption",children:e.caption}):null,n.jsx("span",{className:"wg-push"}),e.trend?n.jsxs("span",{className:"wg-trend",children:[n.jsx(hK,{points:e.trend.points,className:"wg-spark"}),e.trend.label?n.jsx("span",{children:e.trend.label}):null]}):null,e.foot?n.jsx("span",{className:"wg-foot",children:e.foot}):null]});case"list":{const s=e.rows.slice(0,Math.min(e.max??sp,t==="medium"?5:sp));return n.jsxs(n.Fragment,{children:[n.jsx("ul",{className:"wg-list","data-dense":s.length>sp?"true":void 0,"data-wrap":e.wrap?"true":void 0,children:s.map((r,i)=>n.jsxs("li",{className:"wg-row","data-marked":r.image?"true":void 0,children:[r.image?n.jsx(eu,{className:"wg-mark",src:WT(r.image.src)?r.image.src:null,label:r.image.label??r.title}):null,n.jsxs("span",{className:"wg-row-text",children:[n.jsx("span",{className:"wg-row-title",children:r.title}),r.sub&&t==="medium"?n.jsx("span",{className:"wg-row-sub",children:r.sub}):null]}),r.side?n.jsx("span",{className:"wg-row-side","data-tone":r.tone,children:r.side}):null]},`${r.title}-${i}`))}),n.jsx("span",{className:"wg-push"}),e.more?n.jsx("span",{className:"wg-foot",children:e.more}):null]})}case"strip":return n.jsxs(n.Fragment,{children:[n.jsxs("span",{className:"wg-strip-head",children:[n.jsx(rp,{icon:e.icon,size:20}),e.value?n.jsx("span",{className:"wg-strip-value",children:e.value}):null,e.caption?n.jsx("span",{className:"wg-caption",children:e.caption}):null]}),n.jsx("span",{className:"wg-push"}),n.jsx("span",{className:"wg-strip",children:e.items.slice(0,SK[t]).map((s,r)=>n.jsxs("span",{className:"wg-tile",children:[n.jsx("span",{className:"wg-tile-label",children:s.label}),n.jsx(rp,{icon:s.icon,size:18}),n.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 n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"wg-value",children:e.value}),e.caption?n.jsx("span",{className:"wg-caption",children:e.caption}):null,n.jsx("span",{className:"wg-push"}),n.jsx("span",{className:"ui-meter",role:"meter","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":s,"aria-label":e.caption??e.value,children:n.jsx("span",{className:"ui-meter-fill","data-tone":e.tone,style:{inlineSize:`${s}%`}})}),e.foot?n.jsx("span",{className:"wg-foot",children:e.foot}):null]})}case"clocks":return n.jsx(NK,{body:e,size:t});case"text":return n.jsxs("span",{className:"wg-text",children:[e.icon?n.jsx("span",{className:"wg-text-icon",children:n.jsx(ce,{name:Jl(e.icon),size:18})}):null,n.jsxs("span",{className:"wg-text-words",children:[n.jsx("span",{className:"wg-text-main",children:e.text}),e.sub?n.jsx("span",{className:"wg-row-sub",children:e.sub}):null]})]})}}function Rx({label:e,options:t,multiple:s,value:r,onChange:i}){const a=Array.isArray(r)?r:[r],l=c=>a.includes(c),o=c=>{if(!s)return i(c);i(l(c)?a.filter(u=>u!==c):[...a,c])};return n.jsx("div",{className:"wg-options",role:s?"group":"radiogroup","aria-label":e,children:t.map(c=>n.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:[n.jsx("span",{className:"wg-option-mark","data-multiple":s?"true":void 0,"aria-hidden":"true",children:s&&l(c.value)?n.jsx(ce,{name:"check",size:12}):null}),n.jsxs("span",{className:"wg-option-text",children:[n.jsx("span",{className:"wg-option-name",children:c.label}),c.sub?n.jsx("span",{className:"wg-option-sub",children:c.sub}):null]})]},c.value))})}function H0(e){return"place"in e?e.place:`town:${e.latitude.toFixed(3)},${e.longitude.toFixed(3)}`}function CK(e){var t;return{label:((t=e.name.split(",")[0])==null?void 0:t.trim())||e.name,name:e.name,latitude:e.latitude,longitude:e.longitude,timezone:e.timezone??null}}function EK({field:e,value:t,places:s,onChange:r}){const i=Array.isArray(t)?t:t?[t]:[],[a,l]=d.useState(""),[o,c]=d.useState([]),[u,h]=d.useState(!1),[f,m]=d.useState(null),p=new Map;for(const y of s)p.set(y.id,{value:{place:y.id},label:y.label,sub:y.name});for(const y of[...i,...o])"place"in y||p.set(H0(y),{value:y,label:y.label,sub:y.name});const g=[...p.entries()].map(([y,k])=>({value:y,label:k.label,sub:k.sub})),v=i.map(H0),b=s.find(y=>y.id==="home"||y.label.toLowerCase()==="home")??s[0],j=e.multiple?v:v[0]??(b==null?void 0:b.id)??"",x=y=>{const k=(Array.isArray(y)?y:[y]).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)},w=()=>{const y=a.trim();y.length<2||(h(!0),m(null),$.findPlace(y).then(({found:k})=>{const N=k.slice(0,3).map(CK);c(N),N.length===0?m(`Nothing found for “${y}”.`):e.multiple?r([...i,N[0]].slice(-3)):r(N[0])}).catch(()=>m("The place finder didn’t answer. Try again in a moment.")).finally(()=>h(!1)))};return n.jsxs("div",{className:"wg-field-stack",children:[g.length>0?n.jsx(Rx,{label:e.label,options:g,multiple:e.multiple,value:j,onChange:x}):null,n.jsxs("div",{className:"wg-find",children:[n.jsx("input",{value:a,placeholder:"Find a town: Tokyo","aria-label":`Find a town for ${e.label}`,onChange:y=>l(y.target.value),onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),w())}}),n.jsx(A,{size:"sm",disabled:u||a.trim().length<2,onClick:w,children:u?"Finding…":"Find"})]}),f?n.jsx("span",{className:"ui-field-hint",children:f}):null]})}function AK({field:e,value:t,sheet:s,onChange:r}){var a;let i;switch(e.kind){case"select":{const l=e.options??[],o=typeof t=="string"?t:e.default??((a=l[0])==null?void 0:a.value)??"",c=l.length>0&&l.length<=3&&l.every(u=>u.label.length<=14);i=l.length===0?n.jsx("span",{className:"ui-field-hint",children:"Nothing to choose from yet."}):c?n.jsx(qt,{label:e.label,options:l,value:o,onChange:r}):n.jsx(Rx,{label:e.label,options:l,value:o,onChange:r});break}case"multiselect":{const l=e.options??[];i=l.length===0?n.jsx("span",{className:"ui-field-hint",children:"Nothing to choose from yet."}):n.jsx(Rx,{label:e.label,options:l,multiple:!0,value:Array.isArray(t)?t:e.default??[],onChange:r});break}case"toggle":return n.jsxs("div",{className:"wg-field",children:[n.jsxs("label",{className:"wg-toggle",children:[n.jsx("input",{type:"checkbox",checked:typeof t=="boolean"?t:e.default??!1,onChange:l=>r(l.target.checked)}),n.jsx("span",{children:e.label})]}),e.hint?n.jsx("span",{className:"ui-field-hint",children:e.hint}):null]});case"text":i=n.jsx("input",{"aria-label":e.label,value:typeof t=="string"?t:e.default??"",maxLength:e.max??60,placeholder:e.placeholder,onChange:l=>r(l.target.value)});break;case"place":i=n.jsx(EK,{field:e,value:t,places:s.places,onChange:r});break;case"timeFormat":i=n.jsx(qt,{label:e.label,options:[{value:"profile",label:uE()},{value:"12h",label:"12-hour"},{value:"24h",label:"24-hour"}],value:t==="12h"||t==="24h"?t:"profile",onChange:r});break}return n.jsxs("div",{className:"wg-field",role:"group","aria-label":e.label,children:[n.jsx("span",{className:"wg-field-label",children:e.label}),i,e.hint?n.jsx("span",{className:"ui-field-hint",children:e.hint}):null]})}function TK({info:e,placement:t,surface:s,view:r,label:i}){var u;const a=s==="lock",l=((u=r==null?void 0:r.body)==null?void 0:u.kind)==="text",o=a&&(l||t.size==="small")?"small":t.size,c=r?r.body?e.sensitive?n.jsxs("span",{className:"wg-state",children:[n.jsx("span",{className:"wg-mask","aria-hidden":"true",children:"••••"}),n.jsx("span",{className:"wg-state-sub",children:"Hidden on this screen."})]}):n.jsx(yw,{body:r.body,size:o}):n.jsx("span",{className:"wg-state",children:n.jsx("span",{className:"wg-state-sub",children:r.state==="error"?`Couldn't load this${r.error?`: ${r.error}`:""}.`:"Nothing to show right now."})}):n.jsxs("span",{className:"wg-skel-body","aria-hidden":"true",children:[n.jsx("span",{className:"wg-skel","data-w":"half"}),n.jsx("span",{className:"wg-skel","data-w":"third"}),n.jsx("span",{className:"wg-push"}),n.jsx("span",{className:"wg-skel"})]});return n.jsx("div",{className:"wg-preview","data-surface":s,"aria-label":`Preview of ${i}`,role:"img",children:n.jsxs("div",{className:"wg-frame","data-size":o,"data-variant":a?"compact":void 0,"data-kind":r!=null&&r.body&&!e.sensitive?r.body.kind:void 0,"aria-hidden":"true",children:[a?null:n.jsx("div",{className:"wg-head",children:n.jsx("span",{className:"wg-title",children:i})}),n.jsx("div",{className:"wg-body",children:c}),a?n.jsx("span",{className:"wg-compact-title",children:i}):null]})})}function g$({info:e,placement:t,surface:s,onSave:r,onRemove:i,onClose:a}){const l=de(()=>$.widgetSettings(e.id),[e.id]),[o,c]=d.useState(t.settings??{}),[u,h]=d.useState(null),[f,m]=d.useState(t.label??e.title),[p,g]=d.useState(!1),[v,b]=d.useState(null),j=d.useRef(0),x=d.useMemo(()=>JSON.stringify(o),[o]);d.useEffect(()=>{const k=++j.current,N=window.setTimeout(()=>{$.previewWidget({widget:e.id,size:t.size,settings:o}).then(S=>{k===j.current&&(h(S.view),m(S.label))}).catch(()=>{k===j.current&&h({state:"error",error:"the preview could not be made"})})},u?250:0);return()=>window.clearTimeout(N)},[x,e.id,t.size]);const w=()=>{g(!0),b(null),r(o).then(k=>{g(!1),k||b("Couldn’t keep these settings. Try again.")})},y=s==="lock"?"the lock screen":"Home";return n.jsx(Ye,{title:f,onClose:a,foot:n.jsxs(ae,{children:[n.jsxs(A,{variant:"danger-ghost",onClick:i,children:["Remove from ",s==="lock"?"lock screen":"Home"]}),n.jsx(ht,{}),n.jsx(A,{variant:"ghost",onClick:a,children:"Cancel"}),n.jsx(A,{variant:"accent",onClick:w,disabled:p||!l.data,children:p?"Saving…":"Save"})]}),children:n.jsxs("div",{className:"wg-sheet",children:[n.jsx(TK,{info:e,placement:t,surface:s,view:u,label:f}),n.jsxs("p",{className:"wg-sheet-note",children:[e.builtIn?"Built in":`From the ${e.plugin} plugin`," · on ",y,". These settings are this one’s own",s==="lock"?"; Home keeps its own":"","."]}),n.jsx(re,{message:v??(l.error?"Couldn’t read this widget’s settings.":null)}),l.data?l.data.fields.map(k=>n.jsx(AK,{field:k,value:o[k.key],sheet:l.data,onChange:N=>c({...o,[k.key]:N})},k.key)):l.error?null:n.jsx("p",{className:"wg-sheet-note","aria-busy":"true",children:"Reading its choices…"})]})})}const $K=6e4,x$="buddi.clock",v$="buddi.home.widgets";function RK(){try{const e=Number(window.localStorage.getItem(v$));return Number.isInteger(e)&&e>0?Math.min(e,6):0}catch{return 0}}function IK(e){try{window.localStorage.setItem(v$,String(e))}catch{}}function j$(){const e=new Uint8Array(4);return crypto.getRandomValues(e),`w-${Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}`}function w$(e,t){const s=d.useRef(t);s.current=t,d.useEffect(()=>{if(!e)return;let r;const i=()=>{r=setTimeout(()=>{s.current(),i()},6e4-Date.now()%6e4+1e3)};return i(),()=>clearTimeout(r)},[e])}function PK(){const e=de(()=>$.widgets("home"),[],$K),[t,s]=d.useState(void 0);return d.useEffect(()=>{e.data&&s(e.data)},[e.data]),d.useEffect(()=>{t&&IK(t.home.length)},[t]),w$((t==null?void 0:t.home.some(r=>{var i,a;return r.widget===x$&&((a=(i=t.views[r.key])==null?void 0:i.body)==null?void 0:a.kind)!=="clocks"}))??!1,e.reload),{answer:t,error:e.error,apply:s,reload:e.reload}}function MK(e){return new Set(((e==null?void 0:e.home)??[]).map(t=>t.widget))}function DK(e){const[t,s]=d.useState(!1);return d.useEffect(()=>{if(!e||!t)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,t]),[t,s]}const y$=(e,t)=>e.label??(t==null?void 0:t.title)??e.widget;function OK({info:e,placement:t,view:s,index:r,count:i,editing:a,navigate:l,act:o,onRetry:c,retrying:u,drag:h}){var S;const[f,m]=DK(e.sensitive===!0),p=(s==null?void 0:s.state)??"error",g=e.sensitive===!0&&!f,v=e.link?tw(e.link.plugin,e.link.page,e.link.place):null,b=v!==null&&!a&&p!=="error"&&!g,j=t.size==="small"?"medium":"small",x=y$(t,e),w=t.key,y=(((S=e.settings)==null?void 0:S.length)??0)>0;let k;!s&&a?k=n.jsx("span",{className:"wg-state",children:n.jsx("span",{className:"wg-state-sub",children:"Fills in when you press Done."})}):p==="error"||!s?k=n.jsxs("span",{className:"wg-state",children:[n.jsx("span",{className:"wg-state-title",children:"Couldn't load this."}),s!=null&&s.error?n.jsxs("span",{className:"wg-state-sub",children:[LK(s.error),"."]}):null,a?null:n.jsx(A,{size:"sm",onClick:c,disabled:u,children:u?"Trying…":"Try again"})]}):p==="empty"||!s.body?k=n.jsx("span",{className:"wg-state",children:n.jsx("span",{className:"wg-state-sub",children:"Nothing to show right now."})}):g?k=n.jsxs("span",{className:"wg-state",children:[n.jsx("span",{className:"wg-mask","aria-hidden":"true",children:"••••"}),n.jsx("span",{className:"wg-state-sub",children:"Hidden on this screen."}),a?null:n.jsx(A,{size:"sm",onClick:()=>m(!0),children:"Show"})]}):k=n.jsx(yw,{body:s.body,size:t.size});const N=C=>{C.dataTransfer.effectAllowed="move",C.dataTransfer.setData("text/plain",w),h.start(w)};return n.jsxs("div",{className:"wg-frame",role:"group","aria-label":x,"data-id":e.id,"data-key":w,"data-size":t.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":h.dragging===w?"true":void 0,"data-over":h.over===w&&h.dragging!==w?"true":void 0,draggable:a?!0:void 0,onDragStart:a?N:void 0,onDragOver:a?C=>{h.dragging&&(C.preventDefault(),h.enter(w))}:void 0,onDrop:a?C=>{C.preventDefault(),h.drop(w)}:void 0,onDragEnd:a?()=>h.end():void 0,children:[n.jsxs("div",{className:"wg-head",children:[a?n.jsx("button",{type:"button",className:"ui-icon-btn wg-grip","data-size":"sm","data-grip":w,"aria-label":`Move ${x}, position ${r+1} of ${i}: 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:n.jsx(ce,{name:"grip",size:14})}):null,n.jsx("span",{className:"wg-title",children:x}),p==="stale"?n.jsx("span",{className:"wg-stale",title:s!=null&&s.error?`Couldn't refresh: ${s.error}.`:void 0,children:s!=null&&s.updatedAt?`${pj(s.updatedAt)} old`:"Not current"}):null,a&&y?n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Settings for ${x}`,title:"Settings",onClick:()=>o("settings"),children:n.jsx(ce,{name:"settings",size:14})}):null,a?n.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:n.jsx(ce,{name:"close",size:12})}):n.jsx("span",{className:"wg-more",children:n.jsx(Ys,{label:`More for ${x}`,note:s!=null&&s.updatedAt?`${e.builtIn?"Built in":e.plugin} · ${Fe(s.updatedAt)}`:e.builtIn?"Built in":e.plugin,items:[y?{label:"Settings…",onSelect:()=>o("settings")}:null,r>0?{label:"Move earlier",onSelect:()=>o("earlier")}:null,r<i-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?n.jsx("a",{className:"wg-body",href:v,onClick:C=>{C.preventDefault(),l(v)},children:k}):n.jsx("div",{className:"wg-body",children:k}),a?n.jsxs("div",{className:"wg-edit-bar",children:[e.sizes.length>1?n.jsx("span",{className:"ui-segment",role:"radiogroup","aria-label":`Size of ${x}`,children:["small","medium"].filter(C=>e.sizes.includes(C)).map(C=>n.jsx("button",{type:"button",className:"ui-tab",role:"radio","aria-checked":t.size===C,onClick:()=>o("size",C),children:C==="small"?"Small":"Medium"},C))}):n.jsx("span",{className:"wg-edit-note",children:e.sizes[0]==="small"?"Small only":"Medium only"}),n.jsxs("span",{className:"wg-edit-move",children:[n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","data-move":`${w}:earlier`,"aria-label":`Move ${x} earlier`,title:"Move earlier",disabled:r===0,onClick:()=>o("earlier"),children:n.jsx(ce,{name:"chevron-left"})}),n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","data-move":`${w}:later`,"aria-label":`Move ${x} later`,title:"Move later",disabled:r===i-1,onClick:()=>o("later"),children:n.jsx(ce,{name:"chevron-right"})})]})]}):null]})}function LK(e){const t=e.replace(/\.$/,"");return t.charAt(0).toUpperCase()+t.slice(1)}function FK({widgets:e,navigate:t}){const{answer:s,apply:r}=e,[i,a]=d.useState(!1),[l,o]=d.useState([]),[c,u]=d.useState(null),[h,f]=d.useState(""),[m,p]=d.useState(null),[g,v]=d.useState(!1),[b,j]=d.useState(null),[x,w]=d.useState(null),[y,k]=d.useState(null),[N,S]=d.useState(null),[C,E]=d.useState(new Set),[R]=d.useState(RK),I=d.useRef(null);if(d.useEffect(()=>{if(!c)return;const U=window.setTimeout(()=>u(null),m$);return()=>window.clearTimeout(U)},[c]),d.useEffect(()=>{var ie;const U=I.current;U&&(I.current=null,(ie=document.querySelector(`[data-grip="${CSS.escape(U)}"], [data-move="${CSS.escape(U)}"]`))==null||ie.focus())}),!s)return R===0?null:n.jsxs("section",{className:"ui-section wg-section","aria-label":"Widgets","aria-busy":"true",children:[n.jsx("div",{className:"ui-section-head",children:n.jsx("h3",{className:"ui-section-title",children:"Widgets"})}),n.jsx("div",{className:"wg-grid",children:Array.from({length:R},(U,ie)=>n.jsxs("div",{className:"wg-frame","data-state":"loading","aria-hidden":"true",children:[n.jsx("div",{className:"wg-head"}),n.jsxs("span",{className:"wg-skel-body",children:[n.jsx("span",{className:"wg-skel","data-w":"half"}),n.jsx("span",{className:"wg-skel","data-w":"third"}),n.jsx("span",{className:"wg-push"}),n.jsx("span",{className:"wg-skel"})]})]},ie))})]});if(s.available.every(U=>U.builtIn)&&s.home.length===0)return null;const L=new Map(s.available.map(U=>[U.id,U])),F=i?l:s.home,T=U=>y$(U,L.get(U.widget)),M=(U,ie)=>(p(null),r({...ie,home:U,arranged:{...ie.arranged,home:!0}}),$.saveWidgets("home",U).then(J=>(r(J),!0),J=>(r(ie),p(`Couldn't save your widgets: ${J instanceof Error?J.message:String(J)}`),!1))),P=(U,ie,J)=>{if(J<0||J>=U.length||ie===J)return null;const ye=U.slice(),[ge]=ye.splice(ie,1);return ye.splice(J,0,ge),f(`${T(ge)}, position ${J+1} of ${ye.length}.`),ye},D=()=>{o(s.home),E(new Set),u(null),p(null),a(!0)},O=U=>(ie,J)=>{const ye=F[U];if(ie==="edit"){D();return}if(ie==="settings"){S(ye.key);return}if(i){if(ie==="earlier"||ie==="later"){const ge=P(l,U,ie==="earlier"?U-1:U+1);if(ge){const $e=document.activeElement;I.current=($e==null?void 0:$e.dataset.grip)??($e==null?void 0:$e.dataset.move)??null,o(ge)}}ie==="size"&&J&&(o(l.map((ge,$e)=>$e===U?{...ge,size:J}:ge)),E(new Set([...C,ye.key]))),ie==="hide"&&(o(l.filter((ge,$e)=>$e!==U)),f(`${T(ye)} taken off.`));return}if(ie==="earlier"||ie==="later"){const ge=P(s.home,U,ie==="earlier"?U-1:U+1);ge&&M(ge,s)}ie==="size"&&J&&M(s.home.map((ge,$e)=>$e===U?{...ge,size:J}:ge),s),ie==="hide"&&M(s.home.filter((ge,$e)=>$e!==U),s).then(ge=>{ge&&u({item:ye,at:U})})},H=()=>{if(!c)return;const U=s.home.filter(ie=>ie.key!==c.item.key);U.splice(Math.min(c.at,U.length),0,c.item),u(null),M(U,s)},B=()=>{v(!0),M(l,s).then(U=>{v(!1),U&&(a(!1),f("Widgets saved."))})},Y=U=>{j(U),$.refreshWidget(U).then(r,()=>{}).finally(()=>j(null))},W=U=>{var ye;const ie={key:j$(),widget:U.id,size:U.sizes[0],settings:{}},J=l.some(ge=>ge.widget===U.id);o([...l,ie]),f(`${U.title} added.`),J&&(((ye=U.settings)==null?void 0:ye.length)??0)>0&&S(ie.key)},q=(U,ie)=>i?(o(l.map(J=>{if(J.key!==U)return J;const{label:ye,...ge}=J;return{...ge,settings:ie}})),E(new Set([...C,U])),S(null),Promise.resolve(!0)):M(s.home.map(J=>J.key===U?{...J,settings:ie}:J),s).then(J=>(J&&(S(null),f("Settings saved.")),J)),_=U=>{S(null);const ie=F.findIndex(J=>J.key===U);ie>=0&&O(ie)("hide")},X={dragging:x,over:y,start:U=>w(U),enter:U=>{y!==U&&k(U)},end:()=>{w(null),k(null)},drop:U=>{const ie=l.findIndex(ge=>ge.key===x),J=l.findIndex(ge=>ge.key===U),ye=ie>=0&&J>=0?P(l,ie,J):null;ye&&o(ye),w(null),k(null)}},Q=c?n.jsxs("div",{className:"wg-undo","data-size":c.item.size,role:"status","aria-live":"polite",children:[n.jsxs("span",{children:[T(c.item)," hidden"]}),n.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),n.jsx(A,{size:"sm",variant:"ghost",onClick:H,children:"Undo"})]},"undo"):null,ee=[];F.forEach((U,ie)=>{const J=L.get(U.widget);if(!J)return;c&&!i&&c.at===ie&&ee.push(Q);const ye=i&&(C.has(U.key)||!s.home.some(ge=>ge.key===U.key));ee.push(n.jsx(OK,{info:J,placement:U,view:ye?void 0:s.views[U.key],index:ie,count:F.length,editing:i,navigate:t,act:O(ie),onRetry:()=>Y(U.key),retrying:b===U.key,drag:X},U.key))}),c&&!i&&c.at>=F.length&&ee.push(Q);const fe=s.available.filter(U=>!U.builtIn),Le=fe.length-2,Ie=N?F.find(U=>U.key===N):void 0,_e=Ie?L.get(Ie.widget):void 0;return n.jsxs("section",{className:"ui-section wg-section","aria-label":"Widgets",children:[n.jsxs("div",{className:"ui-section-head",children:[n.jsx("h3",{className:"ui-section-title",children:"Widgets"}),i?n.jsxs("div",{className:"ui-toolbar","data-align":"end",children:[n.jsx(A,{size:"sm",variant:"ghost",onClick:()=>{a(!1),o([])},disabled:g,children:"Cancel"}),n.jsx(A,{size:"sm",variant:"accent",onClick:B,disabled:g,children:g?"Saving…":"Done"})]}):F.length>0?n.jsx("div",{className:"ui-toolbar","data-align":"end",children:n.jsx(A,{size:"sm",variant:"ghost",onClick:D,children:"Edit"})}):null]}),n.jsx("p",{className:"sr-only","aria-live":"polite",children:h}),m?n.jsx(V,{tone:"critical",role:"alert",children:m}):null,F.length===0&&!i&&!c?n.jsxs("div",{className:"wg-empty",children:[n.jsxs("div",{className:"wg-empty-text",children:[n.jsx("p",{className:"wg-empty-title",children:"Add widgets to Home"}),n.jsxs("p",{className:"wg-empty-sub",children:["Small live panels from your plugins:"," ",(fe.length>0?fe:s.available).slice(0,2).map(U=>U.title).join(", "),Le>0?` and ${Le} more`:"","."]})]}),n.jsx(A,{size:"sm",variant:"accent",onClick:D,children:"Add widgets"})]}):ee.length>0?n.jsx("div",{className:"wg-grid","data-editing":i?"true":void 0,children:ee}):null,i?n.jsxs("div",{className:"wg-gallery",role:"region","aria-label":"Add widgets",children:[n.jsxs("div",{className:"wg-gallery-head",children:[n.jsx("p",{className:"wg-gallery-title",children:"Add widgets"}),n.jsx("a",{className:"wg-gallery-aside",href:Pe("lock"),onClick:U=>{U.preventDefault(),t(Pe("lock"))},children:"The lock screen has its own pick"})]}),n.jsx("ul",{className:"wg-gallery-list",children:s.available.map(U=>{var De;const ie=l.filter(Je=>Je.widget===U.id).length,J=(((De=U.settings)==null?void 0:De.length)??0)>0,ye=U.builtIn?"Built in":`${U.plugin} plugin`,ge=U.sizes.length>1?"small or medium":`${U.sizes[0]} only`,$e=ie>1?` · ${ie} on Home`:ie===1&&J?" · on Home":"";return n.jsxs("li",{className:"wg-add",children:[n.jsxs("span",{className:"wg-add-text",children:[n.jsx("span",{className:"wg-add-title",children:U.title}),n.jsxs("span",{className:"wg-add-sub",children:[ye," · ",ge,U.sensitive?" · hidden until you show it":"",$e]})]}),ie>0&&!J?n.jsx("span",{className:"wg-add-note",children:"On Home"}):n.jsxs(A,{size:"sm","aria-label":`${ie>0?"Add another":"Add"} ${U.title}`,onClick:()=>W(U),children:[n.jsx(ce,{name:"plus",size:12})," ",ie>0?"Add another":"Add"]})]},U.id)})})]}):null,Ie&&_e?n.jsx(g$,{info:_e,placement:Ie,surface:"home",onClose:()=>S(null),onSave:U=>q(Ie.key,U),onRemove:()=>_(Ie.key)}):null]})}function bw(e,t){return!e||e==="image"&&!t?"earth":e}const _K="(max-width: 720px)",zK=3e4,UK={1:"a minute",5:"5 minutes",15:"15 minutes",60:"an hour"};function ip(e,t){return{time:zt(e,t),day:yr(e,t,{weekday:!0})}}function kw(e,t){return e?zc({timeFormat:e.time,...e.date==="off"?{}:{dateFormat:e.date}},t):t()}function BK(e,t,s=new Date,r){return kw(r,()=>WK(e,t,s))}function WK(e,t,s){if(!e.lockedAt)return"Locked";const r=new Date(e.lockedAt),a=ip(r,t).day===ip(s,t).day?ip(r,t).time:mj(r,t);return e.reason==="idle"?`Locked after ${e.delayMinutes?UK[e.delayMinutes]??`${e.delayMinutes} minutes`:"a while"} away, at ${a}`:e.reason==="start"?`Locked since this session began, at ${a}`:`Locked by you at ${a}`}function HK(e){const t=()=>e?Math.max(0,Math.ceil((Date.parse(e)-Date.now())/1e3)):0,[s,r]=d.useState(t);return d.useEffect(()=>{if(r(t()),!e)return;const i=window.setInterval(()=>r(t()),500);return()=>window.clearInterval(i)},[e]),s}const KK=e=>`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`;function K0({size:e=16}){return n.jsx(ce,{name:"lock",size:e})}function b$({size:e=16}){return n.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:n.jsx("path",{d:"M3 8h9.6M8.6 4l4 4-4 4"})})}function VK(){return n.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:[n.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"}),n.jsx("path",{d:"M9.6 8l4 4M13.6 8l-4 4"})]})}function V0({text:e}){const[t,s]=d.useState(!1),r=()=>{var i;(i=navigator.clipboard)==null||i.writeText(e).then(()=>{s(!0),window.setTimeout(()=>s(!1),1600)}).catch(()=>{})};return n.jsxs("div",{className:"so-cmd",children:[n.jsx("code",{className:"so-cmd-text",children:e}),n.jsx(A,{size:"sm",onClick:r,children:t?"Copied":"Copy"})]})}function GK({onClose:e}){return n.jsx(Dt,{title:"Forgot your PIN?",onClose:e,foot:n.jsx(A,{variant:"accent",onClick:e,children:"Done"}),children:n.jsxs("div",{className:"lk-forgot",children:[n.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:"}),n.jsxs("div",{className:"lk-forgot-way",children:[n.jsx(V0,{text:"buddi dashboard --unlock"}),n.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."})]}),n.jsxs("div",{className:"lk-forgot-way",children:[n.jsx(V0,{text:"buddi dashboard --remove-pin"}),n.jsx("p",{className:"lk-forgot-hint",children:"Removes the PIN on every device. Set a new one in Settings → Lock screen."})]})]})})}function qK({approvals:e,needs:t,after:s,onPick:r}){const i=[];return e>0&&i.push({key:"approvals",n:e,text:e===1?"approval waiting":"approvals waiting"}),t>0&&i.push({key:"needs",n:t,text:e>0?t===1?"more needs you":"more need you":t===1?"thing needs you":"things need you"}),i.length===0?null:n.jsx("ul",{className:"lk-badges","aria-label":"Waiting for you",children:i.map(a=>n.jsx("li",{children:n.jsxs("button",{type:"button",className:"lk-chip","data-kind":a.key,"aria-pressed":s===a.key,disabled:!r,title:r?a.key==="needs"?"Open Needs you once unlocked":"Open your approvals once unlocked":void 0,onClick:()=>r==null?void 0:r(s===a.key?null:a.key),children:[n.jsx("span",{className:"ui-badge","aria-hidden":"true",children:a.n>99?"99+":a.n}),n.jsxs("span",{children:[n.jsxs("span",{className:"lk-sr",children:[a.n," "]}),a.text]})]})},a.key))})}function YK(e,t){const s=t?2:4;let r=0,i=0;for(const a of e){const l=Math.min(a==="medium"?2:1,s);i+l>s&&(i=0),i+=l,r=Math.max(r,i)}return r}function JK({widgets:e,phone:t}){if(e.length===0)return null;const s=e.map(i=>({w:i,size:t||i.view.body.kind==="text"?"small":i.size})),r=YK(s.map(({size:i})=>i),t);return n.jsx("div",{className:"lk-widgets",children:n.jsx("div",{className:"lk-grid","data-phone":t?"true":void 0,"data-cols":r,children:s.map(({w:i,size:a})=>n.jsxs("div",{className:"wg-frame","data-variant":"compact","data-size":a,"data-kind":i.view.body.kind,role:"group","aria-label":i.title,children:[n.jsx("div",{className:"wg-body",children:n.jsx(yw,{body:i.view.body,size:a})}),n.jsx("span",{className:"wg-compact-title",children:i.title})]},i.key??i.id))})})}function QK({text:e}){const t=/^(.*?)[\s\u202f]?([AaPp]\.?[Mm]\.?)$/.exec(e);return n.jsx("p",{className:"lk-time","aria-label":e,children:t?n.jsxs(n.Fragment,{children:[t[1],n.jsx("span",{className:"lk-ampm","aria-hidden":"true",children:t[2]})]}):e})}function G0(e,t){const s=Object.fromEntries(new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(e).map(i=>[i.type,i.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 XK(e,t,s){try{const r=G0(e,t)-G0(e,s);if(r===0)return"Same time";const i=u=>new Intl.DateTimeFormat("en-CA",{timeZone:u,year:"numeric",month:"2-digit",day:"2-digit"}).format(e),a=i(t)!==i(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"}${a}`}catch{return""}}function ZK(e,t,s){const r=s??{date:null,zone:null};return kw(s,()=>({time:zt(e,t),day:r.date==="off"?null:yr(e,t,{weekday:!0}),zone:r.zone?{label:r.zone.label,time:zt(e,r.zone.timezone),offset:XK(e,r.zone.timezone,t)}:null}))}function k$({data:e,now:t,phone:s,pad:r=!1,after:i,onPick:a}){const l=(e==null?void 0:e.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,o=ZK(t,l,e==null?void 0:e.clockView),c=bw(e==null?void 0:e.background,e==null?void 0:e.image),u=(e==null?void 0:e.focus)??null,h=u?kw(e==null?void 0:e.clockView,()=>s?n9($c(u,l,t)):`${na[u.mode]} ${$c(u,l,t)}`):"";return n.jsxs(n.Fragment,{children:[c==="earth"?n.jsxs("div",{className:"lk-ground","aria-hidden":"true",children:[n.jsx("img",{className:"lk-photo","data-earth":"true",src:sK(s),alt:"",decoding:"async"}),n.jsx("div",{className:"lk-scrim"})]}):c==="image"&&(e!=null&&e.image)?n.jsxs("div",{className:"lk-ground","aria-hidden":"true",children:[n.jsx("img",{className:"lk-photo",src:e.image,alt:""}),n.jsx("div",{className:"lk-scrim"})]}):n.jsx("div",{className:"ui-fieldbg lk-ground","aria-hidden":"true"}),n.jsxs("header",{className:"lk-top",children:[n.jsxs("span",{className:"lk-brand",children:[n.jsx(Nc,{size:"sm"}),n.jsx("span",{children:"buddi"})]}),n.jsx("span",{className:"lk-top-spacer"}),u?n.jsxs("span",{className:"lk-chip","data-kind":"focus",children:[n.jsx(ce,{name:"moon",size:13}),n.jsx("span",{children:h})]}):null]}),n.jsxs("div",{className:"lk-main",children:[o.day?n.jsx("p",{className:"lk-date",children:o.day}):null,n.jsx(QK,{text:o.time}),o.zone?n.jsxs("p",{className:"lk-zone",children:[n.jsx("span",{className:"lk-zone-name",children:o.zone.label}),n.jsx("span",{className:"lk-zone-time",children:o.zone.time}),o.zone.offset?n.jsx("span",{className:"lk-zone-off",children:o.zone.offset}):null]}):null,r||!e?null:n.jsx(qK,{approvals:e.approvals,needs:e.needs??0,after:i??null,...a?{onPick:a}:{}}),r||!e?null:n.jsx(JK,{widgets:e.widgets,phone:s})]})]})}function e9({value:e,disabled:t,onDigit:s,onBack:r,onSubmit:i}){return n.jsxs("div",{className:"lk-pad",role:"group","aria-label":"PIN pad",children:[["1","2","3","4","5","6","7","8","9"].map(a=>n.jsx("button",{type:"button",className:"lk-key",disabled:t,onClick:()=>s(a),children:a},a)),n.jsx("button",{type:"button",className:"lk-key","data-kind":"quiet","aria-label":"Delete",disabled:t||e.length===0,onClick:r,children:n.jsx(VK,{})}),n.jsx("button",{type:"button",className:"lk-key",disabled:t,onClick:()=>s("0"),children:"0"}),n.jsx("button",{type:"button",className:"lk-key","data-kind":"go","aria-label":"Unlock",disabled:t||e.length<4,onClick:i,children:n.jsx(b$,{size:18})})]})}function t9({initial:e,onUnlocked:t}){const s=Ns(_K),r=f$(),[i,a]=d.useState(null),l=i??e,[o,c]=d.useState(""),[u,h]=d.useState(null),[f,m]=d.useState((e==null?void 0:e.waitUntil)??null),[p,g]=d.useState(!1),[v,b]=d.useState(!1),[j,x]=d.useState(!1),[w,y]=d.useState(!1),[k,N]=d.useState(!1),[S,C]=d.useState(null),E=d.useRef(null),R=HK(f),I=R>0,L=d.useRef(t),F=d.useRef(S);F.current=S,L.current=q=>{F.current&&(window.location.hash=Cl),t(q)};const T=q=>{var _;C(q),s&&q?y(!0):(_=E.current)==null||_.focus()},M=d.useCallback(()=>{$.lockScreen().then(q=>{b(!1),a(q),m(q.waitUntil),q.locked||L.current(q)}).catch(q=>{q instanceof ve&&q.status===401?window.location.reload():th(q)&&b(!0)})},[]);d.useEffect(()=>{M();const q=window.setInterval(M,zK),_=()=>{document.visibilityState==="visible"&&M()};return document.addEventListener("visibilitychange",_),()=>{window.clearInterval(q),document.removeEventListener("visibilitychange",_)}},[M]),w$((i==null?void 0:i.widgets.some(q=>q.id===x$&&q.view.body.kind!=="clocks"))??!1,M),d.useEffect(()=>{var q;!s&&!j&&!I&&((q=E.current)==null||q.focus())},[s,j,I,p]),d.useEffect(()=>{!I&&f&&h(null)},[I,f]);const P=q=>{q==null||q.preventDefault(),!(p||I||o.length<4)&&(g(!0),$.unlock(o).then(_=>{var Q;if(c(""),_.locked){g(!1);return}if((Q=window.matchMedia)==null?void 0:Q.call(window,"(prefers-reduced-motion: reduce)").matches){L.current(_);return}N(!0),window.setTimeout(()=>L.current(_),240)}).catch(_=>{if(g(!1),c(""),!(_ instanceof ve))return h("Something went wrong. Try again.");const X=_.detail??{};if(_.status===403||_.status===429){X.waitUntil&&m(X.waitUntil);const Q=X.triesLeft??0;h(X.waitUntil?"That PIN isn’t right.":`That PIN isn’t right. ${Q} ${Q===1?"try":"tries"} left.`)}else th(_)?h("buddi isn’t answering. Try again in a moment."):h(_.message)}))},D=(i==null?void 0:i.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,O=bw(l==null?void 0:l.background,l==null?void 0:l.image),H=(i==null?void 0:i.owner)??null,B=v?{tone:"critical",text:"buddi isn’t answering. The lock stays until it does."}:I?{tone:"critical",text:`Too many tries. Try again in ${KK(R)}.`}: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?BK(l,D,r,i==null?void 0:i.clockView):"Locked"},Y=q=>q.replace(/\D/g,"").slice(0,8),W=n.jsxs("div",{className:"lk-who",children:[n.jsx("span",{className:"lk-face","aria-hidden":"true",children:(H??"You").slice(0,1).toUpperCase()}),H?n.jsx("span",{className:"lk-owner",children:H}):null]});return n.jsxs("div",{className:"lk","data-bg":O,"data-phone":s?"true":void 0,"data-view":w?"pad":"glance","data-opening":k?"true":void 0,role:"dialog","aria-modal":"true","aria-label":"buddi is locked","data-testid":"lock-screen",children:[n.jsx(k$,{data:i??(l?{...s9(l)}:null),now:r,phone:s,pad:w,after:S,onPick:T}),n.jsx("footer",{className:"lk-unlock",children:s&&!w?n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",className:"lk-chip lk-enter",onClick:()=>y(!0),children:[n.jsx(K0,{size:14}),n.jsx("span",{children:"Enter PIN"})]}),n.jsx("p",{className:"lk-note","data-tone":B.tone,role:"status","aria-live":"polite",children:B.text})]}):s?n.jsxs(n.Fragment,{children:[W,n.jsx("div",{className:"lk-dots","aria-hidden":"true","data-state":u?"wrong":void 0,children:o.length===0?n.jsx("span",{className:"lk-dots-empty",children:"Enter your PIN"}):Array.from(o).map((q,_)=>n.jsx("span",{className:"lk-dot"},_))}),n.jsx("span",{className:"lk-sr","aria-live":"polite",children:o.length===1?"1 digit entered":`${o.length} digits entered`}),n.jsx("p",{className:"lk-note","data-tone":B.tone,role:"status","aria-live":"polite",children:B.text}),n.jsx(e9,{value:o,disabled:I||p,onDigit:q=>{h(null),c(Y(o+q))},onBack:()=>c(o.slice(0,-1)),onSubmit:()=>P()}),n.jsxs("div",{className:"lk-pad-foot",children:[n.jsx("button",{type:"button",className:"lk-link",onClick:()=>x(!0),children:"Forgot PIN?"}),n.jsx("button",{type:"button",className:"lk-link",onClick:()=>{y(!1),c(""),h(null)},children:"Cancel"})]})]}):n.jsxs(n.Fragment,{children:[W,n.jsxs("form",{className:"lk-pin","data-state":u&&!I?"wrong":I?"wait":void 0,onSubmit:P,children:[n.jsx(K0,{size:15}),n.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:q=>{h(null),c(Y(q.target.value))}}),n.jsx("button",{type:"submit",className:"lk-go","aria-label":"Unlock",disabled:p||I||o.length<4,children:n.jsx(b$,{})})]}),n.jsx("p",{className:"lk-note",id:"lk-note","data-tone":B.tone,role:"status","aria-live":"polite",children:B.text}),n.jsx("button",{type:"button",className:"lk-link",onClick:()=>x(!0),children:"Forgot PIN?"})]})}),j?n.jsx(GK,{onClose:()=>x(!1)}):null]})}function n9(e){return e.slice(0,1).toUpperCase()+e.slice(1)}function s9(e){return{timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,background:e.background,image:e.image,focus:null,approvals:0,needs:0,widgets:[]}}const r9=3e4,i9=5e3,a9="buddi-lock",Ix="buddi-locked",l9=Pe("lock");function N$(){var t;const e=navigator;return/mac|iphone|ipad|ipod/i.test(((t=e.userAgentData)==null?void 0:t.platform)||navigator.platform||navigator.userAgent)}function o9(e=N$()){return e?"⌃⌘L":"Ctrl+Alt+L"}function c9(e,t=N$()){return!(e.code==="KeyL"||e.key.toLowerCase()==="l")||!e.ctrlKey||e.shiftKey?!1:t?e.metaKey&&!e.altKey:e.altKey&&!e.metaKey}const S$=d.createContext({pin:!1,state:null,lockNow:()=>{},update:()=>{},shortcut:"⌃⌘L"});function If(){return d.useContext(S$)}function qu(e){try{e?localStorage.setItem(Ix,"1"):localStorage.removeItem(Ix)}catch{}}function u9(){try{return localStorage.getItem(Ix)==="1"}catch{return!1}}function d9(){try{return typeof BroadcastChannel>"u"?null:new BroadcastChannel(a9)}catch{return null}}function h9({children:e}){const[t,s]=d.useState("checking"),[r,i]=d.useState(null),a=d.useRef(null),l=d.useRef(Date.now()),o=d.useRef(0),c=d.useRef(0),u=d.useRef(0),h=d.useCallback((v,b)=>{v&&i(v),s(b?"locked":"open"),qu(b),b||(l.current=Date.now())},[]),f=d.useCallback(()=>{$.lockState().then(v=>h(v,v.locked)).catch(v=>{if(v instanceof ve&&v.status===401)return s("open");h(null,u9())})},[h]);d.useEffect(()=>{f()},[f]);const m=d.useCallback((v="owner")=>{var b;if(!(r!=null&&r.pin)){window.location.hash=l9;return}s("locked"),qu(!0),v==="owner"&&((b=a.current)==null||b.postMessage({type:"locked"})),(v==="idle"?$.lockNow("idle",Date.now()-l.current):$.lockNow(v)).then(j=>{var x;v==="idle"&&j.locked&&((x=a.current)==null||x.postMessage({type:"locked"})),h(j,j.locked)}).catch(()=>f())},[r==null?void 0:r.pin,h,f]);d.useEffect(()=>{const v=()=>{s("locked"),qu(!0),f()};return window.addEventListener(Mg,v),()=>window.removeEventListener(Mg,v)},[f]),d.useEffect(()=>{const v=d9();if(a.current=v,!!v)return v.onmessage=b=>{const j=b.data;(j==null?void 0:j.type)==="locked"?(s("locked"),qu(!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(),a.current=null}},[f]),d.useEffect(()=>{const v=b=>{c9(b)&&(b.preventDefault(),t==="open"&&m("owner"))};return window.addEventListener("keydown",v,!0),()=>window.removeEventListener("keydown",v,!0)},[t,m]);const p=r!=null&&r.pin?r.delayMinutes:null;d.useEffect(()=>{if(t!=="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=a.current)==null||N.postMessage({type:"activity",at:k}))},b=()=>{const k=Date.now();l.current<=c.current||k-o.current<r9||(o.current=k,c.current=l.current,$.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 w=window.setInterval(j,i9),y=()=>{document.visibilityState==="visible"&&j()};return document.addEventListener("visibilitychange",y),()=>{for(const k of x)window.removeEventListener(k,v,{capture:!0});window.clearInterval(w),document.removeEventListener("visibilitychange",y)}},[t,r==null?void 0:r.pin,p,m]);const g=d.useMemo(()=>({pin:(r==null?void 0:r.pin)===!0,state:r,lockNow:()=>m("owner"),update:v=>h(v,v.locked),shortcut:o9()}),[r,m,h]);return t==="checking"?null:t==="locked"?n.jsx(t9,{initial:r,onUnlocked:v=>{var b;(b=a.current)==null||b.postMessage({type:"unlocked"}),h(v,!1)}}):n.jsx(S$.Provider,{value:g,children:e})}const C$="a connection needs you";function f9({attention:e,place:t,onNavigate:s,theme:r,onTheme:i,plugins:a=[],updateAvailable:l=!1,settingsDot:o,version:c,stale:u=!1,reload:h,timezone:f,status:m}){return n.jsxs("nav",{className:"rail","aria-label":"Places",children:[n.jsx("a",{className:"rail-mark",href:dn,onClick:p=>{p.preventDefault(),s(dn)},"aria-label":"buddi home",children:n.jsx(Nc,{})}),q4.filter(p=>p.route!==ln).map(p=>n.jsx(ap,{label:p.label,href:p.route,active:t===p.route,badge:p.route===dn?e:0,onClick:()=>s(p.route),children:q0[p.route]},p.route)),a.map(p=>{const g=xr(p.plugin,p.id);return n.jsx(ap,{label:p.title,href:g,active:t===g,badge:0,onClick:()=>s(g),children:n.jsx(ce,{name:c$(p.icon)})},g)}),n.jsx("div",{className:"rail-spacer"}),n.jsx(ap,{label:"Settings",href:ln,active:t===ln,badge:0,dot:l?"a newer buddi is ready":o,onClick:()=>s(ln),children:q0[ln]}),m,n.jsx(p9,{theme:r,onTheme:i,onNavigate:s,version:c,stale:u,reload:h,timezone:f})]})}const m9=[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}];function p9({theme:e,onTheme:t,onNavigate:s,version:r,stale:i,reload:a=()=>window.location.reload(),timezone:l}){var y,k,N;const o=de(()=>$.owner(),[]),c=If(),u=de(()=>$.focus(),[],6e4),h=((y=u.data)==null?void 0:y.focus)??null,f=(S,C)=>{$.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]=d.useState(uz),[v]=d.useState(v9),b=Rf(),j=m?`You: ${m}`:"You",x=h?`${na[h.mode]} ${$c(h,l)}`:null,w=[j,x,i?"reload to update":null].filter(Boolean).join(", ");return n.jsx("div",{className:"rail-owner",children:n.jsxs(Hc,{modal:!1,children:[n.jsx(Kc,{asChild:!0,children:n.jsxs("button",{type:"button",className:"rail-owner-btn","aria-label":w,children:[n.jsx("span",{className:"rail-owner-face","aria-hidden":"true",children:p}),i?n.jsx("span",{className:"ui-badge rail-dot","data-kind":"dot","data-testid":"owner-dot","aria-hidden":"true"}):null,h?n.jsx("span",{className:"rail-focus","data-testid":"owner-focus","aria-hidden":"true",children:n.jsx(ce,{name:"moon",size:10})}):null]})}),n.jsx(Gl,{children:n.jsxs(Vc,{className:"ui-menu rail-owner-menu",side:"right",align:"end",sideOffset:10,children:[n.jsxs("div",{className:"rail-owner-head",children:[n.jsx("span",{className:"rail-owner-face","data-size":"lg","aria-hidden":"true",children:p}),n.jsxs("span",{className:"rail-owner-who",children:[n.jsx("span",{className:"rail-owner-name",children:m??"You"}),n.jsx("span",{className:"rail-owner-sub",children:"On this Mac"})]})]}),n.jsx(Dr,{className:"ui-menu-sep"}),n.jsx(x9,{focus:h,timezone:l,onSwitch:f}),n.jsx(Dr,{className:"ui-menu-sep"}),n.jsx(ma,{className:"ui-menu-label",children:"Theme"}),n.jsx("div",{className:"rail-owner-theme",children:n.jsx(qt,{label:"Theme",options:m9,value:e,onChange:t})}),n.jsx(Dr,{className:"ui-menu-sep"}),c.pin?n.jsxs(js,{className:"ui-menu-item rail-owner-reload",onSelect:()=>c.lockNow(),children:[n.jsx("span",{children:"Lock now"}),n.jsx("kbd",{className:"rail-owner-kbd",children:c.shortcut})]}):n.jsx(js,{className:"ui-menu-item",onSelect:()=>s(Pe("lock")),children:"Set up a lock screen…"}),n.jsx(js,{className:"ui-menu-item",onSelect:()=>s(Pe("appearance")),children:"Change appearance"}),b?n.jsx(js,{className:"ui-menu-item",onSelect:()=>{jw(b)},children:"Install the app"}):null,g||i?n.jsxs(js,{className:"ui-menu-item rail-owner-reload","data-update":i?"true":void 0,onSelect:()=>a(),children:[n.jsx("span",{children:i?"Reload to update":"Reload"}),v?n.jsx("kbd",{className:"rail-owner-kbd",children:v}):null]}):null,r?n.jsxs(n.Fragment,{children:[n.jsx(Dr,{className:"ui-menu-sep"}),n.jsxs(js,{className:"ui-menu-item rail-owner-version","data-update":r.updateAvailable?"true":void 0,onSelect:()=>s(Pe("system")),children:[n.jsxs("span",{className:"mono",children:["buddi ",r.current]}),r.updateAvailable&&r.latest?n.jsxs("span",{className:"rail-owner-update",children:["A newer buddi is ready: ",r.latest]}):null]})]}):null]})})]})})}const na={normal:"Off","urgent-only":"Urgent only","do-not-disturb":"Do not disturb"},g9=[{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 $c(e,t,s=new Date){if(!e.until)return"until you turn it off";const r=new Date(e.until),i=t??Intl.DateTimeFormat().resolvedOptions().timeZone,a=c=>new Intl.DateTimeFormat("en-CA",{timeZone:i,dateStyle:"short"}).format(c),l=zt(r,i);return a(r)===a(s)?`until ${l}`:`until ${new Intl.DateTimeFormat("en-US",{timeZone:i,weekday:"short"}).format(r)} ${l}`}function x9({focus:e,timezone:t,onSwitch:s}){return n.jsxs(s4,{children:[n.jsxs(r4,{className:"ui-menu-item rail-owner-focus",children:[n.jsx("span",{children:"Focus"}),n.jsx("span",{className:"rail-owner-kbd",children:e?na[e.mode]:"Off"})]}),n.jsx(Gl,{children:n.jsxs(i4,{className:"ui-menu rail-owner-menu",sideOffset:6,children:[n.jsx("p",{className:"ui-menu-empty",role:"status",children:e?`${na[e.mode]} ${$c(e,t)}${e.by==="schedule"?", from a schedule":""}.`:"No focus is on."}),["do-not-disturb","urgent-only"].map(r=>n.jsxs(lA,{children:[n.jsx(Dr,{className:"ui-menu-sep"}),n.jsx(ma,{className:"ui-menu-label",children:na[r]}),g9.map(i=>n.jsx(js,{className:"ui-menu-item","aria-label":`${na[r]} ${i.label.toLowerCase()}`,onSelect:()=>s(r,i.value),children:i.label},i.value))]},r)),e?n.jsxs(n.Fragment,{children:[n.jsx(Dr,{className:"ui-menu-sep"}),n.jsx(js,{className:"ui-menu-item",onSelect:()=>s("normal"),children:"Turn off"})]}):null]})})]})}function v9(){const e=window.navigator.userAgent;return/iPhone|iPad|Android|Mobile/.test(e)?null:/Mac/.test(e)?"⌘R":"Ctrl+R"}function ap({label:e,href:t,active:s,badge:r,dot:i,onClick:a,children:l}){return n.jsxs("a",{className:"rail-link",href:t,"data-active":s?"true":void 0,"aria-current":s?"page":void 0,"aria-label":r>0?`${e}, ${r} waiting`:i?`${e}, ${i}`:e,onClick:o=>{o.preventDefault(),a()},children:[n.jsxs("span",{className:"rail-icon",children:[l,r>0?n.jsx("span",{className:"rail-badge","aria-hidden":"true",children:r>99?"99+":r}):null,r===0&&i?n.jsx("span",{className:"ui-badge rail-dot","data-kind":"dot","data-testid":"rail-dot","aria-hidden":"true"}):null]}),n.jsx("span",{className:"rail-label",children:e})]})}const q0={[qr]:n.jsx(ce,{name:"files"}),[dn]:n.jsx(ce,{name:"home"}),[yi]:n.jsx(ce,{name:"chat"}),[pt]:n.jsx(ce,{name:"agents"}),[yt]:n.jsx(ce,{name:"activity"}),[ln]:n.jsx(ce,{name:"settings"})},Rc=e=>`${e.plugin}:${e.id}`,j9=new Set;let Nw=j9,Y0=!1;const Px=new Set;function Mx(e){Nw=e;for(const t of Px)t()}function w9(e){return Px.add(e),()=>Px.delete(e)}const J0=()=>Nw;function y9(){Y0||(Y0=!0,Promise.resolve().then(()=>$.rail()).then(e=>Mx(new Set(Array.isArray(e==null?void 0:e.hidden)?e.hidden.filter(t=>typeof t=="string"):[]))).catch(()=>{}))}async function b9(e,t){const s=Nw,r=new Set(s);t?r.add(Rc(e)):r.delete(Rc(e)),Mx(r);try{await $.setRailHidden(e.plugin,e.id,t)}catch(i){throw Mx(s),i}}function E$(){return d.useEffect(y9,[]),d.useSyncExternalStore(w9,J0,J0)}function k9(e,t){return e.filter(s=>!t.has(Rc(s)))}function N9(e){return e instanceof HTMLElement?e.isContentEditable?!0:e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.tagName==="SELECT":!1}function S9(e,t=!0,s){d.useEffect(()=>{if(!t)return;const r=i=>{if(i.key!=="/"||i.defaultPrevented||i.ctrlKey||i.metaKey||i.altKey||N9(i.target))return;i.preventDefault();const a=document.getElementById(yx);if(a instanceof HTMLTextAreaElement){!a.disabled&&!a.hidden&&a.focus();return}s?s():e(dn)};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t,s])}const A$="buddi.theme";function C9(e=T$()){try{const t=e==null?void 0:e.getItem(A$);return t==="light"||t==="dark"||t==="system"?t:"system"}catch{return"system"}}function E9(e,t=T$()){try{t==null||t.setItem(A$,e)}catch{}}function A9(e,t=document.documentElement){t&&(e==="system"?t.removeAttribute("data-theme"):t.setAttribute("data-theme",e))}function T$(){try{return window.localStorage}catch{return}}const $$="buddi.ground",R$="buddi.pageWidth";function T9(e=M$()){const t=i=>{try{return(e==null?void 0:e.getItem(i))??null}catch{return null}},s=t($$),r=t(R$);return{theme:C9(e),ground:s==="sand"?"sand":"blue",width:r==="narrow"||r==="full"?r:"wide"}}function I$(e,t=document.documentElement){t&&(A9(e.theme,t),e.ground==="sand"?t.setAttribute("data-ground","sand"):t.removeAttribute("data-ground"),e.width==="wide"?t.removeAttribute("data-width"):t.setAttribute("data-width",e.width))}function $9(e,t=M$()){E9(e.theme,t);try{t==null||t.setItem($$,e.ground),t==null||t.setItem(R$,e.width)}catch{}}let gl=null;const Dx=new Set;function Ox(){return gl||(gl=T9()),gl}function R9(e){return Dx.add(e),()=>Dx.delete(e)}function I9(e){gl={...Ox(),...e},I$(gl),$9(gl);for(const t of Dx)t()}function P$(){return[d.useSyncExternalStore(R9,Ox,Ox),I9]}function M$(){try{return window.localStorage}catch{return}}const Q0=7,P9=1e4;function M9({timezone:e,embedded:t,agents:s=[],navigate:r}){const{data:i,error:a,reload:l}=de(()=>$.sentinels(),[],3e4),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(null),[p,g]=d.useState(null),[v,b]=d.useState(!1),[j,x]=d.useState(null),w=i==null?void 0:i.alerts,y=(w==null?void 0:w.open)??[],k=D=>{r?r(D):window.location.hash=D},N=D=>{var O;return D?((O=s.find(H=>H.id===D))==null?void 0:O.name)??null:null},S=async D=>{c(null);try{await D()}catch(O){c(O instanceof ve||O instanceof Error?O.message:String(O))}finally{l()}},C=D=>h({...D,id:Date.now()}),E=(D,O,H)=>S(async()=>{const{keys:B}=await $.snoozeAlerts(D,!0,H);C({title:O,undo:()=>$.snoozeAlerts(B,!1)})}),R=D=>S(async()=>{const{id:O}=await $.muteAlert(D.keys[0],D.stop.scope);C({title:"You won’t hear about this again",body:"Turn it back on in Settings → Watchers.",undo:()=>$.unmuteAlert(O)})}),I=D=>S(async()=>{const{agentId:O,conversationId:H}=await $.askAboutAlerts(D.keys);k(st(O,H))}),L=D=>S(async()=>{const[O]=(await $.actOnAlerts([{key:D.key,action:D.index}])).results;if(O!=null&&O.error)throw new Error(O.error);O!=null&&O.approvalId?C({title:"Waiting for your approval",body:"Decide it in Needs you on Home."}):C({title:`${D.label}: done`})}),F=(D,O)=>{O.kind==="open"?k(O.place==="files"?qr:O.plugin&&O.page?xr(O.plugin,O.page,O.item):qr):O.kind==="ask"?I(D):O.kind==="dismiss"?E(D.keys,"Set aside until it changes"):O.kind==="fill"?m(O):O.confirm?g(O):L(O)},T=()=>{const D=y.flatMap(O=>O.keys);E(D,`Cleared ${y.length} for a week`,Q0)},M=w==null?void 0:w.recap,P=D9((M==null?void 0:M.nextAt)??null,e);return n.jsxs(On,{embedded:t,title:"Alerts",lede:"What needs a decision from you.",children:[n.jsx(re,{message:a??o}),n.jsxs(qe,{flush:!0,title:"Needs a decision",tool:y.length>0?String(y.length):void 0,actions:y.length>1?n.jsx(A,{size:"sm",variant:"ghost",onClick:T,children:"Clear all"}):void 0,children:[i?y.length===0?n.jsxs("div",{className:"al-empty",children:[n.jsx(ce,{name:"check"}),n.jsxs("div",{children:[n.jsx("p",{className:"al-empty-title",children:"Nothing needs a decision."}),n.jsxs("p",{className:"al-empty-line",children:["Your watchers are quiet. What they notice in passing waits for ",P,"."]})]})]}):n.jsx("ul",{className:"al-list",children:y.map(D=>n.jsx(X0,{group:D,agentName:N(D.agentId),onAct:F,onStop:R,onNotNow:O=>void E(O.keys,"Snoozed for a week",Q0)},D.id))}):null,M&&M.count>0?n.jsxs("p",{className:"al-recap","data-testid":"recap-line",children:[n.jsxs("span",{children:[M.count," ",M.count===1?"note":"notes"," saved for ",P]}),n.jsx("span",{"aria-hidden":"true",children:"·"}),n.jsx("button",{type:"button",className:"wb-link",onClick:()=>b(!0),children:"Preview"})]}):null]}),w&&(w.snoozed.length>0||w.resolved.length>0)?n.jsxs("p",{className:"al-quiet",children:[w.snoozed.length>0?n.jsxs("button",{type:"button",className:"wb-link","aria-expanded":j==="snoozed",onClick:()=>x(j==="snoozed"?null:"snoozed"),children:[w.snoozed.length," snoozed"]}):null,w.snoozed.length>0&&w.resolved.length>0?n.jsx("span",{"aria-hidden":"true",children:"·"}):null,w.resolved.length>0?n.jsxs("button",{type:"button",className:"wb-link","aria-expanded":j==="resolved",onClick:()=>x(j==="resolved"?null:"resolved"),children:[w.resolved.length," resolved this week"]}):null]}):null,j==="snoozed"&&w?n.jsx(qe,{flush:!0,title:"Snoozed",children:n.jsx("ul",{className:"al-list",children:w.snoozed.map(D=>n.jsxs("li",{className:"al-row",children:[n.jsxs("div",{className:"al-main",children:[n.jsx("p",{className:"al-title",children:D.title}),n.jsx("p",{className:"al-sub",children:D.snoozedUntil?`Back ${Fe(D.snoozedUntil)}`:"Until it changes"})]}),n.jsx("div",{className:"al-actions",children:n.jsx(A,{size:"sm",onClick:()=>void S(async()=>{await $.snoozeAlerts(D.keys,!1)}),children:"Bring back"})})]},D.id))})}):null,j==="resolved"&&w?n.jsx(qe,{flush:!0,title:"Resolved this week",children:n.jsx("ul",{className:"al-list",children:w.resolved.map(D=>n.jsx("li",{className:"al-row",children:n.jsxs("div",{className:"al-main",children:[n.jsx("p",{className:"al-title",children:D.title}),n.jsx("p",{className:"al-sub",children:D.resolvedAt?`Resolved ${Fe(D.resolvedAt)}`:null})]})},D.id))})}):null,v&&M?n.jsxs(Ye,{title:O9(P),onClose:()=>b(!1),children:[n.jsxs("p",{className:"al-form-note",children:["What the watchers noted. buddi reads them out in ",P,"; nothing here needs you now, but you can act on one early."]}),n.jsx("ul",{className:"al-list al-list-sheet",children:M.groups.map(D=>n.jsx(X0,{group:D,agentName:N(D.agentId),recap:!0,onAct:(O,H)=>{H.kind!=="fill"&&b(!1),F(O,H)},onStop:O=>{R(O)}},D.id))})]}):null,f?n.jsx(L9,{action:f,onClose:()=>m(null),onSaved:D=>{m(null),b(!1),C({title:`Saved ${D}`}),l()}}):null,p?n.jsx(Dt,{title:p.label,onClose:()=>g(null),foot:n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",onClick:()=>g(null),children:"Cancel"}),n.jsx(A,{variant:p.tone==="danger"?"danger":"accent",onClick:()=>{const D=p;g(null),L(D)},children:p.label})]}),children:n.jsx("p",{children:p.confirm})}):null,u?n.jsx(ph,{title:u.title,...u.body?{body:u.body}:{},duration:P9,...u.undo?{onUndo:()=>{const D=u.undo;S(async()=>{await D()})}}:{},onGone:()=>h(null)},u.id):null]})}function D9(e,t,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:t}).format(r)}’s recap`}function O9(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Yu(e,t){return e.kind==="ask"?e.label??(t?`Ask ${t}`:"Ask about it"):e.label}function X0({group:e,agentName:t,recap:s,onAct:r,onNotNow:i,onStop:a}){const[l,o]=d.useState(!1),[c,u,...h]=e.actions,f=e.actions.some(p=>p.kind==="ask"),m=e.items.length>1;return n.jsxs("li",{className:"al-row","data-urgent":e.urgent&&!s?"true":void 0,children:[n.jsxs("div",{className:"al-main",children:[n.jsx("p",{className:"al-title",children:e.title}),e.line?n.jsx("p",{className:"al-line",children:e.line}):null,n.jsxs("p",{className:"al-sub",children:[t?n.jsx("span",{children:t}):null,t&&!s?n.jsx("span",{"aria-hidden":"true",children:"·"}):null,s?null:n.jsxs("span",{children:["noticed ",Fe(e.since)]}),m?n.jsxs(n.Fragment,{children:[t||!s?n.jsx("span",{"aria-hidden":"true",children:"·"}):null,n.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?n.jsx("ul",{className:"al-items",children:e.items.map(p=>n.jsxs("li",{className:"al-item",children:[p.subject?n.jsx("span",{className:"al-item-who",children:p.subject.label}):null,n.jsx("span",{className:"al-item-note",children:p.subject?p.note:p.line}),p.actions&&p.actions.length>0?n.jsx("span",{className:"al-item-actions",children:p.actions.map((g,v)=>n.jsx(A,{size:"sm",variant:g.kind==="run"&&g.tone==="danger"?"danger-ghost":"ghost",onClick:()=>r(e,g),children:Yu(g,t)},v))}):null]},p.key))}):null]}),n.jsxs("div",{className:"al-actions",children:[c?n.jsx(A,{size:"sm",variant:"accent",onClick:()=>r(e,c),children:Yu(c,t)}):null,u?n.jsx(A,{size:"sm",variant:u.kind==="run"&&u.tone==="danger"?"danger-ghost":void 0,onClick:()=>r(e,u),children:Yu(u,t)}):null,i?n.jsx(A,{size:"sm",variant:"ghost",onClick:()=>i(e),children:"Not now"}):null,n.jsx("span",{className:"al-more",children:n.jsx(Ys,{label:`More for ${e.title}`,sheet:{title:e.title},items:[...h.map(p=>({label:Yu(p,t),...p.kind==="run"&&p.tone==="danger"?{tone:"critical"}:{},onSelect:()=>r(e,p)})),!f&&{label:t?`Ask ${t}`:"Ask about it",onSelect:()=>r(e,{kind:"ask",label:null})},"separator",{label:"Stop telling me this",hint:"Undo in Settings → Watchers",onSelect:()=>a(e)}]})})]})]})}function L9({action:e,onClose:t,onSaved:s}){const r=e.fields.length===1,[i,a]=d.useState(()=>Object.fromEntries(e.fields.map(p=>[p.key,r&&p.value!==null?String(p.value):""]))),[l,o]=d.useState({}),[c,u]=d.useState(!1),[h,f]=d.useState(null),m=async()=>{const p=e.fields.filter(g=>(i[g.key]??"").trim()!=="").map(g=>({key:g.key,action:g.index,value:(i[g.key]??"").trim()}));if(p.length===0){t();return}u(!0),f(null);try{const{results:g}=await $.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 n.jsx(Ye,{title:e.title,onClose:t,foot:n.jsxs("div",{className:"al-form-foot",children:[n.jsx(A,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(A,{variant:"accent",disabled:c,onClick:()=>void m(),children:c?"Saving…":"Save"})]}),children:n.jsxs("div",{className:"al-form",children:[n.jsx(re,{message:h}),n.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."}),n.jsx("div",{className:"al-form-rows",children:e.fields.map(p=>n.jsxs("label",{className:"al-form-row",children:[n.jsxs("span",{className:"al-form-label",children:[n.jsx("span",{children:p.label}),p.hint?n.jsx("span",{className:"al-form-hint",children:p.hint}):null]}),n.jsx("input",{type:p.type==="date"?"date":"text",inputMode:p.type==="number"?"decimal":void 0,value:i[p.key]??"",placeholder:"—","aria-label":p.label,onChange:g=>a(v=>({...v,[p.key]:g.target.value}))}),l[p.key]?n.jsx("span",{className:"al-form-error",children:l[p.key]}):null]},p.key))})]})})}function F9({mutes:e,onChanged:t}){const[s,r]=d.useState(null);return e.length===0?null:n.jsxs(qe,{flush:!0,title:"Silenced",tool:String(e.length),children:[n.jsx(re,{message:s}),n.jsx("ul",{className:"al-list",children:e.map(i=>n.jsxs("li",{className:"al-row",children:[n.jsxs("div",{className:"al-main",children:[n.jsx("p",{className:"al-title al-silenced-label",children:i.label}),n.jsxs("p",{className:"al-sub",children:["You said “Stop telling me this” ",Fe(i.createdAt)]})]}),n.jsx("div",{className:"al-actions",children:n.jsx(A,{size:"sm",onClick:()=>{r(null),$.unmuteAlert(i.id).then(t,a=>r(a instanceof Error?a.message:String(a)))},children:"Tell me again"})})]},i.id))})]})}const Z0=5e3,eN=50;function _9({timezone:e,embedded:t}){var j;const[s,r]=d.useState(""),[i,a]=d.useState(""),[l,o]=d.useState(null),c=de(()=>$.eventKinds(),[]),{data:u,error:h}=de(()=>$.events({kind:s||void 0,q:i||void 0,limit:eN}),[s,i],Z0),[f,m]=d.useState({events:[],cursor:null,busy:!1,error:null});d.useEffect(()=>{m({events:[],cursor:null,busy:!1,error:null})},[s,i]);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 $.events({kind:s||void 0,q:i||void 0,before:p,limit:eN});m(w=>({events:[...w.events,...x.events],cursor:x.nextCursor,busy:!1,error:null}))}catch(x){m(w=>({...w,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 n.jsxs(On,{embedded:t,title:"Events",lede:"The append-only log. Everything the installation did, including what you do here.",children:[n.jsxs(ae,{children:[n.jsxs("select",{"aria-label":"Event kind",value:s,onChange:x=>r(x.target.value),children:[n.jsx("option",{value:"",children:"every kind"}),(((j=c.data)==null?void 0:j.kinds)??[]).map(x=>n.jsxs("option",{value:x.kind,children:[x.kind," (",x.count,")"]},x.kind))]}),n.jsx("input",{"aria-label":"Payload contains",placeholder:"payload contains…",value:i,onChange:x=>a(x.target.value),size:28}),s||i?n.jsx(A,{onClick:()=>{r(""),a("")},children:"Clear"}):null,n.jsxs("span",{className:"muted",children:["refreshes every ",Z0/1e3,"s"]})]}),n.jsx(re,{message:h}),n.jsx(qe,{flush:!0,children:!u||b.length===0?n.jsx(pe,{children:"No events match."}):n.jsxs(kr,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"#"}),n.jsx("th",{children:"When"}),n.jsx("th",{children:"Kind"}),n.jsx("th",{children:"Payload"})]})}),n.jsx("tbody",{children:b.map(x=>n.jsxs("tr",{"data-clickable":"true",onClick:()=>o(x),children:[n.jsx("td",{className:"mono muted",children:x.id}),n.jsxs("td",{className:"nowrap",children:[nt(x.createdAt,e),n.jsx("div",{className:"sub",children:Fe(x.createdAt)})]}),n.jsx("td",{className:"mono nowrap",children:x.kind}),n.jsx("td",{className:"mono muted",children:Bs(is(x.payload).replace(/\s+/g," "),120)})]},x.id))})]})}),p||f.error?n.jsxs(ae,{children:[n.jsxs("span",{className:"muted",children:[b.length," shown",p?", older ones are kept":"","."]}),n.jsx("span",{className:"ui-toolbar-spacer"}),f.error?n.jsx("span",{className:"critical",children:f.error}):null,p?n.jsx(A,{disabled:f.busy,onClick:()=>void g(),children:f.busy?"Loading…":"Load older"}):null]}):null,l?n.jsxs(Ye,{title:l.kind,onClose:()=>o(null),children:[n.jsxs("p",{className:"muted",children:["Event ",l.id," · ",nt(l.createdAt,e),l.conversationId?n.jsxs(n.Fragment,{children:[" · ",n.jsx("a",{href:`#/conversations/${l.conversationId}`,children:"conversation"})]}):null]}),n.jsx(Pt,{children:is(l.payload)})]}):null]})}const tN=["pending","leased","suspended","failed","succeeded","cancelled"],bo=50,z9=1e4,U9=(e,t,s=`${t}s`)=>e===1?t:s;function B9({timezone:e,embedded:t,initialState:s}){var B,Y;const[r,i]=d.useState(s??""),[a,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(!1),p=r==="failed",{data:g,error:v,reload:b}=de(()=>$.jobs({...r?{state:r}:{},...r?{}:{dismissed:"0"},limit:String(bo)}),[r],1e4),j=de(()=>$.jobFailures(),[],1e4),[x,w]=d.useState({jobs:[],done:!1,busy:!1});d.useEffect(()=>{w({jobs:[],done:!1,busy:!1})},[r]);const y=async()=>{w(W=>({...W,busy:!0}));try{const W=await $.jobs({...r?{state:r}:{dismissed:"0"},limit:String(bo),offset:String(bo+x.jobs.length)});w(q=>({jobs:[...q.jobs,...W.jobs],done:W.jobs.length<bo,busy:!1}))}catch(W){c(W instanceof Error?W.message:String(W)),w(q=>({...q,busy:!1}))}},k=new Set(((g==null?void 0:g.jobs)??[]).map(W=>W.id)),N=[...(g==null?void 0:g.jobs)??[],...x.jobs.filter(W=>!k.has(W.id))],S=(g==null?void 0:g.counts)??{},C=r?S[r]??0:tN.reduce((W,q)=>W+(S[q]??0),0),E=!x.done&&N.length<C&&((g==null?void 0:g.jobs.length)??0)>=bo,R=((B=j.data)==null?void 0:B.open)??[],I=((Y=j.data)==null?void 0:Y.dismissed)??[],L=R.reduce((W,q)=>W+q.count,0),F=I.reduce((W,q)=>W+q.count,0),T=()=>{b(),j.reload()},M=W=>h({...W,id:Date.now()}),P=async W=>{c(null);try{await W()}catch(q){c(q instanceof Error?q.message:String(q))}finally{T()}},D=async W=>{await P(async()=>{await W,l(null)})},O=W=>P(async()=>{const{ids:q}=await $.dismissJobs(W==="all"?{all:!0}:{ids:W});q.length!==0&&M({title:`Dismissed ${q.length===1?"it":q.length}`,body:"Kept under Dismissed, below.",undo:()=>$.undismissJobs(q)})}),H=(W,q)=>P(async()=>{const{jobs:_}=await $.retryJobs({ids:W});if(_.length===0)return;const X=_.length===1;M({title:`Retrying ${X?"it":_.length}`,body:q?`${X?"It runs":"They run"} as soon as a worker is free.`:`If what broke ${X?"it":"them"} hasn’t changed, ${X?"it":"they"} will fail the same way.`})});return n.jsxs(On,{embedded:t,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:t?void 0:n.jsx(A,{size:"sm",variant:g!=null&&g.paused?"accent":void 0,onClick:()=>D($.setPaused(!((g==null?void 0:g.paused)??!1))),children:g!=null&&g.paused?"Resume the queue":"Pause the queue"}),children:[n.jsx(re,{message:v??j.error??o}),R.length>0?n.jsxs(qe,{flush:!0,title:"Gave up",tool:String(L),actions:L>1?n.jsx(A,{size:"sm",variant:"ghost",onClick:()=>void O("all"),children:"Dismiss all"}):void 0,children:[n.jsx("ul",{className:"al-list",children:R.map(W=>n.jsx(sN,{group:W,timezone:e,onOpen:l,onRetry:q=>void H(q,W.likelyFixed),onDismiss:q=>void O(q)},W.key))}),n.jsx("p",{className:"al-recap",children:n.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?n.jsx(qe,{flush:!0,children:n.jsxs("div",{className:"al-empty",children:[n.jsx(ce,{name:"check"}),n.jsxs("div",{children:[n.jsx("p",{className:"al-empty-title",children:"No failed job needs you."}),n.jsx("p",{className:"al-empty-line",children:F>0?"The ones you dismissed stay on record, below.":"Every job either ran or is still on its way."})]})]})}):null,F>0||p?n.jsxs("p",{className:"al-quiet jb-quiet",children:[F>0?n.jsxs("button",{type:"button",className:"wb-link","aria-expanded":f,onClick:()=>m(W=>!W),children:[F," dismissed"]}):null,F>0&&p?n.jsx("span",{"aria-hidden":"true",children:"·"}):null,p?n.jsx("button",{type:"button",className:"wb-link",onClick:()=>i(""),children:"Show the whole queue"}):null]}):null,f&&I.length>0?n.jsx(qe,{flush:!0,title:"Dismissed",children:n.jsx("ul",{className:"al-list",children:I.map(W=>n.jsx(sN,{group:W,timezone:e,dismissed:!0,onOpen:l,onRetry:q=>void H(q,W.likelyFixed)},W.key))})}):null,p?null:n.jsx(qe,{flush:!0,title:"Queue",actions:n.jsxs("select",{"aria-label":"Job state",value:r,onChange:W=>i(W.target.value),children:[n.jsx("option",{value:"",children:"every state"}),tN.map(W=>n.jsxs("option",{value:W,children:[W," (",S[W]??0,")"]},W))]}),children:!g||N.length===0?n.jsx(pe,{children:"No jobs match."}):n.jsxs(kr,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Kind"}),n.jsx("th",{children:"State"}),n.jsx("th",{className:"num",children:"Attempts"}),n.jsx("th",{children:"Last error"}),n.jsx("th",{children:"Updated"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:N.map(W=>n.jsxs("tr",{children:[n.jsxs("td",{className:"clickable",onClick:()=>l(W),children:[W.kind,n.jsx("div",{className:"sub mono",children:gc(W.id)})]}),n.jsxs("td",{children:[n.jsx(Xc,{state:W.state}),W.suspendedReason?n.jsx("div",{className:"sub",children:Bs(W.suspendedReason,40)}):null,W.acknowledgedAt?n.jsx("div",{className:"sub",children:"dismissed"}):null]}),n.jsxs("td",{className:"num",children:[W.attempts,"/",W.maxAttempts]}),n.jsx("td",{className:W.lastError?"critical":"muted",children:W.lastError?Bs(W.lastError,80):"—"}),n.jsxs("td",{className:"nowrap",children:[nt(W.updatedAt,e),n.jsx("div",{className:"sub",children:Fe(W.updatedAt)})]}),n.jsx("td",{children:n.jsxs(ae,{align:"end",children:[["failed","cancelled","suspended"].includes(W.state)?n.jsx(A,{size:"sm",onClick:()=>D($.retryJob(W.id)),children:"Retry"}):null,["pending","leased","suspended","failed"].includes(W.state)?n.jsx(A,{size:"sm",variant:"danger",onClick:()=>D($.cancelJob(W.id)),children:"Cancel"}):null]})})]},W.id))})]})}),E&&!p?n.jsxs(ae,{children:[n.jsxs("span",{className:"muted",children:[N.length," of ",C," shown."]}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(A,{disabled:x.busy,onClick:()=>void y(),children:x.busy?"Loading…":"Load older"})]}):null,a?n.jsxs(Ye,{title:a.kind,onClose:()=>l(null),children:[n.jsx("p",{className:"muted mono",children:a.id}),a.lastError?n.jsx(ue,{title:"Last error",children:n.jsx(Pt,{children:a.lastError})}):null,n.jsx(ue,{title:"Payload",children:n.jsx(Pt,{children:is(a.payload)})}),n.jsx(ue,{title:"Result",children:n.jsx(Pt,{children:is(a.result)})}),a.conversationId?n.jsx("p",{children:n.jsx("a",{href:`#/conversations/${a.conversationId}`,children:"open the transcript"})}):null]}):null,u?n.jsx(ph,{title:u.title,...u.body?{body:u.body}:{},duration:z9,...u.undo?{onUndo:()=>{const W=u.undo;P(async()=>{await W()})}}:{},onGone:()=>h(null)},u.id):null]})}function nN(e){var s;if(e.missionName)return e.missionName;const t=(s=e.job.payload)==null?void 0:s.prompt;return typeof t=="string"&&t.trim()!==""?Bs(t.trim().split(`
111
+ `)[0],48):e.job.kind==="agent-run"?"Agent run":e.job.kind}function sN({group:e,timezone:t,dismissed:s,onOpen:r,onRetry:i,onDismiss:a}){var g;const[l,o]=d.useState(!1),c=e.jobs.length>1,u=e.jobs.map(v=>v.job.id),h=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 ${Fe(((g=e.jobs[0])==null?void 0:g.job.acknowledgedAt)??e.lastAt)}`:`gave up ${Fe(e.lastAt)}`;return n.jsxs("li",{className:"al-row","data-urgent":s?void 0:"true",children:[n.jsxs("div",{className:"al-main",children:[n.jsx("p",{className:"al-title",children:c?`${e.label} · ${e.count}`:e.label}),s?null:n.jsx("p",{className:"al-line",children:e.reason}),n.jsxs("p",{className:"al-sub",children:[h.length>0?n.jsxs(n.Fragment,{children:[n.jsx("span",{children:h.join(", ")}),n.jsx("span",{"aria-hidden":"true",children:"·"})]}):null,!c&&f?n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:"wb-link",onClick:()=>r(f.job),children:nN(f)}),n.jsx("span",{"aria-hidden":"true",children:"·"})]}):null,n.jsx("span",{title:nt(e.lastAt,t),children:p}),c?n.jsxs(n.Fragment,{children:[n.jsx("span",{"aria-hidden":"true",children:"·"}),n.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?n.jsx("ul",{className:"al-items",children:e.jobs.map(v=>n.jsxs("li",{className:"al-item jb-item",children:[v.agentName||v.agentId?n.jsx("span",{className:"al-item-who",children:v.agentName??v.agentId}):null,n.jsxs("span",{className:"al-item-note",children:[n.jsx("button",{type:"button",className:"wb-link",onClick:()=>r(v.job),children:nN(v)})," · ",mj(new Date(v.job.updatedAt),t)," · tried ",v.job.attempts," ",U9(v.job.attempts,"time")]}),n.jsxs("span",{className:"jb-item-acts",children:[n.jsx("button",{type:"button",className:"wb-link",onClick:()=>i([v.job.id]),children:"Retry"}),a?n.jsxs(n.Fragment,{children:[n.jsx("span",{"aria-hidden":"true",children:"·"}),n.jsx("button",{type:"button",className:"wb-link",onClick:()=>a([v.job.id]),children:"Dismiss"})]}):null]})]},v.job.id))}):null]}),n.jsxs("div",{className:"al-actions",children:[n.jsx(A,{size:"sm",variant:e.likelyFixed&&!s?"accent":void 0,onClick:()=>i(u),children:c?"Retry all":"Retry"}),a?n.jsx(A,{size:"sm",variant:"ghost",onClick:()=>a(u),children:"Dismiss"}):null]})]})}const W9=[{id:"conversations",label:"Conversations"},{id:"jobs",label:"Jobs"},{id:"approvals",label:"Approvals"},{id:"alerts",label:"Alerts"},{id:"events",label:"Events"}];function H9({hash:e,timezone:t,navigate:s,agents:r}){var u,h;const i=/^#\/activity\/conversations\/(.+)$/.exec(e),a=f=>{var m;return((m=r.find(p=>p.id===f))==null?void 0:m.name)??f};if(i){let f=i[1];try{f=decodeURIComponent(f)}catch{}return n.jsx(G9,{id:f,timezone:t,navigate:s,nameOf:a})}const l=((u=/^#\/activity\/([a-z]+)/.exec(e))==null?void 0:u[1])??"conversations",o=(h=/[?&]state=([a-z]+)/.exec(e))==null?void 0:h[1],c=f=>m=>{m.preventDefault(),s(f)};return n.jsxs("div",{className:"ui-page",children:[n.jsx(Al,{title:"Activity",lede:"Everything your agents ran, newest first.",actions:n.jsx(J9,{})}),n.jsx(Q9,{}),n.jsx(Zc,{children:W9.map(f=>{const m=f.id==="conversations"?yt:`${yt}/${f.id}`;return n.jsx(Tl,{href:m,active:l===f.id,onClick:c(m),children:f.label},f.id)})}),l==="conversations"?n.jsx(K9,{timezone:t,navigate:s,nameOf:a,agents:r}):null,l==="jobs"?n.jsx(B9,{timezone:t,embedded:!0,initialState:o},o??""):null,l==="approvals"?n.jsx(V9,{timezone:t,nameOf:a}):null,l==="alerts"?n.jsx(M9,{timezone:t,embedded:!0,agents:r,navigate:s}):null,l==="events"?n.jsx(_9,{timezone:t,embedded:!0}):null]})}function K9({timezone:e,navigate:t,nameOf:s,agents:r}){const{data:i,error:a}=de(()=>$.conversations(),[],3e4);return n.jsxs(n.Fragment,{children:[n.jsx(re,{message:a}),n.jsx(qe,{flush:!0,children:i?i.conversations.length===0?n.jsx(In,{icon:"activity",title:"Nothing has run yet",children:"Conversations and runs show up here as your agents work."}):n.jsx(rt,{children:i.conversations.map(l=>n.jsx(et,{href:wc(l.id),onClick:()=>t(wc(l.id)),lead:n.jsx(cn,{agents:r,id:l.agentId,size:"sm"}),title:l.opening?Bs(l.opening,100):"Untitled conversation",sub:`${s(l.agentId)}, ${l.messageCount} message${l.messageCount===1?"":"s"}, ${l.runs} run${l.runs===1?"":"s"}, ${DL(l.usage)}`,side:n.jsx("span",{title:nt(l.lastMessageAt??l.createdAt,e),children:Fe(l.lastMessageAt??l.createdAt)})},l.id))}):n.jsx(pe,{children:"Loading…"})})]})}function V9({timezone:e,nameOf:t}){const{data:s,error:r}=de(()=>$.approvals(),[],1e4),i=[...(s==null?void 0:s.pending)??[],...(s==null?void 0:s.recent)??[]];return n.jsxs(n.Fragment,{children:[n.jsx(re,{message:r}),n.jsx(qe,{flush:!0,children:s?i.length===0?n.jsx(In,{icon:"bell",title:"No approvals yet",children:"When an agent asks before acting, the request and your answer are kept here."}):n.jsxs(kr,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Tool"}),n.jsx("th",{children:"State"}),n.jsx("th",{children:"Asked by"}),n.jsx("th",{children:"Decided"}),n.jsx("th",{children:"Created"})]})}),n.jsx("tbody",{children:i.map(a=>n.jsxs("tr",{children:[n.jsxs("td",{children:[a.tool,n.jsx("div",{className:"sub mono",children:gc(a.id)})]}),n.jsx("td",{children:n.jsx(Xc,{state:a.state})}),n.jsx("td",{children:t(a.agentId)}),n.jsx("td",{className:"nowrap",children:a.decidedAt?n.jsxs(n.Fragment,{children:[nt(a.decidedAt,e),n.jsxs("div",{className:"sub",children:["via ",a.decidedVia??"—"]})]}):n.jsx("span",{className:"muted",children:"—"})}),n.jsxs("td",{className:"nowrap",children:[nt(a.createdAt,e),n.jsx("div",{className:"sub",children:Fe(a.createdAt)})]})]},a.id))})]}):n.jsx(pe,{children:"Loading…"})})]})}function G9({id:e,timezone:t,navigate:s,nameOf:r}){const[i,a]=d.useState(null),[l,o]=d.useState(null);d.useEffect(()=>{let u=!1;return $.conversation(e).then(h=>{u||a(h)}).catch(h=>{u||o(h instanceof Error?h.message:String(h))}),()=>{u=!0}},[e]);const c=u=>h=>{h.preventDefault(),s(u)};return n.jsxs("div",{className:"ui-page",children:[n.jsx("p",{className:"page-crumbs",children:n.jsx("a",{href:yt,onClick:c(yt),children:"Activity"})}),n.jsxs("header",{className:"ui-page-head",children:[n.jsxs("div",{className:"ui-page-head-row",children:[n.jsxs("h2",{className:"ui-page-title",children:[n.jsx(A,{size:"sm",onClick:()=>s(yt),children:"← Back"}),n.jsx("span",{children:"Transcript"})]}),i?n.jsx("div",{className:"ui-page-actions",children:n.jsx(dt,{size:"sm",href:st(i.agentId,e),onClick:c(st(i.agentId,e)),children:"Open in chat"})}):null]}),n.jsx("p",{className:"ui-page-lede mono",children:e})]}),n.jsx(re,{message:l}),i?n.jsxs(n.Fragment,{children:[n.jsxs(Nf,{children:[n.jsx(ur,{label:"Agent",value:r(i.agentId),size:"sm"}),n.jsx(ur,{label:"Runs",value:i.runs.length}),n.jsx(ur,{label:"Tokens",value:`${Xt(i.usage.input)} / ${Xt(i.usage.output)}`,note:Pg(i.usage)?`input / output, ${Pg(i.usage)}`:"input / output"}),n.jsx(ur,{label:"Started",value:nt(i.createdAt,t),size:"sm"})]}),i.runs.length>0?n.jsx(qe,{title:"Runs",flush:!0,children:n.jsxs(kr,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Started"}),n.jsx("th",{children:"Finished"}),n.jsx("th",{className:"num",children:"Turns"}),n.jsx("th",{children:"Stopped"}),n.jsx("th",{className:"num",children:"Tokens"}),n.jsx("th",{className:"num",children:"Cached"})]})}),n.jsx("tbody",{children:i.runs.map((u,h)=>n.jsxs("tr",{children:[n.jsxs("td",{className:"nowrap",children:[nt(u.startedAt,t)," ",u.resumed?n.jsx(we,{children:"resumed"}):null]}),n.jsx("td",{className:"nowrap",children:nt(u.finishedAt,t)}),n.jsx("td",{className:"num",children:u.turns??"—"}),n.jsxs("td",{children:[u.stopped??"—",u.actionId?n.jsxs("div",{className:"sub mono",children:["action ",gc(u.actionId)]}):null]}),n.jsxs("td",{className:"num muted nowrap",children:[Xt(u.usage.input)," / ",Xt(u.usage.output)]}),n.jsx("td",{className:"num muted nowrap",children:u.usage.cacheRead||u.usage.cacheWrite?Xt((u.usage.cacheRead??0)+(u.usage.cacheWrite??0)):"—"})]},h))})]})}):null,n.jsx(ue,{title:"Messages",children:n.jsx(le,{children:i.messages.map(u=>n.jsxs("article",{className:"transcript-msg",children:[n.jsxs("header",{className:"transcript-who",children:[u.speaker===rN?"approved action, result":u.role,", ",nt(u.createdAt,t)]}),n.jsxs("div",{className:"transcript-body",children:[u.blocks.length===0?n.jsx("span",{className:"muted",children:"(empty)"}):null,u.speaker===rN?u.blocks.map((h,f)=>n.jsx(q9,{block:h},f)):u.blocks.map((h,f)=>n.jsx(Y9,{block:h},f))]})]},u.id))})})]}):n.jsx(pe,{children:"Loading…"})]})}const rN="approval:resume";function q9({block:e}){return n.jsxs("div",{className:"transcript-tool",children:[n.jsx("div",{className:"transcript-tool-name mono",children:"← approved action"}),n.jsx(Pt,{children:e.type==="text"?e.text??"":is(e)})]})}function Y9({block:e}){return e.type==="text"?n.jsx("div",{className:"transcript-text",children:n.jsx(Ws,{text:e.text??""})}):e.type==="thinking"?n.jsxs("details",{className:"transcript-thinking",children:[n.jsx("summary",{children:"Thoughts"}),n.jsx("div",{className:"transcript-thinking-text",children:n.jsx(Ws,{text:e.text??""})})]}):e.type==="thinking_hidden"?n.jsx("div",{className:"transcript-thinking-hidden",children:"Thinking (hidden)"}):e.ref===void 0&&e.type==="provider_native"?n.jsx(n.Fragment,{}):e.type==="tool_use"?n.jsxs("div",{className:"transcript-tool",children:[n.jsxs("div",{className:"transcript-tool-name mono",children:["→ ",e.name]}),n.jsx(Pt,{children:is(e.input)})]}):e.type==="tool_result"?n.jsxs("div",{className:"transcript-tool","data-tone":e.isError?"critical":void 0,children:[n.jsxs("div",{className:"transcript-tool-name mono",children:["← ",e.isError?"error":"result"]}),n.jsx(Pt,{children:e.content??""})]}):n.jsxs("div",{className:"transcript-tool",children:[n.jsx("div",{className:"transcript-tool-name mono",children:e.type}),n.jsx(Pt,{children:is(e.ref)})]})}function J9(){const{data:e,reload:t}=de(()=>$.overview(),[],1e4),[s,r]=d.useState(!1);if(!e)return null;const i=()=>{r(!0),$.setPaused(!e.paused).then(t,t).finally(()=>r(!1))};return n.jsx(A,{size:"sm",variant:e.paused?"accent":void 0,disabled:s,onClick:i,children:e.paused?"Resume all":"Pause all"})}function Q9(){const{data:e,reload:t}=de(()=>$.overview(),[],1e4);if(d.useEffect(()=>(window.addEventListener(ta,t),()=>window.removeEventListener(ta,t)),[t]),!e)return null;const s=i=>e.jobs[i]??0,r=s("leased");return n.jsxs(Nf,{children:[n.jsx(ur,{label:"Jobs done",value:Xt(s("succeeded"))}),n.jsx(ur,{label:"Failed",value:Xt(s("failed")),...s("failed")>0?{tone:"critical"}:{}}),n.jsx(ur,{label:"Queued",value:Xt(s("pending")),note:`${r} running`}),n.jsx(ur,{label:"Approvals",value:Xt(e.approvals.pending),note:"waiting for you"})]})}const X9=["replay-all","coalesce","latest-only","skip-after-deadline"];function D$({timezone:e,embedded:t,agentId:s}){const{data:r,error:i,reload:a}=de(()=>$.missions(),[],3e4),l=((r==null?void 0:r.missions)??[]).filter(h=>!s||h.agentId===s),[o,c]=d.useState(null),u=async h=>{c(null);try{await h,a()}catch(f){c(f instanceof Error?f.message:String(f))}};return n.jsxs(On,{embedded:t,title:"Missions",lede:"Standing schedules. A disabled mission materializes nothing.",children:[n.jsx(re,{message:i??o}),!r||l.length===0?n.jsxs(In,{icon:"calendar",title:"No missions yet",children:["Run ",n.jsx("code",{children:"buddi missions add-defaults"})," for the standard set."]}):n.jsx(le,{children:l.map(h=>n.jsx(Z9,{mission:h,timezone:e,onRun:u},h.id))})]})}function Z9({mission:e,timezone:t,onRun:s}){const[r,i]=d.useState(!1);return n.jsxs(ds,{tone:e.enabled&&!e.pausedReason?"good":"muted",title:n.jsxs(n.Fragment,{children:[e.name," ",n.jsx("span",{className:"mono muted",children:e.id})]}),meta:n.jsxs(n.Fragment,{children:[n.jsx(we,{mono:!0,children:e.agentId}),e.alwaysDeliver?n.jsx(we,{children:"always delivers"}):null,e.enabled?null:n.jsx(we,{tone:"warning",children:e.endedAt?"ended":"disabled"}),e.pausedReason?n.jsx(we,{tone:"warning",children:e.pausedReason}):null]}),actions:n.jsxs(n.Fragment,{children:[n.jsx(A,{size:"sm",onClick:()=>s($.setMissionEnabled(e.id,!e.enabled)),children:e.enabled?"Disable":"Enable"}),n.jsx(A,{size:"sm",variant:"ghost",onClick:()=>i(a=>!a),"aria-expanded":r,children:r?"Less":"More"})]}),children:[e.stillUsefulAskedAt?n.jsx(V,{tone:"warning",title:"Still useful?",action:n.jsxs(ae,{align:"end",children:[n.jsx(A,{size:"sm",onClick:()=>s($.answerStillUseful(e.id,"stop")),children:"Stop"}),n.jsx(A,{size:"sm",variant:"accent",onClick:()=>s($.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?n.jsxs("p",{className:"ui-card-meta",children:[e.stopWhen?`Stops itself when ${e.stopWhen}. `:"",e.endedAt?`Ended ${nt(e.endedAt,t)}.`:e.endsAt?`Ends ${nt(e.endsAt,t)}.`:""]}):null,n.jsxs("p",{className:"ui-card-meta",children:[e.schedule?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"mono",children:e.schedule.cron})," ",e.schedule.timezoneExplicit===!1?n.jsx("span",{title:e.schedule.timezone,children:"follows your timezone"}):e.schedule.timezone," ","· rev"," ",e.schedule.revision," · next"," ",e.nextRun?`${nt(e.nextRun,t)} (${Fe(e.nextRun)})`:"—"]}):"no schedule — enqueued by hand or by a sentinel",n.jsx("br",{}),"Last notification:"," ",e.lastNotification?`${e.lastNotification.kind==="mission.delivered"?"delivered":"silent"} ${Fe(e.lastNotification.at)}${e.lastNotification.reason?` — ${e.lastNotification.reason}`:""}`:"none"]}),r?n.jsxs("div",{className:"ui-card-foot",children:[e.schedule?n.jsxs(ae,{children:[n.jsx(oe,{inline:!0,label:"Misfire policy",children:n.jsx("select",{value:e.schedule.misfirePolicy,onChange:a=>s($.setMisfirePolicy(e.id,a.target.value)),children:X9.map(a=>n.jsx("option",{value:a,children:a},a))})}),n.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,n.jsx(ue,{title:"Prompt",children:n.jsx(Pt,{children:e.prompt})}),n.jsx(ue,{title:"Recent occurrences",children:n.jsx(qe,{flush:!0,children:e.occurrences.length===0?n.jsx(pe,{children:"Never run."}):n.jsxs(kr,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Scheduled"}),n.jsx("th",{children:"State"}),n.jsx("th",{children:"Finished"}),n.jsx("th",{children:"Detail"})]})}),n.jsx("tbody",{children:e.occurrences.map(a=>n.jsxs("tr",{children:[n.jsx("td",{className:"nowrap",children:nt(a.scheduledAt,t)}),n.jsx("td",{children:n.jsx(Xc,{state:a.state})}),n.jsx("td",{className:"nowrap",children:nt(a.finishedAt,t)}),n.jsxs("td",{className:a.error?"critical":"muted",children:[a.error?Bs(a.error,120):null,a.runConversationId?n.jsx("a",{href:`#/conversations/${a.runConversationId}`,children:"transcript"}):null]})]},a.id))})]})})})]}):null]})}function eV(e,t){const s=`${e} offer${e===1?"":"s"}`,r=t?` from ${t}`:"";return`Dismiss ${s}${r}? They stop appearing everywhere. Nothing runs, and you can still see them under "Dismissed and lapsed" for a week.`}function O$({ids:e,agentName:t,onDone:s}){const r=e.length,[i,a]=d.useState(!1),[l,o]=d.useState(!1);return r<=0?null:i?n.jsxs("span",{className:"ui-row",children:[n.jsx("span",{className:"muted",children:eV(r,t)}),n.jsx(A,{size:"sm",variant:"danger",disabled:l,onClick:()=>{o(!0),$.dismissOffers(e).then(()=>{a(!1),s()}).finally(()=>o(!1))},children:`Dismiss ${r}`}),n.jsx(A,{size:"sm",variant:"ghost",disabled:l,onClick:()=>a(!1),children:"Keep them"})]}):n.jsx(A,{size:"sm",variant:"ghost",onClick:()=>a(!0),children:"Dismiss all"})}function L$({embedded:e,agentId:t,agentName:s}){const{data:r,error:i,reload:a}=de(()=>$.offers(),[],2e4),l=j=>!t||j.agentId===t,o=((r==null?void 0:r.offers)??[]).filter(l),c=((r==null?void 0:r.closed)??[]).filter(l),[u,h]=d.useState(null),[f,m]=d.useState(null),[p,g]=d.useState(null),v=async(j,x)=>{h(null),m(j);try{const w=await $.takeOffer(j);g(w.jobId?`On it — ${x}. Started as job ${w.jobId}.`:`Taken — ${x}. No worker is running here, so nothing has started yet.`),a()}catch(w){h(w instanceof Error?w.message:String(w))}finally{m(null)}},b=async(j,x)=>{h(null),m(j);try{await $.dismissOffer(j),g(`Dismissed — ${x}. It will not come back.`),a()}catch(w){h(w instanceof Error?w.message:String(w))}finally{m(null)}};return n.jsxs(On,{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:[n.jsx(re,{message:i??u}),p?n.jsx(V,{tone:"good",role:"status",children:p}):null,o.length>0?n.jsxs(ae,{children:[n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(O$,{ids:o.map(j=>j.id),agentName:s,onDone:()=>{g(null),a()}})]}):null,!r||o.length===0?n.jsx(In,{icon:"bulb",title:"Nothing on offer",children:"When an agent works out something you might want done, it waits here."}):n.jsx(le,{children:o.map(j=>n.jsx(ds,{tone:"accent",title:j.label,meta:n.jsxs(n.Fragment,{children:[n.jsx(we,{mono:!0,children:j.agentId}),n.jsxs("span",{className:"muted",children:["expires ",Fe(j.expiresAt)]})]}),actions:n.jsxs(n.Fragment,{children:[n.jsx(A,{size:"sm",variant:"ghost",disabled:f===j.id,onClick:()=>void b(j.id,j.label),children:"Not now"}),n.jsx(A,{variant:"accent",size:"sm",disabled:f===j.id,onClick:()=>void v(j.id,j.label),children:"Take"})]}),children:n.jsx("p",{className:"ui-card-meta",children:j.prompt})},j.id))}),c.length>0?n.jsxs(Tt,{summary:`Dismissed and lapsed (${c.length})`,boxed:!0,children:[n.jsx(qe,{flush:!0,children:n.jsx(rt,{children:c.map(j=>n.jsx(et,{title:j.label,sub:`${j.agentId} — ${_L(j)}`,side:Fe(j.dismissedAt??j.lapsedAt??j.createdAt)},j.id))})}),n.jsx("p",{className:"muted",children:"These stop being shown a week after they closed."})]}):null]})}const tV={work:"Work",money:"Money",home:"Home",health:"Health",learning:"Learning",life:"Life"},Sw=e=>tV[e]??Pf(e);function Pf(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Kt(e){return e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function Rl(e){return e.replace(/\.0$/,"")}function nV(e){return e.avatar?$.marketAssetUrl(e.avatar):void 0}const sV={mailbox:{title:"your mailbox",fix:"Add a mailbox",route:vr("email","settings")},"image-account":{title:"a drawing account",fix:"Choose a drawing account",route:vr("image","settings")}};function Cw(e){return sV[e.replace(/\?$/,"")]??{title:e,fix:"Set it up",route:Pe()}}const Mf=e=>Pf(e);function F$(e){return e.kind==="plugin"?e.title:Cw(e.name).title}function _$(e){if(e.kind==="need"){const t=Cw(e.name);return{label:t.fix,route:t.route}}return e.fix==="enable"?{label:`Turn on ${e.title}`,route:Pe("plugins")}:e.fix==="update"?{label:`Update ${e.title}`,route:Pe("plugins")}:e.byBuddi?null:{label:`Install ${e.title}`,route:Pe("plugins")}}function rV(e,t,s){const r=new Set((e.missing??[]).map(o=>o.name)),a=[...Object.keys(e.requires),...Object.keys(e.optional)].filter(o=>!r.has(o)&&t.has(o)).map(Mf),l=e.needs.includes("mailbox")||e.needs.includes("mailbox?");return s===!0&&l&&!r.has("mailbox")&&a.push("your mailbox"),a}function lp(e){return Pf(e.replace(/\.md$/i,"").replace(/[-_]+/g," ").trim())}const iN=(e,t)=>e.includes(t),iV={email:{title:"Mail",line:e=>iN(e,"email.draft")||iN(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(t=>t.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."}},aV={schedule:"reminder",browser:"web"};function jh(e,t=new Map){const s=[],r=new Map;for(const i of e){const a=i.replace(/\?$/,""),l=a.split(".")[0]??a,o=aV[l]??l;r.has(o)||(r.set(o,[]),s.push(o)),r.get(o).push(a)}return s.map(i=>{const a=r.get(i),l=iV[i],o=a.some(u=>t.get(u)==="gated"||u.endsWith(".*")&&[...t].some(([h,f])=>f==="gated"&&h.startsWith(u.slice(0,-1)))),c=l?l.line(a):`${a.length===1?"One of its tools":`${a.length} of its tools`}.`;return[(l==null?void 0:l.title)??Pf(i),o&&!/asks you/i.test(c)?`${c} Asks you first before it changes anything.`:c]})}function aN(e){return e.length===0?"Nothing beyond its own chat.":`Reaches ${Kt(e.map(([t])=>t))}.`}function wh(e){return new Map((e??[]).filter(t=>t.tier).map(t=>[t.name,t.tier]))}function Xl({entry:e,size:t}){const s=nV(e);return n.jsx("span",{className:"cat-face","data-size":t,children:n.jsx(Sn,{id:e.name,name:e.title,size:t==="xxl"?"xl":t,face:{tools:e.tools,...s?{picture:s}:{}}})})}const z$=800,lV=e=>{var t;return((t=/^.*?[.!?](?=\s|$)/.exec(e.trim()))==null?void 0:t[0])??e.trim()},xl=e=>e instanceof ve?e.message:String(e);function Ir({entry:e,children:t}){return n.jsxs("span",{className:"plugins-sheet-title",children:[n.jsx(Xl,{entry:e,size:"lg"}),n.jsxs("span",{className:"plugins-sheet-name",children:[n.jsx("span",{children:t}),n.jsxs("span",{className:"plugins-sheet-by",children:["by ",e.author.name,e.trust==="by-buddi"?n.jsxs(n.Fragment,{children:[" · ",n.jsx(we,{tone:"accent",children:"by buddi"})]}):null]})]})]})}function op({state:e,children:t}){return n.jsxs("li",{className:"cat-step","data-state":e,children:[n.jsx("span",{className:"cat-step-mark",children:e==="done"?n.jsx(ce,{name:"check",size:12}):e==="failed"?n.jsx(ce,{name:"alert",size:14}):null}),n.jsx("span",{children:t})]})}function cp(e){const t=e.kind==="plugin"?["Installing","Installed"]:["Adding","Added"];return e.state==="done"?{state:"done",words:`${t[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:`${t[0]} ${e.title}`}:{state:"now",words:`${t[0]} ${e.title}…`}}function oV(e){const[t,s]=d.useState(null),[r,i]=d.useState(null);return d.useEffect(()=>{if(s(null),i(null),!e)return;let a=!1,l;const o=()=>{$.catalogueJob(e).then(c=>{a||(s(c),c.state==="running"&&(l=window.setTimeout(o,z$)))}).catch(c=>{a||i(xl(c))})};return o(),()=>{a=!0,l!==void 0&&window.clearTimeout(l)}},[e]),{job:t,error:r,setJob:s}}function U$({entry:e,navigate:t,onClose:s,onAdded:r}){var _e;const i=Ns("(max-width: 720px)"),[a,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState({}),[f,m]=d.useState(""),[p,g]=d.useState([]),[v,b]=d.useState(!1),[j,x]=d.useState(null),[w,y]=d.useState(!1),[k,N]=d.useState(null),{job:S,error:C,setJob:E}=oV(j),[R,I]=d.useState(!1),[L,F]=d.useState(null),[T,M]=d.useState(!1),P=d.useRef(!1),[D,O]=d.useState([]);d.useEffect(()=>{if(!a||a.plugins.length===0)return;let U=!1;return Promise.resolve().then(()=>$.market()).then(ie=>{U||O((ie==null?void 0:ie.plugins)??[])}).catch(()=>{}),()=>{U=!0}},[a]),d.useEffect(()=>{let U=!1;return $.cataloguePlan(e.name).then(ie=>{U||(l(ie),h(Object.fromEntries(ie.fills.map(J=>[J.id,J.value]))),m(ie.handle))}).catch(ie=>{U||c(xl(ie))}),()=>{U=!0}},[e.name]),d.useEffect(()=>{(S==null?void 0:S.state)==="done"&&S.agent&&!P.current&&(P.current=!0,r==null||r(S.agent))},[S,r]);const H=()=>{a&&(y(!0),N(null),P.current=!1,$.catalogueInstall(e.name,{version:a.version,fills:u,handle:f,missionsOn:p,tools:a.tools.map(U=>U.name)}).then(U=>x(U.jobId)).catch(U=>N(xl(U))).finally(()=>y(!1)))},B=()=>{x(null),H()},Y=e.title,W=S==null?void 0:S.agent,q=U=>{W&&(U&&vj(W.id,U),s(),t(st(W.id)))},_=U=>{S&&(I(!0),F(null),$.catalogueConfirm(S.id,U).then(ie=>{E(ie),U||s()}).catch(ie=>F(xl(ie))).finally(()=>I(!1)))};if((S==null?void 0:S.state)==="confirm"&&S.confirm){const U=jh(S.confirm.tools.map(J=>J.name),wh(S.confirm.tools)),ie=S.steps.filter(J=>J.kind==="plugin"&&J.state==="done").map(J=>J.title);return n.jsxs(Ye,{title:n.jsxs(Ir,{entry:e,children:["Add ",Y]}),onClose:s,foot:n.jsxs(ae,{children:[n.jsx(ht,{}),n.jsx(A,{variant:"ghost",disabled:R,onClick:()=>_(!1),children:"Don’t add it"}),n.jsxs(A,{variant:"accent",disabled:R,onClick:()=>_(!0),children:["Add ",Y]})]}),children:[n.jsx("ol",{className:"cat-steps","data-testid":"cat-confirm",children:S.steps.filter(J=>J.kind==="plugin").map(J=>{const{state:ye,words:ge}=cp(J);return n.jsx(op,{state:ye,children:ge},`${J.kind}-${J.name}`)})}),n.jsxs(V,{tone:"warning",title:`${Y} would get more than the list showed.`,children:[ie.length>0?`With ${Kt(ie)} installed, `:"","its tools resolved to a different set",S.confirm.unshown.length>0?`, including ${Kt(S.confirm.unshown)}`:"",". Look at what it can reach before you add it."]}),n.jsx(re,{message:L}),n.jsxs("div",{className:"cat-block",children:[n.jsx("h3",{className:"cat-block-title",children:"What it can reach"}),n.jsxs("p",{className:"cat-prose",children:[aN(U)," ",n.jsx("button",{type:"button",className:"plugins-link cat-link",onClick:()=>M(!T),children:T?"Hide":"See all"})]}),T?n.jsx("dl",{className:"cat-reach",children:U.map(([J,ye])=>n.jsxs("div",{className:"cat-reach-row",children:[n.jsx("dt",{children:J}),n.jsx("dd",{children:ye})]},J))}):null]}),n.jsx("p",{className:"cat-small",children:"The plugins stay installed either way; Settings → Plugins removes them."})]})}if(j&&(!S||S.state==="running")){const U=S==null?void 0:S.steps[S.steps.length-1],ie=(S==null?void 0:S.approvalId)&&(U==null?void 0:U.state)==="adding";return n.jsxs(Ye,{title:n.jsxs(Ir,{entry:e,children:["Add ",Y]}),onClose:s,foot:n.jsx(ae,{align:"end",children:n.jsx(A,{onClick:s,children:"Close"})}),children:[n.jsx("ol",{className:"cat-steps","aria-live":"polite","data-testid":"cat-progress",children:((S==null?void 0:S.steps)??[]).map(J=>{const{state:ye,words:ge}=cp(J);return n.jsx(op,{state:ye,children:ge},`${J.kind}-${J.name}`)})}),ie?n.jsxs(V,{tone:"accent",action:n.jsx(A,{size:"sm",onClick:()=>{s(),t(Cl)},children:"Open it"}),children:["Adding ",Y," waits for your approval in Needs you."]}):null,n.jsx(re,{message:C}),n.jsxs("p",{className:"cat-small",children:["You can close this; it carries on, and ",Y," joins the team when it’s done."]})]})}if((S==null?void 0:S.state)==="done"){const U=S.steps.filter(ye=>ye.kind==="plugin").map(ye=>ye.title),ie=(a==null?void 0:a.missions.length)??e.missions.length,J=p.length;return n.jsxs(Ye,{title:n.jsx(Ir,{entry:e,children:Y}),onClose:s,foot:n.jsxs(ae,{children:[n.jsx(A,{variant:"ghost",onClick:()=>{s(),t(Ht())},children:"Back to teammates"}),n.jsx(ht,{}),n.jsx(A,{variant:"accent",onClick:()=>q(),children:"Say hello"})]}),children:[n.jsxs("div",{className:"cat-done","data-testid":"cat-done",children:[n.jsx(Xl,{entry:e,size:"xxl"}),n.jsxs("p",{className:"cat-done-title",children:[Y," is on your team."]}),n.jsxs("p",{className:"cat-small",children:["@",(W==null?void 0:W.handle)??f,U.length?` · ${Kt(U)} installed`:"",ie>0&&J<ie?` · ${ie-J===1?"a mission":"missions"} off until you turn ${ie-J===1?"it":"them"} on`:""]})]}),e.examples.length>0?n.jsxs("div",{className:"cat-block",children:[n.jsx("h3",{className:"cat-block-title",children:"Try one"}),n.jsx("div",{className:"wb-starters",children:e.examples.map(ye=>n.jsx("button",{type:"button",className:"wb-starter",onClick:()=>q(ye),children:ye},ye))})]}):null]})}if((S==null?void 0:S.state)==="failed"){const U=S.steps.find(ie=>ie.kind==="plugin"&&ie.state==="failed");return n.jsxs(Ye,{title:n.jsxs(Ir,{entry:e,children:[Y," wasn’t added"]}),onClose:s,foot:n.jsxs(ae,{children:[n.jsx(ht,{}),n.jsx(A,{variant:"ghost",onClick:s,children:"Close"}),n.jsx(A,{variant:"accent",disabled:w,onClick:B,children:"Try again"})]}),children:[n.jsx("ol",{className:"cat-steps","data-testid":"cat-failed",children:S.steps.map(ie=>{const{state:J,words:ye}=cp(ie);return n.jsx(op,{state:J==="now"?"next":J,children:J==="now"?ye.replace(/…$/,""):ye},`${ie.kind}-${ie.name}`)})}),n.jsx(V,{tone:"critical",title:`${S.error??"It stopped before it finished"}.`,action:S.approvalId?n.jsx(A,{size:"sm",onClick:()=>{s(),t(Cl)},children:"Open the approval"}):void 0,children:n.jsxs("p",{children:["Nothing was added and nothing else changed.",U?n.jsxs(n.Fragment,{children:[" ",U.title," waits in"," ",n.jsx("a",{href:Pe("plugins"),onClick:ie=>{ie.preventDefault(),s(),t(Pe("plugins"))},children:"Settings → Plugins"})," ","if you’d rather look at it there."]}):null]})}),n.jsx(re,{message:k})]})}const X=(a==null?void 0:a.plugins.filter(U=>U.fix==="install"&&U.byBuddi))??[],Q=(a==null?void 0:a.blocked)??[],ee=Q[0],fe=ee?_$(ee):null,Le=jh(a?a.tools.map(U=>U.name):e.tools,wh([...((_e=e.claims)==null?void 0:_e.tools)??[],...((a==null?void 0:a.tools)??[]).filter(U=>U.tier!=="unknown")])),Ie=U=>{var ie;return((ie=e.missions.find(J=>J.id===U))==null?void 0:ie.when)??""};return n.jsxs(Ye,{title:n.jsxs(Ir,{entry:e,children:["Add ",Y]}),onClose:s,foot:n.jsxs(ae,{children:[i?null:n.jsx("span",{className:"plugins-foot-note",children:X.length?`Installs ${Kt(X.map(U=>U.title))}, then adds ${Y}.`:"Nothing runs until you add it."}),n.jsx(ht,{}),n.jsx(A,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsxs(A,{variant:"accent",disabled:!a||Q.length>0||w||f.length<2,onClick:H,children:["Add ",Y]})]}),children:[n.jsxs("p",{className:"cat-lede",children:[e.pitch," One approval adds it; you can change or remove it from its page."]}),n.jsx(re,{message:o??k}),!a&&!o?n.jsx(pe,{children:"Reading what it needs…"}):a?n.jsxs(le,{divided:!0,gap:"lg",children:[X.length>0?n.jsxs("div",{className:"cat-block",children:[n.jsx("h3",{className:"cat-block-title",children:"Installed on the way"}),n.jsx("ul",{className:"cat-plugins",children:X.map(U=>{const ie=D.find(J=>J.name===U.name);return n.jsxs("li",{children:[n.jsx(Pn,{svg:ie==null?void 0:ie.iconSvg}),n.jsxs("span",{className:"cat-plugin-text",children:[n.jsxs("span",{className:"cat-plugin-name",children:[U.title," ",U.version?n.jsx("span",{className:"plugins-ver",children:U.version}):null]}),n.jsx("span",{className:"cat-small",children:ie!=null&&ie.summary?lV(ie.summary):"Made by buddi; installed only if it matches what withbuddi.com lists."})]}),n.jsx(we,{tone:"accent",children:"by buddi"})]},U.name)})})]}):null,ee?n.jsxs(V,{tone:"warning",action:fe?n.jsx(A,{size:"sm",onClick:()=>{s(),t(fe.route)},children:fe.label}):void 0,children:[Y," needs ",Kt(Q.map(F$))," first. Add ",Q.length===1?"it":"them",", then come back; nothing is added until then."]}):null,a.fills.length>0?n.jsxs("div",{className:"cat-block",children:[n.jsxs("h3",{className:"cat-block-title",children:["A few picks ",n.jsx("span",{className:"cat-block-aside",children:"filled in for you"})]}),n.jsx("div",{className:"cat-fills",children:a.fills.map(U=>n.jsx(oe,{label:n.jsxs(n.Fragment,{children:[U.label,U.optional?n.jsx("span",{className:"faint",children:" · optional"}):null]}),children:U.choices&&U.choices.length>0?n.jsxs("select",{value:u[U.id]??"",onChange:ie=>h({...u,[U.id]:ie.target.value}),children:[U.kind==="calendar"?n.jsx("option",{value:"",children:"All of them"}):null,U.choices.map(ie=>n.jsx("option",{value:ie,children:ie},ie))]}):U.kind==="time"?n.jsx("input",{type:"time",value:u[U.id]??"",onChange:ie=>h({...u,[U.id]:ie.target.value})}):n.jsx("input",{value:u[U.id]??"",onChange:ie=>h({...u,[U.id]:ie.target.value})})},U.id))})]}):null,n.jsx("div",{className:"cat-block",children:n.jsx(oe,{label:"Handle",hint:"How you call it in chat and on Telegram.",children:n.jsxs("span",{className:"cat-handle",children:[n.jsx("span",{className:"mono faint",children:"@"}),n.jsx("input",{className:"mono","aria-label":"Handle",value:f,onChange:U=>m(U.target.value.toLowerCase().replace(/[^a-z0-9-]/g,""))})]})})}),a.missions.length>0?n.jsxs("div",{className:"cat-block",children:[n.jsxs("h3",{className:"cat-block-title",children:["Missions ",n.jsx("span",{className:"cat-block-aside",children:"off unless you turn one on"})]}),n.jsx("ul",{className:"cat-missions","data-switches":"true",children:a.missions.map(U=>n.jsxs("li",{children:[n.jsx("span",{className:"cat-mission-name",children:U.name}),n.jsx("span",{className:"cat-mission-when",children:Ie(U.id)}),n.jsx(YU,{checked:p.includes(U.id),label:`Turn on ${U.name}`,onChange:ie=>g(ie?[...p,U.id]:p.filter(J=>J!==U.id))})]},U.id))})]}):null,n.jsxs("div",{className:"cat-block",children:[n.jsx("h3",{className:"cat-block-title",children:"What it can reach"}),n.jsxs("p",{className:"cat-prose",children:[aN(Le)," ",n.jsx("button",{type:"button",className:"plugins-link cat-link",onClick:()=>b(!v),children:v?"Hide":"See all"})]}),v?n.jsx("dl",{className:"cat-reach",children:Le.map(([U,ie])=>n.jsxs("div",{className:"cat-reach-row",children:[n.jsx("dt",{children:U}),n.jsx("dd",{children:ie})]},U))}):null]})]}):null]})}function cV(e){const t=[];let s=null,r=0;for(const i of e){const a=/^@@ -\d+,\d+ \+(\d+),(\d+) @@$/.exec(i);if(a){const c=Number(a[2])===0?Number(a[1])+1:Number(a[1]);t.length>0&&c-1>r&&t.push({kind:"gap",count:c-1-r}),s=c;continue}const l=i.startsWith("+ ")?"add":i.startsWith("- ")?"del":"ctx",o=l==="ctx"&&!i.startsWith(" ")?i:i.slice(2);l==="del"||s===null?t.push({kind:l,text:o,n:null}):(t.push({kind:l,text:o,n:s}),r=s,s+=1)}return t}function lN({lines:e,label:t}){return n.jsx("div",{className:"cat-diff",role:"region","aria-label":t,children:cV(e).map((s,r)=>s.kind==="gap"?n.jsxs("div",{className:"cat-diff-line","data-kind":"gap",children:[n.jsx("span",{className:"cat-diff-n","aria-hidden":"true"}),n.jsx("span",{className:"cat-diff-k","aria-hidden":"true"}),n.jsxs("span",{children:["⋯ ",s.count," ",s.count===1?"line":"lines"]})]},r):n.jsxs("div",{className:"cat-diff-line","data-kind":s.kind,children:[n.jsx("span",{className:"cat-diff-n","aria-hidden":"true",children:s.n??""}),n.jsx("span",{className:"cat-diff-k","aria-hidden":"true",children:s.kind==="add"?"+":s.kind==="del"?"-":" "}),n.jsx("span",{children:s.text||" "})]},r))})}function B$({entry:e,agentId:t,onClose:s,onUpdated:r}){const[i,a]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(!1),[h,f]=d.useState(!1),[m,p]=d.useState(!1);d.useEffect(()=>{let w=!1;return $.catalogueUpdatePlan(e.name,t).then(y=>{w||a(y)}).catch(y=>{w||o(xl(y))}),()=>{w=!0}},[e.name,t]);const g=Rl((i==null?void 0:i.version)??e.version),v=w=>{i&&(f(!0),o(null),$.catalogueUpdate(e.name,t,i.plan,w).then(()=>{p(!0),r==null||r()}).catch(y=>{o(xl(y)),$.catalogueUpdatePlan(e.name,t).then(a).catch(()=>{})}).finally(()=>f(!1)))};if(m)return n.jsx(Ye,{title:n.jsxs(Ir,{entry:e,children:[e.title," ",g]}),onClose:s,foot:n.jsx(ae,{align:"end",children:n.jsx(A,{variant:"accent",onClick:s,children:"Done"})}),children:n.jsx(V,{tone:"good",title:`${e.title} is on ${g}.`,role:"status",children:i!=null&&i.edited?"Your version is in the trash folder if you want any of it back.":"Your picks and missions are as they were."})});if(!i)return n.jsxs(Ye,{title:n.jsxs(Ir,{entry:e,children:["Update ",e.title]}),onClose:s,children:[n.jsx(re,{message:l}),l?null:n.jsx(pe,{children:"Reading what changed…"})]});const b=i.personaDiff.filter(w=>w.startsWith("+ ")).length,j=i.personaDiff.filter(w=>w.startsWith("- ")).length;if(i.edited)return n.jsxs(Ye,{title:n.jsxs(Ir,{entry:e,children:[e.title," ",g," is out"]}),onClose:s,foot:n.jsxs(ae,{children:[c?null:n.jsx(A,{variant:"ghost",onClick:()=>u(!0),children:"See what changed"}),n.jsx(ht,{}),n.jsx(A,{variant:"ghost",onClick:s,children:"Keep mine"}),n.jsx(A,{variant:"danger",disabled:h,onClick:()=>v(!0),children:"Replace my changes"})]}),children:[n.jsx(V,{tone:"accent",children:i.replacesOwn&&i.replacesOwn.length>0?`${g} brings ${i.replacesOwn.length===1?"a skill":"skills"} named like your own (${Kt(i.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.`:i.via?`${e.title} replaces your @${i.handle}. You’ve changed @${i.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.`}),n.jsx(re,{message:l}),n.jsxs(le,{divided:!0,gap:"lg",children:[n.jsxs("div",{className:"cat-block",children:[n.jsxs("h3",{className:"cat-block-title",children:["New in ",g]}),n.jsx("p",{className:"cat-prose",children:i.changes})]}),n.jsxs("div",{className:"cat-block",children:[n.jsxs("h3",{className:"cat-block-title",children:["Your file and ",g," ",n.jsx("button",{type:"button",className:"cat-block-aside plugins-link",onClick:()=>u(!c),children:c?"Hide":"See what changed"})]}),c?n.jsxs(n.Fragment,{children:[n.jsx(lN,{lines:i.personaDiff,label:`Your ${e.title} against ${g}`}),n.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."]})]}):n.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=i.added.length>0?`New: ${Kt(jh(i.added.map(w=>w.name),wh(i.added)).map(([w])=>w))}. The approval lists each tool.`:"No new tools. It reaches what it reaches today.";return n.jsxs(Ye,{title:n.jsxs(Ir,{entry:e,children:["Update ",e.title," to ",g]}),onClose:s,foot:n.jsxs(ae,{children:[n.jsx("span",{className:"plugins-foot-note",children:"Your picks and handle stay."}),n.jsx(ht,{}),n.jsx(A,{variant:"ghost",onClick:s,children:"Not now"}),n.jsxs(A,{variant:"accent",disabled:h,onClick:()=>v(!1),children:["Update ",e.title]})]}),children:[n.jsx("p",{className:"cat-lede",children:i.changes}),n.jsx(re,{message:l}),n.jsxs(le,{divided:!0,gap:"lg",children:[n.jsxs("div",{className:"cat-block",children:[n.jsx("h3",{className:"cat-block-title",children:"What changes in its file"}),i.personaDiff.length>0?n.jsx(lN,{lines:i.personaDiff,label:i.via?`@${i.handle} against ${e.title} ${g}`:`${e.title} ${Rl(i.fromVersion)} against ${g}`}):n.jsx("p",{className:"cat-prose",children:"Its persona stays word for word."})]}),n.jsxs("div",{className:"cat-block",children:[n.jsx("h3",{className:"cat-block-title",children:"What it can reach"}),n.jsxs("p",{className:"cat-prose",children:[x,i.removed.length>0?` No longer: ${i.removed.join(", ")}.`:""]})]}),n.jsxs("div",{className:"cat-block",children:[n.jsx("h3",{className:"cat-block-title",children:"Missions"}),n.jsxs("p",{className:"cat-prose",children:[i.missionsAdded.length>0?`${Kt(i.missionsAdded.map(w=>w.name))} added, off until you turn ${i.missionsAdded.length===1?"it":"them"} on.`:"None added.",(i.missionsChanged??[]).length>0?" Their prompt, hour and switch stay yours.":" Yours stay as they are."]}),(i.missionsChanged??[]).map(w=>n.jsxs("p",{className:"cat-prose",children:[w.name,": new settings — ",w.words,"."]},w.id))]}),i.retires&&i.retires.length>0?n.jsxs("div",{className:"cat-block",children:[n.jsx("h3",{className:"cat-block-title",children:"Skills"}),n.jsxs("p",{className:"cat-prose",children:[g," no longer has ",Kt(i.retires),"; ",i.retires.length===1?"it goes":"they go"," to the trash folder."]})]}):null]})]})}function _i(e){if(e.state==="unavailable")return"unavailable";const t=e.installed;return e.state!=="installed"||!t?"ready":t.drift==="update"?"update":t.drift==="edited-update"?"edited":"added"}function Ew(){const e=de(()=>$.plugins(),[]);return d.useMemo(()=>{var t;return new Set((((t=e.data)==null?void 0:t.installed)??[]).filter(s=>s.loaded&&s.enabled!==!1).map(s=>s.name))},[e.data])}function Aw(){return n.jsx(ce,{name:"check",size:14})}function uV({entry:e,loaded:t,mailbox:s}){const r=_i(e);if(r==="unavailable")return n.jsx("span",{className:"cat-chips",children:n.jsx("span",{className:"cat-chip","data-need":"true",children:"Needs a newer buddi"})});const i=e.missing??[];if(i.length>0)return n.jsx("span",{className:"cat-chips",children:n.jsxs("span",{className:"cat-chip","data-need":"true",children:["Needs ",Kt(i.map(F$))]})});if(r!=="ready")return null;const a=rV(e,t,s);if(a.length===0)return null;const l=`Uses ${Kt(a)}`;return n.jsx("span",{className:"cat-uses",title:l,children:l})}function dV({entry:e,onAdd:t,onUpdate:s}){const r=_i(e),i=a=>l=>{l.stopPropagation(),a()};return r==="added"?n.jsxs("span",{className:"cat-added",children:[n.jsx(Aw,{}),"Added"]}):r==="update"?n.jsx(A,{size:"sm",onClick:i(s),"aria-label":`Update ${e.title}`,children:"Update"}):r==="edited"?n.jsx(A,{size:"sm",onClick:i(s),children:"See what changed"}):r==="unavailable"?null:n.jsx(A,{size:"sm",variant:"accent",onClick:i(t),"aria-label":`Add ${e.title}`,children:"Add"})}function hV({entry:e}){var i,a,l,o;const t=_i(e),s=Rl(e.version),r=(i=e.installed)==null?void 0:i.handle;return(a=e.installed)!=null&&a.via&&t==="update"?n.jsxs("p",{className:"cat-note",children:["Replaces your @",r,": it keeps its handle, chats, memory and missions."]}):(l=e.installed)!=null&&l.via&&t==="edited"?n.jsxs("p",{className:"cat-note",children:["Replaces your @",r,", which you’ve changed."]}):t==="update"?n.jsxs("p",{className:"cat-note",children:[s," is out: ",e.changes.charAt(0).toLowerCase()+e.changes.slice(1)]}):t==="edited"?n.jsxs("p",{className:"cat-note",children:["You’ve changed ",e.title,"; ",s," is out."]}):t==="added"?n.jsxs("p",{className:"cat-note","data-quiet":"true",children:["On your team as @",(o=e.installed)==null?void 0:o.handle]}):t==="unavailable"?n.jsx("p",{className:"cat-note","data-quiet":"true",children:e.reason}):null}function W$({entry:e,loaded:t,mailbox:s,onOpen:r,onAdd:i,onUpdate:a}){return n.jsx("div",{className:"cat-card","data-state":_i(e),"data-testid":`cat-card-${e.name}`,children:n.jsxs(ds,{onClick:r,label:`${e.title}: details`,children:[n.jsxs("div",{className:"cat-card-head",children:[n.jsx(Xl,{entry:e,size:"lg"}),n.jsxs("div",{className:"cat-card-name",children:[n.jsx("h3",{className:"ui-card-title",children:e.title}),n.jsx("div",{className:"cat-card-kind",children:Sw(e.category)})]})]}),n.jsx("p",{className:"cat-pitch",children:e.pitch}),n.jsx(hV,{entry:e}),n.jsxs("div",{className:"cat-card-foot",children:[n.jsx(uV,{entry:e,loaded:t,mailbox:s}),n.jsx(ht,{}),n.jsx(dV,{entry:e,onAdd:i,onUpdate:a})]})]})})}function fV({row:e,agents:t,navigate:s,pages:r}){const i=dw(e.plugin,e.agent,()=>window.dispatchEvent(new Event(gr))),a=i.created??(e.state==="installed"?{id:e.agent,handle:e.handle,name:e.name}:null),l=r?nT(e.plugin,r.all):Mf(e.plugin);return n.jsx("div",{className:"cat-card","data-state":a?"added":"ready","data-testid":`cat-card-${e.agent}`,children:n.jsxs(ds,{onClick:a?()=>s(Et(a.id)):void 0,label:a?`Open @${a.handle}`:void 0,children:[n.jsxs("div",{className:"cat-card-head",children:[n.jsx("span",{className:"cat-face","data-size":"lg",children:n.jsx(Sn,{id:e.agent,name:e.name,size:"lg",face:t.find(o=>o.id===e.agent)})}),n.jsxs("div",{className:"cat-card-name",children:[n.jsx("h3",{className:"ui-card-title",children:e.name}),n.jsxs("div",{className:"cat-card-kind",children:["From ",l]})]})]}),n.jsx("p",{className:"cat-pitch",children:e.text}),a?n.jsxs("p",{className:"cat-note","data-quiet":"true",children:["On your team as @",a.handle]}):null,n.jsxs("div",{className:"cat-card-foot",children:[n.jsx(re,{message:i.failure}),n.jsx(ht,{}),a?n.jsxs("span",{className:"cat-added",children:[n.jsx(Aw,{}),"Added"]}):n.jsx(A,{size:"sm",variant:"accent",disabled:i.busy,onClick:o=>{o.stopPropagation(),i.accept()},"aria-label":`Add ${e.name}`,children:"Add"})]})]})})}function mV({n:e=6}){return n.jsx("div",{className:"cat-grid","aria-busy":"true","aria-label":"Loading the catalogue","data-testid":"cat-loading",children:Array.from({length:e},(t,s)=>n.jsxs("div",{className:"ui-card cat-skel",children:[n.jsxs("div",{className:"cat-card-head",children:[n.jsx("i",{className:"cat-skel-face"}),n.jsxs("span",{className:"cat-card-name",children:[n.jsx("i",{className:"cat-skel-line","data-w":"40"}),n.jsx("i",{className:"cat-skel-line","data-w":"20"})]})]}),n.jsx("i",{className:"cat-skel-line","data-w":"90"}),n.jsx("i",{className:"cat-skel-line","data-w":"70"})]},s))})}function pV(e,t,s){const r=e.find(i=>i.roles.includes(Jc));r&&(s.trim()&&vj(r.id,`I'd like a teammate for this: ${s.trim()}`),t(st(r.id)))}function gV({sheet:e,view:t,navigate:s,onClose:r,onChanged:i}){const a=e?t==null?void 0:t.agents.find(l=>l.name===e.name):void 0;return!e||!a?null:e.kind==="update"&&a.installed?n.jsx(B$,{entry:a,agentId:a.installed.agentId,onClose:r,onUpdated:i}):n.jsx(U$,{entry:a,navigate:s,onClose:r,onAdded:i})}const xV=[{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 vV(e,t){return[e.title,e.pitch,e.about,e.description,Sw(e.category)].some(s=>s.toLowerCase().includes(t))}function jV({name:e,agents:t,navigate:s,pluginPages:r}){const[i,a]=d.useState(0),l=de(()=>$.catalogue(i>0),[i]),o=Ew(),[c,u]=d.useState(""),[h,f]=d.useState("all"),[m,p]=d.useState(null),g=l.data,v=()=>{l.reload(),window.dispatchEvent(new Event(gr))},b=()=>a(E=>E+1),j=n.jsx(gV,{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,w=d.useRef(!1);if(d.useEffect(()=>{w.current||!x||!M4(window.location.hash,x.name)||(w.current=!0,_i(x)==="ready"&&p({kind:"install",name:x.name}))},[x]),e&&g&&!g.unavailable&&x)return n.jsxs(n.Fragment,{children:[n.jsx(bV,{entry:x,loaded:o,agents:t,navigate:s,onAdd:()=>p({kind:"install",name:x.name}),onUpdate:()=>p({kind:"update",name:x.name})}),j]});const y=c.trim().toLowerCase(),N=((g==null?void 0:g.agents)??[]).filter(E=>(h==="all"||E.category===h)&&(!y||vV(E,y))),S=((g==null?void 0:g.fromPlugins)??[]).filter(E=>h==="all"&&(!y||[E.name,E.text,E.description].some(R=>R.toLowerCase().includes(y)))),C=E=>()=>s(E);return n.jsxs(Gj,{children:[n.jsx(Al,{before:n.jsx(ah,{inline:!0,items:[{label:"Agents",href:pt,onClick:C(pt)}]}),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?n.jsxs(V,{tone:"warning",children:["The catalogue lists no teammate called “",e,"”. Here is everyone it does list."]}):null,n.jsxs("div",{className:"cat-bar",children:[n.jsxs("div",{className:"cat-search",children:[n.jsx(ce,{name:"search",size:16}),n.jsx(Sf,{label:"Search teammates",value:c,placeholder:"Search: meals, money, a language…",onChange:u})]}),n.jsx("div",{className:"cat-cats",children:n.jsx(HA,{label:"Category",options:xV,value:h,onChange:f})})]}),g&&!g.unavailable?g.stale?n.jsxs("p",{className:"plugins-quiet","data-testid":"cat-stale",children:[n.jsx(ce,{name:"globe",size:14}),"From the list kept ",g.fetchedAt?wV(g.fetchedAt):"earlier",": withbuddi.com didn’t answer just now."," ",n.jsx("button",{type:"button",className:"plugins-link",onClick:b,children:"Try again"})]}):n.jsxs("p",{className:"plugins-quiet",children:[n.jsx(ce,{name:"globe",size:14}),"Opening this page fetched the list from withbuddi.com. Nothing else leaves."]}):null,l.error&&!g?n.jsx(pe,{warm:!0,title:"The catalogue didn’t load",action:n.jsx(A,{variant:"accent",size:"sm",onClick:b,children:"Try again"}),children:l.error}):g?g.unavailable?n.jsx(pe,{warm:!0,title:"The catalogue needs withbuddi.com",action:n.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?n.jsxs("div",{className:"cat-grid","data-testid":"cat-grid",children:[N.map(E=>n.jsx(W$,{entry:E,loaded:o,mailbox:g.mailbox,onOpen:()=>s(Ht(E.name)),onAdd:()=>p({kind:"install",name:E.name}),onUpdate:()=>p({kind:"update",name:E.name})},E.name)),S.map(E=>n.jsx(fV,{row:E,agents:t,navigate:s,pages:r},`${E.plugin}/${E.agent}`))]}):n.jsx(pe,{warm:!0,title:"No teammate for that yet",action:n.jsxs("span",{className:"cat-empty-acts",children:[n.jsx(A,{size:"sm",variant:"ghost",onClick:()=>{u(""),f("all")},children:"Show all"}),n.jsx(A,{size:"sm",variant:"accent",onClick:()=>pV(t,s,c),children:"Ask Agent Father"})]}),children:y?n.jsxs(n.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."}):n.jsx(mV,{}),g&&!g.unavailable&&g.delisted.length>0?n.jsx(qe,{title:"No longer in the catalogue",children:n.jsx("ul",{className:"cat-plugins","data-testid":"cat-delisted",children:g.delisted.map(E=>n.jsxs("li",{children:[n.jsx(cn,{agents:t,id:E.agentId,size:"sm"}),n.jsxs("span",{className:"cat-plugin-text",children:[n.jsx("a",{className:"cat-plugin-name",href:Et(E.agentId),onClick:R=>{R.preventDefault(),s(Et(E.agentId))},children:E.name??`@${E.handle}`}),n.jsxs("span",{className:"cat-small",children:["@",E.handle," keeps working as it is; no updates will come."]})]})]},E.agentId))})}):null,j]})}function wV(e){const t=Math.round((Date.now()-Date.parse(e))/36e5);if(!Number.isFinite(t)||t<1)return"an hour ago";if(t<24)return`${t} h ago`;const s=Math.round(t/24);return s===1?"yesterday":`${s} days ago`}function Vi({title:e,children:t}){return n.jsxs("section",{className:"cat-row",children:[n.jsx("h2",{className:"cat-row-title",children:e}),n.jsx("div",{className:"cat-row-body",children:t})]})}function yV({entry:e,loaded:t,navigate:s}){const r=new Map((e.missing??[]).map(a=>[a.name,a])),i=[...Object.keys(e.requires).map(a=>({name:a,needed:!0,need:!1})),...Object.keys(e.optional).map(a=>({name:a,needed:!1,need:!1})),...e.needs.map(a=>({name:a.replace(/\?$/,""),needed:!a.endsWith("?"),need:!0}))];return i.length===0?n.jsx("p",{className:"cat-small",children:"None. It works with what buddi has."}):n.jsx("ul",{className:"cat-plugins",children:i.map(({name:a,needed:l,need:o})=>{const c=r.get(a),u=c?_$(c):null,h=o?Cw(a).title:(c==null?void 0:c.kind)==="plugin"?c.title:Mf(a),f=o?l&&!c:t.has(a);return n.jsxs("li",{children:[n.jsx("span",{className:"ui-app-icon","aria-hidden":"true",children:n.jsx(ce,{name:o?a==="mailbox"?"mail":"key":"plug",size:14})}),n.jsxs("span",{className:"cat-plugin-text",children:[n.jsx("span",{className:"cat-plugin-name",children:h.charAt(0).toUpperCase()+h.slice(1)}),n.jsx("span",{className:"cat-small",children:l?"Needed":"Better with it"})]}),u?n.jsx(A,{size:"sm",onClick:()=>s(u.route),children:u.label}):c?n.jsx("span",{className:"cat-small",children:"Installed when you add it"}):f?n.jsxs("span",{className:"cat-added",children:[n.jsx(Aw,{}),o?"You have one":"Installed"]}):n.jsx("span",{className:"cat-small",children:o?"Optional":"Not installed"})]},`${o?"need":"plugin"}-${a}`)})})}function bV({entry:e,loaded:t,agents:s,navigate:r,onAdd:i,onUpdate:a}){var g,v,b,j;const l=_i(e),c=(g=e.installed)==null?void 0:g.agentId,u=Rl(e.version),h=(v=e.installed)!=null&&v.via?e.installed:void 0,f=x=>{c&&(x&&vj(c,x),r(st(c)))},m=jh(e.tools,wh((b=e.claims)==null?void 0:b.tools)),p=e.replaces.map(x=>lp(x.split("/")[1]??x));return n.jsxs(Gj,{children:[n.jsxs("a",{className:"cat-back",href:Ht(),onClick:x=>{x.preventDefault(),r(Ht())},children:[n.jsx(ce,{name:"chevron-left",size:12}),"Teammates"]}),n.jsxs("header",{className:"cat-hero",children:[n.jsx(Xl,{entry:e,size:"xxl"}),n.jsxs("div",{className:"cat-hero-text",children:[n.jsx("h1",{className:"cat-hero-title",children:e.title}),n.jsx("p",{className:"cat-hero-pitch",children:e.pitch}),n.jsxs("p",{className:"cat-hero-meta",children:[e.trust==="by-buddi"?n.jsx(we,{tone:"accent",children:"by buddi"}):null,n.jsx("span",{children:Sw(e.category)}),n.jsx("span",{"aria-hidden":"true",children:"·"}),n.jsx("span",{className:"mono",children:h?e.version:((j=e.installed)==null?void 0:j.version)??e.version}),e.installed?n.jsxs(n.Fragment,{children:[n.jsx("span",{"aria-hidden":"true",children:"·"}),n.jsxs("span",{children:["on your team as ",n.jsxs("span",{className:"mono",children:["@",e.installed.handle]})]})]}):null]})]}),n.jsx("div",{className:"cat-hero-act",children:l==="ready"?n.jsxs(A,{variant:"accent",onClick:i,children:["Add ",e.title]}):l==="update"?n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",onClick:()=>f(),children:"Open chat"}),n.jsx(A,{variant:"accent",onClick:a,children:h?`Update @${h.handle} to ${e.title}`:`Update to ${u}`})]}):l==="edited"?n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",onClick:()=>f(),children:"Open chat"}),n.jsx(A,{onClick:a,children:"See what changed"})]}):l==="unavailable"?null:n.jsx(A,{variant:"accent",onClick:()=>f(),children:"Open chat"})})]}),l==="edited"&&h?n.jsxs(V,{tone:"accent",children:[e.title," replaces your @",h.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"?n.jsxs(V,{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"?n.jsx(V,{tone:"warning",children:e.reason}):null,n.jsx(qe,{flush:!0,children:n.jsxs("div",{className:"cat-rows",children:[n.jsxs(Vi,{title:"What it does",children:[n.jsx("p",{className:"cat-prose",children:e.about}),p.length>0?n.jsxs("p",{className:"cat-small",children:["Does what ",Kt(p)," did. If you have ",Kt(p)," and haven’t changed it, it’s offered as an update."]}):null]}),e.examples.length>0?n.jsxs(Vi,{title:"Ask it",children:[n.jsx("div",{className:"wb-starters",children:e.examples.map(x=>n.jsx("button",{type:"button",className:"wb-starter",disabled:!c,onClick:()=>f(x),children:x},x))}),c?null:n.jsx("p",{className:"cat-small",children:"Once it’s on your team, a tap opens a chat with it."})]}):null,n.jsx(Vi,{title:"Skills",children:e.skills.length===0?n.jsx("p",{className:"cat-small",children:"None. It works from its persona."}):n.jsxs(n.Fragment,{children:[n.jsx("ul",{className:"cat-plugins","data-testid":"cat-skills",children:e.skills.map(x=>n.jsxs("li",{children:[n.jsx("span",{className:"ui-app-icon","aria-hidden":"true",children:n.jsx(ce,{name:"files",size:14})}),n.jsxs("span",{className:"cat-plugin-text",children:[n.jsx("span",{className:"cat-plugin-name",children:lp(x.name)}),x.description?n.jsx("span",{className:"cat-small",children:x.description}):null,n.jsx(Tt,{summary:"Read it",children:n.jsx(Pt,{label:`${lp(x.name)}: the skill's text`,children:x.text})})]})]},x.name))}),n.jsxs("p",{className:"cat-small",children:["Plain text, no code."," ",c?n.jsxs(n.Fragment,{children:["Read and change them on ",n.jsx("a",{href:Et(c,"skills"),onClick:x=>{x.preventDefault(),r(Et(c,"skills"))},children:"its Skills tab"}),"."]}):"Once it’s on your team they’re files you can read and change."]})]})}),n.jsxs(Vi,{title:"What it can reach",children:[n.jsx("dl",{className:"cat-reach",children:m.map(([x,w])=>n.jsxs("div",{className:"cat-reach-row",children:[n.jsx("dt",{children:x}),n.jsx("dd",{children:w})]},x))}),n.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."})]}),n.jsx(Vi,{title:"Missions",children:e.missions.length>0?n.jsx("ul",{className:"cat-missions",children:e.missions.map(x=>n.jsxs("li",{children:[n.jsx("span",{className:"cat-mission-name",children:x.name}),n.jsx("span",{className:"cat-mission-when",children:x.when}),n.jsx("span",{className:"cat-off",children:"off until you turn it on"})]},x.id))}):n.jsx("p",{className:"cat-small",children:"None. It works when you ask."})}),n.jsx(Vi,{title:"Plugins",children:n.jsx(yV,{entry:e,loaded:t,navigate:r})}),n.jsxs(Vi,{title:"Version",children:[n.jsxs("p",{className:"cat-prose",children:[n.jsx("span",{className:"mono",children:e.version})," · ",e.changes]}),n.jsx("p",{className:"cat-small",children:"Reviewed in withbuddi/buddi-market. An update always asks you, and never touches a file you changed."})]})]})})]})}function kV(e){var r,i;const t=de(()=>$.agents(),[e]),s=(i=(r=t.data)==null?void 0:r.catalogue)==null?void 0:i[e];return{entry:s?{...s,agentId:e}:void 0,reload:t.reload}}function NV({entry:e,navigate:t,onUpdated:s}){const[r,i]=d.useState(null),[a,l]=d.useState(null),[o,c]=d.useState(!1),u=e.delisted?null:e.drift==="update"?"update":e.drift==="edited-update"?"edited":null,h=()=>{c(!0),l(null),$.catalogue().then(f=>{const m=f.agents.find(p=>p.name===e.package);m?i(m):l(f.unavailable??`The catalogue no longer lists ${e.title}.`)}).catch(f=>l(f instanceof ve?f.message:String(f))).finally(()=>c(!1))};return n.jsxs(n.Fragment,{children:[n.jsxs("p",{className:"agent-catalogue-line","data-testid":"agent-catalogue-line","data-delisted":e.delisted?"true":void 0,children:[e.delisted?n.jsx("span",{children:"No longer in the catalogue"}):n.jsx("a",{href:Ht(e.package),onClick:f=>{f.preventDefault(),t(Ht(e.package))},children:"From the catalogue"}),n.jsx("span",{"aria-hidden":"true",children:" · "}),n.jsxs("span",{children:[e.title," ",e.via?`(was ${e.via.split("/")[1]??e.via})`:Rl(e.version)]}),e.delisted?n.jsx("span",{className:"muted",children:" · it keeps working; no updates will come"}):null,u?n.jsx(A,{size:"sm",variant:u==="update"?"accent":void 0,disabled:o,onClick:h,children:u==="update"&&e.latest?`Update to ${Rl(e.latest)}`:u==="update"?"Update":"See what changed"}):null]}),a?n.jsx(re,{message:a}):null,r?n.jsx(B$,{entry:r,agentId:e.agentId,onClose:()=>i(null),onUpdated:s}):null]})}function SV(e){return typeof e=="string"?e:e.name??e.id??"a mission"}function CV({agentId:e,name:t,navigate:s}){const[r,i]=d.useState(!1),[a,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(!1),[f,m]=d.useState(null),p=()=>{i(!1),m(null),s(pt)},g=y=>y instanceof ve?y.message:String(y),v=()=>{i(!0),c(null),l(null),$.agentRemovePreview(e).then(l).catch(y=>c(g(y)))},b=()=>{h(!0),c(null),$.removeAgent(e).then(y=>{var N;window.dispatchEvent(new Event(gr));const k=(N=y.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}i(!1),s(pt)}).catch(y=>c(g(y))).finally(()=>h(!1))},j=(a==null?void 0:a.pausesMissions.map(SV))??[],x=(a==null?void 0:a.unusedPlugins)??[],w=((a==null?void 0:a.handedWorkBy)??[]).map(y=>`@${y}`);return n.jsxs(qe,{children:[n.jsxs(ae,{children:[n.jsxs("div",{className:"agent-remove-text",children:[n.jsx("strong",{children:"Remove from team"}),n.jsx("span",{className:"muted",children:"Its file goes to the trash folder; what it remembers and its conversations stay."})]}),n.jsxs(A,{variant:"danger-ghost",onClick:v,children:["Remove ",t,"…"]})]}),r&&f?n.jsx(Dt,{title:`${t} is off your team`,onClose:p,foot:n.jsx(A,{variant:"accent",onClick:p,children:"Done"}),children:n.jsxs(V,{tone:"warning",title:"Cleanup is incomplete",role:"status",children:["The delegate list of ",Kt(f.map(y=>`@${y}`))," could not be updated and still names it. That entry reaches nobody; edit the list to remove it."]})}):r?n.jsxs(Dt,{title:`Remove ${t} from your team?`,onClose:()=>i(!1),foot:n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",onClick:()=>i(!1),children:"Cancel"}),n.jsx(A,{variant:"danger",disabled:u||!a,onClick:b,children:"Remove from team"})]}),children:[n.jsx(re,{message:o}),a?n.jsxs("div",{className:"ui-stack","data-testid":"remove-preview",children:[n.jsxs("p",{children:["@",a.handle,"’s folder moves to the trash folder, so it can be brought back by hand."]}),j.length>0?n.jsxs("p",{children:["Its ",j.length===1?"mission":"missions"," ",Kt(j)," ",j.length===1?"is":"are"," paused."]}):null,w.length>0?n.jsxs("p",{children:[Kt(w)," will stop handing work to it."]}):null,x.length>0?n.jsxs("p",{children:["No other agent uses ",Kt(x.map(Mf)),"; it stays installed."," ",n.jsxs("a",{href:Pe("plugins"),onClick:y=>{y.preventDefault(),i(!1),s(Pe("plugins"))},children:["Remove ",x.length===1?"it":"them"," in Settings → Plugins"]}),"."]}):null]}):o?null:n.jsx("p",{className:"muted",children:"Reading what it would change…"})]}):null]})}const EV=["fact","observation","todo"];function H$({embedded:e,agents:t,timezone:s,agentId:r}){const{data:i,error:a,reload:l}=de(()=>$.memory(r),[r],3e4),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(null),p=y=>{var k;return y==="shared"?"Everyone":((k=t.find(N=>N.id===y))==null?void 0:k.name)??y},g=async y=>{m(null);try{await y,l()}catch(k){m(k instanceof ve?k.message:String(k))}},v={nameOf:p,timezone:s,onChangePreference:y=>c({key:y.key,scope:y.scope}),onForgetPreference:y=>void g($.forgetPreference({key:y.key,scope:y.scope})),onEditNote:y=>h(y),onForgetNote:y=>void g($.forgetNote(y.id))},b=r?p(r):"",j=r&&i?{preferences:i.preferences.filter(y=>y.scope===r),notes:i.notes.filter(y=>y.scope===r)}:null,x=r&&i?{preferences:i.preferences.filter(y=>y.scope==="shared"),notes:i.notes.filter(y=>y.scope==="shared")}:null,w=n.jsx(A,{variant:"accent",size:"sm",onClick:()=>c({key:"",scope:r??"shared"}),children:"Add a preference"});return n.jsxs(On,{embedded:e,title:"Memory",lede:"What your agents have kept about you. Correct anything here; they see the change on their next turn.",children:[n.jsx(re,{message:a??f}),j&&x?n.jsxs(le,{gap:"lg",children:[n.jsx(ue,{title:"Preferences",aside:`what you told ${b} alone`,actions:w,panel:!0,flush:!0,children:n.jsx(up,{preferences:j.preferences,empty:`Nothing stated to ${b} alone yet.`,...v})}),n.jsx(ue,{title:"Notes",aside:`what ${b} wrote down for itself`,panel:!0,flush:!0,children:n.jsx(dp,{notes:j.notes,empty:`${b} has kept no private notes yet.`,...v})}),n.jsx(Tt,{summary:`Shared with every agent, which ${b} also reads · ${x.preferences.length} preferences, ${x.notes.length} notes`,children:n.jsxs(le,{gap:"lg",children:[n.jsx(ue,{title:"Shared preferences",panel:!0,flush:!0,children:n.jsx(up,{preferences:x.preferences,empty:"No shared preferences.",...v})}),n.jsx(ue,{title:"Shared notes",panel:!0,flush:!0,children:n.jsx(dp,{notes:x.notes,empty:"No shared notes.",...v})})]})})]}):n.jsxs(le,{gap:"lg",children:[n.jsx(ue,{title:"Preferences",aside:"what you said you want, one current value each",actions:w,panel:!0,flush:!0,children:i?n.jsx(up,{preferences:i.preferences,empty:'Nothing stated yet. Tell any agent "from now on…" or add one here.',...v}):n.jsx(pe,{children:"Loading…"})}),n.jsx(ue,{title:"Notes",aside:"what an agent wrote down, with who wrote it",panel:!0,flush:!0,children:i?n.jsx(dp,{notes:i.notes,empty:"No notes yet. An agent writes one when you state something durable about your life.",...v}):n.jsx(pe,{children:"Loading…"})})]}),o?n.jsx(AV,{agents:t,existing:(i==null?void 0:i.preferences)??[],initial:o,onClose:()=>c(null),onSave:async y=>{await g((async()=>{await $.setPreference(y),o.key===y.key&&o.scope!==y.scope&&await $.forgetPreference({key:o.key,scope:o.scope})})()),c(null)}}):null,u?n.jsx(TV,{note:u,agents:t,onClose:()=>h(null),onSave:y=>g($.updateNote(u.id,y)).then(()=>h(null))}):null]})}function up({preferences:e,empty:t,nameOf:s,onChangePreference:r,onForgetPreference:i}){return e.length===0?n.jsx(pe,{children:t}):n.jsxs(kr,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Preference"}),n.jsx("th",{children:"Value"}),n.jsx("th",{children:"Who sees it"}),n.jsx("th",{className:"num",children:"Since"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:e.map(a=>n.jsxs("tr",{children:[n.jsx("td",{className:"mono",children:a.key}),n.jsx("td",{children:a.value}),n.jsx("td",{children:n.jsx(K$,{scope:a.scope,name:s(a.scope)})}),n.jsxs("td",{className:"num muted",title:a.updatedAt??"",children:[a.updatedAt?Fe(a.updatedAt,Date.now()):"",a.revision>1?` · rev ${a.revision}`:""]}),n.jsx("td",{className:"num",children:n.jsxs(ae,{align:"end",children:[n.jsx(A,{size:"sm",onClick:()=>r(a),title:"Store a new value for this key",children:"Change"}),n.jsx(A,{size:"sm",variant:"ghost",onClick:()=>i(a),children:"Forget"})]})})]},`${a.scope}:${a.key}`))})]})}function dp({notes:e,empty:t,nameOf:s,timezone:r,onEditNote:i,onForgetNote:a}){return e.length===0?n.jsx(pe,{children:t}):n.jsxs(kr,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Note"}),n.jsx("th",{children:"Kind"}),n.jsx("th",{children:"Who sees it"}),n.jsx("th",{children:"Written by"}),n.jsx("th",{className:"num",children:"When"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:e.map(l=>n.jsxs("tr",{children:[n.jsx("td",{className:"memory-note",children:l.content}),n.jsx("td",{children:n.jsx(we,{tone:l.kind==="todo"?"warning":l.kind==="fact"?"good":void 0,children:l.kind})}),n.jsx("td",{children:n.jsx(K$,{scope:l.scope,name:s(l.scope)})}),n.jsx("td",{className:"muted",children:l.createdByAgent?s(l.createdByAgent):""}),n.jsxs("td",{className:"num muted",title:l.createdAt??"",children:[l.createdAt?Fe(l.createdAt,Date.now()):"",l.expiresAt?n.jsxs("span",{className:"memory-expires",children:[" · until ",yr(new Date(l.expiresAt),r,{year:!0,compact:!0})]}):null]}),n.jsx("td",{className:"num",children:n.jsxs(ae,{align:"end",children:[n.jsx(A,{size:"sm",onClick:()=>i(l),children:"Edit"}),n.jsx(A,{size:"sm",variant:"ghost",onClick:()=>a(l),children:"Forget"})]})})]},l.id))})]})}function K$({scope:e,name:t}){return n.jsx(we,{tone:e==="shared"?"accent":void 0,title:e==="shared"?"Every agent reads this":`Only ${t} reads this`,children:t})}function V$({value:e,agents:t,onChange:s}){return n.jsxs("select",{value:e,onChange:r=>s(r.target.value),children:[n.jsx("option",{value:"shared",children:"Everyone"}),t.map(r=>n.jsxs("option",{value:r.id,children:["Only ",r.name]},r.id))]})}function AV({agents:e,existing:t,initial:s,onClose:r,onSave:i}){const a=t.find(x=>x.key===s.key&&x.scope===s.scope),[l,o]=d.useState(s.key),[c,u]=d.useState((a==null?void 0:a.value)??""),[h,f]=d.useState(s.scope),[m,p]=d.useState(!1),g=l.trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),v=t.find(x=>x.key===g&&x.scope===h),b=!a||g!==a.key||c.trim()!==a.value||h!==a.scope,j=g!==""&&c.trim()!==""&&b;return n.jsx(Ye,{title:"A preference",onClose:r,children:n.jsxs(le,{children:[n.jsx(V,{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.'}),n.jsx(oe,{label:"Key",hint:g&&g!==l?`Stored as ${g}`:"Short and stable, like reporting_currency or tone.",children:n.jsx("input",{value:l,autoFocus:s.key==="",onChange:x=>o(x.target.value),placeholder:"reporting_currency"})}),n.jsx(oe,{label:"Value",children:n.jsx("textarea",{rows:3,value:c,maxLength:2e3,autoFocus:s.key!=="",onChange:x=>u(x.target.value),placeholder:"EUR"})}),n.jsx(oe,{label:"Who should know",hint:"Shared reaches every agent. Private stays with one.",children:n.jsx(V$,{value:h,agents:e,onChange:f})}),v&&v!==a?n.jsxs(V,{tone:"warning",children:['This replaces the value already stored for this key here, "',v.value,'" (revision ',v.revision,")."]}):null,a&&h!==a.scope?n.jsxs(V,{children:["It moves: the copy for ",a.scope==="shared"?"everyone":"that agent"," is retired and this one takes over."]}):null,n.jsxs(ae,{align:"end",children:[n.jsx(A,{onClick:r,children:"Cancel"}),n.jsx(A,{variant:"accent",disabled:!j||m,onClick:()=>{p(!0),i({key:g,value:c.trim(),scope:h}).finally(()=>p(!1))},children:a?"Save change":"Save"})]})]})})}function TV({note:e,agents:t,onClose:s,onSave:r}){var p;const[i,a]=d.useState(e.content),[l,o]=d.useState(e.scope),[c,u]=d.useState(e.kind),[h,f]=d.useState(!1),m=i.trim()!==e.content||l!==e.scope||c!==e.kind;return n.jsx(Ye,{title:"A note",onClose:s,children:n.jsxs(le,{children:[n.jsx(oe,{label:"What it says",hint:"One sentence that makes sense months from now, on its own.",children:n.jsx("textarea",{rows:4,value:i,maxLength:2e3,autoFocus:!0,onChange:g=>a(g.target.value)})}),n.jsxs(Hs,{children:[n.jsx(oe,{label:"Kind",children:n.jsx("select",{value:c,onChange:g=>u(g.target.value),children:EV.map(g=>n.jsx("option",{value:g,children:g},g))})}),n.jsx(oe,{label:"Who sees it",children:n.jsx(V$,{value:l,agents:t,onChange:o})})]}),e.createdByAgent?n.jsxs("p",{className:"muted",children:["Written by ",((p=t.find(g=>g.id===e.createdByAgent))==null?void 0:p.name)??e.createdByAgent,e.createdAt?`, ${Fe(e.createdAt,Date.now())}`:"",". Editing keeps that record."]}):null,n.jsxs(ae,{align:"end",children:[n.jsx(A,{onClick:s,children:"Cancel"}),n.jsx(A,{variant:"accent",disabled:!m||i.trim()===""||h,onClick:()=>{f(!0);const g={};i.trim()!==e.content&&(g.content=i.trim()),l!==e.scope&&(g.scope=l),c!==e.kind&&(g.kind=c),r(g).finally(()=>f(!1))},children:"Save"})]})]})})}const Ba=e=>`/skills/${encodeURIComponent(e)}`,Bn={list:()=>je("/skills"),detail:e=>je(Ba(e)),downloadUrl:e=>`/api${Ba(e)}/download`,create:e=>te("/skills",e),saveText:(e,t)=>te(`${Ba(e)}/text`,{text:t}),grant:(e,t)=>te(`${Ba(e)}/grants`,t),trust:e=>te(`${Ba(e)}/trust`),remove:e=>ar(Ba(e))};function $V(e){return`${pt}?tab=skills`}function RV(e){var s;const t=(s=/[?&]skill=([^&]+)/.exec(e))==null?void 0:s[1];if(!t)return null;try{return decodeURIComponent(t)}catch{return null}}function G$(e){const t=document.createElement("a");t.href=Bn.downloadUrl(e),t.download="",document.body.appendChild(t),t.click(),t.remove()}const Tw=[{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 $w(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function zr(e,t){var s;return((s=e.find(r=>r.id===t))==null?void 0:s.name)??t}function Rw(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Iw(e,t){const s=e.shadowedBy??[];if(!s.length)return"Every agent";const r=s.map(i=>{var a;return`@${((a=t.find(l=>l.id===i))==null?void 0:a.handle)??i}`});return`Every agent except ${$w(r)} (${s.length===1?"has its own":"each has its own"})`}function q$(e,t){return e.holders.some(s=>s.agent===t)}function IV(e,t){if(e.every)return Iw(e,t);const s=e.holders.map(r=>zr(t,r.agent));return s.length?$w(s):"No agent uses it yet"}function PV(e){return!e.every&&e.holders.length===0}function MV(){const e=new Date;return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}function oN(e){return e.slice(0,10)===MV()?"today":`on ${Bc(e,{compact:!0})}`}function Pw(e,t,s=!1){var l,o;if(e.learned){const c=e.learned.by,u=s&&e.holders.some(f=>f.agent===c),h=e.learned.keptAt?` · kept ${Fe(e.learned.keptAt)}`:"";return`${u?"":`learned by ${zr(t,c)} · `}v${e.learned.version}${e.learned.edited?" with your correction":""}${h}`}const r=e.from;if((r==null?void 0:r.kind)==="plugin")return`from ${Rw(r.plugin)} ${r.version}`;if((r==null?void 0:r.kind)==="catalogue")return`came with ${zr(t,r.agent)} ${r.version}`;if((r==null?void 0:r.kind)==="upload")return`uploaded${e.created?` ${oN(e.created)}`:""} · ${r.filename}`;const i=((l=e.created)==null?void 0:l.slice(0,10))??null,a=((o=e.updatedAt)==null?void 0:o.slice(0,10))??null;return i&&(!a||a<=i)?`written by you ${oN(i)}`:e.updatedAt?`edited by you ${Fe(e.updatedAt)}`:"written by you"}function Y$(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Mw(e,t){var s;return e.untrusted==="page"?`Untrusted: a web page was in view when ${zr(t,((s=e.learned)==null?void 0:s.by)??e.home??"")} proposed it.`:"Untrusted: it came from a file, so agents read it as outside text."}function DV(e){const t=e.file.split(/[\\/]/).pop()??e.file;return e.home?`agents/${e.home}/skills/${t}`:`skills/${t}`}function Dw(e){return e.every?[]:e.holders.map(t=>t.agent)}function OV(e,t){var s;if(e.learned){const r=zr(t,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"?`${zr(t,e.from.agent)}’s next update will ask before it replaces your change.`:null}function LV(e,t,s){var o;const r=t.stops.map(c=>zr(s,c)),i=e.learned?zr(s,e.learned.by):"";if(e.learned&&!t.every&&t.stops.length===1&&t.stops[0]===e.learned.by)return`${i} stops using it and won’t propose it again for 90 days. Earlier versions stay in its folder.`;const a=t.every?"Every agent stops using it.":r.length===0?"No agent uses it, so nothing changes.":`${$w(r)} ${r.length>1?"stop":"stops"} using it.`,l=t.then==="versions-kept"?`${i} won’t propose it again for 90 days. Earlier versions stay in its folder.`:t.then==="catalogue-asks"?`${((o=e.from)==null?void 0:o.kind)==="catalogue"?zr(s,e.from.agent):"Its teammate"}’s next update asks before bringing it back.`:"The file goes to the trash folder.";return`${a} ${l}`}function FV(e,t){var c,u;const s=t.replace(/\r\n/g,`
112
+ `),r=/^---\n([\s\S]*?)\n---\n*/.exec(s),i=h=>{var m;return(r?((m=new RegExp(`^${h}:\\s*(.*)$`,"m").exec(r[1]))==null?void 0:m[1])??"":"").trim().replace(/^(['"])(.*)\1$/,"$2")},a=r?s.slice(r[0].length):s,l=(u=(c=/^#\s+(.+)$/m.exec(a))==null?void 0:c[1])==null?void 0:u.trim(),o=i("name");return{title:l||(o?Y$(o.replace(/-/g," ")):e.replace(/\.md$/i,"")),description:i("description"),body:a}}const _V=5e4,pa=e=>e instanceof ve?e.message:String(e),zV=e=>t=>{t.stopPropagation(),e==null||e()};function UV({faces:e,navigate:t,command:s,openSkill:r}){const i=de(()=>Bn.list(),[]),[a,l]=d.useState(r?{id:r}:null),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(null),[p,g]=d.useState(null),v=d.useRef(null);d.useEffect(()=>{r&&l({id:r})},[r]),d.useEffect(()=>{var w;s&&(s.kind==="write"?c({kind:"write"}):(w=v.current)==null||w.click())},[s]);const b=w=>{var N;const y=(N=w.target.files)==null?void 0:N[0];if(w.target.value="",!y)return;if(!/\.md$/i.test(y.name)){h(`“${y.name}” isn’t a .md file. A skill is one Markdown file.`);return}if(y.size>_V){h(`“${y.name}” is over 50 KB. A skill is a short text.`);return}const k=new FileReader;k.onload=()=>{h(null),c({kind:"upload",file:{name:y.name,size:y.size,...FV(y.name,String(k.result))}})},k.readAsText(y)},j=w=>{m(null),w!==void 0&&g(w),i.reload()};return n.jsxs(n.Fragment,{children:[n.jsx("input",{ref:v,type:"file",accept:".md,text/markdown",hidden:!0,"data-testid":"skill-file",onChange:b}),u?n.jsx(V,{tone:"warning",action:n.jsx(A,{size:"sm",onClick:()=>{var w;h(null),(w=v.current)==null||w.click()},children:"Pick another file"}),children:u}):null,n.jsx(re,{message:f}),p?n.jsx(V,{tone:"good",role:"status",children:p}):null,n.jsx(BV,{view:i,onOpen:w=>l({id:w.id}),onAct:(w,y)=>x(w,y)}),n.jsx(J$,{view:i.data,faces:e,open:a,setOpen:l,dialog:o,setDialog:c,navigate:t,onChanged:j,onFailed:m}),(o==null?void 0:o.kind)==="write"&&i.data?n.jsx(cN,{agents:i.data.agents,faces:e,onClose:()=>c(null),onSaved:w=>{c(null),j(`Saved “${w.title}”.`)}}):null,(o==null?void 0:o.kind)==="upload"&&i.data?n.jsx(cN,{agents:i.data.agents,faces:e,upload:o.file,onClose:()=>c(null),onSaved:w=>{c(null),j(`Saved “${w.title}”.`)}}):null]});function x(w,y){g(null),y==="trust"?Bn.trust(w.id).then(()=>j(),k=>m(pa(k))):y==="download"?G$(w.id):y==="plugin"?t(Pe("plugins")):y==="edit"?(c(null),l({id:w.id,edit:!0})):c({kind:y,id:w.id})}}function BV({view:e,onOpen:t,onAct:s}){if(!e.data&&e.error)return n.jsx(pe,{warm:!0,title:"Couldn’t load your skills",action:n.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 n.jsx(HV,{});const{skills:r,agents:i}=e.data;return r.length===0?n.jsx(pe,{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."}):n.jsx(qe,{flush:!0,children:Tw.map(a=>{const l=r.filter(o=>o.group===a.id);return l.length?n.jsxs("section",{className:"skills-group","aria-label":a.title,children:[n.jsxs("header",{className:"skills-group-head",children:[n.jsx("h3",{className:"skills-group-title",children:a.title}),n.jsx("span",{className:"skills-group-aside",children:a.aside})]}),n.jsx(rt,{children:l.map(o=>n.jsx(WV,{row:o,agents:i,onOpen:t,onAct:s},o.id))})]},a.id):null})})}function WV({row:e,agents:t,onOpen:s,onAct:r}){var l,o,c;const i=e.untrusted?["trust","Mark as mine"]:PV(e)?["picker","Choose agents"]:null,a=IV(e,t);return n.jsx(et,{onClick:()=>s(e),label:`${e.title}: details`,lead:n.jsx(Pn,{icon:"files"}),title:e.title,sub:n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"skills-line",children:e.description}),n.jsxs("span",{className:"skills-line skills-meta",children:[a," · ",Pw(e,t,!0)]}),e.untrusted?n.jsx("span",{className:"skills-status","data-tone":"warning",children:Mw(e,t)}):null]}),side:n.jsxs("span",{className:"skills-side",children:[i?n.jsx(A,{size:"sm",onClick:zV(()=>r(e,i[0])),children:i[1]}):null,n.jsx(Ys,{label:`More for ${e.title}`,sheet:{title:e.title,sub:a},items:[{label:"Choose agents…",hint:"Give it or take it away",onSelect:()=>r(e,"picker")},e.editable?{label:"Edit text",onSelect:()=>r(e,"edit")}:null,{label:"Download",hint:".md file",onSelect:()=>r(e,"download")},((l=e.from)==null?void 0:l.kind)==="plugin"?{label:`Open ${Rw(e.from.plugin)}`,onSelect:()=>r(e,"plugin")}:null,e.deletable&&((o=e.from)==null?void 0:o.kind)!=="plugin"?"separator":null,e.deletable&&((c=e.from)==null?void 0:c.kind)!=="plugin"?{label:"Delete…",tone:"critical",onSelect:()=>r(e,"delete")}:null]})]})})}function HV(){return n.jsx(qe,{flush:!0,children:n.jsxs("div",{className:"skills-group skills-loading","aria-busy":"true","aria-label":"Loading skills",children:[n.jsx("header",{className:"skills-group-head",children:n.jsx("i",{className:"cat-skel-line","data-w":"20"})}),n.jsx(rt,{children:[0,1,2].map(e=>n.jsxs("div",{className:"ui-list-row",children:[n.jsx("span",{className:"ui-app-icon"}),n.jsxs("span",{className:"ui-list-main skills-skel",children:[n.jsx("i",{className:"cat-skel-line","data-w":"40"}),n.jsx("i",{className:"cat-skel-line","data-w":"70"})]})]},e))})]})})}function J$({view:e,faces:t,open:s,setOpen:r,dialog:i,setDialog:a,navigate:l,onChanged:o,onFailed:c}){if(!e)return null;const u=m=>e.skills.find(p=>p.id===m),h=s?u(s.id):void 0,f=i&&"id"in i?u(i.id):void 0;return n.jsxs(n.Fragment,{children:[h?n.jsx(VV,{row:h,agents:e.agents,faces:t,initialEdit:!!(s!=null&&s.edit),onClose:()=>r(null),onPicker:()=>a({kind:"picker",id:h.id}),onDelete:()=>a({kind:"delete",id:h.id}),onChanged:o,onFailed:c,navigate:l},`${h.id}-${s!=null&&s.edit?"edit":"read"}`):null,(i==null?void 0:i.kind)==="picker"&&f?n.jsx(GV,{row:f,agents:e.agents,faces:t,onCancel:()=>a(null),onSaved:()=>{a(null),o()}}):null,(i==null?void 0:i.kind)==="delete"&&f?n.jsx(YV,{row:f,agents:e.agents,onCancel:()=>a(null),onDeleted:m=>{a(null),r(null),o(m)}}):null]})}function Q$({title:e,sub:t}){return n.jsxs("span",{className:"skills-sheet-title",children:[n.jsx(Pn,{icon:"files",size:"lg"}),n.jsxs("span",{className:"skills-sheet-name",children:[n.jsx("span",{children:e}),n.jsx("span",{className:"skills-sheet-by",children:t})]})]})}function bd({title:e,aside:t,children:s}){return n.jsxs("section",{className:"skills-sec","aria-label":e,children:[n.jsxs("header",{className:"skills-sec-head",children:[n.jsx("h3",{className:"skills-sec-title",children:e}),t?n.jsx("span",{className:"skills-sec-aside",children:t}):null]}),s]})}function KV({file:e,body:t,text:s}){const[r,i]=d.useState("read");return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"skills-text-bar",children:[n.jsx(qt,{label:"Show the text as",value:r,onChange:i,options:[{value:"read",label:"Read"},{value:"source",label:"Source"}]}),n.jsx("span",{className:"skills-file mono",children:e})]}),r==="read"?n.jsx(Ws,{className:"wb-md skills-md",text:t}):n.jsx(Pt,{label:e,children:s})]})}function VV({row:e,agents:t,faces:s,initialEdit:r,onClose:i,onPicker:a,onDelete:l,onChanged:o,onFailed:c,navigate:u}){var L,F,T;const h=de(()=>Bn.detail(e.id),[e.id,e.updatedAt,e.untrusted,(L=e.learned)==null?void 0:L.version]),[f,m]=d.useState(!!r&&e.editable),[p,g]=d.useState(null),[v,b]=d.useState(!1),[j,x]=d.useState(null),w=((F=h.data)==null?void 0:F.text)??"",y=Y$(Pw(e,t)),k=OV(e,t),N=((T=e.from)==null?void 0:T.kind)==="plugin"?Rw(e.from.plugin):null,S=M=>s.find(P=>P.id===M),C=async(M,P)=>{b(!0),x(null);try{await M(),P==null||P(),o()}catch(D){x(pa(D)),c(pa(D))}finally{b(!1)}},E=M=>{C(()=>Bn.grant(e.id,{agents:Dw(e).filter(P=>P!==M)}))},R=()=>{C(()=>Bn.saveText(e.id,p??w),()=>{m(!1),g(null)})},I=(M,P)=>{var D,O;if(((D=e.learned)==null?void 0:D.by)===M)return"Proposed it";if(((O=e.from)==null?void 0:O.kind)==="catalogue"&&e.from.agent===M)return"Came with it";if(P==="home")return"In its own folder"};return n.jsxs(Ye,{size:"wide",title:n.jsx(Q$,{title:e.title,sub:y}),onClose:i,foot:f?n.jsxs(ae,{align:"end",children:[n.jsx(A,{variant:"ghost",disabled:v,onClick:()=>{m(!1),g(null)},children:"Cancel"}),n.jsx(A,{variant:"accent",disabled:v||!h.data,onClick:R,children:"Save"})]}):n.jsxs(ae,{children:[e.deletable&&!N?n.jsx(A,{variant:"danger-ghost",onClick:l,children:"Delete…"}):null,n.jsx(ht,{}),n.jsx(A,{onClick:()=>G$(e.id),children:"Download"}),e.editable?n.jsx(A,{variant:e.untrusted?void 0:"accent",onClick:()=>m(!0),children:"Edit text"}):null]}),children:[e.untrusted?n.jsxs(V,{tone:"warning",action:n.jsx(A,{size:"sm",variant:"accent",disabled:v,onClick:()=>void C(()=>Bn.trust(e.id)),children:"Mark as mine"}),children:[Mw(e,t)," Mark it as yours once you’ve read it."]}):null,n.jsx(re,{message:j}),n.jsxs("div",{className:"skills-sheet",children:[n.jsx(bd,{title:"When it’s used",children:n.jsx("p",{className:"skills-desc",children:e.description})}),n.jsx(bd,{title:"Used by",aside:n.jsx(A,{size:"sm",onClick:a,children:"Change…"}),children:e.every?n.jsx(rt,{children:n.jsx(et,{lead:n.jsx(Pn,{icon:"agents"}),title:Iw(e,t),sub:"Now, and any you add later."})}):e.holders.length?n.jsx(rt,{children:e.holders.map(M=>{const P=t.find(D=>D.id===M.agent);return n.jsx(et,{lead:n.jsx(Sn,{id:M.agent,name:(P==null?void 0:P.name)??M.agent,size:"sm",face:S(M.agent)}),title:n.jsxs(n.Fragment,{children:[(P==null?void 0:P.name)??M.agent," ",n.jsxs("span",{className:"skills-handle",children:["@",(P==null?void 0:P.handle)??M.agent]})]}),sub:I(M.agent,M.how),side:M.how==="home"?void 0:n.jsx(A,{size:"sm",variant:"ghost",disabled:v,onClick:()=>E(M.agent),"aria-label":`Take away from ${(P==null?void 0:P.name)??M.agent}`,children:"Take away"})},M.agent)})}):n.jsx("p",{className:"skills-note",children:"No agent uses it yet, so it does nothing. Choose who should."})}),n.jsxs(bd,{title:"The text",children:[h.data?f?n.jsx("textarea",{className:"skills-editor",value:p??w,onChange:M=>g(M.target.value),"aria-label":`Text of ${e.title}`,spellCheck:!1,autoFocus:!0}):n.jsx(KV,{file:DV(e),body:h.data.body,text:w}):h.error?n.jsx(re,{message:h.error}):n.jsx(pe,{children:"Reading the file…"}),f&&k?n.jsx("p",{className:"skills-note",children:k}):null,N?n.jsxs("p",{className:"skills-note",children:["Comes with ",N,", so it’s changed there. To stop an agent using it, take it away above."," ",n.jsx("a",{href:Pe("plugins"),onClick:M=>{M.preventDefault(),u(Pe("plugins"))},children:"Open Plugins"})]}):null]})]})]})}function yh({checked:e,disabled:t,onChange:s,lead:r,title:i,sub:a}){return n.jsxs("label",{className:"skills-pick-row","data-disabled":t?"true":void 0,children:[n.jsx("input",{type:"checkbox",checked:e,disabled:t,onChange:l=>s(l.target.checked)}),r,n.jsxs("span",{className:"skills-pick-text",children:[n.jsx("span",{className:"skills-pick-title",children:i}),a?n.jsx("span",{className:"skills-pick-sub",children:a}):null]})]})}function X$({label:e,value:t,onChange:s}){return n.jsxs("div",{className:"cat-search",children:[n.jsx(ce,{name:"search",size:16}),n.jsx(Sf,{label:e,value:t,placeholder:e,onChange:s})]})}function GV({row:e,agents:t,faces:s,onCancel:r,onSaved:i}){const[a,l]=d.useState(e.every),[o,c]=d.useState(Dw(e)),[u,h]=d.useState(""),[f,m]=d.useState(!1),[p,g]=d.useState(null),v=u.trim().toLowerCase(),b=t.filter(w=>!v||`${w.name} ${w.handle}`.toLowerCase().includes(v)),j=(w,y)=>c(y?[...o,w]:o.filter(k=>k!==w)),x=async()=>{m(!0),g(null);try{await Bn.grant(e.id,a?{every:!0,agents:[]}:{agents:o}),i()}catch(w){g(pa(w))}finally{m(!1)}};return n.jsx(Dt,{title:`Who uses “${e.title}”?`,onClose:r,foot:n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",onClick:r,children:"Cancel"}),n.jsx(A,{variant:"accent",disabled:f,onClick:()=>void x(),children:"Save"})]}),children:n.jsxs("div",{className:"skills-pick",children:[n.jsx(X$,{label:"Find an agent",value:u,onChange:h}),n.jsx(re,{message:p}),n.jsxs("div",{className:"skills-pick-list",children:[v||!e.shareable?null:n.jsx(yh,{checked:a,onChange:l,lead:n.jsx(Pn,{icon:"agents"}),title:"Every agent",sub:"Now, and any you add later."}),b.map(w=>{const y=e.home===w.id,k=(e.shadowedBy??[]).includes(w.id),N=y||k||!w.writable;return n.jsx(yh,{checked:!k&&(a||y||o.includes(w.id)),disabled:a||N,onChange:S=>j(w.id,S),lead:n.jsx(Sn,{id:w.id,name:w.name,size:"sm",face:s.find(S=>S.id===w.id)}),title:n.jsxs(n.Fragment,{children:[w.name," ",n.jsxs("span",{className:"skills-handle",children:["@",w.handle]})]}),sub:y?"Its own skill, in its folder":k?"Has its own skill of this name, and uses that":w.writable?void 0:"Ships with buddi, so its file doesn’t change"},w.id)}),b.length?null:n.jsxs("p",{className:"skills-note skills-pick-none",children:["No agent called “",u.trim(),"”."]})]}),n.jsx("p",{className:"skills-note",children:"Saved in each agent’s file, so the file stays the record."})]})})}function qV({agent:e,view:t,onCancel:s,onSaved:r}){const i=x=>q$(x,e.id),[a,l]=d.useState(t.skills.filter(i).map(x=>x.id)),[o,c]=d.useState(""),[u,h]=d.useState(!1),[f,m]=d.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()=>{h(!0),m(null);try{for(const x of t.skills){if(v(x))continue;const w=a.includes(x.id);if(w===i(x))continue;const y=Dw(x);await Bn.grant(x.id,{agents:w?[...y,e.id]:y.filter(k=>k!==e.id)})}r()}catch(x){m(pa(x))}finally{h(!1)}},j=t.skills.some(g);return n.jsx(Dt,{title:`Skills ${e.name} uses`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(A,{variant:"accent",disabled:u||!e.writable,onClick:()=>void b(),children:"Save"})]}),children:n.jsxs("div",{className:"skills-pick",children:[n.jsx(X$,{label:"Find a skill",value:o,onChange:c}),n.jsx(re,{message:f}),e.writable?null:n.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."]}),n.jsxs("div",{className:"skills-pick-list",children:[Tw.map(x=>{const w=t.skills.filter(y=>y.group===x.id&&g(y));return w.length?n.jsxs("div",{className:"skills-pick-group",role:"group","aria-label":x.title,children:[n.jsx("div",{className:"skills-pick-group-title",children:x.title}),w.map(y=>n.jsx(yh,{checked:a.includes(y.id),disabled:v(y),onChange:k=>l(k?[...a,y.id]:a.filter(N=>N!==y.id)),title:y.title,sub:y.every?i(y)?"Every agent uses it":Iw(y,t.agents):y.home===e.id?"Its own skill, in its folder":y.description},y.id))]},x.id):null}),j?null:n.jsxs("p",{className:"skills-note skills-pick-none",children:["No skill matches “",o.trim(),"”."]})]})]})})}function cN({agents:e,faces:t,upload:s,onClose:r,onSaved:i}){const[a,l]=d.useState((s==null?void 0:s.title)??""),[o,c]=d.useState((s==null?void 0:s.description)??""),[u,h]=d.useState((s==null?void 0:s.body)??""),[f,m]=d.useState([]),[p,g]=d.useState(!1),[v,b]=d.useState(!1),[j,x]=d.useState(null),w=a.trim()!==""&&o.trim()!==""&&u.trim()!=="",y=s?`${Math.max(1,Math.round(s.size/1024))} KB`:"",k=async()=>{b(!0),x(null);try{const{skill:N}=await Bn.create({title:a.trim(),description:o.trim(),body:u,agents:f,...s?{upload:{filename:s.name,mine:p}}:{}});i(N)}catch(N){x(pa(N))}finally{b(!1)}};return n.jsxs(Ye,{size:"wide",title:s?n.jsx(Q$,{title:s.name,sub:`${y} · read, not saved yet`}):"Write a skill",onClose:r,foot:n.jsxs(ae,{align:"end",children:[n.jsx(A,{variant:"ghost",onClick:r,children:"Cancel"}),n.jsx(A,{variant:"accent",disabled:!w||v,onClick:()=>void k(),children:"Save skill"})]}),children:[n.jsx(re,{message:j}),n.jsxs("div",{className:"skills-sheet",children:[n.jsxs("section",{className:"skills-sec skills-form",children:[n.jsx(oe,{label:"Name",hint:"Short, like a task: “Weekly money recap”.",children:n.jsx("input",{value:a,onChange:N=>l(N.target.value),autoFocus:!s})}),n.jsx(oe,{label:"When it’s used",hint:"One line. Agents read it to decide when the skill applies.",children:n.jsx("input",{value:o,onChange:N=>c(N.target.value),placeholder:"When I ask about the week’s spending"})}),n.jsx(oe,{label:"The text",hint:"Plain Markdown: steps, rules, what a good answer looks like.",children:n.jsx("textarea",{className:"skills-editor",value:u,onChange:N=>h(N.target.value),spellCheck:!1,placeholder:`1. Total spent this week.
113
+ 2. The three biggest charges.
114
+ 3. Anything odd.`})})]}),n.jsxs(bd,{title:"Who uses it",children:[n.jsx("div",{className:"skills-who",children:e.map(N=>n.jsx(yh,{checked:f.includes(N.id),disabled:!N.writable,onChange:S=>m(S?[...f,N.id]:f.filter(C=>C!==N.id)),lead:n.jsx(Sn,{id:N.id,name:N.name,size:"sm",face:t.find(S=>S.id===N.id)}),title:N.name},N.id))}),n.jsx("p",{className:"skills-note",children:"You can change this later. With nobody ticked it’s kept and does nothing."})]}),s?n.jsx("section",{className:"skills-sec",children:n.jsxs("label",{className:"plugins-check",children:[n.jsx("input",{type:"checkbox",checked:p,onChange:N=>g(N.target.checked)}),n.jsxs("span",{children:[n.jsx("span",{className:"plugins-check-title",children:"Mark as mine"}),n.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 YV({row:e,agents:t,onCancel:s,onDeleted:r}){const i=de(()=>Bn.detail(e.id),[e.id]),[a,l]=d.useState(!1),[o,c]=d.useState(null),u=d.useMemo(()=>i.data?LV(e,i.data.onDelete,t):null,[i.data,e,t]),h=async()=>{l(!0),c(null);try{const f=await Bn.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(pa(f)),l(!1)}};return n.jsxs(Dt,{title:`Delete “${e.title}”?`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(A,{variant:"danger",disabled:a||!i.data,onClick:()=>void h(),children:"Delete"})]}),children:[n.jsx(re,{message:o??i.error}),n.jsx("p",{className:"skills-dialog-text",children:u??"Checking who uses it…"})]})}function JV(e){var t;return((t=Tw.find(s=>s.id===e.group))==null?void 0:t.title)??""}function QV({agentId:e,agentName:t,faces:s=[],navigate:r}){const i=de(()=>Bn.list(),[e]),[a,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(!1),[f,m]=d.useState(null),[p,g]=d.useState(null),v=k=>{m(null),g(k??null),i.reload()},b=k=>{Bn.trust(k.id).then(()=>v(),N=>m(N instanceof Error?N.message:String(N)))};if(!i.data)return i.error?n.jsx(pe,{warm:!0,title:"Couldn’t load the skills",action:n.jsx(A,{variant:"accent",size:"sm",onClick:i.reload,children:"Try again"}),children:"buddi didn’t answer. The skill files are untouched."}):n.jsx(pe,{children:"Loading…"});const j=i.data,x=j.agents.find(k=>k.id===e)??{id:e,handle:e,name:t,writable:!1},w=j.skills.filter(k=>q$(k,e)),y=$V();return n.jsxs(n.Fragment,{children:[n.jsx(re,{message:f}),p?n.jsx(V,{tone:"good",role:"status",children:p}):null,n.jsx(qe,{flush:!0,title:"Skills",actions:n.jsxs(n.Fragment,{children:[n.jsxs("a",{className:"skills-all",href:y,onClick:k=>{k.preventDefault(),r(y)},children:["All skills",n.jsx(ce,{name:"chevron-right",size:12})]}),n.jsx(A,{size:"sm",onClick:()=>h(!0),children:"Choose skills…"})]}),children:w.length?n.jsx("div",{className:"skills-group",children:n.jsx(rt,{children:w.map(k=>n.jsx(et,{onClick:()=>l({id:k.id}),label:`${k.title}: details`,lead:n.jsx(Pn,{icon:"files"}),title:k.title,sub:n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"skills-line",children:k.description}),n.jsxs("span",{className:"skills-line skills-meta",children:[JV(k)," · ",k.every?"every agent uses it":Pw(k,j.agents,!0)]}),k.untrusted?n.jsx("span",{className:"skills-status","data-tone":"warning",children:Mw(k,j.agents)}):null]}),side:n.jsx("span",{className:"skills-side",children:k.untrusted?n.jsx(A,{size:"sm",onClick:N=>{N.stopPropagation(),b(k)},children:"Mark as mine"}):n.jsx("span",{className:"skills-chevron","aria-hidden":"true",children:n.jsx(ce,{name:"chevron-right",size:14})})})},k.id))})}):n.jsxs(pe,{children:[t," uses no skills yet. Choose some, or write one on the Skills page."]})}),n.jsx(J$,{view:j,faces:s,open:a,setOpen:l,dialog:o,setDialog:c,navigate:r,onChanged:v,onFailed:m}),u?n.jsx(qV,{agent:x,view:j,onCancel:()=>h(!1),onSaved:()=>{h(!1),v()}}):null]})}function Z$({timezone:e,embedded:t,agentId:s}){const{data:r,error:i,reload:a}=de(()=>$.reminders(),[],3e4),l=((r==null?void 0:r.reminders)??[]).filter(h=>!s||h.agentId===s),[o,c]=d.useState(null),u=async h=>{c(null);try{await $.cancelReminder(h),a()}catch(f){c(f instanceof Error?f.message:String(f))}};return n.jsxs(On,{embedded:t,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:[n.jsx(re,{message:i??o}),n.jsx(qe,{flush:!0,children:r?l.length===0?n.jsx(In,{icon:"bell",title:"No reminders",children:"Ask any agent to remind you of something, and it shows up here."}):n.jsxs(kr,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Due"}),n.jsx("th",{children:"Agent"}),n.jsx("th",{children:"Note"}),n.jsx("th",{children:"State"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:l.map(h=>n.jsxs("tr",{children:[n.jsxs("td",{className:"nowrap",children:[nt(h.dueAt,e),n.jsx("div",{className:"sub",children:Fe(h.dueAt)})]}),n.jsx("td",{className:"mono",children:h.agentId}),n.jsxs("td",{children:[h.text,h.context?n.jsx(Tt,{summary:"context",children:n.jsx(Pt,{children:is(h.context)})}):null]}),n.jsxs("td",{children:[n.jsx(Xc,{state:h.state}),h.cancelReason?n.jsx("div",{className:"sub",children:h.cancelReason}):null]}),n.jsx("td",{children:h.state==="pending"?n.jsx(A,{size:"sm",variant:"danger",onClick:()=>u(h.id),children:"Cancel"}):null})]},h.id))})]}):n.jsx(pe,{children:"Loading…"})})]})}const XV=/(flux|klein|schnell|qwen[-_]?image|image)/i;function eR(e){return e.kind==="image"||e.kind===void 0&&XV.test(e.id)}function ZV(e){const t=((e==null?void 0:e.models)??[]).filter(s=>!eR(s));return[...t.filter(s=>s.loaded),...t.filter(s=>!s.loaded)].map(s=>s.id)}function Lx(e){return ZV(e)[0]}function Ow(e){return(e==null?void 0:e.detectedContextWindowSource)==="mlxh"}function e7(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 tR(e){let t=e;try{t=new URL(e).host}catch{}return`mlxh is not answering on ${t}. Start it with \`mlxh serve\`, or \`mlxh service install\` to keep it running.`}const nR="an image model; pick it in the Image plugin, not here";function Lw({accountId:e,label:t,value:s,onChange:r,disabled:i=!1}){const[a,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(""),[f,m]=d.useState(!1),p=d.useRef(0),g=async x=>{if(!e)return;const w=++p.current;c(!0),h("");try{const y=await $.accountModels(e,x);w===p.current&&l(y)}catch(y){w===p.current&&h(y instanceof Error?y.message:"Could not load models. Custom entry is still available.")}finally{w===p.current&&c(!1)}};if(d.useEffect(()=>(l(null),m(!1),h(""),g(!1),()=>{p.current++}),[e]),!e)return n.jsxs(n.Fragment,{children:[n.jsx(oe,{label:t,children:n.jsx("input",{required:!0,maxLength:150,value:s,disabled:i,onChange:x=>r(x.target.value)})}),n.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=(a==null?void 0:a.models)??[],b=!!s&&!v.some(x=>x.id===s),j=[a&&!v.length?"This account returned no models. You can enter a custom model.":null,a!=null&&a.truncated?"Showing the first part of this provider’s list. Custom model entry is available.":null,a?"Uses saved account settings. Listed models may not support every agent tool. Your selection is unchanged until you save.":null].filter(Boolean);return n.jsxs(n.Fragment,{children:[n.jsx(oe,{label:t,children:n.jsxs("select",{value:f?"__buddi_custom__":s,disabled:i,onChange:x=>{x.target.value==="__buddi_custom__"?m(!0):(m(!1),r(x.target.value))},children:[n.jsx("option",{value:"",disabled:!0,children:"Choose a model"}),b&&n.jsxs("option",{value:s,children:[s," (current",a?", not listed":"",")"]}),v.map(x=>n.jsxs("option",{value:x.id,children:[x.name===x.id?x.id:`${x.name} — ${x.id}`,x.isDefault?" (provider default)":"",x.image?` — ${nR}`:""]},x.id)),n.jsx("option",{value:"__buddi_custom__",children:"Custom model…"})]})}),n.jsx(A,{disabled:i||o,onClick:()=>void g(!0),children:o?"Loading models…":"Refresh models"}),f&&n.jsx(oe,{label:`Custom ${t.toLowerCase()}`,children:n.jsx("input",{required:!0,maxLength:150,value:s,disabled:i,onChange:x=>r(x.target.value)})}),u&&n.jsx("p",{role:"alert",className:"ui-toolbar-note critical",children:u}),j.length>0&&n.jsx("p",{className:"ui-toolbar-note",children:j.join(" ")})]})}function t7(e,t){const s=new Set(t),r=[],i=new Set;for(const a of e){for(const o of a.tools)i.add(o.name);const l=a.tools.filter(o=>s.has(o.name));l.length!==0&&(a.glob&&l.length===a.tools.length?r.push(a.glob):r.push(...l.map(o=>o.name)))}return r.push(...t.filter(a=>!i.has(a))),r}function n7(e,t){return[...e].sort().join(",")===[...t].sort().join(",")}const s7="This agent will not remember anything between conversations.";function r7({view:e,chosen:t,onChange:s,disabled:r}){var k;const[i,a]=d.useState(""),[l,o]=d.useState(null),[c,u]=d.useState(()=>new Set),h=N=>u(S=>{const C=new Set(S);return C.has(N)?C.delete(N):C.add(N),C}),f=N=>{a(N),u(new Set)},m=d.useId(),p=new Set(t),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(t.filter(E=>!C.includes(E)))}},b=N=>{s([...t,...N.filter(S=>!p.has(S))])},j=i.trim().toLowerCase(),x=(N,S)=>j===""||N.toLowerCase().includes(j)||S.toLowerCase().includes(j),w=e.groups.map(N=>({group:N,tools:N.tools.filter(S=>x(S.name,S.description))})).filter(N=>N.tools.length>0),y=(((k=e.suggested)==null?void 0:k.tools)??[]).filter(N=>!p.has(N.name));return n.jsxs("div",{className:"tool-picker",children:[e.suggested&&y.length>0?n.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":`${m}-suggested`,children:[n.jsx("div",{className:"tool-picker-head",children:n.jsx("span",{id:`${m}-suggested`,className:"tool-picker-plugin",children:e.suggested.label})}),n.jsx("ul",{className:"ui-list tool-picker-list","aria-label":e.suggested.label,children:y.map(N=>n.jsxs("li",{className:"ui-list-row",children:[n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title mono",children:N.name}),n.jsx("span",{className:"ui-list-sub",children:N.description})]}),n.jsx(A,{size:"sm",disabled:r,"aria-label":`Add ${N.name}`,onClick:()=>b([N.name]),children:"Add"})]},N.name))})]}):null,n.jsxs("label",{className:"tool-picker-search",children:[n.jsx("span",{className:"ui-field-label",children:"Find a tool"}),n.jsx("input",{type:"search",value:i,placeholder:"Name or what it does",onChange:N=>f(N.target.value)})]}),w.length===0?n.jsxs(pe,{children:["No installed tool matches “",i.trim(),"”."]}):null,w.map(({group:N,tools:S})=>{const C=N.tools.filter(T=>T.grantable).map(T=>T.name),E=N.tools.filter(T=>p.has(T.name)).length,R=!!N.glob&&E===N.tools.length,I=`${m}-${N.plugin}`,L=`${m}-${N.plugin}-list`,F=j!==""?!c.has(N.plugin):c.has(N.plugin);return n.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":I,"data-open":F?"true":void 0,children:[n.jsxs("div",{className:"tool-picker-head",children:[n.jsxs("button",{type:"button",className:"tool-picker-toggle","aria-expanded":F,"aria-controls":L,onClick:()=>h(N.plugin),children:[n.jsx(i7,{}),n.jsx("span",{id:I,className:"tool-picker-plugin",children:N.plugin}),n.jsx("span",{className:"muted",children:R?`all ${N.tools.length}`:`${E} of ${N.tools.length} granted`})]}),n.jsx(A,{size:"sm",variant:"ghost","aria-label":`All ${N.plugin} tools`,disabled:r||C.every(T=>p.has(T)),onClick:()=>b(C),children:"all"}),n.jsx(A,{size:"sm",variant:"ghost","aria-label":`No ${N.plugin} tools`,disabled:r||!C.some(T=>p.has(T)),onClick:()=>v(N.plugin,C),children:"none"})]}),(l==null?void 0:l.plugin)===N.plugin?n.jsx(V,{tone:"warning",role:"alert",children:n.jsxs("div",{className:"tool-picker-confirm",children:[n.jsx("span",{children:s7}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(A,{size:"sm",onClick:()=>o(null),children:"Keep"}),n.jsx(A,{size:"sm",variant:"danger",onClick:()=>{s(t.filter(T=>!l.names.includes(T))),o(null)},children:"Remove"})]})}):null,n.jsx("ul",{id:L,className:"ui-list tool-picker-list",hidden:!F,children:S.map(T=>{const M=`${m}-${T.name}`;return n.jsxs("li",{className:"ui-list-row",children:[n.jsx("input",{type:"checkbox",id:M,checked:p.has(T.name),disabled:r||!T.grantable,onChange:P=>P.target.checked?b([T.name]):v(N.plugin,[T.name])}),n.jsxs("label",{htmlFor:M,className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[n.jsx("span",{className:"mono",children:T.name}),T.core?n.jsx(we,{tone:"accent",children:"core"}):null,T.gated?n.jsx(we,{tone:"warning",children:"asks you"}):null]}),n.jsx("span",{className:"ui-list-sub",children:T.grantable?T.description:`${T.description} Granted only by editing the file by hand.`})]})]},T.name)})})]},N.plugin)})]})}function i7(){return n.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:n.jsx("path",{d:"M2.8 4.2 5.5 6.9l2.7-2.7"})})}const gs={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."},ui=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function sR(e){let t;try{t=JSON.parse(e.trim())}catch{throw new Error(gs.json)}if(!ui(t))throw new Error(gs.json);let s,r=t;if("mcpServers"in t){const u=t.mcpServers;if(!ui(u))throw new Error(gs.empty);const h=Object.keys(u);if(h.length===0)throw new Error(gs.empty);if(h.length>1)throw new Error(`It names ${h.length} servers (${h.join(", ")}). Paste one at a time.`);s=h[0];const f=u[s];if(!ui(f))throw new Error(gs.url);r=f}if("command"in r)throw new Error(gs.command);if(typeof r.type=="string"&&r.type.toLowerCase()==="sse")throw new Error(gs.sse);const i=typeof r.url=="string"?r.url.trim():"";if(i==="")throw new Error(gs.url);const a=ui(r.headers)?Object.entries(r.headers).filter(u=>typeof u[1]=="string"&&u[0].trim()!==""):[],l=a.find(([u])=>u.toLowerCase()==="authorization")??a[0];let o,c=!1;if(l){const[u,h]=l,f=/^(Bearer|Basic)\s+/i.exec(h.trim()),m=f?`${f[1].charAt(0).toUpperCase()}${f[1].slice(1).toLowerCase()} `:"";let p=f?h.trim().slice(f[0].length).trim():h.trim();/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$/i.test(p)&&(c=!0,p=""),o={name:u.trim(),prefix:m,value:p}}return{url:i,...s?{name:s}:{},...o?{header:o}:{},dropped:a.filter(u=>u!==l).map(([u])=>u),placeholder:c}}const Wo={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 rR(e){return/TOKEN|KEY|SECRET|PASSWORD|PASSWD|CREDENTIAL|AUTH/i.test(e)}const iR=/^[A-Za-z_][A-Za-z0-9_]*$/;function a7(e){return/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$|^your[_-]/i.test(e.trim())}function aR(e,t){const s=a7(t);return{name:e,value:s?"":t,secret:rR(e),placeholder:s}}function lR(e){const t=[];let s="",r=!1,i=null;for(let a=0;a<e.length;a+=1){const l=e[a];if(i==="'"){l==="'"?i=null:s+=l;continue}if(i==='"'){if(l==='"')i=null;else if(l==="\\"&&a+1<e.length&&'"\\$`\n'.includes(e[a+1])){const o=e[++a];o!==`
115
+ `&&(s+=o)}else s+=l;continue}if(l==="\\"){const o=e[a+1];if(o===void 0)continue;if(a+=1,o===`
116
+ `||o==="\r"&&e[a+1]===`
117
+ `){o==="\r"&&(a+=1);continue}s+=o,r=!0;continue}if(l==="'"||l==='"'){i=l,r=!0;continue}if(/\s/.test(l)){r&&(t.push(s),s="",r=!1);continue}s+=l,r=!0}if(i)throw new Error(Wo.quote);return r&&t.push(s),t}function l7(e){const t=lR(e.trim());let s=0;t[s]==="claude"&&(s+=1),t[s]==="mcp"&&(s+=1),t[s]==="add"&&(s+=1);const r=[],i=[];let a="stdio",l,o;const c=h=>{const f=h.indexOf("="),m=f>0?h.slice(0,f).trim():"";if(!iR.test(m))throw new Error(Wo.env);r.push(aR(m,h.slice(f+1)))},u=[];for(;s<t.length;s+=1){const h=t[s];if(h==="--"){o=t.slice(s+1);break}const[f,m]=h.startsWith("--")&&h.includes("=")?[h.slice(0,h.indexOf("=")),h.slice(h.indexOf("=")+1)]:[h,void 0];if(f==="-e"||f==="--env"){if(m!==void 0){c(m);continue}let p=!1;for(;s+1<t.length&&/^[A-Za-z_][A-Za-z0-9_]*=/.test(t[s+1]);)c(t[++s]),p=!0;if(!p)throw new Error(Wo.env);continue}if(f==="-s"||f==="--scope"){m===void 0&&(s+=1);continue}if(f==="-t"||f==="--transport"){a=(m??t[++s]??"stdio").toLowerCase();continue}if(f==="-H"||f==="--header"){const p=m??t[++s];p&&i.push(p);continue}if(!(f.startsWith("-")&&l===void 0)){if(l===void 0){l=h;continue}u.push(h)}}if(o===void 0?o=u:u.length>0&&(o=[...u,...o]),a==="http"||a==="sse"||o.length===1&&/^https?:\/\//i.test(o[0])){const h=o[0];if(!h)throw new Error(gs.url);const f={};for(const m of i){const p=m.indexOf(":");p>0&&(f[m.slice(0,p).trim()]=m.slice(p+1).trim())}return{kind:"remote",config:sR(JSON.stringify({mcpServers:{[l??"server"]:{type:a,url:h,headers:f}}}))}}if(!l||o.length===0)throw new Error(Wo.claude);return{kind:"program",program:{name:l,command:o[0],args:o.slice(1),env:r}}}function o7(e){const t=e.trim();if(/^claude\s+mcp\s+add\b/.test(t))return l7(t);let s;try{s=JSON.parse(t)}catch{throw new Error(gs.json)}if(!ui(s))throw new Error(gs.json);let r,i=s;if("mcpServers"in s){const c=s.mcpServers;if(!ui(c))throw new Error(gs.empty);const u=Object.keys(c);u.length===1&&ui(c[u[0]])&&(r=u[0],i=c[r])}if(!("command"in i))return{kind:"remote",config:sR(t)};const a=typeof i.command=="string"?i.command.trim():"";if(a==="")throw new Error(Wo.command);const l=Array.isArray(i.args)?i.args.map(c=>String(c)):[],o=ui(i.env)?Object.entries(i.env).filter(([c])=>iR.test(c)).map(([c,u])=>aR(c,String(u??""))):[];return{kind:"program",program:{...r?{name:r}:{},command:a,args:l,env:o}}}function Fw({code:e,label:t="Your code",large:s=!1}){const[r,i]=d.useState(!1),a=async()=>{var l;try{await((l=navigator.clipboard)==null?void 0:l.writeText(e)),i(!0)}catch{}};return n.jsxs(ae,{valign:"end",children:[n.jsx(oe,{label:t,grow:!0,children:n.jsx("input",{readOnly:!0,value:e,"data-code":s?"large":void 0,spellCheck:!1,onFocus:l=>l.currentTarget.select()})}),n.jsx(A,{onClick:()=>void a(),children:r?"Copied":"Copy"})]})}function oR(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 c7="It can delete or destroy something, so it asks you every time and is never remembered.";function u7(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 cR="buddi-connections",d7="/connections/callback",h7="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.",uR="Services and programs your team can use, and the tools each one brings.",_w=(e,t,s)=>`${e} ${e===1?t:s}`;function uN(e,t){return e.transport==="stdio"?void 0:t.find(s=>Uw(s.url,e.url))}function zw({connection:e,card:t,size:s}){return t?n.jsx(Pn,{letter:t.name.slice(0,1).toUpperCase(),size:s}):n.jsx(Pn,{icon:(e==null?void 0:e.transport)==="stdio"?"terminal":"globe",size:s})}function dR({connection:e}){const t=oR(e);return n.jsx(we,{tone:t.tone,dot:t.dot,children:t.label})}const hp=e=>t=>{t.stopPropagation(),e()},kd=[{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"}],hR="buddi.connections.add-way";function f7(){try{const e=window.localStorage.getItem(hR);return kd.some(t=>t.value===e)?e:"address"}catch{return"address"}}function m7({embedded:e,timezone:t,connection:s}={}){const r=de(()=>$.connections(),[],3e4),[i,a]=d.useState(null),[l,o]=d.useState(s??null);d.useEffect(()=>{s&&o(s)},[s]);const[c,u]=d.useState(null),[h,f]=d.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=t??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"&&Uw(N.url,S.url))),x=l?v.find(N=>N.id===l):void 0,w=c?v.find(N=>N.id===c):void 0,y=h?v.find(N=>N.id===h):void 0,k=N=>{o(null),a(N)};return n.jsxs(On,{embedded:e,title:"Connections",lede:uR,children:[n.jsxs(le,{gap:"lg",children:[n.jsxs("p",{className:"plugins-quiet connections-quiet",children:[n.jsx(ce,{name:"plug",size:14}),n.jsxs("span",{children:["A connection is a service or program buddi talks to; a plugin is code buddi installs and runs."," ",n.jsx("a",{href:Pe("plugins"),children:"Plugins"})]})]}),!m&&!r.error?n.jsx(pe,{children:"Reading your connections…"}):null,n.jsx(re,{message:r.error}),m&&!m.vault?n.jsx(V,{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?n.jsx(qe,{flush:!0,title:"Your connections",tool:v.length>0?_w(v.length,"connection","connections"):void 0,children:v.length===0?n.jsx(pe,{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."}):n.jsx("div",{className:"connections-rows",children:n.jsx(rt,{children:v.map(N=>n.jsx(p7,{connection:N,card:uN(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?n.jsx(qe,{title:"Connect a service",children:n.jsx("div",{className:"connections-tiles",children:j.map(N=>n.jsxs("div",{className:"connections-tile",children:[n.jsx(zw,{card:N}),n.jsxs("span",{className:"connections-tile-main",children:[n.jsx("span",{className:"connections-tile-name",children:N.name}),n.jsx("span",{className:"connections-tile-blurb",children:N.blurb})]}),n.jsx(A,{size:"sm",onClick:()=>k({step:"address",card:N}),"aria-label":`Connect ${N.name}`,children:"Connect"})]},N.id))})}):null,m?n.jsx(w7,{onFlow:N=>k({step:N})}):null]}),x?n.jsx(x7,{connection:x,card:uN(x,b),agentName:p,timezone:g,onClose:()=>o(null),onFlow:k,onDisconnect:()=>u(x.id),onHolders:()=>f(x.id)}):null,y&&m?n.jsx(v7,{connection:y,agents:m.agents,onCancel:()=>f(null),onDone:()=>{f(null),r.reload()}},y.id):null,w?n.jsx(j7,{connection:w,agentName:p,onCancel:()=>u(null),onDone:()=>{u(null),o(null),r.reload()}},w.id):null,i&&m?n.jsx(y7,{start:i,agents:m.agents,catalog:m.catalog,tokens:m.tokens??m.vault,onClose:()=>{a(null),r.reload()}}):null]})}function p7({connection:e,card:t,twin:s,onOpen:r,onFlow:i}){const a=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=a?"its tools are not reviewed yet":_w(e.toolCount,"tool","tools");return n.jsx(et,{onClick:r,label:`${l}: details`,lead:n.jsx(zw,{connection:e,card:t}),title:l,sub:n.jsx("span",{className:"connections-sub","data-kind":o?"program":void 0,children:`${c} · ${u}`}),side:n.jsxs("span",{className:"plugins-side",children:[a?n.jsx("span",{className:"connections-act",children:n.jsx(A,{size:"sm",variant:"accent",onClick:hp(()=>i({step:e.signedIn?"review":"consent",connection:e})),children:"Finish"})}):e.state==="needs-reconnect"&&e.authKind!=="none"?n.jsx("span",{className:"connections-act",children:n.jsx(A,{size:"sm",onClick:hp(()=>i({step:"consent",connection:e,keepGrants:!0})),children:"Sign in"})}):e.state==="needs-review"?n.jsx("span",{className:"connections-act",children:n.jsx(A,{size:"sm",onClick:hp(()=>i({step:"review",connection:e,keepGrants:!0})),children:"Review"})}):null,n.jsx(dR,{connection:e}),n.jsx(ce,{name:"chevron-right",size:14})]})})}const g7={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 x7({connection:e,card:t,agentName:s,timezone:r,onClose:i,onFlow:a,onHolders:l,onDisconnect:o}){const c=e.state==="pending-review",u=e.transport==="stdio"?e.program:void 0,h=()=>a({step:"consent",connection:e,keepGrants:!0}),f=()=>a({step:"review",connection:e,keepGrants:!0}),m=()=>a({step:e.signedIn?"review":"consent",connection:e});return n.jsxs(Ye,{title:n.jsxs("span",{className:"plugins-sheet-title",children:[n.jsx(zw,{connection:e,card:t,size:"lg"}),n.jsxs("span",{className:"plugins-sheet-name",children:[n.jsx("span",{children:e.name}),n.jsxs("span",{className:"plugins-sheet-by",children:[u?"A program on this computer":"A service at an address"," · ",n.jsx(dR,{connection:e})]})]})]}),onClose:i,foot:n.jsxs(ae,{children:[n.jsx(A,{variant:"danger-ghost",onClick:o,children:"Disconnect…"}),n.jsx(ht,{}),u?n.jsx(A,{onClick:()=>a({step:"program",connection:e,keepGrants:!0}),children:"Change"}):null,e.authKind!=="none"&&!c?n.jsx(A,{variant:e.state==="needs-reconnect"?"accent":void 0,onClick:h,children:"Reconnect"}):null,c?n.jsx(A,{variant:"accent",onClick:m,children:"Finish"}):n.jsx(A,{variant:e.state==="needs-review"?"accent":void 0,onClick:f,children:"Review again"})]}),children:[c?n.jsx(V,{children:"Not finished: its tools are not reviewed yet, so no agent can use them."}):null,e.state==="needs-reconnect"?n.jsx(V,{tone:"warning",action:e.authKind!=="none"?n.jsx(A,{size:"sm",variant:"accent",onClick:h,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"?n.jsxs(V,{tone:"warning",action:n.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?n.jsx(V,{tone:"critical",children:u?`It stopped answering at ${nt(e.unreachableSince,r)}; the next call starts it again.`:`Unreachable since ${nt(e.unreachableSince,r)}, retrying.`}):null,u!=null&&u.changedSinceReview?n.jsx(V,{tone:"warning",children:"Its command changed since you reviewed it, so its tools wait until you review it again."}):null,e.phase==="starting"?n.jsx(V,{tone:"accent",role:"status",children:"Starting it… The first start can take a minute or two while it downloads."}):null,n.jsx("div",{className:"plugins-facts",children:n.jsx(Gt,{items:[u?{label:"Command",value:n.jsx("span",{className:"connections-line",children:u.line})}:{label:"Address",value:n.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:n.jsx("span",{className:"mono",children:u.env.map(p=>`${p.name}${p.secret?" (secret)":""}`).join(", ")})}]:[],...u?[]:[{label:"Signs in with",value:g7[e.authKind]}],{label:"Tools",value:c?"Not reviewed yet":`${_w(e.toolCount,"tool","tools")}${e.reviewedAt?` · reviewed ${Fe(e.reviewedAt)}`:""}`},...c?[]:[{label:"Held by",value:n.jsxs("span",{className:"connections-holders",children:[n.jsx("span",{children:e.agents.length===0?"No agent holds these tools yet.":e.agents.map(s).join(", ")}),n.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?n.jsx(ue,{title:"What the program last said",children:n.jsx(Pt,{label:"Its last lines on stderr",children:e.stderr.join(`
118
+ `)})}):null,t&&!c?n.jsxs("div",{className:"connections-another",children:[n.jsxs("p",{children:["Another ",t.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."]}),n.jsx(A,{size:"sm",onClick:()=>a({step:"address",card:t}),children:"Add another account"})]}):null]})}function v7({connection:e,agents:t,onCancel:s,onDone:r}){const[i,a]=d.useState(()=>new Set(e.agents)),[l,o]=d.useState(!1),[c,u]=d.useState(null),h=(p,g)=>a(v=>{const b=new Set(v);return g?b.add(p):b.delete(p),b}),f=i.size===e.agents.length&&e.agents.every(p=>i.has(p)),m=async()=>{o(!0),u(null);try{const p=await $.grantConnection(e.id,[...i],!0);p.failed.length>0?u(p.failed.map(g=>`${g.agent}: ${g.message}`).join("; ")):r()}catch(p){u(Vs(p))}finally{o(!1)}};return n.jsxs(Dt,{title:`Who holds ${e.name}`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",disabled:l,onClick:s,children:"Cancel"}),n.jsx(A,{variant:"accent",disabled:l||f,onClick:()=>void m(),children:"Save"})]}),children:[n.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."}),n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Agents",children:t.map(p=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:i.has(p.id),onChange:g=>h(p.id,g.target.checked)}),n.jsxs("span",{children:[p.name,p.frontDesk?" (front desk)":""]})]},p.id))}),n.jsx(re,{message:c})]})}function j7({connection:e,agentName:t,onCancel:s,onDone:r}){const[i,a]=d.useState(!1),[l,o]=d.useState(null),c=e.agents.map(t),u=async()=>{a(!0),o(null);try{await $.disconnect(e.id),r()}catch(h){o(Vs(h))}finally{a(!1)}};return n.jsxs(Dt,{title:`Disconnect ${e.name}?`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",disabled:i,onClick:s,children:"Cancel"}),n.jsx(A,{variant:"danger",disabled:i,onClick:()=>void u(),children:"Disconnect"})]}),children:[n.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."]}),n.jsx(re,{message:l})]})}function w7({onFlow:e}){const[t,s]=d.useState(f7),r=kd.find(a=>a.value===t)??kd[0],i=a=>{s(a);try{window.localStorage.setItem(hR,a)}catch{}};return n.jsx(qe,{title:"Add your own",actions:n.jsx(qt,{label:"How to add it",options:kd.map(({value:a,label:l})=>({value:a,label:l})),value:t,onChange:i}),children:n.jsxs("div",{className:"connections-add",children:[n.jsx("p",{className:"connections-add-text",children:r.text}),n.jsx(A,{variant:"accent",onClick:()=>e(t),children:r.button})]})})}function y7({start:e,agents:t,catalog:s=[],tokens:r=!0,onClose:i,pollMs:a=2e3}){const[l,o]=d.useState(e.step),[c,u]=d.useState(e.connection),[h,f]=d.useState("unknown"),[m,p]=d.useState(null),[g,v]=d.useState(null),b=(m==null?void 0:m.url)??(c==null?void 0:c.url),j=e.card??s.find(y=>b!==void 0&&Uw(y.url,b)),x=(c==null?void 0:c.name)??(j==null?void 0:j.name)??(m==null?void 0:m.name)??"the service",w=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 n.jsxs(Ye,{title:w,onClose:i,size:"wide",children:[l==="paste"?n.jsx(b7,{onRead:y=>{y.kind==="program"?(v(y.program),o("program")):(p(y.config),o("address"))}}):null,l==="address"?n.jsx(k7,{card:j,pasted:m,onDone:(y,k)=>{u(y),k==="none"?o("review"):(f(k),o("consent"))}}):null,l==="program"?n.jsx(R7,{connection:c,pasted:g,tokens:r,onDone:y=>{var k;v(null),u(y),e.keepGrants&&!((k=y.program)!=null&&k.changedSinceReview)&&y.state!=="pending-review"?i():o("review")}}):null,l==="consent"&&c?n.jsx(C7,{connection:c,signIn:h,card:j,pasted:m==null?void 0:m.header,placeholder:(m==null?void 0:m.placeholder)??!1,tokens:r,pollMs:a,onSignedIn:y=>{p(null),u(y),e.keepGrants?i():o("review")}}):null,l==="review"&&c?n.jsx(I7,{connection:c,onKept:y=>{u(y),e.keepGrants?i():o("grant")}}):null,l==="grant"&&c?n.jsx(P7,{connection:c,agents:t,onDone:i}):null]})}function Uw(e,t){const s=r=>r.trim().replace(/\/+$/,"").toLowerCase();return s(e)===s(t)}function Vs(e){return e instanceof Error?e.message:String(e)}function b7({onRead:e}){const[t,s]=d.useState(""),[r,i]=d.useState(null),a=()=>{try{const l=o7(t);s(""),i(null),e(l)}catch(l){i(Vs(l))}};return n.jsxs("form",{className:"ui-stack",onSubmit:l=>{l.preventDefault(),a()},children:[n.jsxs("p",{children:["Paste the block another app uses for this server, the one with ",n.jsx("span",{className:"mono",children:"mcpServers"}),", or the"," ",n.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."]}),n.jsx(oe,{label:"Config",hint:"A url for a remote server, or a command for a program on this computer.",children:n.jsx("textarea",{className:"mono",rows:8,required:!0,autoFocus:!0,spellCheck:!1,autoComplete:"off",value:t,placeholder:'{ "mcpServers": { "github": { "url": "…", "headers": { "Authorization": "Bearer …" } } } }',onChange:l=>s(l.target.value)})}),n.jsx(re,{message:r}),n.jsx(ae,{align:"end",children:n.jsx(A,{type:"submit",variant:"accent",disabled:t.trim()==="",children:"Read it"})})]})}function k7({card:e,pasted:t,onDone:s}){var m,p;const[r,i]=d.useState((t==null?void 0:t.url)??(e==null?void 0:e.url)??""),[a,l]=d.useState(!1),[o,c]=d.useState(null),u=async()=>{l(!0),c(null);try{const g=await $.addConnection(r.trim(),(e==null?void 0:e.name)??(t==null?void 0:t.name));s(g.connection,g.signIn)}catch(g){c(Vs(g))}finally{l(!1)}},h=((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 n.jsxs("form",{className:"ui-stack",onSubmit:g=>{g.preventDefault(),u()},children:[e?n.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."]}):n.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."}),n.jsx(oe,{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:n.jsx("input",{required:!0,autoFocus:!e&&!t,spellCheck:!1,value:r,placeholder:"https://",onChange:g=>i(g.target.value)})}),e&&!e.verified?n.jsxs("p",{className:"ui-card-meta",children:["This address is the one ",e.name," published; buddi has not checked it since."]}):null,f?n.jsxs("p",{className:"ui-card-meta",children:[e.name," signs in with a code you type on its site. The next screen shows it."]}):h?n.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?n.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,t!=null&&t.header?n.jsx("p",{className:"ui-card-meta",children:t.placeholder?`Your config has a placeholder where the ${t.header.name} header's token goes. You paste the token itself on the next screen.`:`The ${t.header.name} header from your config waits for the sign-in screen. buddi tries it before it keeps it.`}):null,t&&t.dropped.length>0?n.jsxs("p",{className:"ui-card-meta",children:["buddi sends one header, so ",t.dropped.join(", ")," ",t.dropped.length===1?"was":"were"," left out."]}):null,n.jsx(re,{message:o}),n.jsx(ae,{align:"end",children:n.jsx(A,{type:"submit",variant:"accent",disabled:a||r.trim()==="",children:a?"Opening…":"Continue"})})]})}const N7={device:"Device",oauth:"Sign in",token:"Token",client:"Client id"};function S7(e,t,s="none"){const r=e==="manual"?["token","client"]:["oauth","token"],i=t?r:r.filter(a=>a!=="token");return s==="first"?["device",...i]:s==="offered"?[...i.filter(a=>a!=="client"),"device",...i.filter(a=>a==="client")]:i}function C7({connection:e,signIn:t,card:s,pasted:r,placeholder:i,tokens:a,pollMs:l,onSignedIn:o}){var H,B;const[c,u]=d.useState(t),h=(H=s==null?void 0:s.auth)!=null&&H.device?s.auth.recommended==="device"?"first":"offered":"none",f=S7(c,a,h),m=r!==void 0||h!=="first"&&(e.authKind==="token"||((B=s==null?void 0:s.auth)==null?void 0:B.recommended)==="token"),[p,g]=d.useState(()=>m&&f.includes("token")?"token":f[0]),v=f.includes(p)?p:f[0],[b,j]=d.useState(h7),[x,w]=d.useState(""),[y,k]=d.useState(null),[N,S]=d.useState(!1),[C,E]=d.useState(null),[R,I]=d.useState(!1),[L,F]=d.useState(null),T=`${location.origin}${d7}`,M=d.useRef(o);M.current=o,d.useEffect(()=>{if(!R)return;let Y=!1;const W=async()=>{if(!Y){Y=!0;try{M.current(await $.connection(e.id))}catch(ee){E(Vs(ee))}}},q=typeof BroadcastChannel=="function"?new BroadcastChannel(cR):null;q&&(q.onmessage=ee=>{var fe;((fe=ee.data)==null?void 0:fe.id)===e.id&&W()});let _;const X=Date.now(),Q=async()=>{if(!Y){try{const ee=await $.connection(e.id);if((!e.signedIn||e.authKind==="token")&&ee.signedIn&&ee.authKind==="oauth"){W();return}}catch{}if(Date.now()-X>10*6e4){I(!1),E("The sign-in did not come back within ten minutes. Start it again.");return}_=window.setTimeout(()=>void Q(),l)}};return _=window.setTimeout(()=>void Q(),l),()=>{Y=!0,q==null||q.close(),window.clearTimeout(_)}},[R,e,l]);const P=async Y=>{var W;S(!0),E(null);try{const{authorizeUrl:q}=await $.connectionConsent(e.id,Y);k(q)}catch(q){q instanceof ve&&((W=q.detail)==null?void 0:W.code)==="client-id"?(j(q.message),u("manual"),g("client")):E(Vs(q))}finally{S(!1)}};d.useEffect(()=>{v!=="oauth"||y!==null||P()},[v]);const D=Y=>{const W=window.open(Y,"_blank");W?(W.opener=null,F(null)):F(Y),I(!0)},O=Y=>{g(Y),k(null),E(null),I(!1),F(null)};return n.jsxs("div",{className:"ui-stack",children:[f.length>1?n.jsx(qt,{label:"How to sign in",options:f.map(Y=>({value:Y,label:N7[Y]})),value:v,onChange:O}):null,v==="oauth"?n.jsxs(n.Fragment,{children:[n.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?n.jsxs(pe,{children:["Getting ",e.name,"’s sign-in page…"]}):null]}):null,v==="client"?n.jsxs(n.Fragment,{children:[n.jsx(V,{tone:"warning",children:b}),n.jsx(oe,{label:"Client id",children:n.jsx("input",{required:!0,spellCheck:!1,value:x,onChange:Y=>{w(Y.target.value),k(null),I(!1)}})}),n.jsxs("p",{className:"ui-card-meta",children:["Its redirect address: ",n.jsx("span",{className:"mono",children:T})]})]}):null,v==="token"?n.jsx(T7,{connection:e,card:s,pasted:r,placeholder:i,onSignedIn:o}):null,v==="device"?n.jsx(A7,{connection:e,service:(s==null?void 0:s.name)??e.name,pollMs:l,onSignedIn:o}):null,(v==="oauth"||v==="client")&&R?n.jsxs(V,{tone:"accent",role:"status",children:["Waiting for you to say yes on ",e.name,"’s page…"]}):null,(v==="oauth"||v==="client")&&L?n.jsx("p",{children:n.jsxs("a",{href:L,target:"_blank",rel:"noopener noreferrer",children:["Open ",e.name,"’s sign-in page"]})}):null,v==="oauth"||v==="client"?n.jsx(re,{message:C}):null,v==="oauth"?n.jsx(ae,{align:"end",children:n.jsx(A,{variant:"accent",onClick:()=>{y&&D(y)},disabled:y===null,children:R?"Open it again":`Sign in to ${e.name}`})}):null,v==="client"?n.jsx(ae,{align:"end",children:y===null?n.jsx(A,{variant:"accent",onClick:()=>void P(x.trim()),disabled:N||x.trim()==="",children:N?"Checking…":"Continue"}):n.jsx(A,{variant:"accent",onClick:()=>D(y),children:R?"Open it again":`Open ${e.name}’s sign-in page`})}):null]})}function E7(e){try{const t=new URL(e);return`${t.host}${t.pathname==="/"?"":t.pathname.replace(/\/$/,"")}`}catch{return e}}function A7({connection:e,service:t,pollMs:s,onSignedIn:r}){const[i,a]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(0),[h,f]=d.useState(null),m=d.useRef(r);m.current=r,d.useEffect(()=>{let v=!1,b;a(null),o(null),f(null);const j=async()=>{var x,w;if(!v){try{const y=await $.connection(e.id);if(v)return;if(((x=y.device)==null?void 0:x.state)==="done"){m.current(y);return}if(((w=y.device)==null?void 0:w.state)==="failed"){o(y.device.reason??"The sign-in did not finish. Start again.");return}}catch{}b=window.setTimeout(()=>void j(),s)}};return(async()=>{try{const x=await $.connectionDevice(e.id);if(v)return;a({userCode:x.userCode,verificationUri:x.verificationUri}),b=window.setTimeout(()=>void j(),s)}catch(x){v||o(Vs(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=i?E7(i.verificationUri):"";return n.jsxs(n.Fragment,{children:[n.jsxs("p",{children:["Type this code on ",t,"’s site and say yes there. buddi keeps the sign-in in its vault and sends it only to"," ",n.jsx("span",{className:"mono",children:e.host}),". No agent ever sees it."]}),i===null&&l===null?n.jsxs(pe,{children:["Asking ",t," for a code…"]}):null,i&&l===null?n.jsxs(n.Fragment,{children:[n.jsx(Fw,{code:i.userCode,label:`Your code for ${t}`,large:!0}),n.jsxs(V,{tone:"accent",role:"status",children:["Waiting for you to approve on ",t,"…"]}),h?n.jsx("p",{children:n.jsxs("a",{href:h,target:"_blank",rel:"noopener noreferrer",children:["Open ",g]})}):null,n.jsx(ae,{align:"end",children:n.jsxs(A,{variant:"accent",onClick:()=>p(i.verificationUri),children:["Open ",g]})})]}):null,l!==null?n.jsxs(n.Fragment,{children:[n.jsx(re,{message:l}),n.jsx(ae,{align:"end",children:n.jsx(A,{variant:"accent",onClick:()=>u(v=>v+1),children:"Start again"})})]}):null]})}function T7({connection:e,card:t,pasted:s,placeholder:r,onSignedIn:i}){var j,x;const[a,l]=d.useState((s==null?void 0:s.value)??""),[o,c]=d.useState((s==null?void 0:s.name)??"Authorization"),[u,h]=d.useState((s==null?void 0:s.prefix)??(s?"":"Bearer ")),[f,m]=d.useState(!1),[p,g]=d.useState(null),v=async()=>{m(!0),g(null);try{const w=await $.connectionToken(e.id,{token:a.trim(),header:o.trim(),prefix:u});l(""),i(w.connection)}catch(w){g(Vs(w))}finally{m(!1)}},b=(j=t==null?void 0:t.auth)==null?void 0:j.tokenPage;return n.jsxs("form",{className:"ui-stack",onSubmit:w=>{w.preventDefault(),v()},children:[n.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"," ",n.jsx("span",{className:"mono",children:e.host})," first, keeps it in its vault, and sends it only there. No agent ever sees it."]}),b?n.jsx("p",{children:n.jsxs("a",{href:b,target:"_blank",rel:"noopener noreferrer",children:["Make a token on ",e.name]})}):null,r?n.jsx(V,{tone:"accent",children:"Your config had a placeholder where the token goes. Paste the token itself."}):null,n.jsx(oe,{label:"Token",hint:(x=t==null?void 0:t.auth)==null?void 0:x.tokenHint,children:n.jsx("input",{type:"password",required:!0,autoFocus:!(s!=null&&s.value),autoComplete:"off",spellCheck:!1,value:a,onChange:w=>l(w.target.value)})}),n.jsxs(Hs,{columns:2,dense:!0,children:[n.jsx(oe,{label:"Header",hint:"Most services want Authorization.",children:n.jsx("input",{required:!0,spellCheck:!1,value:o,onChange:w=>c(w.target.value)})}),n.jsx(oe,{label:"Before the token",hint:"Usually “Bearer ”, with its space. Empty for none.",children:n.jsx("input",{spellCheck:!1,value:u,onChange:w=>h(w.target.value)})})]}),n.jsx(re,{message:p}),n.jsx(ae,{align:"end",children:n.jsx(A,{type:"submit",variant:"accent",disabled:f||a.trim()===""||o.trim()==="",children:f?"Trying it…":"Try it and keep it"})})]})}function $7(e){return e!==""&&/^[A-Za-z0-9_@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function R7({connection:e,pasted:t,tokens:s=!0,onDone:r}){const i=e==null?void 0:e.program,a=d.useRef(0),l=()=>(a.current+=1,a.current),[o,c]=d.useState((e==null?void 0:e.name)??(t==null?void 0:t.name)??""),[u,h]=d.useState((i==null?void 0:i.command)??(t==null?void 0:t.command)??""),[f,m]=d.useState(()=>((i==null?void 0:i.args)??(t==null?void 0:t.args)??[]).map(T=>({key:l(),value:T}))),[p,g]=d.useState(()=>i?i.env.map(T=>({key:l(),name:T.name,value:T.value??"",secret:T.secret,kept:T.secret})):((t==null?void 0:t.env)??[]).map(T=>({key:l(),name:T.name,value:T.value,secret:T.secret,kept:!1}))),[v,b]=d.useState(!1),[j,x]=d.useState(null),w=/\s/.test(u.trim())?lR(u.trim()):[u.trim()],y=w[0]??"",k=[...w.slice(1),...f.map(T=>T.value)],N=[y,...k].filter((T,M)=>M>0||T!==""),S=()=>{w.length<2||(h(y),m(T=>[...w.slice(1).map(M=>({key:l(),value:M})),...T]))},C=N.map($7).join(" "),E=p.filter(T=>T.secret&&T.value===""&&!T.kept).map(T=>T.name||"a variable"),R=((t==null?void 0:t.env)??[]).filter(T=>T.placeholder).map(T=>T.name),I=(T,M)=>m(P=>P.map(D=>D.key===T?{...D,value:M}:D)),L=(T,M)=>g(P=>P.map(D=>D.key===T?{...D,...M}:D)),F=async()=>{b(!0),x(null);const T={name:o.trim(),command:y,args:k,env:p.filter(M=>M.name.trim()!=="").map(M=>({name:M.name.trim(),value:M.value,secret:M.secret}))};try{r(e?await $.updateProgram(e.id,T):(await $.addProgram(T)).connection),g(M=>M.map(P=>P.secret?{...P,value:""}:P))}catch(M){x(Vs(M))}finally{b(!1)}};return n.jsxs("form",{className:"ui-stack",onSubmit:T=>{T.preventDefault(),F()},children:[n.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."}),n.jsxs(Hs,{columns:2,children:[n.jsx(oe,{label:"Name",children:n.jsx("input",{required:!0,autoFocus:!t&&!e,maxLength:80,spellCheck:!1,value:o,onChange:T=>c(T.target.value)})}),n.jsx(oe,{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:n.jsx("input",{required:!0,spellCheck:!1,autoComplete:"off",className:"mono",value:u,placeholder:"npx",onChange:T=>h(T.target.value),onBlur:S})})]}),n.jsx(oe,{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:n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[f.map((T,M)=>n.jsxs("div",{className:"connections-row",children:[n.jsx("input",{"aria-label":`Argument ${M+1}`,className:"mono",spellCheck:!1,autoComplete:"off",value:T.value,onChange:P=>I(T.key,P.target.value)}),n.jsx(A,{size:"sm",variant:"ghost",onClick:()=>m(P=>P.filter(D=>D.key!==T.key)),"aria-label":`Remove argument ${M+1}`,children:"Remove"})]},T.key)),n.jsx(ae,{children:n.jsx(A,{size:"sm",onClick:()=>m(T=>[...T,{key:l(),value:""}]),children:"Add an argument"})})]})}),n.jsx(oe,{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:n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[p.map((T,M)=>n.jsxs("div",{className:"connections-row","data-kind":"env",children:[n.jsx("input",{"aria-label":`Variable ${M+1} name`,className:"mono",spellCheck:!1,autoComplete:"off",placeholder:"NAME",value:T.name,onChange:P=>{const D=P.target.value;L(T.key,T.value===""&&!T.kept?{name:D,secret:rR(D)}:{name:D})}}),n.jsx("input",{"aria-label":`Variable ${M+1} value`,type:T.secret?"password":"text",spellCheck:!1,autoComplete:"off",placeholder:T.kept&&T.value===""?"Kept. Type to replace it.":"value",value:T.value,onChange:P=>L(T.key,{value:P.target.value})}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:T.secret,onChange:P=>L(T.key,{secret:P.target.checked,kept:P.target.checked&&T.kept})}),n.jsx("span",{children:"Secret"})]}),n.jsx(A,{size:"sm",variant:"ghost",onClick:()=>g(P=>P.filter(D=>D.key!==T.key)),"aria-label":`Remove variable ${M+1}`,children:"Remove"})]},T.key)),n.jsx(ae,{children:n.jsx(A,{size:"sm",onClick:()=>g(T=>[...T,{key:l(),name:"",value:"",secret:!1,kept:!1}]),children:"Add a variable"})})]})}),R.length>0?n.jsxs(V,{tone:"accent",children:["Your config had a placeholder for ",R.join(", "),". Type the value itself."]}):null,!s&&p.some(T=>T.secret)?n.jsx(V,{tone:"warning",children:"This installation has no vault, so a secret cannot be kept. Turn the vault on first, or switch Secret off."}):null,n.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."}),n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[n.jsx("span",{className:"ui-field-label",children:"It will run"}),n.jsx(Pt,{label:"The command line",children:C||"…"})]}),n.jsx(re,{message:j}),n.jsx(ae,{align:"end",children:n.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 I7({connection:e,onKept:t}){const s=de(()=>$.connectionReview(e.id),[e.id]),[r,i]=d.useState(null),[a,l]=d.useState(!1),[o,c]=d.useState(null),u=s.data,h=r??(u==null?void 0:u.slug)??"",f=async()=>{var p;if(u){l(!0),c(null);try{t(await $.saveConnectionReview(e.id,{hash:u.hash,...u.slugEditable?{slug:h}:{}}))}catch(g){g instanceof ve&&((p=g.detail)==null?void 0:p.code)==="changed"&&s.reload(),c(Vs(g))}finally{l(!1)}}};if(!u)return s.error?n.jsx(re,{message:s.error}):e.transport==="stdio"?n.jsxs(pe,{children:["Starting ",e.name,"… The first start can take a minute or two while it downloads."]}):n.jsxs(pe,{children:["Reading what ",e.name," offers…"]});const m=u.tools.filter(p=>p.problem===null).length;return n.jsxs("div",{className:"ui-stack",children:[n.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?n.jsx(V,{tone:"warning",title:"This runs on this computer as you",children:n.jsxs(le,{gap:"sm",children:[n.jsx(Pt,{label:"The command",children:u.program.line}),n.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?n.jsxs("p",{className:"ui-card-meta",children:["Variables: ",u.program.env.map(p=>`${p.name}${p.secret?" (secret)":""}`).join(", ")]}):null]})}):n.jsxs("p",{className:"ui-card-meta",children:["buddi talks to ",n.jsx("span",{className:"mono",children:u.host})," for these tools, and nowhere else."]}),u.annotatedNothing?n.jsxs(V,{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?n.jsxs(V,{tone:"warning",title:`${e.name} changed its tools since your last review.`,children:[n.jsxs("ul",{className:"connections-changes","aria-label":"What changed",children:[u.changes.added.length>0?n.jsxs("li",{children:["New: ",n.jsx("span",{className:"mono",children:u.changes.added.join(", ")})]}):null,u.changes.changed.length>0?n.jsxs("li",{children:["Changed: ",n.jsx("span",{className:"mono",children:u.changes.changed.join(", ")})]}):null,u.changes.removed.length>0?n.jsxs("li",{children:["Gone: ",n.jsx("span",{className:"mono",children:u.changes.removed.join(", ")})]}):null]}),n.jsx("p",{children:"Until you keep this list, the new and changed tools wait; the others keep working."})]}):null,u.slugEditable?n.jsx(oe,{label:"Its name in buddi",hint:`Tools are called mcp.${h||"…"}.<tool>. Lower case, letters, digits, _ and -.`,children:n.jsx("input",{required:!0,spellCheck:!1,maxLength:24,value:h,onChange:p=>i(p.target.value.toLowerCase())})}):null,u.tools.length===0?n.jsxs(pe,{children:[e.name," lists no tools."]}):n.jsx("div",{className:"ui-list","aria-label":"Tools",children:u.tools.map(p=>{const g=u7(p),v=u.slugEditable?p.fullName.replace(/^mcp\.[^.]+\./,`mcp.${h||u.slug}.`):p.fullName;return n.jsx("div",{className:"ui-list-row connections-tool",children:n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[n.jsxs("div",{className:"ui-card-head",children:[n.jsx("span",{className:"mono",children:v}),p.problem?n.jsx(we,{tone:"muted",children:"Cannot be used"}):n.jsx(we,{tone:g.tone,children:g.label}),p.change==="added"?n.jsx(kc,{children:"New"}):p.change==="changed"?n.jsx(kc,{children:"Changed"}):null]}),p.description?n.jsx("p",{className:"ui-card-meta",children:p.description}):null,!p.problem&&p.tier==="gated"?n.jsx("p",{className:"ui-card-meta",children:p.destructive?c7:"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?n.jsxs("p",{className:"ui-card-meta",children:["Left out: ",p.problem,"."]}):null]})},p.name)})}),n.jsx(re,{message:o}),n.jsx(ae,{align:"end",children:n.jsx(A,{variant:"accent",onClick:()=>void f(),disabled:a||u.slugEditable&&h.trim()==="",children:m===1?"Keep this tool":`Keep these ${m} tools`})})]})}function P7({connection:e,agents:t,onDone:s}){var b;const r=t.find(j=>j.frontDesk)??t[0],[i,a]=d.useState(()=>new Set(r?[r.id]:[])),o=(((b=de(()=>$.connectionTools(e.id),[e.id]).data)==null?void 0:b.tools)??[]).filter(j=>j.tier==="gated"),[c,u]=d.useState(()=>new Set),[h,f]=d.useState(!1),[m,p]=d.useState(null),g=(j,x)=>{a(w=>{const y=new Set(w);return x?y.add(j):y.delete(j),y})},v=async()=>{f(!0),p(null);try{const j=await $.grantConnection(e.id,[...i]);if(j.failed.length>0){p(j.failed.map(x=>`${x.agent}: ${x.message}`).join(" "));return}for(const x of j.granted)for(const w of c)await $.setRememberedApproval(x,w,!0);s()}catch(j){p(Vs(j))}finally{f(!1)}};return n.jsxs("div",{className:"ui-stack",children:[n.jsxs("p",{children:[r?`Give these tools to ${r.name}?`:"Which agents get these tools?"," Each one you tick gets ",n.jsx("span",{className:"mono",children:e.grant})," on its tools line."]}),n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Agents",children:t.map(j=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:i.has(j.id),onChange:x=>g(j.id,x.target.checked)}),n.jsxs("span",{children:[j.name,j.frontDesk?" (front desk)":""]})]},j.id))}),n.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?n.jsxs("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Remembered approval",children:[n.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=>n.jsxs(le,{gap:"sm",children:[n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",disabled:!j.rememberable,checked:c.has(j.tool),onChange:x=>u(w=>{const y=new Set(w);return x.target.checked?y.add(j.tool):y.delete(j.tool),y})}),n.jsx("span",{className:"mono",children:j.tool})]}),j.why?n.jsx("p",{className:"ui-card-meta",children:j.why}):null]},j.tool))]}):null,n.jsx(re,{message:m}),n.jsxs(ae,{align:"end",children:[n.jsx(A,{onClick:s,disabled:h,children:"Not now"}),n.jsx(A,{variant:"accent",onClick:()=>void v(),disabled:h||i.size===0,children:"Give them"})]})]})}const M7=(e,t,s)=>`${e} ${e===1?t:s}`;function D7(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 O7({agentId:e,agentName:t,readOnly:s,version:r,onSaved:i}){const[a,l]=d.useState({}),o=de(()=>$.connections().then(w=>(l({}),w)),[r]),[c,u]=d.useState(null),[h,f]=d.useState(null),m=Pe("connections"),p=async(w,y)=>{u(w.id),f(null);try{const k=await $.setConnectionHolder(w.id,e,y);l(N=>({...N,[w.id]:k.held})),i==null||i()}catch(k){f(k instanceof Error?k.message:String(k))}finally{u(null)}},g=o.data,v=(g==null?void 0:g.connections)??[],b=w=>a[w.id]??w.agents.includes(e),j=g?g.agents.some(w=>w.id===e):!0,x=v.filter(b).length;return n.jsxs(ue,{title:"Connections",aside:g&&v.length>0?`holds ${x} of ${v.length} · saved as you change them`:void 0,panel:!0,children:[n.jsx(re,{message:o.error??h}),g?v.length===0?n.jsxs("p",{className:"ui-card-meta",children:["Nothing is connected yet. ",n.jsx("a",{href:m,children:"Connect a service in Connections"})]}):j?n.jsxs(n.Fragment,{children:[s?n.jsx(V,{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,n.jsx("ul",{className:"ui-list delegate-list","aria-label":`Connections ${t} holds`,children:v.map(w=>{const y=b(w),k=D7(w),N=w.transport==="stdio"?"on this computer":w.host,S=w.slug?M7(w.toolCount,"tool","tools"):"tools not reviewed",C=`holds-${e}-${w.id}`;return n.jsxs("li",{className:"ui-list-row",children:[n.jsx("input",{type:"checkbox",role:"switch",id:C,checked:y,"aria-checked":y,disabled:s||c!==null||k!==null&&!y,onChange:E=>void p(w,E.target.checked)}),n.jsxs("label",{htmlFor:C,className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[w.name,k?n.jsxs(n.Fragment,{children:[" ",n.jsx(we,{tone:"warning",children:oR(w).label})]}):null]}),n.jsx("span",{className:"ui-list-sub",children:`${N} · ${S}`}),k?n.jsxs("span",{className:"ui-list-sub",children:[k," ",n.jsx("a",{href:m,children:"Open Connections"})]}):null]})]},w.id)})})]}):n.jsxs("p",{className:"ui-card-meta",children:[t," makes and changes agents, so it holds no connections."]}):o.error?null:n.jsx(pe,{children:"Loading the connections…"})]})}const L7=(e,t)=>!!e&&!!t&&e.kind===t.kind&&(e.kind==="mascot"?e.role===t.role:e.kind==="emoji"?e.value===t.value:!0);async function fR(e){const t=await fetch(ka(e));if(!t.ok)throw new Error(`The picture could not be read (${t.status}).`);const s=await t.blob();return new File([s],`buddi-blob-${e}.png`,{type:"image/png"})}function F7({face:e,onPick:t,label:s=z.assistant.face,kept:r,disabled:i,disableEmoji:a,children:l}){return n.jsxs("div",{className:"meet-faces",role:"group","aria-label":s,children:[n.jsxs("div",{className:"meet-face-row",children:[r?n.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:i,onClick:()=>t({kind:"kept",url:r}),children:n.jsx("img",{src:r,alt:""})}):null,nU.map(o=>{const c={kind:"mascot",role:o},u=L7(e,c);return n.jsx("button",{type:"button",className:"meet-face","data-kind":"image","data-chosen":u?"true":void 0,"aria-pressed":u,"aria-label":z.assistant.mascot(o),disabled:i,onClick:()=>t(c),children:n.jsx("img",{src:ka(o),alt:""})},o)})]}),n.jsx("div",{className:"meet-face-row",children:rU.map(o=>{const c=(e==null?void 0:e.kind)==="emoji"&&e.value===o;return n.jsx("button",{type:"button",className:"meet-face","data-chosen":c?"true":void 0,"aria-pressed":c,disabled:i||a,onClick:()=>t({kind:"emoji",value:o}),children:o},o)})}),l]})}const _7=["mirror","en","fr"],z7=[{value:"3h",label:"3 hours"},{value:"1d",label:"A day"},{value:"1w",label:"A week"},{value:"never",label:"Never"}],fp=10,mp=500,mR=[{id:"identity",label:"Identity"},{id:"brain",label:"Brain"},{id:"tools",label:"Tools"},{id:"team",label:"Team"}],dN=e=>{var t;return e==="access"?"tools":((t=mR.find(s=>s.id===e))==null?void 0:t.id)??"identity"};function U7({agentId:e,section:t,navigate:s}){var v,b,j;const{data:r,error:i,reload:a}=de(()=>$.agents(),[]),[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(dN(t));d.useEffect(()=>f(dN(t)),[t]);const m=x=>{f(x),s==null||s(Et(e,"setup",x))},p=async x=>{o(null),u(null);try{const w=await x;u(w.changed.length===0?`No file change needed. ${w.note}.`:`Changed ${w.changed.join(", ")}. ${w.note}.`),a()}catch(w){o(w instanceof Error?w.message:String(w))}},g=r==null?void 0:r.agents.find(x=>x.id===e);return n.jsxs(le,{gap:"lg",children:[n.jsx(Zc,{level:"secondary",label:"Setup",children:mR.map(x=>n.jsx(Tl,{href:Et(e,"setup",x.id),active:h===x.id,onClick:w=>{w.preventDefault(),m(x.id)},children:x.label},x.id))}),n.jsx(re,{message:i??l}),c?n.jsx(V,{tone:"good",role:"status",children:c}):null,r?g?n.jsx(B7,{agent:g,all:r.agents,engine:r.engines.find(x=>x.id===g.id),providers:r.providers,accounts:r.providerAccounts,shown:h,onShow:m,onRun:p,onSaved:a},`${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}`):n.jsx(pe,{children:"This agent is not installed as a file."}):n.jsx(pe,{children:"Loading…"})]})}function B7({agent:e,all:t,engine:s,providers:r,accounts:i,shown:a,onShow:l,onRun:o,onSaved:c}){const u=(s==null?void 0:s.provider)??e.provider.kind,h=r.find(N=>N.kind===u),f=(s==null?void 0:s.model)??e.model,[m,p]=d.useState(String((s==null?void 0:s.maxTurns)??e.maxTurns)),[g,v]=d.useState(null),b=N=>{o($.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=(h==null?void 0:h.models.map(N=>N.id))??[],w=x.includes(f)?x:[f,...x],y=s?s.available:!0,k=(s==null?void 0:s.unavailableReason)??"no credential";return n.jsxs(n.Fragment,{children:[n.jsx("div",{hidden:a!=="identity",children:n.jsxs(le,{gap:"lg",children:[y?null:n.jsxs(V,{tone:"warning",children:["This agent cannot run right now."," ",n.jsx("a",{href:Et(e.id,"setup","brain"),onClick:N=>{N.preventDefault(),l("brain")},children:"See Brain."})]}),n.jsx(W7,{agent:e,onSaved:c})]})}),n.jsx("div",{hidden:a!=="brain",children:n.jsxs(le,{gap:"lg",children:[y?null:n.jsxs(V,{tone:"warning",children:["This agent cannot run right now: ",k,"."]}),n.jsx(ue,{panel:!0,children:n.jsxs(le,{divided:!0,children:[n.jsxs(ue,{title:"Runs on",children:[i?n.jsx(J7,{agentId:e.id,accounts:i,onRun:o}):n.jsxs(Hs,{children:[n.jsx(oe,{label:"Provider",children:n.jsx("select",{value:u,onChange:N=>j(N.target.value),children:r.map(N=>n.jsxs("option",{value:N.kind,children:[N.kind,N.usable?"":" (no credential)"]},N.kind))})}),n.jsxs(oe,{label:"Model",children:[n.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()})}}),n.jsx("datalist",{id:`models-${e.id}`,children:w.map(N=>n.jsx("option",{value:N},N))})]})]}),i?null:n.jsxs("p",{className:"ui-card-meta",children:[(s==null?void 0:s.credentialKind)??e.provider.credentialKind," from"," ",n.jsx("span",{className:"mono",children:(s==null?void 0:s.credentialEnv)??e.provider.credentialEnv}),h&&!h.usable?` · default model ${h.defaultModel} (${h.defaultFrom})`:""]}),s!=null&&s.restartRequired?n.jsx("p",{className:"warning",children:"This file has changed since the service loaded it. Run `buddi service restart`."}):null]}),n.jsx(ue,{title:"Behaviour",aside:"saved as you change them",children:n.jsxs(Hs,{children:[n.jsx(oe,{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?n.jsx("span",{className:"critical save-error",role:"alert",children:g}):null,children:n.jsx("input",{type:"number",min:fp,max:mp,value:m,onChange:N=>{p(N.target.value),v(null)},onBlur:()=>{const N=Number(m);if(!Number.isInteger(N)||N<fp||N>mp){v(`Between ${fp} and ${mp}.`);return}N!==((s==null?void 0:s.maxTurns)??e.maxTurns)&&b({maxTurns:N})}})}),n.jsx(oe,{label:"Language",hint:"Mirror answers in whatever language you write.",children:n.jsx("select",{value:(s==null?void 0:s.language)??e.language,onChange:N=>b({language:N.target.value}),children:_7.map(N=>n.jsx("option",{value:N,children:N},N))})}),s?n.jsx(oe,{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:n.jsx("select",{"aria-label":"New chat after",value:s.idleRollover??"3h",onChange:N=>b({idleRollover:N.target.value==="3h"?null:N.target.value}),children:z7.map(N=>n.jsx("option",{value:N.value,children:N.label},N.value))})}):null,fE(mE(s??{id:e.id,provider:u},i))?n.jsx(oe,{label:"Thinking",hint:"Reasoning before the answer. Off is faster and cheaper.",children:n.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:[n.jsx("option",{value:"default",children:"Model default"}),n.jsx("option",{value:"on",children:"On"}),n.jsx("option",{value:"off",children:"Off"})]})}):n.jsx(oe,{label:"Thinking",hint:BL,children:n.jsx("span",{className:"ui-card-meta",children:"Up to the model"})})]})})]})}),n.jsx(Tt,{summary:"Built-in context",boxed:!0,children:n.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."})})]})}),n.jsx("div",{hidden:a!=="tools",children:n.jsxs(le,{gap:"lg",children:[n.jsx(H7,{agent:e,all:t,onSaved:c}),n.jsx(O7,{agentId:e.id,agentName:e.name,readOnly:e.isExample===!0,version:e.tools.join(","),onSaved:c})]})}),n.jsx("div",{hidden:a!=="team",children:n.jsx(le,{gap:"lg",children:n.jsx(eG,{agent:e,all:t,onSaved:c})})})]})}function pR({dirty:e,busy:t,failure:s,label:r,onSave:i}){return n.jsxs(n.Fragment,{children:[s?n.jsx("span",{className:"critical save-error",role:"alert",children:s}):n.jsx("span",{className:e?"warning":"muted",children:e?"Not saved yet.":"Saved. Applies to new runs."}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(A,{variant:"accent",disabled:!e||t,onClick:i,children:r})]})}const gR=n.jsx(V,{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 W7({agent:e,onSaved:t}){var F;const[s,r]=d.useState(e.name),[i,a]=d.useState(e.handle),[l,o]=d.useState(e.description),[c,u]=d.useState(e.avatar??""),[h,f]=d.useState(!1),m=de(()=>$.agentFile(e.id),[e.id]),[p,g]=d.useState(null),v=((F=m.data)==null?void 0:F.persona.trim())??"",b=p??v,j=m.data!==void 0&&p!==null&&p.trim()!==v,[x,w]=d.useState(!1),[y,k]=d.useState(null),[N,S]=d.useState(null),C=s.trim()!==e.name||i.trim().replace(/^@/,"")!==e.handle||l.trim()!==e.description||c.trim()!==(e.avatar??"")||j,E=c.trim()!==""&&(c.trim()!==(e.avatar??"")||!e.picture),R=Fx(E?{...e,avatar:c.trim()}:e),I={...R?{avatar:R}:{},...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...!E&&e.picture?{picture:e.picture}:{}},L=async()=>{w(!0),k(null),S(null);try{const T=await $.updateAgentFile(e.id,{name:s.trim(),handle:i.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 $.removeAgentPicture(e.id),window.dispatchEvent(new Event(gr))),g(null),m.reload(),S(T.message),t()}catch(T){k(T instanceof Error?T.message:String(T))}finally{w(!1)}};return n.jsx(ue,{title:"Who it is",aside:n.jsx("span",{className:"mono",children:e.id}),panel:!0,foot:e.isExample?void 0:n.jsx(pR,{dirty:C,busy:x,failure:y,label:"Save who it is",onSave:()=>void L()}),children:n.jsxs(le,{children:[e.isExample?gR:null,N?n.jsx(V,{tone:"good",role:"status",children:N}):null,n.jsxs(Hs,{children:[n.jsx(oe,{label:"Name",hint:"What it is called, everywhere.",children:n.jsx("input",{value:s,disabled:x||e.isExample,onChange:T=>r(T.target.value)})}),n.jsx(oe,{label:"Handle",hint:"What you type to reach it. One handle, one agent.",children:n.jsx("input",{value:i,disabled:x||e.isExample,onChange:T=>a(T.target.value)})})]}),n.jsxs(ae,{children:[n.jsx(Sn,{id:e.id,name:s.trim()||e.name,size:"xl",face:I}),n.jsx(A,{"aria-expanded":h,onClick:()=>f(T=>!T),children:h?"Hide faces":"Change face"})]}),h?n.jsx(q7,{agent:e,avatar:c,onEmoji:u,onChanged:t,disabled:x}):null,n.jsx(oe,{label:"Description",hint:"One or two sentences. Its colleagues read this.",children:n.jsx("textarea",{rows:2,value:l,disabled:x||e.isExample,onChange:T=>o(T.target.value)})}),n.jsx(oe,{label:"Persona",hint:n.jsxs(n.Fragment,{children:["Who it is and how it works, in its own file. It reads this before every conversation; ",n.jsx("code",{children:"{{today}}"})," is filled in with the date at run time."]}),wide:!0,children:m.error?n.jsx(re,{message:m.error}):m.data?n.jsx("textarea",{className:"setup-persona",value:b,rows:Math.max(6,b.split(`
119
+ `).length+1),disabled:x||e.isExample,onChange:T=>g(T.target.value)}):n.jsx(pe,{children:"Reading its file…"})})]})})}function H7({agent:e,all:t,onSaved:s}){var E;const r=de(()=>$.agentTools(e.id),[e.id,e.tools.join(",")]),[i,a]=d.useState(null),[l,o]=d.useState(()=>new Set((e.roles??[]).filter($k))),[c,u]=d.useState((e.roles??[]).filter(R=>!$k(R)).join(", ")),[h,f]=d.useState(!1),[m,p]=d.useState(null),[g,v]=d.useState(null),b=(R,I)=>R.split(I).map(L=>L.trim()).filter(L=>L!==""),j=((E=r.data)==null?void 0:E.granted)??e.tools,x=i??j,w=r.data!==void 0&&!n7(x,j),y=Rk(l,b(c,/[\n,]/)),k=R=>o(I=>{const L=new Set(I);return L.has(R)?L.delete(R):L.add(R),L}),S=w||!((R,I)=>R.join(",")===I.join(","))(y,Rk(new Set(e.roles??[]),e.roles??[])),C=async()=>{f(!0),p(null),v(null);try{const R=await $.updateAgentFile(e.id,{...w&&r.data?{tools:t7(r.data.groups,x)}:{},roles:y});v(R.message),a(null),r.reload(),s()}catch(R){p(R instanceof Error?R.message:String(R))}finally{f(!1)}};return n.jsx(ue,{title:"Roles and tools",panel:!0,foot:e.isExample?void 0:n.jsx(pR,{dirty:S,busy:h,failure:m,label:"Save roles and tools",onSave:()=>void C()}),children:n.jsxs(le,{children:[e.isExample?gR:null,g?n.jsx(V,{tone:"good",role:"status",children:g}):null,n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",id:`roles-${e.id}`,children:"Roles"}),n.jsx("div",{className:"role-chips",role:"group","aria-labelledby":`roles-${e.id}`,children:Oj.map(R=>{const I=tz(t,R.id),L=I&&I.id!==e.id?I:void 0;return n.jsxs("button",{type:"button",className:"role-chip","aria-pressed":l.has(R.id),"data-on":l.has(R.id)?"true":void 0,disabled:h||e.isExample,onClick:()=>k(R.id),children:[n.jsx("span",{className:"role-chip-label",children:R.label}),n.jsx("span",{className:"role-chip-meaning",children:R.meaning}),L?n.jsxs("span",{className:"role-chip-holder",children:["Held by ",L.name,". If both claim it, the one listed first keeps it."]}):null]},R.id)})}),n.jsx("span",{className:"ui-field-hint",children:"Where buddi sends things when you do not say who. Tools are granted below."})]}),n.jsx(oe,{label:"Other roles",hint:"Only a plugin that asks for a role by name reads these. Comma separated.",children:n.jsx("input",{value:c,disabled:h||e.isExample,onChange:R=>u(R.target.value)})}),n.jsxs("div",{className:"ui-field",children:[n.jsxs("span",{className:"ui-field-label",children:["Tools · ",j.length," granted"]}),r.error?n.jsx(re,{message:r.error}):r.data?n.jsx(r7,{view:r.data,chosen:x,onChange:a,disabled:h||e.isExample}):n.jsx(pe,{children:"Loading the installed tools…"})]}),n.jsx(K7,{agentId:e.id,version:j.join(","),disabled:h||e.isExample}),V7(j)?n.jsx(G7,{agentId:e.id}):null]})})}function K7({agentId:e,version:t,disabled:s}){var g;const r=de(()=>Promise.resolve().then(()=>$.rememberedApprovals(e)),[e,t]),i=de(()=>Promise.resolve().then(()=>$.connections()).catch(()=>null),[]),[a,l]=d.useState(null),[o,c]=d.useState(null),u=((g=r.data)==null?void 0:g.tools)??[];if(u.length===0)return null;const h=async(v,b)=>{l(v),c(null);try{await $.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=i.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 n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Connection tools that ask first"}),n.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),w=j.filter(k=>k.remembered),y=n.jsxs("span",{className:"remembered-summary",children:[n.jsx("span",{className:"remembered-name",children:m(v)}),n.jsxs("span",{className:"ui-card-meta",children:[` · ${b.length} ask first`,w.length>0?` · ${w.length} remembered: ${w.map(p).join(", ")}`:""]})]});return n.jsxs(Tt,{summary:y,boxed:!0,children:[n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":`${m(v)}: remember my approval`,children:j.map(k=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:k.remembered,disabled:s||a!==null,onChange:N=>void h(k.tool,N.target.checked),"aria-label":`Remember my approval for ${k.tool}`}),n.jsx("span",{className:"mono",children:p(k)})]},k.tool))}),x.length>0?n.jsxs("p",{className:"ui-card-meta remembered-always",children:["These can delete or destroy something, so they always ask and are never remembered:"," ",n.jsx("span",{className:"mono",children:x.map(p).join(", ")})]}):null]},v)})}),n.jsx(re,{message:o}),n.jsx("span",{className:"ui-field-hint",children:"Tick a tool to remember your approval: it asks once, then runs for this agent."})]})}function V7(e){return e.some(t=>t==="owner.notify"||t==="owner.*"||t==="owner.notify?"||t==="owner.*?")}function G7({agentId:e}){var h,f;const t=de(()=>$.notificationSettings(),[]),[s,r]=d.useState(null),[i,a]=d.useState(!1),[l,o]=d.useState(null),c=s??((f=(h=t.data)==null?void 0:h.settings.agents)==null?void 0:f.muted.includes(e))??!1,u=m=>{a(!0),o(null),r(m),$.setAgentMuted(e,m).then(p=>r(p.agents.muted.includes(e))).catch(p=>{r(!m),o(p instanceof Error?p.message:String(p))}).finally(()=>a(!1))};return n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Messages to you"}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:c,disabled:i||!t.data,onChange:m=>u(m.target.checked),"aria-label":"Mute this agent's messages"}),n.jsx("span",{children:"Mute its messages"})]}),n.jsx(re,{message:t.error??l}),n.jsx("span",{className:"ui-field-hint",children:"With owner.notify it can message you itself; muted, it is refused and told so."})]})}function Fx(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 q7({agent:e,avatar:t,onEmoji:s,onChanged:r,disabled:i}){const[a,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(null),f=t.trim()!==""&&(t.trim()!==(e.avatar??"")||!e.picture),m=a??(f?{kind:"emoji",value:t.trim()}:e.picture?{kind:"kept",url:e.picture}:null),p=async g=>{if(h(null),g.kind==="emoji"){s(g.value);return}if(g.kind==="kept"){s(e.avatar??"");return}l(g),c(!0);try{await $.uploadAgentPicture(e.id,await fR(g.role)),s(e.avatar??""),r(),window.dispatchEvent(new Event(gr))}catch(v){h(v instanceof Error?v.message:String(v))}finally{l(null),c(!1)}};return n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Face"}),n.jsx(F7,{face:m,label:"Face",kept:e.picture,disabled:i||o,disableEmoji:e.isExample,onPick:g=>void p(g),children:n.jsx(Y7,{agent:e,onChanged:r})}),u?n.jsx("span",{className:"critical save-error",role:"alert",children:u}):null]})}function Y7({agent:e,onChanged:t}){const[s,r]=d.useState(null),[i,a]=d.useState(null),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(0);d.useEffect(()=>{if(!s)return a(null);const S=URL.createObjectURL(s);return a(S),()=>URL.revokeObjectURL(S)},[s]);const g=S=>{r(null),p(C=>C+1),f(S),t(),window.dispatchEvent(new Event(gr))},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 $.uploadAgentPicture(e.id,s)).note??null),j=()=>v(async()=>(await $.removeAgentPicture(e.id),null)),x={avatar:Fx(e),...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...i??e.picture?{picture:i??e.picture}:{}},[w,y]=d.useState(!1),k=d.useRef(null),N=S=>{u(null),f(null),r(S??null)};return n.jsxs("div",{className:"setup-upload","data-dragging":w?"true":void 0,onDragOver:S=>{S.preventDefault(),l||y(!0)},onDragLeave:()=>y(!1),onDrop:S=>{var C;S.preventDefault(),y(!1),l||N((C=S.dataTransfer.files)==null?void 0:C[0])},children:[n.jsxs(ae,{children:[n.jsx(Sn,{id:e.id,name:e.name,size:"xl",face:x}),n.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),n.jsx(A,{disabled:l,onClick:()=>{var S;return(S=k.current)==null?void 0:S.click()},children:"Upload a picture"}),n.jsx("span",{className:"setup-upload-name",children:s?s.name:"or drop one here"}),n.jsx("span",{className:"ui-toolbar-spacer"}),e.picture&&!s?n.jsx(A,{variant:"ghost",disabled:l,onClick:()=>void j(),children:"Remove picture"}):null,n.jsx(A,{variant:"accent",disabled:!s||l,onClick:()=>void b(),children:"Save picture"})]}),c?n.jsx("span",{className:"critical save-error",role:"alert",children:c}):n.jsx("span",{className:"ui-field-hint",children:h??"Your own picture: a PNG, GIF or SVG up to 1 MB, kept as a square PNG; a GIF keeps its first frame."})]})}function J7({agentId:e,accounts:t,onRun:s}){const r=t.bindings.find(p=>p.agentId===e),[i,a]=d.useState((r==null?void 0:r.accountId)??""),[l,o]=d.useState((r==null?void 0:r.model)??""),[c,u]=d.useState(!1),h=t.accounts.find(p=>p.id===i),f=i!==((r==null?void 0:r.accountId)??"")||l!==((r==null?void 0:r.model)??""),m=t.accounts.find(p=>p.id===(r==null?void 0:r.accountId));return n.jsxs("div",{className:"ui-stack",children:[n.jsxs(ae,{valign:"end",children:[n.jsx(oe,{label:"Account",children:n.jsxs("select",{value:i,disabled:c,onChange:p=>{var g;a(p.target.value),o(((g=t.accounts.find(v=>v.id===p.target.value))==null?void 0:g.defaultModel)??"")},children:[n.jsx("option",{value:"",children:"Choose an account"}),t.accounts.map(p=>n.jsxs("option",{value:p.id,disabled:!p.enabled,children:[p.label,p.enabled?p.configured?"":" (needs credential)":" (disabled)"]},p.id))]})}),n.jsx(Lw,{accountId:h!=null&&h.configured?i:void 0,label:"Model",value:l,onChange:o,disabled:c},`${i}:${h==null?void 0:h.revision}`)]}),n.jsxs(ae,{children:[f&&i&&l.trim()?n.jsxs("span",{className:"warning",children:["Not saved yet. New runs still use ",m?`${m.label}, ${(r==null?void 0:r.model)??""}`:"nothing","."]}):n.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."}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(A,{variant:"accent",disabled:c||!i||!l.trim()||!f,onClick:()=>{u(!0),s($.assignProviderAccount(e,i,l).finally(()=>u(!1)))},children:"Save account selection"})]})]})}const Q7=["platform.create_agent","platform.update_agent","platform.write_skill","platform.delete_agent","platform.accept_plugin_agent","platform.accept_plugin_skill"],pp=e=>e.tools.some(t=>Q7.includes(t)),X7=["front-desk","maker"],Z7={"front-desk":"Can ask: everyone, as the front desk",maker:"Can ask: everyone, as the maker",list:"Can ask: everyone"};function eG({agent:e,all:t,onSaved:s}){const[r,i]=d.useState(e.delegates),[a,l]=d.useState(!1),[o,c]=d.useState(null),[u,h]=d.useState(!1),[f,m]=d.useState(e.delegates),[p,g]=d.useState(e.asksEveryone),[v,b]=d.useState(!1),j=t.filter(R=>R.id!==e.id),x=X7.find(R=>{var I;return(I=e.roles)==null?void 0:I.includes(R)}),w=p===void 0||v,y=v||[...r].sort().join(",")!==[...f].sort().join(","),k=t.filter(R=>R.id!==e.id&&(R.delegates.includes(e.id)||R.asksEveryone!==void 0&&!pp(e))),N=R=>i(I=>I.includes(R)?I.filter(L=>L!==R):[...I,R]),S=async R=>{l(!0),c(null),h(!1);try{const I=await $.setDelegates(e.id,R);m(I.delegates),i(I.delegates),g(I.asksEveryone),b(!1),h(!0),s()}catch(I){c(I instanceof Error?I.message:String(I))}finally{l(!1)}},C=()=>{i(j.filter(R=>!pp(R)).map(R=>R.id)),b(!0),h(!1)},E=y?"Not saved yet.":u?"Saved. Applies to the next run.":w?r.length===0?"Asks nobody.":`May ask ${r.length} agent${r.length===1?"":"s"}.`:"Asks everyone.";return n.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:n.jsxs(n.Fragment,{children:[n.jsx("span",{className:y?"warning":"muted",children:E}),n.jsx("span",{className:"ui-toolbar-spacer"}),w&&x!==void 0?n.jsx(A,{disabled:a,onClick:()=>void S(["*"]),children:"Let it ask everyone"}):null,w?n.jsx(A,{variant:"accent",disabled:!y||a,onClick:()=>void S(r),children:"Save who it can ask"}):n.jsx(A,{variant:"accent",disabled:a,onClick:C,children:"Limit to…"})]}),children:n.jsxs(le,{divided:!0,children:[n.jsxs(ue,{title:"Can ask",children:[e.isExample?n.jsx(V,{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,n.jsx(re,{message:o}),w?j.length===0?n.jsx(pe,{children:"Nobody else is installed."}):n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"ui-card-meta",children:"Only the agents ticked here. New teammates must be added here before it can ask them."}),n.jsx("ul",{className:"ui-list delegate-list","aria-label":"Agents this one may ask",children:j.map(R=>{const I=pp(R);return n.jsxs("li",{className:"ui-list-row",children:[n.jsx("input",{type:"checkbox",id:`can-ask-${e.id}-${R.id}`,checked:r.includes(R.id),disabled:I||e.isExample||a,onChange:()=>N(R.id)}),n.jsxs("label",{htmlFor:`can-ask-${e.id}-${R.id}`,className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[R.name," ",n.jsxs("span",{className:"mono muted",children:["@",R.handle]})]}),n.jsx("span",{className:"ui-list-sub",children:I?"Makes and changes agents. Never reachable by delegation.":R.description})]})]},R.id)})})]}):n.jsxs("p",{className:"ui-card-meta",children:[Z7[p??"list"],". New agents are included without being added here; agents that make and change agents are never reachable by delegation."]})]}),n.jsx(ue,{title:"Asked by",children:k.length===0?n.jsxs("p",{className:"ui-card-meta",children:["No other agent may hand work to ",e.name,"."]}):n.jsx(JU,{children:k.map(R=>n.jsx(we,{children:R.name},R.id))})})]})})}const tG=[{id:"team",label:"Team"},{id:"missions",label:"Missions"},{id:"offers",label:"Offers"},{id:"reminders",label:"Reminders"},{id:"skills",label:"Skills"}],nG=[{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 sG(e){const t=D4(e.hash);return t?n.jsx(jV,{name:t.name,agents:e.agents,navigate:e.navigate,pluginPages:e.pluginPages}):n.jsx(rG,{...e})}function rG({hash:e,timezone:t,navigate:s,agents:r,attention:i,defaultAgentId:a}){var j,x,w,y,k;const l=I4(e),o=((j=/[?&]tab=([a-z]+)/.exec(e))==null?void 0:j[1])??"team",c=N=>S=>{S.preventDefault(),s(N)},u=de(()=>$.agents(),[]),h=Ef(),f=de(()=>$.offers(),[],2e4),m=IT(),p=(((x=f.data)==null?void 0:x.offers.length)??0)+m.offers.length,g=((y=(w=u.data)==null?void 0:w.default)==null?void 0:y.defaultAgentId)??a??null,[v,b]=d.useState(null);return n.jsxs("div",{className:"ui-page",children:[n.jsx(Al,{title:"Agents",lede:o==="skills"?`Skills are short texts an agent follows for one kind of task. Each is a file on ${h}.`:`Your team. Each one is a file on ${h} — what it can reach is listed on its page.`,actions:o==="skills"?n.jsxs(n.Fragment,{children:[n.jsx(A,{onClick:()=>b({kind:"upload",at:Date.now()}),children:"Upload a .md"}),n.jsx(A,{variant:"accent",onClick:()=>b({kind:"write",at:Date.now()}),children:"Write a skill"})]}):n.jsx(dt,{variant:"accent",href:Ht(),onClick:c(Ht()),children:"Add a teammate"})}),n.jsx(Zc,{children:tG.map(N=>n.jsx(Tl,{href:N.id==="team"?pt:`${pt}?tab=${N.id}`,active:o===N.id,count:N.id==="offers"?p:void 0,onClick:c(N.id==="team"?pt:`${pt}?tab=${N.id}`),children:N.label},N.id))}),o==="missions"?n.jsx(D$,{timezone:t,embedded:!0}):null,o==="offers"?n.jsx(PT,{offers:m.offers,reload:m.reload}):null,o==="offers"?n.jsx(L$,{embedded:!0}):null,o==="reminders"?n.jsx(Z$,{timezone:t,embedded:!0}):null,o==="skills"?n.jsx(UV,{faces:r,navigate:s,command:v,openSkill:RV(e)}):null,o==="team"?n.jsx(iG,{data:u.data,error:u.error,reload:u.reload}):null,o==="team"?r.length===0?n.jsx(In,{icon:"agents",title:"No agents yet",children:"Each agent is a file in the installation's agents folder."}):n.jsx("div",{className:"agents-grid",children:bA(r,g).map(N=>{const S=xf(i.get(N.id));return n.jsxs("div",{className:"ui-card agent-card","data-interactive":"true",...Yc(qc(N)),"data-unavailable":N.available?void 0:"true",children:[n.jsx("div",{className:"agent-card-top"}),n.jsx("div",{className:"agent-card-face",children:n.jsx(Sn,{id:N.id,name:N.name,size:"xl",unavailable:!N.available,face:N})}),n.jsxs("div",{children:[n.jsxs("div",{className:"ui-card-title",children:[n.jsx("a",{className:"agent-card-link",href:Et(N.id,"conversations"),onClick:c(Et(N.id,"conversations")),children:N.name}),n.jsxs("span",{className:"agent-card-handle mono faint",children:["@",N.handle]})]}),n.jsx("p",{className:"ui-card-meta agent-card-desc",children:N.description})]}),n.jsxs("div",{className:"ui-row",children:[N.id===g?n.jsx(kc,{children:"front desk"}):null,S?n.jsx(we,{tone:"critical",dot:!0,children:"waiting for you"}):N.available?n.jsx(we,{tone:"good",dot:!0,children:"ready"}):n.jsx(we,{tone:"warning",children:Bs(N.unavailableReason??"cannot run",60)}),n.jsx(we,{mono:!0,children:N.model}),n.jsx(dt,{className:"agent-card-talk",size:"sm",href:st(N.id),onClick:c(st(N.id)),"aria-label":`Talk to ${N.name}`,children:"Talk"})]})]},N.id)})}):null,l?n.jsx(Ye,{title:((k=r.find(N=>N.id===l.agentId))==null?void 0:k.name)??l.agentId,size:"wide",onClose:()=>s(pt),children:n.jsx(aG,{agentId:l.agentId,agent:r.find(N=>N.id===l.agentId),agents:r,tab:l.tab??"conversations",...l.section?{section:l.section}:{},timezone:t,navigate:s,attention:i})}):null]})}function iG({data:e,error:t,reload:s}){const r=e==null?void 0:e.default,[i,a]=d.useState(null),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(null);if(t)return n.jsx(re,{message:t});if(!r||r.choices.length===0)return null;const m=r.defaultAgentId,p=i??m??"",g=p!==""&&p!==m,v=r.problem,b=x=>x.map(w=>{var y;return((y=r.choices.find(k=>k.id===w))==null?void 0:y.name)??w}).join(" and "),j=async()=>{o(!0),u(null),f(null);try{const x=await $.setDefaultAgent(p);f(x.note),a(null),s()}catch(x){u(x instanceof Error?x.message:String(x))}finally{o(!1)}};return n.jsx(qe,{children:n.jsxs("div",{className:"ui-stack",children:[n.jsx(re,{message:c}),(v==null?void 0:v.code)==="multiple-defaults"?n.jsx(V,{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"?n.jsx(V,{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,h?n.jsx(V,{tone:"good",role:"status",children:h}):null,n.jsxs(ae,{children:[n.jsxs("div",{className:"default-agent-text",children:[n.jsx("h3",{className:"default-agent-title",children:"Default agent"}),n.jsx("span",{className:"ui-field-hint",children:"Where a chat that names nobody lands."})]}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsxs("select",{"aria-label":"Default agent",value:p,disabled:l,onChange:x=>a(x.target.value),children:[p===""?n.jsx("option",{value:"",children:"Choose an agent"}):null,r.choices.map(x=>n.jsxs("option",{value:x.id,disabled:!x.available,children:[x.name," @",x.handle,x.available?"":" (cannot run)"]},x.id))]}),n.jsx(A,{variant:"accent",disabled:l||!g,onClick:()=>void j(),children:"Save"})]})]})})}function aG({agentId:e,agent:t,agents:s,tab:r,section:i,timezone:a,navigate:l,attention:o}){const c=p=>g=>{g.preventDefault(),l(p)},u=xf(o.get(e)),h=(t==null?void 0:t.name)??e,f=kV(e),m=t!==void 0&&!t.roles.includes(Jc)&&!t.roles.includes(Gc);return n.jsxs("div",{className:"ui-stack","data-gap":"lg",children:[n.jsxs("header",{className:"agent-head",children:[n.jsx(Sn,{id:e,name:h,size:"xl",unavailable:t?!t.available:!1,face:t}),n.jsxs("div",{className:"agent-head-text",children:[n.jsx("p",{className:"ui-page-lede",children:(t==null?void 0:t.description)??"This agent is not in the roster right now."}),f.entry?n.jsx(NV,{entry:f.entry,navigate:l,onUpdated:f.reload}):null,n.jsxs("div",{className:"ui-row",children:[t?n.jsxs("span",{className:"muted mono",children:["@",t.handle]}):null,t?n.jsx("span",{className:"muted",children:t.model}):null,u?n.jsx(we,{tone:"critical",children:u}):t&&!t.available?n.jsx(we,{tone:"warning",children:t.unavailableReason??"cannot run"}):null]})]}),n.jsx("div",{className:"ui-page-actions",children:n.jsxs(dt,{variant:"accent",href:st(e),onClick:c(st(e)),children:["Talk to ",h]})})]}),t&&!t.available?n.jsxs(V,{tone:"warning",role:"status",children:[NA(t)," ",n.jsx("a",{href:Pe(Xg(t).section),children:Xg(t).label})]}):null,n.jsx(Zc,{children:nG.map(p=>n.jsx(Tl,{href:Et(e,p.id),active:r===p.id,onClick:c(Et(e,p.id)),children:p.label},p.id))}),r==="conversations"?n.jsx(lG,{agentId:e,navigate:l}):null,r==="missions"?n.jsx(D$,{timezone:a,embedded:!0,agentId:e}):null,r==="offers"?n.jsx(L$,{embedded:!0,agentId:e,agentName:h}):null,r==="reminders"?n.jsx(Z$,{timezone:a,embedded:!0,agentId:e}):null,r==="memory"?n.jsx(H$,{embedded:!0,agents:s,timezone:a,agentId:e}):null,r==="skills"?n.jsx(QV,{agentId:e,agentName:h,faces:s,navigate:l}):null,r==="setup"?n.jsx(U7,{agentId:e,section:i,navigate:l}):null,r==="setup"&&m?n.jsx(CV,{agentId:e,name:h,navigate:l}):null]})}function lG({agentId:e,navigate:t}){const{data:s,error:r}=de(()=>Ve.conversations(e,50),[e]);if(r)return n.jsx(pe,{children:r});const i=(s==null?void 0:s.conversations)??[];return n.jsx(qe,{flush:!0,children:s?i.length===0?n.jsx(In,{icon:"chat",title:"No conversations yet",children:"Say hello, and the conversation shows up here."}):n.jsx(rt,{children:i.map(a=>n.jsx(et,{href:st(e,a.id),onClick:()=>t(st(e,a.id)),title:Bs(a.preview||a.opening||"Untitled conversation",90),sub:`${a.messageCount} message${a.messageCount===1?"":"s"}`,side:Fe(a.lastMessageAt??a.startedAt??a.createdAt??null)},a.id))}):n.jsx(pe,{children:"Loading…"})})}const oG=3e4;function xR(){const{data:e,reload:t}=de(()=>$.recovery(),[],oG),s=d.useRef(t);return s.current=t,d.useEffect(()=>{const r=()=>s.current(),i=()=>{document.visibilityState==="visible"&&r()};return window.addEventListener("focus",r),document.addEventListener("visibilitychange",i),()=>{window.removeEventListener("focus",r),document.removeEventListener("visibilitychange",i)}},[]),{data:e,reload:t}}function hN(e){return e.kind==="account"?e.accountId?fA(e.accountId):Pe("accounts"):e.kind==="telegram"?Pe("telegram"):e.kind==="connection"?e.connectionId?mA(e.connectionId):Pe("connections"):e.kind==="email"?e.settingsRoute:Pe("secrets")}function cG(e){return e.install?W4(e.install):H4}const uG=Pe("system");function dG(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 vR="This buddi was restored from a backup. Nothing runs on its own until you finish the checklist.";function hG({view:e,onLeft:t}){const{secrets:s,plugins:r,pending:i,grants:a}=e.checklist,l=e.checklist.keptTables??[],[o,c]=d.useState(!0),[u,h]=d.useState([]),[f,m]=d.useState(!1),[p,g]=d.useState(null),[v,b]=d.useState(!1),j=r.filter(k=>!k.installed||k.waiting!==void 0||k.loadsAtRestart===!0),x=i.jobs+i.missions+i.approvals+i.telegramChats,w=k=>{h(N=>N.includes(k)?N.filter(S=>S!==k):[...N,k])},y=()=>{m(!0),g(null),gf({kind:"recovery"},()=>$.leaveRecovery({dropPending:o,keepGrants:u})).then(k=>{k&&k.restarting===!1&&El(),b(!0),t==null||t()}).catch(k=>g(k instanceof ve?k.message:String(k))).finally(()=>m(!1))};return n.jsx(qe,{title:"Back from a backup",children:n.jsxs(le,{divided:!0,children:[n.jsxs(ue,{children:[n.jsx(Gt,{items:[{label:"Restored",value:e.restoredAt??"just now"},{label:"From",value:n.jsx("span",{className:"mono",children:e.archive??"—"})}]}),n.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."})]}),n.jsx(ue,{title:"Keys to paste again",children:s.length===0?n.jsx(pe,{children:"Nothing is missing."}):n.jsx(rt,{children:s.map(k=>n.jsx(et,{title:k.label??k.name,sub:k.name?n.jsx("span",{className:"mono",children:k.name}):void 0,side:k.signIn?n.jsx(dt,{size:"sm",href:hN(k),"aria-label":`Sign in again: ${k.label??k.name}`,children:"Sign in again"}):n.jsx(dt,{size:"sm",href:hN(k),"aria-label":`Fix ${k.label??k.name}`,children:"Fix"})},`${k.kind}:${k.accountId??k.name}`))})}),n.jsx(ue,{title:"Add-ons to install again",children:j.length===0&&l.length===0?n.jsx(pe,{children:"Everything the backup named is installed."}):n.jsxs(rt,{children:[j.map(k=>n.jsx(et,{title:n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"mono",children:k.name})," ",k.version]}),sub:dG(k),side:k.loadsAtRestart?n.jsx(dt,{size:"sm",href:uG,"aria-label":`Restart to load ${k.name}`,children:"Restart"}):k.installed?void 0:n.jsx(dt,{size:"sm",href:cG(k),"aria-label":`Install ${k.name} again`,children:k.install?"Install":"Find it"})},k.name)),l.map(k=>n.jsx(et,{title:n.jsx("span",{className:"mono",children:k.table}),sub:k.sentence},`kept:${k.table}`))]})}),n.jsx(ue,{title:"Work that was waiting",children:x===0?n.jsx(pe,{children:"Nothing was in flight when the backup was taken."}):n.jsxs(le,{gap:"sm",children:[n.jsx(Gt,{items:[{label:"Jobs",value:String(i.jobs)},{label:"Missions",value:String(i.missions)},{label:"Waiting for an answer",value:String(i.approvals)},{label:"Phones",value:String(i.telegramChats)}]}),n.jsxs("label",{className:"recovery-check",children:[n.jsx("input",{type:"checkbox",checked:o,onChange:k=>c(k.target.checked)}),n.jsx("span",{children:"Drop it. It was queued somewhere else, days ago."})]})]})}),n.jsx(ue,{title:"Standing permissions",children:a.length===0?n.jsx(pe,{children:"No agent had a standing permission."}):n.jsxs(le,{gap:"sm",children:[n.jsx("p",{className:"ui-card-meta",children:"Each of these lets an agent act without asking. Keep only the ones you meant."}),n.jsx("ul",{className:"recovery-list",children:a.map(k=>n.jsx("li",{children:n.jsxs("label",{className:"recovery-check",children:[n.jsx("input",{type:"checkbox",checked:u.includes(k.id),onChange:()=>w(k.id),"aria-label":`Keep ${k.tool} for ${k.agent}`}),n.jsxs("span",{children:[n.jsx("span",{className:"mono",children:k.tool})," for ",k.agent," ",n.jsx("span",{className:"ui-card-meta",children:k.scope}),k.description?n.jsxs("span",{className:"ui-card-meta",children:[" — ",k.description]}):null]})]})},k.id))})]})}),n.jsx(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsx(re,{message:p}),v?n.jsx(V,{tone:"good",role:"status",children:"Turning everything back on. This page comes back in a few seconds."}):n.jsx("p",{className:"ui-card-meta",children:"Leaving starts the schedules, the watchers and the phone again. buddi restarts itself to do it."}),n.jsx(ae,{align:"end",children:n.jsx(A,{variant:"accent",disabled:f||v,onClick:y,children:"Leave recovery mode"})})]})})]})})}function fG({days:e,mailbox:t,money:s,pictures:r}){const i=[];(t||e)&&i.push("chief-of-staff"),s&&i.push("cfo"),r&&i.push("illustrator");for(const a of["researcher","tutor"])i.length<3&&i.push(a);return i.slice(0,4)}function jR(e,t,s=4){const r=a=>!!a&&_i(a)==="ready"&&a.addable,i=fG(t).map(a=>e.find(l=>l.name===a)).filter(r);for(const a of["researcher","tutor"]){if(i.length>=3)break;const l=e.find(o=>o.name===a);r(l)&&!i.includes(l)&&i.push(l)}return i.slice(0,s)}function mG(e,t){const s=e.filter(r=>r.id!==t&&!r.roles.includes(Gc)&&!r.roles.includes(Jc));return e.length>0&&s.length<=1}async function pG(e,t=z$){try{const{jobId:s}=await $.catalogueInstall(e.name,{version:e.version,tools:e.tools});for(;;){const r=await $.catalogueJob(s);if(r.state!=="running")return r;await new Promise(i=>setTimeout(i,t))}}catch(s){return{error:s instanceof ve?s.message:String(s)}}}function gG({entry:e,checked:t,onChange:s}){return n.jsxs("label",{className:"cat-pick","data-checked":t?"true":void 0,children:[n.jsx("input",{type:"checkbox",checked:t,onChange:r=>s(r.target.checked)}),n.jsx(Xl,{entry:e,size:"lg"}),n.jsxs("span",{className:"cat-pick-text",children:[n.jsx("span",{className:"cat-pick-name",children:e.title}),n.jsx("span",{className:"cat-pick-pitch",children:e.pitch})]})]})}function xG({entry:e,added:t,onOpen:s,onAdd:r}){return n.jsxs("div",{className:"cat-suggest",role:"button",tabIndex:0,"aria-label":`${e.title}: details`,"data-testid":`cat-suggest-${e.name}`,onClick:s,onKeyDown:i=>{i.target===i.currentTarget&&i.key==="Enter"&&s()},children:[n.jsx(Xl,{entry:e,size:"lg"}),n.jsxs("span",{className:"cat-pick-text",children:[n.jsx("span",{className:"cat-pick-name",children:e.title}),n.jsx("span",{className:"cat-pick-pitch",children:e.pitch})]}),t?n.jsxs("span",{className:"cat-added",children:[n.jsx(ce,{name:"check",size:14}),"Added"]}):n.jsx(A,{size:"sm",variant:"accent","aria-label":`Add ${e.title}`,onClick:i=>{i.stopPropagation(),r()},children:"Add"})]})}function vG({navigate:e}){const[t,s]=d.useState(null),[r,i]=d.useState(null),[a,l]=d.useState([]),o=Ew();d.useEffect(()=>{let u=!1;return $.catalogue().then(h=>{u||s(h.unavailable?[]:h.agents)}).catch(()=>{u||s([])}),()=>{u=!0}},[]);const c=d.useMemo(()=>t===null?null:jR(t,{days:!0,mailbox:!0,money:o.has("finance"),pictures:o.has("image")},3),[t,o]);return!c||c.length===0?null:n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"cat-suggest-lede",children:"Teammates who could take a job off your hands, from what you set up:"}),n.jsx("div",{className:"cat-suggests","data-testid":"home-suggestions",children:c.map(u=>n.jsx(xG,{entry:u,added:a.includes(u.name),onOpen:()=>e(Ht(u.name)),onAdd:()=>i(u)},u.name))}),r?n.jsx(U$,{entry:r,navigate:e,onClose:()=>i(null),onAdded:()=>{l(u=>[...u,r.name]),window.dispatchEvent(new Event(gr))}}):null]})}function jG({setUp:e,navigate:t}){var j;const[s,r]=d.useState(null),[i,a]=d.useState([]),[l,o]=d.useState("picking"),[c,u]=d.useState([]),[h,f]=d.useState([]),m=JSON.stringify(e);if(d.useEffect(()=>{let x=!1;return $.catalogue().then(w=>{if(x)return;const y=w.unavailable?[]:jR(w.agents,e);r(y),a(y.map(k=>k.name))}).catch(()=>{x||r([])}),()=>{x=!0}},[m]),!s||s.length===0)return null;const p=()=>t(Ht()),g=async()=>{o("adding");const x=[],w=[];for(const y of s.filter(k=>i.includes(k.name))){const k=await pG(y);"error"in k&&!("state"in k)?w.push({entry:y,error:k.error}):k.state==="done"?x.push(y):k.state==="confirm"?w.push({entry:y,error:"it gets more than its card showed, so it waits for your approval in Needs you"}):w.push({entry:y,error:k.error??"it stopped before it finished"})}u(x),f(w),o("added"),x.length>0&&window.dispatchEvent(new Event(gr))},v=i.length,b=l==="adding"?`Adding ${v===1?((j=s.find(x=>x.name===i[0]))==null?void 0:j.title)??"1":v}…`:v===s.length?"Add these":v>0?`Add these ${v}`:"Tick one to add";return n.jsx("section",{className:"handover-team","aria-label":"Who do you want on your team?","data-testid":"handover-team",children:l==="added"?n.jsxs(n.Fragment,{children:[c.length>0?n.jsxs(V,{tone:"good",role:"status",title:`${Kt(c.map(x=>x.title))} ${c.length===1?"is":"are"} on your team.`,action:n.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,h.length>0?n.jsxs(V,{tone:"critical",role:"alert",title:`${Kt(h.map(x=>x.entry.title))} ${h.length===1?"wasn’t":"weren’t"} added.`,action:c.length===0?n.jsx(A,{variant:"ghost",size:"sm",onClick:p,children:"See all teammates"}):void 0,children:[h.map(x=>`${x.entry.title}: ${x.error.replace(/[.\s]+$/,"")}.`).join(" ")," Nothing else changed; try again from the catalogue."]}):null]}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"handover-team-head",children:[n.jsx("h2",{className:"handover-team-title",children:"Who do you want on your team?"}),n.jsx("p",{className:"cat-small",children:"Picked from what you just set up. Their plugins are already in, so one click adds them all."})]}),n.jsx("div",{className:"cat-picks",children:s.map(x=>n.jsx(gG,{entry:x,checked:i.includes(x.name),onChange:w=>a(w?[...i,x.name]:i.filter(y=>y!==x.name))},x.name))}),n.jsx("div",{className:"handover-team-foot",children:n.jsxs(ae,{children:[n.jsx(A,{variant:"ghost",onClick:p,children:"See all teammates"}),n.jsx(ht,{}),n.jsx(A,{variant:"accent",disabled:v===0||l==="adding",onClick:()=>void g(),children:b})]})})]})})}const fN=3,wG=40;function yG({agent:e,navigate:t}){var g;const s=d.useRef(null),[r,i]=d.useState(!1),[a,l]=d.useState(null),[o,c]=d.useState(null),u=de(()=>Ve.conversations(e.id,fN),[e.id],3e4),h=Ns(Vj),f=Ns("(pointer: coarse)");d.useEffect(()=>{var v;!h&&!f&&((v=s.current)==null||v.focus())},[]);const m=(v,b)=>{i(!0),l(null),(async()=>{try{const{conversationId:j}=await Ve.startConversation(e.id),x=await Ve.send(e.id,{conversationId:j,text:v,...b.length>0?{attachmentIds:b.map(w=>w.artifactId)}:{}});t(st(e.id,x.conversationId))}catch(j){l(j instanceof ve?j.message:String(j)),c({text:v,at:Date.now()}),i(!1)}})()},p=(((g=u.data)==null?void 0:g.conversations)??[]).slice(0,fN);return n.jsxs("div",{className:"home-ask",children:[a?n.jsx(re,{message:a}):null,n.jsx(ow,{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?n.jsxs("div",{className:"home-continue",children:[n.jsx("span",{className:"home-continue-label",id:`home-continue-${e.id}`,children:"Continue"}),n.jsx("ul",{className:"home-continue-chips","aria-labelledby":`home-continue-${e.id}`,children:p.map(v=>{const b=st(e.id,v.id),j=v.opening??v.preview??"Untitled conversation",x=pj(v.lastMessageAt??v.createdAt??v.startedAt??null);return n.jsx("li",{children:n.jsxs("a",{className:"home-continue-chip",href:b,title:j,onClick:w=>{w.preventDefault(),t(b)},children:[n.jsx("span",{className:"home-continue-title",children:Bs(j,wG)}),x?n.jsx("span",{className:"home-continue-when",children:x}):null]})},v.id)})})]}):null]})}function bG(e){const t=e.indexOf("?");if(t===-1)return;const s=new URLSearchParams(e.slice(t+1)).get("tip");return s&&/^[a-z0-9-]{1,40}$/.test(s)?s:void 0}function kG({navigate:e,preview:t,hidden:s}){var c;const r=de(()=>$.currentTip(t),[t]),[i,a]=d.useState(null),l=((c=r.data)==null?void 0:c.tip)??null;if(!l||i===l.id||s)return null;const o=u=>{a(l.id),!t&&(u==="dismiss"?$.dismissTip(l.id):$.laterTip(l.id)).catch(()=>{})};return n.jsx("div",{className:"home-tip","data-tip":l.id,children:n.jsxs(V,{children:[n.jsxs("div",{className:"ui-notice-row",children:[n.jsx("p",{className:"ui-notice-body",children:l.text}),n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"Not now",title:"Not now",onClick:()=>o("later"),children:n.jsx(ce,{name:"close"})})]}),n.jsxs(ae,{children:[n.jsx(ht,{}),n.jsx(A,{variant:"ghost",size:"sm",onClick:()=>o("dismiss"),children:"Not this again"}),n.jsx(A,{variant:"accent",size:"sm",onClick:()=>e(l.action.route),children:l.action.label})]})]})})}const _x="buddi.tipsOpen";function NG(e){return Bc(e,{compact:!0})}function SG(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 ${NG(e.shownAt)}`:"Shown"}}function CG(){try{return window.localStorage.getItem(_x)==="1"}catch{return!1}}function EG(){const e=de(()=>$.tips(),[]),[t,s]=d.useState(CG),r=d.useCallback(i=>{s(i);try{i?window.localStorage.setItem(_x,"1"):window.localStorage.removeItem(_x)}catch{}},[]);return{open:t,setOpen:r,list:e}}function AG({tips:e}){const{open:t,setOpen:s,list:r}=e,i=!!r.data&&!r.data.enabled&&r.data.tips.some(a=>a.status==="today");return n.jsxs("button",{type:"button",className:"ui-icon-btn home-tips-btn","aria-label":i?"Tips, one due today":"Tips","aria-pressed":t,title:"Tips","data-open":t,onClick:()=>{t||r.reload(),s(!t)},children:[n.jsx(ce,{name:"bulb"}),i?n.jsx("span",{className:"home-tips-dot","data-testid":"tips-dot"}):null]})}function TG({tips:e,navigate:t}){var b,j;const{open:s,setOpen:r,list:i}=e,[a,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(null);if(!s)return null;const f=((b=i.data)==null?void 0:b.tips)??null,m=u??((j=i.data)==null?void 0:j.enabled)??!0,p=x=>l(x instanceof ve?x.message:String(x)),g=x=>{c(x),l(null),$.restoreTip(x).then(()=>i.reload(),p).finally(()=>c(null))},v=x=>{c("switch"),l(null),h(x),$.saveTipsSettings(x).then(w=>{h(w.enabled),i.reload()}).catch(w=>{h(!x),p(w)}).finally(()=>c(null))};return n.jsx("div",{className:"home-tips","data-testid":"tips-section",children:n.jsxs(ue,{title:"Tips",children:[n.jsx(re,{message:i.error??a}),n.jsx("div",{className:"tips-grid",children:(f??[]).map(x=>n.jsx("div",{className:"tips-card","data-tip":x.id,"data-status":x.status,children:n.jsxs(ds,{tone:x.status==="today"?"accent":void 0,children:[n.jsx("div",{children:n.jsx(we,{tone:x.status==="today"?"accent":"muted",children:SG(x)})}),n.jsx("p",{className:"tips-card-text",children:x.text}),n.jsxs(ae,{children:[n.jsx(ht,{}),x.status==="dismissed"?n.jsx(A,{size:"sm",disabled:o===x.id,onClick:()=>g(x.id),children:"Bring back"}):n.jsx(A,{size:"sm",variant:x.status==="today"?"accent":void 0,onClick:()=>t(x.action.route),children:x.action.label})]})]})},x.id))}),n.jsxs(ae,{children:[n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:m,disabled:o==="switch"||f===null,onChange:x=>v(x.target.checked)}),n.jsx("span",{children:"Tips on Home"})]}),n.jsx(ht,{}),n.jsx(A,{variant:"ghost",size:"sm",onClick:()=>r(!1),children:"Close"})]})]})})}const wR="buddi.needsYouView";function $G(){try{return window.localStorage.getItem(wR)==="list"?"list":"deck"}catch{return"deck"}}function RG(e){try{window.localStorage.setItem(wR,e)}catch{}}function IG(e,t,s){const r=(t.alsoFrom??[]).filter(i=>i!==t.agentId).map(s);return r.length===0?e:`${e} · also ${r.join(", ")}`}function PG({rows:e,agents:t,label:s,onOpen:r,onDone:i}){const[a,l]=d.useState(0);if(e.length===0)return n.jsx(pe,{mascot:!0,children:"Nothing needs you. Your agents are on it."});const o=Math.min(a,e.length-1),c=e[o],u=e.length>1,h=v=>l((o+v+e.length)%e.length),f=()=>r(c),m=()=>i(c),p=v=>{const b=v.target;b.closest('input, textarea, select, [contenteditable="true"]')||(v.key==="ArrowRight"&&u?(v.preventDefault(),h(1)):v.key==="ArrowLeft"&&u?(v.preventDefault(),h(-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=n.jsxs("span",{className:"home-deck-from",children:[c.agentId?n.jsx(cn,{agents:t,id:c.agentId,size:"sm"}):null,n.jsx("span",{children:s(c)})]});return n.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:n.jsx(ds,{as:"article",title:g,meta:n.jsx("span",{className:"ui-card-meta",children:c.state==="held"?"today":Fe(c.createdAt)}),actions:n.jsxs(n.Fragment,{children:[n.jsxs("span",{className:"home-deck-count","aria-live":"polite",children:[o+1," of ",e.length]}),n.jsx(A,{size:"sm",variant:"ghost","aria-label":"Previous",disabled:!u,onClick:()=>h(-1),children:n.jsx(ce,{name:"chevron-left"})}),n.jsx(A,{size:"sm",variant:"ghost","aria-label":"Next",disabled:!u,onClick:()=>h(1),children:n.jsx(ce,{name:"chevron-right"})})]}),foot:n.jsxs(ae,{align:"end",children:[n.jsx(A,{onClick:m,children:"Done"}),c.link||c.agentId?n.jsx(A,{variant:"accent",onClick:f,children:"Open"}):null]}),children:n.jsxs("div",{className:"home-deck-body",children:[n.jsx("p",{className:"home-deck-title",children:xc(c)}),c.text?n.jsx("p",{className:"home-deck-text",children:c.text}):null,c.action?n.jsx("p",{className:"home-deck-text",children:n.jsx("strong",{children:c.action})}):null]})})})}function MG({timezone:e,navigate:t,agents:s,defaultAgentId:r,attention:i,update:a,connectionSignals:l=[],hash:o="",pluginPages:c}){var He,kt,Yt,ne,ke,Qe,ct,Nt,ut,xn,Yn,Z,Re,Xe,jt;const u=de(()=>$.overview(),[],15e3),h=de(()=>$.approvals(),[],1e4),f=de(()=>$.missions(),[],6e4),m=de(()=>$.reminders(),[],6e4),p=de(()=>$.conversations(),[],3e4),g=de(()=>$.offers(),[],3e4),v=de(()=>$.proposals(),[],6e4),b=de(()=>$.agentOffers(),[],6e4),j=de(()=>$.owner(),[]),x=de(()=>$.notificationsNeedingYou(),[],3e4),w=d.useMemo(()=>bA(s,r??null),[s,r]),y=mG(s,r),{busy:k,note:N,failure:S,decide:C}=cw(()=>{h.reload(),u.reload()}),E=u.data,R=s.find(G=>G.id===r)??null,I=G=>{var he;return((he=s.find(We=>We.id===G))==null?void 0:he.name)??G},L=G=>he=>{he.preventDefault(),t(G)},F=((He=h.data)==null?void 0:He.pending)??[],T=((kt=E==null?void 0:E.jobs)==null?void 0:kt.failed)??0,M=((Yt=E==null?void 0:E.sentinels)==null?void 0:Yt.openUrgent)??0,P=((ne=v.data)==null?void 0:ne.open.length)??0,D=(((ke=b.data)==null?void 0:ke.offers)??[]).filter(G=>!F.some(he=>RT(he,G.plugin,G.agent))),O=OG(((Qe=x.data)==null?void 0:Qe.notifications)??[],F),[H,B]=d.useState(new Set),[Y,W]=d.useState($G),q=O.filter(G=>!H.has(G.id)),_=G=>{B(he=>new Set(he).add(G.id)),$.notificationSeen(G.id).catch(()=>{})},X=G=>{_(G);const he=G.link??(G.agentId?st(G.agentId):null);he&&t(he)},Q=G=>IG(G.agentId?I(G.agentId):G.pluginId?nT(G.pluginId,c==null?void 0:c.all):DG[G.kind],G,I),ee=zG(E==null?void 0:E.dismissed,()=>u.reload()),fe=(((ct=E==null?void 0:E.sentinels)==null?void 0:ct.errors)??[]).filter(G=>!ee.is(`watcher-error:${G.sentinelId}`,G.error)),Le=((E==null?void 0:E.mail)??[]).filter(G=>G.lastError&&!ee.is(`source-error:${G.sourceId}`,G.lastError)),Ie=LG(i),_e=l.filter(G=>!ee.is(`connection:${G.id}`,G.sentence)),U=(((Nt=E==null?void 0:E.needsYou)==null?void 0:Nt.recovery)??0)>0,ie=F.length+Ie.length+(T>0?1:0)+(M>0?1:0)+(P>0?1:0)+D.length+O.length+_e.length+(U?1:0);d.useEffect(()=>{var G,he;o===Cl&&((he=(G=document.getElementById(zx))==null?void 0:G.scrollIntoView)==null||he.call(G,{behavior:"smooth",block:"start"}))},[o]);const J=d.useMemo(()=>{var G,he;return HG(((G=f.data)==null?void 0:G.missions)??[],((he=m.data)==null?void 0:he.reminders)??[])},[f.data,m.data]),ye=(((ut=p.data)==null?void 0:ut.conversations)??[]).slice(0,5),ge=((xn=g.data)==null?void 0:xn.offers)??[],$e=ge.slice(0,UG),De=EG(),Je=ge.length-$e.length,Ue=p$(()=>u.reload()),be=PK(),Be=d.useMemo(()=>MK(be.answer),[be.answer]),at=JG((E==null?void 0:E.needsYou)??{approvals:F.length,questions:Ie.length,failed:T,urgent:M,proposals:P,agentsToSetUp:D.length,asks:O.length,signIns:_e.length,recovery:U?1:0},(E==null?void 0:E.paused)??!1);return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"home-band",children:n.jsxs("header",{className:"home-top",children:[n.jsxs("div",{className:"home-top-text",children:[n.jsxs("p",{className:"home-date",children:[n.jsx("span",{children:GG(E==null?void 0:E.now,e)}),n.jsx(uK,{glances:E==null?void 0:E.glances,navigate:t,except:Be,hiding:Ue}),n.jsx(AG,{tips:De})]}),n.jsx("h1",{className:"home-greeting",children:VG(E==null?void 0:E.now,e,((Yn=j.data)==null?void 0:Yn.preferredName)||((Z=j.data)==null?void 0:Z.displayName))}),n.jsx(QG,{items:at,navigate:t})]}),n.jsx("div",{className:"home-side",children:n.jsx($A,{size:"lg",anim:"idle"})})]})}),n.jsxs("div",{className:"home",children:[R?n.jsx(yG,{agent:R,navigate:t},R.id):null,n.jsx(TG,{tips:De,navigate:t}),n.jsx(kG,{navigate:t,preview:bG(o),hidden:De.open}),a&&a.updateAvailable&&!a.checkout&&a.latest&&!ee.is("update",a.latest)?n.jsx(V,{tone:"accent",action:n.jsx(rl,{label:"Not now — tell me at the next version",onClick:()=>ee.close("update",a.latest)}),children:n.jsxs("p",{children:["A newer buddi is ready: ",n.jsx("span",{className:"mono",children:a.latest}),"."," ",n.jsx("a",{href:Pe("system"),onClick:L(Pe("system")),children:"Upgrade from Settings → Version."})]})}):null,fe.map(G=>n.jsxs(V,{tone:"warning",action:n.jsx(rl,{label:"Hide until the error changes",onClick:()=>ee.close(`watcher-error:${G.sentinelId}`,G.error)}),children:["Watcher ",G.sentinelId," failed: ",G.error]},G.sentinelId)),Le.map(G=>n.jsxs(V,{tone:"warning",action:n.jsx(rl,{label:"Hide until the error changes",onClick:()=>ee.close(`source-error:${G.sourceId}`,G.lastError)}),children:["Source ",G.sourceId,": ",G.lastError]},G.sourceId)),n.jsx(re,{message:u.error??h.error??S}),N?n.jsx(V,{tone:"good",role:"status",children:N}):null,ie>0?n.jsx("div",{id:zx,className:"home-needs",children:n.jsx(ue,{title:"Needs you",aside:n.jsx("a",{href:qg,onClick:L(qg),children:"All notifications"}),actions:O.length>0?n.jsx(qt,{label:"Show what needs you as",options:[{value:"list",label:"List"},{value:"deck",label:"Deck"}],value:Y,onChange:G=>{W(G),RG(G)}}):void 0,children:n.jsxs(le,{children:[F.map(G=>n.jsx(uw,{action:G,timezone:e,busy:k===G.id,onDecide:C,agentName:I(G.agentId)},G.id)),M>0?n.jsx(V,{tone:"warning",children:n.jsx("a",{href:`${yt}/alerts`,onClick:L(`${yt}/alerts`),children:YG(M,((Re=E==null?void 0:E.sentinels)==null?void 0:Re.decisions)??[])})}):null,Ie.length>0||O.length>0&&Y==="list"?n.jsx(qe,{flush:!0,children:n.jsxs(rt,{children:[Ie.map(G=>n.jsx(et,{href:G.route,onClick:()=>t(G.route),lead:n.jsx(cn,{agents:s,id:G.agentId,size:"sm"}),title:"Asked you a question",sub:`${I(G.agentId)} · waiting for your answer`,side:Fe(G.at)},G.agentId)),Y==="list"?q.map(G=>n.jsx(et,{href:G.link??void 0,onClick:()=>X(G),lead:G.agentId?n.jsx(cn,{agents:s,id:G.agentId,size:"sm"}):void 0,title:xc(G),sub:G.action?`${Q(G)} · ${G.action}`:Q(G),side:G.state==="held"?"today":Fe(G.createdAt)},G.id)):null]})}):null,O.length>0&&Y==="deck"?n.jsx(PG,{rows:q,agents:s,label:Q,onOpen:X,onDone:_}):null,T>0?n.jsx(V,{tone:"critical",children:n.jsxs("a",{href:`${yt}/jobs?state=failed`,onClick:L(`${yt}/jobs?state=failed`),children:[T," failed job",T===1?"":"s",". See why, then retry or dismiss ",T===1?"it":"them","."]})}):null,P>0?n.jsx(V,{tone:"accent",children:n.jsxs("a",{href:Pe("proposals"),onClick:L(Pe("proposals")),children:[P," proposal",P===1?"":"s"," from your agents to keep or discard."]})}):null,_e.map(G=>n.jsx(V,{tone:"accent",action:n.jsx(rl,{label:"Not now — tell me if it changes",onClick:()=>ee.close(`connection:${G.id}`,G.sentence)}),children:n.jsxs("p",{children:[G.sentence," ",n.jsx("a",{href:Pe("connections"),onClick:L(Pe("connections")),children:"Settings → Connections."})]})},G.id)),D.map(G=>n.jsx(qe,{children:n.jsx(hw,{plugin:G.plugin,agent:G.agent,text:G.text,label:`Create @${G.handle}`,handle:G.handle,onDismiss:()=>{$.dismissAgentOffer(G.plugin,G.agent).then(()=>b.reload())}})},`${G.plugin}/${G.agent}`)),U?n.jsx(V,{tone:"warning",children:n.jsxs("p",{children:[vR," ",n.jsx("a",{href:Yg,onClick:L(Yg),children:"Open the checklist."})]})}):null]})})}):null,n.jsx(FK,{widgets:be,navigate:t}),n.jsxs(ue,{title:"Your team",aside:y?n.jsx("a",{href:Ht(),onClick:L(Ht()),children:"See all teammates"}):n.jsx("a",{href:pt,onClick:L(pt),children:"All agents"}),children:[s.length===0?n.jsx(pe,{mascot:!0,children:"No agents yet. Add one under Agents."}):n.jsxs("div",{className:"home-team",children:[w.map(G=>{const he=xf(i.get(G.id));return n.jsxs("a",{className:"home-face",...Yc(qc(G)),href:st(G.id),onClick:L(st(G.id)),"data-waiting":he?"true":void 0,"data-unavailable":G.available?void 0:"true",children:[n.jsx(Sn,{id:G.id,name:G.name,size:"lg",unavailable:!G.available,face:G}),n.jsxs("span",{className:"home-face-text",children:[n.jsx("span",{className:"home-face-name",children:G.name}),n.jsx("span",{className:"home-face-status",children:he?XG(he):G.available?Bs(G.description,60):G.unavailableReason??"Cannot run right now."})]})]},G.id)}),y?null:n.jsxs("a",{className:"team-add",href:Ht(),onClick:L(Ht()),"data-testid":"team-add",children:[n.jsx(ce,{name:"plus",size:14}),"Add a teammate"]})]}),y?n.jsx(vG,{navigate:t}):null]}),$e.length>0?n.jsx(ue,{title:"On offer",aside:n.jsxs("span",{className:"ui-row",children:[Je>0?n.jsxs("a",{href:`${pt}?tab=offers`,onClick:L(`${pt}?tab=offers`),children:[Je," more"]}):null,n.jsx(O$,{ids:ge.map(G=>G.id),onDone:()=>g.reload()})]}),children:n.jsx("div",{className:"home-offers",children:$e.map(G=>n.jsx(WG,{offer:G,agents:s,open:L(Et(G.agentId,"offers")),onDismissed:()=>g.reload()},G.id))})}):null,n.jsx(XH,{}),(jt=(Xe=v.data)==null?void 0:Xe.digest)!=null&&jt.latest&&_G(v.data.digest.latest,E==null?void 0:E.now,ee.is)?n.jsx(qG,{digest:v.data.digest.latest,go:L,onClose:()=>ee.close(yR,v.data.digest.latest.at)}):null,n.jsxs("div",{className:"home-columns",children:[n.jsx(ue,{title:"Coming up",aside:n.jsx("a",{href:`${pt}?tab=missions`,onClick:L(`${pt}?tab=missions`),children:"All missions"}),children:n.jsx(qe,{flush:!0,children:J.length===0?n.jsx(pe,{mascot:!0,children:"Nothing scheduled. Missions and reminders will show here."}):n.jsx(rt,{children:J.map(G=>n.jsx(et,{href:G.route,onClick:()=>t(G.route),lead:n.jsx(cn,{agents:s,id:G.agentId,size:"sm"}),title:G.title,sub:`${G.kind} for ${I(G.agentId)}`,side:Fe(G.at)},G.key))})})}),n.jsx(ue,{title:"Lately",aside:n.jsx("a",{href:yt,onClick:L(yt),children:"All activity"}),children:n.jsx(qe,{flush:!0,children:ye.length===0?n.jsx(pe,{mascot:!0,children:"Nothing has run yet. Say hello to someone on your team."}):n.jsx(rt,{children:ye.map(G=>n.jsx(et,{href:st(G.agentId,G.id),onClick:()=>t(st(G.agentId,G.id)),lead:n.jsx(cn,{agents:s,id:G.agentId,size:"sm"}),title:G.opening?Bs(G.opening,80):"Untitled conversation",sub:`${I(G.agentId)}, ${G.messageCount} message${G.messageCount===1?"":"s"}`,side:Fe(G.lastMessageAt??G.createdAt)},G.id))})})})]}),((E==null?void 0:E.home)??[]).filter(G=>!ee.is(mN(G.id),pN)).map(G=>n.jsx(ZG,{block:G,onHide:()=>ee.close(mN(G.id),pN)},G.id)),E!=null&&E.jobs&&E.missions?n.jsxs("p",{className:"home-foot muted",children:[Xt(E.jobs.pending??0)," queued, ",Xt(E.jobs.leased??0)," running, ",Xt(E.missions.enabled)," of ",Xt(E.missions.total)," missions on."," ",E.paused?n.jsx(we,{tone:"warning",children:"paused"}):n.jsx(we,{tone:"good",children:"running"})," ",n.jsx("a",{href:wc("").replace(/\/conversations\/$/,""),onClick:L(yt),children:"Activity"})," · ",n.jsx("a",{href:Pe("system"),onClick:L(Pe("system")),children:"System"})]}):null]})]})}const DG={approval:"Approval",question:"Question",watcher:"Watcher",reminder:"Reminder",failure:"Failure",recap:"Report",plugin:"Plugin",agent:"Message"};function OG(e,t){const s=new Set(t.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 LG(e){const t=[];for(const s of e.values())s.question&&t.push({agentId:s.agentId,at:s.question.at,route:st(s.agentId,s.question.conversationId)});return t.sort((s,r)=>s.at.localeCompare(r.at))}const yR="digest",FG=3*864e5;function mN(e){return`block:${e}`}const pN="hidden";function _G(e,t,s){if(s(yR,e.at))return!1;const r=Date.parse(e.at),i=t?Date.parse(t):Date.now();return Number.isFinite(r)&&i-r<FG}function zG(e,t){const[s,r]=d.useState({});return{is:(l,o)=>(s[l]??(e==null?void 0:e[l]))===o,close:(l,o)=>{r(c=>({...c,[l]:o})),$.homeDismiss(l,o).then(t,()=>{r(c=>{const u={...c};return delete u[l],u})})}}}function rl({label:e,onClick:t}){return n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":e,title:e,onClick:t,children:n.jsx(ce,{name:"close"})})}const UG=6,BG=500;function WG({offer:e,agents:t,open:s,onDismissed:r}){const[i,a]=d.useState(!1),l=d.useRef(null),o=d.useRef(!1),c=()=>{i||(a(!0),$.dismissOffer(e.id).then(r).finally(()=>a(!1)))},u=()=>{l.current!==null&&clearTimeout(l.current),l.current=null};return n.jsxs("span",{className:"home-offer-chip",children:[n.jsxs("a",{className:"home-offer",href:Et(e.agentId,"offers"),onClick:h=>{if(o.current){o.current=!1,h.preventDefault();return}s(h)},title:e.prompt,onTouchStart:()=>{o.current=!1,u(),l.current=setTimeout(()=>{o.current=!0,c()},BG)},onTouchEnd:u,onTouchMove:u,onTouchCancel:u,children:[n.jsx(cn,{agents:t,id:e.agentId,size:"sm"}),n.jsx("span",{children:e.label})]}),n.jsx("button",{type:"button",className:"home-offer-x","aria-label":`Dismiss ${e.label}`,disabled:i,onClick:c,children:"×"})]})}function HG(e,t){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:Et(r.agentId,"missions")});for(const r of t)r.state==="pending"&&s.push({key:`r-${r.id}`,at:r.dueAt,title:r.text,kind:"Reminder",agentId:r.agentId,route:Et(r.agentId,"reminders")});return s.sort((r,i)=>r.at.localeCompare(i.at)).slice(0,5)}function KG(e,t){try{const s=new Intl.DateTimeFormat("en-GB",{hour:"numeric",hourCycle:"h23",timeZone:t}).format(e?new Date(e):new Date);return Number(s)}catch{return new Date().getHours()}}function VG(e,t,s){const r=KG(e,t),i=s!=null&&s.trim()?`, ${s.trim()}`:"";return r<5?`Still up${i}?`:r<12?`Good morning${i}.`:r<18?`Good afternoon${i}.`:`Good evening${i}.`}function GG(e,t){try{return yr(e?new Date(e):new Date,t,{weekday:!0})}catch{return nt(e??null,t)}}function qG({digest:e,go:t,onClose:s}){var a,l;const r=e.summary??[],i=Object.entries(((a=e.feedback)==null?void 0:a.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&&i.length===0?null:n.jsx(ue,{title:"What buddi learned this week",aside:n.jsxs("span",{className:"ui-row",children:[n.jsx("span",{className:"muted",children:Fe(e.at)}),s?n.jsx(rl,{label:"Hide until next week",onClick:s}):null]}),children:n.jsx(qe,{children:n.jsxs(le,{divided:!0,children:[r.length>0?n.jsx("ul",{className:"home-digest-list","data-plain":"",children:r.map(o=>n.jsxs("li",{children:[o.text,o.link?n.jsxs(n.Fragment,{children:[" · ",n.jsx("a",{href:o.link.route,onClick:t(o.link.route),children:o.link.label})]}):null]},o.key))}):null,i.length>0?n.jsxs("div",{"data-testid":"digest-reactions",children:[n.jsx("p",{className:"ui-card-meta",children:"Your reactions"}),n.jsxs("ul",{className:"home-digest-list",children:[i.map(o=>n.jsx("li",{children:o},o)),(((l=e.feedback)==null?void 0:l.notes)??[]).map((o,c)=>{var u;return n.jsxs("li",{children:["What was off (",((u=e.agentNames)==null?void 0:u[o.agentId])??o.agentId,"): ",o.note]},`note-${c}`)})]})]}):null]})})})}function YG(e,t){const s=t[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 zx="home-needs";function JG(e,t=!1){const s=(i,a,l=`${a}s`)=>i===1?a: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:`${yt}/alerts`}),e.failed>0&&r.push({key:"failed",count:e.failed,label:s(e.failed,"failed job"),tone:"critical",route:`${yt}/jobs?state=failed`}),t&&r.push({key:"paused",count:null,label:"Paused",route:`${yt}/jobs`}),e.proposals>0&&r.push({key:"proposals",count:e.proposals,label:s(e.proposals,"proposal"),route:Pe("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 QG({items:e,navigate:t}){if(e.length===0)return n.jsx("p",{className:"home-calm",children:"Nothing needs you. Your agents are on it."});const s=()=>{var r,i;(i=(r=document.getElementById(zx))==null?void 0:r.scrollIntoView)==null||i.call(r,{behavior:"smooth",block:"start"})};return n.jsx("p",{className:"home-counts",children:e.map((r,i)=>{const a=n.jsxs(n.Fragment,{children:[r.count!==null?n.jsxs(n.Fragment,{children:[n.jsx("strong",{children:r.count})," "]}):null,r.label]});return n.jsxs(d.Fragment,{children:[i>0?n.jsx("span",{className:"home-count-sep","aria-hidden":"true",children:"·"}):null,r.route?n.jsx("a",{className:"home-count","data-tone":r.tone,href:r.route,onClick:l=>{l.preventDefault(),t(r.route)},children:a}):n.jsx("button",{type:"button",className:"home-count","data-tone":r.tone,onClick:s,children:a})]},r.key)})})}function XG(e){return e.charAt(0).toUpperCase()+e.slice(1)}function ZG({block:e,onHide:t}){const[s,r]=d.useState(!1),i=e.sensitive===!0&&!s;d.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 a=n.jsxs("span",{className:"ui-row",children:[e.rows.length>0&&e.rowsTitle&&!i?n.jsxs("span",{className:"muted",children:[e.rowsTitle.toLowerCase()," below"]}):null,e.sensitive?n.jsx(A,{size:"sm",variant:"ghost","aria-pressed":!i,onClick:()=>r(l=>!l),children:i?"Show":"Hide"}):null,n.jsx(rl,{label:`Hide ${e.title} from Home`,onClick:t})]});return n.jsxs(ue,{title:e.title,aside:a,children:[e.note?n.jsx(V,{tone:"warning",children:e.note}):null,e.stats.length>0?n.jsx(Nf,{children:e.stats.map(l=>n.jsx(ur,{label:l.label,value:i?"••••":l.value,note:i?void 0:l.note,tone:i?void 0:l.tone},l.label))}):null,e.rows.length>0?i?n.jsxs("p",{className:"muted",children:[e.rows.length," item",e.rows.length===1?"":"s"," hidden."]}):n.jsx(qe,{flush:!0,children:n.jsx(rt,{children:e.rows.map((l,o)=>n.jsx(et,{title:l.title,sub:l.sub,side:l.side?n.jsx("span",{className:l.tone==="critical"?"critical":l.tone==="good"?"good":void 0,children:l.side}):void 0},`${l.title}-${o}`))})}):null]})}const eq=2e3,tq={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 Ux(e){return tq[e.phase]??e.detail??e.phase}const nq=new Set(["done","failed","rolled-back"]);function bR(e){return e!==void 0&&(nq.has(e.phase)||!!e.finishedAt)}function sq(e,t=!1){const[s,r]=d.useState(void 0),[i,a]=d.useState(!1),[l,o]=d.useState(null),c=d.useRef(!1);return d.useEffect(()=>{if(!e){r(void 0),a(!1),c.current=!1;return}let u=!1;const h=()=>{t&&c.current||$.backupJob(e).then(m=>{if(!u){if(t&&(wA({step:Ux(m)}),(m.phase==="failed"||m.phase==="rolled-back")&&El()),c.current){window.location.reload();return}r(m),o(null),bR(m)&&(u=!0)}}).catch(m=>{if(!u){if(m instanceof ve&&m.status!==0&&m.status<500){t&&El(),o(m.message);return}c.current=!0,t||a(!0)}})};h();const f=window.setInterval(h,eq);return()=>{u=!0,window.clearInterval(f)}},[e,t]),{job:s,away:i,error:l}}function rq({job:e,away:t,error:s}){return s?n.jsx(re,{message:s}):t?n.jsx(V,{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"?n.jsxs(V,{tone:"critical",role:"alert",children:[Ux(e)," ",e.error??""]}):n.jsxs(V,{tone:e.phase==="done"?"good":void 0,role:"status",children:[Ux(e),e.copyLate?" The backup was made, but the copy to your folder did not go through.":"",e.error?` ${e.error}`:""]}):null}function iq(){var x,w,y,k,N,S,C;const e=de(()=>$.backups(),[],3e4),t=xR(),s=de(()=>$.service(),[]),[r,i]=d.useState(null),[a,l]=d.useState(!1),o=sq(r,a),[c,u]=d.useState(null),[h,f]=d.useState(!1),[m,p]=d.useState(null),g=((x=e.data)==null?void 0:x.supervised)??((w=s.data)==null?void 0:w.supervised),v=m!==null||g===!1,b=((y=e.data)==null?void 0:y.archives)??[],j=(E,R=!1)=>{f(!0),u(null),l(R),E().then(I=>{var L;R&&I.job&&pf({kind:"restore",patienceMs:jA}),i(((L=I.job)==null?void 0:L.id)??null)}).catch(I=>{I instanceof ve&&I.status===409?p(I.message):u(I instanceof ve?I.message:String(I))}).finally(()=>{f(!1),e.reload()})};return d.useEffect(()=>{bR(o.job)&&e.reload()},[(k=o.job)==null?void 0:k.phase]),n.jsxs(le,{gap:"lg",children:[(N=t.data)!=null&&N.active?n.jsx(hG,{view:t.data,onLeft:t.reload}):null,n.jsx(re,{message:e.error??c}),n.jsx(rq,{...o}),n.jsx(lq,{onSaved:()=>e.reload()}),n.jsx(ue,{title:"Backups",panel:!0,actions:n.jsx(A,{variant:"accent",size:"sm",disabled:h,onClick:()=>j(()=>$.startBackup(!0)),children:"Back up now"}),children:n.jsxs(le,{divided:!0,children:[n.jsx(ue,{children:n.jsxs("p",{className:"ui-card-meta",children:["Kept in ",n.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."]})}),n.jsx(ue,{children:e.data&&b.length===0?n.jsx(In,{icon:"archive",title:"No backups yet",children:"Make one now, or turn on the nightly backup."}):e.data?n.jsxs(kr,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Name"}),n.jsx("th",{children:"Taken"}),n.jsx("th",{children:"Size"}),n.jsx("th",{children:"State"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:b.map(E=>{var R;return n.jsx(oq,{archive:E,busy:h,database:(R=e.data)==null?void 0:R.database,checkout:v,onVerify:()=>j(()=>$.verifyArchive(E.name)),onRestore:(I,L)=>j(()=>$.restoreArchive({name:E.name,...I?{passphrase:I}:{},...L?{confirm:L}:{}}),!0)},E.name)})})]}):n.jsx(pe,{children:"Loading…"})})]})}),n.jsx(cq,{}),n.jsx(uq,{busy:h,checkout:v,checkoutSaid:m,database:(C=e.data)==null?void 0:C.database,onRestore:(E,R,I)=>j(()=>$.restoreUpload(E,{passphrase:R,confirm:I}),!0)})]})}const aq={enabled:!1,time:"03:00",keep:7,encryptLocal:!0,copyTo:null};function lq({onSaved:e}){var p;const t=de(()=>$.backupSchedule(),[]),[s,r]=d.useState(null),[i,a]=d.useState(!1),[l,o]=d.useState(null),[c,u]=d.useState(!1);d.useEffect(()=>{t.data&&r(t.data)},[t.data]);const h={...aq,...s??t.data??{}};if(((p=t.data)==null?void 0:p.supervised)===!1)return n.jsx(ue,{title:"Every night",panel:!0,children:n.jsx(ue,{children:n.jsx(V,{tone:"warning",children:t.data.error??"This installation schedules its own backups."})})});const f=g=>{u(!1),r({...h,...g})},m=()=>{a(!0),o(null),$.setBackupSchedule(h).then(g=>{r(g),u(!0),e()}).catch(g=>o(g instanceof ve?g.message:String(g))).finally(()=>a(!1))};return n.jsx(ue,{title:"Every night",panel:!0,foot:n.jsx(A,{variant:"accent",disabled:i,onClick:m,children:"Save"}),children:n.jsxs(le,{divided:!0,children:[n.jsx(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsx(re,{message:l}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:h.enabled,onChange:g=>f({enabled:g.target.checked})}),n.jsx("span",{children:"Back this buddi up on its own"})]}),n.jsxs(Hs,{children:[n.jsx(oe,{label:"At",children:n.jsx("input",{type:"time",value:h.time,onChange:g=>f({time:g.target.value})})}),n.jsx(oe,{label:"Keep",hint:"How many to keep before the oldest is thrown away.",children:n.jsx("input",{type:"number",min:1,max:365,value:h.keep,onChange:g=>f({keep:Number(g.target.value)||1})})})]}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:h.encryptLocal,onChange:g=>f({encryptLocal:g.target.checked})}),n.jsx("span",{children:"Lock each one with the passphrase"})]})]})}),n.jsx(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsx(oe,{label:"Also copy to a folder",hint:"A second disk, or a folder that syncs somewhere. Left empty, backups stay on this machine.",children:n.jsx("input",{type:"text",value:h.copyTo??"",placeholder:"/Volumes/backup/buddi",onChange:g=>f({copyTo:g.target.value===""?null:g.target.value})})}),c?n.jsxs(V,{tone:"good",role:"status",children:["Saved.",h.lastRunAt?` Last run ${Fe(h.lastRunAt)}.`:""]}):null]})})]})})}function oq({archive:e,busy:t,database:s,checkout:r,onVerify:i,onRestore:a}){const[l,o]=d.useState(!1),[c,u]=d.useState(""),[h,f]=d.useState("");return n.jsxs(n.Fragment,{children:[n.jsxs("tr",{children:[n.jsx("td",{className:"mono",children:e.name}),n.jsx("td",{children:Fe(e.createdAt)}),n.jsx("td",{children:qn(e.bytes)}),n.jsxs("td",{children:[e.encrypted?n.jsx(we,{tone:"good",children:"locked"}):n.jsx(we,{tone:"muted",children:"plain"})," ",e.envelopeOk===!1?n.jsx(we,{tone:"critical",children:"damaged"}):null]}),n.jsx("td",{children:n.jsxs(ae,{align:"end",children:[n.jsx(A,{size:"sm",disabled:t,onClick:i,children:"Verify"}),n.jsx(A,{size:"sm",variant:"ghost",onClick:()=>o(!l),children:"Restore…"})]})})]}),l?n.jsx("tr",{children:n.jsx("td",{colSpan:5,children:r?n.jsx(V,{tone:"warning",children:kR}):n.jsx(NR,{what:`${e.name}, taken ${Fe(e.createdAt)}, ${qn(e.bytes)}`,database:s,needsPassphrase:e.encrypted,passphrase:c,onPassphrase:u,confirm:h,onConfirm:f,busy:t,onCancel:()=>o(!1),onGo:()=>a(c,h)})})}):null]})}const kR="Restoring needs the packaged installation. In a checkout, run: buddi backup restore <file>";function NR({what:e,database:t,needsPassphrase:s,passphrase:r,onPassphrase:i,confirm:a,onConfirm:l,busy:o,onCancel:c,onGo:u}){const h=t??"",f=h===""?a.trim()!=="":a.trim()===h;return n.jsxs(le,{gap:"sm",children:[n.jsxs(V,{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?n.jsx(oe,{label:"The passphrase this one was locked with",children:n.jsx("input",{type:"password",autoComplete:"off",value:r,onChange:m=>i(m.target.value)})}):null,n.jsx(oe,{label:h?`Type ${h} to confirm`:"Type the name of this database to confirm",hint:h?void 0:"The same name buddi shows on the System tab.",children:n.jsx("input",{value:a,onChange:m=>l(m.target.value)})}),n.jsxs(ae,{align:"end",children:[n.jsx(A,{variant:"ghost",onClick:c,children:"Cancel"}),n.jsx(A,{variant:"danger",disabled:o||!f||s&&r==="",onClick:u,children:"Restore"})]})]})}function cq(){const[e,t]=d.useState(null),[s,r]=d.useState(""),[i,a]=d.useState(!1),[l,o]=d.useState(null),[c,u]=d.useState(!1),h=()=>{a(!0),o(null),$.backupPassphrase().then(m=>t(m.passphrase)).catch(m=>o(m instanceof ve?m.message:String(m))).finally(()=>a(!1))},f=()=>{a(!0),o(null),$.setBackupPassphrase(s.trim()).then(m=>{t(m.passphrase),r(""),u(!0)}).catch(m=>o(m instanceof ve?m.message:String(m))).finally(()=>a(!1))};return n.jsx(ue,{title:"The passphrase",panel:!0,children:n.jsxs(le,{divided:!0,children:[n.jsx(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsx(re,{message:l}),n.jsx("p",{className:"ui-card-meta",children:"This is the only thing that opens an encrypted backup. Write it down."}),e?n.jsx("p",{className:"backup-phrase mono",children:e}):n.jsx(ae,{align:"end",children:n.jsx(A,{disabled:i,onClick:h,children:"Show it"})}),c?n.jsx(V,{tone:"good",role:"status",children:"Saved. Backups made from now on use it; older ones keep the one they were made with."}):null]})}),n.jsx(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsx(oe,{label:"Use my own",hint:"Six words you can read out loud beat a short one nobody can.",children:n.jsx("input",{type:"text",autoComplete:"off",value:s,onChange:m=>{u(!1),r(m.target.value)}})}),n.jsx(ae,{align:"end",children:n.jsx(A,{variant:"accent",disabled:i||s.trim()==="",onClick:f,children:"Use this one"})})]})})]})})}function uq({busy:e,checkout:t,checkoutSaid:s,database:r,onRestore:i}){const[a,l]=d.useState(null),[o,c]=d.useState(""),[u,h]=d.useState(""),[f,m]=d.useState(!1);return t?n.jsx(ue,{title:"Restore from a file",panel:!0,children:n.jsx(ue,{children:n.jsx(V,{tone:"warning",children:s??kR})})}):n.jsx(ue,{title:"Restore from a file",panel:!0,children:n.jsxs(le,{divided:!0,children:[n.jsx(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsx("p",{className:"ui-card-meta",children:"A backup from another buddi, or one you keep somewhere else."}),n.jsxs(Hs,{children:[n.jsx(oe,{label:"The backup file",children:n.jsx("input",{type:"file",onChange:p=>{var g;m(!1),l(((g=p.target.files)==null?void 0:g[0])??null)}})}),n.jsx(oe,{label:"Its passphrase",hint:"Only if it was locked with one.",children:n.jsx("input",{type:"password",autoComplete:"off",value:o,onChange:p=>c(p.target.value)})})]}),f?null:n.jsx(ae,{align:"end",children:n.jsx(A,{variant:"accent",disabled:e||!a,onClick:()=>m(!0),children:"Restore"})})]})}),f&&a?n.jsx(ue,{children:n.jsx(NR,{what:`${a.name}, ${qn(a.size)}`,database:r,needsPassphrase:!1,passphrase:o,onPassphrase:c,confirm:u,onConfirm:h,busy:e,onCancel:()=>m(!1),onGo:()=>i(a,o,u)})}):null]})})}const SR="gemini-2.5-pro";function Df(e){return e.replace(/^models\//,"")}const Bw=/(image|tts|audio|live|embedding|vision|robotics|transcribe)/;function CR(e){const t=e.map(Df);let s;for(const r of t){const i=/^gemini-(\d+(?:\.\d+)*)-pro(?:-(.+))?$/.exec(r);if(!i||Bw.test(i[2]??""))continue;const a=i[1].split(".").map(Number),l=(i[2]??"")!=="";(!s||bh(a,s.version)>0||bh(a,s.version)===0&&s.preview&&!l)&&(s={id:r,version:a,preview:l})}return(s==null?void 0:s.id)??t.find(r=>r.startsWith("gemini-"))}function ER(e){let t;for(const s of e.map(Df)){const r=/^gemini-(\d+(?:\.\d+)*)-flash(?:-(.+))?$/.exec(s);if(!r||/lite/.test(r[2]??"")||Bw.test(r[2]??""))continue;const i=r[1].split(".").map(Number),a=(r[2]??"")!=="";(!t||bh(i,t.version)>0||bh(i,t.version)===0&&t.preview&&!a)&&(t={id:s,version:i,preview:a})}return t==null?void 0:t.id}function AR(e){return/^gemini-[\d.]+-pro(?:-|$)/.test(Df(e))}function dq(e){return[...new Set(e.map(Df).filter(t=>t.startsWith("gemini-")&&!Bw.test(t)))]}function TR(e){return e.httpStatus===429||e.state==="rate-limited"||e.state==="quota-exhausted"}function bh(e,t){for(let s=0;s<Math.max(e.length,t.length);s+=1){const r=(e[s]??0)-(t[s]??0);if(r!==0)return r}return 0}function $R(e,t){if(!t||e.kind!=="openai-compatible")return!1;const s=r=>r.replace(/\/+$/,"");return s(e.baseUrl)===s(t)}function hq({embedded:e,account:t}={}){const{data:s,error:r,reload:i,loading:a}=de(()=>$.providerAccounts(),[]),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(""),[m,p]=d.useState(!1),[g,v]=d.useState(!1),[b,j]=d.useState(t??null);d.useEffect(()=>{t&&j(t)},[t]);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()});d.useEffect(()=>{if(!x)return;const S=setInterval(i,2e3);return()=>clearInterval(S)},[x,i]);const w=async(S,C)=>{o(!0),u(null),f(""),v(!1);try{const E=await S();return f((E==null?void 0:E.warning)??C),i(),!0}catch(E){return u(E instanceof Error?E.message:"Could not apply change."),i(),!1}finally{o(!1)}},y=(s==null?void 0:s.accounts)??[],k=y.find(S=>S.id===b)??y[0],N=S=>{var C;return $R(S,(C=s==null?void 0:s.gemini)==null?void 0:C.baseUrl)?"Gemini":RR(S)};return n.jsxs(On,{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:[n.jsx(re,{message:r??c}),h&&n.jsx(V,{tone:"good",role:"status",children:h}),g&&n.jsx(V,{role:"status",children:a?"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&&n.jsx(pe,{children:"Loading accounts…"}),r&&n.jsx(ae,{children:n.jsx(A,{onClick:i,children:"Retry"})}),s&&n.jsxs(n.Fragment,{children:[(s.vault.locked||s.vault.kind==="none")&&n.jsx(V,{tone:"warning",children:s.vault.advice||"Run buddi init on the host to configure secure credential storage."}),m&&n.jsx(Ye,{title:"Add an account",onClose:()=>p(!1),children:n.jsx("div",{id:"new-provider-account",children:n.jsx(bq,{accounts:y,codexEnabled:s.codexEnabled,anthropicOAuthEnabled:s.anthropicOAuthEnabled,gemini:s.gemini,busy:l,run:w,onDone:S=>{p(!1),S&&j(S)}})})}),n.jsx(ue,{title:"Accounts",aside:`Secrets live in the ${fq(s.vault.kind)}; Postgres holds names and assignments only.`,actions:n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",size:"sm",disabled:l||a,onClick:()=>{u(null),f(""),v(!0),i()},children:a?"Refreshing…":"Refresh status"}),n.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:y.length===0?n.jsx(In,{icon:"chip",title:"No accounts yet",children:"Add one to give your agents a model to run on."}):n.jsxs("div",{className:"accounts",children:[n.jsx("nav",{className:"accounts-list","aria-label":"Accounts",children:y.map(S=>n.jsxs("button",{type:"button",className:"accounts-row","aria-pressed":(k==null?void 0:k.id)===S.id,onClick:()=>j(S.id),children:[n.jsx(mq,{kind:S.kind,auth:S.auth}),n.jsxs("span",{className:"accounts-row-text",children:[n.jsx("span",{className:"accounts-row-name",children:S.label}),kh(S)?n.jsxs("span",{className:"accounts-row-sub","data-tone":"warning",children:[N(S)," · back at ",Ww(kh(S).until)]}):n.jsxs("span",{className:"accounts-row-sub",children:[N(S)," · ",S.assignedAgents.length===0?"no agents":`${S.assignedAgents.length} agent${S.assignedAgents.length===1?"":"s"}`]})]}),n.jsx(PR,{account:S})]},S.id))}),k?n.jsx(jq,{account:k,provider:N(k),anthropicOAuthEnabled:s.anthropicOAuthEnabled,busy:l,run:w},`${k.id}:${k.revision}`):null]})})]})]})}function fq(e){return e==="keychain"?"macOS Keychain":e==="file"?"encrypted file vault":e==="none"?"vault (none configured)":e}function RR(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":Ow(e)?"mlxh":"OpenAI-compatible"}function IR(e){return e.detectedContextWindowSource==="mlxh"?e7(e.detectedContextWindowTokens):e.detectedContextWindowSource!=="provider"?"assumed":e.kind==="codex"?"from ChatGPT":"from the provider"}function mq({kind:e,auth:t}){const s=e==="anthropic"?"A":e==="codex"?"G":e==="openai"?"O":"∞",r=e==="anthropic"?"3":e==="codex"?"2":e==="openai"?"5":"4";return n.jsx("span",{className:"ui-avatar","data-tint":r,"aria-hidden":"true",title:`${e} · ${t}`,children:s})}function pq(e){return e==="connected"?"good":["rate-limited","quota-exhausted","provider-unavailable"].includes(e)?"warning":"critical"}function kh(e,t=Date.now()){const s=e.rateLimit;return e.enabled&&e.configured&&s&&Date.parse(s.until)>t?s:null}const gq=()=>Intl.DateTimeFormat().resolvedOptions().timeZone;function Ww(e,t=new Date,s=gq()){const r=new Date(e),i=a=>a.toLocaleDateString("en-CA",{timeZone:s});return i(r)===i(t)?zt(r,s):i(r)===i(new Date(t.getTime()+864e5))?`tomorrow at ${zt(r,s)}`:mj(r,s)}function PR({account:e,long:t}){const s=kh(e);if(s){const a=`Rate-limited until ${Ww(s.until)}`;return n.jsx("span",{title:a,children:n.jsx(we,{tone:"warning",children:t?a:"Rate-limited"})})}const r=e.enabled?e.configured?"good":"warning":void 0,i=e.enabled?e.configured?"Configured":"Needs credential":"Disabled";return n.jsx(we,{tone:r,children:i})}function xq({id:e}){const[t,s]=d.useState(!1),r=()=>{var i;(i=navigator.clipboard)==null||i.writeText(e).then(()=>{s(!0),window.setTimeout(()=>s(!1),1600)}).catch(()=>{})};return n.jsxs("span",{className:"accounts-id",children:[n.jsx("code",{className:"accounts-id-text",children:e}),n.jsx(A,{variant:"ghost",size:"sm",onClick:r,"aria-label":"Copy the id of this account",children:t?"Copied":"Copy"})]})}function vq({account:e,provider:t}){const s=kh(e);if(!s)return null;const r=s.provider??t,i=Ww(s.until);if(s.scope==="day"){const a=e.assignedAgents,l=a.length===1?a[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 n.jsx(V,{tone:"warning",title:c,action:a.length>0?n.jsx(dt,{size:"sm",href:a.length===1?Et(a[0],"setup","brain"):pt,children:a.length===1?`Change ${a[0]}'s account`:"Change their accounts"}):void 0,children:n.jsxs("p",{children:["It resets ",/^tomorrow/.test(i)?i:`at ${i}`,". Until then buddi doesn't send this account's requests to ",r,", so ",a.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",", ",a.length?`give ${l} another account`:"use another account",u,"."]})})}return n.jsx(V,{tone:"warning",title:`${r} asked buddi to slow down`,children:n.jsxs("p",{children:["It said to wait until ",i,". A run that meets this waits and tries again — up to a minute during a conversation, longer for work in the background."]})})}function Hw(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 jq({account:e,provider:t,busy:s,run:r,anthropicOAuthEnabled:i}){const[a,l]=d.useState(!1),[o,c]=d.useState(!1);return n.jsxs("section",{className:"accounts-detail","aria-label":e.label,children:[n.jsxs("div",{className:"ui-card-head",children:[n.jsx("h3",{className:"ui-card-title",children:e.label}),n.jsx(PR,{account:e,long:!0})]}),n.jsx(Gt,{items:[{label:"Provider",value:t},{label:"Default model",value:n.jsx("span",{className:"mono",children:e.defaultModel||"—"})},{label:"Context window",value:n.jsx("span",{className:"mono",children:`${(e.contextWindowTokens??e.detectedContextWindowTokens??0).toLocaleString()} tokens${e.contextWindowTokens?"":` (${IR(e)})`}`})},...e.baseUrl?[{label:"Endpoint",value:n.jsx("span",{className:"mono",children:e.baseUrl})}]:[],{label:"Used by",value:e.assignedAgents.length?n.jsx("span",{className:"ui-row",children:e.assignedAgents.map(u=>n.jsx("a",{href:Et(u,"setup","brain"),children:u},u))}):n.jsxs("span",{className:"ui-row",children:[n.jsx("span",{className:"muted",children:"No agents"}),n.jsx("a",{href:pt,children:"Assign to an agent"})]})},...e.tokenExpiresAt?[{label:"Access token",value:`expires ${nt(e.tokenExpiresAt,Intl.DateTimeFormat().resolvedOptions().timeZone)} (not your subscription renewal date)`}]:[],{label:"ID",value:n.jsx(xq,{id:e.id})}]}),n.jsx(vq,{account:e,provider:t}),e.removalPending&&n.jsx(V,{tone:"warning",children:"Removal is pending. Unlock the vault, then retry Remove account."}),e.reconnectRequired&&n.jsxs(V,{tone:"warning",children:["Token refresh did not finish. Reconnect this ",e.kind==="codex"?"ChatGPT":"Claude"," account."]}),e.auth==="anthropic-oauth"&&n.jsx(OR,{account:e,enabled:!!i,busy:s,run:r}),e.kind==="codex"&&n.jsx(MR,{account:e,busy:s,run:r}),e.auth==="device-key"&&n.jsx(DR,{account:e,busy:s,run:r}),n.jsxs(ae,{children:[n.jsx(A,{disabled:s||e.removalPending,onClick:()=>l(!0),children:"Edit account"}),n.jsx(A,{disabled:s||e.removalPending,onClick:()=>void r(()=>$.saveProviderAccount({...Hw(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"&&n.jsx(A,{disabled:s||!e.enabled||!e.configured,onClick:()=>void r(()=>$.testProviderAccount(e.id),"Connection test finished."),children:"Test connection"}),n.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&&n.jsxs(n.Fragment,{children:[n.jsxs(V,{role:"status",tone:pq(e.test.state),children:[n.jsx("p",{children:e.test.message}),e.test.retryAt?n.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)&&n.jsx("p",{children:"The provider did not supply a usable Retry-After time. Reset time is unknown."})]}),n.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."]})]}),a&&n.jsx(Ye,{title:`Edit ${e.label}`,onClose:()=>l(!1),children:n.jsx(wq,{account:e,busy:s,run:r,onDone:()=>l(!1)})}),o&&n.jsxs(V,{tone:"critical",children:[n.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."]}),n.jsxs(ae,{children:[n.jsx(A,{variant:"danger",disabled:s,onClick:()=>void r(()=>$.removeProviderAccount(e.id,e.revision),"Account removed from Buddi."),children:"Confirm removal"}),n.jsx(A,{disabled:s,onClick:()=>c(!1),children:"Cancel"})]})]}),n.jsx(Tt,{summary:"Details",children:n.jsxs("div",{className:"ui-prose muted",children:[e.kind==="codex"?n.jsxs(n.Fragment,{children:[n.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."}),n.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."}),n.jsx("p",{children:"After connecting, assign this account to an agent and send a test message. Model turns use your subscription allowance."})]}):n.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"&&n.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"&&n.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."}),n.jsx("p",{children:"Subscription login is separate from API-key access."})]})})]})}function MR({account:e,busy:t,run:s}){var r,i,a;return n.jsxs(n.Fragment,{children:[n.jsxs(ae,{children:[n.jsx(A,{disabled:t||!e.enabled||e.removalPending||((r=e.login)==null?void 0:r.state)==="pending",onClick:()=>void s(()=>$.codexAccountAction(e.id,"login",e.revision),"Complete device sign-in below."),children:e.configured?"Reconnect ChatGPT":"Connect ChatGPT"}),((i=e.login)==null?void 0:i.state)==="pending"&&n.jsx(A,{disabled:t,onClick:()=>void s(()=>$.codexAccountAction(e.id,"cancel-login",e.revision),"Sign-in cancelled."),children:"Cancel sign-in"}),n.jsx(A,{disabled:t||!e.configured,onClick:()=>void s(()=>$.codexAccountAction(e.id,"logout",e.revision),"Subscription disconnected from Buddi. Your regular Codex login is unchanged."),children:"Disconnect"})]}),((a=e.login)==null?void 0:a.state)==="pending"&&n.jsxs(V,{tone:"accent",role:"status",children:[n.jsxs("p",{children:["Here is your code: ",n.jsx("strong",{children:e.login.userCode}),". Open the link, enter it, and approve buddi on openai.com."]}),e.login.userCode&&n.jsx(Fw,{code:e.login.userCode}),e.login.verificationUrl&&n.jsx(ae,{children:n.jsx(dt,{variant:"accent",href:e.login.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open openai.com"})}),e.login.expiresAt&&n.jsxs("p",{className:"muted",children:["The code works until ",zt(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"&&n.jsx("p",{role:"status",className:"muted",children:e.login.message??`Sign-in ${e.login.state}.`})]})}function wq({account:e,busy:t,run:s,onDone:r,codexEnabled:i,anthropicOAuthEnabled:a}){const[l,o]=d.useState((e==null?void 0:e.label)??""),[c,u]=d.useState((e==null?void 0:e.kind)??"anthropic"),[h,f]=d.useState((e==null?void 0:e.auth)??"api-key"),[m,p]=d.useState((e==null?void 0:e.baseUrl)??""),[g,v]=d.useState((e==null?void 0:e.defaultModel)??"claude-sonnet-5"),[b,j]=d.useState(""),[x,w]=d.useState(e!=null&&e.contextWindowTokens?String(e.contextWindowTokens):""),y=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 n.jsxs("form",{className:"ui-stack",onSubmit:N=>{N.preventDefault();const S=b;j(""),s(()=>$.saveProviderAccount({...e?{id:e.id,revision:e.revision}:{},label:l,kind:c,auth:h,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:[n.jsxs("fieldset",{disabled:t,className:"ui-fields","data-stack":"true",children:[n.jsx(oe,{label:"Account name",children:n.jsx("input",{autoFocus:!0,required:!0,maxLength:100,value:l,onChange:N=>o(N.target.value),placeholder:"Anthropic — Personal"})}),n.jsx(oe,{label:"Provider",children:n.jsxs("select",{disabled:!!e,value:h==="anthropic-oauth"?"anthropic-oauth":h==="device-key"?"ollama-cloud":c,onChange:N=>{N.target.value==="anthropic-oauth"?(y("anthropic"),f("anthropic-oauth")):y(N.target.value)},children:[n.jsx("option",{value:"anthropic",children:"Anthropic API"}),n.jsx("option",{value:"openai",children:"OpenAI API"}),n.jsx("option",{value:"openai-compatible",children:"OpenAI-compatible endpoint"}),(e==null?void 0:e.auth)==="device-key"&&n.jsx("option",{value:"ollama-cloud",children:"Ollama Cloud"}),(a||(e==null?void 0:e.auth)==="anthropic-oauth")&&n.jsx("option",{value:"anthropic-oauth",children:"Claude subscription"}),(i||(e==null?void 0:e.kind)==="codex")&&n.jsx("option",{value:"codex",children:"ChatGPT subscription"})]})}),c==="openai-compatible"&&h!=="device-key"&&n.jsxs(n.Fragment,{children:[n.jsx(oe,{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:n.jsx("input",{required:!0,type:"url",value:m,onChange:N=>p(N.target.value)})}),n.jsx(oe,{label:"Authentication",children:n.jsxs("select",{disabled:!!e,value:h,onChange:N=>{f(N.target.value),j("")},children:[n.jsx("option",{value:"api-key",children:"API key"}),n.jsx("option",{value:"none",children:"No key (local/self-hosted)"})]})})]}),n.jsx(ae,{valign:"end",children:n.jsx(Lw,{accountId:e!=null&&e.configured&&e.enabled?e.id:void 0,label:"Default model",value:g,onChange:v,disabled:t},`${e==null?void 0:e.id}:${e==null?void 0:e.revision}`)}),n.jsx(oe,{label:"Context window",hint:Ow(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:n.jsx("input",{type:"number",inputMode:"numeric",min:8e3,max:2e6,step:1e3,value:x,placeholder:e!=null&&e.detectedContextWindowTokens?`${e.detectedContextWindowTokens} (${IR(e)})`:"assumed from the model",onChange:N=>w(N.target.value)})}),c==="codex"&&n.jsx("p",{className:"muted",children:"Pick a model from the list once the account is connected."}),h==="anthropic-oauth"&&n.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."}),h==="api-key"&&n.jsx(oe,{label:e?"Replacement API key (leave blank to keep)":"API key",children:n.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,value:b,onChange:N=>j(N.target.value)})}),e&&n.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."}),n.jsxs(ae,{align:"end",children:[n.jsx(A,{onClick:r,children:"Cancel"}),n.jsx(A,{type:"submit",variant:"accent",disabled:k,children:"Save account"})]})]}),k&&n.jsx("p",{className:"muted",children:"Enter an account name and default model to enable Save account. The example name is a placeholder."})]})}function DR({account:e,busy:t,run:s}){var o;const r=((o=e.login)==null?void 0:o.state)==="pending"&&e.login.attemptId?e.login:null,i=d.useRef(s);i.current=s,d.useEffect(()=>{if(!(r!=null&&r.attemptId))return;let c=!1,u=!1;const h=setInterval(()=>{c||u||(u=!0,$.ollamaPoll(e.id,r.attemptId).then(f=>{c||f.state==="waiting"||(c=!0,f.state==="connected"?i.current(async()=>{},`Connected as ${f.username}, device ${f.deviceName}.`):i.current(async()=>{throw new Error(f.message)},""))}).catch(()=>{}).finally(()=>{u=!1}))},2e3);return()=>{c=!0,clearInterval(h)}},[e.id,r==null?void 0:r.attemptId]);const a=()=>{const c=typeof window.open=="function"?window.open("","_blank"):null;s(async()=>{try{const u=await $.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 n.jsxs(n.Fragment,{children:[l&&n.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}.`}),n.jsxs(ae,{children:[n.jsx(A,{disabled:t||!e.enabled||e.removalPending||!!r,onClick:a,children:e.configured?"Reconnect Ollama":"Connect Ollama"}),n.jsx(A,{disabled:t||!l||e.removalPending,onClick:()=>void s(async()=>({warning:(await $.ollamaDisconnect(e.id,e.revision)).note}),"Disconnected."),children:"Disconnect"})]}),r&&n.jsxs(V,{tone:"accent",role:"status",children:[n.jsxs("p",{children:[n.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."]}),n.jsxs("p",{className:"muted",children:["buddi stops waiting at ",r.expiresAt&&zt(new Date(r.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone),"."]})]})]})}function OR({account:e,enabled:t,busy:s,run:r}){var l,o,c,u,h;const[i,a]=d.useState("");return d.useEffect(()=>{a("")},[(l=e.login)==null?void 0:l.attemptId,(o=e.login)==null?void 0:o.state]),n.jsxs(n.Fragment,{children:[!t&&n.jsx(V,{tone:"warning",children:"Claude subscription sign-in is turned off on this host."}),n.jsxs(ae,{children:[n.jsx(A,{disabled:s||!t||!e.enabled||e.removalPending||((c=e.login)==null?void 0:c.state)==="pending",onClick:()=>void 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"&&n.jsx(A,{disabled:s,onClick:()=>{a(""),r(()=>$.anthropicAccountAction(e.id,"cancel-login",e.revision),"Claude sign-in cancelled.")},children:"Cancel sign-in"}),n.jsx(A,{disabled:s||!e.configured||e.removalPending,onClick:()=>{a(""),r(()=>$.anthropicAccountAction(e.id,"logout",e.revision),"Claude disconnected from Buddi. This does not revoke access at Anthropic.")},children:"Disconnect Claude"})]}),((h=e.login)==null?void 0:h.state)==="pending"&&n.jsxs("form",{className:"ui-notice","data-tone":"accent",onSubmit:f=>{f.preventDefault();const m=i;a(""),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:[n.jsx("p",{children:n.jsx("a",{href:e.login.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open Claude consent page"})}),n.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&&zt(new Date(e.login.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone),"; restarting Buddi also ends it."]}),n.jsx(oe,{label:"Claude authorization code",children:n.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,maxLength:8192,value:i,onChange:f=>a(f.target.value),disabled:s})}),n.jsx(ae,{align:"end",children:n.jsx(A,{type:"submit",variant:"accent",disabled:s||!i.trim(),children:"Complete Claude sign-in"})})]})]})}const gp={anthropic:"claude-sonnet-5",openai:"gpt-5",codex:"gpt-5.5"};function xp(e,t,s){return Bx(e==="codex"?"ChatGPT subscription":e==="anthropic"?t==="anthropic-oauth"?"Claude subscription":"Anthropic API":e==="openai"?"OpenAI API":t==="device-key"?"Ollama Cloud":"Local endpoint",s)}function Bx(e,t){const s=new Set(t.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 yq="That key was refused. Check it and paste it again.";function bq({accounts:e,busy:t,run:s,onDone:r,codexEnabled:i,anthropicOAuthEnabled:a,gemini:l}){const o=e.map(J=>J.label),[c,u]=d.useState(null),[h,f]=d.useState("anthropic"),[m,p]=d.useState("api-key"),[g,v]=d.useState(()=>xp("anthropic","api-key",o)),[b,j]=d.useState(!1),[x,w]=d.useState(""),[y,k]=d.useState(""),[N,S]=d.useState(null),[C,E]=d.useState(!1),[R,I]=d.useState(""),[L,F]=d.useState(""),[T,M]=d.useState(!1),[P,D]=d.useState(!1),[O,H]=d.useState(!1),[B,Y]=d.useState(void 0),W=(J,ye,ge=!1)=>{f(J),p(ye),k(""),S(null),I(""),F(""),M(!1),D(ge),H(!1),Y(void 0),w(ge?"":J==="openai-compatible"?"http://localhost:11434/v1":""),b||v(ge?xp(J,"device-key",o):xp(J,ye,o))},q=J=>{W("openai-compatible",J?"api-key":"device-key",!0),J&&$.ollama().then(ye=>w(ye.cloudBaseUrl)).catch(()=>{})},_=()=>{l&&(W("openai-compatible","api-key"),H(!0),w(l.baseUrl),b||v(Bx("Gemini",o)))},X=()=>{W("openai-compatible","none"),Y(null),b||v(Bx("mlxh",o)),$.mlxh().then(J=>{Y(J),w(J.baseUrl)}).catch(()=>Y(void 0))},Q=B!==void 0,ee=c?e.find(J=>J.id===c):void 0;if(c)return ee?n.jsx(kq,{account:ee,busy:t,run:s,anthropicOAuthEnabled:a,onDone:()=>r(ee.id)}):n.jsx(pe,{children:"Saving…"});const fe=h==="openai-compatible"&&m!=="device-key",Le=h==="codex"||m==="anthropic-oauth"||m==="device-key",Ie=!Le&&(m==="none"||y.trim()!=="")&&(!fe||x.trim()!==""),_e=async()=>{var J,ye;E(!0),I("");try{const ge=await $.probeModels({kind:h,auth:m,...fe?{baseUrl:x}:{},...y.trim()?{secret:y}:{}});S(ge),L||F(((J=ge.models.find($e=>$e.isDefault))==null?void 0:J.id)??((ye=ge.models[0])==null?void 0:ye.id)??"")}catch(ge){I(ge instanceof Error?ge.message:"Could not load models. You can still enter a custom model.")}finally{E(!1)}},U=L.trim(),ie=!g.trim()||fe&&!x.trim()||fe&&!O&&!Q&&!U||O&&!y.trim()||Q&&!(B!=null&&B.running);return n.jsxs("form",{className:"ui-stack",onSubmit:J=>{var De;J.preventDefault();const ye=y;k("");let ge=U||(Q?Lx(B)??((De=B==null?void 0:B.models[0])==null?void 0:De.id):void 0)||(m==="device-key"?md:gp[h])||"claude-sonnet-5",$e;(async()=>{if(O){ge=SR;try{const at=(await $.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:x,secret:ye})).models.map(He=>He.id);ge=CR(at)??ge,$e=AR(ge)?ER(at):void 0}catch{}}let Je,Ue=!1;!await s(async()=>{if(Je=await $.saveProviderAccount({label:g,kind:h,auth:m,baseUrl:x,defaultModel:ge,enabled:!0,...ye.trim()?{secret:ye}:{}}),m!=="api-key")return Je;const Be=await $.testProviderAccount(Je.id);if(Be.state==="connected")return Je;if(xj(Be)){const at=Je.id;Je=void 0;try{const He=(await $.providerAccounts()).accounts.find(kt=>kt.id===at);He&&await $.removeProviderAccount(at,He.revision)}catch{}throw new Error(yq)}if(O&&$e&&TR(Be)){const at=(await $.providerAccounts()).accounts.find(He=>He.id===Je.id);if(at&&(await $.saveProviderAccount({...Hw(at),defaultModel:$e}),(await $.testProviderAccount(Je.id)).state==="connected"))return{...Je,warning:`Account saved. Google's free tier has no Pro allowance, so it starts on ${$e}; turn on billing at Google to use Pro.`}}return Ue=!0,{...Je,warning:`Account saved. ${Be.message}`}},"Account saved.")||!Je||(O||Q||Ue?u(Je.id):U||!Le?r(Je.id):u(Je.id))})()},children:[n.jsxs("fieldset",{disabled:t,className:"ui-fields","data-stack":"true",children:[n.jsx(oe,{label:"Provider",children:n.jsxs("select",{value:m==="anthropic-oauth"?"anthropic-oauth":P?"ollama-cloud":O?"gemini":Q?"mlxh":h,onChange:J=>{if(J.target.value==="anthropic-oauth")W("anthropic","anthropic-oauth");else if(J.target.value==="gemini")_();else if(J.target.value==="mlxh")X();else if(J.target.value==="ollama-cloud")W("openai-compatible","device-key",!0);else{const ye=J.target.value;W(ye,ye==="codex"?"chatgpt":"api-key")}},children:[n.jsx("option",{value:"anthropic",children:"Anthropic API"}),n.jsx("option",{value:"openai",children:"OpenAI API"}),l&&n.jsx("option",{value:"gemini",children:"Gemini (Google AI key)"}),n.jsx("option",{value:"ollama-cloud",children:"Ollama Cloud"}),n.jsx("option",{value:"mlxh",children:"mlxh, local MLX models on this Mac"}),n.jsx("option",{value:"openai-compatible",children:"OpenAI-compatible endpoint (Ollama, OpenRouter, vLLM…)"}),a&&n.jsx("option",{value:"anthropic-oauth",children:"Claude subscription"}),i&&n.jsx("option",{value:"codex",children:"ChatGPT subscription"})]})}),n.jsx(oe,{label:"Account name",hint:"Proposed from the provider. Change it to anything you will recognise.",children:n.jsx("input",{autoFocus:!0,required:!0,maxLength:100,value:g,onChange:J=>{v(J.target.value),j(!0)},placeholder:"Anthropic — Personal"})}),P&&n.jsxs("label",{className:"ui-row",children:[n.jsx("input",{type:"checkbox",checked:m==="api-key",onChange:J=>q(J.target.checked)}),n.jsx("span",{children:"Use a key instead"})]}),fe&&n.jsxs(n.Fragment,{children:[n.jsx(oe,{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:n.jsx("input",{required:!0,type:"url",value:x,onChange:J=>{w(J.target.value),S(null)}})}),!O&&!Q&&n.jsx(oe,{label:"Authentication",children:n.jsxs("select",{value:m,onChange:J=>{p(J.target.value),k(""),S(null)},children:[n.jsx("option",{value:"api-key",children:"API key"}),n.jsx("option",{value:"none",children:"No key (local/self-hosted)"})]})})]}),m==="api-key"&&n.jsx(oe,{label:"API key",hint:"Stored in the vault, never shown again.",children:n.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,value:y,onChange:J=>{k(J.target.value),S(null)}})}),Q?B===null?n.jsx("p",{className:"muted",children:"Looking for mlxh on this computer…"}):B!=null&&B.running?n.jsxs(le,{gap:"sm",children:[n.jsxs("p",{className:"muted",children:["mlxh answers with ",B.models.length===1?"one model":`${B.models.length} models`,". No key: mlxh takes any. buddi starts on ",Lx(B)??"the first","; the next step lists the rest. A model that is not loaded takes up to a minute on its first answer."]}),B.models.some(J=>J.kind==="image")?n.jsxs("p",{className:"muted",children:[B.models.filter(J=>J.kind==="image").map(J=>J.id).join(", "),": ",nR,"."]}):null]}):n.jsx(V,{tone:"warning",children:tR((B==null?void 0:B.baseUrl)??x)}):O&&l?n.jsxs("p",{className:"muted",children:[n.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."]}):Le?n.jsx("p",{className:"muted",children:h==="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."}):n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Model"}),N?n.jsxs("div",{className:"ui-row",children:[n.jsxs("select",{"aria-label":"Model",value:T?"__custom__":L,onChange:J=>{J.target.value==="__custom__"?(M(!0),F("")):(M(!1),F(J.target.value))},children:[N.models.map(J=>n.jsxs("option",{value:J.id,children:[J.name===J.id?J.id:`${J.name} — ${J.id}`,J.isDefault?" (provider default)":"",J.thinks?" · thinks":""]},J.id)),n.jsx("option",{value:"__custom__",children:"Custom model…"})]}),n.jsx(A,{size:"sm",disabled:C||!Ie,onClick:()=>void _e(),children:C?"Loading…":"Reload"})]}):n.jsxs("div",{className:"ui-row",children:[n.jsx(A,{disabled:C||!Ie,onClick:()=>void _e(),children:C?"Loading models…":"Load models"}),fe?n.jsx("span",{className:"muted",children:"Ask the endpoint what it serves."}):n.jsxs("span",{className:"muted",children:["Optional now: ",gp[h]," is used until you pick one."]})]}),T||fe&&!N?n.jsx("input",{"aria-label":"Custom model",required:fe,maxLength:150,value:L,onChange:J=>F(J.target.value),placeholder:fe?"qwen3:8b":gp[h]}):null,R?n.jsx("span",{className:"ui-field-hint critical",role:"alert",children:R}):null,N!=null&&N.truncated?n.jsx("span",{className:"ui-field-hint",children:"Showing the first part of the provider’s list."}):null]}),n.jsxs(ae,{align:"end",children:[n.jsx(A,{onClick:()=>r(),children:"Cancel"}),n.jsx(A,{type:"submit",variant:"accent",disabled:ie,children:"Save account"})]})]}),ie&&!Q&&n.jsxs("p",{className:"muted",children:["Enter an account name",O?" and a key":fe?", an endpoint and a model":""," to enable Save account."]})]})}function kq({account:e,busy:t,run:s,anthropicOAuthEnabled:r,onDone:i}){const[a,l]=d.useState(e.defaultModel),o=e.configured;return n.jsxs(le,{gap:"lg",children:[n.jsxs(V,{tone:"good",children:["Saved “",e.label,"”."]}),e.auth==="anthropic-oauth"&&!o?n.jsx(OR,{account:e,enabled:!!r,busy:t,run:s}):null,e.kind==="codex"&&!o?n.jsx(MR,{account:e,busy:t,run:s}):null,e.auth==="device-key"&&!o?n.jsx(DR,{account:e,busy:t,run:s}):null,o?n.jsxs(n.Fragment,{children:[n.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."}),n.jsx(ae,{valign:"end",children:n.jsx(Lw,{accountId:e.enabled?e.id:void 0,label:"Default model",value:a,onChange:l,disabled:t},`${e.id}:${e.revision}`)}),n.jsxs(ae,{align:"end",children:[n.jsx(A,{onClick:i,children:"Skip for now"}),n.jsx(A,{variant:"accent",disabled:t||!a.trim(),onClick:()=>{if(a===e.defaultModel){i();return}s(()=>$.saveProviderAccount({...Hw(e),defaultModel:a}),"Default model saved.").then(c=>{c&&i()})},children:"Done"})]})]}):n.jsx(ae,{children:n.jsx(A,{onClick:i,children:"Finish later"})})]})}const gN=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 Nq(e){const t=e.toLowerCase().replace(/\.$/,"");if(!t.includes(".")||gN.has(t))return!0;const s=t.slice(t.indexOf(".")+1);return gN.has(`*.${s}`)}function Sq(e){return typeof e=="string"&&e.includes("*")}function Cq(e){const t=/^(https?):\/\/([^/?#@\s]+)(?:[/?#]\S*)?$/i.exec(e.trim());if(t===null)return{ok:!1,reason:"invalid"};const[,s,r]=t;if(!r.startsWith("*.")||r.slice(2).includes("*"))return{ok:!1,reason:"placement"};let i;try{i=new URL(`${s.toLowerCase()}://${r.slice(2)}`)}catch{return{ok:!1,reason:"invalid"}}const a=i.hostname;return a===""||a.startsWith("[")||/^[\d.]+$/.test(a)||a.startsWith(".")||a.includes("..")?{ok:!1,reason:"invalid"}:Nq(a)?{ok:!1,reason:"public-suffix"}:{ok:!0,value:{pattern:`${i.protocol}//*.${i.host}`,protocol:i.protocol,suffix:a,port:i.port}}}const xN=["every-time","first-time","pre-approved"];function LR(e){const t=xN.indexOf(e);return xN.slice(0,t<0?1:t+1)}function Ta(e){return e.endsWith(".account")}const Eq="Stored, not usable until it has a binding.";function Aq(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==="developer.env"?"the workspace, then the variable name — e.g. cour des comptes ADMIN_PASSWORD":Ta(e)?"the account id, e.g. acct-1":'the place, as JSON — e.g. {"host":"localhost","header":"Authorization"}'}const FR={"browser.form.data":{hint:"an origin, then the field name",build:(e,t)=>({origin:e,field:t})},"http.header":{hint:"a host, then the header name",build:(e,t)=>({host:e,header:t})},"http.url":{hint:"a plugin, then the host",build:(e,t)=>({plugin:e,host:t})},"http.basic":{hint:"a plugin, then the host",build:(e,t)=>({plugin:e,host:t})},"developer.env":{hint:"a workspace, then the variable name",build:(e,t)=>({workspace:e,variable:t})}},Tq="A wildcard may only stand for the leftmost part of a site, like *.wikimedia.org.",$q=e=>`That is a public suffix; ${e} would match every site.`,vN="Give the site as an origin, like https://en.wikipedia.org.";function jN(e){const t=/^[a-z][a-z0-9+.-]*:\/\//i.test(e)?e:["https:","//",e].join("");if(Sq(e)){const s=Cq(t);if(s.ok)return{ok:!0,target:s.value.pattern};if(s.reason==="placement")return{ok:!1,error:Tq};if(s.reason==="public-suffix"){const r=t.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/[/?#:].*$/,"").toLowerCase();return{ok:!1,error:$q(r)}}return{ok:!1,error:vN}}try{const s=new URL(t);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:vN}}}function Rq(e){const t=e.search(/\s\S+\s*$/);if(t<=0)return null;const s=e.slice(t).trim(),r=e.slice(0,t).trim();return r&&s?[r,s]:null}function Iq(e,t){const s=t.trim();if(s==="")return{ok:!1,error:"Give the exact place this value may go."};if(s.startsWith("{"))try{const a=JSON.parse(s);return a!==null&&typeof a=="object"&&!Array.isArray(a)?{ok:!0,target:a}:{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 jN(s);if(e==="browser.native.type"||Ta(e))return{ok:!0,target:s};const r=FR[e];if(r===void 0)return{ok:!0,target:s};const i=Rq(s);if(i===null)return{ok:!1,error:`${e} needs both: ${r.hint}.`};if(e==="browser.form.data"){const a=jN(i[0]);return a.ok?{ok:!0,target:r.build(a.target,i[1])}:a}return{ok:!0,target:r.build(i[0],i[1])}}function Pq(e){if(typeof e=="string")return e;try{return JSON.stringify(e)??""}catch{return""}}function _R(e,t){if(typeof t=="string")return t;if(t!==null&&typeof t=="object"&&!Array.isArray(t)){const s=t,r=FR[e];if(r!==void 0){const i=Object.keys(r.build("a","b")),a=i.map(l=>s[l]);if(i.every(l=>typeof s[l]=="string"))return a.join(" · ")}}try{return JSON.stringify(t)??String(t)}catch{return String(t)}}const Zl="accounts.provider";function zR(e,t){if(typeof e!="object"||e===null)return[];const s=e[t];return Array.isArray(s)?s.flatMap(r=>{if(typeof r!="object"||r===null)return[];const i=r.place,a=r.count;return typeof i!="string"||typeof a!="number"||!(a>0)?[]:[{place:i,count:a}]}):[]}function UR(e){const t=e.map(({place:s,count:r})=>`${r.toLocaleString("en-GB")} ${r===1?s.replace(/s$/,""):s}`);return t.length<=1?t[0]??"":`${t.slice(0,-1).join(", ")} and ${t[t.length-1]}`}function Mq(e){const t=zR(e,"found");return t.length?`The value already sits in ${UR(t)}.`:""}function Dq(e){const t=zR(e,"scrubbed");return t.length?`Replaced with ‹secret:…› in ${UR(t)}.`:""}const Oq=/^(PROVIDER_ACCOUNT_|CODEX_ACCOUNT_|ANTHROPIC_ACCOUNT_|OLLAMA_DEVICE_)/,Lq=/^MCP_(TOKEN|ENV|CONNECTION)_/,BR="GMAIL_APP_PASSWORD";function ei(e){const t=e.usedBy??[],s=e.bindings.map(r=>r.kind);if(t.some(r=>r.kind==="mailbox")||s.includes("email.account")||e.name===BR)return"mail";if(t.some(r=>r.kind==="model-account")||s.includes(Zl)||Oq.test(e.name))return"models";if(t.some(r=>r.kind==="connection")||s.includes("mcp.env")||Lq.test(e.name))return"connections";for(const r of e.bindings){if((r.kind==="http.url"||r.kind==="http.basic")&&Kw(r.target)&&typeof r.target.plugin=="string")return`plugin:${r.target.plugin}`;if(Ta(r.kind))return`plugin:${r.kind.slice(0,-8)}`}return"mine"}function Fq(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 t=e.slice(7);return t==="calendar"?{title:"Calendar links and sign-ins",aside:"Private links and app passwords, used only by the calendar plugin."}:{title:t.charAt(0).toUpperCase()+t.slice(1),aside:`Kept for the ${t} plugin.`}}function _q(e,t){const s=r=>r==="mine"?0:r==="mail"?1:r==="models"?3:r==="connections"?4:2;return s(e)-s(t)||e.localeCompare(t)}function WR(e){return e==="models"||e==="connections"}function Kw(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function wN(e){const t=e.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/\/.*$/,"").replace(/^www\./,"");return t.startsWith("*.")?`any ${t.slice(2)} site`:t}const Vw=e=>(e.usedBy??[]).flatMap(t=>t.kind==="mailbox"?[t]:[]),Of=e=>(e.usedBy??[]).find(t=>t.kind==="model-account"),Gw=e=>(e.usedBy??[]).find(t=>t.kind==="connection");function Ho(e,t=new Map){var r,i;const s=ei(e);if(s==="mail"){const a=Vw(e)[0];return a?`${a.provider==="Email"?"Mailbox":a.provider} ${a.auth==="xoauth2"?"sign-in":"app password"}`:"Old mailbox password"}if(s==="models"){const a=Of(e),l=(a==null?void 0:a.id)??((r=e.bindings.find(c=>c.kind===Zl&&typeof c.target=="string"))==null?void 0:r.target),o=typeof l=="string"?t.get(l):void 0;return(o==null?void 0:o.label)??(a==null?void 0:a.label)??"Old model account key"}if(s==="connections")return((i=Gw(e))==null?void 0:i.name)??"Old connection sign-in";if(s.startsWith("plugin:")){const a=/^[^:]{1,40}:\s+(.+)$/.exec(e.name);return a?a[1]:e.name}return e.name}function zq(e,t){var r,i,a;if(ei(e)!=="models")return null;const s=((r=Of(e))==null?void 0:r.id)??((i=e.bindings.find(l=>l.kind===Zl&&typeof l.target=="string"))==null?void 0:i.target);return typeof s=="string"?((a=t.get(s))==null?void 0:a.provider)??null:null}function HR(e,t){const s=Kw(t)?t:{},r=i=>typeof s[i]=="string"?s[i]:"";return e==="browser.field"&&typeof t=="string"?`Filled on ${wN(t)}`:e==="browser.form.data"&&r("origin")?`Filled into “${r("field")}” on ${wN(r("origin"))}`:e==="browser.native.type"&&typeof t=="string"?`Typed into the app ${t}`:(e==="http.header"||e==="http.url"||e==="http.basic")&&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===Zl?"Used by a model account":Ta(e)?`Used by a ${e.slice(0,-8)} account`:`Goes to ${_R(e,t)}`}function Uq(e,t){return Ta(e)||e===Zl?"Signed in":HR(e,t).replace(/^Sent only to/,"Sent to")}const Bq={"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 Wq(e){return e.length<=1?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function qw(e){const t=ei(e);if(t==="mail"){const a=Vw(e).map(l=>l.address);return a.length?`Used by the ${a.length===1?"mailbox":"mailboxes"} ${Wq(a)}`:e.name===BR?"From the old .env setup":"No mailbox uses it"}if(t==="models"){const a=Of(e);return a?Bq[a.auth]??"Key for this model account":"No model account uses it"}if(t==="connections"){const a=Gw(e);if(a!=null&&a.variable)return`Given to the program as ${a.variable}`;const l=e.bindings.find(c=>c.kind==="http.header"),o=l&&Kw(l.target)&&typeof l.target.host=="string"?l.target.host:null;return o?`Sign-in token · sent only to ${o}`:a?"Sign-in for this connection":"No connection uses it"}if(e.bindings.length===0)return"";const s=e.bindings.map(a=>HR(a.kind,a.target));let r=s.length<=2?s.join(" · "):`${s[0]} and ${s.length-1} more places`;const i=new Set(e.bindings.map(a=>a.rule==="first-time"&&a.firstApprovedAt!==null?"pre-approved":a.rule));return i.size===1&&i.has("every-time")&&(r+=" · asks you every time"),i.size===1&&i.has("first-time")&&(r+=" · asks you the first time"),e.totp&&(r+=" · a fresh code each time"),r}function Hq(e,t=Date.now()){return e.lastUse?`Last used ${Fe(e.lastUse.at,t)}`:"Never used"}function Wx(e){return vr("email","settings",{account:e,set:"password"})}function KR(e){var s,r;const t=ei(e);if(t==="models"){const i=(s=Of(e))==null?void 0:s.id;return{label:"Managed in Model accounts",href:i?fA(i):Pe("accounts")}}if(t==="connections"){const i=(r=Gw(e))==null?void 0:r.id;return{label:"Managed in Connections",href:i?mA(i):Pe("connections")}}return null}function VR(e){const t=/is not bound to (.+?)\.?$/.exec(e);if(!t)return null;const s=t[1];return/[0-9a-f]{8}-[0-9a-f]{4}-/i.test(s)?null:s}function GR(e,t=Date.now()){if(e.unused)return null;const s=ei(e),r=Vw(e)[0],i=KR(e),a=()=>r?{label:"Set password",href:Wx(r.id)}:i?{label:s==="models"?"Fix in Model accounts":"Fix in Connections",href:i.href}:{label:"Set a value",action:"replace"},l=e.lastUse,o=l?Fe(l.at,t):"",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:a()};if(r!=null&&r.loginFailedAt)return{text:`${r.provider==="Email"?"The mail server":r.provider} turned it down at sign-in ${Fe(r.loginFailedAt,t)}.`,fix:{label:"Set password",href:Wx(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"?VR(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}: ${YR(c||null)}.`,fix:null}}if((l==null?void 0:l.outcome)==="failed"){const u=r?a():i?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:Cl}}: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 qR(e){if(!e.unused)return"";const t=ei(e);return t==="mail"?"Not used by anything — no mailbox uses it any more.":t==="models"?"Not used by anything — no model account uses it any more.":t==="connections"?"Not used by anything — no connection uses it any more.":"Not used by anything — what it was for is gone."}function Hx(e){return e.usageUnknown&&!e.unused?"Couldn’t check what uses it just now.":""}function il(e){return!!e.unused&&!WR(ei(e))}function Kq(e){if(e.unused||e.bindings.length===0)return"Nothing uses it, so nothing stops working.";const t=qw(e).split(" · ")[0]??"";return t.startsWith("Filled on ")?`Agents can no longer fill it on ${t.slice(10)}.`:t.startsWith("Sent only to ")?`Agents can no longer send it to ${t.slice(13)}.`:`Whatever uses it stops working: ${t.charAt(0).toLowerCase()}${t.slice(1)}.`}const Vq={"every-time":"Every time","first-time":"The first time, then not again","pre-approved":"Never — allowed ahead of time"};function Gq(e){const t={"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","developer.env":"A workspace variable","mcp.env":"A program’s variable",[Zl]:"A model account"};return t[e]?t[e]:Ta(e)?`A ${e.slice(0,-8)} account`:e}const qq={"every-time":"Every time","first-time":"The first time","pre-approved":"Never"};function YR(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 t=/is not bound to/.test(e)?VR(e):void 0;return t!==void 0?t?`asked for at ${t}, where it may not go`:"asked for somewhere it may not go":e.replace(/\.$/,"")}function Yq(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==="developer.env"?"my-app ADMIN_PASSWORD":Ta(e)?"acct-1":'{"host":"localhost","header":"Authorization"}'}function Nh(e){return LR(e).includes("first-time")?"first-time":e}function Jq(e){const t=Uq(e.kind,e.target);return e.outcome==="refused"?{text:`Held back — ${YR(e.detail)}`,tone:"warning"}:e.outcome==="failed"?{text:`Didn’t go through — ${(e.detail??t).replace(/\.$/,"")}`,tone:"warning"}:e.outcome==="pending"?{text:`Asked for your approval · ${t}`}:{text:t}}async function ga(e,t,s,r){s(!0),r(null);try{return(await $.secretsAct(e,t)).result}catch(i){return r(i instanceof Error?i.message:String(i)),null}finally{s(!1)}}const JR="Passwords, keys and links your agents use without ever seeing them. Each goes only where you allow.";function Qq(e,t){if(t==="mail")return"mail";if(t==="models")return"chip";if(t==="connections")return"plug";if(t==="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 Xq({embedded:e,timezone:t,secret:s,adding:r,navigate:i}={}){const a=de(()=>$.secrets(),[]),l=de(()=>$.providerAccounts(),[]),o=d.useMemo(()=>{var g;return new Map((((g=l.data)==null?void 0:g.accounts)??[]).map(v=>[v.id,{label:v.label,provider:RR(v)}]))},[l.data]),[c,u]=d.useState(s?{what:"replace",name:s}:r?{what:"add"}:null);d.useEffect(()=>{s&&u({what:"replace",name:s})},[s]),d.useEffect(()=>{r&&u({what:"add"})},[r]);const h=()=>{u(null),(s||r)&&i&&i(Pe("secrets"))},f=a.data,m=d.useMemo(()=>{const g=new Map;for(const v of(f==null?void 0:f.secrets)??[]){const b=ei(v);g.set(b,[...g.get(b)??[],v])}return[...g.entries()].sort(([v],[b])=>_q(v,b))},[f]),p=c&&c.what!=="add"?(f==null?void 0:f.secrets.find(g=>g.name===c.name))??null:null;return n.jsxs(On,{embedded:e,title:"Keys and secrets",lede:JR,actions:e?void 0:n.jsx(A,{variant:"accent",size:"sm",onClick:()=>u({what:"add"}),children:"Add a secret"}),children:[n.jsxs(le,{gap:"lg",children:[!f&&!a.error?n.jsx(pe,{children:"Opening the vault…"}):null,a.error?n.jsxs(le,{gap:"sm",children:[n.jsx(re,{message:a.error}),n.jsx(ae,{children:n.jsx(A,{onClick:a.reload,children:"Retry"})})]}):null,f&&f.secrets.length===0?n.jsx(qe,{children:n.jsx(In,{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?n.jsx(qe,{flush:!0,children:m.map(([g,v])=>{const b=Fq(g);return n.jsxs("section",{className:"secrets-group","aria-label":b.title,children:[n.jsxs("header",{className:"secrets-group-head",children:[n.jsx("h3",{className:"secrets-group-title",children:b.title}),n.jsx("span",{className:"secrets-group-aside",children:b.aside})]}),n.jsx(rt,{children:v.map(j=>n.jsx(eY,{secret:j,group:g,accounts:o,onOpen:x=>u({what:x,name:j.name})},j.name))})]},g)})}):null,f&&f.ownKeys.length>0?n.jsx(Tt,{summary:`buddi’s own keys · ${f.ownKeys.length}`,children:n.jsxs("p",{className:"secrets-note",children:["The keys buddi itself runs on, read from its environment:"," ",f.ownKeys.map((g,v)=>n.jsxs("span",{children:[v>0?", ":"",n.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?n.jsx(sY,{destinations:f.destinations,onClose:h,onChanged:a.reload}):null,p&&(c==null?void 0:c.what)==="sheet"?n.jsx(tY,{secret:p,accounts:o,timezone:t,onClose:h,onOpen:g=>u({what:g,name:p.name})}):null,p&&(c==null?void 0:c.what)==="replace"?n.jsx(rY,{secret:p,title:Ho(p,o),onClose:h,onChanged:a.reload}):null,p&&(c==null?void 0:c.what)==="rename"?n.jsx(iY,{secret:p,onClose:h,onChanged:a.reload}):null,p&&(c==null?void 0:c.what)==="places"&&f?n.jsx(aY,{secret:p,title:Ho(p,o),destinations:f.destinations,onClose:h,onChanged:a.reload}):null,p&&(c==null?void 0:c.what)==="delete"?n.jsx(lY,{secret:p,title:Ho(p,o),onClose:h,onChanged:a.reload}):null]})}const Sh=e=>t=>{t.stopPropagation(),e==null||e()};function QR({fix:e,onOpen:t}){return"href"in e?n.jsx(dt,{size:"sm",href:e.href,onClick:Sh(),children:e.label}):n.jsx(A,{size:"sm",onClick:Sh(()=>t(e.action)),children:e.label})}function Zq(e,t,s){if(t==="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(t==="mail"){const r=(e.usedBy??[]).find(i=>i.kind==="mailbox");return[r&&!e.unused?{label:"Set a new password",hint:"On the Email page, which tests it first",onSelect:()=>{window.location.hash=Wx(r.id)}}:null,{label:"Usage history",onSelect:()=>s("sheet")},il(e)?"separator":null,il(e)?{label:"Remove…",tone:"critical",onSelect:()=>s("delete")}:null]}return[{label:t==="plugin:calendar"?"Replace link…":"Replace value…",onSelect:()=>s("replace")},{label:"Usage history",onSelect:()=>s("sheet")},il(e)?"separator":null,il(e)?{label:"Remove…",tone:"critical",onSelect:()=>s("delete")}:null]}function eY({secret:e,group:t,accounts:s,onOpen:r}){const i=Ho(e,s),a=zq(e,s),l=[qw(e),Hq(e)].filter(Boolean).join(" · "),o=GR(e),c=qR(e),u=Hx(e),h=WR(t)?KR(e):null;return n.jsx(et,{onClick:()=>r("sheet"),label:`${i}: details`,lead:n.jsx(Pn,{icon:Qq(e,t)}),title:n.jsxs(n.Fragment,{children:[i,a?n.jsx("span",{className:"secrets-tag",children:a}):null]}),sub:n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"secrets-line",children:l}),o?n.jsx("span",{className:"secrets-status","data-tone":"warning",children:o.text}):null,c?n.jsx("span",{className:"secrets-status",children:c}):null,u?n.jsx("span",{className:"secrets-status",children:u}):null]}),side:n.jsxs("span",{className:"secrets-side",children:[o!=null&&o.fix?n.jsx(QR,{fix:o.fix,onOpen:r}):null,c&&il(e)?n.jsx(A,{size:"sm",variant:"ghost",onClick:Sh(()=>r("delete")),children:"Remove…"}):null,h?n.jsxs("a",{className:"secrets-managed",href:h.href,onClick:Sh(),children:[h.label,n.jsx(ce,{name:"chevron-right",size:12})]}):n.jsx(Ys,{label:`More for ${i}`,items:Zq(e,t,r),sheet:{title:i,sub:l}})]})})}function tY({secret:e,accounts:t,timezone:s,onClose:r,onOpen:i}){const a=ei(e),l=Ho(e,t),o=GR(e),c=qR(e),u=[...new Set(e.bindings.map(m=>m.rule))],h=e.lastUse,f=(e.usedBy??[]).map(m=>({label:m.kind==="mailbox"?"Mailbox":m.kind==="model-account"?"Model account":"Connection",value:n.jsx("code",{className:"mono secrets-mono",children:m.id})}));return n.jsx(Ye,{title:l,onClose:r,foot:a==="mine"?n.jsxs(ae,{children:[n.jsx(A,{variant:"danger-ghost",onClick:()=>i("delete"),children:"Delete…"}),n.jsx(ht,{}),n.jsx(A,{onClick:()=>i("rename"),children:"Rename…"}),n.jsx(A,{variant:"accent",onClick:()=>i("replace"),children:"Replace value…"})]}):void 0,children:n.jsxs(le,{gap:"lg",children:[n.jsx(Gt,{items:[{label:"Where it may go",value:qw(e)||"Nowhere yet"},...u.length===1&&a==="mine"?[{label:"Asks you",value:Vq[u[0]]}]:[],{label:"Last used",value:h?`${Fe(h.at)}${h.agentId?` by ${h.agentId}`:""}`:"Never"}]}),o?n.jsx(V,{tone:"warning",action:o.fix?n.jsx(QR,{fix:o.fix,onOpen:i}):void 0,children:o.text}):null,c?il(e)?n.jsxs(V,{action:n.jsx(A,{size:"sm",onClick:()=>i("delete"),children:"Remove…"}),children:[c," Nothing removes it but you."]}):n.jsx(V,{children:c}):null,Hx(e)?n.jsx(V,{children:Hx(e)}):null,n.jsxs(le,{gap:"sm",children:[n.jsx("h3",{className:"secrets-sheet-head",children:"Usage history"}),n.jsx(nY,{name:e.name,timezone:s})]}),n.jsx(Tt,{summary:"Details",children:n.jsxs(le,{gap:"sm",children:[n.jsx(Gt,{items:[{label:"Stored as",value:n.jsx("code",{className:"mono secrets-mono",children:e.name})},...e.bindings.map((m,p)=>({key:`b${p}`,label:p===0?"Bindings":"",value:n.jsxs("code",{className:"mono secrets-mono",children:[m.kind," ",_R(m.kind,m.target)," · ",m.rule]})})),...e.totp?[{label:"One-time code",value:"buddi fills the current code, never the seed"}]:[],...f]}),n.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 nY({name:e,timezone:t}){const s=de(()=>$.secretUses(e,50),[e]);if(s.error)return n.jsx(re,{message:s.error});if(!s.data)return n.jsx(pe,{children:"Reading the history…"});const r=s.data.uses;return r.length===0?n.jsx("p",{className:"secrets-note",children:"Nothing has used it yet."}):n.jsx(rt,{children:r.map((i,a)=>{const l=Jq(i);return n.jsx(et,{title:n.jsx("span",{className:"secrets-history","data-tone":l.tone,children:l.text}),sub:`${nt(i.at,t??"UTC")} · ${i.agent??(i.plugin?`the ${i.plugin} plugin`:"you")}`},a)})})}function XR({title:e,result:t,scrubbed:s,busy:r,failure:i,onScrub:a}){const l=Mq(t);return n.jsxs(le,{gap:"sm",children:[n.jsxs(V,{tone:"good",role:"status",children:["Saved “",e,"”. Its value is never shown again."]}),n.jsx("p",{className:"secrets-note",children:l||"Nothing of the value sits where buddi already holds text."}),n.jsx(re,{message:i}),l?n.jsx(ae,{children:n.jsx(A,{variant:"accent",disabled:r||s!==null,onClick:a,children:s===null?"Scrub the history":Dq(s)||"Nothing of it was left to replace."})}):null]})}function ZR({destinations:e,bindings:t,disabled:s,onChange:r}){const i=(a,l)=>{r(t.map((o,c)=>c===a?{...o,...l}:o))};return n.jsxs(le,{gap:"sm",children:[t.map((a,l)=>{const o=e.find(h=>h.kind===a.kind),c=(o==null?void 0:o.maxRule)??a.rule,u=o?e:[...e,{kind:a.kind,plugin:"",maxRule:a.rule}];return n.jsxs("div",{className:"secrets-place",children:[n.jsx(oe,{label:"Kind of place",children:n.jsx("select",{value:a.kind,disabled:s,onChange:h=>{var p;const f=h.target.value,m=(p=e.find(g=>g.kind===f))==null?void 0:p.maxRule;i(l,{kind:f,rule:m?Nh(m):a.rule})},children:u.map(h=>n.jsx("option",{value:h.kind,children:Gq(h.kind)},h.kind))})}),n.jsx(oe,{label:"The place",children:n.jsx("input",{type:"text",spellCheck:!1,disabled:s,value:a.target,placeholder:Yq(a.kind),onChange:h=>i(l,{target:h.target.value})})}),n.jsx(oe,{label:"Asks you",children:n.jsx("select",{value:a.rule,disabled:s,onChange:h=>i(l,{rule:h.target.value}),children:LR(c).map(h=>n.jsx("option",{value:h,children:qq[h]},h))})}),n.jsx(A,{size:"sm",variant:"ghost",disabled:s,onClick:()=>r(t.filter((h,f)=>f!==l)),children:"Remove"}),n.jsxs("p",{className:"ui-field-hint secrets-place-hint",children:["The place: ",Aq(a.kind),"."]})]},l)}),t.length===0?n.jsx("p",{className:"ui-field-hint",children:Eq}):null,e.length?n.jsx(ae,{children:n.jsx(A,{size:"sm",disabled:s,onClick:()=>r([...t,{kind:e[0].kind,target:"",rule:Nh(e[0].maxRule)}]),children:"Add a place"})}):n.jsx("p",{className:"ui-field-hint",children:"Nothing installed here takes a secret yet, so there is nowhere to send one."})]})}function eI(e){const t=e.map(r=>Iq(r.kind,r.target)),s=t.findIndex(r=>!r.ok);return s!==-1?{ok:!1,error:`Place ${s+1}: ${t[s].error}`}:{ok:!0,bindings:e.map((r,i)=>({kind:r.kind,target:t[i].target,rule:r.rule}))}}function sY({destinations:e,onClose:t,onChanged:s}){const[r,i]=d.useState(""),[a,l]=d.useState(""),[o,c]=d.useState(!1),[u,h]=d.useState(()=>e.length?[{kind:e[0].kind,target:"",rule:Nh(e[0].maxRule)}]:[]),[f,m]=d.useState(!1),[p,g]=d.useState(null),[v,b]=d.useState(null),[j,x]=d.useState(null),w=async()=>{const k=eI(u);if(!k.ok){g(k.error);return}const N=a;l("");const S=await ga("secrets.put",{name:r.trim(),value:N,totp:o,bindings:k.bindings},m,g);S!==null&&(b({name:r.trim(),result:S}),s())},y=async()=>{const k=await ga("secrets.scrub_history",{name:(v==null?void 0:v.name)??""},m,g);k!==null&&(x(k),s())};return v?n.jsx(Ye,{title:"Add a secret",onClose:t,foot:n.jsx(ae,{align:"end",children:n.jsx(A,{onClick:t,children:"Done"})}),children:n.jsx(XR,{title:v.name,result:v.result,scrubbed:j,busy:f,failure:p,onScrub:()=>void y()})}):n.jsx(Ye,{title:"Add a secret",size:"wide",onClose:t,foot:n.jsxs(ae,{align:"end",children:[n.jsx(A,{onClick:t,children:"Cancel"}),n.jsx(A,{type:"submit",form:"secrets-add",variant:"accent",disabled:f,children:"Save secret"})]}),children:n.jsxs("form",{id:"secrets-add",className:"ui-stack","data-gap":"lg",onSubmit:k=>{k.preventDefault(),w()},children:[n.jsxs("fieldset",{disabled:f,className:"ui-stack","data-gap":"sm",children:[n.jsx(oe,{label:"Name",hint:"What agents ask for it by. Saving a name that exists replaces that secret’s value.",children:n.jsx("input",{required:!0,autoFocus:!0,maxLength:200,value:r,onChange:k=>i(k.target.value),placeholder:"PNC password"})}),n.jsx(oe,{label:"Value",hint:"Kept in the vault and never shown again, not even here.",children:n.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,required:!0,value:a,onChange:k=>l(k.target.value)})}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:o,onChange:k=>c(k.target.checked)}),n.jsx("span",{children:"It’s a one-time-code seed — buddi fills the current code, never the seed"})]})]}),n.jsxs("fieldset",{disabled:f,className:"ui-stack","data-gap":"sm",children:[n.jsx("h3",{className:"secrets-sheet-head",children:"Where it may go"}),n.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."}),n.jsx(ZR,{destinations:e,bindings:u,disabled:f,onChange:h})]}),p?n.jsx(V,{tone:"critical",role:"alert",children:p}):null]})})}function rY({secret:e,title:t,onClose:s,onChanged:r}){const[i,a]=d.useState(""),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(null),g=async()=>{const b=i;a("");const j=await ga("secrets.put",{name:e.name,value:b,totp:e.totp,bindings:e.bindings.map(({kind:x,target:w,rule:y})=>({kind:x,target:w,rule:y}))},o,u);j!==null&&(f(j),r())},v=async()=>{const b=await ga("secrets.scrub_history",{name:e.name},o,u);b!==null&&(p(b),r())};return h?n.jsx(Dt,{title:`Replaced the value of “${t}”`,onClose:s,foot:n.jsx(A,{variant:"accent",onClick:s,children:"Done"}),children:n.jsx(XR,{title:t,result:h,scrubbed:m,busy:l,failure:c,onScrub:()=>void v()})}):n.jsx(Dt,{title:`Replace the value of “${t}”`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(A,{type:"submit",form:"secrets-replace",variant:"accent",disabled:l||i==="",children:"Save value"})]}),children:n.jsxs("form",{id:"secrets-replace",className:"ui-stack","data-gap":"sm",onSubmit:b=>{b.preventDefault(),i!==""&&g()},children:[n.jsx(oe,{label:"New value",hint:"Kept in the vault and never shown again. Where it may go stays the same.",children:n.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,required:!0,autoFocus:!0,disabled:l,value:i,onChange:b=>a(b.target.value)})}),n.jsx(re,{message:c})]})})}function iY({secret:e,onClose:t,onChanged:s}){const[r,i]=d.useState(e.name),[a,l]=d.useState(!1),[o,c]=d.useState(null),u=r.trim()!==""&&r.trim()!==e.name,h=async()=>{await ga("secrets.rename",{name:e.name,to:r.trim()},l,c)!==null&&(s(),t())};return n.jsx(Dt,{title:`Rename “${e.name}”`,onClose:t,foot:n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(A,{type:"submit",form:"secrets-rename",variant:"accent",disabled:a||!u,children:"Rename"})]}),children:n.jsxs("form",{id:"secrets-rename",className:"ui-stack","data-gap":"sm",onSubmit:f=>{f.preventDefault(),u&&h()},children:[n.jsx(oe,{label:"Name",hint:"What agents ask for it by. One that uses the old name needs the new one.",children:n.jsx("input",{required:!0,autoFocus:!0,maxLength:200,disabled:a,value:r,onChange:f=>i(f.target.value)})}),n.jsx(re,{message:o})]})})}function aY({secret:e,title:t,destinations:s,onClose:r,onChanged:i}){const[a,l]=d.useState(()=>e.bindings.length?e.bindings.map(m=>({kind:m.kind,target:Pq(m.target),rule:m.rule})):s.length?[{kind:s[0].kind,target:"",rule:Nh(s[0].maxRule)}]:[]),[o,c]=d.useState(!1),[u,h]=d.useState(null),f=async()=>{const m=eI(a);if(!m.ok){h(m.error);return}await ga("secrets.rebind",{name:e.name,bindings:m.bindings},c,h)!==null&&(i(),r())};return n.jsx(Ye,{title:`Where “${t}” may go`,size:"wide",onClose:r,foot:n.jsxs(ae,{align:"end",children:[n.jsx(A,{onClick:r,children:"Cancel"}),n.jsx(A,{type:"submit",form:"secrets-places",variant:"accent",disabled:o,children:"Save"})]}),children:n.jsxs("form",{id:"secrets-places",className:"ui-stack","data-gap":"sm",onSubmit:m=>{m.preventDefault(),f()},children:[n.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."}),n.jsx(ZR,{destinations:s,bindings:a,disabled:o,onChange:l}),u?n.jsx(V,{tone:"critical",role:"alert",children:u}):null]})})}function lY({secret:e,title:t,onClose:s,onChanged:r}){const[i,a]=d.useState(!1),[l,o]=d.useState(null),c=!!e.unused,u=async()=>{await ga("secrets.delete",{name:e.name},a,o)!==null&&(r(),s())};return n.jsxs(Dt,{title:`${c?"Remove":"Delete"} “${t}”?`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(A,{variant:"danger",disabled:i,onClick:()=>void u(),children:c?"Remove":"Delete"})]}),children:[n.jsxs("p",{className:"secrets-dialog-text",children:[Kq(e)," The value is gone for good; its usage history stays, under its name."]}),n.jsx(re,{message:l})]})}function oY({timezone:e,embedded:t}){var p;const{data:s,error:r,reload:i}=de(()=>$.sentinels(),[],3e4),[a,l]=d.useState(null),[o,c]=d.useState(null),u=(s==null?void 0:s.installed)??[],h=((s==null?void 0:s.runs)??[]).filter(g=>g.lastError),f=u.filter(g=>!g.enabled),m=(g,v)=>{l(g),c(null),$.setSentinelEnabled(g,v).catch(b=>c(b instanceof ve?b.message:String(b))).finally(()=>{l(null),i()})};return n.jsxs(On,{embedded:t,title:"Watchers",children:[n.jsx(re,{message:r??o}),n.jsx(V,{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."}),h.length>0?n.jsx(V,{tone:"warning",children:h.length===1?"One watcher failed on its last run.":`${h.length} watchers failed on their last run.`}):null,f.length>0?n.jsxs(V,{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,n.jsx(ue,{title:"Installed",aside:n.jsx("a",{href:`${yt}/alerts`,children:"See what they found"}),panel:!0,flush:!0,children:s?u.length===0?n.jsx(In,{icon:"eye",title:"No watchers are installed",children:"Plugins bring their own."}):n.jsx(rt,{children:u.map(g=>{const v=s.runs.find(b=>b.sentinelId===g.id);return n.jsx(et,{lead:n.jsx(we,{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 ${cY(g.every)}${v!=null&&v.lastError?`. ${v.lastError}`:""}`,side:n.jsxs(n.Fragment,{children:[n.jsx("span",{title:v?nt(v.lastRunAt,e):void 0,children:v?Fe(v.lastRunAt):"never ran"}),n.jsx(A,{size:"sm",disabled:a===g.id,onClick:()=>m(g.id,!g.enabled),children:g.enabled?"Turn off":"Turn on"})]})},g.id)})}):n.jsx(pe,{children:"Loading…"})}),n.jsx(F9,{mutes:((p=s==null?void 0:s.alerts)==null?void 0:p.mutes)??[],onChanged:i})]})}function cY(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 t=Math.max(1,Math.round(e/60));return t===1?"minute":`${t} minutes`}const yN=4,uY={time:"profile",date:"profile",zone:null};function dY({data:e,phone:t}){const s=d.useRef(null),r=f$(),[i,a]=d.useState(.4),l=t?390:1280,o=t?780:800;d.useEffect(()=>{const u=s.current;if(!u)return;const h=()=>a(u.clientWidth/l||.4);if(h(),typeof ResizeObserver>"u")return;const f=new ResizeObserver(h);return f.observe(u),()=>f.disconnect()},[l]);const c=(e==null?void 0:e.owner)??null;return n.jsx("div",{ref:s,className:"lke-preview","data-phone":t?"true":void 0,style:{aspectRatio:`${l} / ${o}`},role:"img","aria-label":"Preview of the lock screen",children:n.jsxs("div",{className:"lk","data-preview":"true","data-bg":bw(e==null?void 0:e.background,e==null?void 0:e.image),"data-phone":t?"true":void 0,"data-view":"glance",style:{width:l,height:o,transform:`scale(${i})`},"aria-hidden":"true",children:[n.jsx(k$,{data:e??null,now:r,phone:t}),n.jsx("footer",{className:"lk-unlock",children:t?n.jsxs("span",{className:"lk-chip lk-enter",children:[n.jsx(ce,{name:"lock",size:14}),n.jsx("span",{children:"Enter PIN"})]}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"lk-who",children:[n.jsx("span",{className:"lk-face",children:(c??"You").slice(0,1).toUpperCase()}),c?n.jsx("span",{className:"lk-owner",children:c}):null]}),n.jsxs("span",{className:"lk-pin",children:[n.jsx(ce,{name:"lock",size:15}),n.jsx("span",{className:"lke-pin-hint",children:"Enter your PIN"})]})]})})]})})}function hY({info:e,placement:t,index:s,count:r,onSize:i,onSettings:a,onMove:l,onRemove:o}){var u;const c=t.label??e.title;return n.jsxs("li",{className:"lke-row","data-key":t.key,children:[n.jsxs("span",{className:"lke-row-text",children:[n.jsx("span",{className:"lke-row-title",children:c}),n.jsx("span",{className:"lke-row-sub",children:e.builtIn?"Built in":`${e.plugin} plugin`})]}),n.jsxs("span",{className:"lke-row-tools",children:[e.sizes.length>1?n.jsx(qt,{label:`Size of ${c}`,options:["small","medium"].filter(h=>e.sizes.includes(h)).map(h=>({value:h,label:h==="small"?"Small":"Medium"})),value:t.size,onChange:i}):null,n.jsxs("span",{className:"lke-row-acts",children:[(((u=e.settings)==null?void 0:u.length)??0)>0?n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Settings for ${c}`,title:"Settings",onClick:a,children:n.jsx(ce,{name:"settings",size:14})}):null,n.jsxs("span",{className:"lke-move",children:[n.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:n.jsx(ce,{name:"chevron-left"})}),n.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:n.jsx(ce,{name:"chevron-right"})})]}),n.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:n.jsx(ce,{name:"close",size:12})})]})]})]})}function bN(e){return e?"place"in e?`place:${e.place}`:`town:${e.timezone}:${e.label}`:""}function fY({clock:e,onClock:t,version:s}){var Y,W,q;const r=e??uY,i=de(()=>$.lockScreen(),[s]),a=de(()=>$.widgets("lock"),[]),l=de(()=>$.owner(),[]),[o,c]=d.useState(void 0),[u,h]=d.useState(!1),[f,m]=d.useState(null),[p,g]=d.useState(null),[v,b]=d.useState(null),[j,x]=d.useState(null);d.useEffect(()=>{a.data&&c(a.data)},[a.data]);const w=((Y=i.data)==null?void 0:Y.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,y=(o==null?void 0:o.lock)??[],k=new Map(((o==null?void 0:o.available)??[]).map(_=>[_.id,_])),N=y.length>=yN,S=_=>{if(!o)return Promise.resolve(!1);const X=o;return m(null),c({...o,lock:_,arranged:{...o.arranged,lock:!0}}),$.saveWidgets("lock",_).then(Q=>(c(Q),i.reload(),!0),Q=>(c(X),m(`Couldn't save the lock screen's widgets: ${Q instanceof Error?Q.message:String(Q)}`),!1))},C=(_,X)=>{const Q=y.slice(),[ee]=Q.splice(_,1);Q.splice(_+X,0,ee),S(Q)},E=(_,X)=>{const Q=k.get(_);!Q||N||S([...y,{key:j$(),widget:_,size:Q.sizes.includes("small")?"small":Q.sizes[0],settings:X}])},R=_=>{if(_==="find"){b({query:"",found:[],busy:!1});return}if(b(null),_==="")return t({...r,zone:null});if(_.startsWith("place:"))return t({...r,zone:{place:_.slice(6)}});const X=r.zone&&!("place"in r.zone)?r.zone:j;X&&t({...r,zone:X})},I=()=>{if(!v||v.query.trim().length<2)return;const _=v.query.trim();b({query:v.query,found:[],busy:!0}),$.findPlace(_).then(({found:X})=>{var Le;const Q=X.filter(Ie=>Ie.timezone);if(Q.length===0){b({query:_,found:[],busy:!1,missed:`Nothing with a timezone found for “${_}”.`});return}const ee=Q[0],fe={label:((Le=ee.name.split(",")[0])==null?void 0:Le.trim())||ee.name,timezone:ee.timezone};x(fe),b(null),t({...r,zone:fe})}).catch(()=>b({query:_,found:[],busy:!1,missed:"The place finder didn’t answer. Try again in a moment."}))},L=new Date,F=_=>zc({dateFormat:_},()=>yr(L,w,{weekday:!0})),T=(((W=l.data)==null?void 0:W.places)??[]).filter(_=>_.timezone&&_.timezone!==w),M=r.zone&&!("place"in r.zone)?r.zone:j,P=((o==null?void 0:o.home)??[]).filter(_=>k.has(_.widget)&&!k.get(_.widget).sensitive),D=((o==null?void 0:o.available)??[]).filter(_=>!_.sensitive),O=((o==null?void 0:o.available)??[]).filter(_=>_.sensitive).map(_=>_.title),H=p?y.find(_=>_.key===p):void 0,B=H?k.get(H.widget):void 0;return n.jsxs(ue,{title:"What it shows",aside:"Every change is kept at once.",panel:!0,children:[n.jsxs("div",{className:"lke",children:[n.jsxs("div",{className:"lke-look",children:[n.jsx(dY,{data:i.data,phone:u}),n.jsxs("div",{className:"lke-look-foot",children:[n.jsx(qt,{label:"Preview on",options:[{value:"desk",label:"Desk"},{value:"phone",label:"Phone"}],value:u?"phone":"desk",onChange:_=>h(_==="phone")}),n.jsxs("span",{className:"lke-look-note",children:["As it shows now",(q=i.data)!=null&&q.focus?", with your focus on":"","."]})]})]}),n.jsxs("div",{className:"lke-controls",children:[n.jsx(re,{message:f}),n.jsxs("div",{className:"lke-group",role:"group","aria-label":"Clock",children:[n.jsx("p",{className:"lke-group-title",children:"Clock"}),n.jsxs("div",{className:"wg-field",role:"group","aria-label":"Time",children:[n.jsx("span",{className:"wg-field-label",children:"Time"}),n.jsx(qt,{label:"Time",options:[{value:"profile",label:uE()},{value:"12h",label:"12-hour"},{value:"24h",label:"24-hour"}],value:r.time,onChange:_=>t({...r,time:_})})]}),n.jsx(oe,{label:"Date",children:n.jsxs("select",{value:r.date,onChange:_=>t({...r,date:_.target.value}),children:[n.jsxs("option",{value:"profile",children:["Profile · ",F(null)]}),n.jsx("option",{value:"short",children:F("short")}),n.jsx("option",{value:"long",children:F("long")}),n.jsx("option",{value:"iso",children:F("iso")}),n.jsx("option",{value:"off",children:"No date"})]})}),n.jsx(oe,{label:"A second clock",hint:"A place in another zone, under the time.",children:n.jsxs("select",{value:v?"find":bN(r.zone),onChange:_=>R(_.target.value),children:[n.jsx("option",{value:"",children:"None"}),T.map(_=>n.jsxs("option",{value:`place:${_.id}`,children:[_.label," — ",_.name.split(",")[0]]},_.id)),r.zone&&"place"in r.zone&&!T.some(_=>_.id===r.zone.place)?n.jsx("option",{value:bN(r.zone),children:"A place no longer in another zone"}):null,M?n.jsx("option",{value:`town:${M.timezone}:${M.label}`,children:M.label}):null,n.jsx("option",{value:"find",children:"Another town…"})]})}),v?n.jsxs("div",{className:"wg-field-stack",children:[n.jsxs("div",{className:"wg-find",children:[n.jsx("input",{autoFocus:!0,value:v.query,placeholder:"Find a town: Tokyo","aria-label":"Find a town for the second clock",onChange:_=>b({...v,query:_.target.value}),onKeyDown:_=>{_.key==="Enter"&&(_.preventDefault(),I()),_.key==="Escape"&&b(null)}}),n.jsx(A,{size:"sm",disabled:v.busy||v.query.trim().length<2,onClick:I,children:v.busy?"Finding…":"Find"})]}),v.missed?n.jsx("span",{className:"ui-field-hint",children:v.missed}):null]}):null]}),n.jsxs("div",{className:"lke-group",role:"group","aria-label":"Widgets",children:[n.jsxs("div",{className:"lke-group-head",children:[n.jsxs("p",{className:"lke-group-title",children:["Widgets ",n.jsxs("span",{className:"lke-count",children:[y.length," of ",yN]})]}),N||!o?n.jsxs(A,{size:"sm",disabled:!0,children:[n.jsx(ce,{name:"plus",size:12})," Add a widget"]}):n.jsx(Ys,{label:"Add a widget",trigger:n.jsxs("button",{type:"button",className:"ui-btn","data-size":"sm",children:[n.jsx(ce,{name:"plus",size:12})," Add a widget"]}),items:[P.length>0?{heading:"As on Home"}:null,...P.map(_=>({label:_.label??k.get(_.widget).title,hint:"same settings",onSelect:()=>E(_.widget,_.settings)})),P.length>0?"separator":null,{heading:"Every widget"},...D.map(_=>({label:_.title,onSelect:()=>E(_.id,{})}))]})]}),o?y.length===0?n.jsx("p",{className:"lke-empty",children:"No widgets: just the clock and the counts."}):n.jsx("ul",{className:"lke-list",children:y.map((_,X)=>{const Q=k.get(_.widget);return Q?n.jsx(hY,{info:Q,placement:_,index:X,count:y.length,onSize:ee=>void S(y.map(fe=>fe.key===_.key?{...fe,size:ee}:fe)),onSettings:()=>g(_.key),onMove:ee=>C(X,ee),onRemove:()=>void S(y.filter(ee=>ee.key!==_.key))},_.key):null})}):n.jsx("p",{className:"lke-empty","aria-busy":"true",children:"Reading the lock screen’s widgets…"}),n.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.",O.length>0?` A sensitive widget — ${O.join(", ")} — never shows here.`:" A sensitive widget never shows here."," ","One with nothing to show right now stays off until it has."]})]}),n.jsxs("p",{className:"lke-note",children:[n.jsx(ce,{name:"moon",size:13}),n.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&&B?n.jsx(g$,{info:B,placement:H,surface:"lock",onClose:()=>g(null),onSave:_=>S(y.map(X=>X.key===H.key?{...X,settings:_}:X)).then(X=>(X&&g(null),X)),onRemove:()=>{g(null),S(y.filter(_=>_.key!==H.key))}}):null]})}const mY=[{id:"earth",label:"Earth"},{id:"field",label:"Buddi"},{id:"dawn",label:"Dawn"},{id:"sea",label:"Sea"},{id:"moss",label:"Moss"},{id:"dusk",label:"Dusk"}],pY=[{value:"1",label:"1 min"},{value:"5",label:"5 min"},{value:"15",label:"15 min"},{value:"60",label:"1 hour"},{value:"never",label:"Never"}],gY=e=>e.delayMinutes===null?"never":String(e.delayMinutes);function Kx(e){if(e instanceof ve){const t=e.detail??{};return e.status===429||t.waitUntil?"Too many wrong tries. Wait a moment, then try again.":e.status===403&&typeof t.triesLeft=="number"?`${e.message} ${t.triesLeft} ${t.triesLeft===1?"try":"tries"} left.`:e.message}return"Something went wrong. Try again."}function xY({kind:e,onClose:t,onDone:s}){const[r,i]=d.useState(""),[a,l]=d.useState(""),[o,c]=d.useState(""),[u,h]=d.useState(null),[f,m]=d.useState(!1),p=e==="remove",g=e!=="set",v=!f&&(!g||r.length>=4)&&(p||a.length>=4&&o.length>=4),b=y=>y.replace(/\D/g,"").slice(0,8),j=e==="set"?"Set a PIN":e==="change"?"Change your PIN":"Remove the PIN?",x=y=>{if(y==null||y.preventDefault(),!v)return;if(!p&&a!==o){h("The two PINs aren’t the same.");return}m(!0),h(null),(p?$.removePin(r):$.setPin(a,g?r:void 0)).then(s).catch(N=>{m(!1),h(Kx(N))})},w=(y,k,N,S)=>n.jsx(oe,{label:y,children:n.jsx("input",{type:"password",inputMode:"numeric",autoComplete:y==="Current PIN"?"current-password":"new-password",maxLength:8,autoFocus:S,value:k,onChange:C=>{h(null),N(b(C.target.value))}})});return n.jsx(Dt,{title:j,onClose:t,foot:n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(A,{variant:p?"danger":"accent",disabled:!v,onClick:()=>x(),children:p?"Remove PIN":e==="set"?"Set PIN":"Change PIN"})]}),children:n.jsxs("form",{className:"lk-form",onSubmit:x,children:[n.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?w("Current PIN",r,i,!0):null,p?null:w(e==="set"?"PIN":"New PIN",a,l,!g),p?null:w("The same again",o,c,!1),u?n.jsx(V,{tone:"critical",children:u}):null,n.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]})})}function vY(e){const t=If(),s=de(()=>$.lockState(),[]),[r,i]=d.useState(null),[a,l]=d.useState(null),[o,c]=d.useState(!1),u=d.useRef(null),h=s.data??t.state,f=b=>{t.update(b),s.reload()},m=b=>{l(null),b.then(f).catch(j=>l(Kx(j)))},p=b=>{b&&(c(!0),l(null),$.uploadLockBackground(b).then(f).catch(j=>l(Kx(j))).finally(()=>{c(!1),u.current&&(u.current.value="")}))};if(!h)return n.jsx(ue,{title:"Lock screen",panel:!0,children:n.jsx(re,{message:s.error?"Couldn’t read the lock screen’s settings.":null})});const g=h.pin,v=(b,j)=>n.jsxs("button",{type:"button",className:"lk-swatch","data-bg":b,"aria-pressed":h.background===b,"aria-label":j,title:j,onClick:()=>m($.setLockSettings({background:b})),children:[b==="image"&&h.image?n.jsx("img",{src:h.image,alt:""}):b==="earth"?n.jsx("img",{src:$x.thumb,alt:""}):n.jsx("span",{className:"lk-swatch-field"}),n.jsx("span",{className:"lk-swatch-label",children:j})]},b);return n.jsxs(n.Fragment,{children:[n.jsxs(ue,{title:"Lock screen",aside:"Kept for every device signed in to this dashboard.",actions:g?n.jsxs(A,{size:"sm",onClick:()=>t.lockNow(),children:[n.jsx(ce,{name:"lock",size:13})," Lock now"]}):void 0,panel:!0,children:[n.jsxs(le,{divided:!0,gap:"lg",children:[n.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."}),n.jsx(re,{message:a}),n.jsxs("div",{className:"lk-pref ui-section",children:[n.jsxs("div",{className:"lk-pref-text",children:[n.jsx("div",{className:"lk-pref-label",children:"PIN"}),n.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?n.jsxs(ae,{children:[n.jsx(A,{size:"sm",variant:"ghost",onClick:()=>i("remove"),children:"Remove…"}),n.jsx(A,{size:"sm",onClick:()=>i("change"),children:"Change…"})]}):n.jsx(A,{size:"sm",variant:"accent",onClick:()=>i("set"),children:"Set a PIN"})]}),n.jsxs("div",{className:"lk-pref ui-section","data-off":g?void 0:"true","aria-disabled":g?void 0:"true",children:[n.jsxs("div",{className:"lk-pref-text",children:[n.jsx("div",{className:"lk-pref-label",children:"Lock after"}),n.jsx("div",{className:"ui-field-hint",children:g?n.jsxs(n.Fragment,{children:["Nobody using it for this long. Lock it yourself from your menu",n.jsxs("span",{className:"lk-shortcut",children:[", or with ",n.jsx("kbd",{className:"lk-kbd",children:t.shortcut})]}),"."]}):"Set a PIN first."})]}),n.jsx(qt,{label:"Lock after",options:pY,value:g?gY(h):"",onChange:b=>{g&&m($.setLockSettings({delayMinutes:b==="never"?null:Number(b)}))}})]}),n.jsxs("div",{className:"lk-pref ui-section","data-stack":"true",children:[n.jsxs("div",{className:"lk-pref-text",children:[n.jsx("div",{className:"lk-pref-label",children:"Background"}),n.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."})]}),n.jsxs("div",{className:"lk-swatches",role:"group","aria-label":"Background",children:[mY.map(b=>v(b.id,b.label)),h.image?v("image","Your picture"):null,n.jsxs("label",{className:"lk-swatch","data-kind":"add","aria-busy":o?"true":void 0,children:[n.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])}}),n.jsx("span",{className:"lk-swatch-field","data-kind":"add",children:n.jsx(ce,{name:"plus",size:16})}),n.jsx("span",{className:"lk-swatch-label",children:o?"Adding…":h.image?"Replace":"Your picture"})]})]}),n.jsxs("p",{className:"lk-credit",children:["Earth: photo by ",n.jsx("a",{href:np.authorUrl,target:"_blank",rel:"noreferrer",children:np.author})," on ",n.jsx("a",{href:np.photoUrl,target:"_blank",rel:"noreferrer",children:"Unsplash"})]}),h.image?n.jsx(ae,{align:"end",children:n.jsx(A,{size:"sm",variant:"ghost",onClick:()=>m($.removeLockBackground()),children:"Remove picture"})}):null]})]}),r?n.jsx(xY,{kind:r,onClose:()=>i(null),onDone:b=>{i(null),f(b)}}):null]}),n.jsx(fY,{clock:h.clock,onClock:b=>m($.setLockSettings({clock:b})),version:`${h.background}:${h.image??""}:${JSON.stringify(h.clock??null)}`})]})}const vp=60;function tI(e){return e instanceof ve?e.message:"Something went wrong. Try again."}function jY(e,t,s=Date.now()){const r=`made ${yr(new Date(e.createdAt),t,{compact:!0})} ${e.createdVia==="cli"?"in the terminal":"here"}`;return`buddi_…${e.hint} · ${r} · ${e.lastUsedAt?`last used ${Fe(e.lastUsedAt,s)}`:"never used"}`}function wY({onClose:e,onMade:t}){const[s,r]=d.useState(""),[i,a]=d.useState(!1),[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(!1),m=!i&&s.trim()!==""&&s.trim().length<=vp,p=g=>{g==null||g.preventDefault(),m&&(a(!0),o(null),$.createApiToken(s.trim()).then(v=>{u({token:v.token,name:v.apiToken.name}),t()}).catch(v=>o(tI(v))).finally(()=>a(!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 n.jsx(Dt,{title:`Token for ${c.name}`,onClose:e,foot:n.jsx(A,{variant:"accent",onClick:e,children:"Done"}),children:n.jsxs("div",{className:"at-form",children:[n.jsxs("div",{className:"at-secret",children:[n.jsx("code",{className:"at-secret-text","aria-label":"The token",children:c.token}),n.jsx(A,{size:"sm",onClick:g,children:h?"Copied":"Copy"})]}),n.jsx(V,{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."}),n.jsx("p",{className:"at-text",children:"Send it as a header on every request:"}),n.jsx("code",{className:"at-try",children:`curl -H "Authorization: Bearer buddi_…" ${location.origin}/api/overview`})]})})}return n.jsx(Dt,{title:"Make a token",onClose:e,foot:n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",onClick:e,children:"Cancel"}),n.jsx(A,{variant:"accent",disabled:!m,onClick:()=>p(),children:"Make token"})]}),children:n.jsxs("form",{className:"at-form",onSubmit:p,children:[n.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."}),n.jsx(oe,{label:"What will use it",hint:`So you can tell tokens apart later. Up to ${vp} characters.`,children:n.jsx("input",{autoFocus:!0,value:s,maxLength:vp,placeholder:"Home Assistant",onChange:g=>{o(null),r(g.target.value)}})}),l?n.jsx(V,{tone:"critical",children:l}):null,n.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]})})}function yY({token:e,onClose:t,onRevoked:s}){const[r,i]=d.useState(!1),[a,l]=d.useState(null),o=()=>{i(!0),l(null),$.revokeApiToken(e.id).then(()=>{s(),t()}).catch(c=>{i(!1),l(tI(c))})};return n.jsxs(Dt,{title:`Revoke “${e.name}”?`,onClose:t,foot:n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(A,{variant:"danger",disabled:r,onClick:o,children:"Revoke"})]}),children:[n.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."}),a?n.jsx(V,{tone:"critical",children:a}):null]})}function bY({timezone:e}){var o;const t=de(()=>$.apiTokens(),[]),[s,r]=d.useState(!1),[i,a]=d.useState(null),l=((o=t.data)==null?void 0:o.tokens)??[];return n.jsxs(le,{gap:"lg",children:[n.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."}),n.jsx(re,{message:t.error?"Couldn’t read the API tokens.":null}),n.jsx(ue,{title:"Tokens",aside:"Kept as a fingerprint · shown once",actions:n.jsx(A,{variant:"accent",size:"sm",onClick:()=>r(!0),children:"Make a token"}),panel:!0,flush:!0,children:t.data&&l.length===0?n.jsxs(pe,{title:"No tokens yet.",children:["Make one here, or in a terminal with ",n.jsx("code",{className:"mono",children:"buddi api-token create <name>"}),"."]}):n.jsx(rt,{children:l.map(c=>n.jsx(et,{lead:n.jsx(Pn,{icon:"key"}),title:c.name,sub:jY(c,e),side:n.jsx(A,{size:"sm",variant:"ghost",onClick:()=>a(c),children:"Revoke…"})},c.id))})}),n.jsxs(ue,{title:"What a token can’t do",panel:!0,children:[n.jsxs("ul",{className:"at-cant",children:[n.jsx("li",{children:"Approve anything, or make a change where your click is the approval. It can reject."}),n.jsx("li",{children:"Change what an agent may do without asking: its tools, who it hands work to, a connection given out, an “Always”."}),n.jsx("li",{children:"Install or run code buddi hasn’t run before: plugins, upgrades, program connections."}),n.jsx("li",{children:"Change how buddi is reached or unlocked — PIN, Tailscale, Telegram pairing, other tokens — or restore a backup."}),n.jsx("li",{children:"Read or store a secret: owner secrets, model account keys, the backup passphrase."})]}),n.jsxs("p",{className:"at-foot",children:["In a terminal: ",n.jsx("code",{className:"mono",children:"buddi api-token create"}),", ",n.jsx("code",{className:"mono",children:"list"}),", ",n.jsx("code",{className:"mono",children:"revoke"}),". Every route, and which a token may call: docs/api.md."]})]}),s?n.jsx(wY,{onClose:()=>r(!1),onMade:()=>t.reload()}):null,i?n.jsx(yY,{token:i,onClose:()=>a(null),onRevoked:()=>t.reload()}):null]})}function kY({embedded:e}){const{data:t,error:s,reload:r}=de(()=>$.owner(),[]);return n.jsxs(On,{embedded:e,title:"You",lede:"What every agent knows about the person it is talking to.",children:[n.jsx(re,{message:s}),t?n.jsxs(le,{gap:"lg",children:[n.jsx(CY,{initial:t,onSaved:r}),n.jsx($Y,{initial:t})]}):null]})}const nI=new Date(Date.UTC(2026,9,1,14,5));function NY(){return[["",`Auto (${zc({timeFormat:null},()=>zt(nI,"UTC"))} here)`],["12h","12-hour · 2:05 PM"],["24h","24-hour · 14:05"]]}function SY(){return[["",`Auto (${zc({dateFormat:null},()=>yr(nI,"UTC",{weekday:!0}))} here)`],["short","Thu, Oct 1"],["long","Thursday, 1 October"],["iso","2026-10-01"]]}function CY({initial:e,onSaved:t}){const[s,r]=d.useState(e.preferredName??""),[i,a]=d.useState(e.timezone??""),[l,o]=d.useState(e.timeFormat??""),[c,u]=d.useState(e.dateFormat??""),[h,f]=d.useState(e.language??""),[m,p]=d.useState(e.about??""),[g,v]=d.useState(!1),[b,j]=d.useState(!1),[x,w]=d.useState(null);d.useEffect(()=>{r(e.preferredName??""),a(e.timezone??""),o(e.timeFormat??""),u(e.dateFormat??""),f(e.language??""),p(e.about??"")},[e.preferredName,e.timezone,e.timeFormat,e.dateFormat,e.language,e.about]);const y=s.trim()!==(e.preferredName??"")||i!==(e.timezone??"")||l!==(e.timeFormat??"")||c!==(e.dateFormat??"")||h.trim()!==(e.language??"")||m.trim()!==(e.about??""),k=async()=>{v(!0),w(null);try{const C=await $.setOwner({preferredName:s.trim()===""?null:s.trim(),timezone:i===""?null:i,timeFormat:l===""?null:l,dateFormat:c===""?null:c,language:h.trim()===""?null:h.trim(),about:m.trim()===""?null:m.trim()});fj({timeFormat:C.timeFormat??null,dateFormat:C.dateFormat??null}),window.dispatchEvent(new Event(Ig)),j(!0),t()}catch(C){w(C instanceof ve?C.message:String(C))}finally{v(!1)}},N=e.zones.length>0?e.zones:[e.detectedTimezone],S=C=>E=>{j(!1),C(E)};return n.jsx(ue,{title:"Your profile",aside:"read by every agent, as context",panel:!0,foot:n.jsxs(n.Fragment,{children:[b&&!y?n.jsx("span",{className:"muted",children:"Saved"}):null,n.jsx(A,{variant:"accent",disabled:!y||g,onClick:()=>void k(),children:g?"Saving…":"Save"})]}),children:n.jsxs(le,{divided:!0,gap:"lg",children:[n.jsx(ue,{title:"Name, time and language",children:n.jsxs(Hs,{children:[n.jsx(oe,{label:"What the agents call you",children:n.jsx("input",{value:s,maxLength:80,placeholder:e.displayName??"Your name",onChange:C=>S(r)(C.target.value)})}),n.jsx(oe,{label:"Timezone",hint:`This host is in ${e.detectedTimezone}. Existing schedules keep the zone they were made in.`,children:n.jsxs("select",{value:i,onChange:C=>S(a)(C.target.value),children:[n.jsx("option",{value:"",children:"Not set (use the host's)"}),N.map(C=>n.jsx("option",{value:C,children:C},C))]})}),n.jsx(oe,{label:"Time",children:n.jsx("select",{value:l,onChange:C=>S(o)(C.target.value),children:NY().map(([C,E])=>n.jsx("option",{value:C,children:E},C))})}),n.jsx(oe,{label:"Dates",hint:"Auto follows this browser's language. Agents write them your way too.",children:n.jsx("select",{value:c,onChange:C=>S(u)(C.target.value),children:SY().map(([C,E])=>n.jsx("option",{value:C,children:E},C))})}),n.jsx(oe,{label:"Answer me in",hint:"A language, as you would say it. Blank mirrors whatever you write in.",children:n.jsx("input",{value:h,maxLength:40,placeholder:"English, français…",onChange:C=>S(f)(C.target.value)})})]})}),n.jsxs(ue,{title:"About you",children:[n.jsx(oe,{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:n.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:C=>S(p)(C.target.value)})}),x?n.jsx(V,{tone:"critical",children:x}):null]})]})})}const EY=["Home","Work"];function AY(e){const t=e.trim().toLowerCase();return t==="home"?"home":t==="work"?"briefcase":"pin"}function kN({label:e,empty:t}){return n.jsx("span",{className:"place-glyph","data-empty":t?"true":void 0,"aria-hidden":"true",children:n.jsx(ce,{name:AY(e),size:18})})}function TY(e){var s;const t=((s=e.name.split(",").pop())==null?void 0:s.trim())??"";return e.address?t&&!e.address.toLowerCase().includes(t.toLowerCase())?`${e.address} · ${t}`:e.address:e.name}function $Y({initial:e}){var c;const[t,s]=d.useState(e.places??[]);d.useEffect(()=>s(e.places??[]),[e]);const[r,i]=d.useState(null),a=e.timezone??e.detectedTimezone,l=EY.filter(u=>!t.some(h=>h.label.toLowerCase()===u.toLowerCase())),o=d.useMemo(()=>new Date,[t]);return n.jsxs(ue,{title:"Places",aside:"the front desk, and plugins you allow",actions:n.jsx(A,{size:"sm",onClick:()=>i({label:""}),children:"Add a place"}),panel:!0,flush:!0,children:[n.jsxs(rt,{children:[t.map(u=>n.jsx(et,{label:`${u.label}: edit`,onClick:()=>i({place:u,label:u.label}),lead:n.jsx(kN,{label:u.label}),title:u.label,sub:TY(u),side:u.timezone&&u.timezone!==a?n.jsxs(we,{children:[zt(o,u.timezone)," there"]}):void 0},u.id)),l.map(u=>n.jsx(et,{label:`${u}: add`,onClick:()=>i({label:u}),lead:n.jsx(kN,{label:u,empty:!0}),title:n.jsx("span",{className:"muted",children:u}),sub:"Not set",side:n.jsx(A,{size:"sm",onClick:h=>{h.stopPropagation(),i({label:u})},children:"Add"})},u))]}),n.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?n.jsx(RY,{editing:r,zones:e.zones.length>0?e.zones:[e.detectedTimezone],onClose:()=>i(null),onSaved:u=>{s(u),i(null)}},((c=r.place)==null?void 0:c.id)??`new:${r.label}`):null]})}function RY({editing:e,zones:t,onClose:s,onSaved:r}){const i=e.place,[a,l]=d.useState(e.label),[o,c]=d.useState((i==null?void 0:i.address)??""),[u,h]=d.useState(i?[{name:i.name,latitude:i.latitude,longitude:i.longitude,...i.timezone?{timezone:i.timezone}:{}}]:null),[f,m]=d.useState(0),[p,g]=d.useState((i==null?void 0:i.timezone)??""),[v,b]=d.useState(null),[j,x]=d.useState(null),[w,y]=d.useState((i==null?void 0:i.address)??""),k=u==null?void 0:u[f],N=()=>{o.trim().length<2||(b("find"),x(null),$.findPlace(o.trim()).then(I=>{var L;h(I.found),y(o.trim()),m(0),g(((L=I.found[0])==null?void 0:L.timezone)??""),I.found.length===0&&x("Nothing found by that name. Try the town, with its country.")}).catch(I=>x(I instanceof ve?I.message:String(I))).finally(()=>b(null)))},S=()=>{k&&(b("save"),x(null),$.savePlace({...i?{id:i.id}:{},label:a.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 ve?I.message:String(I))).finally(()=>b(null)))},C=()=>{i&&(b("remove"),x(null),$.removePlace(i.id).then(I=>r(I.places)).catch(I=>x(I instanceof ve?I.message:String(I))).finally(()=>b(null)))},E=i?i.label:e.label?`Add ${e.label}`:"Add a place",R=p!==""&&!t.includes(p)?[p,...t]:t;return n.jsx(Ye,{title:E,onClose:s,foot:n.jsxs(ae,{children:[i?n.jsx(A,{variant:"danger-ghost",disabled:v!==null,onClick:C,children:v==="remove"?"Removing…":"Remove"}):null,n.jsx(ht,{}),n.jsx(A,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(A,{variant:"accent",disabled:!k||a.trim()===""||v!==null,onClick:S,children:v==="save"?"Saving…":"Save"})]}),children:n.jsxs(le,{gap:"lg",children:[n.jsx(oe,{label:"Name",hint:"What you call it: Home, Work, Mum's.",children:n.jsx("input",{value:a,maxLength:40,autoFocus:!e.label,onChange:I=>l(I.target.value)})}),n.jsx(oe,{label:"Address",hint:"A street address, or just the town.",action:n.jsx(A,{disabled:o.trim().length<2||v!==null,onClick:N,children:v==="find"?"Finding…":"Find"}),children:n.jsx("input",{value:o,maxLength:200,autoFocus:!!e.label&&!i,placeholder:"12 Elm Street, Portland, Maine",onChange:I=>c(I.target.value),onKeyDown:I=>{I.key==="Enter"&&(I.preventDefault(),N())}})}),u&&u.length>0?n.jsx("div",{className:"place-found",role:"radiogroup","aria-label":"Which place",children:u.map((I,L)=>n.jsxs("button",{type:"button",role:"radio","aria-checked":L===f,className:"place-option","data-on":L===f?"true":void 0,onClick:()=>{m(L),g(I.timezone??"")},children:[n.jsx("span",{className:"place-radio","aria-hidden":"true"}),n.jsxs("span",{className:"place-option-text",children:[n.jsx("span",{className:"place-option-name",children:I.name}),n.jsxs("span",{className:"place-option-sub",children:[I.latitude.toFixed(2),", ",I.longitude.toFixed(2),I.timezone?` · ${I.timezone}`:""]})]})]},`${I.latitude},${I.longitude}`))}):n.jsx("p",{className:"place-note-inline",children:"Find it to pin it on the map; nothing is saved until you say Save."}),i&&u&&o.trim()!==w?n.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,n.jsx(oe,{label:"Its timezone",hint:k?"From where it is. Change it if that is wrong.":"Filled in once the place is found.",children:n.jsxs("select",{value:p,disabled:!k,onChange:I=>g(I.target.value),children:[n.jsx("option",{value:"",children:"Not known"}),R.map(I=>n.jsx("option",{value:I,children:I},I))]})}),n.jsx(re,{message:j})]})})}const IY=2e6;function NN(e,t){const s=e.replace(/\r\n/g,`
120
+ `).replace(/\n+$/,"").split(`
121
+ `),r=t.replace(/\r\n/g,`
122
+ `).replace(/\n+$/,"").split(`
123
+ `);if(e.trim()===t.trim())return"(no change)";if(s.length*r.length>IY)return[...s.map(c=>`-${c}`),...r.map(c=>`+${c}`)].join(`
124
+ `);const i=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--)i[c][u]=s[c]===r[u]?i[c+1][u+1]+1:Math.max(i[c+1][u],i[c][u+1]);const a=[];let l=0,o=0;for(;l<s.length&&o<r.length;)s[l]===r[o]?(a.push(` ${s[l]}`),l++,o++):i[l+1][o]>=i[l][o+1]?a.push(`-${s[l++]}`):a.push(`+${r[o++]}`);for(;l<s.length;)a.push(`-${s[l++]}`);for(;o<r.length;)a.push(`+${r[o++]}`);return a.join(`
125
+ `)}const sI={skill:"skill",policy:"rule",change:"change to itself"};function PY(e){return e===null||typeof e!="object"||Array.isArray(e)?String(e??""):Object.entries(e).filter(([t,s])=>!/Id$/.test(t)&&s!==null&&s!==void 0&&s!=="").map(([t,s])=>`${t} ${typeof s=="object"?JSON.stringify(s):String(s)}`).join(" · ")}function Vx(e){return[...new Set(e.split(/[,\n]/).map(t=>t.trim().replace(/^[-*]\s+/,"")).filter(t=>t!==""))]}function MY(e,t){const s=e.change;if(!s||s.part!=="tools")return[];if(t===e.editable)return s.added;const r=new Set(Vx(s.current??""));return Vx(t).filter(i=>!r.has(i))}function DY(e){const t=a=>a.kind==="policy"&&a.ruleKind?`${String(a.payload.plugin??"")}\0${a.ruleKind}`:null,s=new Map;for(const a of e){const l=t(a);l&&s.set(l,(s.get(l)??0)+1)}const r=new Map,i=[];for(const a of e){const l=t(a);if(!l||(s.get(l)??0)<2){i.push(a);continue}let o=r.get(l);o||(o={key:l,label:a.ruleKindLabel||a.ruleKind||"Rules",plugin:String(a.payload.plugin??""),cards:[]},r.set(l,o),i.push(o)),o.cards.push(a)}return i}function OY(e){return"cards"in e}function SN(e,t){return!t||e.kind==="policy"&&e.payload.plugin===t}function LY({embedded:e,plugin:t}){const{data:s,error:r,reload:i}=de(()=>$.proposals(),[],3e4),[a,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState({}),p=async(x,w,y=!1)=>{l(null),c(null),h(x),m(({[x]:k,...N})=>N);try{c(await w()),i()}catch(k){const N=k instanceof Error?k.message:String(k);y?m(S=>({...S,[x]:N})):l(N)}finally{h(null)}},g=IT(),v=((s==null?void 0:s.open)??[]).filter(x=>SN(x,t)),b=((s==null?void 0:s.closed)??[]).filter(x=>SN(x,t)),j=x=>n.jsx(BY,{proposal:x,busy:u===x.id,refusal:f[x.id]??null,onKeep:w=>void p(x.id,async()=>{const y=await $.keepProposal(x.id,w);return`${x.title}: ${y.note}`},!0),onDiscard:w=>void p(x.id,async()=>(await $.discardProposal(x.id,w),`Discarded: ${x.title}. ${x.agent} will be told once and will not propose it again for 90 days.`))},x.id);return n.jsxs(On,{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:[n.jsx(re,{message:r??a}),t?n.jsxs(V,{role:"status",children:["Showing the rules ",t," proposes. ",n.jsx("a",{href:Pe("proposals"),children:"Show every proposal"})]}):null,o?n.jsx(V,{tone:"good",role:"status",children:o}):null,t?null:n.jsx(PT,{offers:g.offers,reload:g.reload}),!s||v.length===0?n.jsx(ue,{title:"Waiting",panel:!0,children:s?t?n.jsx(In,{icon:"bulb",title:`No rule from ${t} is waiting`,children:"It proposes one when you decide the same way several times running."}):n.jsx(In,{icon:"bulb",title:"Nothing proposed",children:"When an agent learns something worth keeping, it waits here."}):n.jsx(pe,{children:"Loading…"})}):n.jsx(ue,{title:"Waiting",aside:`${v.length} to decide`,children:DY(v).map(x=>OY(x)?n.jsx(FY,{group:x,busy:u===x.key,onKeepAll:()=>void p(x.key,async()=>{const w=await $.keepAllProposals(x.cards.map(y=>y.id));return`${x.label}: ${w.note}`}),card:w=>j(w)},x.key):j(x))}),b.length>0?n.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:n.jsx(rt,{children:b.map(x=>{var w;return n.jsx(et,{title:x.title,sub:`${x.agent}: ${_Y(x)}`,side:x.kind==="skill"&&x.state==="kept"&&((w=x.skill)!=null&&w.live)?n.jsxs(ae,{align:"end",children:[n.jsx("span",{className:"muted",children:Fe(x.decidedAt??x.createdAt)}),n.jsx(A,{size:"sm",variant:"ghost",disabled:u===x.id,onClick:()=>void p(x.id,async()=>{const y=x.skill;return await $.removeSkill(x.agent,y.name),`Removed ${y.name} from ${x.agent}. Its versions are kept, and ${x.agent} will not propose it again for 90 days.`}),children:"Remove this skill"})]}):Fe(x.decidedAt??x.createdAt)},x.id)})})}):null,!t&&(s!=null&&s.digest)?n.jsx(UY,{schedule:s.digest.schedule,onSaved:i}):null]})}function FY({group:e,busy:t,onKeepAll:s,card:r}){const i=e.cards.length,a=e.cards.some(l=>l.untrusted);return n.jsx(ds,{tone:a?"warning":"accent",title:`${e.label} (${i})`,meta:n.jsxs(n.Fragment,{children:[n.jsx(we,{children:sI.policy}),n.jsx(we,{mono:!0,children:e.plugin})]}),foot:n.jsx(ae,{align:"end",children:n.jsxs(A,{variant:"accent",size:"sm",disabled:t,onClick:s,children:["Keep all (",i,")"]})}),children:n.jsxs(le,{gap:"sm",children:[n.jsxs("p",{children:[i," 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."]}),n.jsx(Tt,{summary:`Show each of the ${i}`,children:n.jsx(le,{gap:"sm",children:e.cards.map(l=>r(l))})})]})})}function _Y(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 zY=Array.from({length:24},(e,t)=>t),CN=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function UY({schedule:e,onSaved:t}){const[s,r]=d.useState(e.day),[i,a]=d.useState(e.hour),[l,o]=d.useState(!1),[c,u]=d.useState(null),h=s!==e.day||i!==e.hour,f=async()=>{o(!0),u(null);try{await $.setDigestSchedule(s,i),u({tone:"good",text:`The digest now runs on ${CN[s]} at ${String(i).padStart(2,"0")}:00.`}),t()}catch(m){u({tone:"critical",text:m instanceof Error?m.message:String(m)})}finally{o(!1)}};return n.jsx(ue,{title:"Weekly digest",panel:!0,foot:n.jsx(A,{variant:"accent",disabled:l||!h,onClick:()=>void f(),children:"Save"}),children:n.jsxs(le,{children:[n.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: ${Fe(e.next)}.`:""]}),n.jsxs(ae,{children:[n.jsx(oe,{label:"Day",children:n.jsx("select",{value:s,disabled:l,onChange:m=>r(Number(m.target.value)),children:CN.map((m,p)=>n.jsx("option",{value:p,children:m},m))})}),n.jsx(oe,{label:`Hour (${e.timezone})`,children:n.jsx("select",{value:i,disabled:l,onChange:m=>a(Number(m.target.value)),children:zY.map(m=>n.jsxs("option",{value:m,children:[String(m).padStart(2,"0"),":00"]},m))})})]}),c?n.jsx(V,{tone:c.tone,role:"status",children:c.text}):null]})})}function EN(e,t){return e==="tools"?Vx(t).join(`
126
+ `):t}function BY({proposal:e,busy:t,refusal:s,onKeep:r,onDiscard:i}){const[a,l]=d.useState(e.editable??""),[o,c]=d.useState(""),u=e.editable!==null&&a!==e.editable,h=e.payload,f=e.echoes??[],m=e.kind==="change"?e.change??null:null,p=MY(e,a);return n.jsx(ds,{tone:e.untrusted?"warning":"accent",title:e.title,meta:n.jsxs(n.Fragment,{children:[n.jsx(we,{children:sI[e.kind]}),n.jsx(we,{mono:!0,children:e.agent}),e.untrusted?n.jsx(we,{tone:"warning",children:"untrusted text in view"}):null,p.length>0?n.jsx(we,{tone:"warning",children:"widens its tools"}):null]}),foot:n.jsxs(ae,{align:"end",children:[s?n.jsx("span",{className:"proposal-refusal",role:"alert",children:s}):null,n.jsx("input",{"aria-label":"Reason for discarding (optional)",placeholder:"Reason for discarding (optional)",value:o,maxLength:300,disabled:t,onChange:g=>c(g.target.value)}),n.jsx(A,{variant:"ghost",size:"sm",disabled:t,onClick:()=>i(o.trim()||void 0),children:"Discard"}),n.jsx(A,{variant:"accent",size:"sm",disabled:t||e.editable!==null&&a.trim()==="",onClick:()=>r(u?a:void 0),children:u?"Keep my version":"Keep"})]}),children:n.jsxs(le,{gap:"sm",children:[e.why?n.jsx("p",{children:e.why}):null,n.jsxs("p",{className:"ui-card-meta",children:["Proposed by ",e.agent," ",Fe(e.createdAt),e.conversationId?n.jsxs(n.Fragment,{children:[" in ",n.jsx("a",{href:wc(e.conversationId),children:e.turn?`this conversation, turn ${e.turn}`:"this conversation"})]}):null,"."]}),e.untrusted?n.jsxs(V,{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.",n.jsx("ul",{className:"proposal-sources",children:e.sources.map(g=>n.jsx("li",{className:"mono",children:g},g))}),f.length>0?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"proposal-echo-lede",children:"These sentences of it also appear in that text:"}),n.jsx("ul",{className:"proposal-sources","aria-label":"Sentences found in the untrusted text",children:f.map(g=>n.jsx("li",{children:n.jsx("mark",{className:"wb-diff-mark",children:g})},g))})]}):null]}):null,e.kind==="skill"?n.jsxs(n.Fragment,{children:[typeof h.when=="string"?n.jsxs("p",{className:"ui-card-meta",children:["When: ",h.when]}):null,e.skill?n.jsxs(le,{gap:"sm",children:[n.jsxs("p",{className:"ui-card-meta",children:[e.agent," already has this skill (",n.jsxs("a",{href:Et(e.agent,"skills"),children:[e.skill.name,", version ",e.skill.version]}),"). Keeping this writes version ",e.skill.version+1,"; the earlier ones stay readable."]}),n.jsx(sh,{text:NN(e.skill.steps,a),marks:f,label:`Version ${e.skill.version} against this proposal`})]}):null,n.jsx(oe,{label:"The steps, as it would follow them",hint:"Correct them here and keep your version.",children:n.jsx("textarea",{rows:8,value:a,disabled:t,onChange:g=>l(g.target.value)})})]}):null,e.kind==="change"?n.jsxs(n.Fragment,{children:[p.length>0?n.jsxs(V,{tone:"warning",title:`Adds: ${p.join(", ")}`,children:["Keeping this lets ",e.agent," call tools it cannot call now."]}):null,m!=null&&m.refusal&&!u?n.jsx(V,{tone:"warning",title:"Keeping this as proposed will be refused.",children:m.refusal}):null,m&&m.current!==null?n.jsx(sh,{text:NN(EN(m.part,m.current),EN(m.part,a)),marks:f,label:`${e.agent}'s ${m.part==="tools"?"tool list":"instructions"} now, against this proposal`}):typeof h.before=="string"?n.jsx(Tt,{summary:`What its ${h.part==="tools"?"tool list":"instructions"} said when proposed`,children:n.jsx(Pt,{children:h.before})}):null,n.jsx(oe,{label:h.part==="tools"?"Proposed tool list":"Proposed instructions",hint:"Correct it here and keep your version.",children:n.jsx("textarea",{rows:8,value:a,disabled:t,onChange:g=>l(g.target.value)})})]}):null,e.kind==="policy"?n.jsx(Gt,{items:[{label:"Plugin",value:n.jsx("span",{className:"mono",children:String(h.plugin??"")})},{label:"Matches",value:n.jsx("span",{className:"mono",children:PY(h.matcher??{})})},{label:"Does",value:String(h.action??"")},{label:"Learned from",value:(()=>{const g=Array.isArray(h.verdicts)?h.verdicts.length:0;return`${g} ${g===1?"decision":"decisions"}`})()}]}):null]})})}function WY(e){const t=[{label:"Home",path:e.home}];if(e.path===e.home||!e.path.startsWith(`${e.home}/`))return t;let s=e.home;for(const r of e.path.slice(e.home.length+1).split("/"))s=`${s}/${r}`,t.push({label:r,path:s});return t}function HY({start:e,onPick:t,onClose:s}){const[r,i]=d.useState(null),[a,l]=d.useState(null),[o,c]=d.useState(""),u=(p,g=!1)=>{l(null),$.pluginFolders(p).then(v=>{i(v),c("")}).catch(v=>{g&&p!==void 0?u(void 0):l(v instanceof ve?v.message:String(v))})};d.useEffect(()=>{u(e,!0)},[]);const h=o.trim().toLowerCase(),f=((r==null?void 0:r.folders)??[]).filter(p=>h===""||p.name.toLowerCase().includes(h)),m=r?WY(r):[];return n.jsxs(Ye,{title:"Choose the folder",onClose:s,foot:n.jsxs(ae,{children:[n.jsx("span",{className:"plugins-foot-note mono",children:(r==null?void 0:r.path)??""}),n.jsx(ht,{}),n.jsx(A,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(A,{variant:"accent",disabled:!r,onClick:()=>r&&t(r.path),children:"Use this folder"})]}),children:[n.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?n.jsx(ah,{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,n.jsx(Sf,{label:"Find a folder here",value:o,placeholder:"Find a folder here…",onChange:c}),n.jsx(re,{message:a}),r?f.length===0?n.jsx(pe,{children:h===""?"No folders in here.":`No folder here is called anything like “${o.trim()}”.`}):n.jsx(qe,{flush:!0,children:n.jsx(rt,{children:f.map(p=>n.jsx(et,{onClick:()=>u(p.path),label:`Open ${p.name}`,lead:n.jsx(Pn,{icon:"folder"}),title:p.name,side:p.plugin?n.jsx(we,{tone:"accent",children:"package.json"}):void 0},p.path))})}):a?null:n.jsx(pe,{children:"Reading the folders…"}),r!=null&&r.truncated?n.jsx("p",{className:"plugins-note",children:"Only the first 500 folders are listed; find one by name above."}):null]})}const KY="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 AN(){return n.jsxs("p",{className:"plugins-quiet connections-quiet",children:[n.jsx(ce,{name:"globe",size:14}),n.jsxs("span",{children:["A plugin is code buddi installs and runs; a connection is a service or program buddi talks to."," ",n.jsx("a",{href:Pe("connections"),children:"Connections"})]})]})}const VY=1500,GY={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."},qY="Restart buddi to apply it. In a checkout, stop it and run: buddi serve",rI=[{value:"npm",label:"From npm"},{value:"file",label:"A file"},{value:"directory",label:"A directory I built"}],iI="buddi.plugins.install-mode";function YY(){try{const e=window.localStorage.getItem(iI);if(rI.some(t=>t.value===e))return e}catch{}return"npm"}function JY(e){try{window.localStorage.setItem(iI,e)}catch{}}const Ju=".tgz",Ur=(e,t,s)=>`${e} ${e===1?t:s}`;function aI(e){const t=[];return e.tools>0&&t.push(Ur(e.tools,"tool","tools")),e.sentinels>0&&t.push(`${e.sentinels} on a timer`),e.views>0&&t.push(Ur(e.views,"view","views")),e.agents>0&&t.push(`${Ur(e.agents,"agent","agents")} proposed`),t.length===0?"nothing on its own":t.join(", ")}function Gx(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 lI(e){return e.kind==="registry"?"npm":e.kind==="tarball"?"a file":"a directory"}function Yw(e,t){return e.kind==="directory"?"you, from this machine":e.kind==="tarball"?"a file on this machine":t??"nobody npm will name"}function oI(e){return e.author?e.author.name:e.source.kind==="registry"?e.publisher??"nobody npm will name":"you"}function Lf({author:e}){return e.url?n.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",children:e.name}):n.jsx(n.Fragment,{children:e.name})}function qx({value:e}){return e===void 0||e===""?n.jsx("span",{className:"muted",children:"none — this came off a disk"}):n.jsx("span",{className:"plugins-hash",children:e})}function cI(e){return e.length===0?"none; nothing leaves this computer":n.jsx("span",{className:"mono",children:e.join(", ")})}function Jw(e){return e.length===0?"Nothing beyond its own tables, its own folder and its own tools' approvals.":e.map(t=>`It ${t.words}.`).join(" ")}const Ri=e=>e instanceof ve?e.message:String(e);function QY(e){const[t,s]=d.useState(void 0),[r,i]=d.useState(null);return d.useEffect(()=>{if(!e){s(void 0),i(null);return}let a=!1;const l=()=>{$.pluginJob(e).then(c=>{a||(s(c),(c.phase==="done"||c.phase==="failed")&&(a=!0))}).catch(c=>{a||(i(Ri(c)),a=!0)})};l();const o=window.setInterval(l,VY);return()=>{a=!0,window.clearInterval(o)}},[e]),{job:t,error:r}}function XY({plugin:e,pages:t,navigate:s,variant:r}){const i=t.filter(a=>a.plugin===e);return i.length===0?null:n.jsx(n.Fragment,{children:i.map(a=>{const l=xr(a.plugin,a.id);return n.jsx(dt,{size:"sm",variant:r,href:l,"aria-label":`Open ${a.title}`,onClick:o=>{o.stopPropagation(),s&&(o.preventDefault(),s(l))},children:i.length===1?"Open":`Open ${a.title}`},a.id)})})}function uI({plugin:e}){var s;if(e.enabled===!1)return n.jsx(we,{children:"disabled"});const t=(s=e.needs)==null?void 0:s[0];return t?n.jsxs(we,{tone:"warning",children:["needs ",t.plugin]}):e.loadsAtRestart?n.jsx(we,{tone:"accent",children:"loads at restart"}):e.loaded&&e.setup?n.jsx(we,{tone:"warning",children:"needs setup"}):e.loaded?n.jsx(we,{tone:"good",dot:!0,children:"loaded"}):n.jsx(we,{tone:"critical",children:"did not load"})}function Qw({entry:e}){var t;return e.trust==="by-buddi"?n.jsx(we,{tone:"accent",children:"by buddi"}):n.jsxs(we,{tone:"good",children:["reviewed ",((t=e.reviewed)==null?void 0:t.version)??e.version]})}const Yx=Pe("plugins"),jp={installed:Yx,browse:`${Yx}?tab=browse`};function ZY({railPages:e=[],settingsPages:t=[],navigate:s,hash:r=""}={}){const i=de(()=>$.plugins(),[],2e4),[a,l]=d.useState(null),{job:o,error:c}=QY(a),[u,h]=d.useState(null),[f,m]=d.useState(()=>Tk(r));d.useEffect(()=>m(Tk(r)),[r]);const[p,g]=d.useState(()=>Ak(r));d.useEffect(()=>g(Ak(r)),[r]);const[v,b]=d.useState(null),[j,x]=d.useState(null),[w,y]=d.useState(null),[k,N]=d.useState(null),[S,C]=d.useState(!1),E=ne=>{C(!0),$.market(ne).then(N).catch(ke=>N({plugins:[],unavailable:Ri(ke)})).finally(()=>C(!1))};d.useEffect(()=>{f==="browse"&&k===null&&!S&&E(!1)},[f]);const R=ne=>{h(null),l(ne)},I=ne=>h(Ri(ne)),[L,F]=d.useState(!1),T=ne=>{F(!0),b(null),ne.then(ke=>{R(ke.job.id),m("installed")}).catch(I).finally(()=>F(!1))},M=d.useRef(null);d.useEffect(()=>{const ne=G4(r);if(!(ne===null||M.current===ne)){M.current=ne,m("installed"),T($.stagePlugin(ne));try{window.history.replaceState(window.history.state,"",Yx)}catch{}}},[r]);const P=ne=>ke=>{ke.preventDefault(),m(ne),b(null),s==null||s(jp[ne])};d.useEffect(()=>{((o==null?void 0:o.phase)==="done"||(o==null?void 0:o.phase)==="failed")&&i.reload()},[o==null?void 0:o.phase]);const D=i.data,O=(D==null?void 0:D.checkout)??!0,H=(D==null?void 0:D.installed)??[],B=ne=>k==null?void 0:k.plugins.find(ke=>ke.installed!==void 0&&(ke.installed.name??ke.name)===ne.name),Y=ne=>e.some(ke=>ke.plugin===ne),W=(ne,ke)=>Y(ne)?n.jsx(XY,{plugin:ne,pages:e,navigate:s,variant:ke}):void 0,q=ne=>{const ke=e.find(Qe=>Qe.plugin===ne);ke&&s&&s(xr(ke.plugin,ke.id))},_=ne=>{const ke=t.find(Qe=>Qe.plugin===ne);if(!(!ke||!s))return()=>s(vr(ke.plugin,ke.id))},X=((k==null?void 0:k.plugins)??[]).filter(ne=>ne.update).length,Q=(ne,ke)=>$.setPluginEnabled(ne,ke).then(Qe=>{G3(),y({name:ne,notes:Qe.notes??[]}),i.reload()}),ee=(ne,ke,Qe)=>$.uninstallPlugin(ne,ke?{purge:!0,confirm:Qe}:{}).then(ct=>{b(null),y({name:ne,notes:ct.notes??[]}),i.reload()}),fe=ne=>{h(null),Q(ne,!0).catch(I)},Le=(ne,ke)=>{const Qe=k==null?void 0:k.plugins.find(Nt=>{var ut;return(((ut=Nt.installed)==null?void 0:ut.name)??Nt.name)===ne&&Nt.installed!==void 0}),ct=Qe&&ke?`${Qe.npm}@${ke}`:void 0;T(ct?$.updatePlugin(ne,ke,ct):$.updatePlugin(ne,ke))},Ie=ne=>{h(null);const ke=Qe=>{const ct=Qe.plugins.find(Nt=>{var ut;return Nt.name===ne||((ut=Nt.installed)==null?void 0:ut.name)===ne});if(!ct){h(`${ne} is not listed on withbuddi.com. Add it from npm, a file or a directory above, then install this one.`);return}T($.stagePlugin(`${ct.npm}@${ct.version}`))};if(k&&k.plugins.length>0)return ke(k);F(!0),$.market(!1).then(Qe=>{N(Qe),ke(Qe)}).catch(I).finally(()=>F(!1))},_e=(ne,ke)=>ke===void 0?void 0:ke.place==="settings"?vr(ne,ke.id):xr(ne,ke.id),U=ne=>{var Qe;if(ne.enabled===!1)return;const ke=(Qe=ne.needs)==null?void 0:Qe[0];if(ke)switch(ke.state){case"missing":return{label:`Install ${ke.plugin}`,run:()=>Ie(ke.plugin)};case"disabled":return{label:`Enable ${ke.plugin}`,run:()=>fe(ke.plugin)};case"range":return{label:`Update ${ke.plugin}`,run:()=>Le(ke.plugin)};case"setup":{const ct=_e(ke.plugin,ke.page),Nt=ct&&s?()=>s(ct):_(ke.plugin);return Nt?{label:`Set up ${ke.plugin}`,run:Nt}:void 0}default:return{label:`See ${ke.plugin}`,run:()=>b({kind:"installed",name:ke.plugin})}}if(ne.loaded&&ne.setup){const ct=_e(ne.name,ne.setup.page),Nt=ct&&s?()=>s(ct):_(ne.name);return Nt?{label:"Set it up",run:Nt}:void 0}},ie=n.jsxs(Zc,{label:"Plugins",children:[n.jsx(Tl,{href:jp.installed,active:f==="installed",count:X,onClick:P("installed"),children:"Installed"}),n.jsx(Tl,{href:jp.browse,active:f==="browse",onClick:P("browse"),children:"Browse"})]}),J=(D==null?void 0:D.staged)??[],ye=lJ(J,(o==null?void 0:o.phase)==="done"?o.stagedId:void 0),ge=J.find(ne=>ne.id===ye),$e=J.filter(ne=>ne.id!==ye),De=ne=>{b(null),cJ(ne),l(null),i.reload()},Je=(v==null?void 0:v.kind)==="staged"?$e.find(ne=>ne.id===v.name):void 0,Ue=(v==null?void 0:v.kind)==="installed"?H.find(ne=>ne.name===v.name):void 0,be=(v==null?void 0:v.kind)==="market"?k==null?void 0:k.plugins.find(ne=>ne.name===v.name):void 0,Be=w&&!(Ue&&Ue.name===w.name)&&w.notes.length>0?w.notes:null,at=Je?n.jsx(iJ,{staged:Je,onClose:()=>b(null),onInstalled:De,onInstallFirst:Ie,onGone:()=>{b(null),i.reload()}},Je.id):Ue?n.jsx(gJ,{plugin:Ue,listing:B(Ue),notes:(w==null?void 0:w.name)===Ue.name?w.notes:null,canOpen:Y(Ue.name)&&Ue.enabled!==!1,onOpen:()=>q(Ue.name),onClose:()=>b(null),onDisable:()=>x({kind:"disable",name:Ue.name}),onEnable:()=>fe(Ue.name),onRemove:()=>x({kind:"remove",name:Ue.name}),onUpdate:ne=>Le(Ue.name,ne),onSettings:Ue.enabled===!1?void 0:_(Ue.name),firstStep:U(Ue),busy:L}):be?n.jsx(NJ,{entry:be,canOpen:be.installed!==void 0&&Y(be.installed.name??be.name),onOpen:()=>{var ne;return q(((ne=be.installed)==null?void 0:ne.name)??be.name)},onClose:()=>b(null),onInstall:()=>T($.stagePlugin(`${be.npm}@${be.version}`)),onUpdate:ne=>{var ke;return Le(((ke=be.installed)==null?void 0:ke.name)??be.name,ne)},busy:L}):null,He=j?H.find(ne=>ne.name===j.name):void 0,kt=j?n.jsx(xJ,{kind:j.kind,name:j.name,canDisable:(He==null?void 0:He.enabled)!==!1,onCancel:()=>x(null),onDisableInstead:()=>x({kind:"disable",name:j.name}),onDisable:()=>Q(j.name,!1).then(()=>x(null)),onRemove:(ne,ke)=>ee(j.name,ne,ke).then(()=>x(null))},`${j.kind}:${j.name}`):null;if(f==="browse")return n.jsxs(le,{gap:"lg",children:[n.jsx(AN,{}),ie,n.jsx(re,{message:u}),n.jsx(SJ,{kind:p,onKind:g,navigate:s,market:k,loading:S,busy:L,onRetry:()=>E(!0),onOpen:ne=>b({kind:"market",name:ne.name}),onInstall:ne=>T($.stagePlugin(`${ne.npm}@${ne.version}`)),onUpdate:(ne,ke)=>{var Qe;return Le(((Qe=ne.installed)==null?void 0:Qe.name)??ne.name,ke)}}),at]});const Yt=(D==null?void 0:D.builtIn)??[];return n.jsxs(le,{gap:"lg",children:[n.jsx(AN,{}),ie,n.jsx(re,{message:i.error??u??c}),D!=null&&D.unavailable?n.jsx(V,{tone:"warning",children:D.unavailable}):null,Be?n.jsx(V,{role:"status",children:Be.join(" ")}):null,n.jsx(eJ,{trust:(D==null?void 0:D.trust)??"",job:o,busy:o!==void 0&&o.phase!=="done"&&o.phase!=="failed",onStaged:R,onFailed:h}),ge?n.jsx(sJ,{staged:ge,onInstalled:De,onGone:()=>i.reload(),onInstallFirst:Ie},ge.id):null,$e.length>0?n.jsx(qe,{flush:!0,title:"Waiting for you",tool:Ur($e.length,"package","packages"),children:n.jsx("div",{className:"plugins-rows",children:n.jsx(rt,{children:$e.map(ne=>n.jsx(rJ,{staged:ne,onReview:()=>{hI(ne),b({kind:"staged",name:ne.id})},onReject:()=>{h(null),$.rejectStaged(ne.id).then(()=>i.reload()).catch(I)}},ne.id))})})}):null,D!=null&&D.restartNeeded?n.jsx(oJ,{checkout:O,waiting:H.filter(ne=>ne.loadsAtRestart)}):null,n.jsx(dJ,{list:H,firstStepFor:U}),n.jsx(qe,{flush:!0,title:"Installed",tool:D?Ur(H.length,"plugin","plugins"):void 0,children:D?H.length===0?n.jsx(pe,{children:"Nothing installed yet. Only what buddi ships with is here."}):n.jsx("div",{className:"plugins-rows",children:n.jsx(rt,{children:H.map(ne=>n.jsx(fJ,{plugin:ne,listing:B(ne),open:ne.enabled===!1?void 0:W(ne.name,"ghost"),canOpen:Y(ne.name)&&ne.enabled!==!1,busy:L,onDetails:()=>b({kind:"installed",name:ne.name}),onOpen:()=>q(ne.name),onSettings:ne.enabled===!1?void 0:_(ne.name),onDisable:()=>x({kind:"disable",name:ne.name}),onEnable:()=>fe(ne.name),onRemove:()=>x({kind:"remove",name:ne.name}),onUpdate:ke=>Le(ne.name,ke),firstStep:U(ne)},ne.name))})}):n.jsx(pe,{children:"Loading…"})}),Yt.length>0?n.jsx(vJ,{plugins:Yt,openFor:W}):null,at,kt]})}function eJ({trust:e,job:t,busy:s,onStaged:r,onFailed:i}){const[a,l]=d.useState(YY),[o,c]=d.useState(""),[u,h]=d.useState(!1),[f,m]=d.useState(null),[p,g]=d.useState(null),[v,b]=d.useState(!1),[j,x]=d.useState(!1),w=d.useRef(null),y=C=>i(Ri(C)),k=C=>{l(C),JY(C),g(null)},N=()=>{h(!0),$.stagePlugin(o.trim()).then(C=>{r(C.job.id),c("")}).catch(y).finally(()=>h(!1))},S=C=>{if(C){if(!C.name.toLowerCase().endsWith(Ju)){m(null),g(`${C.name} is not a ${Ju}. A packed plugin is the file npm pack writes.`);return}g(null),m(C.name),h(!0),$.uploadPlugin(C).then(E=>r(E.job.id)).catch(y).finally(()=>h(!1))}};return n.jsxs(qe,{title:"Add a plugin",actions:n.jsx(qt,{label:"Where it comes from",options:rI,value:a,onChange:k}),children:[n.jsxs("div",{className:"plugins-add",children:[a==="file"?n.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,R;C.preventDefault(),b(!1),S((R=(E=C.dataTransfer)==null?void 0:E.files)==null?void 0:R[0])},children:[n.jsx(ce,{name:"drop",size:20}),n.jsx("span",{className:"plugins-drop-text",children:p??(f?`${f} — reading it.`:n.jsxs(n.Fragment,{children:["Drop a ",n.jsx("span",{className:"mono",children:Ju})," here: the file ",n.jsx("span",{className:"mono",children:"npm pack"})," ","writes. It is read the moment it lands."]}))}),n.jsx(A,{variant:"accent",disabled:s||u,onClick:()=>{var C;return(C=w.current)==null?void 0:C.click()},children:"Choose a file"}),n.jsx("input",{ref:w,type:"file",accept:Ju,hidden:!0,"aria-hidden":"true",tabIndex:-1,onChange:C=>{var E;S((E=C.target.files)==null?void 0:E[0]),C.target.value=""}})]}):n.jsxs("div",{className:"plugins-add-row",children:[n.jsxs(ae,{valign:"end",children:[n.jsx(oe,{grow:!0,label:a==="npm"?"Package":"The directory it is in",children:n.jsx("input",{type:"text",value:o,placeholder:a==="npm"?"buddi-plugin-weather":"/home/you/code/buddi-plugin-weather",onChange:C=>c(C.target.value)})}),a==="directory"?n.jsx(A,{onClick:()=>x(!0),children:"Browse…"}):null,n.jsx(A,{variant:"accent",disabled:s||u||o.trim()==="",onClick:N,children:"Read it first"})]}),n.jsx("span",{className:"ui-field-hint",children:a==="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."})]}),t?n.jsxs("p",{className:"plugins-status",role:"status","data-tone":t.phase==="failed"?"critical":void 0,children:[GY[t.phase]," ",t.error??""]}):null,n.jsx("div",{className:"plugins-trust",children:n.jsx(V,{tone:"warning",children:e})})]}),j?n.jsx(HY,{start:o.trim().startsWith("/")?o.trim():void 0,onClose:()=>x(!1),onPick:C=>{c(C),x(!1)}}):null]})}function tJ({staged:e}){var r,i;const t=((r=e.uses)==null?void 0:r.areas)??[],s=((i=e.uses)==null?void 0:i.dropped)??[];return n.jsxs("span",{className:"plugins-uses",children:[t.length===0?Jw([]):t.map(a=>n.jsxs("span",{children:["It ",a.words,". ",a.added?n.jsxs(we,{tone:"warning",children:["new in ",e.version]}):null]},a.use)),s.length>0?n.jsxs("span",{className:"muted",children:["No longer: ",s.map(a=>a.words).join("; "),"."]}):null]})}function dI(e,t,s){const[r,i]=d.useState(e.plan??null),[a,l]=d.useState(!1),[o,c]=d.useState(null);return{plan:r,busy:a,failed:o,approve:f=>{l(!0),c(null),$.approveStaged(e.id,{integrity:e.integrity??"",...f?{acknowledgeDrift:!0}:{}}).then(m=>{m.installed?t(e.name):m.plan&&i(m.plan)}).catch(m=>c(Ri(m))).finally(()=>l(!1))},reject:()=>{l(!0),c(null),$.rejectStaged(e.id).then(()=>s()).catch(f=>c(Ri(f))).finally(()=>l(!1))}}}function hI(e){e.openedAt||$.openedStaged(e.id).catch(()=>{})}function nJ({staged:e,onInstallFirst:t}){return n.jsxs("span",{className:"plugins-requires",children:[(e.requires??[]).map(s=>n.jsxs("span",{className:"plugins-require",children:[n.jsxs("span",{title:s.range,children:[n.jsx("span",{className:"mono",children:s.plugin})," ",s.rangeWords??s.range]}),s.state==="ok"?n.jsx("span",{className:"plugins-require-ok",children:s.installed?`${s.installed} is here`:"here"}):s.state==="missing"?n.jsxs(n.Fragment,{children:[n.jsx(we,{tone:"warning",children:"not installed"}),t?n.jsxs(A,{size:"sm",onClick:()=>t(s.plugin),children:["Install ",s.plugin," first"]}):null]}):n.jsx(we,{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")?n.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 fI({staged:e,inSheet:t,onInstallFirst:s}){var i;const r=e.dependencies;return n.jsxs("div",{className:"plugins-staged","data-in":t?"sheet":void 0,children:[n.jsx("div",{className:"plugins-facts",children:n.jsx(Gt,{items:[...e.author?[{label:"By",value:n.jsx(Lf,{author:e.author})}]:[],{label:"From",value:e.uploadedName?`a file you chose · ${e.uploadedName}`:Gx(e.source)},{label:"Published by",value:Yw(e.source,e.publisher)},...e.previousSource&&e.previous?[{label:"Replaces",value:`${e.previous.version}, installed from ${Gx(e.previousSource)}`}]:e.source.kind==="directory"&&((i=e.previous)==null?void 0:i.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?n.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:n.jsx(tJ,{staged:e})},...(e.requires??[]).length>0?[{label:"Needs",value:n.jsx(nJ,{staged:e,onInstallFirst:s})}]:[],{label:"Integrity",value:n.jsx(qx,{value:e.integrity})},...e.stagedHash?[{label:"Files on disk",value:n.jsx(qx,{value:e.stagedHash})}]:[]]})}),n.jsxs("div",{className:"plugins-claim",children:[n.jsx("div",{className:"plugins-claim-head",children:"What it says about itself"}),n.jsx("div",{className:"plugins-claim-note",children:"From its own buddi.md. Nothing has checked it yet."}),e.claims.missing?n.jsx("p",{className:"plugins-claim-text",children:"It ships no buddi.md, so it says nothing about itself at all."}):n.jsxs("p",{className:"plugins-claim-text",children:["“",e.claims.text,"”"]}),n.jsx("div",{className:"plugins-facts",children:n.jsx(Gt,{items:[{label:"Schema it owns",value:e.claims.schema?n.jsx("span",{className:"mono",children:e.claims.schema}):"it claims none"},{label:"Hosts it reaches",value:e.claims.hosts.length===0?"it claims none":n.jsx("span",{className:"mono",children:e.claims.hosts.join(", ")})}]})})]})]})}function mI({plan:e,busy:t,onReject:s,onInstallAnyway:r}){return n.jsxs(ds,{tone:"warning",title:"What it said, and what it does",meta:n.jsx(we,{tone:"warning",children:"read this first"}),foot:n.jsxs(ae,{children:[n.jsx("span",{className:"plugins-foot-note",children:"Install anyway says you read these."}),n.jsx(ht,{}),n.jsx(A,{variant:"ghost",disabled:t,onClick:s,children:"Not this one"}),n.jsx(A,{variant:"danger",disabled:t,onClick:r,children:"Install anyway"})]}),children:[n.jsx("p",{className:"plugins-note",children:"Its prose and its manifest do not agree. Neither is authoritative; the manifest is what actually runs."}),n.jsx("ul",{className:"plugins-drift",children:e.drift.map(i=>n.jsx("li",{children:i},i))}),n.jsx(pI,{unlocks:e.agents??[]})]})}function sJ({staged:e,onInstalled:t,onGone:s,onInstallFirst:r}){const{plan:i,busy:a,failed:l,approve:o,reject:c}=dI(e,t,s);d.useEffect(()=>hI(e),[e.id]);const u=(i==null?void 0:i.drift)??[];return n.jsxs(le,{gap:"sm",children:[n.jsxs(ds,{tone:"accent",title:n.jsxs(n.Fragment,{children:[e.name," ",n.jsx("span",{className:"plugins-ver",children:e.version})]}),meta:n.jsx(we,{children:"read, not installed"}),foot:n.jsxs(ae,{children:[n.jsx("span",{className:"plugins-foot-note",children:"Nothing of it has run."}),n.jsx(ht,{}),n.jsx(A,{variant:"ghost",disabled:a,onClick:c,children:"Not this one"}),n.jsx(A,{variant:"accent",disabled:a||u.length>0,onClick:()=>o(!1),children:"Install"})]}),children:[n.jsx(re,{message:l}),n.jsx(fI,{staged:e,onInstallFirst:r})]}),i&&u.length>0?n.jsx(mI,{plan:i,busy:a,onReject:c,onInstallAnyway:()=>o(!0)}):null]})}function rJ({staged:e,onReview:t,onReject:s}){const r=Fe(e.createdAt);return n.jsx(et,{onClick:t,label:`${e.name}: review`,lead:n.jsx(Pn,{svg:void 0}),title:n.jsxs(n.Fragment,{children:[e.name," ",n.jsx("span",{className:"plugins-ver",children:e.version})]}),sub:`from ${lI(e.source)}${r?` · read ${r}`:""}`,side:n.jsxs("span",{className:"plugins-side",children:[n.jsxs("span",{className:"plugins-wait-extra",children:[n.jsx(we,{children:"read, not installed"}),n.jsx(A,{size:"sm",variant:"ghost",onClick:Il(s),children:"Not this one"})]}),n.jsx(A,{size:"sm",onClick:Il(t),children:"Review"})]})})}function iJ({staged:e,onClose:t,onInstalled:s,onGone:r,onInstallFirst:i}){const{plan:a,busy:l,failed:o,approve:c,reject:u}=dI(e,s,r),h=(a==null?void 0:a.drift)??[];return n.jsxs(Ye,{title:n.jsx(ey,{svg:void 0,name:e.name,version:e.version,by:e.author?n.jsx(Lf,{author:e.author}):Yw(e.source,e.publisher),pills:n.jsxs(n.Fragment,{children:[" · ",n.jsx(we,{children:"read, not installed"})]})}),onClose:t,foot:n.jsxs(ae,{children:[n.jsx("span",{className:"plugins-foot-note",children:"Nothing of it has run."}),n.jsx(ht,{}),n.jsx(A,{variant:"ghost",disabled:l,onClick:u,children:"Not this one"}),n.jsx(A,{variant:"accent",disabled:l||h.length>0,onClick:()=>c(!1),children:"Install"})]}),children:[n.jsx(re,{message:o}),n.jsx(fI,{staged:e,inSheet:!0,onInstallFirst:i}),a&&h.length>0?n.jsx(mI,{plan:a,busy:l,onReject:u,onInstallAnyway:()=>c(!0)}):null]})}const aJ=10*60*1e3;function lJ(e,t,s=Date.now()){if(t&&e.some(a=>a.id===t))return t;const r=[...e].sort((a,l)=>(l.createdAt??"").localeCompare(a.createdAt??""))[0];if(!(r!=null&&r.createdAt))return null;const i=s-Date.parse(r.createdAt);return Number.isFinite(i)&&i<aJ?r.id:null}function oJ({checkout:e,waiting:t}){const[s,r]=d.useState(!1),[i,a]=d.useState(null),l=Iz(t),o=l?`${l} ${t.length===1?"is":"are"} installed.`:"A plugin was installed, disabled or enabled since buddi started, and this buddi has not caught up.";return n.jsxs(le,{gap:"sm",children:[n.jsx(re,{message:i}),n.jsxs(V,{tone:e?"warning":"accent",role:"status",action:e?void 0:n.jsx(A,{size:"sm",variant:"accent",disabled:s,onClick:()=>{r(!0),a(null),gf({kind:"plugins",...l?{line:`Loading ${l}…`}:{line:"Applying your plugin changes…"}},()=>$.serviceAction("restart")).catch(c=>a(Ri(c))).finally(()=>r(!1))},children:"Restart to load it"}),children:[o," ",e?qY:`${l?t.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 Xw="buddi.plugins.justInstalled";function cJ(e){try{window.sessionStorage.setItem(Xw,e)}catch{}}function uJ(){try{return window.sessionStorage.getItem(Xw)}catch{return null}}function dJ({list:e,firstStepFor:t}){var u;const[s,r]=d.useState(()=>uJ()),i=s?e.find(h=>h.name===s):void 0,a=i!==void 0&&(i.loaded||i.needs!==void 0),l=a&&(i.needs!==void 0||i.setup!==void 0),o=()=>{try{window.sessionStorage.removeItem(Xw)}catch{}r(null)};if(d.useEffect(()=>{a&&!l&&o()},[a,l]),!i||!l)return null;const c=t(i);return n.jsx(V,{tone:"accent",role:"status",action:n.jsxs(n.Fragment,{children:[n.jsx(A,{size:"sm",variant:"ghost",onClick:o,children:"Later"}),c?n.jsx(A,{size:"sm",variant:"accent",onClick:()=>{o(),c.run()},children:c.label}):null]}),children:i.needs?`${i.name} is installed and waits. ${Zw(i)}.`:`${i.name} is loaded. First: ${((u=i.setup)==null?void 0:u.note)??"set it up on its settings page."}`})}const Il=e=>t=>{t.stopPropagation(),e()},hJ=e=>e.unlocks.filter(t=>t.drift.state==="not-accepted").length;function Zw(e){var t;return e.needs&&e.needs.length>0?e.needs.map(s=>s.state==="setup"&&s.note?`${s.words}: ${s.note}`:s.words).join(" · "):((t=e.setup)==null?void 0:t.note)??"Not set up yet. Its settings say what it needs."}function fJ({plugin:e,listing:t,open:s,canOpen:r,busy:i,onDetails:a,onOpen:l,onSettings:o,onDisable:c,onEnable:u,onRemove:h,onUpdate:f,firstStep:m}){const p=e.enabled===!1,g=hJ(e),v=!p&&(e.needs!==void 0||e.loaded&&e.setup!==void 0);return n.jsx(et,{onClick:a,label:`${e.name}: details`,dimmed:p,lead:n.jsx(Pn,{svg:t==null?void 0:t.iconSvg}),title:n.jsxs(n.Fragment,{children:[e.name," ",n.jsx("span",{className:"plugins-ver",children:e.version}),g>0?n.jsxs("span",{className:"plugins-ask",children:[Ur(g,"agent","agents")," to accept"]}):null]}),sub:v?n.jsx("span",{className:"plugins-sub","data-tone":"warning",children:Zw(e)}):`by ${oI(e)} · from ${lI(e.source)} · ${aI(e.contribution)}`,side:n.jsxs("span",{className:"plugins-side",children:[v&&m?n.jsx(A,{size:"sm",onClick:Il(m.run),children:m.label}):null,t!=null&&t.update?n.jsxs(A,{size:"sm",disabled:i,onClick:Il(()=>f(t.update)),children:["Update to ",t.update]}):null,v?null:s,!v&&!r&&o?n.jsx(A,{size:"sm",variant:"ghost",onClick:b=>{b.stopPropagation(),o()},children:"Settings"}):null,n.jsx(uI,{plugin:e}),n.jsx(Ys,{label:`More for ${e.name}`,items:[{label:"Details",onSelect:a},r?{label:"Open its page",onSelect:l}:null,o?{label:"Its settings",onSelect:o}:null,e.source.kind==="directory"&&!i?{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:h}]})]})})}const mJ={"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 pI({plugin:e,unlocks:t}){return t.length===0?null:n.jsxs(ue,{title:"Agents it would unlock",children:[n.jsx("div",{className:"plugins-unlocks",children:n.jsx(rt,{children:t.map(s=>n.jsx(pJ,{plugin:e,unlock:s},s.id))})}),n.jsxs("p",{className:"plugins-note",children:["Nothing here is created by installing. Accept creates the agent with the tools listed; change or remove it"," ",n.jsx("a",{href:pt,children:"on the Agents page"}),"."]})]})}function pJ({plugin:e,unlock:t}){const s=dw(e,t.id),r=s.created?"up-to-date":t.drift.state,[i,a]=mJ[r];return n.jsxs("div",{className:"plugins-unlock",children:[n.jsx(et,{title:n.jsxs("span",{className:"plugins-handle",children:["@",t.handle]}),sub:s.created?"Accepted just now. It is on the Agents page.":t.drift.message,side:n.jsxs("span",{className:"plugins-side",children:[n.jsx(we,{tone:i,children:a}),e&&r==="not-accepted"?n.jsx(A,{size:"sm",variant:"accent",disabled:s.busy,onClick:s.accept,children:"Accept"}):null]})}),n.jsx(re,{message:s.failure}),s.created?n.jsx($T,{agent:s.created}):null]})}function ey({svg:e,name:t,version:s,by:r,pills:i}){return n.jsxs("span",{className:"plugins-sheet-title",children:[n.jsx(Pn,{svg:e,size:"lg"}),n.jsxs("span",{className:"plugins-sheet-name",children:[n.jsxs("span",{children:[t," ",n.jsx("span",{className:"plugins-ver",children:s})]}),n.jsxs("span",{className:"plugins-sheet-by",children:["by ",r,i]})]})]})}function gJ({plugin:e,listing:t,notes:s,canOpen:r,busy:i,onOpen:a,onSettings:l,onClose:o,onDisable:c,onEnable:u,onRemove:h,onUpdate:f,firstStep:m}){var x,w;const p=e.enabled===!1,g=e.author!==void 0&&e.source.kind==="directory",v=(t==null?void 0:t.summary)??e.description,b=(e.network??((w=(x=t==null?void 0:t.claims)==null?void 0:x.manifest)==null?void 0:w.network)??[]).map(y=>y.host),j=e.uses??(t==null?void 0:t.usesWords);return n.jsxs(Ye,{title:n.jsx(ey,{svg:t==null?void 0:t.iconSvg,name:e.name,version:e.version,by:e.author?n.jsx(Lf,{author:e.author}):oI(e),pills:n.jsxs(n.Fragment,{children:[t?n.jsxs(n.Fragment,{children:[" · ",n.jsx(Qw,{entry:t})]}):null," · ",n.jsx(uI,{plugin:e})]})}),onClose:o,foot:n.jsxs(ae,{children:[n.jsx(A,{variant:"danger-ghost",onClick:h,children:"Remove…"}),n.jsx(ht,{}),l?n.jsx(A,{variant:"ghost",onClick:l,children:"Settings"}):null,r?n.jsx(A,{onClick:a,children:"Open"}):null,p?n.jsx(A,{onClick:u,children:"Enable"}):n.jsx(A,{variant:"ghost",onClick:c,children:"Disable…"}),t!=null&&t.update?n.jsxs(A,{variant:"accent",disabled:i,onClick:()=>f(t.update),children:["Update to ",t.update]}):n.jsx(A,{disabled:i,onClick:()=>f(),children:e.source.kind==="directory"?"Reinstall from folder":"Check for an update"})]}),children:[e.error?n.jsx(V,{tone:"critical",children:e.error}):null,s&&s.length>0?n.jsx(V,{role:"status",children:s.join(" ")}):null,p?n.jsx(V,{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?n.jsxs(V,{tone:"warning",action:m?n.jsx(A,{size:"sm",variant:"accent",onClick:m.run,children:m.label}):void 0,children:["Waiting: ",Zw(e),". Its tools and widgets stay off until then; its data is kept."]}):!p&&e.loaded&&e.setup?n.jsxs(V,{tone:"warning",action:m?n.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?n.jsx("p",{className:"plugins-summary-full",children:v}):null,n.jsx("div",{className:"plugins-facts",children:n.jsx(Gt,{items:[{label:"From",value:Gx(e.source)},...g?[]:[{label:"Published by",value:Yw(e.source,e.publisher)}],{label:"Integrity",value:n.jsx(qx,{value:e.integrity})},{label:"Installed",value:Fe(e.installedAt)},...e.installedAs?[{label:"Installed as",value:e.installedAs}]:[],{label:"Contributes",value:aI(e.contribution)},...e.network||t?[{label:"Talks to hosts",value:cI(b)}]:[],...j?[{label:"Reaches in buddi",value:Jw(j)}]:[]]})}),n.jsx(pI,{plugin:e.name,unlocks:e.unlocks})]})}function xJ({kind:e,name:t,canDisable:s,onCancel:r,onDisableInstead:i,onDisable:a,onRemove:l}){const[o,c]=d.useState(!1),[u,h]=d.useState(""),[f,m]=d.useState(!1),[p,g]=d.useState(null),v=j=>{m(!0),g(null),j().catch(x=>g(Ri(x))).finally(()=>m(!1))};if(e==="disable")return n.jsxs(Dt,{title:`Disable ${t}?`,onClose:r,foot:n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",disabled:f,onClick:r,children:"Cancel"}),n.jsx(A,{variant:"accent",disabled:f,onClick:()=>v(a),children:"Disable"})]}),children:[n.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."}),n.jsx(re,{message:p})]});const b=!o||u.trim()===t;return n.jsxs(Dt,{title:`Remove ${t}?`,onClose:r,foot:n.jsxs(n.Fragment,{children:[s?n.jsx(A,{variant:"ghost",size:"sm",disabled:f,onClick:i,children:"Disable instead"}):null,n.jsx(ht,{}),n.jsx(A,{variant:"ghost",disabled:f,onClick:r,children:"Cancel"}),n.jsx(A,{variant:"danger",disabled:f||!b,onClick:()=>v(()=>l(o,u.trim())),children:o?"Remove and drop its data":"Remove"})]}),children:[n.jsxs("p",{className:"plugins-dialog-text",children:["This takes ",t," off this machine and stops its code loading. Its tables and the agents you accepted from it stay."]}),n.jsxs("div",{className:"plugins-purge","data-on":o?"true":void 0,children:[n.jsxs("label",{className:"plugins-check",children:[n.jsx("input",{type:"checkbox",checked:o,onChange:j=>{c(j.target.checked),h("")}}),n.jsxs("span",{children:[n.jsx("span",{className:"plugins-check-title",children:"Also drop its data"}),n.jsx("span",{className:"plugins-check-hint",children:"Its tables are gone for good; there is no undo."})]})]}),o?n.jsx(oe,{label:n.jsxs(n.Fragment,{children:["Type ",n.jsx("span",{className:"mono",children:t})," to confirm"]}),children:n.jsx("input",{autoFocus:!0,value:u,onChange:j=>h(j.target.value)})}):null]}),n.jsx(re,{message:p})]})}function vJ({plugins:e,openFor:t}){return n.jsxs(Tt,{boxed:!0,summary:`Ships with buddi · ${Ur(e.length,"plugin","plugins")}`,children:[n.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."}),n.jsx("div",{className:"plugins-builtins",children:e.map(s=>{const r=(s.network??[]).map(a=>a.host),i=[s.description,s.author?`By ${s.author.name}.`:null,r.length>0?`Talks to ${r.join(", ")}.`:null].filter(Boolean).join(" ");return n.jsxs("div",{className:"plugins-builtin",title:i||void 0,children:[n.jsx("span",{className:"mono",children:s.name}),n.jsxs("span",{className:"plugins-builtin-n",children:[t(s.name,"ghost"),Ur(s.contribution.tools,"tool","tools")]})]},s.name)})})]})}const jJ=[{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 wJ(e,t){const s=t.trim().toLowerCase();return s===""?!0:[e.title,e.summary,e.npm].some(r=>r.toLowerCase().includes(s))}function yJ({pricing:e}){return e.kind==="free"?n.jsx(n.Fragment,{children:"free"}):n.jsxs(n.Fragment,{children:[e.kind==="paid"?"paid":"a subscription",e.trialDays?` · ${e.trialDays} days to try`:"",e.note?` · ${e.note}`:"",e.vendor?n.jsxs(n.Fragment,{children:[" · ",n.jsx("a",{href:e.vendor,target:"_blank",rel:"noopener noreferrer",children:"its maker's page"})]}):null]})}function bJ({entry:e,busy:t,onOpen:s,onInstall:r,onUpdate:i}){var a;return n.jsxs(ds,{onClick:s,label:`${e.title}: details`,children:[n.jsxs("div",{className:"plugins-card-head",children:[n.jsx(Pn,{svg:e.iconSvg,size:"lg"}),n.jsxs("div",{className:"plugins-card-name",children:[n.jsx("h3",{className:"ui-card-title",children:e.title}),n.jsxs("div",{className:"plugins-card-by",children:["by ",((a=e.author)==null?void 0:a.name)??"someone who gave no name"]})]})]}),n.jsx("p",{className:"plugins-summary",children:e.summary}),n.jsxs("div",{className:"plugins-card-foot",children:[n.jsx(Qw,{entry:e}),e.installed?n.jsxs(we,{children:["installed ",e.installed.version]}):null,n.jsx(ht,{}),e.update?n.jsxs(A,{size:"sm",disabled:t,onClick:Il(()=>i(e.update)),children:["Update to ",e.update]}):e.installed?null:n.jsx(A,{size:"sm",variant:"accent",disabled:t,onClick:Il(r),children:"Install"})]})]})}function kJ(e){var o,c;const t=(o=e.claims)==null?void 0:o.manifest,s=t==null?void 0:t.tools;if(!s)return;const r=s.filter(u=>u.tier==="auto").length,i=s.length-r,a=((c=t==null?void 0:t.sentinels)==null?void 0:c.length)??0,l=[r>0?`${r} run without asking`:null,i>0?`${i} ask${i===1?"s":""} you first`:null,a>0?`${a} on a timer`:null].filter(Boolean);return l.length===0?"none":l.join(", ")}function NJ({entry:e,canOpen:t,busy:s,onOpen:r,onClose:i,onInstall:a,onUpdate:l}){var m,p,g,v,b,j,x,w;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(y=>y.host),u=kJ(e),h=((j=(b=(v=e.claims)==null?void 0:v.manifest)==null?void 0:b.agents)==null?void 0:j.length)??0,f=(w=(x=e.claims)==null?void 0:x.package)==null?void 0:w.dependencies;return n.jsxs(Ye,{title:n.jsx(ey,{svg:e.iconSvg,name:e.title,version:e.version,by:e.author?n.jsx(Lf,{author:e.author}):"someone who gave no name",pills:n.jsxs(n.Fragment,{children:[" · ",n.jsx(Qw,{entry:e}),e.installed?n.jsxs(n.Fragment,{children:[" · ",n.jsxs(we,{children:["installed ",e.installed.version]})]}):null]})}),onClose:i,foot:n.jsxs(ae,{children:[n.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."}),n.jsx(ht,{}),t?n.jsx(A,{onClick:r,children:"Open"}):null,e.update?n.jsxs(A,{variant:"accent",disabled:s,onClick:()=>l(e.update),children:["Update to ",e.update]}):e.installed?null:n.jsx(A,{variant:"accent",disabled:s,onClick:a,children:"Install"})]}),children:[o?n.jsx("img",{className:"plugins-shot",src:$.marketAssetUrl(o),alt:`${e.title}, as it looks in buddi`}):null,n.jsx("p",{className:"plugins-summary-full",children:e.summary}),n.jsx("div",{className:"plugins-facts",children:n.jsx(Gt,{items:[{label:"Package",value:n.jsx("span",{className:"mono",children:`${e.npm}@${e.version}`})},...u?[{label:"Tools",value:u}]:[],...h>0?[{label:"Proposes",value:`${Ur(h,"agent","agents")}, created only if you accept`}]:[],{label:"Talks to hosts",value:cI(c)},{label:"Reaches in buddi",value:Jw(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:n.jsxs(n.Fragment,{children:[e.license??"not stated"," · ",n.jsx(yJ,{pricing:e.pricing})]})}]})})]})}function SJ({kind:e="all",onKind:t,navigate:s,market:r,loading:i,busy:a,onRetry:l,onOpen:o,onInstall:c,onUpdate:u}){const[h,f]=d.useState(""),[m,p]=d.useState("all"),g=(r==null?void 0:r.plugins)??[],v=[{value:"all",label:"All"},{value:"recommended",label:"Recommended"},...jJ.filter(y=>g.some(k=>k.category===y.value))],b=g.filter(y=>m==="recommended"&&(y.trust!=="by-buddi"||y.installed)||m!=="all"&&m!=="recommended"&&y.category!==m?!1:wJ(y,h)),j=h.trim(),x=n.jsx("div",{className:"plugins-kind",children:n.jsx(qt,{label:"Show",options:CJ,value:e,onChange:y=>t==null?void 0:t(y)})}),w=e==="plugins"?null:n.jsx(EJ,{kind:e,navigate:s});return e==="agents"?n.jsxs(le,{gap:"lg",children:[x,n.jsxs("p",{className:"plugins-quiet",children:[n.jsx(ce,{name:"globe",size:14}),"Opening this tab fetched the list from withbuddi.com. Nothing else leaves."]}),w]}):n.jsxs(le,{gap:"lg",children:[x,n.jsxs(ae,{children:[n.jsx(Sf,{grow:!0,label:"Search plugins",value:h,placeholder:"Search plugins: weather, money, calendar…",onChange:f}),n.jsx(HA,{label:"Show",options:v,value:m,onChange:p})]}),n.jsxs("p",{className:"plugins-quiet",children:[n.jsx(ce,{name:"globe",size:14}),"Opening this tab fetched the list from withbuddi.com. Nothing else leaves."," ",n.jsx("button",{type:"button",className:"plugins-link",disabled:i,onClick:l,children:"Refresh"})]}),r===null||i&&r.unavailable?n.jsx(pe,{children:"Asking withbuddi.com…"}):r.unavailable?n.jsx(V,{tone:"warning",action:n.jsx(A,{size:"sm",disabled:i,onClick:l,children:"Try again"}),children:r.unavailable}):n.jsxs(n.Fragment,{children:[r.stale?n.jsxs(V,{tone:"warning",action:n.jsx(A,{size:"sm",disabled:i,onClick:l,children:"Try again"}),children:["withbuddi.com did not answer, so this is the list as it was",r.fetchedAt?` ${Fe(r.fetchedAt)}`:" last time","."]}):null,b.length>0?n.jsx("div",{className:"plugins-grid",children:b.map(y=>n.jsx(bJ,{entry:y,busy:a,onOpen:()=>o(y),onInstall:()=>c(y),onUpdate:k=>u(y,k)},y.npm))}):n.jsx(pe,{warm:!0,title:"Nothing listed matches",children:j!==""?`No plugin on withbuddi.com mentions “${j}”.`:g.length===0?"withbuddi.com lists no plugins yet.":"Nothing on this shelf yet."})]}),w]})}const CJ=[{value:"all",label:"All"},{value:"plugins",label:"Plugins"},{value:"agents",label:"Agents"}];function EJ({kind:e,navigate:t}){const s=de(()=>$.catalogue(),[]),r=Ew(),i=c=>t==null?void 0:t(c),a=s.data;if(!a)return s.error?n.jsx(V,{tone:"warning",children:s.error}):n.jsx(pe,{children:"Asking withbuddi.com…"});if(a.unavailable)return e==="agents"?n.jsx(V,{tone:"warning",children:a.unavailable}):null;const l=a.agents.filter(c=>_i(c)==="ready"),o=e==="all"?l.slice(0,3):a.agents;return o.length===0?null:n.jsx(ue,{title:e==="all"?"Teammates":void 0,aside:n.jsx("a",{href:Ht(),onClick:c=>{c.preventDefault(),i(Ht())},children:e==="all"?`See all ${a.agents.length}`:"Open the catalogue"}),children:n.jsx("div",{className:"plugins-grid","data-testid":"browse-agents",children:o.map(c=>n.jsx(W$,{entry:c,loaded:r,onOpen:()=>i(Ht(c.name)),onAdd:()=>i(Ht(c.name)),onUpdate:()=>i(Ht(c.name))},c.name))})})}var tu={},AJ=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then},gI={},fs={};let ty;const TJ=[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];fs.getSymbolSize=function(t){if(!t)throw new Error('"version" cannot be null or undefined');if(t<1||t>40)throw new Error('"version" should be in range from 1 to 40');return t*4+17};fs.getSymbolTotalCodewords=function(t){return TJ[t]};fs.getBCHDigit=function(e){let t=0;for(;e!==0;)t++,e>>>=1;return t};fs.setToSJISFunction=function(t){if(typeof t!="function")throw new Error('"toSJISFunc" is not a valid function.');ty=t};fs.isKanjiModeEnabled=function(){return typeof ty<"u"};fs.toSJIS=function(t){return ty(t)};var Ff={};(function(e){e.L={bit:1},e.M={bit:0},e.Q={bit:3},e.H={bit:2};function t(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,i){if(e.isValid(r))return r;try{return t(r)}catch{return i}}})(Ff);function xI(){this.buffer=[],this.length=0}xI.prototype={get:function(e){const t=Math.floor(e/8);return(this.buffer[t]>>>7-e%8&1)===1},put:function(e,t){for(let s=0;s<t;s++)this.putBit((e>>>t-s-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(e){const t=Math.floor(this.length/8);this.buffer.length<=t&&this.buffer.push(0),e&&(this.buffer[t]|=128>>>this.length%8),this.length++}};var $J=xI;function nu(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)}nu.prototype.set=function(e,t,s,r){const i=e*this.size+t;this.data[i]=s,r&&(this.reservedBit[i]=!0)};nu.prototype.get=function(e,t){return this.data[e*this.size+t]};nu.prototype.xor=function(e,t,s){this.data[e*this.size+t]^=s};nu.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]};var RJ=nu,vI={};(function(e){const t=fs.getSymbolSize;e.getRowColCoords=function(r){if(r===1)return[];const i=Math.floor(r/7)+2,a=t(r),l=a===145?26:Math.ceil((a-13)/(2*i-2))*2,o=[a-7];for(let c=1;c<i-1;c++)o[c]=o[c-1]-l;return o.push(6),o.reverse()},e.getPositions=function(r){const i=[],a=e.getRowColCoords(r),l=a.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||i.push([a[o],a[c]]);return i}})(vI);var jI={};const IJ=fs.getSymbolSize,TN=7;jI.getPositions=function(t){const s=IJ(t);return[[0,0],[s-TN,0],[0,s-TN]]};var wI={};(function(e){e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const t={N1:3,N2:3,N3:40,N4:10};e.isValid=function(i){return i!=null&&i!==""&&!isNaN(i)&&i>=0&&i<=7},e.from=function(i){return e.isValid(i)?parseInt(i,10):void 0},e.getPenaltyN1=function(i){const a=i.size;let l=0,o=0,c=0,u=null,h=null;for(let f=0;f<a;f++){o=c=0,u=h=null;for(let m=0;m<a;m++){let p=i.get(f,m);p===u?o++:(o>=5&&(l+=t.N1+(o-5)),u=p,o=1),p=i.get(m,f),p===h?c++:(c>=5&&(l+=t.N1+(c-5)),h=p,c=1)}o>=5&&(l+=t.N1+(o-5)),c>=5&&(l+=t.N1+(c-5))}return l},e.getPenaltyN2=function(i){const a=i.size;let l=0;for(let o=0;o<a-1;o++)for(let c=0;c<a-1;c++){const u=i.get(o,c)+i.get(o,c+1)+i.get(o+1,c)+i.get(o+1,c+1);(u===4||u===0)&&l++}return l*t.N2},e.getPenaltyN3=function(i){const a=i.size;let l=0,o=0,c=0;for(let u=0;u<a;u++){o=c=0;for(let h=0;h<a;h++)o=o<<1&2047|i.get(u,h),h>=10&&(o===1488||o===93)&&l++,c=c<<1&2047|i.get(h,u),h>=10&&(c===1488||c===93)&&l++}return l*t.N3},e.getPenaltyN4=function(i){let a=0;const l=i.data.length;for(let c=0;c<l;c++)a+=i.data[c];return Math.abs(Math.ceil(a*100/l/5)-10)*t.N4};function s(r,i,a){switch(r){case e.Patterns.PATTERN000:return(i+a)%2===0;case e.Patterns.PATTERN001:return i%2===0;case e.Patterns.PATTERN010:return a%3===0;case e.Patterns.PATTERN011:return(i+a)%3===0;case e.Patterns.PATTERN100:return(Math.floor(i/2)+Math.floor(a/3))%2===0;case e.Patterns.PATTERN101:return i*a%2+i*a%3===0;case e.Patterns.PATTERN110:return(i*a%2+i*a%3)%2===0;case e.Patterns.PATTERN111:return(i*a%3+(i+a)%2)%2===0;default:throw new Error("bad maskPattern:"+r)}}e.applyMask=function(i,a){const l=a.size;for(let o=0;o<l;o++)for(let c=0;c<l;c++)a.isReserved(c,o)||a.xor(c,o,s(i,c,o))},e.getBestMask=function(i,a){const l=Object.keys(e.Patterns).length;let o=0,c=1/0;for(let u=0;u<l;u++){a(u),e.applyMask(u,i);const h=e.getPenaltyN1(i)+e.getPenaltyN2(i)+e.getPenaltyN3(i)+e.getPenaltyN4(i);e.applyMask(u,i),h<c&&(c=h,o=u)}return o}})(wI);var _f={};const di=Ff,Qu=[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],Xu=[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];_f.getBlocksCount=function(t,s){switch(s){case di.L:return Qu[(t-1)*4+0];case di.M:return Qu[(t-1)*4+1];case di.Q:return Qu[(t-1)*4+2];case di.H:return Qu[(t-1)*4+3];default:return}};_f.getTotalCodewordsCount=function(t,s){switch(s){case di.L:return Xu[(t-1)*4+0];case di.M:return Xu[(t-1)*4+1];case di.Q:return Xu[(t-1)*4+2];case di.H:return Xu[(t-1)*4+3];default:return}};var yI={},zf={};const Ko=new Uint8Array(512),Ch=new Uint8Array(256);(function(){let t=1;for(let s=0;s<255;s++)Ko[s]=t,Ch[t]=s,t<<=1,t&256&&(t^=285);for(let s=255;s<512;s++)Ko[s]=Ko[s-255]})();zf.log=function(t){if(t<1)throw new Error("log("+t+")");return Ch[t]};zf.exp=function(t){return Ko[t]};zf.mul=function(t,s){return t===0||s===0?0:Ko[Ch[t]+Ch[s]]};(function(e){const t=zf;e.mul=function(r,i){const a=new Uint8Array(r.length+i.length-1);for(let l=0;l<r.length;l++)for(let o=0;o<i.length;o++)a[l+o]^=t.mul(r[l],i[o]);return a},e.mod=function(r,i){let a=new Uint8Array(r);for(;a.length-i.length>=0;){const l=a[0];for(let c=0;c<i.length;c++)a[c]^=t.mul(i[c],l);let o=0;for(;o<a.length&&a[o]===0;)o++;a=a.slice(o)}return a},e.generateECPolynomial=function(r){let i=new Uint8Array([1]);for(let a=0;a<r;a++)i=e.mul(i,new Uint8Array([1,t.exp(a)]));return i}})(yI);const bI=yI;function ny(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}ny.prototype.initialize=function(t){this.degree=t,this.genPoly=bI.generateECPolynomial(this.degree)};ny.prototype.encode=function(t){if(!this.genPoly)throw new Error("Encoder not initialized");const s=new Uint8Array(t.length+this.degree);s.set(t);const r=bI.mod(s,this.genPoly),i=this.degree-r.length;if(i>0){const a=new Uint8Array(this.degree);return a.set(r,i),a}return r};var PJ=ny,kI={},zi={},sy={};sy.isValid=function(t){return!isNaN(t)&&t>=1&&t<=40};var Nr={};const NI="[0-9]+",MJ="[A-Z $%*+\\-./:]+";let Ic="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";Ic=Ic.replace(/u/g,"\\u");const DJ="(?:(?![A-Z0-9 $%*+\\-./:]|"+Ic+`)(?:.|[\r
127
+ ]))+`;Nr.KANJI=new RegExp(Ic,"g");Nr.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");Nr.BYTE=new RegExp(DJ,"g");Nr.NUMERIC=new RegExp(NI,"g");Nr.ALPHANUMERIC=new RegExp(MJ,"g");const OJ=new RegExp("^"+Ic+"$"),LJ=new RegExp("^"+NI+"$"),FJ=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");Nr.testKanji=function(t){return OJ.test(t)};Nr.testNumeric=function(t){return LJ.test(t)};Nr.testAlphanumeric=function(t){return FJ.test(t)};(function(e){const t=sy,s=Nr;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(a,l){if(!a.ccBits)throw new Error("Invalid mode: "+a);if(!t.isValid(l))throw new Error("Invalid version: "+l);return l>=1&&l<10?a.ccBits[0]:l<27?a.ccBits[1]:a.ccBits[2]},e.getBestModeForData=function(a){return s.testNumeric(a)?e.NUMERIC:s.testAlphanumeric(a)?e.ALPHANUMERIC:s.testKanji(a)?e.KANJI:e.BYTE},e.toString=function(a){if(a&&a.id)return a.id;throw new Error("Invalid mode")},e.isValid=function(a){return a&&a.bit&&a.ccBits};function r(i){if(typeof i!="string")throw new Error("Param is not a string");switch(i.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: "+i)}}e.from=function(a,l){if(e.isValid(a))return a;try{return r(a)}catch{return l}}})(zi);(function(e){const t=fs,s=_f,r=Ff,i=zi,a=sy,l=7973,o=t.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 i.getCharCountIndicator(m,p)+4}function h(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(h(m,g)<=e.getCapacity(g,p,i.MIXED))return g}e.from=function(p,g){return a.isValid(p)?parseInt(p,10):g},e.getCapacity=function(p,g,v){if(!a.isValid(p))throw new Error("Invalid QR Code version");typeof v>"u"&&(v=i.BYTE);const b=t.getSymbolTotalCodewords(p),j=s.getTotalCodewordsCount(p,g),x=(b-j)*8;if(v===i.MIXED)return x;const w=x-u(v,p);switch(v){case i.NUMERIC:return Math.floor(w/10*3);case i.ALPHANUMERIC:return Math.floor(w/11*2);case i.KANJI:return Math.floor(w/13);case i.BYTE:default:return Math.floor(w/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(!a.isValid(p)||p<7)throw new Error("Invalid QR Code version");let g=p<<12;for(;t.getBCHDigit(g)-o>=0;)g^=l<<t.getBCHDigit(g)-o;return p<<12|g}})(kI);var SI={};const Jx=fs,CI=1335,_J=21522,$N=Jx.getBCHDigit(CI);SI.getEncodedBits=function(t,s){const r=t.bit<<3|s;let i=r<<10;for(;Jx.getBCHDigit(i)-$N>=0;)i^=CI<<Jx.getBCHDigit(i)-$N;return(r<<10|i)^_J};var EI={};const zJ=zi;function Pl(e){this.mode=zJ.NUMERIC,this.data=e.toString()}Pl.getBitsLength=function(t){return 10*Math.floor(t/3)+(t%3?t%3*3+1:0)};Pl.prototype.getLength=function(){return this.data.length};Pl.prototype.getBitsLength=function(){return Pl.getBitsLength(this.data.length)};Pl.prototype.write=function(t){let s,r,i;for(s=0;s+3<=this.data.length;s+=3)r=this.data.substr(s,3),i=parseInt(r,10),t.put(i,10);const a=this.data.length-s;a>0&&(r=this.data.substr(s),i=parseInt(r,10),t.put(i,a*3+1))};var UJ=Pl;const BJ=zi,wp=["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 Ml(e){this.mode=BJ.ALPHANUMERIC,this.data=e}Ml.getBitsLength=function(t){return 11*Math.floor(t/2)+6*(t%2)};Ml.prototype.getLength=function(){return this.data.length};Ml.prototype.getBitsLength=function(){return Ml.getBitsLength(this.data.length)};Ml.prototype.write=function(t){let s;for(s=0;s+2<=this.data.length;s+=2){let r=wp.indexOf(this.data[s])*45;r+=wp.indexOf(this.data[s+1]),t.put(r,11)}this.data.length%2&&t.put(wp.indexOf(this.data[s]),6)};var WJ=Ml;const HJ=zi;function Dl(e){this.mode=HJ.BYTE,typeof e=="string"?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}Dl.getBitsLength=function(t){return t*8};Dl.prototype.getLength=function(){return this.data.length};Dl.prototype.getBitsLength=function(){return Dl.getBitsLength(this.data.length)};Dl.prototype.write=function(e){for(let t=0,s=this.data.length;t<s;t++)e.put(this.data[t],8)};var KJ=Dl;const VJ=zi,GJ=fs;function Ol(e){this.mode=VJ.KANJI,this.data=e}Ol.getBitsLength=function(t){return t*13};Ol.prototype.getLength=function(){return this.data.length};Ol.prototype.getBitsLength=function(){return Ol.getBitsLength(this.data.length)};Ol.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let s=GJ.toSJIS(this.data[t]);if(s>=33088&&s<=40956)s-=33088;else if(s>=57408&&s<=60351)s-=49472;else throw new Error("Invalid SJIS character: "+this.data[t]+`
128
+ Make sure your charset is UTF-8`);s=(s>>>8&255)*192+(s&255),e.put(s,13)}};var qJ=Ol,AI={exports:{}};(function(e){var t={single_source_shortest_paths:function(s,r,i){var a={},l={};l[r]=0;var o=t.PriorityQueue.make();o.push(r,0);for(var c,u,h,f,m,p,g,v,b;!o.empty();){c=o.pop(),u=c.value,f=c.cost,m=s[u]||{};for(h in m)m.hasOwnProperty(h)&&(p=m[h],g=f+p,v=l[h],b=typeof l[h]>"u",(b||v>g)&&(l[h]=g,o.push(h,g),a[h]=u))}if(typeof i<"u"&&typeof l[i]>"u"){var j=["Could not find a path from ",r," to ",i,"."].join("");throw new Error(j)}return a},extract_shortest_path_from_predecessor_list:function(s,r){for(var i=[],a=r;a;)i.push(a),s[a],a=s[a];return i.reverse(),i},find_path:function(s,r,i){var a=t.single_source_shortest_paths(s,r,i);return t.extract_shortest_path_from_predecessor_list(a,i)},PriorityQueue:{make:function(s){var r=t.PriorityQueue,i={},a;s=s||{};for(a in r)r.hasOwnProperty(a)&&(i[a]=r[a]);return i.queue=[],i.sorter=s.sorter||r.default_sorter,i},default_sorter:function(s,r){return s.cost-r.cost},push:function(s,r){var i={value:s,cost:r};this.queue.push(i),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};e.exports=t})(AI);var YJ=AI.exports;(function(e){const t=zi,s=UJ,r=WJ,i=KJ,a=qJ,l=Nr,o=fs,c=YJ;function u(j){return unescape(encodeURIComponent(j)).length}function h(j,x,w){const y=[];let k;for(;(k=j.exec(w))!==null;)y.push({data:k[0],index:k.index,mode:x,length:k[0].length});return y}function f(j){const x=h(l.NUMERIC,t.NUMERIC,j),w=h(l.ALPHANUMERIC,t.ALPHANUMERIC,j);let y,k;return o.isKanjiModeEnabled()?(y=h(l.BYTE,t.BYTE,j),k=h(l.KANJI,t.KANJI,j)):(y=h(l.BYTE_KANJI,t.BYTE,j),k=[]),x.concat(w,y,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 t.NUMERIC:return s.getBitsLength(j);case t.ALPHANUMERIC:return r.getBitsLength(j);case t.KANJI:return a.getBitsLength(j);case t.BYTE:return i.getBitsLength(j)}}function p(j){return j.reduce(function(x,w){const y=x.length-1>=0?x[x.length-1]:null;return y&&y.mode===w.mode?(x[x.length-1].data+=w.data,x):(x.push(w),x)},[])}function g(j){const x=[];for(let w=0;w<j.length;w++){const y=j[w];switch(y.mode){case t.NUMERIC:x.push([y,{data:y.data,mode:t.ALPHANUMERIC,length:y.length},{data:y.data,mode:t.BYTE,length:y.length}]);break;case t.ALPHANUMERIC:x.push([y,{data:y.data,mode:t.BYTE,length:y.length}]);break;case t.KANJI:x.push([y,{data:y.data,mode:t.BYTE,length:u(y.data)}]);break;case t.BYTE:x.push([{data:y.data,mode:t.BYTE,length:u(y.data)}])}}return x}function v(j,x){const w={},y={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 R=S[E],I=""+N+E;C.push(I),w[I]={node:R,lastCount:0},y[I]={};for(let L=0;L<k.length;L++){const F=k[L];w[F]&&w[F].node.mode===R.mode?(y[F][I]=m(w[F].lastCount+R.length,R.mode)-m(w[F].lastCount,R.mode),w[F].lastCount+=R.length):(w[F]&&(w[F].lastCount=R.length),y[F][I]=m(R.length,R.mode)+4+t.getCharCountIndicator(R.mode,x))}}k=C}for(let N=0;N<k.length;N++)y[k[N]].end=0;return{map:y,table:w}}function b(j,x){let w;const y=t.getBestModeForData(j);if(w=t.from(x,y),w!==t.BYTE&&w.bit<y.bit)throw new Error('"'+j+'" cannot be encoded with mode '+t.toString(w)+`.
129
+ Suggested mode is: `+t.toString(y));switch(w===t.KANJI&&!o.isKanjiModeEnabled()&&(w=t.BYTE),w){case t.NUMERIC:return new s(j);case t.ALPHANUMERIC:return new r(j);case t.KANJI:return new a(j);case t.BYTE:return new i(j)}}e.fromArray=function(x){return x.reduce(function(w,y){return typeof y=="string"?w.push(b(y,null)):y.data&&w.push(b(y.data,y.mode)),w},[])},e.fromString=function(x,w){const y=f(x,o.isKanjiModeEnabled()),k=g(y),N=v(k,w),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()))}})(EI);const Uf=fs,yp=Ff,JJ=$J,QJ=RJ,XJ=vI,ZJ=jI,Qx=wI,Xx=_f,eQ=PJ,Eh=kI,tQ=SI,nQ=zi,bp=EI;function sQ(e,t){const s=e.size,r=ZJ.getPositions(t);for(let i=0;i<r.length;i++){const a=r[i][0],l=r[i][1];for(let o=-1;o<=7;o++)if(!(a+o<=-1||s<=a+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(a+o,l+c,!0,!0):e.set(a+o,l+c,!1,!0))}}function rQ(e){const t=e.size;for(let s=8;s<t-8;s++){const r=s%2===0;e.set(s,6,r,!0),e.set(6,s,r,!0)}}function iQ(e,t){const s=XJ.getPositions(t);for(let r=0;r<s.length;r++){const i=s[r][0],a=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(i+l,a+o,!0,!0):e.set(i+l,a+o,!1,!0)}}function aQ(e,t){const s=e.size,r=Eh.getEncodedBits(t);let i,a,l;for(let o=0;o<18;o++)i=Math.floor(o/3),a=o%3+s-8-3,l=(r>>o&1)===1,e.set(i,a,l,!0),e.set(a,i,l,!0)}function kp(e,t,s){const r=e.size,i=tQ.getEncodedBits(t,s);let a,l;for(a=0;a<15;a++)l=(i>>a&1)===1,a<6?e.set(a,8,l,!0):a<8?e.set(a+1,8,l,!0):e.set(r-15+a,8,l,!0),a<8?e.set(8,r-a-1,l,!0):a<9?e.set(8,15-a-1+1,l,!0):e.set(8,15-a-1,l,!0);e.set(r-8,8,1,!0)}function lQ(e,t){const s=e.size;let r=-1,i=s-1,a=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(i,o-c)){let u=!1;l<t.length&&(u=(t[l]>>>a&1)===1),e.set(i,o-c,u),a--,a===-1&&(l++,a=7)}if(i+=r,i<0||s<=i){i-=r,r=-r;break}}}function oQ(e,t,s){const r=new JJ;s.forEach(function(c){r.put(c.mode.bit,4),r.put(c.getLength(),nQ.getCharCountIndicator(c.mode,e)),c.write(r)});const i=Uf.getSymbolTotalCodewords(e),a=Xx.getTotalCodewordsCount(e,t),l=(i-a)*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 cQ(r,e,t)}function cQ(e,t,s){const r=Uf.getSymbolTotalCodewords(t),i=Xx.getTotalCodewordsCount(t,s),a=r-i,l=Xx.getBlocksCount(t,s),o=r%l,c=l-o,u=Math.floor(r/l),h=Math.floor(a/l),f=h+1,m=u-h,p=new eQ(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?h:f;v[S]=x.slice(g,g+C),b[S]=p.encode(v[S]),g+=C,j=Math.max(j,C)}const w=new Uint8Array(r);let y=0,k,N;for(k=0;k<j;k++)for(N=0;N<l;N++)k<v[N].length&&(w[y++]=v[N][k]);for(k=0;k<m;k++)for(N=0;N<l;N++)w[y++]=b[N][k];return w}function uQ(e,t,s,r){let i;if(Array.isArray(e))i=bp.fromArray(e);else if(typeof e=="string"){let u=t;if(!u){const h=bp.rawSplit(e);u=Eh.getBestVersionForData(h,s)}i=bp.fromString(e,u||40)}else throw new Error("Invalid data");const a=Eh.getBestVersionForData(i,s);if(!a)throw new Error("The amount of data is too big to be stored in a QR Code");if(!t)t=a;else if(t<a)throw new Error(`
130
+ The chosen QR Code version cannot contain this amount of data.
131
+ Minimum version required to store current data is: `+a+`.
132
+ `);const l=oQ(t,s,i),o=Uf.getSymbolSize(t),c=new QJ(o);return sQ(c,t),rQ(c),iQ(c,t),kp(c,s,0),t>=7&&aQ(c,t),lQ(c,l),isNaN(r)&&(r=Qx.getBestMask(c,kp.bind(null,c,s))),Qx.applyMask(r,c),kp(c,s,r),{modules:c,version:t,errorCorrectionLevel:s,maskPattern:r,segments:i}}gI.create=function(t,s){if(typeof t>"u"||t==="")throw new Error("No input text");let r=yp.M,i,a;return typeof s<"u"&&(r=yp.from(s.errorCorrectionLevel,yp.M),i=Eh.from(s.version),a=Qx.from(s.maskPattern),s.toSJISFunc&&Uf.setToSJISFunction(s.toSJISFunc)),uQ(t,i,r,a)};var TI={},ry={};(function(e){function t(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(a){return[a,a]}))),r.length===6&&r.push("F","F");const i=parseInt(r.join(""),16);return{r:i>>24&255,g:i>>16&255,b:i>>8&255,a:i&255,hex:"#"+r.slice(0,6).join("")}}e.getOptions=function(r){r||(r={}),r.color||(r.color={});const i=typeof r.margin>"u"||r.margin===null||r.margin<0?4:r.margin,a=r.width&&r.width>=21?r.width:void 0,l=r.scale||4;return{width:a,scale:a?4:l,margin:i,color:{dark:t(r.color.dark||"#000000ff"),light:t(r.color.light||"#ffffffff")},type:r.type,rendererOpts:r.rendererOpts||{}}},e.getScale=function(r,i){return i.width&&i.width>=r+i.margin*2?i.width/(r+i.margin*2):i.scale},e.getImageWidth=function(r,i){const a=e.getScale(r,i);return Math.floor((r+i.margin*2)*a)},e.qrToImageData=function(r,i,a){const l=i.modules.size,o=i.modules.data,c=e.getScale(l,a),u=Math.floor((l+a.margin*2)*c),h=a.margin*c,f=[a.color.light,a.color.dark];for(let m=0;m<u;m++)for(let p=0;p<u;p++){let g=(m*u+p)*4,v=a.color.light;if(m>=h&&p>=h&&m<u-h&&p<u-h){const b=Math.floor((m-h)/c),j=Math.floor((p-h)/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}}})(ry);(function(e){const t=ry;function s(i,a,l){i.clearRect(0,0,a.width,a.height),a.style||(a.style={}),a.height=l,a.width=l,a.style.height=l+"px",a.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(a,l,o){let c=o,u=l;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),l||(u=r()),c=t.getOptions(c);const h=t.getImageWidth(a.modules.size,c),f=u.getContext("2d"),m=f.createImageData(h,h);return t.qrToImageData(m.data,a,c),s(f,u,h),f.putImageData(m,0,0),u},e.renderToDataURL=function(a,l,o){let c=o;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),c||(c={});const u=e.render(a,l,c),h=c.type||"image/png",f=c.rendererOpts||{};return u.toDataURL(h,f.quality)}})(TI);var $I={};const dQ=ry;function RN(e,t){const s=e.a/255,r=t+'="'+e.hex+'"';return s<1?r+" "+t+'-opacity="'+s.toFixed(2).slice(1)+'"':r}function Np(e,t,s){let r=e+t;return typeof s<"u"&&(r+=" "+s),r}function hQ(e,t,s){let r="",i=0,a=!1,l=0;for(let o=0;o<e.length;o++){const c=Math.floor(o%t),u=Math.floor(o/t);!c&&!a&&(a=!0),e[o]?(l++,o>0&&c>0&&e[o-1]||(r+=a?Np("M",c+s,.5+u+s):Np("m",i,0),i=0,a=!1),c+1<t&&e[o+1]||(r+=Np("h",l),l=0)):i++}return r}$I.render=function(t,s,r){const i=dQ.getOptions(s),a=t.modules.size,l=t.modules.data,o=a+i.margin*2,c=i.color.light.a?"<path "+RN(i.color.light,"fill")+' d="M0 0h'+o+"v"+o+'H0z"/>':"",u="<path "+RN(i.color.dark,"stroke")+' d="'+hQ(l,a,i.margin)+'"/>',h='viewBox="0 0 '+o+" "+o+'"',m='<svg xmlns="http://www.w3.org/2000/svg" '+(i.width?'width="'+i.width+'" height="'+i.width+'" ':"")+h+' shape-rendering="crispEdges">'+c+u+`</svg>
133
+ `;return typeof r=="function"&&r(null,m),m};const fQ=AJ,Zx=gI,RI=TI,mQ=$I;function iy(e,t,s,r,i){const a=[].slice.call(arguments,1),l=a.length,o=typeof a[l-1]=="function";if(!o&&!fQ())throw new Error("Callback required as last argument");if(o){if(l<2)throw new Error("Too few arguments provided");l===2?(i=s,s=t,t=r=void 0):l===3&&(t.getContext&&typeof i>"u"?(i=r,r=void 0):(i=r,r=s,s=t,t=void 0))}else{if(l<1)throw new Error("Too few arguments provided");return l===1?(s=t,t=r=void 0):l===2&&!t.getContext&&(r=s,s=t,t=void 0),new Promise(function(c,u){try{const h=Zx.create(s,r);c(e(h,t,r))}catch(h){u(h)}})}try{const c=Zx.create(s,r);i(null,e(c,t,r))}catch(c){i(c)}}tu.create=Zx.create;tu.toCanvas=iy.bind(null,RI.render);tu.toDataURL=iy.bind(null,RI.renderToDataURL);tu.toString=iy.bind(null,function(e,t,s){return mQ.render(e,s)});async function pQ(e){const t=await tu.toString(e,{type:"svg",margin:1,errorCorrectionLevel:"M"});return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(t)}`}const IN=10*6e4,gQ=2e3;function ay(e,t){const[s,r]=d.useState(null),[i,a]=d.useState(null),[l,o]=d.useState(!1),[c,u]=d.useState(!1),h=d.useRef(e);h.current=e;const f=d.useRef(t);f.current=t;const m=d.useCallback(async()=>{const p=await $.telegramPairing();r(p),u(!1),o(!1),a(await pQ(p.link).catch(()=>""))},[]);return d.useEffect(()=>{if(!s||l||c)return;let p=!1;const g=Math.min(Date.parse(s.expiresAt)||Date.now()+IN,Date.now()+IN),v=window.setInterval(()=>{if(Date.now()>=g){u(!0);return}h.current().then(b=>{var j;p||!b||(o(!0),(j=f.current)==null||j.call(f))}).catch(()=>{})},gQ);return()=>{p=!0,window.clearInterval(v)}},[s,l,c]),{offer:s,square:i,paired:l,stale:c,ask:m}}function ly({offer:e,square:t,children:s}){return n.jsxs("div",{className:"meet-pair",children:[t?n.jsx("img",{className:"meet-qr",src:t,alt:e.link}):null,n.jsx("a",{className:"meet-link",href:e.link,target:"_blank",rel:"noreferrer",children:e.link}),s]})}const II=new Set(["approval","question"]),Nd={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."}},xQ=new Set(["agent"]),vQ={maxUrgency:"now",muted:[]};function jQ(e,t){var i;const s=Nd[e.kind].label.toLowerCase();return e.kind!=="agent"||!e.agentId?s:`from ${((i=t.find(a=>a.id===e.agentId))==null?void 0:i.name)??e.agentId}`}function wQ({timezone:e}){var j,x,w;const t=de(()=>$.notificationSettings(),[]),s=de(()=>$.agents(),[]),r=de(()=>$.notifications(20),[],3e4),i=d.useRef(!1);d.useEffect(()=>{var y,k;i.current||!r.data||window.location.hash!==qg||(i.current=!0,(k=(y=document.getElementById("notifications-recent"))==null?void 0:y.scrollIntoView)==null||k.call(y,{block:"start"}))},[r.data]);const[a,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(!1),[f,m]=d.useState(null),p=((j=t.data)==null?void 0:j.channels)??[],g=a??((x=t.data)==null?void 0:x.settings),v=y=>{g&&(h(!1),l({...g,...y}))},b=()=>{g&&(c(!0),h(!1),m(null),$.saveNotificationSettings(g).then(()=>{h(!0),l(null),t.reload()}).catch(y=>m(y instanceof ve?y.message:String(y))).finally(()=>c(!1)))};return n.jsxs(le,{gap:"lg",children:[n.jsx(ue,{title:"Notifications",aside:"What buddi tells you when you are not looking at this page.",panel:!0,foot:n.jsx(A,{variant:"accent",disabled:o||!g,onClick:b,children:"Save"}),children:n.jsxs(le,{divided:!0,children:[n.jsx(re,{message:t.error??f}),n.jsx(ue,{title:"Where buddi reaches you",children:g?p.length===0?n.jsxs("p",{className:"ui-card-meta",children:["No channel yet, so everything waits for you here. ",n.jsx("a",{href:Pe("telegram"),children:"Set up Telegram"})," and buddi can reach you on your phone."]}):n.jsxs(le,{gap:"sm",children:[p.map(y=>{var k;return n.jsx(EQ,{channel:y,checked:(g.defaultChannel??((k=p[0])==null?void 0:k.kind))===y.kind,onPick:()=>v({defaultChannel:y.kind})},y.kind)}),p.some(y=>y.kind==="telegram")?null:n.jsxs("p",{className:"ui-card-meta",children:["Telegram is not set up. ",n.jsx("a",{href:Pe("telegram"),children:"Set up Telegram"})]})]}):n.jsx(pe,{children:"Loading…"})}),n.jsx(ue,{title:"By kind",children:g?n.jsxs(le,{gap:"sm",children:[zL.filter(y=>!xQ.has(y)).map(y=>n.jsxs("div",{className:"pref-row nt-kind",children:[n.jsxs("div",{className:"pref-text",children:[n.jsx("span",{className:"pref-label",children:Nd[y].label}),n.jsx("span",{className:"ui-field-hint",children:Nd[y].hint})]}),n.jsxs("select",{"aria-label":Nd[y].label,value:AQ(g,y,p),onChange:k=>{const N={...g.perKind};k.target.value==="default"?delete N[y]:N[y]=k.target.value,v({perKind:N})},children:[n.jsx("option",{value:"default",children:"Default"}),p.map(k=>n.jsx("option",{value:k.kind,children:k.label},k.kind)),II.has(y)?null:n.jsx("option",{value:"off",children:"Off"})]})]},y)),n.jsx("p",{className:"ui-field-hint",children:"Off keeps it in the list below and never sends it."})]}):null}),n.jsx(ue,{title:"Messages from your agents",children:g?n.jsx(yQ,{settings:g,agents:((w=s.data)==null?void 0:w.agents)??[],onChange:v}):null}),n.jsx(ue,{title:"Focus schedules",children:g?n.jsxs(le,{gap:"sm",children:[n.jsx(RQ,{schedules:g.schedules,onChange:y=>v({schedules:y})}),n.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,")."]}),n.jsx("div",{className:"nt-times",children:n.jsx(oe,{label:"End of the day",children:n.jsx("input",{type:"time",value:g.endOfDay,onChange:y=>v({endOfDay:y.target.value})})})}),n.jsx("p",{className:"ui-field-hint",children:"At the end of the day, what could wait goes out as one message."})]}):null}),u?n.jsx(V,{tone:"good",role:"status",children:"Saved."}):null]})}),n.jsx(bQ,{}),n.jsx("div",{id:"notifications-recent",className:"notifications-recent",children:n.jsxs(ue,{title:"The last twenty",panel:!0,flush:!0,children:[n.jsx(re,{message:r.error}),r.data?r.data.notifications.length===0?n.jsx(pe,{children:"Nothing yet. What buddi tells you will be listed here."}):n.jsx(rt,{children:r.data.notifications.map(y=>{var k;return n.jsx(et,{title:xc(y),sub:`${nt(y.createdAt,e)} · ${jQ(y,((k=s.data)==null?void 0:k.agents)??[])} · ${TQ(y,p)}`,side:n.jsx($Q,{row:y})},y.id)})}):n.jsx(pe,{children:"Loading…"})]})})]})}function yQ({settings:e,agents:t,onChange:s}){const r=e.perKind.agent!=="off",i=e.agents??vQ,a=o=>{const c={...e.perKind};o?delete c.agent:c.agent="off",s({perKind:c})},l=(o,c)=>s({agents:{...i,muted:c?[...new Set([...i.muted,o])]:i.muted.filter(u=>u!==o)}});return n.jsxs(le,{gap:"sm",children:[n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:r,onChange:o=>a(o.target.checked)}),n.jsx("span",{children:"Agents may message you"})]}),n.jsxs("div",{className:"pref-row nt-kind",children:[n.jsxs("div",{className:"pref-text",children:[n.jsx("span",{className:"pref-label",children:"Highest urgency"}),n.jsx("span",{className:"ui-field-hint",children:"End of the day holds every message for the end-of-day message."})]}),n.jsxs("select",{"aria-label":"Highest urgency for agents",value:i.maxUrgency,disabled:!r,onChange:o=>s({agents:{...i,maxUrgency:o.target.value==="today"?"today":"now"}}),children:[n.jsx("option",{value:"now",children:"Now"}),n.jsx("option",{value:"today",children:"End of the day"})]})]}),t.length>0?n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Muted agents",children:t.map(o=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:i.muted.includes(o.id),disabled:!r,onChange:c=>l(o.id,c.target.checked),"aria-label":`Mute @${o.handle}`}),n.jsxs("span",{children:["Mute ",o.name," (@",o.handle,")"]})]},o.id))}):null,n.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 bQ(){var u;const e=de(()=>$.tipsSettings(),[]),[t,s]=d.useState(!1),[r,i]=d.useState(null),[a,l]=d.useState(null),o=a??((u=e.data)==null?void 0:u.enabled)??!0,c=h=>{s(!0),i(null),l(h),$.saveTipsSettings(h).then(f=>l(f.enabled)).catch(f=>{l(!h),i(f instanceof ve?f.message:String(f))}).finally(()=>s(!1))};return n.jsx(ue,{title:"Tips",panel:!0,children:n.jsxs(le,{gap:"sm",children:[n.jsx(re,{message:e.error??r}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:o,disabled:t||!e.data,onChange:h=>c(h.target.checked)}),n.jsx("span",{children:"Tips on Home"})]}),n.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 kQ({timezone:e}){return n.jsx(NQ,{timezone:e,onChange:()=>{}})}function NQ({timezone:e,onChange:t}){var C,E;const s=de(()=>$.telegramBot(),[]),r=de(()=>$.telegramDevices(),[]),[i,a]=d.useState(!1),[l,o]=d.useState(""),[c,u]=d.useState(!1),[h,f]=d.useState(null),[m,p]=d.useState(null),g=d.useRef(new Set),v=ay(()=>$.telegramDevices().then(R=>R.devices.some(I=>!g.current.has(I.id))),()=>{r.reload(),t()}),b=((C=s.data)==null?void 0:C.configured)??!1,j=!b||i,x=()=>{var I;if(l.trim()===""||c)return;u(!0),f(null);const R=i&&(((I=s.data)==null?void 0:I.running)??!1);$.saveTelegramToken(l.trim()).then(L=>{o(""),a(!1),f(L.restartNeeded?{ok:!1,text:L.note??"Saved. It will be ready the next time buddi starts."}:R?{ok:!0,text:"Saved. The new bot takes over the next time buddi starts."}:{ok:!0,text:"Saved."}),s.reload(),t()}).catch(L=>f({ok:!1,text:L instanceof ve?L.message:String(L)})).finally(()=>u(!1))},w=()=>{var R;p(null),g.current=new Set((((R=r.data)==null?void 0:R.devices)??[]).map(I=>I.id)),v.ask().catch(I=>p(I instanceof ve?I.message:String(I)))},{offer:y,square:k,paired:N,stale:S}=v;return n.jsx(ue,{title:"Telegram",aside:"Talk to buddi from your phone.",panel:!0,children:n.jsxs(le,{divided:!0,children:[n.jsx(ue,{title:"The bot",foot:j?n.jsxs(n.Fragment,{children:[i?n.jsx(A,{variant:"ghost",onClick:()=>{a(!1),o("")},children:"Cancel"}):null,n.jsx(A,{variant:"accent",disabled:c||l.trim()==="",onClick:x,children:"Save token"})]}):void 0,children:n.jsxs(le,{gap:"sm",children:[n.jsx(re,{message:s.error}),!s.data&&!s.error?n.jsx(pe,{children:"Loading…"}):b&&!i?n.jsxs("div",{className:"nt-channel",children:[n.jsx("span",{className:"pref-label",children:(E=s.data)!=null&&E.username?`Bot: @${s.data.username}`:"A bot token is saved."}),n.jsx(A,{variant:"ghost",size:"sm",onClick:()=>{a(!0),f(null)},children:"Replace token"})]}):null,j?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"ui-card-meta",children:"Ask @BotFather for a bot and paste its token here."}),n.jsx(oe,{label:"Bot token",grow:!0,children:n.jsx("input",{type:"password",value:l,autoComplete:"off",spellCheck:!1,onChange:R=>o(R.target.value),onKeyDown:R=>{R.key==="Enter"&&(R.preventDefault(),x())}})})]}):null,h?n.jsx(V,{tone:h.ok?"good":"warning",role:"status",children:h.text}):null]})}),n.jsxs(ue,{title:"Your devices",children:[n.jsx(re,{message:r.error}),r.data?r.data.devices.length===0?n.jsx("p",{className:"ui-card-meta",children:"No phone is paired yet."}):n.jsx(rt,{children:r.data.devices.map(R=>n.jsx(et,{title:R.name??`Telegram user ${R.userId}`,sub:`Paired ${nt(R.pairedAt,e)} · ${R.lastSeenAt?`last spoke ${Fe(R.lastSeenAt)}`:"has not spoken yet"}`,side:n.jsx(SQ,{id:R.id,onGone:()=>{r.reload(),t()}})},R.id))}):r.error?null:n.jsx(pe,{children:"Loading…"})]}),n.jsx(ue,{title:"Pair a device",foot:b&&(!y||N)?n.jsx(A,{variant:y?void 0:"accent",onClick:w,children:"Pair a phone"}):b&&S?n.jsx(A,{variant:"accent",onClick:w,children:"New code"}):void 0,children:n.jsxs(le,{gap:"sm",children:[n.jsx(re,{message:m}),b?N?n.jsx(V,{tone:"good",role:"status",children:"Paired."}):y&&S?n.jsx("p",{className:"ui-card-meta",children:"That code has run out."}):y?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"ui-card-meta",children:"Open this on your phone, then send /start to the bot."}),n.jsx(ly,{offer:y,square:k,children:n.jsx(CQ,{text:y.link})}),n.jsxs("p",{className:"ui-field-hint",children:["The code works until ",nt(y.expiresAt,e),"."]})]}):n.jsx("p",{className:"ui-card-meta",children:"Pair another phone, or the first one if you skipped it."}):n.jsx("p",{className:"ui-card-meta",children:"Save a bot token first."})]})})]})})}function SQ({id:e,onGone:t}){const[s,r]=d.useState(!1),[i,a]=d.useState(!1),[l,o]=d.useState(null);if(!s)return n.jsx(A,{size:"sm",onClick:()=>r(!0),children:"Unpair"});const c=()=>{a(!0),o(null),$.unpairTelegramDevice(e).then(t).catch(u=>o(u instanceof ve?u.message:String(u))).finally(()=>a(!1))};return n.jsxs("span",{className:"nt-channel",children:[n.jsx("span",{className:"ui-field-hint",role:l?"alert":void 0,children:l??"It will no longer reach your agents."}),n.jsx(A,{size:"sm",variant:"ghost",disabled:i,onClick:()=>r(!1),children:"Keep"}),n.jsx(A,{size:"sm",variant:"danger",disabled:i,onClick:c,children:"Unpair"})]})}function CQ({text:e}){const[t,s]=d.useState(null),r=()=>{var i;if(!((i=navigator.clipboard)!=null&&i.writeText)){s("Select the link to copy it.");return}navigator.clipboard.writeText(e).then(()=>s("Copied."),()=>s("Select the link to copy it."))};return n.jsxs("span",{className:"nt-channel",children:[n.jsx(A,{size:"sm",onClick:r,children:"Copy"}),t?n.jsx("span",{className:"ui-field-hint",role:"status",children:t}):null]})}function EQ({channel:e,checked:t,onPick:s}){const[r,i]=d.useState(!1),[a,l]=d.useState(null),o=()=>{i(!0),l(null),$.testChannel(e.kind).then(()=>l({ok:!0,text:"Sent. Check that it arrived."})).catch(c=>l({ok:!1,text:c instanceof ve?c.message:String(c)})).finally(()=>i(!1))};return n.jsxs("div",{className:"nt-channel",children:[n.jsxs("label",{children:[n.jsx("input",{type:"radio",name:"nt-default-channel",checked:t,onChange:s}),n.jsxs("span",{className:"nt-channel-text",children:[n.jsxs("span",{className:"pref-label",children:[e.label,e.where?`, ${e.where}`:""]}),n.jsxs("span",{className:"ui-field-hint",children:["The title and a few lines of each message go to ",e.label,"."]}),a?n.jsx("span",{className:"nt-channel-sent","data-tone":a.ok?void 0:"critical",role:"status",children:a.text}):null]})]}),n.jsx(A,{size:"sm",disabled:r,onClick:o,children:"Send a test"})]})}function AQ(e,t,s){const r=e.perKind[t];return r==="off"?II.has(t)?"default":"off":r&&s.some(i=>i.kind===r)?r:"default"}function TQ(e,t){var s;return e.channel&&e.channel!=="dashboard"?((s=t.find(r=>r.kind===e.channel))==null?void 0:s.label)??e.channel:"dashboard"}function $Q({row:e}){return e.state==="failed"?n.jsxs("span",{className:"nt-state","data-tone":"critical",children:["Failed: ",e.error??"no reason given"]}):e.actedAt?n.jsx("span",{className:"nt-state",children:"Acted on"}):e.seenAt?n.jsx("span",{className:"nt-state",children:"Seen"}):e.state==="held"?n.jsx("span",{className:"nt-state",children:"Waiting"}):e.state==="stored"?n.jsx("span",{className:"nt-state",children:"Kept"}):e.state==="sent"?n.jsx("span",{className:"nt-state",children:"Sent"}):n.jsx("span",{className:"nt-state",children:"Not seen"})}const PN={mon:"Mon",tue:"Tue",wed:"Wed",thu:"Thu",fri:"Fri",sat:"Sat",sun:"Sun"},MN={mode:"do-not-disturb",days:[...Fg],from:"22:00",to:"07:00"};function RQ({schedules:e,onChange:t}){const s=(r,i)=>t(e.map((a,l)=>l===r?{...a,...i}:a));return n.jsxs(le,{gap:"sm",children:[e.length===0?n.jsx("p",{className:"ui-card-meta",children:"No schedule: a focus is on only when you switch one on."}):null,e.map((r,i)=>{const a=i+1;return n.jsxs("div",{className:"nt-schedule",role:"group","aria-label":`Schedule ${a}`,children:[n.jsxs("select",{"aria-label":`Schedule ${a} mode`,value:r.mode,onChange:l=>s(i,{mode:l.target.value}),children:[n.jsx("option",{value:"do-not-disturb",children:"Do not disturb"}),n.jsx("option",{value:"urgent-only",children:"Urgent only"})]}),n.jsx("span",{className:"nt-days",children:Fg.map(l=>{const o=r.days.includes(l);return n.jsx("button",{type:"button",className:"nt-day","aria-pressed":o,"aria-label":`Schedule ${a} ${PN[l]}`,onClick:()=>s(i,{days:o?r.days.filter(c=>c!==l):Fg.filter(c=>c===l||r.days.includes(c))}),children:PN[l]},l)})}),n.jsx(oe,{label:"From",children:n.jsx("input",{type:"time","aria-label":`Schedule ${a} from`,value:r.from,onChange:l=>s(i,{from:l.target.value})})}),n.jsx(oe,{label:"To",children:n.jsx("input",{type:"time","aria-label":`Schedule ${a} to`,value:r.to,onChange:l=>s(i,{to:l.target.value})})}),n.jsx(A,{size:"sm",variant:"ghost","aria-label":`Remove schedule ${a}`,onClick:()=>t(e.filter((l,o)=>o!==i)),children:"Remove"})]},i)}),n.jsx("div",{className:"nt-schedule-add",children:n.jsx(A,{size:"sm",onClick:()=>t([...e,{...MN,days:[...MN.days]}]),children:"Add a schedule"})})]})}const IQ={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 PQ(e){const t=J4.map(r=>({id:r.id,route:Pe(r.id),label:r.label,icon:IQ[r.id],group:r.group})),s=[...e].sort((r,i)=>r.title.localeCompare(i.title,void 0,{sensitivity:"base"})||r.plugin.localeCompare(i.plugin)||r.id.localeCompare(i.id)).map(r=>({id:hA(r.plugin,r.id),route:vr(r.plugin,r.id),label:r.title,icon:c$(r.icon),group:"plugins"}));return[...t,...s]}function PI(e){return Y4.map(t=>({id:t.id,label:t.label,entries:e.filter(s=>s.group===t.id)})).filter(t=>t.entries.length>0)}function MI(e,t,s){return t?`${e}, ${t} open`:s?`${e}, ${s}`:void 0}function MQ({entries:e,active:t,counts:s={},dots:r={},navigate:i}){var u;const a=d.useRef(null),l=PI(e),o=e.some(h=>h.id===t)?t:(u=e[0])==null?void 0:u.id,c=h=>{var g;const f=[...((g=a.current)==null?void 0:g.querySelectorAll("a.settings-nav-link"))??[]],m=f.indexOf(document.activeElement);if(m===-1)return;const p=v=>{var b;h.preventDefault(),(b=f[Math.max(0,Math.min(f.length-1,v))])==null||b.focus()};if(h.key==="ArrowDown")p(m+1);else if(h.key==="ArrowUp")p(m-1);else if(h.key==="Home")p(0);else if(h.key==="End")p(f.length-1);else if(h.key==="Enter"||h.key===" "){h.preventDefault();const v=f[m].getAttribute("href");v&&i(v)}};return n.jsx("nav",{className:"settings-nav","aria-label":"Settings sections",ref:a,onKeyDown:c,children:l.map(h=>n.jsxs("div",{className:"settings-nav-group",role:"group","aria-labelledby":`settings-nav-${h.id}`,children:[n.jsx("div",{className:"settings-nav-label",id:`settings-nav-${h.id}`,children:h.label}),h.entries.map(f=>{const m=f.id===t,p=s[f.id],g=r[f.id];return n.jsxs("a",{className:"settings-nav-link",href:f.route,"data-active":m?"true":void 0,"aria-current":m?"page":void 0,"aria-label":MI(f.label,p,g),tabIndex:f.id===o?0:-1,onClick:v=>{v.preventDefault(),i(f.route)},children:[n.jsx(ce,{name:f.icon,className:"settings-nav-icon"}),n.jsx("span",{className:"settings-nav-text",children:f.label}),p?n.jsx("span",{className:"ui-badge settings-nav-count","aria-hidden":"true",children:p>99?"99+":p}):g?n.jsx("span",{className:"ui-badge settings-nav-dot","data-kind":"dot","data-testid":"settings-nav-dot","aria-hidden":"true"}):null]},f.id)})]},h.id))})}function DQ({entries:e,active:t,counts:s={},dots:r={},navigate:i}){const a=PI(e),l=e.find(o=>o.id===t)??e[0];return n.jsx("nav",{className:"settings-menu","aria-label":"Settings sections",children:n.jsxs(Hc,{modal:!1,children:[n.jsx(Kc,{asChild:!0,children:n.jsxs("button",{type:"button",className:"settings-menu-trigger","aria-label":`Settings section: ${(l==null?void 0:l.label)??""}`,children:[l?n.jsx(ce,{name:l.icon,className:"settings-nav-icon"}):null,n.jsx("span",{className:"settings-nav-text",children:l==null?void 0:l.label}),n.jsx(ce,{name:"chevron-down",className:"settings-menu-chevron"})]})}),n.jsx(Gl,{children:n.jsx(Vc,{className:"ui-menu settings-menu-list",align:"start",sideOffset:6,children:n.jsx(t4,{value:t,onValueChange:o=>{const c=e.find(u=>u.id===o);c&&i(c.route)},children:a.map((o,c)=>n.jsxs(lA,{children:[c>0?n.jsx(Dr,{className:"ui-menu-sep"}):null,n.jsx(ma,{className:"ui-menu-label",children:o.label}),o.entries.map(u=>{const h=s[u.id],f=r[u.id];return n.jsxs(n4,{value:u.id,className:"ui-menu-item settings-menu-item","data-active":u.id===t?"true":void 0,"aria-label":MI(u.label,h,f),children:[n.jsxs("span",{className:"settings-menu-entry",children:[n.jsx(ce,{name:u.icon,className:"settings-nav-icon"}),n.jsx("span",{className:"settings-nav-text",children:u.label})]}),h?n.jsx("span",{className:"ui-badge settings-nav-count","aria-hidden":"true",children:h>99?"99+":h}):f?n.jsx("span",{className:"ui-badge settings-nav-dot","data-kind":"dot","aria-hidden":"true"}):null]},u.id)})]},o.id))})})})]})})}function OQ({hash:e,timezone:t,navigate:s,agents:r,pluginPages:i}){var w,y,k;const a=Q4(e),l=tT(i!==void 0),o=i??l,c=dA(e),u=c?o.find(c.plugin,c.page):void 0,h=u?null:F4(e,o.settings);d.useEffect(()=>{h&&s(h,!0)},[h,s]);const f=Ns(Vj),m=PQ(o.settings),g={proposals:((y=(w=de(()=>Promise.resolve().then(()=>$.proposals()),[],3e4).data)==null?void 0:w.open)==null?void 0:y.length)??0},v=de(()=>$.version(),[]),b=de(()=>Promise.resolve().then(()=>$.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=C$);const x={entries:m,active:a,counts:g,dots:j,navigate:N=>s(N)};return n.jsxs("div",{className:"settings",children:[f?null:n.jsx(MQ,{...x}),n.jsx("div",{className:"settings-body",children:n.jsxs("div",{className:"ui-page",children:[a==="secrets"?n.jsx(Al,{before:n.jsx(ah,{inline:!0,items:[{label:"Settings",href:ln,onClick:()=>s(ln)}]}),title:"Keys and secrets",lede:JR,actions:n.jsx(dt,{variant:"accent",size:"sm",href:Ek,onClick:N=>{N.preventDefault(),s(Ek)},children:"Add a secret"})}):a==="plugins"||a==="connections"?n.jsx(Al,{before:n.jsx(ah,{inline:!0,items:[{label:"Settings",href:ln,onClick:()=>s(ln)}]}),title:a==="plugins"?"Plugins":"Connections",lede:a==="plugins"?KY:uR}):n.jsxs("header",{className:"ui-page-head",children:[n.jsx("h2",{className:"ui-page-title",children:"Settings"}),n.jsx("p",{className:"ui-page-lede",children:"How this installation runs, and where it reaches."})]}),f?n.jsx(DQ,{...x}):null,u?n.jsx(WH,{page:u,params:Pj(e),navigate:s,timezone:t,siblings:o.all.filter(N=>N.plugin===u.plugin)}):null,a==="you"?n.jsx(kY,{embedded:!0}):null,a==="appearance"?n.jsx(LQ,{railPages:o.rail}):null,a==="notifications"?n.jsx(wQ,{timezone:t}):null,a==="telegram"?n.jsx(kQ,{timezone:t}):null,a==="memory"?n.jsx(H$,{embedded:!0,agents:r,timezone:t}):null,a==="proposals"?n.jsx(LY,{embedded:!0,plugin:V4(e)}):null,a==="accounts"?n.jsx(hq,{embedded:!0,account:_4(e)}):null,a==="computer"?n.jsx(F5,{embedded:!0,timezone:t}):null,a==="secrets"?n.jsx(Xq,{embedded:!0,timezone:t,secret:U4(e),adding:B4(e),navigate:s}):null,a==="connections"?n.jsx(m7,{embedded:!0,timezone:t,connection:z4(e)}):null,a==="lock"?n.jsx(vY,{navigate:s}):null,a==="api"?n.jsx(bY,{timezone:t}):null,a==="watchers"?n.jsx(oY,{timezone:t,embedded:!0}):null,a==="backup"?n.jsx(iq,{}):null,a==="plugins"?n.jsx(ZY,{railPages:o.rail,settingsPages:o.settings,navigate:s,hash:e}):null,a==="system"?n.jsx(zQ,{timezone:t}):null]})})]})}function LQ({railPages:e}){const[t,s]=P$();return n.jsx(ue,{title:"Appearance",aside:"Kept in this browser only. Another browser keeps its own.",panel:!0,children:n.jsxs(le,{divided:!0,gap:"lg",children:[n.jsx(Sp,{label:"Theme",hint:"System follows your Mac.",children:n.jsx(qt,{label:"Theme",options:[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}],value:t.theme,onChange:r=>s({theme:r})})}),n.jsx(Sp,{label:"Background",hint:"Blue carries the first-run colours through the app. Sand is quieter.",children:n.jsx(qt,{label:"Background",options:[{value:"blue",label:"Blue"},{value:"sand",label:"Sand"}],value:t.ground,onChange:r=>s({ground:r})})}),n.jsx(Sp,{label:"Page width",hint:"How far pages stretch on a wide screen.",children:n.jsx(qt,{label:"Page width",options:[{value:"narrow",label:"Narrow"},{value:"wide",label:"Wide"},{value:"full",label:"Full"}],value:t.width,onChange:r=>s({width:r})})}),n.jsx(_Q,{pages:e}),n.jsx(FQ,{})]})})}function FQ(){var c,u,h;const e=de(()=>$.overview(),[]),[t,s]=d.useState(null),r=((c=e.data)==null?void 0:c.glances)??[],i=((u=e.data)==null?void 0:u.home)??[],a=((h=e.data)==null?void 0:h.dismissed)??{};if(r.length===0&&i.length===0)return null;const l=(f,m)=>{s(f),$.setGlanceHidden(f,!m).then(()=>e.reload()).finally(()=>s(null))},o=(f,m)=>{s(`block:${f}`),$.homeDismiss(`block:${f}`,m?null:"hidden").then(()=>e.reload()).finally(()=>s(null))};return n.jsxs(n.Fragment,{children:[r.length>0?n.jsxs("div",{className:"pref-row ui-section",children:[n.jsxs("div",{className:"pref-text",children:[n.jsx("span",{className:"pref-label",children:"Home glances"}),n.jsx("span",{className:"ui-field-hint",children:"The lines beside the date on Home, at most three. Kept for every browser."})]}),n.jsx(le,{gap:"sm",children:r.map(f=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:!f.hidden,disabled:t===f.id,onChange:m=>l(f.id,m.target.checked)}),n.jsx("span",{children:f.title})]},f.id))})]}):null,i.length>0?n.jsxs("div",{className:"pref-row ui-section",children:[n.jsxs("div",{className:"pref-text",children:[n.jsx("span",{className:"pref-label",children:"Home sections"}),n.jsx("span",{className:"ui-field-hint",children:"What the plugins put on Home. Kept for every browser."})]}),n.jsx(le,{gap:"sm",children:i.map(f=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:a[`block:${f.id}`]!=="hidden",disabled:t===`block:${f.id}`,onChange:m=>o(f.id,m.target.checked)}),n.jsx("span",{children:f.title})]},f.id))})]}):null]})}function _Q({pages:e}){const t=E$(),[s,r]=d.useState(null);if(e.length===0)return null;const i=(a,l)=>{r(null),b9(a,!l).catch(o=>r(o instanceof Error?o.message:String(o)))};return n.jsxs("div",{className:"pref-row ui-section",children:[n.jsxs("div",{className:"pref-text",children:[n.jsx("span",{className:"pref-label",children:"In the rail"}),n.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."})]}),n.jsxs(le,{gap:"sm",children:[n.jsx(re,{message:s}),e.map(a=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:!t.has(Rc(a)),onChange:l=>i(a,l.target.checked)}),n.jsx("span",{children:a.title})]},Rc(a)))]})]})}function Sp({label:e,hint:t,children:s}){return n.jsxs("div",{className:"pref-row ui-section",children:[n.jsxs("div",{className:"pref-text",children:[n.jsx("span",{className:"pref-label",children:e}),n.jsx("span",{className:"ui-field-hint",children:t})]}),s]})}function zQ({timezone:e}){const t=de(()=>$.overview(),[],15e3),s=de(()=>$.session(),[]),r=de(()=>$.providerAccounts(),[]),i=t.data;return n.jsxs(le,{gap:"lg",children:[n.jsx(re,{message:t.error}),n.jsx(ZQ,{}),i?n.jsx(ue,{title:"The queue",panel:!0,actions:n.jsx(A,{size:"sm",variant:i.paused?"accent":void 0,onClick:()=>{$.setPaused(!i.paused).then(()=>t.reload())},children:i.paused?"Resume the queue":"Pause the queue"}),children:n.jsxs("p",{className:"ui-card-meta",children:[i.paused?"Paused. Nothing is being claimed until you resume.":"Running. Jobs are claimed as they come due."," ",i.paused?n.jsx(we,{tone:"warning",children:"paused"}):n.jsx(we,{tone:"good",children:"running"})]})}):null,n.jsxs(ue,{title:"This host",panel:!0,children:[n.jsx(Gt,{items:[{label:"Time zone",value:e},{label:"Server time",value:i?nt(i.now,e):"…"},{label:"Bound to",value:s.data?`${s.data.host}:${s.data.port}`:"…"},{label:"Credential vault",value:r.data?HQ(r.data.vault.kind):"…"}]}),r.data&&(r.data.vault.locked||r.data.vault.kind==="none")?n.jsx(V,{tone:"warning",children:r.data.vault.advice||"Run buddi init on the host to configure secure credential storage."}):null]}),n.jsx(WQ,{}),n.jsx(ZH,{}),n.jsx(UQ,{}),n.jsx(ue,{title:"Mail and sources",panel:!0,children:i?i.mail.length===0?n.jsx(pe,{children:"No sources are installed."}):n.jsx(Gt,{items:i.mail.map(a=>({key:a.sourceId,label:n.jsx("span",{className:"mono",children:a.sourceId}),value:a.lastError?n.jsx("span",{className:"critical",children:a.lastError}):n.jsxs("span",{children:["polled ",Fe(a.lastRunAt)]})}))}):n.jsx(pe,{children:"Loading…"})})]})}function UQ(){var p;const e=de(()=>$.tailscale(),[]),[t,s]=d.useState(null),[r,i]=d.useState(!1),[a,l]=d.useState(null),[o,c]=d.useState(!1),u=e.data,h=t??((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=>{i(!0),l(null),c(!1),$.setTailscale({enabled:g,login:h.trim()}).then(()=>{c(!0)}).catch(v=>l(v instanceof ve?v.message:String(v))).finally(()=>{i(!1),e.reload()})};return n.jsx(ue,{title:"Sign in through Tailscale",panel:!0,foot:n.jsx(A,{variant:"accent",disabled:r||!u||f,onClick:()=>m((u==null?void 0:u.enabled)??!1),children:"Save"}),children:n.jsx(le,{divided:!0,children:n.jsx(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsx(re,{message:e.error??a}),n.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?n.jsxs(n.Fragment,{children:[n.jsx(V,{tone:"warning",children:"Change this from the computer buddi runs on."}),n.jsx("p",{className:"ui-card-meta",children:u!=null&&u.enabled?`On, for ${h}`:"Off"})]}):null,n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:(u==null?void 0:u.enabled)??!1,disabled:r||!u||f,onChange:g=>m(g.target.checked)}),n.jsx("span",{children:"Let this Tailscale login sign in"})]}),n.jsx(oe,{label:"Tailscale login",children:n.jsx("input",{type:"text",value:h,placeholder:"you@example.com",disabled:r||!u||f,onChange:g=>s(g.target.value)})}),n.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:"}),n.jsxs("div",{className:"tailscale-command",children:[n.jsx("code",{className:"mono",children:(u==null?void 0:u.serveCommand)??"tailscale serve"}),n.jsx(A,{size:"sm",disabled:r||!u,onClick:()=>{BQ((u==null?void 0:u.serveCommand)??"")},children:"Copy"})]}),n.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?n.jsx(V,{tone:"good",role:"status",children:"Saved."}):null]})})})})}async function BQ(e){var t;try{await((t=navigator.clipboard)==null?void 0:t.writeText(e))}catch{}}function WQ(){var u;const e=de(()=>$.service(),[],1e4),[t,s]=d.useState(null),[r,i]=d.useState(!1),[a,l]=d.useState(null),o=(u=e.data)!=null&&u.supervised?e.data.status:void 0;if(!o)return null;const c=h=>{i(!0),l(null),gf({kind:h},()=>$.serviceAction(h)).then(()=>{s(null)}).catch(f=>{l(f.message),e.reload()}).finally(()=>{i(!1)})};return n.jsx(ue,{title:"Service",panel:!0,children:n.jsxs(le,{divided:!0,children:[n.jsx(ue,{children:n.jsx(Gt,{items:[{label:"Database",value:n.jsx(DN,{state:o.database,pid:o.databasePid})},{label:"Gateway",value:n.jsx(DN,{state:o.gateway,pid:o.gatewayPid})},{label:"Supervisor",value:n.jsxs("span",{className:"mono",children:["pid ",o.supervisorPid]})}]})}),n.jsx(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsx(re,{message:a}),t?n.jsx(V,{tone:"warning",role:"alert",children:t==="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."}):n.jsx("p",{className:"ui-card-meta",children:"Stopping the gateway ends this dashboard until buddi is run again."}),n.jsx(ae,{align:"end",children:t?n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",disabled:r,onClick:()=>{s(null),l(null)},children:"Cancel"}),n.jsx(A,{variant:t==="stop"?"danger":"accent",disabled:r,onClick:()=>{c(t)},children:t==="stop"?"Stop it":"Restart it"})]}):n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",onClick:()=>{s("stop")},children:"Stop gateway"}),n.jsx(A,{variant:"accent",onClick:()=>{s("restart")},children:"Restart gateway"})]})})]})})]})})}function DN({state:e,pid:t}){return n.jsxs("span",{children:[n.jsx(we,{tone:e==="running"?"good":e==="stopped"?"warning":e==="failed"?"critical":"muted",children:e})," ",t===null?n.jsx("span",{className:"ui-card-meta",children:"no process"}):n.jsxs("span",{className:"mono",children:["pid ",t]})]})}function HQ(e){return e==="keychain"?"macOS Keychain":e==="file"?"Encrypted file vault":e==="none"?"None":e}const KQ=2e3,Ah={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."},VQ=new Set(["done","failed","rolled-back"]),GQ="The check asks the npm registry for the newest version and sends nothing else.",qQ="This takes a backup, installs the new version and restarts buddi. This page waits for it and comes back by itself.",YQ="A checkout upgrades with git pull, then buddi upgrade in a terminal.",JQ=15*6e4;function QQ(e){const t=e.step==="starting"?"while starting":`at ${e.step??"an unknown step"}`;return`The upgrade to ${e.to} failed ${t}: ${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 ON(e,t=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)&&t-r<JQ?s:null}function XQ(e,t){const[s,r]=d.useState(void 0),[i,a]=d.useState(null),l=d.useRef(t);return l.current=t,d.useEffect(()=>{if(!e){r(void 0);return}let o=!1,c=!1;const u=()=>{o||c||$.upgradeJob(e).then(f=>{var m;o||(r(f),a(null),wA({step:Ah[f.phase]??f.detail??f.phase}),(VQ.has(f.phase)||f.finishedAt)&&(o=!0,f.phase==="failed"&&(El(),(m=l.current)==null||m.call(l,f))))}).catch(f=>{o||(f instanceof ve&&f.status!==0&&f.status<500?(o=!0,El(),a(f.message)):c=!0)})};u();const h=window.setInterval(u,KQ);return()=>{o=!0,window.clearInterval(h)}},[e]),{job:s,error:i}}function ZQ(){const e=de(()=>$.version(),[]),[t,s]=d.useState(null),[r,i]=d.useState(!1),[a,l]=d.useState(!1),[o,c]=d.useState(null),[u,h]=d.useState(null),f=d.useCallback(j=>{s(null),h(j)},[]),m=XQ(t,f),p=e.data,g=()=>{l(!0),c(null),$.checkVersion().catch(j=>c(j instanceof ve?j.message:String(j))).finally(()=>{l(!1),e.reload()})},v=j=>{l(!0),c(null),$.setVersionCheck(j).catch(x=>c(x instanceof ve?x.message:String(x))).finally(()=>{l(!1),e.reload()})},b=()=>{l(!0),c(null),h(null),gf({kind:"upgrade",line:p!=null&&p.latest?`Upgrading to ${p.latest}…`:"Upgrading…",step:Ah.starting,patienceMs:jA},()=>$.startUpgrade(p==null?void 0:p.latest)).then(j=>{var x;i(!1),s(((x=j==null?void 0:j.job)==null?void 0:x.id)??null)}).catch(j=>c(j instanceof ve?j.message:String(j))).finally(()=>l(!1))};return p!=null&&p.checkout?n.jsx(ue,{title:"Version",panel:!0,children:n.jsxs(le,{divided:!0,children:[n.jsx(ue,{children:n.jsx(Gt,{items:[{label:"Running",value:n.jsx("span",{className:"mono",children:p.current})}]})}),n.jsx(ue,{children:n.jsx("p",{className:"ui-card-meta",children:YQ})})]})}):n.jsx(ue,{title:"Version",panel:!0,children:n.jsxs(le,{divided:!0,children:[n.jsx(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsx(re,{message:e.error??o}),n.jsx(Gt,{items:[{label:"Running",value:p?n.jsx("span",{className:"mono",children:p.current}):"…"},{label:"Newest",value:p?p.updateAvailable&&p.latest?n.jsxs("span",{children:["A newer buddi is available: ",n.jsx("span",{className:"mono",children:p.latest})]}):p.checkedAt?n.jsxs("span",{children:["This is the latest, as of ",Fe(p.checkedAt),"."]}):n.jsx("span",{children:"Not checked yet."}):"…"}]}),p!=null&&p.error?n.jsxs(V,{tone:"warning",children:["The last check did not get an answer: ",p.error]}):null,n.jsx(ae,{align:"end",children:n.jsx(A,{disabled:a,onClick:g,children:"Check now"})})]})}),n.jsx(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:(p==null?void 0:p.checkEnabled)??!1,disabled:a||!p,onChange:j=>v(j.target.checked)}),n.jsx("span",{children:"Check once a day"})]}),n.jsx("p",{className:"ui-card-meta",children:GQ})]})}),p!=null&&p.updateAvailable&&p.latest&&p.latestNotes?n.jsx(ue,{title:`What changes in ${p.latest}`,children:n.jsx(Ws,{text:p.latestNotes})}):null,n.jsx(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsx(eX,{...m,job:m.job??u??void 0}),!m.job&&!u&&!m.error&&p&&ON(p.history)?n.jsx(V,{tone:"critical",role:"alert",children:QQ(ON(p.history))}):null,r?n.jsx(V,{tone:"warning",role:"alert",children:qQ}):null,n.jsx(ae,{align:"end",children:r?n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",disabled:a,onClick:()=>i(!1),children:"Cancel"}),n.jsxs(A,{variant:"accent",disabled:a,onClick:b,children:["Upgrade to ",p==null?void 0:p.latest]})]}):n.jsx(A,{variant:"accent",disabled:a||t!==null||!(p!=null&&p.updateAvailable),onClick:()=>i(!0),children:p!=null&&p.updateAvailable&&p.latest?`Upgrade to ${p.latest}`:"Upgrade"})})]})}),p&&p.history.length>0?n.jsx(ue,{title:"Upgrades so far",children:n.jsx(Gt,{items:p.history.slice().reverse().map(j=>({key:j.startedAt,label:n.jsxs("span",{className:"mono",children:[j.from," → ",j.to]}),value:n.jsx(tX,{attempt:j})}))})}):null]})})}function eX({job:e,error:t}){return t?n.jsx(re,{message:t}):e?e.phase==="failed"?n.jsxs(V,{tone:"critical",role:"alert",children:[Ah.failed," ",e.error??""," buddi is still running on the version it had."]}):n.jsx(V,{tone:e.phase==="done"?"good":void 0,role:"status",children:Ah[e.phase]??e.detail??e.phase}):null}function tX({attempt:e}){return n.jsxs("span",{children:[n.jsx(we,{tone:e.outcome==="done"?"good":e.outcome==="failed"?"critical":"warning",children:e.outcome})," ",Fe(e.startedAt),e.step?`, at ${e.step}`:"",e.error?`: ${e.error}`:"",e.backup?n.jsxs("span",{className:"ui-card-meta",children:[" Backup: ",n.jsx("span",{className:"mono",children:e.backup})]}):null]})}const Th=["hello","brain","takeOn","reach","assistant","handover"],DI={hello:"you",brain:"model",takeOn:"take-on",reach:"reach",assistant:"agent",handover:"hello"};function OI(e){return((e==null?void 0:e.accounts)??[]).filter(t=>t.enabled&&t.configured&&t.removalPending!==!0)}function nX(e){var a,l,o;const t=OI(e.accounts),s=e.assistant?(((a=e.accounts)==null?void 0:a.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 i=t.find(c=>c.id===r);if(i)return{accountId:i.id,label:i.label,model:(s==null?void 0:s.model)??i.defaultModel}}function LI(e){var a,l,o,c,u;const t=nX(e),s=e.onboarding&&!e.onboarding.needs.agent?e.assistant:void 0,r=((a=e.onboarding)==null?void 0:a.details)??{},i=((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}:{},...t?{brain:t}:{},...Array.isArray(r.takeOn)?{takeOn:r.takeOn}:s?{takeOn:[]}:{},...r.reach?{reach:r.reach}:i.includes("reach")||s?{reach:{}}:{},...i.includes("browser")||((u=r.reach)==null?void 0:u.browser)===!0?{browser:e.browser??"other"}:{},...s?{assistant:s}:{}}}function FI(e,t){return t==="hello"?typeof e.name=="string"&&e.name!==""&&typeof e.clock=="string"&&e.clock!=="":t==="brain"?e.brain!==void 0:t==="takeOn"?e.takeOn!==void 0:t==="reach"?e.reach!==void 0:t==="assistant"?e.assistant!==void 0:!1}function Sd(e){return Th.find(t=>!FI(e,t))??"handover"}function sX(e){const t=Th.indexOf(e);return t>0?Th[t-1]:null}function LN(e,t,s){return s===t?"now":FI(e,s)?"done":"todo"}function rX(e,t){return{...e}}const ev="buddi.firstRun.restore";function tv(e){try{e===null?window.sessionStorage.removeItem(ev):window.sessionStorage.setItem(ev,e)}catch{}}function _I(){try{return window.sessionStorage.getItem(ev)}catch{return null}}function iX(e){const t=LI(e),s=Sd(t);return{answers:t,open:s,stay:s!=="handover"}}function aX(e){return e.trim().startsWith("sk-ant-")?"anthropic":"openai"}function lX(e){const t=e.normalize("NFKD").replace(/[̀-ͯ]/g,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^[^a-z]+/,"").replace(/-+$/,"").slice(0,20).replace(/-+$/,"");return t===""?"assistant":t}const oX=6e4,cX=5*6e4,zI=1500,uX=2e3,dX="(max-width: 720px)";function eo(){const e=d.useRef(null);return d.useEffect(()=>{let t=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},i=()=>{const l=e.current;l&&r(l)&&l.focus()},a=()=>{i(),s=window.setTimeout(i,0)};return typeof window.requestAnimationFrame=="function"?t=window.requestAnimationFrame(a):a(),window.addEventListener("focus",i),()=>{t&&window.cancelAnimationFrame(t),window.clearTimeout(s),window.removeEventListener("focus",i)}},[]),e}const oy=d.createContext({busy:0,report:()=>{}});function hX({children:e}){const[t,s]=d.useState(0),r=d.useCallback(a=>s(l=>Math.max(0,l+(a?1:-1))),[]),i=d.useMemo(()=>({busy:t,report:r}),[t,r]);return n.jsx(oy.Provider,{value:i,children:e})}function ft({children:e}){const{busy:t}=d.useContext(oy);return n.jsxs("div",{className:"wiz-say",children:[n.jsx(Qc,{state:t>0?"working":"idle",size:"sm",className:"wiz-say-face"}),n.jsx("div",{className:"wiz-bubble",children:e})]})}function it({children:e}){return n.jsx(n.Fragment,{children:e})}function Js({line:e}){const{report:t}=d.useContext(oy);return d.useEffect(()=>(t(!0),()=>t(!1)),[t]),n.jsxs("div",{className:"wiz-busy",role:"status","aria-live":"polite",children:[n.jsxs("span",{className:"wiz-pulse","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]}),e]})}const cy=d.createContext(null);function tn({children:e,actions:t}){const s=d.useContext(cy),r=t==null?null:s?Ul.createPortal(t,s):n.jsx("div",{className:"wiz-dock-inline",children:t});return n.jsxs(n.Fragment,{children:[e?n.jsx("div",{className:"wiz-ask",children:e}):null,r]})}function as({onClick:e,disabled:t}){return n.jsxs(A,{variant:"ghost",size:"lg",onClick:e,disabled:t,children:[n.jsx(ce,{name:"chevron-left"}),z.back]})}function to({children:e,onClick:t,disabled:s}){return n.jsxs(A,{variant:"accent",size:"lg",onClick:t,disabled:s,children:[e,n.jsx(ce,{name:"arrow"})]})}function fX({navigate:e,timezone:t}){var xn,Yn,Z,Re,Xe,jt,G;const s=Ns(dX),[r,i]=d.useState(void 0);d.useEffect(()=>{$.session().then(he=>i(he.platform)).catch(()=>{})},[]);const[a,l]=d.useState({}),[o,c]=d.useState(null),[u,h]=d.useState(void 0),[f,m]=d.useState(void 0),[p,g]=d.useState([]),[v,b]=d.useState(null),[j,x]=d.useState(null),[w,y]=d.useState(!1),[k,N]=d.useState(null),[S,C]=d.useState(null),[E,R]=d.useState(null),[I,L]=d.useState(null),[F,T]=d.useState(()=>_I()?"running":"idle"),[M,P]=d.useState({}),[D,O]=d.useState([]),[H,B]=d.useState(0),Y=d.useRef(void 0),[W,q]=d.useState(null),_=d.useCallback(()=>{Promise.resolve().then(()=>$.takeOnProgress()).then(he=>{he&&Array.isArray(he.plugins)&&q(he)}).catch(()=>{})},[]);d.useEffect(()=>{if(!(W!=null&&W.running))return;const he=window.setInterval(_,uX);return()=>window.clearInterval(he)},[W==null?void 0:W.running,_]);const X=d.useMemo(()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone||t}catch{return t}},[t]),Q=d.useRef(e);Q.current=e;const ee=d.useCallback(async(he=!0,We=!1)=>{var Jn,Ln,Qs,so,Ui,Fn,Bi,Sr,ti;const[ze,sn,As,Cn,Ts,$s]=await Promise.all([$.onboarding().catch(()=>{}),$.owner().catch(()=>{}),$.providerAccounts().catch(()=>{}),Ve.agents().catch(()=>{}),$.browser().catch(()=>{}),$.providers().catch(()=>{})]);h(As);const Se=(Ln=(Jn=$s==null?void 0:$s.providers.find(Ut=>Ut.kind==="anthropic"))==null?void 0:Jn.defaultModel)==null?void 0:Ln.trim();m(Se||void 0),g((sn==null?void 0:sn.zones)??[]),N(((Qs=ze==null?void 0:ze.details)==null?void 0:Qs.conversationId)??null);const Ee=(Cn==null?void 0:Cn.agents.find(Ut=>Ut.id===Cn.defaultAgentId))??(Cn==null?void 0:Cn.agents[0]);Ee&&b(Ee),C(ze&&!ze.needs.agent&&Ee?{id:Ee.id,name:Ee.name,avatar:((so=Ee.avatar)==null?void 0:so.kind)==="emoji"?Ee.avatar.value:"",description:Ee.description,...Ee.picture?{picture:Ee.picture}:{}}:null),Array.isArray((Ui=ze==null?void 0:ze.details)==null?void 0:Ui.takeOn)&&_();const Ke={onboarding:ze,owner:sn,accounts:As,browser:(Fn=Ts==null?void 0:Ts.browser)==null?void 0:Fn.engine,...Ee?{assistant:{id:Ee.id,name:Ee.name,avatar:((Bi=Ee.avatar)==null?void 0:Bi.kind)==="emoji"?Ee.avatar.value:""}}:{}};if(We){const Ut=iX(Ke);if(l(Ut.answers),c(Ut.open),!Ut.stay){const Xs=(Sr=ze==null?void 0:ze.details)==null?void 0:Sr.conversationId;Q.current(Xs&&Ee?st(Ee.id,Xs):dn,!0)}return}if(he&&(ze==null?void 0:ze.state)==="done"){const Ut=(ti=ze.details)==null?void 0:ti.conversationId;Q.current(Ut&&Ee?st(Ee.id,Ut):dn,!0);return}if(!he)return;const me=LI(Ke);l(me),c(Ut=>Ut??Sd(me))},[]);d.useEffect(()=>{ee()},[ee]);const fe=(he,We={})=>{Promise.resolve().then(()=>$.onboardingStep(DI[he],We)).catch(()=>{})},Le=he=>Sd(he)==="brain"&&M.brain?{...he,brain:M.brain}:he,Ie=(he,We)=>{const ze=Le(We);ze.brain&&(Y.current=ze.brain),x(null),O([]),l(ze),he==="brain"&&ze.brain?fe(he,{accountId:ze.brain.accountId}):he==="reach"?fe(he,ze.reach?{reach:ze.reach}:{}):he!=="takeOn"&&fe(he),c(Sd(ze))},_e=(he,We)=>{x(null),l(We),We.brain&&(Y.current=We.brain),he==="brain"&&We.brain&&fe(he,{accountId:We.brain.accountId})},U=he=>{x(null),l(We=>rX(We)),c(he)},ie=()=>{if(!o)return;const he=sX(o==="handover"?"handover":o);he&&U(he)},J=()=>{const he=a.brain??Y.current,We=((W==null?void 0:W.plugins)??[]).filter(ze=>ze.state==="ready").map(ze=>ze.title);x(null),P({}),O([]),l({}),c("hello"),B(ze=>ze+1),(async()=>{var Se;const[ze,sn,As]=await Promise.all([Promise.resolve().then(()=>$.providerAccounts()).catch(()=>{}),Promise.resolve().then(()=>$.telegram()).catch(()=>{}),Promise.resolve().then(()=>$.browser()).catch(()=>{})]),Cn=OI(ze),Ts=he&&Cn.some(Ee=>Ee.id===he.accountId)?he:void 0;ze&&h(ze),P(Ts?{brain:Ts}:{});const $s=[...new Set(Cn.map(Ee=>Ee.label)),...sn!=null&&sn.paired?[z.startOver.telegram]:[],...((Se=As==null?void 0:As.browser)==null?void 0:Se.engine)==="chromium"?[z.startOver.browser]:[],...We];O($s.length>0?[z.startOver.said($s.join(", "))]:[])})()},ye=()=>{y(!0),$.skipOnboarding().then(()=>e(dn)).catch(he=>x(he instanceof ve?he.message:String(he))).finally(()=>y(!1))},ge=de(()=>$.version().catch(()=>({current:""})),[]),$e=d.useRef(null);d.useEffect(()=>{$e.current&&($e.current.scrollTop=0)},[o]);const De=F==="running",Je=Object.keys(a).length===0,Ue={answers:a,accounts:u,claudeModel:f,zones:p,browserZone:X,assistantAgent:v,met:k,onMet:N,existing:S,progress:W,onProgress:_,navigate:e,onSettled:he=>o&&Ie(o,he),onKept:he=>o&&_e(o,he),onBack:ie,onTrouble:x,onReload:()=>void ee(!1),onPickAnotherBrain:()=>U("brain"),onSpoken:L},be=(a.takeOn??[]).map(he=>{var We;return((We=zo.find(ze=>ze.id===he))==null?void 0:We.title)??he}),Be=(W==null?void 0:W.plugins)??[],at=Be.filter(he=>he.state==="ready").length,He=Be.length===0?null:W!=null&&W.running?z.takeOn.installing(at,Be.length):at===Be.length?z.takeOn.installed:null,kt=[(xn=a.reach)!=null&&xn.phone?z.reach.done.phone:null,(Yn=a.reach)!=null&&Yn.mailbox?z.reach.done.mailbox:null,(Z=a.reach)!=null&&Z.app||(Re=a.reach)!=null&&Re.browser?z.reach.done.app:null].filter(he=>he!==null),Yt={hello:{answer:z.hello.answer(a.name??""),sub:a.clock??null},brain:{answer:z.brain.answer(((Xe=a.brain)==null?void 0:Xe.label)??"")},takeOn:{answer:z.takeOn.answer(be),sub:He},reach:{answer:z.reach.answer(kt)},assistant:{answer:((jt=a.assistant)==null?void 0:jt.name)??""}},ne=Th.filter(he=>he!=="handover"),ke=o===null||o==="handover"?ne.length:ne.indexOf(o),Qe=Math.min(ke,ne.length-1),ct=I?null:n.jsxs("div",{className:"wiz-map-out",children:[n.jsx("button",{type:"button",className:"wiz-link",disabled:w,onClick:ye,children:z.later}),o==="hello"&&Je&&F==="idle"?n.jsx("button",{type:"button",className:"wiz-link",onClick:()=>T("form"),children:z.restore.offer}):!De&&o!==null&&!(o==="hello"&&Je)?n.jsx("button",{type:"button",className:"wiz-link",disabled:w,onClick:J,children:z.startOver.link}):null]}),Nt=r===void 0||r==="darwin"?z.tagline:z.taglineElsewhere,ut=o&&o!=="handover"?n.jsx("span",{className:"wiz-count",children:z.count(ke+1)}):n.jsx("span",{className:"wiz-count"});return n.jsx(cy.Provider,{value:E,children:n.jsx(hX,{children:n.jsxs(VA,{className:"wiz-ground",children:[n.jsx("div",{className:"wiz",ref:$e,"data-phone":s?"true":void 0,"data-testid":"meet",children:n.jsxs("div",{className:"wiz-frame",children:[s?n.jsxs("div",{className:"wiz-strip",children:[n.jsx(Nc,{size:"sm"}),n.jsx("span",{className:"wiz-dots","aria-label":o&&o!=="handover"?z.count(ke+1):void 0,children:ne.map(he=>n.jsx("i",{"data-state":LN(a,o,he)},he))}),n.jsx("span",{className:"wiz-strip-name",children:o&&o!=="handover"?z.strip(ke+1,z.chapters[ke]??""):z.handover.starterLabel})]}):n.jsxs("nav",{className:"wiz-map","aria-label":"Chapters",children:[n.jsxs("div",{className:"wiz-head",children:[n.jsx(Nc,{size:"lg"}),n.jsxs("div",{children:[n.jsx("div",{className:"wiz-head-name",children:"buddi"}),n.jsx("div",{className:"wiz-head-line",children:Nt}),(G=ge.data)!=null&&G.current?n.jsxs("div",{className:"wiz-head-version mono",children:["buddi ",ge.data.current]}):null]})]}),ne.map((he,We)=>{const ze=De?he==="hello"?"now":"todo":LN(a,o,he),sn=Yt[he];return n.jsxs("div",{className:"wiz-ch","data-state":ze,"aria-current":ze==="now"?"step":void 0,children:[n.jsx("span",{className:"wiz-num","data-state":ze,children:ze==="done"?n.jsx(ce,{name:"check",size:12}):We+1}),n.jsxs("span",{className:"wiz-ch-label",children:[ze==="done"?sn.answer:z.chapters[We],ze==="done"&&sn.sub?n.jsx("span",{className:"wiz-ch-sub",children:sn.sub}):null]}),ze==="done"&&!De?n.jsx("button",{type:"button",className:"wiz-link",onClick:()=>U(he),children:z.change}):null]},he)}),n.jsx("div",{className:"wiz-map-spacer"}),n.jsx("div",{className:"wiz-map-note",children:z.mapNotes[Qe]}),ct]}),n.jsx("div",{className:"wiz-stage",role:"main",children:n.jsxs("div",{className:"wiz-column","data-width":o==="hello"?"narrow":o==="brain"?"mid":"wide",children:[n.jsxs(s3,{dock:n.jsxs(n.Fragment,{children:[ut,n.jsx("div",{className:"wiz-dock-actions",ref:R})]}),children:[De?n.jsx(BX,{onDone:he=>{T("idle"),O([...he?[z.restore.welcome(he)]:[],z.restore.keys]),ee(!0,!0)},onFailed:he=>{T("idle"),x(he)}}):o==="hello"?n.jsx(mX,{...Ue}):o==="brain"?n.jsx(gX,{...Ue}):o==="takeOn"?n.jsx(IX,{...Ue}):o==="reach"?n.jsx(PX,{...Ue}):o==="assistant"?n.jsx(FX,{...Ue}):o==="handover"?n.jsx(_X,{...Ue}):n.jsx(Js,{}),D.length>0||j?n.jsxs(it,{children:[D.map(he=>n.jsx(ft,{children:he},he)),j?n.jsx(ft,{children:j}):null]}):null]},`${H}-${o??""}-${De?"r":""}`),s?n.jsx("div",{className:"wiz-phone-out",children:ct}):null]})})]})}),F==="form"?n.jsx(UX,{onCancel:()=>T("idle"),onStarted:()=>T("running"),onTrouble:x}):null]})})})}function no({children:e}){return n.jsx("h1",{className:"wiz-title",children:e})}function FN(e){try{return zt(new Date,e)}catch{return""}}function mX({answers:e,zones:t,browserZone:s,onSettled:r,onTrouble:i}){const a=eo(),[l,o]=d.useState(e.name??""),[c,u]=d.useState(e.clock??s),[h,f]=d.useState(!1),[m,p]=d.useState(!1),g=()=>{const v=l.trim();v===""||m||(p(!0),$.setOwner({preferredName:v,timezone:c}).then(()=>r({...e,name:v,clock:c})).catch(b=>i(b instanceof ve?b.message:String(b))).finally(()=>p(!1)))};return n.jsxs(n.Fragment,{children:[n.jsx(no,{children:z.hello.title}),n.jsx(it,{children:z.hello.opening.map(v=>n.jsx(ft,{children:v},v))}),n.jsxs(tn,{actions:n.jsx(to,{onClick:g,disabled:m||l.trim()==="",children:z.hello.submit}),children:[n.jsxs("div",{className:"wiz-pair",children:[n.jsx(oe,{label:z.name.label,children:n.jsx("input",{ref:a,placeholder:z.name.placeholder,maxLength:80,value:l,onChange:v=>o(v.target.value),onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),g())}})}),h?n.jsx(oe,{label:z.clock.label,hint:z.clock.hint(FN(c)),children:n.jsx("select",{value:c,onChange:v=>u(v.target.value),children:(t.includes(c)?t:[c,...t]).map(v=>n.jsx("option",{value:v,children:v},v))})}):n.jsx(oe,{label:z.clock.label,hint:z.clock.hint(FN(c)),action:n.jsx(A,{size:"lg",onClick:()=>f(!0),children:z.clock.change}),children:n.jsx("input",{value:c,readOnly:!0})})]}),n.jsx("div",{className:"wiz-foot",children:z.hello.foot})]})]})}const pX={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 gX(e){const{accounts:t,answers:s,onSettled:r,onKept:i,onReload:a,onBack:l}=e,[o,c]=d.useState(null),[u,h]=d.useState("key"),[f,m]=d.useState(null),[p,g]=d.useState(!1),[v,b]=d.useState(null),[j,x]=d.useState(null),[w,y]=d.useState(null),k=(t==null?void 0:t.anthropicOAuthEnabled)===!0,N=(t==null?void 0:t.codexEnabled)===!0,S=t==null?void 0:t.gemini,[C,E]=d.useState(null);d.useEffect(()=>{let H=!1;const B=()=>{Promise.resolve().then(()=>$.ollama()).then(W=>{!H&&W&&b(W)}).catch(()=>{}),Promise.resolve().then(()=>$.mlxh()).then(W=>{!H&&W&&x(W)}).catch(()=>{H||x({running:!1,baseUrl:"",manager:!1,models:[]})})};B();const Y=window.setInterval(B,4e3);return()=>{H=!0,window.clearInterval(Y)}},[]);const R=async H=>{if(s.assistant??e.existing)try{await $.bindBrain({accountId:H.accountId,model:H.model})}catch(B){return B instanceof ve?B.message:String(B)}return a(),i({...s,brain:H}),C==null||C.close(),E(null),c(null),y(null),null},I=async(H,B,Y)=>{g(!0),m(null);try{const W=await $.saveProviderAccount(H);let q=await $.testProviderAccount(W.id),_=H.defaultModel,X=!1;if(q.state!=="connected"&&Y&&Y!==_&&TR(q)){const ee=(await $.providerAccounts()).accounts.find(fe=>fe.id===W.id);ee&&(await $.saveProviderAccount({id:ee.id,revision:ee.revision,label:ee.label,kind:ee.kind,auth:ee.auth,baseUrl:ee.baseUrl,defaultModel:Y,enabled:ee.enabled}),q=await $.testProviderAccount(W.id),q.state==="connected"&&(_=Y,X=!0))}if(q.state!=="connected"){try{const ee=(await $.providerAccounts()).accounts.find(fe=>fe.id===W.id);ee&&await $.removeProviderAccount(W.id,ee.revision)}catch{}return m(q.message),q}const Q=await R({accountId:W.id,label:B,model:_,...X?{freeTier:X}:{}});return Q&&m(Q),q}catch(W){return m(W instanceof ve?W.message:String(W)),null}finally{g(!1)}},L=async H=>{g(!0),m(null);try{const B=await $.saveProviderAccount(H);let Y;try{Y=await $.testProviderAccount(B.id)}finally{try{const W=(await $.providerAccounts()).accounts.find(q=>q.id===B.id);W&&await $.removeProviderAccount(B.id,W.revision)}catch{}}return Y.state!=="connected"&&m(Y.message),Y}catch(B){return m(B instanceof ve?B.message:String(B)),null}finally{g(!1)}},F=(H,B,Y)=>{if(H.length<=1){I(B(H[0]??""),Y);return}y({models:H,make:B,label:Y})},T=H=>{if(H===o)return;C==null||C.close(),E((H==="free"||H==="chatgpt")&&typeof window.open=="function"?window.open("","_blank"):null),m(null),y(null),h("key"),c(H)},M=()=>{C==null||C.close(),E(null),y(null),m(null),c(null)},P=BI(v,j),D=["free",...k?["claude"]:[],...N?["chatgpt"]:[],"key","local"];let O=null;return w?O=n.jsxs(n.Fragment,{children:[n.jsx(it,{children:n.jsx(ft,{children:z.brain.model.ask})}),p?n.jsx(Js,{line:z.brain.checking.service}):f?n.jsx(it,{children:n.jsx(ft,{children:f})}):null,n.jsx(xX,{busy:p,models:w.models,onBack:M,onUse:H=>void I(w.make(H),w.label)})]}):o==="key"?O=n.jsxs(n.Fragment,{children:[n.jsx(qt,{label:z.brain.keyKinds.label,value:u,onChange:H=>{m(null),h(H)},options:[{value:"key",label:z.brain.keyKinds.key},...S?[{value:"gemini",label:z.brain.keyKinds.gemini}]:[],{value:"service",label:z.brain.keyKinds.service}]}),u==="gemini"&&S?n.jsx(jX,{busy:p,problem:f,preset:S,onBack:M,onUse:I},"gemini"):u==="service"?n.jsx(yX,{busy:p,problem:f,address:(v==null?void 0:v.cloudBaseUrl)??"",onBack:M,onOffer:F,onTrial:L,onUse:I},"service"):n.jsx(vX,{busy:p,problem:f,onBack:M,onUse:I},"key")]}):o==="local"?O=n.jsx(wX,{busy:p,problem:f,probe:v,mlxh:j,onBack:M,onOffer:F,onUse:I}):o==="free"?O=n.jsx(kX,{...e,busy:p,consent:C,onBack:M,onConnected:R}):o==="chatgpt"?O=n.jsx(CX,{...e,busy:p,consent:C,onBack:M,onConnected:R}):o==="claude"&&(O=n.jsx(AX,{...e,busy:p,problem:f,onBack:M,onConnected:R})),n.jsxs(n.Fragment,{children:[n.jsx(no,{children:z.brain.title}),n.jsx(it,{children:n.jsx(ft,{children:z.brain.ask})}),n.jsx("div",{className:"wiz-grid",role:"group","aria-label":z.brain.ask,children:D.map(H=>{const B=pX[H],Y=z.brain.cards[H];return n.jsxs("button",{type:"button",className:"wiz-opt","aria-pressed":o===H,"data-wide":B.wide?"true":void 0,onClick:()=>T(H),children:[n.jsx("span",{className:"wiz-glyph","data-tone":B.tone,"aria-hidden":"true",children:n.jsx(ce,{name:B.icon})}),n.jsxs("span",{children:[n.jsx("span",{className:"wiz-opt-title",children:Y.title}),n.jsx("span",{className:"wiz-opt-line",children:H==="local"?P:Y.line}),"pill"in Y?n.jsx(we,{tone:"good",children:Y.pill}):null]})]},H)})}),O,O===null&&s.brain?n.jsxs(it,{children:[n.jsx(ft,{children:s.brain.freeTier?z.brain.worksOnFlash(s.brain.model):z.brain.works(s.brain.model)}),n.jsx(NX,{...e})]}):null,O===null?n.jsx(tn,{actions:n.jsxs(n.Fragment,{children:[n.jsx(as,{onClick:l}),n.jsx(to,{onClick:()=>s.brain&&r(s),disabled:!s.brain,children:z.brain.submit})]})}):null]})}function xX({busy:e,models:t,onBack:s,onUse:r}){const[i,a]=d.useState(t[0]??"");return n.jsx(tn,{actions:n.jsxs(n.Fragment,{children:[n.jsx(as,{onClick:s,disabled:e}),n.jsx(A,{variant:"accent",size:"lg",disabled:e||i==="",onClick:()=>r(i),children:z.brain.model.submit})]}),children:n.jsx(oe,{label:z.brain.model.label,grow:!0,children:n.jsx("select",{value:i,onChange:l=>a(l.target.value),children:t.map(l=>n.jsx("option",{value:l,children:l},l))})})})}function UI({models:e,picked:t,disabled:s,onPick:r}){return n.jsx(oe,{label:z.brain.model.label,grow:!0,children:n.jsx("select",{value:t,disabled:s,onChange:i=>r(i.target.value),children:e.map(i=>n.jsx("option",{value:i,children:i},i))})})}function vX({busy:e,problem:t,onBack:s,onUse:r}){const i=eo(),[a,l]=d.useState(""),[o,c]=d.useState(null),[u,h]=d.useState(!1),[f,m]=d.useState([]),[p,g]=d.useState(""),[v,b]=d.useState(!1),j=e||u,x=!v&&t!==null&&f.length>0,w=o??aX(a),y=()=>{const k=a.trim();k===""||j||(h(!0),b(!1),(async()=>{var E;let N=w==="anthropic"?"claude-sonnet-5":"gpt-5",S=f;if(x&&p!=="")N=p;else try{const R=await $.probeModels({kind:w,auth:"api-key",secret:k});N=((E=R.models.find(I=>I.isDefault))==null?void 0:E.id)??N,S=R.models.map(I=>I.id)}catch{S=[]}h(!1);const C=await r({label:w==="anthropic"?z.brain.key.anthropic:z.brain.key.openai,kind:w,auth:"api-key",baseUrl:"",defaultModel:N,enabled:!0,secret:k},w==="anthropic"?z.brain.key.anthropic:z.brain.key.openai);if(!(!C||C.state==="connected")){if(xj(C)){b(!0),m([]);return}m(S.includes(N)||S.length===0?S:[N,...S]),g(N)}})())};return n.jsxs(n.Fragment,{children:[j?n.jsx(it,{children:n.jsx(Js,{line:z.brain.checking.key})}):v?n.jsx(it,{children:n.jsx(ft,{children:z.brain.key.refused})}):t?n.jsx(it,{children:n.jsx(ft,{children:t})}):null,n.jsxs(tn,{actions:n.jsxs(n.Fragment,{children:[n.jsx(as,{onClick:s,disabled:j}),n.jsx(A,{variant:"accent",size:"lg",disabled:j||a.trim()==="",onClick:y,children:x?z.brain.model.retry:z.brain.key.submit})]}),children:[n.jsx(oe,{label:z.brain.key.field,grow:!0,children:n.jsx("input",{ref:i,type:"password",autoComplete:"off",spellCheck:!1,placeholder:z.brain.key.placeholder,value:a,onChange:k=>{l(k.target.value),m([])},onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),y())}})}),x?n.jsx(UI,{models:f,picked:p,disabled:j,onPick:g}):null,n.jsxs("button",{type:"button",className:"wiz-link",onClick:()=>c(w==="anthropic"?"openai":"anthropic"),children:[w==="anthropic"?z.brain.key.anthropic:z.brain.key.openai," · ",z.brain.key.which]})]})]})}function jX({busy:e,problem:t,preset:s,onBack:r,onUse:i}){const a=eo(),[l,o]=d.useState(""),[c,u]=d.useState(!1),[h,f]=d.useState([]),[m,p]=d.useState(""),g=e||c,v=t!==null&&h.length>0,b=()=>{const j=l.trim();j===""||g||(u(!0),(async()=>{let x=SR,w;if(v&&m!=="")x=m;else try{const k=(await $.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,secret:j})).models.map(N=>N.id);x=CR(k)??x,w=AR(x)?ER(k):void 0,f(dq(k)),p(w??x)}catch{}u(!1),await i({label:z.brain.gemini.label,kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,defaultModel:x,enabled:!0,secret:j},z.brain.gemini.label,w)})())};return n.jsxs(n.Fragment,{children:[g?n.jsx(it,{children:n.jsx(Js,{line:z.brain.checking.gemini})}):t?n.jsx(it,{children:n.jsx(ft,{children:t})}):null,n.jsxs(tn,{actions:n.jsxs(n.Fragment,{children:[n.jsx(as,{onClick:r,disabled:g}),n.jsx(A,{variant:"accent",size:"lg",disabled:g||l.trim()==="",onClick:b,children:z.brain.gemini.submit})]}),children:[n.jsx(oe,{label:z.brain.gemini.field,grow:!0,children:n.jsx("input",{ref:a,type:"password",autoComplete:"off",spellCheck:!1,placeholder:z.brain.gemini.placeholder,value:l,onChange:j=>o(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),b())}})}),v?n.jsx(oe,{label:z.brain.model.label,grow:!0,children:n.jsx("select",{value:m,disabled:g,onChange:j=>p(j.target.value),children:h.map(j=>n.jsx("option",{value:j,children:j},j))})}):null,n.jsx("a",{className:"wiz-link",href:s.keyUrl,target:"_blank",rel:"noreferrer",children:z.brain.gemini.get})]})]})}function BI(e,t){return e===null||t===null?z.brain.local.looking:!e.running&&!t.running?z.brain.local.missing:z.brain.local.found({...e.running?{ollama:e.models.length}:{},...t.running?{mlxh:t.models.length}:{}})}function wX({busy:e,problem:t,probe:s,mlxh:r,onBack:i,onOffer:a,onUse:l}){const o=(s==null?void 0:s.models)??[],c=Lx(r),u=()=>{!(r!=null&&r.running)||!c||l({label:z.brain.mlxh.label,kind:"openai-compatible",auth:"none",baseUrl:r.baseUrl,defaultModel:c,enabled:!0},z.brain.mlxh.label)},h=s!==null&&r!==null&&!s.running&&!r.running,f=()=>{s&&a(o,m=>({label:z.brain.ollama.label,kind:"openai-compatible",auth:"none",baseUrl:s.baseUrl,defaultModel:m,enabled:!0}),z.brain.ollama.label)};return n.jsxs(n.Fragment,{children:[e?n.jsx(it,{children:n.jsx(Js,{line:z.brain.checking.ollama})}):t?n.jsx(it,{children:n.jsx(ft,{children:t})}):null,n.jsx(tn,{actions:n.jsxs(n.Fragment,{children:[n.jsx(as,{onClick:i,disabled:e}),s!=null&&s.running?n.jsx(A,{variant:r!=null&&r.running?void 0:"accent",size:"lg",disabled:e||o.length===0,onClick:f,children:z.brain.ollama.connect}):null,r!=null&&r.running?n.jsx(A,{variant:"accent",size:"lg",disabled:e||!c,onClick:u,children:z.brain.mlxh.connect}):null,h&&s?n.jsx(dt,{variant:"accent",size:"lg",href:s.downloadUrl,target:"_blank",rel:"noreferrer",children:z.brain.ollama.download}):null]}),children:n.jsxs("span",{className:"wiz-foot",children:[BI(s,r),r!=null&&r.running&&!c?` ${z.brain.mlxh.noBrain}`:"",h&&(r!=null&&r.baseUrl)?` ${tR(r.baseUrl)}`:""]})})]})}function yX({busy:e,problem:t,address:s,onBack:r,onOffer:i,onTrial:a,onUse:l}){const o=eo(),[c,u]=d.useState(s),[h,f]=d.useState(""),[m,p]=d.useState(!1),[g,v]=d.useState([]),[b,j]=d.useState(""),[x,w]=d.useState(!1),y=e||m,k=!x&&t!==null&&g.length>0,N=()=>{c.trim()===""||y||(p(!0),w(!1),(async()=>{var M;const S=h.trim()?"api-key":"none",C=P=>({label:z.brain.service.label,kind:"openai-compatible",auth:S,baseUrl:c.trim(),defaultModel:P,enabled:!0,...h.trim()?{secret:h.trim()}:{}}),E=(P,D,O)=>{if(!(!P||P.state==="connected")){if(xj(P)){w(!0),v([]);return}v(D),j(O)}};if(S==="api-key"&&k&&b!==""){p(!1),E(await l(C(b),z.brain.service.label),g,b);return}let R=[],I;try{const P=await $.probeModels({kind:"openai-compatible",auth:S,baseUrl:c.trim(),...h.trim()?{secret:h.trim()}:{}});R=P.models.map(D=>D.id),I=(M=P.models.find(D=>D.isDefault))==null?void 0:M.id}catch{}p(!1);const L=I?[I]:R;if(S==="none"){i(L,C,z.brain.service.label);return}const F=L[0]??"";if(L.length<=1){E(await l(C(F),z.brain.service.label),R,F);return}const T=await a(C(F));(T==null?void 0:T.state)==="connected"?i(L,C,z.brain.service.label):E(T,R,F)})())};return n.jsxs(n.Fragment,{children:[y?n.jsx(it,{children:n.jsx(Js,{line:z.brain.checking.service})}):x?n.jsx(it,{children:n.jsx(ft,{children:z.brain.key.refused})}):t?n.jsx(it,{children:n.jsx(ft,{children:t})}):null,n.jsxs(tn,{actions:n.jsxs(n.Fragment,{children:[n.jsx(as,{onClick:r,disabled:y}),n.jsx(A,{variant:"accent",size:"lg",disabled:y||c.trim()==="",onClick:N,children:k?z.brain.model.retry:z.brain.service.submit})]}),children:[n.jsx(oe,{label:z.brain.service.address,grow:!0,children:n.jsx("input",{ref:o,value:c,placeholder:z.brain.service.addressPlaceholder,onChange:S=>{u(S.target.value),v([])}})}),n.jsx(oe,{label:z.brain.service.key,children:n.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,value:h,onChange:S=>{f(S.target.value),v([])}})}),k?n.jsx(UI,{models:g,picked:b,disabled:y,onPick:j}):null]})]})}const bX=2e3;function kX({busy:e,consent:t,onBack:s,onConnected:r,accounts:i}){const[a,l]=d.useState(!0),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(0),p=d.useRef(-1),g=d.useRef(null),v=z.brain.cloud.label;d.useEffect(()=>{if(p.current===f)return;p.current=f,l(!0),c(null);const j=f===0?t:g.current;(async()=>{try{const x=((i==null?void 0:i.accounts)??[]).find(N=>N.auth==="device-key"),w=x?{id:x.id}:await $.saveProviderAccount({label:v,kind:"openai-compatible",auth:"device-key",baseUrl:"",defaultModel:md,enabled:!0}),y=(await $.providerAccounts()).accounts.find(N=>N.id===w.id),k=await $.ollamaConnect(y.id,y.revision);h({id:y.id,attemptId:k.attemptId,url:k.verificationUrl}),j&&(j.location.href=k.verificationUrl)}catch(x){j==null||j.close(),c(x instanceof ve?x.message:String(x))}finally{l(!1)}})()},[f]),d.useEffect(()=>{if(!u)return;let j=!1,x=!1;const w=async()=>{if(!(j||x)){x=!0;try{const k=await $.ollamaPoll(u.id,u.attemptId);if(j||k.state==="waiting")return;if(j=!0,h(null),k.state==="failed"){c(k.message);return}l(!0),c(await b(u.id)),l(!1)}catch{}finally{x=!1}}},y=window.setInterval(()=>void w(),bX);return()=>{j=!0,window.clearInterval(y)}},[u]);const b=async j=>{try{const x=(await $.accountModels(j).catch(()=>({models:[]}))).models.map(N=>N.id),w=x.length===0||x.includes(md)?md:x[0],y=(await $.providerAccounts()).accounts.find(N=>N.id===j);y&&y.defaultModel!==w&&await $.saveProviderAccount({id:y.id,revision:y.revision,label:y.label,kind:y.kind,auth:y.auth,baseUrl:y.baseUrl,defaultModel:w,enabled:y.enabled});const k=await $.testProviderAccount(j);return k.state!=="connected"?k.message:await r({accountId:j,label:v,model:w})}catch(x){return x instanceof ve?x.message:String(x)}};return n.jsxs(n.Fragment,{children:[a||e?n.jsx(it,{children:n.jsx(Js,{line:z.brain.checking.cloud})}):o?n.jsx(it,{children:n.jsx(ft,{children:o})}):u?n.jsx(it,{children:n.jsx(ft,{children:z.brain.cloud.waiting})}):null,n.jsx(tn,{actions:n.jsxs(n.Fragment,{children:[n.jsx(as,{onClick:s,disabled:a||e}),u?n.jsx(dt,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",children:z.brain.cloud.open}):o?n.jsx(A,{variant:"accent",size:"lg",disabled:a||e,onClick:()=>{g.current=typeof window.open=="function"?window.open("","_blank"):null,m(j=>j+1)},children:z.brain.cloud.again}):null]})})]})}function NX({answers:e,accounts:t,onKept:s,onTrouble:r}){var p;const i=e.brain,a=i?((t==null?void 0:t.accounts)??[]).find(g=>g.id===i.accountId):void 0,[l,o]=d.useState([]),[c,u]=d.useState(!1),h=Ow(a),f=(a==null?void 0:a.auth)==="device-key"||(a==null?void 0:a.kind)==="codex"||h||!!a&&$R(a,(p=t==null?void 0:t.gemini)==null?void 0:p.baseUrl);if(d.useEffect(()=>{if(!f||!a)return;let g=!1;return $.accountModels(a.id).then(v=>{const b=h?v.models.filter(j=>!eR({id:j.id,...j.image?{kind:"image"}:{}})):v.models;g||o(b.map(j=>j.id))}).catch(()=>{}),()=>{g=!0}},[f,a==null?void 0:a.id]),!f||!a||!i||l.length<2)return null;const m=g=>{g===i.model||c||(u(!0),r(null),(async()=>{try{await $.saveProviderAccount({id:a.id,revision:a.revision,label:a.label,kind:a.kind,auth:a.auth,baseUrl:a.baseUrl,defaultModel:g,enabled:a.enabled}),e.assistant&&await $.bindBrain({accountId:a.id,model:g}),s({...e,brain:{accountId:i.accountId,label:i.label,model:g}})}catch(v){r(v instanceof ve?v.message:String(v))}finally{u(!1)}})())};return n.jsx(ft,{children:n.jsx(oe,{label:z.brain.model.change,children:n.jsx("select",{value:i.model,disabled:c,onChange:g=>m(g.target.value),children:(l.includes(i.model)?l:[i.model,...l]).map(g=>n.jsx("option",{value:g,children:g},g))})})})}const _N="gpt-5.5",SX=2e3;function CX({busy:e,consent:t,onBack:s,onConnected:r,accounts:i}){const[a,l]=d.useState(!0),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(0),p=d.useRef(-1),g=d.useRef(null),v=d.useRef(null),b=z.brain.chatgpt.label;d.useEffect(()=>()=>{const w=v.current;v.current=null,w&&$.codexAccountAction(w.id,"cancel-login",w.revision).catch(()=>{})},[]),d.useEffect(()=>{if(p.current===f)return;p.current=f,l(!0),c(null);const w=f===0?t:g.current;(async()=>{try{const y=((i==null?void 0:i.accounts)??[]).find(C=>C.kind==="codex"),k=y?{id:y.id}:await $.saveProviderAccount({label:b,kind:"codex",auth:"chatgpt",baseUrl:"",defaultModel:_N,enabled:!0}),N=(await $.providerAccounts()).accounts.find(C=>C.id===k.id),S=await $.codexAccountAction(N.id,"login",N.revision);if(!(S!=null&&S.verificationUrl)||!S.userCode)throw new Error((S==null?void 0:S.message)??z.brain.chatgpt.failed);v.current={id:N.id,revision:N.revision},h({id:N.id,revision:N.revision,url:S.verificationUrl,code:S.userCode}),w&&(w.location.href=S.verificationUrl)}catch(y){w==null||w.close(),c(y instanceof ve||y instanceof Error?y.message:String(y))}finally{l(!1)}})()},[f]),d.useEffect(()=>{if(!u)return;let w=!1,y=!1;const k=async()=>{if(!(w||y)){y=!0;try{const S=(await $.providerAccounts()).accounts.find(E=>E.id===u.id);if(w)return;const C=S==null?void 0:S.login;if(!C||C.state==="pending")return;if(w=!0,v.current=null,h(null),C.state!=="connected"){c(C.message??z.brain.chatgpt.failed);return}l(!0),c(await j(u.id)),l(!1)}catch{}finally{y=!1}}},N=window.setInterval(()=>void k(),SX);return()=>{w=!0,window.clearInterval(N)}},[u]);const j=async w=>{var y,k;try{const N=(await $.accountModels(w).catch(()=>({models:[]}))).models,S=((y=N.find(E=>E.isDefault))==null?void 0:y.id)??((k=N[0])==null?void 0:k.id)??_N,C=(await $.providerAccounts()).accounts.find(E=>E.id===w);return C&&C.defaultModel!==S&&await $.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:w,label:b,model:S})}catch(N){return N instanceof ve?N.message:String(N)}},x=()=>{const w=v.current;v.current=null,w&&$.codexAccountAction(w.id,"cancel-login",w.revision).catch(()=>{}),s()};return n.jsxs(n.Fragment,{children:[a||e?n.jsx(it,{children:n.jsx(Js,{line:z.brain.checking.chatgpt})}):o?n.jsx(it,{children:n.jsx(ft,{children:o})}):u?n.jsx(it,{children:n.jsxs(ft,{children:[z.brain.chatgpt.codeBefore,n.jsx("strong",{children:u.code}),z.brain.chatgpt.codeAfter]})}):null,n.jsx(tn,{actions:n.jsxs(n.Fragment,{children:[n.jsx(as,{onClick:x,disabled:a||e}),u?n.jsx(dt,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",children:z.brain.chatgpt.open}):o?n.jsx(A,{variant:"accent",size:"lg",disabled:a||e,onClick:()=>{g.current=typeof window.open=="function"?window.open("","_blank"):null,m(w=>w+1)},children:z.brain.chatgpt.again}):null]}),children:u?n.jsx(Fw,{code:u.code,label:z.brain.chatgpt.code}):null})]})}const EX="claude-sonnet-5";function AX({busy:e,problem:t,onBack:s,onConnected:r,accounts:i,claudeModel:a}){const[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(""),g=d.useRef(null);d.useEffect(()=>()=>{const w=g.current;g.current=null,w&&$.anthropicAccountAction(w.id,"cancel-login",w.revision).catch(()=>{})},[]);const v=()=>{const w=g.current;g.current=null,w&&$.anthropicAccountAction(w.id,"cancel-login",w.revision).catch(()=>{}),s()},b=a??EX,j=()=>{o(!0),u(null);const w=typeof window.open=="function"?window.open("","_blank"):null;(async()=>{try{const y=((i==null?void 0:i.accounts)??[]).find(E=>E.auth==="anthropic-oauth"),k=y?{id:y.id}:await $.saveProviderAccount({label:z.brain.claude.label,kind:"anthropic",auth:"anthropic-oauth",baseUrl:"",defaultModel:b,enabled:!0}),S=(await $.providerAccounts()).accounts.find(E=>E.id===k.id),C=await $.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??""}),w&&C.verificationUrl?w.location.href=C.verificationUrl:w==null||w.close()}catch(y){w==null||w.close(),u(y instanceof ve?y.message:String(y))}finally{o(!1)}})()},x=()=>{!h||m.trim()===""||(g.current=null,o(!0),(async()=>{try{await $.anthropicAccountAction(h.id,"complete-login",h.revision,{attemptId:h.attemptId,code:m.trim()});const w=await $.testProviderAccount(h.id);if(w.state!=="connected"){u(w.message);return}u(await r({accountId:h.id,label:z.brain.claude.label,model:b}))}catch(w){u(w instanceof ve?w.message:String(w))}finally{o(!1)}})())};return n.jsxs(n.Fragment,{children:[l||e?n.jsx(it,{children:n.jsx(Js,{line:z.brain.checking.claude})}):t??c?n.jsx(it,{children:n.jsx(ft,{children:t??c})}):null,h?n.jsxs(n.Fragment,{children:[n.jsx(it,{children:n.jsx(ft,{children:z.brain.claude.waiting})}),n.jsx(tn,{actions:n.jsxs(n.Fragment,{children:[n.jsx(as,{onClick:v,disabled:l}),n.jsx(dt,{size:"lg",href:h.url,target:"_blank",rel:"noreferrer",children:z.brain.claude.open}),n.jsx(A,{variant:"accent",size:"lg",disabled:l||m.trim()==="",onClick:x,children:z.brain.claude.finish})]}),children:n.jsx(oe,{label:z.brain.claude.paste,grow:!0,children:n.jsx(TX,{value:m,onChange:p})})})]}):n.jsx(tn,{actions:n.jsxs(n.Fragment,{children:[n.jsx(as,{onClick:v,disabled:e||l}),n.jsx(A,{variant:"accent",size:"lg",disabled:e||l,onClick:j,children:z.brain.claude.start})]})})]})}function TX({value:e,onChange:t}){const s=eo();return n.jsx("input",{ref:s,type:"password",autoComplete:"off",spellCheck:!1,value:e,onChange:r=>t(r.target.value)})}const $X={days:"calendar",mail:"mail",money:"money",voice:"bulb",code:"monitor",pictures:"files"};function RX(e){const t=(e==null?void 0:e.plugins)??[];if(t.length===0)return null;const s=t.map(i=>i.title),r=t.filter(i=>i.state==="failed");if(e!=null&&e.running){const i=t.filter(a=>a.state==="ready"||a.state==="failed").length;return{line:z.takeOn.fetching(s,Math.min(i+1,t.length),t.length),done:!1}}return r.length>0?{line:r.map(i=>z.takeOn.failed(i.title,i.reason??"")).join(" "),done:!0}:{line:z.takeOn.ready(s),done:!0}}function IX({answers:e,progress:t,onProgress:s,onSettled:r,onBack:i,onTrouble:a}){const[l,o]=d.useState(()=>e.takeOn??[...oU]),[c,u]=d.useState(!1),h=zo.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(()=>$.takeOn(g)).then(()=>{s(),r({...e,takeOn:g})}).catch(v=>a(v instanceof ve?v.message:String(v))).finally(()=>u(!1)))},p=RX(t);return n.jsxs(n.Fragment,{children:[n.jsx(no,{children:z.takeOn.title}),n.jsx(it,{children:n.jsx(ft,{children:z.takeOn.ask})}),n.jsxs(tn,{actions:n.jsxs(n.Fragment,{children:[n.jsx(as,{onClick:i,disabled:c}),n.jsx(A,{variant:"ghost",size:"lg",disabled:c,onClick:()=>m([]),children:z.takeOn.none}),n.jsx(to,{onClick:()=>m(zo.filter(g=>l.includes(g.id)).map(g=>g.id)),disabled:c||l.length===0,children:z.takeOn.submit})]}),children:[n.jsx("div",{className:"wiz-grid","data-cols":"3",role:"group","aria-label":z.takeOn.title,children:zo.map(g=>{const v=l.includes(g.id);return n.jsxs("button",{type:"button",className:"wiz-opt","data-tile":"true","aria-pressed":v,onClick:()=>f(g.id),children:[n.jsxs("span",{className:"wiz-tile-top",children:[n.jsx("span",{className:"wiz-glyph","aria-hidden":"true",children:n.jsx(ce,{name:$X[g.id]})}),n.jsx("span",{className:"wiz-tick","aria-hidden":"true",children:v?n.jsx(ce,{name:"check",size:12}):null})]}),n.jsxs("span",{children:[n.jsx("span",{className:"wiz-opt-title",children:g.title}),n.jsx("span",{className:"wiz-opt-plugins",children:g.plugins})]}),n.jsx("span",{className:"wiz-opt-line",children:g.line})]},g.id)})}),h.length>0?n.jsxs("div",{className:"wiz-stack",children:[p?n.jsxs("div",{className:"wiz-busy","data-boxed":"true",role:"status",children:[n.jsxs("span",{className:"wiz-pulse","data-done":p.done?"true":void 0,"aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]}),n.jsx("span",{children:p.line}),l.includes("mail")?n.jsx("span",{className:"wiz-busy-side",children:z.takeOn.builtIn}):null]}):null,n.jsx("div",{className:"wiz-foot",children:h.map(g=>g.note).join(" ")})]}):n.jsx("div",{className:"wiz-foot",children:z.takeOn.nothing})]})]})}function PX({answers:e,navigate:t,onSettled:s,onBack:r}){var g,v,b;const[i,a]=d.useState(((g=e.reach)==null?void 0:g.phone)===!0),[l,o]=d.useState(((v=e.reach)==null?void 0:v.mailbox)===!0),[c,u]=d.useState(((b=e.reach)==null?void 0:b.app)===!0),[h,f]=d.useState(e.browser),m=(e.takeOn??[]).includes("mail"),p=()=>{const j={phone:i,mailbox:l,app:c,browser:h==="chrome"||h==="chromium"||h==="installed"};h!==void 0&&Promise.resolve().then(()=>$.onboardingStep("browser")).catch(()=>{}),s({...e,reach:j,...h!==void 0?{browser:h}:{}})};return n.jsxs(n.Fragment,{children:[n.jsx(no,{children:z.reach.title}),n.jsx(it,{children:n.jsx(ft,{children:z.reach.ask})}),n.jsx(tn,{actions:n.jsxs(n.Fragment,{children:[n.jsx(as,{onClick:r}),n.jsx(to,{onClick:p,children:z.reach.submit})]}),children:n.jsxs("div",{className:"wiz-rows",children:[n.jsx(MX,{paired:i,onPaired:()=>a(!0)}),n.jsx(OX,{wanted:m,added:l,onAdded:o,navigate:t,timezone:e.clock??"UTC"}),n.jsx(LX,{app:c,onApp:()=>u(!0),browser:h,onBrowser:f}),i?n.jsx(V,{tone:"good",role:"status",children:z.reach.phone.hello}):null]})})]})}function MX({paired:e,onPaired:t}){const[s,r]=d.useState(null),[i,a]=d.useState(!1),l=d.useRef(t);l.current=t,d.useEffect(()=>{let c=!1;return Promise.resolve().then(()=>$.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 n.jsxs("div",{className:"wiz-row",children:[n.jsx("span",{className:"wiz-glyph","aria-hidden":"true",children:n.jsx(ce,{name:"chat"})}),n.jsxs("span",{className:"wiz-row-text",children:[n.jsx("span",{className:"wiz-opt-title",children:z.reach.phone.title}),n.jsx("span",{className:"wiz-opt-line",children:z.reach.phone.line})]}),e?n.jsx("span",{className:"wiz-row-side",children:n.jsx(we,{tone:"good",dot:!0,children:z.reach.phone.paired})}):o?n.jsx(DX,{onPaired:t}):n.jsx("span",{className:"wiz-row-side",children:n.jsx(A,{size:"lg",disabled:s===null,onClick:()=>a(!0),children:z.reach.phone.setUp})}),i?n.jsx(Ye,{title:z.telegram.sheet,onClose:()=>a(!1),children:n.jsx(WX,{onPaired:t,onDismiss:()=>a(!1)})}):null]})}function DX({onPaired:e}){const{offer:t,square:s,paired:r,stale:i,ask:a}=ay(()=>$.telegram().then(o=>o.paired),e),l=d.useRef(!1);return d.useEffect(()=>{l.current||(l.current=!0,a().catch(()=>{}))},[a]),r?n.jsx("span",{className:"wiz-row-side",children:n.jsx(we,{tone:"good",dot:!0,children:z.reach.phone.paired})}):i||!t?n.jsx("span",{className:"wiz-row-side",children:n.jsx(A,{size:"lg",onClick:()=>void a().catch(()=>{}),children:z.telegram.newCode})}):n.jsx("span",{className:"wiz-qr-slot",children:n.jsx(ly,{offer:t,square:s})})}function OX({wanted:e,added:t,onAdded:s,navigate:r,timezone:i}){const[a,l]=d.useState(void 0),[o,c]=d.useState(!1),[u,h]=d.useState(null),f=d.useCallback(()=>{Promise.resolve().then(()=>$.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;h(p),s(p!==null)}).catch(()=>{})},[]);return d.useEffect(()=>{let m=!1;return Promise.resolve().then(()=>$.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]),n.jsxs("div",{className:"wiz-row",children:[n.jsx("span",{className:"wiz-glyph","data-tone":"mail","aria-hidden":"true",children:n.jsx(ce,{name:"mail"})}),n.jsxs("span",{className:"wiz-row-text",children:[n.jsx("span",{className:"wiz-opt-title",children:e?z.reach.mailbox.forTriage:z.reach.mailbox.title}),n.jsx("span",{className:"wiz-opt-line",children:a===null?z.reach.mailbox.unavailable:z.reach.mailbox.line})]}),n.jsx("span",{className:"wiz-row-side",children:t||u?n.jsx(we,{tone:"good",dot:!0,mono:u!==null,children:u??z.reach.mailbox.added}):a?n.jsx(A,{size:"lg",onClick:()=>c(!0),children:z.reach.mailbox.add}):null}),o&&a?n.jsx(Ye,{title:z.reach.mailbox.sheet,size:"wide",onClose:()=>{c(!1),f()},children:n.jsx(vw,{page:a.page,siblings:a.siblings,navigate:r,timezone:i,embedded:!0})}):null]})}function LX({app:e,onApp:t,browser:s,onBrowser:r}){const i=Rf(),a=typeof navigator>"u"?null:h$(navigator.userAgent),[l,o]=d.useState(null),[c,u]=d.useState("idle"),[h,f]=d.useState(null),[m,p]=d.useState(null),[g,v]=d.useState(void 0),b=d.useRef(!1),j=d.useRef(!0);d.useEffect(()=>(j.current=!0,Promise.resolve().then(()=>$.browser()).then(C=>{var R;if(!j.current)return;const E=C==null?void 0:C.browser;E?((R=E.install)==null?void 0:R.state)==="running"?(o("none"),b.current=!0,u("installing"),y()):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))},w=async C=>{u("launching");let E;try{E=await $.browserCheck()}catch(R){return x(R instanceof ve?R.message:String(R))}if(j.current){if(E.ok){u("idle"),o(C),r(b.current?"installed":C);return}x(E.message,E.command)}},y=async()=>{var R,I;let C;try{C=await $.browser()}catch(L){return x(L instanceof ve?L.message:String(L))}if(!j.current)return;const E=C.browser;if(!E)return x(z.browser.failed(""));if(((R=E.install)==null?void 0:R.state)==="running"){u("installing"),v(E.install.progress),window.setTimeout(()=>void y(),1e3);return}return E.engine!=="none"?w(E.engine):x(((I=E.install)==null?void 0:I.line)??"")},k=()=>{if(p(null),l==="chrome"||l==="chromium"){w(l);return}b.current=!0,u("installing"),v(void 0),Promise.resolve().then(()=>$.browserInstall()).then(()=>{j.current&&window.setTimeout(()=>void y(),1e3)}).catch(C=>x(C instanceof ve?C.message:String(C)))},N=s==="chrome"||s==="chromium"||s==="installed",S=c==="installing"||c==="launching";return n.jsxs("div",{className:"wiz-row","data-wrap":c!=="idle"?"true":void 0,children:[n.jsx("span",{className:"wiz-glyph","data-tone":"good","aria-hidden":"true",children:n.jsx(ce,{name:"globe"})}),n.jsxs("span",{className:"wiz-row-text",children:[n.jsx("span",{className:"wiz-opt-title",children:z.reach.app.title}),n.jsx("span",{className:"wiz-opt-line",children:z.reach.app.line})]}),n.jsxs("span",{className:"wiz-row-side",children:[e?n.jsx(we,{tone:"good",dot:!0,children:z.reach.app.installed}):i?n.jsx(A,{size:"lg",onClick:()=>{i.prompt().then(()=>i.userChoice).then(C=>{(!C||C.outcome==="accepted")&&t()}).catch(()=>{})},children:z.reach.app.install}):null,N?n.jsx(we,{tone:"good",dot:!0,children:z.reach.app.ready(s==="chrome"?"chrome":"chromium")}):l===null||l==="other"?null:n.jsx(A,{size:"lg",disabled:S,onClick:k,children:S?z.browser.installing:c==="failed"?z.browser.retry:l==="chrome"?z.reach.app.chrome:l==="chromium"?z.reach.app.chromium:z.reach.app.fetch})]}),!e&&!i&&a?n.jsx("span",{className:"wiz-row-note",children:a}):null,c==="installing"?n.jsxs("div",{className:"wiz-row-more",children:[n.jsx("span",{className:"wiz-opt-line",children:z.browser.needs}),n.jsx(bT,{progress:g})]}):c==="launching"?n.jsx("div",{className:"wiz-row-more",children:n.jsx(Js,{line:z.browser.launching})}):c==="failed"?n.jsxs("div",{className:"wiz-row-more",children:[n.jsx("span",{className:"wiz-opt-line",children:z.browser.failed(h??"")}),m?n.jsx(zX,{command:m}):null]}):null]})}function FX({answers:e,existing:t,onSettled:s,onTrouble:r,onReload:i,onBack:a}){const[l,o]=d.useState(()=>(t==null?void 0:t.name)??tU),[c,u]=d.useState(()=>t!=null&&t.picture||t!=null&&t.avatar?null:"buddi"),[h,f]=d.useState(t?null:z.assistant.purposeValue),[m,p]=d.useState(t?"":z.assistant.purposeValue);d.useEffect(()=>{if(!t)return;let w=!1;return $.firstAgentPersona().then(y=>{w||(f(y.persona),p(y.persona))},y=>{w||r(y instanceof ve?y.message:String(y))}),()=>{w=!0}},[t==null?void 0:t.id]);const[g,v]=d.useState(!1),b=zo.filter(w=>(e.takeOn??[]).includes(w.id)&&"mate"in w).map(w=>w.mate),j=Fk.find(w=>w.id===c),x=()=>{if(l.trim()===""||g)return;v(!0);const w=!t||h!==null&&m.trim()!==""&&m.trim()!==h.trim()?{instructions:m.trim()}:{},y=t?$.updateFirstAgent({name:l.trim(),...w}):$.createFirstAgent({name:l.trim(),handle:lX(l),description:"",...w,...e.brain?{accountId:e.brain.accountId}:{}});(async()=>{let k;try{k=await y}catch(S){r(S instanceof ve?S.message:String(S)),v(!1);return}let N=null;try{j&&await $.uploadAgentPicture(k.id,await fR(j.role))}catch(S){N=S instanceof ve?S.message:String(S)}v(!1),i(),s({...e,assistant:{id:k.id,name:l.trim(),avatar:j?"":(t==null?void 0:t.avatar)??""}}),N&&r(N)})()};return n.jsxs(n.Fragment,{children:[n.jsx(no,{children:z.assistant.title}),n.jsx(it,{children:n.jsxs(ft,{children:[z.assistant.ask,b.length>0?z.assistant.team(b):""]})}),n.jsx(tn,{actions:n.jsxs(n.Fragment,{children:[n.jsx(as,{onClick:a,disabled:g}),n.jsx(to,{onClick:x,disabled:g||l.trim()===""||h===null,children:z.assistant.submit})]}),children:n.jsxs("div",{className:"wiz-meet",children:[n.jsxs("div",{className:"wiz-face",children:[n.jsx("span",{className:"wiz-face-tile","data-agent":(j==null?void 0:j.id)??"buddi","aria-hidden":"true",children:j?n.jsx("img",{src:ka(j.role),alt:""}):t!=null&&t.picture?n.jsx("img",{src:t.picture,alt:""}):n.jsx("span",{className:"wiz-face-emoji",children:(t==null?void 0:t.avatar)??""})}),n.jsx("div",{className:"wiz-swatches",role:"group","aria-label":z.assistant.colour,children:Fk.map(w=>n.jsx("button",{type:"button",className:"wiz-swatch","data-agent":w.id,"aria-label":z.assistant.swatch(w.label),"aria-pressed":c===w.id,onClick:()=>u(w.id)},w.id))}),n.jsx("span",{className:"wiz-face-cap",children:z.assistant.colour})]}),n.jsxs("div",{className:"wiz-stack",children:[n.jsx(oe,{label:z.assistant.name,children:n.jsx("input",{value:l,maxLength:60,onChange:w=>o(w.target.value)})}),n.jsx(oe,{label:z.assistant.purpose,hint:z.assistant.purposeHint,children:n.jsx("textarea",{className:"wiz-persona",value:m,maxLength:8e3,rows:7,onChange:w=>p(w.target.value)})})]})]})})]})}function _X({answers:e,assistantAgent:t,met:s,onMet:r,navigate:i,onPickAnotherBrain:a,onSpoken:l,progress:o,onProgress:c}){var M,P;const u=e.assistant,[h,f]=d.useState(s),[m,p]=d.useState([]),[g,v]=d.useState(!1),[b,j]=d.useState(!1),[x,w]=d.useState(!0),[y,k]=d.useState(!1),N=d.useRef(!1),S=d.useMemo(()=>t?[t]:[],[t]);d.useEffect(()=>{c()},[]),d.useEffect(()=>{if(!u||N.current)return;if(N.current=!0,s){f(s);return}let D=!1;return(async()=>{try{const O=await Ve.startConversation(u.id);if(D)return;f(O.conversationId),r(O.conversationId),await $.onboardingStep(DI.handover,{conversationId:O.conversationId}).catch(()=>{}),await Ve.send(u.id,{conversationId:O.conversationId,text:iU,opening:!0})}catch{D||(w(!1),v(!0))}})(),()=>{D=!0}},[u==null?void 0:u.id,s]),d.useEffect(()=>{if(!h)return;let D=!1;const O=Date.now(),H=()=>{Ve.conversation(h).then(Y=>{if(D)return;p(Y.messages);const W=Date.now()-O;if(Y.messages.some(zN)){w(!1),v(!1),j(!1);return}const q=Y.runs??[],_=q.some(Q=>Q.finishedAt===null),X=q.length>0&&!_;j(_&&W>=oX),(X||W>=cX)&&(w(!1),v(!0))}).catch(()=>{})};H();const B=window.setInterval(H,zI);return()=>{D=!0,window.clearInterval(B)}},[h]);const C=u&&h?st(u.id,h):null,E=m.some(zN);d.useEffect(()=>{E&&C&&l(C)},[E,C,l]);const R=e.takeOn??[],I=z.handover.starters({days:R.includes("days"),mail:R.includes("mail"),mailbox:((M=e.reach)==null?void 0:M.mailbox)===!0}),L={days:R.includes("days"),mailbox:((P=e.reach)==null?void 0:P.mailbox)===!0,money:R.includes("money"),pictures:R.includes("pictures")},F=(o==null?void 0:o.waiting)??[],T=D=>{!u||!h||y||(k(!0),Promise.resolve().then(()=>Ve.send(u.id,{conversationId:h,text:D})).then(()=>i(st(u.id,h),!0)).catch(()=>k(!1)))};return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"wiz-hello",children:n.jsx(aw,{messages:m,live:[],now:Date.now(),onOpen:()=>{},working:x,agents:S,agentName:(u==null?void 0:u.name)??"",...u?{agentId:u.id}:{},emptyHint:z.handover.waiting,plain:!0,workingLine:z.handover.looking((u==null?void 0:u.name)??"")})}),b&&!g?n.jsx(it,{children:n.jsx(ft,{children:z.handover.slow})}):null,g?n.jsxs(n.Fragment,{children:[n.jsx(it,{children:n.jsx(ft,{children:z.handover.silent})}),n.jsx(tn,{actions:n.jsx(to,{onClick:a,children:z.handover.again})})]}):null,E?n.jsx("div",{className:"wiz-starters",role:"group","aria-label":z.handover.starterLabel,children:I.map(D=>n.jsx("button",{type:"button",className:"wiz-starter",disabled:y,onClick:()=>T(D),children:D},D))}):null,E?n.jsx(jG,{setUp:L,navigate:D=>i(D,!0)}):null,E&&F.length>0?n.jsx(V,{tone:"warm",title:z.handover.waitingTitle(F.length),action:n.jsx(A,{variant:"accent",onClick:()=>i(dn,!0),children:z.handover.home}),children:z.handover.waitingBody(F)}):null,E&&C?n.jsx(tn,{actions:n.jsx(dt,{variant:"accent",size:"lg",href:C,onClick:D=>{D.preventDefault(),i(C,!0)},children:z.done.open})}):null]})}function zX({command:e}){const[t,s]=d.useState("idle"),r=()=>{var i;if(!((i=navigator.clipboard)!=null&&i.writeText)){s("failed");return}navigator.clipboard.writeText(e).then(()=>s("done"),()=>s("failed"))};return n.jsxs(le,{gap:"sm",children:[n.jsx(Pt,{label:"The command to run",children:e}),n.jsxs(ae,{align:"end",children:[t==="failed"?n.jsx("span",{className:"ui-toolbar-note",children:"Select it to copy."}):null,n.jsx(A,{size:"sm",onClick:r,children:t==="done"?"Copied":"Copy"})]})]})}function zN(e){return e.role==="assistant"&&(e.blocks??[]).some(t=>t.type==="text"&&t.text.trim()!=="")}function UX({onCancel:e,onStarted:t,onTrouble:s}){const[r,i]=d.useState(null),[a,l]=d.useState(""),[o,c]=d.useState(!1),u=()=>{!r||o||(c(!0),s(null),$.firstRunRestore(r,a.trim()).then(h=>{tv(h.job.id),t()}).catch(h=>s(h instanceof ve?h.message:String(h))).finally(()=>c(!1)))};return n.jsx(Ye,{title:z.restore.sheet,onClose:e,children:n.jsxs("div",{className:"wiz-restore",children:[n.jsx("p",{className:"wiz-foot",children:z.restore.lede}),n.jsx(oe,{label:z.restore.file,children:n.jsx("input",{type:"file",onChange:h=>{var f;return i(((f=h.target.files)==null?void 0:f[0])??null)}})}),n.jsx(oe,{label:z.restore.passphrase,hint:z.restore.passphraseHint,children:n.jsx("input",{type:"password",autoComplete:"off",value:a,onChange:h=>l(h.target.value)})}),n.jsxs(ae,{align:"end",children:[n.jsx(A,{variant:"ghost",onClick:e,children:z.restore.cancel}),n.jsx(A,{variant:"accent",disabled:o||!r,onClick:u,children:z.restore.submit})]})]})})}function BX({onDone:e,onFailed:t}){const[s,r]=d.useState([]),i=d.useRef({onDone:e,onFailed:t});i.current={onDone:e,onFailed:t},d.useEffect(()=>{const l=_I();if(!l)return;let o=!1;const c=()=>{$.backupJob(l).then(h=>{o||(r(f=>f.includes(h.phase)?f:[...f,h.phase]),h.phase==="done"?(o=!0,tv(null),$.owner().then(f=>i.current.onDone(f.preferredName??void 0),()=>i.current.onDone(void 0))):(h.phase==="rolled-back"||h.phase==="failed")&&(o=!0,tv(null),i.current.onFailed(h.error??z.restore.phases[h.phase])))}).catch(()=>{})};c();const u=window.setInterval(c,zI);return()=>{o=!0,window.clearInterval(u)}},[]);const a=s.filter(l=>l in z.restore.phases);return n.jsxs(n.Fragment,{children:[n.jsx(no,{children:z.restore.title}),n.jsxs(it,{children:[n.jsx(ft,{children:z.restore.started}),a.map(l=>n.jsx(ft,{children:z.restore.phases[l]},l))]}),n.jsx(Js,{})]})}function WX(e){return n.jsx(cy.Provider,{value:null,children:n.jsx("div",{className:"wiz-sheet-body",children:n.jsx(HX,{...e})})})}function HX({onPaired:e,onDismiss:t}){const s=eo(),[r,i]=d.useState(""),[a,l]=d.useState(!1),[o,c]=d.useState(null),{offer:u,square:h,paired:f,stale:m,ask:p}=ay(()=>$.telegram().then(b=>b.paired),e),g=()=>{r.trim()===""||a||(l(!0),c(null),(async()=>{try{const b=await $.saveTelegramToken(r.trim());if(i(""),b.restartNeeded){c(b.note??z.telegram.restart);return}await p()}catch(b){c(b instanceof ve?b.message:String(b))}finally{l(!1)}})())},v=()=>{c(null),p().catch(b=>c(b instanceof ve?b.message:String(b)))};return f?n.jsxs(n.Fragment,{children:[n.jsx(it,{children:n.jsx(ft,{children:z.telegram.paired})}),n.jsx(tn,{actions:n.jsx(A,{variant:"accent",onClick:t,children:z.telegram.close})})]}):u?n.jsxs(n.Fragment,{children:[n.jsx(it,{children:n.jsx(ft,{children:m?z.telegram.expired:z.telegram.scan})}),n.jsx(tn,{actions:n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",onClick:t,children:z.telegram.notNow}),m?n.jsx(A,{variant:"accent",onClick:v,children:z.telegram.newCode}):null]}),children:m?null:n.jsx(ly,{offer:u,square:h})})]}):n.jsxs(n.Fragment,{children:[n.jsxs(it,{children:[n.jsx(ft,{children:z.telegram.how}),o?n.jsx(ft,{children:o}):null]}),n.jsx(tn,{actions:n.jsxs(n.Fragment,{children:[n.jsx(A,{variant:"ghost",onClick:t,children:z.telegram.notNow}),n.jsx(A,{variant:"accent",disabled:a||r.trim()==="",onClick:g,children:z.telegram.submit})]}),children:n.jsx(oe,{label:z.telegram.field,grow:!0,children:n.jsx("input",{ref:s,type:"password",value:r,autoComplete:"off",spellCheck:!1,onChange:b=>i(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),g())}})})})]})}const Cp={recovery:0,lost:1,paused:2},KX="Lost buddi. Retrying…",VX="The queue is paused. Nothing is being claimed until you resume it.";function GX(e){const t=[];return e.recovery&&t.push({id:"recovery",priority:Cp.recovery,tone:"warning",text:vR,action:{label:"Finish the checklist",href:Yg}}),e.lost&&t.push({id:"lost",priority:Cp.lost,tone:"critical",text:KX}),e.paused&&t.push({id:"paused",priority:Cp.paused,tone:"warning",text:VX,action:{label:"Resume",onClick:()=>{$.setPaused(!1).catch(()=>{})}}}),t}function qX({banners:e,onNavigate:t}){if(e.length===0)return null;const s=[...e].sort((l,o)=>l.priority-o.priority),r=s[0],i=s.slice(1),a=r.action;return n.jsxs("div",{className:"shell-banner",role:"status","data-tone":r.tone,"data-banner":r.id,children:[n.jsx("span",{className:"shell-banner-dot","aria-hidden":"true"}),n.jsx("span",{className:"shell-banner-text",children:r.text}),i.length>0?n.jsxs("span",{className:"shell-banner-more",title:i.map(l=>l.text).join(`
134
+ `),children:["+",i.length," more"]}):null,a!=null&&a.href?n.jsx(dt,{size:"sm",href:a.href,onClick:l=>{l.preventDefault(),t(a.href)},children:a.label}):a?n.jsx(A,{size:"sm",onClick:a.onClick,children:a.label}):null]})}const WI=1e4,YX=3e4,HI=6e3,uy=/^(localhost|127(?:\.\d{1,3}){3}|\[?::1\]?)$|\.localhost$/i;function JX(e){return uy.test(e)?n.jsxs(n.Fragment,{children:["Is buddi running on this Mac? ",n.jsx("code",{children:"buddi status"})," says."]}):n.jsx(n.Fragment,{children:"Is Tailscale on, and the Mac it runs on awake?"})}async function KI(e){let t;const s=new Promise((r,i)=>{t=setTimeout(()=>i(new ve(0,eh)),e)});try{return{up:!0,version:await Promise.race([$.version(),s])}}catch(r){return th(r)?{up:!1}:{up:!0}}finally{clearTimeout(t)}}function VI(e){var t;return e.up&&Fj((t=e.version)==null?void 0:t.web)?(window.location.reload(),!1):e.up}function QX({host:e,onRetry:t,retrying:s}){return n.jsxs("main",{className:"unreachable",role:"alert",children:[n.jsx("span",{className:"ui-blob","data-size":"lg","aria-hidden":"true",children:n.jsx("img",{src:ka("core"),alt:""})}),n.jsxs("h1",{children:["buddi isn't answering at ",e,"."]}),n.jsx("p",{children:JX(e.replace(/:\d+$/,""))}),n.jsx("div",{className:"unreachable-actions",children:n.jsx(A,{variant:"accent",onClick:t,disabled:s,children:s?"Retrying…":"Retry"})})]})}function XX({children:e}){const[t,s]=d.useState("checking"),[r,i]=d.useState(!1),a=d.useRef(!1),l=d.useCallback(async()=>{if(a.current)return;a.current=!0,i(!0);const o=await KI(HI);a.current=!1,i(!1),s(c=>c==="checking"?o.up?"up":"down":VI(o)?"up":"down")},[]);return d.useEffect(()=>{l()},[l]),d.useEffect(()=>{if(t!=="down")return;const o=window.setInterval(()=>void l(),WI);return()=>window.clearInterval(o)},[t,l]),t==="checking"?null:t==="down"?n.jsx(QX,{host:window.location.host,onRetry:()=>void l(),retrying:r}):n.jsx(n.Fragment,{children:e})}function ZX(e=YX){const[t,s]=d.useState(!1);return d.useEffect(()=>{let r;const i=()=>{clearTimeout(r);const l=vc();if(l===null)return s(!1);const o=l+e-Date.now();o<=0?s(!0):r=setTimeout(i,o)};i();const a=gj(i);return()=>{a(),clearTimeout(r)}},[e]),t}function eZ(){const e=ZX();return d.useEffect(()=>{if(!e)return;const t=window.setInterval(()=>{KI(HI).then(VI)},WI);return()=>window.clearInterval(t)},[e]),e}const tZ={local:"Local",tailnet:"Tailnet",reconnecting:"Reconnecting…"},UN=(e,t,s=`${t}s`)=>e===1?t:s;function nZ(){return Intl.DateTimeFormat().resolvedOptions().timeZone}function sZ(e){return e.includes("/")?e.split("/").pop().replace(/_/g," "):e}function rZ(e,t){return t?"reconnecting":uy.test(e)?"local":"tailnet"}function GI(e,t,s=nZ()){const r=[],i=tZ[e.link];if(r.push({key:"link",route:Pe("system"),dot:e.link==="reconnecting"?"warning":"good",text:i,label:`Connection: ${i}`}),e.focus){const u=`${na[e.focus.mode]} ${$c(e.focus,e.timezone,t)}`;r.push({key:"focus",route:Pe("notifications"),icon:"moon",text:u,label:`Focus: ${u}`})}const a=[];if(e.working>0&&a.push({key:"working",dot:"working",text:`${e.working} ${UN(e.working,"agent")} working`}),a.push(e.paused?{key:"queue",tone:"warning",text:"Queue paused"}:{key:"queue",text:"Queue running"}),e.failed>0&&a.push({key:"failed",tone:"critical",text:`${e.failed} failed`}),r.push({key:"work",route:e.failed>0?`${yt}/jobs?state=failed`:`${yt}/jobs`,parts:a,label:`Work: ${a.map(u=>u.text).join(", ")}`}),e.approvals>0){const u=`${UN(e.approvals,"approval")} waiting`;r.push({key:"approvals",route:Cl,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:Pe("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=zt(t,l),c=l!==s;return r.push({key:"time",route:Pe("you"),end:!0,time:o,...c?{zone:sZ(l)}:{},label:`Your time: ${o}${c?`, ${l}`:""}`}),r}function iZ(e){var t;return e.link==="reconnecting"||e.failed>0?"critical":e.paused?"warning":e.approvals>0||(((t=e.version)==null?void 0:t.updateAvailable)??!1)?"attention":"good"}function qI(){const[e,t]=d.useState(()=>new Date);return d.useEffect(()=>{let s;const r=()=>{s=setTimeout(()=>{t(new Date),r()},6e4-Date.now()%6e4)};return r(),()=>clearTimeout(s)},[]),e}function aZ(){const[e,t]=d.useState(()=>vc()!==null);return d.useEffect(()=>gj(()=>t(vc()!==null)),[]),e}function YI({item:e}){var t;return n.jsxs(n.Fragment,{children:[e.dot?n.jsx("span",{className:"shell-status-dot","data-tone":e.dot,"aria-hidden":"true"}):null,e.icon?n.jsx(ce,{name:e.icon,size:12}):null,e.count?n.jsx("span",{className:"ui-badge","aria-hidden":"true",children:e.count>99?"99+":e.count}):null,(t=e.parts)==null?void 0:t.map((s,r)=>n.jsxs(d.Fragment,{children:[r>0?n.jsx("span",{className:"shell-status-sep","aria-hidden":"true",children:"·"}):null,s.dot?n.jsx("span",{className:"shell-status-dot","data-tone":s.dot,"aria-hidden":"true"}):null,n.jsx("span",{"data-tone":s.tone,children:s.text})]},s.key)),e.text?n.jsx("span",{children:e.text}):null,e.mono?n.jsx("span",{className:"shell-status-mono",children:e.mono}):null,e.update?n.jsx("span",{className:"ui-badge","data-kind":"dot","data-testid":"status-update-dot","aria-hidden":"true"}):null,e.time?n.jsx("span",{className:"shell-status-time",children:e.time}):null,e.zone?n.jsx("span",{className:"shell-status-zone",children:e.zone}):null]})}function lZ({status:e,onNavigate:t}){const s=qI(),r=If(),i=GI(e,s),a=l=>n.jsx("a",{className:"shell-status-item","data-item":l.key,href:l.route,"aria-label":l.label,title:l.label,onClick:o=>{o.preventDefault(),t(l.route)},children:n.jsx(YI,{item:l})},l.key);return n.jsxs("footer",{className:"shell-status","aria-label":"Status",children:[i.filter(l=>!l.end).map(a),n.jsx("span",{className:"shell-status-spacer"}),i.filter(l=>l.end).map(a),r.pin?n.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:n.jsx(ce,{name:"lock",size:13})}):null]})}function oZ({status:e,onNavigate:t}){const s=qI(),r=If(),i=iZ(e);return n.jsx("div",{className:"rail-status",children:n.jsxs(Hc,{modal:!1,children:[n.jsx(Kc,{asChild:!0,children:n.jsx("button",{type:"button",className:"rail-status-btn","aria-label":"Status",children:n.jsx("span",{className:"rail-status-dot","data-tone":i,"data-testid":"rail-status-dot","aria-hidden":"true"})})}),n.jsx(Gl,{children:n.jsxs(Vc,{className:"ui-menu rail-status-menu",side:"right",align:"end",sideOffset:10,children:[n.jsx(ma,{className:"ui-menu-label",children:"Status"}),GI(e,s).map(a=>n.jsx(js,{asChild:!0,onSelect:()=>t(a.route),children:n.jsx("a",{className:"ui-menu-item rail-status-item","data-item":a.key,href:a.route,"aria-label":a.label,children:n.jsx("span",{className:"rail-status-line",children:n.jsx(YI,{item:a})})})},a.key)),r.pin?n.jsxs(n.Fragment,{children:[n.jsx(Dr,{className:"ui-menu-sep"}),n.jsx(js,{className:"ui-menu-item rail-status-item","data-item":"lock",onSelect:()=>r.lockNow(),children:n.jsxs("span",{className:"rail-status-line",children:[n.jsx(ce,{name:"lock",size:12}),n.jsx("span",{children:"Lock now"})]})})]}):null]})})]})})}const cZ=1e4;function JI(){return d.useSyncExternalStore(Ez,Dk,Dk)}function uZ(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 BN(e){const t=Math.max(0,Math.floor(e/1e3));return`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`}function dZ({command:e}){const[t,s]=d.useState(!1);return d.useEffect(()=>{if(!t)return;const r=window.setTimeout(()=>s(!1),1600);return()=>window.clearTimeout(r)},[t]),n.jsxs("div",{className:"rs-cmd",children:[n.jsx("code",{className:"rs-cmd-text",children:e}),n.jsx(A,{size:"sm",onClick:()=>{var r;(r=navigator.clipboard)==null||r.writeText(e).then(()=>s(!0),()=>{})},children:t?"Copied":"Copy"})]})}function hZ({state:e,elapsedMs:t,hostname:s=window.location.hostname,onReload:r=()=>ml.reload()}){const i=uZ(e),a=e.kind==="stop",l=!a&&t>=(e.patienceMs??bz),o=uy.test(s),c=d.useRef(null);d.useEffect(()=>{var h;return(h=c.current)==null?void 0:h.focus()},[]);const u=a?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 n.jsx("div",{className:"ui-fieldbg rs-field","data-quiet":"true",children:n.jsx("div",{ref:c,className:"rs",role:"dialog","aria-modal":"true","aria-labelledby":"rs-title",tabIndex:-1,"data-state":a?"stopped":l?"long":"waiting",children:n.jsxs("div",{className:"rs-body",children:[n.jsx("span",{className:"ui-mascot rs-blob","data-size":"lg","aria-hidden":"true",children:n.jsx(Qc,{role:"core",state:a||l?"idle":"working",className:"ui-mascot-blob"})}),n.jsx("h1",{id:"rs-title",className:"rs-title",children:i.title}),n.jsx("p",{className:"rs-line",role:"status",children:l?"Still waiting — buddi may need a hand.":i.line}),!l&&e.step?n.jsx("p",{className:"rs-step",children:e.step}):null,a||l?null:n.jsx("div",{className:"rs-track","aria-hidden":"true",children:n.jsx("span",{})}),a||l?n.jsxs("div",{className:"rs-help",children:[n.jsx("p",{className:"rs-help-line",children:u}),n.jsx(dZ,{command:a?"buddi service start":"buddi status"})]}):null,n.jsxs("div",{className:"rs-foot",children:[n.jsx("span",{className:"rs-meta",children:a?"Checking every few seconds.":l?`${BN(t)} · still checking every few seconds`:t>=cZ?`${BN(t)} · this page reloads when buddi is back`:"This page reloads when buddi is back."}),a||l?n.jsx(A,{size:"sm",variant:l?"accent":void 0,onClick:r,children:"Reload"}):null]})]})})})}function fZ(e){const[t,s]=d.useState(()=>ml.now());return d.useEffect(()=>{if(!e)return;s(ml.now());const r=window.setInterval(()=>s(ml.now()),1e3);return()=>window.clearInterval(r)},[e]),e?Math.max(0,t-e.startedAt):0}function mZ({children:e}){const t=JI(),s=fZ(t),r=d.useRef(null);return d.useEffect(()=>{Tz();let i=vc()!==null;const a=gj(()=>{const o=vc()!==null;i&&!o&&Ok(),i=o}),l=()=>void Ok();return window.addEventListener(yc,l),()=>{a(),window.removeEventListener(yc,l)}},[]),d.useEffect(()=>{const i=r.current;i&&(i.toggleAttribute("inert",t!==null),t?i.setAttribute("aria-hidden","true"):i.removeAttribute("aria-hidden"))},[t]),n.jsxs(n.Fragment,{children:[n.jsx("div",{ref:r,className:"rs-host",children:e}),t?n.jsx(hZ,{state:t,elapsedMs:s}):null]})}const pZ="(max-width: 1080px)",gZ="(max-width: 720px)";function xZ(){const[e,t]=d.useState(()=>window.location.hash||dn);d.useEffect(()=>{const r=()=>t(window.location.hash||dn);return window.addEventListener("hashchange",r),()=>window.removeEventListener("hashchange",r)},[]);const s=d.useCallback((r,i=!1)=>{i?window.history.replaceState(null,"",r):window.location.hash=r,t(r)},[]);return[e,s]}function vZ(){const[e,t]=P$();d.useEffect(()=>{I$(e)},[e]);const s=d.useCallback(r=>t({theme:r}),[t]);return[e.theme,s]}const WN=new Map;function jZ(){var As,Cn,Ts,$s;const[e,t]=xZ(),[s,r]=d.useState("UTC"),[i,a]=d.useState({approvals:0,failed:0,paused:!1,running:0,needs:0}),[l,o]=vZ(),c=Ns(Vj),[u,h]=d.useState(!1),[f,m]=d.useState([]),[p,g]=d.useState(null),[v,b]=d.useState(null),[j,x]=d.useState([]),[w,y]=d.useState(!1),[k,N]=d.useState(null),[S,C]=d.useState(null),[E,R]=d.useState(0),[I,L]=d.useState(null),F=Lz(),T=f.find(Se=>Se.id===p)??null,M=T!==null&&Q8(e),[P,D]=d.useState(!1),O=d.useCallback(()=>D(!0),[]);d.useEffect(()=>{M||D(!1)},[M]),S9(t,xd(e)===null,M?O:void 0);const H=Ns(pZ),B=xR(),Y=tT(),W=E$(),q=de(()=>Promise.resolve().then(()=>$.version()),[],dz),_=q.data;wz(q.reload);const X=_&&!_.checkout&&_.updateAvailable?_:null,Q=Fj(_==null?void 0:_.web);yz(_==null?void 0:_.web);const ee=((As=de(()=>Promise.resolve().then(()=>$.connectionSignals()),[],6e4).data)==null?void 0:As.signals)??[],[fe,Le]=d.useState(null),Ie=d.useMemo(()=>new Set(fe?[fe]:[]),[fe]),[_e,U]=d.useState(new Map);d.useEffect(()=>{const Se=()=>{$.conversations().then(Ke=>{const me=new Map;for(const Jn of Ke.conversations){const Ln=Jn.lastMessageAt??Jn.createdAt,Qs=me.get(Jn.agentId);(!Qs||Ln>Qs)&&me.set(Jn.agentId,Ln)}U(me)}).catch(()=>{})};Se();const Ee=window.setInterval(Se,3e4);return()=>window.clearInterval(Ee)},[e]);const[ie,J]=d.useState(!1);d.useEffect(()=>{if(ie)return;let Se=!1;return $.onboarding().then(Ee=>{Se||(J(!0),Ee.state==="pending"&&Ee.needs.model&&!xd(window.location.hash)&&t(T4,!0))}).catch(()=>{Se||J(!0)}),()=>{Se=!0}},[ie,t]),d.useEffect(()=>{const Se=X4(e);Se&&t(Se,!0)},[e,t]),d.useEffect(()=>{let Se=!1;const Ee=()=>{Ve.agents().then(me=>{Se||(m(me.agents),iz(me.defaultAgentId??null),g(me.defaultAgentId??null),b(Jn=>{var Ln;return Jn??me.defaultAgentId??((Ln=me.agents[0])==null?void 0:Ln.id)??null}))}).catch(()=>{})};Ee();const Ke=window.setInterval(Ee,15e3);return window.addEventListener("focus",Ee),window.addEventListener(gr,Ee),()=>{Se=!0,window.clearInterval(Ke),window.removeEventListener("focus",Ee),window.removeEventListener(gr,Ee)}},[e]),d.useEffect(()=>{let Se=!1;const Ee=()=>{Ve.groups().then(me=>{Se||x(me.groups)}).catch(()=>{})};Ee();const Ke=window.setInterval(Ee,3e4);return()=>{Se=!0,window.clearInterval(Ke)}},[e]);const ye=yA(f,p),ge=R4(e),$e=cA(e),De=$e?j.find(Se=>Se.id===$e.groupId)??null:null,Je=$e?null:(ge==null?void 0:ge.agentId)??v;d.useEffect(()=>{ge&&b(ge.agentId)},[ge==null?void 0:ge.agentId]);const Ue=d.useRef(null);ge&&(Ue.current=e);const be=Se=>{b(Se),t(st(Se))},Be=Se=>t(Yi(Se)),at=d.useCallback((Se,Ee,Ke=!0)=>t($e?Yi($e.groupId,Ee):st(Se,Ee),Ke),[t,$e==null?void 0:$e.groupId]),[He,kt]=d.useState(!1),[,Yt]=d.useState(0);d.useEffect(()=>{const Se=()=>{Yt(Ee=>Ee+1),$.session().then(Ee=>r(Ee.timezone)).catch(()=>{})};return window.addEventListener(Ig,Se),()=>window.removeEventListener(Ig,Se)},[]),d.useEffect(()=>{$.session().then(Se=>{fj({timeFormat:Se.timeFormat??null,dateFormat:Se.dateFormat??null}),r(Se.timezone),kt(!0)}).catch(()=>{})},[]);const ne=aW(He);dW(He,ne.refresh,()=>kt(!1)),d.useEffect(()=>{const Se=()=>{$.overview().then(Ke=>{var me;return a({approvals:Ke.approvals.pending,failed:Ke.jobs.failed??0,paused:Ke.paused,running:Ke.running??0,needs:((me=Ke.needsYou)==null?void 0:me.total)??Ke.approvals.pending+(Ke.jobs.failed??0)})}).catch(()=>{})};Se();const Ee=window.setInterval(Se,2e4);return window.addEventListener(ta,Se),()=>{window.clearInterval(Ee),window.removeEventListener(ta,Se)}},[]);const ke=de(()=>Promise.resolve().then(()=>$.focus()),[],6e4),Qe=d.useRef(ke.reload);Qe.current=ke.reload,d.useEffect(()=>{const Se=()=>Qe.current();return window.addEventListener(ta,Se),()=>window.removeEventListener(ta,Se)},[]);const ct=aZ(),Nt=eZ(),ut=JI()!==null,xn=Ns(gZ);d.useEffect(()=>{if(!He)return;if(e===Z4){y(!0),t(yi,!0);return}const Se=ez(e),Ee=new Date().toDateString();!Se||WN.get(Se)===Ee||(WN.set(Se,Ee),$.tipsSeenPage(Se).catch(()=>{}))},[e,He,t]);const Yn={link:rZ(window.location.hostname,ct&&!ut),focus:((Cn=ke.data)==null?void 0:Cn.focus)??null,working:i.running,paused:i.paused,failed:i.failed,approvals:i.approvals,version:_?{current:_.current,latest:_.latest,updateAvailable:!_.checkout&&_.updateAvailable}:void 0,timezone:s},Z=GX({recovery:((Ts=B.data)==null?void 0:Ts.active)===!0,lost:Nt&&!ut,paused:i.paused}),Re=xd(e),Xe=pA(e),jt=Xe===yi,G=k?j.find(Se=>Se.id===k.groupId)??null:null,he=Se=>x(Ee=>Ee.map(Ke=>Ke.id===Se.id?Se:Ke)),We=()=>N(null),ze=w?n.jsx(hW,{agents:f,onClose:()=>y(!1),onCreated:Se=>{x(Ee=>[...Ee,Se]),y(!1),t(Yi(Se.id))}}):G&&(k==null?void 0:k.kind)==="members"?n.jsx(F8,{group:G,agents:f,onClose:We,onSaved:he}):G&&(k==null?void 0:k.kind)==="rename"?n.jsx(_8,{group:G,onClose:We,onSaved:Se=>{he(Se),We()}}):G&&(k==null?void 0:k.kind)==="clear"?n.jsx(U8,{group:G,onClose:We,onCleared:()=>{We(),R(Se=>Se+1),t(Yi(G.id),!0)}}):G&&(k==null?void 0:k.kind)==="delete"?n.jsx(B8,{group:G,agents:f,onClose:We,onDeleted:Se=>{const Ee=j.findIndex(Ke=>Ke.id===G.id);We(),x(Ke=>Ke.filter(me=>me.id!==G.id)),C({group:G,index:Ee,until:Se}),t(Ue.current??yi)}}):null,sn=()=>{const Se=S;Se&&(C(null),Ve.restoreGroup(Se.group.id).then(Ee=>{x(Ke=>{if(Ke.some(Jn=>Jn.id===Ee.id))return Ke;const me=[...Ke];return me.splice(Math.min(Math.max(Se.index,0),me.length),0,Ee),me}),t(Yi(Ee.id))}).catch(()=>L(Se.group.name)))};return Re?n.jsx(fk,{delayDuration:400,children:n.jsxs(ek,{swipeDirection:"right",children:[n.jsx(fX,{navigate:t,timezone:s}),n.jsx(tk,{className:"ui-toasts"})]})}):n.jsx(hU,{picture:($s=f.find(Se=>Se.id===p))==null?void 0:$s.picture,children:n.jsx(fk,{delayDuration:400,children:n.jsxs(ek,{swipeDirection:"right",children:[ze,n.jsxs("div",{className:"wb-shell",children:[n.jsx(qX,{banners:Z,onNavigate:t}),n.jsxs("div",{className:"wb",children:[n.jsx(f9,{attention:i.needs,place:Xe,onNavigate:t,theme:l,onTheme:o,plugins:k9(Y.rail,W),updateAvailable:X!==null,settingsDot:ee.length>0?C$:void 0,stale:Q,timezone:s,version:_&&!_.checkout?{current:_.current,latest:_.latest,updateAvailable:_.updateAvailable}:_?{current:_.current,updateAvailable:!1}:void 0,status:xn?n.jsx(oZ,{status:Yn,onNavigate:t}):void 0}),jt&&!H?n.jsx(CA,{agents:ye,currentId:Je,attention:F,onSelect:be,lastActivity:_e,working:Ie,groups:j,currentGroupId:(De==null?void 0:De.id)??null,onSelectGroup:Be,onNewGroup:()=>y(!0)}):null,jt?n.jsx(W8,{timezone:s,agents:ye,agentId:De?De.coordinator:Je,defaultAgentId:p,group:De,...De?{onGroupAction:Se=>N({kind:Se,groupId:De.id})}:{},requestedConversationId:($e==null?void 0:$e.conversationId)??(ge==null?void 0:ge.conversationId),requestedTab:ge==null?void 0:ge.tab,onConversationOpened:at,onSelectAgent:be,onWorking:Le,attention:F,agentsInHeader:H,narrow:c,canvasOpen:u,onOpenCanvas:()=>h(!0),onCloseCanvas:()=>h(!1)},`room-${E}`):n.jsx("main",{"data-ground":wZ(Xe,e)?"plain":void 0,"data-layout":Xe===ln?"split":void 0,children:n.jsx(yZ,{hash:e,place:Xe,timezone:s,navigate:t,agents:f,defaultAgentId:p,attention:F,pluginPages:Y,update:X,connectionSignals:ee})})]}),xn?null:n.jsx(lZ,{status:Yn,onNavigate:t})]}),M&&T?n.jsx(X8,{agent:T,agents:f,open:P,onOpenChange:D,navigate:t}):null,n.jsxs(rW,{placement:sW(M,P),children:[n.jsx(lW,{queue:ne.queue,agents:f,navigate:t,onDismiss:ne.dismiss}),S?n.jsx(ph,{title:`Deleted ${S.group.name}`,body:"Its history goes for good in a few seconds.",duration:mW,onUndo:sn,onGone:()=>C(null)},S.group.id):null,I?n.jsx(ph,{title:`${I} is gone for good`,body:"Undo came too late to bring it back.",duration:6e3,onGone:()=>L(null)},`late-${I}`):null,n.jsx(tk,{className:"ui-toasts"})]})]})})})}function wZ(e,t){return Ij(t)!==null}function yZ({place:e,pluginPages:t,...s}){const r={...s,pluginPages:t},i=Ij(s.hash);if(i){const a=t.find(i.plugin,i.page);if(a)return n.jsx(vw,{page:a,item:i.item??null,params:Pj(s.hash),navigate:s.navigate,timezone:s.timezone,siblings:t.all.filter(l=>l.plugin===i.plugin)});if(t.all.length===0)return n.jsx(n.Fragment,{})}switch(e){case pt:return n.jsx(sG,{...r});case yt:return n.jsx(H9,{...s});case ln:return n.jsx(OQ,{...r});case qr:return n.jsx(KH,{...s});default:return n.jsx(MG,{...r})}}function bZ(){"serviceWorker"in navigator&&window.addEventListener("load",()=>{const e=`./sw.js?v=${encodeURIComponent(Lj)}`;navigator.serviceWorker.register(e,{scope:"./"}).catch(()=>{})})}function kZ({search:e=location.search}){const[t,s]=d.useState(null),r=d.useRef(!1);return d.useEffect(()=>{if(r.current)return;r.current=!0;const i=new URLSearchParams(e);try{history.replaceState(null,"",location.pathname)}catch{}const a=i.get("state")??"",l=i.get("code")??void 0,o=i.get("error")??void 0;$.connectionCallback({state:a,...l?{code:l}:{},...o?{error:o}:{}}).then(c=>{s({ok:!0,name:c.name,cli:c.cli===!0});try{const u=new BroadcastChannel(cR);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]),n.jsx("main",{className:"ui-page connections-callback",children:n.jsxs(le,{gap:"lg",children:[n.jsx("h2",{className:"ui-page-title",children:"Connections"}),t===null?n.jsx(V,{tone:"accent",role:"status",children:"Finishing the sign-in…"}):null,t!=null&&t.ok?n.jsxs(V,{tone:"good",role:"status",title:`Signed in to ${t.name}`,children:["buddi keeps the sign-in in its vault. You can close this tab; ",t.cli?"the terminal carries on.":"the other one carries on."]}):null,t&&!t.ok?n.jsx(V,{tone:"critical",role:"alert",title:"Nothing was connected",children:t.message}):null,t?n.jsx(dt,{href:"/#/settings/connections",children:"Back to Connections"}):null]})})}const HN=document.getElementById("root");HN&&s1(HN).render(n.jsx(d.StrictMode,{children:location.pathname==="/connections/callback"?n.jsx(kZ,{}):n.jsx(mZ,{children:n.jsx(XX,{children:n.jsx(h9,{children:n.jsx(jZ,{})})})})}));bZ();export{SZ as c,fP as g};