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

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 (832) hide show
  1. package/examples/agents/concierge/agent.md +5 -0
  2. package/examples/skills/letterhead/SKILL.md +21 -0
  3. package/examples/skills/letterhead/assets/letterhead.md +16 -0
  4. package/examples/skills/letterhead/assets/logo.svg +6 -0
  5. package/extension/manifest.json +2 -2
  6. package/node_modules/@buddi/cli/dist/.tsbuildinfo +1 -1
  7. package/node_modules/@buddi/cli/dist/doctor-probes.d.ts.map +1 -1
  8. package/node_modules/@buddi/cli/dist/doctor-probes.js +44 -3
  9. package/node_modules/@buddi/cli/dist/doctor-probes.js.map +1 -1
  10. package/node_modules/@buddi/cli/dist/doctor.d.ts +37 -0
  11. package/node_modules/@buddi/cli/dist/doctor.d.ts.map +1 -1
  12. package/node_modules/@buddi/cli/dist/doctor.js +37 -0
  13. package/node_modules/@buddi/cli/dist/doctor.js.map +1 -1
  14. package/node_modules/@buddi/core/dist/.tsbuildinfo +1 -1
  15. package/node_modules/@buddi/core/dist/actions/approvals.d.ts +7 -0
  16. package/node_modules/@buddi/core/dist/actions/approvals.d.ts.map +1 -1
  17. package/node_modules/@buddi/core/dist/actions/approvals.js +11 -1
  18. package/node_modules/@buddi/core/dist/actions/approvals.js.map +1 -1
  19. package/node_modules/@buddi/core/dist/agents/catalog.d.ts.map +1 -1
  20. package/node_modules/@buddi/core/dist/agents/catalog.js +2 -2
  21. package/node_modules/@buddi/core/dist/agents/catalog.js.map +1 -1
  22. package/node_modules/@buddi/core/dist/agents/skills.d.ts +60 -1
  23. package/node_modules/@buddi/core/dist/agents/skills.d.ts.map +1 -1
  24. package/node_modules/@buddi/core/dist/agents/skills.js +157 -17
  25. package/node_modules/@buddi/core/dist/agents/skills.js.map +1 -1
  26. package/node_modules/@buddi/core/dist/day-month.d.ts +52 -0
  27. package/node_modules/@buddi/core/dist/day-month.d.ts.map +1 -0
  28. package/node_modules/@buddi/core/dist/day-month.js +101 -0
  29. package/node_modules/@buddi/core/dist/day-month.js.map +1 -0
  30. package/node_modules/@buddi/core/dist/host/build.d.ts +25 -2
  31. package/node_modules/@buddi/core/dist/host/build.d.ts.map +1 -1
  32. package/node_modules/@buddi/core/dist/host/build.js +169 -8
  33. package/node_modules/@buddi/core/dist/host/build.js.map +1 -1
  34. package/node_modules/@buddi/core/dist/host/http.d.ts +97 -0
  35. package/node_modules/@buddi/core/dist/host/http.d.ts.map +1 -1
  36. package/node_modules/@buddi/core/dist/host/http.js +321 -26
  37. package/node_modules/@buddi/core/dist/host/http.js.map +1 -1
  38. package/node_modules/@buddi/core/dist/host/types.d.ts +114 -4
  39. package/node_modules/@buddi/core/dist/host/types.d.ts.map +1 -1
  40. package/node_modules/@buddi/core/dist/index.d.ts +3 -0
  41. package/node_modules/@buddi/core/dist/index.d.ts.map +1 -1
  42. package/node_modules/@buddi/core/dist/index.js +3 -0
  43. package/node_modules/@buddi/core/dist/index.js.map +1 -1
  44. package/node_modules/@buddi/core/dist/notifications/notify.d.ts.map +1 -1
  45. package/node_modules/@buddi/core/dist/notifications/notify.js +10 -6
  46. package/node_modules/@buddi/core/dist/notifications/notify.js.map +1 -1
  47. package/node_modules/@buddi/core/dist/notifications/store.d.ts.map +1 -1
  48. package/node_modules/@buddi/core/dist/notifications/store.js +2 -1
  49. package/node_modules/@buddi/core/dist/notifications/store.js.map +1 -1
  50. package/node_modules/@buddi/core/dist/notifications/types.d.ts +8 -0
  51. package/node_modules/@buddi/core/dist/notifications/types.d.ts.map +1 -1
  52. package/node_modules/@buddi/core/dist/notifications/types.js.map +1 -1
  53. package/node_modules/@buddi/core/dist/onboarding/store.d.ts.map +1 -1
  54. package/node_modules/@buddi/core/dist/onboarding/store.js +28 -5
  55. package/node_modules/@buddi/core/dist/onboarding/store.js.map +1 -1
  56. package/node_modules/@buddi/core/dist/onboarding/types.d.ts +10 -0
  57. package/node_modules/@buddi/core/dist/onboarding/types.d.ts.map +1 -1
  58. package/node_modules/@buddi/core/dist/onboarding/types.js.map +1 -1
  59. package/node_modules/@buddi/core/dist/pages.d.ts +449 -20
  60. package/node_modules/@buddi/core/dist/pages.d.ts.map +1 -1
  61. package/node_modules/@buddi/core/dist/pages.js +223 -8
  62. package/node_modules/@buddi/core/dist/pages.js.map +1 -1
  63. package/node_modules/@buddi/core/dist/plugin/assets.d.ts +52 -0
  64. package/node_modules/@buddi/core/dist/plugin/assets.d.ts.map +1 -0
  65. package/node_modules/@buddi/core/dist/plugin/assets.js +59 -0
  66. package/node_modules/@buddi/core/dist/plugin/assets.js.map +1 -0
  67. package/node_modules/@buddi/core/dist/plugin/index.d.ts +10 -4
  68. package/node_modules/@buddi/core/dist/plugin/index.d.ts.map +1 -1
  69. package/node_modules/@buddi/core/dist/plugin/index.js +4 -1
  70. package/node_modules/@buddi/core/dist/plugin/index.js.map +1 -1
  71. package/node_modules/@buddi/core/dist/plugin/requires.d.ts +3 -1
  72. package/node_modules/@buddi/core/dist/plugin/requires.d.ts.map +1 -1
  73. package/node_modules/@buddi/core/dist/plugin/requires.js +5 -3
  74. package/node_modules/@buddi/core/dist/plugin/requires.js.map +1 -1
  75. package/node_modules/@buddi/core/dist/plugin/sign-in.d.ts +78 -0
  76. package/node_modules/@buddi/core/dist/plugin/sign-in.d.ts.map +1 -0
  77. package/node_modules/@buddi/core/dist/plugin/sign-in.js +54 -0
  78. package/node_modules/@buddi/core/dist/plugin/sign-in.js.map +1 -0
  79. package/node_modules/@buddi/core/dist/plugin/uses.d.ts +1 -1
  80. package/node_modules/@buddi/core/dist/plugin/uses.d.ts.map +1 -1
  81. package/node_modules/@buddi/core/dist/plugin/uses.js +2 -0
  82. package/node_modules/@buddi/core/dist/plugin/uses.js.map +1 -1
  83. package/node_modules/@buddi/core/dist/plugin/version.d.ts +1 -1
  84. package/node_modules/@buddi/core/dist/plugin/version.js +1 -1
  85. package/node_modules/@buddi/core/dist/plugin-assets.d.ts +21 -0
  86. package/node_modules/@buddi/core/dist/plugin-assets.d.ts.map +1 -0
  87. package/node_modules/@buddi/core/dist/plugin-assets.js +140 -0
  88. package/node_modules/@buddi/core/dist/plugin-assets.js.map +1 -0
  89. package/node_modules/@buddi/core/dist/provider-accounts.d.ts +7 -0
  90. package/node_modules/@buddi/core/dist/provider-accounts.d.ts.map +1 -1
  91. package/node_modules/@buddi/core/dist/provider-accounts.js +15 -0
  92. package/node_modules/@buddi/core/dist/provider-accounts.js.map +1 -1
  93. package/node_modules/@buddi/core/dist/questions/types.d.ts +1 -1
  94. package/node_modules/@buddi/core/dist/questions/types.js +1 -1
  95. package/node_modules/@buddi/core/dist/queue/jobs.d.ts +57 -2
  96. package/node_modules/@buddi/core/dist/queue/jobs.d.ts.map +1 -1
  97. package/node_modules/@buddi/core/dist/queue/jobs.js +114 -0
  98. package/node_modules/@buddi/core/dist/queue/jobs.js.map +1 -1
  99. package/node_modules/@buddi/core/dist/queue/worker.d.ts +24 -2
  100. package/node_modules/@buddi/core/dist/queue/worker.d.ts.map +1 -1
  101. package/node_modules/@buddi/core/dist/queue/worker.js +66 -11
  102. package/node_modules/@buddi/core/dist/queue/worker.js.map +1 -1
  103. package/node_modules/@buddi/core/dist/registry.d.ts +17 -0
  104. package/node_modules/@buddi/core/dist/registry.d.ts.map +1 -1
  105. package/node_modules/@buddi/core/dist/registry.js +48 -4
  106. package/node_modules/@buddi/core/dist/registry.js.map +1 -1
  107. package/node_modules/@buddi/core/dist/scheduler/missions.d.ts +14 -0
  108. package/node_modules/@buddi/core/dist/scheduler/missions.d.ts.map +1 -1
  109. package/node_modules/@buddi/core/dist/scheduler/missions.js +17 -4
  110. package/node_modules/@buddi/core/dist/scheduler/missions.js.map +1 -1
  111. package/node_modules/@buddi/core/dist/scheduler/types.d.ts +13 -0
  112. package/node_modules/@buddi/core/dist/scheduler/types.d.ts.map +1 -1
  113. package/node_modules/@buddi/core/dist/scheduler/types.js +14 -0
  114. package/node_modules/@buddi/core/dist/scheduler/types.js.map +1 -1
  115. package/node_modules/@buddi/core/dist/secrets/scrub.d.ts.map +1 -1
  116. package/node_modules/@buddi/core/dist/secrets/scrub.js +15 -0
  117. package/node_modules/@buddi/core/dist/secrets/scrub.js.map +1 -1
  118. package/node_modules/@buddi/core/dist/surfaces.d.ts +10 -0
  119. package/node_modules/@buddi/core/dist/surfaces.d.ts.map +1 -1
  120. package/node_modules/@buddi/core/dist/surfaces.js +11 -0
  121. package/node_modules/@buddi/core/dist/surfaces.js.map +1 -1
  122. package/node_modules/@buddi/core/dist/tools.d.ts +72 -1
  123. package/node_modules/@buddi/core/dist/tools.d.ts.map +1 -1
  124. package/node_modules/@buddi/core/dist/tools.js +38 -0
  125. package/node_modules/@buddi/core/dist/tools.js.map +1 -1
  126. package/node_modules/@buddi/core/dist/views.d.ts +29 -12
  127. package/node_modules/@buddi/core/dist/views.d.ts.map +1 -1
  128. package/node_modules/@buddi/core/dist/views.js +1 -0
  129. package/node_modules/@buddi/core/dist/views.js.map +1 -1
  130. package/node_modules/@buddi/core/dist/widget-settings.d.ts +2 -1
  131. package/node_modules/@buddi/core/dist/widget-settings.d.ts.map +1 -1
  132. package/node_modules/@buddi/core/dist/widget-settings.js +8 -2
  133. package/node_modules/@buddi/core/dist/widget-settings.js.map +1 -1
  134. package/node_modules/@buddi/core/dist/widgets.d.ts +46 -3
  135. package/node_modules/@buddi/core/dist/widgets.d.ts.map +1 -1
  136. package/node_modules/@buddi/core/dist/widgets.js +68 -5
  137. package/node_modules/@buddi/core/dist/widgets.js.map +1 -1
  138. package/node_modules/@buddi/core/migrations/073_mission_report.sql +15 -0
  139. package/node_modules/@buddi/core/migrations/074_owner_identity.sql +14 -0
  140. package/node_modules/@buddi/gateway/dist/.tsbuildinfo +1 -1
  141. package/node_modules/@buddi/gateway/dist/agents/catalog.d.ts.map +1 -1
  142. package/node_modules/@buddi/gateway/dist/agents/catalog.js +3 -3
  143. package/node_modules/@buddi/gateway/dist/agents/catalog.js.map +1 -1
  144. package/node_modules/@buddi/gateway/dist/agents/catalogue-package.d.ts +76 -0
  145. package/node_modules/@buddi/gateway/dist/agents/catalogue-package.d.ts.map +1 -1
  146. package/node_modules/@buddi/gateway/dist/agents/catalogue-package.js +29 -5
  147. package/node_modules/@buddi/gateway/dist/agents/catalogue-package.js.map +1 -1
  148. package/node_modules/@buddi/gateway/dist/agents/owner-text.d.ts +19 -0
  149. package/node_modules/@buddi/gateway/dist/agents/owner-text.d.ts.map +1 -0
  150. package/node_modules/@buddi/gateway/dist/agents/owner-text.js +44 -0
  151. package/node_modules/@buddi/gateway/dist/agents/owner-text.js.map +1 -0
  152. package/node_modules/@buddi/gateway/dist/agents/owner-tools.d.ts.map +1 -1
  153. package/node_modules/@buddi/gateway/dist/agents/owner-tools.js +36 -2
  154. package/node_modules/@buddi/gateway/dist/agents/owner-tools.js.map +1 -1
  155. package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.d.ts +68 -3
  156. package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.d.ts.map +1 -1
  157. package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.js +264 -32
  158. package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.js.map +1 -1
  159. package/node_modules/@buddi/gateway/dist/agents/platform.d.ts +11 -4
  160. package/node_modules/@buddi/gateway/dist/agents/platform.d.ts.map +1 -1
  161. package/node_modules/@buddi/gateway/dist/agents/platform.js +15 -0
  162. package/node_modules/@buddi/gateway/dist/agents/platform.js.map +1 -1
  163. package/node_modules/@buddi/gateway/dist/bootstrap.d.ts.map +1 -1
  164. package/node_modules/@buddi/gateway/dist/bootstrap.js +7 -1
  165. package/node_modules/@buddi/gateway/dist/bootstrap.js.map +1 -1
  166. package/node_modules/@buddi/gateway/dist/evals/golden.d.ts +33 -1
  167. package/node_modules/@buddi/gateway/dist/evals/golden.d.ts.map +1 -1
  168. package/node_modules/@buddi/gateway/dist/evals/golden.js +168 -3
  169. package/node_modules/@buddi/gateway/dist/evals/golden.js.map +1 -1
  170. package/node_modules/@buddi/gateway/dist/index.d.ts +2 -1
  171. package/node_modules/@buddi/gateway/dist/index.d.ts.map +1 -1
  172. package/node_modules/@buddi/gateway/dist/index.js +2 -1
  173. package/node_modules/@buddi/gateway/dist/index.js.map +1 -1
  174. package/node_modules/@buddi/gateway/dist/missions/agent-run.d.ts.map +1 -1
  175. package/node_modules/@buddi/gateway/dist/missions/agent-run.js +2 -0
  176. package/node_modules/@buddi/gateway/dist/missions/agent-run.js.map +1 -1
  177. package/node_modules/@buddi/gateway/dist/missions/dates.d.ts +98 -0
  178. package/node_modules/@buddi/gateway/dist/missions/dates.d.ts.map +1 -0
  179. package/node_modules/@buddi/gateway/dist/missions/dates.js +252 -0
  180. package/node_modules/@buddi/gateway/dist/missions/dates.js.map +1 -0
  181. package/node_modules/@buddi/gateway/dist/missions/defaults.d.ts.map +1 -1
  182. package/node_modules/@buddi/gateway/dist/missions/defaults.js +2 -0
  183. package/node_modules/@buddi/gateway/dist/missions/defaults.js.map +1 -1
  184. package/node_modules/@buddi/gateway/dist/missions/execute.d.ts +25 -1
  185. package/node_modules/@buddi/gateway/dist/missions/execute.d.ts.map +1 -1
  186. package/node_modules/@buddi/gateway/dist/missions/execute.js +80 -8
  187. package/node_modules/@buddi/gateway/dist/missions/execute.js.map +1 -1
  188. package/node_modules/@buddi/gateway/dist/missions/report.d.ts +25 -2
  189. package/node_modules/@buddi/gateway/dist/missions/report.d.ts.map +1 -1
  190. package/node_modules/@buddi/gateway/dist/missions/report.js +71 -11
  191. package/node_modules/@buddi/gateway/dist/missions/report.js.map +1 -1
  192. package/node_modules/@buddi/gateway/dist/ollama-local.d.ts +90 -0
  193. package/node_modules/@buddi/gateway/dist/ollama-local.d.ts.map +1 -0
  194. package/node_modules/@buddi/gateway/dist/ollama-local.js +201 -0
  195. package/node_modules/@buddi/gateway/dist/ollama-local.js.map +1 -0
  196. package/node_modules/@buddi/gateway/dist/owner-notify.d.ts.map +1 -1
  197. package/node_modules/@buddi/gateway/dist/owner-notify.js +7 -3
  198. package/node_modules/@buddi/gateway/dist/owner-notify.js.map +1 -1
  199. package/node_modules/@buddi/gateway/dist/plugins/asset-image-worker.d.ts +2 -0
  200. package/node_modules/@buddi/gateway/dist/plugins/asset-image-worker.d.ts.map +1 -0
  201. package/node_modules/@buddi/gateway/dist/plugins/asset-image-worker.js +18 -0
  202. package/node_modules/@buddi/gateway/dist/plugins/asset-image-worker.js.map +1 -0
  203. package/node_modules/@buddi/gateway/dist/plugins/asset-image.d.ts +31 -0
  204. package/node_modules/@buddi/gateway/dist/plugins/asset-image.d.ts.map +1 -0
  205. package/node_modules/@buddi/gateway/dist/plugins/asset-image.js +332 -0
  206. package/node_modules/@buddi/gateway/dist/plugins/asset-image.js.map +1 -0
  207. package/node_modules/@buddi/gateway/dist/plugins/load.d.ts.map +1 -1
  208. package/node_modules/@buddi/gateway/dist/plugins/load.js +14 -1
  209. package/node_modules/@buddi/gateway/dist/plugins/load.js.map +1 -1
  210. package/node_modules/@buddi/gateway/dist/plugins/stage.d.ts +6 -0
  211. package/node_modules/@buddi/gateway/dist/plugins/stage.d.ts.map +1 -1
  212. package/node_modules/@buddi/gateway/dist/plugins/stage.js +5 -0
  213. package/node_modules/@buddi/gateway/dist/plugins/stage.js.map +1 -1
  214. package/node_modules/@buddi/gateway/dist/plugins/uninstall.d.ts.map +1 -1
  215. package/node_modules/@buddi/gateway/dist/plugins/uninstall.js +8 -0
  216. package/node_modules/@buddi/gateway/dist/plugins/uninstall.js.map +1 -1
  217. package/node_modules/@buddi/gateway/dist/plugins-cli.d.ts +8 -0
  218. package/node_modules/@buddi/gateway/dist/plugins-cli.d.ts.map +1 -1
  219. package/node_modules/@buddi/gateway/dist/plugins-cli.js +22 -1
  220. package/node_modules/@buddi/gateway/dist/plugins-cli.js.map +1 -1
  221. package/node_modules/@buddi/gateway/dist/serve.d.ts.map +1 -1
  222. package/node_modules/@buddi/gateway/dist/serve.js +50 -5
  223. package/node_modules/@buddi/gateway/dist/serve.js.map +1 -1
  224. package/node_modules/@buddi/gateway/dist/surfaces/pending-question.js +2 -2
  225. package/node_modules/@buddi/gateway/dist/system-context.d.ts +21 -1
  226. package/node_modules/@buddi/gateway/dist/system-context.d.ts.map +1 -1
  227. package/node_modules/@buddi/gateway/dist/system-context.js +76 -2
  228. package/node_modules/@buddi/gateway/dist/system-context.js.map +1 -1
  229. package/node_modules/@buddi/gateway/dist/telegram/approvals.d.ts.map +1 -1
  230. package/node_modules/@buddi/gateway/dist/telegram/approvals.js +4 -2
  231. package/node_modules/@buddi/gateway/dist/telegram/approvals.js.map +1 -1
  232. package/node_modules/@buddi/gateway/dist/telegram/channel.d.ts +12 -0
  233. package/node_modules/@buddi/gateway/dist/telegram/channel.d.ts.map +1 -1
  234. package/node_modules/@buddi/gateway/dist/telegram/channel.js +49 -2
  235. package/node_modules/@buddi/gateway/dist/telegram/channel.js.map +1 -1
  236. package/node_modules/@buddi/gateway/dist/telegram/html.d.ts +34 -0
  237. package/node_modules/@buddi/gateway/dist/telegram/html.d.ts.map +1 -0
  238. package/node_modules/@buddi/gateway/dist/telegram/html.js +263 -0
  239. package/node_modules/@buddi/gateway/dist/telegram/html.js.map +1 -0
  240. package/node_modules/@buddi/gateway/dist/telegram/notify.d.ts +6 -0
  241. package/node_modules/@buddi/gateway/dist/telegram/notify.d.ts.map +1 -1
  242. package/node_modules/@buddi/gateway/dist/telegram/notify.js +25 -3
  243. package/node_modules/@buddi/gateway/dist/telegram/notify.js.map +1 -1
  244. package/node_modules/@buddi/gateway/dist/tips/facts.d.ts +2 -0
  245. package/node_modules/@buddi/gateway/dist/tips/facts.d.ts.map +1 -1
  246. package/node_modules/@buddi/gateway/dist/tips/facts.js +4 -1
  247. package/node_modules/@buddi/gateway/dist/tips/facts.js.map +1 -1
  248. package/node_modules/@buddi/gateway/dist/tips/rules.d.ts.map +1 -1
  249. package/node_modules/@buddi/gateway/dist/tips/rules.js +10 -0
  250. package/node_modules/@buddi/gateway/dist/tips/rules.js.map +1 -1
  251. package/node_modules/@buddi/gateway/dist/web/api-routes.d.ts.map +1 -1
  252. package/node_modules/@buddi/gateway/dist/web/api-routes.js +80 -11
  253. package/node_modules/@buddi/gateway/dist/web/api-routes.js.map +1 -1
  254. package/node_modules/@buddi/gateway/dist/web/api-scan.d.ts +1 -1
  255. package/node_modules/@buddi/gateway/dist/web/api-scan.d.ts.map +1 -1
  256. package/node_modules/@buddi/gateway/dist/web/api-scan.js +1 -0
  257. package/node_modules/@buddi/gateway/dist/web/api-scan.js.map +1 -1
  258. package/node_modules/@buddi/gateway/dist/web/catalogue.d.ts.map +1 -1
  259. package/node_modules/@buddi/gateway/dist/web/catalogue.js +7 -4
  260. package/node_modules/@buddi/gateway/dist/web/catalogue.js.map +1 -1
  261. package/node_modules/@buddi/gateway/dist/web/chat.d.ts.map +1 -1
  262. package/node_modules/@buddi/gateway/dist/web/chat.js +9 -0
  263. package/node_modules/@buddi/gateway/dist/web/chat.js.map +1 -1
  264. package/node_modules/@buddi/gateway/dist/web/composer.d.ts +45 -0
  265. package/node_modules/@buddi/gateway/dist/web/composer.d.ts.map +1 -0
  266. package/node_modules/@buddi/gateway/dist/web/composer.js +85 -0
  267. package/node_modules/@buddi/gateway/dist/web/composer.js.map +1 -0
  268. package/node_modules/@buddi/gateway/dist/web/extension.d.ts +12 -0
  269. package/node_modules/@buddi/gateway/dist/web/extension.d.ts.map +1 -1
  270. package/node_modules/@buddi/gateway/dist/web/extension.js +11 -1
  271. package/node_modules/@buddi/gateway/dist/web/extension.js.map +1 -1
  272. package/node_modules/@buddi/gateway/dist/web/lock.d.ts +6 -0
  273. package/node_modules/@buddi/gateway/dist/web/lock.d.ts.map +1 -1
  274. package/node_modules/@buddi/gateway/dist/web/lock.js +33 -2
  275. package/node_modules/@buddi/gateway/dist/web/lock.js.map +1 -1
  276. package/node_modules/@buddi/gateway/dist/web/market.d.ts +20 -1
  277. package/node_modules/@buddi/gateway/dist/web/market.d.ts.map +1 -1
  278. package/node_modules/@buddi/gateway/dist/web/market.js +41 -1
  279. package/node_modules/@buddi/gateway/dist/web/market.js.map +1 -1
  280. package/node_modules/@buddi/gateway/dist/web/people.d.ts +44 -0
  281. package/node_modules/@buddi/gateway/dist/web/people.d.ts.map +1 -0
  282. package/node_modules/@buddi/gateway/dist/web/people.js +114 -0
  283. package/node_modules/@buddi/gateway/dist/web/people.js.map +1 -0
  284. package/node_modules/@buddi/gateway/dist/web/server.d.ts +4 -0
  285. package/node_modules/@buddi/gateway/dist/web/server.d.ts.map +1 -1
  286. package/node_modules/@buddi/gateway/dist/web/server.js +171 -13
  287. package/node_modules/@buddi/gateway/dist/web/server.js.map +1 -1
  288. package/node_modules/@buddi/gateway/dist/web/skill-bundles.d.ts +101 -0
  289. package/node_modules/@buddi/gateway/dist/web/skill-bundles.d.ts.map +1 -0
  290. package/node_modules/@buddi/gateway/dist/web/skill-bundles.js +439 -0
  291. package/node_modules/@buddi/gateway/dist/web/skill-bundles.js.map +1 -0
  292. package/node_modules/@buddi/gateway/dist/web/skills.d.ts +57 -1
  293. package/node_modules/@buddi/gateway/dist/web/skills.d.ts.map +1 -1
  294. package/node_modules/@buddi/gateway/dist/web/skills.js +171 -9
  295. package/node_modules/@buddi/gateway/dist/web/skills.js.map +1 -1
  296. package/node_modules/@buddi/gateway/dist/web/widgets.js +2 -2
  297. package/node_modules/@buddi/gateway/dist/web/widgets.js.map +1 -1
  298. package/node_modules/@buddi/gateway/dist/web/zip-read.d.ts +31 -0
  299. package/node_modules/@buddi/gateway/dist/web/zip-read.d.ts.map +1 -0
  300. package/node_modules/@buddi/gateway/dist/web/zip-read.js +125 -0
  301. package/node_modules/@buddi/gateway/dist/web/zip-read.js.map +1 -0
  302. package/node_modules/@buddi/install/dist/.tsbuildinfo +1 -1
  303. package/node_modules/@buddi/runtime/dist/.tsbuildinfo +1 -1
  304. package/node_modules/@buddi/runtime/dist/index.d.ts +1 -0
  305. package/node_modules/@buddi/runtime/dist/index.d.ts.map +1 -1
  306. package/node_modules/@buddi/runtime/dist/index.js +1 -0
  307. package/node_modules/@buddi/runtime/dist/index.js.map +1 -1
  308. package/node_modules/@buddi/runtime/dist/loop.js +11 -1
  309. package/node_modules/@buddi/runtime/dist/loop.js.map +1 -1
  310. package/node_modules/@buddi/runtime/dist/plugin-sign-in.d.ts +12 -0
  311. package/node_modules/@buddi/runtime/dist/plugin-sign-in.d.ts.map +1 -0
  312. package/node_modules/@buddi/runtime/dist/plugin-sign-in.js +397 -0
  313. package/node_modules/@buddi/runtime/dist/plugin-sign-in.js.map +1 -0
  314. package/node_modules/@buddi/runtime/dist/transport.d.ts +1 -1
  315. package/node_modules/@buddi/runtime/dist/transport.d.ts.map +1 -1
  316. package/node_modules/@buddi/runtime/dist/transport.js +6 -0
  317. package/node_modules/@buddi/runtime/dist/transport.js.map +1 -1
  318. package/node_modules/@buddi/tool-artifacts/dist/.tsbuildinfo +1 -1
  319. package/node_modules/@buddi/tool-artifacts/dist/tools/write.d.ts.map +1 -1
  320. package/node_modules/@buddi/tool-artifacts/dist/tools/write.js +1 -0
  321. package/node_modules/@buddi/tool-artifacts/dist/tools/write.js.map +1 -1
  322. package/node_modules/@buddi/tool-browser/dist/.tsbuildinfo +1 -1
  323. package/node_modules/@buddi/tool-browser/dist/computer.d.ts +13 -0
  324. package/node_modules/@buddi/tool-browser/dist/computer.d.ts.map +1 -1
  325. package/node_modules/@buddi/tool-browser/dist/computer.js +22 -2
  326. package/node_modules/@buddi/tool-browser/dist/computer.js.map +1 -1
  327. package/node_modules/@buddi/tool-browser/dist/controller.d.ts +4 -0
  328. package/node_modules/@buddi/tool-browser/dist/controller.d.ts.map +1 -1
  329. package/node_modules/@buddi/tool-browser/dist/controller.js +8 -3
  330. package/node_modules/@buddi/tool-browser/dist/controller.js.map +1 -1
  331. package/node_modules/@buddi/tool-browser/dist/index.d.ts +1 -1
  332. package/node_modules/@buddi/tool-browser/dist/index.d.ts.map +1 -1
  333. package/node_modules/@buddi/tool-browser/dist/index.js +1 -1
  334. package/node_modules/@buddi/tool-browser/dist/index.js.map +1 -1
  335. package/node_modules/@buddi/tool-browser/dist/native/buddi-computer +0 -0
  336. package/node_modules/@buddi/tool-browser/dist/service.d.ts +5 -0
  337. package/node_modules/@buddi/tool-browser/dist/service.d.ts.map +1 -1
  338. package/node_modules/@buddi/tool-browser/dist/service.js.map +1 -1
  339. package/node_modules/@buddi/tool-email/dist/.tsbuildinfo +1 -1
  340. package/node_modules/@buddi/tool-email/dist/widgets.d.ts.map +1 -1
  341. package/node_modules/@buddi/tool-email/dist/widgets.js +2 -1
  342. package/node_modules/@buddi/tool-email/dist/widgets.js.map +1 -1
  343. package/node_modules/@buddi/tool-host/dist/.tsbuildinfo +1 -1
  344. package/node_modules/@buddi/tool-host/dist/index.d.ts +2 -1
  345. package/node_modules/@buddi/tool-host/dist/index.d.ts.map +1 -1
  346. package/node_modules/@buddi/tool-host/dist/index.js +3 -2
  347. package/node_modules/@buddi/tool-host/dist/index.js.map +1 -1
  348. package/node_modules/@buddi/tool-host/dist/process.d.ts +4 -0
  349. package/node_modules/@buddi/tool-host/dist/process.d.ts.map +1 -1
  350. package/node_modules/@buddi/tool-host/dist/process.js +4 -2
  351. package/node_modules/@buddi/tool-host/dist/process.js.map +1 -1
  352. package/node_modules/@buddi/tool-host/dist/service.d.ts +66 -17
  353. package/node_modules/@buddi/tool-host/dist/service.d.ts.map +1 -1
  354. package/node_modules/@buddi/tool-host/dist/service.js +172 -9
  355. package/node_modules/@buddi/tool-host/dist/service.js.map +1 -1
  356. package/node_modules/@buddi/tool-host/dist/skill-run.d.ts +55 -0
  357. package/node_modules/@buddi/tool-host/dist/skill-run.d.ts.map +1 -0
  358. package/node_modules/@buddi/tool-host/dist/skill-run.js +132 -0
  359. package/node_modules/@buddi/tool-host/dist/skill-run.js.map +1 -0
  360. package/node_modules/@buddi/tool-mcp/dist/.tsbuildinfo +1 -1
  361. package/node_modules/@buddi/tool-memory/dist/.tsbuildinfo +1 -1
  362. package/node_modules/@buddi/tool-memory/dist/index.d.ts +1 -0
  363. package/node_modules/@buddi/tool-memory/dist/index.d.ts.map +1 -1
  364. package/node_modules/@buddi/tool-memory/dist/index.js +7 -2
  365. package/node_modules/@buddi/tool-memory/dist/index.js.map +1 -1
  366. package/node_modules/@buddi/tool-memory/dist/people.d.ts +218 -0
  367. package/node_modules/@buddi/tool-memory/dist/people.d.ts.map +1 -0
  368. package/node_modules/@buddi/tool-memory/dist/people.js +582 -0
  369. package/node_modules/@buddi/tool-memory/dist/people.js.map +1 -0
  370. package/node_modules/@buddi/tool-memory/dist/preamble.d.ts +4 -1
  371. package/node_modules/@buddi/tool-memory/dist/preamble.d.ts.map +1 -1
  372. package/node_modules/@buddi/tool-memory/dist/preamble.js +25 -7
  373. package/node_modules/@buddi/tool-memory/dist/preamble.js.map +1 -1
  374. package/node_modules/@buddi/tool-memory/migrations/002_people.sql +40 -0
  375. package/node_modules/@buddi/tool-web/dist/.tsbuildinfo +1 -1
  376. package/node_modules/imapflow/CHANGELOG.md +8 -0
  377. package/node_modules/imapflow/dist/cjs/commands/append.js +27 -3
  378. package/node_modules/imapflow/dist/cjs/commands/store.js +31 -6
  379. package/node_modules/imapflow/dist/cjs/imap-flow.d.ts +1 -1
  380. package/node_modules/imapflow/dist/cjs/imap-flow.js +1 -1
  381. package/node_modules/imapflow/dist/cjs/package-info.d.ts +1 -1
  382. package/node_modules/imapflow/dist/cjs/package-info.js +1 -1
  383. package/node_modules/imapflow/dist/esm/commands/append.js +27 -3
  384. package/node_modules/imapflow/dist/esm/commands/store.js +31 -6
  385. package/node_modules/imapflow/dist/esm/imap-flow.d.ts +1 -1
  386. package/node_modules/imapflow/dist/esm/imap-flow.js +1 -1
  387. package/node_modules/imapflow/dist/esm/package-info.d.ts +1 -1
  388. package/node_modules/imapflow/dist/esm/package-info.js +1 -1
  389. package/node_modules/imapflow/package.json +4 -4
  390. package/node_modules/pino/CONTRIBUTING.md +5 -1
  391. package/node_modules/pino/LICENSE +1 -1
  392. package/node_modules/pino/README.md +1 -1
  393. package/node_modules/pino/SECURITY.md +18 -2
  394. package/node_modules/pino/browser.js +68 -8
  395. package/node_modules/pino/docs/api.md +75 -4
  396. package/node_modules/pino/docs/asynchronous.md +18 -3
  397. package/node_modules/pino/docs/browser.md +63 -0
  398. package/node_modules/pino/docs/child-loggers.md +22 -1
  399. package/node_modules/pino/docs/ecosystem.md +1 -0
  400. package/node_modules/pino/docs/help.md +11 -3
  401. package/node_modules/pino/docs/lts.md +29 -0
  402. package/node_modules/pino/docs/pretty.md +3 -0
  403. package/node_modules/pino/docs/redaction.md +3 -8
  404. package/node_modules/pino/docs/transports.md +71 -0
  405. package/node_modules/pino/docs/web.md +11 -14
  406. package/node_modules/pino/eslint.config.js +15 -7
  407. package/node_modules/pino/lib/caller.js +10 -0
  408. package/node_modules/pino/lib/meta.js +1 -1
  409. package/node_modules/pino/lib/multistream.js +15 -7
  410. package/node_modules/pino/lib/redaction.js +8 -3
  411. package/node_modules/pino/lib/symbols.js +3 -1
  412. package/node_modules/pino/lib/tools.js +2 -2
  413. package/node_modules/pino/lib/transport.js +14 -1
  414. package/node_modules/pino/lib/worker.js +4 -1
  415. package/node_modules/pino/package.json +14 -22
  416. package/node_modules/pino/pino.d.ts +709 -736
  417. package/node_modules/pino/pino.js +27 -2
  418. package/node_modules/pino/test/basic.test.js +66 -0
  419. package/node_modules/pino/test/browser-bindings.test.js +114 -0
  420. package/node_modules/pino/test/browser-redaction.test.js +264 -0
  421. package/node_modules/pino/test/browser-set-bindings.test.js +99 -0
  422. package/node_modules/pino/test/caller.test.js +20 -0
  423. package/node_modules/pino/test/escaping.test.js +17 -0
  424. package/node_modules/pino/test/fixtures/caller-loop.js +6 -0
  425. package/node_modules/pino/test/fixtures/ts/transpile.cjs +3 -3
  426. package/node_modules/pino/test/helper.js +6 -2
  427. package/node_modules/pino/test/multistream.test.js +64 -0
  428. package/node_modules/pino/test/redact.test.js +30 -0
  429. package/node_modules/pino/test/smoke.js +59 -0
  430. package/node_modules/pino/test/transport/core.test.js +85 -0
  431. package/node_modules/pino/test/transport/sync-false.test.js +12 -0
  432. package/node_modules/pino/test/transport/uses-pino-config.test.js +4 -4
  433. package/node_modules/pino/test/types/pino-import.tst.cts +30 -0
  434. package/node_modules/pino/test/types/pino-import.tst.js +73 -0
  435. package/node_modules/pino/test/types/pino-multistream.tst.ts +49 -0
  436. package/node_modules/pino/test/types/pino-top-export.tst.ts +32 -0
  437. package/node_modules/pino/test/types/{pino-transport.test-d.ts → pino-transport.tst.ts} +85 -70
  438. package/node_modules/pino/test/types/pino-type-only.tst.ts +77 -0
  439. package/node_modules/pino/test/types/pino.ts +14 -7
  440. package/node_modules/pino/test/types/{pino.test-d.ts → pino.tst.ts} +135 -137
  441. package/node_modules/pino/test/types/tsconfig.json +10 -0
  442. package/node_modules/pino/tsconfig.json +6 -6
  443. package/node_modules/real-require/README.md +6 -6
  444. package/node_modules/real-require/package.json +10 -21
  445. package/node_modules/real-require/src/index.js +2 -2
  446. package/package.json +2 -2
  447. package/packages/cli/dist/.tsbuildinfo +1 -1
  448. package/packages/cli/dist/doctor-probes.d.ts.map +1 -1
  449. package/packages/cli/dist/doctor-probes.js +44 -3
  450. package/packages/cli/dist/doctor-probes.js.map +1 -1
  451. package/packages/cli/dist/doctor.d.ts +37 -0
  452. package/packages/cli/dist/doctor.d.ts.map +1 -1
  453. package/packages/cli/dist/doctor.js +37 -0
  454. package/packages/cli/dist/doctor.js.map +1 -1
  455. package/packages/core/dist/.tsbuildinfo +1 -1
  456. package/packages/core/dist/actions/approvals.d.ts +7 -0
  457. package/packages/core/dist/actions/approvals.d.ts.map +1 -1
  458. package/packages/core/dist/actions/approvals.js +11 -1
  459. package/packages/core/dist/actions/approvals.js.map +1 -1
  460. package/packages/core/dist/agents/catalog.d.ts.map +1 -1
  461. package/packages/core/dist/agents/catalog.js +2 -2
  462. package/packages/core/dist/agents/catalog.js.map +1 -1
  463. package/packages/core/dist/agents/skills.d.ts +60 -1
  464. package/packages/core/dist/agents/skills.d.ts.map +1 -1
  465. package/packages/core/dist/agents/skills.js +157 -17
  466. package/packages/core/dist/agents/skills.js.map +1 -1
  467. package/packages/core/dist/day-month.d.ts +52 -0
  468. package/packages/core/dist/day-month.d.ts.map +1 -0
  469. package/packages/core/dist/day-month.js +101 -0
  470. package/packages/core/dist/day-month.js.map +1 -0
  471. package/packages/core/dist/host/build.d.ts +25 -2
  472. package/packages/core/dist/host/build.d.ts.map +1 -1
  473. package/packages/core/dist/host/build.js +169 -8
  474. package/packages/core/dist/host/build.js.map +1 -1
  475. package/packages/core/dist/host/http.d.ts +97 -0
  476. package/packages/core/dist/host/http.d.ts.map +1 -1
  477. package/packages/core/dist/host/http.js +321 -26
  478. package/packages/core/dist/host/http.js.map +1 -1
  479. package/packages/core/dist/host/types.d.ts +114 -4
  480. package/packages/core/dist/host/types.d.ts.map +1 -1
  481. package/packages/core/dist/index.d.ts +3 -0
  482. package/packages/core/dist/index.d.ts.map +1 -1
  483. package/packages/core/dist/index.js +3 -0
  484. package/packages/core/dist/index.js.map +1 -1
  485. package/packages/core/dist/notifications/notify.d.ts.map +1 -1
  486. package/packages/core/dist/notifications/notify.js +10 -6
  487. package/packages/core/dist/notifications/notify.js.map +1 -1
  488. package/packages/core/dist/notifications/store.d.ts.map +1 -1
  489. package/packages/core/dist/notifications/store.js +2 -1
  490. package/packages/core/dist/notifications/store.js.map +1 -1
  491. package/packages/core/dist/notifications/types.d.ts +8 -0
  492. package/packages/core/dist/notifications/types.d.ts.map +1 -1
  493. package/packages/core/dist/notifications/types.js.map +1 -1
  494. package/packages/core/dist/onboarding/store.d.ts.map +1 -1
  495. package/packages/core/dist/onboarding/store.js +28 -5
  496. package/packages/core/dist/onboarding/store.js.map +1 -1
  497. package/packages/core/dist/onboarding/types.d.ts +10 -0
  498. package/packages/core/dist/onboarding/types.d.ts.map +1 -1
  499. package/packages/core/dist/onboarding/types.js.map +1 -1
  500. package/packages/core/dist/pages.d.ts +449 -20
  501. package/packages/core/dist/pages.d.ts.map +1 -1
  502. package/packages/core/dist/pages.js +223 -8
  503. package/packages/core/dist/pages.js.map +1 -1
  504. package/packages/core/dist/plugin/assets.d.ts +52 -0
  505. package/packages/core/dist/plugin/assets.d.ts.map +1 -0
  506. package/packages/core/dist/plugin/assets.js +59 -0
  507. package/packages/core/dist/plugin/assets.js.map +1 -0
  508. package/packages/core/dist/plugin/index.d.ts +10 -4
  509. package/packages/core/dist/plugin/index.d.ts.map +1 -1
  510. package/packages/core/dist/plugin/index.js +4 -1
  511. package/packages/core/dist/plugin/index.js.map +1 -1
  512. package/packages/core/dist/plugin/requires.d.ts +3 -1
  513. package/packages/core/dist/plugin/requires.d.ts.map +1 -1
  514. package/packages/core/dist/plugin/requires.js +5 -3
  515. package/packages/core/dist/plugin/requires.js.map +1 -1
  516. package/packages/core/dist/plugin/sign-in.d.ts +78 -0
  517. package/packages/core/dist/plugin/sign-in.d.ts.map +1 -0
  518. package/packages/core/dist/plugin/sign-in.js +54 -0
  519. package/packages/core/dist/plugin/sign-in.js.map +1 -0
  520. package/packages/core/dist/plugin/uses.d.ts +1 -1
  521. package/packages/core/dist/plugin/uses.d.ts.map +1 -1
  522. package/packages/core/dist/plugin/uses.js +2 -0
  523. package/packages/core/dist/plugin/uses.js.map +1 -1
  524. package/packages/core/dist/plugin/version.d.ts +1 -1
  525. package/packages/core/dist/plugin/version.js +1 -1
  526. package/packages/core/dist/plugin-assets.d.ts +21 -0
  527. package/packages/core/dist/plugin-assets.d.ts.map +1 -0
  528. package/packages/core/dist/plugin-assets.js +140 -0
  529. package/packages/core/dist/plugin-assets.js.map +1 -0
  530. package/packages/core/dist/provider-accounts.d.ts +7 -0
  531. package/packages/core/dist/provider-accounts.d.ts.map +1 -1
  532. package/packages/core/dist/provider-accounts.js +15 -0
  533. package/packages/core/dist/provider-accounts.js.map +1 -1
  534. package/packages/core/dist/questions/types.d.ts +1 -1
  535. package/packages/core/dist/questions/types.js +1 -1
  536. package/packages/core/dist/queue/jobs.d.ts +57 -2
  537. package/packages/core/dist/queue/jobs.d.ts.map +1 -1
  538. package/packages/core/dist/queue/jobs.js +114 -0
  539. package/packages/core/dist/queue/jobs.js.map +1 -1
  540. package/packages/core/dist/queue/worker.d.ts +24 -2
  541. package/packages/core/dist/queue/worker.d.ts.map +1 -1
  542. package/packages/core/dist/queue/worker.js +66 -11
  543. package/packages/core/dist/queue/worker.js.map +1 -1
  544. package/packages/core/dist/registry.d.ts +17 -0
  545. package/packages/core/dist/registry.d.ts.map +1 -1
  546. package/packages/core/dist/registry.js +48 -4
  547. package/packages/core/dist/registry.js.map +1 -1
  548. package/packages/core/dist/scheduler/missions.d.ts +14 -0
  549. package/packages/core/dist/scheduler/missions.d.ts.map +1 -1
  550. package/packages/core/dist/scheduler/missions.js +17 -4
  551. package/packages/core/dist/scheduler/missions.js.map +1 -1
  552. package/packages/core/dist/scheduler/types.d.ts +13 -0
  553. package/packages/core/dist/scheduler/types.d.ts.map +1 -1
  554. package/packages/core/dist/scheduler/types.js +14 -0
  555. package/packages/core/dist/scheduler/types.js.map +1 -1
  556. package/packages/core/dist/secrets/scrub.d.ts.map +1 -1
  557. package/packages/core/dist/secrets/scrub.js +15 -0
  558. package/packages/core/dist/secrets/scrub.js.map +1 -1
  559. package/packages/core/dist/surfaces.d.ts +10 -0
  560. package/packages/core/dist/surfaces.d.ts.map +1 -1
  561. package/packages/core/dist/surfaces.js +11 -0
  562. package/packages/core/dist/surfaces.js.map +1 -1
  563. package/packages/core/dist/tools.d.ts +72 -1
  564. package/packages/core/dist/tools.d.ts.map +1 -1
  565. package/packages/core/dist/tools.js +38 -0
  566. package/packages/core/dist/tools.js.map +1 -1
  567. package/packages/core/dist/views.d.ts +29 -12
  568. package/packages/core/dist/views.d.ts.map +1 -1
  569. package/packages/core/dist/views.js +1 -0
  570. package/packages/core/dist/views.js.map +1 -1
  571. package/packages/core/dist/widget-settings.d.ts +2 -1
  572. package/packages/core/dist/widget-settings.d.ts.map +1 -1
  573. package/packages/core/dist/widget-settings.js +8 -2
  574. package/packages/core/dist/widget-settings.js.map +1 -1
  575. package/packages/core/dist/widgets.d.ts +46 -3
  576. package/packages/core/dist/widgets.d.ts.map +1 -1
  577. package/packages/core/dist/widgets.js +68 -5
  578. package/packages/core/dist/widgets.js.map +1 -1
  579. package/packages/core/migrations/073_mission_report.sql +15 -0
  580. package/packages/core/migrations/074_owner_identity.sql +14 -0
  581. package/packages/gateway/dist/.tsbuildinfo +1 -1
  582. package/packages/gateway/dist/agents/catalog.d.ts.map +1 -1
  583. package/packages/gateway/dist/agents/catalog.js +3 -3
  584. package/packages/gateway/dist/agents/catalog.js.map +1 -1
  585. package/packages/gateway/dist/agents/catalogue-package.d.ts +76 -0
  586. package/packages/gateway/dist/agents/catalogue-package.d.ts.map +1 -1
  587. package/packages/gateway/dist/agents/catalogue-package.js +29 -5
  588. package/packages/gateway/dist/agents/catalogue-package.js.map +1 -1
  589. package/packages/gateway/dist/agents/owner-text.d.ts +19 -0
  590. package/packages/gateway/dist/agents/owner-text.d.ts.map +1 -0
  591. package/packages/gateway/dist/agents/owner-text.js +44 -0
  592. package/packages/gateway/dist/agents/owner-text.js.map +1 -0
  593. package/packages/gateway/dist/agents/owner-tools.d.ts.map +1 -1
  594. package/packages/gateway/dist/agents/owner-tools.js +36 -2
  595. package/packages/gateway/dist/agents/owner-tools.js.map +1 -1
  596. package/packages/gateway/dist/agents/platform-catalogue.d.ts +68 -3
  597. package/packages/gateway/dist/agents/platform-catalogue.d.ts.map +1 -1
  598. package/packages/gateway/dist/agents/platform-catalogue.js +264 -32
  599. package/packages/gateway/dist/agents/platform-catalogue.js.map +1 -1
  600. package/packages/gateway/dist/agents/platform.d.ts +11 -4
  601. package/packages/gateway/dist/agents/platform.d.ts.map +1 -1
  602. package/packages/gateway/dist/agents/platform.js +15 -0
  603. package/packages/gateway/dist/agents/platform.js.map +1 -1
  604. package/packages/gateway/dist/bootstrap.d.ts.map +1 -1
  605. package/packages/gateway/dist/bootstrap.js +7 -1
  606. package/packages/gateway/dist/bootstrap.js.map +1 -1
  607. package/packages/gateway/dist/evals/golden.d.ts +33 -1
  608. package/packages/gateway/dist/evals/golden.d.ts.map +1 -1
  609. package/packages/gateway/dist/evals/golden.js +168 -3
  610. package/packages/gateway/dist/evals/golden.js.map +1 -1
  611. package/packages/gateway/dist/index.d.ts +2 -1
  612. package/packages/gateway/dist/index.d.ts.map +1 -1
  613. package/packages/gateway/dist/index.js +2 -1
  614. package/packages/gateway/dist/index.js.map +1 -1
  615. package/packages/gateway/dist/missions/agent-run.d.ts.map +1 -1
  616. package/packages/gateway/dist/missions/agent-run.js +2 -0
  617. package/packages/gateway/dist/missions/agent-run.js.map +1 -1
  618. package/packages/gateway/dist/missions/dates.d.ts +98 -0
  619. package/packages/gateway/dist/missions/dates.d.ts.map +1 -0
  620. package/packages/gateway/dist/missions/dates.js +252 -0
  621. package/packages/gateway/dist/missions/dates.js.map +1 -0
  622. package/packages/gateway/dist/missions/defaults.d.ts.map +1 -1
  623. package/packages/gateway/dist/missions/defaults.js +2 -0
  624. package/packages/gateway/dist/missions/defaults.js.map +1 -1
  625. package/packages/gateway/dist/missions/execute.d.ts +25 -1
  626. package/packages/gateway/dist/missions/execute.d.ts.map +1 -1
  627. package/packages/gateway/dist/missions/execute.js +80 -8
  628. package/packages/gateway/dist/missions/execute.js.map +1 -1
  629. package/packages/gateway/dist/missions/report.d.ts +25 -2
  630. package/packages/gateway/dist/missions/report.d.ts.map +1 -1
  631. package/packages/gateway/dist/missions/report.js +71 -11
  632. package/packages/gateway/dist/missions/report.js.map +1 -1
  633. package/packages/gateway/dist/ollama-local.d.ts +90 -0
  634. package/packages/gateway/dist/ollama-local.d.ts.map +1 -0
  635. package/packages/gateway/dist/ollama-local.js +201 -0
  636. package/packages/gateway/dist/ollama-local.js.map +1 -0
  637. package/packages/gateway/dist/owner-notify.d.ts.map +1 -1
  638. package/packages/gateway/dist/owner-notify.js +7 -3
  639. package/packages/gateway/dist/owner-notify.js.map +1 -1
  640. package/packages/gateway/dist/plugins/asset-image-worker.d.ts +2 -0
  641. package/packages/gateway/dist/plugins/asset-image-worker.d.ts.map +1 -0
  642. package/packages/gateway/dist/plugins/asset-image-worker.js +18 -0
  643. package/packages/gateway/dist/plugins/asset-image-worker.js.map +1 -0
  644. package/packages/gateway/dist/plugins/asset-image.d.ts +31 -0
  645. package/packages/gateway/dist/plugins/asset-image.d.ts.map +1 -0
  646. package/packages/gateway/dist/plugins/asset-image.js +332 -0
  647. package/packages/gateway/dist/plugins/asset-image.js.map +1 -0
  648. package/packages/gateway/dist/plugins/load.d.ts.map +1 -1
  649. package/packages/gateway/dist/plugins/load.js +14 -1
  650. package/packages/gateway/dist/plugins/load.js.map +1 -1
  651. package/packages/gateway/dist/plugins/stage.d.ts +6 -0
  652. package/packages/gateway/dist/plugins/stage.d.ts.map +1 -1
  653. package/packages/gateway/dist/plugins/stage.js +5 -0
  654. package/packages/gateway/dist/plugins/stage.js.map +1 -1
  655. package/packages/gateway/dist/plugins/uninstall.d.ts.map +1 -1
  656. package/packages/gateway/dist/plugins/uninstall.js +8 -0
  657. package/packages/gateway/dist/plugins/uninstall.js.map +1 -1
  658. package/packages/gateway/dist/plugins-cli.d.ts +8 -0
  659. package/packages/gateway/dist/plugins-cli.d.ts.map +1 -1
  660. package/packages/gateway/dist/plugins-cli.js +22 -1
  661. package/packages/gateway/dist/plugins-cli.js.map +1 -1
  662. package/packages/gateway/dist/serve.d.ts.map +1 -1
  663. package/packages/gateway/dist/serve.js +50 -5
  664. package/packages/gateway/dist/serve.js.map +1 -1
  665. package/packages/gateway/dist/surfaces/pending-question.js +2 -2
  666. package/packages/gateway/dist/system-context.d.ts +21 -1
  667. package/packages/gateway/dist/system-context.d.ts.map +1 -1
  668. package/packages/gateway/dist/system-context.js +76 -2
  669. package/packages/gateway/dist/system-context.js.map +1 -1
  670. package/packages/gateway/dist/telegram/approvals.d.ts.map +1 -1
  671. package/packages/gateway/dist/telegram/approvals.js +4 -2
  672. package/packages/gateway/dist/telegram/approvals.js.map +1 -1
  673. package/packages/gateway/dist/telegram/channel.d.ts +12 -0
  674. package/packages/gateway/dist/telegram/channel.d.ts.map +1 -1
  675. package/packages/gateway/dist/telegram/channel.js +49 -2
  676. package/packages/gateway/dist/telegram/channel.js.map +1 -1
  677. package/packages/gateway/dist/telegram/html.d.ts +34 -0
  678. package/packages/gateway/dist/telegram/html.d.ts.map +1 -0
  679. package/packages/gateway/dist/telegram/html.js +263 -0
  680. package/packages/gateway/dist/telegram/html.js.map +1 -0
  681. package/packages/gateway/dist/telegram/notify.d.ts +6 -0
  682. package/packages/gateway/dist/telegram/notify.d.ts.map +1 -1
  683. package/packages/gateway/dist/telegram/notify.js +25 -3
  684. package/packages/gateway/dist/telegram/notify.js.map +1 -1
  685. package/packages/gateway/dist/tips/facts.d.ts +2 -0
  686. package/packages/gateway/dist/tips/facts.d.ts.map +1 -1
  687. package/packages/gateway/dist/tips/facts.js +4 -1
  688. package/packages/gateway/dist/tips/facts.js.map +1 -1
  689. package/packages/gateway/dist/tips/rules.d.ts.map +1 -1
  690. package/packages/gateway/dist/tips/rules.js +10 -0
  691. package/packages/gateway/dist/tips/rules.js.map +1 -1
  692. package/packages/gateway/dist/web/api-routes.d.ts.map +1 -1
  693. package/packages/gateway/dist/web/api-routes.js +80 -11
  694. package/packages/gateway/dist/web/api-routes.js.map +1 -1
  695. package/packages/gateway/dist/web/api-scan.d.ts +1 -1
  696. package/packages/gateway/dist/web/api-scan.d.ts.map +1 -1
  697. package/packages/gateway/dist/web/api-scan.js +1 -0
  698. package/packages/gateway/dist/web/api-scan.js.map +1 -1
  699. package/packages/gateway/dist/web/catalogue.d.ts.map +1 -1
  700. package/packages/gateway/dist/web/catalogue.js +7 -4
  701. package/packages/gateway/dist/web/catalogue.js.map +1 -1
  702. package/packages/gateway/dist/web/chat.d.ts.map +1 -1
  703. package/packages/gateway/dist/web/chat.js +9 -0
  704. package/packages/gateway/dist/web/chat.js.map +1 -1
  705. package/packages/gateway/dist/web/composer.d.ts +45 -0
  706. package/packages/gateway/dist/web/composer.d.ts.map +1 -0
  707. package/packages/gateway/dist/web/composer.js +85 -0
  708. package/packages/gateway/dist/web/composer.js.map +1 -0
  709. package/packages/gateway/dist/web/extension.d.ts +12 -0
  710. package/packages/gateway/dist/web/extension.d.ts.map +1 -1
  711. package/packages/gateway/dist/web/extension.js +11 -1
  712. package/packages/gateway/dist/web/extension.js.map +1 -1
  713. package/packages/gateway/dist/web/lock.d.ts +6 -0
  714. package/packages/gateway/dist/web/lock.d.ts.map +1 -1
  715. package/packages/gateway/dist/web/lock.js +33 -2
  716. package/packages/gateway/dist/web/lock.js.map +1 -1
  717. package/packages/gateway/dist/web/market.d.ts +20 -1
  718. package/packages/gateway/dist/web/market.d.ts.map +1 -1
  719. package/packages/gateway/dist/web/market.js +41 -1
  720. package/packages/gateway/dist/web/market.js.map +1 -1
  721. package/packages/gateway/dist/web/people.d.ts +44 -0
  722. package/packages/gateway/dist/web/people.d.ts.map +1 -0
  723. package/packages/gateway/dist/web/people.js +114 -0
  724. package/packages/gateway/dist/web/people.js.map +1 -0
  725. package/packages/gateway/dist/web/server.d.ts +4 -0
  726. package/packages/gateway/dist/web/server.d.ts.map +1 -1
  727. package/packages/gateway/dist/web/server.js +171 -13
  728. package/packages/gateway/dist/web/server.js.map +1 -1
  729. package/packages/gateway/dist/web/skill-bundles.d.ts +101 -0
  730. package/packages/gateway/dist/web/skill-bundles.d.ts.map +1 -0
  731. package/packages/gateway/dist/web/skill-bundles.js +439 -0
  732. package/packages/gateway/dist/web/skill-bundles.js.map +1 -0
  733. package/packages/gateway/dist/web/skills.d.ts +57 -1
  734. package/packages/gateway/dist/web/skills.d.ts.map +1 -1
  735. package/packages/gateway/dist/web/skills.js +171 -9
  736. package/packages/gateway/dist/web/skills.js.map +1 -1
  737. package/packages/gateway/dist/web/widgets.js +2 -2
  738. package/packages/gateway/dist/web/widgets.js.map +1 -1
  739. package/packages/gateway/dist/web/zip-read.d.ts +31 -0
  740. package/packages/gateway/dist/web/zip-read.d.ts.map +1 -0
  741. package/packages/gateway/dist/web/zip-read.js +125 -0
  742. package/packages/gateway/dist/web/zip-read.js.map +1 -0
  743. package/packages/install/dist/.tsbuildinfo +1 -1
  744. package/packages/runtime/dist/.tsbuildinfo +1 -1
  745. package/packages/runtime/dist/index.d.ts +1 -0
  746. package/packages/runtime/dist/index.d.ts.map +1 -1
  747. package/packages/runtime/dist/index.js +1 -0
  748. package/packages/runtime/dist/index.js.map +1 -1
  749. package/packages/runtime/dist/loop.js +11 -1
  750. package/packages/runtime/dist/loop.js.map +1 -1
  751. package/packages/runtime/dist/plugin-sign-in.d.ts +12 -0
  752. package/packages/runtime/dist/plugin-sign-in.d.ts.map +1 -0
  753. package/packages/runtime/dist/plugin-sign-in.js +397 -0
  754. package/packages/runtime/dist/plugin-sign-in.js.map +1 -0
  755. package/packages/runtime/dist/transport.d.ts +1 -1
  756. package/packages/runtime/dist/transport.d.ts.map +1 -1
  757. package/packages/runtime/dist/transport.js +6 -0
  758. package/packages/runtime/dist/transport.js.map +1 -1
  759. package/packages/tools/artifacts/dist/.tsbuildinfo +1 -1
  760. package/packages/tools/artifacts/dist/tools/write.d.ts.map +1 -1
  761. package/packages/tools/artifacts/dist/tools/write.js +1 -0
  762. package/packages/tools/artifacts/dist/tools/write.js.map +1 -1
  763. package/packages/tools/browser/dist/.tsbuildinfo +1 -1
  764. package/packages/tools/browser/dist/computer.d.ts +13 -0
  765. package/packages/tools/browser/dist/computer.d.ts.map +1 -1
  766. package/packages/tools/browser/dist/computer.js +22 -2
  767. package/packages/tools/browser/dist/computer.js.map +1 -1
  768. package/packages/tools/browser/dist/controller.d.ts +4 -0
  769. package/packages/tools/browser/dist/controller.d.ts.map +1 -1
  770. package/packages/tools/browser/dist/controller.js +8 -3
  771. package/packages/tools/browser/dist/controller.js.map +1 -1
  772. package/packages/tools/browser/dist/index.d.ts +1 -1
  773. package/packages/tools/browser/dist/index.d.ts.map +1 -1
  774. package/packages/tools/browser/dist/index.js +1 -1
  775. package/packages/tools/browser/dist/index.js.map +1 -1
  776. package/packages/tools/browser/dist/native/buddi-computer +0 -0
  777. package/packages/tools/browser/dist/service.d.ts +5 -0
  778. package/packages/tools/browser/dist/service.d.ts.map +1 -1
  779. package/packages/tools/browser/dist/service.js.map +1 -1
  780. package/packages/tools/email/dist/.tsbuildinfo +1 -1
  781. package/packages/tools/email/dist/widgets.d.ts.map +1 -1
  782. package/packages/tools/email/dist/widgets.js +2 -1
  783. package/packages/tools/email/dist/widgets.js.map +1 -1
  784. package/packages/tools/host/dist/.tsbuildinfo +1 -1
  785. package/packages/tools/host/dist/index.d.ts +2 -1
  786. package/packages/tools/host/dist/index.d.ts.map +1 -1
  787. package/packages/tools/host/dist/index.js +3 -2
  788. package/packages/tools/host/dist/index.js.map +1 -1
  789. package/packages/tools/host/dist/process.d.ts +4 -0
  790. package/packages/tools/host/dist/process.d.ts.map +1 -1
  791. package/packages/tools/host/dist/process.js +4 -2
  792. package/packages/tools/host/dist/process.js.map +1 -1
  793. package/packages/tools/host/dist/service.d.ts +66 -17
  794. package/packages/tools/host/dist/service.d.ts.map +1 -1
  795. package/packages/tools/host/dist/service.js +172 -9
  796. package/packages/tools/host/dist/service.js.map +1 -1
  797. package/packages/tools/host/dist/skill-run.d.ts +55 -0
  798. package/packages/tools/host/dist/skill-run.d.ts.map +1 -0
  799. package/packages/tools/host/dist/skill-run.js +132 -0
  800. package/packages/tools/host/dist/skill-run.js.map +1 -0
  801. package/packages/tools/mcp/dist/.tsbuildinfo +1 -1
  802. package/packages/tools/memory/dist/.tsbuildinfo +1 -1
  803. package/packages/tools/memory/dist/index.d.ts +1 -0
  804. package/packages/tools/memory/dist/index.d.ts.map +1 -1
  805. package/packages/tools/memory/dist/index.js +7 -2
  806. package/packages/tools/memory/dist/index.js.map +1 -1
  807. package/packages/tools/memory/dist/people.d.ts +218 -0
  808. package/packages/tools/memory/dist/people.d.ts.map +1 -0
  809. package/packages/tools/memory/dist/people.js +582 -0
  810. package/packages/tools/memory/dist/people.js.map +1 -0
  811. package/packages/tools/memory/dist/preamble.d.ts +4 -1
  812. package/packages/tools/memory/dist/preamble.d.ts.map +1 -1
  813. package/packages/tools/memory/dist/preamble.js +25 -7
  814. package/packages/tools/memory/dist/preamble.js.map +1 -1
  815. package/packages/tools/memory/migrations/002_people.sql +40 -0
  816. package/packages/tools/web/dist/.tsbuildinfo +1 -1
  817. package/packages/web/dist/assets/index-CN1AXMI1.css +1 -0
  818. package/packages/web/dist/assets/index-CQRE9LJX.js +145 -0
  819. package/packages/web/dist/assets/{lottie_light-DYHnHRWL.js → lottie_light-CKJ88Yuk.js} +1 -1
  820. package/packages/web/dist/build.json +1 -1
  821. package/packages/web/dist/index.html +2 -2
  822. package/packages/web/dist/precache.json +4 -4
  823. package/node_modules/pino/test/types/pino-import.test-d.cts +0 -30
  824. package/node_modules/pino/test/types/pino-multistream.test-d.ts +0 -28
  825. package/node_modules/pino/test/types/pino-top-export.test-d.ts +0 -34
  826. package/node_modules/pino/test/types/pino-type-only.test-d.ts +0 -75
  827. package/node_modules/thread-stream/node_modules/real-require/LICENSE.md +0 -21
  828. package/node_modules/thread-stream/node_modules/real-require/README.md +0 -51
  829. package/node_modules/thread-stream/node_modules/real-require/package.json +0 -38
  830. package/node_modules/thread-stream/node_modules/real-require/src/index.js +0 -14
  831. package/packages/web/dist/assets/index-ZauRFo4G.js +0 -134
  832. package/packages/web/dist/assets/index-viBWQfeT.css +0 -1
@@ -1,134 +0,0 @@
1
- var Cy=e=>{throw TypeError(e)};var Ey=(e,t,s)=>t.has(e)||Cy("Cannot "+s);var xn=(e,t,s)=>(Ey(e,t,"read from private field"),s?s.call(e):t.get(e)),Ay=(e,t,s)=>t.has(e)?Cy("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),zf=(e,t,s,r)=>(Ey(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s);function ZI(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 HX=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function eP(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var MN={exports:{}},Nh={},DN={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 Ac=Symbol.for("react.element"),tP=Symbol.for("react.portal"),nP=Symbol.for("react.fragment"),sP=Symbol.for("react.strict_mode"),rP=Symbol.for("react.profiler"),iP=Symbol.for("react.provider"),aP=Symbol.for("react.context"),lP=Symbol.for("react.forward_ref"),oP=Symbol.for("react.suspense"),cP=Symbol.for("react.memo"),uP=Symbol.for("react.lazy"),Ty=Symbol.iterator;function dP(e){return e===null||typeof e!="object"?null:(e=Ty&&e[Ty]||e["@@iterator"],typeof e=="function"?e:null)}var ON={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},LN=Object.assign,FN={};function $l(e,t,s){this.props=e,this.context=t,this.refs=FN,this.updater=s||ON}$l.prototype.isReactComponent={};$l.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")};$l.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function _N(){}_N.prototype=$l.prototype;function Yx(e,t,s){this.props=e,this.context=t,this.refs=FN,this.updater=s||ON}var qx=Yx.prototype=new _N;qx.constructor=Yx;LN(qx,$l.prototype);qx.isPureReactComponent=!0;var $y=Array.isArray,zN=Object.prototype.hasOwnProperty,Jx={current:null},UN={key:!0,ref:!0,__self:!0,__source:!0};function BN(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)zN.call(t,r)&&!UN.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:Ac,type:e,key:a,ref:l,props:i,_owner:Jx.current}}function hP(e,t){return{$$typeof:Ac,type:e.type,key:t,ref:e.ref,props:e.props,_owner:e._owner}}function Qx(e){return typeof e=="object"&&e!==null&&e.$$typeof===Ac}function fP(e){var t={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(s){return t[s]})}var Ry=/\/+/g;function Uf(e,t){return typeof e=="object"&&e!==null&&e.key!=null?fP(""+e.key):t.toString(36)}function Yu(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 Ac:case tP:l=!0}}if(l)return l=e,i=i(l),e=r===""?"."+Uf(l,0):r,$y(i)?(s="",e!=null&&(s=e.replace(Ry,"$&/")+"/"),Yu(i,t,s,"",function(u){return u})):i!=null&&(Qx(i)&&(i=hP(i,s+(!i.key||l&&l.key===i.key?"":(""+i.key).replace(Ry,"$&/")+"/")+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+Uf(a,o);l+=Yu(a,t,s,c,i)}else if(c=dP(e),typeof c=="function")for(e=c.call(e),o=0;!(a=e.next()).done;)a=a.value,c=r+Uf(a,o++),l+=Yu(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 iu(e,t,s){if(e==null)return e;var r=[],i=0;return Yu(e,r,"","",function(a){return t.call(s,a,i++)}),r}function mP(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 In={current:null},qu={transition:null},pP={ReactCurrentDispatcher:In,ReactCurrentBatchConfig:qu,ReactCurrentOwner:Jx};function WN(){throw Error("act(...) is not supported in production builds of React.")}tt.Children={map:iu,forEach:function(e,t,s){iu(e,function(){t.apply(this,arguments)},s)},count:function(e){var t=0;return iu(e,function(){t++}),t},toArray:function(e){return iu(e,function(t){return t})||[]},only:function(e){if(!Qx(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};tt.Component=$l;tt.Fragment=nP;tt.Profiler=rP;tt.PureComponent=Yx;tt.StrictMode=sP;tt.Suspense=oP;tt.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=pP;tt.act=WN;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=LN({},e.props),i=e.key,a=e.ref,l=e._owner;if(t!=null){if(t.ref!==void 0&&(a=t.ref,l=Jx.current),t.key!==void 0&&(i=""+t.key),e.type&&e.type.defaultProps)var o=e.type.defaultProps;for(c in t)zN.call(t,c)&&!UN.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:Ac,type:e.type,key:i,ref:a,props:r,_owner:l}};tt.createContext=function(e){return e={$$typeof:aP,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:iP,_context:e},e.Consumer=e};tt.createElement=BN;tt.createFactory=function(e){var t=BN.bind(null,e);return t.type=e,t};tt.createRef=function(){return{current:null}};tt.forwardRef=function(e){return{$$typeof:lP,render:e}};tt.isValidElement=Qx;tt.lazy=function(e){return{$$typeof:uP,_payload:{_status:-1,_result:e},_init:mP}};tt.memo=function(e,t){return{$$typeof:cP,type:e,compare:t===void 0?null:t}};tt.startTransition=function(e){var t=qu.transition;qu.transition={};try{e()}finally{qu.transition=t}};tt.unstable_act=WN;tt.useCallback=function(e,t){return In.current.useCallback(e,t)};tt.useContext=function(e){return In.current.useContext(e)};tt.useDebugValue=function(){};tt.useDeferredValue=function(e){return In.current.useDeferredValue(e)};tt.useEffect=function(e,t){return In.current.useEffect(e,t)};tt.useId=function(){return In.current.useId()};tt.useImperativeHandle=function(e,t,s){return In.current.useImperativeHandle(e,t,s)};tt.useInsertionEffect=function(e,t){return In.current.useInsertionEffect(e,t)};tt.useLayoutEffect=function(e,t){return In.current.useLayoutEffect(e,t)};tt.useMemo=function(e,t){return In.current.useMemo(e,t)};tt.useReducer=function(e,t,s){return In.current.useReducer(e,t,s)};tt.useRef=function(e){return In.current.useRef(e)};tt.useState=function(e){return In.current.useState(e)};tt.useSyncExternalStore=function(e,t,s){return In.current.useSyncExternalStore(e,t,s)};tt.useTransition=function(){return In.current.useTransition()};tt.version="18.3.1";DN.exports=tt;var d=DN.exports;const gP=eP(d),Rl=ZI({__proto__:null,default:gP},[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 xP=d,vP=Symbol.for("react.element"),jP=Symbol.for("react.fragment"),wP=Object.prototype.hasOwnProperty,yP=xP.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,bP={key:!0,ref:!0,__self:!0,__source:!0};function HN(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)wP.call(t,r)&&!bP.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:vP,type:e,key:a,ref:l,props:i,_owner:yP.current}}Nh.Fragment=jP;Nh.jsx=HN;Nh.jsxs=HN;MN.exports=Nh;var n=MN.exports,KN={exports:{}},as={},VN={exports:{}},GN={};/**
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(D,H){var B=D.length;D.push(H);e:for(;0<B;){var q=B-1>>>1,W=D[q];if(0<i(W,H))D[q]=H,D[B]=W,B=q;else break e}}function s(D){return D.length===0?null:D[0]}function r(D){if(D.length===0)return null;var H=D[0],B=D.pop();if(B!==H){D[0]=B;e:for(var q=0,W=D.length,Y=W>>>1;q<Y;){var F=2*(q+1)-1,X=D[F],Q=F+1,ee=D[Q];if(0>i(X,B))Q<W&&0>i(ee,X)?(D[q]=ee,D[Q]=B,q=Q):(D[q]=X,D[F]=B,q=F);else if(Q<W&&0>i(ee,B))D[q]=ee,D[Q]=B,q=Q;else break e}}return H}function i(D,H){var B=D.sortIndex-H.sortIndex;return B!==0?B:D.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(D){for(var H=s(u);H!==null;){if(H.callback===null)r(u);else if(H.startTime<=D)r(u),H.sortIndex=H.expirationTime,t(c,H);else break;H=s(u)}}function y(D){if(v=!1,w(D),!g)if(s(c)!==null)g=!0,O(k);else{var H=s(u);H!==null&&M(y,H.startTime-D)}}function k(D,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)||D&&!I());){var q=f.callback;if(typeof q=="function"){f.callback=null,m=f.priorityLevel;var W=q(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 Y=!0;else{var F=s(u);F!==null&&M(y,F.startTime-H),Y=!1}return Y}finally{f=null,m=B,p=!1}}var N=!1,S=null,C=-1,T=5,R=-1;function I(){return!(e.unstable_now()-R<T)}function L(){if(S!==null){var D=e.unstable_now();R=D;var H=!0;try{H=S(!0,D)}finally{H?_():(N=!1,S=null)}}else N=!1}var _;if(typeof x=="function")_=function(){x(L)};else if(typeof MessageChannel<"u"){var $=new MessageChannel,P=$.port2;$.port1.onmessage=L,_=function(){P.postMessage(null)}}else _=function(){b(L,0)};function O(D){S=D,N||(N=!0,_())}function M(D,H){C=b(function(){D(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(D){D.callback=null},e.unstable_continueExecution=function(){g||p||(g=!0,O(k))},e.unstable_forceFrameRate=function(D){0>D||125<D?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):T=0<D?Math.floor(1e3/D):5},e.unstable_getCurrentPriorityLevel=function(){return m},e.unstable_getFirstCallbackNode=function(){return s(c)},e.unstable_next=function(D){switch(m){case 1:case 2:case 3:var H=3;break;default:H=m}var B=m;m=H;try{return D()}finally{m=B}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(D,H){switch(D){case 1:case 2:case 3:case 4:case 5:break;default:D=3}var B=m;m=D;try{return H()}finally{m=B}},e.unstable_scheduleCallback=function(D,H,B){var q=e.unstable_now();switch(typeof B=="object"&&B!==null?(B=B.delay,B=typeof B=="number"&&0<B?q+B:q):B=q,D){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,D={id:h++,callback:H,priorityLevel:D,startTime:B,expirationTime:W,sortIndex:-1},B>q?(D.sortIndex=B,t(u,D),s(c)===null&&D===s(u)&&(v?(j(C),C=-1):v=!0,M(y,B-q))):(D.sortIndex=W,t(c,D),g||p||(g=!0,O(k))),D},e.unstable_shouldYield=I,e.unstable_wrapCallback=function(D){var H=m;return function(){var B=m;m=H;try{return D.apply(this,arguments)}finally{m=B}}}})(GN);VN.exports=GN;var kP=VN.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 NP=d,ss=kP;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 YN=new Set,Bo={};function ma(e,t){dl(e,t),dl(e+"Capture",t)}function dl(e,t){for(Bo[e]=t,e=0;e<t.length;e++)YN.add(t[e])}var _r=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),vp=Object.prototype.hasOwnProperty,SP=/^[: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]*$/,Iy={},Py={};function CP(e){return vp.call(Py,e)?!0:vp.call(Iy,e)?!1:SP.test(e)?Py[e]=!0:(Iy[e]=!0,!1)}function EP(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 AP(e,t,s,r){if(t===null||typeof t>"u"||EP(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 Pn(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 mn={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){mn[e]=new Pn(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];mn[t]=new Pn(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){mn[e]=new Pn(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){mn[e]=new Pn(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){mn[e]=new Pn(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){mn[e]=new Pn(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){mn[e]=new Pn(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){mn[e]=new Pn(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){mn[e]=new Pn(e,5,!1,e.toLowerCase(),null,!1,!1)});var Xx=/[\-:]([a-z])/g;function Zx(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(Xx,Zx);mn[t]=new Pn(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(Xx,Zx);mn[t]=new Pn(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(Xx,Zx);mn[t]=new Pn(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){mn[e]=new Pn(e,1,!1,e.toLowerCase(),null,!1,!1)});mn.xlinkHref=new Pn("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){mn[e]=new Pn(e,1,!1,e.toLowerCase(),null,!0,!0)});function ev(e,t,s,r){var i=mn.hasOwnProperty(t)?mn[t]:null;(i!==null?i.type!==0:r||!(2<t.length)||t[0]!=="o"&&t[0]!=="O"||t[1]!=="n"&&t[1]!=="N")&&(AP(t,s,i,r)&&(s=null),r||i===null?CP(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 Yr=NP.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,au=Symbol.for("react.element"),La=Symbol.for("react.portal"),Fa=Symbol.for("react.fragment"),tv=Symbol.for("react.strict_mode"),jp=Symbol.for("react.profiler"),qN=Symbol.for("react.provider"),JN=Symbol.for("react.context"),nv=Symbol.for("react.forward_ref"),wp=Symbol.for("react.suspense"),yp=Symbol.for("react.suspense_list"),sv=Symbol.for("react.memo"),ei=Symbol.for("react.lazy"),QN=Symbol.for("react.offscreen"),My=Symbol.iterator;function so(e){return e===null||typeof e!="object"?null:(e=My&&e[My]||e["@@iterator"],typeof e=="function"?e:null)}var Mt=Object.assign,Bf;function jo(e){if(Bf===void 0)try{throw Error()}catch(s){var t=s.stack.trim().match(/\n( *(at )?)/);Bf=t&&t[1]||""}return`
34
- `+Bf+e}var Wf=!1;function Hf(e,t){if(!e||Wf)return"";Wf=!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{Wf=!1,Error.prepareStackTrace=s}return(e=e?e.displayName||e.name:"")?jo(e):""}function TP(e){switch(e.tag){case 5:return jo(e.type);case 16:return jo("Lazy");case 13:return jo("Suspense");case 19:return jo("SuspenseList");case 0:case 2:case 15:return e=Hf(e.type,!1),e;case 11:return e=Hf(e.type.render,!1),e;case 1:return e=Hf(e.type,!0),e;default:return""}}function bp(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 Fa:return"Fragment";case La:return"Portal";case jp:return"Profiler";case tv:return"StrictMode";case wp:return"Suspense";case yp:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case JN:return(e.displayName||"Context")+".Consumer";case qN:return(e._context.displayName||"Context")+".Provider";case nv:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case sv:return t=e.displayName||null,t!==null?t:bp(e.type)||"Memo";case ei:t=e._payload,e=e._init;try{return bp(e(t))}catch{}}return null}function $P(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 bp(t);case 8:return t===tv?"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 ji(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function XN(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function RP(e){var t=XN(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 lu(e){e._valueTracker||(e._valueTracker=RP(e))}function ZN(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var s=t.getValue(),r="";return e&&(r=XN(e)?e.checked?"true":"false":e.value),e=r,e!==s?(t.setValue(e),!0):!1}function yd(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 kp(e,t){var s=t.checked;return Mt({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:s??e._wrapperState.initialChecked})}function Dy(e,t){var s=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;s=ji(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 eS(e,t){t=t.checked,t!=null&&ev(e,"checked",t,!1)}function Np(e,t){eS(e,t);var s=ji(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")?Sp(e,t.type,s):t.hasOwnProperty("defaultValue")&&Sp(e,t.type,ji(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function Oy(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 Sp(e,t,s){(t!=="number"||yd(e.ownerDocument)!==e)&&(s==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+s&&(e.defaultValue=""+s))}var wo=Array.isArray;function Za(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=""+ji(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 Cp(e,t){if(t.dangerouslySetInnerHTML!=null)throw Error(xe(91));return Mt({},t,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function Ly(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(wo(s)){if(1<s.length)throw Error(xe(93));s=s[0]}t=s}t==null&&(t=""),s=t}e._wrapperState={initialValue:ji(s)}}function tS(e,t){var s=ji(t.value),r=ji(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 Fy(e){var t=e.textContent;t===e._wrapperState.initialValue&&t!==""&&t!==null&&(e.value=t)}function nS(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 Ep(e,t){return e==null||e==="http://www.w3.org/1999/xhtml"?nS(t):e==="http://www.w3.org/2000/svg"&&t==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var ou,sS=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(ou=ou||document.createElement("div"),ou.innerHTML="<svg>"+t.valueOf().toString()+"</svg>",t=ou.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Wo(e,t){if(t){var s=e.firstChild;if(s&&s===e.lastChild&&s.nodeType===3){s.nodeValue=t;return}}e.textContent=t}var Eo={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},IP=["Webkit","ms","Moz","O"];Object.keys(Eo).forEach(function(e){IP.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Eo[t]=Eo[e]})});function rS(e,t,s){return t==null||typeof t=="boolean"||t===""?"":s||typeof t!="number"||t===0||Eo.hasOwnProperty(e)&&Eo[e]?(""+t).trim():t+"px"}function iS(e,t){e=e.style;for(var s in t)if(t.hasOwnProperty(s)){var r=s.indexOf("--")===0,i=rS(s,t[s],r);s==="float"&&(s="cssFloat"),r?e.setProperty(s,i):e[s]=i}}var PP=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 Ap(e,t){if(t){if(PP[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 Tp(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 rv(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Rp=null,el=null,tl=null;function _y(e){if(e=Rc(e)){if(typeof Rp!="function")throw Error(xe(280));var t=e.stateNode;t&&(t=Th(t),Rp(e.stateNode,e.type,t))}}function aS(e){el?tl?tl.push(e):tl=[e]:el=e}function lS(){if(el){var e=el,t=tl;if(tl=el=null,_y(e),t)for(e=0;e<t.length;e++)_y(t[e])}}function oS(e,t){return e(t)}function cS(){}var Kf=!1;function uS(e,t,s){if(Kf)return e(t,s);Kf=!0;try{return oS(e,t,s)}finally{Kf=!1,(el!==null||tl!==null)&&(cS(),lS())}}function Ho(e,t){var s=e.stateNode;if(s===null)return null;var r=Th(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 Ip=!1;if(_r)try{var ro={};Object.defineProperty(ro,"passive",{get:function(){Ip=!0}}),window.addEventListener("test",ro,ro),window.removeEventListener("test",ro,ro)}catch{Ip=!1}function MP(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 Ao=!1,bd=null,kd=!1,Pp=null,DP={onError:function(e){Ao=!0,bd=e}};function OP(e,t,s,r,i,a,l,o,c){Ao=!1,bd=null,MP.apply(DP,arguments)}function LP(e,t,s,r,i,a,l,o,c){if(OP.apply(this,arguments),Ao){if(Ao){var u=bd;Ao=!1,bd=null}else throw Error(xe(198));kd||(kd=!0,Pp=u)}}function pa(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 dS(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 zy(e){if(pa(e)!==e)throw Error(xe(188))}function FP(e){var t=e.alternate;if(!t){if(t=pa(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 zy(i),e;if(a===r)return zy(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 hS(e){return e=FP(e),e!==null?fS(e):null}function fS(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var t=fS(e);if(t!==null)return t;e=e.sibling}return null}var mS=ss.unstable_scheduleCallback,Uy=ss.unstable_cancelCallback,_P=ss.unstable_shouldYield,zP=ss.unstable_requestPaint,_t=ss.unstable_now,UP=ss.unstable_getCurrentPriorityLevel,iv=ss.unstable_ImmediatePriority,pS=ss.unstable_UserBlockingPriority,Nd=ss.unstable_NormalPriority,BP=ss.unstable_LowPriority,gS=ss.unstable_IdlePriority,Sh=null,lr=null;function WP(e){if(lr&&typeof lr.onCommitFiberRoot=="function")try{lr.onCommitFiberRoot(Sh,e,void 0,(e.current.flags&128)===128)}catch{}}var Os=Math.clz32?Math.clz32:VP,HP=Math.log,KP=Math.LN2;function VP(e){return e>>>=0,e===0?32:31-(HP(e)/KP|0)|0}var cu=64,uu=4194304;function yo(e){switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return e&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return e}}function Sd(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=yo(o):(a&=l,a!==0&&(r=yo(a)))}else l=s&~i,l!==0?r=yo(l):a!==0&&(r=yo(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-Os(t),i=1<<s,r|=e[s],t&=~i;return r}function GP(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 YP(e,t){for(var s=e.suspendedLanes,r=e.pingedLanes,i=e.expirationTimes,a=e.pendingLanes;0<a;){var l=31-Os(a),o=1<<l,c=i[l];c===-1?(!(o&s)||o&r)&&(i[l]=GP(o,t)):c<=t&&(e.expiredLanes|=o),a&=~o}}function Mp(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function xS(){var e=cu;return cu<<=1,!(cu&4194240)&&(cu=64),e}function Vf(e){for(var t=[],s=0;31>s;s++)t.push(e);return t}function Tc(e,t,s){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-Os(t),e[t]=s}function qP(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-Os(s),a=1<<i;t[i]=0,r[i]=-1,e[i]=-1,s&=~a}}function av(e,t){var s=e.entangledLanes|=t;for(e=e.entanglements;s;){var r=31-Os(s),i=1<<r;i&t|e[r]&t&&(e[r]|=t),s&=~i}}var pt=0;function vS(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var jS,lv,wS,yS,bS,Dp=!1,du=[],oi=null,ci=null,ui=null,Ko=new Map,Vo=new Map,ni=[],JP="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 By(e,t){switch(e){case"focusin":case"focusout":oi=null;break;case"dragenter":case"dragleave":ci=null;break;case"mouseover":case"mouseout":ui=null;break;case"pointerover":case"pointerout":Ko.delete(t.pointerId);break;case"gotpointercapture":case"lostpointercapture":Vo.delete(t.pointerId)}}function io(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=Rc(t),t!==null&&lv(t)),e):(e.eventSystemFlags|=r,t=e.targetContainers,i!==null&&t.indexOf(i)===-1&&t.push(i),e)}function QP(e,t,s,r,i){switch(t){case"focusin":return oi=io(oi,e,t,s,r,i),!0;case"dragenter":return ci=io(ci,e,t,s,r,i),!0;case"mouseover":return ui=io(ui,e,t,s,r,i),!0;case"pointerover":var a=i.pointerId;return Ko.set(a,io(Ko.get(a)||null,e,t,s,r,i)),!0;case"gotpointercapture":return a=i.pointerId,Vo.set(a,io(Vo.get(a)||null,e,t,s,r,i)),!0}return!1}function kS(e){var t=qi(e.target);if(t!==null){var s=pa(t);if(s!==null){if(t=s.tag,t===13){if(t=dS(s),t!==null){e.blockedOn=t,bS(e.priority,function(){wS(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 Ju(e){if(e.blockedOn!==null)return!1;for(var t=e.targetContainers;0<t.length;){var s=Op(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=Rc(s),t!==null&&lv(t),e.blockedOn=s,!1;t.shift()}return!0}function Wy(e,t,s){Ju(e)&&s.delete(t)}function XP(){Dp=!1,oi!==null&&Ju(oi)&&(oi=null),ci!==null&&Ju(ci)&&(ci=null),ui!==null&&Ju(ui)&&(ui=null),Ko.forEach(Wy),Vo.forEach(Wy)}function ao(e,t){e.blockedOn===t&&(e.blockedOn=null,Dp||(Dp=!0,ss.unstable_scheduleCallback(ss.unstable_NormalPriority,XP)))}function Go(e){function t(i){return ao(i,e)}if(0<du.length){ao(du[0],e);for(var s=1;s<du.length;s++){var r=du[s];r.blockedOn===e&&(r.blockedOn=null)}}for(oi!==null&&ao(oi,e),ci!==null&&ao(ci,e),ui!==null&&ao(ui,e),Ko.forEach(t),Vo.forEach(t),s=0;s<ni.length;s++)r=ni[s],r.blockedOn===e&&(r.blockedOn=null);for(;0<ni.length&&(s=ni[0],s.blockedOn===null);)kS(s),s.blockedOn===null&&ni.shift()}var nl=Yr.ReactCurrentBatchConfig,Cd=!0;function ZP(e,t,s,r){var i=pt,a=nl.transition;nl.transition=null;try{pt=1,ov(e,t,s,r)}finally{pt=i,nl.transition=a}}function e2(e,t,s,r){var i=pt,a=nl.transition;nl.transition=null;try{pt=4,ov(e,t,s,r)}finally{pt=i,nl.transition=a}}function ov(e,t,s,r){if(Cd){var i=Op(e,t,s,r);if(i===null)nm(e,t,r,Ed,s),By(e,r);else if(QP(i,e,t,s,r))r.stopPropagation();else if(By(e,r),t&4&&-1<JP.indexOf(e)){for(;i!==null;){var a=Rc(i);if(a!==null&&jS(a),a=Op(e,t,s,r),a===null&&nm(e,t,r,Ed,s),a===i)break;i=a}i!==null&&r.stopPropagation()}else nm(e,t,r,null,s)}}var Ed=null;function Op(e,t,s,r){if(Ed=null,e=rv(r),e=qi(e),e!==null)if(t=pa(e),t===null)e=null;else if(s=t.tag,s===13){if(e=dS(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 Ed=e,null}function NS(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(UP()){case iv:return 1;case pS:return 4;case Nd:case BP:return 16;case gS:return 536870912;default:return 16}default:return 16}}var ri=null,cv=null,Qu=null;function SS(){if(Qu)return Qu;var e,t=cv,s=t.length,r,i="value"in ri?ri.value:ri.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 Qu=i.slice(e,1<r?1-r:void 0)}function Xu(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 hu(){return!0}function Hy(){return!1}function ls(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)?hu:Hy,this.isPropagationStopped=Hy,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=hu)},stopPropagation:function(){var s=this.nativeEvent;s&&(s.stopPropagation?s.stopPropagation():typeof s.cancelBubble!="unknown"&&(s.cancelBubble=!0),this.isPropagationStopped=hu)},persist:function(){},isPersistent:hu}),t}var Il={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},uv=ls(Il),$c=Mt({},Il,{view:0,detail:0}),t2=ls($c),Gf,Yf,lo,Ch=Mt({},$c,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:dv,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!==lo&&(lo&&e.type==="mousemove"?(Gf=e.screenX-lo.screenX,Yf=e.screenY-lo.screenY):Yf=Gf=0,lo=e),Gf)},movementY:function(e){return"movementY"in e?e.movementY:Yf}}),Ky=ls(Ch),n2=Mt({},Ch,{dataTransfer:0}),s2=ls(n2),r2=Mt({},$c,{relatedTarget:0}),qf=ls(r2),i2=Mt({},Il,{animationName:0,elapsedTime:0,pseudoElement:0}),a2=ls(i2),l2=Mt({},Il,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),o2=ls(l2),c2=Mt({},Il,{data:0}),Vy=ls(c2),u2={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},d2={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"},h2={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function f2(e){var t=this.nativeEvent;return t.getModifierState?t.getModifierState(e):(e=h2[e])?!!t[e]:!1}function dv(){return f2}var m2=Mt({},$c,{key:function(e){if(e.key){var t=u2[e.key]||e.key;if(t!=="Unidentified")return t}return e.type==="keypress"?(e=Xu(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?d2[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:dv,charCode:function(e){return e.type==="keypress"?Xu(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?Xu(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),p2=ls(m2),g2=Mt({},Ch,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),Gy=ls(g2),x2=Mt({},$c,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:dv}),v2=ls(x2),j2=Mt({},Il,{propertyName:0,elapsedTime:0,pseudoElement:0}),w2=ls(j2),y2=Mt({},Ch,{deltaX:function(e){return"deltaX"in e?e.deltaX:"wheelDeltaX"in e?-e.wheelDeltaX:0},deltaY:function(e){return"deltaY"in e?e.deltaY:"wheelDeltaY"in e?-e.wheelDeltaY:"wheelDelta"in e?-e.wheelDelta:0},deltaZ:0,deltaMode:0}),b2=ls(y2),k2=[9,13,27,32],hv=_r&&"CompositionEvent"in window,To=null;_r&&"documentMode"in document&&(To=document.documentMode);var N2=_r&&"TextEvent"in window&&!To,CS=_r&&(!hv||To&&8<To&&11>=To),Yy=" ",qy=!1;function ES(e,t){switch(e){case"keyup":return k2.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function AS(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var _a=!1;function S2(e,t){switch(e){case"compositionend":return AS(t);case"keypress":return t.which!==32?null:(qy=!0,Yy);case"textInput":return e=t.data,e===Yy&&qy?null:e;default:return null}}function C2(e,t){if(_a)return e==="compositionend"||!hv&&ES(e,t)?(e=SS(),Qu=cv=ri=null,_a=!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 CS&&t.locale!=="ko"?null:t.data;default:return null}}var E2={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 Jy(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t==="input"?!!E2[e.type]:t==="textarea"}function TS(e,t,s,r){aS(r),t=Ad(t,"onChange"),0<t.length&&(s=new uv("onChange","change",null,s,r),e.push({event:s,listeners:t}))}var $o=null,Yo=null;function A2(e){zS(e,0)}function Eh(e){var t=Ba(e);if(ZN(t))return e}function T2(e,t){if(e==="change")return t}var $S=!1;if(_r){var Jf;if(_r){var Qf="oninput"in document;if(!Qf){var Qy=document.createElement("div");Qy.setAttribute("oninput","return;"),Qf=typeof Qy.oninput=="function"}Jf=Qf}else Jf=!1;$S=Jf&&(!document.documentMode||9<document.documentMode)}function Xy(){$o&&($o.detachEvent("onpropertychange",RS),Yo=$o=null)}function RS(e){if(e.propertyName==="value"&&Eh(Yo)){var t=[];TS(t,Yo,e,rv(e)),uS(A2,t)}}function $2(e,t,s){e==="focusin"?(Xy(),$o=t,Yo=s,$o.attachEvent("onpropertychange",RS)):e==="focusout"&&Xy()}function R2(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return Eh(Yo)}function I2(e,t){if(e==="click")return Eh(t)}function P2(e,t){if(e==="input"||e==="change")return Eh(t)}function M2(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var zs=typeof Object.is=="function"?Object.is:M2;function qo(e,t){if(zs(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(!vp.call(t,i)||!zs(e[i],t[i]))return!1}return!0}function Zy(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function eb(e,t){var s=Zy(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=Zy(s)}}function IS(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?IS(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function PS(){for(var e=window,t=yd();t instanceof e.HTMLIFrameElement;){try{var s=typeof t.contentWindow.location.href=="string"}catch{s=!1}if(s)e=t.contentWindow;else break;t=yd(e.document)}return t}function fv(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 D2(e){var t=PS(),s=e.focusedElem,r=e.selectionRange;if(t!==s&&s&&s.ownerDocument&&IS(s.ownerDocument.documentElement,s)){if(r!==null&&fv(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=eb(s,a);var l=eb(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 O2=_r&&"documentMode"in document&&11>=document.documentMode,za=null,Lp=null,Ro=null,Fp=!1;function tb(e,t,s){var r=s.window===s?s.document:s.nodeType===9?s:s.ownerDocument;Fp||za==null||za!==yd(r)||(r=za,"selectionStart"in r&&fv(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}),Ro&&qo(Ro,r)||(Ro=r,r=Ad(Lp,"onSelect"),0<r.length&&(t=new uv("onSelect","select",null,t,s),e.push({event:t,listeners:r}),t.target=za)))}function fu(e,t){var s={};return s[e.toLowerCase()]=t.toLowerCase(),s["Webkit"+e]="webkit"+t,s["Moz"+e]="moz"+t,s}var Ua={animationend:fu("Animation","AnimationEnd"),animationiteration:fu("Animation","AnimationIteration"),animationstart:fu("Animation","AnimationStart"),transitionend:fu("Transition","TransitionEnd")},Xf={},MS={};_r&&(MS=document.createElement("div").style,"AnimationEvent"in window||(delete Ua.animationend.animation,delete Ua.animationiteration.animation,delete Ua.animationstart.animation),"TransitionEvent"in window||delete Ua.transitionend.transition);function Ah(e){if(Xf[e])return Xf[e];if(!Ua[e])return e;var t=Ua[e],s;for(s in t)if(t.hasOwnProperty(s)&&s in MS)return Xf[e]=t[s];return e}var DS=Ah("animationend"),OS=Ah("animationiteration"),LS=Ah("animationstart"),FS=Ah("transitionend"),_S=new Map,nb="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 Ai(e,t){_S.set(e,t),ma(t,[e])}for(var Zf=0;Zf<nb.length;Zf++){var em=nb[Zf],L2=em.toLowerCase(),F2=em[0].toUpperCase()+em.slice(1);Ai(L2,"on"+F2)}Ai(DS,"onAnimationEnd");Ai(OS,"onAnimationIteration");Ai(LS,"onAnimationStart");Ai("dblclick","onDoubleClick");Ai("focusin","onFocus");Ai("focusout","onBlur");Ai(FS,"onTransitionEnd");dl("onMouseEnter",["mouseout","mouseover"]);dl("onMouseLeave",["mouseout","mouseover"]);dl("onPointerEnter",["pointerout","pointerover"]);dl("onPointerLeave",["pointerout","pointerover"]);ma("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));ma("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));ma("onBeforeInput",["compositionend","keypress","textInput","paste"]);ma("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));ma("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));ma("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var bo="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(" "),_2=new Set("cancel close invalid load scroll toggle".split(" ").concat(bo));function sb(e,t,s){var r=e.type||"unknown-event";e.currentTarget=s,LP(r,t,void 0,e),e.currentTarget=null}function zS(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;sb(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;sb(i,o,u),a=c}}}if(kd)throw e=Pp,kd=!1,Pp=null,e}function Nt(e,t){var s=t[Wp];s===void 0&&(s=t[Wp]=new Set);var r=e+"__bubble";s.has(r)||(US(t,e,2,!1),s.add(r))}function tm(e,t,s){var r=0;t&&(r|=4),US(s,e,r,t)}var mu="_reactListening"+Math.random().toString(36).slice(2);function Jo(e){if(!e[mu]){e[mu]=!0,YN.forEach(function(s){s!=="selectionchange"&&(_2.has(s)||tm(s,!1,e),tm(s,!0,e))});var t=e.nodeType===9?e:e.ownerDocument;t===null||t[mu]||(t[mu]=!0,tm("selectionchange",!1,t))}}function US(e,t,s,r){switch(NS(t)){case 1:var i=ZP;break;case 4:i=e2;break;default:i=ov}s=i.bind(null,t,s,e),i=void 0,!Ip||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 nm(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=qi(o),l===null)return;if(c=l.tag,c===5||c===6){r=a=l;continue e}o=o.parentNode}}r=r.return}uS(function(){var u=a,h=rv(s),f=[];e:{var m=_S.get(e);if(m!==void 0){var p=uv,g=e;switch(e){case"keypress":if(Xu(s)===0)break e;case"keydown":case"keyup":p=p2;break;case"focusin":g="focus",p=qf;break;case"focusout":g="blur",p=qf;break;case"beforeblur":case"afterblur":p=qf;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=Ky;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":p=s2;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":p=v2;break;case DS:case OS:case LS:p=a2;break;case FS:p=w2;break;case"scroll":p=t2;break;case"wheel":p=b2;break;case"copy":case"cut":case"paste":p=o2;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":p=Gy}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=Ho(x,j),y!=null&&v.push(Qo(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)&&(qi(g)||g[zr]))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?qi(g):null,g!==null&&(b=pa(g),g!==b||g.tag!==5&&g.tag!==6)&&(g=null)):(p=null,g=u),p!==g)){if(v=Ky,y="onMouseLeave",j="onMouseEnter",x="mouse",(e==="pointerout"||e==="pointerover")&&(v=Gy,y="onPointerLeave",j="onPointerEnter",x="pointer"),b=p==null?m:Ba(p),w=g==null?m:Ba(g),m=new v(y,x+"leave",p,s,h),m.target=b,m.relatedTarget=w,y=null,qi(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=Ea(w))x++;for(w=0,y=j;y;y=Ea(y))w++;for(;0<x-w;)v=Ea(v),x--;for(;0<w-x;)j=Ea(j),w--;for(;x--;){if(v===j||j!==null&&v===j.alternate)break t;v=Ea(v),j=Ea(j)}v=null}else v=null;p!==null&&rb(f,m,p,v,!1),g!==null&&b!==null&&rb(f,b,g,v,!0)}}e:{if(m=u?Ba(u):window,p=m.nodeName&&m.nodeName.toLowerCase(),p==="select"||p==="input"&&m.type==="file")var k=T2;else if(Jy(m))if($S)k=P2;else{k=R2;var N=$2}else(p=m.nodeName)&&p.toLowerCase()==="input"&&(m.type==="checkbox"||m.type==="radio")&&(k=I2);if(k&&(k=k(e,u))){TS(f,k,s,h);break e}N&&N(e,m,u),e==="focusout"&&(N=m._wrapperState)&&N.controlled&&m.type==="number"&&Sp(m,"number",m.value)}switch(N=u?Ba(u):window,e){case"focusin":(Jy(N)||N.contentEditable==="true")&&(za=N,Lp=u,Ro=null);break;case"focusout":Ro=Lp=za=null;break;case"mousedown":Fp=!0;break;case"contextmenu":case"mouseup":case"dragend":Fp=!1,tb(f,s,h);break;case"selectionchange":if(O2)break;case"keydown":case"keyup":tb(f,s,h)}var S;if(hv)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 _a?ES(e,s)&&(C="onCompositionEnd"):e==="keydown"&&s.keyCode===229&&(C="onCompositionStart");C&&(CS&&s.locale!=="ko"&&(_a||C!=="onCompositionStart"?C==="onCompositionEnd"&&_a&&(S=SS()):(ri=h,cv="value"in ri?ri.value:ri.textContent,_a=!0)),N=Ad(u,C),0<N.length&&(C=new Vy(C,e,null,s,h),f.push({event:C,listeners:N}),S?C.data=S:(S=AS(s),S!==null&&(C.data=S)))),(S=N2?S2(e,s):C2(e,s))&&(u=Ad(u,"onBeforeInput"),0<u.length&&(h=new Vy("onBeforeInput","beforeinput",null,s,h),f.push({event:h,listeners:u}),h.data=S))}zS(f,t)})}function Qo(e,t,s){return{instance:e,listener:t,currentTarget:s}}function Ad(e,t){for(var s=t+"Capture",r=[];e!==null;){var i=e,a=i.stateNode;i.tag===5&&a!==null&&(i=a,a=Ho(e,s),a!=null&&r.unshift(Qo(e,a,i)),a=Ho(e,t),a!=null&&r.push(Qo(e,a,i))),e=e.return}return r}function Ea(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function rb(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=Ho(s,a),c!=null&&l.unshift(Qo(s,c,o))):i||(c=Ho(s,a),c!=null&&l.push(Qo(s,c,o)))),s=s.return}l.length!==0&&e.push({event:t,listeners:l})}var z2=/\r\n?/g,U2=/\u0000|\uFFFD/g;function ib(e){return(typeof e=="string"?e:""+e).replace(z2,`
38
- `).replace(U2,"")}function pu(e,t,s){if(t=ib(t),ib(e)!==t&&s)throw Error(xe(425))}function Td(){}var _p=null,zp=null;function Up(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 Bp=typeof setTimeout=="function"?setTimeout:void 0,B2=typeof clearTimeout=="function"?clearTimeout:void 0,ab=typeof Promise=="function"?Promise:void 0,W2=typeof queueMicrotask=="function"?queueMicrotask:typeof ab<"u"?function(e){return ab.resolve(null).then(e).catch(H2)}:Bp;function H2(e){setTimeout(function(){throw e})}function sm(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),Go(t);return}r--}else s!=="$"&&s!=="$?"&&s!=="$!"||r++;s=i}while(s);Go(t)}function di(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 lb(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 Pl=Math.random().toString(36).slice(2),sr="__reactFiber$"+Pl,Xo="__reactProps$"+Pl,zr="__reactContainer$"+Pl,Wp="__reactEvents$"+Pl,K2="__reactListeners$"+Pl,V2="__reactHandles$"+Pl;function qi(e){var t=e[sr];if(t)return t;for(var s=e.parentNode;s;){if(t=s[zr]||s[sr]){if(s=t.alternate,t.child!==null||s!==null&&s.child!==null)for(e=lb(e);e!==null;){if(s=e[sr])return s;e=lb(e)}return t}e=s,s=e.parentNode}return null}function Rc(e){return e=e[sr]||e[zr],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function Ba(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(xe(33))}function Th(e){return e[Xo]||null}var Hp=[],Wa=-1;function Ti(e){return{current:e}}function Ct(e){0>Wa||(e.current=Hp[Wa],Hp[Wa]=null,Wa--)}function bt(e,t){Wa++,Hp[Wa]=e.current,e.current=t}var wi={},bn=Ti(wi),Bn=Ti(!1),ra=wi;function hl(e,t){var s=e.type.contextTypes;if(!s)return wi;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 Wn(e){return e=e.childContextTypes,e!=null}function $d(){Ct(Bn),Ct(bn)}function ob(e,t,s){if(bn.current!==wi)throw Error(xe(168));bt(bn,t),bt(Bn,s)}function BS(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,$P(e)||"Unknown",i));return Mt({},s,r)}function Rd(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||wi,ra=bn.current,bt(bn,e),bt(Bn,Bn.current),!0}function cb(e,t,s){var r=e.stateNode;if(!r)throw Error(xe(169));s?(e=BS(e,t,ra),r.__reactInternalMemoizedMergedChildContext=e,Ct(Bn),Ct(bn),bt(bn,e)):Ct(Bn),bt(Bn,s)}var Cr=null,$h=!1,rm=!1;function WS(e){Cr===null?Cr=[e]:Cr.push(e)}function G2(e){$h=!0,WS(e)}function $i(){if(!rm&&Cr!==null){rm=!0;var e=0,t=pt;try{var s=Cr;for(pt=1;e<s.length;e++){var r=s[e];do r=r(!0);while(r!==null)}Cr=null,$h=!1}catch(i){throw Cr!==null&&(Cr=Cr.slice(e+1)),mS(iv,$i),i}finally{pt=t,rm=!1}}return null}var Ha=[],Ka=0,Id=null,Pd=0,gs=[],xs=0,ia=null,$r=1,Rr="";function Hi(e,t){Ha[Ka++]=Pd,Ha[Ka++]=Id,Id=e,Pd=t}function HS(e,t,s){gs[xs++]=$r,gs[xs++]=Rr,gs[xs++]=ia,ia=e;var r=$r;e=Rr;var i=32-Os(r)-1;r&=~(1<<i),s+=1;var a=32-Os(t)+i;if(30<a){var l=i-i%5;a=(r&(1<<l)-1).toString(32),r>>=l,i-=l,$r=1<<32-Os(t)+i|s<<i|r,Rr=a+e}else $r=1<<a|s<<i|r,Rr=e}function mv(e){e.return!==null&&(Hi(e,1),HS(e,1,0))}function pv(e){for(;e===Id;)Id=Ha[--Ka],Ha[Ka]=null,Pd=Ha[--Ka],Ha[Ka]=null;for(;e===ia;)ia=gs[--xs],gs[xs]=null,Rr=gs[--xs],gs[xs]=null,$r=gs[--xs],gs[xs]=null}var ts=null,Zn=null,Tt=!1,Ms=null;function KS(e,t){var s=ys(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 ub(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,ts=e,Zn=di(t.firstChild),!0):!1;case 6:return t=e.pendingProps===""||t.nodeType!==3?null:t,t!==null?(e.stateNode=t,ts=e,Zn=null,!0):!1;case 13:return t=t.nodeType!==8?null:t,t!==null?(s=ia!==null?{id:$r,overflow:Rr}:null,e.memoizedState={dehydrated:t,treeContext:s,retryLane:1073741824},s=ys(18,null,null,0),s.stateNode=t,s.return=e,e.child=s,ts=e,Zn=null,!0):!1;default:return!1}}function Kp(e){return(e.mode&1)!==0&&(e.flags&128)===0}function Vp(e){if(Tt){var t=Zn;if(t){var s=t;if(!ub(e,t)){if(Kp(e))throw Error(xe(418));t=di(s.nextSibling);var r=ts;t&&ub(e,t)?KS(r,s):(e.flags=e.flags&-4097|2,Tt=!1,ts=e)}}else{if(Kp(e))throw Error(xe(418));e.flags=e.flags&-4097|2,Tt=!1,ts=e}}}function db(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;ts=e}function gu(e){if(e!==ts)return!1;if(!Tt)return db(e),Tt=!0,!1;var t;if((t=e.tag!==3)&&!(t=e.tag!==5)&&(t=e.type,t=t!=="head"&&t!=="body"&&!Up(e.type,e.memoizedProps)),t&&(t=Zn)){if(Kp(e))throw VS(),Error(xe(418));for(;t;)KS(e,t),t=di(t.nextSibling)}if(db(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){Zn=di(e.nextSibling);break e}t--}else s!=="$"&&s!=="$!"&&s!=="$?"||t++}e=e.nextSibling}Zn=null}}else Zn=ts?di(e.stateNode.nextSibling):null;return!0}function VS(){for(var e=Zn;e;)e=di(e.nextSibling)}function fl(){Zn=ts=null,Tt=!1}function gv(e){Ms===null?Ms=[e]:Ms.push(e)}var Y2=Yr.ReactCurrentBatchConfig;function oo(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 xu(e,t){throw e=Object.prototype.toString.call(t),Error(xe(31,e==="[object Object]"?"object with keys {"+Object.keys(t).join(", ")+"}":e))}function hb(e){var t=e._init;return t(e._payload)}function GS(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=pi(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=dm(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===Fa?h(j,x,w.props.children,y,w.key):x!==null&&(x.elementType===k||typeof k=="object"&&k!==null&&k.$$typeof===ei&&hb(k)===x.type)?(y=i(x,w.props),y.ref=oo(j,x,w),y.return=j,y):(y=id(w.type,w.key,w.props,null,j.mode,y),y.ref=oo(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=hm(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=ta(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=dm(""+x,j.mode,w),x.return=j,x;if(typeof x=="object"&&x!==null){switch(x.$$typeof){case au:return w=id(x.type,x.key,x.props,null,j.mode,w),w.ref=oo(j,null,x),w.return=j,w;case La:return x=hm(x,j.mode,w),x.return=j,x;case ei:var y=x._init;return f(j,y(x._payload),w)}if(wo(x)||so(x))return x=ta(x,j.mode,w,null),x.return=j,x;xu(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 au:return w.key===k?c(j,x,w,y):null;case La:return w.key===k?u(j,x,w,y):null;case ei:return k=w._init,m(j,x,k(w._payload),y)}if(wo(w)||so(w))return k!==null?null:h(j,x,w,y,null);xu(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 au:return j=j.get(y.key===null?w:y.key)||null,c(x,j,y,k);case La:return j=j.get(y.key===null?w:y.key)||null,u(x,j,y,k);case ei:var N=y._init;return p(j,x,w,N(y._payload),k)}if(wo(y)||so(y))return j=j.get(w)||null,h(x,j,y,k,null);xu(x,y)}return null}function g(j,x,w,y){for(var k=null,N=null,S=x,C=x=0,T=null;S!==null&&C<w.length;C++){S.index>C?(T=S,S=null):T=S.sibling;var R=m(j,S,w[C],y);if(R===null){S===null&&(S=T);break}e&&S&&R.alternate===null&&t(j,S),x=a(R,x,C),N===null?k=R:N.sibling=R,N=R,S=T}if(C===w.length)return s(j,S),Tt&&Hi(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 Tt&&Hi(j,C),k}for(S=r(j,S);C<w.length;C++)T=p(S,j,C,w[C],y),T!==null&&(e&&T.alternate!==null&&S.delete(T.key===null?C:T.key),x=a(T,x,C),N===null?k=T:N.sibling=T,N=T);return e&&S.forEach(function(I){return t(j,I)}),Tt&&Hi(j,C),k}function v(j,x,w,y){var k=so(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,T=null,R=w.next();S!==null&&!R.done;C++,R=w.next()){S.index>C?(T=S,S=null):T=S.sibling;var I=m(j,S,R.value,y);if(I===null){S===null&&(S=T);break}e&&S&&I.alternate===null&&t(j,S),x=a(I,x,C),N===null?k=I:N.sibling=I,N=I,S=T}if(R.done)return s(j,S),Tt&&Hi(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 Tt&&Hi(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)}),Tt&&Hi(j,C),k}function b(j,x,w,y){if(typeof w=="object"&&w!==null&&w.type===Fa&&w.key===null&&(w=w.props.children),typeof w=="object"&&w!==null){switch(w.$$typeof){case au:e:{for(var k=w.key,N=x;N!==null;){if(N.key===k){if(k=w.type,k===Fa){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===ei&&hb(k)===N.type){s(j,N.sibling),x=i(N,w.props),x.ref=oo(j,N,w),x.return=j,j=x;break e}s(j,N);break}else t(j,N);N=N.sibling}w.type===Fa?(x=ta(w.props.children,j.mode,y,w.key),x.return=j,j=x):(y=id(w.type,w.key,w.props,null,j.mode,y),y.ref=oo(j,x,w),y.return=j,j=y)}return l(j);case La: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=hm(w,j.mode,y),x.return=j,j=x}return l(j);case ei:return N=w._init,b(j,x,N(w._payload),y)}if(wo(w))return g(j,x,w,y);if(so(w))return v(j,x,w,y);xu(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=dm(w,j.mode,y),x.return=j,j=x),l(j)):s(j,x)}return b}var ml=GS(!0),YS=GS(!1),Md=Ti(null),Dd=null,Va=null,xv=null;function vv(){xv=Va=Dd=null}function jv(e){var t=Md.current;Ct(Md),e._currentValue=t}function Gp(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 sl(e,t){Dd=e,xv=Va=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(zn=!0),e.firstContext=null)}function Ss(e){var t=e._currentValue;if(xv!==e)if(e={context:e,memoizedValue:t,next:null},Va===null){if(Dd===null)throw Error(xe(308));Va=e,Dd.dependencies={lanes:0,firstContext:e}}else Va=Va.next=e;return t}var Ji=null;function wv(e){Ji===null?Ji=[e]:Ji.push(e)}function qS(e,t,s,r){var i=t.interleaved;return i===null?(s.next=s,wv(t)):(s.next=i.next,i.next=s),t.interleaved=s,Ur(e,r)}function Ur(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 ti=!1;function yv(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function JS(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 Pr(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function hi(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,Ur(e,s)}return i=r.interleaved,i===null?(t.next=t,wv(r)):(t.next=i.next,i.next=t),r.interleaved=t,Ur(e,s)}function Zu(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,av(e,s)}}function fb(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 Od(e,t,s,r){var i=e.updateQueue;ti=!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:ti=!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);la|=l,e.lanes=l,e.memoizedState=f}}function mb(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 Ic={},or=Ti(Ic),Zo=Ti(Ic),ec=Ti(Ic);function Qi(e){if(e===Ic)throw Error(xe(174));return e}function bv(e,t){switch(bt(ec,t),bt(Zo,e),bt(or,Ic),e=t.nodeType,e){case 9:case 11:t=(t=t.documentElement)?t.namespaceURI:Ep(null,"");break;default:e=e===8?t.parentNode:t,t=e.namespaceURI||null,e=e.tagName,t=Ep(t,e)}Ct(or),bt(or,t)}function pl(){Ct(or),Ct(Zo),Ct(ec)}function QS(e){Qi(ec.current);var t=Qi(or.current),s=Ep(t,e.type);t!==s&&(bt(Zo,e),bt(or,s))}function kv(e){Zo.current===e&&(Ct(or),Ct(Zo))}var Rt=Ti(0);function Ld(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 im=[];function Nv(){for(var e=0;e<im.length;e++)im[e]._workInProgressVersionPrimary=null;im.length=0}var ed=Yr.ReactCurrentDispatcher,am=Yr.ReactCurrentBatchConfig,aa=0,It=null,Jt=null,sn=null,Fd=!1,Io=!1,tc=0,q2=0;function vn(){throw Error(xe(321))}function Sv(e,t){if(t===null)return!1;for(var s=0;s<t.length&&s<e.length;s++)if(!zs(e[s],t[s]))return!1;return!0}function Cv(e,t,s,r,i,a){if(aa=a,It=t,t.memoizedState=null,t.updateQueue=null,t.lanes=0,ed.current=e===null||e.memoizedState===null?Z2:eM,e=s(r,i),Io){a=0;do{if(Io=!1,tc=0,25<=a)throw Error(xe(301));a+=1,sn=Jt=null,t.updateQueue=null,ed.current=tM,e=s(r,i)}while(Io)}if(ed.current=_d,t=Jt!==null&&Jt.next!==null,aa=0,sn=Jt=It=null,Fd=!1,t)throw Error(xe(300));return e}function Ev(){var e=tc!==0;return tc=0,e}function er(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return sn===null?It.memoizedState=sn=e:sn=sn.next=e,sn}function Cs(){if(Jt===null){var e=It.alternate;e=e!==null?e.memoizedState:null}else e=Jt.next;var t=sn===null?It.memoizedState:sn.next;if(t!==null)sn=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},sn===null?It.memoizedState=sn=e:sn=sn.next=e}return sn}function nc(e,t){return typeof t=="function"?t(e):t}function lm(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((aa&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,la|=h}u=u.next}while(u!==null&&u!==a);c===null?l=r:c.next=o,zs(r,t.memoizedState)||(zn=!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,la|=a,i=i.next;while(i!==e)}else i===null&&(s.lanes=0);return[t.memoizedState,s.dispatch]}function om(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);zs(a,t.memoizedState)||(zn=!0),t.memoizedState=a,t.baseQueue===null&&(t.baseState=a),s.lastRenderedState=a}return[a,r]}function XS(){}function ZS(e,t){var s=It,r=Cs(),i=t(),a=!zs(r.memoizedState,i);if(a&&(r.memoizedState=i,zn=!0),r=r.queue,Av(nC.bind(null,s,r,e),[e]),r.getSnapshot!==t||a||sn!==null&&sn.memoizedState.tag&1){if(s.flags|=2048,sc(9,tC.bind(null,s,r,i,t),void 0,null),cn===null)throw Error(xe(349));aa&30||eC(s,t,i)}return i}function eC(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 tC(e,t,s,r){t.value=s,t.getSnapshot=r,sC(t)&&rC(e)}function nC(e,t,s){return s(function(){sC(t)&&rC(e)})}function sC(e){var t=e.getSnapshot;e=e.value;try{var s=t();return!zs(e,s)}catch{return!0}}function rC(e){var t=Ur(e,1);t!==null&&Ls(t,e,1,-1)}function pb(e){var t=er();return typeof e=="function"&&(e=e()),t.memoizedState=t.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:nc,lastRenderedState:e},t.queue=e,e=e.dispatch=X2.bind(null,It,e),[t.memoizedState,e]}function sc(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 iC(){return Cs().memoizedState}function td(e,t,s,r){var i=er();It.flags|=e,i.memoizedState=sc(1|t,s,void 0,r===void 0?null:r)}function Rh(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&&Sv(r,l.deps)){i.memoizedState=sc(t,s,a,r);return}}It.flags|=e,i.memoizedState=sc(1|t,s,a,r)}function gb(e,t){return td(8390656,8,e,t)}function Av(e,t){return Rh(2048,8,e,t)}function aC(e,t){return Rh(4,2,e,t)}function lC(e,t){return Rh(4,4,e,t)}function oC(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 cC(e,t,s){return s=s!=null?s.concat([e]):null,Rh(4,4,oC.bind(null,t,e),s)}function Tv(){}function uC(e,t){var s=Cs();t=t===void 0?null:t;var r=s.memoizedState;return r!==null&&t!==null&&Sv(t,r[1])?r[0]:(s.memoizedState=[e,t],e)}function dC(e,t){var s=Cs();t=t===void 0?null:t;var r=s.memoizedState;return r!==null&&t!==null&&Sv(t,r[1])?r[0]:(e=e(),s.memoizedState=[e,t],e)}function hC(e,t,s){return aa&21?(zs(s,t)||(s=xS(),It.lanes|=s,la|=s,e.baseState=!0),t):(e.baseState&&(e.baseState=!1,zn=!0),e.memoizedState=s)}function J2(e,t){var s=pt;pt=s!==0&&4>s?s:4,e(!0);var r=am.transition;am.transition={};try{e(!1),t()}finally{pt=s,am.transition=r}}function fC(){return Cs().memoizedState}function Q2(e,t,s){var r=mi(e);if(s={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null},mC(e))pC(t,s);else if(s=qS(e,t,s,r),s!==null){var i=An();Ls(s,e,r,i),gC(s,t,r)}}function X2(e,t,s){var r=mi(e),i={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null};if(mC(e))pC(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,zs(o,l)){var c=t.interleaved;c===null?(i.next=i,wv(t)):(i.next=c.next,c.next=i),t.interleaved=i;return}}catch{}finally{}s=qS(e,t,i,r),s!==null&&(i=An(),Ls(s,e,r,i),gC(s,t,r))}}function mC(e){var t=e.alternate;return e===It||t!==null&&t===It}function pC(e,t){Io=Fd=!0;var s=e.pending;s===null?t.next=t:(t.next=s.next,s.next=t),e.pending=t}function gC(e,t,s){if(s&4194240){var r=t.lanes;r&=e.pendingLanes,s|=r,t.lanes=s,av(e,s)}}var _d={readContext:Ss,useCallback:vn,useContext:vn,useEffect:vn,useImperativeHandle:vn,useInsertionEffect:vn,useLayoutEffect:vn,useMemo:vn,useReducer:vn,useRef:vn,useState:vn,useDebugValue:vn,useDeferredValue:vn,useTransition:vn,useMutableSource:vn,useSyncExternalStore:vn,useId:vn,unstable_isNewReconciler:!1},Z2={readContext:Ss,useCallback:function(e,t){return er().memoizedState=[e,t===void 0?null:t],e},useContext:Ss,useEffect:gb,useImperativeHandle:function(e,t,s){return s=s!=null?s.concat([e]):null,td(4194308,4,oC.bind(null,t,e),s)},useLayoutEffect:function(e,t){return td(4194308,4,e,t)},useInsertionEffect:function(e,t){return td(4,2,e,t)},useMemo:function(e,t){var s=er();return t=t===void 0?null:t,e=e(),s.memoizedState=[e,t],e},useReducer:function(e,t,s){var r=er();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=Q2.bind(null,It,e),[r.memoizedState,e]},useRef:function(e){var t=er();return e={current:e},t.memoizedState=e},useState:pb,useDebugValue:Tv,useDeferredValue:function(e){return er().memoizedState=e},useTransition:function(){var e=pb(!1),t=e[0];return e=J2.bind(null,e[1]),er().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,s){var r=It,i=er();if(Tt){if(s===void 0)throw Error(xe(407));s=s()}else{if(s=t(),cn===null)throw Error(xe(349));aa&30||eC(r,t,s)}i.memoizedState=s;var a={value:s,getSnapshot:t};return i.queue=a,gb(nC.bind(null,r,a,e),[e]),r.flags|=2048,sc(9,tC.bind(null,r,a,s,t),void 0,null),s},useId:function(){var e=er(),t=cn.identifierPrefix;if(Tt){var s=Rr,r=$r;s=(r&~(1<<32-Os(r)-1)).toString(32)+s,t=":"+t+"R"+s,s=tc++,0<s&&(t+="H"+s.toString(32)),t+=":"}else s=q2++,t=":"+t+"r"+s.toString(32)+":";return e.memoizedState=t},unstable_isNewReconciler:!1},eM={readContext:Ss,useCallback:uC,useContext:Ss,useEffect:Av,useImperativeHandle:cC,useInsertionEffect:aC,useLayoutEffect:lC,useMemo:dC,useReducer:lm,useRef:iC,useState:function(){return lm(nc)},useDebugValue:Tv,useDeferredValue:function(e){var t=Cs();return hC(t,Jt.memoizedState,e)},useTransition:function(){var e=lm(nc)[0],t=Cs().memoizedState;return[e,t]},useMutableSource:XS,useSyncExternalStore:ZS,useId:fC,unstable_isNewReconciler:!1},tM={readContext:Ss,useCallback:uC,useContext:Ss,useEffect:Av,useImperativeHandle:cC,useInsertionEffect:aC,useLayoutEffect:lC,useMemo:dC,useReducer:om,useRef:iC,useState:function(){return om(nc)},useDebugValue:Tv,useDeferredValue:function(e){var t=Cs();return Jt===null?t.memoizedState=e:hC(t,Jt.memoizedState,e)},useTransition:function(){var e=om(nc)[0],t=Cs().memoizedState;return[e,t]},useMutableSource:XS,useSyncExternalStore:ZS,useId:fC,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 Yp(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 Ih={isMounted:function(e){return(e=e._reactInternals)?pa(e)===e:!1},enqueueSetState:function(e,t,s){e=e._reactInternals;var r=An(),i=mi(e),a=Pr(r,i);a.payload=t,s!=null&&(a.callback=s),t=hi(e,a,i),t!==null&&(Ls(t,e,i,r),Zu(t,e,i))},enqueueReplaceState:function(e,t,s){e=e._reactInternals;var r=An(),i=mi(e),a=Pr(r,i);a.tag=1,a.payload=t,s!=null&&(a.callback=s),t=hi(e,a,i),t!==null&&(Ls(t,e,i,r),Zu(t,e,i))},enqueueForceUpdate:function(e,t){e=e._reactInternals;var s=An(),r=mi(e),i=Pr(s,r);i.tag=2,t!=null&&(i.callback=t),t=hi(e,i,r),t!==null&&(Ls(t,e,r,s),Zu(t,e,r))}};function xb(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?!qo(s,r)||!qo(i,a):!0}function xC(e,t,s){var r=!1,i=wi,a=t.contextType;return typeof a=="object"&&a!==null?a=Ss(a):(i=Wn(t)?ra:bn.current,r=t.contextTypes,a=(r=r!=null)?hl(e,i):wi),t=new t(s,a),e.memoizedState=t.state!==null&&t.state!==void 0?t.state:null,t.updater=Ih,e.stateNode=t,t._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=i,e.__reactInternalMemoizedMaskedChildContext=a),t}function vb(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&&Ih.enqueueReplaceState(t,t.state,null)}function qp(e,t,s,r){var i=e.stateNode;i.props=s,i.state=e.memoizedState,i.refs={},yv(e);var a=t.contextType;typeof a=="object"&&a!==null?i.context=Ss(a):(a=Wn(t)?ra:bn.current,i.context=hl(e,a)),i.state=e.memoizedState,a=t.getDerivedStateFromProps,typeof a=="function"&&(Yp(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&&Ih.enqueueReplaceState(i,i.state,null),Od(e,s,i,r),i.state=e.memoizedState),typeof i.componentDidMount=="function"&&(e.flags|=4194308)}function gl(e,t){try{var s="",r=t;do s+=TP(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 cm(e,t,s){return{value:e,source:null,stack:s??null,digest:t??null}}function Jp(e,t){try{console.error(t.value)}catch(s){setTimeout(function(){throw s})}}var nM=typeof WeakMap=="function"?WeakMap:Map;function vC(e,t,s){s=Pr(-1,s),s.tag=3,s.payload={element:null};var r=t.value;return s.callback=function(){Ud||(Ud=!0,ag=r),Jp(e,t)},s}function jC(e,t,s){s=Pr(-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(){Jp(e,t)}}var a=e.stateNode;return a!==null&&typeof a.componentDidCatch=="function"&&(s.callback=function(){Jp(e,t),typeof r!="function"&&(fi===null?fi=new Set([this]):fi.add(this));var l=t.stack;this.componentDidCatch(t.value,{componentStack:l!==null?l:""})}),s}function jb(e,t,s){var r=e.pingCache;if(r===null){r=e.pingCache=new nM;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=gM.bind(null,e,t,s),t.then(e,e))}function wb(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 yb(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=Pr(-1,1),t.tag=2,hi(s,t,1))),s.lanes|=1),e)}var sM=Yr.ReactCurrentOwner,zn=!1;function Cn(e,t,s,r){t.child=e===null?YS(t,null,s,r):ml(t,e.child,s,r)}function bb(e,t,s,r,i){s=s.render;var a=t.ref;return sl(t,i),r=Cv(e,t,s,r,a,i),s=Ev(),e!==null&&!zn?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,Br(e,t,i)):(Tt&&s&&mv(t),t.flags|=1,Cn(e,t,r,i),t.child)}function kb(e,t,s,r,i){if(e===null){var a=s.type;return typeof a=="function"&&!Lv(a)&&a.defaultProps===void 0&&s.compare===null&&s.defaultProps===void 0?(t.tag=15,t.type=a,wC(e,t,a,r,i)):(e=id(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:qo,s(l,r)&&e.ref===t.ref)return Br(e,t,i)}return t.flags|=1,e=pi(a,r),e.ref=t.ref,e.return=t,t.child=e}function wC(e,t,s,r,i){if(e!==null){var a=e.memoizedProps;if(qo(a,r)&&e.ref===t.ref)if(zn=!1,t.pendingProps=r=a,(e.lanes&i)!==0)e.flags&131072&&(zn=!0);else return t.lanes=e.lanes,Br(e,t,i)}return Qp(e,t,s,r,i)}function yC(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},bt(Ya,Qn),Qn|=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,bt(Ya,Qn),Qn|=e,null;t.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=a!==null?a.baseLanes:s,bt(Ya,Qn),Qn|=r}else a!==null?(r=a.baseLanes|s,t.memoizedState=null):r=s,bt(Ya,Qn),Qn|=r;return Cn(e,t,i,s),t.child}function bC(e,t){var s=t.ref;(e===null&&s!==null||e!==null&&e.ref!==s)&&(t.flags|=512,t.flags|=2097152)}function Qp(e,t,s,r,i){var a=Wn(s)?ra:bn.current;return a=hl(t,a),sl(t,i),s=Cv(e,t,s,r,a,i),r=Ev(),e!==null&&!zn?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,Br(e,t,i)):(Tt&&r&&mv(t),t.flags|=1,Cn(e,t,s,i),t.child)}function Nb(e,t,s,r,i){if(Wn(s)){var a=!0;Rd(t)}else a=!1;if(sl(t,i),t.stateNode===null)nd(e,t),xC(t,s,r),qp(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=Wn(s)?ra:bn.current,u=hl(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)&&vb(t,l,r,u),ti=!1;var m=t.memoizedState;l.state=m,Od(t,r,l,i),c=t.memoizedState,o!==r||m!==c||Bn.current||ti?(typeof h=="function"&&(Yp(t,s,h,r),c=t.memoizedState),(o=ti||xb(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,JS(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=Wn(s)?ra:bn.current,c=hl(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)&&vb(t,l,r,c),ti=!1,m=t.memoizedState,l.state=m,Od(t,r,l,i);var g=t.memoizedState;o!==f||m!==g||Bn.current||ti?(typeof p=="function"&&(Yp(t,s,p,r),g=t.memoizedState),(u=ti||xb(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 Xp(e,t,s,r,a,i)}function Xp(e,t,s,r,i,a){bC(e,t);var l=(t.flags&128)!==0;if(!r&&!l)return i&&cb(t,s,!1),Br(e,t,a);r=t.stateNode,sM.current=t;var o=l&&typeof s.getDerivedStateFromError!="function"?null:r.render();return t.flags|=1,e!==null&&l?(t.child=ml(t,e.child,null,a),t.child=ml(t,null,o,a)):Cn(e,t,o,a),t.memoizedState=r.state,i&&cb(t,s,!0),t.child}function kC(e){var t=e.stateNode;t.pendingContext?ob(e,t.pendingContext,t.pendingContext!==t.context):t.context&&ob(e,t.context,!1),bv(e,t.containerInfo)}function Sb(e,t,s,r,i){return fl(),gv(i),t.flags|=256,Cn(e,t,s,r),t.child}var Zp={dehydrated:null,treeContext:null,retryLane:0};function eg(e){return{baseLanes:e,cachePool:null,transitions:null}}function NC(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),bt(Rt,i&1),e===null)return Vp(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=Dh(l,r,0,null),e=ta(e,r,s,null),a.return=t,e.return=t,a.sibling=e,t.child=a,t.child.memoizedState=eg(s),t.memoizedState=Zp,e):$v(t,l));if(i=e.memoizedState,i!==null&&(o=i.dehydrated,o!==null))return rM(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=pi(i,c),r.subtreeFlags=i.subtreeFlags&14680064),o!==null?a=pi(o,a):(a=ta(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?eg(s):{baseLanes:l.baseLanes|s,cachePool:null,transitions:l.transitions},a.memoizedState=l,a.childLanes=e.childLanes&~s,t.memoizedState=Zp,r}return a=e.child,e=a.sibling,r=pi(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 $v(e,t){return t=Dh({mode:"visible",children:t},e.mode,0,null),t.return=e,e.child=t}function vu(e,t,s,r){return r!==null&&gv(r),ml(t,e.child,null,s),e=$v(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function rM(e,t,s,r,i,a,l){if(s)return t.flags&256?(t.flags&=-257,r=cm(Error(xe(422))),vu(e,t,l,r)):t.memoizedState!==null?(t.child=e.child,t.flags|=128,null):(a=r.fallback,i=t.mode,r=Dh({mode:"visible",children:r.children},i,0,null),a=ta(a,i,l,null),a.flags|=2,r.return=t,a.return=t,r.sibling=a,t.child=r,t.mode&1&&ml(t,e.child,null,l),t.child.memoizedState=eg(l),t.memoizedState=Zp,a);if(!(t.mode&1))return vu(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=cm(a,r,void 0),vu(e,t,l,r)}if(o=(l&e.childLanes)!==0,zn||o){if(r=cn,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,Ur(e,i),Ls(r,e,i,-1))}return Ov(),r=cm(Error(xe(421))),vu(e,t,l,r)}return i.data==="$?"?(t.flags|=128,t.child=e.child,t=xM.bind(null,e),i._reactRetry=t,null):(e=a.treeContext,Zn=di(i.nextSibling),ts=t,Tt=!0,Ms=null,e!==null&&(gs[xs++]=$r,gs[xs++]=Rr,gs[xs++]=ia,$r=e.id,Rr=e.overflow,ia=t),t=$v(t,r.children),t.flags|=4096,t)}function Cb(e,t,s){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),Gp(e.return,t,s)}function um(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 SC(e,t,s){var r=t.pendingProps,i=r.revealOrder,a=r.tail;if(Cn(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&&Cb(e,s,t);else if(e.tag===19)Cb(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(bt(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&&Ld(e)===null&&(i=s),s=s.sibling;s=i,s===null?(i=t.child,t.child=null):(i=s.sibling,s.sibling=null),um(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&&Ld(e)===null){t.child=i;break}e=i.sibling,i.sibling=s,s=i,i=e}um(t,!0,s,null,a);break;case"together":um(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function nd(e,t){!(t.mode&1)&&e!==null&&(e.alternate=null,t.alternate=null,t.flags|=2)}function Br(e,t,s){if(e!==null&&(t.dependencies=e.dependencies),la|=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=pi(e,e.pendingProps),t.child=s,s.return=t;e.sibling!==null;)e=e.sibling,s=s.sibling=pi(e,e.pendingProps),s.return=t;s.sibling=null}return t.child}function iM(e,t,s){switch(t.tag){case 3:kC(t),fl();break;case 5:QS(t);break;case 1:Wn(t.type)&&Rd(t);break;case 4:bv(t,t.stateNode.containerInfo);break;case 10:var r=t.type._context,i=t.memoizedProps.value;bt(Md,r._currentValue),r._currentValue=i;break;case 13:if(r=t.memoizedState,r!==null)return r.dehydrated!==null?(bt(Rt,Rt.current&1),t.flags|=128,null):s&t.child.childLanes?NC(e,t,s):(bt(Rt,Rt.current&1),e=Br(e,t,s),e!==null?e.sibling:null);bt(Rt,Rt.current&1);break;case 19:if(r=(s&t.childLanes)!==0,e.flags&128){if(r)return SC(e,t,s);t.flags|=128}if(i=t.memoizedState,i!==null&&(i.rendering=null,i.tail=null,i.lastEffect=null),bt(Rt,Rt.current),r)break;return null;case 22:case 23:return t.lanes=0,yC(e,t,s)}return Br(e,t,s)}var CC,tg,EC,AC;CC=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}};tg=function(){};EC=function(e,t,s,r){var i=e.memoizedProps;if(i!==r){e=t.stateNode,Qi(or.current);var a=null;switch(s){case"input":i=kp(e,i),r=kp(e,r),a=[];break;case"select":i=Mt({},i,{value:void 0}),r=Mt({},r,{value:void 0}),a=[];break;case"textarea":i=Cp(e,i),r=Cp(e,r),a=[];break;default:typeof i.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=Td)}Ap(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"&&(Bo.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"&&(Bo.hasOwnProperty(u)?(c!=null&&u==="onScroll"&&Nt("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)}};AC=function(e,t,s,r){s!==r&&(t.flags|=4)};function co(e,t){if(!Tt)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 jn(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 aM(e,t,s){var r=t.pendingProps;switch(pv(t),t.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return jn(t),null;case 1:return Wn(t.type)&&$d(),jn(t),null;case 3:return r=t.stateNode,pl(),Ct(Bn),Ct(bn),Nv(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(gu(t)?t.flags|=4:e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,Ms!==null&&(cg(Ms),Ms=null))),tg(e,t),jn(t),null;case 5:kv(t);var i=Qi(ec.current);if(s=t.type,e!==null&&t.stateNode!=null)EC(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 jn(t),null}if(e=Qi(or.current),gu(t)){r=t.stateNode,s=t.type;var a=t.memoizedProps;switch(r[sr]=t,r[Xo]=a,e=(t.mode&1)!==0,s){case"dialog":Nt("cancel",r),Nt("close",r);break;case"iframe":case"object":case"embed":Nt("load",r);break;case"video":case"audio":for(i=0;i<bo.length;i++)Nt(bo[i],r);break;case"source":Nt("error",r);break;case"img":case"image":case"link":Nt("error",r),Nt("load",r);break;case"details":Nt("toggle",r);break;case"input":Dy(r,a),Nt("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!a.multiple},Nt("invalid",r);break;case"textarea":Ly(r,a),Nt("invalid",r)}Ap(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&&pu(r.textContent,o,e),i=["children",o]):typeof o=="number"&&r.textContent!==""+o&&(a.suppressHydrationWarning!==!0&&pu(r.textContent,o,e),i=["children",""+o]):Bo.hasOwnProperty(l)&&o!=null&&l==="onScroll"&&Nt("scroll",r)}switch(s){case"input":lu(r),Oy(r,a,!0);break;case"textarea":lu(r),Fy(r);break;case"select":case"option":break;default:typeof a.onClick=="function"&&(r.onclick=Td)}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=nS(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[sr]=t,e[Xo]=r,CC(e,t,!1,!1),t.stateNode=e;e:{switch(l=Tp(s,r),s){case"dialog":Nt("cancel",e),Nt("close",e),i=r;break;case"iframe":case"object":case"embed":Nt("load",e),i=r;break;case"video":case"audio":for(i=0;i<bo.length;i++)Nt(bo[i],e);i=r;break;case"source":Nt("error",e),i=r;break;case"img":case"image":case"link":Nt("error",e),Nt("load",e),i=r;break;case"details":Nt("toggle",e),i=r;break;case"input":Dy(e,r),i=kp(e,r),Nt("invalid",e);break;case"option":i=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},i=Mt({},r,{value:void 0}),Nt("invalid",e);break;case"textarea":Ly(e,r),i=Cp(e,r),Nt("invalid",e);break;default:i=r}Ap(s,i),o=i;for(a in o)if(o.hasOwnProperty(a)){var c=o[a];a==="style"?iS(e,c):a==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,c!=null&&sS(e,c)):a==="children"?typeof c=="string"?(s!=="textarea"||c!=="")&&Wo(e,c):typeof c=="number"&&Wo(e,""+c):a!=="suppressContentEditableWarning"&&a!=="suppressHydrationWarning"&&a!=="autoFocus"&&(Bo.hasOwnProperty(a)?c!=null&&a==="onScroll"&&Nt("scroll",e):c!=null&&ev(e,a,c,l))}switch(s){case"input":lu(e),Oy(e,r,!1);break;case"textarea":lu(e),Fy(e);break;case"option":r.value!=null&&e.setAttribute("value",""+ji(r.value));break;case"select":e.multiple=!!r.multiple,a=r.value,a!=null?Za(e,!!r.multiple,a,!1):r.defaultValue!=null&&Za(e,!!r.multiple,r.defaultValue,!0);break;default:typeof i.onClick=="function"&&(e.onclick=Td)}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 jn(t),null;case 6:if(e&&t.stateNode!=null)AC(e,t,e.memoizedProps,r);else{if(typeof r!="string"&&t.stateNode===null)throw Error(xe(166));if(s=Qi(ec.current),Qi(or.current),gu(t)){if(r=t.stateNode,s=t.memoizedProps,r[sr]=t,(a=r.nodeValue!==s)&&(e=ts,e!==null))switch(e.tag){case 3:pu(r.nodeValue,s,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&pu(r.nodeValue,s,(e.mode&1)!==0)}a&&(t.flags|=4)}else r=(s.nodeType===9?s:s.ownerDocument).createTextNode(r),r[sr]=t,t.stateNode=r}return jn(t),null;case 13:if(Ct(Rt),r=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(Tt&&Zn!==null&&t.mode&1&&!(t.flags&128))VS(),fl(),t.flags|=98560,a=!1;else if(a=gu(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[sr]=t}else fl(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;jn(t),a=!1}else Ms!==null&&(cg(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):Ov())),t.updateQueue!==null&&(t.flags|=4),jn(t),null);case 4:return pl(),tg(e,t),e===null&&Jo(t.stateNode.containerInfo),jn(t),null;case 10:return jv(t.type._context),jn(t),null;case 17:return Wn(t.type)&&$d(),jn(t),null;case 19:if(Ct(Rt),a=t.memoizedState,a===null)return jn(t),null;if(r=(t.flags&128)!==0,l=a.rendering,l===null)if(r)co(a,!1);else{if(Zt!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(l=Ld(e),l!==null){for(t.flags|=128,co(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 bt(Rt,Rt.current&1|2),t.child}e=e.sibling}a.tail!==null&&_t()>xl&&(t.flags|=128,r=!0,co(a,!1),t.lanes=4194304)}else{if(!r)if(e=Ld(l),e!==null){if(t.flags|=128,r=!0,s=e.updateQueue,s!==null&&(t.updateQueue=s,t.flags|=4),co(a,!0),a.tail===null&&a.tailMode==="hidden"&&!l.alternate&&!Tt)return jn(t),null}else 2*_t()-a.renderingStartTime>xl&&s!==1073741824&&(t.flags|=128,r=!0,co(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,bt(Rt,r?s&1|2:s&1),t):(jn(t),null);case 22:case 23:return Dv(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?Qn&1073741824&&(jn(t),t.subtreeFlags&6&&(t.flags|=8192)):jn(t),null;case 24:return null;case 25:return null}throw Error(xe(156,t.tag))}function lM(e,t){switch(pv(t),t.tag){case 1:return Wn(t.type)&&$d(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return pl(),Ct(Bn),Ct(bn),Nv(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return kv(t),null;case 13:if(Ct(Rt),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(xe(340));fl()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return Ct(Rt),null;case 4:return pl(),null;case 10:return jv(t.type._context),null;case 22:case 23:return Dv(),null;case 24:return null;default:return null}}var ju=!1,wn=!1,oM=typeof WeakSet=="function"?WeakSet:Set,Te=null;function Ga(e,t){var s=e.ref;if(s!==null)if(typeof s=="function")try{s(null)}catch(r){Ot(e,t,r)}else s.current=null}function ng(e,t,s){try{s()}catch(r){Ot(e,t,r)}}var Eb=!1;function cM(e,t){if(_p=Cd,e=PS(),fv(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(zp={focusedElem:e,selectionRange:s},Cd=!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){Ot(t,t.return,y)}if(e=t.sibling,e!==null){e.return=t.return,Te=e;break}Te=t.return}return g=Eb,Eb=!1,g}function Po(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&&ng(t,s,a)}i=i.next}while(i!==r)}}function Ph(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 sg(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 TC(e){var t=e.alternate;t!==null&&(e.alternate=null,TC(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[sr],delete t[Xo],delete t[Wp],delete t[K2],delete t[V2])),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 $C(e){return e.tag===5||e.tag===3||e.tag===4}function Ab(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||$C(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 rg(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=Td));else if(r!==4&&(e=e.child,e!==null))for(rg(e,t,s),e=e.sibling;e!==null;)rg(e,t,s),e=e.sibling}function ig(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(ig(e,t,s),e=e.sibling;e!==null;)ig(e,t,s),e=e.sibling}var hn=null,Ps=!1;function Xr(e,t,s){for(s=s.child;s!==null;)RC(e,t,s),s=s.sibling}function RC(e,t,s){if(lr&&typeof lr.onCommitFiberUnmount=="function")try{lr.onCommitFiberUnmount(Sh,s)}catch{}switch(s.tag){case 5:wn||Ga(s,t);case 6:var r=hn,i=Ps;hn=null,Xr(e,t,s),hn=r,Ps=i,hn!==null&&(Ps?(e=hn,s=s.stateNode,e.nodeType===8?e.parentNode.removeChild(s):e.removeChild(s)):hn.removeChild(s.stateNode));break;case 18:hn!==null&&(Ps?(e=hn,s=s.stateNode,e.nodeType===8?sm(e.parentNode,s):e.nodeType===1&&sm(e,s),Go(e)):sm(hn,s.stateNode));break;case 4:r=hn,i=Ps,hn=s.stateNode.containerInfo,Ps=!0,Xr(e,t,s),hn=r,Ps=i;break;case 0:case 11:case 14:case 15:if(!wn&&(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)&&ng(s,t,l),i=i.next}while(i!==r)}Xr(e,t,s);break;case 1:if(!wn&&(Ga(s,t),r=s.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=s.memoizedProps,r.state=s.memoizedState,r.componentWillUnmount()}catch(o){Ot(s,t,o)}Xr(e,t,s);break;case 21:Xr(e,t,s);break;case 22:s.mode&1?(wn=(r=wn)||s.memoizedState!==null,Xr(e,t,s),wn=r):Xr(e,t,s);break;default:Xr(e,t,s)}}function Tb(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var s=e.stateNode;s===null&&(s=e.stateNode=new oM),t.forEach(function(r){var i=vM.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:hn=o.stateNode,Ps=!1;break e;case 3:hn=o.stateNode.containerInfo,Ps=!0;break e;case 4:hn=o.stateNode.containerInfo,Ps=!0;break e}o=o.return}if(hn===null)throw Error(xe(160));RC(a,l,i),hn=null,Ps=!1;var c=i.alternate;c!==null&&(c.return=null),i.return=null}catch(u){Ot(i,t,u)}}if(t.subtreeFlags&12854)for(t=t.child;t!==null;)IC(t,e),t=t.sibling}function IC(e,t){var s=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(Rs(t,e),Js(e),r&4){try{Po(3,e,e.return),Ph(3,e)}catch(v){Ot(e,e.return,v)}try{Po(5,e,e.return)}catch(v){Ot(e,e.return,v)}}break;case 1:Rs(t,e),Js(e),r&512&&s!==null&&Ga(s,s.return);break;case 5:if(Rs(t,e),Js(e),r&512&&s!==null&&Ga(s,s.return),e.flags&32){var i=e.stateNode;try{Wo(i,"")}catch(v){Ot(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&&eS(i,a),Tp(o,l);var u=Tp(o,a);for(l=0;l<c.length;l+=2){var h=c[l],f=c[l+1];h==="style"?iS(i,f):h==="dangerouslySetInnerHTML"?sS(i,f):h==="children"?Wo(i,f):ev(i,h,f,u)}switch(o){case"input":Np(i,a);break;case"textarea":tS(i,a);break;case"select":var m=i._wrapperState.wasMultiple;i._wrapperState.wasMultiple=!!a.multiple;var p=a.value;p!=null?Za(i,!!a.multiple,p,!1):m!==!!a.multiple&&(a.defaultValue!=null?Za(i,!!a.multiple,a.defaultValue,!0):Za(i,!!a.multiple,a.multiple?[]:"",!1))}i[Xo]=a}catch(v){Ot(e,e.return,v)}}break;case 6:if(Rs(t,e),Js(e),r&4){if(e.stateNode===null)throw Error(xe(162));i=e.stateNode,a=e.memoizedProps;try{i.nodeValue=a}catch(v){Ot(e,e.return,v)}}break;case 3:if(Rs(t,e),Js(e),r&4&&s!==null&&s.memoizedState.isDehydrated)try{Go(t.containerInfo)}catch(v){Ot(e,e.return,v)}break;case 4:Rs(t,e),Js(e);break;case 13:Rs(t,e),Js(e),i=e.child,i.flags&8192&&(a=i.memoizedState!==null,i.stateNode.isHidden=a,!a||i.alternate!==null&&i.alternate.memoizedState!==null||(Pv=_t())),r&4&&Tb(e);break;case 22:if(h=s!==null&&s.memoizedState!==null,e.mode&1?(wn=(u=wn)||h,Rs(t,e),wn=u):Rs(t,e),Js(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:Po(4,m,m.return);break;case 1:Ga(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){Ot(r,s,v)}}break;case 5:Ga(m,m.return);break;case 22:if(m.memoizedState!==null){Rb(f);continue}}p!==null?(p.return=m,Te=p):Rb(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=rS("display",l))}catch(v){Ot(e,e.return,v)}}}else if(f.tag===6){if(h===null)try{f.stateNode.nodeValue=u?"":f.memoizedProps}catch(v){Ot(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),Js(e),r&4&&Tb(e);break;case 21:break;default:Rs(t,e),Js(e)}}function Js(e){var t=e.flags;if(t&2){try{e:{for(var s=e.return;s!==null;){if($C(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&&(Wo(i,""),r.flags&=-33);var a=Ab(e);ig(e,a,i);break;case 3:case 4:var l=r.stateNode.containerInfo,o=Ab(e);rg(e,o,l);break;default:throw Error(xe(161))}}catch(c){Ot(e,e.return,c)}e.flags&=-3}t&4096&&(e.flags&=-4097)}function uM(e,t,s){Te=e,PC(e)}function PC(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||ju;if(!l){var o=i.alternate,c=o!==null&&o.memoizedState!==null||wn;o=ju;var u=wn;if(ju=l,(wn=c)&&!u)for(Te=i;Te!==null;)l=Te,c=l.child,l.tag===22&&l.memoizedState!==null?Ib(i):c!==null?(c.return=l,Te=c):Ib(i);for(;a!==null;)Te=a,PC(a),a=a.sibling;Te=i,ju=o,wn=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:wn||Ph(5,t);break;case 1:var r=t.stateNode;if(t.flags&4&&!wn)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&&mb(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}mb(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&&Go(f)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(xe(163))}wn||t.flags&512&&sg(t)}catch(m){Ot(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 Rb(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 Ib(e){for(;Te!==null;){var t=Te;try{switch(t.tag){case 0:case 11:case 15:var s=t.return;try{Ph(4,t)}catch(c){Ot(t,s,c)}break;case 1:var r=t.stateNode;if(typeof r.componentDidMount=="function"){var i=t.return;try{r.componentDidMount()}catch(c){Ot(t,i,c)}}var a=t.return;try{sg(t)}catch(c){Ot(t,a,c)}break;case 5:var l=t.return;try{sg(t)}catch(c){Ot(t,l,c)}}}catch(c){Ot(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 dM=Math.ceil,zd=Yr.ReactCurrentDispatcher,Rv=Yr.ReactCurrentOwner,bs=Yr.ReactCurrentBatchConfig,lt=0,cn=null,Wt=null,fn=0,Qn=0,Ya=Ti(0),Zt=0,rc=null,la=0,Mh=0,Iv=0,Mo=null,_n=null,Pv=0,xl=1/0,Nr=null,Ud=!1,ag=null,fi=null,wu=!1,ii=null,Bd=0,Do=0,lg=null,sd=-1,rd=0;function An(){return lt&6?_t():sd!==-1?sd:sd=_t()}function mi(e){return e.mode&1?lt&2&&fn!==0?fn&-fn:Y2.transition!==null?(rd===0&&(rd=xS()),rd):(e=pt,e!==0||(e=window.event,e=e===void 0?16:NS(e.type)),e):1}function Ls(e,t,s,r){if(50<Do)throw Do=0,lg=null,Error(xe(185));Tc(e,s,r),(!(lt&2)||e!==cn)&&(e===cn&&(!(lt&2)&&(Mh|=s),Zt===4&&si(e,fn)),Hn(e,r),s===1&&lt===0&&!(t.mode&1)&&(xl=_t()+500,$h&&$i()))}function Hn(e,t){var s=e.callbackNode;YP(e,t);var r=Sd(e,e===cn?fn:0);if(r===0)s!==null&&Uy(s),e.callbackNode=null,e.callbackPriority=0;else if(t=r&-r,e.callbackPriority!==t){if(s!=null&&Uy(s),t===1)e.tag===0?G2(Pb.bind(null,e)):WS(Pb.bind(null,e)),W2(function(){!(lt&6)&&$i()}),s=null;else{switch(vS(r)){case 1:s=iv;break;case 4:s=pS;break;case 16:s=Nd;break;case 536870912:s=gS;break;default:s=Nd}s=UC(s,MC.bind(null,e))}e.callbackPriority=t,e.callbackNode=s}}function MC(e,t){if(sd=-1,rd=0,lt&6)throw Error(xe(327));var s=e.callbackNode;if(rl()&&e.callbackNode!==s)return null;var r=Sd(e,e===cn?fn:0);if(r===0)return null;if(r&30||r&e.expiredLanes||t)t=Wd(e,r);else{t=r;var i=lt;lt|=2;var a=OC();(cn!==e||fn!==t)&&(Nr=null,xl=_t()+500,ea(e,t));do try{mM();break}catch(o){DC(e,o)}while(!0);vv(),zd.current=a,lt=i,Wt!==null?t=0:(cn=null,fn=0,t=Zt)}if(t!==0){if(t===2&&(i=Mp(e),i!==0&&(r=i,t=og(e,i))),t===1)throw s=rc,ea(e,0),si(e,r),Hn(e,_t()),s;if(t===6)si(e,r);else{if(i=e.current.alternate,!(r&30)&&!hM(i)&&(t=Wd(e,r),t===2&&(a=Mp(e),a!==0&&(r=a,t=og(e,a))),t===1))throw s=rc,ea(e,0),si(e,r),Hn(e,_t()),s;switch(e.finishedWork=i,e.finishedLanes=r,t){case 0:case 1:throw Error(xe(345));case 2:Ki(e,_n,Nr);break;case 3:if(si(e,r),(r&130023424)===r&&(t=Pv+500-_t(),10<t)){if(Sd(e,0)!==0)break;if(i=e.suspendedLanes,(i&r)!==r){An(),e.pingedLanes|=e.suspendedLanes&i;break}e.timeoutHandle=Bp(Ki.bind(null,e,_n,Nr),t);break}Ki(e,_n,Nr);break;case 4:if(si(e,r),(r&4194240)===r)break;for(t=e.eventTimes,i=-1;0<r;){var l=31-Os(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*dM(r/1960))-r,10<r){e.timeoutHandle=Bp(Ki.bind(null,e,_n,Nr),r);break}Ki(e,_n,Nr);break;case 5:Ki(e,_n,Nr);break;default:throw Error(xe(329))}}}return Hn(e,_t()),e.callbackNode===s?MC.bind(null,e):null}function og(e,t){var s=Mo;return e.current.memoizedState.isDehydrated&&(ea(e,t).flags|=256),e=Wd(e,t),e!==2&&(t=_n,_n=s,t!==null&&cg(t)),e}function cg(e){_n===null?_n=e:_n.push.apply(_n,e)}function hM(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(!zs(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 si(e,t){for(t&=~Iv,t&=~Mh,e.suspendedLanes|=t,e.pingedLanes&=~t,e=e.expirationTimes;0<t;){var s=31-Os(t),r=1<<s;e[s]=-1,t&=~r}}function Pb(e){if(lt&6)throw Error(xe(327));rl();var t=Sd(e,0);if(!(t&1))return Hn(e,_t()),null;var s=Wd(e,t);if(e.tag!==0&&s===2){var r=Mp(e);r!==0&&(t=r,s=og(e,r))}if(s===1)throw s=rc,ea(e,0),si(e,t),Hn(e,_t()),s;if(s===6)throw Error(xe(345));return e.finishedWork=e.current.alternate,e.finishedLanes=t,Ki(e,_n,Nr),Hn(e,_t()),null}function Mv(e,t){var s=lt;lt|=1;try{return e(t)}finally{lt=s,lt===0&&(xl=_t()+500,$h&&$i())}}function oa(e){ii!==null&&ii.tag===0&&!(lt&6)&&rl();var t=lt;lt|=1;var s=bs.transition,r=pt;try{if(bs.transition=null,pt=1,e)return e()}finally{pt=r,bs.transition=s,lt=t,!(lt&6)&&$i()}}function Dv(){Qn=Ya.current,Ct(Ya)}function ea(e,t){e.finishedWork=null,e.finishedLanes=0;var s=e.timeoutHandle;if(s!==-1&&(e.timeoutHandle=-1,B2(s)),Wt!==null)for(s=Wt.return;s!==null;){var r=s;switch(pv(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&$d();break;case 3:pl(),Ct(Bn),Ct(bn),Nv();break;case 5:kv(r);break;case 4:pl();break;case 13:Ct(Rt);break;case 19:Ct(Rt);break;case 10:jv(r.type._context);break;case 22:case 23:Dv()}s=s.return}if(cn=e,Wt=e=pi(e.current,null),fn=Qn=t,Zt=0,rc=null,Iv=Mh=la=0,_n=Mo=null,Ji!==null){for(t=0;t<Ji.length;t++)if(s=Ji[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}Ji=null}return e}function DC(e,t){do{var s=Wt;try{if(vv(),ed.current=_d,Fd){for(var r=It.memoizedState;r!==null;){var i=r.queue;i!==null&&(i.pending=null),r=r.next}Fd=!1}if(aa=0,sn=Jt=It=null,Io=!1,tc=0,Rv.current=null,s===null||s.return===null){Zt=1,rc=t,Wt=null;break}e:{var a=e,l=s.return,o=s,c=t;if(t=fn,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=wb(l);if(p!==null){p.flags&=-257,yb(p,l,o,a,t),p.mode&1&&jb(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)){jb(a,u,t),Ov();break e}c=Error(xe(426))}}else if(Tt&&o.mode&1){var b=wb(l);if(b!==null){!(b.flags&65536)&&(b.flags|=256),yb(b,l,o,a,t),gv(gl(c,o));break e}}a=c=gl(c,o),Zt!==4&&(Zt=2),Mo===null?Mo=[a]:Mo.push(a),a=l;do{switch(a.tag){case 3:a.flags|=65536,t&=-t,a.lanes|=t;var j=vC(a,c,t);fb(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"&&(fi===null||!fi.has(w)))){a.flags|=65536,t&=-t,a.lanes|=t;var y=jC(a,o,t);fb(a,y);break e}}a=a.return}while(a!==null)}FC(s)}catch(k){t=k,Wt===s&&s!==null&&(Wt=s=s.return);continue}break}while(!0)}function OC(){var e=zd.current;return zd.current=_d,e===null?_d:e}function Ov(){(Zt===0||Zt===3||Zt===2)&&(Zt=4),cn===null||!(la&268435455)&&!(Mh&268435455)||si(cn,fn)}function Wd(e,t){var s=lt;lt|=2;var r=OC();(cn!==e||fn!==t)&&(Nr=null,ea(e,t));do try{fM();break}catch(i){DC(e,i)}while(!0);if(vv(),lt=s,zd.current=r,Wt!==null)throw Error(xe(261));return cn=null,fn=0,Zt}function fM(){for(;Wt!==null;)LC(Wt)}function mM(){for(;Wt!==null&&!_P();)LC(Wt)}function LC(e){var t=zC(e.alternate,e,Qn);e.memoizedProps=e.pendingProps,t===null?FC(e):Wt=t,Rv.current=null}function FC(e){var t=e;do{var s=t.alternate;if(e=t.return,t.flags&32768){if(s=lM(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=aM(s,t,Qn),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 Ki(e,t,s){var r=pt,i=bs.transition;try{bs.transition=null,pt=1,pM(e,t,s,r)}finally{bs.transition=i,pt=r}return null}function pM(e,t,s,r){do rl();while(ii!==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(qP(e,a),e===cn&&(Wt=cn=null,fn=0),!(s.subtreeFlags&2064)&&!(s.flags&2064)||wu||(wu=!0,UC(Nd,function(){return rl(),null})),a=(s.flags&15990)!==0,s.subtreeFlags&15990||a){a=bs.transition,bs.transition=null;var l=pt;pt=1;var o=lt;lt|=4,Rv.current=null,cM(e,s),IC(s,e),D2(zp),Cd=!!_p,zp=_p=null,e.current=s,uM(s),zP(),lt=o,pt=l,bs.transition=a}else e.current=s;if(wu&&(wu=!1,ii=e,Bd=i),a=e.pendingLanes,a===0&&(fi=null),WP(s.stateNode),Hn(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(Ud)throw Ud=!1,e=ag,ag=null,e;return Bd&1&&e.tag!==0&&rl(),a=e.pendingLanes,a&1?e===lg?Do++:(Do=0,lg=e):Do=0,$i(),null}function rl(){if(ii!==null){var e=vS(Bd),t=bs.transition,s=pt;try{if(bs.transition=null,pt=16>e?16:e,ii===null)var r=!1;else{if(e=ii,ii=null,Bd=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:Po(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(TC(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:Po(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:Ph(9,o)}}catch(k){Ot(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,$i(),lr&&typeof lr.onPostCommitFiberRoot=="function")try{lr.onPostCommitFiberRoot(Sh,e)}catch{}r=!0}return r}finally{pt=s,bs.transition=t}}return!1}function Mb(e,t,s){t=gl(s,t),t=vC(e,t,1),e=hi(e,t,1),t=An(),e!==null&&(Tc(e,1,t),Hn(e,t))}function Ot(e,t,s){if(e.tag===3)Mb(e,e,s);else for(;t!==null;){if(t.tag===3){Mb(t,e,s);break}else if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(fi===null||!fi.has(r))){e=gl(s,e),e=jC(t,e,1),t=hi(t,e,1),e=An(),t!==null&&(Tc(t,1,e),Hn(t,e));break}}t=t.return}}function gM(e,t,s){var r=e.pingCache;r!==null&&r.delete(t),t=An(),e.pingedLanes|=e.suspendedLanes&s,cn===e&&(fn&s)===s&&(Zt===4||Zt===3&&(fn&130023424)===fn&&500>_t()-Pv?ea(e,0):Iv|=s),Hn(e,t)}function _C(e,t){t===0&&(e.mode&1?(t=uu,uu<<=1,!(uu&130023424)&&(uu=4194304)):t=1);var s=An();e=Ur(e,t),e!==null&&(Tc(e,t,s),Hn(e,s))}function xM(e){var t=e.memoizedState,s=0;t!==null&&(s=t.retryLane),_C(e,s)}function vM(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),_C(e,s)}var zC;zC=function(e,t,s){if(e!==null)if(e.memoizedProps!==t.pendingProps||Bn.current)zn=!0;else{if(!(e.lanes&s)&&!(t.flags&128))return zn=!1,iM(e,t,s);zn=!!(e.flags&131072)}else zn=!1,Tt&&t.flags&1048576&&HS(t,Pd,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;nd(e,t),e=t.pendingProps;var i=hl(t,bn.current);sl(t,s),i=Cv(null,t,r,e,i,s);var a=Ev();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,Wn(r)?(a=!0,Rd(t)):a=!1,t.memoizedState=i.state!==null&&i.state!==void 0?i.state:null,yv(t),i.updater=Ih,t.stateNode=i,i._reactInternals=t,qp(t,r,e,s),t=Xp(null,t,r,!0,a,s)):(t.tag=0,Tt&&a&&mv(t),Cn(null,t,i,s),t=t.child),t;case 16:r=t.elementType;e:{switch(nd(e,t),e=t.pendingProps,i=r._init,r=i(r._payload),t.type=r,i=t.tag=wM(r),e=Is(r,e),i){case 0:t=Qp(null,t,r,e,s);break e;case 1:t=Nb(null,t,r,e,s);break e;case 11:t=bb(null,t,r,e,s);break e;case 14:t=kb(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),Qp(e,t,r,i,s);case 1:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:Is(r,i),Nb(e,t,r,i,s);case 3:e:{if(kC(t),e===null)throw Error(xe(387));r=t.pendingProps,a=t.memoizedState,i=a.element,JS(e,t),Od(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=gl(Error(xe(423)),t),t=Sb(e,t,r,s,i);break e}else if(r!==i){i=gl(Error(xe(424)),t),t=Sb(e,t,r,s,i);break e}else for(Zn=di(t.stateNode.containerInfo.firstChild),ts=t,Tt=!0,Ms=null,s=YS(t,null,r,s),t.child=s;s;)s.flags=s.flags&-3|4096,s=s.sibling;else{if(fl(),r===i){t=Br(e,t,s);break e}Cn(e,t,r,s)}t=t.child}return t;case 5:return QS(t),e===null&&Vp(t),r=t.type,i=t.pendingProps,a=e!==null?e.memoizedProps:null,l=i.children,Up(r,i)?l=null:a!==null&&Up(r,a)&&(t.flags|=32),bC(e,t),Cn(e,t,l,s),t.child;case 6:return e===null&&Vp(t),null;case 13:return NC(e,t,s);case 4:return bv(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=ml(t,null,r,s):Cn(e,t,r,s),t.child;case 11:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:Is(r,i),bb(e,t,r,i,s);case 7:return Cn(e,t,t.pendingProps,s),t.child;case 8:return Cn(e,t,t.pendingProps.children,s),t.child;case 12:return Cn(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,bt(Md,r._currentValue),r._currentValue=l,a!==null)if(zs(a.value,l)){if(a.children===i.children&&!Bn.current){t=Br(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=Pr(-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),Gp(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),Gp(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}Cn(e,t,i.children,s),t=t.child}return t;case 9:return i=t.type,r=t.pendingProps.children,sl(t,s),i=Ss(i),r=r(i),t.flags|=1,Cn(e,t,r,s),t.child;case 14:return r=t.type,i=Is(r,t.pendingProps),i=Is(r.type,i),kb(e,t,r,i,s);case 15:return wC(e,t,t.type,t.pendingProps,s);case 17:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:Is(r,i),nd(e,t),t.tag=1,Wn(r)?(e=!0,Rd(t)):e=!1,sl(t,s),xC(t,r,i),qp(t,r,i,s),Xp(null,t,r,!0,e,s);case 19:return SC(e,t,s);case 22:return yC(e,t,s)}throw Error(xe(156,t.tag))};function UC(e,t){return mS(e,t)}function jM(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 ys(e,t,s,r){return new jM(e,t,s,r)}function Lv(e){return e=e.prototype,!(!e||!e.isReactComponent)}function wM(e){if(typeof e=="function")return Lv(e)?1:0;if(e!=null){if(e=e.$$typeof,e===nv)return 11;if(e===sv)return 14}return 2}function pi(e,t){var s=e.alternate;return s===null?(s=ys(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 id(e,t,s,r,i,a){var l=2;if(r=e,typeof e=="function")Lv(e)&&(l=1);else if(typeof e=="string")l=5;else e:switch(e){case Fa:return ta(s.children,i,a,t);case tv:l=8,i|=8;break;case jp:return e=ys(12,s,t,i|2),e.elementType=jp,e.lanes=a,e;case wp:return e=ys(13,s,t,i),e.elementType=wp,e.lanes=a,e;case yp:return e=ys(19,s,t,i),e.elementType=yp,e.lanes=a,e;case QN:return Dh(s,i,a,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case qN:l=10;break e;case JN:l=9;break e;case nv:l=11;break e;case sv:l=14;break e;case ei:l=16,r=null;break e}throw Error(xe(130,e==null?e:typeof e,""))}return t=ys(l,s,t,i),t.elementType=e,t.type=r,t.lanes=a,t}function ta(e,t,s,r){return e=ys(7,e,r,t),e.lanes=s,e}function Dh(e,t,s,r){return e=ys(22,e,r,t),e.elementType=QN,e.lanes=s,e.stateNode={isHidden:!1},e}function dm(e,t,s){return e=ys(6,e,null,t),e.lanes=s,e}function hm(e,t,s){return t=ys(4,e.children!==null?e.children:[],e.key,t),t.lanes=s,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function yM(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=Vf(0),this.expirationTimes=Vf(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Vf(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function Fv(e,t,s,r,i,a,l,o,c){return e=new yM(e,t,s,o,c),t===1?(t=1,a===!0&&(t|=8)):t=0,a=ys(3,null,null,t),e.current=a,a.stateNode=e,a.memoizedState={element:r,isDehydrated:s,cache:null,transitions:null,pendingSuspenseBoundaries:null},yv(a),e}function bM(e,t,s){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:La,key:r==null?null:""+r,children:e,containerInfo:t,implementation:s}}function BC(e){if(!e)return wi;e=e._reactInternals;e:{if(pa(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(Wn(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(Wn(s))return BS(e,s,t)}return t}function WC(e,t,s,r,i,a,l,o,c){return e=Fv(s,r,!0,e,i,a,l,o,c),e.context=BC(null),s=e.current,r=An(),i=mi(s),a=Pr(r,i),a.callback=t??null,hi(s,a,i),e.current.lanes=i,Tc(e,i,r),Hn(e,r),e}function Oh(e,t,s,r){var i=t.current,a=An(),l=mi(i);return s=BC(s),t.context===null?t.context=s:t.pendingContext=s,t=Pr(a,l),t.payload={element:e},r=r===void 0?null:r,r!==null&&(t.callback=r),e=hi(i,t,l),e!==null&&(Ls(e,i,l,a),Zu(e,i,l)),l}function Hd(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 Db(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var s=e.retryLane;e.retryLane=s!==0&&s<t?s:t}}function _v(e,t){Db(e,t),(e=e.alternate)&&Db(e,t)}function kM(){return null}var HC=typeof reportError=="function"?reportError:function(e){console.error(e)};function zv(e){this._internalRoot=e}Lh.prototype.render=zv.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(xe(409));Oh(e,t,null,null)};Lh.prototype.unmount=zv.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;oa(function(){Oh(null,e,null,null)}),t[zr]=null}};function Lh(e){this._internalRoot=e}Lh.prototype.unstable_scheduleHydration=function(e){if(e){var t=yS();e={blockedOn:null,target:e,priority:t};for(var s=0;s<ni.length&&t!==0&&t<ni[s].priority;s++);ni.splice(s,0,e),s===0&&kS(e)}};function Uv(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function Fh(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function Ob(){}function NM(e,t,s,r,i){if(i){if(typeof r=="function"){var a=r;r=function(){var u=Hd(l);a.call(u)}}var l=WC(t,r,e,0,null,!1,!1,"",Ob);return e._reactRootContainer=l,e[zr]=l.current,Jo(e.nodeType===8?e.parentNode:e),oa(),l}for(;i=e.lastChild;)e.removeChild(i);if(typeof r=="function"){var o=r;r=function(){var u=Hd(c);o.call(u)}}var c=Fv(e,0,!1,null,null,!1,!1,"",Ob);return e._reactRootContainer=c,e[zr]=c.current,Jo(e.nodeType===8?e.parentNode:e),oa(function(){Oh(t,c,s,r)}),c}function _h(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=Hd(l);o.call(c)}}Oh(t,l,e,i)}else l=NM(s,t,e,i,r);return Hd(l)}jS=function(e){switch(e.tag){case 3:var t=e.stateNode;if(t.current.memoizedState.isDehydrated){var s=yo(t.pendingLanes);s!==0&&(av(t,s|1),Hn(t,_t()),!(lt&6)&&(xl=_t()+500,$i()))}break;case 13:oa(function(){var r=Ur(e,1);if(r!==null){var i=An();Ls(r,e,1,i)}}),_v(e,1)}};lv=function(e){if(e.tag===13){var t=Ur(e,134217728);if(t!==null){var s=An();Ls(t,e,134217728,s)}_v(e,134217728)}};wS=function(e){if(e.tag===13){var t=mi(e),s=Ur(e,t);if(s!==null){var r=An();Ls(s,e,t,r)}_v(e,t)}};yS=function(){return pt};bS=function(e,t){var s=pt;try{return pt=e,t()}finally{pt=s}};Rp=function(e,t,s){switch(t){case"input":if(Np(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=Th(r);if(!i)throw Error(xe(90));ZN(r),Np(r,i)}}}break;case"textarea":tS(e,s);break;case"select":t=s.value,t!=null&&Za(e,!!s.multiple,t,!1)}};oS=Mv;cS=oa;var SM={usingClientEntryPoint:!1,Events:[Rc,Ba,Th,aS,lS,Mv]},uo={findFiberByHostInstance:qi,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},CM={bundleType:uo.bundleType,version:uo.version,rendererPackageName:uo.rendererPackageName,rendererConfig:uo.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:Yr.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=hS(e),e===null?null:e.stateNode},findFiberByHostInstance:uo.findFiberByHostInstance||kM,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 yu=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!yu.isDisabled&&yu.supportsFiber)try{Sh=yu.inject(CM),lr=yu}catch{}}as.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=SM;as.createPortal=function(e,t){var s=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!Uv(t))throw Error(xe(200));return bM(e,t,null,s)};as.createRoot=function(e,t){if(!Uv(e))throw Error(xe(299));var s=!1,r="",i=HC;return t!=null&&(t.unstable_strictMode===!0&&(s=!0),t.identifierPrefix!==void 0&&(r=t.identifierPrefix),t.onRecoverableError!==void 0&&(i=t.onRecoverableError)),t=Fv(e,1,!1,null,null,s,!1,r,i),e[zr]=t.current,Jo(e.nodeType===8?e.parentNode:e),new zv(t)};as.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=hS(t),e=e===null?null:e.stateNode,e};as.flushSync=function(e){return oa(e)};as.hydrate=function(e,t,s){if(!Fh(t))throw Error(xe(200));return _h(null,e,t,!0,s)};as.hydrateRoot=function(e,t,s){if(!Uv(e))throw Error(xe(405));var r=s!=null&&s.hydratedSources||null,i=!1,a="",l=HC;if(s!=null&&(s.unstable_strictMode===!0&&(i=!0),s.identifierPrefix!==void 0&&(a=s.identifierPrefix),s.onRecoverableError!==void 0&&(l=s.onRecoverableError)),t=WC(t,null,e,1,s??null,i,!1,a,l),e[zr]=t.current,Jo(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 Lh(t)};as.render=function(e,t,s){if(!Fh(t))throw Error(xe(200));return _h(null,e,t,!1,s)};as.unmountComponentAtNode=function(e){if(!Fh(e))throw Error(xe(40));return e._reactRootContainer?(oa(function(){_h(null,null,e,!1,function(){e._reactRootContainer=null,e[zr]=null})}),!0):!1};as.unstable_batchedUpdates=Mv;as.unstable_renderSubtreeIntoContainer=function(e,t,s,r){if(!Fh(s))throw Error(xe(200));if(e==null||e._reactInternals===void 0)throw Error(xe(38));return _h(e,t,s,!1,r)};as.version="18.3.1-next-f1338f8080-20240426";function KC(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(KC)}catch(e){console.error(e)}}KC(),KN.exports=as;var Ml=KN.exports,VC,Lb=Ml;VC=Lb.createRoot,Lb.hydrateRoot;var EM=Object.defineProperty,Dl=(e,t)=>EM(e,"name",{value:t,configurable:!0}),GC=!!(typeof window<"u"&&window.document&&window.document.createElement);function Me(e,t,{checkForDefaultPrevented:s=!0}={}){return Dl(function(i){if(e==null||e(i),s===!1||!i||!i.defaultPrevented)return t==null?void 0:t(i)},"handleEvent")}Dl(Me,"composeEventHandlers");function AM(e){var t;if(!GC)throw new Error("Cannot access window outside of the DOM");return((t=e==null?void 0:e.ownerDocument)==null?void 0:t.defaultView)??window}Dl(AM,"getOwnerWindow");function ug(e){if(!GC)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}Dl(ug,"getOwnerDocument");function YC(e,t=!1){const{activeElement:s}=ug(e);if(!(s!=null&&s.nodeName))return null;if(qC(s)&&s.contentDocument)return YC(s.contentDocument.body,t);if(t){const r=s.getAttribute("aria-activedescendant");if(r){const i=ug(s).getElementById(r);if(i)return i}}return s}Dl(YC,"getActiveElement");function qC(e){return e.tagName==="IFRAME"}Dl(qC,"isFrame");var TM=Object.defineProperty,Bv=(e,t)=>TM(e,"name",{value:t,configurable:!0});function dg(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}Bv(dg,"setRef");function JC(...e){return t=>{let s=!1;const r=e.map(i=>{const a=dg(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():dg(e[i],null)}}}}Bv(JC,"composeRefs");function wt(...e){return d.useCallback(JC(...e),e)}Bv(wt,"useComposedRefs");var $M=Object.defineProperty,ws=(e,t)=>$M(e,"name",{value:t,configurable:!0});function RM(e,t){const s=d.createContext(t);s.displayName=e+"Context";const r=ws(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 ws(i,"useContext"),[r,i]}ws(RM,"createContext");function Hs(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=ws(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 ws(h,"useContext"),[u,h]}ws(r,"createContext");const i=ws(()=>{const a=s.map(l=>d.createContext(l));return ws(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,QC(i,...t)]}ws(Hs,"createContextScope");function QC(...e){const t=e[0];if(e.length===1)return t;const s=ws(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return ws(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}ws(QC,"composeContextScopes");var IM=Object.defineProperty,Ks=(e,t)=>IM(e,"name",{value:t,configurable:!0});function yi(e){const t=d.forwardRef((s,r)=>{let{children:i,...a}=s,l=null,o=!1;const c=[];hg(i)&&typeof bu=="function"&&(i=bu(i._payload)),d.Children.forEach(i,m=>{var p;if(n1(m)){o=!0;const g=m;let v="child"in g.props?g.props.child:g.props.children;hg(v)&&typeof bu=="function"&&(v=bu(v._payload)),l=PM(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?t1(l):void 0,h=wt(r,u);if(!l){if(i||i===0)throw new Error(o?OM(e):DM(e));return i}const f=e1(a,l.props??{});return l.type!==d.Fragment&&(f.ref=r?h:u),d.cloneElement(l,f)});return t.displayName=`${e}.Slot`,t}Ks(yi,"createSlot");var XC=Symbol.for("radix.slottable");function ZC(e){const t=Ks(s=>"child"in s?s.children(s.child):s.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=XC,t}Ks(ZC,"createSlottable");var PM=Ks((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 e1(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}}Ks(e1,"mergeProps");function t1(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)}Ks(t1,"getElementRef");function n1(e){return d.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===XC}Ks(n1,"isSlottable");var MM=Symbol.for("react.lazy");function hg(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===MM&&"_payload"in e&&s1(e._payload)}Ks(hg,"isLazyComponent");function s1(e){return typeof e=="object"&&e!==null&&"then"in e}Ks(s1,"isPromiseLike");var DM=Ks(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),OM=Ks(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),bu=Rl[" use ".trim().toString()],LM=Object.defineProperty,rn=(e,t)=>LM(e,"name",{value:t,configurable:!0});function zh(e){const t=e+"CollectionProvider",[s,r]=Hs(t),[i,a]=s(t,{collectionRef:{current:null},itemMap:new Map}),l=rn(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=yi(o),u=d.forwardRef((v,b)=>{const{scope:j,children:x}=v,w=a(o,j),y=wt(b,w.collectionRef);return n.jsx(c,{ref:y,children:x})});u.displayName=o;const h=e+"CollectionItemSlot",f="data-radix-collection-item",m=yi(h),p=d.forwardRef((v,b)=>{const{scope:j,children:x,...w}=v,y=d.useRef(null),k=wt(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 rn(g,"useCollection"),[{Provider:l,Slot:u,ItemSlot:p},g,r]}rn(zh,"createCollection");var Fb=new WeakMap,Bt,Xn,fm=(Xn=class extends Map{constructor(s){super(s);Ay(this,Bt);zf(this,Bt,[...super.keys()]),Fb.set(this,!0)}set(s,r){return Fb.get(this)&&(this.has(s)?xn(this,Bt)[xn(this,Bt).indexOf(s)]=s:xn(this,Bt).push(s)),super.set(s,r),this}insert(s,r,i){const a=this.has(r),l=xn(this,Bt).length,o=Wv(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=[...xn(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 Xn(this);return a.insert(s,r,i),a}before(s){const r=xn(this,Bt).indexOf(s)-1;if(!(r<0))return this.entryAt(r)}setBefore(s,r,i){const a=xn(this,Bt).indexOf(s);return a===-1?this:this.insert(a,r,i)}after(s){let r=xn(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=xn(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 zf(this,Bt,[]),super.clear()}delete(s){const r=super.delete(s);return r&&xn(this,Bt).splice(xn(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=ad(xn(this,Bt),s);if(r!==void 0)return this.get(r)}entryAt(s){const r=ad(xn(this,Bt),s);if(r!==void 0)return[r,this.get(r)]}indexOf(s){return xn(this,Bt).indexOf(s)}keyAt(s){return ad(xn(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 Xn(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 Xn(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 Xn(r)}toReversed(){const s=new Xn;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 Xn(r)}slice(s,r){const i=new Xn;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,rn(Xn,"OrderedDict"),Xn);function ad(e,t){if("at"in Array.prototype)return Array.prototype.at.call(e,t);const s=r1(e,t);return s===-1?void 0:e[s]}rn(ad,"at");function r1(e,t){const s=e.length,r=Wv(t),i=r>=0?r:s+r;return i<0||i>=s?-1:i}rn(r1,"toSafeIndex");function Wv(e){return e!==e||e===0?0:Math.trunc(e)}rn(Wv,"toSafeInteger");function FM(e){const t=e+"CollectionProvider",[s,r]=Hs(t),[i,a]=s(t,{collectionElement:null,collectionRef:{current:null},collectionRefObject:{current:null},itemMap:new fm,setItemMap:rn(()=>{},"setItemMap")}),l=rn(({state:w,...y})=>w?n.jsx(c,{...y,state:w}):n.jsx(o,{...y}),"CollectionProvider");l.displayName=t;const o=rn(w=>{const y=b();return n.jsx(c,{...w,state:y})},"CollectionInit");o.displayName=t+"Init";const c=rn(w=>{const{scope:y,children:k,state:N}=w,S=d.useRef(null),[C,T]=d.useState(null),R=wt(S,T),[I,L]=N;return d.useEffect(()=>{if(!C)return;const _=l1(()=>{});return _.observe(C,{childList:!0,subtree:!0}),()=>{_.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=yi(u),f=d.forwardRef((w,y)=>{const{scope:k,children:N}=w,S=a(u,k),C=wt(y,S.collectionRef);return n.jsx(h,{ref:C,children:N})});f.displayName=u;const m=e+"CollectionItemSlot",p="data-radix-collection-item",g=yi(m),v=d.forwardRef((w,y)=>{const{scope:k,children:N,...S}=w,C=d.useRef(null),[T,R]=d.useState(null),I=wt(y,C,R),L=a(m,k),{setItemMap:_}=L,$=d.useRef(S);i1($.current,S)||($.current=S);const P=$.current;return d.useEffect(()=>{const O=P;return _(M=>T?M.has(T)?M.set(T,{...O,element:T}).toSorted(fg):(M.set(T,{...O,element:T}),M.toSorted(fg)):M),()=>{_(M=>!T||!M.has(T)?M:(M.delete(T),new fm(M)))}},[T,P,_]),n.jsx(g,{[p]:"",ref:I,children:N})});v.displayName=m;function b(){return d.useState(new fm)}rn(b,"useInitCollection");function j(w){const{itemMap:y}=a(e+"CollectionConsumer",w);return y}return rn(j,"useCollection"),[{Provider:l,Slot:f,ItemSlot:v},{createCollectionScope:r,useCollection:j,useInitCollection:b}]}rn(FM,"createCollection");function i1(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}rn(i1,"shallowEqual");function a1(e,t){return!!(t.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_PRECEDING)}rn(a1,"isElementPreceding");function fg(e,t){return!e[1].element||!t[1].element?0:a1(e[1].element,t[1].element)?-1:1}rn(fg,"sortByDocumentPosition");function l1(e){return new MutationObserver(s=>{for(const r of s)if(r.type==="childList"){e();return}})}rn(l1,"getChildListObserver");var _M=Object.defineProperty,zM=(e,t)=>_M(e,"name",{value:t,configurable:!0}),UM=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],gt=UM.reduce((e,t)=>{const s=yi(`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 Uh(e,t){e&&Ml.flushSync(()=>e.dispatchEvent(t))}zM(Uh,"dispatchDiscreteCustomEvent");var BM=Object.defineProperty,WM=(e,t)=>BM(e,"name",{value:t,configurable:!0});function Tn(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)},[])}WM(Tn,"useCallbackRef");var HM=Object.defineProperty,Qt=(e,t)=>HM(e,"name",{value:t,configurable:!0}),mg="dismissableLayer.update",KM="dismissableLayer.pointerDownOutside",VM="dismissableLayer.focusOutside",_b,Hv=d.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),Bh=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(Hv),[m,p]=d.useState(null),g=(m==null?void 0:m.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,v]=d.useState({}),b=wt(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=c1(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.branches].some($=>$.contains(L));return N&&!_},[f.branches,N])}),T=u1(L=>{if(i&&S.current)return;const _=L.target;[...f.branches].some(P=>P.contains(_))||(o==null||o(L),c==null||c(L),L.defaultPrevented||u==null||u())},g),R=m?y===j.length-1:!1,I=Tn(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&&(_b=g.body.style.pointerEvents,g.body.style.pointerEvents="none"),f.layersWithOutsidePointerEventsDisabled.add(m)),f.layers.add(m),pg(),()=>{r&&(f.layersWithOutsidePointerEventsDisabled.delete(m),f.layersWithOutsidePointerEventsDisabled.size===0&&(g.body.style.pointerEvents=_b))}},[m,g,r,f]),d.useEffect(()=>()=>{m&&(f.layers.delete(m),f.layersWithOutsidePointerEventsDisabled.delete(m),pg())},[m,f]),d.useEffect(()=>{const L=Qt(()=>v({}),"handleUpdate");return document.addEventListener(mg,L),()=>document.removeEventListener(mg,L)},[]),n.jsx(gt.div,{...h,ref:b,style:{pointerEvents:k?N?"auto":"none":void 0,...t.style},onFocusCapture:Me(t.onFocusCapture,T.onFocusCapture),onBlurCapture:Me(t.onBlurCapture,T.onBlurCapture),onPointerDownCapture:Me(t.onPointerDownCapture,C.onPointerDownCapture)})},"DismissableLayer")),GM=d.forwardRef(Qt(function(t,s){const r=d.useContext(Hv),i=d.useRef(null),a=wt(s,i);return d.useEffect(()=>{const l=i.current;if(l)return r.branches.add(l),()=>{r.branches.delete(l)}},[r.branches]),n.jsx(gt.div,{...t,ref:a})},"DismissableLayerBranch"));function o1(){const e=d.useContext(Hv),[t,s]=d.useState(null);return d.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),s}Qt(o1,"useDismissableLayerSurface");var YM=Qt(()=>!0,"IS_TRUE");function c1(e,t){const{ownerDocument:s=globalThis==null?void 0:globalThis.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:i,dismissableSurfaces:a,shouldHandlePointerDownOutside:l=YM}=t,o=Tn(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||Kv(KM,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(c1,"usePointerDownOutside");function u1(e,t=globalThis==null?void 0:globalThis.document){const s=Tn(e),r=d.useRef(!1);return d.useEffect(()=>{const i=Qt(a=>{a.target&&!r.current&&Kv(VM,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(u1,"useFocusOutside");function pg(){const e=new CustomEvent(mg);document.dispatchEvent(e)}Qt(pg,"dispatchUpdate");function Kv(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?Uh(i,a):i.dispatchEvent(a)}Qt(Kv,"handleAndDispatchCustomEvent");var qM=Bh,JM=GM,Kn=globalThis!=null&&globalThis.document?d.useLayoutEffect:()=>{},QM=Object.defineProperty,XM=(e,t)=>QM(e,"name",{value:t,configurable:!0}),Wh=d.forwardRef(XM(function(t,s){var c;const{container:r,...i}=t,[a,l]=d.useState(!1);Kn(()=>l(!0),[]);const o=r||a&&((c=globalThis==null?void 0:globalThis.document)==null?void 0:c.body);return o?Ml.createPortal(n.jsx(gt.div,{...i,ref:s}),o):null},"Portal")),ZM=Object.defineProperty,Wr=(e,t)=>ZM(e,"name",{value:t,configurable:!0});function d1(e,t){return d.useReducer((s,r)=>t[s][r]??s,e)}Wr(d1,"useStateMachine");var xr=Wr(e=>{const{present:t,children:s}=e,r=h1(t),i=typeof s=="function"?s({present:r.isPresent}):d.Children.only(s),a=f1(r.ref,m1(i));return typeof s=="function"||r.isPresent?d.cloneElement(i,{ref:a}):null},"Presence");function h1(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]=d1(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??Oa(r.current),l.current=void 0):a.current="none"},[c]),Kn(()=>{const h=r.current,f=i.current;if(f!==e){const p=a.current,g=Oa(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]),Kn(()=>{if(t){let h;const f=t.ownerDocument.defaultView??window,m=Wr(g=>{const b=Oa(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=Wr(g=>{g.target===t&&(a.current=Oa(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=Oa(f)}else r.current=null;s(h)},[])}}Wr(h1,"usePresence");function gg(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}Wr(gg,"setRef");function f1(...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=gg(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():gg(r[l],null)}}},[])}Wr(f1,"useStableComposedRefs");function Oa(e){return(e==null?void 0:e.animationName)||"none"}Wr(Oa,"getAnimationName");function m1(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)}Wr(m1,"getElementRef");var eD=Object.defineProperty,tD=(e,t)=>eD(e,"name",{value:t,configurable:!0}),zb=Rl[" useEffectEvent ".trim().toString()],Ub=Rl[" useInsertionEffect ".trim().toString()];function p1(e){if(typeof zb=="function")return zb(e);const t=d.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof Ub=="function"?Ub(()=>{t.current=e}):Kn(()=>{t.current=e}),d.useMemo(()=>(...s)=>{var r;return(r=t.current)==null?void 0:r.call(t,...s)},[])}tD(p1,"useEffectEvent");var nD=Object.defineProperty,Pc=(e,t)=>nD(e,"name",{value:t,configurable:!0}),sD=Rl[" useInsertionEffect ".trim().toString()]||Kn;function Ri({prop:e,defaultProp:t,onChange:s=Pc(()=>{},"onChange"),caller:r}){const[i,a,l]=g1({defaultProp:t,onChange:s}),o=e!==void 0,c=o?e:i,u=d.useCallback(h=>{var f;if(o){const m=x1(h)?h(e):h;m!==e&&((f=l.current)==null||f.call(l,m))}else a(h)},[o,e,a,l]);return[c,u]}Pc(Ri,"useControllableState");function g1({defaultProp:e,onChange:t}){const[s,r]=d.useState(e),i=d.useRef(s),a=d.useRef(t);return sD(()=>{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]}Pc(g1,"useUncontrolledState");function x1(e){return typeof e=="function"}Pc(x1,"isFunction");var Bb=Symbol("RADIX:SYNC_STATE");function rD(e,t,s,r){const{prop:i,defaultProp:a,onChange:l,caller:o}=t,c=i!==void 0,u=p1(l),h=[{...s,state:a}];r&&h.push(r);const[f,m]=d.useReducer((b,j)=>{if(j.type===Bb)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:Bb,state:i})},[i,f.state,c]),[v,m]}Pc(rD,"useControllableStateReducer");var iD=Object.defineProperty,aD=(e,t)=>iD(e,"name",{value:t,configurable:!0}),lD=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"}),Vv=d.forwardRef(aD(function(t,s){return n.jsx(gt.span,{...t,ref:s,style:{...lD,...t.style}})},"VisuallyHidden")),oD=Vv,cD=Object.defineProperty,vt=(e,t)=>cD(e,"name",{value:t,configurable:!0}),v1="ToastProvider",[Gv,j1,uD]=zh("Toast"),[w1,KX]=Hs("Toast",[uD]),[dD,Hh]=w1(v1),hD=vt(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 \`${v1}\`. Expected non-empty \`string\`.`),n.jsx(Gv.Provider,{scope:t,children:n.jsx(dD,{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"),fD="ToastViewport",mD=["F8"],xg="toast.viewportPause",vg="toast.viewportResume",pD=d.forwardRef(vt(function(t,s){const{__scopeToast:r,hotkey:i=mD,label:a="Notifications ({hotkey})",...l}=t,o=Hh(fD,r),c=j1(r),u=d.useRef(null),h=d.useRef(null),f=d.useRef(null),m=d.useRef(null),p=wt(s,m,o.onViewportChange),g=i.join("+").replace(/Key/g,"").replace(/Digit/g,""),v=o.toastCount>0;d.useEffect(()=>{const j=vt(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=vt(()=>{if(!o.isClosePausedRef.current){const S=new CustomEvent(xg);x.dispatchEvent(S),o.isClosePausedRef.current=!0}},"handlePause"),y=vt(()=>{if(o.isClosePausedRef.current){const S=new CustomEvent(vg);x.dispatchEvent(S),o.isClosePausedRef.current=!1}},"handleResume"),k=vt(S=>{!j.contains(S.relatedTarget)&&y()},"handleFocusOutResume"),N=vt(()=>{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,...N1(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=vt(w=>{var N,S,C;const y=w.altKey||w.ctrlKey||w.metaKey;if(w.key==="Tab"&&!y){const T=document.activeElement,R=w.shiftKey;if(w.target===j&&R){(N=h.current)==null||N.focus();return}const _=b({tabbingDirection:R?"backwards":"forwards"}),$=_.findIndex(P=>P===T);ld(_.slice($+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(JM,{ref:u,role:"region","aria-label":a.replace("{hotkey}",g),tabIndex:-1,style:{pointerEvents:v?void 0:"none"},children:[v&&n.jsx(Wb,{ref:h,onFocusFromOutsideViewport:()=>{const j=b({tabbingDirection:"forwards"});ld(j)}}),n.jsx(Gv.Slot,{scope:r,children:n.jsx(gt.ol,{tabIndex:-1,...l,ref:p})}),v&&n.jsx(Wb,{ref:f,onFocusFromOutsideViewport:()=>{const j=b({tabbingDirection:"backwards"});ld(j)}})]})},"ToastViewport")),gD="ToastFocusProxy",Wb=d.forwardRef(vt(function(t,s){const{__scopeToast:r,onFocusFromOutsideViewport:i,...a}=t,l=Hh(gD,r);return n.jsx(Vv,{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")),Kh="Toast",xD="toast.swipeStart",vD="toast.swipeMove",jD="toast.swipeCancel",wD="toast.swipeEnd",yD=d.forwardRef(vt(function(t,s){const{forceMount:r,open:i,defaultOpen:a,onOpenChange:l,...o}=t,[c,u]=Ri({prop:i,defaultProp:a??!0,onChange:l,caller:Kh});return n.jsx(xr,{present:r||c,children:n.jsx(ND,{open:c,...o,ref:s,onClose:()=>u(!1),onPause:Tn(t.onPause),onResume:Tn(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")),[bD,kD]=w1(Kh,{onClose(){}}),ND=d.forwardRef(vt(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=Hh(Kh,r),j=j1(r),[x,w]=d.useState(null),y=wt(s,w),k=d.useRef(null),N=d.useRef(null),S=a||b.duration,C=d.useRef(0),T=d.useRef(S),R=d.useRef(0),{onToastAdd:I,onToastRemove:L}=b,_=Tn(()=>{var M;(x==null?void 0:x.contains(document.activeElement))&&((M=b.viewport)==null||M.focus()),o()}),$=d.useCallback(O=>{!O||O===1/0||(window.clearTimeout(R.current),C.current=new Date().getTime(),R.current=window.setTimeout(_,O))},[_]);d.useEffect(()=>{const O=b.viewport;if(O){const M=vt(()=>{$(T.current),h==null||h()},"handleResume"),D=vt(()=>{const H=new Date().getTime()-C.current;T.current=T.current-H,window.clearTimeout(R.current),u==null||u()},"handlePause");return O.addEventListener(xg,D),O.addEventListener(vg,M),()=>{O.removeEventListener(xg,D),O.removeEventListener(vg,M)}}},[b.viewport,S,u,h,$]),d.useEffect(()=>{l&&!b.isClosePausedRef.current&&$(S)},[l,S,b.isClosePausedRef,$]),d.useEffect(()=>()=>{window.clearTimeout(R.current)},[]),d.useEffect(()=>(I(),()=>L()),[I,L]);const P=d.useMemo(()=>x?Yv(x):null,[x]);return b.viewport?n.jsxs(n.Fragment,{children:[P&&n.jsx(SD,{__scopeToast:r,role:"status","aria-live":i==="foreground"?"assertive":"polite",children:P}),n.jsx(bD,{scope:r,onClose:_,children:Ml.createPortal(n.jsx(Gv.ItemSlot,{scope:r,children:n.jsx(qM,{asChild:!0,onEscapeKeyDown:Me(c,O=>{j().some(D=>{var H;return(H=D.ref.current)==null?void 0:H.contains(O.target)})||_()}),children:n.jsx(gt.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,O=>{O.key==="Escape"&&(c==null||c(O.nativeEvent),O.nativeEvent.defaultPrevented||_())}),onPointerDown:Me(t.onPointerDown,O=>{O.button===0&&(k.current={x:O.clientX,y:O.clientY})}),onPointerMove:Me(t.onPointerMove,O=>{if(!k.current)return;const M=O.clientX-k.current.x,D=O.clientY-k.current.y,H=!!N.current,B=["left","right"].includes(b.swipeDirection),q=["left","up"].includes(b.swipeDirection)?Math.min:Math.max,W=B?q(0,M):0,Y=B?0:q(0,D),F=O.pointerType==="touch"?10:2,X={x:W,y:Y},Q={originalEvent:O,delta:X};H?(N.current=X,ko(vD,m,Q,{discrete:!1})):Hb(X,b.swipeDirection,F)?(N.current=X,ko(xD,f,Q,{discrete:!1}),O.target.setPointerCapture(O.pointerId)):(Math.abs(M)>F||Math.abs(D)>F)&&(k.current=null)}),onPointerUp:Me(t.onPointerUp,O=>{const M=N.current,D=O.target;if(D.hasPointerCapture(O.pointerId)&&D.releasePointerCapture(O.pointerId),N.current=null,k.current=null,M){const H=O.currentTarget,B={originalEvent:O,delta:M};Hb(M,b.swipeDirection,b.swipeThreshold)?ko(wD,g,B,{discrete:!0}):ko(jD,p,B,{discrete:!0}),H.addEventListener("click",q=>q.preventDefault(),{once:!0})}})})})}),b.viewport)})]}):null},"ToastImpl")),SD=vt(e=>{const{__scopeToast:t,children:s,...r}=e,i=Hh(Kh,t),[a,l]=d.useState(!1),[o,c]=d.useState(!1);return b1(()=>l(!0)),d.useEffect(()=>{const u=window.setTimeout(()=>c(!0),1e3);return()=>window.clearTimeout(u)},[]),o?null:n.jsx(Wh,{asChild:!0,container:i.announcerContainer||void 0,children:n.jsx(Vv,{...r,children:a&&n.jsxs(n.Fragment,{children:[i.label," ",s]})})})},"ToastAnnounce"),CD=d.forwardRef(vt(function(t,s){const{__scopeToast:r,...i}=t;return n.jsx(gt.div,{...i,ref:s})},"ToastTitle")),ED=d.forwardRef(vt(function(t,s){const{__scopeToast:r,...i}=t;return n.jsx(gt.div,{...i,ref:s})},"ToastDescription")),AD="ToastAction",TD=d.forwardRef(vt(function(t,s){const{altText:r,...i}=t;return r.trim()?n.jsx(y1,{altText:r,asChild:!0,children:n.jsx(RD,{...i,ref:s})}):(console.error(`Invalid prop \`altText\` supplied to \`${AD}\`. Expected non-empty \`string\`.`),null)},"ToastAction")),$D="ToastClose",RD=d.forwardRef(vt(function(t,s){const{__scopeToast:r,...i}=t,a=kD($D,r);return n.jsx(y1,{asChild:!0,children:n.jsx(gt.button,{type:"button",...i,ref:s,onClick:Me(t.onClick,a.onClose)})})},"ToastClose")),y1=d.forwardRef(vt(function(t,s){const{__scopeToast:r,altText:i,...a}=t;return n.jsx(gt.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":i||void 0,...a,ref:s})},"ToastAnnounceExclude"));function Yv(e){const t=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&t.push(r.textContent),k1(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(...Yv(r))}}),t}vt(Yv,"getAnnounceTextContent");function ko(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?Uh(i,a):i.dispatchEvent(a)}vt(ko,"handleAndDispatchCustomEvent");var Hb=vt((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 b1(e=()=>{}){const t=Tn(e);Kn(()=>{let s=0,r=0;return s=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(t)),()=>{window.cancelAnimationFrame(s),window.cancelAnimationFrame(r)}},[t])}vt(b1,"useNextFrame");function k1(e){return e.nodeType===e.ELEMENT_NODE}vt(k1,"isHTMLElement");function N1(e){const t=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:vt(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}vt(N1,"getTabbableCandidates");function ld(e){const t=document.activeElement;return e.some(s=>s===t?!0:(s.focus(),document.activeElement!==t))}vt(ld,"focusFirst");var Kb=hD,Vb=pD,ID=yD,PD=CD,MD=ED,DD=TD,OD=Object.defineProperty,LD=(e,t)=>OD(e,"name",{value:t,configurable:!0}),FD=Rl[" useId ".trim().toString()]||(()=>{}),_D=0;function Fs(e){const[t,s]=d.useState(FD());return Kn(()=>{e||s(r=>r??String(_D++))},[e]),e||(t?`radix-${t}`:"")}LD(Fs,"useId");const zD=["top","right","bottom","left"],bi=Math.min,Mr=Math.max,Kd=Math.round,ku=Math.floor,Dr=e=>({x:e,y:e}),UD={left:"right",right:"left",bottom:"top",top:"bottom"};function S1(e,t,s){return Mr(e,bi(t,s))}function Hr(e,t){return typeof e=="function"?e(t):e}function ki(e){return e.split("-")[0]}function Ol(e){return e.split("-")[1]}function qv(e){return e==="x"?"y":"x"}function Jv(e){return e==="y"?"height":"width"}function ir(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function Qv(e){return qv(ir(e))}function BD(e,t,s){s===void 0&&(s=!1);const r=Ol(e),i=Qv(e),a=Jv(i);let l=i==="x"?r===(s?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[a]>t.floating[a]&&(l=Vd(l)),[l,Vd(l)]}function WD(e){const t=Vd(e);return[jg(e),t,jg(t)]}function jg(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const Gb=["left","right"],Yb=["right","left"],HD=["top","bottom"],KD=["bottom","top"];function VD(e,t,s){switch(e){case"top":case"bottom":return s?t?Yb:Gb:t?Gb:Yb;case"left":case"right":return t?HD:KD;default:return[]}}function GD(e,t,s,r){const i=Ol(e);let a=VD(ki(e),s==="start",r);return i&&(a=a.map(l=>l+"-"+i),t&&(a=a.concat(a.map(jg)))),a}function Vd(e){const t=ki(e);return UD[t]+e.slice(t.length)}function YD(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 C1(e){return typeof e!="number"?YD(e):{top:e,right:e,bottom:e,left:e}}function Gd(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 qb(e,t,s){let{reference:r,floating:i}=e;const a=ir(t),l=Qv(t),o=Jv(l),c=ki(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=Ol(t);return g&&(p[l]+=m*(g==="end"?1:-1)*(s&&u?-1:1)),p}async function qD(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}=Hr(t,e),g=C1(p),b=o[m?f==="floating"?"reference":"floating":f],j=Gd(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=Gd(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 JD=50,QD=async(e,t,s)=>{const{placement:r="bottom",strategy:i="absolute",middleware:a=[],platform:l}=s,o=l.detectOverflow?l:{...l,detectOverflow:qD},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}=qb(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<JD&&(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}=qb(u,m,c)),v=-1)}return{x:h,y:f,placement:m,strategy:i,middlewareData:g}},XD=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}=Hr(e,t)||{};if(u==null)return{};const f=C1(h),m={x:s,y:r},p=Qv(i),g=Jv(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,T=S/2-v[g]/2-1,R=bi(f[j],T),I=bi(f[x],T),L=S-v[g]-I,_=S/2-v[g]/2+C,$=S1(R,_,L),P=!c.arrow&&Ol(i)!=null&&_!==$&&a.reference[g]/2-(_<R?R:I)-v[g]/2<0,O=P?_<R?_-R:_-L:0;return{[p]:m[p]+O,data:{[p]:$,centerOffset:_-$-O,...P&&{alignmentOffset:O}},reset:P}}}),ZD=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}=Hr(e,t);if((s=a.arrow)!=null&&s.alignmentOffset)return{};const j=ki(i),x=ir(o),w=ki(o)===o,y=await(c.isRTL==null?void 0:c.isRTL(u.floating)),k=m||(w||!v?[Vd(o)]:WD(o)),N=g!=="none";!m&&N&&k.push(...GD(o,v,g,y));const S=[o,...k],C=await c.detectOverflow(t,b),T=[];let R=((r=a.flip)==null?void 0:r.overflows)||[];if(h&&T.push(C[j]),f){const $=BD(i,l,y);T.push(C[$[0]],C[$[1]])}if(R=[...R,{placement:i,overflows:T}],!T.every($=>$<=0)){var I,L;const $=(((I=a.flip)==null?void 0:I.index)||0)+1,P=S[$];if(P&&(!(f==="alignment"?x!==ir(P):!1)||R.every(D=>ir(D.placement)===x?D.overflows[0]>0:!0)))return{data:{index:$,overflows:R},reset:{placement:P}};let O=(L=R.filter(M=>M.overflows[0]<=0).sort((M,D)=>M.overflows[1]-D.overflows[1])[0])==null?void 0:L.placement;if(!O)switch(p){case"bestFit":{var _;const M=(_=R.filter(D=>{if(N){const H=ir(D.placement);return H===x||H==="y"}return!0}).map(D=>[D.placement,D.overflows.filter(H=>H>0).reduce((H,B)=>H+B,0)]).sort((D,H)=>D[1]-H[1])[0])==null?void 0:_[0];M&&(O=M);break}case"initialPlacement":O=o;break}if(i!==O)return{reset:{placement:O}}}return{}}}};function Jb(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Qb(e){return zD.some(t=>e[t]>=0)}const eO=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:s,platform:r}=t,{strategy:i="referenceHidden",...a}=Hr(e,t);switch(i){case"referenceHidden":{const l=await r.detectOverflow(t,{...a,elementContext:"reference"}),o=Jb(l,s.reference);return{data:{referenceHiddenOffsets:o,referenceHidden:Qb(o)}}}case"escaped":{const l=await r.detectOverflow(t,{...a,altBoundary:!0}),o=Jb(l,s.floating);return{data:{escapedOffsets:o,escaped:Qb(o)}}}default:return{}}}}},E1=new Set(["left","top"]);async function tO(e,t){const{placement:s,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),l=ki(s),o=Ol(s),c=ir(s)==="y",u=E1.has(l)?-1:1,h=a&&c?-1:1,f=Hr(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 nO=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 tO(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}}}}},sO=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}=Hr(e,t),h={x:s,y:r},f=await a.detectOverflow(t,u),m=ir(i),p=qv(m);let g=h[p],v=h[m];const b=(x,w)=>S1(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}}}}}},rO=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}=Hr(e,t),m={x:i,y:a},p=ir(l),g=qv(p);let v=m[g],b=m[p];const j=Hr(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=E1.has(ki(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}}}},iO=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}=Hr(e,t),c=await i.detectOverflow(t,o),u=ki(s),h=Ol(s),f=ir(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=bi(p-c[g],b),w=bi(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*Mr(c.left,c.right):N=p-2*Mr(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 Vh(){return typeof window<"u"}function Ll(e){return A1(e)?(e.nodeName||"").toLowerCase():"#document"}function Vn(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function qr(e){var t;return(t=(A1(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function A1(e){return Vh()?e instanceof Node||e instanceof Vn(e).Node:!1}function ur(e){return Vh()?e instanceof Element||e instanceof Vn(e).Element:!1}function Ii(e){return Vh()?e instanceof HTMLElement||e instanceof Vn(e).HTMLElement:!1}function Xb(e){return!Vh()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Vn(e).ShadowRoot}function Gh(e){const{overflow:t,overflowX:s,overflowY:r,display:i}=dr(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+s)&&i!=="inline"&&i!=="contents"}function aO(e){return/^(table|td|th)$/.test(Ll(e))}function Yh(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const lO=/transform|translate|scale|rotate|perspective|filter/,oO=/paint|layout|strict|content/,Ui=e=>!!e&&e!=="none";let mm;function Xv(e){const t=ur(e)?dr(e):e;return Ui(t.transform)||Ui(t.translate)||Ui(t.scale)||Ui(t.rotate)||Ui(t.perspective)||!Zv()&&(Ui(t.backdropFilter)||Ui(t.filter))||lO.test(t.willChange||"")||oO.test(t.contain||"")}function cO(e){let t=ca(e);for(;Ii(t)&&!ic(t);){if(Xv(t))return t;if(Yh(t))return null;t=ca(t)}return null}function Zv(){return mm==null&&(mm=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),mm}function ic(e){return/^(html|body|#document)$/.test(Ll(e))}function dr(e){return Vn(e).getComputedStyle(e)}function qh(e){return ur(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function ca(e){if(Ll(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Xb(e)&&e.host||qr(e);return Xb(t)?t.host:t}function T1(e){const t=ca(e);return ic(t)?(e.ownerDocument||e).body:Ii(t)&&Gh(t)?t:T1(t)}function ac(e,t,s){var r;t===void 0&&(t=[]),s===void 0&&(s=!0);const i=T1(e),a=i===((r=e.ownerDocument)==null?void 0:r.body),l=Vn(i);if(a){const o=wg(l);return t.concat(l,l.visualViewport||[],Gh(i)?i:[],o&&s?ac(o):[])}else return t.concat(i,ac(i,[],s))}function wg(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function $1(e){const t=dr(e);let s=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Ii(e),a=i?e.offsetWidth:s,l=i?e.offsetHeight:r,o=Kd(s)!==a||Kd(r)!==l;return o&&(s=a,r=l),{width:s,height:r,$:o}}function ej(e){return ur(e)?e:e.contextElement}function il(e){const t=ej(e);if(!Ii(t))return Dr(1);const s=t.getBoundingClientRect(),{width:r,height:i,$:a}=$1(t);let l=(a?Kd(s.width):s.width)/r,o=(a?Kd(s.height):s.height)/i;return(!l||!Number.isFinite(l))&&(l=1),(!o||!Number.isFinite(o))&&(o=1),{x:l,y:o}}const uO=Dr(0);function R1(e){const t=Vn(e);return!Zv()||!t.visualViewport?uO:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function dO(e,t,s){return t===void 0&&(t=!1),!!s&&t&&s===Vn(e)}function ua(e,t,s,r){t===void 0&&(t=!1),s===void 0&&(s=!1);const i=e.getBoundingClientRect(),a=ej(e);let l=Dr(1);t&&(r?ur(r)&&(l=il(r)):l=il(e));const o=dO(a,s,r)?R1(a):Dr(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=Vn(a),p=ur(r)?Vn(r):r;let g=m,v=wg(g);for(;v&&p!==g;){const b=il(v),j=v.getBoundingClientRect(),x=dr(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=Vn(v),v=wg(g)}}return Gd({width:h,height:f,x:c,y:u})}function Jh(e,t){const s=qh(e).scrollLeft;return t?t.left+s:ua(qr(e)).left+s}function I1(e,t){const s=e.getBoundingClientRect(),r=s.left+t.scrollLeft-Jh(e,s),i=s.top+t.scrollTop;return{x:r,y:i}}function hO(e){let{elements:t,rect:s,offsetParent:r,strategy:i}=e;const a=i==="fixed",l=qr(r),o=t?Yh(t.floating):!1;if(r===l||o&&a)return s;let c={scrollLeft:0,scrollTop:0},u=Dr(1);const h=Dr(0),f=Ii(r);if((f||!a)&&((Ll(r)!=="body"||Gh(l))&&(c=qh(r)),f)){const p=ua(r);u=il(r),h.x=p.x+r.clientLeft,h.y=p.y+r.clientTop}const m=l&&!f&&!a?I1(l,c):Dr(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 fO(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function mO(e){const t=qh(e),s=e.ownerDocument.body,r=Mr(e.scrollWidth,e.clientWidth,s.scrollWidth,s.clientWidth),i=Mr(e.scrollHeight,e.clientHeight,s.scrollHeight,s.clientHeight);let a=-t.scrollLeft+Jh(e);const l=-t.scrollTop;return dr(s).direction==="rtl"&&(a+=Mr(e.clientWidth,s.clientWidth)-r),{width:r,height:i,x:a,y:l}}const pO=25;function gO(e,t,s){s===void 0&&(s="viewport");const r=s==="layoutViewport",i=Vn(e),a=qr(e),l=i.visualViewport;let o=a.clientWidth,c=a.clientHeight,u=0,h=0;if(l){const m=!Zv()||t==="fixed";r?m||(u=-l.offsetLeft,h=-l.offsetTop):(o=l.width,c=l.height,m&&(u=l.offsetLeft,h=l.offsetTop))}if(Jh(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<=pO&&(o-=j)}return{width:o,height:c,x:u,y:h}}function xO(e,t){const s=ua(e,!0,t==="fixed"),r=s.top+e.clientTop,i=s.left+e.clientLeft,a=il(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 Zb(e,t,s){let r;if(t==="viewport"||t==="layoutViewport")r=gO(e,s,t);else if(t==="document")r=mO(qr(e));else if(ur(t))r=xO(t,s);else{const i=R1(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Gd(r)}function vO(e,t){const s=t.get(e);if(s)return s;let r=ac(e,[],!1).filter(o=>ur(o)&&Ll(o)!=="body"),i=null;const a=dr(e).position==="fixed";let l=a?ca(e):e;for(;ur(l)&&!ic(l);){const o=dr(l),c=Xv(l),u=i?i.position:a?"fixed":"";!c&&(u==="fixed"||u==="absolute"&&o.position==="static")?r=r.filter(f=>f!==l):i=o,l=ca(l)}return t.set(e,r),r}function jO(e){let{element:t,boundary:s,rootBoundary:r,strategy:i}=e;const l=[...s==="clippingAncestors"?Yh(t)?[]:vO(t,this._c):[].concat(s),r],o=Zb(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=Zb(t,l[m],i);c=Mr(p.top,c),u=bi(p.right,u),h=bi(p.bottom,h),f=Mr(p.left,f)}return{width:u-f,height:h-c,x:f,y:c}}function wO(e){const{width:t,height:s}=$1(e);return{width:t,height:s}}function yO(e,t,s){const r=Ii(t),i=qr(t),a=s==="fixed",l=ua(e,!0,a,t);let o={scrollLeft:0,scrollTop:0};const c=Dr(0);if((r||!a)&&((Ll(t)!=="body"||Gh(i))&&(o=qh(t)),r)){const m=ua(t,!0,a,t);c.x=m.x+t.clientLeft,c.y=m.y+t.clientTop}!r&&i&&(c.x=Jh(i));const u=i&&!r&&!a?I1(i,o):Dr(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 pm(e){return dr(e).position==="static"}function ek(e,t){if(!Ii(e)||dr(e).position==="fixed")return null;if(t)return t(e);let s=e.offsetParent;return qr(e)===s&&(s=s.ownerDocument.body),s}function P1(e,t){const s=Vn(e);if(Yh(e))return s;if(!Ii(e)){let i=ca(e);for(;i&&!ic(i);){if(ur(i)&&!pm(i))return i;i=ca(i)}return s}let r=ek(e,t);for(;r&&aO(r)&&pm(r);)r=ek(r,t);return r&&ic(r)&&pm(r)&&!Xv(r)?s:r||cO(e)||s}const bO=async function(e){const t=this.getOffsetParent||P1,s=this.getDimensions,r=await s(e.floating);return{reference:yO(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function kO(e){return dr(e).direction==="rtl"}const NO={convertOffsetParentRelativeRectToViewportRelativeRect:hO,getDocumentElement:qr,getClippingRect:jO,getOffsetParent:P1,getElementRects:bO,getClientRects:fO,getDimensions:wO,getScale:il,isElement:ur,isRTL:kO};function M1(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function SO(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=ku(g),x=ku(a.clientWidth-(p+v)),w=ku(a.clientHeight-(g+b)),y=ku(p),N={rootMargin:-j+"px "+-x+"px "+-w+"px "+-y+"px",threshold:Mr(0,bi(1,f))||1};let S=!0;function C(T){const R=T[0].intersectionRatio;if(!M1(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=Vn(e),u=()=>o(s);return c.addEventListener("resize",u),o(!0),()=>{c.removeEventListener("resize",u),l()}}function CO(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=ej(e),h=i||a?[...u?ac(u):[],...t?ac(t):[]]:[];h.forEach(j=>{i&&j.addEventListener("scroll",s),a&&j.addEventListener("resize",s)});const f=u&&o?SO(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?ua(e):null;c&&b();function b(){const j=ua(e);v&&!M1(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 EO=nO,AO=sO,TO=ZD,$O=iO,RO=eO,tk=XD,IO=rO,PO=(e,t,s)=>{const r=new Map,i=s??{},a={...NO,...i.platform,_c:r};return QD(e,t,{...i,platform:a})};var MO=typeof document<"u",DO=function(){},od=MO?d.useLayoutEffect:DO;function Yd(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(!Yd(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)&&!Yd(e[a],t[a]))return!1}return!0}return e!==e&&t!==t}function D1(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function nk(e,t){const s=D1(e);return Math.round(t*s)/s}function gm(e){const t=d.useRef(e);return od(()=>{t.current=e}),t}function OO(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);Yd(m,r)||p(r);const[g,v]=d.useState(null),[b,j]=d.useState(null),x=d.useCallback(D=>{D!==N.current&&(N.current=D,v(D))},[]),w=d.useCallback(D=>{D!==S.current&&(S.current=D,j(D))},[]),y=a||g,k=l||b,N=d.useRef(null),S=d.useRef(null),C=d.useRef(h),T=c!=null,R=gm(c),I=gm(i),L=gm(u),_=d.useCallback(()=>{if(!N.current||!S.current)return;const D={placement:t,strategy:s,middleware:m};I.current&&(D.platform=I.current),PO(N.current,S.current,D).then(H=>{const B={...H,isPositioned:L.current!==!1};$.current&&!Yd(C.current,B)&&(C.current=B,Ml.flushSync(()=>{f(B)}))})},[m,t,s,I,L]);od(()=>{u===!1&&C.current.isPositioned&&(C.current.isPositioned=!1,f(D=>({...D,isPositioned:!1})))},[u]);const $=d.useRef(!1);od(()=>($.current=!0,()=>{$.current=!1}),[]),od(()=>{if(y&&(N.current=y),k&&(S.current=k),y&&k){if(R.current)return R.current(y,k,_);_()}},[y,k,_,R,T]);const P=d.useMemo(()=>({reference:N,floating:S,setReference:x,setFloating:w}),[x,w]),O=d.useMemo(()=>({reference:y,floating:k}),[y,k]),M=d.useMemo(()=>{const D={position:s,left:0,top:0};if(!O.floating)return D;const H=nk(O.floating,h.x),B=nk(O.floating,h.y);return o?{...D,transform:"translate("+H+"px, "+B+"px)",...D1(O.floating)>=1.5&&{willChange:"transform"}}:{position:s,left:H,top:B}},[s,o,O.floating,h.x,h.y]);return d.useMemo(()=>({...h,update:_,refs:P,elements:O,floatingStyles:M}),[h,_,P,O,M])}const LO=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?tk({element:r.current,padding:i}).fn(s):{}:r?tk({element:r,padding:i}).fn(s):{}}}},FO=(e,t)=>{const s=EO(e);return{name:s.name,fn:s.fn,options:[e,t]}},_O=(e,t)=>{const s=AO(e);return{name:s.name,fn:s.fn,options:[e,t]}},zO=(e,t)=>({fn:IO(e).fn,options:[e,t]}),UO=(e,t)=>{const s=TO(e);return{name:s.name,fn:s.fn,options:[e,t]}},BO=(e,t)=>{const s=$O(e);return{name:s.name,fn:s.fn,options:[e,t]}},WO=(e,t)=>{const s=RO(e);return{name:s.name,fn:s.fn,options:[e,t]}},HO=(e,t)=>{const s=LO(e);return{name:s.name,fn:s.fn,options:[e,t]}};var KO=Object.defineProperty,VO=(e,t)=>KO(e,"name",{value:t,configurable:!0});function O1(e){const[t,s]=d.useState(void 0);return Kn(()=>{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}VO(O1,"useSize");var GO=Object.defineProperty,gi=(e,t)=>GO(e,"name",{value:t,configurable:!0}),L1="Popper",[F1,Qh]=Hs(L1),[YO,_1]=F1(L1),qO=gi(e=>{const{__scopePopper:t,children:s}=e,[r,i]=d.useState(null),[a,l]=d.useState(void 0);return n.jsx(YO,{scope:t,anchor:r,onAnchorChange:i,placementState:a,setPlacementState:l,children:s})},"Popper"),JO="PopperAnchor",QO=d.forwardRef(gi(function(t,s){const{__scopePopper:r,virtualRef:i,...a}=t,l=_1(JO,r),o=d.useRef(null),c=l.onAnchorChange,u=d.useCallback(v=>{o.current=v,v&&c(v)},[c]),h=wt(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&&Xh(l.placementState),p=m==null?void 0:m[0],g=m==null?void 0:m[1];return i?null:n.jsx(gt.div,{"data-radix-popper-side":p,"data-radix-popper-align":g,...a,ref:h})},"PopperAnchor")),z1="PopperContent",[XO,VX]=F1(z1),ZO=d.forwardRef(gi(function(t,s){var Oe,Ie,Fe,U,se,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=_1(z1,r),[x,w]=d.useState(null),y=wt(s,w),[k,N]=d.useState(null),S=O1(k),C=(S==null?void 0:S.width)??0,T=(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],_=L.length>0,$={padding:I,boundary:L.filter(U1),altBoundary:_},{refs:P,floatingStyles:O,placement:M,isPositioned:D,middlewareData:H}=OO({strategy:"fixed",placement:R,whileElementsMounted:gi((...ge)=>CO(...ge,{animationFrame:g==="always"}),"whileElementsMounted"),elements:{reference:j.anchor},middleware:[FO({mainAxis:a+T,alignmentAxis:o}),u&&_O({mainAxis:!0,crossAxis:!1,limiter:m==="partial"?zO():void 0,...$}),u&&UO({...$}),BO({...$,apply:gi(({elements:ge,rects:$e,availableWidth:De,availableHeight:Je})=>{const{width:ze,height:Se}=$e.reference,Ue=ge.floating.style;Ue.setProperty("--radix-popper-available-width",`${De}px`),Ue.setProperty("--radix-popper-available-height",`${Je}px`),Ue.setProperty("--radix-popper-anchor-width",`${ze}px`),Ue.setProperty("--radix-popper-anchor-height",`${Se}px`)},"apply")}),k&&HO({element:k,padding:c}),eL({arrowWidth:C,arrowHeight:T}),p&&WO({strategy:"referenceHidden",...$,boundary:_?$.boundary:void 0})]}),B=j.setPlacementState;Kn(()=>(B(M),()=>{B(void 0)}),[M,B]);const[q,W]=Xh(M),Y=Tn(v);Kn(()=>{D&&(Y==null||Y())},[D,Y]);const F=(Oe=H.arrow)==null?void 0:Oe.x,X=(Ie=H.arrow)==null?void 0:Ie.y,Q=((Fe=H.arrow)==null?void 0:Fe.centerOffset)!==0,[ee,fe]=d.useState();return Kn(()=>{x&&fe(window.getComputedStyle(x).zIndex)},[x]),n.jsx("div",{ref:P.setFloating,"data-radix-popper-content-wrapper":"",style:{...O,transform:D?O.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ee,"--radix-popper-transform-origin":[(U=H.transformOrigin)==null?void 0:U.x,(se=H.transformOrigin)==null?void 0:se.y].join(" "),...((J=H.hide)==null?void 0:J.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:n.jsx(XO,{scope:r,placedSide:q,placedAlign:W,onArrowChange:N,arrowX:F,arrowY:X,shouldHideArrow:Q,children:n.jsx(gt.div,{"data-side":q,"data-align":W,...b,ref:y,style:{...b.style,animation:D?(ye=b.style)==null?void 0:ye.animation:"none"}})})})},"PopperContent"));function U1(e){return e!==null}gi(U1,"isNotNull");var eL=gi(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]=Xh(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 Xh(e){const[t,s="center"]=e.split("-");return[t,s]}gi(Xh,"getSideAndAlignFromPlacement");var tj=qO,B1=QO,W1=ZO,tL=Object.defineProperty,ln=(e,t)=>tL(e,"name",{value:t,configurable:!0}),[nj,GX]=Hs("Tooltip",[Qh]),sj=Qh(),nL="TooltipProvider",sL=700,yg="tooltip.open",[rL,rj]=nj(nL),iL=ln(e=>{const{__scopeTooltip:t,delayDuration:s=sL,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(rL,{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"),bg="Tooltip",[aL,Mc]=nj(bg),lL=ln(e=>{const{__scopeTooltip:t,children:s,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:l,delayDuration:o}=e,c=rj(bg,e.__scopeTooltip),u=sj(t),[h,f]=d.useState(null),[m,p]=d.useState(void 0),g=Fs(),v=d.useRef(0),b=l??c.disableHoverableContent,j=o??c.delayDuration,x=d.useRef(!1),[w,y]=Ri({prop:r,defaultProp:i??!1,onChange:ln(R=>{R?(c.onOpen(),document.dispatchEvent(new CustomEvent(yg))):c.onClose(),a==null||a(R)},"onChange"),caller:bg}),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 T=m??g;return n.jsx(tj,{...u,children:n.jsx(aL,{scope:t,contentId:T,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"),sk="TooltipTrigger",oL=d.forwardRef(ln(function(t,s){const{__scopeTooltip:r,...i}=t,a=Mc(sk,r),l=rj(sk,r),o=sj(r),c=d.useRef(null),u=wt(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(B1,{asChild:!0,...o,children:n.jsx(gt.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")),H1="TooltipPortal",[cL,uL]=nj(H1,{forceMount:void 0}),dL=ln(e=>{const{__scopeTooltip:t,forceMount:s,children:r,container:i}=e,a=Mc(H1,t);return n.jsx(cL,{scope:t,forceMount:s,children:n.jsx(xr,{present:s||a.open,children:n.jsx(Wh,{asChild:!0,container:i,children:r})})})},"TooltipPortal"),lc="TooltipContent",hL=d.forwardRef(ln(function(t,s){const r=uL(lc,t.__scopeTooltip),{forceMount:i=r.forceMount,side:a="top",...l}=t,o=Mc(lc,t.__scopeTooltip);return n.jsx(xr,{present:i||o.open,children:o.disableHoverableContent?n.jsx(K1,{side:a,...l,ref:s}):n.jsx(fL,{side:a,...l,ref:s})})},"TooltipContent")),fL=d.forwardRef(ln(function(t,s){const r=Mc(lc,t.__scopeTooltip),i=rj(lc,t.__scopeTooltip),a=d.useRef(null),l=wt(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=V1(x,j.getBoundingClientRect()),y=G1(x,w),k=Y1(b.getBoundingClientRect()),N=J1([...y,...k]);c(N),m(!0)},[m]);return d.useEffect(()=>()=>p(),[p]),d.useEffect(()=>{if(u&&f){const v=ln(j=>g(j,f),"handleTriggerLeave"),b=ln(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=ln(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=!q1(x,o);w?p():y&&(p(),h())},"handleTrackPointerGrace");return document.addEventListener("pointermove",v),()=>document.removeEventListener("pointermove",v)}},[u,f,o,h,p]),n.jsx(K1,{...t,ref:l})},"TooltipContentHoverable")),mL=ZC("TooltipContent"),K1=d.forwardRef(ln(function(t,s){const{__scopeTooltip:r,children:i,"aria-label":a,id:l,onEscapeKeyDown:o,onPointerDownOutside:c,...u}=t,h=Mc(lc,r),f=sj(r),{onClose:m}=h;d.useEffect(()=>(document.addEventListener(yg,m),()=>document.removeEventListener(yg,m)),[m]),d.useEffect(()=>{if(h.trigger){const g=ln(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 Kn(()=>(p(l),()=>{p(void 0)}),[l,p]),n.jsx(Bh,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:o,onPointerDownOutside:c,onFocusOutside:g=>g.preventDefault(),onDismiss:m,children:n.jsxs(W1,{"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(mL,{children:i}),a?n.jsx(oD,{id:h.contentId,role:"tooltip",children:a}):null]})})},"TooltipContentImpl"));function V1(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")}}ln(V1,"getExitSideFromRect");function G1(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}ln(G1,"getPaddedExitPoints");function Y1(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}]}ln(Y1,"getPointsFromRect");function q1(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}ln(q1,"isPointInPolygon");function J1(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),Q1(t)}ln(J1,"getHull");function Q1(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)}ln(Q1,"getHullPresorted");var rk=iL,oc=lL,cc=oL,uc=dL,dc=hL;let Vt={time:"auto",date:"auto",locale:void 0};function ij(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 X1(){return{time:Vt.time,date:Vt.date}}function Dc(e,t){const s=Vt;ij(e);try{return t()}finally{Vt=s}}const kg="buddi:formats";function Oc(){if(Vt.locale)return Vt.locale;try{return typeof navigator<"u"&&navigator.language?navigator.language:"en-US"}catch{return"en-US"}}const ik=new Map;function Fl(e,t){const s=`${e}|${JSON.stringify(t)}`;let r=ik.get(s);if(!r){try{r=new Intl.DateTimeFormat(e,t)}catch{r=new Intl.DateTimeFormat(e,{...t,timeZone:"UTC"})}ik.set(s,r)}return r}function xm(e,t,s,r){return Object.fromEntries(Fl(s,{timeZone:t,...r}).formatToParts(e).map(i=>[i.type,i.value]))}function pL(){return Vt.time==="12h"?{hour:"numeric",minute:"2-digit",hourCycle:"h12"}:Vt.time==="24h"?{hour:"2-digit",minute:"2-digit",hourCycle:"h23"}:{hour:Zh()?"numeric":"2-digit",minute:"2-digit"}}function gL(){return Vt.time==="auto"?Oc():"en-US"}function zt(e,t){return Number.isNaN(e.getTime())?"—":Fl(gL(),{timeZone:t,...pL()}).format(e)}function xL(e){return e>=1440&&!Zh()?"24:00":zt(new Date(Date.UTC(2026,0,1,Math.floor(e/60)%24,e%60)),"UTC")}function Zh(){var e;return Vt.time!=="auto"?Vt.time==="12h":((e=Fl(Oc(),{hour:"numeric"}).resolvedOptions().hourCycle)==null?void 0:e.startsWith("h1"))===!0}function Z1(){return`Profile (${Zh()?"12-hour":"24-hour"})`}function vL(){if(Vt.date!=="auto")return Vt.date==="short";const e=Fl(Oc(),{month:"short",day:"numeric"}).formatToParts(new Date(Date.UTC(2026,9,1))).map(t=>t.type);return e.indexOf("month")<e.indexOf("day")}function vr(e,t,s={}){return jL(e,t,s).replace(/\bSept\b/g,"Sep")}function jL(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=xm(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=xm(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=xm(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 Fl(Oc(),{timeZone:t,month:a?"short":"long",day:"numeric",...i?{year:"numeric"}:{},...r?{weekday:a?"short":"long"}:{}}).format(e)}}function eE(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"?Oc():"en-GB";return Fl(r,{timeZone:"UTC",month:"long",year:"numeric"}).format(s)}function Lc(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:vr(r,"UTC",t)}function nt(e,t){if(!e)return"—";const s=new Date(e);return Number.isNaN(s.getTime())?String(e):`${vr(s,t,{year:!0,compact:!0})}, ${zt(s,t)}`}function aj(e,t){return`${vr(e,t,{weekday:!0,compact:!0})}, ${zt(e,t)}`}function Le(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 lj(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 wL(e,t=Date.now()){const s=lj(e,t);return s===""?"":s==="now"||new Date(e).getTime()>t?"just now":s==="1 d"?"yesterday":`${s} ago`}function yL(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 Ng(e){return[...e.cacheRead?[`cached ${Xt(e.cacheRead)}`]:[],...e.cacheWrite?[`cache write ${Xt(e.cacheWrite)}`]:[]].join(", ")}function bL(e){const t=Ng(e);return`${Xt(e.input)} in${t?` (${t})`:""} / ${Xt(e.output)} out`}function rs(e){try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function hc(e,t=8){return e.length<=t?e:e.slice(0,t)}function Us(e,t){return e.length<=t?e:`${e.slice(0,t-1)}…`}function fc(e){if(e.kind!=="agent")return e.title;const t=e.title.replace(/^@[^\s:]+:\s+/,"");return t.trim()===""?e.title:t}const ak="buddi_csrf",_l="x-buddi-csrf",hr="buddi:agents-changed",Xi="buddi:status-changed",ho=e=>(window.dispatchEvent(new Event(Xi)),e),Sg="buddi:locked",kL="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 ga(){var r;const e=Number(location.port)||(location.protocol==="https:"?443:80),t=document.cookie.match(new RegExp(`(?:^|; )${ak}_${e}=([^;]*)`));if(t!=null&&t[1])return decodeURIComponent(t[1]);const s=[...document.cookie.matchAll(new RegExp(`(?:^|; )${ak}(?:_\\d+)?=([^;]*)`,"g"))];return s.length===1&&((r=s[0])!=null&&r[1])?decodeURIComponent(s[0][1]):""}const qd="buddi isn't answering.";let Cg=null;const Eg=new Set;function fo(e){if(e!==(Cg===null)){Cg=e?null:Date.now();for(const t of Eg)t()}}function mc(){return Cg}function oj(e){return Eg.add(e),()=>Eg.delete(e)}function Jd(e){return e instanceof ve&&(e.status===0||e.status===502||e.status===503)&&e.message===qd}async function xa(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:(fo(!1),new ve(0,qd,o))}if(s.status===401)throw fo(!0),new ve(401,"This session has expired. Run `buddi dashboard` for a fresh link.");if(s.status===423)throw fo(!0),window.dispatchEvent(new Event(Sg)),new ve(423,"This dashboard is locked.");const r=await s.text(),i=r===""?null:NL(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 fo(!1),new ve(s.status,qd,i);if(fo(!0),!s.ok){const o=(t.method??"GET").toUpperCase(),c=a??(s.status===403&&o!=="GET"&&o!=="HEAD"?kL:`request failed (${s.status})`);throw new ve(s.status,c,i)}return i}function NL(e){try{return JSON.parse(e)}catch{return null}}function vm(){return X1().time==="auto"?{hour:Zh()?"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 xa(`/api${e}${r?`?${r}`:""}`)}function Ag(e,t){return xa(`/api${e}`,{method:"POST",headers:{[_l]:ga()},body:t})}function nr(e){return xa(`/api${e}`,{method:"DELETE",headers:{[_l]:ga()}})}function te(e,t={}){return xa(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/json",[_l]:ga()},body:JSON.stringify(t??{})})}function tE(e,t,s,r={}){const i=t.name.replace(/[^\w.-]+/g,"_").slice(-120)||s;return xa(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/octet-stream",[_l]:ga(),"X-Filename":i,...r},body:t})}function lk(e,t,s){return tE(e,t,"backup.tar.gz",{...s.passphrase?{"X-Backup-Passphrase":s.passphrase}:{},...s.confirm?{"X-Backup-Confirm":s.confirm}:{}})}function SL(e,t={}){return xa(`/api${e}`,{method:"PATCH",headers:{"Content-Type":"application/json",[_l]:ga()},body:JSON.stringify(t??{})})}function Qs(e,t={}){return xa(`/api${e}`,{method:"PUT",headers:{"Content-Type":"application/json",[_l]:ga()},body:JSON.stringify(t??{})})}function CL(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 cd="gpt-oss:120b",EL=["approval","question","watcher","reminder","failure","recap","plugin","agent"],Tg=["mon","tue","wed","thu","fri","sat","sun"],He={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=>nr(`/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),Ag("/chat/attachments",t)},transcribe:e=>te("/speech/transcribe",e),say:e=>te("/speech/say",e),discardAttachment:e=>nr(`/artifacts/${encodeURIComponent(e)}`),groups:()=>je("/groups"),group:e=>je(`/groups/${encodeURIComponent(e)}`),createGroup:e=>te("/groups",e),updateGroup:(e,t)=>SL(`/groups/${encodeURIComponent(e)}`,t),deleteGroup:e=>nr(`/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 cj(e){return e.httpStatus===401||e.httpStatus===403||e.state==="authentication-error"||e.state==="access-denied"}const A={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:()=>nr("/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}:{},...vm()}),saveWidgets:(e,t)=>Qs(`/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,...vm()}),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=>nr(`/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=>Qs("/notifications/settings",e),focus:()=>je("/notifications/focus"),lockState:()=>je("/lock"),lockScreen:()=>je("/lock/screen",vm()),lockNow:(e="owner")=>te("/lock",{reason:e}),unlock:e=>te("/lock/unlock",{pin:e}),lockActivity:()=>te("/lock/activity"),setPin:(e,t)=>Qs("/lock/pin",t===void 0?{pin:e}:{pin:e,current:t}),removePin:e=>te("/lock/pin/remove",{current:e}),setLockSettings:e=>Qs("/lock/settings",e),uploadLockBackground:e=>{const t=new FormData;return t.append("file",e),Ag("/lock/background",t)},removeLockBackground:()=>nr("/lock/background"),setFocus:(e,t)=>Qs("/notifications/focus",t?{mode:e,duration:t}:{mode:e}).then(ho),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=>Qs("/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=>nr(`/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(ho),service:()=>je("/service"),serviceAction:e=>te(`/service/${e}`),version:()=>je("/version"),checkVersion:()=>te("/version/check"),setVersionCheck:e=>Qs("/version/check",{enabled:e}),tailscale:()=>je("/tailscale"),setTailscale:e=>Qs("/tailscale",e),apiTokens:()=>je("/api-tokens"),createApiToken:e=>te("/api-tokens",{name:e}),revokeApiToken:e=>nr(`/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)=>lk("/backups/restore",e,t),backupJob:e=>je(`/backups/jobs/${encodeURIComponent(e)}`),backupSchedule:()=>je("/backups/schedule"),setBackupSchedule:e=>Qs("/backups/schedule",e),backupPassphrase:()=>je("/backups/passphrase"),setBackupPassphrase:e=>Qs("/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=>tE("/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)=>lk("/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(ho),undismissJobs:e=>te("/jobs/undismiss",{ids:e}).then(ho),retryJobs:e=>te("/jobs/retry",e).then(ho),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),Ag(`/agents/${encodeURIComponent(e)}/avatar`,s)},removeAgentPicture:e=>nr(`/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 uj(e,t){try{window.sessionStorage.setItem($g,JSON.stringify({agentId:e,text:t}))}catch{}}function AL(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 nE(e){return e==="anthropic"||e==="openai"}function sE(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 TL="Thinking is up to this model. What it writes while thinking is shown apart and kept out of the answer.";var $L=Object.defineProperty,RL=(e,t)=>$L(e,"name",{value:t,configurable:!0}),IL=d.createContext(void 0);function ef(e){const t=d.useContext(IL);return e||t||"ltr"}RL(ef,"useDirection");var PL=Object.defineProperty,dj=(e,t)=>PL(e,"name",{value:t,configurable:!0}),Nu=0,Xs=null;function ML(e){return tf(),e.children}dj(ML,"FocusGuards");function tf(){d.useEffect(()=>{Xs||(Xs={start:Rg(),end:Rg()});const{start:e,end:t}=Xs;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),Nu++,()=>{Nu===1&&(Xs==null||Xs.start.remove(),Xs==null||Xs.end.remove(),Xs=null),Nu=Math.max(0,Nu-1)}},[])}dj(tf,"useFocusGuards");function Rg(){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}dj(Rg,"createFocusGuard");var DL=Object.defineProperty,En=(e,t)=>DL(e,"name",{value:t,configurable:!0}),jm="focusScope.autoFocusOnMount",wm="focusScope.autoFocusOnUnmount",ok={bubbles:!1,cancelable:!0},rE=d.forwardRef(En(function(t,s){const{loop:r=!1,trapped:i=!1,onMountAutoFocus:a,onUnmountAutoFocus:l,...o}=t,[c,u]=d.useState(null),h=Tn(a),f=Tn(l),m=d.useRef(null),p=wt(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:Sr(m.current,{select:!0})},j=function(y){if(g.paused||!c)return;const k=y.relatedTarget;k!==null&&(c.contains(k)||Sr(m.current,{select:!0}))},x=function(y){if(document.activeElement===document.body)for(const N of y)N.removedNodes.length>0&&Sr(c)};En(b,"handleFocusIn"),En(j,"handleFocusOut"),En(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){ck.add(g);const b=document.activeElement;if(!c.contains(b)){const x=new CustomEvent(jm,ok);c.addEventListener(jm,h),c.dispatchEvent(x),x.defaultPrevented||(iE(uE(hj(c)),{select:!0}),document.activeElement===b&&Sr(c))}return()=>{c.removeEventListener(jm,h),setTimeout(()=>{const x=new CustomEvent(wm,ok);c.addEventListener(wm,f),c.dispatchEvent(x),x.defaultPrevented||Sr(b??document.body,{select:!0}),c.removeEventListener(wm,f),ck.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]=aE(w);y&&k?!b.shiftKey&&x===k?(b.preventDefault(),r&&Sr(y,{select:!0})):b.shiftKey&&x===y&&(b.preventDefault(),r&&Sr(k,{select:!0})):x===w&&b.preventDefault()}},[r,i,g.paused]);return n.jsx(gt.div,{tabIndex:-1,...o,ref:p,onKeyDown:v})},"FocusScope"));function iE(e,{select:t=!1}={}){const s=document.activeElement;for(const r of e)if(Sr(r,{select:t}),document.activeElement!==s)return}En(iE,"focusFirst");function aE(e){const t=hj(e),s=Ig(t,e),r=Ig(t.reverse(),e);return[s,r]}En(aE,"getTabbableEdges");function hj(e){const t=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:En(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}En(hj,"getTabbableCandidates");function Ig(e,t){const s=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(s?!r.checkVisibility({checkVisibilityCSS:!0}):lE(r,{upTo:t})))return r}En(Ig,"findVisible");function lE(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}En(lE,"isHidden");function oE(e){return e instanceof HTMLInputElement&&"select"in e}En(oE,"isSelectableInput");function Sr(e,{select:t=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&oE(e)&&t&&e.select()}}En(Sr,"focus");var ck=cE();function cE(){let e=[];return{add(t){const s=e[0];t!==s&&(s==null||s.pause()),e=Pg(e,t),e.unshift(t)},remove(t){var s;e=Pg(e,t),(s=e[0])==null||s.resume()}}}En(cE,"createFocusScopesStack");function Pg(e,t){const s=[...e],r=s.indexOf(t);return r!==-1&&s.splice(r,1),s}En(Pg,"arrayRemove");function uE(e){return e.filter(t=>t.tagName!=="A")}En(uE,"removeLinks");var OL=Object.defineProperty,fj=(e,t)=>OL(e,"name",{value:t,configurable:!0}),ym=!1;function dE(){const[e,t]=d.useState(ym);return d.useEffect(()=>{ym||(ym=!0,t(!0))},[]),e}fj(dE,"useIsHydrated");var hE=Rl[" useSyncExternalStore ".trim().toString()];function fE(){return()=>{}}fj(fE,"subscribe");function mE(){return hE(fE,()=>!0,()=>!1)}fj(mE,"useIsHydratedModern");var LL=typeof hE=="function"?mE:dE,FL=Object.defineProperty,va=(e,t)=>FL(e,"name",{value:t,configurable:!0}),bm="rovingFocusGroup.onEntryFocus",_L={bubbles:!1,cancelable:!0},nf="RovingFocusGroup",[Mg,pE,zL]=zh(nf),[UL,sf]=Hs(nf,[zL]),[BL,WL]=UL(nf),HL=d.forwardRef(va(function(t,s){return n.jsx(Mg.Provider,{scope:t.__scopeRovingFocusGroup,children:n.jsx(Mg.Slot,{scope:t.__scopeRovingFocusGroup,children:n.jsx(KL,{...t,ref:s})})})},"RovingFocusGroup")),KL=d.forwardRef(va(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=wt(s,p),v=ef(l),[b,j]=Ri({prop:o,defaultProp:c??null,onChange:u,caller:nf}),[x,w]=d.useState(!1),y=Tn(h),k=pE(r),N=d.useRef(!1),[S,C]=d.useState(0);return d.useEffect(()=>{const T=p.current;if(T)return T.addEventListener(bm,y),()=>T.removeEventListener(bm,y)},[y]),n.jsx(BL,{scope:r,orientation:i,dir:v,loop:a,currentTabStopId:b,onItemFocus:d.useCallback(T=>j(T),[j]),onItemShiftTab:d.useCallback(()=>w(!0),[]),onFocusableItemAdd:d.useCallback(()=>C(T=>T+1),[]),onFocusableItemRemove:d.useCallback(()=>C(T=>T-1),[]),children:n.jsx(gt.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,T=>{const R=!N.current;if(T.target===T.currentTarget&&R&&!x){const I=new CustomEvent(bm,_L);if(T.currentTarget.dispatchEvent(I),!I.defaultPrevented){const L=k().filter(M=>M.focusable),_=L.find(M=>M.active),$=L.find(M=>M.id===b),O=[_,$,...L].filter(Boolean).map(M=>M.ref.current);mj(O,f)}}N.current=!1}),onBlur:Me(t.onBlur,()=>w(!1))})})},"RovingFocusGroupImpl")),VL="RovingFocusGroupItem",GL=d.forwardRef(va(function(t,s){const{__scopeRovingFocusGroup:r,focusable:i=!0,active:a=!1,tabStopId:l,children:o,...c}=t,u=Fs(),h=l||u,f=WL(VL,r),m=f.currentTabStopId===h,p=pE(r),{onFocusableItemAdd:g,onFocusableItemRemove:v,currentTabStopId:b}=f,j=LL();return Kn(()=>{if(!(!j||!i))return g(),()=>v()},[j,i,g,v]),d.useEffect(()=>{if(!(j||!i))return g(),()=>v()},[j,i,g,v]),n.jsx(Mg.ItemSlot,{scope:r,id:h,focusable:i,active:a,children:n.jsx(gt.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=xE(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?vE(k,N+1):k.slice(N+1)}setTimeout(()=>mj(k))}}),children:typeof o=="function"?o({isCurrentTabStop:m,hasTabStop:b!=null}):o})})},"RovingFocusGroupItem")),YL={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function gE(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}va(gE,"getDirectionAwareKey");function xE(e,t,s){const r=gE(e.key,s);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return YL[r]}va(xE,"getFocusIntent");function mj(e,t=!1){const s=document.activeElement;for(const r of e)if(r===s||(r.focus({preventScroll:t}),document.activeElement!==s))return}va(mj,"focusFirst");function vE(e,t){return e.map((s,r)=>e[(t+r)%e.length])}va(vE,"wrapArray");var jE=HL,wE=GL,qL=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Aa=new WeakMap,Su=new WeakMap,Cu={},km=0,yE=function(e){return e&&(e.host||yE(e.parentNode))},JL=function(e,t){return t.map(function(s){if(e.contains(s))return s;var r=yE(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})},QL=function(e,t,s,r){var i=JL(t,Array.isArray(e)?e:[e]);Cu[s]||(Cu[s]=new WeakMap);var a=Cu[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=(Aa.get(m)||0)+1,b=(a.get(m)||0)+1;Aa.set(m,v),a.set(m,b),l.push(m),v===1&&g&&Su.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(),km++,function(){l.forEach(function(f){var m=Aa.get(f)-1,p=a.get(f)-1;Aa.set(f,m),a.set(f,p),m||(Su.has(f)||f.removeAttribute(r),Su.delete(f)),p||f.removeAttribute(s)}),km--,km||(Aa=new WeakMap,Aa=new WeakMap,Su=new WeakMap,Cu={})}},bE=function(e,t,s){s===void 0&&(s="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),i=qL(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll("[aria-live], script"))),QL(r,i,s,"aria-hidden")):function(){return null}},rr=function(){return rr=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},rr.apply(this,arguments)};function kE(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 XL(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 ud="right-scroll-bar-position",dd="width-before-scroll-bar",ZL="with-scroll-bars-hidden",eF="--removed-body-scroll-bar-size";function Nm(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function tF(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 nF=typeof window<"u"?d.useLayoutEffect:d.useEffect,uk=new WeakMap;function sF(e,t){var s=tF(null,function(r){return e.forEach(function(i){return Nm(i,r)})});return nF(function(){var r=uk.get(s);if(r){var i=new Set(r),a=new Set(e),l=s.current;i.forEach(function(o){a.has(o)||Nm(o,null)}),a.forEach(function(o){i.has(o)||Nm(o,l)})}uk.set(s,e)},[e]),s}function rF(e){return e}function iF(e,t){t===void 0&&(t=rF);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 aF(e){e===void 0&&(e={});var t=iF(null);return t.options=rr({async:!0,ssr:!1},e),t}var NE=function(e){var t=e.sideCar,s=kE(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,rr({},s))};NE.isSideCarExport=!0;function lF(e,t){return e.useMedium(t),NE}var SE=aF(),Sm=function(){},rf=d.forwardRef(function(e,t){var s=d.useRef(null),r=d.useState({onScrollCapture:Sm,onWheelCapture:Sm,onTouchMoveCapture:Sm}),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=kE(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=m,N=sF([s,t]),S=rr(rr({},y),i);return d.createElement(d.Fragment,null,h&&d.createElement(k,{sideCar:SE,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),rr(rr({},S),{ref:N})):d.createElement(x,rr({},S,{className:c,ref:N}),o))});rf.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};rf.classNames={fullWidth:dd,zeroRight:ud};var oF=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function cF(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=oF();return t&&e.setAttribute("nonce",t),e}function uF(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function dF(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var hF=function(){var e=0,t=null;return{add:function(s){e==0&&(t=cF())&&(uF(t,s),dF(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},fF=function(){var e=hF();return function(t,s){d.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&s])}},CE=function(){var e=fF(),t=function(s){var r=s.styles,i=s.dynamic;return e(r,i),null};return t},mF={left:0,top:0,right:0,gap:0},Cm=function(e){return parseInt(e||"",10)||0},pF=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[Cm(s),Cm(r),Cm(i)]},gF=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return mF;var t=pF(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])}},xF=CE(),al="data-scroll-locked",vF=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(ZL,` {
42
- overflow: hidden `).concat(r,`;
43
- padding-right: `).concat(o,"px ").concat(r,`;
44
- }
45
- body[`).concat(al,`] {
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(ud,` {
59
- right: `).concat(o,"px ").concat(r,`;
60
- }
61
-
62
- .`).concat(dd,` {
63
- margin-right: `).concat(o,"px ").concat(r,`;
64
- }
65
-
66
- .`).concat(ud," .").concat(ud,` {
67
- right: 0 `).concat(r,`;
68
- }
69
-
70
- .`).concat(dd," .").concat(dd,` {
71
- margin-right: 0 `).concat(r,`;
72
- }
73
-
74
- body[`).concat(al,`] {
75
- `).concat(eF,": ").concat(o,`px;
76
- }
77
- `)},dk=function(){var e=parseInt(document.body.getAttribute(al)||"0",10);return isFinite(e)?e:0},jF=function(){d.useEffect(function(){return document.body.setAttribute(al,(dk()+1).toString()),function(){var e=dk()-1;e<=0?document.body.removeAttribute(al):document.body.setAttribute(al,e.toString())}},[])},wF=function(e){var t=e.noRelative,s=e.noImportant,r=e.gapMode,i=r===void 0?"margin":r;jF();var a=d.useMemo(function(){return gF(i)},[i]);return d.createElement(xF,{styles:vF(a,!t,i,s?"":"!important")})},Dg=!1;if(typeof window<"u")try{var Eu=Object.defineProperty({},"passive",{get:function(){return Dg=!0,!0}});window.addEventListener("test",Eu,Eu),window.removeEventListener("test",Eu,Eu)}catch{Dg=!1}var Ta=Dg?{passive:!1}:!1,yF=function(e){return e.tagName==="TEXTAREA"},EE=function(e,t){if(!(e instanceof Element))return!1;var s=window.getComputedStyle(e);return s[t]!=="hidden"&&!(s.overflowY===s.overflowX&&!yF(e)&&s[t]==="visible")},bF=function(e){return EE(e,"overflowY")},kF=function(e){return EE(e,"overflowX")},hk=function(e,t){var s=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var i=AE(e,r);if(i){var a=TE(e,r),l=a[1],o=a[2];if(l>o)return!0}r=r.parentNode}while(r&&r!==s.body);return!1},NF=function(e){var t=e.scrollTop,s=e.scrollHeight,r=e.clientHeight;return[t,s,r]},SF=function(e){var t=e.scrollLeft,s=e.scrollWidth,r=e.clientWidth;return[t,s,r]},AE=function(e,t){return e==="v"?bF(t):kF(t)},TE=function(e,t){return e==="v"?NF(t):SF(t)},CF=function(e,t){return e==="h"&&t==="rtl"?-1:1},EF=function(e,t,s,r,i){var a=CF(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=TE(e,o),g=p[0],v=p[1],b=p[2],j=v-b-a*g;(g||j)&&AE(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},Au=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},fk=function(e){return[e.deltaX,e.deltaY]},mk=function(e){return e&&"current"in e?e.current:e},AF=function(e,t){return e[0]===t[0]&&e[1]===t[1]},TF=function(e){return`
78
- .block-interactivity-`.concat(e,` {pointer-events: none;}
79
- .allow-interactivity-`).concat(e,` {pointer-events: all;}
80
- `)},$F=0,$a=[];function RF(e){var t=d.useRef([]),s=d.useRef([0,0]),r=d.useRef(),i=d.useState($F++)[0],a=d.useState(CE)[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=XL([e.lockRef.current],(e.shards||[]).map(mk),!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=Au(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(),T=C&&C.anchorNode,R=T?T===N||T.contains(N):!1;if(R)return!1;var I=hk(S,N);if(!I)return!0;if(I?k=S:(k=S==="v"?"h":"v",I=hk(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 EF(L,b,v,L==="h"?w:y)},[]),c=d.useCallback(function(v){var b=v;if(!(!$a.length||$a[$a.length-1]!==a)){var j="deltaY"in b?fk(b):Au(b),x=t.current.filter(function(k){return k.name===b.type&&(k.target===b.target||b.target===k.shadowParent)&&AF(k.delta,j)})[0];if(x&&x.should){b.cancelable&&b.preventDefault();return}if(!x){var w=(l.current.shards||[]).map(mk).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:IF(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=Au(v),r.current=void 0},[]),f=d.useCallback(function(v){u(v.type,fk(v),v.target,o(v,e.lockRef.current))},[]),m=d.useCallback(function(v){u(v.type,Au(v),v.target,o(v,e.lockRef.current))},[]);d.useEffect(function(){return $a.push(a),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:m}),document.addEventListener("wheel",c,Ta),document.addEventListener("touchmove",c,Ta),document.addEventListener("touchstart",h,Ta),function(){$a=$a.filter(function(v){return v!==a}),document.removeEventListener("wheel",c,Ta),document.removeEventListener("touchmove",c,Ta),document.removeEventListener("touchstart",h,Ta)}},[]);var p=e.removeScrollBar,g=e.inert;return d.createElement(d.Fragment,null,g?d.createElement(a,{styles:TF(i)}):null,p?d.createElement(wF,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function IF(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const PF=lF(SE,RF);var pj=d.forwardRef(function(e,t){return d.createElement(rf,rr({},e,{ref:t,sideCar:PF}))});pj.classNames=rf.classNames;var MF=Object.defineProperty,ot=(e,t)=>MF(e,"name",{value:t,configurable:!0}),Og=["Enter"," "],DF=["ArrowDown","PageUp","Home"],$E=["ArrowUp","PageDown","End"],OF=[...DF,...$E],LF={ltr:[...Og,"ArrowRight"],rtl:[...Og,"ArrowLeft"]},FF={ltr:["ArrowLeft"],rtl:["ArrowRight"]},af="Menu",[pc,_F,zF]=zh(af),[ja,RE]=Hs(af,[zF,Qh,sf]),lf=Qh(),IE=sf(),[PE,Pi]=ja(af),[UF,Fc]=ja(af),BF=ot(e=>{const{__scopeMenu:t,open:s=!1,children:r,dir:i,onOpenChange:a,modal:l=!0}=e,o=lf(t),[c,u]=d.useState(null),h=d.useRef(!1),f=Tn(a),m=ef(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(tj,{...o,children:n.jsx(PE,{scope:t,open:s,onOpenChange:f,content:c,onContentChange:u,children:n.jsx(UF,{scope:t,onClose:d.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:h,dir:m,modal:l,children:r})})})},"Menu"),ME=d.forwardRef(ot(function(t,s){const{__scopeMenu:r,...i}=t,a=lf(r);return n.jsx(B1,{...a,...i,ref:s})},"MenuAnchor")),DE="MenuPortal",[WF,OE]=ja(DE,{forceMount:void 0}),HF=ot(e=>{const{__scopeMenu:t,forceMount:s,children:r,container:i}=e,a=Pi(DE,t);return n.jsx(WF,{scope:t,forceMount:s,children:n.jsx(xr,{present:s||a.open,children:n.jsx(Wh,{asChild:!0,container:i,children:r})})})},"MenuPortal"),_s="MenuContent",[KF,gj]=ja(_s),VF=d.forwardRef(ot(function(t,s){const r=OE(_s,t.__scopeMenu),{forceMount:i=r.forceMount,...a}=t,l=Pi(_s,t.__scopeMenu),o=Fc(_s,t.__scopeMenu);return n.jsx(pc.Provider,{scope:t.__scopeMenu,children:n.jsx(xr,{present:i||l.open,children:n.jsx(pc.Slot,{scope:t.__scopeMenu,children:o.modal?n.jsx(GF,{...a,ref:s}):n.jsx(YF,{...a,ref:s})})})})},"MenuContent")),GF=d.forwardRef(ot(function(t,s){const r=Pi(_s,t.__scopeMenu),i=d.useRef(null),a=wt(s,i);return d.useEffect(()=>{const l=i.current;if(l)return bE(l)},[]),n.jsx(xj,{...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")),YF=d.forwardRef(ot(function(t,s){const r=Pi(_s,t.__scopeMenu);return n.jsx(xj,{...t,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentNonModal")),qF=yi("MenuContent.ScrollLock"),xj=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=Pi(_s,r),x=Fc(_s,r),w=lf(r),y=IE(r),k=_F(r),[N,S]=d.useState(null),C=d.useRef(null),T=wt(s,C,j.onContentChange),R=d.useRef(0),I=d.useRef(""),L=d.useRef(0),_=d.useRef(null),$=d.useRef("right"),P=d.useRef(0),O=v?pj:d.Fragment,M=v?{as:qF,allowPinchZoom:!0}:void 0,D=ot(B=>{var fe,Oe;const q=I.current+B,W=k().filter(Ie=>!Ie.disabled),Y=document.activeElement,F=(fe=W.find(Ie=>Ie.ref.current===Y))==null?void 0:fe.textValue,X=W.map(Ie=>Ie.textValue),Q=VE(X,q,F),ee=(Oe=W.find(Ie=>Ie.textValue===Q))==null?void 0:Oe.ref.current;ot(function Ie(Fe){I.current=Fe,window.clearTimeout(R.current),Fe!==""&&(R.current=window.setTimeout(()=>Ie(""),1e3))},"updateSearch")(q),ee&&setTimeout(()=>ee.focus())},"handleTypeaheadSearch");d.useEffect(()=>()=>window.clearTimeout(R.current),[]),tf();const H=d.useCallback(B=>{var W,Y;return $.current===((W=_.current)==null?void 0:W.side)&&YE(B,(Y=_.current)==null?void 0:Y.area)},[]);return n.jsx(KF,{scope:r,searchRef:I,onItemEnter:d.useCallback(B=>{H(B)&&B.preventDefault()},[H]),onItemLeave:d.useCallback(B=>{var q;H(B)||((q=C.current)==null||q.focus(),S(null))},[H]),onTriggerLeave:d.useCallback(B=>{H(B)&&B.preventDefault()},[H]),pointerGraceTimerRef:L,onPointerGraceIntentChange:d.useCallback(B=>{_.current=B},[]),children:n.jsx(O,{...M,children:n.jsx(rE,{asChild:!0,trapped:a,onMountAutoFocus:Me(l,B=>{var q;B.preventDefault(),(q=C.current)==null||q.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:n.jsx(Bh,{asChild:!0,disableOutsidePointerEvents:c,onEscapeKeyDown:h,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:p,onDismiss:g,children:n.jsx(jE,{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(W1,{role:"menu","aria-orientation":"vertical","data-state":vj(j.open),"data-radix-menu-content":"",dir:x.dir,...w,...b,ref:T,style:{outline:"none",...b.style},onKeyDown:Me(b.onKeyDown,B=>{const W=B.target.closest("[data-radix-menu-content]")===B.currentTarget,Y=B.ctrlKey||B.altKey||B.metaKey,F=B.key.length===1;W&&(B.key==="Tab"&&B.preventDefault(),!Y&&F&&D(B.key));const X=C.current;if(B.target!==X||!OF.includes(B.key))return;B.preventDefault();const ee=k().filter(fe=>!fe.disabled).map(fe=>fe.ref.current);$E.includes(B.key)&&ee.reverse(),HE(ee)}),onBlur:Me(t.onBlur,B=>{B.currentTarget.contains(B.target)||(window.clearTimeout(R.current),I.current="")}),onPointerMove:Me(t.onPointerMove,vl(B=>{const q=B.target,W=P.current!==B.clientX;if(B.currentTarget.contains(q)&&W){const Y=B.clientX>P.current?"right":"left";$.current=Y,P.current=B.clientX}}))})})})})})})},"MenuContentImpl")),LE=d.forwardRef(ot(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(gt.div,{role:"group",...i,ref:s})},"MenuGroup")),JF=d.forwardRef(ot(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(gt.div,{...i,ref:s})},"MenuLabel")),Lg="MenuItem",pk="menu.itemSelect",FE=d.forwardRef(ot(function(t,s){const{disabled:r=!1,onSelect:i,...a}=t,l=d.useRef(null),o=Fc(Lg,t.__scopeMenu),c=gj(Lg,t.__scopeMenu),u=wt(s,l),h=d.useRef(!1),f=ot(()=>{const m=l.current;if(!r&&m){const p=new CustomEvent(pk,{bubbles:!0,cancelable:!0});m.addEventListener(pk,g=>i==null?void 0:i(g),{once:!0}),Uh(m,p),p.defaultPrevented?h.current=!1:o.onClose()}},"handleSelect");return n.jsx(_E,{...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===" "||Og.includes(m.key)&&(m.currentTarget.click(),m.preventDefault())})})},"MenuItem")),_E=d.forwardRef(ot(function(t,s){const{__scopeMenu:r,disabled:i=!1,textValue:a,...l}=t,o=gj(Lg,r),c=IE(r),u=d.useRef(null),h=wt(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(pc.ItemSlot,{scope:r,disabled:i,textValue:a??p,children:n.jsx(wE,{asChild:!0,...c,focusable:!i,children:n.jsx(gt.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,vl(v=>{i?o.onItemLeave(v):(o.onItemEnter(v),v.defaultPrevented||v.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Me(t.onPointerLeave,vl(v=>o.onItemLeave(v))),onFocus:Me(t.onFocus,()=>m(!0)),onBlur:Me(t.onBlur,()=>m(!1))})})})},"MenuItemImpl")),QF="MenuRadioGroup",[XF,ZF]=ja(QF,{value:void 0,onValueChange:ot(()=>{},"onValueChange")}),e_=d.forwardRef(ot(function(t,s){const{value:r,onValueChange:i,...a}=t,l=Tn(i);return n.jsx(XF,{scope:t.__scopeMenu,value:r,onValueChange:l,children:n.jsx(LE,{...a,ref:s})})},"MenuRadioGroup")),t_="MenuRadioItem",n_=d.forwardRef(ot(function(t,s){const{value:r,...i}=t,a=ZF(t_,t.__scopeMenu),l=r===a.value;return n.jsx(r_,{scope:t.__scopeMenu,checked:l,children:n.jsx(FE,{role:"menuitemradio","aria-checked":l,...i,ref:s,"data-state":WE(l),onSelect:Me(i.onSelect,()=>{var o;return(o=a.onValueChange)==null?void 0:o.call(a,r)},{checkForDefaultPrevented:!1})})})},"MenuRadioItem")),s_="MenuItemIndicator",[r_,YX]=ja(s_,{checked:!1}),i_=d.forwardRef(ot(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(gt.div,{role:"separator","aria-orientation":"horizontal",...i,ref:s})},"MenuSeparator")),zE="MenuSub",[a_,UE]=ja(zE),l_=ot(e=>{const{__scopeMenu:t,children:s,open:r=!1,onOpenChange:i}=e,a=Pi(zE,t),l=lf(t),[o,c]=d.useState(null),[u,h]=d.useState(null),f=Tn(i);return d.useEffect(()=>(a.open===!1&&f(!1),()=>f(!1)),[a.open,f]),n.jsx(tj,{...l,children:n.jsx(PE,{scope:t,open:r,onOpenChange:f,content:u,onContentChange:h,children:n.jsx(a_,{scope:t,contentId:Fs(),triggerId:Fs(),trigger:o,onTriggerChange:c,children:s})})})},"MenuSub"),Tu="MenuSubTrigger",o_=d.forwardRef(ot(function(t,s){const r=Pi(Tu,t.__scopeMenu),i=Fc(Tu,t.__scopeMenu),a=UE(Tu,t.__scopeMenu),l=gj(Tu,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=wt(s,a.onTriggerChange);return n.jsx(ME,{asChild:!0,...h,children:n.jsx(_E,{id:a.triggerId,"aria-haspopup":"menu","aria-expanded":r.open,"aria-controls":r.open?a.contentId:void 0,"data-state":vj(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,vl(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,vl(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===" "||LF[i.dir].includes(p.key)&&(r.onOpenChange(!0),(v=r.content)==null||v.focus(),p.preventDefault())})})})},"MenuSubTrigger")),c_="MenuSubContent",u_=d.forwardRef(ot(function(t,s){const r=OE(_s,t.__scopeMenu),{forceMount:i=r.forceMount,align:a="start",...l}=t,o=Pi(_s,t.__scopeMenu),c=Fc(_s,t.__scopeMenu),u=UE(c_,t.__scopeMenu),h=d.useRef(null),f=wt(s,h);return n.jsx(pc.Provider,{scope:t.__scopeMenu,children:n.jsx(xr,{present:i||o.open,children:n.jsx(pc.Slot,{scope:t.__scopeMenu,children:n.jsx(xj,{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=FF[c.dir].includes(m.key);p&&g&&(o.onOpenChange(!1),(v=u.trigger)==null||v.focus(),m.preventDefault())})})})})})},"MenuSubContent"));function vj(e){return e?"open":"closed"}ot(vj,"getOpenState");function BE(e){return e==="indeterminate"}ot(BE,"isIndeterminate");function WE(e){return BE(e)?"indeterminate":e?"checked":"unchecked"}ot(WE,"getCheckedState");function HE(e){const t=document.activeElement;for(const s of e)if(s===t||(s.focus(),document.activeElement!==t))return}ot(HE,"focusFirst");function KE(e,t){return e.map((s,r)=>e[(t+r)%e.length])}ot(KE,"wrapArray");function VE(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=KE(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(VE,"getNextMatch");function GE(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(GE,"isPointInPolygon");function YE(e,t){if(!t)return!1;const s={x:e.clientX,y:e.clientY};return GE(s,t)}ot(YE,"isPointerInGraceArea");function vl(e){return t=>t.pointerType==="mouse"?e(t):void 0}ot(vl,"whenMouse");var d_=BF,h_=ME,f_=HF,m_=VF,p_=LE,g_=JF,x_=FE,v_=e_,j_=n_,w_=i_,y_=l_,b_=o_,k_=u_,N_=Object.defineProperty,os=(e,t)=>N_(e,"name",{value:t,configurable:!0}),jj="DropdownMenu",[S_,qX]=Hs(jj,[RE]),cs=RE(),[C_,qE]=S_(jj),E_=os(e=>{const{__scopeDropdownMenu:t,children:s,dir:r,open:i,defaultOpen:a,onOpenChange:l,modal:o=!0}=e,c=cs(t),u=d.useRef(null),[h,f]=Ri({prop:i,defaultProp:a??!1,onChange:l,caller:jj});return n.jsx(C_,{scope:t,triggerId:Fs(),triggerRef:u,contentId:Fs(),open:h,onOpenChange:f,onOpenToggle:d.useCallback(()=>f(m=>!m),[f]),modal:o,children:n.jsx(d_,{...c,open:h,onOpenChange:f,dir:r,modal:o,children:s})})},"DropdownMenu"),A_="DropdownMenuTrigger",T_=d.forwardRef(os(function(t,s){const{__scopeDropdownMenu:r,disabled:i=!1,...a}=t,l=qE(A_,r),o=cs(r),c=wt(s,l.triggerRef);return n.jsx(h_,{asChild:!0,...o,children:n.jsx(gt.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")),$_=os(e=>{const{__scopeDropdownMenu:t,...s}=e,r=cs(t);return n.jsx(f_,{...r,...s})},"DropdownMenuPortal"),R_="DropdownMenuContent",I_=d.forwardRef(os(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=qE(R_,r),l=cs(r),o=d.useRef(!1);return n.jsx(m_,{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")),P_=d.forwardRef(os(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=cs(r);return n.jsx(p_,{...a,...i,ref:s})},"DropdownMenuGroup")),M_=d.forwardRef(os(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=cs(r);return n.jsx(g_,{...a,...i,ref:s})},"DropdownMenuLabel")),D_=d.forwardRef(os(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=cs(r);return n.jsx(x_,{...a,...i,ref:s})},"DropdownMenuItem")),O_=d.forwardRef(os(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=cs(r);return n.jsx(v_,{...a,...i,ref:s})},"DropdownMenuRadioGroup")),L_=d.forwardRef(os(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=cs(r);return n.jsx(j_,{...a,...i,ref:s})},"DropdownMenuRadioItem")),F_=d.forwardRef(os(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=cs(r);return n.jsx(w_,{...a,...i,ref:s})},"DropdownMenuSeparator")),__=os(e=>{const{__scopeDropdownMenu:t,children:s,open:r,onOpenChange:i,defaultOpen:a}=e,l=cs(t),[o,c]=Ri({prop:r,defaultProp:a??!1,onChange:i,caller:"DropdownMenuSub"});return n.jsx(y_,{...l,open:o,onOpenChange:c,children:s})},"DropdownMenuSub"),z_=d.forwardRef(os(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=cs(r);return n.jsx(b_,{...a,...i,ref:s})},"DropdownMenuSubTrigger")),U_=d.forwardRef(os(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=cs(r);return n.jsx(k_,{...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")),_c=E_,zc=T_,zl=$_,Uc=I_,JE=P_,da=M_,vs=D_,B_=O_,W_=L_,Ir=F_,H_=__,K_=z_,V_=U_,G_=Object.defineProperty,Ul=(e,t)=>G_(e,"name",{value:t,configurable:!0}),wj="Tabs",[Y_,JX]=Hs(wj,[sf]),QE=sf(),[q_,yj]=Y_(wj),J_=d.forwardRef(Ul(function(t,s){const{__scopeTabs:r,value:i,onValueChange:a,defaultValue:l,orientation:o="horizontal",dir:c,activationMode:u="automatic",...h}=t,f=ef(c),[m,p]=Ri({prop:i,onChange:a,defaultProp:l??"",caller:wj});return n.jsx(q_,{scope:r,baseId:Fs(),value:m,onValueChange:p,orientation:o,dir:f,activationMode:u,children:n.jsx(gt.div,{dir:f,"data-orientation":o,...h,ref:s})})},"Tabs")),Q_="TabsList",X_=d.forwardRef(Ul(function(t,s){const{__scopeTabs:r,loop:i=!0,...a}=t,l=yj(Q_,r),o=QE(r);return n.jsx(jE,{asChild:!0,...o,orientation:l.orientation,dir:l.dir,loop:i,children:n.jsx(gt.div,{role:"tablist","aria-orientation":l.orientation,...a,ref:s})})},"TabsList")),Z_="TabsTrigger",e4=d.forwardRef(Ul(function(t,s){const{__scopeTabs:r,value:i,disabled:a=!1,...l}=t,o=yj(Z_,r),c=QE(r),u=bj(o.baseId,i),h=kj(o.baseId,i),f=i===o.value;return n.jsx(wE,{asChild:!0,...c,focusable:!a,active:f,children:n.jsx(gt.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")),t4="TabsContent",n4=d.forwardRef(Ul(function(t,s){const{__scopeTabs:r,value:i,forceMount:a,children:l,...o}=t,c=yj(t4,r),u=bj(c.baseId,i),h=kj(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(xr,{present:a||f,children:({present:p})=>n.jsx(gt.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 bj(e,t){return`${e}-trigger-${t}`}Ul(bj,"makeTriggerId");function kj(e,t){return`${e}-content-${t}`}Ul(kj,"makeContentId");var s4=J_,r4=X_,i4=e4,a4=n4;function tn(e,t,s){if(e==null)return"—";switch(t){case"currency":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?l4(r,s):String(e)}case"percent":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?`${gk(r)}%`:String(e)}case"number":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?Number.isInteger(r)?Xt(r):gk(r):String(e)}case"date":return o4(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 l4(e,t){if(!(Math.abs(e)<1e3&&!Number.isInteger(e)))return yL(e,t);try{return new Intl.NumberFormat("en-US",{style:"currency",currency:t??"USD",maximumFractionDigits:2}).format(e)}catch{return e.toFixed(2)}}function o4(e){const t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);return t?Lc(t[0],{year:!0,compact:!0}):e}function Fg(e){const t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);return t?Lc(t[0],{compact:!0}):e}function gk(e){return String(Math.round(e*100)/100)}function Qd(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 c4({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:tn(a.value,e.unit,e.currency)})]},a.category)})})}const u4=/^(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 )/,d4=/^(… |\.\.\. |\(no change\)$|\)/;function h4(e){return e.replace(/\n$/,"").split(`
81
- `).map(s=>({kind:f4(s),text:s}))}function f4(e){return e.startsWith("@@")?"hunk":u4.test(e)||d4.test(e)?"meta":e.startsWith("+")?"add":e.startsWith("-")?"del":"context"}function m4({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 Xd({text:e,limit:t,more:s,label:r="Diff",marks:i}){const a=h4(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(m4,{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 p4({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:tn(t.value,t.unit,null)})]},t.label))}):null,e.diff?n.jsx(Xd,{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 un="#/",jl="#/needs",xi="#/chat",ft="#/agents",jt="#/activity",an="#/settings",Kr="#/files",g4="#/welcome";function hd(e){const t=/^#\/welcome(?:\?(.*))?$/.exec(e);if(!t)return null;try{return{step:new URLSearchParams(t[1]??"").get("step")}}catch{return{step:null}}}function $u(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`${Kr}${e?`/${encodeURIComponent(e)}`:""}${r?`?${r}`:""}`}function x4(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 v4(e){if(XE(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 Vi(e,t){return`#/chat/g/${encodeURIComponent(e)}${t?`/${encodeURIComponent(t)}`:""}`}function XE(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 St(e,t,s){return`${ft}/${encodeURIComponent(e)}${t?`/${t}${s?`/${s}`:""}`:""}`}function j4(e){const t=/^#\/agents\/([^/]+)(?:\/([a-z-]+)(?:\/([a-z-]+))?)?$/.exec(e);if(!t||t[1]===ZE)return null;try{return{agentId:decodeURIComponent(t[1]),...t[2]?{tab:t[2]}:{},...t[3]?{section:t[3]}:{}}}catch{return null}}const ZE="catalogue",xk=`${ft}/${ZE}`;function Ht(e){return e?`${xk}/${encodeURIComponent(e)}`:xk}function w4(e){return`${Ht(e)}?add=1`}function y4(e,t){const s=/^#\/agents\/catalogue\/([a-z0-9-]+)\?(?:.*&)?add=1(?:&|$)/.exec(e);return(s==null?void 0:s[1])===t}function b4(e){const t=/^#\/agents\/catalogue(?:\/([a-z0-9-]+))?(?:\?.*)?$/.exec(e);return t?t[1]?{name:t[1]}:{}:null}function gc(e){return`${jt}/conversations/${encodeURIComponent(e)}`}const k4="#/p";function fr(e,t,s){const r=`${k4}/${encodeURIComponent(e)}/${encodeURIComponent(t)}`;return s?`${r}/${encodeURIComponent(s)}`:r}function Nj(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 N4="p.";function Vr(e,t,s){const r=s?new URLSearchParams(s).toString():"";return`${an}/${encodeURIComponent(tA(e,t))}${r?`?${r}`:""}`}function eA(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 S4(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 tA(e,t){return`${N4}${e}${t===e?"":`.${t}`}`}function Pe(e){return e?`${an}/${e}`:an}function nA(e){return`${Pe("accounts")}?account=${encodeURIComponent(e)}`}function C4(e){const t=/^#\/settings\/accounts\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1]).get("account")||null}catch{return null}}function Sj(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 sA(e){return`${Pe("connections")}?connection=${encodeURIComponent(e)}`}function E4(e){return Sj(e,"connections","connection")}function A4(e){return Sj(e,"secrets","secret")}const vk=`${Pe("secrets")}?add=1`;function T4(e){return Sj(e,"secrets","add")==="1"}function $4(e){return`${Pe("plugins")}?install=${encodeURIComponent(e)}`}const R4=`${Pe("plugins")}?tab=browse`;function I4(e){return`${Pe("proposals")}${e?`?plugin=${encodeURIComponent(e)}`:""}`}function P4(e){const t=/^#\/settings\/proposals\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1]).get("plugin")||null}catch{return null}}function Cj(e){const t=/^#\/settings\/plugins\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1])}catch{return null}}function M4(e){var s,r;const t=(r=(s=Cj(e))==null?void 0:s.get("install"))==null?void 0:r.trim();return t||null}function jk(e){var s;const t=(s=Cj(e))==null?void 0:s.get("kind");return t==="plugins"||t==="agents"?t:"all"}function wk(e){const t=Cj(e);return t!=null&&t.get("install")?"installed":(t==null?void 0:t.get("tab"))==="browse"?"browse":"installed"}const D4=[{route:un,label:"Home"},{route:xi,label:"Chat"},{route:ft,label:"Agents"},{route:jt,label:"Activity"},{route:Kr,label:"Files"},{route:an,label:"Settings"}],O4=[{id:"you",label:"You"},{id:"access",label:"Models and access"},{id:"running",label:"Running"},{id:"plugins",label:"Plugins"}],L4=[{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 F4(e){var t;return((t=/^#\/settings\/([a-z0-9.-]+)/.exec(e))==null?void 0:t[1])??"you"}const _g="#/settings/notifications/recent",zg=Pe("backup");function _4(e){const t=/^#\/conversations\/(.+)$/.exec(e);if(t)return gc(decodeURIComponent(t[1]));const s=/^#\/email(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(s)try{return fr("email","mail",s[1]?decodeURIComponent(s[1]):null)}catch{return fr("email","mail")}return e==="#/settings/email"?Vr("email","settings"):{"#/overview":un,"#/approvals":un,"#/events":`${jt}/events`,"#/jobs":`${jt}/jobs`,"#/conversations":jt,"#/missions":`${ft}?tab=missions`,"#/offers":`${ft}?tab=offers`,"#/reminders":`${ft}?tab=reminders`,"#/providers":Pe("accounts"),"#/browser":Pe("computer"),"#/sentinels":Pe("watchers"),"#/settings/sentinels":Pe("watchers")}[e]??null}function rA(e){if(e===""||e==="#"||e===un)return un;if(e.startsWith(xi))return xi;if(e.startsWith(ft))return ft;if(e.startsWith(jt))return jt;if(e.startsWith(Kr))return Kr;if(e.startsWith(an))return an;const t=Nj(e);return t?fr(t.plugin,t.page):un}const z4="#/chat?group=new";function U4(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 Bc="front-desk",Ej=[{id:Bc,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."}],iA=new Set(Ej.map(e=>e.id)),yk=e=>iA.has(e);function bk(e,t){const s=t.filter(r=>!iA.has(r));return[...Ej.filter(r=>e.has(r.id)).map(r=>r.id),...s.filter((r,i)=>s.indexOf(r)===i)]}function B4(e,t){return e.find(s=>(s.roles??[]).includes(t))}const kk=["coding","finance","mail","research","calendar","files","memory"],W4={developer:"coding",coding:"coding",finance:"finance",credit:"finance",mail:"mail",email:"mail",research:"research",calendar:"calendar",files:"files",memory:"memory",[Bc]:"buddi"},H4=[["mail",["email"]],["finance",["finance"]],["coding",["developer"]],["research",["web","browser"]],["art",["image"]]];function K4(e){const t=new Set(e.map(s=>s.split(".")[0]??s));for(const[s,r]of H4)if(r.some(i=>t.has(i)))return s;return t.size>0&&[...t].every(s=>s==="memory")?"memory":null}let Ug=null;function V4(e){Ug=e}function Wc(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=W4[s];if(r)return{key:r}}const t=K4(e.tools??[]);return t?{key:t}:Ug!==null&&e.id===Ug?{key:"buddi"}:{key:kk[G4(e.id)%kk.length]??"coding"}}function Hc(e){return e.key==="own"?{"data-agent":"own",style:{"--agent-fill":e.hex}}:{"data-agent":e.key}}function G4(e){let t=0;for(const s of e)t=(t*31+s.charCodeAt(0))%997;return t}const Y4=["run.started","tool.called","tool.result","message.appended","awaiting-approval","run.finished","reaction","live","live.settle","live.snapshot","attention","closing","ping"];function q4(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:Y4.includes(o)?o:"ping",data:J4(c.join(`
86
- `))})}return{events:i,rest:r}}function J4(e){if(e==="")return{};try{const t=JSON.parse(e);return t!==null&&typeof t=="object"?t:{value:t}}catch{return{value:e}}}function of(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}=q4(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 Aj="0.1.0+3bee568";function Tj(e,t=Aj){return typeof e=="string"&&e!==""&&typeof t=="string"&&t!==""&&e!==t}function Q4(){var e;try{if((e=window.matchMedia)!=null&&e.call(window,"(display-mode: standalone)").matches)return!0}catch{}return window.navigator.standalone===!0}const X4=5*6e4,Z4=6e4,ez=5e3,xc="buddi:stream-reconnected",aA="buddi.autoReloadedFor";function tz(){window.dispatchEvent(new Event(xc))}const Nk=["keydown","pointerdown","pointermove","wheel","touchstart","input"];let $j=Date.now(),Ru=0;const Sk=()=>{$j=Date.now()};function nz(){if(Ru===0){$j=Date.now();for(const e of Nk)window.addEventListener(e,Sk,{capture:!0,passive:!0})}return Ru+=1,()=>{if(Ru-=1,Ru===0)for(const e of Nk)window.removeEventListener(e,Sk,{capture:!0})}}function sz(e=Date.now()){return e-$j}function lA(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 rz(e){return e.hidden?!0:e.idleMs>=Z4&&!e.busy}function iz(e){try{return window.sessionStorage.getItem(aA)===e}catch{return!1}}function az(e){try{window.sessionStorage.setItem(aA,e)}catch{}}function lz(e){const t=d.useRef(e);t.current=e,d.useEffect(()=>{const s=()=>t.current();return window.addEventListener(xc,s),()=>window.removeEventListener(xc,s)},[])}function oz(e,t=()=>window.location.reload(),s=Aj){const r=Tj(e,s),i=d.useRef(t);i.current=t,d.useEffect(()=>nz(),[]),d.useEffect(()=>{if(!r||e===void 0||iz(e))return;let a=!1;const l=()=>{if(a)return;const c=document.visibilityState==="hidden";rz({hidden:c,idleMs:sz(),busy:lA()})&&(a=!0,az(e),i.current())};l();const o=window.setInterval(l,ez);return document.addEventListener("visibilitychange",l),()=>{window.clearInterval(o),document.removeEventListener("visibilitychange",l)}},[r,e])}const cz=9e4,oA=5*6e4,uz=500,dz=2e3,hz=3e3,fz="/_buddi/ready",ll={reload:()=>window.location.reload(),now:()=>Date.now()};let Ni=null,qa=null,No=null;const Bg=new Set;function Zd(e){Ni=e;for(const t of Bg)t()}function Ck(){return Ni}function mz(e){return Bg.add(e),()=>Bg.delete(e)}function pz(){const e=new Uint8Array(32);return crypto.getRandomValues(e),[...e].map(t=>t.toString(16).padStart(2,"0")).join("")}async function Rj(e=hz){const t=new AbortController,s=setTimeout(()=>t.abort(),e);try{const r=await fetch(`${fz}?challenge=${pz()}`,{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 gz(){const e=await Rj();e&&(qa=e)}function xz(){let e=qa,t=!1,s=!1,r=uz,i;const a=async()=>{if(t)return;const l=await Rj();if(!t){if(l===null)s=!0;else if(e!==null?l!==e:s){t=!0,ll.reload();return}else e===null&&l!==""&&(e=l);r=Math.min(Math.round(r*1.5),dz),i=setTimeout(()=>void a(),r)}};return i=setTimeout(()=>void a(),r),()=>{t=!0,clearTimeout(i)}}function cf(e){if(Ni){if(e.kind==="detected")return;Zd({...Ni,...e});return}Zd({...e,startedAt:ll.now()}),No=xz()}function cA(e){Ni&&Zd({...Ni,...e})}function wl(){No==null||No(),No=null,Zd(null)}async function uf(e,t){cf(e);try{return await t()}catch(s){if(Jd(s))return;throw wl(),s}}function vz(e){cf({kind:e.for==="stop"?"stop":"detected"})}async function Ek(){if(Ni)return;const e=await Rj();if(qa===null){e&&(qa=e);return}if(!(!e||e===qa||Ni)){if(lA()){qa=e;return}cf({kind:"detected"})}}function jz(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 wz="/api/chat/attention/stream";function uA(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 dA(e,t){const s=uA(e,t);return[...s.top,...s.middle,...s.bottom]}function df(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 yz(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 bz(e,t){return e&&(e.approvals>0||e.question)?"needs":t?"working":null}function kz(e){return new Map(((e==null?void 0:e.agents)??[]).map(t=>[t.agentId,t]))}function Nz(){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=of({url:wz,onEvent:a=>a.name==="closing"?vz(a.data):r(),onReconnect:tz});return()=>{s=!0,i.close()}},[]),kz(e)}const Kc="maker";function Ij(e){return e.filter(t=>t.available&&!t.roles.includes(Kc))}function hA(e){return Ij(e).length>=2}function Sz(e){var t;return((t=e.find(s=>s.roles.includes(Kc)))==null?void 0:t.name)??"the agent maker"}const Cz="{{default}}";function Ez(e,t){return e.split(Cz).join(t??"your assistant")}function Az(e,t){return((e==null?void 0:e.starters)??[]).slice(0,3).map(s=>Ez(s,t))}function Tz(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 $z(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 fA(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 Rz="Settings → Model accounts",Iz="Install it in Settings → Plugins";function Wg(e){return e!=null&&e.heldBack?{section:"plugins",label:Iz}:{section:"accounts",label:Rz}}const Pz={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"})]})],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]=Pz[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 mA="buddi.rosterCollapsed";function Mz(){try{return window.localStorage.getItem(mA)==="1"}catch{return!1}}function Dz(e){try{window.localStorage.setItem(mA,e?"1":"0")}catch{}}function pA({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(Mz),v=b=>n.jsx(Oz,{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&&hA(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(hf,{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:ft,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=>(Dz(!b),!b)),children:n.jsx(ce,{name:p?"chevron-right":"chevron-left"})}):null]})}function Oz({agent:e,active:t,attention:s,side:r,onSelect:i,lastAt:a=null,working:l=!1}){const o=df(s),c=yz(s)??(e.available?a?wL(a):e.description:e.unavailableReason??"Cannot run right now"),u=bz(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(oc,{children:[n.jsx(cc,{asChild:!0,children:n.jsxs("button",{className:"wb-face",...Hc(Wc(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(hf,{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(uc,{children:n.jsxs(dc,{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:Lz(o)}):null]})})]})}function Lz(e){return`${e.slice(0,1).toUpperCase()}${e.slice(1)}.`}function Fz(e){let t=0;for(const s of e)t=(t*31+s.charCodeAt(0))%997;return t%6+1}const _z="modulepreload",zz=function(e,t){return new URL(e,t).href},Ak={},Uz=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 Ak)return;Ak[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":_z,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)})},Bz="buddi",Wz=["core","coding","finance","garage","mail","maker","playground","research"],wa=e=>`./mascot/${e}.png`,Hz=["core"],Hg=(e,t)=>Hz.includes(e)?`./mascot/anim/${e}-${t}.json`:null,Kz=["🙂","📚","🧭","🦊","🛟","🌿","🛠️","🎧"],Vz="Introduce yourself by name and say one thing you can do today.",Gz=["Hello","A brain","What I take on","Reach me","Your assistant"],Iu=(e,t=!1)=>e.length<2?e.join(""):`${e.slice(0,-1).join(", ")}${t&&e.length>2?", and ":" and "}${e[e.length-1]}`,Em=e=>e.charAt(0).toUpperCase()+e.slice(1),Yz=["No","One","Two","Three","Four","Five","Six","Seven","Eight"],Oo=[{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."}],qz=["days","mail"],Tk=[{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:Gz,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 ${Iu(e)} from withbuddi.com and reading them. ${t} of ${s}.`,ready:e=>`${Iu(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":Em(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":Em(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: ${Iu(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=>`${Yz[e]??String(e)} ${e===1?"thing":"things"} still waiting.`,waitingBody:e=>`${Em(Iu(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 Pu=null;const $k=new Map;function Jz(){return Pu??(Pu=Uz(()=>import("./lottie_light-DYHnHRWL.js").then(e=>e.l),[],import.meta.url).then(e=>e.default)),Pu.catch(()=>{Pu=null}),Pu}function Qz(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 Rk="(prefers-reduced-motion: reduce)";function gA(){const[e,t]=d.useState(()=>typeof window.matchMedia=="function"&&!window.matchMedia(Rk).matches);return d.useEffect(()=>{var i;if(typeof window.matchMedia!="function")return;const s=window.matchMedia(Rk),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 Vc({role:e="core",state:t,size:s,still:r,className:i,onStillError:a}){const l=d.useRef(null),o=gA(),[c,u]=d.useState(!1),h=s==="xs"?null:Hg(e,t);return d.useEffect(()=>{if(u(!1),!o||!h)return;let f=!1,m=null;return Promise.all([Jz(),Qz(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??wa(e),alt:"",onError:a})})}async function Ik(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 xA(e,t="core"){const s=gA(),r=e!==null&&Xz(e,t),[i,a]=d.useState(!1);return d.useEffect(()=>{if(a(!1),!e||r||!s||!Hg(t,"idle"))return;let l=!1;return Promise.all([Ik(e),Ik(wa(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&&Hg(t,"idle")!==null&&(r||i)}function Xz(e,t){const s=wa(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 hf({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?Hc(Wc({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:$z(s).slice(0,o)})}function kn({id:e,name:t,size:s,unavailable:r,face:i}){return n.jsx(hf,{className:"ui-avatar",id:e,tint:Fz(e),name:t,size:s,unavailable:r,face:i})}function on({agents:e,id:t,size:s}){const r=e.find(i=>i.id===t);return n.jsx(kn,{id:t,name:(r==null?void 0:r.name)??t,size:s,unavailable:r?!r.available:!1,face:r})}const vA=d.createContext(null);function Zz({picture:e,children:t}){return n.jsx(vA.Provider,{value:e??null,children:t})}function jA({size:e,anim:t}){const s=d.useContext(vA),[r,i]=d.useState(null),a=xA(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(Vc,{state:t,still:s,className:"ui-mascot-blob",onStillError:()=>i(s)}):n.jsx("img",{src:s,alt:"",onError:()=>i(s)})})}const wA=d.createContext([]);function mr({text:e,className:t}){const s=Kg(e.replace(/\r\n/g,`
88
- `).split(`
89
- `));return n.jsx("div",{className:t??"wb-md",children:s.map((r,i)=>n.jsx(Vg,{block:r},i))})}const Pk=/^(\s*)(```|~~~)\s*([\w+-]*)\s*$/,Mk=/^(#{1,6})\s+(.*?)\s*#*\s*$/,Dk=/^\s*([-*_])(\s*\1){2,}\s*$/,Mu=/^(\s*)([-*+])\s+(.*)$/,mo=/^(\s*)(\d{1,9})[.)]\s+(.*)$/,Du=/^\s*>\s?(.*)$/,Am=/^\s*\|.*\|\s*$/,Ok=/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/;function Kg(e){const t=[];let s=0;for(;s<e.length;){const r=e[s];if(r.trim()===""){s+=1;continue}const i=Pk.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=Mk.exec(r);if(a){t.push({type:"h",level:a[1].length,text:a[2]}),s+=1;continue}if(Dk.test(r)){t.push({type:"hr"}),s+=1;continue}if(Du.test(r)){const o=[];for(;s<e.length&&Du.test(e[s]);)o.push(Du.exec(e[s])[1]),s+=1;t.push({type:"quote",blocks:Kg(o),raw:o.join(`
91
- `)});continue}if(Am.test(r)&&s+1<e.length&&Ok.test(e[s+1])){const o=$m(r),c=$m(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&&Am.test(e[s]);)u.push($m(e[s])),s+=1;t.push({type:"table",head:o,rows:u,align:c});continue}if(Mu.test(r)||mo.test(r)){const o=mo.exec(r)??Mu.exec(r),c=mo.test(r),u=o[1].length,h=c?Number(o[2]):1,f=[];for(;s<e.length;){const m=c?mo.exec(e[s]):Mu.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()!==""&&Tm(g)>u,b=g.trim()===""&&s+1<e.length&&e[s+1].trim()!==""&&Tm(e[s+1])>u;if(!v&&!b)break;p.push(g.trim()===""?"":g.slice(Math.min(Tm(g),u+2))),s+=1}f.push(Kg(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()===""||Pk.test(o)||Mk.test(o)||Dk.test(o)||Du.test(o)||Mu.test(o)||mo.test(o)||Am.test(o)&&s+1<e.length&&Ok.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 Tm(e){return e.length-e.trimStart().length}function $m(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 Vg({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(Lk,{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(Vg,{block:t},s))}),n.jsx(Lk,{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(Vg,{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 Lk({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 eU({handle:e}){const s=d.useContext(wA).find(r=>r.handle.toLowerCase()===e.toLowerCase());return s?n.jsxs(oc,{children:[n.jsx(cc,{asChild:!0,children:n.jsxs("a",{className:"wb-mention-link",href:st(s.id),children:["@",s.handle]})}),n.jsx(uc,{children:n.jsxs(dc,{className:"wb-agent-card",sideOffset:6,children:[n.jsx(kn,{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 tU=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=tU.exec(s);if(!i){t.push(...Fk(s,r));break}i.index>0&&t.push(...Fk(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(eU,{handle:i[11]},r)),s=s.slice(i.index+i[0].length)}return t}function Fk(e,t){return e.split(`
93
- `).flatMap((r,i)=>i===0?[r]:[n.jsx("br",{},`${t}-br-${i}`),r])}function nU({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:tn(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(mr,{text:e.text})}):n.jsx("p",{className:"wb-empty",children:"This document came back with no body."})]})}const sU=["mail","money","calendar","people","file","chart","bell","plug","key","globe","sun","partly-cloudy","cloud","rain","drizzle","snow","storm","fog","wind","moon-clear","check","clock","moon-cloud"];function Ce(e,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 Ve(e,t){if(t)return"const"in t?t.const:Ce(e,t.path)}function ns(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 mt(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):null}function vi(e){return Array.isArray(e)?e:[]}function rU(e,t){const s=vi(Ce(e,t.points)).map(i=>{const a=ns(Ce(i,t.y)),l=mt(Ce(i,t.x));return a===null||l===null?null:{x:l,y:a}}).filter(i=>i!==null),r=(t.referenceLines??[]).map(i=>{const a=ns(Ve(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:mt(Ve(e,t.currency)),label:mt(Ve(e,t.label)),referenceLines:r,mark:t.mark??null,shadeBelow:ns(Ve(e,t.shadeBelow)),events:iU(e,t)}}function iU(e,t){const s=t.events;if(!s)return[];const r=[],i=(a,l)=>{const o=mt(Ce(a,s.label));if(o===null)return;const c=mt(Ce(a,s.at))??l;c!==null&&r.push({at:c,label:o,amount:s.amount?ns(Ce(a,s.amount)):null})};if(s.parent){for(const a of vi(Ce(e,t.points))){const l=mt(Ce(a,t.x));for(const o of vi(Ce(a,s.parent)))i(o,l)}return r}for(const a of vi(Ce(e,s.path??t.points)))i(a,null);return r}function aU(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=Ce(o,c.key);let h=null;if(c.bar){const f=ns(Ve(o,c.bar.max))??ns(Ve(e,c.bar.max)),m=ns(u);if(f!==null&&f>0&&m!==null){const p=Math.max(0,Math.min(1,m/f));h={fraction:p,tone:oU(p*100,c.bar.thresholds)}}}return{value:u,type:c.type??"text",currency:mt(Ve(o,c.currency))??mt(Ve(e,c.currency)),bar:h}}),i=vi(Ce(e,t.rows)),a=t.groupBy?lU(i,t.groupBy,r):[{label:null,rows:i.map(r)}],l=(t.summary??[]).map(o=>({label:o.label,value:Ve(e,o.value),unit:o.unit??"text",currency:mt(Ve(e,o.currency)),tone:o.tone??"neutral"}));return{columns:s,groups:a,summary:l,empty:t.empty??"Nothing to show."}}function lU(e,t,s){const r=new Map;for(const i of e){const a=String(Ce(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 oU(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 cU(e,t){return{bars:vi(Ce(e,t.bars)).map(r=>{const i=ns(Ce(r,t.value)),a=mt(Ce(r,t.category));return i===null||a===null?null:{category:a,value:i}}).filter(r=>r!==null),unit:t.unit??"number",currency:mt(Ve(e,t.currency))}}function uU(e,t){if(t.pairs)return{pairs:t.pairs.map(r=>({label:r.label,value:Ve(e,r.value),unit:r.unit??"text",currency:mt(Ve(e,r.currency)),tone:r.tone??"neutral"}))};const s=Ce(e,t.from??"$");return s===null||typeof s!="object"||Array.isArray(s)?{pairs:[]}:{pairs:Object.entries(s).map(([r,i])=>({label:yn(r),value:i,unit:"text",currency:null,tone:"neutral"}))}}const dU=new Set(["good","warning","critical","neutral","accent"]),hU=new Set(sU);function Gg(e){return typeof e=="string"&&hU.has(e)?e:null}function Pj(e,t,s=""){const r=t.empty??"Nothing to show.",i=s.split(".")[0]??"";if(t.notice){const l=mt(Ce(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:Gg(t.notice.icon??"bell"),value:"",label:l.trim(),lines:[],tone:"neutral",link:o}],notice:!0,empty:r}}}return{tiles:vi(Ce(e,t.items)).map(l=>{const o=mt(Ce(l,t.value))??"",c=mt(Ce(l,t.label))??"";if(o===""&&c==="")return null;const u=t.tone?mt(Ce(l,t.tone)):null;return{icon:Gg(Ve(l,t.icon)),value:o,label:c,lines:(t.lines??[]).slice(0,2).map(h=>mt(Ce(l,h))).filter(h=>h!==null&&h.trim()!==""),tone:u!==null&&dU.has(u)?u:"neutral",link:null}}).filter(l=>l!==null),notice:!1,empty:r}}function fU(e,t){const s=mt(Ve(e,t.kind)),r=s==="image"||s==="pdf"?s:"text",i=t.src?mt(Ce(e,t.src)):null;return{kind:r,text:t.text?mt(Ce(e,t.text)):null,src:i&&bA(i)?i:null,title:mt(Ve(e,t.title)),metadata:(t.metadata??[]).map(a=>({label:a.label,value:Ve(e,a.value),unit:a.unit??"text"}))}}function mU(e,t){const s=t.diff?Ce(e,t.diff):void 0;return{diff:typeof s=="string"&&s.trim()!==""?s:null,title:mt(Ve(e,t.title)),metadata:(t.metadata??[]).map(r=>({label:r.label,value:Ve(e,r.value),unit:r.unit??"text"}))}}function pU(e,t){const s=t.output?Ce(e,t.output):void 0,r=l=>{const o=l?Ce(e,l):void 0;return typeof o=="number"&&Number.isInteger(o)?o:null},i=r(t.omittedBytes),a=t.elapsedMs?Ce(e,t.elapsedMs):void 0;return{command:mt(Ve(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:Ve(e,l.value),unit:l.unit??"text"}))}}const gU=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function yA(e){const t=e!==null&&typeof e=="object"&&!Array.isArray(e)?e.artifactId??e.id:e;return typeof t=="string"&&gU.test(t)?t.toLowerCase():null}function xU(e,t){return{artifactId:t.src?yA(Ce(e,t.src)):null,title:mt(Ve(e,t.title)),caption:mt(Ve(e,t.caption)),...t.captionLabel?{captionLabel:mt(Ve(e,t.captionLabel))}:{}}}function _k(e){if(!bA(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 vU(e,t){const s=t.src?mt(Ce(e,t.src)):null,r=t.port?Ce(e,t.port):null,i=t.awaiting?mt(Ce(e,t.awaiting)):null;return{target:s?_k(s):null,title:mt(Ve(e,t.title)),output:t.output?mt(Ce(e,t.output)):null,port:typeof r=="number"&&Number.isInteger(r)&&r>0&&r<=65535?r:null,awaiting:i?_k(i):null,reloadsItself:t.reloadsItself?Ce(e,t.reloadsItself)===!0:!1,ports:t.ports?jU(Ce(e,t.ports)):[]}}function jU(e){const t=vi(e).filter(s=>typeof s=="number"&&Number.isInteger(s)&&s>0&&s<=65535);return[...new Set(t)].sort((s,r)=>s-r)}function bA(e){return e.startsWith("/")&&!e.startsWith("//")}function yn(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 kA(e,t){const s=e.map??{};switch(e.renderer){case"timeseries":return{renderer:"timeseries",props:rU(t,s)};case"table":return{renderer:"table",props:aU(t,s)};case"bars":return{renderer:"bars",props:cU(t,s)};case"keyvalue":return{renderer:"keyvalue",props:uU(t,s)};case"tiles":return{renderer:"tiles",props:Pj(t,s,e.tool)};case"document":return{renderer:"document",props:fU(t,s)};case"diff":return{renderer:"diff",props:mU(t,s)};case"terminal":return{renderer:"terminal",props:pU(t,s)};case"image":return{renderer:"image",props:xU(t,s)};case"preview":return{renderer:"preview",props:vU(t,s)};default:return{renderer:"structured",props:{value:t}}}}var wU=Object.defineProperty,Es=(e,t)=>wU(e,"name",{value:t,configurable:!0}),Mj="Dialog",[NA,QX]=Hs(Mj),[yU,jr]=NA(Mj),ff=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]=Ri({prop:r,defaultProp:i??!1,onChange:a,caller:Mj}),[f,m]=d.useState(0),[p,g]=d.useState(0);return n.jsx(yU,{scope:t,triggerRef:o,contentRef:c,contentId:Fs(),titleId:Fs(),descriptionId:Fs(),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"),bU="DialogTrigger",kU=d.forwardRef(Es(function(t,s){const{__scopeDialog:r,...i}=t,a=jr(bU,r),l=wt(s,a.triggerRef);return n.jsx(gt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":xf(a.open),...i,ref:l,onClick:Me(t.onClick,a.onOpenToggle)})},"DialogTrigger")),SA="DialogPortal",[NU,CA]=NA(SA,{forceMount:void 0}),mf=Es(e=>{const{__scopeDialog:t,forceMount:s,children:r,container:i}=e,a=jr(SA,t);return n.jsx(NU,{scope:t,forceMount:s,children:d.Children.map(r,l=>n.jsx(xr,{present:s||a.open,children:n.jsx(Wh,{asChild:!0,container:i,children:l})}))})},"DialogPortal"),Yg="DialogOverlay",Dj=d.forwardRef(Es(function(t,s){const r=CA(Yg,t.__scopeDialog),{forceMount:i=r.forceMount,...a}=t,l=jr(Yg,t.__scopeDialog);return l.modal?n.jsx(xr,{present:i||l.open,children:n.jsx(CU,{...a,ref:s})}):null},"DialogOverlay")),SU=yi("DialogOverlay.RemoveScroll"),CU=d.forwardRef(Es(function(t,s){const{__scopeDialog:r,...i}=t,a=jr(Yg,r),l=o1(),o=wt(s,l);return n.jsx(pj,{as:SU,allowPinchZoom:!0,shards:[a.contentRef],children:n.jsx(gt.div,{"data-state":xf(a.open),...i,ref:o,style:{pointerEvents:"auto",...i.style}})})},"DialogOverlayImpl")),vc="DialogContent",pf=d.forwardRef(Es(function(t,s){const r=CA(vc,t.__scopeDialog),{forceMount:i=r.forceMount,...a}=t,l=jr(vc,t.__scopeDialog);return n.jsx(xr,{present:i||l.open,children:l.modal?n.jsx(EU,{...a,ref:s}):n.jsx(AU,{...a,ref:s})})},"DialogContent")),EU=d.forwardRef(Es(function(t,s){const r=jr(vc,t.__scopeDialog),i=d.useRef(null),a=wt(s,r.contentRef,i);return d.useEffect(()=>{const l=i.current;if(l)return bE(l)},[]),n.jsx(EA,{...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")),AU=d.forwardRef(Es(function(t,s){const r=jr(vc,t.__scopeDialog),i=d.useRef(!1),a=d.useRef(!1);return n.jsx(EA,{...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")),EA=d.forwardRef(Es(function(t,s){const{__scopeDialog:r,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:l,...o}=t,c=jr(vc,r);return tf(),n.jsx(n.Fragment,{children:n.jsx(rE,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:a,onUnmountAutoFocus:l,children:n.jsx(Bh,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionPresent?c.descriptionId:void 0,"aria-labelledby":c.titlePresent?c.titleId:void 0,"data-state":xf(c.open),...o,ref:s,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})},"DialogContentImpl")),TU="DialogTitle",gf=d.forwardRef(Es(function(t,s){const{__scopeDialog:r,...i}=t,a=jr(TU,r),{setTitleCount:l}=a;return Kn(()=>(l(o=>o+1),()=>l(o=>o-1)),[l]),n.jsx(gt.h2,{id:a.titleId,...i,ref:s})},"DialogTitle")),$U="DialogClose",Oj=d.forwardRef(Es(function(t,s){const{__scopeDialog:r,...i}=t,a=jr($U,r);return n.jsx(gt.button,{type:"button",...i,ref:s,onClick:Me(t.onClick,()=>a.onOpenChange(!1))})},"DialogClose"));function xf(e){return e?"open":"closed"}Es(xf,"getState");const RU=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>=RU)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 AA={width:480,height:160,top:10,right:10,bottom:22,left:40},TA={width:1200,height:180,top:10,right:40,bottom:22,left:40};function IU({xs:e,series:t}){const s=TA,r=s.width-s.left-s.right,i=s.height-s.top-s.bottom,a=_=>_.filter($=>$!==null&&Number.isFinite($)),l=t.filter(_=>_.type!=="bar"),o=t.filter(_=>_.type==="bar"),c=l.flatMap(_=>a(_.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 _=(m-f)*.08;f-=_,m+=_}const p=_=>js(s.top+i-(_-f)/(m-f)*i),g=o.length>0&&o.every(_=>_.unit==="percent"),v=g?100:Math.max(1,...o.flatMap(_=>a(_.values))),b=_=>js(s.top+i-Math.max(0,_)/v*i),j=e.length,x=j>0?r/j:r,w=_=>js(s.left+x*(_+.5)),y=t.map(_=>{if(_.type==="bar")return"";let $="M";const P=[];return _.values.forEach((O,M)=>{if(O===null||!Number.isFinite(O)){$="M";return}P.push(`${$}${w(M)},${p(O)}`),$="L"}),P.join(" ")}),k=[],N=x*.6/Math.max(1,o.length),S=s.height-s.bottom;let C=0;t.forEach((_,$)=>{if(_.type!=="bar")return;const P=C++;_.values.forEach((O,M)=>{if(O===null||!Number.isFinite(O)||O<=0)return;const D=b(O);k.push({series:$,index:M,x:js(w(M)-x*.3+N*P),y:D,width:js(N),height:js(S-D)})})});const T=c.length>0?Qd(u,h,2).map(_=>({value:_,y:p(_)})):[],R=o.length===0?[]:(g?[0,50,100]:Qd(0,v,2)).map(_=>({value:_,y:b(_),percent:g})),I=Math.max(1,Math.ceil(j/8)),L=e.flatMap((_,$)=>$%I===0?[{index:$,x:w($)}]:[]);return{lines:y,bars:k,targetY:null,ticks:T,xLabels:L,rightTicks:R}}function PU({xs:e,series:t,type:s="line",target:r=null}){const i=AA,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=>js(i.top+l-(w-c)/(u-c)*l),f=e.length,m=f>0?a/f:a,p=w=>js(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,T)=>{if(C===null||!Number.isFinite(C))return;const R=h(C);v.push({series:S,index:T,x:js(i.left+m*T+(m-w)/2+y*S),y:Math.min(R,k),width:js(y),height:js(Math.abs(k-R))})})})}const j=(o.length>0?Qd(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 MU(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 DU({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?TA:AA,u=o?IU({xs:e,series:t}):PU({xs:e,series:t,type:s,target:r}),h=MU({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 js(e){return Math.round(e*10)/10}const Lj="(max-width: 900px)";function ks(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 Mi(...e){return e.filter(Boolean).join(" ")}function E({variant:e,size:t,className:s,type:r="button",...i}){return n.jsx("button",{type:r,className:Mi("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":t,...i})}function Et({variant:e,size:t,className:s,...r}){return n.jsx("a",{className:Mi("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":t,...r})}function OU({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:Mi("ui-toolbar",r),"data-align":t,"data-valign":s,children:e})}function dt(){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 Bs({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:Mi("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 qg({children:e}){return n.jsx("span",{className:"ui-tag",children:e})}function Gc({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 ie({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(jA,{size:"sm"}),n.jsx("p",{children:i})]}):n.jsx("p",{className:"ui-empty",children:i})}function $n({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 Fj({children:e}){return n.jsx("div",{className:"ui-page",children:e})}function yl({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 Mn({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(Fj,{children:[n.jsx(yl,{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 Ge({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 us({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 LU({children:e}){return n.jsx("div",{className:"ui-row",children:e})}function vf({inline:e,children:t}){return n.jsx("div",{className:"ui-stats","data-inline":e?"true":void 0,children:t})}function ar({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 wr({children:e}){return n.jsx("div",{className:"ui-table-wrap",children:n.jsx("table",{className:"ui-table",children:e})})}function $A({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 At({summary:e,boxed:t,open:s,className:r,onToggle:i,children:a}){return n.jsxs("details",{className:Mi("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 qe({title:e,onClose:t,size:s,foot:r,children:i}){return n.jsx(ff,{open:!0,onOpenChange:a=>{a||t()},children:n.jsxs(mf,{children:[n.jsx(Dj,{className:"ui-sheet-overlay"}),n.jsxs(pf,{className:"ui-sheet","data-size":s,"aria-describedby":void 0,children:[n.jsxs("div",{className:"ui-sheet-head",children:[n.jsx(gf,{className:"ui-sheet-title",children:e}),n.jsx(Oj,{asChild:!0,children:n.jsx(E,{size:"sm",children:"Close"})})]}),i,r?n.jsx("div",{className:"ui-sheet-foot",children:r}):null]})]})})}function Lt({title:e,onClose:t,foot:s,children:r}){return n.jsx(ff,{open:!0,onOpenChange:i=>{i||t()},children:n.jsxs(mf,{children:[n.jsx(Dj,{className:"ui-sheet-overlay","data-layer":"modal"}),n.jsxs(pf,{className:"ui-modal",role:"alertdialog","aria-describedby":void 0,children:[n.jsx(gf,{className:"ui-modal-title",children:e}),r,s?n.jsx("div",{className:"ui-modal-foot",children:s}):null]})]})})}function Di({label:e,items:t,note:s,trigger:r,sheet:i}){const a=ks(FU);return i&&a&&!r?n.jsx(_U,{label:e,items:t,title:i.title,sub:i.sub}):n.jsx(zU,{label:e,items:t,note:s,trigger:r})}const FU="(max-width: 720px)";function _U({label:e,items:t,title:s,sub:r}){const[i,a]=d.useState(!1);return n.jsxs(ff,{open:i,onOpenChange:a,children:[n.jsx(kU,{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(mf,{children:[n.jsx(Dj,{className:"ui-sheet-overlay",onClick:l=>l.stopPropagation()}),n.jsxs(pf,{className:"ui-action-sheet","aria-describedby":void 0,onClick:l=>l.stopPropagation(),children:[n.jsxs("div",{className:"ui-action-sheet-head",children:[n.jsx(gf,{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(Oj,{asChild:!0,children:n.jsx(E,{className:"ui-action-sheet-cancel",children:"Cancel"})})]})]})]})}function zU({label:e,items:t,note:s,trigger:r}){const i=l=>l.stopPropagation(),a=d.useRef(!1);return n.jsxs(_c,{modal:!1,onOpenChange:l=>{l&&(a.current=!1)},children:[n.jsx(zc,{asChild:!0,children:r??n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":e,title:e,onClick:i,children:n.jsx(ce,{name:"more"})})}),n.jsx(zl,{children:n.jsxs(Uc,{className:"ui-menu",align:"end",sideOffset:4,onClick:i,onKeyDown:i,onCloseAutoFocus:l=>{a.current&&l.preventDefault()},children:[s?n.jsx(da,{className:"ui-menu-label",children:s}):null,t.map((l,o)=>l?l==="separator"?n.jsx(Ir,{className:"ui-menu-sep"},`sep-${o}`):"heading"in l?n.jsx(da,{className:"ui-menu-label",children:l.heading},`head-${o}`):n.jsxs(vs,{className:"ui-menu-item","data-tone":l.tone,onSelect:()=>{a.current=!0,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)]})})]})}function UU({title:e,actions:t,onClose:s,onCloseAutoFocus:r,onOpenAutoFocus:i,label:a,children:l}){return n.jsx(ff,{open:!0,modal:!1,onOpenChange:o=>{o||s()},children:n.jsx(mf,{children:n.jsxs(pf,{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(gf,{className:"ui-dock-title",children:e}),n.jsxs("div",{className:"ui-dock-actions",children:[t,n.jsx(Oj,{asChild:!0,children:n.jsx(E,{size:"sm",variant:"ghost",children:"Close"})})]})]}),n.jsx("div",{className:"ui-dock-body",children:l})]})})})}function Yc({level:e,label:t,children:s}){return n.jsx("nav",{className:"ui-tabs","data-level":e,"aria-label":t,children:s})}function bl({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 Yt({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 RA({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 IA({list:e,detail:t,empty:s,label:r,className:i}){return n.jsxs("div",{className:Mi("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 eh({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 BU=8;function WU({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=$=>{var P;return((P=t.find(O=>O.value===$))==null?void 0:P.label)??$},w=i!==void 0&&s.length>=i,y=t.filter($=>!s.includes($.value)),k=t.length>BU,N=u.trim().toLowerCase(),S=N===""?y:y.filter($=>$.label.toLowerCase().includes(N)),C=Math.min(f,Math.max(0,S.length-1)),T=$=>{var P;c(!1),h(""),m(0),$&&((P=g.current)==null||P.focus())};d.useEffect(()=>{var P;if(!o)return;(P=k?v.current:b.current)==null||P.focus();const $=O=>{p.current&&!p.current.contains(O.target)&&T(!1)};return document.addEventListener("mousedown",$),()=>document.removeEventListener("mousedown",$)},[o,k]);const R=$=>{const P=[...s,$];r(P),h(""),m(0);const O=i!==void 0&&P.length>=i;(O||P.length>=t.length)&&T(!O)},I=$=>{if($.key==="Escape")$.preventDefault(),T(!0);else if($.key==="ArrowDown")$.preventDefault(),m(S.length===0?0:(C+1)%S.length);else if($.key==="ArrowUp")$.preventDefault(),m(S.length===0?0:(C-1+S.length)%S.length);else if($.key==="Enter"){$.preventDefault();const P=S[C];P&&R(P.value)}else $.key==="Backspace"&&u===""&&s.length>0&&($.preventDefault(),r(s.slice(0,-1)))},L=$=>`${j}-${$}`,_=o&&S.length>0?L(C):void 0;return n.jsxs("div",{className:"ui-chippicker",ref:p,id:l,children:[s.map($=>n.jsx(eh,{label:x($),disabled:a,onRemove:()=>r(s.filter(P=>P!==$)),children:x($)},$)),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?T(!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":_,value:u,onChange:$=>{h($.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:_,tabIndex:k?-1:0,className:"ui-chippicker-list",children:[S.map(($,P)=>n.jsx("div",{id:L(P),role:"option","aria-selected":"false",className:"ui-menu-item","data-highlighted":P===C?"":void 0,onMouseEnter:()=>m(P),onMouseDown:O=>O.preventDefault(),onClick:()=>R($.value),children:$.label},$.value)),S.length===0?n.jsx("p",{className:"ui-menu-empty",children:"Nothing matches"}):null]})]}):null]})]})}function PA({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 jf({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 Rn({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 th({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 MA({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(E,{"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 jc({size:e}){return n.jsx("span",{className:"ui-mark","data-size":e,"aria-hidden":"true",children:"b"})}function DA({quiet:e,still:t,className:s,children:r}){return n.jsx("div",{className:Mi("ui-fieldbg",s),"data-quiet":e?"true":void 0,"data-still":t?"true":void 0,children:r})}function HU({dock:e,className:t,children:s}){return n.jsxs("div",{className:Mi("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 KU(e){const t={};for(const s of e??[])t[s.key]=s.default;return t}function _j(e){const[t,s]=d.useState({}),r=e??[],i={...KU(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 VU({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),A.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}=_j(r==null?void 0:r.choices),p=(y,k)=>{h(y),l(null),(f&&y==="approve"?A.decide(e.approvalId,y,k,f):A.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=GU(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=>yn(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(Gc,{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(ie,{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 GU(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(zk(yn(i),a));else s!=null&&t.push({label:"Envelope",value:zj(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 · ${yn(i)}`;t.some(o=>o.label===l)||t.push(zk(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 zk(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:zj(t)}}function zj(e){return e==null?"—":Array.isArray(e)?e.map(t=>zj(t)).join(", ")||"—":typeof e=="object"?JSON.stringify(e):tn(e,"text",null)}const YU=new Set(["image/png","image/jpeg","image/gif","image/webp"]),qU=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function nh(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"||!qU.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 Uj(e){return YU.has(e.toLowerCase())}function Gr(e){return`/api/artifacts/${encodeURIComponent(e)}/preview`}function Si(e){return`/api/artifacts/${encodeURIComponent(e)}/download`}function Gn(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 Bj(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 na={image:"Image",pdf:"PDF",table:"Spreadsheet",text:"Document",code:"Code",audio:"Audio",video:"Video",archive:"Archive",file:"File"};function fd(e){return`artifact:${e}`}function JU(e){const t=Bj(e.mime,e.filename);return{id:fd(e.artifactId),tool:na[t],title:e.filename??"Untitled file",renderer:"artifact",props:{attachment:e},at:null,source:"artifact",substantial:!1}}function QU({props:e}){const t=yA(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),A.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?Gn(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:Gr(t),className:"wb-image-link",title:"Open at full size",children:n.jsx("img",{src:Gr(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(Et,{size:"sm",href:Si(t),download:(s==null?void 0:s.filename)??c,children:"Download"})]}),e.caption&&e.captionLabel?n.jsx(At,{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 XU({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:tn(t.value,t.unit,t.currency)})]},t.label))})}const ZU=8;function OA({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<=ZU},children:e})}function e3(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 t3({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(E,{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 n3({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:e3(e.elapsedMs)}):null,n.jsx("span",{className:"ui-toolbar-spacer"}),t!==""?n.jsx(t3,{text:t}):null]}),e.omittedBytes!==null?n.jsxs("p",{className:"wb-terminal-note",children:["First ",Gn(e.omittedBytes)," not shown."]}):null,t!==""?n.jsx(OA,{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:tn(s.value,s.unit,null)})]},s.label))}):null]})}function s3(){const e=window.location.hostname.replace(/^\[|\]$/g,"").toLowerCase();return e==="127.0.0.1"||e==="::1"||e==="localhost"}function Uk(e){try{const t=new URL(e);return t.searchParams.delete("ticket"),t.toString()}catch{return e}}function r3(e){const t=new Set(e.ports??[]);return e.port!==null&&t.add(e.port),[...t].sort((s,r)=>s-r)}function i3({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=r3(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),A.previewLink(u,g).then(S=>{N&&(s(S.url),i(Uk(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||A.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&&s3()?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:Uk(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(OA,{text:e.output??"",className:"wb-preview-output"}):null]})]})}const a3=50,l3=9,o3=24,c3=.6,u3=48,d3=/(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,h3=/^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}|$)/,f3=/^id$|(^|[a-z0-9])Id$|_id$/;function Ja(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function es(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function LA(...e){for(const t of e)if(es(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 FA(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&&d3.test(e)?"currency":"number":r.every(i=>typeof i=="string"&&h3.test(i))?"date":"text"}function m3(e,t){if(!f3.test(e))return!1;const s=t.filter(r=>!Bl(r));return s.length<2?!1:new Set(s.map(r=>String(r))).size===s.length}function Bl(e){return e==null||e===""?!0:Array.isArray(e)?e.length===0:es(e)?Object.keys(e).length===0:!1}function Bk(e,t){const s=e.filter(es);if(s.length===0||s.length/e.length<.8)return null;const r=s.slice(0,a3),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>o3||[...i.values()].reduce((h,f)=>h+f,0)/(i.size*r.length)<c3)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=>!Bl(v));if(m.length===0||m3(h,f))continue;const p=LA(r[0],t),g=FA(h,f,p);if(r.length>=4&&m.length===f.length&&f.every(v=>Ja(v)&&v===f[0])){u.push({label:yn(h),value:f[0],type:g,currency:p});continue}if(c.push({key:h,label:yn(h),type:g,currency:g==="currency"?p:null}),c.length===l3)break}return c.length===0?null:{columns:c,rows:s,constants:u}}function p3(e,t,s){const r=LA(s);return{label:yn(e),value:t,type:FA(e,[t],r),currency:r}}function _A(e){return typeof e=="string"&&e.length>u3}function g3(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.":es(e)&&Object.keys(e).length===0?"This tool returned an empty result.":null}function Jg(e){if(typeof e=="string"&&e.trim()!=="")return e;if(es(e))for(const t of["message","error","reason","detail","description"]){const s=e[t];if(typeof s=="string"&&s.trim()!=="")return s;if(es(s)){const r=Jg(s);if(r!=="The call failed with no reason given.")return r}}return"The call failed with no reason given."}function Wj(e,t={}){if(t.failed){let f=e;if(typeof e=="string")try{const m=JSON.parse(e.replace(/^tool-error:\s*/,""));es(m)&&(f=m)}catch{}return{kind:"error",summary:Jg(f),detail:Wk(f)}}if(es(e)){const f=e.error,m=e.ok;if(typeof f=="string"&&f.trim()!==""||m===!1)return{kind:"error",summary:Jg(e),detail:Wk(e)}}const s=g3(e);if(s)return{kind:"empty",note:s,stats:[]};if(Array.isArray(e)){const f=Bk(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(Ja)?{kind:"list",label:null,items:e,total:e.length,stats:[],notes:[],asides:[]}:{kind:"tree",value:e}}if(!es(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=Bk(m,e);if(p){(!i||p.rows.length>i.candidate.rows.length)&&(i={key:f,candidate:p});continue}m.length>0&&m.every(Ja)&&(!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(_A(m)){c.push(m);continue}if(Ja(m)){if(m==="")continue;o.push(p3(f,m,e));continue}m!==void 0&&u.push({label:yn(f),value:m})}if(i)return{kind:"table",label:yn(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:yn(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])=>yn(m).toLowerCase()).join(", ")} to show.`,stats:o}:r.every(([,f])=>Ja(f)||es(f)||Array.isArray(f))?{kind:"record",pairs:o,notes:c,asides:u}:{kind:"tree",value:e}}function Wk(e){if(!es(e))return null;const t=Object.entries(e).filter(([s])=>s!=="message"&&s!=="error");return t.length===0?null:Object.fromEntries(t)}const sh=25,x3=3,Qg=8,zA=6;function Xg(e,t=0){if(t>zA||Bl(e)||_A(e))return 0;if(Ja(e))return 1;if(Array.isArray(e)){let s=0;for(const r of e)if(s+=Xg(r,t+1),s>=Qg)return s;return s}if(es(e)){let s=0;for(const r of Object.values(e))if(s+=Xg(r,t+1),s>=Qg)return s;return s}return 0}function Zg(e,t=0){if(t>zA)return!1;if(Array.isArray(e))return e.some(a=>Zg(a,t+1));if(!es(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=>Zg(a,t+1))}function v3(e){if(Zg(e))return!0;const t=Wj(e);switch(t.kind){case"table":return t.rows.length>0;case"list":return t.items.length>=x3;case"record":case"tree":return Xg(e)>=Qg;default:return!1}}function Rm(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function Hj(e){const t=Rm(e);if(!t)return null;const s=Rm(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:Rm(t.input),i=(r==null?void 0:r.command)??s.command;return{command:typeof i=="string"?i:null,input:r,result:s}}function j3({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 Im({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(j3,{text:t,label:`Copy ${e.toLowerCase()}`})]}),n.jsx("pre",{className:"wb-command-text","aria-label":e,tabIndex:0,children:t})]})}function w3({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(Im,{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(Im,{title:"Output",text:s.stdout}):n.jsx("p",{className:"wb-note",children:"No standard output."}),s.stderr?n.jsx(Im,{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:rs({...c,...i?{input:i}:{}})})]})]})}const Ou=2,Hk=64;function y3({props:e}){const[t,s]=d.useState(!1),r=Hj(e.value),i=b3((r==null?void 0:r.result)??e.value),a=d.useMemo(()=>Wj(e.value,{failed:e.failed??!1}),[e.value,e.failed]);return n.jsxs("div",{children:[!r&&n.jsx(Kk,{files:i}),t?n.jsx("pre",{className:"ui-code",children:rs(e.value)}):r?n.jsx(w3,{value:r,children:i.length>0&&n.jsxs("section",{children:[n.jsx("h4",{children:"Generated files"}),n.jsx(Kk,{files:i})]})}):i.length?n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:"Tool details"}),n.jsx(Vk,{shape:a})]}):n.jsx(Vk,{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 b3(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 Kk({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(k3,{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 k3({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 Vk({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:wc(e.detail,1)})]})]});case"empty":return n.jsxs("div",{children:[n.jsx(Pm,{stats:e.stats}),n.jsx("p",{className:"wb-note",children:e.note})]});case"table":{const t=T3(e.columns,e.rows);return n.jsxs("div",{children:[n.jsx(Pm,{stats:e.stats}),n.jsx(Mm,{notes:e.notes}),t?n.jsx($3,{label:e.label,plan:t,rows:e.rows,total:e.total}):n.jsx(S3,{label:e.label,columns:e.columns,rows:e.rows,total:e.total}),n.jsx(Dm,{asides:e.asides})]})}case"list":return n.jsxs("div",{children:[n.jsx(Pm,{stats:e.stats}),n.jsx(Mm,{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:tn(t,"text",null)},s))}),e.total>100?n.jsxs("p",{className:"wb-note",children:["Showing 100 of ",e.total,"."]}):null,n.jsx(Dm,{asides:e.asides})]});case"record":return n.jsxs("div",{children:[n.jsx(Mm,{notes:e.notes}),n.jsx(N3,{pairs:e.pairs}),n.jsx(Dm,{asides:e.asides})]});default:return n.jsx("div",{className:"wb-tree",children:wc(e.value,0)})}}function Pm({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:Kj(t.value,t.type,t.currency)})]},t.label))})}const Gk=200;function Mm({notes:e}){if(e.length===0)return null;const t=e.filter(r=>r.length<=Gk),s=e.filter(r=>r.length>Gk);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 N3({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:Kj(t.value,t.type,t.currency)})]},t.label))})}function Dm({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:wc(t.value,1)})]},t.label))})}function S3({label:e,columns:t,rows:s,total:r}){const[i,a]=d.useState(!1),l=r<=sh+5?r:sh,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:BA(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(R3,{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 C3=/^(title|name|headline|subject|label|heading)$/i,E3=/^(url|link|href|uri|permalink)$/i;function rh(e){return typeof e=="string"&&/^https?:\/\/[^\s]+$/i.test(e.trim())}function A3(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function UA(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 Lu(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 T3(e,t){if(t.length===0)return null;const s=e.filter(h=>h.type==="text"),r=s.find(h=>E3.test(h.key)&&t.some(f=>rh(f[h.key])))??s.find(h=>{const f=t.map(m=>m[h.key]).filter(m=>!Bl(m));return f.length>0&&f.filter(rh).length/f.length>=.6});if(!r)return null;const i=s.filter(h=>h.key!==r.key),a=i.find(h=>C3.test(h.key))??i.find(h=>Lu(t,h.key)>0);if(!a)return null;const o=[...i.filter(h=>h.key!==a.key)].sort((h,f)=>Lu(t,f.key)-Lu(t,h.key)),c=o[0]&&Lu(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 $3({label:e,plan:t,rows:s,total:r}){const[i,a]=d.useState(!1),l=r<=sh+5?r:sh,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=rh(h)?h.trim():null,m=typeof c[t.title]=="string"&&c[t.title].trim()!==""?c[t.title]:f?UA(f):"Untitled",p=t.description&&typeof c[t.description]=="string"?c[t.description]:null,g=f?A3(f):null,v=t.meta.map(b=>c[b]).filter(b=>!Bl(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 R3({value:e,column:t}){if(Bl(e))return n.jsx("td",{className:"wb-cell-soft",children:"—"});if(rh(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:UA(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:rs(e),children:i})}const s=Kj(e,t.type,t.currency),r=s.length>Hk?`${s.slice(0,Hk-1)}…`:s;return n.jsx("td",{className:BA(t.type)?"num":"wb-cell-text",...r===s?{}:{title:s},children:r})}function BA(e){return e==="number"||e==="currency"}function Kj(e,t,s){return e==null?"—":t==="boolean"?e?"yes":"no":tn(e,t==="text"?"text":t,s)}function wc(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,". "]}),wc(a,t+1)]},l)),e.length>50?n.jsxs("div",{className:"wb-tree-key",children:["…and ",e.length-50," more"]}):null]});return t>=Ou?n.jsx(Yk,{summary:`${e.length} items`,open:t===Ou,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:[yn(i),": "]}),wc(a,t+1)]},i))});return t>=Ou?n.jsx(Yk,{summary:`${s.length} fields`,open:t===Ou,children:r}):r}function Yk({summary:e,open:t,children:s}){return n.jsxs("details",{open:t,children:[n.jsx("summary",{className:"wb-tree-key",children:e}),s]})}function I3({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:tn(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:WA(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(P3,{cell:l},((c=e.columns[o])==null?void 0:c.key)??o)})},a))})]})})]},s.label??r))]})}function P3({cell:e}){const t=tn(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:WA(e.type)?"num":void 0,"data-type":e.type,title:t.length>40?t:void 0,children:t})}function WA(e){return e==="number"||e==="currency"||e==="percent"}const qk={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 Wl(e){return(e&&Object.prototype.hasOwnProperty.call(qk,e)?qk[e]:void 0)??"dot"}function ih(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 ah="buddi:plugin-pages-changed";function M3(){window.dispatchEvent(new Event(ah))}function HA(e=!1){const[t,s]=d.useState([]);return d.useEffect(()=>{if(e)return;let r=!1;const i=()=>{Promise.resolve().then(()=>A.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(ah,i),document.addEventListener("visibilitychange",a),()=>{r=!0,window.removeEventListener(ah,i),document.removeEventListener("visibilitychange",a)}},[e]),{all:t,rail:ih(t,"rail"),settings:ih(t,"settings"),find:(r,i)=>t.find(a=>a.plugin===r&&a.id===i)}}function KA(e,t){const s=(t??[]).filter(a=>a.plugin===e),r=ih(s,"rail")[0]??ih(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 md=null;typeof window<"u"&&window.addEventListener(ah,()=>{md=null});function D3(){return md??(md=Promise.resolve().then(()=>A.pages()).then(e=>Array.isArray(e==null?void 0:e.pages)?e.pages:[]).catch(()=>(md=null,[]))),md}function Vj(e,t,s){return s==="settings"?Vr(e,t):fr(e,t)}function O3(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 D3().then(l=>{const o=l.find(c=>c.plugin===r&&c.id===i);a||s(o?{href:Vj(r,i,o.place),label:o.place==="settings"?`Settings → ${o.title}`:o.title}:null)}),()=>{a=!0}},[r,i]),t}function VA({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(L3,{tile:i,...r?{picked:a===s,onPick:()=>r(a)}:{}},`${a}-${i.label}`))})}function L3({tile:e,picked:t,onPick:s}){const r=O3(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:Wl(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(us,{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 Ra=760,Om=400,Ft={top:18,right:18,bottom:36,left:66},F3=5;function _3({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=Ra-Ft.left-Ft.right,m=Om-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=Qd(l,o,4),b=U3(t.map(y=>y.y),e.mark),j=e.shadeBelow===null?[]:B3(t.map(y=>y.y),e.shadeBelow),x=t.map((y,k)=>`${k===0?"M":"L"}${p(k)},${g(y.y)}`).join(" "),w=y=>tn(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 ${Ra} ${Om}`,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:Ra-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:Ra-Ft.right,y1:g(y.value),y2:g(y.value)}),n.jsxs("text",{x:Ra-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:Ra-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,W3(t.length).map(y=>n.jsx("text",{x:p(y),y:Om-10,textAnchor:"middle",children:Fg(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:Fg(y.at)}),y.label]}),y.amount===null?null:n.jsx("span",{className:y.amount<0?"tnum critical":"tnum good",children:tn(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 U3(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 B3(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 W3(e,t=F3){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 fs=e=>e,ex={timeseries:fs(_3),table:fs(I3),bars:fs(c4),keyvalue:fs(XU),tiles:fs(VA),document:fs(nU),diff:fs(p4),terminal:fs(n3),image:fs(QU),preview:fs(i3),envelope:fs(VU),structured:fs(y3)},H3="structured";function K3(e){return(lh(e)?ex[e]:void 0)??ex[H3]}function lh(e){return Object.prototype.hasOwnProperty.call(ex,e)}function V3({renderer:e,props:t,timezone:s,onDecided:r}){const i=K3(e),l=lh(e)?t:{value:t};return n.jsx(i,{props:l,timezone:s,onDecided:r})}function G3({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(Lm,{children:"Opens by default"}):null,n.jsx(Lm,{children:e.source==="example"?"Shipped with buddi":"Yours"}),e.roles.map(s=>n.jsx(Lm,{title:`A surface command that asks for "${s}" lands on this agent.`,children:yn(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(po,{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(GA,{}),"Exact action"]})]})]})}),n.jsx(po,{title:"What it can do",note:Y3(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(q3,{family:s},s.family))}),n.jsx(po,{title:"What it runs on",children:n.jsxs("dl",{className:"wb-prof-kv",children:[n.jsx(go,{label:"Provider",children:e.engine.provider}),n.jsx(go,{label:"Model",children:n.jsx("span",{className:"mono",children:e.engine.model})}),n.jsxs(go,{label:"Credential",children:[e.engine.credentialKind," from"," ",n.jsx("span",{className:"mono",children:e.engine.credentialEnv})]}),n.jsxs(go,{label:"Turn budget",children:[e.engine.maxTurns," ",e.engine.maxTurns===1?"turn":"turns"," per message"]}),n.jsx(go,{label:"Language",children:e6(e.engine.language)})]})}),e.skills.length>0?n.jsx(po,{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(po,{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 Y3(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 q3({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:yn(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(J3,{tool:s},s.name))})]})}function J3({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:Z3(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(GA,{}),"Needs your approval"]}):n.jsx("span",{className:"wb-prof-auto",title:X3(e.tier),children:Q3(e.tier)})]})}function Q3(e){return e==="auto"?"Runs on its own":e==="gated"?"Needs your approval":"Not runnable here"}function X3(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 Z3(e){const t=e.split(".");return(t[t.length-1]??e).replace(/_/g," ")}function e6(e){return e==="mirror"?"Mirrors whichever language you write in":e==="en"?"Always English":e==="fr"?"Always French":e}function po({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 go({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 Lm({children:e,title:t}){return n.jsx("span",{className:"wb-prof-tag",title:t,children:e})}function GA(){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 Jk=16e3,t6=10*6e4,n6="The microphone is blocked for this page: allow it in the browser’s site settings to talk.",YA="This browser cannot record here: talking needs a microphone and a secure page (https or localhost).";function s6(){const e=window;return e.AudioContext??e.webkitAudioContext}function r6(e){const t=e&&typeof e=="object"&&"name"in e?String(e.name):"";return t==="NotAllowedError"||t==="SecurityError"||t==="PermissionDeniedError"?n6:t==="NotFoundError"||t==="DevicesNotFoundError"?"No microphone was found on this computer.":t==="NotReadableError"?"The microphone is in use by another app.":YA}async function i6(e){var c;const t=s6();if(!((c=navigator.mediaDevices)!=null&&c.getUserMedia)||!t)throw Object.assign(new Error(YA),{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(),o6(l6(a6(l),u,Jk),Jk)},cancel:o}}function a6(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 l6(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 o6(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 tx="buddi.readAloud";function qA(){try{return window.localStorage.getItem(tx)==="on"}catch{return!1}}function JA(e){try{e?window.localStorage.setItem(tx,"on"):window.localStorage.removeItem(tx)}catch{}}let tr=null,Lo=null,yc=0,nx=null;const sx=new Set;function oh(e){nx!==e&&(nx=e,sx.forEach(t=>t()))}function c6(){return nx}function u6(e){return sx.add(e),()=>sx.delete(e)}function QA(e){return Hl(),oh(e),yc}function Qk(e){return e===yc}function Hl(){yc++,tr&&(tr.pause(),tr.removeAttribute("src")),Lo&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(Lo),Lo=null,oh(null)}async function d6(e,t,s=null){var i;const r=QA(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!==yc)return;tr||(tr=new Audio,(i=tr.addEventListener)==null||i.call(tr,"ended",()=>oh(null))),Lo=URL.createObjectURL(l),tr.src=Lo,await tr.play()}catch(a){throw r===yc&&oh(null),a}}const h6=new Set(["audio/ogg","audio/mpeg","audio/mp4","audio/wav","audio/x-wav","audio/webm"]);function XA(e){return h6.has(e.toLowerCase().split(";")[0].trim())}function Xk(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 ZA({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}Hl(),f(!1);try{if(!a.current){u(!0);const w=await fetch(Si(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.":`${Xk(m)} / ${Xk(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&&Gn(r)?` · ${Gn(r)}`:""]})]}),n.jsx("a",{className:"ui-icon-btn wb-audio-download","data-size":"sm",href:Si(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 Fm=1e5,_m=200,zm=30;function eT({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:Gr(e),alt:t??"Image",onError:()=>l(!0)})}):r==="audio"&&XA(s)?n.jsx("div",{className:"file-preview file-preview-audio",children:n.jsx(ZA,{artifactId:e,name:t??"Audio",mime:s})}):r==="pdf"?n.jsx("div",{className:"file-preview file-preview-pdf",children:n.jsx("object",{data:Gr(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(f6,{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 f6({artifactId:e,filename:t,mime:s,family:r}){const[i,a]=d.useState("loading");if(d.useEffect(()=>{let o=!1;return a("loading"),fetch(Gr(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,Fm),truncated:c.headers.get("X-Preview-Truncated")==="1"||u.length>Fm})}).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(p6,{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 ",Fm.toLocaleString()," characters. The download has the whole file."]}):null]})}function m6(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 p6({text:e,delimiter:t}){const s=d.useMemo(()=>m6(e,t,_m+1,zm),[e,t]),[r,...i]=s.rows;if(!r)return n.jsx("p",{className:"muted",children:"The file is empty."});const a=Math.min(zm,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,_m).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 ",_m," rows",s.truncatedCols?` and ${zm} columns`:"",". The download has the whole file."]}):null]})}function g6(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 x6(e,t){return`/api/artifacts/${encodeURIComponent(e)}/export/${t}`}function v6(e,t){return`${(e??"document").replace(/\.[a-z0-9]{1,8}$/i,"")||"document"}.${t}`}function Zk(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 tT({artifactId:e,filename:t,mime:s,accent:r=!0}){const i=t??"download",a=g6(s,t),l=r?"accent":void 0;if(a.length===0)return n.jsx("a",{className:"ui-btn","data-variant":l,href:Si(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?Zk(Si(e),i):Zk(x6(e,h.format),v6(t,h.format))});return n.jsx(Di,{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 j6({attachment:e}){const t=Bj(e.mime,e.filename);return n.jsxs("div",{className:"wb-artifact","data-family":t,"data-testid":"artifact-view",children:[n.jsx(eT,{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:[na[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:Gn(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(tT,{artifactId:e.artifactId,filename:e.filename,mime:e.mime})})]})}const e0=80,w6=["query","path","url","dir"],y6=["message","task"];function Gj(e,t){const s=b6(t);if(!s)return null;const r=Ia(s.command);if(r!==null){const l=Ia(s.name);return Fu(l===null?r:`${l}: ${r}`)}for(const l of w6){const o=Ia(s[l]);if(o!==null)return Fu(o)}const i=Ia(s.action);if(i!==null){const l=y6.map(o=>Ia(s[o])).find(o=>o!==null)??null;return Fu(l===null?i:`${i} · ${l}`)}const a=Object.values(s).filter(l=>typeof l=="string");return a.length===1?Fu(Ia(a[0])):null}function Ia(e){if(typeof e!="string")return null;const t=e.replace(/\s+/g," ").trim();return t===""?null:t}function Fu(e){return e===null?null:e.length>e0?`${e.slice(0,e0-1)}…`:e}function b6(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const nT="owner.notify",Er=e=>typeof e=="string"&&e.trim()!==""?e:null;function k6(e){const t=e!==null&&typeof e=="object"?e:{};return{title:Er(t.title)??"(no title)",text:Er(t.text),urgency:Er(t.urgency)??"now",key:Er(t.key),link:Er(t.link)}}function sT(e){if(e===null||typeof e!="object")return Er(e);const t=e;return Er(t.delivered)??Er(t.message)??Er(t.error)}function N6(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 Ci="agent.delegate";function S6(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 C6(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 rx="canvas.show",t0="canvas.clear",n0=12;function E6(e){return`sources:${e}`}function A6(e){return e.role==="user"&&(e.blocks??[]).some(t=>t.type==="text"&&t.text.trim()!=="")}function ol(e){return`${e.plugin}/${e.name}`}function T6(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;const t=e.diff;return typeof t=="string"&&t.trim()!==""}function $6({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=kA(o,ix(l.output)).props;c.target===null&&c.awaiting!==null&&i.push({...c.awaiting,at:a.at??null})}return i}function R6({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:E6(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){A6(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===rx){const S=P6(g.id,g.input,p.at??null);S&&c.push(S)}if(g.name===t0&&(c=[],h=null),g.name===Ci){const S=S6(g.input);S&&c.push({id:g.id,tool:Ci,title:"Delegation",renderer:"delegate",props:{...S,result:null},at:p.at??null,source:"delegate",substantial:!0})}continue}if(g.type!=="tool_result"||g.name===rx||g.name===t0)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:C6(g.ok?g.output:g.error??g.output),...g.ok&&nh(g.output).length>0?{files:nh(g.output)}:{}}},g.ok||(x.tone="critical");continue}const w=g.approval?lx(g):(s==null?void 0:s.get(g.toolUseId))??lx(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:ix(g.output)??null,ok:g.ok!==!1,...g.error===void 0?{}:{error:g.error},at:b});continue}if(j===nT){c.push({id:g.toolUseId,tool:j,title:"Message to you",renderer:"notify",props:{input:(v==null?void 0:v.input)??null,output:g.output??null,ok:g.ok!==!1},at:b,tone:g.ok===!1?"critical":void 0,source:"notify",substantial:!1});continue}const y=ix(g.output);if(g.ok===!1){c.push({id:g.toolUseId,tool:j,title:cr(j),renderer:"structured",props:{value:g.error??y??null,failed:!0},at:b,tone:"critical",source:"fallback",substantial:!1});continue}T6(y)&&(u+=1);const k=l.get(j);if(k){const S=kA(k,y),{renderer:C}=S;let{props:T}=S;if(C==="preview"){const R=T,I=R.target??(R.awaiting&&(i!=null&&i.has(ol(R.awaiting)))?R.awaiting:null);if(I===null)continue;T={...R,target:I,awaiting:null};const L=ol(I);c=c.filter(_=>!(_.source==="descriptor"&&_.renderer==="preview"&&_.props.target!==null&&ol(_.props.target)===L))}c.push({id:g.toolUseId,tool:j,title:k.title??cr(j),renderer:C,props:T,at:b,source:"descriptor",substantial:ax(C,T)});continue}const N={value:Hj(y)?{input:v==null?void 0:v.input,output:y}:y};M6("structured",N)&&c.push({id:g.toolUseId,tool:j,title:cr(j),renderer:"structured",props:N,at:b,source:"fallback",substantial:ax("structured",N)})}}for(const p of c)p.source==="descriptor"&&p.renderer==="preview"&&(p.props={...p.props,changes:u});return I6(c)}const s0="forAgent";function ix(e){if(e===null||typeof e!="object"||Array.isArray(e)||!(s0 in e))return e;const{[s0]:t,...s}=e;return s}function I6(e){if(e.length<=n0)return e;const t=e.length-n0;return[...e.slice(0,t).filter(r=>r.source==="approval"),...e.slice(t)]}function P6(e,t,s){if(t===null||typeof t!="object")return null;const{renderer:r,title:i,data:a}=t,l=typeof r=="string"&&lh(r)?r:"structured";return{id:e,tool:rx,title:typeof i=="string"&&i.trim()!==""?i:"Shown",renderer:l,props:l==="structured"&&!lh(String(r))?{value:a}:a,at:s,substantial:!0,source:"canvas"}}function M6(e,t){const s=t??{};return!!(s.failed===!0||ax(e,t)||Wj(s.value).kind==="error")}function ax(e,t){const s=t??{};switch(e){case"timeseries":return xo(s.points)>0;case"bars":return xo(s.bars)>0;case"keyvalue":return xo(s.pairs)>0;case"tiles":return s.notice!==!0&&xo(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=>xo(i.rows)>0);default:return Hj(s.value)?!0:s.failed===!0?!1:v3(s.value)}}function xo(e){return Array.isArray(e)?e.length:0}function lx(e){if(e.approval)return e.approval.state==="pending"?e.approval.id:null;for(const t of[e.error,e.output]){const s=iT(t,0);if(s)return s}return null}function D6(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)?rT(i.input):i.input;return{id:t,tool:i.name,title:cr(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 O6=new Set(["value","text","password","secret","code"]);function rT(e){if(e===null||typeof e!="object"||Array.isArray(e))return e;const t={};for(const[s,r]of Object.entries(e))t[s]=O6.has(s)&&typeof r=="string"?"— withheld —":rT(r);return t}function iT(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=iT(a,t+1);if(l)return l}return null}function cr(e){const t=e.split(".");return t.length===1?yn(e):t.map(s=>yn(s)).join(" · ")}function r0(e,t){return e.find(s=>s.source==="sources"&&s.props.entries.some(r=>r.id===t))??null}function wf({name:e,mime:t,sizeBytes:s,thumbnail:r,state:i,error:a,onOpen:l,onRemove:o,size:c="md"}){const u=Bj(t,e),h=[na[u],Gn(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(Yj,{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 Yj({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 L6(e,t,s){const r=a0(e),i=a0(t==null?void 0:t.input),a=Bi(r==null?void 0:r.name)??B6(Bi(r==null?void 0:r.handle))??Bi(r==null?void 0:r.agent)??Bi(i==null?void 0:i.agent),l=typeof e=="string"?e.trim()||null:Bi(r==null?void 0:r.text)??Bi(r==null?void 0:r.note),o=i0(r==null?void 0:r.durationMs)??i0(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:Bi(i==null?void 0:i.task),answer:l,files:nh(e),durationMs:o??h}}function F6(e,t){var r;let s=null;for(const i of e)for(const a of i.blocks??[])a.type==="tool_result"&&a.name===Ci&&((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 _6({block:e,messages:t,answeredAt:s}){const r=L6(e.output,F6(t,e.actionId),s),i=[r.who?`Asked ${r.who}`:null,r.durationMs===null?null:`took ${z6(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(mr,{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:Si(a.artifactId),download:!0,children:n.jsx(wf,{name:a.filename??"Untitled file",mime:a.mime,sizeBytes:a.sizeBytes,thumbnail:Uj(a.mime)?Gr(a.artifactId):null,size:"sm"})},a.artifactId))}):null,n.jsx(At,{summary:"Raw JSON",children:n.jsx("pre",{className:"wb-approval-output mono",children:U6(e.output)})})]})}function z6(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 U6(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function B6(e){return e===null?null:`@${e.replace(/^@/,"")}`}function Bi(e){return typeof e=="string"&&e.trim()!==""?e:null}function i0(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function a0(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const W6=1e3;function H6({messageId:e,text:t,onReadAloud:s}){const[r,i]=d.useState(!1),a=d.useRef(null),l=d.useSyncExternalStore(u6,c6)===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),W6)},()=>{})};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?Hl():s(e,t),children:n.jsx(ce,{name:l?"stop":"play",size:14})}):null]})}function K6(e){const t=V6(e);if(!t)return null;const s=Um(t.diff);if(s!==null)return{kind:"diff",diff:s};const r=Um(t.command),i=Um(t.plain),a=Bm(t.exitCode);return r!==null&&(i!==null||a!==null||Bm(t.pid)!==null)?{kind:"command",command:r,output:i,exitCode:a,elapsedMs:Bm(t.elapsedMs)}:null}function Um(e){return typeof e=="string"&&e.trim()!==""?e:null}function Bm(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function V6(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const l0="offer:",aT="owner:interjection";function G6(e){return e===aT}function Y6(e){if(typeof e!="string"||!e.startsWith(l0))return null;const t=e.slice(l0.length).trim();return t===""?null:t}const o0="brief:";function q6(e){if(typeof e!="string"||!e.startsWith(o0))return null;const t=e.slice(o0.length).trim();return t===""?null:t}function qj({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 F;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(lB)).map(lT),C=iB(S,w??[]),T=c??l??[],R=X=>(o&&!c?T.find(Q=>Q.id===o):void 0)??T.find(Q=>Q.name===X)??null,I=o?T.find(X=>X.id===o)??null:null,L=i||t.length>0,_=L||!!N,$=!!N&&a.text!=="",P=L&&!$,O=S.at(-1),M=(O==null?void 0:O.role)!=="assistant"||!!h,D=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=_&&!M?((F=H.at(-1))==null?void 0:F.id)??null:null,q=(w??[]).reduce((X,Q)=>X===null||(Q.startedAt??"")>(X.startedAt??"")?Q:X,null),W=(w??[]).some(X=>X.finishedAt===null),Y=y&&!_&&!W&&O&&(q==null?void 0:q.stopped)==="max_turns"&&C.get(O.id)===q?O.id:null;return n.jsx(wA.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",Oe=c&&ee==="room",Ie=c&&ee&&ee!=="owner"&&ee!=="room"?c.find(Se=>Se.id===ee)??null:null,Fe=S[Q-1],U=Q===0||(c?((Fe==null?void 0:Fe.speaker)??null)!==ee:Fe.role!==X.role);if(Oe)return n.jsx("div",{className:"wb-msg wb-msg-room","data-role":"room",children:(X.blocks??[]).filter(Se=>Se.type==="text").map((Se,Ue)=>n.jsx("span",{children:Se.text},Ue))},X.id);const se=(X.blocks??[]).filter(Se=>Se.type==="approval_result");if(se.length>0)return n.jsx("div",{className:"wb-msg","data-role":"assistant","data-testid":"approval-result",children:se.map((Se,Ue)=>n.jsx(oB,{block:Se,messages:e,at:X.at||null},Ue))},X.id);const J=X.role==="user"&&G6(ee),ye=X.role==="user"?q6(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"?Y6(ee):null;if(ge){const Se=(X.blocks??[]).filter(Ue=>Ue.type==="text").map(Ue=>Ue.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:Se,children:ge})},X.id)}const $e=c&&Ie&&X.role==="user"?tB(X):null;if($e){const Se=S.slice(Q+1).find(at=>at.role==="assistant"&&at.speaker&&at.speaker!==Ie.id),Ue=Se!=null&&Se.speaker?c.find(at=>at.id===Se.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 ",(Ue==null?void 0:Ue.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=rB(X,e),ze=!fe&&!J&&!j?sB(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(c0,{name:Ie?Ie.name:c&&ee&&ee!=="owner"&&ee!=="room"?ee:g??"Assistant",face:Ie??I??R(g),moving:P&&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(Se=>n.jsx("span",{role:"listitem",children:XA(Se.mime)?n.jsx(ZA,{artifactId:Se.artifactId,name:Se.filename??"Untitled file",mime:Se.mime,sizeBytes:Se.sizeBytes}):n.jsx(wf,{name:Se.filename??"Untitled file",mime:Se.mime,sizeBytes:Se.sizeBytes,thumbnail:Uj(Se.mime)?Gr(Se.artifactId):null,...f?{onOpen:()=>f(Se)}:{}})},Se.artifactId))}):null,(X.blocks??[]).map((Se,Ue)=>{const at=X6(X.blocks??[],Ue,e);if(at==="inside")return null;if(at)return n.jsx(Z6,{refusals:at.refusals},Ue);if(Se.type==="thinking")return j||Se.text.trim()===""?null:n.jsx(ox,{text:Se.text},Ue);if(Se.type==="text")return Se.text.trim()===""?null:fe?n.jsx("div",{className:"wb-bubble",children:Se.text},Ue):n.jsx("div",{className:"wb-bubble","data-rich":"true",children:n.jsx(mr,{text:Se.text})},Ue);if(Se.type==="attachment")return null;if(Se.type==="tool_use"){if(j)return null;const Ye=Jj(e,Se.id),kt=Ye?dB(Ye):null,qt=!kt&&Se.name===nT&&Ye?sT(Ye.output):null;return n.jsx(cx,{label:kt&&!(Ye!=null&&Ye.delegation)?`Approval · ${Se.name}`:cr(Se.name),tool:Se.name,ok:(Ye==null?void 0:Ye.ok)??null,running:Ye===null,...kt?{status:kt.status,waiting:kt.waiting,approval:!0}:qt?{status:qt}:{},gist:Gj(Se.name,Se.input),body:Ye?K6(Ye.output):null,opens:!0,onOpen:()=>r(Se.id)},Ue)}return null}),De?n.jsxs("div",{className:"wb-msg-budget","data-testid":"budget-stop",children:[n.jsx("span",{children:aB(De)}),Y===X.id?n.jsx(E,{size:"sm",className:"wb-msg-budget-continue","data-testid":"budget-continue",onClick:y,children:"Continue"}):null]}):null,X.feedback&&!fe&&!J?n.jsx(mB,{feedback:X.feedback}):null,ze!==""?n.jsx(H6,{messageId:X.id,text:ze,onReadAloud:m}):null]},X.id)}),_?n.jsxs("div",{className:"wb-msg","data-role":"assistant","data-testid":"live-turn",children:[M?n.jsx(c0,{name:D,face:R(D)??I,moving:P}):null,N&&a.thinking!==""&&!j?n.jsx(ox,{text:a.thinking,live:a.text==="",seconds:eB(a.thinkingStartedAt,a.textStartedAt??s)}):null,$?n.jsxs("div",{className:"wb-bubble","data-live":"true","data-rich":"true",children:[n.jsx(mr,{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(cx,{label:cr(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 c0({name:e,face:t,moving:s=!1,children:r}){const i=(t==null?void 0:t.picture)??null,a=xA(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(Vc,{state:"working",size:"sm",still:i,className:"wb-msg-blob"}):n.jsx(kn,{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 J6(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 Q6="delegation refused:";function X6(e,t,s){const r=a=>{const l=e[a];if(!l||l.type!=="tool_use"||l.name!==Ci)return null;const o=Jj(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(Q6))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 Z6({refusals:e}){const[t,s]=d.useState(!1),r=e.map(o=>J6(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:[cr(Ci)," · ",o.target]}),n.jsx("span",{className:"wb-tool-elapsed",children:"refused"})]}),n.jsx("p",{className:"wb-refusal-why",children:o.message})]},c))}):null]})}function eB(e,t){return e===null?null:Math.max(0,Math.round((t-e)/1e3))}function ox({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(mr,{text:e})}):null]})}function tB(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 lT(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+nB(a.text,i.text)+i.text},r=!0):s.push(i)}return r?{...e,blocks:s}:e}function nB(e,t){return e===""||t===""||/\s$/.test(e)||/^\s/.test(t)||/^[.,;:!?)\]}»”’'"]/.test(t)?"":/[.!?:…)"”»]$/.test(e)?`
97
-
98
- `:""}function sB(e){return(lT(e).blocks??[]).filter(t=>t.type==="text").map(t=>t.text.trim()).filter(t=>t!=="").join(`
99
-
100
- `)}function rB(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===Ci){const l=Jj(t,a.id);l!=null&&l.ok&&nh(l.output).forEach(i)}return s}function iB(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 aB(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 lB(e){return e.type==="text"||e.type==="thinking"?e.text.trim()!=="":e.type==="tool_use"||e.type==="attachment"||e.type==="approval_result"}function oB({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":cr(e.name)}),n.jsx("span",{className:"wb-tool-elapsed",children:e.state}),n.jsx(ce,{name:"arrow",className:"wb-tool-arrow"})]}),r&&e.name===Ci?n.jsx(_6,{block:e,messages:t,answeredAt:s}):null,r&&e.name!==Ci?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 uB=40;function dB(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(lx(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 cx({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(oc,{children:[n.jsx(cc,{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(uc,{children:n.jsxs(dc,{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(hB,{body:f,onOpen:a?l:null}):null]}):a?n.jsxs(oc,{children:[n.jsx(cc,{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(uc,{children:n.jsxs(dc,{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 hB({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(Xd,{text:e.diff,limit:uB,...s?{more:s}:{}})});const r=[e.exitCode===null?null:`exit ${e.exitCode}`,e.elapsedMs===null?null:fB(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 fB(e){return e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(1)}s`}function Jj(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 mB({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 oT="approval-dock";function pB(){var t;const e=document.getElementById(oT);e&&((t=e.scrollIntoView)==null||t.call(e,{block:"nearest"}),e.focus())}const gB=["workspace","cwd","workdir","root"];function xB({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(vB,{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 vB({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 T=!1;return A.approval(e.approvalId).then(R=>{T||(u(R),R.state!=="pending"&&a(R))}).catch(R=>{T||f(R instanceof ve?R.message:String(R))}),()=>{T=!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}=_j(c==null?void 0:c.choices),w=(T,R)=>{const I=g.trim();p(T),f(null),(j&&T==="approve"?A.decide(e.approvalId,T,R,j):A.decide(e.approvalId,T,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?Gj(c.tool,c.canonicalArgs)??wB(c.preview):null,S=c?jB(c):null;return n.jsxs("section",{id:oT,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?cr(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(ie,{message:h}),n.jsx("div",{className:"wb-dock-section",children:n.jsx("input",{className:"wb-dock-instead",value:g,onChange:T=>v(T.target.value),onKeyDown:T=>{T.key==="Enter"&&T.preventDefault()},placeholder:"Tell the agent what to do instead (optional)","aria-label":"Tell the agent what to do instead (optional)",disabled:m!==null})}),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(E,{variant:"ghost",size:"sm",disabled:y,onClick:()=>w("reject"),children:m==="reject"?"Rejecting…":"Reject"}),k?n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",size:"sm",disabled:y,onClick:()=>w("approve","conversation"),children:"Auto: this conversation"}),n.jsx(E,{size:"sm",disabled:y,onClick:()=>w("approve","always"),children:"Always: this agent"})]}):null,n.jsx(E,{variant:"good",size:"sm",disabled:y,onClick:()=>w("approve"),children:m==="approve"?"Approving…":k?"Allow once":"Approve"})]})]})}function jB(e){for(const t of[e.canonicalArgs,e.envelope])if(!(t===null||typeof t!="object"||Array.isArray(t)))for(const s of gB){const r=t[s];if(typeof r=="string"&&r.trim()!=="")return r.trim()}return null}function wB(e){const t=(e??"").split(`
101
- `).map(s=>s.trim()).find(Boolean);return t?t.length>160?`${t.slice(0,157)}…`:t:null}const yB=2e3;function bB({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(()=>He.conversation(e),[e,o,(i==null?void 0:i.approvalId)??null],u?yB: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)??kB(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(on,{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(ox,{text:N.text},S);if(N.type==="tool_use"){const C=SB(NB(x,N.id));return n.jsx(cx,{label:cr(N.name),tool:N.name,ok:C.ok,running:C.running,waiting:C.waiting,status:C.status,gist:Gj(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(mr,{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:Si(y.artifactId),download:!0,children:n.jsx(wf,{name:y.filename??"Untitled file",mime:y.mime,sizeBytes:y.sizeBytes,thumbnail:Uj(y.mime)?Gr(y.artifactId):null})},y.artifactId))}):null,n.jsxs("div",{className:"wb-delegate-actions",children:[v==="waiting"?n.jsx(E,{variant:"accent",onClick:()=>pB(),"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 kB(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 NB(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 SB(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 u0=1024*1024;function CB({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(EB,{files:e,agentId:t,root:s,path:i.path,revision:r,go:a}):n.jsx(AB,{files:e,agentId:t,root:s,path:i.path,revision:r,go:a})})}function cT({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 EB({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),A.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(A.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(cT,{root:s,path:r,go:a}),n.jsx(dt,{}),n.jsx(E,{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:Kr,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($B,{kind:b.kind}),title:n.jsxs("span",{className:"mono",children:[b.name,b.kind==="dir"?"/":""]}),side:b.kind==="file"?Gn(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 AB({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),A.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?A.pageFileUrl(e.plugin,e.read,{agent:t,path:r,v:p}):"",v=A.pageFileUrl(e.plugin,e.read,{agent:t,path:r,download:"1"}),b=(m==null?void 0:m.type)==="text"&&m.bytes<=u0;return n.jsxs(n.Fragment,{children:[n.jsxs(ae,{children:[n.jsx(cT,{root:s,path:r,go:a}),n.jsx(dt,{}),b?n.jsx(E,{size:"sm","aria-pressed":h,onClick:()=>f(j=>!j),children:"Wrap"}):null,n.jsx(Et,{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(TB,{src:g,wrap:h}):n.jsxs(n.Fragment,{children:[n.jsx(V,{children:m.type==="text"?`This file is over ${Gn(u0)}, 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:Gn(m.bytes)},{label:"Type",value:n.jsx("span",{className:"mono",children:m.mime})}]})]})]})}function TB({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 $B({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 RB({input:e,output:t,ok:s}){const r=k6(e),i=sT(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:N6(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(At,{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 So=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)?e:{},Dt=e=>typeof e=="string"&&e.trim()!==""?e:null,IB={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 PB(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 Wm(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function MB(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 ux(e){try{const t=new URL(e);return`${t.hostname.replace(/^www\./,"")}${t.pathname.replace(/\/+$/,"")}${t.search}`}catch{return e}}function d0(e){var t;return((t=e.match(/[\p{L}\p{N}]/u))==null?void 0:t[0])??"?"}function uT(e){const t=So(e.input),s=So(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=Dt(e.error)??Dt(So(e.error).message);if(Array.isArray(s.results)||Dt(t.query)&&!Dt(t.url)){const f=(Array.isArray(s.results)?s.results:[]).map(p=>So(p)).flatMap(p=>{const g=Dt(p.url);return g?[{title:Dt(p.title)??Wm(g),url:g,host:Dt(p.source)??Wm(g),snippet:Dt(p.snippet)}]:[]}),m=s.available===!1;return{kind:"search",id:e.id,raw:r,query:Dt(s.query)??Dt(t.query)??"",state:e.ok===null?"pending":i||m?"failed":"ok",provider:Dt(s.provider),results:f,why:i?`The search failed${a?`: ${a}`:"."}`:m?Dt(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=Dt(s.url)??Dt(t.url)??"",o=!i&&s.ok!==!1&&PB(Dt(s.text)??""),c=i||s.ok===!1||o,u=o?"unreadable":Dt(s.problem),h=Dt(s.message);return{kind:"page",id:e.id,url:l,raw:r,host:Dt(s.source)??Wm(l),state:e.ok===null?"pending":c?"failed":"ok",title:Dt(s.title),text:o?null:Dt(s.text),truncated:s.truncated===!0,retrievedAt:Dt(s.retrievedAt)??e.at,why:c?(u&&IB[u])??(h?h.charAt(0).toUpperCase()+h.slice(1)+(/[.!?]$/.test(h)?"":"."):null)??`The read failed${a?`: ${a}`:"."}`:null}}function DB(e){const t=e.entries.map(uT),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 OB(e){return e.split(/\s+/).filter(Boolean).length}function LB(e){return e>=1e3?`${(e/1e3).toFixed(1).replace(/\.0$/,"")}k words`:`${e} ${e===1?"word":"words"}`}function FB(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 dT({url:e,className:t,children:s}){const r=MB(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 hT({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 _B({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:d0(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?OB(e.text):0,h=FB(e.retrievedAt,s),f=[e.host,h?`read ${h}`:null,u?LB(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?"!":d0(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(dT,{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(hT,{value:e.raw})]})]}):null]})}const h0=3;function zB({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,h0),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(hT,{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(dT,{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(ux(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>h0?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 UB({entries:e,focus:t,timezone:s}){const r=e.map(uT),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=Dt(So(c==null?void 0:c.input).url);return[ux(o.url),...u?[ux(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(_B,{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(zB,{search:o,read:l,focused:t===o.id},o.id))]}):null]})}const BB=3,WB=152,HB=104,KB=100,VB=2,f0=5;function GB({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]=YB(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:ZB(u,e5(o??[],c??[]))})]})})]});const j=e.some(y=>y.id===t)?t:e[e.length-1].id,{shown:x,hidden:w}=qB(e,j,b);return n.jsx("div",{className:"wb-canvas","data-testid":"canvas",children:n.jsxs(s4,{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(r4,{className:"wb-tabstrip","aria-label":"Canvas",children:x.map(y=>n.jsxs("div",{className:"wb-tab-item",children:[n.jsxs(i4,{value:y.id,className:"wb-tab","data-tone":y.tone,onKeyDown:k=>{k.key==="Delete"&&p&&m0(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&&m0(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(JB,{items:w,onActivate:s,timezone:r})]}),e.map(y=>n.jsx(a4,{value:y.id,className:"wb-canvas-body","data-renderer":y.source==="descriptor"&&y.renderer==="preview"?"preview":void 0,"data-dense":n5.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"?DB(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(G3,{...y.props,...a?{onChange:a}:{}}):y.source==="artifact"?n.jsx(j6,{...y.props}):y.source==="files"?n.jsx(CB,{...y.props}):y.source==="sources"?n.jsx(UB,{...y.props,timezone:r}):y.source==="notify"?n.jsx(RB,{...y.props}):y.source==="delegate"?n.jsx(bB,{...y.props,agents:m??[]}):n.jsx(V3,{renderer:y.renderer,props:y.props,timezone:r,onDecided:i})]})},y.id))]})})}function m0(e){return e.source==="approval"?!1:e.source==="browser"?e.pinned!==!0:e.source!=="files"}function YB(e){const[t,s]=d.useState(f0),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-KB-HB)/WB);s(Math.max(VB,Math.min(f0,u)))};l(),r.current=new ResizeObserver(l),r.current.observe(a)},[e]),e??t]}function qB(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 JB({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(_c,{modal:!1,children:[n.jsx(zc,{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(zl,{children:n.jsxs(Uc,{className:"ui-menu","data-wide":"true",align:"end",sideOffset:6,children:[n.jsx(da,{className:"ui-menu-label",children:"Earlier in this conversation"}),[...e].reverse().map(i=>n.jsxs(vs,{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:QB(i.at,s)??i.tool})]},i.id))]})})]})}function QB(e,t){if(!e)return null;const s=new Date(e);return Number.isNaN(s.getTime())?null:zt(s,t)}const XB={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 ZB(e,t){const s=e?`What ${e} shows you`:"What your agent shows you",r=[...new Set(t.map(i=>XB[i.renderer]??"results"))].slice(0,3);return r.length>0?`${s} lands here: ${r.join(", ")}.`:`${s} lands here.`}function e5(e,t){const s=new Set(t),r=new Set,i=e.filter(c=>{if(!s.has(c.tool))return!1;const u=t5(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,BB)}function t5(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 n5=new Set(["table","diff","files"]),s5=3.5*6e4,r5=2e3;function i5(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??A.previewCheck,o=s.everyMs??r5,c=e.map(u=>`${ol(u)}@${u.at??""}`).join("|");return d.useEffect(()=>{const u=new Map;for(const p of e){const g=ol(p);if(a.current.has(g))continue;const v=p.at===null?Number.NaN:Date.parse(p.at),b=Number.isNaN(v)?0:v+s5,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 dx="workspace-files";function a5(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 l5(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 A.pages();for(const l of Array.isArray(i==null?void 0:i.files)?i.files:[]){const o=await A.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 o5(e,t){return{id:dx,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 hx(e){return`agent-properties:${e}`}function c5(e){return{id:hx(e.id),tool:`@${e.handle}`,title:"Properties",renderer:"profile",props:{profile:e},at:null,source:"profile",substantial:!1}}function u5(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 fT({progress:e}){return n.jsxs(le,{gap:"sm",children:[n.jsx("span",{role:"status",children:u5(e)}),n.jsx($A,{value:(e==null?void 0:e.percent)??0,label:"Fetching the browser"})]})}function d5(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 Hm(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}function p0(e){return[...e].length===1&&e.codePointAt(0)>=32&&e.codePointAt(0)!==127}const h5=4e3;function f5(e){return e.replace(/\r\n?/g,`
106
- `).replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g,"").slice(0,h5)}const m5=["left","middle","right"],p5=33;function g5(e,t){return e.deviceWidth===t.deviceWidth&&e.deviceHeight===t.deviceHeight&&e.pageScaleFactor===t.pageScaleFactor&&e.offsetTop===t.offsetTop}function x5(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 v5(e=window.location){return`${e.protocol==="https:"?"wss":"ws"}://${e.host}/api/browser/hand`}function j5({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 $=r??(M=>new WebSocket(M));let P=!0,O;try{O=$(v5())}catch{a("lost");return}return O.binaryType="arraybuffer",b.current=O,O.onopen=()=>O.send(JSON.stringify({type:"hello",csrf:t,sessionId:e})),O.onmessage=M=>{if(!P)return;if(typeof M.data!="string"){const H=x5(M.data);if(!H||(f(B=>B&&g5(B,H.metadata)?B:H.metadata),u(!0),typeof createImageBitmap!="function"))return;createImageBitmap(H.jpeg).then(B=>{var W,Y,F;const q=j.current;if(!P||!q){(W=B.close)==null||W.call(B);return}(q.width!==B.width||q.height!==B.height)&&(q.width=B.width,q.height=B.height),(Y=q.getContext("2d"))==null||Y.drawImage(B,0,0),(F=B.close)==null||F.call(B)}).catch(()=>{});return}const D=JSON.parse(M.data);if(D.type==="driving"){a("driving"),o(null);return}(D.type==="refused"||D.type==="ended")&&(o(D.error??"The screen cannot be driven from here."),a("refused"))},O.onclose=()=>{P&&a(M=>M==="refused"?M:"lost")},O.onerror=()=>{P&&a(M=>M==="refused"?M:"lost")},()=>{P=!1,b.current=null;try{O.close()}catch{}}},[e,t,g,r]),d.useEffect(()=>()=>{clearTimeout(w.current.timer)},[]);const y=d.useCallback($=>{const P=b.current;if(P)try{P.send(JSON.stringify({type:"input",input:$}))}catch{}},[]),k=$=>{var M;const P=j.current;if(!P||!h)return null;const O=(M=P.getBoundingClientRect)==null?void 0:M.call(P);return O?d5(O,h,$.clientX,$.clientY):null},N=$=>{const P=w.current,O=Date.now();clearTimeout(P.timer),P.timer=void 0;const M=P.at+p5-O;if(M<=0){P.at=O,P.pending=void 0,y($);return}P.pending=$,P.timer=setTimeout(()=>{const D=w.current.pending;w.current.timer=void 0,w.current.pending=void 0,w.current.at=Date.now(),D&&y(D)},M)},S=()=>{const $=w.current;clearTimeout($.timer),$.timer=void 0;const P=$.pending;$.pending=void 0,P&&($.at=Date.now(),y(P))},C=$=>P=>{var D,H;const O=k(P);if(!O)return;$==="mousePressed"&&(P.preventDefault(),(H=(D=j.current)==null?void 0:D.focus)==null||H.call(D));const M={kind:"mouse",type:$,x:O.x,y:O.y,button:m5[P.button]??"left",clickCount:$==="mouseMoved"?0:Math.min(3,Math.max(1,P.detail||1)),modifiers:Hm(P)};if($==="mouseMoved"){N(M);return}S(),y(M)},T=$=>{const P=k($);P&&(S(),y({kind:"wheel",x:P.x,y:P.y,deltaX:Math.round($.deltaX),deltaY:Math.round($.deltaY)}))},R=$=>$.ctrlKey||$.metaKey||$.altKey,I=$=>{var O,M;if($.key==="Escape"&&R($)){p(!1),(M=(O=$.target).blur)==null||M.call(O);return}if($.preventDefault(),($.metaKey||$.ctrlKey)&&($.key==="v"||$.key==="V"))return;const P=Hm($);if(p0($.key)&&!R($)){y({kind:"key",type:"char",key:$.key,code:$.code,text:$.key,modifiers:P});return}y({kind:"key",type:"keyDown",key:$.key,code:$.code,modifiers:P})},L=$=>{$.key==="Escape"&&R($)||($.preventDefault(),!(($.metaKey||$.ctrlKey)&&($.key==="v"||$.key==="V"))&&(p0($.key)&&!R($)||y({kind:"key",type:"keyUp",key:$.key,code:$.code,modifiers:Hm($)})))},_=$=>{var O;$.preventDefault();const P=f5(((O=$.clipboardData)==null?void 0:O.getData("text/plain"))??"");P!==""&&y({kind:"text",text:P})};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(E,{size:"sm",variant:m?"accent":"ghost","aria-pressed":m,onClick:()=>{var P,O,M,D;const $=!m;p($),$?(O=(P=x.current)==null?void 0:P.focus)==null||O.call(P):(D=(M=x.current)==null?void 0:M.blur)==null||D.call(M)},children:"Keyboard"}),n.jsx(E,{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(E,{size:"sm",variant:"accent",onClick:()=>{a("connecting"),v($=>$+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:T,onKeyDown:I,onKeyUp:L,onPaste:_,onContextMenu:$=>$.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:_,onBlur:()=>p(!1)})]})}function w5(e){return e==="darwin"?"this Mac":"this computer"}let Km=null;function yf(){const[e,t]=d.useState(void 0);return d.useEffect(()=>{let s=!0;return Km??(Km=A.session().then(r=>r.platform,()=>{Km=null})),Km.then(r=>{s&&t(r)}),()=>{s=!1}},[]),w5(e)}function y5({embedded:e,timezone:t}={}){var c;const{data:s,error:r,reload:i}=de(()=>A.browser(),[],3e3),a=de(()=>A.session(),[]),l=(c=a.data)!=null&&c.platform?a.data.platform==="darwin":!0,o=!!a.data||!!a.error;return n.jsxs(Mn,{embedded:e,title:"Computer & browser",children:[n.jsx(ie,{message:r}),!s||!o?n.jsx(pe,{children:"Checking the host…"}):n.jsx(b5,{data:s,macOS:l,reload:i,timezone:t},JSON.stringify(s.settings??null))]})}function b5({data:e,macOS:t,reload:s,timezone:r}){var S,C,T;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=(S=e.sessions)!=null&&S.length?e.sessions:e.session?[e]:[],g=p.length>0||e.busy,v=async R=>{a(!0),o(null);try{await R()}catch(I){o(I instanceof Error?I.message:String(I))}finally{a(!1),s()}},b=R=>void v(()=>A.browserSettings(R)),j=e.permissions,x=f==="playwright"?e.browser:void 0,w=((C=x==null?void 0:x.install)==null?void 0:C.state)==="running",y=(x==null?void 0:x.engine)==="none",k=!!e.enabled&&!y&&!(x!=null&&x.problem)&&(!m||!(j!=null&&j.supported)||j.accessibility&&j.screenRecording),N=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(ie,{message:l}),n.jsx(ue,{title:"Status",panel:!0,actions:n.jsxs(n.Fragment,{children:[n.jsx(E,{size:"sm",disabled:i,onClick:()=>void v(()=>A.computerPermissions(!1)),children:"Check again"}),m&&!k&&(j!=null&&j.supported)?n.jsx(E,{size:"sm",variant:"accent",disabled:i||g,onClick:()=>void v(()=>A.computerPermissions(!0)),children:"Request macOS permissions"}):null,y||w?n.jsx(E,{size:"sm",variant:"accent",disabled:i||w,onClick:()=>void v(()=>A.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}):k?n.jsx(V,{tone:"good",children:N}):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?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:null,((T=x==null?void 0:x.install)==null?void 0:T.state)==="running"?n.jsx(fT,{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&&(j!=null&&j.message)?n.jsx("p",{className:"muted",children:j.message}):null,m&&(j!=null&&j.supported)&&!k?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(E,{variant:"danger",size:"sm",disabled:i,onClick:()=>void v(()=>A.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(R=>n.jsxs("a",{className:"ui-list-row",href:st(R.session.agentId,R.session.conversationId),children:[n.jsx(kn,{id:R.session.agentId,name:R.session.agentId,size:"sm"}),n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title",children:R.session.task}),n.jsxs("span",{className:"ui-list-sub",children:[R.session.agentId,", ",R.busy?"working":R.state,", ",R.session.steps," of ",R.session.maxSteps," steps"]})]}),n.jsx("span",{className:"ui-list-side",children:"Open the Canvas"})]},R.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(Vm,{current:h.mode,value:"computer",disabled:i||g||!e.enabled,title:"Use my apps",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(Vm,{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(Vm,{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(R5,{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(I5,{settings:h,disabled:i||g||!e.enabled,onChange:b,onAdd:()=>u(!0)}),n.jsx(At,{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(L5,{chosen:h.allowedApps,onClose:()=>u(!1),onPick:R=>{u(!1),h.allowedApps.includes(R)||b({...h,allowedApps:[...h.allowedApps,R]})}}):null]}):null]})}const k5="kmbckpnnjfggeffkkbmkggojnolkdokb",N5="pbfpjefkiijjgefblpnlnlpmeaddfbah",S5="https://chromewebstore.google.com/detail/pbfpjefkiijjgefblpnlnlpmeaddfbah",C5=[k5,N5].filter(Boolean);function E5(e){const t=/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?/.exec(e.trim());if(!t)return e;const s=t[4]?/^pre\.(\d+)$/.exec(t[4]):null;return[t[1],t[2],t[3],...s?[s[1]]:[]].map(Number).join(".")}async function A5(){var e;try{if(typeof chrome>"u"||!((e=chrome==null?void 0:chrome.runtime)!=null&&e.sendMessage))return null;for(const t of C5)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 T5(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 $5(e){try{return new URL(e).origin===window.location.origin}catch{return!1}}function R5({busy:e,timezone:t}){const{data:s,error:r,reload:i}=de(()=>A.extension(),[],3e3),a=yf(),l=de(()=>A5(),[],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=T5(),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(dt,{}),n.jsx(Et,{variant:"accent",href:S5,target:"_blank",rel:"noopener noreferrer",children:"Add to Chrome"})]}),n.jsx(At,{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(ie,{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.buddi)&&E5(s.buddi)!==l.version?n.jsx("p",{className:"muted",children:`buddi is ${s.buddi}; the extension is ${l.version}. Update it from chrome://extensions or the store.`}):null,l&&!$5(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(dt,{}),n.jsx(E,{variant:"accent",disabled:v||o.replace(/[^0-9]/g,"").length!==6,onClick:()=>void g(async()=>{await A.pairExtension(o),c("")}),children:"Pair"})]}):null,x?s!=null&&s.connected?n.jsx(At,{summary:"Pair a different browser",children:x}):x:null,n.jsx(ae,{align:"end",children:n.jsx(E,{variant:"danger",disabled:v||!(s!=null&&s.pairedAt),onClick:()=>void g(()=>A.forgetExtension()),children:"Forget this browser"})})]})}function Vm({current:e,value:t,title:s,body:r,disabled:i,onPick:a}){const l=e===t;return n.jsxs("button",{type:"button",role:"radio","aria-checked":l,className:"mode-option",disabled:i,onClick:()=>{l||a()},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})]})]})}function I5({settings:e,disabled:t,onChange:s,onAdd:r}){const i=de(()=>A.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(kn,{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&&O5(l)?n.jsx(E,{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(E,{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(E,{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"&&P5.includes(e.browserApp)?n.jsx(M5,{settings:e,disabled:t,onChange:s}):null]})}const P5=["com.google.Chrome","org.chromium.Chromium","com.microsoft.edgemac","com.brave.Browser"];function M5({settings:e,disabled:t,onChange:s}){var l;const i=((l=de(()=>A.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 D5=["com.google.Chrome","com.apple.Safari","org.chromium.Chromium","com.microsoft.edgemac","com.brave.Browser","org.mozilla.firefox","company.thebrowser.Browser"];function O5(e){return D5.includes(e)}function L5({chosen:e,onClose:t,onPick:s}){const r=de(()=>A.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(qe,{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(ie,{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(kn,{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(E,{size:"sm",disabled:h,onClick:()=>s(u.id),children:h?"Allowed":"Allow"})]},u.id)})}):n.jsx(pe,{children:"Reading your Applications folder…"}),n.jsx(At,{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(E,{disabled:!l.trim(),onClick:()=>s(l.trim()),children:"Allow this identifier"})]})})]})}function F5({data:e,error:t,reload:s,compact:r=!1,refresh:i,screenshotSrc:a,onScreenshotError:l,onScreenshotLoad:o,controls:c=!0}){var _,$,P;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=yf(),y=async O=>{h(!0),m(null),b(null),x(!1);try{const M=O!=="stop"&&(e!=null&&e.session)?await A.browserControl(O,e.session.id):await A.browserControl(O);O==="takeover"?M.hand&&M.session?g(M.session.id):M.handReason==="browser-offline"?x(!0):b(M.handMessage??null):g(null)}catch(M){m(M instanceof Error?M.message:String(M))}finally{h(!1),s()}},k=async()=>{if(e!=null&&e.settings){h(!0),m(null);try{e.session&&await A.browserControl("release",e.session.id),await A.browserSettings({...e.settings,mode:"playwright"}),x(!1),g(null),b("Switched to buddi’s browser. Send the agent a message and it opens the page there.")}catch(O){m(O instanceof Error?O.message:String(O))}finally{h(!1),s()}}},N=p&&((_=e==null?void 0:e.session)==null?void 0:_.id)===p&&e.state==="paused"?p:null,S=!!(e!=null&&e.enabled)&&!u,C=(e==null?void 0:e.mode)==="computer",T=(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":T?"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.":T?"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(ie,{message:t??f}),c?n.jsxs(ae,{children:[n.jsx(E,{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(E,{disabled:!S||!(e!=null&&e.session)||(e==null?void 0:e.state)==="paused",onClick:()=>void y("takeover"),children:"Take over"}),n.jsx(E,{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(E,{disabled:!S||!(e!=null&&e.session),onClick:()=>void y("release"),children:C?"Release control":"Close & release"})]}):null,c?r?n.jsx(At,{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&&T?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(E,{size:"sm",disabled:u,onClick:()=>void k(),children:"Switch to buddi’s browser"}):null,n.jsx(E,{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&&T)?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(j5,{sessionId:N,csrf:ga(),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:(($=e==null?void 0:e.page)==null?void 0:$.url)??(C?"Waiting for an application":"Waiting for a website")})]}),e!=null&&e.hasScreenshot&&e.page?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."})]})]}),(((P=e==null?void 0:e.page)==null?void 0:P.tabs.length)??0)>1?n.jsx(At,{summary:`${e.page.tabs.length} open tabs`,children:n.jsx("ul",{className:"ui-prose",children:e.page.tabs.map(O=>n.jsxs("li",{children:[O.title||O.id," — ",O.url]},O.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 _5=2e3,z5=5;function U5(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 B5({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>=z5;d.useEffect(()=>{if(!i||h)return;const y=window.setInterval(()=>{typeof document<"u"&&document.hidden||o(k=>k+1)},_5);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?U5(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(F5,{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(W5,{steps:r,newestId:(x==null?void 0:x.id)??null,focusedId:a??null,live:i})]})}function W5({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 H5({agentId:e,conversationId:t}){const{data:s,error:r,reload:i}=de(()=>A.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(At,{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(ie,{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(E,{size:"sm",disabled:o,onClick:()=>void u(()=>A.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(E,{size:"sm",variant:"danger",disabled:o,onClick:()=>void u(()=>A.stopHost(p.agentId,p.conversationId)),children:"Stop command"})})]},p.actionId))]})})}const mT="browser.act",K5="browser.status",pd=new Set([mT,K5]);function V5(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 G5(e,t){return{...e,title:`${t==="computer"?"Computer":"Browser"} (ended)`,pinned:!1}}function Y5(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===mT){const o={id:a.id,action:q5(a.input)??"act",target:J5(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:Q5(a)}}return t}function g0(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=pd.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 q5(e){if(e===null||typeof e!="object")return null;const t=e.action;return typeof t=="string"&&t!==""?t:null}function J5(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 Q5(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 X5="web.read",Z5="web.search",e8=new Set([X5,Z5]);function t8({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?He.groupConversations(t):He.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?Vi(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 pT="buddi.dismissedTabs";function n8(){try{const e=JSON.parse(sessionStorage.getItem(pT)??"{}");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 x0(e){try{sessionStorage.setItem(pT,JSON.stringify(Object.fromEntries(Object.entries(e).slice(-100))))}catch{}}const s8=350,r8=60;function i8({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 i6(k=>{var N;return(N=f.current)==null?void 0:N.call(f,k)})}catch(k){h.current=null,l("idle"),m.current.onNotice(r6(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),t6),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 He.attach(k),S=m.current.conversationId,C=await He.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>=s8&&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 a8({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 l8({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(o8,{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 o8({sink:e,frozen:t}){const[s,r]=d.useState(()=>Array(r8).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.",_u="The tab could not be captured. Try again, and pick the tab itself rather than the whole screen.",u8=e=>e instanceof Error&&(e.name==="NotAllowedError"||e.name==="AbortError");async function d8(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(u8(i))return null;throw new Error(_u)}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(_u))}),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(_u);o.drawImage(a,0,0);const c=await new Promise(h=>l.toBlob(h,"image/png"));if(!c)throw new Error(_u);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 v0="Send files once the agent has answered.",fx="wb-composer-input",Qj=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)),[T,R]=d.useState([]),[I,L]=d.useState(!1),[_,$]=d.useState(null),[P,O]=d.useState(!1),M=d.useRef(null),D=d.useRef(null),[H,B]=d.useState(null),[q,W]=d.useState(0),Y=H&&m?m.filter(Z=>Z.handle.toLowerCase().startsWith(H.query.toLowerCase())||Z.name.toLowerCase().startsWith(H.query.toLowerCase())).slice(0,6):[],F=(Z,Re)=>{if(!m||m.length===0){B(null);return}const Xe=Z.slice(0,Re),xt=/(^|\s)@([\w-]*)$/.exec(Xe);if(!xt){B(null);return}B({start:Re-xt[2].length-1,query:xt[2]}),W(0)},X=Z=>{if(!H)return;const Re=D.current,Xe=Re?Re.selectionStart:S.length,xt=`${S.slice(0,H.start)}@${Z} ${S.slice(Xe)}`;C(xt),ee<0&&Fe(xt),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),Oe=d.useRef(S),Ie=d.useRef(k);if(Ie.current!==k){Ie.current=k;const Z=N(k);Oe.current=Z,Z!==S&&(C(Z),fe(-1),B(null))}const Fe=Z=>{if(Oe.current=Z,!!k)try{Z===""?window.localStorage.removeItem(k):window.localStorage.setItem(k,Z)}catch{}},U=Z=>{C(Z),B(null);const Re=D.current;Re&&(Re.value=Z,Re.setSelectionRange(Z.length,Z.length)),window.requestAnimationFrame(kt)},se=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(Oe.current))},ge=T.some(Z=>Z.state==="uploading"),$e=T.length>0,De=s&&$e,Je=!t&&!ge&&!De&&S.trim()!=="",ze=Z=>{for(const Re of Array.from(Z??[])){const Xe=`${Re.name}:${Re.size}:${Math.random().toString(36).slice(2,8)}`,xt=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:xt,state:"uploading"}]),He.attach(Re).then(G=>R(he=>he.map(Be=>Be.key===Xe?{...Be,state:"ready",uploaded:G}:Be))).catch(G=>R(he=>he.map(Be=>Be.key===Xe?{...Be,state:"failed",error:G instanceof ve?G.message:String(G)}:Be)))}},Se=Z=>{Z.thumbnail&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(Z.thumbnail)},Ue=Z=>{const Re=T.find(Xe=>Xe.key===Z);Re&&(Se(Re),Re.state==="ready"&&Re.uploaded&&He.discardAttachment(Re.uploaded.artifactId).catch(()=>{})),R(Xe=>Xe.filter(xt=>xt.key!==Z))};d.useImperativeHandle(y,()=>({addFiles:Z=>{var Re;ze(Z),(Re=D.current)==null||Re.focus()},focus:()=>{var Z;return(Z=D.current)==null?void 0:Z.focus()}}));const at=d.useRef(T);at.current=T,d.useEffect(()=>()=>at.current.forEach(Se),[]);const Ye=d.useRef(0);d.useEffect(()=>{if(!l||l.at===Ye.current)return;Ye.current=l.at,C(Re=>Re.trim()===""?l.text:Re),ee<0&&S.trim()===""&&Fe(l.text);const Z=D.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=D.current;Z&&(Z.style.height="auto",Z.style.height=`${Math.min(Z.scrollHeight,200)}px`)},qt=Z=>{const Re=(Z??S).trim();if(Z===void 0?!Je:t||ge||De||Re==="")return;const Xe=T.filter(xt=>xt.state==="ready"&&xt.uploaded).map(xt=>xt.uploaded);r(Re,Xe),T.forEach(Se),fe(-1),Fe(""),C(""),R([]),window.requestAnimationFrame(kt)},re=Z=>{if(H&&Y.length>0){if(Z.key==="ArrowDown"){Z.preventDefault(),W(Re=>(Re+1)%Y.length);return}if(Z.key==="ArrowUp"){Z.preventDefault(),W(Re=>(Re-1+Y.length)%Y.length);return}if(Z.key==="Enter"||Z.key==="Tab"){Z.preventDefault(),X(Y[q].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&&se(Re)&&J()){Z.preventDefault(),ee<0&&(Oe.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(),qt())},be=Z=>{var Xe;const Re=Array.from(((Xe=Z.clipboardData)==null?void 0:Xe.files)??[]);Re.length!==0&&(Z.preventDefault(),ze(Re))},Qe=T.filter(Z=>Z.state==="failed"),ct=Qe.length,yt=i8({conversationId:v??null,onNotice:$,onText:(Z,Re)=>{const Xe=S.trim()===""?Z:`${S.replace(/\s+$/,"")} ${Z}`;if(Re){qt(Xe);return}U(Xe),ee<0&&Fe(Xe)}}),ut=yt.state!=="idle",pn=d.useRef(!1);return d.useEffect(()=>{var Z;pn.current&&!ut&&((Z=D.current)==null||Z.focus(),window.requestAnimationFrame(kt)),pn.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":P||ut,"data-disabled":t,"data-listening":ut||void 0,children:[T.length>0?n.jsx("div",{className:"wb-composer-files",role:"list","aria-label":"Files to send",children:T.map(Z=>n.jsx("span",{role:"listitem",children:n.jsx(wf,{name:Z.filename,mime:Z.mime,sizeBytes:Z.sizeBytes,thumbnail:Z.thumbnail,state:Z.state,error:Z.error,onRemove:()=>Ue(Z.key),...f&&Z.state==="ready"&&Z.uploaded?{onOpen:()=>f(h8(Z.uploaded))}:{},size:"sm"})},Z.key))}):null,n.jsxs("label",{className:"sr-only",htmlFor:fx,children:["Message ",a]}),n.jsx("textarea",{id:fx,ref:D,value:S,rows:w?1:2,placeholder:s?`${a} is working…`:x??`Message ${a}`,onChange:Z=>{C(Z.target.value),ee<0&&Fe(Z.target.value),F(Z.target.value,Z.target.selectionStart??Z.target.value.length),kt()},onFocus:()=>O(!0),onBlur:()=>O(!1),onKeyDown:re,onPaste:be,disabled:t,hidden:ut}),ut?n.jsx(l8,{voice:yt}):null,!ut&&H&&Y.length>0?n.jsx("div",{className:"wb-mentions",role:"listbox","aria-label":"Members",children:Y.map((Z,Re)=>n.jsxs("button",{type:"button",role:"option","aria-selected":Re===q,className:"wb-mention","data-active":Re===q||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:M,type:"file",multiple:!0,hidden:!0,"data-testid":"file-input",onChange:Z=>{ze(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=M.current)==null?void 0:Z.click()},disabled:t,children:n.jsx(ce,{name:"clip"})}),n.jsx(a8,{disabled:t,voice:yt}),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:()=>{$(null),L(!0),d8().then(Z=>{var Re;Z&&(ze([Z]),(Re=D.current)==null||Re.focus())}).catch(Z=>$(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":zu(u),disabled:t||s,title:s?`Wait for ${a} to finish — this run started with thinking ${zu(u)?"on":"off"}`:zu(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(zu(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||_!==null,"data-tone":ct>0||_!==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`:_!==null?_:De?v0:"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?v0:ge?"Waiting for the upload to finish":s?`Send — ${a} picks it up between steps`:"Send",onClick:()=>qt(),disabled:!Je,children:n.jsx(ce,{name:"send"})})]})]})})});function zu(e){return(e??"on")==="on"}function h8(e){return{type:"attachment",artifactId:e.artifactId,filename:e.filename,mime:e.mime,kind:e.kind,sizeBytes:e.sizeBytes}}function f8({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(E,{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:m8(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 m8(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 p8(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 g8(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 x8(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 ${g8(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(p8(t,r))return{text:`${o} · your next message starts a fresh one`,title:l,tone:"note"};const c=s?Le(s,r):"";return{text:c===""?o:`${o} · started ${c}`,title:s?`Started ${nt(s,i)}. ${l}`:l,tone:"quiet"}}function v8({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(At,{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(E,{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 gT(e){return e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function xT(e,t){return e.members.map(s=>t.find(r=>r.id===s)).filter(s=>s!==void 0)}function j8(e,t){var i;const s=xT(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 w8(){return n.jsx("span",{className:"ui-avatar group-gone-face","aria-hidden":"true",children:"?"})}function y8({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=Ij(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 He.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(qe,{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(on,{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(E,{size:"sm",disabled:i,onClick:()=>void m({coordinator:g}),children:"Make coordinator"}):null,n.jsx(Di,{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=St(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(w8,{}),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(E,{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(on,{agents:t,id:g.id,size:"sm"}),title:g.name,sub:g.description,side:n.jsx(E,{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 b8({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 He.updateGroup(e.id,{name:r.trim()}))}catch(f){c(f instanceof ve?f.message:String(f)),l(!1)}}};return n.jsx(Lt,{title:"Rename group",onClose:t,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(E,{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 vT(e){const[t,s]=d.useState(null);return d.useEffect(()=>{let r=!0;return He.group(e).then(i=>{var a;r&&s(((a=i.history)==null?void 0:a.conversations)??null)}).catch(()=>{}),()=>{r=!1}},[e]),t}function k8(e){return e===null?"Its conversations":e===0?"Nothing has been said yet, and its next conversation":`Its ${e} ${e===1?"conversation":"conversations"}`}function N8({group:e,onClose:t,onCleared:s}){const r=vT(e.id),[i,a]=d.useState(!1),[l,o]=d.useState(null),c=async()=>{a(!0),o(null);try{await He.clearGroup(e.id),s()}catch(h){o(h instanceof ve?h.message:String(h)),a(!1)}},u=r===0;return n.jsxs(Lt,{title:`Clear the history of ${e.name}?`,onClose:t,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(E,{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.":`${k8(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 S8({group:e,agents:t,onClose:s,onDeleted:r}){const i=vT(e.id),[a,l]=d.useState(!1),[o,c]=d.useState(null),u=xT(e,t).map(m=>m.name),h=async()=>{l(!0),c(null);try{const{undoUntil:m}=await He.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(Lt,{title:`Delete ${e.name}?`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(E,{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?`${gT(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 gd=320,jT="buddi.chatWidth";function C8({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 jy,wy,yy,by,ky,Ny,Sy;const x=yf(),[w,y]=d.useState([]),[k,N]=d.useState(null),[S,C]=d.useState(null),[T,R]=d.useState(null),[I,L]=d.useState([]),[_,$]=d.useState([]),[P,O]=d.useState(null),[M,D]=d.useState(!1),[H,B]=d.useState(new Map),[q,W]=d.useState(null),[Y,F]=d.useState(n8),[X,Q]=d.useState([]),[ee,fe]=d.useState(!1),Oe=d.useRef(0),Ie=d.useRef(null),[Fe,U]=d.useState(!1),se=d.useRef(g??0),J=d.useRef(s),ye=d.useRef({agentId:s,conversationId:k});ye.current={agentId:s,conversationId:k};const ge=Y[k??""]??[],[$e,De]=d.useState(null),[Je,ze]=d.useState(null),[Se,Ue]=d.useState(null),[at,Ye]=d.useState([]),[kt,qt]=d.useState(!1),[re,be]=d.useState(()=>Date.now()),[Qe,ct]=d.useState(E8),yt=d.useRef(null),[ut,pn]=d.useState(null),[Yn,Z]=d.useState(!1),[Re,Xe]=d.useState(null),[xt,G]=d.useState(qA),he=d.useRef(xt);he.current=xt;const Be=d.useRef(null),[_e,nn]=d.useState(null),As=d.useCallback(K=>{G(K),JA(K),K||Hl()},[]),[Nn,Ts]=d.useState(null),[$s,ke]=d.useState(null);d.useEffect(()=>{if(!s)return;const K=AL(s);K&&Xe({text:K,at:Date.now()})},[s]);const Ee=i?`group:${i.id}`:s??null,We=[...t.top,...t.middle,...t.bottom],me=We.find(K=>K.id===s)??null,qn=de(()=>A.providerAccounts(),[]),On=i?i.members.map(K=>We.find(ne=>ne.id===K)).filter(K=>!!K):[],[Gs,Zl]=d.useState(null),Fi=M?Gs??s??null:null;d.useEffect(()=>{o==null||o(Fi)},[Fi,o]),d.useEffect(()=>()=>o==null?void 0:o(null),[o]),d.useEffect(()=>{let K=!1;return He.views().then(ne=>{K||y(ne.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 ne=!1;return N(null),C(null),R(null),L([]),De(null),D(!1),W(null),Q([]),Xc(null),U(!1),pn(null),v?(v!=="new"?N(v):R(Ee),()=>{ne=!0}):((i?He.groupConversations(i.id):He.conversations(s)).then(Ae=>{if(ne)return;const Ne=[...Ae.conversations??[]].sort(A8)[0];Ne?(N(Ne.id),j==null||j(s,Ne.id)):R(Ee)}).catch(()=>{ne||R(Ee)}),()=>{ne=!0})},[s,i==null?void 0:i.id,Ee,v,j]);const Ln=d.useCallback(K=>He.conversation(K).then(ne=>{if(ye.current.conversationId===K){if(ne.agentId!==ye.current.agentId)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(ne),L(Ae=>Ae.filter(Ne=>!Gm(ne,Ne)))}}).catch(ne=>{ye.current.conversationId===K&&De(Zr(ne))}),[]);d.useEffect(()=>{if(!k)return;let K=!1;return B(new Map),$([]),He.conversation(k).then(ne=>{if(!K){if(ne.agentId!==s)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(ne),L(Ae=>Ae.filter(Ne=>!Gm(ne,Ne)))}}).catch(ne=>{K||De(Zr(ne))}),()=>{K=!0}},[k,s]),d.useEffect(()=>{if(!k)return;let K=!1;const ne=window.setInterval(()=>{He.conversation(k).then(Ae=>{K||Ae.agentId!==ye.current.agentId||(C(Ae),L(Ne=>Ne.filter(Ze=>!Gm(Ae,Ze))))}).catch(()=>{})},3e3);return()=>{K=!0,window.clearInterval(ne)}},[k,s]),d.useEffect(()=>{if(!k)return;const K=of({url:He.streamUrl(k),onEvent:ne=>{var Ae;switch(ne.name){case"run.started":Be.current=null,D(!0),O(null),Zl(dn(ne.data.agentId));break;case"live":{const Ne=dn(ne.data.runId)??"",Ze=Number(ne.data.turn??0),Ke=ne.data.kind==="thinking"?"thinking":"text",Sn=dn(ne.data.text)??"",kr=Date.now();if(Ke==="text"){const qs=Be.current;Be.current=qs&&qs.runId===Ne&&qs.turn===Ze?{...qs,text:qs.text+Sn}:{runId:Ne,turn:Ze,text:Sn}}O(qs=>{const Ca=qs&&qs.runId===Ne&&qs.turn===Ze?qs:{runId:Ne,turn:Ze,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return Ke==="thinking"?{...Ca,thinking:Ca.thinking+Sn,thinkingStartedAt:Ca.thinkingStartedAt??kr}:{...Ca,text:Ca.text+Sn,textStartedAt:Ca.textStartedAt??kr}});break}case"live.snapshot":{const Ne=dn(ne.data.runId)??"",Ze=Number(ne.data.turn??0),Ke=dn(ne.data.text)??"",Sn=dn(ne.data.thinking)??"",kr=Number(ne.data.startedAt??Date.now());Be.current={runId:Ne,turn:Ze,text:Ke},O({runId:Ne,turn:Ze,text:Ke,thinking:Sn,thinkingStartedAt:Sn?kr:null,textStartedAt:Ke?kr:null,settled:!1});break}case"live.settle":{const Ne=dn(ne.data.runId)??"",Ze=Number(ne.data.turn??0);O(Ke=>Ke&&Ke.runId===Ne&&Ke.turn===Ze?{...Ke,settled:!0}:Ke);break}case"tool.called":{const Ne=dn(ne.data.toolUseId)??dn(ne.data.id),Ze=dn(ne.data.name)??dn(ne.data.tool)??"tool";Ne&&$(Ke=>[...Ke.filter(Sn=>Sn.toolUseId!==Ne),{toolUseId:Ne,name:Ze,startedAt:Date.now()}]);break}case"tool.result":{const Ne=dn(ne.data.toolUseId)??dn(ne.data.id);Ne&&$(Ze=>Ze.filter(Ke=>Ke.toolUseId!==Ne)),Ln(k);break}case"reaction":Ln(k);break;case"message.appended":Ln(k).then(()=>{O(Ne=>Ne!=null&&Ne.settled?null:Ne)});break;case"awaiting-approval":{const Ne=dn(ne.data.approvalId)??dn(ne.data.actionId),Ze=dn(ne.data.toolUseId);Ne&&Ze&&B(Ke=>new Map(Ke).set(Ze,Ne)),$(Ke=>Ke.filter(Sn=>Sn.toolUseId!==Ze)),Ln(k);break}case"run.finished":{D(!1),$([]),O(null),Zl(null);const Ne=dn(ne.data.message);De(Ne??null);const Ze=((Ae=Be.current)==null?void 0:Ae.text.trim())??"";Be.current=null,!Ne&&Ze!==""&&he.current&&ch(Ze,k).then(Ke=>{Ke&&nn(Ke)}),Ln(k);break}}}});return()=>K.close()},[k,Ln]),d.useEffect(()=>{const K=window.setInterval(()=>be(Date.now()),_.length===0?6e4:1e3);return()=>window.clearInterval(K)},[_.length]);const _i=de(()=>s&&k?A.browser({agentId:s,conversationId:k}):Promise.resolve(void 0),[s,k],1500),br=_i.error?void 0:_i.data,Qr=br!=null&&br.session&&br.session.agentId===s&&br.session.conversationId===k?br:void 0,Ut=V5(Qr,s,k),Ys=(Ut==null?void 0:Ut.id)??null,[eo,FI]=d.useState(null),ny=Qr==null?void 0:Qr.mode;d.useEffect(()=>{Ut&&s&&k&&FI({agentId:s,conversationId:k,tab:G5(Ut,ny)})},[Ys,ny,s,k]);const _I=eo&&eo.agentId===s&&eo.conversationId===k&&!ge.includes(eo.tab.id)?eo.tab:null,gn=Ut??_I,zI=d.useMemo(()=>Y5((S==null?void 0:S.messages)??[]),[S]),[UI,Xc]=d.useState(null),BI=d.useMemo(()=>$6({messages:(S==null?void 0:S.messages)??[],descriptors:w}),[S,w]),Na=i5(BI,k??null),Mf=l5(i?null:s),sy=d.useMemo(()=>a5((S==null?void 0:S.messages)??[]),[S]),Fn=d.useMemo(()=>{const ne=R6({messages:(S==null?void 0:S.messages)??[],descriptors:w,awaiting:H,served:Na.served,...gn?{folded:pd}:{},gathered:e8}).filter(Ne=>Ne.source==="approval"||!ge.includes(Ne.id)),Ae=q?r0(ne,q):null;if(Ae&&(Ae.props={...Ae.props,focus:q}),q&&!Ae&&!ge.includes(q)&&!ne.some(Ne=>Ne.id===q)){const Ne=D6((S==null?void 0:S.messages)??[],q,{redactInputOf:pd});Ne&&!pd.has(Ne.tool)&&ne.push(Ne)}gn&&ne.push(gn);for(const Ne of X)ne.push(JU(Ne));return Mf&&ne.unshift(o5(Mf,sy)),ut?[...ne,c5(ut)]:ne},[S,w,H,ut,Ys,gn==null?void 0:gn.title,q,Y,k,X,Na.served,Mf,sy]),WI=d.useMemo(()=>{var ne;const K=[];for(const Ae of(S==null?void 0:S.messages)??[]){if(Ae.role!=="user"||Ae.speaker&&Ae.speaker!=="owner")continue;const Ne=(ne=Ae.blocks.find(Ze=>Ze.type==="text"))==null?void 0:ne.text.trim();Ne&&K.unshift(Ne)}return K},[S]),Df=d.useMemo(()=>Fn.filter(K=>K.source==="approval"),[Fn]),Zc=Df.at(-1)??null,eu=d.useMemo(()=>[...Df.map(K=>({approvalId:K.props.approvalId,toolUseId:K.id})),...((S==null?void 0:S.delegatedApprovals)??[]).map(K=>({approvalId:K.approvalId,toolUseId:K.toolUseId??"",askedBy:I8(K.chain,We)}))],[Df,S==null?void 0:S.delegatedApprovals]),to=d.useMemo(()=>{for(let K=Fn.length-1;K>=0;K-=1){const ne=Fn[K];if(ne!=null&&ne.substantial)return ne.id}return null},[Fn]),tu=d.useRef(null),Of=((jy=Fn.filter(K=>(K.source!=="browser"||K.pinned===!0)&&K.id!==dx).at(-1))==null?void 0:jy.id)??((wy=Fn.filter(K=>K.id!==dx).at(-1))==null?void 0:wy.id)??null;d.useEffect(()=>{if(to&&to!==tu.current){tu.current=to,W(to);return}q===null&&Of&&W(Of)},[to,q,Of]);const ry=d.useRef(Na.live);d.useEffect(()=>{const K=ry.current;ry.current=Na.live;const ne=[...Na.live].filter(Ze=>!K.has(Ze));if(ne.length===0||Zc||q!==null&&q!==tu.current)return;const Ne=[...Fn].reverse().find(Ze=>Ze.source==="descriptor"&&Ze.renderer==="preview"&&Ze.props.target!==null&&ne.includes(ol(Ze.props.target)));Ne&&W(Ne.id)},[Na.live,Fn,Zc,q]);const iy=d.useRef(null);d.useEffect(()=>{Ys!==iy.current&&(iy.current=Ys,Ys&&!Zc&&W(Ys))},[Ys,Zc]);const ay=d.useRef(null),no=b==="browser"?(gn==null?void 0:gn.id)??null:null;d.useEffect(()=>{!no||ay.current===no||(ay.current=no,W(no))},[no]);const Lf=(gn==null?void 0:gn.id)??null;d.useEffect(()=>{!Lf||!q||g0((S==null?void 0:S.messages)??[],q)!==null&&(Xc(q),W(Lf))},[Lf,q,S]);const ly=K=>{Q(ne=>ne.some(Ae=>Ae.artifactId===K.artifactId)?ne:[...ne,K]),W(fd(K.artifactId)),h&&(m==null||m())},nu=!i&&me&&!me.available?fA(me):null,oy=i?n.jsx("span",{className:"wb-group-stack","aria-hidden":"true",children:i.members.slice(0,2).map(K=>{const ne=We.find(Ae=>Ae.id===K);return n.jsx(hf,{className:"wb-group-chip",id:K,name:(ne==null?void 0:ne.name)??"?",face:ne,initials:1},K)})}):null,zi=i&&We.length>0?j8(i,We):null,cy=(zi==null?void 0:zi.kind)==="coordinator",uy=Wg(i?null:me),Ff=((S==null?void 0:S.offers)??[]).filter(K=>!at.includes(K.id)&&Date.parse(K.expiresAt)>re),HI=me&&$s===me.id?Nn:(me==null?void 0:me.thinking)??null,KI=K=>{if(!me)return;const ne=me.id;ke(ne),Ts(K),A.setAgentEngine(ne,{thinking:K}).catch(Ae=>{ke(null),De(Ae instanceof ve?Ae.message:String(Ae))})},_f=(K,ne)=>{if(!s)return;const Ae=ne.map(Ke=>Ke.artifactId),Ne=M,Ze={id:`optimistic:${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:K},...ne.map(Ke=>({type:"attachment",artifactId:Ke.artifactId,filename:Ke.filename,mime:Ke.mime,kind:Ke.kind,sizeBytes:Ke.sizeBytes}))],...Ne?{speaker:aT}:{}};L(Ke=>Ne?[...Ke,Ze]:[Ze]),De(null),ze(null),D(!0),(i?He.sendToGroup(i.id,{...k?{conversationId:k}:{},text:K,attachmentIds:Ae}):He.send(s,{...k?{conversationId:k}:{},text:K,attachmentIds:Ae})).then(async Ke=>{ye.current.agentId!==s||ye.current.conversationId!==k||(ze(Ke.rolledOver===!0?"(New thread — the room had grown long. Where it stopped carries over as a summary.)":null),Ke.conversationId!==k?(C(null),N(Ke.conversationId)):await Ln(Ke.conversationId),Ke.queued===!0&&L(Sn=>Sn.filter(kr=>kr.id!==Ze.id)),j==null||j(s,Ke.conversationId))}).catch(Ke=>{L(Sn=>Sn.filter(kr=>kr.id!==Ze.id)),De(Zr(Ke)),D(!1)})},VI=K=>{var Ae;const ne=Ff.find(Ne=>Ne.id===K);if(((Ae=ne==null?void 0:ne.handoff)==null?void 0:Ae.kind)==="install"){window.location.hash=w4(ne.handoff.package);return}De(null),Ue(K),Ye(Ne=>[...Ne,K]),A.takeOffer(K,k??void 0).then(Ne=>{if(Ne.agentId&&Ne.agentId!==(me==null?void 0:me.id)){window.location.hash=st(Ne.agentId,Ne.conversationId??null);return}Ne.runId&&(ze(null),D(!0)),k&&Ln(k)}).catch(Ne=>{Ye(Ze=>Ze.filter(Ke=>Ke!==K)),De(Zr(Ne)),k&&Ln(k)}).finally(()=>Ue(null))},GI=(K,ne)=>dy({answer:K,...ne?{optionId:ne}:{}}),YI=()=>dy({answer:"",skipped:!0}),dy=K=>{const ne=S==null?void 0:S.question;ne&&(De(null),qt(!0),D(!0),He.answerQuestion(ne.id,K).then(()=>{if(k)return Ln(k)}).catch(Ae=>{De(Zr(Ae)),D(!1)}).finally(()=>qt(!1)))},qI=()=>{if(s){if(ut){pn(null);return}Z(!0),A.agentProfile(s).then(K=>{pn(K),W(hx(K.id)),h&&(m==null||m())}).catch(K=>De(Zr(K))).finally(()=>Z(!1))}},JI=K=>{Xe({text:K.prompt,at:Date.now()}),l(K.agentId),h&&(p==null||p())},QI=()=>{k&&He.cancel(k).catch(K=>De(Zr(K))).finally(()=>{D(!1),$([])})},su=d.useCallback(()=>{if(N(null),C(null),L([]),D(!1),De(null),ze(null),$([]),B(new Map),W(null),Q([]),Xc(null),tu.current=null,i){He.startGroupConversation(i.id).then(({conversationId:K})=>{N(K),s&&(j==null||j(s,K))}).catch(K=>De(Zr(K)));return}R(Ee),s&&(j==null||j(s,"new"))},[s,i,Ee,j]);d.useEffect(()=>{g&&g!==se.current&&(se.current=g,su())},[g,su]);const hy=K=>{k&&Ln(k),A.overview().catch(()=>{}),K.state!=="pending"&&B(ne=>new Map([...ne].filter(([,Ae])=>Ae!==K.id)))},ru=d.useRef(!1);d.useEffect(()=>{const K=Ae=>{if(!ru.current)return;const Ne=Math.max(gd,Math.min(720,Ae.clientX-52));ct(Ne)},ne=()=>{if(ru.current){ru.current=!1;try{Qe!==null&&window.localStorage.setItem(jT,String(Qe))}catch{}}};return window.addEventListener("pointermove",K),window.addEventListener("pointerup",ne),()=>{window.removeEventListener("pointermove",K),window.removeEventListener("pointerup",ne)}},[Qe]);const XI=((yy=We.find(K=>K.id===r))==null?void 0:yy.name)??null,fy=i?[]:Az(me,XI),my=!(S&&S.conversationId===k)&&!(!k&&T!==null&&T===Ee),py=my?n.jsx("div",{className:"wb-chat-loading","data-testid":"chat-loading","aria-busy":"true"}):!i&&me?n.jsx(DA,{quiet:!0,still:!0,className:"wb-chat-field",children:n.jsxs("div",{className:"wb-chat-opening","data-testid":"chat-opening",children:[n.jsx(on,{agents:We,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:Tz(me)}),fy.length>0?n.jsx("div",{className:"wb-starters",role:"group","aria-label":`Things to ask ${me.name}`,children:fy.map(K=>n.jsx("button",{type:"button",className:"wb-starter",onClick:()=>{var ne;Xe({text:K,at:Date.now()}),(ne=Ie.current)==null||ne.focus()},children:K},K))}):null]})}):null,gy=n.jsx(GB,{renderables:Fn,activeId:(q?(by=r0(Fn,q))==null?void 0:by.id:null)??q,onActivate:W,onClose:K=>{ut&&K===hx(ut.id)?pn(null):X.some(ne=>fd(ne.artifactId)===K)?Q(ne=>ne.filter(Ae=>fd(Ae.artifactId)!==K)):k&&F(ne=>{const Ae={...ne,[k]:[...new Set([...ne[k]??[],K])]};return x0(Ae),Ae}),q===K&&W(null)},timezone:e,onDecided:hy,onChangeAgent:JI,agents:We,browserPanel:gn?n.jsx(B5,{status:Qr,error:_i.error,reload:_i.reload,steps:zI,live:Ut!==null,focusedStepId:UI},gn.id):null,descriptors:w,grantedTools:i?On.flatMap(K=>K.tools??[]):(me==null?void 0:me.tools)??[],...me?{agentName:me.name}:{},loading:my,...!i&&me?{face:n.jsx(on,{agents:We,id:me.id,size:"xl"})}:{}}),xy=(Ny=(ky=[...(S==null?void 0:S.messages)??[],...I].find(K=>K.role==="user"))==null?void 0:ky.blocks.find(K=>K.type==="text"))==null?void 0:Ny.text.trim(),vy=xy?xy.split(`
109
- `)[0]:"New conversation",Sa=x8({lifetime:(S==null?void 0:S.lifetime)??null,startedAt:(S==null?void 0:S.startedAt)??null,now:re,timezone:e});return n.jsxs(n.Fragment,{children:[n.jsxs("section",{className:"wb-chat",ref:yt,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=>{Uu(K)&&(K.preventDefault(),Oe.current+=1,fe(!0))},onDragOver:K=>{Uu(K)&&(K.preventDefault(),K.dataTransfer.dropEffect="copy")},onDragLeave:K=>{Uu(K)&&(Oe.current=Math.max(0,Oe.current-1),Oe.current===0&&fe(!1))},onDrop:K=>{var ne;Uu(K)&&(K.preventDefault(),Oe.current=0,fe(!1),s&&((ne=Ie.current)==null||ne.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(T8,{}),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?Hc(Wc(me)):{},children:[n.jsxs("div",{className:"wb-head-row",children:[i?n.jsx("span",{className:"wb-head-face","aria-hidden":"true",children:oy}):me?n.jsx("a",{className:"wb-head-face",href:St(me.id),"aria-label":`${me.name}'s page`,children:n.jsx(on,{agents:We,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:vy,children:vy}),n.jsx("span",{className:"wb-head-meta","data-tone":Sa.tone,title:i?`${On.map(K=>K.name).join(", ")}. Coordinator: ${(me==null?void 0:me.name)??i.coordinator}.`:Sa.title,children:i?`${On.map(K=>K.name).join(", ")} · ${Sa.text}`:me?n.jsxs(n.Fragment,{children:[n.jsx("a",{className:"wb-head-name",href:St(me.id),title:`${me.name}'s page`,children:me.name})," ",n.jsxs("span",{className:"wb-head-handle",children:["@",me.handle]}),` · ${Sa.tone==="quiet"&&Sa.text==="New conversation"?`on ${x}`:Sa.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),su()},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":Fe,"data-open":Fe?"true":void 0,disabled:!s,onClick:()=>U(K=>!K),children:n.jsx($8,{})}),h?n.jsxs("button",{className:"ui-btn",onClick:m,disabled:Fn.length===0,children:["Canvas",Fn.length>0?` (${Fn.length})`:""]}):null,i?n.jsx(j0,{disabled:!1,label:"More about this group",title:i.name,sub:gT(On.map(K=>K.name)),face:oy,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(j0,{disabled:!s,label:"More about this agent",title:(me==null?void 0:me.name)??"Agent",...me?{sub:`@${me.handle}`,face:n.jsx(on,{agents:We,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:qI},...me?[{label:"Set up",hint:"Identity, model and access",href:St(me.id,"setup")},{label:"Open agent page",hint:"Profile, activity and setup",href:St(me.id)}]:[]]})]}),u?n.jsx(pA,{agents:t,currentId:s,attention:c,onSelect:l,orientation:"horizontal",...Fi?{working:new Set([Fi])}:{}}):null]}),Fe&&s?n.jsx(t8,{agentId:s,...i?{groupId:i.id}:{},currentId:k,timezone:e,onNew:()=>{U(!1),su()},onSelect:K=>{if(K===k){U(!1);return}U(!1),C(null),L([]),D(!1),W(null),De(null),ze(null),Q([]),N(K),j==null||j(s,K,!1)}}):null,s&&k?n.jsx(H5,{agentId:s,conversationId:k},`${s}:${k}`):null,$e?n.jsx("div",{className:"wb-chat-notice",children:n.jsx(ie,{message:$e})}):null,Je?n.jsx("div",{className:"wb-chat-notice","data-testid":"chat-notice",children:Je}):null,S!=null&&S.carriedOver?n.jsx(v8,{text:S.carriedOver,onDelete:async()=>{const K=S.conversationId;await He.deleteCarryOver(K),C(ne=>{if(!ne||ne.conversationId!==K)return ne;const{carriedOver:Ae,...Ne}=ne;return Ne})}},S.conversationId):null,n.jsx(qj,{messages:[...(S==null?void 0:S.messages)??[],...I],live:_,now:re,working:M,partial:P,agents:We,...S!=null&&S.runs?{runs:S.runs}:{},...s&&k?{onContinue:()=>_f("continue",[])}:{},...i?{speakers:We,coordinatorId:i.coordinator}:{},...Gs?{workingAs:((Sy=We.find(K=>K.id===Gs))==null?void 0:Sy.name)??Gs}:{},onOpenFile:ly,onReadAloud:(K,ne)=>{nn(null),ch(ne,k??void 0,K).then(Ae=>{Ae&&nn(Ae)})},onOpen:K=>{if(gn){const ne=g0([...(S==null?void 0:S.messages)??[],...I],K);if(ne){Xc(ne),W(gn.id),h&&(m==null||m());return}}k&&F(ne=>{const Ae={...ne,[k]:(ne[k]??[]).filter(Ne=>Ne!==K)};return x0(Ae),Ae}),W(K),h&&(m==null||m())},...me?{agentName:me.name,agentId:me.id}:{},...py?{empty:py}:{},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…"}),Ff.length>0?n.jsx("div",{className:"wb-offers","data-testid":"chat-offers",children:Ff.map(K=>{var ne,Ae;return n.jsx("button",{className:"ui-btn",disabled:Se!==null,title:((ne=K.handoff)==null?void 0:ne.kind)==="install"?`Opens ${K.handoff.title}'s install sheet`:K.prompt,"data-handoff":(Ae=K.handoff)==null?void 0:Ae.kind,onClick:()=>VI(K.id),children:K.label},K.id)})}):null,zi?n.jsx("div",{className:"wb-composer-blocked","data-testid":"group-problem","data-kind":zi.kind,children:n.jsx(V,{tone:cy?"warning":void 0,role:"status",children:n.jsxs("span",{children:[zi.text," ",n.jsx("button",{type:"button",className:"wb-link-btn",onClick:()=>a==null?void 0:a("members"),children:zi.action})]})})}):null,nu?n.jsx("div",{className:"wb-composer-blocked","data-testid":"composer-blocked",children:n.jsxs(V,{tone:"warning",role:"status",children:[nu," ",n.jsx("a",{href:Pe(uy.section),children:uy.label})]})}):eu.length>0?n.jsx(xB,{approvals:eu,timezone:e,now:re,version:S,onDecided:hy,onSay:K=>_f(K,[]),onOpenFull:K=>{W(K),h&&(m==null||m())}}):null,nu||eu.length>0?null:S!=null&&S.question?n.jsx(f8,{question:S.question,disabled:kt||M,onAnswer:GI,onSkip:YI},S.question.id):null,nu||cy?null:n.jsxs("div",{hidden:eu.length>0||!!(S!=null&&S.question),"data-testid":"composer-slot",children:[n.jsx(Qj,{ref:Ie,disabled:!s,running:M,onSend:_f,onStop:QI,agentName:i?i.name:(me==null?void 0:me.name)??"the agent",draft:Re,history:WI,threadKey:k??(i?`group:${i.id}`:s),model:i?null:(me==null?void 0:me.model)??null,setupHref:i?null:me?St(me.id,"setup","brain"):null,thinking:HI,...!i&&me&&nE(sE(me,qn.data))?{onThinking:KI}:{},...i?{mentions:On.map(K=>({handle:K.handle,name:K.name}))}:{},onOpenFile:ly,conversationId:k??null,readAloud:xt,onReadAloud:As}),_e?n.jsx("p",{className:"wb-voice-note",role:"status",children:_e}):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"})]}),gy]}):null:n.jsxs(n.Fragment,{children:[n.jsx("button",{className:"wb-grip","aria-label":"Resize the conversation column",onPointerDown:K=>{var ne,Ae;ru.current=!0,(Ae=(ne=K.currentTarget).setPointerCapture)==null||Ae.call(ne,K.pointerId)},onKeyDown:K=>{const ne=Ae=>{var Ne;return Ae??((Ne=yt.current)==null?void 0:Ne.offsetWidth)??gd};K.key==="ArrowLeft"&&ct(Ae=>Math.max(gd,ne(Ae)-16)),K.key==="ArrowRight"&&ct(Ae=>Math.min(720,ne(Ae)+16))}}),gy]})]})}function E8(){try{const e=window.localStorage.getItem(jT),t=Number(e);return e!==null&&Number.isFinite(t)&&t>=gd?t:null}catch{return null}}function A8(e,t){return Date.parse(t.lastMessageAt??t.startedAt??t.createdAt??"")-Date.parse(e.lastMessageAt??e.startedAt??e.createdAt??"")}function dn(e){return typeof e=="string"&&e!==""?e:null}function Zr(e){return e instanceof ve||e instanceof Error?e.message:String(e)}function Gm(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 Uu(e){var s;const t=(s=e.dataTransfer)==null?void 0:s.types;return!!(t&&Array.from(t).includes("Files"))}function T8(){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 $8(){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 R8(){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 j0({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(R8,{})}),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 I8(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 w0=!1;const P8=new Set(["missing","unconfigured","not-english"]);async function ch(e,t,s=null){const r=QA(s);try{const i=await He.say({text:e,...t?{conversationId:t}:{}});return Qk(r)&&await d6(i.audioUrl,i.mime,s),null}catch(i){Qk(r)&&Hl();const a=i instanceof ve&&i.detail&&typeof i.detail=="object"?i.detail.reason:void 0;return typeof a=="string"&&P8.has(a)&&(s!==null||!w0)?(w0=!0,i.message):null}}let ms=null;function M8(e){if(hd(e)!==null)return!1;const t=rA(e);return t!==un&&t!==xi}function D8({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||!ms)return;const h=of({url:He.streamUrl(ms.conversationId),lastEventId:ms.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(L8,{agent:e,agents:t,navigate:i,onClose:()=>r(!1),onBusy:u}):n.jsxs(oc,{children:[n.jsx(cc,{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(O8,{busy:c})})}),n.jsx(uc,{children:n.jsx(dc,{className:"ui-tip",side:"left",sideOffset:8,children:o})})]})}function O8({busy:e}){const[t,s]=d.useState(!1);return t?n.jsx(jc,{size:"lg"}):n.jsx(Vc,{state:e?"working":"idle",className:"wb-ask-fab-face",onStillError:()=>s(!0)})}function L8({agent:e,agents:t,navigate:s,onClose:r,onBusy:i}){const a=d.useRef(null),[l,o]=d.useState(ms&&ms.agentId===e.id?ms.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,T]=d.useState(Date.now()),[R,I]=d.useState(qA),L=d.useRef(R);L.current=R;const[_,$]=d.useState(null),P=d.useRef(null),O=d.useCallback(async Y=>{try{const F=await He.conversation(Y);u(F),f(X=>X.filter(Q=>!F8(F,Q)))}catch{}},[]);d.useEffect(()=>{l&&O(l)},[l,O]),d.useEffect(()=>{if(!l)return;const Y=of({url:He.streamUrl(l),onEvent:F=>{var X;switch(F.name){case"run.started":P.current=null,j(!0),v(null);break;case"live":{const Q=Jn(F.data.runId)??"",ee=Number(F.data.turn??0),fe=F.data.kind==="thinking"?"thinking":"text",Oe=Jn(F.data.text)??"",Ie=Date.now();if(fe==="text"){const Fe=P.current;P.current=Fe&&Fe.runId===Q&&Fe.turn===ee?{...Fe,text:Fe.text+Oe}:{runId:Q,turn:ee,text:Oe}}v(Fe=>{const U=Fe&&Fe.runId===Q&&Fe.turn===ee?Fe:{runId:Q,turn:ee,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return fe==="thinking"?{...U,thinking:U.thinking+Oe,thinkingStartedAt:U.thinkingStartedAt??Ie}:{...U,text:U.text+Oe,textStartedAt:U.textStartedAt??Ie}});break}case"live.snapshot":{const Q=Jn(F.data.runId)??"",ee=Number(F.data.turn??0),fe=Jn(F.data.text)??"",Oe=Jn(F.data.thinking)??"",Ie=Number(F.data.startedAt??Date.now());P.current={runId:Q,turn:ee,text:fe},j(!0),v({runId:Q,turn:ee,text:fe,thinking:Oe,thinkingStartedAt:Oe?Ie:null,textStartedAt:fe?Ie:null,settled:!1});break}case"live.settle":{const Q=Jn(F.data.runId)??"",ee=Number(F.data.turn??0);v(fe=>fe&&fe.runId===Q&&fe.turn===ee?{...fe,settled:!0}:fe);break}case"tool.called":{const Q=Jn(F.data.toolUseId)??Jn(F.data.id),ee=Jn(F.data.name)??Jn(F.data.tool)??"tool";Q&&p(fe=>[...fe.filter(Oe=>Oe.toolUseId!==Q),{toolUseId:Q,name:ee,startedAt:Date.now()}]);break}case"tool.result":{const Q=Jn(F.data.toolUseId)??Jn(F.data.id);Q&&p(ee=>ee.filter(fe=>fe.toolUseId!==Q)),O(l);break}case"message.appended":case"awaiting-approval":O(l).then(()=>v(Q=>Q!=null&&Q.settled?null:Q));break;case"run.finished":{j(!1),p([]),v(null);const Q=Jn(F.data.message);k(Q??null);const ee=((X=P.current)==null?void 0:X.text.trim())??"";P.current=null,!Q&&ee!==""&&L.current&&ch(ee,l).then(fe=>{fe&&$(fe)}),O(l);break}}}});return()=>{ms&&ms.conversationId===l&&(ms.lastEventId=Y.lastEventId()),Y.close()}},[l,O]),d.useEffect(()=>{i(b||x)},[b,x,i]),d.useEffect(()=>{if(m.length===0)return;const Y=window.setInterval(()=>T(Date.now()),1e3);return()=>window.clearInterval(Y)},[m.length]);const M=(Y,F)=>{w(!0),k(null);const X={id:`local-${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:Y}]};f(Q=>[...Q,X]),(async()=>{try{const Q=l??(await He.startConversation(e.id)).conversationId;Q!==l&&(ms={agentId:e.id,conversationId:Q},o(Q));const ee=await He.send(e.id,{conversationId:Q,text:Y,...F.length>0?{attachmentIds:F.map(fe=>fe.artifactId)}:{}});ee.conversationId!==Q&&(ms={agentId:e.id,conversationId:ee.conversationId},o(ee.conversationId)),j(!0),O(ee.conversationId)}catch(Q){f(ee=>ee.filter(fe=>fe.id!==X.id)),k(Q instanceof ve?Q.message:String(Q)),S({text:Y,at:Date.now()})}finally{w(!1)}})()},D=()=>{l&&He.cancel(l).catch(Y=>k(String(Y))).finally(()=>j(!1))},H=()=>{var Y;ms=null,o(null),u(null),f([]),p([]),v(null),j(!1),k(null),(Y=a.current)==null||Y.focus()},B=Y=>{I(Y),JA(Y),Y||Hl()},q=l?st(e.id,l):st(e.id),W=[...(c==null?void 0:c.messages)??[],...h];return n.jsxs(UU,{title:e.name,label:`${e.name}, a quick chat`,onClose:r,onOpenAutoFocus:Y=>{var F;Y.preventDefault(),(F=a.current)==null||F.focus()},onCloseAutoFocus:Y=>Y.preventDefault(),actions:n.jsxs(n.Fragment,{children:[n.jsx(E,{size:"sm",variant:"ghost",onClick:H,disabled:l===null&&h.length===0,children:"New"}),n.jsx(Et,{size:"sm",variant:"ghost",href:q,onClick:Y=>{Y.preventDefault(),s(q)},children:"Open in Chat"})]}),children:[n.jsx("div",{className:"wb-ask-thread",children:n.jsx(qj,{messages:W,live:m,now:C,working:b||x,partial:g,agents:t,agentName:e.name,agentId:e.id,onOpen:()=>s(q),onReadAloud:(Y,F)=>{$(null),ch(F,l??void 0,Y).then(X=>{X&&$(X)})},emptyHint:`Ask ${e.name} anything, without leaving this page.`})}),n.jsxs("div",{className:"wb-ask-compose",children:[y?n.jsx(ie,{message:y}):null,n.jsx(Qj,{ref:a,disabled:x||!e.available,running:b,onSend:M,onStop:D,agentName:e.name,placeholder:`Message ${e.name}…`,draft:N,threadKey:`dock.${l??e.id}`,conversationId:l,readAloud:R,onReadAloud:B}),_?n.jsx("p",{className:"wb-voice-note",role:"status",children:_}):null]})]})}function Jn(e){return typeof e=="string"?e:null}function F8(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 wT=3;function _8(e){if(e==="approval"||e==="question")return"accent";if(e==="watcher"||e==="reminder")return"warm";if(e==="failure")return"critical"}function z8(e,t){return e?t?"above-dock":"above-button":"corner"}function U8({placement:e,children:t}){return n.jsx("div",{className:"wb-toast-stack","data-placement":e,children:t})}function B8(e){return e.state==="shown"&&e.seenAt===null}function W8(e){const[t,s]=d.useState([]),r=d.useRef(new Set),i=d.useRef(new Set),a=d.useCallback(()=>{e&&A.notifications(20).then(({notifications:o})=>{const c=o.filter(u=>B8(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,wT))i.current.has(o.id)||(i.current.add(o.id),A.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 H8({queue:e,agents:t,navigate:s,onDismiss:r}){if(e.length===0)return null;const i=e.slice(0,wT),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":_8(l.kind),role:"status",children:[l.agentId?n.jsx(on,{agents:t,id:l.agentId,size:"sm"}):null,n.jsxs("div",{className:"nt-toast-main",children:[n.jsx("div",{className:"ui-toast-title",children:fc(l)}),l.text?n.jsx("div",{className:"ui-toast-body nt-toast-line",children:K8(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 ${fc(l)}`,onClick:()=>r(l.id),children:"×"})]},l.id)),a>0?n.jsxs("p",{className:"nt-toasts-more",children:["and ",a," more"]}):null]})}function K8(e){var t;return((t=e.split(`
110
- `).find(s=>s.trim()!==""))==null?void 0:t.trim())??""}const V8=3e4,G8=1e3;function Y8(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(),A.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+G8-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")},V8);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 q8({agents:e,onClose:t,onCreated:s}){return hA(e)?n.jsx(J8,{agents:Ij(e),onClose:t,...s?{onCreated:s}:{}}):n.jsx(qe,{title:"A new group",onClose:t,children:n.jsxs(V,{children:["A group needs two agents. Make another one with ",Sz(e)," first."]})})}function J8({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(Bc)))==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 He.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(qe,{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(on,{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(E,{onClick:t,children:"Cancel"}),n.jsx(E,{variant:"accent",disabled:!g||u,onClick:()=>void b(),children:u?"Creating…":"Create group"})]})]})})}const Q8=1e4;function uh({title:e,body:t,duration:s,onUndo:r,onGone:i}){return n.jsxs(ID,{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(PD,{className:"ui-toast-title",children:e}),t?n.jsx(MD,{className:"ui-toast-body",children:t}):null]}),r?n.jsx(DD,{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 Xj(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 A.decide(c,u,h,f):await A.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 Zj({action:e,timezone:t,busy:s,onDecide:r,agentName:i}){var h,f;const[a,l]=d.useState(!1),{values:o,controls:c}=_j(e.choices),u=m=>o?r(e.id,"approve",m,o):r(e.id,"approve",m);return n.jsxs(us,{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)," (",Le(e.expiresAt),"). Policy v",e.policyVersion,", args ",hc(e.argsHash,12),e.jobId?`, job ${hc(e.jobId)}`:"","."]}),c,n.jsxs(ae,{children:[n.jsx(E,{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(E,{disabled:s,onClick:()=>u("conversation"),children:"Auto: this conversation"}),n.jsx(E,{disabled:s,onClick:()=>u("always"),children:"Always: this agent"})]}):null,n.jsx(E,{variant:"danger",disabled:s,onClick:()=>r(e.id,"reject"),children:"Reject"}),n.jsx(E,{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:rs(e.envelope)})}),n.jsx(ue,{title:"Canonical arguments",children:n.jsx(Pt,{children:rs(e.canonicalArgs)})})]}):null]})}function ew(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),A.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 yT({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 bT(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 X8(e,t){var i;const s=de(()=>A.approvals(),[e,t],15e3);return{action:((i=s.data)==null?void 0:i.pending.find(a=>bT(a,e,t)))??null,reload:s.reload}}function Z8({action:e,onDecided:t}){const{busy:s,failure:r,decide:i}=Xj(a=>t(a));return n.jsxs(le,{gap:"sm",children:[n.jsx(Zj,{action:e,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,busy:s===e.id,onDecide:(a,l,o,c)=>{i(a,l,o,c)}}),n.jsx(ie,{message:r})]})}function tw({plugin:e,agent:t,text:s,label:r,handle:i,onDismiss:a}){var f;const l=ew(e,t),o=X8(e,t),[c,u]=d.useState(null),h=l.created??c;if(h)return n.jsx(yT,{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(Z8,{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(dt,{}),a?n.jsx(E,{variant:"ghost",disabled:l.busy,onClick:a,children:"Not now"}):null,n.jsx(E,{variant:"accent",disabled:l.busy,onClick:l.accept,children:r})]}),n.jsx(ie,{message:l.failure})]})}function kT(){var t;const e=de(()=>A.agentOffers(),[],6e4);return{offers:((t=e.data)==null?void 0:t.offers)??[],reload:e.reload}}function NT({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(tw,{plugin:s.plugin,agent:s.agent,text:s.text,label:`Create @${s.handle}`,handle:s.handle,onDismiss:()=>{A.dismissAgentOffer(s.plugin,s.agent).then(t,t)}},`${s.plugin}/${s.agent}`))})})}const eW=512*1024,tW=/^[A-Za-z0-9+/]*={0,2}$/;function ST(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===""||!tW.test(r)||Math.floor(r.length*3/4)>eW+2?null:{mime:s,data:r}}function CT(e){const t=e==null?void 0:e.message;return typeof t=="string"&&t.trim()!==""?t:null}let Ar=null,Fo=null,bc=null;const mx=new Set;function ET(){for(const e of mx)e()}function Co(){Ar&&(Ar.onended=null,Ar.onerror=null,Ar.pause()),Fo&&URL.revokeObjectURL(Fo),Fo=null,bc!==null&&(bc=null,ET())}async function AT(e,t){Co();const s=atob(e.data),r=new Uint8Array(s.length);for(let i=0;i<s.length;i+=1)r[i]=s.charCodeAt(i);Ar??(Ar=new Audio),Fo=URL.createObjectURL(new Blob([r],{type:e.mime})),bc=t,Ar.onended=Co,Ar.onerror=Co,Ar.src=Fo,ET();try{await Ar.play()}catch{throw Co(),new Error("The browser would not play the sound.")}}function y0(e){e!==void 0&&bc!==e||Co()}function nW(){return d.useSyncExternalStore(e=>(mx.add(e),()=>mx.delete(e)),()=>bc,()=>null)}const sW=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Zs=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],b0=/^\d{4}-\d{2}-\d{2}$/;function sa(e){return e.split("-").map(Number)}function ya(e,t){const[s,r,i]=sa(e);return new Date(Date.UTC(s,r-1,i+t)).toISOString().slice(0,10)}function TT(e){const[t,s,r]=sa(e);return new Date(Date.UTC(t,s-1,r)).getUTCDay()}function $T(e){return sW[TT(e)]}function RT(e){return sa(e)[2]}function k0(e){return ya(e,-((TT(e)+6)%7))}function Or(e){return Lc(e,{weekday:!0,compact:!0})}function rW(e,t){return e===t?`Today · ${Or(e)}`:e===ya(t,1)?`Tomorrow · ${Or(e)}`:Or(e)}function Gi(e){return xL(e)}const N0=new Map;function px(e,t){let s=N0.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"}),N0.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 iW(e,t=new Date){return px(t,e).date}function aW(e,t){return e==="week"?{from:k0(t),days:7}:e==="month"?{from:k0(`${t.slice(0,8)}01`),days:42}:{from:t,days:7}}function lW(e,t,s){if(e!=="month")return ya(t,s*7);const[r,i]=sa(t);return new Date(Date.UTC(r,i-1+s,1)).toISOString().slice(0,10)}function oW(e,t,s,r){const[i,a]=sa(t);if(e==="month")return eE(i,a);const l=ya(s,r-1),[o,c,u]=sa(s),[h,f,m]=sa(l);return X1().date==="iso"?`${s} – ${l}`:vL()?c===f&&o===h?`${Zs[c-1]} ${u} – ${m}, ${h}`:o===h?`${Zs[c-1]} ${u} – ${Zs[f-1]} ${m}, ${h}`:`${Zs[c-1]} ${u}, ${o} – ${Zs[f-1]} ${m}, ${h}`:c===f&&o===h?`${u} – ${m} ${Zs[f-1]} ${h}`:o===h?`${u} ${Zs[c-1]} – ${m} ${Zs[f-1]} ${h}`:`${u} ${Zs[c-1]} ${o} – ${m} ${Zs[f-1]} ${h}`}function Pa(e){return e==null?"":String(e)}function cW(e,t,s,r){const i=[],a=new Set;return e.forEach((l,o)=>{const c=Pa(Ce(l,t.id)),u=Pa(Ce(l,t.title)),h=Pa(Ce(l,t.start)),f=Pa(Ce(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:Ce(l,t.allDay),p=m===void 0?b0.test(h):m===!0||m==="true",g=t.tone===void 0?0:Number(Ce(l,t.tone)),v=Number.isFinite(g)?(Math.trunc(g)%4+4)%4:0,b={id:c,title:u,calendar:t.calendar===void 0?"":Pa(Ce(l,t.calendar)),tone:v,location:t.location===void 0?"":Pa(Ce(l,t.location))};if(p){const k=h.slice(0,10),N=b0.test(f.slice(0,10))&&f.slice(0,10)>k?f.slice(0,10):ya(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=px(j,s),y=Number.isNaN(x.getTime())||x<j?w:px(x,s);i.push({...b,allDay:!1,startDate:w.date,startMin:w.minutes,endDate:y.date,endMin:y.minutes})}),i}function uW(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 nw(e,t){return e.map(s=>({event:s,part:uW(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 sw(e,t){if(t.allDay)return"All day";const s=e.startDate!==e.endDate;return s&&t.from===0?`until ${Gi(t.to)}`:s&&t.to===1440?`from ${Gi(t.from)}`:t.from===t.to?Gi(t.from):`${Gi(t.from)}–${Gi(t.to)}`}function gx(e,t,s){return[sw(e,t),e.title,e.location,e.calendar,Or(s)].filter(Boolean).join(", ")}const IT=30;function dW(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+IT);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 hW={week:"Week",month:"Month",list:"List"},fW=["week","month","list"],mW="(max-width: 720px)";function pW(e){try{return window.localStorage.getItem(e)}catch{return null}}function gW(e,t){try{window.localStorage.setItem(e,t)}catch{}}function xW(e){const t=e.views&&e.views.length>0?e.views:fW,s=ks(mW),[r,i]=d.useState(()=>{const p=pW(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}=aW(l,o);return{views:t,view:l,setView:p=>{i(p),gW(e.storageKey,p),h(null)},anchor:o,today:e.today,go:p=>{c(p===0?e.today:lW(l,o,p)),h(null)},from:f,days:m,to:ya(f,m),selected:u,select:h}}function vW({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)=>ya(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(E,{size:"sm","aria-label":`Previous ${f}`,onClick:()=>e.go(-1),children:n.jsx(ce,{name:"chevron-left",size:14})}),n.jsx(E,{size:"sm",onClick:()=>e.go(0),children:"Today"}),n.jsx(E,{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:oW(a,l,c,u)}),e.views.length>1?n.jsx(Yt,{label:"View",options:e.views.map(v=>({value:v,label:hW[v]})),value:a,onChange:e.setView}):null]}),a==="week"?n.jsx(jW,{dates:h,today:o,events:t,hours:s??[7,21],onPick:e.select}):null,a==="month"?n.jsx(yW,{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(S0,{date:v,today:o,events:t,empty:r},v))}):null,p?n.jsx(S0,{date:p,today:o,events:t,empty:r}):null]})}function S0({date:e,today:t,events:s,empty:r}){const i=nw(s,e);return n.jsx(Ge,{flush:!0,title:rW(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:sw(a,l)},a.id))})})}function jW({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:nw(s,c)})),o=c=>c===t?"true":void 0;return n.jsx(Ge,{flush:!0,children:n.jsxs("div",{className:"cal-week",role:"grid","aria-label":`Week of ${Or(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":Or(c),children:[n.jsx("span",{className:"cal-wd",children:$T(c)}),n.jsx("span",{className:"cal-num",children:RT(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":gx(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:Gi(c*60)},c))}),l.map(({date:c,items:u})=>n.jsx("div",{className:"cal-col",role:"gridcell","aria-label":Or(c),"data-today":o(c),children:dW(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":gx(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,IT)/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:sw(h,f)}),n.jsx("span",{className:"cal-event-title",children:h.title})]},h.id))},c))]})})]})})}const wW=3;function yW({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=eE(o,c);return n.jsx(Ge,{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=nw(r,f),p=m.slice(0,wW),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":`${Or(f)}, ${v}`,"aria-pressed":f===i,children:RT(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":gx(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:Gi(j.from)})," ",b.title]})},b.id)),g>0?n.jsxs("button",{type:"button",className:"cal-more","aria-label":`${g} more on ${Or(f)}`,children:["+",g]}):null]},f)})},h[0]))]})})}const PT={width:1200,height:200,top:28,right:12,bottom:24,left:36};function bW(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 Bu(e,t){return t==="temp"?`${e}°`:t==="percent"?`${e}%`:String(e)}function kW(e){const t=PT,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=>Yi(t.left+l*(j+.5)),c=e.values.filter(j=>j!==null&&Number.isFinite(j)),u=bW(c,e.unit),h=u[0],f=u[u.length-1],m=j=>Yi(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:Yi(j.x-l*.28),y:j.y,width:Yi(l*.56),height:Yi(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 NW({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=kW(v),j=PT,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 T,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=(T=m.current)==null?void 0:T.children[C])==null?void 0:R.querySelector("button"))==null||I.focus())};return n.jsxs(Ge,{...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:Bu(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:Bu(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:Yi(j.left+b.slot*N.index),y:0,width:Yi(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 ${Bu(Math.min(...w),v.unit)}, highest ${Bu(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:Wl(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,T)=>n.jsx("span",{className:"wb-tile-line",children:C},T))]})})},S))})]})]})}function Yi(e){return Math.round(e*10)/10}const rw=d.createContext(null),dh=d.createContext(!1);function $t(){const e=d.useContext(rw);if(!e)throw new Error("a plugin page component outside a plugin page");return e}function xx(e,t=new Set){if(Array.isArray(e))for(const s of e)xx(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))xx(r,t)}return t}function MT(e,t){if(t.size===0)return!1;for(const s of xx(e))if(t.has(s))return!0;return!1}function DT(){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 OT({revealed:e,onToggle:t}){return n.jsx(E,{size:"sm",variant:"ghost","aria-pressed":e,onClick:t,children:e?"Hide":"Show"})}function LT(){return n.jsx("p",{className:"muted",children:"Hidden until you show it."})}function FT({children:e}){const[t,s]=DT();return n.jsxs(le,{gap:"sm",children:[n.jsx(ae,{align:"end",children:n.jsx(OT,{revealed:t,onToggle:s})}),t?n.jsx(dh.Provider,{value:!0,children:e}):n.jsx(LT,{})]})}function iw(e){return e===void 0||e==="neutral"?void 0:e}function vx(e){return iw(e)}function SW(e){const t=iw(e);return t==="accent"?void 0:t}function Ns(e,t){if(!t)return!0;const s=Ce(e,t.path),r=t.in!==void 0?t.in.includes(s):s===t.equals;return t.not===!0?!r:r}function aw(e,t,s){if("chat"in t){const a=Ve(s,t.chat);return a==null?"":st(String(a))}if("proposals"in t)return I4(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:Ve(s,t.item);return fr(e.plugin,t.page,i==null?null:String(i))}function lw(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=Ce(t.row,r);return i==null?"":String(i)})}function jx(e,t){if(e===void 0)return;if(typeof e=="string")return e;const s=Ve(t,e);return s==="good"||s==="warning"||s==="critical"||s==="neutral"?s:void 0}function _T(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=Ve(t,a),!(l==null||l==="")&&(r[i]=String(l))}return r}function ba(e,t){var r,i,a;const s={};for(const[l,o]of Object.entries(e??{}))if("row"in o)s[l]=Ce(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]=Ve(t.data,o);return s}function Dn(e,t,s,r){const i=$t(),a=e?{..._T(e.params,t,i),...r}:{},l=JSON.stringify([(e==null?void 0:e.query)??null,a,i.version]),o=de(()=>e?A.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 qc(){const e=$t(),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=Ve(x,j.done);return w==null?null:String(w)},p=(j,x,w)=>{const y=j??"refresh";if(typeof y=="object"){const k=aw(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 A.pageAct(e.plugin,{tool:j.tool,args:x});if(y.approvalId){u(y.approvalId),f({then:j.then,ref:j,...w?{onDone:w}:{}});return}u(null),f(null);const k=ST(y.result);o(m(j,y.result)??(k?CT(y.result):null)),k&&await AT(k,t),p(j.then,y.result,w)}catch(y){a(y instanceof Error?y.message:String(y)),e.refresh()}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 Kl({action:e,args:t,disabled:s,running:r,count:i,row:a,onRun:l}){const[o,c]=d.useState(!1),u=f=>lw(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(E,{variant:"ghost",onClick:()=>c(!1),children:"Cancel"}),n.jsxs(E,{variant:e.tone==="danger"?"danger":"accent",disabled:s,onClick:()=>{c(!1),l(e,t)},children:["Yes, ",h.toLowerCase()]})]}):n.jsx(E,{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 hh({id:e,onDecided:t}){const s=$t(),r=de(()=>A.approval(e),[e,s.version]),{busy:i,note:a,failure:l,decide:o}=Xj(c=>{t?t(c):s.refresh()});return r.error?n.jsx(ie,{message:r.error}):r.data?n.jsxs(le,{children:[n.jsx(Zj,{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(ie,{message:l})]}):n.jsx(pe,{children:"Loading the approval…"})}function Vl({act:e}){return e.error?n.jsx(ie,{message:e.error}):e.approvalId?e.waiting?n.jsxs(le,{children:[n.jsx(V,{role:"status",children:e.waiting}),n.jsx(hh,{id:e.approvalId,onDecided:e.settle})]}):n.jsx(hh,{id:e.approvalId,onDecided:e.settle}):e.done?n.jsx(V,{tone:"good",role:"status",children:e.done}):null}function kc(e,t){const s={};for(const r of e){const i=r.from===void 0?void 0:Ce(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 zT(e,t,s){const r=$t(),i=e.optionsFrom,a=i?{..._T(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?A.pageQuery(r.plugin,i.query.query,a).then(c=>c.data):Promise.resolve(void 0),[l]);return i?{options:gr(o.data,i.rows).map(c=>({value:String(Ce(c,i.value)??""),label:String(Ce(c,i.label)??"")})),loading:o.loading}:{options:e.options??[],loading:!1}}function CW({field:e,fields:t,value:s,values:r,data:i,disabled:a,compact:l,onChange:o}){const c=zT(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(WU,{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(EW,{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"?AW(m.target.value):m.target.value)})})}function EW({field:e,action:t,fields:s,values:r,data:i,disabled:a,hint:l,children:o}){const c=$t(),u=d.useId(),h=nW()===u,[f,m]=d.useState(!1),[p,g]=d.useState(null),[v,b]=d.useState(null),[j,x]=d.useState(null);d.useEffect(()=>()=>y0(u),[u]);const w=ow(s,r,i),y=t.args!==void 0?ba(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){y0(u);return}m(!0),g(null),b(null),x(null);try{const S=await A.pageAct(c.plugin,{tool:t.tool,args:y});if(S.approvalId){x(S.approvalId);return}g(CT(S.result));const C=ST(S.result);C&&await AT(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(E,{"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(ie,{message:v}):j?n.jsx(hh,{id:j,onDecided:()=>x(null)}):p?n.jsx("span",{className:"ui-field-hint",role:"status",children:p}):null,children:o})}function AW(e){if(e.trim()==="")return"";const t=Number(e);return Number.isFinite(t)?t:e}function UT(e,t){return{...typeof t=="object"&&t!==null?t:{},...e}}function ow(e,t,s){const r=UT(t,s);return new Set(e.filter(i=>i.when!==void 0&&!Ns(r,i.when)||i.disabledWhen!==void 0&&Ns(r,i.disabledWhen)).map(i=>i.name))}function bf({fields:e,values:t,data:s,disabled:r,compact:i,columns:a,onChange:l}){const o=UT(t,s);return n.jsx(Bs,{dense:i,columns:a,children:e.filter(c=>c.when===void 0||Ns(o,c.when)).map(c=>n.jsx(CW,{field:c,fields:e,compact:i,value:t[c.name],values:t,data:s,disabled:r===!0||c.disabledWhen!==void 0&&Ns(o,c.disabledWhen),onChange:u=>l(c.name,u)},c.name))})}const Nc=d.createContext(!1),BT=d.createContext(!1),WT=d.createContext(!1);function ds({title:e,note:t,actions:s,children:r}){const i=d.useContext(Nc);return n.jsx(ue,{title:e,aside:t,actions:s,panel:i,children:n.jsx(Nc.Provider,{value:!1,children:n.jsx(BT.Provider,{value:i,children:r})})})}function pr({component:e,data:t,choose:s,chosen:r}){const i=$t(),a=d.useContext(dh);if(!Ns(t,e.when))return null;if(e.kind!=="section"&&!a&&MT(e,i.sensitive))return n.jsx(FT,{children:n.jsx(pr,{component:e,data:t,...s?{choose:s}:{},...r===void 0?{}:{chosen:r}})});switch(e.kind){case"section":return n.jsx(TW,{component:e,data:t});case"notice":return n.jsx(V,{tone:iw(e.tone),title:e.title,children:typeof e.text=="string"?e.text:String(Ve(t,e.text)??"")});case"link":return n.jsx($W,{component:e,data:t});case"progress":return n.jsx(IW,{component:e,data:t});case"chart":return n.jsx(PW,{component:e,data:t});case"stats":return n.jsx(MW,{component:e,data:t});case"list":return n.jsx(OW,{component:e,data:t,...s?{onChoose:s}:{},...r===void 0?{}:{chosen:r}});case"table":return n.jsx(FW,{component:e,data:t});case"detail":return n.jsx(UW,{component:e,data:t});case"form":return n.jsx(BW,{component:e,data:t});case"search":return n.jsx(KW,{component:e,data:t});case"list-detail":return n.jsx(VW,{component:e,data:t});case"repeat":return n.jsx(GW,{component:e,data:t});case"calendar":return n.jsx(YW,{component:e,data:t});case"tiles":return n.jsx(qW,{component:e,data:t});case"series-panel":return n.jsx(JW,{component:e,data:t});case"hero":return n.jsx(QW,{component:e,data:t});case"tabs":return n.jsx(XW,{component:e,data:t});case"expand":return n.jsx(ZW,{component:e,data:t});case"button":return n.jsx(eH,{component:e,data:t});case"approval":return n.jsx(nH,{component:e,data:t});case"artifact":return n.jsx(sH,{component:e,data:t});case"editor":return n.jsx(rH,{component:e,data:t});case"agent-offer":return n.jsx(tH,{component:e});default:return n.jsx(V,{children:"This page uses a part this dashboard does not know yet. Reload buddi to see it."})}}function TW({component:e,data:t}){const s=$t(),r=d.useContext(dh),[i,a]=DT(),l=!r&&MT(e.body,s.sensitive),o=l&&!i,c=d.useContext(Nc);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(ds,{title:e.title,note:e.note,actions:m.length>0||l?n.jsxs(n.Fragment,{children:[m.map((p,g)=>n.jsx(pr,{component:p,data:t},g)),l?n.jsx(OT,{revealed:i,onToggle:a}):null]}):void 0,children:n.jsx(le,{gap:"lg",divided:c,children:o?n.jsx(LT,{}):n.jsx(dh.Provider,{value:r||l,children:f.map((p,g)=>n.jsx(pr,{component:p,data:t},g))})})})}function $W({component:e,data:t}){const s=$t(),r=aw(s,e.to,t);return r===""?null:n.jsx(ae,{children:n.jsx(Et,{href:r,onClick:i=>{i.preventDefault(),s.navigate(r)},children:e.label})})}function C0(e){return Math.round(e/1e6)}function RW(e,t){const s=ns(Ve(t,e.value))??0,r=e.total?ns(Ve(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?`${C0(s)} of ${Math.max(1,C0(r))} MB · ${l}%`:`${l}%`;return{percent:l,full:o,line:c}}function IW({component:e,data:t}){const s=c=>c===void 0?"":typeof c=="string"?c:String(Ve(t,c)??""),r=s(e.label),i=s(e.done),{percent:a,full:l,line:o}=RW(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($A,{value:a,label:r||"Progress"}),n.jsx("span",{role:"status",children:o})]})]})}function PW({component:e,data:t}){const s=Dn(e.query,t),r=e.rows===void 0?Array.isArray(s.data)?s.data:[]:gr(s.data,e.rows),i=r.map(h=>String(Ce(h,e.x)??"")),a=h=>r.map(f=>ns(Ce(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?ns(Ve(s.data,e.target))??null:null;return n.jsxs(ds,{title:e.title,note:e.note,children:[n.jsx(ie,{message:s.error}),r.length===0?s.loading||s.data===void 0?n.jsx(pe,{children:"Loading…"}):n.jsx(Gl,{text:e.empty??"Nothing recorded yet."}):n.jsx(DU,{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)?Fg(h):h,formatY:h=>tn(h,"number",null)})]})}function MW({component:e,data:t}){const s=Dn(e.query,t);return n.jsxs(ds,{title:e.title,note:e.note,children:[n.jsx(ie,{message:s.error}),s.data===void 0?n.jsx(pe,{children:e.empty??"Loading…"}):n.jsx(vf,{children:e.items.map((r,i)=>n.jsx(ar,{label:r.label,value:tn(Ve(s.data,r.value),r.unit??"text",null),tone:SW(r.tone)},i))})]})}function HT(e,t,s,r){const i=(t.meta??[]).map(u=>String(Ve(s,u)??"")).filter(u=>u!==""),a=String(Ve(s,t.title)??""),l=t.to&&!r?aw(e,t.to,s):null,c=[...t.pill?[t.pill]:[],...t.pills??[]].map((u,h)=>{const f=Ve(s,u.value);if(f==null||f==="")return null;const m=DW(u,f,s);return n.jsx(we,{tone:vx(m.tone),children:m.text},h)});return{text:a,href:l,pills:n.jsx(n.Fragment,{children:c}),meta:i.join(" · "),title:l?n.jsx("a",{href:l,onClick:u=>{u.preventDefault(),e.navigate(l)},children:a}):a,sub:t.sub?String(Ve(s,t.sub)??""):null,side:n.jsxs(n.Fragment,{children:[c,i.length>0?n.jsxs("span",{className:"muted",children:[" ",i.join(" · ")]}):null]})}}function DW(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]:jx(e.tone,s)}}function gr(e,t){const s=Ce(e,t);return Array.isArray(s)?s:[]}function KT(e,t,s){const r=[],i=new Set;return e.forEach((a,l)=>{const o=t===void 0?void 0:Ce(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 OW({component:e,data:t,onChoose:s,chosen:r}){var N;const i=$t(),a=d.useContext(WT),l=Dn(e.query,t),o=qc(),[c,u]=d.useState([]),h=a&&!e.select&&(e.actions??[]).length===0&&(e.bulk??[]).length===0,f=gr(l.data,e.rows),m=e.collapsed?gr(l.data,e.collapsed.rows):[],p=VT(e.actions,f,o),g={plugin:i.plugin,page:i.page,component:`list "${e.title??e.rows}"`},v=KT([...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||!Ns(S,e.select.disabledWhen)}).map(({key:S})=>S)),w=c.filter(S=>x.has(S)),y=d.useMemo(()=>{const S=f.filter(T=>j.has(T));if(!e.groupBy)return[{label:null,rows:S}];const C=new Map;for(const T of S){const R=String(Ce(T,e.groupBy.key)??"");C.set(R,[...C.get(R)??[],T])}return[...C].map(([T,R])=>{var I,L;return{label:((L=(I=e.groupBy)==null?void 0:I.labels)==null?void 0:L[T])??T,rows:R}})},[f,e.groupBy,v.length]),k=S=>S.map(C=>{var _;const T=HT(i,e.item,C,s),R=b.get(C);if(h&&(s||T.href))return n.jsx(RA,{href:T.href??"#",current:r===R,onClick:()=>s?s(R):i.navigate(T.href),title:T.text,meta:T.meta,sub:T.sub,side:T.pills},R);const I=((_=e.select)==null?void 0:_.disabledWhen)!==void 0&&Ns(C,e.select.disabledWhen),L=(e.actions??[]).filter($=>Ns(C,$.when));return n.jsx(et,{lead:e.select?n.jsx("input",{type:"checkbox","aria-label":`Select ${T.text}`,disabled:I,checked:c.includes(R),onClick:$=>$.stopPropagation(),onChange:$=>u(P=>$.target.checked?[...P,R]:P.filter(O=>O!==R))}):void 0,title:s?n.jsx("a",{href:"#","aria-current":r===R?"true":void 0,onClick:$=>{$.preventDefault(),s(R)},children:T.text}):T.title,sub:T.sub,side:n.jsxs(n.Fragment,{children:[T.side,L.map(($,P)=>n.jsx(GT,{action:$,row:C,data:l.data,act:o,onForm:p.show},P))]})},R)});return n.jsxs(ds,{title:e.title,note:e.note,children:[n.jsx(ie,{message:l.error}),p.open?null:n.jsx(Vl,{act:o}),p.open?n.jsx(YT,{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(Gl,{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.jsx("div",{className:"ui-list-group",children:S.label}):null,k(S.rows)]},C))]}),e.collapsed&&m.some(S=>j.has(S))?n.jsx(At,{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 T=w.length>0||S.all!==!0?w:[...x];return n.jsx(Kl,{action:S,args:ba(S.args,{data:l.data,selected:T,scope:i}),count:T.length,disabled:o.busy||T.length===0,running:o.running===S.tool,onRun:(R,I)=>{u([]),o.run(R,I)}},C)})]}):null]})}function LW(e,t,s){return Object.entries(e).every(([r,i])=>{const a=typeof i=="string"?i:Ce(s,i.row);return a!=null&&t[r]===String(a)})}function VT(e,t,s){const r=$t(),[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=>Ns(h,o.when)&&LW(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 GT({action:e,row:t,data:s,act:r,onForm:i}){const a=$t();return e.form?n.jsx(E,{disabled:r.busy,onClick:()=>i(e,t),children:lw(e.label,{row:t})}):n.jsx(Kl,{action:e,args:ba(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 YT({open:e,data:t,act:s,onClose:r,onDone:i}){const a=$t(),{action:l,row:o}=e,c=l.form,[u,h]=d.useState(()=>kc(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(qe,{title:lw(c.title,{row:o}),onClose:r,foot:n.jsxs(ae,{align:"end",children:[n.jsx(E,{variant:"ghost",onClick:r,children:"Cancel"}),n.jsx(Kl,{action:g,args:ba(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(bf,{fields:c.fields,values:u,data:o,onChange:(v,b)=>h(j=>({...j,[v]:b}))}),n.jsx(ie,{message:s.error})]})})}function FW({component:e,data:t}){const s=Dn(e.query,t),r=qc(),i=gr(s.data,e.rows),a=VT(e.actions,i,r);return n.jsxs(ds,{title:e.title,note:e.note,children:[n.jsx(ie,{message:s.error}),a.open?null:n.jsx(Vl,{act:r}),a.open?n.jsx(YT,{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(Gl,{text:e.empty??"Nothing here yet."}):n.jsxs(wr,{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:tn(Ce(l,c.key),c.type??"text",null);return n.jsx("td",{"data-fit":c.fit,title:_W(c,l,u),children:c.pill?n.jsx(zW,{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=>Ns(l,c.when)).map((c,u)=>n.jsx(GT,{action:c,row:l,data:s.data,act:r,onForm:a.show},u))})}):null]},o))})]})]})}function _W(e,t,s){if(e.hint){const r=Ce(t,e.hint);if(r!=null&&r!=="")return String(r)}return e.fit==="truncate"&&s?s:void 0}function zW({column:e,row:t}){var l,o;const s=Ce(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)]:tn(f,e.type??"text",null);return n.jsx(we,{tone:vx(jx(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]:tn(s,e.type??"text",null);return n.jsx(we,{tone:vx(jx((o=e.pill)==null?void 0:o.tone,t)),children:a})}function UW({component:e,data:t}){const s=Dn(e.query,t);return s.error?n.jsx(ie,{message:s.error}):s.data===void 0?n.jsx(pe,{children:e.empty??"Loading…"}):n.jsx(ds,{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:tn(Ve(s.data,r.value),r.unit??"text",null)}))}):null,e.body.map((r,i)=>n.jsx(pr,{component:r,data:s.data},i))]})})}function BW({component:e,data:t}){const s=$t(),r=Dn(e.initial,t),i=qc(),[a,l]=d.useState(!1),o=JSON.stringify([r.data??null,s.version]),c=n.jsx(WW,{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(E,{variant:"accent",onClick:()=>l(!0),children:e.drawer.button}),children:[n.jsx(Vl,{act:i}),a?n.jsx(qe,{title:e.drawer.title,onClose:()=>l(!1),children:c}):null]}):n.jsxs(ds,{title:e.title,note:e.note,children:[n.jsx(ie,{message:r.error}),c]})}function WW({component:e,data:t,initialData:s,act:r,onDone:i}){const a=d.useContext(BT),l=$t(),[o,c]=d.useState(()=>kc(e.fields,s)),u=ow(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(bf,{fields:e.fields,columns:e.columns,values:o,data:s,onChange:(f,m)=>c(p=>({...p,[f]:m}))}),e.drawer?null:n.jsx(Vl,{act:r}),n.jsx(ae,{align:"end",className:a?"ui-panel-foot":void 0,children:n.jsx(Kl,{action:e.submit,args:ba(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 HW(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 E0(e){return e!=null&&e!==""&&e!==!1&&e!=="false"}function KW({component:e,data:t}){const s=$t(),[r,i]=d.useState(()=>kc(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=Dn(a&&u?e.query:void 0,t),f=gr(h.data,e.rows),m=e.count===void 0?void 0:Ce(h.data,e.count),p=e.note===void 0?void 0:Ce(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(T=>[T.name,String(C[T.name]??"")||null]))),l(!0)},j=(C,T)=>{const R={...r,[C]:T};i(R),e.auto&&b(R)},x=()=>{const C=kc(e.fields,null);i(C),e.auto?b(C):(s.setParams(Object.fromEntries(e.fields.map(T=>[T.name,null]))),l(!1))},w=a?v.filter(C=>E0(s.params[C.name])):[],y=g?w.map(C=>n.jsx(eh,{label:C.label,onRemove:()=>{const T={...r,[C.name]:C.type==="checkbox"?!1:""};i(T),b(T)},children:HW(C,String(s.params[C.name]))},C.name)):[],k=v.filter(C=>E0(r[C.name])).length,N=e.auto&&!e.reset?null:n.jsxs(n.Fragment,{children:[e.reset?n.jsx(E,{variant:"ghost",onClick:x,children:"Clear"}):null,e.auto?null:n.jsx(E,{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(ds,{title:e.title,children:n.jsxs(le,{children:[n.jsx(MA,{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(bf,{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(ie,{message:h.error}),a&&(m!==void 0||p!==void 0)?n.jsxs("p",{className:"ui-card-meta",children:[m===void 0?"":`${tn(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,T)=>{const R=HT(s,S,C);return n.jsx(et,{title:R.title,sub:R.sub,side:R.side},T)})})}):null]})})}function VW({component:e,data:t}){const s=$t(),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(pr,{component:u,data:t},h))});return n.jsx(Nc.Provider,{value:!1,children:n.jsx(IA,{list:n.jsx(WT.Provider,{value:!0,children:n.jsx(pr,{component:e.list,data:t,chosen:l??null,...r?{choose:a}:{}})}),detail:l?o?n.jsx(rw.Provider,{value:o,children:c}):c:void 0,empty:e.empty??"Choose one to see it here."})})}function GW({component:e,data:t}){const s=$t(),[r,i]=d.useState(!1),a=Dn(e.query,t,r&&e.poll?e.poll.seconds*1e3:void 0),l=e.poll!==void 0&&a.data!==void 0&&Ns(a.data,e.poll.while);d.useEffect(()=>i(l),[l]);const o=gr(a.data,e.rows);return n.jsxs(ds,{title:e.title,note:e.note,children:[n.jsx(ie,{message:a.error}),o.length===0?a.loading?n.jsx(pe,{children:"Loading…"}):n.jsx(Gl,{text:e.empty??"Nothing here yet."}):n.jsx(le,{gap:"lg",divided:!0,children:KT(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(pr,{component:h,data:u},f))})},c))})]})}function YW({component:e,data:t}){const s=$t(),r=xW({...e.views?{views:e.views}:{},...e.default?{default:e.default}:{},today:iW(s.timezone),storageKey:`buddi.calendar-view:${s.plugin}/${s.page}`}),i=Dn(e.query,t,void 0,{from:r.from,to:r.to}),a=d.useMemo(()=>cW(gr(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(ds,{title:e.title,note:e.note,children:[n.jsx(ie,{message:i.error}),n.jsx(vW,{state:r,events:a,hours:e.hours,empty:e.empty??"Nothing.",label:e.title??"Calendar"})]})}function qW({component:e,data:t}){var f;const s=$t(),r=Dn(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=gr(r.data,e.items).flatMap(m=>{const p=Pj([m],i).tiles[0];return p?[{tile:p,key:e.select?String(Ce(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(ds,{title:e.title,note:e.note,children:[n.jsx(ie,{message:r.error}),r.data===void 0?n.jsx(pe,{children:"Loading…"}):a.length===0?n.jsx(Gl,{text:e.empty??"Nothing to show."}):n.jsx(VA,{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 JW({component:e,data:t}){const s=Dn(e.query,t),r=gr(s.data,e.points);if(s.data===void 0||r.length===0)return n.jsxs(ds,{title:e.title,note:e.note,children:[n.jsx(ie,{message:s.error}),s.data===void 0?n.jsx(pe,{children:"Loading…"}):n.jsx(Gl,{text:e.empty??"Nothing to show."})]});const i=r.map(c=>String(Ce(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)=>Pj([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=>ns(Ce(u,c.y))??null)}));return n.jsxs(n.Fragment,{children:[n.jsx(ie,{message:s.error}),n.jsx(NW,{...e.title?{title:e.title}:{},...e.note?{note:e.note}:{},...e.labelEvery?{labelEvery:e.labelEvery}:{},xs:i,series:o,tiles:l})]})}function QW({component:e,data:t}){const s=Dn(e.query,t),r=o=>{const c=Ce(s.data,o);return c==null?"":String(c)};if(s.data===void 0||s.data===null)return n.jsxs(n.Fragment,{children:[n.jsx(ie,{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:Wl(Gg(Ve(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 XW({component:e,data:t}){var u;const s=$t(),[r,i]=d.useState(e.default??e.tabs[0].id),a=e.pick,{options:l}=zT({name:(a==null?void 0:a.param)??"",label:(a==null?void 0:a.label)??"",...a!=null&&a.options?{options:a.options}:{},...a!=null&&a.optionsFrom?{optionsFrom:a.optionsFrom}:{}},{},t),o=a?l.some(h=>h.value===s.params[a.param])?s.params[a.param]:((u=l[0])==null?void 0:u.value)??"":"",c=e.tabs.find(h=>h.id===r)??e.tabs[0];return n.jsxs("div",{className:"pg-tabs",children:[n.jsxs("div",{className:"pg-tabs-bar","data-only":e.tabs.length===1?"pick":void 0,children:[a&&l.length>1?n.jsx(Yt,{label:a.label,options:l,value:o,onChange:h=>s.setParams({[a.param]:h})}):null,e.tabs.length>1?n.jsx(Yt,{label:e.title??"View",options:e.tabs.map(h=>({value:h.id,label:h.label})),value:c.id,onChange:i}):null]}),c.body.map((h,f)=>n.jsx(pr,{component:h,data:t},`${c.id}-${f}`))]})}function ZW({component:e,data:t}){const[s,r]=d.useState(!1),i=Dn(s?e.query:void 0,t),a=typeof e.label=="string"?e.label:String(Ve(t,e.label)??"");return n.jsxs(At,{summary:a,boxed:!0,onToggle:l=>r(l),children:[n.jsx(ie,{message:i.error}),i.data===void 0?n.jsx(pe,{children:"Loading…"}):n.jsx(le,{children:e.body.map((l,o)=>n.jsx(pr,{component:l,data:i.data},o))})]})}function eH({component:e,data:t}){const s=$t(),r=qc();return n.jsxs(n.Fragment,{children:[n.jsx(ae,{align:"end",children:n.jsx(Kl,{action:e.action,args:ba(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(Vl,{act:r})]})}function tH({component:e}){const t=$t();return n.jsx(tw,{plugin:t.plugin,agent:e.agent,text:e.text,label:e.label})}function nH({component:e,data:t}){const s=Ce(t,e.path);return typeof s!="string"||s===""?null:n.jsx(hh,{id:s})}function sH({component:e,data:t}){const s=Ce(t,e.path);return typeof s!="string"||s===""?null:n.jsx(ae,{children:n.jsx("a",{href:Si(s),children:e.label})})}function rH({component:e,data:t}){const s=Dn(e.query,t),r=qc();return s.error?n.jsx(ie,{message:s.error}):s.data===void 0?n.jsx(pe,{children:e.empty??"Loading…"}):n.jsxs(n.Fragment,{children:[n.jsx(Vl,{act:r}),n.jsx(iH,{component:e,data:t,loaded:s.data,act:r},JSON.stringify(s.data))]})}function iH({component:e,data:t,loaded:s,act:r}){const i=$t(),[a,l]=d.useState(()=>kc(e.fields,s)),o={...a,version:Ce(s,e.version)},c=ow(e.fields,a,s),u=e.readOnlyWhen!==void 0&&Ns(s,e.readOnlyWhen),h=(e.actions??[]).filter(p=>p.placement==="leading"),f=(e.actions??[]).filter(p=>p.placement!=="leading"),m=(p,g)=>n.jsx(Kl,{action:p,args:ba(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(ds,{title:e.title,note:e.note,children:n.jsxs(le,{children:[n.jsx(bf,{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(dt,{}):null,m(e.save,-1),f.map(m)]}),e.footnote?n.jsx("p",{className:"ui-toolbar-note",children:e.footnote}):null]})})}function cw({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}:{},...lH(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"&&typeof p.text=="string"&&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(rw.Provider,{value:m,children:n.jsx(Mn,{embedded:i,title:e.title,lede:g,children:n.jsx(aH,{page:v,boxed:i===!0})})})}function aH({page:e,boxed:t}){const s=$t();return e.data&&s.sensitive.has(e.data.query)?n.jsx(FT,{children:n.jsx(A0,{page:e,boxed:t})}):n.jsx(A0,{page:e,boxed:t})}function A0({page:e,boxed:t}){const s=Dn(e.data,null);return n.jsxs(le,{gap:"lg",divided:!t,children:[n.jsx(ie,{message:s.error}),n.jsx(Nc.Provider,{value:t,children:e.body.map((r,i)=>n.jsx(pr,{component:r,data:s.data??null},i))})]})}function lH(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 oH(e){return n.jsx(cw,{...e,embedded:!0})}function Gl({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($n,{title:s,children:r||null})}const T0=[{id:"",label:"All files"},{id:"produced",label:"Created by agents"},{id:"uploaded",label:"Uploaded by you"}],cH=["","image","pdf","table","text","code","audio","video","archive","file"];function uH({hash:e,timezone:t,navigate:s,agents:r}){var _;const i=x4(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=($,P=!1)=>s($u(a,{q:c,origin:l,family:o,...$}),P);d.useEffect(()=>{if(u===c)return;const $=window.setTimeout(()=>f({q:u},!0),250);return()=>window.clearTimeout($)},[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=$=>{var P;return $?((P=r.find(O=>O.id===$))==null?void 0:P.name)??$:""},S=d.useRef(0);d.useEffect(()=>{const $=++S.current;p(null),v(null),w(!1),j(null),A.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{}}).then(P=>{S.current===$&&(p(P.entries),v(P.next))}).catch(P=>{S.current===$&&j(P instanceof ve?P.message:String(P))})},[c,l,o]);const C=()=>{if(!g||x)return;w(!0);const $=S.current;A.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{},cursor:g}).then(P=>{S.current===$&&(p(O=>{const M=new Set((O??[]).map(D=>D.id));return[...O??[],...P.entries.filter(D=>!M.has(D.id))]}),v(P.next))}).catch(P=>{S.current===$&&j(P instanceof ve?P.message:String(P))}).finally(()=>{S.current===$&&w(!1)})},T=(l?1:0)+(o?1:0),R=((_=T0.find($=>$.id===l))==null?void 0:_.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($=>n.jsx(RA,{href:$u($.id,{q:c,origin:l,family:o}),current:$.id===a,onClick:()=>s($u($.id,{q:c,origin:l,family:o})),lead:n.jsx("span",{className:"files-row-visual","data-family":$.family,children:$.family==="image"&&!$.deleted?n.jsx("img",{src:Gr($.id),alt:"",loading:"lazy"}):n.jsx(Yj,{family:$.family})}),title:$.filename??"Untitled file",meta:n.jsx("span",{title:nt($.createdAt,t),children:Le($.createdAt)}),sub:`${$.caption&&$.origin==="produced"?`${$.caption} · `:""}${na[$.family]} · ${Gn($.sizeBytes)} · ${qT($,N)}${dH($,N)}`},$.id))}),g?n.jsx("div",{className:"files-more",children:n.jsx(E,{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($n,{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(MA,{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:$=>h($.target.value)}),filters:n.jsxs(Bs,{dense:!0,children:[n.jsx(oe,{label:"Origin",children:n.jsx("select",{value:l,"aria-label":"Origin",onChange:$=>f({origin:$.target.value}),children:T0.map($=>n.jsx("option",{value:$.id,children:$.label},$.id))})}),n.jsx(oe,{label:"Kind",children:n.jsx("select",{value:o,"aria-label":"Kind",onChange:$=>f({family:$.target.value}),children:cH.map($=>n.jsx("option",{value:$,children:$===""?"Any kind":na[$]},$))})})]}),filtersOpen:y,onToggleFilters:()=>k($=>!$),active:T,chips:T>0?n.jsxs(n.Fragment,{children:[l?n.jsx(eh,{label:"Origin",onRemove:()=>f({origin:""}),children:R}):null,o?n.jsx(eh,{label:"Kind",onRemove:()=>f({family:""}),children:na[o]}):null]}):void 0}),n.jsx(ie,{message:b}),n.jsx(IA,{className:"files-split",label:"Files",list:I,detail:a?n.jsx(hH,{id:a,timezone:t,agents:r,navigate:s,onBack:()=>s($u(null,{q:c,origin:l,family:o}))},a):void 0,empty:"Choose a file to see it here."})]})]})}function dH(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 qT(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 hH({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),A.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(E,{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),A.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(E,{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(Yj,{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:[na[m.family]," · ",Gn(m.sizeBytes)," · ",nt(m.createdAt,t)]})]}),v?n.jsx(tT,{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(eT,{artifactId:m.id,filename:m.filename,mime:m.mime,family:m.family,available:v}),n.jsx(Gt,{items:[{label:"Origin",value:qT(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(on,{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?Vi(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"," · ",Le(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(E,{size:"sm",onClick:j,disabled:o,children:o?"Loading…":`Show ${g-p.length} more`})}):null]})]})}const fH={mail:"mail",money:"money",calendar:"calendar",people:"agents",file:"files",chart:"chart",bell:"bell",plug:"plug",key:"key",globe:"globe",sun:"sun",cloud:"cloud"};function JT(e){return e&&fH[e]||"plug"}const QT="buddi.keepClose";let kl=null;const wx=new Set;function yx(){for(const e of wx)e()}typeof window<"u"&&(window.addEventListener("beforeinstallprompt",e=>{e.preventDefault(),kl=e,yx()}),window.addEventListener("appinstalled",()=>{kl=null,dw(),yx()}));function kf(){const[e,t]=d.useState(kl);return d.useEffect(()=>{const s=()=>t(kl);return wx.add(s),s(),()=>{wx.delete(s)}},[]),XT()?null:e}async function uw(e){try{await e.prompt();const t=await e.userChoice;kl===e&&(kl=null);const s=(t==null?void 0:t.outcome)==="accepted";return s&&dw(),yx(),s}catch{return!1}}function mH(){try{return window.localStorage.getItem(QT)!==null}catch{return!1}}function dw(){try{window.localStorage.setItem(QT,"dismissed")}catch{}}function XT(){var e;try{return((e=window.matchMedia)==null?void 0:e.call(window,"(display-mode: standalone)").matches)??!1}catch{return!1}}function pH(e=window.location.hostname){const t=e.replace(/^\[|\]$/g,"").toLowerCase();return t==="127.0.0.1"||t==="::1"||t==="localhost"}function ZT(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 gH(e){return/Mac|iPhone|iPad/.test(e)}function xH(){const e=kf(),[t,s]=d.useState(mH);if(t||!e)return null;const r=()=>{dw(),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(E,{size:"sm",variant:"ghost",onClick:r,children:"Not now"}),n.jsx(E,{size:"sm",variant:"accent",onClick:()=>{uw(e).then(i=>{i&&s(!0)})},children:"Install"})]})]})}function vH(){const e=kf(),[t,s]=d.useState(void 0),[r]=d.useState(XT);if(d.useEffect(()=>{if(r)return;let o=!0;return A.session().then(c=>{o&&s(c.platform)},()=>{}),()=>{o=!1}},[r]),r)return null;const i=typeof navigator>"u"?"":navigator.userAgent,a=pH(),l=e?null:ZT(i);return n.jsx(ue,{title:"The dashboard as an app",panel:!0,foot:e?n.jsx(ae,{align:"end",children:n.jsx(E,{variant:"accent",onClick:()=>{uw(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 ",gH(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 jH=""+new URL("earth-2560-Ce3xs8Cb.webp",import.meta.url).href,wH=""+new URL("earth-phone-BqC7cDhk.webp",import.meta.url).href,yH="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=",bx={desk:jH,phone:wH,thumb:yH},Ym={author:"ActionVance",authorUrl:"https://unsplash.com/@actionvance",photoUrl:"https://unsplash.com/photos/outer-space-photography-of-earth-t7EL2iG3jMc"};function bH(e){return e?bx.phone:bx.desk}function e$(){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 kH=3,t$=8e3,NH={hiddenHere:new Set,restoredHere:new Set};function SH(e,t){return t.hiddenHere.has(e.id)?!0:e.hidden&&!t.restoredHere.has(e.id)}function CH(e,t=NH){return(e??[]).filter(s=>!SH(s,t)).slice(0,kH)}function n$(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),t$);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}),A.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)),A.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 EH({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(E,{size:"sm",variant:"ghost",onClick:e.undo,children:"Undo"})]})}function AH(e){return e.link?Vj(e.link.plugin,e.link.page,e.link.place):null}function TH({glances:e,navigate:t,onChanged:s,except:r,hiding:i}){var u,h;const a=n$(s),l=i??a,o=CH(e,l).filter(f=>!(r!=null&&r.has(f.id))),c=n.jsx(EH,{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=AH(f),p=n.jsxs(n.Fragment,{children:[n.jsx(ce,{name:Wl(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 $H(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 RH({points:e,className:t="wg-spark"}){const s=$H(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 Ma=Math.PI/180;function IH(e,t,s){const r=e.getTime()/864e5+24405875e-1-2451545,i=(357.529+.98560028*r)*Ma,l=(280.459+.98564736*r+1.915*Math.sin(i)+.02*Math.sin(2*i))*Ma,o=(23.439-36e-8*r)*Ma,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)*Ma-c,m=t*Ma,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)))/Ma}function PH(e,t,s){return IH(e,t,s)>-.833}const MH={small:2,medium:4},$0=new Map;function DH(e){let t=$0.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"}),$0.set(e,t)),t}function R0(e,t){const s=Object.fromEntries(DH(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 OH(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 LH(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 FH(e,t,s,r,i){const a=R0(e,t.zone),l=R0(e,s),o=a.date===l.date?"Today":a.date>l.date?"Tomorrow":"Yesterday",c=a.offset-l.offset,u=Dc(i?{timeFormat:i}:{},()=>zt(e,t.zone)),h=r?"your time":LH(c);return{...a,day:o,daytime:typeof t.latitude=="number"&&typeof t.longitude=="number"?PH(e,t.latitude,t.longitude):a.h>=6&&a.h<18,offsetText:r?"Here":OH(c),time:u,label:`${t.label}, ${u}${o==="Today"?"":` ${o.toLowerCase()}`}, ${h}`}}function _H(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 zH(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 I0({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 UH=Array.from({length:12},(e,t)=>t);function BH({time:e,seconds:t}){const s=_H(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"}),UH.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(I0,{angle:s.hour,length:24,width:4.6}),n.jsx(I0,{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 WH({body:e,size:t}){const s=ks("(prefers-reduced-motion: reduce)"),r=zH(!s),i=e.clocks.slice(0,MH[t]);return n.jsx("div",{className:"wg-clocks","data-count":i.length,children:i.map((a,l)=>{let o;try{o=FH(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(BH,{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 HH=3,KH={small:4,medium:6};function qm({icon:e,size:t}){return e?n.jsx("span",{className:"wg-icon",children:n.jsx(ce,{name:Wl(e),size:t})}):null}function hw({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(qm,{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(RH,{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":return n.jsxs(n.Fragment,{children:[n.jsx("ul",{className:"wg-list",children:e.rows.slice(0,HH).map((s,r)=>n.jsxs("li",{className:"wg-row",children:[n.jsxs("span",{className:"wg-row-text",children:[n.jsx("span",{className:"wg-row-title",children:s.title}),s.sub&&t==="medium"?n.jsx("span",{className:"wg-row-sub",children:s.sub}):null]}),s.side?n.jsx("span",{className:"wg-row-side","data-tone":s.tone,children:s.side}):null]},`${s.title}-${r}`))}),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(qm,{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,KH[t]).map((s,r)=>n.jsxs("span",{className:"wg-tile",children:[n.jsx("span",{className:"wg-tile-label",children:s.label}),n.jsx(qm,{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(WH,{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:Wl(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 kx({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 P0(e){return"place"in e?e.place:`town:${e.latitude.toFixed(3)},${e.longitude.toFixed(3)}`}function VH(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 GH({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(P0(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(P0),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),A.findPlace(y).then(({found:k})=>{const N=k.slice(0,3).map(VH);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(kx,{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(E,{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 YH({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(Yt,{label:e.label,options:l,value:o,onChange:r}):n.jsx(kx,{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(kx,{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(GH,{field:e,value:t,places:s.places,onChange:r});break;case"timeFormat":i=n.jsx(Yt,{label:e.label,options:[{value:"profile",label:Z1()},{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 qH({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(hw,{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 s$({info:e,placement:t,surface:s,onSave:r,onRemove:i,onClose:a}){const l=de(()=>A.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(()=>{A.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(qe,{title:f,onClose:a,foot:n.jsxs(ae,{children:[n.jsxs(E,{variant:"danger-ghost",onClick:i,children:["Remove from ",s==="lock"?"lock screen":"Home"]}),n.jsx(dt,{}),n.jsx(E,{variant:"ghost",onClick:a,children:"Cancel"}),n.jsx(E,{variant:"accent",onClick:w,disabled:p||!l.data,children:p?"Saving…":"Save"})]}),children:n.jsxs("div",{className:"wg-sheet",children:[n.jsx(qH,{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(ie,{message:v??(l.error?"Couldn’t read this widget’s settings.":null)}),l.data?l.data.fields.map(k=>n.jsx(YH,{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 JH=6e4,r$="buddi.clock",i$="buddi.home.widgets";function QH(){try{const e=Number(window.localStorage.getItem(i$));return Number.isInteger(e)&&e>0?Math.min(e,6):0}catch{return 0}}function XH(e){try{window.localStorage.setItem(i$,String(e))}catch{}}function a$(){const e=new Uint8Array(4);return crypto.getRandomValues(e),`w-${Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}`}function l$(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 ZH(){const e=de(()=>A.widgets("home"),[],JH),[t,s]=d.useState(void 0);return d.useEffect(()=>{e.data&&s(e.data)},[e.data]),d.useEffect(()=>{t&&XH(t.home.length)},[t]),l$((t==null?void 0:t.home.some(r=>{var i,a;return r.widget===r$&&((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 eK(e){return new Set(((e==null?void 0:e.home)??[]).map(t=>t.widget))}function tK(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 o$=(e,t)=>e.label??(t==null?void 0:t.title)??e.widget;function nK({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]=tK(e.sensitive===!0),p=(s==null?void 0:s.state)??"error",g=e.sensitive===!0&&!f,v=e.link?Vj(e.link.plugin,e.link.page,e.link.place):null,b=v!==null&&!a&&p!=="error"&&!g,j=t.size==="small"?"medium":"small",x=o$(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:[sK(s.error),"."]}):null,a?null:n.jsx(E,{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(E,{size:"sm",onClick:()=>m(!0),children:"Show"})]}):k=n.jsx(hw,{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?`${lj(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(Di,{label:`More for ${x}`,note:s!=null&&s.updatedAt?`${e.builtIn?"Built in":e.plugin} · ${Le(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 sK(e){const t=e.replace(/\.$/,"");return t.charAt(0).toUpperCase()+t.slice(1)}function rK({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,T]=d.useState(new Set),[R]=d.useState(QH),I=d.useRef(null);if(d.useEffect(()=>{if(!c)return;const U=window.setTimeout(()=>u(null),t$);return()=>window.clearTimeout(U)},[c]),d.useEffect(()=>{var se;const U=I.current;U&&(I.current=null,(se=document.querySelector(`[data-grip="${CSS.escape(U)}"], [data-move="${CSS.escape(U)}"]`))==null||se.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,se)=>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"})]})]},se))})]});if(s.available.every(U=>U.builtIn)&&s.home.length===0)return null;const L=new Map(s.available.map(U=>[U.id,U])),_=i?l:s.home,$=U=>o$(U,L.get(U.widget)),P=(U,se)=>(p(null),r({...se,home:U,arranged:{...se.arranged,home:!0}}),A.saveWidgets("home",U).then(J=>(r(J),!0),J=>(r(se),p(`Couldn't save your widgets: ${J instanceof Error?J.message:String(J)}`),!1))),O=(U,se,J)=>{if(J<0||J>=U.length||se===J)return null;const ye=U.slice(),[ge]=ye.splice(se,1);return ye.splice(J,0,ge),f(`${$(ge)}, position ${J+1} of ${ye.length}.`),ye},M=()=>{o(s.home),T(new Set),u(null),p(null),a(!0)},D=U=>(se,J)=>{const ye=_[U];if(se==="edit"){M();return}if(se==="settings"){S(ye.key);return}if(i){if(se==="earlier"||se==="later"){const ge=O(l,U,se==="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)}}se==="size"&&J&&(o(l.map((ge,$e)=>$e===U?{...ge,size:J}:ge)),T(new Set([...C,ye.key]))),se==="hide"&&(o(l.filter((ge,$e)=>$e!==U)),f(`${$(ye)} taken off.`));return}if(se==="earlier"||se==="later"){const ge=O(s.home,U,se==="earlier"?U-1:U+1);ge&&P(ge,s)}se==="size"&&J&&P(s.home.map((ge,$e)=>$e===U?{...ge,size:J}:ge),s),se==="hide"&&P(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(se=>se.key!==c.item.key);U.splice(Math.min(c.at,U.length),0,c.item),u(null),P(U,s)},B=()=>{v(!0),P(l,s).then(U=>{v(!1),U&&(a(!1),f("Widgets saved."))})},q=U=>{j(U),A.refreshWidget(U).then(r,()=>{}).finally(()=>j(null))},W=U=>{var ye;const se={key:a$(),widget:U.id,size:U.sizes[0],settings:{}},J=l.some(ge=>ge.widget===U.id);o([...l,se]),f(`${U.title} added.`),J&&(((ye=U.settings)==null?void 0:ye.length)??0)>0&&S(se.key)},Y=(U,se)=>i?(o(l.map(J=>{if(J.key!==U)return J;const{label:ye,...ge}=J;return{...ge,settings:se}})),T(new Set([...C,U])),S(null),Promise.resolve(!0)):P(s.home.map(J=>J.key===U?{...J,settings:se}:J),s).then(J=>(J&&(S(null),f("Settings saved.")),J)),F=U=>{S(null);const se=_.findIndex(J=>J.key===U);se>=0&&D(se)("hide")},X={dragging:x,over:y,start:U=>w(U),enter:U=>{y!==U&&k(U)},end:()=>{w(null),k(null)},drop:U=>{const se=l.findIndex(ge=>ge.key===x),J=l.findIndex(ge=>ge.key===U),ye=se>=0&&J>=0?O(l,se,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:[$(c.item)," hidden"]}),n.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),n.jsx(E,{size:"sm",variant:"ghost",onClick:H,children:"Undo"})]},"undo"):null,ee=[];_.forEach((U,se)=>{const J=L.get(U.widget);if(!J)return;c&&!i&&c.at===se&&ee.push(Q);const ye=i&&(C.has(U.key)||!s.home.some(ge=>ge.key===U.key));ee.push(n.jsx(nK,{info:J,placement:U,view:ye?void 0:s.views[U.key],index:se,count:_.length,editing:i,navigate:t,act:D(se),onRetry:()=>q(U.key),retrying:b===U.key,drag:X},U.key))}),c&&!i&&c.at>=_.length&&ee.push(Q);const fe=s.available.filter(U=>!U.builtIn),Oe=fe.length-2,Ie=N?_.find(U=>U.key===N):void 0,Fe=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(E,{size:"sm",variant:"ghost",onClick:()=>{a(!1),o([])},disabled:g,children:"Cancel"}),n.jsx(E,{size:"sm",variant:"accent",onClick:B,disabled:g,children:g?"Saving…":"Done"})]}):_.length>0?n.jsx("div",{className:"ui-toolbar","data-align":"end",children:n.jsx(E,{size:"sm",variant:"ghost",onClick:M,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,_.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(", "),Oe>0?` and ${Oe} more`:"","."]})]}),n.jsx(E,{size:"sm",variant:"accent",onClick:M,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 se=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=se>1?` · ${se} on Home`:se===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]})]}),se>0&&!J?n.jsx("span",{className:"wg-add-note",children:"On Home"}):n.jsxs(E,{size:"sm","aria-label":`${se>0?"Add another":"Add"} ${U.title}`,onClick:()=>W(U),children:[n.jsx(ce,{name:"plus",size:12})," ",se>0?"Add another":"Add"]})]},U.id)})})]}):null,Ie&&Fe?n.jsx(s$,{info:Fe,placement:Ie,surface:"home",onClose:()=>S(null),onSave:U=>Y(Ie.key,U),onRemove:()=>F(Ie.key)}):null]})}function fw(e,t){return!e||e==="image"&&!t?"earth":e}const iK="(max-width: 720px)",aK=3e4,lK={1:"a minute",5:"5 minutes",15:"15 minutes",60:"an hour"};function Jm(e,t){return{time:zt(e,t),day:vr(e,t,{weekday:!0})}}function mw(e,t){return e?Dc({timeFormat:e.time,...e.date==="off"?{}:{dateFormat:e.date}},t):t()}function oK(e,t,s=new Date,r){return mw(r,()=>cK(e,t,s))}function cK(e,t,s){if(!e.lockedAt)return"Locked";const r=new Date(e.lockedAt),a=Jm(r,t).day===Jm(s,t).day?Jm(r,t).time:aj(r,t);return e.reason==="idle"?`Locked after ${e.delayMinutes?lK[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 uK(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 dK=e=>`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`;function M0({size:e=16}){return n.jsx(ce,{name:"lock",size:e})}function c$({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 hK(){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 D0({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(E,{size:"sm",onClick:r,children:t?"Copied":"Copy"})]})}function fK({onClose:e}){return n.jsx(Lt,{title:"Forgot your PIN?",onClose:e,foot:n.jsx(E,{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(D0,{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(D0,{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 mK({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 pK(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 gK({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=pK(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(hw,{body:i.view.body,size:a})}),n.jsx("span",{className:"wg-compact-title",children:i.title})]},i.key??i.id))})})}function xK({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 O0(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 vK(e,t,s){try{const r=O0(e,t)-O0(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 jK(e,t,s){const r=s??{date:null,zone:null};return mw(s,()=>({time:zt(e,t),day:r.date==="off"?null:vr(e,t,{weekday:!0}),zone:r.zone?{label:r.zone.label,time:zt(e,r.zone.timezone),offset:vK(e,r.zone.timezone,t)}:null}))}function u$({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=jK(t,l,e==null?void 0:e.clockView),c=fw(e==null?void 0:e.background,e==null?void 0:e.image),u=(e==null?void 0:e.focus)??null,h=u?mw(e==null?void 0:e.clockView,()=>s?bK(Sc(u,l,t)):`${Zi[u.mode]} ${Sc(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:bH(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(jc,{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(xK,{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(mK,{approvals:e.approvals,needs:e.needs??0,after:i??null,...a?{onPick:a}:{}}),r||!e?null:n.jsx(gK,{widgets:e.widgets,phone:s})]})]})}function wK({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(hK,{})}),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(c$,{size:18})})]})}function yK({initial:e,onUnlocked:t}){const s=ks(iK),r=e$(),[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),T=d.useRef(null),R=uK(f),I=R>0,L=d.useRef(t),_=d.useRef(S);_.current=S,L.current=Y=>{_.current&&(window.location.hash=jl),t(Y)};const $=Y=>{var F;C(Y),s&&Y?y(!0):(F=T.current)==null||F.focus()},P=d.useCallback(()=>{A.lockScreen().then(Y=>{b(!1),a(Y),m(Y.waitUntil),Y.locked||L.current(Y)}).catch(Y=>{Y instanceof ve&&Y.status===401?window.location.reload():Jd(Y)&&b(!0)})},[]);d.useEffect(()=>{P();const Y=window.setInterval(P,aK),F=()=>{document.visibilityState==="visible"&&P()};return document.addEventListener("visibilitychange",F),()=>{window.clearInterval(Y),document.removeEventListener("visibilitychange",F)}},[P]),l$((i==null?void 0:i.widgets.some(Y=>Y.id===r$&&Y.view.body.kind!=="clocks"))??!1,P),d.useEffect(()=>{var Y;!s&&!j&&!I&&((Y=T.current)==null||Y.focus())},[s,j,I,p]),d.useEffect(()=>{!I&&f&&h(null)},[I,f]);const O=Y=>{Y==null||Y.preventDefault(),!(p||I||o.length<4)&&(g(!0),A.unlock(o).then(F=>{var Q;if(c(""),F.locked){g(!1);return}if((Q=window.matchMedia)==null?void 0:Q.call(window,"(prefers-reduced-motion: reduce)").matches){L.current(F);return}N(!0),window.setTimeout(()=>L.current(F),240)}).catch(F=>{if(g(!1),c(""),!(F instanceof ve))return h("Something went wrong. Try again.");const X=F.detail??{};if(F.status===403||F.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 Jd(F)?h("buddi isn’t answering. Try again in a moment."):h(F.message)}))},M=(i==null?void 0:i.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,D=fw(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 ${dK(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?oK(l,M,r,i==null?void 0:i.clockView):"Locked"},q=Y=>Y.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":D,"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(u$,{data:i??(l?{...kK(l)}:null),now:r,phone:s,pad:w,after:S,onPick:$}),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(M0,{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((Y,F)=>n.jsx("span",{className:"lk-dot"},F))}),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(wK,{value:o,disabled:I||p,onDigit:Y=>{h(null),c(q(o+Y))},onBack:()=>c(o.slice(0,-1)),onSubmit:()=>O()}),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:O,children:[n.jsx(M0,{size:15}),n.jsx("input",{ref:T,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:Y=>{h(null),c(q(Y.target.value))}}),n.jsx("button",{type:"submit",className:"lk-go","aria-label":"Unlock",disabled:p||I||o.length<4,children:n.jsx(c$,{})})]}),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(fK,{onClose:()=>x(!1)}):null]})}function bK(e){return e.slice(0,1).toUpperCase()+e.slice(1)}function kK(e){return{timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,background:e.background,image:e.image,focus:null,approvals:0,needs:0,widgets:[]}}const NK=3e4,SK=5e3,CK="buddi-lock",Nx="buddi-locked",EK=Pe("lock");function d$(){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 AK(e=d$()){return e?"⌃⌘L":"Ctrl+Alt+L"}function TK(e,t=d$()){return!(e.code==="KeyL"||e.key.toLowerCase()==="l")||!e.ctrlKey||e.shiftKey?!1:t?e.metaKey&&!e.altKey:e.altKey&&!e.metaKey}const h$=d.createContext({pin:!1,state:null,lockNow:()=>{},update:()=>{},shortcut:"⌃⌘L"});function Nf(){return d.useContext(h$)}function Wu(e){try{e?localStorage.setItem(Nx,"1"):localStorage.removeItem(Nx)}catch{}}function $K(){try{return localStorage.getItem(Nx)==="1"}catch{return!1}}function RK(){try{return typeof BroadcastChannel>"u"?null:new BroadcastChannel(CK)}catch{return null}}function IK({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"),Wu(b),b||(l.current=Date.now())},[]),f=d.useCallback(()=>{A.lockState().then(v=>h(v,v.locked)).catch(v=>{if(v instanceof ve&&v.status===401)return s("open");h(null,$K())})},[h]);d.useEffect(()=>{f()},[f]);const m=d.useCallback((v="owner")=>{var b;if(!(r!=null&&r.pin)){window.location.hash=EK;return}s("locked"),Wu(!0),(b=a.current)==null||b.postMessage({type:"locked"}),A.lockNow(v).then(j=>h(j,j.locked)).catch(()=>f())},[r==null?void 0:r.pin,h,f]);d.useEffect(()=>{const v=()=>{s("locked"),Wu(!0),f()};return window.addEventListener(Sg,v),()=>window.removeEventListener(Sg,v)},[f]),d.useEffect(()=>{const v=RK();if(a.current=v,!!v)return v.onmessage=b=>{const j=b.data;(j==null?void 0:j.type)==="locked"?(s("locked"),Wu(!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=>{TK(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<NK||(o.current=k,c.current=l.current,A.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,SK),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:AK()}),[r,m,h]);return t==="checking"?null:t==="locked"?n.jsx(yK,{initial:r,onUnlocked:v=>{var b;(b=a.current)==null||b.postMessage({type:"unlocked"}),h(v,!1)}}):n.jsx(h$.Provider,{value:g,children:e})}const f$="a connection needs you";function PK({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:un,onClick:p=>{p.preventDefault(),s(un)},"aria-label":"buddi home",children:n.jsx(jc,{})}),D4.filter(p=>p.route!==an).map(p=>n.jsx(Qm,{label:p.label,href:p.route,active:t===p.route,badge:p.route===un?e:0,onClick:()=>s(p.route),children:L0[p.route]},p.route)),a.map(p=>{const g=fr(p.plugin,p.id);return n.jsx(Qm,{label:p.title,href:g,active:t===g,badge:0,onClick:()=>s(g),children:n.jsx(ce,{name:JT(p.icon)})},g)}),n.jsx("div",{className:"rail-spacer"}),n.jsx(Qm,{label:"Settings",href:an,active:t===an,badge:0,dot:l?"a newer buddi is ready":o,onClick:()=>s(an),children:L0[an]}),m,n.jsx(DK,{theme:r,onTheme:i,onNavigate:s,version:c,stale:u,reload:h,timezone:f})]})}const MK=[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}];function DK({theme:e,onTheme:t,onNavigate:s,version:r,stale:i,reload:a=()=>window.location.reload(),timezone:l}){var y,k,N;const o=de(()=>A.owner(),[]),c=Nf(),u=de(()=>A.focus(),[],6e4),h=((y=u.data)==null?void 0:y.focus)??null,f=(S,C)=>{A.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(Q4),[v]=d.useState(FK),b=kf(),j=m?`You: ${m}`:"You",x=h?`${Zi[h.mode]} ${Sc(h,l)}`:null,w=[j,x,i?"reload to update":null].filter(Boolean).join(", ");return n.jsx("div",{className:"rail-owner",children:n.jsxs(_c,{modal:!1,children:[n.jsx(zc,{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(zl,{children:n.jsxs(Uc,{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(Ir,{className:"ui-menu-sep"}),n.jsx(LK,{focus:h,timezone:l,onSwitch:f}),n.jsx(Ir,{className:"ui-menu-sep"}),n.jsx(da,{className:"ui-menu-label",children:"Theme"}),n.jsx("div",{className:"rail-owner-theme",children:n.jsx(Yt,{label:"Theme",options:MK,value:e,onChange:t})}),n.jsx(Ir,{className:"ui-menu-sep"}),c.pin?n.jsxs(vs,{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(vs,{className:"ui-menu-item",onSelect:()=>s(Pe("lock")),children:"Set up a lock screen…"}),n.jsx(vs,{className:"ui-menu-item",onSelect:()=>s(Pe("appearance")),children:"Change appearance"}),b?n.jsx(vs,{className:"ui-menu-item",onSelect:()=>{uw(b)},children:"Install the app"}):null,g||i?n.jsxs(vs,{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(Ir,{className:"ui-menu-sep"}),n.jsxs(vs,{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 Zi={normal:"Off","urgent-only":"Urgent only","do-not-disturb":"Do not disturb"},OK=[{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 Sc(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 LK({focus:e,timezone:t,onSwitch:s}){return n.jsxs(H_,{children:[n.jsxs(K_,{className:"ui-menu-item rail-owner-focus",children:[n.jsx("span",{children:"Focus"}),n.jsx("span",{className:"rail-owner-kbd",children:e?Zi[e.mode]:"Off"})]}),n.jsx(zl,{children:n.jsxs(V_,{className:"ui-menu rail-owner-menu",sideOffset:6,children:[n.jsx("p",{className:"ui-menu-empty",role:"status",children:e?`${Zi[e.mode]} ${Sc(e,t)}${e.by==="schedule"?", from a schedule":""}.`:"No focus is on."}),["do-not-disturb","urgent-only"].map(r=>n.jsxs(JE,{children:[n.jsx(Ir,{className:"ui-menu-sep"}),n.jsx(da,{className:"ui-menu-label",children:Zi[r]}),OK.map(i=>n.jsx(vs,{className:"ui-menu-item","aria-label":`${Zi[r]} ${i.label.toLowerCase()}`,onSelect:()=>s(r,i.value),children:i.label},i.value))]},r)),e?n.jsxs(n.Fragment,{children:[n.jsx(Ir,{className:"ui-menu-sep"}),n.jsx(vs,{className:"ui-menu-item",onSelect:()=>s("normal"),children:"Turn off"})]}):null]})})]})}function FK(){const e=window.navigator.userAgent;return/iPhone|iPad|Android|Mobile/.test(e)?null:/Mac/.test(e)?"⌘R":"Ctrl+R"}function Qm({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 L0={[Kr]:n.jsx(ce,{name:"files"}),[un]:n.jsx(ce,{name:"home"}),[xi]:n.jsx(ce,{name:"chat"}),[ft]:n.jsx(ce,{name:"agents"}),[jt]:n.jsx(ce,{name:"activity"}),[an]:n.jsx(ce,{name:"settings"})},Cc=e=>`${e.plugin}:${e.id}`,_K=new Set;let pw=_K,F0=!1;const Sx=new Set;function Cx(e){pw=e;for(const t of Sx)t()}function zK(e){return Sx.add(e),()=>Sx.delete(e)}const _0=()=>pw;function UK(){F0||(F0=!0,Promise.resolve().then(()=>A.rail()).then(e=>Cx(new Set(Array.isArray(e==null?void 0:e.hidden)?e.hidden.filter(t=>typeof t=="string"):[]))).catch(()=>{}))}async function BK(e,t){const s=pw,r=new Set(s);t?r.add(Cc(e)):r.delete(Cc(e)),Cx(r);try{await A.setRailHidden(e.plugin,e.id,t)}catch(i){throw Cx(s),i}}function m$(){return d.useEffect(UK,[]),d.useSyncExternalStore(zK,_0,_0)}function WK(e,t){return e.filter(s=>!t.has(Cc(s)))}function HK(e){return e instanceof HTMLElement?e.isContentEditable?!0:e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.tagName==="SELECT":!1}function KK(e,t=!0,s){d.useEffect(()=>{if(!t)return;const r=i=>{if(i.key!=="/"||i.defaultPrevented||i.ctrlKey||i.metaKey||i.altKey||HK(i.target))return;i.preventDefault();const a=document.getElementById(fx);if(a instanceof HTMLTextAreaElement){!a.disabled&&!a.hidden&&a.focus();return}s?s():e(un)};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t,s])}const p$="buddi.theme";function VK(e=g$()){try{const t=e==null?void 0:e.getItem(p$);return t==="light"||t==="dark"||t==="system"?t:"system"}catch{return"system"}}function GK(e,t=g$()){try{t==null||t.setItem(p$,e)}catch{}}function YK(e,t=document.documentElement){t&&(e==="system"?t.removeAttribute("data-theme"):t.setAttribute("data-theme",e))}function g$(){try{return window.localStorage}catch{return}}const x$="buddi.ground",v$="buddi.pageWidth";function qK(e=y$()){const t=i=>{try{return(e==null?void 0:e.getItem(i))??null}catch{return null}},s=t(x$),r=t(v$);return{theme:VK(e),ground:s==="sand"?"sand":"blue",width:r==="narrow"||r==="full"?r:"wide"}}function j$(e,t=document.documentElement){t&&(YK(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 JK(e,t=y$()){GK(e.theme,t);try{t==null||t.setItem(x$,e.ground),t==null||t.setItem(v$,e.width)}catch{}}let cl=null;const Ex=new Set;function Ax(){return cl||(cl=qK()),cl}function QK(e){return Ex.add(e),()=>Ex.delete(e)}function XK(e){cl={...Ax(),...e},j$(cl),JK(cl);for(const t of Ex)t()}function w$(){return[d.useSyncExternalStore(QK,Ax,Ax),XK]}function y$(){try{return window.localStorage}catch{return}}const z0=7,ZK=1e4;function eV({timezone:e,embedded:t,agents:s=[],navigate:r}){const{data:i,error:a,reload:l}=de(()=>A.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=M=>{r?r(M):window.location.hash=M},N=M=>{var D;return M?((D=s.find(H=>H.id===M))==null?void 0:D.name)??null:null},S=async M=>{c(null);try{await M()}catch(D){c(D instanceof ve||D instanceof Error?D.message:String(D))}finally{l()}},C=M=>h({...M,id:Date.now()}),T=(M,D,H)=>S(async()=>{const{keys:B}=await A.snoozeAlerts(M,!0,H);C({title:D,undo:()=>A.snoozeAlerts(B,!1)})}),R=M=>S(async()=>{const{id:D}=await A.muteAlert(M.keys[0],M.stop.scope);C({title:"You won’t hear about this again",body:"Turn it back on in Settings → Watchers.",undo:()=>A.unmuteAlert(D)})}),I=M=>S(async()=>{const{agentId:D,conversationId:H}=await A.askAboutAlerts(M.keys);k(st(D,H))}),L=M=>S(async()=>{const[D]=(await A.actOnAlerts([{key:M.key,action:M.index}])).results;if(D!=null&&D.error)throw new Error(D.error);D!=null&&D.approvalId?C({title:"Waiting for your approval",body:"Decide it in Needs you on Home."}):C({title:`${M.label}: done`})}),_=(M,D)=>{D.kind==="open"?k(D.place==="files"?Kr:D.plugin&&D.page?fr(D.plugin,D.page,D.item):Kr):D.kind==="ask"?I(M):D.kind==="dismiss"?T(M.keys,"Set aside until it changes"):D.kind==="fill"?m(D):D.confirm?g(D):L(D)},$=()=>{const M=y.flatMap(D=>D.keys);T(M,`Cleared ${y.length} for a week`,z0)},P=w==null?void 0:w.recap,O=tV((P==null?void 0:P.nextAt)??null,e);return n.jsxs(Mn,{embedded:t,title:"Alerts",lede:"What needs a decision from you.",children:[n.jsx(ie,{message:a??o}),n.jsxs(Ge,{flush:!0,title:"Needs a decision",tool:y.length>0?String(y.length):void 0,actions:y.length>1?n.jsx(E,{size:"sm",variant:"ghost",onClick:$,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 ",O,"."]})]})]}):n.jsx("ul",{className:"al-list",children:y.map(M=>n.jsx(U0,{group:M,agentName:N(M.agentId),onAct:_,onStop:R,onNotNow:D=>void T(D.keys,"Snoozed for a week",z0)},M.id))}):null,P&&P.count>0?n.jsxs("p",{className:"al-recap","data-testid":"recap-line",children:[n.jsxs("span",{children:[P.count," ",P.count===1?"note":"notes"," saved for ",O]}),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(Ge,{flush:!0,title:"Snoozed",children:n.jsx("ul",{className:"al-list",children:w.snoozed.map(M=>n.jsxs("li",{className:"al-row",children:[n.jsxs("div",{className:"al-main",children:[n.jsx("p",{className:"al-title",children:M.title}),n.jsx("p",{className:"al-sub",children:M.snoozedUntil?`Back ${Le(M.snoozedUntil)}`:"Until it changes"})]}),n.jsx("div",{className:"al-actions",children:n.jsx(E,{size:"sm",onClick:()=>void S(async()=>{await A.snoozeAlerts(M.keys,!1)}),children:"Bring back"})})]},M.id))})}):null,j==="resolved"&&w?n.jsx(Ge,{flush:!0,title:"Resolved this week",children:n.jsx("ul",{className:"al-list",children:w.resolved.map(M=>n.jsx("li",{className:"al-row",children:n.jsxs("div",{className:"al-main",children:[n.jsx("p",{className:"al-title",children:M.title}),n.jsx("p",{className:"al-sub",children:M.resolvedAt?`Resolved ${Le(M.resolvedAt)}`:null})]})},M.id))})}):null,v&&P?n.jsxs(qe,{title:nV(O),onClose:()=>b(!1),children:[n.jsxs("p",{className:"al-form-note",children:["What the watchers noted. buddi reads them out in ",O,"; nothing here needs you now, but you can act on one early."]}),n.jsx("ul",{className:"al-list al-list-sheet",children:P.groups.map(M=>n.jsx(U0,{group:M,agentName:N(M.agentId),recap:!0,onAct:(D,H)=>{H.kind!=="fill"&&b(!1),_(D,H)},onStop:D=>{R(D)}},M.id))})]}):null,f?n.jsx(sV,{action:f,onClose:()=>m(null),onSaved:M=>{m(null),b(!1),C({title:`Saved ${M}`}),l()}}):null,p?n.jsx(Lt,{title:p.label,onClose:()=>g(null),foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:()=>g(null),children:"Cancel"}),n.jsx(E,{variant:p.tone==="danger"?"danger":"accent",onClick:()=>{const M=p;g(null),L(M)},children:p.label})]}),children:n.jsx("p",{children:p.confirm})}):null,u?n.jsx(uh,{title:u.title,...u.body?{body:u.body}:{},duration:ZK,...u.undo?{onUndo:()=>{const M=u.undo;S(async()=>{await M()})}}:{},onGone:()=>h(null)},u.id):null]})}function tV(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 nV(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Hu(e,t){return e.kind==="ask"?e.label??(t?`Ask ${t}`:"Ask about it"):e.label}function U0({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 ",Le(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(E,{size:"sm",variant:g.kind==="run"&&g.tone==="danger"?"danger-ghost":"ghost",onClick:()=>r(e,g),children:Hu(g,t)},v))}):null]},p.key))}):null]}),n.jsxs("div",{className:"al-actions",children:[c?n.jsx(E,{size:"sm",variant:"accent",onClick:()=>r(e,c),children:Hu(c,t)}):null,u?n.jsx(E,{size:"sm",variant:u.kind==="run"&&u.tone==="danger"?"danger-ghost":void 0,onClick:()=>r(e,u),children:Hu(u,t)}):null,i?n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>i(e),children:"Not now"}):null,n.jsx("span",{className:"al-more",children:n.jsx(Di,{label:`More for ${e.title}`,sheet:{title:e.title},items:[...h.map(p=>({label:Hu(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 sV({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 A.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(qe,{title:e.title,onClose:t,foot:n.jsxs("div",{className:"al-form-foot",children:[n.jsx(E,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(E,{variant:"accent",disabled:c,onClick:()=>void m(),children:c?"Saving…":"Save"})]}),children:n.jsxs("div",{className:"al-form",children:[n.jsx(ie,{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 rV({mutes:e,onChanged:t}){const[s,r]=d.useState(null);return e.length===0?null:n.jsxs(Ge,{flush:!0,title:"Silenced",tool:String(e.length),children:[n.jsx(ie,{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” ",Le(i.createdAt)]})]}),n.jsx("div",{className:"al-actions",children:n.jsx(E,{size:"sm",onClick:()=>{r(null),A.unmuteAlert(i.id).then(t,a=>r(a instanceof Error?a.message:String(a)))},children:"Tell me again"})})]},i.id))})]})}const B0=5e3,W0=50;function iV({timezone:e,embedded:t}){var j;const[s,r]=d.useState(""),[i,a]=d.useState(""),[l,o]=d.useState(null),c=de(()=>A.eventKinds(),[]),{data:u,error:h}=de(()=>A.events({kind:s||void 0,q:i||void 0,limit:W0}),[s,i],B0),[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 A.events({kind:s||void 0,q:i||void 0,before:p,limit:W0});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(Mn,{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(E,{onClick:()=>{r(""),a("")},children:"Clear"}):null,n.jsxs("span",{className:"muted",children:["refreshes every ",B0/1e3,"s"]})]}),n.jsx(ie,{message:h}),n.jsx(Ge,{flush:!0,children:!u||b.length===0?n.jsx(pe,{children:"No events match."}):n.jsxs(wr,{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:Le(x.createdAt)})]}),n.jsx("td",{className:"mono nowrap",children:x.kind}),n.jsx("td",{className:"mono muted",children:Us(rs(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(E,{disabled:f.busy,onClick:()=>void g(),children:f.busy?"Loading…":"Load older"}):null]}):null,l?n.jsxs(qe,{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:rs(l.payload)})]}):null]})}const H0=["pending","leased","suspended","failed","succeeded","cancelled"],vo=50,aV=1e4,lV=(e,t,s=`${t}s`)=>e===1?t:s;function oV({timezone:e,embedded:t,initialState:s}){var B,q;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(()=>A.jobs({...r?{state:r}:{},...r?{}:{dismissed:"0"},limit:String(vo)}),[r],1e4),j=de(()=>A.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 A.jobs({...r?{state:r}:{dismissed:"0"},limit:String(vo),offset:String(vo+x.jobs.length)});w(Y=>({jobs:[...Y.jobs,...W.jobs],done:W.jobs.length<vo,busy:!1}))}catch(W){c(W instanceof Error?W.message:String(W)),w(Y=>({...Y,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:H0.reduce((W,Y)=>W+(S[Y]??0),0),T=!x.done&&N.length<C&&((g==null?void 0:g.jobs.length)??0)>=vo,R=((B=j.data)==null?void 0:B.open)??[],I=((q=j.data)==null?void 0:q.dismissed)??[],L=R.reduce((W,Y)=>W+Y.count,0),_=I.reduce((W,Y)=>W+Y.count,0),$=()=>{b(),j.reload()},P=W=>h({...W,id:Date.now()}),O=async W=>{c(null);try{await W()}catch(Y){c(Y instanceof Error?Y.message:String(Y))}finally{$()}},M=async W=>{await O(async()=>{await W,l(null)})},D=W=>O(async()=>{const{ids:Y}=await A.dismissJobs(W==="all"?{all:!0}:{ids:W});Y.length!==0&&P({title:`Dismissed ${Y.length===1?"it":Y.length}`,body:"Kept under Dismissed, below.",undo:()=>A.undismissJobs(Y)})}),H=(W,Y)=>O(async()=>{const{jobs:F}=await A.retryJobs({ids:W});if(F.length===0)return;const X=F.length===1;P({title:`Retrying ${X?"it":F.length}`,body:Y?`${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(Mn,{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(E,{size:"sm",variant:g!=null&&g.paused?"accent":void 0,onClick:()=>M(A.setPaused(!((g==null?void 0:g.paused)??!1))),children:g!=null&&g.paused?"Resume the queue":"Pause the queue"}),children:[n.jsx(ie,{message:v??j.error??o}),R.length>0?n.jsxs(Ge,{flush:!0,title:"Gave up",tool:String(L),actions:L>1?n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>void D("all"),children:"Dismiss all"}):void 0,children:[n.jsx("ul",{className:"al-list",children:R.map(W=>n.jsx(V0,{group:W,timezone:e,onOpen:l,onRetry:Y=>void H(Y,W.likelyFixed),onDismiss:Y=>void D(Y)},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(Ge,{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:_>0?"The ones you dismissed stay on record, below.":"Every job either ran or is still on its way."})]})]})}):null,_>0||p?n.jsxs("p",{className:"al-quiet jb-quiet",children:[_>0?n.jsxs("button",{type:"button",className:"wb-link","aria-expanded":f,onClick:()=>m(W=>!W),children:[_," dismissed"]}):null,_>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(Ge,{flush:!0,title:"Dismissed",children:n.jsx("ul",{className:"al-list",children:I.map(W=>n.jsx(V0,{group:W,timezone:e,dismissed:!0,onOpen:l,onRetry:Y=>void H(Y,W.likelyFixed)},W.key))})}):null,p?null:n.jsx(Ge,{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"}),H0.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(wr,{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:hc(W.id)})]}),n.jsxs("td",{children:[n.jsx(Gc,{state:W.state}),W.suspendedReason?n.jsx("div",{className:"sub",children:Us(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?Us(W.lastError,80):"—"}),n.jsxs("td",{className:"nowrap",children:[nt(W.updatedAt,e),n.jsx("div",{className:"sub",children:Le(W.updatedAt)})]}),n.jsx("td",{children:n.jsxs(ae,{align:"end",children:[["failed","cancelled","suspended"].includes(W.state)?n.jsx(E,{size:"sm",onClick:()=>M(A.retryJob(W.id)),children:"Retry"}):null,["pending","leased","suspended","failed"].includes(W.state)?n.jsx(E,{size:"sm",variant:"danger",onClick:()=>M(A.cancelJob(W.id)),children:"Cancel"}):null]})})]},W.id))})]})}),T&&!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(E,{disabled:x.busy,onClick:()=>void y(),children:x.busy?"Loading…":"Load older"})]}):null,a?n.jsxs(qe,{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:rs(a.payload)})}),n.jsx(ue,{title:"Result",children:n.jsx(Pt,{children:rs(a.result)})}),a.conversationId?n.jsx("p",{children:n.jsx("a",{href:`#/conversations/${a.conversationId}`,children:"open the transcript"})}):null]}):null,u?n.jsx(uh,{title:u.title,...u.body?{body:u.body}:{},duration:aV,...u.undo?{onUndo:()=>{const W=u.undo;O(async()=>{await W()})}}:{},onGone:()=>h(null)},u.id):null]})}function K0(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()!==""?Us(t.trim().split(`
111
- `)[0],48):e.job.kind==="agent-run"?"Agent run":e.job.kind}function V0({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 ${Le(((g=e.jobs[0])==null?void 0:g.job.acknowledgedAt)??e.lastAt)}`:`gave up ${Le(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:K0(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:K0(v)})," · ",aj(new Date(v.job.updatedAt),t)," · tried ",v.job.attempts," ",lV(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(E,{size:"sm",variant:e.likelyFixed&&!s?"accent":void 0,onClick:()=>i(u),children:c?"Retry all":"Retry"}),a?n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>a(u),children:"Dismiss"}):null]})]})}const cV=[{id:"conversations",label:"Conversations"},{id:"jobs",label:"Jobs"},{id:"approvals",label:"Approvals"},{id:"alerts",label:"Alerts"},{id:"events",label:"Events"}];function uV({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(fV,{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(yl,{title:"Activity",lede:"Everything your agents ran, newest first.",actions:n.jsx(gV,{})}),n.jsx(xV,{}),n.jsx(Yc,{children:cV.map(f=>{const m=f.id==="conversations"?jt:`${jt}/${f.id}`;return n.jsx(bl,{href:m,active:l===f.id,onClick:c(m),children:f.label},f.id)})}),l==="conversations"?n.jsx(dV,{timezone:t,navigate:s,nameOf:a,agents:r}):null,l==="jobs"?n.jsx(oV,{timezone:t,embedded:!0,initialState:o},o??""):null,l==="approvals"?n.jsx(hV,{timezone:t,nameOf:a}):null,l==="alerts"?n.jsx(eV,{timezone:t,embedded:!0,agents:r,navigate:s}):null,l==="events"?n.jsx(iV,{timezone:t,embedded:!0}):null]})}function dV({timezone:e,navigate:t,nameOf:s,agents:r}){const{data:i,error:a}=de(()=>A.conversations(),[],3e4);return n.jsxs(n.Fragment,{children:[n.jsx(ie,{message:a}),n.jsx(Ge,{flush:!0,children:i?i.conversations.length===0?n.jsx($n,{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:gc(l.id),onClick:()=>t(gc(l.id)),lead:n.jsx(on,{agents:r,id:l.agentId,size:"sm"}),title:l.opening?Us(l.opening,100):"Untitled conversation",sub:`${s(l.agentId)}, ${l.messageCount} message${l.messageCount===1?"":"s"}, ${l.runs} run${l.runs===1?"":"s"}, ${bL(l.usage)}`,side:n.jsx("span",{title:nt(l.lastMessageAt??l.createdAt,e),children:Le(l.lastMessageAt??l.createdAt)})},l.id))}):n.jsx(pe,{children:"Loading…"})})]})}function hV({timezone:e,nameOf:t}){const{data:s,error:r}=de(()=>A.approvals(),[],1e4),i=[...(s==null?void 0:s.pending)??[],...(s==null?void 0:s.recent)??[]];return n.jsxs(n.Fragment,{children:[n.jsx(ie,{message:r}),n.jsx(Ge,{flush:!0,children:s?i.length===0?n.jsx($n,{icon:"bell",title:"No approvals yet",children:"When an agent asks before acting, the request and your answer are kept here."}):n.jsxs(wr,{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:hc(a.id)})]}),n.jsx("td",{children:n.jsx(Gc,{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:Le(a.createdAt)})]})]},a.id))})]}):n.jsx(pe,{children:"Loading…"})})]})}function fV({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 A.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:jt,onClick:c(jt),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(E,{size:"sm",onClick:()=>s(jt),children:"← Back"}),n.jsx("span",{children:"Transcript"})]}),i?n.jsx("div",{className:"ui-page-actions",children:n.jsx(Et,{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(ie,{message:l}),i?n.jsxs(n.Fragment,{children:[n.jsxs(vf,{children:[n.jsx(ar,{label:"Agent",value:r(i.agentId),size:"sm"}),n.jsx(ar,{label:"Runs",value:i.runs.length}),n.jsx(ar,{label:"Tokens",value:`${Xt(i.usage.input)} / ${Xt(i.usage.output)}`,note:Ng(i.usage)?`input / output, ${Ng(i.usage)}`:"input / output"}),n.jsx(ar,{label:"Started",value:nt(i.createdAt,t),size:"sm"})]}),i.runs.length>0?n.jsx(Ge,{title:"Runs",flush:!0,children:n.jsxs(wr,{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 ",hc(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===G0?"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===G0?u.blocks.map((h,f)=>n.jsx(mV,{block:h},f)):u.blocks.map((h,f)=>n.jsx(pV,{block:h},f))]})]},u.id))})})]}):n.jsx(pe,{children:"Loading…"})]})}const G0="approval:resume";function mV({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??"":rs(e)})]})}function pV({block:e}){return e.type==="text"?n.jsx("div",{className:"transcript-text",children:n.jsx(mr,{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(mr,{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:rs(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:rs(e.ref)})]})}function gV(){const{data:e,reload:t}=de(()=>A.overview(),[],1e4),[s,r]=d.useState(!1);if(!e)return null;const i=()=>{r(!0),A.setPaused(!e.paused).then(t,t).finally(()=>r(!1))};return n.jsx(E,{size:"sm",variant:e.paused?"accent":void 0,disabled:s,onClick:i,children:e.paused?"Resume all":"Pause all"})}function xV(){const{data:e,reload:t}=de(()=>A.overview(),[],1e4);if(d.useEffect(()=>(window.addEventListener(Xi,t),()=>window.removeEventListener(Xi,t)),[t]),!e)return null;const s=i=>e.jobs[i]??0,r=s("leased");return n.jsxs(vf,{children:[n.jsx(ar,{label:"Jobs done",value:Xt(s("succeeded"))}),n.jsx(ar,{label:"Failed",value:Xt(s("failed")),...s("failed")>0?{tone:"critical"}:{}}),n.jsx(ar,{label:"Queued",value:Xt(s("pending")),note:`${r} running`}),n.jsx(ar,{label:"Approvals",value:Xt(e.approvals.pending),note:"waiting for you"})]})}const vV=["replay-all","coalesce","latest-only","skip-after-deadline"];function b$({timezone:e,embedded:t,agentId:s}){const{data:r,error:i,reload:a}=de(()=>A.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(Mn,{embedded:t,title:"Missions",lede:"Standing schedules. A disabled mission materializes nothing.",children:[n.jsx(ie,{message:i??o}),!r||l.length===0?n.jsxs($n,{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(jV,{mission:h,timezone:e,onRun:u},h.id))})]})}function jV({mission:e,timezone:t,onRun:s}){const[r,i]=d.useState(!1);return n.jsxs(us,{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(E,{size:"sm",onClick:()=>s(A.setMissionEnabled(e.id,!e.enabled)),children:e.enabled?"Disable":"Enable"}),n.jsx(E,{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(E,{size:"sm",onClick:()=>s(A.answerStillUseful(e.id,"stop")),children:"Stop"}),n.jsx(E,{size:"sm",variant:"accent",onClick:()=>s(A.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)} (${Le(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"} ${Le(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(A.setMisfirePolicy(e.id,a.target.value)),children:vV.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(Ge,{flush:!0,children:e.occurrences.length===0?n.jsx(pe,{children:"Never run."}):n.jsxs(wr,{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(Gc,{state:a.state})}),n.jsx("td",{className:"nowrap",children:nt(a.finishedAt,t)}),n.jsxs("td",{className:a.error?"critical":"muted",children:[a.error?Us(a.error,120):null,a.runConversationId?n.jsx("a",{href:`#/conversations/${a.runConversationId}`,children:"transcript"}):null]})]},a.id))})]})})})]}):null]})}function wV(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 k$({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:wV(r,t)}),n.jsx(E,{size:"sm",variant:"danger",disabled:l,onClick:()=>{o(!0),A.dismissOffers(e).then(()=>{a(!1),s()}).finally(()=>o(!1))},children:`Dismiss ${r}`}),n.jsx(E,{size:"sm",variant:"ghost",disabled:l,onClick:()=>a(!1),children:"Keep them"})]}):n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>a(!0),children:"Dismiss all"})}function N$({embedded:e,agentId:t,agentName:s}){const{data:r,error:i,reload:a}=de(()=>A.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 A.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 A.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(Mn,{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(ie,{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(k$,{ids:o.map(j=>j.id),agentName:s,onDone:()=>{g(null),a()}})]}):null,!r||o.length===0?n.jsx($n,{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(us,{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 ",Le(j.expiresAt)]})]}),actions:n.jsxs(n.Fragment,{children:[n.jsx(E,{size:"sm",variant:"ghost",disabled:f===j.id,onClick:()=>void b(j.id,j.label),children:"Not now"}),n.jsx(E,{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(At,{summary:`Dismissed and lapsed (${c.length})`,boxed:!0,children:[n.jsx(Ge,{flush:!0,children:n.jsx(rt,{children:c.map(j=>n.jsx(et,{title:j.label,sub:`${j.agentId} — ${CL(j)}`,side:Le(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 yV={work:"Work",money:"Money",home:"Home",health:"Health",learning:"Learning",life:"Life"},gw=e=>yV[e]??Sf(e);function Sf(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 Nl(e){return e.replace(/\.0$/,"")}function bV(e){return e.avatar?A.marketAssetUrl(e.avatar):void 0}const kV={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 xw(e){return kV[e.replace(/\?$/,"")]??{title:e,fix:"Set it up",route:Pe()}}const Cf=e=>Sf(e);function S$(e){return e.kind==="plugin"?e.title:xw(e.name).title}function C$(e){if(e.kind==="need"){const t=xw(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 NV(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(Cf),l=e.needs.includes("mailbox")||e.needs.includes("mailbox?");return s===!0&&l&&!r.has("mailbox")&&a.push("your mailbox"),a}function Xm(e){return Sf(e.replace(/\.md$/i,"").replace(/[-_]+/g," ").trim())}const Y0=(e,t)=>e.includes(t),SV={email:{title:"Mail",line:e=>Y0(e,"email.draft")||Y0(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."}},CV={schedule:"reminder",browser:"web"};function fh(e,t=new Map){const s=[],r=new Map;for(const i of e){const a=i.replace(/\?$/,""),l=a.split(".")[0]??a,o=CV[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=SV[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)??Sf(i),o&&!/asks you/i.test(c)?`${c} Asks you first before it changes anything.`:c]})}function q0(e){return e.length===0?"Nothing beyond its own chat.":`Reaches ${Kt(e.map(([t])=>t))}.`}function mh(e){return new Map((e??[]).filter(t=>t.tier).map(t=>[t.name,t.tier]))}function Yl({entry:e,size:t}){const s=bV(e);return n.jsx("span",{className:"cat-face","data-size":t,children:n.jsx(kn,{id:e.name,name:e.title,size:t==="xxl"?"xl":t,face:{tools:e.tools,...s?{picture:s}:{}}})})}const E$=800,EV=e=>{var t;return((t=/^.*?[.!?](?=\s|$)/.exec(e.trim()))==null?void 0:t[0])??e.trim()},ul=e=>e instanceof ve?e.message:String(e);function Tr({entry:e,children:t}){return n.jsxs("span",{className:"plugins-sheet-title",children:[n.jsx(Yl,{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 Zm({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 ep(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 AV(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=()=>{A.catalogueJob(e).then(c=>{a||(s(c),c.state==="running"&&(l=window.setTimeout(o,E$)))}).catch(c=>{a||i(ul(c))})};return o(),()=>{a=!0,l!==void 0&&window.clearTimeout(l)}},[e]),{job:t,error:r,setJob:s}}function A$({entry:e,navigate:t,onClose:s,onAdded:r}){var Fe;const i=ks("(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:T}=AV(j),[R,I]=d.useState(!1),[L,_]=d.useState(null),[$,P]=d.useState(!1),O=d.useRef(!1),[M,D]=d.useState([]);d.useEffect(()=>{if(!a||a.plugins.length===0)return;let U=!1;return Promise.resolve().then(()=>A.market()).then(se=>{U||D((se==null?void 0:se.plugins)??[])}).catch(()=>{}),()=>{U=!0}},[a]),d.useEffect(()=>{let U=!1;return A.cataloguePlan(e.name).then(se=>{U||(l(se),h(Object.fromEntries(se.fills.map(J=>[J.id,J.value]))),m(se.handle))}).catch(se=>{U||c(ul(se))}),()=>{U=!0}},[e.name]),d.useEffect(()=>{(S==null?void 0:S.state)==="done"&&S.agent&&!O.current&&(O.current=!0,r==null||r(S.agent))},[S,r]);const H=()=>{a&&(y(!0),N(null),O.current=!1,A.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(ul(U))).finally(()=>y(!1)))},B=()=>{x(null),H()},q=e.title,W=S==null?void 0:S.agent,Y=U=>{W&&(U&&uj(W.id,U),s(),t(st(W.id)))},F=U=>{S&&(I(!0),_(null),A.catalogueConfirm(S.id,U).then(se=>{T(se),U||s()}).catch(se=>_(ul(se))).finally(()=>I(!1)))};if((S==null?void 0:S.state)==="confirm"&&S.confirm){const U=fh(S.confirm.tools.map(J=>J.name),mh(S.confirm.tools)),se=S.steps.filter(J=>J.kind==="plugin"&&J.state==="done").map(J=>J.title);return n.jsxs(qe,{title:n.jsxs(Tr,{entry:e,children:["Add ",q]}),onClose:s,foot:n.jsxs(ae,{children:[n.jsx(dt,{}),n.jsx(E,{variant:"ghost",disabled:R,onClick:()=>F(!1),children:"Don’t add it"}),n.jsxs(E,{variant:"accent",disabled:R,onClick:()=>F(!0),children:["Add ",q]})]}),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}=ep(J);return n.jsx(Zm,{state:ye,children:ge},`${J.kind}-${J.name}`)})}),n.jsxs(V,{tone:"warning",title:`${q} would get more than the list showed.`,children:[se.length>0?`With ${Kt(se)} 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(ie,{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:[q0(U)," ",n.jsx("button",{type:"button",className:"plugins-link cat-link",onClick:()=>P(!$),children:$?"Hide":"See all"})]}),$?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],se=(S==null?void 0:S.approvalId)&&(U==null?void 0:U.state)==="adding";return n.jsxs(qe,{title:n.jsxs(Tr,{entry:e,children:["Add ",q]}),onClose:s,foot:n.jsx(ae,{align:"end",children:n.jsx(E,{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}=ep(J);return n.jsx(Zm,{state:ye,children:ge},`${J.kind}-${J.name}`)})}),se?n.jsxs(V,{tone:"accent",action:n.jsx(E,{size:"sm",onClick:()=>{s(),t(jl)},children:"Open it"}),children:["Adding ",q," waits for your approval in Needs you."]}):null,n.jsx(ie,{message:C}),n.jsxs("p",{className:"cat-small",children:["You can close this; it carries on, and ",q," 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),se=(a==null?void 0:a.missions.length)??e.missions.length,J=p.length;return n.jsxs(qe,{title:n.jsx(Tr,{entry:e,children:q}),onClose:s,foot:n.jsxs(ae,{children:[n.jsx(E,{variant:"ghost",onClick:()=>{s(),t(Ht())},children:"Back to teammates"}),n.jsx(dt,{}),n.jsx(E,{variant:"accent",onClick:()=>Y(),children:"Say hello"})]}),children:[n.jsxs("div",{className:"cat-done","data-testid":"cat-done",children:[n.jsx(Yl,{entry:e,size:"xxl"}),n.jsxs("p",{className:"cat-done-title",children:[q," is on your team."]}),n.jsxs("p",{className:"cat-small",children:["@",(W==null?void 0:W.handle)??f,U.length?` · ${Kt(U)} installed`:"",se>0&&J<se?` · ${se-J===1?"a mission":"missions"} off until you turn ${se-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:()=>Y(ye),children:ye},ye))})]}):null]})}if((S==null?void 0:S.state)==="failed"){const U=S.steps.find(se=>se.kind==="plugin"&&se.state==="failed");return n.jsxs(qe,{title:n.jsxs(Tr,{entry:e,children:[q," wasn’t added"]}),onClose:s,foot:n.jsxs(ae,{children:[n.jsx(dt,{}),n.jsx(E,{variant:"ghost",onClick:s,children:"Close"}),n.jsx(E,{variant:"accent",disabled:w,onClick:B,children:"Try again"})]}),children:[n.jsx("ol",{className:"cat-steps","data-testid":"cat-failed",children:S.steps.map(se=>{const{state:J,words:ye}=ep(se);return n.jsx(Zm,{state:J==="now"?"next":J,children:J==="now"?ye.replace(/…$/,""):ye},`${se.kind}-${se.name}`)})}),n.jsx(V,{tone:"critical",title:`${S.error??"It stopped before it finished"}.`,action:S.approvalId?n.jsx(E,{size:"sm",onClick:()=>{s(),t(jl)},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:se=>{se.preventDefault(),s(),t(Pe("plugins"))},children:"Settings → Plugins"})," ","if you’d rather look at it there."]}):null]})}),n.jsx(ie,{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?C$(ee):null,Oe=fh(a?a.tools.map(U=>U.name):e.tools,mh([...((Fe=e.claims)==null?void 0:Fe.tools)??[],...((a==null?void 0:a.tools)??[]).filter(U=>U.tier!=="unknown")])),Ie=U=>{var se;return((se=e.missions.find(J=>J.id===U))==null?void 0:se.when)??""};return n.jsxs(qe,{title:n.jsxs(Tr,{entry:e,children:["Add ",q]}),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 ${q}.`:"Nothing runs until you add it."}),n.jsx(dt,{}),n.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsxs(E,{variant:"accent",disabled:!a||Q.length>0||w||f.length<2,onClick:H,children:["Add ",q]})]}),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(ie,{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 se=M.find(J=>J.name===U.name);return n.jsxs("li",{children:[n.jsx(Rn,{svg:se==null?void 0:se.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:se!=null&&se.summary?EV(se.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(E,{size:"sm",onClick:()=>{s(),t(fe.route)},children:fe.label}):void 0,children:[q," needs ",Kt(Q.map(S$))," 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:se=>h({...u,[U.id]:se.target.value}),children:[U.kind==="calendar"?n.jsx("option",{value:"",children:"All of them"}):null,U.choices.map(se=>n.jsx("option",{value:se,children:se},se))]}):U.kind==="time"?n.jsx("input",{type:"time",value:u[U.id]??"",onChange:se=>h({...u,[U.id]:se.target.value})}):n.jsx("input",{value:u[U.id]??"",onChange:se=>h({...u,[U.id]:se.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(OU,{checked:p.includes(U.id),label:`Turn on ${U.name}`,onChange:se=>g(se?[...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:[q0(Oe)," ",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:Oe.map(([U,se])=>n.jsxs("div",{className:"cat-reach-row",children:[n.jsx("dt",{children:U}),n.jsx("dd",{children:se})]},U))}):null]})]}):null]})}function J0({lines:e,label:t}){return n.jsx("div",{className:"cat-diff",role:"region","aria-label":t,children:e.map((s,r)=>{const i=s.startsWith("+ ")?"+":s.startsWith("- ")?"-":" ";return n.jsxs("div",{className:"cat-diff-line","data-kind":i==="+"?"add":i==="-"?"del":void 0,children:[n.jsx("span",{className:"cat-diff-k","aria-hidden":"true",children:i}),n.jsx("span",{children:(i===" "?s:s.slice(2))||" "})]},r)})})}function T$({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 A.catalogueUpdatePlan(e.name,t).then(y=>{w||a(y)}).catch(y=>{w||o(ul(y))}),()=>{w=!0}},[e.name,t]);const g=Nl((i==null?void 0:i.version)??e.version),v=w=>{i&&(f(!0),o(null),A.catalogueUpdate(e.name,t,i.plan,w).then(()=>{p(!0),r==null||r()}).catch(y=>{o(ul(y)),A.catalogueUpdatePlan(e.name,t).then(a).catch(()=>{})}).finally(()=>f(!1)))};if(m)return n.jsx(qe,{title:n.jsxs(Tr,{entry:e,children:[e.title," ",g]}),onClose:s,foot:n.jsx(ae,{align:"end",children:n.jsx(E,{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(qe,{title:n.jsxs(Tr,{entry:e,children:["Update ",e.title]}),onClose:s,children:[n.jsx(ie,{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(qe,{title:n.jsxs(Tr,{entry:e,children:[e.title," ",g," is out"]}),onClose:s,foot:n.jsxs(ae,{children:[c?null:n.jsx(E,{variant:"ghost",onClick:()=>u(!0),children:"See what changed"}),n.jsx(dt,{}),n.jsx(E,{variant:"ghost",onClick:s,children:"Keep mine"}),n.jsx(E,{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(ie,{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(J0,{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(fh(i.added.map(w=>w.name),mh(i.added)).map(([w])=>w))}. The approval lists each tool.`:"No new tools. It reaches what it reaches today.";return n.jsxs(qe,{title:n.jsxs(Tr,{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(dt,{}),n.jsx(E,{variant:"ghost",onClick:s,children:"Not now"}),n.jsxs(E,{variant:"accent",disabled:h,onClick:()=>v(!1),children:["Update ",e.title]})]}),children:[n.jsx("p",{className:"cat-lede",children:i.changes}),n.jsx(ie,{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(J0,{lines:i.personaDiff,label:i.via?`@${i.handle} against ${e.title} ${g}`:`${e.title} ${Nl(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.jsx("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. Yours stay as they are.`:"None added. Yours stay as they are."})]}),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 Oi(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 vw(){const e=de(()=>A.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 jw(){return n.jsx(ce,{name:"check",size:14})}function TV({entry:e,loaded:t,mailbox:s}){const r=Oi(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(S$))]})});if(r!=="ready")return null;const a=NV(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 $V({entry:e,onAdd:t,onUpdate:s}){const r=Oi(e),i=a=>l=>{l.stopPropagation(),a()};return r==="added"?n.jsxs("span",{className:"cat-added",children:[n.jsx(jw,{}),"Added"]}):r==="update"?n.jsx(E,{size:"sm",onClick:i(s),"aria-label":`Update ${e.title}`,children:"Update"}):r==="edited"?n.jsx(E,{size:"sm",onClick:i(s),children:"See what changed"}):r==="unavailable"?null:n.jsx(E,{size:"sm",variant:"accent",onClick:i(t),"aria-label":`Add ${e.title}`,children:"Add"})}function RV({entry:e}){var i,a,l,o;const t=Oi(e),s=Nl(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 $$({entry:e,loaded:t,mailbox:s,onOpen:r,onAdd:i,onUpdate:a}){return n.jsx("div",{className:"cat-card","data-state":Oi(e),"data-testid":`cat-card-${e.name}`,children:n.jsxs(us,{onClick:r,label:`${e.title}: details`,children:[n.jsxs("div",{className:"cat-card-head",children:[n.jsx(Yl,{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:gw(e.category)})]})]}),n.jsx("p",{className:"cat-pitch",children:e.pitch}),n.jsx(RV,{entry:e}),n.jsxs("div",{className:"cat-card-foot",children:[n.jsx(TV,{entry:e,loaded:t,mailbox:s}),n.jsx(dt,{}),n.jsx($V,{entry:e,onAdd:i,onUpdate:a})]})]})})}function IV({row:e,agents:t,navigate:s,pages:r}){const i=ew(e.plugin,e.agent,()=>window.dispatchEvent(new Event(hr))),a=i.created??(e.state==="installed"?{id:e.agent,handle:e.handle,name:e.name}:null),l=r?KA(e.plugin,r.all):Cf(e.plugin);return n.jsx("div",{className:"cat-card","data-state":a?"added":"ready","data-testid":`cat-card-${e.agent}`,children:n.jsxs(us,{onClick:a?()=>s(St(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(kn,{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(ie,{message:i.failure}),n.jsx(dt,{}),a?n.jsxs("span",{className:"cat-added",children:[n.jsx(jw,{}),"Added"]}):n.jsx(E,{size:"sm",variant:"accent",disabled:i.busy,onClick:o=>{o.stopPropagation(),i.accept()},"aria-label":`Add ${e.name}`,children:"Add"})]})]})})}function PV({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 MV(e,t,s){const r=e.find(i=>i.roles.includes(Kc));r&&(s.trim()&&uj(r.id,`I'd like a teammate for this: ${s.trim()}`),t(st(r.id)))}function DV({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(T$,{entry:a,agentId:a.installed.agentId,onClose:r,onUpdated:i}):n.jsx(A$,{entry:a,navigate:s,onClose:r,onAdded:i})}const OV=[{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 LV(e,t){return[e.title,e.pitch,e.about,e.description,gw(e.category)].some(s=>s.toLowerCase().includes(t))}function FV({name:e,agents:t,navigate:s,pluginPages:r}){const[i,a]=d.useState(0),l=de(()=>A.catalogue(i>0),[i]),o=vw(),[c,u]=d.useState(""),[h,f]=d.useState("all"),[m,p]=d.useState(null),g=l.data,v=()=>{l.reload(),window.dispatchEvent(new Event(hr))},b=()=>a(T=>T+1),j=n.jsx(DV,{sheet:m,view:g,navigate:s,onClose:()=>p(null),onChanged:v}),x=e?g==null?void 0:g.agents.find(T=>T.name===e):void 0,w=d.useRef(!1);if(d.useEffect(()=>{w.current||!x||!y4(window.location.hash,x.name)||(w.current=!0,Oi(x)==="ready"&&p({kind:"install",name:x.name}))},[x]),e&&g&&!g.unavailable&&x)return n.jsxs(n.Fragment,{children:[n.jsx(UV,{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(T=>(h==="all"||T.category===h)&&(!y||LV(T,y))),S=((g==null?void 0:g.fromPlugins)??[]).filter(T=>h==="all"&&(!y||[T.name,T.text,T.description].some(R=>R.toLowerCase().includes(y)))),C=T=>()=>s(T);return n.jsxs(Fj,{children:[n.jsx(yl,{before:n.jsx(th,{inline:!0,items:[{label:"Agents",href:ft,onClick:C(ft)}]}),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(jf,{label:"Search teammates",value:c,placeholder:"Search: meals, money, a language…",onChange:u})]}),n.jsx("div",{className:"cat-cats",children:n.jsx(PA,{label:"Category",options:OV,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?_V(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(E,{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(E,{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(T=>n.jsx($$,{entry:T,loaded:o,mailbox:g.mailbox,onOpen:()=>s(Ht(T.name)),onAdd:()=>p({kind:"install",name:T.name}),onUpdate:()=>p({kind:"update",name:T.name})},T.name)),S.map(T=>n.jsx(IV,{row:T,agents:t,navigate:s,pages:r},`${T.plugin}/${T.agent}`))]}):n.jsx(pe,{warm:!0,title:"No teammate for that yet",action:n.jsxs("span",{className:"cat-empty-acts",children:[n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>{u(""),f("all")},children:"Show all"}),n.jsx(E,{size:"sm",variant:"accent",onClick:()=>MV(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(PV,{}),g&&!g.unavailable&&g.delisted.length>0?n.jsx(Ge,{title:"No longer in the catalogue",children:n.jsx("ul",{className:"cat-plugins","data-testid":"cat-delisted",children:g.delisted.map(T=>n.jsxs("li",{children:[n.jsx(on,{agents:t,id:T.agentId,size:"sm"}),n.jsxs("span",{className:"cat-plugin-text",children:[n.jsx("a",{className:"cat-plugin-name",href:St(T.agentId),onClick:R=>{R.preventDefault(),s(St(T.agentId))},children:T.name??`@${T.handle}`}),n.jsxs("span",{className:"cat-small",children:["@",T.handle," keeps working as it is; no updates will come."]})]})]},T.agentId))})}):null,j]})}function _V(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 Wi({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 zV({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$(c):null,h=o?xw(a).title:(c==null?void 0:c.kind)==="plugin"?c.title:Cf(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(E,{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(jw,{}),o?"You have one":"Installed"]}):n.jsx("span",{className:"cat-small",children:o?"Optional":"Not installed"})]},`${o?"need":"plugin"}-${a}`)})})}function UV({entry:e,loaded:t,agents:s,navigate:r,onAdd:i,onUpdate:a}){var g,v,b,j;const l=Oi(e),c=(g=e.installed)==null?void 0:g.agentId,u=Nl(e.version),h=(v=e.installed)!=null&&v.via?e.installed:void 0,f=x=>{c&&(x&&uj(c,x),r(st(c)))},m=fh(e.tools,mh((b=e.claims)==null?void 0:b.tools)),p=e.replaces.map(x=>Xm(x.split("/")[1]??x));return n.jsxs(Fj,{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(Yl,{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:gw(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(E,{variant:"accent",onClick:i,children:["Add ",e.title]}):l==="update"?n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:()=>f(),children:"Open chat"}),n.jsx(E,{variant:"accent",onClick:a,children:h?`Update @${h.handle} to ${e.title}`:`Update to ${u}`})]}):l==="edited"?n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:()=>f(),children:"Open chat"}),n.jsx(E,{onClick:a,children:"See what changed"})]}):l==="unavailable"?null:n.jsx(E,{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(Ge,{flush:!0,children:n.jsxs("div",{className:"cat-rows",children:[n.jsxs(Wi,{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(Wi,{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(Wi,{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:Xm(x.name)}),x.description?n.jsx("span",{className:"cat-small",children:x.description}):null,n.jsx(At,{summary:"Read it",children:n.jsx(Pt,{label:`${Xm(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:St(c,"skills"),onClick:x=>{x.preventDefault(),r(St(c,"skills"))},children:"its Skills tab"}),"."]}):"Once it’s on your team they’re files you can read and change."]})]})}),n.jsxs(Wi,{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(Wi,{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(Wi,{title:"Plugins",children:n.jsx(zV,{entry:e,loaded:t,navigate:r})}),n.jsxs(Wi,{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 BV(e){var r,i;const t=de(()=>A.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 WV({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),A.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})`:Nl(e.version)]}),e.delisted?n.jsx("span",{className:"muted",children:" · it keeps working; no updates will come"}):null,u?n.jsx(E,{size:"sm",variant:u==="update"?"accent":void 0,disabled:o,onClick:h,children:u==="update"&&e.latest?`Update to ${Nl(e.latest)}`:u==="update"?"Update":"See what changed"}):null]}),a?n.jsx(ie,{message:a}):null,r?n.jsx(T$,{entry:r,agentId:e.agentId,onClose:()=>i(null),onUpdated:s}):null]})}function HV(e){return typeof e=="string"?e:e.name??e.id??"a mission"}function KV({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(ft)},g=y=>y instanceof ve?y.message:String(y),v=()=>{i(!0),c(null),l(null),A.agentRemovePreview(e).then(l).catch(y=>c(g(y)))},b=()=>{h(!0),c(null),A.removeAgent(e).then(y=>{var N;window.dispatchEvent(new Event(hr));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(ft)}).catch(y=>c(g(y))).finally(()=>h(!1))},j=(a==null?void 0:a.pausesMissions.map(HV))??[],x=(a==null?void 0:a.unusedPlugins)??[],w=((a==null?void 0:a.handedWorkBy)??[]).map(y=>`@${y}`);return n.jsxs(Ge,{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(E,{variant:"danger-ghost",onClick:v,children:["Remove ",t,"…"]})]}),r&&f?n.jsx(Lt,{title:`${t} is off your team`,onClose:p,foot:n.jsx(E,{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(Lt,{title:`Remove ${t} from your team?`,onClose:()=>i(!1),foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:()=>i(!1),children:"Cancel"}),n.jsx(E,{variant:"danger",disabled:u||!a,onClick:b,children:"Remove from team"})]}),children:[n.jsx(ie,{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(Cf)),"; 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 VV=["fact","observation","todo"];function R$({embedded:e,agents:t,timezone:s,agentId:r}){const{data:i,error:a,reload:l}=de(()=>A.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(A.forgetPreference({key:y.key,scope:y.scope})),onEditNote:y=>h(y),onForgetNote:y=>void g(A.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(E,{variant:"accent",size:"sm",onClick:()=>c({key:"",scope:r??"shared"}),children:"Add a preference"});return n.jsxs(Mn,{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(ie,{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(tp,{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(np,{notes:j.notes,empty:`${b} has kept no private notes yet.`,...v})}),n.jsx(At,{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(tp,{preferences:x.preferences,empty:"No shared preferences.",...v})}),n.jsx(ue,{title:"Shared notes",panel:!0,flush:!0,children:n.jsx(np,{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(tp,{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(np,{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(GV,{agents:t,existing:(i==null?void 0:i.preferences)??[],initial:o,onClose:()=>c(null),onSave:async y=>{await g((async()=>{await A.setPreference(y),o.key===y.key&&o.scope!==y.scope&&await A.forgetPreference({key:o.key,scope:o.scope})})()),c(null)}}):null,u?n.jsx(YV,{note:u,agents:t,onClose:()=>h(null),onSave:y=>g(A.updateNote(u.id,y)).then(()=>h(null))}):null]})}function tp({preferences:e,empty:t,nameOf:s,onChangePreference:r,onForgetPreference:i}){return e.length===0?n.jsx(pe,{children:t}):n.jsxs(wr,{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(I$,{scope:a.scope,name:s(a.scope)})}),n.jsxs("td",{className:"num muted",title:a.updatedAt??"",children:[a.updatedAt?Le(a.updatedAt,Date.now()):"",a.revision>1?` · rev ${a.revision}`:""]}),n.jsx("td",{className:"num",children:n.jsxs(ae,{align:"end",children:[n.jsx(E,{size:"sm",onClick:()=>r(a),title:"Store a new value for this key",children:"Change"}),n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>i(a),children:"Forget"})]})})]},`${a.scope}:${a.key}`))})]})}function np({notes:e,empty:t,nameOf:s,timezone:r,onEditNote:i,onForgetNote:a}){return e.length===0?n.jsx(pe,{children:t}):n.jsxs(wr,{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(I$,{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?Le(l.createdAt,Date.now()):"",l.expiresAt?n.jsxs("span",{className:"memory-expires",children:[" · until ",vr(new Date(l.expiresAt),r,{year:!0,compact:!0})]}):null]}),n.jsx("td",{className:"num",children:n.jsxs(ae,{align:"end",children:[n.jsx(E,{size:"sm",onClick:()=>i(l),children:"Edit"}),n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>a(l),children:"Forget"})]})})]},l.id))})]})}function I$({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 P$({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 GV({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(qe,{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(P$,{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(E,{onClick:r,children:"Cancel"}),n.jsx(E,{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 YV({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(qe,{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(Bs,{children:[n.jsx(oe,{label:"Kind",children:n.jsx("select",{value:c,onChange:g=>u(g.target.value),children:VV.map(g=>n.jsx("option",{value:g,children:g},g))})}),n.jsx(oe,{label:"Who sees it",children:n.jsx(P$,{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?`, ${Le(e.createdAt,Date.now())}`:"",". Editing keeps that record."]}):null,n.jsxs(ae,{align:"end",children:[n.jsx(E,{onClick:s,children:"Cancel"}),n.jsx(E,{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 Da=e=>`/skills/${encodeURIComponent(e)}`,Un={list:()=>je("/skills"),detail:e=>je(Da(e)),downloadUrl:e=>`/api${Da(e)}/download`,create:e=>te("/skills",e),saveText:(e,t)=>te(`${Da(e)}/text`,{text:t}),grant:(e,t)=>te(`${Da(e)}/grants`,t),trust:e=>te(`${Da(e)}/trust`),remove:e=>nr(Da(e))};function qV(e){return`${ft}?tab=skills`}function JV(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 M$(e){const t=document.createElement("a");t.href=Un.downloadUrl(e),t.download="",document.body.appendChild(t),t.click(),t.remove()}const ww=[{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 yw(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function Lr(e,t){var s;return((s=e.find(r=>r.id===t))==null?void 0:s.name)??t}function bw(e){return e.charAt(0).toUpperCase()+e.slice(1)}function kw(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 ${yw(r)} (${s.length===1?"has its own":"each has its own"})`}function D$(e,t){return e.holders.some(s=>s.agent===t)}function QV(e,t){if(e.every)return kw(e,t);const s=e.holders.map(r=>Lr(t,r.agent));return s.length?yw(s):"No agent uses it yet"}function XV(e){return!e.every&&e.holders.length===0}function ZV(){const e=new Date;return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}function Q0(e){return e.slice(0,10)===ZV()?"today":`on ${Lc(e,{compact:!0})}`}function Nw(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 ${Le(e.learned.keptAt)}`:"";return`${u?"":`learned by ${Lr(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 ${bw(r.plugin)} ${r.version}`;if((r==null?void 0:r.kind)==="catalogue")return`came with ${Lr(t,r.agent)} ${r.version}`;if((r==null?void 0:r.kind)==="upload")return`uploaded${e.created?` ${Q0(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 ${Q0(i)}`:e.updatedAt?`edited by you ${Le(e.updatedAt)}`:"written by you"}function O$(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Sw(e,t){var s;return e.untrusted==="page"?`Untrusted: a web page was in view when ${Lr(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 e9(e){const t=e.file.split(/[\\/]/).pop()??e.file;return e.home?`agents/${e.home}/skills/${t}`:`skills/${t}`}function Cw(e){return e.every?[]:e.holders.map(t=>t.agent)}function t9(e,t){var s;if(e.learned){const r=Lr(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"?`${Lr(t,e.from.agent)}’s next update will ask before it replaces your change.`:null}function n9(e,t,s){var o;const r=t.stops.map(c=>Lr(s,c)),i=e.learned?Lr(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.":`${yw(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"?Lr(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 s9(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?O$(o.replace(/-/g," ")):e.replace(/\.md$/i,"")),description:i("description"),body:a}}const r9=5e4,ha=e=>e instanceof ve?e.message:String(e),i9=e=>t=>{t.stopPropagation(),e==null||e()};function a9({faces:e,navigate:t,command:s,openSkill:r}){const i=de(()=>Un.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>r9){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,...s9(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(E,{size:"sm",onClick:()=>{var w;h(null),(w=v.current)==null||w.click()},children:"Pick another file"}),children:u}):null,n.jsx(ie,{message:f}),p?n.jsx(V,{tone:"good",role:"status",children:p}):null,n.jsx(l9,{view:i,onOpen:w=>l({id:w.id}),onAct:(w,y)=>x(w,y)}),n.jsx(L$,{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(X0,{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(X0,{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"?Un.trust(w.id).then(()=>j(),k=>m(ha(k))):y==="download"?M$(w.id):y==="plugin"?t(Pe("plugins")):y==="edit"?(c(null),l({id:w.id,edit:!0})):c({kind:y,id:w.id})}}function l9({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(E,{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(c9,{});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(Ge,{flush:!0,children:ww.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(o9,{row:o,agents:i,onOpen:t,onAct:s},o.id))})]},a.id):null})})}function o9({row:e,agents:t,onOpen:s,onAct:r}){var l,o,c;const i=e.untrusted?["trust","Mark as mine"]:XV(e)?["picker","Choose agents"]:null,a=QV(e,t);return n.jsx(et,{onClick:()=>s(e),label:`${e.title}: details`,lead:n.jsx(Rn,{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," · ",Nw(e,t,!0)]}),e.untrusted?n.jsx("span",{className:"skills-status","data-tone":"warning",children:Sw(e,t)}):null]}),side:n.jsxs("span",{className:"skills-side",children:[i?n.jsx(E,{size:"sm",onClick:i9(()=>r(e,i[0])),children:i[1]}):null,n.jsx(Di,{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 ${bw(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 c9(){return n.jsx(Ge,{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 L$({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(d9,{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(h9,{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(m9,{row:f,agents:e.agents,onCancel:()=>a(null),onDeleted:m=>{a(null),r(null),o(m)}}):null]})}function F$({title:e,sub:t}){return n.jsxs("span",{className:"skills-sheet-title",children:[n.jsx(Rn,{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 xd({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 u9({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(Yt,{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(mr,{className:"wb-md skills-md",text:t}):n.jsx(Pt,{label:e,children:s})]})}function d9({row:e,agents:t,faces:s,initialEdit:r,onClose:i,onPicker:a,onDelete:l,onChanged:o,onFailed:c,navigate:u}){var L,_,$;const h=de(()=>Un.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=((_=h.data)==null?void 0:_.text)??"",y=O$(Nw(e,t)),k=t9(e,t),N=(($=e.from)==null?void 0:$.kind)==="plugin"?bw(e.from.plugin):null,S=P=>s.find(O=>O.id===P),C=async(P,O)=>{b(!0),x(null);try{await P(),O==null||O(),o()}catch(M){x(ha(M)),c(ha(M))}finally{b(!1)}},T=P=>{C(()=>Un.grant(e.id,{agents:Cw(e).filter(O=>O!==P)}))},R=()=>{C(()=>Un.saveText(e.id,p??w),()=>{m(!1),g(null)})},I=(P,O)=>{var M,D;if(((M=e.learned)==null?void 0:M.by)===P)return"Proposed it";if(((D=e.from)==null?void 0:D.kind)==="catalogue"&&e.from.agent===P)return"Came with it";if(O==="home")return"In its own folder"};return n.jsxs(qe,{size:"wide",title:n.jsx(F$,{title:e.title,sub:y}),onClose:i,foot:f?n.jsxs(ae,{align:"end",children:[n.jsx(E,{variant:"ghost",disabled:v,onClick:()=>{m(!1),g(null)},children:"Cancel"}),n.jsx(E,{variant:"accent",disabled:v||!h.data,onClick:R,children:"Save"})]}):n.jsxs(ae,{children:[e.deletable&&!N?n.jsx(E,{variant:"danger-ghost",onClick:l,children:"Delete…"}):null,n.jsx(dt,{}),n.jsx(E,{onClick:()=>M$(e.id),children:"Download"}),e.editable?n.jsx(E,{variant:e.untrusted?void 0:"accent",onClick:()=>m(!0),children:"Edit text"}):null]}),children:[e.untrusted?n.jsxs(V,{tone:"warning",action:n.jsx(E,{size:"sm",variant:"accent",disabled:v,onClick:()=>void C(()=>Un.trust(e.id)),children:"Mark as mine"}),children:[Sw(e,t)," Mark it as yours once you’ve read it."]}):null,n.jsx(ie,{message:j}),n.jsxs("div",{className:"skills-sheet",children:[n.jsx(xd,{title:"When it’s used",children:n.jsx("p",{className:"skills-desc",children:e.description})}),n.jsx(xd,{title:"Used by",aside:n.jsx(E,{size:"sm",onClick:a,children:"Change…"}),children:e.every?n.jsx(rt,{children:n.jsx(et,{lead:n.jsx(Rn,{icon:"agents"}),title:kw(e,t),sub:"Now, and any you add later."})}):e.holders.length?n.jsx(rt,{children:e.holders.map(P=>{const O=t.find(M=>M.id===P.agent);return n.jsx(et,{lead:n.jsx(kn,{id:P.agent,name:(O==null?void 0:O.name)??P.agent,size:"sm",face:S(P.agent)}),title:n.jsxs(n.Fragment,{children:[(O==null?void 0:O.name)??P.agent," ",n.jsxs("span",{className:"skills-handle",children:["@",(O==null?void 0:O.handle)??P.agent]})]}),sub:I(P.agent,P.how),side:P.how==="home"?void 0:n.jsx(E,{size:"sm",variant:"ghost",disabled:v,onClick:()=>T(P.agent),"aria-label":`Take away from ${(O==null?void 0:O.name)??P.agent}`,children:"Take away"})},P.agent)})}):n.jsx("p",{className:"skills-note",children:"No agent uses it yet, so it does nothing. Choose who should."})}),n.jsxs(xd,{title:"The text",children:[h.data?f?n.jsx("textarea",{className:"skills-editor",value:p??w,onChange:P=>g(P.target.value),"aria-label":`Text of ${e.title}`,spellCheck:!1,autoFocus:!0}):n.jsx(u9,{file:e9(e),body:h.data.body,text:w}):h.error?n.jsx(ie,{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:P=>{P.preventDefault(),u(Pe("plugins"))},children:"Open Plugins"})]}):null]})]})]})}function ph({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 _$({label:e,value:t,onChange:s}){return n.jsxs("div",{className:"cat-search",children:[n.jsx(ce,{name:"search",size:16}),n.jsx(jf,{label:e,value:t,placeholder:e,onChange:s})]})}function h9({row:e,agents:t,faces:s,onCancel:r,onSaved:i}){const[a,l]=d.useState(e.every),[o,c]=d.useState(Cw(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 Un.grant(e.id,a?{every:!0,agents:[]}:{agents:o}),i()}catch(w){g(ha(w))}finally{m(!1)}};return n.jsx(Lt,{title:`Who uses “${e.title}”?`,onClose:r,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:r,children:"Cancel"}),n.jsx(E,{variant:"accent",disabled:f,onClick:()=>void x(),children:"Save"})]}),children:n.jsxs("div",{className:"skills-pick",children:[n.jsx(_$,{label:"Find an agent",value:u,onChange:h}),n.jsx(ie,{message:p}),n.jsxs("div",{className:"skills-pick-list",children:[v||!e.shareable?null:n.jsx(ph,{checked:a,onChange:l,lead:n.jsx(Rn,{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(ph,{checked:!k&&(a||y||o.includes(w.id)),disabled:a||N,onChange:S=>j(w.id,S),lead:n.jsx(kn,{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 f9({agent:e,view:t,onCancel:s,onSaved:r}){const i=x=>D$(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=Cw(x);await Un.grant(x.id,{agents:w?[...y,e.id]:y.filter(k=>k!==e.id)})}r()}catch(x){m(ha(x))}finally{h(!1)}},j=t.skills.some(g);return n.jsx(Lt,{title:`Skills ${e.name} uses`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(E,{variant:"accent",disabled:u||!e.writable,onClick:()=>void b(),children:"Save"})]}),children:n.jsxs("div",{className:"skills-pick",children:[n.jsx(_$,{label:"Find a skill",value:o,onChange:c}),n.jsx(ie,{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:[ww.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(ph,{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":kw(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 X0({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 Un.create({title:a.trim(),description:o.trim(),body:u,agents:f,...s?{upload:{filename:s.name,mine:p}}:{}});i(N)}catch(N){x(ha(N))}finally{b(!1)}};return n.jsxs(qe,{size:"wide",title:s?n.jsx(F$,{title:s.name,sub:`${y} · read, not saved yet`}):"Write a skill",onClose:r,foot:n.jsxs(ae,{align:"end",children:[n.jsx(E,{variant:"ghost",onClick:r,children:"Cancel"}),n.jsx(E,{variant:"accent",disabled:!w||v,onClick:()=>void k(),children:"Save skill"})]}),children:[n.jsx(ie,{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(xd,{title:"Who uses it",children:[n.jsx("div",{className:"skills-who",children:e.map(N=>n.jsx(ph,{checked:f.includes(N.id),disabled:!N.writable,onChange:S=>m(S?[...f,N.id]:f.filter(C=>C!==N.id)),lead:n.jsx(kn,{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 m9({row:e,agents:t,onCancel:s,onDeleted:r}){const i=de(()=>Un.detail(e.id),[e.id]),[a,l]=d.useState(!1),[o,c]=d.useState(null),u=d.useMemo(()=>i.data?n9(e,i.data.onDelete,t):null,[i.data,e,t]),h=async()=>{l(!0),c(null);try{const f=await Un.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(ha(f)),l(!1)}};return n.jsxs(Lt,{title:`Delete “${e.title}”?`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(E,{variant:"danger",disabled:a||!i.data,onClick:()=>void h(),children:"Delete"})]}),children:[n.jsx(ie,{message:o??i.error}),n.jsx("p",{className:"skills-dialog-text",children:u??"Checking who uses it…"})]})}function p9(e){var t;return((t=ww.find(s=>s.id===e.group))==null?void 0:t.title)??""}function g9({agentId:e,agentName:t,faces:s=[],navigate:r}){const i=de(()=>Un.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=>{Un.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(E,{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=>D$(k,e)),y=qV();return n.jsxs(n.Fragment,{children:[n.jsx(ie,{message:f}),p?n.jsx(V,{tone:"good",role:"status",children:p}):null,n.jsx(Ge,{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(E,{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(Rn,{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:[p9(k)," · ",k.every?"every agent uses it":Nw(k,j.agents,!0)]}),k.untrusted?n.jsx("span",{className:"skills-status","data-tone":"warning",children:Sw(k,j.agents)}):null]}),side:n.jsx("span",{className:"skills-side",children:k.untrusted?n.jsx(E,{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(L$,{view:j,faces:s,open:a,setOpen:l,dialog:o,setDialog:c,navigate:r,onChanged:v,onFailed:m}),u?n.jsx(f9,{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(()=>A.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 A.cancelReminder(h),a()}catch(f){c(f instanceof Error?f.message:String(f))}};return n.jsxs(Mn,{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(ie,{message:i??o}),n.jsx(Ge,{flush:!0,children:r?l.length===0?n.jsx($n,{icon:"bell",title:"No reminders",children:"Ask any agent to remind you of something, and it shows up here."}):n.jsxs(wr,{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:Le(h.dueAt)})]}),n.jsx("td",{className:"mono",children:h.agentId}),n.jsxs("td",{children:[h.text,h.context?n.jsx(At,{summary:"context",children:n.jsx(Pt,{children:rs(h.context)})}):null]}),n.jsxs("td",{children:[n.jsx(Gc,{state:h.state}),h.cancelReason?n.jsx("div",{className:"sub",children:h.cancelReason}):null]}),n.jsx("td",{children:h.state==="pending"?n.jsx(E,{size:"sm",variant:"danger",onClick:()=>u(h.id),children:"Cancel"}):null})]},h.id))})]}):n.jsx(pe,{children:"Loading…"})})]})}const x9=/(flux|klein|schnell|qwen[-_]?image|image)/i;function U$(e){return e.kind==="image"||e.kind===void 0&&x9.test(e.id)}function v9(e){const t=((e==null?void 0:e.models)??[]).filter(s=>!U$(s));return[...t.filter(s=>s.loaded),...t.filter(s=>!s.loaded)].map(s=>s.id)}function Tx(e){return v9(e)[0]}function Ew(e){return(e==null?void 0:e.detectedContextWindowSource)==="mlxh"}function j9(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 B$(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 W$="an image model; pick it in the Image plugin, not here";function Aw({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 A.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?` — ${W$}`:""]},x.id)),n.jsx("option",{value:"__buddi_custom__",children:"Custom model…"})]})}),n.jsx(E,{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 w9(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 y9(e,t){return[...e].sort().join(",")===[...t].sort().join(",")}const b9="This agent will not remember anything between conversations.";function k9({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(T=>p.has(T));if(C.length!==0){if(C.some(T=>g.has(T))){o({plugin:N,names:C});return}s(t.filter(T=>!C.includes(T)))}},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(E,{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($=>$.grantable).map($=>$.name),T=N.tools.filter($=>p.has($.name)).length,R=!!N.glob&&T===N.tools.length,I=`${m}-${N.plugin}`,L=`${m}-${N.plugin}-list`,_=j!==""?!c.has(N.plugin):c.has(N.plugin);return n.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":I,"data-open":_?"true":void 0,children:[n.jsxs("div",{className:"tool-picker-head",children:[n.jsxs("button",{type:"button",className:"tool-picker-toggle","aria-expanded":_,"aria-controls":L,onClick:()=>h(N.plugin),children:[n.jsx(N9,{}),n.jsx("span",{id:I,className:"tool-picker-plugin",children:N.plugin}),n.jsx("span",{className:"muted",children:R?`all ${N.tools.length}`:`${T} of ${N.tools.length} granted`})]}),n.jsx(E,{size:"sm",variant:"ghost","aria-label":`All ${N.plugin} tools`,disabled:r||C.every($=>p.has($)),onClick:()=>b(C),children:"all"}),n.jsx(E,{size:"sm",variant:"ghost","aria-label":`No ${N.plugin} tools`,disabled:r||!C.some($=>p.has($)),onClick:()=>v(N.plugin,C),children:"none"})]}),(l==null?void 0:l.plugin)===N.plugin?n.jsx(V,{tone:"warning",role:"alert",children:n.jsxs("div",{className:"tool-picker-confirm",children:[n.jsx("span",{children:b9}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(E,{size:"sm",onClick:()=>o(null),children:"Keep"}),n.jsx(E,{size:"sm",variant:"danger",onClick:()=>{s(t.filter($=>!l.names.includes($))),o(null)},children:"Remove"})]})}):null,n.jsx("ul",{id:L,className:"ui-list tool-picker-list",hidden:!_,children:S.map($=>{const P=`${m}-${$.name}`;return n.jsxs("li",{className:"ui-list-row",children:[n.jsx("input",{type:"checkbox",id:P,checked:p.has($.name),disabled:r||!$.grantable,onChange:O=>O.target.checked?b([$.name]):v(N.plugin,[$.name])}),n.jsxs("label",{htmlFor:P,className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[n.jsx("span",{className:"mono",children:$.name}),$.core?n.jsx(we,{tone:"accent",children:"core"}):null,$.gated?n.jsx(we,{tone:"warning",children:"asks you"}):null]}),n.jsx("span",{className:"ui-list-sub",children:$.grantable?$.description:`${$.description} Granted only by editing the file by hand.`})]})]},$.name)})})]},N.plugin)})]})}function N9(){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 ps={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."},ai=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function H$(e){let t;try{t=JSON.parse(e.trim())}catch{throw new Error(ps.json)}if(!ai(t))throw new Error(ps.json);let s,r=t;if("mcpServers"in t){const u=t.mcpServers;if(!ai(u))throw new Error(ps.empty);const h=Object.keys(u);if(h.length===0)throw new Error(ps.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(!ai(f))throw new Error(ps.url);r=f}if("command"in r)throw new Error(ps.command);if(typeof r.type=="string"&&r.type.toLowerCase()==="sse")throw new Error(ps.sse);const i=typeof r.url=="string"?r.url.trim():"";if(i==="")throw new Error(ps.url);const a=ai(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 _o={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 K$(e){return/TOKEN|KEY|SECRET|PASSWORD|PASSWD|CREDENTIAL|AUTH/i.test(e)}const V$=/^[A-Za-z_][A-Za-z0-9_]*$/;function S9(e){return/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$|^your[_-]/i.test(e.trim())}function G$(e,t){const s=S9(t);return{name:e,value:s?"":t,secret:K$(e),placeholder:s}}function Y$(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(_o.quote);return r&&t.push(s),t}function C9(e){const t=Y$(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(!V$.test(m))throw new Error(_o.env);r.push(G$(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(_o.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(ps.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:H$(JSON.stringify({mcpServers:{[l??"server"]:{type:a,url:h,headers:f}}}))}}if(!l||o.length===0)throw new Error(_o.claude);return{kind:"program",program:{name:l,command:o[0],args:o.slice(1),env:r}}}function E9(e){const t=e.trim();if(/^claude\s+mcp\s+add\b/.test(t))return C9(t);let s;try{s=JSON.parse(t)}catch{throw new Error(ps.json)}if(!ai(s))throw new Error(ps.json);let r,i=s;if("mcpServers"in s){const c=s.mcpServers;if(!ai(c))throw new Error(ps.empty);const u=Object.keys(c);u.length===1&&ai(c[u[0]])&&(r=u[0],i=c[r])}if(!("command"in i))return{kind:"remote",config:H$(t)};const a=typeof i.command=="string"?i.command.trim():"";if(a==="")throw new Error(_o.command);const l=Array.isArray(i.args)?i.args.map(c=>String(c)):[],o=ai(i.env)?Object.entries(i.env).filter(([c])=>V$.test(c)).map(([c,u])=>G$(c,String(u??""))):[];return{kind:"program",program:{...r?{name:r}:{},command:a,args:l,env:o}}}function Tw({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(E,{onClick:()=>void a(),children:r?"Copied":"Copy"})]})}function q$(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 A9="It can delete or destroy something, so it asks you every time and is never remembered.";function T9(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 J$="buddi-connections",$9="/connections/callback",R9="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.",Q$="Services and programs your team can use, and the tools each one brings.",$w=(e,t,s)=>`${e} ${e===1?t:s}`;function Z0(e,t){return e.transport==="stdio"?void 0:t.find(s=>Iw(s.url,e.url))}function Rw({connection:e,card:t,size:s}){return t?n.jsx(Rn,{letter:t.name.slice(0,1).toUpperCase(),size:s}):n.jsx(Rn,{icon:(e==null?void 0:e.transport)==="stdio"?"terminal":"globe",size:s})}function X$({connection:e}){const t=q$(e);return n.jsx(we,{tone:t.tone,dot:t.dot,children:t.label})}const sp=e=>t=>{t.stopPropagation(),e()},vd=[{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"}],Z$="buddi.connections.add-way";function I9(){try{const e=window.localStorage.getItem(Z$);return vd.some(t=>t.value===e)?e:"address"}catch{return"address"}}function P9({embedded:e,timezone:t,connection:s}={}){const r=de(()=>A.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"&&Iw(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(Mn,{embedded:e,title:"Connections",lede:Q$,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(ie,{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(Ge,{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(M9,{connection:N,card:Z0(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(Ge,{title:"Connect a service",children:n.jsx("div",{className:"connections-tiles",children:j.map(N=>n.jsxs("div",{className:"connections-tile",children:[n.jsx(Rw,{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(E,{size:"sm",onClick:()=>k({step:"address",card:N}),"aria-label":`Connect ${N.name}`,children:"Connect"})]},N.id))})}):null,m?n.jsx(_9,{onFlow:N=>k({step:N})}):null]}),x?n.jsx(O9,{connection:x,card:Z0(x,b),agentName:p,timezone:g,onClose:()=>o(null),onFlow:k,onDisconnect:()=>u(x.id),onHolders:()=>f(x.id)}):null,y&&m?n.jsx(L9,{connection:y,agents:m.agents,onCancel:()=>f(null),onDone:()=>{f(null),r.reload()}},y.id):null,w?n.jsx(F9,{connection:w,agentName:p,onCancel:()=>u(null),onDone:()=>{u(null),o(null),r.reload()}},w.id):null,i&&m?n.jsx(z9,{start:i,agents:m.agents,catalog:m.catalog,tokens:m.tokens??m.vault,onClose:()=>{a(null),r.reload()}}):null]})}function M9({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(Rw,{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(E,{size:"sm",variant:"accent",onClick:sp(()=>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(E,{size:"sm",onClick:sp(()=>i({step:"consent",connection:e,keepGrants:!0})),children:"Sign in"})}):e.state==="needs-review"?n.jsx("span",{className:"connections-act",children:n.jsx(E,{size:"sm",onClick:sp(()=>i({step:"review",connection:e,keepGrants:!0})),children:"Review"})}):null,n.jsx(X$,{connection:e}),n.jsx(ce,{name:"chevron-right",size:14})]})})}const D9={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 O9({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(qe,{title:n.jsxs("span",{className:"plugins-sheet-title",children:[n.jsx(Rw,{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(X$,{connection:e})]})]})]}),onClose:i,foot:n.jsxs(ae,{children:[n.jsx(E,{variant:"danger-ghost",onClick:o,children:"Disconnect…"}),n.jsx(dt,{}),u?n.jsx(E,{onClick:()=>a({step:"program",connection:e,keepGrants:!0}),children:"Change"}):null,e.authKind!=="none"&&!c?n.jsx(E,{variant:e.state==="needs-reconnect"?"accent":void 0,onClick:h,children:"Reconnect"}):null,c?n.jsx(E,{variant:"accent",onClick:m,children:"Finish"}):n.jsx(E,{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(E,{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(E,{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:D9[e.authKind]}],{label:"Tools",value:c?"Not reviewed yet":`${$w(e.toolCount,"tool","tools")}${e.reviewedAt?` · reviewed ${Le(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(E,{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(E,{size:"sm",onClick:()=>a({step:"address",card:t}),children:"Add another account"})]}):null]})}function L9({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 A.grantConnection(e.id,[...i],!0);p.failed.length>0?u(p.failed.map(g=>`${g.agent}: ${g.message}`).join("; ")):r()}catch(p){u(Ws(p))}finally{o(!1)}};return n.jsxs(Lt,{title:`Who holds ${e.name}`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",disabled:l,onClick:s,children:"Cancel"}),n.jsx(E,{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(ie,{message:c})]})}function F9({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 A.disconnect(e.id),r()}catch(h){o(Ws(h))}finally{a(!1)}};return n.jsxs(Lt,{title:`Disconnect ${e.name}?`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",disabled:i,onClick:s,children:"Cancel"}),n.jsx(E,{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(ie,{message:l})]})}function _9({onFlow:e}){const[t,s]=d.useState(I9),r=vd.find(a=>a.value===t)??vd[0],i=a=>{s(a);try{window.localStorage.setItem(Z$,a)}catch{}};return n.jsx(Ge,{title:"Add your own",actions:n.jsx(Yt,{label:"How to add it",options:vd.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(E,{variant:"accent",onClick:()=>e(t),children:r.button})]})})}function z9({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&&Iw(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(qe,{title:w,onClose:i,size:"wide",children:[l==="paste"?n.jsx(U9,{onRead:y=>{y.kind==="program"?(v(y.program),o("program")):(p(y.config),o("address"))}}):null,l==="address"?n.jsx(B9,{card:j,pasted:m,onDone:(y,k)=>{u(y),k==="none"?o("review"):(f(k),o("consent"))}}):null,l==="program"?n.jsx(J9,{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(K9,{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(Q9,{connection:c,onKept:y=>{u(y),e.keepGrants?i():o("grant")}}):null,l==="grant"&&c?n.jsx(X9,{connection:c,agents:t,onDone:i}):null]})}function Iw(e,t){const s=r=>r.trim().replace(/\/+$/,"").toLowerCase();return s(e)===s(t)}function Ws(e){return e instanceof Error?e.message:String(e)}function U9({onRead:e}){const[t,s]=d.useState(""),[r,i]=d.useState(null),a=()=>{try{const l=E9(t);s(""),i(null),e(l)}catch(l){i(Ws(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(ie,{message:r}),n.jsx(ae,{align:"end",children:n.jsx(E,{type:"submit",variant:"accent",disabled:t.trim()==="",children:"Read it"})})]})}function B9({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 A.addConnection(r.trim(),(e==null?void 0:e.name)??(t==null?void 0:t.name));s(g.connection,g.signIn)}catch(g){c(Ws(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(ie,{message:o}),n.jsx(ae,{align:"end",children:n.jsx(E,{type:"submit",variant:"accent",disabled:a||r.trim()==="",children:a?"Opening…":"Continue"})})]})}const W9={device:"Device",oauth:"Sign in",token:"Token",client:"Client id"};function H9(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 K9({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=H9(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(R9),[x,w]=d.useState(""),[y,k]=d.useState(null),[N,S]=d.useState(!1),[C,T]=d.useState(null),[R,I]=d.useState(!1),[L,_]=d.useState(null),$=`${location.origin}${$9}`,P=d.useRef(o);P.current=o,d.useEffect(()=>{if(!R)return;let q=!1;const W=async()=>{if(!q){q=!0;try{P.current(await A.connection(e.id))}catch(ee){T(Ws(ee))}}},Y=typeof BroadcastChannel=="function"?new BroadcastChannel(J$):null;Y&&(Y.onmessage=ee=>{var fe;((fe=ee.data)==null?void 0:fe.id)===e.id&&W()});let F;const X=Date.now(),Q=async()=>{if(!q){try{const ee=await A.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),T("The sign-in did not come back within ten minutes. Start it again.");return}F=window.setTimeout(()=>void Q(),l)}};return F=window.setTimeout(()=>void Q(),l),()=>{q=!0,Y==null||Y.close(),window.clearTimeout(F)}},[R,e,l]);const O=async q=>{var W;S(!0),T(null);try{const{authorizeUrl:Y}=await A.connectionConsent(e.id,q);k(Y)}catch(Y){Y instanceof ve&&((W=Y.detail)==null?void 0:W.code)==="client-id"?(j(Y.message),u("manual"),g("client")):T(Ws(Y))}finally{S(!1)}};d.useEffect(()=>{v!=="oauth"||y!==null||O()},[v]);const M=q=>{const W=window.open(q,"_blank");W?(W.opener=null,_(null)):_(q),I(!0)},D=q=>{g(q),k(null),T(null),I(!1),_(null)};return n.jsxs("div",{className:"ui-stack",children:[f.length>1?n.jsx(Yt,{label:"How to sign in",options:f.map(q=>({value:q,label:W9[q]})),value:v,onChange:D}):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:q=>{w(q.target.value),k(null),I(!1)}})}),n.jsxs("p",{className:"ui-card-meta",children:["Its redirect address: ",n.jsx("span",{className:"mono",children:$})]})]}):null,v==="token"?n.jsx(Y9,{connection:e,card:s,pasted:r,placeholder:i,onSignedIn:o}):null,v==="device"?n.jsx(G9,{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(ie,{message:C}):null,v==="oauth"?n.jsx(ae,{align:"end",children:n.jsx(E,{variant:"accent",onClick:()=>{y&&M(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(E,{variant:"accent",onClick:()=>void O(x.trim()),disabled:N||x.trim()==="",children:N?"Checking…":"Continue"}):n.jsx(E,{variant:"accent",onClick:()=>M(y),children:R?"Open it again":`Open ${e.name}’s sign-in page`})}):null]})}function V9(e){try{const t=new URL(e);return`${t.host}${t.pathname==="/"?"":t.pathname.replace(/\/$/,"")}`}catch{return e}}function G9({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 A.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 A.connectionDevice(e.id);if(v)return;a({userCode:x.userCode,verificationUri:x.verificationUri}),b=window.setTimeout(()=>void j(),s)}catch(x){v||o(Ws(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?V9(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(Tw,{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(E,{variant:"accent",onClick:()=>p(i.verificationUri),children:["Open ",g]})})]}):null,l!==null?n.jsxs(n.Fragment,{children:[n.jsx(ie,{message:l}),n.jsx(ae,{align:"end",children:n.jsx(E,{variant:"accent",onClick:()=>u(v=>v+1),children:"Start again"})})]}):null]})}function Y9({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 A.connectionToken(e.id,{token:a.trim(),header:o.trim(),prefix:u});l(""),i(w.connection)}catch(w){g(Ws(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(Bs,{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(ie,{message:p}),n.jsx(ae,{align:"end",children:n.jsx(E,{type:"submit",variant:"accent",disabled:f||a.trim()===""||o.trim()==="",children:f?"Trying it…":"Try it and keep it"})})]})}function q9(e){return e!==""&&/^[A-Za-z0-9_@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function J9({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($=>({key:l(),value:$}))),[p,g]=d.useState(()=>i?i.env.map($=>({key:l(),name:$.name,value:$.value??"",secret:$.secret,kept:$.secret})):((t==null?void 0:t.env)??[]).map($=>({key:l(),name:$.name,value:$.value,secret:$.secret,kept:!1}))),[v,b]=d.useState(!1),[j,x]=d.useState(null),w=/\s/.test(u.trim())?Y$(u.trim()):[u.trim()],y=w[0]??"",k=[...w.slice(1),...f.map($=>$.value)],N=[y,...k].filter(($,P)=>P>0||$!==""),S=()=>{w.length<2||(h(y),m($=>[...w.slice(1).map(P=>({key:l(),value:P})),...$]))},C=N.map(q9).join(" "),T=p.filter($=>$.secret&&$.value===""&&!$.kept).map($=>$.name||"a variable"),R=((t==null?void 0:t.env)??[]).filter($=>$.placeholder).map($=>$.name),I=($,P)=>m(O=>O.map(M=>M.key===$?{...M,value:P}:M)),L=($,P)=>g(O=>O.map(M=>M.key===$?{...M,...P}:M)),_=async()=>{b(!0),x(null);const $={name:o.trim(),command:y,args:k,env:p.filter(P=>P.name.trim()!=="").map(P=>({name:P.name.trim(),value:P.value,secret:P.secret}))};try{r(e?await A.updateProgram(e.id,$):(await A.addProgram($)).connection),g(P=>P.map(O=>O.secret?{...O,value:""}:O))}catch(P){x(Ws(P))}finally{b(!1)}};return n.jsxs("form",{className:"ui-stack",onSubmit:$=>{$.preventDefault(),_()},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(Bs,{columns:2,children:[n.jsx(oe,{label:"Name",children:n.jsx("input",{required:!0,autoFocus:!t&&!e,maxLength:80,spellCheck:!1,value:o,onChange:$=>c($.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:$=>h($.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(($,P)=>n.jsxs("div",{className:"connections-row",children:[n.jsx("input",{"aria-label":`Argument ${P+1}`,className:"mono",spellCheck:!1,autoComplete:"off",value:$.value,onChange:O=>I($.key,O.target.value)}),n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>m(O=>O.filter(M=>M.key!==$.key)),"aria-label":`Remove argument ${P+1}`,children:"Remove"})]},$.key)),n.jsx(ae,{children:n.jsx(E,{size:"sm",onClick:()=>m($=>[...$,{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(($,P)=>n.jsxs("div",{className:"connections-row","data-kind":"env",children:[n.jsx("input",{"aria-label":`Variable ${P+1} name`,className:"mono",spellCheck:!1,autoComplete:"off",placeholder:"NAME",value:$.name,onChange:O=>{const M=O.target.value;L($.key,$.value===""&&!$.kept?{name:M,secret:K$(M)}:{name:M})}}),n.jsx("input",{"aria-label":`Variable ${P+1} value`,type:$.secret?"password":"text",spellCheck:!1,autoComplete:"off",placeholder:$.kept&&$.value===""?"Kept. Type to replace it.":"value",value:$.value,onChange:O=>L($.key,{value:O.target.value})}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:$.secret,onChange:O=>L($.key,{secret:O.target.checked,kept:O.target.checked&&$.kept})}),n.jsx("span",{children:"Secret"})]}),n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>g(O=>O.filter(M=>M.key!==$.key)),"aria-label":`Remove variable ${P+1}`,children:"Remove"})]},$.key)),n.jsx(ae,{children:n.jsx(E,{size:"sm",onClick:()=>g($=>[...$,{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($=>$.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(ie,{message:j}),n.jsx(ae,{align:"end",children:n.jsx(E,{type:"submit",variant:"accent",disabled:v||o.trim()===""||u.trim()===""||T.length>0,title:T.length>0?`Give ${T.join(", ")} a value.`:void 0,children:v?"Saving…":e?"Save":"Continue"})})]})}function Q9({connection:e,onKept:t}){const s=de(()=>A.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 A.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(Ws(g))}finally{l(!1)}}};if(!u)return s.error?n.jsx(ie,{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=T9(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(qg,{children:"New"}):p.change==="changed"?n.jsx(qg,{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?A9:"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(ie,{message:o}),n.jsx(ae,{align:"end",children:n.jsx(E,{variant:"accent",onClick:()=>void f(),disabled:a||u.slugEditable&&h.trim()==="",children:m===1?"Keep this tool":`Keep these ${m} tools`})})]})}function X9({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(()=>A.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 A.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 A.setRememberedApproval(x,w,!0);s()}catch(j){p(Ws(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(ie,{message:m}),n.jsxs(ae,{align:"end",children:[n.jsx(E,{onClick:s,disabled:h,children:"Not now"}),n.jsx(E,{variant:"accent",onClick:()=>void v(),disabled:h||i.size===0,children:"Give them"})]})]})}const Z9=(e,t,s)=>`${e} ${e===1?t:s}`;function e7(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 t7({agentId:e,agentName:t,readOnly:s,version:r,onSaved:i}){const[a,l]=d.useState({}),o=de(()=>A.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 A.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(ie,{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=e7(w),N=w.transport==="stdio"?"on this computer":w.host,S=w.slug?Z9(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:T=>void p(w,T.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:q$(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 n7=(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 eR(e){const t=await fetch(wa(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 s7({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,Wz.map(o=>{const c={kind:"mascot",role:o},u=n7(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:wa(o),alt:""})},o)})]}),n.jsx("div",{className:"meet-face-row",children:Kz.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 r7=["mirror","en","fr"],i7=[{value:"3h",label:"3 hours"},{value:"1d",label:"A day"},{value:"1w",label:"A week"},{value:"never",label:"Never"}],rp=10,ip=500,tR=[{id:"identity",label:"Identity"},{id:"brain",label:"Brain"},{id:"tools",label:"Tools"},{id:"team",label:"Team"}],eN=e=>{var t;return e==="access"?"tools":((t=tR.find(s=>s.id===e))==null?void 0:t.id)??"identity"};function a7({agentId:e,section:t,navigate:s}){var v,b,j;const{data:r,error:i,reload:a}=de(()=>A.agents(),[]),[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(eN(t));d.useEffect(()=>f(eN(t)),[t]);const m=x=>{f(x),s==null||s(St(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(Yc,{level:"secondary",label:"Setup",children:tR.map(x=>n.jsx(bl,{href:St(e,"setup",x.id),active:h===x.id,onClick:w=>{w.preventDefault(),m(x.id)},children:x.label},x.id))}),n.jsx(ie,{message:i??l}),c?n.jsx(V,{tone:"good",role:"status",children:c}):null,r?g?n.jsx(l7,{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 l7({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(A.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:St(e.id,"setup","brain"),onClick:N=>{N.preventDefault(),l("brain")},children:"See Brain."})]}),n.jsx(o7,{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(p7,{agentId:e.id,accounts:i,onRun:o}):n.jsxs(Bs,{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(Bs,{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:rp,max:ip,value:m,onChange:N=>{p(N.target.value),v(null)},onBlur:()=>{const N=Number(m);if(!Number.isInteger(N)||N<rp||N>ip){v(`Between ${rp} and ${ip}.`);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:r7.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:i7.map(N=>n.jsx("option",{value:N.value,children:N.label},N.value))})}):null,nE(sE(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:TL,children:n.jsx("span",{className:"ui-card-meta",children:"Up to the model"})})]})})]})}),n.jsx(At,{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(c7,{agent:e,all:t,onSaved:c}),n.jsx(t7,{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(j7,{agent:e,all:t,onSaved:c})})})]})}function nR({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(E,{variant:"accent",disabled:!e||t,onClick:i,children:r})]})}const sR=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 o7({agent:e,onSaved:t}){var _;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(()=>A.agentFile(e.id),[e.id]),[p,g]=d.useState(null),v=((_=m.data)==null?void 0:_.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,T=c.trim()!==""&&(c.trim()!==(e.avatar??"")||!e.picture),R=$x(T?{...e,avatar:c.trim()}:e),I={...R?{avatar:R}:{},...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...!T&&e.picture?{picture:e.picture}:{}},L=async()=>{w(!0),k(null),S(null);try{const $=await A.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 A.removeAgentPicture(e.id),window.dispatchEvent(new Event(hr))),g(null),m.reload(),S($.message),t()}catch($){k($ instanceof Error?$.message:String($))}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(nR,{dirty:C,busy:x,failure:y,label:"Save who it is",onSave:()=>void L()}),children:n.jsxs(le,{children:[e.isExample?sR:null,N?n.jsx(V,{tone:"good",role:"status",children:N}):null,n.jsxs(Bs,{children:[n.jsx(oe,{label:"Name",hint:"What it is called, everywhere.",children:n.jsx("input",{value:s,disabled:x||e.isExample,onChange:$=>r($.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:$=>a($.target.value)})})]}),n.jsxs(ae,{children:[n.jsx(kn,{id:e.id,name:s.trim()||e.name,size:"xl",face:I}),n.jsx(E,{"aria-expanded":h,onClick:()=>f($=>!$),children:h?"Hide faces":"Change face"})]}),h?n.jsx(f7,{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:$=>o($.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(ie,{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:$=>g($.target.value)}):n.jsx(pe,{children:"Reading its file…"})})]})})}function c7({agent:e,all:t,onSaved:s}){var T;const r=de(()=>A.agentTools(e.id),[e.id,e.tools.join(",")]),[i,a]=d.useState(null),[l,o]=d.useState(()=>new Set((e.roles??[]).filter(yk))),[c,u]=d.useState((e.roles??[]).filter(R=>!yk(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=((T=r.data)==null?void 0:T.granted)??e.tools,x=i??j,w=r.data!==void 0&&!y9(x,j),y=bk(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,bk(new Set(e.roles??[]),e.roles??[])),C=async()=>{f(!0),p(null),v(null);try{const R=await A.updateAgentFile(e.id,{...w&&r.data?{tools:w9(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(nR,{dirty:S,busy:h,failure:m,label:"Save roles and tools",onSave:()=>void C()}),children:n.jsxs(le,{children:[e.isExample?sR: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:Ej.map(R=>{const I=B4(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(ie,{message:r.error}):r.data?n.jsx(k9,{view:r.data,chosen:x,onChange:a,disabled:h||e.isExample}):n.jsx(pe,{children:"Loading the installed tools…"})]}),n.jsx(u7,{agentId:e.id,version:j.join(","),disabled:h||e.isExample}),d7(j)?n.jsx(h7,{agentId:e.id}):null]})})}function u7({agentId:e,version:t,disabled:s}){var g;const r=de(()=>Promise.resolve().then(()=>A.rememberedApprovals(e)),[e,t]),i=de(()=>Promise.resolve().then(()=>A.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 A.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(At,{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(ie,{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 d7(e){return e.some(t=>t==="owner.notify"||t==="owner.*"||t==="owner.notify?"||t==="owner.*?")}function h7({agentId:e}){var h,f;const t=de(()=>A.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),A.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(ie,{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 $x(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 f7({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 A.uploadAgentPicture(e.id,await eR(g.role)),s(e.avatar??""),r(),window.dispatchEvent(new Event(hr))}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(s7,{face:m,label:"Face",kept:e.picture,disabled:i||o,disableEmoji:e.isExample,onPick:g=>void p(g),children:n.jsx(m7,{agent:e,onChanged:r})}),u?n.jsx("span",{className:"critical save-error",role:"alert",children:u}):null]})}function m7({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(hr))},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 A.uploadAgentPicture(e.id,s)).note??null),j=()=>v(async()=>(await A.removeAgentPicture(e.id),null)),x={avatar:$x(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(kn,{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(E,{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(E,{variant:"ghost",disabled:l,onClick:()=>void j(),children:"Remove picture"}):null,n.jsx(E,{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 p7({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(Aw,{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(E,{variant:"accent",disabled:c||!i||!l.trim()||!f,onClick:()=>{u(!0),s(A.assignProviderAccount(e,i,l).finally(()=>u(!1)))},children:"Save account selection"})]})]})}const g7=["platform.create_agent","platform.update_agent","platform.write_skill","platform.delete_agent","platform.accept_plugin_agent","platform.accept_plugin_skill"],ap=e=>e.tools.some(t=>g7.includes(t)),x7=["front-desk","maker"],v7={"front-desk":"Can ask: everyone, as the front desk",maker:"Can ask: everyone, as the maker",list:"Can ask: everyone"};function j7({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&&!ap(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 A.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=>!ap(R)).map(R=>R.id)),b(!0),h(!1)},T=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:T}),n.jsx("span",{className:"ui-toolbar-spacer"}),w&&x!==void 0?n.jsx(E,{disabled:a,onClick:()=>void S(["*"]),children:"Let it ask everyone"}):null,w?n.jsx(E,{variant:"accent",disabled:!y||a,onClick:()=>void S(r),children:"Save who it can ask"}):n.jsx(E,{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(ie,{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=ap(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:[v7[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(LU,{children:k.map(R=>n.jsx(we,{children:R.name},R.id))})})]})})}const w7=[{id:"team",label:"Team"},{id:"missions",label:"Missions"},{id:"offers",label:"Offers"},{id:"reminders",label:"Reminders"},{id:"skills",label:"Skills"}],y7=[{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 b7(e){const t=b4(e.hash);return t?n.jsx(FV,{name:t.name,agents:e.agents,navigate:e.navigate,pluginPages:e.pluginPages}):n.jsx(k7,{...e})}function k7({hash:e,timezone:t,navigate:s,agents:r,attention:i,defaultAgentId:a}){var j,x,w,y,k;const l=j4(e),o=((j=/[?&]tab=([a-z]+)/.exec(e))==null?void 0:j[1])??"team",c=N=>S=>{S.preventDefault(),s(N)},u=de(()=>A.agents(),[]),h=yf(),f=de(()=>A.offers(),[],2e4),m=kT(),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(yl,{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(E,{onClick:()=>b({kind:"upload",at:Date.now()}),children:"Upload a .md"}),n.jsx(E,{variant:"accent",onClick:()=>b({kind:"write",at:Date.now()}),children:"Write a skill"})]}):n.jsx(Et,{variant:"accent",href:Ht(),onClick:c(Ht()),children:"Add a teammate"})}),n.jsx(Yc,{children:w7.map(N=>n.jsx(bl,{href:N.id==="team"?ft:`${ft}?tab=${N.id}`,active:o===N.id,count:N.id==="offers"?p:void 0,onClick:c(N.id==="team"?ft:`${ft}?tab=${N.id}`),children:N.label},N.id))}),o==="missions"?n.jsx(b$,{timezone:t,embedded:!0}):null,o==="offers"?n.jsx(NT,{offers:m.offers,reload:m.reload}):null,o==="offers"?n.jsx(N$,{embedded:!0}):null,o==="reminders"?n.jsx(z$,{timezone:t,embedded:!0}):null,o==="skills"?n.jsx(a9,{faces:r,navigate:s,command:v,openSkill:JV(e)}):null,o==="team"?n.jsx(N7,{data:u.data,error:u.error,reload:u.reload}):null,o==="team"?r.length===0?n.jsx($n,{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:dA(r,g).map(N=>{const S=df(i.get(N.id));return n.jsxs("div",{className:"ui-card agent-card","data-interactive":"true",...Hc(Wc(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(kn,{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:St(N.id,"conversations"),onClick:c(St(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(qg,{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:Us(N.unavailableReason??"cannot run",60)}),n.jsx(we,{mono:!0,children:N.model}),n.jsx(Et,{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(qe,{title:((k=r.find(N=>N.id===l.agentId))==null?void 0:k.name)??l.agentId,size:"wide",onClose:()=>s(ft),children:n.jsx(S7,{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 N7({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(ie,{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 A.setDefaultAgent(p);f(x.note),a(null),s()}catch(x){u(x instanceof Error?x.message:String(x))}finally{o(!1)}};return n.jsx(Ge,{children:n.jsxs("div",{className:"ui-stack",children:[n.jsx(ie,{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(E,{variant:"accent",disabled:l||!g,onClick:()=>void j(),children:"Save"})]})]})})}function S7({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=df(o.get(e)),h=(t==null?void 0:t.name)??e,f=BV(e),m=t!==void 0&&!t.roles.includes(Kc)&&!t.roles.includes(Bc);return n.jsxs("div",{className:"ui-stack","data-gap":"lg",children:[n.jsxs("header",{className:"agent-head",children:[n.jsx(kn,{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(WV,{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(Et,{variant:"accent",href:st(e),onClick:c(st(e)),children:["Talk to ",h]})})]}),t&&!t.available?n.jsxs(V,{tone:"warning",role:"status",children:[fA(t)," ",n.jsx("a",{href:Pe(Wg(t).section),children:Wg(t).label})]}):null,n.jsx(Yc,{children:y7.map(p=>n.jsx(bl,{href:St(e,p.id),active:r===p.id,onClick:c(St(e,p.id)),children:p.label},p.id))}),r==="conversations"?n.jsx(C7,{agentId:e,navigate:l}):null,r==="missions"?n.jsx(b$,{timezone:a,embedded:!0,agentId:e}):null,r==="offers"?n.jsx(N$,{embedded:!0,agentId:e,agentName:h}):null,r==="reminders"?n.jsx(z$,{timezone:a,embedded:!0,agentId:e}):null,r==="memory"?n.jsx(R$,{embedded:!0,agents:s,timezone:a,agentId:e}):null,r==="skills"?n.jsx(g9,{agentId:e,agentName:h,faces:s,navigate:l}):null,r==="setup"?n.jsx(a7,{agentId:e,section:i,navigate:l}):null,r==="setup"&&m?n.jsx(KV,{agentId:e,name:h,navigate:l}):null]})}function C7({agentId:e,navigate:t}){const{data:s,error:r}=de(()=>He.conversations(e,50),[e]);if(r)return n.jsx(pe,{children:r});const i=(s==null?void 0:s.conversations)??[];return n.jsx(Ge,{flush:!0,children:s?i.length===0?n.jsx($n,{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:Us(a.preview||a.opening||"Untitled conversation",90),sub:`${a.messageCount} message${a.messageCount===1?"":"s"}`,side:Le(a.lastMessageAt??a.startedAt??a.createdAt??null)},a.id))}):n.jsx(pe,{children:"Loading…"})})}const E7=3e4;function rR(){const{data:e,reload:t}=de(()=>A.recovery(),[],E7),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 tN(e){return e.kind==="account"?e.accountId?nA(e.accountId):Pe("accounts"):e.kind==="telegram"?Pe("telegram"):e.kind==="connection"?e.connectionId?sA(e.connectionId):Pe("connections"):e.kind==="email"?e.settingsRoute:Pe("secrets")}function A7(e){return e.install?$4(e.install):R4}const T7=Pe("system");function $7(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 iR="This buddi was restored from a backup. Nothing runs on its own until you finish the checklist.";function R7({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),uf({kind:"recovery"},()=>A.leaveRecovery({dropPending:o,keepGrants:u})).then(k=>{k&&k.restarting===!1&&wl(),b(!0),t==null||t()}).catch(k=>g(k instanceof ve?k.message:String(k))).finally(()=>m(!1))};return n.jsx(Ge,{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(Et,{size:"sm",href:tN(k),"aria-label":`Sign in again: ${k.label??k.name}`,children:"Sign in again"}):n.jsx(Et,{size:"sm",href:tN(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:$7(k),side:k.loadsAtRestart?n.jsx(Et,{size:"sm",href:T7,"aria-label":`Restart to load ${k.name}`,children:"Restart"}):k.installed?void 0:n.jsx(Et,{size:"sm",href:A7(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(ie,{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(E,{variant:"accent",disabled:f||v,onClick:y,children:"Leave recovery mode"})})]})})]})})}function I7({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 aR(e,t,s=4){const r=a=>!!a&&Oi(a)==="ready"&&a.addable,i=I7(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 P7(e,t){const s=e.filter(r=>r.id!==t&&!r.roles.includes(Bc)&&!r.roles.includes(Kc));return e.length>0&&s.length<=1}async function M7(e,t=E$){try{const{jobId:s}=await A.catalogueInstall(e.name,{version:e.version,tools:e.tools});for(;;){const r=await A.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 D7({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(Yl,{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 O7({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(Yl,{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(E,{size:"sm",variant:"accent","aria-label":`Add ${e.title}`,onClick:i=>{i.stopPropagation(),r()},children:"Add"})]})}function L7({navigate:e}){const[t,s]=d.useState(null),[r,i]=d.useState(null),[a,l]=d.useState([]),o=vw();d.useEffect(()=>{let u=!1;return A.catalogue().then(h=>{u||s(h.unavailable?[]:h.agents)}).catch(()=>{u||s([])}),()=>{u=!0}},[]);const c=d.useMemo(()=>t===null?null:aR(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(O7,{entry:u,added:a.includes(u.name),onOpen:()=>e(Ht(u.name)),onAdd:()=>i(u)},u.name))}),r?n.jsx(A$,{entry:r,navigate:e,onClose:()=>i(null),onAdded:()=>{l(u=>[...u,r.name]),window.dispatchEvent(new Event(hr))}}):null]})}function F7({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 A.catalogue().then(w=>{if(x)return;const y=w.unavailable?[]:aR(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 M7(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(hr))},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(E,{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(E,{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(D7,{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(E,{variant:"ghost",onClick:p,children:"See all teammates"}),n.jsx(dt,{}),n.jsx(E,{variant:"accent",disabled:v===0||l==="adding",onClick:()=>void g(),children:b})]})})]})})}const nN=3,_7=40;function z7({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(()=>He.conversations(e.id,nN),[e.id],3e4),h=ks(Lj),f=ks("(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 He.startConversation(e.id),x=await He.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,nN);return n.jsxs("div",{className:"home-ask",children:[a?n.jsx(ie,{message:a}):null,n.jsx(Qj,{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=lj(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:Us(j,_7)}),x?n.jsx("span",{className:"home-continue-when",children:x}):null]})},v.id)})})]}):null]})}function U7(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 B7({navigate:e,preview:t,hidden:s}){var c;const r=de(()=>A.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"?A.dismissTip(l.id):A.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(dt,{}),n.jsx(E,{variant:"ghost",size:"sm",onClick:()=>o("dismiss"),children:"Not this again"}),n.jsx(E,{variant:"accent",size:"sm",onClick:()=>e(l.action.route),children:l.action.label})]})]})})}const Rx="buddi.tipsOpen";function W7(e){return Lc(e,{compact:!0})}function H7(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 ${W7(e.shownAt)}`:"Shown"}}function K7(){try{return window.localStorage.getItem(Rx)==="1"}catch{return!1}}function V7(){const e=de(()=>A.tips(),[]),[t,s]=d.useState(K7),r=d.useCallback(i=>{s(i);try{i?window.localStorage.setItem(Rx,"1"):window.localStorage.removeItem(Rx)}catch{}},[]);return{open:t,setOpen:r,list:e}}function G7({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 Y7({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),A.restoreTip(x).then(()=>i.reload(),p).finally(()=>c(null))},v=x=>{c("switch"),l(null),h(x),A.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(ie,{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(us,{tone:x.status==="today"?"accent":void 0,children:[n.jsx("div",{children:n.jsx(we,{tone:x.status==="today"?"accent":"muted",children:H7(x)})}),n.jsx("p",{className:"tips-card-text",children:x.text}),n.jsxs(ae,{children:[n.jsx(dt,{}),x.status==="dismissed"?n.jsx(E,{size:"sm",disabled:o===x.id,onClick:()=>g(x.id),children:"Bring back"}):n.jsx(E,{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(dt,{}),n.jsx(E,{variant:"ghost",size:"sm",onClick:()=>r(!1),children:"Close"})]})]})})}const lR="buddi.needsYouView";function q7(){try{return window.localStorage.getItem(lR)==="list"?"list":"deck"}catch{return"deck"}}function J7(e){try{window.localStorage.setItem(lR,e)}catch{}}function Q7(e,t,s){const r=(t.alsoFrom??[]).filter(i=>i!==t.agentId).map(s);return r.length===0?e:`${e} · also ${r.join(", ")}`}function X7({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(on,{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(us,{as:"article",title:g,meta:n.jsx("span",{className:"ui-card-meta",children:c.state==="held"?"today":Le(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(E,{size:"sm",variant:"ghost","aria-label":"Previous",disabled:!u,onClick:()=>h(-1),children:n.jsx(ce,{name:"chevron-left"})}),n.jsx(E,{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(E,{onClick:m,children:"Done"}),c.link||c.agentId?n.jsx(E,{variant:"accent",onClick:f,children:"Open"}):null]}),children:n.jsxs("div",{className:"home-deck-body",children:[n.jsx("p",{className:"home-deck-title",children:fc(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 Z7({timezone:e,navigate:t,agents:s,defaultAgentId:r,attention:i,update:a,connectionSignals:l=[],hash:o="",pluginPages:c}){var Ye,kt,qt,re,be,Qe,ct,yt,ut,pn,Yn,Z,Re,Xe,xt;const u=de(()=>A.overview(),[],15e3),h=de(()=>A.approvals(),[],1e4),f=de(()=>A.missions(),[],6e4),m=de(()=>A.reminders(),[],6e4),p=de(()=>A.conversations(),[],3e4),g=de(()=>A.offers(),[],3e4),v=de(()=>A.proposals(),[],6e4),b=de(()=>A.agentOffers(),[],6e4),j=de(()=>A.owner(),[]),x=de(()=>A.notificationsNeedingYou(),[],3e4),w=d.useMemo(()=>dA(s,r??null),[s,r]),y=P7(s,r),{busy:k,note:N,failure:S,decide:C}=Xj(()=>{h.reload(),u.reload()}),T=u.data,R=s.find(G=>G.id===r)??null,I=G=>{var he;return((he=s.find(Be=>Be.id===G))==null?void 0:he.name)??G},L=G=>he=>{he.preventDefault(),t(G)},_=((Ye=h.data)==null?void 0:Ye.pending)??[],$=((kt=T==null?void 0:T.jobs)==null?void 0:kt.failed)??0,P=((qt=T==null?void 0:T.sentinels)==null?void 0:qt.openUrgent)??0,O=((re=v.data)==null?void 0:re.open.length)??0,M=(((be=b.data)==null?void 0:be.offers)??[]).filter(G=>!_.some(he=>bT(he,G.plugin,G.agent))),D=tG(((Qe=x.data)==null?void 0:Qe.notifications)??[],_),[H,B]=d.useState(new Set),[q,W]=d.useState(q7),Y=D.filter(G=>!H.has(G.id)),F=G=>{B(he=>new Set(he).add(G.id)),A.notificationSeen(G.id).catch(()=>{})},X=G=>{F(G);const he=G.link??(G.agentId?st(G.agentId):null);he&&t(he)},Q=G=>Q7(G.agentId?I(G.agentId):G.pluginId?KA(G.pluginId,c==null?void 0:c.all):eG[G.kind],G,I),ee=iG(T==null?void 0:T.dismissed,()=>u.reload()),fe=(((ct=T==null?void 0:T.sentinels)==null?void 0:ct.errors)??[]).filter(G=>!ee.is(`watcher-error:${G.sentinelId}`,G.error)),Oe=((T==null?void 0:T.mail)??[]).filter(G=>G.lastError&&!ee.is(`source-error:${G.sourceId}`,G.lastError)),Ie=nG(i),Fe=l.filter(G=>!ee.is(`connection:${G.id}`,G.sentence)),U=(((yt=T==null?void 0:T.needsYou)==null?void 0:yt.recovery)??0)>0,se=_.length+Ie.length+($>0?1:0)+(P>0?1:0)+(O>0?1:0)+M.length+D.length+Fe.length+(U?1:0);d.useEffect(()=>{var G,he;o===jl&&((he=(G=document.getElementById(Ix))==null?void 0:G.scrollIntoView)==null||he.call(G,{behavior:"smooth",block:"start"}))},[o]);const J=d.useMemo(()=>{var G,he;return cG(((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=((pn=g.data)==null?void 0:pn.offers)??[],$e=ge.slice(0,aG),De=V7(),Je=ge.length-$e.length,ze=n$(()=>u.reload()),Se=ZH(),Ue=d.useMemo(()=>eK(Se.answer),[Se.answer]),at=pG((T==null?void 0:T.needsYou)??{approvals:_.length,questions:Ie.length,failed:$,urgent:P,proposals:O,agentsToSetUp:M.length,asks:D.length,signIns:Fe.length,recovery:U?1:0},(T==null?void 0:T.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:hG(T==null?void 0:T.now,e)}),n.jsx(TH,{glances:T==null?void 0:T.glances,navigate:t,except:Ue,hiding:ze}),n.jsx(G7,{tips:De})]}),n.jsx("h1",{className:"home-greeting",children:dG(T==null?void 0:T.now,e,((Yn=j.data)==null?void 0:Yn.preferredName)||((Z=j.data)==null?void 0:Z.displayName))}),n.jsx(gG,{items:at,navigate:t})]}),n.jsx("div",{className:"home-side",children:n.jsx(jA,{size:"lg",anim:"idle"})})]})}),n.jsxs("div",{className:"home",children:[R?n.jsx(z7,{agent:R,navigate:t},R.id):null,n.jsx(Y7,{tips:De,navigate:t}),n.jsx(B7,{navigate:t,preview:U7(o),hidden:De.open}),a&&a.updateAvailable&&!a.checkout&&a.latest&&!ee.is("update",a.latest)?n.jsx(V,{tone:"accent",action:n.jsx(Qa,{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(Qa,{label:"Hide until the error changes",onClick:()=>ee.close(`watcher-error:${G.sentinelId}`,G.error)}),children:["Watcher ",G.sentinelId," failed: ",G.error]},G.sentinelId)),Oe.map(G=>n.jsxs(V,{tone:"warning",action:n.jsx(Qa,{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(ie,{message:u.error??h.error??S}),N?n.jsx(V,{tone:"good",role:"status",children:N}):null,se>0?n.jsx("div",{id:Ix,className:"home-needs",children:n.jsx(ue,{title:"Needs you",aside:n.jsx("a",{href:_g,onClick:L(_g),children:"All notifications"}),actions:D.length>0?n.jsx(Yt,{label:"Show what needs you as",options:[{value:"list",label:"List"},{value:"deck",label:"Deck"}],value:q,onChange:G=>{W(G),J7(G)}}):void 0,children:n.jsxs(le,{children:[_.map(G=>n.jsx(Zj,{action:G,timezone:e,busy:k===G.id,onDecide:C,agentName:I(G.agentId)},G.id)),P>0?n.jsx(V,{tone:"warning",children:n.jsx("a",{href:`${jt}/alerts`,onClick:L(`${jt}/alerts`),children:mG(P,((Re=T==null?void 0:T.sentinels)==null?void 0:Re.decisions)??[])})}):null,Ie.length>0||D.length>0&&q==="list"?n.jsx(Ge,{flush:!0,children:n.jsxs(rt,{children:[Ie.map(G=>n.jsx(et,{href:G.route,onClick:()=>t(G.route),lead:n.jsx(on,{agents:s,id:G.agentId,size:"sm"}),title:"Asked you a question",sub:`${I(G.agentId)} · waiting for your answer`,side:Le(G.at)},G.agentId)),q==="list"?Y.map(G=>n.jsx(et,{href:G.link??void 0,onClick:()=>X(G),lead:G.agentId?n.jsx(on,{agents:s,id:G.agentId,size:"sm"}):void 0,title:fc(G),sub:G.action?`${Q(G)} · ${G.action}`:Q(G),side:G.state==="held"?"today":Le(G.createdAt)},G.id)):null]})}):null,D.length>0&&q==="deck"?n.jsx(X7,{rows:Y,agents:s,label:Q,onOpen:X,onDone:F}):null,$>0?n.jsx(V,{tone:"critical",children:n.jsxs("a",{href:`${jt}/jobs?state=failed`,onClick:L(`${jt}/jobs?state=failed`),children:[$," failed job",$===1?"":"s",". See why, then retry or dismiss ",$===1?"it":"them","."]})}):null,O>0?n.jsx(V,{tone:"accent",children:n.jsxs("a",{href:Pe("proposals"),onClick:L(Pe("proposals")),children:[O," proposal",O===1?"":"s"," from your agents to keep or discard."]})}):null,Fe.map(G=>n.jsx(V,{tone:"accent",action:n.jsx(Qa,{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)),M.map(G=>n.jsx(Ge,{children:n.jsx(tw,{plugin:G.plugin,agent:G.agent,text:G.text,label:`Create @${G.handle}`,handle:G.handle,onDismiss:()=>{A.dismissAgentOffer(G.plugin,G.agent).then(()=>b.reload())}})},`${G.plugin}/${G.agent}`)),U?n.jsx(V,{tone:"warning",children:n.jsxs("p",{children:[iR," ",n.jsx("a",{href:zg,onClick:L(zg),children:"Open the checklist."})]})}):null]})})}):null,n.jsx(rK,{widgets:Se,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:ft,onClick:L(ft),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=df(i.get(G.id));return n.jsxs("a",{className:"home-face",...Hc(Wc(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(kn,{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?Us(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(L7,{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:`${ft}?tab=offers`,onClick:L(`${ft}?tab=offers`),children:[Je," more"]}):null,n.jsx(k$,{ids:ge.map(G=>G.id),onDone:()=>g.reload()})]}),children:n.jsx("div",{className:"home-offers",children:$e.map(G=>n.jsx(oG,{offer:G,agents:s,open:L(St(G.agentId,"offers")),onDismissed:()=>g.reload()},G.id))})}):null,n.jsx(xH,{}),(xt=(Xe=v.data)==null?void 0:Xe.digest)!=null&&xt.latest&&rG(v.data.digest.latest,T==null?void 0:T.now,ee.is)?n.jsx(fG,{digest:v.data.digest.latest,go:L,onClose:()=>ee.close(oR,v.data.digest.latest.at)}):null,n.jsxs("div",{className:"home-columns",children:[n.jsx(ue,{title:"Coming up",aside:n.jsx("a",{href:`${ft}?tab=missions`,onClick:L(`${ft}?tab=missions`),children:"All missions"}),children:n.jsx(Ge,{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(on,{agents:s,id:G.agentId,size:"sm"}),title:G.title,sub:`${G.kind} for ${I(G.agentId)}`,side:Le(G.at)},G.key))})})}),n.jsx(ue,{title:"Lately",aside:n.jsx("a",{href:jt,onClick:L(jt),children:"All activity"}),children:n.jsx(Ge,{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(on,{agents:s,id:G.agentId,size:"sm"}),title:G.opening?Us(G.opening,80):"Untitled conversation",sub:`${I(G.agentId)}, ${G.messageCount} message${G.messageCount===1?"":"s"}`,side:Le(G.lastMessageAt??G.createdAt)},G.id))})})})]}),((T==null?void 0:T.home)??[]).filter(G=>!ee.is(sN(G.id),rN)).map(G=>n.jsx(vG,{block:G,onHide:()=>ee.close(sN(G.id),rN)},G.id)),T!=null&&T.jobs&&T.missions?n.jsxs("p",{className:"home-foot muted",children:[Xt(T.jobs.pending??0)," queued, ",Xt(T.jobs.leased??0)," running, ",Xt(T.missions.enabled)," of ",Xt(T.missions.total)," missions on."," ",T.paused?n.jsx(we,{tone:"warning",children:"paused"}):n.jsx(we,{tone:"good",children:"running"})," ",n.jsx("a",{href:gc("").replace(/\/conversations\/$/,""),onClick:L(jt),children:"Activity"})," · ",n.jsx("a",{href:Pe("system"),onClick:L(Pe("system")),children:"System"})]}):null]})]})}const eG={approval:"Approval",question:"Question",watcher:"Watcher",reminder:"Reminder",failure:"Failure",recap:"Report",plugin:"Plugin",agent:"Message"};function tG(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 nG(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 oR="digest",sG=3*864e5;function sN(e){return`block:${e}`}const rN="hidden";function rG(e,t,s){if(s(oR,e.at))return!1;const r=Date.parse(e.at),i=t?Date.parse(t):Date.now();return Number.isFinite(r)&&i-r<sG}function iG(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})),A.homeDismiss(l,o).then(t,()=>{r(c=>{const u={...c};return delete u[l],u})})}}}function Qa({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 aG=6,lG=500;function oG({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),A.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:St(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()},lG)},onTouchEnd:u,onTouchMove:u,onTouchCancel:u,children:[n.jsx(on,{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 cG(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:St(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:St(r.agentId,"reminders")});return s.sort((r,i)=>r.at.localeCompare(i.at)).slice(0,5)}function uG(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 dG(e,t,s){const r=uG(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 hG(e,t){try{return vr(e?new Date(e):new Date,t,{weekday:!0})}catch{return nt(e??null,t)}}function fG({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:Le(e.at)}),s?n.jsx(Qa,{label:"Hide until next week",onClick:s}):null]}),children:n.jsx(Ge,{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 mG(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 Ix="home-needs";function pG(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:`${jt}/alerts`}),e.failed>0&&r.push({key:"failed",count:e.failed,label:s(e.failed,"failed job"),tone:"critical",route:`${jt}/jobs?state=failed`}),t&&r.push({key:"paused",count:null,label:"Paused",route:`${jt}/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 gG({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(Ix))==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 vG({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(E,{size:"sm",variant:"ghost","aria-pressed":!i,onClick:()=>r(l=>!l),children:i?"Show":"Hide"}):null,n.jsx(Qa,{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(vf,{children:e.stats.map(l=>n.jsx(ar,{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(Ge,{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 jG=2e3,wG={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 Px(e){return wG[e.phase]??e.detail??e.phase}const yG=new Set(["done","failed","rolled-back"]);function cR(e){return e!==void 0&&(yG.has(e.phase)||!!e.finishedAt)}function bG(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||A.backupJob(e).then(m=>{if(!u){if(t&&(cA({step:Px(m)}),(m.phase==="failed"||m.phase==="rolled-back")&&wl()),c.current){window.location.reload();return}r(m),o(null),cR(m)&&(u=!0)}}).catch(m=>{if(!u){if(m instanceof ve&&m.status!==0&&m.status<500){t&&wl(),o(m.message);return}c.current=!0,t||a(!0)}})};h();const f=window.setInterval(h,jG);return()=>{u=!0,window.clearInterval(f)}},[e,t]),{job:s,away:i,error:l}}function kG({job:e,away:t,error:s}){return s?n.jsx(ie,{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:[Px(e)," ",e.error??""]}):n.jsxs(V,{tone:e.phase==="done"?"good":void 0,role:"status",children:[Px(e),e.copyLate?" The backup was made, but the copy to your folder did not go through.":"",e.error?` ${e.error}`:""]}):null}function NG(){var x,w,y,k,N,S,C;const e=de(()=>A.backups(),[],3e4),t=rR(),s=de(()=>A.service(),[]),[r,i]=d.useState(null),[a,l]=d.useState(!1),o=bG(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=(T,R=!1)=>{f(!0),u(null),l(R),T().then(I=>{var L;R&&I.job&&cf({kind:"restore",patienceMs:oA}),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(()=>{cR(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(R7,{view:t.data,onLeft:t.reload}):null,n.jsx(ie,{message:e.error??c}),n.jsx(kG,{...o}),n.jsx(CG,{onSaved:()=>e.reload()}),n.jsx(ue,{title:"Backups",panel:!0,actions:n.jsx(E,{variant:"accent",size:"sm",disabled:h,onClick:()=>j(()=>A.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($n,{icon:"archive",title:"No backups yet",children:"Make one now, or turn on the nightly backup."}):e.data?n.jsxs(wr,{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(T=>{var R;return n.jsx(EG,{archive:T,busy:h,database:(R=e.data)==null?void 0:R.database,checkout:v,onVerify:()=>j(()=>A.verifyArchive(T.name)),onRestore:(I,L)=>j(()=>A.restoreArchive({name:T.name,...I?{passphrase:I}:{},...L?{confirm:L}:{}}),!0)},T.name)})})]}):n.jsx(pe,{children:"Loading…"})})]})}),n.jsx(AG,{}),n.jsx(TG,{busy:h,checkout:v,checkoutSaid:m,database:(C=e.data)==null?void 0:C.database,onRestore:(T,R,I)=>j(()=>A.restoreUpload(T,{passphrase:R,confirm:I}),!0)})]})}const SG={enabled:!1,time:"03:00",keep:7,encryptLocal:!0,copyTo:null};function CG({onSaved:e}){var p;const t=de(()=>A.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={...SG,...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),A.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(E,{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(ie,{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(Bs,{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 ${Le(h.lastRunAt)}.`:""]}):null]})})]})})}function EG({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:Le(e.createdAt)}),n.jsx("td",{children:Gn(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(E,{size:"sm",disabled:t,onClick:i,children:"Verify"}),n.jsx(E,{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:uR}):n.jsx(dR,{what:`${e.name}, taken ${Le(e.createdAt)}, ${Gn(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 uR="Restoring needs the packaged installation. In a checkout, run: buddi backup restore <file>";function dR({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(E,{variant:"ghost",onClick:c,children:"Cancel"}),n.jsx(E,{variant:"danger",disabled:o||!f||s&&r==="",onClick:u,children:"Restore"})]})]})}function AG(){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),A.backupPassphrase().then(m=>t(m.passphrase)).catch(m=>o(m instanceof ve?m.message:String(m))).finally(()=>a(!1))},f=()=>{a(!0),o(null),A.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(ie,{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(E,{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(E,{variant:"accent",disabled:i||s.trim()==="",onClick:f,children:"Use this one"})})]})})]})})}function TG({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??uR})})}):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(Bs,{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(E,{variant:"accent",disabled:e||!a,onClick:()=>m(!0),children:"Restore"})})]})}),f&&a?n.jsx(ue,{children:n.jsx(dR,{what:`${a.name}, ${Gn(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 hR="gemini-2.5-pro";function Ef(e){return e.replace(/^models\//,"")}const Pw=/(image|tts|audio|live|embedding|vision|robotics|transcribe)/;function fR(e){const t=e.map(Ef);let s;for(const r of t){const i=/^gemini-(\d+(?:\.\d+)*)-pro(?:-(.+))?$/.exec(r);if(!i||Pw.test(i[2]??""))continue;const a=i[1].split(".").map(Number),l=(i[2]??"")!=="";(!s||gh(a,s.version)>0||gh(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 mR(e){let t;for(const s of e.map(Ef)){const r=/^gemini-(\d+(?:\.\d+)*)-flash(?:-(.+))?$/.exec(s);if(!r||/lite/.test(r[2]??"")||Pw.test(r[2]??""))continue;const i=r[1].split(".").map(Number),a=(r[2]??"")!=="";(!t||gh(i,t.version)>0||gh(i,t.version)===0&&t.preview&&!a)&&(t={id:s,version:i,preview:a})}return t==null?void 0:t.id}function pR(e){return/^gemini-[\d.]+-pro(?:-|$)/.test(Ef(e))}function $G(e){return[...new Set(e.map(Ef).filter(t=>t.startsWith("gemini-")&&!Pw.test(t)))]}function gR(e){return e.httpStatus===429||e.state==="rate-limited"||e.state==="quota-exhausted"}function gh(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 xR(e,t){if(!t||e.kind!=="openai-compatible")return!1;const s=r=>r.replace(/\/+$/,"");return s(e.baseUrl)===s(t)}function RG({embedded:e,account:t}={}){const{data:s,error:r,reload:i,loading:a}=de(()=>A.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 T=await S();return f((T==null?void 0:T.warning)??C),i(),!0}catch(T){return u(T instanceof Error?T.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 xR(S,(C=s==null?void 0:s.gemini)==null?void 0:C.baseUrl)?"Gemini":vR(S)};return n.jsxs(Mn,{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(ie,{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(E,{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(qe,{title:"Add an account",onClose:()=>p(!1),children:n.jsx("div",{id:"new-provider-account",children:n.jsx(UG,{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 ${IG(s.vault.kind)}; Postgres holds names and assignments only.`,actions:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",size:"sm",disabled:l||a,onClick:()=>{u(null),f(""),v(!0),i()},children:a?"Refreshing…":"Refresh status"}),n.jsx(E,{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($n,{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(PG,{kind:S.kind,auth:S.auth}),n.jsxs("span",{className:"accounts-row-text",children:[n.jsx("span",{className:"accounts-row-name",children:S.label}),xh(S)?n.jsxs("span",{className:"accounts-row-sub","data-tone":"warning",children:[N(S)," · back at ",Mw(xh(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(wR,{account:S})]},S.id))}),k?n.jsx(FG,{account:k,provider:N(k),anthropicOAuthEnabled:s.anthropicOAuthEnabled,busy:l,run:w},`${k.id}:${k.revision}`):null]})})]})]})}function IG(e){return e==="keychain"?"macOS Keychain":e==="file"?"encrypted file vault":e==="none"?"vault (none configured)":e}function vR(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":Ew(e)?"mlxh":"OpenAI-compatible"}function jR(e){return e.detectedContextWindowSource==="mlxh"?j9(e.detectedContextWindowTokens):e.detectedContextWindowSource!=="provider"?"assumed":e.kind==="codex"?"from ChatGPT":"from the provider"}function PG({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 MG(e){return e==="connected"?"good":["rate-limited","quota-exhausted","provider-unavailable"].includes(e)?"warning":"critical"}function xh(e,t=Date.now()){const s=e.rateLimit;return e.enabled&&e.configured&&s&&Date.parse(s.until)>t?s:null}const DG=()=>Intl.DateTimeFormat().resolvedOptions().timeZone;function Mw(e,t=new Date,s=DG()){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)}`:aj(r,s)}function wR({account:e,long:t}){const s=xh(e);if(s){const a=`Rate-limited until ${Mw(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 OG({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(E,{variant:"ghost",size:"sm",onClick:r,"aria-label":"Copy the id of this account",children:t?"Copied":"Copy"})]})}function LG({account:e,provider:t}){const s=xh(e);if(!s)return null;const r=s.provider??t,i=Mw(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(Et,{size:"sm",href:a.length===1?St(a[0],"setup","brain"):ft,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 Dw(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 FG({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(wR,{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?"":` (${jR(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:St(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:ft,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(OG,{id:e.id})}]}),n.jsx(LG,{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(kR,{account:e,enabled:!!i,busy:s,run:r}),e.kind==="codex"&&n.jsx(yR,{account:e,busy:s,run:r}),e.auth==="device-key"&&n.jsx(bR,{account:e,busy:s,run:r}),n.jsxs(ae,{children:[n.jsx(E,{disabled:s||e.removalPending,onClick:()=>l(!0),children:"Edit account"}),n.jsx(E,{disabled:s||e.removalPending,onClick:()=>void r(()=>A.saveProviderAccount({...Dw(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(E,{disabled:s||!e.enabled||!e.configured,onClick:()=>void r(()=>A.testProviderAccount(e.id),"Connection test finished."),children:"Test connection"}),n.jsx(E,{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:MG(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(qe,{title:`Edit ${e.label}`,onClose:()=>l(!1),children:n.jsx(_G,{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(E,{variant:"danger",disabled:s,onClick:()=>void r(()=>A.removeProviderAccount(e.id,e.revision),"Account removed from Buddi."),children:"Confirm removal"}),n.jsx(E,{disabled:s,onClick:()=>c(!1),children:"Cancel"})]})]}),n.jsx(At,{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 yR({account:e,busy:t,run:s}){var r,i,a;return n.jsxs(n.Fragment,{children:[n.jsxs(ae,{children:[n.jsx(E,{disabled:t||!e.enabled||e.removalPending||((r=e.login)==null?void 0:r.state)==="pending",onClick:()=>void s(()=>A.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(E,{disabled:t,onClick:()=>void s(()=>A.codexAccountAction(e.id,"cancel-login",e.revision),"Sign-in cancelled."),children:"Cancel sign-in"}),n.jsx(E,{disabled:t||!e.configured,onClick:()=>void s(()=>A.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(Tw,{code:e.login.userCode}),e.login.verificationUrl&&n.jsx(ae,{children:n.jsx(Et,{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 _G({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(()=>A.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(Aw,{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:Ew(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} (${jR(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(E,{onClick:r,children:"Cancel"}),n.jsx(E,{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 bR({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,A.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 A.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(E,{disabled:t||!e.enabled||e.removalPending||!!r,onClick:a,children:e.configured?"Reconnect Ollama":"Connect Ollama"}),n.jsx(E,{disabled:t||!l||e.removalPending,onClick:()=>void s(async()=>({warning:(await A.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 kR({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(E,{disabled:s||!t||!e.enabled||e.removalPending||((c=e.login)==null?void 0:c.state)==="pending",onClick:()=>void r(()=>A.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(E,{disabled:s,onClick:()=>{a(""),r(()=>A.anthropicAccountAction(e.id,"cancel-login",e.revision),"Claude sign-in cancelled.")},children:"Cancel sign-in"}),n.jsx(E,{disabled:s||!e.configured||e.removalPending,onClick:()=>{a(""),r(()=>A.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(()=>A.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(E,{type:"submit",variant:"accent",disabled:s||!i.trim(),children:"Complete Claude sign-in"})})]})]})}const lp={anthropic:"claude-sonnet-5",openai:"gpt-5",codex:"gpt-5.5"};function op(e,t,s){return Mx(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 Mx(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 zG="That key was refused. Check it and paste it again.";function UG({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(()=>op("anthropic","api-key",o)),[b,j]=d.useState(!1),[x,w]=d.useState(""),[y,k]=d.useState(""),[N,S]=d.useState(null),[C,T]=d.useState(!1),[R,I]=d.useState(""),[L,_]=d.useState(""),[$,P]=d.useState(!1),[O,M]=d.useState(!1),[D,H]=d.useState(!1),[B,q]=d.useState(void 0),W=(J,ye,ge=!1)=>{f(J),p(ye),k(""),S(null),I(""),_(""),P(!1),M(ge),H(!1),q(void 0),w(ge?"":J==="openai-compatible"?"http://localhost:11434/v1":""),b||v(ge?op(J,"device-key",o):op(J,ye,o))},Y=J=>{W("openai-compatible",J?"api-key":"device-key",!0),J&&A.ollama().then(ye=>w(ye.cloudBaseUrl)).catch(()=>{})},F=()=>{l&&(W("openai-compatible","api-key"),H(!0),w(l.baseUrl),b||v(Mx("Gemini",o)))},X=()=>{W("openai-compatible","none"),q(null),b||v(Mx("mlxh",o)),A.mlxh().then(J=>{q(J),w(J.baseUrl)}).catch(()=>q(void 0))},Q=B!==void 0,ee=c?e.find(J=>J.id===c):void 0;if(c)return ee?n.jsx(BG,{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",Oe=h==="codex"||m==="anthropic-oauth"||m==="device-key",Ie=!Oe&&(m==="none"||y.trim()!=="")&&(!fe||x.trim()!==""),Fe=async()=>{var J,ye;T(!0),I("");try{const ge=await A.probeModels({kind:h,auth:m,...fe?{baseUrl:x}:{},...y.trim()?{secret:y}:{}});S(ge),L||_(((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{T(!1)}},U=L.trim(),se=!g.trim()||fe&&!x.trim()||fe&&!D&&!Q&&!U||D&&!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?Tx(B)??((De=B==null?void 0:B.models[0])==null?void 0:De.id):void 0)||(m==="device-key"?cd:lp[h])||"claude-sonnet-5",$e;(async()=>{if(D){ge=hR;try{const at=(await A.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:x,secret:ye})).models.map(Ye=>Ye.id);ge=fR(at)??ge,$e=pR(ge)?mR(at):void 0}catch{}}let Je,ze=!1;!await s(async()=>{if(Je=await A.saveProviderAccount({label:g,kind:h,auth:m,baseUrl:x,defaultModel:ge,enabled:!0,...ye.trim()?{secret:ye}:{}}),m!=="api-key")return Je;const Ue=await A.testProviderAccount(Je.id);if(Ue.state==="connected")return Je;if(cj(Ue)){const at=Je.id;Je=void 0;try{const Ye=(await A.providerAccounts()).accounts.find(kt=>kt.id===at);Ye&&await A.removeProviderAccount(at,Ye.revision)}catch{}throw new Error(zG)}if(D&&$e&&gR(Ue)){const at=(await A.providerAccounts()).accounts.find(Ye=>Ye.id===Je.id);if(at&&(await A.saveProviderAccount({...Dw(at),defaultModel:$e}),(await A.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 ze=!0,{...Je,warning:`Account saved. ${Ue.message}`}},"Account saved.")||!Je||(D||Q||ze?u(Je.id):U||!Oe?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":O?"ollama-cloud":D?"gemini":Q?"mlxh":h,onChange:J=>{if(J.target.value==="anthropic-oauth")W("anthropic","anthropic-oauth");else if(J.target.value==="gemini")F();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"})}),O&&n.jsxs("label",{className:"ui-row",children:[n.jsx("input",{type:"checkbox",checked:m==="api-key",onChange:J=>Y(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)}})}),!D&&!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 ",Tx(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(", "),": ",W$,"."]}):null]}):n.jsx(V,{tone:"warning",children:B$((B==null?void 0:B.baseUrl)??x)}):D&&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."]}):Oe?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:$?"__custom__":L,onChange:J=>{J.target.value==="__custom__"?(P(!0),_("")):(P(!1),_(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(E,{size:"sm",disabled:C||!Ie,onClick:()=>void Fe(),children:C?"Loading…":"Reload"})]}):n.jsxs("div",{className:"ui-row",children:[n.jsx(E,{disabled:C||!Ie,onClick:()=>void Fe(),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: ",lp[h]," is used until you pick one."]})]}),$||fe&&!N?n.jsx("input",{"aria-label":"Custom model",required:fe,maxLength:150,value:L,onChange:J=>_(J.target.value),placeholder:fe?"qwen3:8b":lp[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(E,{onClick:()=>r(),children:"Cancel"}),n.jsx(E,{type:"submit",variant:"accent",disabled:se,children:"Save account"})]})]}),se&&!Q&&n.jsxs("p",{className:"muted",children:["Enter an account name",D?" and a key":fe?", an endpoint and a model":""," to enable Save account."]})]})}function BG({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(kR,{account:e,enabled:!!r,busy:t,run:s}):null,e.kind==="codex"&&!o?n.jsx(yR,{account:e,busy:t,run:s}):null,e.auth==="device-key"&&!o?n.jsx(bR,{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(Aw,{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(E,{onClick:i,children:"Skip for now"}),n.jsx(E,{variant:"accent",disabled:t||!a.trim(),onClick:()=>{if(a===e.defaultModel){i();return}s(()=>A.saveProviderAccount({...Dw(e),defaultModel:a}),"Default model saved.").then(c=>{c&&i()})},children:"Done"})]})]}):n.jsx(ae,{children:n.jsx(E,{onClick:i,children:"Finish later"})})]})}const iN=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 WG(e){const t=e.toLowerCase().replace(/\.$/,"");if(!t.includes(".")||iN.has(t))return!0;const s=t.slice(t.indexOf(".")+1);return iN.has(`*.${s}`)}function HG(e){return typeof e=="string"&&e.includes("*")}function KG(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"}:WG(a)?{ok:!1,reason:"public-suffix"}:{ok:!0,value:{pattern:`${i.protocol}//*.${i.host}`,protocol:i.protocol,suffix:a,port:i.port}}}const aN=["every-time","first-time","pre-approved"];function NR(e){const t=aN.indexOf(e);return aN.slice(0,t<0?1:t+1)}function ka(e){return e.endsWith(".account")}const VG="Stored, not usable until it has a binding.";function GG(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==="developer.env"?"the workspace, then the variable name — e.g. cour des comptes ADMIN_PASSWORD":ka(e)?"the account id, e.g. acct-1":'the place, as JSON — e.g. {"host":"localhost","header":"Authorization"}'}const SR={"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})},"developer.env":{hint:"a workspace, then the variable name",build:(e,t)=>({workspace:e,variable:t})}},YG="A wildcard may only stand for the leftmost part of a site, like *.wikimedia.org.",qG=e=>`That is a public suffix; ${e} would match every site.`,lN="Give the site as an origin, like https://en.wikipedia.org.";function oN(e){const t=/^[a-z][a-z0-9+.-]*:\/\//i.test(e)?e:["https:","//",e].join("");if(HG(e)){const s=KG(t);if(s.ok)return{ok:!0,target:s.value.pattern};if(s.reason==="placement")return{ok:!1,error:YG};if(s.reason==="public-suffix"){const r=t.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/[/?#:].*$/,"").toLowerCase();return{ok:!1,error:qG(r)}}return{ok:!1,error:lN}}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:lN}}}function JG(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 QG(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 oN(s);if(e==="browser.native.type"||ka(e))return{ok:!0,target:s};const r=SR[e];if(r===void 0)return{ok:!0,target:s};const i=JG(s);if(i===null)return{ok:!1,error:`${e} needs both: ${r.hint}.`};if(e==="browser.form.data"){const a=oN(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 XG(e){if(typeof e=="string")return e;try{return JSON.stringify(e)??""}catch{return""}}function CR(e,t){if(typeof t=="string")return t;if(t!==null&&typeof t=="object"&&!Array.isArray(t)){const s=t,r=SR[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 ql="accounts.provider";function ER(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 AR(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 ZG(e){const t=ER(e,"found");return t.length?`The value already sits in ${AR(t)}.`:""}function eY(e){const t=ER(e,"scrubbed");return t.length?`Replaced with ‹secret:…› in ${AR(t)}.`:""}const tY=/^(PROVIDER_ACCOUNT_|CODEX_ACCOUNT_|ANTHROPIC_ACCOUNT_|OLLAMA_DEVICE_)/,nY=/^MCP_(TOKEN|ENV|CONNECTION)_/,TR="GMAIL_APP_PASSWORD";function Jr(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===TR)return"mail";if(t.some(r=>r.kind==="model-account")||s.includes(ql)||tY.test(e.name))return"models";if(t.some(r=>r.kind==="connection")||s.includes("mcp.env")||nY.test(e.name))return"connections";for(const r of e.bindings){if(r.kind==="http.url"&&Ow(r.target)&&typeof r.target.plugin=="string")return`plugin:${r.target.plugin}`;if(ka(r.kind))return`plugin:${r.kind.slice(0,-8)}`}return"mine"}function sY(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",aside:"Private links, fetched only by the calendar plugin."}:{title:t.charAt(0).toUpperCase()+t.slice(1),aside:`Kept for the ${t} plugin.`}}function rY(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 $R(e){return e==="models"||e==="connections"}function Ow(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function cN(e){const t=e.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/\/.*$/,"").replace(/^www\./,"");return t.startsWith("*.")?`any ${t.slice(2)} site`:t}const Lw=e=>(e.usedBy??[]).flatMap(t=>t.kind==="mailbox"?[t]:[]),Af=e=>(e.usedBy??[]).find(t=>t.kind==="model-account"),Fw=e=>(e.usedBy??[]).find(t=>t.kind==="connection");function zo(e,t=new Map){var r,i;const s=Jr(e);if(s==="mail"){const a=Lw(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=Af(e),l=(a==null?void 0:a.id)??((r=e.bindings.find(c=>c.kind===ql&&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=Fw(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 iY(e,t){var r,i,a;if(Jr(e)!=="models")return null;const s=((r=Af(e))==null?void 0:r.id)??((i=e.bindings.find(l=>l.kind===ql&&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 RR(e,t){const s=Ow(t)?t:{},r=i=>typeof s[i]=="string"?s[i]:"";return e==="browser.field"&&typeof t=="string"?`Filled on ${cN(t)}`:e==="browser.form.data"&&r("origin")?`Filled into “${r("field")}” on ${cN(r("origin"))}`:e==="browser.native.type"&&typeof t=="string"?`Typed into the app ${t}`:(e==="http.header"||e==="http.url")&&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===ql?"Used by a model account":ka(e)?`Used by a ${e.slice(0,-8)} account`:`Goes to ${CR(e,t)}`}function aY(e,t){return ka(e)||e===ql?"Signed in":RR(e,t).replace(/^Sent only to/,"Sent to")}const lY={"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 oY(e){return e.length<=1?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function _w(e){const t=Jr(e);if(t==="mail"){const a=Lw(e).map(l=>l.address);return a.length?`Used by the ${a.length===1?"mailbox":"mailboxes"} ${oY(a)}`:e.name===TR?"From the old .env setup":"No mailbox uses it"}if(t==="models"){const a=Af(e);return a?lY[a.auth]??"Key for this model account":"No model account uses it"}if(t==="connections"){const a=Fw(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&&Ow(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=>RR(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 cY(e,t=Date.now()){return e.lastUse?`Last used ${Le(e.lastUse.at,t)}`:"Never used"}function Dx(e){return Vr("email","settings",{account:e,set:"password"})}function IR(e){var s,r;const t=Jr(e);if(t==="models"){const i=(s=Af(e))==null?void 0:s.id;return{label:"Managed in Model accounts",href:i?nA(i):Pe("accounts")}}if(t==="connections"){const i=(r=Fw(e))==null?void 0:r.id;return{label:"Managed in Connections",href:i?sA(i):Pe("connections")}}return null}function PR(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 MR(e,t=Date.now()){if(e.unused)return null;const s=Jr(e),r=Lw(e)[0],i=IR(e),a=()=>r?{label:"Set password",href:Dx(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?Le(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 ${Le(r.loginFailedAt,t)}.`,fix:{label:"Set password",href:Dx(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"?PR(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}: ${OR(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:jl}}: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 DR(e){if(!e.unused)return"";const t=Jr(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 Ox(e){return e.usageUnknown&&!e.unused?"Couldn’t check what uses it just now.":""}function Xa(e){return!!e.unused&&!$R(Jr(e))}function uY(e){if(e.unused||e.bindings.length===0)return"Nothing uses it, so nothing stops working.";const t=_w(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 dY={"every-time":"Every time","first-time":"The first time, then not again","pre-approved":"Never — allowed ahead of time"};function hY(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","developer.env":"A workspace variable","mcp.env":"A program’s variable",[ql]:"A model account"};return t[e]?t[e]:ka(e)?`A ${e.slice(0,-8)} account`:e}const fY={"every-time":"Every time","first-time":"The first time","pre-approved":"Never"};function OR(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)?PR(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 mY(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==="developer.env"?"my-app ADMIN_PASSWORD":ka(e)?"acct-1":'{"host":"localhost","header":"Authorization"}'}function vh(e){return NR(e).includes("first-time")?"first-time":e}function pY(e){const t=aY(e.kind,e.target);return e.outcome==="refused"?{text:`Held back — ${OR(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 fa(e,t,s,r){s(!0),r(null);try{return(await A.secretsAct(e,t)).result}catch(i){return r(i instanceof Error?i.message:String(i)),null}finally{s(!1)}}const LR="Passwords, keys and links your agents use without ever seeing them. Each goes only where you allow.";function gY(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 xY({embedded:e,timezone:t,secret:s,adding:r,navigate:i}={}){const a=de(()=>A.secrets(),[]),l=de(()=>A.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:vR(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=Jr(v);g.set(b,[...g.get(b)??[],v])}return[...g.entries()].sort(([v],[b])=>rY(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(Mn,{embedded:e,title:"Keys and secrets",lede:LR,actions:e?void 0:n.jsx(E,{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(ie,{message:a.error}),n.jsx(ae,{children:n.jsx(E,{onClick:a.reload,children:"Retry"})})]}):null,f&&f.secrets.length===0?n.jsx(Ge,{children:n.jsx($n,{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(Ge,{flush:!0,children:m.map(([g,v])=>{const b=sY(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(jY,{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(At,{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(bY,{destinations:f.destinations,onClose:h,onChanged:a.reload}):null,p&&(c==null?void 0:c.what)==="sheet"?n.jsx(wY,{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(kY,{secret:p,title:zo(p,o),onClose:h,onChanged:a.reload}):null,p&&(c==null?void 0:c.what)==="rename"?n.jsx(NY,{secret:p,onClose:h,onChanged:a.reload}):null,p&&(c==null?void 0:c.what)==="places"&&f?n.jsx(SY,{secret:p,title:zo(p,o),destinations:f.destinations,onClose:h,onChanged:a.reload}):null,p&&(c==null?void 0:c.what)==="delete"?n.jsx(CY,{secret:p,title:zo(p,o),onClose:h,onChanged:a.reload}):null]})}const jh=e=>t=>{t.stopPropagation(),e==null||e()};function FR({fix:e,onOpen:t}){return"href"in e?n.jsx(Et,{size:"sm",href:e.href,onClick:jh(),children:e.label}):n.jsx(E,{size:"sm",onClick:jh(()=>t(e.action)),children:e.label})}function vY(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=Dx(r.id)}}:null,{label:"Usage history",onSelect:()=>s("sheet")},Xa(e)?"separator":null,Xa(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")},Xa(e)?"separator":null,Xa(e)?{label:"Remove…",tone:"critical",onSelect:()=>s("delete")}:null]}function jY({secret:e,group:t,accounts:s,onOpen:r}){const i=zo(e,s),a=iY(e,s),l=[_w(e),cY(e)].filter(Boolean).join(" · "),o=MR(e),c=DR(e),u=Ox(e),h=$R(t)?IR(e):null;return n.jsx(et,{onClick:()=>r("sheet"),label:`${i}: details`,lead:n.jsx(Rn,{icon:gY(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(FR,{fix:o.fix,onOpen:r}):null,c&&Xa(e)?n.jsx(E,{size:"sm",variant:"ghost",onClick:jh(()=>r("delete")),children:"Remove…"}):null,h?n.jsxs("a",{className:"secrets-managed",href:h.href,onClick:jh(),children:[h.label,n.jsx(ce,{name:"chevron-right",size:12})]}):n.jsx(Di,{label:`More for ${i}`,items:vY(e,t,r),sheet:{title:i,sub:l}})]})})}function wY({secret:e,accounts:t,timezone:s,onClose:r,onOpen:i}){const a=Jr(e),l=zo(e,t),o=MR(e),c=DR(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(qe,{title:l,onClose:r,foot:a==="mine"?n.jsxs(ae,{children:[n.jsx(E,{variant:"danger-ghost",onClick:()=>i("delete"),children:"Delete…"}),n.jsx(dt,{}),n.jsx(E,{onClick:()=>i("rename"),children:"Rename…"}),n.jsx(E,{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:_w(e)||"Nowhere yet"},...u.length===1&&a==="mine"?[{label:"Asks you",value:dY[u[0]]}]:[],{label:"Last used",value:h?`${Le(h.at)}${h.agentId?` by ${h.agentId}`:""}`:"Never"}]}),o?n.jsx(V,{tone:"warning",action:o.fix?n.jsx(FR,{fix:o.fix,onOpen:i}):void 0,children:o.text}):null,c?Xa(e)?n.jsxs(V,{action:n.jsx(E,{size:"sm",onClick:()=>i("delete"),children:"Remove…"}),children:[c," Nothing removes it but you."]}):n.jsx(V,{children:c}):null,Ox(e)?n.jsx(V,{children:Ox(e)}):null,n.jsxs(le,{gap:"sm",children:[n.jsx("h3",{className:"secrets-sheet-head",children:"Usage history"}),n.jsx(yY,{name:e.name,timezone:s})]}),n.jsx(At,{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," ",CR(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 yY({name:e,timezone:t}){const s=de(()=>A.secretUses(e,50),[e]);if(s.error)return n.jsx(ie,{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=pY(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 _R({title:e,result:t,scrubbed:s,busy:r,failure:i,onScrub:a}){const l=ZG(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(ie,{message:i}),l?n.jsx(ae,{children:n.jsx(E,{variant:"accent",disabled:r||s!==null,onClick:a,children:s===null?"Scrub the history":eY(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?vh(m):a.rule})},children:u.map(h=>n.jsx("option",{value:h.kind,children:hY(h.kind)},h.kind))})}),n.jsx(oe,{label:"The place",children:n.jsx("input",{type:"text",spellCheck:!1,disabled:s,value:a.target,placeholder:mY(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:NR(c).map(h=>n.jsx("option",{value:h,children:fY[h]},h))})}),n.jsx(E,{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: ",GG(a.kind),"."]})]},l)}),t.length===0?n.jsx("p",{className:"ui-field-hint",children:VG}):null,e.length?n.jsx(ae,{children:n.jsx(E,{size:"sm",disabled:s,onClick:()=>r([...t,{kind:e[0].kind,target:"",rule:vh(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 UR(e){const t=e.map(r=>QG(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 bY({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:vh(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=UR(u);if(!k.ok){g(k.error);return}const N=a;l("");const S=await fa("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 fa("secrets.scrub_history",{name:(v==null?void 0:v.name)??""},m,g);k!==null&&(x(k),s())};return v?n.jsx(qe,{title:"Add a secret",onClose:t,foot:n.jsx(ae,{align:"end",children:n.jsx(E,{onClick:t,children:"Done"})}),children:n.jsx(_R,{title:v.name,result:v.result,scrubbed:j,busy:f,failure:p,onScrub:()=>void y()})}):n.jsx(qe,{title:"Add a secret",size:"wide",onClose:t,foot:n.jsxs(ae,{align:"end",children:[n.jsx(E,{onClick:t,children:"Cancel"}),n.jsx(E,{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 kY({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 fa("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 fa("secrets.scrub_history",{name:e.name},o,u);b!==null&&(p(b),r())};return h?n.jsx(Lt,{title:`Replaced the value of “${t}”`,onClose:s,foot:n.jsx(E,{variant:"accent",onClick:s,children:"Done"}),children:n.jsx(_R,{title:t,result:h,scrubbed:m,busy:l,failure:c,onScrub:()=>void v()})}):n.jsx(Lt,{title:`Replace the value of “${t}”`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(E,{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(ie,{message:c})]})})}function NY({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 fa("secrets.rename",{name:e.name,to:r.trim()},l,c)!==null&&(s(),t())};return n.jsx(Lt,{title:`Rename “${e.name}”`,onClose:t,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(E,{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(ie,{message:o})]})})}function SY({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:XG(m.target),rule:m.rule})):s.length?[{kind:s[0].kind,target:"",rule:vh(s[0].maxRule)}]:[]),[o,c]=d.useState(!1),[u,h]=d.useState(null),f=async()=>{const m=UR(a);if(!m.ok){h(m.error);return}await fa("secrets.rebind",{name:e.name,bindings:m.bindings},c,h)!==null&&(i(),r())};return n.jsx(qe,{title:`Where “${t}” may go`,size:"wide",onClose:r,foot:n.jsxs(ae,{align:"end",children:[n.jsx(E,{onClick:r,children:"Cancel"}),n.jsx(E,{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 CY({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 fa("secrets.delete",{name:e.name},a,o)!==null&&(r(),s())};return n.jsxs(Lt,{title:`${c?"Remove":"Delete"} “${t}”?`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(E,{variant:"danger",disabled:i,onClick:()=>void u(),children:c?"Remove":"Delete"})]}),children:[n.jsxs("p",{className:"secrets-dialog-text",children:[uY(e)," The value is gone for good; its usage history stays, under its name."]}),n.jsx(ie,{message:l})]})}function EY({timezone:e,embedded:t}){var p;const{data:s,error:r,reload:i}=de(()=>A.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),A.setSentinelEnabled(g,v).catch(b=>c(b instanceof ve?b.message:String(b))).finally(()=>{l(null),i()})};return n.jsxs(Mn,{embedded:t,title:"Watchers",children:[n.jsx(ie,{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:`${jt}/alerts`,children:"See what they found"}),panel:!0,flush:!0,children:s?u.length===0?n.jsx($n,{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 ${AY(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?Le(v.lastRunAt):"never ran"}),n.jsx(E,{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(rV,{mutes:((p=s==null?void 0:s.alerts)==null?void 0:p.mutes)??[],onChanged:i})]})}function AY(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 uN=4,TY={time:"profile",date:"profile",zone:null};function $Y({data:e,phone:t}){const s=d.useRef(null),r=e$(),[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":fw(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(u$,{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 RY({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(Yt,{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 dN(e){return e?"place"in e?`place:${e.place}`:`town:${e.timezone}:${e.label}`:""}function IY({clock:e,onClock:t,version:s}){var q,W,Y;const r=e??TY,i=de(()=>A.lockScreen(),[s]),a=de(()=>A.widgets("lock"),[]),l=de(()=>A.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=((q=i.data)==null?void 0:q.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,y=(o==null?void 0:o.lock)??[],k=new Map(((o==null?void 0:o.available)??[]).map(F=>[F.id,F])),N=y.length>=uN,S=F=>{if(!o)return Promise.resolve(!1);const X=o;return m(null),c({...o,lock:F,arranged:{...o.arranged,lock:!0}}),A.saveWidgets("lock",F).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=(F,X)=>{const Q=y.slice(),[ee]=Q.splice(F,1);Q.splice(F+X,0,ee),S(Q)},T=(F,X)=>{const Q=k.get(F);!Q||N||S([...y,{key:a$(),widget:F,size:Q.sizes.includes("small")?"small":Q.sizes[0],settings:X}])},R=F=>{if(F==="find"){b({query:"",found:[],busy:!1});return}if(b(null),F==="")return t({...r,zone:null});if(F.startsWith("place:"))return t({...r,zone:{place:F.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 F=v.query.trim();b({query:v.query,found:[],busy:!0}),A.findPlace(F).then(({found:X})=>{var Oe;const Q=X.filter(Ie=>Ie.timezone);if(Q.length===0){b({query:F,found:[],busy:!1,missed:`Nothing with a timezone found for “${F}”.`});return}const ee=Q[0],fe={label:((Oe=ee.name.split(",")[0])==null?void 0:Oe.trim())||ee.name,timezone:ee.timezone};x(fe),b(null),t({...r,zone:fe})}).catch(()=>b({query:F,found:[],busy:!1,missed:"The place finder didn’t answer. Try again in a moment."}))},L=new Date,_=F=>Dc({dateFormat:F},()=>vr(L,w,{weekday:!0})),$=(((W=l.data)==null?void 0:W.places)??[]).filter(F=>F.timezone&&F.timezone!==w),P=r.zone&&!("place"in r.zone)?r.zone:j,O=((o==null?void 0:o.home)??[]).filter(F=>k.has(F.widget)&&!k.get(F.widget).sensitive),M=((o==null?void 0:o.available)??[]).filter(F=>!F.sensitive),D=((o==null?void 0:o.available)??[]).filter(F=>F.sensitive).map(F=>F.title),H=p?y.find(F=>F.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($Y,{data:i.data,phone:u}),n.jsxs("div",{className:"lke-look-foot",children:[n.jsx(Yt,{label:"Preview on",options:[{value:"desk",label:"Desk"},{value:"phone",label:"Phone"}],value:u?"phone":"desk",onChange:F=>h(F==="phone")}),n.jsxs("span",{className:"lke-look-note",children:["As it shows now",(Y=i.data)!=null&&Y.focus?", with your focus on":"","."]})]})]}),n.jsxs("div",{className:"lke-controls",children:[n.jsx(ie,{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(Yt,{label:"Time",options:[{value:"profile",label:Z1()},{value:"12h",label:"12-hour"},{value:"24h",label:"24-hour"}],value:r.time,onChange:F=>t({...r,time:F})})]}),n.jsx(oe,{label:"Date",children:n.jsxs("select",{value:r.date,onChange:F=>t({...r,date:F.target.value}),children:[n.jsxs("option",{value:"profile",children:["Profile · ",_(null)]}),n.jsx("option",{value:"short",children:_("short")}),n.jsx("option",{value:"long",children:_("long")}),n.jsx("option",{value:"iso",children:_("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":dN(r.zone),onChange:F=>R(F.target.value),children:[n.jsx("option",{value:"",children:"None"}),$.map(F=>n.jsxs("option",{value:`place:${F.id}`,children:[F.label," — ",F.name.split(",")[0]]},F.id)),r.zone&&"place"in r.zone&&!$.some(F=>F.id===r.zone.place)?n.jsx("option",{value:dN(r.zone),children:"A place no longer in another zone"}):null,P?n.jsx("option",{value:`town:${P.timezone}:${P.label}`,children:P.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:F=>b({...v,query:F.target.value}),onKeyDown:F=>{F.key==="Enter"&&(F.preventDefault(),I()),F.key==="Escape"&&b(null)}}),n.jsx(E,{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 ",uN]})]}),N||!o?n.jsxs(E,{size:"sm",disabled:!0,children:[n.jsx(ce,{name:"plus",size:12})," Add a widget"]}):n.jsx(Di,{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:[O.length>0?{heading:"As on Home"}:null,...O.map(F=>({label:F.label??k.get(F.widget).title,hint:"same settings",onSelect:()=>T(F.widget,F.settings)})),O.length>0?"separator":null,{heading:"Every widget"},...M.map(F=>({label:F.title,onSelect:()=>T(F.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((F,X)=>{const Q=k.get(F.widget);return Q?n.jsx(RY,{info:Q,placement:F,index:X,count:y.length,onSize:ee=>void S(y.map(fe=>fe.key===F.key?{...fe,size:ee}:fe)),onSettings:()=>g(F.key),onMove:ee=>C(X,ee),onRemove:()=>void S(y.filter(ee=>ee.key!==F.key))},F.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.",D.length>0?` A sensitive widget — ${D.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(s$,{info:B,placement:H,surface:"lock",onClose:()=>g(null),onSave:F=>S(y.map(X=>X.key===H.key?{...X,settings:F}:X)).then(X=>(X&&g(null),X)),onRemove:()=>{g(null),S(y.filter(F=>F.key!==H.key))}}):null]})}const PY=[{id:"earth",label:"Earth"},{id:"field",label:"Buddi"},{id:"dawn",label:"Dawn"},{id:"sea",label:"Sea"},{id:"moss",label:"Moss"},{id:"dusk",label:"Dusk"}],MY=[{value:"1",label:"1 min"},{value:"5",label:"5 min"},{value:"15",label:"15 min"},{value:"60",label:"1 hour"},{value:"never",label:"Never"}],DY=e=>e.delayMinutes===null?"never":String(e.delayMinutes);function Lx(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 OY({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?A.removePin(r):A.setPin(a,g?r:void 0)).then(s).catch(N=>{m(!1),h(Lx(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(Lt,{title:j,onClose:t,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(E,{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 LY(e){const t=Nf(),s=de(()=>A.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(Lx(j)))},p=b=>{b&&(c(!0),l(null),A.uploadLockBackground(b).then(f).catch(j=>l(Lx(j))).finally(()=>{c(!1),u.current&&(u.current.value="")}))};if(!h)return n.jsx(ue,{title:"Lock screen",panel:!0,children:n.jsx(ie,{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(A.setLockSettings({background:b})),children:[b==="image"&&h.image?n.jsx("img",{src:h.image,alt:""}):b==="earth"?n.jsx("img",{src:bx.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(E,{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(ie,{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(E,{size:"sm",variant:"ghost",onClick:()=>i("remove"),children:"Remove…"}),n.jsx(E,{size:"sm",onClick:()=>i("change"),children:"Change…"})]}):n.jsx(E,{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(Yt,{label:"Lock after",options:MY,value:g?DY(h):"",onChange:b=>{g&&m(A.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:[PY.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:Ym.authorUrl,target:"_blank",rel:"noreferrer",children:Ym.author})," on ",n.jsx("a",{href:Ym.photoUrl,target:"_blank",rel:"noreferrer",children:"Unsplash"})]}),h.image?n.jsx(ae,{align:"end",children:n.jsx(E,{size:"sm",variant:"ghost",onClick:()=>m(A.removeLockBackground()),children:"Remove picture"})}):null]})]}),r?n.jsx(OY,{kind:r,onClose:()=>i(null),onDone:b=>{i(null),f(b)}}):null]}),n.jsx(IY,{clock:h.clock,onClock:b=>m(A.setLockSettings({clock:b})),version:`${h.background}:${h.image??""}:${JSON.stringify(h.clock??null)}`})]})}const cp=60;function BR(e){return e instanceof ve?e.message:"Something went wrong. Try again."}function FY(e,t,s=Date.now()){const r=`made ${vr(new Date(e.createdAt),t,{compact:!0})} ${e.createdVia==="cli"?"in the terminal":"here"}`;return`buddi_…${e.hint} · ${r} · ${e.lastUsedAt?`last used ${Le(e.lastUsedAt,s)}`:"never used"}`}function _Y({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<=cp,p=g=>{g==null||g.preventDefault(),m&&(a(!0),o(null),A.createApiToken(s.trim()).then(v=>{u({token:v.token,name:v.apiToken.name}),t()}).catch(v=>o(BR(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(Lt,{title:`Token for ${c.name}`,onClose:e,foot:n.jsx(E,{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(E,{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(Lt,{title:"Make a token",onClose:e,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:e,children:"Cancel"}),n.jsx(E,{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 ${cp} characters.`,children:n.jsx("input",{autoFocus:!0,value:s,maxLength:cp,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 zY({token:e,onClose:t,onRevoked:s}){const[r,i]=d.useState(!1),[a,l]=d.useState(null),o=()=>{i(!0),l(null),A.revokeApiToken(e.id).then(()=>{s(),t()}).catch(c=>{i(!1),l(BR(c))})};return n.jsxs(Lt,{title:`Revoke “${e.name}”?`,onClose:t,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:t,children:"Cancel"}),n.jsx(E,{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 UY({timezone:e}){var o;const t=de(()=>A.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(ie,{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(E,{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(Rn,{icon:"key"}),title:c.name,sub:FY(c,e),side:n.jsx(E,{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(_Y,{onClose:()=>r(!1),onMade:()=>t.reload()}):null,i?n.jsx(zY,{token:i,onClose:()=>a(null),onRevoked:()=>t.reload()}):null]})}function BY({embedded:e}){const{data:t,error:s,reload:r}=de(()=>A.owner(),[]);return n.jsxs(Mn,{embedded:e,title:"You",lede:"What every agent knows about the person it is talking to.",children:[n.jsx(ie,{message:s}),t?n.jsxs(le,{gap:"lg",children:[n.jsx(KY,{initial:t,onSaved:r}),n.jsx(qY,{initial:t})]}):null]})}const WR=new Date(Date.UTC(2026,9,1,14,5));function WY(){return[["",`Auto (${Dc({timeFormat:null},()=>zt(WR,"UTC"))} here)`],["12h","12-hour · 2:05 PM"],["24h","24-hour · 14:05"]]}function HY(){return[["",`Auto (${Dc({dateFormat:null},()=>vr(WR,"UTC",{weekday:!0}))} here)`],["short","Thu, Oct 1"],["long","Thursday, 1 October"],["iso","2026-10-01"]]}function KY({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 A.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()});ij({timeFormat:C.timeFormat??null,dateFormat:C.dateFormat??null}),window.dispatchEvent(new Event(kg)),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=>T=>{j(!1),C(T)};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(E,{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(Bs,{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:WY().map(([C,T])=>n.jsx("option",{value:C,children:T},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:HY().map(([C,T])=>n.jsx("option",{value:C,children:T},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 VY=["Home","Work"];function GY(e){const t=e.trim().toLowerCase();return t==="home"?"home":t==="work"?"briefcase":"pin"}function hN({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:GY(e),size:18})})}function YY(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 qY({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=VY.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(E,{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(hN,{label:u.label}),title:u.label,sub:YY(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(hN,{label:u,empty:!0}),title:n.jsx("span",{className:"muted",children:u}),sub:"Not set",side:n.jsx(E,{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(JY,{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 JY({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),A.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),A.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),A.removePlace(i.id).then(I=>r(I.places)).catch(I=>x(I instanceof ve?I.message:String(I))).finally(()=>b(null)))},T=i?i.label:e.label?`Add ${e.label}`:"Add a place",R=p!==""&&!t.includes(p)?[p,...t]:t;return n.jsx(qe,{title:T,onClose:s,foot:n.jsxs(ae,{children:[i?n.jsx(E,{variant:"danger-ghost",disabled:v!==null,onClick:C,children:v==="remove"?"Removing…":"Remove"}):null,n.jsx(dt,{}),n.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(E,{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(E,{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(ie,{message:j})]})})}const QY=2e6;function fN(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>QY)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 HR={skill:"skill",policy:"rule",change:"change to itself"};function XY(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 Fx(e){return[...new Set(e.split(/[,\n]/).map(t=>t.trim().replace(/^[-*]\s+/,"")).filter(t=>t!==""))]}function ZY(e,t){const s=e.change;if(!s||s.part!=="tools")return[];if(t===e.editable)return s.added;const r=new Set(Fx(s.current??""));return Fx(t).filter(i=>!r.has(i))}function eq(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 tq(e){return"cards"in e}function mN(e,t){return!t||e.kind==="policy"&&e.payload.plugin===t}function nq({embedded:e,plugin:t}){const{data:s,error:r,reload:i}=de(()=>A.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=kT(),v=((s==null?void 0:s.open)??[]).filter(x=>mN(x,t)),b=((s==null?void 0:s.closed)??[]).filter(x=>mN(x,t)),j=x=>n.jsx(lq,{proposal:x,busy:u===x.id,refusal:f[x.id]??null,onKeep:w=>void p(x.id,async()=>{const y=await A.keepProposal(x.id,w);return`${x.title}: ${y.note}`},!0),onDiscard:w=>void p(x.id,async()=>(await A.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(Mn,{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(ie,{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(NT,{offers:g.offers,reload:g.reload}),!s||v.length===0?n.jsx(ue,{title:"Waiting",panel:!0,children:s?t?n.jsx($n,{icon:"bulb",title:`No rule from ${t} is waiting`,children:"It proposes one when you decide the same way several times running."}):n.jsx($n,{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:eq(v).map(x=>tq(x)?n.jsx(sq,{group:x,busy:u===x.key,onKeepAll:()=>void p(x.key,async()=>{const w=await A.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}: ${rq(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:Le(x.decidedAt??x.createdAt)}),n.jsx(E,{size:"sm",variant:"ghost",disabled:u===x.id,onClick:()=>void p(x.id,async()=>{const y=x.skill;return await A.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"})]}):Le(x.decidedAt??x.createdAt)},x.id)})})}):null,!t&&(s!=null&&s.digest)?n.jsx(aq,{schedule:s.digest.schedule,onSaved:i}):null]})}function sq({group:e,busy:t,onKeepAll:s,card:r}){const i=e.cards.length,a=e.cards.some(l=>l.untrusted);return n.jsx(us,{tone:a?"warning":"accent",title:`${e.label} (${i})`,meta:n.jsxs(n.Fragment,{children:[n.jsx(we,{children:HR.policy}),n.jsx(we,{mono:!0,children:e.plugin})]}),foot:n.jsx(ae,{align:"end",children:n.jsxs(E,{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(At,{summary:`Show each of the ${i}`,children:n.jsx(le,{gap:"sm",children:e.cards.map(l=>r(l))})})]})})}function rq(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 iq=Array.from({length:24},(e,t)=>t),pN=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function aq({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 A.setDigestSchedule(s,i),u({tone:"good",text:`The digest now runs on ${pN[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(E,{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: ${Le(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:pN.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:iq.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 gN(e,t){return e==="tools"?Fx(t).join(`
126
- `):t}function lq({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=ZY(e,a);return n.jsx(us,{tone:e.untrusted?"warning":"accent",title:e.title,meta:n.jsxs(n.Fragment,{children:[n.jsx(we,{children:HR[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(E,{variant:"ghost",size:"sm",disabled:t,onClick:()=>i(o.trim()||void 0),children:"Discard"}),n.jsx(E,{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," ",Le(e.createdAt),e.conversationId?n.jsxs(n.Fragment,{children:[" in ",n.jsx("a",{href:gc(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:St(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(Xd,{text:fN(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(Xd,{text:fN(gN(m.part,m.current),gN(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(At,{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:XY(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 oq(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 cq({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),A.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?oq(r):[];return n.jsxs(qe,{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(dt,{}),n.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(E,{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(th,{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(jf,{label:"Find a folder here",value:o,placeholder:"Find a folder here…",onChange:c}),n.jsx(ie,{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(Ge,{flush:!0,children:n.jsx(rt,{children:f.map(p=>n.jsx(et,{onClick:()=>u(p.path),label:`Open ${p.name}`,lead:n.jsx(Rn,{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 uq="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 xN(){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 dq=1500,hq={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."},fq="Restart buddi to apply it. In a checkout, stop it and run: buddi serve",KR=[{value:"npm",label:"From npm"},{value:"file",label:"A file"},{value:"directory",label:"A directory I built"}],VR="buddi.plugins.install-mode";function mq(){try{const e=window.localStorage.getItem(VR);if(KR.some(t=>t.value===e))return e}catch{}return"npm"}function pq(e){try{window.localStorage.setItem(VR,e)}catch{}}const Ku=".tgz",Fr=(e,t,s)=>`${e} ${e===1?t:s}`;function GR(e){const t=[];return e.tools>0&&t.push(Fr(e.tools,"tool","tools")),e.sentinels>0&&t.push(`${e.sentinels} on a timer`),e.views>0&&t.push(Fr(e.views,"view","views")),e.agents>0&&t.push(`${Fr(e.agents,"agent","agents")} proposed`),t.length===0?"nothing on its own":t.join(", ")}function _x(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 YR(e){return e.kind==="registry"?"npm":e.kind==="tarball"?"a file":"a directory"}function zw(e,t){return e.kind==="directory"?"you, from this machine":e.kind==="tarball"?"a file on this machine":t??"nobody npm will name"}function qR(e){return e.author?e.author.name:e.source.kind==="registry"?e.publisher??"nobody npm will name":"you"}function Tf({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 zx({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 JR(e){return e.length===0?"none; nothing leaves this computer":n.jsx("span",{className:"mono",children:e.join(", ")})}function Uw(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 Ei=e=>e instanceof ve?e.message:String(e);function gq(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=()=>{A.pluginJob(e).then(c=>{a||(s(c),(c.phase==="done"||c.phase==="failed")&&(a=!0))}).catch(c=>{a||(i(Ei(c)),a=!0)})};l();const o=window.setInterval(l,dq);return()=>{a=!0,window.clearInterval(o)}},[e]),{job:t,error:r}}function xq({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=fr(a.plugin,a.id);return n.jsx(Et,{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 QR({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 Bw({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 Ux=Pe("plugins"),up={installed:Ux,browse:`${Ux}?tab=browse`};function vq({railPages:e=[],settingsPages:t=[],navigate:s,hash:r=""}={}){const i=de(()=>A.plugins(),[],2e4),[a,l]=d.useState(null),{job:o,error:c}=gq(a),[u,h]=d.useState(null),[f,m]=d.useState(()=>wk(r));d.useEffect(()=>m(wk(r)),[r]);const[p,g]=d.useState(()=>jk(r));d.useEffect(()=>g(jk(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),T=re=>{C(!0),A.market(re).then(N).catch(be=>N({plugins:[],unavailable:Ei(be)})).finally(()=>C(!1))};d.useEffect(()=>{f==="browse"&&k===null&&!S&&T(!1)},[f]);const R=re=>{h(null),l(re)},I=re=>h(Ei(re)),[L,_]=d.useState(!1),$=re=>{_(!0),b(null),re.then(be=>{R(be.job.id),m("installed")}).catch(I).finally(()=>_(!1))},P=d.useRef(null);d.useEffect(()=>{const re=M4(r);if(!(re===null||P.current===re)){P.current=re,m("installed"),$(A.stagePlugin(re));try{window.history.replaceState(window.history.state,"",Ux)}catch{}}},[r]);const O=re=>be=>{be.preventDefault(),m(re),b(null),s==null||s(up[re])};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 M=i.data,D=(M==null?void 0:M.checkout)??!0,H=(M==null?void 0:M.installed)??[],B=re=>k==null?void 0:k.plugins.find(be=>be.installed!==void 0&&(be.installed.name??be.name)===re.name),q=re=>e.some(be=>be.plugin===re),W=(re,be)=>q(re)?n.jsx(xq,{plugin:re,pages:e,navigate:s,variant:be}):void 0,Y=re=>{const be=e.find(Qe=>Qe.plugin===re);be&&s&&s(fr(be.plugin,be.id))},F=re=>{const be=t.find(Qe=>Qe.plugin===re);if(!(!be||!s))return()=>s(Vr(be.plugin,be.id))},X=((k==null?void 0:k.plugins)??[]).filter(re=>re.update).length,Q=(re,be)=>A.setPluginEnabled(re,be).then(Qe=>{M3(),y({name:re,notes:Qe.notes??[]}),i.reload()}),ee=(re,be,Qe)=>A.uninstallPlugin(re,be?{purge:!0,confirm:Qe}:{}).then(ct=>{b(null),y({name:re,notes:ct.notes??[]}),i.reload()}),fe=re=>{h(null),Q(re,!0).catch(I)},Oe=(re,be)=>{const Qe=k==null?void 0:k.plugins.find(yt=>{var ut;return(((ut=yt.installed)==null?void 0:ut.name)??yt.name)===re&&yt.installed!==void 0}),ct=Qe&&be?`${Qe.npm}@${be}`:void 0;$(ct?A.updatePlugin(re,be,ct):A.updatePlugin(re,be))},Ie=re=>{h(null);const be=Qe=>{const ct=Qe.plugins.find(yt=>{var ut;return yt.name===re||((ut=yt.installed)==null?void 0:ut.name)===re});if(!ct){h(`${re} is not listed on withbuddi.com. Add it from npm, a file or a directory above, then install this one.`);return}$(A.stagePlugin(`${ct.npm}@${ct.version}`))};if(k&&k.plugins.length>0)return be(k);_(!0),A.market(!1).then(Qe=>{N(Qe),be(Qe)}).catch(I).finally(()=>_(!1))},Fe=(re,be)=>be===void 0?void 0:be.place==="settings"?Vr(re,be.id):fr(re,be.id),U=re=>{var Qe;if(re.enabled===!1)return;const be=(Qe=re.needs)==null?void 0:Qe[0];if(be)switch(be.state){case"missing":return{label:`Install ${be.plugin}`,run:()=>Ie(be.plugin)};case"disabled":return{label:`Enable ${be.plugin}`,run:()=>fe(be.plugin)};case"range":return{label:`Update ${be.plugin}`,run:()=>Oe(be.plugin)};case"setup":{const ct=Fe(be.plugin,be.page),yt=ct&&s?()=>s(ct):F(be.plugin);return yt?{label:`Set up ${be.plugin}`,run:yt}:void 0}default:return{label:`See ${be.plugin}`,run:()=>b({kind:"installed",name:be.plugin})}}if(re.loaded&&re.setup){const ct=Fe(re.name,re.setup.page),yt=ct&&s?()=>s(ct):F(re.name);return yt?{label:"Set it up",run:yt}:void 0}},se=n.jsxs(Yc,{label:"Plugins",children:[n.jsx(bl,{href:up.installed,active:f==="installed",count:X,onClick:O("installed"),children:"Installed"}),n.jsx(bl,{href:up.browse,active:f==="browse",onClick:O("browse"),children:"Browse"})]}),J=(M==null?void 0:M.staged)??[],ye=Cq(J,(o==null?void 0:o.phase)==="done"?o.stagedId:void 0),ge=J.find(re=>re.id===ye),$e=J.filter(re=>re.id!==ye),De=re=>{b(null),Aq(re),l(null),i.reload()},Je=(v==null?void 0:v.kind)==="staged"?$e.find(re=>re.id===v.name):void 0,ze=(v==null?void 0:v.kind)==="installed"?H.find(re=>re.name===v.name):void 0,Se=(v==null?void 0:v.kind)==="market"?k==null?void 0:k.plugins.find(re=>re.name===v.name):void 0,Ue=w&&!(ze&&ze.name===w.name)&&w.notes.length>0?w.notes:null,at=Je?n.jsx(Nq,{staged:Je,onClose:()=>b(null),onInstalled:De,onInstallFirst:Ie,onGone:()=>{b(null),i.reload()}},Je.id):ze?n.jsx(Dq,{plugin:ze,listing:B(ze),notes:(w==null?void 0:w.name)===ze.name?w.notes:null,canOpen:q(ze.name)&&ze.enabled!==!1,onOpen:()=>Y(ze.name),onClose:()=>b(null),onDisable:()=>x({kind:"disable",name:ze.name}),onEnable:()=>fe(ze.name),onRemove:()=>x({kind:"remove",name:ze.name}),onUpdate:re=>Oe(ze.name,re),onSettings:ze.enabled===!1?void 0:F(ze.name),firstStep:U(ze),busy:L}):Se?n.jsx(Wq,{entry:Se,canOpen:Se.installed!==void 0&&q(Se.installed.name??Se.name),onOpen:()=>{var re;return Y(((re=Se.installed)==null?void 0:re.name)??Se.name)},onClose:()=>b(null),onInstall:()=>$(A.stagePlugin(`${Se.npm}@${Se.version}`)),onUpdate:re=>{var be;return Oe(((be=Se.installed)==null?void 0:be.name)??Se.name,re)},busy:L}):null,Ye=j?H.find(re=>re.name===j.name):void 0,kt=j?n.jsx(Oq,{kind:j.kind,name:j.name,canDisable:(Ye==null?void 0:Ye.enabled)!==!1,onCancel:()=>x(null),onDisableInstead:()=>x({kind:"disable",name:j.name}),onDisable:()=>Q(j.name,!1).then(()=>x(null)),onRemove:(re,be)=>ee(j.name,re,be).then(()=>x(null))},`${j.kind}:${j.name}`):null;if(f==="browse")return n.jsxs(le,{gap:"lg",children:[n.jsx(xN,{}),se,n.jsx(ie,{message:u}),n.jsx(Hq,{kind:p,onKind:g,navigate:s,market:k,loading:S,busy:L,onRetry:()=>T(!0),onOpen:re=>b({kind:"market",name:re.name}),onInstall:re=>$(A.stagePlugin(`${re.npm}@${re.version}`)),onUpdate:(re,be)=>{var Qe;return Oe(((Qe=re.installed)==null?void 0:Qe.name)??re.name,be)}}),at]});const qt=(M==null?void 0:M.builtIn)??[];return n.jsxs(le,{gap:"lg",children:[n.jsx(xN,{}),se,n.jsx(ie,{message:i.error??u??c}),M!=null&&M.unavailable?n.jsx(V,{tone:"warning",children:M.unavailable}):null,Ue?n.jsx(V,{role:"status",children:Ue.join(" ")}):null,n.jsx(jq,{trust:(M==null?void 0:M.trust)??"",job:o,busy:o!==void 0&&o.phase!=="done"&&o.phase!=="failed",onStaged:R,onFailed:h}),ge?n.jsx(bq,{staged:ge,onInstalled:De,onGone:()=>i.reload(),onInstallFirst:Ie},ge.id):null,$e.length>0?n.jsx(Ge,{flush:!0,title:"Waiting for you",tool:Fr($e.length,"package","packages"),children:n.jsx("div",{className:"plugins-rows",children:n.jsx(rt,{children:$e.map(re=>n.jsx(kq,{staged:re,onReview:()=>{ZR(re),b({kind:"staged",name:re.id})},onReject:()=>{h(null),A.rejectStaged(re.id).then(()=>i.reload()).catch(I)}},re.id))})})}):null,M!=null&&M.restartNeeded?n.jsx(Eq,{checkout:D,waiting:H.filter(re=>re.loadsAtRestart)}):null,n.jsx($q,{list:H,firstStepFor:U}),n.jsx(Ge,{flush:!0,title:"Installed",tool:M?Fr(H.length,"plugin","plugins"):void 0,children:M?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(re=>n.jsx(Iq,{plugin:re,listing:B(re),open:re.enabled===!1?void 0:W(re.name,"ghost"),canOpen:q(re.name)&&re.enabled!==!1,busy:L,onDetails:()=>b({kind:"installed",name:re.name}),onOpen:()=>Y(re.name),onSettings:re.enabled===!1?void 0:F(re.name),onDisable:()=>x({kind:"disable",name:re.name}),onEnable:()=>fe(re.name),onRemove:()=>x({kind:"remove",name:re.name}),onUpdate:be=>Oe(re.name,be),firstStep:U(re)},re.name))})}):n.jsx(pe,{children:"Loading…"})}),qt.length>0?n.jsx(Lq,{plugins:qt,openFor:W}):null,at,kt]})}function jq({trust:e,job:t,busy:s,onStaged:r,onFailed:i}){const[a,l]=d.useState(mq),[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(Ei(C)),k=C=>{l(C),pq(C),g(null)},N=()=>{h(!0),A.stagePlugin(o.trim()).then(C=>{r(C.job.id),c("")}).catch(y).finally(()=>h(!1))},S=C=>{if(C){if(!C.name.toLowerCase().endsWith(Ku)){m(null),g(`${C.name} is not a ${Ku}. A packed plugin is the file npm pack writes.`);return}g(null),m(C.name),h(!0),A.uploadPlugin(C).then(T=>r(T.job.id)).catch(y).finally(()=>h(!1))}};return n.jsxs(Ge,{title:"Add a plugin",actions:n.jsx(Yt,{label:"Where it comes from",options:KR,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 T,R;C.preventDefault(),b(!1),S((R=(T=C.dataTransfer)==null?void 0:T.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:Ku})," here: the file ",n.jsx("span",{className:"mono",children:"npm pack"})," ","writes. It is read the moment it lands."]}))}),n.jsx(E,{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:Ku,hidden:!0,"aria-hidden":"true",tabIndex:-1,onChange:C=>{var T;S((T=C.target.files)==null?void 0:T[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(E,{onClick:()=>x(!0),children:"Browse…"}):null,n.jsx(E,{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:[hq[t.phase]," ",t.error??""]}):null,n.jsx("div",{className:"plugins-trust",children:n.jsx(V,{tone:"warning",children:e})})]}),j?n.jsx(cq,{start:o.trim().startsWith("/")?o.trim():void 0,onClose:()=>x(!1),onPick:C=>{c(C),x(!1)}}):null]})}function wq({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?Uw([]):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 XR(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),A.approveStaged(e.id,{integrity:e.integrity??"",...f?{acknowledgeDrift:!0}:{}}).then(m=>{m.installed?t(e.name):m.plan&&i(m.plan)}).catch(m=>c(Ei(m))).finally(()=>l(!1))},reject:()=>{l(!0),c(null),A.rejectStaged(e.id).then(()=>s()).catch(f=>c(Ei(f))).finally(()=>l(!1))}}}function ZR(e){e.openedAt||A.openedStaged(e.id).catch(()=>{})}function yq({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(E,{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 eI({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(Tf,{author:e.author})}]:[],{label:"From",value:e.uploadedName?`a file you chose · ${e.uploadedName}`:_x(e.source)},{label:"Published by",value:zw(e.source,e.publisher)},...e.previousSource&&e.previous?[{label:"Replaces",value:`${e.previous.version}, installed from ${_x(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(wq,{staged:e})},...(e.requires??[]).length>0?[{label:"Needs",value:n.jsx(yq,{staged:e,onInstallFirst:s})}]:[],{label:"Integrity",value:n.jsx(zx,{value:e.integrity})},...e.stagedHash?[{label:"Files on disk",value:n.jsx(zx,{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 tI({plan:e,busy:t,onReject:s,onInstallAnyway:r}){return n.jsxs(us,{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(dt,{}),n.jsx(E,{variant:"ghost",disabled:t,onClick:s,children:"Not this one"}),n.jsx(E,{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(nI,{unlocks:e.agents??[]})]})}function bq({staged:e,onInstalled:t,onGone:s,onInstallFirst:r}){const{plan:i,busy:a,failed:l,approve:o,reject:c}=XR(e,t,s);d.useEffect(()=>ZR(e),[e.id]);const u=(i==null?void 0:i.drift)??[];return n.jsxs(le,{gap:"sm",children:[n.jsxs(us,{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(dt,{}),n.jsx(E,{variant:"ghost",disabled:a,onClick:c,children:"Not this one"}),n.jsx(E,{variant:"accent",disabled:a||u.length>0,onClick:()=>o(!1),children:"Install"})]}),children:[n.jsx(ie,{message:l}),n.jsx(eI,{staged:e,onInstallFirst:r})]}),i&&u.length>0?n.jsx(tI,{plan:i,busy:a,onReject:c,onInstallAnyway:()=>o(!0)}):null]})}function kq({staged:e,onReview:t,onReject:s}){const r=Le(e.createdAt);return n.jsx(et,{onClick:t,label:`${e.name}: review`,lead:n.jsx(Rn,{svg:void 0}),title:n.jsxs(n.Fragment,{children:[e.name," ",n.jsx("span",{className:"plugins-ver",children:e.version})]}),sub:`from ${YR(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(E,{size:"sm",variant:"ghost",onClick:Sl(s),children:"Not this one"})]}),n.jsx(E,{size:"sm",onClick:Sl(t),children:"Review"})]})})}function Nq({staged:e,onClose:t,onInstalled:s,onGone:r,onInstallFirst:i}){const{plan:a,busy:l,failed:o,approve:c,reject:u}=XR(e,s,r),h=(a==null?void 0:a.drift)??[];return n.jsxs(qe,{title:n.jsx(Kw,{svg:void 0,name:e.name,version:e.version,by:e.author?n.jsx(Tf,{author:e.author}):zw(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(dt,{}),n.jsx(E,{variant:"ghost",disabled:l,onClick:u,children:"Not this one"}),n.jsx(E,{variant:"accent",disabled:l||h.length>0,onClick:()=>c(!1),children:"Install"})]}),children:[n.jsx(ie,{message:o}),n.jsx(eI,{staged:e,inSheet:!0,onInstallFirst:i}),a&&h.length>0?n.jsx(tI,{plan:a,busy:l,onReject:u,onInstallAnyway:()=>c(!0)}):null]})}const Sq=10*60*1e3;function Cq(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<Sq?r.id:null}function Eq({checkout:e,waiting:t}){const[s,r]=d.useState(!1),[i,a]=d.useState(null),l=jz(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(ie,{message:i}),n.jsxs(V,{tone:e?"warning":"accent",role:"status",action:e?void 0:n.jsx(E,{size:"sm",variant:"accent",disabled:s,onClick:()=>{r(!0),a(null),uf({kind:"plugins",...l?{line:`Loading ${l}…`}:{line:"Applying your plugin changes…"}},()=>A.serviceAction("restart")).catch(c=>a(Ei(c))).finally(()=>r(!1))},children:"Restart to load it"}),children:[o," ",e?fq:`${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 Ww="buddi.plugins.justInstalled";function Aq(e){try{window.sessionStorage.setItem(Ww,e)}catch{}}function Tq(){try{return window.sessionStorage.getItem(Ww)}catch{return null}}function $q({list:e,firstStepFor:t}){var u;const[s,r]=d.useState(()=>Tq()),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(Ww)}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(E,{size:"sm",variant:"ghost",onClick:o,children:"Later"}),c?n.jsx(E,{size:"sm",variant:"accent",onClick:()=>{o(),c.run()},children:c.label}):null]}),children:i.needs?`${i.name} is installed and waits. ${Hw(i)}.`:`${i.name} is loaded. First: ${((u=i.setup)==null?void 0:u.note)??"set it up on its settings page."}`})}const Sl=e=>t=>{t.stopPropagation(),e()},Rq=e=>e.unlocks.filter(t=>t.drift.state==="not-accepted").length;function Hw(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 Iq({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=Rq(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(Rn,{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:[Fr(g,"agent","agents")," to accept"]}):null]}),sub:v?n.jsx("span",{className:"plugins-sub","data-tone":"warning",children:Hw(e)}):`by ${qR(e)} · from ${YR(e.source)} · ${GR(e.contribution)}`,side:n.jsxs("span",{className:"plugins-side",children:[v&&m?n.jsx(E,{size:"sm",onClick:Sl(m.run),children:m.label}):null,t!=null&&t.update?n.jsxs(E,{size:"sm",disabled:i,onClick:Sl(()=>f(t.update)),children:["Update to ",t.update]}):null,v?null:s,!v&&!r&&o?n.jsx(E,{size:"sm",variant:"ghost",onClick:b=>{b.stopPropagation(),o()},children:"Settings"}):null,n.jsx(QR,{plugin:e}),n.jsx(Di,{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 Pq={"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 nI({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(Mq,{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:ft,children:"on the Agents page"}),"."]})]})}function Mq({plugin:e,unlock:t}){const s=ew(e,t.id),r=s.created?"up-to-date":t.drift.state,[i,a]=Pq[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(E,{size:"sm",variant:"accent",disabled:s.busy,onClick:s.accept,children:"Accept"}):null]})}),n.jsx(ie,{message:s.failure}),s.created?n.jsx(yT,{agent:s.created}):null]})}function Kw({svg:e,name:t,version:s,by:r,pills:i}){return n.jsxs("span",{className:"plugins-sheet-title",children:[n.jsx(Rn,{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 Dq({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(qe,{title:n.jsx(Kw,{svg:t==null?void 0:t.iconSvg,name:e.name,version:e.version,by:e.author?n.jsx(Tf,{author:e.author}):qR(e),pills:n.jsxs(n.Fragment,{children:[t?n.jsxs(n.Fragment,{children:[" · ",n.jsx(Bw,{entry:t})]}):null," · ",n.jsx(QR,{plugin:e})]})}),onClose:o,foot:n.jsxs(ae,{children:[n.jsx(E,{variant:"danger-ghost",onClick:h,children:"Remove…"}),n.jsx(dt,{}),l?n.jsx(E,{variant:"ghost",onClick:l,children:"Settings"}):null,r?n.jsx(E,{onClick:a,children:"Open"}):null,p?n.jsx(E,{onClick:u,children:"Enable"}):n.jsx(E,{variant:"ghost",onClick:c,children:"Disable…"}),t!=null&&t.update?n.jsxs(E,{variant:"accent",disabled:i,onClick:()=>f(t.update),children:["Update to ",t.update]}):n.jsx(E,{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(E,{size:"sm",variant:"accent",onClick:m.run,children:m.label}):void 0,children:["Waiting: ",Hw(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(E,{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:_x(e.source)},...g?[]:[{label:"Published by",value:zw(e.source,e.publisher)}],{label:"Integrity",value:n.jsx(zx,{value:e.integrity})},{label:"Installed",value:Le(e.installedAt)},...e.installedAs?[{label:"Installed as",value:e.installedAs}]:[],{label:"Contributes",value:GR(e.contribution)},...e.network||t?[{label:"Talks to hosts",value:JR(b)}]:[],...j?[{label:"Reaches in buddi",value:Uw(j)}]:[]]})}),n.jsx(nI,{plugin:e.name,unlocks:e.unlocks})]})}function Oq({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(Ei(x))).finally(()=>m(!1))};if(e==="disable")return n.jsxs(Lt,{title:`Disable ${t}?`,onClose:r,foot:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",disabled:f,onClick:r,children:"Cancel"}),n.jsx(E,{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(ie,{message:p})]});const b=!o||u.trim()===t;return n.jsxs(Lt,{title:`Remove ${t}?`,onClose:r,foot:n.jsxs(n.Fragment,{children:[s?n.jsx(E,{variant:"ghost",size:"sm",disabled:f,onClick:i,children:"Disable instead"}):null,n.jsx(dt,{}),n.jsx(E,{variant:"ghost",disabled:f,onClick:r,children:"Cancel"}),n.jsx(E,{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(ie,{message:p})]})}function Lq({plugins:e,openFor:t}){return n.jsxs(At,{boxed:!0,summary:`Ships with buddi · ${Fr(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"),Fr(s.contribution.tools,"tool","tools")]})]},s.name)})})]})}const Fq=[{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 _q(e,t){const s=t.trim().toLowerCase();return s===""?!0:[e.title,e.summary,e.npm].some(r=>r.toLowerCase().includes(s))}function zq({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 Uq({entry:e,busy:t,onOpen:s,onInstall:r,onUpdate:i}){var a;return n.jsxs(us,{onClick:s,label:`${e.title}: details`,children:[n.jsxs("div",{className:"plugins-card-head",children:[n.jsx(Rn,{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(Bw,{entry:e}),e.installed?n.jsxs(we,{children:["installed ",e.installed.version]}):null,n.jsx(dt,{}),e.update?n.jsxs(E,{size:"sm",disabled:t,onClick:Sl(()=>i(e.update)),children:["Update to ",e.update]}):e.installed?null:n.jsx(E,{size:"sm",variant:"accent",disabled:t,onClick:Sl(r),children:"Install"})]})]})}function Bq(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 Wq({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=Bq(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(qe,{title:n.jsx(Kw,{svg:e.iconSvg,name:e.title,version:e.version,by:e.author?n.jsx(Tf,{author:e.author}):"someone who gave no name",pills:n.jsxs(n.Fragment,{children:[" · ",n.jsx(Bw,{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(dt,{}),t?n.jsx(E,{onClick:r,children:"Open"}):null,e.update?n.jsxs(E,{variant:"accent",disabled:s,onClick:()=>l(e.update),children:["Update to ",e.update]}):e.installed?null:n.jsx(E,{variant:"accent",disabled:s,onClick:a,children:"Install"})]}),children:[o?n.jsx("img",{className:"plugins-shot",src:A.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:`${Fr(h,"agent","agents")}, created only if you accept`}]:[],{label:"Talks to hosts",value:JR(c)},{label:"Reaches in buddi",value:Uw(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(zq,{pricing:e.pricing})]})}]})})]})}function Hq({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"},...Fq.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:_q(y,h)),j=h.trim(),x=n.jsx("div",{className:"plugins-kind",children:n.jsx(Yt,{label:"Show",options:Kq,value:e,onChange:y=>t==null?void 0:t(y)})}),w=e==="plugins"?null:n.jsx(Vq,{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(jf,{grow:!0,label:"Search plugins",value:h,placeholder:"Search plugins: weather, money, calendar…",onChange:f}),n.jsx(PA,{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(E,{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(E,{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?` ${Le(r.fetchedAt)}`:" last time","."]}):null,b.length>0?n.jsx("div",{className:"plugins-grid",children:b.map(y=>n.jsx(Uq,{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 Kq=[{value:"all",label:"All"},{value:"plugins",label:"Plugins"},{value:"agents",label:"Agents"}];function Vq({kind:e,navigate:t}){const s=de(()=>A.catalogue(),[]),r=vw(),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=>Oi(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($$,{entry:c,loaded:r,onOpen:()=>i(Ht(c.name)),onAdd:()=>i(Ht(c.name)),onUpdate:()=>i(Ht(c.name))},c.name))})})}var Jc={},Gq=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then},sI={},hs={};let Vw;const Yq=[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];hs.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};hs.getSymbolTotalCodewords=function(t){return Yq[t]};hs.getBCHDigit=function(e){let t=0;for(;e!==0;)t++,e>>>=1;return t};hs.setToSJISFunction=function(t){if(typeof t!="function")throw new Error('"toSJISFunc" is not a valid function.');Vw=t};hs.isKanjiModeEnabled=function(){return typeof Vw<"u"};hs.toSJIS=function(t){return Vw(t)};var $f={};(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}}})($f);function rI(){this.buffer=[],this.length=0}rI.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 qq=rI;function Qc(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)}Qc.prototype.set=function(e,t,s,r){const i=e*this.size+t;this.data[i]=s,r&&(this.reservedBit[i]=!0)};Qc.prototype.get=function(e,t){return this.data[e*this.size+t]};Qc.prototype.xor=function(e,t,s){this.data[e*this.size+t]^=s};Qc.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]};var Jq=Qc,iI={};(function(e){const t=hs.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}})(iI);var aI={};const Qq=hs.getSymbolSize,vN=7;aI.getPositions=function(t){const s=Qq(t);return[[0,0],[s-vN,0],[0,s-vN]]};var lI={};(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}})(lI);var Rf={};const li=$f,Vu=[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],Gu=[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];Rf.getBlocksCount=function(t,s){switch(s){case li.L:return Vu[(t-1)*4+0];case li.M:return Vu[(t-1)*4+1];case li.Q:return Vu[(t-1)*4+2];case li.H:return Vu[(t-1)*4+3];default:return}};Rf.getTotalCodewordsCount=function(t,s){switch(s){case li.L:return Gu[(t-1)*4+0];case li.M:return Gu[(t-1)*4+1];case li.Q:return Gu[(t-1)*4+2];case li.H:return Gu[(t-1)*4+3];default:return}};var oI={},If={};const Uo=new Uint8Array(512),wh=new Uint8Array(256);(function(){let t=1;for(let s=0;s<255;s++)Uo[s]=t,wh[t]=s,t<<=1,t&256&&(t^=285);for(let s=255;s<512;s++)Uo[s]=Uo[s-255]})();If.log=function(t){if(t<1)throw new Error("log("+t+")");return wh[t]};If.exp=function(t){return Uo[t]};If.mul=function(t,s){return t===0||s===0?0:Uo[wh[t]+wh[s]]};(function(e){const t=If;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}})(oI);const cI=oI;function Gw(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}Gw.prototype.initialize=function(t){this.degree=t,this.genPoly=cI.generateECPolynomial(this.degree)};Gw.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=cI.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 Xq=Gw,uI={},Li={},Yw={};Yw.isValid=function(t){return!isNaN(t)&&t>=1&&t<=40};var yr={};const dI="[0-9]+",Zq="[A-Z $%*+\\-./:]+";let Ec="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";Ec=Ec.replace(/u/g,"\\u");const eJ="(?:(?![A-Z0-9 $%*+\\-./:]|"+Ec+`)(?:.|[\r
127
- ]))+`;yr.KANJI=new RegExp(Ec,"g");yr.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");yr.BYTE=new RegExp(eJ,"g");yr.NUMERIC=new RegExp(dI,"g");yr.ALPHANUMERIC=new RegExp(Zq,"g");const tJ=new RegExp("^"+Ec+"$"),nJ=new RegExp("^"+dI+"$"),sJ=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");yr.testKanji=function(t){return tJ.test(t)};yr.testNumeric=function(t){return nJ.test(t)};yr.testAlphanumeric=function(t){return sJ.test(t)};(function(e){const t=Yw,s=yr;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}}})(Li);(function(e){const t=hs,s=Rf,r=$f,i=Li,a=Yw,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}})(uI);var hI={};const Bx=hs,fI=1335,rJ=21522,jN=Bx.getBCHDigit(fI);hI.getEncodedBits=function(t,s){const r=t.bit<<3|s;let i=r<<10;for(;Bx.getBCHDigit(i)-jN>=0;)i^=fI<<Bx.getBCHDigit(i)-jN;return(r<<10|i)^rJ};var mI={};const iJ=Li;function Cl(e){this.mode=iJ.NUMERIC,this.data=e.toString()}Cl.getBitsLength=function(t){return 10*Math.floor(t/3)+(t%3?t%3*3+1:0)};Cl.prototype.getLength=function(){return this.data.length};Cl.prototype.getBitsLength=function(){return Cl.getBitsLength(this.data.length)};Cl.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 aJ=Cl;const lJ=Li,dp=["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 El(e){this.mode=lJ.ALPHANUMERIC,this.data=e}El.getBitsLength=function(t){return 11*Math.floor(t/2)+6*(t%2)};El.prototype.getLength=function(){return this.data.length};El.prototype.getBitsLength=function(){return El.getBitsLength(this.data.length)};El.prototype.write=function(t){let s;for(s=0;s+2<=this.data.length;s+=2){let r=dp.indexOf(this.data[s])*45;r+=dp.indexOf(this.data[s+1]),t.put(r,11)}this.data.length%2&&t.put(dp.indexOf(this.data[s]),6)};var oJ=El;const cJ=Li;function Al(e){this.mode=cJ.BYTE,typeof e=="string"?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}Al.getBitsLength=function(t){return t*8};Al.prototype.getLength=function(){return this.data.length};Al.prototype.getBitsLength=function(){return Al.getBitsLength(this.data.length)};Al.prototype.write=function(e){for(let t=0,s=this.data.length;t<s;t++)e.put(this.data[t],8)};var uJ=Al;const dJ=Li,hJ=hs;function Tl(e){this.mode=dJ.KANJI,this.data=e}Tl.getBitsLength=function(t){return t*13};Tl.prototype.getLength=function(){return this.data.length};Tl.prototype.getBitsLength=function(){return Tl.getBitsLength(this.data.length)};Tl.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let s=hJ.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 fJ=Tl,pI={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})(pI);var mJ=pI.exports;(function(e){const t=Li,s=aJ,r=oJ,i=uJ,a=fJ,l=yr,o=hs,c=mJ;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 T=0;T<S.length;T++){const R=S[T],I=""+N+T;C.push(I),w[I]={node:R,lastCount:0},y[I]={};for(let L=0;L<k.length;L++){const _=k[L];w[_]&&w[_].node.mode===R.mode?(y[_][I]=m(w[_].lastCount+R.length,R.mode)-m(w[_].lastCount,R.mode),w[_].lastCount+=R.length):(w[_]&&(w[_].lastCount=R.length),y[_][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 T=1;T<S.length-1;T++)C.push(N.table[S[T]].node);return e.fromArray(p(C))},e.rawSplit=function(x){return e.fromArray(f(x,o.isKanjiModeEnabled()))}})(mI);const Pf=hs,hp=$f,pJ=qq,gJ=Jq,xJ=iI,vJ=aI,Wx=lI,Hx=Rf,jJ=Xq,yh=uI,wJ=hI,yJ=Li,fp=mI;function bJ(e,t){const s=e.size,r=vJ.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 kJ(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 NJ(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 SJ(e,t){const s=e.size,r=yh.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 mp(e,t,s){const r=e.size,i=wJ.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 CJ(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 EJ(e,t,s){const r=new pJ;s.forEach(function(c){r.put(c.mode.bit,4),r.put(c.getLength(),yJ.getCharCountIndicator(c.mode,e)),c.write(r)});const i=Pf.getSymbolTotalCodewords(e),a=Hx.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 AJ(r,e,t)}function AJ(e,t,s){const r=Pf.getSymbolTotalCodewords(t),i=Hx.getTotalCodewordsCount(t,s),a=r-i,l=Hx.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 jJ(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 TJ(e,t,s,r){let i;if(Array.isArray(e))i=fp.fromArray(e);else if(typeof e=="string"){let u=t;if(!u){const h=fp.rawSplit(e);u=yh.getBestVersionForData(h,s)}i=fp.fromString(e,u||40)}else throw new Error("Invalid data");const a=yh.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=EJ(t,s,i),o=Pf.getSymbolSize(t),c=new gJ(o);return bJ(c,t),kJ(c),NJ(c,t),mp(c,s,0),t>=7&&SJ(c,t),CJ(c,l),isNaN(r)&&(r=Wx.getBestMask(c,mp.bind(null,c,s))),Wx.applyMask(r,c),mp(c,s,r),{modules:c,version:t,errorCorrectionLevel:s,maskPattern:r,segments:i}}sI.create=function(t,s){if(typeof t>"u"||t==="")throw new Error("No input text");let r=hp.M,i,a;return typeof s<"u"&&(r=hp.from(s.errorCorrectionLevel,hp.M),i=yh.from(s.version),a=Wx.from(s.maskPattern),s.toSJISFunc&&Pf.setToSJISFunction(s.toSJISFunc)),TJ(t,i,r,a)};var gI={},qw={};(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}}})(qw);(function(e){const t=qw;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)}})(gI);var xI={};const $J=qw;function wN(e,t){const s=e.a/255,r=t+'="'+e.hex+'"';return s<1?r+" "+t+'-opacity="'+s.toFixed(2).slice(1)+'"':r}function pp(e,t,s){let r=e+t;return typeof s<"u"&&(r+=" "+s),r}function RJ(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?pp("M",c+s,.5+u+s):pp("m",i,0),i=0,a=!1),c+1<t&&e[o+1]||(r+=pp("h",l),l=0)):i++}return r}xI.render=function(t,s,r){const i=$J.getOptions(s),a=t.modules.size,l=t.modules.data,o=a+i.margin*2,c=i.color.light.a?"<path "+wN(i.color.light,"fill")+' d="M0 0h'+o+"v"+o+'H0z"/>':"",u="<path "+wN(i.color.dark,"stroke")+' d="'+RJ(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 IJ=Gq,Kx=sI,vI=gI,PJ=xI;function Jw(e,t,s,r,i){const a=[].slice.call(arguments,1),l=a.length,o=typeof a[l-1]=="function";if(!o&&!IJ())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=Kx.create(s,r);c(e(h,t,r))}catch(h){u(h)}})}try{const c=Kx.create(s,r);i(null,e(c,t,r))}catch(c){i(c)}}Jc.create=Kx.create;Jc.toCanvas=Jw.bind(null,vI.render);Jc.toDataURL=Jw.bind(null,vI.renderToDataURL);Jc.toString=Jw.bind(null,function(e,t,s){return PJ.render(e,s)});async function MJ(e){const t=await Jc.toString(e,{type:"svg",margin:1,errorCorrectionLevel:"M"});return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(t)}`}const yN=10*6e4,DJ=2e3;function Qw(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 A.telegramPairing();r(p),u(!1),o(!1),a(await MJ(p.link).catch(()=>""))},[]);return d.useEffect(()=>{if(!s||l||c)return;let p=!1;const g=Math.min(Date.parse(s.expiresAt)||Date.now()+yN,Date.now()+yN),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(()=>{})},DJ);return()=>{p=!0,window.clearInterval(v)}},[s,l,c]),{offer:s,square:i,paired:l,stale:c,ask:m}}function Xw({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 jI=new Set(["approval","question"]),jd={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."}},OJ=new Set(["agent"]),LJ={maxUrgency:"now",muted:[]};function FJ(e,t){var i;const s=jd[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 _J({timezone:e}){var j,x,w;const t=de(()=>A.notificationSettings(),[]),s=de(()=>A.agents(),[]),r=de(()=>A.notifications(20),[],3e4),i=d.useRef(!1);d.useEffect(()=>{var y,k;i.current||!r.data||window.location.hash!==_g||(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),A.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(E,{variant:"accent",disabled:o||!g,onClick:b,children:"Save"}),children:n.jsxs(le,{divided:!0,children:[n.jsx(ie,{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(VJ,{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:[EL.filter(y=>!OJ.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:jd[y].label}),n.jsx("span",{className:"ui-field-hint",children:jd[y].hint})]}),n.jsxs("select",{"aria-label":jd[y].label,value:GJ(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)),jI.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(zJ,{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(JJ,{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(UJ,{}),n.jsx("div",{id:"notifications-recent",className:"notifications-recent",children:n.jsxs(ue,{title:"The last twenty",panel:!0,flush:!0,children:[n.jsx(ie,{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:fc(y),sub:`${nt(y.createdAt,e)} · ${FJ(y,((k=s.data)==null?void 0:k.agents)??[])} · ${YJ(y,p)}`,side:n.jsx(qJ,{row:y})},y.id)})}):n.jsx(pe,{children:"Loading…"})]})})]})}function zJ({settings:e,agents:t,onChange:s}){const r=e.perKind.agent!=="off",i=e.agents??LJ,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 UJ(){var u;const e=de(()=>A.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),A.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(ie,{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 BJ({timezone:e}){return n.jsx(WJ,{timezone:e,onChange:()=>{}})}function WJ({timezone:e,onChange:t}){var C,T;const s=de(()=>A.telegramBot(),[]),r=de(()=>A.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=Qw(()=>A.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);A.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(E,{variant:"ghost",onClick:()=>{a(!1),o("")},children:"Cancel"}):null,n.jsx(E,{variant:"accent",disabled:c||l.trim()==="",onClick:x,children:"Save token"})]}):void 0,children:n.jsxs(le,{gap:"sm",children:[n.jsx(ie,{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:(T=s.data)!=null&&T.username?`Bot: @${s.data.username}`:"A bot token is saved."}),n.jsx(E,{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(ie,{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 ${Le(R.lastSeenAt)}`:"has not spoken yet"}`,side:n.jsx(HJ,{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(E,{variant:y?void 0:"accent",onClick:w,children:"Pair a phone"}):b&&S?n.jsx(E,{variant:"accent",onClick:w,children:"New code"}):void 0,children:n.jsxs(le,{gap:"sm",children:[n.jsx(ie,{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(Xw,{offer:y,square:k,children:n.jsx(KJ,{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 HJ({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(E,{size:"sm",onClick:()=>r(!0),children:"Unpair"});const c=()=>{a(!0),o(null),A.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(E,{size:"sm",variant:"ghost",disabled:i,onClick:()=>r(!1),children:"Keep"}),n.jsx(E,{size:"sm",variant:"danger",disabled:i,onClick:c,children:"Unpair"})]})}function KJ({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(E,{size:"sm",onClick:r,children:"Copy"}),t?n.jsx("span",{className:"ui-field-hint",role:"status",children:t}):null]})}function VJ({channel:e,checked:t,onPick:s}){const[r,i]=d.useState(!1),[a,l]=d.useState(null),o=()=>{i(!0),l(null),A.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(E,{size:"sm",disabled:r,onClick:o,children:"Send a test"})]})}function GJ(e,t,s){const r=e.perKind[t];return r==="off"?jI.has(t)?"default":"off":r&&s.some(i=>i.kind===r)?r:"default"}function YJ(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 qJ({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 bN={mon:"Mon",tue:"Tue",wed:"Wed",thu:"Thu",fri:"Fri",sat:"Sat",sun:"Sun"},kN={mode:"do-not-disturb",days:[...Tg],from:"22:00",to:"07:00"};function JJ({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:Tg.map(l=>{const o=r.days.includes(l);return n.jsx("button",{type:"button",className:"nt-day","aria-pressed":o,"aria-label":`Schedule ${a} ${bN[l]}`,onClick:()=>s(i,{days:o?r.days.filter(c=>c!==l):Tg.filter(c=>c===l||r.days.includes(c))}),children:bN[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(E,{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(E,{size:"sm",onClick:()=>t([...e,{...kN,days:[...kN.days]}]),children:"Add a schedule"})})]})}const QJ={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 XJ(e){const t=L4.map(r=>({id:r.id,route:Pe(r.id),label:r.label,icon:QJ[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:tA(r.plugin,r.id),route:Vr(r.plugin,r.id),label:r.title,icon:JT(r.icon),group:"plugins"}));return[...t,...s]}function wI(e){return O4.map(t=>({id:t.id,label:t.label,entries:e.filter(s=>s.group===t.id)})).filter(t=>t.entries.length>0)}function yI(e,t,s){return t?`${e}, ${t} open`:s?`${e}, ${s}`:void 0}function ZJ({entries:e,active:t,counts:s={},dots:r={},navigate:i}){var u;const a=d.useRef(null),l=wI(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":yI(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 eQ({entries:e,active:t,counts:s={},dots:r={},navigate:i}){const a=wI(e),l=e.find(o=>o.id===t)??e[0];return n.jsx("nav",{className:"settings-menu","aria-label":"Settings sections",children:n.jsxs(_c,{modal:!1,children:[n.jsx(zc,{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(zl,{children:n.jsx(Uc,{className:"ui-menu settings-menu-list",align:"start",sideOffset:6,children:n.jsx(B_,{value:t,onValueChange:o=>{const c=e.find(u=>u.id===o);c&&i(c.route)},children:a.map((o,c)=>n.jsxs(JE,{children:[c>0?n.jsx(Ir,{className:"ui-menu-sep"}):null,n.jsx(da,{className:"ui-menu-label",children:o.label}),o.entries.map(u=>{const h=s[u.id],f=r[u.id];return n.jsxs(W_,{value:u.id,className:"ui-menu-item settings-menu-item","data-active":u.id===t?"true":void 0,"aria-label":yI(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 tQ({hash:e,timezone:t,navigate:s,agents:r,pluginPages:i}){var x,w,y;const a=F4(e),l=HA(i!==void 0),o=i??l,c=S4(e),u=c?o.find(c.plugin,c.page):void 0,h=ks(Lj),f=XJ(o.settings),p={proposals:((w=(x=de(()=>Promise.resolve().then(()=>A.proposals()),[],3e4).data)==null?void 0:x.open)==null?void 0:w.length)??0},g=de(()=>A.version(),[]),v=de(()=>Promise.resolve().then(()=>A.connectionSignals()),[],6e4),b={};g.data&&!g.data.checkout&&g.data.updateAvailable&&(b.system="a newer buddi is ready"),(((y=v.data)==null?void 0:y.signals)??[]).length>0&&(b.connections=f$);const j={entries:f,active:a,counts:p,dots:b,navigate:k=>s(k)};return n.jsxs("div",{className:"settings",children:[h?null:n.jsx(ZJ,{...j}),n.jsx("div",{className:"settings-body",children:n.jsxs("div",{className:"ui-page",children:[a==="secrets"?n.jsx(yl,{before:n.jsx(th,{inline:!0,items:[{label:"Settings",href:an,onClick:()=>s(an)}]}),title:"Keys and secrets",lede:LR,actions:n.jsx(Et,{variant:"accent",size:"sm",href:vk,onClick:k=>{k.preventDefault(),s(vk)},children:"Add a secret"})}):a==="plugins"||a==="connections"?n.jsx(yl,{before:n.jsx(th,{inline:!0,items:[{label:"Settings",href:an,onClick:()=>s(an)}]}),title:a==="plugins"?"Plugins":"Connections",lede:a==="plugins"?uq:Q$}):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."})]}),h?n.jsx(eQ,{...j}):null,u?n.jsx(oH,{page:u,params:eA(e),navigate:s,timezone:t,siblings:o.all.filter(k=>k.plugin===u.plugin)}):null,a==="you"?n.jsx(BY,{embedded:!0}):null,a==="appearance"?n.jsx(nQ,{railPages:o.rail}):null,a==="notifications"?n.jsx(_J,{timezone:t}):null,a==="telegram"?n.jsx(BJ,{timezone:t}):null,a==="memory"?n.jsx(R$,{embedded:!0,agents:r,timezone:t}):null,a==="proposals"?n.jsx(nq,{embedded:!0,plugin:P4(e)}):null,a==="accounts"?n.jsx(RG,{embedded:!0,account:C4(e)}):null,a==="computer"?n.jsx(y5,{embedded:!0,timezone:t}):null,a==="secrets"?n.jsx(xY,{embedded:!0,timezone:t,secret:A4(e),adding:T4(e),navigate:s}):null,a==="connections"?n.jsx(P9,{embedded:!0,timezone:t,connection:E4(e)}):null,a==="lock"?n.jsx(LY,{navigate:s}):null,a==="api"?n.jsx(UY,{timezone:t}):null,a==="watchers"?n.jsx(EY,{timezone:t,embedded:!0}):null,a==="backup"?n.jsx(NG,{}):null,a==="plugins"?n.jsx(vq,{railPages:o.rail,settingsPages:o.settings,navigate:s,hash:e}):null,a==="system"?n.jsx(iQ,{timezone:t}):null]})})]})}function nQ({railPages:e}){const[t,s]=w$();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(gp,{label:"Theme",hint:"System follows your Mac.",children:n.jsx(Yt,{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(gp,{label:"Background",hint:"Blue carries the first-run colours through the app. Sand is quieter.",children:n.jsx(Yt,{label:"Background",options:[{value:"blue",label:"Blue"},{value:"sand",label:"Sand"}],value:t.ground,onChange:r=>s({ground:r})})}),n.jsx(gp,{label:"Page width",hint:"How far pages stretch on a wide screen.",children:n.jsx(Yt,{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(rQ,{pages:e}),n.jsx(sQ,{})]})})}function sQ(){var c,u,h;const e=de(()=>A.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),A.setGlanceHidden(f,!m).then(()=>e.reload()).finally(()=>s(null))},o=(f,m)=>{s(`block:${f}`),A.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 rQ({pages:e}){const t=m$(),[s,r]=d.useState(null);if(e.length===0)return null;const i=(a,l)=>{r(null),BK(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(ie,{message:s}),e.map(a=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:!t.has(Cc(a)),onChange:l=>i(a,l.target.checked)}),n.jsx("span",{children:a.title})]},Cc(a)))]})]})}function gp({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 iQ({timezone:e}){const t=de(()=>A.overview(),[],15e3),s=de(()=>A.session(),[]),r=de(()=>A.providerAccounts(),[]),i=t.data;return n.jsxs(le,{gap:"lg",children:[n.jsx(ie,{message:t.error}),n.jsx(vQ,{}),i?n.jsx(ue,{title:"The queue",panel:!0,actions:n.jsx(E,{size:"sm",variant:i.paused?"accent":void 0,onClick:()=>{A.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?cQ(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(oQ,{}),n.jsx(vH,{}),n.jsx(aQ,{}),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 ",Le(a.lastRunAt)]})}))}):n.jsx(pe,{children:"Loading…"})})]})}function aQ(){var p;const e=de(()=>A.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),A.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(E,{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(ie,{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(E,{size:"sm",disabled:r||!u,onClick:()=>{lQ((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 lQ(e){var t;try{await((t=navigator.clipboard)==null?void 0:t.writeText(e))}catch{}}function oQ(){var u;const e=de(()=>A.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),uf({kind:h},()=>A.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(NN,{state:o.database,pid:o.databasePid})},{label:"Gateway",value:n.jsx(NN,{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(ie,{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(E,{variant:"ghost",disabled:r,onClick:()=>{s(null),l(null)},children:"Cancel"}),n.jsx(E,{variant:t==="stop"?"danger":"accent",disabled:r,onClick:()=>{c(t)},children:t==="stop"?"Stop it":"Restart it"})]}):n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:()=>{s("stop")},children:"Stop gateway"}),n.jsx(E,{variant:"accent",onClick:()=>{s("restart")},children:"Restart gateway"})]})})]})})]})})}function NN({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 cQ(e){return e==="keychain"?"macOS Keychain":e==="file"?"Encrypted file vault":e==="none"?"None":e}const uQ=2e3,bh={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."},dQ=new Set(["done","failed","rolled-back"]),hQ="The check asks the npm registry for the newest version and sends nothing else.",fQ="This takes a backup, installs the new version and restarts buddi. This page waits for it and comes back by itself.",mQ="A checkout upgrades with git pull, then buddi upgrade in a terminal.",pQ=15*6e4;function gQ(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 SN(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<pQ?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||A.upgradeJob(e).then(f=>{var m;o||(r(f),a(null),cA({step:bh[f.phase]??f.detail??f.phase}),(dQ.has(f.phase)||f.finishedAt)&&(o=!0,f.phase==="failed"&&(wl(),(m=l.current)==null||m.call(l,f))))}).catch(f=>{o||(f instanceof ve&&f.status!==0&&f.status<500?(o=!0,wl(),a(f.message)):c=!0)})};u();const h=window.setInterval(u,uQ);return()=>{o=!0,window.clearInterval(h)}},[e]),{job:s,error:i}}function vQ(){const e=de(()=>A.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),A.checkVersion().catch(j=>c(j instanceof ve?j.message:String(j))).finally(()=>{l(!1),e.reload()})},v=j=>{l(!0),c(null),A.setVersionCheck(j).catch(x=>c(x instanceof ve?x.message:String(x))).finally(()=>{l(!1),e.reload()})},b=()=>{l(!0),c(null),h(null),uf({kind:"upgrade",line:p!=null&&p.latest?`Upgrading to ${p.latest}…`:"Upgrading…",step:bh.starting,patienceMs:oA},()=>A.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:mQ})})]})}):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(ie,{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 ",Le(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(E,{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:hQ})]})}),p!=null&&p.updateAvailable&&p.latest&&p.latestNotes?n.jsx(ue,{title:`What changes in ${p.latest}`,children:n.jsx(mr,{text:p.latestNotes})}):null,n.jsx(ue,{children:n.jsxs(le,{gap:"sm",children:[n.jsx(jQ,{...m,job:m.job??u??void 0}),!m.job&&!u&&!m.error&&p&&SN(p.history)?n.jsx(V,{tone:"critical",role:"alert",children:gQ(SN(p.history))}):null,r?n.jsx(V,{tone:"warning",role:"alert",children:fQ}):null,n.jsx(ae,{align:"end",children:r?n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",disabled:a,onClick:()=>i(!1),children:"Cancel"}),n.jsxs(E,{variant:"accent",disabled:a,onClick:b,children:["Upgrade to ",p==null?void 0:p.latest]})]}):n.jsx(E,{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(wQ,{attempt:j})}))})}):null]})})}function jQ({job:e,error:t}){return t?n.jsx(ie,{message:t}):e?e.phase==="failed"?n.jsxs(V,{tone:"critical",role:"alert",children:[bh.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:bh[e.phase]??e.detail??e.phase}):null}function wQ({attempt:e}){return n.jsxs("span",{children:[n.jsx(we,{tone:e.outcome==="done"?"good":e.outcome==="failed"?"critical":"warning",children:e.outcome})," ",Le(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 kh=["hello","brain","takeOn","reach","assistant","handover"],bI={hello:"you",brain:"model",takeOn:"take-on",reach:"reach",assistant:"agent",handover:"hello"};function kI(e){return((e==null?void 0:e.accounts)??[]).filter(t=>t.enabled&&t.configured&&t.removalPending!==!0)}function yQ(e){var a,l,o;const t=kI(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 NI(e){var a,l,o,c,u;const t=yQ(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 SI(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 wd(e){return kh.find(t=>!SI(e,t))??"handover"}function bQ(e){const t=kh.indexOf(e);return t>0?kh[t-1]:null}function CN(e,t,s){return s===t?"now":SI(e,s)?"done":"todo"}function kQ(e,t){return{...e}}const Vx="buddi.firstRun.restore";function Gx(e){try{e===null?window.sessionStorage.removeItem(Vx):window.sessionStorage.setItem(Vx,e)}catch{}}function CI(){try{return window.sessionStorage.getItem(Vx)}catch{return null}}function NQ(e){const t=NI(e),s=wd(t);return{answers:t,open:s,stay:s!=="handover"}}function SQ(e){return e.trim().startsWith("sk-ant-")?"anthropic":"openai"}function CQ(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 EQ=6e4,AQ=5*6e4,EI=1500,TQ=2e3,$Q="(max-width: 720px)";function Jl(){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 Zw=d.createContext({busy:0,report:()=>{}});function RQ({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(Zw.Provider,{value:i,children:e})}function ht({children:e}){const{busy:t}=d.useContext(Zw);return n.jsxs("div",{className:"wiz-say",children:[n.jsx(Vc,{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 Vs({line:e}){const{report:t}=d.useContext(Zw);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 ey=d.createContext(null);function en({children:e,actions:t}){const s=d.useContext(ey),r=t==null?null:s?Ml.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 is({onClick:e,disabled:t}){return n.jsxs(E,{variant:"ghost",size:"lg",onClick:e,disabled:t,children:[n.jsx(ce,{name:"chevron-left"}),z.back]})}function Ql({children:e,onClick:t,disabled:s}){return n.jsxs(E,{variant:"accent",size:"lg",onClick:t,disabled:s,children:[e,n.jsx(ce,{name:"arrow"})]})}function IQ({navigate:e,timezone:t}){var pn,Yn,Z,Re,Xe,xt,G;const s=ks($Q),[r,i]=d.useState(void 0);d.useEffect(()=>{A.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),[T,R]=d.useState(null),[I,L]=d.useState(null),[_,$]=d.useState(()=>CI()?"running":"idle"),[P,O]=d.useState({}),[M,D]=d.useState([]),[H,B]=d.useState(0),q=d.useRef(void 0),[W,Y]=d.useState(null),F=d.useCallback(()=>{Promise.resolve().then(()=>A.takeOnProgress()).then(he=>{he&&Array.isArray(he.plugins)&&Y(he)}).catch(()=>{})},[]);d.useEffect(()=>{if(!(W!=null&&W.running))return;const he=window.setInterval(F,TQ);return()=>window.clearInterval(he)},[W==null?void 0:W.running,F]);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,Be=!1)=>{var qn,On,Gs,Zl,Fi,Ln,_i,br,Qr;const[_e,nn,As,Nn,Ts,$s]=await Promise.all([A.onboarding().catch(()=>{}),A.owner().catch(()=>{}),A.providerAccounts().catch(()=>{}),He.agents().catch(()=>{}),A.browser().catch(()=>{}),A.providers().catch(()=>{})]);h(As);const ke=(On=(qn=$s==null?void 0:$s.providers.find(Ut=>Ut.kind==="anthropic"))==null?void 0:qn.defaultModel)==null?void 0:On.trim();m(ke||void 0),g((nn==null?void 0:nn.zones)??[]),N(((Gs=_e==null?void 0:_e.details)==null?void 0:Gs.conversationId)??null);const Ee=(Nn==null?void 0:Nn.agents.find(Ut=>Ut.id===Nn.defaultAgentId))??(Nn==null?void 0:Nn.agents[0]);Ee&&b(Ee),C(_e&&!_e.needs.agent&&Ee?{id:Ee.id,name:Ee.name,avatar:((Zl=Ee.avatar)==null?void 0:Zl.kind)==="emoji"?Ee.avatar.value:"",description:Ee.description,...Ee.picture?{picture:Ee.picture}:{}}:null),Array.isArray((Fi=_e==null?void 0:_e.details)==null?void 0:Fi.takeOn)&&F();const We={onboarding:_e,owner:nn,accounts:As,browser:(Ln=Ts==null?void 0:Ts.browser)==null?void 0:Ln.engine,...Ee?{assistant:{id:Ee.id,name:Ee.name,avatar:((_i=Ee.avatar)==null?void 0:_i.kind)==="emoji"?Ee.avatar.value:""}}:{}};if(Be){const Ut=NQ(We);if(l(Ut.answers),c(Ut.open),!Ut.stay){const Ys=(br=_e==null?void 0:_e.details)==null?void 0:br.conversationId;Q.current(Ys&&Ee?st(Ee.id,Ys):un,!0)}return}if(he&&(_e==null?void 0:_e.state)==="done"){const Ut=(Qr=_e.details)==null?void 0:Qr.conversationId;Q.current(Ut&&Ee?st(Ee.id,Ut):un,!0);return}if(!he)return;const me=NI(We);l(me),c(Ut=>Ut??wd(me))},[]);d.useEffect(()=>{ee()},[ee]);const fe=(he,Be={})=>{Promise.resolve().then(()=>A.onboardingStep(bI[he],Be)).catch(()=>{})},Oe=he=>wd(he)==="brain"&&P.brain?{...he,brain:P.brain}:he,Ie=(he,Be)=>{const _e=Oe(Be);_e.brain&&(q.current=_e.brain),x(null),D([]),l(_e),he==="brain"&&_e.brain?fe(he,{accountId:_e.brain.accountId}):he==="reach"?fe(he,_e.reach?{reach:_e.reach}:{}):he!=="takeOn"&&fe(he),c(wd(_e))},Fe=(he,Be)=>{x(null),l(Be),Be.brain&&(q.current=Be.brain),he==="brain"&&Be.brain&&fe(he,{accountId:Be.brain.accountId})},U=he=>{x(null),l(Be=>kQ(Be)),c(he)},se=()=>{if(!o)return;const he=bQ(o==="handover"?"handover":o);he&&U(he)},J=()=>{const he=a.brain??q.current,Be=((W==null?void 0:W.plugins)??[]).filter(_e=>_e.state==="ready").map(_e=>_e.title);x(null),O({}),D([]),l({}),c("hello"),B(_e=>_e+1),(async()=>{var ke;const[_e,nn,As]=await Promise.all([Promise.resolve().then(()=>A.providerAccounts()).catch(()=>{}),Promise.resolve().then(()=>A.telegram()).catch(()=>{}),Promise.resolve().then(()=>A.browser()).catch(()=>{})]),Nn=kI(_e),Ts=he&&Nn.some(Ee=>Ee.id===he.accountId)?he:void 0;_e&&h(_e),O(Ts?{brain:Ts}:{});const $s=[...new Set(Nn.map(Ee=>Ee.label)),...nn!=null&&nn.paired?[z.startOver.telegram]:[],...((ke=As==null?void 0:As.browser)==null?void 0:ke.engine)==="chromium"?[z.startOver.browser]:[],...Be];D($s.length>0?[z.startOver.said($s.join(", "))]:[])})()},ye=()=>{y(!0),A.skipOnboarding().then(()=>e(un)).catch(he=>x(he instanceof ve?he.message:String(he))).finally(()=>y(!1))},ge=de(()=>A.version().catch(()=>({current:""})),[]),$e=d.useRef(null);d.useEffect(()=>{$e.current&&($e.current.scrollTop=0)},[o]);const De=_==="running",Je=Object.keys(a).length===0,ze={answers:a,accounts:u,claudeModel:f,zones:p,browserZone:X,assistantAgent:v,met:k,onMet:N,existing:S,progress:W,onProgress:F,navigate:e,onSettled:he=>o&&Ie(o,he),onKept:he=>o&&Fe(o,he),onBack:se,onTrouble:x,onReload:()=>void ee(!1),onPickAnotherBrain:()=>U("brain"),onSpoken:L},Se=(a.takeOn??[]).map(he=>{var Be;return((Be=Oo.find(_e=>_e.id===he))==null?void 0:Be.title)??he}),Ue=(W==null?void 0:W.plugins)??[],at=Ue.filter(he=>he.state==="ready").length,Ye=Ue.length===0?null:W!=null&&W.running?z.takeOn.installing(at,Ue.length):at===Ue.length?z.takeOn.installed:null,kt=[(pn=a.reach)!=null&&pn.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),qt={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(Se),sub:Ye},reach:{answer:z.reach.answer(kt)},assistant:{answer:((xt=a.assistant)==null?void 0:xt.name)??""}},re=kh.filter(he=>he!=="handover"),be=o===null||o==="handover"?re.length:re.indexOf(o),Qe=Math.min(be,re.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&&_==="idle"?n.jsx("button",{type:"button",className:"wiz-link",onClick:()=>$("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]}),yt=r===void 0||r==="darwin"?z.tagline:z.taglineElsewhere,ut=o&&o!=="handover"?n.jsx("span",{className:"wiz-count",children:z.count(be+1)}):n.jsx("span",{className:"wiz-count"});return n.jsx(ey.Provider,{value:T,children:n.jsx(RQ,{children:n.jsxs(DA,{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(jc,{size:"sm"}),n.jsx("span",{className:"wiz-dots","aria-label":o&&o!=="handover"?z.count(be+1):void 0,children:re.map(he=>n.jsx("i",{"data-state":CN(a,o,he)},he))}),n.jsx("span",{className:"wiz-strip-name",children:o&&o!=="handover"?z.strip(be+1,z.chapters[be]??""):z.handover.starterLabel})]}):n.jsxs("nav",{className:"wiz-map","aria-label":"Chapters",children:[n.jsxs("div",{className:"wiz-head",children:[n.jsx(jc,{size:"lg"}),n.jsxs("div",{children:[n.jsx("div",{className:"wiz-head-name",children:"buddi"}),n.jsx("div",{className:"wiz-head-line",children:yt}),(G=ge.data)!=null&&G.current?n.jsxs("div",{className:"wiz-head-version mono",children:["buddi ",ge.data.current]}):null]})]}),re.map((he,Be)=>{const _e=De?he==="hello"?"now":"todo":CN(a,o,he),nn=qt[he];return n.jsxs("div",{className:"wiz-ch","data-state":_e,"aria-current":_e==="now"?"step":void 0,children:[n.jsx("span",{className:"wiz-num","data-state":_e,children:_e==="done"?n.jsx(ce,{name:"check",size:12}):Be+1}),n.jsxs("span",{className:"wiz-ch-label",children:[_e==="done"?nn.answer:z.chapters[Be],_e==="done"&&nn.sub?n.jsx("span",{className:"wiz-ch-sub",children:nn.sub}):null]}),_e==="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(HU,{dock:n.jsxs(n.Fragment,{children:[ut,n.jsx("div",{className:"wiz-dock-actions",ref:R})]}),children:[De?n.jsx(lX,{onDone:he=>{$("idle"),D([...he?[z.restore.welcome(he)]:[],z.restore.keys]),ee(!0,!0)},onFailed:he=>{$("idle"),x(he)}}):o==="hello"?n.jsx(PQ,{...ze}):o==="brain"?n.jsx(DQ,{...ze}):o==="takeOn"?n.jsx(QQ,{...ze}):o==="reach"?n.jsx(XQ,{...ze}):o==="assistant"?n.jsx(sX,{...ze}):o==="handover"?n.jsx(rX,{...ze}):n.jsx(Vs,{}),M.length>0||j?n.jsxs(it,{children:[M.map(he=>n.jsx(ht,{children:he},he)),j?n.jsx(ht,{children:j}):null]}):null]},`${H}-${o??""}-${De?"r":""}`),s?n.jsx("div",{className:"wiz-phone-out",children:ct}):null]})})]})}),_==="form"?n.jsx(aX,{onCancel:()=>$("idle"),onStarted:()=>$("running"),onTrouble:x}):null]})})})}function Xl({children:e}){return n.jsx("h1",{className:"wiz-title",children:e})}function EN(e){try{return zt(new Date,e)}catch{return""}}function PQ({answers:e,zones:t,browserZone:s,onSettled:r,onTrouble:i}){const a=Jl(),[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),A.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(Xl,{children:z.hello.title}),n.jsx(it,{children:z.hello.opening.map(v=>n.jsx(ht,{children:v},v))}),n.jsxs(en,{actions:n.jsx(Ql,{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(EN(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(EN(c)),action:n.jsx(E,{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 MQ={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 DQ(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,T]=d.useState(null);d.useEffect(()=>{let H=!1;const B=()=>{Promise.resolve().then(()=>A.ollama()).then(W=>{!H&&W&&b(W)}).catch(()=>{}),Promise.resolve().then(()=>A.mlxh()).then(W=>{!H&&W&&x(W)}).catch(()=>{H||x({running:!1,baseUrl:"",manager:!1,models:[]})})};B();const q=window.setInterval(B,4e3);return()=>{H=!0,window.clearInterval(q)}},[]);const R=async H=>{if(s.assistant??e.existing)try{await A.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(),T(null),c(null),y(null),null},I=async(H,B,q)=>{g(!0),m(null);try{const W=await A.saveProviderAccount(H);let Y=await A.testProviderAccount(W.id),F=H.defaultModel,X=!1;if(Y.state!=="connected"&&q&&q!==F&&gR(Y)){const ee=(await A.providerAccounts()).accounts.find(fe=>fe.id===W.id);ee&&(await A.saveProviderAccount({id:ee.id,revision:ee.revision,label:ee.label,kind:ee.kind,auth:ee.auth,baseUrl:ee.baseUrl,defaultModel:q,enabled:ee.enabled}),Y=await A.testProviderAccount(W.id),Y.state==="connected"&&(F=q,X=!0))}if(Y.state!=="connected"){try{const ee=(await A.providerAccounts()).accounts.find(fe=>fe.id===W.id);ee&&await A.removeProviderAccount(W.id,ee.revision)}catch{}return m(Y.message),Y}const Q=await R({accountId:W.id,label:B,model:F,...X?{freeTier:X}:{}});return Q&&m(Q),Y}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 A.saveProviderAccount(H);let q;try{q=await A.testProviderAccount(B.id)}finally{try{const W=(await A.providerAccounts()).accounts.find(Y=>Y.id===B.id);W&&await A.removeProviderAccount(B.id,W.revision)}catch{}}return q.state!=="connected"&&m(q.message),q}catch(B){return m(B instanceof ve?B.message:String(B)),null}finally{g(!1)}},_=(H,B,q)=>{if(H.length<=1){I(B(H[0]??""),q);return}y({models:H,make:B,label:q})},$=H=>{if(H===o)return;C==null||C.close(),T((H==="free"||H==="chatgpt")&&typeof window.open=="function"?window.open("","_blank"):null),m(null),y(null),h("key"),c(H)},P=()=>{C==null||C.close(),T(null),y(null),m(null),c(null)},O=TI(v,j),M=["free",...k?["claude"]:[],...N?["chatgpt"]:[],"key","local"];let D=null;return w?D=n.jsxs(n.Fragment,{children:[n.jsx(it,{children:n.jsx(ht,{children:z.brain.model.ask})}),p?n.jsx(Vs,{line:z.brain.checking.service}):f?n.jsx(it,{children:n.jsx(ht,{children:f})}):null,n.jsx(OQ,{busy:p,models:w.models,onBack:P,onUse:H=>void I(w.make(H),w.label)})]}):o==="key"?D=n.jsxs(n.Fragment,{children:[n.jsx(Yt,{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(FQ,{busy:p,problem:f,preset:S,onBack:P,onUse:I},"gemini"):u==="service"?n.jsx(zQ,{busy:p,problem:f,address:(v==null?void 0:v.cloudBaseUrl)??"",onBack:P,onOffer:_,onTrial:L,onUse:I},"service"):n.jsx(LQ,{busy:p,problem:f,onBack:P,onUse:I},"key")]}):o==="local"?D=n.jsx(_Q,{busy:p,problem:f,probe:v,mlxh:j,onBack:P,onOffer:_,onUse:I}):o==="free"?D=n.jsx(BQ,{...e,busy:p,consent:C,onBack:P,onConnected:R}):o==="chatgpt"?D=n.jsx(KQ,{...e,busy:p,consent:C,onBack:P,onConnected:R}):o==="claude"&&(D=n.jsx(GQ,{...e,busy:p,problem:f,onBack:P,onConnected:R})),n.jsxs(n.Fragment,{children:[n.jsx(Xl,{children:z.brain.title}),n.jsx(it,{children:n.jsx(ht,{children:z.brain.ask})}),n.jsx("div",{className:"wiz-grid",role:"group","aria-label":z.brain.ask,children:M.map(H=>{const B=MQ[H],q=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:()=>$(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:q.title}),n.jsx("span",{className:"wiz-opt-line",children:H==="local"?O:q.line}),"pill"in q?n.jsx(we,{tone:"good",children:q.pill}):null]})]},H)})}),D,D===null&&s.brain?n.jsxs(it,{children:[n.jsx(ht,{children:s.brain.freeTier?z.brain.worksOnFlash(s.brain.model):z.brain.works(s.brain.model)}),n.jsx(WQ,{...e})]}):null,D===null?n.jsx(en,{actions:n.jsxs(n.Fragment,{children:[n.jsx(is,{onClick:l}),n.jsx(Ql,{onClick:()=>s.brain&&r(s),disabled:!s.brain,children:z.brain.submit})]})}):null]})}function OQ({busy:e,models:t,onBack:s,onUse:r}){const[i,a]=d.useState(t[0]??"");return n.jsx(en,{actions:n.jsxs(n.Fragment,{children:[n.jsx(is,{onClick:s,disabled:e}),n.jsx(E,{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 AI({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 LQ({busy:e,problem:t,onBack:s,onUse:r}){const i=Jl(),[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??SQ(a),y=()=>{const k=a.trim();k===""||j||(h(!0),b(!1),(async()=>{var T;let N=w==="anthropic"?"claude-sonnet-5":"gpt-5",S=f;if(x&&p!=="")N=p;else try{const R=await A.probeModels({kind:w,auth:"api-key",secret:k});N=((T=R.models.find(I=>I.isDefault))==null?void 0:T.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(cj(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(Vs,{line:z.brain.checking.key})}):v?n.jsx(it,{children:n.jsx(ht,{children:z.brain.key.refused})}):t?n.jsx(it,{children:n.jsx(ht,{children:t})}):null,n.jsxs(en,{actions:n.jsxs(n.Fragment,{children:[n.jsx(is,{onClick:s,disabled:j}),n.jsx(E,{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(AI,{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 FQ({busy:e,problem:t,preset:s,onBack:r,onUse:i}){const a=Jl(),[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=hR,w;if(v&&m!=="")x=m;else try{const k=(await A.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,secret:j})).models.map(N=>N.id);x=fR(k)??x,w=pR(x)?mR(k):void 0,f($G(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(Vs,{line:z.brain.checking.gemini})}):t?n.jsx(it,{children:n.jsx(ht,{children:t})}):null,n.jsxs(en,{actions:n.jsxs(n.Fragment,{children:[n.jsx(is,{onClick:r,disabled:g}),n.jsx(E,{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 TI(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 _Q({busy:e,problem:t,probe:s,mlxh:r,onBack:i,onOffer:a,onUse:l}){const o=(s==null?void 0:s.models)??[],c=Tx(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(Vs,{line:z.brain.checking.ollama})}):t?n.jsx(it,{children:n.jsx(ht,{children:t})}):null,n.jsx(en,{actions:n.jsxs(n.Fragment,{children:[n.jsx(is,{onClick:i,disabled:e}),s!=null&&s.running?n.jsx(E,{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(E,{variant:"accent",size:"lg",disabled:e||!c,onClick:u,children:z.brain.mlxh.connect}):null,h&&s?n.jsx(Et,{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:[TI(s,r),r!=null&&r.running&&!c?` ${z.brain.mlxh.noBrain}`:"",h&&(r!=null&&r.baseUrl)?` ${B$(r.baseUrl)}`:""]})})]})}function zQ({busy:e,problem:t,address:s,onBack:r,onOffer:i,onTrial:a,onUse:l}){const o=Jl(),[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 P;const S=h.trim()?"api-key":"none",C=O=>({label:z.brain.service.label,kind:"openai-compatible",auth:S,baseUrl:c.trim(),defaultModel:O,enabled:!0,...h.trim()?{secret:h.trim()}:{}}),T=(O,M,D)=>{if(!(!O||O.state==="connected")){if(cj(O)){w(!0),v([]);return}v(M),j(D)}};if(S==="api-key"&&k&&b!==""){p(!1),T(await l(C(b),z.brain.service.label),g,b);return}let R=[],I;try{const O=await A.probeModels({kind:"openai-compatible",auth:S,baseUrl:c.trim(),...h.trim()?{secret:h.trim()}:{}});R=O.models.map(M=>M.id),I=(P=O.models.find(M=>M.isDefault))==null?void 0:P.id}catch{}p(!1);const L=I?[I]:R;if(S==="none"){i(L,C,z.brain.service.label);return}const _=L[0]??"";if(L.length<=1){T(await l(C(_),z.brain.service.label),R,_);return}const $=await a(C(_));($==null?void 0:$.state)==="connected"?i(L,C,z.brain.service.label):T($,R,_)})())};return n.jsxs(n.Fragment,{children:[y?n.jsx(it,{children:n.jsx(Vs,{line:z.brain.checking.service})}):x?n.jsx(it,{children:n.jsx(ht,{children:z.brain.key.refused})}):t?n.jsx(it,{children:n.jsx(ht,{children:t})}):null,n.jsxs(en,{actions:n.jsxs(n.Fragment,{children:[n.jsx(is,{onClick:r,disabled:y}),n.jsx(E,{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(AI,{models:g,picked:b,disabled:y,onPick:j}):null]})]})}const UQ=2e3;function BQ({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 A.saveProviderAccount({label:v,kind:"openai-compatible",auth:"device-key",baseUrl:"",defaultModel:cd,enabled:!0}),y=(await A.providerAccounts()).accounts.find(N=>N.id===w.id),k=await A.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 A.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(),UQ);return()=>{j=!0,window.clearInterval(y)}},[u]);const b=async j=>{try{const x=(await A.accountModels(j).catch(()=>({models:[]}))).models.map(N=>N.id),w=x.length===0||x.includes(cd)?cd:x[0],y=(await A.providerAccounts()).accounts.find(N=>N.id===j);y&&y.defaultModel!==w&&await A.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 A.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(Vs,{line:z.brain.checking.cloud})}):o?n.jsx(it,{children:n.jsx(ht,{children:o})}):u?n.jsx(it,{children:n.jsx(ht,{children:z.brain.cloud.waiting})}):null,n.jsx(en,{actions:n.jsxs(n.Fragment,{children:[n.jsx(is,{onClick:s,disabled:a||e}),u?n.jsx(Et,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",children:z.brain.cloud.open}):o?n.jsx(E,{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 WQ({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=Ew(a),f=(a==null?void 0:a.auth)==="device-key"||(a==null?void 0:a.kind)==="codex"||h||!!a&&xR(a,(p=t==null?void 0:t.gemini)==null?void 0:p.baseUrl);if(d.useEffect(()=>{if(!f||!a)return;let g=!1;return A.accountModels(a.id).then(v=>{const b=h?v.models.filter(j=>!U$({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 A.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 A.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(ht,{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 AN="gpt-5.5",HQ=2e3;function KQ({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&&A.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 A.saveProviderAccount({label:b,kind:"codex",auth:"chatgpt",baseUrl:"",defaultModel:AN,enabled:!0}),N=(await A.providerAccounts()).accounts.find(C=>C.id===k.id),S=await A.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 A.providerAccounts()).accounts.find(T=>T.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(),HQ);return()=>{w=!0,window.clearInterval(N)}},[u]);const j=async w=>{var y,k;try{const N=(await A.accountModels(w).catch(()=>({models:[]}))).models,S=((y=N.find(T=>T.isDefault))==null?void 0:y.id)??((k=N[0])==null?void 0:k.id)??AN,C=(await A.providerAccounts()).accounts.find(T=>T.id===w);return C&&C.defaultModel!==S&&await A.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&&A.codexAccountAction(w.id,"cancel-login",w.revision).catch(()=>{}),s()};return n.jsxs(n.Fragment,{children:[a||e?n.jsx(it,{children:n.jsx(Vs,{line:z.brain.checking.chatgpt})}):o?n.jsx(it,{children:n.jsx(ht,{children:o})}):u?n.jsx(it,{children:n.jsxs(ht,{children:[z.brain.chatgpt.codeBefore,n.jsx("strong",{children:u.code}),z.brain.chatgpt.codeAfter]})}):null,n.jsx(en,{actions:n.jsxs(n.Fragment,{children:[n.jsx(is,{onClick:x,disabled:a||e}),u?n.jsx(Et,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",children:z.brain.chatgpt.open}):o?n.jsx(E,{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(Tw,{code:u.code,label:z.brain.chatgpt.code}):null})]})}const VQ="claude-sonnet-5";function GQ({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&&A.anthropicAccountAction(w.id,"cancel-login",w.revision).catch(()=>{})},[]);const v=()=>{const w=g.current;g.current=null,w&&A.anthropicAccountAction(w.id,"cancel-login",w.revision).catch(()=>{}),s()},b=a??VQ,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(T=>T.auth==="anthropic-oauth"),k=y?{id:y.id}:await A.saveProviderAccount({label:z.brain.claude.label,kind:"anthropic",auth:"anthropic-oauth",baseUrl:"",defaultModel:b,enabled:!0}),S=(await A.providerAccounts()).accounts.find(T=>T.id===k.id),C=await A.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 A.anthropicAccountAction(h.id,"complete-login",h.revision,{attemptId:h.attemptId,code:m.trim()});const w=await A.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(Vs,{line:z.brain.checking.claude})}):t??c?n.jsx(it,{children:n.jsx(ht,{children:t??c})}):null,h?n.jsxs(n.Fragment,{children:[n.jsx(it,{children:n.jsx(ht,{children:z.brain.claude.waiting})}),n.jsx(en,{actions:n.jsxs(n.Fragment,{children:[n.jsx(is,{onClick:v,disabled:l}),n.jsx(Et,{size:"lg",href:h.url,target:"_blank",rel:"noreferrer",children:z.brain.claude.open}),n.jsx(E,{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(YQ,{value:m,onChange:p})})})]}):n.jsx(en,{actions:n.jsxs(n.Fragment,{children:[n.jsx(is,{onClick:v,disabled:e||l}),n.jsx(E,{variant:"accent",size:"lg",disabled:e||l,onClick:j,children:z.brain.claude.start})]})})]})}function YQ({value:e,onChange:t}){const s=Jl();return n.jsx("input",{ref:s,type:"password",autoComplete:"off",spellCheck:!1,value:e,onChange:r=>t(r.target.value)})}const qQ={days:"calendar",mail:"mail",money:"money",voice:"bulb",code:"monitor",pictures:"files"};function JQ(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 QQ({answers:e,progress:t,onProgress:s,onSettled:r,onBack:i,onTrouble:a}){const[l,o]=d.useState(()=>e.takeOn??[...qz]),[c,u]=d.useState(!1),h=Oo.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(()=>A.takeOn(g)).then(()=>{s(),r({...e,takeOn:g})}).catch(v=>a(v instanceof ve?v.message:String(v))).finally(()=>u(!1)))},p=JQ(t);return n.jsxs(n.Fragment,{children:[n.jsx(Xl,{children:z.takeOn.title}),n.jsx(it,{children:n.jsx(ht,{children:z.takeOn.ask})}),n.jsxs(en,{actions:n.jsxs(n.Fragment,{children:[n.jsx(is,{onClick:i,disabled:c}),n.jsx(E,{variant:"ghost",size:"lg",disabled:c,onClick:()=>m([]),children:z.takeOn.none}),n.jsx(Ql,{onClick:()=>m(Oo.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:Oo.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:qQ[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 XQ({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(()=>A.onboardingStep("browser")).catch(()=>{}),s({...e,reach:j,...h!==void 0?{browser:h}:{}})};return n.jsxs(n.Fragment,{children:[n.jsx(Xl,{children:z.reach.title}),n.jsx(it,{children:n.jsx(ht,{children:z.reach.ask})}),n.jsx(en,{actions:n.jsxs(n.Fragment,{children:[n.jsx(is,{onClick:r}),n.jsx(Ql,{onClick:p,children:z.reach.submit})]}),children:n.jsxs("div",{className:"wiz-rows",children:[n.jsx(ZQ,{paired:i,onPaired:()=>a(!0)}),n.jsx(tX,{wanted:m,added:l,onAdded:o,navigate:t,timezone:e.clock??"UTC"}),n.jsx(nX,{app:c,onApp:()=>u(!0),browser:h,onBrowser:f}),i?n.jsx(V,{tone:"good",role:"status",children:z.reach.phone.hello}):null]})})]})}function ZQ({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(()=>A.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(eX,{onPaired:t}):n.jsx("span",{className:"wiz-row-side",children:n.jsx(E,{size:"lg",disabled:s===null,onClick:()=>a(!0),children:z.reach.phone.setUp})}),i?n.jsx(qe,{title:z.telegram.sheet,onClose:()=>a(!1),children:n.jsx(oX,{onPaired:t,onDismiss:()=>a(!1)})}):null]})}function eX({onPaired:e}){const{offer:t,square:s,paired:r,stale:i,ask:a}=Qw(()=>A.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(E,{size:"lg",onClick:()=>void a().catch(()=>{}),children:z.telegram.newCode})}):n.jsx("span",{className:"wiz-qr-slot",children:n.jsx(Xw,{offer:t,square:s})})}function tX({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(()=>A.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(()=>A.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(E,{size:"lg",onClick:()=>c(!0),children:z.reach.mailbox.add}):null}),o&&a?n.jsx(qe,{title:z.reach.mailbox.sheet,size:"wide",onClose:()=>{c(!1),f()},children:n.jsx(cw,{page:a.page,siblings:a.siblings,navigate:r,timezone:i,embedded:!0})}):null]})}function nX({app:e,onApp:t,browser:s,onBrowser:r}){const i=kf(),a=typeof navigator>"u"?null:ZT(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(()=>A.browser()).then(C=>{var R;if(!j.current)return;const T=C==null?void 0:C.browser;T?((R=T.install)==null?void 0:R.state)==="running"?(o("none"),b.current=!0,u("installing"),y()):o(T.engine):o("other")}).catch(()=>{j.current&&o("other")}),()=>{j.current=!1}),[]);const x=(C,T)=>{j.current&&(b.current=!1,u("failed"),f(C),p(T??null))},w=async C=>{u("launching");let T;try{T=await A.browserCheck()}catch(R){return x(R instanceof ve?R.message:String(R))}if(j.current){if(T.ok){u("idle"),o(C),r(b.current?"installed":C);return}x(T.message,T.command)}},y=async()=>{var R,I;let C;try{C=await A.browser()}catch(L){return x(L instanceof ve?L.message:String(L))}if(!j.current)return;const T=C.browser;if(!T)return x(z.browser.failed(""));if(((R=T.install)==null?void 0:R.state)==="running"){u("installing"),v(T.install.progress),window.setTimeout(()=>void y(),1e3);return}return T.engine!=="none"?w(T.engine):x(((I=T.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(()=>A.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(E,{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(E,{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(fT,{progress:g})]}):c==="launching"?n.jsx("div",{className:"wiz-row-more",children:n.jsx(Vs,{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(iX,{command:m}):null]}):null]})}function sX({answers:e,existing:t,onSettled:s,onTrouble:r,onReload:i,onBack:a}){const[l,o]=d.useState(()=>(t==null?void 0:t.name)??Bz),[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 A.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=Oo.filter(w=>(e.takeOn??[]).includes(w.id)&&"mate"in w).map(w=>w.mate),j=Tk.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?A.updateFirstAgent({name:l.trim(),...w}):A.createFirstAgent({name:l.trim(),handle:CQ(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 A.uploadAgentPicture(k.id,await eR(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(Xl,{children:z.assistant.title}),n.jsx(it,{children:n.jsxs(ht,{children:[z.assistant.ask,b.length>0?z.assistant.team(b):""]})}),n.jsx(en,{actions:n.jsxs(n.Fragment,{children:[n.jsx(is,{onClick:a,disabled:g}),n.jsx(Ql,{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:wa(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:Tk.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 rX({answers:e,assistantAgent:t,met:s,onMet:r,navigate:i,onPickAnotherBrain:a,onSpoken:l,progress:o,onProgress:c}){var P,O;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 M=!1;return(async()=>{try{const D=await He.startConversation(u.id);if(M)return;f(D.conversationId),r(D.conversationId),await A.onboardingStep(bI.handover,{conversationId:D.conversationId}).catch(()=>{}),await He.send(u.id,{conversationId:D.conversationId,text:Vz,opening:!0})}catch{M||(w(!1),v(!0))}})(),()=>{M=!0}},[u==null?void 0:u.id,s]),d.useEffect(()=>{if(!h)return;let M=!1;const D=Date.now(),H=()=>{He.conversation(h).then(q=>{if(M)return;p(q.messages);const W=Date.now()-D;if(q.messages.some(TN)){w(!1),v(!1),j(!1);return}const Y=q.runs??[],F=Y.some(Q=>Q.finishedAt===null),X=Y.length>0&&!F;j(F&&W>=EQ),(X||W>=AQ)&&(w(!1),v(!0))}).catch(()=>{})};H();const B=window.setInterval(H,EI);return()=>{M=!0,window.clearInterval(B)}},[h]);const C=u&&h?st(u.id,h):null,T=m.some(TN);d.useEffect(()=>{T&&C&&l(C)},[T,C,l]);const R=e.takeOn??[],I=z.handover.starters({days:R.includes("days"),mail:R.includes("mail"),mailbox:((P=e.reach)==null?void 0:P.mailbox)===!0}),L={days:R.includes("days"),mailbox:((O=e.reach)==null?void 0:O.mailbox)===!0,money:R.includes("money"),pictures:R.includes("pictures")},_=(o==null?void 0:o.waiting)??[],$=M=>{!u||!h||y||(k(!0),Promise.resolve().then(()=>He.send(u.id,{conversationId:h,text:M})).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(qj,{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(ht,{children:z.handover.slow})}):null,g?n.jsxs(n.Fragment,{children:[n.jsx(it,{children:n.jsx(ht,{children:z.handover.silent})}),n.jsx(en,{actions:n.jsx(Ql,{onClick:a,children:z.handover.again})})]}):null,T?n.jsx("div",{className:"wiz-starters",role:"group","aria-label":z.handover.starterLabel,children:I.map(M=>n.jsx("button",{type:"button",className:"wiz-starter",disabled:y,onClick:()=>$(M),children:M},M))}):null,T?n.jsx(F7,{setUp:L,navigate:M=>i(M,!0)}):null,T&&_.length>0?n.jsx(V,{tone:"warm",title:z.handover.waitingTitle(_.length),action:n.jsx(E,{variant:"accent",onClick:()=>i(un,!0),children:z.handover.home}),children:z.handover.waitingBody(_)}):null,T&&C?n.jsx(en,{actions:n.jsx(Et,{variant:"accent",size:"lg",href:C,onClick:M=>{M.preventDefault(),i(C,!0)},children:z.done.open})}):null]})}function iX({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(E,{size:"sm",onClick:r,children:t==="done"?"Copied":"Copy"})]})]})}function TN(e){return e.role==="assistant"&&(e.blocks??[]).some(t=>t.type==="text"&&t.text.trim()!=="")}function aX({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),A.firstRunRestore(r,a.trim()).then(h=>{Gx(h.job.id),t()}).catch(h=>s(h instanceof ve?h.message:String(h))).finally(()=>c(!1)))};return n.jsx(qe,{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(E,{variant:"ghost",onClick:e,children:z.restore.cancel}),n.jsx(E,{variant:"accent",disabled:o||!r,onClick:u,children:z.restore.submit})]})]})})}function lX({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=CI();if(!l)return;let o=!1;const c=()=>{A.backupJob(l).then(h=>{o||(r(f=>f.includes(h.phase)?f:[...f,h.phase]),h.phase==="done"?(o=!0,Gx(null),A.owner().then(f=>i.current.onDone(f.preferredName??void 0),()=>i.current.onDone(void 0))):(h.phase==="rolled-back"||h.phase==="failed")&&(o=!0,Gx(null),i.current.onFailed(h.error??z.restore.phases[h.phase])))}).catch(()=>{})};c();const u=window.setInterval(c,EI);return()=>{o=!0,window.clearInterval(u)}},[]);const a=s.filter(l=>l in z.restore.phases);return n.jsxs(n.Fragment,{children:[n.jsx(Xl,{children:z.restore.title}),n.jsxs(it,{children:[n.jsx(ht,{children:z.restore.started}),a.map(l=>n.jsx(ht,{children:z.restore.phases[l]},l))]}),n.jsx(Vs,{})]})}function oX(e){return n.jsx(ey.Provider,{value:null,children:n.jsx("div",{className:"wiz-sheet-body",children:n.jsx(cX,{...e})})})}function cX({onPaired:e,onDismiss:t}){const s=Jl(),[r,i]=d.useState(""),[a,l]=d.useState(!1),[o,c]=d.useState(null),{offer:u,square:h,paired:f,stale:m,ask:p}=Qw(()=>A.telegram().then(b=>b.paired),e),g=()=>{r.trim()===""||a||(l(!0),c(null),(async()=>{try{const b=await A.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(ht,{children:z.telegram.paired})}),n.jsx(en,{actions:n.jsx(E,{variant:"accent",onClick:t,children:z.telegram.close})})]}):u?n.jsxs(n.Fragment,{children:[n.jsx(it,{children:n.jsx(ht,{children:m?z.telegram.expired:z.telegram.scan})}),n.jsx(en,{actions:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:t,children:z.telegram.notNow}),m?n.jsx(E,{variant:"accent",onClick:v,children:z.telegram.newCode}):null]}),children:m?null:n.jsx(Xw,{offer:u,square:h})})]}):n.jsxs(n.Fragment,{children:[n.jsxs(it,{children:[n.jsx(ht,{children:z.telegram.how}),o?n.jsx(ht,{children:o}):null]}),n.jsx(en,{actions:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"ghost",onClick:t,children:z.telegram.notNow}),n.jsx(E,{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 xp={recovery:0,lost:1,paused:2},uX="Lost buddi. Retrying…",dX="The queue is paused. Nothing is being claimed until you resume it.";function hX(e){const t=[];return e.recovery&&t.push({id:"recovery",priority:xp.recovery,tone:"warning",text:iR,action:{label:"Finish the checklist",href:zg}}),e.lost&&t.push({id:"lost",priority:xp.lost,tone:"critical",text:uX}),e.paused&&t.push({id:"paused",priority:xp.paused,tone:"warning",text:dX,action:{label:"Resume",onClick:()=>{A.setPaused(!1).catch(()=>{})}}}),t}function fX({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(Et,{size:"sm",href:a.href,onClick:l=>{l.preventDefault(),t(a.href)},children:a.label}):a?n.jsx(E,{size:"sm",onClick:a.onClick,children:a.label}):null]})}const $I=1e4,mX=3e4,RI=6e3,ty=/^(localhost|127(?:\.\d{1,3}){3}|\[?::1\]?)$|\.localhost$/i;function pX(e){return ty.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 II(e){let t;const s=new Promise((r,i)=>{t=setTimeout(()=>i(new ve(0,qd)),e)});try{return{up:!0,version:await Promise.race([A.version(),s])}}catch(r){return Jd(r)?{up:!1}:{up:!0}}finally{clearTimeout(t)}}function PI(e){var t;return e.up&&Tj((t=e.version)==null?void 0:t.web)?(window.location.reload(),!1):e.up}function gX({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:wa("core"),alt:""})}),n.jsxs("h1",{children:["buddi isn't answering at ",e,"."]}),n.jsx("p",{children:pX(e.replace(/:\d+$/,""))}),n.jsx("div",{className:"unreachable-actions",children:n.jsx(E,{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 II(RI);a.current=!1,i(!1),s(c=>c==="checking"?o.up?"up":"down":PI(o)?"up":"down")},[]);return d.useEffect(()=>{l()},[l]),d.useEffect(()=>{if(t!=="down")return;const o=window.setInterval(()=>void l(),$I);return()=>window.clearInterval(o)},[t,l]),t==="checking"?null:t==="down"?n.jsx(gX,{host:window.location.host,onRetry:()=>void l(),retrying:r}):n.jsx(n.Fragment,{children:e})}function vX(e=mX){const[t,s]=d.useState(!1);return d.useEffect(()=>{let r;const i=()=>{clearTimeout(r);const l=mc();if(l===null)return s(!1);const o=l+e-Date.now();o<=0?s(!0):r=setTimeout(i,o)};i();const a=oj(i);return()=>{a(),clearTimeout(r)}},[e]),t}function jX(){const e=vX();return d.useEffect(()=>{if(!e)return;const t=window.setInterval(()=>{II(RI).then(PI)},$I);return()=>window.clearInterval(t)},[e]),e}const wX={local:"Local",tailnet:"Tailnet",reconnecting:"Reconnecting…"},$N=(e,t,s=`${t}s`)=>e===1?t:s;function yX(){return Intl.DateTimeFormat().resolvedOptions().timeZone}function bX(e){return e.includes("/")?e.split("/").pop().replace(/_/g," "):e}function kX(e,t){return t?"reconnecting":ty.test(e)?"local":"tailnet"}function MI(e,t,s=yX()){const r=[],i=wX[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=`${Zi[e.focus.mode]} ${Sc(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} ${$N(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?`${jt}/jobs?state=failed`:`${jt}/jobs`,parts:a,label:`Work: ${a.map(u=>u.text).join(", ")}`}),e.approvals>0){const u=`${$N(e.approvals,"approval")} waiting`;r.push({key:"approvals",route:jl,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:bX(l)}:{},label:`Your time: ${o}${c?`, ${l}`:""}`}),r}function NX(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 DI(){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 SX(){const[e,t]=d.useState(()=>mc()!==null);return d.useEffect(()=>oj(()=>t(mc()!==null)),[]),e}function OI({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 CX({status:e,onNavigate:t}){const s=DI(),r=Nf(),i=MI(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(OI,{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 EX({status:e,onNavigate:t}){const s=DI(),r=Nf(),i=NX(e);return n.jsx("div",{className:"rail-status",children:n.jsxs(_c,{modal:!1,children:[n.jsx(zc,{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(zl,{children:n.jsxs(Uc,{className:"ui-menu rail-status-menu",side:"right",align:"end",sideOffset:10,children:[n.jsx(da,{className:"ui-menu-label",children:"Status"}),MI(e,s).map(a=>n.jsx(vs,{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(OI,{item:a})})})},a.key)),r.pin?n.jsxs(n.Fragment,{children:[n.jsx(Ir,{className:"ui-menu-sep"}),n.jsx(vs,{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 AX=1e4;function LI(){return d.useSyncExternalStore(mz,Ck,Ck)}function TX(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 RN(e){const t=Math.max(0,Math.floor(e/1e3));return`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`}function $X({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(E,{size:"sm",onClick:()=>{var r;(r=navigator.clipboard)==null||r.writeText(e).then(()=>s(!0),()=>{})},children:t?"Copied":"Copy"})]})}function RX({state:e,elapsedMs:t,hostname:s=window.location.hostname,onReload:r=()=>ll.reload()}){const i=TX(e),a=e.kind==="stop",l=!a&&t>=(e.patienceMs??cz),o=ty.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(Vc,{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($X,{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?`${RN(t)} · still checking every few seconds`:t>=AX?`${RN(t)} · this page reloads when buddi is back`:"This page reloads when buddi is back."}),a||l?n.jsx(E,{size:"sm",variant:l?"accent":void 0,onClick:r,children:"Reload"}):null]})]})})})}function IX(e){const[t,s]=d.useState(()=>ll.now());return d.useEffect(()=>{if(!e)return;s(ll.now());const r=window.setInterval(()=>s(ll.now()),1e3);return()=>window.clearInterval(r)},[e]),e?Math.max(0,t-e.startedAt):0}function PX({children:e}){const t=LI(),s=IX(t),r=d.useRef(null);return d.useEffect(()=>{gz();let i=mc()!==null;const a=oj(()=>{const o=mc()!==null;i&&!o&&Ek(),i=o}),l=()=>void Ek();return window.addEventListener(xc,l),()=>{a(),window.removeEventListener(xc,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(RX,{state:t,elapsedMs:s}):null]})}const MX="(max-width: 1080px)",DX="(max-width: 720px)";function OX(){const[e,t]=d.useState(()=>window.location.hash||un);d.useEffect(()=>{const r=()=>t(window.location.hash||un);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 LX(){const[e,t]=w$();d.useEffect(()=>{j$(e)},[e]);const s=d.useCallback(r=>t({theme:r}),[t]);return[e.theme,s]}const IN=new Map;function FX(){var As,Nn,Ts,$s;const[e,t]=OX(),[s,r]=d.useState("UTC"),[i,a]=d.useState({approvals:0,failed:0,paused:!1,running:0,needs:0}),[l,o]=LX(),c=ks(Lj),[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),[T,R]=d.useState(0),[I,L]=d.useState(null),_=Nz(),$=f.find(ke=>ke.id===p)??null,P=$!==null&&M8(e),[O,M]=d.useState(!1),D=d.useCallback(()=>M(!0),[]);d.useEffect(()=>{P||M(!1)},[P]),KK(t,hd(e)===null,P?D:void 0);const H=ks(MX),B=rR(),q=HA(),W=m$(),Y=de(()=>Promise.resolve().then(()=>A.version()),[],X4),F=Y.data;lz(Y.reload);const X=F&&!F.checkout&&F.updateAvailable?F:null,Q=Tj(F==null?void 0:F.web);oz(F==null?void 0:F.web);const ee=((As=de(()=>Promise.resolve().then(()=>A.connectionSignals()),[],6e4).data)==null?void 0:As.signals)??[],[fe,Oe]=d.useState(null),Ie=d.useMemo(()=>new Set(fe?[fe]:[]),[fe]),[Fe,U]=d.useState(new Map);d.useEffect(()=>{const ke=()=>{A.conversations().then(We=>{const me=new Map;for(const qn of We.conversations){const On=qn.lastMessageAt??qn.createdAt,Gs=me.get(qn.agentId);(!Gs||On>Gs)&&me.set(qn.agentId,On)}U(me)}).catch(()=>{})};ke();const Ee=window.setInterval(ke,3e4);return()=>window.clearInterval(Ee)},[e]);const[se,J]=d.useState(!1);d.useEffect(()=>{if(se)return;let ke=!1;return A.onboarding().then(Ee=>{ke||(J(!0),Ee.state==="pending"&&Ee.needs.model&&!hd(window.location.hash)&&t(g4,!0))}).catch(()=>{ke||J(!0)}),()=>{ke=!0}},[se,t]),d.useEffect(()=>{const ke=_4(e);ke&&t(ke,!0)},[e,t]),d.useEffect(()=>{let ke=!1;const Ee=()=>{He.agents().then(me=>{ke||(m(me.agents),V4(me.defaultAgentId??null),g(me.defaultAgentId??null),b(qn=>{var On;return qn??me.defaultAgentId??((On=me.agents[0])==null?void 0:On.id)??null}))}).catch(()=>{})};Ee();const We=window.setInterval(Ee,15e3);return window.addEventListener("focus",Ee),window.addEventListener(hr,Ee),()=>{ke=!0,window.clearInterval(We),window.removeEventListener("focus",Ee),window.removeEventListener(hr,Ee)}},[e]),d.useEffect(()=>{let ke=!1;const Ee=()=>{He.groups().then(me=>{ke||x(me.groups)}).catch(()=>{})};Ee();const We=window.setInterval(Ee,3e4);return()=>{ke=!0,window.clearInterval(We)}},[e]);const ye=uA(f,p),ge=v4(e),$e=XE(e),De=$e?j.find(ke=>ke.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 ze=d.useRef(null);ge&&(ze.current=e);const Se=ke=>{b(ke),t(st(ke))},Ue=ke=>t(Vi(ke)),at=d.useCallback((ke,Ee,We=!0)=>t($e?Vi($e.groupId,Ee):st(ke,Ee),We),[t,$e==null?void 0:$e.groupId]),[Ye,kt]=d.useState(!1),[,qt]=d.useState(0);d.useEffect(()=>{const ke=()=>{qt(Ee=>Ee+1),A.session().then(Ee=>r(Ee.timezone)).catch(()=>{})};return window.addEventListener(kg,ke),()=>window.removeEventListener(kg,ke)},[]),d.useEffect(()=>{A.session().then(ke=>{ij({timeFormat:ke.timeFormat??null,dateFormat:ke.dateFormat??null}),r(ke.timezone),kt(!0)}).catch(()=>{})},[]);const re=W8(Ye);Y8(Ye,re.refresh,()=>kt(!1)),d.useEffect(()=>{const ke=()=>{A.overview().then(We=>{var me;return a({approvals:We.approvals.pending,failed:We.jobs.failed??0,paused:We.paused,running:We.running??0,needs:((me=We.needsYou)==null?void 0:me.total)??We.approvals.pending+(We.jobs.failed??0)})}).catch(()=>{})};ke();const Ee=window.setInterval(ke,2e4);return window.addEventListener(Xi,ke),()=>{window.clearInterval(Ee),window.removeEventListener(Xi,ke)}},[]);const be=de(()=>Promise.resolve().then(()=>A.focus()),[],6e4),Qe=d.useRef(be.reload);Qe.current=be.reload,d.useEffect(()=>{const ke=()=>Qe.current();return window.addEventListener(Xi,ke),()=>window.removeEventListener(Xi,ke)},[]);const ct=SX(),yt=jX(),ut=LI()!==null,pn=ks(DX);d.useEffect(()=>{if(!Ye)return;if(e===z4){y(!0),t(xi,!0);return}const ke=U4(e),Ee=new Date().toDateString();!ke||IN.get(ke)===Ee||(IN.set(ke,Ee),A.tipsSeenPage(ke).catch(()=>{}))},[e,Ye,t]);const Yn={link:kX(window.location.hostname,ct&&!ut),focus:((Nn=be.data)==null?void 0:Nn.focus)??null,working:i.running,paused:i.paused,failed:i.failed,approvals:i.approvals,version:F?{current:F.current,latest:F.latest,updateAvailable:!F.checkout&&F.updateAvailable}:void 0,timezone:s},Z=hX({recovery:((Ts=B.data)==null?void 0:Ts.active)===!0,lost:yt&&!ut,paused:i.paused}),Re=hd(e),Xe=rA(e),xt=Xe===xi,G=k?j.find(ke=>ke.id===k.groupId)??null:null,he=ke=>x(Ee=>Ee.map(We=>We.id===ke.id?ke:We)),Be=()=>N(null),_e=w?n.jsx(q8,{agents:f,onClose:()=>y(!1),onCreated:ke=>{x(Ee=>[...Ee,ke]),y(!1),t(Vi(ke.id))}}):G&&(k==null?void 0:k.kind)==="members"?n.jsx(y8,{group:G,agents:f,onClose:Be,onSaved:he}):G&&(k==null?void 0:k.kind)==="rename"?n.jsx(b8,{group:G,onClose:Be,onSaved:ke=>{he(ke),Be()}}):G&&(k==null?void 0:k.kind)==="clear"?n.jsx(N8,{group:G,onClose:Be,onCleared:()=>{Be(),R(ke=>ke+1),t(Vi(G.id),!0)}}):G&&(k==null?void 0:k.kind)==="delete"?n.jsx(S8,{group:G,agents:f,onClose:Be,onDeleted:ke=>{const Ee=j.findIndex(We=>We.id===G.id);Be(),x(We=>We.filter(me=>me.id!==G.id)),C({group:G,index:Ee,until:ke}),t(ze.current??xi)}}):null,nn=()=>{const ke=S;ke&&(C(null),He.restoreGroup(ke.group.id).then(Ee=>{x(We=>{if(We.some(qn=>qn.id===Ee.id))return We;const me=[...We];return me.splice(Math.min(Math.max(ke.index,0),me.length),0,Ee),me}),t(Vi(Ee.id))}).catch(()=>L(ke.group.name)))};return Re?n.jsx(rk,{delayDuration:400,children:n.jsxs(Kb,{swipeDirection:"right",children:[n.jsx(IQ,{navigate:t,timezone:s}),n.jsx(Vb,{className:"ui-toasts"})]})}):n.jsx(Zz,{picture:($s=f.find(ke=>ke.id===p))==null?void 0:$s.picture,children:n.jsx(rk,{delayDuration:400,children:n.jsxs(Kb,{swipeDirection:"right",children:[_e,n.jsxs("div",{className:"wb-shell",children:[n.jsx(fX,{banners:Z,onNavigate:t}),n.jsxs("div",{className:"wb",children:[n.jsx(PK,{attention:i.needs,place:Xe,onNavigate:t,theme:l,onTheme:o,plugins:WK(q.rail,W),updateAvailable:X!==null,settingsDot:ee.length>0?f$:void 0,stale:Q,timezone:s,version:F&&!F.checkout?{current:F.current,latest:F.latest,updateAvailable:F.updateAvailable}:F?{current:F.current,updateAvailable:!1}:void 0,status:pn?n.jsx(EX,{status:Yn,onNavigate:t}):void 0}),xt&&!H?n.jsx(pA,{agents:ye,currentId:Je,attention:_,onSelect:Se,lastActivity:Fe,working:Ie,groups:j,currentGroupId:(De==null?void 0:De.id)??null,onSelectGroup:Ue,onNewGroup:()=>y(!0)}):null,xt?n.jsx(C8,{timezone:s,agents:ye,agentId:De?De.coordinator:Je,defaultAgentId:p,group:De,...De?{onGroupAction:ke=>N({kind:ke,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:Se,onWorking:Oe,attention:_,agentsInHeader:H,narrow:c,canvasOpen:u,onOpenCanvas:()=>h(!0),onCloseCanvas:()=>h(!1)},`room-${T}`):n.jsx("main",{"data-ground":_X(Xe,e)?"plain":void 0,"data-layout":Xe===an?"split":void 0,children:n.jsx(zX,{hash:e,place:Xe,timezone:s,navigate:t,agents:f,defaultAgentId:p,attention:_,pluginPages:q,update:X,connectionSignals:ee})})]}),pn?null:n.jsx(CX,{status:Yn,onNavigate:t})]}),P&&$?n.jsx(D8,{agent:$,agents:f,open:O,onOpenChange:M,navigate:t}):null,n.jsxs(U8,{placement:z8(P,O),children:[n.jsx(H8,{queue:re.queue,agents:f,navigate:t,onDismiss:re.dismiss}),S?n.jsx(uh,{title:`Deleted ${S.group.name}`,body:"Its history goes for good in a few seconds.",duration:Q8,onUndo:nn,onGone:()=>C(null)},S.group.id):null,I?n.jsx(uh,{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(Vb,{className:"ui-toasts"})]})]})})})}function _X(e,t){return Nj(t)!==null}function zX({place:e,pluginPages:t,...s}){const r={...s,pluginPages:t},i=Nj(s.hash);if(i){const a=t.find(i.plugin,i.page);if(a)return n.jsx(cw,{page:a,item:i.item??null,params:eA(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 ft:return n.jsx(b7,{...r});case jt:return n.jsx(uV,{...s});case an:return n.jsx(tQ,{...r});case Kr:return n.jsx(uH,{...s});default:return n.jsx(Z7,{...r})}}function UX(){"serviceWorker"in navigator&&window.addEventListener("load",()=>{const e=`./sw.js?v=${encodeURIComponent(Aj)}`;navigator.serviceWorker.register(e,{scope:"./"}).catch(()=>{})})}function BX({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;A.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(J$);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(Et,{href:"/#/settings/connections",children:"Back to Connections"}):null]})})}const PN=document.getElementById("root");PN&&VC(PN).render(n.jsx(d.StrictMode,{children:location.pathname==="/connections/callback"?n.jsx(BX,{}):n.jsx(PX,{children:n.jsx(xX,{children:n.jsx(IK,{children:n.jsx(FX,{})})})})}));UX();export{HX as c,eP as g};