@withbuddi/buddi 0.1.0-pre.53 → 0.1.0-pre.54

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 (439) hide show
  1. package/extension/background.js +38 -7
  2. package/extension/manifest.json +2 -2
  3. package/extension/popup.html +2 -2
  4. package/node_modules/@buddi/cli/dist/.tsbuildinfo +1 -1
  5. package/node_modules/@buddi/cli/dist/dashboard-cmd.d.ts.map +1 -1
  6. package/node_modules/@buddi/cli/dist/dashboard-cmd.js +6 -3
  7. package/node_modules/@buddi/cli/dist/dashboard-cmd.js.map +1 -1
  8. package/node_modules/@buddi/cli/dist/main.js +2 -2
  9. package/node_modules/@buddi/cli/dist/main.js.map +1 -1
  10. package/node_modules/@buddi/cli/dist/status.d.ts +16 -2
  11. package/node_modules/@buddi/cli/dist/status.d.ts.map +1 -1
  12. package/node_modules/@buddi/cli/dist/status.js +42 -2
  13. package/node_modules/@buddi/cli/dist/status.js.map +1 -1
  14. package/node_modules/@buddi/core/dist/.tsbuildinfo +1 -1
  15. package/node_modules/@buddi/core/dist/agents/catalog.d.ts +6 -0
  16. package/node_modules/@buddi/core/dist/agents/catalog.d.ts.map +1 -1
  17. package/node_modules/@buddi/core/dist/agents/catalog.js +1 -1
  18. package/node_modules/@buddi/core/dist/agents/catalog.js.map +1 -1
  19. package/node_modules/@buddi/core/dist/backup/archive.d.ts +6 -0
  20. package/node_modules/@buddi/core/dist/backup/archive.d.ts.map +1 -1
  21. package/node_modules/@buddi/core/dist/backup/archive.js +19 -6
  22. package/node_modules/@buddi/core/dist/backup/archive.js.map +1 -1
  23. package/node_modules/@buddi/core/dist/postgres/binaries.d.ts +21 -1
  24. package/node_modules/@buddi/core/dist/postgres/binaries.d.ts.map +1 -1
  25. package/node_modules/@buddi/core/dist/postgres/binaries.js +72 -10
  26. package/node_modules/@buddi/core/dist/postgres/binaries.js.map +1 -1
  27. package/node_modules/@buddi/core/dist/postgres/cluster.d.ts +8 -0
  28. package/node_modules/@buddi/core/dist/postgres/cluster.d.ts.map +1 -1
  29. package/node_modules/@buddi/core/dist/postgres/cluster.js +119 -17
  30. package/node_modules/@buddi/core/dist/postgres/cluster.js.map +1 -1
  31. package/node_modules/@buddi/core/dist/postgres/windows-guard.d.ts +20 -0
  32. package/node_modules/@buddi/core/dist/postgres/windows-guard.d.ts.map +1 -0
  33. package/node_modules/@buddi/core/dist/postgres/windows-guard.js +140 -0
  34. package/node_modules/@buddi/core/dist/postgres/windows-guard.js.map +1 -0
  35. package/node_modules/@buddi/gateway/dist/.tsbuildinfo +1 -1
  36. package/node_modules/@buddi/gateway/dist/agents/catalog.d.ts.map +1 -1
  37. package/node_modules/@buddi/gateway/dist/agents/catalog.js +3 -2
  38. package/node_modules/@buddi/gateway/dist/agents/catalog.js.map +1 -1
  39. package/node_modules/@buddi/gateway/dist/agents/catalogue-package.d.ts +2 -2
  40. package/node_modules/@buddi/gateway/dist/agents/catalogue-package.d.ts.map +1 -1
  41. package/node_modules/@buddi/gateway/dist/agents/catalogue-package.js +1 -1
  42. package/node_modules/@buddi/gateway/dist/agents/catalogue-package.js.map +1 -1
  43. package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.d.ts +6 -6
  44. package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.d.ts.map +1 -1
  45. package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.js +5 -5
  46. package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.js.map +1 -1
  47. package/node_modules/@buddi/gateway/dist/browser-host.js +1 -1
  48. package/node_modules/@buddi/gateway/dist/browser-host.js.map +1 -1
  49. package/node_modules/@buddi/gateway/dist/missions/chrome-scope.d.ts +10 -10
  50. package/node_modules/@buddi/gateway/dist/missions/chrome-scope.d.ts.map +1 -1
  51. package/node_modules/@buddi/gateway/dist/missions/chrome-scope.js +20 -20
  52. package/node_modules/@buddi/gateway/dist/missions/chrome-scope.js.map +1 -1
  53. package/node_modules/@buddi/gateway/dist/missions/execute.d.ts +2 -2
  54. package/node_modules/@buddi/gateway/dist/missions/execute.d.ts.map +1 -1
  55. package/node_modules/@buddi/gateway/dist/missions/execute.js +11 -11
  56. package/node_modules/@buddi/gateway/dist/missions/execute.js.map +1 -1
  57. package/node_modules/@buddi/gateway/dist/missions/reminders.d.ts +2 -2
  58. package/node_modules/@buddi/gateway/dist/missions/reminders.d.ts.map +1 -1
  59. package/node_modules/@buddi/gateway/dist/missions/reminders.js +5 -5
  60. package/node_modules/@buddi/gateway/dist/missions/reminders.js.map +1 -1
  61. package/node_modules/@buddi/gateway/dist/owner-notify.js +1 -1
  62. package/node_modules/@buddi/gateway/dist/owner-notify.js.map +1 -1
  63. package/node_modules/@buddi/gateway/dist/plugins/npm.d.ts +9 -2
  64. package/node_modules/@buddi/gateway/dist/plugins/npm.d.ts.map +1 -1
  65. package/node_modules/@buddi/gateway/dist/plugins/npm.js +29 -6
  66. package/node_modules/@buddi/gateway/dist/plugins/npm.js.map +1 -1
  67. package/node_modules/@buddi/gateway/dist/plugins/stage.d.ts.map +1 -1
  68. package/node_modules/@buddi/gateway/dist/plugins/stage.js +2 -2
  69. package/node_modules/@buddi/gateway/dist/plugins/stage.js.map +1 -1
  70. package/node_modules/@buddi/gateway/dist/serve.js +1 -1
  71. package/node_modules/@buddi/gateway/dist/serve.js.map +1 -1
  72. package/node_modules/@buddi/gateway/dist/surfaces/browser-cards.d.ts +1 -1
  73. package/node_modules/@buddi/gateway/dist/surfaces/browser-cards.js +1 -1
  74. package/node_modules/@buddi/gateway/dist/system-context.d.ts +11 -0
  75. package/node_modules/@buddi/gateway/dist/system-context.d.ts.map +1 -1
  76. package/node_modules/@buddi/gateway/dist/system-context.js +42 -1
  77. package/node_modules/@buddi/gateway/dist/system-context.js.map +1 -1
  78. package/node_modules/@buddi/gateway/dist/telegram/approvals.js +1 -1
  79. package/node_modules/@buddi/gateway/dist/telegram/approvals.js.map +1 -1
  80. package/node_modules/@buddi/gateway/dist/telegram/browser-view.js +1 -1
  81. package/node_modules/@buddi/gateway/dist/telegram/browser-view.js.map +1 -1
  82. package/node_modules/@buddi/gateway/dist/web/api-routes.js +6 -6
  83. package/node_modules/@buddi/gateway/dist/web/api-routes.js.map +1 -1
  84. package/node_modules/@buddi/gateway/dist/web/approval-ask.js +1 -1
  85. package/node_modules/@buddi/gateway/dist/web/extension.d.ts +6 -0
  86. package/node_modules/@buddi/gateway/dist/web/extension.d.ts.map +1 -1
  87. package/node_modules/@buddi/gateway/dist/web/extension.js +22 -11
  88. package/node_modules/@buddi/gateway/dist/web/extension.js.map +1 -1
  89. package/node_modules/@buddi/gateway/dist/web/read.d.ts +1 -1
  90. package/node_modules/@buddi/gateway/dist/web/read.d.ts.map +1 -1
  91. package/node_modules/@buddi/gateway/dist/web/server.js +4 -4
  92. package/node_modules/@buddi/gateway/dist/web/server.js.map +1 -1
  93. package/node_modules/@buddi/gateway/dist/web/service.d.ts +6 -1
  94. package/node_modules/@buddi/gateway/dist/web/service.d.ts.map +1 -1
  95. package/node_modules/@buddi/gateway/dist/web/service.js +10 -1
  96. package/node_modules/@buddi/gateway/dist/web/service.js.map +1 -1
  97. package/node_modules/@buddi/gateway/dist/web/skills.d.ts.map +1 -1
  98. package/node_modules/@buddi/gateway/dist/web/skills.js +2 -1
  99. package/node_modules/@buddi/gateway/dist/web/skills.js.map +1 -1
  100. package/node_modules/@buddi/gateway/dist/web/write.d.ts +1 -1
  101. package/node_modules/@buddi/gateway/dist/web/write.js +1 -1
  102. package/node_modules/@buddi/install/dist/.tsbuildinfo +1 -1
  103. package/node_modules/@buddi/install/dist/app-layout.d.ts +30 -1
  104. package/node_modules/@buddi/install/dist/app-layout.d.ts.map +1 -1
  105. package/node_modules/@buddi/install/dist/app-layout.js +61 -10
  106. package/node_modules/@buddi/install/dist/app-layout.js.map +1 -1
  107. package/node_modules/@buddi/install/dist/cloudflared.js +2 -2
  108. package/node_modules/@buddi/install/dist/cloudflared.js.map +1 -1
  109. package/node_modules/@buddi/install/dist/environment.d.ts +40 -1
  110. package/node_modules/@buddi/install/dist/environment.d.ts.map +1 -1
  111. package/node_modules/@buddi/install/dist/environment.js +158 -12
  112. package/node_modules/@buddi/install/dist/environment.js.map +1 -1
  113. package/node_modules/@buddi/install/dist/launcher.d.ts.map +1 -1
  114. package/node_modules/@buddi/install/dist/launcher.js +257 -50
  115. package/node_modules/@buddi/install/dist/launcher.js.map +1 -1
  116. package/node_modules/@buddi/install/dist/postgres-check.js +1 -1
  117. package/node_modules/@buddi/install/dist/postgres-check.js.map +1 -1
  118. package/node_modules/@buddi/install/dist/product-uninstall.d.ts +14 -0
  119. package/node_modules/@buddi/install/dist/product-uninstall.d.ts.map +1 -1
  120. package/node_modules/@buddi/install/dist/product-uninstall.js +10 -0
  121. package/node_modules/@buddi/install/dist/product-uninstall.js.map +1 -1
  122. package/node_modules/@buddi/install/dist/runtime-info.d.ts.map +1 -1
  123. package/node_modules/@buddi/install/dist/runtime-info.js +4 -1
  124. package/node_modules/@buddi/install/dist/runtime-info.js.map +1 -1
  125. package/node_modules/@buddi/install/dist/supervisor.d.ts +60 -3
  126. package/node_modules/@buddi/install/dist/supervisor.d.ts.map +1 -1
  127. package/node_modules/@buddi/install/dist/supervisor.js +173 -17
  128. package/node_modules/@buddi/install/dist/supervisor.js.map +1 -1
  129. package/node_modules/@buddi/install/dist/uninstall.d.ts +29 -3
  130. package/node_modules/@buddi/install/dist/uninstall.d.ts.map +1 -1
  131. package/node_modules/@buddi/install/dist/uninstall.js +135 -27
  132. package/node_modules/@buddi/install/dist/uninstall.js.map +1 -1
  133. package/node_modules/@buddi/install/dist/upgrade.d.ts +16 -4
  134. package/node_modules/@buddi/install/dist/upgrade.d.ts.map +1 -1
  135. package/node_modules/@buddi/install/dist/upgrade.js +50 -13
  136. package/node_modules/@buddi/install/dist/upgrade.js.map +1 -1
  137. package/node_modules/@buddi/install/dist/windows-install.d.ts +102 -0
  138. package/node_modules/@buddi/install/dist/windows-install.d.ts.map +1 -0
  139. package/node_modules/@buddi/install/dist/windows-install.js +223 -0
  140. package/node_modules/@buddi/install/dist/windows-install.js.map +1 -0
  141. package/node_modules/@buddi/install/dist/windows-setup.d.ts +107 -0
  142. package/node_modules/@buddi/install/dist/windows-setup.d.ts.map +1 -0
  143. package/node_modules/@buddi/install/dist/windows-setup.js +700 -0
  144. package/node_modules/@buddi/install/dist/windows-setup.js.map +1 -0
  145. package/node_modules/@buddi/install/dist/windows-task.d.ts +49 -0
  146. package/node_modules/@buddi/install/dist/windows-task.d.ts.map +1 -0
  147. package/node_modules/@buddi/install/dist/windows-task.js +167 -0
  148. package/node_modules/@buddi/install/dist/windows-task.js.map +1 -0
  149. package/node_modules/@buddi/runtime/dist/.tsbuildinfo +1 -1
  150. package/node_modules/@buddi/runtime/dist/codex-direct.d.ts +1 -1
  151. package/node_modules/@buddi/runtime/dist/codex-direct.js +1 -1
  152. package/node_modules/@buddi/runtime/dist/openai.d.ts +11 -0
  153. package/node_modules/@buddi/runtime/dist/openai.d.ts.map +1 -1
  154. package/node_modules/@buddi/runtime/dist/openai.js +36 -3
  155. package/node_modules/@buddi/runtime/dist/openai.js.map +1 -1
  156. package/node_modules/@buddi/tool-artifacts/dist/.tsbuildinfo +1 -1
  157. package/node_modules/@buddi/tool-artifacts/dist/tools/write.js +3 -3
  158. package/node_modules/@buddi/tool-artifacts/dist/tools/write.js.map +1 -1
  159. package/node_modules/@buddi/tool-browser/dist/.tsbuildinfo +1 -1
  160. package/node_modules/@buddi/tool-browser/dist/availability.d.ts.map +1 -1
  161. package/node_modules/@buddi/tool-browser/dist/availability.js +1 -0
  162. package/node_modules/@buddi/tool-browser/dist/availability.js.map +1 -1
  163. package/node_modules/@buddi/tool-browser/dist/brand.d.ts +19 -0
  164. package/node_modules/@buddi/tool-browser/dist/brand.d.ts.map +1 -0
  165. package/node_modules/@buddi/tool-browser/dist/brand.js +31 -0
  166. package/node_modules/@buddi/tool-browser/dist/brand.js.map +1 -0
  167. package/node_modules/@buddi/tool-browser/dist/controller.d.ts +2 -2
  168. package/node_modules/@buddi/tool-browser/dist/controller.d.ts.map +1 -1
  169. package/node_modules/@buddi/tool-browser/dist/controller.js +16 -7
  170. package/node_modules/@buddi/tool-browser/dist/controller.js.map +1 -1
  171. package/node_modules/@buddi/tool-browser/dist/downloads.js +1 -1
  172. package/node_modules/@buddi/tool-browser/dist/downloads.js.map +1 -1
  173. package/node_modules/@buddi/tool-browser/dist/extension.d.ts +3 -1
  174. package/node_modules/@buddi/tool-browser/dist/extension.d.ts.map +1 -1
  175. package/node_modules/@buddi/tool-browser/dist/extension.js +4 -4
  176. package/node_modules/@buddi/tool-browser/dist/extension.js.map +1 -1
  177. package/node_modules/@buddi/tool-browser/dist/index.d.ts +3 -2
  178. package/node_modules/@buddi/tool-browser/dist/index.d.ts.map +1 -1
  179. package/node_modules/@buddi/tool-browser/dist/index.js +7 -6
  180. package/node_modules/@buddi/tool-browser/dist/index.js.map +1 -1
  181. package/node_modules/@buddi/tool-browser/dist/routes.d.ts +12 -1
  182. package/node_modules/@buddi/tool-browser/dist/routes.d.ts.map +1 -1
  183. package/node_modules/@buddi/tool-browser/dist/routes.js +31 -14
  184. package/node_modules/@buddi/tool-browser/dist/routes.js.map +1 -1
  185. package/node_modules/@buddi/tool-browser/dist/service.d.ts +2 -0
  186. package/node_modules/@buddi/tool-browser/dist/service.d.ts.map +1 -1
  187. package/node_modules/@buddi/tool-browser/dist/service.js +6 -6
  188. package/node_modules/@buddi/tool-browser/dist/service.js.map +1 -1
  189. package/node_modules/@buddi/tool-browser/dist/telemetry.d.ts +2 -2
  190. package/node_modules/@buddi/tool-browser/dist/telemetry.js +2 -2
  191. package/node_modules/@buddi/tool-browser/dist/telemetry.js.map +1 -1
  192. package/node_modules/@buddi/tool-browser/dist/types.js +1 -1
  193. package/node_modules/@buddi/tool-browser/dist/types.js.map +1 -1
  194. package/node_modules/@buddi/tool-host/dist/.tsbuildinfo +1 -1
  195. package/node_modules/@buddi/tool-host/dist/index.d.ts +2 -1
  196. package/node_modules/@buddi/tool-host/dist/index.d.ts.map +1 -1
  197. package/node_modules/@buddi/tool-host/dist/index.js +11 -2
  198. package/node_modules/@buddi/tool-host/dist/index.js.map +1 -1
  199. package/node_modules/@buddi/tool-host/dist/process.d.ts +58 -1
  200. package/node_modules/@buddi/tool-host/dist/process.d.ts.map +1 -1
  201. package/node_modules/@buddi/tool-host/dist/process.js +229 -15
  202. package/node_modules/@buddi/tool-host/dist/process.js.map +1 -1
  203. package/node_modules/@buddi/tool-host/dist/service.d.ts +2 -0
  204. package/node_modules/@buddi/tool-host/dist/service.d.ts.map +1 -1
  205. package/node_modules/@buddi/tool-host/dist/service.js +8 -6
  206. package/node_modules/@buddi/tool-host/dist/service.js.map +1 -1
  207. package/node_modules/@buddi/tool-host/dist/skill-run.d.ts +10 -0
  208. package/node_modules/@buddi/tool-host/dist/skill-run.d.ts.map +1 -1
  209. package/node_modules/@buddi/tool-host/dist/skill-run.js +14 -0
  210. package/node_modules/@buddi/tool-host/dist/skill-run.js.map +1 -1
  211. package/node_modules/ip-address/README.md +70 -70
  212. package/node_modules/ip-address/dist/ipv6.js +7 -4
  213. package/node_modules/ip-address/dist/ipv6.js.map +1 -1
  214. package/node_modules/ip-address/dist/v6/constants.d.ts +3 -0
  215. package/node_modules/ip-address/dist/v6/constants.js +3 -0
  216. package/node_modules/ip-address/dist/v6/constants.js.map +1 -1
  217. package/node_modules/ip-address/package.json +2 -1
  218. package/node_modules/marked/bin/main.js +1 -1
  219. package/node_modules/marked/lib/marked.d.ts +6 -3
  220. package/node_modules/marked/lib/marked.esm.js +48 -50
  221. package/node_modules/marked/lib/marked.esm.js.map +3 -3
  222. package/node_modules/marked/lib/marked.umd.js +45 -47
  223. package/node_modules/marked/lib/marked.umd.js.map +3 -3
  224. package/node_modules/marked/man/marked.1 +1 -1
  225. package/node_modules/marked/package.json +1 -1
  226. package/package.json +2 -2
  227. package/packages/cli/dist/.tsbuildinfo +1 -1
  228. package/packages/cli/dist/dashboard-cmd.d.ts.map +1 -1
  229. package/packages/cli/dist/dashboard-cmd.js +6 -3
  230. package/packages/cli/dist/dashboard-cmd.js.map +1 -1
  231. package/packages/cli/dist/main.js +2 -2
  232. package/packages/cli/dist/main.js.map +1 -1
  233. package/packages/cli/dist/status.d.ts +16 -2
  234. package/packages/cli/dist/status.d.ts.map +1 -1
  235. package/packages/cli/dist/status.js +42 -2
  236. package/packages/cli/dist/status.js.map +1 -1
  237. package/packages/core/dist/.tsbuildinfo +1 -1
  238. package/packages/core/dist/agents/catalog.d.ts +6 -0
  239. package/packages/core/dist/agents/catalog.d.ts.map +1 -1
  240. package/packages/core/dist/agents/catalog.js +1 -1
  241. package/packages/core/dist/agents/catalog.js.map +1 -1
  242. package/packages/core/dist/backup/archive.d.ts +6 -0
  243. package/packages/core/dist/backup/archive.d.ts.map +1 -1
  244. package/packages/core/dist/backup/archive.js +19 -6
  245. package/packages/core/dist/backup/archive.js.map +1 -1
  246. package/packages/core/dist/postgres/binaries.d.ts +21 -1
  247. package/packages/core/dist/postgres/binaries.d.ts.map +1 -1
  248. package/packages/core/dist/postgres/binaries.js +72 -10
  249. package/packages/core/dist/postgres/binaries.js.map +1 -1
  250. package/packages/core/dist/postgres/cluster.d.ts +8 -0
  251. package/packages/core/dist/postgres/cluster.d.ts.map +1 -1
  252. package/packages/core/dist/postgres/cluster.js +119 -17
  253. package/packages/core/dist/postgres/cluster.js.map +1 -1
  254. package/packages/core/dist/postgres/windows-guard.d.ts +20 -0
  255. package/packages/core/dist/postgres/windows-guard.d.ts.map +1 -0
  256. package/packages/core/dist/postgres/windows-guard.js +140 -0
  257. package/packages/core/dist/postgres/windows-guard.js.map +1 -0
  258. package/packages/gateway/dist/.tsbuildinfo +1 -1
  259. package/packages/gateway/dist/agents/catalog.d.ts.map +1 -1
  260. package/packages/gateway/dist/agents/catalog.js +3 -2
  261. package/packages/gateway/dist/agents/catalog.js.map +1 -1
  262. package/packages/gateway/dist/agents/catalogue-package.d.ts +2 -2
  263. package/packages/gateway/dist/agents/catalogue-package.d.ts.map +1 -1
  264. package/packages/gateway/dist/agents/catalogue-package.js +1 -1
  265. package/packages/gateway/dist/agents/catalogue-package.js.map +1 -1
  266. package/packages/gateway/dist/agents/platform-catalogue.d.ts +6 -6
  267. package/packages/gateway/dist/agents/platform-catalogue.d.ts.map +1 -1
  268. package/packages/gateway/dist/agents/platform-catalogue.js +5 -5
  269. package/packages/gateway/dist/agents/platform-catalogue.js.map +1 -1
  270. package/packages/gateway/dist/browser-host.js +1 -1
  271. package/packages/gateway/dist/browser-host.js.map +1 -1
  272. package/packages/gateway/dist/missions/chrome-scope.d.ts +10 -10
  273. package/packages/gateway/dist/missions/chrome-scope.d.ts.map +1 -1
  274. package/packages/gateway/dist/missions/chrome-scope.js +20 -20
  275. package/packages/gateway/dist/missions/chrome-scope.js.map +1 -1
  276. package/packages/gateway/dist/missions/execute.d.ts +2 -2
  277. package/packages/gateway/dist/missions/execute.d.ts.map +1 -1
  278. package/packages/gateway/dist/missions/execute.js +11 -11
  279. package/packages/gateway/dist/missions/execute.js.map +1 -1
  280. package/packages/gateway/dist/missions/reminders.d.ts +2 -2
  281. package/packages/gateway/dist/missions/reminders.d.ts.map +1 -1
  282. package/packages/gateway/dist/missions/reminders.js +5 -5
  283. package/packages/gateway/dist/missions/reminders.js.map +1 -1
  284. package/packages/gateway/dist/owner-notify.js +1 -1
  285. package/packages/gateway/dist/owner-notify.js.map +1 -1
  286. package/packages/gateway/dist/plugins/npm.d.ts +9 -2
  287. package/packages/gateway/dist/plugins/npm.d.ts.map +1 -1
  288. package/packages/gateway/dist/plugins/npm.js +29 -6
  289. package/packages/gateway/dist/plugins/npm.js.map +1 -1
  290. package/packages/gateway/dist/plugins/stage.d.ts.map +1 -1
  291. package/packages/gateway/dist/plugins/stage.js +2 -2
  292. package/packages/gateway/dist/plugins/stage.js.map +1 -1
  293. package/packages/gateway/dist/serve.js +1 -1
  294. package/packages/gateway/dist/serve.js.map +1 -1
  295. package/packages/gateway/dist/surfaces/browser-cards.d.ts +1 -1
  296. package/packages/gateway/dist/surfaces/browser-cards.js +1 -1
  297. package/packages/gateway/dist/system-context.d.ts +11 -0
  298. package/packages/gateway/dist/system-context.d.ts.map +1 -1
  299. package/packages/gateway/dist/system-context.js +42 -1
  300. package/packages/gateway/dist/system-context.js.map +1 -1
  301. package/packages/gateway/dist/telegram/approvals.js +1 -1
  302. package/packages/gateway/dist/telegram/approvals.js.map +1 -1
  303. package/packages/gateway/dist/telegram/browser-view.js +1 -1
  304. package/packages/gateway/dist/telegram/browser-view.js.map +1 -1
  305. package/packages/gateway/dist/web/api-routes.js +6 -6
  306. package/packages/gateway/dist/web/api-routes.js.map +1 -1
  307. package/packages/gateway/dist/web/approval-ask.js +1 -1
  308. package/packages/gateway/dist/web/extension.d.ts +6 -0
  309. package/packages/gateway/dist/web/extension.d.ts.map +1 -1
  310. package/packages/gateway/dist/web/extension.js +22 -11
  311. package/packages/gateway/dist/web/extension.js.map +1 -1
  312. package/packages/gateway/dist/web/read.d.ts +1 -1
  313. package/packages/gateway/dist/web/read.d.ts.map +1 -1
  314. package/packages/gateway/dist/web/server.js +4 -4
  315. package/packages/gateway/dist/web/server.js.map +1 -1
  316. package/packages/gateway/dist/web/service.d.ts +6 -1
  317. package/packages/gateway/dist/web/service.d.ts.map +1 -1
  318. package/packages/gateway/dist/web/service.js +10 -1
  319. package/packages/gateway/dist/web/service.js.map +1 -1
  320. package/packages/gateway/dist/web/skills.d.ts.map +1 -1
  321. package/packages/gateway/dist/web/skills.js +2 -1
  322. package/packages/gateway/dist/web/skills.js.map +1 -1
  323. package/packages/gateway/dist/web/write.d.ts +1 -1
  324. package/packages/gateway/dist/web/write.js +1 -1
  325. package/packages/install/dist/.tsbuildinfo +1 -1
  326. package/packages/install/dist/app-layout.d.ts +30 -1
  327. package/packages/install/dist/app-layout.d.ts.map +1 -1
  328. package/packages/install/dist/app-layout.js +61 -10
  329. package/packages/install/dist/app-layout.js.map +1 -1
  330. package/packages/install/dist/cloudflared.js +2 -2
  331. package/packages/install/dist/cloudflared.js.map +1 -1
  332. package/packages/install/dist/environment.d.ts +40 -1
  333. package/packages/install/dist/environment.d.ts.map +1 -1
  334. package/packages/install/dist/environment.js +158 -12
  335. package/packages/install/dist/environment.js.map +1 -1
  336. package/packages/install/dist/launcher.d.ts.map +1 -1
  337. package/packages/install/dist/launcher.js +257 -50
  338. package/packages/install/dist/launcher.js.map +1 -1
  339. package/packages/install/dist/postgres-check.js +1 -1
  340. package/packages/install/dist/postgres-check.js.map +1 -1
  341. package/packages/install/dist/product-uninstall.d.ts +14 -0
  342. package/packages/install/dist/product-uninstall.d.ts.map +1 -1
  343. package/packages/install/dist/product-uninstall.js +10 -0
  344. package/packages/install/dist/product-uninstall.js.map +1 -1
  345. package/packages/install/dist/runtime-info.d.ts.map +1 -1
  346. package/packages/install/dist/runtime-info.js +4 -1
  347. package/packages/install/dist/runtime-info.js.map +1 -1
  348. package/packages/install/dist/supervisor.d.ts +60 -3
  349. package/packages/install/dist/supervisor.d.ts.map +1 -1
  350. package/packages/install/dist/supervisor.js +173 -17
  351. package/packages/install/dist/supervisor.js.map +1 -1
  352. package/packages/install/dist/uninstall.d.ts +29 -3
  353. package/packages/install/dist/uninstall.d.ts.map +1 -1
  354. package/packages/install/dist/uninstall.js +135 -27
  355. package/packages/install/dist/uninstall.js.map +1 -1
  356. package/packages/install/dist/upgrade.d.ts +16 -4
  357. package/packages/install/dist/upgrade.d.ts.map +1 -1
  358. package/packages/install/dist/upgrade.js +50 -13
  359. package/packages/install/dist/upgrade.js.map +1 -1
  360. package/packages/install/dist/windows-install.d.ts +102 -0
  361. package/packages/install/dist/windows-install.d.ts.map +1 -0
  362. package/packages/install/dist/windows-install.js +223 -0
  363. package/packages/install/dist/windows-install.js.map +1 -0
  364. package/packages/install/dist/windows-setup.d.ts +107 -0
  365. package/packages/install/dist/windows-setup.d.ts.map +1 -0
  366. package/packages/install/dist/windows-setup.js +700 -0
  367. package/packages/install/dist/windows-setup.js.map +1 -0
  368. package/packages/install/dist/windows-task.d.ts +49 -0
  369. package/packages/install/dist/windows-task.d.ts.map +1 -0
  370. package/packages/install/dist/windows-task.js +167 -0
  371. package/packages/install/dist/windows-task.js.map +1 -0
  372. package/packages/runtime/dist/.tsbuildinfo +1 -1
  373. package/packages/runtime/dist/codex-direct.d.ts +1 -1
  374. package/packages/runtime/dist/codex-direct.js +1 -1
  375. package/packages/runtime/dist/openai.d.ts +11 -0
  376. package/packages/runtime/dist/openai.d.ts.map +1 -1
  377. package/packages/runtime/dist/openai.js +36 -3
  378. package/packages/runtime/dist/openai.js.map +1 -1
  379. package/packages/tools/artifacts/dist/.tsbuildinfo +1 -1
  380. package/packages/tools/artifacts/dist/tools/write.js +3 -3
  381. package/packages/tools/artifacts/dist/tools/write.js.map +1 -1
  382. package/packages/tools/browser/dist/.tsbuildinfo +1 -1
  383. package/packages/tools/browser/dist/availability.d.ts.map +1 -1
  384. package/packages/tools/browser/dist/availability.js +1 -0
  385. package/packages/tools/browser/dist/availability.js.map +1 -1
  386. package/packages/tools/browser/dist/brand.d.ts +19 -0
  387. package/packages/tools/browser/dist/brand.d.ts.map +1 -0
  388. package/packages/tools/browser/dist/brand.js +31 -0
  389. package/packages/tools/browser/dist/brand.js.map +1 -0
  390. package/packages/tools/browser/dist/controller.d.ts +2 -2
  391. package/packages/tools/browser/dist/controller.d.ts.map +1 -1
  392. package/packages/tools/browser/dist/controller.js +16 -7
  393. package/packages/tools/browser/dist/controller.js.map +1 -1
  394. package/packages/tools/browser/dist/downloads.js +1 -1
  395. package/packages/tools/browser/dist/downloads.js.map +1 -1
  396. package/packages/tools/browser/dist/extension.d.ts +3 -1
  397. package/packages/tools/browser/dist/extension.d.ts.map +1 -1
  398. package/packages/tools/browser/dist/extension.js +4 -4
  399. package/packages/tools/browser/dist/extension.js.map +1 -1
  400. package/packages/tools/browser/dist/index.d.ts +3 -2
  401. package/packages/tools/browser/dist/index.d.ts.map +1 -1
  402. package/packages/tools/browser/dist/index.js +7 -6
  403. package/packages/tools/browser/dist/index.js.map +1 -1
  404. package/packages/tools/browser/dist/routes.d.ts +12 -1
  405. package/packages/tools/browser/dist/routes.d.ts.map +1 -1
  406. package/packages/tools/browser/dist/routes.js +31 -14
  407. package/packages/tools/browser/dist/routes.js.map +1 -1
  408. package/packages/tools/browser/dist/service.d.ts +2 -0
  409. package/packages/tools/browser/dist/service.d.ts.map +1 -1
  410. package/packages/tools/browser/dist/service.js +6 -6
  411. package/packages/tools/browser/dist/service.js.map +1 -1
  412. package/packages/tools/browser/dist/telemetry.d.ts +2 -2
  413. package/packages/tools/browser/dist/telemetry.js +2 -2
  414. package/packages/tools/browser/dist/telemetry.js.map +1 -1
  415. package/packages/tools/browser/dist/types.js +1 -1
  416. package/packages/tools/browser/dist/types.js.map +1 -1
  417. package/packages/tools/host/dist/.tsbuildinfo +1 -1
  418. package/packages/tools/host/dist/index.d.ts +2 -1
  419. package/packages/tools/host/dist/index.d.ts.map +1 -1
  420. package/packages/tools/host/dist/index.js +11 -2
  421. package/packages/tools/host/dist/index.js.map +1 -1
  422. package/packages/tools/host/dist/process.d.ts +58 -1
  423. package/packages/tools/host/dist/process.d.ts.map +1 -1
  424. package/packages/tools/host/dist/process.js +229 -15
  425. package/packages/tools/host/dist/process.js.map +1 -1
  426. package/packages/tools/host/dist/service.d.ts +2 -0
  427. package/packages/tools/host/dist/service.d.ts.map +1 -1
  428. package/packages/tools/host/dist/service.js +8 -6
  429. package/packages/tools/host/dist/service.js.map +1 -1
  430. package/packages/tools/host/dist/skill-run.d.ts +10 -0
  431. package/packages/tools/host/dist/skill-run.d.ts.map +1 -1
  432. package/packages/tools/host/dist/skill-run.js +14 -0
  433. package/packages/tools/host/dist/skill-run.js.map +1 -1
  434. package/packages/web/dist/assets/index-DnZhfnM7.js +155 -0
  435. package/packages/web/dist/assets/{lottie_light-twPed1FM.js → lottie_light-CGUtDt_b.js} +1 -1
  436. package/packages/web/dist/build.json +1 -1
  437. package/packages/web/dist/index.html +1 -1
  438. package/packages/web/dist/precache.json +3 -3
  439. package/packages/web/dist/assets/index-DgpPl0TR.js +0 -155
@@ -1,155 +0,0 @@
1
- var OL=Object.defineProperty;var T0=e=>{throw TypeError(e)};var DL=(e,n,s)=>n in e?OL(e,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[n]=s;var R0=(e,n,s)=>DL(e,typeof n!="symbol"?n+"":n,s),I0=(e,n,s)=>n.has(e)||T0("Cannot "+s);var Bt=(e,n,s)=>(I0(e,n,"read from private field"),s?s.call(e):n.get(e)),Li=(e,n,s)=>n.has(e)?T0("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(e):n.set(e,s),ls=(e,n,s,r)=>(I0(e,n,"write to private field"),r?r.call(e,s):n.set(e,s),s);function LL(e,n){for(var s=0;s<n.length;s++){const r=n[s];if(typeof r!="string"&&!Array.isArray(r)){for(const a in r)if(a!=="default"&&!(a in e)){const i=Object.getOwnPropertyDescriptor(r,a);i&&Object.defineProperty(e,a,i.get?i:{enumerable:!0,get:()=>r[a]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))r(a);new MutationObserver(a=>{for(const i of a)if(i.type==="childList")for(const l of i.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&r(l)}).observe(document,{childList:!0,subtree:!0});function s(a){const i={};return a.integrity&&(i.integrity=a.integrity),a.referrerPolicy&&(i.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?i.credentials="include":a.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(a){if(a.ep)return;a.ep=!0;const i=s(a);fetch(a.href,i)}})();var hue=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function FL(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ZE={exports:{}},vm={},eA={exports:{}},Ct={};/**
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 rd=Symbol.for("react.element"),_L=Symbol.for("react.portal"),zL=Symbol.for("react.fragment"),UL=Symbol.for("react.strict_mode"),BL=Symbol.for("react.profiler"),WL=Symbol.for("react.provider"),HL=Symbol.for("react.context"),KL=Symbol.for("react.forward_ref"),VL=Symbol.for("react.suspense"),GL=Symbol.for("react.memo"),qL=Symbol.for("react.lazy"),P0=Symbol.iterator;function YL(e){return e===null||typeof e!="object"?null:(e=P0&&e[P0]||e["@@iterator"],typeof e=="function"?e:null)}var tA={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},nA=Object.assign,sA={};function Ho(e,n,s){this.props=e,this.context=n,this.refs=sA,this.updater=s||tA}Ho.prototype.isReactComponent={};Ho.prototype.setState=function(e,n){if(typeof e!="object"&&typeof e!="function"&&e!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,n,"setState")};Ho.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function rA(){}rA.prototype=Ho.prototype;function Iy(e,n,s){this.props=e,this.context=n,this.refs=sA,this.updater=s||tA}var Py=Iy.prototype=new rA;Py.constructor=Iy;nA(Py,Ho.prototype);Py.isPureReactComponent=!0;var M0=Array.isArray,aA=Object.prototype.hasOwnProperty,My={current:null},iA={key:!0,ref:!0,__self:!0,__source:!0};function lA(e,n,s){var r,a={},i=null,l=null;if(n!=null)for(r in n.ref!==void 0&&(l=n.ref),n.key!==void 0&&(i=""+n.key),n)aA.call(n,r)&&!iA.hasOwnProperty(r)&&(a[r]=n[r]);var o=arguments.length-2;if(o===1)a.children=s;else if(1<o){for(var c=Array(o),u=0;u<o;u++)c[u]=arguments[u+2];a.children=c}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)a[r]===void 0&&(a[r]=o[r]);return{$$typeof:rd,type:e,key:i,ref:l,props:a,_owner:My.current}}function QL(e,n){return{$$typeof:rd,type:e.type,key:n,ref:e.ref,props:e.props,_owner:e._owner}}function Oy(e){return typeof e=="object"&&e!==null&&e.$$typeof===rd}function JL(e){var n={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(s){return n[s]})}var O0=/\/+/g;function Hp(e,n){return typeof e=="object"&&e!==null&&e.key!=null?JL(""+e.key):n.toString(36)}function Th(e,n,s,r,a){var i=typeof e;(i==="undefined"||i==="boolean")&&(e=null);var l=!1;if(e===null)l=!0;else switch(i){case"string":case"number":l=!0;break;case"object":switch(e.$$typeof){case rd:case _L:l=!0}}if(l)return l=e,a=a(l),e=r===""?"."+Hp(l,0):r,M0(a)?(s="",e!=null&&(s=e.replace(O0,"$&/")+"/"),Th(a,n,s,"",function(u){return u})):a!=null&&(Oy(a)&&(a=QL(a,s+(!a.key||l&&l.key===a.key?"":(""+a.key).replace(O0,"$&/")+"/")+e)),n.push(a)),1;if(l=0,r=r===""?".":r+":",M0(e))for(var o=0;o<e.length;o++){i=e[o];var c=r+Hp(i,o);l+=Th(i,n,s,c,a)}else if(c=YL(e),typeof c=="function")for(e=c.call(e),o=0;!(i=e.next()).done;)i=i.value,c=r+Hp(i,o++),l+=Th(i,n,s,c,a);else if(i==="object")throw n=String(e),Error("Objects are not valid as a React child (found: "+(n==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":n)+"). If you meant to render a collection of children, use an array instead.");return l}function Ld(e,n,s){if(e==null)return e;var r=[],a=0;return Th(e,r,"","",function(i){return n.call(s,i,a++)}),r}function XL(e){if(e._status===-1){var n=e._result;n=n(),n.then(function(s){(e._status===0||e._status===-1)&&(e._status=1,e._result=s)},function(s){(e._status===0||e._status===-1)&&(e._status=2,e._result=s)}),e._status===-1&&(e._status=0,e._result=n)}if(e._status===1)return e._result.default;throw e._result}var gs={current:null},Rh={transition:null},ZL={ReactCurrentDispatcher:gs,ReactCurrentBatchConfig:Rh,ReactCurrentOwner:My};function oA(){throw Error("act(...) is not supported in production builds of React.")}Ct.Children={map:Ld,forEach:function(e,n,s){Ld(e,function(){n.apply(this,arguments)},s)},count:function(e){var n=0;return Ld(e,function(){n++}),n},toArray:function(e){return Ld(e,function(n){return n})||[]},only:function(e){if(!Oy(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};Ct.Component=Ho;Ct.Fragment=zL;Ct.Profiler=BL;Ct.PureComponent=Iy;Ct.StrictMode=UL;Ct.Suspense=VL;Ct.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=ZL;Ct.act=oA;Ct.cloneElement=function(e,n,s){if(e==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+e+".");var r=nA({},e.props),a=e.key,i=e.ref,l=e._owner;if(n!=null){if(n.ref!==void 0&&(i=n.ref,l=My.current),n.key!==void 0&&(a=""+n.key),e.type&&e.type.defaultProps)var o=e.type.defaultProps;for(c in n)aA.call(n,c)&&!iA.hasOwnProperty(c)&&(r[c]=n[c]===void 0&&o!==void 0?o[c]:n[c])}var c=arguments.length-2;if(c===1)r.children=s;else if(1<c){o=Array(c);for(var u=0;u<c;u++)o[u]=arguments[u+2];r.children=o}return{$$typeof:rd,type:e.type,key:a,ref:i,props:r,_owner:l}};Ct.createContext=function(e){return e={$$typeof:HL,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:WL,_context:e},e.Consumer=e};Ct.createElement=lA;Ct.createFactory=function(e){var n=lA.bind(null,e);return n.type=e,n};Ct.createRef=function(){return{current:null}};Ct.forwardRef=function(e){return{$$typeof:KL,render:e}};Ct.isValidElement=Oy;Ct.lazy=function(e){return{$$typeof:qL,_payload:{_status:-1,_result:e},_init:XL}};Ct.memo=function(e,n){return{$$typeof:GL,type:e,compare:n===void 0?null:n}};Ct.startTransition=function(e){var n=Rh.transition;Rh.transition={};try{e()}finally{Rh.transition=n}};Ct.unstable_act=oA;Ct.useCallback=function(e,n){return gs.current.useCallback(e,n)};Ct.useContext=function(e){return gs.current.useContext(e)};Ct.useDebugValue=function(){};Ct.useDeferredValue=function(e){return gs.current.useDeferredValue(e)};Ct.useEffect=function(e,n){return gs.current.useEffect(e,n)};Ct.useId=function(){return gs.current.useId()};Ct.useImperativeHandle=function(e,n,s){return gs.current.useImperativeHandle(e,n,s)};Ct.useInsertionEffect=function(e,n){return gs.current.useInsertionEffect(e,n)};Ct.useLayoutEffect=function(e,n){return gs.current.useLayoutEffect(e,n)};Ct.useMemo=function(e,n){return gs.current.useMemo(e,n)};Ct.useReducer=function(e,n,s){return gs.current.useReducer(e,n,s)};Ct.useRef=function(e){return gs.current.useRef(e)};Ct.useState=function(e){return gs.current.useState(e)};Ct.useSyncExternalStore=function(e,n,s){return gs.current.useSyncExternalStore(e,n,s)};Ct.useTransition=function(){return gs.current.useTransition()};Ct.version="18.3.1";eA.exports=Ct;var d=eA.exports;const eF=FL(d),Ko=LL({__proto__:null,default:eF},[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 tF=d,nF=Symbol.for("react.element"),sF=Symbol.for("react.fragment"),rF=Object.prototype.hasOwnProperty,aF=tF.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,iF={key:!0,ref:!0,__self:!0,__source:!0};function cA(e,n,s){var r,a={},i=null,l=null;s!==void 0&&(i=""+s),n.key!==void 0&&(i=""+n.key),n.ref!==void 0&&(l=n.ref);for(r in n)rF.call(n,r)&&!iF.hasOwnProperty(r)&&(a[r]=n[r]);if(e&&e.defaultProps)for(r in n=e.defaultProps,n)a[r]===void 0&&(a[r]=n[r]);return{$$typeof:nF,type:e,key:i,ref:l,props:a,_owner:aF.current}}vm.Fragment=sF;vm.jsx=cA;vm.jsxs=cA;ZE.exports=vm;var t=ZE.exports,uA={exports:{}},qs={},dA={exports:{}},hA={};/**
18
- * @license React
19
- * scheduler.production.min.js
20
- *
21
- * Copyright (c) Facebook, Inc. and its affiliates.
22
- *
23
- * This source code is licensed under the MIT license found in the
24
- * LICENSE file in the root directory of this source tree.
25
- */(function(e){function n(M,z){var D=M.length;M.push(z);e:for(;0<D;){var K=D-1>>>1,B=M[K];if(0<a(B,z))M[K]=z,M[D]=B,D=K;else break e}}function s(M){return M.length===0?null:M[0]}function r(M){if(M.length===0)return null;var z=M[0],D=M.pop();if(D!==z){M[0]=D;e:for(var K=0,B=M.length,se=B>>>1;K<se;){var W=2*(K+1)-1,xe=M[W],me=W+1,ie=M[me];if(0>a(xe,D))me<B&&0>a(ie,xe)?(M[K]=ie,M[me]=D,K=me):(M[K]=xe,M[W]=D,K=W);else if(me<B&&0>a(ie,D))M[K]=ie,M[me]=D,K=me;else break e}}return z}function a(M,z){var D=M.sortIndex-z.sortIndex;return D!==0?D:M.id-z.id}if(typeof performance=="object"&&typeof performance.now=="function"){var i=performance;e.unstable_now=function(){return i.now()}}else{var l=Date,o=l.now();e.unstable_now=function(){return l.now()-o}}var c=[],u=[],h=1,m=null,f=3,p=!1,x=!1,g=!1,w=typeof setTimeout=="function"?setTimeout:null,v=typeof clearTimeout=="function"?clearTimeout:null,j=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function y(M){for(var z=s(u);z!==null;){if(z.callback===null)r(u);else if(z.startTime<=M)r(u),z.sortIndex=z.expirationTime,n(c,z);else break;z=s(u)}}function k(M){if(g=!1,y(M),!x)if(s(c)!==null)x=!0,U(N);else{var z=s(u);z!==null&&L(k,z.startTime-M)}}function N(M,z){x=!1,g&&(g=!1,v(C),C=-1),p=!0;var D=f;try{for(y(z),m=s(c);m!==null&&(!(m.expirationTime>z)||M&&!R());){var K=m.callback;if(typeof K=="function"){m.callback=null,f=m.priorityLevel;var B=K(m.expirationTime<=z);z=e.unstable_now(),typeof B=="function"?m.callback=B:m===s(c)&&r(c),y(z)}else r(c);m=s(c)}if(m!==null)var se=!0;else{var W=s(u);W!==null&&L(k,W.startTime-z),se=!1}return se}finally{m=null,f=D,p=!1}}var b=!1,S=null,C=-1,A=5,E=-1;function R(){return!(e.unstable_now()-E<A)}function P(){if(S!==null){var M=e.unstable_now();E=M;var z=!0;try{z=S(!0,M)}finally{z?O():(b=!1,S=null)}}else b=!1}var O;if(typeof j=="function")O=function(){j(P)};else if(typeof MessageChannel<"u"){var I=new MessageChannel,F=I.port2;I.port1.onmessage=P,O=function(){F.postMessage(null)}}else O=function(){w(P,0)};function U(M){S=M,b||(b=!0,O())}function L(M,z){C=w(function(){M(e.unstable_now())},z)}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(M){M.callback=null},e.unstable_continueExecution=function(){x||p||(x=!0,U(N))},e.unstable_forceFrameRate=function(M){0>M||125<M?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):A=0<M?Math.floor(1e3/M):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_getFirstCallbackNode=function(){return s(c)},e.unstable_next=function(M){switch(f){case 1:case 2:case 3:var z=3;break;default:z=f}var D=f;f=z;try{return M()}finally{f=D}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(M,z){switch(M){case 1:case 2:case 3:case 4:case 5:break;default:M=3}var D=f;f=M;try{return z()}finally{f=D}},e.unstable_scheduleCallback=function(M,z,D){var K=e.unstable_now();switch(typeof D=="object"&&D!==null?(D=D.delay,D=typeof D=="number"&&0<D?K+D:K):D=K,M){case 1:var B=-1;break;case 2:B=250;break;case 5:B=1073741823;break;case 4:B=1e4;break;default:B=5e3}return B=D+B,M={id:h++,callback:z,priorityLevel:M,startTime:D,expirationTime:B,sortIndex:-1},D>K?(M.sortIndex=D,n(u,M),s(c)===null&&M===s(u)&&(g?(v(C),C=-1):g=!0,L(k,D-K))):(M.sortIndex=B,n(c,M),x||p||(x=!0,U(N))),M},e.unstable_shouldYield=R,e.unstable_wrapCallback=function(M){var z=f;return function(){var D=f;f=z;try{return M.apply(this,arguments)}finally{f=D}}}})(hA);dA.exports=hA;var lF=dA.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 oF=d,Hs=lF;function Te(e){for(var n="https://reactjs.org/docs/error-decoder.html?invariant="+e,s=1;s<arguments.length;s++)n+="&args[]="+encodeURIComponent(arguments[s]);return"Minified React error #"+e+"; visit "+n+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var fA=new Set,ou={};function vl(e,n){ko(e,n),ko(e+"Capture",n)}function ko(e,n){for(ou[e]=n,e=0;e<n.length;e++)fA.add(n[e])}var Ta=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Px=Object.prototype.hasOwnProperty,cF=/^[: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]*$/,D0={},L0={};function uF(e){return Px.call(L0,e)?!0:Px.call(D0,e)?!1:cF.test(e)?L0[e]=!0:(D0[e]=!0,!1)}function dF(e,n,s,r){if(s!==null&&s.type===0)return!1;switch(typeof n){case"function":case"symbol":return!0;case"boolean":return r?!1:s!==null?!s.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function hF(e,n,s,r){if(n===null||typeof n>"u"||dF(e,n,s,r))return!0;if(r)return!1;if(s!==null)switch(s.type){case 3:return!n;case 4:return n===!1;case 5:return isNaN(n);case 6:return isNaN(n)||1>n}return!1}function xs(e,n,s,r,a,i,l){this.acceptsBooleans=n===2||n===3||n===4,this.attributeName=r,this.attributeNamespace=a,this.mustUseProperty=s,this.propertyName=e,this.type=n,this.sanitizeURL=i,this.removeEmptyString=l}var qn={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){qn[e]=new xs(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var n=e[0];qn[n]=new xs(n,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){qn[e]=new xs(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){qn[e]=new xs(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){qn[e]=new xs(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){qn[e]=new xs(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){qn[e]=new xs(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){qn[e]=new xs(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){qn[e]=new xs(e,5,!1,e.toLowerCase(),null,!1,!1)});var Dy=/[\-:]([a-z])/g;function Ly(e){return e[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(e){var n=e.replace(Dy,Ly);qn[n]=new xs(n,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var n=e.replace(Dy,Ly);qn[n]=new xs(n,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var n=e.replace(Dy,Ly);qn[n]=new xs(n,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){qn[e]=new xs(e,1,!1,e.toLowerCase(),null,!1,!1)});qn.xlinkHref=new xs("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){qn[e]=new xs(e,1,!1,e.toLowerCase(),null,!0,!0)});function Fy(e,n,s,r){var a=qn.hasOwnProperty(n)?qn[n]:null;(a!==null?a.type!==0:r||!(2<n.length)||n[0]!=="o"&&n[0]!=="O"||n[1]!=="n"&&n[1]!=="N")&&(hF(n,s,a,r)&&(s=null),r||a===null?uF(n)&&(s===null?e.removeAttribute(n):e.setAttribute(n,""+s)):a.mustUseProperty?e[a.propertyName]=s===null?a.type===3?!1:"":s:(n=a.attributeName,r=a.attributeNamespace,s===null?e.removeAttribute(n):(a=a.type,s=a===3||a===4&&s===!0?"":""+s,r?e.setAttributeNS(r,n,s):e.setAttribute(n,s))))}var Fa=oF.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,Fd=Symbol.for("react.element"),Vl=Symbol.for("react.portal"),Gl=Symbol.for("react.fragment"),_y=Symbol.for("react.strict_mode"),Mx=Symbol.for("react.profiler"),mA=Symbol.for("react.provider"),pA=Symbol.for("react.context"),zy=Symbol.for("react.forward_ref"),Ox=Symbol.for("react.suspense"),Dx=Symbol.for("react.suspense_list"),Uy=Symbol.for("react.memo"),qa=Symbol.for("react.lazy"),gA=Symbol.for("react.offscreen"),F0=Symbol.iterator;function xc(e){return e===null||typeof e!="object"?null:(e=F0&&e[F0]||e["@@iterator"],typeof e=="function"?e:null)}var un=Object.assign,Kp;function Mc(e){if(Kp===void 0)try{throw Error()}catch(s){var n=s.stack.trim().match(/\n( *(at )?)/);Kp=n&&n[1]||""}return`
34
- `+Kp+e}var Vp=!1;function Gp(e,n){if(!e||Vp)return"";Vp=!0;var s=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(n)if(n=function(){throw Error()},Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(n,[])}catch(u){var r=u}Reflect.construct(e,[],n)}else{try{n.call()}catch(u){r=u}e.call(n.prototype)}else{try{throw Error()}catch(u){r=u}e()}}catch(u){if(u&&r&&typeof u.stack=="string"){for(var a=u.stack.split(`
35
- `),i=r.stack.split(`
36
- `),l=a.length-1,o=i.length-1;1<=l&&0<=o&&a[l]!==i[o];)o--;for(;1<=l&&0<=o;l--,o--)if(a[l]!==i[o]){if(l!==1||o!==1)do if(l--,o--,0>o||a[l]!==i[o]){var c=`
37
- `+a[l].replace(" at new "," at ");return e.displayName&&c.includes("<anonymous>")&&(c=c.replace("<anonymous>",e.displayName)),c}while(1<=l&&0<=o);break}}}finally{Vp=!1,Error.prepareStackTrace=s}return(e=e?e.displayName||e.name:"")?Mc(e):""}function fF(e){switch(e.tag){case 5:return Mc(e.type);case 16:return Mc("Lazy");case 13:return Mc("Suspense");case 19:return Mc("SuspenseList");case 0:case 2:case 15:return e=Gp(e.type,!1),e;case 11:return e=Gp(e.type.render,!1),e;case 1:return e=Gp(e.type,!0),e;default:return""}}function Lx(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 Gl:return"Fragment";case Vl:return"Portal";case Mx:return"Profiler";case _y:return"StrictMode";case Ox:return"Suspense";case Dx:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case pA:return(e.displayName||"Context")+".Consumer";case mA:return(e._context.displayName||"Context")+".Provider";case zy:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Uy:return n=e.displayName||null,n!==null?n:Lx(e.type)||"Memo";case qa:n=e._payload,e=e._init;try{return Lx(e(n))}catch{}}return null}function mF(e){var n=e.type;switch(e.tag){case 24:return"Cache";case 9:return(n.displayName||"Context")+".Consumer";case 10:return(n._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=n.render,e=e.displayName||e.name||"",n.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return n;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return Lx(n);case 8:return n===_y?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof n=="function")return n.displayName||n.name||null;if(typeof n=="string")return n}return null}function mi(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function xA(e){var n=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(n==="checkbox"||n==="radio")}function pF(e){var n=xA(e)?"checked":"value",s=Object.getOwnPropertyDescriptor(e.constructor.prototype,n),r=""+e[n];if(!e.hasOwnProperty(n)&&typeof s<"u"&&typeof s.get=="function"&&typeof s.set=="function"){var a=s.get,i=s.set;return Object.defineProperty(e,n,{configurable:!0,get:function(){return a.call(this)},set:function(l){r=""+l,i.call(this,l)}}),Object.defineProperty(e,n,{enumerable:s.enumerable}),{getValue:function(){return r},setValue:function(l){r=""+l},stopTracking:function(){e._valueTracker=null,delete e[n]}}}}function _d(e){e._valueTracker||(e._valueTracker=pF(e))}function jA(e){if(!e)return!1;var n=e._valueTracker;if(!n)return!0;var s=n.getValue(),r="";return e&&(r=xA(e)?e.checked?"true":"false":e.value),e=r,e!==s?(n.setValue(e),!0):!1}function of(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 Fx(e,n){var s=n.checked;return un({},n,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:s??e._wrapperState.initialChecked})}function _0(e,n){var s=n.defaultValue==null?"":n.defaultValue,r=n.checked!=null?n.checked:n.defaultChecked;s=mi(n.value!=null?n.value:s),e._wrapperState={initialChecked:r,initialValue:s,controlled:n.type==="checkbox"||n.type==="radio"?n.checked!=null:n.value!=null}}function vA(e,n){n=n.checked,n!=null&&Fy(e,"checked",n,!1)}function _x(e,n){vA(e,n);var s=mi(n.value),r=n.type;if(s!=null)r==="number"?(s===0&&e.value===""||e.value!=s)&&(e.value=""+s):e.value!==""+s&&(e.value=""+s);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}n.hasOwnProperty("value")?zx(e,n.type,s):n.hasOwnProperty("defaultValue")&&zx(e,n.type,mi(n.defaultValue)),n.checked==null&&n.defaultChecked!=null&&(e.defaultChecked=!!n.defaultChecked)}function z0(e,n,s){if(n.hasOwnProperty("value")||n.hasOwnProperty("defaultValue")){var r=n.type;if(!(r!=="submit"&&r!=="reset"||n.value!==void 0&&n.value!==null))return;n=""+e._wrapperState.initialValue,s||n===e.value||(e.value=n),e.defaultValue=n}s=e.name,s!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,s!==""&&(e.name=s)}function zx(e,n,s){(n!=="number"||of(e.ownerDocument)!==e)&&(s==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+s&&(e.defaultValue=""+s))}var Oc=Array.isArray;function co(e,n,s,r){if(e=e.options,n){n={};for(var a=0;a<s.length;a++)n["$"+s[a]]=!0;for(s=0;s<e.length;s++)a=n.hasOwnProperty("$"+e[s].value),e[s].selected!==a&&(e[s].selected=a),a&&r&&(e[s].defaultSelected=!0)}else{for(s=""+mi(s),n=null,a=0;a<e.length;a++){if(e[a].value===s){e[a].selected=!0,r&&(e[a].defaultSelected=!0);return}n!==null||e[a].disabled||(n=e[a])}n!==null&&(n.selected=!0)}}function Ux(e,n){if(n.dangerouslySetInnerHTML!=null)throw Error(Te(91));return un({},n,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function U0(e,n){var s=n.value;if(s==null){if(s=n.children,n=n.defaultValue,s!=null){if(n!=null)throw Error(Te(92));if(Oc(s)){if(1<s.length)throw Error(Te(93));s=s[0]}n=s}n==null&&(n=""),s=n}e._wrapperState={initialValue:mi(s)}}function yA(e,n){var s=mi(n.value),r=mi(n.defaultValue);s!=null&&(s=""+s,s!==e.value&&(e.value=s),n.defaultValue==null&&e.defaultValue!==s&&(e.defaultValue=s)),r!=null&&(e.defaultValue=""+r)}function B0(e){var n=e.textContent;n===e._wrapperState.initialValue&&n!==""&&n!==null&&(e.value=n)}function wA(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 Bx(e,n){return e==null||e==="http://www.w3.org/1999/xhtml"?wA(n):e==="http://www.w3.org/2000/svg"&&n==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var zd,bA=function(e){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(n,s,r,a){MSApp.execUnsafeLocalFunction(function(){return e(n,s,r,a)})}:e}(function(e,n){if(e.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in e)e.innerHTML=n;else{for(zd=zd||document.createElement("div"),zd.innerHTML="<svg>"+n.valueOf().toString()+"</svg>",n=zd.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;n.firstChild;)e.appendChild(n.firstChild)}});function cu(e,n){if(n){var s=e.firstChild;if(s&&s===e.lastChild&&s.nodeType===3){s.nodeValue=n;return}}e.textContent=n}var Wc={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},gF=["Webkit","ms","Moz","O"];Object.keys(Wc).forEach(function(e){gF.forEach(function(n){n=n+e.charAt(0).toUpperCase()+e.substring(1),Wc[n]=Wc[e]})});function kA(e,n,s){return n==null||typeof n=="boolean"||n===""?"":s||typeof n!="number"||n===0||Wc.hasOwnProperty(e)&&Wc[e]?(""+n).trim():n+"px"}function NA(e,n){e=e.style;for(var s in n)if(n.hasOwnProperty(s)){var r=s.indexOf("--")===0,a=kA(s,n[s],r);s==="float"&&(s="cssFloat"),r?e.setProperty(s,a):e[s]=a}}var xF=un({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 Wx(e,n){if(n){if(xF[e]&&(n.children!=null||n.dangerouslySetInnerHTML!=null))throw Error(Te(137,e));if(n.dangerouslySetInnerHTML!=null){if(n.children!=null)throw Error(Te(60));if(typeof n.dangerouslySetInnerHTML!="object"||!("__html"in n.dangerouslySetInnerHTML))throw Error(Te(61))}if(n.style!=null&&typeof n.style!="object")throw Error(Te(62))}}function Hx(e,n){if(e.indexOf("-")===-1)return typeof n.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var Kx=null;function By(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Vx=null,uo=null,ho=null;function W0(e){if(e=ld(e)){if(typeof Vx!="function")throw Error(Te(280));var n=e.stateNode;n&&(n=Nm(n),Vx(e.stateNode,e.type,n))}}function SA(e){uo?ho?ho.push(e):ho=[e]:uo=e}function CA(){if(uo){var e=uo,n=ho;if(ho=uo=null,W0(e),n)for(e=0;e<n.length;e++)W0(n[e])}}function EA(e,n){return e(n)}function AA(){}var qp=!1;function $A(e,n,s){if(qp)return e(n,s);qp=!0;try{return EA(e,n,s)}finally{qp=!1,(uo!==null||ho!==null)&&(AA(),CA())}}function uu(e,n){var s=e.stateNode;if(s===null)return null;var r=Nm(s);if(r===null)return null;s=r[n];e:switch(n){case"onClick":case"onClickCapture":case"onDoubleClick":case"onDoubleClickCapture":case"onMouseDown":case"onMouseDownCapture":case"onMouseMove":case"onMouseMoveCapture":case"onMouseUp":case"onMouseUpCapture":case"onMouseEnter":(r=!r.disabled)||(e=e.type,r=!(e==="button"||e==="input"||e==="select"||e==="textarea")),e=!r;break e;default:e=!1}if(e)return null;if(s&&typeof s!="function")throw Error(Te(231,n,typeof s));return s}var Gx=!1;if(Ta)try{var jc={};Object.defineProperty(jc,"passive",{get:function(){Gx=!0}}),window.addEventListener("test",jc,jc),window.removeEventListener("test",jc,jc)}catch{Gx=!1}function jF(e,n,s,r,a,i,l,o,c){var u=Array.prototype.slice.call(arguments,3);try{n.apply(s,u)}catch(h){this.onError(h)}}var Hc=!1,cf=null,uf=!1,qx=null,vF={onError:function(e){Hc=!0,cf=e}};function yF(e,n,s,r,a,i,l,o,c){Hc=!1,cf=null,jF.apply(vF,arguments)}function wF(e,n,s,r,a,i,l,o,c){if(yF.apply(this,arguments),Hc){if(Hc){var u=cf;Hc=!1,cf=null}else throw Error(Te(198));uf||(uf=!0,qx=u)}}function yl(e){var n=e,s=e;if(e.alternate)for(;n.return;)n=n.return;else{e=n;do n=e,n.flags&4098&&(s=n.return),e=n.return;while(e)}return n.tag===3?s:null}function TA(e){if(e.tag===13){var n=e.memoizedState;if(n===null&&(e=e.alternate,e!==null&&(n=e.memoizedState)),n!==null)return n.dehydrated}return null}function H0(e){if(yl(e)!==e)throw Error(Te(188))}function bF(e){var n=e.alternate;if(!n){if(n=yl(e),n===null)throw Error(Te(188));return n!==e?null:e}for(var s=e,r=n;;){var a=s.return;if(a===null)break;var i=a.alternate;if(i===null){if(r=a.return,r!==null){s=r;continue}break}if(a.child===i.child){for(i=a.child;i;){if(i===s)return H0(a),e;if(i===r)return H0(a),n;i=i.sibling}throw Error(Te(188))}if(s.return!==r.return)s=a,r=i;else{for(var l=!1,o=a.child;o;){if(o===s){l=!0,s=a,r=i;break}if(o===r){l=!0,r=a,s=i;break}o=o.sibling}if(!l){for(o=i.child;o;){if(o===s){l=!0,s=i,r=a;break}if(o===r){l=!0,r=i,s=a;break}o=o.sibling}if(!l)throw Error(Te(189))}}if(s.alternate!==r)throw Error(Te(190))}if(s.tag!==3)throw Error(Te(188));return s.stateNode.current===s?e:n}function RA(e){return e=bF(e),e!==null?IA(e):null}function IA(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var n=IA(e);if(n!==null)return n;e=e.sibling}return null}var PA=Hs.unstable_scheduleCallback,K0=Hs.unstable_cancelCallback,kF=Hs.unstable_shouldYield,NF=Hs.unstable_requestPaint,jn=Hs.unstable_now,SF=Hs.unstable_getCurrentPriorityLevel,Wy=Hs.unstable_ImmediatePriority,MA=Hs.unstable_UserBlockingPriority,df=Hs.unstable_NormalPriority,CF=Hs.unstable_LowPriority,OA=Hs.unstable_IdlePriority,ym=null,ta=null;function EF(e){if(ta&&typeof ta.onCommitFiberRoot=="function")try{ta.onCommitFiberRoot(ym,e,void 0,(e.current.flags&128)===128)}catch{}}var Ar=Math.clz32?Math.clz32:TF,AF=Math.log,$F=Math.LN2;function TF(e){return e>>>=0,e===0?32:31-(AF(e)/$F|0)|0}var Ud=64,Bd=4194304;function Dc(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 hf(e,n){var s=e.pendingLanes;if(s===0)return 0;var r=0,a=e.suspendedLanes,i=e.pingedLanes,l=s&268435455;if(l!==0){var o=l&~a;o!==0?r=Dc(o):(i&=l,i!==0&&(r=Dc(i)))}else l=s&~a,l!==0?r=Dc(l):i!==0&&(r=Dc(i));if(r===0)return 0;if(n!==0&&n!==r&&!(n&a)&&(a=r&-r,i=n&-n,a>=i||a===16&&(i&4194240)!==0))return n;if(r&4&&(r|=s&16),n=e.entangledLanes,n!==0)for(e=e.entanglements,n&=r;0<n;)s=31-Ar(n),a=1<<s,r|=e[s],n&=~a;return r}function RF(e,n){switch(e){case 1:case 2:case 4:return n+250;case 8:case 16:case 32:case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return n+5e3;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return-1;case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function IF(e,n){for(var s=e.suspendedLanes,r=e.pingedLanes,a=e.expirationTimes,i=e.pendingLanes;0<i;){var l=31-Ar(i),o=1<<l,c=a[l];c===-1?(!(o&s)||o&r)&&(a[l]=RF(o,n)):c<=n&&(e.expiredLanes|=o),i&=~o}}function Yx(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function DA(){var e=Ud;return Ud<<=1,!(Ud&4194240)&&(Ud=64),e}function Yp(e){for(var n=[],s=0;31>s;s++)n.push(e);return n}function ad(e,n,s){e.pendingLanes|=n,n!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,n=31-Ar(n),e[n]=s}function PF(e,n){var s=e.pendingLanes&~n;e.pendingLanes=n,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=n,e.mutableReadLanes&=n,e.entangledLanes&=n,n=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0<s;){var a=31-Ar(s),i=1<<a;n[a]=0,r[a]=-1,e[a]=-1,s&=~i}}function Hy(e,n){var s=e.entangledLanes|=n;for(e=e.entanglements;s;){var r=31-Ar(s),a=1<<r;a&n|e[r]&n&&(e[r]|=n),s&=~a}}var Ft=0;function LA(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var FA,Ky,_A,zA,UA,Qx=!1,Wd=[],si=null,ri=null,ai=null,du=new Map,hu=new Map,Qa=[],MF="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 V0(e,n){switch(e){case"focusin":case"focusout":si=null;break;case"dragenter":case"dragleave":ri=null;break;case"mouseover":case"mouseout":ai=null;break;case"pointerover":case"pointerout":du.delete(n.pointerId);break;case"gotpointercapture":case"lostpointercapture":hu.delete(n.pointerId)}}function vc(e,n,s,r,a,i){return e===null||e.nativeEvent!==i?(e={blockedOn:n,domEventName:s,eventSystemFlags:r,nativeEvent:i,targetContainers:[a]},n!==null&&(n=ld(n),n!==null&&Ky(n)),e):(e.eventSystemFlags|=r,n=e.targetContainers,a!==null&&n.indexOf(a)===-1&&n.push(a),e)}function OF(e,n,s,r,a){switch(n){case"focusin":return si=vc(si,e,n,s,r,a),!0;case"dragenter":return ri=vc(ri,e,n,s,r,a),!0;case"mouseover":return ai=vc(ai,e,n,s,r,a),!0;case"pointerover":var i=a.pointerId;return du.set(i,vc(du.get(i)||null,e,n,s,r,a)),!0;case"gotpointercapture":return i=a.pointerId,hu.set(i,vc(hu.get(i)||null,e,n,s,r,a)),!0}return!1}function BA(e){var n=Vi(e.target);if(n!==null){var s=yl(n);if(s!==null){if(n=s.tag,n===13){if(n=TA(s),n!==null){e.blockedOn=n,UA(e.priority,function(){_A(s)});return}}else if(n===3&&s.stateNode.current.memoizedState.isDehydrated){e.blockedOn=s.tag===3?s.stateNode.containerInfo:null;return}}}e.blockedOn=null}function Ih(e){if(e.blockedOn!==null)return!1;for(var n=e.targetContainers;0<n.length;){var s=Jx(e.domEventName,e.eventSystemFlags,n[0],e.nativeEvent);if(s===null){s=e.nativeEvent;var r=new s.constructor(s.type,s);Kx=r,s.target.dispatchEvent(r),Kx=null}else return n=ld(s),n!==null&&Ky(n),e.blockedOn=s,!1;n.shift()}return!0}function G0(e,n,s){Ih(e)&&s.delete(n)}function DF(){Qx=!1,si!==null&&Ih(si)&&(si=null),ri!==null&&Ih(ri)&&(ri=null),ai!==null&&Ih(ai)&&(ai=null),du.forEach(G0),hu.forEach(G0)}function yc(e,n){e.blockedOn===n&&(e.blockedOn=null,Qx||(Qx=!0,Hs.unstable_scheduleCallback(Hs.unstable_NormalPriority,DF)))}function fu(e){function n(a){return yc(a,e)}if(0<Wd.length){yc(Wd[0],e);for(var s=1;s<Wd.length;s++){var r=Wd[s];r.blockedOn===e&&(r.blockedOn=null)}}for(si!==null&&yc(si,e),ri!==null&&yc(ri,e),ai!==null&&yc(ai,e),du.forEach(n),hu.forEach(n),s=0;s<Qa.length;s++)r=Qa[s],r.blockedOn===e&&(r.blockedOn=null);for(;0<Qa.length&&(s=Qa[0],s.blockedOn===null);)BA(s),s.blockedOn===null&&Qa.shift()}var fo=Fa.ReactCurrentBatchConfig,ff=!0;function LF(e,n,s,r){var a=Ft,i=fo.transition;fo.transition=null;try{Ft=1,Vy(e,n,s,r)}finally{Ft=a,fo.transition=i}}function FF(e,n,s,r){var a=Ft,i=fo.transition;fo.transition=null;try{Ft=4,Vy(e,n,s,r)}finally{Ft=a,fo.transition=i}}function Vy(e,n,s,r){if(ff){var a=Jx(e,n,s,r);if(a===null)ag(e,n,r,mf,s),V0(e,r);else if(OF(a,e,n,s,r))r.stopPropagation();else if(V0(e,r),n&4&&-1<MF.indexOf(e)){for(;a!==null;){var i=ld(a);if(i!==null&&FA(i),i=Jx(e,n,s,r),i===null&&ag(e,n,r,mf,s),i===a)break;a=i}a!==null&&r.stopPropagation()}else ag(e,n,r,null,s)}}var mf=null;function Jx(e,n,s,r){if(mf=null,e=By(r),e=Vi(e),e!==null)if(n=yl(e),n===null)e=null;else if(s=n.tag,s===13){if(e=TA(n),e!==null)return e;e=null}else if(s===3){if(n.stateNode.current.memoizedState.isDehydrated)return n.tag===3?n.stateNode.containerInfo:null;e=null}else n!==e&&(e=null);return mf=e,null}function WA(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(SF()){case Wy:return 1;case MA:return 4;case df:case CF:return 16;case OA:return 536870912;default:return 16}default:return 16}}var Za=null,Gy=null,Ph=null;function HA(){if(Ph)return Ph;var e,n=Gy,s=n.length,r,a="value"in Za?Za.value:Za.textContent,i=a.length;for(e=0;e<s&&n[e]===a[e];e++);var l=s-e;for(r=1;r<=l&&n[s-r]===a[i-r];r++);return Ph=a.slice(e,1<r?1-r:void 0)}function Mh(e){var n=e.keyCode;return"charCode"in e?(e=e.charCode,e===0&&n===13&&(e=13)):e=n,e===10&&(e=13),32<=e||e===13?e:0}function Hd(){return!0}function q0(){return!1}function Ys(e){function n(s,r,a,i,l){this._reactName=s,this._targetInst=a,this.type=r,this.nativeEvent=i,this.target=l,this.currentTarget=null;for(var o in e)e.hasOwnProperty(o)&&(s=e[o],this[o]=s?s(i):i[o]);return this.isDefaultPrevented=(i.defaultPrevented!=null?i.defaultPrevented:i.returnValue===!1)?Hd:q0,this.isPropagationStopped=q0,this}return un(n.prototype,{preventDefault:function(){this.defaultPrevented=!0;var s=this.nativeEvent;s&&(s.preventDefault?s.preventDefault():typeof s.returnValue!="unknown"&&(s.returnValue=!1),this.isDefaultPrevented=Hd)},stopPropagation:function(){var s=this.nativeEvent;s&&(s.stopPropagation?s.stopPropagation():typeof s.cancelBubble!="unknown"&&(s.cancelBubble=!0),this.isPropagationStopped=Hd)},persist:function(){},isPersistent:Hd}),n}var Vo={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},qy=Ys(Vo),id=un({},Vo,{view:0,detail:0}),_F=Ys(id),Qp,Jp,wc,wm=un({},id,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:Yy,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!==wc&&(wc&&e.type==="mousemove"?(Qp=e.screenX-wc.screenX,Jp=e.screenY-wc.screenY):Jp=Qp=0,wc=e),Qp)},movementY:function(e){return"movementY"in e?e.movementY:Jp}}),Y0=Ys(wm),zF=un({},wm,{dataTransfer:0}),UF=Ys(zF),BF=un({},id,{relatedTarget:0}),Xp=Ys(BF),WF=un({},Vo,{animationName:0,elapsedTime:0,pseudoElement:0}),HF=Ys(WF),KF=un({},Vo,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),VF=Ys(KF),GF=un({},Vo,{data:0}),Q0=Ys(GF),qF={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},YF={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"},QF={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function JF(e){var n=this.nativeEvent;return n.getModifierState?n.getModifierState(e):(e=QF[e])?!!n[e]:!1}function Yy(){return JF}var XF=un({},id,{key:function(e){if(e.key){var n=qF[e.key]||e.key;if(n!=="Unidentified")return n}return e.type==="keypress"?(e=Mh(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?YF[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:Yy,charCode:function(e){return e.type==="keypress"?Mh(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?Mh(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),ZF=Ys(XF),e_=un({},wm,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),J0=Ys(e_),t_=un({},id,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:Yy}),n_=Ys(t_),s_=un({},Vo,{propertyName:0,elapsedTime:0,pseudoElement:0}),r_=Ys(s_),a_=un({},wm,{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}),i_=Ys(a_),l_=[9,13,27,32],Qy=Ta&&"CompositionEvent"in window,Kc=null;Ta&&"documentMode"in document&&(Kc=document.documentMode);var o_=Ta&&"TextEvent"in window&&!Kc,KA=Ta&&(!Qy||Kc&&8<Kc&&11>=Kc),X0=" ",Z0=!1;function VA(e,n){switch(e){case"keyup":return l_.indexOf(n.keyCode)!==-1;case"keydown":return n.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function GA(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var ql=!1;function c_(e,n){switch(e){case"compositionend":return GA(n);case"keypress":return n.which!==32?null:(Z0=!0,X0);case"textInput":return e=n.data,e===X0&&Z0?null:e;default:return null}}function u_(e,n){if(ql)return e==="compositionend"||!Qy&&VA(e,n)?(e=HA(),Ph=Gy=Za=null,ql=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(n.ctrlKey||n.altKey||n.metaKey)||n.ctrlKey&&n.altKey){if(n.char&&1<n.char.length)return n.char;if(n.which)return String.fromCharCode(n.which)}return null;case"compositionend":return KA&&n.locale!=="ko"?null:n.data;default:return null}}var d_={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 eN(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n==="input"?!!d_[e.type]:n==="textarea"}function qA(e,n,s,r){SA(r),n=pf(n,"onChange"),0<n.length&&(s=new qy("onChange","change",null,s,r),e.push({event:s,listeners:n}))}var Vc=null,mu=null;function h_(e){a$(e,0)}function bm(e){var n=Jl(e);if(jA(n))return e}function f_(e,n){if(e==="change")return n}var YA=!1;if(Ta){var Zp;if(Ta){var eg="oninput"in document;if(!eg){var tN=document.createElement("div");tN.setAttribute("oninput","return;"),eg=typeof tN.oninput=="function"}Zp=eg}else Zp=!1;YA=Zp&&(!document.documentMode||9<document.documentMode)}function nN(){Vc&&(Vc.detachEvent("onpropertychange",QA),mu=Vc=null)}function QA(e){if(e.propertyName==="value"&&bm(mu)){var n=[];qA(n,mu,e,By(e)),$A(h_,n)}}function m_(e,n,s){e==="focusin"?(nN(),Vc=n,mu=s,Vc.attachEvent("onpropertychange",QA)):e==="focusout"&&nN()}function p_(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return bm(mu)}function g_(e,n){if(e==="click")return bm(n)}function x_(e,n){if(e==="input"||e==="change")return bm(n)}function j_(e,n){return e===n&&(e!==0||1/e===1/n)||e!==e&&n!==n}var Ir=typeof Object.is=="function"?Object.is:j_;function pu(e,n){if(Ir(e,n))return!0;if(typeof e!="object"||e===null||typeof n!="object"||n===null)return!1;var s=Object.keys(e),r=Object.keys(n);if(s.length!==r.length)return!1;for(r=0;r<s.length;r++){var a=s[r];if(!Px.call(n,a)||!Ir(e[a],n[a]))return!1}return!0}function sN(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function rN(e,n){var s=sN(e);e=0;for(var r;s;){if(s.nodeType===3){if(r=e+s.textContent.length,e<=n&&r>=n)return{node:s,offset:n-e};e=r}e:{for(;s;){if(s.nextSibling){s=s.nextSibling;break e}s=s.parentNode}s=void 0}s=sN(s)}}function JA(e,n){return e&&n?e===n?!0:e&&e.nodeType===3?!1:n&&n.nodeType===3?JA(e,n.parentNode):"contains"in e?e.contains(n):e.compareDocumentPosition?!!(e.compareDocumentPosition(n)&16):!1:!1}function XA(){for(var e=window,n=of();n instanceof e.HTMLIFrameElement;){try{var s=typeof n.contentWindow.location.href=="string"}catch{s=!1}if(s)e=n.contentWindow;else break;n=of(e.document)}return n}function Jy(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n&&(n==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||n==="textarea"||e.contentEditable==="true")}function v_(e){var n=XA(),s=e.focusedElem,r=e.selectionRange;if(n!==s&&s&&s.ownerDocument&&JA(s.ownerDocument.documentElement,s)){if(r!==null&&Jy(s)){if(n=r.start,e=r.end,e===void 0&&(e=n),"selectionStart"in s)s.selectionStart=n,s.selectionEnd=Math.min(e,s.value.length);else if(e=(n=s.ownerDocument||document)&&n.defaultView||window,e.getSelection){e=e.getSelection();var a=s.textContent.length,i=Math.min(r.start,a);r=r.end===void 0?i:Math.min(r.end,a),!e.extend&&i>r&&(a=r,r=i,i=a),a=rN(s,i);var l=rN(s,r);a&&l&&(e.rangeCount!==1||e.anchorNode!==a.node||e.anchorOffset!==a.offset||e.focusNode!==l.node||e.focusOffset!==l.offset)&&(n=n.createRange(),n.setStart(a.node,a.offset),e.removeAllRanges(),i>r?(e.addRange(n),e.extend(l.node,l.offset)):(n.setEnd(l.node,l.offset),e.addRange(n)))}}for(n=[],e=s;e=e.parentNode;)e.nodeType===1&&n.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof s.focus=="function"&&s.focus(),s=0;s<n.length;s++)e=n[s],e.element.scrollLeft=e.left,e.element.scrollTop=e.top}}var y_=Ta&&"documentMode"in document&&11>=document.documentMode,Yl=null,Xx=null,Gc=null,Zx=!1;function aN(e,n,s){var r=s.window===s?s.document:s.nodeType===9?s:s.ownerDocument;Zx||Yl==null||Yl!==of(r)||(r=Yl,"selectionStart"in r&&Jy(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}),Gc&&pu(Gc,r)||(Gc=r,r=pf(Xx,"onSelect"),0<r.length&&(n=new qy("onSelect","select",null,n,s),e.push({event:n,listeners:r}),n.target=Yl)))}function Kd(e,n){var s={};return s[e.toLowerCase()]=n.toLowerCase(),s["Webkit"+e]="webkit"+n,s["Moz"+e]="moz"+n,s}var Ql={animationend:Kd("Animation","AnimationEnd"),animationiteration:Kd("Animation","AnimationIteration"),animationstart:Kd("Animation","AnimationStart"),transitionend:Kd("Transition","TransitionEnd")},tg={},ZA={};Ta&&(ZA=document.createElement("div").style,"AnimationEvent"in window||(delete Ql.animationend.animation,delete Ql.animationiteration.animation,delete Ql.animationstart.animation),"TransitionEvent"in window||delete Ql.transitionend.transition);function km(e){if(tg[e])return tg[e];if(!Ql[e])return e;var n=Ql[e],s;for(s in n)if(n.hasOwnProperty(s)&&s in ZA)return tg[e]=n[s];return e}var e$=km("animationend"),t$=km("animationiteration"),n$=km("animationstart"),s$=km("transitionend"),r$=new Map,iN="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 Ni(e,n){r$.set(e,n),vl(n,[e])}for(var ng=0;ng<iN.length;ng++){var sg=iN[ng],w_=sg.toLowerCase(),b_=sg[0].toUpperCase()+sg.slice(1);Ni(w_,"on"+b_)}Ni(e$,"onAnimationEnd");Ni(t$,"onAnimationIteration");Ni(n$,"onAnimationStart");Ni("dblclick","onDoubleClick");Ni("focusin","onFocus");Ni("focusout","onBlur");Ni(s$,"onTransitionEnd");ko("onMouseEnter",["mouseout","mouseover"]);ko("onMouseLeave",["mouseout","mouseover"]);ko("onPointerEnter",["pointerout","pointerover"]);ko("onPointerLeave",["pointerout","pointerover"]);vl("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));vl("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));vl("onBeforeInput",["compositionend","keypress","textInput","paste"]);vl("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));vl("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));vl("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var Lc="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(" "),k_=new Set("cancel close invalid load scroll toggle".split(" ").concat(Lc));function lN(e,n,s){var r=e.type||"unknown-event";e.currentTarget=s,wF(r,n,void 0,e),e.currentTarget=null}function a$(e,n){n=(n&4)!==0;for(var s=0;s<e.length;s++){var r=e[s],a=r.event;r=r.listeners;e:{var i=void 0;if(n)for(var l=r.length-1;0<=l;l--){var o=r[l],c=o.instance,u=o.currentTarget;if(o=o.listener,c!==i&&a.isPropagationStopped())break e;lN(a,o,u),i=c}else for(l=0;l<r.length;l++){if(o=r[l],c=o.instance,u=o.currentTarget,o=o.listener,c!==i&&a.isPropagationStopped())break e;lN(a,o,u),i=c}}}if(uf)throw e=qx,uf=!1,qx=null,e}function Jt(e,n){var s=n[rj];s===void 0&&(s=n[rj]=new Set);var r=e+"__bubble";s.has(r)||(i$(n,e,2,!1),s.add(r))}function rg(e,n,s){var r=0;n&&(r|=4),i$(s,e,r,n)}var Vd="_reactListening"+Math.random().toString(36).slice(2);function gu(e){if(!e[Vd]){e[Vd]=!0,fA.forEach(function(s){s!=="selectionchange"&&(k_.has(s)||rg(s,!1,e),rg(s,!0,e))});var n=e.nodeType===9?e:e.ownerDocument;n===null||n[Vd]||(n[Vd]=!0,rg("selectionchange",!1,n))}}function i$(e,n,s,r){switch(WA(n)){case 1:var a=LF;break;case 4:a=FF;break;default:a=Vy}s=a.bind(null,n,s,e),a=void 0,!Gx||n!=="touchstart"&&n!=="touchmove"&&n!=="wheel"||(a=!0),r?a!==void 0?e.addEventListener(n,s,{capture:!0,passive:a}):e.addEventListener(n,s,!0):a!==void 0?e.addEventListener(n,s,{passive:a}):e.addEventListener(n,s,!1)}function ag(e,n,s,r,a){var i=r;if(!(n&1)&&!(n&2)&&r!==null)e:for(;;){if(r===null)return;var l=r.tag;if(l===3||l===4){var o=r.stateNode.containerInfo;if(o===a||o.nodeType===8&&o.parentNode===a)break;if(l===4)for(l=r.return;l!==null;){var c=l.tag;if((c===3||c===4)&&(c=l.stateNode.containerInfo,c===a||c.nodeType===8&&c.parentNode===a))return;l=l.return}for(;o!==null;){if(l=Vi(o),l===null)return;if(c=l.tag,c===5||c===6){r=i=l;continue e}o=o.parentNode}}r=r.return}$A(function(){var u=i,h=By(s),m=[];e:{var f=r$.get(e);if(f!==void 0){var p=qy,x=e;switch(e){case"keypress":if(Mh(s)===0)break e;case"keydown":case"keyup":p=ZF;break;case"focusin":x="focus",p=Xp;break;case"focusout":x="blur",p=Xp;break;case"beforeblur":case"afterblur":p=Xp;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=Y0;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":p=UF;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":p=n_;break;case e$:case t$:case n$:p=HF;break;case s$:p=r_;break;case"scroll":p=_F;break;case"wheel":p=i_;break;case"copy":case"cut":case"paste":p=VF;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":p=J0}var g=(n&4)!==0,w=!g&&e==="scroll",v=g?f!==null?f+"Capture":null:f;g=[];for(var j=u,y;j!==null;){y=j;var k=y.stateNode;if(y.tag===5&&k!==null&&(y=k,v!==null&&(k=uu(j,v),k!=null&&g.push(xu(j,k,y)))),w)break;j=j.return}0<g.length&&(f=new p(f,x,null,s,h),m.push({event:f,listeners:g}))}}if(!(n&7)){e:{if(f=e==="mouseover"||e==="pointerover",p=e==="mouseout"||e==="pointerout",f&&s!==Kx&&(x=s.relatedTarget||s.fromElement)&&(Vi(x)||x[Ra]))break e;if((p||f)&&(f=h.window===h?h:(f=h.ownerDocument)?f.defaultView||f.parentWindow:window,p?(x=s.relatedTarget||s.toElement,p=u,x=x?Vi(x):null,x!==null&&(w=yl(x),x!==w||x.tag!==5&&x.tag!==6)&&(x=null)):(p=null,x=u),p!==x)){if(g=Y0,k="onMouseLeave",v="onMouseEnter",j="mouse",(e==="pointerout"||e==="pointerover")&&(g=J0,k="onPointerLeave",v="onPointerEnter",j="pointer"),w=p==null?f:Jl(p),y=x==null?f:Jl(x),f=new g(k,j+"leave",p,s,h),f.target=w,f.relatedTarget=y,k=null,Vi(h)===u&&(g=new g(v,j+"enter",x,s,h),g.target=y,g.relatedTarget=w,k=g),w=k,p&&x)t:{for(g=p,v=x,j=0,y=g;y;y=Ml(y))j++;for(y=0,k=v;k;k=Ml(k))y++;for(;0<j-y;)g=Ml(g),j--;for(;0<y-j;)v=Ml(v),y--;for(;j--;){if(g===v||v!==null&&g===v.alternate)break t;g=Ml(g),v=Ml(v)}g=null}else g=null;p!==null&&oN(m,f,p,g,!1),x!==null&&w!==null&&oN(m,w,x,g,!0)}}e:{if(f=u?Jl(u):window,p=f.nodeName&&f.nodeName.toLowerCase(),p==="select"||p==="input"&&f.type==="file")var N=f_;else if(eN(f))if(YA)N=x_;else{N=p_;var b=m_}else(p=f.nodeName)&&p.toLowerCase()==="input"&&(f.type==="checkbox"||f.type==="radio")&&(N=g_);if(N&&(N=N(e,u))){qA(m,N,s,h);break e}b&&b(e,f,u),e==="focusout"&&(b=f._wrapperState)&&b.controlled&&f.type==="number"&&zx(f,"number",f.value)}switch(b=u?Jl(u):window,e){case"focusin":(eN(b)||b.contentEditable==="true")&&(Yl=b,Xx=u,Gc=null);break;case"focusout":Gc=Xx=Yl=null;break;case"mousedown":Zx=!0;break;case"contextmenu":case"mouseup":case"dragend":Zx=!1,aN(m,s,h);break;case"selectionchange":if(y_)break;case"keydown":case"keyup":aN(m,s,h)}var S;if(Qy)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 ql?VA(e,s)&&(C="onCompositionEnd"):e==="keydown"&&s.keyCode===229&&(C="onCompositionStart");C&&(KA&&s.locale!=="ko"&&(ql||C!=="onCompositionStart"?C==="onCompositionEnd"&&ql&&(S=HA()):(Za=h,Gy="value"in Za?Za.value:Za.textContent,ql=!0)),b=pf(u,C),0<b.length&&(C=new Q0(C,e,null,s,h),m.push({event:C,listeners:b}),S?C.data=S:(S=GA(s),S!==null&&(C.data=S)))),(S=o_?c_(e,s):u_(e,s))&&(u=pf(u,"onBeforeInput"),0<u.length&&(h=new Q0("onBeforeInput","beforeinput",null,s,h),m.push({event:h,listeners:u}),h.data=S))}a$(m,n)})}function xu(e,n,s){return{instance:e,listener:n,currentTarget:s}}function pf(e,n){for(var s=n+"Capture",r=[];e!==null;){var a=e,i=a.stateNode;a.tag===5&&i!==null&&(a=i,i=uu(e,s),i!=null&&r.unshift(xu(e,i,a)),i=uu(e,n),i!=null&&r.push(xu(e,i,a))),e=e.return}return r}function Ml(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function oN(e,n,s,r,a){for(var i=n._reactName,l=[];s!==null&&s!==r;){var o=s,c=o.alternate,u=o.stateNode;if(c!==null&&c===r)break;o.tag===5&&u!==null&&(o=u,a?(c=uu(s,i),c!=null&&l.unshift(xu(s,c,o))):a||(c=uu(s,i),c!=null&&l.push(xu(s,c,o)))),s=s.return}l.length!==0&&e.push({event:n,listeners:l})}var N_=/\r\n?/g,S_=/\u0000|\uFFFD/g;function cN(e){return(typeof e=="string"?e:""+e).replace(N_,`
38
- `).replace(S_,"")}function Gd(e,n,s){if(n=cN(n),cN(e)!==n&&s)throw Error(Te(425))}function gf(){}var ej=null,tj=null;function nj(e,n){return e==="textarea"||e==="noscript"||typeof n.children=="string"||typeof n.children=="number"||typeof n.dangerouslySetInnerHTML=="object"&&n.dangerouslySetInnerHTML!==null&&n.dangerouslySetInnerHTML.__html!=null}var sj=typeof setTimeout=="function"?setTimeout:void 0,C_=typeof clearTimeout=="function"?clearTimeout:void 0,uN=typeof Promise=="function"?Promise:void 0,E_=typeof queueMicrotask=="function"?queueMicrotask:typeof uN<"u"?function(e){return uN.resolve(null).then(e).catch(A_)}:sj;function A_(e){setTimeout(function(){throw e})}function ig(e,n){var s=n,r=0;do{var a=s.nextSibling;if(e.removeChild(s),a&&a.nodeType===8)if(s=a.data,s==="/$"){if(r===0){e.removeChild(a),fu(n);return}r--}else s!=="$"&&s!=="$?"&&s!=="$!"||r++;s=a}while(s);fu(n)}function ii(e){for(;e!=null;e=e.nextSibling){var n=e.nodeType;if(n===1||n===3)break;if(n===8){if(n=e.data,n==="$"||n==="$!"||n==="$?")break;if(n==="/$")return null}}return e}function dN(e){e=e.previousSibling;for(var n=0;e;){if(e.nodeType===8){var s=e.data;if(s==="$"||s==="$!"||s==="$?"){if(n===0)return e;n--}else s==="/$"&&n++}e=e.previousSibling}return null}var Go=Math.random().toString(36).slice(2),Yr="__reactFiber$"+Go,ju="__reactProps$"+Go,Ra="__reactContainer$"+Go,rj="__reactEvents$"+Go,$_="__reactListeners$"+Go,T_="__reactHandles$"+Go;function Vi(e){var n=e[Yr];if(n)return n;for(var s=e.parentNode;s;){if(n=s[Ra]||s[Yr]){if(s=n.alternate,n.child!==null||s!==null&&s.child!==null)for(e=dN(e);e!==null;){if(s=e[Yr])return s;e=dN(e)}return n}e=s,s=e.parentNode}return null}function ld(e){return e=e[Yr]||e[Ra],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function Jl(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(Te(33))}function Nm(e){return e[ju]||null}var aj=[],Xl=-1;function Si(e){return{current:e}}function Xt(e){0>Xl||(e.current=aj[Xl],aj[Xl]=null,Xl--)}function Yt(e,n){Xl++,aj[Xl]=e.current,e.current=n}var pi={},ns=Si(pi),Ss=Si(!1),al=pi;function No(e,n){var s=e.type.contextTypes;if(!s)return pi;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===n)return r.__reactInternalMemoizedMaskedChildContext;var a={},i;for(i in s)a[i]=n[i];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=n,e.__reactInternalMemoizedMaskedChildContext=a),a}function Cs(e){return e=e.childContextTypes,e!=null}function xf(){Xt(Ss),Xt(ns)}function hN(e,n,s){if(ns.current!==pi)throw Error(Te(168));Yt(ns,n),Yt(Ss,s)}function l$(e,n,s){var r=e.stateNode;if(n=n.childContextTypes,typeof r.getChildContext!="function")return s;r=r.getChildContext();for(var a in r)if(!(a in n))throw Error(Te(108,mF(e)||"Unknown",a));return un({},s,r)}function jf(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||pi,al=ns.current,Yt(ns,e),Yt(Ss,Ss.current),!0}function fN(e,n,s){var r=e.stateNode;if(!r)throw Error(Te(169));s?(e=l$(e,n,al),r.__reactInternalMemoizedMergedChildContext=e,Xt(Ss),Xt(ns),Yt(ns,e)):Xt(Ss),Yt(Ss,s)}var va=null,Sm=!1,lg=!1;function o$(e){va===null?va=[e]:va.push(e)}function R_(e){Sm=!0,o$(e)}function Ci(){if(!lg&&va!==null){lg=!0;var e=0,n=Ft;try{var s=va;for(Ft=1;e<s.length;e++){var r=s[e];do r=r(!0);while(r!==null)}va=null,Sm=!1}catch(a){throw va!==null&&(va=va.slice(e+1)),PA(Wy,Ci),a}finally{Ft=n,lg=!1}}return null}var Zl=[],eo=0,vf=null,yf=0,ar=[],ir=0,il=null,ka=1,Na="";function Bi(e,n){Zl[eo++]=yf,Zl[eo++]=vf,vf=e,yf=n}function c$(e,n,s){ar[ir++]=ka,ar[ir++]=Na,ar[ir++]=il,il=e;var r=ka;e=Na;var a=32-Ar(r)-1;r&=~(1<<a),s+=1;var i=32-Ar(n)+a;if(30<i){var l=a-a%5;i=(r&(1<<l)-1).toString(32),r>>=l,a-=l,ka=1<<32-Ar(n)+a|s<<a|r,Na=i+e}else ka=1<<i|s<<a|r,Na=e}function Xy(e){e.return!==null&&(Bi(e,1),c$(e,1,0))}function Zy(e){for(;e===vf;)vf=Zl[--eo],Zl[eo]=null,yf=Zl[--eo],Zl[eo]=null;for(;e===il;)il=ar[--ir],ar[ir]=null,Na=ar[--ir],ar[ir]=null,ka=ar[--ir],ar[ir]=null}var zs=null,Fs=null,tn=!1,Nr=null;function u$(e,n){var s=cr(5,null,null,0);s.elementType="DELETED",s.stateNode=n,s.return=e,n=e.deletions,n===null?(e.deletions=[s],e.flags|=16):n.push(s)}function mN(e,n){switch(e.tag){case 5:var s=e.type;return n=n.nodeType!==1||s.toLowerCase()!==n.nodeName.toLowerCase()?null:n,n!==null?(e.stateNode=n,zs=e,Fs=ii(n.firstChild),!0):!1;case 6:return n=e.pendingProps===""||n.nodeType!==3?null:n,n!==null?(e.stateNode=n,zs=e,Fs=null,!0):!1;case 13:return n=n.nodeType!==8?null:n,n!==null?(s=il!==null?{id:ka,overflow:Na}:null,e.memoizedState={dehydrated:n,treeContext:s,retryLane:1073741824},s=cr(18,null,null,0),s.stateNode=n,s.return=e,e.child=s,zs=e,Fs=null,!0):!1;default:return!1}}function ij(e){return(e.mode&1)!==0&&(e.flags&128)===0}function lj(e){if(tn){var n=Fs;if(n){var s=n;if(!mN(e,n)){if(ij(e))throw Error(Te(418));n=ii(s.nextSibling);var r=zs;n&&mN(e,n)?u$(r,s):(e.flags=e.flags&-4097|2,tn=!1,zs=e)}}else{if(ij(e))throw Error(Te(418));e.flags=e.flags&-4097|2,tn=!1,zs=e}}}function pN(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;zs=e}function qd(e){if(e!==zs)return!1;if(!tn)return pN(e),tn=!0,!1;var n;if((n=e.tag!==3)&&!(n=e.tag!==5)&&(n=e.type,n=n!=="head"&&n!=="body"&&!nj(e.type,e.memoizedProps)),n&&(n=Fs)){if(ij(e))throw d$(),Error(Te(418));for(;n;)u$(e,n),n=ii(n.nextSibling)}if(pN(e),e.tag===13){if(e=e.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(Te(317));e:{for(e=e.nextSibling,n=0;e;){if(e.nodeType===8){var s=e.data;if(s==="/$"){if(n===0){Fs=ii(e.nextSibling);break e}n--}else s!=="$"&&s!=="$!"&&s!=="$?"||n++}e=e.nextSibling}Fs=null}}else Fs=zs?ii(e.stateNode.nextSibling):null;return!0}function d$(){for(var e=Fs;e;)e=ii(e.nextSibling)}function So(){Fs=zs=null,tn=!1}function ew(e){Nr===null?Nr=[e]:Nr.push(e)}var I_=Fa.ReactCurrentBatchConfig;function bc(e,n,s){if(e=s.ref,e!==null&&typeof e!="function"&&typeof e!="object"){if(s._owner){if(s=s._owner,s){if(s.tag!==1)throw Error(Te(309));var r=s.stateNode}if(!r)throw Error(Te(147,e));var a=r,i=""+e;return n!==null&&n.ref!==null&&typeof n.ref=="function"&&n.ref._stringRef===i?n.ref:(n=function(l){var o=a.refs;l===null?delete o[i]:o[i]=l},n._stringRef=i,n)}if(typeof e!="string")throw Error(Te(284));if(!s._owner)throw Error(Te(290,e))}return e}function Yd(e,n){throw e=Object.prototype.toString.call(n),Error(Te(31,e==="[object Object]"?"object with keys {"+Object.keys(n).join(", ")+"}":e))}function gN(e){var n=e._init;return n(e._payload)}function h$(e){function n(v,j){if(e){var y=v.deletions;y===null?(v.deletions=[j],v.flags|=16):y.push(j)}}function s(v,j){if(!e)return null;for(;j!==null;)n(v,j),j=j.sibling;return null}function r(v,j){for(v=new Map;j!==null;)j.key!==null?v.set(j.key,j):v.set(j.index,j),j=j.sibling;return v}function a(v,j){return v=ui(v,j),v.index=0,v.sibling=null,v}function i(v,j,y){return v.index=y,e?(y=v.alternate,y!==null?(y=y.index,y<j?(v.flags|=2,j):y):(v.flags|=2,j)):(v.flags|=1048576,j)}function l(v){return e&&v.alternate===null&&(v.flags|=2),v}function o(v,j,y,k){return j===null||j.tag!==6?(j=mg(y,v.mode,k),j.return=v,j):(j=a(j,y),j.return=v,j)}function c(v,j,y,k){var N=y.type;return N===Gl?h(v,j,y.props.children,k,y.key):j!==null&&(j.elementType===N||typeof N=="object"&&N!==null&&N.$$typeof===qa&&gN(N)===j.type)?(k=a(j,y.props),k.ref=bc(v,j,y),k.return=v,k):(k=Uh(y.type,y.key,y.props,null,v.mode,k),k.ref=bc(v,j,y),k.return=v,k)}function u(v,j,y,k){return j===null||j.tag!==4||j.stateNode.containerInfo!==y.containerInfo||j.stateNode.implementation!==y.implementation?(j=pg(y,v.mode,k),j.return=v,j):(j=a(j,y.children||[]),j.return=v,j)}function h(v,j,y,k,N){return j===null||j.tag!==7?(j=tl(y,v.mode,k,N),j.return=v,j):(j=a(j,y),j.return=v,j)}function m(v,j,y){if(typeof j=="string"&&j!==""||typeof j=="number")return j=mg(""+j,v.mode,y),j.return=v,j;if(typeof j=="object"&&j!==null){switch(j.$$typeof){case Fd:return y=Uh(j.type,j.key,j.props,null,v.mode,y),y.ref=bc(v,null,j),y.return=v,y;case Vl:return j=pg(j,v.mode,y),j.return=v,j;case qa:var k=j._init;return m(v,k(j._payload),y)}if(Oc(j)||xc(j))return j=tl(j,v.mode,y,null),j.return=v,j;Yd(v,j)}return null}function f(v,j,y,k){var N=j!==null?j.key:null;if(typeof y=="string"&&y!==""||typeof y=="number")return N!==null?null:o(v,j,""+y,k);if(typeof y=="object"&&y!==null){switch(y.$$typeof){case Fd:return y.key===N?c(v,j,y,k):null;case Vl:return y.key===N?u(v,j,y,k):null;case qa:return N=y._init,f(v,j,N(y._payload),k)}if(Oc(y)||xc(y))return N!==null?null:h(v,j,y,k,null);Yd(v,y)}return null}function p(v,j,y,k,N){if(typeof k=="string"&&k!==""||typeof k=="number")return v=v.get(y)||null,o(j,v,""+k,N);if(typeof k=="object"&&k!==null){switch(k.$$typeof){case Fd:return v=v.get(k.key===null?y:k.key)||null,c(j,v,k,N);case Vl:return v=v.get(k.key===null?y:k.key)||null,u(j,v,k,N);case qa:var b=k._init;return p(v,j,y,b(k._payload),N)}if(Oc(k)||xc(k))return v=v.get(y)||null,h(j,v,k,N,null);Yd(j,k)}return null}function x(v,j,y,k){for(var N=null,b=null,S=j,C=j=0,A=null;S!==null&&C<y.length;C++){S.index>C?(A=S,S=null):A=S.sibling;var E=f(v,S,y[C],k);if(E===null){S===null&&(S=A);break}e&&S&&E.alternate===null&&n(v,S),j=i(E,j,C),b===null?N=E:b.sibling=E,b=E,S=A}if(C===y.length)return s(v,S),tn&&Bi(v,C),N;if(S===null){for(;C<y.length;C++)S=m(v,y[C],k),S!==null&&(j=i(S,j,C),b===null?N=S:b.sibling=S,b=S);return tn&&Bi(v,C),N}for(S=r(v,S);C<y.length;C++)A=p(S,v,C,y[C],k),A!==null&&(e&&A.alternate!==null&&S.delete(A.key===null?C:A.key),j=i(A,j,C),b===null?N=A:b.sibling=A,b=A);return e&&S.forEach(function(R){return n(v,R)}),tn&&Bi(v,C),N}function g(v,j,y,k){var N=xc(y);if(typeof N!="function")throw Error(Te(150));if(y=N.call(y),y==null)throw Error(Te(151));for(var b=N=null,S=j,C=j=0,A=null,E=y.next();S!==null&&!E.done;C++,E=y.next()){S.index>C?(A=S,S=null):A=S.sibling;var R=f(v,S,E.value,k);if(R===null){S===null&&(S=A);break}e&&S&&R.alternate===null&&n(v,S),j=i(R,j,C),b===null?N=R:b.sibling=R,b=R,S=A}if(E.done)return s(v,S),tn&&Bi(v,C),N;if(S===null){for(;!E.done;C++,E=y.next())E=m(v,E.value,k),E!==null&&(j=i(E,j,C),b===null?N=E:b.sibling=E,b=E);return tn&&Bi(v,C),N}for(S=r(v,S);!E.done;C++,E=y.next())E=p(S,v,C,E.value,k),E!==null&&(e&&E.alternate!==null&&S.delete(E.key===null?C:E.key),j=i(E,j,C),b===null?N=E:b.sibling=E,b=E);return e&&S.forEach(function(P){return n(v,P)}),tn&&Bi(v,C),N}function w(v,j,y,k){if(typeof y=="object"&&y!==null&&y.type===Gl&&y.key===null&&(y=y.props.children),typeof y=="object"&&y!==null){switch(y.$$typeof){case Fd:e:{for(var N=y.key,b=j;b!==null;){if(b.key===N){if(N=y.type,N===Gl){if(b.tag===7){s(v,b.sibling),j=a(b,y.props.children),j.return=v,v=j;break e}}else if(b.elementType===N||typeof N=="object"&&N!==null&&N.$$typeof===qa&&gN(N)===b.type){s(v,b.sibling),j=a(b,y.props),j.ref=bc(v,b,y),j.return=v,v=j;break e}s(v,b);break}else n(v,b);b=b.sibling}y.type===Gl?(j=tl(y.props.children,v.mode,k,y.key),j.return=v,v=j):(k=Uh(y.type,y.key,y.props,null,v.mode,k),k.ref=bc(v,j,y),k.return=v,v=k)}return l(v);case Vl:e:{for(b=y.key;j!==null;){if(j.key===b)if(j.tag===4&&j.stateNode.containerInfo===y.containerInfo&&j.stateNode.implementation===y.implementation){s(v,j.sibling),j=a(j,y.children||[]),j.return=v,v=j;break e}else{s(v,j);break}else n(v,j);j=j.sibling}j=pg(y,v.mode,k),j.return=v,v=j}return l(v);case qa:return b=y._init,w(v,j,b(y._payload),k)}if(Oc(y))return x(v,j,y,k);if(xc(y))return g(v,j,y,k);Yd(v,y)}return typeof y=="string"&&y!==""||typeof y=="number"?(y=""+y,j!==null&&j.tag===6?(s(v,j.sibling),j=a(j,y),j.return=v,v=j):(s(v,j),j=mg(y,v.mode,k),j.return=v,v=j),l(v)):s(v,j)}return w}var Co=h$(!0),f$=h$(!1),wf=Si(null),bf=null,to=null,tw=null;function nw(){tw=to=bf=null}function sw(e){var n=wf.current;Xt(wf),e._currentValue=n}function oj(e,n,s){for(;e!==null;){var r=e.alternate;if((e.childLanes&n)!==n?(e.childLanes|=n,r!==null&&(r.childLanes|=n)):r!==null&&(r.childLanes&n)!==n&&(r.childLanes|=n),e===s)break;e=e.return}}function mo(e,n){bf=e,tw=to=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&n&&(ks=!0),e.firstContext=null)}function hr(e){var n=e._currentValue;if(tw!==e)if(e={context:e,memoizedValue:n,next:null},to===null){if(bf===null)throw Error(Te(308));to=e,bf.dependencies={lanes:0,firstContext:e}}else to=to.next=e;return n}var Gi=null;function rw(e){Gi===null?Gi=[e]:Gi.push(e)}function m$(e,n,s,r){var a=n.interleaved;return a===null?(s.next=s,rw(n)):(s.next=a.next,a.next=s),n.interleaved=s,Ia(e,r)}function Ia(e,n){e.lanes|=n;var s=e.alternate;for(s!==null&&(s.lanes|=n),s=e,e=e.return;e!==null;)e.childLanes|=n,s=e.alternate,s!==null&&(s.childLanes|=n),s=e,e=e.return;return s.tag===3?s.stateNode:null}var Ya=!1;function aw(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function p$(e,n){e=e.updateQueue,n.updateQueue===e&&(n.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function Sa(e,n){return{eventTime:e,lane:n,tag:0,payload:null,callback:null,next:null}}function li(e,n,s){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,Rt&2){var a=r.pending;return a===null?n.next=n:(n.next=a.next,a.next=n),r.pending=n,Ia(e,s)}return a=r.interleaved,a===null?(n.next=n,rw(r)):(n.next=a.next,a.next=n),r.interleaved=n,Ia(e,s)}function Oh(e,n,s){if(n=n.updateQueue,n!==null&&(n=n.shared,(s&4194240)!==0)){var r=n.lanes;r&=e.pendingLanes,s|=r,n.lanes=s,Hy(e,s)}}function xN(e,n){var s=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,s===r)){var a=null,i=null;if(s=s.firstBaseUpdate,s!==null){do{var l={eventTime:s.eventTime,lane:s.lane,tag:s.tag,payload:s.payload,callback:s.callback,next:null};i===null?a=i=l:i=i.next=l,s=s.next}while(s!==null);i===null?a=i=n:i=i.next=n}else a=i=n;s={baseState:r.baseState,firstBaseUpdate:a,lastBaseUpdate:i,shared:r.shared,effects:r.effects},e.updateQueue=s;return}e=s.lastBaseUpdate,e===null?s.firstBaseUpdate=n:e.next=n,s.lastBaseUpdate=n}function kf(e,n,s,r){var a=e.updateQueue;Ya=!1;var i=a.firstBaseUpdate,l=a.lastBaseUpdate,o=a.shared.pending;if(o!==null){a.shared.pending=null;var c=o,u=c.next;c.next=null,l===null?i=u:l.next=u,l=c;var 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(i!==null){var m=a.baseState;l=0,h=u=c=null,o=i;do{var f=o.lane,p=o.eventTime;if((r&f)===f){h!==null&&(h=h.next={eventTime:p,lane:0,tag:o.tag,payload:o.payload,callback:o.callback,next:null});e:{var x=e,g=o;switch(f=n,p=s,g.tag){case 1:if(x=g.payload,typeof x=="function"){m=x.call(p,m,f);break e}m=x;break e;case 3:x.flags=x.flags&-65537|128;case 0:if(x=g.payload,f=typeof x=="function"?x.call(p,m,f):x,f==null)break e;m=un({},m,f);break e;case 2:Ya=!0}}o.callback!==null&&o.lane!==0&&(e.flags|=64,f=a.effects,f===null?a.effects=[o]:f.push(o))}else p={eventTime:p,lane:f,tag:o.tag,payload:o.payload,callback:o.callback,next:null},h===null?(u=h=p,c=m):h=h.next=p,l|=f;if(o=o.next,o===null){if(o=a.shared.pending,o===null)break;f=o,o=f.next,f.next=null,a.lastBaseUpdate=f,a.shared.pending=null}}while(!0);if(h===null&&(c=m),a.baseState=c,a.firstBaseUpdate=u,a.lastBaseUpdate=h,n=a.shared.interleaved,n!==null){a=n;do l|=a.lane,a=a.next;while(a!==n)}else i===null&&(a.shared.lanes=0);ol|=l,e.lanes=l,e.memoizedState=m}}function jN(e,n,s){if(e=n.effects,n.effects=null,e!==null)for(n=0;n<e.length;n++){var r=e[n],a=r.callback;if(a!==null){if(r.callback=null,r=s,typeof a!="function")throw Error(Te(191,a));a.call(r)}}}var od={},na=Si(od),vu=Si(od),yu=Si(od);function qi(e){if(e===od)throw Error(Te(174));return e}function iw(e,n){switch(Yt(yu,n),Yt(vu,e),Yt(na,od),e=n.nodeType,e){case 9:case 11:n=(n=n.documentElement)?n.namespaceURI:Bx(null,"");break;default:e=e===8?n.parentNode:n,n=e.namespaceURI||null,e=e.tagName,n=Bx(n,e)}Xt(na),Yt(na,n)}function Eo(){Xt(na),Xt(vu),Xt(yu)}function g$(e){qi(yu.current);var n=qi(na.current),s=Bx(n,e.type);n!==s&&(Yt(vu,e),Yt(na,s))}function lw(e){vu.current===e&&(Xt(na),Xt(vu))}var rn=Si(0);function Nf(e){for(var n=e;n!==null;){if(n.tag===13){var s=n.memoizedState;if(s!==null&&(s=s.dehydrated,s===null||s.data==="$?"||s.data==="$!"))return n}else if(n.tag===19&&n.memoizedProps.revealOrder!==void 0){if(n.flags&128)return n}else if(n.child!==null){n.child.return=n,n=n.child;continue}if(n===e)break;for(;n.sibling===null;){if(n.return===null||n.return===e)return null;n=n.return}n.sibling.return=n.return,n=n.sibling}return null}var og=[];function ow(){for(var e=0;e<og.length;e++)og[e]._workInProgressVersionPrimary=null;og.length=0}var Dh=Fa.ReactCurrentDispatcher,cg=Fa.ReactCurrentBatchConfig,ll=0,an=null,Tn=null,Ln=null,Sf=!1,qc=!1,wu=0,P_=0;function Jn(){throw Error(Te(321))}function cw(e,n){if(n===null)return!1;for(var s=0;s<n.length&&s<e.length;s++)if(!Ir(e[s],n[s]))return!1;return!0}function uw(e,n,s,r,a,i){if(ll=i,an=n,n.memoizedState=null,n.updateQueue=null,n.lanes=0,Dh.current=e===null||e.memoizedState===null?L_:F_,e=s(r,a),qc){i=0;do{if(qc=!1,wu=0,25<=i)throw Error(Te(301));i+=1,Ln=Tn=null,n.updateQueue=null,Dh.current=__,e=s(r,a)}while(qc)}if(Dh.current=Cf,n=Tn!==null&&Tn.next!==null,ll=0,Ln=Tn=an=null,Sf=!1,n)throw Error(Te(300));return e}function dw(){var e=wu!==0;return wu=0,e}function Gr(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return Ln===null?an.memoizedState=Ln=e:Ln=Ln.next=e,Ln}function fr(){if(Tn===null){var e=an.alternate;e=e!==null?e.memoizedState:null}else e=Tn.next;var n=Ln===null?an.memoizedState:Ln.next;if(n!==null)Ln=n,Tn=e;else{if(e===null)throw Error(Te(310));Tn=e,e={memoizedState:Tn.memoizedState,baseState:Tn.baseState,baseQueue:Tn.baseQueue,queue:Tn.queue,next:null},Ln===null?an.memoizedState=Ln=e:Ln=Ln.next=e}return Ln}function bu(e,n){return typeof n=="function"?n(e):n}function ug(e){var n=fr(),s=n.queue;if(s===null)throw Error(Te(311));s.lastRenderedReducer=e;var r=Tn,a=r.baseQueue,i=s.pending;if(i!==null){if(a!==null){var l=a.next;a.next=i.next,i.next=l}r.baseQueue=a=i,s.pending=null}if(a!==null){i=a.next,r=r.baseState;var o=l=null,c=null,u=i;do{var h=u.lane;if((ll&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 m={lane:h,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null};c===null?(o=c=m,l=r):c=c.next=m,an.lanes|=h,ol|=h}u=u.next}while(u!==null&&u!==i);c===null?l=r:c.next=o,Ir(r,n.memoizedState)||(ks=!0),n.memoizedState=r,n.baseState=l,n.baseQueue=c,s.lastRenderedState=r}if(e=s.interleaved,e!==null){a=e;do i=a.lane,an.lanes|=i,ol|=i,a=a.next;while(a!==e)}else a===null&&(s.lanes=0);return[n.memoizedState,s.dispatch]}function dg(e){var n=fr(),s=n.queue;if(s===null)throw Error(Te(311));s.lastRenderedReducer=e;var r=s.dispatch,a=s.pending,i=n.memoizedState;if(a!==null){s.pending=null;var l=a=a.next;do i=e(i,l.action),l=l.next;while(l!==a);Ir(i,n.memoizedState)||(ks=!0),n.memoizedState=i,n.baseQueue===null&&(n.baseState=i),s.lastRenderedState=i}return[i,r]}function x$(){}function j$(e,n){var s=an,r=fr(),a=n(),i=!Ir(r.memoizedState,a);if(i&&(r.memoizedState=a,ks=!0),r=r.queue,hw(w$.bind(null,s,r,e),[e]),r.getSnapshot!==n||i||Ln!==null&&Ln.memoizedState.tag&1){if(s.flags|=2048,ku(9,y$.bind(null,s,r,a,n),void 0,null),zn===null)throw Error(Te(349));ll&30||v$(s,n,a)}return a}function v$(e,n,s){e.flags|=16384,e={getSnapshot:n,value:s},n=an.updateQueue,n===null?(n={lastEffect:null,stores:null},an.updateQueue=n,n.stores=[e]):(s=n.stores,s===null?n.stores=[e]:s.push(e))}function y$(e,n,s,r){n.value=s,n.getSnapshot=r,b$(n)&&k$(e)}function w$(e,n,s){return s(function(){b$(n)&&k$(e)})}function b$(e){var n=e.getSnapshot;e=e.value;try{var s=n();return!Ir(e,s)}catch{return!0}}function k$(e){var n=Ia(e,1);n!==null&&$r(n,e,1,-1)}function vN(e){var n=Gr();return typeof e=="function"&&(e=e()),n.memoizedState=n.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:bu,lastRenderedState:e},n.queue=e,e=e.dispatch=D_.bind(null,an,e),[n.memoizedState,e]}function ku(e,n,s,r){return e={tag:e,create:n,destroy:s,deps:r,next:null},n=an.updateQueue,n===null?(n={lastEffect:null,stores:null},an.updateQueue=n,n.lastEffect=e.next=e):(s=n.lastEffect,s===null?n.lastEffect=e.next=e:(r=s.next,s.next=e,e.next=r,n.lastEffect=e)),e}function N$(){return fr().memoizedState}function Lh(e,n,s,r){var a=Gr();an.flags|=e,a.memoizedState=ku(1|n,s,void 0,r===void 0?null:r)}function Cm(e,n,s,r){var a=fr();r=r===void 0?null:r;var i=void 0;if(Tn!==null){var l=Tn.memoizedState;if(i=l.destroy,r!==null&&cw(r,l.deps)){a.memoizedState=ku(n,s,i,r);return}}an.flags|=e,a.memoizedState=ku(1|n,s,i,r)}function yN(e,n){return Lh(8390656,8,e,n)}function hw(e,n){return Cm(2048,8,e,n)}function S$(e,n){return Cm(4,2,e,n)}function C$(e,n){return Cm(4,4,e,n)}function E$(e,n){if(typeof n=="function")return e=e(),n(e),function(){n(null)};if(n!=null)return e=e(),n.current=e,function(){n.current=null}}function A$(e,n,s){return s=s!=null?s.concat([e]):null,Cm(4,4,E$.bind(null,n,e),s)}function fw(){}function $$(e,n){var s=fr();n=n===void 0?null:n;var r=s.memoizedState;return r!==null&&n!==null&&cw(n,r[1])?r[0]:(s.memoizedState=[e,n],e)}function T$(e,n){var s=fr();n=n===void 0?null:n;var r=s.memoizedState;return r!==null&&n!==null&&cw(n,r[1])?r[0]:(e=e(),s.memoizedState=[e,n],e)}function R$(e,n,s){return ll&21?(Ir(s,n)||(s=DA(),an.lanes|=s,ol|=s,e.baseState=!0),n):(e.baseState&&(e.baseState=!1,ks=!0),e.memoizedState=s)}function M_(e,n){var s=Ft;Ft=s!==0&&4>s?s:4,e(!0);var r=cg.transition;cg.transition={};try{e(!1),n()}finally{Ft=s,cg.transition=r}}function I$(){return fr().memoizedState}function O_(e,n,s){var r=ci(e);if(s={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null},P$(e))M$(n,s);else if(s=m$(e,n,s,r),s!==null){var a=hs();$r(s,e,r,a),O$(s,n,r)}}function D_(e,n,s){var r=ci(e),a={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null};if(P$(e))M$(n,a);else{var i=e.alternate;if(e.lanes===0&&(i===null||i.lanes===0)&&(i=n.lastRenderedReducer,i!==null))try{var l=n.lastRenderedState,o=i(l,s);if(a.hasEagerState=!0,a.eagerState=o,Ir(o,l)){var c=n.interleaved;c===null?(a.next=a,rw(n)):(a.next=c.next,c.next=a),n.interleaved=a;return}}catch{}finally{}s=m$(e,n,a,r),s!==null&&(a=hs(),$r(s,e,r,a),O$(s,n,r))}}function P$(e){var n=e.alternate;return e===an||n!==null&&n===an}function M$(e,n){qc=Sf=!0;var s=e.pending;s===null?n.next=n:(n.next=s.next,s.next=n),e.pending=n}function O$(e,n,s){if(s&4194240){var r=n.lanes;r&=e.pendingLanes,s|=r,n.lanes=s,Hy(e,s)}}var Cf={readContext:hr,useCallback:Jn,useContext:Jn,useEffect:Jn,useImperativeHandle:Jn,useInsertionEffect:Jn,useLayoutEffect:Jn,useMemo:Jn,useReducer:Jn,useRef:Jn,useState:Jn,useDebugValue:Jn,useDeferredValue:Jn,useTransition:Jn,useMutableSource:Jn,useSyncExternalStore:Jn,useId:Jn,unstable_isNewReconciler:!1},L_={readContext:hr,useCallback:function(e,n){return Gr().memoizedState=[e,n===void 0?null:n],e},useContext:hr,useEffect:yN,useImperativeHandle:function(e,n,s){return s=s!=null?s.concat([e]):null,Lh(4194308,4,E$.bind(null,n,e),s)},useLayoutEffect:function(e,n){return Lh(4194308,4,e,n)},useInsertionEffect:function(e,n){return Lh(4,2,e,n)},useMemo:function(e,n){var s=Gr();return n=n===void 0?null:n,e=e(),s.memoizedState=[e,n],e},useReducer:function(e,n,s){var r=Gr();return n=s!==void 0?s(n):n,r.memoizedState=r.baseState=n,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:n},r.queue=e,e=e.dispatch=O_.bind(null,an,e),[r.memoizedState,e]},useRef:function(e){var n=Gr();return e={current:e},n.memoizedState=e},useState:vN,useDebugValue:fw,useDeferredValue:function(e){return Gr().memoizedState=e},useTransition:function(){var e=vN(!1),n=e[0];return e=M_.bind(null,e[1]),Gr().memoizedState=e,[n,e]},useMutableSource:function(){},useSyncExternalStore:function(e,n,s){var r=an,a=Gr();if(tn){if(s===void 0)throw Error(Te(407));s=s()}else{if(s=n(),zn===null)throw Error(Te(349));ll&30||v$(r,n,s)}a.memoizedState=s;var i={value:s,getSnapshot:n};return a.queue=i,yN(w$.bind(null,r,i,e),[e]),r.flags|=2048,ku(9,y$.bind(null,r,i,s,n),void 0,null),s},useId:function(){var e=Gr(),n=zn.identifierPrefix;if(tn){var s=Na,r=ka;s=(r&~(1<<32-Ar(r)-1)).toString(32)+s,n=":"+n+"R"+s,s=wu++,0<s&&(n+="H"+s.toString(32)),n+=":"}else s=P_++,n=":"+n+"r"+s.toString(32)+":";return e.memoizedState=n},unstable_isNewReconciler:!1},F_={readContext:hr,useCallback:$$,useContext:hr,useEffect:hw,useImperativeHandle:A$,useInsertionEffect:S$,useLayoutEffect:C$,useMemo:T$,useReducer:ug,useRef:N$,useState:function(){return ug(bu)},useDebugValue:fw,useDeferredValue:function(e){var n=fr();return R$(n,Tn.memoizedState,e)},useTransition:function(){var e=ug(bu)[0],n=fr().memoizedState;return[e,n]},useMutableSource:x$,useSyncExternalStore:j$,useId:I$,unstable_isNewReconciler:!1},__={readContext:hr,useCallback:$$,useContext:hr,useEffect:hw,useImperativeHandle:A$,useInsertionEffect:S$,useLayoutEffect:C$,useMemo:T$,useReducer:dg,useRef:N$,useState:function(){return dg(bu)},useDebugValue:fw,useDeferredValue:function(e){var n=fr();return Tn===null?n.memoizedState=e:R$(n,Tn.memoizedState,e)},useTransition:function(){var e=dg(bu)[0],n=fr().memoizedState;return[e,n]},useMutableSource:x$,useSyncExternalStore:j$,useId:I$,unstable_isNewReconciler:!1};function br(e,n){if(e&&e.defaultProps){n=un({},n),e=e.defaultProps;for(var s in e)n[s]===void 0&&(n[s]=e[s]);return n}return n}function cj(e,n,s,r){n=e.memoizedState,s=s(r,n),s=s==null?n:un({},n,s),e.memoizedState=s,e.lanes===0&&(e.updateQueue.baseState=s)}var Em={isMounted:function(e){return(e=e._reactInternals)?yl(e)===e:!1},enqueueSetState:function(e,n,s){e=e._reactInternals;var r=hs(),a=ci(e),i=Sa(r,a);i.payload=n,s!=null&&(i.callback=s),n=li(e,i,a),n!==null&&($r(n,e,a,r),Oh(n,e,a))},enqueueReplaceState:function(e,n,s){e=e._reactInternals;var r=hs(),a=ci(e),i=Sa(r,a);i.tag=1,i.payload=n,s!=null&&(i.callback=s),n=li(e,i,a),n!==null&&($r(n,e,a,r),Oh(n,e,a))},enqueueForceUpdate:function(e,n){e=e._reactInternals;var s=hs(),r=ci(e),a=Sa(s,r);a.tag=2,n!=null&&(a.callback=n),n=li(e,a,r),n!==null&&($r(n,e,r,s),Oh(n,e,r))}};function wN(e,n,s,r,a,i,l){return e=e.stateNode,typeof e.shouldComponentUpdate=="function"?e.shouldComponentUpdate(r,i,l):n.prototype&&n.prototype.isPureReactComponent?!pu(s,r)||!pu(a,i):!0}function D$(e,n,s){var r=!1,a=pi,i=n.contextType;return typeof i=="object"&&i!==null?i=hr(i):(a=Cs(n)?al:ns.current,r=n.contextTypes,i=(r=r!=null)?No(e,a):pi),n=new n(s,i),e.memoizedState=n.state!==null&&n.state!==void 0?n.state:null,n.updater=Em,e.stateNode=n,n._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=a,e.__reactInternalMemoizedMaskedChildContext=i),n}function bN(e,n,s,r){e=n.state,typeof n.componentWillReceiveProps=="function"&&n.componentWillReceiveProps(s,r),typeof n.UNSAFE_componentWillReceiveProps=="function"&&n.UNSAFE_componentWillReceiveProps(s,r),n.state!==e&&Em.enqueueReplaceState(n,n.state,null)}function uj(e,n,s,r){var a=e.stateNode;a.props=s,a.state=e.memoizedState,a.refs={},aw(e);var i=n.contextType;typeof i=="object"&&i!==null?a.context=hr(i):(i=Cs(n)?al:ns.current,a.context=No(e,i)),a.state=e.memoizedState,i=n.getDerivedStateFromProps,typeof i=="function"&&(cj(e,n,i,s),a.state=e.memoizedState),typeof n.getDerivedStateFromProps=="function"||typeof a.getSnapshotBeforeUpdate=="function"||typeof a.UNSAFE_componentWillMount!="function"&&typeof a.componentWillMount!="function"||(n=a.state,typeof a.componentWillMount=="function"&&a.componentWillMount(),typeof a.UNSAFE_componentWillMount=="function"&&a.UNSAFE_componentWillMount(),n!==a.state&&Em.enqueueReplaceState(a,a.state,null),kf(e,s,a,r),a.state=e.memoizedState),typeof a.componentDidMount=="function"&&(e.flags|=4194308)}function Ao(e,n){try{var s="",r=n;do s+=fF(r),r=r.return;while(r);var a=s}catch(i){a=`
39
- Error generating stack: `+i.message+`
40
- `+i.stack}return{value:e,source:n,stack:a,digest:null}}function hg(e,n,s){return{value:e,source:null,stack:s??null,digest:n??null}}function dj(e,n){try{console.error(n.value)}catch(s){setTimeout(function(){throw s})}}var z_=typeof WeakMap=="function"?WeakMap:Map;function L$(e,n,s){s=Sa(-1,s),s.tag=3,s.payload={element:null};var r=n.value;return s.callback=function(){Af||(Af=!0,wj=r),dj(e,n)},s}function F$(e,n,s){s=Sa(-1,s),s.tag=3;var r=e.type.getDerivedStateFromError;if(typeof r=="function"){var a=n.value;s.payload=function(){return r(a)},s.callback=function(){dj(e,n)}}var i=e.stateNode;return i!==null&&typeof i.componentDidCatch=="function"&&(s.callback=function(){dj(e,n),typeof r!="function"&&(oi===null?oi=new Set([this]):oi.add(this));var l=n.stack;this.componentDidCatch(n.value,{componentStack:l!==null?l:""})}),s}function kN(e,n,s){var r=e.pingCache;if(r===null){r=e.pingCache=new z_;var a=new Set;r.set(n,a)}else a=r.get(n),a===void 0&&(a=new Set,r.set(n,a));a.has(s)||(a.add(s),e=e4.bind(null,e,n,s),n.then(e,e))}function NN(e){do{var n;if((n=e.tag===13)&&(n=e.memoizedState,n=n!==null?n.dehydrated!==null:!0),n)return e;e=e.return}while(e!==null);return null}function SN(e,n,s,r,a){return e.mode&1?(e.flags|=65536,e.lanes=a,e):(e===n?e.flags|=65536:(e.flags|=128,s.flags|=131072,s.flags&=-52805,s.tag===1&&(s.alternate===null?s.tag=17:(n=Sa(-1,1),n.tag=2,li(s,n,1))),s.lanes|=1),e)}var U_=Fa.ReactCurrentOwner,ks=!1;function cs(e,n,s,r){n.child=e===null?f$(n,null,s,r):Co(n,e.child,s,r)}function CN(e,n,s,r,a){s=s.render;var i=n.ref;return mo(n,a),r=uw(e,n,s,r,i,a),s=dw(),e!==null&&!ks?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~a,Pa(e,n,a)):(tn&&s&&Xy(n),n.flags|=1,cs(e,n,r,a),n.child)}function EN(e,n,s,r,a){if(e===null){var i=s.type;return typeof i=="function"&&!ww(i)&&i.defaultProps===void 0&&s.compare===null&&s.defaultProps===void 0?(n.tag=15,n.type=i,_$(e,n,i,r,a)):(e=Uh(s.type,null,r,n,n.mode,a),e.ref=n.ref,e.return=n,n.child=e)}if(i=e.child,!(e.lanes&a)){var l=i.memoizedProps;if(s=s.compare,s=s!==null?s:pu,s(l,r)&&e.ref===n.ref)return Pa(e,n,a)}return n.flags|=1,e=ui(i,r),e.ref=n.ref,e.return=n,n.child=e}function _$(e,n,s,r,a){if(e!==null){var i=e.memoizedProps;if(pu(i,r)&&e.ref===n.ref)if(ks=!1,n.pendingProps=r=i,(e.lanes&a)!==0)e.flags&131072&&(ks=!0);else return n.lanes=e.lanes,Pa(e,n,a)}return hj(e,n,s,r,a)}function z$(e,n,s){var r=n.pendingProps,a=r.children,i=e!==null?e.memoizedState:null;if(r.mode==="hidden")if(!(n.mode&1))n.memoizedState={baseLanes:0,cachePool:null,transitions:null},Yt(so,Os),Os|=s;else{if(!(s&1073741824))return e=i!==null?i.baseLanes|s:s,n.lanes=n.childLanes=1073741824,n.memoizedState={baseLanes:e,cachePool:null,transitions:null},n.updateQueue=null,Yt(so,Os),Os|=e,null;n.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=i!==null?i.baseLanes:s,Yt(so,Os),Os|=r}else i!==null?(r=i.baseLanes|s,n.memoizedState=null):r=s,Yt(so,Os),Os|=r;return cs(e,n,a,s),n.child}function U$(e,n){var s=n.ref;(e===null&&s!==null||e!==null&&e.ref!==s)&&(n.flags|=512,n.flags|=2097152)}function hj(e,n,s,r,a){var i=Cs(s)?al:ns.current;return i=No(n,i),mo(n,a),s=uw(e,n,s,r,i,a),r=dw(),e!==null&&!ks?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~a,Pa(e,n,a)):(tn&&r&&Xy(n),n.flags|=1,cs(e,n,s,a),n.child)}function AN(e,n,s,r,a){if(Cs(s)){var i=!0;jf(n)}else i=!1;if(mo(n,a),n.stateNode===null)Fh(e,n),D$(n,s,r),uj(n,s,r,a),r=!0;else if(e===null){var l=n.stateNode,o=n.memoizedProps;l.props=o;var c=l.context,u=s.contextType;typeof u=="object"&&u!==null?u=hr(u):(u=Cs(s)?al:ns.current,u=No(n,u));var h=s.getDerivedStateFromProps,m=typeof h=="function"||typeof l.getSnapshotBeforeUpdate=="function";m||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==r||c!==u)&&bN(n,l,r,u),Ya=!1;var f=n.memoizedState;l.state=f,kf(n,r,l,a),c=n.memoizedState,o!==r||f!==c||Ss.current||Ya?(typeof h=="function"&&(cj(n,s,h,r),c=n.memoizedState),(o=Ya||wN(n,s,o,r,f,c,u))?(m||typeof l.UNSAFE_componentWillMount!="function"&&typeof l.componentWillMount!="function"||(typeof l.componentWillMount=="function"&&l.componentWillMount(),typeof l.UNSAFE_componentWillMount=="function"&&l.UNSAFE_componentWillMount()),typeof l.componentDidMount=="function"&&(n.flags|=4194308)):(typeof l.componentDidMount=="function"&&(n.flags|=4194308),n.memoizedProps=r,n.memoizedState=c),l.props=r,l.state=c,l.context=u,r=o):(typeof l.componentDidMount=="function"&&(n.flags|=4194308),r=!1)}else{l=n.stateNode,p$(e,n),o=n.memoizedProps,u=n.type===n.elementType?o:br(n.type,o),l.props=u,m=n.pendingProps,f=l.context,c=s.contextType,typeof c=="object"&&c!==null?c=hr(c):(c=Cs(s)?al:ns.current,c=No(n,c));var p=s.getDerivedStateFromProps;(h=typeof p=="function"||typeof l.getSnapshotBeforeUpdate=="function")||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==m||f!==c)&&bN(n,l,r,c),Ya=!1,f=n.memoizedState,l.state=f,kf(n,r,l,a);var x=n.memoizedState;o!==m||f!==x||Ss.current||Ya?(typeof p=="function"&&(cj(n,s,p,r),x=n.memoizedState),(u=Ya||wN(n,s,u,r,f,x,c)||!1)?(h||typeof l.UNSAFE_componentWillUpdate!="function"&&typeof l.componentWillUpdate!="function"||(typeof l.componentWillUpdate=="function"&&l.componentWillUpdate(r,x,c),typeof l.UNSAFE_componentWillUpdate=="function"&&l.UNSAFE_componentWillUpdate(r,x,c)),typeof l.componentDidUpdate=="function"&&(n.flags|=4),typeof l.getSnapshotBeforeUpdate=="function"&&(n.flags|=1024)):(typeof l.componentDidUpdate!="function"||o===e.memoizedProps&&f===e.memoizedState||(n.flags|=4),typeof l.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&f===e.memoizedState||(n.flags|=1024),n.memoizedProps=r,n.memoizedState=x),l.props=r,l.state=x,l.context=c,r=u):(typeof l.componentDidUpdate!="function"||o===e.memoizedProps&&f===e.memoizedState||(n.flags|=4),typeof l.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&f===e.memoizedState||(n.flags|=1024),r=!1)}return fj(e,n,s,r,i,a)}function fj(e,n,s,r,a,i){U$(e,n);var l=(n.flags&128)!==0;if(!r&&!l)return a&&fN(n,s,!1),Pa(e,n,i);r=n.stateNode,U_.current=n;var o=l&&typeof s.getDerivedStateFromError!="function"?null:r.render();return n.flags|=1,e!==null&&l?(n.child=Co(n,e.child,null,i),n.child=Co(n,null,o,i)):cs(e,n,o,i),n.memoizedState=r.state,a&&fN(n,s,!0),n.child}function B$(e){var n=e.stateNode;n.pendingContext?hN(e,n.pendingContext,n.pendingContext!==n.context):n.context&&hN(e,n.context,!1),iw(e,n.containerInfo)}function $N(e,n,s,r,a){return So(),ew(a),n.flags|=256,cs(e,n,s,r),n.child}var mj={dehydrated:null,treeContext:null,retryLane:0};function pj(e){return{baseLanes:e,cachePool:null,transitions:null}}function W$(e,n,s){var r=n.pendingProps,a=rn.current,i=!1,l=(n.flags&128)!==0,o;if((o=l)||(o=e!==null&&e.memoizedState===null?!1:(a&2)!==0),o?(i=!0,n.flags&=-129):(e===null||e.memoizedState!==null)&&(a|=1),Yt(rn,a&1),e===null)return lj(n),e=n.memoizedState,e!==null&&(e=e.dehydrated,e!==null)?(n.mode&1?e.data==="$!"?n.lanes=8:n.lanes=1073741824:n.lanes=1,null):(l=r.children,e=r.fallback,i?(r=n.mode,i=n.child,l={mode:"hidden",children:l},!(r&1)&&i!==null?(i.childLanes=0,i.pendingProps=l):i=Tm(l,r,0,null),e=tl(e,r,s,null),i.return=n,e.return=n,i.sibling=e,n.child=i,n.child.memoizedState=pj(s),n.memoizedState=mj,e):mw(n,l));if(a=e.memoizedState,a!==null&&(o=a.dehydrated,o!==null))return B_(e,n,l,r,o,a,s);if(i){i=r.fallback,l=n.mode,a=e.child,o=a.sibling;var c={mode:"hidden",children:r.children};return!(l&1)&&n.child!==a?(r=n.child,r.childLanes=0,r.pendingProps=c,n.deletions=null):(r=ui(a,c),r.subtreeFlags=a.subtreeFlags&14680064),o!==null?i=ui(o,i):(i=tl(i,l,s,null),i.flags|=2),i.return=n,r.return=n,r.sibling=i,n.child=r,r=i,i=n.child,l=e.child.memoizedState,l=l===null?pj(s):{baseLanes:l.baseLanes|s,cachePool:null,transitions:l.transitions},i.memoizedState=l,i.childLanes=e.childLanes&~s,n.memoizedState=mj,r}return i=e.child,e=i.sibling,r=ui(i,{mode:"visible",children:r.children}),!(n.mode&1)&&(r.lanes=s),r.return=n,r.sibling=null,e!==null&&(s=n.deletions,s===null?(n.deletions=[e],n.flags|=16):s.push(e)),n.child=r,n.memoizedState=null,r}function mw(e,n){return n=Tm({mode:"visible",children:n},e.mode,0,null),n.return=e,e.child=n}function Qd(e,n,s,r){return r!==null&&ew(r),Co(n,e.child,null,s),e=mw(n,n.pendingProps.children),e.flags|=2,n.memoizedState=null,e}function B_(e,n,s,r,a,i,l){if(s)return n.flags&256?(n.flags&=-257,r=hg(Error(Te(422))),Qd(e,n,l,r)):n.memoizedState!==null?(n.child=e.child,n.flags|=128,null):(i=r.fallback,a=n.mode,r=Tm({mode:"visible",children:r.children},a,0,null),i=tl(i,a,l,null),i.flags|=2,r.return=n,i.return=n,r.sibling=i,n.child=r,n.mode&1&&Co(n,e.child,null,l),n.child.memoizedState=pj(l),n.memoizedState=mj,i);if(!(n.mode&1))return Qd(e,n,l,null);if(a.data==="$!"){if(r=a.nextSibling&&a.nextSibling.dataset,r)var o=r.dgst;return r=o,i=Error(Te(419)),r=hg(i,r,void 0),Qd(e,n,l,r)}if(o=(l&e.childLanes)!==0,ks||o){if(r=zn,r!==null){switch(l&-l){case 4:a=2;break;case 16:a=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:a=32;break;case 536870912:a=268435456;break;default:a=0}a=a&(r.suspendedLanes|l)?0:a,a!==0&&a!==i.retryLane&&(i.retryLane=a,Ia(e,a),$r(r,e,a,-1))}return yw(),r=hg(Error(Te(421))),Qd(e,n,l,r)}return a.data==="$?"?(n.flags|=128,n.child=e.child,n=t4.bind(null,e),a._reactRetry=n,null):(e=i.treeContext,Fs=ii(a.nextSibling),zs=n,tn=!0,Nr=null,e!==null&&(ar[ir++]=ka,ar[ir++]=Na,ar[ir++]=il,ka=e.id,Na=e.overflow,il=n),n=mw(n,r.children),n.flags|=4096,n)}function TN(e,n,s){e.lanes|=n;var r=e.alternate;r!==null&&(r.lanes|=n),oj(e.return,n,s)}function fg(e,n,s,r,a){var i=e.memoizedState;i===null?e.memoizedState={isBackwards:n,rendering:null,renderingStartTime:0,last:r,tail:s,tailMode:a}:(i.isBackwards=n,i.rendering=null,i.renderingStartTime=0,i.last=r,i.tail=s,i.tailMode=a)}function H$(e,n,s){var r=n.pendingProps,a=r.revealOrder,i=r.tail;if(cs(e,n,r.children,s),r=rn.current,r&2)r=r&1|2,n.flags|=128;else{if(e!==null&&e.flags&128)e:for(e=n.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&TN(e,s,n);else if(e.tag===19)TN(e,s,n);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===n)break e;for(;e.sibling===null;){if(e.return===null||e.return===n)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}if(Yt(rn,r),!(n.mode&1))n.memoizedState=null;else switch(a){case"forwards":for(s=n.child,a=null;s!==null;)e=s.alternate,e!==null&&Nf(e)===null&&(a=s),s=s.sibling;s=a,s===null?(a=n.child,n.child=null):(a=s.sibling,s.sibling=null),fg(n,!1,a,s,i);break;case"backwards":for(s=null,a=n.child,n.child=null;a!==null;){if(e=a.alternate,e!==null&&Nf(e)===null){n.child=a;break}e=a.sibling,a.sibling=s,s=a,a=e}fg(n,!0,s,null,i);break;case"together":fg(n,!1,null,null,void 0);break;default:n.memoizedState=null}return n.child}function Fh(e,n){!(n.mode&1)&&e!==null&&(e.alternate=null,n.alternate=null,n.flags|=2)}function Pa(e,n,s){if(e!==null&&(n.dependencies=e.dependencies),ol|=n.lanes,!(s&n.childLanes))return null;if(e!==null&&n.child!==e.child)throw Error(Te(153));if(n.child!==null){for(e=n.child,s=ui(e,e.pendingProps),n.child=s,s.return=n;e.sibling!==null;)e=e.sibling,s=s.sibling=ui(e,e.pendingProps),s.return=n;s.sibling=null}return n.child}function W_(e,n,s){switch(n.tag){case 3:B$(n),So();break;case 5:g$(n);break;case 1:Cs(n.type)&&jf(n);break;case 4:iw(n,n.stateNode.containerInfo);break;case 10:var r=n.type._context,a=n.memoizedProps.value;Yt(wf,r._currentValue),r._currentValue=a;break;case 13:if(r=n.memoizedState,r!==null)return r.dehydrated!==null?(Yt(rn,rn.current&1),n.flags|=128,null):s&n.child.childLanes?W$(e,n,s):(Yt(rn,rn.current&1),e=Pa(e,n,s),e!==null?e.sibling:null);Yt(rn,rn.current&1);break;case 19:if(r=(s&n.childLanes)!==0,e.flags&128){if(r)return H$(e,n,s);n.flags|=128}if(a=n.memoizedState,a!==null&&(a.rendering=null,a.tail=null,a.lastEffect=null),Yt(rn,rn.current),r)break;return null;case 22:case 23:return n.lanes=0,z$(e,n,s)}return Pa(e,n,s)}var K$,gj,V$,G$;K$=function(e,n){for(var s=n.child;s!==null;){if(s.tag===5||s.tag===6)e.appendChild(s.stateNode);else if(s.tag!==4&&s.child!==null){s.child.return=s,s=s.child;continue}if(s===n)break;for(;s.sibling===null;){if(s.return===null||s.return===n)return;s=s.return}s.sibling.return=s.return,s=s.sibling}};gj=function(){};V$=function(e,n,s,r){var a=e.memoizedProps;if(a!==r){e=n.stateNode,qi(na.current);var i=null;switch(s){case"input":a=Fx(e,a),r=Fx(e,r),i=[];break;case"select":a=un({},a,{value:void 0}),r=un({},r,{value:void 0}),i=[];break;case"textarea":a=Ux(e,a),r=Ux(e,r),i=[];break;default:typeof a.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=gf)}Wx(s,r);var l;s=null;for(u in a)if(!r.hasOwnProperty(u)&&a.hasOwnProperty(u)&&a[u]!=null)if(u==="style"){var o=a[u];for(l in o)o.hasOwnProperty(l)&&(s||(s={}),s[l]="")}else u!=="dangerouslySetInnerHTML"&&u!=="children"&&u!=="suppressContentEditableWarning"&&u!=="suppressHydrationWarning"&&u!=="autoFocus"&&(ou.hasOwnProperty(u)?i||(i=[]):(i=i||[]).push(u,null));for(u in r){var c=r[u];if(o=a!=null?a[u]:void 0,r.hasOwnProperty(u)&&c!==o&&(c!=null||o!=null))if(u==="style")if(o){for(l in o)!o.hasOwnProperty(l)||c&&c.hasOwnProperty(l)||(s||(s={}),s[l]="");for(l in c)c.hasOwnProperty(l)&&o[l]!==c[l]&&(s||(s={}),s[l]=c[l])}else s||(i||(i=[]),i.push(u,s)),s=c;else u==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,o=o?o.__html:void 0,c!=null&&o!==c&&(i=i||[]).push(u,c)):u==="children"?typeof c!="string"&&typeof c!="number"||(i=i||[]).push(u,""+c):u!=="suppressContentEditableWarning"&&u!=="suppressHydrationWarning"&&(ou.hasOwnProperty(u)?(c!=null&&u==="onScroll"&&Jt("scroll",e),i||o===c||(i=[])):(i=i||[]).push(u,c))}s&&(i=i||[]).push("style",s);var u=i;(n.updateQueue=u)&&(n.flags|=4)}};G$=function(e,n,s,r){s!==r&&(n.flags|=4)};function kc(e,n){if(!tn)switch(e.tailMode){case"hidden":n=e.tail;for(var s=null;n!==null;)n.alternate!==null&&(s=n),n=n.sibling;s===null?e.tail=null:s.sibling=null;break;case"collapsed":s=e.tail;for(var r=null;s!==null;)s.alternate!==null&&(r=s),s=s.sibling;r===null?n||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function Xn(e){var n=e.alternate!==null&&e.alternate.child===e.child,s=0,r=0;if(n)for(var a=e.child;a!==null;)s|=a.lanes|a.childLanes,r|=a.subtreeFlags&14680064,r|=a.flags&14680064,a.return=e,a=a.sibling;else for(a=e.child;a!==null;)s|=a.lanes|a.childLanes,r|=a.subtreeFlags,r|=a.flags,a.return=e,a=a.sibling;return e.subtreeFlags|=r,e.childLanes=s,n}function H_(e,n,s){var r=n.pendingProps;switch(Zy(n),n.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Xn(n),null;case 1:return Cs(n.type)&&xf(),Xn(n),null;case 3:return r=n.stateNode,Eo(),Xt(Ss),Xt(ns),ow(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(qd(n)?n.flags|=4:e===null||e.memoizedState.isDehydrated&&!(n.flags&256)||(n.flags|=1024,Nr!==null&&(Nj(Nr),Nr=null))),gj(e,n),Xn(n),null;case 5:lw(n);var a=qi(yu.current);if(s=n.type,e!==null&&n.stateNode!=null)V$(e,n,s,r,a),e.ref!==n.ref&&(n.flags|=512,n.flags|=2097152);else{if(!r){if(n.stateNode===null)throw Error(Te(166));return Xn(n),null}if(e=qi(na.current),qd(n)){r=n.stateNode,s=n.type;var i=n.memoizedProps;switch(r[Yr]=n,r[ju]=i,e=(n.mode&1)!==0,s){case"dialog":Jt("cancel",r),Jt("close",r);break;case"iframe":case"object":case"embed":Jt("load",r);break;case"video":case"audio":for(a=0;a<Lc.length;a++)Jt(Lc[a],r);break;case"source":Jt("error",r);break;case"img":case"image":case"link":Jt("error",r),Jt("load",r);break;case"details":Jt("toggle",r);break;case"input":_0(r,i),Jt("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!i.multiple},Jt("invalid",r);break;case"textarea":U0(r,i),Jt("invalid",r)}Wx(s,i),a=null;for(var l in i)if(i.hasOwnProperty(l)){var o=i[l];l==="children"?typeof o=="string"?r.textContent!==o&&(i.suppressHydrationWarning!==!0&&Gd(r.textContent,o,e),a=["children",o]):typeof o=="number"&&r.textContent!==""+o&&(i.suppressHydrationWarning!==!0&&Gd(r.textContent,o,e),a=["children",""+o]):ou.hasOwnProperty(l)&&o!=null&&l==="onScroll"&&Jt("scroll",r)}switch(s){case"input":_d(r),z0(r,i,!0);break;case"textarea":_d(r),B0(r);break;case"select":case"option":break;default:typeof i.onClick=="function"&&(r.onclick=gf)}r=a,n.updateQueue=r,r!==null&&(n.flags|=4)}else{l=a.nodeType===9?a:a.ownerDocument,e==="http://www.w3.org/1999/xhtml"&&(e=wA(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[Yr]=n,e[ju]=r,K$(e,n,!1,!1),n.stateNode=e;e:{switch(l=Hx(s,r),s){case"dialog":Jt("cancel",e),Jt("close",e),a=r;break;case"iframe":case"object":case"embed":Jt("load",e),a=r;break;case"video":case"audio":for(a=0;a<Lc.length;a++)Jt(Lc[a],e);a=r;break;case"source":Jt("error",e),a=r;break;case"img":case"image":case"link":Jt("error",e),Jt("load",e),a=r;break;case"details":Jt("toggle",e),a=r;break;case"input":_0(e,r),a=Fx(e,r),Jt("invalid",e);break;case"option":a=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},a=un({},r,{value:void 0}),Jt("invalid",e);break;case"textarea":U0(e,r),a=Ux(e,r),Jt("invalid",e);break;default:a=r}Wx(s,a),o=a;for(i in o)if(o.hasOwnProperty(i)){var c=o[i];i==="style"?NA(e,c):i==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,c!=null&&bA(e,c)):i==="children"?typeof c=="string"?(s!=="textarea"||c!=="")&&cu(e,c):typeof c=="number"&&cu(e,""+c):i!=="suppressContentEditableWarning"&&i!=="suppressHydrationWarning"&&i!=="autoFocus"&&(ou.hasOwnProperty(i)?c!=null&&i==="onScroll"&&Jt("scroll",e):c!=null&&Fy(e,i,c,l))}switch(s){case"input":_d(e),z0(e,r,!1);break;case"textarea":_d(e),B0(e);break;case"option":r.value!=null&&e.setAttribute("value",""+mi(r.value));break;case"select":e.multiple=!!r.multiple,i=r.value,i!=null?co(e,!!r.multiple,i,!1):r.defaultValue!=null&&co(e,!!r.multiple,r.defaultValue,!0);break;default:typeof a.onClick=="function"&&(e.onclick=gf)}switch(s){case"button":case"input":case"select":case"textarea":r=!!r.autoFocus;break e;case"img":r=!0;break e;default:r=!1}}r&&(n.flags|=4)}n.ref!==null&&(n.flags|=512,n.flags|=2097152)}return Xn(n),null;case 6:if(e&&n.stateNode!=null)G$(e,n,e.memoizedProps,r);else{if(typeof r!="string"&&n.stateNode===null)throw Error(Te(166));if(s=qi(yu.current),qi(na.current),qd(n)){if(r=n.stateNode,s=n.memoizedProps,r[Yr]=n,(i=r.nodeValue!==s)&&(e=zs,e!==null))switch(e.tag){case 3:Gd(r.nodeValue,s,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&Gd(r.nodeValue,s,(e.mode&1)!==0)}i&&(n.flags|=4)}else r=(s.nodeType===9?s:s.ownerDocument).createTextNode(r),r[Yr]=n,n.stateNode=r}return Xn(n),null;case 13:if(Xt(rn),r=n.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(tn&&Fs!==null&&n.mode&1&&!(n.flags&128))d$(),So(),n.flags|=98560,i=!1;else if(i=qd(n),r!==null&&r.dehydrated!==null){if(e===null){if(!i)throw Error(Te(318));if(i=n.memoizedState,i=i!==null?i.dehydrated:null,!i)throw Error(Te(317));i[Yr]=n}else So(),!(n.flags&128)&&(n.memoizedState=null),n.flags|=4;Xn(n),i=!1}else Nr!==null&&(Nj(Nr),Nr=null),i=!0;if(!i)return n.flags&65536?n:null}return n.flags&128?(n.lanes=s,n):(r=r!==null,r!==(e!==null&&e.memoizedState!==null)&&r&&(n.child.flags|=8192,n.mode&1&&(e===null||rn.current&1?In===0&&(In=3):yw())),n.updateQueue!==null&&(n.flags|=4),Xn(n),null);case 4:return Eo(),gj(e,n),e===null&&gu(n.stateNode.containerInfo),Xn(n),null;case 10:return sw(n.type._context),Xn(n),null;case 17:return Cs(n.type)&&xf(),Xn(n),null;case 19:if(Xt(rn),i=n.memoizedState,i===null)return Xn(n),null;if(r=(n.flags&128)!==0,l=i.rendering,l===null)if(r)kc(i,!1);else{if(In!==0||e!==null&&e.flags&128)for(e=n.child;e!==null;){if(l=Nf(e),l!==null){for(n.flags|=128,kc(i,!1),r=l.updateQueue,r!==null&&(n.updateQueue=r,n.flags|=4),n.subtreeFlags=0,r=s,s=n.child;s!==null;)i=s,e=r,i.flags&=14680066,l=i.alternate,l===null?(i.childLanes=0,i.lanes=e,i.child=null,i.subtreeFlags=0,i.memoizedProps=null,i.memoizedState=null,i.updateQueue=null,i.dependencies=null,i.stateNode=null):(i.childLanes=l.childLanes,i.lanes=l.lanes,i.child=l.child,i.subtreeFlags=0,i.deletions=null,i.memoizedProps=l.memoizedProps,i.memoizedState=l.memoizedState,i.updateQueue=l.updateQueue,i.type=l.type,e=l.dependencies,i.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext}),s=s.sibling;return Yt(rn,rn.current&1|2),n.child}e=e.sibling}i.tail!==null&&jn()>$o&&(n.flags|=128,r=!0,kc(i,!1),n.lanes=4194304)}else{if(!r)if(e=Nf(l),e!==null){if(n.flags|=128,r=!0,s=e.updateQueue,s!==null&&(n.updateQueue=s,n.flags|=4),kc(i,!0),i.tail===null&&i.tailMode==="hidden"&&!l.alternate&&!tn)return Xn(n),null}else 2*jn()-i.renderingStartTime>$o&&s!==1073741824&&(n.flags|=128,r=!0,kc(i,!1),n.lanes=4194304);i.isBackwards?(l.sibling=n.child,n.child=l):(s=i.last,s!==null?s.sibling=l:n.child=l,i.last=l)}return i.tail!==null?(n=i.tail,i.rendering=n,i.tail=n.sibling,i.renderingStartTime=jn(),n.sibling=null,s=rn.current,Yt(rn,r?s&1|2:s&1),n):(Xn(n),null);case 22:case 23:return vw(),r=n.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(n.flags|=8192),r&&n.mode&1?Os&1073741824&&(Xn(n),n.subtreeFlags&6&&(n.flags|=8192)):Xn(n),null;case 24:return null;case 25:return null}throw Error(Te(156,n.tag))}function K_(e,n){switch(Zy(n),n.tag){case 1:return Cs(n.type)&&xf(),e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 3:return Eo(),Xt(Ss),Xt(ns),ow(),e=n.flags,e&65536&&!(e&128)?(n.flags=e&-65537|128,n):null;case 5:return lw(n),null;case 13:if(Xt(rn),e=n.memoizedState,e!==null&&e.dehydrated!==null){if(n.alternate===null)throw Error(Te(340));So()}return e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 19:return Xt(rn),null;case 4:return Eo(),null;case 10:return sw(n.type._context),null;case 22:case 23:return vw(),null;case 24:return null;default:return null}}var Jd=!1,es=!1,V_=typeof WeakSet=="function"?WeakSet:Set,Fe=null;function no(e,n){var s=e.ref;if(s!==null)if(typeof s=="function")try{s(null)}catch(r){mn(e,n,r)}else s.current=null}function xj(e,n,s){try{s()}catch(r){mn(e,n,r)}}var RN=!1;function G_(e,n){if(ej=ff,e=XA(),Jy(e)){if("selectionStart"in e)var s={start:e.selectionStart,end:e.selectionEnd};else e:{s=(s=e.ownerDocument)&&s.defaultView||window;var r=s.getSelection&&s.getSelection();if(r&&r.rangeCount!==0){s=r.anchorNode;var a=r.anchorOffset,i=r.focusNode;r=r.focusOffset;try{s.nodeType,i.nodeType}catch{s=null;break e}var l=0,o=-1,c=-1,u=0,h=0,m=e,f=null;t:for(;;){for(var p;m!==s||a!==0&&m.nodeType!==3||(o=l+a),m!==i||r!==0&&m.nodeType!==3||(c=l+r),m.nodeType===3&&(l+=m.nodeValue.length),(p=m.firstChild)!==null;)f=m,m=p;for(;;){if(m===e)break t;if(f===s&&++u===a&&(o=l),f===i&&++h===r&&(c=l),(p=m.nextSibling)!==null)break;m=f,f=m.parentNode}m=p}s=o===-1||c===-1?null:{start:o,end:c}}else s=null}s=s||{start:0,end:0}}else s=null;for(tj={focusedElem:e,selectionRange:s},ff=!1,Fe=n;Fe!==null;)if(n=Fe,e=n.child,(n.subtreeFlags&1028)!==0&&e!==null)e.return=n,Fe=e;else for(;Fe!==null;){n=Fe;try{var x=n.alternate;if(n.flags&1024)switch(n.tag){case 0:case 11:case 15:break;case 1:if(x!==null){var g=x.memoizedProps,w=x.memoizedState,v=n.stateNode,j=v.getSnapshotBeforeUpdate(n.elementType===n.type?g:br(n.type,g),w);v.__reactInternalSnapshotBeforeUpdate=j}break;case 3:var y=n.stateNode.containerInfo;y.nodeType===1?y.textContent="":y.nodeType===9&&y.documentElement&&y.removeChild(y.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(Te(163))}}catch(k){mn(n,n.return,k)}if(e=n.sibling,e!==null){e.return=n.return,Fe=e;break}Fe=n.return}return x=RN,RN=!1,x}function Yc(e,n,s){var r=n.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var a=r=r.next;do{if((a.tag&e)===e){var i=a.destroy;a.destroy=void 0,i!==void 0&&xj(n,s,i)}a=a.next}while(a!==r)}}function Am(e,n){if(n=n.updateQueue,n=n!==null?n.lastEffect:null,n!==null){var s=n=n.next;do{if((s.tag&e)===e){var r=s.create;s.destroy=r()}s=s.next}while(s!==n)}}function jj(e){var n=e.ref;if(n!==null){var s=e.stateNode;switch(e.tag){case 5:e=s;break;default:e=s}typeof n=="function"?n(e):n.current=e}}function q$(e){var n=e.alternate;n!==null&&(e.alternate=null,q$(n)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(n=e.stateNode,n!==null&&(delete n[Yr],delete n[ju],delete n[rj],delete n[$_],delete n[T_])),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 Y$(e){return e.tag===5||e.tag===3||e.tag===4}function IN(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||Y$(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 vj(e,n,s){var r=e.tag;if(r===5||r===6)e=e.stateNode,n?s.nodeType===8?s.parentNode.insertBefore(e,n):s.insertBefore(e,n):(s.nodeType===8?(n=s.parentNode,n.insertBefore(e,s)):(n=s,n.appendChild(e)),s=s._reactRootContainer,s!=null||n.onclick!==null||(n.onclick=gf));else if(r!==4&&(e=e.child,e!==null))for(vj(e,n,s),e=e.sibling;e!==null;)vj(e,n,s),e=e.sibling}function yj(e,n,s){var r=e.tag;if(r===5||r===6)e=e.stateNode,n?s.insertBefore(e,n):s.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(yj(e,n,s),e=e.sibling;e!==null;)yj(e,n,s),e=e.sibling}var Vn=null,kr=!1;function Ka(e,n,s){for(s=s.child;s!==null;)Q$(e,n,s),s=s.sibling}function Q$(e,n,s){if(ta&&typeof ta.onCommitFiberUnmount=="function")try{ta.onCommitFiberUnmount(ym,s)}catch{}switch(s.tag){case 5:es||no(s,n);case 6:var r=Vn,a=kr;Vn=null,Ka(e,n,s),Vn=r,kr=a,Vn!==null&&(kr?(e=Vn,s=s.stateNode,e.nodeType===8?e.parentNode.removeChild(s):e.removeChild(s)):Vn.removeChild(s.stateNode));break;case 18:Vn!==null&&(kr?(e=Vn,s=s.stateNode,e.nodeType===8?ig(e.parentNode,s):e.nodeType===1&&ig(e,s),fu(e)):ig(Vn,s.stateNode));break;case 4:r=Vn,a=kr,Vn=s.stateNode.containerInfo,kr=!0,Ka(e,n,s),Vn=r,kr=a;break;case 0:case 11:case 14:case 15:if(!es&&(r=s.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){a=r=r.next;do{var i=a,l=i.destroy;i=i.tag,l!==void 0&&(i&2||i&4)&&xj(s,n,l),a=a.next}while(a!==r)}Ka(e,n,s);break;case 1:if(!es&&(no(s,n),r=s.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=s.memoizedProps,r.state=s.memoizedState,r.componentWillUnmount()}catch(o){mn(s,n,o)}Ka(e,n,s);break;case 21:Ka(e,n,s);break;case 22:s.mode&1?(es=(r=es)||s.memoizedState!==null,Ka(e,n,s),es=r):Ka(e,n,s);break;default:Ka(e,n,s)}}function PN(e){var n=e.updateQueue;if(n!==null){e.updateQueue=null;var s=e.stateNode;s===null&&(s=e.stateNode=new V_),n.forEach(function(r){var a=n4.bind(null,e,r);s.has(r)||(s.add(r),r.then(a,a))})}}function yr(e,n){var s=n.deletions;if(s!==null)for(var r=0;r<s.length;r++){var a=s[r];try{var i=e,l=n,o=l;e:for(;o!==null;){switch(o.tag){case 5:Vn=o.stateNode,kr=!1;break e;case 3:Vn=o.stateNode.containerInfo,kr=!0;break e;case 4:Vn=o.stateNode.containerInfo,kr=!0;break e}o=o.return}if(Vn===null)throw Error(Te(160));Q$(i,l,a),Vn=null,kr=!1;var c=a.alternate;c!==null&&(c.return=null),a.return=null}catch(u){mn(a,n,u)}}if(n.subtreeFlags&12854)for(n=n.child;n!==null;)J$(n,e),n=n.sibling}function J$(e,n){var s=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(yr(n,e),Hr(e),r&4){try{Yc(3,e,e.return),Am(3,e)}catch(g){mn(e,e.return,g)}try{Yc(5,e,e.return)}catch(g){mn(e,e.return,g)}}break;case 1:yr(n,e),Hr(e),r&512&&s!==null&&no(s,s.return);break;case 5:if(yr(n,e),Hr(e),r&512&&s!==null&&no(s,s.return),e.flags&32){var a=e.stateNode;try{cu(a,"")}catch(g){mn(e,e.return,g)}}if(r&4&&(a=e.stateNode,a!=null)){var i=e.memoizedProps,l=s!==null?s.memoizedProps:i,o=e.type,c=e.updateQueue;if(e.updateQueue=null,c!==null)try{o==="input"&&i.type==="radio"&&i.name!=null&&vA(a,i),Hx(o,l);var u=Hx(o,i);for(l=0;l<c.length;l+=2){var h=c[l],m=c[l+1];h==="style"?NA(a,m):h==="dangerouslySetInnerHTML"?bA(a,m):h==="children"?cu(a,m):Fy(a,h,m,u)}switch(o){case"input":_x(a,i);break;case"textarea":yA(a,i);break;case"select":var f=a._wrapperState.wasMultiple;a._wrapperState.wasMultiple=!!i.multiple;var p=i.value;p!=null?co(a,!!i.multiple,p,!1):f!==!!i.multiple&&(i.defaultValue!=null?co(a,!!i.multiple,i.defaultValue,!0):co(a,!!i.multiple,i.multiple?[]:"",!1))}a[ju]=i}catch(g){mn(e,e.return,g)}}break;case 6:if(yr(n,e),Hr(e),r&4){if(e.stateNode===null)throw Error(Te(162));a=e.stateNode,i=e.memoizedProps;try{a.nodeValue=i}catch(g){mn(e,e.return,g)}}break;case 3:if(yr(n,e),Hr(e),r&4&&s!==null&&s.memoizedState.isDehydrated)try{fu(n.containerInfo)}catch(g){mn(e,e.return,g)}break;case 4:yr(n,e),Hr(e);break;case 13:yr(n,e),Hr(e),a=e.child,a.flags&8192&&(i=a.memoizedState!==null,a.stateNode.isHidden=i,!i||a.alternate!==null&&a.alternate.memoizedState!==null||(xw=jn())),r&4&&PN(e);break;case 22:if(h=s!==null&&s.memoizedState!==null,e.mode&1?(es=(u=es)||h,yr(n,e),es=u):yr(n,e),Hr(e),r&8192){if(u=e.memoizedState!==null,(e.stateNode.isHidden=u)&&!h&&e.mode&1)for(Fe=e,h=e.child;h!==null;){for(m=Fe=h;Fe!==null;){switch(f=Fe,p=f.child,f.tag){case 0:case 11:case 14:case 15:Yc(4,f,f.return);break;case 1:no(f,f.return);var x=f.stateNode;if(typeof x.componentWillUnmount=="function"){r=f,s=f.return;try{n=r,x.props=n.memoizedProps,x.state=n.memoizedState,x.componentWillUnmount()}catch(g){mn(r,s,g)}}break;case 5:no(f,f.return);break;case 22:if(f.memoizedState!==null){ON(m);continue}}p!==null?(p.return=f,Fe=p):ON(m)}h=h.sibling}e:for(h=null,m=e;;){if(m.tag===5){if(h===null){h=m;try{a=m.stateNode,u?(i=a.style,typeof i.setProperty=="function"?i.setProperty("display","none","important"):i.display="none"):(o=m.stateNode,c=m.memoizedProps.style,l=c!=null&&c.hasOwnProperty("display")?c.display:null,o.style.display=kA("display",l))}catch(g){mn(e,e.return,g)}}}else if(m.tag===6){if(h===null)try{m.stateNode.nodeValue=u?"":m.memoizedProps}catch(g){mn(e,e.return,g)}}else if((m.tag!==22&&m.tag!==23||m.memoizedState===null||m===e)&&m.child!==null){m.child.return=m,m=m.child;continue}if(m===e)break e;for(;m.sibling===null;){if(m.return===null||m.return===e)break e;h===m&&(h=null),m=m.return}h===m&&(h=null),m.sibling.return=m.return,m=m.sibling}}break;case 19:yr(n,e),Hr(e),r&4&&PN(e);break;case 21:break;default:yr(n,e),Hr(e)}}function Hr(e){var n=e.flags;if(n&2){try{e:{for(var s=e.return;s!==null;){if(Y$(s)){var r=s;break e}s=s.return}throw Error(Te(160))}switch(r.tag){case 5:var a=r.stateNode;r.flags&32&&(cu(a,""),r.flags&=-33);var i=IN(e);yj(e,i,a);break;case 3:case 4:var l=r.stateNode.containerInfo,o=IN(e);vj(e,o,l);break;default:throw Error(Te(161))}}catch(c){mn(e,e.return,c)}e.flags&=-3}n&4096&&(e.flags&=-4097)}function q_(e,n,s){Fe=e,X$(e)}function X$(e,n,s){for(var r=(e.mode&1)!==0;Fe!==null;){var a=Fe,i=a.child;if(a.tag===22&&r){var l=a.memoizedState!==null||Jd;if(!l){var o=a.alternate,c=o!==null&&o.memoizedState!==null||es;o=Jd;var u=es;if(Jd=l,(es=c)&&!u)for(Fe=a;Fe!==null;)l=Fe,c=l.child,l.tag===22&&l.memoizedState!==null?DN(a):c!==null?(c.return=l,Fe=c):DN(a);for(;i!==null;)Fe=i,X$(i),i=i.sibling;Fe=a,Jd=o,es=u}MN(e)}else a.subtreeFlags&8772&&i!==null?(i.return=a,Fe=i):MN(e)}}function MN(e){for(;Fe!==null;){var n=Fe;if(n.flags&8772){var s=n.alternate;try{if(n.flags&8772)switch(n.tag){case 0:case 11:case 15:es||Am(5,n);break;case 1:var r=n.stateNode;if(n.flags&4&&!es)if(s===null)r.componentDidMount();else{var a=n.elementType===n.type?s.memoizedProps:br(n.type,s.memoizedProps);r.componentDidUpdate(a,s.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var i=n.updateQueue;i!==null&&jN(n,i,r);break;case 3:var l=n.updateQueue;if(l!==null){if(s=null,n.child!==null)switch(n.child.tag){case 5:s=n.child.stateNode;break;case 1:s=n.child.stateNode}jN(n,l,s)}break;case 5:var o=n.stateNode;if(s===null&&n.flags&4){s=o;var c=n.memoizedProps;switch(n.type){case"button":case"input":case"select":case"textarea":c.autoFocus&&s.focus();break;case"img":c.src&&(s.src=c.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(n.memoizedState===null){var u=n.alternate;if(u!==null){var h=u.memoizedState;if(h!==null){var m=h.dehydrated;m!==null&&fu(m)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(Te(163))}es||n.flags&512&&jj(n)}catch(f){mn(n,n.return,f)}}if(n===e){Fe=null;break}if(s=n.sibling,s!==null){s.return=n.return,Fe=s;break}Fe=n.return}}function ON(e){for(;Fe!==null;){var n=Fe;if(n===e){Fe=null;break}var s=n.sibling;if(s!==null){s.return=n.return,Fe=s;break}Fe=n.return}}function DN(e){for(;Fe!==null;){var n=Fe;try{switch(n.tag){case 0:case 11:case 15:var s=n.return;try{Am(4,n)}catch(c){mn(n,s,c)}break;case 1:var r=n.stateNode;if(typeof r.componentDidMount=="function"){var a=n.return;try{r.componentDidMount()}catch(c){mn(n,a,c)}}var i=n.return;try{jj(n)}catch(c){mn(n,i,c)}break;case 5:var l=n.return;try{jj(n)}catch(c){mn(n,l,c)}}}catch(c){mn(n,n.return,c)}if(n===e){Fe=null;break}var o=n.sibling;if(o!==null){o.return=n.return,Fe=o;break}Fe=n.return}}var Y_=Math.ceil,Ef=Fa.ReactCurrentDispatcher,pw=Fa.ReactCurrentOwner,ur=Fa.ReactCurrentBatchConfig,Rt=0,zn=null,Sn=null,Gn=0,Os=0,so=Si(0),In=0,Nu=null,ol=0,$m=0,gw=0,Qc=null,ws=null,xw=0,$o=1/0,xa=null,Af=!1,wj=null,oi=null,Xd=!1,ei=null,$f=0,Jc=0,bj=null,_h=-1,zh=0;function hs(){return Rt&6?jn():_h!==-1?_h:_h=jn()}function ci(e){return e.mode&1?Rt&2&&Gn!==0?Gn&-Gn:I_.transition!==null?(zh===0&&(zh=DA()),zh):(e=Ft,e!==0||(e=window.event,e=e===void 0?16:WA(e.type)),e):1}function $r(e,n,s,r){if(50<Jc)throw Jc=0,bj=null,Error(Te(185));ad(e,s,r),(!(Rt&2)||e!==zn)&&(e===zn&&(!(Rt&2)&&($m|=s),In===4&&Ja(e,Gn)),Es(e,r),s===1&&Rt===0&&!(n.mode&1)&&($o=jn()+500,Sm&&Ci()))}function Es(e,n){var s=e.callbackNode;IF(e,n);var r=hf(e,e===zn?Gn:0);if(r===0)s!==null&&K0(s),e.callbackNode=null,e.callbackPriority=0;else if(n=r&-r,e.callbackPriority!==n){if(s!=null&&K0(s),n===1)e.tag===0?R_(LN.bind(null,e)):o$(LN.bind(null,e)),E_(function(){!(Rt&6)&&Ci()}),s=null;else{switch(LA(r)){case 1:s=Wy;break;case 4:s=MA;break;case 16:s=df;break;case 536870912:s=OA;break;default:s=df}s=iT(s,Z$.bind(null,e))}e.callbackPriority=n,e.callbackNode=s}}function Z$(e,n){if(_h=-1,zh=0,Rt&6)throw Error(Te(327));var s=e.callbackNode;if(po()&&e.callbackNode!==s)return null;var r=hf(e,e===zn?Gn:0);if(r===0)return null;if(r&30||r&e.expiredLanes||n)n=Tf(e,r);else{n=r;var a=Rt;Rt|=2;var i=tT();(zn!==e||Gn!==n)&&(xa=null,$o=jn()+500,el(e,n));do try{X_();break}catch(o){eT(e,o)}while(!0);nw(),Ef.current=i,Rt=a,Sn!==null?n=0:(zn=null,Gn=0,n=In)}if(n!==0){if(n===2&&(a=Yx(e),a!==0&&(r=a,n=kj(e,a))),n===1)throw s=Nu,el(e,0),Ja(e,r),Es(e,jn()),s;if(n===6)Ja(e,r);else{if(a=e.current.alternate,!(r&30)&&!Q_(a)&&(n=Tf(e,r),n===2&&(i=Yx(e),i!==0&&(r=i,n=kj(e,i))),n===1))throw s=Nu,el(e,0),Ja(e,r),Es(e,jn()),s;switch(e.finishedWork=a,e.finishedLanes=r,n){case 0:case 1:throw Error(Te(345));case 2:Wi(e,ws,xa);break;case 3:if(Ja(e,r),(r&130023424)===r&&(n=xw+500-jn(),10<n)){if(hf(e,0)!==0)break;if(a=e.suspendedLanes,(a&r)!==r){hs(),e.pingedLanes|=e.suspendedLanes&a;break}e.timeoutHandle=sj(Wi.bind(null,e,ws,xa),n);break}Wi(e,ws,xa);break;case 4:if(Ja(e,r),(r&4194240)===r)break;for(n=e.eventTimes,a=-1;0<r;){var l=31-Ar(r);i=1<<l,l=n[l],l>a&&(a=l),r&=~i}if(r=a,r=jn()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*Y_(r/1960))-r,10<r){e.timeoutHandle=sj(Wi.bind(null,e,ws,xa),r);break}Wi(e,ws,xa);break;case 5:Wi(e,ws,xa);break;default:throw Error(Te(329))}}}return Es(e,jn()),e.callbackNode===s?Z$.bind(null,e):null}function kj(e,n){var s=Qc;return e.current.memoizedState.isDehydrated&&(el(e,n).flags|=256),e=Tf(e,n),e!==2&&(n=ws,ws=s,n!==null&&Nj(n)),e}function Nj(e){ws===null?ws=e:ws.push.apply(ws,e)}function Q_(e){for(var n=e;;){if(n.flags&16384){var s=n.updateQueue;if(s!==null&&(s=s.stores,s!==null))for(var r=0;r<s.length;r++){var a=s[r],i=a.getSnapshot;a=a.value;try{if(!Ir(i(),a))return!1}catch{return!1}}}if(s=n.child,n.subtreeFlags&16384&&s!==null)s.return=n,n=s;else{if(n===e)break;for(;n.sibling===null;){if(n.return===null||n.return===e)return!0;n=n.return}n.sibling.return=n.return,n=n.sibling}}return!0}function Ja(e,n){for(n&=~gw,n&=~$m,e.suspendedLanes|=n,e.pingedLanes&=~n,e=e.expirationTimes;0<n;){var s=31-Ar(n),r=1<<s;e[s]=-1,n&=~r}}function LN(e){if(Rt&6)throw Error(Te(327));po();var n=hf(e,0);if(!(n&1))return Es(e,jn()),null;var s=Tf(e,n);if(e.tag!==0&&s===2){var r=Yx(e);r!==0&&(n=r,s=kj(e,r))}if(s===1)throw s=Nu,el(e,0),Ja(e,n),Es(e,jn()),s;if(s===6)throw Error(Te(345));return e.finishedWork=e.current.alternate,e.finishedLanes=n,Wi(e,ws,xa),Es(e,jn()),null}function jw(e,n){var s=Rt;Rt|=1;try{return e(n)}finally{Rt=s,Rt===0&&($o=jn()+500,Sm&&Ci())}}function cl(e){ei!==null&&ei.tag===0&&!(Rt&6)&&po();var n=Rt;Rt|=1;var s=ur.transition,r=Ft;try{if(ur.transition=null,Ft=1,e)return e()}finally{Ft=r,ur.transition=s,Rt=n,!(Rt&6)&&Ci()}}function vw(){Os=so.current,Xt(so)}function el(e,n){e.finishedWork=null,e.finishedLanes=0;var s=e.timeoutHandle;if(s!==-1&&(e.timeoutHandle=-1,C_(s)),Sn!==null)for(s=Sn.return;s!==null;){var r=s;switch(Zy(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&xf();break;case 3:Eo(),Xt(Ss),Xt(ns),ow();break;case 5:lw(r);break;case 4:Eo();break;case 13:Xt(rn);break;case 19:Xt(rn);break;case 10:sw(r.type._context);break;case 22:case 23:vw()}s=s.return}if(zn=e,Sn=e=ui(e.current,null),Gn=Os=n,In=0,Nu=null,gw=$m=ol=0,ws=Qc=null,Gi!==null){for(n=0;n<Gi.length;n++)if(s=Gi[n],r=s.interleaved,r!==null){s.interleaved=null;var a=r.next,i=s.pending;if(i!==null){var l=i.next;i.next=a,r.next=l}s.pending=r}Gi=null}return e}function eT(e,n){do{var s=Sn;try{if(nw(),Dh.current=Cf,Sf){for(var r=an.memoizedState;r!==null;){var a=r.queue;a!==null&&(a.pending=null),r=r.next}Sf=!1}if(ll=0,Ln=Tn=an=null,qc=!1,wu=0,pw.current=null,s===null||s.return===null){In=1,Nu=n,Sn=null;break}e:{var i=e,l=s.return,o=s,c=n;if(n=Gn,o.flags|=32768,c!==null&&typeof c=="object"&&typeof c.then=="function"){var u=c,h=o,m=h.tag;if(!(h.mode&1)&&(m===0||m===11||m===15)){var f=h.alternate;f?(h.updateQueue=f.updateQueue,h.memoizedState=f.memoizedState,h.lanes=f.lanes):(h.updateQueue=null,h.memoizedState=null)}var p=NN(l);if(p!==null){p.flags&=-257,SN(p,l,o,i,n),p.mode&1&&kN(i,u,n),n=p,c=u;var x=n.updateQueue;if(x===null){var g=new Set;g.add(c),n.updateQueue=g}else x.add(c);break e}else{if(!(n&1)){kN(i,u,n),yw();break e}c=Error(Te(426))}}else if(tn&&o.mode&1){var w=NN(l);if(w!==null){!(w.flags&65536)&&(w.flags|=256),SN(w,l,o,i,n),ew(Ao(c,o));break e}}i=c=Ao(c,o),In!==4&&(In=2),Qc===null?Qc=[i]:Qc.push(i),i=l;do{switch(i.tag){case 3:i.flags|=65536,n&=-n,i.lanes|=n;var v=L$(i,c,n);xN(i,v);break e;case 1:o=c;var j=i.type,y=i.stateNode;if(!(i.flags&128)&&(typeof j.getDerivedStateFromError=="function"||y!==null&&typeof y.componentDidCatch=="function"&&(oi===null||!oi.has(y)))){i.flags|=65536,n&=-n,i.lanes|=n;var k=F$(i,o,n);xN(i,k);break e}}i=i.return}while(i!==null)}sT(s)}catch(N){n=N,Sn===s&&s!==null&&(Sn=s=s.return);continue}break}while(!0)}function tT(){var e=Ef.current;return Ef.current=Cf,e===null?Cf:e}function yw(){(In===0||In===3||In===2)&&(In=4),zn===null||!(ol&268435455)&&!($m&268435455)||Ja(zn,Gn)}function Tf(e,n){var s=Rt;Rt|=2;var r=tT();(zn!==e||Gn!==n)&&(xa=null,el(e,n));do try{J_();break}catch(a){eT(e,a)}while(!0);if(nw(),Rt=s,Ef.current=r,Sn!==null)throw Error(Te(261));return zn=null,Gn=0,In}function J_(){for(;Sn!==null;)nT(Sn)}function X_(){for(;Sn!==null&&!kF();)nT(Sn)}function nT(e){var n=aT(e.alternate,e,Os);e.memoizedProps=e.pendingProps,n===null?sT(e):Sn=n,pw.current=null}function sT(e){var n=e;do{var s=n.alternate;if(e=n.return,n.flags&32768){if(s=K_(s,n),s!==null){s.flags&=32767,Sn=s;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{In=6,Sn=null;return}}else if(s=H_(s,n,Os),s!==null){Sn=s;return}if(n=n.sibling,n!==null){Sn=n;return}Sn=n=e}while(n!==null);In===0&&(In=5)}function Wi(e,n,s){var r=Ft,a=ur.transition;try{ur.transition=null,Ft=1,Z_(e,n,s,r)}finally{ur.transition=a,Ft=r}return null}function Z_(e,n,s,r){do po();while(ei!==null);if(Rt&6)throw Error(Te(327));s=e.finishedWork;var a=e.finishedLanes;if(s===null)return null;if(e.finishedWork=null,e.finishedLanes=0,s===e.current)throw Error(Te(177));e.callbackNode=null,e.callbackPriority=0;var i=s.lanes|s.childLanes;if(PF(e,i),e===zn&&(Sn=zn=null,Gn=0),!(s.subtreeFlags&2064)&&!(s.flags&2064)||Xd||(Xd=!0,iT(df,function(){return po(),null})),i=(s.flags&15990)!==0,s.subtreeFlags&15990||i){i=ur.transition,ur.transition=null;var l=Ft;Ft=1;var o=Rt;Rt|=4,pw.current=null,G_(e,s),J$(s,e),v_(tj),ff=!!ej,tj=ej=null,e.current=s,q_(s),NF(),Rt=o,Ft=l,ur.transition=i}else e.current=s;if(Xd&&(Xd=!1,ei=e,$f=a),i=e.pendingLanes,i===0&&(oi=null),EF(s.stateNode),Es(e,jn()),n!==null)for(r=e.onRecoverableError,s=0;s<n.length;s++)a=n[s],r(a.value,{componentStack:a.stack,digest:a.digest});if(Af)throw Af=!1,e=wj,wj=null,e;return $f&1&&e.tag!==0&&po(),i=e.pendingLanes,i&1?e===bj?Jc++:(Jc=0,bj=e):Jc=0,Ci(),null}function po(){if(ei!==null){var e=LA($f),n=ur.transition,s=Ft;try{if(ur.transition=null,Ft=16>e?16:e,ei===null)var r=!1;else{if(e=ei,ei=null,$f=0,Rt&6)throw Error(Te(331));var a=Rt;for(Rt|=4,Fe=e.current;Fe!==null;){var i=Fe,l=i.child;if(Fe.flags&16){var o=i.deletions;if(o!==null){for(var c=0;c<o.length;c++){var u=o[c];for(Fe=u;Fe!==null;){var h=Fe;switch(h.tag){case 0:case 11:case 15:Yc(8,h,i)}var m=h.child;if(m!==null)m.return=h,Fe=m;else for(;Fe!==null;){h=Fe;var f=h.sibling,p=h.return;if(q$(h),h===u){Fe=null;break}if(f!==null){f.return=p,Fe=f;break}Fe=p}}}var x=i.alternate;if(x!==null){var g=x.child;if(g!==null){x.child=null;do{var w=g.sibling;g.sibling=null,g=w}while(g!==null)}}Fe=i}}if(i.subtreeFlags&2064&&l!==null)l.return=i,Fe=l;else e:for(;Fe!==null;){if(i=Fe,i.flags&2048)switch(i.tag){case 0:case 11:case 15:Yc(9,i,i.return)}var v=i.sibling;if(v!==null){v.return=i.return,Fe=v;break e}Fe=i.return}}var j=e.current;for(Fe=j;Fe!==null;){l=Fe;var y=l.child;if(l.subtreeFlags&2064&&y!==null)y.return=l,Fe=y;else e:for(l=j;Fe!==null;){if(o=Fe,o.flags&2048)try{switch(o.tag){case 0:case 11:case 15:Am(9,o)}}catch(N){mn(o,o.return,N)}if(o===l){Fe=null;break e}var k=o.sibling;if(k!==null){k.return=o.return,Fe=k;break e}Fe=o.return}}if(Rt=a,Ci(),ta&&typeof ta.onPostCommitFiberRoot=="function")try{ta.onPostCommitFiberRoot(ym,e)}catch{}r=!0}return r}finally{Ft=s,ur.transition=n}}return!1}function FN(e,n,s){n=Ao(s,n),n=L$(e,n,1),e=li(e,n,1),n=hs(),e!==null&&(ad(e,1,n),Es(e,n))}function mn(e,n,s){if(e.tag===3)FN(e,e,s);else for(;n!==null;){if(n.tag===3){FN(n,e,s);break}else if(n.tag===1){var r=n.stateNode;if(typeof n.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(oi===null||!oi.has(r))){e=Ao(s,e),e=F$(n,e,1),n=li(n,e,1),e=hs(),n!==null&&(ad(n,1,e),Es(n,e));break}}n=n.return}}function e4(e,n,s){var r=e.pingCache;r!==null&&r.delete(n),n=hs(),e.pingedLanes|=e.suspendedLanes&s,zn===e&&(Gn&s)===s&&(In===4||In===3&&(Gn&130023424)===Gn&&500>jn()-xw?el(e,0):gw|=s),Es(e,n)}function rT(e,n){n===0&&(e.mode&1?(n=Bd,Bd<<=1,!(Bd&130023424)&&(Bd=4194304)):n=1);var s=hs();e=Ia(e,n),e!==null&&(ad(e,n,s),Es(e,s))}function t4(e){var n=e.memoizedState,s=0;n!==null&&(s=n.retryLane),rT(e,s)}function n4(e,n){var s=0;switch(e.tag){case 13:var r=e.stateNode,a=e.memoizedState;a!==null&&(s=a.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(Te(314))}r!==null&&r.delete(n),rT(e,s)}var aT;aT=function(e,n,s){if(e!==null)if(e.memoizedProps!==n.pendingProps||Ss.current)ks=!0;else{if(!(e.lanes&s)&&!(n.flags&128))return ks=!1,W_(e,n,s);ks=!!(e.flags&131072)}else ks=!1,tn&&n.flags&1048576&&c$(n,yf,n.index);switch(n.lanes=0,n.tag){case 2:var r=n.type;Fh(e,n),e=n.pendingProps;var a=No(n,ns.current);mo(n,s),a=uw(null,n,r,e,a,s);var i=dw();return n.flags|=1,typeof a=="object"&&a!==null&&typeof a.render=="function"&&a.$$typeof===void 0?(n.tag=1,n.memoizedState=null,n.updateQueue=null,Cs(r)?(i=!0,jf(n)):i=!1,n.memoizedState=a.state!==null&&a.state!==void 0?a.state:null,aw(n),a.updater=Em,n.stateNode=a,a._reactInternals=n,uj(n,r,e,s),n=fj(null,n,r,!0,i,s)):(n.tag=0,tn&&i&&Xy(n),cs(null,n,a,s),n=n.child),n;case 16:r=n.elementType;e:{switch(Fh(e,n),e=n.pendingProps,a=r._init,r=a(r._payload),n.type=r,a=n.tag=r4(r),e=br(r,e),a){case 0:n=hj(null,n,r,e,s);break e;case 1:n=AN(null,n,r,e,s);break e;case 11:n=CN(null,n,r,e,s);break e;case 14:n=EN(null,n,r,br(r.type,e),s);break e}throw Error(Te(306,r,""))}return n;case 0:return r=n.type,a=n.pendingProps,a=n.elementType===r?a:br(r,a),hj(e,n,r,a,s);case 1:return r=n.type,a=n.pendingProps,a=n.elementType===r?a:br(r,a),AN(e,n,r,a,s);case 3:e:{if(B$(n),e===null)throw Error(Te(387));r=n.pendingProps,i=n.memoizedState,a=i.element,p$(e,n),kf(n,r,null,s);var l=n.memoizedState;if(r=l.element,i.isDehydrated)if(i={element:r,isDehydrated:!1,cache:l.cache,pendingSuspenseBoundaries:l.pendingSuspenseBoundaries,transitions:l.transitions},n.updateQueue.baseState=i,n.memoizedState=i,n.flags&256){a=Ao(Error(Te(423)),n),n=$N(e,n,r,s,a);break e}else if(r!==a){a=Ao(Error(Te(424)),n),n=$N(e,n,r,s,a);break e}else for(Fs=ii(n.stateNode.containerInfo.firstChild),zs=n,tn=!0,Nr=null,s=f$(n,null,r,s),n.child=s;s;)s.flags=s.flags&-3|4096,s=s.sibling;else{if(So(),r===a){n=Pa(e,n,s);break e}cs(e,n,r,s)}n=n.child}return n;case 5:return g$(n),e===null&&lj(n),r=n.type,a=n.pendingProps,i=e!==null?e.memoizedProps:null,l=a.children,nj(r,a)?l=null:i!==null&&nj(r,i)&&(n.flags|=32),U$(e,n),cs(e,n,l,s),n.child;case 6:return e===null&&lj(n),null;case 13:return W$(e,n,s);case 4:return iw(n,n.stateNode.containerInfo),r=n.pendingProps,e===null?n.child=Co(n,null,r,s):cs(e,n,r,s),n.child;case 11:return r=n.type,a=n.pendingProps,a=n.elementType===r?a:br(r,a),CN(e,n,r,a,s);case 7:return cs(e,n,n.pendingProps,s),n.child;case 8:return cs(e,n,n.pendingProps.children,s),n.child;case 12:return cs(e,n,n.pendingProps.children,s),n.child;case 10:e:{if(r=n.type._context,a=n.pendingProps,i=n.memoizedProps,l=a.value,Yt(wf,r._currentValue),r._currentValue=l,i!==null)if(Ir(i.value,l)){if(i.children===a.children&&!Ss.current){n=Pa(e,n,s);break e}}else for(i=n.child,i!==null&&(i.return=n);i!==null;){var o=i.dependencies;if(o!==null){l=i.child;for(var c=o.firstContext;c!==null;){if(c.context===r){if(i.tag===1){c=Sa(-1,s&-s),c.tag=2;var u=i.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}}i.lanes|=s,c=i.alternate,c!==null&&(c.lanes|=s),oj(i.return,s,n),o.lanes|=s;break}c=c.next}}else if(i.tag===10)l=i.type===n.type?null:i.child;else if(i.tag===18){if(l=i.return,l===null)throw Error(Te(341));l.lanes|=s,o=l.alternate,o!==null&&(o.lanes|=s),oj(l,s,n),l=i.sibling}else l=i.child;if(l!==null)l.return=i;else for(l=i;l!==null;){if(l===n){l=null;break}if(i=l.sibling,i!==null){i.return=l.return,l=i;break}l=l.return}i=l}cs(e,n,a.children,s),n=n.child}return n;case 9:return a=n.type,r=n.pendingProps.children,mo(n,s),a=hr(a),r=r(a),n.flags|=1,cs(e,n,r,s),n.child;case 14:return r=n.type,a=br(r,n.pendingProps),a=br(r.type,a),EN(e,n,r,a,s);case 15:return _$(e,n,n.type,n.pendingProps,s);case 17:return r=n.type,a=n.pendingProps,a=n.elementType===r?a:br(r,a),Fh(e,n),n.tag=1,Cs(r)?(e=!0,jf(n)):e=!1,mo(n,s),D$(n,r,a),uj(n,r,a,s),fj(null,n,r,!0,e,s);case 19:return H$(e,n,s);case 22:return z$(e,n,s)}throw Error(Te(156,n.tag))};function iT(e,n){return PA(e,n)}function s4(e,n,s,r){this.tag=e,this.key=s,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=n,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function cr(e,n,s,r){return new s4(e,n,s,r)}function ww(e){return e=e.prototype,!(!e||!e.isReactComponent)}function r4(e){if(typeof e=="function")return ww(e)?1:0;if(e!=null){if(e=e.$$typeof,e===zy)return 11;if(e===Uy)return 14}return 2}function ui(e,n){var s=e.alternate;return s===null?(s=cr(e.tag,n,e.key,e.mode),s.elementType=e.elementType,s.type=e.type,s.stateNode=e.stateNode,s.alternate=e,e.alternate=s):(s.pendingProps=n,s.type=e.type,s.flags=0,s.subtreeFlags=0,s.deletions=null),s.flags=e.flags&14680064,s.childLanes=e.childLanes,s.lanes=e.lanes,s.child=e.child,s.memoizedProps=e.memoizedProps,s.memoizedState=e.memoizedState,s.updateQueue=e.updateQueue,n=e.dependencies,s.dependencies=n===null?null:{lanes:n.lanes,firstContext:n.firstContext},s.sibling=e.sibling,s.index=e.index,s.ref=e.ref,s}function Uh(e,n,s,r,a,i){var l=2;if(r=e,typeof e=="function")ww(e)&&(l=1);else if(typeof e=="string")l=5;else e:switch(e){case Gl:return tl(s.children,a,i,n);case _y:l=8,a|=8;break;case Mx:return e=cr(12,s,n,a|2),e.elementType=Mx,e.lanes=i,e;case Ox:return e=cr(13,s,n,a),e.elementType=Ox,e.lanes=i,e;case Dx:return e=cr(19,s,n,a),e.elementType=Dx,e.lanes=i,e;case gA:return Tm(s,a,i,n);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case mA:l=10;break e;case pA:l=9;break e;case zy:l=11;break e;case Uy:l=14;break e;case qa:l=16,r=null;break e}throw Error(Te(130,e==null?e:typeof e,""))}return n=cr(l,s,n,a),n.elementType=e,n.type=r,n.lanes=i,n}function tl(e,n,s,r){return e=cr(7,e,r,n),e.lanes=s,e}function Tm(e,n,s,r){return e=cr(22,e,r,n),e.elementType=gA,e.lanes=s,e.stateNode={isHidden:!1},e}function mg(e,n,s){return e=cr(6,e,null,n),e.lanes=s,e}function pg(e,n,s){return n=cr(4,e.children!==null?e.children:[],e.key,n),n.lanes=s,n.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},n}function a4(e,n,s,r,a){this.tag=n,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Yp(0),this.expirationTimes=Yp(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Yp(0),this.identifierPrefix=r,this.onRecoverableError=a,this.mutableSourceEagerHydrationData=null}function bw(e,n,s,r,a,i,l,o,c){return e=new a4(e,n,s,o,c),n===1?(n=1,i===!0&&(n|=8)):n=0,i=cr(3,null,null,n),e.current=i,i.stateNode=e,i.memoizedState={element:r,isDehydrated:s,cache:null,transitions:null,pendingSuspenseBoundaries:null},aw(i),e}function i4(e,n,s){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:Vl,key:r==null?null:""+r,children:e,containerInfo:n,implementation:s}}function lT(e){if(!e)return pi;e=e._reactInternals;e:{if(yl(e)!==e||e.tag!==1)throw Error(Te(170));var n=e;do{switch(n.tag){case 3:n=n.stateNode.context;break e;case 1:if(Cs(n.type)){n=n.stateNode.__reactInternalMemoizedMergedChildContext;break e}}n=n.return}while(n!==null);throw Error(Te(171))}if(e.tag===1){var s=e.type;if(Cs(s))return l$(e,s,n)}return n}function oT(e,n,s,r,a,i,l,o,c){return e=bw(s,r,!0,e,a,i,l,o,c),e.context=lT(null),s=e.current,r=hs(),a=ci(s),i=Sa(r,a),i.callback=n??null,li(s,i,a),e.current.lanes=a,ad(e,a,r),Es(e,r),e}function Rm(e,n,s,r){var a=n.current,i=hs(),l=ci(a);return s=lT(s),n.context===null?n.context=s:n.pendingContext=s,n=Sa(i,l),n.payload={element:e},r=r===void 0?null:r,r!==null&&(n.callback=r),e=li(a,n,l),e!==null&&($r(e,a,l,i),Oh(e,a,l)),l}function Rf(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 _N(e,n){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var s=e.retryLane;e.retryLane=s!==0&&s<n?s:n}}function kw(e,n){_N(e,n),(e=e.alternate)&&_N(e,n)}function l4(){return null}var cT=typeof reportError=="function"?reportError:function(e){console.error(e)};function Nw(e){this._internalRoot=e}Im.prototype.render=Nw.prototype.render=function(e){var n=this._internalRoot;if(n===null)throw Error(Te(409));Rm(e,n,null,null)};Im.prototype.unmount=Nw.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var n=e.containerInfo;cl(function(){Rm(null,e,null,null)}),n[Ra]=null}};function Im(e){this._internalRoot=e}Im.prototype.unstable_scheduleHydration=function(e){if(e){var n=zA();e={blockedOn:null,target:e,priority:n};for(var s=0;s<Qa.length&&n!==0&&n<Qa[s].priority;s++);Qa.splice(s,0,e),s===0&&BA(e)}};function Sw(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function Pm(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function zN(){}function o4(e,n,s,r,a){if(a){if(typeof r=="function"){var i=r;r=function(){var u=Rf(l);i.call(u)}}var l=oT(n,r,e,0,null,!1,!1,"",zN);return e._reactRootContainer=l,e[Ra]=l.current,gu(e.nodeType===8?e.parentNode:e),cl(),l}for(;a=e.lastChild;)e.removeChild(a);if(typeof r=="function"){var o=r;r=function(){var u=Rf(c);o.call(u)}}var c=bw(e,0,!1,null,null,!1,!1,"",zN);return e._reactRootContainer=c,e[Ra]=c.current,gu(e.nodeType===8?e.parentNode:e),cl(function(){Rm(n,c,s,r)}),c}function Mm(e,n,s,r,a){var i=s._reactRootContainer;if(i){var l=i;if(typeof a=="function"){var o=a;a=function(){var c=Rf(l);o.call(c)}}Rm(n,l,e,a)}else l=o4(s,n,e,a,r);return Rf(l)}FA=function(e){switch(e.tag){case 3:var n=e.stateNode;if(n.current.memoizedState.isDehydrated){var s=Dc(n.pendingLanes);s!==0&&(Hy(n,s|1),Es(n,jn()),!(Rt&6)&&($o=jn()+500,Ci()))}break;case 13:cl(function(){var r=Ia(e,1);if(r!==null){var a=hs();$r(r,e,1,a)}}),kw(e,1)}};Ky=function(e){if(e.tag===13){var n=Ia(e,134217728);if(n!==null){var s=hs();$r(n,e,134217728,s)}kw(e,134217728)}};_A=function(e){if(e.tag===13){var n=ci(e),s=Ia(e,n);if(s!==null){var r=hs();$r(s,e,n,r)}kw(e,n)}};zA=function(){return Ft};UA=function(e,n){var s=Ft;try{return Ft=e,n()}finally{Ft=s}};Vx=function(e,n,s){switch(n){case"input":if(_x(e,s),n=s.name,s.type==="radio"&&n!=null){for(s=e;s.parentNode;)s=s.parentNode;for(s=s.querySelectorAll("input[name="+JSON.stringify(""+n)+'][type="radio"]'),n=0;n<s.length;n++){var r=s[n];if(r!==e&&r.form===e.form){var a=Nm(r);if(!a)throw Error(Te(90));jA(r),_x(r,a)}}}break;case"textarea":yA(e,s);break;case"select":n=s.value,n!=null&&co(e,!!s.multiple,n,!1)}};EA=jw;AA=cl;var c4={usingClientEntryPoint:!1,Events:[ld,Jl,Nm,SA,CA,jw]},Nc={findFiberByHostInstance:Vi,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},u4={bundleType:Nc.bundleType,version:Nc.version,rendererPackageName:Nc.rendererPackageName,rendererConfig:Nc.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:Fa.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=RA(e),e===null?null:e.stateNode},findFiberByHostInstance:Nc.findFiberByHostInstance||l4,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 Zd=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Zd.isDisabled&&Zd.supportsFiber)try{ym=Zd.inject(u4),ta=Zd}catch{}}qs.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=c4;qs.createPortal=function(e,n){var s=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!Sw(n))throw Error(Te(200));return i4(e,n,null,s)};qs.createRoot=function(e,n){if(!Sw(e))throw Error(Te(299));var s=!1,r="",a=cT;return n!=null&&(n.unstable_strictMode===!0&&(s=!0),n.identifierPrefix!==void 0&&(r=n.identifierPrefix),n.onRecoverableError!==void 0&&(a=n.onRecoverableError)),n=bw(e,1,!1,null,null,s,!1,r,a),e[Ra]=n.current,gu(e.nodeType===8?e.parentNode:e),new Nw(n)};qs.findDOMNode=function(e){if(e==null)return null;if(e.nodeType===1)return e;var n=e._reactInternals;if(n===void 0)throw typeof e.render=="function"?Error(Te(188)):(e=Object.keys(e).join(","),Error(Te(268,e)));return e=RA(n),e=e===null?null:e.stateNode,e};qs.flushSync=function(e){return cl(e)};qs.hydrate=function(e,n,s){if(!Pm(n))throw Error(Te(200));return Mm(null,e,n,!0,s)};qs.hydrateRoot=function(e,n,s){if(!Sw(e))throw Error(Te(405));var r=s!=null&&s.hydratedSources||null,a=!1,i="",l=cT;if(s!=null&&(s.unstable_strictMode===!0&&(a=!0),s.identifierPrefix!==void 0&&(i=s.identifierPrefix),s.onRecoverableError!==void 0&&(l=s.onRecoverableError)),n=oT(n,null,e,1,s??null,a,!1,i,l),e[Ra]=n.current,gu(e),r)for(e=0;e<r.length;e++)s=r[e],a=s._getVersion,a=a(s._source),n.mutableSourceEagerHydrationData==null?n.mutableSourceEagerHydrationData=[s,a]:n.mutableSourceEagerHydrationData.push(s,a);return new Im(n)};qs.render=function(e,n,s){if(!Pm(n))throw Error(Te(200));return Mm(null,e,n,!1,s)};qs.unmountComponentAtNode=function(e){if(!Pm(e))throw Error(Te(40));return e._reactRootContainer?(cl(function(){Mm(null,null,e,!1,function(){e._reactRootContainer=null,e[Ra]=null})}),!0):!1};qs.unstable_batchedUpdates=jw;qs.unstable_renderSubtreeIntoContainer=function(e,n,s,r){if(!Pm(s))throw Error(Te(200));if(e==null||e._reactInternals===void 0)throw Error(Te(38));return Mm(e,n,s,!1,r)};qs.version="18.3.1-next-f1338f8080-20240426";function uT(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(uT)}catch(e){console.error(e)}}uT(),uA.exports=qs;var qo=uA.exports,dT,UN=qo;dT=UN.createRoot,UN.hydrateRoot;const d4=["use","new","stop","quiet"];function BN(e){return d4.includes(e)}function h4(e,n){return[{group:"This chat",name:"use",args:"<agent>",desc:"Talk to another agent from here on",source:"chat"},{group:"This chat",name:"new",args:"[what it is for]",desc:"Make a new agent with Agent Father",source:"chat"},{group:"This chat",name:"stop",desc:n?`Stop what ${e} is doing`:"Nothing is running",key:"Esc",off:!n,source:"chat"},{group:"This chat",name:"quiet",args:"[1d|1w|off]",desc:"No messages from agents for a while",source:"chat"}]}const f4=e=>e.replace(/^plugin-/,"").replace(/[-_]+/g," ").replace(/^./,n=>n.toUpperCase());function m4(e){return e.map(n=>({group:`From ${f4(n.plugin)}`,name:n.name,...n.args?{args:n.args}:{},desc:n.description,source:"plugin"}))}const p4=e=>!!(e.args&&e.args.startsWith("<"));let If=[];const Sj=new Set;function g4(e){const n=e??[];JSON.stringify(n)!==JSON.stringify(If)&&(If=n,Sj.forEach(s=>s()))}function x4(){return d.useSyncExternalStore(e=>(Sj.add(e),()=>Sj.delete(e)),()=>If,()=>If)}var j4=Object.defineProperty,Yo=(e,n)=>j4(e,"name",{value:n,configurable:!0}),hT=!!(typeof window<"u"&&window.document&&window.document.createElement);function Ge(e,n,{checkForDefaultPrevented:s=!0}={}){return Yo(function(a){if(e==null||e(a),s===!1||!a||!a.defaultPrevented)return n==null?void 0:n(a)},"handleEvent")}Yo(Ge,"composeEventHandlers");function v4(e){var n;if(!hT)throw new Error("Cannot access window outside of the DOM");return((n=e==null?void 0:e.ownerDocument)==null?void 0:n.defaultView)??window}Yo(v4,"getOwnerWindow");function Cj(e){if(!hT)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}Yo(Cj,"getOwnerDocument");function fT(e,n=!1){const{activeElement:s}=Cj(e);if(!(s!=null&&s.nodeName))return null;if(mT(s)&&s.contentDocument)return fT(s.contentDocument.body,n);if(n){const r=s.getAttribute("aria-activedescendant");if(r){const a=Cj(s).getElementById(r);if(a)return a}}return s}Yo(fT,"getActiveElement");function mT(e){return e.tagName==="IFRAME"}Yo(mT,"isFrame");var y4=Object.defineProperty,Cw=(e,n)=>y4(e,"name",{value:n,configurable:!0});function Ej(e,n){if(typeof e=="function")return e(n);e!=null&&(e.current=n)}Cw(Ej,"setRef");function pT(...e){return n=>{let s=!1;const r=e.map(a=>{const i=Ej(a,n);return!s&&typeof i=="function"&&(s=!0),i});if(s)return()=>{for(let a=0;a<r.length;a++){const i=r[a];typeof i=="function"?i():Ej(e[a],null)}}}}Cw(pT,"composeRefs");function Ht(...e){return d.useCallback(pT(...e),e)}Cw(Ht,"useComposedRefs");var w4=Object.defineProperty,or=(e,n)=>w4(e,"name",{value:n,configurable:!0});function b4(e,n){const s=d.createContext(n);s.displayName=e+"Context";const r=or(i=>{const{children:l,...o}=i,c=d.useMemo(()=>o,Object.values(o));return t.jsx(s.Provider,{value:c,children:l})},"Provider");r.displayName=e+"Provider";function a(i,l={}){const{optional:o=!1}=l,c=d.useContext(s);if(c)return c;if(n!==void 0)return n;if(!o)throw new Error(`\`${i}\` must be used within \`${e}\``)}return or(a,"useContext"),[r,a]}or(b4,"createContext");function zr(e,n=[]){let s=[];function r(i,l){const o=d.createContext(l);o.displayName=i+"Context";const c=s.length;s=[...s,l];const u=or(m=>{var v;const{scope:f,children:p,...x}=m,g=((v=f==null?void 0:f[e])==null?void 0:v[c])||o,w=d.useMemo(()=>x,Object.values(x));return t.jsx(g.Provider,{value:w,children:p})},"Provider");u.displayName=i+"Provider";function h(m,f,p={}){var v;const{optional:x=!1}=p,g=((v=f==null?void 0:f[e])==null?void 0:v[c])||o,w=d.useContext(g);if(w)return w;if(l!==void 0)return l;if(!x)throw new Error(`\`${m}\` must be used within \`${i}\``)}return or(h,"useContext"),[u,h]}or(r,"createContext");const a=or(()=>{const i=s.map(l=>d.createContext(l));return or(function(o){const c=(o==null?void 0:o[e])||i;return d.useMemo(()=>({[`__scope${e}`]:{...o,[e]:c}}),[o,c])},"useScope")},"createScope");return a.scopeName=e,[r,gT(a,...n)]}or(zr,"createContextScope");function gT(...e){const n=e[0];if(e.length===1)return n;const s=or(()=>{const r=e.map(a=>({useScope:a(),scopeName:a.scopeName}));return or(function(i){const l=r.reduce((o,{useScope:c,scopeName:u})=>{const m=c(i)[`__scope${u}`];return{...o,...m}},{});return d.useMemo(()=>({[`__scope${n.scopeName}`]:l}),[l])},"useComposedScopes")},"createScope");return s.scopeName=n.scopeName,s}or(gT,"composeContextScopes");var k4=Object.defineProperty,Ur=(e,n)=>k4(e,"name",{value:n,configurable:!0});function gi(e){const n=d.forwardRef((s,r)=>{let{children:a,...i}=s,l=null,o=!1;const c=[];Aj(a)&&typeof eh=="function"&&(a=eh(a._payload)),d.Children.forEach(a,f=>{var p;if(wT(f)){o=!0;const x=f;let g="child"in x.props?x.props.child:x.props.children;Aj(g)&&typeof eh=="function"&&(g=eh(g._payload)),l=N4(x,g),c.push((p=l==null?void 0:l.props)==null?void 0:p.children)}else c.push(f)}),l?l=d.cloneElement(l,void 0,c):!o&&d.Children.count(a)===1&&d.isValidElement(a)&&(l=a);const u=l?yT(l):void 0,h=Ht(r,u);if(!l){if(a||a===0)throw new Error(o?E4(e):C4(e));return a}const m=vT(i,l.props??{});return l.type!==d.Fragment&&(m.ref=r?h:u),d.cloneElement(l,m)});return n.displayName=`${e}.Slot`,n}Ur(gi,"createSlot");var xT=Symbol.for("radix.slottable");function jT(e){const n=Ur(s=>"child"in s?s.children(s.child):s.children,"Slottable");return n.displayName=`${e}.Slottable`,n.__radixId=xT,n}Ur(jT,"createSlottable");var N4=Ur((e,n)=>{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(n)?n:null},"getSlottableElementFromSlottable");function vT(e,n){const s={...n};for(const r in n){const a=e[r],i=n[r];/^on[A-Z]/.test(r)?a&&i?s[r]=(...o)=>{const c=i(...o);return a(...o),c}:a&&(s[r]=a):r==="style"?s[r]={...a,...i}:r==="className"&&(s[r]=[a,i].filter(Boolean).join(" "))}return{...e,...s}}Ur(vT,"mergeProps");function yT(e){var r,a;let n=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,s=n&&"isReactWarning"in n&&n.isReactWarning;return s?e.ref:(n=(a=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:a.get,s=n&&"isReactWarning"in n&&n.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}Ur(yT,"getElementRef");function wT(e){return d.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===xT}Ur(wT,"isSlottable");var S4=Symbol.for("react.lazy");function Aj(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===S4&&"_payload"in e&&bT(e._payload)}Ur(Aj,"isLazyComponent");function bT(e){return typeof e=="object"&&e!==null&&"then"in e}Ur(bT,"isPromiseLike");var C4=Ur(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),E4=Ur(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),eh=Ko[" use ".trim().toString()],A4=Object.defineProperty,Fn=(e,n)=>A4(e,"name",{value:n,configurable:!0});function Om(e){const n=e+"CollectionProvider",[s,r]=zr(n),[a,i]=s(n,{collectionRef:{current:null},itemMap:new Map}),l=Fn(g=>{const{scope:w,children:v}=g,j=d.useRef(null),y=d.useRef(new Map).current;return t.jsx(a,{scope:w,itemMap:y,collectionRef:j,children:v})},"CollectionProvider");l.displayName=n;const o=e+"CollectionSlot",c=gi(o),u=d.forwardRef((g,w)=>{const{scope:v,children:j}=g,y=i(o,v),k=Ht(w,y.collectionRef);return t.jsx(c,{ref:k,children:j})});u.displayName=o;const h=e+"CollectionItemSlot",m="data-radix-collection-item",f=gi(h),p=d.forwardRef((g,w)=>{const{scope:v,children:j,...y}=g,k=d.useRef(null),N=Ht(w,k),b=i(h,v);return d.useEffect(()=>(b.itemMap.set(k,{ref:k,...y}),()=>void b.itemMap.delete(k))),t.jsx(f,{[m]:"",ref:N,children:j})});p.displayName=h;function x(g){const w=i(e+"CollectionConsumer",g);return d.useCallback(()=>{const j=w.collectionRef.current;if(!j)return[];const y=Array.from(j.querySelectorAll(`[${m}]`));return Array.from(w.itemMap.values()).sort((b,S)=>y.indexOf(b.ref.current)-y.indexOf(S.ref.current))},[w.collectionRef,w.itemMap])}return Fn(x,"useCollection"),[{Provider:l,Slot:u,ItemSlot:p},x,r]}Fn(Om,"createCollection");var WN=new WeakMap,kn,Ds,gg=(Ds=class extends Map{constructor(s){super(s);Li(this,kn);ls(this,kn,[...super.keys()]),WN.set(this,!0)}set(s,r){return WN.get(this)&&(this.has(s)?Bt(this,kn)[Bt(this,kn).indexOf(s)]=s:Bt(this,kn).push(s)),super.set(s,r),this}insert(s,r,a){const i=this.has(r),l=Bt(this,kn).length,o=Ew(s);let c=o>=0?o:l+o;const u=c<0||c>=l?-1:c;if(u===this.size||i&&u===this.size-1||u===-1)return this.set(r,a),this;const h=this.size+(i?0:1);o<0&&c++;const m=[...Bt(this,kn)];let f,p=!1;for(let x=c;x<h;x++)if(c===x){let g=m[x];m[x]===r&&(g=m[x+1]),i&&this.delete(r),f=this.get(g),this.set(r,a)}else{!p&&m[x-1]===r&&(p=!0);const g=m[p?x:x-1],w=f;f=this.get(g),this.delete(g),this.set(g,w)}return this}with(s,r,a){const i=new Ds(this);return i.insert(s,r,a),i}before(s){const r=Bt(this,kn).indexOf(s)-1;if(!(r<0))return this.entryAt(r)}setBefore(s,r,a){const i=Bt(this,kn).indexOf(s);return i===-1?this:this.insert(i,r,a)}after(s){let r=Bt(this,kn).indexOf(s);if(r=r===-1||r===this.size-1?-1:r+1,r!==-1)return this.entryAt(r)}setAfter(s,r,a){const i=Bt(this,kn).indexOf(s);return i===-1?this:this.insert(i+1,r,a)}first(){return this.entryAt(0)}last(){return this.entryAt(-1)}clear(){return ls(this,kn,[]),super.clear()}delete(s){const r=super.delete(s);return r&&Bt(this,kn).splice(Bt(this,kn).indexOf(s),1),r}deleteAt(s){const r=this.keyAt(s);return r!==void 0?this.delete(r):!1}at(s){const r=Bh(Bt(this,kn),s);if(r!==void 0)return this.get(r)}entryAt(s){const r=Bh(Bt(this,kn),s);if(r!==void 0)return[r,this.get(r)]}indexOf(s){return Bt(this,kn).indexOf(s)}keyAt(s){return Bh(Bt(this,kn),s)}from(s,r){const a=this.indexOf(s);if(a===-1)return;let i=a+r;return i<0&&(i=0),i>=this.size&&(i=this.size-1),this.at(i)}keyFrom(s,r){const a=this.indexOf(s);if(a===-1)return;let i=a+r;return i<0&&(i=0),i>=this.size&&(i=this.size-1),this.keyAt(i)}find(s,r){let a=0;for(const i of this){if(Reflect.apply(s,r,[i,a,this]))return i;a++}}findIndex(s,r){let a=0;for(const i of this){if(Reflect.apply(s,r,[i,a,this]))return a;a++}return-1}filter(s,r){const a=[];let i=0;for(const l of this)Reflect.apply(s,r,[l,i,this])&&a.push(l),i++;return new Ds(a)}map(s,r){const a=[];let i=0;for(const l of this)a.push([l[0],Reflect.apply(s,r,[l,i,this])]),i++;return new Ds(a)}reduce(...s){const[r,a]=s;let i=0,l=a??this.at(0);for(const o of this)i===0&&s.length===1?l=o:l=Reflect.apply(r,this,[l,o,i,this]),i++;return l}reduceRight(...s){const[r,a]=s;let i=a??this.at(-1);for(let l=this.size-1;l>=0;l--){const o=this.at(l);l===this.size-1&&s.length===1?i=o:i=Reflect.apply(r,this,[i,o,l,this])}return i}toSorted(s){const r=[...this.entries()].sort(s);return new Ds(r)}toReversed(){const s=new Ds;for(let r=this.size-1;r>=0;r--){const a=this.keyAt(r),i=this.get(a);s.set(a,i)}return s}toSpliced(...s){const r=[...this.entries()];return r.splice(...s),new Ds(r)}slice(s,r){const a=new Ds;let i=this.size-1;if(s===void 0)return a;s<0&&(s=s+this.size),r!==void 0&&r>0&&(i=r-1);for(let l=s;l<=i;l++){const o=this.keyAt(l),c=this.get(o);a.set(o,c)}return a}every(s,r){let a=0;for(const i of this){if(!Reflect.apply(s,r,[i,a,this]))return!1;a++}return!0}some(s,r){let a=0;for(const i of this){if(Reflect.apply(s,r,[i,a,this]))return!0;a++}return!1}},kn=new WeakMap,Fn(Ds,"OrderedDict"),Ds);function Bh(e,n){if("at"in Array.prototype)return Array.prototype.at.call(e,n);const s=kT(e,n);return s===-1?void 0:e[s]}Fn(Bh,"at");function kT(e,n){const s=e.length,r=Ew(n),a=r>=0?r:s+r;return a<0||a>=s?-1:a}Fn(kT,"toSafeIndex");function Ew(e){return e!==e||e===0?0:Math.trunc(e)}Fn(Ew,"toSafeInteger");function $4(e){const n=e+"CollectionProvider",[s,r]=zr(n),[a,i]=s(n,{collectionElement:null,collectionRef:{current:null},collectionRefObject:{current:null},itemMap:new gg,setItemMap:Fn(()=>{},"setItemMap")}),l=Fn(({state:y,...k})=>y?t.jsx(c,{...k,state:y}):t.jsx(o,{...k}),"CollectionProvider");l.displayName=n;const o=Fn(y=>{const k=w();return t.jsx(c,{...y,state:k})},"CollectionInit");o.displayName=n+"Init";const c=Fn(y=>{const{scope:k,children:N,state:b}=y,S=d.useRef(null),[C,A]=d.useState(null),E=Ht(S,A),[R,P]=b;return d.useEffect(()=>{if(!C)return;const O=CT(()=>{});return O.observe(C,{childList:!0,subtree:!0}),()=>{O.disconnect()}},[C]),t.jsx(a,{scope:k,itemMap:R,setItemMap:P,collectionRef:E,collectionRefObject:S,collectionElement:C,children:N})},"CollectionProviderImpl");c.displayName=n+"Impl";const u=e+"CollectionSlot",h=gi(u),m=d.forwardRef((y,k)=>{const{scope:N,children:b}=y,S=i(u,N),C=Ht(k,S.collectionRef);return t.jsx(h,{ref:C,children:b})});m.displayName=u;const f=e+"CollectionItemSlot",p="data-radix-collection-item",x=gi(f),g=d.forwardRef((y,k)=>{const{scope:N,children:b,...S}=y,C=d.useRef(null),[A,E]=d.useState(null),R=Ht(k,C,E),P=i(f,N),{setItemMap:O}=P,I=d.useRef(S);NT(I.current,S)||(I.current=S);const F=I.current;return d.useEffect(()=>{const U=F;return O(L=>A?L.has(A)?L.set(A,{...U,element:A}).toSorted($j):(L.set(A,{...U,element:A}),L.toSorted($j)):L),()=>{O(L=>!A||!L.has(A)?L:(L.delete(A),new gg(L)))}},[A,F,O]),t.jsx(x,{[p]:"",ref:R,children:b})});g.displayName=f;function w(){return d.useState(new gg)}Fn(w,"useInitCollection");function v(y){const{itemMap:k}=i(e+"CollectionConsumer",y);return k}return Fn(v,"useCollection"),[{Provider:l,Slot:m,ItemSlot:g},{createCollectionScope:r,useCollection:v,useInitCollection:w}]}Fn($4,"createCollection");function NT(e,n){if(e===n)return!0;if(typeof e!="object"||typeof n!="object"||e==null||n==null)return!1;const s=Object.keys(e),r=Object.keys(n);if(s.length!==r.length)return!1;for(const a of s)if(!Object.prototype.hasOwnProperty.call(n,a)||e[a]!==n[a])return!1;return!0}Fn(NT,"shallowEqual");function ST(e,n){return!!(n.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_PRECEDING)}Fn(ST,"isElementPreceding");function $j(e,n){return!e[1].element||!n[1].element?0:ST(e[1].element,n[1].element)?-1:1}Fn($j,"sortByDocumentPosition");function CT(e){return new MutationObserver(s=>{for(const r of s)if(r.type==="childList"){e();return}})}Fn(CT,"getChildListObserver");var T4=Object.defineProperty,R4=(e,n)=>T4(e,"name",{value:n,configurable:!0}),I4=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],_t=I4.reduce((e,n)=>{const s=gi(`Primitive.${n}`),r=d.forwardRef((a,i)=>{const{asChild:l,...o}=a,c=l?s:n;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),t.jsx(c,{...o,ref:i})});return r.displayName=`Primitive.${n}`,{...e,[n]:r}},{});function Dm(e,n){e&&qo.flushSync(()=>e.dispatchEvent(n))}R4(Dm,"dispatchDiscreteCustomEvent");var P4=Object.defineProperty,M4=(e,n)=>P4(e,"name",{value:n,configurable:!0});function fs(e){const n=d.useRef(e);return d.useEffect(()=>{n.current=e}),d.useMemo(()=>(...s)=>{var r;return(r=n.current)==null?void 0:r.call(n,...s)},[])}M4(fs,"useCallbackRef");var O4=Object.defineProperty,Rn=(e,n)=>O4(e,"name",{value:n,configurable:!0}),Tj="dismissableLayer.update",D4="dismissableLayer.pointerDownOutside",L4="dismissableLayer.focusOutside",HN,Aw=d.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),Lm=d.forwardRef(Rn(function(n,s){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:a=!1,onEscapeKeyDown:i,onPointerDownOutside:l,onFocusOutside:o,onInteractOutside:c,onDismiss:u,...h}=n,m=d.useContext(Aw),[f,p]=d.useState(null),x=(f==null?void 0:f.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,g]=d.useState({}),w=Ht(s,p),v=Array.from(m.layers),[j]=[...m.layersWithOutsidePointerEventsDisabled].slice(-1),y=j?v.indexOf(j):-1,k=f?v.indexOf(f):-1,N=m.layersWithOutsidePointerEventsDisabled.size>0,b=k>=y,S=d.useRef(!1),C=AT(P=>{l==null||l(P),c==null||c(P),P.defaultPrevented||u==null||u()},{ownerDocument:x,deferPointerDownOutside:a,isDeferredPointerDownOutsideRef:S,dismissableSurfaces:m.dismissableSurfaces,shouldHandlePointerDownOutside:d.useCallback(P=>{if(!(P instanceof Node))return!1;const O=[...m.branches].some(I=>I.contains(P));return b&&!O},[m.branches,b])}),A=$T(P=>{if(a&&S.current)return;const O=P.target;[...m.branches].some(F=>F.contains(O))||(o==null||o(P),c==null||c(P),P.defaultPrevented||u==null||u())},x),E=f?k===v.length-1:!1,R=fs(P=>{P.key==="Escape"&&(i==null||i(P),!P.defaultPrevented&&u&&(P.preventDefault(),u()))});return d.useEffect(()=>{if(E)return x.addEventListener("keydown",R,{capture:!0}),()=>x.removeEventListener("keydown",R,{capture:!0})},[x,E,R]),d.useEffect(()=>{if(f)return r&&(m.layersWithOutsidePointerEventsDisabled.size===0&&(HN=x.body.style.pointerEvents,x.body.style.pointerEvents="none"),m.layersWithOutsidePointerEventsDisabled.add(f)),m.layers.add(f),Rj(),()=>{r&&(m.layersWithOutsidePointerEventsDisabled.delete(f),m.layersWithOutsidePointerEventsDisabled.size===0&&(x.body.style.pointerEvents=HN))}},[f,x,r,m]),d.useEffect(()=>()=>{f&&(m.layers.delete(f),m.layersWithOutsidePointerEventsDisabled.delete(f),Rj())},[f,m]),d.useEffect(()=>{const P=Rn(()=>g({}),"handleUpdate");return document.addEventListener(Tj,P),()=>document.removeEventListener(Tj,P)},[]),t.jsx(_t.div,{...h,ref:w,style:{pointerEvents:N?b?"auto":"none":void 0,...n.style},onFocusCapture:Ge(n.onFocusCapture,A.onFocusCapture),onBlurCapture:Ge(n.onBlurCapture,A.onBlurCapture),onPointerDownCapture:Ge(n.onPointerDownCapture,C.onPointerDownCapture)})},"DismissableLayer")),F4=d.forwardRef(Rn(function(n,s){const r=d.useContext(Aw),a=d.useRef(null),i=Ht(s,a);return d.useEffect(()=>{const l=a.current;if(l)return r.branches.add(l),()=>{r.branches.delete(l)}},[r.branches]),t.jsx(_t.div,{...n,ref:i})},"DismissableLayerBranch"));function ET(){const e=d.useContext(Aw),[n,s]=d.useState(null);return d.useEffect(()=>{if(n)return e.dismissableSurfaces.add(n),()=>{e.dismissableSurfaces.delete(n)}},[n,e.dismissableSurfaces]),s}Rn(ET,"useDismissableLayerSurface");var _4=Rn(()=>!0,"IS_TRUE");function AT(e,n){const{ownerDocument:s=globalThis==null?void 0:globalThis.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:a,dismissableSurfaces:i,shouldHandlePointerDownOutside:l=_4}=n,o=fs(e),c=d.useRef(!1),u=d.useRef(!1),h=d.useRef(new Map),m=d.useRef(()=>{});return d.useEffect(()=>{function f(){u.current=!1,a.current=!1,h.current.clear()}Rn(f,"resetOutsideInteraction");function p(){return Array.from(h.current.values()).some(Boolean)}Rn(p,"isOutsideInteractionIntercepted");function x(y){if(!u.current)return;const k=y.target;k instanceof Node&&[...i].some(b=>b.contains(k))||h.current.set(y.type,!0),y.type==="click"&&window.setTimeout(()=>{u.current&&m.current()},0)}Rn(x,"handleInteractionCapture");function g(y){u.current&&h.current.set(y.type,!1)}Rn(g,"handleInteractionBubble");const w=Rn(y=>{if(y.target&&!c.current){let k=function(){s.removeEventListener("click",m.current);const b=p();f(),b||$w(D4,o,N,{discrete:!0})};if(Rn(k,"handleAndDispatchPointerDownOutsideEvent"),!l(y.target)){s.removeEventListener("click",m.current),f(),c.current=!1;return}const N={originalEvent:y};u.current=!0,a.current=r&&y.button===0,h.current.clear(),!r||y.button!==0?k():(s.removeEventListener("click",m.current),m.current=k,s.addEventListener("click",m.current,{once:!0}))}else s.removeEventListener("click",m.current),f();c.current=!1},"handlePointerDown"),v=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const y of v)s.addEventListener(y,x,!0),s.addEventListener(y,g);const j=window.setTimeout(()=>{s.addEventListener("pointerdown",w)},0);return()=>{window.clearTimeout(j),s.removeEventListener("pointerdown",w),s.removeEventListener("click",m.current);for(const y of v)s.removeEventListener(y,x,!0),s.removeEventListener(y,g)}},[s,o,r,a,i,l]),{onPointerDownCapture:Rn(()=>c.current=!0,"onPointerDownCapture")}}Rn(AT,"usePointerDownOutside");function $T(e,n=globalThis==null?void 0:globalThis.document){const s=fs(e),r=d.useRef(!1);return d.useEffect(()=>{const a=Rn(i=>{i.target&&!r.current&&$w(L4,s,{originalEvent:i},{discrete:!1})},"handleFocus");return n.addEventListener("focusin",a),()=>n.removeEventListener("focusin",a)},[n,s]),{onFocusCapture:Rn(()=>r.current=!0,"onFocusCapture"),onBlurCapture:Rn(()=>r.current=!1,"onBlurCapture")}}Rn($T,"useFocusOutside");function Rj(){const e=new CustomEvent(Tj);document.dispatchEvent(e)}Rn(Rj,"dispatchUpdate");function $w(e,n,s,{discrete:r}){const a=s.originalEvent.target,i=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:s});n&&a.addEventListener(e,n,{once:!0}),r?Dm(a,i):a.dispatchEvent(i)}Rn($w,"handleAndDispatchCustomEvent");var z4=Lm,U4=F4,As=globalThis!=null&&globalThis.document?d.useLayoutEffect:()=>{},B4=Object.defineProperty,W4=(e,n)=>B4(e,"name",{value:n,configurable:!0}),Fm=d.forwardRef(W4(function(n,s){var c;const{container:r,...a}=n,[i,l]=d.useState(!1);As(()=>l(!0),[]);const o=r||i&&((c=globalThis==null?void 0:globalThis.document)==null?void 0:c.body);return o?qo.createPortal(t.jsx(_t.div,{...a,ref:s}),o):null},"Portal")),H4=Object.defineProperty,Ma=(e,n)=>H4(e,"name",{value:n,configurable:!0});function TT(e,n){return d.useReducer((s,r)=>n[s][r]??s,e)}Ma(TT,"useStateMachine");var ca=Ma(e=>{const{present:n,children:s}=e,r=RT(n),a=typeof s=="function"?s({present:r.isPresent}):d.Children.only(s),i=IT(r.ref,PT(a));return typeof s=="function"||r.isPresent?d.cloneElement(a,{ref:i}):null},"Presence");function RT(e){const[n,s]=d.useState(),r=d.useRef(null),a=d.useRef(e),i=d.useRef("none"),l=d.useRef(void 0),o=e?"mounted":"unmounted",[c,u]=TT(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return d.useEffect(()=>{c==="mounted"?(i.current=l.current??Kl(r.current),l.current=void 0):i.current="none"},[c]),As(()=>{const h=r.current,m=a.current;if(m!==e){const p=i.current,x=Kl(h);e?(l.current=x,u("MOUNT")):x==="none"||(h==null?void 0:h.display)==="none"?u("UNMOUNT"):u(m&&p!==x?"ANIMATION_OUT":"UNMOUNT"),a.current=e}},[e,u]),As(()=>{if(n){let h;const m=n.ownerDocument.defaultView??window,f=Ma(x=>{const w=Kl(r.current).includes(CSS.escape(x.animationName));if(x.target===n&&w&&(u("ANIMATION_END"),!a.current)){const v=n.style.animationFillMode;n.style.animationFillMode="forwards",h=m.setTimeout(()=>{n.style.animationFillMode==="forwards"&&(n.style.animationFillMode=v)})}},"handleAnimationEnd"),p=Ma(x=>{x.target===n&&(i.current=Kl(r.current))},"handleAnimationStart");return n.addEventListener("animationstart",p),n.addEventListener("animationcancel",f),n.addEventListener("animationend",f),()=>{m.clearTimeout(h),n.removeEventListener("animationstart",p),n.removeEventListener("animationcancel",f),n.removeEventListener("animationend",f)}}else u("ANIMATION_END")},[n,u]),{isPresent:["mounted","unmountSuspended"].includes(c),ref:d.useCallback(h=>{if(h){const m=getComputedStyle(h);r.current=m,l.current=Kl(m)}else r.current=null;s(h)},[])}}Ma(RT,"usePresence");function Ij(e,n){if(typeof e=="function")return e(n);e!=null&&(e.current=n)}Ma(Ij,"setRef");function IT(...e){const n=d.useRef(e);return n.current=e,d.useCallback(s=>{const r=n.current;let a=!1;const i=r.map(l=>{const o=Ij(l,s);return!a&&typeof o=="function"&&(a=!0),o});if(a)return()=>{for(let l=0;l<i.length;l++){const o=i[l];typeof o=="function"?o():Ij(r[l],null)}}},[])}Ma(IT,"useStableComposedRefs");function Kl(e){return(e==null?void 0:e.animationName)||"none"}Ma(Kl,"getAnimationName");function PT(e){var r,a;let n=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,s=n&&"isReactWarning"in n&&n.isReactWarning;return s?e.ref:(n=(a=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:a.get,s=n&&"isReactWarning"in n&&n.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}Ma(PT,"getElementRef");var K4=Object.defineProperty,V4=(e,n)=>K4(e,"name",{value:n,configurable:!0}),KN=Ko[" useEffectEvent ".trim().toString()],VN=Ko[" useInsertionEffect ".trim().toString()];function MT(e){if(typeof KN=="function")return KN(e);const n=d.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof VN=="function"?VN(()=>{n.current=e}):As(()=>{n.current=e}),d.useMemo(()=>(...s)=>{var r;return(r=n.current)==null?void 0:r.call(n,...s)},[])}V4(MT,"useEffectEvent");var G4=Object.defineProperty,cd=(e,n)=>G4(e,"name",{value:n,configurable:!0}),q4=Ko[" useInsertionEffect ".trim().toString()]||As;function Ei({prop:e,defaultProp:n,onChange:s=cd(()=>{},"onChange"),caller:r}){const[a,i,l]=OT({defaultProp:n,onChange:s}),o=e!==void 0,c=o?e:a,u=d.useCallback(h=>{var m;if(o){const f=DT(h)?h(e):h;f!==e&&((m=l.current)==null||m.call(l,f))}else i(h)},[o,e,i,l]);return[c,u]}cd(Ei,"useControllableState");function OT({defaultProp:e,onChange:n}){const[s,r]=d.useState(e),a=d.useRef(s),i=d.useRef(n);return q4(()=>{i.current=n},[n]),d.useEffect(()=>{var l;a.current!==s&&((l=i.current)==null||l.call(i,s),a.current=s)},[s,a]),[s,r,i]}cd(OT,"useUncontrolledState");function DT(e){return typeof e=="function"}cd(DT,"isFunction");var GN=Symbol("RADIX:SYNC_STATE");function Y4(e,n,s,r){const{prop:a,defaultProp:i,onChange:l,caller:o}=n,c=a!==void 0,u=MT(l),h=[{...s,state:i}];r&&h.push(r);const[m,f]=d.useReducer((w,v)=>{if(v.type===GN)return{...w,state:v.state};const j=e(w,v);return c&&!Object.is(j.state,w.state)&&u(j.state),j},...h),p=m.state,x=d.useRef(p);d.useEffect(()=>{x.current!==p&&(x.current=p,c||u(p))},[p,x,c]);const g=d.useMemo(()=>a!==void 0?{...m,state:a}:m,[m,a]);return d.useEffect(()=>{c&&!Object.is(a,m.state)&&f({type:GN,state:a})},[a,m.state,c]),[g,f]}cd(Y4,"useControllableStateReducer");var Q4=Object.defineProperty,J4=(e,n)=>Q4(e,"name",{value:n,configurable:!0}),X4=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"}),Tw=d.forwardRef(J4(function(n,s){return t.jsx(_t.span,{...n,ref:s,style:{...X4,...n.style}})},"VisuallyHidden")),Z4=Tw,ez=Object.defineProperty,Wt=(e,n)=>ez(e,"name",{value:n,configurable:!0}),LT="ToastProvider",[Rw,FT,tz]=Om("Toast"),[_T,fue]=zr("Toast",[tz]),[nz,_m]=_T(LT),sz=Wt(e=>{const{__scopeToast:n,label:s="Notification",duration:r=5e3,swipeDirection:a="right",swipeThreshold:i=50,announcerContainer:l,children:o}=e,[c,u]=d.useState(null),[h,m]=d.useState(0),f=d.useRef(!1);return s.trim()||console.error(`Invalid prop \`label\` supplied to \`${LT}\`. Expected non-empty \`string\`.`),t.jsx(Rw.Provider,{scope:n,children:t.jsx(nz,{scope:n,label:s,duration:r,swipeDirection:a,swipeThreshold:i,toastCount:h,viewport:c,onViewportChange:u,onToastAdd:d.useCallback(()=>m(p=>p+1),[]),onToastRemove:d.useCallback(()=>m(p=>p-1),[]),isClosePausedRef:f,announcerContainer:l,children:o})})},"ToastProvider"),rz="ToastViewport",az=["F8"],Pj="toast.viewportPause",Mj="toast.viewportResume",iz=d.forwardRef(Wt(function(n,s){const{__scopeToast:r,hotkey:a=az,label:i="Notifications ({hotkey})",...l}=n,o=_m(rz,r),c=FT(r),u=d.useRef(null),h=d.useRef(null),m=d.useRef(null),f=d.useRef(null),p=Ht(s,f,o.onViewportChange),x=a.join("+").replace(/Key/g,"").replace(/Digit/g,""),g=o.toastCount>0;d.useEffect(()=>{const v=Wt(j=>{var k;a.length!==0&&a.every(N=>j[N]||j.code===N)&&((k=f.current)==null||k.focus())},"handleKeyDown");return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[a]),d.useEffect(()=>{const v=u.current,j=f.current;if(g&&v&&j){const y=Wt(()=>{if(!o.isClosePausedRef.current){const S=new CustomEvent(Pj);j.dispatchEvent(S),o.isClosePausedRef.current=!0}},"handlePause"),k=Wt(()=>{if(o.isClosePausedRef.current){const S=new CustomEvent(Mj);j.dispatchEvent(S),o.isClosePausedRef.current=!1}},"handleResume"),N=Wt(S=>{!v.contains(S.relatedTarget)&&k()},"handleFocusOutResume"),b=Wt(()=>{v.contains(document.activeElement)||k()},"handlePointerLeaveResume");return v.addEventListener("focusin",y),v.addEventListener("focusout",N),v.addEventListener("pointermove",y),v.addEventListener("pointerleave",b),window.addEventListener("blur",y),window.addEventListener("focus",k),()=>{v.removeEventListener("focusin",y),v.removeEventListener("focusout",N),v.removeEventListener("pointermove",y),v.removeEventListener("pointerleave",b),window.removeEventListener("blur",y),window.removeEventListener("focus",k)}}},[g,o.isClosePausedRef]);const w=d.useCallback(({tabbingDirection:v})=>{const y=c().map(k=>{const N=k.ref.current,b=[N,...WT(N)];return v==="forwards"?b:b.reverse()});return(v==="forwards"?y.reverse():y).flat()},[c]);return d.useEffect(()=>{const v=f.current;if(v){const j=Wt(y=>{var b,S,C;const k=y.altKey||y.ctrlKey||y.metaKey;if(y.key==="Tab"&&!k){const A=document.activeElement,E=y.shiftKey;if(y.target===v&&E){(b=h.current)==null||b.focus();return}const O=w({tabbingDirection:E?"backwards":"forwards"}),I=O.findIndex(F=>F===A);Wh(O.slice(I+1))?y.preventDefault():E?(S=h.current)==null||S.focus():(C=m.current)==null||C.focus()}},"handleKeyDown");return v.addEventListener("keydown",j),()=>v.removeEventListener("keydown",j)}},[c,w]),t.jsxs(U4,{ref:u,role:"region","aria-label":i.replace("{hotkey}",x),tabIndex:-1,style:{pointerEvents:g?void 0:"none"},children:[g&&t.jsx(qN,{ref:h,onFocusFromOutsideViewport:()=>{const v=w({tabbingDirection:"forwards"});Wh(v)}}),t.jsx(Rw.Slot,{scope:r,children:t.jsx(_t.ol,{tabIndex:-1,...l,ref:p})}),g&&t.jsx(qN,{ref:m,onFocusFromOutsideViewport:()=>{const v=w({tabbingDirection:"backwards"});Wh(v)}})]})},"ToastViewport")),lz="ToastFocusProxy",qN=d.forwardRef(Wt(function(n,s){const{__scopeToast:r,onFocusFromOutsideViewport:a,...i}=n,l=_m(lz,r);return t.jsx(Tw,{tabIndex:0,...i,ref:s,style:{position:"fixed"},onFocus:o=>{var h;const c=o.relatedTarget;!((h=l.viewport)!=null&&h.contains(c))&&a()}})},"ToastFocusProxy")),zm="Toast",oz="toast.swipeStart",cz="toast.swipeMove",uz="toast.swipeCancel",dz="toast.swipeEnd",hz=d.forwardRef(Wt(function(n,s){const{forceMount:r,open:a,defaultOpen:i,onOpenChange:l,...o}=n,[c,u]=Ei({prop:a,defaultProp:i??!0,onChange:l,caller:zm});return t.jsx(ca,{present:r||c,children:t.jsx(pz,{open:c,...o,ref:s,onClose:()=>u(!1),onPause:fs(n.onPause),onResume:fs(n.onResume),onSwipeStart:Ge(n.onSwipeStart,h=>{h.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:Ge(n.onSwipeMove,h=>{const{x:m,y:f}=h.detail.delta;h.currentTarget.setAttribute("data-swipe","move"),h.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${m}px`),h.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${f}px`)}),onSwipeCancel:Ge(n.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:Ge(n.onSwipeEnd,h=>{const{x:m,y:f}=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",`${m}px`),h.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${f}px`),u(!1)})})})},"Toast")),[fz,mz]=_T(zm,{onClose(){}}),pz=d.forwardRef(Wt(function(n,s){const{__scopeToast:r,type:a="foreground",duration:i,open:l,onClose:o,onEscapeKeyDown:c,onPause:u,onResume:h,onSwipeStart:m,onSwipeMove:f,onSwipeCancel:p,onSwipeEnd:x,...g}=n,w=_m(zm,r),v=FT(r),[j,y]=d.useState(null),k=Ht(s,y),N=d.useRef(null),b=d.useRef(null),S=i||w.duration,C=d.useRef(0),A=d.useRef(S),E=d.useRef(0),{onToastAdd:R,onToastRemove:P}=w,O=fs(()=>{var L;(j==null?void 0:j.contains(document.activeElement))&&((L=w.viewport)==null||L.focus()),o()}),I=d.useCallback(U=>{!U||U===1/0||(window.clearTimeout(E.current),C.current=new Date().getTime(),E.current=window.setTimeout(O,U))},[O]);d.useEffect(()=>{const U=w.viewport;if(U){const L=Wt(()=>{I(A.current),h==null||h()},"handleResume"),M=Wt(()=>{const z=new Date().getTime()-C.current;A.current=A.current-z,window.clearTimeout(E.current),u==null||u()},"handlePause");return U.addEventListener(Pj,M),U.addEventListener(Mj,L),()=>{U.removeEventListener(Pj,M),U.removeEventListener(Mj,L)}}},[w.viewport,S,u,h,I]),d.useEffect(()=>{l&&!w.isClosePausedRef.current&&I(S)},[l,S,w.isClosePausedRef,I]),d.useEffect(()=>()=>{window.clearTimeout(E.current)},[]),d.useEffect(()=>(R(),()=>P()),[R,P]);const F=d.useMemo(()=>j?Iw(j):null,[j]);return w.viewport?t.jsxs(t.Fragment,{children:[F&&t.jsx(gz,{__scopeToast:r,role:"status","aria-live":a==="foreground"?"assertive":"polite",children:F}),t.jsx(fz,{scope:r,onClose:O,children:qo.createPortal(t.jsx(Rw.ItemSlot,{scope:r,children:t.jsx(z4,{asChild:!0,onEscapeKeyDown:Ge(c,U=>{v().some(M=>{var z;return(z=M.ref.current)==null?void 0:z.contains(U.target)})||O()}),children:t.jsx(_t.li,{tabIndex:0,"data-state":l?"open":"closed","data-swipe-direction":w.swipeDirection,...g,ref:k,style:{userSelect:"none",touchAction:"none",...n.style},onKeyDown:Ge(n.onKeyDown,U=>{U.key==="Escape"&&(c==null||c(U.nativeEvent),U.nativeEvent.defaultPrevented||O())}),onPointerDown:Ge(n.onPointerDown,U=>{U.button===0&&(N.current={x:U.clientX,y:U.clientY})}),onPointerMove:Ge(n.onPointerMove,U=>{if(!N.current)return;const L=U.clientX-N.current.x,M=U.clientY-N.current.y,z=!!b.current,D=["left","right"].includes(w.swipeDirection),K=["left","up"].includes(w.swipeDirection)?Math.min:Math.max,B=D?K(0,L):0,se=D?0:K(0,M),W=U.pointerType==="touch"?10:2,xe={x:B,y:se},me={originalEvent:U,delta:xe};z?(b.current=xe,Fc(cz,f,me,{discrete:!1})):YN(xe,w.swipeDirection,W)?(b.current=xe,Fc(oz,m,me,{discrete:!1}),U.target.setPointerCapture(U.pointerId)):(Math.abs(L)>W||Math.abs(M)>W)&&(N.current=null)}),onPointerUp:Ge(n.onPointerUp,U=>{const L=b.current,M=U.target;if(M.hasPointerCapture(U.pointerId)&&M.releasePointerCapture(U.pointerId),b.current=null,N.current=null,L){const z=U.currentTarget,D={originalEvent:U,delta:L};YN(L,w.swipeDirection,w.swipeThreshold)?Fc(dz,x,D,{discrete:!0}):Fc(uz,p,D,{discrete:!0}),z.addEventListener("click",K=>K.preventDefault(),{once:!0})}})})})}),w.viewport)})]}):null},"ToastImpl")),gz=Wt(e=>{const{__scopeToast:n,children:s,...r}=e,a=_m(zm,n),[i,l]=d.useState(!1),[o,c]=d.useState(!1);return UT(()=>l(!0)),d.useEffect(()=>{const u=window.setTimeout(()=>c(!0),1e3);return()=>window.clearTimeout(u)},[]),o?null:t.jsx(Fm,{asChild:!0,container:a.announcerContainer||void 0,children:t.jsx(Tw,{...r,children:i&&t.jsxs(t.Fragment,{children:[a.label," ",s]})})})},"ToastAnnounce"),xz=d.forwardRef(Wt(function(n,s){const{__scopeToast:r,...a}=n;return t.jsx(_t.div,{...a,ref:s})},"ToastTitle")),jz=d.forwardRef(Wt(function(n,s){const{__scopeToast:r,...a}=n;return t.jsx(_t.div,{...a,ref:s})},"ToastDescription")),vz="ToastAction",yz=d.forwardRef(Wt(function(n,s){const{altText:r,...a}=n;return r.trim()?t.jsx(zT,{altText:r,asChild:!0,children:t.jsx(bz,{...a,ref:s})}):(console.error(`Invalid prop \`altText\` supplied to \`${vz}\`. Expected non-empty \`string\`.`),null)},"ToastAction")),wz="ToastClose",bz=d.forwardRef(Wt(function(n,s){const{__scopeToast:r,...a}=n,i=mz(wz,r);return t.jsx(zT,{asChild:!0,children:t.jsx(_t.button,{type:"button",...a,ref:s,onClick:Ge(n.onClick,i.onClose)})})},"ToastClose")),zT=d.forwardRef(Wt(function(n,s){const{__scopeToast:r,altText:a,...i}=n;return t.jsx(_t.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":a||void 0,...i,ref:s})},"ToastAnnounceExclude"));function Iw(e){const n=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&n.push(r.textContent),BT(r)){const a=r.ariaHidden||r.hidden||r.style.display==="none",i=r.dataset.radixToastAnnounceExclude==="";if(!a)if(i){const l=r.dataset.radixToastAnnounceAlt;l&&n.push(l)}else n.push(...Iw(r))}}),n}Wt(Iw,"getAnnounceTextContent");function Fc(e,n,s,{discrete:r}){const a=s.originalEvent.currentTarget,i=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:s});n&&a.addEventListener(e,n,{once:!0}),r?Dm(a,i):a.dispatchEvent(i)}Wt(Fc,"handleAndDispatchCustomEvent");var YN=Wt((e,n,s=0)=>{const r=Math.abs(e.x),a=Math.abs(e.y),i=r>a;return n==="left"||n==="right"?i&&r>s:!i&&a>s},"isDeltaInDirection");function UT(e=()=>{}){const n=fs(e);As(()=>{let s=0,r=0;return s=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(n)),()=>{window.cancelAnimationFrame(s),window.cancelAnimationFrame(r)}},[n])}Wt(UT,"useNextFrame");function BT(e){return e.nodeType===e.ELEMENT_NODE}Wt(BT,"isHTMLElement");function WT(e){const n=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:Wt(r=>{const a=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||a?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;s.nextNode();)n.push(s.currentNode);return n}Wt(WT,"getTabbableCandidates");function Wh(e){const n=document.activeElement;return e.some(s=>s===n?!0:(s.focus(),document.activeElement!==n))}Wt(Wh,"focusFirst");var QN=sz,JN=iz,kz=hz,Nz=xz,Sz=jz,Cz=yz,Ez=Object.defineProperty,Az=(e,n)=>Ez(e,"name",{value:n,configurable:!0}),$z=Ko[" useId ".trim().toString()]||(()=>{}),Tz=0;function Tr(e){const[n,s]=d.useState($z());return As(()=>{e||s(r=>r??String(Tz++))},[e]),e||(n?`radix-${n}`:"")}Az(Tr,"useId");const Rz=["top","right","bottom","left"],xi=Math.min,Ca=Math.max,Pf=Math.round,th=Math.floor,Ea=e=>({x:e,y:e}),Iz={left:"right",right:"left",bottom:"top",top:"bottom"};function HT(e,n,s){return Ca(e,xi(n,s))}function Oa(e,n){return typeof e=="function"?e(n):e}function ji(e){return e.split("-")[0]}function Qo(e){return e.split("-")[1]}function Pw(e){return e==="x"?"y":"x"}function Mw(e){return e==="y"?"height":"width"}function Jr(e){const n=e[0];return n==="t"||n==="b"?"y":"x"}function Ow(e){return Pw(Jr(e))}function Pz(e,n,s){s===void 0&&(s=!1);const r=Qo(e),a=Ow(e),i=Mw(a);let l=a==="x"?r===(s?"end":"start")?"right":"left":r==="start"?"bottom":"top";return n.reference[i]>n.floating[i]&&(l=Mf(l)),[l,Mf(l)]}function Mz(e){const n=Mf(e);return[Oj(e),n,Oj(n)]}function Oj(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const XN=["left","right"],ZN=["right","left"],Oz=["top","bottom"],Dz=["bottom","top"];function Lz(e,n,s){switch(e){case"top":case"bottom":return s?n?ZN:XN:n?XN:ZN;case"left":case"right":return n?Oz:Dz;default:return[]}}function Fz(e,n,s,r){const a=Qo(e);let i=Lz(ji(e),s==="start",r);return a&&(i=i.map(l=>l+"-"+a),n&&(i=i.concat(i.map(Oj)))),i}function Mf(e){const n=ji(e);return Iz[n]+e.slice(n.length)}function _z(e){var n,s,r,a;return{top:(n=e.top)!=null?n:0,right:(s=e.right)!=null?s:0,bottom:(r=e.bottom)!=null?r:0,left:(a=e.left)!=null?a:0}}function KT(e){return typeof e!="number"?_z(e):{top:e,right:e,bottom:e,left:e}}function Of(e){const{x:n,y:s,width:r,height:a}=e;return{width:r,height:a,top:s,left:n,right:n+r,bottom:s+a,x:n,y:s}}function eS(e,n,s){let{reference:r,floating:a}=e;const i=Jr(n),l=Ow(n),o=Mw(l),c=ji(n),u=i==="y",h=r.x+r.width/2-a.width/2,m=r.y+r.height/2-a.height/2,f=r[o]/2-a[o]/2;let p;switch(c){case"top":p={x:h,y:r.y-a.height};break;case"bottom":p={x:h,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:m};break;case"left":p={x:r.x-a.width,y:m};break;default:p={x:r.x,y:r.y}}const x=Qo(n);return x&&(p[l]+=f*(x==="end"?1:-1)*(s&&u?-1:1)),p}async function zz(e,n){var s;n===void 0&&(n={});const{x:r,y:a,platform:i,rects:l,elements:o,strategy:c}=e,{boundary:u="clippingAncestors",rootBoundary:h="viewport",elementContext:m="floating",altBoundary:f=!1,padding:p=0}=Oa(n,e),x=KT(p),w=o[f?m==="floating"?"reference":"floating":m],v=Of(await i.getClippingRect({element:(s=await(i.isElement==null?void 0:i.isElement(w)))==null||s?w:w.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:u,rootBoundary:h,strategy:c})),j=m==="floating"?{x:r,y:a,width:l.floating.width,height:l.floating.height}:l.reference,y=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),k=await(i.isElement==null?void 0:i.isElement(y))&&await(i.getScale==null?void 0:i.getScale(y))||{x:1,y:1},N=Of(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:j,offsetParent:y,strategy:c}):j);return{top:(v.top-N.top+x.top)/k.y,bottom:(N.bottom-v.bottom+x.bottom)/k.y,left:(v.left-N.left+x.left)/k.x,right:(N.right-v.right+x.right)/k.x}}const Uz=50,Bz=async(e,n,s)=>{const{placement:r="bottom",strategy:a="absolute",middleware:i=[],platform:l}=s,o=l.detectOverflow?l:{...l,detectOverflow:zz},c=await(l.isRTL==null?void 0:l.isRTL(n));let u=await l.getElementRects({reference:e,floating:n,strategy:a}),{x:h,y:m}=eS(u,r,c),f=r,p=0;const x={};for(let g=0;g<i.length;g++){const w=i[g];if(!w)continue;const{name:v,fn:j}=w,{x:y,y:k,data:N,reset:b}=await j({x:h,y:m,initialPlacement:r,placement:f,strategy:a,middlewareData:x,rects:u,platform:o,elements:{reference:e,floating:n}});h=y??h,m=k??m,x[v]={...x[v],...N},b&&p<Uz&&(p++,typeof b=="object"&&(b.placement&&(f=b.placement),b.rects&&(u=b.rects===!0?await l.getElementRects({reference:e,floating:n,strategy:a}):b.rects),{x:h,y:m}=eS(u,f,c)),g=-1)}return{x:h,y:m,placement:f,strategy:a,middlewareData:x}},Wz=e=>({name:"arrow",options:e,async fn(n){const{x:s,y:r,placement:a,rects:i,platform:l,elements:o,middlewareData:c}=n,{element:u,padding:h=0}=Oa(e,n)||{};if(u==null)return{};const m=KT(h),f={x:s,y:r},p=Ow(a),x=Mw(p),g=await l.getDimensions(u),w=p==="y",v=w?"top":"left",j=w?"bottom":"right",y=w?"clientHeight":"clientWidth",k=i.reference[x]+i.reference[p]-f[p]-i.floating[x],N=f[p]-i.reference[p],b=await(l.getOffsetParent==null?void 0:l.getOffsetParent(u));let S=b?b[y]:0;(!S||!await(l.isElement==null?void 0:l.isElement(b)))&&(S=o.floating[y]||i.floating[x]);const C=k/2-N/2,A=S/2-g[x]/2-1,E=xi(m[v],A),R=xi(m[j],A),P=S-g[x]-R,O=S/2-g[x]/2+C,I=HT(E,O,P),F=!c.arrow&&Qo(a)!=null&&O!==I&&i.reference[x]/2-(O<E?E:R)-g[x]/2<0,U=F?O<E?O-E:O-P:0;return{[p]:f[p]+U,data:{[p]:I,centerOffset:O-I-U,...F&&{alignmentOffset:U}},reset:F}}}),Hz=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(n){var s,r;const{placement:a,middlewareData:i,rects:l,initialPlacement:o,platform:c,elements:u}=n,{mainAxis:h=!0,crossAxis:m=!0,fallbackPlacements:f,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:x="none",flipAlignment:g=!0,...w}=Oa(e,n);if((s=i.arrow)!=null&&s.alignmentOffset)return{};const v=ji(a),j=Jr(o),y=ji(o)===o,k=await(c.isRTL==null?void 0:c.isRTL(u.floating)),N=f||(y||!g?[Mf(o)]:Mz(o)),b=x!=="none";!f&&b&&N.push(...Fz(o,g,x,k));const S=[o,...N],C=await c.detectOverflow(n,w),A=[];let E=((r=i.flip)==null?void 0:r.overflows)||[];if(h&&A.push(C[v]),m){const I=Pz(a,l,k);A.push(C[I[0]],C[I[1]])}if(E=[...E,{placement:a,overflows:A}],!A.every(I=>I<=0)){var R,P;const I=(((R=i.flip)==null?void 0:R.index)||0)+1,F=S[I];if(F&&(!(m==="alignment"?j!==Jr(F):!1)||E.every(M=>Jr(M.placement)===j?M.overflows[0]>0:!0)))return{data:{index:I,overflows:E},reset:{placement:F}};let U=(P=E.filter(L=>L.overflows[0]<=0).sort((L,M)=>L.overflows[1]-M.overflows[1])[0])==null?void 0:P.placement;if(!U)switch(p){case"bestFit":{var O;const L=(O=E.filter(M=>{if(b){const z=Jr(M.placement);return z===j||z==="y"}return!0}).map(M=>[M.placement,M.overflows.filter(z=>z>0).reduce((z,D)=>z+D,0)]).sort((M,z)=>M[1]-z[1])[0])==null?void 0:O[0];L&&(U=L);break}case"initialPlacement":U=o;break}if(a!==U)return{reset:{placement:U}}}return{}}}};function tS(e,n){return{top:e.top-n.height,right:e.right-n.width,bottom:e.bottom-n.height,left:e.left-n.width}}function nS(e){return Rz.some(n=>e[n]>=0)}const Kz=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(n){const{rects:s,platform:r}=n,{strategy:a="referenceHidden",...i}=Oa(e,n);switch(a){case"referenceHidden":{const l=await r.detectOverflow(n,{...i,elementContext:"reference"}),o=tS(l,s.reference);return{data:{referenceHiddenOffsets:o,referenceHidden:nS(o)}}}case"escaped":{const l=await r.detectOverflow(n,{...i,altBoundary:!0}),o=tS(l,s.floating);return{data:{escapedOffsets:o,escaped:nS(o)}}}default:return{}}}}},VT=new Set(["left","top"]);async function Vz(e,n){const{placement:s,platform:r,elements:a}=e,i=await(r.isRTL==null?void 0:r.isRTL(a.floating)),l=ji(s),o=Qo(s),c=Jr(s)==="y",u=VT.has(l)?-1:1,h=i&&c?-1:1,m=Oa(n,e);let{mainAxis:f,crossAxis:p,alignmentAxis:x}=typeof m=="number"?{mainAxis:m,crossAxis:0,alignmentAxis:null}:{mainAxis:m.mainAxis||0,crossAxis:m.crossAxis||0,alignmentAxis:m.alignmentAxis};return o&&typeof x=="number"&&(p=o==="end"?x*-1:x),c?{x:p*h,y:f*u}:{x:f*u,y:p*h}}const Gz=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(n){var s,r;const{x:a,y:i,placement:l,middlewareData:o}=n,c=await Vz(n,e);return l===((s=o.offset)==null?void 0:s.placement)&&(r=o.arrow)!=null&&r.alignmentOffset?{}:{x:a+c.x,y:i+c.y,data:{...c,placement:l}}}}},qz=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(n){const{x:s,y:r,placement:a,platform:i}=n,{mainAxis:l=!0,crossAxis:o=!1,limiter:c={fn:j=>{let{x:y,y:k}=j;return{x:y,y:k}}},...u}=Oa(e,n),h={x:s,y:r},m=await i.detectOverflow(n,u),f=Jr(a),p=Pw(f);let x=h[p],g=h[f];const w=(j,y)=>HT(y+m[j==="y"?"top":"left"],y,y-m[j==="y"?"bottom":"right"]);l&&(x=w(p,x)),o&&(g=w(f,g));const v=c.fn({...n,[p]:x,[f]:g});return{...v,data:{x:v.x-s,y:v.y-r,enabled:{[p]:l,[f]:o}}}}}},Yz=function(e){return e===void 0&&(e={}),{options:e,fn(n){var s,r;const{x:a,y:i,placement:l,rects:o,middlewareData:c}=n,{offset:u=0,mainAxis:h=!0,crossAxis:m=!0}=Oa(e,n),f={x:a,y:i},p=Jr(l),x=Pw(p);let g=f[x],w=f[p];const v=Oa(u,n),j=typeof v=="number"?{mainAxis:v,crossAxis:0}:{mainAxis:(s=v.mainAxis)!=null?s:0,crossAxis:(r=v.crossAxis)!=null?r:0};if(h){const N=x==="y"?"height":"width",b=o.reference[x]-o.floating[N]+j.mainAxis,S=o.reference[x]+o.reference[N]-j.mainAxis;g<b?g=b:g>S&&(g=S)}if(m){var y,k;const N=x==="y"?"width":"height",b=VT.has(ji(l)),S=o.reference[p]-o.floating[N]+(b&&((y=c.offset)==null?void 0:y[p])||0)+(b?0:j.crossAxis),C=o.reference[p]+o.reference[N]+(b?0:((k=c.offset)==null?void 0:k[p])||0)-(b?j.crossAxis:0);w<S?w=S:w>C&&(w=C)}return{[x]:g,[p]:w}}}},Qz=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(n){const{placement:s,rects:r,platform:a,elements:i}=n,{apply:l=()=>{},...o}=Oa(e,n),c=await a.detectOverflow(n,o),u=ji(s),h=Qo(s),m=Jr(s)==="y",{width:f,height:p}=r.floating;let x,g;u==="top"||u==="bottom"?(x=u,g=h===(await(a.isRTL==null?void 0:a.isRTL(i.floating))?"start":"end")?"left":"right"):(g=u,x=h==="end"?"top":"bottom");const w=p-c.top-c.bottom,v=f-c.left-c.right,j=xi(p-c[x],w),y=xi(f-c[g],v),k=n.middlewareData.shift,N=!k;let b=j,S=y;k!=null&&k.enabled.x&&(S=v),k!=null&&k.enabled.y&&(b=w),N&&!h&&(m?S=f-2*Ca(c.left,c.right):b=p-2*Ca(c.top,c.bottom)),await l({...n,availableWidth:S,availableHeight:b});const C=await a.getDimensions(i.floating);return f!==C.width||p!==C.height?{reset:{rects:!0}}:{}}}};function Um(){return typeof window<"u"}function Jo(e){return GT(e)?(e.nodeName||"").toLowerCase():"#document"}function $s(e){var n;return(e==null||(n=e.ownerDocument)==null?void 0:n.defaultView)||window}function _a(e){var n;return(n=(GT(e)?e.ownerDocument:e.document)||window.document)==null?void 0:n.documentElement}function GT(e){return Um()?e instanceof Node||e instanceof $s(e).Node:!1}function aa(e){return Um()?e instanceof Element||e instanceof $s(e).Element:!1}function Ai(e){return Um()?e instanceof HTMLElement||e instanceof $s(e).HTMLElement:!1}function sS(e){return!Um()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof $s(e).ShadowRoot}function Bm(e){const{overflow:n,overflowX:s,overflowY:r,display:a}=ia(e);return/auto|scroll|overlay|hidden|clip/.test(n+r+s)&&a!=="inline"&&a!=="contents"}function Jz(e){return/^(table|td|th)$/.test(Jo(e))}function Wm(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const Xz=/transform|translate|scale|rotate|perspective|filter/,Zz=/paint|layout|strict|content/,Fi=e=>!!e&&e!=="none";let xg;function Dw(e){const n=aa(e)?ia(e):e;return Fi(n.transform)||Fi(n.translate)||Fi(n.scale)||Fi(n.rotate)||Fi(n.perspective)||!Lw()&&(Fi(n.backdropFilter)||Fi(n.filter))||Xz.test(n.willChange||"")||Zz.test(n.contain||"")}function e3(e){let n=ul(e);for(;Ai(n)&&!Su(n);){if(Dw(n))return n;if(Wm(n))return null;n=ul(n)}return null}function Lw(){return xg==null&&(xg=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),xg}function Su(e){return/^(html|body|#document)$/.test(Jo(e))}function ia(e){return $s(e).getComputedStyle(e)}function Hm(e){return aa(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function ul(e){if(Jo(e)==="html")return e;const n=e.assignedSlot||e.parentNode||sS(e)&&e.host||_a(e);return sS(n)?n.host:n}function qT(e){const n=ul(e);return Su(n)?(e.ownerDocument||e).body:Ai(n)&&Bm(n)?n:qT(n)}function Cu(e,n,s){var r;n===void 0&&(n=[]),s===void 0&&(s=!0);const a=qT(e),i=a===((r=e.ownerDocument)==null?void 0:r.body),l=$s(a);if(i){const o=Dj(l);return n.concat(l,l.visualViewport||[],Bm(a)?a:[],o&&s?Cu(o):[])}else return n.concat(a,Cu(a,[],s))}function Dj(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function YT(e){const n=ia(e);let s=parseFloat(n.width)||0,r=parseFloat(n.height)||0;const a=Ai(e),i=a?e.offsetWidth:s,l=a?e.offsetHeight:r,o=Pf(s)!==i||Pf(r)!==l;return o&&(s=i,r=l),{width:s,height:r,$:o}}function Fw(e){return aa(e)?e:e.contextElement}function go(e){const n=Fw(e);if(!Ai(n))return Ea(1);const s=n.getBoundingClientRect(),{width:r,height:a,$:i}=YT(n);let l=(i?Pf(s.width):s.width)/r,o=(i?Pf(s.height):s.height)/a;return(!l||!Number.isFinite(l))&&(l=1),(!o||!Number.isFinite(o))&&(o=1),{x:l,y:o}}const t3=Ea(0);function QT(e){const n=$s(e);return!Lw()||!n.visualViewport?t3:{x:n.visualViewport.offsetLeft,y:n.visualViewport.offsetTop}}function n3(e,n,s){return n===void 0&&(n=!1),!!s&&n&&s===$s(e)}function dl(e,n,s,r){n===void 0&&(n=!1),s===void 0&&(s=!1);const a=e.getBoundingClientRect(),i=Fw(e);let l=Ea(1);n&&(r?aa(r)&&(l=go(r)):l=go(e));const o=n3(i,s,r)?QT(i):Ea(0);let c=(a.left+o.x)/l.x,u=(a.top+o.y)/l.y,h=a.width/l.x,m=a.height/l.y;if(i&&r){const f=$s(i),p=aa(r)?$s(r):r;let x=f,g=Dj(x);for(;g&&p!==x;){const w=go(g),v=g.getBoundingClientRect(),j=ia(g),y=v.left+(g.clientLeft+parseFloat(j.paddingLeft))*w.x,k=v.top+(g.clientTop+parseFloat(j.paddingTop))*w.y;c*=w.x,u*=w.y,h*=w.x,m*=w.y,c+=y,u+=k,x=$s(g),g=Dj(x)}}return Of({width:h,height:m,x:c,y:u})}function Km(e,n){const s=Hm(e).scrollLeft;return n?n.left+s:dl(_a(e)).left+s}function JT(e,n){const s=e.getBoundingClientRect(),r=s.left+n.scrollLeft-Km(e,s),a=s.top+n.scrollTop;return{x:r,y:a}}function s3(e){let{elements:n,rect:s,offsetParent:r,strategy:a}=e;const i=a==="fixed",l=_a(r),o=n?Wm(n.floating):!1;if(r===l||o&&i)return s;let c={scrollLeft:0,scrollTop:0},u=Ea(1);const h=Ea(0),m=Ai(r);if((m||!i)&&((Jo(r)!=="body"||Bm(l))&&(c=Hm(r)),m)){const p=dl(r);u=go(r),h.x=p.x+r.clientLeft,h.y=p.y+r.clientTop}const f=l&&!m&&!i?JT(l,c):Ea(0);return{width:s.width*u.x,height:s.height*u.y,x:s.x*u.x-c.scrollLeft*u.x+h.x+f.x,y:s.y*u.y-c.scrollTop*u.y+h.y+f.y}}function r3(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function a3(e){const n=Hm(e),s=e.ownerDocument.body,r=Ca(e.scrollWidth,e.clientWidth,s.scrollWidth,s.clientWidth),a=Ca(e.scrollHeight,e.clientHeight,s.scrollHeight,s.clientHeight);let i=-n.scrollLeft+Km(e);const l=-n.scrollTop;return ia(s).direction==="rtl"&&(i+=Ca(e.clientWidth,s.clientWidth)-r),{width:r,height:a,x:i,y:l}}const i3=25;function l3(e,n,s){s===void 0&&(s="viewport");const r=s==="layoutViewport",a=$s(e),i=_a(e),l=a.visualViewport;let o=i.clientWidth,c=i.clientHeight,u=0,h=0;if(l){const f=!Lw()||n==="fixed";r?f||(u=-l.offsetLeft,h=-l.offsetTop):(o=l.width,c=l.height,f&&(u=l.offsetLeft,h=l.offsetTop))}if(Km(i)<=0){const f=i.ownerDocument,p=f.body,x=getComputedStyle(p),g=f.compatMode==="CSS1Compat"&&parseFloat(x.marginLeft)+parseFloat(x.marginRight)||0,w=Math.abs(i.clientWidth-p.clientWidth-g),v=getComputedStyle(i).scrollbarGutter==="stable both-edges"?w/2:w;v<=i3&&(o-=v)}return{width:o,height:c,x:u,y:h}}function o3(e,n){const s=dl(e,!0,n==="fixed"),r=s.top+e.clientTop,a=s.left+e.clientLeft,i=go(e),l=e.clientWidth*i.x,o=e.clientHeight*i.y,c=a*i.x,u=r*i.y;return{width:l,height:o,x:c,y:u}}function rS(e,n,s){let r;if(n==="viewport"||n==="layoutViewport")r=l3(e,s,n);else if(n==="document")r=a3(_a(e));else if(aa(n))r=o3(n,s);else{const a=QT(e);r={x:n.x-a.x,y:n.y-a.y,width:n.width,height:n.height}}return Of(r)}function c3(e,n){const s=n.get(e);if(s)return s;let r=Cu(e,[],!1).filter(o=>aa(o)&&Jo(o)!=="body"),a=null;const i=ia(e).position==="fixed";let l=i?ul(e):e;for(;aa(l)&&!Su(l);){const o=ia(l),c=Dw(l),u=a?a.position:i?"fixed":"";!c&&(u==="fixed"||u==="absolute"&&o.position==="static")?r=r.filter(m=>m!==l):a=o,l=ul(l)}return n.set(e,r),r}function u3(e){let{element:n,boundary:s,rootBoundary:r,strategy:a}=e;const l=[...s==="clippingAncestors"?Wm(n)?[]:c3(n,this._c):[].concat(s),r],o=rS(n,l[0],a);let c=o.top,u=o.right,h=o.bottom,m=o.left;for(let f=1;f<l.length;f++){const p=rS(n,l[f],a);c=Ca(p.top,c),u=xi(p.right,u),h=xi(p.bottom,h),m=Ca(p.left,m)}return{width:u-m,height:h-c,x:m,y:c}}function d3(e){const{width:n,height:s}=YT(e);return{width:n,height:s}}function h3(e,n,s){const r=Ai(n),a=_a(n),i=s==="fixed",l=dl(e,!0,i,n);let o={scrollLeft:0,scrollTop:0};const c=Ea(0);if((r||!i)&&((Jo(n)!=="body"||Bm(a))&&(o=Hm(n)),r)){const f=dl(n,!0,i,n);c.x=f.x+n.clientLeft,c.y=f.y+n.clientTop}!r&&a&&(c.x=Km(a));const u=a&&!r&&!i?JT(a,o):Ea(0),h=l.left+o.scrollLeft-c.x-u.x,m=l.top+o.scrollTop-c.y-u.y;return{x:h,y:m,width:l.width,height:l.height}}function jg(e){return ia(e).position==="static"}function aS(e,n){if(!Ai(e)||ia(e).position==="fixed")return null;if(n)return n(e);let s=e.offsetParent;return _a(e)===s&&(s=s.ownerDocument.body),s}function XT(e,n){const s=$s(e);if(Wm(e))return s;if(!Ai(e)){let a=ul(e);for(;a&&!Su(a);){if(aa(a)&&!jg(a))return a;a=ul(a)}return s}let r=aS(e,n);for(;r&&Jz(r)&&jg(r);)r=aS(r,n);return r&&Su(r)&&jg(r)&&!Dw(r)?s:r||e3(e)||s}const f3=async function(e){const n=this.getOffsetParent||XT,s=this.getDimensions,r=await s(e.floating);return{reference:h3(e.reference,await n(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function m3(e){return ia(e).direction==="rtl"}const p3={convertOffsetParentRelativeRectToViewportRelativeRect:s3,getDocumentElement:_a,getClippingRect:u3,getOffsetParent:XT,getElementRects:f3,getClientRects:r3,getDimensions:d3,getScale:go,isElement:aa,isRTL:m3};function ZT(e,n){return e.x===n.x&&e.y===n.y&&e.width===n.width&&e.height===n.height}function g3(e,n,s){let r=null,a;const i=_a(e);function l(){var h;clearTimeout(a),(h=r)==null||h.disconnect(),r=null}function o(h,m){h===void 0&&(h=!1),m===void 0&&(m=1),l();const f=e.getBoundingClientRect(),{left:p,top:x,width:g,height:w}=f;if(h||n(),!g||!w)return;const v=th(x),j=th(i.clientWidth-(p+g)),y=th(i.clientHeight-(x+w)),k=th(p),b={rootMargin:-v+"px "+-j+"px "+-y+"px "+-k+"px",threshold:Ca(0,xi(1,m))||1};let S=!0;function C(A){const E=A[0].intersectionRatio;if(!ZT(f,e.getBoundingClientRect()))return o();if(E!==m){if(!S)return o();E?o(!1,E):a=setTimeout(()=>{o(!1,1e-7)},1e3)}S=!1}try{r=new IntersectionObserver(C,{...b,root:i.ownerDocument})}catch{r=new IntersectionObserver(C,b)}r.observe(e)}const c=$s(e),u=()=>o(s);return c.addEventListener("resize",u),o(!0),()=>{c.removeEventListener("resize",u),l()}}function x3(e,n,s,r){r===void 0&&(r={});const{ancestorScroll:a=!0,ancestorResize:i=!0,elementResize:l=typeof ResizeObserver=="function",layoutShift:o=typeof IntersectionObserver=="function",animationFrame:c=!1}=r,u=Fw(e),h=a||i?[...u?Cu(u):[],...n?Cu(n):[]]:[];h.forEach(v=>{a&&v.addEventListener("scroll",s),i&&v.addEventListener("resize",s)});const m=u&&o?g3(u,s,i):null;let f=-1,p=null;l&&(p=new ResizeObserver(v=>{let[j]=v;j&&j.target===u&&p&&n&&(p.unobserve(n),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var y;(y=p)==null||y.observe(n)})),s()}),u&&!c&&p.observe(u),n&&p.observe(n));let x,g=c?dl(e):null;c&&w();function w(){const v=dl(e);g&&!ZT(g,v)&&s(),g=v,x=requestAnimationFrame(w)}return s(),()=>{var v;h.forEach(j=>{a&&j.removeEventListener("scroll",s),i&&j.removeEventListener("resize",s)}),m==null||m(),(v=p)==null||v.disconnect(),p=null,c&&cancelAnimationFrame(x)}}const j3=Gz,v3=qz,y3=Hz,w3=Qz,b3=Kz,iS=Wz,k3=Yz,N3=(e,n,s)=>{const r=new Map,a=s??{},i={...p3,...a.platform,_c:r};return Bz(e,n,{...a,platform:i})};var S3=typeof document<"u",C3=function(){},Hh=S3?d.useLayoutEffect:C3;function Df(e,n){if(e===n)return!0;if(typeof e!=typeof n)return!1;if(typeof e=="function"&&e.toString()===n.toString())return!0;let s,r,a;if(e&&n&&typeof e=="object"){if(Array.isArray(e)){if(s=e.length,s!==n.length)return!1;for(r=s;r--!==0;)if(!Df(e[r],n[r]))return!1;return!0}if(a=Object.keys(e),s=a.length,s!==Object.keys(n).length)return!1;for(r=s;r--!==0;)if(!{}.hasOwnProperty.call(n,a[r]))return!1;for(r=s;r--!==0;){const i=a[r];if(!(i==="_owner"&&e.$$typeof)&&!Df(e[i],n[i]))return!1}return!0}return e!==e&&n!==n}function eR(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function lS(e,n){const s=eR(e);return Math.round(n*s)/s}function vg(e){const n=d.useRef(e);return Hh(()=>{n.current=e}),n}function E3(e){e===void 0&&(e={});const{placement:n="bottom",strategy:s="absolute",middleware:r=[],platform:a,elements:{reference:i,floating:l}={},transform:o=!0,whileElementsMounted:c,open:u}=e,[h,m]=d.useState({x:0,y:0,strategy:s,placement:n,middlewareData:{},isPositioned:!1}),[f,p]=d.useState(r);Df(f,r)||p(r);const[x,g]=d.useState(null),[w,v]=d.useState(null),j=d.useCallback(M=>{M!==b.current&&(b.current=M,g(M))},[]),y=d.useCallback(M=>{M!==S.current&&(S.current=M,v(M))},[]),k=i||x,N=l||w,b=d.useRef(null),S=d.useRef(null),C=d.useRef(h),A=c!=null,E=vg(c),R=vg(a),P=vg(u),O=d.useCallback(()=>{if(!b.current||!S.current)return;const M={placement:n,strategy:s,middleware:f};R.current&&(M.platform=R.current),N3(b.current,S.current,M).then(z=>{const D={...z,isPositioned:P.current!==!1};I.current&&!Df(C.current,D)&&(C.current=D,qo.flushSync(()=>{m(D)}))})},[f,n,s,R,P]);Hh(()=>{u===!1&&C.current.isPositioned&&(C.current.isPositioned=!1,m(M=>({...M,isPositioned:!1})))},[u]);const I=d.useRef(!1);Hh(()=>(I.current=!0,()=>{I.current=!1}),[]),Hh(()=>{if(k&&(b.current=k),N&&(S.current=N),k&&N){if(E.current)return E.current(k,N,O);O()}},[k,N,O,E,A]);const F=d.useMemo(()=>({reference:b,floating:S,setReference:j,setFloating:y}),[j,y]),U=d.useMemo(()=>({reference:k,floating:N}),[k,N]),L=d.useMemo(()=>{const M={position:s,left:0,top:0};if(!U.floating)return M;const z=lS(U.floating,h.x),D=lS(U.floating,h.y);return o?{...M,transform:"translate("+z+"px, "+D+"px)",...eR(U.floating)>=1.5&&{willChange:"transform"}}:{position:s,left:z,top:D}},[s,o,U.floating,h.x,h.y]);return d.useMemo(()=>({...h,update:O,refs:F,elements:U,floatingStyles:L}),[h,O,F,U,L])}const A3=e=>{function n(s){return{}.hasOwnProperty.call(s,"current")}return{name:"arrow",options:e,fn(s){const{element:r,padding:a}=typeof e=="function"?e(s):e;return r&&n(r)?r.current!=null?iS({element:r.current,padding:a}).fn(s):{}:r?iS({element:r,padding:a}).fn(s):{}}}},$3=(e,n)=>{const s=j3(e);return{name:s.name,fn:s.fn,options:[e,n]}},T3=(e,n)=>{const s=v3(e);return{name:s.name,fn:s.fn,options:[e,n]}},R3=(e,n)=>({fn:k3(e).fn,options:[e,n]}),I3=(e,n)=>{const s=y3(e);return{name:s.name,fn:s.fn,options:[e,n]}},P3=(e,n)=>{const s=w3(e);return{name:s.name,fn:s.fn,options:[e,n]}},M3=(e,n)=>{const s=b3(e);return{name:s.name,fn:s.fn,options:[e,n]}},O3=(e,n)=>{const s=A3(e);return{name:s.name,fn:s.fn,options:[e,n]}};var D3=Object.defineProperty,L3=(e,n)=>D3(e,"name",{value:n,configurable:!0});function tR(e){const[n,s]=d.useState(void 0);return As(()=>{if(e){s({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(a=>{if(!Array.isArray(a)||!a.length)return;const i=a[0];let l,o;if("borderBoxSize"in i){const c=i.borderBoxSize,u=Array.isArray(c)?c[0]:c;l=u.inlineSize,o=u.blockSize}else l=e.offsetWidth,o=e.offsetHeight;s({width:l,height:o})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else s(void 0)},[e]),n}L3(tR,"useSize");var F3=Object.defineProperty,di=(e,n)=>F3(e,"name",{value:n,configurable:!0}),nR="Popper",[sR,Vm]=zr(nR),[_3,rR]=sR(nR),z3=di(e=>{const{__scopePopper:n,children:s}=e,[r,a]=d.useState(null),[i,l]=d.useState(void 0);return t.jsx(_3,{scope:n,anchor:r,onAnchorChange:a,placementState:i,setPlacementState:l,children:s})},"Popper"),U3="PopperAnchor",B3=d.forwardRef(di(function(n,s){const{__scopePopper:r,virtualRef:a,...i}=n,l=rR(U3,r),o=d.useRef(null),c=l.onAnchorChange,u=d.useCallback(g=>{o.current=g,g&&c(g)},[c]),h=Ht(s,u),m=d.useRef(null);d.useEffect(()=>{if(!a)return;const g=m.current;m.current=a.current,g!==m.current&&c(m.current)});const f=l.placementState&&Gm(l.placementState),p=f==null?void 0:f[0],x=f==null?void 0:f[1];return a?null:t.jsx(_t.div,{"data-radix-popper-side":p,"data-radix-popper-align":x,...i,ref:h})},"PopperAnchor")),aR="PopperContent",[W3,mue]=sR(aR),H3=d.forwardRef(di(function(n,s){var de,ge,Ue,G,ae,J,Ne;const{__scopePopper:r,side:a="bottom",sideOffset:i=0,align:l="center",alignOffset:o=0,arrowPadding:c=0,avoidCollisions:u=!0,collisionBoundary:h=[],collisionPadding:m=0,sticky:f="partial",hideWhenDetached:p=!1,updatePositionStrategy:x="optimized",onPlaced:g,...w}=n,v=rR(aR,r),[j,y]=d.useState(null),k=Ht(s,y),[N,b]=d.useState(null),S=tR(N),C=(S==null?void 0:S.width)??0,A=(S==null?void 0:S.height)??0,E=a+(l!=="center"?"-"+l:""),R=typeof m=="number"?m:{top:0,right:0,bottom:0,left:0,...m},P=Array.isArray(h)?h:[h],O=P.length>0,I={padding:R,boundary:P.filter(iR),altBoundary:O},{refs:F,floatingStyles:U,placement:L,isPositioned:M,middlewareData:z}=E3({strategy:"fixed",placement:E,whileElementsMounted:di((...Ie)=>x3(...Ie,{animationFrame:x==="always"}),"whileElementsMounted"),elements:{reference:v.anchor},middleware:[$3({mainAxis:i+A,alignmentAxis:o}),u&&T3({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?R3():void 0,...I}),u&&I3({...I}),P3({...I,apply:di(({elements:Ie,rects:Y,availableWidth:X,availableHeight:oe})=>{const{width:ve,height:be}=Y.reference,Ce=Ie.floating.style;Ce.setProperty("--radix-popper-available-width",`${X}px`),Ce.setProperty("--radix-popper-available-height",`${oe}px`),Ce.setProperty("--radix-popper-anchor-width",`${ve}px`),Ce.setProperty("--radix-popper-anchor-height",`${be}px`)},"apply")}),N&&O3({element:N,padding:c}),K3({arrowWidth:C,arrowHeight:A}),p&&M3({strategy:"referenceHidden",...I,boundary:O?I.boundary:void 0})]}),D=v.setPlacementState;As(()=>(D(L),()=>{D(void 0)}),[L,D]);const[K,B]=Gm(L),se=fs(g);As(()=>{M&&(se==null||se())},[M,se]);const W=(de=z.arrow)==null?void 0:de.x,xe=(ge=z.arrow)==null?void 0:ge.y,me=((Ue=z.arrow)==null?void 0:Ue.centerOffset)!==0,[ie,H]=d.useState();return As(()=>{j&&H(window.getComputedStyle(j).zIndex)},[j]),t.jsx("div",{ref:F.setFloating,"data-radix-popper-content-wrapper":"",style:{...U,transform:M?U.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ie,"--radix-popper-transform-origin":[(G=z.transformOrigin)==null?void 0:G.x,(ae=z.transformOrigin)==null?void 0:ae.y].join(" "),...((J=z.hide)==null?void 0:J.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:n.dir,children:t.jsx(W3,{scope:r,placedSide:K,placedAlign:B,onArrowChange:b,arrowX:W,arrowY:xe,shouldHideArrow:me,children:t.jsx(_t.div,{"data-side":K,"data-align":B,...w,ref:k,style:{...w.style,animation:M?(Ne=w.style)==null?void 0:Ne.animation:"none"}})})})},"PopperContent"));function iR(e){return e!==null}di(iR,"isNotNull");var K3=di(e=>({name:"transformOrigin",options:e,fn(n){var w,v,j;const{placement:s,rects:r,middlewareData:a}=n,l=((w=a.arrow)==null?void 0:w.centerOffset)!==0,o=l?0:e.arrowWidth,c=l?0:e.arrowHeight,[u,h]=Gm(s),m={start:"0%",center:"50%",end:"100%"}[h],f=(((v=a.arrow)==null?void 0:v.x)??0)+o/2,p=(((j=a.arrow)==null?void 0:j.y)??0)+c/2;let x="",g="";return u==="bottom"?(x=l?m:`${f}px`,g=`${-c}px`):u==="top"?(x=l?m:`${f}px`,g=`${r.floating.height+c}px`):u==="right"?(x=`${-c}px`,g=l?m:`${p}px`):u==="left"&&(x=`${r.floating.width+c}px`,g=l?m:`${p}px`),{data:{x,y:g}}}}),"transformOrigin");function Gm(e){const[n,s="center"]=e.split("-");return[n,s]}di(Gm,"getSideAndAlignFromPlacement");var _w=z3,lR=B3,oR=H3,V3=Object.defineProperty,_n=(e,n)=>V3(e,"name",{value:n,configurable:!0}),[zw,pue]=zr("Tooltip",[Vm]),Uw=Vm(),G3="TooltipProvider",q3=700,Lj="tooltip.open",[Y3,Bw]=zw(G3),Q3=_n(e=>{const{__scopeTooltip:n,delayDuration:s=q3,skipDelayDuration:r=300,disableHoverableContent:a=!1,children:i}=e,l=d.useRef(!0),o=d.useRef(!1),c=d.useRef(0);return d.useEffect(()=>{const u=c.current;return()=>window.clearTimeout(u)},[]),t.jsx(Y3,{scope:n,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:a,children:i})},"TooltipProvider"),Fj="Tooltip",[J3,ud]=zw(Fj),X3=_n(e=>{const{__scopeTooltip:n,children:s,open:r,defaultOpen:a,onOpenChange:i,disableHoverableContent:l,delayDuration:o}=e,c=Bw(Fj,e.__scopeTooltip),u=Uw(n),[h,m]=d.useState(null),[f,p]=d.useState(void 0),x=Tr(),g=d.useRef(0),w=l??c.disableHoverableContent,v=o??c.delayDuration,j=d.useRef(!1),[y,k]=Ei({prop:r,defaultProp:a??!1,onChange:_n(E=>{E?(c.onOpen(),document.dispatchEvent(new CustomEvent(Lj))):c.onClose(),i==null||i(E)},"onChange"),caller:Fj}),N=d.useMemo(()=>y?j.current?"delayed-open":"instant-open":"closed",[y]),b=d.useCallback(()=>{window.clearTimeout(g.current),g.current=0,j.current=!1,k(!0)},[k]),S=d.useCallback(()=>{window.clearTimeout(g.current),g.current=0,k(!1)},[k]),C=d.useCallback(()=>{window.clearTimeout(g.current),g.current=window.setTimeout(()=>{j.current=!0,k(!0),g.current=0},v)},[v,k]);d.useEffect(()=>()=>{g.current&&(window.clearTimeout(g.current),g.current=0)},[]);const A=f??x;return t.jsx(_w,{...u,children:t.jsx(J3,{scope:n,contentId:A,setContentId:p,open:y,stateAttribute:N,trigger:h,onTriggerChange:m,onTriggerEnter:d.useCallback(()=>{c.isOpenDelayedRef.current?C():b()},[c.isOpenDelayedRef,C,b]),onTriggerLeave:d.useCallback(()=>{w?S():(window.clearTimeout(g.current),g.current=0)},[S,w]),onOpen:b,onClose:S,disableHoverableContent:w,children:s})})},"Tooltip"),oS="TooltipTrigger",Z3=d.forwardRef(_n(function(n,s){const{__scopeTooltip:r,...a}=n,i=ud(oS,r),l=Bw(oS,r),o=Uw(r),c=d.useRef(null),u=Ht(s,c,i.onTriggerChange),h=d.useRef(!1),m=d.useRef(!1),f=d.useCallback(()=>h.current=!1,[]);return d.useEffect(()=>()=>document.removeEventListener("pointerup",f),[f]),t.jsx(lR,{asChild:!0,...o,children:t.jsx(_t.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...a,ref:u,onPointerMove:Ge(n.onPointerMove,p=>{p.pointerType!=="touch"&&!m.current&&!l.isPointerInTransitRef.current&&(i.onTriggerEnter(),m.current=!0)}),onPointerLeave:Ge(n.onPointerLeave,()=>{i.onTriggerLeave(),m.current=!1}),onPointerDown:Ge(n.onPointerDown,()=>{i.open&&i.onClose(),h.current=!0,document.addEventListener("pointerup",f,{once:!0})}),onFocus:Ge(n.onFocus,()=>{h.current||i.onOpen()}),onBlur:Ge(n.onBlur,i.onClose),onClick:Ge(n.onClick,i.onClose)})})},"TooltipTrigger")),cR="TooltipPortal",[eU,tU]=zw(cR,{forceMount:void 0}),nU=_n(e=>{const{__scopeTooltip:n,forceMount:s,children:r,container:a}=e,i=ud(cR,n);return t.jsx(eU,{scope:n,forceMount:s,children:t.jsx(ca,{present:s||i.open,children:t.jsx(Fm,{asChild:!0,container:a,children:r})})})},"TooltipPortal"),Eu="TooltipContent",sU=d.forwardRef(_n(function(n,s){const r=tU(Eu,n.__scopeTooltip),{forceMount:a=r.forceMount,side:i="top",...l}=n,o=ud(Eu,n.__scopeTooltip);return t.jsx(ca,{present:a||o.open,children:o.disableHoverableContent?t.jsx(uR,{side:i,...l,ref:s}):t.jsx(rU,{side:i,...l,ref:s})})},"TooltipContent")),rU=d.forwardRef(_n(function(n,s){const r=ud(Eu,n.__scopeTooltip),a=Bw(Eu,n.__scopeTooltip),i=d.useRef(null),l=Ht(s,i),[o,c]=d.useState(null),{trigger:u,onClose:h}=r,m=i.current,{onPointerInTransitChange:f}=a,p=d.useCallback(()=>{c(null),f(!1)},[f]),x=d.useCallback((g,w)=>{const v=g.currentTarget,j={x:g.clientX,y:g.clientY},y=dR(j,v.getBoundingClientRect()),k=hR(j,y),N=fR(w.getBoundingClientRect()),b=pR([...k,...N]);c(b),f(!0)},[f]);return d.useEffect(()=>()=>p(),[p]),d.useEffect(()=>{if(u&&m){const g=_n(v=>x(v,m),"handleTriggerLeave"),w=_n(v=>x(v,u),"handleContentLeave");return u.addEventListener("pointerleave",g),m.addEventListener("pointerleave",w),()=>{u.removeEventListener("pointerleave",g),m.removeEventListener("pointerleave",w)}}},[u,m,x,p]),d.useEffect(()=>{if(o){const g=_n(w=>{const v=w.target,j={x:w.clientX,y:w.clientY},y=(u==null?void 0:u.contains(v))||(m==null?void 0:m.contains(v)),k=!mR(j,o);y?p():k&&(p(),h())},"handleTrackPointerGrace");return document.addEventListener("pointermove",g),()=>document.removeEventListener("pointermove",g)}},[u,m,o,h,p]),t.jsx(uR,{...n,ref:l})},"TooltipContentHoverable")),aU=jT("TooltipContent"),uR=d.forwardRef(_n(function(n,s){const{__scopeTooltip:r,children:a,"aria-label":i,id:l,onEscapeKeyDown:o,onPointerDownOutside:c,...u}=n,h=ud(Eu,r),m=Uw(r),{onClose:f}=h;d.useEffect(()=>(document.addEventListener(Lj,f),()=>document.removeEventListener(Lj,f)),[f]),d.useEffect(()=>{if(h.trigger){const x=_n(g=>{g.target instanceof Node&&g.target.contains(h.trigger)&&f()},"handleScroll");return window.addEventListener("scroll",x,{capture:!0}),()=>window.removeEventListener("scroll",x,{capture:!0})}},[h.trigger,f]);const{setContentId:p}=h;return As(()=>(p(l),()=>{p(void 0)}),[l,p]),t.jsx(Lm,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:o,onPointerDownOutside:c,onFocusOutside:x=>x.preventDefault(),onDismiss:f,children:t.jsxs(oR,{"data-state":h.stateAttribute,role:i?void 0:"tooltip",id:i?void 0:h.contentId,...m,...u,ref:s,style:{...u.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[t.jsx(aU,{children:a}),i?t.jsx(Z4,{id:h.contentId,role:"tooltip",children:i}):null]})})},"TooltipContentImpl"));function dR(e,n){const s=Math.abs(n.top-e.y),r=Math.abs(n.bottom-e.y),a=Math.abs(n.right-e.x),i=Math.abs(n.left-e.x);switch(Math.min(s,r,a,i)){case i:return"left";case a:return"right";case s:return"top";case r:return"bottom";default:throw new Error("unreachable")}}_n(dR,"getExitSideFromRect");function hR(e,n,s=5){const r=[];switch(n){case"top":r.push({x:e.x-s,y:e.y+s},{x:e.x+s,y:e.y+s});break;case"bottom":r.push({x:e.x-s,y:e.y-s},{x:e.x+s,y:e.y-s});break;case"left":r.push({x:e.x+s,y:e.y-s},{x:e.x+s,y:e.y+s});break;case"right":r.push({x:e.x-s,y:e.y-s},{x:e.x-s,y:e.y+s});break}return r}_n(hR,"getPaddedExitPoints");function fR(e){const{top:n,right:s,bottom:r,left:a}=e;return[{x:a,y:n},{x:s,y:n},{x:s,y:r},{x:a,y:r}]}_n(fR,"getPointsFromRect");function mR(e,n){const{x:s,y:r}=e;let a=!1;for(let i=0,l=n.length-1;i<n.length;l=i++){const o=n[i],c=n[l],u=o.x,h=o.y,m=c.x,f=c.y;h>r!=f>r&&s<(m-u)*(r-h)/(f-h)+u&&(a=!a)}return a}_n(mR,"isPointInPolygon");function pR(e){const n=e.slice();return n.sort((s,r)=>s.x<r.x?-1:s.x>r.x?1:s.y<r.y?-1:s.y>r.y?1:0),gR(n)}_n(pR,"getHull");function gR(e){if(e.length<=1)return e.slice();const n=[];for(let r=0;r<e.length;r++){const a=e[r];for(;n.length>=2;){const i=n[n.length-1],l=n[n.length-2];if((i.x-l.x)*(a.y-l.y)>=(i.y-l.y)*(a.x-l.x))n.pop();else break}n.push(a)}n.pop();const s=[];for(let r=e.length-1;r>=0;r--){const a=e[r];for(;s.length>=2;){const i=s[s.length-1],l=s[s.length-2];if((i.x-l.x)*(a.y-l.y)>=(i.y-l.y)*(a.x-l.x))s.pop();else break}s.push(a)}return s.pop(),n.length===1&&s.length===1&&n[0].x===s[0].x&&n[0].y===s[0].y?n:n.concat(s)}_n(gR,"getHullPresorted");var cS=Q3,Au=X3,$u=Z3,Tu=nU,Ru=sU;let An={time:"auto",date:"auto",locale:void 0};function Ww(e){const n=e.timeFormat===void 0?An.time:e.timeFormat==="12h"||e.timeFormat==="24h"?e.timeFormat:"auto",s=e.dateFormat===void 0?An.date:e.dateFormat==="short"||e.dateFormat==="long"||e.dateFormat==="iso"?e.dateFormat:"auto";An={time:n,date:s,locale:e.locale??An.locale}}function xR(){return{time:An.time,date:An.date}}function dd(e,n){const s=An;Ww(e);try{return n()}finally{An=s}}const _j="buddi:formats";function hd(){if(An.locale)return An.locale;try{return typeof navigator<"u"&&navigator.language?navigator.language:"en-US"}catch{return"en-US"}}const uS=new Map;function Xo(e,n){const s=`${e}|${JSON.stringify(n)}`;let r=uS.get(s);if(!r){try{r=new Intl.DateTimeFormat(e,n)}catch{r=new Intl.DateTimeFormat(e,{...n,timeZone:"UTC"})}uS.set(s,r)}return r}function yg(e,n,s,r){return Object.fromEntries(Xo(s,{timeZone:n,...r}).formatToParts(e).map(a=>[a.type,a.value]))}function iU(){return An.time==="12h"?{hour:"numeric",minute:"2-digit",hourCycle:"h12"}:An.time==="24h"?{hour:"2-digit",minute:"2-digit",hourCycle:"h23"}:{hour:qm()?"numeric":"2-digit",minute:"2-digit"}}function lU(){return An.time==="auto"?hd():"en-US"}function Lt(e,n){return Number.isNaN(e.getTime())?"—":Xo(lU(),{timeZone:n,...iU()}).format(e)}function oU(e){return e>=1440&&!qm()?"24:00":Lt(new Date(Date.UTC(2026,0,1,Math.floor(e/60)%24,e%60)),"UTC")}function qm(){var e;return An.time!=="auto"?An.time==="12h":((e=Xo(hd(),{hour:"numeric"}).resolvedOptions().hourCycle)==null?void 0:e.startsWith("h1"))===!0}function jR(){return`Profile (${qm()?"12-hour":"24-hour"})`}function cU(){if(An.date!=="auto")return An.date==="short";const e=Xo(hd(),{month:"short",day:"numeric"}).formatToParts(new Date(Date.UTC(2026,9,1))).map(n=>n.type);return e.indexOf("month")<e.indexOf("day")}function Ks(e,n,s={}){return uU(e,n,s).replace(/\bSept\b/g,"Sep")}function uU(e,n,s){if(Number.isNaN(e.getTime()))return"—";const{weekday:r=!1,year:a=!1,compact:i=!1}=s;switch(An.date){case"iso":{const l=yg(e,n,"en-CA",{year:"numeric",month:"2-digit",day:"2-digit",...r?{weekday:i?"short":"long"}:{}}),o=`${l.year}-${l.month}-${l.day}`;return r?`${l.weekday} ${o}`:o}case"short":{const l=yg(e,n,"en-US",{month:"short",day:"numeric",year:"numeric",weekday:"short"});return`${r?`${l.weekday}, `:""}${l.month} ${l.day}${a?`, ${l.year}`:""}`}case"long":{const l=yg(e,n,"en-GB",{month:i?"short":"long",day:"numeric",year:"numeric",weekday:i?"short":"long"});return`${r?`${l.weekday}, `:""}${l.day} ${l.month}${a?` ${l.year}`:""}`}default:return Xo(hd(),{timeZone:n,month:i?"short":"long",day:"numeric",...a?{year:"numeric"}:{},...r?{weekday:i?"short":"long"}:{}}).format(e)}}function vR(e,n){if(An.date==="iso")return`${e}-${String(n).padStart(2,"0")}`;const s=new Date(Date.UTC(e,n-1,15)),r=An.date==="auto"?hd():"en-GB";return Xo(r,{timeZone:"UTC",month:"long",year:"numeric"}).format(s)}function Zo(e,n={}){const s=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);if(!s)return e;const r=new Date(`${s[0]}T12:00:00Z`);return Number.isNaN(r.getTime())?e:Ks(r,"UTC",n)}function St(e,n){if(!e)return"—";const s=new Date(e);return Number.isNaN(s.getTime())?String(e):`${Ks(s,n,{year:!0,compact:!0})}, ${Lt(s,n)}`}function Ym(e,n){return`${Ks(e,n,{weekday:!0,compact:!0})}, ${Lt(e,n)}`}function Xe(e,n=Date.now()){if(!e)return"";const s=new Date(e).getTime();if(Number.isNaN(s))return"";const r=Math.round((s-n)/1e3),a=Math.abs(r),[i,l]=a<60?[r,"second"]:a<3600?[Math.round(r/60),"minute"]:a<86400?[Math.round(r/3600),"hour"]:[Math.round(r/86400),"day"];return new Intl.RelativeTimeFormat("en",{numeric:"auto"}).format(i,l)}function Hw(e,n=Date.now()){if(!e)return"";const s=new Date(e).getTime();if(Number.isNaN(s))return"";const r=Math.abs(Math.round((n-s)/1e3));return r<60?"now":r<3600?`${Math.floor(r/60)} min`:r<86400?`${Math.floor(r/3600)} h`:`${Math.floor(r/86400)} d`}function yR(e,n=Date.now()){const s=Hw(e,n);return s===""?"":s==="now"||new Date(e).getTime()>n?"just now":s==="1 d"?"yesterday":`${s} ago`}function dU(e,n){if(e==null||!Number.isFinite(e))return"—";try{return new Intl.NumberFormat("en-US",{style:"currency",currency:n??"USD",maximumFractionDigits:0}).format(e)}catch{return e.toFixed(2)}}function Cn(e){return new Intl.NumberFormat("en-US").format(e)}function zj(e){return[...e.cacheRead?[`cached ${Cn(e.cacheRead)}`]:[],...e.cacheWrite?[`cache write ${Cn(e.cacheWrite)}`]:[]].join(", ")}function hU(e){const n=zj(e);return`${Cn(e.input)} in${n?` (${n})`:""} / ${Cn(e.output)} out`}function ms(e){try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function Iu(e,n=8){return e.length<=n?e:e.slice(0,n)}function mr(e,n){return e.length<=n?e:`${e.slice(0,n-1)}…`}function Pu(e){if(e.kind!=="agent")return e.title;const n=e.title.replace(/^@[^\s:]+:\s+/,"");return n.trim()===""?e.title:n}const dS="buddi_csrf",ec="x-buddi-csrf",Rs="buddi:agents-changed",Yi="buddi:status-changed",Sc=e=>(window.dispatchEvent(new Event(Yi)),e),Uj="buddi:locked",fU="This page's sign-in no longer matches its cookies. Reload the page and try again.";class pe extends Error{constructor(n,s,r){super(s),this.status=n,this.detail=r,this.name="ApiError"}}function wl(){var r;const e=Number(location.port)||(location.protocol==="https:"?443:80),n=document.cookie.match(new RegExp(`(?:^|; )${dS}_${e}=([^;]*)`));if(n!=null&&n[1])return decodeURIComponent(n[1]);const s=[...document.cookie.matchAll(new RegExp(`(?:^|; )${dS}(?:_\\d+)?=([^;]*)`,"g"))];return s.length===1&&((r=s[0])!=null&&r[1])?decodeURIComponent(s[0][1]):""}const Lf="buddi isn't answering.";let Bj=null;const Wj=new Set;function Cc(e){if(e!==(Bj===null)){Bj=e?null:Date.now();for(const n of Wj)n()}}function Mu(){return Bj}function Kw(e){return Wj.add(e),()=>Wj.delete(e)}function Ff(e){return e instanceof pe&&(e.status===0||e.status===502||e.status===503)&&e.message===Lf}async function bl(e,n={}){var l;let s;try{s=await fetch(e,{...n,credentials:"same-origin",redirect:"error",headers:{Accept:"application/json",...n.headers??{}}})}catch(o){throw(o==null?void 0:o.name)==="AbortError"||(l=n.signal)!=null&&l.aborted?o:(Cc(!1),new pe(0,Lf,o))}if(s.status===401)throw Cc(!0),new pe(401,"This session has expired. Run `buddi dashboard` for a fresh link.");if(s.status===423)throw Cc(!0),window.dispatchEvent(new Event(Uj)),new pe(423,"This dashboard is locked.");const r=await s.text(),a=r===""?null:mU(r),i=a&&typeof a=="object"&&"error"in a?String(a.error):void 0;if((s.status===502||s.status===503)&&i===void 0)throw Cc(!1),new pe(s.status,Lf,a);if(Cc(!0),!s.ok){const o=(n.method??"GET").toUpperCase(),c=i??(s.status===403&&o!=="GET"&&o!=="HEAD"?fU:`request failed (${s.status})`);throw new pe(s.status,c,a)}return a}function mU(e){try{return JSON.parse(e)}catch{return null}}function wg(){return xR().time==="auto"?{hour:qm()?"12":"24"}:{}}function ke(e,n={}){const s=new URLSearchParams;for(const[a,i]of Object.entries(n))i!==void 0&&i!==""&&s.set(a,String(i));const r=s.toString();return bl(`/api${e}${r?`?${r}`:""}`)}function Kh(e,n){return bl(`/api${e}`,{method:"POST",headers:{[ec]:wl()},body:n})}function ys(e){return bl(`/api${e}`,{method:"DELETE",headers:{[ec]:wl()}})}function Z(e,n={}){return bl(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/json",[ec]:wl()},body:JSON.stringify(n??{})})}function Vw(e,n,s,r={}){const a=n.name.replace(/[^\w.-]+/g,"_").slice(-120)||s;return bl(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/octet-stream",[ec]:wl(),"X-Filename":a,...r},body:n})}function hS(e,n,s){return Vw(e,n,"backup.tar.gz",{...s.passphrase?{"X-Backup-Passphrase":s.passphrase}:{},...s.confirm?{"X-Backup-Confirm":s.confirm}:{}})}function pU(e,n={}){return bl(`/api${e}`,{method:"PATCH",headers:{"Content-Type":"application/json",[ec]:wl()},body:JSON.stringify(n??{})})}function wr(e,n={}){return bl(`/api${e}`,{method:"PUT",headers:{"Content-Type":"application/json",[ec]:wl()},body:JSON.stringify(n??{})})}function gU(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 Vh="gpt-oss:120b",xU=["approval","question","watcher","reminder","failure","recap","plugin","agent"],Hj=["mon","tue","wed","thu","fri","sat","sun"],nt={agents:()=>ke("/chat/agents"),views:()=>ke("/chat/views"),conversations:(e,n)=>ke(`/chat/${encodeURIComponent(e)}/conversations`,{limit:n}),startConversation:e=>Z(`/chat/${encodeURIComponent(e)}/conversations`),conversation:e=>ke(`/chat/conversations/${encodeURIComponent(e)}`),deleteCarryOver:e=>ys(`/chat/conversations/${encodeURIComponent(e)}/carry-over`),canvasTabs:e=>ke(`/chat/conversations/${encodeURIComponent(e)}/canvas-tabs`),saveCanvasTabs:(e,n)=>wr(`/chat/conversations/${encodeURIComponent(e)}/canvas-tabs`,n),send:(e,n)=>Z(`/chat/${encodeURIComponent(e)}/messages`,n),answerQuestion:(e,n)=>Z(`/chat/questions/${encodeURIComponent(e)}/answer`,n),cancel:e=>Z(`/chat/conversations/${encodeURIComponent(e)}/cancel`),attach:e=>{const n=new FormData;return n.append("file",e,e.name),Kh("/chat/attachments",n)},transcribe:e=>Z("/speech/transcribe",e),say:e=>Z("/speech/say",e),discardAttachment:e=>ys(`/artifacts/${encodeURIComponent(e)}`),groups:()=>ke("/groups"),group:e=>ke(`/groups/${encodeURIComponent(e)}`),createGroup:e=>Z("/groups",e),updateGroup:(e,n)=>pU(`/groups/${encodeURIComponent(e)}`,n),deleteGroup:e=>ys(`/groups/${encodeURIComponent(e)}`),restoreGroup:e=>Z(`/groups/${encodeURIComponent(e)}/restore`),clearGroup:e=>Z(`/groups/${encodeURIComponent(e)}/clear`),groupConversations:e=>ke(`/groups/${encodeURIComponent(e)}/conversations`),startGroupConversation:e=>Z(`/groups/${encodeURIComponent(e)}/conversations`),sendToGroup:(e,n)=>Z(`/groups/${encodeURIComponent(e)}/messages`,n),streamUrl:e=>`/api/chat/conversations/${encodeURIComponent(e)}/stream`};function Gw(e){return e.httpStatus===401||e.httpStatus===403||e.state==="authentication-error"||e.state==="access-denied"}const T={providers:()=>ke("/providers"),providerAccounts:()=>ke("/provider-accounts"),probeModels:e=>Z("/provider-accounts/probe-models",e),accountModels:(e,n=!1)=>Z(`/provider-accounts/${encodeURIComponent(e)}/models`,{refresh:n}),saveProviderAccount:e=>Z("/provider-accounts/save",e),testProviderAccount:e=>Z(`/provider-accounts/${encodeURIComponent(e)}/test`),removeProviderAccount:(e,n)=>Z(`/provider-accounts/${encodeURIComponent(e)}/remove`,{revision:n}),codexAccountAction:(e,n,s)=>Z(`/provider-accounts/${encodeURIComponent(e)}/${n}`,{revision:s}),ollamaConnect:(e,n)=>Z(`/provider-accounts/${encodeURIComponent(e)}/ollama/connect`,{revision:n}),ollamaPoll:(e,n)=>Z(`/provider-accounts/${encodeURIComponent(e)}/ollama/poll`,{attemptId:n}),ollamaDisconnect:(e,n)=>Z(`/provider-accounts/${encodeURIComponent(e)}/ollama/disconnect`,{revision:n}),anthropicAccountAction:(e,n,s,r)=>Z(`/provider-accounts/${encodeURIComponent(e)}/anthropic/${n}`,{revision:s,...r}),assignProviderAccount:(e,n,s)=>Z(`/agents/${encodeURIComponent(e)}/account`,{accountId:n,model:s}),configureProvider:(e,n)=>Z(`/providers/${encodeURIComponent(e)}/settings`,n),saveCredential:(e,n)=>Z(`/providers/credentials/${encodeURIComponent(e)}/save`,{value:n}),removeCredential:e=>Z(`/providers/credentials/${encodeURIComponent(e)}/remove`),testProvider:e=>Z(`/providers/${encodeURIComponent(e)}/test`),browser:e=>ke(`/browser${e?`?agentId=${encodeURIComponent(e.agentId)}&conversationId=${encodeURIComponent(e.conversationId)}`:""}`),browserControl:(e,n,s)=>Z(`/browser/${e}`,{...n===void 0?{}:{sessionId:n},...s!=null&&s.forever?{forever:!0}:{}}),browserSettings:e=>Z("/browser/settings",e),browserCapture:e=>Z("/browser/capture",{sessionId:e}),browserFront:e=>Z("/browser/front",{sessionId:e}),browserPin:(e,n)=>Z("/browser/pin",{conversationId:e,route:n}),browserLogin:(e,n)=>Z("/browser/login",{id:e,decision:n}),browserCard:(e,n)=>Z("/browser/card",{conversationId:e,answer:n}),browserInstall:()=>Z("/browser/install",{}),browserCheck:()=>Z("/browser/check",{}),browserDownloads:()=>ke("/browser/downloads"),clearBrowserDownloads:()=>Z("/browser/downloads/clear",{}),fileBrowserDownload:e=>Z("/browser/downloads/file",{id:e}),previewLink:(e,n)=>ke(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(n)}/link`),previewCheck:(e,n)=>ke(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(n)}/check`),extension:()=>ke("/extension"),pairExtension:e=>Z("/extension/pair",{code:e}),forgetExtension:()=>ys("/extension/pair"),session:()=>ke("/session"),overview:()=>ke("/overview"),events:e=>ke("/events",e),eventKinds:()=>ke("/events/kinds"),conversations:()=>ke("/conversations"),conversation:e=>ke(`/conversations/${encodeURIComponent(e)}`),missions:()=>ke("/missions"),jobs:(e={})=>ke("/jobs",e),approvals:()=>ke("/approvals"),approval:e=>ke(`/approvals/${encodeURIComponent(e)}`).then(n=>n.action),offers:()=>ke("/offers"),dismissOffer:e=>Z(`/offers/${encodeURIComponent(e)}/dismiss`,{}),dismissOffers:e=>Z("/offers/dismiss-all",{ids:e}),agentOffers:()=>ke("/agent-offers"),catalogue:(e=!1)=>ke(`/catalogue${e?"?refresh=1":""}`),cataloguePlan:(e,n={})=>Z(`/catalogue/${encodeURIComponent(e)}/plan`,n),catalogueInstall:(e,n)=>Z(`/catalogue/${encodeURIComponent(e)}/install`,n),catalogueJob:e=>ke(`/catalogue/jobs/${encodeURIComponent(e)}`),catalogueConfirm:(e,n)=>Z(`/catalogue/jobs/${encodeURIComponent(e)}/confirm`,{approve:n}),catalogueUpdatePlan:(e,n)=>Z(`/catalogue/${encodeURIComponent(e)}/update/plan`,{agentId:n}),catalogueUpdate:(e,n,s,r=!1)=>Z(`/catalogue/${encodeURIComponent(e)}/update`,{agentId:n,plan:s,...r?{replace:!0}:{}}),agentRemovePreview:e=>ke(`/agents/${encodeURIComponent(e)}/remove`),removeAgent:e=>Z(`/agents/${encodeURIComponent(e)}/remove`),dismissAgentOffer:(e,n)=>Z(`/agent-offers/${encodeURIComponent(e)}/${encodeURIComponent(n)}/dismiss`,{}),proposals:()=>ke("/proposals"),setDigestSchedule:(e,n)=>Z("/proposals/digest-schedule",{day:e,hour:n}),keepProposal:(e,n)=>Z(`/proposals/${encodeURIComponent(e)}/keep`,n===void 0?{}:{text:n}),keepAllProposals:e=>Z("/proposals/keep-all",{ids:e}),discardProposal:(e,n)=>Z(`/proposals/${encodeURIComponent(e)}/discard`,n?{reason:n}:{}),reminders:()=>ke("/reminders"),sentinels:()=>ke("/sentinels"),setSentinelEnabled:(e,n)=>Z(`/sentinels/${encodeURIComponent(e)}/enabled`,{enabled:n}),widgets:(e="home")=>ke("/widgets",{...e==="lock"?{surface:e}:{},...wg()}),saveWidgets:(e,n)=>wr(`/widgets/${e}`,{placements:n.map(({key:s,widget:r,size:a,settings:i})=>({...s?{key:s}:{},widget:r,size:a,settings:i}))}),widgetSettings:e=>ke(`/widgets/settings/${encodeURIComponent(e)}`),previewWidget:e=>Z("/widgets/preview",{...e,...wg()}),refreshWidget:(e,n="home")=>Z(`/widgets/${encodeURIComponent(e)}/refresh${n==="lock"?"?surface=lock":""}`),homeDismiss:(e,n)=>Z("/home/dismiss",{slot:e,token:n}),setGlanceHidden:(e,n)=>Z(`/home/glances/${encodeURIComponent(e)}/hidden`,{hidden:n}),rail:()=>ke("/rail"),setRailHidden:(e,n,s)=>Z(`/rail/pages/${encodeURIComponent(e)}/${encodeURIComponent(n)}/hidden`,{hidden:s}),snoozeAlerts:(e,n,s)=>Z("/alerts/snooze",{keys:e,snoozed:n,...s!==void 0?{days:s}:{}}),muteAlert:(e,n)=>Z("/alerts/mute",{key:e,scope:n}),unmuteAlert:e=>Z(`/alerts/mutes/${encodeURIComponent(e)}/remove`,{}),actOnAlerts:e=>Z("/alerts/act",{entries:e}),askAboutAlerts:e=>Z("/alerts/ask",{keys:e}),agents:()=>ke("/agents"),library:e=>ke("/artifacts",e),libraryEntry:(e,n=0)=>ke(`/artifacts/${encodeURIComponent(e)}`,n?{contexts:n}:{}),onboarding:()=>ke("/onboarding"),onboardingStep:(e,n={})=>Z("/onboarding/step",{step:e,...n}),takeOn:e=>Z("/onboarding/take-on",{tiles:e}),takeOnProgress:()=>ke("/onboarding/take-on"),completeOnboarding:()=>Z("/onboarding/complete"),skipOnboarding:()=>Z("/onboarding/skip"),createFirstAgent:e=>Z("/onboarding/agent",e),ollama:()=>ke("/onboarding/ollama"),ollamaPull:e=>Z("/onboarding/ollama/pull",{model:e}),ollamaPullState:()=>ke("/onboarding/ollama/pull"),mlxh:()=>ke("/onboarding/mlxh"),firstAgentPersona:()=>ke("/onboarding/agent"),updateFirstAgent:e=>Z("/onboarding/agent/update",e),bindBrain:e=>Z("/onboarding/brain",e),reportAudio:e=>ke("/reports/audio",{link:e}),pages:()=>ke("/pages"),pageQuery:(e,n,s={})=>ke(`/pages/${encodeURIComponent(e)}/${encodeURIComponent(n)}`,s),pageFileUrl:(e,n,s={})=>{const r=new URLSearchParams(Object.entries(s).filter(([,a])=>a!=="")).toString();return`/api/pages/${encodeURIComponent(e)}/${encodeURIComponent(n)}${r?`?${r}`:""}`},pageAct:(e,n)=>Z(`/pages/${encodeURIComponent(e)}/act`,n),telegram:()=>ke("/telegram"),saveTelegramToken:e=>Z("/telegram/token",{token:e}),telegramPairing:()=>Z("/telegram/pairing"),telegramBot:()=>ke("/telegram/bot"),telegramDevices:()=>ke("/telegram/devices"),unpairTelegramDevice:e=>ys(`/telegram/devices/${encodeURIComponent(e)}`),notifications:(e=20)=>ke("/notifications",{limit:e}),notificationsNeedingYou:()=>ke("/notifications",{needs:1}),notificationSeen:e=>Z(`/notifications/${encodeURIComponent(e)}/seen`),notificationSettings:()=>ke("/notifications/settings"),saveNotificationSettings:e=>wr("/notifications/settings",e),focus:()=>ke("/notifications/focus"),lockState:()=>ke("/lock"),lockScreen:()=>ke("/lock/screen",wg()),lockNow:(e="owner",n)=>Z("/lock",{reason:e,...e==="idle"&&n!==void 0?{idleForMs:Math.max(0,Math.round(n))}:{}}),unlock:e=>Z("/lock/unlock",{pin:e}),lockActivity:()=>Z("/lock/activity"),setPin:(e,n)=>wr("/lock/pin",n===void 0?{pin:e}:{pin:e,current:n}),removePin:e=>Z("/lock/pin/remove",{current:e}),setLockSettings:e=>wr("/lock/settings",e),uploadLockBackground:e=>{const n=new FormData;return n.append("file",e),Kh("/lock/background",n)},removeLockBackground:()=>ys("/lock/background"),uploadLockPortrait:e=>{const n=new FormData;return n.append("file",e),Kh("/lock/background/portrait",n)},removeLockPortrait:()=>ys("/lock/background/portrait"),setFocus:(e,n)=>wr("/notifications/focus",n?{mode:e,duration:n}:{mode:e}).then(Sc),testChannel:e=>Z("/notifications/test",{channel:e}),setAgentMuted:(e,n)=>Z("/notifications/agent-mute",{agentId:e,muted:n}),currentTip:e=>ke(e?`/tips/current?preview=${encodeURIComponent(e)}`:"/tips/current"),tipQueue:(e,n)=>ke(e?`/tips/queue?preview=${encodeURIComponent(e)}`:n?"/tips/queue?peek=1":"/tips/queue"),tips:()=>ke("/tips"),dismissedTips:()=>ke("/tips/dismissed"),restoreTip:e=>Z(`/tips/${encodeURIComponent(e)}/restore`),dismissTip:e=>Z(`/tips/${encodeURIComponent(e)}/dismiss`),laterTip:e=>Z(`/tips/${encodeURIComponent(e)}/later`),tipsSeenPage:e=>Z("/tips/seen-page",{page:e}),presence:e=>Z("/presence",{state:e}),owner:()=>ke("/owner"),setOwner:e=>Z("/owner",e),findPlace:e=>Z("/owner/places/find",{address:e}),savePlace:e=>Z("/owner/places",e),removePlace:e=>Z("/owner/places/remove",{id:e}),memory:e=>ke(e?`/memory?agent=${encodeURIComponent(e)}`:"/memory"),setPreference:e=>Z("/memory/preferences",e),forgetPreference:e=>Z("/memory/preferences/forget",e),updateNote:(e,n)=>Z(`/memory/notes/${encodeURIComponent(e)}`,n),forgetNote:e=>Z(`/memory/notes/${encodeURIComponent(e)}/forget`),people:()=>ke("/memory/people"),savePerson:e=>Z("/memory/people",e),forgetPerson:e=>Z(`/memory/people/${encodeURIComponent(e)}/forget`),restorePerson:e=>Z(`/memory/people/${encodeURIComponent(e)}/restore`),birthday:()=>ke("/owner/birthday"),agentIntro:e=>ke(`/agents/${encodeURIComponent(e)}/intro`),dismissAgentIntro:e=>Z(`/agents/${encodeURIComponent(e)}/intro/dismiss`),setDelegates:(e,n)=>Z(`/agents/${encodeURIComponent(e)}/delegates`,{delegates:n}),agentProfile:e=>ke(`/agents/${encodeURIComponent(e)}/profile`),agentSkills:e=>ke(`/agents/${encodeURIComponent(e)}/skills`),removeSkill:(e,n)=>Z(`/agents/${encodeURIComponent(e)}/skills/${encodeURIComponent(n)}/remove`,{}),host:(e,n)=>ke("/host",{agentId:e,conversationId:n}),connections:()=>ke("/connections"),connection:e=>ke(`/connections/${e}`),addConnection:(e,n)=>Z("/connections",{url:e,...n?{name:n}:{}}),addProgram:e=>Z("/connections",{transport:"stdio",...e}),updateProgram:(e,n)=>Z(`/connections/${e}/program`,n),connectionConsent:(e,n)=>Z(`/connections/${e}/consent`,n?{clientId:n}:{}),connectionToken:(e,n)=>Z(`/connections/${e}/token`,n),connectionDevice:e=>Z(`/connections/${e}/device`,{}),connectionCallback:e=>Z("/connections/callback",e),connectionReview:e=>ke(`/connections/${e}/review`),saveConnectionReview:(e,n)=>Z(`/connections/${e}/review`,n),grantConnection:(e,n,s=!1)=>Z(`/connections/${e}/grant`,s?{agents:n,exact:!0}:{agents:n}),setConnectionHolder:(e,n,s)=>Z(`/connections/${e}/holders/${encodeURIComponent(n)}`,{held:s}),disconnect:e=>ys(`/connections/${e}`),connectionSignals:()=>ke("/connections/signals"),connectionTools:e=>ke(`/connections/${e}/tools`),rememberedApprovals:e=>ke(`/connections/remembered/${encodeURIComponent(e)}`),setRememberedApproval:(e,n,s)=>Z("/connections/remembered",{agent:e,tool:n,remember:s}),secrets:()=>ke("/secrets"),secretUses:(e,n)=>ke("/secrets/uses",{name:e,limit:n}),secretsAct:(e,n)=>Z("/secrets/act",{tool:e,args:n}),saveSecretSet:e=>Z("/secrets",e),declineSecretRequest:(e,n)=>Z("/secrets/request/decline",{questionId:e,reason:n}),stopHost:(e,n)=>Z("/host/stop",{agentId:e,conversationId:n}),revokeHost:e=>Z("/host/revoke",{id:e}),decide:(e,n,s,r)=>Z(`/approvals/${encodeURIComponent(e)}/${n}`,s||r?{...s?{permissionScope:s}:{},...r?{ownerChoices:r}:{}}:void 0),setPaused:e=>Z("/pause",{paused:e}).then(Sc),service:()=>ke("/service"),runtimes:()=>ke("/runtimes"),removeEngine:()=>ys("/runtimes/onnx"),removeModel:e=>ys(`/runtimes/models/${encodeURIComponent(e)}`),serviceAction:e=>Z(`/service/${e}`),version:()=>ke("/version"),checkVersion:()=>Z("/version/check"),setVersionCheck:e=>wr("/version/check",{enabled:e}),tailscale:()=>ke("/access/tailscale"),setTailscale:e=>wr("/access/tailscale",e),access:()=>ke("/access"),cloudflareAccess:()=>ke("/access/cloudflare-access"),setCloudflareAccess:e=>wr("/access/cloudflare-access",e),testCloudflareAccess:e=>Z("/access/cloudflare-access/test",e),cloudflareSetup:()=>ke("/access/cloudflare-access/setup"),cloudflareZones:(e={})=>Z("/access/cloudflare-access/zones",e),startCloudflareSetup:e=>Z("/access/cloudflare-access/setup",e),stopCloudflareSetup:()=>Z("/access/cloudflare-access/setup/stop"),removeCloudflareSetup:(e={})=>Z("/access/cloudflare-access/setup/remove",e),forgetCloudflareToken:()=>Z("/access/cloudflare-access/setup/forget-token"),apiTokens:()=>ke("/api-tokens"),createApiToken:e=>Z("/api-tokens",{name:e}),revokeApiToken:e=>ys(`/api-tokens/${encodeURIComponent(e)}`),startUpgrade:e=>Z("/upgrade",e===void 0?{}:{version:e}),upgradeJob:e=>ke(`/upgrade/jobs/${encodeURIComponent(e)}`),backups:()=>ke("/backups"),startBackup:e=>Z("/backups",{encrypt:e}),verifyArchive:e=>Z("/backups/verify",{name:e}),restoreArchive:e=>Z("/backups/restore",e),restoreUpload:(e,n)=>hS("/backups/restore",e,n),backupJob:e=>ke(`/backups/jobs/${encodeURIComponent(e)}`),backupSchedule:()=>ke("/backups/schedule"),setBackupSchedule:e=>wr("/backups/schedule",e),backupPassphrase:()=>ke("/backups/passphrase"),revealBackupPassphrase:e=>Z("/backups/passphrase/reveal",e===void 0?{}:{pin:e}),cliTool:()=>ke("/system/cli"),installCliTool:()=>Z("/system/cli",{}),uninstallPlan:()=>ke("/system/uninstall"),uninstallBackup:e=>Z("/system/uninstall/backup",{token:e}),uninstallJob:e=>ke(`/system/uninstall/jobs/${encodeURIComponent(e)}`),uninstall:e=>Z("/system/uninstall",e),passphraseNotice:()=>ke("/backups/passphrase/notice"),acknowledgePassphrase:()=>Z("/backups/passphrase/notice",{}),setBackupPassphrase:e=>wr("/backups/passphrase",{passphrase:e}),plugins:()=>ke("/plugins"),market:(e=!1)=>ke(`/market${e?"?refresh=1":""}`),marketAssetUrl:e=>`/api/market/asset?url=${encodeURIComponent(e)}`,pluginFolders:e=>ke("/plugins/folders",e?{path:e}:{}),stagePlugin:e=>Z("/plugins/stage",{spec:e}),uploadPlugin:e=>Vw("/plugins/upload",e,"plugin.tgz"),pluginJob:e=>ke(`/plugins/jobs/${encodeURIComponent(e)}`),approveStaged:(e,n)=>Z(`/plugins/staged/${encodeURIComponent(e)}/approve`,n),rejectStaged:e=>Z(`/plugins/staged/${encodeURIComponent(e)}/reject`),openedStaged:e=>Z(`/plugins/staged/${encodeURIComponent(e)}/opened`),updatePlugin:(e,n,s)=>Z(`/plugins/${encodeURIComponent(e)}/update`,{...n?{version:n}:{},...s?{from:s}:{}}),setPluginEnabled:(e,n)=>Z(`/plugins/${encodeURIComponent(e)}/${n?"enable":"disable"}`,{}),uninstallPlugin:(e,n)=>Z(`/plugins/${encodeURIComponent(e)}/uninstall`,n),acceptPluginAgent:(e,n)=>Z(`/plugins/${encodeURIComponent(e)}/agents/${encodeURIComponent(n)}/accept`),recovery:()=>ke("/recovery"),leaveRecovery:e=>Z("/recovery/leave",e),firstRunRestore:(e,n)=>hS("/onboarding/restore",e,{passphrase:n}),setMissionEnabled:(e,n)=>Z(`/missions/${encodeURIComponent(e)}/enabled`,{enabled:n}),setMissionChrome:(e,n)=>Z(`/missions/${encodeURIComponent(e)}/browser`,{chrome:n}),runMission:e=>Z(`/missions/${encodeURIComponent(e)}/run`,{}),keepMission:e=>Z(`/missions/${encodeURIComponent(e)}/keep`,{}),answerStillUseful:(e,n)=>Z(`/missions/${encodeURIComponent(e)}/still-useful`,{answer:n}),setMisfirePolicy:(e,n,s)=>Z(`/missions/${encodeURIComponent(e)}/schedule`,{misfirePolicy:n,...s===void 0?{}:{deadlineMinutes:s}}),retryJob:e=>Z(`/jobs/${encodeURIComponent(e)}/retry`),cancelJob:e=>Z(`/jobs/${encodeURIComponent(e)}/cancel`),jobFailures:()=>ke("/jobs/failures"),dismissJobs:e=>Z("/jobs/dismiss",e).then(Sc),undismissJobs:e=>Z("/jobs/undismiss",{ids:e}).then(Sc),retryJobs:e=>Z("/jobs/retry",e).then(Sc),setDefaultAgent:e=>Z("/agents/default",{agentId:e}),agentTools:e=>ke(`/agents/${encodeURIComponent(e)}/tools`),agentFile:e=>ke(`/agents/${encodeURIComponent(e)}/file`),uploadAgentPicture:(e,n)=>{const s=new FormData;return s.append("file",n,n.name),Kh(`/agents/${encodeURIComponent(e)}/avatar`,s)},removeAgentPicture:e=>ys(`/agents/${encodeURIComponent(e)}/avatar`),updateAgentFile:(e,n)=>Z(`/agents/${encodeURIComponent(e)}/file`,n),setAgentEngine:(e,n)=>Z(`/agents/${encodeURIComponent(e)}/engine`,n),quiet:e=>Z("/quiet",{arg:e}),takeOffer:(e,n)=>Z(`/offers/${encodeURIComponent(e)}/take`,n?{conversationId:n}:{}),cancelReminder:e=>Z(`/reminders/${encodeURIComponent(e)}/cancel`,{reason:"cancelled from the dashboard"})},qw=e=>`buddi.chatReference.${e}`;function jU(e,n){try{sessionStorage.setItem(qw(e),JSON.stringify(n))}catch{}}function vU(e){try{const n=JSON.parse(sessionStorage.getItem(qw(e))??"null");return n&&typeof n.title=="string"&&typeof n.text=="string"&&Array.isArray(n.suggestions)&&n.suggestions.every(s=>typeof s=="string")?n:null}catch{return null}}function fS(e){try{sessionStorage.removeItem(qw(e))}catch{}}function yU(e,n){return n?`${e}
41
-
42
- Reference: ${n.title}
43
- ${n.text}`:e}const Kj="buddi.chatDraft";function fd(e,n){try{window.sessionStorage.setItem(Kj,JSON.stringify({agentId:e,text:n}))}catch{}}function wU(e){try{const n=window.sessionStorage.getItem(Kj);if(!n)return null;const s=JSON.parse(n);return s.agentId!==e||typeof s.text!="string"?null:(window.sessionStorage.removeItem(Kj),s.text)}catch{return null}}const bU=4e3,kU={ts:"TypeScript",tsx:"TypeScript",js:"JavaScript",jsx:"JavaScript",py:"Python",sh:"Shell",bash:"Shell",json:"JSON",sql:"SQL",md:"Markdown",html:"HTML",css:"CSS",go:"Go",rs:"Rust",yaml:"YAML",yml:"YAML"},wR=e=>kU[e.toLowerCase()]??e;function Qm(e,n){const s=e.lastIndexOf(`
44
- `,n-1)+1,r=e.indexOf(`
45
- `,n),a=r<0?e.length:r;return{start:s,end:a,text:e.slice(s,a)}}function Xc(e,n){return(e.slice(0,Qm(e,n).start).match(/^```/gm)??[]).length%2===1}function NU(e,n){const s=e.slice(0,n),r=/(^|[\s(])@([a-z0-9-]*)$/i.exec(s);return!r||Xc(e,n)?null:{start:n-r[2].length-1,query:r[2]}}function SU(e,n){const s=/^\/([a-z0-9-]*)$/i.exec(e.slice(0,n));return s?{query:s[1]}:null}function CU(e,n){return/^\/use @?[a-z0-9-]*$/i.test(e.slice(0,n))}function EU(e){const n=/^\/([a-z][a-z0-9-]*)(?:[ \t]+([\s\S]*))?$/i.exec(e.trim());return n?{name:n[1].toLowerCase(),arg:(n[2]??"").trim()}:null}function AU(e,n,s,r){const a=e.slice(n),i=a.startsWith(" ")?"":" ";return{value:`${e.slice(0,s)}@${r}${i}${a}`,caret:s+r.length+2}}const $U=/^(\s*)([-*]|\d+\.)( )(.*)$/;function Yw(e,n){if(Xc(e,n))return null;const s=$U.exec(Qm(e,n).text);return s?{indent:s[1],mark:s[2],body:s[4]}:null}function TU(e,n){const s=Yw(e,n);if(!s)return null;const r=Qm(e,n);if(s.body.trim()==="")return{value:e.slice(0,r.start)+e.slice(r.end),caret:r.start};const a=/\d/.test(s.mark)?`${parseInt(s.mark,10)+1}.`:s.mark,i=`
46
- ${s.indent}${a} `;return{value:e.slice(0,n)+i+e.slice(n),caret:n+i.length}}function RU(e,n,s){if(!Yw(e,n))return null;const r=Qm(e,n);if(!s)return{value:e.slice(0,r.start)+" "+e.slice(r.start),caret:n+2};const a=r.text.replace(/^ {1,2}/,""),i=r.text.length-a.length;return{value:e.slice(0,r.start)+a+e.slice(r.end),caret:Math.max(r.start,n-i)}}function IU(e){const n=e.replace(/\n$/,"").split(`
47
- `);return n.length<3||/^```/m.test(e)?!1:n.filter(r=>/[;{}()=<>]\s*$|^\s{2,}\S|^\t+\S|^\s*(const|let|var|function|def|import|from|export|return|if|for|while|class|SELECT|INSERT|UPDATE|<\w)/.test(r)).length/n.length>.5}function PU(e){return/\bdef \w+\(|^\s*import \w+$|^\s*from \w+ import /m.test(e)?"py":/^\s*(SELECT|INSERT|UPDATE|WITH)\b/im.test(e)?"sql":/^\s*[{[]/.test(e)&&/"\w+"\s*:/.test(e)&&!/;\s*$/m.test(e)?"json":/:\s*\w+[\]>]?\s*[=;),]|\binterface \w+|\bas const\b|\btype \w+ =/.test(e)?"ts":"js"}function MU(e,n,s,r){const i=`${n>0&&e[n-1]!==`
48
- `?`
49
- `:""}\`\`\`${r}
50
- ${s.replace(/\n$/,"")}
51
- \`\`\`
52
- `;return{value:e.slice(0,n)+i+e.slice(n),caret:n+i.length}}function OU(e){const n=e.replace(/```[\s\S]*?(```|$)/g," ").replace(/`[^`\n]*`/g," "),s=[];for(const r of n.matchAll(/(^|[\s(])@([a-z][a-z0-9-]*)/gi)){const a=r[2].toLowerCase();s.includes(a)||s.push(a)}return s}function bR(e){const n=/^@([a-z][a-z0-9-]*)\s*[:,]?[ \t]*([\s\S]*)$/i.exec(e.trim());return n?{handle:n[1].toLowerCase(),rest:n[2].trim()}:null}function kR(e){return e==="anthropic"||e==="openai"}function NR(e,n){var a,i;if(!e)return null;const s=e.credentialEnv&&(n!=null&&n.accounts.some(l=>l.id===e.credentialEnv))?e.credentialEnv:(i=(a=n==null?void 0:n.bindings)==null?void 0:a.find(l=>l.agentId===e.id))==null?void 0:i.accountId,r=s?n==null?void 0:n.accounts.find(l=>l.id===s):void 0;return(r==null?void 0:r.kind)??e.provider}const DU="Thinking is up to this model. What it writes while thinking is shown apart and kept out of the answer.";var LU=Object.defineProperty,FU=(e,n)=>LU(e,"name",{value:n,configurable:!0}),_U=d.createContext(void 0);function Jm(e){const n=d.useContext(_U);return e||n||"ltr"}FU(Jm,"useDirection");var zU=Object.defineProperty,Qw=(e,n)=>zU(e,"name",{value:n,configurable:!0}),nh=0,Kr=null;function UU(e){return Xm(),e.children}Qw(UU,"FocusGuards");function Xm(){d.useEffect(()=>{Kr||(Kr={start:Vj(),end:Vj()});const{start:e,end:n}=Kr;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==n&&document.body.insertAdjacentElement("beforeend",n),nh++,()=>{nh===1&&(Kr==null||Kr.start.remove(),Kr==null||Kr.end.remove(),Kr=null),nh=Math.max(0,nh-1)}},[])}Qw(Xm,"useFocusGuards");function Vj(){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}Qw(Vj,"createFocusGuard");var BU=Object.defineProperty,ds=(e,n)=>BU(e,"name",{value:n,configurable:!0}),bg="focusScope.autoFocusOnMount",kg="focusScope.autoFocusOnUnmount",mS={bubbles:!1,cancelable:!0},SR=d.forwardRef(ds(function(n,s){const{loop:r=!1,trapped:a=!1,onMountAutoFocus:i,onUnmountAutoFocus:l,...o}=n,[c,u]=d.useState(null),h=fs(i),m=fs(l),f=d.useRef(null),p=Ht(s,u),x=d.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;d.useEffect(()=>{if(a){let w=function(k){if(x.paused||!c)return;const N=k.target;c.contains(N)?f.current=N:ja(f.current,{select:!0})},v=function(k){if(x.paused||!c)return;const N=k.relatedTarget;N!==null&&(c.contains(N)||ja(f.current,{select:!0}))},j=function(k){if(document.activeElement===document.body)for(const b of k)b.removedNodes.length>0&&ja(c)};ds(w,"handleFocusIn"),ds(v,"handleFocusOut"),ds(j,"handleMutations"),document.addEventListener("focusin",w),document.addEventListener("focusout",v);const y=new MutationObserver(j);return c&&y.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",w),document.removeEventListener("focusout",v),y.disconnect()}}},[a,c,x.paused]),d.useEffect(()=>{if(c){pS.add(x);const w=document.activeElement;if(!c.contains(w)){const j=new CustomEvent(bg,mS);c.addEventListener(bg,h),c.dispatchEvent(j),j.defaultPrevented||(CR(RR(Jw(c)),{select:!0}),document.activeElement===w&&ja(c))}return()=>{c.removeEventListener(bg,h),setTimeout(()=>{const j=new CustomEvent(kg,mS);c.addEventListener(kg,m),c.dispatchEvent(j),j.defaultPrevented||ja(w??document.body,{select:!0}),c.removeEventListener(kg,m),pS.remove(x)},0)}}},[c,h,m,x]);const g=d.useCallback(w=>{if(!r&&!a||x.paused)return;const v=w.key==="Tab"&&!w.altKey&&!w.ctrlKey&&!w.metaKey,j=document.activeElement;if(v&&j){const y=w.currentTarget,[k,N]=ER(y);k&&N?!w.shiftKey&&j===N?(w.preventDefault(),r&&ja(k,{select:!0})):w.shiftKey&&j===k&&(w.preventDefault(),r&&ja(N,{select:!0})):j===y&&w.preventDefault()}},[r,a,x.paused]);return t.jsx(_t.div,{tabIndex:-1,...o,ref:p,onKeyDown:g})},"FocusScope"));function CR(e,{select:n=!1}={}){const s=document.activeElement;for(const r of e)if(ja(r,{select:n}),document.activeElement!==s)return}ds(CR,"focusFirst");function ER(e){const n=Jw(e),s=Gj(n,e),r=Gj(n.reverse(),e);return[s,r]}ds(ER,"getTabbableEdges");function Jw(e){const n=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:ds(r=>{const a=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||a?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;s.nextNode();)n.push(s.currentNode);return n}ds(Jw,"getTabbableCandidates");function Gj(e,n){const s=typeof n.checkVisibility=="function"&&n.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(s?!r.checkVisibility({checkVisibilityCSS:!0}):AR(r,{upTo:n})))return r}ds(Gj,"findVisible");function AR(e,{upTo:n}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(n!==void 0&&e===n)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}ds(AR,"isHidden");function $R(e){return e instanceof HTMLInputElement&&"select"in e}ds($R,"isSelectableInput");function ja(e,{select:n=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&$R(e)&&n&&e.select()}}ds(ja,"focus");var pS=TR();function TR(){let e=[];return{add(n){const s=e[0];n!==s&&(s==null||s.pause()),e=qj(e,n),e.unshift(n)},remove(n){var s;e=qj(e,n),(s=e[0])==null||s.resume()}}}ds(TR,"createFocusScopesStack");function qj(e,n){const s=[...e],r=s.indexOf(n);return r!==-1&&s.splice(r,1),s}ds(qj,"arrayRemove");function RR(e){return e.filter(n=>n.tagName!=="A")}ds(RR,"removeLinks");var WU=Object.defineProperty,Xw=(e,n)=>WU(e,"name",{value:n,configurable:!0}),Ng=!1;function IR(){const[e,n]=d.useState(Ng);return d.useEffect(()=>{Ng||(Ng=!0,n(!0))},[]),e}Xw(IR,"useIsHydrated");var PR=Ko[" useSyncExternalStore ".trim().toString()];function MR(){return()=>{}}Xw(MR,"subscribe");function OR(){return PR(MR,()=>!0,()=>!1)}Xw(OR,"useIsHydratedModern");var HU=typeof PR=="function"?OR:IR,KU=Object.defineProperty,kl=(e,n)=>KU(e,"name",{value:n,configurable:!0}),Sg="rovingFocusGroup.onEntryFocus",VU={bubbles:!1,cancelable:!0},Zm="RovingFocusGroup",[Yj,DR,GU]=Om(Zm),[qU,ep]=zr(Zm,[GU]),[YU,QU]=qU(Zm),JU=d.forwardRef(kl(function(n,s){return t.jsx(Yj.Provider,{scope:n.__scopeRovingFocusGroup,children:t.jsx(Yj.Slot,{scope:n.__scopeRovingFocusGroup,children:t.jsx(XU,{...n,ref:s})})})},"RovingFocusGroup")),XU=d.forwardRef(kl(function(n,s){const{__scopeRovingFocusGroup:r,orientation:a,loop:i=!1,dir:l,currentTabStopId:o,defaultCurrentTabStopId:c,onCurrentTabStopIdChange:u,onEntryFocus:h,preventScrollOnEntryFocus:m=!1,...f}=n,p=d.useRef(null),x=Ht(s,p),g=Jm(l),[w,v]=Ei({prop:o,defaultProp:c??null,onChange:u,caller:Zm}),[j,y]=d.useState(!1),k=fs(h),N=DR(r),b=d.useRef(!1),[S,C]=d.useState(0);return d.useEffect(()=>{const A=p.current;if(A)return A.addEventListener(Sg,k),()=>A.removeEventListener(Sg,k)},[k]),t.jsx(YU,{scope:r,orientation:a,dir:g,loop:i,currentTabStopId:w,onItemFocus:d.useCallback(A=>v(A),[v]),onItemShiftTab:d.useCallback(()=>y(!0),[]),onFocusableItemAdd:d.useCallback(()=>C(A=>A+1),[]),onFocusableItemRemove:d.useCallback(()=>C(A=>A-1),[]),children:t.jsx(_t.div,{tabIndex:j||S===0?-1:0,"data-orientation":a,...f,ref:x,style:{outline:"none",...n.style},onMouseDown:Ge(n.onMouseDown,()=>{b.current=!0}),onFocus:Ge(n.onFocus,A=>{const E=!b.current;if(A.target===A.currentTarget&&E&&!j){const R=new CustomEvent(Sg,VU);if(A.currentTarget.dispatchEvent(R),!R.defaultPrevented){const P=N().filter(L=>L.focusable),O=P.find(L=>L.active),I=P.find(L=>L.id===w),U=[O,I,...P].filter(Boolean).map(L=>L.ref.current);Zw(U,m)}}b.current=!1}),onBlur:Ge(n.onBlur,()=>y(!1))})})},"RovingFocusGroupImpl")),ZU="RovingFocusGroupItem",e6=d.forwardRef(kl(function(n,s){const{__scopeRovingFocusGroup:r,focusable:a=!0,active:i=!1,tabStopId:l,children:o,...c}=n,u=Tr(),h=l||u,m=QU(ZU,r),f=m.currentTabStopId===h,p=DR(r),{onFocusableItemAdd:x,onFocusableItemRemove:g,currentTabStopId:w}=m,v=HU();return As(()=>{if(!(!v||!a))return x(),()=>g()},[v,a,x,g]),d.useEffect(()=>{if(!(v||!a))return x(),()=>g()},[v,a,x,g]),t.jsx(Yj.ItemSlot,{scope:r,id:h,focusable:a,active:i,children:t.jsx(_t.span,{tabIndex:f?0:-1,"data-orientation":m.orientation,...c,ref:s,onMouseDown:Ge(n.onMouseDown,j=>{a?m.onItemFocus(h):j.preventDefault()}),onFocus:Ge(n.onFocus,()=>m.onItemFocus(h)),onKeyDown:Ge(n.onKeyDown,j=>{if(j.key==="Tab"&&j.shiftKey){m.onItemShiftTab();return}if(j.target!==j.currentTarget)return;const y=FR(j,m.orientation,m.dir);if(y!==void 0){if(j.metaKey||j.ctrlKey||j.altKey||j.shiftKey)return;j.preventDefault();let N=p().filter(b=>b.focusable).map(b=>b.ref.current);if(y==="last")N.reverse();else if(y==="prev"||y==="next"){y==="prev"&&N.reverse();const b=N.indexOf(j.currentTarget);N=m.loop?_R(N,b+1):N.slice(b+1)}setTimeout(()=>Zw(N))}}),children:typeof o=="function"?o({isCurrentTabStop:f,hasTabStop:w!=null}):o})})},"RovingFocusGroupItem")),t6={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function LR(e,n){return n!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}kl(LR,"getDirectionAwareKey");function FR(e,n,s){const r=LR(e.key,s);if(!(n==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(n==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return t6[r]}kl(FR,"getFocusIntent");function Zw(e,n=!1){const s=document.activeElement;for(const r of e)if(r===s||(r.focus({preventScroll:n}),document.activeElement!==s))return}kl(Zw,"focusFirst");function _R(e,n){return e.map((s,r)=>e[(n+r)%e.length])}kl(_R,"wrapArray");var zR=JU,UR=e6,n6=function(e){if(typeof document>"u")return null;var n=Array.isArray(e)?e[0]:e;return n.ownerDocument.body},Ol=new WeakMap,sh=new WeakMap,rh={},Cg=0,BR=function(e){return e&&(e.host||BR(e.parentNode))},s6=function(e,n){return n.map(function(s){if(e.contains(s))return s;var r=BR(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})},r6=function(e,n,s,r){var a=s6(n,Array.isArray(e)?e:[e]);rh[s]||(rh[s]=new WeakMap);var i=rh[s],l=[],o=new Set,c=new Set(a),u=function(m){!m||o.has(m)||(o.add(m),u(m.parentNode))};a.forEach(u);var h=function(m){!m||c.has(m)||Array.prototype.forEach.call(m.children,function(f){if(o.has(f))h(f);else try{var p=f.getAttribute(r),x=p!==null&&p!=="false",g=(Ol.get(f)||0)+1,w=(i.get(f)||0)+1;Ol.set(f,g),i.set(f,w),l.push(f),g===1&&x&&sh.set(f,!0),w===1&&f.setAttribute(s,"true"),x||f.setAttribute(r,"true")}catch(v){console.error("aria-hidden: cannot operate on ",f,v)}})};return h(n),o.clear(),Cg++,function(){l.forEach(function(m){var f=Ol.get(m)-1,p=i.get(m)-1;Ol.set(m,f),i.set(m,p),f||(sh.has(m)||m.removeAttribute(r),sh.delete(m)),p||m.removeAttribute(s)}),Cg--,Cg||(Ol=new WeakMap,Ol=new WeakMap,sh=new WeakMap,rh={})}},WR=function(e,n,s){s===void 0&&(s="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),a=n6(e);return a?(r.push.apply(r,Array.from(a.querySelectorAll("[aria-live], script"))),r6(r,a,s,"aria-hidden")):function(){return null}},Qr=function(){return Qr=Object.assign||function(n){for(var s,r=1,a=arguments.length;r<a;r++){s=arguments[r];for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(n[i]=s[i])}return n},Qr.apply(this,arguments)};function HR(e,n){var s={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(s[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,r=Object.getOwnPropertySymbols(e);a<r.length;a++)n.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(e,r[a])&&(s[r[a]]=e[r[a]]);return s}function a6(e,n,s){if(s||arguments.length===2)for(var r=0,a=n.length,i;r<a;r++)(i||!(r in n))&&(i||(i=Array.prototype.slice.call(n,0,r)),i[r]=n[r]);return e.concat(i||Array.prototype.slice.call(n))}var Gh="right-scroll-bar-position",qh="width-before-scroll-bar",i6="with-scroll-bars-hidden",l6="--removed-body-scroll-bar-size";function Eg(e,n){return typeof e=="function"?e(n):e&&(e.current=n),e}function o6(e,n){var s=d.useState(function(){return{value:e,callback:n,facade:{get current(){return s.value},set current(r){var a=s.value;a!==r&&(s.value=r,s.callback(r,a))}}}})[0];return s.callback=n,s.facade}var c6=typeof window<"u"?d.useLayoutEffect:d.useEffect,gS=new WeakMap;function u6(e,n){var s=o6(null,function(r){return e.forEach(function(a){return Eg(a,r)})});return c6(function(){var r=gS.get(s);if(r){var a=new Set(r),i=new Set(e),l=s.current;a.forEach(function(o){i.has(o)||Eg(o,null)}),i.forEach(function(o){a.has(o)||Eg(o,l)})}gS.set(s,e)},[e]),s}function d6(e){return e}function h6(e,n){n===void 0&&(n=d6);var s=[],r=!1,a={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return s.length?s[s.length-1]:e},useMedium:function(i){var l=n(i,r);return s.push(l),function(){s=s.filter(function(o){return o!==l})}},assignSyncMedium:function(i){for(r=!0;s.length;){var l=s;s=[],l.forEach(i)}s={push:function(o){return i(o)},filter:function(){return s}}},assignMedium:function(i){r=!0;var l=[];if(s.length){var o=s;s=[],o.forEach(i),l=s}var c=function(){var h=l;l=[],h.forEach(i)},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 a}function f6(e){e===void 0&&(e={});var n=h6(null);return n.options=Qr({async:!0,ssr:!1},e),n}var KR=function(e){var n=e.sideCar,s=HR(e,["sideCar"]);if(!n)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=n.read();if(!r)throw new Error("Sidecar medium not found");return d.createElement(r,Qr({},s))};KR.isSideCarExport=!0;function m6(e,n){return e.useMedium(n),KR}var VR=f6(),Ag=function(){},tp=d.forwardRef(function(e,n){var s=d.useRef(null),r=d.useState({onScrollCapture:Ag,onWheelCapture:Ag,onTouchMoveCapture:Ag}),a=r[0],i=r[1],l=e.forwardProps,o=e.children,c=e.className,u=e.removeScrollBar,h=e.enabled,m=e.shards,f=e.sideCar,p=e.noRelative,x=e.noIsolation,g=e.inert,w=e.allowPinchZoom,v=e.as,j=v===void 0?"div":v,y=e.gapMode,k=HR(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),N=f,b=u6([s,n]),S=Qr(Qr({},k),a);return d.createElement(d.Fragment,null,h&&d.createElement(N,{sideCar:VR,removeScrollBar:u,shards:m,noRelative:p,noIsolation:x,inert:g,setCallbacks:i,allowPinchZoom:!!w,lockRef:s,gapMode:y}),l?d.cloneElement(d.Children.only(o),Qr(Qr({},S),{ref:b})):d.createElement(j,Qr({},S,{className:c,ref:b}),o))});tp.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};tp.classNames={fullWidth:qh,zeroRight:Gh};var p6=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function g6(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var n=p6();return n&&e.setAttribute("nonce",n),e}function x6(e,n){e.styleSheet?e.styleSheet.cssText=n:e.appendChild(document.createTextNode(n))}function j6(e){var n=document.head||document.getElementsByTagName("head")[0];n.appendChild(e)}var v6=function(){var e=0,n=null;return{add:function(s){e==0&&(n=g6())&&(x6(n,s),j6(n)),e++},remove:function(){e--,!e&&n&&(n.parentNode&&n.parentNode.removeChild(n),n=null)}}},y6=function(){var e=v6();return function(n,s){d.useEffect(function(){return e.add(n),function(){e.remove()}},[n&&s])}},GR=function(){var e=y6(),n=function(s){var r=s.styles,a=s.dynamic;return e(r,a),null};return n},w6={left:0,top:0,right:0,gap:0},$g=function(e){return parseInt(e||"",10)||0},b6=function(e){var n=window.getComputedStyle(document.body),s=n[e==="padding"?"paddingLeft":"marginLeft"],r=n[e==="padding"?"paddingTop":"marginTop"],a=n[e==="padding"?"paddingRight":"marginRight"];return[$g(s),$g(r),$g(a)]},k6=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return w6;var n=b6(e),s=document.documentElement.clientWidth,r=window.innerWidth;return{left:n[0],top:n[1],right:n[2],gap:Math.max(0,r-s+n[2]-n[0])}},N6=GR(),xo="data-scroll-locked",S6=function(e,n,s,r){var a=e.left,i=e.top,l=e.right,o=e.gap;return s===void 0&&(s="margin"),`
53
- .`.concat(i6,` {
54
- overflow: hidden `).concat(r,`;
55
- padding-right: `).concat(o,"px ").concat(r,`;
56
- }
57
- body[`).concat(xo,`] {
58
- overflow: hidden `).concat(r,`;
59
- overscroll-behavior: contain;
60
- `).concat([n&&"position: relative ".concat(r,";"),s==="margin"&&`
61
- padding-left: `.concat(a,`px;
62
- padding-top: `).concat(i,`px;
63
- padding-right: `).concat(l,`px;
64
- margin-left:0;
65
- margin-top:0;
66
- margin-right: `).concat(o,"px ").concat(r,`;
67
- `),s==="padding"&&"padding-right: ".concat(o,"px ").concat(r,";")].filter(Boolean).join(""),`
68
- }
69
-
70
- .`).concat(Gh,` {
71
- right: `).concat(o,"px ").concat(r,`;
72
- }
73
-
74
- .`).concat(qh,` {
75
- margin-right: `).concat(o,"px ").concat(r,`;
76
- }
77
-
78
- .`).concat(Gh," .").concat(Gh,` {
79
- right: 0 `).concat(r,`;
80
- }
81
-
82
- .`).concat(qh," .").concat(qh,` {
83
- margin-right: 0 `).concat(r,`;
84
- }
85
-
86
- body[`).concat(xo,`] {
87
- `).concat(l6,": ").concat(o,`px;
88
- }
89
- `)},xS=function(){var e=parseInt(document.body.getAttribute(xo)||"0",10);return isFinite(e)?e:0},C6=function(){d.useEffect(function(){return document.body.setAttribute(xo,(xS()+1).toString()),function(){var e=xS()-1;e<=0?document.body.removeAttribute(xo):document.body.setAttribute(xo,e.toString())}},[])},E6=function(e){var n=e.noRelative,s=e.noImportant,r=e.gapMode,a=r===void 0?"margin":r;C6();var i=d.useMemo(function(){return k6(a)},[a]);return d.createElement(N6,{styles:S6(i,!n,a,s?"":"!important")})},Qj=!1;if(typeof window<"u")try{var ah=Object.defineProperty({},"passive",{get:function(){return Qj=!0,!0}});window.addEventListener("test",ah,ah),window.removeEventListener("test",ah,ah)}catch{Qj=!1}var Dl=Qj?{passive:!1}:!1,A6=function(e){return e.tagName==="TEXTAREA"},qR=function(e,n){if(!(e instanceof Element))return!1;var s=window.getComputedStyle(e);return s[n]!=="hidden"&&!(s.overflowY===s.overflowX&&!A6(e)&&s[n]==="visible")},$6=function(e){return qR(e,"overflowY")},T6=function(e){return qR(e,"overflowX")},jS=function(e,n){var s=n.ownerDocument,r=n;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var a=YR(e,r);if(a){var i=QR(e,r),l=i[1],o=i[2];if(l>o)return!0}r=r.parentNode}while(r&&r!==s.body);return!1},R6=function(e){var n=e.scrollTop,s=e.scrollHeight,r=e.clientHeight;return[n,s,r]},I6=function(e){var n=e.scrollLeft,s=e.scrollWidth,r=e.clientWidth;return[n,s,r]},YR=function(e,n){return e==="v"?$6(n):T6(n)},QR=function(e,n){return e==="v"?R6(n):I6(n)},P6=function(e,n){return e==="h"&&n==="rtl"?-1:1},M6=function(e,n,s,r,a){var i=P6(e,window.getComputedStyle(n).direction),l=i*r,o=s.target,c=n.contains(o),u=!1,h=l>0,m=0,f=0;do{if(!o)break;var p=QR(e,o),x=p[0],g=p[1],w=p[2],v=g-w-i*x;(x||v)&&YR(e,o)&&(m+=v,f+=x);var j=o.parentNode;o=j&&j.nodeType===Node.DOCUMENT_FRAGMENT_NODE?j.host:j}while(!c&&o!==document.body||c&&(n.contains(o)||n===o));return(h&&Math.abs(m)<1||!h&&Math.abs(f)<1)&&(u=!0),u},ih=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},vS=function(e){return[e.deltaX,e.deltaY]},yS=function(e){return e&&"current"in e?e.current:e},O6=function(e,n){return e[0]===n[0]&&e[1]===n[1]},D6=function(e){return`
90
- .block-interactivity-`.concat(e,` {pointer-events: none;}
91
- .allow-interactivity-`).concat(e,` {pointer-events: all;}
92
- `)},L6=0,Ll=[];function F6(e){var n=d.useRef([]),s=d.useRef([0,0]),r=d.useRef(),a=d.useState(L6++)[0],i=d.useState(GR)[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(a));var g=a6([e.lockRef.current],(e.shards||[]).map(yS),!0).filter(Boolean);return g.forEach(function(w){return w.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),g.forEach(function(w){return w.classList.remove("allow-interactivity-".concat(a))})}}},[e.inert,e.lockRef.current,e.shards]);var o=d.useCallback(function(g,w){if("touches"in g&&g.touches.length===2||g.type==="wheel"&&g.ctrlKey)return!l.current.allowPinchZoom;var v=ih(g),j=s.current,y="deltaX"in g?g.deltaX:j[0]-v[0],k="deltaY"in g?g.deltaY:j[1]-v[1],N,b=g.target,S=Math.abs(y)>Math.abs(k)?"h":"v";if("touches"in g&&S==="h"&&b.type==="range")return!1;var C=window.getSelection(),A=C&&C.anchorNode,E=A?A===b||A.contains(b):!1;if(E)return!1;var R=jS(S,b);if(!R)return!0;if(R?N=S:(N=S==="v"?"h":"v",R=jS(S,b)),!R)return!1;if(!r.current&&"changedTouches"in g&&(y||k)&&(r.current=N),!N)return!0;var P=r.current||N;return M6(P,w,g,P==="h"?y:k)},[]),c=d.useCallback(function(g){var w=g;if(!(!Ll.length||Ll[Ll.length-1]!==i)){var v="deltaY"in w?vS(w):ih(w),j=n.current.filter(function(N){return N.name===w.type&&(N.target===w.target||w.target===N.shadowParent)&&O6(N.delta,v)})[0];if(j&&j.should){w.cancelable&&w.preventDefault();return}if(!j){var y=(l.current.shards||[]).map(yS).filter(Boolean).filter(function(N){return N.contains(w.target)}),k=y.length>0?o(w,y[0]):!l.current.noIsolation;k&&w.cancelable&&w.preventDefault()}}},[]),u=d.useCallback(function(g,w,v,j){var y={name:g,delta:w,target:v,should:j,shadowParent:_6(v)};n.current.push(y),setTimeout(function(){n.current=n.current.filter(function(k){return k!==y})},1)},[]),h=d.useCallback(function(g){s.current=ih(g),r.current=void 0},[]),m=d.useCallback(function(g){u(g.type,vS(g),g.target,o(g,e.lockRef.current))},[]),f=d.useCallback(function(g){u(g.type,ih(g),g.target,o(g,e.lockRef.current))},[]);d.useEffect(function(){return Ll.push(i),e.setCallbacks({onScrollCapture:m,onWheelCapture:m,onTouchMoveCapture:f}),document.addEventListener("wheel",c,Dl),document.addEventListener("touchmove",c,Dl),document.addEventListener("touchstart",h,Dl),function(){Ll=Ll.filter(function(g){return g!==i}),document.removeEventListener("wheel",c,Dl),document.removeEventListener("touchmove",c,Dl),document.removeEventListener("touchstart",h,Dl)}},[]);var p=e.removeScrollBar,x=e.inert;return d.createElement(d.Fragment,null,x?d.createElement(i,{styles:D6(a)}):null,p?d.createElement(E6,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function _6(e){for(var n=null;e!==null;)e instanceof ShadowRoot&&(n=e.host,e=e.host),e=e.parentNode;return n}const z6=m6(VR,F6);var eb=d.forwardRef(function(e,n){return d.createElement(tp,Qr({},e,{ref:n,sideCar:z6}))});eb.classNames=tp.classNames;var U6=Object.defineProperty,It=(e,n)=>U6(e,"name",{value:n,configurable:!0}),Jj=["Enter"," "],B6=["ArrowDown","PageUp","Home"],JR=["ArrowUp","PageDown","End"],W6=[...B6,...JR],H6={ltr:[...Jj,"ArrowRight"],rtl:[...Jj,"ArrowLeft"]},K6={ltr:["ArrowLeft"],rtl:["ArrowRight"]},np="Menu",[Ou,V6,G6]=Om(np),[Nl,XR]=zr(np,[G6,Vm,ep]),sp=Vm(),ZR=ep(),[eI,$i]=Nl(np),[q6,md]=Nl(np),Y6=It(e=>{const{__scopeMenu:n,open:s=!1,children:r,dir:a,onOpenChange:i,modal:l=!0}=e,o=sp(n),[c,u]=d.useState(null),h=d.useRef(!1),m=fs(i),f=Jm(a);return d.useEffect(()=>{const p=It(()=>{h.current=!0,document.addEventListener("pointerdown",x,{capture:!0,once:!0}),document.addEventListener("pointermove",x,{capture:!0,once:!0})},"handleKeyDown"),x=It(()=>h.current=!1,"handlePointer");return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",x,{capture:!0}),document.removeEventListener("pointermove",x,{capture:!0})}},[]),d.useEffect(()=>{if(!s)return;const p=It(()=>m(!1),"handleBlur");return window.addEventListener("blur",p),()=>window.removeEventListener("blur",p)},[s,m]),t.jsx(_w,{...o,children:t.jsx(eI,{scope:n,open:s,onOpenChange:m,content:c,onContentChange:u,children:t.jsx(q6,{scope:n,onClose:d.useCallback(()=>m(!1),[m]),isUsingKeyboardRef:h,dir:f,modal:l,children:r})})})},"Menu"),tI=d.forwardRef(It(function(n,s){const{__scopeMenu:r,...a}=n,i=sp(r);return t.jsx(lR,{...i,...a,ref:s})},"MenuAnchor")),nI="MenuPortal",[Q6,sI]=Nl(nI,{forceMount:void 0}),J6=It(e=>{const{__scopeMenu:n,forceMount:s,children:r,container:a}=e,i=$i(nI,n);return t.jsx(Q6,{scope:n,forceMount:s,children:t.jsx(ca,{present:s||i.open,children:t.jsx(Fm,{asChild:!0,container:a,children:r})})})},"MenuPortal"),Rr="MenuContent",[X6,tb]=Nl(Rr),Z6=d.forwardRef(It(function(n,s){const r=sI(Rr,n.__scopeMenu),{forceMount:a=r.forceMount,...i}=n,l=$i(Rr,n.__scopeMenu),o=md(Rr,n.__scopeMenu);return t.jsx(Ou.Provider,{scope:n.__scopeMenu,children:t.jsx(ca,{present:a||l.open,children:t.jsx(Ou.Slot,{scope:n.__scopeMenu,children:o.modal?t.jsx(eB,{...i,ref:s}):t.jsx(tB,{...i,ref:s})})})})},"MenuContent")),eB=d.forwardRef(It(function(n,s){const r=$i(Rr,n.__scopeMenu),a=d.useRef(null),i=Ht(s,a);return d.useEffect(()=>{const l=a.current;if(l)return WR(l)},[]),t.jsx(nb,{...n,ref:i,trapFocus:r.open,disableOutsidePointerEvents:r.open,disableOutsideScroll:!0,onFocusOutside:Ge(n.onFocusOutside,l=>l.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentModal")),tB=d.forwardRef(It(function(n,s){const r=$i(Rr,n.__scopeMenu);return t.jsx(nb,{...n,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentNonModal")),nB=gi("MenuContent.ScrollLock"),nb=d.forwardRef(It(function(n,s){const{__scopeMenu:r,loop:a=!1,trapFocus:i,onOpenAutoFocus:l,onCloseAutoFocus:o,disableOutsidePointerEvents:c,onEntryFocus:u,onEscapeKeyDown:h,onPointerDownOutside:m,onFocusOutside:f,onInteractOutside:p,onDismiss:x,disableOutsideScroll:g,...w}=n,v=$i(Rr,r),j=md(Rr,r),y=sp(r),k=ZR(r),N=V6(r),[b,S]=d.useState(null),C=d.useRef(null),A=Ht(s,C,v.onContentChange),E=d.useRef(0),R=d.useRef(""),P=d.useRef(0),O=d.useRef(null),I=d.useRef("right"),F=d.useRef(0),U=g?eb:d.Fragment,L=g?{as:nB,allowPinchZoom:!0}:void 0,M=It(D=>{var H,de;const K=R.current+D,B=N().filter(ge=>!ge.disabled),se=document.activeElement,W=(H=B.find(ge=>ge.ref.current===se))==null?void 0:H.textValue,xe=B.map(ge=>ge.textValue),me=fI(xe,K,W),ie=(de=B.find(ge=>ge.textValue===me))==null?void 0:de.ref.current;It(function ge(Ue){R.current=Ue,window.clearTimeout(E.current),Ue!==""&&(E.current=window.setTimeout(()=>ge(""),1e3))},"updateSearch")(K),ie&&setTimeout(()=>ie.focus())},"handleTypeaheadSearch");d.useEffect(()=>()=>window.clearTimeout(E.current),[]),Xm();const z=d.useCallback(D=>{var B,se;return I.current===((B=O.current)==null?void 0:B.side)&&pI(D,(se=O.current)==null?void 0:se.area)},[]);return t.jsx(X6,{scope:r,searchRef:R,onItemEnter:d.useCallback(D=>{z(D)&&D.preventDefault()},[z]),onItemLeave:d.useCallback(D=>{var K;z(D)||((K=C.current)==null||K.focus(),S(null))},[z]),onTriggerLeave:d.useCallback(D=>{z(D)&&D.preventDefault()},[z]),pointerGraceTimerRef:P,onPointerGraceIntentChange:d.useCallback(D=>{O.current=D},[]),children:t.jsx(U,{...L,children:t.jsx(SR,{asChild:!0,trapped:i,onMountAutoFocus:Ge(l,D=>{var K;D.preventDefault(),(K=C.current)==null||K.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:t.jsx(Lm,{asChild:!0,disableOutsidePointerEvents:c,onEscapeKeyDown:h,onPointerDownOutside:m,onFocusOutside:f,onInteractOutside:p,onDismiss:x,children:t.jsx(zR,{asChild:!0,...k,dir:j.dir,orientation:"vertical",loop:a,currentTabStopId:b,onCurrentTabStopIdChange:S,onEntryFocus:Ge(u,D=>{j.isUsingKeyboardRef.current||D.preventDefault()}),preventScrollOnEntryFocus:!0,children:t.jsx(oR,{role:"menu","aria-orientation":"vertical","data-state":sb(v.open),"data-radix-menu-content":"",dir:j.dir,...y,...w,ref:A,style:{outline:"none",...w.style},onKeyDown:Ge(w.onKeyDown,D=>{const B=D.target.closest("[data-radix-menu-content]")===D.currentTarget,se=D.ctrlKey||D.altKey||D.metaKey,W=D.key.length===1;B&&(D.key==="Tab"&&D.preventDefault(),!se&&W&&M(D.key));const xe=C.current;if(D.target!==xe||!W6.includes(D.key))return;D.preventDefault();const ie=N().filter(H=>!H.disabled).map(H=>H.ref.current);JR.includes(D.key)&&ie.reverse(),dI(ie)}),onBlur:Ge(n.onBlur,D=>{D.currentTarget.contains(D.target)||(window.clearTimeout(E.current),R.current="")}),onPointerMove:Ge(n.onPointerMove,To(D=>{const K=D.target,B=F.current!==D.clientX;if(D.currentTarget.contains(K)&&B){const se=D.clientX>F.current?"right":"left";I.current=se,F.current=D.clientX}}))})})})})})})},"MenuContentImpl")),rI=d.forwardRef(It(function(n,s){const{__scopeMenu:r,...a}=n;return t.jsx(_t.div,{role:"group",...a,ref:s})},"MenuGroup")),sB=d.forwardRef(It(function(n,s){const{__scopeMenu:r,...a}=n;return t.jsx(_t.div,{...a,ref:s})},"MenuLabel")),Xj="MenuItem",wS="menu.itemSelect",aI=d.forwardRef(It(function(n,s){const{disabled:r=!1,onSelect:a,...i}=n,l=d.useRef(null),o=md(Xj,n.__scopeMenu),c=tb(Xj,n.__scopeMenu),u=Ht(s,l),h=d.useRef(!1),m=It(()=>{const f=l.current;if(!r&&f){const p=new CustomEvent(wS,{bubbles:!0,cancelable:!0});f.addEventListener(wS,x=>a==null?void 0:a(x),{once:!0}),Dm(f,p),p.defaultPrevented?h.current=!1:o.onClose()}},"handleSelect");return t.jsx(iI,{...i,ref:u,disabled:r,onClick:Ge(n.onClick,m),onPointerDown:f=>{var p;(p=n.onPointerDown)==null||p.call(n,f),h.current=!0},onPointerUp:Ge(n.onPointerUp,f=>{var p;h.current||(p=f.currentTarget)==null||p.click()}),onKeyDown:Ge(n.onKeyDown,f=>{r||f.target!==f.currentTarget||c.searchRef.current!==""&&f.key===" "||Jj.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})},"MenuItem")),iI=d.forwardRef(It(function(n,s){const{__scopeMenu:r,disabled:a=!1,textValue:i,...l}=n,o=tb(Xj,r),c=ZR(r),u=d.useRef(null),h=Ht(s,u),[m,f]=d.useState(!1),[p,x]=d.useState("");return d.useEffect(()=>{const g=u.current;g&&x((g.textContent??"").trim())},[l.children]),t.jsx(Ou.ItemSlot,{scope:r,disabled:a,textValue:i??p,children:t.jsx(UR,{asChild:!0,...c,focusable:!a,children:t.jsx(_t.div,{role:"menuitem","data-highlighted":m?"":void 0,"aria-disabled":a||void 0,"data-disabled":a?"":void 0,...l,ref:h,onPointerMove:Ge(n.onPointerMove,To(g=>{a?o.onItemLeave(g):(o.onItemEnter(g),g.defaultPrevented||g.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Ge(n.onPointerLeave,To(g=>o.onItemLeave(g))),onFocus:Ge(n.onFocus,()=>f(!0)),onBlur:Ge(n.onBlur,()=>f(!1))})})})},"MenuItemImpl")),rB="MenuRadioGroup",[aB,iB]=Nl(rB,{value:void 0,onValueChange:It(()=>{},"onValueChange")}),lB=d.forwardRef(It(function(n,s){const{value:r,onValueChange:a,...i}=n,l=fs(a);return t.jsx(aB,{scope:n.__scopeMenu,value:r,onValueChange:l,children:t.jsx(rI,{...i,ref:s})})},"MenuRadioGroup")),oB="MenuRadioItem",cB=d.forwardRef(It(function(n,s){const{value:r,...a}=n,i=iB(oB,n.__scopeMenu),l=r===i.value;return t.jsx(dB,{scope:n.__scopeMenu,checked:l,children:t.jsx(aI,{role:"menuitemradio","aria-checked":l,...a,ref:s,"data-state":uI(l),onSelect:Ge(a.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,r)},{checkForDefaultPrevented:!1})})})},"MenuRadioItem")),uB="MenuItemIndicator",[dB,gue]=Nl(uB,{checked:!1}),hB=d.forwardRef(It(function(n,s){const{__scopeMenu:r,...a}=n;return t.jsx(_t.div,{role:"separator","aria-orientation":"horizontal",...a,ref:s})},"MenuSeparator")),lI="MenuSub",[fB,oI]=Nl(lI),mB=It(e=>{const{__scopeMenu:n,children:s,open:r=!1,onOpenChange:a}=e,i=$i(lI,n),l=sp(n),[o,c]=d.useState(null),[u,h]=d.useState(null),m=fs(a);return d.useEffect(()=>(i.open===!1&&m(!1),()=>m(!1)),[i.open,m]),t.jsx(_w,{...l,children:t.jsx(eI,{scope:n,open:r,onOpenChange:m,content:u,onContentChange:h,children:t.jsx(fB,{scope:n,contentId:Tr(),triggerId:Tr(),trigger:o,onTriggerChange:c,children:s})})})},"MenuSub"),lh="MenuSubTrigger",pB=d.forwardRef(It(function(n,s){const r=$i(lh,n.__scopeMenu),a=md(lh,n.__scopeMenu),i=oI(lh,n.__scopeMenu),l=tb(lh,n.__scopeMenu),o=d.useRef(null),{pointerGraceTimerRef:c,onPointerGraceIntentChange:u}=l,h={__scopeMenu:n.__scopeMenu},m=d.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);d.useEffect(()=>m,[m]),d.useEffect(()=>{const p=c.current;return()=>{window.clearTimeout(p),u(null)}},[c,u]);const f=Ht(s,i.onTriggerChange);return t.jsx(tI,{asChild:!0,...h,children:t.jsx(iI,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":r.open,"aria-controls":r.open?i.contentId:void 0,"data-state":sb(r.open),...n,ref:f,onClick:p=>{var x;(x=n.onClick)==null||x.call(n,p),!(n.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),r.open||r.onOpenChange(!0))},onPointerMove:Ge(n.onPointerMove,To(p=>{l.onItemEnter(p),!p.defaultPrevented&&!n.disabled&&!r.open&&!o.current&&(l.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{r.onOpenChange(!0),m()},100))})),onPointerLeave:Ge(n.onPointerLeave,To(p=>{var g,w;m();const x=(g=r.content)==null?void 0:g.getBoundingClientRect();if(x){const v=(w=r.content)==null?void 0:w.dataset.side,j=v==="right",y=j?-5:5,k=x[j?"left":"right"],N=x[j?"right":"left"];l.onPointerGraceIntentChange({area:[{x:p.clientX+y,y:p.clientY},{x:k,y:x.top},{x:N,y:x.top},{x:N,y:x.bottom},{x:k,y:x.bottom}],side:v}),window.clearTimeout(c.current),c.current=window.setTimeout(()=>l.onPointerGraceIntentChange(null),300)}else{if(l.onTriggerLeave(p),p.defaultPrevented)return;l.onPointerGraceIntentChange(null)}})),onKeyDown:Ge(n.onKeyDown,p=>{var g;n.disabled||p.target!==p.currentTarget||l.searchRef.current!==""&&p.key===" "||H6[a.dir].includes(p.key)&&(r.onOpenChange(!0),(g=r.content)==null||g.focus(),p.preventDefault())})})})},"MenuSubTrigger")),gB="MenuSubContent",xB=d.forwardRef(It(function(n,s){const r=sI(Rr,n.__scopeMenu),{forceMount:a=r.forceMount,align:i="start",...l}=n,o=$i(Rr,n.__scopeMenu),c=md(Rr,n.__scopeMenu),u=oI(gB,n.__scopeMenu),h=d.useRef(null),m=Ht(s,h);return t.jsx(Ou.Provider,{scope:n.__scopeMenu,children:t.jsx(ca,{present:a||o.open,children:t.jsx(Ou.Slot,{scope:n.__scopeMenu,children:t.jsx(nb,{id:u.contentId,"aria-labelledby":u.triggerId,...l,ref:m,align:i,side:c.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:f=>{var p;c.isUsingKeyboardRef.current&&((p=h.current)==null||p.focus()),f.preventDefault()},onCloseAutoFocus:f=>f.preventDefault(),onFocusOutside:Ge(n.onFocusOutside,f=>{f.target!==u.trigger&&o.onOpenChange(!1)}),onEscapeKeyDown:Ge(n.onEscapeKeyDown,f=>{c.onClose(),f.preventDefault()}),onKeyDown:Ge(n.onKeyDown,f=>{var g;const p=f.currentTarget.contains(f.target),x=K6[c.dir].includes(f.key);p&&x&&(o.onOpenChange(!1),(g=u.trigger)==null||g.focus(),f.preventDefault())})})})})})},"MenuSubContent"));function sb(e){return e?"open":"closed"}It(sb,"getOpenState");function cI(e){return e==="indeterminate"}It(cI,"isIndeterminate");function uI(e){return cI(e)?"indeterminate":e?"checked":"unchecked"}It(uI,"getCheckedState");function dI(e){const n=document.activeElement;for(const s of e)if(s===n||(s.focus(),document.activeElement!==n))return}It(dI,"focusFirst");function hI(e,n){return e.map((s,r)=>e[(n+r)%e.length])}It(hI,"wrapArray");function fI(e,n,s){const a=n.length>1&&Array.from(n).every(u=>u===n[0])?n[0]:n,i=s?e.indexOf(s):-1;let l=hI(e,Math.max(i,0));a.length===1&&(l=l.filter(u=>u!==s));const c=l.find(u=>u.toLowerCase().startsWith(a.toLowerCase()));return c!==s?c:void 0}It(fI,"getNextMatch");function mI(e,n){const{x:s,y:r}=e;let a=!1;for(let i=0,l=n.length-1;i<n.length;l=i++){const o=n[i],c=n[l],u=o.x,h=o.y,m=c.x,f=c.y;h>r!=f>r&&s<(m-u)*(r-h)/(f-h)+u&&(a=!a)}return a}It(mI,"isPointInPolygon");function pI(e,n){if(!n)return!1;const s={x:e.clientX,y:e.clientY};return mI(s,n)}It(pI,"isPointerInGraceArea");function To(e){return n=>n.pointerType==="mouse"?e(n):void 0}It(To,"whenMouse");var jB=Y6,vB=tI,yB=J6,wB=Z6,bB=rI,kB=sB,NB=aI,SB=lB,CB=cB,EB=hB,AB=mB,$B=pB,TB=xB,RB=Object.defineProperty,Qs=(e,n)=>RB(e,"name",{value:n,configurable:!0}),rb="DropdownMenu",[IB,xue]=zr(rb,[XR]),Js=XR(),[PB,gI]=IB(rb),MB=Qs(e=>{const{__scopeDropdownMenu:n,children:s,dir:r,open:a,defaultOpen:i,onOpenChange:l,modal:o=!0}=e,c=Js(n),u=d.useRef(null),[h,m]=Ei({prop:a,defaultProp:i??!1,onChange:l,caller:rb});return t.jsx(PB,{scope:n,triggerId:Tr(),triggerRef:u,contentId:Tr(),open:h,onOpenChange:m,onOpenToggle:d.useCallback(()=>m(f=>!f),[m]),modal:o,children:t.jsx(jB,{...c,open:h,onOpenChange:m,dir:r,modal:o,children:s})})},"DropdownMenu"),OB="DropdownMenuTrigger",DB=d.forwardRef(Qs(function(n,s){const{__scopeDropdownMenu:r,disabled:a=!1,...i}=n,l=gI(OB,r),o=Js(r),c=Ht(s,l.triggerRef);return t.jsx(vB,{asChild:!0,...o,children:t.jsx(_t.button,{type:"button",id:l.triggerId,"aria-haspopup":"menu","aria-expanded":l.open,"aria-controls":l.open?l.contentId:void 0,"data-state":l.open?"open":"closed","data-disabled":a?"":void 0,disabled:a,...i,ref:c,onPointerDown:Ge(n.onPointerDown,u=>{!a&&u.button===0&&u.ctrlKey===!1&&(l.onOpenToggle(),l.open||u.preventDefault())}),onKeyDown:Ge(n.onKeyDown,u=>{a||(["Enter"," "].includes(u.key)&&l.onOpenToggle(),u.key==="ArrowDown"&&l.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(u.key)&&u.preventDefault())})})})},"DropdownMenuTrigger")),LB=Qs(e=>{const{__scopeDropdownMenu:n,...s}=e,r=Js(n);return t.jsx(yB,{...r,...s})},"DropdownMenuPortal"),FB="DropdownMenuContent",_B=d.forwardRef(Qs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=gI(FB,r),l=Js(r),o=d.useRef(!1);return t.jsx(wB,{id:i.contentId,"aria-labelledby":i.triggerId,...l,...a,ref:s,onCloseAutoFocus:Ge(n.onCloseAutoFocus,c=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,c.preventDefault()}),onInteractOutside:Ge(n.onInteractOutside,c=>{const u=c.detail.originalEvent,h=u.button===0&&u.ctrlKey===!0,m=u.button===2||h;(!i.modal||m)&&(o.current=!0)}),style:{...n.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})},"DropdownMenuContent")),zB=d.forwardRef(Qs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Js(r);return t.jsx(bB,{...i,...a,ref:s})},"DropdownMenuGroup")),UB=d.forwardRef(Qs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Js(r);return t.jsx(kB,{...i,...a,ref:s})},"DropdownMenuLabel")),BB=d.forwardRef(Qs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Js(r);return t.jsx(NB,{...i,...a,ref:s})},"DropdownMenuItem")),WB=d.forwardRef(Qs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Js(r);return t.jsx(SB,{...i,...a,ref:s})},"DropdownMenuRadioGroup")),HB=d.forwardRef(Qs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Js(r);return t.jsx(CB,{...i,...a,ref:s})},"DropdownMenuRadioItem")),KB=d.forwardRef(Qs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Js(r);return t.jsx(EB,{...i,...a,ref:s})},"DropdownMenuSeparator")),VB=Qs(e=>{const{__scopeDropdownMenu:n,children:s,open:r,onOpenChange:a,defaultOpen:i}=e,l=Js(n),[o,c]=Ei({prop:r,defaultProp:i??!1,onChange:a,caller:"DropdownMenuSub"});return t.jsx(AB,{...l,open:o,onOpenChange:c,children:s})},"DropdownMenuSub"),GB=d.forwardRef(Qs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Js(r);return t.jsx($B,{...i,...a,ref:s})},"DropdownMenuSubTrigger")),qB=d.forwardRef(Qs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Js(r);return t.jsx(TB,{...i,...a,ref:s,style:{...n.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})},"DropdownMenuSubContent")),pd=MB,gd=DB,tc=LB,xd=_B,ab=zB,hl=UB,bs=BB,YB=WB,QB=HB,Xr=KB,JB=VB,XB=GB,ZB=qB,e5=Object.defineProperty,nc=(e,n)=>e5(e,"name",{value:n,configurable:!0}),ib="Tabs",[t5,jue]=zr(ib,[ep]),xI=ep(),[n5,lb]=t5(ib),s5=d.forwardRef(nc(function(n,s){const{__scopeTabs:r,value:a,onValueChange:i,defaultValue:l,orientation:o="horizontal",dir:c,activationMode:u="automatic",...h}=n,m=Jm(c),[f,p]=Ei({prop:a,onChange:i,defaultProp:l??"",caller:ib});return t.jsx(n5,{scope:r,baseId:Tr(),value:f,onValueChange:p,orientation:o,dir:m,activationMode:u,children:t.jsx(_t.div,{dir:m,"data-orientation":o,...h,ref:s})})},"Tabs")),r5="TabsList",a5=d.forwardRef(nc(function(n,s){const{__scopeTabs:r,loop:a=!0,...i}=n,l=lb(r5,r),o=xI(r);return t.jsx(zR,{asChild:!0,...o,orientation:l.orientation,dir:l.dir,loop:a,children:t.jsx(_t.div,{role:"tablist","aria-orientation":l.orientation,...i,ref:s})})},"TabsList")),i5="TabsTrigger",l5=d.forwardRef(nc(function(n,s){const{__scopeTabs:r,value:a,disabled:i=!1,...l}=n,o=lb(i5,r),c=xI(r),u=ob(o.baseId,a),h=cb(o.baseId,a),m=a===o.value;return t.jsx(UR,{asChild:!0,...c,focusable:!i,active:m,children:t.jsx(_t.button,{type:"button",role:"tab","aria-selected":m,"aria-controls":h,"data-state":m?"active":"inactive","data-disabled":i?"":void 0,disabled:i,id:u,...l,ref:s,onMouseDown:Ge(n.onMouseDown,f=>{!i&&f.button===0&&f.ctrlKey===!1?o.onValueChange(a):f.preventDefault()}),onKeyDown:Ge(n.onKeyDown,f=>{i||f.target!==f.currentTarget||[" ","Enter"].includes(f.key)&&o.onValueChange(a)}),onFocus:Ge(n.onFocus,()=>{const f=o.activationMode!=="manual";!m&&!i&&f&&o.onValueChange(a)})})})},"TabsTrigger")),o5="TabsContent",c5=d.forwardRef(nc(function(n,s){const{__scopeTabs:r,value:a,forceMount:i,children:l,...o}=n,c=lb(o5,r),u=ob(c.baseId,a),h=cb(c.baseId,a),m=a===c.value,f=d.useRef(m);return d.useEffect(()=>{const p=requestAnimationFrame(()=>f.current=!1);return()=>cancelAnimationFrame(p)},[]),t.jsx(ca,{present:i||m,children:({present:p})=>t.jsx(_t.div,{"data-state":m?"active":"inactive","data-orientation":c.orientation,role:"tabpanel","aria-labelledby":u,hidden:!p,id:h,tabIndex:0,...o,ref:s,style:{...n.style,animationDuration:f.current?"0s":void 0},children:p&&l})})},"TabsContent"));function ob(e,n){return`${e}-trigger-${n}`}nc(ob,"makeTriggerId");function cb(e,n){return`${e}-content-${n}`}nc(cb,"makeContentId");var u5=s5,d5=a5,h5=l5,f5=c5;const m5=/^[a-z0-9](?:[a-z0-9._-]{0,94}[a-z0-9])?$/,p5=/^[a-z][a-z0-9_-]{0,63}$/;function Sl(e,n,s=64){return!p5.test(e)||typeof n!="string"||!m5.test(n)||n.includes("..")?null:`/api/plugin-assets/${e}/${n}?size=${s}`}function jI(e){return typeof e=="string"&&/^\/api\/plugin-assets\/[a-z][a-z0-9_-]{0,63}\/[a-z0-9._-]+(\?size=(64|128|768))?$/.test(e)}function g5(e){var n,s;return((s=(n=e.match(/[\p{L}\p{N}]/u))==null?void 0:n[0])==null?void 0:s.toUpperCase())??"?"}function Cl({src:e,label:n,className:s}){const[r,a]=d.useState(!1),i=e!==null&&jI(e)&&!r;return t.jsx("span",{className:["pl-logo",s].filter(Boolean).join(" "),"data-letter":i?void 0:"true","aria-hidden":"true",children:i?t.jsx("img",{src:e,alt:"",loading:"lazy",decoding:"async",onError:()=>a(!0)}):g5(n)})}var x5=Object.defineProperty,gr=(e,n)=>x5(e,"name",{value:n,configurable:!0}),ub="Dialog",[vI,vue]=zr(ub),[j5,ua]=vI(ub),rp=gr(e=>{const{__scopeDialog:n,children:s,open:r,defaultOpen:a,onOpenChange:i,modal:l=!0}=e,o=d.useRef(null),c=d.useRef(null),[u,h]=Ei({prop:r,defaultProp:a??!1,onChange:i,caller:ub}),[m,f]=d.useState(0),[p,x]=d.useState(0);return t.jsx(j5,{scope:n,triggerRef:o,contentRef:c,contentId:Tr(),titleId:Tr(),descriptionId:Tr(),titlePresent:m>0,descriptionPresent:p>0,setTitleCount:f,setDescriptionCount:x,open:u,onOpenChange:h,onOpenToggle:d.useCallback(()=>h(g=>!g),[h]),modal:l,children:s})},"Dialog"),v5="DialogTrigger",y5=d.forwardRef(gr(function(n,s){const{__scopeDialog:r,...a}=n,i=ua(v5,r),l=Ht(s,i.triggerRef);return t.jsx(_t.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":op(i.open),...a,ref:l,onClick:Ge(n.onClick,i.onOpenToggle)})},"DialogTrigger")),yI="DialogPortal",[w5,wI]=vI(yI,{forceMount:void 0}),ap=gr(e=>{const{__scopeDialog:n,forceMount:s,children:r,container:a}=e,i=ua(yI,n);return t.jsx(w5,{scope:n,forceMount:s,children:d.Children.map(r,l=>t.jsx(ca,{present:s||i.open,children:t.jsx(Fm,{asChild:!0,container:a,children:l})}))})},"DialogPortal"),Zj="DialogOverlay",db=d.forwardRef(gr(function(n,s){const r=wI(Zj,n.__scopeDialog),{forceMount:a=r.forceMount,...i}=n,l=ua(Zj,n.__scopeDialog);return l.modal?t.jsx(ca,{present:a||l.open,children:t.jsx(k5,{...i,ref:s})}):null},"DialogOverlay")),b5=gi("DialogOverlay.RemoveScroll"),k5=d.forwardRef(gr(function(n,s){const{__scopeDialog:r,...a}=n,i=ua(Zj,r),l=ET(),o=Ht(s,l);return t.jsx(eb,{as:b5,allowPinchZoom:!0,shards:[i.contentRef],children:t.jsx(_t.div,{"data-state":op(i.open),...a,ref:o,style:{pointerEvents:"auto",...a.style}})})},"DialogOverlayImpl")),Du="DialogContent",ip=d.forwardRef(gr(function(n,s){const r=wI(Du,n.__scopeDialog),{forceMount:a=r.forceMount,...i}=n,l=ua(Du,n.__scopeDialog);return t.jsx(ca,{present:a||l.open,children:l.modal?t.jsx(N5,{...i,ref:s}):t.jsx(S5,{...i,ref:s})})},"DialogContent")),N5=d.forwardRef(gr(function(n,s){const r=ua(Du,n.__scopeDialog),a=d.useRef(null),i=Ht(s,r.contentRef,a);return d.useEffect(()=>{const l=a.current;if(l)return WR(l)},[]),t.jsx(bI,{...n,ref:i,trapFocus:r.open,disableOutsidePointerEvents:r.open,onCloseAutoFocus:Ge(n.onCloseAutoFocus,l=>{var o;l.preventDefault(),(o=r.triggerRef.current)==null||o.focus()}),onPointerDownOutside:Ge(n.onPointerDownOutside,l=>{const o=l.detail.originalEvent,c=o.button===0&&o.ctrlKey===!0;(o.button===2||c)&&l.preventDefault()}),onFocusOutside:Ge(n.onFocusOutside,l=>l.preventDefault())})},"DialogContentModal")),S5=d.forwardRef(gr(function(n,s){const r=ua(Du,n.__scopeDialog),a=d.useRef(!1),i=d.useRef(!1);return t.jsx(bI,{...n,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:l=>{var o,c;(o=n.onCloseAutoFocus)==null||o.call(n,l),l.defaultPrevented||(a.current||(c=r.triggerRef.current)==null||c.focus(),l.preventDefault()),a.current=!1,i.current=!1},onInteractOutside:l=>{var u,h;(u=n.onInteractOutside)==null||u.call(n,l),l.defaultPrevented||(a.current=!0,l.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const o=l.target;((h=r.triggerRef.current)==null?void 0:h.contains(o))&&l.preventDefault(),l.detail.originalEvent.type==="focusin"&&i.current&&l.preventDefault()}})},"DialogContentNonModal")),bI=d.forwardRef(gr(function(n,s){const{__scopeDialog:r,trapFocus:a,onOpenAutoFocus:i,onCloseAutoFocus:l,...o}=n,c=ua(Du,r);return Xm(),t.jsx(t.Fragment,{children:t.jsx(SR,{asChild:!0,loop:!0,trapped:a,onMountAutoFocus:i,onUnmountAutoFocus:l,children:t.jsx(Lm,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionPresent?c.descriptionId:void 0,"aria-labelledby":c.titlePresent?c.titleId:void 0,"data-state":op(c.open),...o,ref:s,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})},"DialogContentImpl")),C5="DialogTitle",lp=d.forwardRef(gr(function(n,s){const{__scopeDialog:r,...a}=n,i=ua(C5,r),{setTitleCount:l}=i;return As(()=>(l(o=>o+1),()=>l(o=>o-1)),[l]),t.jsx(_t.h2,{id:i.titleId,...a,ref:s})},"DialogTitle")),E5="DialogClose",hb=d.forwardRef(gr(function(n,s){const{__scopeDialog:r,...a}=n,i=ua(E5,r);return t.jsx(_t.button,{type:"button",...a,ref:s,onClick:Ge(n.onClick,()=>i.onOpenChange(!1))})},"DialogClose"));function op(e){return e?"open":"closed"}gr(op,"getState");const A5=5;function je(e,n,s){const[r,a]=d.useState(void 0),[i,l]=d.useState(null),[o,c]=d.useState(!0),[u,h]=d.useState(0),[m,f]=d.useState(0),p=d.useRef(e);p.current=e;const x=d.useRef([]),g=()=>{for(const w of x.current.splice(0))w()};return d.useEffect(()=>g,[]),d.useEffect(()=>{let w=!1;return c(!0),p.current().then(v=>{w||(a(v),l(null),f(0))}).catch(v=>{w||(l(v instanceof pe?v.message:String(v)),f(j=>j+1))}).finally(()=>{w||(c(!1),g())}),()=>{w=!0}},[...n,u]),d.useEffect(()=>{if(!s||m>=A5)return;const w=window.setTimeout(()=>h(v=>v+1),s*2**m);return()=>window.clearTimeout(w)},[s,m,u]),{data:r,error:i,loading:o,reload:()=>new Promise(w=>{x.current.push(w),f(0),h(v=>v+1)})}}const $5="modulepreload",T5=function(e,n){return new URL(e,n).href},bS={},kI=function(n,s,r){let a=Promise.resolve();if(s&&s.length>0){const l=document.getElementsByTagName("link"),o=document.querySelector("meta[property=csp-nonce]"),c=(o==null?void 0:o.nonce)||(o==null?void 0:o.getAttribute("nonce"));a=Promise.allSettled(s.map(u=>{if(u=T5(u,r),u in bS)return;bS[u]=!0;const h=u.endsWith(".css"),m=h?'[rel="stylesheet"]':"";if(!!r)for(let x=l.length-1;x>=0;x--){const g=l[x];if(g.href===u&&(!h||g.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${u}"]${m}`))return;const p=document.createElement("link");if(p.rel=h?"stylesheet":$5,h||(p.as="script"),p.crossOrigin="",p.href=u,c&&p.setAttribute("nonce",c),document.head.appendChild(p),h)return new Promise((x,g)=>{p.addEventListener("load",x),p.addEventListener("error",()=>g(new Error(`Unable to preload CSS for ${u}`)))})}))}function i(l){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=l,window.dispatchEvent(o),!o.defaultPrevented)throw l}return a.then(l=>{for(const o of l||[])o.status==="rejected"&&i(o.reason);return n().catch(i)})},R5="buddi",I5=["core","coding","finance","garage","mail","maker","playground","research"],Ti=e=>`./mascot/${e}.png`,P5=["core"],ev=(e,n)=>P5.includes(e)?`./mascot/anim/${e}-${n}.json`:null,M5=["🙂","📚","🧭","🦊","🛟","🌿","🛠️","🎧"],O5="Introduce yourself by name and say one thing you can do today.",D5=["Hello","A brain","What I take on","Reach me","Your assistant"],oh=(e,n=!1)=>e.length<2?e.join(""):`${e.slice(0,-1).join(", ")}${n&&e.length>2?", and ":" and "}${e[e.length-1]}`,Tg=e=>e.charAt(0).toUpperCase()+e.slice(1),L5=["No","One","Two","Three","Four","Five","Six","Seven","Eight"],_f=[{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 in chapter 4."},{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 reads the statements you hand it; no bank sign-in."},{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."}],F5=["days","mail"],kS=[{id:"buddi",role:"core",label:"Blue"},{id:"mail",role:"mail",label:"Orange"},{id:"finance",role:"finance",label:"Green"},{id:"coding",role:"coding",label:"Violet"},{id:"research",role:"research",label:"Purple"}],_={tagline:"Setting up, on this Mac.",taglineElsewhere:"Setting up, on this computer.",chapters:D5,mapNotes:["Two minutes. Everything can be changed later in Settings, and nothing leaves this computer until you say so.","One line decides which company sees your assistant’s conversations. You can add more brains later and give each agent its own.","Each choice installs a plugin from withbuddi.com. At the end I suggest teammates for what you picked; nothing runs until you have read its card, and you can say no to any of them.","All three are optional. The mailbox is what “My mail” needs; the phone is how I reach you when you are away.","The persona is a plain text file the assistant grows over time. Keep it, rewrite it, or let Agent Father write one after an interview."],count:e=>`Chapter ${e} of 5`,back:"Back",change:"change",later:"Set up later",startOver:{link:"Start over",said:e=>`Starting again. What you already connected stays in Settings: ${e}.`,telegram:"Telegram",browser:"the browser"},strip:(e,n)=>`${e} · ${n}`,hello:{title:"Hi. I’m buddi.",opening:["I live on this computer and I’m about to introduce you to your first assistant. Nothing you tell me leaves this machine, except what your assistant sends to the AI you pick next.","First, what should we call you, and what time is it where you are?"],foot:"Your agents use your name in every reply, and your clock for reminders and the morning brief.",submit:"That’s me",answer:e=>e},name:{label:"Your first name",placeholder:"Sam"},clock:{label:"Your clock",hint:e=>`What this browser says. ${e} right now.`,change:"Change"},brain:{title:"Which AI should your team think with?",ask:"Pick what you already have. I test it with one small call before we go on.",submit:"Use this brain",cards:{free:{title:"Free to start, no key",line:"Ollama Cloud, one tap. Good enough to meet your assistant today.",pill:"Recommended to begin"},claude:{title:"I pay for Claude",line:"Sign in with your Claude account. Uses its extra usage."},chatgpt:{title:"I pay for ChatGPT",line:"Sign in with a code on openai.com. Uses your plan."},key:{title:"I have an API key",line:"Anthropic, OpenAI, Google AI, or another service with an address."},local:{title:"On this computer",line:"Free and private. Looking on this computer…"}},keyKinds:{label:"Which key",key:"Anthropic or OpenAI",gemini:"Google AI",service:"Another service"},claude:{label:"Claude",start:"Sign in with Claude",open:"Open the Claude sign-in page",paste:"Paste what Claude gave you",finish:"Done",waiting:"Sign in on the claude.ai page that just opened, then paste the code Claude shows you."},chatgpt:{label:"ChatGPT",instruct:"Open openai.com, type this code there and approve buddi. I’ll notice.",waiting:"Waiting for your approval…",signedIn:e=>e?`Signed in as ${e}.`:"Signed in.",code:"Your code",open:"Open openai.com",again:"Try again",failed:"The sign-in did not finish. Try again."},cloud:{label:"Ollama Cloud",waiting:"Press Connect on the ollama.com page that just opened. Sign in there first if it asks. I’ll notice.",open:"Open the ollama.com page",again:"Try again"},gemini:{label:"Gemini",field:"Your Google AI key",placeholder:"Paste it here",submit:"Use this key",get:"Get a key at aistudio.google.com"},key:{field:"Your key",placeholder:"Paste it here",hint:"I can tell which AI it belongs to from the key. It stays on this computer.",submit:"Use this key",which:"Not right?",anthropic:"Anthropic",openai:"OpenAI",refused:"That key was refused. Check it and paste it again."},local:{looking:"Free and private. Looking on this computer…",found:e=>{const n=r=>r===1?"one model":`${r} models`;return`Free and private. I found ${[e.ollama!==void 0?`Ollama with ${n(e.ollama)}`:null,e.mlxh!==void 0?`mlxh with ${n(e.mlxh)}`:null].filter(Boolean).join(" and ")}; the first answer takes a minute.`},missing:"Free, private, no key. Not here yet: I show you how to install Ollama and fetch a model."},mlxh:{label:"mlxh",connect:"Use mlxh",noBrain:"mlxh has no language model installed. Pull one with `mlxh pull`, then come back."},ollama:{label:"Ollama",connect:"Use Ollama",download:"Get Ollama",copy:"Copy",copied:"Copied",missing:e=>`Ollama isn’t on ${e} yet. Install it, open it, and I’ll notice; I never run an installer for you.`,missingHow:(e,n)=>e==="linux"?`The official script from ollama.com. Paste it into a terminal on ${n}.`:e==="darwin"?"In Terminal, with Homebrew. Or download the app.":"Download it from ollama.com and open it.",stopped:e=>`Ollama is installed but not running. Open the Ollama app${e==="linux"?", or start it with the command below":""}, and I’ll notice.`,empty:(e,n,s,r)=>`Ollama is running, with no model yet. For ${e}’s ${Math.round(n)} GB I’d fetch ${s}: about ${r} GB, once.`,emptyFoot:e=>`Free and private: it runs here, and nothing you say leaves ${e}.`,fetch:e=>`Fetch ${e}`,fetching:(e,n,s)=>s?`Fetching ${e}: ${n} of ${s} GB.`:`Fetching ${e}…`,fetchingFoot:"Keep this page open or not: Ollama keeps fetching, and I pick up where it is.",failed:e=>`The download stopped: ${e} Try again; it picks up where it was.`,again:"Try again",cloud:(e,n)=>e==="memory"?`${Math.round(n)} GB is little for a model of its own: it would be slow. Ollama Cloud runs bigger models for you, free to start.`:e==="gpu"?"No graphics chip Ollama can use here: it would be slow. Ollama Cloud runs bigger models for you, free to start.":"Rather not run a model here? Ollama Cloud runs bigger models for you, free to start.",useCloud:"Use Ollama Cloud instead",honestTitle:"A small model, honestly",honest:"Private and free, but slower and less able than Claude or ChatGPT: fine for chat, notes and reminders; weaker at long plans, careful tool use and code. Home shows how to add a stronger brain whenever you like."},model:{ask:"Which one should it think with?",label:"The model",submit:"Use this one",retry:"Try again",change:"Think with another"},checking:{key:"Checking that key…",service:"Asking the service…",ollama:"Asking the first model one small question. It can take a minute.",cloud:"Asking Ollama Cloud…",claude:"Checking with Claude…",chatgpt:"Asking ChatGPT…",gemini:"Asking Gemini…"},service:{label:"Another service",address:"Address",addressPlaceholder:"The address they gave you",key:"Key",submit:"Connect it"},works:e=>`That works. Your assistant will think with ${e}.`,worksOnFlash:e=>`That works. Google's free tier has no Pro allowance, so your assistant will think with ${e}; turn on billing at Google to use Pro.`,answer:e=>e},takeOn:{title:"What should I take on for you?",ask:"Pick a few. Each one brings a plugin and, for some, a teammate who owns that job. Skip this and I stay a plain assistant; you can add any of it later.",submit:"Take these on",none:"Just an assistant for now",nothing:"Nothing picked. I’ll be a plain assistant, and Home will offer these again.",builtIn:"Mail is built in.",nothingToFetch:"Nothing to fetch.",fetching:(e,n,s)=>`Fetching ${oh(e)} from withbuddi.com and reading them. ${n} of ${s}.`,ready:e=>`${oh(e)} ${e.length>1?"are":"is"} in, read and ready.`,failed:(e,n)=>`${e} did not come: ${n}.`,installing:(e,n)=>`Installing, ${e} of ${n} ready`,installed:"Installed",answer:e=>e.length===0?"Just an assistant":Tg(e.join(", ").toLowerCase())},reach:{title:"How do we reach each other?",ask:"A few 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",pair:"Pair your phone",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."},calendar:{title:"Your calendar",line:"Its private link, or a Google sign-in. Reading only until you say otherwise.",waiting:"Calendar is still being fetched. The button wakes up when it is in.",add:"Link a calendar",linked:"Calendar linked",google:e=>`Google · ${e}`,googleWaiting:"Waiting for Google…",googleExpired:e=>`Sign in again · ${e}`},bank:{title:"Your bank",line:"No bank sign-in: Finance reads the statements you hand it.",add:"How it works",later:"After setup"},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. Chrome pairs later, in Settings → Browser & apps.",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",inApp:{title:"buddi is in your Dock, and a browser of its own",line:"You’re in buddi.app already. To open it when your Mac starts, choose Start at Login in the buddi menu at the top of your screen. Give your assistant Chrome or its own Chromium (150 MB) so it can look at websites. Chrome pairs later, in Settings → Browser & apps.",extension:"Get the Chrome extension"}},answer:e=>e.length===0?"Later, in Settings":Tg(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.",making:"Making a code…",waiting:"Waiting for your Start…",pairedWith:e=>e!=null&&e.trim()?`Paired with ${e.trim()}’s phone`:"Paired with your phone",expired:"That code has run out. I can make you another one.",newCode:"Show a new code",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: ${oh(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(`
93
- `),submit:"Introduce us",refusedTitle:"You already have an assistant.",toAgents:"Open Agents"},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=>`${L5[e]??String(e)} ${e===1?"thing":"things"} still waiting.`,waitingBody:e=>`${Tg(oh(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 ch=null;const NS=new Map;function _5(){return ch??(ch=kI(()=>import("./lottie_light-twPed1FM.js").then(e=>e.l),[],import.meta.url).then(e=>e.default)),ch.catch(()=>{ch=null}),ch}function z5(e){let n=NS.get(e);return n||(n=fetch(e).then(s=>s.ok?s.text():null).catch(()=>null),NS.set(e,n)),n}const SS="(prefers-reduced-motion: reduce)";function NI(){const[e,n]=d.useState(()=>typeof window.matchMedia=="function"&&!window.matchMedia(SS).matches);return d.useEffect(()=>{var a;if(typeof window.matchMedia!="function")return;const s=window.matchMedia(SS),r=()=>n(!s.matches);return(a=s.addEventListener)==null||a.call(s,"change",r),()=>{var i;return(i=s.removeEventListener)==null?void 0:i.call(s,"change",r)}},[]),e}function jd({role:e="core",state:n,size:s,still:r,className:a,onStillError:i}){const l=d.useRef(null),o=NI(),[c,u]=d.useState(!1),h=s==="xs"?null:ev(e,n);return d.useEffect(()=>{if(u(!1),!o||!h)return;let m=!1,f=null;return Promise.all([_5(),z5(h)]).then(([p,x])=>{if(m||!x||!l.current)return;const g=p.loadAnimation({container:l.current,renderer:"svg",loop:!0,autoplay:!document.hidden,animationData:JSON.parse(x),rendererSettings:{preserveAspectRatio:"xMidYMid meet"}}),w=()=>{document.hidden?g.pause():g.play()};document.addEventListener("visibilitychange",w),f=()=>{document.removeEventListener("visibilitychange",w),g.destroy()},u(!0)}).catch(()=>{}),()=>{m=!0,f==null||f()}},[o,h]),t.jsx("span",{ref:l,className:a?`ui-blob ${a}`:"ui-blob","data-size":s,"data-playing":c?"true":void 0,"data-testid":"blob","data-state":n,"aria-hidden":"true",children:c?null:t.jsx("img",{src:r??Ti(e),alt:"",onError:i})})}async function CS(e){const n=new Image;n.src=e,await n.decode();const s=document.createElement("canvas");s.width=8,s.height=8;const r=s.getContext("2d");return r?(r.fillStyle="#fff",r.fillRect(0,0,8,8),r.drawImage(n,0,0,8,8),Array.from(r.getImageData(0,0,8,8).data)):null}function SI(e,n="core"){const s=NI(),r=e!==null&&U5(e,n),[a,i]=d.useState(!1);return d.useEffect(()=>{if(i(!1),!e||r||!s||!ev(n,"idle"))return;let l=!1;return Promise.all([CS(e),CS(Ti(n))]).then(([o,c])=>{if(l||!o||!c||o.length!==c.length)return;const u=o.reduce((h,m,f)=>h+Math.abs(m-c[f]),0)/o.length;i(u<12)}).catch(()=>{}),()=>{l=!0}},[e,r,s,n]),s&&ev(n,"idle")!==null&&(r||a)}function U5(e,n){const s=Ti(n);if(e===s)return!0;try{const r=typeof window>"u"?"http://localhost/":window.location.href;return new URL(e,r).href===new URL(s,r).href}catch{return!1}}function Mn(e,n,s){if(e==null)return"—";switch(n){case"currency":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?B5(r,s):String(e)}case"percent":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?`${ES(r)}%`:String(e)}case"number":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?Number.isInteger(r)?Cn(r):ES(r):String(e)}case"date":return W5(String(e));default:return typeof e=="string"?e:typeof e=="number"?Cn(e):typeof e=="boolean"?e?"yes":"no":JSON.stringify(e)??String(e)}}function B5(e,n){if(!(Math.abs(e)<1e3&&!Number.isInteger(e)))return dU(e,n);try{return new Intl.NumberFormat("en-US",{style:"currency",currency:n??"USD",maximumFractionDigits:2}).format(e)}catch{return e.toFixed(2)}}function W5(e){const n=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);return n?Zo(n[0],{year:!0,compact:!0}):e}function tv(e){const n=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);return n?Zo(n[0],{compact:!0}):e}function ES(e){return String(Math.round(e*100)/100)}function zf(e,n,s=4){if(!Number.isFinite(e)||!Number.isFinite(n))return[];if(e===n)return[e];const r=(n-e)/Math.max(1,s),a=10**Math.floor(Math.log10(r)),i=[1,2,2.5,5,10].map(o=>o*a).find(o=>o>=r)??a*10,l=[];for(let o=Math.ceil(e/i)*i;o<=n+i/1e3;o+=i)l.push(Math.round(o*1e6)/1e6);return l.filter(o=>o>=e&&o<=n)}const CI={width:480,height:160,top:10,right:10,bottom:22,left:40},EI={width:1200,height:180,top:10,right:40,bottom:22,left:40};function H5({xs:e,series:n}){const s=EI,r=s.width-s.left-s.right,a=s.height-s.top-s.bottom,i=O=>O.filter(I=>I!==null&&Number.isFinite(I)),l=n.filter(O=>O.type!=="bar"),o=n.filter(O=>O.type==="bar"),c=l.flatMap(O=>i(O.values)),u=c.length>0?Math.min(...c):0,h=c.length>0?Math.max(...c):1;let m=u,f=h;if(m===f)m-=1,f+=1;else{const O=(f-m)*.08;m-=O,f+=O}const p=O=>lr(s.top+a-(O-m)/(f-m)*a),x=o.length>0&&o.every(O=>O.unit==="percent"),g=x?100:Math.max(1,...o.flatMap(O=>i(O.values))),w=O=>lr(s.top+a-Math.max(0,O)/g*a),v=e.length,j=v>0?r/v:r,y=O=>lr(s.left+j*(O+.5)),k=n.map(O=>{if(O.type==="bar")return"";let I="M";const F=[];return O.values.forEach((U,L)=>{if(U===null||!Number.isFinite(U)){I="M";return}F.push(`${I}${y(L)},${p(U)}`),I="L"}),F.join(" ")}),N=[],b=j*.6/Math.max(1,o.length),S=s.height-s.bottom;let C=0;n.forEach((O,I)=>{if(O.type!=="bar")return;const F=C++;O.values.forEach((U,L)=>{if(U===null||!Number.isFinite(U)||U<=0)return;const M=w(U);N.push({series:I,index:L,x:lr(y(L)-j*.3+b*F),y:M,width:lr(b),height:lr(S-M)})})});const A=c.length>0?zf(u,h,2).map(O=>({value:O,y:p(O)})):[],E=o.length===0?[]:(x?[0,50,100]:zf(0,g,2)).map(O=>({value:O,y:w(O),percent:x})),R=Math.max(1,Math.ceil(v/8)),P=e.flatMap((O,I)=>I%R===0?[{index:I,x:y(I)}]:[]);return{lines:k,bars:N,targetY:null,ticks:A,xLabels:P,rightTicks:E}}function K5({xs:e,series:n,type:s="line",target:r=null}){const a=CI,i=a.width-a.left-a.right,l=a.height-a.top-a.bottom,o=n.flatMap(y=>y.values.filter(k=>k!==null&&Number.isFinite(k)));r!==null&&Number.isFinite(r)&&o.push(r),s==="bar"&&o.push(0);let c=o.length>0?Math.min(...o):0,u=o.length>0?Math.max(...o):1;if(c===u)c-=1,u+=1;else if(s==="line"){const y=(u-c)*.08;c-=y,u+=y}const h=y=>lr(a.top+l-(y-c)/(u-c)*l),m=e.length,f=m>0?i/m:i,p=y=>lr(s==="bar"?a.left+f*(y+.5):a.left+(m<=1?i/2:y/(m-1)*i)),x=s==="line"?n.map(y=>{let k="M";const N=[];return y.values.forEach((b,S)=>{if(b===null||!Number.isFinite(b)){k="M";return}N.push(`${k}${p(S)},${h(b)}`),k="L"}),N.join(" ")}):[],g=[];if(s==="bar"&&m>0){const y=f*.7,k=y/Math.max(1,n.length),N=h(0);n.forEach((b,S)=>{b.values.forEach((C,A)=>{if(C===null||!Number.isFinite(C))return;const E=h(C);g.push({series:S,index:A,x:lr(a.left+f*A+(f-y)/2+k*S),y:Math.min(E,N),width:lr(k),height:lr(Math.abs(N-E))})})})}const v=(o.length>0?zf(Math.min(...o),Math.max(...o),2):[]).map(y=>({value:y,y:h(y)})),j=m===0?[]:m===1?[0]:m<5?[0,m-1]:[0,Math.floor((m-1)/2),m-1];return{lines:x,bars:g,targetY:r!==null&&Number.isFinite(r)?h(r):null,ticks:v,xLabels:j.map(y=>({index:y,x:p(y)}))}}function V5(e){const n=e.formatX??(o=>o),s=e.formatY??(o=>String(o)),r=e.xs.length;if(r===0)return`${e.label??"Chart"}: nothing recorded yet.`;const a=r===1?`on ${n(e.xs[0])}`:`from ${n(e.xs[0])} to ${n(e.xs[r-1])}`,i=e.series.map(o=>{const c=o.values.filter(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"} ${a}. ${i.join("; ")}.${l}`}function G5({xs:e,series:n,type:s="line",target:r=null,label:a,formatX:i=o=>o,formatY:l=o=>String(o)}){const o=s==="mixed",c=o?EI:CI,u=o?H5({xs:e,series:n}):K5({xs:e,series:n,type:s,target:r}),h=V5({xs:e,series:n,target:r,...a?{label:a}:{},formatX:i,formatY:l});return t.jsxs("figure",{className:"ui-chart","data-type":s,children:[t.jsxs("svg",{viewBox:`0 0 ${c.width} ${c.height}`,"aria-hidden":"true",focusable:"false","data-testid":"chart-svg",children:[u.ticks.map(m=>t.jsxs("g",{children:[t.jsx("line",{className:"ui-chart-grid",x1:c.left,x2:c.width-c.right,y1:m.y,y2:m.y}),t.jsx("text",{x:c.left-6,y:m.y,textAnchor:"end",dominantBaseline:"middle",children:l(m.value)})]},m.value)),(u.rightTicks??[]).map(m=>t.jsx("text",{x:c.width-c.right+6,y:m.y,textAnchor:"start",dominantBaseline:"middle",children:m.percent?`${m.value}%`:l(m.value)},`r-${m.value}`)),t.jsx("line",{className:"ui-chart-axis",x1:c.left,x2:c.width-c.right,y1:c.height-c.bottom,y2:c.height-c.bottom}),u.bars.map(m=>t.jsx("rect",{className:"ui-chart-bar","data-series":m.series,x:m.x,y:m.y,width:m.width,height:m.height},`${m.series}-${m.index}`)),u.lines.map((m,f)=>m?t.jsx("path",{className:"ui-chart-line","data-series":f,d:m},f):null),u.targetY!==null?t.jsx("line",{className:"ui-chart-target","data-testid":"chart-target",x1:c.left,x2:c.width-c.right,y1:u.targetY,y2:u.targetY}):null,u.xLabels.map(m=>t.jsx("text",{x:m.x,y:c.height-6,textAnchor:o?"middle":u.xLabels.length>1&&m.index===0?"start":m.index===e.length-1&&e.length>1?"end":"middle",children:i(e[m.index])},m.index))]}),t.jsx("figcaption",{className:"sr-only",children:h}),n.length>1?t.jsx("ul",{className:"ui-chart-legend","aria-hidden":"true",children:n.map((m,f)=>t.jsx("li",{"data-series":f,"data-type":o?m.type??"line":void 0,children:m.label},m.label))}):null]})}function lr(e){return Math.round(e*10)/10}const q5={home:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M3.5 9.2 10 3.6l6.5 5.6"}),t.jsx("path",{d:"M5.2 8.4v7.4a1 1 0 0 0 1 1h2.6v-4.6h2.4v4.6h2.6a1 1 0 0 0 1-1V8.4"})]})],chat:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M17 10.6a4.9 4.9 0 0 1-4.9 4.9H7.8L3.6 18l.9-3A4.9 4.9 0 0 1 3 11V8.2A4.9 4.9 0 0 1 7.9 3.3h4.2A4.9 4.9 0 0 1 17 8.2Z"}),t.jsx("path",{d:"M7 8.3h6M7 11.3h3.6"})]})],agents:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"7.5",cy:"7",r:"2.8"}),t.jsx("path",{d:"M2.8 16.2a4.7 4.7 0 0 1 9.4 0"}),t.jsx("circle",{cx:"14",cy:"7.8",r:"2.2"}),t.jsx("path",{d:"M13.2 12.5a3.9 3.9 0 0 1 4.3 3.7"})]})],activity:[20,1.6,t.jsx("path",{d:"M2.8 10.5h3.4l2-5.2 3.4 9.8 2.2-4.6h3.4"})],settings:[24,1.9,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),t.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),20],files:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M7.5 2.8h5.2L16.5 6.6v8.6a1.2 1.2 0 0 1-1.2 1.2H7.5a1.2 1.2 0 0 1-1.2-1.2V4a1.2 1.2 0 0 1 1.2-1.2z"}),t.jsx("path",{d:"M12.7 2.8v3.8h3.8"}),t.jsx("path",{d:"M4.4 6.2v9.4a1.6 1.6 0 0 0 1.6 1.6h6.6"})]})],mail:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"3",y:"5",width:"14",height:"10.5",rx:"1.4"}),t.jsx("path",{d:"M3.4 6 10 11l6.6-5"})]})],money:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"2.6",y:"5.2",width:"14.8",height:"9.6",rx:"1.6"}),t.jsx("circle",{cx:"10",cy:"10",r:"2.2"}),t.jsx("path",{d:"M5.4 10h.5M14.1 10h.5"})]})],calendar:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"3",y:"4.4",width:"14",height:"12.2",rx:"1.6"}),t.jsx("path",{d:"M3 8.2h14M6.8 2.9v2.6M13.2 2.9v2.6"})]})],chart:[20,1.6,t.jsx("path",{d:"M3.2 16.4V8.6M8.4 16.4V3.9M13.6 16.4v-5.8M3.2 16.4h13.6"})],bell:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M5.4 13.6V9a4.6 4.6 0 0 1 9.2 0v4.6l1.2 1.7H4.2Z"}),t.jsx("path",{d:"M8.4 17.1a1.8 1.8 0 0 0 3.2 0"})]})],plug:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M7.4 2.8v3.4M12.6 2.8v3.4"}),t.jsx("path",{d:"M5 6.2h10v3.1a5 5 0 0 1-10 0Z"}),t.jsx("path",{d:"M10 14.3v3"})]})],key:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"6.6",cy:"10",r:"3.2"}),t.jsx("path",{d:"M9.8 10h7.2M14.4 10v2.6M16.6 10v1.8"})]})],globe:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"10",cy:"10",r:"7.1"}),t.jsx("path",{d:"M2.9 10h14.2M10 2.9c3.4 3.7 3.4 10.5 0 14.2-3.4-3.7-3.4-10.5 0-14.2Z"})]})],news:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M4 3.6h9.2a.8.8 0 0 1 .8.8v11.2a.8.8 0 0 0 .8.8H5.2A1.6 1.6 0 0 1 3.6 14.8V4a.4.4 0 0 1 .4-.4Z"}),t.jsx("path",{d:"M14 7h1.6a.8.8 0 0 1 .8.8v7.2a1.4 1.4 0 0 1-1.4 1.4"}),t.jsx("path",{d:"M6.4 6.8h4.4M6.4 9.8h4.4M6.4 12.8h2.8"})]})],terminal:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"12.8",rx:"1.6"}),t.jsx("path",{d:"M6.2 8l2.6 2.4-2.6 2.4M10.6 12.8h3.4"})]})],person:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"10",cy:"7",r:"3.2"}),t.jsx("path",{d:"M4 16.6a6 6 0 0 1 12 0"})]})],briefcase:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"2.8",y:"6",width:"14.4",height:"10.2",rx:"1.6"}),t.jsx("path",{d:"M7.4 6V4.6a1 1 0 0 1 1-1h3.2a1 1 0 0 1 1 1V6M2.8 10.4h14.4"})]})],pin:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M10 17.2s5.2-4.9 5.2-9a5.2 5.2 0 0 0-10.4 0c0 4.1 5.2 9 5.2 9Z"}),t.jsx("circle",{cx:"10",cy:"8.2",r:"1.9"})]})],sun:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"10",cy:"10",r:"3.2"}),t.jsx("path",{d:"M10 2.6v1.6M10 15.8v1.6M2.6 10h1.6M15.8 10h1.6M4.8 4.8l1.1 1.1M14.1 14.1l1.1 1.1M4.8 15.2l1.1-1.1M14.1 5.9l1.1-1.1"})]})],notebook:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M5.5 3.2h8.3a1 1 0 0 1 1 1v11.6a1 1 0 0 1-1 1H5.5a1 1 0 0 1-1-1V4.2a1 1 0 0 1 1-1Z"}),t.jsx("path",{d:"M7.6 3.2v13.6M10 7h2.6M10 9.8h2.6"})]})],bulb:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M7.2 13.2a5 5 0 1 1 5.6 0v1.6H7.2Z"}),t.jsx("path",{d:"M8 17.2h4"})]})],monitor:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"10",rx:"1.4"}),t.jsx("path",{d:"M7.4 16.8h5.2M10 13.6v3.2"})]})],lock:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"4",y:"8.6",width:"12",height:"8.6",rx:"2.2"}),t.jsx("path",{d:"M6.8 8.6V6.2a3.2 3.2 0 0 1 6.4 0v2.4"})]})],eye:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M2.4 10S5.2 4.8 10 4.8 17.6 10 17.6 10 14.8 15.2 10 15.2 2.4 10 2.4 10Z"}),t.jsx("circle",{cx:"10",cy:"10",r:"2.4"})]})],archive:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"3.6",rx:"1"}),t.jsx("path",{d:"M4 7.2v8a1.2 1.2 0 0 0 1.2 1.2h9.6a1.2 1.2 0 0 0 1.2-1.2v-8M8.2 10.4h3.6"})]})],chip:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"5.4",y:"5.4",width:"9.2",height:"9.2",rx:"1.4"}),t.jsx("path",{d:"M8 2.8v2.6M12 2.8v2.6M8 14.6v2.6M12 14.6v2.6M2.8 8h2.6M2.8 12h2.6M14.6 8h2.6M14.6 12h2.6"})]})],"partly-cloudy":[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"7.4",cy:"7.4",r:"2.4"}),t.jsx("path",{d:"M7.4 2.8v1M2.8 7.4h1M4.2 4.2l.7.7M10.6 4.2l-.7.7"}),t.jsx("path",{d:"M7.8 16.8h6.4a2.9 2.9 0 0 0 .3-5.8 4 4 0 0 0-7.6 1.1 2.4 2.4 0 0 0 .9 4.7Z"})]})],cloud:[20,1.6,t.jsx("path",{d:"M6 15.6h8.2a3.3 3.3 0 0 0 .4-6.6 4.6 4.6 0 0 0-8.9 1A2.8 2.8 0 0 0 6 15.6Z"})],rain:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),t.jsx("path",{d:"M7.2 14.6l-.8 2M10.4 14.6l-.8 2M13.6 14.6l-.8 2"})]})],drizzle:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),t.jsx("path",{d:"M7 15.2v.3M10 16.4v.3M13 15.2v.3"})]})],snow:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),t.jsx("path",{d:"M7.4 14.4v2.4M6.2 15.6h2.4M12.6 14.4v2.4M11.4 15.6h2.4"})]})],storm:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),t.jsx("path",{d:"M10.8 13.2 9 15.6h2.4l-1.8 2.6"})]})],fog:[20,1.6,t.jsx("path",{d:"M3.6 7.2h12.8M5.2 10.2h9.6M3.6 13.2h12.8M6.4 16.2h7.2"})],wind:[20,1.6,t.jsx("path",{d:"M3 8h9.4a2.2 2.2 0 1 0-2.2-2.2M3 12h11.6a2.2 2.2 0 1 1-2.2 2.2M3 10h5.4"})],"moon-clear":[20,1.6,t.jsx("path",{d:"M15.8 12.2A6.2 6.2 0 0 1 7.8 4.2a6.2 6.2 0 1 0 8 8Z"})],"moon-cloud":[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M9.4 6.8A3.6 3.6 0 0 1 4.6 2a3.6 3.6 0 1 0 4.8 4.8Z"}),t.jsx("path",{d:"M7.8 16.8h6.4a2.9 2.9 0 0 0 .3-5.8 4 4 0 0 0-7.6 1.1 2.4 2.4 0 0 0 .9 4.7Z"})]})],clock:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"10",cy:"10",r:"7.1"}),t.jsx("path",{d:"M10 5.8V10l2.8 1.8"})]})],dot:[20,1.6,t.jsx("circle",{cx:"10",cy:"10",r:"2.2"})],camera:[17,1.5,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M2.6 6.2a1.4 1.4 0 0 1 1.4-1.4h2l1.1-1.6h2.8l1.1 1.6h2a1.4 1.4 0 0 1 1.4 1.4v6.4a1.4 1.4 0 0 1-1.4 1.4H4a1.4 1.4 0 0 1-1.4-1.4z"}),t.jsx("circle",{cx:"8.5",cy:"9.2",r:"2.4"})]})],clip:[17,1.5,t.jsx("path",{d:"M13.2 8 8.4 12.8a3 3 0 0 1-4.2-4.2l5.1-5.1a2 2 0 1 1 2.8 2.8l-5 5"})],mic:[17,1.5,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"6.3",y:"2.4",width:"4.4",height:"7.6",rx:"2.2"}),t.jsx("path",{d:"M3.9 8.4a4.6 4.6 0 0 0 9.2 0M8.5 13v2"})]})],speaker:[17,1.5,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M2.8 6.6h2.4l3.4-2.8v9.4l-3.4-2.8H2.8z"}),t.jsx("path",{d:"M11.2 6.2a3.2 3.2 0 0 1 0 4.6M13.2 4.4a5.8 5.8 0 0 1 0 8.2"})]})],send:[16,1.8,t.jsx("path",{d:"M8 13V3.5M3.8 7.7 8 3.5l4.2 4.2"})],check:[16,1.8,t.jsx("path",{d:"M3.5 8.4 6.6 11.4 12.5 4.8"})],close:[16,1.8,t.jsx("path",{d:"M4.5 4.5l7 7M11.5 4.5l-7 7"})],search:[16,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"7",cy:"7",r:"4.5"}),t.jsx("path",{d:"M10.5 10.5L14 14"})]})],alert:[16,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"8",cy:"8",r:"6.2"}),t.jsx("path",{d:"M8 4.8v3.8M8 11.2v.01"})]})],thought:[13,1.4,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M4.2 9.6a3.6 3.6 0 1 1 4.6 0v1.2H4.2z"}),t.jsx("path",{d:"M5.2 12.2h2.6"})]})],spark:[16,1.5,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M7 2.6c.5 2.6 1.4 3.5 4 4-2.6.5-3.5 1.4-4 4-.5-2.6-1.4-3.5-4-4 2.6-.5 3.5-1.4 4-4Z"}),t.jsx("path",{d:"M12.2 10.4c.2 1 .6 1.4 1.6 1.6-1 .2-1.4.6-1.6 1.6-.2-1-.6-1.4-1.6-1.6 1-.2 1.4-.6 1.6-1.6Z"})]})],chevron:[11,1.5,t.jsx("path",{d:"M2.8 4.2 5.5 6.9l2.7-2.7"})],arrow:[13,1.5,t.jsx("path",{d:"M4.8 2.6 9 6.5l-4.2 3.9"})],back:[16,1.6,t.jsx("path",{d:"M13 8H3.4M7.4 4 3.4 8l4 4"})],forward:[16,1.6,t.jsx("path",{d:"M3 8h9.6M8.6 4l4 4-4 4"})],reload:[16,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M13 8a5 5 0 1 1-1.6-3.7"}),t.jsx("path",{d:"M11.8 1.9v2.8H9"})]})],expand:[16,1.6,t.jsx("path",{d:"M9.6 2.8h3.6v3.6M13.2 2.8 9 7M6.4 13.2H2.8V9.6M2.8 13.2 7 9"})],collapse:[16,1.6,t.jsx("path",{d:"M12.8 7H9V3.2M9 7l4.2-4.2M3.2 9H7v3.8M7 9l-4.2 4.2"})],copy:[16,1.5,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"5.6",y:"5.6",width:"7.6",height:"7.6",rx:"1.4"}),t.jsx("path",{d:"M10.4 5.6V4a1.2 1.2 0 0 0-1.2-1.2H4A1.2 1.2 0 0 0 2.8 4v5.2A1.2 1.2 0 0 0 4 10.4h1.6"})]})],play:[16,1.5,t.jsx("path",{d:"M5.2 3.4v9.2L12.6 8z"})],pause:[16,1.5,t.jsx("path",{d:"M5.6 3.6v8.8M10.4 3.6v8.8"})],stop:[16,1.5,t.jsx("rect",{x:"4.2",y:"4.2",width:"7.6",height:"7.6",rx:"1.2"})],download:[16,1.5,t.jsx("path",{d:"M8 2.8v7.2M4.9 7 8 10.1 11.1 7M3 12.8h10"})],out:[12,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"6",cy:"6",r:"4.4"}),t.jsx("path",{d:"M3.4 8.6 8.6 3.4"})]}),11],external:[12,1.6,t.jsx("path",{d:"M4.5 3H9v4.5M9 3 3 9"}),11],"chevron-left":[14,1.6,t.jsx("path",{d:"M9 2.5 4.5 7 9 11.5"})],"chevron-right":[14,1.6,t.jsx("path",{d:"M5 2.5 9.5 7 5 11.5"})],plus:[14,1.6,t.jsx("path",{d:"M7 2.5v9M2.5 7h9"})],grip:[16,0,t.jsxs("g",{fill:"currentColor",stroke:"none",children:[t.jsx("circle",{cx:"6",cy:"4",r:"1.2"}),t.jsx("circle",{cx:"10",cy:"4",r:"1.2"}),t.jsx("circle",{cx:"6",cy:"8",r:"1.2"}),t.jsx("circle",{cx:"10",cy:"8",r:"1.2"}),t.jsx("circle",{cx:"6",cy:"12",r:"1.2"}),t.jsx("circle",{cx:"10",cy:"12",r:"1.2"})]})],more:[16,0,t.jsxs("g",{fill:"currentColor",stroke:"none",children:[t.jsx("circle",{cx:"8",cy:"3.4",r:"1.35"}),t.jsx("circle",{cx:"8",cy:"8",r:"1.35"}),t.jsx("circle",{cx:"8",cy:"12.6",r:"1.35"})]})],drop:[28,1.8,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M14 4v13M8.5 11.5 14 17l5.5-5.5"}),t.jsx("path",{d:"M5 19.5v2a2.5 2.5 0 0 0 2.5 2.5h13a2.5 2.5 0 0 0 2.5-2.5v-2"})]})],folder:[20,1.6,t.jsx("path",{d:"M2.8 5.6a1.4 1.4 0 0 1 1.4-1.4h3.4l1.7 1.9h6.5a1.4 1.4 0 0 1 1.4 1.4v7.3a1.4 1.4 0 0 1-1.4 1.4H4.2a1.4 1.4 0 0 1-1.4-1.4Z"})],"chevron-down":[14,1.4,t.jsx("path",{d:"M4 5.5 7 8.5l3-3"}),12],frame:[22,1.3,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"2.6",y:"3.6",width:"16.8",height:"14.8",rx:"2"}),t.jsx("path",{d:"M2.6 14.2 7.4 9.6l3.4 3 3-2.6 3.6 3.2"}),t.jsx("circle",{cx:"7.4",cy:"7.6",r:"1.2"})]})],"shape-timeseries":[16,1.4,t.jsx("path",{d:"M2 11.5 5.4 7.2l2.6 2.2L14 3.5"})],"shape-table":[16,1.4,t.jsx("path",{d:"M2.2 3.5h11.6v9H2.2zM2.2 6.6h11.6M6.6 6.6v5.9"})],"shape-bars":[16,1.4,t.jsx("path",{d:"M3 13V8.2M7 13V3.6M11 13V6.4M2 13.6h12"})],"shape-keyvalue":[16,1.4,t.jsx("path",{d:"M2.6 4.6h4M9.4 4.6h4M2.6 8h4M9.4 8h4M2.6 11.4h4M9.4 11.4h4"})],"shape-tiles":[16,1.4,t.jsx("path",{d:"M2.4 3.4h4.8v4.2H2.4zM8.8 3.4h4.8v4.2H8.8zM2.4 9.2h4.8v4.2H2.4zM8.8 9.2h4.8v4.2H8.8z"})],"shape-document":[16,1.4,t.jsx("path",{d:"M4 2.4h5l3 3v8.2H4zM9 2.4v3h3M6 9h4M6 11.2h3"})],"shape-diff":[16,1.4,t.jsx("path",{d:"M8 2.6v5M5.5 5.1h5M5.5 11.6h5M3 14h10"})],"shape-terminal":[16,1.4,t.jsx("path",{d:"M2.2 3.4h11.6v9.2H2.2zM4.6 6.4l2 1.6-2 1.6M8 10h3"})],"shape-image":[16,1.4,t.jsx("path",{d:"M2.2 3.4h11.6v9.2H2.2zM2.2 11l3.6-3.4 2.6 2.4 2-1.8 3.4 3M10.6 6.2h.01"})],"shape-preview":[16,1.4,t.jsx("path",{d:"M2.2 3.4h11.6v9.2H2.2zM2.2 6h11.6M4.1 4.7h.01M6 4.7h.01"})],"shape-envelope":[16,1.4,t.jsx("path",{d:"M2.2 4h11.6v8H2.2zM2.2 4.4 8 8.8l5.8-4.4"})],moon:[16,1.5,t.jsx("path",{d:"M12.9 9.7A5.3 5.3 0 0 1 6.3 3.1a5.3 5.3 0 1 0 6.6 6.6z"})],code:[16,1.6,t.jsx("path",{d:"M5.8 4.6L2.4 8l3.4 3.4M10.2 4.6L13.6 8l-3.4 3.4"})],"pasted-doc":[16,1.5,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M4 2.5h5.2L12 5.3v8.2H4z"}),t.jsx("path",{d:"M9 2.5v3h3M6 8.5h4M6 10.8h4"})]})],"shape-structured":[16,1.4,t.jsx("path",{d:"M4 2.6h8v10.8H4zM6.2 5.6h3.6M6.2 8h3.6M6.2 10.4h2.2"})]};function ne({name:e,size:n,className:s,...r}){const[a,i,l,o]=q5[e],c=n??o??a;return t.jsx("svg",{className:s,width:c,height:c,viewBox:`0 0 ${a} ${a}`,"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:i,strokeLinecap:"round",strokeLinejoin:"round","data-icon":e,...r,children:l})}const vd="front-desk",fb=[{id:vd,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."}],AI=new Set(fb.map(e=>e.id)),AS=e=>AI.has(e);function $S(e,n){const s=n.filter(r=>!AI.has(r));return[...fb.filter(r=>e.has(r.id)).map(r=>r.id),...s.filter((r,a)=>s.indexOf(r)===a)]}function Y5(e,n){return e.find(s=>(s.roles??[]).includes(n))}const TS=["coding","finance","mail","research","calendar","files","memory"],Q5={developer:"coding",coding:"coding",finance:"finance",credit:"finance",mail:"mail",email:"mail",research:"research",calendar:"calendar",files:"files",memory:"memory",[vd]:"buddi"},J5=[["mail",["email"]],["finance",["finance"]],["coding",["developer"]],["research",["web","browser"]],["art",["image"]]];function X5(e){const n=new Set(e.map(s=>s.split(".")[0]??s));for(const[s,r]of J5)if(r.some(a=>n.has(a)))return s;return n.size>0&&[...n].every(s=>s==="memory")?"memory":null}let nv=null;function Z5(e){nv=e}function sc(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=Q5[s];if(r)return{key:r}}const n=X5(e.tools??[]);return n?{key:n}:nv!==null&&e.id===nv?{key:"buddi"}:{key:TS[e8(e.id)%TS.length]??"coding"}}function fl(e){return e.key==="own"?{"data-agent":"own",style:{"--agent-fill":e.hex}}:{"data-agent":e.key}}function e8(e){let n=0;for(const s of e)n=(n*31+s.charCodeAt(0))%997;return n}const t8=["run.started","tool.called","tool.result","message.appended","awaiting-approval","run.finished","reaction","live","live.settle","live.snapshot","attention","plugins-changed","pages.changed","closing","ping"];function n8(e){const s=e.replace(/\r\n/g,`
94
- `).split(`
95
-
96
- `),r=s.pop()??"",a=[];for(const i of s){let l=null,o="message";const c=[];for(const u of i.split(`
97
- `)){if(u===""||u.startsWith(":"))continue;const h=u.indexOf(":"),m=h===-1?u:u.slice(0,h),f=h===-1?"":u.slice(h+1).replace(/^ /,"");m==="id"?l=f:m==="event"?o=f:m==="data"&&c.push(f)}c.length===0&&o==="message"||a.push({id:l,name:t8.includes(o)?o:"ping",data:s8(c.join(`
98
- `))})}return{events:a,rest:r}}function s8(e){if(e==="")return{};try{const n=JSON.parse(e);return n!==null&&typeof n=="object"?n:{value:n}}catch{return{value:e}}}function cp(e){const n=e.fetchImpl??globalThis.fetch.bind(globalThis),s=e.wait??(u=>new Promise(h=>setTimeout(h,u))),r=e.retryMs??1500;let a=e.lastEventId??null,i=!1,l=!1,o=null;return(async()=>{var u,h,m,f,p;for(;!i;){(u=e.onStatus)==null||u.call(e,"connecting"),o=new AbortController;try{const x=await n(e.url,{credentials:"same-origin",signal:o.signal,headers:{Accept:"text/event-stream",...a===null?{}:{"Last-Event-ID":a}}});if(!x.ok||!x.body)throw new Error(`stream ${x.status}`);(h=e.onStatus)==null||h.call(e,"open"),l&&((m=e.onReconnect)==null||m.call(e));const g=x.body.getReader(),w=new TextDecoder;let v="";for(;;){const{done:j,value:y}=await g.read();if(j)break;v+=w.decode(y,{stream:!0});const{events:k,rest:N}=n8(v);v=N;for(const b of k)e.onEvent(b),b.id!==null&&(a=b.id);if(i)break}}catch{}if(i)break;l=!0,(f=e.onStatus)==null||f.call(e,"closed"),await s(r)}(p=e.onStatus)==null||p.call(e,"closed")})(),{close:()=>{i=!0,o==null||o.abort()},lastEventId:()=>a}}const mb="0.1.0+e128924";function pb(e,n=mb){return typeof e=="string"&&e!==""&&typeof n=="string"&&n!==""&&e!==n}function r8(){var e;try{if((e=window.matchMedia)!=null&&e.call(window,"(display-mode: standalone)").matches)return!0}catch{}return window.navigator.standalone===!0}const a8=5*6e4,i8=6e4,l8=5e3,Lu="buddi:stream-reconnected",$I="buddi.autoReloadedFor";function o8(){window.dispatchEvent(new Event(Lu))}const RS=["keydown","pointerdown","pointermove","wheel","touchstart","input"];let gb=Date.now(),uh=0;const IS=()=>{gb=Date.now()};function c8(){if(uh===0){gb=Date.now();for(const e of RS)window.addEventListener(e,IS,{capture:!0,passive:!0})}return uh+=1,()=>{if(uh-=1,uh===0)for(const e of RS)window.removeEventListener(e,IS,{capture:!0})}}function u8(e=Date.now()){return e-gb}function TI(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 d8(e){return e.hidden?!0:e.idleMs>=i8&&!e.busy}function h8(e){try{return window.sessionStorage.getItem($I)===e}catch{return!1}}function f8(e){try{window.sessionStorage.setItem($I,e)}catch{}}function m8(e){const n=d.useRef(e);n.current=e,d.useEffect(()=>{const s=()=>n.current();return window.addEventListener(Lu,s),()=>window.removeEventListener(Lu,s)},[])}function p8(e,n=()=>window.location.reload(),s=mb){const r=pb(e,s),a=d.useRef(n);a.current=n,d.useEffect(()=>c8(),[]),d.useEffect(()=>{if(!r||e===void 0||h8(e))return;let i=!1;const l=()=>{if(i)return;const c=document.visibilityState==="hidden";d8({hidden:c,idleMs:u8(),busy:TI()})&&(i=!0,f8(e),a.current())};l();const o=window.setInterval(l,l8);return document.addEventListener("visibilitychange",l),()=>{window.clearInterval(o),document.removeEventListener("visibilitychange",l)}},[r,e])}const g8=9e4,RI=5*6e4,x8=500,j8=2e3,v8=3e3,y8="/_buddi/ready",jo={reload:()=>window.location.reload(),now:()=>Date.now()};let vi=null,ro=null,_c=null;const sv=new Set;function Uf(e){vi=e;for(const n of sv)n()}function PS(){return vi}function w8(e){return sv.add(e),()=>sv.delete(e)}function b8(){const e=new Uint8Array(32);return crypto.getRandomValues(e),[...e].map(n=>n.toString(16).padStart(2,"0")).join("")}async function xb(e=v8){const n=new AbortController,s=setTimeout(()=>n.abort(),e);try{const r=await fetch(`${y8}?challenge=${b8()}`,{cache:"no-store",credentials:"omit",redirect:"error",signal:n.signal,headers:{Accept:"application/json"}});if(r.status!==200)return null;const a=await r.json().catch(()=>null);return typeof(a==null?void 0:a.boot)=="string"?a.boot:""}catch{return null}finally{clearTimeout(s)}}async function k8(){const e=await xb();e&&(ro=e)}function N8(){let e=ro,n=!1,s=!1,r=x8,a;const i=async()=>{if(n)return;const l=await xb();if(!n){if(l===null)s=!0;else if(e!==null?l!==e:s){n=!0,jo.reload();return}else e===null&&l!==""&&(e=l);r=Math.min(Math.round(r*1.5),j8),a=setTimeout(()=>void i(),r)}};return a=setTimeout(()=>void i(),r),()=>{n=!0,clearTimeout(a)}}function up(e){if(vi){if(e.kind==="detected")return;Uf({...vi,...e});return}Uf({...e,startedAt:jo.now()}),_c=N8()}function II(e){vi&&Uf({...vi,...e})}function Ro(){_c==null||_c(),_c=null,Uf(null)}async function rc(e,n){up(e);try{return await n()}catch(s){if(Ff(s))return;throw Ro(),s}}function S8(e){up({kind:e.for==="stop"?"stop":"detected"})}async function MS(){if(vi)return;const e=await xb();if(ro===null){e&&(ro=e);return}if(!(!e||e===ro||vi)){if(TI()){ro=e;return}up({kind:"detected"})}}function C8(e){const[n,s]=e;if(!n)return null;const r=`${n.name} ${n.version}`;return s?e.length===2?`${r} and ${s.name} ${s.version}`:`${r} and ${e.length-1} more`:r}function Bf(e,n){return(e??[]).filter(s=>s.place===n).map((s,r)=>({page:s,index:r})).sort((s,r)=>(s.page.order??0)-(r.page.order??0)||s.index-r.index).map(s=>s.page)}const Wf="buddi:plugin-pages-changed";function jb(){window.dispatchEvent(new Event(Wf))}const rv="buddi:plugin-data-changed",E8=500;function A8(e){window.dispatchEvent(new CustomEvent(rv,{detail:e}))}function PI(e,n,s=E8){const r=d.useRef(n);r.current=n,d.useEffect(()=>{let a;const i=l=>{l.detail===e&&(a!==void 0&&clearTimeout(a),a=setTimeout(()=>{a=void 0,r.current()},s))};return window.addEventListener(rv,i),()=>{window.removeEventListener(rv,i),a!==void 0&&clearTimeout(a)}},[e,s])}function MI(e=!1){const[n,s]=d.useState([]);return d.useEffect(()=>{if(e)return;let r=!1;const a=()=>{Promise.resolve().then(()=>T.pages()).then(l=>{r||s(Array.isArray(l==null?void 0:l.pages)?l.pages:[])}).catch(()=>{})};a();const i=()=>{document.visibilityState==="visible"&&a()};return window.addEventListener(Wf,a),document.addEventListener("visibilitychange",i),()=>{r=!0,window.removeEventListener(Wf,a),document.removeEventListener("visibilitychange",i)}},[e]),{all:n,rail:Bf(n,"rail"),settings:Bf(n,"settings"),find:(r,a)=>n.find(i=>i.plugin===r&&i.id===a)}}function av(e,n){const s=(n??[]).filter(i=>i.plugin===e),r=Bf(s,"rail")[0]??Bf(s,"settings")[0];if(r!=null&&r.title.trim())return r.title.trim();const a=e.replace(/[-_]+/g," ").trim();return a?a.charAt(0).toUpperCase()+a.slice(1):e}const $8="/api/chat/attention/stream";function OI(e,n){const s=(i,l)=>i.name.localeCompare(l.name),r=i=>e.filter(l=>l.anchor===i).sort(s),a=e.filter(i=>i.anchor!=="top"&&i.anchor!=="bottom").sort((i,l)=>i.id===n?l.id===n?0:-1:l.id===n?1:s(i,l));return{top:r("top"),middle:a,bottom:r("bottom")}}function DI(e,n){const s=OI(e,n);return[...s.top,...s.middle,...s.bottom]}function yd(e){if(!e)return null;const n=[];return e.approvals>0&&n.push(e.approvals===1?"one approval is waiting for you":`${e.approvals} approvals are waiting for you`),e.question&&n.push("asked you a question and is holding for the answer"),n.length===0?null:n.join(", and ")}function T8(e){if(!e)return null;const n=e.approvals,s=n===1?"1 approval":`${n} approvals`;return n>0&&e.question?`${s} and a question`:n>0?`${s} waiting`:e.question?"Has a question":null}function R8(e,n){return e&&(e.approvals>0||e.question)?"needs":n?"working":null}function I8(e){return new Map(((e==null?void 0:e.agents)??[]).map(n=>[n.agentId,n]))}function P8(){const[e,n]=d.useState(null);return d.useEffect(()=>{let s=!1;const r=()=>{ke("/chat/attention").then(i=>{s||n(i)}).catch(()=>{})};r();const a=cp({url:$8,onEvent:i=>{i.name==="closing"?S8(i.data):i.name==="plugins-changed"?jb():i.name==="pages.changed"?typeof i.data.plugin=="string"&&A8(i.data.plugin):r()},onReconnect:o8});return()=>{s=!0,a.close()}},[]),I8(e)}const Pr="maker";function vb(e){return e.filter(n=>n.available&&!n.roles.includes(Pr))}function LI(e){return vb(e).length>=2}function M8(e){var n;return((n=e.find(s=>s.roles.includes(Pr)))==null?void 0:n.name)??"the agent maker"}const O8="{{default}}";function D8(e,n){return e.split(O8).join(n??"your assistant")}function L8(e,n){return((e==null?void 0:e.starters)??[]).slice(0,3).map(s=>D8(s,n))}function F8(e){var s,r;const n=(s=e==null?void 0:e.intro)==null?void 0:s.trim();return n&&n!==""?n:((r=e==null?void 0:e.description)==null?void 0:r.trim())??""}function _8(e){const n=(e??"·").trim().split(/\s+/).filter(Boolean);return n.length===0?"·":n.length===1?n[0].slice(0,2).toUpperCase():(n[0][0]+n[1][0]).toUpperCase()}function FI(e){var r,a;const n=(r=e.heldBack)==null?void 0:r.message.trim();if(n!==void 0&&n!=="")return`${e.name??"This agent"} is held back. ${n}`;const s=(a=e.unavailableReason)==null?void 0:a.trim();return s&&s!==""?`${e.name??"This agent"} cannot run: ${s}`:`${e.name??"This agent"} cannot run: it has no model account yet.`}const z8="Settings → Model accounts",U8="Install it in Settings → Plugins";function iv(e){return e!=null&&e.heldBack?{section:"plugins",label:U8}:{section:"accounts",label:z8}}const Un="#/",Io="#/needs",Aa="#/chat",Pt="#/agents",ln="#/activity",Nn="#/settings",Da="#/files",B8="#/welcome";function Yh(e){const n=/^#\/welcome(?:\?(.*))?$/.exec(e);if(!n)return null;try{return{step:new URLSearchParams(n[1]??"").get("step")}}catch{return{step:null}}}function ao(e,n={}){const s=new URLSearchParams;n.q&&s.set("q",n.q),n.origin&&s.set("origin",n.origin),n.family&&s.set("family",n.family);const r=s.toString();return`${Da}${e?`/${encodeURIComponent(e)}`:""}${r?`?${r}`:""}`}function W8(e){const n=/^#\/files(?:\/([^/?]+))?(?:\?(.*))?$/.exec(e);if(!n)return null;try{const s=new URLSearchParams(n[2]??""),r={};return s.get("q")&&(r.q=s.get("q")),s.get("origin")&&(r.origin=s.get("origin")),s.get("family")&&(r.family=s.get("family")),{...n[1]?{artifactId:decodeURIComponent(n[1])}:{},filters:r}}catch{return null}}function ut(e,n,s){return`#/chat/${encodeURIComponent(e)}${n?`/${encodeURIComponent(n)}`:""}${s?`?tab=${s}`:""}`}function H8(e){if(_I(e))return null;const n=/^#\/chat\/([^/?]+)(?:\/([^/?]+))?(?:\?(.*))?$/.exec(e);if(!n)return null;try{const s=new URLSearchParams(n[3]??"").get("tab");return{agentId:decodeURIComponent(n[1]),...n[2]?{conversationId:decodeURIComponent(n[2])}:{},...s?{tab:s}:{}}}catch{return null}}function Hi(e,n){return`#/chat/g/${encodeURIComponent(e)}${n?`/${encodeURIComponent(n)}`:""}`}function _I(e){const n=/^#\/chat\/g\/([^/?]+)(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(!n)return null;try{return{groupId:decodeURIComponent(n[1]),...n[2]?{conversationId:decodeURIComponent(n[2])}:{}}}catch{return null}}function Qt(e,n,s){return`${Pt}/${encodeURIComponent(e)}${n?`/${n}${s?`/${s}`:""}`:""}`}function K8(e){const n=/^#\/agents\/([^/]+)(?:\/([a-z-]+)(?:\/([a-z-]+))?)?$/.exec(e);if(!n||n[1]===zI)return null;try{return{agentId:decodeURIComponent(n[1]),...n[2]?{tab:n[2]}:{},...n[3]?{section:n[3]}:{}}}catch{return null}}const zI="catalogue",OS=`${Pt}/${zI}`;function En(e){return e?`${OS}/${encodeURIComponent(e)}`:OS}function V8(e){return`${En(e)}?add=1`}function G8(e,n){const s=/^#\/agents\/catalogue\/([a-z0-9-]+)\?(?:.*&)?add=1(?:&|$)/.exec(e);return(s==null?void 0:s[1])===n}function q8(e){const n=/^#\/agents\/catalogue(?:\/([a-z0-9-]+))?(?:\?.*)?$/.exec(e);return n?n[1]?{name:n[1]}:{}:null}function Fu(e){return`${ln}/conversations/${encodeURIComponent(e)}`}const Y8="#/p";function Mr(e,n,s){const r=`${Y8}/${encodeURIComponent(e)}/${encodeURIComponent(n)}`;return s?`${r}/${encodeURIComponent(s)}`:r}function yb(e){const n=/^#\/p\/([^/?]+)\/([^/?]+)(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(!n)return null;try{return{plugin:decodeURIComponent(n[1]),page:decodeURIComponent(n[2]),...n[3]?{item:decodeURIComponent(n[3])}:{}}}catch{return null}}const Q8="p.";function Or(e,n=e,s){const r=s?new URLSearchParams(s).toString():"";return`${Nn}/${encodeURIComponent(BI(e,n))}${r?`?${r}`:""}`}function J8(e,n){const s=UI(e);if(!s)return null;const r=n.filter(i=>i.plugin===s.plugin);if(r.length===0||r.some(i=>i.id===s.page))return null;const a=wb(e);return Or(s.plugin,r[0].id,Object.keys(a).length>0?a:void 0)}function wb(e){const n=e.indexOf("?");if(n===-1)return{};try{const s={};for(const[r,a]of new URLSearchParams(e.slice(n+1)))a!==""&&(s[r]=a);return s}catch{return{}}}function UI(e){const n=/^#\/settings\/p\.([^/?.]+)(?:\.([^/?.]+))?(?:\?.*)?$/.exec(e);if(!n)return null;const s=decodeURIComponent(n[1]);return{plugin:s,page:n[2]?decodeURIComponent(n[2]):s}}function BI(e,n){return`${Q8}${e}${n===e?"":`.${n}`}`}function ze(e){return e?`${Nn}/${e}`:Nn}function WI(e){return`${ze("accounts")}?account=${encodeURIComponent(e)}`}function X8(e){const n=/^#\/settings\/accounts\?(.*)$/.exec(e);if(!n)return null;try{return new URLSearchParams(n[1]).get("account")||null}catch{return null}}function _u(e,n,s){const r=new RegExp(`^#/settings/${n}\\?(.*)$`).exec(e);if(!r)return null;try{return new URLSearchParams(r[1]).get(s)||null}catch{return null}}function HI(e){return`${ze("connections")}?connection=${encodeURIComponent(e)}`}function DS(e){const n=(_u(e,"computer","code")??_u(e,"browser","code")??"").replace(/[\s-]/g,"");return/^\d{6}$/.test(n)?n:null}function Z8(e){const n=/^(#\/settings\/(?:computer|browser))\?(.*)$/.exec(e);if(!n)return e;let s;try{s=new URLSearchParams(n[2])}catch{return e}if(!s.has("code"))return e;s.delete("code");const r=s.toString();return r?`${n[1]}?${r}`:n[1]}function eW(e){return _u(e,"connections","connection")}const tW=ze("computer");function nW(e){return _u(e,"secrets","secret")}const lv=`${ze("secrets")}?add=1`;function sW(e){return _u(e,"secrets","add")==="1"}function rW(e){return`${ze("plugins")}?install=${encodeURIComponent(e)}`}const ov=`${ze("plugins")}?tab=browse`;function cv(e="all"){return e==="all"?ov:`${ov}&kind=${e}`}function aW(e){return`${ze("proposals")}${e?`?plugin=${encodeURIComponent(e)}`:""}`}function iW(e){const n=/^#\/settings\/proposals\?(.*)$/.exec(e);if(!n)return null;try{return new URLSearchParams(n[1]).get("plugin")||null}catch{return null}}function bb(e){const n=/^#\/settings\/plugins\?(.*)$/.exec(e);if(!n)return null;try{return new URLSearchParams(n[1])}catch{return null}}function lW(e){var s,r;const n=(r=(s=bb(e))==null?void 0:s.get("install"))==null?void 0:r.trim();return n||null}function LS(e){var s;const n=(s=bb(e))==null?void 0:s.get("kind");return n==="plugins"||n==="widgets"||n==="agents"?n:"all"}function FS(e){const n=bb(e);return n!=null&&n.get("install")?"installed":(n==null?void 0:n.get("tab"))==="browse"?"browse":"installed"}const oW=[{route:Un,label:"Home"},{route:Aa,label:"Chat"},{route:Pt,label:"Agents"},{route:ln,label:"Activity"},{route:Da,label:"Files"},{route:Nn,label:"Settings"}],cW=[{id:"you",label:"You"},{id:"access",label:"Models and access"},{id:"running",label:"Running"},{id:"plugins",label:"Plugins"}],uW=[{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:"Browser & apps",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 dW(e){var n;return((n=/^#\/settings\/([a-z0-9.-]+)/.exec(e))==null?void 0:n[1])??"you"}const uv="#/settings/notifications/recent",dv=ze("backup");function hW(e){const n=/^#\/conversations\/(.+)$/.exec(e);if(n)return Fu(decodeURIComponent(n[1]));const s=/^#\/email(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(s)try{return Mr("email","mail",s[1]?decodeURIComponent(s[1]):null)}catch{return Mr("email","mail")}if(e==="#/settings/email")return Or("email","settings");const r=/^#\/settings\/browser(\?.*)?$/.exec(e);return r?`${ze("computer")}${r[1]??""}`:{"#/overview":Un,"#/approvals":Un,"#/events":`${ln}/events`,"#/jobs":`${ln}/jobs`,"#/conversations":ln,"#/missions":`${Pt}?tab=missions`,"#/offers":`${Pt}?tab=offers`,"#/reminders":`${Pt}?tab=reminders`,"#/providers":ze("accounts"),"#/browser":ze("computer"),"#/sentinels":ze("watchers"),"#/settings/sentinels":ze("watchers")}[e]??null}function KI(e){if(e===""||e==="#"||e===Un)return Un;if(e.startsWith(Aa))return Aa;if(e.startsWith(Pt))return Pt;if(e.startsWith(ln))return ln;if(e.startsWith(Da))return Da;if(e.startsWith(Nn))return Nn;const n=yb(e);return n?Mr(n.plugin,n.page):Un}const fW="#/chat?group=new";function mW(e){const n=e.replace(/^#\/?/,"").split("?")[0].toLowerCase();if(n==="")return"home";const[s,r]=n.split("/");return!s||!/^[a-z0-9-]+$/.test(s)?null:(s==="settings"||s==="p")&&r&&/^[a-z0-9.-]+$/.test(r)?`${s}/${r}`:s}const VI="buddi.rosterHidden",GI=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform||navigator.userAgent),_S=GI?"⌘\\":"Ctrl+\\",zS=GI?"Meta+\\":"Control+\\";function pW(){try{return window.localStorage.getItem(VI)==="1"}catch{return!1}}function US(e){try{window.localStorage.setItem(VI,e?"1":"0")}catch{}}function qI({agents:e,currentId:n,attention:s,onSelect:r,orientation:a="vertical",lastActivity:i,working:l,groups:o=[],currentGroupId:c=null,onSelectGroup:u,onNewGroup:h}){const m=[...e.top,...e.middle,...e.bottom],f=a==="vertical"?"right":"bottom",[p,x]=d.useState(pW),g=v=>t.jsx(gW,{agent:v,active:v.id===n,attention:s.get(v.id),side:f,onSelect:r,lastAt:(i==null?void 0:i.get(v.id))??null,working:(l==null?void 0:l.has(v.id))??!1},v.id),w=()=>x(v=>(US(!v),!v));if(d.useEffect(()=>{if(a!=="vertical")return;const v=j=>{j.key!=="\\"||!(j.metaKey||j.ctrlKey)||j.altKey||j.shiftKey||(j.preventDefault(),x(y=>(US(!y),!y)))};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[a]),a==="vertical"&&p){const v=m.some(j=>yd(s.get(j.id))!==null);return t.jsxs("button",{type:"button",className:"wb-roster-tab","data-testid":"agent-rail-tab","aria-label":v?"Show the list — someone is waiting for you":"Show the list","aria-keyshortcuts":zS,title:`Show the list (${_S})`,onClick:w,children:[t.jsx(ne,{name:"chevron-right"}),v?t.jsx("span",{className:"wb-roster-tab-dot","aria-hidden":"true"}):null]})}return t.jsxs("nav",{className:a==="vertical"?"wb-agent-rail":"wb-agent-strip","aria-label":"Agents","data-testid":"agent-rail",children:[e.top.map(g),e.top.length>0&&e.middle.length>0?t.jsx("span",{className:"wb-agent-sep","data-testid":"agent-rail-sep","aria-hidden":"true"}):null,a==="vertical"?t.jsxs("div",{className:"wb-roster-head",children:[t.jsx("span",{className:"wb-roster-label",children:"Your team"}),t.jsx("button",{type:"button",className:"ui-icon-btn wb-roster-toggle","data-size":"sm","aria-label":"Hide the list","aria-keyshortcuts":zS,title:`Hide the list (${_S})`,onClick:w,children:t.jsx(ne,{name:"chevron-left"})})]}):null,t.jsxs("div",{className:"wb-agent-scroll",children:[e.middle.map(g),u&&LI(m)?t.jsxs("div",{className:"wb-groups","data-testid":"group-rail",children:[t.jsx("span",{className:"wb-agent-sep","aria-hidden":"true"}),t.jsxs("div",{className:"wb-groups-head",children:[t.jsx("span",{className:"wb-groups-label",children:"Groups"}),h?t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"New group",title:"A team of agents in one conversation",onClick:h,children:t.jsx(ne,{name:"plus"})}):null]}),o.map(v=>t.jsxs("button",{type:"button",className:"wb-face wb-group-face","data-active":v.id===c?"true":void 0,"aria-current":v.id===c?"true":void 0,"aria-label":`${v.name}, ${v.members.length} agents`,onClick:()=>u(v.id),children:[t.jsx("span",{className:"wb-group-stack","aria-hidden":"true",children:v.members.slice(0,2).map(j=>{const y=m.find(k=>k.id===j);return t.jsx(dp,{className:"wb-group-chip",id:j,name:(y==null?void 0:y.name)??"?",face:y,initials:1},j)})}),t.jsxs("span",{className:"wb-face-text",children:[t.jsx("span",{className:"wb-face-name",children:v.name}),t.jsx("span",{className:"wb-face-status",children:v.members.map(j=>{var y;return((y=m.find(k=>k.id===j))==null?void 0:y.name)??j}).join(", ")})]})]},v.id))]}):u?t.jsxs("div",{className:"wb-groups","data-testid":"group-rail-hint",children:[t.jsx("span",{className:"wb-agent-sep","aria-hidden":"true"}),t.jsx("div",{className:"wb-groups-head",children:t.jsx("span",{className:"wb-groups-label",children:"Groups"})}),t.jsxs("p",{className:"wb-groups-hint",children:["A group needs two agents; ",t.jsx("a",{href:Pt,children:"add a teammate"}),"."]})]}):null]}),e.bottom.map(g)]})}function gW({agent:e,active:n,attention:s,side:r,onSelect:a,lastAt:i=null,working:l=!1}){const o=yd(s),c=T8(s)??(e.available?i?yR(i):e.description:e.unavailableReason??"Cannot run right now"),u=R8(s,l&&e.available),h=e.unavailableReason??"This agent cannot run on this machine right now.",m=[`${e.name} @${e.handle}`,e.available?null:"unavailable",o,u==="working"?"working now":null,n?"current":null].filter(f=>f!==null&&f!=="").join(" — ");return t.jsxs(Au,{children:[t.jsx($u,{asChild:!0,children:t.jsxs("button",{className:"wb-face",...fl(sc(e)),"data-active":n?"true":void 0,"data-unavailable":e.available?void 0:"true","data-testid":`agent-face-${e.id}`,"aria-label":m,"aria-current":n?"true":void 0,disabled:!e.available,onClick:()=>e.available&&a(e.id),children:[t.jsxs("span",{className:"wb-face-frame",children:[t.jsx(dp,{className:"wb-face-mark",id:e.id,name:e.name,face:e}),u?t.jsx("span",{className:"wb-face-dot","data-state":u,"data-testid":`agent-dot-${e.id}`,"aria-hidden":"true"}):null]}),t.jsxs("span",{className:"wb-face-text","aria-hidden":"true",children:[t.jsx("span",{className:"wb-face-name",children:e.name}),t.jsx("span",{className:"wb-face-status","data-tone":o?"critical":void 0,children:c})]}),e.available?null:t.jsx("span",{className:"wb-face-out","aria-hidden":"true",children:t.jsx(ne,{name:"out"})})]})}),t.jsx(Tu,{children:t.jsxs(Ru,{className:"ui-tip",side:r,sideOffset:8,children:[t.jsx("span",{className:"ui-tip-title",children:e.name}),t.jsx("span",{className:"ui-tip-hint",children:e.available?`@${e.handle} · ${e.model}`:h}),o?t.jsx("span",{className:"ui-tip-alert",children:xW(o)}):null]})})]})}function xW(e){return`${e.slice(0,1).toUpperCase()}${e.slice(1)}.`}function jW(e){let n=0;for(const s of e)n=(n*31+s.charCodeAt(0))%997;return n%6+1}function dp({className:e,id:n,name:s,face:r,tint:a,size:i,unavailable:l,initials:o=2}){const[c,u]=d.useState(null),h=r!=null&&r.picture&&r.picture!==c?r.picture:void 0,m=r==null?void 0:r.avatar,f=h?"image":m==null?void 0:m.kind,p=n?fl(sc({id:n,accent:r==null?void 0:r.accent,roles:r==null?void 0:r.roles,tools:r==null?void 0:r.tools})):void 0;return t.jsx("span",{className:e,"data-tint":p?void 0:a,"data-size":i,"data-kind":f,"data-unavailable":l?"true":void 0,...p,"aria-hidden":"true",children:h?t.jsx("img",{src:h,alt:"",onError:()=>u(h)}):(m==null?void 0:m.kind)==="image"?t.jsx("img",{src:m.url,alt:""}):(m==null?void 0:m.kind)==="emoji"?m.value:_8(s).slice(0,o)})}function Bn({id:e,name:n,size:s,unavailable:r,face:a}){return t.jsx(dp,{className:"ui-avatar",id:e,tint:jW(e),name:n,size:s,unavailable:r,face:a})}const YI="owner",zu="buddi";function Uu(e){return e===YI}function vW(e,n=[]){var s;return Uu(e)?zu:((s=n.find(r=>r.id===e))==null?void 0:s.name)??e}function QI({size:e}){return t.jsx(Bn,{id:YI,name:zu,size:e,face:{picture:Ti("core")}})}function vn({agents:e,id:n,size:s}){if(Uu(n))return t.jsx(QI,{size:s});const r=e.find(a=>a.id===n);return t.jsx(Bn,{id:n,name:(r==null?void 0:r.name)??n,size:s,unavailable:r?!r.available:!1,face:r})}const JI=d.createContext(null);function yW({picture:e,children:n}){return t.jsx(JI.Provider,{value:e??null,children:n})}function XI({size:e,anim:n}){const s=d.useContext(JI),[r,a]=d.useState(null),i=SI(n?s:null);return!s||s===r?null:t.jsx("span",{className:"ui-mascot","data-size":e,"data-testid":"mascot","aria-hidden":"true",children:n&&i?t.jsx(jd,{state:n,still:s,className:"ui-mascot-blob",onStillError:()=>a(s)}):t.jsx("img",{src:s,alt:"",onError:()=>a(s)})})}const kb="(max-width: 900px)";function ts(e){const[n,s]=d.useState(()=>{try{return window.matchMedia(e).matches}catch{return!1}});return d.useEffect(()=>{var i;let r;try{r=window.matchMedia(e)}catch{return}const a=l=>s(l.matches);return(i=r.addEventListener)==null||i.call(r,"change",a),()=>{var l;return(l=r.removeEventListener)==null?void 0:l.call(r,"change",a)}},[e]),n}function Ri(...e){return e.filter(Boolean).join(" ")}function $({variant:e,size:n,className:s,type:r="button",...a}){return t.jsx("button",{type:r,className:Ri("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":n,...a})}function it({variant:e,size:n,className:s,...r}){return t.jsx("a",{className:Ri("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":n,...r})}function ac({checked:e,onChange:n,label:s,disabled:r}){return t.jsxs("label",{className:"ui-switch","data-disabled":r?"true":void 0,children:[t.jsx("input",{type:"checkbox",role:"switch",checked:e,disabled:r,"aria-label":s,onChange:a=>n(a.target.checked)}),t.jsx("i",{"aria-hidden":"true"})]})}function te({children:e,align:n,valign:s,className:r}){return t.jsx("div",{className:Ri("ui-toolbar",r),"data-align":n,"data-valign":s,children:e})}function ht(){return t.jsx("span",{className:"ui-toolbar-spacer"})}function le({label:e,hint:n,inline:s,grow:r,wide:a,group:i,action:l,after:o,children:c}){const u=d.useId();return t.jsxs("div",{className:"ui-field","data-inline":s?"true":void 0,"data-grow":r?"true":void 0,"data-wide":a?"true":void 0,children:[l?t.jsxs("div",{className:"ui-field-row",children:[t.jsxs("label",{className:"ui-field-control",children:[t.jsx("span",{className:"ui-field-label",children:e}),c]}),l]}):i?t.jsxs("div",{className:"ui-field-control",role:"group","aria-labelledby":u,children:[t.jsx("span",{className:"ui-field-label",id:u,children:e}),c]}):t.jsxs("label",{className:"ui-field-control",children:[t.jsx("span",{className:"ui-field-label",children:e}),c]}),n?t.jsx("span",{className:"ui-field-hint",children:n}):null,o]})}function Vs({children:e,dense:n,columns:s}){return t.jsx("div",{className:"ui-formgrid","data-dense":n?"true":void 0,"data-columns":s===3?"3":void 0,children:e})}function $e({tone:e,mono:n,dot:s,children:r,className:a,title:i}){return t.jsxs("span",{className:Ri("ui-pill",n&&"mono",a),"data-tone":e,title:i,children:[s?t.jsx("span",{className:"ui-pill-dot","aria-hidden":"true"}):null,r]})}function Po({children:e}){return t.jsx("span",{className:"ui-tag",children:e})}function wd({state:e}){const n=e==="succeeded"||e==="approved"||e==="fired"||e==="running"||e==="leased"?"good":e==="failed"||e==="rejected"||e==="unknown"||e==="error"||e==="refused"?"critical":e==="pending"||e==="suspended"||e==="expired"||e==="paused"?"warning":void 0;return t.jsx($e,{tone:n,children:e})}function Q({tone:e,title:n,children:s,role:r,action:a}){return a?t.jsx("div",{className:"ui-notice","data-tone":e,role:r,children:t.jsxs("div",{className:"ui-notice-row",children:[t.jsxs("div",{className:"ui-notice-body",children:[n?t.jsx("div",{className:"ui-notice-title",children:n}):null,s]}),a]})}):t.jsxs("div",{className:"ui-notice","data-tone":e,role:r,children:[n?t.jsx("div",{className:"ui-notice-title",children:n}):null,s]})}function re({message:e}){return e?t.jsx(Q,{tone:"critical",role:"alert",children:e}):null}function Ee({mascot:e,warm:n,title:s,action:r,children:a}){return n||s?t.jsxs("div",{className:"ui-empty","data-warm":n?"true":void 0,children:[s?t.jsx("div",{className:"ui-empty-title",children:s}):null,t.jsx("div",{children:a}),r]}):e?t.jsxs("div",{className:"ui-empty","data-mascot":"true",children:[t.jsx(XI,{size:"sm"}),t.jsx("p",{children:a})]}):t.jsx("p",{className:"ui-empty",children:a})}function ps({icon:e,title:n,action:s,children:r}){return t.jsxs("div",{className:"ui-empty-state",children:[e?t.jsx("span",{className:"ui-empty-state-icon",children:typeof e=="string"?t.jsx(ne,{name:e}):e}):null,t.jsx("div",{className:"ui-empty-state-title",children:n}),r?t.jsx("p",{className:"ui-empty-state-line",children:r}):null,s?t.jsx("div",{className:"ui-empty-state-action",children:s}):null]})}function Nb({children:e}){return t.jsx("div",{className:"ui-page",children:e})}function nl({title:e,lede:n,actions:s,before:r}){return t.jsxs("header",{className:"ui-page-head",children:[t.jsxs("div",{className:"ui-page-head-row",children:[t.jsxs("h2",{className:"ui-page-title",children:[r,t.jsx("span",{children:e})]}),s?t.jsx("div",{className:"ui-page-actions",children:s}):null]}),n?t.jsx("p",{className:"ui-page-lede",children:n}):null]})}function Is({embedded:e,title:n,lede:s,actions:r,children:a}){return e?t.jsxs("div",{className:"ui-stack","data-gap":"lg",children:[r?t.jsx("div",{className:"ui-toolbar","data-align":"end",children:r}):null,a]}):t.jsxs(Nb,{children:[t.jsx(nl,{title:n,lede:s,actions:r}),a]})}function ye({title:e,aside:n,actions:s,panel:r,flush:a,foot:i,children:l}){const o=e||n||s?t.jsxs("div",{className:"ui-section-head",children:[e?t.jsx("h3",{className:"ui-section-title",children:e}):t.jsx("span",{}),n||s?t.jsxs("div",{className:"ui-section-side",children:[n?t.jsx("span",{className:"ui-section-aside",children:n}):null,s?t.jsx("div",{className:"ui-section-actions",children:s}):null]}):null]}):null;return t.jsxs("section",{className:"ui-section","data-panel":r?"true":void 0,children:[o,r?t.jsxs("div",{className:"ui-panel","data-flush":a?"true":void 0,children:[l,i?t.jsx("div",{className:"ui-panel-foot",children:i}):null]}):t.jsxs(t.Fragment,{children:[l,i?t.jsx("div",{className:"ui-toolbar","data-align":"end",children:i}):null]})]})}function lt({title:e,tool:n,actions:s,flush:r,children:a}){return t.jsxs("section",{className:"ui-panel","data-flush":r?"true":void 0,children:[e||n||s?t.jsxs("header",{className:"ui-panel-head",children:[e?t.jsx("h3",{className:"ui-panel-title",children:e}):t.jsx("span",{}),n?t.jsx("span",{className:"ui-panel-tool",children:n}):null,s?t.jsx("div",{className:"ui-panel-actions",children:s}):null]}):null,a]})}function Br({tone:e,title:n,meta:s,actions:r,children:a,foot:i,onClick:l,label:o,as:c="div",labelledBy:u,density:h}){const m=l?{"data-interactive":"true",tabIndex:0,"aria-label":o,onClick:l,onKeyDown:f=>{f.target!==f.currentTarget||f.key!=="Enter"&&f.key!==" "||(f.preventDefault(),l())}}:{};return t.jsxs(c,{className:"ui-card","data-tone":e,"data-density":h,"aria-labelledby":u,...m,children:[n||s||r?t.jsxs("div",{className:"ui-card-head",children:[n?t.jsx("h3",{className:"ui-card-title",children:n}):null,s,r?t.jsx("div",{className:"ui-card-actions",children:r}):null]}):null,a,i?t.jsx("div",{className:"ui-card-foot",children:i}):null]})}function ue({gap:e,divided:n,children:s}){return t.jsx("div",{className:"ui-stack","data-gap":e,"data-divided":n?"true":void 0,children:s})}function wW({children:e}){return t.jsx("div",{className:"ui-row",children:e})}function hp({inline:e,children:n}){return t.jsx("div",{className:"ui-stats","data-inline":e?"true":void 0,children:n})}function Zr({label:e,value:n,note:s,tone:r,size:a}){return t.jsxs("div",{className:"ui-stat",children:[t.jsx("div",{className:"ui-stat-k",children:e}),t.jsx("div",{className:"ui-stat-v","data-tone":r,"data-size":a,children:n}),s?t.jsx("div",{className:"ui-stat-n",children:s}):null]})}function on({items:e}){return t.jsx("dl",{className:"ui-kv",children:e.map((n,s)=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:n.label}),t.jsx("dd",{children:n.value})]},n.key??s))})}function da({children:e}){return t.jsx("div",{className:"ui-table-wrap",children:t.jsx("table",{className:"ui-table",children:e})})}function Sb({value:e,label:n}){const s=Math.max(0,Math.min(100,Math.round(Number.isFinite(e)?e:0)));return t.jsx("div",{className:"ui-progress",role:"progressbar","aria-label":n,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":s,"aria-valuetext":`${s}%`,children:t.jsx("div",{className:"ui-progress-fill",style:{inlineSize:`${s}%`}})})}function Zt({children:e,label:n}){return t.jsx("pre",{className:"ui-code","aria-label":n,children:e})}function Vt({summary:e,boxed:n,open:s,className:r,onToggle:a,children:i}){return t.jsxs("details",{className:Ri("ui-details",r),"data-boxed":n?"true":void 0,open:s,onToggle:a?l=>a(l.currentTarget.open):void 0,children:[t.jsx("summary",{children:e}),i]})}function Ye({title:e,onClose:n,size:s,foot:r,scrollBody:a,container:i,children:l}){const o=i?"true":void 0;return t.jsx(rp,{open:!0,modal:!i,onOpenChange:c=>{c||n()},children:t.jsxs(ap,{...i?{container:i}:{},children:[i?t.jsx("div",{className:"ui-sheet-overlay","data-contained":o,onClick:n,"aria-hidden":"true"}):t.jsx(db,{className:"ui-sheet-overlay"}),t.jsxs(ip,{className:"ui-sheet","data-size":s,"data-contained":o,"data-scroll-body":a||void 0,"aria-describedby":void 0,...i?{onInteractOutside:c=>c.preventDefault()}:{},children:[t.jsxs("div",{className:"ui-sheet-head",children:[t.jsx(lp,{className:"ui-sheet-title",children:e}),t.jsx(hb,{asChild:!0,children:t.jsx($,{size:"sm",children:"Close"})})]}),a?t.jsx("div",{className:"ui-sheet-body",children:l}):l,r?t.jsx("div",{className:"ui-sheet-foot",children:r}):null]})]})})}function Gt({title:e,onClose:n,foot:s,children:r}){return t.jsx(rp,{open:!0,onOpenChange:a=>{a||n()},children:t.jsxs(ap,{children:[t.jsx(db,{className:"ui-sheet-overlay","data-layer":"modal"}),t.jsxs(ip,{className:"ui-modal",role:"alertdialog","aria-describedby":void 0,children:[t.jsx(lp,{className:"ui-modal-title",children:e}),r,s?t.jsx("div",{className:"ui-modal-foot",children:s}):null]})]})})}function rs({label:e,items:n,note:s,trigger:r,sheet:a,stacked:i}){const l=ts(bW);return a&&l&&!r?t.jsx(kW,{label:e,items:n,title:a.title,sub:a.sub}):t.jsx(NW,{label:e,items:n,note:s,trigger:r,stacked:i})}const bW="(max-width: 720px)";function kW({label:e,items:n,title:s,sub:r}){const[a,i]=d.useState(!1);return t.jsxs(rp,{open:a,onOpenChange:i,children:[t.jsx(y5,{asChild:!0,children:t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":e,title:e,onClick:l=>l.stopPropagation(),children:t.jsx(ne,{name:"more"})})}),t.jsxs(ap,{children:[t.jsx(db,{className:"ui-sheet-overlay",onClick:l=>l.stopPropagation()}),t.jsxs(ip,{className:"ui-action-sheet","aria-describedby":void 0,onClick:l=>l.stopPropagation(),children:[t.jsxs("div",{className:"ui-action-sheet-head",children:[t.jsx(lp,{className:"ui-action-sheet-title",children:s}),r?t.jsx("span",{className:"ui-action-sheet-sub",children:r}):null]}),t.jsx("div",{className:"ui-menu ui-action-sheet-list",role:"menu",children:n.map((l,o)=>l?l==="separator"?t.jsx("div",{className:"ui-menu-sep",role:"separator"},`sep-${o}`):"heading"in l?t.jsx("div",{className:"ui-menu-label",children:l.heading},`head-${o}`):t.jsxs("button",{type:"button",role:"menuitem",className:"ui-menu-item","data-tone":l.tone,onClick:()=>{i(!1),l.onSelect()},children:[t.jsx("span",{children:l.label}),l.hint?t.jsx("span",{className:"ui-menu-item-hint",children:l.hint}):null]},o):null)}),t.jsx(hb,{asChild:!0,children:t.jsx($,{className:"ui-action-sheet-cancel",children:"Cancel"})})]})]})]})}function NW({label:e,items:n,note:s,trigger:r,stacked:a}){const i=o=>o.stopPropagation(),l=d.useRef(!1);return t.jsxs(pd,{modal:!1,onOpenChange:o=>{o&&(l.current=!1)},children:[t.jsx(gd,{asChild:!0,children:r??t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":e,title:e,onClick:i,children:t.jsx(ne,{name:"more"})})}),t.jsx(tc,{children:t.jsxs(xd,{className:"ui-menu","data-stacked":a?"true":void 0,align:"end",sideOffset:4,onClick:i,onKeyDown:i,onCloseAutoFocus:o=>{l.current&&o.preventDefault()},children:[s?t.jsx(hl,{className:"ui-menu-label",children:s}):null,n.map((o,c)=>o?o==="separator"?t.jsx(Xr,{className:"ui-menu-sep"},`sep-${c}`):"heading"in o?t.jsx(hl,{className:"ui-menu-label",children:o.heading},`head-${c}`):t.jsxs(bs,{className:"ui-menu-item","data-tone":o.tone,onSelect:()=>{l.current=!0,o.onSelect()},children:[t.jsx("span",{children:o.label}),o.hint?t.jsx("span",{className:"ui-menu-item-hint",children:o.hint}):null]},c):null)]})})]})}function SW({title:e,actions:n,onClose:s,onCloseAutoFocus:r,onOpenAutoFocus:a,label:i,children:l}){return t.jsx(rp,{open:!0,modal:!1,onOpenChange:o=>{o||s()},children:t.jsx(ap,{children:t.jsxs(ip,{className:"ui-dock","aria-describedby":void 0,...i?{"aria-label":i}:{},onInteractOutside:o=>o.preventDefault(),...r?{onCloseAutoFocus:r}:{},...a?{onOpenAutoFocus:a}:{},children:[t.jsxs("div",{className:"ui-dock-head",children:[t.jsx(lp,{className:"ui-dock-title",children:e}),t.jsxs("div",{className:"ui-dock-actions",children:[n,t.jsx(hb,{asChild:!0,children:t.jsx($,{size:"sm",variant:"ghost",children:"Close"})})]})]}),t.jsx("div",{className:"ui-dock-body",children:l})]})})})}function ic({level:e,label:n,children:s}){return t.jsx("nav",{className:"ui-tabs","data-level":e,"aria-label":n,children:s})}function ml({href:e,active:n,count:s,onClick:r,children:a}){return t.jsxs("a",{className:"ui-tab",href:e,"aria-current":n?"page":void 0,onClick:r,children:[a,s?t.jsx("span",{className:"ui-count",children:s}):null]})}function cn({label:e,options:n,value:s,onChange:r}){return t.jsx("div",{className:"ui-segment",role:"radiogroup","aria-label":e,children:n.map(a=>t.jsx("button",{type:"button",role:"radio",className:"ui-tab","aria-checked":a.value===s,onClick:()=>r(a.value),children:a.label},a.value))})}function yt({children:e}){return t.jsx("div",{className:"ui-list",children:e})}function pt({href:e,onClick:n,lead:s,title:r,sub:a,side:i,dimmed:l,label:o}){const c=t.jsxs(t.Fragment,{children:[s,t.jsxs("span",{className:"ui-list-main",children:[t.jsx("span",{className:"ui-list-title",children:r}),a?t.jsx("span",{className:"ui-list-sub",children:a}):null]}),i?t.jsx("span",{className:"ui-list-side",children:i}):null]}),u=l?"true":void 0;return e?t.jsx("a",{className:"ui-list-row","data-dimmed":u,href:e,onClick:n?h=>{h.preventDefault(),n()}:void 0,children:c}):n?t.jsx("div",{className:"ui-list-row","data-interactive":"true","data-dimmed":u,tabIndex:0,"aria-label":o,onClick:n,onKeyDown:h=>{h.target!==h.currentTarget||h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),n())},children:c}):t.jsx("div",{className:"ui-list-row","data-dimmed":u,children:c})}function ZI({href:e,onClick:n,current:s,lead:r,title:a,meta:i,sub:l,snippet:o,side:c,strong:u}){return t.jsxs("a",{className:"ui-pick",href:e,"data-strong":u===void 0?void 0:String(u),"aria-current":s?"true":void 0,onClick:n?h=>{h.preventDefault(),n()}:void 0,children:[r?t.jsx("span",{className:"ui-pick-lead",children:r}):null,t.jsxs("span",{className:"ui-pick-main",children:[t.jsxs("span",{className:"ui-pick-top",children:[t.jsx("span",{className:"ui-pick-title",children:a}),i?t.jsx("span",{className:"ui-pick-meta",children:i}):null]}),l||c?t.jsxs("span",{className:"ui-pick-line",children:[l?t.jsx("span",{className:"ui-pick-sub",children:l}):null,c?t.jsx("span",{className:"ui-pick-side",children:c}):null]}):null,o?t.jsx("span",{className:"ui-pick-snippet",children:o}):null]})]})}function eP({list:e,detail:n,empty:s,label:r,className:a}){return t.jsxs("div",{className:Ri("ui-split",a),"data-open":n?"true":void 0,children:[t.jsx("section",{className:"ui-split-list","aria-label":r,children:e}),t.jsx("section",{className:"ui-split-detail","data-empty":n?void 0:"true",children:n??t.jsx("p",{className:"ui-empty ui-split-empty",children:s})})]})}function Hf({children:e,onRemove:n,label:s,disabled:r}){return t.jsxs("span",{className:"ui-chip",children:[e,t.jsx("button",{type:"button",className:"ui-chip-x","aria-label":`Remove ${s}`,onClick:n,disabled:r,children:"×"})]})}const CW=8;function EW({label:e,options:n,value:s,onChange:r,max:a,disabled:i,id:l}){const[o,c]=d.useState(!1),[u,h]=d.useState(""),[m,f]=d.useState(0),p=d.useRef(null),x=d.useRef(null),g=d.useRef(null),w=d.useRef(null),v=d.useId(),j=I=>{var F;return((F=n.find(U=>U.value===I))==null?void 0:F.label)??I},y=a!==void 0&&s.length>=a,k=n.filter(I=>!s.includes(I.value)),N=n.length>CW,b=u.trim().toLowerCase(),S=b===""?k:k.filter(I=>I.label.toLowerCase().includes(b)),C=Math.min(m,Math.max(0,S.length-1)),A=I=>{var F;c(!1),h(""),f(0),I&&((F=x.current)==null||F.focus())};d.useEffect(()=>{var F;if(!o)return;(F=N?g.current:w.current)==null||F.focus();const I=U=>{p.current&&!p.current.contains(U.target)&&A(!1)};return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[o,N]);const E=I=>{const F=[...s,I];r(F),h(""),f(0);const U=a!==void 0&&F.length>=a;(U||F.length>=n.length)&&A(!U)},R=I=>{if(I.key==="Escape")I.preventDefault(),A(!0);else if(I.key==="ArrowDown")I.preventDefault(),f(S.length===0?0:(C+1)%S.length);else if(I.key==="ArrowUp")I.preventDefault(),f(S.length===0?0:(C-1+S.length)%S.length);else if(I.key==="Enter"){I.preventDefault();const F=S[C];F&&E(F.value)}else I.key==="Backspace"&&u===""&&s.length>0&&(I.preventDefault(),r(s.slice(0,-1)))},P=I=>`${v}-${I}`,O=o&&S.length>0?P(C):void 0;return t.jsxs("div",{className:"ui-chippicker",ref:p,id:l,children:[s.map(I=>t.jsx(Hf,{label:j(I),disabled:i,onRemove:()=>r(s.filter(F=>F!==I)),children:j(I)},I)),t.jsxs("div",{className:"ui-chippicker-add",children:[t.jsx("button",{ref:x,type:"button",className:"ui-btn","data-size":"sm","data-variant":"ghost","aria-haspopup":"listbox","aria-expanded":o,"aria-controls":o?v:void 0,disabled:i||y||k.length===0,onClick:()=>o?A(!1):c(!0),children:"Add…"}),o?t.jsxs("div",{className:"ui-menu ui-chippicker-menu",onKeyDown:R,children:[N?t.jsx("input",{ref:g,type:"search",className:"ui-chippicker-filter","aria-label":`Filter ${e}`,"aria-controls":v,"aria-activedescendant":O,value:u,onChange:I=>{h(I.target.value),f(0)}}):null,t.jsxs("div",{ref:w,id:v,role:"listbox","aria-multiselectable":"true","aria-label":e,"aria-activedescendant":N?void 0:O,tabIndex:N?-1:0,className:"ui-chippicker-list",children:[S.map((I,F)=>t.jsx("div",{id:P(F),role:"option","aria-selected":"false",className:"ui-menu-item","data-highlighted":F===C?"":void 0,onMouseEnter:()=>f(F),onMouseDown:U=>U.preventDefault(),onClick:()=>E(I.value),children:I.label},I.value)),S.length===0?t.jsx("p",{className:"ui-menu-empty",children:"Nothing matches"}):null]})]}):null]})]})}function tP({label:e,options:n,value:s,onChange:r}){return t.jsx("div",{className:"ui-filter-chips",role:"group","aria-label":e,children:n.map(a=>t.jsx("button",{type:"button",className:"ui-btn ui-filter-chip","data-size":"sm","aria-pressed":a.value===s,onClick:()=>r(a.value),children:a.label},a.value))})}function fp({label:e,value:n,onChange:s,placeholder:r,grow:a}){return t.jsx("span",{className:"ui-search","data-grow":a?"true":void 0,children:t.jsx("input",{type:"search","aria-label":e,value:n,placeholder:r,onChange:i=>s(i.target.value)})})}function ss({svg:e,icon:n="plug",letter:s,size:r}){return t.jsx("span",{className:"ui-app-icon","data-size":r,"data-tone":e||s?"accent":void 0,"aria-hidden":"true",children:e?t.jsx("span",{className:"ui-app-icon-svg",dangerouslySetInnerHTML:{__html:e}}):s?t.jsx("span",{className:"ui-app-icon-letter",children:s}):t.jsx(ne,{name:n})})}function Zc({items:e,label:n="Where this is",inline:s}){const r=e.map((a,i)=>{const l=a.key??String(i);if(a.current)return t.jsx("span",{className:"ui-crumb","aria-current":"page",children:a.label},l);const o=a.href?t.jsx("a",{className:"ui-crumb",href:a.href,onClick:a.onClick?c=>{var u;c.preventDefault(),(u=a.onClick)==null||u.call(a)}:void 0,children:a.label}):t.jsx("button",{type:"button",className:"ui-crumb",onClick:a.onClick,children:a.label});return t.jsxs("span",{className:"ui-crumb-step",children:[o,t.jsx(ne,{name:"chevron-right",size:12})]},l)});return s?t.jsx("span",{className:"ui-crumbs","aria-label":n,children:r}):t.jsx("nav",{className:"ui-crumbs","aria-label":n,children:r})}function nP({main:e,filters:n,filtersOpen:s,onToggleFilters:r,active:a,chips:i,actions:l,onSubmit:o,label:c}){return t.jsxs("form",{className:"ui-panel ui-searchbar",role:"search","aria-label":c,onSubmit:u=>{u.preventDefault(),o()},children:[t.jsxs("div",{className:"ui-searchbar-row",children:[e?t.jsx("div",{className:"ui-searchbar-main",children:e}):null,n&&r?t.jsxs($,{"aria-expanded":s===!0,"aria-pressed":s===!0,onClick:r,children:["Filters",a?t.jsx("span",{className:"ui-count",children:a}):null]}):null,!r&&n?t.jsx("div",{className:"ui-searchbar-inline",children:n}):null,l?t.jsx("div",{className:"ui-searchbar-actions",children:l}):null]}),n&&r&&s?t.jsx("div",{className:"ui-searchbar-filters",children:n}):null,i?t.jsx("div",{className:"ui-searchbar-chips",children:i}):null]})}function Bu({size:e}){return t.jsx("span",{className:"ui-mark","data-size":e,"aria-hidden":"true",children:"b"})}function sP({quiet:e,still:n,className:s,children:r}){return t.jsx("div",{className:Ri("ui-fieldbg",s),"data-quiet":e?"true":void 0,"data-still":n?"true":void 0,children:r})}function AW({dock:e,className:n,children:s}){return t.jsxs("div",{className:Ri("ui-float",n),children:[t.jsx("div",{className:"ui-float-body",children:s}),e?t.jsx("div",{className:"ui-float-dock",children:e}):null]})}const $W=new Set(["image/png","image/jpeg","image/gif","image/webp"]),TW=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function Kf(e){const n=e!==null&&typeof e=="object"?e.artifacts:null;return Array.isArray(n)?n.flatMap(s=>{if(s===null||typeof s!="object")return[];const r=s;return typeof r.id!="string"||!TW.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 Cb(e){return $W.has(e.toLowerCase())}function Dr(e){return`/api/artifacts/${encodeURIComponent(e)}/preview`}function la(e){return`/api/artifacts/${encodeURIComponent(e)}/download`}function Yn(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 Eb(e,n){const s=e.toLowerCase(),r=(n??"").toLowerCase().split(".").pop()??"";return s.startsWith("image/")?"image":s==="application/pdf"?"pdf":s.startsWith("audio/")?"audio":s.startsWith("video/")?"video":s==="text/csv"||s==="text/tab-separated-values"||s.includes("spreadsheet")||s.includes("excel")||["csv","tsv","xls","xlsx","numbers"].includes(r)?"table":s.includes("zip")||s.includes("tar")||s.includes("compressed")||["zip","gz","tgz","rar","7z"].includes(r)?"archive":s==="application/json"||s.includes("javascript")||s.includes("xml")||["ts","tsx","js","py","rb","go","rs","swift","json","yaml","yml","toml","sh","sql","html","css"].includes(r)?"code":s.startsWith("text/")||["md","txt","rtf","doc","docx"].includes(r)?"text":"file"}const sl={image:"Image",pdf:"PDF",table:"Spreadsheet",text:"Document",code:"Code",audio:"Audio",video:"Video",archive:"Archive",file:"File"};function Qh(e){return`artifact:${e}`}function RW(e){const n=Eb(e.mime,e.filename);return{id:Qh(e.artifactId),tool:sl[n],title:e.filename??"Untitled file",renderer:"artifact",props:{attachment:e},at:null,source:"artifact",substantial:!1}}const BS=16e3,IW=10*6e4,PW="The microphone is blocked for this page: allow it in the browser’s site settings to talk.",rP="This browser cannot record here: talking needs a microphone and a secure page (https or localhost).";function MW(){const e=window;return e.AudioContext??e.webkitAudioContext}function OW(e){const n=e&&typeof e=="object"&&"name"in e?String(e.name):"";return n==="NotAllowedError"||n==="SecurityError"||n==="PermissionDeniedError"?PW:n==="NotFoundError"||n==="DevicesNotFoundError"?"No microphone was found on this computer.":n==="NotReadableError"?"The microphone is in use by another app.":rP}async function DW(e){var c;const n=MW();if(!((c=navigator.mediaDevices)!=null&&c.getUserMedia)||!n)throw Object.assign(new Error(rP),{name:"Unsupported"});const s=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),r=new n,a=r.createMediaStreamSource(s),i=r.createScriptProcessor(4096,1,1),l=[];i.onaudioprocess=u=>{const h=u.inputBuffer.getChannelData(0);l.push(new Float32Array(h));let m=0;for(let f=0;f<h.length;f++)m+=h[f]*h[f];e(Math.min(1,Math.sqrt(m/h.length)*6))},a.connect(i),i.connect(r.destination),r.state==="suspended"&&await r.resume().catch(()=>{});const o=()=>{i.onaudioprocess=null;try{a.disconnect(),i.disconnect()}catch{}s.getTracks().forEach(u=>u.stop()),r.close().catch(()=>{})};return{async stop(){const u=r.sampleRate;return o(),_W(FW(LW(l),u,BS),BS)},cancel:o}}function LW(e){const n=new Float32Array(e.reduce((r,a)=>r+a.length,0));let s=0;for(const r of e)n.set(r,s),s+=r.length;return n}function FW(e,n,s){if(n<=s)return e;const r=n/s,a=new Float32Array(Math.floor(e.length/r));for(let i=0;i<a.length;i++){const l=Math.floor(i*r),o=Math.min(e.length,Math.floor((i+1)*r));let c=0;for(let u=l;u<o;u++)c+=e[u];a[i]=o>l?c/(o-l):0}return a}function _W(e,n){const s=new ArrayBuffer(44+e.length*2),r=new DataView(s),a=(i,l)=>{for(let o=0;o<l.length;o++)r.setUint8(i+o,l.charCodeAt(o))};a(0,"RIFF"),r.setUint32(4,36+e.length*2,!0),a(8,"WAVEfmt "),r.setUint32(16,16,!0),r.setUint16(20,1,!0),r.setUint16(22,1,!0),r.setUint32(24,n,!0),r.setUint32(28,n*2,!0),r.setUint16(32,2,!0),r.setUint16(34,16,!0),a(36,"data"),r.setUint32(40,e.length*2,!0);for(let i=0;i<e.length;i++){const l=Math.max(-1,Math.min(1,e[i]));r.setInt16(44+i*2,Math.round(l<0?l*32768:l*32767),!0)}return new Blob([s],{type:"audio/wav"})}const hv="buddi.readAloud";function aP(){try{return window.localStorage.getItem(hv)==="on"}catch{return!1}}function iP(e){try{e?window.localStorage.setItem(hv,"on"):window.localStorage.removeItem(hv)}catch{}}let qr=null,eu=null,Wu=0,fv=null;const mv=new Set;function Vf(e){fv!==e&&(fv=e,mv.forEach(n=>n()))}function zW(){return fv}function UW(e){return mv.add(e),()=>mv.delete(e)}function lP(e){return lc(),Vf(e),Wu}function WS(e){return e===Wu}function lc(){Wu++,qr&&(qr.pause(),qr.removeAttribute("src")),eu&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(eu),eu=null,Vf(null)}async function BW(e,n,s=null){var a;const r=lP(s);try{const i=await fetch(e,{credentials:"same-origin"});if(!i.ok)throw new Error(`The spoken reply could not be fetched (${i.status}).`);const l=new Blob([await i.arrayBuffer()],{type:n});if(r!==Wu)return;qr||(qr=new Audio,(a=qr.addEventListener)==null||a.call(qr,"ended",()=>Vf(null))),eu=URL.createObjectURL(l),qr.src=eu,await qr.play()}catch(i){throw r===Wu&&Vf(null),i}}const WW=new Set(["audio/ogg","audio/mpeg","audio/mp4","audio/wav","audio/x-wav","audio/webm"]);function mp(e){return WW.has(e.toLowerCase().split(";")[0].trim())}function io(e){if(e===null||!Number.isFinite(e)||e<0)return"–:––";const n=Math.floor(e);return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function oP(e,n,s=!1){const r=d.useRef(null),a=d.useRef(null),[i,l]=d.useState(!1),[o,c]=d.useState(!1),[u,h]=d.useState(!1),[m,f]=d.useState(0),[p,x]=d.useState(null),g=d.useRef(null),w=d.useCallback(async()=>{const k=r.current;if(!k||a.current)return;if(g.current)return g.current;const N=(async()=>{c(!0);try{const b=await fetch(la(e),{credentials:"same-origin"});if(!b.ok)throw new Error(String(b.status));const S=await b.arrayBuffer();if(r.current!==k)return;a.current=URL.createObjectURL(new Blob([S],{type:n})),k.src=a.current,k.load()}finally{c(!1),g.current=null}})();return g.current=N,N},[e,n]);return d.useEffect(()=>{s&&w().catch(()=>h(!0));const k=r.current;return()=>{k==null||k.pause(),a.current&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(a.current),a.current=null}},[w,s]),{playing:i,loading:o,failed:u,position:m,duration:p,toggle:async()=>{const k=r.current;if(k){if(i){k.pause();return}lc(),h(!1);try{await w(),await k.play()}catch{h(!0)}finally{c(!1)}}},seek:k=>{const N=r.current;!N||p===null||!Number.isFinite(k)||(N.currentTime=Math.max(0,Math.min(p,k)),f(N.currentTime))},bind:{ref:r,preload:"none",onPlay:()=>l(!0),onPause:()=>l(!1),onEnded:()=>{l(!1),f(0)},onTimeUpdate:k=>f(k.currentTarget.currentTime),onLoadedMetadata:k=>x(Number.isFinite(k.currentTarget.duration)?k.currentTarget.duration:null),onDurationChange:k=>x(Number.isFinite(k.currentTarget.duration)?k.currentTarget.duration:null)}}}function pp({artifactId:e,name:n,mime:s,sizeBytes:r}){const{playing:a,loading:i,failed:l,position:o,duration:c,toggle:u,bind:h}=oP(e,s),m=l?"Could not play. Download it instead.":`${io(o)} / ${io(c)}`;return t.jsxs("span",{className:"wb-audio","data-testid":"audio-card","data-playing":a?"true":void 0,children:[t.jsx("button",{type:"button",className:"ui-icon-btn wb-audio-play","data-size":"sm","aria-label":a?`Pause ${n}`:`Play ${n}`,disabled:i,onClick:()=>void u(),children:t.jsx(ne,{name:a?"pause":"play",size:14})}),t.jsxs("span",{className:"wb-file-text",children:[t.jsx("span",{className:"wb-file-name",title:n,children:n}),t.jsxs("span",{className:"wb-file-meta","data-testid":"audio-time",children:[i?"Loading…":m,!l&&Yn(r)?` · ${Yn(r)}`:""]})]}),t.jsx("a",{className:"ui-icon-btn wb-audio-download","data-size":"sm",href:la(e),download:n,"aria-label":`Download ${n}`,title:"Download",children:t.jsx(ne,{name:"download",size:14})}),t.jsx("audio",{...h})]})}async function HW(e){var l;const n=await fetch(la(e.fileId),{credentials:"same-origin"});if(!n.ok)throw Error("Audio download failed");const s=await n.arrayBuffer();let r;if(e.mime==="audio/mpeg")r=new Blob([s],{type:"audio/mpeg"});else{const o=new AudioContext({sampleRate:44100});try{const c=await o.decodeAudioData(s),{Mp3Encoder:u}=await kI(async()=>{const{Mp3Encoder:x}=await import("./lamejs-fr7QR4q8.js");return{Mp3Encoder:x}},[],import.meta.url),h=Math.min(2,c.numberOfChannels),m=new u(h,c.sampleRate,128),f=Array.from({length:h},(x,g)=>Int16Array.from(c.getChannelData(g),w=>Math.round(Math.max(-1,Math.min(1,w))*(w<0?32768:32767)))),p=[];for(let x=0;x<c.length;x+=1152){const g=m.encodeBuffer(f[0].subarray(x,x+1152),(l=f[1])==null?void 0:l.subarray(x,x+1152));g.length&&p.push(Uint8Array.from(g)),x%(1152*64)===0&&await new Promise(w=>setTimeout(w,0))}p.push(Uint8Array.from(m.flush())),r=new Blob(p,{type:"audio/mpeg"})}finally{await o.close()}}const a=URL.createObjectURL(r),i=document.createElement("a");i.href=a,i.download=`${(e.filename??"recording").replace(/\.[^.]+$/,"")}.mp3`,document.body.append(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(a),6e4)}const HS="news",KW="edition";function cP(e){if(!e)return null;const n=/^#\/p\/news\/stories\?(.*)$/.exec(e);if(!n)return null;const s=new URLSearchParams(n[1]).get("edition");return s&&/^[A-Za-z0-9_-]{1,40}$/.test(s)?s:null}const Ut=e=>typeof e=="string"?e:"",VW=e=>/^https?:\/\/[^\s]+$/i.test(e),KS=/^[a-z][a-z0-9_]*\.[a-z][a-z0-9_]*$/,Hu=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null;function VS(e){const n=Hu(e);if(!n)return null;const s={};for(const[r,a]of Object.entries(n)){const i=Hu(a);if(!i||!("const"in i))return null;s[r]=i.const}return s}function GW(e){return(Array.isArray(e)?e:[]).flatMap(n=>{const s=Hu(n);if(!s)return[];const r=Ut(s.label).trim(),a=Ut(s.tool),i=VS(s.args??{});if(r===""||!KS.test(a)||!i)return[];const l=Hu(s.undo),o=l?VS(l.args??{}):null,c=l&&KS.test(Ut(l.tool))&&o?{tool:Ut(l.tool),label:Ut(l.label).trim()||"Undo",args:o}:null,u=Ut(s.hint).trim(),h=Ut(s.group).trim(),m=Ut(s.confirm).trim();return[{label:r,tool:a,args:i,...u?{hint:u}:{},...h?{group:h}:{},...m?{confirm:m}:{},done:Ut(s.done).trim()||"Done.",...c?{undo:c}:{}}]}).slice(0,12)}function uP(e){const n=e!==null&&typeof e=="object"?e.edition:null;if(n===null||typeof n!="object")return null;const s=n,r=(Array.isArray(s.groups)?s.groups:[]).flatMap(i=>{if(i===null||typeof i!="object")return[];const l=(Array.isArray(i.stories)?i.stories:[]).flatMap(o=>{if(o===null||typeof o!="object")return[];const c=o,u=Ut(c.title).trim();if(u==="")return[];const h=c.link!==null&&typeof c.link=="object"?c.link:null,m=h?Ut(h.url):"",f=c.mark==="update"||c.mark==="opinion"?c.mark:void 0,p=Ut(c.topicName).trim(),x=GW(c.actions);return[{...f?{mark:f,markLabel:Ut(c.markLabel)||void 0}:{},title:u,lead:Ut(c.lead),outlet:Ut(c.outlet),more:typeof c.more=="number"&&Number.isFinite(c.more)&&c.more>0?Math.floor(c.more):0,...VW(m)?{link:{url:m,label:Ut(h.label)||m}}:{},logos:(Array.isArray(c.logos)?c.logos:[]).flatMap(g=>{if(g===null||typeof g!="object")return[];const w=Ut(g.name),v=Ut(g.logo);return w?[{name:w,...v?{logo:v}:{}}]:[]}),...p?{topicName:p}:{},...x.length>0?{actions:x}:{}}]});return l.length>0?[{topic:Ut(i.topic),stories:l}]:[]});if(r.length===0)return null;const a=Ut(s.next);return{id:Ut(s.id),name:Ut(s.name)||"Edition",when:Ut(s.when),lede:Ut(s.lede),groups:r,notes:(Array.isArray(s.notes)?s.notes:[]).filter(i=>typeof i=="string"&&i.trim()!==""),.../^\d{1,2}:\d{2}$/.test(a)?{next:a}:{},...Ut(s.foot).trim()?{foot:Ut(s.foot).trim()}:{},.../^#\/p\/[a-z][a-z0-9_-]{0,63}\//.test(Ut(s.report))?{report:Ut(s.report)}:{}}}function qW(e,n){const s=[];let r=null;return e.forEach((a,i)=>{const l=a.group??a.tool;i>0&&l!==r&&s.push("separator"),a.group&&l!==r&&s.push({heading:a.group}),r=l,s.push({label:a.label,...a.hint?{hint:a.hint}:{},onSelect:()=>n(a)})}),s}function YW({s:e,plugin:n}){const[s,r]=d.useState(null),a=e.logos[0]??{name:e.outlet||e.title},i=e.outlet||a.name,[l,o]=d.useState(null),c=e.actions??[],u=async f=>{try{const p=await T.pageAct(n,{tool:f.tool,args:f.args});r(p.approvalId?{text:"Waiting for your approval."}:{text:f.done,...f.undo?{undo:f.undo}:{}})}catch(p){r({text:p instanceof Error&&p.message?`That did not work: ${p.message}`:"That did not work."})}},h=async f=>{try{await T.pageAct(n,{tool:f.tool,args:f.args}),r(null)}catch{r({text:"Could not take it back."})}};if(s)return t.jsxs("li",{className:"ed-story ed-story-gone",role:"status",children:[t.jsx("span",{children:s.text}),s.undo?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"pl-story-gone-sep","aria-hidden":"true",children:"·"}),t.jsx($,{size:"sm",variant:"ghost",onClick:()=>void h(s.undo),children:s.undo.label})]}):null]});const m=[e.topicName,i?e.more>0?`${i} and ${e.more} more`:i:""].filter(Boolean).join(" · ");return t.jsxs("li",{className:"ed-story",children:[c.length>0?t.jsx("span",{className:"ed-more-btn",children:t.jsx(rs,{label:`Ways out for ${e.title}`,items:qW(c,f=>f.confirm?o(f):void u(f)),sheet:{title:e.title,sub:m},stacked:!0})}):null,l?t.jsx(Gt,{title:l.confirm??l.label,onClose:()=>o(null),foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:()=>o(null),children:"Cancel"}),t.jsx($,{variant:"accent",onClick:()=>{const f=l;o(null),u(f)},children:l.label})]})}):null,t.jsx(Cl,{src:a.logo?Sl(n,a.logo):null,label:a.name,className:"pl-logo-md"}),t.jsxs("span",{className:"ed-story-text",children:[t.jsxs("span",{className:"ed-story-title",children:[e.mark?t.jsx("span",{className:"ed-mark","data-kind":e.mark==="update"?"update":void 0,children:e.mark==="update"?"Update":"Opinion"}):null,e.title]}),e.lead?t.jsx("span",{className:"ed-story-line",children:e.lead}):null,i?t.jsxs("span",{className:"ed-story-src",children:[e.link?t.jsxs("a",{className:"wb-src-link",href:e.link.url,target:"_blank",rel:"noopener noreferrer",title:e.link.label,children:[i,t.jsx("span",{className:"wb-src-out","aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:i}),e.more>0?t.jsxs("span",{className:"ed-more",children:["and ",e.more," more"]}):null]}):null]})]})}const GS=Array.from({length:64},(e,n)=>30+Math.round(Math.abs(Math.sin(n*1.7)*Math.cos(n*.4))*70));function gp({audio:e}){const{playing:n,loading:s,failed:r,position:a,duration:i,toggle:l,seek:o,bind:c}=oP(e.fileId,e.mime,!0),[u,h]=d.useState(!1),[m,f]=d.useState(!1),p=i?Math.min(1,a/i):0;return t.jsxs("div",{children:[t.jsxs("div",{className:"ed-audio","data-testid":"edition-audio",children:[t.jsx("button",{type:"button",className:"ed-play ui-icon-btn","aria-label":n?"Pause the recording":"Play the recording","aria-pressed":n,disabled:s,onClick:()=>void l(),children:t.jsx(ne,{name:n?"pause":"play",size:14})}),t.jsxs("span",{className:"ed-seek",children:[t.jsx("span",{className:"ed-wave","aria-hidden":"true",children:GS.map((x,g)=>t.jsx("i",{style:{"--h":`${x}%`},"data-on":g<Math.round(p*GS.length)?"true":void 0},g))}),t.jsx("input",{type:"range","aria-label":"Playback position","aria-valuetext":`${io(a)} of ${io(i)}`,min:0,max:i??0,step:.1,value:a,disabled:!i,onChange:x=>o(Number(x.target.value))})]}),t.jsx("span",{className:"ed-dur",role:"status",children:r?"Could not play":s?"Loading…":`${io(a)} / ${io(i)}`}),t.jsx("button",{className:"ui-icon-btn",type:"button","aria-label":"Download as MP3",title:"Download MP3",disabled:u,onClick:()=>{h(!0),f(!1),HW(e).catch(()=>f(!0)).finally(()=>h(!1))},children:t.jsx(ne,{name:"download",size:16})}),t.jsx("audio",{...c})]}),u?t.jsx("p",{className:"muted",role:"status",children:"Preparing MP3…"}):null,m?t.jsxs("p",{role:"alert",children:["Could not create MP3. ",t.jsx("a",{href:la(e.fileId),download:e.filename??"recording.ogg",children:"Download the original audio"}),"."]}):null]})}function dP({link:e}){const[n,s]=d.useState(null);return d.useEffect(()=>{let r=!0;s(null);let a=0,i;const l=async()=>{try{const o=await T.reportAudio(e);if(!r)return;s(o.audio),!o.audio&&++a<24&&(i=setTimeout(()=>void l(),5e3))}catch{}};return l(),()=>{r=!1,i&&clearTimeout(i)}},[e]),n?t.jsx(gp,{audio:n},n.fileId):null}function QW({id:e}){const[n,s]=d.useState(null);return d.useEffect(()=>{let r=!0;return s(null),T.libraryEntry(e).then(({entry:a})=>{r&&a.mime.startsWith("audio/")&&s({fileId:a.id,mime:a.mime,filename:a.filename,sizeBytes:a.sizeBytes})}).catch(()=>{}),()=>{r=!1}},[e]),n?t.jsx(gp,{audio:n},n.fileId):null}function hP(e,n){return typeof n=="string"&&n.length<=512&&n.startsWith(`#/p/${e}/`)&&/^[a-z][a-z0-9-]{0,39}(?:\?[A-Za-z0-9_.~%=&+-]{0,400})?$/.test(n.slice(`#/p/${e}/`.length))}function fP({edition:e,audio:n,plugin:s,legacyFoot:r=!1}){const a=e.foot??(r?`${e.next?`Next edition at ${e.next}. `:""}Tell me what to leave out, or mute anything from News.`:""),i=[...e.notes,...a?[a]:[]];return t.jsxs("div",{className:"ed","data-testid":"edition-card",children:[t.jsxs("div",{className:"ed-head",children:[t.jsx("span",{className:"ed-kicker",children:e.name}),e.when?t.jsx("span",{className:"ed-when",children:e.when}):null]}),n,e.lede?t.jsx("p",{className:"ed-lede",children:e.lede}):null,e.groups.map((l,o)=>t.jsxs("section",{className:"ed-group",children:[l.topic?t.jsx("h4",{className:"ed-topic",children:l.topic}):null,t.jsx("ul",{className:"ed-list",children:l.stories.map((c,u)=>t.jsx(YW,{s:c,plugin:s},u))})]},o)),i.length>0?t.jsx("p",{className:"ed-foot",children:i.join(" ")}):null]})}function JW({editionId:e,text:n,audio:s,link:r}){const[a,i]=d.useState(void 0),[l,o]=d.useState(!1);d.useEffect(()=>{let u=!0;return i(void 0),T.pageQuery(HS,KW,{id:e}).then(h=>{u&&i(uP(h.data))}).catch(()=>{u&&i(null)}),()=>{u=!1}},[e]);const c=a&&!l;return t.jsxs("div",{className:"wb-report ed-report","data-testid":"mission-report",children:[c?t.jsx("div",{className:"ed-bubble",children:t.jsx(fP,{edition:a,plugin:HS,legacyFoot:!0,audio:s?t.jsx(gp,{audio:s}):null})}):a===void 0?t.jsx("div",{className:"ed-bubble","aria-busy":"true",children:t.jsx("div",{className:"ed ed-loading"})}):t.jsxs(t.Fragment,{children:[s?t.jsx(pp,{artifactId:s.fileId,name:s.filename??"Voice note",mime:s.mime,sizeBytes:s.sizeBytes}):null,n]}),t.jsxs("div",{className:"ed-actions",children:[a?t.jsx($,{size:"sm",variant:"ghost","aria-pressed":l,onClick:()=>o(!l),children:l?"Show as card":"Show as text"}):null,t.jsx(it,{className:"wb-report-link",size:"sm",href:r.route,children:r.label})]})]})}function XW(e,n){if(!n||typeof n!="object"||Array.isArray(n))return[];const s=n.attachments;if(!Array.isArray(s))return[];const r=[];for(const a of s.slice(0,4)){const i=Hu(a);!i||i.kind!=="audio"||Object.keys(i).length!==2||(typeof i.artifact=="string"&&/^[A-Za-z0-9_-]{1,64}$/.test(i.artifact)?r.push({artifact:i.artifact}):hP(e,i.report)&&r.push({report:i.report}))}return r}function xp({image:e,plugin:n,compact:s=!1}){const[r,a]=d.useState(null),i=e?Sl(n,e.key,768):null;if(!i||r===i||!e)return null;const l=/^https?:\/\//i.test(e.url)?e.url:void 0;return t.jsxs("figure",{className:"pl-story-image","data-compact":s||void 0,children:[t.jsx("img",{src:i,alt:s?"":e.caption||`Image supplied by ${e.outlet}`,loading:"lazy",decoding:"async",onError:()=>a(i)}),s?null:t.jsxs("figcaption",{children:[e.caption?t.jsxs("span",{children:[e.caption," "]}):null,[e.credit,e.outlet].filter(Boolean).join(" · "),l?t.jsxs(t.Fragment,{children:[" · ",t.jsx("a",{href:l,target:"_blank",rel:"noopener noreferrer",children:"Source ↗"})]}):null]})]})}function bd({name:e,mime:n,sizeBytes:s,thumbnail:r,state:a,error:i,onOpen:l,onRemove:o,size:c="md",detail:u}){const h=Eb(n,e),m=u??[sl[h],Yn(s)].filter(Boolean).join(" · "),f=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"wb-file-visual","data-family":h,children:r?t.jsx("img",{src:r,alt:""}):t.jsx(Ab,{family:h})}),t.jsxs("span",{className:"wb-file-text",children:[t.jsx("span",{className:"wb-file-name",title:e,children:e}),t.jsx("span",{className:"wb-file-meta",children:a==="uploading"?"Uploading…":a==="failed"?"Upload failed":m})]})]});return t.jsxs("span",{className:"wb-file","data-size":c,"data-state":a,"data-thumb":r?"true":void 0,title:a==="failed"?i:void 0,children:[l?t.jsx("button",{type:"button",className:"wb-file-open",onClick:l,"aria-label":`Open ${e}`,children:f}):t.jsx("span",{className:"wb-file-open",children:f}),o?t.jsx("button",{type:"button",className:"wb-file-x","aria-label":`Remove ${e}`,onClick:o,children:t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:t.jsx("path",{d:"M2.5 2.5l5 5M7.5 2.5l-5 5"})})}):null]})}function Ab({family:e}){const n={width:20,height:20,viewBox:"0 0 20 20","aria-hidden":!0,fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"};switch(e){case"image":return t.jsxs("svg",{...n,children:[t.jsx("rect",{x:"3",y:"4",width:"14",height:"12",rx:"2"}),t.jsx("circle",{cx:"7.5",cy:"8.5",r:"1.4"}),t.jsx("path",{d:"M17 13l-3.6-3.6a1 1 0 0 0-1.4 0L6 15.5"})]});case"pdf":return t.jsxs("svg",{...n,children:[t.jsx("path",{d:"M6 2.5h5.5L16 7v9.5a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-13a1 1 0 0 1 1-1z"}),t.jsx("path",{d:"M11.5 2.5V7H16"}),t.jsx("path",{d:"M7.5 13.5h5M7.5 11h5"})]});case"table":return t.jsxs("svg",{...n,children:[t.jsx("rect",{x:"3",y:"4",width:"14",height:"12",rx:"1.5"}),t.jsx("path",{d:"M3 8.5h14M3 12.5h14M8 4v12M13 4v12"})]});case"text":return t.jsxs("svg",{...n,children:[t.jsx("path",{d:"M6 2.5h5.5L16 7v9.5a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-13a1 1 0 0 1 1-1z"}),t.jsx("path",{d:"M11.5 2.5V7H16"}),t.jsx("path",{d:"M7.5 10.5h5M7.5 13.5h3.5"})]});case"code":return t.jsx("svg",{...n,children:t.jsx("path",{d:"M7 6l-4 4 4 4M13 6l4 4-4 4M11.5 4l-3 12"})});case"audio":return t.jsx("svg",{...n,children:t.jsx("path",{d:"M4 8v4M7.5 5.5v9M11 3.5v13M14.5 6.5v7M18 8.5v3"})});case"video":return t.jsxs("svg",{...n,children:[t.jsx("rect",{x:"3",y:"5",width:"10",height:"10",rx:"1.5"}),t.jsx("path",{d:"M13 9l4-2.5v7L13 11"})]});case"archive":return t.jsxs("svg",{...n,children:[t.jsx("rect",{x:"4",y:"3",width:"12",height:"14",rx:"1.5"}),t.jsx("path",{d:"M10 3v3M10 8v2M10 12v2M8.5 14h3"})]});default:return t.jsxs("svg",{...n,children:[t.jsx("path",{d:"M6 2.5h5.5L16 7v9.5a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-13a1 1 0 0 1 1-1z"}),t.jsx("path",{d:"M11.5 2.5V7H16"})]})}}const ZW=6e5,eH=5e3,tH=32,nH=256*1024,sH=new Set(["script","style","iframe","frame","frameset","object","embed","applet","form","input","button","select","option","textarea","noscript","template","svg","math","head","title","meta","link","base","audio","video","source","track","canvas","map","area","dialog","portal","slot","xml"]),rH=new Set(["p","div","span","br","hr","b","strong","i","em","u","s","strike","del","ins","mark","small","big","sub","sup","code","pre","kbd","tt","samp","q","cite","abbr","blockquote","center","font","h1","h2","h3","h4","h5","h6","ul","ol","li","dl","dt","dd","table","thead","tbody","tfoot","tr","td","th","caption","colgroup","col","wbr","address","section","article","header","footer","main","aside","figure","figcaption","a","img"]),aH={center:"div",font:"span",big:"span",tt:"code",strike:"s",section:"div",article:"div",header:"div",footer:"div",main:"div",aside:"div",address:"div"},iH=new Set(["br","hr","wbr","col","img"]),lH=new Set(["color","background-color","font-weight","font-style","font-size","font-family","font-variant","text-decoration","text-decoration-line","text-align","text-transform","text-indent","vertical-align","line-height","letter-spacing","word-spacing","white-space","word-break","overflow-wrap","padding","padding-top","padding-right","padding-bottom","padding-left","margin","margin-top","margin-right","margin-bottom","margin-left","border","border-top","border-right","border-bottom","border-left","border-color","border-style","border-width","border-radius","border-collapse","border-spacing","width","max-width","min-width","height","max-height","min-height","display","list-style-type","table-layout","float","clear"]),oH=new Set(["block","inline","inline-block","none","table","table-row","table-cell","list-item","flex"]),cH=/url\s*\(|expression|javascript:|vbscript:|@import|\\|behavior|binding|attr\s*\(|var\s*\(/i,uH=["gmail_quote","yahoo_quoted","protonmail_quote","moz-cite-prefix","reply-head"],dH=/^data:image\/(png|gif|jpeg|jpg|webp);base64,[a-z0-9+/=\s]+$/i;function hH(e){return e.replace(/-([a-z])/g,(n,s)=>s.toUpperCase())}function qS(e){if(e===null)return null;const n=e.trim();return/^\d{1,4}$/.test(n)?`${n}px`:/^\d{1,3}%$/.test(n)?Number.parseInt(n,10)>100?"100%":n:null}function YS(e){if(e===null)return null;const n=e.trim();return/^#[0-9a-f]{3,8}$/i.test(n)||/^[a-z]{3,20}$/i.test(n)?n:null}const fH=/(^|[\s(,])-\s*(\d|\.\d)/,mH=new Set(["width","max-width","min-width","height","max-height","min-height"]);function pH(e){if(/v(w|h|min|max)\b|calc\s*\(|fixed|fit-content\s*\(/i.test(e))return null;const n=/^(\d+(?:\.\d+)?)%$/.exec(e);return n&&Number(n[1])>100?"100%":e}function gH(e){const n={},s=e.style;if(!s)return n;for(let r=0;r<s.length;r+=1){const a=s.item(r).toLowerCase();if(!lH.has(a))continue;const i=s.getPropertyValue(a).trim();if(i===""||i.length>200||cH.test(i)||a==="display"&&!oH.has(i.toLowerCase())||fH.test(i)||/calc\s*\(/i.test(i))continue;const l=mH.has(a)?pH(i):i;l!==null&&(n[hH(a)]=l)}return n}function QS(e,n){const s=r=>{if(r==null)return!1;const a=Number.parseFloat(r);return Number.isFinite(a)&&a<=2&&!/%/.test(r)};return s(e.getAttribute("width"))||s(e.getAttribute("height"))||s(n.width)||s(n.height)||(n.display??"").toLowerCase()==="none"||/visibility\s*:\s*hidden/i.test(e.getAttribute("style")??"")}function mP(e){if(e===null)return null;const n=e.trim();if(/^https?:\/\//i.test(n))try{const s=new URL(n);if(s.protocol==="http:"||s.protocol==="https:")return{href:s.toString(),outside:!0}}catch{return null}return/^mailto:[^\s<>"]+$/i.test(n)?{href:n,outside:!1}:null}function JS(e,n){if(n==="blockquote"&&(e.getAttribute("type")??"").toLowerCase()==="cite")return!0;const s=(e.getAttribute("class")??"").split(/\s+/);return uH.some(r=>s.includes(r))?!0:(e.getAttribute("id")??"")==="divRplyFwdMsg"}function XS(e){return(e.getAttribute("class")??"").split(/\s+/).includes("reply-head")||(e.getAttribute("id")??"")==="divRplyFwdMsg"}function xH(e){if(typeof e!="string"||e.trim()===""||e.length>ZW)return null;let n;try{n=new DOMParser().parseFromString(e,"text/html")}catch{return null}const s={nodes:0,remoteImages:0,pixels:0,truncated:!1},r=o=>{const c=o.textContent??"";return c.trim()===""?[]:[{t:"text",v:c}]},a=(o,c,u=!1)=>{const h=[],m=Array.from(o.childNodes);for(let f=0;f<m.length;f+=1){const p=m[f];if(p.nodeType===1&&JS(p,p.tagName.toLowerCase())&&XS(p)){const g=m.slice(f).flatMap(w=>i(w,c+1,!0));g.length>0&&h.push({t:"quote",kids:g});break}h.push(...i(p,c,u))}return h},i=(o,c,u)=>{if(o.nodeType===3){const N=o.nodeValue??"";return N===""?[]:[{t:"text",v:N}]}if(o.nodeType!==1)return[];const h=o,m=h.tagName.toLowerCase();if(sH.has(m))return[];if(s.nodes>=eH)return s.truncated=!0,[];if(c>tH)return s.truncated=!0,r(h);if(s.nodes+=1,!u&&JS(h,m)&&!XS(h)){const N=a(h,c+1,!0);return N.length>0?[{t:"quote",kids:N}]:[]}if(!rH.has(m))return a(h,c+1);const f=gH(h),p=YS(h.getAttribute("bgcolor"));if(p&&!f.backgroundColor&&(f.backgroundColor=p),m==="font"){const N=YS(h.getAttribute("color"));N&&!f.color&&(f.color=N);const b=h.getAttribute("face");b&&/^[\w\s,'"-]{1,80}$/.test(b)&&!f.fontFamily&&(f.fontFamily=b)}const x=(h.getAttribute("align")??"").toLowerCase();["left","right","center","justify"].includes(x)&&!f.textAlign&&m!=="img"&&m!=="table"&&(f.textAlign=x),m==="table"&&x==="center"&&(f.marginLeft=f.marginLeft??"auto",f.marginRight=f.marginRight??"auto");const g=(h.getAttribute("valign")??"").toLowerCase();if(["top","middle","bottom","baseline"].includes(g)&&!f.verticalAlign&&(f.verticalAlign=g),["table","td","th","img","col"].includes(m)){const N=qS(h.getAttribute("width")),b=qS(h.getAttribute("height"));N&&!f.width&&(f.width=N),b&&!f.height&&m!=="table"&&(f.height=b)}const w=Object.keys(f).length>0?{style:f}:{};if(m==="img"){const N=(h.getAttribute("src")??"").trim(),b=(h.getAttribute("alt")??"").slice(0,200);return/^https?:\/\//i.test(N)?QS(h,f)?(s.pixels+=1,[]):(s.remoteImages+=1,[{t:"img",kind:"remote",src:N,alt:b,...w}]):/^cid:/i.test(N)?[{t:"img",kind:"cid",src:N.slice(4).replace(/^<|>$/g,""),alt:b,...w}]:dH.test(N)&&N.length<=nH?QS(h,f)?(s.pixels+=1,[]):[{t:"img",kind:"data",src:N,alt:b,...w}]:b?[{t:"text",v:b}]:[]}const v=iH.has(m)?[]:a(h,c+1);if(m==="a"){const N=mP(h.getAttribute("href"));return N?[{t:"link",href:N.href,outside:N.outside,...w,kids:v}]:v.length>0?[{t:"el",tag:"span",...w,kids:v}]:[]}const j={};if(m==="td"||m==="th"){const N=Number.parseInt(h.getAttribute("colspan")??"",10),b=Number.parseInt(h.getAttribute("rowspan")??"",10);N>1&&N<=100&&(j.colSpan=N),b>1&&b<=100&&(j.rowSpan=b)}if(m==="ol"){const N=Number.parseInt(h.getAttribute("start")??"",10);Number.isFinite(N)&&(j.start=N)}if(m==="table"){const N=Number.parseInt(h.getAttribute("cellpadding")??"",10),b=Number.parseInt(h.getAttribute("cellspacing")??"",10);Number.isFinite(N)&&N>=0&&N<=40&&(j.cellPadding=N),Number.isFinite(b)&&b>=0&&b<=40&&(j.cellSpacing=b)}const y=h.getAttribute("title");y&&(j.title=y.slice(0,200));const k=(h.getAttribute("dir")??"").toLowerCase();return(k==="rtl"||k==="ltr"||k==="auto")&&(j.dir=k),[{t:"el",tag:aH[m]??m,...w,...Object.keys(j).length>0?{attrs:j}:{},kids:v}]};return{nodes:a(n.body,0),remoteImages:s.remoteImages,pixels:s.pixels,truncated:s.truncated}}const jH=/(wrote|a écrit|schrieb|escribió|scrisse|schreef|написал)\s*:\s*$/i,vH=/^(-{2,}\s*(original message|forwarded message|message d'origine)\s*-{2,}|_{10,})\s*$/i,ZS=2e5;function yH(e){const n=e.split(/\r?\n/),s=[];let r=[];const a=()=>{r.length>0&&s.push({t:"text",v:r.join(`
99
- `)}),r=[]},i=()=>{let l=r.length-1;for(;l>=0&&r[l].trim()==="";)l-=1;if(l<0||!jH.test(r[l]))return null;const o=r[l].trim();return r=r.slice(0,l),o};for(let l=0;l<n.length;l+=1){const o=n[l];if(vH.test(o.trim())){const c=i();return a(),s.push({t:"quote",head:c,inner:n.slice(l+1).join(`
100
- `)}),s}if(o.startsWith(">")){const c=[];let u=l;for(;u<n.length&&(n[u].startsWith(">")||n[u].trim()===""&&(n[u+1]??"").startsWith(">"));)c.push(n[u].replace(/^> ?/,"")),u+=1;const h=i();a(),s.push({t:"quote",head:h,inner:c.join(`
101
- `)}),l=u-1;continue}r.push(o)}return a(),s}const wH=/\bhttps?:\/\/[^\s<>"'`]+/gi;function bH(e){var r,a;const n=[];let s=0;for(const i of e.matchAll(wH)){let l=i[0];for(;/[.,;:!?)\]}'"]$/.test(l)&&!(l.endsWith(")")&&(((r=l.match(/\(/g))==null?void 0:r.length)??0)>=(((a=l.match(/\)/g))==null?void 0:a.length)??0));)l=l.slice(0,-1);const o=i.index??0,c=mP(l);!c||!c.outside||(o>s&&n.push({t:"text",v:e.slice(s,o)}),n.push({t:"link",href:c.href,v:l}),s=o+l.length)}return s<e.length&&n.push({t:"text",v:e.slice(s)}),n}const pP="buddi.mail.images.v1";function gP(){try{const e=window.localStorage.getItem(pP),n=e?JSON.parse(e):[];return new Set(Array.isArray(n)?n.filter(s=>typeof s=="string"):[])}catch{return new Set}}function eC(e,n){const s=e.trim().toLowerCase();if(s!=="")try{const r=gP();n?r.add(s):r.delete(s),window.localStorage.setItem(pP,JSON.stringify([...r].slice(-500)))}catch{}}const kH=8;function xP({children:e,head:n}){const[s,r]=d.useState(!1);return t.jsxs("div",{className:"pl-mail-quote","data-open":s?"true":void 0,children:[t.jsxs("button",{type:"button",className:"pl-mail-quote-toggle","aria-expanded":s,title:s?"Hide the earlier message":"Show the earlier message",onClick:()=>r(a=>!a),children:[t.jsx("span",{"aria-hidden":"true",children:"···"}),t.jsx("span",{className:"pl-mail-quote-words",children:s?"Hide earlier message":"earlier message"})]}),s?t.jsxs("div",{className:"pl-mail-quote-body",children:[n?t.jsx("p",{className:"pl-mail-quote-head",children:n}):null,e]}):null]})}function Jh(e,n,s=""){return e.map((r,a)=>NH(r,n,`${s}${a}`))}function NH(e,n,s){switch(e.t){case"text":return e.v;case"quote":return t.jsx(xP,{children:Jh(e.kids,n,`${s}.`)},s);case"link":return t.jsx("a",{href:e.href,style:e.style,...e.outside?{target:"_blank",rel:"noopener noreferrer"}:{},children:Jh(e.kids,n,`${s}.`)},s);case"img":{const r=e.style;if(e.kind==="remote")return n.showImages?t.jsx("img",{src:e.src,alt:e.alt,style:r,referrerPolicy:"no-referrer",loading:"lazy"},s):e.alt?t.jsx("span",{className:"pl-mail-img-held",children:e.alt},s):null;if(e.kind==="cid"){const a=n.cid(e.src);return a?t.jsx("img",{src:a,alt:e.alt,style:r,loading:"lazy"},s):t.jsx("span",{className:"pl-mail-img-held",children:e.alt||"Picture in an attachment"},s)}return t.jsx("img",{src:e.src,alt:e.alt,style:r},s)}case"el":return d.createElement(e.tag,{key:s,...e.style?{style:e.style}:{},...e.attrs??{}},...e.kids.length>0?Jh(e.kids,n,`${s}.`):[])}}function jP({text:e,depth:n=0}){const s=n>=kH?[{t:"text",v:e}]:yH(e);return t.jsx(t.Fragment,{children:s.map((r,a)=>r.t==="text"?t.jsx("div",{className:"pl-mail-text",children:bH(r.v).map((i,l)=>i.t==="link"?t.jsx("a",{href:i.href,target:"_blank",rel:"noopener noreferrer",children:i.v},l):t.jsx("span",{children:i.v},l))},a):t.jsx(xP,{head:r.head,children:t.jsx(jP,{text:r.inner,depth:n+1})},a))})}function SH({html:e,text:n,sender:s,attachments:r,cidSrc:a}){const i=d.useMemo(()=>e?xH(e):null,[e]),l=s.trim().toLowerCase(),o=d.useMemo(()=>gP().has(l),[l]),[c,u]=d.useState(null),h=c!==null&&c.who===l?c.show:o,m=p=>u({who:l,show:p}),f=p=>{const x=p.trim().replace(/^<|>$/g,"").toLowerCase(),g=(r??[]).find(w=>typeof w.contentId=="string"&&w.contentId.trim().replace(/^<|>$/g,"").toLowerCase()===x);return g!=null&&g.artifactId?a(g.artifactId):null};if(i&&i.nodes.length>0)return t.jsxs("div",{className:"pl-mail-body",children:[i.remoteImages>0?t.jsx("div",{className:"pl-mail-images",role:"status",children:h?t.jsxs(t.Fragment,{children:[t.jsxs("span",{children:["Pictures from ",s," are shown."]}),t.jsx($,{size:"sm",variant:"ghost",onClick:()=>{eC(s,!1),m(!1)},children:"Hide pictures from this sender"})]}):t.jsxs(t.Fragment,{children:[t.jsxs("span",{children:[i.remoteImages===1?"One picture is":`${i.remoteImages} pictures are`," held back, so the sender cannot see you opened this."]}),t.jsx($,{size:"sm",onClick:()=>{eC(s,!0),m(!0)},children:"Show images"})]})}):null,t.jsx("div",{className:"pl-mail-html",children:Jh(i.nodes,{showImages:h,cid:f})}),i.truncated?t.jsx("p",{className:"pl-mail-note",children:"Part of this message was too long or too deeply nested to show."}):null]});if(typeof n=="string"&&n.trim()!==""){const p=n.length>ZS;return t.jsxs("div",{className:"pl-mail-body",children:[t.jsx(jP,{text:p?n.slice(0,ZS):n}),p?t.jsx("p",{className:"pl-mail-note",children:"The rest of this message is too long to show here; it is in your mailbox."}):null]})}return null}const CH=["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 Re(e,n){if(n===""||n==="$")return e;let s=e;for(const r of n.split(".")){const a=/^([^[\]]*)((?:\[\d+\])*)$/.exec(r);if(!a)return;const[,i="",l=""]=a;if(i!==""){if(s===null||typeof s!="object")return;s=s[i]}for(const o of l.match(/\d+/g)??[]){if(!Array.isArray(s))return;s=s[Number(o)]}if(s===void 0)return}return s}function Be(e,n){if(n)return"const"in n?n.const:Re(e,n.path)}function Us(e){if(typeof e=="number")return Number.isFinite(e)?e:null;if(typeof e=="string"&&e.trim()!==""){const n=Number(e);return Number.isFinite(n)?n:null}return null}function Ot(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):null}function $a(e){return Array.isArray(e)?e:[]}function EH(e,n){const s=$a(Re(e,n.points)).map(a=>{const i=Us(Re(a,n.y)),l=Ot(Re(a,n.x));return i===null||l===null?null:{x:l,y:i}}).filter(a=>a!==null),r=(n.referenceLines??[]).map(a=>{const i=Us(Be(e,a.value));return i===null?null:{value:i,label:a.label,tone:a.tone??"neutral"}}).filter(a=>a!==null);return{points:s,unit:n.unit??"number",currency:Ot(Be(e,n.currency)),label:Ot(Be(e,n.label)),referenceLines:r,mark:n.mark??null,shadeBelow:Us(Be(e,n.shadeBelow)),events:AH(e,n)}}function AH(e,n){const s=n.events;if(!s)return[];const r=[],a=(i,l)=>{const o=Ot(Re(i,s.label));if(o===null)return;const c=Ot(Re(i,s.at))??l;c!==null&&r.push({at:c,label:o,amount:s.amount?Us(Re(i,s.amount)):null})};if(s.parent){for(const i of $a(Re(e,n.points))){const l=Ot(Re(i,n.x));for(const o of $a(Re(i,s.parent)))a(o,l)}return r}for(const i of $a(Re(e,s.path??n.points)))a(i,null);return r}function $H(e,n){const s=(n.columns??[]).map(o=>({key:o.key,label:o.label,type:o.type??"text"})),r=o=>(n.columns??[]).map(c=>{const u=Re(o,c.key);let h=null;if(c.bar){const m=Us(Be(o,c.bar.max))??Us(Be(e,c.bar.max)),f=Us(u);if(m!==null&&m>0&&f!==null){const p=Math.max(0,Math.min(1,f/m));h={fraction:p,tone:RH(p*100,c.bar.thresholds)}}}return{value:u,type:c.type??"text",currency:Ot(Be(o,c.currency))??Ot(Be(e,c.currency)),bar:h}}),a=$a(Re(e,n.rows)),i=n.groupBy?TH(a,n.groupBy,r):[{label:null,rows:a.map(r)}],l=(n.summary??[]).map(o=>({label:o.label,value:Be(e,o.value),unit:o.unit??"text",currency:Ot(Be(e,o.currency)),tone:o.tone??"neutral"}));return{columns:s,groups:i,summary:l,empty:n.empty??"Nothing to show."}}function TH(e,n,s){const r=new Map;for(const a of e){const i=String(Re(a,n.key)??""),l=r.get(i);l?l.push(a):r.set(i,[a])}return[...r.entries()].map(([a,i])=>{var l;return{label:((l=n.labels)==null?void 0:l[a])??a,rows:i.map(s)}})}function RH(e,n){var r;return!n||n.length===0?"neutral":((r=[...n].sort((a,i)=>i.atLeast-a.atLeast).find(a=>e>=a.atLeast))==null?void 0:r.tone)??"neutral"}function IH(e,n){return{bars:$a(Re(e,n.bars)).map(r=>{const a=Us(Re(r,n.value)),i=Ot(Re(r,n.category));return a===null||i===null?null:{category:i,value:a}}).filter(r=>r!==null),unit:n.unit??"number",currency:Ot(Be(e,n.currency))}}function PH(e,n){if(n.pairs)return{pairs:n.pairs.map(r=>({label:r.label,value:Be(e,r.value),unit:r.unit??"text",currency:Ot(Be(e,r.currency)),tone:r.tone??"neutral"}))};const s=Re(e,n.from??"$");return s===null||typeof s!="object"||Array.isArray(s)?{pairs:[]}:{pairs:Object.entries(s).map(([r,a])=>({label:nn(r),value:a,unit:"text",currency:null,tone:"neutral"}))}}const MH=new Set(["good","warning","critical","neutral","accent"]),OH=new Set(CH);function pv(e){return typeof e=="string"&&OH.has(e)?e:null}function $b(e,n,s=""){const r=n.empty??"Nothing to show.",a=s.split(".")[0]??"";if(n.notice){const l=Ot(Re(e,n.notice.text));if(l!==null&&l.trim()!==""){const o=n.notice.link&&a!==""?{plugin:a,page:n.notice.link.page}:null;return{tiles:[{icon:pv(n.notice.icon??"bell"),value:"",label:l.trim(),lines:[],tone:"neutral",link:o}],notice:!0,empty:r}}}return{tiles:$a(Re(e,n.items)).map(l=>{const o=Ot(Re(l,n.value))??"",c=Ot(Re(l,n.label))??"";if(o===""&&c==="")return null;const u=n.tone?Ot(Re(l,n.tone)):null;return{icon:pv(Be(l,n.icon)),value:o,label:c,lines:(n.lines??[]).slice(0,2).map(h=>Ot(Re(l,h))).filter(h=>h!==null&&h.trim()!==""),tone:u!==null&&MH.has(u)?u:"neutral",link:null}}).filter(l=>l!==null),notice:!1,empty:r}}function DH(e,n){const s=Ot(Be(e,n.kind)),r=s==="image"||s==="pdf"?s:"text",a=n.src?Ot(Re(e,n.src)):null;return{kind:r,text:n.text?Ot(Re(e,n.text)):null,src:a&&yP(a)?a:null,title:Ot(Be(e,n.title)),metadata:(n.metadata??[]).map(i=>({label:i.label,value:Be(e,i.value),unit:i.unit??"text"}))}}function LH(e,n){const s=n.diff?Re(e,n.diff):void 0;return{diff:typeof s=="string"&&s.trim()!==""?s:null,title:Ot(Be(e,n.title)),metadata:(n.metadata??[]).map(r=>({label:r.label,value:Be(e,r.value),unit:r.unit??"text"}))}}function FH(e,n){const s=n.output?Re(e,n.output):void 0,r=l=>{const o=l?Re(e,l):void 0;return typeof o=="number"&&Number.isInteger(o)?o:null},a=r(n.omittedBytes),i=n.elapsedMs?Re(e,n.elapsedMs):void 0;return{command:Ot(Be(e,n.command)),output:typeof s=="string"?s:null,exitCode:r(n.exitCode),elapsedMs:typeof i=="number"&&Number.isFinite(i)&&i>=0?i:null,omittedBytes:a!==null&&a>0?a:null,metadata:(n.metadata??[]).map(l=>({label:l.label,value:Be(e,l.value),unit:l.unit??"text"}))}}const _H=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function vP(e){const n=e!==null&&typeof e=="object"&&!Array.isArray(e)?e.artifactId??e.id:e;return typeof n=="string"&&_H.test(n)?n.toLowerCase():null}function zH(e,n){return{artifactId:n.src?vP(Re(e,n.src)):null,title:Ot(Be(e,n.title)),caption:Ot(Be(e,n.caption)),...n.captionLabel?{captionLabel:Ot(Be(e,n.captionLabel))}:{}}}function tC(e){if(!yP(e))return null;let n;try{n=new URL(e,"file:///").pathname}catch{return null}const s=/^\/preview\/([A-Za-z0-9][A-Za-z0-9_.-]*)\/([A-Za-z0-9][A-Za-z0-9_.-]*)\/?$/.exec(n);return s?{plugin:s[1],name:s[2]}:null}function UH(e,n){const s=n.src?Ot(Re(e,n.src)):null,r=n.port?Re(e,n.port):null,a=n.awaiting?Ot(Re(e,n.awaiting)):null;return{target:s?tC(s):null,title:Ot(Be(e,n.title)),output:n.output?Ot(Re(e,n.output)):null,port:typeof r=="number"&&Number.isInteger(r)&&r>0&&r<=65535?r:null,awaiting:a?tC(a):null,reloadsItself:n.reloadsItself?Re(e,n.reloadsItself)===!0:!1,ports:n.ports?BH(Re(e,n.ports)):[]}}function BH(e){const n=$a(e).filter(s=>typeof s=="number"&&Number.isInteger(s)&&s>0&&s<=65535);return[...new Set(n)].sort((s,r)=>s-r)}function yP(e){return e.startsWith("/")&&!e.startsWith("//")}function nn(e){const n=e.replace(/[_-]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").trim().toLowerCase();return n.charAt(0).toUpperCase()+n.slice(1)}function wP(e){return e.split(".")[0]??""}function WH(e,n,s){const r=wP(s);return n.rows!==void 0?{plugin:r,rows:$a(Re(e,n.rows)),value:e}:{plugin:r,value:e}}function HH(e,n,s){const r={};for(const[a,i]of Object.entries(n.params??{})){const l=Re(e,i);(typeof l=="string"||typeof l=="number"||typeof l=="boolean")&&(r[a]=String(l))}return{plugin:wP(s),query:n.query,params:r,body:Array.isArray(n.body)?n.body:[],value:e}}function bP(e,n){const s=e.map??{};switch(e.renderer){case"timeseries":return{renderer:"timeseries",props:EH(n,s)};case"table":return{renderer:"table",props:$H(n,s)};case"bars":return{renderer:"bars",props:IH(n,s)};case"keyvalue":return{renderer:"keyvalue",props:PH(n,s)};case"tiles":return{renderer:"tiles",props:$b(n,s,e.tool)};case"audio":return{renderer:"audio",props:{value:n}};case"story":return{renderer:"story",props:WH(n,s,e.tool)};case"query":return{renderer:"query",props:HH(n,s,e.tool)};case"document":return{renderer:"document",props:DH(n,s)};case"diff":return{renderer:"diff",props:LH(n,s)};case"terminal":return{renderer:"terminal",props:FH(n,s)};case"image":return{renderer:"image",props:zH(n,s)};case"preview":return{renderer:"preview",props:UH(n,s)};default:return{renderer:"structured",props:{value:n}}}}const nC={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 oc(e){return(e&&Object.prototype.hasOwnProperty.call(nC,e)?nC[e]:void 0)??"dot"}let Xh=null;typeof window<"u"&&window.addEventListener(Wf,()=>{Xh=null});function KH(){return Xh??(Xh=Promise.resolve().then(()=>T.pages()).then(e=>Array.isArray(e==null?void 0:e.pages)?e.pages:[]).catch(()=>(Xh=null,[]))),Xh}function Tb(e,n,s){return s==="settings"?Or(e,n):Mr(e,n)}function VH(e){const[n,s]=d.useState(null),r=e==null?void 0:e.plugin,a=e==null?void 0:e.page;return d.useEffect(()=>{if(!r||!a)return;let i=!1;return KH().then(l=>{const o=l.find(c=>c.plugin===r&&c.id===a);i||s(o?{href:Tb(r,a,o.place),label:o.place==="settings"?`Settings → ${o.title}`:o.title}:null)}),()=>{i=!0}},[r,a]),n}const yi="••••",kP=new WeakMap;function hi(e){return e===null||typeof e!="object"?e:kP.get(e)??e}function GH(e){const n=[];for(const s of e.split(".")){const r=/^([^[\]]*)((?:\[\])*)$/.exec(s);if(r){r[1]&&n.push({key:r[1]});for(let a=0;a<(r[2]??"").length/2;a++)n.push({each:!0})}}return n}function sC(e,n){return kP.set(e,hi(n)),e}function gv(e,[n,...s]){if(e==null)return e;if(n===void 0)return yi;if("each"in n)return Array.isArray(e)?sC(e.map(a=>gv(a,s)),e):e;if(typeof e!="object"||Array.isArray(e)||!Object.prototype.hasOwnProperty.call(e,n.key))return e;const r=e;return sC({...r,[n.key]:gv(r[n.key],s)},r)}function qH(e,n){if(!n||n.length===0)return e;let s=e;for(const r of n)s=gv(s,GH(r));return s}function NP(){return t.jsx("span",{className:"pp-masked",role:"img","aria-label":"hidden",children:[...yi].map((e,n)=>t.jsx("span",{className:"pp-mask-dot",children:e},n))})}function Rb({shown:e,onToggle:n,show:s="Show",hide:r="Hide",size:a}){return t.jsxs($,{className:"pp-reveal",size:a,onClick:n,children:[t.jsx(ne,{name:"eye",size:a==="sm"?14:16}),t.jsx("span",{children:e?r:s})]})}function ea({text:e}){if(e==null)return null;if(!e.includes(yi))return t.jsx(t.Fragment,{children:e});const n=e.split(yi),s=[];return n.forEach((r,a)=>{r&&s.push(r),a<n.length-1&&s.push(t.jsx(NP,{},a))}),t.jsx(t.Fragment,{children:s})}function jp(e){return e===yi?!0:Array.isArray(e)?e.some(jp):!1}function SP({props:e,layout:n,selected:s,onPick:r}){return e.tiles.length===0?t.jsx("p",{className:"wb-empty",children:e.empty}):t.jsx("ul",{className:"wb-tiles","data-notice":e.notice?"true":void 0,"data-layout":n&&n!=="grid"?n:void 0,style:n==="row"?{"--tiles-n":e.tiles.length}:void 0,children:e.tiles.map((a,i)=>t.jsx(YH,{tile:a,...r?{picked:i===s,onPick:()=>r(i)}:{}},`${i}-${a.label}`))})}function YH({tile:e,picked:n,onPick:s}){const r=VH(e.link),a=[e.label,e.value,...e.lines].filter(l=>l!=="").map(l=>l.split(yi).join("hidden")).join(", "),i=t.jsxs("div",{className:"wb-tile-body","aria-hidden":"true",children:[t.jsx("span",{className:"wb-tile-icon","data-icon":e.icon??"dot",children:t.jsx(ne,{name:oc(e.icon),size:22})}),e.value!==""?t.jsx("span",{className:"wb-tile-value tnum",children:t.jsx(ea,{text:e.value})}):null,t.jsx("span",{className:"wb-tile-label",children:e.label}),e.lines.map((l,o)=>t.jsx("span",{className:"wb-tile-line",children:t.jsx(ea,{text:l})},o))]});return s?t.jsx("li",{className:"wb-tile",children:t.jsx("button",{type:"button",className:"ui-card","data-tone":n?"accent":e.tone==="neutral"?void 0:e.tone,"data-selected":n?"true":void 0,"aria-pressed":n===!0,"aria-label":a,onClick:s,children:i})}):t.jsxs("li",{className:"wb-tile",children:[t.jsx("span",{className:"sr-only",children:a}),t.jsxs(Br,{tone:e.tone==="neutral"?void 0:e.tone,children:[i,r?t.jsx("a",{className:"wb-tile-link",href:r.href,children:r.label}):null]})]})}function Ls({tone:e="accent",icon:n,title:s,href:r,onOpen:a,from:i,time:l,dismiss:o,extraDismiss:c,lead:u,actions:h,compact:m,kind:f,children:p}){const g=`${d.useId()}-title`,w=(j,y)=>t.jsx($,{variant:"ghost",size:m?"sm":void 0,title:j.hint,disabled:j.disabled,onClick:j.onClick,children:j.label??y}),v=!!(o||c||u||h);return t.jsx(Br,{as:"article",labelledBy:g,...m?{density:"compact"}:{},children:t.jsxs("div",{className:"needs-card","data-tone":e,"data-compact":m?"true":void 0,"data-kind":f,children:[t.jsx("span",{className:"needs-card-mark","aria-hidden":"true",children:n?t.jsx(ne,{name:n,size:m?14:16}):t.jsx("i",{className:"needs-card-dot"})}),t.jsxs("div",{className:"needs-card-main",children:[t.jsxs("div",{className:"needs-card-head",children:[t.jsx("h3",{className:"needs-card-title",id:g,children:r||a?t.jsx("a",{href:r??"#",onClick:j=>{a&&(j.preventDefault(),a())},children:s}):s}),l?t.jsx("span",{className:"needs-card-time",children:l}):null]}),i?t.jsx("div",{className:"needs-card-from",children:i}):null,p?t.jsx("div",{className:"needs-card-body",children:p}):null,v?t.jsxs("div",{className:"needs-card-actions",children:[o||c||u?t.jsxs("div",{className:"needs-card-out",children:[o?w(o,"Not now"):null,c?w(c,"Not this again"):null,u]}):null,h?t.jsx("div",{className:"needs-card-do",children:h}):null]}):null]})]})})}function Ku({face:e,children:n}){return t.jsxs(t.Fragment,{children:[e,t.jsx("span",{className:"needs-card-from-text",children:n})]})}function QH(e){const n={};for(const s of e??[])n[s.key]=s.default;return n}function Ib(e){const[n,s]=d.useState({}),r=e??[],a={...QH(r),...n};return r.length===0?{values:void 0,controls:null}:{values:a,controls:t.jsx("div",{className:"ui-choices",children:r.map(i=>t.jsx(le,{label:i.label,inline:!0,children:t.jsx("select",{value:a[i.key],onChange:l=>s(o=>({...o,[i.key]:l.target.value})),children:i.options.map(l=>t.jsx("option",{value:l,children:l},l))})},i.key))})}}function Pb(e){const[n,s]=d.useState(null),[r,a]=d.useState(null),[i,l]=d.useState(null);return{busy:n,note:r,failure:i,decide:async(c,u,h,m)=>{var p,x,g,w;s(c),l(null),a(null);let f;try{const v=m?await T.decide(c,u,h,m):await T.decide(c,u,h);f={decision:u,...(p=v.execution)!=null&&p.state?{state:v.execution.state}:{},...v.execution&&"result"in v.execution?{result:v.execution.result}:{}},a(u==="reject"?`Rejected ${v.action.tool}.`:((x=v.execution)==null?void 0:x.state)==="succeeded"?`Approved and done: ${v.action.tool}.`:`Approved ${v.action.tool}: ${((g=v.execution)==null?void 0:g.state)??"no execution"}${(w=v.execution)!=null&&w.message?` (${v.execution.message})`:""}`)}catch(v){l(v instanceof Error?v.message:String(v))}finally{s(null),e(f)}}}}function JH(e){var r;if((r=e.ask)!=null&&r.trim())return e.ask.trim();const s=(e.preview.split(`
102
- `).map(a=>a.trim()).find(Boolean)??"").split(" — ")[0].trim();return s&&s!==e.tool&&!s.startsWith(`${e.tool} `)&&!/^[[{"]/.test(s)?s:"An action needs your approval"}function XH(e,n){const s=e.trim(),r=n.replace(/…$/,"");return!r||!s.toLowerCase().startsWith(r.toLowerCase())||n.endsWith("…")?s:s.slice(r.length).replace(/^[:.\s]*(—\s*)?/,"").trim()}function Mb({action:e,timezone:n,busy:s,onDecide:r,agentName:a,agents:i}){var x,g,w;const[l,o]=d.useState(!1),{values:c,controls:u}=Ib(e.choices),h=v=>c?r(e.id,"approve",v,c):r(e.id,"approve",v),m=!!((x=e.permissionScopes)!=null&&x.length),f=JH(e),p=XH(e.preview,f);return t.jsxs(Ls,{kind:"approval",tone:"accent",icon:"lock",title:f,time:Xe(e.createdAt),from:Uu(e.agentId)?t.jsxs(Ku,{face:t.jsx(QI,{size:"sm"}),children:["Asked by ",zu]}):t.jsxs(Ku,{face:i?t.jsx(vn,{agents:i,id:e.agentId,size:"sm"}):void 0,children:["Asked by ",a??e.agentId]}),lead:t.jsx($,{variant:"ghost",onClick:()=>o(v=>!v),"aria-expanded":l,children:l?"Hide envelope":"Show envelope"}),actions:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:e.answers?"ghost":"danger",disabled:s,onClick:()=>r(e.id,"reject"),children:((g=e.answers)==null?void 0:g.reject)??"Reject"}),m?t.jsxs(t.Fragment,{children:[t.jsx($,{disabled:s,onClick:()=>h("conversation"),children:"Auto: this conversation"}),t.jsx($,{disabled:s,onClick:()=>h("always"),children:"Always: this agent"})]}):null,t.jsx($,{variant:"accent",disabled:s,onClick:()=>h(),children:((w=e.answers)==null?void 0:w.approve)??(m?"Allow once":"Approve")})]}),children:[p?t.jsx(Zt,{children:p}):null,t.jsxs("p",{className:"ui-card-meta",children:[t.jsx("span",{className:"mono",children:e.tool})," v",e.toolVersion,". Expires ",St(e.expiresAt,n)," (",Xe(e.expiresAt),"). Policy v",e.policyVersion,", args ",Iu(e.argsHash,12),e.jobId?`, job ${Iu(e.jobId)}`:"","."]}),u,l?t.jsxs("div",{className:"ui-card-foot",children:[t.jsx(ye,{title:"Envelope: everything that decides what the world will see",children:t.jsx(Zt,{children:ms(e.envelope)})}),t.jsx(ye,{title:"Canonical arguments",children:t.jsx(Zt,{children:ms(e.canonicalArgs)})})]}):null]})}function Ob(e,n,s){const[r,a]=d.useState(!1),[i,l]=d.useState(null),[o,c]=d.useState(null);return{accept:()=>{e&&(a(!0),c(null),T.acceptPluginAgent(e,n).then(h=>{l(h.agent),s==null||s(h.agent)}).catch(h=>c(h instanceof pe?h.message:String(h))).finally(()=>a(!1)))},busy:r,created:i,failure:o}}function CP({agent:e}){return t.jsxs(Q,{tone:"good",role:"status",children:["@",e.handle," is ready. ",t.jsxs("a",{href:ut(e.id),children:["Talk to @",e.handle]})]})}function EP(e,n,s){const r=e.canonicalArgs;return e.tool==="platform.accept_plugin_agent"&&(r==null?void 0:r.plugin)===n&&typeof r.agent=="string"&&r.agent.toLowerCase()===s.toLowerCase()}function ZH(e,n){var a;const s=je(()=>T.approvals(),[e,n],15e3);return{action:((a=s.data)==null?void 0:a.pending.find(i=>EP(i,e,n)))??null,reload:s.reload}}function rC({action:e,onDecided:n}){const{busy:s,failure:r,decide:a}=Pb(i=>n(i));return t.jsxs(ue,{gap:"sm",children:[t.jsx(Mb,{action:e,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,busy:s===e.id,onDecide:(i,l,o,c)=>{a(i,l,o,c)}}),t.jsx(re,{message:r})]})}function Db({plugin:e,agent:n,text:s,label:r,handle:a,onDismiss:i,card:l}){var p;const o=Ob(e,n),c=ZH(e,n),[u,h]=d.useState(null),m=o.created??u,f=a??((p=/@(\S+)/.exec(r))==null?void 0:p[1])??n;if(m&&l)return t.jsx(Ls,{kind:"offer",tone:"accent",icon:"check",title:`@${m.handle} is ready`,from:l.from,actions:t.jsxs(it,{variant:"accent",href:ut(m.id),children:["Talk to @",m.handle]})});if(m)return t.jsx(CP,{agent:m});if(c.action){const x=g=>{(g==null?void 0:g.decision)==="approve"&&g.state==="succeeded"?h({id:n,handle:f,name:f}):c.reload()};return l?t.jsx(rC,{action:c.action,onDecided:x}):t.jsxs(ue,{gap:"sm",children:[t.jsx("span",{children:s}),t.jsx(rC,{action:c.action,onDecided:x})]})}return l?t.jsxs(Ls,{kind:"offer",tone:"accent",icon:"agents",title:`Set up @${f}`,from:l.from,...i?{dismiss:{onClick:i,disabled:o.busy,hint:"Hide this offer"}}:{},actions:t.jsx($,{variant:"accent",disabled:o.busy,onClick:o.accept,children:r}),children:[t.jsx("p",{children:s}),t.jsx(re,{message:o.failure})]}):t.jsxs(ue,{gap:"sm",children:[t.jsxs(te,{children:[t.jsx("span",{children:s}),t.jsx(ht,{}),i?t.jsx($,{variant:"ghost",disabled:o.busy,onClick:i,children:"Not now"}):null,t.jsx($,{variant:"accent",disabled:o.busy,onClick:o.accept,children:r})]}),t.jsx(re,{message:o.failure})]})}function AP(){var n;const e=je(()=>T.agentOffers(),[],6e4);return{offers:((n=e.data)==null?void 0:n.offers)??[],reload:e.reload}}function $P({offers:e,reload:n}){return e.length===0?null:t.jsx(ye,{title:"From your plugins",aside:`${e.length} to decide`,panel:!0,children:t.jsx(ue,{gap:"sm",divided:!0,children:e.map(s=>t.jsx(Db,{plugin:s.plugin,agent:s.agent,text:s.text,label:`Create @${s.handle}`,handle:s.handle,onDismiss:()=>{T.dismissAgentOffer(s.plugin,s.agent).then(n,n)}},`${s.plugin}/${s.agent}`))})})}const eK={work:"Work",money:"Money",home:"Home",health:"Health",learning:"Learning",life:"Life"},Lb=e=>eK[e]??vp(e);function vp(e){return e.charAt(0).toUpperCase()+e.slice(1)}function yn(e){return e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function Mo(e){return e.replace(/\.0$/,"")}function tK(e){return e.avatar?T.marketAssetUrl(e.avatar):void 0}const nK={mailbox:{title:"your mailbox",fix:"Add a mailbox",route:Or("email","settings")},"image-account":{title:"a drawing account",fix:"Choose a drawing account",route:Or("image","settings")}};function Fb(e){return nK[e.replace(/\?$/,"")]??{title:e,fix:"Set it up",route:ze()}}const yp=e=>vp(e);function _b(e){return e.kind==="plugin"?e.title:Fb(e.name).title}function Gf(e){if(e.kind==="need"){const n=Fb(e.name);return{label:n.fix,route:n.route}}return e.fix==="enable"?{label:`Turn on ${e.title}`,route:ze("plugins")}:e.fix==="update"?{label:`Update ${e.title}`,route:ze("plugins")}:e.byBuddi?null:{label:`Install ${e.title}`,route:ze("plugins")}}function sK(e,n,s){const r=new Set((e.missing??[]).map(o=>o.name)),i=[...Object.keys(e.requires),...Object.keys(e.optional)].filter(o=>!r.has(o)&&n.has(o)).map(yp),l=e.needs.includes("mailbox")||e.needs.includes("mailbox?");return s===!0&&l&&!r.has("mailbox")&&i.push("your mailbox"),i}function Rg(e){return vp(e.replace(/\.md$/i,"").replace(/[-_]+/g," ").trim())}const aC=(e,n)=>e.includes(n),rK={email:{title:"Mail",line:e=>aC(e,"email.draft")||aC(e,"email.*")?"Reads and searches your mail. Writes drafts; you send them.":"Searches and reads your mail."},calendar:{title:"Calendar",line:()=>"Reads your calendars. Never adds or moves an event."},weather:{title:"Weather",line:()=>"Reads the forecast for your places."},reminder:{title:"Reminders",line:e=>e.some(n=>n.startsWith("schedule."))?"Sets reminders and runs its own missions.":"Sets reminders."},memory:{title:"Memory",line:()=>"Remembers what you tell it. You can read every note."},owner:{title:"You",line:()=>"Messages you when something needs you."},web:{title:"Web",line:()=>"Searches and reads web pages."},artifacts:{title:"Files",line:()=>"Reads what you share in Files."},finance:{title:"Finance",line:()=>"Reads your accounts, cards, loans and statements."},image:{title:"Image",line:()=>"Makes pictures with your drawing account."},speech:{title:"Speech",line:()=>"Says words out loud."},goal:{title:"Goals",line:()=>"Keeps your goals and progress."},canvas:{title:"Canvas",line:()=>"Draws on the canvas beside your chat."}},aK={schedule:"reminder",browser:"web"};function qf(e,n=new Map){const s=[],r=new Map;for(const a of e){const i=a.replace(/\?$/,""),l=i.split(".")[0]??i,o=aK[l]??l;r.has(o)||(r.set(o,[]),s.push(o)),r.get(o).push(i)}return s.map(a=>{const i=r.get(a),l=rK[a],o=i.some(u=>n.get(u)==="gated"||u.endsWith(".*")&&[...n].some(([h,m])=>m==="gated"&&h.startsWith(u.slice(0,-1)))),c=l?l.line(i):`${i.length===1?"One of its tools":`${i.length} of its tools`}.`;return[(l==null?void 0:l.title)??vp(a),o&&!/asks you/i.test(c)?`${c} Asks you first before it changes anything.`:c]})}function iC(e){return e.length===0?"Nothing beyond its own chat.":`Reaches ${yn(e.map(([n])=>n))}.`}function Yf(e){return new Map((e??[]).filter(n=>n.tier).map(n=>[n.name,n.tier]))}function El({entry:e,size:n}){const s=tK(e);return t.jsx("span",{className:"cat-face","data-size":n,children:t.jsx(Bn,{id:e.name,name:e.title,size:n==="xxl"?"xl":n,face:{tools:e.tools,...s?{picture:s}:{}}})})}const TP=800,iK=e=>{var n;return((n=/^.*?[.!?](?=\s|$)/.exec(e.trim()))==null?void 0:n[0])??e.trim()},vo=e=>e instanceof pe?e.message:String(e);function ya({entry:e,children:n}){return t.jsxs("span",{className:"plugins-sheet-title",children:[t.jsx(El,{entry:e,size:"lg"}),t.jsxs("span",{className:"plugins-sheet-name",children:[t.jsx("span",{children:n}),t.jsxs("span",{className:"plugins-sheet-by",children:["by ",e.author.name,e.trust==="by-buddi"?t.jsxs(t.Fragment,{children:[" · ",t.jsx($e,{tone:"accent",children:"by buddi"})]}):null]})]})]})}function Ig({state:e,children:n}){return t.jsxs("li",{className:"cat-step","data-state":e,children:[t.jsx("span",{className:"cat-step-mark",children:e==="done"?t.jsx(ne,{name:"check",size:12}):e==="failed"?t.jsx(ne,{name:"alert",size:14}):null}),t.jsx("span",{children:n})]})}function Pg(e){const n=e.kind==="plugin"?["Installing","Installed"]:["Adding","Added"];return e.state==="done"?{state:"done",words:`${n[1]} ${e.title}`}:e.state==="failed"?{state:"failed",words:e.kind==="plugin"?`${e.title} didn’t install`:`${e.title} wasn’t added`}:e.state==="waiting"?{state:"next",words:`${n[0]} ${e.title}`}:{state:"now",words:`${n[0]} ${e.title}…`}}function lK(e){const[n,s]=d.useState(null),[r,a]=d.useState(null);return d.useEffect(()=>{if(s(null),a(null),!e)return;let i=!1,l;const o=()=>{T.catalogueJob(e).then(c=>{i||(s(c),c.state==="running"&&(l=window.setTimeout(o,TP)))}).catch(c=>{i||a(vo(c))})};return o(),()=>{i=!0,l!==void 0&&window.clearTimeout(l)}},[e]),{job:n,error:r,setJob:s}}function zb({entry:e,navigate:n,onClose:s,onAdded:r}){var Ue;const a=ts("(max-width: 720px)"),[i,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState({}),[m,f]=d.useState(""),[p,x]=d.useState([]),[g,w]=d.useState(!1),[v,j]=d.useState(null),[y,k]=d.useState(!1),[N,b]=d.useState(null),{job:S,error:C,setJob:A}=lK(v),[E,R]=d.useState(!1),[P,O]=d.useState(null),[I,F]=d.useState(!1),U=d.useRef(!1),[L,M]=d.useState([]);d.useEffect(()=>{if(!i||i.plugins.length===0)return;let G=!1;return Promise.resolve().then(()=>T.market()).then(ae=>{G||M((ae==null?void 0:ae.plugins)??[])}).catch(()=>{}),()=>{G=!0}},[i]),d.useEffect(()=>{let G=!1;return T.cataloguePlan(e.name).then(ae=>{G||(l(ae),h(Object.fromEntries(ae.fills.map(J=>[J.id,J.value]))),f(ae.handle))}).catch(ae=>{G||c(vo(ae))}),()=>{G=!0}},[e.name]),d.useEffect(()=>{(S==null?void 0:S.state)==="done"&&S.agent&&!U.current&&(U.current=!0,r==null||r(S.agent))},[S,r]);const z=()=>{i&&(k(!0),b(null),U.current=!1,T.catalogueInstall(e.name,{version:i.version,fills:u,handle:m,missionsOn:p,tools:i.tools.map(G=>G.name)}).then(G=>j(G.jobId)).catch(G=>b(vo(G))).finally(()=>k(!1)))},D=()=>{j(null),z()},K=e.title,B=S==null?void 0:S.agent,se=G=>{B&&(G&&fd(B.id,G),s(),n(ut(B.id)))},W=G=>{S&&(R(!0),O(null),T.catalogueConfirm(S.id,G).then(ae=>{A(ae),G||s()}).catch(ae=>O(vo(ae))).finally(()=>R(!1)))};if((S==null?void 0:S.state)==="confirm"&&S.confirm){const G=qf(S.confirm.tools.map(J=>J.name),Yf(S.confirm.tools)),ae=S.steps.filter(J=>J.kind==="plugin"&&J.state==="done").map(J=>J.title);return t.jsxs(Ye,{title:t.jsxs(ya,{entry:e,children:["Add ",K]}),onClose:s,foot:t.jsxs(te,{children:[t.jsx(ht,{}),t.jsx($,{variant:"ghost",disabled:E,onClick:()=>W(!1),children:"Don’t add it"}),t.jsxs($,{variant:"accent",disabled:E,onClick:()=>W(!0),children:["Add ",K]})]}),children:[t.jsx("ol",{className:"cat-steps","data-testid":"cat-confirm",children:S.steps.filter(J=>J.kind==="plugin").map(J=>{const{state:Ne,words:Ie}=Pg(J);return t.jsx(Ig,{state:Ne,children:Ie},`${J.kind}-${J.name}`)})}),t.jsxs(Q,{tone:"warning",title:`${K} would get more than the list showed.`,children:[ae.length>0?`With ${yn(ae)} installed, `:"","its tools resolved to a different set",S.confirm.unshown.length>0?`, including ${yn(S.confirm.unshown)}`:"",". Look at what it can reach before you add it."]}),t.jsx(re,{message:P}),t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"What it can reach"}),t.jsxs("p",{className:"cat-prose",children:[iC(G)," ",t.jsx("button",{type:"button",className:"plugins-link cat-link",onClick:()=>F(!I),children:I?"Hide":"See all"})]}),I?t.jsx("dl",{className:"cat-reach",children:G.map(([J,Ne])=>t.jsxs("div",{className:"cat-reach-row",children:[t.jsx("dt",{children:J}),t.jsx("dd",{children:Ne})]},J))}):null]}),t.jsx("p",{className:"cat-small",children:"The plugins stay installed either way; Settings → Plugins removes them."})]})}if(v&&(!S||S.state==="running")){const G=S==null?void 0:S.steps[S.steps.length-1],ae=(S==null?void 0:S.approvalId)&&(G==null?void 0:G.state)==="adding";return t.jsxs(Ye,{title:t.jsxs(ya,{entry:e,children:["Add ",K]}),onClose:s,foot:t.jsx(te,{align:"end",children:t.jsx($,{onClick:s,children:"Close"})}),children:[t.jsx("ol",{className:"cat-steps","aria-live":"polite","data-testid":"cat-progress",children:((S==null?void 0:S.steps)??[]).map(J=>{const{state:Ne,words:Ie}=Pg(J);return t.jsx(Ig,{state:Ne,children:Ie},`${J.kind}-${J.name}`)})}),ae?t.jsxs(Q,{tone:"accent",action:t.jsx($,{size:"sm",onClick:()=>{s(),n(Io)},children:"Open it"}),children:["Adding ",K," waits for your approval in Needs you."]}):null,t.jsx(re,{message:C}),t.jsxs("p",{className:"cat-small",children:["You can close this; it carries on, and ",K," joins the team when it’s done."]})]})}if((S==null?void 0:S.state)==="done"){const G=S.steps.filter(Ne=>Ne.kind==="plugin").map(Ne=>Ne.title),ae=(i==null?void 0:i.missions.length)??e.missions.length,J=p.length;return t.jsxs(Ye,{title:t.jsx(ya,{entry:e,children:K}),onClose:s,foot:t.jsxs(te,{children:[t.jsx($,{variant:"ghost",onClick:()=>{s(),n(En())},children:"Back to teammates"}),t.jsx(ht,{}),t.jsx($,{variant:"accent",onClick:()=>se(),children:"Say hello"})]}),children:[t.jsxs("div",{className:"cat-done","data-testid":"cat-done",children:[t.jsx(El,{entry:e,size:"xxl"}),t.jsxs("p",{className:"cat-done-title",children:[K," is on your team."]}),t.jsxs("p",{className:"cat-small",children:["@",(B==null?void 0:B.handle)??m,G.length?` · ${yn(G)} installed`:"",ae>0&&J<ae?` · ${ae-J===1?"a mission":"missions"} off until you turn ${ae-J===1?"it":"them"} on`:""]})]}),e.examples.length>0?t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"Try one"}),t.jsx("div",{className:"wb-starters",children:e.examples.map(Ne=>t.jsx("button",{type:"button",className:"wb-starter",onClick:()=>se(Ne),children:Ne},Ne))})]}):null]})}if((S==null?void 0:S.state)==="failed"){const G=S.steps.find(ae=>ae.kind==="plugin"&&ae.state==="failed");return t.jsxs(Ye,{title:t.jsxs(ya,{entry:e,children:[K," wasn’t added"]}),onClose:s,foot:t.jsxs(te,{children:[t.jsx(ht,{}),t.jsx($,{variant:"ghost",onClick:s,children:"Close"}),t.jsx($,{variant:"accent",disabled:y,onClick:D,children:"Try again"})]}),children:[t.jsx("ol",{className:"cat-steps","data-testid":"cat-failed",children:S.steps.map(ae=>{const{state:J,words:Ne}=Pg(ae);return t.jsx(Ig,{state:J==="now"?"next":J,children:J==="now"?Ne.replace(/…$/,""):Ne},`${ae.kind}-${ae.name}`)})}),t.jsx(Q,{tone:"critical",title:`${S.error??"It stopped before it finished"}.`,action:S.approvalId?t.jsx($,{size:"sm",onClick:()=>{s(),n(Io)},children:"Open the approval"}):void 0,children:t.jsxs("p",{children:["Nothing was added and nothing else changed.",G?t.jsxs(t.Fragment,{children:[" ",G.title," waits in"," ",t.jsx("a",{href:ze("plugins"),onClick:ae=>{ae.preventDefault(),s(),n(ze("plugins"))},children:"Settings → Plugins"})," ","if you’d rather look at it there."]}):null]})}),t.jsx(re,{message:N})]})}const xe=(i==null?void 0:i.plugins.filter(G=>G.fix==="install"&&G.byBuddi))??[],me=(i==null?void 0:i.blocked)??[],ie=me[0],H=ie?Gf(ie):null,de=qf(i?i.tools.map(G=>G.name):e.tools,Yf([...((Ue=e.claims)==null?void 0:Ue.tools)??[],...((i==null?void 0:i.tools)??[]).filter(G=>G.tier!=="unknown")])),ge=G=>{var ae;return((ae=e.missions.find(J=>J.id===G))==null?void 0:ae.when)??""};return t.jsxs(Ye,{title:t.jsxs(ya,{entry:e,children:["Add ",K]}),onClose:s,foot:t.jsxs(te,{children:[a?null:t.jsx("span",{className:"plugins-foot-note",children:xe.length?`Installs ${yn(xe.map(G=>G.title))}, then adds ${K}.`:"Nothing runs until you add it."}),t.jsx(ht,{}),t.jsx($,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsxs($,{variant:"accent",disabled:!i||me.length>0||y||m.length<2,onClick:z,children:["Add ",K]})]}),children:[t.jsxs("p",{className:"cat-lede",children:[e.pitch," One approval adds it; you can change or remove it from its page."]}),t.jsx(re,{message:o??N}),!i&&!o?t.jsx(Ee,{children:"Reading what it needs…"}):i?t.jsxs(ue,{divided:!0,gap:"lg",children:[xe.length>0?t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"Installed on the way"}),t.jsx("ul",{className:"cat-plugins",children:xe.map(G=>{const ae=L.find(J=>J.name===G.name);return t.jsxs("li",{children:[t.jsx(ss,{svg:ae==null?void 0:ae.iconSvg}),t.jsxs("span",{className:"cat-plugin-text",children:[t.jsxs("span",{className:"cat-plugin-name",children:[G.title," ",G.version?t.jsx("span",{className:"plugins-ver",children:G.version}):null]}),t.jsx("span",{className:"cat-small",children:ae!=null&&ae.summary?iK(ae.summary):"Made by buddi; installed only if it matches what withbuddi.com lists."})]}),t.jsx($e,{tone:"accent",children:"by buddi"})]},G.name)})})]}):null,ie?t.jsxs(Q,{tone:"warning",action:H?t.jsx($,{size:"sm",onClick:()=>{s(),n(H.route)},children:H.label}):void 0,children:[K," needs ",yn(me.map(_b))," first. Add ",me.length===1?"it":"them",", then come back; nothing is added until then."]}):null,i.fills.length>0?t.jsxs("div",{className:"cat-block",children:[t.jsxs("h3",{className:"cat-block-title",children:["A few picks ",t.jsx("span",{className:"cat-block-aside",children:"filled in for you"})]}),t.jsx("div",{className:"cat-fills",children:i.fills.map(G=>t.jsx(le,{label:t.jsxs(t.Fragment,{children:[G.label,G.optional?t.jsx("span",{className:"faint",children:" · optional"}):null]}),children:G.choices&&G.choices.length>0?t.jsxs("select",{value:u[G.id]??"",onChange:ae=>h({...u,[G.id]:ae.target.value}),children:[G.kind==="calendar"?t.jsx("option",{value:"",children:"All of them"}):null,G.choices.map(ae=>t.jsx("option",{value:ae,children:ae},ae))]}):G.kind==="time"?t.jsx("input",{type:"time",value:u[G.id]??"",onChange:ae=>h({...u,[G.id]:ae.target.value})}):t.jsx("input",{value:u[G.id]??"",onChange:ae=>h({...u,[G.id]:ae.target.value})})},G.id))})]}):null,t.jsx("div",{className:"cat-block",children:t.jsx(le,{label:"Handle",hint:"How you call it in chat and on Telegram.",children:t.jsxs("span",{className:"cat-handle",children:[t.jsx("span",{className:"mono faint",children:"@"}),t.jsx("input",{className:"mono","aria-label":"Handle",value:m,onChange:G=>f(G.target.value.toLowerCase().replace(/[^a-z0-9-]/g,""))})]})})}),i.missions.length>0?t.jsxs("div",{className:"cat-block",children:[t.jsxs("h3",{className:"cat-block-title",children:["Missions ",t.jsx("span",{className:"cat-block-aside",children:"off unless you turn one on"})]}),t.jsx("ul",{className:"cat-missions","data-switches":"true",children:i.missions.map(G=>t.jsxs("li",{children:[t.jsx("span",{className:"cat-mission-name",children:G.name}),t.jsx("span",{className:"cat-mission-when",children:ge(G.id)}),t.jsx(ac,{checked:p.includes(G.id),label:`Turn on ${G.name}`,onChange:ae=>x(ae?[...p,G.id]:p.filter(J=>J!==G.id))})]},G.id))})]}):null,t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"What it can reach"}),t.jsxs("p",{className:"cat-prose",children:[iC(de)," ",t.jsx("button",{type:"button",className:"plugins-link cat-link",onClick:()=>w(!g),children:g?"Hide":"See all"})]}),g?t.jsx("dl",{className:"cat-reach",children:de.map(([G,ae])=>t.jsxs("div",{className:"cat-reach-row",children:[t.jsx("dt",{children:G}),t.jsx("dd",{children:ae})]},G))}):null]})]}):null]})}function oK(e){const n=[];let s=null,r=0;for(const a of e){const i=/^@@ -\d+,\d+ \+(\d+),(\d+) @@$/.exec(a);if(i){const c=Number(i[2])===0?Number(i[1])+1:Number(i[1]);n.length>0&&c-1>r&&n.push({kind:"gap",count:c-1-r}),s=c;continue}const l=a.startsWith("+ ")?"add":a.startsWith("- ")?"del":"ctx",o=l==="ctx"&&!a.startsWith(" ")?a:a.slice(2);l==="del"||s===null?n.push({kind:l,text:o,n:null}):(n.push({kind:l,text:o,n:s}),r=s,s+=1)}return n}function lC({lines:e,label:n}){return t.jsx("div",{className:"cat-diff",role:"region","aria-label":n,children:oK(e).map((s,r)=>s.kind==="gap"?t.jsxs("div",{className:"cat-diff-line","data-kind":"gap",children:[t.jsx("span",{className:"cat-diff-n","aria-hidden":"true"}),t.jsx("span",{className:"cat-diff-k","aria-hidden":"true"}),t.jsxs("span",{children:["⋯ ",s.count," ",s.count===1?"line":"lines"]})]},r):t.jsxs("div",{className:"cat-diff-line","data-kind":s.kind,children:[t.jsx("span",{className:"cat-diff-n","aria-hidden":"true",children:s.n??""}),t.jsx("span",{className:"cat-diff-k","aria-hidden":"true",children:s.kind==="add"?"+":s.kind==="del"?"-":" "}),t.jsx("span",{children:s.text||" "})]},r))})}function RP({entry:e,agentId:n,onClose:s,onUpdated:r}){const[a,i]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(!1),[h,m]=d.useState(!1),[f,p]=d.useState(!1);d.useEffect(()=>{let y=!1;return T.catalogueUpdatePlan(e.name,n).then(k=>{y||i(k)}).catch(k=>{y||o(vo(k))}),()=>{y=!0}},[e.name,n]);const x=Mo((a==null?void 0:a.version)??e.version),g=y=>{a&&(m(!0),o(null),T.catalogueUpdate(e.name,n,a.plan,y).then(()=>{p(!0),r==null||r()}).catch(k=>{o(vo(k)),T.catalogueUpdatePlan(e.name,n).then(i).catch(()=>{})}).finally(()=>m(!1)))};if(f)return t.jsx(Ye,{title:t.jsxs(ya,{entry:e,children:[e.title," ",x]}),onClose:s,foot:t.jsx(te,{align:"end",children:t.jsx($,{variant:"accent",onClick:s,children:"Done"})}),children:t.jsx(Q,{tone:"good",title:`${e.title} is on ${x}.`,role:"status",children:a!=null&&a.edited?"Your version is in the trash folder if you want any of it back.":"Your picks and missions are as they were."})});if(!a)return t.jsxs(Ye,{title:t.jsxs(ya,{entry:e,children:["Update ",e.title]}),onClose:s,children:[t.jsx(re,{message:l}),l?null:t.jsx(Ee,{children:"Reading what changed…"})]});const w=a.personaDiff.filter(y=>y.startsWith("+ ")).length,v=a.personaDiff.filter(y=>y.startsWith("- ")).length;if(a.edited)return t.jsxs(Ye,{title:t.jsxs(ya,{entry:e,children:[e.title," ",x," is out"]}),onClose:s,foot:t.jsxs(te,{children:[c?null:t.jsx($,{variant:"ghost",onClick:()=>u(!0),children:"See what changed"}),t.jsx(ht,{}),t.jsx($,{variant:"ghost",onClick:s,children:"Keep mine"}),t.jsx($,{variant:"danger",disabled:h,onClick:()=>g(!0),children:"Replace my changes"})]}),children:[t.jsx(Q,{tone:"accent",children:a.replacesOwn&&a.replacesOwn.length>0?`${x} brings ${a.replacesOwn.length===1?"a skill":"skills"} named like your own (${yn(a.replacesOwn)}), so nothing is updated on its own. Yours stay exactly as they are unless you replace them; replaced, they go to the trash folder.`:a.via?`${e.title} replaces your @${a.handle}. You’ve changed @${a.handle}, so nothing is replaced on its own. Your file stays exactly as it is unless you replace it; its handle, chats, memory and missions stay either way.`:`You’ve changed ${e.title} since you added it, so nothing is updated on its own. Your file stays exactly as it is unless you replace it.`}),t.jsx(re,{message:l}),t.jsxs(ue,{divided:!0,gap:"lg",children:[t.jsxs("div",{className:"cat-block",children:[t.jsxs("h3",{className:"cat-block-title",children:["New in ",x]}),t.jsx("p",{className:"cat-prose",children:a.changes})]}),t.jsxs("div",{className:"cat-block",children:[t.jsxs("h3",{className:"cat-block-title",children:["Your file and ",x," ",t.jsx("button",{type:"button",className:"cat-block-aside plugins-link",onClick:()=>u(!c),children:c?"Hide":"See what changed"})]}),c?t.jsxs(t.Fragment,{children:[t.jsx(lC,{lines:a.personaDiff,label:`Your ${e.title} against ${x}`}),t.jsxs("p",{className:"cat-small",children:["Lines marked − are in your file and not in ",x,"; + is new in ",x,". Replacing keeps your picks, and drops what you wrote by hand."]})]}):t.jsxs("p",{className:"cat-small",children:[v===1?"1 line":`${v} lines`," only in your file, ",w===1?"1 line":`${w} lines`," new in ",x,"."]})]})]})]});const j=a.added.length>0?`New: ${yn(qf(a.added.map(y=>y.name),Yf(a.added)).map(([y])=>y))}. The approval lists each tool.`:"No new tools. It reaches what it reaches today.";return t.jsxs(Ye,{title:t.jsxs(ya,{entry:e,children:["Update ",e.title," to ",x]}),onClose:s,foot:t.jsxs(te,{children:[t.jsx("span",{className:"plugins-foot-note",children:"Your picks and handle stay."}),t.jsx(ht,{}),t.jsx($,{variant:"ghost",onClick:s,children:"Not now"}),t.jsxs($,{variant:"accent",disabled:h,onClick:()=>g(!1),children:["Update ",e.title]})]}),children:[t.jsx("p",{className:"cat-lede",children:a.changes}),t.jsx(re,{message:l}),t.jsxs(ue,{divided:!0,gap:"lg",children:[t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"What changes in its file"}),a.personaDiff.length>0?t.jsx(lC,{lines:a.personaDiff,label:a.via?`@${a.handle} against ${e.title} ${x}`:`${e.title} ${Mo(a.fromVersion)} against ${x}`}):t.jsx("p",{className:"cat-prose",children:"Its persona stays word for word."})]}),t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"What it can reach"}),t.jsxs("p",{className:"cat-prose",children:[j,a.removed.length>0?` No longer: ${a.removed.join(", ")}.`:""]})]}),t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"Missions"}),t.jsxs("p",{className:"cat-prose",children:[a.missionsAdded.length>0?`${yn(a.missionsAdded.map(y=>y.name))} added, off until you turn ${a.missionsAdded.length===1?"it":"them"} on.`:"None added.",(a.missionsChanged??[]).length>0?" Their prompt, hour and switch stay yours.":" Yours stay as they are."]}),(a.missionsChanged??[]).map(y=>t.jsxs("p",{className:"cat-prose",children:[y.name,": new settings — ",y.words,"."]},y.id))]}),a.retires&&a.retires.length>0?t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"Skills"}),t.jsxs("p",{className:"cat-prose",children:[x," no longer has ",yn(a.retires),"; ",a.retires.length===1?"it goes":"they go"," to the trash folder."]})]}):null]})]})}function Bs(e){if(e.state==="unavailable")return"unavailable";const n=e.installed;return e.state!=="installed"||!n?"ready":n.drift==="update"?"update":n.drift==="edited-update"?"edited":"added"}function Ub(){const e=je(()=>T.plugins(),[]);return d.useMemo(()=>{var n;return new Set((((n=e.data)==null?void 0:n.installed)??[]).filter(s=>s.loaded&&s.enabled!==!1).map(s=>s.name))},[e.data])}function Bb(){return t.jsx(ne,{name:"check",size:14})}function cK({entry:e,loaded:n,mailbox:s}){const r=Bs(e);if(r==="unavailable")return t.jsx("span",{className:"cat-chips",children:t.jsx("span",{className:"cat-chip","data-need":"true",children:"Needs a newer buddi"})});const a=e.missing??[];if(a.length>0)return t.jsx("span",{className:"cat-chips",children:t.jsxs("span",{className:"cat-chip","data-need":"true",children:["Needs ",yn(a.map(_b))]})});if(r!=="ready")return null;const i=sK(e,n,s);if(i.length===0)return null;const l=`Uses ${yn(i)}`;return t.jsx("span",{className:"cat-uses",title:l,children:l})}function uK({entry:e,onAdd:n,onUpdate:s}){const r=Bs(e),a=i=>l=>{l.stopPropagation(),i()};return r==="added"?t.jsxs("span",{className:"cat-added",children:[t.jsx(Bb,{}),"Added"]}):r==="update"?t.jsx($,{size:"sm",onClick:a(s),"aria-label":`Update ${e.title}`,children:"Update"}):r==="edited"?t.jsx($,{size:"sm",onClick:a(s),children:"See what changed"}):r==="unavailable"?null:t.jsx($,{size:"sm",variant:"accent",onClick:a(n),"aria-label":`Add ${e.title}`,children:"Add"})}function dK({entry:e}){var a,i,l,o;const n=Bs(e),s=Mo(e.version),r=(a=e.installed)==null?void 0:a.handle;return(i=e.installed)!=null&&i.via&&n==="update"?t.jsxs("p",{className:"cat-note",children:["Replaces your @",r,": it keeps its handle, chats, memory and missions."]}):(l=e.installed)!=null&&l.via&&n==="edited"?t.jsxs("p",{className:"cat-note",children:["Replaces your @",r,", which you’ve changed."]}):n==="update"?t.jsxs("p",{className:"cat-note",children:[s," is out: ",e.changes.charAt(0).toLowerCase()+e.changes.slice(1)]}):n==="edited"?t.jsxs("p",{className:"cat-note",children:["You’ve changed ",e.title,"; ",s," is out."]}):n==="added"?t.jsxs("p",{className:"cat-note","data-quiet":"true",children:["On your team as @",(o=e.installed)==null?void 0:o.handle]}):n==="unavailable"?t.jsx("p",{className:"cat-note","data-quiet":"true",children:e.reason}):null}function IP({entry:e,loaded:n,mailbox:s,onOpen:r,onAdd:a,onUpdate:i}){return t.jsx("div",{className:"cat-card","data-state":Bs(e),"data-testid":`cat-card-${e.name}`,children:t.jsxs(Br,{onClick:r,label:`${e.title}: details`,children:[t.jsxs("div",{className:"cat-card-head",children:[t.jsx(El,{entry:e,size:"lg"}),t.jsxs("div",{className:"cat-card-name",children:[t.jsx("h3",{className:"ui-card-title",children:e.title}),t.jsx("div",{className:"cat-card-kind",children:Lb(e.category)})]})]}),t.jsx("p",{className:"cat-pitch",children:e.pitch}),t.jsx(dK,{entry:e}),t.jsxs("div",{className:"cat-card-foot",children:[t.jsx(cK,{entry:e,loaded:n,mailbox:s}),t.jsx(ht,{}),t.jsx(uK,{entry:e,onAdd:a,onUpdate:i})]})]})})}function hK({row:e,agents:n,navigate:s,pages:r}){const a=Ob(e.plugin,e.agent,()=>window.dispatchEvent(new Event(Rs))),i=a.created??(e.state==="installed"?{id:e.agent,handle:e.handle,name:e.name}:null),l=r?av(e.plugin,r.all):yp(e.plugin);return t.jsx("div",{className:"cat-card","data-state":i?"added":"ready","data-testid":`cat-card-${e.agent}`,children:t.jsxs(Br,{onClick:i?()=>s(Qt(i.id)):void 0,label:i?`Open @${i.handle}`:void 0,children:[t.jsxs("div",{className:"cat-card-head",children:[t.jsx("span",{className:"cat-face","data-size":"lg",children:t.jsx(Bn,{id:e.agent,name:e.name,size:"lg",face:n.find(o=>o.id===e.agent)})}),t.jsxs("div",{className:"cat-card-name",children:[t.jsx("h3",{className:"ui-card-title",children:e.name}),t.jsxs("div",{className:"cat-card-kind",children:["From ",l]})]})]}),t.jsx("p",{className:"cat-pitch",children:e.text}),i?t.jsxs("p",{className:"cat-note","data-quiet":"true",children:["On your team as @",i.handle]}):null,t.jsxs("div",{className:"cat-card-foot",children:[t.jsx(re,{message:a.failure}),t.jsx(ht,{}),i?t.jsxs("span",{className:"cat-added",children:[t.jsx(Bb,{}),"Added"]}):t.jsx($,{size:"sm",variant:"accent",disabled:a.busy,onClick:o=>{o.stopPropagation(),a.accept()},"aria-label":`Add ${e.name}`,children:"Add"})]})]})})}function fK({n:e=6}){return t.jsx("div",{className:"cat-grid","aria-busy":"true","aria-label":"Loading the catalogue","data-testid":"cat-loading",children:Array.from({length:e},(n,s)=>t.jsxs("div",{className:"ui-card cat-skel",children:[t.jsxs("div",{className:"cat-card-head",children:[t.jsx("i",{className:"cat-skel-face"}),t.jsxs("span",{className:"cat-card-name",children:[t.jsx("i",{className:"cat-skel-line","data-w":"40"}),t.jsx("i",{className:"cat-skel-line","data-w":"20"})]})]}),t.jsx("i",{className:"cat-skel-line","data-w":"90"}),t.jsx("i",{className:"cat-skel-line","data-w":"70"})]},s))})}function mK(e,n,s){const r=e.find(a=>a.roles.includes(Pr));r&&(s.trim()&&fd(r.id,`I'd like a teammate for this: ${s.trim()}`),n(ut(r.id)))}function pK({sheet:e,view:n,navigate:s,onClose:r,onChanged:a}){const i=e?n==null?void 0:n.agents.find(l=>l.name===e.name):void 0;return!e||!i?null:e.kind==="update"&&i.installed?t.jsx(RP,{entry:i,agentId:i.installed.agentId,onClose:r,onUpdated:a}):t.jsx(zb,{entry:i,navigate:s,onClose:r,onAdded:a})}const gK=[{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 xK(e,n){return[e.title,e.pitch,e.about,e.description,Lb(e.category)].some(s=>s.toLowerCase().includes(n))}function jK({name:e,agents:n,navigate:s,pluginPages:r}){const[a,i]=d.useState(0),l=je(()=>T.catalogue(a>0),[a]),o=Ub(),[c,u]=d.useState(""),[h,m]=d.useState("all"),[f,p]=d.useState(null),x=l.data,g=()=>{l.reload(),window.dispatchEvent(new Event(Rs))},w=()=>i(A=>A+1),v=t.jsx(pK,{sheet:f,view:x,navigate:s,onClose:()=>p(null),onChanged:g}),j=e?x==null?void 0:x.agents.find(A=>A.name===e):void 0,y=d.useRef(!1);if(d.useEffect(()=>{y.current||!j||!G8(window.location.hash,j.name)||(y.current=!0,Bs(j)==="ready"&&p({kind:"install",name:j.name}))},[j]),e&&x&&!x.unavailable&&j)return t.jsxs(t.Fragment,{children:[t.jsx(wK,{entry:j,loaded:o,agents:n,navigate:s,onAdd:()=>p({kind:"install",name:j.name}),onUpdate:()=>p({kind:"update",name:j.name})}),v]});const k=c.trim().toLowerCase(),b=((x==null?void 0:x.agents)??[]).filter(A=>(h==="all"||A.category===h)&&(!k||xK(A,k))),S=((x==null?void 0:x.fromPlugins)??[]).filter(A=>h==="all"&&(!k||[A.name,A.text,A.description].some(E=>E.toLowerCase().includes(k)))),C=A=>()=>s(A);return t.jsxs(Nb,{children:[t.jsx(nl,{before:t.jsx(Zc,{inline:!0,items:[{label:"Agents",href:Pt,onClick:C(Pt)}]}),title:"Add a teammate",lede:"Agents tested with the plugins they use. Adding one is one approval, and it becomes a file on this computer you can change."}),e&&x&&!x.unavailable&&!j?t.jsxs(Q,{tone:"warning",children:["The catalogue lists no teammate called “",e,"”. Here is everyone it does list."]}):null,t.jsxs("div",{className:"cat-bar",children:[t.jsxs("div",{className:"cat-search",children:[t.jsx(ne,{name:"search",size:16}),t.jsx(fp,{label:"Search teammates",value:c,placeholder:"Search: meals, money, a language…",onChange:u})]}),t.jsx("div",{className:"cat-cats",children:t.jsx(tP,{label:"Category",options:gK,value:h,onChange:m})})]}),x&&!x.unavailable?x.stale?t.jsxs("p",{className:"plugins-quiet","data-testid":"cat-stale",children:[t.jsx(ne,{name:"globe",size:14}),"From the list kept ",x.fetchedAt?vK(x.fetchedAt):"earlier",": withbuddi.com didn’t answer just now."," ",t.jsx("button",{type:"button",className:"plugins-link",onClick:w,children:"Try again"})]}):t.jsxs("p",{className:"plugins-quiet",children:[t.jsx(ne,{name:"globe",size:14}),"Opening this page fetched the list from withbuddi.com. Nothing else leaves."]}):null,l.error&&!x?t.jsx(Ee,{warm:!0,title:"The catalogue didn’t load",action:t.jsx($,{variant:"accent",size:"sm",onClick:w,children:"Try again"}),children:l.error}):x?x.unavailable?t.jsx(Ee,{warm:!0,title:"The catalogue needs withbuddi.com",action:t.jsx($,{variant:"accent",size:"sm",disabled:l.loading,onClick:w,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."}):b.length+S.length>0?t.jsxs("div",{className:"cat-grid","data-testid":"cat-grid",children:[b.map(A=>t.jsx(IP,{entry:A,loaded:o,mailbox:x.mailbox,onOpen:()=>s(En(A.name)),onAdd:()=>p({kind:"install",name:A.name}),onUpdate:()=>p({kind:"update",name:A.name})},A.name)),S.map(A=>t.jsx(hK,{row:A,agents:n,navigate:s,pages:r},`${A.plugin}/${A.agent}`))]}):t.jsx(Ee,{warm:!0,title:"No teammate for that yet",action:t.jsxs("span",{className:"cat-empty-acts",children:[t.jsx($,{size:"sm",variant:"ghost",onClick:()=>{u(""),m("all")},children:"Show all"}),t.jsx($,{size:"sm",variant:"accent",onClick:()=>mK(n,s,c),children:"Ask Agent Father"})]}),children:k?t.jsxs(t.Fragment,{children:["Nothing in the catalogue does “",c.trim(),"”. Agent Father can make one for you; your words go with you."]}):"Nothing in this category yet."}):t.jsx(fK,{}),x&&!x.unavailable&&x.delisted.length>0?t.jsx(lt,{title:"No longer in the catalogue",children:t.jsx("ul",{className:"cat-plugins","data-testid":"cat-delisted",children:x.delisted.map(A=>t.jsxs("li",{children:[t.jsx(vn,{agents:n,id:A.agentId,size:"sm"}),t.jsxs("span",{className:"cat-plugin-text",children:[t.jsx("a",{className:"cat-plugin-name",href:Qt(A.agentId),onClick:E=>{E.preventDefault(),s(Qt(A.agentId))},children:A.name??`@${A.handle}`}),t.jsxs("span",{className:"cat-small",children:["@",A.handle," keeps working as it is; no updates will come."]})]})]},A.agentId))})}):null,v]})}function vK(e){const n=Math.round((Date.now()-Date.parse(e))/36e5);if(!Number.isFinite(n)||n<1)return"an hour ago";if(n<24)return`${n} h ago`;const s=Math.round(n/24);return s===1?"yesterday":`${s} days ago`}function _i({title:e,children:n}){return t.jsxs("section",{className:"cat-row",children:[t.jsx("h2",{className:"cat-row-title",children:e}),t.jsx("div",{className:"cat-row-body",children:n})]})}function yK({entry:e,loaded:n,navigate:s}){const r=new Map((e.missing??[]).map(i=>[i.name,i])),a=[...Object.keys(e.requires).map(i=>({name:i,needed:!0,need:!1})),...Object.keys(e.optional).map(i=>({name:i,needed:!1,need:!1})),...e.needs.map(i=>({name:i.replace(/\?$/,""),needed:!i.endsWith("?"),need:!0}))];return a.length===0?t.jsx("p",{className:"cat-small",children:"None. It works with what buddi has."}):t.jsx("ul",{className:"cat-plugins",children:a.map(({name:i,needed:l,need:o})=>{const c=r.get(i),u=c?Gf(c):null,h=o?Fb(i).title:(c==null?void 0:c.kind)==="plugin"?c.title:yp(i),m=o?l&&!c:n.has(i);return t.jsxs("li",{children:[t.jsx("span",{className:"ui-app-icon","aria-hidden":"true",children:t.jsx(ne,{name:o?i==="mailbox"?"mail":"key":"plug",size:14})}),t.jsxs("span",{className:"cat-plugin-text",children:[t.jsx("span",{className:"cat-plugin-name",children:h.charAt(0).toUpperCase()+h.slice(1)}),t.jsx("span",{className:"cat-small",children:l?"Needed":"Better with it"})]}),u?t.jsx($,{size:"sm",onClick:()=>s(u.route),children:u.label}):c?t.jsx("span",{className:"cat-small",children:"Installed when you add it"}):m?t.jsxs("span",{className:"cat-added",children:[t.jsx(Bb,{}),o?"You have one":"Installed"]}):t.jsx("span",{className:"cat-small",children:o?"Optional":"Not installed"})]},`${o?"need":"plugin"}-${i}`)})})}function wK({entry:e,loaded:n,agents:s,navigate:r,onAdd:a,onUpdate:i}){var x,g,w,v;const l=Bs(e),c=(x=e.installed)==null?void 0:x.agentId,u=Mo(e.version),h=(g=e.installed)!=null&&g.via?e.installed:void 0,m=j=>{c&&(j&&fd(c,j),r(ut(c)))},f=qf(e.tools,Yf((w=e.claims)==null?void 0:w.tools)),p=e.replaces.map(j=>Rg(j.split("/")[1]??j));return t.jsxs(Nb,{children:[t.jsxs("a",{className:"cat-back",href:En(),onClick:j=>{j.preventDefault(),r(En())},children:[t.jsx(ne,{name:"chevron-left",size:12}),"Teammates"]}),t.jsxs("header",{className:"cat-hero",children:[t.jsx(El,{entry:e,size:"xxl"}),t.jsxs("div",{className:"cat-hero-text",children:[t.jsx("h1",{className:"cat-hero-title",children:e.title}),t.jsx("p",{className:"cat-hero-pitch",children:e.pitch}),t.jsxs("p",{className:"cat-hero-meta",children:[e.trust==="by-buddi"?t.jsx($e,{tone:"accent",children:"by buddi"}):null,t.jsx("span",{children:Lb(e.category)}),t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("span",{className:"mono",children:h?e.version:((v=e.installed)==null?void 0:v.version)??e.version}),e.installed?t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsxs("span",{children:["on your team as ",t.jsxs("span",{className:"mono",children:["@",e.installed.handle]})]})]}):null]})]}),t.jsx("div",{className:"cat-hero-act",children:l==="ready"?t.jsxs($,{variant:"accent",onClick:a,children:["Add ",e.title]}):l==="update"?t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:()=>m(),children:"Open chat"}),t.jsx($,{variant:"accent",onClick:i,children:h?`Update @${h.handle} to ${e.title}`:`Update to ${u}`})]}):l==="edited"?t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:()=>m(),children:"Open chat"}),t.jsx($,{onClick:i,children:"See what changed"})]}):l==="unavailable"?null:t.jsx($,{variant:"accent",onClick:()=>m(),children:"Open chat"})})]}),l==="edited"&&h?t.jsxs(Q,{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"?t.jsxs(Q,{tone:"accent",children:["You’ve changed ",e.title," since you added it, so ",u," isn’t applied on its own. Your file stays as it is unless you replace it."]}):l==="unavailable"?t.jsx(Q,{tone:"warning",children:e.reason}):null,t.jsx(lt,{flush:!0,children:t.jsxs("div",{className:"cat-rows",children:[t.jsxs(_i,{title:"What it does",children:[t.jsx("p",{className:"cat-prose",children:e.about}),p.length>0?t.jsxs("p",{className:"cat-small",children:["Does what ",yn(p)," did. If you have ",yn(p)," and haven’t changed it, it’s offered as an update."]}):null]}),e.examples.length>0?t.jsxs(_i,{title:"Ask it",children:[t.jsx("div",{className:"wb-starters",children:e.examples.map(j=>t.jsx("button",{type:"button",className:"wb-starter",disabled:!c,onClick:()=>m(j),children:j},j))}),c?null:t.jsx("p",{className:"cat-small",children:"Once it’s on your team, a tap opens a chat with it."})]}):null,t.jsx(_i,{title:"Skills",children:e.skills.length===0?t.jsx("p",{className:"cat-small",children:"None. It works from its persona."}):t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"cat-plugins","data-testid":"cat-skills",children:e.skills.map(j=>t.jsxs("li",{children:[t.jsx("span",{className:"ui-app-icon","aria-hidden":"true",children:t.jsx(ne,{name:"files",size:14})}),t.jsxs("span",{className:"cat-plugin-text",children:[t.jsx("span",{className:"cat-plugin-name",children:Rg(j.name)}),j.description?t.jsx("span",{className:"cat-small",children:j.description}):null,t.jsx(Vt,{summary:"Read it",children:t.jsx(Zt,{label:`${Rg(j.name)}: the skill's text`,children:j.text})})]})]},j.name))}),t.jsxs("p",{className:"cat-small",children:["Plain text, no code."," ",c?t.jsxs(t.Fragment,{children:["Read and change them on ",t.jsx("a",{href:Qt(c,"skills"),onClick:j=>{j.preventDefault(),r(Qt(c,"skills"))},children:"its Skills tab"}),"."]}):"Once it’s on your team they’re files you can read and change."]})]})}),t.jsxs(_i,{title:"What it can reach",children:[t.jsx("dl",{className:"cat-reach",children:f.map(([j,y])=>t.jsxs("div",{className:"cat-reach-row",children:[t.jsx("dt",{children:j}),t.jsx("dd",{children:y})]},j))}),t.jsx("p",{className:"cat-small",children:"Anything that sends or pays still asks you first, every time. You can change any of this on its page."})]}),t.jsx(_i,{title:"Missions",children:e.missions.length>0?t.jsx("ul",{className:"cat-missions",children:e.missions.map(j=>t.jsxs("li",{children:[t.jsx("span",{className:"cat-mission-name",children:j.name}),t.jsx("span",{className:"cat-mission-when",children:j.when}),t.jsx("span",{className:"cat-off",children:"off until you turn it on"})]},j.id))}):t.jsx("p",{className:"cat-small",children:"None. It works when you ask."})}),t.jsx(_i,{title:"Plugins",children:t.jsx(yK,{entry:e,loaded:n,navigate:r})}),t.jsxs(_i,{title:"Version",children:[t.jsxs("p",{className:"cat-prose",children:[t.jsx("span",{className:"mono",children:e.version})," · ",e.changes]}),t.jsx("p",{className:"cat-small",children:"Reviewed in withbuddi/buddi-market. An update always asks you, and never touches a file you changed."})]})]})})]})}function PP({days:e,mailbox:n,mail:s,money:r,pictures:a}){const i=[];(n||s||e)&&i.push("chief-of-staff"),r&&i.push("cfo"),a&&i.push("illustrator");for(const l of["researcher","tutor"])i.length<3&&i.push(l);return i.slice(0,4)}function bK(e,n,s=4){const r=i=>!!i&&Bs(i)==="ready"&&i.addable,a=PP(n).map(i=>e.find(l=>l.name===i)).filter(r);for(const i of["researcher","tutor"]){if(a.length>=3)break;const l=e.find(o=>o.name===i);r(l)&&!a.includes(l)&&a.push(l)}return a.slice(0,s)}const oC=["researcher","tutor"];function cC(e,n){return e==="chief-of-staff"?n.days?"because you set up My days":n.mailbox?"because you added a mailbox":"because you set up My mail":e==="cfo"?"because you set up My money":e==="illustrator"?"because you set up Pictures":"popular"}function kK(e,n,s=4){const r=[];for(const a of PP(n).filter(i=>!oC.includes(i))){const i=e.find(h=>h.name===a);if(!i||Bs(i)!=="ready")continue;if(i.addable){r.push({entry:i,reason:cC(a,n)});continue}const l=i.missing??[],o=l.find(h=>Gf(h)!==null)??l[0];if(!o)continue;const c=Gf(o),u=c?c.label.charAt(0).toLowerCase()+c.label.slice(1):`${_b(o)} is here`;r.push({entry:i,reason:cC(a,n),blocked:{step:u,fix:c}})}for(const a of oC){if(r.length>=3)break;const i=e.find(l=>l.name===a);i&&Bs(i)==="ready"&&i.addable&&r.push({entry:i,reason:"popular"})}return r.slice(0,s)}const NK={image:"makes pictures",finance:"keeps your books",calendar:"looks after your days",email:"reads your mail"};function MP(e,n){const s=NK[e];return s?`Nobody ${s} yet`:`Nobody uses ${n??e.charAt(0).toUpperCase()+e.slice(1)} yet`}function OP(e,n){const s=e.filter(r=>Object.keys(r.requires??{}).includes(n));if(!s.some(r=>Bs(r)!=="ready"&&Bs(r)!=="unavailable"))return s.find(r=>Bs(r)==="ready")}function uC(e,n){const s=[];for(const r of n){const a=OP(e,r);a&&!s.some(i=>i.entry.name===a.name)&&s.push({plugin:r,entry:a})}return s}const tu=e=>`teammate:${e}`;function DP({plugin:e,title:n,navigate:s,dismissible:r=!1}){const[a,i]=d.useState(null),[l,o]=d.useState(!1),[c,u]=d.useState(!1),[h,m]=d.useState(!1);if(d.useEffect(()=>{let p=!1;return Promise.resolve().then(()=>T.catalogue()).then(async x=>{const g=x.unavailable?void 0:OP(x.agents,e);return!g||!r?g??null:(await Promise.resolve().then(()=>T.overview()).then(v=>v.dismissed??{},()=>({})))[tu(e)]!==g.name?g:null}).then(x=>{p||i(x)}).catch(()=>{p||i(null)}),()=>{p=!0}},[e,r]),!a||c||h)return null;const f=()=>{m(!0),T.homeDismiss(tu(e),a.name).catch(()=>m(!1))};return t.jsxs(t.Fragment,{children:[t.jsx(Q,{action:t.jsxs(te,{children:[r?t.jsx($,{size:"sm",variant:"ghost",onClick:f,children:"Not now"}):null,t.jsxs($,{size:"sm",onClick:()=>o(!0),children:["Add ",a.title]})]}),children:t.jsx("span",{"data-testid":"plugin-teammate",children:MP(e,n)})}),l?t.jsx(zb,{entry:a,navigate:s,onClose:()=>o(!1),onAdded:()=>{u(!0),window.dispatchEvent(new Event(Rs))}}):null]})}function SK(e,n){const s=e.filter(r=>r.id!==n&&!r.roles.includes(vd)&&!r.roles.includes(Pr));return e.length>0&&s.length<=1}async function CK(e,n=TP){try{const{jobId:s}=await T.catalogueInstall(e.name,{version:e.version,tools:e.tools});for(;;){const r=await T.catalogueJob(s);if(r.state!=="running")return r;await new Promise(a=>setTimeout(a,n))}}catch(s){return{error:s instanceof pe?s.message:String(s)}}}function EK({entry:e,checked:n,onChange:s,reason:r}){return t.jsxs("label",{className:"cat-pick","data-checked":n?"true":void 0,"data-testid":`cat-pick-${e.name}`,children:[t.jsx("input",{type:"checkbox",checked:n,onChange:a=>s(a.target.checked)}),t.jsx(El,{entry:e,size:"lg"}),t.jsxs("span",{className:"cat-pick-text",children:[t.jsxs("span",{className:"cat-pick-name",children:[e.title,r?t.jsx("span",{className:"cat-pick-why",children:r}):null]}),t.jsx("span",{className:"cat-pick-pitch",children:e.pitch})]})]})}function AK({suggestion:e,onFix:n}){const{entry:s,reason:r,blocked:a}=e;return t.jsxs("div",{className:"cat-pick","data-blocked":"true","data-testid":`cat-pick-${s.name}`,children:[t.jsx("input",{type:"checkbox",checked:!1,disabled:!0,"aria-label":`${s.title}: not ready yet`,onChange:()=>{}}),t.jsx(El,{entry:s,size:"lg"}),t.jsxs("span",{className:"cat-pick-text",children:[t.jsxs("span",{className:"cat-pick-name",children:[s.title," · ready once you ",a==null?void 0:a.step,t.jsx("span",{className:"cat-pick-why",children:r})]}),t.jsx("span",{className:"cat-pick-pitch",children:s.pitch})]}),a!=null&&a.fix?t.jsx($,{size:"sm",onClick:()=>n(a.fix.route),children:a.fix.label}):null]})}function $K({entry:e,added:n,onOpen:s,onAdd:r,why:a,onDismiss:i}){return t.jsxs("div",{className:"cat-suggest",role:"button",tabIndex:0,"aria-label":`${e.title}: details`,"data-testid":`cat-suggest-${e.name}`,onClick:s,onKeyDown:l=>{l.target===l.currentTarget&&l.key==="Enter"&&s()},children:[t.jsx(El,{entry:e,size:"lg"}),t.jsxs("span",{className:"cat-pick-text",children:[t.jsxs("span",{className:"cat-pick-name",children:[e.title,a?t.jsx("span",{className:"cat-pick-why",children:a}):null]}),t.jsx("span",{className:"cat-pick-pitch",children:e.pitch})]}),n?t.jsxs("span",{className:"cat-added",children:[t.jsx(ne,{name:"check",size:14}),"Added"]}):t.jsx($,{size:"sm",variant:"accent","aria-label":`Add ${e.title}`,onClick:l=>{l.stopPropagation(),r()},children:"Add"}),i?t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Not now: ${e.title}`,title:"Not now",onClick:l=>{l.stopPropagation(),i()},children:t.jsx(ne,{name:"close"})}):null]})}function TK({navigate:e,newTeam:n=!0,closed:s}){const[r,a]=d.useState(null),[i,l]=d.useState(null),[o,c]=d.useState([]),u=Ub();d.useEffect(()=>{let f=!1;return T.catalogue().then(p=>{f||a(p.unavailable?[]:p.agents)}).catch(()=>{f||a([])}),()=>{f=!0}},[]);const h=d.useMemo(()=>r===null?[]:uC(r,u).filter(f=>!(s!=null&&s.is(tu(f.plugin),f.entry.name))),[r,u,s]),m=d.useMemo(()=>{if(r===null)return null;const f=h.map(g=>g.entry);if(!n)return f;const p=new Set(uC(r,u).filter(g=>s==null?void 0:s.is(tu(g.plugin),g.entry.name)).map(g=>g.entry.name)),x=bK(r,{days:!0,mailbox:!0,money:u.has("finance"),pictures:u.has("image")},3+p.size).filter(g=>!f.some(w=>w.name===g.name)&&!p.has(g.name));return[...f,...x].slice(0,Math.max(3,f.length))},[r,u,h,n,s]);return!m||m.length===0?null:t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"cat-suggest-lede",children:"Teammates who could take a job off your hands, from what you set up:"}),t.jsx("div",{className:"cat-suggests","data-testid":"home-suggestions",children:m.map(f=>{const p=h.find(x=>x.entry.name===f.name);return t.jsx($K,{entry:f,added:o.includes(f.name),onOpen:()=>e(En(f.name)),onAdd:()=>l(f),...p&&s&&!o.includes(f.name)?{onDismiss:()=>s.close(tu(p.plugin),f.name),why:MP(p.plugin)}:{}},f.name)})}),i?t.jsx(zb,{entry:i,navigate:e,onClose:()=>l(null),onAdded:()=>{c(f=>[...f,i.name]),window.dispatchEvent(new Event(Rs))}}):null]})}function RK(){const[e,n]=d.useState(null);return d.useEffect(()=>{let s=!1;const r=()=>{Promise.resolve().then(()=>nt.agents()).then(a=>{s||n(((a==null?void 0:a.agents)??[]).filter(i=>!i.roles.includes(Pr)).map(i=>i.name))}).catch(()=>{s||n(a=>a??[])})};return r(),window.addEventListener(Rs,r),()=>{s=!0,window.removeEventListener(Rs,r)}},[]),e}function IK({setUp:e,navigate:n}){var b;const s=RK(),[r,a]=d.useState(null),[i,l]=d.useState([]),[o,c]=d.useState("picking"),[u,h]=d.useState([]),[m,f]=d.useState([]),p=JSON.stringify(e);d.useEffect(()=>{let S=!1;return T.catalogue().then(C=>{if(S)return;const A=C.unavailable?[]:kK(C.agents,e);a(A),l(A.filter(E=>!E.blocked).map(E=>E.entry.name))}).catch(()=>{S||a([])}),()=>{S=!0}},[p]);const x=s??[];if(!r||r.length===0&&x.length===0)return null;const g=x.length===0?null:t.jsxs("p",{className:"cat-small","data-testid":"handover-team-now",children:["On your team: ",yn(x),"."]}),w=r.filter(S=>!S.blocked).map(S=>S.entry),v=r.some(S=>!S.blocked&&S.reason!=="popular"),j=()=>n(En()),y=async()=>{c("adding");const S=[],C=[];for(const A of w.filter(E=>i.includes(E.name))){const E=await CK(A);"error"in E&&!("state"in E)?C.push({entry:A,error:E.error}):E.state==="done"?S.push(A):E.state==="confirm"?C.push({entry:A,error:"it gets more than its card showed, so it waits for your approval in Needs you"}):C.push({entry:A,error:E.error??"it stopped before it finished"})}h(S),f(C),c("added"),S.length>0&&window.dispatchEvent(new Event(Rs))},k=i.length,N=o==="adding"?`Adding ${k===1?((b=w.find(S=>S.name===i[0]))==null?void 0:b.title)??"1":k}…`:k>0&&k===w.length?"Add these":k>0?`Add these ${k}`:"Tick one to add";return t.jsx("section",{className:"handover-team","aria-label":"Who do you want on your team?","data-testid":"handover-team",children:o==="added"?t.jsxs(t.Fragment,{children:[u.length>0?t.jsxs(Q,{tone:"good",role:"status",title:`${yn(u.map(S=>S.title))} ${u.length===1?"is":"are"} on your team.`,action:t.jsx($,{variant:"ghost",size:"sm",onClick:j,children:"See all teammates"}),children:["Say hello in Chat. ",u.length===1?"Its missions are":"Their missions are"," off until you turn them on."]}):null,m.length>0?t.jsxs(Q,{tone:"critical",role:"alert",title:`${yn(m.map(S=>S.entry.title))} ${m.length===1?"wasn’t":"weren’t"} added.`,action:u.length===0?t.jsx($,{variant:"ghost",size:"sm",onClick:j,children:"See all teammates"}):void 0,children:[m.map(S=>`${S.entry.title}: ${S.error.replace(/[.\s]+$/,"")}.`).join(" ")," Nothing else changed; try again from the catalogue."]}):null]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"handover-team-head",children:[t.jsx("h2",{className:"handover-team-title",children:r.length===0?"Your team":"Who do you want on your team?"}),g,r.length===0?null:t.jsx("p",{className:"cat-small",children:v?"Picked from what you just set up. Their plugins are already in, so one click adds them all.":"A few teammates people often start with. One click adds the ones you tick."})]}),r.length===0?null:t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"cat-picks",children:r.map(S=>S.blocked?t.jsx(AK,{suggestion:S,onFix:n},S.entry.name):t.jsx(EK,{entry:S.entry,reason:S.reason,checked:i.includes(S.entry.name),onChange:C=>l(C?[...i,S.entry.name]:i.filter(A=>A!==S.entry.name))},S.entry.name))}),t.jsx("div",{className:"handover-team-foot",children:t.jsxs(te,{children:[t.jsx($,{variant:"ghost",onClick:j,children:"See all teammates"}),t.jsx(ht,{}),t.jsx($,{variant:"accent",disabled:k===0||o==="adding"||w.length===0,onClick:()=>void y(),children:N})]})})]})]})})}const PK=512*1024,MK=/^[A-Za-z0-9+/]*={0,2}$/;function LP(e){const n=e==null?void 0:e.play;if(typeof n!="object"||n===null)return null;const{mime:s,data:r}=n;return typeof s!="string"||!/^audio\/[a-z0-9.+-]+$/i.test(s.split(";")[0].trim())||typeof r!="string"||r===""||!MK.test(r)||Math.floor(r.length*3/4)>PK+2?null:{mime:s,data:r}}function FP(e){const n=e==null?void 0:e.message;return typeof n=="string"&&n.trim()!==""?n:null}let wa=null,nu=null,Vu=null;const xv=new Set;function _P(){for(const e of xv)e()}function zc(){wa&&(wa.onended=null,wa.onerror=null,wa.pause()),nu&&URL.revokeObjectURL(nu),nu=null,Vu!==null&&(Vu=null,_P())}async function zP(e,n){zc();const s=atob(e.data),r=new Uint8Array(s.length);for(let a=0;a<s.length;a+=1)r[a]=s.charCodeAt(a);wa??(wa=new Audio),nu=URL.createObjectURL(new Blob([r],{type:e.mime})),Vu=n,wa.onended=zc,wa.onerror=zc,wa.src=nu,_P();try{await wa.play()}catch{throw zc(),new Error("The browser would not play the sound.")}}function dC(e){e!==void 0&&Vu!==e||zc()}function OK(){return d.useSyncExternalStore(e=>(xv.add(e),()=>xv.delete(e)),()=>Vu,()=>null)}const DK=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Vr=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],hC=/^\d{4}-\d{2}-\d{2}$/;function rl(e){return e.split("-").map(Number)}function Ii(e,n){const[s,r,a]=rl(e);return new Date(Date.UTC(s,r-1,a+n)).toISOString().slice(0,10)}function UP(e){const[n,s,r]=rl(e);return new Date(Date.UTC(n,s-1,r)).getUTCDay()}function BP(e){return DK[UP(e)]}function WP(e){return rl(e)[2]}function fC(e){return Ii(e,-((UP(e)+6)%7))}function us(e){return Zo(e,{weekday:!0,compact:!0})}function LK(e,n){return e===n?`Today · ${us(e)}`:e===Ii(n,1)?`Tomorrow · ${us(e)}`:us(e)}function Er(e){return oU(e)}const mC=new Map;function jv(e,n){let s=mC.get(n);s||(s=new Intl.DateTimeFormat("en-GB",{timeZone:n,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}),mC.set(n,s));const r=Object.fromEntries(s.formatToParts(e).map(a=>[a.type,a.value]));return{date:`${r.year}-${r.month}-${r.day}`,minutes:Number(r.hour)*60+Number(r.minute)}}function FK(e,n=new Date){return jv(n,e).date}function _K(e,n){return e==="week"?{from:fC(n),days:7}:e==="month"?{from:fC(`${n.slice(0,8)}01`),days:42}:{from:n,days:7}}function zK(e,n,s){if(e!=="month")return Ii(n,s*7);const[r,a]=rl(n);return new Date(Date.UTC(r,a-1+s,1)).toISOString().slice(0,10)}function UK(e,n,s,r){const[a,i]=rl(n);if(e==="month")return vR(a,i);const l=Ii(s,r-1),[o,c,u]=rl(s),[h,m,f]=rl(l);return xR().date==="iso"?`${s} – ${l}`:cU()?c===m&&o===h?`${Vr[c-1]} ${u} – ${f}, ${h}`:o===h?`${Vr[c-1]} ${u} – ${Vr[m-1]} ${f}, ${h}`:`${Vr[c-1]} ${u}, ${o} – ${Vr[m-1]} ${f}, ${h}`:c===m&&o===h?`${u} – ${f} ${Vr[m-1]} ${h}`:o===h?`${u} ${Vr[c-1]} – ${f} ${Vr[m-1]} ${h}`:`${u} ${Vr[c-1]} ${o} – ${f} ${Vr[m-1]} ${h}`}function Fl(e){return e==null?"":String(e)}function BK(e,n,s,r){const a=[],i=new Set;return e.forEach((l,o)=>{const c=Fl(Re(l,n.id)),u=Fl(Re(l,n.title)),h=Fl(Re(l,n.start)),m=Fl(Re(l,n.end));if(c===""||i.has(c)||h===""){console.warn(`buddi: ${r}: event ${o} has no id, a repeated one, or no start — not drawn`);return}i.add(c);const f=n.allDay===void 0?void 0:Re(l,n.allDay),p=f===void 0?hC.test(h):f===!0||f==="true",x=n.tone===void 0?0:Number(Re(l,n.tone)),g=Number.isFinite(x)?(Math.trunc(x)%4+4)%4:0,w={id:c,title:u,calendar:n.calendar===void 0?"":Fl(Re(l,n.calendar)),tone:g,location:n.location===void 0?"":Fl(Re(l,n.location)),row:l};if(p){const N=h.slice(0,10),b=hC.test(m.slice(0,10))&&m.slice(0,10)>N?m.slice(0,10):Ii(N,1);a.push({...w,allDay:!0,startDate:N,startMin:0,endDate:b,endMin:0});return}const v=new Date(h);if(Number.isNaN(v.getTime())){console.warn(`buddi: ${r}: event ${o} starts at "${h}", which is not a time — not drawn`);return}const j=new Date(m),y=jv(v,s),k=Number.isNaN(j.getTime())||j<v?y:jv(j,s);a.push({...w,allDay:!1,startDate:y.date,startMin:y.minutes,endDate:k.date,endMin:k.minutes})}),a}function WK(e,n){if(e.allDay)return n>=e.startDate&&n<e.endDate?{from:0,to:1440,allDay:!0}:null;if(n<e.startDate||n>e.endDate)return null;const s=n===e.startDate?e.startMin:0,r=n===e.endDate?e.endMin:1440,a=e.startDate===e.endDate&&e.startMin===e.endMin;return r<=s&&!(a&&n===e.startDate)?null:{from:s,to:r,allDay:s===0&&r===1440}}function Wb(e,n){return e.map(s=>({event:s,part:WK(s,n)})).filter(s=>s.part!==null).sort((s,r)=>Number(r.part.allDay)-Number(s.part.allDay)||s.part.from-r.part.from||r.part.to-s.part.to)}function Hb(e,n){if(n.allDay)return"All day";const s=e.startDate!==e.endDate;return s&&n.from===0?`until ${Er(n.to)}`:s&&n.to===1440?`from ${Er(n.from)}`:n.from===n.to?Er(n.from):`${Er(n.from)}–${Er(n.to)}`}function vv(e,n,s){return[Hb(e,n),e.title,e.location,e.calendar,us(s)].filter(Boolean).join(", ")}const HP=30;function HK(e){const n=[];let s=[],r=-1;const a=[],i=()=>{const l=Math.max(1,...s.map(o=>o.lane+1));for(const o of s)n.push({...o,lanes:l});s=[],a.length=0};for(const l of e){const o=Math.max(l.part.to,l.part.from+HP);s.length>0&&l.part.from>=r&&i();let c=a.findIndex(u=>u<=l.part.from);c===-1?(c=a.length,a.push(o)):a[c]=o,s.push({...l,lane:c,lanes:1}),r=Math.max(r,o)}return s.length>0&&i(),n}function KK(e){if(e<60)return`${e} min`;const n=Math.floor(e/60),s=e%60;return s===0?`${n} h`:`${n} h ${String(s).padStart(2,"0")}`}function VK(e){if(e.allDay){const a=Ii(e.endDate,-1);return a>e.startDate?`${us(e.startDate)} – ${us(a)} · all day`:`${us(e.startDate)} · all day`}const n=Math.round((Date.parse(`${e.endDate}T00:00:00Z`)-Date.parse(`${e.startDate}T00:00:00Z`))/864e5),s=n*1440+e.endMin-e.startMin,r=n===0?`${us(e.startDate)} · ${Er(e.startMin)}–${Er(e.endMin)}`:`${us(e.startDate)} ${Er(e.startMin)} – ${us(e.endDate)} ${Er(e.endMin)}`;return s>0?`${r} · ${KK(s)}`:r}const yv="buddi:ask";function GK(e){const n={text:e,handled:!1};return window.dispatchEvent(new CustomEvent(yv,{detail:n})),n.handled}const qK={week:"Week",month:"Month",list:"List"},YK=["week","month","list"],QK="(max-width: 720px)";function JK(e){try{return window.localStorage.getItem(e)}catch{return null}}function XK(e,n){try{window.localStorage.setItem(e,n)}catch{}}function ZK(e){const n=e.views&&e.views.length>0?e.views:YK,s=ts(QK),[r,a]=d.useState(()=>{const p=JK(e.storageKey);return p!==null&&n.includes(p)?p:null}),i=s&&n.includes("list")?"list":e.default&&n.includes(e.default)?e.default:n[0],l=r??i,[o,c]=d.useState(e.today),[u,h]=d.useState(null),{from:m,days:f}=_K(l,o);return{views:n,view:l,setView:p=>{a(p),XK(e.storageKey,p),h(null)},anchor:o,today:e.today,go:p=>{c(p===0?e.today:zK(l,o,p)),h(null)},from:m,days:f,to:Ii(m,f),selected:u,select:h}}function e9({state:e,events:n,hours:s,empty:r,label:a,onEvent:i,count:l}){const{view:o,anchor:c,today:u,from:h,days:m}=e,f=d.useMemo(()=>Array.from({length:m},(v,j)=>Ii(h,j)),[h,m]),p=o==="month"?"month":"week",x=e.selected??(c.slice(0,7)===u.slice(0,7)?u:`${c.slice(0,8)}01`),g=o==="month"?x:o==="week"&&!i?e.selected:null,w=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 t.jsxs("div",{className:"cal",role:"region","aria-label":a,tabIndex:0,onKeyDown:w,children:[t.jsxs("div",{className:"cal-bar",children:[t.jsx($,{size:"sm","aria-label":`Previous ${p}`,onClick:()=>e.go(-1),children:t.jsx(ne,{name:"chevron-left",size:14})}),t.jsx($,{size:"sm",onClick:()=>e.go(0),children:"Today"}),t.jsx($,{size:"sm","aria-label":`Next ${p}`,onClick:()=>e.go(1),children:t.jsx(ne,{name:"chevron-right",size:14})}),t.jsxs("h3",{className:"cal-title","aria-live":"polite",children:[UK(o,c,h,m),l!==void 0?t.jsx("span",{className:"cal-count",children:l===0?"No events":l===1?"1 event":`${l} events`}):null]}),e.views.length>1?t.jsx(cn,{label:"View",options:e.views.map(v=>({value:v,label:qK[v]})),value:o,onChange:e.setView}):null]}),o==="week"?t.jsx(t9,{dates:f,today:u,events:n,hours:s??[7,21],onPick:e.select,onEvent:i}):null,o==="month"?t.jsx(s9,{dates:f,month:c.slice(0,7),today:u,events:n,selected:x,onPick:e.select,onEvent:i}):null,o==="list"?t.jsx("div",{className:"cal-list",children:f.map(v=>t.jsx(pC,{date:v,today:u,events:n,empty:r,onEvent:i},v))}):null,g?t.jsx(pC,{date:g,today:u,events:n,empty:r,onEvent:i}):null]})}function pC({date:e,today:n,events:s,empty:r,onEvent:a}){const i=Wb(s,e);return t.jsx(lt,{flush:!0,title:LK(e,n),children:t.jsx(yt,{children:i.length===0?t.jsx(pt,{title:t.jsx("span",{className:"muted",children:r})}):i.map(({event:l,part:o})=>t.jsx(pt,{lead:t.jsx("span",{className:"cal-dot","data-tone":l.tone,"aria-hidden":"true"}),title:l.title,sub:l.location||void 0,side:Hb(l,o),...a?{onClick:()=>a(l)}:{}},l.id))})})}function t9({dates:e,today:n,events:s,hours:r,onPick:a,onEvent:i}){const l=d.useRef(null);d.useLayoutEffect(()=>{const h=l.current;h&&(h.scrollTop=h.scrollHeight/24*r[0])},[r[0]]);const o=r9(l),c=e.map(h=>({date:h,items:Wb(s,h)})),u=h=>h===n?"true":void 0;return t.jsx(lt,{flush:!0,children:t.jsxs("div",{className:"cal-week",role:"grid","aria-label":`Week of ${us(e[0])}`,style:{"--cal-span":r[1]-r[0],"--cal-scrollbar":`${o}px`},children:[t.jsxs("div",{className:"cal-row",role:"row",children:[t.jsx("span",{className:"cal-gutter","aria-hidden":"true"}),e.map(h=>t.jsxs("div",{className:"cal-day-head",role:"columnheader","data-today":u(h),"aria-label":us(h),children:[t.jsx("span",{className:"cal-wd",children:BP(h)}),t.jsx("span",{className:"cal-num",children:WP(h)})]},h))]}),t.jsxs("div",{className:"cal-row cal-allday",role:"row",children:[t.jsx("span",{className:"cal-gutter cal-gutter-label",children:"All day"}),c.map(({date:h,items:m})=>t.jsx("div",{className:"cal-allday-cell",role:"gridcell","data-today":u(h),children:m.filter(f=>f.part.allDay).map(({event:f,part:p})=>t.jsx("button",{type:"button",className:"cal-chip","data-tone":f.tone,"aria-label":vv(f,p,h),onClick:()=>i?i(f):a(h),children:f.title},f.id))},h))]}),t.jsx("div",{className:"cal-scroll",ref:l,children:t.jsxs("div",{className:"cal-row cal-times",role:"row",children:[t.jsx("div",{className:"cal-gutter cal-hours","aria-hidden":"true",children:Array.from({length:23},(h,m)=>m+1).map(h=>t.jsx("span",{className:"cal-hour-label",style:{top:`calc(var(--cal-hour) * ${h})`},children:Er(h*60)},h))}),c.map(({date:h,items:m})=>t.jsx("div",{className:"cal-col",role:"gridcell","aria-label":us(h),"data-today":u(h),children:HK(m.filter(f=>!f.part.allDay)).map(({event:f,part:p,lane:x,lanes:g})=>t.jsxs("button",{type:"button",className:"cal-event","data-tone":f.tone,"data-short":p.to-p.from<60?"true":void 0,"data-lane":x,"aria-label":vv(f,p,h),onClick:()=>i?i(f):a(h),style:{top:`calc(var(--cal-hour) * ${p.from/60})`,height:`calc(var(--cal-hour) * ${Math.max(p.to-p.from,HP)/60})`,left:`calc((100% - var(--space-1)) * ${x/g} + var(--space-0))`,width:`calc((100% - var(--space-1)) / ${g} - var(--space-0))`},children:[t.jsx("span",{className:"cal-event-time",children:Hb(f,p)}),t.jsx("span",{className:"cal-event-title",children:f.title})]},f.id))},h))]})})]})})}const n9=3;function s9({dates:e,month:n,today:s,events:r,selected:a,onPick:i,onEvent:l}){const o=Array.from({length:6},(m,f)=>e.slice(f*7,f*7+7)),[c,u]=n.split("-").map(Number),h=vR(c,u);return t.jsx(lt,{flush:!0,children:t.jsxs("div",{className:"cal-month",role:"grid","aria-label":h,children:[t.jsx("div",{className:"cal-row",role:"row",children:e.slice(0,7).map(m=>t.jsx("div",{className:"cal-wd-head",role:"columnheader",children:BP(m)},m))}),o.map(m=>t.jsx("div",{className:"cal-row",role:"row",children:m.map(f=>{const p=Wb(r,f),x=p.slice(0,n9),g=p.length-x.length,w=p.length===0?"nothing":p.length===1?"1 event":`${p.length} events`;return t.jsxs("div",{className:"cal-cell",role:"gridcell","aria-selected":f===a,"data-date":f,"data-today":f===s?"true":void 0,"data-outside":f.slice(0,7)!==n?"true":void 0,"data-selected":f===a?"true":void 0,onClick:()=>i(f),children:[t.jsx("button",{type:"button",className:"cal-num","aria-label":`${us(f)}, ${w}`,"aria-pressed":f===a,children:WP(f)}),x.map(({event:v,part:j})=>t.jsx("button",{type:"button",className:"cal-chip","data-tone":v.tone,"data-timed":j.allDay?void 0:"true","aria-label":vv(v,j,f),...l?{onClick:y=>{y.stopPropagation(),i(f),l(v)}}:{},children:j.allDay?v.title:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"cal-dot","data-tone":v.tone,"aria-hidden":"true"}),t.jsx("span",{className:"cal-chip-time",children:Er(j.from)})," ",v.title]})},v.id)),g>0?t.jsxs("button",{type:"button",className:"cal-more","aria-label":`${g} more on ${us(f)}`,children:["+",g]}):null]},f)})},m[0]))]})})}function r9(e){const[n,s]=d.useState(0);return d.useLayoutEffect(()=>{const r=e.current;if(!r)return;const a=()=>s(Math.max(0,r.offsetWidth-r.clientWidth));if(a(),typeof ResizeObserver>"u")return;const i=new ResizeObserver(a);return i.observe(r),()=>i.disconnect()},[e]),n}const KP={width:1200,height:200,top:28,right:12,bottom:24,left:36};function a9(e,n){if(n==="percent")return[0,50,100];let s=e.length>0?Math.min(...e):0,r=e.length>0?Math.max(...e):1;n!=="temp"&&(s=Math.min(0,s)),s===r&&(s-=1,r+=1);const a=10**Math.floor(Math.log10(Math.max(1,(r-s)/3))),i=c=>Math.ceil(r/c)-Math.floor(s/c);let l=[1,2,5,10].map(c=>c*a).find(c=>i(c)<=3)??a*10;i(l)<2&&(l>1?l/=2:r+=l);const o=[];for(let c=Math.floor(s/l)*l;c<=Math.ceil(r/l)*l+l/1e3;c+=l)o.push(Math.round(c*1e6)/1e6);return o}function dh(e,n){return n==="temp"?`${e}°`:n==="percent"?`${e}%`:String(e)}function i9(e){const n=KP,s=e.values.length,r=n.width-n.left-n.right,a=n.height-n.top-n.bottom,i=n.height-n.bottom,l=s>0?r/s:r,o=v=>Ki(n.left+l*(v+.5)),c=e.values.filter(v=>v!==null&&Number.isFinite(v)),u=a9(c,e.unit),h=u[0],m=u[u.length-1],f=v=>Ki(n.top+a-(v-h)/(m-h)*a),p=e.values.map((v,j)=>{const y=v!==null&&Number.isFinite(v);return{index:j,x:o(j),y:y?f(v):null,value:y?v:null}}),x=[],g=[];if(e.kind==="area"){let v=[];const j=()=>{if(v.length===0)return;const y=v.map((k,N)=>`${N===0?"M":"L"}${k.x},${k.y}`).join(" ");x.push(y),g.push(`${y} L${v[v.length-1].x},${i} L${v[0].x},${i} Z`),v=[]};for(const y of p)y.y===null?j():v.push(y);j()}const w=e.kind==="bars"?p.flatMap(v=>v.y===null?[]:[{index:v.index,x:Ki(v.x-l*.28),y:v.y,width:Ki(l*.56),height:Ki(i-v.y)}]):[];return{ticks:u.map(v=>({value:v,y:f(v)})),lines:x,areas:g,bars:w,points:p,slot:l,floor:i}}function l9({title:e,note:n,xs:s,series:r,tiles:a,labelEvery:i=3}){var N;const[l,o]=d.useState(((N=r[0])==null?void 0:N.id)??""),[c,u]=d.useState(null),[h,m]=d.useState(null),f=d.useRef(null),p=s.length,x=c??h,g=r.find(b=>b.id===l)??r[0],w=i9(g),v=KP,j=b=>b%i===0||b===x,y=g.values.filter(b=>b!==null&&Number.isFinite(b));d.useEffect(()=>{const b=f.current,S=x===null?null:b==null?void 0:b.children[x];!b||!S||typeof b.scrollTo!="function"||(S.offsetLeft<b.scrollLeft?b.scrollTo({left:S.offsetLeft,behavior:"smooth"}):S.offsetLeft+S.offsetWidth>b.scrollLeft+b.clientWidth&&b.scrollTo({left:S.offsetLeft+S.offsetWidth-b.clientWidth,behavior:"smooth"}))},[x]);const k=b=>{var A,E,R;const S=b.key==="ArrowRight"?1:b.key==="ArrowLeft"?-1:0,C=b.key==="Home"?0:b.key==="End"?p-1:S===0?null:Math.max(0,Math.min(p-1,(h??-S)+S));C!==null&&(b.preventDefault(),m(C),(R=(E=(A=f.current)==null?void 0:A.children[C])==null?void 0:E.querySelector("button"))==null||R.focus())};return t.jsxs(lt,{...e?{title:e}:{},children:[n?t.jsx("p",{className:"ui-panel-sub",children:n}):null,t.jsxs("div",{className:"pg-series",onMouseLeave:()=>u(null),children:[r.length>1?t.jsx("div",{className:"pg-series-tabs",role:"tablist","aria-label":"Series",children:r.map(b=>t.jsx("button",{type:"button",role:"tab",className:"ui-tab","aria-selected":b.id===g.id,onClick:()=>o(b.id),children:b.label},b.id))}):null,t.jsxs("figure",{className:"pg-series-chart","data-kind":g.kind,children:[t.jsxs("svg",{viewBox:`0 0 ${v.width} ${v.height}`,"aria-hidden":"true",focusable:"false","data-testid":"series-svg",children:[w.ticks.map(b=>t.jsxs("g",{children:[t.jsx("line",{className:"pg-series-grid",x1:v.left,x2:v.width-v.right,y1:b.y,y2:b.y}),t.jsx("text",{className:"pg-series-tick",x:v.left-8,y:b.y,textAnchor:"end",dominantBaseline:"middle",children:dh(b.value,g.unit)})]},b.value)),w.areas.map((b,S)=>t.jsx("path",{className:"pg-series-area",d:b},`a${S}`)),w.lines.map((b,S)=>t.jsx("path",{className:"pg-series-line",d:b},`l${S}`)),w.bars.map(b=>t.jsx("rect",{className:"pg-series-bar","data-index":b.index,"data-hover":b.index===x?"true":void 0,x:b.x,y:b.y,width:b.width,height:b.height},b.index)),x!==null&&w.points[x]?t.jsx("line",{className:"pg-series-guide","data-index":x,x1:w.points[x].x,x2:w.points[x].x,y1:v.top-4,y2:w.floor}):null,g.kind==="area"?w.points.map(b=>b.y!==null&&j(b.index)?t.jsx("circle",{className:"pg-series-dot","data-index":b.index,"data-hover":b.index===x?"true":void 0,cx:b.x,cy:b.y,r:b.index===x?5:3},b.index):null):null,w.points.map(b=>b.y!==null&&b.value!==null&&j(b.index)?t.jsx("text",{className:"pg-series-value","data-index":b.index,"data-hover":b.index===x?"true":void 0,x:b.x,y:b.y-(g.kind==="area"?10:6),textAnchor:"middle",children:dh(b.value,g.unit)},b.index):null),w.points.map(b=>b.index%i===0?t.jsx("text",{className:"pg-series-x",x:b.x,y:v.height-6,textAnchor:"middle",children:s[b.index]},b.index):null),w.points.map(b=>t.jsx("rect",{className:"pg-series-hit","data-index":b.index,x:Ki(v.left+w.slot*b.index),y:0,width:Ki(w.slot),height:v.height,onMouseEnter:()=>u(b.index),onClick:()=>m(b.index)},b.index))]}),t.jsx("figcaption",{className:"sr-only",children:y.length===0?`${g.label}: no values.`:`${g.label}, ${p} ${p===1?"point":"points"} from ${s[0]} to ${s[p-1]}: lowest ${dh(Math.min(...y),g.unit)}, highest ${dh(Math.max(...y),g.unit)}.`})]}),t.jsx("ul",{className:"wb-tiles","data-layout":"strip",ref:f,onKeyDown:k,children:a.map((b,S)=>t.jsx("li",{className:"wb-tile",children:t.jsx("button",{type:"button",className:"ui-card","data-index":S,"data-hover":S===x?"true":void 0,"aria-pressed":S===h,"aria-label":[b.label,b.value,...b.lines].filter(C=>C!=="").join(", "),onMouseEnter:()=>u(S),onClick:()=>m(S),children:t.jsxs("div",{className:"wb-tile-body","aria-hidden":"true",children:[t.jsx("span",{className:"wb-tile-icon","data-icon":b.icon??"dot",children:t.jsx(ne,{name:oc(b.icon),size:22})}),b.value!==""?t.jsx("span",{className:"wb-tile-value tnum",children:b.value}):null,t.jsx("span",{className:"wb-tile-label",children:b.label}),b.lines.map((C,A)=>t.jsx("span",{className:"wb-tile-line",children:C},A))]})})},S))})]})]})}function Ki(e){return Math.round(e*10)/10}function VP(e){const n=()=>{document.visibilityState==="hidden"&&e()};return document.addEventListener("visibilitychange",n),window.addEventListener("blur",e),()=>{document.removeEventListener("visibilitychange",n),window.removeEventListener("blur",e)}}function o9(e,n){d.useEffect(()=>{if(e)return VP(()=>n())},[e])}function Kb(){const[e,n]=d.useState(!1);return o9(e,()=>n(!1)),[e,()=>n(s=>!s)]}const gC=5*6e4;let GP=0,hh,Ec;const wv=new Set;function c9(){for(const e of wv)e()}function bv(e,n=Date.now()){hh!==void 0&&clearTimeout(hh),hh=void 0,GP=e?n+gC:0,e&&(hh=setTimeout(()=>bv(!1),gC)),e&&!Ec&&typeof window<"u"&&(Ec=VP(()=>bv(!1))),!e&&Ec&&(Ec(),Ec=void 0),c9()}function Mg(){return GP>0}function u9(e){return wv.add(e),()=>wv.delete(e)}function Vb(){return[d.useSyncExternalStore(u9,Mg,Mg),()=>bv(!Mg())]}const wp=d.createContext(null),Qf=d.createContext(!1);function jt(){const e=d.useContext(wp);if(!e)throw new Error("a plugin page component outside a plugin page");return e}function Jf(e,n=new Set){if(Array.isArray(e))for(const s of e)Jf(s,n);else if(e&&typeof e=="object"){const s=e.query;typeof s=="string"&&n.add(s);for(const r of Object.values(e))Jf(r,n)}return n}function qP(e,n){if(n.size===0)return!1;for(const s of Jf(e))if(n.has(s))return!0;return!1}function d9(e,n){var s;for(const r of Jf(e))if((((s=n[r])==null?void 0:s.length)??0)>0)return!0;return!1}function h9(){const[e,n]=Vb();return t.jsx(Rb,{shown:e,onToggle:n,show:"Show amounts",hide:"Hide amounts"})}function YP({revealed:e,onToggle:n}){return t.jsx(Rb,{size:"sm",shown:e,onToggle:n})}function QP(){return t.jsx("p",{className:"muted",children:"Hidden until you show it."})}function JP({children:e}){const[n,s]=Kb();return t.jsxs(ue,{gap:"sm",children:[t.jsx(te,{align:"end",children:t.jsx(YP,{revealed:n,onToggle:s})}),n?t.jsx(Qf.Provider,{value:!0,children:e}):t.jsx(QP,{})]})}function Gb(e){return e===void 0||e==="neutral"?void 0:e}function kv(e){return Gb(e)}function f9(e){const n=Gb(e);return n==="accent"?void 0:n}function Kt(e,n){if(!n)return!0;const s=Re(e,n.path),r=n.in!==void 0?n.in.includes(s):s===n.equals;return n.not===!0?!r:r}function Xf(e){if(typeof e!="string"||e.length>2048)return null;try{const n=new URL(e);return n.protocol==="https:"&&n.hostname!==""&&n.username===""&&n.password===""?n.href:null}catch{return null}}function m9({plugin:e,images:n,row:s}){const a=(Array.isArray(n)?n.map(l=>({asset:Be(s,l.asset),label:String(Be(s,l.label)??"").trim()})):(()=>{const l=Re(s,n.from);return(Array.isArray(l)?l:[]).map(o=>({asset:Re(o,n.asset),label:String(Re(o,n.label)??"").trim()}))})()).filter(l=>l.label!=="");if(a.length===0)return null;const i=a.length===1?a[0].label:`${a[0].label} and ${a.length-1} more`;return t.jsxs("span",{className:"pl-stack","data-testid":"row-images",children:[t.jsx("span",{className:"pl-stack-logos",children:a.slice(0,3).map((l,o)=>t.jsx(Cl,{src:Sl(e,l.asset),label:l.label},o))}),t.jsx("span",{className:"pl-stack-words",children:i})]})}function Oo({href:e,children:n,className:s}){return t.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:s,onClick:r=>r.stopPropagation(),children:[n,t.jsx("span",{className:"wb-src-out","aria-hidden":"true",children:"↗"}),t.jsx("span",{className:"sr-only",children:" (opens in a new tab)"})]})}function za(e,n,s){if("href"in n)return Xf(Be(s,n.href))??"";if("chat"in n){const o=Be(s,n.chat);return o==null?"":ut(String(o))}if("proposals"in n)return aW(e.plugin);const r=e.pages.find(o=>o.id===n.page);if((r==null?void 0:r.place)==="settings")return Or(e.plugin,n.page);const a=n.item===void 0?null:Be(s,n.item),i=Mr(e.plugin,n.page,a==null?null:String(a)),l=new URLSearchParams;for(const[o,c]of Object.entries(n.params??{})){const u=Be(s,c);u!=null&&l.set(o,String(u))}return l.size?`${i}?${l}`:i}function Ns(e,n){return e.replace(/\{count\}/g,String(n.count??0)).replace(/\{([^{}|]+)\|([^{}|]+)\}/g,(s,r,a)=>(n.count??0)===1?r:a).replace(/\{([A-Za-z_][A-Za-z0-9_.]*)\}/g,(s,r)=>{const a=Re(n.row,r);return a==null?"":String(a)})}function Zf(e,n){if(e===void 0)return;if(typeof e=="string")return e;const s=Be(n,e);return s==="good"||s==="warning"||s==="critical"||s==="neutral"?s:void 0}function XP(e,n,s){const r={};for(const[a,i]of Object.entries(e??{})){let l;"param"in i?l=s.params[i.param]:"route"in i?l=i.route==="plugin"?s.plugin:i.route==="page"?s.page:s.item:l=Be(hi(n),i),!(l==null||l==="")&&(r[a]=String(l))}return r}function Xs(e,n){var r,a,i;const s={};for(const[l,o]of Object.entries(e??{}))if("row"in o)s[l]=Re(hi(n.row),o.row);else if("choice"in o)s[l]=n.choice;else if("field"in o){if((r=n.omit)!=null&&r.has(o.field))continue;const c=(a=n.fields)==null?void 0:a[o.field],u=(i=n.shape)==null?void 0:i.find(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]=n.selected??[]:"param"in o?s[l]=n.scope.params[o.param]:s[l]=Be(hi(n.data),o);return s}function wn(e,n,s,r){const a=jt(),i=e?XP(e.params,n,a):{},l=e?{...i,...r}:{},o=JSON.stringify([(e==null?void 0:e.query)??null,i]),c=JSON.stringify([(e==null?void 0:e.query)??null,l,a.version]),u=je(()=>e?T.pageQuery(a.plugin,e.query,l).then(x=>({asked:o,data:x.data})):Promise.resolve({asked:o,data:void 0}),[c],s),h=u.data!==void 0&&u.data.asked===o,m=e&&!a.amountsShown?a.sensitivePaths[e.query]:void 0,f=h?u.data.data:void 0;return{data:d.useMemo(()=>qH(f,m),[f,m]),error:h||!u.loading?u.error:null,loading:u.loading}}function ha(){const e=jt(),n=d.useId(),[s,r]=d.useState(null),[a,i]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(null),[h,m]=d.useState(null),[f,p]=d.useState(0),x=(y,k)=>{if(y.done===void 0)return null;if(typeof y.done=="string")return y.done;const N=Be(k,y.done);return N==null?null:String(N)},g=(y,k,N)=>{p(S=>S+1);const b=y??"refresh";if(typeof b=="object"){const S="href"in b.route?"":za(e,b.route,k);S===""?e.refresh():e.navigate(S);return}b==="close"&&(N==null||N()),e.refresh()},w=async(y,k,N)=>{r(y.tool),i(null),o(null);try{const b=await T.pageAct(e.plugin,{tool:y.tool,args:k});if(b.approvalId)return u(b.approvalId),m({then:y.then,ref:y,...N?{onDone:N}:{}}),!1;u(null),m(null);const S=LP(b.result);return o(x(y,b.result)??(S?FP(b.result):null)),S&&await zP(S,n),g(y.then,b.result,N),!0}catch(b){return i(b instanceof Error?b.message:String(b)),e.refresh(),!1}finally{r(null)}},v=y=>{if(!y){e.refresh();return}const k=h;if(u(null),m(null),k&&y.decision==="approve"&&y.state==="succeeded"){o(x(k.ref,y.result)),g(k.then,void 0,k.onDone);return}e.refresh()},j=()=>{i(null),o(null)};return{running:s,busy:s!==null,error:a,done:l,approvalId:c,waiting:(h==null?void 0:h.ref.pending)??null,settle:v,run:w,reset:j,happened:f}}function Pi({action:e,args:n,disabled:s,running:r,count:a,row:i,onRun:l}){const[o,c]=d.useState(!1),u=s===!0||Sv(n),h=f=>Ns(f,{...a===void 0?{}:{count:a},row:i}),m=h(e.label);return o&&e.confirm?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"ui-toolbar-note",children:h(e.confirm)}),t.jsx($,{variant:"ghost",onClick:()=>c(!1),children:"Cancel"}),t.jsxs($,{variant:e.tone==="danger"?"danger":"accent",disabled:u,onClick:()=>{c(!1),l(e,n)},children:["Yes, ",m.toLowerCase()]})]}):t.jsx($,{variant:e.tone==="danger"?"danger":e.tone==="accent"?"accent":void 0,disabled:u,onClick:()=>e.confirm?c(!0):l(e,n),children:r&&e.busy?e.busy:m})}function em({id:e,onDecided:n}){const s=jt(),r=je(()=>T.approval(e),[e,s.version]),{busy:a,note:i,failure:l,decide:o}=Pb(c=>{n?n(c):s.refresh()});return r.error?t.jsx(re,{message:r.error}):r.data?t.jsxs(ue,{children:[t.jsx(Mb,{action:r.data,timezone:s.timezone,busy:a===e,onDecide:(c,u,h,m)=>{o(c,u,h,m)}}),i?t.jsx(Q,{tone:"good",role:"status",children:i}):null,t.jsx(re,{message:l})]}):t.jsx(Ee,{children:"Loading the approval…"})}function Lr({act:e}){return e.error?t.jsx(re,{message:e.error}):e.approvalId?e.waiting?t.jsxs(ue,{children:[t.jsx(Q,{role:"status",children:e.waiting}),t.jsx(em,{id:e.approvalId,onDecided:e.settle})]}):t.jsx(em,{id:e.approvalId,onDecided:e.settle}):e.done?t.jsx(Q,{tone:"good",role:"status",children:e.done}):null}function Nv(e,n){const s={};for(const r of e){const a=r.from===void 0?void 0:Re(n,r.from);s[r.name]=r.multiple?Array.isArray(a)?a.map(String):[]:a!==void 0?a:r.type==="checkbox"?!1:""}return s}function Sv(e){return e===yi?!0:Array.isArray(e)?e.some(Sv):e!==null&&typeof e=="object"?Object.values(e).some(Sv):!1}function qb(e,n){const s=Nv(e,n),r=JSON.stringify(s),[a,i]=d.useState(()=>({values:s,base:s,key:r}));let l=a;if(a.key!==r){const c={...a.values};for(const u of e)JSON.stringify(a.values[u.name])!==JSON.stringify(a.base[u.name])||(c[u.name]=s[u.name]);l={values:c,base:s,key:r},i(l)}const o=(c,u)=>i(h=>({...h,values:{...h.values,[c]:u}}));return[l.values,o]}function ZP(e,n,s){const r=jt(),a=e.optionsFrom,i=a?{...XP(a.query.params,s,r),...Object.fromEntries((a.dependsOn??[]).map(c=>[c,String(n[c]??"")]).filter(([,c])=>c!==""))}:{},l=JSON.stringify([(a==null?void 0:a.query.query)??null,i,r.version]),o=je(()=>a?T.pageQuery(r.plugin,a.query.query,i).then(c=>c.data):Promise.resolve(void 0),[l]);return a?{options:Fr(o.data,a.rows).map(c=>({value:String(Re(c,a.value)??""),label:String(Re(c,a.label)??"")})),loading:o.loading}:{options:e.options??[],loading:!1}}function p9({field:e,fields:n,value:s,values:r,data:a,disabled:i,compact:l,onChange:o}){const c=ZP(e,r,a),u={id:`f-${e.name}`,required:e.required,name:e.name,disabled:i,...l&&e.hint?{title:e.hint}:{}},h=l?void 0:e.hint;if(e.type==="select"&&e.multiple){const f=Array.isArray(s)?s.map(String):[],x=e.max!==void 0&&f.length>=e.max?`Up to ${e.max}; remove one to add another.`:void 0;return t.jsx(le,{label:e.label,hint:l?void 0:[h,x].filter(Boolean).join(" ")||void 0,group:!0,children:t.jsx(EW,{id:u.id,label:e.label,options:c.options,value:f,max:e.max,disabled:i,onChange:o})})}if(e.type==="select"){const f=t.jsxs("select",{...u,value:String(s??""),onChange:p=>o(p.target.value),children:[t.jsx("option",{value:"",children:c.loading?"Loading…":"—"}),c.options.map(p=>t.jsx("option",{value:p.value,children:p.label},p.value))]});return e.action&&!l?t.jsx(g9,{field:e,action:e.action,fields:n??[e],values:r,data:a,disabled:i,hint:h,children:f}):t.jsx(le,{label:e.label,hint:h,children:f})}if(e.type==="textarea")return t.jsx(le,{label:e.label,hint:h,wide:!0,children:t.jsx("textarea",{...u,value:String(s??""),onChange:f=>o(f.target.value),rows:6})});if(e.type==="checkbox")return t.jsx(le,{label:e.label,hint:h,inline:!0,wide:!l,children:t.jsx("input",{...u,type:"checkbox",checked:s===!0,onChange:f=>o(f.target.checked)})});const m=e.type==="secret"?"password":e.type==="number"?"number":e.type;return t.jsx(le,{label:e.label,hint:h,children:t.jsx("input",{...u,type:m,value:s==null?"":String(s),min:e.min,max:e.max,step:e.step,...l&&e.hint?{placeholder:e.hint}:{},onChange:f=>o(e.type==="number"?x9(f.target.value):f.target.value)})})}function g9({field:e,action:n,fields:s,values:r,data:a,disabled:i,hint:l,children:o}){const c=jt(),u=d.useId(),h=OK()===u,[m,f]=d.useState(!1),[p,x]=d.useState(null),[g,w]=d.useState(null),[v,j]=d.useState(null);d.useEffect(()=>()=>dC(u),[u]);const y=Yb(s,r,a),k=n.args!==void 0?Xs(n.args,{data:a,fields:r,shape:s,omit:y,scope:c}):Object.fromEntries(Object.entries(r).filter(([S,C])=>!y.has(S)&&C!=="")),N=async()=>{if(h){dC(u);return}f(!0),x(null),w(null),j(null);try{const S=await T.pageAct(c.plugin,{tool:n.tool,args:k});if(S.approvalId){j(S.approvalId);return}x(FP(S.result));const C=LP(S.result);C&&await zP(C,u)}catch(S){w(S instanceof Error?S.message:String(S))}finally{f(!1)}},b=h?"Stop":n.label;return t.jsx(le,{label:e.label,hint:l,action:t.jsx($,{"data-shape":"icon","aria-label":m?`${n.label}: working`:b,title:b,"aria-busy":m||void 0,"aria-pressed":n.icon==="play"?h:void 0,disabled:i===!0||m,onClick:()=>void N(),children:m?t.jsx("span",{className:"ui-spinner","aria-hidden":"true"}):t.jsx(ne,{name:h?"stop":n.icon??"arrow"})}),after:g?t.jsx(re,{message:g}):v?t.jsx(em,{id:v,onDecided:()=>j(null)}):p?t.jsx("span",{className:"ui-field-hint",role:"status",children:p}):null,children:o})}function x9(e){if(e.trim()==="")return"";const n=Number(e);return Number.isFinite(n)?n:e}function eM(e,n){return{...typeof n=="object"&&n!==null?n:{},...e}}function Yb(e,n,s){const r=eM(n,s);return new Set(e.filter(a=>a.when!==void 0&&!Kt(r,a.when)||a.disabledWhen!==void 0&&Kt(r,a.disabledWhen)).map(a=>a.name))}function bp({fields:e,values:n,data:s,disabled:r,compact:a,columns:i,onChange:l}){const o=eM(n,s);return t.jsx(Vs,{dense:a,columns:i,children:e.filter(c=>c.when===void 0||Kt(o,c.when)).map(c=>t.jsx(p9,{field:c,fields:e,compact:a,value:n[c.name],values:n,data:s,disabled:r===!0||c.disabledWhen!==void 0&&Kt(o,c.disabledWhen),onChange:u=>l(c.name,u)},c.name))})}const pl=d.createContext(!1),tM=d.createContext(!1),nM=d.createContext(!1);function Zs({title:e,note:n,actions:s,children:r,plain:a}){const l=d.useContext(pl)&&!a;return t.jsx(ye,{title:e,aside:n,actions:s,panel:l,children:t.jsx(pl.Provider,{value:!1,children:t.jsx(tM.Provider,{value:l,children:r})})})}function j9({component:e,data:n}){return jt().params[e.param]?t.jsx(v9,{component:e,data:n}):null}function v9({component:e,data:n}){const s=jt(),r=wn(e.query,n),a=e.query?r.data:n,i=e.heading?Be(a,e.heading):void 0,l=typeof i=="string"&&i!==""?i:e.title;return t.jsx(Ye,{scrollBody:!0,title:l,onClose:()=>{s.setParams({[e.param]:null});const o=new URLSearchParams(s.params);o.delete(e.param),o.delete("item"),s.navigate(`${Mr(s.plugin,s.page,s.item)}${o.size?`?${o}`:""}`)},children:e.query&&r.loading&&r.data===void 0?t.jsx(Q,{children:"Loading…"}):r.error?t.jsx(re,{message:r.error}):t.jsx(ue,{children:e.body.map((o,c)=>t.jsx(Ws,{component:o,data:a},c))})})}function y9({component:e,data:n}){const s=jt(),r=uP({edition:Re(n,e.path)});if(!r)return e.emptyTitle||e.empty?t.jsx(Ee,{title:e.emptyTitle,children:e.empty}):null;const a=r.report&&hP(s.plugin,r.report)?r.report:null;return t.jsx(fP,{edition:r,plugin:s.plugin,audio:a?t.jsx(dP,{link:a}):null})}function w9({plugin:e,query:n,params:s,body:r,timezone:a,navigate:i}){const[l,o]=d.useState({}),[c,u]=d.useState(0),[h]=Vb();PI(e,()=>u(p=>p+1));const m={plugin:e,page:"",pages:[],item:null,params:l,setParams:p=>o(x=>{const g={...x};for(const[w,v]of Object.entries(p))v===null?delete g[w]:g[w]=v;return g}),navigate:i??(p=>{window.location.hash=p}),timezone:a,version:c,refresh:()=>u(p=>p+1),sensitive:new Set,sensitivePaths:hM,amountsShown:h},f={query:n,params:Object.fromEntries(Object.entries(s).map(([p,x])=>[p,{const:x}]))};return t.jsx(wp.Provider,{value:m,children:t.jsx(b9,{queryRef:f,body:r})})}function b9({queryRef:e,body:n}){const s=wn(e,null);return s.error?t.jsx(re,{message:s.error}):s.data===void 0?t.jsx(Q,{children:"Loading…"}):t.jsx(ue,{children:n.map((r,a)=>t.jsx(Ws,{component:r,data:s.data},a))})}function Ws({component:e,data:n,choose:s,chosen:r}){const a=jt(),i=d.useContext(Qf);if(!Kt(n,e.when)||e.where!==void 0&&e.where!==(N9()?"local":"remote"))return null;if(e.kind!=="section"&&!i&&qP(e,a.sensitive))return t.jsx(JP,{children:t.jsx(Ws,{component:e,data:n,...s?{choose:s}:{},...r===void 0?{}:{chosen:r}})});switch(e.kind){case"section":return t.jsx(k9,{component:e,data:n});case"notice":return t.jsx(S9,{component:e,data:n});case"link":return t.jsx(C9,{component:e,data:n});case"progress":return t.jsx(A9,{component:e,data:n});case"chart":return t.jsx($9,{component:e,data:n});case"stats":return t.jsx(T9,{component:e,data:n});case"list":return t.jsx(P9,{component:e,data:n,...s?{onChoose:s}:{},...r===void 0?{}:{chosen:r}});case"table":return t.jsx(F9,{component:e,data:n});case"detail":return t.jsx(B9,{component:e,data:n});case"form":return t.jsx(W9,{component:e,data:n});case"search":return t.jsx(V9,{component:e,data:n});case"list-detail":return t.jsx(G9,{component:e,data:n});case"repeat":return t.jsx(q9,{component:e,data:n});case"calendar":return t.jsx(Y9,{component:e,data:n});case"tiles":return t.jsx(J9,{component:e,data:n});case"series-panel":return t.jsx(X9,{component:e,data:n});case"hero":return t.jsx(Z9,{component:e,data:n});case"tabs":return t.jsx(eV,{component:e,data:n});case"expand":return t.jsx(tV,{component:e,data:n});case"button":return t.jsx(cM,{component:e,data:n});case"menu":return t.jsx(sM,{component:e,data:n});case"sheet":return t.jsx(j9,{component:e,data:n});case"digest":return t.jsx(y9,{component:e,data:n});case"approval":return t.jsx(hV,{component:e,data:n});case"artifact":return t.jsx(fV,{component:e,data:n});case"message":return t.jsx(gV,{component:e,data:n});case"editor":return t.jsx(jV,{component:e,data:n});case"agent-offer":return t.jsx(nV,{component:e});case"stories":return t.jsx(aV,{component:e,data:n});default:return t.jsx(Q,{children:"This page uses a part this dashboard does not know yet. Reload buddi to see it."})}}function k9({component:e,data:n}){const s=jt(),r=d.useContext(Qf),[a,i]=Kb(),l=!r&&qP([e.query,e.body],s.sensitive),o=l&&!a,c=wn(o?void 0:e.query,n),u=e.query?c.data:n,h=e.heading&&!o?Be(u,e.heading):void 0,m=h==null||h===""?e.title:String(h),f=d.useContext(pl);let p=e.body.length;const x=N=>{var b;return N.kind==="button"||N.kind==="link"||N.kind==="menu"||N.kind==="form"&&((b=N.drawer)==null?void 0:b.button)!==void 0&&!N.title};for(;f&&e.look!=="setup"&&p>0&&x(e.body[p-1]);)p-=1;const g=e.body.slice(0,p),w=e.look==="setup"?g.filter(N=>N.kind==="button").sort((N,b)=>+(N.kind==="button"&&N.action.tone==="accent")-+(b.kind==="button"&&b.action.tone==="accent")):[],v=e.look==="setup"?g.filter(N=>N.kind!=="button"):g,j=[...e.actions??[],...e.body.slice(p)],[y,k]=d.useState(null);return t.jsx(Cv.Provider,{value:k,children:t.jsx("div",{className:e.look==="setup"?"pp-setup":void 0,style:e.look==="setup"?void 0:{display:"contents"},children:t.jsx(Zs,{plain:e.look==="setup",title:m,note:e.note,actions:j.length>0||l?t.jsxs(t.Fragment,{children:[j.map((N,b)=>t.jsx(Ws,{component:N,data:u},b)),l?t.jsx(YP,{revealed:a,onToggle:i}):null]}):void 0,children:t.jsxs(ue,{gap:"lg",divided:f,children:[y,e.query&&!o?t.jsx(re,{message:c.error}):null,o?t.jsx(QP,{}):e.query&&c.data===void 0&&!c.error?t.jsx(Ee,{children:"Loading…"}):t.jsx(Qf.Provider,{value:r||l,children:t.jsxs(Cv.Provider,{value:null,children:[v.map((N,b)=>t.jsx(Ws,{component:N,data:u},b)),w.length>0?t.jsx("div",{className:"pp-setup-actions",children:w.map((N,b)=>t.jsx(Ws,{component:N,data:u},b))}):null]})})]})})})})}const Cv=d.createContext(null);function N9(){const e=typeof location>"u"?"":location.hostname;return e==="127.0.0.1"||e==="localhost"||e==="::1"||e==="[::1]"}function sM({component:e,data:n}){var c;const s=jt(),r=ha(),a=d.useContext(Cv),i=e.items.filter(u=>Kt(n,u.when)).map(u=>({label:u.label,...u.hint?{hint:u.hint}:{},onSelect:()=>{u.open!==void 0?s.setParams({open:u.open}):u.action&&r.run(u.action,Xs(u.action.args,{data:n,row:n,scope:s}))}})),l=(c=e.items.find(u=>{var h;return((h=u.action)==null?void 0:h.tool)===r.running}))==null?void 0:c.action,o=r.error||r.done||r.approvalId?t.jsx(Lr,{act:r}):null;return d.useEffect(()=>{a&&a(o)},[r.error,r.done,r.approvalId,r.waiting]),d.useEffect(()=>()=>a==null?void 0:a(null),[a]),t.jsxs(t.Fragment,{children:[t.jsx(rs,{label:e.label,items:i,stacked:e.items.some(u=>u.hint!==void 0),trigger:t.jsxs("button",{type:"button",className:"ui-btn pl-menu-btn","data-variant":e.tone==="accent"?"accent":void 0,disabled:r.busy,children:[(l==null?void 0:l.busy)??e.label,t.jsx(ne,{name:"chevron-down",size:12})]})}),a?null:o]})}function S9({component:e,data:n}){const s=jt(),r=ha(),a=typeof e.text=="string"?e.text:String(Be(n,e.text)??""),i=e.link&&Kt(n,e.link.when)?e.link:void 0,l=i?za(s,i.to,n):"",o=i?typeof i.label=="string"?i.label:String(Be(n,i.label)??""):"",c=i&&l!==""&&o!==""?"href"in i.to?t.jsx(Oo,{href:l,children:o}):t.jsx("a",{href:l,onClick:h=>{h.preventDefault(),s.navigate(l)},children:o}):null;if(e.look==="quiet")return a===""&&!c?null:t.jsxs("p",{className:"pl-quiet","data-tone":e.tone,children:[e.icon?t.jsx(ne,{name:e.icon,size:14}):null,t.jsxs("span",{children:[a,c?t.jsxs(t.Fragment,{children:[a?" · ":null,c]}):null]})]});const u=e.action;return t.jsxs(t.Fragment,{children:[t.jsxs(Q,{tone:Gb(e.tone),title:e.title,action:u?t.jsx(Pi,{action:u,args:Xs(u.args,{data:n,scope:s}),disabled:r.busy,running:r.running===u.tool,row:n,onRun:(h,m)=>void r.run(h,m)}):void 0,children:[a,c?t.jsxs(t.Fragment,{children:[" ",c]}):null]}),t.jsx(uM,{act:r})]})}function C9({component:e,data:n}){const s=jt(),r=za(s,e.to,n);return r===""?null:"href"in e.to?t.jsx(te,{children:t.jsxs(it,{href:r,target:"_blank",rel:"noopener noreferrer",variant:e.tone==="accent"?"accent":void 0,children:[e.label,t.jsx("span",{className:"wb-src-out","aria-hidden":"true",children:"↗"}),t.jsx("span",{className:"sr-only",children:" (opens in a new tab)"})]})}):t.jsx(te,{children:t.jsx(it,{href:r,variant:e.tone==="accent"?"accent":void 0,onClick:a=>{a.preventDefault(),s.navigate(r)},children:e.label})})}function xC(e){return Math.round(e/1e6)}function E9(e,n){const s=Us(Be(n,e.value))??0,r=e.total?Us(Be(n,e.total)):null,a=e.total?r&&r>0?s/r:0:s,i=Math.max(0,Math.min(1,a)),l=Math.floor(i*100),o=a>=1,c=e.total&&r&&r>0?`${xC(s)} of ${Math.max(1,xC(r))} MB · ${l}%`:`${l}%`;return{percent:l,full:o,line:c}}function A9({component:e,data:n}){const s=c=>c===void 0?"":typeof c=="string"?c:String(Be(n,c)??""),r=s(e.label),a=s(e.done),{percent:i,full:l,line:o}=E9(e,n);return t.jsxs(ue,{gap:"sm",children:[r?t.jsx("span",{children:r}):null,l&&a?t.jsx("span",{role:"status",children:a}):t.jsxs(t.Fragment,{children:[t.jsx(Sb,{value:i,label:r||"Progress"}),t.jsx("span",{role:"status",children:o})]})]})}function $9({component:e,data:n}){const s=wn(e.query,n),r=e.rows===void 0?Array.isArray(s.data)?s.data:[]:Fr(s.data,e.rows),a=r.map(h=>String(Re(h,e.x)??"")),i=h=>r.map(m=>Us(Re(m,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:i(h.y),type:h.type,...h.unit?{unit:h.unit}:{}})):o.map(h=>({label:o.length===1?e.label??h:h,values:i(h)})),u=e.target?Us(Be(s.data,e.target))??null:null;return t.jsxs(Zs,{title:e.title,note:e.note,children:[t.jsx(re,{message:s.error}),r.length===0?s.loading||s.data===void 0?t.jsx(Ee,{children:"Loading…"}):t.jsx(Al,{text:e.empty??"Nothing recorded yet."}):t.jsx(G5,{xs:a,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)?tv(h):h,formatY:h=>Mn(h,"number",null)})]})}function T9({component:e,data:n}){const s=wn(e.query,n);return t.jsxs(Zs,{title:e.title,note:e.note,children:[t.jsx(re,{message:s.error}),s.data===void 0?t.jsx(Ee,{children:e.empty??"Loading…"}):t.jsx(hp,{children:e.items.map((r,a)=>t.jsx(Zr,{label:r.label,value:t.jsx(ea,{text:Mn(Be(s.data,r.value),r.unit??"text",null)}),tone:f9(r.tone)},a))})]})}function rM(e,n,s,r){const a=(n.meta??[]).map(b=>String(Be(s,b)??"")).filter(b=>b!==""),i=String(Be(s,n.title)??""),l=n.to&&!r?za(e,n.to,s):null,o=l===""?null:l,c=o!==null&&n.to!==void 0&&"href"in n.to,u=n.images?t.jsx(m9,{plugin:e.plugin,images:n.images,row:s}):null,m=[...n.pill?[n.pill]:[],...n.pills??[]].map((b,S)=>{const C=Be(s,b.value);if(C==null||C==="")return null;const A=R9(b,C,s);return t.jsx($e,{tone:kv(A.tone),children:A.text},S)}),f=o&&c?t.jsx(Oo,{href:o,children:i}):o?t.jsx("a",{href:o,onClick:b=>{b.preventDefault(),e.navigate(o)},children:i}):i,p=n.tag?Be(s,n.tag):void 0,x=p==null||p===""?null:t.jsx("span",{className:"pl-row-tag",children:String(p)}),g=n.status?Be(s,n.status.text):void 0,w=n.status?Zf(n.status.tone,s):void 0,v=g==null||g===""?null:t.jsx("span",{className:"pl-row-status","data-tone":w,children:String(g)}),j=n.sub?String(Be(s,n.sub)??""):"",y=n.swatch?Re(s,n.swatch):void 0,k=n.logo?t.jsx(Cl,{className:"pl-logo-lg",src:Sl(e.plugin,Be(s,n.logo.asset)),label:String(Be(s,n.logo.label)??"")}):n.swatch?typeof y=="string"&&Jb.test(y)?t.jsx("span",{className:"pl-swatch","aria-hidden":"true",style:{"--swatch":y}}):t.jsx("span",{className:"pl-swatch","data-none":"true","aria-hidden":"true"}):null,N=n.preview?String(Be(s,n.preview)??""):"";return{text:i,href:o,outside:c,lead:k,preview:N,strong:n.strong?Kt(s,n.strong):void 0,pills:t.jsx(t.Fragment,{children:m}),meta:a.length>0?t.jsx(ea,{text:a.join(" · ")}):"",title:u?t.jsxs(t.Fragment,{children:[u,t.jsx("span",{className:"pl-row-title",children:f}),x]}):x?t.jsxs(t.Fragment,{children:[f,x]}):f,sub:v?t.jsxs(t.Fragment,{children:[j?t.jsx("span",{className:"pl-row-line",children:t.jsx(ea,{text:j})}):null,v]}):n.sub?j&&t.jsx(ea,{text:j}):null,side:t.jsxs(t.Fragment,{children:[m,a.length>0?t.jsxs("span",{className:"muted",children:[" ",t.jsx(ea,{text:a.join(" · ")})]}):null]})}}function R9(e,n,s){const r=String(n),a=e.labels??{},i=e.tones??{};return{text:Object.prototype.hasOwnProperty.call(a,r)?a[r]:r,tone:Object.prototype.hasOwnProperty.call(i,r)?i[r]:Zf(e.tone,s)}}function Fr(e,n){const s=Re(e,n);return Array.isArray(s)?s:[]}function aM(e,n,s){const r=[],a=new Set;return e.forEach((i,l)=>{const o=n===void 0?void 0:Re(i,n),c=o==null||o===""?null:String(o);if(c===null){console.warn(`buddi: plugin ${s.plugin}, page ${s.page}, ${s.component}: row ${l} has no value at "${n??"(no key)"}" — not drawn`);return}if(a.has(c)){console.warn(`buddi: plugin ${s.plugin}, page ${s.page}, ${s.component}: two rows share the key "${c}" — the second is not drawn`);return}a.add(c),r.push({key:c,row:i})}),r}function I9(e){var i;if(!["ArrowDown","ArrowUp","Home","End"].includes(e.key)||e.altKey||e.ctrlKey||e.metaKey)return;const n=Array.from(e.currentTarget.querySelectorAll("a.ui-pick"));if(n.length===0)return;const s=n.findIndex(l=>l===document.activeElement),r=s>=0?s:n.findIndex(l=>l.getAttribute("aria-current")==="true"),a=e.key==="Home"?0:e.key==="End"?n.length-1:e.key==="ArrowDown"?Math.min(n.length-1,r+1):Math.max(0,r<0?0:r-1);e.preventDefault(),(i=n[a])==null||i.focus()}function P9({component:e,data:n,onChoose:s,chosen:r}){var b;const a=jt(),i=d.useContext(nM),l=wn(e.query,n),o=ha(),[c,u]=d.useState([]),h=i&&!e.select&&(e.actions??[]).length===0&&(e.bulk??[]).length===0,m=Fr(l.data,e.rows),f=e.collapsed?Fr(l.data,e.collapsed.rows):[],p=iM(e.actions,m,o),x={plugin:a.plugin,page:a.page,component:`list "${e.title??e.rows}"`},g=aM([...m,...f],e.key??((b=e.select)==null?void 0:b.key),x),w=new Map(g.map(S=>[S.row,S.key])),v=new Set(g.map(S=>S.row)),j=new Set(g.filter(({row:S})=>{var C;return((C=e.select)==null?void 0:C.disabledWhen)===void 0||!Kt(S,e.select.disabledWhen)}).map(({key:S})=>S)),y=c.filter(S=>j.has(S)),k=d.useMemo(()=>{const S=m.filter(E=>v.has(E));if(!e.groupBy)return[{label:null,aside:null,asideTone:void 0,rows:S}];const C=new Map;for(const E of S){const R=String(Re(E,e.groupBy.key)??"");C.set(R,[...C.get(R)??[],E])}const A=(E,R)=>{var I,F,U;const P=(F=(I=e.groupBy)==null?void 0:I.labels)==null?void 0:F[E];if(P!==void 0)return P;const O=(U=e.groupBy)!=null&&U.label?Re(R,e.groupBy.label):void 0;return O==null||O===""?E:String(O)};return[...C].map(([E,R])=>{var I,F;const P=(I=e.groupBy)!=null&&I.aside?Re(R[0],e.groupBy.aside):void 0,O=(F=e.groupBy)!=null&&F.asideTone?Re(R[0],e.groupBy.asideTone):void 0;return{label:A(E,R[0]),aside:P==null||P===""?null:String(P),asideTone:O==="warning"||O==="critical"?O:void 0,rows:R}})},[m,e.groupBy,g.length]),N=S=>S.map(C=>{var F;const A=rM(a,e.item,C,s),E=w.get(C);if(h&&(s||A.href&&!A.outside))return t.jsx(ZI,{href:A.href??"#",current:r===E,onClick:()=>s?s(E):a.navigate(A.href),title:A.text,meta:A.meta,sub:A.sub,side:A.pills,snippet:A.preview||void 0,strong:A.strong},E);const R=((F=e.select)==null?void 0:F.disabledWhen)!==void 0&&Kt(C,e.select.disabledWhen),P=(e.actions??[]).filter(U=>Kt(C,U.when)),O=P.filter(U=>U.menu!==!0),I=P.filter(U=>U.menu===!0);return t.jsx(pt,{lead:A.lead?A.lead:e.select?t.jsx("input",{type:"checkbox","aria-label":`Select ${A.text}`,disabled:R,checked:c.includes(E),onClick:U=>U.stopPropagation(),onChange:U=>u(L=>U.target.checked?[...L,E]:L.filter(M=>M!==E))}):void 0,title:s?t.jsx("a",{href:"#","aria-current":r===E?"true":void 0,onClick:U=>{U.preventDefault(),s(E)},children:A.text}):A.title,sub:A.preview?t.jsxs(t.Fragment,{children:[A.sub?t.jsx("span",{className:"pl-row-line",children:A.sub}):null,t.jsx("span",{className:"pl-row-preview",children:A.preview})]}):A.sub,side:t.jsxs(t.Fragment,{children:[A.side,e.item.choice?t.jsx(O9,{choice:e.item.choice,row:C,data:l.data,act:o}):null,O.map((U,L)=>t.jsx(Qb,{action:U,row:C,data:l.data,act:o,onForm:p.show},L)),I.length>0?t.jsx(lM,{actions:I,row:C,title:A.text,data:l.data,act:o,onForm:p.show}):null]})},E)});return t.jsxs(Zs,{title:e.title,note:e.note,children:[t.jsx(re,{message:l.error}),p.open?null:t.jsx(Lr,{act:o}),p.open?t.jsx(oM,{open:p.open,data:l.data,rows:m,act:o,onClose:p.close,onDone:p.finish}):null,k.every(S=>S.rows.length===0)?l.loading?t.jsx(Ee,{children:"Loading…"}):t.jsx(Al,{text:e.empty??"Nothing here yet."}):t.jsxs(yt,{children:[e.select?t.jsx(pt,{lead:t.jsx("input",{type:"checkbox","aria-label":"Select every row",checked:j.size>0&&y.length===j.size,disabled:j.size===0,onChange:S=>u(S.target.checked?[...j]:[])}),title:t.jsxs("span",{className:"muted",children:[j.size," to choose from"]})}):null,k.map((S,C)=>{var A,E;return(A=e.groupBy)!=null&&A.actions||(E=e.groupBy)!=null&&E.asideTone?t.jsxs("section",{className:"pl-group","aria-label":S.label??void 0,children:[t.jsxs("header",{className:"pl-group-head",children:[t.jsx("span",{className:"pl-group-title",children:S.label}),S.aside?t.jsx("span",{className:"pl-group-aside","data-tone":S.asideTone,children:S.aside}):null,t.jsx(M9,{actions:e.groupBy.actions??[],row:S.rows[0],title:S.label??"",data:l.data,act:o,onForm:p.show})]}),N(S.rows)]},C):t.jsxs("div",{children:[S.label?t.jsxs("div",{className:"ui-list-group","data-aside":S.aside?"true":void 0,children:[S.label,S.aside?t.jsx("span",{className:"pl-group-aside",children:S.aside}):null]}):null,N(S.rows)]},C)})]}),e.collapsed&&f.some(S=>v.has(S))?t.jsx(Vt,{summary:`${e.collapsed.label} (${f.filter(S=>v.has(S)).length})`,children:t.jsx(yt,{children:N(f.filter(S=>v.has(S)))})}):null,e.bulk&&e.bulk.length>0?t.jsxs(te,{align:"end",children:[t.jsxs("span",{className:"ui-toolbar-note",children:[y.length," selected"]}),e.bulk.map((S,C)=>{const A=y.length>0||S.all!==!0?y:[...j];return t.jsx(Pi,{action:S,args:Xs(S.args,{data:l.data,selected:A,scope:a}),count:A.length,disabled:o.busy||A.length===0,running:o.running===S.tool,onRun:(E,R)=>{u([]),o.run(E,R)}},C)})]}):null]})}function M9({actions:e,row:n,title:s,data:r,act:a,onForm:i}){const l=e.filter(u=>Kt(n,u.when));if(l.length===0)return null;const o=l.filter(u=>u.menu!==!0),c=l.filter(u=>u.menu===!0);return t.jsxs("span",{className:"pl-group-act",children:[o.map((u,h)=>t.jsx(Qb,{action:u,row:n,data:r,act:a,onForm:i},h)),c.length>0?t.jsx(lM,{actions:c,row:n,title:s,data:r,act:a,onForm:i}):null]})}function O9({choice:e,row:n,data:s,act:r}){const a=jt(),i=String(Re(n,e.value)??""),[l,o]=d.useState(null);d.useEffect(()=>o(null),[i]);const c=l??i,u=e.options.filter(h=>Kt(n,h.when));return t.jsx("span",{className:"ui-segment pl-choice",role:"radiogroup","aria-label":Ns(e.label,{row:n}),"aria-busy":l!==null&&r.running===e.tool?"true":void 0,children:u.map(h=>{const m=h.disabledWhen!==void 0&&Kt(n,h.disabledWhen),f=m&&h.hint?Ns(h.hint,{row:n}):void 0;return t.jsx("button",{type:"button",role:"radio",className:"ui-tab","aria-checked":c===h.value,disabled:m||r.busy,title:f,"aria-description":f,onClick:()=>{if(h.value===c)return;o(h.value);const p=Xs(e.args,{data:s,row:n,choice:h.value,scope:a});r.run(e,p).then(x=>{x||o(null)})},children:h.label},h.value)})})}function D9(e,n,s){return Object.entries(e).every(([r,a])=>{const i=typeof a=="string"?a:Re(s,a.row);return i!=null&&n[r]===String(i)})}function iM(e,n,s){const r=jt(),[a,i]=d.useState(null);return d.useEffect(()=>{var l;if(!(a!==null||n.length===0))for(const o of e??[]){const c=(l=o.form)==null?void 0:l.openWhen;if(!c)continue;const u=n.find(h=>Kt(h,o.when)&&D9(c,r.params,h));if(u!==void 0){i({action:o,row:u}),r.setParams(Object.fromEntries(Object.keys(c).map(h=>[h,null])));return}}},[n.length,JSON.stringify(r.params)]),{open:a,show:(l,o)=>{s.reset(),i({action:l,row:o})},close:()=>{s.reset(),i(null)},finish:()=>i(null)}}function Qb({action:e,row:n,data:s,act:r,onForm:a}){const i=jt();return e.form?t.jsx($,{disabled:r.busy,onClick:()=>a(e,n),children:Ns(e.label,{row:n})}):t.jsx(Pi,{action:e,args:Xs(e.args,{data:s,row:n,scope:i}),disabled:r.busy,running:r.running===e.tool,row:n,onRun:(l,o)=>void r.run(l,o)})}function lM({actions:e,row:n,title:s,data:r,act:a,onForm:i}){const l=jt(),[o,c]=d.useState(null),u=f=>void a.run(f,Xs(f.args,{data:r,row:n,scope:l})),h=[];let m;return e.forEach((f,p)=>{f.group!==m?(p>0&&h.push("separator"),f.group&&h.push({heading:f.group}),m=f.group):f.tone==="danger"&&p>0&&h.push("separator"),h.push({label:Ns(f.label,{row:n}),...f.hint?{hint:Ns(f.hint,{row:n})}:{},...f.tone==="danger"?{tone:"critical"}:{},onSelect:()=>f.form?i(f,n):f.confirm?c(f):u(f)})}),t.jsxs(t.Fragment,{children:[t.jsx(rs,{label:`More for ${s}`,items:h,sheet:{title:s}}),o?t.jsx(Gt,{title:Ns(o.confirm??o.label,{row:n}),onClose:()=>c(null),foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:()=>c(null),children:"Cancel"}),t.jsx($,{variant:o.tone==="danger"?"danger":"accent",onClick:()=>{const f=o;c(null),u(f)},children:Ns(o.label,{row:n})})]})}):null]})}function L9(e,n){const s=hi(e),r=n.find(i=>hi(i)===s);if(r!==void 0)return r;const a=JSON.stringify(s);return n.find(i=>JSON.stringify(hi(i))===a)??e}function oM({open:e,data:n,rows:s,act:r,onClose:a,onDone:i}){const l=jt(),{action:o}=e,c=L9(e.row,s),u=o.form,[h,m]=qb(u.fields,c),f=u.fields.some(v=>v.from!==void 0&&jp(Re(c,v.from))),p=u.fields.some(v=>v.required&&(h[v.name]===""||h[v.name]===void 0)),{confirm:x,...g}=o,w={...g,label:u.submit};return t.jsx(Ye,{title:Ns(u.title,{row:c}),onClose:a,foot:t.jsxs(te,{align:"end",children:[t.jsx($,{variant:"ghost",onClick:a,children:"Cancel"}),t.jsx(Pi,{action:w,args:Xs(o.args,{data:n,row:c,fields:h,shape:u.fields,scope:l}),disabled:r.busy||p||f,running:r.running===o.tool,row:c,onRun:(v,j)=>void r.run(v,j,i)})]}),children:t.jsxs(ue,{children:[t.jsx(bp,{fields:u.fields,values:h,data:c,onChange:m}),f?t.jsx("p",{className:"muted",children:"Show amounts to change this."}):null,t.jsx(re,{message:r.error})]})})}function F9({component:e,data:n}){const s=wn(e.query,n),r=ha(),a=Fr(s.data,e.rows),i=iM(e.actions,a,r);return t.jsxs(Zs,{title:e.title,note:e.note,children:[t.jsx(re,{message:s.error}),i.open?null:t.jsx(Lr,{act:r}),i.open?t.jsx(oM,{open:i.open,data:s.data,rows:a,act:r,onClose:i.close,onDone:i.finish}):null,a.length===0?s.loading?t.jsx(Ee,{children:"Loading…"}):t.jsx(Al,{text:e.empty??"Nothing here yet."}):t.jsxs(da,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[e.columns.map(l=>t.jsx("th",{children:l.label},l.key)),e.actions&&e.actions.length>0?t.jsx("th",{"aria-label":"Actions"}):null]})}),t.jsx("tbody",{children:a.map((l,o)=>t.jsxs("tr",{children:[e.columns.map(c=>{const u=c.pill?null:Mn(Re(l,c.key),c.type??"text",null);return t.jsxs("td",{"data-fit":c.fit,title:z9(c,l,u),children:[c.pill?null:t.jsx(_9,{column:c,row:l}),c.pill?t.jsx(U9,{column:c,row:l}):c.fit==="truncate"?t.jsx("span",{className:"ui-table-cut",children:t.jsx(ea,{text:u})}):t.jsx(ea,{text:u})]},c.key)}),e.actions&&e.actions.length>0?t.jsx("td",{children:t.jsx(te,{align:"end",children:e.actions.filter(c=>Kt(l,c.when)).map((c,u)=>t.jsx(Qb,{action:c,row:l,data:s.data,act:r,onForm:i.show},u))})}):null]},o))})]})]})}const Jb=/^#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i;function _9({column:e,row:n}){if(!e.swatch)return null;const s=Re(n,e.swatch);return typeof s!="string"||!Jb.test(s)?null:t.jsx("span",{className:"ui-table-swatch","aria-hidden":"true",style:{"--swatch":s}})}function z9(e,n,s){if(e.hint){const r=Re(n,e.hint);if(r!=null&&r!=="")return String(r)}return e.fit==="truncate"&&s?s:void 0}function U9({column:e,row:n}){var l,o;const s=Re(n,e.key);if(Array.isArray(s))return t.jsx(t.Fragment,{children:s.map((c,u)=>{var g;const h=c,m=typeof h=="object"&&h!==null?h.value:c;if(m==null||m==="")return null;const f=typeof h=="object"&&h!==null?h.tone:void 0,p=(g=e.pill)==null?void 0:g.labels,x=p&&Object.prototype.hasOwnProperty.call(p,String(m))?p[String(m)]:Mn(m,e.type??"text",null);return t.jsx($e,{tone:kv(Zf(typeof f=="string"?f:void 0,n)),children:x},u)})});const r=(l=e.pill)==null?void 0:l.labels,a=String(s),i=r&&Object.prototype.hasOwnProperty.call(r,a)?r[a]:Mn(s,e.type??"text",null);return t.jsx($e,{tone:kv(Zf((o=e.pill)==null?void 0:o.tone,n)),children:i})}function B9({component:e,data:n}){const s=wn(e.query,n);return s.error?t.jsx(re,{message:s.error}):s.data===void 0?t.jsx(Ee,{children:e.empty??"Loading…"}):t.jsx(Zs,{title:e.title,note:e.note,children:t.jsxs(ue,{gap:"lg",children:[e.fields.length>0?t.jsx(on,{items:e.fields.map(r=>({key:r.label,label:r.label,value:t.jsx(ea,{text:Mn(Be(s.data,r.value),r.unit??"text",null)})}))}):null,e.body.map((r,a)=>t.jsx(Ws,{component:r,data:s.data},a))]})})}function W9({component:e,data:n}){var m;const s=jt(),r=wn(e.initial,n),a=ha(),[i,l]=d.useState(!1),o=((m=e.drawer)==null?void 0:m.id)!==void 0&&s.params.open===e.drawer.id,c=i||o,u=f=>{l(f),!f&&o&&s.setParams({open:null})},h=t.jsx(H9,{component:e,data:n,initialData:r.data,act:a,onDone:()=>u(!1)},a.happened);return e.drawer?e.drawer.button===void 0&&!e.title?t.jsxs(t.Fragment,{children:[t.jsx(Lr,{act:a}),c?t.jsx(Ye,{title:e.drawer.title,onClose:()=>u(!1),children:h}):null]}):t.jsxs(ye,{title:e.title,aside:e.note,actions:e.drawer.button!==void 0?t.jsx($,{variant:"accent",onClick:()=>u(!0),children:e.drawer.button}):void 0,children:[t.jsx(Lr,{act:a}),c?t.jsx(Ye,{title:e.drawer.title,onClose:()=>u(!1),children:h}):null]}):t.jsxs(Zs,{title:e.title,note:e.note,children:[t.jsx(re,{message:r.error}),h]})}function H9({component:e,data:n,initialData:s,act:r,onDone:a}){const i=d.useContext(tM),l=jt(),[o,c]=qb(e.fields,s),u=Yb(e.fields,o,s),h=e.fields.some(f=>f.from!==void 0&&jp(Re(s,f.from))),m=e.fields.some(f=>f.required&&!u.has(f.name)&&(o[f.name]===""||o[f.name]===void 0||Array.isArray(o[f.name])&&o[f.name].length===0));return t.jsxs(ue,{children:[t.jsx(bp,{fields:e.fields,columns:e.columns,values:o,data:s,onChange:c}),e.drawer?null:t.jsx(Lr,{act:r}),h?t.jsx("p",{className:"muted",children:"Show amounts to change this."}):null,t.jsx(te,{align:"end",className:i?"ui-panel-foot":void 0,children:t.jsx(Pi,{action:e.submit,args:Xs(e.submit.args,{data:n,fields:o,shape:e.fields,omit:u,scope:l}),disabled:r.busy||m||h,running:r.running===e.submit.tool,onRun:(f,p)=>void r.run(f,p,a)})})]})}function K9(e,n){var r;if(e.type==="checkbox")return e.label;const s=(r=e.options)==null?void 0:r.find(a=>a.value===n);return`${e.label}: ${s?s.label:n}`}function jC(e){return e!=null&&e!==""&&e!==!1&&e!=="false"}function V9({component:e,data:n}){const s=jt(),[r,a]=d.useState(()=>Nv(e.fields,n)),[i,l]=d.useState(e.auto===!0),[o,c]=d.useState(!1),u=e.fields.every(C=>!C.required||String(r[C.name]??"")!==""),h=wn(i&&u?e.query:void 0,n),m=Fr(h.data,e.rows),f=e.count===void 0?void 0:Re(h.data,e.count),p=e.note===void 0?void 0:Re(h.data,e.note),x=e.fields.find(C=>C.type==="text"||C.type==="email")??null,g=e.fields.filter(C=>C!==x),w=C=>{s.setParams(Object.fromEntries(e.fields.map(A=>[A.name,String(C[A.name]??"")||null]))),l(!0)},v=(C,A)=>{const E={...r,[C]:A};a(E),e.auto&&w(E)},j=()=>{const C=Nv(e.fields,null);a(C),e.auto?w(C):(s.setParams(Object.fromEntries(e.fields.map(A=>[A.name,null]))),l(!1))},y=i?g.filter(C=>jC(s.params[C.name])):[],k=x?y.map(C=>t.jsx(Hf,{label:C.label,onRemove:()=>{const A={...r,[C.name]:C.type==="checkbox"?!1:""};a(A),w(A)},children:K9(C,String(s.params[C.name]))},C.name)):[],N=g.filter(C=>jC(r[C.name])).length,b=e.auto&&!e.reset?null:t.jsxs(t.Fragment,{children:[e.reset?t.jsx($,{variant:"ghost",onClick:j,children:"Clear"}):null,e.auto?null:t.jsx($,{type:"submit",variant:"accent",disabled:!u,children:"Search"})]}),S=e.results.to?e.results:e.to?{...e.results,to:e.to}:e.results;return t.jsx(Zs,{title:e.title,children:t.jsxs(ue,{children:[t.jsx(nP,{label:e.title??"Search",onSubmit:()=>{!e.auto&&u&&w(r)},main:x?t.jsx("input",{id:`f-${x.name}`,name:x.name,type:x.type==="email"?"email":"search","aria-label":x.label,placeholder:x.hint??x.label,title:x.hint,required:x.required,value:String(r[x.name]??""),onChange:C=>v(x.name,C.target.value)}):void 0,filters:g.length>0?t.jsx(bp,{fields:g,values:r,data:n,compact:!0,onChange:v}):void 0,...x&&g.length>0?{filtersOpen:o,onToggleFilters:()=>c(C=>!C),active:N}:{},chips:k.length>0?k:void 0,actions:b}),t.jsx(re,{message:h.error}),i&&(f!==void 0||p!==void 0)?t.jsxs("p",{className:"ui-card-meta",children:[f===void 0?"":`${Mn(f,"number",null)} in all. `,p===void 0?"":String(p)]}):null,i?m.length===0?t.jsx(Ee,{children:h.loading?"Searching…":e.empty??"Nothing matches."}):t.jsx("div",{className:"ui-panel","data-flush":"true",children:t.jsx(yt,{children:m.map((C,A)=>{const E=rM(s,S,C);return t.jsx(pt,{title:E.title,sub:E.sub,side:E.side},A)})})}):null]})})}function G9({component:e,data:n}){const s=jt(),r=e.selection==="local",[a,i]=d.useState(null),l=r?a:s.params[e.param]??s.item,o=r&&a!==null?{...s,params:{...s.params,[e.param]:a}}:null,c=t.jsx(ue,{gap:"lg",divided:!0,children:e.detail.map((u,h)=>t.jsx(Ws,{component:u,data:n},h))},l??"");return t.jsx(pl.Provider,{value:!1,children:t.jsx(eP,{list:t.jsx(nM.Provider,{value:!0,children:t.jsx("div",{className:"pl-picks",onKeyDown:I9,children:t.jsx(Ws,{component:e.list,data:n,chosen:l??null,...r?{choose:i}:{}})})}),detail:l?o?t.jsx(wp.Provider,{value:o,children:c}):c:void 0,empty:e.empty??"Choose one to see it here."})})}function q9({component:e,data:n}){var j;const s=jt(),r=d.useContext(pl),a=e.body.length>0&&e.body.every(y=>y.kind==="section"),[i,l]=d.useState(!1),o=wn(e.query,n,i&&e.poll?e.poll.seconds*1e3:void 0),c=e.poll!==void 0&&o.data!==void 0&&Kt(o.data,e.poll.while);d.useEffect(()=>l(c),[c]);const u=Fr(o.data,e.rows),h=(j=e.poll)==null?void 0:j.finish,m=ha(),[f,p]=d.useState(()=>new Set),x=h?u.find(y=>{if(!Kt(y,h.when))return!1;const k=String(Re(y,e.key)??"");return k!==""&&!f.has(k)}):void 0,g=x===void 0?null:String(Re(x,e.key)??"");d.useEffect(()=>{!h||x===void 0||g===null||g===""||f.has(g)||m.busy||(p(y=>new Set([...y,g])),m.run(h.action,Xs(h.action.args,{data:x,row:x,scope:s})))},[g,m.busy]);const w=u.some(y=>e.body.some(k=>k.kind==="section"&&k.look==="setup"&&(!k.when||Kt(y,k.when)))),v=h!==void 0&&m.running===h.action.tool;return t.jsxs(Zs,{title:e.title,note:e.note,plain:w||a,children:[t.jsx(re,{message:o.error}),v?t.jsxs("p",{className:"pl-wait",role:"status",children:[t.jsx("span",{className:"pl-spin","aria-hidden":"true"}),h.action.busy??h.action.label]}):t.jsx(Lr,{act:m}),v?null:u.length===0?o.loading?t.jsx(Ee,{children:"Loading…"}):t.jsx(Al,{text:e.empty??"Nothing here yet."}):t.jsx(ue,{gap:"lg",divided:!0,children:aM(u,e.key,{plugin:s.plugin,page:s.page,component:`repeat "${e.title??e.rows}"`}).map(({key:y,row:k})=>t.jsx(ye,{children:t.jsx(ue,{children:t.jsx(pl.Provider,{value:a&&r,children:e.body.map((N,b)=>t.jsx(Ws,{component:N,data:k},b))})})},y))})]})}function Y9({component:e,data:n}){const s=jt(),r=ZK({...e.views?{views:e.views}:{},...e.default?{default:e.default}:{},today:FK(s.timezone),storageKey:`buddi.calendar-view:${s.plugin}/${s.page}`}),a=wn(e.query,n,void 0,{from:r.from,to:r.to}),i=d.useMemo(()=>BK(Fr(a.data,e.events),e.map,s.timezone,`plugin ${s.plugin}, page ${s.page}, calendar`),[a.data,e.events,e.map,s.timezone,s.plugin,s.page]),[l,o]=d.useState(null),c=e.sheet&&l!==null?i.find(u=>u.id===l)??null:null;return t.jsxs(Zs,{title:e.title,note:e.note,children:[t.jsx(re,{message:a.error}),t.jsx(e9,{state:r,events:i,hours:e.hours,empty:e.empty??"Nothing.",label:e.title??"Calendar",onEvent:e.sheet?u=>o(u.id):void 0,count:e.count&&a.data!==void 0?i.length:void 0}),c&&e.sheet?t.jsx(Q9,{event:c,sheet:e.sheet,onClose:()=>o(null)}):null]})}function Q9({event:e,sheet:n,onClose:s}){const r=jt(),a=e.row,i=p=>{if(p===void 0)return"";const x=Re(a,p);return x==null?"":String(x)},l=VK(e),o=i(n.color),c=i(n.notes),u=Xf(i(n.mapHref)),h=n.open?Xf(i(n.open.href)):null,m=n.open?i(n.open.label):"",f=p=>{const x=Ns(p.replace(/\{when\}/g,l),{row:{...a,title:e.title,calendar:e.calendar,location:e.location}});s(),GK(x)||r.navigate(Aa)};return t.jsx(Ye,{title:e.title,onClose:s,foot:n.asks&&n.asks.length>0?t.jsx(te,{align:"end",children:n.asks.map((p,x)=>t.jsx($,{onClick:()=>f(p.text),children:p.label},x))}):void 0,children:t.jsxs("div",{className:"pl-event-sheet",children:[t.jsx("p",{className:"pl-event-when",children:l}),e.calendar?t.jsxs("p",{className:"pl-event-cal",children:[o&&Jb.test(o)?t.jsx("span",{className:"pl-swatch","aria-hidden":"true",style:{"--swatch":o}}):t.jsx("span",{className:"cal-dot","data-tone":e.tone,"aria-hidden":"true"}),e.calendar]}):null,e.location?t.jsxs("p",{className:"pl-event-where",children:[t.jsx(ne,{name:"pin",size:14}),u?t.jsx(Oo,{href:u,children:e.location}):t.jsx("span",{children:e.location})]}):null,c?t.jsx("p",{className:"pl-event-notes",children:c}):null,h&&m?t.jsx("p",{className:"pl-event-open",children:t.jsx(Oo,{href:h,className:"wb-src-link",children:m})}):null]})})}function J9({component:e,data:n}){var m;const s=jt(),r=wn(e.query,n),a={items:"$",icon:e.icon,value:e.value,label:e.label,...e.lines?{lines:e.lines}:{},...e.tone?{tone:e.tone}:{}},i=Fr(r.data,e.items).flatMap(f=>{const p=$b([f],a).tiles[0];return p?[{tile:p,key:e.select?String(Re(f,e.select.key)??""):""}]:[]}),l=e.select,o=l?Math.max(0,i.findIndex(f=>f.key===s.params[l.param])):null,c=((m=i[0])==null?void 0:m.key)??"",u=l?s.params[l.param]:void 0,h=i.some(f=>f.key===u);return d.useEffect(()=>{l&&c!==""&&!h&&s.setParams({[l.param]:c})},[l==null?void 0:l.param,c,h]),t.jsxs(Zs,{title:e.title,note:e.note,children:[t.jsx(re,{message:r.error}),r.data===void 0?t.jsx(Ee,{children:"Loading…"}):i.length===0?t.jsx(Al,{text:e.empty??"Nothing to show."}):t.jsx(SP,{props:{tiles:i.map(f=>f.tile),notice:!1,empty:""},...e.layout?{layout:e.layout}:{},...l?{selected:o,onPick:f=>{var p;return s.setParams({[l.param]:((p=i[f])==null?void 0:p.key)||null})}}:{}})]})}function X9({component:e,data:n}){const s=wn(e.query,n),r=Fr(s.data,e.points);if(s.data===void 0||r.length===0)return t.jsxs(Zs,{title:e.title,note:e.note,children:[t.jsx(re,{message:s.error}),s.data===void 0?t.jsx(Ee,{children:"Loading…"}):t.jsx(Al,{text:e.empty??"Nothing to show."})]});const a=r.map(c=>String(Re(c,e.x)??"")),i={items:"$",icon:e.tiles.icon,value:e.tiles.value,label:e.tiles.label,...e.tiles.lines?{lines:e.tiles.lines}:{}},l=r.map((c,u)=>$b([c],i).tiles[0]??{icon:null,value:"",label:a[u]??"",lines:[],tone:"neutral",link:null}),o=e.series.map(c=>({id:c.id,label:c.label,kind:c.kind,...c.unit?{unit:c.unit}:{},values:r.map(u=>Us(Re(u,c.y))??null)}));return t.jsxs(t.Fragment,{children:[t.jsx(re,{message:s.error}),t.jsx(l9,{...e.title?{title:e.title}:{},...e.note?{note:e.note}:{},...e.labelEvery?{labelEvery:e.labelEvery}:{},xs:a,series:o,tiles:l})]})}function Z9({component:e,data:n}){const s=wn(e.query,n),r=o=>{const c=Re(s.data,o);return c==null?"":String(c)};if(s.data===void 0||s.data===null)return t.jsxs(t.Fragment,{children:[t.jsx(re,{message:s.error}),t.jsx(Ee,{children:s.loading?"Loading…":e.empty??"Nothing to show."})]});const a=r(e.value),i=r(e.title),l=e.facts.map(o=>({label:o.label,value:r(o.path)})).filter(o=>o.value!=="");return t.jsxs("section",{className:"pg-hero","aria-label":[a,i,...l.map(o=>`${o.label} ${o.value}`)].filter(Boolean).join(", ").split(yi).join("hidden"),children:[t.jsxs("div",{className:"pg-hero-main","aria-hidden":"true",children:[t.jsx("span",{className:"pg-hero-icon",children:t.jsx(ne,{name:oc(pv(Be(s.data,e.icon))),size:44})}),t.jsx("span",{className:"pg-hero-value",children:a}),i?t.jsx("span",{className:"pg-hero-title",children:i}):null]}),l.length>0?t.jsx("dl",{className:"pg-hero-facts","aria-hidden":"true",children:l.map(o=>t.jsxs("div",{className:"pg-hero-fact",children:[t.jsx("dt",{children:o.label}),t.jsx("dd",{children:o.value})]},o.label))}):null]})}function eV({component:e,data:n}){var x;const s=jt(),[r,a]=d.useState(e.default??e.tabs[0].id),i=e.param,l=i?s.params[i]??e.default??e.tabs[0].id:r,o=g=>i?s.setParams({[i]:g}):a(g),c=e.pick,{options:u}=ZP({name:(c==null?void 0:c.param)??"",label:(c==null?void 0:c.label)??"",...c!=null&&c.options?{options:c.options}:{},...c!=null&&c.optionsFrom?{optionsFrom:c.optionsFrom}:{}},{},n),h=c?u.some(g=>g.value===s.params[c.param])?s.params[c.param]:((x=u[0])==null?void 0:x.value)??"":"",m=e.tabs.find(g=>g.id===l)??e.tabs[0],f=(c==null?void 0:c.look)==="chips",p=c!=null&&c.add?za(s,c.add.to,n):"";return t.jsxs("div",{className:"pg-tabs",children:[t.jsxs("div",{className:"pg-tabs-bar","data-only":e.tabs.length===1?"pick":void 0,"data-chips":f?"true":void 0,children:[c&&f&&u.length>0?t.jsxs("div",{className:"pl-chips",role:"group","aria-label":c.label,children:[u.map(g=>t.jsx($,{size:"sm","aria-pressed":g.value===h,onClick:()=>s.setParams({[c.param]:g.value}),children:g.label},g.value)),c.add&&p!==""?t.jsxs(it,{size:"sm",variant:"ghost",href:p,onClick:g=>{g.preventDefault(),s.navigate(p)},children:[t.jsx(ne,{name:"plus",size:12}),c.add.label]}):null]}):c&&u.length>1?t.jsx(cn,{label:c.label,options:u,value:h,onChange:g=>s.setParams({[c.param]:g})}):null,e.tabs.length>1?t.jsx("span",{className:"pg-tabs-switch",children:t.jsx(cn,{label:e.title??"View",options:e.tabs.map(g=>({value:g.id,label:g.label})),value:m.id,onChange:o})}):null]}),m.body.map((g,w)=>t.jsx(Ws,{component:g,data:n},`${m.id}-${w}`))]})}function tV({component:e,data:n}){const[s,r]=d.useState(!1),a=wn(s?e.query:void 0,n),i=e.query?a.data:n,l=typeof e.label=="string"?e.label:String(Be(n,e.label)??"");return t.jsxs(Vt,{summary:l,boxed:!0,onToggle:o=>r(o),children:[t.jsx(re,{message:a.error}),s?e.query&&a.data===void 0?t.jsx(Ee,{children:"Loading…"}):t.jsx(ue,{children:e.body.map((o,c)=>t.jsx(Ws,{component:o,data:i},c))}):null]})}function cM({component:e,data:n}){const s=jt(),r=ha();return t.jsxs(t.Fragment,{children:[t.jsx(te,{align:"end",children:t.jsx(Pi,{action:e.action,args:Xs(e.action.args,{data:n,row:n,scope:s}),disabled:r.busy,running:r.running===e.action.tool,row:n,onRun:(a,i)=>void r.run(a,i)})}),t.jsx(Lr,{act:r})]})}function nV({component:e}){const n=jt();return t.jsx(Db,{plugin:n.plugin,agent:e.agent,text:e.text,label:e.label})}function sV(e){if(!e||typeof e!="object")return null;const n=e;return typeof n.id!="string"||n.id===""||typeof n.title!="string"?null:{...n,outlets:Array.isArray(n.outlets)?n.outlets.filter(s=>s&&typeof s.name=="string"):[]}}function Ev(e){return e.length===0?"":e.length===1?e[0].name:`${e[0].name} and ${e.length-1} more`}function vC(e,n,s){const r={};for(const[a,i]of Object.entries(e))"row"in i?r[a]=Re(n,i.row):"item"in i?r[a]=Re(s,i.item):r[a]=Be(n,i);return r}const rV=8e3;function yC(e,n,s){const r=[];let a=null;return e.forEach((i,l)=>{if(!Kt(n,i.when))return;const o=i.each?Array.isArray(Re(n,i.each))?Re(n,i.each).slice(0,4):[]:[void 0];if(o.length!==0){l>0&&r.length>0&&i.group!==a&&r.push("separator"),i.group&&i.group!==a&&r.push({heading:i.group}),a=i.group;for(const c of o)r.push({label:Ns(i.label,{row:c===void 0?n:c}),...i.hint?{hint:Ns(i.hint,{row:n})}:{},onSelect:()=>s(i,c)})}}),r}function aV({component:e,data:n}){var S,C;const s=jt(),r=wn(e.query,n),a=ha(),i=e.param??"story",[l,o]=d.useState(null);d.useEffect(()=>{if(!l)return;const A=setTimeout(()=>o(null),rV);return()=>clearTimeout(A)},[l]);const c=Fr(r.data,e.rows).map(sV).filter(A=>A!==null),u=e.ways??[],h=s.params[i],m=h?c.find(A=>A.id===h)??null:null,f=async(A,E,R,P)=>{var U;const O=vC(A.args,E,R);if(!await a.run({tool:A.tool,label:A.label,...A.done!==void 0?{done:A.done}:{},...A.then?{then:A.then}:{}},O)||!A.hides)return;h===E.id&&s.setParams({[i]:null});const F=typeof A.done=="string"?Ns(A.done,{row:R===void 0?E:R}):"Hidden.";o({id:E.id,group:((U=E.group)==null?void 0:U.id)??null,index:P,text:F,...A.undo?{undo:{tool:A.undo.tool,label:A.undo.label,args:vC(A.undo.args,E,R)}}:{}})},p=()=>{const A=l;o(null),A!=null&&A.undo&&a.run({tool:A.undo.tool,label:A.undo.label},A.undo.args)},x=[];for(const A of c){if(l&&A.id===l.id)continue;const E=e.groups&&A.group?A.group.id:null;let R=x.find(P=>P.id===E);R||(R={id:E,name:e.groups&&A.group?A.group.name:null,rows:[]},x.push(R)),R.rows.push(A)}l&&!x.some(A=>A.id===l.group)&&x.push({id:l.group,name:null,rows:[]});const g=(S=e.groups)==null?void 0:S.param,w=!(x.length===1&&g!==void 0&&s.params[g]===x[0].id),v=(A,E)=>t.jsx(cV,{row:A,plugin:s.plugin,menu:yC(u,A,(R,P)=>void f(R,A,P,E)),onOpen:()=>s.setParams({[i]:A.id})},A.id),j=A=>t.jsxs("div",{className:"pl-story-gone",role:"status",children:[t.jsx("span",{children:A.text}),A.undo?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"pl-story-gone-sep","aria-hidden":"true",children:"·"}),t.jsx($,{size:"sm",variant:"ghost",onClick:p,children:A.undo.label})]}):null]},`gone-${A.id}`),y=A=>{const E=A.rows.map(v);return l&&l.group===A.id&&E.splice(Math.min(l.index,E.length),0,j(l)),E};let k;if(r.data===void 0&&r.loading)k=t.jsx("div",{className:"pl-story-grid","aria-busy":"true","aria-label":"Fetching stories",children:Array.from({length:6},(A,E)=>t.jsxs("div",{className:"ui-card pl-story cat-skel pl-story-skel",children:[t.jsxs("span",{className:"pl-story-head",children:[t.jsx("i",{className:"cat-skel-face pl-story-skel-logo"}),t.jsx("i",{className:"cat-skel-line","data-w":"30"})]}),t.jsx("i",{className:"cat-skel-line","data-w":"90"}),t.jsx("i",{className:"cat-skel-line","data-w":"70"}),t.jsx("i",{className:"cat-skel-line","data-w":"40"})]},E))});else if(c.length===0&&!l){const A=(e.emptyStates??[]).find(E=>Kt(r.data,E.when));if(A){const E=P=>P===void 0?"":typeof P=="string"?P:String(Be(r.data,P)??""),R=(A.actions??[]).map((P,O,I)=>{const F=O===I.length-1&&(I.length>1||A.warm===!0);if(P.set)return t.jsx($,{size:"sm",variant:F?"accent":"ghost",onClick:()=>s.setParams(P.set),children:P.label},O);const U=P.to?za(s,P.to,r.data):"";return U===""?null:t.jsx(it,{size:"sm",variant:F?"accent":"ghost",href:U,onClick:L=>{L.preventDefault(),s.navigate(U)},children:P.label},O)});k=t.jsx(Ee,{warm:A.warm===!0,title:E(A.title),action:R.length>0?t.jsx(te,{children:R}):void 0,children:E(A.text)})}else k=t.jsx(Al,{text:e.empty??"Nothing here yet."})}else k=x.map(A=>{var E;return t.jsxs("section",{className:"pl-story-group","aria-label":A.name??e.title??"Stories",children:[w&&A.name?t.jsxs("header",{className:"pl-story-group-head",children:[t.jsx("h2",{className:"pl-story-group-title",children:A.name}),g&&A.id?t.jsxs("a",{href:"#",className:"pl-story-group-aside",onClick:R=>{R.preventDefault(),s.setParams({[g]:A.id})},children:[((E=e.groups)==null?void 0:E.label)??"See all",t.jsx(ne,{name:"arrow",size:12})]}):null]}):null,t.jsx("div",{className:"pl-story-grid",children:y(A)})]},A.id??"all")});const N=u.find(A=>A.hides&&!A.each&&Kt(m,A.when)),b=u.filter(A=>A!==N);return t.jsxs("div",{className:"pl-stories",children:[t.jsx(re,{message:r.error}),t.jsx(uM,{act:a}),k,m?t.jsx(Ye,{scrollBody:!0,title:m.kicker??((C=m.group)==null?void 0:C.name)??e.title??"Story",onClose:()=>s.setParams({[i]:null}),foot:t.jsxs(te,{children:[N?t.jsx($,{variant:"ghost",disabled:a.busy,onClick:()=>void f(N,m,void 0,0),children:Ns(N.label,{row:m})}):null,b.length>0?t.jsx(rs,{label:`Less of this: ${m.title}`,trigger:t.jsx("button",{type:"button",className:"ui-btn","data-variant":"ghost",disabled:a.busy,children:"Less of this…"}),items:yC(b,m,(A,E)=>void f(A,m,E,0)),stacked:!0}):null,t.jsx(ht,{}),e.ask&&Kt(m,e.ask.when)?t.jsx(iV,{to:e.ask.to,row:m,label:e.ask.label,context:e.ask.context,accent:!0}):null]}),children:t.jsx(uV,{row:m,plugin:s.plugin,edition:e.edition})}):null]})}function uM({act:e}){return e.error?t.jsx(re,{message:e.error}):e.approvalId?t.jsx(Lr,{act:e}):null}function iV({to:e,row:n,label:s,accent:r,context:a}){const i=jt(),l=a&&"chat"in e?Be(n,e.chat):null,o=typeof l=="string"&&l?ut(l,"new"):za(i,e,n);return o===""?null:"href"in e?t.jsx(it,{variant:r?"accent":"ghost",href:o,target:"_blank",rel:"noopener noreferrer",children:s}):t.jsx(it,{variant:r?"accent":"ghost",href:o,onClick:c=>{if(c.preventDefault(),a&&"chat"in e){const u=Be(n,e.chat),h=Be(n,a.title),m=Be(n,a.text);typeof u=="string"&&typeof h=="string"&&typeof m=="string"&&jU(u,{title:h,text:m,suggestions:a.suggestions??[]})}i.navigate(o)},children:s})}function lV({row:e}){var s;const n=((s=e.mark)==null?void 0:s.kind)==="told";return!e.opinion&&!e.languages&&!e.mark?null:t.jsxs("span",{className:"pl-story-marks",children:[e.opinion?t.jsx(Po,{children:"Opinion"}):null,e.languages?t.jsx("span",{className:"pl-story-lang",children:e.languages}):null,e.mark?n?t.jsxs("span",{className:"pl-story-told",children:[t.jsx(ne,{name:"check",size:12}),e.mark.text]}):t.jsx("span",{className:"pl-story-new",children:e.mark.text}):null]})}function oV({plugin:e,outlets:n}){return n.length===0?null:t.jsxs("span",{className:"pl-stack","aria-label":Ev(n),children:[t.jsx("span",{className:"pl-stack-logos",children:n.slice(0,3).map((s,r)=>t.jsx(Cl,{src:Sl(e,s.logo),label:s.name},r))}),t.jsx("span",{className:"pl-stack-words",children:Ev(n)})]})}function cV({row:e,plugin:n,menu:s,onOpen:r}){var i;const a=Ev(e.outlets);return t.jsxs("article",{className:"ui-card pl-story","data-told":e.quiet?"true":void 0,"data-opinion":e.opinion?"true":void 0,tabIndex:0,onClick:r,onKeyDown:l=>{l.target!==l.currentTarget||l.key!=="Enter"||(l.preventDefault(),r())},"aria-label":`${e.opinion?"Opinion: ":""}${e.title}.${a?` ${a}`:""}${e.ago?`, ${e.ago}`:""}.`,children:[t.jsxs("header",{className:"pl-story-head",children:[t.jsx(oV,{plugin:n,outlets:e.outlets}),e.ago?t.jsx("span",{className:"pl-story-time",children:e.ago}):null,s.length>0?t.jsx("span",{className:"pl-story-more",onClick:l=>l.stopPropagation(),onKeyDown:l=>l.stopPropagation(),children:t.jsx(rs,{label:`Ways out for ${e.title}`,items:s.map(l=>typeof l=="string"||"heading"in l?l:{label:l.label,...l.hint?{hint:l.hint}:{},onSelect:l.onSelect}),sheet:{title:e.title,sub:[e.kicker??((i=e.group)==null?void 0:i.name),a].filter(Boolean).join(" · ")},stacked:!0})}):null]}),t.jsx(xp,{image:e.image,plugin:n,compact:!0}),t.jsx("h3",{className:"pl-story-title",children:e.title}),e.lead?t.jsx("p",{className:"pl-story-lead",children:e.lead}):null,t.jsx(lV,{row:e})]})}function uV({row:e,plugin:n,edition:s}){const r=Array.isArray(e.sources)?e.sources.filter(u=>u&&typeof u.title=="string"):[],a=Array.isArray(e.timeline)?e.timeline.filter(u=>u&&typeof u.text=="string"):[],i=s&&Kt(e,s.when)?s:void 0,l=e.summary??e.lead,o=u=>u.replace(/\s+/g," ").trim().toLocaleLowerCase(),c=e.update&&o(e.update)!==o(l??"")&&o(e.update)!==o(e.title)?e.update:void 0;return t.jsxs("div",{className:"pl-story-sheet",children:[t.jsxs("div",{className:"pl-story-sheet-lead",children:[e.opinion?t.jsx(Po,{children:"Opinion"}):null,t.jsx("h3",{className:"pl-story-sheet-title",children:e.title}),e.titleAttribution?t.jsx("p",{className:"pl-story-sheet-meta",children:e.titleAttribution}):null,t.jsx(xp,{image:e.image,plugin:n}),l?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"pl-story-sheet-summary",children:l}),e.summaryAttribution?t.jsx("p",{className:"pl-story-sheet-meta",children:e.summaryAttribution}):null]}):null,c?t.jsxs("div",{className:"pl-story-sheet-update",children:[e.mark&&e.mark.kind==="new"?t.jsx("span",{className:"pl-story-new",children:e.mark.text}):null,t.jsx("p",{children:c}),e.updateAttribution?t.jsx("p",{className:"pl-story-sheet-meta",children:e.updateAttribution}):null]}):null,e.meta||i?t.jsxs("p",{className:"pl-story-sheet-meta",children:[e.meta,i?t.jsxs(t.Fragment,{children:[e.meta?" · ":null,t.jsx(dV,{to:i.to,row:e,label:i.label})]}):null]}):null]}),r.length>0?t.jsxs("section",{className:"pl-story-sheet-block",children:[t.jsx("h4",{className:"pl-story-sheet-head",children:"Sources"}),t.jsx("ul",{className:"pl-story-sources",children:r.map((u,h)=>{const m=Xf(u.url);return t.jsxs("li",{className:"pl-story-source",children:[t.jsx(Cl,{className:"pl-logo-md",src:Sl(n,u.logo),label:u.outlet}),t.jsxs("span",{className:"pl-story-source-text",children:[m?t.jsx(Oo,{href:m,className:"wb-src-link pl-story-source-title",children:u.title}):t.jsx("span",{className:"pl-story-source-title",children:u.title}),u.meta?t.jsx("span",{className:"pl-story-source-meta",children:u.meta}):null]})]},h)})})]}):null,a.length>0?t.jsxs("section",{className:"pl-story-sheet-block",children:[t.jsx("h4",{className:"pl-story-sheet-head",children:"Coverage timeline"}),t.jsx("ol",{className:"pl-story-timeline",children:a.map((u,h)=>t.jsxs("li",{className:"pl-story-tl","data-told":u.told?"true":void 0,"data-last":h===a.length-1?"true":void 0,children:[t.jsx("span",{className:"pl-story-tl-at",children:u.at}),t.jsx("span",{className:"pl-story-tl-dot","aria-hidden":"true"}),t.jsx("span",{className:"pl-story-tl-what",children:u.text})]},h))})]}):null]})}function dV({to:e,row:n,label:s}){const r=jt(),a=za(r,e,n);return a===""?null:"href"in e?t.jsx(Oo,{href:a,children:s}):t.jsx("a",{href:a,onClick:i=>{i.preventDefault(),r.navigate(a)},children:s})}function hV({component:e,data:n}){const s=Re(n,e.path);return typeof s!="string"||s===""?null:t.jsx(em,{id:s})}function fV({component:e,data:n}){const s=Re(n,e.path);return typeof s!="string"||s===""?null:t.jsx(te,{children:t.jsx("a",{href:la(s),children:e.label})})}function dM(e){if(typeof e=="string")return e.trim()===""?null:{address:e.trim()};if(e&&typeof e=="object"&&typeof e.address=="string"){const n=e;return{address:n.address,name:typeof n.name=="string"&&n.name.trim()!==""?n.name.trim():null}}return null}function wC(e){return Array.isArray(e)?e.map(dM).filter(n=>n!==null):[]}function bC(e){return e.name?`${e.name} <${e.address}>`:e.address}function kC(e){if(!e||typeof e!="object")return null;const n=e,s=dM(n.from);if(!s)return null;const r=i=>typeof n[i]=="string"?n[i]:null,a=Array.isArray(n.attachments)?n.attachments.filter(i=>!!i&&typeof i=="object"&&typeof i.name=="string"):[];return{...typeof n.id=="string"?{id:n.id}:{},from:s,to:wC(n.to),cc:wC(n.cc),at:r("at"),html:r("html"),text:r("text"),snippet:r("snippet"),note:r("note"),attachments:a}}function mV(e){var s;return(((s=(e.name??e.address).replace(/^["'\s]+/,"").match(/[\p{L}\p{N}]/u))==null?void 0:s[0])??"?").toUpperCase()}function pV(e){let n=0;for(const s of e.toLowerCase())n=n*31+s.charCodeAt(0)>>>0;return n%6+1}function gV({component:e,data:n}){const s=jt(),r=e.path?Re(n,e.path):n,a=e.folded!==void 0&&Kt(r,e.folded),[i,l]=d.useState(!a),[o,c]=d.useState(!1),u=wn(i?e.query:void 0,r),h=kC(r),m=e.query?kC(u.data):h,f=m??h;if(!f)return null;const p=f.from,x=f.at?Ym(new Date(f.at),s.timezone):"",g=[...f.to??[],...f.cc??[]],w=t.jsx("span",{className:"ui-avatar pl-mail-face","data-face":pV(p.address),"aria-hidden":"true",children:mV(p)});return i?t.jsxs("article",{className:"pl-mail","aria-label":`Message from ${p.name??p.address}`,children:[t.jsxs("header",{className:"pl-mail-head",children:[w,t.jsxs("span",{className:"pl-mail-who",children:[t.jsxs("span",{className:"pl-mail-from",children:[p.name?t.jsx("span",{className:"pl-mail-name",children:p.name}):null,t.jsx("span",{className:"pl-mail-address",children:p.name?`<${p.address}>`:p.address})]}),g.length>0?t.jsxs("button",{type:"button",className:"pl-mail-to-toggle","aria-expanded":o,onClick:()=>c(v=>!v),children:["to ",g.map(v=>v.name??v.address).join(", ")]}):null]}),t.jsx("span",{className:"pl-mail-when",children:a?t.jsx("button",{type:"button",className:"pl-mail-fold",onClick:()=>l(!1),title:"Fold this message",children:x}):x})]}),o?t.jsxs("dl",{className:"pl-mail-recipients",children:[(f.to??[]).length>0?t.jsxs(t.Fragment,{children:[t.jsx("dt",{children:"To"}),t.jsx("dd",{children:(f.to??[]).map(bC).join(", ")})]}):null,(f.cc??[]).length>0?t.jsxs(t.Fragment,{children:[t.jsx("dt",{children:"Cc"}),t.jsx("dd",{children:(f.cc??[]).map(bC).join(", ")})]}):null]}):null,t.jsx(re,{message:u.error}),e.query&&!m&&!u.error?t.jsx(Ee,{children:"Loading…"}):t.jsxs(t.Fragment,{children:[f.note?t.jsx("p",{className:"pl-mail-note",children:f.note}):null,t.jsx(SH,{html:f.html,text:f.text,sender:p.address,attachments:f.attachments,cidSrc:Dr}),(f.attachments??[]).length>0?t.jsx(xV,{attachments:f.attachments??[],fetch:e.fetch}):null]})]}):t.jsxs("button",{type:"button",className:"pl-mail-folded",onClick:()=>l(!0),"aria-label":`Open the message from ${p.name??p.address}`,children:[w,t.jsx("span",{className:"pl-mail-folded-who",children:p.name??p.address}),t.jsx("span",{className:"pl-mail-folded-snippet",children:f.snippet??""}),t.jsx("span",{className:"pl-mail-when",children:x})]})}function xV({attachments:e,fetch:n}){const s=jt(),r=ha();return t.jsxs("div",{className:"pl-mail-files",children:[t.jsx("div",{className:"wb-msg-files",role:"list","aria-label":"Attachments",children:e.map((a,i)=>t.jsxs("span",{role:"listitem",className:"pl-mail-file",children:[t.jsx(bd,{name:a.name,mime:a.mime,sizeBytes:typeof a.size=="number"?a.size:null,...a.artifactId?{onOpen:()=>s.navigate(ao(a.artifactId))}:{}}),!a.artifactId&&n?t.jsx(Pi,{action:n,args:Xs(n.args,{data:a,row:a,scope:s}),disabled:r.busy,running:r.running===n.tool,row:a,onRun:(l,o)=>void r.run(l,o)}):null]},`${i}-${a.name}`))}),t.jsx(Lr,{act:r})]})}function jV({component:e,data:n}){const s=wn(e.query,n),r=ha();return s.error?t.jsx(re,{message:s.error}):s.data===void 0?t.jsx(Ee,{children:e.empty??"Loading…"}):t.jsxs(t.Fragment,{children:[t.jsx(Lr,{act:r}),t.jsx(vV,{component:e,data:n,loaded:s.data,act:r},JSON.stringify(hi(s.data)))]})}function vV({component:e,data:n,loaded:s,act:r}){const a=jt(),[i,l]=qb(e.fields,s),o=e.fields.some(x=>x.from!==void 0&&jp(Re(s,x.from))),c={...i,version:Re(s,e.version)},u=Yb(e.fields,i,s),h=e.readOnlyWhen!==void 0&&Kt(s,e.readOnlyWhen),m=(e.actions??[]).filter(x=>x.placement==="leading"),f=(e.actions??[]).filter(x=>x.placement!=="leading"),p=(x,g)=>t.jsx(Pi,{action:x,args:Xs(x.args,{data:n,fields:c,shape:e.fields,omit:u,scope:a}),disabled:r.busy,running:r.running===x.tool,onRun:(w,v)=>void r.run(w,v)},`${x.tool}-${g}`);return t.jsx(Zs,{title:e.title,note:e.note,children:t.jsxs(ue,{children:[t.jsx(bp,{fields:e.fields,values:i,data:s,disabled:h,onChange:l}),o&&!h?t.jsx("p",{className:"muted",children:"Show amounts to change this."}):null,h?null:t.jsxs(te,{align:"end",children:[m.map(p),m.length>0?t.jsx(ht,{}):null,p(e.save,-1),f.map(p)]}),e.footnote?t.jsx("p",{className:"ui-toolbar-note",children:e.footnote}):null]})})}const hM={};function fM({page:e,item:n,navigate:s,timezone:r,embedded:a,siblings:i,params:l}){const[o,c]=d.useState(()=>({...l})),u=JSON.stringify(l??{});d.useEffect(()=>{l&&Object.keys(l).length>0&&c(v=>({...v,...l}))},[u]);const[h,m]=d.useState(0);PI(e.plugin,()=>m(v=>v+1));const[f]=Vb(),p={plugin:e.plugin,page:e.id,pages:i??[e],item:n??null,params:{...o,...n?{item:n}:{},...kV(e,n)},setParams:v=>c(j=>{const y={...j};for(const[k,N]of Object.entries(v))N===null?delete y[k]:y[k]=N;return y}),navigate:s,timezone:r,version:h,refresh:()=>m(v=>v+1),sensitive:new Set(e.sensitive??[]),sensitivePaths:e.sensitivePaths??hM,amountsShown:f},x=e.body[0],g=!a&&(x==null?void 0:x.kind)==="notice"&&x.look!=="quiet"&&x.link===void 0&&x.action===void 0&&x.when===void 0&&x.title===void 0&&(x.tone===void 0||x.tone==="neutral")?x.text:void 0,w=g===void 0?e:{...e,body:e.body.slice(1)};return t.jsx(wp.Provider,{value:p,children:t.jsx(yV,{page:w,embedded:a===!0,lede:g})})}function yV({page:e,embedded:n,lede:s}){const r=jt(),a=e.data!==void 0&&r.sensitive.has(e.data.query),i=wn(a?void 0:e.data,null),l=i.data??null,o=s===void 0||typeof s=="string"?s:Be(l,s),c=o==null||o===""?void 0:String(o),u=d9([e.data,e.actions,e.body],r.sensitivePaths),h=!n&&e.actions&&e.actions.length>0,m=h||u?t.jsxs(t.Fragment,{children:[u?t.jsx(h9,{}):null,h?e.actions.map((f,p)=>t.jsx(wV,{component:f,data:l},p)):null]}):void 0;return t.jsxs(Is,{embedded:n,title:e.title,lede:c,actions:m,children:[!n&&e.place==="rail"?t.jsx(DP,{plugin:e.plugin,navigate:r.navigate,dismissible:!0},e.plugin):null,t.jsx(bV,{page:e,boxed:n,root:a?void 0:i})]})}function wV({component:e,data:n}){const s=jt();if(!Kt(n,e.when))return null;if(e.kind==="button")return t.jsx(cM,{component:e,data:n});if(e.kind==="menu")return t.jsx(sM,{component:e,data:n});const r=za(s,e.to,n);if(r==="")return null;const a=e.tone==="accent"?"accent":"ghost";return"href"in e.to?t.jsxs(it,{variant:a,href:r,target:"_blank",rel:"noopener noreferrer",children:[e.label,t.jsx("span",{className:"wb-src-out","aria-hidden":"true",children:"↗"})]}):t.jsx(it,{variant:a,href:r,onClick:i=>{i.preventDefault(),s.navigate(r)},children:e.label})}function bV({page:e,boxed:n,root:s}){const r=jt();return e.data&&r.sensitive.has(e.data.query)?t.jsx(JP,{children:t.jsx(NC,{page:e,boxed:n})}):t.jsx(NC,{page:e,boxed:n,root:s})}function NC({page:e,boxed:n,root:s}){const r=wn(s?void 0:e.data,null),a=s??r;return t.jsxs(ue,{gap:"lg",divided:!n,children:[t.jsx(re,{message:a.error}),t.jsx(pl.Provider,{value:n,children:e.body.map((i,l)=>t.jsx(Ws,{component:i,data:a.data??null},l))})]})}function kV(e,n){if(!n)return{};const s=[],r=a=>{for(const i of a)if(i.kind==="list-detail")s.push(i.param),r(i.detail);else if(i.kind==="section"||i.kind==="detail"||i.kind==="expand")r(i.body);else if(i.kind==="tabs")for(const l of i.tabs)r(l.body)};return r(e.body),Object.fromEntries(s.map(a=>[a,n]))}function NV(e){return t.jsx(fM,{...e,embedded:!0})}function Al({text:e}){const n=e.search(/[.!?]\s/),s=n===-1?e.replace(/[.]$/,""):e.slice(0,n+(e[n]==="."?0:1)),r=n===-1?"":e.slice(n+1).trim();return t.jsx(ps,{title:s,children:r||null})}const SV=50,CV=9,EV=24,AV=.6,$V=48,TV=/(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,RV=/^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}|$)/,IV=/^id$|(^|[a-z0-9])Id$|_id$/;function lo(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function _s(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function mM(...e){for(const n of e)if(_s(n))for(const s of["currency","currencyCode"]){const r=n[s];if(typeof r=="string"&&/^[A-Za-z]{3}$/.test(r))return r.toUpperCase()}return null}function pM(e,n,s){const r=n.filter(a=>a!=null&&a!=="");return r.length===0?"text":r.every(a=>typeof a=="boolean")?"boolean":r.every(a=>typeof a=="number"&&Number.isFinite(a))?s!==null&&TV.test(e)?"currency":"number":r.every(a=>typeof a=="string"&&RV.test(a))?"date":"text"}function PV(e,n){if(!IV.test(e))return!1;const s=n.filter(r=>!oa(r));return s.length<2?!1:new Set(s.map(r=>String(r))).size===s.length}function oa(e){return e==null||e===""?!0:Array.isArray(e)?e.length===0:_s(e)?Object.keys(e).length===0:!1}function SC(e,n){const s=e.filter(_s);if(s.length===0||s.length/e.length<.8)return null;const r=s.slice(0,SV),a=new Map,i=[];for(const h of r)for(const m of Object.keys(h))a.has(m)||i.push(m),a.set(m,(a.get(m)??0)+1);if(a.size===0||a.size>EV||[...a.values()].reduce((h,m)=>h+m,0)/(a.size*r.length)<AV)return null;const o=[...a.keys()].sort((h,m)=>{const f=(a.get(m)??0)-(a.get(h)??0);return f!==0?f:i.indexOf(h)-i.indexOf(m)}),c=[],u=[];for(const h of o){const m=r.map(g=>g[h]),f=m.filter(g=>!oa(g));if(f.length===0||PV(h,m))continue;const p=mM(r[0],n),x=pM(h,m,p);if(r.length>=4&&f.length===m.length&&m.every(g=>lo(g)&&g===m[0])){u.push({label:nn(h),value:m[0],type:x,currency:p});continue}if(c.push({key:h,label:nn(h),type:x,currency:x==="currency"?p:null}),c.length===CV)break}return c.length===0?null:{columns:c,rows:s,constants:u}}function MV(e,n,s){const r=mM(s);return{label:nn(e),value:n,type:pM(e,[n],r),currency:r}}function gM(e){return typeof e=="string"&&e.length>$V}function OV(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.":_s(e)&&Object.keys(e).length===0?"This tool returned an empty result.":null}function Av(e){if(typeof e=="string"&&e.trim()!=="")return e;if(_s(e))for(const n of["message","error","reason","detail","description"]){const s=e[n];if(typeof s=="string"&&s.trim()!=="")return s;if(_s(s)){const r=Av(s);if(r!=="The call failed with no reason given.")return r}}return"The call failed with no reason given."}function Xb(e,n={}){if(n.failed){let m=e;if(typeof e=="string")try{const f=JSON.parse(e.replace(/^tool-error:\s*/,""));_s(f)&&(m=f)}catch{}return{kind:"error",summary:Av(m),detail:CC(m)}}if(_s(e)){const m=e.error,f=e.ok;if(typeof m=="string"&&m.trim()!==""||f===!1)return{kind:"error",summary:Av(e),detail:CC(e)}}const s=OV(e);if(s)return{kind:"empty",note:s,stats:[]};if(Array.isArray(e)){const m=SC(e,e);return m?{kind:"table",label:null,columns:m.columns,rows:m.rows,total:m.rows.length,stats:m.constants,notes:[],asides:[]}:e.every(lo)?{kind:"list",label:null,items:e,total:e.length,stats:[],notes:[],asides:[]}:{kind:"tree",value:e}}if(!_s(e))return{kind:"tree",value:e};const r=Object.entries(e);let a=null,i=null;for(const[m,f]of r){if(!Array.isArray(f))continue;const p=SC(f,e);if(p){(!a||p.rows.length>a.candidate.rows.length)&&(a={key:m,candidate:p});continue}f.length>0&&f.every(lo)&&(!i||f.length>i.items.length)&&(i={key:m,items:f})}const l=(a==null?void 0:a.key)??(i==null?void 0:i.key)??null,o=[],c=[],u=[];for(const[m,f]of r)if(m!==l){if(gM(f)){c.push(f);continue}if(lo(f)){if(f==="")continue;o.push(MV(m,f,e));continue}f!==void 0&&u.push({label:nn(m),value:f})}if(a)return{kind:"table",label:nn(a.key),columns:a.candidate.columns,rows:a.candidate.rows,total:a.candidate.rows.length,stats:[...o,...a.candidate.constants],notes:c,asides:u};if(i)return{kind:"list",label:nn(i.key),items:i.items,total:i.items.length,stats:o,notes:c,asides:u};const h=r.filter(([,m])=>Array.isArray(m)&&m.length===0);return h.length>0&&h.length===r.filter(([,m])=>Array.isArray(m)).length?{kind:"empty",note:`No ${h.map(([f])=>nn(f).toLowerCase()).join(", ")} to show.`,stats:o}:r.every(([,m])=>lo(m)||_s(m)||Array.isArray(m))?{kind:"record",pairs:o,notes:c,asides:u}:{kind:"tree",value:e}}function CC(e){if(!_s(e))return null;const n=Object.entries(e).filter(([s])=>s!=="message"&&s!=="error");return n.length===0?null:Object.fromEntries(n)}const tm=25,DV=3,$v=8,xM=6;function Tv(e,n=0){if(n>xM||oa(e)||gM(e))return 0;if(lo(e))return 1;if(Array.isArray(e)){let s=0;for(const r of e)if(s+=Tv(r,n+1),s>=$v)return s;return s}if(_s(e)){let s=0;for(const r of Object.values(e))if(s+=Tv(r,n+1),s>=$v)return s;return s}return 0}function Rv(e,n=0){if(n>xM)return!1;if(Array.isArray(e))return e.some(i=>Rv(i,n+1));if(!_s(e))return!1;const s=e.artifactId??e.artifact_id;if(typeof s=="string"&&s.trim()!=="")return!0;const r=e.mime??e.mimeType??e.contentType,a=e.url??e.src??e.downloadUrl??e.path;return typeof r=="string"&&r.includes("/")&&typeof a=="string"&&a.trim()!==""?!0:Object.values(e).some(i=>Rv(i,n+1))}function LV(e){if(Rv(e))return!0;const n=Xb(e);switch(n.kind){case"table":return n.rows.length>0;case"list":return n.items.length>=DV;case"record":case"tree":return Tv(e)>=$v;default:return!1}}function Og(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function kp(e){const n=Og(e);if(!n)return null;const s=Og(n.output)??n;if(typeof s.state!="string"||typeof s.stdout!="string"||typeof s.stderr!="string"||!(s.exitCode===null||typeof s.exitCode=="number"&&Number.isFinite(s.exitCode)))return null;const r=s===n?null:Og(n.input),a=(r==null?void 0:r.command)??s.command;return{command:typeof a=="string"?a:null,input:r,result:s}}function FV({text:e,label:n}){const[s,r]=d.useState("");return t.jsxs("span",{className:"wb-command-copy",children:[t.jsx("button",{className:"ui-btn",onClick:()=>{var a;if(r(""),!((a=navigator.clipboard)!=null&&a.writeText)){r("Copy unavailable; select the text to copy.");return}navigator.clipboard.writeText(e).then(()=>r("Copied"),()=>r("Copy failed; select the text to copy."))},children:n}),s&&t.jsx("span",{role:"status",className:"wb-hint",children:s})]})}function Dg({title:e,text:n,error:s=!1}){return t.jsxs("section",{className:"wb-command-stream","data-error":s||void 0,children:[t.jsxs("div",{className:"wb-command-bar",children:[t.jsx("h4",{children:e}),t.jsx(FV,{text:n,label:`Copy ${e.toLowerCase()}`})]}),t.jsx("pre",{className:"wb-command-text","aria-label":e,tabIndex:0,children:n})]})}function _V({value:e,children:n}){const{result:s,command:r,input:a}=e,i=s.state==="completed"&&s.exitCode!==null&&s.exitCode!==0,l=typeof s.signal=="string"&&s.signal?s.signal:null,o=s.state==="completed"&&s.exitCode===0,c=Object.fromEntries(Object.entries(s).filter(([h,m])=>!["stdout","stderr","state","exitCode","artifacts","outputErrors","command"].includes(h)&&m!==null&&m!==void 0&&m!=="")),u=Array.isArray(s.outputErrors)?s.outputErrors.filter(h=>typeof h=="string"):[];return t.jsxs("div",{className:"wb-command-result",children:[t.jsxs("div",{className:"wb-command-bar",children:[t.jsx("span",{className:"ui-pill","data-tone":o?"good":"critical",children:i?"Failed":s.state==="completed"&&l?"Terminated":s.state}),s.exitCode!==null&&t.jsxs("span",{className:"mono",children:["Exit code ",s.exitCode]}),l&&t.jsxs("span",{className:"mono",children:["Signal ",l]}),t.jsx("span",{className:"wb-hint",children:"Recorded command result"})]}),r!==null&&t.jsx(Dg,{title:"Command",text:r}),s.state==="output-limit"&&t.jsx("p",{className:"wb-fail",children:"Output limit reached. The command was stopped and the captured output may be incomplete."}),s.state==="timed-out"&&t.jsx("p",{className:"wb-fail",children:"The command exceeded its time limit. Output below may be partial."}),s.state==="cancelled"&&t.jsx("p",{className:"wb-note",children:"The command was cancelled. Completed changes were not undone."}),s.stdout?t.jsx(Dg,{title:"Output",text:s.stdout}):t.jsx("p",{className:"wb-note",children:"No standard output."}),s.stderr?t.jsx(Dg,{title:"Standard error",text:s.stderr,error:!0}):null,u.length>0&&t.jsxs("section",{children:[t.jsx("h4",{children:"File export errors"}),u.map((h,m)=>t.jsx("p",{className:"wb-fail",children:h},m))]}),n,(Object.keys(c).length>0||a!==null)&&t.jsxs("details",{className:"wb-aside",children:[t.jsx("summary",{children:"Execution details"}),t.jsx("pre",{children:ms({...c,...a?{input:a}:{}})})]})]})}const fh=2,EC=64;function $l({props:e,bare:n=!1}){const[s,r]=d.useState(!1),a=kp(e.value),i=zV((a==null?void 0:a.result)??e.value),l=d.useMemo(()=>Xb(e.value,{failed:e.failed??!1}),[e.value,e.failed]);return t.jsxs("div",{children:[!a&&t.jsx(AC,{files:i}),s?t.jsx("pre",{className:"ui-code",children:ms(e.value)}):a?t.jsx(_V,{value:a,children:i.length>0&&t.jsxs("section",{children:[t.jsx("h4",{children:"Generated files"}),t.jsx(AC,{files:i})]})}):i.length?t.jsxs("details",{className:"wb-aside",children:[t.jsx("summary",{children:"Tool details"}),t.jsx($C,{shape:l})]}):t.jsx($C,{shape:l}),n?null:t.jsx("div",{className:"wb-row-end wb-section",children:t.jsx("button",{className:"ui-btn","data-variant":"ghost","data-size":"sm",onClick:()=>r(o=>!o),"aria-pressed":s,children:s?"Readable":"Raw JSON"})})]})}function zV(e){const n=e&&typeof e=="object"&&"artifacts"in e?e.artifacts:null;return Array.isArray(n)?n.filter(s=>s&&typeof s.id=="string"&&/^[0-9a-f-]{36}$/i.test(s.id)&&typeof s.filename=="string"):[]}function AC({files:e}){return e.length?t.jsx("div",{className:"wb-artifacts",children:e.map(n=>{var s;return t.jsxs("div",{children:[["image/png","image/jpeg","image/gif","image/webp"].includes(n.mime??"")?t.jsx(UV,{file:n}):null,t.jsx("a",{className:"ui-btn",href:`/api/artifacts/${encodeURIComponent(n.id)}/download`,download:!0,children:(s=n.mime)!=null&&s.startsWith("image/")?`Download ${n.filename}`:n.filename})]},n.id)})}):null}function UV({file:e}){const[n,s]=d.useState(!1);return n?t.jsx("p",{className:"wb-note",children:"Preview unavailable. You can still download the file."}):t.jsx("img",{className:"wb-artifact-image",src:`/api/artifacts/${e.id}/preview`,alt:e.filename,onError:()=>s(!0)})}function $C({shape:e}){switch(e.kind){case"error":return t.jsxs("div",{children:[t.jsx("p",{className:"wb-fail",role:"status",children:e.summary}),e.detail===null?null:t.jsxs("details",{className:"wb-aside",children:[t.jsx("summary",{children:"What came back with it"}),t.jsx("div",{className:"wb-tree",children:Gu(e.detail,1)})]})]});case"empty":return t.jsxs("div",{children:[t.jsx(Lg,{stats:e.stats}),t.jsx("p",{className:"wb-note",children:e.note})]});case"table":{const n=GV(e.columns,e.rows);return t.jsxs("div",{children:[t.jsx(Lg,{stats:e.stats}),t.jsx(Fg,{notes:e.notes}),n?t.jsx(qV,{label:e.label,plan:n,rows:e.rows,total:e.total}):t.jsx(WV,{label:e.label,columns:e.columns,rows:e.rows,total:e.total}),t.jsx(_g,{asides:e.asides})]})}case"list":return t.jsxs("div",{children:[t.jsx(Lg,{stats:e.stats}),t.jsx(Fg,{notes:e.notes}),e.label?t.jsx("h4",{className:"wb-sub",children:e.label}):null,t.jsx("ul",{className:"wb-list",children:e.items.slice(0,100).map((n,s)=>t.jsx("li",{children:Mn(n,"text",null)},s))}),e.total>100?t.jsxs("p",{className:"wb-note",children:["Showing 100 of ",e.total,"."]}):null,t.jsx(_g,{asides:e.asides})]});case"record":return t.jsxs("div",{children:[t.jsx(Fg,{notes:e.notes}),t.jsx(BV,{pairs:e.pairs}),t.jsx(_g,{asides:e.asides})]});default:return t.jsx("div",{className:"wb-tree",children:Gu(e.value,0)})}}function Lg({stats:e}){return e.length===0?null:t.jsx("div",{className:"ui-stats","data-inline":"true",children:e.map(n=>t.jsxs("div",{children:[t.jsx("div",{className:"ui-stat-k",children:n.label}),t.jsx("div",{className:"ui-stat-v",children:Zb(n.value,n.type,n.currency)})]},n.label))})}const TC=200;function Fg({notes:e}){if(e.length===0)return null;const n=e.filter(r=>r.length<=TC),s=e.filter(r=>r.length>TC);return t.jsxs(t.Fragment,{children:[n.map(r=>t.jsx("p",{className:"wb-note",children:r},r)),s.length>0?t.jsxs("details",{className:"wb-aside",children:[t.jsx("summary",{children:s.length===1?"A note that came with this result":`${s.length} notes that came with this result`}),s.map(r=>t.jsx("p",{className:"wb-note",children:r},r))]}):null]})}function BV({pairs:e}){return e.length===0?t.jsx("p",{className:"wb-note",children:"Nothing to show."}):t.jsx("dl",{className:"ui-kv",children:e.map(n=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:n.label}),t.jsx("dd",{className:n.type==="text"?void 0:"tnum",children:Zb(n.value,n.type,n.currency)})]},n.label))})}function _g({asides:e}){return e.length===0?null:t.jsx("div",{className:"wb-section",children:e.map(n=>t.jsxs("details",{className:"wb-aside",children:[t.jsx("summary",{children:n.label}),t.jsx("div",{className:"wb-tree",children:Gu(n.value,1)})]},n.label))})}function WV({label:e,columns:n,rows:s,total:r}){const[a,i]=d.useState(!1),l=r<=tm+5?r:tm,o=a?s:s.slice(0,l);return t.jsxs("div",{children:[e?t.jsx("h4",{className:"wb-sub",children:e}):null,t.jsx("div",{className:"ui-table-wrap",children:t.jsxs("table",{className:"ui-table",children:[t.jsx("thead",{children:t.jsx("tr",{children:n.map(c=>t.jsx("th",{className:vM(c.type)?"num":void 0,children:c.label},c.key))})}),t.jsx("tbody",{children:o.map((c,u)=>t.jsx("tr",{children:n.map(h=>t.jsx(YV,{value:c[h.key],column:h},h.key))},u))})]})}),r>o.length?t.jsxs("p",{className:"wb-note wb-note-row",children:[t.jsxs("span",{children:["Showing ",o.length," of ",r]}),t.jsxs("button",{className:"ui-btn",onClick:()=>i(!0),children:["Show all ",r]})]}):null]})}const HV=/^(title|name|headline|subject|label|heading)$/i,KV=/^(url|link|href|uri|permalink)$/i;function nm(e){return typeof e=="string"&&/^https?:\/\/[^\s]+$/i.test(e.trim())}function VV(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function jM(e,n=48){try{const s=new URL(e),r=s.pathname==="/"?"":s.pathname,a=`${s.hostname.replace(/^www\./,"")}${r}${s.search}`;return a.length>n?`${a.slice(0,n-1)}…`:a}catch{return e.length>n?`${e.slice(0,n-1)}…`:e}}function mh(e,n){const s=e.map(r=>r[n]).filter(r=>typeof r=="string"&&r.trim()!=="");return s.length===0?0:s.reduce((r,a)=>r+a.length,0)/s.length}function GV(e,n){if(n.length===0)return null;const s=e.filter(h=>h.type==="text"),r=s.find(h=>KV.test(h.key)&&n.some(m=>nm(m[h.key])))??s.find(h=>{const m=n.map(f=>f[h.key]).filter(f=>!oa(f));return m.length>0&&m.filter(nm).length/m.length>=.6});if(!r)return null;const a=s.filter(h=>h.key!==r.key),i=a.find(h=>HV.test(h.key))??a.find(h=>mh(n,h.key)>0);if(!i)return null;const o=[...a.filter(h=>h.key!==i.key)].sort((h,m)=>mh(n,m.key)-mh(n,h.key)),c=o[0]&&mh(n,o[0].key)>40?o[0]:null,u=e.filter(h=>h.key!==r.key&&h.key!==i.key&&h.key!==(c==null?void 0:c.key)).map(h=>h.key);return{url:r.key,title:i.key,description:(c==null?void 0:c.key)??null,meta:u}}function qV({label:e,plan:n,rows:s,total:r}){const[a,i]=d.useState(!1),l=r<=tm+5?r:tm,o=a?s:s.slice(0,l);return t.jsxs("div",{children:[e?t.jsx("h4",{className:"wb-sub",children:e}):null,t.jsx("ol",{className:"wb-records",children:o.map((c,u)=>{const h=c[n.url],m=nm(h)?h.trim():null,f=typeof c[n.title]=="string"&&c[n.title].trim()!==""?c[n.title]:m?jM(m):"Untitled",p=n.description&&typeof c[n.description]=="string"?c[n.description]:null,x=m?VV(m):null,g=n.meta.map(w=>c[w]).filter(w=>!oa(w)&&typeof w!="object").map(w=>String(w)).filter(w=>x===null||w.replace(/^www\./,"")!==x);return t.jsxs("li",{className:"wb-record",children:[m?t.jsx("a",{className:"wb-record-title",href:m,target:"_blank",rel:"noopener noreferrer",children:f}):t.jsx("span",{className:"wb-record-title",children:f}),t.jsxs("div",{className:"wb-record-meta",children:[x?t.jsx("span",{className:"wb-record-host",title:m??void 0,children:x}):null,g.map((w,v)=>t.jsx("span",{children:w.length>60?`${w.slice(0,59)}…`:w},v))]}),p?t.jsx("p",{className:"wb-record-desc",children:p.length>280?`${p.slice(0,279)}…`:p}):null]},u)})}),r>o.length?t.jsxs("p",{className:"wb-note wb-note-row",children:[t.jsxs("span",{children:["Showing ",o.length," of ",r]}),t.jsxs("button",{className:"ui-btn",onClick:()=>i(!0),children:["Show all ",r]})]}):null]})}function YV({value:e,column:n}){if(oa(e))return t.jsx("td",{className:"wb-cell-soft",children:"—"});if(nm(e)){const a=e.trim();return t.jsx("td",{className:"wb-cell-link",children:t.jsx("a",{href:a,target:"_blank",rel:"noopener noreferrer",title:a,children:jM(a)})})}if(e!==null&&typeof e=="object"){const a=Array.isArray(e)?`${e.length} item${e.length===1?"":"s"}`:`${Object.keys(e).length} fields`;return t.jsx("td",{className:"wb-cell-soft",title:ms(e),children:a})}const s=Zb(e,n.type,n.currency),r=s.length>EC?`${s.slice(0,EC-1)}…`:s;return t.jsx("td",{className:vM(n.type)?"num":"wb-cell-text",...r===s?{}:{title:s},children:r})}function vM(e){return e==="number"||e==="currency"}function Zb(e,n,s){return e==null?"—":n==="boolean"?e?"yes":"no":Mn(e,n==="text"?"text":n,s)}function Gu(e,n){if(e===null)return t.jsx("span",{className:"wb-tree-null",children:"null"});if(e===void 0)return t.jsx("span",{className:"wb-tree-null",children:"—"});if(typeof e=="number")return t.jsx("span",{className:"wb-tree-num",children:e});if(typeof e=="boolean")return t.jsx("span",{className:"wb-tree-bool",children:e?"true":"false"});if(typeof e=="string")return t.jsx("span",{children:e===""?t.jsx("em",{className:"wb-tree-null",children:"empty"}):e});if(Array.isArray(e)){if(e.length===0)return t.jsx("span",{className:"wb-tree-null",children:"none"});const a=t.jsxs("div",{className:"wb-tree-branch",children:[e.slice(0,50).map((i,l)=>t.jsxs("div",{children:[t.jsxs("span",{className:"wb-tree-key",children:[l,". "]}),Gu(i,n+1)]},l)),e.length>50?t.jsxs("div",{className:"wb-tree-key",children:["…and ",e.length-50," more"]}):null]});return n>=fh?t.jsx(RC,{summary:`${e.length} items`,open:n===fh,children:a}):a}const s=Object.entries(e);if(s.length===0)return t.jsx("span",{className:"wb-tree-null",children:"empty"});const r=t.jsx("div",{className:n===0?void 0:"wb-tree-branch",children:s.map(([a,i])=>t.jsxs("div",{children:[t.jsxs("span",{className:"wb-tree-key",children:[nn(a),": "]}),Gu(i,n+1)]},a))});return n>=fh?t.jsx(RC,{summary:`${s.length} fields`,open:n===fh,children:r}):r}function RC({summary:e,open:n,children:s}){return t.jsxs("details",{open:n,children:[t.jsx("summary",{className:"wb-tree-key",children:e}),s]})}const QV=e=>e&&typeof e=="object"&&!Array.isArray(e)?e:{};function yM({value:e}){return t.jsxs("details",{className:"cv-story-details",children:[t.jsx("summary",{children:"Technical details"}),t.jsx($l,{props:{value:e}})]})}function JV({props:e}){const n=QV(e.value);if(typeof n.id!="string"||typeof n.mime!="string"||!mp(n.mime))return t.jsx($l,{props:e});const s=[n.voice,n.model].filter(r=>typeof r=="string"&&r!=="").join(" · ");return t.jsxs("div",{children:[t.jsx(gp,{audio:{fileId:n.id,mime:n.mime,filename:typeof n.name=="string"?n.name:null,sizeBytes:typeof n.bytes=="number"?n.bytes:null}}),s?t.jsx("p",{className:"muted",children:s}):null,t.jsx(yM,{value:n})]})}function XV({props:e,timezone:n}){return!e.plugin||!e.query||e.body.length===0?t.jsx($l,{props:{value:e.value}}):t.jsxs("div",{children:[t.jsx(w9,{plugin:e.plugin,query:e.query,params:e.params,body:e.body,timezone:n??Intl.DateTimeFormat().resolvedOptions().timeZone}),t.jsx(yM,{value:e.value})]})}const yo=e=>e&&typeof e=="object"&&!Array.isArray(e)?e:{},Nt=e=>typeof e=="string"?e:"",zg=e=>Array.isArray(e)?e.map(yo):[];function wM(e){try{const n=new URL(Nt(e));return n.protocol==="https:"||n.protocol==="http:"?n.href:void 0}catch{return}}function bM(e){const n=yo(e);return Nt(n.key)?n:void 0}const ZV=new Set(["kicker","title","titleAttribution","image","summary","lead","summaryAttribution","update","updateAttribution","meta","sources","timeline","url","attachments"]);function IC(e,n){return Object.fromEntries(Object.entries(yo(e)).filter(([s])=>!n.has(s)))}function kM({value:e}){return Object.keys(e).length===0?null:t.jsxs("details",{className:"pl-story-sheet-block",children:[t.jsx("summary",{children:"Technical details"}),t.jsx($l,{props:{value:e}})]})}function eG({props:e}){if(e.rows)return t.jsx(tG,{rows:zg(e.rows),plugin:e.plugin,value:IC(e.value,new Set([...Object.keys(yo(e.value)).filter(i=>yo(e.value)[i]===e.rows),"attachments"]))});const n=yo(e.value);if(!Nt(n.title))return t.jsx($l,{props:{value:e.value}});const s=Nt(n.summary)||Nt(n.lead),r=zg(n.sources).filter(i=>Nt(i.title)),a=zg(n.timeline).filter(i=>Nt(i.text));return t.jsxs("article",{className:"pl-story-sheet",children:[t.jsxs("header",{className:"pl-story-sheet-lead",children:[Nt(n.kicker)?t.jsx("p",{className:"pl-story-sheet-meta",children:Nt(n.kicker)}):null,t.jsx("h2",{className:"pl-story-sheet-title",children:Nt(n.title)}),Nt(n.titleAttribution)?t.jsx("p",{className:"pl-story-sheet-meta",children:Nt(n.titleAttribution)}):null,t.jsx(xp,{image:bM(n.image),plugin:e.plugin}),s?t.jsx("p",{className:"pl-story-sheet-summary",children:s}):null,s&&Nt(n.summaryAttribution)?t.jsx("p",{className:"pl-story-sheet-meta",children:Nt(n.summaryAttribution)}):null,Nt(n.update)?t.jsxs("div",{className:"pl-story-sheet-update",children:[t.jsx("p",{children:Nt(n.update)}),Nt(n.updateAttribution)?t.jsx("p",{className:"pl-story-sheet-meta",children:Nt(n.updateAttribution)}):null]}):null,Nt(n.meta)?t.jsx("p",{className:"pl-story-sheet-meta",children:Nt(n.meta)}):null]}),r.length>0?t.jsxs("section",{className:"pl-story-sheet-block",children:[t.jsx("h3",{className:"pl-story-sheet-head",children:"Sources"}),t.jsx("ul",{className:"cv-story-sources",children:r.map((i,l)=>{const o=wM(i.url);return t.jsxs("li",{children:[t.jsx(Cl,{src:Sl(e.plugin,i.logo),label:Nt(i.outlet)}),t.jsxs("div",{children:[o?t.jsxs("a",{href:o,target:"_blank",rel:"noopener noreferrer",children:[Nt(i.title)," ↗"]}):t.jsx("span",{children:Nt(i.title)}),t.jsx("p",{className:"pl-story-sheet-meta",children:Nt(i.meta)||Nt(i.outlet)})]})]},l)})})]}):null,a.length>0?t.jsxs("section",{className:"pl-story-sheet-block",children:[t.jsx("h3",{className:"pl-story-sheet-head",children:"Timeline"}),t.jsx("ol",{className:"cv-story-timeline",children:a.map((i,l)=>t.jsxs("li",{"data-told":i.told===!0||void 0,children:[t.jsx("time",{children:Nt(i.at)}),t.jsx("div",{children:t.jsx("p",{children:Nt(i.text)})})]},l))})]}):null,t.jsx(kM,{value:IC(e.value,ZV)})]})}function tG({rows:e,plugin:n,value:s}){const r=e.filter(a=>Nt(a.title));return t.jsxs("section",{className:"cv-story-list",children:[r.length>0?t.jsx("ul",{children:r.map((a,i)=>{const l=wM(a.url),o=bM(a.image),c=Nt(a.meta)||Nt(a.kicker),u=o?[o.credit,o.outlet].filter(Boolean).join(" · "):"";return t.jsxs("li",{children:[t.jsx(xp,{image:o,plugin:n,compact:!0}),t.jsxs("div",{children:[c?t.jsx("p",{className:"pl-story-sheet-meta",children:c}):null,t.jsx("h3",{children:l?t.jsxs("a",{href:l,target:"_blank",rel:"noopener noreferrer",children:[Nt(a.title)," ↗"]}):Nt(a.title)}),Nt(a.lead)||Nt(a.summary)?t.jsx("p",{children:Nt(a.lead)||Nt(a.summary)}):null,u?t.jsx("p",{className:"pl-story-sheet-meta",children:u}):null]})]},Nt(a.id)||i)})}):t.jsx("p",{className:"muted",children:"Nothing to show."}),t.jsx(kM,{value:s})]})}function nG({props:e}){if(e.bars.length===0)return t.jsx("p",{className:"wb-empty",children:"No categories came back."});const n=e.bars.map(i=>i.value),s=Math.max(0,...n),r=Math.min(0,...n),a=s-r||1;return t.jsx("div",{className:"wb-bars",children:e.bars.map(i=>{const l=Math.abs(i.value)/a;return t.jsxs("div",{className:"wb-bar-row",children:[t.jsx("div",{className:"wb-bar-cat",title:i.category,children:i.category}),t.jsx("div",{className:"wb-bar-track",children:t.jsx("div",{className:"wb-bar-fill",style:{width:`${Math.max(1,l*100)}%`,background:i.value<0?"var(--chart-bar-negative)":"var(--chart-bar)"}})}),t.jsx("div",{className:"wb-bar-val",children:Mn(i.value,e.unit,e.currency)})]},i.category)})})}const sG=/^(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 )/,rG=/^(… |\.\.\. |\(no change\)$|\)/;function aG(e){return e.replace(/\n$/,"").split(`
103
- `).map(s=>({kind:iG(s),text:s}))}function iG(e){return e.startsWith("@@")?"hunk":sG.test(e)||rG.test(e)?"meta":e.startsWith("+")?"add":e.startsWith("-")?"del":"context"}function lG({text:e,marks:n}){const s=e.toLowerCase(),r=[];for(const l of n){const o=l.trim().toLowerCase();if(o!=="")for(let c=s.indexOf(o);c!==-1;c=s.indexOf(o,c+o.length))r.push([c,c+o.length])}if(r.length===0)return t.jsx(t.Fragment,{children:e===""?" ":e});r.sort((l,o)=>l[0]-o[0]);const a=[];let i=0;for(const[l,o]of r)l<i||(l>i&&a.push(t.jsx("span",{children:e.slice(i,l)},`t${i}`)),a.push(t.jsx("mark",{className:"wb-diff-mark",children:e.slice(l,o)},`m${l}`)),i=o);return i<e.length&&a.push(t.jsx("span",{children:e.slice(i)},`t${i}`)),t.jsx(t.Fragment,{children:a})}function sm({text:e,limit:n,more:s,label:r="Diff",marks:a}){const i=aG(e),l=n===void 0?i:i.slice(0,n),o=i.length-l.length;return t.jsxs("div",{className:"wb-diff-wrap",children:[t.jsx("pre",{className:"wb-diff","aria-label":r,"data-testid":"diff",children:l.map((c,u)=>t.jsx("span",{className:"wb-diff-line","data-kind":c.kind,children:a&&a.length>0?t.jsx(lG,{text:c.text,marks:a}):c.text===""?" ":c.text},u))}),o>0?t.jsxs("p",{className:"wb-diff-more",children:[o," more line",o===1?"":"s",s?t.jsxs(t.Fragment,{children:[" · ",t.jsx("button",{type:"button",className:"wb-diff-open",onClick:s.onClick,children:s.label})]}):null]}):null]})}function oG({props:e}){return t.jsxs("div",{children:[e.title?t.jsx("h4",{className:"wb-doc-title mono",children:e.title}):null,e.metadata.length>0?t.jsx("dl",{className:"ui-kv wb-block",children:e.metadata.map(n=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:n.label}),t.jsx("dd",{children:Mn(n.value,n.unit,null)})]},n.label))}):null,e.diff?t.jsx(sm,{text:e.diff,label:e.title?`Diff of ${e.title}`:"Diff"}):t.jsx("p",{className:"wb-empty",children:"This change came back with no diff."})]})}const NM=d.createContext([]);function pr({text:e,className:n}){const s=Iv(e.replace(/\r\n/g,`
104
- `).split(`
105
- `));return t.jsx("div",{className:n??"wb-md",children:s.map((r,a)=>t.jsx(Pv,{block:r},a))})}const PC=/^(\s*)(```|~~~)\s*([\w+-]*)\s*$/,MC=/^(#{1,6})\s+(.*?)\s*#*\s*$/,OC=/^\s*([-*_])(\s*\1){2,}\s*$/,ph=/^(\s*)([-*+])\s+(.*)$/,Ac=/^(\s*)(\d{1,9})[.)]\s+(.*)$/,gh=/^\s*>\s?(.*)$/,Ug=/^\s*\|.*\|\s*$/,DC=/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/;function Iv(e){const n=[];let s=0;for(;s<e.length;){const r=e[s];if(r.trim()===""){s+=1;continue}const a=PC.exec(r);if(a){const o=a[2],c=[];for(s+=1;s<e.length&&!new RegExp(`^\\s*${o}\\s*$`).test(e[s]);)c.push(e[s]),s+=1;s+=1,n.push({type:"code",lang:a[3]||null,text:c.join(`
106
- `)});continue}const i=MC.exec(r);if(i){n.push({type:"h",level:i[1].length,text:i[2]}),s+=1;continue}if(OC.test(r)){n.push({type:"hr"}),s+=1;continue}if(gh.test(r)){const o=[];for(;s<e.length&&gh.test(e[s]);)o.push(gh.exec(e[s])[1]),s+=1;n.push({type:"quote",blocks:Iv(o),raw:o.join(`
107
- `)});continue}if(Ug.test(r)&&s+1<e.length&&DC.test(e[s+1])){const o=Wg(r),c=Wg(e[s+1]).map(h=>{const m=h.startsWith(":"),f=h.endsWith(":");return m&&f?"center":f?"right":m?"left":null});s+=2;const u=[];for(;s<e.length&&Ug.test(e[s]);)u.push(Wg(e[s])),s+=1;n.push({type:"table",head:o,rows:u,align:c});continue}if(ph.test(r)||Ac.test(r)){const o=Ac.exec(r)??ph.exec(r),c=Ac.test(r),u=o[1].length,h=c?Number(o[2]):1,m=[];for(;s<e.length;){const f=c?Ac.exec(e[s]):ph.exec(e[s]);if(!f||f[1].length!==u)break;const p=[f[3]];for(s+=1;s<e.length;){const x=e[s],g=x.trim()!==""&&Bg(x)>u,w=x.trim()===""&&s+1<e.length&&e[s+1].trim()!==""&&Bg(e[s+1])>u;if(!g&&!w)break;p.push(x.trim()===""?"":x.slice(Math.min(Bg(x),u+2))),s+=1}m.push(Iv(p))}n.push({type:"list",ordered:c,start:h,items:m});continue}const l=[];for(;s<e.length;){const o=e[s];if(o.trim()===""||PC.test(o)||MC.test(o)||OC.test(o)||gh.test(o)||ph.test(o)||Ac.test(o)||Ug.test(o)&&s+1<e.length&&DC.test(e[s+1]))break;l.push(o.trim()),s+=1}l.length>0&&n.push({type:"p",text:l.join(`
108
- `)})}return n}function Bg(e){return e.length-e.trimStart().length}function Wg(e){const n=e.trim().replace(/^\|/,"").replace(/\|$/,""),s=[];let r="";for(let a=0;a<n.length;a+=1){const i=n[a];if(i==="\\"&&n[a+1]==="|"){r+="|",a+=1;continue}if(i==="|"){s.push(r.trim()),r="";continue}r+=i}return s.push(r.trim()),s}function Pv({block:e}){switch(e.type){case"p":return t.jsx("p",{children:Sr(e.text)});case"h":{const n=Math.min(6,Math.max(1,e.level)),s=`h${Math.min(n+2,6)}`;return t.jsx(s,{className:"wb-md-h","data-level":n,children:Sr(e.text)})}case"code":return t.jsxs("div",{className:"wb-md-code-frame",children:[t.jsxs("div",{className:"wb-md-code-head",children:[t.jsx("span",{className:"wb-md-code-lang",children:e.lang??"text"}),t.jsx(LC,{text:e.text,what:"code",always:!0})]}),t.jsx("pre",{className:"wb-md-code","data-lang":e.lang??void 0,children:t.jsx("code",{children:e.text})})]});case"quote":return t.jsxs("div",{className:"wb-md-copyable",children:[t.jsx("blockquote",{children:e.blocks.map((n,s)=>t.jsx(Pv,{block:n},s))}),t.jsx(LC,{text:e.raw,what:"quote"})]});case"hr":return t.jsx("hr",{});case"list":{const n=e.items.map((s,r)=>t.jsx("li",{children:s.map((a,i)=>a.type==="p"?t.jsx(d.Fragment,{children:Sr(a.text)},i):t.jsx(Pv,{block:a},i))},r));return e.ordered?t.jsx("ol",{start:e.start,children:n}):t.jsx("ul",{children:n})}case"table":return t.jsx("div",{className:"ui-table-wrap",children:t.jsxs("table",{className:"ui-table wb-md-table",children:[t.jsx("thead",{children:t.jsx("tr",{children:e.head.map((n,s)=>t.jsx("th",{style:e.align[s]?{textAlign:e.align[s]}:void 0,children:Sr(n)},s))})}),t.jsx("tbody",{children:e.rows.map((n,s)=>t.jsx("tr",{children:n.map((r,a)=>t.jsx("td",{style:e.align[a]?{textAlign:e.align[a]}:void 0,children:Sr(r)},a))},s))})]})})}}function LC({text:e,what:n,always:s=!1}){const[r,a]=d.useState("idle"),i=()=>{var l;if(!((l=navigator.clipboard)!=null&&l.writeText)){a("failed");return}navigator.clipboard.writeText(e).then(()=>a("done"),()=>a("failed")),window.setTimeout(()=>a("idle"),1500)};return t.jsx("button",{type:"button",className:"wb-md-copy","data-state":r,"data-always":s||void 0,"aria-label":`Copy ${n}`,title:`Copy ${n}`,onClick:i,children:r==="done"?"Copied":r==="failed"?"Select to copy":t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 13 13","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"4.5",y:"4.5",width:"6.5",height:"6.5",rx:"1.2"}),t.jsx("path",{d:"M8.5 4.5V3a1 1 0 0 0-1-1H3a1 1 0 0 0-1 1v4.5a1 1 0 0 0 1 1h1.5"})]})})}function cG({handle:e}){const s=d.useContext(NM).find(r=>r.handle.toLowerCase()===e.toLowerCase());return s?t.jsxs(Au,{children:[t.jsx($u,{asChild:!0,children:t.jsxs("a",{className:"wb-mention-link",href:ut(s.id),children:["@",s.handle]})}),t.jsx(Tu,{children:t.jsxs(Ru,{className:"wb-agent-card",sideOffset:6,children:[t.jsx(Bn,{id:s.id,name:s.name,face:s,unavailable:!s.available}),t.jsxs("span",{className:"wb-agent-card-text",children:[t.jsx("span",{className:"wb-agent-card-name",children:s.name}),t.jsx("span",{className:"wb-agent-card-desc",children:s.description}),t.jsxs("span",{className:"wb-agent-card-meta",children:[s.model,s.available?"":" · unavailable"]})]})]})})]}):t.jsxs(t.Fragment,{children:["@",e]})}const uG=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 Sr(e){const n=[];let s=e,r=0;for(;s!=="";){const a=uG.exec(s);if(!a){n.push(...FC(s,r));break}a.index>0&&n.push(...FC(s.slice(0,a.index),r)),r+=100,a[2]!==void 0?n.push(t.jsx("code",{children:a[2]},r)):a[3]!==void 0?n.push(t.jsx("strong",{children:Sr(a[3])},r)):a[4]!==void 0?n.push(t.jsx("strong",{children:Sr(a[4])},r)):a[5]!==void 0?n.push(t.jsx("s",{children:Sr(a[5])},r)):a[6]!==void 0?n.push(t.jsx("em",{children:Sr(a[6])},r)):a[7]!==void 0?n.push(t.jsx("em",{children:Sr(a[7])},r)):a[8]!==void 0&&a[9]!==void 0?n.push(t.jsx("a",{href:a[9],target:"_blank",rel:"noopener noreferrer",children:Sr(a[8])},r)):a[10]!==void 0?n.push(t.jsx("a",{href:a[10],target:"_blank",rel:"noopener noreferrer",children:a[10]},r)):a[11]!==void 0&&n.push(t.jsx(cG,{handle:a[11]},r)),s=s.slice(a.index+a[0].length)}return n}function FC(e,n){return e.split(`
109
- `).flatMap((r,a)=>a===0?[r]:[t.jsx("br",{},`${n}-br-${a}`),r])}function dG({props:e}){return t.jsxs("div",{children:[e.title?t.jsx("h4",{className:"wb-doc-title",children:e.title}):null,e.metadata.length>0?t.jsx("dl",{className:"ui-kv wb-block",children:e.metadata.map(n=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:n.label}),t.jsx("dd",{children:Mn(n.value,n.unit,null)})]},n.label))}):null,e.kind==="image"&&e.src?t.jsx("img",{src:e.src,alt:e.title??"Attached image",className:"wb-doc-image"}):e.kind==="pdf"&&e.src?t.jsx("object",{data:e.src,type:"application/pdf",className:"wb-doc-pdf",children:t.jsx("a",{href:e.src,children:"Open the PDF"})}):e.text?t.jsx("div",{className:"wb-doc",children:t.jsx(pr,{text:e.text})}):t.jsx("p",{className:"wb-empty",children:"This document came back with no body."})]})}function hG({props:e,timezone:n="UTC",onDecided:s}){var y;const[r,a]=d.useState(null),[i,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(null);d.useEffect(()=>{let k=!1;return a(null),l(null),T.approval(e.approvalId).then(N=>{k||a(N)}).catch(N=>{k||l(N instanceof pe?N.message:String(N))}),()=>{k=!0}},[e.approvalId]);const{values:m,controls:f}=Ib(r==null?void 0:r.choices),p=(k,N)=>{h(k),l(null),(m&&k==="approve"?T.decide(e.approvalId,k,N,m):T.decide(e.approvalId,k,N)).then(b=>{a(b.action),s==null||s(b.action)}).catch(b=>l(b instanceof pe?b.message:String(b))).finally(()=>h(null))};if(i&&!r)return t.jsx("p",{className:"wb-empty",children:i});if(!r)return t.jsx("p",{className:"wb-empty",children:"Loading the envelope…"});const x=r.state==="pending",g=(y=r.permissionScopes)==null?void 0:y.includes("always"),w=fG(r),v=(r.preview??"").split(`
110
- `).length>12||(r.preview??"").length>900,j=[r.decidedBy?`by ${r.decidedBy}`:"",r.decidedVia?`via ${r.decidedVia}`:""].filter(Boolean).join(" ");return t.jsxs("div",{className:"wb-envelope",children:[t.jsxs("div",{className:"envelope",children:[t.jsxs("dl",{className:"envelope-head",children:[t.jsx("dt",{children:"Action"}),t.jsx("dd",{className:"wb-envelope-action",children:r.tool.split(".").map(k=>nn(k)).join(" · ")}),t.jsx("dt",{children:"Status"}),t.jsxs("dd",{children:[x?t.jsx($e,{tone:"warning",dot:!0,children:"waiting for you"}):t.jsx(wd,{state:r.state}),!x&&j?t.jsxs("span",{className:"wb-envelope-note",children:[" ",j]}):null]}),t.jsx("dt",{children:x?"Expires":"Decided"}),t.jsx("dd",{children:St(x?r.expiresAt:r.decidedAt,n)})]}),t.jsxs("div",{className:"envelope-body","data-clamp":v&&!o?"true":void 0,children:[r.preview||"(this tool wrote no preview)",v&&!o?t.jsx("button",{type:"button",className:"wb-doc-more",onClick:()=>c(!0),children:"Show the whole preview"}):null]})]}),t.jsx(re,{message:i}),x?f:null,x?t.jsxs("div",{className:"wb-envelope-decide",children:[t.jsx("p",{className:"wb-envelope-note",children:g?"Auto and Always also approve later calls to this tool in that scope; you can take it back on the agent's Tools tab.":"This runs the action exactly as shown above."}),t.jsxs("div",{className:"wb-envelope-buttons",children:[t.jsx("button",{className:"ui-btn","data-variant":"danger",disabled:u!==null,onClick:()=>p("reject"),children:u==="reject"?"Rejecting…":"Reject"}),g?t.jsxs(t.Fragment,{children:[t.jsx("button",{className:"ui-btn",disabled:u!==null,onClick:()=>p("approve","conversation"),children:"Auto: this conversation"}),t.jsx("button",{className:"ui-btn",disabled:u!==null,onClick:()=>p("approve","always"),children:"Always: this agent"})]}):null,t.jsx("button",{className:"ui-btn","data-variant":"good",disabled:u!==null,onClick:()=>p("approve"),children:u==="approve"?"Approving…":g?"Allow once":"Approve"})]})]}):null,t.jsxs("details",{className:"ui-details",children:[t.jsx("summary",{children:"The envelope, field by field"}),t.jsx("dl",{className:"ui-kv wb-envelope-fields",children:w.map(k=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:k.label}),k.block?t.jsx("dd",{className:"wb-envelope-block",children:t.jsx("pre",{className:"mono",children:k.value})}):t.jsx("dd",{className:k.mono?"mono":void 0,children:k.value})]},k.label))})]})]})}function fG(e){const n=[],s=e.envelope;if(s!==null&&typeof s=="object"&&!Array.isArray(s))for(const[a,i]of Object.entries(s))n.push(_C(nn(a),i));else s!=null&&n.push({label:"Envelope",value:ek(s)});const r=e.canonicalArgs;if(r!==null&&typeof r=="object"&&!Array.isArray(r))for(const[a,i]of Object.entries(r)){const l=`Argument · ${nn(a)}`;n.some(o=>o.label===l)||n.push(_C(l,i))}return n.push({label:"Action id",value:e.id,mono:!0},{label:"Tool version",value:e.toolVersion,mono:!0},{label:"Agent",value:e.agentId,mono:!0},{label:"Args hash",value:e.argsHash,mono:!0},{label:"Policy version",value:String(e.policyVersion)}),e.conversationId&&n.push({label:"Conversation",value:e.conversationId,mono:!0}),e.jobId&&n.push({label:"Job",value:e.jobId,mono:!0}),n}function _C(e,n){return n!==null&&typeof n=="object"&&(!Array.isArray(n)||n.some(r=>r!==null&&typeof r=="object"))?{label:e,value:JSON.stringify(n,null,2),block:!0}:{label:e,value:ek(n)}}function ek(e){return e==null?"—":Array.isArray(e)?e.map(n=>ek(n)).join(", ")||"—":typeof e=="object"?JSON.stringify(e):Mn(e,"text",null)}function mG({props:e}){const n=vP(e.artifactId),[s,r]=d.useState(null),[a,i]=d.useState(null),[l,o]=d.useState(!1);if(d.useEffect(()=>{if(n===null)return;let h=!0;return r(null),i(null),o(!1),T.libraryEntry(n).then(m=>{h&&r({filename:m.entry.filename,sizeBytes:m.entry.sizeBytes})}).catch(()=>{}),()=>{h=!1}},[n]),n===null)return t.jsx("p",{className:"wb-empty",children:"This result names no file in the Files library."});const c=e.title??(s==null?void 0:s.filename)??"Image",u=[a?`${a.width} × ${a.height}`:null,s!=null&&s.sizeBytes?Yn(s.sizeBytes):null].filter(h=>h!==null);return t.jsxs("figure",{className:"wb-image",children:[t.jsx("div",{className:"wb-image-frame",children:l?t.jsx("p",{className:"wb-empty",children:"This file cannot be shown here. Download it to open it."}):t.jsx("a",{href:Dr(n),className:"wb-image-link",title:"Open at full size",children:t.jsx("img",{src:Dr(n),alt:e.caption??c,onLoad:h=>{const m=h.currentTarget;m.naturalWidth>0&&i({width:m.naturalWidth,height:m.naturalHeight})},onError:()=>o(!0)})})}),t.jsxs("figcaption",{className:"wb-image-caption",children:[t.jsxs(te,{children:[t.jsx("span",{className:"wb-image-name",children:c}),u.length>0?t.jsx("span",{className:"wb-image-facts",children:u.join(" · ")}):null,t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx(it,{size:"sm",href:la(n),download:(s==null?void 0:s.filename)??c,children:"Download"})]}),e.caption&&e.captionLabel?t.jsx(Vt,{summary:e.captionLabel,className:"wb-image-note",children:t.jsx("p",{className:"wb-image-note-body",children:e.caption})}):e.caption?t.jsx("p",{className:"wb-image-note",children:e.caption}):null]})]})}function pG({props:e}){return e.pairs.length===0?t.jsx("p",{className:"wb-empty",children:"Nothing to show."}):t.jsx("dl",{className:"ui-kv",children:e.pairs.map(n=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:n.label}),t.jsx("dd",{className:"tnum",style:n.tone==="neutral"?void 0:{color:`var(--${n.tone})`},children:Mn(n.value,n.unit,n.currency)})]},n.label))})}const gG=8;function SM({text:e,label:n="Output",className:s}){const r=d.useRef(null),a=d.useRef(!0);return d.useLayoutEffect(()=>{const i=r.current;i&&a.current&&(i.scrollTop=i.scrollHeight)},[e]),t.jsx("pre",{ref:r,className:s?`wb-terminal-body ${s}`:"wb-terminal-body","aria-label":n,tabIndex:0,onScroll:i=>{const l=i.currentTarget;a.current=l.scrollHeight-l.scrollTop-l.clientHeight<=gG},children:e})}function xG(e){if(e<1e3)return`${Math.round(e)} ms`;const n=e/1e3;if(n<60)return`${n.toFixed(n<10?1:0)} s`;const s=Math.floor(n/60);return`${s} min ${Math.round(n-s*60)} s`}function jG({text:e}){const[n,s]=d.useState("");return t.jsxs(t.Fragment,{children:[n?t.jsx("span",{role:"status",className:"wb-hint",children:n}):null,t.jsx($,{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 vG({props:e}){const n=e.output??"";return t.jsxs("div",{className:"wb-terminal",children:[t.jsxs(te,{className:"wb-terminal-head",children:[e.command!==null?t.jsx("code",{className:"wb-terminal-command",title:e.command,children:e.command}):null,e.exitCode!==null?t.jsxs($e,{tone:e.exitCode===0?"good":"critical",mono:!0,children:["exit ",e.exitCode]}):null,e.elapsedMs!==null?t.jsx("span",{className:"wb-terminal-fact",children:xG(e.elapsedMs)}):null,t.jsx("span",{className:"ui-toolbar-spacer"}),n!==""?t.jsx(jG,{text:n}):null]}),e.omittedBytes!==null?t.jsxs("p",{className:"wb-terminal-note",children:["First ",Yn(e.omittedBytes)," not shown."]}):null,n!==""?t.jsx(SM,{text:n}):t.jsx("p",{className:"wb-empty",children:"No output."}),e.metadata.length>0?t.jsx("dl",{className:"ui-kv wb-terminal-facts",children:e.metadata.map(s=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:s.label}),t.jsx("dd",{children:Mn(s.value,s.unit,null)})]},s.label))}):null]})}function yG(){const e=window.location.hostname.replace(/^\[|\]$/g,"").toLowerCase();return e==="127.0.0.1"||e==="::1"||e==="localhost"}function zC(e){try{const n=new URL(e);return n.searchParams.delete("ticket"),n.toString()}catch{return e}}function wG(e){const n=new Set(e.ports??[]);return e.port!==null&&n.add(e.port),[...n].sort((s,r)=>s-r)}function bG({props:e}){var N;const[n,s]=d.useState(null),[r,a]=d.useState(null),[i,l]=d.useState(null),[o,c]=d.useState(!1),u=((N=e.target)==null?void 0:N.plugin)??null,h=wG(e),[m,f]=d.useState(null),p=m!==null&&h.includes(m)?m:e.port,x=e.target?p!==null&&p!==e.port?`${e.target.name}.${p}`:e.target.name:null,g=e.changes??0,w=d.useRef(g),[v,j]=d.useState(0);d.useEffect(()=>{g<=w.current||(w.current=g,e.reloadsItself||j(b=>b+1))},[g,e.reloadsItself]),d.useEffect(()=>{if(u===null||x===null)return;let b=!0;return s(null),a(null),l(null),j(0),T.previewLink(u,x).then(S=>{b&&(s(S.url),a(zC(S.url)))}).catch(S=>{b&&l(S instanceof Error?S.message:"That preview could not be opened.")}),()=>{b=!1}},[u,x]);const y=()=>{u===null||x===null||T.previewLink(u,x).then(b=>a(b.url)).catch(()=>{})};if(e.target===null)return t.jsxs("p",{className:"wb-empty",children:["This panel names no preview. A preview is ",t.jsx("code",{children:"/preview/<plugin>/<name>/"}),", and nothing else is framed here."]});const k=!(e.output===null||e.output==="");return t.jsxs("div",{className:"wb-preview","data-output":o||void 0,children:[t.jsxs("div",{className:"wb-row wb-preview-head",children:[e.title?t.jsx("h4",{className:"wb-doc-title",children:e.title}):null,h.length>1?t.jsx("select",{className:"wb-preview-port","aria-label":"Port",title:"The ports this process is listening on.",value:p??"",onChange:b=>f(Number(b.target.value)),children:h.map(b=>t.jsxs("option",{value:b,children:[":",b]},b))}):null,k?t.jsx("button",{type:"button",className:"ui-btn wb-preview-toggle","data-variant":"ghost","data-size":"sm","aria-pressed":o,onClick:()=>c(b=>!b),children:o?"Hide output":"Output"}):null,r?t.jsx("a",{className:"wb-preview-open",href:r,target:"_blank",rel:"noreferrer noopener",onPointerEnter:y,onFocus:y,title:"Through buddi: works from anywhere the dashboard does, including the tailnet.",children:"Open in a tab"}):null,p!==null&&yG()?t.jsxs("a",{className:"wb-preview-direct",href:`http://localhost:${p}/`,target:"_blank",rel:"noreferrer noopener",title:"The process itself, on this machine only.",children:["localhost:",p]}):null]}),t.jsxs("div",{className:"wb-preview-body",children:[n?t.jsx("iframe",{className:"wb-preview-frame",src:v===0?n:zC(n),title:e.title??"Preview",sandbox:"allow-scripts allow-forms allow-same-origin allow-modals allow-downloads"},v):t.jsx("p",{className:"wb-empty wb-preview-frame",children:i??"Opening the preview…"}),k&&o?t.jsx(SM,{text:e.output??"",className:"wb-preview-output"}):null]})]})}function kG({props:e}){const n=e.groups.every(s=>s.rows.length===0);return t.jsxs("div",{children:[e.summary.length>0?t.jsx("div",{className:"ui-stats","data-inline":"true",children:e.summary.map(s=>t.jsxs("div",{children:[t.jsx("div",{className:"ui-stat-k",children:s.label}),t.jsx("div",{className:"ui-stat-v","data-tone":s.tone,children:Mn(s.value,s.unit,s.currency)})]},s.label))}):null,n?t.jsx("p",{className:"wb-empty",children:e.empty}):e.groups.map((s,r)=>t.jsxs("div",{className:r>0?"wb-section":void 0,children:[s.label?t.jsx("h4",{className:"ui-stat-k wb-label",children:s.label}):null,t.jsx("div",{className:"ui-table-wrap",children:t.jsxs("table",{className:"ui-table",children:[t.jsx("thead",{children:t.jsx("tr",{children:e.columns.map(a=>t.jsx("th",{className:CM(a.type)?"num":void 0,"data-type":a.type,children:a.label},a.key))})}),t.jsx("tbody",{children:s.rows.map((a,i)=>t.jsx("tr",{children:a.map((l,o)=>{var c;return t.jsx(NG,{cell:l},((c=e.columns[o])==null?void 0:c.key)??o)})},i))})]})})]},s.label??r))]})}function NG({cell:e}){const n=Mn(e.value,e.type,e.currency);return e.bar?t.jsx("td",{className:"num",children:t.jsxs("div",{className:"wb-row wb-row-end",children:[t.jsx("div",{className:"ui-meter",role:"meter","aria-valuenow":Math.round(e.bar.fraction*100),"aria-valuemin":0,"aria-valuemax":100,"aria-label":n,children:t.jsx("div",{className:"ui-meter-fill","data-tone":e.bar.tone,style:{width:`${Math.round(e.bar.fraction*100)}%`}})}),t.jsx("span",{className:"tnum",children:n})]})}):t.jsx("td",{className:CM(e.type)?"num":void 0,"data-type":e.type,title:n.length>40?n:void 0,children:n})}function CM(e){return e==="number"||e==="currency"||e==="percent"}const _l=760,Hg=400,xn={top:18,right:18,bottom:36,left:66},SG=5;function CG({props:e}){const{points:n,referenceLines:s,unit:r,currency:a}=e;if(n.length===0)return t.jsx("p",{className:"wb-empty",children:"This result carried no points to plot."});const i=[...n.map(k=>k.y),...s.map(k=>k.value)],l=Math.min(...i),o=Math.max(...i),c=o-l||Math.abs(o)||1,u=l-c*.08,h=o+c*.08,m=_l-xn.left-xn.right,f=Hg-xn.top-xn.bottom,p=k=>xn.left+(n.length===1?m/2:k/(n.length-1)*m),x=k=>xn.top+f-(k-u)/(h-u)*f,g=zf(l,o,4),w=AG(n.map(k=>k.y),e.mark),v=e.shadeBelow===null?[]:$G(n.map(k=>k.y),e.shadeBelow),j=n.map((k,N)=>`${N===0?"M":"L"}${p(N)},${x(k.y)}`).join(" "),y=k=>Mn(k,r,a);return t.jsxs("div",{children:[e.label?t.jsx("p",{className:"ui-panel-sub",children:e.label}):null,t.jsxs("div",{className:"wb-chart-layout",children:[t.jsx("div",{className:"wb-chart-plot",children:t.jsxs("svg",{className:"wb-chart",viewBox:`0 0 ${_l} ${Hg}`,role:"img","aria-label":EG(e,y),preserveAspectRatio:"xMidYMid meet",children:[v.map(k=>t.jsx("rect",{className:"wb-chart-breach",x:p(k.from),width:Math.max(2,p(k.to)-p(k.from)),y:xn.top,height:f},`band-${k.from}`)),g.map(k=>t.jsxs("g",{children:[t.jsx("line",{className:"wb-chart-grid",x1:xn.left,x2:_l-xn.right,y1:x(k),y2:x(k)}),t.jsx("text",{x:xn.left-8,y:x(k)+4,textAnchor:"end",children:y(k)})]},`tick-${k}`)),s.map(k=>t.jsxs("g",{children:[t.jsx("line",{className:"wb-chart-floor",x1:xn.left,x2:_l-xn.right,y1:x(k.value),y2:x(k.value)}),t.jsxs("text",{x:_l-xn.right,y:x(k.value)-6,textAnchor:"end",children:[k.label," ",y(k.value)]})]},`rule-${k.label}`)),t.jsx("line",{className:"wb-chart-axis",x1:xn.left,x2:xn.left,y1:xn.top,y2:xn.top+f}),t.jsx("line",{className:"wb-chart-axis",x1:xn.left,x2:_l-xn.right,y1:xn.top+f,y2:xn.top+f}),t.jsx("path",{className:"wb-chart-series",d:j}),w!==null?t.jsxs("g",{children:[t.jsx("circle",{className:"wb-chart-min",cx:p(w),cy:x(n[w].y),r:4.5}),t.jsx("text",{x:p(w),y:x(n[w].y)+20,textAnchor:"middle",children:y(n[w].y)})]}):null,TG(n.length).map(k=>t.jsx("text",{x:p(k),y:Hg-10,textAnchor:"middle",children:tv(n[k].x)},`x-${k}`))]})}),e.events.length>0?t.jsxs("aside",{className:"wb-chart-events",children:[t.jsx("h4",{className:"ui-stat-k wb-label",children:"What happens"}),t.jsx("ul",{className:"wb-chart-event-list",children:e.events.map((k,N)=>t.jsxs("li",{className:"wb-chart-event",children:[t.jsxs("span",{children:[t.jsx("span",{className:"wb-chart-event-day",children:tv(k.at)}),k.label]}),k.amount===null?null:t.jsx("span",{className:k.amount<0?"tnum critical":"tnum good",children:Mn(k.amount,r,a)})]},`${k.at}-${k.label}-${N}`))})]}):null]})]})}function EG(e,n){const s=e.points.map(l=>l.y),r=e.points[0],a=e.points[e.points.length-1],i=e.referenceLines.map(l=>`${l.label} at ${n(l.value)}`).join(", ");return[`${e.points.length} points from ${r==null?void 0:r.x} to ${a==null?void 0:a.x}`,`low ${n(Math.min(...s))}, high ${n(Math.max(...s))}`,i].filter(Boolean).join("; ")}function AG(e,n){if(!n||e.length===0)return null;let s=0;for(let r=1;r<e.length;r+=1)(n==="min"?e[r]<e[s]:e[r]>e[s])&&(s=r);return s}function $G(e,n){const s=[];let r=null;return e.forEach((a,i)=>{a<n?r===null&&(r=i):r!==null&&(s.push({from:r,to:i}),r=null)}),r!==null&&s.push({from:r,to:e.length-1}),s}function TG(e,n=SG){if(e<=0)return[];if(e<=n)return[...Array(e).keys()];const s=e-1,r=new Set;for(let a=0;a<n;a+=1)r.add(Math.round(a/(n-1)*s));return[...r].sort((a,i)=>a-i)}const os=e=>e,Mv={timeseries:os(CG),table:os(kG),bars:os(nG),keyvalue:os(pG),tiles:os(SP),document:os(dG),diff:os(oG),terminal:os(vG),image:os(mG),preview:os(bG),envelope:os(hG),story:os(eG),audio:os(JV),query:os(XV),structured:os($l)},RG="structured";function IG(e){return(rm(e)?Mv[e]:void 0)??Mv[RG]}function rm(e){return Object.prototype.hasOwnProperty.call(Mv,e)}function PG({renderer:e,props:n,timezone:s,onDecided:r}){const a=IG(e),l=rm(e)?n:{value:n};return t.jsx(a,{props:l,timezone:s,onDecided:r})}function wi(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}const MG=["preferredName","displayName","fullName","name","title","label","subject","username","email"],OG=/^(name|title|label|subject|displayName|display_name|heading)$/i,DG=/^(url|link|href|uri|permalink)$/i,LG=/^(id|uuid|_id)$|(Id|_id)$/;function Ov(e){return e===null||["string","number","boolean"].includes(typeof e)}function tk(e){return MG.find(n=>typeof e[n]=="string"&&e[n].trim()!=="")??null}const FG=6;function EM(e){let n=e,s=null,r=[];if(wi(e)){const c=Object.entries(e).filter(([,h])=>Array.isArray(h)),u=Object.entries(e).filter(([,h])=>!Array.isArray(h));if(c.length!==1||!u.every(([,h])=>Ov(h)))return null;[s,n]=[nn(c[0][0]),c[0][1]],r=u.filter(([,h])=>!oa(h))}if(!Array.isArray(n)||n.length===0||!n.every(wi))return null;const a=n,i=[...new Set(a.flatMap(c=>Object.keys(c)))];if(i.length>FG||i.some(c=>DG.test(c)))return null;const l=i.find(c=>OG.test(c)&&a.filter(u=>typeof u[c]=="string").length>=a.length*.8);if(!l)return null;const o=i.filter(c=>c!==l&&!LG.test(c)).filter(c=>a.some(u=>Ov(u[c])&&!oa(u[c]))).sort((c,u)=>UC(a,u)-UC(a,c)).slice(0,2);return{label:s,rows:a,name:l,facts:o,extras:r}}function UC(e,n){return e.filter(s=>!oa(s[n])).length}function _G(e){return wi(e)&&tk(e)!==null&&Object.keys(e).length>=3}const zG=60;function UG(e){if(!wi(e))return!1;const n=Object.values(e);return n.length>=2&&n.every(s=>Ov(s)&&(typeof s!="string"||s.length<=zG))}const BG=[{name:"items",matches:e=>EM(e)!==null},{name:"profile",matches:_G},{name:"settings",matches:UG},{name:"fields",matches:e=>wi(e)&&Object.keys(e).length>0}];function WG(e){var n;return((n=BG.find(s=>s.matches(e)))==null?void 0:n.name)??"other"}const AM=8,HG=32,KG=/^\d{4}-\d{2}-\d{2}$/,VG=/^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?$/,GG=/^[a-z]+([_-][a-z]+)*$/,qG=/(name|title|label|email|subject|text|note|message|description|summary|path|file)$/i;function $M(e,n){if(oa(n))return{kind:"empty"};if(typeof n=="boolean")return{kind:"boolean",value:n};if(typeof n=="number")return{kind:"number",value:n};if(typeof n=="string"){const s=n.trim();return KG.test(s)?{kind:"day",value:s}:VG.test(s)&&!Number.isNaN(Date.parse(s))?{kind:"moment",value:s}:/^https?:\/\/\S+$/i.test(s)?{kind:"link",value:s}:s.length<=24&&GG.test(s)&&!qG.test(e)?{kind:"enum",value:s}:{kind:"text",value:n}}return Array.isArray(n)?n.length<=AM&&n.every(s=>typeof s=="string"&&s.length<=HG)?{kind:"chips",values:n}:{kind:"rows",values:n}:wi(n)?{kind:"group",value:n}:{kind:"text",value:String(n)}}function YG({value:e,title:n,tool:s,face:r,timezone:a}){const[i,l]=d.useState(!1),o=kp(e)||QG(e)?"other":WG(e);return t.jsxs("div",{className:"wb-result","data-testid":"tool-result","data-view":o,children:[t.jsxs("header",{className:"ui-panel-head wb-result-head",children:[r?t.jsx("span",{className:"wb-result-face","aria-hidden":"true",children:r}):null,t.jsx("h2",{className:"ui-panel-title wb-result-title",title:s,children:n}),t.jsx(rs,{label:`More for ${n}`,items:[{label:i?"Show readable":"Raw JSON",onSelect:()=>l(c=>!c)}]})]}),i?t.jsx("pre",{className:"ui-code",children:ms(e)}):t.jsx(JG,{view:o,value:e,timezone:a})]})}function QG(e){return wi(e)&&Array.isArray(e.artifacts)}function JG({view:e,value:n,timezone:s}){switch(e){case"items":return t.jsx(ZG,{shape:EM(n),timezone:s});case"profile":return t.jsx(XG,{value:n,timezone:s});case"settings":return t.jsx(e7,{value:n,timezone:s});case"fields":return t.jsx(nk,{value:n,timezone:s,depth:0});default:return t.jsx($l,{props:{value:n},bare:!0})}}function XG({value:e,timezone:n}){const s=tk(e),r=Object.fromEntries(Object.entries(e).filter(([a])=>a!==s));return t.jsxs("div",{className:"wb-result-profile",children:[t.jsxs("p",{className:"wb-result-lead",children:[t.jsx("span",{className:"wb-result-lead-k",children:nn(s)}),t.jsx("span",{className:"wb-result-lead-v",children:String(e[s])})]}),t.jsx(nk,{value:r,timezone:n,depth:0})]})}function ZG({shape:e,timezone:n}){const[s,r]=d.useState(!1),a=e.rows.length<=25?e.rows.length:20,i=s?e.rows:e.rows.slice(0,a);return t.jsxs("div",{className:"wb-result-items",children:[e.label||e.extras.length?t.jsxs("p",{className:"wb-result-items-head",children:[e.label?t.jsx("span",{className:"wb-result-items-label",children:e.label}):null,e.extras.map(([l,o])=>t.jsxs("span",{className:"wb-result-items-extra",children:[nn(l)," ",t.jsx(Do,{field:l,value:o,timezone:n})]},l))]}):null,t.jsx("ul",{className:"wb-result-rows",children:i.map((l,o)=>t.jsxs("li",{className:"wb-result-row",children:[t.jsx("span",{className:"wb-result-row-name",children:String(l[e.name]??"—")}),e.facts.length?t.jsx("span",{className:"wb-result-row-facts",children:e.facts.filter(c=>l[c]!==void 0&&l[c]!==null&&l[c]!=="").map(c=>t.jsx("span",{className:"wb-result-row-fact",title:nn(c),children:t.jsx(Do,{field:c,value:l[c],timezone:n})},c))}):null]},o))}),e.rows.length>i.length?t.jsxs("p",{className:"wb-note wb-note-row",children:[t.jsxs("span",{children:["Showing ",i.length," of ",e.rows.length]}),t.jsxs("button",{type:"button",className:"ui-btn","data-size":"sm",onClick:()=>r(!0),children:["Show all ",e.rows.length]})]}):null]})}function e7({value:e,timezone:n}){return t.jsx("dl",{className:"wb-result-settings",children:Object.entries(e).map(([s,r])=>t.jsxs("div",{className:"wb-result-setting",children:[t.jsx("dt",{children:nn(s)}),t.jsx("dd",{children:t.jsx(Do,{field:s,value:r,timezone:n})})]},s))})}const t7=3;function nk({value:e,timezone:n,depth:s}){const r=Object.entries(e);return r.length===0?t.jsx("p",{className:"wb-note",children:"Nothing to show."}):t.jsx("dl",{className:"wb-result-grid",children:r.map(([a,i])=>{const l=$M(a,i);if(l.kind==="group"){const o=Object.keys(l.value).length;return t.jsx("div",{className:"wb-result-group",children:t.jsx(Vt,{summary:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"wb-result-group-k",children:nn(a)})," ",t.jsxs("span",{className:"wb-result-group-n",children:[o," ",o===1?"field":"fields"]})]}),open:s===0&&o<=4,children:s+1>=t7?t.jsx("pre",{className:"ui-code",children:ms(l.value)}):t.jsx(nk,{value:l.value,timezone:n,depth:s+1})})},a)}return t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:nn(a)}),t.jsx("dd",{children:t.jsx(Do,{field:a,value:i,timezone:n})})]},a)})})}function Do({field:e,value:n,timezone:s}){const r=$M(e,n);switch(r.kind){case"empty":return t.jsx("span",{className:"wb-result-empty",children:Array.isArray(n)?"None":"—"});case"boolean":return t.jsx($e,{tone:r.value?"good":void 0,dot:!0,children:r.value?"Yes":"No"});case"number":return t.jsx("span",{className:"tnum",children:Number.isInteger(r.value)?Cn(r.value):String(Math.round(r.value*100)/100)});case"day":return t.jsx("span",{children:Zo(r.value,{year:!0})});case"moment":return t.jsx("time",{dateTime:r.value,children:St(r.value,s)});case"link":return t.jsx("a",{href:r.value,target:"_blank",rel:"noopener noreferrer",children:r.value});case"enum":return t.jsx($e,{children:r.value.replace(/_/g," ")});case"text":return t.jsx("span",{className:"wb-result-text",children:r.value});case"chips":return t.jsx("span",{className:"wb-result-chips",children:r.values.map((a,i)=>t.jsx($e,{children:a},`${a}-${i}`))});case"rows":return t.jsx(n7,{values:r.values,timezone:s});case"group":return t.jsxs("span",{className:"wb-result-empty",children:[Object.keys(r.value).length," fields"]})}}function n7({values:e,timezone:n}){const[s,r]=d.useState(!1),a=s?e:e.slice(0,AM);return t.jsxs("span",{className:"wb-result-compact",children:[t.jsx("ul",{children:a.map((i,l)=>t.jsx("li",{children:s7(i,n)},l))}),e.length>a.length?t.jsxs("button",{type:"button",className:"ui-btn","data-variant":"ghost","data-size":"sm",onClick:()=>r(!0),children:[e.length-a.length," more"]}):null]})}function s7(e,n){if(wi(e)){const s=tk(e),r=Object.entries(e).filter(([a,i])=>a!==s&&(typeof i=="string"||typeof i=="number"||typeof i=="boolean")).slice(0,2);return t.jsxs(t.Fragment,{children:[s?t.jsx("span",{className:"wb-result-row-name",children:String(e[s])}):null,r.map(([a,i])=>t.jsxs("span",{className:"wb-result-row-fact",title:nn(a),children:[" ",t.jsx(Do,{field:a,value:i,timezone:n})]},a))]})}return t.jsx(Do,{field:"",value:e,timezone:n})}function r7({profile:e,onChange:n}){return t.jsxs("div",{className:"wb-prof","data-testid":"agent-profile",children:[t.jsx("p",{className:"wb-prof-lead",children:e.description}),t.jsxs("div",{className:"wb-prof-tags",children:[e.isDefault?t.jsx(Kg,{children:"Opens by default"}):null,t.jsx(Kg,{children:e.source==="example"?"Shipped with buddi":"Yours"}),e.roles.map(s=>t.jsx(Kg,{title:`A surface command that asks for "${s}" lands on this agent.`,children:nn(s)},s))]}),e.available?null:t.jsxs("p",{className:"wb-prof-blocked","data-testid":"agent-profile-unavailable",children:[t.jsx("strong",{children:"This agent cannot run here."})," ",e.unavailableReason]}),(e.disabled??[]).map(s=>t.jsx("p",{className:"wb-prof-blocked","data-testid":"agent-profile-disabled",children:s},s)),t.jsx($c,{title:"How it works with you",note:"Live decisions stay in the conversation; this page explains the standing rules.",children:t.jsxs("ul",{className:"wb-prof-list",children:[t.jsxs("li",{className:"wb-prof-row",children:[t.jsxs("span",{className:"wb-prof-row-main",children:[t.jsx("span",{className:"wb-prof-row-name",children:"Quick questions"}),t.jsx("span",{className:"wb-prof-row-desc",children:"When it knows the likely answers, it can show one-tap choices in the dashboard and Telegram. You can still write a different answer when the question allows it."})]}),t.jsx("span",{className:"wb-prof-auto",children:"Answers only"})]}),t.jsxs("li",{className:"wb-prof-row","data-gated":"true",children:[t.jsxs("span",{className:"wb-prof-row-main",children:[t.jsx("span",{className:"wb-prof-row-name",children:"Action approvals"}),t.jsx("span",{className:"wb-prof-row-desc",children:"A request to send, spend, publish or otherwise affect the world appears in the conversation with the exact action. Answering a question never approves it."})]}),t.jsxs("span",{className:"wb-prof-gate",children:[t.jsx(TM,{}),"Exact action"]})]})]})}),t.jsx($c,{title:"What it can do",note:a7(e),tone:e.gatedCount>0?"warning":void 0,children:e.tools.length===0?t.jsx("p",{className:"wb-prof-empty",children:"No tools at all. It answers from the conversation and from what it remembers, and it can change nothing."}):[...e.tools].sort((s,r)=>+(r.gated>0)-+(s.gated>0)).map(s=>t.jsx(i7,{family:s},s.family))}),t.jsx($c,{title:"What it runs on",children:t.jsxs("dl",{className:"wb-prof-kv",children:[t.jsx(Tc,{label:"Provider",children:e.engine.provider}),t.jsx(Tc,{label:"Model",children:t.jsx("span",{className:"mono",children:e.engine.model})}),t.jsxs(Tc,{label:"Credential",children:[e.engine.credentialKind," from"," ",t.jsx("span",{className:"mono",children:e.engine.credentialEnv})]}),t.jsxs(Tc,{label:"Turn budget",children:[e.engine.maxTurns," ",e.engine.maxTurns===1?"turn":"turns"," per message"]}),t.jsx(Tc,{label:"Language",children:d7(e.engine.language)})]})}),e.skills.length>0?t.jsx($c,{title:"What it has read",note:`${e.skills.length} ${e.skills.length===1?"skill":"skills"}, composed into every run`,children:t.jsx("ul",{className:"wb-prof-list",children:e.skills.map(s=>t.jsxs("li",{className:"wb-prof-row",children:[t.jsxs("span",{className:"wb-prof-row-main",children:[t.jsx("span",{className:"wb-prof-row-name mono",children:s.name}),s.description?t.jsx("span",{className:"wb-prof-row-desc",children:s.description}):null]}),t.jsxs("span",{className:"wb-prof-row-side",title:s.file,children:[s.scope==="private"?"its own":"shared"," · ",s.provenance]})]},s.file))})}):null,e.delegates.length>0?t.jsx($c,{title:"Who it can hand work to",note:"A colleague's tools are reached through the colleague, never held here",children:t.jsx("ul",{className:"wb-prof-list",children:e.delegates.map(s=>t.jsxs("li",{className:"wb-prof-row",children:[t.jsxs("span",{className:"wb-prof-row-main",children:[t.jsxs("span",{className:"wb-prof-row-name mono",children:["@",s.handle]}),t.jsx("span",{className:"wb-prof-row-desc",children:s.description})]}),t.jsx("span",{className:"wb-prof-row-side",children:s.available?s.name:`${s.name} · cannot run`})]},s.id))})}):null,t.jsxs("footer",{className:"wb-prof-foot",children:[t.jsx("p",{className:"wb-prof-note",children:e.note}),t.jsx("p",{className:"wb-prof-file mono",title:e.file,children:e.file}),e.changeVia&&n?t.jsxs("button",{className:"ui-btn","data-testid":"agent-profile-change",title:e.changeVia.prompt,onClick:()=>n({agentId:e.changeVia.agentId,prompt:e.changeVia.prompt}),children:["Ask @",e.changeVia.handle," to change this"]}):null]})]})}function a7(e){if(e.toolCount===0)return"Nothing. This agent holds no tools.";const n=`${e.toolCount} ${e.toolCount===1?"tool":"tools"}`;if(e.gatedCount===0)return`${n}, every one of them running without asking you. None of them can send, spend or write to the world.`;const s=e.gatedCount===1?"one of them stops and waits for you":`${e.gatedCount} of them stop and wait for you`;return`${n}, and ${s}.`}function i7({family:e}){const n=[...e.tools].sort((s,r)=>Number(r.gated)-Number(s.gated));return t.jsxs("section",{className:"wb-prof-family",children:[t.jsxs("h4",{className:"wb-prof-family-head",children:[t.jsx("span",{className:"wb-prof-family-name",children:nn(e.family)}),t.jsxs("span",{className:"wb-prof-family-note",children:[e.tools.length," ",e.tools.length===1?"tool":"tools",e.gated>0?` · ${e.gated} needs you`:""]})]}),t.jsx("ul",{className:"wb-prof-list",children:n.map(s=>t.jsx(l7,{tool:s},s.name))})]})}function l7({tool:e}){return t.jsxs("li",{className:"wb-prof-row","data-gated":e.gated?"true":void 0,"data-testid":"agent-profile-tool",children:[t.jsxs("span",{className:"wb-prof-row-main",children:[t.jsx("span",{className:"wb-prof-row-name mono",children:u7(e.name)}),t.jsx("span",{className:"wb-prof-row-desc","data-clamp":"true",title:e.description,children:e.description})]}),e.gated?t.jsxs("span",{className:"wb-prof-gate",title:"The call is recorded and waits; nothing happens until you approve it.",children:[t.jsx(TM,{}),"Needs your approval"]}):t.jsx("span",{className:"wb-prof-auto",title:c7(e.tier),children:o7(e.tier)})]})}function o7(e){return e==="auto"?"Runs on its own":e==="gated"?"Needs your approval":"Not runnable here"}function c7(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 u7(e){const n=e.split(".");return(n[n.length-1]??e).replace(/_/g," ")}function d7(e){return e==="mirror"?"Mirrors whichever language you write in":e==="en"?"Always English":e==="fr"?"Always French":e}function $c({title:e,note:n,tone:s,children:r}){return t.jsxs("section",{className:"wb-prof-section",children:[t.jsx("h3",{className:"wb-prof-title",children:e}),n?t.jsx("p",{className:"wb-prof-note-lead","data-tone":s,children:n}):null,r]})}function Tc({label:e,children:n}){return t.jsxs(t.Fragment,{children:[t.jsx("dt",{className:"wb-prof-k",children:e}),t.jsx("dd",{className:"wb-prof-v",children:n})]})}function Kg({children:e,title:n}){return t.jsx("span",{className:"wb-prof-tag",title:n,children:e})}function TM(){return t.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 14 14","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"2.8",y:"6",width:"8.4",height:"6.2",rx:"1.4"}),t.jsx("path",{d:"M4.8 6V4.4a2.2 2.2 0 0 1 4.4 0V6"})]})}const Vg=1e5,Gg=200,qg=30;function RM({artifactId:e,filename:n,mime:s,family:r,available:a=!0}){const[i,l]=d.useState(!1);return a?r==="image"&&!i?t.jsx("figure",{className:"file-preview file-preview-image",children:t.jsx("img",{src:Dr(e),alt:n??"Image",onError:()=>l(!0)})}):r==="audio"&&mp(s)?t.jsx("div",{className:"file-preview file-preview-audio",children:t.jsx(pp,{artifactId:e,name:n??"Audio",mime:s})}):r==="pdf"?t.jsx("div",{className:"file-preview file-preview-pdf",children:t.jsx("object",{data:Dr(e),type:"application/pdf","aria-label":n??"PDF",children:t.jsx(Q,{children:"Your browser cannot show this PDF here. Download it to open it."})})}):r==="text"||r==="code"||r==="table"?t.jsx(h7,{artifactId:e,filename:n,mime:s,family:r}):t.jsx(Q,{children:"Preview not supported for this kind of file. Download it to open it."}):t.jsx(Q,{children:"The file is no longer available; its record is kept."})}function h7({artifactId:e,filename:n,mime:s,family:r}){const[a,i]=d.useState("loading");if(d.useEffect(()=>{let o=!1;return i("loading"),fetch(Dr(e),{credentials:"same-origin"}).then(async c=>{if(!c.ok)throw new Error(String(c.status));const u=await c.text();o||i({text:u.slice(0,Vg),truncated:c.headers.get("X-Preview-Truncated")==="1"||u.length>Vg})}).catch(()=>{o||i("failed")}),()=>{o=!0}},[e]),a==="loading")return t.jsx("div",{className:"file-preview",children:t.jsx(Ee,{children:"Loading preview…"})});if(a==="failed")return t.jsx(Q,{children:"The preview could not be loaded. Download the file to open it."});const l=r==="table"&&(/csv|tab-separated/.test(s)||/\.(csv|tsv)$/i.test(n??""));return t.jsxs("div",{className:"file-preview",children:[l?t.jsx(m7,{text:a.text,delimiter:/tab|\.tsv$/i.test(s+(n??""))?" ":","}):t.jsx("pre",{className:"file-preview-text",children:a.text}),a.truncated?t.jsxs("p",{className:"muted",children:["Showing the first ",Vg.toLocaleString()," characters. The download has the whole file."]}):null]})}function f7(e,n,s,r){const a=[];let i=[],l="",o=!1,c=!1,u=!1;const h=()=>{i.length<r?i.push(l):c=!0,l=""},m=()=>{h(),a.push(i),i=[]};let f=0;for(;f<e.length;f+=1){if(a.length>=s){u=e.slice(f).trim()!=="";break}const p=e[f];if(o){p==='"'?e[f+1]==='"'?(l+='"',f+=1):o=!1:l+=p;continue}if(p==='"'){o=!0;continue}if(p===n){h();continue}if(p!=="\r"){if(p===`
111
- `){m();continue}l+=p}}return a.length<s&&(l!==""||i.length>0)&&m(),{rows:a,truncatedRows:u,truncatedCols:c}}function m7({text:e,delimiter:n}){const s=d.useMemo(()=>f7(e,n,Gg+1,qg),[e,n]),[r,...a]=s.rows;if(!r)return t.jsx("p",{className:"muted",children:"The file is empty."});const i=Math.min(qg,s.rows.reduce((o,c)=>Math.max(o,c.length),0)),l=Array.from({length:i},(o,c)=>c);return t.jsxs("div",{className:"ui-table-wrap file-preview-table",children:[t.jsxs("table",{className:"ui-table",children:[t.jsx("thead",{children:t.jsx("tr",{children:l.map(o=>t.jsx("th",{children:r[o]??""},o))})}),t.jsx("tbody",{children:a.slice(0,Gg).map((o,c)=>t.jsx("tr",{children:l.map(u=>t.jsx("td",{children:o[u]??""},u))},c))})]}),s.truncatedRows||s.truncatedCols?t.jsxs("p",{className:"muted",children:["Showing the first ",Gg," rows",s.truncatedCols?` and ${qg} columns`:"",". The download has the whole file."]}):null]})}function p7(e,n){const s=e.toLowerCase().split(";")[0].trim(),r=(n??"").toLowerCase().split(".").pop()??"";return s==="text/markdown"||s==="text/x-markdown"||s==="text/plain"&&(r==="md"||r==="markdown")?[{format:"pdf",label:"PDF",hint:".pdf"},{format:"docx",label:"Word",hint:".docx"},{format:"md",label:"Markdown",hint:".md, as written",asWritten:!0}]:s==="text/csv"||s==="text/plain"&&r==="csv"?[{format:"xlsx",label:"Excel",hint:".xlsx"},{format:"csv",label:"CSV",hint:".csv, as written",asWritten:!0}]:[]}function g7(e,n){return`/api/artifacts/${encodeURIComponent(e)}/export/${n}`}function x7(e,n){return`${(e??"document").replace(/\.[a-z0-9]{1,8}$/i,"")||"document"}.${n}`}function BC(e,n){const s=document.createElement("a");s.href=e,s.download=n,s.rel="noopener",document.body.appendChild(s),s.click(),s.remove()}function IM({artifactId:e,filename:n,mime:s,accent:r=!0}){const a=n??"download",i=p7(s,n),l=r?"accent":void 0;if(i.length===0)return t.jsx("a",{className:"ui-btn","data-variant":l,href:la(e),download:a,children:"Download"});const o=i.filter(h=>!h.asWritten),c=i.filter(h=>h.asWritten),u=h=>({label:h.label,hint:h.hint,onSelect:()=>h.asWritten?BC(la(e),a):BC(g7(e,h.format),x7(n,h.format))});return t.jsx(rs,{label:`Download ${a}`,note:"Download as",items:[...o.map(u),"separator",...c.map(u)],trigger:t.jsxs("button",{type:"button",className:"ui-btn","data-variant":l,"aria-label":`Download ${a}`,children:["Download ",t.jsx(ne,{name:"chevron-down"})]})})}function j7({attachment:e}){const n=Eb(e.mime,e.filename);return t.jsxs("div",{className:"wb-artifact","data-family":n,"data-testid":"artifact-view",children:[t.jsx(RM,{artifactId:e.artifactId,filename:e.filename??null,mime:e.mime,family:n}),t.jsxs("dl",{className:"ui-kv",children:[t.jsx("dt",{children:"Type"}),t.jsxs("dd",{children:[sl[n],t.jsx("span",{className:"wb-artifact-mime mono",children:e.mime})]}),e.sizeBytes?t.jsxs(t.Fragment,{children:[t.jsx("dt",{children:"Size"}),t.jsx("dd",{children:Yn(e.sizeBytes)})]}):null,t.jsx("dt",{children:"Id"}),t.jsx("dd",{className:"mono",children:e.artifactId})]}),t.jsx("div",{className:"ui-toolbar","data-align":"end",children:t.jsx(IM,{artifactId:e.artifactId,filename:e.filename,mime:e.mime})})]})}const WC=80,v7=["query","path","url","dir"],y7=["message","task"];function sk(e,n){const s=w7(n);if(!s)return null;const r=zl(s.command);if(r!==null){const l=zl(s.name);return xh(l===null?r:`${l}: ${r}`)}for(const l of v7){const o=zl(s[l]);if(o!==null)return xh(o)}const a=zl(s.action);if(a!==null){const l=y7.map(o=>zl(s[o])).find(o=>o!==null)??null;return xh(l===null?a:`${a} · ${l}`)}const i=Object.values(s).filter(l=>typeof l=="string");return i.length===1?xh(zl(i[0])):null}function zl(e){if(typeof e!="string")return null;const n=e.replace(/\s+/g," ").trim();return n===""?null:n}function xh(e){return e===null?null:e.length>WC?`${e.slice(0,WC-1)}…`:e}function w7(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function b7({text:e}){const s=e.indexOf(`
112
-
113
- The material this mission reads first`),r=/<DATA-([a-f0-9]+)>/.exec(e.slice(s));return s<0||!r||!e.includes(`</DATA-${r[1]}>`)?t.jsx(t.Fragment,{children:e}):t.jsxs(t.Fragment,{children:[e.slice(0,s),t.jsxs("details",{className:"wb-mission-material",children:[t.jsx("summary",{children:"Mission material · supplied to the agent"}),t.jsx("pre",{children:e.slice(s+2)})]})]})}const PM="owner.notify",ba=e=>typeof e=="string"&&e.trim()!==""?e:null;function k7(e){const n=e!==null&&typeof e=="object"?e:{};return{title:ba(n.title)??"(no title)",text:ba(n.text),urgency:ba(n.urgency)??"now",key:ba(n.key),link:ba(n.link)}}function MM(e){if(e===null||typeof e!="object")return ba(e);const n=e;return ba(n.delivered)??ba(n.message)??ba(n.error)}function N7(e,n){if(!n||!e)return"critical";const s=e.toLowerCase();return/^(refused|not sent)/.test(s)?"critical":/^sent\b/.test(s)?"good":"warning"}const S7="mission.report",Ul=e=>typeof e=="string"&&e.trim()!==""?e.trim():null,C7=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function E7(e,n){const s=e!==null&&typeof e=="object"?e:{},r=n!==null&&typeof n=="object"?n:{},a=Ul(r.link),i=r.audio!==null&&typeof r.audio=="object"?r.audio:null,l=i?Ul(i.fileId):null,o=i?Ul(i.mime):null;return{text:Ul(s.text),link:a&&a.startsWith("#/")?{route:a,label:Ul(r.linkLabel)??"Open"}:null,audio:l&&C7.test(l)&&o&&mp(o)?{fileId:l,mime:o,filename:i?Ul(i.filename):null,sizeBytes:i&&typeof i.sizeBytes=="number"?i.sizeBytes:null}:null}}function A7(e){return!!(e.text&&e.link&&cP(e.link.route))}function HC({view:e}){var a;if(!e.text&&!e.audio)return null;const n=e.audio?t.jsx(pp,{artifactId:e.audio.fileId,name:e.audio.filename??"Voice note",mime:e.audio.mime,sizeBytes:e.audio.sizeBytes}):null,s=e.text?t.jsx("div",{className:"wb-bubble","data-rich":"true",children:t.jsx(pr,{text:e.text})}):null,r=cP((a=e.link)==null?void 0:a.route);return r&&e.link&&e.text?t.jsx(JW,{editionId:r,text:s,audio:e.audio,link:e.link}):t.jsxs("div",{className:"wb-report","data-testid":"mission-report",children:[n,s,e.link?t.jsx("a",{className:"ui-btn wb-report-link","data-size":"sm",href:e.link.route,children:e.link.label}):null]})}const OM=3,$7=2*6e4,KC=40,T7=["filename","fileName","file_name","file","filePath","file_path","path"],R7=["accountName","account_name","account"],I7=["pageId","page_id","page"],P7=["url","href","link"],M7=new Set(["conversationId","agentId","runId","toolUseId","ownerId","requestId"]);function DM(e){return e.length>KC?`${e.slice(0,KC-1)}…`:e}function Zh(e){const n=e.trim();return n===""?null:{key:n,label:DM(n)}}function VC(e){const n=(e.split(/[?#]/)[0]??"").trim(),s=(n.split(/[\\/]/).filter(Boolean).at(-1)??"").trim();return s===""?null:{key:n,label:DM(s)}}function O7(e){try{const n=new URL(e);return n.host?Zh(n.host.replace(/^www\./,"")):null}catch{return null}}function Yg(e){if(typeof e=="string")return Zh(e);if(typeof e=="number"&&Number.isFinite(e))return Zh(String(e));if(e&&typeof e=="object"&&!Array.isArray(e)){const n=e;for(const s of["name","filename","title"])if(typeof n[s]=="string")return Zh(n[s])}return null}function GC(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;const n=e;for(const s of T7){const r=n[s];if(typeof r=="string"){const a=VC(r);if(a)return a}else if(s==="file"){const a=Yg(r);if(a)return VC(a.key)}}for(const s of R7){const r=Yg(n[s]);if(r)return r}for(const s of I7){const r=Yg(n[s]);if(r)return r}for(const s of P7){const r=n[s];if(typeof r=="string"){const a=O7(r);if(a)return a}}return null}function D7(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;for(const[n,s]of Object.entries(e))if(!(M7.has(n)||!/(?:[a-z]Id|_id)$/.test(n))){if(typeof s=="string"&&s.trim()!==""){const r=s.trim();return{key:r,label:r.length>8?r.slice(0,8):r}}if(typeof s=="number")return{key:String(s),label:String(s)}}return null}function L7(e,n){return GC(e)??GC(n)??D7(e)}function qC(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;const n=e;for(const s of["expiresAt","expires_at","expires"]){const r=n[s];if(typeof r=="string"&&!Number.isNaN(Date.parse(r)))return r}return null}function Np(e){var n;return((n=e.versions)==null?void 0:n.at(-1))??null}function zi(e){var n;return((n=Np(e))==null?void 0:n.id)??e.id}function YC(e,n){return e.find(s=>s.id!==n&&(s.versions??[]).some(r=>r.id===n))??null}function F7(e,n){if(e.expiresAt&&Date.parse(e.expiresAt)<=n)return"gone";if(e.source==="fallback"&&e.tone==="critical"){const s=e.versions??[],r=a=>(a==null?void 0:a.failed)===!0;if(s.length>0?s.every(a=>r(a.props)):r(e.props))return"parked"}return null}function qu(e){if(!e)return 0;const n=Date.parse(e);return Number.isNaN(n)?0:n}function _7(e,n){var s;return Math.max(qu(((s=Np(e))==null?void 0:s.at)??e.at),n[e.id]??0)}function LM(e,n={}){return e.map((s,r)=>({item:s,index:r,at:_7(s,n)})).sort((s,r)=>r.at-s.at||r.index-s.index).map(({item:s})=>s)}function z7(e,n,s=OM,r={},{turnStartedAt:a=null}={}){const i=LM(e,r),l=qu(a),o=h=>{var f;if(l===0||r[h.id]!==void 0)return!1;const m=qu(((f=Np(h))==null?void 0:f.at)??h.at);return m>0&&m<l},c=new Set(e.filter(h=>h.id===n||h.source==="approval"||h.pinned===!0).map(h=>h.id));for(const h of i){if(c.size>=s)break;h.parked||o(h)||c.add(h.id)}const u=i.filter(h=>c.has(h.id));return{shown:[...u.filter(h=>h.pinned===!0),...u.filter(h=>h.pinned!==!0)],hidden:i.filter(h=>!c.has(h.id))}}function U7(e,{now:n,turnStartedAt:s,touched:r={}}){var l;const a=qu(s),i=[{label:"Now",items:[]},{label:"Earlier this turn",items:[]},{label:"Earlier",items:[]}];for(const o of LM(e,r)){const c=qu(((l=Np(o))==null?void 0:l.at)??o.at),u=a>0&&c>=a;c>0&&c>=n-$7&&(a===0||u)?i[0].items.push(o):u?i[1].items.push(o):i[2].items.push(o)}return i.filter(o=>o.items.length>0)}const B7=new Set(["table","tiles","timeseries","bars","keyvalue","story","document","diff","terminal","image","audio","preview","query","envelope"]),W7=["browser.*","secret.*","secrets.*","mission.*","owner.notify"];function FM(e){return W7.some(n=>n.endsWith(".*")?e.startsWith(n.slice(0,-1)):e===n)}function H7({tool:e,renderer:n,substantial:s}){return FM(e)?!1:n==="structured"?s:B7.has(n)}const bi="agent.delegate";function K7(e){if(e===null||typeof e!="object")return null;const n=e,s=n.conversationId;if(typeof s!="string"||s==="")return null;const r=n.agentId??n.agent;return{conversationId:s,agentId:typeof r=="string"?r:"",runId:typeof n.runId=="string"?n.runId:null}}function V7(e){if(typeof e=="string")return e;if(e===null||typeof e!="object")return null;const n=e.text;return typeof n=="string"?n:null}const Dv="canvas.show",QC="canvas.clear",JC=12;function G7(e){return`sources:${e}`}function q7(e){return`tab:${e}`}function _M(e){return e.role==="user"&&(e.blocks??[]).some(n=>n.type==="text"&&n.text.trim()!==""||n.type==="attachment")}function wo(e){return`${e.plugin}/${e.name}`}function Y7(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;const n=e.diff;return typeof n=="string"&&n.trim()!==""}function Q7({messages:e,descriptors:n}){const s=new Map(n.filter(i=>i.renderer==="preview").map(i=>[i.tool,i]));if(s.size===0)return[];const r=new Map,a=[];for(const i of e)for(const l of i.blocks??[]){if(l.type==="tool_use"&&r.set(l.id,l.name),l.type!=="tool_result"||l.ok===!1)continue;const o=s.get(l.name||r.get(l.toolUseId)||"");if(!o)continue;const c=bP(o,am(l.output)).props;c.target===null&&c.awaiting!==null&&a.push({...c.awaiting,at:i.at??null})}return a}function zM({messages:e,descriptors:n,awaiting:s,folded:r,served:a,gathered:i,quiet:l,titles:o}){var w,v;const c=j=>WM(j,o),u=new Map(n.map(j=>[j.tool,j])),h=new Map;let m=[],f=0,p=null;const x=j=>{p||(p={id:G7(j.id),tool:j.tool,title:"Sources",renderer:"sources",source:"sources",props:{entries:[]},at:j.at,substantial:!1,count:0},m.push(p));const y=p.props,k=y.entries.some(b=>b.id===j.id)?y.entries.map(b=>b.id===j.id?{...j,input:j.input??b.input}:b):[...y.entries,j],N=[...new Set(k.map(b=>b.tool))];p.props={entries:k},p.tool=N.join(" · "),p.count=k.length,p.substantial=k.some(b=>b.ok===!0),p.tone=k.every(b=>b.ok===!1)?"critical":void 0},g=(j,y,k)=>{if(k&&(j.expiresAt=k),!y){m.push(j);return}j.subject=y.label,j.subjectKey=y.key,j.title=`${j.title} · ${y.label}`;const N={id:j.id,at:j.at,title:j.title,renderer:j.renderer,props:j.props,substantial:j.substantial,...j.tone?{tone:j.tone}:{}},b=m.find(C=>C.subjectKey===y.key&&C.tool===j.tool&&(C.source==="descriptor"||C.source==="fallback"));if(!b){m.push({...j,id:q7(j.id),versions:[N]});return}m=m.filter(C=>C!==b);const S={...j,id:b.id,versions:[...b.versions??[],N]};j.tone||delete S.tone,k||delete S.expiresAt,m.push(S)};for(const j of e){_M(j)&&(p=null);for(const y of j.blocks??[]){if(y.type==="tool_use"){if(h.set(y.id,{name:y.name,input:y.input,at:j.at??null}),i!=null&&i.has(y.name)){x({id:y.id,tool:y.name,input:y.input,output:null,ok:null,at:j.at??null});continue}if(y.name===Dv){const I=X7(y.id,y.input,j.at??null);I&&m.push(I)}if(y.name===QC&&(m=[],p=null),y.name===bi){const I=K7(y.input);I&&m.push({id:y.id,tool:bi,title:"Delegation",renderer:"delegate",props:{...I,result:null},at:j.at??null,source:"delegate",substantial:!0})}continue}if(y.type!=="tool_result"||y.name===Dv||y.name===QC)continue;const k=h.get(y.toolUseId),N=j.at??(k==null?void 0:k.at)??null,b=y.name||(k==null?void 0:k.name)||"tool",S=m.find(I=>I.source==="delegate"&&I.id===y.toolUseId);if(S&&((w=y.delegation)==null?void 0:w.state)==="waiting"){S.props={...S.props,result:null,waiting:{approvalId:y.delegation.approvalId}},y.delegation.approvalId&&(S.tone="warning");continue}if(S){S.props={...S.props,result:{ok:y.ok,text:V7(y.ok?y.output:y.error??y.output),...y.ok&&Kf(y.output).length>0?{files:Kf(y.output)}:{}}},y.ok||(S.tone="critical");continue}const C=y.approval?Lv(y):(s==null?void 0:s.get(y.toolUseId))??Lv(y);if(C){m.push({id:y.toolUseId,tool:b,title:"Approval",renderer:"envelope",props:{approvalId:C},at:N,tone:"warning",source:"approval",substantial:!0});continue}if(r!=null&&r.has(b)||l!=null&&l.has(b)&&y.ok!==!1||FM(b))continue;if(i!=null&&i.has(b)){x({id:y.toolUseId,tool:b,input:(k==null?void 0:k.input)??null,output:am(y.output)??null,ok:y.ok!==!1,...y.error===void 0?{}:{error:y.error},at:N});continue}const A=am(y.output),E=((v=u.get(b))==null?void 0:v.renderer)==="story"&&A&&typeof A=="object"?A:null,R=E&&typeof E.title=="string"&&typeof E.id=="string"?{key:E.id,label:E.title.length>60?`${E.title.slice(0,59)}…`:E.title}:L7((k==null?void 0:k.input)??null,A);if(y.ok===!1){g({id:y.toolUseId,tool:b,title:c(b),renderer:"structured",props:{value:y.error??A??null,failed:!0},at:N,tone:"critical",source:"fallback",substantial:!1},R,null);continue}Y7(A)&&(f+=1);const P=u.get(b);if(P){const I=bP(P,A),{renderer:F}=I;let{props:U}=I;if(F==="preview"){const M=U,z=M.target??(M.awaiting&&(a!=null&&a.has(wo(M.awaiting)))?M.awaiting:null);if(z===null)continue;U={...M,target:z,awaiting:null};const D=wo(z);m=m.filter(K=>!(K.source==="descriptor"&&K.renderer==="preview"&&K.props.target!==null&&wo(K.props.target)===D))}if(!H7({tool:b,renderer:F,substantial:ef(F,U)}))continue;const L={id:y.toolUseId,tool:b,title:P.title??c(b),renderer:F,props:U,at:N,source:"descriptor",substantial:ef(F,U)};F==="preview"?m.push(L):g(L,R,qC(A));continue}const O={value:kp(A)?{input:k==null?void 0:k.input,output:A}:A};Z7("structured",O)&&g({id:y.toolUseId,tool:b,title:c(b),renderer:"structured",props:O,at:N,source:"fallback",substantial:ef("structured",O)},R,qC(A))}}for(const j of m)j.source==="descriptor"&&j.renderer==="preview"&&(j.props={...j.props,changes:f});return J7(m)}const XC="forAgent";function am(e){if(e===null||typeof e!="object"||Array.isArray(e)||!(XC in e))return e;const{[XC]:n,...s}=e;return s}function J7(e){if(e.length<=JC)return e;const n=e.length-JC;return[...e.slice(0,n).filter(r=>r.source==="approval"),...e.slice(n)]}function X7(e,n,s){if(n===null||typeof n!="object")return null;const{renderer:r,title:a,data:i}=n,l=typeof r=="string"&&rm(r)?r:"structured";return{id:e,tool:Dv,title:typeof a=="string"&&a.trim()!==""?a:"Shown",renderer:l,props:l==="structured"&&!rm(String(r))?{value:i}:i,at:s,substantial:!0,source:"canvas"}}function Z7(e,n){const s=n??{};return!!(s.failed===!0||ef(e,n)||Xb(s.value).kind==="error")}function ef(e,n){const s=n??{};switch(e){case"timeseries":return Rc(s.points)>0;case"bars":return Rc(s.bars)>0;case"keyvalue":return Rc(s.pairs)>0;case"tiles":return s.notice!==!0&&Rc(s.tiles)>0;case"document":return!!s.text||!!s.src;case"diff":return!!s.diff;case"terminal":return!!s.output||!!s.command;case"image":return!!s.artifactId;case"preview":return!!s.target;case"envelope":return!0;case"table":return(Array.isArray(s.groups)?s.groups:[]).some(a=>Rc(a.rows)>0);default:return kp(s.value)?!0:s.failed===!0?!1:LV(s.value)}}function Rc(e){return Array.isArray(e)?e.length:0}function Lv(e){if(e.approval)return e.approval.state==="pending"?e.approval.id:null;for(const n of[e.error,e.output]){const s=BM(n,0);if(s)return s}return null}function eq(e,n,s={}){var c,u,h;const r=m=>WM(m,s.titles),a=e.flatMap(m=>m.blocks),i=a.find(m=>m.type==="tool_use"&&m.id===n);if((i==null?void 0:i.type)!=="tool_use")return null;const l=a.find(m=>m.type==="tool_result"&&m.toolUseId===n);if(i.name===PM&&(l==null?void 0:l.type)==="tool_result")return{id:n,tool:i.name,title:"Message to you",renderer:"notify",props:{input:i.input??null,output:l.output??null,ok:l.ok!==!1},at:null,tone:l.ok===!1?"critical":void 0,source:"notify",substantial:!1};if((c=s.resultOf)!=null&&c.has(i.name)&&(l==null?void 0:l.type)==="tool_result"&&l.ok&&!l.approval)return{id:n,tool:i.name,title:r(i.name),renderer:"structured",props:{value:am(l.output)??null},at:null,source:"fallback",substantial:!1};const o=(u=s.redactInputOf)!=null&&u.has(i.name)?UM(i.input):i.input;return{id:n,tool:i.name,title:r(i.name),renderer:"structured",props:{value:{input:o,...(l==null?void 0:l.type)==="tool_result"?{status:((h=l.approval)==null?void 0:h.state)??(l.ok?"completed":"failed"),output:l.output,...l.error?{error:l.error}:{}}:{status:"Awaiting result"}}},at:null,source:"fallback",substantial:!1}}const tq=new Set(["value","text","password","secret","code"]);function UM(e){if(e===null||typeof e!="object"||Array.isArray(e))return e;const n={};for(const[s,r]of Object.entries(e))n[s]=tq.has(s)&&typeof r=="string"?"— withheld —":UM(r);return n}function BM(e,n){if(n>3||e===null||typeof e!="object")return null;const s=e,r=s.reason,a=s.actionId??s.approvalId;if(typeof a=="string"&&a!==""&&(r===void 0||r==="approval-required"))return a;for(const i of Object.values(s)){const l=BM(i,n+1);if(l)return l}return null}function gl(e){const n=e.split(".");return n.length===1?nn(e):n.map(s=>nn(s)).join(" · ")}function WM(e,n){return(n==null?void 0:n.get(e))??gl(e)}function ZC(e,n){return e.find(s=>s.source==="sources"&&s.props.entries.some(r=>r.id===n))??null}function nq(e,n,s){const r=t1(e),a=t1(n==null?void 0:n.input),i=Ui(r==null?void 0:r.name)??lq(Ui(r==null?void 0:r.handle))??Ui(r==null?void 0:r.agent)??Ui(a==null?void 0:a.agent),l=typeof e=="string"?e.trim()||null:Ui(r==null?void 0:r.text)??Ui(r==null?void 0:r.note),o=e1(r==null?void 0:r.durationMs)??e1(r==null?void 0:r.elapsedMs),c=n!=null&&n.at?Date.parse(n.at):NaN,u=s?Date.parse(s):NaN,h=Number.isFinite(c)&&Number.isFinite(u)&&u>=c?u-c:null;return{who:i,question:Ui(a==null?void 0:a.task),answer:l,files:Kf(e),durationMs:o??h}}function sq(e,n){var r;let s=null;for(const a of e)for(const i of a.blocks??[])i.type==="tool_result"&&i.name===bi&&((r=i.delegation)==null?void 0:r.approvalId)===n&&(s=i.toolUseId);if(s===null)return null;for(const a of e)for(const i of a.blocks??[])if(i.type==="tool_use"&&i.id===s)return{input:i.input,at:a.at||null};return null}function rq({block:e,messages:n,answeredAt:s}){const r=nq(e.output,sq(n,e.actionId),s),a=[r.who?`Asked ${r.who}`:null,r.durationMs===null?null:`took ${aq(r.durationMs)}`].filter(i=>i!==null);return t.jsxs("div",{className:"wb-delegation-result","data-testid":"delegation-result",children:[a.length>0?t.jsx("p",{className:"wb-delegation-facts",children:a.join(" · ")}):null,r.question?t.jsx("blockquote",{className:"wb-delegation-question",children:r.question}):null,r.answer?t.jsx("div",{className:"wb-delegation-answer","data-testid":"delegation-answer",children:t.jsx(pr,{text:r.answer})}):t.jsx("p",{className:"wb-delegation-facts",children:"No answer came back."}),r.files.length>0?t.jsx("div",{className:"wb-msg-files",role:"list","aria-label":`Files ${r.who??"the colleague"} made`,children:r.files.map(i=>t.jsx("a",{role:"listitem",href:la(i.artifactId),download:!0,children:t.jsx(bd,{name:i.filename??"Untitled file",mime:i.mime,sizeBytes:i.sizeBytes,thumbnail:Cb(i.mime)?Dr(i.artifactId):null,size:"sm"})},i.artifactId))}):null,t.jsx(Vt,{summary:"Raw JSON",children:t.jsx("pre",{className:"wb-approval-output mono",children:iq(e.output)})})]})}function aq(e){if(e<1e3)return`${Math.round(e)}ms`;const n=Math.round(e/1e3);if(n<60)return`${n}s`;const s=Math.floor(n/60);return s<60?`${s}m ${String(n%60).padStart(2,"0")}s`:`${Math.floor(s/60)}h ${String(s%60).padStart(2,"0")}m`}function iq(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function lq(e){return e===null?null:`@${e.replace(/^@/,"")}`}function Ui(e){return typeof e=="string"&&e.trim()!==""?e:null}function e1(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function t1(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const oq=1e3;function cq({messageId:e,text:n,onReadAloud:s,rawTextBlocks:r}){const[a,i]=d.useState(!1),[l,o]=d.useState(!1),c=d.useRef(null),u=d.useSyncExternalStore(UW,zW)===e;d.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]);const h=()=>{var m;(m=navigator.clipboard)==null||m.writeText(n).then(()=>{o(!0),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>o(!1),oq)},()=>{})};return t.jsxs("div",{className:"wb-reply-actions","data-testid":"reply-actions",children:[t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":l?"Copied":"Copy",title:l?"Copied":"Copy",onClick:h,children:t.jsx(ne,{name:l?"check":"copy",size:14})}),t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"View raw response",title:"View raw response",onClick:()=>i(!0),children:t.jsx(ne,{name:"code",size:14})}),a?t.jsxs(Ye,{title:"Raw response",onClose:()=>i(!1),scrollBody:!0,children:[t.jsx("p",{children:"Stored text blocks before Markdown rendering. Each block is shown unchanged; this is not the full provider response."}),(r??[n]).map((m,f)=>t.jsxs("section",{children:[t.jsxs("h3",{children:["Text block ",f+1]}),t.jsx("pre",{className:"wb-raw-response",children:t.jsx("code",{children:m})})]},f))]}):null,l?t.jsx("span",{className:"wb-reply-copied",role:"status",children:"Copied"}):null,s?t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":u?"Stop reading aloud":"Read aloud",title:u?"Stop reading aloud":"Read aloud","aria-pressed":u,onClick:()=>u?lc():s(e,n),children:t.jsx(ne,{name:u?"stop":"play",size:14})}):null]})}function uq(e){const n=dq(e);if(!n)return null;const s=Qg(n.diff);if(s!==null)return{kind:"diff",diff:s};const r=Qg(n.command),a=Qg(n.plain),i=Jg(n.exitCode);return r!==null&&(a!==null||i!==null||Jg(n.pid)!==null)?{kind:"command",command:r,output:a,exitCode:i,elapsedMs:Jg(n.elapsedMs)}:null}function Qg(e){return typeof e=="string"&&e.trim()!==""?e:null}function Jg(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function dq(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const n1="offer:",HM="owner:interjection";function hq(e){return e===HM}function fq(e){if(typeof e!="string"||!e.startsWith(n1))return null;const n=e.slice(n1.length).trim();return n===""?null:n}const s1="brief:";function mq(e){if(typeof e!="string"||!e.startsWith(s1))return null;const n=e.slice(s1.length).trim();return n===""?null:n}const r1="stamp:";function pq(e){if(typeof e!="string"||!e.startsWith(r1))return null;const n=e.slice(r1.length).trim();return n===""?null:n}function rk({messages:e,live:n,now:s,onOpen:r,working:a=!1,partial:i=null,agents:l,agentId:o,speakers:c,coordinatorId:u,workingAs:h,onOpenFile:m,onReadAloud:f,children:p,agentName:x,emptyHint:g,empty:w,plain:v=!1,workingLine:j,runs:y,onContinue:k,mediaTools:N,timezone:b}){var ie;const S=d.useRef(null);d.useEffect(()=>{var H;(H=S.current)==null||H.scrollIntoView({block:"end"})},[e.length,n.length,a,i==null?void 0:i.text.length,i==null?void 0:i.thinking.length,!!p]);const C=i&&!i.settled&&(i.text!==""||i.thinking!==""),A=e.filter(H=>(H.blocks??[]).some($q)).map(KM),E=Sq(A,y??[]),R=Eq(A,y??[]),P=c??l??[],O=H=>(o&&!c?P.find(de=>de.id===o):void 0)??P.find(de=>de.name===H)??null,I=o?P.find(H=>H.id===o)??null:null,F=a||n.length>0,U=F||!!C,L=!!C&&i.text!=="",M=F&&!L,z=A.at(-1),D=(z==null?void 0:z.role)!=="assistant"||!!h,K=h??x??"Assistant",B=A.filter((H,de)=>{var ge;return de===0||(c?(((ge=A[de-1])==null?void 0:ge.speaker)??null)!==(H.speaker??null):A[de-1].role!==H.role)}),se=U&&!D?((ie=B.at(-1))==null?void 0:ie.id)??null:null,W=(y??[]).reduce((H,de)=>H===null||(de.startedAt??"")>(H.startedAt??"")?de:H,null),xe=(y??[]).some(H=>H.finishedAt===null),me=k&&!U&&!xe&&z&&(W==null?void 0:W.stopped)==="max_turns"&&E.get(z.id)===W?z.id:null;return t.jsx(NM.Provider,{value:l??c??[],children:t.jsxs("div",{className:"wb-messages","data-testid":"messages",children:[A.length===0&&n.length===0?w??t.jsx("p",{className:"wb-chat-empty",children:g}):null,A.map((H,de)=>{var Ze;const ge=H.speaker??null,Ue=c?ge==="owner"||ge===null&&H.role==="user":H.role==="user",G=c&&ge==="room",ae=c&&ge&&ge!=="owner"&&ge!=="room"?c.find(Se=>Se.id===ge)??null:null,J=A[de-1],Ne=de===0||(c?((J==null?void 0:J.speaker)??null)!==ge:J.role!==H.role);if(G)return t.jsx("div",{className:"wb-msg wb-msg-room","data-role":"room",children:(H.blocks??[]).filter(Se=>Se.type==="text").map((Se,Le)=>t.jsx("span",{children:Se.text},Le))},H.id);const Ie=(H.blocks??[]).filter(Se=>Se.type==="approval_result");if(Ie.length>0)return t.jsx("div",{className:"wb-msg","data-role":"assistant","data-testid":"approval-result",children:Ie.map((Se,Le)=>t.jsx(Tq,{block:Se,messages:e,at:H.at||null},Le))},H.id);const Y=H.role==="user"&&hq(ge),X=H.role==="user"?pq(ge):null;if(X){const Se=H.at?new Date(H.at):null;return t.jsxs("p",{className:"ss-stamp",role:"status","data-testid":"thread-stamp",children:[t.jsx(ne,{name:"key",size:14}),t.jsx("span",{children:X}),Se&&!Number.isNaN(Se.getTime())?t.jsx("span",{className:"ss-stamp-when",children:Lt(Se,b??Intl.DateTimeFormat().resolvedOptions().timeZone)}):null]},H.id)}const oe=H.role==="user"?mq(ge):null;if(oe)return t.jsx("div",{className:"wb-msg","data-role":"user","data-testid":"offer-turn",children:t.jsx("div",{className:"wb-bubble wb-bubble-offer",children:oe})},H.id);const ve=H.role==="user"?fq(ge):null;if(ve){const Se=(H.blocks??[]).filter(Le=>Le.type==="text").map(Le=>Le.text).join(`
114
- `);return t.jsx("div",{className:"wb-msg","data-role":"user","data-testid":"offer-turn",children:t.jsx("div",{className:"wb-bubble wb-bubble-offer",title:Se,children:ve})},H.id)}const be=c&&ae&&H.role==="user"?wq(H):null;if(be){const Se=A.slice(de+1).find(Ve=>Ve.role==="assistant"&&Ve.speaker&&Ve.speaker!==ae.id),Le=Se!=null&&Se.speaker?c.find(Ve=>Ve.id===Se.speaker):void 0;return t.jsxs("details",{className:"wb-msg wb-msg-room wb-msg-ask","data-role":"room",children:[t.jsxs("summary",{children:[ae.name," asked ",(Le==null?void 0:Le.name)??"a member",be.request?`: ${be.request.length>120?`${be.request.slice(0,119)}…`:be.request}`:""]}),be.request?t.jsx("p",{children:be.request}):null]},H.id)}const Ce=E.get(H.id)??null,we=Nq(H,e),He=!Ue&&!Y&&!v?kq(H):"";return t.jsxs("div",{className:"wb-msg","data-role":Ue||Y?"user":"assistant",children:[Y?t.jsx("div",{className:"wb-msg-added","data-testid":"added-while-working",children:we.length>0?`Queued with ${we.length} file${we.length===1?"":"s"}`:"added while working"}):null,Ne&&!Ue&&!Y?t.jsx(a1,{name:ae?ae.name:c&&ge&&ge!=="owner"&&ge!=="room"?ge:x??"Assistant",face:ae??I??O(x),moving:M&&se===H.id,children:ae&&u===ae.id?t.jsx("span",{className:"wb-msg-role",children:"coordinator"}):null}):null,we.length>0?t.jsx("div",{className:"wb-msg-files",role:"list","aria-label":"Files sent with this message",children:we.map(Se=>t.jsx("span",{role:"listitem",children:mp(Se.mime)?t.jsx(pp,{artifactId:Se.artifactId,name:Se.filename??"Untitled file",mime:Se.mime,sizeBytes:Se.sizeBytes}):t.jsx(bd,{name:Se.filename??"Untitled file",mime:Se.mime,sizeBytes:Se.sizeBytes,thumbnail:Cb(Se.mime)?Dr(Se.artifactId):null,...m?{onOpen:()=>m(Se)}:{}})},Se.artifactId))}):null,(H.blocks??[]).map((Se,Le)=>{const Ve=jq(H.blocks??[],Le,e);if(Ve==="inside")return null;if(Ve)return t.jsx(vq,{refusals:Ve.refusals},Le);if(Se.type==="thinking")return v||Se.text.trim()===""?null:t.jsx(Fv,{text:Se.text},Le);if(Se.type==="text")return Se.text.trim()===""?null:Ue?t.jsx("div",{className:"wb-bubble",children:t.jsx(b7,{text:Se.text})},Le):t.jsx("div",{className:"wb-bubble","data-rich":"true",children:t.jsx(pr,{text:Se.text})},Le);if(Se.type==="attachment")return null;if(Se.type==="tool_use"){if(v||Se.name==="secret.request")return null;const Qe=ak(e,Se.id),wt=Qe?Pq(Qe):null,dt=!wt&&Se.name===PM&&Qe?MM(Qe.output):null,qt=!wt&&Qe!==null&&!Qe.ok&&typeof Qe.error=="string"&&Qe.error.startsWith("not-executed:"),vt=!wt&&Se.name===S7&&(Qe!=null&&Qe.ok)?E7(Se.input,Qe.output):null;return vt&&A7(vt)?t.jsx(HC,{view:vt},Le):t.jsxs(d.Fragment,{children:[t.jsx(_v,{label:wt&&!(Qe!=null&&Qe.delegation)?`Approval · ${Se.name}`:gl(Se.name),tool:Se.name,ok:qt?null:(Qe==null?void 0:Qe.ok)??null,running:Qe===null,...wt?{status:wt.status,waiting:wt.waiting,approval:!0}:dt?{status:dt}:qt?{status:"not run"}:{},gist:sk(Se.name,Se.input),body:Qe?uq(Qe.output):null,opens:!0,onOpen:()=>r(Se.id)},Le),!wt&&(Qe!=null&&Qe.ok)&&(N!=null&&N.has(Se.name))?XW(Se.name.split(".")[0]??"",Qe.output).map(Dt=>"report"in Dt?t.jsx(dP,{link:Dt.report},Dt.report):t.jsx(QW,{id:Dt.artifact},Dt.artifact)):null,vt?t.jsx(HC,{view:vt}):null]},Le)}return null}),Ce?t.jsxs("div",{className:"wb-msg-budget","data-testid":"budget-stop",children:[t.jsx("span",{children:Aq(Ce)}),me===H.id?t.jsx($,{size:"sm",className:"wb-msg-budget-continue","data-testid":"budget-continue",onClick:k,children:"Continue"}):null]}):null,R.has(H.id)?t.jsx("div",{className:"wb-msg-unchecked","data-testid":"unchecked-answer",children:Cq}):null,H.feedback&&!Ue&&!Y?t.jsx(Dq,{feedback:H.feedback}):null,He!==""?t.jsx(cq,{messageId:H.id,text:He,rawTextBlocks:(((Ze=e.find(Se=>Se.id===H.id))==null?void 0:Ze.blocks)??[]).flatMap(Se=>Se.type==="text"?[Se.text]:[]),onReadAloud:f}):null]},H.id)}),U?t.jsxs("div",{className:"wb-msg","data-role":"assistant","data-testid":"live-turn",children:[D?t.jsx(a1,{name:K,face:O(K)??I,moving:M}):null,C&&i.thinking!==""&&!v?t.jsx(Fv,{text:i.thinking,live:i.text==="",seconds:yq(i.thinkingStartedAt,i.textStartedAt??s)}):null,L?t.jsxs("div",{className:"wb-bubble","data-live":"true","data-rich":"true",children:[t.jsx(pr,{text:i.text}),t.jsx("span",{className:"wb-caret","aria-hidden":"true"})]}):null,a&&n.length===0&&!C?t.jsxs("span",{className:"wb-working",role:"status","aria-live":"polite","data-testid":"working",children:[j??`${h??x??"The agent"} is working`,t.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]})]}):null,n.map(H=>t.jsx(_v,{label:gl(H.name),tool:H.name,ok:null,running:!0,elapsed:Math.max(0,Math.round((s-H.startedAt)/1e3)),opens:!1,onOpen:()=>r(H.toolUseId)},H.toolUseId))]}):null,p,t.jsx("div",{ref:S})]})})}function a1({name:e,face:n,moving:s=!1,children:r}){const a=(n==null?void 0:n.picture)??null,i=SI(s?a:null);return t.jsxs("div",{className:"wb-msg-who","data-testid":"turn-head",children:[t.jsx("span",{className:"wb-msg-mark","data-moving":s?i&&a?"blob":"ring":void 0,children:s&&i&&a?t.jsx(jd,{state:"working",size:"sm",still:a,className:"wb-msg-blob"}):t.jsx(Bn,{id:(n==null?void 0:n.id)??e,name:(n==null?void 0:n.name)??e,unavailable:n?!n.available:!1,...n?{face:n}:{}})}),t.jsx("span",{children:e}),r]})}function gq(e){var n,s;return((s=(n=/ may delegate to ([^;]*);/.exec(e)??/\(allowed: ([^)]*)\)/.exec(e))==null?void 0:n[1])==null?void 0:s.trim())||null}const xq="delegation refused:";function jq(e,n,s){const r=i=>{const l=e[i];if(!l||l.type!=="tool_use"||l.name!==bi)return null;const o=ak(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(xq))return null;const u=l.input??{};return{target:typeof u.agent=="string"&&u.agent!==""?u.agent:"a colleague",message:c}};if(!r(n))return null;if(r(n-1))return"inside";const a=[];for(let i=n;;i+=1){const l=r(i);if(!l)break;a.push(l)}return a.length<2?null:{refusals:a}}function vq({refusals:e}){const[n,s]=d.useState(!1),r=e.map(o=>gq(o.message)).find(o=>o!==null)??null,a=e.map(o=>o.target),i=a.slice(0,3),l=`Delegation refused ${e.length} times: ${i.join(", ")}${a.length>i.length?", …":""}`+(r?` (allowed: ${r})`:"");return t.jsxs("div",{className:"wb-refusals","data-testid":"delegation-refusals","data-open":n||void 0,children:[t.jsxs("button",{type:"button",className:"wb-tool","data-ok":!1,"aria-expanded":n,onClick:()=>s(o=>!o),children:[t.jsx("span",{className:"wb-tool-mark","data-ok":"false","aria-hidden":"true"}),t.jsx("span",{className:"wb-tool-label",children:l}),t.jsx(ne,{name:"arrow",className:"wb-tool-arrow"})]}),n?t.jsx("div",{className:"wb-refusals-list",children:e.map((o,c)=>t.jsxs("div",{className:"wb-refusal",children:[t.jsxs("span",{className:"wb-tool","data-static":"true","data-ok":!1,children:[t.jsx("span",{className:"wb-tool-mark","data-ok":"false","aria-hidden":"true"}),t.jsxs("span",{className:"wb-tool-label",children:[gl(bi)," · ",o.target]}),t.jsx("span",{className:"wb-tool-elapsed",children:"refused"})]}),t.jsx("p",{className:"wb-refusal-why",children:o.message})]},c))}):null]})}function yq(e,n){return e===null?null:Math.max(0,Math.round((n-e)/1e3))}function Fv({text:e,live:n=!1,seconds:s=null}){const[r,a]=d.useState(!1),i=n?`Thinking${s!==null&&s>0?` · ${s}s`:""}`:s!==null&&s>0?`Thought for ${s}s`:"Thoughts";return t.jsxs("div",{className:"wb-thought","data-live":n||void 0,"data-open":r||void 0,children:[t.jsxs("button",{type:"button",className:"wb-thought-toggle","aria-expanded":r,onClick:()=>a(l=>!l),children:[n?t.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]}):t.jsx(ne,{name:"thought"}),t.jsx("span",{children:i}),t.jsx(ne,{name:"arrow",className:"wb-tool-arrow"})]}),r?t.jsx("div",{className:"wb-thought-text",children:t.jsx(pr,{text:e})}):null]})}function wq(e){var r;const n=((r=(e.blocks??[]).find(a=>a.type==="text"))==null?void 0:r.text)??"",s=/You are a member of the group "[^"]*"\. @([\w-]+), the coordinator, asks you now:\n\n([\s\S]*?)(?:\n\nAnswer for the room|$)/.exec(n);return s?{handle:s[1],request:s[2].trim()}:null}function KM(e){const n=e.blocks??[];if(e.role!=="assistant"||n.length<2)return e;const s=[];let r=!1;for(const a of n){const i=s[s.length-1];a.type==="text"&&(i==null?void 0:i.type)==="text"?(s[s.length-1]={...i,text:i.text+bq(i.text,a.text)+a.text},r=!0):s.push(a)}return r?{...e,blocks:s}:e}function bq(e,n){return e===""||n===""||/\s$/.test(e)||/^\s/.test(n)||/^[.,;:!?)\]}»”’'"]/.test(n)?"":/[.!?:…)"”»]$/.test(e)?`
115
-
116
- `:""}function kq(e){return(KM(e).blocks??[]).filter(n=>n.type==="text").map(n=>n.text.trim()).filter(n=>n!=="").join(`
117
-
118
- `)}function Nq(e,n){const s=[],r=new Set,a=i=>{r.has(i.artifactId)||(r.add(i.artifactId),s.push(i))};for(const i of e.blocks??[])if(i.type==="attachment"&&a(i),i.type==="tool_use"&&i.name===bi){const l=ak(n,i.id);l!=null&&l.ok&&Kf(l.output).forEach(a)}return s}function Sq(e,n){return VM(e,n,s=>(s.stopped==="max_turns"||s.stopped==="max_tokens")&&s.noticed===!0)}const Cq="Answered from memory, not checked";function Eq(e,n){return VM(e,n,s=>s.unchecked===!0)}function VM(e,n,s){const r=n.filter(o=>o.startedAt!==null&&o.finishedAt!==null),a=(o,c)=>c.at!==""&&c.at>=o.startedAt&&c.at<=o.finishedAt,i=(o,c)=>o!==c&&o.startedAt>=c.startedAt&&o.finishedAt<=c.finishedAt&&(o.startedAt>c.startedAt||o.finishedAt<c.finishedAt),l=new Map;for(const o of r){if(!s(o)||o.runId===null)continue;let c=null;for(const u of e)u.role!=="assistant"||!a(o,u)||(c=u);c===null||r.some(u=>i(u,o)&&a(u,c))||l.has(c.id)||l.set(c.id,o)}return l}function Aq(e){if(e.stopped==="max_tokens")return"Length limit reached · answer cut off";const n=e.turns;return n===null?"Turn budget reached":`Turn budget reached · ${n} ${n===1?"step":"steps"}`}function $q(e){return e.type==="text"||e.type==="thinking"?e.text.trim()!=="":e.type==="tool_use"||e.type==="attachment"||e.type==="approval_result"}function Tq({block:e,messages:n,at:s}){const[r,a]=d.useState(!1),i=e.state==="succeeded";return t.jsxs("div",{className:"wb-approval","data-open":r||void 0,children:[t.jsxs("button",{type:"button",className:"wb-tool","data-ok":i,"aria-expanded":r,onClick:()=>a(l=>!l),children:[t.jsx("span",{className:"wb-tool-mark","data-ok":i?"true":"false","aria-hidden":"true"}),t.jsx("span",{className:"wb-tool-label",children:e.name===""?"Approved action":gl(e.name)}),t.jsx("span",{className:"wb-tool-elapsed",children:e.state}),t.jsx(ne,{name:"arrow",className:"wb-tool-arrow"})]}),r&&e.name===bi?t.jsx(rq,{block:e,messages:n,answeredAt:s}):null,r&&e.name!==bi?t.jsx("pre",{className:"wb-approval-output mono",children:Rq(e.output)}):null]})}function Rq(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}const Iq=40;function Pq(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(Lv(e))return{status:"waiting",waiting:!0};const n=(r=e.approval)==null?void 0:r.state;return n?n==="approved"||n==="executing"?{status:"approved",waiting:!0}:n==="succeeded"?{status:"approved",waiting:!1}:{status:n,waiting:!1}:null}function _v({label:e,tool:n,ok:s,running:r,elapsed:a,opens:i,onOpen:l,status:o,waiting:c=!1,approval:u=!1,gist:h=null,body:m=null}){const[f,p]=d.useState(!1),x=t.jsxs(t.Fragment,{children:[r?t.jsx("span",{className:"wb-pulse","aria-hidden":"true"}):t.jsx("span",{className:"wb-tool-mark","data-ok":c?"pending":s===!1?"false":"true","aria-hidden":"true"}),t.jsx("span",{className:"wb-tool-label",children:e}),h?t.jsx("span",{className:"wb-tool-gist mono","data-testid":"tool-gist",children:h}):null,a===void 0?null:t.jsxs("span",{className:"wb-tool-elapsed",children:[a,"s"]}),o||s===!1?t.jsx("span",{className:"wb-tool-elapsed",children:o??"failed"}):null]}),g={"data-ok":s===null?void 0:s,"data-running":r,"data-gist":h?!0:void 0,"data-approval":u||void 0};return m?t.jsxs("div",{className:"wb-toolcall","data-open":f||void 0,children:[t.jsxs("div",{className:"wb-tool","data-split":"true",...g,children:[t.jsxs("button",{type:"button",className:"wb-tool-toggle","aria-expanded":f,onClick:()=>p(w=>!w),children:[t.jsx(ne,{name:"chevron",className:"wb-tool-chevron"}),x]}),i?t.jsxs(Au,{children:[t.jsx($u,{asChild:!0,children:t.jsx("button",{type:"button",className:"wb-tool-open","aria-label":"Open on the canvas",onClick:l,children:t.jsx(ne,{name:"arrow",className:"wb-tool-arrow"})})}),t.jsx(Tu,{children:t.jsxs(Ru,{className:"ui-tip",sideOffset:6,children:[t.jsx("span",{className:"ui-tip-title",children:"Open on the canvas"}),t.jsx("span",{className:"ui-tip-hint mono",children:n})]})})]}):null]}),f?t.jsx(Mq,{body:m,onOpen:i?l:null}):null]}):i?t.jsxs(Au,{children:[t.jsx($u,{asChild:!0,children:t.jsxs("button",{className:"wb-tool",...g,onClick:l,children:[x,t.jsx(ne,{name:"arrow",className:"wb-tool-arrow"})]})}),t.jsx(Tu,{children:t.jsxs(Ru,{className:"ui-tip",sideOffset:6,children:[t.jsx("span",{className:"ui-tip-title",children:"Open on the canvas"}),t.jsx("span",{className:"ui-tip-hint mono",children:n})]})})]}):t.jsx("span",{className:"wb-tool","data-static":"true",...g,children:x})}function Mq({body:e,onOpen:n}){const s=n?{label:"Open on the canvas",onClick:n}:void 0;if(e.kind==="diff")return t.jsx("div",{className:"wb-tool-body","data-kind":"diff","data-testid":"tool-body",children:t.jsx(sm,{text:e.diff,limit:Iq,...s?{more:s}:{}})});const r=[e.exitCode===null?null:`exit ${e.exitCode}`,e.elapsedMs===null?null:Oq(e.elapsedMs)].filter(a=>a!==null);return t.jsxs("div",{className:"wb-tool-body","data-kind":"command","data-testid":"tool-body",children:[t.jsxs("div",{className:"wb-tool-command",children:[t.jsx("code",{className:"mono",children:e.command}),r.length>0?t.jsx("span",{className:"wb-tool-facts","data-failed":e.exitCode!==null&&e.exitCode!==0?!0:void 0,children:r.join(" · ")}):null]}),e.output?t.jsx("pre",{className:"wb-tool-output",children:e.output}):null]})}function Oq(e){return e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(1)}s`}function ak(e,n){for(const s of e)for(const r of s.blocks??[])if(r.type==="tool_result"&&r.toolUseId===n)return r;return null}function Dq({feedback:e}){const n=e.source==="telegram"?"on Telegram":`on ${e.source}`;return t.jsxs("div",{className:"wb-msg-feedback","data-value":e.value,"data-testid":"message-feedback",title:`You reacted ${e.emoji} ${n}`,children:[t.jsx("span",{className:"wb-msg-feedback-emoji","aria-label":`You reacted ${e.emoji} ${n}`,children:e.emoji}),t.jsx("span",{children:n}),e.note?t.jsxs("span",{className:"wb-msg-feedback-note",children:["“",e.note,"”"]}):null]})}const Lq=20*1024*1024,Fq=500,Va=e=>`/skills/${encodeURIComponent(e)}`,jh=e=>`/skills/bundles/${encodeURIComponent(e)}`;async function _q(e){var n;try{const{staged:s}=await Vw("/skills/bundles",e,"bundle.zip");return s}catch(s){const r=s instanceof pe?(n=s.detail)==null?void 0:n.refusal:void 0;throw r?new GM({...r,filename:e.name,error:s instanceof Error?s.message:void 0}):s}}class GM extends Error{constructor(s){super(s.error??`“${s.filename}” was refused.`);R0(this,"name","BundleRefused");this.refusal=s}}const pn={list:()=>ke("/skills"),detail:e=>ke(Va(e)),downloadUrl:e=>`/api${Va(e)}/download`,create:e=>Z("/skills",e),saveText:(e,n)=>Z(`${Va(e)}/text`,{text:n}),grant:(e,n)=>Z(`${Va(e)}/grants`,n),trust:e=>Z(`${Va(e)}/trust`),remove:e=>ys(Va(e)),file:(e,n)=>ke(`${Va(e)}/file`,{path:n}),imageUrl:(e,n)=>`/api${Va(e)}/image?path=${encodeURIComponent(n)}`,uploadBundle:_q,stagedFile:(e,n)=>ke(`${jh(e)}/file`,{path:n}),stagedImageUrl:(e,n)=>`/api${jh(e)}/image?path=${encodeURIComponent(n)}`,acceptBundle:(e,n)=>Z(jh(e),n),discardBundle:e=>ys(jh(e))};function qM(e,n){return`${Pt}?tab=skills${e?`&skill=${encodeURIComponent(e)}`:""}${e&&n?`&skfile=${encodeURIComponent(n)}`:""}`}function zq(e){var s;const n=(s=/[?&]skfile=([^&]+)/.exec(e))==null?void 0:s[1];if(!n)return null;try{return decodeURIComponent(n)}catch{return null}}function Uq(e){var s;const n=(s=/[?&]skill=([^&]+)/.exec(e))==null?void 0:s[1];if(!n)return null;try{return decodeURIComponent(n)}catch{return null}}function YM(e){const n=document.createElement("a");n.href=pn.downloadUrl(e),n.download="",document.body.appendChild(n),n.click(),n.remove()}const ik=[{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 ki(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function dr(e,n){var s;return((s=e.find(r=>r.id===n))==null?void 0:s.name)??n}function lk(e){return e.charAt(0).toUpperCase()+e.slice(1)}function ok(e,n){const s=e.shadowedBy??[];if(!s.length)return"Every agent";const r=s.map(a=>{var i;return`@${((i=n.find(l=>l.id===a))==null?void 0:i.handle)??a}`});return`Every agent except ${ki(r)} (${s.length===1?"has its own":"each has its own"})`}function QM(e,n){return e.holders.some(s=>s.agent===n)}function Bq(e,n){if(e.every)return ok(e,n);const s=e.holders.map(r=>dr(n,r.agent));return s.length?ki(s):"No agent uses it yet"}function Wq(e){return!e.every&&e.holders.length===0}function Hq(){const e=new Date;return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}function i1(e){return e.slice(0,10)===Hq()?"today":`on ${Zo(e,{compact:!0})}`}function su(e,n,s=!1){var l,o;if(e.learned){const c=e.learned.by,u=s&&e.holders.some(m=>m.agent===c),h=e.learned.keptAt?` · kept ${Xe(e.learned.keptAt)}`:"";return`${u?"":`learned by ${dr(n,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 ${lk(r.plugin)} ${r.version}`;if((r==null?void 0:r.kind)==="catalogue")return`came with ${dr(n,r.agent)} ${r.version}`;if((r==null?void 0:r.kind)==="upload")return`uploaded${e.created?` ${i1(e.created)}`:""} · ${r.filename}`;const a=((l=e.created)==null?void 0:l.slice(0,10))??null,i=((o=e.updatedAt)==null?void 0:o.slice(0,10))??null;return a&&(!i||i<=a)?`written by you ${i1(a)}`:e.updatedAt?`edited by you ${Xe(e.updatedAt)}`:"written by you"}function JM(e){return e.charAt(0).toUpperCase()+e.slice(1)}function ck(e,n){var s;return e.untrusted==="page"?`Untrusted: a web page was in view when ${dr(n,((s=e.learned)==null?void 0:s.by)??e.home??"")} proposed it.`:e.bundle?"Untrusted: it came in a .zip, so agents read its text as outside text and its scripts can’t run.":"Untrusted: it came from a file, so agents read it as outside text."}function sa(e){return e<1024*1024?`${Math.max(1,Math.round(e/1024))} KB`:`${(e/(1024*1024)).toFixed(e<10*1024*1024?1:0).replace(/\.0$/,"")} MB`}function XM(e,n){return e.every?n.filter(s=>!(e.shadowedBy??[]).includes(s.id)).map(s=>s.id):e.holders.map(s=>s.agent)}function Kq(e,n){const s=e.bundle;if(!s)return null;const r=s.scripts.length;if(!r)return`No scripts · ${s.files} file${s.files===1?"":"s"} beside the text`;const a=XM(e,n),i=u=>{var h;return((h=n.find(m=>m.id===u))==null?void 0:h.canRunScripts)===!0},l=a.filter(i).map(u=>dr(n,u)),o=a.filter(u=>!i(u)).map(u=>dr(n,u)),c=`${r} script${r>1?"s":""}`;return e.untrusted?`${c} · they can’t run until you mark it as yours`:a.length?l.length?`${c} · ${ki(l)} can run them, asking first${o.length?`; ${ki(o)} ${o.length>1?"read":"reads"} the text only`:""}`:`${c} · nobody holding it can run them, so it’s text only`:`${c} · they run only through an agent you allow, and ask first`}function Vq(e){var n;switch(e.kind){case"big":return{title:`“${e.filename}” is too big`,body:`${e.size?`It’s ${sa(e.size)}; a`:"A"} bundle can be up to 20 MB unpacked. Leave large files out — SKILL.md can say where to find them.`};case"count":return{title:`“${e.filename}” holds too many files`,body:`It holds ${e.files??"over 500"} files; a bundle can hold up to ${Fq}.`};case"noskill":{const s=(e.looked??[]).filter(r=>r!=="");return{title:`No SKILL.md in “${e.filename}”`,body:`buddi looked at the top${s.length?` and inside ${s.join(", ")}`:""}. A bundle needs SKILL.md in one of them, with scripts/ and assets/ beside it.`}}case"paths":{const s=((n=e.entries)==null?void 0:n.length)??0;return{title:`“${e.filename}” was refused`,body:`${s===1?"One entry reaches":`${s===2?"Two":s} entries reach`} outside the bundle, so nothing was unpacked. A bundle holds plain files inside its own folder.`,items:(e.entries??[]).map(r=>({path:r.path,rest:r.why==="is a link"&&r.target?`is a link to ${r.target}`:r.why}))}}case"executable":return{title:`“${e.filename}” was refused`,body:"Something that runs is outside scripts/, so nothing was kept. A bundle keeps anything that runs in scripts/.",items:(e.entries??[]).map(s=>({path:s.path,rest:s.why}))};case"frontmatter":return{title:`“${e.filename}” has no usable SKILL.md`,body:"Its SKILL.md needs front matter with a description (when it’s used) between --- lines, then the steps."};case"notzip":return{title:`“${e.filename}” isn’t a .zip or a .md`,body:"A skill is one Markdown file, or a .zip bundle with SKILL.md inside."};default:return{title:`“${e.filename}” was refused`,body:e.error??"It could not be read as a bundle."}}}function l1(e){const n=e.file.split(/[\\/]/).pop()??e.file;return e.bundle?`skills/${e.name}/${n}`:e.home?`agents/${e.home}/skills/${n}`:`skills/${n}`}function uk(e){return e.every?[]:e.holders.map(n=>n.agent)}function Gq(e,n){var s;if(e.learned){const r=dr(n,e.learned.by);return`Saved as v${e.learned.version+1}, your correction. v${e.learned.version} stays in ${r}’s folder.`}return((s=e.from)==null?void 0:s.kind)==="catalogue"?`${dr(n,e.from.agent)}’s next update will ask before it replaces your change.`:null}function qq(e,n,s){var o;const r=n.stops.map(c=>dr(s,c)),a=e.learned?dr(s,e.learned.by):"";if(e.learned&&!n.every&&n.stops.length===1&&n.stops[0]===e.learned.by)return`${a} stops using it and won’t propose it again for 90 days. Earlier versions stay in its folder.`;const i=n.every?"Every agent stops using it.":r.length===0?"No agent uses it, so nothing changes.":`${ki(r)} ${r.length>1?"stop":"stops"} using it.`,l=n.then==="versions-kept"?`${a} won’t propose it again for 90 days. Earlier versions stay in its folder.`:n.then==="catalogue-asks"?`${((o=e.from)==null?void 0:o.kind)==="catalogue"?dr(s,e.from.agent):"Its teammate"}’s next update asks before bringing it back.`:"The file goes to the trash folder.";return`${i} ${l}`}function Yq(e,n){var c,u;const s=n.replace(/\r\n/g,`
119
- `),r=/^---\n([\s\S]*?)\n---\n*/.exec(s),a=h=>{var f;return(r?((f=new RegExp(`^${h}:\\s*(.*)$`,"m").exec(r[1]))==null?void 0:f[1])??"":"").trim().replace(/^(['"])(.*)\1$/,"$2")},i=r?s.slice(r[0].length):s,l=(u=(c=/^#\s+(.+)$/m.exec(i))==null?void 0:c[1])==null?void 0:u.trim(),o=a("name");return{title:l||(o?JM(o.replace(/-/g," ")):e.replace(/\.md$/i,"")),description:a("description"),body:i}}function Qq(e){const n=e==null?void 0:e.envelope;if(!n||typeof n!="object"||Array.isArray(n))return null;const s=n.skillRun;if(!s||typeof s!="object")return null;const r=s;return typeof r.bundle!="string"||typeof r.script!="string"?null:{bundle:r.bundle,title:typeof r.title=="string"?r.title:r.bundle,script:r.script,interpreter:typeof r.interpreter=="string"?r.interpreter:"",args:Array.isArray(r.args)?r.args.filter(a=>typeof a=="string"):[],reads:typeof r.reads=="string"?r.reads:"",writes:typeof r.writes=="string"?r.writes:"",files:typeof r.files=="number"?r.files:0}}function Xg(e){return/[\s"'\\]/.test(e)||e===""?JSON.stringify(e):e}function Jq(e){const n=[];for(let s=0;s<e.length;s+=1){const r=e[s],a=e[s+1];r.startsWith("-")&&!r.includes("=")&&a!==void 0&&!a.startsWith("-")?(n.push(`${Xg(r)} ${Xg(a)}`),s+=1):n.push(Xg(r))}return n}function Xq({action:e,run:n,agentName:s,count:r,busy:a,error:i,onDecide:l}){const o=a!==null||e.state!=="pending",c=Jq(n.args);return t.jsxs("section",{id:"approval-dock",tabIndex:-1,className:"wb-question skb-dock","data-kind":"approval","aria-label":"Approval needed","data-testid":"approval-dock",children:[t.jsxs("div",{className:"wb-question-head",children:[t.jsx("span",{className:"wb-question-kicker",children:"Needs your OK"}),r>1?t.jsxs("span",{className:"wb-dock-count","data-testid":"approval-dock-count",children:["1 of ",r]}):null,t.jsxs("strong",{children:[s," wants to run a script from ",n.title]})]}),t.jsxs("div",{className:"wb-dock-section wb-dock-subject",children:[t.jsx("code",{className:"wb-dock-gist",children:[n.interpreter,n.script].filter(Boolean).join(" ")}),t.jsx("span",{className:"wb-dock-where",children:"From a bundle you marked as yours."})]}),t.jsx("div",{className:"wb-dock-section",children:t.jsx(on,{items:[{label:"Arguments",value:c.length?t.jsx("span",{className:"mono skb-args",children:c.map((u,h)=>t.jsx("span",{children:u},`${h}:${u}`))}):"None"},{label:"Working folder",value:t.jsx("span",{className:"mono skb-path",children:n.writes})},{label:"What it may touch",value:`Reads ${n.title}’s ${n.files} file${n.files===1?"":"s"} without changing them, and the working folder. Writes only in the working folder.`}]})}),t.jsx(re,{message:i}),t.jsx("div",{className:"wb-dock-section",children:t.jsxs(te,{children:[t.jsx("span",{className:"skb-dock-note",children:"Scripts ask every time."}),t.jsx(ht,{}),t.jsx($,{variant:"ghost",size:"sm",disabled:o,onClick:()=>l("reject"),children:a==="reject"?"Rejecting…":"Reject"}),t.jsx($,{size:"sm",onClick:()=>{window.location.hash=qM(n.bundle,n.script)},children:"Show the script"}),t.jsx($,{variant:"good",size:"sm",disabled:o,onClick:()=>l("approve"),children:a==="approve"?"Allowing…":"Allow once"})]})})]})}function Zq(e,n,s,r){const a=e.width||1,i=e.height||1,l=n.pageScaleFactor||1,o=(s-e.left)*(n.deviceWidth/a)/l,c=((r-e.top)*(n.deviceHeight/i)-n.offsetTop)/l,u=(h,m)=>Math.max(0,Math.min(Math.round(h),Math.round(m)));return{x:u(o,n.deviceWidth),y:u(c,n.deviceHeight)}}function Zg(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}function o1(e){return[...e].length===1&&e.codePointAt(0)>=32&&e.codePointAt(0)!==127}const eY=4e3;function tY(e){return e.replace(/\r\n?/g,`
120
- `).replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g,"").slice(0,eY)}const nY=3e3;async function sY(e,n=typeof navigator>"u"?void 0:navigator.clipboard,s=globalThis.ClipboardItem){if(!n)return!1;if(s&&n.write)try{return await n.write([new s({"text/plain":e.then(a=>new Blob([a],{type:"text/plain"}))})]),!0}catch{}const r=await e.catch(()=>null);if(r===null||!n.writeText)return!1;try{return await n.writeText(r),!0}catch{return!1}}const rY=["left","middle","right"],aY=33,c1=150,u1=1e4;function iY(e,n=800){const s=e.deltaMode===1?16:e.deltaMode===2?n:1;return{dx:e.deltaX*s,dy:e.deltaY*s}}var Xi,Zi,nd,sd,sr;class lY{constructor(n,s=a=>typeof requestAnimationFrame=="function"?requestAnimationFrame(a):setTimeout(a,16),r=a=>{typeof cancelAnimationFrame=="function"?cancelAnimationFrame(a):clearTimeout(a)}){Li(this,Xi,0);Li(this,Zi,0);Li(this,nd,0);Li(this,sd,0);Li(this,sr);this.sendWheel=n,this.schedule=s,this.cancel=r}add(n,s,r){ls(this,Xi,Bt(this,Xi)+s),ls(this,Zi,Bt(this,Zi)+r),ls(this,nd,n.x),ls(this,sd,n.y),Bt(this,sr)===void 0&&ls(this,sr,this.schedule(()=>{ls(this,sr,void 0),this.flush()}))}flush(){Bt(this,sr)!==void 0&&(this.cancel(Bt(this,sr)),ls(this,sr,void 0));const n=a=>Math.max(-u1,Math.min(u1,Math.round(a))),s=n(Bt(this,Xi)),r=n(Bt(this,Zi));ls(this,Xi,0),ls(this,Zi,0),!(s===0&&r===0)&&this.sendWheel({kind:"wheel",x:Bt(this,nd),y:Bt(this,sd),deltaX:s,deltaY:r})}reset(){Bt(this,sr)!==void 0&&this.cancel(Bt(this,sr)),ls(this,sr,void 0),ls(this,Xi,0),ls(this,Zi,0)}}Xi=new WeakMap,Zi=new WeakMap,nd=new WeakMap,sd=new WeakMap,sr=new WeakMap;function oY(e,n,s){if(!s||!e||!ZM(e,n))return!0;const r=n.scrollOffsetX-e.scrollOffsetX,a=n.scrollOffsetY-e.scrollOffsetY;if(r===0&&a===0)return!0;const i=(l,o)=>l!==0&&o!==0&&Math.sign(l)!==Math.sign(o);return!i(r,s.dx)&&!i(a,s.dy)}function vh(e,n){return(e.metaKey||e.ctrlKey)&&!e.altKey&&e.key.toLowerCase()===n}function ZM(e,n){return e.deviceWidth===n.deviceWidth&&e.deviceHeight===n.deviceHeight&&e.pageScaleFactor===n.pageScaleFactor&&e.offsetTop===n.offsetTop&&e.url===n.url}function cY(e){if(e.byteLength<3)return null;const n=new DataView(e);if(n.getUint8(0)!==1)return null;const s=n.getUint16(1);if(e.byteLength<3+s)return null;try{return{metadata:JSON.parse(new TextDecoder().decode(new Uint8Array(e,3,s))),jpeg:new Blob([new Uint8Array(e,3+s)],{type:"image/jpeg"})}}catch{return null}}function uY(e=window.location){return`${e.protocol==="https:"?"wss":"ws"}://${e.host}/api/browser/hand`}const dY=d.forwardRef(function({sessionId:n,csrf:s,onGiveBack:r,connect:a,bare:i=!1,typing:l,onTyping:o,onLocation:c,onLoginSeen:u,onLevel:h},m){const[f,p]=d.useState("connecting"),[x,g]=d.useState(null),[w,v]=d.useState(!1),[j,y]=d.useState(null),[k,N]=d.useState(void 0),[b,S]=d.useState(!1),C=l??b,A=Y=>{o?o(Y):S(Y)},[E,R]=d.useState(0),P=d.useRef(null),O=d.useRef(u);O.current=u;const I=d.useRef(null),F=d.useRef(null),U=d.useRef({at:0});d.useEffect(()=>{var Y,X,oe,ve;l!==void 0&&(l?(X=(Y=F.current)==null?void 0:Y.focus)==null||X.call(Y):(ve=(oe=F.current)==null?void 0:oe.blur)==null||ve.call(oe))},[l]);const L=d.useRef(null),M=d.useRef(null),z=d.useRef(null),D=d.useRef(null),K=d.useRef({arrived:0,drawn:0,shown:null}),B=(Y,X)=>{const oe=K.current,ve=X??++oe.arrived,be=D.current&&Date.now()-D.current.at<c1?D.current:null;if(X===void 0&&!oY(oe.shown,Y.metadata,be)){oe.held={...Y,seq:ve},clearTimeout(oe.timer),oe.timer=setTimeout(()=>{const Ce=K.current.held;K.current.held=void 0,Ce&&B(Ce,Ce.seq)},c1);return}X===void 0&&oe.held&&oe.held.seq<ve&&(oe.held=void 0),typeof createImageBitmap=="function"&&createImageBitmap(Y.jpeg).then(Ce=>{var Ze,Se,Le;const we=I.current,He=K.current;if(!we||ve<=He.drawn){(Ze=Ce.close)==null||Ze.call(Ce);return}He.drawn=ve,He.shown=Y.metadata,(we.width!==Ce.width||we.height!==Ce.height)&&(we.width=Ce.width,we.height=Ce.height),(Se=we.getContext("2d"))==null||Se.drawImage(Ce,0,0),(Le=Ce.close)==null||Le.call(Ce)}).catch(()=>{})};d.useEffect(()=>{const Y=a??(ve=>new WebSocket(ve));let X=!0,oe;try{oe=Y(uY())}catch{p("lost");return}return oe.binaryType="arraybuffer",P.current=oe,oe.onopen=()=>oe.send(JSON.stringify({type:"hello",csrf:s,sessionId:n})),oe.onmessage=ve=>{var Ce;if(!X)return;if(typeof ve.data!="string"){const we=cY(ve.data);if(!we)return;y(He=>He&&ZM(He,we.metadata)?He:we.metadata),v(!0),we.metadata.level&&N(we.metadata.level),B(we);return}const be=JSON.parse(ve.data);if(be.type==="driving"){p("driving"),g(null);return}if(be.type==="clipboard"){const we=L.current;L.current=null,we==null||we.answer(typeof be.text=="string"?be.text:"");return}if(be.type==="loginSeen"){typeof be.id=="string"&&typeof be.site=="string"&&typeof be.username=="string"&&((Ce=O.current)==null||Ce.call(O,{id:be.id,site:be.site,username:be.username,...be.update===!0?{update:!0}:{}}));return}(be.type==="refused"||be.type==="ended")&&(g(be.error??"The screen cannot be driven from here."),p("refused"))},oe.onclose=()=>{X&&p(ve=>ve==="refused"?ve:"lost")},oe.onerror=()=>{X&&p(ve=>ve==="refused"?ve:"lost")},()=>{var ve;X=!1,P.current=null,(ve=z.current)==null||ve.reset(),clearTimeout(K.current.timer),K.current.held=void 0;try{oe.close()}catch{}}},[n,s,E,a]),d.useEffect(()=>()=>{clearTimeout(U.current.timer)},[]);const se=j==null?void 0:j.url;d.useEffect(()=>{se&&(c==null||c(se))},[se]),d.useEffect(()=>{k&&(h==null||h(k))},[k]);const W=d.useCallback(Y=>{const X=P.current;if(X)try{X.send(JSON.stringify({type:"input",input:Y}))}catch{}},[]);z.current||(z.current=new lY(Y=>W(Y))),d.useImperativeHandle(m,()=>({nav:(Y,X)=>P.current?(W({kind:"nav",action:Y,...Y==="navigate"&&X?{url:X}:{}}),!0):!1,snapshot:()=>{const Y=I.current;if(!Y||K.current.drawn===0||!Y.width||!Y.height)return null;try{const X=Y.toDataURL("image/jpeg",.85);return typeof X=="string"&&X.startsWith("data:image/")?X:null}catch{return null}}}),[W]);const xe=Y=>{var ve;const X=I.current;if(!X||!j)return null;const oe=(ve=X.getBoundingClientRect)==null?void 0:ve.call(X);return oe?Zq(oe,j,Y.clientX,Y.clientY):null},me=Y=>{const X=U.current,oe=Date.now();clearTimeout(X.timer),X.timer=void 0;const ve=X.at+aY-oe;if(ve<=0){X.at=oe,X.pending=void 0,W(Y);return}X.pending=Y,X.timer=setTimeout(()=>{const be=U.current.pending;U.current.timer=void 0,U.current.pending=void 0,U.current.at=Date.now(),be&&W(be)},ve)},ie=()=>{const Y=U.current;clearTimeout(Y.timer),Y.timer=void 0;const X=Y.pending;Y.pending=void 0,X&&(Y.at=Date.now(),W(X))},H=Y=>X=>{var be,Ce,we;const oe=xe(X);if(!oe)return;Y==="mousePressed"&&(X.preventDefault(),(Ce=(be=I.current)==null?void 0:be.focus)==null||Ce.call(be));const ve={kind:"mouse",type:Y,x:oe.x,y:oe.y,button:rY[X.button]??"left",clickCount:Y==="mouseMoved"?0:Math.min(3,Math.max(1,X.detail||1)),modifiers:Zg(X)};if(Y==="mouseMoved"){me(ve);return}ie(),(we=z.current)==null||we.flush(),W(ve)},de=d.useRef(xe);de.current=xe,d.useEffect(()=>{const Y=I.current;if(!w||!Y)return;const X=oe=>{var we,He,Ze,Se;oe.preventDefault();const ve=de.current(oe);if(!ve)return;ie();const{dx:be,dy:Ce}=iY(oe,((we=Y.getBoundingClientRect)==null?void 0:we.call(Y).height)||800);D.current={dx:be||((He=D.current)==null?void 0:He.dx)||0,dy:Ce||((Ze=D.current)==null?void 0:Ze.dy)||0,at:Date.now()},(Se=z.current)==null||Se.add(ve,be,Ce)};return Y.addEventListener("wheel",X,{passive:!1}),()=>Y.removeEventListener("wheel",X)},[w]);const ge=Y=>Y.ctrlKey||Y.metaKey||Y.altKey,Ue=Y=>{var oe,ve;if(Y.key==="Escape"&&ge(Y)){A(!1),(ve=(oe=Y.target).blur)==null||ve.call(oe);return}if(vh(Y,"v")){J(Y.currentTarget);return}if(Y.preventDefault(),vh(Y,"c")){Ie();return}const X=Zg(Y);if(o1(Y.key)&&!ge(Y)){W({kind:"key",type:"char",key:Y.key,code:Y.code,text:Y.key,modifiers:X});return}W({kind:"key",type:"keyDown",key:Y.key,code:Y.code,modifiers:X})},G=Y=>{Y.key==="Escape"&&ge(Y)||vh(Y,"v")||(Y.preventDefault(),!vh(Y,"c")&&(o1(Y.key)&&!ge(Y)||W({kind:"key",type:"keyUp",key:Y.key,code:Y.code,modifiers:Zg(Y)})))},ae=Y=>{var oe;Y.preventDefault(),Ne();const X=tY(((oe=Y.clipboardData)==null?void 0:oe.getData("text/plain"))??"");X!==""&&W({kind:"text",text:X})},J=Y=>{var oe;const X=F.current;!X||Y===X||(M.current=Y,(oe=X.focus)==null||oe.call(X,{preventScroll:!0}),setTimeout(Ne,250))},Ne=()=>{var X;const Y=M.current;M.current=null,(X=Y==null?void 0:Y.focus)==null||X.call(Y,{preventScroll:!0})},Ie=()=>{var X;(X=L.current)==null||X.answer("");const Y=new Promise((oe,ve)=>{const be=setTimeout(()=>{var we;((we=L.current)==null?void 0:we.answer)===Ce&&(L.current=null),ve(new Error("no answer"))},nY),Ce=we=>{clearTimeout(be),we===""?ve(new Error("nothing selected")):oe(we)};L.current={answer:Ce}});Y.catch(()=>{}),W({kind:"copy"}),sY(Y)};return t.jsxs("section",{className:"hand","data-testid":"remote-hand","data-phase":f,"data-bare":i?"true":void 0,"aria-label":"Driving the page",children:[i?null:t.jsxs("div",{className:"hand-bar",children:[t.jsx("span",{className:"hand-said",role:"status",children:"You have the page. Nothing you type here is kept."}),t.jsxs(te,{align:"end",children:[t.jsx($,{size:"sm",variant:C?"accent":"ghost","aria-pressed":C,onClick:()=>{var X,oe,ve,be;const Y=!C;A(Y),Y?(oe=(X=F.current)==null?void 0:X.focus)==null||oe.call(X):(be=(ve=F.current)==null?void 0:ve.blur)==null||be.call(ve)},children:"Keyboard"}),t.jsx($,{size:"sm",variant:"accent",onClick:r,children:"Give it back"})]})]}),f==="lost"?t.jsxs(Q,{tone:"warning",role:"status",children:["Connection lost. The picture below is the last frame that arrived.",t.jsx(te,{align:"end",children:t.jsx($,{size:"sm",variant:"accent",onClick:()=>{p("connecting"),R(Y=>Y+1)},children:"Reconnect"})})]}):null,f==="refused"&&x?t.jsx(Q,{tone:"warning",role:"status",children:x}):null,t.jsx("div",{className:"hand-screen",children:w?t.jsx("canvas",{ref:I,className:"hand-picture",role:"img","aria-label":"The host browser, live","data-testid":"hand-picture",tabIndex:0,onMouseDown:H("mousePressed"),onMouseUp:H("mouseReleased"),onMouseMove:H("mouseMoved"),onKeyDown:Ue,onKeyUp:G,onPaste:ae,onContextMenu:Y=>Y.preventDefault()}):t.jsx("p",{className:"muted hand-waiting",children:f==="lost"?"No picture arrived before the connection dropped.":"Waiting for the first frame…"})}),t.jsx("input",{ref:F,className:"hand-typing","aria-label":"Type into the host browser",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,value:"",onChange:()=>{},onKeyDown:Ue,onKeyUp:G,onPaste:ae,onBlur:()=>{M.current||A(!1)}})]})});function hY(e){return e==="darwin"?"this Mac":"this computer"}let ex=null;function cc(){const[e,n]=d.useState(void 0);return d.useEffect(()=>{let s=!0;return ex??(ex=Promise.resolve().then(()=>T.session()).then(r=>r.platform,()=>{ex=null})),ex.then(r=>{s&&n(r)}),()=>{s=!1}},[]),hY(e)}const fY="sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0";function mY({timezone:e,navigate:n}={}){var u;const{data:s,error:r,reload:a}=je(()=>T.browser(),[],3e3),i=je(()=>T.session(),[]),l=(u=i.data)!=null&&u.platform?i.data.platform==="darwin":!0,o=!!i.data||!!i.error,c=h=>{n?n(h):window.location.hash=h};return t.jsxs("div",{className:"ui-stack br-looking","data-gap":"lg",children:[t.jsx(re,{message:r}),!s||!o?t.jsx(Ee,{children:"Checking where agents may look…"}):t.jsx(yY,{data:s,macOS:l,reload:a,timezone:e,go:c})]})}function dk({kind:e}){const n={own:t.jsxs("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"12.8",rx:"1.8"}),t.jsx("path",{d:"M2.8 7.2h14.4M5.4 5.4h.1M7.4 5.4h.1"})]}),chrome:t.jsxs("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"10",cy:"10",r:"7.1"}),t.jsx("circle",{cx:"10",cy:"10",r:"2.6"}),t.jsx("path",{d:"M10 7.4h6.6M7.8 11.4 4.4 5.6M12.2 11.4 9 16.9"})]}),apps:t.jsxs("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"3",width:"6",height:"6",rx:"1.4"}),t.jsx("rect",{x:"11",y:"3",width:"6",height:"6",rx:"1.4"}),t.jsx("rect",{x:"3",y:"11",width:"6",height:"6",rx:"1.4"}),t.jsx("rect",{x:"11",y:"11",width:"6",height:"6",rx:"1.4"})]})}[e];return t.jsx("span",{className:"br-glyph","aria-hidden":"true",children:n})}function Cr({line:e,status:n,tone:s,children:r}){return t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"pl-row-line",children:e}),n?t.jsx("span",{className:"pl-row-status","data-tone":s,children:n}):null,r]})}function pY({text:e}){const[n,s]=d.useState(!1);return t.jsxs("span",{className:"br-copy",children:[t.jsx("code",{className:"mono",children:e}),t.jsx($,{size:"sm",variant:"ghost",onClick:()=>{var r;(r=navigator.clipboard)==null||r.writeText(e).then(()=>s(!0),()=>{})},children:n?"Copied":"Copy"})]})}function yh({label:e,hint:n,children:s}){return t.jsxs("div",{className:"br-adv-row",children:[t.jsxs("span",{className:"br-adv-head",children:[t.jsx("span",{className:"br-adv-title",children:e}),n?t.jsx("span",{className:"br-adv-hint",children:n}):null]}),s]})}function Sp(e){const n=e.split(".").filter(Boolean).at(-1)??e;return n.charAt(0).toUpperCase()+n.slice(1)}function gY(e){return e.length<=2?e.join(" and "):`${e.slice(0,2).join(", ")} and ${e.length-2} more`}const xY=[{value:"auto",label:"Let it choose"},{value:"own",label:"Its own browser only"},{value:"chrome",label:"Your Chrome first"},{value:"apps",label:"Your apps first"}];function zv({value:e,label:n,apps:s,disabled:r,onChange:a}){return t.jsx("select",{className:"br-select",value:e,"aria-label":n,disabled:r,onChange:i=>a(i.target.value),children:xY.filter(i=>s||i.value!=="apps"||e==="apps").map(i=>t.jsx("option",{value:i.value,children:i.label},i.value))})}function jY(e){return(e==null?void 0:e.installed)===!0}function vY(e,n){var s;return e?e.pending?"pair":e.pairedAt?e.connected?"connected":(s=n==null?void 0:n.pairings)!=null&&s.some(r=>Yu(r.origin)&&r.enabled===!1)?"off":n&&n.state!=="paired"&&(Yu(n.gateway)||Uv(n))?"broken":"notrunning":n&&n.state!=="paired"?"pair":"none":"none"}function Uv(e){return Array.isArray(e.pairings)}function d1(e){return e!=null&&e.pairings?e.pairings.filter(n=>!Yu(n.origin)).length:0}function h1(e){return e<=0?null:`paired with this buddi and ${e} other${e===1?"":"s"}`}function yY({data:e,macOS:n,reload:s,timezone:r,go:a}){var v,j;const[i,l]=d.useState(!1),[o,c]=d.useState(null),u=async y=>{l(!0),c(null);try{await y()}catch(k){c(k instanceof Error?k.message:String(k))}finally{l(!1),s()}},h=e.settings,m=y=>void u(()=>T.browserSettings(y)),f=r??Intl.DateTimeFormat().resolvedOptions().timeZone,p=e.learnedSignInSites??[],x=(v=e.routes)==null?void 0:v.find(y=>y.kind==="apps"),g=jY(x),w=(j=e.sessions)!=null&&j.length?e.sessions:e.session?[e]:[];return t.jsxs(t.Fragment,{children:[t.jsx(Q,{children:"Agents pick where to look for each task: their own browser first, your Chrome for a site that needs your sign-in, an app when you name one. You don’t choose each time; here you say what they may use."}),t.jsx(re,{message:o}),e.enabled?null:t.jsx(Q,{tone:"warning",children:"Agents can’t look at pages from here. Start buddi serve on the machine buddi runs on."}),e.stop?t.jsx(Q,{tone:"warning",role:"status",action:t.jsx($,{size:"sm",variant:"accent",disabled:i,onClick:()=>void u(()=>T.browserControl("resume")),children:"Resume"}),children:`Agents’ browsing is paused since ${Lt(new Date(e.stop.at),f)}, by you from the Canvas, ${e.stop.until?`until ${Lt(new Date(e.stop.until),f)}`:"until you resume it"}. An agent that needs a page asks you in its chat.`}):null,t.jsx(lt,{title:"Browsers and apps",flush:!0,children:t.jsxs("div",{className:"ui-list",children:[t.jsx(NY,{data:e,busy:i,run:u}),h?t.jsx(SY,{settings:h,learned:p,busy:i||!e.enabled,save:m,zone:f}):null,g&&h?t.jsx(CY,{route:x,settings:h,busy:i||!e.enabled,save:m,run:u,onSettings:()=>a(Or(x.provider||"computer"))}):null]})}),t.jsx(kY,{busy:i,run:u}),!g&&n?t.jsxs("p",{className:"pl-note br-foot","data-testid":"computer-plugin-offer",children:["Agents can also work in apps on this Mac with the Computer plugin. ",t.jsx("a",{href:"#/settings/plugins?tab=browse&kind=plugins",children:"See plugins"})]}):null,w.length>0?t.jsx(lt,{title:"Looking now",flush:!0,actions:t.jsx($,{size:"sm",disabled:i,onClick:()=>void u(()=>T.browserControl("stop")),children:"Stop agents’ browsing"}),children:t.jsx("div",{className:"ui-list",children:w.map(y=>{var k;return t.jsxs("a",{className:"ui-list-row",href:ut(y.session.agentId,y.session.conversationId,"browser"),children:[t.jsx(Bn,{id:y.session.agentId,name:y.session.agentId,size:"sm"}),t.jsxs("span",{className:"ui-list-main",children:[t.jsx("span",{className:"ui-list-title",children:((k=y.page)==null?void 0:k.title)||y.session.task}),t.jsx("span",{className:"ui-list-sub",children:e2(y)})]}),t.jsx("span",{className:"ui-list-side",children:"Open the Canvas"})]},y.session.id)})})}):null,h?t.jsx(EY,{settings:h,learned:p,busy:i,save:m,run:u,showApps:g}):null]})}function wY(e){return`${e.files===0?"Nothing waiting":`${e.files} ${e.files===1?"file":"files"} waiting · ${Yn(e.bytes)}`} · kept ${e.retentionDays} days, at most ${Yn(e.fileCap)} a file`}function bY(e){return`${e===1?"This file is":`These ${e} files are`} not in Files: ${e===1?"it is the only copy":"they are the only copies"}. Clearing deletes ${e===1?"it":"them"} for good. File ${e===1?"it":"the ones you want"} first.`}function kY({busy:e,run:n}){var m;const s=je(()=>T.browserDownloads(),[],3e4),r=je(()=>T.agents(),[]),[a,i]=d.useState(!1),l=s.data,o=(l==null?void 0:l.waiting)??[],c=new Map((((m=r.data)==null?void 0:m.agents)??[]).map(f=>[f.id,f.name])),u=f=>void n(async()=>{await T.fileBrowserDownload(f),s.reload()}),h=()=>void n(async()=>{i(!1),await T.clearBrowserDownloads(),s.reload()});return t.jsxs(lt,{title:"Downloads",flush:!0,children:[t.jsxs("div",{className:"ui-list",children:[t.jsxs("div",{className:"ui-list-row","data-testid":"downloads-row",children:[t.jsxs("span",{className:"ui-list-main",children:[t.jsx("span",{className:"ui-list-title",children:"Files agents download"}),t.jsxs("span",{className:"ui-list-sub",children:[l?wY(l):"Checking…",". A download goes straight to Files; only one that could not be filed waits here."]}),t.jsx("span",{className:"ui-list-sub",children:"In your Chrome, agents’ downloads need the extension’s Downloads permission: open the buddi extension and press Allow downloads. Downloads you start yourself are never read."})]}),t.jsx("span",{className:"ui-list-side",children:t.jsx($,{size:"sm",disabled:e||!l||l.files===0,onClick:()=>i(!0),children:"Clear"})})]}),o.map(f=>t.jsxs("div",{className:"ui-list-row","data-testid":"download-waiting",children:[t.jsxs("span",{className:"ui-list-main",children:[t.jsx("span",{className:"ui-list-title",children:f.name}),t.jsx("span",{className:"ui-list-sub",children:`${c.get(f.agent)??f.agent} · ${Zo(f.day)} · ${Yn(f.size)} · not in Files yet`})]}),t.jsx("span",{className:"ui-list-side",children:t.jsx($,{size:"sm",variant:"accent",disabled:e,onClick:()=>u(f.id),children:"File it"})})]},f.id))]}),a&&l?t.jsx(Gt,{title:`Clear ${l.files} ${l.files===1?"download":"downloads"}?`,onClose:()=>i(!1),foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:()=>i(!1),children:l.files===1?"Keep it":"Keep them"}),t.jsx($,{variant:"danger",disabled:e,onClick:h,children:`Clear ${l.files}`})]}),children:t.jsx("p",{children:bY(l.files)})}):null]})}function e2(e){var s,r;return e.needsOwner?`Waiting for you · ${e.needsOwner.kind==="human"?"it asks for a human":e.needsOwner.kind==="uncertain"?"did that click land?":e.needsOwner.kind==="budget"?"keep going?":"it asks for your sign-in"}`:e.route==="apps"?`Working in ${(s=e.page)!=null&&s.appId?Sp(e.page.appId):"an app"} · its own window`:`Looking at ${hk((r=e.page)==null?void 0:r.url)??"a page"} · ${e.route==="chrome"?"in your Chrome · background tab":"in buddi’s browser"}`}function hk(e){if(e)try{return new URL(e).hostname.replace(/^www\./,"")||void 0}catch{return}}function NY({data:e,busy:n,run:s}){var c,u,h;const r=e.browser,a=r==null?void 0:r.install,i=(c=e.settings)!=null&&c.showWindow?"For every page, in a window on this machine":"For every page, out of sight";let l,o;if((a==null?void 0:a.state)==="running"){const m=(u=a.progress)==null?void 0:u.percent;l=t.jsx(Cr,{line:i,status:t.jsxs("span",{className:"br-installing",children:[t.jsx("span",{className:"pl-spin","aria-hidden":"true"}),`Installing Chromium…${m!==void 0?` ${Math.round(m)}%`:""}`]})}),o=null}else(r==null?void 0:r.engine)==="none"?(l=t.jsx(Cr,{line:i,tone:"critical",status:(a==null?void 0:a.state)==="failed"?`The install didn’t finish: ${a.line??"no reason given"}`:"Chromium isn’t installed, so agents can’t look at pages yet."}),o=t.jsx($,{size:"sm",variant:"accent",disabled:n,onClick:()=>void s(()=>T.browserInstall()),children:"Install · 150 MB"})):(r==null?void 0:r.problem)==="no-sandbox"?(l=t.jsx(Cr,{line:i,tone:"critical",status:"Linux blocks its sandbox (AppArmor). Run this once, then Check again:",children:t.jsx(pY,{text:fY})}),o=t.jsx($,{size:"sm",disabled:n,onClick:()=>void s(()=>T.browserCheck()),children:"Check again"})):r!=null&&r.problem?(l=t.jsx(Cr,{line:i,tone:"critical",status:r.message??"It doesn’t start on this machine."}),o=t.jsx($,{size:"sm",disabled:n,onClick:()=>void s(()=>T.browserCheck()),children:"Check again"})):(l=(h=e.settings)!=null&&h.showWindow?"For every page, in a window on this machine. You also watch it on the Canvas.":"For every page, out of sight. You watch it on the Canvas.",o=e.enabled?t.jsx($e,{tone:"good",dot:!0,children:"ready"}):null);return t.jsxs("div",{className:"ui-list-row",children:[t.jsx(dk,{kind:"own"}),t.jsxs("span",{className:"ui-list-main",children:[t.jsx("span",{className:"ui-list-title",children:"buddi’s own browser"}),t.jsx("span",{className:"ui-list-sub",children:l})]}),o?t.jsx("span",{className:"ui-list-side",children:t.jsx("span",{className:"br-side",children:o})}):null]})}const f1=1e4;async function m1(e,n={pair:s=>T.pairExtension(s),extension:()=>T.extension()}){try{await n.pair(e)}catch(s){if((s==null?void 0:s.status)!==409)throw s;const r=(n.now??Date.now)(),a=await n.extension().catch(()=>{}),i=a!=null&&a.pairedAt?Date.parse(a.pairedAt):NaN;if(!(Number.isFinite(i)&&r-i>=-f1&&r-i<=f1))throw s}t2()}function t2(){if(typeof window>"u")return;const e=window.location.hash,n=Z8(e);if(n!==e)try{window.history.replaceState(window.history.state,"",`${window.location.pathname}${window.location.search}${n}`)}catch{}}function SY({settings:e,learned:n,busy:s,save:r,zone:a}){var D,K,B,se,W,xe,me,ie,H,de;const i=je(()=>T.extension(),[],3e3),l=je(()=>IY(),[],3e3).data??null,o=cc(),[c,u]=d.useState(()=>DS(typeof window>"u"?"":window.location.hash)??"");d.useEffect(()=>{const ge=()=>{const Ue=DS(window.location.hash);Ue&&u(Ue)};return window.addEventListener("hashchange",ge),()=>window.removeEventListener("hashchange",ge)},[]);const[h,m]=d.useState(!1),[f,p]=d.useState(null),[x,g]=d.useState(!1),[w,v]=d.useState(!1),j=vY(i.data,l),y=PY(),k=async ge=>{m(!0),p(null);try{await ge()}catch(Ue){p(Ue instanceof Error?Ue.message:String(Ue))}finally{m(!1),i.reload()}},N=(D=i.data)!=null&&D.pending&&(l==null?void 0:l.state)==="pairing"?l.code??"":"",b=d.useRef("");d.useEffect(()=>{!N||b.current===N||h||(b.current=N,k(async()=>{await T.pairExtension(N),t2()}))},[N]);const S=s||h,C=(K=i.data)!=null&&K.pairedAt?`paired ${St(i.data.pairedAt,a)}`:null,A=(l==null?void 0:l.version)??((B=i.data)==null?void 0:B.extension),E=t.jsx(rs,{label:"More for your Chrome",items:[C||j==="broken"||j==="notrunning"||j==="connected"?{label:"Pair again",hint:[A?`Extension ${A}`:null,C].filter(Boolean).join(" · ")||void 0,onSelect:()=>void k(()=>T.forgetExtension())}:null,(se=i.data)!=null&&se.checkout?{label:"Install unpacked…",hint:"For a developer build of the extension",onSelect:()=>v(!0)}:null,(W=i.data)!=null&&W.pairedAt?"separator":null,(xe=i.data)!=null&&xe.pairedAt?{label:"Forget this Chrome…",tone:"critical",onSelect:()=>g(!0)}:null]}),R=t.jsxs("span",{className:"br-pair",children:[t.jsx("input",{"aria-label":"Pairing code",inputMode:"numeric",autoComplete:"one-time-code",maxLength:7,placeholder:"482 913",value:c,onChange:ge=>u(ge.target.value),onKeyDown:ge=>{ge.key==="Enter"&&c.replace(/[^0-9]/g,"").length===6&&!S&&k(async()=>{await m1(c),u("")})}}),t.jsx($,{size:"sm",variant:"accent",disabled:S||c.replace(/[^0-9]/g,"").length!==6,onClick:()=>void k(async()=>{await m1(c),u("")}),children:"Pair"})]}),P=t.jsxs("span",{className:"br-enter-code",children:[t.jsx("span",{className:"pl-row-line",children:"Enter the code · Open the buddi icon in Chrome; type its code here"}),R]}),O=[...e.signInSites,...n],I=O.length>0?`Always for ${gY(O)}`:null;let F,U;if(j==="none")F=t.jsx(Cr,{line:"For sites that need your sign-in",status:y==="chromium"?"Add the buddi extension to Chrome, then pair it here. Until then agents use their own browser and your saved logins.":"The buddi extension runs in Chrome, Edge, Brave or Arc on a computer: add it there, then pair it on this page. Until then agents use their own browser and your saved logins.",children:P}),U=t.jsxs(t.Fragment,{children:[y==="chromium"?t.jsxs(it,{size:"sm",variant:"accent",href:n2,target:"_blank",rel:"noopener noreferrer",children:["Add to Chrome ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):null,E]});else if(j==="pair"){const ge=l?`Extension ${l.version} found in Chrome`:"The buddi extension asks to pair",Ue=l&&Uv(l)&&(l.pairings??[]).length>0&&!l.pairings.some(G=>Yu(G.origin))?"Open the extension and press Add a buddi: it offers this buddi’s address, then shows a code, and this page pairs with it.":"Open the extension and press Connect: it shows a code, and this page pairs with it.";F=N?t.jsx(Cr,{line:ge,status:"Pairing with the code the extension shows. This finishes by itself.",children:t.jsx("span",{className:"br-code mono","aria-label":"Pairing code",children:N.replace(/^(\d{3})(\d{3})$/,"$1 · $2")})}):(me=i.data)!=null&&me.pending?t.jsx(Cr,{line:ge,status:"Type the six digits the extension shows.",children:R}):t.jsx(Cr,{line:ge,status:Ue,children:P}),U=E}else if(j==="broken")F=t.jsx(Cr,{line:"Used only for sites that need your sign-in",tone:"critical",status:"Chrome forgot the pairing, so agents use their own browser instead."}),U=t.jsxs(t.Fragment,{children:[t.jsx($,{size:"sm",variant:"accent",disabled:S,onClick:()=>void k(()=>T.forgetExtension()),children:"Pair again"}),E]});else{const ge=e.yourChrome?j==="notrunning"?`Used only for sites that need your sign-in · Chrome isn’t open on ${o}; agents wait or use their own browser`:j==="off"?"Switched off for this buddi in the buddi extension · turn it on in its popup; until then agents use their own browser":`Used only for sites that need your sign-in · background tabs in a buddi group${h1(d1(l))?` · ${h1(d1(l))}`:""}`:"Off. Sites that need a sign-in use your saved logins, or ask you.";F=I&&e.yourChrome?t.jsx(Cr,{line:ge,status:I}):ge,U=t.jsxs(t.Fragment,{children:[e.yourChrome?j==="notrunning"?t.jsx($e,{children:"Chrome closed"}):j==="off"?t.jsx($e,{children:"off in Chrome"}):t.jsx($e,{tone:"good",dot:!0,children:"connected"}):null,t.jsx(ac,{checked:e.yourChrome,label:"Let agents use your Chrome",disabled:S,onChange:Ue=>r({yourChrome:Ue})}),E]})}const L=l&&((ie=i.data)!=null&&ie.extensionMinimum)&&RY(l.version,i.data.extensionMinimum)?`This extension is ${l.version}; this buddi needs ${i.data.extensionMinimum} or later. Update it from chrome://extensions or the store.`:null,M=l&&!Uv(l)&&!Yu(l.gateway)?`The extension is pointed at ${l.gateway}; set it to ${window.location.origin} in its popup.`:null,z=(H=i.data)!=null&&H.portMoved&&j!=="pair"?`Port ${i.data.portMoved.from} was taken by another program, so buddi now listens on ${i.data.portMoved.to}. Pair the extension again: in its popup press Add a buddi with http://127.0.0.1:${i.data.portMoved.to}.`:null;return z&&j!=="broken"&&j!=="none"&&(U=t.jsxs(t.Fragment,{children:[t.jsx($,{size:"sm",variant:"accent",disabled:S,onClick:()=>void k(()=>T.forgetExtension()),children:"Pair again"}),E]})),t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"ui-list-row",children:[t.jsx(dk,{kind:"chrome"}),t.jsxs("span",{className:"ui-list-main",children:[t.jsx("span",{className:"ui-list-title",children:"Your Chrome"}),t.jsxs("span",{className:"ui-list-sub",children:[F,L?t.jsx("span",{className:"pl-row-status","data-tone":"warning",children:L}):null,M?t.jsx("span",{className:"pl-row-status","data-tone":"warning",children:M}):null,z?t.jsx("span",{className:"pl-row-status","data-tone":"warning",children:z}):null,f??i.error?t.jsx("span",{className:"pl-row-status","data-tone":"critical",children:f??i.error}):null]})]}),t.jsx("span",{className:"ui-list-side",children:t.jsx("span",{className:"br-side",children:U})})]}),x?t.jsx("div",{className:"br-confirm",children:t.jsx(Q,{tone:"warning",action:t.jsxs(te,{align:"end",children:[t.jsx($,{size:"sm",variant:"ghost",onClick:()=>g(!1),children:"Cancel"}),t.jsx($,{size:"sm",variant:"danger",disabled:S,onClick:()=>{g(!1),k(()=>T.forgetExtension())},children:"Forget"})]}),children:"Forget this Chrome? Agents stop using it until you pair it again."})}):null,w?t.jsxs(Ye,{title:"Install the extension unpacked",onClose:()=>v(!1),children:[t.jsx("div",{className:"ui-prose muted",children:t.jsx("p",{children:"For a developer build. Open chrome://extensions, turn on Developer mode, choose Load unpacked, and pick this folder. Then pair it on this page."})}),t.jsx(Zt,{label:"The unpacked extension",children:((de=i.data)==null?void 0:de.path)??"…"})]}):null]})}function CY({route:e,settings:n,busy:s,save:r,run:a,onSettings:i}){const l=n.yourApps!=="off",o=`From the ${e.label??Sp(e.provider.replace(/^@withbuddi\/plugin-/,""))} plugin`,c=l&&!e.available&&!!e.message,u=c?t.jsx(Cr,{line:o,tone:"critical",status:e.message}):l?`${o} · ${n.yourApps==="ask"?"asks for each app":"when you name an app"}`:"Off. Agents tell you when a task needs an app.";return t.jsxs("div",{className:"ui-list-row",children:[t.jsx(dk,{kind:"apps"}),t.jsxs("span",{className:"ui-list-main",children:[t.jsx("span",{className:"ui-list-title",children:"Your apps"}),t.jsx("span",{className:"ui-list-sub",children:u})]}),t.jsx("span",{className:"ui-list-side",children:t.jsxs("span",{className:"br-side",children:[c&&e.repair==="permissions"?t.jsx($,{size:"sm",variant:"accent",onClick:i,children:"Allow in macOS"}):null,!c&&l?t.jsx($e,{tone:"good",dot:!0,children:"ready"}):null,c&&e.repair==="permissions"?null:t.jsx(ac,{checked:l,label:"Let agents use your apps",disabled:s,onChange:h=>r({yourApps:h?"on":"off"})}),t.jsxs($,{size:"sm",variant:"ghost","aria-label":"Manage apps",onClick:i,children:["Settings",t.jsx(ne,{name:"chevron-right",size:12})]})]})})]})}function EY({settings:e,learned:n,busy:s,save:r,run:a,showApps:i}){var b;const l=je(()=>T.agents(),[]),o=((b=l.data)==null?void 0:b.engines)??[],c=o.filter(S=>S.browser&&S.browser!=="auto"),u=o.filter(S=>!S.browser||S.browser==="auto"),[h,m]=d.useState(!1),[f,p]=d.useState(""),[x,g]=d.useState("own"),[w,v]=d.useState(""),j=(S,C)=>void a(async()=>{await T.setAgentEngine(S,{browser:C}),l.reload()}),y=e.defaultRoute==="apps"?"auto":e.defaultRoute,k=[1,3,5].includes(e.maxOwnPages)?[1,3,5]:[1,3,5,e.maxOwnPages].sort((S,C)=>S-C),N=()=>{const S=w.trim().toLowerCase().replace(/^https?:\/\//,"").replace(/\/.*$/,"").replace(/^www\./,"");if(!S||e.signInSites.includes(S)||n.includes(S)){v("");return}r({signInSites:[...e.signInSites,S]}),v("")};return t.jsx(Vt,{boxed:!0,summary:"Advanced",children:t.jsxs("div",{className:"br-adv",children:[t.jsx(yh,{label:"First choice for every agent",hint:"Let them choose is right for almost everyone: a wrong guess costs one extra page load, never a stop.",children:t.jsx(cn,{label:"First choice for every agent",value:y,onChange:S=>r({defaultRoute:S}),options:[{value:"auto",label:"Let them choose"},{value:"own",label:"Own browser only"},{value:"chrome",label:"Your Chrome first"}]})}),t.jsxs("div",{className:"br-adv-block",children:[t.jsxs("span",{className:"br-adv-head",children:[t.jsx("span",{className:"br-adv-title",children:"Agents with their own rule"}),t.jsx("span",{className:"br-adv-hint",children:"Also on each agent’s page, under Where it may look. A rule never allows what is off above."})]}),c.length?t.jsx("div",{className:"ui-list",children:c.map(S=>t.jsxs("div",{className:"ui-list-row",children:[t.jsx(Bn,{id:S.id,name:S.name,size:"sm"}),t.jsx("span",{className:"ui-list-main",children:t.jsx("span",{className:"ui-list-title",children:S.name})}),t.jsxs("span",{className:"ui-list-side",children:[t.jsx(zv,{value:S.browser??"auto",label:`Where ${S.name} may look`,apps:i,disabled:s,onChange:C=>j(S.id,C)}),t.jsx($,{size:"sm",variant:"ghost",disabled:s,onClick:()=>j(S.id,"auto"),children:"Remove"})]})]},S.id))}):t.jsx("p",{className:"br-adv-empty",children:"No agent has its own rule. Every agent follows the first choice."}),h?t.jsxs(te,{children:[t.jsxs("select",{className:"br-select","aria-label":"Agent",value:f,onChange:S=>p(S.target.value),children:[t.jsx("option",{value:"",children:"Choose an agent"}),u.map(S=>t.jsx("option",{value:S.id,children:S.name},S.id))]}),t.jsx(zv,{value:x,label:"Its rule",apps:i,onChange:g}),t.jsx(ht,{}),t.jsx($,{size:"sm",variant:"ghost",onClick:()=>m(!1),children:"Cancel"}),t.jsx($,{size:"sm",variant:"accent","aria-label":"Add this rule",disabled:s||!f||x==="auto",onClick:()=>{j(f,x),m(!1),p("")},children:"Add"})]}):t.jsx(te,{children:t.jsxs($,{size:"sm",disabled:u.length===0,onClick:()=>m(!0),children:[t.jsx("span",{"aria-hidden":"true",children:"+"})," Give an agent its own rule"]})})]}),t.jsxs("div",{className:"br-adv-block",children:[t.jsxs("span",{className:"br-adv-head",children:[t.jsx("span",{className:"br-adv-title",children:"Sites that need your sign-in"}),t.jsx("span",{className:"br-adv-hint",children:"Always looked at in your Chrome while it is on and connected. buddi adds a site, outlined dashed, when it meets its sign-in page."})]}),e.signInSites.length||n.length?t.jsxs("span",{className:"br-sites",children:[e.signInSites.map(S=>t.jsxs("span",{className:"br-site-chip mono",children:[S,t.jsx("button",{type:"button","aria-label":`Remove ${S}`,disabled:s,onClick:()=>r({forgetSignInSite:S}),children:"×"})]},S)),n.map(S=>t.jsxs("span",{className:"br-site-chip mono","data-learned":"true",title:"buddi added this when it met its sign-in page",children:[S,t.jsx("button",{type:"button","aria-label":`Remove ${S}`,disabled:s,onClick:()=>r({forgetSignInSite:S}),children:"×"})]},S))]}):t.jsx("p",{className:"br-adv-empty",children:"None yet."}),t.jsxs("form",{className:"br-site-add",onSubmit:S=>{S.preventDefault(),N()},children:[t.jsx("input",{"aria-label":"A site that needs your sign-in",placeholder:"amazon.com",value:w,onChange:S=>v(S.target.value)}),t.jsx($,{size:"sm",type:"submit",disabled:s||!w.trim(),children:"Add"})]})]}),t.jsx(yh,{label:"Stop agents’ browsing lasts",hint:"What Stop in the Canvas does. Resume from the chat card, here, or /browser resume on Telegram.",children:t.jsx(cn,{label:"Stop agents’ browsing lasts",value:e.stopExpiryMinutes===0?"until":"hour",onChange:S=>r({stopExpiryMinutes:S==="until"?0:60}),options:[{value:"hour",label:"An hour"},{value:"until",label:"Until I say"}]})}),t.jsx(yh,{label:"Pages open at once",hint:"In buddi’s own browser. One more waits its turn; nothing is refused.",children:t.jsx(cn,{label:"Pages open at once",value:String(e.maxOwnPages),onChange:S=>r({maxOwnPages:Number(S)}),options:k.map(S=>({value:String(S),label:String(S)}))})}),t.jsx(yh,{label:"Show buddi’s browser as a window",hint:"Off: it works out of sight and you watch on the Canvas. On for the few sites that refuse a hidden browser.",children:t.jsx(ac,{checked:e.showWindow,label:"Show buddi’s browser as a window",disabled:s,onChange:S=>r({showWindow:S})})}),t.jsx("p",{className:"br-adv-empty",children:"Missions run without you, so they look only in buddi’s own browser, never in your Chrome."})]})})}const AY="kmbckpnnjfggeffkkbmkggojnolkdokb",$Y="pbfpjefkiijjgefblpnlnlpmeaddfbah",n2="https://chromewebstore.google.com/detail/pbfpjefkiijjgefblpnlnlpmeaddfbah",TY=[AY,$Y].filter(Boolean);function RY(e,n){const s=i=>/^\d+(\.\d+){0,3}$/.test(i.trim())?i.trim().split(".").map(Number):null,r=s(e),a=s(n);if(!r||!a)return!1;for(let i=0;i<4;i++){const l=(r[i]??0)-(a[i]??0);if(l!==0)return l<0}return!1}async function IY(){var e;try{if(typeof chrome>"u"||!((e=chrome==null?void 0:chrome.runtime)!=null&&e.sendMessage))return null;for(const n of TY)try{const s=await chrome.runtime.sendMessage(n,{type:"buddi.status"});if(s!=null&&s.installed)return s}catch{}return null}catch{return null}}function PY(e=navigator){var s,r,a;const n=e.userAgent??"";return(s=e.userAgentData)!=null&&s.mobile||/Android|iPhone|iPad|iPod|Mobile/i.test(n)?"phone":(a=(r=e.userAgentData)==null?void 0:r.brands)!=null&&a.some(i=>/Chromium/i.test(i.brand))||/Chrome\/|Chromium\/|Edg\//.test(n)&&!/Firefox\/|OPR\//.test(n)?"chromium":"other"}function Yu(e){try{return new URL(e).origin===window.location.origin}catch{return!1}}const p1=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 MY(e){const n=e.toLowerCase().replace(/\.$/,"");if(!n.includes(".")||p1.has(n))return!0;const s=n.slice(n.indexOf(".")+1);return p1.has(`*.${s}`)}function OY(e){return typeof e=="string"&&e.includes("*")}function DY(e){const n=/^(https?):\/\/([^/?#@\s]+)(?:[/?#]\S*)?$/i.exec(e.trim());if(n===null)return{ok:!1,reason:"invalid"};const[,s,r]=n;if(!r.startsWith("*.")||r.slice(2).includes("*"))return{ok:!1,reason:"placement"};let a;try{a=new URL(`${s.toLowerCase()}://${r.slice(2)}`)}catch{return{ok:!1,reason:"invalid"}}const i=a.hostname;return i===""||i.startsWith("[")||/^[\d.]+$/.test(i)||i.startsWith(".")||i.includes("..")?{ok:!1,reason:"invalid"}:MY(i)?{ok:!1,reason:"public-suffix"}:{ok:!0,value:{pattern:`${a.protocol}//*.${a.host}`,protocol:a.protocol,suffix:i,port:a.port}}}const g1=["every-time","first-time","pre-approved"];function s2(e){const n=g1.indexOf(e);return g1.slice(0,n<0?1:n+1)}function Tl(e){return e.endsWith(".account")}const LY="Stored, not usable until it has a binding.";function FY(e){return e==="browser.field"?"the origin of the site that holds the field, e.g. https://en.wikipedia.org or *.wikimedia.org":e==="browser.form.data"?"the origin, then the field name — e.g. https://localhost:8443 card-number":e==="browser.native.type"?"the app’s bundle id, e.g. com.bank.app":e==="http.header"?"the host, then the header name — e.g. localhost:9200 Authorization":e==="http.url"?"the plugin, then the host — e.g. calendar calendar.google.com":e==="http.basic"?"the plugin, then the host — e.g. calendar *.icloud.com":e==="http.bearer"?"the plugin, then the host — e.g. calendar www.googleapis.com":e==="developer.env"?"the workspace, then the variable name — e.g. cour des comptes ADMIN_PASSWORD":Tl(e)?"the account id, e.g. acct-1":'the place, as JSON — e.g. {"host":"localhost","header":"Authorization"}'}const r2={"browser.form.data":{hint:"an origin, then the field name",build:(e,n)=>({origin:e,field:n})},"http.header":{hint:"a host, then the header name",build:(e,n)=>({host:e,header:n})},"http.url":{hint:"a plugin, then the host",build:(e,n)=>({plugin:e,host:n})},"http.basic":{hint:"a plugin, then the host",build:(e,n)=>({plugin:e,host:n})},"http.bearer":{hint:"a plugin, then the host",build:(e,n)=>({plugin:e,host:n})},"developer.env":{hint:"a workspace, then the variable name",build:(e,n)=>({workspace:e,variable:n})}},_Y="A wildcard may only stand for the leftmost part of a site, like *.wikimedia.org.",zY=e=>`That is a public suffix; ${e} would match every site.`,x1="Give the site as an origin, like https://en.wikipedia.org.";function j1(e){const n=/^[a-z][a-z0-9+.-]*:\/\//i.test(e)?e:["https:","//",e].join("");if(OY(e)){const s=DY(n);if(s.ok)return{ok:!0,target:s.value.pattern};if(s.reason==="placement")return{ok:!1,error:_Y};if(s.reason==="public-suffix"){const r=n.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/[/?#:].*$/,"").toLowerCase();return{ok:!1,error:zY(r)}}return{ok:!1,error:x1}}try{const s=new URL(n);if(s.origin==="null"||s.protocol!=="https:"&&s.protocol!=="http:")throw new Error("not an origin");return{ok:!0,target:s.origin}}catch{return{ok:!1,error:x1}}}function UY(e){const n=e.search(/\s\S+\s*$/);if(n<=0)return null;const s=e.slice(n).trim(),r=e.slice(0,n).trim();return r&&s?[r,s]:null}function BY(e,n){const s=n.trim();if(s==="")return{ok:!1,error:"Give the exact place this value may go."};if(s.startsWith("{"))try{const i=JSON.parse(s);return i!==null&&typeof i=="object"&&!Array.isArray(i)?{ok:!0,target:i}:{ok:!1,error:'A target in JSON is an object, like {"host":"localhost","header":"Authorization"}.'}}catch{return{ok:!1,error:"That opens like JSON but does not parse."}}if(e==="browser.field")return j1(s);if(e==="browser.native.type"||Tl(e))return{ok:!0,target:s};const r=r2[e];if(r===void 0)return{ok:!0,target:s};const a=UY(s);if(a===null)return{ok:!1,error:`${e} needs both: ${r.hint}.`};if(e==="browser.form.data"){const i=j1(a[0]);return i.ok?{ok:!0,target:r.build(i.target,a[1])}:i}return{ok:!0,target:r.build(a[0],a[1])}}function WY(e){if(typeof e=="string")return e;try{return JSON.stringify(e)??""}catch{return""}}function a2(e,n){if(typeof n=="string")return n;if(n!==null&&typeof n=="object"&&!Array.isArray(n)){const s=n,r=r2[e];if(r!==void 0){const a=Object.keys(r.build("a","b")),i=a.map(l=>s[l]);if(a.every(l=>typeof s[l]=="string"))return i.join(" · ")}}try{return JSON.stringify(n)??String(n)}catch{return String(n)}}const uc="accounts.provider";function i2(e,n){if(typeof e!="object"||e===null)return[];const s=e[n];return Array.isArray(s)?s.flatMap(r=>{if(typeof r!="object"||r===null)return[];const a=r.place,i=r.count;return typeof a!="string"||typeof i!="number"||!(i>0)?[]:[{place:a,count:i}]}):[]}function l2(e){const n=e.map(({place:s,count:r})=>`${r.toLocaleString("en-GB")} ${r===1?s.replace(/s$/,""):s}`);return n.length<=1?n[0]??"":`${n.slice(0,-1).join(", ")} and ${n[n.length-1]}`}function HY(e){const n=i2(e,"found");return n.length?`The value already sits in ${l2(n)}.`:""}function KY(e){const n=i2(e,"scrubbed");return n.length?`Replaced with ‹secret:…› in ${l2(n)}.`:""}const VY=/^(PROVIDER_ACCOUNT_|CODEX_ACCOUNT_|ANTHROPIC_ACCOUNT_|OLLAMA_DEVICE_)/,GY=/^MCP_(TOKEN|ENV|CONNECTION)_/,o2="GMAIL_APP_PASSWORD";function Ua(e){const n=e.usedBy??[],s=e.bindings.map(r=>r.kind);if(n.some(r=>r.kind==="mailbox")||s.includes("email.account")||e.name===o2)return"mail";if(n.some(r=>r.kind==="model-account")||s.includes(uc)||VY.test(e.name))return"models";if(n.some(r=>r.kind==="connection")||s.includes("mcp.env")||GY.test(e.name))return"connections";for(const r of e.bindings){if((r.kind==="http.url"||r.kind==="http.basic"||r.kind==="http.bearer")&&fk(r.target)&&typeof r.target.plugin=="string")return`plugin:${r.target.plugin}`;if(Tl(r.kind))return`plugin:${r.kind.slice(0,-8)}`}return"mine"}function qY(e){if(e==="mine")return{title:"Your secrets",aside:"Agents fill these where you allow, without seeing them."};if(e==="mail")return{title:"Mail",aside:"Mailbox passwords. A new one is set on the Email page, which tests it first."};if(e==="models")return{title:"Model accounts",aside:"Managed in Model accounts."};if(e==="connections")return{title:"Connections",aside:"Managed in Connections."};const n=e.slice(7);return n==="calendar"?{title:"Calendar links and sign-ins",aside:"Private links and app passwords, used only by the calendar plugin."}:{title:n.charAt(0).toUpperCase()+n.slice(1),aside:`Kept for the ${n} plugin.`}}function YY(e,n){const s=r=>r==="mine"?0:r==="mail"?1:r==="models"?3:r==="connections"?4:2;return s(e)-s(n)||e.localeCompare(n)}function c2(e){return e==="models"||e==="connections"}function fk(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function v1(e){const n=e.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/\/.*$/,"").replace(/^www\./,"");return n.startsWith("*.")?`any ${n.slice(2)} site`:n}const mk=e=>(e.usedBy??[]).flatMap(n=>n.kind==="mailbox"?[n]:[]),Cp=e=>(e.usedBy??[]).find(n=>n.kind==="model-account"),pk=e=>(e.usedBy??[]).find(n=>n.kind==="connection");function ru(e,n=new Map){var r,a;const s=Ua(e);if(s==="mail"){const i=mk(e)[0];return i?`${i.provider==="Email"?"Mailbox":i.provider} ${i.auth==="xoauth2"?"sign-in":"app password"}`:"Old mailbox password"}if(s==="models"){const i=Cp(e),l=(i==null?void 0:i.id)??((r=e.bindings.find(c=>c.kind===uc&&typeof c.target=="string"))==null?void 0:r.target),o=typeof l=="string"?n.get(l):void 0;return(o==null?void 0:o.label)??(i==null?void 0:i.label)??"Old model account key"}if(s==="connections")return((a=pk(e))==null?void 0:a.name)??"Old connection sign-in";if(s.startsWith("plugin:")){const i=/^[^:]{1,40}:\s+(.+)$/.exec(e.name);return i?i[1]:e.name}return e.login?`Login · ${e.login.site}`:e.name}function u2(e){const n=e.indexOf("@");return n>0?`${e.slice(0,Math.min(n,24))}@…`:e.length>24?`${e.slice(0,23)}…`:e}function QY(e,n){const s=new Date(e);if(Number.isNaN(s.getTime()))return"";try{return new Intl.DateTimeFormat("en-GB",{day:"numeric",month:"short",...n?{timeZone:n}:{}}).format(s)}catch{return new Intl.DateTimeFormat("en-GB",{day:"numeric",month:"short"}).format(s)}}function JY(e,n){const s=e.login;if(!s)return null;const r=QY(s.savedAt,n);return[s.username?`for ${u2(s.username)}`:null,r?`saved ${r}`:null].filter(Boolean).join(" · ")}function XY(e,n){var r,a,i;if(Ua(e)!=="models")return null;const s=((r=Cp(e))==null?void 0:r.id)??((a=e.bindings.find(l=>l.kind===uc&&typeof l.target=="string"))==null?void 0:a.target);return typeof s=="string"?((i=n.get(s))==null?void 0:i.provider)??null:null}function d2(e,n){const s=fk(n)?n:{},r=a=>typeof s[a]=="string"?s[a]:"";return e==="browser.field"&&typeof n=="string"?`Filled on ${v1(n)}`:e==="browser.form.data"&&r("origin")?`Filled into “${r("field")}” on ${v1(r("origin"))}`:e==="browser.native.type"&&typeof n=="string"?`Typed into the app ${n}`:(e==="http.header"||e==="http.url"||e==="http.basic"||e==="http.bearer")&&r("host")?`Sent only to ${r("host")}`:e==="developer.env"&&r("variable")?`Given to ${r("workspace")} as ${r("variable")}`:e==="mcp.env"&&r("variable")?`Given to a program as ${r("variable")}`:e==="email.account"?"Used by a mailbox":e===uc?"Used by a model account":Tl(e)?`Used by a ${e.slice(0,-8)} account`:`Goes to ${a2(e,n)}`}function ZY(e,n){return Tl(e)||e===uc?"Signed in":d2(e,n).replace(/^Sent only to/,"Sent to")}const eQ={"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 tQ(e){return e.length<=1?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function gk(e){const n=Ua(e);if(n==="mail"){const l=mk(e).map(o=>o.address);return l.length?`Used by the ${l.length===1?"mailbox":"mailboxes"} ${tQ(l)}`:e.name===o2?"From the old .env setup":"No mailbox uses it"}if(n==="models"){const l=Cp(e);return l?eQ[l.auth]??"Key for this model account":"No model account uses it"}if(n==="connections"){const l=pk(e);if(l!=null&&l.variable)return`Given to the program as ${l.variable}`;const o=e.bindings.find(u=>u.kind==="http.header"),c=o&&fk(o.target)&&typeof o.target.host=="string"?o.target.host:null;return c?`Sign-in token · sent only to ${c}`:l?"Sign-in for this connection":"No connection uses it"}if(e.bindings.length===0)return"";const s=nQ(e),r=s?[`Filled on ${s}`]:e.bindings.map(l=>d2(l.kind,l.target));let a=r.length<=2?r.join(" · "):`${r[0]} and ${r.length-1} more places`;const i=new Set(e.bindings.map(l=>l.rule==="first-time"&&l.firstApprovedAt!==null?"pre-approved":l.rule));return i.size===1&&i.has("every-time")&&(a+=" · asks you every time"),i.size===1&&i.has("first-time")&&(a+=" · asks you the first time"),e.totp&&(a+=" · a fresh code each time"),a}function nQ(e){var r;const n=(r=e.savedFrom)==null?void 0:r.site;if(!n)return null;const s=a=>{if(typeof a!="string")return!1;const i=a.replace(/^https?:\/\//,"").replace(/:\d+$/,"").replace(/^\*\./,"").replace(/^www\./,"");return i===n||i.endsWith(`.${n}`)};return e.bindings.every(a=>a.kind==="browser.field"&&s(a.target))?n:null}function sQ(e,n=Date.now()){return e.lastUse?`Last used ${Xe(e.lastUse.at,n)}`:"Never used"}function Bv(e){return Or("email","settings",{account:e,set:"password"})}function h2(e){var s,r;const n=Ua(e);if(n==="models"){const a=(s=Cp(e))==null?void 0:s.id;return{label:"Managed in Model accounts",href:a?WI(a):ze("accounts")}}if(n==="connections"){const a=(r=pk(e))==null?void 0:r.id;return{label:"Managed in Connections",href:a?HI(a):ze("connections")}}return null}function f2(e){const n=/is not bound to (.+?)\.?$/.exec(e);if(!n)return null;const s=n[1];return/[0-9a-f]{8}-[0-9a-f]{4}-/i.test(s)?null:s}function m2(e,n=Date.now()){if(e.unused)return null;const s=Ua(e),r=mk(e)[0],a=h2(e),i=()=>r?{label:"Set password",href:Bv(r.id)}:a?{label:s==="models"?"Fix in Model accounts":"Fix in Connections",href:a.href}:{label:"Set a value",action:"replace"},l=e.lastUse,o=l?Xe(l.at,n):"",c=(l==null?void 0:l.detail)??"";if(e.hasValue===!1||(l==null?void 0:l.outcome)==="refused"&&/has no value stored/.test(c))return{text:"No value stored.",fix:i()};if(r!=null&&r.loginFailedAt)return{text:`${r.provider==="Email"?"The mail server":r.provider} turned it down at sign-in ${Xe(r.loginFailedAt,n)}.`,fix:{label:"Set password",href:Bv(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"?f2(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}: ${g2(c||null)}.`,fix:null}}if((l==null?void 0:l.outcome)==="failed"){const u=r?i():a?null:{label:"Replace value",action:"replace"};return{text:`Didn’t go through ${o}${c?`: ${c.replace(/\.$/,"")}`:""}.`,fix:u}}return(l==null?void 0:l.outcome)==="pending"?{text:`Waiting for your approval since ${o}.`,fix:{label:"Review",href:Io}}: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 p2(e){if(!e.unused)return"";const n=Ua(e);return n==="mail"?"Not used by anything — no mailbox uses it any more.":n==="models"?"Not used by anything — no model account uses it any more.":n==="connections"?"Not used by anything — no connection uses it any more.":"Not used by anything — what it was for is gone."}function Wv(e){return e.usageUnknown&&!e.unused?"Couldn’t check what uses it just now.":""}function oo(e){return!!e.unused&&!c2(Ua(e))}function rQ(e){if(e.unused||e.bindings.length===0)return"Nothing uses it, so nothing stops working.";const n=gk(e).split(" · ")[0]??"";return n.startsWith("Filled on ")?`Agents can no longer fill it on ${n.slice(10)}.`:n.startsWith("Sent only to ")?`Agents can no longer send it to ${n.slice(13)}.`:`Whatever uses it stops working: ${n.charAt(0).toLowerCase()}${n.slice(1)}.`}const aQ={"every-time":"Every time","first-time":"The first time, then not again","pre-approved":"Never — allowed ahead of time"};function iQ(e){const n={"browser.field":"A field on a website","browser.form.data":"A form field, by its name","browser.native.type":"An app on this computer","http.header":"A request to a host","http.url":"A plugin’s web address","http.basic":"A plugin’s sign-in","http.bearer":"A plugin’s account sign-in","developer.env":"A workspace variable","mcp.env":"A program’s variable",[uc]:"A model account"};return n[e]?n[e]:Tl(e)?`A ${e.slice(0,-8)} account`:e}const lQ={"every-time":"Every time","first-time":"The first time","pre-approved":"Never"};function g2(e){if(!e)return"buddi didn’t hand it over";if(/has no value stored/.test(e))return"no value was stored";if(/vault is locked/.test(e))return"the vault was locked";if(/TOTP secret/.test(e))return"a one-time code goes only into a field on a website";const n=/is not bound to/.test(e)?f2(e):void 0;return n!==void 0?n?`asked for at ${n}, where it may not go`:"asked for somewhere it may not go":e.replace(/\.$/,"")}function oQ(e){return e==="browser.field"?"www.pnc.com":e==="browser.form.data"?"www.pnc.com card-number":e==="browser.native.type"?"com.bank.app":e==="http.header"?"api.github.com Authorization":e==="http.url"?"calendar calendar.google.com":e==="http.basic"?"calendar caldav.fastmail.com":e==="http.bearer"?"calendar www.googleapis.com":e==="developer.env"?"my-app ADMIN_PASSWORD":Tl(e)?"acct-1":'{"host":"localhost","header":"Authorization"}'}function im(e){return s2(e).includes("first-time")?"first-time":e}function cQ(e){const n=ZY(e.kind,e.target);return e.outcome==="refused"?{text:`Held back — ${g2(e.detail)}`,tone:"warning"}:e.outcome==="failed"?{text:`Didn’t go through — ${(e.detail??n).replace(/\.$/,"")}`,tone:"warning"}:e.outcome==="pending"?{text:`Asked for your approval · ${n}`}:{text:n}}const uQ=2*6e4,dQ=2e3;function hQ({login:e,onDone:n}){const[s,r]=d.useState(!1),[a,i]=d.useState(null),[l,o]=d.useState(!1);d.useEffect(()=>{o(!1),i(null);const m=window.setTimeout(n,uQ);return()=>window.clearTimeout(m)},[e.id]),d.useEffect(()=>{if(!l)return;const m=window.setTimeout(n,dQ);return()=>window.clearTimeout(m)},[l]);const c=async m=>{r(!0),i(null);try{const f=await T.browserLogin(e.id,m);if(m==="save"&&f.outcome==="saved"){o(!0);return}if(m==="save"&&f.outcome==="gone"){i({reason:"That sign-in is no longer held. Add it in Keys and secrets.",retry:!1});return}n()}catch(f){i({reason:f instanceof Error?f.message:String(f),retry:m==="save"})}finally{r(!1)}},u=e.update===!0;if(l)return t.jsxs(Q,{tone:"good",role:"status",title:u?`Updated the login for ${e.site}`:`Saved the login for ${e.site}`,children:["Agents can sign in there now without seeing it. It’s under ",t.jsx("a",{className:"wb-link",href:ze("secrets"),children:"Keys and secrets"}),"."]});const h=e.username?`For ${u2(e.username)}. `:"";return t.jsxs("section",{className:"br-login","data-testid":"save-login","aria-label":u?"Update this login":"Save this login",children:[t.jsx(Q,{tone:"accent",role:"status",title:u?`Update the login for ${e.site}?`:`Save this login for ${e.site}?`,action:t.jsxs(te,{align:"end",children:[t.jsx($,{size:"sm",variant:"ghost",disabled:s,onClick:()=>void c("never"),children:"Never for this site"}),t.jsx($,{size:"sm",disabled:s,onClick:()=>void c("later"),children:"Not now"}),t.jsx($,{size:"sm",variant:"accent",disabled:s,onClick:()=>void c("save"),children:u?"Update":"Save"})]}),children:u?`${h}buddi replaces the password it keeps under Keys and secrets with the one you just used.`:`${h}buddi keeps it under Keys and secrets, and agents use it without ever seeing it.`}),a?t.jsx(Q,{tone:"critical",role:"alert",action:a.retry?t.jsx($,{size:"sm",disabled:s,onClick:()=>void c("save"),children:"Try again"}):void 0,children:a.reason}):null]})}const fQ=2e3,mQ=5,pQ="(hover: none) and (pointer: coarse)",Hv="buddi:browser-enlarge",gQ=4e3,xQ=8e3,jQ="https:";function vQ(e){const n=e.trim();if(n===""||/\s/.test(n))return null;const s=/^[a-z][a-z0-9+.-]*:/i.test(n)&&!/^[^:]+:\d+(\/|$)/.test(n)?n:`${jQ}//${n}`;try{const r=new URL(s);return r.protocol==="https:"||r.protocol==="http:"?r.toString():null}catch{return null}}function yQ(e){if(!e)return null;try{const n=new URL(e);if(n.protocol!=="http:"&&n.protocol!=="https:")return{host:e,rest:"",secure:!1};const s=`${n.pathname==="/"?"":n.pathname}${n.search}${n.hash}`;return{host:n.host.replace(/^www\./,""),rest:s,secure:n.protocol==="https:"}}catch{return{host:e,rest:"",secure:!1}}}function Kv(e,n){if(!e.hasScreenshot||!e.page)return null;const s=e.session?`&sessionId=${encodeURIComponent(e.session.id)}`:"";return`/api/browser/screenshot?v=${encodeURIComponent(e.page.id)}${s}${n?`&tick=${n}`:""}`}function Vv(e){var s,r,a;return(e==null?void 0:e.route)==="apps"&&((s=e.page)!=null&&s.appId)?Sp(e.page.appId).charAt(0).toUpperCase():(hk((r=e==null?void 0:e.page)==null?void 0:r.url)??((a=e==null?void 0:e.page)==null?void 0:a.title)??"·").charAt(0).toUpperCase()}function wQ({status:e,error:n,reload:s,live:r,agentName:a="The agent",timezone:i,paused:l=null}){var On,$n,Ae,De,gt,Mt,Dn,as,js,Ps,Wn,ft;const o=i??Intl.DateTimeFormat().resolvedOptions().timeZone,[c,u]=d.useState(0),[h,m]=d.useState(0),f=h>=mQ;d.useEffect(()=>{if(!r||f)return;const fe=window.setInterval(()=>{typeof document<"u"&&document.hidden||u(ct=>ct+1)},fQ);return()=>window.clearInterval(fe)},[r,f]);const p=d.useRef(null);r&&(e!=null&&e.session)&&(p.current=e);const[x,g]=d.useState(null);d.useEffect(()=>{!r&&p.current&&x===null&&g(Date.now()),r&&g(null)},[r]);const[w,v]=d.useState(null),j=d.useRef(null),y=((On=e==null?void 0:e.page)==null?void 0:On.id)??null;d.useEffect(()=>{const fe=r&&e?Kv(e):null;if(!fe||typeof fetch!="function"||typeof(URL==null?void 0:URL.createObjectURL)!="function")return;let ct=!1;return(async()=>{try{const Et=await fetch(fe);if(!Et.ok||ct)return;const gn=await Et.blob();if(ct)return;const is=URL.createObjectURL(gn);j.current&&URL.revokeObjectURL(j.current),j.current=is,v(is)}catch{}})(),()=>{ct=!0}},[r,y]),d.useEffect(()=>()=>{j.current&&typeof(URL==null?void 0:URL.revokeObjectURL)=="function"&&URL.revokeObjectURL(j.current)},[]);const k=p.current,N=r?e:k??e,[b,S]=d.useState(!1),[C,A]=d.useState(null),[E,R]=d.useState(null),[P,O]=d.useState(!1),[I,F]=d.useState(null),[U,L]=d.useState(!1),M=cc(),z=ts(pQ),D=d.useRef(null),[K,B]=d.useState(null),se=d.useRef(null),W=N==null?void 0:N.session,xe=async(fe,ct)=>{S(!0),A(null);try{await fe()}catch(Et){ct==null||ct(),A(Et instanceof Error?Et.message:String(Et))}try{await Promise.race([Promise.resolve(s()),new Promise(Et=>{window.setTimeout(Et,gQ)})])}catch{}S(!1)},[me,ie]=d.useState(null),H=()=>void xe(async()=>{var Et;F(null),L(!1);const fe=W==null?void 0:W.id;fe&&(se.current=fe);const ct=await T.browserControl("takeover",fe);((Et=ct.held)==null?void 0:Et.where)!=="chrome"&&(ct.hand&&ct.session&&(!fe||ct.session.id===fe)?R(ct.session.id):ct.handReason==="browser-offline"?L(!0):F(ct.handMessage??null))}),[de,ge]=d.useState(null),Ue=()=>{var Et;const fe=(W==null?void 0:W.id)??null,ct=((Et=D.current)==null?void 0:Et.snapshot())??null;ct&&ge(ct),ie(fe),R(null),O(!1)},G=()=>void xe(async()=>{Ue(),await T.browserControl("resume",W==null?void 0:W.id)},()=>ie(null)),ae=()=>void xe(async()=>{var ct;if(!W)return;const fe=((ct=D.current)==null?void 0:ct.snapshot())??null;fe&&ge(fe),R(null),O(!1),await T.browserFront(W.id)}),J=()=>void xe(async()=>{Ue(),await T.browserControl("stop",W==null?void 0:W.id)},()=>ie(null)),Ne=()=>void xe(async()=>{W&&(await T.browserPin(W.conversationId,"own"),await T.browserControl("release",W.id),L(!1),F("This conversation uses buddi’s browser now. Send the agent a message and it opens the page there."))}),Ie=r&&!!(e!=null&&e.session)&&e.state==="paused"&&e.session.id!==me;d.useEffect(()=>{var fe;!me||b||(!r||((fe=e==null?void 0:e.session)==null?void 0:fe.id)!==me||e.state!=="paused")&&ie(null)},[me,b,e,r]);const Y=Ie&&(($n=e==null?void 0:e.held)==null?void 0:$n.where)==="chrome",X=!Y&&E&&((Ae=e==null?void 0:e.session)==null?void 0:Ae.id)===E&&(Ie||b)&&e.session.id!==me?E:null;d.useEffect(()=>{X&&ge(null)},[X]);const oe=Ie?((De=e==null?void 0:e.session)==null?void 0:De.id)??null:null;d.useEffect(()=>{!oe||E===oe||z||b||(e==null?void 0:e.route)==="apps"||Y||se.current!==oe&&H()},[oe,E,z,b]),d.useEffect(()=>{Ie||(se.current=null)},[Ie]);const[ve,be]=d.useState(!1),[Ce,we]=d.useState(null),He=()=>{var ct;const fe=(ct=e==null?void 0:e.session)==null?void 0:ct.id;!fe||ve||(be(!0),A(null),we(null),T.browserCapture(fe).then(Et=>we({artifactId:Et.artifactId,name:Et.name})).catch(Et=>A(Et instanceof Error?Et.message:String(Et))).finally(()=>be(!1)))},[Ze,Se]=d.useState(!1);d.useEffect(()=>{const fe=()=>Se(!0);return window.addEventListener(Hv,fe),()=>window.removeEventListener(Hv,fe)},[]),d.useEffect(()=>{if(!Ze)return;const fe=ct=>{ct.key==="Escape"&&!ct.defaultPrevented&&Se(!1)};return window.addEventListener("keydown",fe),()=>window.removeEventListener("keydown",fe)},[Ze]);const[Le,Ve]=d.useState(null),[Qe,wt]=d.useState(!1),[dt,qt]=d.useState(null);d.useEffect(()=>{Ve(null),wt(!1),qt(null)},[X]),d.useEffect(()=>{if(!Qe)return;const fe=window.setTimeout(()=>wt(!1),xQ);return()=>window.clearTimeout(fe)},[Qe]);const vt=fe=>{Ve(fe),wt(!1)},Dt=(fe,ct)=>{var Et;A(null),(Et=D.current)!=null&&Et.nav(fe,ct)&&wt(!0)},bn=Ie||!!X,sn=r&&!!(N!=null&&N.needsOwner),ce=!r&&!l,Me=hk((gt=N==null?void 0:N.page)==null?void 0:gt.url)??((Mt=N==null?void 0:N.page)!=null&&Mt.appId?Sp(N.page.appId):"the page"),tt=(N==null?void 0:N.route)==="chrome",Tt=tt?"in your Chrome · background tab":(N==null?void 0:N.route)==="apps"?`in ${Me}`:"in buddi’s browser",bt=l?"Browsing is paused":((Dn=N==null?void 0:N.page)==null?void 0:Dn.title)||Me,Pe=l?`By you at ${Lt(new Date(l.at),o)} · ${l.until?`until ${Lt(new Date(l.until),o)}`:"until you resume it"}`:Y?"You have the page · in your Chrome · it’s in front":bn?`You have the page · ${tt?"in your Chrome":Tt}`:ce?`${a} looked at ${Me} · done${x?` at ${Lt(new Date(x),o)}`:""}`:N?e2(N):"Opening the page…",st=r?(N?Kv(N,c):null)??de:w??de,_e=(N==null?void 0:N.route)==="apps",en=X?Le??((as=N==null?void 0:N.page)==null?void 0:as.url):(js=N==null?void 0:N.page)==null?void 0:js.url,ee=r&&(Qe||!bn&&!!(e!=null&&e.busy)),rt=N||r?t.jsx("button",{type:"button",className:"ui-icon-btn br-enlarge","data-size":"sm","aria-label":Ze?"Back to the side":"Enlarge the page",title:Ze?"Back to the side (Esc)":"Enlarge the page",onClick:()=>Se(!Ze),children:t.jsx(ne,{name:Ze?"collapse":"expand"})}):null;return t.jsxs("div",{className:"br-canvas","data-testid":"browser-view","data-live":r?"true":"false","data-enlarged":Ze?"true":void 0,...Ze?{role:"dialog","aria-modal":!0,"aria-label":"The page, full size"}:{},children:[t.jsxs("header",{className:"br-head",children:[t.jsx("span",{className:"br-tile","aria-hidden":"true",children:l?t.jsx(kQ,{}):Vv(N)}),t.jsxs("span",{className:"br-head-text",children:[t.jsx("span",{className:"br-head-title",children:bt}),t.jsxs("span",{className:"br-head-line",role:"status",children:[r&&!sn&&!bn&&!l?t.jsx("span",{className:"br-live","aria-hidden":"true"}):null,Pe]})]}),bn?t.jsxs(te,{align:"end",children:[Y?null:X?z?t.jsx($,{size:"sm",variant:P?"accent":"ghost","aria-pressed":P,onClick:()=>O(!P),children:"Type into the page"}):null:t.jsx($,{size:"sm",variant:"ghost",disabled:b,onClick:H,children:"Drive it here"}),tt&&!Y?t.jsx($,{size:"sm",variant:"ghost",disabled:b,title:"For when you are at the computer: the tab comes to the front of your Chrome",onClick:ae,children:"Bring the tab to the front"}):null,t.jsx($,{size:"sm",variant:"accent",disabled:b,onClick:G,children:"Give it back"}),rt]}):l?t.jsx($,{size:"sm",variant:"accent",disabled:b,onClick:()=>void xe(async()=>{await T.browserControl("resume")}),children:"Resume"}):ce||!W?rt?t.jsx(te,{align:"end",children:rt}):null:t.jsxs(te,{align:"end",children:[t.jsx($,{size:"sm",disabled:b||!(N!=null&&N.enabled),onClick:J,children:"Stop"}),t.jsx($,{size:"sm",variant:sn?"accent":void 0,disabled:b||!(N!=null&&N.enabled)||(N==null?void 0:N.state)==="paused",onClick:H,children:"Take over"}),rt]})]}),bn?t.jsx("p",{className:"br-hand-said",role:"status",children:Y?"Finish in Chrome, then give it back.":X?`Nothing you type here is kept. ${a} carries on when you give it back.${z?" Tap Type into the page to bring up your keyboard.":""}`:`${a} waits. It carries on when you give the page back.`}):null,C||n?t.jsx(Q,{tone:"critical",role:"alert",children:C??n}):null,I?t.jsx(Q,{tone:"warning",role:"status",children:I}):null,Ce?t.jsx(Q,{tone:"good",role:"status",action:t.jsxs(te,{align:"end",children:[t.jsx($,{size:"sm",variant:"ghost",onClick:()=>we(null),children:"Dismiss"}),t.jsx($,{size:"sm",variant:"accent",onClick:()=>{window.location.hash=ao(Ce.artifactId)},children:"Open in Files"})]}),children:`Saved to Files as ${Ce.name}.`}):null,U?t.jsx(Q,{tone:"warning",role:"status",title:"Your Chrome isn’t connected.",action:t.jsxs(te,{align:"end",children:[t.jsx($,{size:"sm",disabled:b,onClick:Ne,children:"Use buddi’s browser"}),t.jsx($,{size:"sm",variant:"accent",disabled:b,onClick:H,children:"Try again"})]}),children:`Open Chrome on ${M} and try again, or let this conversation use buddi’s own browser.`}):null,K?t.jsx(hQ,{login:K,onDone:()=>B(null)}):null,l?t.jsx("div",{className:"br-frame br-frame-empty",children:t.jsx("p",{className:"ui-empty",children:`No page is open. Agents look again when you resume${l.until?`, or by themselves at ${Lt(new Date(l.until),o)}`:""}.`})}):t.jsxs("div",{className:"br-window","data-state":X?"yours":sn?"waiting":ce?"done":"live",children:[t.jsx(bQ,{app:_e?Me:null,title:((Ps=N==null?void 0:N.page)==null?void 0:Ps.title)||void 0,address:en,held:!!X,level:X&&dt?dt==="sharp"?"sharp":"fast":null,loading:ee,onCapture:r&&(e!=null&&e.session)&&!_e?He:void 0,capturing:ve,onNav:Dt,onRefused:fe=>A(fe)}),X?t.jsx("div",{className:"br-frame","data-state":"yours",children:t.jsx(dY,{ref:D,sessionId:X,csrf:wl(),onGiveBack:G,bare:!0,typing:P,onTyping:O,onLocation:vt,onLoginSeen:B,onLevel:qt})}):t.jsx("div",{className:"br-frame","data-state":sn?"waiting":ce?"done":"live",children:st?t.jsx("img",{className:"br-shot",src:st,alt:`What ${a} sees: ${((Wn=N==null?void 0:N.page)==null?void 0:Wn.title)||Me}`,onError:()=>m(fe=>fe+1),onLoad:()=>m(0)},r?((ft=N==null?void 0:N.page)==null?void 0:ft.id)??"live":"kept"):t.jsx("p",{className:"ui-empty br-frame-wait",children:r?"The page appears here as soon as it opens.":"No picture of this page was kept."})})]}),ce?t.jsx("p",{className:"br-ended",role:"status",children:"The page is closed. This is the last thing it showed."}):r&&f?t.jsx("p",{className:"br-ended",role:"status",children:"The newest picture didn’t load. Showing the one before it."}):null]})}function bQ({app:e,title:n,address:s,held:r,level:a=null,loading:i,onCapture:l,capturing:o=!1,onNav:c,onRefused:u}){const[h,m]=d.useState(null),[f,p]=d.useState(!1);d.useEffect(()=>{m(null)},[s,r]),d.useEffect(()=>{if(!f)return;const j=window.setTimeout(()=>p(!1),1500);return()=>window.clearTimeout(j)},[f]);const x=yQ(s),g=()=>{var j;s&&((j=navigator.clipboard)==null||j.writeText(s).then(()=>p(!0),()=>{}))},w=j=>{var k,N;if(j.preventDefault(),h===null)return;const y=vQ(h);if(!y){u("That isn’t a web address. Type one like amazon.com/orders.");return}m(null),c("navigate",y),(N=(k=document.activeElement)==null?void 0:k.blur)==null||N.call(k)},v=j=>{j.key==="Escape"&&(j.preventDefault(),m(null),j.currentTarget.blur())};return t.jsxs("div",{className:"br-window-bar",role:"toolbar","aria-label":"Page controls",children:[e?t.jsx("span",{className:"br-window-app",children:e}):t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"br-window-nav",children:[t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"Back",title:"Back",disabled:!r,onClick:()=>c("back"),children:t.jsx(ne,{name:"back"})}),t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"Forward",title:"Forward",disabled:!r,onClick:()=>c("forward"),children:t.jsx(ne,{name:"forward"})}),t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"Reload",title:"Reload",disabled:!r,onClick:()=>c("reload"),children:t.jsx(ne,{name:"reload"})})]}),r?t.jsxs("form",{className:"br-address","data-editable":"true",onSubmit:w,children:[t.jsx(y1,{secure:(x==null?void 0:x.secure)??!1}),t.jsx("input",{className:"br-address-input","aria-label":"Address",value:h??s??"",spellCheck:!1,autoCapitalize:"off",autoCorrect:"off",onFocus:j=>j.currentTarget.select(),onChange:j=>m(j.target.value),onKeyDown:v}),t.jsx("button",{type:"button",className:"br-address-copy","aria-label":f?"Copied":"Copy the address",title:f?"Copied":"Copy the address",disabled:!s,onClick:g,children:t.jsx(ne,{name:f?"check":"copy",size:14})})]}):t.jsxs("button",{type:"button",className:"br-address","aria-label":f?"Address copied":"Copy the address",title:f?"Copied":"Copy the address",disabled:!s,onClick:g,children:[t.jsx(y1,{secure:(x==null?void 0:x.secure)??!1}),t.jsx("span",{className:"br-address-text",children:x?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"br-address-host",children:x.host}),t.jsx("span",{className:"br-address-rest",children:x.rest})]}):t.jsx("span",{className:"br-address-rest",children:"No address yet"})}),f?t.jsx("span",{className:"br-address-said","aria-hidden":"true",children:"Copied"}):null]})]}),n?t.jsx("span",{className:"br-window-title",title:n,children:n}):null,a?t.jsx("span",{className:"br-window-level","data-testid":"hand-level",title:a==="sharp"?"The picture is at full quality":"The picture is kept small so it stays live on this link",children:a}):null,l?t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"Capture the page to Files",title:"Capture the page to Files",disabled:o,onClick:l,children:t.jsx(ne,{name:"camera"})}):null,i?t.jsx("span",{className:"br-window-progress",role:"progressbar","aria-label":"Loading"}):null]})}function y1({secure:e}){return t.jsx("span",{className:"br-address-mark","aria-hidden":"true",children:t.jsx(ne,{name:e?"lock":"globe",size:12})})}function kQ(){return t.jsxs("svg",{viewBox:"0 0 20 20",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round","aria-hidden":"true",children:[t.jsx("circle",{cx:"10",cy:"10",r:"7.2"}),t.jsx("path",{d:"M2.8 10h14.4M10 2.8c2.2 2.3 2.2 12.1 0 14.4M10 2.8c-2.2 2.3-2.2 12.1 0 14.4"})]})}function NQ({status:e,timezone:n,reload:s}){var o;const r=n??Intl.DateTimeFormat().resolvedOptions().timeZone,a=((o=e==null?void 0:e.settings)==null?void 0:o.stopExpiryMinutes)??60,i=Lt(new Date(Date.now()+(a||60)*6e4),r),l=c=>void c().catch(()=>{}).finally(s);return t.jsx(rs,{label:"More for this page",items:[{heading:"Stop agents’ browsing"},{label:"For an hour",hint:`Every agent, every conversation; back on at ${i}`,onSelect:()=>l(()=>T.browserControl("stop"))},{label:"Until I say",hint:"Until you press Resume",onSelect:()=>l(()=>T.browserControl("stop",void 0,{forever:!0}))},"separator",e!=null&&e.settings&&!e.settings.showWindow?{label:"Show the window",hint:"A window on this machine, for sites that refuse a hidden browser",onSelect:()=>l(()=>T.browserSettings({showWindow:!0}))}:null,{label:"Open the full page view",hint:"This page over the whole window; Esc comes back",onSelect:()=>{window.dispatchEvent(new Event(Hv))}}]})}function tf(e){const n=e==null?void 0:e.request;return n&&n.kind==="secret.request"&&!n.expand?n:null}function w1(e){const n=e==null?void 0:e.request;return n&&n.kind==="secret.request"&&n.expand?n:null}function SQ(e){const n=e.split(".").filter(Boolean);if(n.length<2)return e;const s=n.length>=3&&/^(co|com|net|org|gov|ac|edu)$/.test(n[n.length-2])?n[n.length-3]:n[n.length-2];return s.charAt(0).toUpperCase()+s.slice(1)}function tx(e,n){const s=n.trim();return`${SQ(e)} ${s.charAt(0).toLowerCase()}${s.slice(1)}`}function CQ(e){return e.length<3?e.join(" and "):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}const x2=e=>e.kind!=="username";function nf({value:e,onChange:n,label:s,autoFocus:r,disabled:a}){const[i,l]=d.useState(!1);return t.jsxs("span",{className:"ss-reveal",children:[t.jsx("input",{type:i?"text":"password",autoComplete:"new-password",spellCheck:!1,value:e,onChange:o=>n(o.target.value),"aria-label":s,autoFocus:r,disabled:a}),t.jsx("button",{type:"button",className:"ss-reveal-btn","aria-pressed":i,onClick:()=>l(!i),children:i?"Hide":"Show"})]})}function j2(){return t.jsx(Q,{tone:"critical",title:"Nothing was saved: the vault is locked.",children:"The keychain on this Mac is locked, so buddi can’t store anything. Unlock this Mac, then press Save and fill again. What you typed is still here."})}function EQ(e,n){return[...e.fields.map((s,r)=>({label:s.label,kind:s.kind,value:n.values[r]??""})),...n.totp?[{label:"Code",kind:"totp",value:n.seed}]:[],...n.extra.filter(s=>s.label.trim()!=="").map(s=>({label:s.label.trim(),kind:"other",value:s.value}))]}function xk({question:e,card:n,phone:s,container:r,page:a,disabled:i,onSettled:l,onChoice:o}){var S;const[c,u]=d.useState({values:n.fields.map(()=>""),totp:!1,seed:"",extra:[]}),[h,m]=d.useState(!1),[f,p]=d.useState(null),[x,g]=d.useState(!1),[w,v]=d.useState(null),j=n.agentName??"The agent",y=C=>{p(C),v(null),T.saveSecretSet({questionId:e.id,then:C,fields:EQ(n,c)}).then(()=>l()).catch(A=>{var E;if(p(null),A instanceof pe&&((E=A.detail)==null?void 0:E.locked)===!0){g(!0);return}g(!1),v(A instanceof pe?A.message:String(A))})},k=()=>{p("self"),v(null),T.declineSecretRequest(e.id,"sign-in-myself").then(()=>l()).catch(C=>{p(null),v(C instanceof pe?C.message:String(C))})},N=i||f!==null,b=C=>A=>u(E=>({...E,values:E.values.map((R,P)=>P===C?A:R)}));return t.jsxs(t.Fragment,{children:[t.jsxs("section",{className:"wb-question br-ask ss-card","data-phone":s?"true":void 0,"aria-label":`No saved sign-in for ${n.site}`,"data-testid":"secret-request",children:[t.jsxs("div",{className:"br-ask-head",children:[t.jsx("span",{className:"wb-question-kicker",children:"Needs you"}),t.jsxs("strong",{children:["No saved sign-in for ",n.site]}),t.jsxs("span",{className:"br-ask-line",children:[j," stopped at the sign-in form. Type these once; buddi keeps them and fills them in, and ",j," carries on."]})]}),t.jsxs("div",{className:"wb-dock-section ss-inline",children:[t.jsx("div",{className:"ss-inline-fields",children:n.fields.map((C,A)=>t.jsx(le,{label:C.label,children:x2(C)?t.jsx(nf,{value:c.values[A]??"",onChange:b(A),label:C.label,disabled:N}):t.jsx("input",{value:c.values[A]??"",onChange:E=>b(A)(E.target.value),autoComplete:"off",spellCheck:!1,autoFocus:!s&&!x&&A===0,disabled:N})},C.label))}),t.jsxs("span",{className:"ss-place-row",children:[t.jsxs("span",{className:"ss-site-chip",children:[t.jsx(ne,{name:"globe",size:14}),n.site]}),t.jsxs("span",{className:"ss-place-text",children:["only on this site · ",j," never sees them"]})]}),(S=n.warnings)==null?void 0:S.map(C=>t.jsx("p",{className:"ss-warning",role:"note",children:C},C)),x&&!h?t.jsx(j2,{}):null,t.jsx(re,{message:h?null:w})]}),t.jsxs("div",{className:"wb-dock-section",children:[t.jsxs(te,{align:"end",children:[(n.choices??[]).map(C=>{const A=e.options.find(E=>E.label===C);return o&&A?t.jsx($,{size:"sm",variant:"ghost",disabled:N,title:A.hint??void 0,onClick:()=>o(C,A.id),children:C},C):null}),t.jsx($,{size:"sm",variant:"ghost",disabled:N,onClick:k,children:f==="self"?"Handing it over…":"I’ll sign in myself"}),t.jsx($,{size:"sm",disabled:N,onClick:()=>m(!0),children:"More options"}),t.jsx($,{size:"sm",variant:"accent",disabled:N,onClick:()=>y("fill"),children:f==="fill"?"Saving…":"Save and fill"})]}),t.jsxs("p",{className:"ss-save-only",children:["Rather sign in yourself this time? ",t.jsx("button",{type:"button",className:"wb-link",disabled:N,onClick:()=>y("save"),children:"Save only"})," keeps them for next time and hands you the page."]})]})]}),h?t.jsx($Q,{card:n,typed:c,setTyped:u,phone:s,container:s?null:r,page:a,locked:x,error:w,busy:f,disabled:N,onClose:()=>m(!1),onSave:y}):null]})}function AQ({site:e}){return t.jsxs("div",{className:"ss-place",children:[t.jsx("span",{className:"ui-field-label",children:"Where they go"}),t.jsxs("span",{className:"ss-place-row",children:[t.jsxs("span",{className:"ss-site-chip",children:[t.jsx(ne,{name:"globe",size:14}),e]}),t.jsx("span",{className:"ss-place-text",children:"only on this site"})]}),t.jsx("span",{className:"ui-field-hint",children:"Agents can use them only here. Anywhere else, buddi holds them back and the row in Keys and secrets says so. Filling asks you the first time, then not again."})]})}function $Q({card:e,typed:n,setTyped:s,phone:r,container:a,page:i,locked:l,error:o,busy:c,disabled:u,onClose:h,onSave:m}){var j,y,k;const[f,p]=d.useState(!1),x=e.agentName??"The agent",g=[...e.fields.map(N=>tx(e.site,N.label)),...n.totp?[tx(e.site,"Code")]:[],...n.extra.filter(N=>N.label.trim()!=="").map(N=>tx(e.site,N.label))],w=i?Kv(i):null,v=((j=i==null?void 0:i.page)==null?void 0:j.title)??((y=e.page)==null?void 0:y.title)??e.site;return t.jsxs(Ye,{title:`Sign-in for ${e.site}`,onClose:h,container:a,children:[t.jsxs("div",{className:"ss-sheet",children:[r?t.jsxs("div",{className:"ss-peek",children:[t.jsxs("div",{className:"ss-peek-head",children:[t.jsx("span",{className:"br-tile","aria-hidden":"true",children:Vv(i)==="·"?e.site.charAt(0).toUpperCase():Vv(i)}),t.jsxs("span",{className:"br-head-text",children:[t.jsx("span",{className:"br-head-title",children:v}),t.jsxs("span",{className:"br-head-line",children:["The page ",x," has open"]})]}),t.jsx($,{size:"sm",variant:"ghost","aria-expanded":f,onClick:()=>p(!f),children:f?"Hide the page":"Show the page"})]}),f?t.jsx("div",{className:"br-frame ss-peek-frame","data-state":"waiting",children:w?t.jsx("img",{src:w,alt:`The page ${x} has open`}):t.jsx("p",{className:"br-frame-wait",children:"No picture of the page yet."})}):null]}):null,t.jsxs("p",{className:"ss-note",children:[x," saw these fields on the page. Type them once; buddi keeps them and fills them in for you here."]}),t.jsxs("div",{className:"ss-form",children:[e.fields.map((N,b)=>t.jsx(le,{label:N.label,children:x2(N)?t.jsx(nf,{value:n.values[b]??"",onChange:S=>s(C=>({...C,values:C.values.map((A,E)=>E===b?S:A)})),label:N.label,disabled:u}):t.jsx("input",{value:n.values[b]??"",onChange:S=>{const C=S.target.value;s(A=>({...A,values:A.values.map((E,R)=>R===b?C:E)}))},autoComplete:"off",spellCheck:!1,autoFocus:!r&&!l&&b===0,disabled:u})},N.label)),n.totp?t.jsxs("div",{className:"ss-extra",children:[t.jsx(le,{label:"Authenticator (TOTP seed)",hint:"The setup key the site showed when you turned on two-step sign-in. buddi fills the current code, never the seed.",children:t.jsx(nf,{value:n.seed,onChange:N=>s(b=>({...b,seed:N})),label:"Authenticator (TOTP seed)",disabled:u})}),t.jsx($,{size:"sm",variant:"ghost",onClick:()=>s(N=>({...N,totp:!1,seed:""})),children:"Remove"})]}):null,n.extra.map((N,b)=>t.jsxs("div",{className:"ss-extra ss-extra-pair",children:[t.jsx(le,{label:"Label",children:t.jsx("input",{value:N.label,placeholder:"Security answer",onChange:S=>{const C=S.target.value;s(A=>({...A,extra:A.extra.map((E,R)=>R===b?{...E,label:C}:E)}))},disabled:u})}),t.jsx(le,{label:"Value",children:t.jsx(nf,{value:N.value,onChange:S=>s(C=>({...C,extra:C.extra.map((A,E)=>E===b?{...A,value:S}:A)})),label:"Value",disabled:u})}),t.jsx($,{size:"sm",variant:"ghost",onClick:()=>s(S=>({...S,extra:S.extra.filter((C,A)=>A!==b)})),children:"Remove"})]},b)),t.jsxs(te,{children:[n.totp?null:t.jsxs($,{size:"sm",variant:"ghost",onClick:()=>s(N=>({...N,totp:!0})),children:[t.jsx(ne,{name:"plus",size:12})," Add a code field"]}),t.jsxs($,{size:"sm",variant:"ghost",onClick:()=>s(N=>({...N,extra:[...N.extra,{label:"",value:""}]})),children:[t.jsx(ne,{name:"plus",size:12})," Add another field"]})]})]}),t.jsxs("div",{className:"ss-notes",children:[t.jsx(AQ,{site:e.site}),(k=e.warnings)==null?void 0:k.map(N=>t.jsx("p",{className:"ss-warning",role:"note",children:N},N)),t.jsxs("p",{className:"ss-note",children:["Kept in the vault and never shown again, not even here. ",x," never sees them: buddi types them into the page itself."]}),t.jsxs("p",{className:"ss-note",children:["Saved as ",CQ(g)," in Keys and secrets."]})]})]}),t.jsxs("div",{className:"ss-sheet-foot",children:[l?t.jsx(j2,{}):null,t.jsx(re,{message:o}),t.jsxs(te,{align:"end",children:[t.jsx($,{onClick:h,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:u,onClick:()=>m("fill"),children:c==="fill"?"Saving…":"Save and fill"})]}),t.jsxs("p",{className:"ss-save-only",children:["Rather sign in yourself this time? ",t.jsx("button",{type:"button",className:"wb-link",disabled:u,onClick:()=>m("save"),children:"Save only"})," keeps them for next time and hands you the page."]})]})]})}function TQ(e){var s;const n=((s=(e??"").split(/\s[·|–—-]\s/)[0])==null?void 0:s.trim())??"";return n&&n.length<=40?`${n} `:""}function b1(e){if(!e||e.tool!=="secrets.use_set")return null;const n=e.canonicalArgs;if(!n||typeof n.site!="string"||!Array.isArray(n.items))return null;const s=n.items.filter(r=>typeof r.secret=="string").map(r=>({secret:String(r.secret),...typeof r.field=="string"?{field:r.field}:{}}));return s.length>0?{site:n.site,items:s}:null}function RQ({set:e,agentName:n,pageTitle:s,phone:r,busy:a,error:i,onFill:l,onSelf:o}){return t.jsxs("section",{className:"wb-question ss-card ss-saved","data-phone":r?"true":void 0,"aria-label":"Approval needed","data-testid":"secret-set-dock",children:[t.jsxs("div",{className:"br-ask-head",children:[t.jsx("span",{className:"wb-question-kicker",children:"Needs your OK"}),t.jsxs("strong",{children:[t.jsx("span",{className:"ss-saved-mark","aria-hidden":"true",children:"✓"}),"Saved ",e.items.length," secret",e.items.length===1?"":"s"," for ",e.site]})]}),t.jsxs("div",{className:"wb-dock-section",children:[t.jsx("ul",{className:"ss-set","aria-label":"What will be filled",children:e.items.map(c=>t.jsxs("li",{children:[t.jsx(ne,{name:"key",size:14}),t.jsx("span",{className:"ss-set-name",children:c.secret}),c.field?t.jsxs("span",{className:"ss-set-into",children:["into ",c.field]}):null]},c.secret))}),t.jsxs("div",{className:"wb-dock-where",children:["On ",e.site,", the ",TQ(s),"page ",n," has open. ",n," never sees them; buddi types them in."]}),t.jsx(re,{message:i})]}),t.jsx("div",{className:"wb-dock-section",children:t.jsxs(te,{align:"end",children:[t.jsx("a",{className:"wb-link ss-quiet-link",href:ze("secrets"),children:"Edit in Keys and secrets"}),t.jsx(ht,{}),t.jsx($,{size:"sm",variant:"ghost",disabled:a!==null,onClick:o,children:"I’ll sign in myself"}),t.jsx($,{size:"sm",variant:"accent",disabled:a!==null,onClick:l,children:a==="approve"?"Filling…":"Fill them in"})]})})]})}const v2="approval-dock";function IQ(){var n;const e=document.getElementById(v2);e&&((n=e.scrollIntoView)==null||n.call(e,{block:"nearest"}),e.focus())}const PQ=["workspace","cwd","workdir","root"];function y2({approvals:e,timezone:n,now:s,version:r,onDecided:a,onSay:i,onOpenFull:l,phone:o,onSignInMyself:c,pageTitle:u,onSecretSet:h}){const[m,f]=d.useState([]),p=e.filter(w=>!m.includes(w.approvalId)),x=p[0];if(!x)return null;const g=w=>f(v=>v.includes(w)?v:[...v,w]);return t.jsx(MQ,{item:x,count:p.length,timezone:n,now:s,version:r,onSettled:w=>{g(x.approvalId),w&&a(w)},onSay:i,onOpenFull:()=>l(x.toolUseId),phone:o===!0,...c?{onSignInMyself:c}:{},...u?{pageTitle:u}:{},...h?{onSecretSet:h}:{}},x.approvalId)}function MQ({item:e,count:n,timezone:s,now:r,version:a,onSettled:i,onSay:l,onOpenFull:o,phone:c=!1,onSignInMyself:u,pageTitle:h,onSecretSet:m}){var F,U,L;const[f,p]=d.useState(null),[x,g]=d.useState(null),[w,v]=d.useState(null),[j,y]=d.useState("");d.useEffect(()=>{let M=!1;return T.approval(e.approvalId).then(z=>{M||(p(z),z.state!=="pending"&&i(z))}).catch(z=>{M||g(z instanceof pe?z.message:String(z))}),()=>{M=!0}},[e.approvalId,a]);const k=f!==null&&f.state==="pending"&&Date.parse(f.expiresAt)<=r;d.useEffect(()=>{k&&f&&i({...f,state:"expired"})},[k]);const{values:N,controls:b}=Ib(f==null?void 0:f.choices),S=b1(f)!==null;d.useEffect(()=>(m==null||m(S),()=>m==null?void 0:m(!1)),[S]);const C=(M,z)=>{const D=j.trim();v(M),g(null),(N&&M==="approve"?T.decide(e.approvalId,M,z,N):T.decide(e.approvalId,M,z)).then(K=>{i(K.action),D&&l(D)}).catch(K=>{g(K instanceof pe?K.message:String(K)),v(null)})},A=Qq(f);if(f&&A){const M=Uu(f.agentId)?zu:f.agentId?f.agentId.charAt(0).toUpperCase()+f.agentId.slice(1):"An agent";return t.jsx(Xq,{action:f,run:A,agentName:M,count:n,busy:w,error:x,onDecide:z=>C(z)})}const E=b1(f);if(f&&E){const M=Uu(f.agentId)?zu:f.agentId?f.agentId.charAt(0).toUpperCase()+f.agentId.slice(1):"The agent";return t.jsx(RQ,{set:E,agentName:M,...h?{pageTitle:h}:{},phone:c,busy:w,error:x,onFill:()=>C("approve"),onSelf:()=>{C("reject"),u==null||u()}})}const R=w!==null||f===null||f.state!=="pending",P=((F=f==null?void 0:f.permissionScopes)==null?void 0:F.includes("always"))??!1,O=f?sk(f.tool,f.canonicalArgs)??DQ(f.preview):null,I=f?OQ(f):null;return t.jsxs("section",{id:v2,tabIndex:-1,className:"wb-question","data-kind":"approval","aria-label":"Approval needed","data-testid":"approval-dock",children:[t.jsxs("div",{className:"wb-question-head",children:[t.jsx("span",{className:"wb-question-kicker",children:"Needs your OK"}),n>1?t.jsxs("span",{className:"wb-dock-count","data-testid":"approval-dock-count",children:["1 of ",n]}):null,t.jsx("strong",{children:f?gl(f.tool):"Loading the request…"}),e.askedBy?t.jsx("span",{className:"wb-dock-asker","data-testid":"approval-dock-asker",children:e.askedBy}):null]}),O||I?t.jsxs("div",{className:"wb-dock-section wb-dock-subject",children:[O?t.jsx("code",{className:"wb-dock-gist",children:O}):null,I?t.jsxs("span",{className:"wb-dock-where",children:["in ",t.jsx("span",{className:"mono",children:I})]}):null]}):null,b?t.jsx("div",{className:"wb-dock-section",children:b}):null,t.jsx(re,{message:x}),t.jsx("div",{className:"wb-dock-section",children:t.jsx("input",{className:"wb-dock-instead",value:j,onChange:M=>y(M.target.value),onKeyDown:M=>{M.key==="Enter"&&M.preventDefault()},placeholder:"Tell the agent what to do instead (optional)","aria-label":"Tell the agent what to do instead (optional)",disabled:w!==null})}),t.jsxs("div",{className:"wb-dock-section wb-dock-actions",children:[t.jsxs("span",{className:"wb-dock-meta",children:[f?t.jsxs(t.Fragment,{children:["Expires ",St(f.expiresAt,s)," · "]}):null,t.jsx("button",{type:"button",className:"wb-link",onClick:o,children:"See the full request on the Canvas"})]}),t.jsx($,{variant:"ghost",size:"sm",disabled:R,onClick:()=>C("reject"),children:w==="reject"?"Rejecting…":((U=f==null?void 0:f.answers)==null?void 0:U.reject)??"Reject"}),P?t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",size:"sm",disabled:R,onClick:()=>C("approve","conversation"),children:"Auto: this conversation"}),t.jsx($,{size:"sm",disabled:R,onClick:()=>C("approve","always"),children:"Always: this agent"})]}):null,t.jsx($,{variant:"good",size:"sm",disabled:R,onClick:()=>C("approve"),children:w==="approve"?"Approving…":((L=f==null?void 0:f.answers)==null?void 0:L.approve)??(P?"Allow once":"Approve")})]})]})}function OQ(e){for(const n of[e.canonicalArgs,e.envelope])if(!(n===null||typeof n!="object"||Array.isArray(n)))for(const s of PQ){const r=n[s];if(typeof r=="string"&&r.trim()!=="")return r.trim()}return null}function DQ(e){const n=(e??"").split(`
121
- `).map(s=>s.trim()).find(Boolean);return n?n.length>160?`${n.slice(0,157)}…`:n:null}const LQ=2e3;function FQ({conversationId:e,agentId:n,runId:s=null,result:r=null,waiting:a=null,agents:i=[]}){const l=r!==null,[o,c]=d.useState(l),u=!o||a!==null,{data:h,error:m}=je(()=>nt.conversation(e),[e,o,(a==null?void 0:a.approvalId)??null],u?LQ:void 0),f=(h==null?void 0:h.runs)??[],p=s===null?null:f.find(k=>k.runId===s)??null,x=l||a===null&&(s!==null?p!==null&&p.finishedAt!==null:f.length>0&&f.every(k=>k.finishedAt!==null));d.useEffect(()=>{x&&c(!0)},[x]);const g=r?r.ok?"done":"failed":a!=null&&a.approvalId?"waiting":x?"done":"working",w=i.find(k=>k.id===n)??null,v=(w==null?void 0:w.name)??(h==null?void 0:h.agentId)??n,j=(h==null?void 0:h.messages)??[],y=(r==null?void 0:r.text)??_Q(j);return t.jsxs("div",{className:"wb-delegate","data-testid":"delegate-view","data-status":g,children:[t.jsxs("header",{className:"wb-delegate-head",children:[t.jsx(vn,{agents:i,id:n}),t.jsxs("div",{className:"wb-delegate-who",children:[t.jsx("strong",{children:v}),t.jsx("span",{className:"wb-delegate-status","data-status":g,role:"status",children:g==="working"?t.jsxs(t.Fragment,{children:["Working",t.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]})]}):g==="waiting"?"Waiting for your approval":g==="failed"?"Failed":"Done"})]})]}),m?t.jsx("p",{className:"muted",children:m}):null,t.jsx("div",{className:"wb-delegate-work",children:j.map((k,N)=>t.jsx("div",{className:"wb-delegate-turn",children:(k.blocks??[]).map((b,S)=>{if(b.type==="thinking")return b.text.trim()===""?null:t.jsx(Fv,{text:b.text},S);if(b.type==="tool_use"){const C=UQ(zQ(j,b.id));return t.jsx(_v,{label:gl(b.name),tool:b.name,ok:C.ok,running:C.running,waiting:C.waiting,status:C.status,gist:sk(b.name,b.input),opens:!1,onOpen:()=>{}},S)}return null})},k.id??N))}),y?t.jsx("div",{className:"wb-delegate-answer","data-testid":"delegate-answer",children:t.jsx(pr,{text:y})}):g==="working"||g==="waiting"?t.jsxs("p",{className:"muted",children:[v," has not answered yet."]}):null,r!=null&&r.files&&r.files.length>0?t.jsx("div",{className:"wb-msg-files",role:"list","aria-label":`Files ${v} made`,"data-testid":"delegate-files",children:r.files.map(k=>t.jsx("a",{role:"listitem",href:la(k.artifactId),download:!0,children:t.jsx(bd,{name:k.filename??"Untitled file",mime:k.mime,sizeBytes:k.sizeBytes,thumbnail:Cb(k.mime)?Dr(k.artifactId):null})},k.artifactId))}):null,t.jsxs("div",{className:"wb-delegate-actions",children:[g==="waiting"?t.jsx($,{variant:"accent",onClick:()=>IQ(),"data-testid":"delegate-to-approval",children:"Go to the approval"}):null,t.jsx("a",{className:"ui-btn",href:ut(n||(h==null?void 0:h.agentId)||"",e),children:"Open this conversation"})]})]})}function _Q(e){for(let n=e.length-1;n>=0;n-=1){const s=e[n];if(s.role!=="assistant")continue;const r=(s.blocks??[]).filter(a=>a.type==="text").map(a=>a.text.trim()).filter(a=>a!=="").join(`
122
-
123
- `);if(r!=="")return r}return null}function zQ(e,n){for(const s of e)for(const r of s.blocks??[])if(r.type==="tool_result"&&r.toolUseId===n)return r;return null}function UQ(e){var s;if(e===null)return{running:!0,ok:null,waiting:!1,status:void 0};const n=(s=e.approval)==null?void 0:s.state;return n==="pending"?{running:!1,ok:null,waiting:!0,status:"waiting approval"}:n==="approved"||n==="executing"?{running:!0,ok:null,waiting:!1,status:"running"}:n==="succeeded"?{running:!1,ok:!0,waiting:!1,status:void 0}:n?{running:!1,ok:!1,waiting:!1,status:n}:{running:!1,ok:e.ok,waiting:!1,status:void 0}}const k1=1024*1024;function BQ({files:e,agentId:n,root:s,revision:r}){const[a,i]=d.useState({kind:"dir",path:""});return d.useEffect(()=>i({kind:"dir",path:""}),[e.plugin,n]),t.jsx("div",{className:"wb-files","data-testid":"files-view",children:a.kind==="dir"?t.jsx(WQ,{files:e,agentId:n,root:s,path:a.path,revision:r,go:i}):t.jsx(HQ,{files:e,agentId:n,root:s,path:a.path,revision:r,go:i})})}function w2({root:e,path:n,go:s}){const r=n===""?[]:n.split("/"),a=[{label:e,path:""},...r.map((i,l)=>({label:i,path:r.slice(0,l+1).join("/")}))];return t.jsx("nav",{className:"wb-files-crumbs","aria-label":"Where you are in the workspace",children:a.map((i,l)=>{const o=l===a.length-1;return t.jsxs("span",{className:"wb-files-crumb",children:[l>0?t.jsx("span",{className:"wb-files-sep","aria-hidden":"true",children:"/"}):null,o?t.jsx("span",{className:"wb-files-here mono","aria-current":"location",children:i.label}):t.jsx("button",{type:"button",className:"wb-files-step mono",onClick:()=>s({kind:"dir",path:i.path}),children:i.label})]},i.path)})})}function WQ({files:e,agentId:n,root:s,path:r,revision:a,go:i}){const[l,o]=d.useState(null),[c,u]=d.useState(null),[h,m]=d.useState(!1),[f,p]=d.useState(null);d.useEffect(()=>{let w=!1;return u(null),T.pageQuery(e.plugin,e.list,{agent:n,...r?{path:r}:{}}).then(v=>{w||o(v.data)}).catch(v=>{w||u(v instanceof Error?v.message:String(v))}),()=>{w=!0}},[e.plugin,e.list,n,r,a]),d.useEffect(()=>p(null),[r]);const x=async()=>{m(!0),p(null);try{const w=await fetch(T.pageFileUrl(e.plugin,e.archive,{agent:n,...r?{path:r}:{}}),{credentials:"same-origin"});if(!w.ok){const k=await w.json().catch(()=>null);p((k==null?void 0:k.error)??"The archive could not be made.");return}const v=await w.blob(),j=URL.createObjectURL(v),y=document.createElement("a");y.href=j,y.download=`${r===""?s:r.split("/").at(-1)}.zip`,y.click(),window.setTimeout(()=>URL.revokeObjectURL(j),1e4)}catch{p("The archive could not be made.")}finally{m(!1)}},g=l&&l.path===r?l.entries:null;return t.jsxs(t.Fragment,{children:[t.jsxs(te,{children:[t.jsx(w2,{root:s,path:r,go:i}),t.jsx(ht,{}),t.jsx($,{size:"sm",onClick:()=>void x(),disabled:h||g===null||g.length===0,children:h?"Packing…":"Download as archive"})]}),f?t.jsx(Q,{tone:"warning",role:"alert",children:f}):null,c?t.jsx(Q,{tone:"critical",role:"alert",children:c}):null,g===null?c?null:t.jsx(Ee,{children:"Reading the folder…"}):g.length===0?t.jsx(Ee,{children:r===""?t.jsxs(t.Fragment,{children:["Nothing in this workspace yet. To hand the agent a file, add it to the ",t.jsx("a",{href:Da,children:"Files library"})," and mention it here."]}):"This folder is empty."}):t.jsx(yt,{children:g.map(w=>t.jsx(pt,{href:"#",onClick:()=>i({kind:w.kind,path:w.path}),lead:t.jsx(VQ,{kind:w.kind}),title:t.jsxs("span",{className:"mono",children:[w.name,w.kind==="dir"?"/":""]}),side:w.kind==="file"?Yn(w.bytes):void 0},w.path))}),l&&l.path===r&&(l.skipped>0||l.truncated)?t.jsxs("p",{className:"wb-files-note",children:[l.truncated?`Only the first ${l.entries.length} entries are shown. `:"",l.skipped>0?`${l.skipped} ${l.skipped===1?"entry is":"entries are"} not shown: symbolic links and protected paths are never read.`:""]}):null]})}function HQ({files:e,agentId:n,root:s,path:r,revision:a,go:i}){const[l,o]=d.useState(null),[c,u]=d.useState(null),[h,m]=d.useState(!1);d.useEffect(()=>{let v=!1;return u(null),T.pageQuery(e.plugin,e.stat,{agent:n,path:r}).then(j=>{v||o(j.data)}).catch(j=>{v||u(j instanceof Error?j.message:String(j))}),()=>{v=!0}},[e.plugin,e.stat,n,r,a]);const f=l&&l.path===r?l:null,p=f?`${f.bytes}-${Math.round(f.mtimeMs)}`:"",x=f?T.pageFileUrl(e.plugin,e.read,{agent:n,path:r,v:p}):"",g=T.pageFileUrl(e.plugin,e.read,{agent:n,path:r,download:"1"}),w=(f==null?void 0:f.type)==="text"&&f.bytes<=k1;return t.jsxs(t.Fragment,{children:[t.jsxs(te,{children:[t.jsx(w2,{root:s,path:r,go:i}),t.jsx(ht,{}),w?t.jsx($,{size:"sm","aria-pressed":h,onClick:()=>m(v=>!v),children:"Wrap"}):null,t.jsx(it,{size:"sm",href:g,download:(f==null?void 0:f.name)??r.split("/").at(-1),children:"Download"})]}),c?t.jsx(Q,{tone:"critical",role:"alert",children:c}):null,f===null?c?null:t.jsx(Ee,{children:"Reading the file…"}):f.type==="image"?t.jsx("figure",{className:"wb-files-picture",children:t.jsx("img",{src:x,alt:f.name})}):f.type==="pdf"?t.jsx("div",{className:"file-preview file-preview-pdf",children:t.jsx("object",{data:x,type:"application/pdf","aria-label":f.name,children:t.jsx(Q,{children:"Your browser cannot show this PDF here. Download it to open it."})})}):w?t.jsx(KQ,{src:x,wrap:h}):t.jsxs(t.Fragment,{children:[t.jsx(Q,{children:f.type==="text"?`This file is over ${Yn(k1)}, too long to read here. Download it to open it.`:"This kind of file is not shown here. Download it to open it."}),t.jsx(on,{items:[{label:"Size",value:Yn(f.bytes)},{label:"Type",value:t.jsx("span",{className:"mono",children:f.mime})}]})]})]})}function KQ({src:e,wrap:n}){const[s,r]=d.useState(null),[a,i]=d.useState(!1);return d.useEffect(()=>{let l=!1;return i(!1),fetch(e,{credentials:"same-origin"}).then(async o=>{if(!o.ok)throw new Error(String(o.status));const c=await o.text();l||r(c)}).catch(()=>{l||i(!0)}),()=>{l=!0}},[e]),a?t.jsx(Q,{tone:"critical",children:"The file could not be read."}):s===null?t.jsx(Ee,{children:"Reading the file…"}):s===""?t.jsx(Ee,{children:"This file is empty."}):t.jsx("pre",{className:"wb-files-text","data-wrap":n?"true":void 0,"data-testid":"files-text",children:s})}function VQ({kind:e}){return t.jsx("span",{className:"wb-files-icon","data-kind":e,"aria-hidden":"true",children:t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.4,strokeLinecap:"round",strokeLinejoin:"round",children:e==="dir"?t.jsx("path",{d:"M2 4.2h4.2l1.4 1.6H14v7H2z"}):t.jsx("path",{d:"M4 2.4h5l3 3v8.2H4zM9 2.4v3h3"})})})}function GQ({input:e,output:n,ok:s}){const r=k7(e),a=MM(n)??(s?"sent":"not sent");return t.jsxs("div",{className:"wb-envelope",children:[t.jsxs("div",{className:"envelope",children:[t.jsxs("dl",{className:"envelope-head",children:[t.jsx("dt",{children:"To"}),t.jsx("dd",{className:"wb-envelope-action",children:"You"}),t.jsx("dt",{children:"Status"}),t.jsx("dd",{children:t.jsx($e,{tone:N7(a,s),dot:!0,children:a})})]}),t.jsxs("div",{className:"envelope-body",children:[t.jsx("strong",{children:r.title}),r.text?`
124
-
125
- ${r.text}`:null]})]}),t.jsx(Vt,{summary:"The call",children:t.jsxs("dl",{className:"ui-kv wb-envelope-fields",children:[t.jsx("dt",{children:"Urgency"}),t.jsx("dd",{children:r.urgency}),r.link?t.jsxs(t.Fragment,{children:[t.jsx("dt",{children:"Link"}),t.jsx("dd",{className:"mono",children:r.link})]}):null,r.key?t.jsxs(t.Fragment,{children:[t.jsx("dt",{children:"Key"}),t.jsx("dd",{className:"mono",children:r.key})]}):null]})})]})}const Uc=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)?e:{},fn=e=>typeof e=="string"&&e.trim()!==""?e:null,qQ={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 YQ(e){const n=e.slice(0,4e3);if(n.length<20)return!1;let s=0;for(const r of n){const a=r.codePointAt(0);(a===65533||a<32&&a!==9&&a!==10&&a!==13||a>=127&&a<160)&&(s+=1)}return s/n.length>.1}function nx(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function QQ(e){if(!e)return null;try{const n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"?n.href:null}catch{return null}}function Gv(e){try{const n=new URL(e);return`${n.hostname.replace(/^www\./,"")}${n.pathname.replace(/\/+$/,"")}${n.search}`}catch{return e}}function N1(e){var n;return((n=e.match(/[\p{L}\p{N}]/u))==null?void 0:n[0])??"?"}function b2(e){const n=Uc(e.input),s=Uc(e.output),r={input:e.input,...e.ok===null?{status:"Awaiting result"}:{output:e.output},...e.error===void 0?{}:{error:e.error}},a=e.ok===!1,i=fn(e.error)??fn(Uc(e.error).message);if(Array.isArray(s.results)||fn(n.query)&&!fn(n.url)){const m=(Array.isArray(s.results)?s.results:[]).map(p=>Uc(p)).flatMap(p=>{const x=fn(p.url);return x?[{title:fn(p.title)??nx(x),url:x,host:fn(p.source)??nx(x),snippet:fn(p.snippet)}]:[]}),f=s.available===!1;return{kind:"search",id:e.id,raw:r,query:fn(s.query)??fn(n.query)??"",state:e.ok===null?"pending":a||f?"failed":"ok",provider:fn(s.provider),results:m,why:a?`The search failed${i?`: ${i}`:"."}`:f?fn(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=fn(s.url)??fn(n.url)??"",o=!a&&s.ok!==!1&&YQ(fn(s.text)??""),c=a||s.ok===!1||o,u=o?"unreadable":fn(s.problem),h=fn(s.message);return{kind:"page",id:e.id,url:l,raw:r,host:fn(s.source)??nx(l),state:e.ok===null?"pending":c?"failed":"ok",title:fn(s.title),text:o?null:fn(s.text),truncated:s.truncated===!0,retrievedAt:fn(s.retrievedAt)??e.at,why:c?(u&&qQ[u])??(h?h.charAt(0).toUpperCase()+h.slice(1)+(/[.!?]$/.test(h)?"":"."):null)??`The read failed${i?`: ${i}`:"."}`:null}}function JQ(e){const n=e.entries.map(b2),s=n.filter(a=>a.kind==="search").length,r=n.length-s;return[s?`${s} ${s===1?"search":"searches"}`:null,r?`${r} ${r===1?"page":"pages"}`:null].filter(Boolean).join(" · ")}function XQ(e){return e.split(/\s+/).filter(Boolean).length}function ZQ(e){return e>=1e3?`${(e/1e3).toFixed(1).replace(/\.0$/,"")}k words`:`${e} ${e===1?"word":"words"}`}function eJ(e,n){if(!e)return null;const s=new Date(e);return Number.isNaN(s.getTime())?null:Lt(s,n??Intl.DateTimeFormat().resolvedOptions().timeZone)}function k2({url:e,className:n,children:s}){const r=QQ(e);return r?t.jsxs("a",{className:`wb-src-link ${n}`,href:r,target:"_blank",rel:"noopener noreferrer",children:[s,t.jsx("span",{className:"wb-src-out","aria-hidden":"true",children:"↗"})]}):t.jsx("span",{className:n,children:s})}function N2({value:e}){const[n,s]=d.useState(!1);return t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:"wb-src-quiet","data-raw":"","aria-expanded":n,onClick:()=>s(!n),children:n?"Hide JSON":"Raw JSON"}),n?t.jsx("pre",{className:"wb-src-raw",children:JSON.stringify(e,null,2)}):null]})}function tJ({page:e,focused:n,timezone:s}){const[r,a]=d.useState(n),[i,l]=d.useState(!1),o=d.useRef(null);if(d.useEffect(()=>{var f,p;n&&(a(!0),(p=(f=o.current)==null?void 0:f.scrollIntoView)==null||p.call(f,{block:"nearest"}))},[n]),e.state==="pending")return t.jsx("li",{className:"wb-src-page","data-state":"pending",ref:o,children:t.jsxs("div",{className:"wb-src-row",children:[t.jsx("span",{className:"wb-src-tile","data-state":"pending","aria-hidden":"true",children:N1(e.host)}),t.jsxs("span",{className:"wb-src-head",children:[t.jsxs("span",{className:"wb-src-title",children:["Reading ",e.host,"…"]}),t.jsx("span",{className:"wb-src-meta",children:e.url})]}),t.jsx("span",{})]})});const c=e.state==="failed",u=e.text?XQ(e.text):0,h=eJ(e.retrievedAt,s),m=[e.host,h?`read ${h}`:null,u?ZQ(u):null,u?`${Math.max(1,Math.round(u/230))} min read`:null].filter(Boolean).join(" · ");return t.jsxs("li",{className:"wb-src-page","data-open":r?"true":void 0,"data-state":e.state,ref:o,children:[t.jsxs("div",{className:"wb-src-row",children:[t.jsx("span",{className:"wb-src-tile","data-tone":c?"critical":void 0,"aria-hidden":"true",children:c?"!":N1(e.host)}),t.jsxs("span",{className:"wb-src-head",children:[c?t.jsxs("span",{className:"wb-src-title",children:["Couldn’t read ",e.host]}):t.jsx(k2,{url:e.url,className:"wb-src-title",children:e.title??e.host}),c?t.jsx("span",{className:"wb-src-why",children:e.why}):t.jsx("span",{className:"wb-src-meta",children:m})]}),t.jsx("button",{type:"button",className:"wb-src-toggle","aria-expanded":r,"aria-label":r?`Hide what was read from ${e.host}`:`Show what was read from ${e.host}`,onClick:()=>a(!r),children:t.jsx(ne,{name:"chevron"})})]}),r?t.jsxs("div",{className:"wb-src-body",children:[c?t.jsx("p",{className:"wb-src-note",children:e.url}):t.jsxs(t.Fragment,{children:[e.text?t.jsx("p",{className:"wb-src-text","data-clamped":i?void 0:"true",children:e.text}):t.jsx("p",{className:"wb-src-note",children:"The page had no text to read."}),e.truncated?t.jsx("p",{className:"wb-src-note",children:"Only the beginning of the page was read; it was longer than the limit."}):null]}),t.jsxs("div",{className:"wb-src-foot",children:[!c&&e.text?t.jsx("button",{type:"button",className:"wb-src-quiet",onClick:()=>l(!i),children:i?"Show less":"Show more"}):null,t.jsx(N2,{value:e.raw})]})]}):null]})}const S1=3;function nJ({search:e,read:n,focused:s}){const[r,a]=d.useState(!1),i=d.useRef(null);d.useEffect(()=>{var c,u;s&&((u=(c=i.current)==null?void 0:c.scrollIntoView)==null||u.call(c,{block:"nearest"}))},[s]);const l=r?e.results:e.results.slice(0,S1),o=e.state==="pending"?"Searching…":[e.provider,e.state==="ok"?`${e.results.length} ${e.results.length===1?"result":"results"}`:null].filter(Boolean).join(" · ");return t.jsxs("div",{className:"wb-src-list","data-state":e.state,ref:i,children:[t.jsxs("div",{className:"wb-src-query",children:[t.jsxs("span",{className:"wb-src-query-text",children:["“",e.query,"”"]}),o?t.jsx("span",{className:"wb-src-query-meta",children:o}):null,t.jsx("span",{className:"wb-src-query-raw",children:t.jsx(N2,{value:e.raw})})]}),e.state==="failed"?t.jsx("p",{className:"wb-src-empty wb-src-why",children:e.why}):null,e.state==="ok"&&e.results.length===0?t.jsx("p",{className:"wb-src-empty",children:"No results."}):null,l.length>0?t.jsx("ol",{className:"wb-src-results",children:l.map(c=>t.jsxs("li",{className:"wb-src-result",children:[t.jsx(k2,{url:c.url,className:"wb-src-result-title",children:c.title}),t.jsx("span",{className:"wb-src-result-site",children:c.host}),c.snippet?t.jsx("p",{className:"wb-src-result-snippet",children:c.snippet}):null,n.has(Gv(c.url))?t.jsx("span",{className:"wb-src-result-side",children:t.jsx($e,{tone:"good",children:"Read"})}):null]},c.url))}):null,e.results.length>S1?t.jsx("div",{className:"wb-src-more",children:t.jsx("button",{type:"button",className:"wb-src-quiet",onClick:()=>a(!r),children:r?"Show fewer":`Show all ${e.results.length}`})}):null]})}function sJ({entries:e,focus:n,timezone:s}){const r=e.map(b2),a=r.filter(o=>o.kind==="page"),i=r.filter(o=>o.kind==="search"),l=new Set(a.filter(o=>o.state==="ok").flatMap(o=>{const c=e.find(h=>h.id===o.id),u=fn(Uc(c==null?void 0:c.input).url);return[Gv(o.url),...u?[Gv(u)]:[]]}));return t.jsxs("div",{className:"wb-src",children:[a.length>0?t.jsxs("div",{className:"wb-src-group",children:[t.jsx("p",{className:"wb-src-kicker",children:"Read"}),t.jsx("ul",{className:"wb-src-list",children:a.map(o=>t.jsx(tJ,{page:o,focused:n===o.id,timezone:s},o.id))})]}):null,i.length>0?t.jsxs("div",{className:"wb-src-group",children:[t.jsx("p",{className:"wb-src-kicker",children:"Searched"}),i.map(o=>t.jsx(nJ,{search:o,read:l,focused:n===o.id},o.id))]}):null]})}const rJ=3,aJ=152,iJ=104,lJ=100,oJ=2,sx=OM;function cJ({renderables:e,activeId:n,onActivate:s,timezone:r,onDecided:a,onChangeAgent:i,face:l,cardFace:o,descriptors:c,grantedTools:u,agentName:h,maxTabs:m,browserPanel:f,browserMenu:p,agents:x,onClose:g,onCloseMany:w,touched:v,turnStartedAt:j,unread:y,now:k=Date.now,loading:N=!1}){var U;const[b,S]=uJ(m),[C,A]=d.useState({}),E=d.useMemo(()=>hJ(e,r),[e,r]);if(e.length===0)return t.jsxs("div",{className:"wb-canvas","data-testid":"canvas",children:[t.jsx("div",{className:"wb-canvas-tabs",ref:b,"aria-hidden":"true",children:t.jsx("span",{className:"wb-canvas-label",children:"Canvas"})}),t.jsx("div",{className:"wb-canvas-body wb-canvas-body-empty",children:N?null:t.jsxs("div",{className:"wb-empty",children:[l?t.jsx("span",{className:"wb-empty-face",children:l}):null,t.jsx("p",{className:"ui-empty wb-empty-line",children:gJ(h,xJ(c??[],u??[]))})]})})]});const R=e.some(L=>L.id===n)?n:e[e.length-1].id,{shown:P,hidden:O}=z7(e,R,S,v,{turnStartedAt:j??null}),I=L=>L.id!==R&&(y==null?void 0:y.has(L.id))===!0,F=e.filter(rx).map(L=>L.id);return t.jsx("div",{className:"wb-canvas","data-testid":"canvas",children:t.jsxs(u5,{value:R,onValueChange:s,className:"contents",children:[t.jsxs("div",{className:"wb-canvas-tabs",ref:b,children:[t.jsx("span",{className:"wb-canvas-label","aria-hidden":"true",children:"Canvas"}),t.jsx(d5,{className:"wb-tabstrip","aria-label":"Canvas",children:P.map(L=>t.jsxs("div",{className:"wb-tab-item",children:[t.jsxs(h5,{value:L.id,className:"wb-tab","data-tone":L.tone,"data-unread":I(L)?"true":void 0,onKeyDown:M=>{M.key==="Delete"&&g&&rx(L)&&(M.preventDefault(),g(L.id))},children:[L.tone==="warning"||L.tone==="critical"?t.jsx("span",{className:"wb-tab-dot","data-tone":L.tone,"aria-hidden":"true"}):I(L)?t.jsx("span",{className:"wb-tab-dot","data-tone":"unread","aria-hidden":"true"}):null,t.jsx("span",{className:"wb-tab-text",children:E.get(L.id)??L.title}),L.count?t.jsx("span",{className:"wb-tab-count",children:L.count}):null]}),g&&rx(L)?t.jsx("button",{className:"wb-tab-close","aria-label":`Close ${E.get(L.id)??L.title} tab`,title:"Dismiss panel; keep conversation history",onClick:()=>g(L.id),children:"×"}):null]},L.id))}),t.jsx(mJ,{items:O,unread:new Set(O.filter(I).map(L=>L.id)),onActivate:s,timezone:r,labels:E,groups:U7(O,{now:k(),turnStartedAt:j??null,...v?{touched:v}:{}}),...w?{onCloseAll:F.length>0?()=>w(F):void 0,onCloseOthers:F.some(L=>L!==R)?()=>w(F.filter(L=>L!==R)):void 0}:{}}),p&&((U=e.find(L=>L.id===R))==null?void 0:U.source)==="browser"?t.jsx("span",{className:"wb-canvas-menu",children:p}):null]}),e.map(L=>{const M=L.versions??[],z=C[`${L.id}:${M.length}:${L.focus??""}`]??(L.focus&&M.some(B=>B.id===L.focus)?L.focus:null),D=z?M.find(B=>B.id===z)??null:null,K=D?dJ(L,D):L;return t.jsxs(f5,{value:L.id,className:"wb-canvas-body","data-renderer":K.source==="descriptor"&&K.renderer==="preview"?"preview":void 0,"data-dense":vJ.has(K.renderer)?"true":void 0,"data-page":K.source==="browser"?"true":void 0,children:[M.length>1?t.jsx(fJ,{versions:M,current:K.id===L.id&&!D?M.at(-1).id:(D==null?void 0:D.id)??M.at(-1).id,timezone:r,onPick:B=>A(se=>({...se,[`${L.id}:${M.length}:${L.focus??""}`]:B}))}):null,K.source==="browser"?f:t.jsxs("section",{className:"ui-panel","data-flush":K.source==="descriptor"&&K.renderer==="preview"?"true":void 0,children:[K.source!=="files"&&!C1(K)&&!(K.source==="descriptor"&&K.renderer==="preview")?t.jsxs("header",{className:"ui-panel-head",children:[t.jsx("h2",{className:"ui-panel-title",children:K.title}),t.jsx("span",{className:"ui-panel-tool mono",children:K.source==="sources"?JQ(K.props):K.tool})]}):null,K.tone==="critical"?t.jsxs("p",{className:"muted",children:["Recorded tool failure",K.at?` · ${St(K.at,Intl.DateTimeFormat().resolvedOptions().timeZone)}`:"",". This is history, not live session status."]}):null,C1(K)?t.jsx(YG,{value:K.props.value,title:K.title,tool:K.tool,face:o,timezone:r}):K.source==="profile"?t.jsx(r7,{...K.props,...i?{onChange:i}:{}}):K.source==="artifact"?t.jsx(j7,{...K.props}):K.source==="files"?t.jsx(BQ,{...K.props}):K.source==="sources"?t.jsx(sJ,{...K.props,timezone:r}):K.source==="notify"?t.jsx(GQ,{...K.props}):K.source==="delegate"?t.jsx(FQ,{...K.props,agents:x??[]}):t.jsx(PG,{renderer:K.renderer,props:K.props,timezone:r,onDecided:a})]})]},L.id)})]})})}function C1(e){var n;return e.renderer==="structured"&&(e.source==="fallback"||e.source==="descriptor")&&!((n=e.props)!=null&&n.failed)}function rx(e){return e.source==="approval"?!1:e.source==="browser"?e.pinned!==!0:e.source!=="files"}function uJ(e){const[n,s]=d.useState(sx),r=d.useRef(null);return[d.useCallback(i=>{var o;if((o=r.current)==null||o.disconnect(),r.current=null,!i||e!==void 0||typeof ResizeObserver>"u")return;const l=()=>{const c=i.clientWidth;if(c===0)return;const u=Math.floor((c-lJ-iJ)/aJ);s(Math.max(oJ,Math.min(sx,u)))};l(),r.current=new ResizeObserver(l),r.current.observe(i)},[e]),e===void 0?n:Math.min(sx,e)]}function dJ(e,n){const s={...e,title:n.title,renderer:n.renderer,props:n.props,at:n.at,substantial:n.substantial};return n.tone?s.tone=n.tone:delete s.tone,s}function hJ(e,n){const s=new Map;for(const a of e)s.set(a.title,(s.get(a.title)??0)+1);const r=new Map;for(const a of e){const i=a.subject||(s.get(a.title)??0)<2?null:jk(a.at,n);r.set(a.id,i?`${a.title} · ${i}`:a.title)}return r}function fJ({versions:e,current:n,timezone:s,onPick:r}){const a=Math.max(0,e.findIndex(c=>c.id===n)),i=e[a],l=a===e.length-1,o=jk(i.at,s);return t.jsxs("div",{className:"wb-versions",role:"group","aria-label":"Earlier results",children:[t.jsx($,{variant:"ghost",size:"sm","aria-label":"Earlier result",disabled:a===0,onClick:()=>r(e[a-1].id),children:t.jsx(ne,{name:"chevron-left"})}),t.jsxs("span",{className:"wb-versions-text",children:[l?"Latest":"Earlier"," · ",a+1," of ",e.length,o?t.jsxs("span",{className:"mono",children:[" · ",o]}):null]}),t.jsx($,{variant:"ghost",size:"sm","aria-label":"Later result",disabled:l,onClick:()=>r(e[a+1].id),children:t.jsx(ne,{name:"chevron-right"})})]})}function mJ({items:e,unread:n,groups:s,labels:r,onActivate:a,onCloseAll:i,onCloseOthers:l,timezone:o}){if(e.length===0&&!i&&!l)return null;const c=e.some(u=>u.tone==="critical")?"critical":e.some(u=>u.tone==="warning")?"warning":n.size>0?"unread":null;return t.jsxs(pd,{modal:!1,children:[t.jsx(gd,{asChild:!0,children:t.jsxs("button",{className:"wb-tab wb-tab-more","data-tone":c??void 0,"data-bare":e.length===0?"true":void 0,"aria-label":e.length>0?`${e.length} more ${e.length===1?"view":"views"} in this conversation`:"Tab actions",children:[c?t.jsx("span",{className:"wb-tab-dot","data-tone":c,"aria-hidden":"true"}):null,e.length>0?t.jsxs("span",{className:"wb-tab-text",children:[e.length," more"]}):null,t.jsx(ne,{name:"chevron-down"})]})}),t.jsx(tc,{children:t.jsxs(xd,{className:"ui-menu","data-wide":"true",align:"end",sideOffset:6,children:[s.length>0?t.jsx("div",{className:"wb-tab-timeline",children:s.map(u=>t.jsxs(ab,{children:[t.jsx(hl,{className:"ui-menu-label",children:u.label}),u.items.map(h=>{var m,f;return t.jsxs(bs,{className:"ui-menu-item",onSelect:()=>a(h.id),children:[t.jsxs("span",{className:"ui-menu-item-text",children:[h.tone==="warning"||h.tone==="critical"?t.jsx("span",{className:"wb-tab-dot","data-tone":h.tone,"aria-hidden":"true"}):n.has(h.id)?t.jsx("span",{className:"wb-tab-dot","data-tone":"unread","aria-hidden":"true"}):null,r.get(h.id)??h.title]}),t.jsx("span",{className:"ui-menu-note mono",children:jk(((f=(m=h.versions)==null?void 0:m.at(-1))==null?void 0:f.at)??h.at,o)??h.tool})]},h.id)})]},u.label))}):null,i||l?t.jsxs(t.Fragment,{children:[s.length>0?t.jsx(Xr,{className:"ui-menu-sep"}):null,t.jsx(bs,{className:"ui-menu-item",disabled:!l,onSelect:()=>l==null?void 0:l(),children:t.jsx("span",{className:"ui-menu-item-text",children:"Close others"})}),t.jsx(bs,{className:"ui-menu-item",disabled:!i,onSelect:()=>i==null?void 0:i(),children:t.jsx("span",{className:"ui-menu-item-text",children:"Close all"})})]}):null]})})]})}function jk(e,n){if(!e)return null;const s=new Date(e);return Number.isNaN(s.getTime())?null:Lt(s,n)}const pJ={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",story:"stories",audio:"recordings",query:"results",structured:"results"};function gJ(e,n){const s=e?`What ${e} shows you`:"What your agent shows you",r=[...new Set(n.map(a=>pJ[a.renderer]??"results"))].slice(0,3);return r.length>0?`${s} lands here: ${r.join(", ")}.`:`${s} lands here.`}function xJ(e,n){const s=new Set(n),r=new Set,a=e.filter(c=>{if(!s.has(c.tool))return!1;const u=jJ(c);return r.has(u)?!1:(r.add(u),!0)}),i=new Set,l=a.filter(c=>i.has(c.renderer)?!1:(i.add(c.renderer),!0)),o=a.filter(c=>!l.includes(c));return[...l,...o].slice(0,rJ)}function jJ(e){return e.title&&e.title.trim()!==""?e.title:e.tool.split(".").map(n=>n.replace(/[_-]+/g," ")).join(" · ").replace(/\b\w/,n=>n.toUpperCase())}const vJ=new Set(["table","diff","files"]),Xa=320,yJ=280,E1=24,wJ=12,bJ=[1/3,1/2,2/3],qv="buddi.chatWidth";function lm(e){return{min:Xa,max:Math.max(Xa,Math.round(e)-yJ)}}function kJ(e,n,s){return Math.max(0,Math.round(e+n-Math.max(0,s)))}function NJ(e,n){return om(e,n)}function om(e,n){const{min:s,max:r}=lm(n);return Number.isFinite(e)?n<=0?Math.max(s,Math.round(e)):Math.min(r,Math.max(s,Math.round(e))):s}function SJ(e,n){if(n<=0)return e;for(const s of bJ){const r=Math.round(n*s);if(Math.abs(e-r)<=wJ)return r}return e}function CJ(e,n){return om(SJ(e,n),n)}function EJ(e,n,s){const{min:r,max:a}=lm(s);switch(n){case"ArrowLeft":return om(e-E1,s);case"ArrowRight":return om(e+E1,s);case"Home":return r;case"End":return s>0?a:null;default:return null}}function AJ(){try{const e=window.localStorage.getItem(qv);if(e===null)return null;const n=Number(e);return Number.isFinite(n)&&n>=Xa?Math.round(n):null}catch{return null}}function $J(e){try{e===null?window.localStorage.removeItem(qv):window.localStorage.setItem(qv,String(Math.round(e)))}catch{}}const Yv="--wb-chat-w";function TJ({columnRef:e,width:n,onChange:s,label:r="Resize the conversation column"}){const a=d.useRef(null),i=d.useRef(null),[l,o]=d.useState(!1),[c,u]=d.useState({now:n??Xa,max:Xa}),h=()=>{var N;const g=e.current,w=(N=a.current)==null?void 0:N.nextElementSibling,v=(g==null?void 0:g.getBoundingClientRect().width)||(g==null?void 0:g.offsetWidth)||n||Xa,j=g==null?void 0:g.parentElement,y=j?j.scrollWidth-j.clientWidth:0;return{shared:kJ((g==null?void 0:g.getBoundingClientRect().width)??0,(w==null?void 0:w.getBoundingClientRect().width)??0,y),current:v,left:(g==null?void 0:g.getBoundingClientRect().left)??0}},m=g=>{const{shared:w,current:v}=h();u({now:Math.round(g??v),max:lm(w).max})};d.useEffect(()=>{m(n??void 0)},[n]);const f=g=>{const w=e.current;w&&(g===null?(w.style.removeProperty(Yv),delete w.dataset.sized):(w.style.setProperty(Yv,`${g}px`),w.dataset.sized="true"))},p=g=>{f(g),$J(g),s(g)},x=()=>{const g=i.current;g&&(g.frame!==null&&cancelAnimationFrame(g.frame),i.current=null,o(!1),document.documentElement.removeAttribute("data-resizing"),g.next!==null&&p(g.next))};return d.useEffect(()=>{var j;if(n===null)return;const g=(j=e.current)==null?void 0:j.parentElement;if(!g)return;const w=()=>{if(i.current)return;const{shared:y}=h();if(y<=0)return;const k=NJ(n,y);f(k),u({now:k,max:lm(y).max})};w();const v=typeof ResizeObserver>"u"?null:new ResizeObserver(w);return v==null||v.observe(g),window.addEventListener("resize",w),()=>{v==null||v.disconnect(),window.removeEventListener("resize",w)}},[n]),d.useEffect(()=>()=>{var g;((g=i.current)==null?void 0:g.frame)!=null&&cancelAnimationFrame(i.current.frame),document.documentElement.removeAttribute("data-resizing")},[]),t.jsx("div",{ref:a,className:"wb-grip",role:"separator",tabIndex:0,"aria-orientation":"vertical","aria-label":r,"aria-valuemin":Xa,"aria-valuemax":Math.max(Xa,c.max),"aria-valuenow":c.now,title:"Drag to resize · double-click to reset","data-dragging":l?"true":void 0,onPointerDown:g=>{var j,y;if(g.pointerType==="mouse"&&g.button!==0)return;g.preventDefault(),(y=(j=g.currentTarget).setPointerCapture)==null||y.call(j,g.pointerId);const{shared:w,left:v}=h();i.current={pointerId:g.pointerId,left:v,shared:w,next:null,frame:null},o(!0),document.documentElement.setAttribute("data-resizing","true")},onPointerMove:g=>{const w=i.current;!w||w.pointerId!==g.pointerId||(w.next=CJ(g.clientX-w.left,w.shared),w.frame===null&&(w.frame=requestAnimationFrame(()=>{const v=i.current;v&&(v.frame=null,v.next!==null&&f(v.next))})))},onPointerUp:x,onPointerCancel:x,onLostPointerCapture:x,onDoubleClick:()=>{p(null),m()},onKeyDown:g=>{const{shared:w,current:v}=h(),j=EJ(n??v,g.key,w);j!==null&&(g.preventDefault(),p(j))}})}const RJ=3.5*6e4,IJ=2e3;function PJ(e,n,s={}){const[r,a]=d.useState({served:new Set,live:new Set,scope:n}),i=d.useRef(r.served);if(r.scope!==n){const u={served:new Set,live:new Set,scope:n};i.current=u.served,a(u)}const l=s.check??T.previewCheck,o=s.everyMs??IJ,c=e.map(u=>`${wo(u)}@${u.at??""}`).join("|");return d.useEffect(()=>{const u=new Map;for(const p of e){const x=wo(p);if(i.current.has(x))continue;const g=p.at===null?Number.NaN:Date.parse(p.at),w=Number.isNaN(g)?0:g+RJ,v=u.get(x);(!v||w>v.until)&&u.set(x,{plugin:p.plugin,name:p.name,until:w})}if(u.size===0)return;let h=!1,m;const f=async()=>{const p=Date.now();for(const[x,g]of[...u]){const w=await l(g.plugin,g.name).catch(()=>null);if(h)return;const v=p<=g.until;w!=null&&w.ok?(u.delete(x),a(j=>{const y={served:new Set(j.served).add(x),live:v?new Set(j.live).add(x):j.live,scope:j.scope};return i.current=y.served,y})):v||u.delete(x)}!h&&u.size>0&&(m=setTimeout(()=>void f(),o))};return f(),()=>{h=!0,m!==void 0&&clearTimeout(m)}},[c,n,l,o]),r}const Qv="workspace-files";function MJ(e){let n=0;for(const s of e)for(const r of s.blocks??[]){if(r.type!=="tool_result"||r.ok===!1)continue;const a=r.output;if(a===null||typeof a!="object"||Array.isArray(a))continue;const{diff:i,path:l}=a;typeof i=="string"&&i.trim()!==""&&typeof l=="string"&&l!==""&&(n+=1)}return n}function OJ(e){const[n,s]=d.useState(null);return d.useEffect(()=>{if(s(null),!e)return;let r=!1;return(async()=>{var i;const a=await T.pages();for(const l of Array.isArray(a==null?void 0:a.files)?a.files:[]){const o=await T.pageQuery(l.plugin,l.workspace,{agent:e}).catch(()=>null),c=(i=o==null?void 0:o.data)==null?void 0:i.workspace;if(c&&typeof c.name=="string")return{files:l,agentId:e,root:c.name}}return null})().then(a=>{r||s(a)}).catch(()=>{}),()=>{r=!0}},[e]),n&&n.agentId===e?n:null}function DJ(e,n){return{id:Qv,tool:"",title:"Files",renderer:"files",props:{files:e.files,agentId:e.agentId,root:e.root,revision:n},at:null,source:"files",pinned:!0,substantial:!1}}function Jv(e){return`agent-properties:${e}`}function LJ(e){return{id:Jv(e.id),tool:`@${e.handle}`,title:"Properties",renderer:"profile",props:{profile:e},at:null,source:"profile",substantial:!1}}function FJ({agentId:e,conversationId:n}){const{data:s,error:r,reload:a}=je(()=>T.host(e,n),[e,n],2e3),[i,l]=d.useState(null),[o,c]=d.useState(!1),u=async p=>{c(!0),l(null);try{await p(),a()}catch(x){l(x instanceof Error?x.message:String(x))}finally{c(!1)}},h=(s==null?void 0:s.permissions)??[],m=(s==null?void 0:s.runs)??[],f=h.some(p=>!p.conversationId)?"Always allowed":h.length?"Conversation auto-mode":"Ask each time";return t.jsx(Vt,{className:"host-controls",summary:`Host execution · ${r?"Status unavailable":f}${m.length?` · ${m.length} running`:""}`,children:t.jsxs(ue,{gap:"sm",children:[t.jsx("p",{className:"muted",children:"Commands run as your user, not in a sandbox. Auto-mode covers all commands within its scope. Stop interrupts a command; revoke also ends the permission. Neither undoes completed changes."}),t.jsx(re,{message:i??r}),h.map(p=>t.jsxs(te,{children:[t.jsxs("span",{children:[p.agentId,": ",p.conversationId?"conversation auto-mode":"always allowed"]}),t.jsx($,{size:"sm",disabled:o,onClick:()=>void u(()=>T.revokeHost(p.id)),children:"Revoke permission"})]},p.id)),h.length?null:t.jsx("p",{className:"muted",children:"The next command will ask for approval. Choose its permission scope there."}),m.map(p=>t.jsxs(ue,{gap:"sm",children:[t.jsxs("p",{children:[p.agentId," · ",t.jsx("span",{className:"mono",children:p.cwd})]}),t.jsx(Zt,{children:p.command}),t.jsx(Zt,{label:"Command output",children:p.stdout||p.stderr?`${p.stdout}
126
- ${p.stderr}`:"Waiting for output…"}),t.jsx(te,{children:t.jsx($,{size:"sm",variant:"danger",disabled:o,onClick:()=>void u(()=>T.stopHost(p.agentId,p.conversationId)),children:"Stop command"})})]},p.actionId))]})})}const _J="browser.act",zJ="browser.status",sf=new Set([_J,zJ]);function UJ(e,n,s){const r=e==null?void 0:e.session;return!r||!n||!s||r.agentId!==n||r.conversationId!==s?null:{id:`host-browser:${r.id}`,title:"Page",tool:"Page",renderer:"browser",source:"browser",pinned:!0,props:{},at:null,substantial:!1}}function BJ(e,n){return{...e,title:"Page",pinned:!1}}function WJ(e,n,s){return!(e!=null&&e.stop)||!n||!s?null:{id:`host-browser:paused:${n}`,title:"Page",tool:"Page",renderer:"browser",source:"browser",pinned:!0,props:{},at:null,substantial:!1}}function A1(e,n){var r;let s=!1;for(const a of e)for(const i of a.blocks??[])if(i.type==="tool_use"&&i.id===n&&(s=sf.has(i.name)),i.type==="tool_result"&&i.toolUseId===n&&((r=i.approval)==null?void 0:r.state)==="pending")return null;return s?n:null}const ax="Save a login for next time",HJ=new Set(["Skip this site","Skip it","Keep paused","Leave it stopped"]),KJ=["Use my Chrome","Use Chrome when it’s open","Open Chrome and I'll use it there"];function Xv(e){if(!e||e.allowOther)return null;const n=new Set(e.options.map(h=>h.label)),s=(...h)=>h.some(m=>n.has(m)),r=s("Look")&&s("Carry on")?"look":s("Keep going")&&s("Stop here")?"budget":s("Resume")&&s("Keep paused","Leave it stopped")?"paused":s("Take over")&&s("Skip this site","Skip it")?"human":s("Take over")&&(s(ax,...KJ)||/sign-in|asks for a code/i.test(e.question))?"signin":null;if(!r)return null;const[a,...i]=e.question.split(`
127
- `),l=(a??"").trim().replace(/\.$/,""),o=e.options.find(h=>h.label===ax)??null,c=e.options.filter(h=>h.label!==ax),u=[...c.filter(h=>!h.recommended),...c.filter(h=>h.recommended)];return{kind:r,title:l,line:i.join(" ").trim(),saveLogin:o,actions:u}}function S2({card:e,disabled:n,onAnswer:s,site:r,signIn:a}){const[i,l]=d.useState(!1);if(i&&a)return t.jsx(xk,{question:a.question,card:a.card,phone:a.phone,container:a.container,disabled:n,onSettled:a.onSettled});const o=`${lv}${r?`&site=${encodeURIComponent(r)}`:""}`;return t.jsxs("section",{className:"wb-question br-ask","data-kind":e.kind,"aria-label":e.kind==="paused"?"Browsing is paused":"The agent needs you","data-testid":"browser-ask",children:[t.jsxs("div",{className:"br-ask-head",children:[t.jsx("span",{className:"wb-question-kicker",children:e.kind==="paused"?"Paused":"Needs you"}),t.jsx("strong",{children:e.title}),e.line?t.jsx("span",{className:"br-ask-line",children:e.line}):null]}),t.jsx("div",{className:"wb-dock-section",children:t.jsxs(te,{align:"end",children:[e.saveLogin?t.jsxs(t.Fragment,{children:[a?t.jsx("button",{type:"button",className:"wb-link","aria-expanded":!1,onClick:()=>l(!0),children:e.saveLogin.label}):t.jsx("a",{className:"wb-link",href:o,children:e.saveLogin.label}),t.jsx(ht,{})]}):null,e.actions.map(c=>t.jsx($,{size:"sm",variant:c.recommended?"accent":HJ.has(c.label)?"ghost":void 0,disabled:n,title:c.hint??void 0,onClick:()=>s(c.label,c.id),children:c.label},c.id))]})})]})}const VJ="web.read",GJ="web.search",qJ=new Set([VJ,GJ]),$1=new Set(["owner.get_profile","memory.recall","memory.get_preferences","memory.people","memory.person","platform.list_agents","platform.read_agent","platform.installed_tools","platform.list_skills","platform.list_accounts","platform.list_groups","system.time"]),T1=new Map([["owner.get_profile","Your profile"],["owner.set_profile","Your profile, updated"],["owner.rename_me","A new name"],["owner.finish_onboarding","First run finished"],["memory.recall","From memory"],["memory.note","Noted"],["memory.get_preferences","Your preferences"],["memory.remember_preference","A preference, kept"],["memory.people","People you know"],["memory.person","Someone you know"],["platform.list_agents","Your team"],["platform.read_agent","An agent, in detail"],["platform.installed_tools","Installed tools"],["platform.list_skills","Skills"],["platform.list_accounts","Accounts"],["platform.list_groups","Groups"],["platform.catalogue","Agents you can add"],["system.time","The time"],["system.info","This Mac"],["reminder.list","Reminders"],["schedule.list_mine","Scheduled runs"],["goal.list","Goals"],["goal.status","How a goal is going"]]);function YJ({agentId:e,groupId:n,currentId:s,timezone:r,onSelect:a,onNew:i}){const[l,o]=d.useState(null),[c,u]=d.useState(null),[h,m]=d.useState(0);return d.useEffect(()=>{let f=!1;return o(null),u(null),(n?nt.groupConversations(n):nt.conversations(e,100)).then(p=>{f||o(p.conversations)}).catch(p=>{f||u(p instanceof Error?p.message:String(p))}),()=>{f=!0}},[e,n,h]),t.jsxs("section",{className:"wb-history","aria-label":"Past conversations",children:[t.jsxs("div",{className:"ui-toolbar",children:[t.jsx("strong",{children:"Past conversations"}),t.jsx("button",{className:"ui-btn",onClick:i,children:"New conversation"})]}),c?t.jsxs("p",{role:"alert",children:[c," ",t.jsx("button",{className:"ui-btn",onClick:()=>m(f=>f+1),children:"Retry"})]}):l===null?t.jsx("p",{className:"muted",children:"Loading conversations…"}):l.length===0?t.jsx("p",{className:"muted",children:"No conversations yet."}):t.jsx("ul",{children:l.map(f=>t.jsx("li",{children:t.jsxs("a",{href:n?Hi(n,f.id):ut(e,f.id),"aria-current":f.id===s?"page":void 0,onClick:p=>{p.button===0&&!p.metaKey&&!p.ctrlKey&&!p.shiftKey&&!p.altKey&&(p.preventDefault(),a(f.id))},children:[t.jsx("span",{children:f.preview||f.opening||"Untitled conversation"}),t.jsxs("small",{children:[St(f.lastMessageAt??f.startedAt??f.createdAt??null,r)," · ",f.messageCount," messages",f.id===s?" · Current":""]})]})},f.id))}),t.jsx("a",{href:"#/conversations",children:"View all agents’ conversation records ↗"}),(l==null?void 0:l.length)===100?t.jsx("p",{className:"muted",children:"Showing the 100 most recent conversations."}):null]})}const QJ=600,Bl={closed:[],touched:{}},R1=/^[\w:./-]{1,200}$/;function JJ(e){return{closed:e.closed.filter(n=>R1.test(n)).slice(-200),touched:Object.fromEntries(Object.entries(e.touched).filter(([n])=>R1.test(n)).sort((n,s)=>n[1]-s[1]).slice(-200))}}function XJ(e,n=Date.now){const[s,r]=d.useState({id:null,value:Bl}),a=d.useRef(null),i=d.useRef(null),l=d.useRef([]),o=d.useRef(null),c=d.useCallback(()=>{a.current&&clearTimeout(a.current),a.current=null;const g=i.current;i.current=null,g&&nt.saveCanvasTabs(g.id,g.value).catch(()=>{})},[]);d.useEffect(()=>{if(c(),l.current=[],o.current=null,r({id:e,value:Bl}),!e)return;let g=!0;return Promise.resolve().then(()=>nt.canvasTabs(e)).catch(()=>Bl).then(w=>{if(!g)return;const v=w&&Array.isArray(w.closed)&&w.touched&&typeof w.touched=="object"?w:Bl,j=l.current.reduce((k,N)=>N(k),v),y=l.current.length>0;l.current=[],o.current=e,r({id:e,value:j,ready:!0}),y&&(i.current={id:e,value:j},c())}),()=>{g=!1}},[e,c]),d.useEffect(()=>()=>c(),[c]);const u=d.useCallback(g=>{e&&(o.current!==e&&l.current.push(g),r(w=>{const v=JJ(g(w.id===e?w.value:Bl));return o.current===e&&(i.current={id:e,value:v},a.current&&clearTimeout(a.current),a.current=setTimeout(c,QJ)),{id:e,value:v,ready:w.id===e&&w.ready===!0}}))},[e,c]),h=d.useCallback(g=>u(w=>({...w,closed:[...w.closed.filter(v=>!g.includes(v)),...g]})),[u]),m=d.useCallback(g=>u(w=>w.closed.some(v=>g.includes(v))?{...w,closed:w.closed.filter(v=>!g.includes(v))}:w),[u]),f=d.useCallback(g=>u(w=>({...w,touched:{...w.touched,[g]:n()}})),[u,n]),p=s.id===e?s.value:Bl;return{ready:e===null||s.id===e&&s.ready===!0,closed:p.closed,touched:p.touched,close:h,reopen:m,touch:f}}const I1=3;function ZJ(e){return e.frontDesk?"the front desk":`@${e.handle}`}function P1(e){const n=e.slice(0,I1).map(ZJ);return e.length>I1?`${n.join(", ")}, …`:n.join(", ")}function eX(e){const n=e.asks==="everyone"?"may ask everyone":e.asks.length===0?"asks nobody yet":`may ask ${P1(e.asks)}`,s=e.askedBy.length===0?"and nobody asks it yet":`and can be asked by ${P1(e.askedBy)}`;return`New here. @${e.handle} ${n}, ${s}.`}function tX({agentId:e}){const n=je(()=>T.agentIntro(e),[e]),[s,r]=d.useState(!1),a=n.data;if(s||!a||!a.show)return null;const i=()=>{r(!0),T.dismissAgentIntro(e).catch(()=>{})};return t.jsxs("div",{className:"wb-new-agent",role:"status","data-testid":"new-agent-strip",children:[t.jsx("p",{className:"wb-new-agent-text",children:eX(a)}),t.jsx(it,{variant:"ghost",size:"sm",href:Qt(e,"setup","team"),onClick:i,children:"Adjust"}),t.jsx($,{variant:"ghost",size:"sm",className:"ui-icon-btn","aria-label":"Close",title:"Close",onClick:i,children:t.jsx(ne,{name:"close",size:14})})]})}const Zv="​",ix=/(`[^`\n]+`)|(\*\*[^*\n]+\*\*)|(\*[^*\s][^*\n]*\*|_[^_\s][^_\n]*_)|(\[[^\]\n]+\]\([^)\s]+\))|(https?:\/\/[^\s)]+)|(@[a-z][a-z0-9-]*)/gi;function lx(e,n,s){const r=[];let a=0,i=0;ix.lastIndex=0;for(let l=ix.exec(e);l;l=ix.exec(e)){l.index>a&&r.push(e.slice(a,l.index));const o=l[0],c=`${s}-${i++}`;if(l[1])r.push(t.jsxs("span",{className:"cv-code",children:[t.jsx("span",{className:"cv-mark",children:"`"}),o.slice(1,-1),t.jsx("span",{className:"cv-mark",children:"`"})]},c));else if(l[2])r.push(t.jsxs("span",{className:"cv-b",children:[t.jsx("span",{className:"cv-mark",children:"**"}),o.slice(2,-2),t.jsx("span",{className:"cv-mark",children:"**"})]},c));else if(l[3])r.push(t.jsxs("span",{className:"cv-i",children:[t.jsx("span",{className:"cv-mark",children:o[0]}),o.slice(1,-1),t.jsx("span",{className:"cv-mark",children:o[0]})]},c));else if(l[4]){const u=o.indexOf("](");r.push(t.jsxs("span",{className:"cv-link-md",children:[t.jsx("span",{className:"cv-mark",children:"["}),t.jsx("span",{className:"cv-link",children:o.slice(1,u)}),t.jsx("span",{className:"cv-mark",children:o.slice(u)})]},c))}else if(l[5])r.push(t.jsx("span",{className:"cv-link",children:o},c));else{const u=l.index>0?e[l.index-1]:" ",h=/[\s(]/.test(u)?n.find(m=>m.handle.toLowerCase()===o.slice(1).toLowerCase()):void 0;r.push(h?t.jsx("span",{className:"cv-chip",...h.accent,children:o},c):o)}a=l.index+o.length}return a<e.length&&r.push(e.slice(a)),r}function nX(e,n){const s=e.split(`
128
- `);let r=null;return s.map((a,i)=>{const l=/^```(\w*)\s*$/.exec(a);if(r===null&&l){r=l[1]??"";const u=s.slice(i+1).some(h=>/^```\s*$/.test(h));return t.jsxs("div",{className:"cv-line","data-code":"open","data-unclosed":u?void 0:"true",children:[t.jsx("span",{className:"cv-mark",children:a}),r?t.jsx("span",{className:"cv-lang","aria-hidden":"true","data-paint-extra":"",children:wR(r)}):null]},i)}if(r!==null)return/^```\s*$/.test(a)?(r=null,t.jsx("div",{className:"cv-line","data-code":"close",children:t.jsx("span",{className:"cv-mark",children:a})},i)):t.jsx("div",{className:"cv-line","data-code":"body",children:t.jsx("span",{className:"cv-code-ink",children:a||Zv})},i);const o=/^(#{1,3} )(.*)$/.exec(a);if(o)return t.jsxs("div",{className:"cv-line","data-h":o[1].length-1,children:[t.jsx("span",{className:"cv-mark",children:o[1]}),t.jsx("span",{className:"cv-h",children:lx(o[2],n,String(i))})]},i);const c=/^(\s*)([-*]|\d+\.)( )(.*)$/.exec(a);return c?t.jsxs("div",{className:"cv-line",children:[c[1],t.jsx("span",{className:"cv-bullet",children:c[2]}),c[3],lx(c[4],n,String(i))]},i):t.jsx("div",{className:"cv-line",children:a?lx(a,n,String(i)):Zv},i)})}const vk=(e,n)=>`${e}-opt-${n}`;function sX({id:e,items:n,active:s,onPick:r,phone:a,maxHeight:i}){let l=null;return t.jsxs("div",{className:"cv-pop","data-testid":"mention-popup",children:[t.jsx("div",{className:"cv-pop-list",id:e,role:"listbox","aria-label":"Mention someone",style:i?{maxHeight:i}:void 0,children:n.map((o,c)=>{const u=o.group!==l?l=o.group:null;return t.jsxs(d.Fragment,{children:[u?t.jsx("div",{className:"cv-pop-group",role:"presentation",children:u}):null,t.jsxs("div",{id:vk(e,c),role:"option","aria-selected":c===s,"aria-label":`${o.name}, @${o.handle}. ${o.effect}`,className:"cv-pop-row","data-mention":"true","data-active":c===s||void 0,onMouseDown:h=>{h.preventDefault(),r(o)},children:[t.jsx(Bn,{id:o.id,name:o.name,size:"sm",...o.face?{face:o.face}:{}}),t.jsxs("span",{className:"cv-pop-title",children:[o.name," ",t.jsxs("span",{className:"cv-pop-handle",children:["@",o.handle]})]}),c===s?t.jsx("span",{className:"cv-pop-effect",children:o.effect}):null,c===s&&!a?t.jsx("kbd",{className:"cv-kbd",children:"↵"}):null]})]},o.id)})}),a?null:t.jsxs("div",{className:"cv-pop-foot","aria-hidden":"true",children:[t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"↑"}),t.jsx("kbd",{className:"cv-kbd",children:"↓"})," choose"]}),t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"↵"})," or ",t.jsx("kbd",{className:"cv-kbd",children:"Tab"})," mention"]}),t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"Esc"})," close"]})]})]})}function rX({id:e,items:n,active:s,onPick:r,phone:a,query:i,maxHeight:l}){if(n.length===0)return t.jsx("div",{className:"cv-pop","data-testid":"command-menu",children:t.jsx("div",{className:"cv-pop-list",id:e,role:"listbox","aria-label":"Commands",children:t.jsxs("div",{className:"cv-pop-empty",role:"status",children:["No command called ",t.jsxs("span",{className:"mono",children:["/",i]}),". ",a?"Send sends it as text.":"Enter sends it as text."]})})});let o=null;return t.jsxs("div",{className:"cv-pop","data-testid":"command-menu",children:[t.jsx("div",{className:"cv-pop-list",id:e,role:"listbox","aria-label":"Commands",style:l?{maxHeight:l}:void 0,children:n.map((c,u)=>{const h=c.group!==o?o=c.group:null;return t.jsxs(d.Fragment,{children:[h?t.jsx("div",{className:"cv-pop-group",role:"presentation",children:h}):null,t.jsxs("div",{id:vk(e,u),role:"option","aria-selected":u===s,"aria-disabled":c.off||void 0,"aria-label":`/${c.name}${c.args?` ${c.args}`:""}: ${c.desc}`,className:"cv-pop-row","data-cmd":"true","data-active":u===s||void 0,"data-off":c.off||void 0,onMouseDown:m=>{m.preventDefault(),c.off||r(c)},children:[t.jsxs("span",{className:"cv-pop-cmd",children:["/",c.name,c.args?t.jsxs("span",{className:"cv-pop-args",children:[" ",c.args]}):null]}),t.jsx("span",{className:"cv-pop-desc",children:c.desc}),a?null:c.key?t.jsx("kbd",{className:"cv-kbd",children:c.key}):u===s?t.jsx("kbd",{className:"cv-kbd",children:"↵"}):null]})]},`${c.group}/${c.name}`)})}),a?null:t.jsxs("div",{className:"cv-pop-foot","aria-hidden":"true",children:[t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"↑"}),t.jsx("kbd",{className:"cv-kbd",children:"↓"})," choose"]}),t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"↵"})," run"]}),t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"Tab"})," add words"]}),t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"Esc"})," close"]})]})]})}const aX=350,iX=60;function lX({conversationId:e,onText:n,onNotice:s}){const[r,a]=d.useState("idle"),i=d.useRef("idle"),l=j=>{i.current=j,a(j)},o=d.useRef(null),c=d.useRef(null),u=d.useRef(null),h=d.useRef(null),m=d.useRef(null),f=d.useRef({onText:n,onNotice:s,conversationId:e});f.current={onText:n,onNotice:s,conversationId:e};const p=()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null)},x=async()=>{if(i.current!=="idle")return;f.current.onNotice(null),l("starting"),c.current=null;let j;try{j=await DW(N=>{var b;return(b=m.current)==null?void 0:b.call(m,N)})}catch(N){h.current=null,l("idle"),f.current.onNotice(OW(N));return}const y=c.current;c.current=null;const k=i.current;if(y==="discard"||k!=="starting"){j.cancel(),k==="starting"&&l("idle");return}o.current=j,l("recording"),u.current=window.setTimeout(()=>void g(!1),IW),y&&g(y.sendNow)},g=async j=>{h.current=null;const y=o.current;if(!y){i.current==="starting"&&(c.current={sendNow:j});return}o.current=null,p(),l("transcribing");try{const k=await y.stop();if(k.size<=44){f.current.onNotice("Nothing was recorded.");return}const N=new File([k],`recording-${new Date().toISOString().slice(0,19).replace(/[:T]/g,"-")}.wav`,{type:"audio/wav"}),b=await nt.attach(N),S=f.current.conversationId,C=await nt.transcribe({artifactId:b.artifactId,...S?{conversationId:S}:{}});f.current.onText(C.text,j)}catch(k){f.current.onNotice(k instanceof pe||k instanceof Error?k.message:String(k))}finally{l("idle")}},w=()=>{h.current=null;const j=o.current;if(!j){i.current==="starting"&&(c.current="discard");return}o.current=null,p(),j.cancel(),l("idle")};d.useEffect(()=>{const j=y=>{if(h.current===null)return;const k=Date.now()-h.current;h.current=null,k>=aX&&g(y.shiftKey)};return window.addEventListener("pointerup",j),()=>window.removeEventListener("pointerup",j)},[]);const v=r==="starting"||r==="recording";return d.useEffect(()=>{if(!v)return;const j=y=>{y.isComposing||y.repeat||(y.key==="Escape"?(y.preventDefault(),y.stopPropagation(),w()):y.key==="Enter"&&(y.preventDefault(),y.stopPropagation(),g(y.shiftKey)))};return window.addEventListener("keydown",j,!0),()=>window.removeEventListener("keydown",j,!0)},[v]),d.useEffect(()=>()=>{var j;(j=o.current)==null||j.cancel(),p()},[]),{state:r,hold:()=>{h.current=Date.now(),x()},start:()=>{h.current=null,x()},finish:j=>void g(j),discard:w,levels:m}}function oX({disabled:e,voice:n}){const s=a=>{e||a.button>0||n.state!=="idle"||(a.preventDefault(),n.hold())},r=a=>{a.detail!==0||e||n.state!=="idle"||n.start()};return t.jsx("button",{type:"button",className:"ui-icon-btn wb-mic","data-size":"sm","aria-label":"Talk",title:"Talk: click to start, or hold to speak and let go to stop",disabled:e,onPointerDown:s,onClick:r,onContextMenu:a=>a.preventDefault(),children:t.jsx(ne,{name:"mic"})})}function cX({voice:e}){const n=d.useRef(null),s=e.state==="transcribing";return d.useEffect(()=>{var r;(r=n.current)==null||r.focus()},[]),t.jsxs("div",{className:"wb-listening",role:"group","aria-label":"Recording","data-phase":s?"transcribing":"listening",children:[t.jsx("p",{className:"wb-listening-label","aria-live":"polite",children:s?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"wb-listening-spinner","aria-hidden":"true"}),"Transcribing…"]}):"Listening…"}),t.jsxs("div",{className:"wb-listening-row",children:[t.jsx(uX,{sink:e.levels,frozen:s}),t.jsx("button",{type:"button",className:"wb-send","data-variant":"quiet","aria-label":"Discard recording",title:"Discard (Escape)",disabled:s,onClick:()=>e.discard(),children:t.jsx(ne,{name:"close"})}),t.jsx("button",{ref:n,type:"button",className:"wb-send","aria-label":"Stop and transcribe",title:"Stop and transcribe (Enter); Shift sends at once",disabled:s,onClick:r=>e.finish(r.shiftKey),children:t.jsx(ne,{name:"check"})})]})]})}function uX({sink:e,frozen:n}){const[s,r]=d.useState(()=>Array(iX).fill(0));return d.useEffect(()=>{if(!n)return e.current=a=>r(i=>[...i.slice(1),a]),()=>{e.current=null}},[n]),t.jsx("div",{className:"wb-wave","aria-hidden":"true","data-testid":"waveform",children:s.map((a,i)=>t.jsx("span",{className:"wb-wave-bar",style:{"--level":a.toFixed(3)}},i))})}const dX="This browser cannot capture a tab. Chrome, Safari and Firefox can, on a secure address.",wh="The tab could not be captured. Try again, and pick the tab itself rather than the whole screen.",hX=e=>e instanceof Error&&(e.name==="NotAllowedError"||e.name==="AbortError");async function fX(e={}){var r;const n=e.media??(typeof navigator>"u"?void 0:navigator.mediaDevices);if(!n||typeof n.getDisplayMedia!="function")throw new Error(dX);let s;try{s=await n.getDisplayMedia({video:{displaySurface:"browser"},audio:!1,selfBrowserSurface:"exclude",surfaceSwitching:"exclude",preferCurrentTab:!1})}catch(a){if(hX(a))return null;throw new Error(wh)}try{const a=e.document??document,i=a.createElement("video");i.muted=!0,i.playsInline=!0,i.srcObject=s,await new Promise((h,m)=>{i.onloadedmetadata=()=>h(),i.onerror=()=>m(new Error(wh))}),await i.play(),await new Promise(h=>{const m=i.requestVideoFrameCallback;typeof m=="function"?m.call(i,()=>h()):setTimeout(h,120)});const l=a.createElement("canvas");l.width=i.videoWidth,l.height=i.videoHeight;const o=l.getContext("2d");if(!o||l.width===0)throw new Error(wh);o.drawImage(i,0,0);const c=await new Promise(h=>l.toBlob(h,"image/png"));if(!c)throw new Error(wh);const u=(((r=e.now)==null?void 0:r.call(e))??new Date).toISOString().slice(0,19).replace("T"," ").replace(/:/g,".");return new File([c],`Tab ${u}.png`,{type:"image/png"})}finally{s.getTracks().forEach(a=>a.stop())}}function mX(e,n){return`${e} picks up ${n===1?"the file":"the files"} between steps, or right after this answer.`}const ey="wb-composer-input",pX="(max-width: 720px)",M1={desk:288,phone:240};function gX(e,n,s){const[r,a]=d.useState(void 0);return d.useEffect(()=>{if(!n)return;const i=window.visualViewport??null,l=()=>{const o=e.current;if(!o||typeof o.getBoundingClientRect!="function")return;const c=o.getBoundingClientRect().top-(i?i.offsetTop:0),u=Math.floor(c-(s?16:64)),h=s?M1.phone:M1.desk;a(u>0&&u<h?Math.max(u,96):void 0)};return l(),i==null||i.addEventListener("resize",l),i==null||i.addEventListener("scroll",l),window.addEventListener("resize",l),()=>{i==null||i.removeEventListener("resize",l),i==null||i.removeEventListener("scroll",l),window.removeEventListener("resize",l)}},[n,s,e]),r}const yk=d.forwardRef(function({disabled:n,running:s,onSend:r,onStop:a,agentName:i,draft:l,model:o,chrome:c,setupHref:u,thinking:h,onThinking:m,onOpenFile:f,mentions:p,team:x,onCommand:g,history:w,threadKey:v,conversationId:j,readAloud:y,onReadAloud:k,placeholder:N,slim:b},S){var Sd,Cd,Ed;const C=v?`buddi.draft.${v}`:null,A=q=>{if(!q)return"";try{return window.localStorage.getItem(q)??""}catch{return""}},[E,R]=d.useState(()=>A(C)),[P,O]=d.useState(()=>E.length),[I,F]=d.useState([]),[U,L]=d.useState(!1),[M,z]=d.useState(null),[D,K]=d.useState(!1),[B,se]=d.useState(null),W=d.useRef(null),xe=d.useRef(null),me=d.useRef(null),ie=ts(pX),H=`cv-pop-${d.useId().replace(/[^a-zA-Z0-9_-]/g,"")}`,de=x4(),ge=d.useMemo(()=>{const q=Je=>x==null?void 0:x.agents.find(At=>At.id===Je),We=(Je,At)=>fl(sc(Je??{id:At}));if(p)return p.map(Je=>{const At=Je.id??Je.handle,Hn=q(At);return{id:At,handle:Je.handle,name:Je.name,effect:`Asks @${Je.handle} in this room`,group:"In this room",accent:We(Hn,At),...Hn?{face:Hn}:{}}});if(!x)return[];const et=x.agents.find(Je=>Je.roles.includes(Pr)&&Je.id!==x.selfId),dn=x.agents.filter(Je=>Je.id!==x.selfId&&Je!==et);return[...et?[{id:et.id,handle:et.handle,name:et.name,effect:`Borrows ${et.name} for this message`,group:"Borrow",accent:fl({key:"buddi"}),face:et}]:[],...dn.map(Je=>({id:Je.id,handle:Je.handle,name:Je.name,effect:`${i} asks @${Je.handle}`,group:"Ask a teammate",accent:We(Je,Je.id),face:Je}))]},[p,x,i]),Ue=!p&&x?((Sd=x.agents.find(q=>q.roles.includes(Pr)&&q.id!==x.selfId))==null?void 0:Sd.handle)??null:null,[G,ae]=d.useState(!1),[J,Ne]=d.useState(0),Ie=!!g,Y=Ie&&CU(E,P),X=!G&&ge.length>0?NU(E,P):null,oe=!G&&Ie&&!X?SU(E,P):null,ve=X?ge.filter(q=>!Y||q.group!=="Borrow").filter(q=>q.handle.toLowerCase().startsWith(X.query.toLowerCase())||q.name.toLowerCase().startsWith(X.query.toLowerCase())).map(q=>Y?{...q,group:"Talk to",effect:`Talk to ${q.name} from here on`}:q).slice(0,8):[],be=d.useMemo(()=>[...h4(i,s),...m4(de)],[i,s,de]),Ce=oe?be.filter(q=>q.name.startsWith(oe.query.toLowerCase())):[],we=X&&ve.length>0?"mention":oe?"slash":null,He=we==="mention"?ve:we==="slash"?Ce:[],Ze=He.length>0?Math.min(J,He.length-1):-1,Se=gX(me,we!==null,ie),Le=w??[],[Ve,Qe]=d.useState(-1),wt=d.useRef(E),dt=d.useRef(C);if(dt.current!==C){dt.current=C;const q=A(C);wt.current=q,q!==E&&(R(q),O(q.length),Qe(-1),se(null))}const qt=q=>{if(wt.current=q,!!C)try{q===""?window.localStorage.removeItem(C):window.localStorage.setItem(C,q)}catch{}},vt=q=>{R(q.value),O(q.caret),ae(!1),Ne(0),Ve<0&&qt(q.value);const We=xe.current;We&&(We.value=q.value,We.setSelectionRange(q.caret,q.caret),window.requestAnimationFrame(()=>{We.focus(),We.setSelectionRange(q.caret,q.caret)}))},Dt=q=>{R(q),O(q.length),ae(!1);const We=xe.current;We&&(We.value=q,We.setSelectionRange(q.length,q.length))},bn=q=>!q.value.slice(0,q.selectionStart??q.value.length).includes(`
129
- `),sn=()=>E===""||Ve>=0&&E===Le[Ve],ce=()=>{Ve<0||(Qe(-1),Dt(wt.current))},Me=I.some(q=>q.state==="uploading"),tt=I.length>0,Tt=s&&tt,bt=I.some(q=>q.state==="ready"&&q.uploaded),Pe=!n&&!Me&&(E.trim()!==""||bt),st=q=>{const We=[];for(const et of Array.from(q??[])){const dn=`${et.name}:${et.size}:${Math.random().toString(36).slice(2,8)}`;We.push(dn);const Je=et.type.startsWith("image/")&&typeof URL.createObjectURL=="function"?URL.createObjectURL(et):null;F(At=>[...At,{key:dn,filename:et.name||"Pasted image",mime:et.type||"application/octet-stream",sizeBytes:et.size,thumbnail:Je,state:"uploading"}]),nt.attach(et).then(At=>F(Hn=>Hn.map(tr=>tr.key===dn?{...tr,state:"ready",uploaded:At}:tr))).catch(At=>F(Hn=>Hn.map(tr=>tr.key===dn?{...tr,state:"failed",error:At instanceof pe?At.message:String(At)}:tr)))}return We},_e=q=>{q.thumbnail&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(q.thumbnail)},en=q=>{const We=I.find(et=>et.key===q);We&&(_e(We),We.state==="ready"&&We.uploaded&&nt.discardAttachment(We.uploaded.artifactId).catch(()=>{})),F(et=>et.filter(dn=>dn.key!==q)),(B==null?void 0:B.kind)==="long"&&B.key===q&&se(null)};d.useImperativeHandle(S,()=>({addFiles:q=>{var We;st(q),(We=xe.current)==null||We.focus()},focus:()=>{var q;return(q=xe.current)==null?void 0:q.focus()},carryDraftTo:q=>{const We=`buddi.draft.${q}`;dt.current=We;try{E?window.localStorage.setItem(We,E):window.localStorage.removeItem(We),C&&C!==We&&window.localStorage.removeItem(C)}catch{}}}));const ee=d.useRef(I);ee.current=I,d.useEffect(()=>()=>ee.current.forEach(_e),[]);const rt=d.useRef(0);d.useEffect(()=>{if(!l||l.at===rt.current)return;rt.current=l.at;const q=E.trim()==="";R(et=>et.trim()===""?l.text:et),Ve<0&&q&&qt(l.text);const We=xe.current;We&&(We.focus(),window.requestAnimationFrame(()=>{We.setSelectionRange(We.value.length,We.value.length),O(We.value.length)}))},[l]);const On=()=>{Qe(-1),qt(""),R(""),O(0),se(null),ae(!1)},$n=(q,We)=>{if(g){if(q==="stop"&&!s){On();return}On(),g(q,We)}},Ae=q=>{const We=(q??E).trim();if(q===void 0?!Pe:n||Me||We==="")return;const et=q===void 0&&g?EU(We):null;if(et&&BN(et.name)&&I.length===0){if(et.name==="use"&&et.arg===""){vt({value:"/use @",caret:6});return}$n(et.name,et.arg.replace(/^@/,""));return}const dn=I.filter(Je=>Je.state==="ready"&&Je.uploaded).map(Je=>Je.uploaded);r(We,dn),I.forEach(_e),On(),F([])},De=q=>{if(X){if(Y&&g){$n("use",q.handle);return}vt(AU(E,P,X.start,q.handle))}},gt=(q,We)=>{if(q.off)return;const et=E.slice(P);if(We||p4(q)){const Je=`/${q.name} ${q.name==="use"?"@":""}`;vt({value:Je+et.replace(/^\S*/,"").replace(/^ /,""),caret:Je.length});return}if(q.source==="chat"&&BN(q.name)){$n(q.name,"");return}const dn=`/${q.name}`;if(n||Me){vt({value:`${dn} `,caret:dn.length+1});return}Ae(dn)},Mt=q=>{if(q.nativeEvent.isComposing)return;if(we&&He.length>0){if(q.key==="ArrowDown"){q.preventDefault(),Ne((Ze+1)%He.length);return}if(q.key==="ArrowUp"){q.preventDefault(),Ne((Ze-1+He.length)%He.length);return}if(q.key==="Enter"&&!q.shiftKey||q.key==="Tab"){q.preventDefault();const Je=He[Ze];we==="mention"?De(Je):gt(Je,q.key==="Tab");return}}if(we&&q.key==="Escape"){q.preventDefault(),ae(!0);return}if(q.key==="ArrowUp"&&!q.shiftKey&&!q.altKey&&!q.metaKey&&!q.ctrlKey){const Je=q.currentTarget;if(Le.length>0&&Ve+1<Le.length&&bn(Je)&&sn()){q.preventDefault(),Ve<0&&(wt.current=E),Qe(Ve+1),Dt(Le[Ve+1]);return}}if(q.key==="ArrowDown"&&!q.shiftKey&&!q.altKey&&!q.metaKey&&!q.ctrlKey&&Ve>=0&&E===Le[Ve]){if(q.preventDefault(),Ve===0){ce();return}Qe(Ve-1),Dt(Le[Ve-1]);return}if(q.key==="Escape"&&Ve>=0){q.preventDefault(),ce();return}if(q.key==="Escape"&&s&&g){q.preventDefault(),a();return}const We=q.currentTarget,et=We.selectionStart??P,dn=We.selectionStart===We.selectionEnd;if(q.key==="Tab"&&dn&&!q.altKey&&!q.metaKey&&!q.ctrlKey){const Je=RU(E,et,q.shiftKey);if(Je){q.preventDefault(),vt(Je);return}}if(q.key==="Enter"&&!q.shiftKey&&!q.metaKey&&!q.ctrlKey&&!q.altKey){const Je=dn?TU(E,et):null;if(Je){q.preventDefault(),vt(Je);return}if(Xc(E,et))return;q.preventDefault(),Ae();return}q.key==="Enter"&&(q.metaKey||q.ctrlKey)&&(q.preventDefault(),Ae())},Dn=q=>{var tr,Lp;const We=Array.from(((tr=q.clipboardData)==null?void 0:tr.files)??[]);if(We.length>0){q.preventDefault(),st(We);return}const et=typeof((Lp=q.clipboardData)==null?void 0:Lp.getData)=="function"?q.clipboardData.getData("text/plain"):"";if(et==="")return;const dn=q.currentTarget,Je=dn.selectionStart??P,At=dn.selectionEnd??Je,Hn=E.slice(0,Je)+E.slice(At);if(et.length>bU){q.preventDefault();const pa=new File([et],"pasted-text.txt",{type:"text/plain"}),[Wa]=st([pa]),ga=et.replace(/\n$/,"").split(`
130
- `).length,mc=`${ga} ${ga===1?"line":"lines"} · ${Math.ceil(et.length/1024)} KB`;F(Ad=>Ad.map(Il=>Il.key===Wa?{...Il,detail:mc}:Il)),Hn!==E&&vt({value:Hn,caret:Je}),se({kind:"long",key:Wa,text:et,caret:Je});return}if(IU(et)&&!Xc(Hn,Je)){q.preventDefault();const pa=PU(et),Wa=MU(Hn,Je,et,pa);se({kind:"fenced",lang:pa,block:Wa.value.slice(Je,Wa.caret),text:et}),vt(Wa)}},as=()=>{if(B){if(B.kind==="fenced"){const q=E.indexOf(B.block);q>=0&&vt({value:E.slice(0,q)+B.text+E.slice(q+B.block.length),caret:q+B.text.length})}else{en(B.key);const q=Math.min(B.caret,E.length);vt({value:E.slice(0,q)+B.text+E.slice(q),caret:q+B.text.length})}se(null)}},js=I.filter(q=>q.state==="failed"),Ps=js.length,Wn=lX({conversationId:j??null,onNotice:z,onText:(q,We)=>{const et=E.trim()===""?q:`${E.replace(/\s+$/,"")} ${q}`;if(We){Ae(et);return}Dt(et),Ve<0&&qt(et)}}),ft=Wn.state!=="idle",fe=d.useRef(!1);d.useEffect(()=>{var q;fe.current&&!ft&&((q=xe.current)==null||q.focus()),fe.current=ft},[ft]);const ct=we!==null&&!ft&&!n,Et=Yw(E,P),gn=Xc(E,P),is=OU(E).map(q=>ge.find(We=>We.handle.toLowerCase()===q)).filter(q=>!!q),Rl=Ue!==null&&((Cd=bR(E))==null?void 0:Cd.handle)===Ue.toLowerCase(),Ms=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform||navigator.userAgent),xr=q=>q.group==="Borrow"?Rl?`borrows ${q.name} for this message`:`${i} asks them`:q.group==="In this room"?"is asked in this room":`${i} asks them`,zt=Ps>0?Ps===1&&((Ed=js[0])!=null&&Ed.error)?js[0].error:`${Ps} files failed to upload and will not be sent`:M,Qn=zt??(s||ct?null:Et?"Enter continues the list · Enter on an empty item ends it · Tab indents":gn?`In a code block Enter adds a line · ${Ms?"⌘":"Ctrl+"}Enter sends`:is.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"cv-chip",...is[0].accent,children:["@",is[0].handle]})," ",xr(is[0]),is.length>1?` · and ${is.length-1} more`:""]}):E!==""?"Enter sends, Shift+Enter for a new line":null),jr=N??(s?`${i} is working…`:p?"Message the room · @ to ask someone":x&&Ie?`Message ${i} · @ to mention, / for commands`:`Message ${i}`),ma=d.useMemo(()=>ge.map(q=>({handle:q.handle,accent:q.accent})),[ge]),Ba=q=>O(q.selectionStart??q.value.length);return t.jsxs("div",{className:"wb-composer cv","data-testid":"composer","data-slim":b||void 0,"data-phone":ie?"true":void 0,"data-busy":E.trim()!==""||tt||ft?"true":void 0,children:[t.jsxs("div",{className:"cv-anchor",children:[ct&&we==="mention"?t.jsx(sX,{id:H,items:ve,active:Ze,onPick:De,phone:ie,maxHeight:Se}):null,ct&&we==="slash"?t.jsx(rX,{id:H,items:Ce,active:Ze,onPick:q=>gt(q,!1),phone:ie,query:(oe==null?void 0:oe.query)??"",maxHeight:Se}):null,t.jsxs("div",{ref:me,className:"wb-composer-box cv-box","data-focused":D||ft,"data-disabled":n,"data-listening":ft||void 0,children:[I.length>0?t.jsx("div",{className:"wb-composer-files",role:"list","aria-label":"Files to send",children:I.map(q=>t.jsx("span",{role:"listitem",children:t.jsx(bd,{name:q.filename,mime:q.mime,sizeBytes:q.sizeBytes,thumbnail:q.thumbnail,state:q.state,error:q.error,onRemove:()=>en(q.key),...f&&q.state==="ready"&&q.uploaded?{onOpen:()=>f(jX(q.uploaded))}:{},size:"sm",detail:q.detail})},q.key))}):null,t.jsxs("label",{className:"sr-only",htmlFor:ey,children:["Message ",i]}),t.jsxs("div",{className:"cv-field",hidden:ft,children:[t.jsxs("div",{className:"cv-paint","aria-hidden":"true","data-testid":"composer-paint",children:[nX(E,ma),t.jsx("span",{className:"cv-tail",children:Zv})]}),t.jsx("textarea",{id:ey,ref:xe,value:E,rows:1,spellCheck:!1,placeholder:jr,"aria-controls":ct?H:void 0,"aria-expanded":ct?!0:void 0,"aria-autocomplete":ge.length>0||Ie?"list":void 0,"aria-activedescendant":ct&&Ze>=0?vk(H,Ze):void 0,onChange:q=>{R(q.target.value),Ba(q.target),ae(!1),Ne(0),Ve<0&&qt(q.target.value)},onSelect:q=>Ba(q.currentTarget),onFocus:()=>K(!0),onBlur:()=>K(!1),onKeyDown:Mt,onPaste:Dn,disabled:n,hidden:ft})]}),ft?t.jsx(cX,{voice:Wn}):null,B&&!ft?t.jsxs("div",{className:"cv-note",role:"status",children:[t.jsx("span",{className:"cv-note-icon",children:t.jsx(ne,{name:B.kind==="long"?"pasted-doc":"code"})}),t.jsx("span",{className:"cv-note-text",children:B.kind==="fenced"?t.jsxs(t.Fragment,{children:["Pasted as code · ",wR(B.lang)]}):t.jsx(t.Fragment,{children:"Long paste, attached as a file"})}),t.jsx($,{size:"sm",variant:"ghost",onClick:as,children:B.kind==="fenced"?"Undo":"Put it in the message"})]}):null,t.jsxs("div",{className:"wb-composer-row",hidden:ft,children:[t.jsx("input",{ref:W,type:"file",multiple:!0,hidden:!0,"data-testid":"file-input",onChange:q=>{st(q.target.files),q.target.value=""}}),t.jsx("button",{className:"ui-icon-btn","data-size":"sm","aria-label":"Attach a file",title:"Attach a file — or paste one, or drop it anywhere on the chat",onClick:()=>{var q;return(q=W.current)==null?void 0:q.click()},disabled:n,children:t.jsx(ne,{name:"clip"})}),t.jsx(oX,{disabled:n,voice:Wn}),ie?null:t.jsx("button",{className:"ui-icon-btn","data-size":"sm","aria-label":"Snap a tab",title:"Snap a tab — one picture of another tab in this browser, attached here",onClick:()=>{z(null),L(!0),fX().then(q=>{var We;q&&(st([q]),(We=xe.current)==null||We.focus())}).catch(q=>z(q instanceof Error?q.message:String(q))).finally(()=>L(!1))},disabled:n||U,children:t.jsx(ne,{name:"camera"})}),o&&!ie?u?t.jsxs("a",{className:"wb-composer-model",href:u,title:`${o} — the model this agent runs on. Click to change it.`,children:[t.jsx("span",{className:"wb-composer-model-dot","aria-hidden":"true"}),t.jsx(O1,{model:o})]}):t.jsxs("span",{className:"wb-composer-model",title:`${o} — the model this agent runs on`,children:[t.jsx("span",{className:"wb-composer-model-dot","aria-hidden":"true"}),t.jsx(O1,{model:o})]}):null,m?t.jsxs("button",{type:"button",className:"ui-icon-btn wb-composer-thinking","data-size":"sm","aria-label":"Thinking","aria-pressed":bh(h),disabled:n||s,title:s?`Thinking: ${bh(h)?"on":"off"} — wait for ${i} to finish to change it`:`Thinking: ${bh(h)?"on":"off"}`,onClick:()=>m(bh(h)?"off":"on"),children:[t.jsx(ne,{name:"spark"}),t.jsx("span",{className:"wb-composer-think-dot","aria-hidden":"true"})]}):null,c?t.jsxs("button",{type:"button",className:"wb-composer-think wb-composer-chrome","aria-pressed":c.on,disabled:n,title:c.on?"This conversation looks in your Chrome first, where you are signed in. Click to let the agent choose again.":"Use my Chrome for this conversation: pages open in background tabs of your Chrome, where you are signed in.",onClick:()=>c.onChange(!c.on),children:[t.jsx("span",{className:"wb-composer-think-dot","aria-hidden":"true"}),t.jsxs("span",{className:"wb-composer-chip-label",children:[ie?null:t.jsx("span",{className:"wb-composer-chip-lead",children:"Use my "}),"Chrome"]})]}):null,k?t.jsx("button",{type:"button",className:"ui-icon-btn wb-read-aloud","data-size":"sm","aria-label":"Read replies aloud","aria-pressed":!!y,title:y?"Replies are read aloud. Click to stop.":"Read replies aloud, through the voice chosen in Settings → Speech",onClick:()=>k(!y),children:t.jsx(ne,{name:"speaker"})}):null,t.jsx("span",{className:"wb-hint cv-hint","data-shown":!!Qn&&(!ie||zt!==null),"data-tone":Ps>0||M!==null?"critical":void 0,children:ie&&zt===null?null:Qn}),s?t.jsx("button",{className:"ui-btn","data-variant":"stop",onClick:a,children:"Stop"}):null,t.jsx("button",{className:"wb-send","aria-label":"Send",title:Me?"Waiting for the upload to finish":s?`Send — ${i} picks it up between steps`:"Send",onClick:()=>Ae(),disabled:!Pe,children:t.jsx(ne,{name:"send"})})]})]})]}),Tt?t.jsx("p",{className:"cv-wait",role:"status","data-testid":"files-wait",children:mX(i,I.length)}):null]})});function xX(e){const s=e.slice(e.lastIndexOf("/")+1).replace(/[:@].*$/,"").replace(/^claude-/,"").replace(/-\d{8}$/,"");return s===""?e:s}function O1({model:e}){const n=xX(e);return t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"wb-composer-chip-label wb-composer-model-full",children:e}),t.jsx("span",{className:"wb-composer-chip-label wb-composer-model-short","aria-hidden":"true",children:n})]})}function bh(e){return(e??"on")==="on"}function jX(e){return{type:"attachment",artifactId:e.artifactId,filename:e.filename,mime:e.mime,kind:e.kind,sizeBytes:e.sizeBytes}}function C2({question:e,disabled:n,onAnswer:s,onSkip:r}){const[a,i]=d.useState("");return d.useEffect(()=>{if(n)return;const l=o=>{o.key!=="Escape"||o.defaultPrevented||(o.preventDefault(),r())};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[n,r]),t.jsxs("section",{className:"wb-question","aria-label":"Question from agent","data-testid":"question-picker",children:[t.jsxs("div",{className:"wb-question-head",children:[t.jsx("span",{className:"wb-question-kicker",children:"Needs your input"}),t.jsx($,{className:"wb-question-skip",variant:"ghost",size:"sm",disabled:n,onClick:r,title:"Skip this question (Esc). The agent carries on without an answer.",children:"Skip"}),t.jsx("strong",{children:vX(e.question)})]}),e.options.length>0?t.jsx("div",{className:"wb-question-options",children:e.options.map((l,o)=>t.jsxs("button",{className:"wb-question-option","data-recommended":l.recommended||void 0,disabled:n,onClick:()=>s(l.label,l.id),children:[t.jsx("span",{className:"wb-question-number",children:o+1}),t.jsxs("span",{children:[t.jsxs("span",{className:"wb-question-label",children:[l.label,l.recommended?t.jsx("em",{children:"Recommended"}):null]}),l.hint?t.jsx("small",{children:l.hint}):null]})]},l.id))}):null,e.allowOther?t.jsxs("form",{className:"wb-question-other",onSubmit:l=>{l.preventDefault(),a.trim()&&s(a.trim())},children:[t.jsx("input",{value:a,onChange:l=>i(l.target.value),placeholder:e.options.length?"Something else…":"Type your answer…",disabled:n}),t.jsx("button",{className:"ui-btn","data-variant":"accent",disabled:n||!a.trim(),children:"Answer"})]}):null,t.jsx("p",{className:"wb-question-note",children:"This answers a question. It does not approve an action. Esc skips it."})]})}function vX(e){const n=[];let s=0;for(const r of e.matchAll(/https:\/\/[^\s<>"']+/g)){const a=r[0].replace(/[.,;:!?)\]]+$/,""),i=r.index??0;i>s&&n.push(e.slice(s,i)),n.push(t.jsx("a",{href:a,target:"_blank",rel:"noopener noreferrer",children:a},i)),s=i+a.length}return s<e.length&&n.push(e.slice(s)),n}function yX(e,n){const s=i=>{var l;return`@${((l=n.find(o=>o.id===i))==null?void 0:l.handle)??i}`},[r,...a]=e;return r===void 0?"":[s(r),...a.map(i=>`asked by ${s(i)}`)].join(", ")}function wX(e,n,s){return e?[...zM({messages:e.messages,descriptors:[],...s?{awaiting:new Map(s)}:{}}).filter(a=>a.source==="approval").map(a=>({approvalId:a.props.approvalId,toolUseId:a.id})),...E2(e,n)]:[]}function E2(e,n){return((e==null?void 0:e.delegatedApprovals)??[]).map(s=>({approvalId:s.approvalId,toolUseId:s.toolUseId??"",askedBy:yX(s.chain,n)}))}function D1(e){return e instanceof pe||e instanceof Error?e.message:String(e)}function A2({conversation:e,conversationId:n,agentId:s,now:r,refresh:a,onRunStarted:i,onError:l,navigate:o}){const[c,u]=d.useState(null),[h,m]=d.useState([]),[f,p]=d.useState(!1),x=((e==null?void 0:e.offers)??[]).filter(v=>!h.includes(v.id)&&Date.parse(v.expiresAt)>r),g=v=>{var y;const j=x.find(k=>k.id===v);if(((y=j==null?void 0:j.handoff)==null?void 0:y.kind)==="install"){o(V8(j.handoff.package));return}l(null),u(v),m(k=>[...k,v]),T.takeOffer(v,n??void 0).then(k=>{if(k.agentId&&k.agentId!==s){o(ut(k.agentId,k.conversationId??null));return}k.runId&&i(),n&&a(n)}).catch(k=>{m(N=>N.filter(b=>b!==v)),l(D1(k)),n&&a(n)}).finally(()=>u(null))},w=v=>{const j=e==null?void 0:e.question;j&&(l(null),p(!0),i(),nt.answerQuestion(j.id,v).then(()=>{if(n)return a(n)}).catch(y=>l(D1(y),!0)).finally(()=>p(!1)))};return{openOffers:x,takingOffer:c,takeOffer:g,answeringQuestion:f,answerQuestion:(v,j)=>w({answer:v,...j?{optionId:j}:{}}),skipQuestion:()=>w({answer:"",skipped:!0})}}function $2({offers:e,disabled:n,onTake:s}){return e.length===0?null:t.jsx("div",{className:"wb-offers","data-testid":"chat-offers",children:e.map(r=>{var a,i;return t.jsx("button",{type:"button",className:"ui-btn",disabled:n,title:((a=r.handoff)==null?void 0:a.kind)==="install"?`Opens ${r.handoff.title}'s install sheet`:r.prompt,"data-handoff":(i=r.handoff)==null?void 0:i.kind,onClick:()=>s(r.id),children:r.label},r.id)})})}function bX(e,n){return e.messages<=0?!1:e.chars>e.maxChars?!0:e.lastActivityAt===null||e.idleTimeoutMs===null?!1:n-Date.parse(e.lastActivityAt)>e.idleTimeoutMs}function kX(e){const n=e/864e5;if(n>=1&&Number.isInteger(n))return n===7?"1 week":`${n} day${n===1?"":"s"}`;const s=e/36e5;if(s>=1&&Number.isInteger(s))return`${s} hour${s===1?"":"s"}`;const r=Math.round(e/6e4);return`${r} minute${r===1?"":"s"}`}function NX(e){const{lifetime:n,startedAt:s,now:r,timezone:a}=e;if(!n||n.messages<=0)return{text:"New conversation",title:"Nothing has been said in this one yet.",tone:"quiet"};const i=`${Math.round(n.maxChars/1e3)}k characters`,l=(n.idleTimeoutMs===null?`A conversation ends once its transcript grows past ${i}. `:`A conversation ends after ${kX(n.idleTimeoutMs)} idle, or once its transcript grows past ${i}. `)+"What the agent remembers about you carries over.",o=`${n.messages} message${n.messages===1?"":"s"}`;if(bX(n,r))return{text:`${o} · your next message starts a fresh one`,title:l,tone:"note"};const c=s?Xe(s,r):"";return{text:c===""?o:`${o} · started ${c}`,title:s?`Started ${St(s,a)}. ${l}`:l,tone:"quiet"}}function SX({text:e,onDelete:n}){const[s,r]=d.useState(!1),[a,i]=d.useState(null);return t.jsx("div",{className:"wb-carryover","data-testid":"chat-carryover",children:t.jsxs(Vt,{summary:"Carried over from the previous conversation",children:[t.jsx("p",{className:"wb-carryover-text",children:e}),t.jsxs(te,{align:"end",children:[a?t.jsx("span",{className:"critical",role:"alert",children:a}):null,t.jsx($,{size:"sm",variant:"danger-ghost",disabled:s,onClick:()=>{r(!0),i(null),n().catch(l=>{i(l instanceof Error?l.message:String(l)),r(!1)})},children:"Delete note"})]})]})})}function T2(e){return e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function R2(e,n){return e.members.map(s=>n.find(r=>r.id===s)).filter(s=>s!==void 0)}function CX(e,n){var a;const s=R2(e,n),r=e.members.filter(i=>!n.some(l=>l.id===i));if(!n.some(i=>i.id===e.coordinator))return{kind:"coordinator",text:`${e.coordinator} coordinated this group and is no longer in buddi, so the group can't take requests.`,action:"Choose a coordinator"};if(s.length<2){const i=r.length>0?`: ${r.join(", ")} ${r.length===1?"was":"were"} removed from buddi`:"";return{kind:"alone",text:`Only ${((a=s[0])==null?void 0:a.name)??e.coordinator} is left here${i}.`,action:"Add a member"}}return null}function EX(){return t.jsx("span",{className:"ui-avatar group-gone-face","aria-hidden":"true",children:"?"})}function AX({group:e,agents:n,onClose:s,onSaved:r}){const[a,i]=d.useState(!1),[l,o]=d.useState(null),c=[e.coordinator,...e.members.filter(x=>x!==e.coordinator)],u=e.members.length>2,h=vb(n).filter(x=>!e.members.includes(x.id)),m=!n.some(x=>x.id===e.coordinator),f=async x=>{i(!0),o(null);try{r(await nt.updateGroup(e.id,x))}catch(g){o(g instanceof pe?g.message:String(g))}finally{i(!1)}},p=x=>void f({members:e.members.filter(g=>g!==x)});return t.jsxs(Ye,{title:"Members",onClose:s,children:[t.jsxs("p",{className:"group-lede",children:[e.name," · ",e.members.length," agents. The coordinator may ask members here; each keeps its own account, tools and approvals."]}),m?t.jsxs(Q,{tone:"warning",children:[e.coordinator," coordinated this group and is no longer in buddi. Pick who coordinates now."]}):null,l?t.jsx(Q,{tone:"critical",children:l}):null,t.jsx(yt,{children:c.map(x=>{const g=n.find(v=>v.id===x),w=x===e.coordinator;return g?t.jsx(pt,{lead:t.jsx(vn,{agents:n,id:x}),title:g.name,sub:g.description,side:t.jsxs(t.Fragment,{children:[w?t.jsx($e,{tone:"accent",children:"Coordinator"}):null,m&&g.available?t.jsx($,{size:"sm",disabled:a,onClick:()=>void f({coordinator:x}),children:"Make coordinator"}):null,t.jsx(rs,{label:`More for ${g.name}`,...w?{note:"Coordinates the group"}:{},items:[!w&&g.available&&{label:"Make coordinator",hint:"Reads your requests, answers for the room",onSelect:()=>void f({coordinator:x})},{label:`Open ${g.name}'s page`,onSelect:()=>{window.location.hash=Qt(x)}},!w&&"separator",!w&&{label:"Remove from group",hint:u?"What it said stays":"A group needs two",tone:"critical",onSelect:()=>{u?p(x):o("A group needs two agents. Add someone before taking this one out.")}}]})]})},x):t.jsx(pt,{lead:t.jsx(EX,{}),title:t.jsx("span",{className:"group-gone-id",children:x}),sub:t.jsxs("span",{className:"group-gone-line",children:["No longer in buddi",w?" · was the coordinator":u?"":" · add a member to take it out"]}),side:u&&!w?t.jsx($,{size:"sm",disabled:a,onClick:()=>p(x),children:"Remove"}):void 0},x)})}),t.jsxs("div",{className:"group-add",children:[t.jsx("h3",{className:"group-add-title",children:"Add a member"}),h.length>0?t.jsx(yt,{children:h.map(x=>t.jsx(pt,{lead:t.jsx(vn,{agents:n,id:x.id,size:"sm"}),title:x.name,sub:x.description,side:t.jsx($,{size:"sm",disabled:a,onClick:()=>void f({members:[...e.members,x.id]}),children:"Add"})},x.id))}):t.jsx("p",{className:"group-quiet",children:"Everyone who can join a group is here."})]}),t.jsx("p",{className:"group-quiet",children:"Members read what is said here and what they recall from shared and group memory; nothing an agent knows privately comes in on its own. Taking a member out leaves what it said in the history."})]})}function $X({group:e,onClose:n,onSaved:s}){const[r,a]=d.useState(e.name),[i,l]=d.useState(!1),[o,c]=d.useState(null),u=r.trim()!==""&&r.trim()!==e.name&&!i,h=async()=>{if(u){l(!0),c(null);try{s(await nt.updateGroup(e.id,{name:r.trim()}))}catch(m){c(m instanceof pe?m.message:String(m)),l(!1)}}};return t.jsx(Gt,{title:"Rename group",onClose:n,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:!u,onClick:()=>void h(),children:i?"Renaming…":"Rename"})]}),children:t.jsx("form",{onSubmit:m=>{m.preventDefault(),h()},children:t.jsxs(ue,{children:[t.jsx(le,{label:"Name",hint:"What this team is for: Household finances, The move, Tax season.",children:t.jsx("input",{value:r,autoFocus:!0,maxLength:80,onFocus:m=>m.currentTarget.select(),onChange:m=>a(m.target.value)})}),o?t.jsx(Q,{tone:"critical",children:o}):null]})})})}function I2(e){const[n,s]=d.useState(null);return d.useEffect(()=>{let r=!0;return nt.group(e).then(a=>{var i;r&&s(((i=a.history)==null?void 0:i.conversations)??null)}).catch(()=>{}),()=>{r=!1}},[e]),n}function TX(e){return e===null?"Its conversations":e===0?"Nothing has been said yet, and its next conversation":`Its ${e} ${e===1?"conversation":"conversations"}`}function RX({group:e,onClose:n,onCleared:s}){const r=I2(e.id),[a,i]=d.useState(!1),[l,o]=d.useState(null),c=async()=>{i(!0),o(null);try{await nt.clearGroup(e.id),s()}catch(h){o(h instanceof pe?h.message:String(h)),i(!1)}},u=r===0;return t.jsxs(Gt,{title:`Clear the history of ${e.name}?`,onClose:n,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx($,{variant:"danger",disabled:a||u,"data-testid":"group-clear-confirm",onClick:()=>void c(),children:a?"Clearing…":"Clear history"})]}),children:[t.jsx("p",{className:"group-dialog-text",children:u?"Nothing has been said in this group yet, so there is nothing to clear.":`${TX(r)} ${r===1?"is":"are"} deleted for good, and anything it is doing now stops. The group, its members and what it remembers stay; files it made stay in Files.`}),l?t.jsx(Q,{tone:"critical",children:l}):null]})}function IX({group:e,agents:n,onClose:s,onDeleted:r}){const a=I2(e.id),[i,l]=d.useState(!1),[o,c]=d.useState(null),u=R2(e,n).map(f=>f.name),h=async()=>{l(!0),c(null);try{const{undoUntil:f}=await nt.deleteGroup(e.id);r(f)}catch(f){c(f instanceof pe?f.message:String(f)),l(!1)}},m=a===null?"its conversations":a===0?"nothing said yet":`its ${a} ${a===1?"conversation":"conversations"}`;return t.jsxs(Gt,{title:`Delete ${e.name}?`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx($,{variant:"danger",disabled:i,"data-testid":"group-delete-confirm",onClick:()=>void h(),children:i?"Deleting…":"Delete group"})]}),children:[t.jsxs("p",{className:"group-dialog-text",children:["The group goes with ",m," and what it remembers."," ",u.length>0?`${T2(u)} ${u.length===1?"is":"are"} not touched, and files it made stay in Files.`:"Files it made stay in Files."]}),o?t.jsx(Q,{tone:"critical",children:o}):null]})}function L1(){var e;return typeof document>"u"||document.querySelector('[role="dialog"], [role="alertdialog"]')?!0:((e=window.matchMedia)==null?void 0:e.call(window,"(pointer: coarse)").matches)===!0}function PX({timezone:e,agents:n,agentId:s,defaultAgentId:r=null,group:a=null,onGroupAction:i,onSelectAgent:l,onWorking:o,attention:c,agentsInHeader:u,narrow:h,canvasOpen:m,onOpenCanvas:f,onCloseCanvas:p,newConversationSignal:x,requestedConversationId:g,requestedTab:w,onConversationOpened:v}){var x0,j0,v0,y0,w0,b0,k0,N0,S0,C0,E0,A0,$0;const j=cc(),[y,k]=d.useState(()=>{try{const V=Number(localStorage.getItem("buddi.chatTextSize"));return Number.isInteger(V)&&V>=11&&V<=19?V:13}catch{return 13}}),N=V=>{k(V);try{localStorage.setItem("buddi.chatTextSize",String(V))}catch{}},b=t.jsxs("div",{className:"wb-reading-controls",role:"group","aria-label":"Message text size",children:[t.jsx("span",{children:"Text size"}),t.jsx("button",{className:"ui-btn","data-size":"sm",role:"menuitem","aria-label":"Decrease message text size",disabled:y<=11,onClick:()=>N(y-1),children:"A−"}),t.jsx("button",{className:"ui-btn","data-size":"sm",role:"menuitem","aria-label":"Increase message text size",disabled:y>=19,onClick:()=>N(y+1),children:"A+"}),t.jsx("button",{className:"ui-btn","data-size":"sm",role:"menuitem","aria-label":"Reset message text size",disabled:y===13,onClick:()=>N(13),children:"Reset"})]}),[S,C]=d.useState([]),A=d.useMemo(()=>new Set(S.filter(V=>{var he;return((he=V.messenger)==null?void 0:he.mediaFirst)===!0}).map(V=>V.tool)),[S]),[E,R]=d.useState(null),[P,O]=d.useState(null),[I,F]=d.useState(null),[U,L]=d.useState([]),[M,z]=d.useState([]),[D,K]=d.useState(null),[B,se]=d.useState(!1),[W,xe]=d.useState(new Map),[me,ie]=d.useState(new Set),[H,de]=d.useState(null),[ge,Ue]=d.useState(0),G=d.useCallback(V=>{de(V),Ue(he=>he+1)},[]),[ae,J]=d.useState(()=>new Set),Ne=XJ(E??null),[Ie,Y]=d.useState(()=>Date.now());d.useEffect(()=>{const V=setInterval(()=>Y(Date.now()),6e4);return()=>clearInterval(V)},[]);const[X,oe]=d.useState([]),[ve,be]=d.useState(!1),Ce=d.useRef(0),we=d.useRef(null),[He,Ze]=d.useState(!1),Se=d.useRef(x??0),Le=d.useRef(s),Ve=d.useRef({agentId:s,conversationId:E});Ve.current={agentId:s,conversationId:E};const Qe=Ne.closed,[wt,dt]=d.useState(null),[qt,vt]=d.useState(null),[Dt,bn]=d.useState(()=>Date.now()),[sn,ce]=d.useState(AJ),Me=d.useRef(null),[tt,Tt]=d.useState(null),[bt,Pe]=d.useState(!1),[st,_e]=d.useState(null),[en,ee]=d.useState(null),[rt,On]=d.useState(aP),$n=d.useRef(rt);$n.current=rt;const Ae=d.useRef(null),[De,gt]=d.useState(null),Mt=d.useCallback(V=>{On(V),iP(V),V||lc()},[]),[Dn,as]=d.useState(null),[js,Ps]=d.useState(null);d.useEffect(()=>{if(!s)return;_e(vU(s));const V=wU(s);V&&ee({text:V,at:Date.now()})},[s]);const Wn=a?`group:${a.id}`:s??null,ft=[...n.top,...n.middle,...n.bottom],fe=ft.find(V=>V.id===s)??null,ct=je(()=>T.providerAccounts(),[]),Et=a?a.members.map(V=>ft.find(he=>he.id===V)).filter(V=>!!V):[],[gn,is]=d.useState(null),Rl=B?gn??s??null:null;d.useEffect(()=>{o==null||o(Rl)},[Rl,o]),d.useEffect(()=>()=>o==null?void 0:o(null),[o]),d.useEffect(()=>{let V=!1;return nt.views().then(he=>{V||C(he.views??[])}).catch(()=>{}),()=>{V=!0}},[]),d.useEffect(()=>{if(!s)return;const V=Le.current===s;if(Le.current=s,V&&g&&g===Ve.current.conversationId)return;let he=!1;return R(null),O(null),F(null),L([]),dt(null),se(!1),de(null),oe([]),pa(null),Ze(!1),Tt(null),g?(g!=="new"?R(g):F(Wn),()=>{he=!0}):((a?nt.groupConversations(a.id):nt.conversations(s)).then(Oe=>{if(he)return;const Ke=[...Oe.conversations??[]].sort(MX)[0];Ke?(R(Ke.id),v==null||v(s,Ke.id)):F(Wn)}).catch(()=>{he||F(Wn)}),()=>{he=!0})},[s,a==null?void 0:a.id,Wn,g,v]);const Ms=d.useCallback(V=>nt.conversation(V).then(he=>{if(Ve.current.conversationId===V){if(he.agentId!==Ve.current.agentId)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");O(he),L(Oe=>Oe.filter(Ke=>!ox(he,Ke)))}}).catch(he=>{Ve.current.conversationId===V&&dt(Ga(he))}),[]);d.useEffect(()=>{if(!E)return;let V=!1;return xe(new Map),ie(new Set),z([]),nt.conversation(E).then(he=>{if(!V){if(he.agentId!==s)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");O(he),L(Oe=>Oe.filter(Ke=>!ox(he,Ke)))}}).catch(he=>{V||dt(Ga(he))}),()=>{V=!0}},[E,s]),d.useEffect(()=>{if(!E)return;let V=!1;const he=window.setInterval(()=>{nt.conversation(E).then(Oe=>{V||Oe.agentId!==Ve.current.agentId||(O(Oe),L(Ke=>Ke.filter(qe=>!ox(Oe,qe))))}).catch(()=>{})},3e3);return()=>{V=!0,window.clearInterval(he)}},[E,s]),d.useEffect(()=>{if(!E)return;const V=cp({url:nt.streamUrl(E),onEvent:he=>{var Oe,Ke;switch(he.name){case"run.started":Ae.current=null,se(!0),K(null),is(Kn(he.data.agentId));break;case"live":{const qe=Kn(he.data.runId)??"",ot=Number(he.data.turn??0),mt=he.data.kind==="thinking"?"thinking":"text",kt=Kn(he.data.text)??"",Wr=Date.now();if(mt==="text"){const vs=Ae.current;Ae.current=vs&&vs.runId===qe&&vs.turn===ot?{...vs,text:vs.text+kt}:{runId:qe,turn:ot,text:kt}}K(vs=>{const Ha=vs&&vs.runId===qe&&vs.turn===ot?vs:{runId:qe,turn:ot,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return mt==="thinking"?{...Ha,thinking:Ha.thinking+kt,thinkingStartedAt:Ha.thinkingStartedAt??Wr}:{...Ha,text:Ha.text+kt,textStartedAt:Ha.textStartedAt??Wr}});break}case"live.snapshot":{const qe=Kn(he.data.runId)??"",ot=Number(he.data.turn??0),mt=Kn(he.data.text)??"",kt=Kn(he.data.thinking)??"",Wr=Number(he.data.startedAt??Date.now());Ae.current={runId:qe,turn:ot,text:mt},K({runId:qe,turn:ot,text:mt,thinking:kt,thinkingStartedAt:kt?Wr:null,textStartedAt:mt?Wr:null,settled:!1});break}case"live.settle":{const qe=Kn(he.data.runId)??"",ot=Number(he.data.turn??0);if(he.data.retracted===!0){((Oe=Ae.current)==null?void 0:Oe.runId)===qe&&Ae.current.turn===ot&&(Ae.current=null),K(mt=>mt&&mt.runId===qe&&mt.turn===ot?null:mt);break}K(mt=>mt&&mt.runId===qe&&mt.turn===ot?{...mt,settled:!0}:mt);break}case"tool.called":{const qe=Kn(he.data.toolUseId)??Kn(he.data.id),ot=Kn(he.data.name)??Kn(he.data.tool)??"tool";qe&&z(mt=>[...mt.filter(kt=>kt.toolUseId!==qe),{toolUseId:qe,name:ot,startedAt:Date.now()}]);break}case"tool.result":{const qe=Kn(he.data.toolUseId)??Kn(he.data.id);qe&&z(ot=>ot.filter(mt=>mt.toolUseId!==qe)),Ms(E);break}case"reaction":Ms(E);break;case"message.appended":Ms(E).then(()=>{K(qe=>qe!=null&&qe.settled?null:qe)});break;case"awaiting-approval":{const qe=Kn(he.data.approvalId)??Kn(he.data.actionId),ot=Kn(he.data.toolUseId);qe&&ot&&xe(mt=>new Map(mt).set(ot,qe)),z(mt=>mt.filter(kt=>kt.toolUseId!==ot)),Ms(E);break}case"run.finished":{se(!1),z([]),K(null),is(null);const qe=Kn(he.data.message);dt(qe??null);const ot=((Ke=Ae.current)==null?void 0:Ke.text.trim())??"";Ae.current=null,!qe&&ot!==""&&$n.current&&cm(ot,E).then(mt=>{mt&&gt(mt)}),Ms(E);break}}}});return()=>V.close()},[E,Ms]),d.useEffect(()=>{const V=window.setInterval(()=>bn(Date.now()),M.length===0?6e4:1e3);return()=>window.clearInterval(V)},[M.length]);const xr=je(()=>s&&E?T.browser({agentId:s,conversationId:E}):Promise.resolve(void 0),[s,E],1500),zt=xr.error?void 0:xr.data,Qn=zt!=null&&zt.session&&zt.session.agentId===s&&zt.session.conversationId===E?zt:void 0,jr=UJ(Qn,s,E),ma=(jr==null?void 0:jr.id)??null,[Ba,Sd]=d.useState(null),Cd=Qn==null?void 0:Qn.mode;d.useEffect(()=>{jr&&s&&E&&Sd({agentId:s,conversationId:E,tab:BJ(jr)})},[ma,Cd,s,E]);const Ed=Ba&&Ba.agentId===s&&Ba.conversationId===E&&!Qe.includes(Ba.tab.id)?Ba.tab:null,q=Xv(P==null?void 0:P.question),We=tf(P==null?void 0:P.question),[et,dn]=d.useState(!1),Je=jr?null:WJ(zt,E??null,(q==null?void 0:q.kind)==="paused"),At=jr??Je??Ed,Hn=(x0=zt==null?void 0:zt.routes)==null?void 0:x0.find(V=>V.kind==="chrome"),tr=!a&&E&&(Hn!=null&&Hn.allowed)&&Hn.paired?{on:(zt==null?void 0:zt.pin)==="chrome",onChange:V=>{T.browserPin(E,V?"chrome":"auto").catch(()=>{}).finally(xr.reload)}}:void 0,[Lp,pa]=d.useState(null),Wa=d.useMemo(()=>Q7({messages:(P==null?void 0:P.messages)??[],descriptors:S}),[P,S]),ga=PJ(Wa,E??null),mc=OJ(a?null:s),Ad=d.useMemo(()=>MJ((P==null?void 0:P.messages)??[]),[P]),Il=d.useRef([]),hn=d.useMemo(()=>{const V=zM({messages:(P==null?void 0:P.messages)??[],descriptors:S,awaiting:W,served:ga.served,...At?{folded:sf}:{},gathered:qJ,quiet:$1,titles:T1});Il.current=V;const he=ot=>H!==null&&(ot.id===H||(ot.versions??[]).some(mt=>mt.id===H)),Oe=[];for(const ot of Ne.ready?V:V.filter(mt=>mt.source==="approval")){if(ot.source!=="approval"&&Qe.includes(zi(ot))&&!he(ot))continue;const mt=F7(ot,Ie);mt==="gone"&&!he(ot)||Oe.push(mt==="parked"?{...ot,parked:!0}:ot)}const Ke=H?ZC(Oe,H):null;Ke&&(Ke.props={...Ke.props,focus:H});const qe=H&&!Ke?YC(Oe,H):null;if(qe&&(qe.focus=H),H&&!Ke&&!qe&&!Qe.includes(H)&&!Oe.some(ot=>ot.id===H)){const ot=eq((P==null?void 0:P.messages)??[],H,{redactInputOf:sf,resultOf:$1,titles:T1});ot&&!sf.has(ot.tool)&&Oe.push(ot)}At&&Oe.push(At);for(const ot of X)Oe.push(RW(ot));return mc&&Oe.unshift(DJ(mc,Ad)),tt?[...Oe,LJ(tt)]:Oe},[P,S,W,tt,ma,At==null?void 0:At.title,H,Ne.closed,Ne.ready,Ie,E,X,ga.served,mc,Ad]),kL=d.useMemo(()=>{var he;const V=[];for(const Oe of(P==null?void 0:P.messages)??[]){if(Oe.role!=="user"||Oe.speaker&&Oe.speaker!=="owner")continue;const Ke=(he=Oe.blocks.find(qe=>qe.type==="text"))==null?void 0:he.text.trim();Ke&&V.unshift(Ke)}return V},[P]),Fp=d.useMemo(()=>hn.filter(V=>V.source==="approval"),[hn]),$d=Fp.at(-1)??null,Td=d.useMemo(()=>[...Fp.map(V=>({approvalId:V.props.approvalId,toolUseId:V.id})),...E2(P,ft)].filter(V=>!me.has(V.approvalId)),[Fp,P==null?void 0:P.delegatedApprovals,me]),Oi=d.useMemo(()=>{for(let V=hn.length-1;V>=0;V-=1){const he=hn[V];if(he!=null&&he.substantial)return zi(he)}return null},[hn]),vr=(H?((j0=ZC(hn,H))==null?void 0:j0.id)??((v0=YC(hn,H))==null?void 0:v0.id):null)??H,Xk=Ne.touch;d.useEffect(()=>{ge!==0&&vr&&hn.some(V=>V.id===vr)&&Xk(vr)},[ge,vr,Xk]),d.useEffect(()=>{vr&&J(V=>{if(!V.has(vr))return V;const he=new Set(V);return he.delete(vr),he})},[vr]);const NL=d.useMemo(()=>{const V=(P==null?void 0:P.messages)??[];for(let he=V.length-1;he>=0;he-=1){const Oe=V[he];if((!Oe.speaker||Oe.speaker==="owner")&&_M(Oe))return Oe.at??null}return null},[P]),Rd=d.useRef(null),_p=((y0=hn.filter(V=>(V.source!=="browser"||V.pinned===!0)&&V.id!==Qv).at(-1))==null?void 0:y0.id)??((w0=hn.filter(V=>V.id!==Qv).at(-1))==null?void 0:w0.id)??null,Id=jr!==null&&!h,zp=d.useCallback(V=>V!==void 0&&(!Id||V.source==="canvas"),[Id]);d.useEffect(()=>{if(Oi&&Oi!==Rd.current){Rd.current=Oi;const V=hn.find(he=>zi(he)===Oi);if(zp(V)){de(Oi);return}}H===null&&_p&&de(_p)},[Oi,H,_p,hn,zp]);const Pd=d.useRef({key:null,stamps:new Map}),Md=P&&Ne.ready?E??null:null;d.useEffect(()=>{const V=new Map(hn.map(Ke=>[Ke.id,zi(Ke)]));if(Md===null||Pd.current.key!==Md){Pd.current={key:Md,stamps:V},J(Ke=>Ke.size===0?Ke:new Set);return}const he=Pd.current.stamps;Pd.current.stamps=V;const Oe=hn.filter(Ke=>he.get(Ke.id)!==V.get(Ke.id)&&Ke.at!==null&&Ke.id!==vr&&!(zi(Ke)===Oi&&zp(Ke)));Oe.length!==0&&J(Ke=>new Set([...Ke,...Oe.map(qe=>qe.id)]))},[hn,Md]);const Zk=d.useRef(ga.live);d.useEffect(()=>{const V=Zk.current;Zk.current=ga.live;const he=[...ga.live].filter(qe=>!V.has(qe));if(he.length===0||$d||Id||H!==null&&H!==Rd.current)return;const Ke=[...hn].reverse().find(qe=>qe.source==="descriptor"&&qe.renderer==="preview"&&qe.props.target!==null&&he.includes(wo(qe.props.target)));Ke&&de(Ke.id)},[ga.live,hn,$d,H,Id]);const e0=d.useRef(null);d.useEffect(()=>{ma!==e0.current&&(e0.current=ma,ma&&!$d&&de(ma))},[ma,$d]);const t0=d.useRef(null),pc=w==="browser"?(At==null?void 0:At.id)??null:null;d.useEffect(()=>{!pc||t0.current===pc||(t0.current=pc,de(pc))},[pc]);const Up=(At==null?void 0:At.id)??null;d.useEffect(()=>{!Up||!H||A1((P==null?void 0:P.messages)??[],H)!==null&&(pa(H),de(Up))},[Up,H,P]);const n0=V=>{oe(he=>he.some(Oe=>Oe.artifactId===V.artifactId)?he:[...he,V]),G(Qh(V.artifactId)),h&&(f==null||f())},gc=!a&&fe&&!fe.available?FI(fe):null,s0=a?t.jsx("span",{className:"wb-group-stack","aria-hidden":"true",children:a.members.slice(0,2).map(V=>{const he=ft.find(Oe=>Oe.id===V);return t.jsx(dp,{className:"wb-group-chip",id:V,name:(he==null?void 0:he.name)??"?",face:he,initials:1},V)})}):null,Di=a&&ft.length>0?CX(a,ft):null,r0=(Di==null?void 0:Di.kind)==="coordinator",a0=iv(a?null:fe),i0=Td.length>0||!!(P!=null&&P.question),Bp=d.useRef(i0);Bp.current=i0,d.useEffect(()=>{if(Bp.current||L1())return;const V=window.requestAnimationFrame(()=>{var he;Bp.current||L1()||(he=we.current)==null||he.focus()});return()=>window.cancelAnimationFrame(V)},[s,a==null?void 0:a.id,E,x]);const SL=fe&&js===fe.id?Dn:(fe==null?void 0:fe.thinking)??null,CL=V=>{if(!fe)return;const he=fe.id;Ps(he),as(V),T.setAgentEngine(he,{thinking:V}).catch(Oe=>{Ps(null),dt(Oe instanceof pe?Oe.message:String(Oe))})},Od=(V,he,Oe=!1)=>{if(!s)return;const Ke=a?null:_X(V,ft,s);if(Ke){dt(null),nt.send(Ke.agent.id,{text:Ke.rest,attachmentIds:he.map(kt=>kt.artifactId)}).then(kt=>{window.location.hash=ut(Ke.agent.id,kt.conversationId)}).catch(kt=>dt(Ga(kt)));return}V=yU(V,a?null:st);const qe=he.map(kt=>kt.artifactId),ot=B,mt={id:`optimistic:${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[...V.trim()===""?[]:[{type:"text",text:V}],...he.map(kt=>({type:"attachment",artifactId:kt.artifactId,filename:kt.filename,mime:kt.mime,kind:kt.kind,sizeBytes:kt.sizeBytes}))],...ot?{speaker:HM}:{}};L(kt=>ot?[...kt,mt]:[mt]),dt(null),vt(null),se(!0),(a?nt.sendToGroup(a.id,{...E?{conversationId:E}:{},text:V,attachmentIds:qe}):nt.send(s,{...E?{conversationId:E}:{},text:V,attachmentIds:qe})).then(async kt=>{var Wr;Ve.current.agentId!==s||Ve.current.conversationId!==E||(!a&&st&&(fS(s),_e(null)),vt(kt.rolledOver===!0?"(New thread — the room had grown long. Where it stopped carries over as a summary.)":null),kt.conversationId!==E?(Oe&&((Wr=we.current)==null||Wr.carryDraftTo(kt.conversationId)),O(null),R(kt.conversationId)):await Ms(kt.conversationId),kt.queued===!0&&L(vs=>vs.filter(Ha=>Ha.id!==mt.id)),v==null||v(s,kt.conversationId))}).catch(kt=>{L(Wr=>Wr.filter(vs=>vs.id!==mt.id)),dt(Ga(kt)),se(!1)})},{openOffers:EL,takingOffer:AL,takeOffer:$L,answeringQuestion:l0,answerQuestion:Wp,skipQuestion:TL}=A2({conversation:P,conversationId:E??null,agentId:(fe==null?void 0:fe.id)??null,now:Dt,refresh:Ms,onRunStarted:()=>{vt(null),se(!0)},onError:(V,he)=>{dt(V),he&&se(!1)},navigate:V=>{window.location.hash=V}}),RL=()=>{if(s){if(tt){Tt(null);return}Pe(!0),T.agentProfile(s).then(V=>{Tt(V),G(Jv(V.id)),h&&(f==null||f())}).catch(V=>dt(Ga(V))).finally(()=>Pe(!1))}},IL=V=>{ee({text:V.prompt,at:Date.now()}),l(V.agentId),h&&(p==null||p())},o0=()=>{E&&nt.cancel(E).catch(V=>dt(Ga(V))).finally(()=>{se(!1),z([])})},PL=(V,he)=>{if(dt(null),V==="stop"){o0();return}if(V==="use"){const Oe=he.replace(/^@/,"").toLowerCase(),Ke=ft.find(qe=>qe.handle.toLowerCase()===Oe||qe.id===Oe);if(!Ke){vt(Oe?`No agent called @${Oe}.`:"Say who: /use @handle.");return}vt(null),l(Ke.id);return}if(V==="new"){const Oe=ft.find(Ke=>Ke.roles.includes(Pr));if(!Oe){vt("There is no agent here that makes agents.");return}he.trim()&&fd(Oe.id,`I'd like a teammate for this: ${he.trim()}`),l(Oe.id);return}T.quiet(he).then(Oe=>vt(Oe.text)).catch(Oe=>dt(Ga(Oe)))},Dd=d.useCallback(()=>{if(R(null),O(null),L([]),se(!1),dt(null),vt(null),z([]),xe(new Map),ie(new Set),de(null),oe([]),pa(null),Rd.current=null,a){nt.startGroupConversation(a.id).then(({conversationId:V})=>{R(V),s&&(v==null||v(s,V))}).catch(V=>dt(Ga(V)));return}F(Wn),s&&(v==null||v(s,"new"))},[s,a,Wn,v]);d.useEffect(()=>{x&&x!==Se.current&&(Se.current=x,Dd())},[x,Dd]);const c0=V=>{E&&Ms(E),T.overview().catch(()=>{}),V.state!=="pending"&&(xe(he=>new Map([...he].filter(([,Oe])=>Oe!==V.id))),ie(he=>he.has(V.id)?he:new Set([...he,V.id])))},ML=((b0=ft.find(V=>V.id===r))==null?void 0:b0.name)??null,u0=a?[]:L8(fe,ML),d0=!(P&&P.conversationId===E)&&!(!E&&I!==null&&I===Wn),h0=d0?t.jsx("div",{className:"wb-chat-loading","data-testid":"chat-loading","aria-busy":"true"}):!a&&fe?t.jsx(sP,{quiet:!0,still:!0,className:"wb-chat-field",children:t.jsxs("div",{className:"wb-chat-opening","data-testid":"chat-opening",children:[t.jsx(vn,{agents:ft,id:fe.id,size:"xl"}),t.jsx("h2",{className:"wb-chat-hello",children:`Hi, I'm ${fe.name}.`}),t.jsx("p",{className:"wb-chat-intro",children:F8(fe)}),u0.length>0?t.jsx("div",{className:"wb-starters",role:"group","aria-label":`Things to ask ${fe.name}`,children:u0.map(V=>t.jsx("button",{type:"button",className:"wb-starter",onClick:()=>{var he;ee({text:V,at:Date.now()}),(he=we.current)==null||he.focus()},children:V},V))}):null]})}):null,f0=V=>{const he=[];for(const Oe of V)if(tt&&Oe===Jv(tt.id))Tt(null);else if(X.some(Ke=>Qh(Ke.artifactId)===Oe))oe(Ke=>Ke.filter(qe=>Qh(qe.artifactId)!==Oe));else{const Ke=hn.find(qe=>qe.id===Oe);he.push(Ke?zi(Ke):Oe)}he.length>0&&Ne.close(he),H!==null&&(V.includes(H)||V.includes(vr??""))&&de(null)},m0=t.jsx(cJ,{renderables:hn,activeId:vr,onActivate:G,onClose:V=>f0([V]),onCloseMany:f0,touched:Ne.touched,turnStartedAt:NL,unread:ae,timezone:e,onDecided:c0,onChangeAgent:IL,agents:ft,browserPanel:At?t.jsx(wQ,{status:Qn,error:xr.error,reload:xr.reload,live:jr!==null,agentName:(fe==null?void 0:fe.name)??"The agent",timezone:e,paused:Je&&(zt!=null&&zt.stop)?zt.stop:null},At.id):null,browserMenu:At?t.jsx(NQ,{status:zt,timezone:e,reload:xr.reload}):null,descriptors:S,grantedTools:a?Et.flatMap(V=>V.tools??[]):(fe==null?void 0:fe.tools)??[],...fe?{agentName:fe.name}:{},loading:d0,...!a&&fe?{face:t.jsx(vn,{agents:ft,id:fe.id,size:"xl"}),cardFace:t.jsx(vn,{agents:ft,id:fe.id,size:"sm"})}:{}}),p0=(N0=(k0=[...(P==null?void 0:P.messages)??[],...U].find(V=>V.role==="user"))==null?void 0:k0.blocks.find(V=>V.type==="text"))==null?void 0:N0.text.trim(),g0=p0?p0.split(`
131
- `)[0]:"New conversation",Pl=NX({lifetime:(P==null?void 0:P.lifetime)??null,startedAt:(P==null?void 0:P.startedAt)??null,now:Dt,timezone:e});return t.jsxs(t.Fragment,{children:[t.jsxs("section",{className:"wb-chat",ref:Me,style:{...h||sn===null?{}:{[Yv]:`${sn}px`},"--chat-text-scale":y/13},"data-sized":!h&&sn!==null?"true":void 0,"data-testid":"chat-column","data-dropping":ve||void 0,onDragEnter:V=>{kh(V)&&(V.preventDefault(),Ce.current+=1,be(!0))},onDragOver:V=>{kh(V)&&(V.preventDefault(),V.dataTransfer.dropEffect="copy")},onDragLeave:V=>{kh(V)&&(Ce.current=Math.max(0,Ce.current-1),Ce.current===0&&be(!1))},onDrop:V=>{var he;kh(V)&&(V.preventDefault(),Ce.current=0,be(!1),s&&((he=we.current)==null||he.addFiles(V.dataTransfer.files)))},children:[ve?t.jsx("div",{className:"wb-drop","aria-hidden":"true",children:t.jsxs("div",{className:"wb-drop-card",children:[t.jsx(OX,{}),t.jsx("strong",{children:"Drop to attach"}),t.jsx("span",{children:fe?`It goes with your next message to ${fe.name}`:"Pick an agent first"})]})}):null,t.jsxs("header",{className:"wb-chat-head","data-testid":"chat-head",...!a&&fe?fl(sc(fe)):{},children:[t.jsxs("div",{className:"wb-head-row",children:[a?t.jsx("span",{className:"wb-head-face","aria-hidden":"true",children:s0}):fe?t.jsx("a",{className:"wb-head-face",href:Qt(fe.id),"aria-label":`${fe.name}'s page`,children:t.jsx(vn,{agents:ft,id:fe.id})}):null,t.jsxs("div",{className:"wb-head-text",children:[a?t.jsx("span",{className:"wb-head-title",children:a.name}):t.jsx("span",{className:"wb-head-title",title:g0,children:g0}),t.jsx("span",{className:"wb-head-meta","data-tone":Pl.tone,title:a?`${Et.map(V=>V.name).join(", ")}. Coordinator: ${(fe==null?void 0:fe.name)??a.coordinator}.`:Pl.title,children:a?`${Et.map(V=>V.name).join(", ")} · ${Pl.text}`:fe?t.jsxs(t.Fragment,{children:[t.jsx("a",{className:"wb-head-name",href:Qt(fe.id),title:`${fe.name}'s page`,children:fe.name})," ",t.jsxs("span",{className:"wb-head-handle",children:["@",fe.handle]}),` · ${Pl.tone==="quiet"&&Pl.text==="New conversation"?`on ${j}`:Pl.text}`]}):"No agent"})]}),t.jsx("button",{className:"ui-icon-btn wb-head-more","data-size":"sm","aria-label":"New chat",title:"New chat",disabled:!s,onClick:()=>{Ze(!1),Dd()},children:t.jsx(ne,{name:"plus",size:16})}),t.jsx("button",{className:"ui-icon-btn wb-head-more","aria-label":"History",title:"Earlier conversations","aria-expanded":He,"data-open":He?"true":void 0,disabled:!s,onClick:()=>Ze(V=>!V),children:t.jsx(DX,{})}),h?t.jsxs("button",{className:"ui-btn",onClick:f,disabled:hn.length===0,children:["Canvas",hn.length>0?` (${hn.length})`:""]}):null,a?t.jsx(F1,{readingControls:b,disabled:!1,label:"More about this group",title:a.name,sub:T2(Et.map(V=>V.name)),face:s0,items:[{label:"Members",hint:`${a.members.length} agents · ${fe?`${fe.name} coordinates`:"no coordinator"}`,testId:"group-members",onSelect:()=>i==null?void 0:i("members")},{label:"Rename…",hint:"What this team is for",testId:"group-rename",onSelect:()=>i==null?void 0:i("rename")},"separator",{label:"Clear history…",hint:"Keeps the group and its members",testId:"group-clear",onSelect:()=>i==null?void 0:i("clear")},{label:"Delete group…",hint:"With its history; the agents stay",tone:"critical",testId:"group-delete",onSelect:()=>i==null?void 0:i("delete")}]}):t.jsx(F1,{readingControls:b,disabled:!s,label:"More about this agent",title:(fe==null?void 0:fe.name)??"Agent",...fe?{sub:`@${fe.handle}`,face:t.jsx(vn,{agents:ft,id:fe.id,size:"sm"})}:{},items:[{label:tt?"Close properties":"Properties",hint:"What this agent can do, on the Canvas",testId:"agent-properties",disabled:bt,onSelect:RL},...fe?[{label:"Set up",hint:"Identity, model and access",href:Qt(fe.id,"setup")},{label:"Open agent page",hint:"Profile, activity and setup",href:Qt(fe.id)}]:[]]})]}),u?t.jsx(qI,{agents:n,currentId:s,attention:c,onSelect:l,orientation:"horizontal",...Rl?{working:new Set([Rl])}:{}}):null]}),!a&&fe?t.jsx(tX,{agentId:fe.id},fe.id):null,He&&s?t.jsx(YJ,{agentId:s,...a?{groupId:a.id}:{},currentId:E,timezone:e,onNew:()=>{Ze(!1),Dd()},onSelect:V=>{if(V===E){Ze(!1);return}Ze(!1),O(null),L([]),se(!1),de(null),dt(null),vt(null),oe([]),R(V),v==null||v(s,V,!1)}}):null,s&&E?t.jsx(FJ,{agentId:s,conversationId:E},`${s}:${E}`):null,wt?t.jsx("div",{className:"wb-chat-notice",children:t.jsx(re,{message:wt})}):null,qt?t.jsx("div",{className:"wb-chat-notice","data-testid":"chat-notice",children:qt}):null,P!=null&&P.carriedOver?t.jsx(SX,{text:P.carriedOver,onDelete:async()=>{const V=P.conversationId;await nt.deleteCarryOver(V),O(he=>{if(!he||he.conversationId!==V)return he;const{carriedOver:Oe,...Ke}=he;return Ke})}},P.conversationId):null,t.jsx(rk,{timezone:e,mediaTools:A,messages:[...(P==null?void 0:P.messages)??[],...U],live:M,now:Dt,working:B,partial:D,agents:ft,...P!=null&&P.runs?{runs:P.runs}:{},...s&&E?{onContinue:()=>Od("continue",[])}:{},...a?{speakers:ft,coordinatorId:a.coordinator}:{},...gn?{workingAs:((S0=ft.find(V=>V.id===gn))==null?void 0:S0.name)??gn}:{},onOpenFile:n0,onReadAloud:(V,he)=>{gt(null),cm(he,E??void 0,V).then(Oe=>{Oe&&gt(Oe)})},onOpen:V=>{if(At){const Oe=A1([...(P==null?void 0:P.messages)??[],...U],V);if(Oe){pa(Oe),G(At.id),h&&(f==null||f());return}}const he=Il.current.find(Oe=>Oe.id===V||(Oe.versions??[]).some(Ke=>Ke.id===V));Ne.reopen(he?[V,zi(he)]:[V]),G(V),h&&(f==null||f())},...fe?{agentName:fe.name,agentId:fe.id}:{},...h0?{empty:h0}:{},emptyHint:a?`Give the team a task once; ${fe?fe.name:"the coordinator"} brings members in. @ addresses one of them.`:fe?`Nothing here yet. Ask ${fe.name} for something.`:"Loading agents…"}),t.jsx($2,{offers:EL,disabled:AL!==null,onTake:$L}),Di?t.jsx("div",{className:"wb-composer-blocked","data-testid":"group-problem","data-kind":Di.kind,children:t.jsx(Q,{tone:r0?"warning":void 0,role:"status",children:t.jsxs("span",{children:[Di.text," ",t.jsx("button",{type:"button",className:"wb-link-btn",onClick:()=>i==null?void 0:i("members"),children:Di.action})]})})}):null,gc?t.jsx("div",{className:"wb-composer-blocked","data-testid":"composer-blocked",children:t.jsxs(Q,{tone:"warning",role:"status",children:[gc," ",t.jsx("a",{href:ze(a0.section),children:a0.label})]})}):null,gc?null:P!=null&&P.question&&We?t.jsx(xk,{question:P.question,card:We,phone:h,container:Me.current,page:Qn,disabled:B,onSettled:()=>{E&&Ms(E),xr.reload()},onChoice:Wp},P.question.id):P!=null&&P.question&&q?t.jsx(S2,{card:q,disabled:l0||B,onAnswer:Wp,signIn:w1(P.question)?{question:P.question,card:w1(P.question),phone:h,container:Me.current,onSettled:()=>{E&&Ms(E),xr.reload()}}:void 0,site:((C0=zt==null?void 0:zt.needsOwner)==null?void 0:C0.site)??((A0=(E0=zt==null?void 0:zt.page)==null?void 0:E0.url)==null?void 0:A0.replace(/^https?:\/\/(www\.)?([^/]+).*$/,"$2"))},P.question.id):P!=null&&P.question?t.jsx(C2,{question:P.question,disabled:l0||B,onAnswer:Wp,onSkip:TL},P.question.id):null,!gc&&Td.length>0?t.jsx(y2,{approvals:Td,timezone:e,now:Dt,version:P,onDecided:c0,onSay:V=>Od(V,[]),onOpenFull:V=>{G(V),h&&(f==null||f())},phone:h,onSecretSet:dn,...($0=Qn==null?void 0:Qn.page)!=null&&$0.title?{pageTitle:Qn.page.title}:{},onSignInMyself:()=>{var he;const V=(he=Qn==null?void 0:Qn.session)==null?void 0:he.id;V&&T.browserControl("takeover",V).catch(()=>{}).finally(xr.reload)}}):null,gc||r0?null:t.jsxs("div",{hidden:Td.length>0&&!et||!!(P!=null&&P.question)&&!We,"data-testid":"composer-slot",children:[!a&&st?t.jsxs("section",{className:"wb-chat-reference","aria-label":"Story reference",children:[t.jsxs("div",{className:"wb-chat-reference-head",children:[t.jsxs("div",{children:[t.jsx("small",{children:"Asking about"}),t.jsx("p",{children:t.jsx("strong",{children:st.title})})]}),t.jsx("button",{type:"button",className:"ui-btn",onClick:()=>{s&&fS(s),_e(null)},children:"Remove reference"})]}),t.jsxs("details",{children:[t.jsx("summary",{children:"Context sent with your question"}),t.jsx("p",{children:st.text})]}),t.jsx("div",{className:"wb-starters",role:"group","aria-label":"Questions about this story",children:st.suggestions.map(V=>t.jsxs("button",{type:"button",className:"wb-starter",disabled:B||!s,title:"Send this question",onClick:()=>Od(V,[],!0),children:[V," ",t.jsx(ne,{name:"send",size:16})]},V))})]}):null,t.jsx(yk,{ref:we,disabled:!s,running:B,onSend:Od,onStop:o0,agentName:a?a.name:(fe==null?void 0:fe.name)??"the agent",draft:en,history:kL,threadKey:E??(a?`group:${a.id}`:s),model:a?null:(fe==null?void 0:fe.model)??null,chrome:tr,setupHref:a?null:fe?Qt(fe.id,"setup","brain"):null,thinking:SL,...!a&&fe&&kR(NR(fe,ct.data))?{onThinking:CL}:{},...a?{mentions:Et.map(V=>({id:V.id,handle:V.handle,name:V.name})),team:{agents:ft,selfId:""}}:s?{team:{agents:ft,selfId:s}}:{},onCommand:PL,onOpenFile:n0,conversationId:E??null,readAloud:rt,onReadAloud:Mt}),De?t.jsx("p",{className:"wb-voice-note",role:"status",children:De}):null]})]}),h?m?t.jsxs("div",{className:"wb-sheet",role:"dialog","aria-label":"Canvas",children:[t.jsxs("div",{className:"wb-sheet-head",children:[t.jsx("strong",{children:"Canvas"}),t.jsx("button",{className:"ui-btn",onClick:p,children:"Close"})]}),m0]}):null:t.jsxs(t.Fragment,{children:[t.jsx(TJ,{columnRef:Me,width:sn,onChange:ce}),m0]})]})}function MX(e,n){return Date.parse(n.lastMessageAt??n.startedAt??n.createdAt??"")-Date.parse(e.lastMessageAt??e.startedAt??e.createdAt??"")}function Kn(e){return typeof e=="string"&&e!==""?e:null}function Ga(e){return e instanceof pe||e instanceof Error?e.message:String(e)}function ox(e,n){var r;const s=(r=n.blocks.find(a=>a.type==="text"))==null?void 0:r.text.trim();if(!s)return!0;for(let a=e.messages.length-1;a>=0;a-=1){const i=e.messages[a];if(i.role!=="user")continue;const l=i.blocks.find(o=>o.type==="text");if(l)return l.text.trim()===s}return!1}function kh(e){var s;const n=(s=e.dataTransfer)==null?void 0:s.types;return!!(n&&Array.from(n).includes("Files"))}function OX(){return t.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 28 28","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M14 4v13M8.5 11.5 14 17l5.5-5.5"}),t.jsx("path",{d:"M5 19.5v2a2.5 2.5 0 0 0 2.5 2.5h13a2.5 2.5 0 0 0 2.5-2.5v-2"})]})}function DX(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M2.6 8a5.4 5.4 0 1 0 1.6-3.8"}),t.jsx("path",{d:"M2.4 2.6v2.6h2.6M8 5.2V8l2 1.3"})]})}function LX(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",fill:"currentColor",children:[t.jsx("circle",{cx:"8",cy:"3.4",r:"1.35"}),t.jsx("circle",{cx:"8",cy:"8",r:"1.35"}),t.jsx("circle",{cx:"8",cy:"12.6",r:"1.35"})]})}function F1({items:e,disabled:n,label:s,title:r,sub:a,face:i,readingControls:l}){const[o,c]=d.useState(!1),u=d.useRef(null);d.useEffect(()=>{if(!o)return;const m=p=>{u.current&&!u.current.contains(p.target)&&c(!1)},f=p=>{p.key==="Escape"&&c(!1)};return window.addEventListener("mousedown",m),window.addEventListener("keydown",f),()=>{window.removeEventListener("mousedown",m),window.removeEventListener("keydown",f)}},[o]);const h=m=>{const f=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"ui-menu-item-text",children:m.label}),m.hint?t.jsx("span",{className:"ui-menu-item-hint",children:m.hint}):null]});return m.href?t.jsx("a",{className:"ui-menu-item",role:"menuitem",href:m.href,"data-tone":m.tone,onClick:()=>c(!1),children:f},m.label):t.jsx("button",{className:"ui-menu-item",role:"menuitem","data-testid":m.testId,"data-tone":m.tone,disabled:m.disabled,onClick:()=>{var p;c(!1),(p=m.onSelect)==null||p.call(m)},children:f},m.label)};return t.jsxs("div",{className:"wb-head-menu",ref:u,children:[t.jsx("button",{className:"ui-icon-btn wb-head-more","data-testid":"chat-menu","aria-label":s,"aria-haspopup":"menu","aria-expanded":o,"data-open":o?"true":void 0,disabled:n,onClick:()=>c(m=>!m),children:t.jsx(LX,{})}),o?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"wb-head-menu-scrim","aria-hidden":"true",onClick:()=>c(!1)}),t.jsxs("div",{className:"ui-menu wb-head-menu-list",role:"menu","aria-label":r,children:[t.jsxs("div",{className:"wb-head-menu-head","aria-hidden":"true",children:[i,t.jsxs("span",{className:"wb-head-menu-heading",children:[t.jsx("span",{className:"wb-head-menu-title",children:r}),a?t.jsx("span",{className:"wb-head-menu-sub",children:a}):null]})]}),l,e.map((m,f)=>m==="separator"?t.jsx("div",{className:"ui-menu-sep",role:"separator"},`sep-${f}`):h(m)),t.jsx("button",{type:"button",className:"ui-btn wb-head-menu-cancel",onClick:()=>c(!1),children:"Cancel"})]})]}):null]})}let _1=!1;const FX=new Set(["missing","unconfigured","not-english"]);async function cm(e,n,s=null){const r=lP(s);try{const a=await nt.say({text:e,...n?{conversationId:n}:{}});return WS(r)&&await BW(a.audioUrl,a.mime,s),null}catch(a){WS(r)&&lc();const i=a instanceof pe&&a.detail&&typeof a.detail=="object"?a.detail.reason:void 0;return typeof i=="string"&&FX.has(i)&&(s!==null||!_1)?(_1=!0,a.message):null}}function _X(e,n,s){const r=bR(e);if(!r||r.rest==="")return null;const a=n.find(i=>i.roles.includes(Pr));return!a||a.id===s||a.handle.toLowerCase()!==r.handle?null:{agent:a,rest:r.rest}}let nr=null;function zX(e){if(Yh(e)!==null)return!1;const n=KI(e);return n!==Un&&n!==Aa}function UX({agent:e,agents:n,open:s,onOpenChange:r,navigate:a,timezone:i}){const l=d.useRef(null),o=d.useRef(s),c=`Ask ${e.name}`,[u,h]=d.useState(!1),[m,f]=d.useState(null);return d.useEffect(()=>{const p=x=>{const g=x.detail;!g||typeof g.text!="string"||(g.handled=!0,f({text:g.text,at:Date.now()}),r(!0))};return window.addEventListener(yv,p),()=>window.removeEventListener(yv,p)},[r]),d.useEffect(()=>{if(s||!u||!nr)return;const p=cp({url:nt.streamUrl(nr.conversationId),lastEventId:nr.lastEventId??null,onEvent:x=>{x.name==="run.finished"&&h(!1)}});return()=>p.close()},[s,u]),d.useEffect(()=>{const p=x=>{!x.altKey||x.ctrlKey||x.metaKey||x.code!=="Slash"||(x.preventDefault(),r(!s))};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[s,r]),d.useEffect(()=>{var p;o.current&&!s&&((p=l.current)==null||p.focus()),o.current=s},[s]),s?t.jsx(WX,{agent:e,agents:n,timezone:i,navigate:a,onClose:()=>r(!1),onBusy:h,prefill:m}):t.jsxs(Au,{children:[t.jsx($u,{asChild:!0,children:t.jsx("button",{ref:l,type:"button",className:"wb-ask-fab","data-busy":u?"true":void 0,"aria-label":c,onClick:()=>r(!0),children:t.jsx(BX,{busy:u})})}),t.jsx(Tu,{children:t.jsx(Ru,{className:"ui-tip",side:"left",sideOffset:8,children:c})})]})}function BX({busy:e}){const[n,s]=d.useState(!1);return n?t.jsx(Bu,{size:"lg"}):t.jsx(jd,{state:e?"working":"idle",className:"wb-ask-fab-face",onStillError:()=>s(!0)})}function WX({agent:e,agents:n,timezone:s,navigate:r,onClose:a,onBusy:i,prefill:l}){const o=d.useRef(null),[c,u]=d.useState(nr&&nr.agentId===e.id?nr.conversationId:null),[h,m]=d.useState(null),[f,p]=d.useState([]),[x,g]=d.useState([]),[w,v]=d.useState(null),[j,y]=d.useState(!1),[k,N]=d.useState(!1),[b,S]=d.useState(null),[C,A]=d.useState(l??null);d.useEffect(()=>{l&&A(l)},[l]);const[E,R]=d.useState(Date.now()),[P,O]=d.useState(aP),I=d.useRef(P);I.current=P;const[F,U]=d.useState(null),[L,M]=d.useState(new Map),z=d.useRef(null),D=d.useCallback(async Y=>{try{const X=await nt.conversation(Y);m(X),p(oe=>oe.filter(ve=>!HX(X,ve)))}catch{}},[]);d.useEffect(()=>{c&&D(c)},[c,D]),d.useEffect(()=>{if(!c)return;const Y=cp({url:nt.streamUrl(c),onEvent:X=>{var oe,ve;switch(X.name){case"run.started":z.current=null,y(!0),v(null);break;case"live":{const be=Zn(X.data.runId)??"",Ce=Number(X.data.turn??0),we=X.data.kind==="thinking"?"thinking":"text",He=Zn(X.data.text)??"",Ze=Date.now();if(we==="text"){const Se=z.current;z.current=Se&&Se.runId===be&&Se.turn===Ce?{...Se,text:Se.text+He}:{runId:be,turn:Ce,text:He}}v(Se=>{const Le=Se&&Se.runId===be&&Se.turn===Ce?Se:{runId:be,turn:Ce,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return we==="thinking"?{...Le,thinking:Le.thinking+He,thinkingStartedAt:Le.thinkingStartedAt??Ze}:{...Le,text:Le.text+He,textStartedAt:Le.textStartedAt??Ze}});break}case"live.snapshot":{const be=Zn(X.data.runId)??"",Ce=Number(X.data.turn??0),we=Zn(X.data.text)??"",He=Zn(X.data.thinking)??"",Ze=Number(X.data.startedAt??Date.now());z.current={runId:be,turn:Ce,text:we},y(!0),v({runId:be,turn:Ce,text:we,thinking:He,thinkingStartedAt:He?Ze:null,textStartedAt:we?Ze:null,settled:!1});break}case"live.settle":{const be=Zn(X.data.runId)??"",Ce=Number(X.data.turn??0);if(X.data.retracted===!0){((oe=z.current)==null?void 0:oe.runId)===be&&z.current.turn===Ce&&(z.current=null),v(we=>we&&we.runId===be&&we.turn===Ce?null:we);break}v(we=>we&&we.runId===be&&we.turn===Ce?{...we,settled:!0}:we);break}case"tool.called":{const be=Zn(X.data.toolUseId)??Zn(X.data.id),Ce=Zn(X.data.name)??Zn(X.data.tool)??"tool";be&&g(we=>[...we.filter(He=>He.toolUseId!==be),{toolUseId:be,name:Ce,startedAt:Date.now()}]);break}case"tool.result":{const be=Zn(X.data.toolUseId)??Zn(X.data.id);be&&g(Ce=>Ce.filter(we=>we.toolUseId!==be)),D(c);break}case"awaiting-approval":{const be=Zn(X.data.approvalId)??Zn(X.data.actionId),Ce=Zn(X.data.toolUseId);be&&Ce&&M(we=>new Map(we).set(Ce,be)),Ce&&g(we=>we.filter(He=>He.toolUseId!==Ce)),D(c).then(()=>v(we=>we!=null&&we.settled?null:we));break}case"message.appended":D(c).then(()=>v(be=>be!=null&&be.settled?null:be));break;case"run.finished":{y(!1),g([]),v(null);const be=Zn(X.data.message);S(be??null);const Ce=((ve=z.current)==null?void 0:ve.text.trim())??"";z.current=null,!be&&Ce!==""&&I.current&&cm(Ce,c).then(we=>{we&&U(we)}),D(c);break}}}});return()=>{nr&&nr.conversationId===c&&(nr.lastEventId=Y.lastEventId()),Y.close()}},[c,D]),d.useEffect(()=>{i(j||k)},[j,k,i]),d.useEffect(()=>{if(x.length===0)return;const Y=window.setInterval(()=>R(Date.now()),1e3);return()=>window.clearInterval(Y)},[x.length]);const K=(Y,X)=>{N(!0),S(null);const oe={id:`local-${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[...Y.trim()===""?[]:[{type:"text",text:Y}],...X.map(ve=>({type:"attachment",artifactId:ve.artifactId,filename:ve.filename,mime:ve.mime,kind:ve.kind,sizeBytes:ve.sizeBytes}))]};p(ve=>[...ve,oe]),(async()=>{try{const ve=c??(await nt.startConversation(e.id)).conversationId;ve!==c&&(nr={agentId:e.id,conversationId:ve},u(ve));const be=await nt.send(e.id,{conversationId:ve,text:Y,...X.length>0?{attachmentIds:X.map(Ce=>Ce.artifactId)}:{}});be.conversationId!==ve&&(nr={agentId:e.id,conversationId:be.conversationId},u(be.conversationId)),y(!0),D(be.conversationId)}catch(ve){p(be=>be.filter(Ce=>Ce.id!==oe.id)),S(ve instanceof pe?ve.message:String(ve)),A({text:Y,at:Date.now()})}finally{N(!1)}})()},B=(Y,X)=>{if(S(null),Y==="stop"){se();return}if(Y==="use"){const oe=X.replace(/^@/,"").toLowerCase(),ve=n.find(be=>be.handle.toLowerCase()===oe||be.id===oe);if(!ve){U(oe?`No agent called @${oe}.`:"Say who: /use @handle.");return}r(ut(ve.id));return}if(Y==="new"){const oe=n.find(ve=>ve.roles.includes(Pr));if(!oe){U("There is no agent here that makes agents.");return}X.trim()&&fd(oe.id,`I'd like a teammate for this: ${X.trim()}`),r(ut(oe.id));return}T.quiet(X).then(oe=>U(oe.text)).catch(oe=>S(oe instanceof Error?oe.message:String(oe)))},se=()=>{c&&nt.cancel(c).catch(Y=>S(String(Y))).finally(()=>y(!1))},W=()=>{var Y;nr=null,u(null),m(null),p([]),g([]),v(null),y(!1),S(null),M(new Map),(Y=o.current)==null||Y.focus()},xe=Y=>{O(Y),iP(Y),Y||lc()},me=c?ut(e.id,c):ut(e.id),ie=[...(h==null?void 0:h.messages)??[],...f],{openOffers:H,takingOffer:de,takeOffer:ge,answeringQuestion:Ue,answerQuestion:G,skipQuestion:ae}=A2({conversation:h,conversationId:c,agentId:e.id,now:E,refresh:D,onRunStarted:()=>y(!0),onError:(Y,X)=>{S(Y),X&&y(!1)},navigate:r}),J=d.useMemo(()=>wX(h,n,L),[h,n,L]),Ne=J.length===0?(h==null?void 0:h.question)??null:null,Ie=Y=>{c&&D(c),T.overview().catch(()=>{}),Y.state!=="pending"&&M(X=>new Map([...X].filter(([,oe])=>oe!==Y.id)))};return t.jsxs(SW,{title:e.name,label:`${e.name}, a quick chat`,onClose:a,onOpenAutoFocus:Y=>{var X;Y.preventDefault(),(X=o.current)==null||X.focus()},onCloseAutoFocus:Y=>Y.preventDefault(),actions:t.jsxs(t.Fragment,{children:[t.jsx($,{size:"sm",variant:"ghost",onClick:W,disabled:c===null&&f.length===0,children:"New"}),t.jsx(it,{size:"sm",variant:"ghost",href:me,onClick:Y=>{Y.preventDefault(),r(me)},children:"Open in Chat"})]}),children:[t.jsx("div",{className:"wb-ask-thread",children:t.jsx(rk,{messages:ie,live:x,now:E,working:j||k,partial:w,agents:n,agentName:e.name,agentId:e.id,onOpen:()=>r(me),onReadAloud:(Y,X)=>{U(null),cm(X,c??void 0,Y).then(oe=>{oe&&U(oe)})},emptyHint:`Ask ${e.name} anything, without leaving this page.`})}),t.jsxs("div",{className:"wb-ask-compose",children:[b?t.jsx(re,{message:b}):null,t.jsx($2,{offers:H,disabled:de!==null,onTake:ge}),J.length>0?t.jsx(y2,{approvals:J,timezone:s,now:E,version:h,onDecided:Ie,onSay:Y=>K(Y,[]),onOpenFull:()=>r(me)}):Ne&&tf(Ne)?t.jsx(xk,{question:Ne,card:tf(Ne),phone:!0,container:null,disabled:j,onSettled:()=>{c&&D(c)},onChoice:G},Ne.id):Ne&&Xv(Ne)?t.jsx(S2,{card:Xv(Ne),disabled:Ue||j,onAnswer:G},Ne.id):Ne?t.jsx(C2,{question:Ne,disabled:Ue||j,onAnswer:G,onSkip:ae},Ne.id):null,t.jsxs("div",{hidden:J.length>0||Ne!==null&&!tf(Ne),"data-testid":"composer-slot",children:[t.jsx(yk,{ref:o,disabled:k||!e.available,running:j,onSend:K,onStop:se,agentName:e.name,placeholder:`Message ${e.name}…`,draft:C,threadKey:`dock.${c??e.id}`,conversationId:c,readAloud:P,onReadAloud:xe,team:{agents:n,selfId:e.id},onCommand:B}),F?t.jsx("p",{className:"wb-voice-note",role:"status",children:F}):null]})]})]})}function Zn(e){return typeof e=="string"?e:null}function HX(e,n){var r;const s=(r=n.blocks)==null?void 0:r.find(a=>a.type==="text");return!s||s.type!=="text"?!1:e.messages.some(a=>a.role==="user"&&(a.blocks??[]).some(i=>i.type==="text"&&i.text.includes(s.text)))}const P2=3;function KX(e){if(e==="approval"||e==="question")return"accent";if(e==="watcher"||e==="reminder")return"warm";if(e==="failure")return"critical"}function VX(e,n){return e?n?"above-dock":"above-button":"corner"}function GX({placement:e,children:n}){return t.jsx("div",{className:"wb-toast-stack","data-placement":e,children:n})}function qX(e){return e.state==="shown"&&e.seenAt===null}function YX(e){const[n,s]=d.useState([]),r=d.useRef(new Set),a=d.useRef(new Set),i=d.useCallback(()=>{e&&T.notifications(20).then(({notifications:o})=>{const c=o.filter(u=>qX(u)&&!r.current.has(u.id));s(u=>{const h=new Set(u.map(f=>f.id)),m=c.filter(f=>!h.has(f.id));return m.length===0?u:[...u,...m].sort((f,p)=>p.createdAt.localeCompare(f.createdAt))})}).catch(()=>{})},[e]);d.useEffect(()=>{for(const o of n.slice(0,P2))a.current.has(o.id)||(a.current.add(o.id),T.notificationSeen(o.id).catch(()=>{}))},[n]);const l=d.useCallback(o=>{r.current.add(o),s(c=>c.filter(u=>u.id!==o))},[]);return{queue:n,refresh:i,dismiss:l}}function QX({queue:e,agents:n,navigate:s,onDismiss:r}){if(e.length===0)return null;const a=e.slice(0,P2),i=e.length-a.length;return t.jsxs("section",{className:"nt-toasts","aria-label":"Notifications",children:[a.map(l=>t.jsxs("div",{className:"ui-toast nt-toast","data-tone":KX(l.kind),role:"status",children:[l.agentId?t.jsx(vn,{agents:n,id:l.agentId,size:"sm"}):null,t.jsxs("div",{className:"nt-toast-main",children:[t.jsx("div",{className:"ui-toast-title",children:Pu(l)}),l.text?t.jsx("div",{className:"ui-toast-body nt-toast-line",children:JX(l.text)}):null,l.link?t.jsx("a",{className:"nt-toast-link",href:l.link,onClick:o=>{o.preventDefault(),r(l.id),s(l.link)},children:"See"}):null]}),t.jsx("button",{type:"button",className:"nt-toast-x","aria-label":`Dismiss ${Pu(l)}`,onClick:()=>r(l.id),children:"×"})]},l.id)),i>0?t.jsxs("p",{className:"nt-toasts-more",children:["and ",i," more"]}):null]})}function JX(e){var n;return((n=e.split(`
132
- `).find(s=>s.trim()!==""))==null?void 0:n.trim())??""}const XX=3e4,ZX=1e3;function eZ(e,n,s){const r=d.useRef(n);r.current=n;const a=d.useRef(s);a.current=s,d.useEffect(()=>{if(!e)return;let i=!1,l=-1/0,o=null,c=null,u=!0;const h=()=>document.visibilityState!=="hidden",m=v=>{var j;l=Date.now(),T.presence(v).catch(y=>{var k;y instanceof pe&&y.status===401&&(i=!0,(k=a.current)==null||k.call(a))}),v==="active"&&((j=r.current)==null||j.call(r))},f=v=>{if(i||(o=v,c!==null))return;const j=l+ZX-Date.now();if(j<=0){o=null,m(v);return}c=window.setTimeout(()=>{if(c=null,i||o===null)return;const y=o;o=null,m(y)},j)},p=()=>{u=!0,h()&&f("active")},x=()=>{u=!1,f("away")},g=()=>f(h()?"active":"away");h()&&f("active");const w=window.setInterval(()=>{h()&&u&&f("active")},XX);return window.addEventListener("focus",p),window.addEventListener("blur",x),document.addEventListener("visibilitychange",g),()=>{i=!0,window.clearInterval(w),c!==null&&window.clearTimeout(c),window.removeEventListener("focus",p),window.removeEventListener("blur",x),document.removeEventListener("visibilitychange",g)}},[e])}function tZ({agents:e,onClose:n,onCreated:s}){return LI(e)?t.jsx(nZ,{agents:vb(e),onClose:n,...s?{onCreated:s}:{}}):t.jsx(Ye,{title:"A new group",onClose:n,children:t.jsxs(Q,{children:["A group needs two agents. Make another one with ",M8(e)," first."]})})}function nZ({agents:e,onClose:n,onCreated:s}){var v,j;const[r,a]=d.useState(""),[i,l]=d.useState([]),[o,c]=d.useState(((v=e.find(y=>y.roles.includes(vd)))==null?void 0:v.id)??((j=e[0])==null?void 0:j.id)??""),[u,h]=d.useState(!1),[m,f]=d.useState(null),p=[...new Set([o,...i])].filter(Boolean),x=r.trim()!==""&&o!==""&&p.length>=2,g=y=>l(k=>k.includes(y)?k.filter(N=>N!==y):[...k,y]),w=async()=>{h(!0),f(null);try{s==null||s(await nt.createGroup({name:r.trim(),coordinator:o,members:p.filter(y=>y!==o)}))}catch(y){f(y instanceof pe?y.message:String(y))}finally{h(!1)}};return t.jsx(Ye,{title:"A new group",onClose:n,children:t.jsxs(ue,{children:[t.jsx(le,{label:"Name",hint:"What this team is for: Household finances, The move, Tax season.",children:t.jsx("input",{value:r,autoFocus:!0,maxLength:80,onChange:y=>a(y.target.value),placeholder:"Household finances"})}),t.jsx(le,{label:"Coordinator",hint:"Reads your request, brings members in, and answers for the group. Concierge by default.",children:t.jsx("select",{value:o,onChange:y=>c(y.target.value),children:e.map(y=>t.jsx("option",{value:y.id,children:y.name},y.id))})}),t.jsx(le,{label:"Members",hint:"The coordinator may ask the room's members in this room's conversations; each member keeps its own account, tools and approvals.",children:t.jsx("div",{className:"group-pick",role:"group","aria-label":"Members",children:e.filter(y=>y.id!==o).map(y=>t.jsxs("label",{className:"group-pick-row","data-on":i.includes(y.id)||void 0,children:[t.jsx("input",{type:"checkbox",checked:i.includes(y.id),onChange:()=>g(y.id)}),t.jsx(vn,{agents:e,id:y.id,size:"sm"}),t.jsxs("span",{className:"group-pick-text",children:[t.jsx("span",{className:"group-pick-name",children:y.name}),t.jsx("span",{className:"group-pick-desc",children:y.description})]})]},y.id))})}),t.jsx(Q,{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."}),m?t.jsx(Q,{tone:"critical",children:m}):null,t.jsxs(te,{align:"end",children:[t.jsx($,{onClick:n,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:!x||u,onClick:()=>void w(),children:u?"Creating…":"Create group"})]})]})})}const sZ=1e4;function Qu({title:e,body:n,duration:s,onUndo:r,onGone:a}){return t.jsxs(kz,{className:"ui-toast wb-undo-toast",duration:s,onOpenChange:i=>{i||a()},"data-testid":"undo-toast",children:[t.jsx("span",{className:"ui-toast-mark","aria-hidden":"true"}),t.jsxs("div",{className:"ui-toast-main",children:[t.jsx(Nz,{className:"ui-toast-title",children:e}),n?t.jsx(Sz,{className:"ui-toast-body",children:n}):null]}),r?t.jsx(Cz,{altText:"Undo",asChild:!0,children:t.jsx("button",{type:"button",className:"ui-btn wb-undo-toast-action","data-variant":"ghost","data-size":"sm",onClick:r,children:"Undo"})}):null]})}const z1=[{id:"",label:"All files"},{id:"produced",label:"Created by agents"},{id:"uploaded",label:"Uploaded by you"}],rZ=["","image","pdf","table","text","code","audio","video","archive","file"];function aZ({hash:e,timezone:n,navigate:s,agents:r}){var O;const a=W8(e),i=(a==null?void 0:a.artifactId)??null,l=(a==null?void 0:a.filters.origin)??"",o=(a==null?void 0:a.filters.family)??"",c=(a==null?void 0:a.filters.q)??"",[u,h]=d.useState(c);d.useEffect(()=>{h(c)},[c]);const m=(I,F=!1)=>s(ao(i,{q:c,origin:l,family:o,...I}),F);d.useEffect(()=>{if(u===c)return;const I=window.setTimeout(()=>m({q:u},!0),250);return()=>window.clearTimeout(I)},[u]);const[f,p]=d.useState(null),[x,g]=d.useState(null),[w,v]=d.useState(null),[j,y]=d.useState(!1),[k,N]=d.useState(!1),b=I=>{var F;return I?((F=r.find(U=>U.id===I))==null?void 0:F.name)??I:""},S=d.useRef(0);d.useEffect(()=>{const I=++S.current;p(null),g(null),y(!1),v(null),T.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{}}).then(F=>{S.current===I&&(p(F.entries),g(F.next))}).catch(F=>{S.current===I&&v(F instanceof pe?F.message:String(F))})},[c,l,o]);const C=()=>{if(!x||j)return;y(!0);const I=S.current;T.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{},cursor:x}).then(F=>{S.current===I&&(p(U=>{const L=new Set((U??[]).map(M=>M.id));return[...U??[],...F.entries.filter(M=>!L.has(M.id))]}),g(F.next))}).catch(F=>{S.current===I&&v(F instanceof pe?F.message:String(F))}).finally(()=>{S.current===I&&y(!1)})},A=(l?1:0)+(o?1:0),E=((O=z1.find(I=>I.id===l))==null?void 0:O.label)??l,R=t.jsxs(t.Fragment,{children:[f===null?t.jsx(Ee,{children:"Loading…"}):f.length===0?t.jsx(Ee,{children:"No file matches that."}):t.jsx(yt,{children:f.map(I=>t.jsx(ZI,{href:ao(I.id,{q:c,origin:l,family:o}),current:I.id===i,onClick:()=>s(ao(I.id,{q:c,origin:l,family:o})),lead:t.jsx("span",{className:"files-row-visual","data-family":I.family,children:I.family==="image"&&!I.deleted?t.jsx("img",{src:Dr(I.id),alt:"",loading:"lazy"}):t.jsx(Ab,{family:I.family})}),title:I.filename??"Untitled file",meta:t.jsx("span",{title:St(I.createdAt,n),children:Xe(I.createdAt)}),sub:`${I.caption&&I.origin==="produced"?`${I.caption} · `:""}${sl[I.family]} · ${Yn(I.sizeBytes)} · ${M2(I,b)}${iZ(I,b)}`},I.id))}),x?t.jsx("div",{className:"files-more",children:t.jsx($,{size:"sm",onClick:C,disabled:j,children:j?"Loading…":"Show more"})}):null]}),P=f!==null&&f.length===0&&!c&&!l&&!o&&!u;return t.jsxs("div",{className:"ui-page files","data-selected":i?"true":void 0,children:[t.jsxs("header",{className:"ui-page-head",children:[t.jsx("h2",{className:"ui-page-title",children:"Files"}),t.jsx("p",{className:"ui-page-lede",children:"What your agents made or were given."})]}),P?t.jsx(ps,{icon:"files",title:"Nothing here yet",children:"Drop a file into any conversation and it shows up here too."}):t.jsxs(t.Fragment,{children:[t.jsx(nP,{label:"Files",onSubmit:()=>m({q:u},!0),main:t.jsx("input",{type:"search",value:u,placeholder:"Search by name or label","aria-label":"Search files by name or label",onChange:I=>h(I.target.value)}),filters:t.jsxs(Vs,{dense:!0,children:[t.jsx(le,{label:"Origin",children:t.jsx("select",{value:l,"aria-label":"Origin",onChange:I=>m({origin:I.target.value}),children:z1.map(I=>t.jsx("option",{value:I.id,children:I.label},I.id))})}),t.jsx(le,{label:"Kind",children:t.jsx("select",{value:o,"aria-label":"Kind",onChange:I=>m({family:I.target.value}),children:rZ.map(I=>t.jsx("option",{value:I,children:I===""?"Any kind":sl[I]},I))})})]}),filtersOpen:k,onToggleFilters:()=>N(I=>!I),active:A,chips:A>0?t.jsxs(t.Fragment,{children:[l?t.jsx(Hf,{label:"Origin",onRemove:()=>m({origin:""}),children:E}):null,o?t.jsx(Hf,{label:"Kind",onRemove:()=>m({family:""}),children:sl[o]}):null]}):void 0}),t.jsx(re,{message:w}),t.jsx(eP,{className:"files-split",label:"Files",list:R,detail:i?t.jsx(lZ,{id:i,timezone:n,agents:r,navigate:s,onBack:()=>s(ao(null,{q:c,origin:l,family:o}))},i):void 0,empty:"Choose a file to see it here."})]})]})}function iZ(e,n){var a,i;const s=(a=e.context)!=null&&a.groupName?`in ${e.context.groupName}`:(i=e.context)!=null&&i.agentId&&e.context.agentId!==e.agentId?`with ${n(e.context.agentId)}`:"",r=e.contexts>1?`${e.contexts} conversations`:"";return[s,r].filter(Boolean).map(l=>` · ${l}`).join("")}function M2(e,n){return e.origin==="uploaded"?"You sent it":e.origin==="produced"?`Made by ${n(e.agentId)||"an agent"}`:e.agentId?`Saved by ${n(e.agentId)}`:"Origin unknown"}function lZ({id:e,timezone:n,agents:s,navigate:r,onBack:a}){const[i,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(null);d.useEffect(()=>{let j=!1;return l(null),h(null),T.libraryEntry(e).then(y=>{j||l(y)}).catch(y=>{j||h(y instanceof pe&&y.status===404?"This file is no longer in the library.":y instanceof pe?y.message:String(y))}),()=>{j=!0}},[e]);const m=j=>{var y;return j?((y=s.find(k=>k.id===j))==null?void 0:y.name)??j:""};if(u)return t.jsxs("div",{className:"files-detail-body",children:[t.jsx($,{size:"sm",onClick:a,className:"files-back",children:"Back to Files"}),t.jsx(Q,{tone:"critical",children:u})]});if(!i)return t.jsx("div",{className:"files-detail-body",children:t.jsx(Ee,{children:"Loading…"})});const{entry:f,contexts:p,contextsTotal:x,available:g}=i,w=f.filename??"Untitled file",v=()=>{c(!0),T.libraryEntry(e,p.length).then(j=>l(y=>y&&{...y,contexts:[...y.contexts,...j.contexts],contextsTotal:j.contextsTotal})).catch(()=>{}).finally(()=>c(!1))};return t.jsxs("div",{className:"files-detail-body",children:[t.jsx($,{size:"sm",onClick:a,className:"files-back",children:"Back to Files"}),t.jsxs("header",{className:"files-detail-head",children:[t.jsx("span",{className:"files-detail-mark","data-family":f.family,"aria-hidden":"true",children:t.jsx(Ab,{family:f.family})}),t.jsxs("div",{className:"files-detail-text",children:[t.jsx("h3",{className:"files-detail-name",children:w}),t.jsxs("p",{className:"files-detail-meta",children:[sl[f.family]," · ",Yn(f.sizeBytes)," · ",St(f.createdAt,n)]})]}),g?t.jsx(IM,{artifactId:f.id,filename:f.filename,mime:f.mime}):null]}),g?null:t.jsx(Q,{tone:"warning",children:"The file's bytes are no longer on this machine. What is known about it stays here; the download will not work."}),t.jsx(RM,{artifactId:f.id,filename:f.filename,mime:f.mime,family:f.family,available:g}),t.jsx(on,{items:[{label:"Origin",value:M2(f,m)},...f.caption&&f.origin==="produced"?[{label:"Filed under",value:f.caption}]:[],...f.agentId&&f.origin==="produced"?[{label:"Made by",value:t.jsxs("span",{className:"files-agent",children:[t.jsx(vn,{agents:s,id:f.agentId,size:"sm"}),m(f.agentId)]})}]:[],{label:"Type",value:t.jsx("span",{className:"mono",children:f.mime})},{label:"Id",value:t.jsx("span",{className:"mono",children:f.id})}]}),t.jsxs("section",{className:"files-conversations",children:[t.jsx("h4",{className:"ui-section-title",children:"Conversations"}),p.length===0?t.jsx("p",{className:"muted",children:"No conversation is recorded for this file. It may date from before the library kept track."}):t.jsx("ul",{className:"files-ctx",role:"list",children:p.map(j=>{const y=j.groupId?Hi(j.groupId,j.conversationId):ut(j.conversationAgentId,j.conversationId),k=j.groupId?j.groupName??"a group":m(j.conversationAgentId);return t.jsxs("li",{className:"files-ctx-row",children:[t.jsxs("span",{className:"files-ctx-text",children:[t.jsx("span",{children:j.groupId?`Group: ${k}`:k}),t.jsxs("span",{className:"muted",children:[" · ",j.kind==="produced"?`made by ${m(j.agentId)||"an agent"}`:j.kind==="reused"?"sent again":"sent by you"," · ",Xe(j.at)]})]}),t.jsx("a",{className:"ui-btn","data-size":"sm",href:y,onClick:N=>{N.preventDefault(),r(y)},children:"Open conversation"})]},`${j.conversationId}:${j.kind}`)})}),p.length<x?t.jsx(te,{align:"end",children:t.jsx($,{size:"sm",onClick:v,disabled:o,children:o?"Loading…":`Show ${x-p.length} more`})}):null]})]})}const O2="buddi.keepClose";let Lo=null;const ty=new Set;function ny(){for(const e of ty)e()}typeof window<"u"&&(window.addEventListener("beforeinstallprompt",e=>{e.preventDefault(),Lo=e,ny()}),window.addEventListener("appinstalled",()=>{Lo=null,bk(),ny()}));function Ep(){const[e,n]=d.useState(Lo);return d.useEffect(()=>{const s=()=>n(Lo);return ty.add(s),s(),()=>{ty.delete(s)}},[]),D2()?null:e}async function wk(e){try{await e.prompt();const n=await e.userChoice;Lo===e&&(Lo=null);const s=(n==null?void 0:n.outcome)==="accepted";return s&&bk(),ny(),s}catch{return!1}}function oZ(){try{return window.localStorage.getItem(O2)!==null}catch{return!1}}function bk(){try{window.localStorage.setItem(O2,"dismissed")}catch{}}function D2(){var e;try{return((e=window.matchMedia)==null?void 0:e.call(window,"(display-mode: standalone)").matches)??!1}catch{return!1}}function cZ(e=window.location.hostname){const n=e.replace(/^\[|\]$/g,"").toLowerCase();return n==="127.0.0.1"||n==="::1"||n==="localhost"}function kk(e=typeof navigator>"u"?"":navigator.userAgent){return/\bbuddi-mac\/\S+/.test(e)}function L2(e){return kk(e)?null:/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 uZ(e){return/Mac|iPhone|iPad/.test(e)}function dZ(){const e=Ep(),[n,s]=d.useState(oZ);if(n||!e)return null;const r=()=>{bk(),s(!0)};return t.jsxs("div",{className:"home-install",role:"region","aria-label":"Install buddi",children:[t.jsx("p",{className:"home-install-text",children:"Install buddi as an app, one click from your dock."}),t.jsxs(te,{align:"end",children:[t.jsx($,{size:"sm",variant:"ghost",onClick:r,children:"Not now"}),t.jsx($,{size:"sm",variant:"accent",onClick:()=>{wk(e).then(a=>{a&&s(!0)})},children:"Install"})]})]})}function hZ(){const e=Ep(),[n,s]=d.useState(void 0),[r]=d.useState(D2);if(d.useEffect(()=>{if(r)return;let o=!0;return T.session().then(c=>{o&&s(c.platform)},()=>{}),()=>{o=!1}},[r]),r)return null;const a=typeof navigator>"u"?"":navigator.userAgent,i=cZ(),l=e?null:L2(a);return t.jsx(ye,{title:"The dashboard as an app",panel:!0,foot:e?t.jsx(te,{align:"end",children:t.jsx($,{variant:"accent",onClick:()=>{wk(e)},children:"Install the app"})}):void 0,children:t.jsxs(ue,{children:[t.jsxs("p",{children:[e?"This browser can install buddi as an app: its own window, the Blob as its icon. ":l?`${l} `:null,"Or bookmark it with ",uZ(a)?"⌘D":"Ctrl+D",".",i?null:" This tailnet address installs as its own app, separate from the one on the machine buddi runs on."]}),i&&n==="darwin"?t.jsxs("p",{children:["On this Mac, ",t.jsx("span",{className:"mono",children:"buddi dashboard --install-app"})," puts a double-clickable app in ~/Applications that signs you in each time it opens (docs/cli.md, under Everyday)."]}):null]})})}const fZ={mail:"mail",money:"money",calendar:"calendar",people:"agents",file:"files",chart:"chart",bell:"bell",plug:"plug",key:"key",globe:"globe",sun:"sun",cloud:"cloud",news:"news"};function F2(e){return e&&fZ[e]||"plug"}const mZ=""+new URL("earth-2560-Ce3xs8Cb.webp",import.meta.url).href,pZ=""+new URL("earth-phone-BqC7cDhk.webp",import.meta.url).href,gZ="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=",sy={desk:mZ,phone:pZ,thumb:gZ},cx={author:"ActionVance",authorUrl:"https://unsplash.com/@actionvance",photoUrl:"https://unsplash.com/photos/outer-space-photography-of-earth-t7EL2iG3jMc"};function xZ(e){return e?sy.phone:sy.desk}const _2="backgrounds/",jZ=`${_2}manifest.json`,vZ=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,yZ=/^[\w.-]+\.jpg$/;function wZ(e){const n=e==null?void 0:e.pictures;if(!Array.isArray(n))return[];const s=[];for(const r of n){if(!r||typeof r!="object")continue;const a=r;if(typeof a.id!="string"||!vZ.test(a.id)||a.id.length>64||s.some(u=>u.id===a.id)||typeof a.title!="string"||!a.title.trim()||typeof a.credit!="string"||!a.credit.trim())continue;const i=u=>u===void 0?null:typeof u=="string"&&yZ.test(u)?`${_2}${u}`:void 0,l=i(a.landscape),o=i(a.portrait),c=i(a.thumb);l===void 0||o===void 0||c===void 0||!l&&!o||s.push({id:a.id,title:a.title.trim(),credit:a.credit.trim(),landscape:l,portrait:o,thumb:c})}return s}let Ic=null;function bZ(){if(!Ic){const e=(async()=>{const n=await fetch(jZ,{credentials:"same-origin"});if(!n.ok)throw new Error(`manifest ${n.status}`);return wZ(await n.json())})();Ic=e,e.catch(()=>{Ic===e&&(Ic=null)})}return Ic}function z2(e=!0){const[n,s]=d.useState(null);return d.useEffect(()=>{if(!e)return;let r=!0;return bZ().then(a=>{r&&s(a)},()=>{r&&s([])}),()=>{r=!1}},[e]),n}const ry="picture:";function kZ(e){return`${ry}${e}`}function U2(e){return typeof e=="string"&&e.startsWith(ry)?e.slice(ry.length):null}function NZ(e,n){return n?{src:e.portrait??e.landscape,fit:"cover"}:e.landscape?{src:e.landscape,fit:"cover"}:{src:e.portrait,fit:"contain"}}function SZ(e,n,s){return s&&n?n:e}function B2(){const[e,n]=d.useState(()=>new Date);return d.useEffect(()=>{let s;const r=()=>{s=setTimeout(()=>{n(new Date),r()},6e4-Date.now()%6e4+50)};return r(),()=>clearTimeout(s)},[]),e}const CZ=3,W2=8e3,EZ={hiddenHere:new Set,restoredHere:new Set};function AZ(e,n){return n.hiddenHere.has(e.id)?!0:e.hidden&&!n.restoredHere.has(e.id)}function $Z(e,n=EZ){return(e??[]).filter(s=>!AZ(s,n)).slice(0,CZ)}function H2(e){const[n,s]=d.useState(new Set),[r,a]=d.useState(new Set),[i,l]=d.useState(null),o=d.useRef(e);o.current=e;const c=(f,p)=>new Set(f).add(p),u=(f,p)=>{const x=new Set(f);return x.delete(p),x};return d.useEffect(()=>{if(!i)return;const f=window.setTimeout(()=>l(null),W2);return()=>window.clearTimeout(f)},[i]),{hiddenHere:n,restoredHere:r,justHidden:i,hide:(f,p)=>{s(x=>c(x,f.id)),a(x=>u(x,f.id)),l({glance:f,spot:p}),T.setGlanceHidden(f.id,!0).then(()=>{var x;return(x=o.current)==null?void 0:x.call(o)},()=>{s(x=>u(x,f.id)),l(x=>(x==null?void 0:x.glance.id)===f.id?null:x)})},undo:()=>{if(!i)return;const{glance:f}=i;l(null),s(p=>u(p,f.id)),a(p=>c(p,f.id)),T.setGlanceHidden(f.id,!1).then(()=>{var p;return(p=o.current)==null?void 0:p.call(o)},()=>{a(p=>u(p,f.id)),s(p=>c(p,f.id))})}}}function TZ({hiding:e,spot:n}){const s=e.justHidden;return!s||s.spot!==n?null:t.jsxs("span",{className:"home-glance-undo",role:"status","aria-live":"polite","data-spot":n,children:[t.jsxs("span",{children:[s.glance.title," hidden"]}),t.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),t.jsx($,{size:"sm",variant:"ghost",onClick:e.undo,children:"Undo"})]})}function RZ(e){return e.link?Tb(e.link.plugin,e.link.page,e.link.place):null}function IZ({glances:e,navigate:n,onChanged:s,except:r,hiding:a}){var u,h;const i=H2(s),l=a??i,o=$Z(e,l).filter(m=>!(r!=null&&r.has(m.id))),c=t.jsx(TZ,{hiding:l,spot:"line"});return o.length===0&&((u=l.justHidden)==null?void 0:u.spot)!=="line"?null:t.jsxs("span",{className:"home-glances",children:[((h=l.justHidden)==null?void 0:h.spot)==="line"?t.jsxs("span",{className:"home-glance",children:[t.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),c]}):null,o.map(m=>{const f=RZ(m),p=t.jsxs(t.Fragment,{children:[t.jsx(ne,{name:oc(m.icon),size:14}),t.jsx("span",{children:m.text})]});return t.jsxs("span",{className:"home-glance",children:[t.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),f?t.jsx("a",{className:"home-glance-text",href:f,onClick:x=>{x.preventDefault(),n(f)},children:p}):t.jsx("span",{className:"home-glance-text",children:p}),t.jsx("button",{type:"button",className:"home-glance-hide","aria-label":`Hide ${m.title} from Home`,title:"Hide from Home",onClick:()=>l.hide(m,"line"),children:t.jsx(ne,{name:"close",size:10})})]},m.id)})]})}function PZ(e){const a=Math.min(...e),l=Math.max(...e)-a||1,o=Math.max(e.length-1,1);return e.map((c,u)=>[u/o*100,2+(1-(c-a)/l)*(24-2*2)])}function MZ({points:e,className:n="wg-spark"}){const s=PZ(e).map(([r,a])=>`${r.toFixed(1)},${a.toFixed(1)}`);return t.jsxs("svg",{className:n,viewBox:"0 0 100 24",preserveAspectRatio:"none","aria-hidden":"true","data-testid":"spark",children:[t.jsx("path",{d:`M0,24 L${s.join(" L")} L100,24 Z`,fill:"currentColor",opacity:"0.12",stroke:"none"}),t.jsx("polyline",{points:s.join(" "),fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",vectorEffect:"non-scaling-stroke"})]})}const Wl=Math.PI/180;function OZ(e,n,s){const r=e.getTime()/864e5+24405875e-1-2451545,a=(357.529+.98560028*r)*Wl,l=(280.459+.98564736*r+1.915*Math.sin(a)+.02*Math.sin(2*a))*Wl,o=(23.439-36e-8*r)*Wl,c=Math.atan2(Math.cos(o)*Math.sin(l),Math.cos(l)),u=Math.asin(Math.sin(o)*Math.sin(l)),m=((18.697374558+24.06570982441908*r)*15+s)*Wl-c,f=n*Wl,p=Math.sin(f)*Math.sin(u)+Math.cos(f)*Math.cos(u)*Math.cos(m);return Math.asin(Math.max(-1,Math.min(1,p)))/Wl}function DZ(e,n,s){return OZ(e,n,s)>-.833}const LZ={small:2,medium:4},U1=new Map;function FZ(e){let n=U1.get(e);return n||(n=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hourCycle:"h23"}),U1.set(e,n)),n}function B1(e,n){const s=Object.fromEntries(FZ(n).formatToParts(e).map(l=>[l.type,l.value])),r=Number(s.hour)%24,a=Number(s.minute),i=Date.UTC(Number(s.year),Number(s.month)-1,Number(s.day),r,a);return{date:`${s.year}-${s.month}-${s.day}`,h:r,m:a,s:Number(s.second),offset:Math.round((i-Math.floor(e.getTime()/6e4)*6e4)/6e4)}}function _Z(e){if(e===0)return"Same time";const n=Math.floor(Math.abs(e)/60),s=Math.abs(e)%60;return`${e>0?"+":"−"}${n===0?`${s} min`:s===0?`${n} h`:`${n} h ${s}`}`}function zZ(e){if(e===0)return"same time";const n=Math.floor(Math.abs(e)/60),s=Math.abs(e)%60;return`${[n?`${n} hour${n===1?"":"s"}`:"",s?`${s} minute${s===1?"":"s"}`:""].filter(Boolean).join(" ")} ${e>0?"ahead":"behind"}`}function UZ(e,n,s,r,a){const i=B1(e,n.zone),l=B1(e,s),o=i.date===l.date?"Today":i.date>l.date?"Tomorrow":"Yesterday",c=i.offset-l.offset,u=dd(a?{timeFormat:a}:{},()=>Lt(e,n.zone)),h=r?"your time":zZ(c);return{...i,day:o,daytime:typeof n.latitude=="number"&&typeof n.longitude=="number"?DZ(e,n.latitude,n.longitude):i.h>=6&&i.h<18,offsetText:r?"Here":_Z(c),time:u,label:`${n.label}, ${u}${o==="Today"?"":` ${o.toLowerCase()}`}, ${h}`}}function BZ(e,n){const s=n?e.s:0;return{hour:(e.h%12+e.m/60+s/3600)*30,minute:(e.m+s/60)*6,second:n?e.s*6:null}}function WZ(e){const[n,s]=d.useState(()=>new Date);return d.useEffect(()=>{const r=e?1e3:6e4;let a;const i=()=>{a=setTimeout(()=>{s(new Date),i()},r-Date.now()%r+5)};return s(new Date),i(),()=>clearTimeout(a)},[e]),n}function W1({angle:e,length:n,width:s}){return t.jsxs("g",{className:"wg-clock-hand",transform:`rotate(${e} 50 50)`,children:[t.jsx("line",{x1:"50",y1:"50",x2:"50",y2:"42",strokeWidth:Math.min(s,1.8)}),t.jsx("line",{x1:"50",y1:"42",x2:"50",y2:50-n,strokeWidth:s})]})}const HZ=Array.from({length:12},(e,n)=>n);function KZ({time:e,seconds:n}){const s=BZ(e,n);return t.jsxs("svg",{className:"wg-clock-face",viewBox:"0 0 100 100","aria-hidden":"true",focusable:"false",children:[t.jsx("circle",{className:"wg-clock-dial",cx:"50",cy:"50",r:"49.25"}),HZ.map(r=>t.jsx("line",{className:"wg-clock-tick","data-major":r%3===0?"true":void 0,x1:"50",y1:r%3===0?6.5:7.5,x2:"50",y2:r%3===0?14:12,transform:`rotate(${r*30} 50 50)`},r)),t.jsx(W1,{angle:s.hour,length:24,width:4.6}),t.jsx(W1,{angle:s.minute,length:37,width:3.4}),s.second===null?null:t.jsx("g",{className:"wg-clock-second","data-testid":"second-hand",transform:`rotate(${s.second} 50 50)`,children:t.jsx("line",{x1:"50",y1:"59",x2:"50",y2:"9"})}),t.jsx("circle",{className:"wg-clock-pin",cx:"50",cy:"50",r:"2.8"}),s.second===null?null:t.jsx("circle",{className:"wg-clock-pin-second",cx:"50",cy:"50",r:"1.5"})]})}function VZ({body:e,size:n}){const s=ts("(prefers-reduced-motion: reduce)"),r=WZ(!s),a=e.clocks.slice(0,LZ[n]);return t.jsx("div",{className:"wg-clocks","data-count":a.length,children:a.map((i,l)=>{let o;try{o=UZ(r,i,e.home,l===0&&i.zone===e.home,e.time)}catch{return null}return t.jsxs("div",{className:"wg-clock","data-night":o.daytime?void 0:"true",role:"img","aria-label":o.label,title:`${i.label} · ${o.time}`,children:[t.jsx(KZ,{time:o,seconds:!s}),t.jsxs("span",{className:"wg-clock-words","aria-hidden":"true",children:[t.jsx("span",{className:"wg-clock-city",children:i.label}),t.jsx("span",{className:"wg-clock-day","data-today":o.day==="Today"?"true":void 0,children:o.day}),t.jsx("span",{className:"wg-clock-off",children:o.offsetText})]})]},`${i.label}-${i.zone}`)})})}const ux=3,GZ={small:4,medium:6};function dx({icon:e,size:n}){return e?t.jsx("span",{className:"wg-icon",children:t.jsx(ne,{name:oc(e),size:n})}):null}function Ap({body:e,size:n}){switch(e.kind){case"stat":return t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"wg-stat-now",children:[t.jsx(dx,{icon:e.icon,size:24}),t.jsx("span",{className:"wg-value",children:e.value})]}),e.caption?t.jsx("span",{className:"wg-caption",children:e.caption}):null,t.jsx("span",{className:"wg-push"}),e.trend?t.jsxs("span",{className:"wg-trend",children:[t.jsx(MZ,{points:e.trend.points,className:"wg-spark"}),e.trend.label?t.jsx("span",{children:e.trend.label}):null]}):null,e.foot?t.jsx("span",{className:"wg-foot",children:e.foot}):null]});case"list":{const s=e.rows.slice(0,Math.min(e.max??ux,n==="medium"?5:ux));return t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"wg-list","data-dense":s.length>ux?"true":void 0,"data-wrap":e.wrap?"true":void 0,children:s.map((r,a)=>t.jsxs("li",{className:"wg-row","data-marked":r.image?"true":void 0,children:[r.image?t.jsx(Cl,{className:"wg-mark",src:jI(r.image.src)?r.image.src:null,label:r.image.label??r.title}):null,t.jsxs("span",{className:"wg-row-text",children:[t.jsx("span",{className:"wg-row-title",children:r.title}),r.sub&&n==="medium"?t.jsx("span",{className:"wg-row-sub",children:r.sub}):null]}),r.side?t.jsx("span",{className:"wg-row-side","data-tone":r.tone,children:r.side}):null]},`${r.title}-${a}`))}),t.jsx("span",{className:"wg-push"}),e.more?t.jsx("span",{className:"wg-foot",children:e.more}):null]})}case"strip":return t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"wg-strip-head",children:[t.jsx(dx,{icon:e.icon,size:20}),e.value?t.jsx("span",{className:"wg-strip-value",children:e.value}):null,e.caption?t.jsx("span",{className:"wg-caption",children:e.caption}):null]}),t.jsx("span",{className:"wg-push"}),t.jsx("span",{className:"wg-strip",children:e.items.slice(0,GZ[n]).map((s,r)=>t.jsxs("span",{className:"wg-tile",children:[t.jsx("span",{className:"wg-tile-label",children:s.label}),t.jsx(dx,{icon:s.icon,size:18}),t.jsx("span",{className:"wg-tile-value",children:s.value})]},`${s.label}-${r}`))})]});case"progress":{const s=Math.round(Math.max(0,Math.min(1,e.ratio))*100);return t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"wg-value",children:e.value}),e.caption?t.jsx("span",{className:"wg-caption",children:e.caption}):null,t.jsx("span",{className:"wg-push"}),t.jsx("span",{className:"ui-meter",role:"meter","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":s,"aria-label":e.caption??e.value,children:t.jsx("span",{className:"ui-meter-fill","data-tone":e.tone,style:{inlineSize:`${s}%`}})}),e.foot?t.jsx("span",{className:"wg-foot",children:e.foot}):null]})}case"clocks":return t.jsx(VZ,{body:e,size:n});case"text":return t.jsxs("span",{className:"wg-text",children:[e.icon?t.jsx("span",{className:"wg-text-icon",children:t.jsx(ne,{name:oc(e.icon),size:18})}):null,t.jsxs("span",{className:"wg-text-words",children:[t.jsx("span",{className:"wg-text-main",children:e.text}),e.sub?t.jsx("span",{className:"wg-row-sub",children:e.sub}):null]})]})}}function ay({label:e,options:n,multiple:s,value:r,onChange:a}){const i=Array.isArray(r)?r:[r],l=c=>i.includes(c),o=c=>{if(!s)return a(c);a(l(c)?i.filter(u=>u!==c):[...i,c])};return t.jsx("div",{className:"wg-options",role:s?"group":"radiogroup","aria-label":e,children:n.map(c=>t.jsxs("button",{type:"button",role:s?"checkbox":"radio","aria-checked":l(c.value),className:"wg-option","data-on":l(c.value)?"true":void 0,onClick:()=>o(c.value),children:[t.jsx("span",{className:"wg-option-mark","data-multiple":s?"true":void 0,"aria-hidden":"true",children:s&&l(c.value)?t.jsx(ne,{name:"check",size:12}):null}),t.jsxs("span",{className:"wg-option-text",children:[t.jsx("span",{className:"wg-option-name",children:c.label}),c.sub?t.jsx("span",{className:"wg-option-sub",children:c.sub}):null]})]},c.value))})}function H1(e){return"place"in e?e.place:`town:${e.latitude.toFixed(3)},${e.longitude.toFixed(3)}`}function qZ(e){var n;return{label:((n=e.name.split(",")[0])==null?void 0:n.trim())||e.name,name:e.name,latitude:e.latitude,longitude:e.longitude,timezone:e.timezone??null}}function YZ({field:e,value:n,places:s,onChange:r}){const a=Array.isArray(n)?n:n?[n]:[],[i,l]=d.useState(""),[o,c]=d.useState([]),[u,h]=d.useState(!1),[m,f]=d.useState(null),p=new Map;for(const k of s)p.set(k.id,{value:{place:k.id},label:k.label,sub:k.name});for(const k of[...a,...o])"place"in k||p.set(H1(k),{value:k,label:k.label,sub:k.name});const x=[...p.entries()].map(([k,N])=>({value:k,label:N.label,sub:N.sub})),g=a.map(H1),w=s.find(k=>k.id==="home"||k.label.toLowerCase()==="home")??s[0],v=e.multiple?g:g[0]??(w==null?void 0:w.id)??"",j=k=>{const N=(Array.isArray(k)?k:[k]).map(b=>{var S;return(S=p.get(b))==null?void 0:S.value}).filter(b=>!!b);r(e.multiple?N.slice(-3):N[0]??null)},y=()=>{const k=i.trim();k.length<2||(h(!0),f(null),T.findPlace(k).then(({found:N})=>{const b=N.slice(0,3).map(qZ);c(b),b.length===0?f(`Nothing found for “${k}”.`):e.multiple?r([...a,b[0]].slice(-3)):r(b[0])}).catch(()=>f("The place finder didn’t answer. Try again in a moment.")).finally(()=>h(!1)))};return t.jsxs("div",{className:"wg-field-stack",children:[x.length>0?t.jsx(ay,{label:e.label,options:x,multiple:e.multiple,value:v,onChange:j}):null,t.jsxs("div",{className:"wg-find",children:[t.jsx("input",{value:i,placeholder:"Find a town: Tokyo","aria-label":`Find a town for ${e.label}`,onChange:k=>l(k.target.value),onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),y())}}),t.jsx($,{size:"sm",disabled:u||i.trim().length<2,onClick:y,children:u?"Finding…":"Find"})]}),m?t.jsx("span",{className:"ui-field-hint",children:m}):null]})}function QZ({field:e,value:n,sheet:s,onChange:r}){var i;let a;switch(e.kind){case"select":{const l=e.options??[],o=typeof n=="string"?n:e.default??((i=l[0])==null?void 0:i.value)??"",c=l.length>0&&l.length<=3&&l.every(u=>u.label.length<=14);a=l.length===0?t.jsx("span",{className:"ui-field-hint",children:"Nothing to choose from yet."}):c?t.jsx(cn,{label:e.label,options:l,value:o,onChange:r}):t.jsx(ay,{label:e.label,options:l,value:o,onChange:r});break}case"multiselect":{const l=e.options??[];a=l.length===0?t.jsx("span",{className:"ui-field-hint",children:"Nothing to choose from yet."}):t.jsx(ay,{label:e.label,options:l,multiple:!0,value:Array.isArray(n)?n:e.default??[],onChange:r});break}case"toggle":return t.jsxs("div",{className:"wg-field",children:[t.jsxs("label",{className:"wg-toggle",children:[t.jsx("input",{type:"checkbox",checked:typeof n=="boolean"?n:e.default??!1,onChange:l=>r(l.target.checked)}),t.jsx("span",{children:e.label})]}),e.hint?t.jsx("span",{className:"ui-field-hint",children:e.hint}):null]});case"text":a=t.jsx("input",{"aria-label":e.label,value:typeof n=="string"?n:e.default??"",maxLength:e.max??60,placeholder:e.placeholder,onChange:l=>r(l.target.value)});break;case"place":a=t.jsx(YZ,{field:e,value:n,places:s.places,onChange:r});break;case"timeFormat":a=t.jsx(cn,{label:e.label,options:[{value:"profile",label:jR()},{value:"12h",label:"12-hour"},{value:"24h",label:"24-hour"}],value:n==="12h"||n==="24h"?n:"profile",onChange:r});break}return t.jsxs("div",{className:"wg-field",role:"group","aria-label":e.label,children:[t.jsx("span",{className:"wg-field-label",children:e.label}),a,e.hint?t.jsx("span",{className:"ui-field-hint",children:e.hint}):null]})}function JZ({info:e,placement:n,surface:s,view:r,label:a}){var u;const i=s==="lock",l=((u=r==null?void 0:r.body)==null?void 0:u.kind)==="text",o=i&&(l||n.size==="small")?"small":n.size,c=r?r.body?e.sensitive?t.jsxs("span",{className:"wg-state",children:[t.jsx("span",{className:"wg-mask","aria-hidden":"true",children:"••••"}),t.jsx("span",{className:"wg-state-sub",children:"Hidden on this screen."})]}):t.jsx(Ap,{body:r.body,size:o}):t.jsx("span",{className:"wg-state",children:t.jsx("span",{className:"wg-state-sub",children:r.state==="error"?`Couldn't load this${r.error?`: ${r.error}`:""}.`:"Nothing to show right now."})}):t.jsxs("span",{className:"wg-skel-body","aria-hidden":"true",children:[t.jsx("span",{className:"wg-skel","data-w":"half"}),t.jsx("span",{className:"wg-skel","data-w":"third"}),t.jsx("span",{className:"wg-push"}),t.jsx("span",{className:"wg-skel"})]});return t.jsx("div",{className:"wg-preview","data-surface":s,"aria-label":`Preview of ${a}`,role:"img",children:t.jsxs("div",{className:"wg-frame","data-size":o,"data-variant":i?"compact":void 0,"data-kind":r!=null&&r.body&&!e.sensitive?r.body.kind:void 0,"aria-hidden":"true",children:[i?null:t.jsx("div",{className:"wg-head",children:t.jsx("span",{className:"wg-title",children:a})}),t.jsx("div",{className:"wg-body",children:c}),i?t.jsx("span",{className:"wg-compact-title",children:a}):null]})})}function K2({info:e,placement:n,surface:s,onSave:r,onRemove:a,onClose:i}){const l=je(()=>T.widgetSettings(e.id),[e.id]),[o,c]=d.useState(n.settings??{}),[u,h]=d.useState(null),[m,f]=d.useState(n.label??e.title),[p,x]=d.useState(!1),[g,w]=d.useState(null),v=d.useRef(0),j=d.useMemo(()=>JSON.stringify(o),[o]);d.useEffect(()=>{const N=++v.current,b=window.setTimeout(()=>{T.previewWidget({widget:e.id,size:n.size,settings:o}).then(S=>{N===v.current&&(h(S.view),f(S.label))}).catch(()=>{N===v.current&&h({state:"error",error:"the preview could not be made"})})},u?250:0);return()=>window.clearTimeout(b)},[j,e.id,n.size]);const y=()=>{x(!0),w(null),r(o).then(N=>{x(!1),N||w("Couldn’t keep these settings. Try again.")})},k=s==="lock"?"the lock screen":"Home";return t.jsx(Ye,{title:m,onClose:i,foot:t.jsxs(te,{children:[t.jsxs($,{variant:"danger-ghost",onClick:a,children:["Remove from ",s==="lock"?"lock screen":"Home"]}),t.jsx(ht,{}),t.jsx($,{variant:"ghost",onClick:i,children:"Cancel"}),t.jsx($,{variant:"accent",onClick:y,disabled:p||!l.data,children:p?"Saving…":"Save"})]}),children:t.jsxs("div",{className:"wg-sheet",children:[t.jsx(JZ,{info:e,placement:n,surface:s,view:u,label:m}),t.jsxs("p",{className:"wg-sheet-note",children:[e.builtIn?"Built in":`From the ${e.plugin} plugin`," · on ",k,". These settings are this one’s own",s==="lock"?"; Home keeps its own":"","."]}),t.jsx(re,{message:g??(l.error?"Couldn’t read this widget’s settings.":null)}),l.data?l.data.fields.map(N=>t.jsx(QZ,{field:N,value:o[N.key],sheet:l.data,onChange:b=>c({...o,[N.key]:b})},N.key)):l.error?null:t.jsx("p",{className:"wg-sheet-note","aria-busy":"true",children:"Reading its choices…"})]})})}const XZ=6e4,V2="buddi.clock",G2="buddi.home.widgets";function ZZ(){try{const e=Number(window.localStorage.getItem(G2));return Number.isInteger(e)&&e>0?Math.min(e,6):0}catch{return 0}}function eee(e){try{window.localStorage.setItem(G2,String(e))}catch{}}function q2(){const e=new Uint8Array(4);return crypto.getRandomValues(e),`w-${Array.from(e,n=>n.toString(16).padStart(2,"0")).join("")}`}function Y2(e,n){const s=d.useRef(n);s.current=n,d.useEffect(()=>{if(!e)return;let r;const a=()=>{r=setTimeout(()=>{s.current(),a()},6e4-Date.now()%6e4+1e3)};return a(),()=>clearTimeout(r)},[e])}function tee(){const e=je(()=>T.widgets("home"),[],XZ),[n,s]=d.useState(void 0);return d.useEffect(()=>{e.data&&s(e.data)},[e.data]),d.useEffect(()=>{n&&eee(n.home.length)},[n]),Y2((n==null?void 0:n.home.some(r=>{var a,i;return r.widget===V2&&((i=(a=n.views[r.key])==null?void 0:a.body)==null?void 0:i.kind)!=="clocks"}))??!1,e.reload),{answer:n,error:e.error,apply:s,reload:e.reload}}function nee(e){return new Set(((e==null?void 0:e.home)??[]).map(n=>n.widget))}function see(e){const[n,s]=d.useState(!1);return d.useEffect(()=>{if(!e||!n)return;const r=()=>{(document.visibilityState==="hidden"||!document.hasFocus())&&s(!1)};return document.addEventListener("visibilitychange",r),window.addEventListener("blur",r),()=>{document.removeEventListener("visibilitychange",r),window.removeEventListener("blur",r)}},[e,n]),[n,s]}const Q2=(e,n)=>e.label??(n==null?void 0:n.title)??e.widget;function ree({info:e,placement:n,view:s,index:r,count:a,editing:i,navigate:l,act:o,onRetry:c,retrying:u,drag:h}){var S;const[m,f]=see(e.sensitive===!0),p=(s==null?void 0:s.state)??"error",x=e.sensitive===!0&&!m,g=e.link?Tb(e.link.plugin,e.link.page,e.link.place):null,w=g!==null&&!i&&p!=="error"&&!x,v=n.size==="small"?"medium":"small",j=Q2(n,e),y=n.key,k=(((S=e.settings)==null?void 0:S.length)??0)>0;let N;!s&&i?N=t.jsx("span",{className:"wg-state",children:t.jsx("span",{className:"wg-state-sub",children:"Fills in when you press Done."})}):p==="error"||!s?N=t.jsxs("span",{className:"wg-state",children:[t.jsx("span",{className:"wg-state-title",children:"Couldn't load this."}),s!=null&&s.error?t.jsxs("span",{className:"wg-state-sub",children:[aee(s.error),"."]}):null,i?null:t.jsx($,{size:"sm",onClick:c,disabled:u,children:u?"Trying…":"Try again"})]}):p==="empty"||!s.body?N=t.jsx("span",{className:"wg-state",children:t.jsx("span",{className:"wg-state-sub",children:"Nothing to show right now."})}):x?N=t.jsxs("span",{className:"wg-state",children:[t.jsx("span",{className:"wg-mask","aria-hidden":"true",children:"••••"}),t.jsx("span",{className:"wg-state-sub",children:"Hidden on this screen."}),i?null:t.jsx($,{size:"sm",onClick:()=>f(!0),children:"Show"})]}):N=t.jsx(Ap,{body:s.body,size:n.size});const b=C=>{C.dataTransfer.effectAllowed="move",C.dataTransfer.setData("text/plain",y),h.start(y)};return t.jsxs("div",{className:"wg-frame",role:"group","aria-label":j,"data-id":e.id,"data-key":y,"data-size":n.size,"data-kind":s!=null&&s.body&&!x&&p!=="error"?s.body.kind:void 0,"data-state":p==="ok"?void 0:p,"data-linked":w?"true":void 0,"data-dragging":h.dragging===y?"true":void 0,"data-over":h.over===y&&h.dragging!==y?"true":void 0,draggable:i?!0:void 0,onDragStart:i?b:void 0,onDragOver:i?C=>{h.dragging&&(C.preventDefault(),h.enter(y))}:void 0,onDrop:i?C=>{C.preventDefault(),h.drop(y)}:void 0,onDragEnd:i?()=>h.end():void 0,children:[t.jsxs("div",{className:"wg-head",children:[i?t.jsx("button",{type:"button",className:"ui-icon-btn wg-grip","data-size":"sm","data-grip":y,"aria-label":`Move ${j}, position ${r+1} of ${a}: arrow keys`,title:"Drag, or use the arrow keys",onKeyDown:C=>{(C.key==="ArrowLeft"||C.key==="ArrowUp")&&(C.preventDefault(),o("earlier")),(C.key==="ArrowRight"||C.key==="ArrowDown")&&(C.preventDefault(),o("later"))},children:t.jsx(ne,{name:"grip",size:14})}):null,t.jsx("span",{className:"wg-title",children:j}),p==="stale"?t.jsx("span",{className:"wg-stale",title:s!=null&&s.error?`Couldn't refresh: ${s.error}.`:void 0,children:s!=null&&s.updatedAt?`${Hw(s.updatedAt)} old`:"Not current"}):null,i&&k?t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Settings for ${j}`,title:"Settings",onClick:()=>o("settings"),children:t.jsx(ne,{name:"settings",size:14})}):null,i?t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Take ${j} off Home`,title:"Take off Home",onClick:()=>o("hide"),children:t.jsx(ne,{name:"close",size:12})}):t.jsx("span",{className:"wg-more",children:t.jsx(rs,{label:`More for ${j}`,note:s!=null&&s.updatedAt?`${e.builtIn?"Built in":e.plugin} · ${Xe(s.updatedAt)}`:e.builtIn?"Built in":e.plugin,items:[k?{label:"Settings…",onSelect:()=>o("settings")}:null,r>0?{label:"Move earlier",onSelect:()=>o("earlier")}:null,r<a-1?{label:"Move later",onSelect:()=>o("later")}:null,e.sizes.includes(v)?{label:`Make it ${v}`,onSelect:()=>o("size",v)}:null,{label:"Edit widgets",onSelect:()=>o("edit")},"separator",{label:"Hide from Home",onSelect:()=>o("hide")}]})})]}),w?t.jsx("a",{className:"wg-body",href:g,onClick:C=>{C.preventDefault(),l(g)},children:N}):t.jsx("div",{className:"wg-body",children:N}),i?t.jsxs("div",{className:"wg-edit-bar",children:[e.sizes.length>1?t.jsx("span",{className:"ui-segment",role:"radiogroup","aria-label":`Size of ${j}`,children:["small","medium"].filter(C=>e.sizes.includes(C)).map(C=>t.jsx("button",{type:"button",className:"ui-tab",role:"radio","aria-checked":n.size===C,onClick:()=>o("size",C),children:C==="small"?"Small":"Medium"},C))}):t.jsx("span",{className:"wg-edit-note",children:e.sizes[0]==="small"?"Small only":"Medium only"}),t.jsxs("span",{className:"wg-edit-move",children:[t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","data-move":`${y}:earlier`,"aria-label":`Move ${j} earlier`,title:"Move earlier",disabled:r===0,onClick:()=>o("earlier"),children:t.jsx(ne,{name:"chevron-left"})}),t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","data-move":`${y}:later`,"aria-label":`Move ${j} later`,title:"Move later",disabled:r===a-1,onClick:()=>o("later"),children:t.jsx(ne,{name:"chevron-right"})})]})]}):null]})}function aee(e){const n=e.replace(/\.$/,"");return n.charAt(0).toUpperCase()+n.slice(1)}function iee({widgets:e,navigate:n}){const{answer:s,apply:r}=e,[a,i]=d.useState(!1),[l,o]=d.useState([]),[c,u]=d.useState(null),[h,m]=d.useState(""),[f,p]=d.useState(null),[x,g]=d.useState(!1),[w,v]=d.useState(null),[j,y]=d.useState(null),[k,N]=d.useState(null),[b,S]=d.useState(null),[C,A]=d.useState(new Set),[E]=d.useState(ZZ),R=d.useRef(null);if(d.useEffect(()=>{if(!c)return;const G=window.setTimeout(()=>u(null),W2);return()=>window.clearTimeout(G)},[c]),d.useEffect(()=>{var ae;const G=R.current;G&&(R.current=null,(ae=document.querySelector(`[data-grip="${CSS.escape(G)}"], [data-move="${CSS.escape(G)}"]`))==null||ae.focus())}),!s)return E===0?null:t.jsxs("section",{className:"ui-section wg-section","aria-label":"Widgets","aria-busy":"true",children:[t.jsx("div",{className:"ui-section-head",children:t.jsx("h3",{className:"ui-section-title",children:"Widgets"})}),t.jsx("div",{className:"wg-grid",children:Array.from({length:E},(G,ae)=>t.jsxs("div",{className:"wg-frame","data-state":"loading","aria-hidden":"true",children:[t.jsx("div",{className:"wg-head"}),t.jsxs("span",{className:"wg-skel-body",children:[t.jsx("span",{className:"wg-skel","data-w":"half"}),t.jsx("span",{className:"wg-skel","data-w":"third"}),t.jsx("span",{className:"wg-push"}),t.jsx("span",{className:"wg-skel"})]})]},ae))})]});if(s.available.every(G=>G.builtIn)&&s.home.length===0)return null;const P=new Map(s.available.map(G=>[G.id,G])),O=a?l:s.home,I=G=>Q2(G,P.get(G.widget)),F=(G,ae)=>(p(null),r({...ae,home:G,arranged:{...ae.arranged,home:!0}}),T.saveWidgets("home",G).then(J=>(r(J),!0),J=>(r(ae),p(`Couldn't save your widgets: ${J instanceof Error?J.message:String(J)}`),!1))),U=(G,ae,J)=>{if(J<0||J>=G.length||ae===J)return null;const Ne=G.slice(),[Ie]=Ne.splice(ae,1);return Ne.splice(J,0,Ie),m(`${I(Ie)}, position ${J+1} of ${Ne.length}.`),Ne},L=()=>{o(s.home),A(new Set),u(null),p(null),i(!0)},M=G=>(ae,J)=>{const Ne=O[G];if(ae==="edit"){L();return}if(ae==="settings"){S(Ne.key);return}if(a){if(ae==="earlier"||ae==="later"){const Ie=U(l,G,ae==="earlier"?G-1:G+1);if(Ie){const Y=document.activeElement;R.current=(Y==null?void 0:Y.dataset.grip)??(Y==null?void 0:Y.dataset.move)??null,o(Ie)}}ae==="size"&&J&&(o(l.map((Ie,Y)=>Y===G?{...Ie,size:J}:Ie)),A(new Set([...C,Ne.key]))),ae==="hide"&&(o(l.filter((Ie,Y)=>Y!==G)),m(`${I(Ne)} taken off.`));return}if(ae==="earlier"||ae==="later"){const Ie=U(s.home,G,ae==="earlier"?G-1:G+1);Ie&&F(Ie,s)}ae==="size"&&J&&F(s.home.map((Ie,Y)=>Y===G?{...Ie,size:J}:Ie),s),ae==="hide"&&F(s.home.filter((Ie,Y)=>Y!==G),s).then(Ie=>{Ie&&u({item:Ne,at:G})})},z=()=>{if(!c)return;const G=s.home.filter(ae=>ae.key!==c.item.key);G.splice(Math.min(c.at,G.length),0,c.item),u(null),F(G,s)},D=()=>{g(!0),F(l,s).then(G=>{g(!1),G&&(i(!1),m("Widgets saved."))})},K=G=>{v(G),T.refreshWidget(G).then(r,()=>{}).finally(()=>v(null))},B=G=>{var Ne;const ae={key:q2(),widget:G.id,size:G.sizes[0],settings:{}},J=l.some(Ie=>Ie.widget===G.id);o([...l,ae]),m(`${G.title} added.`),J&&(((Ne=G.settings)==null?void 0:Ne.length)??0)>0&&S(ae.key)},se=(G,ae)=>a?(o(l.map(J=>{if(J.key!==G)return J;const{label:Ne,...Ie}=J;return{...Ie,settings:ae}})),A(new Set([...C,G])),S(null),Promise.resolve(!0)):F(s.home.map(J=>J.key===G?{...J,settings:ae}:J),s).then(J=>(J&&(S(null),m("Settings saved.")),J)),W=G=>{S(null);const ae=O.findIndex(J=>J.key===G);ae>=0&&M(ae)("hide")},xe={dragging:j,over:k,start:G=>y(G),enter:G=>{k!==G&&N(G)},end:()=>{y(null),N(null)},drop:G=>{const ae=l.findIndex(Ie=>Ie.key===j),J=l.findIndex(Ie=>Ie.key===G),Ne=ae>=0&&J>=0?U(l,ae,J):null;Ne&&o(Ne),y(null),N(null)}},me=c?t.jsxs("div",{className:"wg-undo","data-size":c.item.size,role:"status","aria-live":"polite",children:[t.jsxs("span",{children:[I(c.item)," hidden"]}),t.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),t.jsx($,{size:"sm",variant:"ghost",onClick:z,children:"Undo"})]},"undo"):null,ie=[];O.forEach((G,ae)=>{const J=P.get(G.widget);if(!J)return;c&&!a&&c.at===ae&&ie.push(me);const Ne=a&&(C.has(G.key)||!s.home.some(Ie=>Ie.key===G.key));ie.push(t.jsx(ree,{info:J,placement:G,view:Ne?void 0:s.views[G.key],index:ae,count:O.length,editing:a,navigate:n,act:M(ae),onRetry:()=>K(G.key),retrying:w===G.key,drag:xe},G.key))}),c&&!a&&c.at>=O.length&&ie.push(me);const H=s.available.filter(G=>!G.builtIn),de=H.length-2,ge=b?O.find(G=>G.key===b):void 0,Ue=ge?P.get(ge.widget):void 0;return t.jsxs("section",{className:"ui-section wg-section","aria-label":"Widgets",children:[t.jsxs("div",{className:"ui-section-head",children:[t.jsx("h3",{className:"ui-section-title",children:"Widgets"}),a?t.jsxs("div",{className:"ui-toolbar","data-align":"end",children:[t.jsx($,{size:"sm",variant:"ghost",onClick:()=>{i(!1),o([])},disabled:x,children:"Cancel"}),t.jsx($,{size:"sm",variant:"accent",onClick:D,disabled:x,children:x?"Saving…":"Done"})]}):O.length>0?t.jsx("div",{className:"ui-toolbar","data-align":"end",children:t.jsx($,{size:"sm",variant:"ghost",onClick:L,children:"Edit"})}):null]}),t.jsx("p",{className:"sr-only","aria-live":"polite",children:h}),f?t.jsx(Q,{tone:"critical",role:"alert",children:f}):null,O.length===0&&!a&&!c?t.jsxs("div",{className:"wg-empty",children:[t.jsxs("div",{className:"wg-empty-text",children:[t.jsx("p",{className:"wg-empty-title",children:"Add widgets to Home"}),t.jsxs("p",{className:"wg-empty-sub",children:["Small live panels from your plugins:"," ",(H.length>0?H:s.available).slice(0,2).map(G=>G.title).join(", "),de>0?` and ${de} more`:"","."]})]}),t.jsx($,{size:"sm",variant:"accent",onClick:L,children:"Add widgets"})]}):ie.length>0?t.jsx("div",{className:"wg-grid","data-editing":a?"true":void 0,children:ie}):null,a?t.jsxs("div",{className:"wg-gallery",role:"region","aria-label":"Add widgets",children:[t.jsxs("div",{className:"wg-gallery-head",children:[t.jsx("p",{className:"wg-gallery-title",children:"Add widgets"}),t.jsx("a",{className:"wg-gallery-aside",href:ze("lock"),onClick:G=>{G.preventDefault(),n(ze("lock"))},children:"The lock screen has its own pick"})]}),t.jsx("ul",{className:"wg-gallery-list",children:s.available.map(G=>{var X;const ae=l.filter(oe=>oe.widget===G.id).length,J=(((X=G.settings)==null?void 0:X.length)??0)>0,Ne=G.builtIn?"Built in":`${G.plugin} plugin`,Ie=G.sizes.length>1?"small or medium":`${G.sizes[0]} only`,Y=ae>1?` · ${ae} on Home`:ae===1&&J?" · on Home":"";return t.jsxs("li",{className:"wg-add",children:[t.jsxs("span",{className:"wg-add-text",children:[t.jsx("span",{className:"wg-add-title",children:G.title}),t.jsxs("span",{className:"wg-add-sub",children:[Ne," · ",Ie,G.sensitive?" · hidden until you show it":"",Y]})]}),ae>0&&!J?t.jsx("span",{className:"wg-add-note",children:"On Home"}):t.jsxs($,{size:"sm","aria-label":`${ae>0?"Add another":"Add"} ${G.title}`,onClick:()=>B(G),children:[t.jsx(ne,{name:"plus",size:12})," ",ae>0?"Add another":"Add"]})]},G.id)})}),t.jsxs("a",{className:"wg-gallery-more",href:cv("widgets"),onClick:G=>{G.preventDefault(),n(cv("widgets"))},children:[t.jsx(ne,{name:"plug",size:14}),t.jsx("span",{children:"Get more widgets"}),t.jsx("span",{className:"wg-gallery-more-sub",children:"from plugins on withbuddi.com"})]})]}):null,ge&&Ue?t.jsx(K2,{info:Ue,placement:ge,surface:"home",onClose:()=>S(null),onSave:G=>se(ge.key,G),onRemove:()=>W(ge.key)}):null]})}function Nk(e,n){return!e||e==="image"&&!n?"earth":e}const lee="(max-width: 720px)",oee="(orientation: portrait)",cee=3e4,uee=5e3,dee={1:"a minute",5:"5 minutes",15:"15 minutes",60:"an hour"};function hx(e,n){return{time:Lt(e,n),day:Ks(e,n,{weekday:!0})}}function $p(e,n){return e?dd({timeFormat:e.time,...e.date==="off"?{}:{dateFormat:e.date}},n):n()}function hee(e,n,s=new Date,r){return $p(r,()=>fee(e,n,s))}function fee(e,n,s){if(!e.lockedAt)return"Locked";const r=new Date(e.lockedAt),i=hx(r,n).day===hx(s,n).day?hx(r,n).time:Ym(r,n);return e.reason==="idle"?`Locked after ${e.delayMinutes?dee[e.delayMinutes]??`${e.delayMinutes} minutes`:"a while"} away, at ${i}`:e.reason==="start"?`Locked since this session began, at ${i}`:`Locked by you at ${i}`}function mee(e){const n=()=>e?Math.max(0,Math.ceil((Date.parse(e)-Date.now())/1e3)):0,[s,r]=d.useState(n);return d.useEffect(()=>{if(r(n()),!e)return;const a=window.setInterval(()=>r(n()),500);return()=>window.clearInterval(a)},[e]),s}const pee=e=>`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`;function K1({size:e=16}){return t.jsx(ne,{name:"lock",size:e})}function J2({size:e=16}){return t.jsx("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M3 8h9.6M8.6 4l4 4-4 4"})})}function gee(){return t.jsxs("svg",{width:18,height:18,viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M7.6 5h8a1.4 1.4 0 0 1 1.4 1.4v7.2A1.4 1.4 0 0 1 15.6 15h-8L3 10z"}),t.jsx("path",{d:"M9.6 8l4 4M13.6 8l-4 4"})]})}function V1({text:e}){const[n,s]=d.useState(!1),r=()=>{var a;(a=navigator.clipboard)==null||a.writeText(e).then(()=>{s(!0),window.setTimeout(()=>s(!1),1600)}).catch(()=>{})};return t.jsxs("div",{className:"so-cmd",children:[t.jsx("code",{className:"so-cmd-text",children:e}),t.jsx($,{size:"sm",onClick:r,children:n?"Copied":"Copy"})]})}function xee({onClose:e}){return t.jsx(Gt,{title:"Forgot your PIN?",onClose:e,foot:t.jsx($,{variant:"accent",onClick:e,children:"Done"}),children:t.jsxs("div",{className:"lk-forgot",children:[t.jsx("p",{className:"lk-forgot-text",children:"The PIN covers this dashboard; it doesn’t sign you in. On the computer buddi runs on, run one of these:"}),t.jsxs("div",{className:"lk-forgot-way",children:[t.jsx(V1,{text:"buddi dashboard --unlock"}),t.jsx("p",{className:"lk-forgot-hint",children:"Opens buddi without the PIN, once. It prints a link for your other devices too, good for five minutes."})]}),t.jsxs("div",{className:"lk-forgot-way",children:[t.jsx(V1,{text:"buddi dashboard --remove-pin"}),t.jsx("p",{className:"lk-forgot-hint",children:"Removes the PIN on every device. Set a new one in Settings → Lock screen."})]})]})})}function jee({approvals:e,needs:n,after:s,onPick:r}){const a=[];return e>0&&a.push({key:"approvals",n:e,text:e===1?"approval waiting":"approvals waiting"}),n>0&&a.push({key:"needs",n,text:e>0?n===1?"more needs you":"more need you":n===1?"thing needs you":"things need you"}),a.length===0?null:t.jsx("ul",{className:"lk-badges","aria-label":"Waiting for you",children:a.map(i=>t.jsx("li",{children:t.jsxs("button",{type:"button",className:"lk-chip","data-kind":i.key,"aria-pressed":s===i.key,disabled:!r,title:r?i.key==="needs"?"Open Needs you once unlocked":"Open your approvals once unlocked":void 0,onClick:()=>r==null?void 0:r(s===i.key?null:i.key),children:[t.jsx("span",{className:"ui-badge","aria-hidden":"true",children:i.n>99?"99+":i.n}),t.jsxs("span",{children:[t.jsxs("span",{className:"lk-sr",children:[i.n," "]}),i.text]})]})},i.key))})}function vee(e,n){const s=n?2:4;let r=0,a=0;for(const i of e){const l=Math.min(i==="medium"?2:1,s);a+l>s&&(a=0),a+=l,r=Math.max(r,a)}return r}function yee(e){return e.filter(n=>!(n.view.body.kind==="text"&&!n.view.body.sub))}function G1(e,n){const s=Object.fromEntries(new Intl.DateTimeFormat("en-CA",{timeZone:n,year:"numeric",month:"2-digit",day:"2-digit"}).formatToParts(e).map(r=>[r.type,r.value]));return Math.round(Date.UTC(Number(s.year),Number(s.month)-1,Number(s.day))/864e5)}function wee(e,n,s,r=new Date){if(e.state!=="stale"||!e.updatedAt)return null;const a=new Date(e.updatedAt);return Number.isNaN(a.getTime())?null:`from ${$p(s,()=>{const i=Lt(a,n),l=G1(r,n)-G1(a,n);return l<=0?i:l===1?`yesterday ${i}`:l<7?`${new Intl.DateTimeFormat("en-US",{timeZone:n,weekday:"short"}).format(a)} ${i}`:`${Ks(a,n,{compact:!0})} ${i}`})}`}function bee({widgets:e,phone:n,timezone:s,clockView:r,now:a}){const i=yee(e);if(i.length===0)return null;const l=i.map(c=>({w:c,size:n||c.view.body.kind==="text"?"small":c.size})),o=vee(l.map(({size:c})=>c),n);return t.jsx("div",{className:"lk-widgets",children:t.jsx("div",{className:"lk-grid","data-phone":n?"true":void 0,"data-cols":o,children:l.map(({w:c,size:u})=>{const h=wee(c.view,s,r,a);return t.jsxs("div",{className:"wg-frame","data-variant":"compact","data-size":u,"data-kind":c.view.body.kind,"data-stale":h?"true":void 0,role:"group","aria-label":c.title,children:[t.jsx("div",{className:"wg-body",children:t.jsx(Ap,{body:c.view.body,size:u})}),t.jsxs("span",{className:"wg-compact-title",children:[c.title,h?t.jsxs("span",{className:"wg-compact-from",children:[" · ",h]}):null]})]},c.key??c.id)})})})}function kee({text:e}){const n=/^(.*?)[\s\u202f]?([AaPp]\.?[Mm]\.?)$/.exec(e);return t.jsx("p",{className:"lk-time","aria-label":e,children:n?t.jsxs(t.Fragment,{children:[n[1],t.jsx("span",{className:"lk-ampm","aria-hidden":"true",children:n[2]})]}):e})}function q1(e,n){const s=Object.fromEntries(new Intl.DateTimeFormat("en-US",{timeZone:n,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(e).map(a=>[a.type,a.value])),r=Date.UTC(Number(s.year),Number(s.month)-1,Number(s.day),Number(s.hour)%24,Number(s.minute));return Math.round((r-Math.floor(e.getTime()/6e4)*6e4)/6e4)}function Nee(e,n,s){try{const r=q1(e,n)-q1(e,s);if(r===0)return"Same time";const a=u=>new Intl.DateTimeFormat("en-CA",{timeZone:u,year:"numeric",month:"2-digit",day:"2-digit"}).format(e),i=a(n)!==a(s)?r>0?", tomorrow":", yesterday":"",l=Math.floor(Math.abs(r)/60),o=Math.abs(r)%60;return`${o===0?`${l} h`:l===0?`${o} min`:`${l} h ${o}`} ${r>0?"ahead":"behind"}${i}`}catch{return""}}function See(e,n,s){const r=s??{date:null,zone:null};return $p(s,()=>({time:Lt(e,n),day:r.date==="off"?null:Ks(e,n,{weekday:!0}),zone:r.zone?{label:r.zone.label,time:Lt(e,r.zone.timezone),offset:Nee(e,r.zone.timezone,n)}:null}))}function Cee({background:e,image:n,imagePortrait:s,phone:r,portrait:a}){const i=U2(e),l=z2(i!==null);if(e==="earth"||i!==null&&l!==null&&!l.some(c=>c.id===i))return t.jsxs("div",{className:"lk-ground","aria-hidden":"true",children:[t.jsx("img",{className:"lk-photo","data-earth":"true",src:xZ(r),alt:"",decoding:"async"}),t.jsx("div",{className:"lk-scrim"})]});if(e==="image"&&n)return t.jsxs("div",{className:"lk-ground","aria-hidden":"true",children:[t.jsx("img",{className:"lk-photo",src:SZ(n,s,a),alt:""}),t.jsx("div",{className:"lk-scrim"})]});const o=i!==null?l==null?void 0:l.find(c=>c.id===i):void 0;if(o){const{src:c,fit:u}=NZ(o,a);return t.jsxs("div",{className:u==="contain"?"ui-fieldbg lk-ground":"lk-ground","data-fit":u,"aria-hidden":"true",children:[t.jsx("img",{className:"lk-photo","data-fit":u,"data-picture":o.id,src:c,alt:"",decoding:"async"}),t.jsx("div",{className:"lk-scrim"})]})}return t.jsx("div",{className:"ui-fieldbg lk-ground","aria-hidden":"true"})}function X2({data:e,now:n,phone:s,portrait:r=s,pad:a=!1,after:i,onPick:l}){const o=(e==null?void 0:e.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,c=See(n,o,e==null?void 0:e.clockView),u=Nk(e==null?void 0:e.background,e==null?void 0:e.image),h=(e==null?void 0:e.focus)??null,m=h?$p(e==null?void 0:e.clockView,()=>s?Tee(Ju(h,o,n)):`${Qi[h.mode]} ${Ju(h,o,n)}`):"";return t.jsxs(t.Fragment,{children:[t.jsx(Cee,{background:u,image:e==null?void 0:e.image,imagePortrait:e==null?void 0:e.imagePortrait,phone:s,portrait:r}),t.jsxs("header",{className:"lk-top",children:[t.jsxs("span",{className:"lk-brand",children:[t.jsx(Bu,{size:"sm"}),t.jsx("span",{children:"buddi"})]}),t.jsx("span",{className:"lk-top-spacer"}),h?t.jsxs("span",{className:"lk-chip","data-kind":"focus",children:[t.jsx(ne,{name:"moon",size:13}),t.jsx("span",{children:m})]}):null]}),t.jsxs("div",{className:"lk-main",children:[c.day?t.jsx("p",{className:"lk-date",children:c.day}):null,t.jsx(kee,{text:c.time}),c.zone?t.jsxs("p",{className:"lk-zone",children:[t.jsx("span",{className:"lk-zone-name",children:c.zone.label}),t.jsx("span",{className:"lk-zone-time",children:c.zone.time}),c.zone.offset?t.jsx("span",{className:"lk-zone-off",children:c.zone.offset}):null]}):null,a||!e?null:t.jsx(jee,{approvals:e.approvals,needs:e.needs??0,after:i??null,...l?{onPick:l}:{}}),a||!e?null:t.jsx(bee,{widgets:e.widgets,phone:s,timezone:o,clockView:e.clockView,now:n})]})]})}function Eee({value:e,disabled:n,onDigit:s,onBack:r,onSubmit:a}){return t.jsxs("div",{className:"lk-pad",role:"group","aria-label":"PIN pad",children:[["1","2","3","4","5","6","7","8","9"].map(i=>t.jsx("button",{type:"button",className:"lk-key",disabled:n,onClick:()=>s(i),children:i},i)),t.jsx("button",{type:"button",className:"lk-key","data-kind":"quiet","aria-label":"Delete",disabled:n||e.length===0,onClick:r,children:t.jsx(gee,{})}),t.jsx("button",{type:"button",className:"lk-key",disabled:n,onClick:()=>s("0"),children:"0"}),t.jsx("button",{type:"button",className:"lk-key","data-kind":"go","aria-label":"Unlock",disabled:n||e.length<4,onClick:a,children:t.jsx(J2,{size:18})})]})}function Aee({initial:e,onUnlocked:n}){const s=ts(lee),r=ts(oee)||s,a=B2(),[i,l]=d.useState(null),o=i??e,[c,u]=d.useState(""),[h,m]=d.useState(null),[f,p]=d.useState((e==null?void 0:e.waitUntil)??null),[x,g]=d.useState(!1),[w,v]=d.useState(!1),[j,y]=d.useState(!1),[k,N]=d.useState(!1),[b,S]=d.useState(!1),[C,A]=d.useState(null),E=d.useRef(null),R=mee(f),P=R>0,O=d.useRef(n),I=d.useRef(C);I.current=C,O.current=ie=>{I.current&&(window.location.hash=Io),n(ie)};const F=ie=>{var H;A(ie),s&&ie?N(!0):(H=E.current)==null||H.focus()},U=d.useRef(0),L=d.useRef(0),M=d.useRef(0),z=d.useCallback(()=>{const ie=++U.current;M.current=Date.now(),T.lockScreen().then(H=>{ie<L.current||(L.current=ie,v(!1),l(H),p(H.waitUntil),H.locked||O.current(H))}).catch(H=>{H instanceof pe&&H.status===401?window.location.reload():Ff(H)&&v(!0)})},[]);d.useEffect(()=>{z();const ie=window.setInterval(z,cee),H=()=>{document.visibilityState==="visible"&&z()},de=()=>{Date.now()-M.current>=uee&&z()};return document.addEventListener("visibilitychange",H),document.addEventListener("resume",de),window.addEventListener("focus",de),window.addEventListener("pageshow",de),window.addEventListener("online",z),()=>{window.clearInterval(ie),document.removeEventListener("visibilitychange",H),document.removeEventListener("resume",de),window.removeEventListener("focus",de),window.removeEventListener("pageshow",de),window.removeEventListener("online",z)}},[z]),Y2((i==null?void 0:i.widgets.some(ie=>ie.id===V2&&ie.view.body.kind!=="clocks"))??!1,z),d.useEffect(()=>{var ie;!s&&!j&&!P&&((ie=E.current)==null||ie.focus())},[s,j,P,x]),d.useEffect(()=>{!P&&f&&m(null)},[P,f]);const D=ie=>{ie==null||ie.preventDefault(),!(x||P||c.length<4)&&(g(!0),T.unlock(c).then(H=>{var ge;if(u(""),H.locked){g(!1);return}if((ge=window.matchMedia)==null?void 0:ge.call(window,"(prefers-reduced-motion: reduce)").matches){O.current(H);return}S(!0),window.setTimeout(()=>O.current(H),240)}).catch(H=>{if(g(!1),u(""),!(H instanceof pe))return m("Something went wrong. Try again.");const de=H.detail??{};if(H.status===403||H.status===429){de.waitUntil&&p(de.waitUntil);const ge=de.triesLeft??0;m(de.waitUntil?"That PIN isn’t right.":`That PIN isn’t right. ${ge} ${ge===1?"try":"tries"} left.`)}else Ff(H)?m("buddi isn’t answering. Try again in a moment."):m(H.message)}))},K=(i==null?void 0:i.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,B=Nk(o==null?void 0:o.background,o==null?void 0:o.image),se=(i==null?void 0:i.owner)??null,W=w?{tone:"critical",text:"buddi isn’t answering. The lock stays until it does."}:P?{tone:"critical",text:`Too many tries. Try again in ${pee(R)}.`}:h?{tone:"critical",text:h}:C?{tone:void 0,text:C==="needs"?"Unlock to open what needs you.":"Unlock to open your approvals."}:{tone:void 0,text:o?hee(o,K,a,i==null?void 0:i.clockView):"Locked"},xe=ie=>ie.replace(/\D/g,"").slice(0,8),me=t.jsxs("div",{className:"lk-who",children:[t.jsx("span",{className:"lk-face","aria-hidden":"true",children:(se??"You").slice(0,1).toUpperCase()}),se?t.jsx("span",{className:"lk-owner",children:se}):null]});return t.jsxs("div",{className:"lk","data-bg":B,"data-phone":s?"true":void 0,"data-view":k?"pad":"glance","data-opening":b?"true":void 0,role:"dialog","aria-modal":"true","aria-label":"buddi is locked","data-testid":"lock-screen",children:[t.jsx(X2,{data:i??(o?{...Ree(o)}:null),now:a,phone:s,portrait:r,pad:k,after:C,onPick:F}),t.jsx("footer",{className:"lk-unlock",children:s&&!k?t.jsxs(t.Fragment,{children:[t.jsxs("button",{type:"button",className:"lk-chip lk-enter",onClick:()=>N(!0),children:[t.jsx(K1,{size:14}),t.jsx("span",{children:"Enter PIN"})]}),t.jsx("p",{className:"lk-note","data-tone":W.tone,role:"status","aria-live":"polite",children:W.text})]}):s?t.jsxs(t.Fragment,{children:[me,t.jsx("div",{className:"lk-dots","aria-hidden":"true","data-state":h?"wrong":void 0,children:c.length===0?t.jsx("span",{className:"lk-dots-empty",children:"Enter your PIN"}):Array.from(c).map((ie,H)=>t.jsx("span",{className:"lk-dot"},H))}),t.jsx("span",{className:"lk-sr","aria-live":"polite",children:c.length===1?"1 digit entered":`${c.length} digits entered`}),t.jsx("p",{className:"lk-note","data-tone":W.tone,role:"status","aria-live":"polite",children:W.text}),t.jsx(Eee,{value:c,disabled:P||x,onDigit:ie=>{m(null),u(xe(c+ie))},onBack:()=>u(c.slice(0,-1)),onSubmit:()=>D()}),t.jsxs("div",{className:"lk-pad-foot",children:[t.jsx("button",{type:"button",className:"lk-link",onClick:()=>y(!0),children:"Forgot PIN?"}),t.jsx("button",{type:"button",className:"lk-link",onClick:()=>{N(!1),u(""),m(null)},children:"Cancel"})]})]}):t.jsxs(t.Fragment,{children:[me,t.jsxs("form",{className:"lk-pin","data-state":h&&!P?"wrong":P?"wait":void 0,onSubmit:D,children:[t.jsx(K1,{size:15}),t.jsx("input",{ref:E,type:"password",inputMode:"numeric",autoComplete:"off",maxLength:8,"aria-label":"PIN","aria-describedby":"lk-note",placeholder:P?"Wait a moment":"Enter your PIN",disabled:P,value:c,onChange:ie=>{m(null),u(xe(ie.target.value))}}),t.jsx("button",{type:"submit",className:"lk-go","aria-label":"Unlock",disabled:x||P||c.length<4,children:t.jsx(J2,{})})]}),t.jsx("p",{className:"lk-note",id:"lk-note","data-tone":W.tone,role:"status","aria-live":"polite",children:W.text}),t.jsx("button",{type:"button",className:"lk-link",onClick:()=>y(!0),children:"Forgot PIN?"})]})}),i!=null&&i.version?t.jsx("p",{className:"lk-version",children:$ee(i.version)}):null,j?t.jsx(xee,{onClose:()=>y(!1)}):null]})}function $ee(e){return`buddi ${e.current}${e.updateAvailable?" · update ready":""}`}function Tee(e){return e.slice(0,1).toUpperCase()+e.slice(1)}function Ree(e){return{timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,background:e.background,image:e.image,imagePortrait:e.imagePortrait??null,focus:null,approvals:0,needs:0,widgets:[]}}const Iee=3e4,Pee=5e3,Mee="buddi-lock",iy="buddi-locked",Oee=ze("lock");function Z2(){var n;const e=navigator;return/mac|iphone|ipad|ipod/i.test(((n=e.userAgentData)==null?void 0:n.platform)||navigator.platform||navigator.userAgent)}function Dee(e=Z2()){return e?"⌃⌘L":"Ctrl+Alt+L"}function Lee(e,n=Z2()){return!(e.code==="KeyL"||e.key.toLowerCase()==="l")||!e.ctrlKey||e.shiftKey?!1:n?e.metaKey&&!e.altKey:e.altKey&&!e.metaKey}const eO=d.createContext({pin:!1,state:null,lockNow:()=>{},update:()=>{},shortcut:"⌃⌘L"});function Tp(){return d.useContext(eO)}function Nh(e){try{e?localStorage.setItem(iy,"1"):localStorage.removeItem(iy)}catch{}}function Fee(){try{return localStorage.getItem(iy)==="1"}catch{return!1}}function _ee(){try{return typeof BroadcastChannel>"u"?null:new BroadcastChannel(Mee)}catch{return null}}function zee({children:e}){const[n,s]=d.useState("checking"),[r,a]=d.useState(null),i=d.useRef(null),l=d.useRef(Date.now()),o=d.useRef(0),c=d.useRef(0),u=d.useRef(0),h=d.useCallback((g,w)=>{g&&a(g),s(w?"locked":"open"),Nh(w),w||(l.current=Date.now())},[]),m=d.useCallback(()=>{T.lockState().then(g=>h(g,g.locked)).catch(g=>{if(g instanceof pe&&g.status===401)return s("open");h(null,Fee())})},[h]);d.useEffect(()=>{m()},[m]);const f=d.useCallback((g="owner")=>{var w;if(!(r!=null&&r.pin)){window.location.hash=Oee;return}s("locked"),Nh(!0),g==="owner"&&((w=i.current)==null||w.postMessage({type:"locked"})),(g==="idle"?T.lockNow("idle",Date.now()-l.current):T.lockNow(g)).then(v=>{var j;g==="idle"&&v.locked&&((j=i.current)==null||j.postMessage({type:"locked"})),h(v,v.locked)}).catch(()=>m())},[r==null?void 0:r.pin,h,m]);d.useEffect(()=>{const g=()=>{s("locked"),Nh(!0),m()};return window.addEventListener(Uj,g),()=>window.removeEventListener(Uj,g)},[m]),d.useEffect(()=>{const g=_ee();if(i.current=g,!!g)return g.onmessage=w=>{const v=w.data;(v==null?void 0:v.type)==="locked"?(s("locked"),Nh(!0)):(v==null?void 0:v.type)==="unlocked"?m():(v==null?void 0:v.type)==="activity"&&typeof v.at=="number"&&(l.current=Math.max(l.current,v.at))},()=>{g.close(),i.current=null}},[m]),d.useEffect(()=>{const g=w=>{Lee(w)&&(w.preventDefault(),n==="open"&&f("owner"))};return window.addEventListener("keydown",g,!0),()=>window.removeEventListener("keydown",g,!0)},[n,f]);const p=r!=null&&r.pin?r.delayMinutes:null;d.useEffect(()=>{if(n!=="open"||!(r!=null&&r.pin))return;c.current=l.current;const g=()=>{var b;const N=Date.now();l.current=N,N-u.current>1e4&&(u.current=N,(b=i.current)==null||b.postMessage({type:"activity",at:N}))},w=()=>{const N=Date.now();l.current<=c.current||N-o.current<Iee||(o.current=N,c.current=l.current,T.lockActivity().catch(()=>{}))},v=()=>{if(p!==null&&Date.now()-l.current>=p*6e4){f("idle");return}w()},j=["pointerdown","pointermove","keydown","wheel","touchstart"];for(const N of j)window.addEventListener(N,g,{passive:!0,capture:!0});const y=window.setInterval(v,Pee),k=()=>{document.visibilityState==="visible"&&v()};return document.addEventListener("visibilitychange",k),()=>{for(const N of j)window.removeEventListener(N,g,{capture:!0});window.clearInterval(y),document.removeEventListener("visibilitychange",k)}},[n,r==null?void 0:r.pin,p,f]);const x=d.useMemo(()=>({pin:(r==null?void 0:r.pin)===!0,state:r,lockNow:()=>f("owner"),update:g=>h(g,g.locked),shortcut:Dee()}),[r,f,h]);return n==="checking"?null:n==="locked"?t.jsx(Aee,{initial:r,onUnlocked:g=>{var w;(w=i.current)==null||w.postMessage({type:"unlocked"}),h(g,!1)}}):t.jsx(eO.Provider,{value:x,children:e})}const tO="a connection needs you";function Uee({attention:e,place:n,onNavigate:s,theme:r,onTheme:a,plugins:i=[],updateAvailable:l=!1,settingsDot:o,version:c,stale:u=!1,reload:h,timezone:m,status:f}){return t.jsxs("nav",{className:"rail","aria-label":"Places",children:[t.jsx("a",{className:"rail-mark",href:Un,onClick:p=>{p.preventDefault(),s(Un)},"aria-label":"buddi home",children:t.jsx(Bu,{})}),oW.filter(p=>p.route!==Nn).map(p=>t.jsx(fx,{label:p.label,href:p.route,active:n===p.route,badge:p.route===Un?e:0,onClick:()=>s(p.route),children:Y1[p.route]},p.route)),i.map(p=>{const x=Mr(p.plugin,p.id);return t.jsx(fx,{label:p.title,href:x,active:n===x,badge:0,onClick:()=>s(x),children:t.jsx(ne,{name:F2(p.icon)})},x)}),t.jsx("div",{className:"rail-spacer"}),t.jsx(fx,{label:"Settings",href:Nn,active:n===Nn,badge:0,dot:l?"a newer buddi is ready":o,onClick:()=>s(Nn),children:Y1[Nn]}),f,t.jsx(Wee,{theme:r,onTheme:a,onNavigate:s,version:c,stale:u,reload:h,timezone:m})]})}const Bee=[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}];function Wee({theme:e,onTheme:n,onNavigate:s,version:r,stale:a,reload:i=()=>window.location.reload(),timezone:l}){var N,b,S;const o=je(()=>T.owner(),[]),c=cc(),u=Tp(),h=je(()=>T.focus(),[],6e4),m=((N=h.data)==null?void 0:N.focus)??null,f=(C,A)=>{T.setFocus(C,A).finally(()=>h.reload())},p=((S=(b=o.data)==null?void 0:b.preferredName)==null?void 0:S.trim())||null,x=(p??"You").slice(0,1).toUpperCase(),[g]=d.useState(()=>r8()||kk()),[w]=d.useState(Vee),v=Ep(),j=p?`You: ${p}`:"You",y=m?`${Qi[m.mode]} ${Ju(m,l)}`:null,k=[j,y,a?"reload to update":null].filter(Boolean).join(", ");return t.jsx("div",{className:"rail-owner",children:t.jsxs(pd,{modal:!1,children:[t.jsx(gd,{asChild:!0,children:t.jsxs("button",{type:"button",className:"rail-owner-btn","aria-label":k,children:[t.jsx("span",{className:"rail-owner-face","aria-hidden":"true",children:x}),a?t.jsx("span",{className:"ui-badge rail-dot","data-kind":"dot","data-testid":"owner-dot","aria-hidden":"true"}):null,m?t.jsx("span",{className:"rail-focus","data-testid":"owner-focus","aria-hidden":"true",children:t.jsx(ne,{name:"moon",size:10})}):null]})}),t.jsx(tc,{children:t.jsxs(xd,{className:"ui-menu rail-owner-menu",side:"right",align:"end",sideOffset:10,children:[t.jsxs("div",{className:"rail-owner-head",children:[t.jsx("span",{className:"rail-owner-face","data-size":"lg","aria-hidden":"true",children:x}),t.jsxs("span",{className:"rail-owner-who",children:[t.jsx("span",{className:"rail-owner-name",children:p??"You"}),t.jsxs("span",{className:"rail-owner-sub",children:["On ",c]})]})]}),t.jsx(Xr,{className:"ui-menu-sep"}),t.jsx(Kee,{focus:m,timezone:l,onSwitch:f}),t.jsx(Xr,{className:"ui-menu-sep"}),t.jsx(hl,{className:"ui-menu-label",children:"Theme"}),t.jsx("div",{className:"rail-owner-theme",children:t.jsx(cn,{label:"Theme",options:Bee,value:e,onChange:n})}),t.jsx(Xr,{className:"ui-menu-sep"}),u.pin?t.jsxs(bs,{className:"ui-menu-item rail-owner-reload",onSelect:()=>u.lockNow(),children:[t.jsx("span",{children:"Lock now"}),t.jsx("kbd",{className:"rail-owner-kbd",children:u.shortcut})]}):t.jsx(bs,{className:"ui-menu-item",onSelect:()=>s(ze("lock")),children:"Set up a lock screen…"}),t.jsx(bs,{className:"ui-menu-item",onSelect:()=>s(ze("appearance")),children:"Change appearance"}),v?t.jsx(bs,{className:"ui-menu-item",onSelect:()=>{wk(v)},children:"Install the app"}):null,g||a?t.jsxs(bs,{className:"ui-menu-item rail-owner-reload","data-update":a?"true":void 0,onSelect:()=>i(),children:[t.jsx("span",{children:a?"Reload to update":"Reload"}),w?t.jsx("kbd",{className:"rail-owner-kbd",children:w}):null]}):null,r?t.jsxs(t.Fragment,{children:[t.jsx(Xr,{className:"ui-menu-sep"}),t.jsxs(bs,{className:"ui-menu-item rail-owner-version","data-update":r.updateAvailable?"true":void 0,onSelect:()=>s(ze("system")),children:[t.jsxs("span",{className:"mono",children:["buddi ",r.current]}),r.updateAvailable&&r.latest?t.jsxs("span",{className:"rail-owner-update",children:["A newer buddi is ready: ",r.latest]}):null]})]}):null]})})]})})}const Qi={normal:"Off","urgent-only":"Urgent only","do-not-disturb":"Do not disturb"},Hee=[{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 Ju(e,n,s=new Date){if(!e.until)return"until you turn it off";const r=new Date(e.until),a=n??Intl.DateTimeFormat().resolvedOptions().timeZone,i=c=>new Intl.DateTimeFormat("en-CA",{timeZone:a,dateStyle:"short"}).format(c),l=Lt(r,a);return i(r)===i(s)?`until ${l}`:`until ${new Intl.DateTimeFormat("en-US",{timeZone:a,weekday:"short"}).format(r)} ${l}`}function Kee({focus:e,timezone:n,onSwitch:s}){return t.jsxs(JB,{children:[t.jsxs(XB,{className:"ui-menu-item rail-owner-focus",children:[t.jsx("span",{children:"Focus"}),t.jsx("span",{className:"rail-owner-kbd",children:e?Qi[e.mode]:"Off"})]}),t.jsx(tc,{children:t.jsxs(ZB,{className:"ui-menu rail-owner-menu",sideOffset:6,children:[t.jsx("p",{className:"ui-menu-empty",role:"status",children:e?`${Qi[e.mode]} ${Ju(e,n)}${e.by==="schedule"?", from a schedule":""}.`:"No focus is on."}),["do-not-disturb","urgent-only"].map(r=>t.jsxs(ab,{children:[t.jsx(Xr,{className:"ui-menu-sep"}),t.jsx(hl,{className:"ui-menu-label",children:Qi[r]}),Hee.map(a=>t.jsx(bs,{className:"ui-menu-item","aria-label":`${Qi[r]} ${a.label.toLowerCase()}`,onSelect:()=>s(r,a.value),children:a.label},a.value))]},r)),e?t.jsxs(t.Fragment,{children:[t.jsx(Xr,{className:"ui-menu-sep"}),t.jsx(bs,{className:"ui-menu-item",onSelect:()=>s("normal"),children:"Turn off"})]}):null]})})]})}function Vee(){const e=window.navigator.userAgent;return/iPhone|iPad|Android|Mobile/.test(e)?null:/Mac/.test(e)?"⌘R":"Ctrl+R"}function fx({label:e,href:n,active:s,badge:r,dot:a,onClick:i,children:l}){return t.jsxs("a",{className:"rail-link",href:n,"data-active":s?"true":void 0,"aria-current":s?"page":void 0,"aria-label":r>0?`${e}, ${r} waiting`:a?`${e}, ${a}`:e,onClick:o=>{o.preventDefault(),i()},children:[t.jsxs("span",{className:"rail-icon",children:[l,r>0?t.jsx("span",{className:"rail-badge","aria-hidden":"true",children:r>99?"99+":r}):null,r===0&&a?t.jsx("span",{className:"ui-badge rail-dot","data-kind":"dot","data-testid":"rail-dot","aria-hidden":"true"}):null]}),t.jsx("span",{className:"rail-label",children:e})]})}const Y1={[Da]:t.jsx(ne,{name:"files"}),[Un]:t.jsx(ne,{name:"home"}),[Aa]:t.jsx(ne,{name:"chat"}),[Pt]:t.jsx(ne,{name:"agents"}),[ln]:t.jsx(ne,{name:"activity"}),[Nn]:t.jsx(ne,{name:"settings"})},Xu=e=>`${e.plugin}:${e.id}`,Gee=new Set;let Sk=Gee,Q1=!1;const ly=new Set;function oy(e){Sk=e;for(const n of ly)n()}function qee(e){return ly.add(e),()=>ly.delete(e)}const J1=()=>Sk;function Yee(){Q1||(Q1=!0,Promise.resolve().then(()=>T.rail()).then(e=>oy(new Set(Array.isArray(e==null?void 0:e.hidden)?e.hidden.filter(n=>typeof n=="string"):[]))).catch(()=>{}))}async function Qee(e,n){const s=Sk,r=new Set(s);n?r.add(Xu(e)):r.delete(Xu(e)),oy(r);try{await T.setRailHidden(e.plugin,e.id,n)}catch(a){throw oy(s),a}}function nO(){return d.useEffect(Yee,[]),d.useSyncExternalStore(qee,J1,J1)}function Jee(e,n){return e.filter(s=>!n.has(Xu(s)))}function Xee(e){return e instanceof HTMLElement?e.isContentEditable?!0:e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.tagName==="SELECT":!1}function Zee(e,n=!0,s){d.useEffect(()=>{if(!n)return;const r=a=>{if(a.key!=="/"||a.defaultPrevented||a.ctrlKey||a.metaKey||a.altKey||Xee(a.target))return;a.preventDefault();const i=document.getElementById(ey);if(i instanceof HTMLTextAreaElement){!i.disabled&&!i.hidden&&i.focus();return}s?s():e(Un)};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,n,s])}const sO="buddi.theme";function ete(e=rO()){try{const n=e==null?void 0:e.getItem(sO);return n==="light"||n==="dark"||n==="system"?n:"system"}catch{return"system"}}function tte(e,n=rO()){try{n==null||n.setItem(sO,e)}catch{}}function nte(e,n=document.documentElement){n&&(e==="system"?n.removeAttribute("data-theme"):n.setAttribute("data-theme",e))}function rO(){try{return window.localStorage}catch{return}}const aO="buddi.ground",iO="buddi.pageWidth";function ste(e=cO()){const n=a=>{try{return(e==null?void 0:e.getItem(a))??null}catch{return null}},s=n(aO),r=n(iO);return{theme:ete(e),ground:s==="sand"?"sand":"blue",width:r==="narrow"||r==="full"?r:"wide"}}function lO(e,n=document.documentElement){n&&(nte(e.theme,n),e.ground==="sand"?n.setAttribute("data-ground","sand"):n.removeAttribute("data-ground"),e.width==="wide"?n.removeAttribute("data-width"):n.setAttribute("data-width",e.width))}function rte(e,n=cO()){tte(e.theme,n);try{n==null||n.setItem(aO,e.ground),n==null||n.setItem(iO,e.width)}catch{}}let bo=null;const cy=new Set;function uy(){return bo||(bo=ste()),bo}function ate(e){return cy.add(e),()=>cy.delete(e)}function ite(e){bo={...uy(),...e},lO(bo),rte(bo);for(const n of cy)n()}function oO(){return[d.useSyncExternalStore(ate,uy,uy),ite]}function cO(){try{return window.localStorage}catch{return}}const X1=7,lte=1e4;function ote({timezone:e,embedded:n,agents:s=[],navigate:r}){const{data:a,error:i,reload:l}=je(()=>T.sentinels(),[],3e4),[o,c]=d.useState(null),[u,h]=d.useState(null),[m,f]=d.useState(null),[p,x]=d.useState(null),[g,w]=d.useState(!1),[v,j]=d.useState(null),y=a==null?void 0:a.alerts,k=(y==null?void 0:y.open)??[],N=L=>{r?r(L):window.location.hash=L},b=L=>{var M;return L?((M=s.find(z=>z.id===L))==null?void 0:M.name)??null:null},S=async L=>{c(null);try{await L()}catch(M){c(M instanceof pe||M instanceof Error?M.message:String(M))}finally{l()}},C=L=>h({...L,id:Date.now()}),A=(L,M,z)=>S(async()=>{const{keys:D}=await T.snoozeAlerts(L,!0,z);C({title:M,undo:()=>T.snoozeAlerts(D,!1)})}),E=L=>S(async()=>{const{id:M}=await T.muteAlert(L.keys[0],L.stop.scope);C({title:"You won’t hear about this again",body:"Turn it back on in Settings → Watchers.",undo:()=>T.unmuteAlert(M)})}),R=L=>S(async()=>{const{agentId:M,conversationId:z}=await T.askAboutAlerts(L.keys);N(ut(M,z))}),P=L=>S(async()=>{const[M]=(await T.actOnAlerts([{key:L.key,action:L.index}])).results;if(M!=null&&M.error)throw new Error(M.error);M!=null&&M.approvalId?C({title:"Waiting for your approval",body:"Decide it in Needs you on Home."}):C({title:`${L.label}: done`})}),O=(L,M)=>{M.kind==="open"?N(M.place==="files"?Da:M.plugin&&M.page?Mr(M.plugin,M.page,M.item):Da):M.kind==="ask"?R(L):M.kind==="dismiss"?A(L.keys,"Set aside until it changes"):M.kind==="fill"?f(M):M.confirm?x(M):P(M)},I=()=>{const L=k.flatMap(M=>M.keys);A(L,`Cleared ${k.length} for a week`,X1)},F=y==null?void 0:y.recap,U=cte((F==null?void 0:F.nextAt)??null,e);return t.jsxs(Is,{embedded:n,title:"Alerts",lede:"What needs a decision from you.",children:[t.jsx(re,{message:i??o}),t.jsxs(lt,{flush:!0,title:"Needs a decision",tool:k.length>0?String(k.length):void 0,actions:k.length>1?t.jsx($,{size:"sm",variant:"ghost",onClick:I,children:"Clear all"}):void 0,children:[a?k.length===0?t.jsxs("div",{className:"al-empty",children:[t.jsx(ne,{name:"check"}),t.jsxs("div",{children:[t.jsx("p",{className:"al-empty-title",children:"Nothing needs a decision."}),t.jsxs("p",{className:"al-empty-line",children:["Your watchers are quiet. What they notice in passing waits for ",U,"."]})]})]}):t.jsx("ul",{className:"al-list",children:k.map(L=>t.jsx(Z1,{group:L,agentName:b(L.agentId),onAct:O,onStop:E,onNotNow:M=>void A(M.keys,"Snoozed for a week",X1)},L.id))}):null,F&&F.count>0?t.jsxs("p",{className:"al-recap","data-testid":"recap-line",children:[t.jsxs("span",{children:[F.count," ",F.count===1?"note":"notes"," saved for ",U]}),t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("button",{type:"button",className:"wb-link",onClick:()=>w(!0),children:"Preview"})]}):null]}),y&&(y.snoozed.length>0||y.resolved.length>0)?t.jsxs("p",{className:"al-quiet",children:[y.snoozed.length>0?t.jsxs("button",{type:"button",className:"wb-link","aria-expanded":v==="snoozed",onClick:()=>j(v==="snoozed"?null:"snoozed"),children:[y.snoozed.length," snoozed"]}):null,y.snoozed.length>0&&y.resolved.length>0?t.jsx("span",{"aria-hidden":"true",children:"·"}):null,y.resolved.length>0?t.jsxs("button",{type:"button",className:"wb-link","aria-expanded":v==="resolved",onClick:()=>j(v==="resolved"?null:"resolved"),children:[y.resolved.length," resolved this week"]}):null]}):null,v==="snoozed"&&y?t.jsx(lt,{flush:!0,title:"Snoozed",children:t.jsx("ul",{className:"al-list",children:y.snoozed.map(L=>t.jsxs("li",{className:"al-row",children:[t.jsxs("div",{className:"al-main",children:[t.jsx("p",{className:"al-title",children:L.title}),t.jsx("p",{className:"al-sub",children:L.snoozedUntil?`Back ${Xe(L.snoozedUntil)}`:"Until it changes"})]}),t.jsx("div",{className:"al-actions",children:t.jsx($,{size:"sm",onClick:()=>void S(async()=>{await T.snoozeAlerts(L.keys,!1)}),children:"Bring back"})})]},L.id))})}):null,v==="resolved"&&y?t.jsx(lt,{flush:!0,title:"Resolved this week",children:t.jsx("ul",{className:"al-list",children:y.resolved.map(L=>t.jsx("li",{className:"al-row",children:t.jsxs("div",{className:"al-main",children:[t.jsx("p",{className:"al-title",children:L.title}),t.jsx("p",{className:"al-sub",children:L.resolvedAt?`Resolved ${Xe(L.resolvedAt)}`:null})]})},L.id))})}):null,g&&F?t.jsxs(Ye,{title:ute(U),onClose:()=>w(!1),children:[t.jsxs("p",{className:"al-form-note",children:["What the watchers noted. buddi reads them out in ",U,"; nothing here needs you now, but you can act on one early."]}),t.jsx("ul",{className:"al-list al-list-sheet",children:F.groups.map(L=>t.jsx(Z1,{group:L,agentName:b(L.agentId),recap:!0,onAct:(M,z)=>{z.kind!=="fill"&&w(!1),O(M,z)},onStop:M=>{E(M)}},L.id))})]}):null,m?t.jsx(dte,{action:m,onClose:()=>f(null),onSaved:L=>{f(null),w(!1),C({title:`Saved ${L}`}),l()}}):null,p?t.jsx(Gt,{title:p.label,onClose:()=>x(null),foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:()=>x(null),children:"Cancel"}),t.jsx($,{variant:p.tone==="danger"?"danger":"accent",onClick:()=>{const L=p;x(null),P(L)},children:p.label})]}),children:t.jsx("p",{children:p.confirm})}):null,u?t.jsx(Qu,{title:u.title,...u.body?{body:u.body}:{},duration:lte,...u.undo?{onUndo:()=>{const L=u.undo;S(async()=>{await L()})}}:{},onGone:()=>h(null)},u.id):null]})}function cte(e,n,s=Date.now()){if(!e)return"the weekly recap";const r=new Date(e);return Number.isNaN(r.getTime())||r.getTime()-s>7*864e5?"the weekly recap":`${new Intl.DateTimeFormat("en",{weekday:"long",timeZone:n}).format(r)}’s recap`}function ute(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Sh(e,n){return e.kind==="ask"?e.label??(n?`Ask ${n}`:"Ask about it"):e.label}function Z1({group:e,agentName:n,recap:s,onAct:r,onNotNow:a,onStop:i}){const[l,o]=d.useState(!1),[c,u,...h]=e.actions,m=e.actions.some(p=>p.kind==="ask"),f=e.items.length>1;return t.jsxs("li",{className:"al-row","data-urgent":e.urgent&&!s?"true":void 0,children:[t.jsxs("div",{className:"al-main",children:[t.jsx("p",{className:"al-title",children:e.title}),e.line?t.jsx("p",{className:"al-line",children:e.line}):null,t.jsxs("p",{className:"al-sub",children:[n?t.jsx("span",{children:n}):null,n&&!s?t.jsx("span",{"aria-hidden":"true",children:"·"}):null,s?null:t.jsxs("span",{children:["noticed ",Xe(e.since)]}),f?t.jsxs(t.Fragment,{children:[n||!s?t.jsx("span",{"aria-hidden":"true",children:"·"}):null,t.jsx("button",{type:"button",className:"wb-link al-toggle","aria-expanded":l,onClick:()=>o(p=>!p),children:l?"Hide":`Show the ${e.items.length}`})]}):null]}),l&&f?t.jsx("ul",{className:"al-items",children:e.items.map(p=>t.jsxs("li",{className:"al-item",children:[p.subject?t.jsx("span",{className:"al-item-who",children:p.subject.label}):null,t.jsx("span",{className:"al-item-note",children:p.subject?p.note:p.line}),p.actions&&p.actions.length>0?t.jsx("span",{className:"al-item-actions",children:p.actions.map((x,g)=>t.jsx($,{size:"sm",variant:x.kind==="run"&&x.tone==="danger"?"danger-ghost":"ghost",onClick:()=>r(e,x),children:Sh(x,n)},g))}):null]},p.key))}):null]}),t.jsxs("div",{className:"al-actions",children:[c?t.jsx($,{size:"sm",variant:"accent",onClick:()=>r(e,c),children:Sh(c,n)}):null,u?t.jsx($,{size:"sm",variant:u.kind==="run"&&u.tone==="danger"?"danger-ghost":void 0,onClick:()=>r(e,u),children:Sh(u,n)}):null,a?t.jsx($,{size:"sm",variant:"ghost",onClick:()=>a(e),children:"Not now"}):null,t.jsx("span",{className:"al-more",children:t.jsx(rs,{label:`More for ${e.title}`,sheet:{title:e.title},items:[...h.map(p=>({label:Sh(p,n),...p.kind==="run"&&p.tone==="danger"?{tone:"critical"}:{},onSelect:()=>r(e,p)})),!m&&{label:n?`Ask ${n}`:"Ask about it",onSelect:()=>r(e,{kind:"ask",label:null})},"separator",{label:"Stop telling me this",hint:"Undo in Settings → Watchers",onSelect:()=>i(e)}]})})]})]})}function dte({action:e,onClose:n,onSaved:s}){const r=e.fields.length===1,[a,i]=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,m]=d.useState(null),f=async()=>{const p=e.fields.filter(x=>(a[x.key]??"").trim()!=="").map(x=>({key:x.key,action:x.index,value:(a[x.key]??"").trim()}));if(p.length===0){n();return}u(!0),m(null);try{const{results:x}=await T.actOnAlerts(p),g=Object.fromEntries(x.filter(w=>w.error).map(w=>[w.key,w.error]));o(g),Object.keys(g).length===0&&s(p.length)}catch(x){m(x instanceof Error?x.message:String(x))}finally{u(!1)}};return t.jsx(Ye,{title:e.title,onClose:n,foot:t.jsxs("div",{className:"al-form-foot",children:[t.jsx($,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:c,onClick:()=>void f(),children:c?"Saving…":"Save"})]}),children:t.jsxs("div",{className:"al-form",children:[t.jsx(re,{message:h}),t.jsx("p",{className:"al-form-note",children:r?"Check it and save.":"Type what each is today. Leave the ones you don’t know; they stay as they are."}),t.jsx("div",{className:"al-form-rows",children:e.fields.map(p=>t.jsxs("label",{className:"al-form-row",children:[t.jsxs("span",{className:"al-form-label",children:[t.jsx("span",{children:p.label}),p.hint?t.jsx("span",{className:"al-form-hint",children:p.hint}):null]}),t.jsx("input",{type:p.type==="date"?"date":"text",inputMode:p.type==="number"?"decimal":void 0,value:a[p.key]??"",placeholder:"—","aria-label":p.label,onChange:x=>i(g=>({...g,[p.key]:x.target.value}))}),l[p.key]?t.jsx("span",{className:"al-form-error",children:l[p.key]}):null]},p.key))})]})})}function hte({mutes:e,onChanged:n}){const[s,r]=d.useState(null);return e.length===0?null:t.jsxs(lt,{flush:!0,title:"Silenced",tool:String(e.length),children:[t.jsx(re,{message:s}),t.jsx("ul",{className:"al-list",children:e.map(a=>t.jsxs("li",{className:"al-row",children:[t.jsxs("div",{className:"al-main",children:[t.jsx("p",{className:"al-title al-silenced-label",children:a.label}),t.jsxs("p",{className:"al-sub",children:["You said “Stop telling me this” ",Xe(a.createdAt)]})]}),t.jsx("div",{className:"al-actions",children:t.jsx($,{size:"sm",onClick:()=>{r(null),T.unmuteAlert(a.id).then(n,i=>r(i instanceof Error?i.message:String(i)))},children:"Tell me again"})})]},a.id))})]})}const eE=5e3,tE=50;function fte({timezone:e,embedded:n}){var v;const[s,r]=d.useState(""),[a,i]=d.useState(""),[l,o]=d.useState(null),c=je(()=>T.eventKinds(),[]),{data:u,error:h}=je(()=>T.events({kind:s||void 0,q:a||void 0,limit:tE}),[s,a],eE),[m,f]=d.useState({events:[],cursor:null,busy:!1,error:null});d.useEffect(()=>{f({events:[],cursor:null,busy:!1,error:null})},[s,a]);const p=m.events.length>0?m.cursor:(u==null?void 0:u.nextCursor)??null,x=async()=>{if(p){f(j=>({...j,busy:!0,error:null}));try{const j=await T.events({kind:s||void 0,q:a||void 0,before:p,limit:tE});f(y=>({events:[...y.events,...j.events],cursor:j.nextCursor,busy:!1,error:null}))}catch(j){f(y=>({...y,busy:!1,error:j instanceof Error?j.message:String(j)}))}}},g=new Set(((u==null?void 0:u.events)??[]).map(j=>j.id)),w=[...(u==null?void 0:u.events)??[],...m.events.filter(j=>!g.has(j.id))];return t.jsxs(Is,{embedded:n,title:"Events",lede:"The append-only log. Everything the installation did, including what you do here.",children:[t.jsxs(te,{children:[t.jsxs("select",{"aria-label":"Event kind",value:s,onChange:j=>r(j.target.value),children:[t.jsx("option",{value:"",children:"every kind"}),(((v=c.data)==null?void 0:v.kinds)??[]).map(j=>t.jsxs("option",{value:j.kind,children:[j.kind," (",j.count,")"]},j.kind))]}),t.jsx("input",{"aria-label":"Payload contains",placeholder:"payload contains…",value:a,onChange:j=>i(j.target.value),size:28}),s||a?t.jsx($,{onClick:()=>{r(""),i("")},children:"Clear"}):null,t.jsxs("span",{className:"muted",children:["refreshes every ",eE/1e3,"s"]})]}),t.jsx(re,{message:h}),t.jsx(lt,{flush:!0,children:!u||w.length===0?t.jsx(Ee,{children:"No events match."}):t.jsxs(da,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"#"}),t.jsx("th",{children:"When"}),t.jsx("th",{children:"Kind"}),t.jsx("th",{children:"Payload"})]})}),t.jsx("tbody",{children:w.map(j=>t.jsxs("tr",{"data-clickable":"true",onClick:()=>o(j),children:[t.jsx("td",{className:"mono muted",children:j.id}),t.jsxs("td",{className:"nowrap",children:[St(j.createdAt,e),t.jsx("div",{className:"sub",children:Xe(j.createdAt)})]}),t.jsx("td",{className:"mono nowrap",children:j.kind}),t.jsx("td",{className:"mono muted",children:mr(ms(j.payload).replace(/\s+/g," "),120)})]},j.id))})]})}),p||m.error?t.jsxs(te,{children:[t.jsxs("span",{className:"muted",children:[w.length," shown",p?", older ones are kept":"","."]}),t.jsx("span",{className:"ui-toolbar-spacer"}),m.error?t.jsx("span",{className:"critical",children:m.error}):null,p?t.jsx($,{disabled:m.busy,onClick:()=>void x(),children:m.busy?"Loading…":"Load older"}):null]}):null,l?t.jsxs(Ye,{title:l.kind,onClose:()=>o(null),children:[t.jsxs("p",{className:"muted",children:["Event ",l.id," · ",St(l.createdAt,e),l.conversationId?t.jsxs(t.Fragment,{children:[" · ",t.jsx("a",{href:`#/conversations/${l.conversationId}`,children:"conversation"})]}):null]}),t.jsx(Zt,{children:ms(l.payload)})]}):null]})}const nE=["pending","leased","suspended","failed","succeeded","cancelled"],Pc=50,mte=1e4,pte=(e,n,s=`${n}s`)=>e===1?n:s;function gte({timezone:e,embedded:n,initialState:s}){var D,K;const[r,a]=d.useState(s??""),[i,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(null),[m,f]=d.useState(!1),p=r==="failed",{data:x,error:g,reload:w}=je(()=>T.jobs({...r?{state:r}:{},...r?{}:{dismissed:"0"},limit:String(Pc)}),[r],1e4),v=je(()=>T.jobFailures(),[],1e4),[j,y]=d.useState({jobs:[],done:!1,busy:!1});d.useEffect(()=>{y({jobs:[],done:!1,busy:!1})},[r]);const k=async()=>{y(B=>({...B,busy:!0}));try{const B=await T.jobs({...r?{state:r}:{dismissed:"0"},limit:String(Pc),offset:String(Pc+j.jobs.length)});y(se=>({jobs:[...se.jobs,...B.jobs],done:B.jobs.length<Pc,busy:!1}))}catch(B){c(B instanceof Error?B.message:String(B)),y(se=>({...se,busy:!1}))}},N=new Set(((x==null?void 0:x.jobs)??[]).map(B=>B.id)),b=[...(x==null?void 0:x.jobs)??[],...j.jobs.filter(B=>!N.has(B.id))],S=(x==null?void 0:x.counts)??{},C=r?S[r]??0:nE.reduce((B,se)=>B+(S[se]??0),0),A=!j.done&&b.length<C&&((x==null?void 0:x.jobs.length)??0)>=Pc,E=((D=v.data)==null?void 0:D.open)??[],R=((K=v.data)==null?void 0:K.dismissed)??[],P=E.reduce((B,se)=>B+se.count,0),O=R.reduce((B,se)=>B+se.count,0),I=()=>{w(),v.reload()},F=B=>h({...B,id:Date.now()}),U=async B=>{c(null);try{await B()}catch(se){c(se instanceof Error?se.message:String(se))}finally{I()}},L=async B=>{await U(async()=>{await B,l(null)})},M=B=>U(async()=>{const{ids:se}=await T.dismissJobs(B==="all"?{all:!0}:{ids:B});se.length!==0&&F({title:`Dismissed ${se.length===1?"it":se.length}`,body:"Kept under Dismissed, below.",undo:()=>T.undismissJobs(se)})}),z=(B,se)=>U(async()=>{const{jobs:W}=await T.retryJobs({ids:B});if(W.length===0)return;const xe=W.length===1;F({title:`Retrying ${xe?"it":W.length}`,body:se?`${xe?"It runs":"They run"} as soon as a worker is free.`:`If what broke ${xe?"it":"them"} hasn’t changed, ${xe?"it":"they"} will fail the same way.`})});return t.jsxs(Is,{embedded:n,title:"Jobs",lede:`${x!=null&&x.paused?"Paused: nothing is being claimed. ":""}Bounded retries with backoff; past the budget a job waits for you.`,actions:n?void 0:t.jsx($,{size:"sm",variant:x!=null&&x.paused?"accent":void 0,onClick:()=>L(T.setPaused(!((x==null?void 0:x.paused)??!1))),children:x!=null&&x.paused?"Resume the queue":"Pause the queue"}),children:[t.jsx(re,{message:g??v.error??o}),E.length>0?t.jsxs(lt,{flush:!0,title:"Gave up",tool:String(P),actions:P>1?t.jsx($,{size:"sm",variant:"ghost",onClick:()=>void M("all"),children:"Dismiss all"}):void 0,children:[t.jsx("ul",{className:"al-list",children:E.map(B=>t.jsx(rE,{group:B,timezone:e,onOpen:l,onRetry:se=>void z(se,B.likelyFixed),onDismiss:se=>void M(se)},B.key))}),t.jsx("p",{className:"al-recap",children:t.jsx("span",{children:"These will not run again on their own. Dismissed jobs stay on record; any failed job older than 14 days is dismissed for you."})})]}):p&&v.data?t.jsx(lt,{flush:!0,children:t.jsxs("div",{className:"al-empty",children:[t.jsx(ne,{name:"check"}),t.jsxs("div",{children:[t.jsx("p",{className:"al-empty-title",children:"No failed job needs you."}),t.jsx("p",{className:"al-empty-line",children:O>0?"The ones you dismissed stay on record, below.":"Every job either ran or is still on its way."})]})]})}):null,O>0||p?t.jsxs("p",{className:"al-quiet jb-quiet",children:[O>0?t.jsxs("button",{type:"button",className:"wb-link","aria-expanded":m,onClick:()=>f(B=>!B),children:[O," dismissed"]}):null,O>0&&p?t.jsx("span",{"aria-hidden":"true",children:"·"}):null,p?t.jsx("button",{type:"button",className:"wb-link",onClick:()=>a(""),children:"Show the whole queue"}):null]}):null,m&&R.length>0?t.jsx(lt,{flush:!0,title:"Dismissed",children:t.jsx("ul",{className:"al-list",children:R.map(B=>t.jsx(rE,{group:B,timezone:e,dismissed:!0,onOpen:l,onRetry:se=>void z(se,B.likelyFixed)},B.key))})}):null,p?null:t.jsx(lt,{flush:!0,title:"Queue",actions:t.jsxs("select",{"aria-label":"Job state",value:r,onChange:B=>a(B.target.value),children:[t.jsx("option",{value:"",children:"every state"}),nE.map(B=>t.jsxs("option",{value:B,children:[B," (",S[B]??0,")"]},B))]}),children:!x||b.length===0?t.jsx(Ee,{children:"No jobs match."}):t.jsxs(da,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Kind"}),t.jsx("th",{children:"State"}),t.jsx("th",{className:"num",children:"Attempts"}),t.jsx("th",{children:"Last error"}),t.jsx("th",{children:"Updated"}),t.jsx("th",{})]})}),t.jsx("tbody",{children:b.map(B=>t.jsxs("tr",{children:[t.jsxs("td",{className:"clickable",onClick:()=>l(B),children:[B.kind,t.jsx("div",{className:"sub mono",children:Iu(B.id)})]}),t.jsxs("td",{children:[t.jsx(wd,{state:B.state}),B.suspendedReason?t.jsx("div",{className:"sub",children:mr(B.suspendedReason,40)}):null,B.acknowledgedAt?t.jsx("div",{className:"sub",children:"dismissed"}):null]}),t.jsxs("td",{className:"num",children:[B.attempts,"/",B.maxAttempts]}),t.jsx("td",{className:B.lastError?"critical":"muted",children:B.lastError?mr(B.lastError,80):"—"}),t.jsxs("td",{className:"nowrap",children:[St(B.updatedAt,e),t.jsx("div",{className:"sub",children:Xe(B.updatedAt)})]}),t.jsx("td",{children:t.jsxs(te,{align:"end",children:[["failed","cancelled","suspended"].includes(B.state)?t.jsx($,{size:"sm",onClick:()=>L(T.retryJob(B.id)),children:"Retry"}):null,["pending","leased","suspended","failed"].includes(B.state)?t.jsx($,{size:"sm",variant:"danger",onClick:()=>L(T.cancelJob(B.id)),children:"Cancel"}):null]})})]},B.id))})]})}),A&&!p?t.jsxs(te,{children:[t.jsxs("span",{className:"muted",children:[b.length," of ",C," shown."]}),t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx($,{disabled:j.busy,onClick:()=>void k(),children:j.busy?"Loading…":"Load older"})]}):null,i?t.jsxs(Ye,{title:i.kind,onClose:()=>l(null),children:[t.jsx("p",{className:"muted mono",children:i.id}),i.lastError?t.jsx(ye,{title:"Last error",children:t.jsx(Zt,{children:i.lastError})}):null,t.jsx(ye,{title:"Payload",children:t.jsx(Zt,{children:ms(i.payload)})}),t.jsx(ye,{title:"Result",children:t.jsx(Zt,{children:ms(i.result)})}),i.conversationId?t.jsx("p",{children:t.jsx("a",{href:`#/conversations/${i.conversationId}`,children:"open the transcript"})}):null]}):null,u?t.jsx(Qu,{title:u.title,...u.body?{body:u.body}:{},duration:mte,...u.undo?{onUndo:()=>{const B=u.undo;U(async()=>{await B()})}}:{},onGone:()=>h(null)},u.id):null]})}function sE(e){var s;if(e.missionName)return e.missionName;const n=(s=e.job.payload)==null?void 0:s.prompt;return typeof n=="string"&&n.trim()!==""?mr(n.trim().split(`
133
- `)[0],48):e.job.kind==="agent-run"?"Agent run":e.job.kind}function rE({group:e,timezone:n,dismissed:s,onOpen:r,onRetry:a,onDismiss:i}){var x;const[l,o]=d.useState(!1),c=e.jobs.length>1,u=e.jobs.map(g=>g.job.id),h=e.agents.map(g=>g.name??g.id),m=e.jobs[0],f=e.jobs.every(g=>g.job.acknowledgedBy==="auto"),p=s?f?"dismissed on its own after 14 days":`dismissed ${Xe(((x=e.jobs[0])==null?void 0:x.job.acknowledgedAt)??e.lastAt)}`:`gave up ${Xe(e.lastAt)}`;return t.jsxs("li",{className:"al-row","data-urgent":s?void 0:"true",children:[t.jsxs("div",{className:"al-main",children:[t.jsx("p",{className:"al-title",children:c?`${e.label} · ${e.count}`:e.label}),s?null:t.jsx("p",{className:"al-line",children:e.reason}),t.jsxs("p",{className:"al-sub",children:[h.length>0?t.jsxs(t.Fragment,{children:[t.jsx("span",{children:h.join(", ")}),t.jsx("span",{"aria-hidden":"true",children:"·"})]}):null,!c&&m?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:"wb-link",onClick:()=>r(m.job),children:sE(m)}),t.jsx("span",{"aria-hidden":"true",children:"·"})]}):null,t.jsx("span",{title:St(e.lastAt,n),children:p}),c?t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("button",{type:"button",className:"wb-link al-toggle","aria-expanded":l,onClick:()=>o(g=>!g),children:l?"Hide":`Show the ${e.count}`})]}):null]}),l&&c?t.jsx("ul",{className:"al-items",children:e.jobs.map(g=>t.jsxs("li",{className:"al-item jb-item",children:[g.agentName||g.agentId?t.jsx("span",{className:"al-item-who",children:g.agentName??g.agentId}):null,t.jsxs("span",{className:"al-item-note",children:[t.jsx("button",{type:"button",className:"wb-link",onClick:()=>r(g.job),children:sE(g)})," · ",Ym(new Date(g.job.updatedAt),n)," · tried ",g.job.attempts," ",pte(g.job.attempts,"time")]}),t.jsxs("span",{className:"jb-item-acts",children:[t.jsx("button",{type:"button",className:"wb-link",onClick:()=>a([g.job.id]),children:"Retry"}),i?t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("button",{type:"button",className:"wb-link",onClick:()=>i([g.job.id]),children:"Dismiss"})]}):null]})]},g.job.id))}):null]}),t.jsxs("div",{className:"al-actions",children:[t.jsx($,{size:"sm",variant:e.likelyFixed&&!s?"accent":void 0,onClick:()=>a(u),children:c?"Retry all":"Retry"}),i?t.jsx($,{size:"sm",variant:"ghost",onClick:()=>i(u),children:"Dismiss"}):null]})]})}const xte=[{id:"conversations",label:"Conversations"},{id:"jobs",label:"Jobs"},{id:"approvals",label:"Approvals"},{id:"alerts",label:"Alerts"},{id:"events",label:"Events"}];function jte({hash:e,timezone:n,navigate:s,agents:r}){var u,h;const a=/^#\/activity\/conversations\/(.+)$/.exec(e),i=m=>{var f;return((f=r.find(p=>p.id===m))==null?void 0:f.name)??m};if(a){let m=a[1];try{m=decodeURIComponent(m)}catch{}return t.jsx(wte,{id:m,timezone:n,navigate:s,nameOf:i})}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=m=>f=>{f.preventDefault(),s(m)};return t.jsxs("div",{className:"ui-page",children:[t.jsx(nl,{title:"Activity",lede:"Everything your agents ran, newest first.",actions:t.jsx(Nte,{})}),t.jsx(Ste,{}),t.jsx(ic,{children:xte.map(m=>{const f=m.id==="conversations"?ln:`${ln}/${m.id}`;return t.jsx(ml,{href:f,active:l===m.id,onClick:c(f),children:m.label},m.id)})}),l==="conversations"?t.jsx(vte,{timezone:n,navigate:s,nameOf:i,agents:r}):null,l==="jobs"?t.jsx(gte,{timezone:n,embedded:!0,initialState:o},o??""):null,l==="approvals"?t.jsx(yte,{timezone:n,nameOf:i}):null,l==="alerts"?t.jsx(ote,{timezone:n,embedded:!0,agents:r,navigate:s}):null,l==="events"?t.jsx(fte,{timezone:n,embedded:!0}):null]})}function vte({timezone:e,navigate:n,nameOf:s,agents:r}){const{data:a,error:i}=je(()=>T.conversations(),[],3e4);return t.jsxs(t.Fragment,{children:[t.jsx(re,{message:i}),t.jsx(lt,{flush:!0,children:a?a.conversations.length===0?t.jsx(ps,{icon:"activity",title:"Nothing has run yet",children:"Conversations and runs show up here as your agents work."}):t.jsx(yt,{children:a.conversations.map(l=>t.jsx(pt,{href:Fu(l.id),onClick:()=>n(Fu(l.id)),lead:t.jsx(vn,{agents:r,id:l.agentId,size:"sm"}),title:l.opening?mr(l.opening,100):"Untitled conversation",sub:`${s(l.agentId)}, ${l.messageCount} message${l.messageCount===1?"":"s"}, ${l.runs} run${l.runs===1?"":"s"}, ${hU(l.usage)}`,side:t.jsx("span",{title:St(l.lastMessageAt??l.createdAt,e),children:Xe(l.lastMessageAt??l.createdAt)})},l.id))}):t.jsx(Ee,{children:"Loading…"})})]})}function yte({timezone:e,nameOf:n}){const{data:s,error:r}=je(()=>T.approvals(),[],1e4),a=[...(s==null?void 0:s.pending)??[],...(s==null?void 0:s.recent)??[]];return t.jsxs(t.Fragment,{children:[t.jsx(re,{message:r}),t.jsx(lt,{flush:!0,children:s?a.length===0?t.jsx(ps,{icon:"bell",title:"No approvals yet",children:"When an agent asks before acting, the request and your answer are kept here."}):t.jsxs(da,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Tool"}),t.jsx("th",{children:"State"}),t.jsx("th",{children:"Asked by"}),t.jsx("th",{children:"Decided"}),t.jsx("th",{children:"Created"})]})}),t.jsx("tbody",{children:a.map(i=>t.jsxs("tr",{children:[t.jsxs("td",{children:[i.tool,t.jsx("div",{className:"sub mono",children:Iu(i.id)})]}),t.jsx("td",{children:t.jsx(wd,{state:i.state})}),t.jsx("td",{children:n(i.agentId)}),t.jsx("td",{className:"nowrap",children:i.decidedAt?t.jsxs(t.Fragment,{children:[St(i.decidedAt,e),t.jsxs("div",{className:"sub",children:["via ",i.decidedVia??"—"]})]}):t.jsx("span",{className:"muted",children:"—"})}),t.jsxs("td",{className:"nowrap",children:[St(i.createdAt,e),t.jsx("div",{className:"sub",children:Xe(i.createdAt)})]})]},i.id))})]}):t.jsx(Ee,{children:"Loading…"})})]})}function wte({id:e,timezone:n,navigate:s,nameOf:r}){const[a,i]=d.useState(null),[l,o]=d.useState(null);d.useEffect(()=>{let u=!1;return T.conversation(e).then(h=>{u||i(h)}).catch(h=>{u||o(h instanceof Error?h.message:String(h))}),()=>{u=!0}},[e]);const c=u=>h=>{h.preventDefault(),s(u)};return t.jsxs("div",{className:"ui-page",children:[t.jsx("p",{className:"page-crumbs",children:t.jsx("a",{href:ln,onClick:c(ln),children:"Activity"})}),t.jsxs("header",{className:"ui-page-head",children:[t.jsxs("div",{className:"ui-page-head-row",children:[t.jsxs("h2",{className:"ui-page-title",children:[t.jsx($,{size:"sm",onClick:()=>s(ln),children:"← Back"}),t.jsx("span",{children:"Transcript"})]}),a?t.jsx("div",{className:"ui-page-actions",children:t.jsx(it,{size:"sm",href:ut(a.agentId,e),onClick:c(ut(a.agentId,e)),children:"Open in chat"})}):null]}),t.jsx("p",{className:"ui-page-lede mono",children:e})]}),t.jsx(re,{message:l}),a?t.jsxs(t.Fragment,{children:[t.jsxs(hp,{children:[t.jsx(Zr,{label:"Agent",value:r(a.agentId),size:"sm"}),t.jsx(Zr,{label:"Runs",value:a.runs.length}),t.jsx(Zr,{label:"Tokens",value:`${Cn(a.usage.input)} / ${Cn(a.usage.output)}`,note:zj(a.usage)?`input / output, ${zj(a.usage)}`:"input / output"}),t.jsx(Zr,{label:"Started",value:St(a.createdAt,n),size:"sm"})]}),a.runs.length>0?t.jsx(lt,{title:"Runs",flush:!0,children:t.jsxs(da,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Started"}),t.jsx("th",{children:"Finished"}),t.jsx("th",{className:"num",children:"Turns"}),t.jsx("th",{children:"Stopped"}),t.jsx("th",{className:"num",children:"Tokens"}),t.jsx("th",{className:"num",children:"Cached"})]})}),t.jsx("tbody",{children:a.runs.map((u,h)=>t.jsxs("tr",{children:[t.jsxs("td",{className:"nowrap",children:[St(u.startedAt,n)," ",u.resumed?t.jsx($e,{children:"resumed"}):null]}),t.jsx("td",{className:"nowrap",children:St(u.finishedAt,n)}),t.jsx("td",{className:"num",children:u.turns??"—"}),t.jsxs("td",{children:[u.stopped??"—",u.actionId?t.jsxs("div",{className:"sub mono",children:["action ",Iu(u.actionId)]}):null]}),t.jsxs("td",{className:"num muted nowrap",children:[Cn(u.usage.input)," / ",Cn(u.usage.output)]}),t.jsx("td",{className:"num muted nowrap",children:u.usage.cacheRead||u.usage.cacheWrite?Cn((u.usage.cacheRead??0)+(u.usage.cacheWrite??0)):"—"})]},h))})]})}):null,t.jsx(ye,{title:"Messages",children:t.jsx(ue,{children:a.messages.map(u=>t.jsxs("article",{className:"transcript-msg",children:[t.jsxs("header",{className:"transcript-who",children:[u.speaker===aE?"approved action, result":u.role,", ",St(u.createdAt,n)]}),t.jsxs("div",{className:"transcript-body",children:[u.blocks.length===0?t.jsx("span",{className:"muted",children:"(empty)"}):null,u.speaker===aE?u.blocks.map((h,m)=>t.jsx(bte,{block:h},m)):u.blocks.map((h,m)=>t.jsx(kte,{block:h},m))]})]},u.id))})})]}):t.jsx(Ee,{children:"Loading…"})]})}const aE="approval:resume";function bte({block:e}){return t.jsxs("div",{className:"transcript-tool",children:[t.jsx("div",{className:"transcript-tool-name mono",children:"← approved action"}),t.jsx(Zt,{children:e.type==="text"?e.text??"":ms(e)})]})}function kte({block:e}){return e.type==="text"?t.jsx("div",{className:"transcript-text",children:t.jsx(pr,{text:e.text??""})}):e.type==="thinking"?t.jsxs("details",{className:"transcript-thinking",children:[t.jsx("summary",{children:"Thoughts"}),t.jsx("div",{className:"transcript-thinking-text",children:t.jsx(pr,{text:e.text??""})})]}):e.type==="thinking_hidden"?t.jsx("div",{className:"transcript-thinking-hidden",children:"Thinking (hidden)"}):e.ref===void 0&&e.type==="provider_native"?t.jsx(t.Fragment,{}):e.type==="tool_use"?t.jsxs("div",{className:"transcript-tool",children:[t.jsxs("div",{className:"transcript-tool-name mono",children:["→ ",e.name]}),t.jsx(Zt,{children:ms(e.input)})]}):e.type==="tool_result"?t.jsxs("div",{className:"transcript-tool","data-tone":e.isError?"critical":void 0,children:[t.jsxs("div",{className:"transcript-tool-name mono",children:["← ",e.isError?"error":"result"]}),t.jsx(Zt,{children:e.content??""})]}):t.jsxs("div",{className:"transcript-tool",children:[t.jsx("div",{className:"transcript-tool-name mono",children:e.type}),t.jsx(Zt,{children:ms(e.ref)})]})}function Nte(){const{data:e,reload:n}=je(()=>T.overview(),[],1e4),[s,r]=d.useState(!1);if(!e)return null;const a=()=>{r(!0),T.setPaused(!e.paused).then(n,n).finally(()=>r(!1))};return t.jsx($,{size:"sm",variant:e.paused?"accent":void 0,disabled:s,onClick:a,children:e.paused?"Resume all":"Pause all"})}function Ste(){const{data:e,reload:n}=je(()=>T.overview(),[],1e4);if(d.useEffect(()=>(window.addEventListener(Yi,n),()=>window.removeEventListener(Yi,n)),[n]),!e)return null;const s=a=>e.jobs[a]??0,r=s("leased");return t.jsxs(hp,{children:[t.jsx(Zr,{label:"Jobs done",value:Cn(s("succeeded"))}),t.jsx(Zr,{label:"Failed",value:Cn(s("failed")),...s("failed")>0?{tone:"critical"}:{}}),t.jsx(Zr,{label:"Queued",value:Cn(s("pending")),note:`${r} running`}),t.jsx(Zr,{label:"Approvals",value:Cn(e.approvals.pending),note:"waiting for you"})]})}const Cte=["replay-all","coalesce","latest-only","skip-after-deadline"],Ete=3e3;function Ck(e){const n=e.occurrences[0];return(n==null?void 0:n.state)==="pending"||(n==null?void 0:n.state)==="claimed"}function Ate(e){if(Ck(e))return"Running…";const n=e.occurrences[0];if((n==null?void 0:n.state)==="failed")return`Last run failed${n.finishedAt?` ${Xe(n.finishedAt)}`:""}${n.error?` — ${mr(n.error,120)}`:""}`;const s=e.lastNotification;return s?`Last run ${s.kind==="mission.delivered"?"reported":"stayed silent"} ${Xe(s.at)}${s.reason?` — ${s.reason}`:""}`:"Last run: none"}function uO({timezone:e,embedded:n,agentId:s}){const[r,a]=d.useState(()=>new Set),[i,l]=d.useState(!1),{data:o,error:c,reload:u}=je(()=>T.missions(),[],i||r.size>0?Ete:3e4),h=((o==null?void 0:o.missions)??[]).filter(w=>!s||w.agentId===s),[m,f]=d.useState(null),p=h.some(Ck);d.useEffect(()=>l(p),[p]);const x=async w=>{f(null);try{await w,u()}catch(v){f(v instanceof Error?v.message:String(v))}},g=async w=>{a(v=>new Set(v).add(w)),await x(T.runMission(w)),a(v=>{const j=new Set(v);return j.delete(w),j})};return t.jsxs(Is,{embedded:n,title:"Missions",lede:"Standing schedules. A disabled mission materializes nothing.",children:[t.jsx(re,{message:c??m}),!o||h.length===0?t.jsxs(ps,{icon:"calendar",title:"No missions yet",children:["Run ",t.jsx("code",{children:"buddi missions add-defaults"})," for the standard set."]}):t.jsx(ue,{children:h.map(w=>t.jsx($te,{mission:w,timezone:e,onRun:x,starting:r.has(w.id),onRunNow:()=>void g(w.id)},w.id))})]})}function $te({mission:e,timezone:n,onRun:s,starting:r,onRunNow:a}){var u;const[i,l]=d.useState(!1),o=e.enabled&&!e.pausedReason,c=r||Ck(e);return t.jsxs(Br,{tone:e.enabled&&!e.pausedReason?"good":"muted",title:t.jsxs(t.Fragment,{children:[e.name," ",t.jsx("span",{className:"mono muted",children:e.id})]}),meta:t.jsxs(t.Fragment,{children:[t.jsx($e,{mono:!0,children:e.agentId}),e.alwaysDeliver?t.jsx($e,{children:"always delivers"}):null,e.enabled?null:t.jsx($e,{tone:"warning",children:e.endedAt?"ended":"disabled"}),e.pausedReason?t.jsx($e,{tone:"warning",children:e.pausedReason}):null]}),actions:t.jsxs(t.Fragment,{children:[t.jsx($,{size:"sm",variant:"ghost",onClick:()=>l(h=>!h),"aria-expanded":i,children:i?"Less":"More"}),t.jsx($,{size:"sm",onClick:()=>s(T.setMissionEnabled(e.id,!e.enabled)),children:e.enabled?"Disable":"Enable"}),o?t.jsx($,{size:"sm",variant:"accent",disabled:c,onClick:a,children:"Run now"}):null]}),children:[e.stillUsefulAskedAt?t.jsx(Q,{tone:"warning",title:"Still useful?",action:t.jsxs(te,{align:"end",children:[t.jsx($,{size:"sm",onClick:()=>s(T.answerStillUseful(e.id,"stop")),children:"Stop"}),t.jsx($,{size:"sm",variant:"accent",onClick:()=>s(T.keepMission(e.id)),children:"Keep"})]}),children:`It has run ${e.quietRuns??"many"} times in a row without anything to tell you.`}):null,e.browser?t.jsxs(te,{children:[t.jsxs("span",{children:[t.jsx("strong",{children:e.browser==="owner"?"Uses your Chrome":"Own browser"}),t.jsx("span",{className:"muted",children:e.browser==="owner"?" · it may open pages in your signed-in Chrome while you are away":" · it opens pages only in buddi’s browser, never your Chrome"})]}),t.jsx(ht,{}),t.jsx(ac,{checked:e.browser==="owner",label:`Let ${e.name} use your Chrome`,onChange:h=>s(T.setMissionChrome(e.id,h))})]}):null,e.stopWhen||e.endsAt?t.jsxs("p",{className:"ui-card-meta",children:[e.stopWhen?`Stops itself when ${e.stopWhen}. `:"",e.endedAt?`Ended ${St(e.endedAt,n)}.`:e.endsAt?`Ends ${St(e.endsAt,n)}.`:""]}):null,t.jsxs("p",{className:"ui-card-meta",children:[e.schedule?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"mono",children:e.schedule.cron})," ",e.schedule.timezoneExplicit===!1?t.jsx("span",{title:e.schedule.timezone,children:"follows your timezone"}):e.schedule.timezone," ","· rev"," ",e.schedule.revision," · next"," ",e.nextRun?`${St(e.nextRun,n)} (${Xe(e.nextRun)})`:"—"]}):"no schedule — enqueued by hand or by a sentinel",t.jsx("br",{}),t.jsx("span",{role:"status",className:!c&&((u=e.occurrences[0])==null?void 0:u.state)==="failed"?"critical":void 0,children:c?"Running…":Ate(e)})]}),i?t.jsxs("div",{className:"ui-card-foot",children:[e.schedule?t.jsxs(te,{children:[t.jsx(le,{inline:!0,label:"Misfire policy",children:t.jsx("select",{value:e.schedule.misfirePolicy,onChange:h=>s(T.setMisfirePolicy(e.id,h.target.value)),children:Cte.map(h=>t.jsx("option",{value:h,children:h},h))})}),t.jsx("span",{className:"muted",children:"What a week asleep does: replay every instant, coalesce into one, keep only the latest, or skip past a deadline."})]}):null,t.jsx(ye,{title:"Prompt",children:t.jsx(Zt,{children:e.prompt})}),t.jsx(ye,{title:"Recent occurrences",children:t.jsx(lt,{flush:!0,children:e.occurrences.length===0?t.jsx(Ee,{children:"Never run."}):t.jsxs(da,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Scheduled"}),t.jsx("th",{children:"State"}),t.jsx("th",{children:"Finished"}),t.jsx("th",{children:"Detail"})]})}),t.jsx("tbody",{children:e.occurrences.map(h=>t.jsxs("tr",{children:[t.jsxs("td",{className:"nowrap",children:[St(h.scheduledAt,n)," ",h.manual?t.jsx($e,{children:"run now"}):null]}),t.jsx("td",{children:t.jsx(wd,{state:h.state})}),t.jsx("td",{className:"nowrap",children:St(h.finishedAt,n)}),t.jsxs("td",{className:h.error?"critical":"muted",children:[h.error?mr(h.error,120):null,h.runConversationId?t.jsx("a",{href:`#/conversations/${h.runConversationId}`,children:"transcript"}):null]})]},h.id))})]})})})]}):null]})}function Tte(e,n){const s=`${e} offer${e===1?"":"s"}`,r=n?` from ${n}`:"";return`Dismiss ${s}${r}? They stop appearing everywhere. Nothing runs, and you can still see them under "Dismissed and lapsed" for a week.`}function dO({ids:e,agentName:n,onDone:s}){const r=e.length,[a,i]=d.useState(!1),[l,o]=d.useState(!1);return r<=0?null:a?t.jsxs("span",{className:"ui-row",children:[t.jsx("span",{className:"muted",children:Tte(r,n)}),t.jsx($,{size:"sm",variant:"danger",disabled:l,onClick:()=>{o(!0),T.dismissOffers(e).then(()=>{i(!1),s()}).finally(()=>o(!1))},children:`Dismiss ${r}`}),t.jsx($,{size:"sm",variant:"ghost",disabled:l,onClick:()=>i(!1),children:"Keep them"})]}):t.jsx($,{size:"sm",variant:"ghost",onClick:()=>i(!0),children:"Dismiss all"})}function hO({embedded:e,agentId:n,agentName:s}){const{data:r,error:a,reload:i}=je(()=>T.offers(),[],2e4),l=v=>!n||v.agentId===n,o=((r==null?void 0:r.offers)??[]).filter(l),c=((r==null?void 0:r.closed)??[]).filter(l),[u,h]=d.useState(null),[m,f]=d.useState(null),[p,x]=d.useState(null),g=async(v,j)=>{h(null),f(v);try{const y=await T.takeOffer(v);x(y.jobId?`On it — ${j}. Started as job ${y.jobId}.`:`Taken — ${j}. No worker is running here, so nothing has started yet.`),i()}catch(y){h(y instanceof Error?y.message:String(y))}finally{f(null)}},w=async(v,j)=>{h(null),f(v);try{await T.dismissOffer(v),x(`Dismissed — ${j}. It will not come back.`),i()}catch(y){h(y instanceof Error?y.message:String(y))}finally{f(null)}};return t.jsxs(Is,{embedded:e,title:"Offers",lede:"Things an agent already worked out that you might want done. Taking one asks that agent the sentence it wrote. It authorizes nothing, and anything that would leave this machine still comes back to you as an approval.",children:[t.jsx(re,{message:a??u}),p?t.jsx(Q,{tone:"good",role:"status",children:p}):null,o.length>0?t.jsxs(te,{children:[t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx(dO,{ids:o.map(v=>v.id),agentName:s,onDone:()=>{x(null),i()}})]}):null,!r||o.length===0?t.jsx(ps,{icon:"bulb",title:"Nothing on offer",children:"When an agent works out something you might want done, it waits here."}):t.jsx(ue,{children:o.map(v=>t.jsx(Br,{tone:"accent",title:v.label,meta:t.jsxs(t.Fragment,{children:[t.jsx($e,{mono:!0,children:v.agentId}),t.jsxs("span",{className:"muted",children:["expires ",Xe(v.expiresAt)]})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx($,{size:"sm",variant:"ghost",disabled:m===v.id,onClick:()=>void w(v.id,v.label),children:"Not now"}),t.jsx($,{variant:"accent",size:"sm",disabled:m===v.id,onClick:()=>void g(v.id,v.label),children:"Take"})]}),children:t.jsx("p",{className:"ui-card-meta",children:v.prompt})},v.id))}),c.length>0?t.jsxs(Vt,{summary:`Dismissed and lapsed (${c.length})`,boxed:!0,children:[t.jsx(lt,{flush:!0,children:t.jsx(yt,{children:c.map(v=>t.jsx(pt,{title:v.label,sub:`${v.agentId} — ${gU(v)}`,side:Xe(v.dismissedAt??v.lapsedAt??v.createdAt)},v.id))})}),t.jsx("p",{className:"muted",children:"These stop being shown a week after they closed."})]}):null]})}function Rte(e){var r,a;const n=je(()=>T.agents(),[e]),s=(a=(r=n.data)==null?void 0:r.catalogue)==null?void 0:a[e];return{entry:s?{...s,agentId:e}:void 0,reload:n.reload}}function Ite({entry:e,navigate:n,onUpdated:s}){const[r,a]=d.useState(null),[i,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),T.catalogue().then(m=>{const f=m.agents.find(p=>p.name===e.package);f?a(f):l(m.unavailable??`The catalogue no longer lists ${e.title}.`)}).catch(m=>l(m instanceof pe?m.message:String(m))).finally(()=>c(!1))};return t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:"agent-catalogue-line","data-testid":"agent-catalogue-line","data-delisted":e.delisted?"true":void 0,children:[e.delisted?t.jsx("span",{children:"No longer in the catalogue"}):t.jsx("a",{href:En(e.package),onClick:m=>{m.preventDefault(),n(En(e.package))},children:"From the catalogue"}),t.jsx("span",{"aria-hidden":"true",children:" · "}),t.jsxs("span",{children:[e.title," ",e.via?`(was ${e.via.split("/")[1]??e.via})`:Mo(e.version)]}),e.delisted?t.jsx("span",{className:"muted",children:" · it keeps working; no updates will come"}):null,u?t.jsx($,{size:"sm",variant:u==="update"?"accent":void 0,disabled:o,onClick:h,children:u==="update"&&e.latest?`Update to ${Mo(e.latest)}`:u==="update"?"Update":"See what changed"}):null]}),i?t.jsx(re,{message:i}):null,r?t.jsx(RP,{entry:r,agentId:e.agentId,onClose:()=>a(null),onUpdated:s}):null]})}function Pte(e){return typeof e=="string"?e:e.name??e.id??"a mission"}function Mte({agentId:e,name:n,navigate:s}){const[r,a]=d.useState(!1),[i,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(!1),[m,f]=d.useState(null),p=()=>{a(!1),f(null),s(Pt)},x=k=>k instanceof pe?k.message:String(k),g=()=>{a(!0),c(null),l(null),T.agentRemovePreview(e).then(l).catch(k=>c(x(k)))},w=()=>{h(!0),c(null),T.removeAgent(e).then(k=>{var b;window.dispatchEvent(new Event(Rs));const N=(b=k.result)==null?void 0:b.delegateListsNotUpdated;if(Array.isArray(N)&&N.length>0){f(N.map(S=>String((S==null?void 0:S.handle)??(S==null?void 0:S.id)??"")));return}a(!1),s(Pt)}).catch(k=>c(x(k))).finally(()=>h(!1))},v=(i==null?void 0:i.pausesMissions.map(Pte))??[],j=(i==null?void 0:i.unusedPlugins)??[],y=((i==null?void 0:i.handedWorkBy)??[]).map(k=>`@${k}`);return t.jsxs(lt,{children:[t.jsxs(te,{children:[t.jsxs("div",{className:"agent-remove-text",children:[t.jsx("strong",{children:"Remove from team"}),t.jsx("span",{className:"muted",children:"Its file goes to the trash folder; what it remembers and its conversations stay."})]}),t.jsxs($,{variant:"danger-ghost",onClick:g,children:["Remove ",n,"…"]})]}),r&&m?t.jsx(Gt,{title:`${n} is off your team`,onClose:p,foot:t.jsx($,{variant:"accent",onClick:p,children:"Done"}),children:t.jsxs(Q,{tone:"warning",title:"Cleanup is incomplete",role:"status",children:["The delegate list of ",yn(m.map(k=>`@${k}`))," could not be updated and still names it. That entry reaches nobody; edit the list to remove it."]})}):r?t.jsxs(Gt,{title:`Remove ${n} from your team?`,onClose:()=>a(!1),foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:()=>a(!1),children:"Cancel"}),t.jsx($,{variant:"danger",disabled:u||!i,onClick:w,children:"Remove from team"})]}),children:[t.jsx(re,{message:o}),i?t.jsxs("div",{className:"ui-stack","data-testid":"remove-preview",children:[t.jsxs("p",{children:["@",i.handle,"’s folder moves to the trash folder, so it can be brought back by hand."]}),v.length>0?t.jsxs("p",{children:["Its ",v.length===1?"mission":"missions"," ",yn(v)," ",v.length===1?"is":"are"," paused."]}):null,y.length>0?t.jsxs("p",{children:[yn(y)," will stop handing work to it."]}):null,j.length>0?t.jsxs("p",{children:["No other agent uses ",yn(j.map(yp)),"; it stays installed."," ",t.jsxs("a",{href:ze("plugins"),onClick:k=>{k.preventDefault(),a(!1),s(ze("plugins"))},children:["Remove ",j.length===1?"it":"them"," in Settings → Plugins"]}),"."]}):null]}):o?null:t.jsx("p",{className:"muted",children:"Reading what it would change…"})]}):null]})}const fO=["January","February","March","April","May","June","July","August","September","October","November","December"],um=e=>e?{day:String(e.day),month:String(e.month),year:e.year?String(e.year):""}:{day:"",month:"",year:""};function dm(e){if(e.day===""&&e.month===""&&e.year.trim()==="")return null;if(e.day===""||e.month==="")return"incomplete";const s=e.year.trim();return s!==""&&!/^\d{4}$/.test(s)?"incomplete":{day:Number(e.day),month:Number(e.month),year:s===""?null:Number(s)}}const Ote=(e,n)=>(e??null)===(n??null)||!!e&&!!n&&e.day===n.day&&e.month===n.month&&(e.year??null)===(n.year??null),mO=(e,n=!0)=>`${e.day} ${fO[e.month-1]}${n&&e.year?` ${e.year}`:""}`;function dy({label:e,hint:n,value:s,onChange:r}){const a=dm(s)==="incomplete";return t.jsx(le,{group:!0,label:e,hint:a?"A day and a month; the year is optional, four digits.":n,children:t.jsxs("div",{className:"day-month",children:[t.jsxs("select",{"aria-label":`${e}: day`,value:s.day,onChange:i=>r({...s,day:i.target.value}),children:[t.jsx("option",{value:"",children:"Day"}),Array.from({length:31},(i,l)=>t.jsx("option",{value:String(l+1),children:l+1},l+1))]}),t.jsxs("select",{"aria-label":`${e}: month`,value:s.month,onChange:i=>r({...s,month:i.target.value}),children:[t.jsx("option",{value:"",children:"Month"}),fO.map((i,l)=>t.jsx("option",{value:String(l+1),children:i},i))]}),t.jsx("input",{"aria-label":`${e}: year (optional)`,inputMode:"numeric",placeholder:"Year",maxLength:4,value:s.year,onChange:i=>r({...s,year:i.target.value.replace(/\D/g,"")})})]})})}const Dte=8e3;function Lte(e){return e.kind==="policy"&&e.state==="open"&&String(e.payload.plugin??"")==="memory"&&e.ruleKind==="person"}function Fte(e){if(!e.next)return null;const n=e.next.what==="birthday"?"Birthday":"Anniversary",s=e.next.turning===null?"":e.next.what==="birthday"?` · turns ${e.next.turning}`:` · ${e.next.turning} years`;if(e.next.inDays===0)return`${n} today${s}`;if(e.next.inDays===1)return`${n} tomorrow${s}`;if(e.next.inDays<=14)return`${n} in ${e.next.inDays} days${s}`;if(e.next.inDays<=31)return`${n} in ${Math.round(e.next.inDays/7)} weeks`;const r=e[e.next.what];return r?`${n} ${mO(r,!1)}`:null}function iE({name:e,small:n}){return t.jsx("span",{className:"person-face","data-size":n?"sm":void 0,"aria-hidden":"true",children:e.trim().charAt(0).toUpperCase()})}function _te(){var w,v;const e=je(()=>T.people(),[],6e4),n=je(()=>T.proposals(),[],6e4),[s,r]=d.useState(null),[a,i]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(null),[h,m]=d.useState(null),f=async(j,y)=>{m(j),u(null);try{return await y(),e.reload(),n.reload(),!0}catch(k){return u(k instanceof pe?k.message:String(k)),!1}finally{m(null)}},p=(((w=n.data)==null?void 0:w.open)??[]).filter(Lte),x=((v=e.data)==null?void 0:v.people)??[],g=j=>[j.relationship,j.birthday?`born ${mO(j.birthday)}`:null].filter(Boolean).join(" · ")||"No details yet";return t.jsxs(ue,{gap:"lg",children:[c?t.jsx(Q,{tone:"critical",children:c}):null,p.length>0?t.jsxs(Q,{tone:"accent",title:p.length===1?"One person to keep?":`${p.length} people to keep?`,children:[t.jsx("p",{children:"Your agents and your notes name them. Keep them as people and every agent knows who they are; nothing is added until you say so."}),t.jsx(lt,{flush:!0,children:t.jsx(yt,{children:p.map(j=>{var y;return t.jsx(pt,{lead:t.jsx(iE,{name:String(((y=j.payload.matcher)==null?void 0:y.person)??"?"),small:!0}),title:String(j.payload.action??""),sub:t.jsx("span",{className:"person-from",children:j.why}),side:t.jsxs("span",{className:"person-side",children:[t.jsx($,{variant:"ghost",size:"sm",disabled:h!==null,onClick:()=>void f(`discard:${j.id}`,()=>T.discardProposal(j.id,"Not a person")),children:"Not a person"}),t.jsx($,{size:"sm",disabled:h!==null,onClick:()=>void f(`keep:${j.id}`,()=>T.keepProposal(j.id)),children:"Keep"})]})},j.id)})})}),p.length>1?t.jsx(te,{align:"end",children:t.jsxs($,{variant:"accent",size:"sm",disabled:h!==null,onClick:()=>void f("keep-all",()=>T.keepAllProposals(p.map(j=>j.id))),children:["Keep all (",p.length,")"]})}):null]}):null,t.jsxs(ye,{title:"People",aside:"every agent knows who they are",panel:!0,flush:!0,actions:t.jsx($,{variant:"accent",size:"sm",onClick:()=>r("new"),children:"Add a person"}),children:[e.data?x.length===0?t.jsx(Ee,{children:"Nobody yet. Tell any agent “Marion is my wife, her birthday is 14 March”, or add someone here. Agents ask before they add anyone you did not tell them about."}):t.jsx(yt,{children:x.map(j=>{const y=Fte(j);return t.jsx(pt,{label:`${j.name}: edit`,onClick:()=>r(j),lead:t.jsx(iE,{name:j.name}),title:j.name,sub:g(j),side:t.jsxs("span",{className:"person-side",children:[y?t.jsx($e,{tone:j.next&&j.next.inDays<=7?"accent":void 0,children:y}):null,j.reminders?t.jsx("span",{className:"person-bell",title:"Reminders on","aria-label":"Reminders on",children:t.jsx(ne,{name:"bell",size:14})}):null]})},j.id)})}):t.jsx(Ee,{children:e.error??"Loading…"}),t.jsx("p",{className:"person-note",children:"Agents read each person in one line: name, who they are to you, how to address them, their dates. Notes are read only when an agent looks the person up."})]}),s?t.jsx(zte,{person:s==="new"?null:s,onClose:()=>r(null),onSaved:()=>{r(null),e.reload()},onForget:j=>{r(null),i(j)}}):null,a?t.jsx(Ye,{title:`Forget ${a.name}?`,onClose:()=>i(null),foot:t.jsxs(te,{children:[t.jsx(ht,{}),t.jsx($,{variant:"ghost",onClick:()=>i(null),children:"Cancel"}),t.jsx($,{variant:"danger",disabled:h!==null,onClick:()=>{const j=a;f(`forget:${j.id}`,()=>T.forgetPerson(j.id)).then(y=>{i(null),y&&o({id:Date.now(),person:j})})},children:"Forget"})]}),children:t.jsxs("p",{children:["Every agent stops knowing who ",a.name," is",a.reminders!==null?", and the reminders for their dates are removed":"",". Notes that mention them stay in Notes."]})}):null,l?t.jsx(Qu,{title:`Forgot ${l.person.name}.`,duration:Dte,onUndo:()=>{const j=l.person;f(`restore:${j.id}`,()=>T.restorePerson(j.id))},onGone:()=>o(null)},l.id):null]})}function zte({person:e,onClose:n,onSaved:s,onForget:r}){const[a,i]=d.useState((e==null?void 0:e.name)??""),[l,o]=d.useState((e==null?void 0:e.relationship)??""),[c,u]=d.useState((e==null?void 0:e.addressAs)??""),[h,m]=d.useState(um(e==null?void 0:e.birthday)),[f,p]=d.useState(um(e==null?void 0:e.anniversary)),[x,g]=d.useState((e==null?void 0:e.notes)??""),[w,v]=d.useState((e==null?void 0:e.reminders)===!0),[j,y]=d.useState(!1),[k,N]=d.useState(null),b=dm(h),S=dm(f),C=b==="incomplete"||S==="incomplete",A=b!==null&&b!=="incomplete"||S!==null&&S!=="incomplete",E=async()=>{if(!C){y(!0),N(null);try{const R=P=>P.trim()===""?null:P.trim();await T.savePerson({...e?{id:e.id}:{},name:a.trim(),relationship:R(l),addressAs:R(c),birthday:b,anniversary:S,notes:R(x),reminders:A&&w}),s()}catch(R){N(R instanceof pe?R.message:String(R))}finally{y(!1)}}};return t.jsx(Ye,{title:e?e.name:"Add a person",onClose:n,foot:t.jsxs(te,{children:[e?t.jsx($,{variant:"danger-ghost",disabled:j,onClick:()=>r(e),children:"Forget…"}):null,t.jsx(ht,{}),t.jsx($,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:j||a.trim()===""||C,onClick:()=>void E(),children:j?"Saving…":"Save"})]}),children:t.jsxs(ue,{gap:"lg",children:[t.jsxs(Vs,{children:[t.jsx(le,{label:"Name",children:t.jsx("input",{value:a,maxLength:80,placeholder:"Marion",autoFocus:!e,onChange:R=>i(R.target.value)})}),t.jsx(le,{label:"Who they are to you",children:t.jsx("input",{value:l,maxLength:60,placeholder:"wife, brother, accountant…",onChange:R=>o(R.target.value)})})]}),t.jsx(le,{label:"How to address them",hint:"What agents call them when they write to you about them, or to them for you.",children:t.jsx("input",{value:c,maxLength:80,placeholder:a.trim()||"Mum, Dr Lee…",onChange:R=>u(R.target.value)})}),t.jsx(dy,{label:"Birthday",hint:"The year is optional.",value:h,onChange:m}),t.jsx(dy,{label:"Anniversary",hint:"A wedding, the day you met: the year is optional.",value:f,onChange:p}),t.jsx(le,{label:"Notes",hint:"Gift ideas, allergies, what they are into. Read when an agent looks them up.",children:t.jsx("textarea",{rows:3,maxLength:1e3,value:x,onChange:R=>g(R.target.value)})}),t.jsxs("div",{className:"person-remind","data-off":A?void 0:"true",children:[t.jsxs("div",{className:"person-remind-text",children:[t.jsx("div",{className:"person-remind-title",children:"Remind me of their dates"}),t.jsx("div",{className:"ui-field-hint",children:A?"A week before and on the day, from the front desk, with an offer to find something.":"Add a birthday or an anniversary first."})]}),t.jsx(ac,{checked:A&&w,disabled:!A,onChange:v,label:"Remind me of their dates"})]}),k?t.jsx(Q,{tone:"critical",children:k}):null]})})}const Ute=["fact","observation","todo"];function pO({embedded:e,agents:n,timezone:s,agentId:r,initialTab:a="people"}){const{data:i,error:l,reload:o}=je(()=>T.memory(r),[r],3e4),[c,u]=d.useState(null),[h,m]=d.useState(null),[f,p]=d.useState(null),[x,g]=d.useState(a),w=S=>{var C;return S==="shared"?"Everyone":((C=n.find(A=>A.id===S))==null?void 0:C.name)??S},v=async S=>{p(null);try{await S,o()}catch(C){p(C instanceof pe?C.message:String(C))}},j={nameOf:w,timezone:s,onChangePreference:S=>u({key:S.key,scope:S.scope}),onForgetPreference:S=>void v(T.forgetPreference({key:S.key,scope:S.scope})),onEditNote:S=>m(S),onForgetNote:S=>void v(T.forgetNote(S.id))},y=r?w(r):"",k=r&&i?{preferences:i.preferences.filter(S=>S.scope===r),notes:i.notes.filter(S=>S.scope===r)}:null,N=r&&i?{preferences:i.preferences.filter(S=>S.scope==="shared"),notes:i.notes.filter(S=>S.scope==="shared")}:null,b=t.jsx($,{variant:"accent",size:"sm",onClick:()=>u({key:"",scope:r??"shared"}),children:"Add a preference"});return t.jsxs(Is,{embedded:e,title:"Memory",lede:"What your agents have kept about you. Correct anything here; they see the change on their next turn.",children:[t.jsx(re,{message:l??f}),k&&N?t.jsxs(ue,{gap:"lg",children:[t.jsx(ye,{title:"Preferences",aside:`what you told ${y} alone`,actions:b,panel:!0,flush:!0,children:t.jsx(mx,{preferences:k.preferences,empty:`Nothing stated to ${y} alone yet.`,...j})}),t.jsx(ye,{title:"Notes",aside:`what ${y} wrote down for itself`,panel:!0,flush:!0,children:t.jsx(px,{notes:k.notes,empty:`${y} has kept no private notes yet.`,...j})}),t.jsx(Vt,{summary:`Shared with every agent, which ${y} also reads · ${N.preferences.length} preferences, ${N.notes.length} notes`,children:t.jsxs(ue,{gap:"lg",children:[t.jsx(ye,{title:"Shared preferences",panel:!0,flush:!0,children:t.jsx(mx,{preferences:N.preferences,empty:"No shared preferences.",...j})}),t.jsx(ye,{title:"Shared notes",panel:!0,flush:!0,children:t.jsx(px,{notes:N.notes,empty:"No shared notes.",...j})})]})})]}):t.jsxs(ue,{gap:"lg",children:[t.jsx(ic,{label:"Memory",children:[["people","People"],["preferences","Preferences",i==null?void 0:i.preferences.length],["notes","Notes",i==null?void 0:i.notes.length]].map(([S,C,A])=>t.jsx(ml,{href:`${ze("memory")}?tab=${S}`,active:x===S,...A?{count:A}:{},onClick:E=>{E.preventDefault(),g(S)},children:C},S))}),x==="people"?t.jsx(_te,{}):null,x==="preferences"?t.jsx(ye,{title:"Preferences",aside:"what you said you want, one current value each",actions:b,panel:!0,flush:!0,children:i?t.jsx(mx,{preferences:i.preferences,empty:'Nothing stated yet. Tell any agent "from now on…" or add one here.',...j}):t.jsx(Ee,{children:"Loading…"})}):null,x==="notes"?t.jsx(ye,{title:"Notes",aside:"what an agent wrote down, with who wrote it",panel:!0,flush:!0,children:i?t.jsx(px,{notes:i.notes,empty:"No notes yet. An agent writes one when you state something durable about your life.",...j}):t.jsx(Ee,{children:"Loading…"})}):null]}),c?t.jsx(Bte,{agents:n,existing:(i==null?void 0:i.preferences)??[],initial:c,onClose:()=>u(null),onSave:async S=>{await v((async()=>{await T.setPreference(S),c.key===S.key&&c.scope!==S.scope&&await T.forgetPreference({key:c.key,scope:c.scope})})()),u(null)}}):null,h?t.jsx(Wte,{note:h,agents:n,onClose:()=>m(null),onSave:S=>v(T.updateNote(h.id,S)).then(()=>m(null))}):null]})}function mx({preferences:e,empty:n,nameOf:s,onChangePreference:r,onForgetPreference:a}){return e.length===0?t.jsx(Ee,{children:n}):t.jsxs(da,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Preference"}),t.jsx("th",{children:"Value"}),t.jsx("th",{children:"Who sees it"}),t.jsx("th",{className:"num",children:"Since"}),t.jsx("th",{})]})}),t.jsx("tbody",{children:e.map(i=>t.jsxs("tr",{children:[t.jsx("td",{className:"mono",children:i.key}),t.jsx("td",{children:i.value}),t.jsx("td",{children:t.jsx(gO,{scope:i.scope,name:s(i.scope)})}),t.jsxs("td",{className:"num muted",title:i.updatedAt??"",children:[i.updatedAt?Xe(i.updatedAt,Date.now()):"",i.revision>1?` · rev ${i.revision}`:""]}),t.jsx("td",{className:"num",children:t.jsxs(te,{align:"end",children:[t.jsx($,{size:"sm",onClick:()=>r(i),title:"Store a new value for this key",children:"Change"}),t.jsx($,{size:"sm",variant:"ghost",onClick:()=>a(i),children:"Forget"})]})})]},`${i.scope}:${i.key}`))})]})}function px({notes:e,empty:n,nameOf:s,timezone:r,onEditNote:a,onForgetNote:i}){return e.length===0?t.jsx(Ee,{children:n}):t.jsxs(da,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Note"}),t.jsx("th",{children:"Kind"}),t.jsx("th",{children:"Who sees it"}),t.jsx("th",{children:"Written by"}),t.jsx("th",{className:"num",children:"When"}),t.jsx("th",{})]})}),t.jsx("tbody",{children:e.map(l=>t.jsxs("tr",{children:[t.jsx("td",{className:"memory-note",children:l.content}),t.jsx("td",{children:t.jsx($e,{tone:l.kind==="todo"?"warning":l.kind==="fact"?"good":void 0,children:l.kind})}),t.jsx("td",{children:t.jsx(gO,{scope:l.scope,name:s(l.scope)})}),t.jsx("td",{className:"muted",children:l.createdByAgent?s(l.createdByAgent):""}),t.jsxs("td",{className:"num muted",title:l.createdAt??"",children:[l.createdAt?Xe(l.createdAt,Date.now()):"",l.expiresAt?t.jsxs("span",{className:"memory-expires",children:[" · until ",Ks(new Date(l.expiresAt),r,{year:!0,compact:!0})]}):null]}),t.jsx("td",{className:"num",children:t.jsxs(te,{align:"end",children:[t.jsx($,{size:"sm",onClick:()=>a(l),children:"Edit"}),t.jsx($,{size:"sm",variant:"ghost",onClick:()=>i(l),children:"Forget"})]})})]},l.id))})]})}function gO({scope:e,name:n}){return t.jsx($e,{tone:e==="shared"?"accent":void 0,title:e==="shared"?"Every agent reads this":`Only ${n} reads this`,children:n})}function xO({value:e,agents:n,onChange:s}){return t.jsxs("select",{value:e,onChange:r=>s(r.target.value),children:[t.jsx("option",{value:"shared",children:"Everyone"}),n.map(r=>t.jsxs("option",{value:r.id,children:["Only ",r.name]},r.id))]})}function Bte({agents:e,existing:n,initial:s,onClose:r,onSave:a}){const i=n.find(j=>j.key===s.key&&j.scope===s.scope),[l,o]=d.useState(s.key),[c,u]=d.useState((i==null?void 0:i.value)??""),[h,m]=d.useState(s.scope),[f,p]=d.useState(!1),x=l.trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),g=n.find(j=>j.key===x&&j.scope===h),w=!i||x!==i.key||c.trim()!==i.value||h!==i.scope,v=x!==""&&c.trim()!==""&&w;return t.jsx(Ye,{title:"A preference",onClose:r,children:t.jsxs(ue,{children:[t.jsx(Q,{children:'A preference is a standing choice, in your words: "paid biweekly on Thursdays", "answers short, numbers first". Storing the same key again records a correction and keeps the old value in the history.'}),t.jsx(le,{label:"Key",hint:x&&x!==l?`Stored as ${x}`:"Short and stable, like reporting_currency or tone.",children:t.jsx("input",{value:l,autoFocus:s.key==="",onChange:j=>o(j.target.value),placeholder:"reporting_currency"})}),t.jsx(le,{label:"Value",children:t.jsx("textarea",{rows:3,value:c,maxLength:2e3,autoFocus:s.key!=="",onChange:j=>u(j.target.value),placeholder:"EUR"})}),t.jsx(le,{label:"Who should know",hint:"Shared reaches every agent. Private stays with one.",children:t.jsx(xO,{value:h,agents:e,onChange:m})}),g&&g!==i?t.jsxs(Q,{tone:"warning",children:['This replaces the value already stored for this key here, "',g.value,'" (revision ',g.revision,")."]}):null,i&&h!==i.scope?t.jsxs(Q,{children:["It moves: the copy for ",i.scope==="shared"?"everyone":"that agent"," is retired and this one takes over."]}):null,t.jsxs(te,{align:"end",children:[t.jsx($,{onClick:r,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:!v||f,onClick:()=>{p(!0),a({key:x,value:c.trim(),scope:h}).finally(()=>p(!1))},children:i?"Save change":"Save"})]})]})})}function Wte({note:e,agents:n,onClose:s,onSave:r}){var p;const[a,i]=d.useState(e.content),[l,o]=d.useState(e.scope),[c,u]=d.useState(e.kind),[h,m]=d.useState(!1),f=a.trim()!==e.content||l!==e.scope||c!==e.kind;return t.jsx(Ye,{title:"A note",onClose:s,children:t.jsxs(ue,{children:[t.jsx(le,{label:"What it says",hint:"One sentence that makes sense months from now, on its own.",children:t.jsx("textarea",{rows:4,value:a,maxLength:2e3,autoFocus:!0,onChange:x=>i(x.target.value)})}),t.jsxs(Vs,{children:[t.jsx(le,{label:"Kind",children:t.jsx("select",{value:c,onChange:x=>u(x.target.value),children:Ute.map(x=>t.jsx("option",{value:x,children:x},x))})}),t.jsx(le,{label:"Who sees it",children:t.jsx(xO,{value:l,agents:n,onChange:o})})]}),e.createdByAgent?t.jsxs("p",{className:"muted",children:["Written by ",((p=n.find(x=>x.id===e.createdByAgent))==null?void 0:p.name)??e.createdByAgent,e.createdAt?`, ${Xe(e.createdAt,Date.now())}`:"",". Editing keeps that record."]}):null,t.jsxs(te,{align:"end",children:[t.jsx($,{onClick:s,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:!f||a.trim()===""||h,onClick:()=>{m(!0);const x={};a.trim()!==e.content&&(x.content=a.trim()),l!==e.scope&&(x.scope=l),c!==e.kind&&(x.kind=c),r(x).finally(()=>m(!1))},children:"Save"})]})]})})}const hm="host.exec",Hte={bundle:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M3.4 6.4 10 3.2l6.6 3.2v7.2L10 16.8l-6.6-3.2Z"}),t.jsx("path",{d:"M3.4 6.4 10 9.6l6.6-3.2M10 9.6v7.2"})]})],folder:[16,1.5,t.jsx("path",{d:"M2.2 4.4a1 1 0 0 1 1-1h3l1.4 1.6h5.2a1 1 0 0 1 1 1v6.6a1 1 0 0 1-1 1H3.2a1 1 0 0 1-1-1Z"})],doc:[16,1.5,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M4.4 1.9h4.8l3 3v8.2a1 1 0 0 1-1 1H4.4a1 1 0 0 1-1-1V2.9a1 1 0 0 1 1-1Z"}),t.jsx("path",{d:"M9 2v3h3"})]})],script:[16,1.5,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"1.9",y:"2.6",width:"12.2",height:"10.8",rx:"1.4"}),t.jsx("path",{d:"m4.6 6.4 2 1.6-2 1.6M8.4 10h3"})]})],font:[16,1.5,t.jsx("path",{d:"M3.4 13 8 3l4.6 10M5 9.6h6"})],image:[16,1.5,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"2",y:"2.6",width:"12",height:"10.8",rx:"1.4"}),t.jsx("circle",{cx:"5.8",cy:"6.2",r:"1.2"}),t.jsx("path",{d:"m2.4 12 3.8-3.6 2.6 2.4 2-1.8 3 2.6"})]})],upload:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M10 13.2V3.6M6.2 7.2 10 3.4l3.8 3.8"}),t.jsx("path",{d:"M3.6 12.6v2.6a1.4 1.4 0 0 0 1.4 1.4h10a1.4 1.4 0 0 0 1.4-1.4v-2.6"})]})],shield:[16,1.5,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M8 1.8 13 3.6v4c0 3-2.1 5.4-5 6.6-2.9-1.2-5-3.6-5-6.6v-4Z"}),t.jsx("path",{d:"m5.8 8 1.6 1.6 2.8-3"})]})]};function fi({name:e,size:n}){const[s,r,a]=Hte[e];return t.jsx("svg",{width:n??s,height:n??s,viewBox:`0 0 ${s} ${s}`,"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:r,strokeLinecap:"round",strokeLinejoin:"round",children:a})}function Ek({size:e}){return t.jsx("span",{className:"ui-app-icon","data-size":e,"aria-hidden":"true",children:t.jsx(fi,{name:"bundle",size:e?22:18})})}const Kte={skill:"doc",script:"script",font:"font",image:"image",data:"doc",template:"doc",other:"doc"},Vte={skill:"The skill",script:"Script",font:"Font",image:"Picture",data:"Data",template:"Template",other:"File"};function Gte(e){const n=[],s=new Set,r=[...e].sort((a,i)=>a.path==="SKILL.md"?-1:i.path==="SKILL.md"?1:a.path.localeCompare(i.path));for(const a of r){const i=a.path.split("/");i.slice(0,-1).forEach((l,o)=>{const c=i.slice(0,o+1).join("/");s.has(c)||(s.add(c),n.push({dir:c,name:`${i[o]}/`,depth:o}))}),n.push({file:a,name:i[i.length-1],depth:i.length-1})}return n}function jO({files:e,selected:n,onSelect:s}){return t.jsx("ul",{className:"skb-tree",role:s?"listbox":void 0,"aria-label":"Files in the bundle",children:Gte(e).map(r=>"dir"in r?t.jsxs("li",{className:"skb-node","data-dir":"true","data-depth":Math.min(r.depth,6),children:[t.jsx(fi,{name:"folder",size:14}),t.jsx("span",{className:"skb-name",children:r.name})]},`d:${r.dir}`):t.jsxs("li",{className:"skb-node","data-depth":Math.min(r.depth,6),"data-kind":r.file.kind,"data-selected":n===r.file.path?"true":void 0,role:s?"option":void 0,"aria-selected":s?n===r.file.path:void 0,tabIndex:s?0:void 0,onClick:s?()=>s(r.file.path):void 0,onKeyDown:s?a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),s(r.file.path))}:void 0,children:[t.jsx(fi,{name:Kte[r.file.kind],size:14}),t.jsx("span",{className:"skb-name",title:r.file.path,children:r.name}),r.file.kind==="script"?t.jsx("span",{className:"skb-flag",children:r.file.setup?"setup":"script"}):null,t.jsx("span",{className:"skb-size",children:sa(r.file.size)})]},r.file.path))})}function qte(e,n){const s=e.setup?"A setup script. It didn’t run when you uploaded the bundle and never runs on its own. ":"";return n.untrusted?`${s}It can’t run until you mark the bundle as yours. Then it runs only when an agent you allow runs it with ${hm}, and asks you first.`:n.run.length?`${s}It runs only when ${ki(n.run)} ${n.run.length>1?"run":"runs"} it with ${hm}, and asks you first. It can read this bundle’s files, not change them.`:n.held?`${s}Nobody holding this skill can run scripts, so it never runs.`:`${s}It runs only when an agent you allow runs it, and asks you first. It can read the bundle’s files, not change them.`}function vO({file:e,skillView:n,read:s,imageUrl:r,reach:a}){const[i,l]=d.useState(null);if(d.useEffect(()=>{if(e.kind==="skill")return;let c=!0;return l({path:e.path}),s(e.path).then(u=>{c&&l({path:e.path,file:u.file})},u=>{c&&l({path:e.path,error:u instanceof pe?u.message:String(u)})}),()=>{c=!1}},[e.path,e.kind]),e.kind==="skill")return t.jsx("div",{className:"skb-view",children:n});const o=(i==null?void 0:i.path)===e.path?i.file:void 0;return t.jsxs("div",{className:"skb-view",children:[t.jsxs("div",{className:"skills-text-bar",children:[t.jsxs("span",{className:"skb-view-kind",children:[Vte[e.kind]," · ",sa(e.size)]}),t.jsx("span",{className:"skills-file mono",children:e.path})]}),e.kind==="script"?t.jsxs("p",{className:"skb-script-note",children:[t.jsx(fi,{name:"shield",size:14}),t.jsx("span",{children:qte(e,a)})]}):null,i!=null&&i.error?t.jsx(re,{message:i.error}):e.kind==="font"?t.jsxs("div",{className:"skb-blank",children:[t.jsx(fi,{name:"font",size:20}),t.jsx("span",{children:"A font. The skill’s scripts or documents set text with it; there’s nothing to read here."})]}):e.kind==="image"&&(o!=null&&o.image)?t.jsx("div",{className:"skb-picture",children:t.jsx("img",{src:r(e.path),alt:e.path})}):o?o.binary||o.text===void 0?t.jsxs("div",{className:"skb-blank",children:[t.jsx(fi,{name:"doc",size:20}),t.jsxs("span",{children:["Not text, so there’s nothing to read here. ",sa(e.size),"."]})]}):t.jsx(Zt,{label:e.path,children:o.text}):t.jsx("p",{className:"skills-note",children:"Reading the file…"})]})}function yO({children:e}){return t.jsx("div",{className:"skb-files",children:e})}function wO({children:e}){return t.jsxs("p",{className:"skb-promise",children:[t.jsx(fi,{name:"shield",size:16}),t.jsx("span",{children:e})]})}const Yte="Up to 20 MB and 500 files. Nothing in it runs when you upload it.";function Qte({initialRefusal:e,onClose:n,onMd:s,onStaged:r}){var g;const[a,i]=d.useState(!1),[l,o]=d.useState(e??null),[c,u]=d.useState(null),[h,m]=d.useState(null),f=d.useRef(null),p=w=>{if(!(!w||c)){if(m(null),/\.md$/i.test(w.name)){s(w);return}if(!/\.zip$/i.test(w.name)){o({kind:"notzip",filename:w.name});return}if(w.size>Lq){o({kind:"big",filename:w.name,size:w.size});return}u(w.name),pn.uploadBundle(w).then(v=>r(v),v=>{u(null),v instanceof GM?o(v.refusal):m(v instanceof pe?v.message:String(v))})}},x=l?Vq(l):null;return t.jsxs(Ye,{title:"Upload a skill",onClose:n,children:[t.jsx("input",{ref:f,type:"file",accept:".zip,.md,application/zip,text/markdown",hidden:!0,"data-testid":"skill-drop-file",onChange:w=>{var v;p((v=w.target.files)==null?void 0:v[0]),w.target.value=""}}),t.jsxs("div",{className:"skills-sheet skb-drop-sheet",children:[x?t.jsx(Q,{tone:"critical",title:x.title,role:"alert",children:t.jsxs("div",{className:"skb-refusal",children:[x.body,(g=x.items)!=null&&g.length?t.jsx("ul",{className:"skb-refused",children:x.items.map(w=>t.jsxs("li",{children:[t.jsx("span",{className:"mono",children:w.path})," ",w.rest]},w.path))}):null]})}):null,t.jsx(re,{message:h}),t.jsxs("div",{className:"skb-drop","data-over":a?"true":void 0,"data-testid":"skill-drop",onDragOver:w=>{w.preventDefault(),i(!0)},onDragLeave:()=>i(!1),onDrop:w=>{var v;w.preventDefault(),i(!1),p((v=w.dataTransfer.files)==null?void 0:v[0])},children:[t.jsx("span",{className:"skb-drop-glyph",children:t.jsx(fi,{name:"upload",size:24})}),t.jsx("span",{className:"skb-drop-title",children:c?`Reading “${c}”…`:a?"Drop to read it":x?"Drop another file here":"Drop a .zip or a .md here"}),t.jsx($,{variant:x?void 0:"accent",disabled:c!==null,onClick:()=>{var w;return(w=f.current)==null?void 0:w.click()},children:x?"Choose another file":"Choose a file"}),t.jsx("span",{className:"skb-drop-limits",children:Yte})]}),t.jsxs("section",{className:"skills-sec skb-shape","aria-label":"What a bundle looks like",children:[t.jsx("h3",{className:"skills-sec-title",children:"What a bundle looks like"}),t.jsxs("dl",{className:"skb-shape-tree",children:[t.jsx("dt",{className:"mono",children:"cover-art-kit/"}),t.jsx("dd",{}),t.jsx("dt",{className:"mono","data-in":"true",children:"SKILL.md"}),t.jsx("dd",{children:"the skill: a name, when it’s used, the steps"}),t.jsx("dt",{className:"mono","data-in":"true",children:"scripts/"}),t.jsx("dd",{children:"run only by an agent you allow, asking first"}),t.jsx("dt",{className:"mono","data-in":"true",children:"assets/"}),t.jsx("dd",{children:"fonts, templates, pictures it reads"})]})]})]})]})}function Jte({checked:e,onChange:n,lead:s,title:r,sub:a}){return t.jsxs("label",{className:"skills-pick-row",children:[t.jsx("input",{type:"checkbox",checked:e,onChange:i=>n(i.target.checked)}),s,t.jsxs("span",{className:"skills-pick-text",children:[t.jsx("span",{className:"skills-pick-title",children:r}),a?t.jsx("span",{className:"skills-pick-sub",children:a}):null]})]})}function Xte({staged:e,agents:n,faces:s,onClose:r,onBack:a,onAdded:i}){var b,S;const l=e.files.filter(C=>C.kind==="script"),[o,c]=d.useState(((b=l.find(C=>C.setup))==null?void 0:b.path)??((S=l[0])==null?void 0:S.path)??"SKILL.md"),[u,h]=d.useState([]),[m,f]=d.useState(!1),[p,x]=d.useState(!1),[g,w]=d.useState(null),v=n.filter(C=>C.canRunScripts).map(C=>C.name),j=e.files.find(C=>C.path===o)??e.files[0],y=C=>{pn.discardBundle(e.id).catch(()=>{}),C()},k=async()=>{x(!0),w(null);try{const{skill:C}=await pn.acceptBundle(e.id,{agents:u,mine:m});i(C)}catch(C){w(C instanceof pe?C.message:String(C)),x(!1)}},N=l.some(C=>C.setup);return t.jsxs(Ye,{size:"wide",title:t.jsxs("span",{className:"skills-sheet-title",children:[t.jsx(Ek,{size:"lg"}),t.jsxs("span",{className:"skills-sheet-name",children:[t.jsx("span",{children:e.filename}),t.jsxs("span",{className:"skills-sheet-by",children:[e.files.length," files · ",sa(e.size)," unpacked · read, not saved yet"]})]})]}),onClose:()=>y(r),foot:t.jsxs(te,{children:[t.jsx($,{variant:"ghost",onClick:()=>y(a),children:"Choose another file"}),t.jsx(ht,{}),t.jsx($,{variant:"ghost",onClick:()=>y(r),children:"Cancel"}),t.jsx($,{variant:"accent",disabled:p,onClick:()=>void k(),children:"Add the skill"})]}),children:[l.length?t.jsxs(Q,{title:`${l.length} script${l.length>1?"s":""} inside. None of them ran.`,children:["They run later only when an agent you allow runs them, after you mark the bundle as yours, and each run asks you first",N?" — setup scripts too.":"."]}):null,t.jsx(re,{message:g}),t.jsxs("div",{className:"skills-sheet",children:[t.jsxs("section",{className:"skills-sec","aria-label":"From its SKILL.md",children:[t.jsx("header",{className:"skills-sec-head",children:t.jsx("h3",{className:"skills-sec-title",children:"From its SKILL.md"})}),t.jsx(on,{items:[{label:"Name",value:e.skill.title},{label:"When it’s used",value:e.skill.description},{label:"First lines",value:t.jsxs("span",{className:"skb-first",children:[e.skill.firstLines,e.skill.firstLines.length>=160?"…":""]})}]})]}),t.jsxs("section",{className:"skills-sec","aria-label":"What’s inside",children:[t.jsxs("header",{className:"skills-sec-head",children:[t.jsx("h3",{className:"skills-sec-title",children:"What’s inside"}),t.jsxs("span",{className:"skills-sec-aside skills-note",children:[sa(e.size)," unpacked · ",sa(e.packed)," as a .zip"]})]}),t.jsxs(yO,{children:[t.jsx(jO,{files:e.files,selected:j.path,onSelect:c}),t.jsx(vO,{file:j,read:C=>pn.stagedFile(e.id,C),imageUrl:C=>pn.stagedImageUrl(e.id,C),reach:{run:[],held:!1,untrusted:!1},skillView:t.jsx(Zte,{staged:e})})]}),t.jsx("p",{className:"skills-note",children:"Checked: every file stays inside the bundle, no links, nothing over the limits. Pick a file to read it before you add it."})]}),t.jsxs("section",{className:"skills-sec","aria-label":"Who uses it",children:[t.jsx("header",{className:"skills-sec-head",children:t.jsx("h3",{className:"skills-sec-title",children:"Who uses it"})}),t.jsx("div",{className:"skills-who",children:n.filter(C=>C.writable).map(C=>t.jsx(Jte,{checked:u.includes(C.id),onChange:A=>h(A?[...u,C.id]:u.filter(E=>E!==C.id)),lead:t.jsx(Bn,{id:C.id,name:C.name,size:"sm",face:s.find(A=>A.id===C.id)}),title:C.name,sub:C.canRunScripts&&l.length?"can run scripts":void 0},C.id))}),t.jsx("p",{className:"skills-note",children:l.length?v.length?`Only ${ki(v)} ${v.length>1?"have":"has"} a tool that runs scripts; the others read the text. You can change this later.`:"No agent has a tool that runs scripts, so they all read the text only. You can change this later.":"You can change this later. With nobody ticked it’s kept and does nothing."})]}),t.jsx("section",{className:"skills-sec",children:t.jsxs("label",{className:"plugins-check",children:[t.jsx("input",{type:"checkbox",checked:m,onChange:C=>f(C.target.checked)}),t.jsxs("span",{children:[t.jsx("span",{className:"plugins-check-title",children:"Mark as mine"}),t.jsx("span",{className:"plugins-check-hint",children:l.length?"I wrote it, or I’ve read it and its scripts and trust them. Otherwise agents read its text as outside text and its scripts can’t run.":"I wrote it, or I’ve read it and trust it. Otherwise agents read its text as outside text."})]})]})})]})]})}function Zte({staged:e}){const[n,s]=d.useState(null);return d.useEffect(()=>{let r=!0;return pn.stagedFile(e.id,"SKILL.md").then(a=>{r&&s(a.file.text??"")},()=>{r&&s("")}),()=>{r=!1}},[e.id]),t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"skills-text-bar",children:[t.jsx("span",{className:"skb-view-kind",children:"The skill"}),t.jsx("span",{className:"skills-file mono",children:"SKILL.md"})]}),n===null?t.jsx("p",{className:"skills-note",children:"Reading the file…"}):t.jsx(Zt,{label:"SKILL.md",children:n})]})}const ene=5e4,xl=e=>e instanceof pe?e.message:String(e),tne=e=>n=>{n.stopPropagation(),e==null||e()};function nne({faces:e,navigate:n,command:s,openSkill:r,openFile:a}){const i=je(()=>pn.list(),[]),[l,o]=d.useState(r?{id:r,...a?{file:a}:{}}:null),[c,u]=d.useState(null),[h,m]=d.useState(null),[f,p]=d.useState(null),[x,g]=d.useState(null),w=d.useRef(null);d.useEffect(()=>{r&&o({id:r,...a?{file:a}:{}})},[r,a]),d.useEffect(()=>{s&&u(s.kind==="write"?{kind:"write"}:{kind:"drop"})},[s]);const v=N=>{var S;const b=(S=N.target.files)==null?void 0:S[0];N.target.value="",b&&j(b)},j=N=>{if(!/\.md$/i.test(N.name)){m(`“${N.name}” isn’t a .md file. A skill is one Markdown file.`);return}if(N.size>ene){m(`“${N.name}” is over 50 KB. A skill is a short text.`);return}const b=new FileReader;b.onload=()=>{m(null),u({kind:"upload",file:{name:N.name,size:N.size,...Yq(N.name,String(b.result))}})},b.readAsText(N)},y=N=>{p(null),N!==void 0&&g(N),i.reload()};return t.jsxs(t.Fragment,{children:[t.jsx("input",{ref:w,type:"file",accept:".md,text/markdown",hidden:!0,"data-testid":"skill-file",onChange:v}),h?t.jsx(Q,{tone:"warning",action:t.jsx($,{size:"sm",onClick:()=>{m(null),u({kind:"drop"})},children:"Pick another file"}),children:h}):null,t.jsx(re,{message:f}),x?t.jsx(Q,{tone:"good",role:"status",children:x}):null,t.jsx(sne,{view:i,onOpen:N=>o({id:N.id}),onAct:(N,b)=>k(N,b)}),t.jsx(bO,{view:i.data,faces:e,open:l,setOpen:o,dialog:c,setDialog:u,navigate:n,onChanged:y,onFailed:p}),(c==null?void 0:c.kind)==="write"&&i.data?t.jsx(oE,{agents:i.data.agents,faces:e,onClose:()=>u(null),onSaved:N=>{u(null),y(`Saved “${N.title}”.`)}}):null,(c==null?void 0:c.kind)==="drop"?t.jsx(Qte,{onClose:()=>u(null),onMd:N=>{u(null),j(N)},onStaged:N=>u({kind:"zip",staged:N})}):null,(c==null?void 0:c.kind)==="zip"&&i.data?t.jsx(Xte,{staged:c.staged,agents:i.data.agents,faces:e,onClose:()=>u(null),onBack:()=>u({kind:"drop"}),onAdded:N=>{u(null),y(`Added “${N.title}”.`),o({id:N.id})}}):null,(c==null?void 0:c.kind)==="upload"&&i.data?t.jsx(oE,{agents:i.data.agents,faces:e,upload:c.file,onClose:()=>u(null),onSaved:N=>{u(null),y(`Saved “${N.title}”.`)}}):null]});function k(N,b){g(null),b==="trust"?pn.trust(N.id).then(()=>y(),S=>p(xl(S))):b==="download"?YM(N.id):b==="plugin"?n(ze("plugins")):b==="edit"?(u(null),o({id:N.id,edit:!0})):u({kind:b,id:N.id})}}function sne({view:e,onOpen:n,onAct:s}){if(!e.data&&e.error)return t.jsx(Ee,{warm:!0,title:"Couldn’t load your skills",action:t.jsx($,{variant:"accent",size:"sm",onClick:e.reload,children:"Try again"}),children:"buddi didn’t answer. Your skill files are untouched."});if(!e.data)return t.jsx(ane,{});const{skills:r,agents:a}=e.data;return r.length===0?t.jsx(Ee,{warm:!0,title:"No skills yet",children:"A skill teaches an agent one kind of task, in plain words. Write one here, or upload a .md file you already have."}):t.jsx(lt,{flush:!0,children:ik.map(i=>{const l=r.filter(o=>o.group===i.id);return l.length?t.jsxs("section",{className:"skills-group","aria-label":i.title,children:[t.jsxs("header",{className:"skills-group-head",children:[t.jsx("h3",{className:"skills-group-title",children:i.title}),t.jsx("span",{className:"skills-group-aside",children:i.aside})]}),t.jsx(yt,{children:l.map(o=>t.jsx(rne,{row:o,agents:a,onOpen:n,onAct:s},o.id))})]},i.id):null})})}function rne({row:e,agents:n,onOpen:s,onAct:r}){var o,c,u;const a=e.untrusted?["trust","Mark as mine"]:Wq(e)?["picker","Choose agents"]:null,i=Bq(e,n),l=Kq(e,n);return t.jsx(pt,{onClick:()=>s(e),label:`${e.title}: details`,lead:e.bundle?t.jsx(Ek,{}):t.jsx(ss,{icon:"files"}),title:e.bundle?t.jsxs("span",{className:"skb-title",children:[e.title,t.jsx(Po,{children:"bundle"})]}):e.title,sub:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"skills-line",children:e.description}),t.jsxs("span",{className:"skills-line skills-meta",children:[i," · ",su(e,n,!0)]}),l?t.jsx("span",{className:"skills-line skb-scripts",children:l}):null,e.untrusted?t.jsx("span",{className:"skills-status","data-tone":"warning",children:ck(e,n)}):null]}),side:t.jsxs("span",{className:"skills-side",children:[a?t.jsx($,{size:"sm",onClick:tne(()=>r(e,a[0])),children:a[1]}):null,t.jsx(rs,{label:`More for ${e.title}`,sheet:{title:e.title,sub:i},items:[{label:"Choose agents…",hint:"Give it or take it away",onSelect:()=>r(e,"picker")},e.editable?{label:e.bundle?"Edit SKILL.md":"Edit text",onSelect:()=>r(e,"edit")}:null,{label:"Download",hint:e.bundle?".zip with its files":".md file",onSelect:()=>r(e,"download")},((o=e.from)==null?void 0:o.kind)==="plugin"?{label:`Open ${lk(e.from.plugin)}`,onSelect:()=>r(e,"plugin")}:null,e.deletable&&((c=e.from)==null?void 0:c.kind)!=="plugin"?"separator":null,e.deletable&&((u=e.from)==null?void 0:u.kind)!=="plugin"?{label:"Delete…",tone:"critical",onSelect:()=>r(e,"delete")}:null]})]})})}function ane(){return t.jsx(lt,{flush:!0,children:t.jsxs("div",{className:"skills-group skills-loading","aria-busy":"true","aria-label":"Loading skills",children:[t.jsx("header",{className:"skills-group-head",children:t.jsx("i",{className:"cat-skel-line","data-w":"20"})}),t.jsx(yt,{children:[0,1,2].map(e=>t.jsxs("div",{className:"ui-list-row",children:[t.jsx("span",{className:"ui-app-icon"}),t.jsxs("span",{className:"ui-list-main skills-skel",children:[t.jsx("i",{className:"cat-skel-line","data-w":"40"}),t.jsx("i",{className:"cat-skel-line","data-w":"70"})]})]},e))})]})})}function bO({view:e,faces:n,open:s,setOpen:r,dialog:a,setDialog:i,navigate:l,onChanged:o,onFailed:c}){if(!e)return null;const u=f=>e.skills.find(p=>p.id===f),h=s?u(s.id):void 0,m=a&&"id"in a?u(a.id):void 0;return t.jsxs(t.Fragment,{children:[h?t.jsx(ine,{row:h,agents:e.agents,faces:n,initialEdit:!!(s!=null&&s.edit),...s!=null&&s.file?{initialFile:s.file}:{},onClose:()=>r(null),onPicker:()=>i({kind:"picker",id:h.id}),onDelete:()=>i({kind:"delete",id:h.id}),onChanged:o,onFailed:c,navigate:l},`${h.id}-${s!=null&&s.edit?"edit":"read"}`):null,(a==null?void 0:a.kind)==="picker"&&m?t.jsx(lne,{row:m,agents:e.agents,faces:n,onCancel:()=>i(null),onSaved:()=>{i(null),o()}}):null,(a==null?void 0:a.kind)==="delete"&&m?t.jsx(cne,{row:m,agents:e.agents,onCancel:()=>i(null),onDeleted:f=>{i(null),r(null),o(f)}}):null]})}function kO({title:e,sub:n}){return t.jsxs("span",{className:"skills-sheet-title",children:[t.jsx(ss,{icon:"files",size:"lg"}),t.jsxs("span",{className:"skills-sheet-name",children:[t.jsx("span",{children:e}),t.jsx("span",{className:"skills-sheet-by",children:n})]})]})}function Bc({title:e,aside:n,children:s}){return t.jsxs("section",{className:"skills-sec","aria-label":e,children:[t.jsxs("header",{className:"skills-sec-head",children:[t.jsx("h3",{className:"skills-sec-title",children:e}),n?t.jsx("span",{className:"skills-sec-aside",children:n}):null]}),s]})}function lE({file:e,body:n,text:s}){const[r,a]=d.useState("read");return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"skills-text-bar",children:[t.jsx(cn,{label:"Show the text as",value:r,onChange:a,options:[{value:"read",label:"Read"},{value:"source",label:"Source"}]}),t.jsx("span",{className:"skills-file mono",children:e})]}),r==="read"?t.jsx(pr,{className:"wb-md skills-md",text:n}):t.jsx(Zt,{label:e,children:s})]})}function ine({row:e,agents:n,faces:s,initialEdit:r,initialFile:a,onClose:i,onPicker:l,onDelete:o,onChanged:c,onFailed:u,navigate:h}){var W,xe,me,ie;const m=je(()=>pn.detail(e.id),[e.id,e.updatedAt,e.untrusted,(W=e.learned)==null?void 0:W.version]),[f,p]=d.useState(!!r&&e.editable),[x,g]=d.useState(null),[w,v]=d.useState(!1),[j,y]=d.useState(null),[k,N]=d.useState(r?"SKILL.md":a??"SKILL.md"),b=((xe=m.data)==null?void 0:xe.text)??"",S=JM(su(e,n)),C=Gq(e,n),A=((me=e.from)==null?void 0:me.kind)==="plugin"?lk(e.from.plugin):null,E=H=>s.find(de=>de.id===H),R=e.bundle??null,P=((ie=m.data)==null?void 0:ie.bundle)??null,O=(R==null?void 0:R.scripts.length)??0,I=H=>{var de;return((de=n.find(ge=>ge.id===H))==null?void 0:de.canRunScripts)===!0},F=XM(e,n).filter(I).map(H=>dr(n,H)),U=async(H,de)=>{v(!0),y(null);try{await H(),de==null||de(),c()}catch(ge){y(xl(ge)),u(xl(ge))}finally{v(!1)}},L=H=>{U(()=>pn.grant(e.id,{agents:uk(e).filter(de=>de!==H)}))},M=()=>{U(()=>pn.saveText(e.id,x??b),()=>{p(!1),g(null)})},z=()=>{N("SKILL.md"),p(!0)},D=(H,de)=>{var ge,Ue;if(R)return O?I(H)?t.jsxs("span",{className:"skb-can",children:["Can run its scripts with ",t.jsx("span",{className:"mono",children:hm}),", asking each time"]}):"Reads the text only: it has no tool that runs scripts":"Uses the text and its files";if(((ge=e.learned)==null?void 0:ge.by)===H)return"Proposed it";if(((Ue=e.from)==null?void 0:Ue.kind)==="catalogue"&&e.from.agent===H)return"Came with it";if(de==="home")return"In its own folder"},K=t.jsx("textarea",{className:"skills-editor",value:x??b,onChange:H=>g(H.target.value),"aria-label":`Text of ${e.title}`,spellCheck:!1,autoFocus:!0}),B=R&&P?`Bundle · ${P.files.length} files · ${sa(P.size)} · ${su(e,n)}`:R?`Bundle · ${R.files+1} files · ${sa(R.size)} · ${su(e,n)}`:S,se=(P==null?void 0:P.files.find(H=>H.path===k))??(P==null?void 0:P.files[0]);return t.jsxs(Ye,{size:"wide",title:R?t.jsxs("span",{className:"skills-sheet-title",children:[t.jsx(Ek,{size:"lg"}),t.jsxs("span",{className:"skills-sheet-name",children:[t.jsx("span",{children:e.title}),t.jsx("span",{className:"skills-sheet-by",children:B})]})]}):t.jsx(kO,{title:e.title,sub:S}),onClose:i,foot:f?t.jsxs(te,{align:"end",children:[t.jsx($,{variant:"ghost",disabled:w,onClick:()=>{p(!1),g(null)},children:"Cancel"}),t.jsx($,{variant:"accent",disabled:w||!m.data,onClick:M,children:R?"Save SKILL.md":"Save"})]}):t.jsxs(te,{children:[e.deletable&&!A?t.jsx($,{variant:"danger-ghost",onClick:o,children:"Delete…"}):null,t.jsx(ht,{}),t.jsx($,{onClick:()=>YM(e.id),children:R?"Download .zip":"Download"}),e.editable?t.jsx($,{variant:e.untrusted?void 0:"accent",onClick:z,children:R?"Edit SKILL.md":"Edit text"}):null]}),children:[e.untrusted?t.jsxs(Q,{tone:"warning",action:t.jsx($,{size:"sm",variant:"accent",disabled:w,onClick:()=>void U(()=>pn.trust(e.id)),children:"Mark as mine"}),children:[ck(e,n)," Mark it as yours once you’ve read it",O?" and its scripts":"","."]}):null,t.jsx(re,{message:j}),t.jsxs("div",{className:"skills-sheet",children:[t.jsx(Bc,{title:"When it’s used",children:t.jsx("p",{className:"skills-desc",children:e.description})}),t.jsxs(Bc,{title:"Used by",aside:t.jsx($,{size:"sm",onClick:l,children:"Change…"}),children:[O?t.jsx(wO,{children:e.untrusted?"Its scripts can’t run until you mark it as yours. Then they run only when an agent you allow runs them, and ask first. Nothing ran when it was uploaded.":"Scripts run only when an agent you allow runs them, and ask first. Nothing ran when it was uploaded."}):null,e.every?t.jsx(yt,{children:t.jsx(pt,{lead:t.jsx(ss,{icon:"agents"}),title:ok(e,n),sub:O?F.length?`Now, and any you add later. ${ki(F)} can run its scripts, asking each time.`:"Now, and any you add later. None of them can run its scripts.":"Now, and any you add later."})}):e.holders.length?t.jsx("div",{className:R?"skb-holders":void 0,children:t.jsx(yt,{children:e.holders.map(H=>{const de=n.find(ge=>ge.id===H.agent);return t.jsx(pt,{lead:t.jsx(Bn,{id:H.agent,name:(de==null?void 0:de.name)??H.agent,size:"sm",face:E(H.agent)}),title:t.jsxs(t.Fragment,{children:[(de==null?void 0:de.name)??H.agent," ",t.jsxs("span",{className:"skills-handle",children:["@",(de==null?void 0:de.handle)??H.agent]})]}),sub:D(H.agent,H.how),side:H.how==="home"?void 0:t.jsx($,{size:"sm",variant:"ghost",disabled:w,onClick:()=>L(H.agent),"aria-label":`Take away from ${(de==null?void 0:de.name)??H.agent}`,children:"Take away"})},H.agent)})})}):t.jsx("p",{className:"skills-note",children:"No agent uses it yet, so it does nothing. Choose who should."})]}),R?t.jsxs(Bc,{title:"Files",aside:P?t.jsxs("span",{className:"skills-note",children:[P.files.length," files · ",sa(P.size)]}):void 0,children:[!m.data||!P||!se?m.error?t.jsx(re,{message:m.error}):t.jsx(Ee,{children:"Reading the bundle…"}):t.jsxs(yO,{children:[t.jsx(jO,{files:P.files,selected:se.path,onSelect:f?null:N}),t.jsx(vO,{file:se,read:H=>pn.file(e.id,H),imageUrl:H=>pn.imageUrl(e.id,H),reach:{run:F,held:e.every||e.holders.length>0,untrusted:e.untrusted!==null},skillView:f?K:t.jsx(lE,{file:l1(e),body:m.data.body,text:b})})]}),t.jsx("p",{className:"skills-note",children:"Read only, except SKILL.md. To change any other file, upload the bundle again."})]}):t.jsxs(Bc,{title:"The text",children:[m.data?f?K:t.jsx(lE,{file:l1(e),body:m.data.body,text:b}):m.error?t.jsx(re,{message:m.error}):t.jsx(Ee,{children:"Reading the file…"}),f&&C?t.jsx("p",{className:"skills-note",children:C}):null,A?t.jsxs("p",{className:"skills-note",children:["Comes with ",A,", so it’s changed there. To stop an agent using it, take it away above."," ",t.jsx("a",{href:ze("plugins"),onClick:H=>{H.preventDefault(),h(ze("plugins"))},children:"Open Plugins"})]}):null]})]})]})}function fm({checked:e,disabled:n,onChange:s,lead:r,title:a,sub:i}){return t.jsxs("label",{className:"skills-pick-row","data-disabled":n?"true":void 0,children:[t.jsx("input",{type:"checkbox",checked:e,disabled:n,onChange:l=>s(l.target.checked)}),r,t.jsxs("span",{className:"skills-pick-text",children:[t.jsx("span",{className:"skills-pick-title",children:a}),i?t.jsx("span",{className:"skills-pick-sub",children:i}):null]})]})}function NO({label:e,value:n,onChange:s}){return t.jsxs("div",{className:"cat-search",children:[t.jsx(ne,{name:"search",size:16}),t.jsx(fp,{label:e,value:n,placeholder:e,onChange:s})]})}function lne({row:e,agents:n,faces:s,onCancel:r,onSaved:a}){var N;const[i,l]=d.useState(e.every),[o,c]=d.useState(uk(e)),[u,h]=d.useState(""),[m,f]=d.useState(!1),[p,x]=d.useState(null),g=u.trim().toLowerCase(),w=n.filter(b=>!g||`${b.name} ${b.handle}`.toLowerCase().includes(g)),v=(b,S)=>c(S?[...o,b]:o.filter(C=>C!==b)),j=((N=e.bundle)==null?void 0:N.scripts.length)??0,y=j?[["Can run its scripts",w.filter(b=>b.canRunScripts)],["Text only",w.filter(b=>!b.canRunScripts)]]:[[null,w]],k=async()=>{f(!0),x(null);try{await pn.grant(e.id,i?{every:!0,agents:[]}:{agents:o}),a()}catch(b){x(xl(b))}finally{f(!1)}};return t.jsx(Gt,{title:`Who uses “${e.title}”?`,onClose:r,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:r,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:m,onClick:()=>void k(),children:"Save"})]}),children:t.jsxs("div",{className:"skills-pick",children:[j?t.jsxs(wO,{children:[j," script",j>1?"s":""," come",j>1?"":"s"," with it. Only an agent with a tool that runs commands can run them, and it asks you each time",e.untrusted?", once you’ve marked it as yours":"","."]}):null,t.jsx(NO,{label:"Find an agent",value:u,onChange:h}),t.jsx(re,{message:p}),t.jsxs("div",{className:"skills-pick-list",children:[g||!e.shareable?null:t.jsx(fm,{checked:i,onChange:l,lead:t.jsx(ss,{icon:"agents"}),title:"Every agent",sub:j?"Now and later. Scripts still ask each time.":"Now, and any you add later."}),y.map(([b,S])=>S.length?t.jsxs("div",{className:"skills-pick-group",role:b?"group":void 0,"aria-label":b??void 0,children:[b?t.jsxs("div",{className:"skills-pick-group-title",children:[b,b==="Text only"?" · no tool that runs scripts":" · asking you each time"]}):null,S.map(C=>{const A=e.home===C.id,E=(e.shadowedBy??[]).includes(C.id),R=A||E||!C.writable;return t.jsx(fm,{checked:!E&&(i||A||o.includes(C.id)),disabled:i||R,onChange:P=>v(C.id,P),lead:t.jsx(Bn,{id:C.id,name:C.name,size:"sm",face:s.find(P=>P.id===C.id)}),title:t.jsxs(t.Fragment,{children:[C.name," ",t.jsxs("span",{className:"skills-handle",children:["@",C.handle]})]}),sub:A?"Its own skill, in its folder":E?"Has its own skill of this name, and uses that":C.writable?j&&C.canRunScripts?t.jsxs("span",{className:"skb-can",children:["With ",t.jsx("span",{className:"mono",children:hm})]}):void 0:"Ships with buddi, so its file doesn’t change"},C.id)})]},b??"all"):null),w.length?null:t.jsxs("p",{className:"skills-note skills-pick-none",children:["No agent called “",u.trim(),"”."]})]}),t.jsx("p",{className:"skills-note",children:"Saved in each agent’s file, so the file stays the record."})]})})}function one({agent:e,view:n,onCancel:s,onSaved:r}){const a=j=>QM(j,e.id),[i,l]=d.useState(n.skills.filter(a).map(j=>j.id)),[o,c]=d.useState(""),[u,h]=d.useState(!1),[m,f]=d.useState(null),p=o.trim().toLowerCase(),x=j=>!p||`${j.title} ${j.description}`.toLowerCase().includes(p),g=j=>j.every||j.home===e.id||!e.writable,w=async()=>{h(!0),f(null);try{for(const j of n.skills){if(g(j))continue;const y=i.includes(j.id);if(y===a(j))continue;const k=uk(j);await pn.grant(j.id,{agents:y?[...k,e.id]:k.filter(N=>N!==e.id)})}r()}catch(j){f(xl(j))}finally{h(!1)}},v=n.skills.some(x);return t.jsx(Gt,{title:`Skills ${e.name} uses`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:u||!e.writable,onClick:()=>void w(),children:"Save"})]}),children:t.jsxs("div",{className:"skills-pick",children:[t.jsx(NO,{label:"Find a skill",value:o,onChange:c}),t.jsx(re,{message:m}),e.writable?null:t.jsxs("p",{className:"skills-note",children:[e.name," ships with buddi, so its file doesn’t change. Ask Agent Father to make it yours first."]}),t.jsxs("div",{className:"skills-pick-list",children:[ik.map(j=>{const y=n.skills.filter(k=>k.group===j.id&&x(k));return y.length?t.jsxs("div",{className:"skills-pick-group",role:"group","aria-label":j.title,children:[t.jsx("div",{className:"skills-pick-group-title",children:j.title}),y.map(k=>t.jsx(fm,{checked:i.includes(k.id),disabled:g(k),onChange:N=>l(N?[...i,k.id]:i.filter(b=>b!==k.id)),title:k.title,sub:k.every?a(k)?"Every agent uses it":ok(k,n.agents):k.home===e.id?"Its own skill, in its folder":k.description},k.id))]},j.id):null}),v?null:t.jsxs("p",{className:"skills-note skills-pick-none",children:["No skill matches “",o.trim(),"”."]})]})]})})}function oE({agents:e,faces:n,upload:s,onClose:r,onSaved:a}){const[i,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)??""),[m,f]=d.useState([]),[p,x]=d.useState(!1),[g,w]=d.useState(!1),[v,j]=d.useState(null),y=i.trim()!==""&&o.trim()!==""&&u.trim()!=="",k=s?`${Math.max(1,Math.round(s.size/1024))} KB`:"",N=async()=>{w(!0),j(null);try{const{skill:b}=await pn.create({title:i.trim(),description:o.trim(),body:u,agents:m,...s?{upload:{filename:s.name,mine:p}}:{}});a(b)}catch(b){j(xl(b))}finally{w(!1)}};return t.jsxs(Ye,{size:"wide",title:s?t.jsx(kO,{title:s.name,sub:`${k} · read, not saved yet`}):"Write a skill",onClose:r,foot:t.jsxs(te,{align:"end",children:[t.jsx($,{variant:"ghost",onClick:r,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:!y||g,onClick:()=>void N(),children:"Save skill"})]}),children:[t.jsx(re,{message:v}),t.jsxs("div",{className:"skills-sheet",children:[t.jsxs("section",{className:"skills-sec skills-form",children:[t.jsx(le,{label:"Name",hint:"Short, like a task: “Weekly money recap”.",children:t.jsx("input",{value:i,onChange:b=>l(b.target.value),autoFocus:!s})}),t.jsx(le,{label:"When it’s used",hint:"One line. Agents read it to decide when the skill applies.",children:t.jsx("input",{value:o,onChange:b=>c(b.target.value),placeholder:"When I ask about the week’s spending"})}),t.jsx(le,{label:"The text",hint:"Plain Markdown: steps, rules, what a good answer looks like.",children:t.jsx("textarea",{className:"skills-editor",value:u,onChange:b=>h(b.target.value),spellCheck:!1,placeholder:`1. Total spent this week.
134
- 2. The three biggest charges.
135
- 3. Anything odd.`})})]}),t.jsxs(Bc,{title:"Who uses it",children:[t.jsx("div",{className:"skills-who",children:e.map(b=>t.jsx(fm,{checked:m.includes(b.id),disabled:!b.writable,onChange:S=>f(S?[...m,b.id]:m.filter(C=>C!==b.id)),lead:t.jsx(Bn,{id:b.id,name:b.name,size:"sm",face:n.find(S=>S.id===b.id)}),title:b.name},b.id))}),t.jsx("p",{className:"skills-note",children:"You can change this later. With nobody ticked it’s kept and does nothing."})]}),s?t.jsx("section",{className:"skills-sec",children:t.jsxs("label",{className:"plugins-check",children:[t.jsx("input",{type:"checkbox",checked:p,onChange:b=>x(b.target.checked)}),t.jsxs("span",{children:[t.jsx("span",{className:"plugins-check-title",children:"Mark as mine"}),t.jsx("span",{className:"plugins-check-hint",children:"I wrote it, or I’ve read it and trust it. Otherwise agents read it as outside text."})]})]})}):null]})]})}function cne({row:e,agents:n,onCancel:s,onDeleted:r}){const a=je(()=>pn.detail(e.id),[e.id]),[i,l]=d.useState(!1),[o,c]=d.useState(null),u=d.useMemo(()=>a.data?qq(e,a.data.onDelete,n):null,[a.data,e,n]),h=async()=>{l(!0),c(null);try{const m=await pn.remove(e.id);r(`Deleted “${e.title}”.${m.movedTo?" The file is in the trash folder.":m.versionsKept?" Its earlier versions are kept.":""}`)}catch(m){c(xl(m)),l(!1)}};return t.jsxs(Gt,{title:`Delete “${e.title}”?`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx($,{variant:"danger",disabled:i||!a.data,onClick:()=>void h(),children:"Delete"})]}),children:[t.jsx(re,{message:o??a.error}),t.jsx("p",{className:"skills-dialog-text",children:u??"Checking who uses it…"})]})}function une(e){var n;return((n=ik.find(s=>s.id===e.group))==null?void 0:n.title)??""}function dne({agentId:e,agentName:n,faces:s=[],navigate:r}){const a=je(()=>pn.list(),[e]),[i,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(!1),[m,f]=d.useState(null),[p,x]=d.useState(null),g=N=>{f(null),x(N??null),a.reload()},w=N=>{pn.trust(N.id).then(()=>g(),b=>f(b instanceof Error?b.message:String(b)))};if(!a.data)return a.error?t.jsx(Ee,{warm:!0,title:"Couldn’t load the skills",action:t.jsx($,{variant:"accent",size:"sm",onClick:a.reload,children:"Try again"}),children:"buddi didn’t answer. The skill files are untouched."}):t.jsx(Ee,{children:"Loading…"});const v=a.data,j=v.agents.find(N=>N.id===e)??{id:e,handle:e,name:n,writable:!1},y=v.skills.filter(N=>QM(N,e)),k=qM();return t.jsxs(t.Fragment,{children:[t.jsx(re,{message:m}),p?t.jsx(Q,{tone:"good",role:"status",children:p}):null,t.jsx(lt,{flush:!0,title:"Skills",actions:t.jsxs(t.Fragment,{children:[t.jsxs("a",{className:"skills-all",href:k,onClick:N=>{N.preventDefault(),r(k)},children:["All skills",t.jsx(ne,{name:"chevron-right",size:12})]}),t.jsx($,{size:"sm",onClick:()=>h(!0),children:"Choose skills…"})]}),children:y.length?t.jsx("div",{className:"skills-group",children:t.jsx(yt,{children:y.map(N=>t.jsx(pt,{onClick:()=>l({id:N.id}),label:`${N.title}: details`,lead:t.jsx(ss,{icon:"files"}),title:N.title,sub:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"skills-line",children:N.description}),t.jsxs("span",{className:"skills-line skills-meta",children:[une(N)," · ",N.every?"every agent uses it":su(N,v.agents,!0)]}),N.untrusted?t.jsx("span",{className:"skills-status","data-tone":"warning",children:ck(N,v.agents)}):null]}),side:t.jsx("span",{className:"skills-side",children:N.untrusted?t.jsx($,{size:"sm",onClick:b=>{b.stopPropagation(),w(N)},children:"Mark as mine"}):t.jsx("span",{className:"skills-chevron","aria-hidden":"true",children:t.jsx(ne,{name:"chevron-right",size:14})})})},N.id))})}):t.jsxs(Ee,{children:[n," uses no skills yet. Choose some, or write one on the Skills page."]})}),t.jsx(bO,{view:v,faces:s,open:i,setOpen:l,dialog:o,setDialog:c,navigate:r,onChanged:g,onFailed:f}),u?t.jsx(one,{agent:j,view:v,onCancel:()=>h(!1),onSaved:()=>{h(!1),g()}}):null]})}function SO({timezone:e,embedded:n,agentId:s}){const{data:r,error:a,reload:i}=je(()=>T.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 T.cancelReminder(h),i()}catch(m){c(m instanceof Error?m.message:String(m))}};return t.jsxs(Is,{embedded:n,title:"Reminders",lede:"A reminder wakes an agent with a note and the instruction to check before it speaks, never a message queued for delivery.",children:[t.jsx(re,{message:a??o}),t.jsx(lt,{flush:!0,children:r?l.length===0?t.jsx(ps,{icon:"bell",title:"No reminders",children:"Ask any agent to remind you of something, and it shows up here."}):t.jsxs(da,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Due"}),t.jsx("th",{children:"Agent"}),t.jsx("th",{children:"Note"}),t.jsx("th",{children:"State"}),t.jsx("th",{})]})}),t.jsx("tbody",{children:l.map(h=>t.jsxs("tr",{children:[t.jsxs("td",{className:"nowrap",children:[St(h.dueAt,e),t.jsx("div",{className:"sub",children:Xe(h.dueAt)})]}),t.jsx("td",{className:"mono",children:h.agentId}),t.jsxs("td",{children:[h.text,h.context?t.jsx(Vt,{summary:"context",children:t.jsx(Zt,{children:ms(h.context)})}):null]}),t.jsxs("td",{children:[t.jsx(wd,{state:h.state}),h.cancelReason?t.jsx("div",{className:"sub",children:h.cancelReason}):null]}),t.jsx("td",{children:h.state==="pending"?t.jsx($,{size:"sm",variant:"danger",onClick:()=>u(h.id),children:"Cancel"}):null})]},h.id))})]}):t.jsx(Ee,{children:"Loading…"})})]})}const hne=/(flux|klein|schnell|qwen[-_]?image|image)/i;function CO(e){return e.kind==="image"||e.kind===void 0&&hne.test(e.id)}function fne(e){const n=((e==null?void 0:e.models)??[]).filter(s=>!CO(s));return[...n.filter(s=>s.loaded),...n.filter(s=>!s.loaded)].map(s=>s.id)}function hy(e){return fne(e)[0]}function Ak(e){return(e==null?void 0:e.detectedContextWindowSource)==="mlxh"}function mne(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 EO(e){let n=e;try{n=new URL(e).host}catch{}return`mlxh is not answering on ${n}. Start it with \`mlxh serve\`, or \`mlxh service install\` to keep it running.`}const AO="an image model; pick it in the Image plugin, not here";function $k({accountId:e,label:n,value:s,onChange:r,disabled:a=!1,origin:i="from the provider",suggest:l,onSuggest:o}){const[c,u]=d.useState(null),[h,m]=d.useState(!1),[f,p]=d.useState(""),[x,g]=d.useState(!1),w=d.useRef(0),v=async S=>{if(!e)return;const C=++w.current;m(!0),p("");try{const A=await T.accountModels(e,S);if(C===w.current){u(A);const E=(l==null?void 0:l(A))??null;E&&(o==null||o(E))}}catch(A){C===w.current&&p(A instanceof Error?A.message:"Could not load models. Custom entry is still available.")}finally{C===w.current&&m(!1)}};if(d.useEffect(()=>(u(null),g(!1),p(""),v(!1),()=>{w.current++}),[e]),!e)return t.jsxs(t.Fragment,{children:[t.jsx(le,{label:n,children:t.jsx("input",{required:!0,maxLength:150,value:s,disabled:a,onChange:S=>r(S.target.value)})}),t.jsx("p",{className:"ui-toolbar-note",children:"Save and connect the account to load its model list. You can enter a model manually now."})]});const j=(c==null?void 0:c.models)??[],y=c&&l?l(c):null,k=!!s&&!j.some(S=>S.id===s),N=[c&&!j.length?"This account returned no models. You can enter a custom model.":null,c!=null&&c.truncated?"Showing the first part of this provider’s list. Custom model entry is available.":null,c?"Uses saved account settings. Listed models may not support every agent tool. Your selection is unchanged until you save.":null].filter(Boolean),b=(c==null?void 0:c.source)==="built-in"?"built-in list":(c==null?void 0:c.source)==="provider"?[i,c.fetchedAt?`refreshed ${yR(c.fetchedAt)}`:""].filter(Boolean).join(" · "):"";return t.jsxs(t.Fragment,{children:[t.jsx(le,{label:n,children:t.jsxs("select",{value:x?"__buddi_custom__":s,disabled:a,onChange:S=>{S.target.value==="__buddi_custom__"?g(!0):(g(!1),r(S.target.value))},children:[t.jsx("option",{value:"",disabled:!0,children:"Choose a model"}),k&&t.jsxs("option",{value:s,children:[s," (current",c?", not listed":"",")"]}),j.map(S=>t.jsxs("option",{value:S.id,children:[S.name===S.id?S.id:`${S.name} — ${S.id}`,S.id===y?" (suggested)":S.isDefault?" (provider default)":"",S.image?` — ${AO}`:""]},S.id)),t.jsx("option",{value:"__buddi_custom__",children:"Custom model…"})]})}),t.jsx($,{disabled:a||h,onClick:()=>void v(!0),children:h?"Loading models…":"Refresh models"}),x&&t.jsx(le,{label:`Custom ${n.toLowerCase()}`,children:t.jsx("input",{required:!0,maxLength:150,value:s,disabled:a,onChange:S=>r(S.target.value)})}),f&&t.jsx("p",{role:"alert",className:"ui-toolbar-note critical",children:f}),N.length>0&&t.jsx("p",{className:"ui-toolbar-note",children:N.join(" ")}),b&&t.jsx("p",{className:"ui-toolbar-note muted","data-testid":"model-list-source",children:b})]})}function pne(e,n){const s=new Set(n),r=[],a=new Set;for(const i of e){for(const o of i.tools)a.add(o.name);const l=i.tools.filter(o=>s.has(o.name));l.length!==0&&(i.glob&&l.length===i.tools.length?r.push(i.glob):r.push(...l.map(o=>o.name)))}return r.push(...n.filter(i=>!a.has(i))),r}function gne(e,n){return[...e].sort().join(",")===[...n].sort().join(",")}const xne="This agent will not remember anything between conversations.";function jne({view:e,chosen:n,onChange:s,disabled:r}){var N;const[a,i]=d.useState(""),[l,o]=d.useState(null),[c,u]=d.useState(()=>new Set),h=b=>u(S=>{const C=new Set(S);return C.has(b)?C.delete(b):C.add(b),C}),m=b=>{i(b),u(new Set)},f=d.useId(),p=new Set(n),x=new Set(e.groups.flatMap(b=>b.tools.filter(S=>S.core).map(S=>S.name))),g=(b,S)=>{const C=S.filter(A=>p.has(A));if(C.length!==0){if(C.some(A=>x.has(A))){o({plugin:b,names:C});return}s(n.filter(A=>!C.includes(A)))}},w=b=>{s([...n,...b.filter(S=>!p.has(S))])},v=a.trim().toLowerCase(),j=(b,S)=>v===""||b.toLowerCase().includes(v)||S.toLowerCase().includes(v),y=e.groups.map(b=>({group:b,tools:b.tools.filter(S=>j(S.name,S.description))})).filter(b=>b.tools.length>0),k=(((N=e.suggested)==null?void 0:N.tools)??[]).filter(b=>!p.has(b.name));return t.jsxs("div",{className:"tool-picker",children:[e.suggested&&k.length>0?t.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":`${f}-suggested`,children:[t.jsx("div",{className:"tool-picker-head",children:t.jsx("span",{id:`${f}-suggested`,className:"tool-picker-plugin",children:e.suggested.label})}),t.jsx("ul",{className:"ui-list tool-picker-list","aria-label":e.suggested.label,children:k.map(b=>t.jsxs("li",{className:"ui-list-row",children:[t.jsxs("span",{className:"ui-list-main",children:[t.jsx("span",{className:"ui-list-title mono",children:b.name}),t.jsx("span",{className:"ui-list-sub",children:b.description})]}),t.jsx($,{size:"sm",disabled:r,"aria-label":`Add ${b.name}`,onClick:()=>w([b.name]),children:"Add"})]},b.name))})]}):null,t.jsxs("label",{className:"tool-picker-search",children:[t.jsx("span",{className:"ui-field-label",children:"Find a tool"}),t.jsx("input",{type:"search",value:a,placeholder:"Name or what it does",onChange:b=>m(b.target.value)})]}),y.length===0?t.jsxs(Ee,{children:["No installed tool matches “",a.trim(),"”."]}):null,y.map(({group:b,tools:S})=>{const C=b.tools.filter(I=>I.grantable).map(I=>I.name),A=b.tools.filter(I=>p.has(I.name)).length,E=!!b.glob&&A===b.tools.length,R=`${f}-${b.plugin}`,P=`${f}-${b.plugin}-list`,O=v!==""?!c.has(b.plugin):c.has(b.plugin);return t.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":R,"data-open":O?"true":void 0,children:[t.jsxs("div",{className:"tool-picker-head",children:[t.jsxs("button",{type:"button",className:"tool-picker-toggle","aria-expanded":O,"aria-controls":P,onClick:()=>h(b.plugin),children:[t.jsx(vne,{}),t.jsx("span",{id:R,className:"tool-picker-plugin",children:b.plugin}),t.jsx("span",{className:"muted",children:E?`all ${b.tools.length}`:`${A} of ${b.tools.length} granted`})]}),t.jsx($,{size:"sm",variant:"ghost","aria-label":`All ${b.plugin} tools`,disabled:r||C.every(I=>p.has(I)),onClick:()=>w(C),children:"all"}),t.jsx($,{size:"sm",variant:"ghost","aria-label":`No ${b.plugin} tools`,disabled:r||!C.some(I=>p.has(I)),onClick:()=>g(b.plugin,C),children:"none"})]}),(l==null?void 0:l.plugin)===b.plugin?t.jsx(Q,{tone:"warning",role:"alert",children:t.jsxs("div",{className:"tool-picker-confirm",children:[t.jsx("span",{children:xne}),t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx($,{size:"sm",onClick:()=>o(null),children:"Keep"}),t.jsx($,{size:"sm",variant:"danger",onClick:()=>{s(n.filter(I=>!l.names.includes(I))),o(null)},children:"Remove"})]})}):null,t.jsx("ul",{id:P,className:"ui-list tool-picker-list",hidden:!O,children:S.map(I=>{const F=`${f}-${I.name}`;return t.jsxs("li",{className:"ui-list-row",children:[t.jsx("input",{type:"checkbox",id:F,checked:p.has(I.name),disabled:r||!I.grantable,onChange:U=>U.target.checked?w([I.name]):g(b.plugin,[I.name])}),t.jsxs("label",{htmlFor:F,className:"ui-list-main",children:[t.jsxs("span",{className:"ui-list-title",children:[t.jsx("span",{className:"mono",children:I.name}),I.core?t.jsx($e,{tone:"accent",children:"core"}):null,I.gated?t.jsx($e,{tone:"warning",children:"asks you"}):null]}),t.jsx("span",{className:"ui-list-sub",children:I.grantable?I.description:`${I.description} Granted only by editing the file by hand.`})]})]},I.name)})})]},b.plugin)})]})}function vne(){return t.jsx("svg",{className:"tool-picker-chevron",viewBox:"0 0 11 11","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M2.8 4.2 5.5 6.9l2.7-2.7"})})}const rr={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."},ti=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function $O(e){let n;try{n=JSON.parse(e.trim())}catch{throw new Error(rr.json)}if(!ti(n))throw new Error(rr.json);let s,r=n;if("mcpServers"in n){const u=n.mcpServers;if(!ti(u))throw new Error(rr.empty);const h=Object.keys(u);if(h.length===0)throw new Error(rr.empty);if(h.length>1)throw new Error(`It names ${h.length} servers (${h.join(", ")}). Paste one at a time.`);s=h[0];const m=u[s];if(!ti(m))throw new Error(rr.url);r=m}if("command"in r)throw new Error(rr.command);if(typeof r.type=="string"&&r.type.toLowerCase()==="sse")throw new Error(rr.sse);const a=typeof r.url=="string"?r.url.trim():"";if(a==="")throw new Error(rr.url);const i=ti(r.headers)?Object.entries(r.headers).filter(u=>typeof u[1]=="string"&&u[0].trim()!==""):[],l=i.find(([u])=>u.toLowerCase()==="authorization")??i[0];let o,c=!1;if(l){const[u,h]=l,m=/^(Bearer|Basic)\s+/i.exec(h.trim()),f=m?`${m[1].charAt(0).toUpperCase()}${m[1].slice(1).toLowerCase()} `:"";let p=m?h.trim().slice(m[0].length).trim():h.trim();/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$/i.test(p)&&(c=!0,p=""),o={name:u.trim(),prefix:f,value:p}}return{url:a,...s?{name:s}:{},...o?{header:o}:{},dropped:i.filter(u=>u!==l).map(([u])=>u),placeholder:c}}const au={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 TO(e){return/TOKEN|KEY|SECRET|PASSWORD|PASSWD|CREDENTIAL|AUTH/i.test(e)}const RO=/^[A-Za-z_][A-Za-z0-9_]*$/;function yne(e){return/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$|^your[_-]/i.test(e.trim())}function IO(e,n){const s=yne(n);return{name:e,value:s?"":n,secret:TO(e),placeholder:s}}function PO(e){const n=[];let s="",r=!1,a=null;for(let i=0;i<e.length;i+=1){const l=e[i];if(a==="'"){l==="'"?a=null:s+=l;continue}if(a==='"'){if(l==='"')a=null;else if(l==="\\"&&i+1<e.length&&'"\\$`\n'.includes(e[i+1])){const o=e[++i];o!==`
136
- `&&(s+=o)}else s+=l;continue}if(l==="\\"){const o=e[i+1];if(o===void 0)continue;if(i+=1,o===`
137
- `||o==="\r"&&e[i+1]===`
138
- `){o==="\r"&&(i+=1);continue}s+=o,r=!0;continue}if(l==="'"||l==='"'){a=l,r=!0;continue}if(/\s/.test(l)){r&&(n.push(s),s="",r=!1);continue}s+=l,r=!0}if(a)throw new Error(au.quote);return r&&n.push(s),n}function wne(e){const n=PO(e.trim());let s=0;n[s]==="claude"&&(s+=1),n[s]==="mcp"&&(s+=1),n[s]==="add"&&(s+=1);const r=[],a=[];let i="stdio",l,o;const c=h=>{const m=h.indexOf("="),f=m>0?h.slice(0,m).trim():"";if(!RO.test(f))throw new Error(au.env);r.push(IO(f,h.slice(m+1)))},u=[];for(;s<n.length;s+=1){const h=n[s];if(h==="--"){o=n.slice(s+1);break}const[m,f]=h.startsWith("--")&&h.includes("=")?[h.slice(0,h.indexOf("=")),h.slice(h.indexOf("=")+1)]:[h,void 0];if(m==="-e"||m==="--env"){if(f!==void 0){c(f);continue}let p=!1;for(;s+1<n.length&&/^[A-Za-z_][A-Za-z0-9_]*=/.test(n[s+1]);)c(n[++s]),p=!0;if(!p)throw new Error(au.env);continue}if(m==="-s"||m==="--scope"){f===void 0&&(s+=1);continue}if(m==="-t"||m==="--transport"){i=(f??n[++s]??"stdio").toLowerCase();continue}if(m==="-H"||m==="--header"){const p=f??n[++s];p&&a.push(p);continue}if(!(m.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]),i==="http"||i==="sse"||o.length===1&&/^https?:\/\//i.test(o[0])){const h=o[0];if(!h)throw new Error(rr.url);const m={};for(const f of a){const p=f.indexOf(":");p>0&&(m[f.slice(0,p).trim()]=f.slice(p+1).trim())}return{kind:"remote",config:$O(JSON.stringify({mcpServers:{[l??"server"]:{type:i,url:h,headers:m}}}))}}if(!l||o.length===0)throw new Error(au.claude);return{kind:"program",program:{name:l,command:o[0],args:o.slice(1),env:r}}}function bne(e){const n=e.trim();if(/^claude\s+mcp\s+add\b/.test(n))return wne(n);let s;try{s=JSON.parse(n)}catch{throw new Error(rr.json)}if(!ti(s))throw new Error(rr.json);let r,a=s;if("mcpServers"in s){const c=s.mcpServers;if(!ti(c))throw new Error(rr.empty);const u=Object.keys(c);u.length===1&&ti(c[u[0]])&&(r=u[0],a=c[r])}if(!("command"in a))return{kind:"remote",config:$O(n)};const i=typeof a.command=="string"?a.command.trim():"";if(i==="")throw new Error(au.command);const l=Array.isArray(a.args)?a.args.map(c=>String(c)):[],o=ti(a.env)?Object.entries(a.env).filter(([c])=>RO.test(c)).map(([c,u])=>IO(c,String(u??""))):[];return{kind:"program",program:{...r?{name:r}:{},command:i,args:l,env:o}}}function Tk({code:e,label:n="Your code",large:s=!1}){const[r,a]=d.useState(!1),i=async()=>{var l;try{await((l=navigator.clipboard)==null?void 0:l.writeText(e)),a(!0)}catch{}};return t.jsxs(te,{valign:"end",children:[t.jsx(le,{label:n,grow:!0,children:t.jsx("input",{readOnly:!0,value:e,"data-code":s?"large":void 0,spellCheck:!1,onFocus:l=>l.currentTarget.select()})}),t.jsx($,{onClick:()=>void i(),children:r?"Copied":"Copy"})]})}function MO(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 kne="It can delete or destroy something, so it asks you every time and is never remembered.";function Nne(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 OO="buddi-connections",Sne="/connections/callback",Cne="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.",DO="Services and programs your team can use, and the tools each one brings.",Rk=(e,n,s)=>`${e} ${e===1?n:s}`;function cE(e,n){return e.transport==="stdio"?void 0:n.find(s=>Pk(s.url,e.url))}function Ik({connection:e,card:n,size:s}){return n?t.jsx(ss,{letter:n.name.slice(0,1).toUpperCase(),size:s}):t.jsx(ss,{icon:(e==null?void 0:e.transport)==="stdio"?"terminal":"globe",size:s})}function LO({connection:e}){const n=MO(e);return t.jsx($e,{tone:n.tone,dot:n.dot,children:n.label})}const gx=e=>n=>{n.stopPropagation(),e()},rf=[{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"}],FO="buddi.connections.add-way";function Ene(){try{const e=window.localStorage.getItem(FO);return rf.some(n=>n.value===e)?e:"address"}catch{return"address"}}function Ane({embedded:e,timezone:n,connection:s}={}){const r=je(()=>T.connections(),[],3e4),[a,i]=d.useState(null),[l,o]=d.useState(s??null);d.useEffect(()=>{s&&o(s)},[s]);const[c,u]=d.useState(null),[h,m]=d.useState(null),f=r.data,p=b=>{var S;return((S=f==null?void 0:f.agents.find(C=>C.id===b))==null?void 0:S.name)??b},x=n??Intl.DateTimeFormat().resolvedOptions().timeZone,g=(f==null?void 0:f.connections)??[],w=(f==null?void 0:f.catalog)??[],v=w.filter(b=>!g.some(S=>S.transport!=="stdio"&&Pk(b.url,S.url))),j=l?g.find(b=>b.id===l):void 0,y=c?g.find(b=>b.id===c):void 0,k=h?g.find(b=>b.id===h):void 0,N=b=>{o(null),i(b)};return t.jsxs(Is,{embedded:e,title:"Connections",lede:DO,children:[t.jsxs(ue,{gap:"lg",children:[t.jsxs("p",{className:"plugins-quiet connections-quiet",children:[t.jsx(ne,{name:"plug",size:14}),t.jsxs("span",{children:["A connection is a service or program buddi talks to; a plugin is code buddi installs and runs."," ",t.jsx("a",{href:ze("plugins"),children:"Plugins"})]})]}),!f&&!r.error?t.jsx(Ee,{children:"Reading your connections…"}):null,t.jsx(re,{message:r.error}),f&&!f.vault?t.jsx(Q,{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,f?t.jsx(lt,{flush:!0,title:"Your connections",tool:g.length>0?Rk(g.length,"connection","connections"):void 0,children:g.length===0?t.jsx(Ee,{title:"Nothing connected yet",children:"Pick a service below, or add your own: an address, a program on this computer, or a config you already have."}):t.jsx("div",{className:"connections-rows",children:t.jsx(yt,{children:g.map(b=>t.jsx($ne,{connection:b,card:cE(b,w),twin:b.slug!==null&&g.some(S=>S.id!==b.id&&S.name===b.name),onOpen:()=>o(b.id),onFlow:N},b.id))})})}):null,f&&v.length>0?t.jsx(lt,{title:"Connect a service",children:t.jsx("div",{className:"connections-tiles",children:v.map(b=>t.jsxs("div",{className:"connections-tile",children:[t.jsx(Ik,{card:b}),t.jsxs("span",{className:"connections-tile-main",children:[t.jsx("span",{className:"connections-tile-name",children:b.name}),t.jsx("span",{className:"connections-tile-blurb",children:b.blurb})]}),t.jsx($,{size:"sm",onClick:()=>N({step:"address",card:b}),"aria-label":`Connect ${b.name}`,children:"Connect"})]},b.id))})}):null,f?t.jsx(Mne,{onFlow:b=>N({step:b})}):null]}),j?t.jsx(Rne,{connection:j,card:cE(j,w),agentName:p,timezone:x,onClose:()=>o(null),onFlow:N,onDisconnect:()=>u(j.id),onHolders:()=>m(j.id)}):null,k&&f?t.jsx(Ine,{connection:k,agents:f.agents,onCancel:()=>m(null),onDone:()=>{m(null),r.reload()}},k.id):null,y?t.jsx(Pne,{connection:y,agentName:p,onCancel:()=>u(null),onDone:()=>{u(null),o(null),r.reload()}},y.id):null,a&&f?t.jsx(One,{start:a,agents:f.agents,catalog:f.catalog,tokens:f.tokens??f.vault,onClose:()=>{i(null),r.reload()}}):null]})}function $ne({connection:e,card:n,twin:s,onOpen:r,onFlow:a}){const i=e.state==="pending-review",l=s?`${e.name} (${e.slug})`:e.name,o=e.transport==="stdio"?e.program:void 0,c=o?o.line:e.host,u=i?"its tools are not reviewed yet":Rk(e.toolCount,"tool","tools");return t.jsx(pt,{onClick:r,label:`${l}: details`,lead:t.jsx(Ik,{connection:e,card:n}),title:l,sub:t.jsx("span",{className:"connections-sub","data-kind":o?"program":void 0,children:`${c} · ${u}`}),side:t.jsxs("span",{className:"plugins-side",children:[i?t.jsx("span",{className:"connections-act",children:t.jsx($,{size:"sm",variant:"accent",onClick:gx(()=>a({step:e.signedIn?"review":"consent",connection:e})),children:"Finish"})}):e.state==="needs-reconnect"&&e.authKind!=="none"?t.jsx("span",{className:"connections-act",children:t.jsx($,{size:"sm",onClick:gx(()=>a({step:"consent",connection:e,keepGrants:!0})),children:"Sign in"})}):e.state==="needs-review"?t.jsx("span",{className:"connections-act",children:t.jsx($,{size:"sm",onClick:gx(()=>a({step:"review",connection:e,keepGrants:!0})),children:"Review"})}):null,t.jsx(LO,{connection:e}),t.jsx(ne,{name:"chevron-right",size:14})]})})}const Tne={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 Rne({connection:e,card:n,agentName:s,timezone:r,onClose:a,onFlow:i,onHolders:l,onDisconnect:o}){const c=e.state==="pending-review",u=e.transport==="stdio"?e.program:void 0,h=()=>i({step:"consent",connection:e,keepGrants:!0}),m=()=>i({step:"review",connection:e,keepGrants:!0}),f=()=>i({step:e.signedIn?"review":"consent",connection:e});return t.jsxs(Ye,{title:t.jsxs("span",{className:"plugins-sheet-title",children:[t.jsx(Ik,{connection:e,card:n,size:"lg"}),t.jsxs("span",{className:"plugins-sheet-name",children:[t.jsx("span",{children:e.name}),t.jsxs("span",{className:"plugins-sheet-by",children:[u?"A program on this computer":"A service at an address"," · ",t.jsx(LO,{connection:e})]})]})]}),onClose:a,foot:t.jsxs(te,{children:[t.jsx($,{variant:"danger-ghost",onClick:o,children:"Disconnect…"}),t.jsx(ht,{}),u?t.jsx($,{onClick:()=>i({step:"program",connection:e,keepGrants:!0}),children:"Change"}):null,e.authKind!=="none"&&!c?t.jsx($,{variant:e.state==="needs-reconnect"?"accent":void 0,onClick:h,children:"Reconnect"}):null,c?t.jsx($,{variant:"accent",onClick:f,children:"Finish"}):t.jsx($,{variant:e.state==="needs-review"?"accent":void 0,onClick:m,children:"Review again"})]}),children:[c?t.jsx(Q,{children:"Not finished: its tools are not reviewed yet, so no agent can use them."}):null,e.state==="needs-reconnect"?t.jsx(Q,{tone:"warning",action:e.authKind!=="none"?t.jsx($,{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"?t.jsxs(Q,{tone:"warning",action:t.jsx($,{size:"sm",variant:"accent",onClick:m,children:"Review it"}),children:["It changed its tools since you reviewed them. The new and changed ones wait until you review it again",e.heldTools?` (${e.heldTools} of the ones you kept ${e.heldTools===1?"waits":"wait"})`:"","; the others keep working."]}):null,e.state==="unreachable"&&e.unreachableSince?t.jsx(Q,{tone:"critical",children:u?`It stopped answering at ${St(e.unreachableSince,r)}; the next call starts it again.`:`Unreachable since ${St(e.unreachableSince,r)}, retrying.`}):null,u!=null&&u.changedSinceReview?t.jsx(Q,{tone:"warning",children:"Its command changed since you reviewed it, so its tools wait until you review it again."}):null,e.phase==="starting"?t.jsx(Q,{tone:"accent",role:"status",children:"Starting it… The first start can take a minute or two while it downloads."}):null,t.jsx("div",{className:"plugins-facts",children:t.jsx(on,{items:[u?{label:"Command",value:t.jsx("span",{className:"connections-line",children:u.line})}:{label:"Address",value:t.jsx("span",{className:"connections-line",children:e.url})},...u?[{label:"Runs",value:"On this computer as you, with your PATH and only the variables you named. It stops after ten quiet minutes."}]:[],...u&&u.env.length>0?[{label:"Variables",value:t.jsx("span",{className:"mono",children:u.env.map(p=>`${p.name}${p.secret?" (secret)":""}`).join(", ")})}]:[],...u?[]:[{label:"Signs in with",value:Tne[e.authKind]}],{label:"Tools",value:c?"Not reviewed yet":`${Rk(e.toolCount,"tool","tools")}${e.reviewedAt?` · reviewed ${Xe(e.reviewedAt)}`:""}`},...c?[]:[{label:"Held by",value:t.jsxs("span",{className:"connections-holders",children:[t.jsx("span",{children:e.agents.length===0?"No agent holds these tools yet.":e.agents.map(s).join(", ")}),t.jsx($,{size:"sm",onClick:l,"aria-label":"Change who holds it",children:e.agents.length===0?"Give them":"Change"})]})}]]})}),e.stderr&&e.stderr.length>0?t.jsx(ye,{title:"What the program last said",children:t.jsx(Zt,{label:"Its last lines on stderr",children:e.stderr.join(`
139
- `)})}):null,n&&!c?t.jsxs("div",{className:"connections-another",children:[t.jsxs("p",{children:["Another ",n.name," account or workspace? It connects beside this one, with its own sign-in and its own name. In the browser, sign in as that other account."]}),t.jsx($,{size:"sm",onClick:()=>i({step:"address",card:n}),children:"Add another account"})]}):null]})}function Ine({connection:e,agents:n,onCancel:s,onDone:r}){const[a,i]=d.useState(()=>new Set(e.agents)),[l,o]=d.useState(!1),[c,u]=d.useState(null),h=(p,x)=>i(g=>{const w=new Set(g);return x?w.add(p):w.delete(p),w}),m=a.size===e.agents.length&&e.agents.every(p=>a.has(p)),f=async()=>{o(!0),u(null);try{const p=await T.grantConnection(e.id,[...a],!0);p.failed.length>0?u(p.failed.map(x=>`${x.agent}: ${x.message}`).join("; ")):r()}catch(p){u(_r(p))}finally{o(!1)}};return t.jsxs(Gt,{title:`Who holds ${e.name}`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",disabled:l,onClick:s,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:l||m,onClick:()=>void f(),children:"Save"})]}),children:[t.jsx("p",{className:"plugins-dialog-text",children:"Each agent you tick can use its tools; untick one to take them away. Approvals still ask as before."}),t.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Agents",children:n.map(p=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:a.has(p.id),onChange:x=>h(p.id,x.target.checked)}),t.jsxs("span",{children:[p.name,p.frontDesk?" (front desk)":""]})]},p.id))}),t.jsx(re,{message:c})]})}function Pne({connection:e,agentName:n,onCancel:s,onDone:r}){const[a,i]=d.useState(!1),[l,o]=d.useState(null),c=e.agents.map(n),u=async()=>{i(!0),o(null);try{await T.disconnect(e.id),r()}catch(h){o(_r(h))}finally{i(!1)}};return t.jsxs(Gt,{title:`Disconnect ${e.name}?`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",disabled:a,onClick:s,children:"Cancel"}),t.jsx($,{variant:"danger",disabled:a,onClick:()=>void u(),children:"Disconnect"})]}),children:[t.jsxs("p",{className:"plugins-dialog-text",children:["buddi forgets its sign-in and its tools."," ",c.length>0?`${c.join(" and ")} ${c.length===1?"loses":"lose"} them.`:"No agent holds its tools."]}),t.jsx(re,{message:l})]})}function Mne({onFlow:e}){const[n,s]=d.useState(Ene),r=rf.find(i=>i.value===n)??rf[0],a=i=>{s(i);try{window.localStorage.setItem(FO,i)}catch{}};return t.jsx(lt,{title:"Add your own",actions:t.jsx(cn,{label:"How to add it",options:rf.map(({value:i,label:l})=>({value:i,label:l})),value:n,onChange:a}),children:t.jsxs("div",{className:"connections-add",children:[t.jsx("p",{className:"connections-add-text",children:r.text}),t.jsx($,{variant:"accent",onClick:()=>e(n),children:r.button})]})})}function One({start:e,agents:n,catalog:s=[],tokens:r=!0,onClose:a,pollMs:i=2e3}){const[l,o]=d.useState(e.step),[c,u]=d.useState(e.connection),[h,m]=d.useState("unknown"),[f,p]=d.useState(null),[x,g]=d.useState(null),w=(f==null?void 0:f.url)??(c==null?void 0:c.url),v=e.card??s.find(k=>w!==void 0&&Pk(k.url,w)),j=(c==null?void 0:c.name)??(v==null?void 0:v.name)??(f==null?void 0:f.name)??"the service",y=l==="paste"?"Paste a config":l==="address"?"Connect a service":l==="program"?c?`Change ${c.name}`:"A program on this computer":l==="consent"?`Sign in to ${j}`:l==="review"?`What ${j} brings`:"Who gets these tools";return t.jsxs(Ye,{title:y,onClose:a,size:"wide",children:[l==="paste"?t.jsx(Dne,{onRead:k=>{k.kind==="program"?(g(k.program),o("program")):(p(k.config),o("address"))}}):null,l==="address"?t.jsx(Lne,{card:v,pasted:f,onDone:(k,N)=>{u(k),N==="none"?o("review"):(m(N),o("consent"))}}):null,l==="program"?t.jsx(Kne,{connection:c,pasted:x,tokens:r,onDone:k=>{var N;g(null),u(k),e.keepGrants&&!((N=k.program)!=null&&N.changedSinceReview)&&k.state!=="pending-review"?a():o("review")}}):null,l==="consent"&&c?t.jsx(zne,{connection:c,signIn:h,card:v,pasted:f==null?void 0:f.header,placeholder:(f==null?void 0:f.placeholder)??!1,tokens:r,pollMs:i,onSignedIn:k=>{p(null),u(k),e.keepGrants?a():o("review")}}):null,l==="review"&&c?t.jsx(Vne,{connection:c,onKept:k=>{u(k),e.keepGrants?a():o("grant")}}):null,l==="grant"&&c?t.jsx(Gne,{connection:c,agents:n,onDone:a}):null]})}function Pk(e,n){const s=r=>r.trim().replace(/\/+$/,"").toLowerCase();return s(e)===s(n)}function _r(e){return e instanceof Error?e.message:String(e)}function Dne({onRead:e}){const[n,s]=d.useState(""),[r,a]=d.useState(null),i=()=>{try{const l=bne(n);s(""),a(null),e(l)}catch(l){a(_r(l))}};return t.jsxs("form",{className:"ui-stack",onSubmit:l=>{l.preventDefault(),i()},children:[t.jsxs("p",{children:["Paste the block another app uses for this server, the one with ",t.jsx("span",{className:"mono",children:"mcpServers"}),", or the"," ",t.jsx("span",{className:"mono",children:"claude mcp add"})," line its docs print. A remote server gives its address, name and one header; a program its command, arguments and variables. Nothing is kept before you have read it on the next screen."]}),t.jsx(le,{label:"Config",hint:"A url for a remote server, or a command for a program on this computer.",children:t.jsx("textarea",{className:"mono",rows:8,required:!0,autoFocus:!0,spellCheck:!1,autoComplete:"off",value:n,placeholder:'{ "mcpServers": { "github": { "url": "…", "headers": { "Authorization": "Bearer …" } } } }',onChange:l=>s(l.target.value)})}),t.jsx(re,{message:r}),t.jsx(te,{align:"end",children:t.jsx($,{type:"submit",variant:"accent",disabled:n.trim()==="",children:"Read it"})})]})}function Lne({card:e,pasted:n,onDone:s}){var f,p;const[r,a]=d.useState((n==null?void 0:n.url)??(e==null?void 0:e.url)??""),[i,l]=d.useState(!1),[o,c]=d.useState(null),u=async()=>{l(!0),c(null);try{const x=await T.addConnection(r.trim(),(e==null?void 0:e.name)??(n==null?void 0:n.name));s(x.connection,x.signIn)}catch(x){c(_r(x))}finally{l(!1)}},h=((f=e==null?void 0:e.auth)==null?void 0:f.recommended)==="token",m=((p=e==null?void 0:e.auth)==null?void 0:p.recommended)==="device"&&e.auth.device!==void 0;return t.jsxs("form",{className:"ui-stack",onSubmit:x=>{x.preventDefault(),u()},children:[e?t.jsxs("p",{children:["buddi opens ",e.name,"’s server, reads its name and what it offers, and asks whether it wants you to sign in. Nothing else is sent."]}):t.jsx("p",{children:"Where is the server? buddi opens it, reads its name and what it offers, and nothing else until you have read its tools."}),t.jsx(le,{label:"Address",hint:"An https:// address. A server you start with npx, uvx or a local command is “A program on this computer” instead.",children:t.jsx("input",{required:!0,autoFocus:!e&&!n,spellCheck:!1,value:r,placeholder:"https://",onChange:x=>a(x.target.value)})}),e&&!e.verified?t.jsxs("p",{className:"ui-card-meta",children:["This address is the one ",e.name," published; buddi has not checked it since."]}):null,m?t.jsxs("p",{className:"ui-card-meta",children:[e.name," signs in with a code you type on its site. The next screen shows it."]}):h?t.jsxs("p",{className:"ui-card-meta",children:[e.name," signs in with a token you make on its site. The next screen links to the page."]}):e!=null&&e.clientIdRequired?t.jsxs("p",{className:"ui-card-meta",children:[e.name," does not let buddi register itself: signing in needs a token, or a client id from its developer settings."]}):null,n!=null&&n.header?t.jsx("p",{className:"ui-card-meta",children:n.placeholder?`Your config has a placeholder where the ${n.header.name} header's token goes. You paste the token itself on the next screen.`:`The ${n.header.name} header from your config waits for the sign-in screen. buddi tries it before it keeps it.`}):null,n&&n.dropped.length>0?t.jsxs("p",{className:"ui-card-meta",children:["buddi sends one header, so ",n.dropped.join(", ")," ",n.dropped.length===1?"was":"were"," left out."]}):null,t.jsx(re,{message:o}),t.jsx(te,{align:"end",children:t.jsx($,{type:"submit",variant:"accent",disabled:i||r.trim()==="",children:i?"Opening…":"Continue"})})]})}const Fne={device:"Device",oauth:"Sign in",token:"Token",client:"Client id"};function _ne(e,n,s="none"){const r=e==="manual"?["token","client"]:["oauth","token"],a=n?r:r.filter(i=>i!=="token");return s==="first"?["device",...a]:s==="offered"?[...a.filter(i=>i!=="client"),"device",...a.filter(i=>i==="client")]:a}function zne({connection:e,signIn:n,card:s,pasted:r,placeholder:a,tokens:i,pollMs:l,onSignedIn:o}){var z,D;const[c,u]=d.useState(n),h=(z=s==null?void 0:s.auth)!=null&&z.device?s.auth.recommended==="device"?"first":"offered":"none",m=_ne(c,i,h),f=r!==void 0||h!=="first"&&(e.authKind==="token"||((D=s==null?void 0:s.auth)==null?void 0:D.recommended)==="token"),[p,x]=d.useState(()=>f&&m.includes("token")?"token":m[0]),g=m.includes(p)?p:m[0],[w,v]=d.useState(Cne),[j,y]=d.useState(""),[k,N]=d.useState(null),[b,S]=d.useState(!1),[C,A]=d.useState(null),[E,R]=d.useState(!1),[P,O]=d.useState(null),I=`${location.origin}${Sne}`,F=d.useRef(o);F.current=o,d.useEffect(()=>{if(!E)return;let K=!1;const B=async()=>{if(!K){K=!0;try{F.current(await T.connection(e.id))}catch(ie){A(_r(ie))}}},se=typeof BroadcastChannel=="function"?new BroadcastChannel(OO):null;se&&(se.onmessage=ie=>{var H;((H=ie.data)==null?void 0:H.id)===e.id&&B()});let W;const xe=Date.now(),me=async()=>{if(!K){try{const ie=await T.connection(e.id);if((!e.signedIn||e.authKind==="token")&&ie.signedIn&&ie.authKind==="oauth"){B();return}}catch{}if(Date.now()-xe>10*6e4){R(!1),A("The sign-in did not come back within ten minutes. Start it again.");return}W=window.setTimeout(()=>void me(),l)}};return W=window.setTimeout(()=>void me(),l),()=>{K=!0,se==null||se.close(),window.clearTimeout(W)}},[E,e,l]);const U=async K=>{var B;S(!0),A(null);try{const{authorizeUrl:se}=await T.connectionConsent(e.id,K);N(se)}catch(se){se instanceof pe&&((B=se.detail)==null?void 0:B.code)==="client-id"?(v(se.message),u("manual"),x("client")):A(_r(se))}finally{S(!1)}};d.useEffect(()=>{g!=="oauth"||k!==null||U()},[g]);const L=K=>{const B=window.open(K,"_blank");B?(B.opener=null,O(null)):O(K),R(!0)},M=K=>{x(K),N(null),A(null),R(!1),O(null)};return t.jsxs("div",{className:"ui-stack",children:[m.length>1?t.jsx(cn,{label:"How to sign in",options:m.map(K=>({value:K,label:Fne[K]})),value:g,onChange:M}):null,g==="oauth"?t.jsxs(t.Fragment,{children:[t.jsxs("p",{children:["buddi opens ",e.name,"’s own sign-in page in a new tab. You say yes there, the tab comes back here, and buddi keeps the sign-in in its vault. No agent ever sees it."]}),b?t.jsxs(Ee,{children:["Getting ",e.name,"’s sign-in page…"]}):null]}):null,g==="client"?t.jsxs(t.Fragment,{children:[t.jsx(Q,{tone:"warning",children:w}),t.jsx(le,{label:"Client id",children:t.jsx("input",{required:!0,spellCheck:!1,value:j,onChange:K=>{y(K.target.value),N(null),R(!1)}})}),t.jsxs("p",{className:"ui-card-meta",children:["Its redirect address: ",t.jsx("span",{className:"mono",children:I})]})]}):null,g==="token"?t.jsx(Wne,{connection:e,card:s,pasted:r,placeholder:a,onSignedIn:o}):null,g==="device"?t.jsx(Bne,{connection:e,service:(s==null?void 0:s.name)??e.name,pollMs:l,onSignedIn:o}):null,(g==="oauth"||g==="client")&&E?t.jsxs(Q,{tone:"accent",role:"status",children:["Waiting for you to say yes on ",e.name,"’s page…"]}):null,(g==="oauth"||g==="client")&&P?t.jsx("p",{children:t.jsxs("a",{href:P,target:"_blank",rel:"noopener noreferrer",children:["Open ",e.name,"’s sign-in page"]})}):null,g==="oauth"||g==="client"?t.jsx(re,{message:C}):null,g==="oauth"?t.jsx(te,{align:"end",children:t.jsx($,{variant:"accent",onClick:()=>{k&&L(k)},disabled:k===null,children:E?"Open it again":`Sign in to ${e.name}`})}):null,g==="client"?t.jsx(te,{align:"end",children:k===null?t.jsx($,{variant:"accent",onClick:()=>void U(j.trim()),disabled:b||j.trim()==="",children:b?"Checking…":"Continue"}):t.jsx($,{variant:"accent",onClick:()=>L(k),children:E?"Open it again":`Open ${e.name}’s sign-in page`})}):null]})}function Une(e){try{const n=new URL(e);return`${n.host}${n.pathname==="/"?"":n.pathname.replace(/\/$/,"")}`}catch{return e}}function Bne({connection:e,service:n,pollMs:s,onSignedIn:r}){const[a,i]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(0),[h,m]=d.useState(null),[f,p]=d.useState(!1),x=d.useRef(r);x.current=r,d.useEffect(()=>{let v=!1,j;i(null),o(null),m(null),p(!1);const y=async()=>{var k,N;if(!v){try{const b=await T.connection(e.id);if(v)return;if(((k=b.device)==null?void 0:k.state)==="done"){x.current(b);return}if(((N=b.device)==null?void 0:N.state)==="failed"){o(b.device.reason??"The sign-in did not finish. Start again.");return}}catch{}j=window.setTimeout(()=>void y(),s)}};return(async()=>{try{const k=await T.connectionDevice(e.id);if(v)return;i({userCode:k.userCode,verificationUri:k.verificationUri}),j=window.setTimeout(()=>void y(),s)}catch(k){v||o(_r(k))}})(),()=>{v=!0,window.clearTimeout(j)}},[e.id,s,c]);const g=v=>{const j=window.open(v,"_blank");p(!0),j?(j.opener=null,m(null)):m(v)},w=a?Une(a.verificationUri):"";return t.jsxs(t.Fragment,{children:[t.jsxs("p",{children:[a?`Open ${w}, type this code there and say yes.`:`Type a code on ${n}’s site and say yes there.`," buddi keeps the sign-in in its vault and sends it only to"," ",t.jsx("span",{className:"mono",children:e.host}),". No agent ever sees it."]}),a===null&&l===null?t.jsxs(Ee,{children:["Asking ",n," for a code…"]}):null,a&&l===null?t.jsxs(t.Fragment,{children:[t.jsx(Tk,{code:a.userCode,label:`Your code for ${n}`,large:!0}),f?t.jsxs(Q,{tone:"accent",role:"status",children:["Waiting for you to approve on ",n,"…"]}):null,h?t.jsx("p",{children:t.jsxs("a",{href:h,target:"_blank",rel:"noopener noreferrer",children:["Open ",w]})}):null,t.jsx(te,{align:"end",children:t.jsxs($,{variant:"accent",onClick:()=>g(a.verificationUri),children:["Open ",w]})})]}):null,l!==null?t.jsxs(t.Fragment,{children:[t.jsx(re,{message:l}),t.jsx(te,{align:"end",children:t.jsx($,{variant:"accent",onClick:()=>u(v=>v+1),children:"Start again"})})]}):null]})}function Wne({connection:e,card:n,pasted:s,placeholder:r,onSignedIn:a}){var v,j;const[i,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 ")),[m,f]=d.useState(!1),[p,x]=d.useState(null),g=async()=>{f(!0),x(null);try{const y=await T.connectionToken(e.id,{token:i.trim(),header:o.trim(),prefix:u});l(""),a(y.connection)}catch(y){x(_r(y))}finally{f(!1)}},w=(v=n==null?void 0:n.auth)==null?void 0:v.tokenPage;return t.jsxs("form",{className:"ui-stack",onSubmit:y=>{y.preventDefault(),g()},children:[t.jsxs("p",{children:[w?`Make a token on ${e.name}’s site and paste it here.`:`Paste a token ${e.name} gave you.`," buddi tries it on"," ",t.jsx("span",{className:"mono",children:e.host})," first, keeps it in its vault, and sends it only there. No agent ever sees it."]}),w?t.jsx("p",{children:t.jsxs("a",{href:w,target:"_blank",rel:"noopener noreferrer",children:["Make a token on ",e.name]})}):null,r?t.jsx(Q,{tone:"accent",children:"Your config had a placeholder where the token goes. Paste the token itself."}):null,t.jsx(le,{label:"Token",hint:(j=n==null?void 0:n.auth)==null?void 0:j.tokenHint,children:t.jsx("input",{type:"password",required:!0,autoFocus:!(s!=null&&s.value),autoComplete:"off",spellCheck:!1,value:i,onChange:y=>l(y.target.value)})}),t.jsxs(Vs,{columns:2,dense:!0,children:[t.jsx(le,{label:"Header",hint:"Most services want Authorization.",children:t.jsx("input",{required:!0,spellCheck:!1,value:o,onChange:y=>c(y.target.value)})}),t.jsx(le,{label:"Before the token",hint:"Usually “Bearer ”, with its space. Empty for none.",children:t.jsx("input",{spellCheck:!1,value:u,onChange:y=>h(y.target.value)})})]}),t.jsx(re,{message:p}),t.jsx(te,{align:"end",children:t.jsx($,{type:"submit",variant:"accent",disabled:m||i.trim()===""||o.trim()==="",children:m?"Trying it…":"Try it and keep it"})})]})}function Hne(e){return e!==""&&/^[A-Za-z0-9_@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function Kne({connection:e,pasted:n,tokens:s=!0,onDone:r}){const a=e==null?void 0:e.program,i=d.useRef(0),l=()=>(i.current+=1,i.current),[o,c]=d.useState((e==null?void 0:e.name)??(n==null?void 0:n.name)??""),[u,h]=d.useState((a==null?void 0:a.command)??(n==null?void 0:n.command)??""),[m,f]=d.useState(()=>((a==null?void 0:a.args)??(n==null?void 0:n.args)??[]).map(I=>({key:l(),value:I}))),[p,x]=d.useState(()=>a?a.env.map(I=>({key:l(),name:I.name,value:I.value??"",secret:I.secret,kept:I.secret})):((n==null?void 0:n.env)??[]).map(I=>({key:l(),name:I.name,value:I.value,secret:I.secret,kept:!1}))),[g,w]=d.useState(!1),[v,j]=d.useState(null),y=/\s/.test(u.trim())?PO(u.trim()):[u.trim()],k=y[0]??"",N=[...y.slice(1),...m.map(I=>I.value)],b=[k,...N].filter((I,F)=>F>0||I!==""),S=()=>{y.length<2||(h(k),f(I=>[...y.slice(1).map(F=>({key:l(),value:F})),...I]))},C=b.map(Hne).join(" "),A=p.filter(I=>I.secret&&I.value===""&&!I.kept).map(I=>I.name||"a variable"),E=((n==null?void 0:n.env)??[]).filter(I=>I.placeholder).map(I=>I.name),R=(I,F)=>f(U=>U.map(L=>L.key===I?{...L,value:F}:L)),P=(I,F)=>x(U=>U.map(L=>L.key===I?{...L,...F}:L)),O=async()=>{w(!0),j(null);const I={name:o.trim(),command:k,args:N,env:p.filter(F=>F.name.trim()!=="").map(F=>({name:F.name.trim(),value:F.value,secret:F.secret}))};try{r(e?await T.updateProgram(e.id,I):(await T.addProgram(I)).connection),x(F=>F.map(U=>U.secret?{...U,value:""}:U))}catch(F){j(_r(F))}finally{w(!1)}};return t.jsxs("form",{className:"ui-stack",onSubmit:I=>{I.preventDefault(),O()},children:[t.jsx("p",{children:"A server buddi starts itself on this computer, as you, when an agent needs it, and stops after ten quiet minutes. It runs with your PATH and only the variables you name here. The review screen is the first time it runs, only to list its tools."}),t.jsxs(Vs,{columns:2,children:[t.jsx(le,{label:"Name",children:t.jsx("input",{required:!0,autoFocus:!n&&!e,maxLength:80,spellCheck:!1,value:o,onChange:I=>c(I.target.value)})}),t.jsx(le,{label:"Command",hint:"The program that starts the server: npx, uvx, node, or a full path. A whole line is split into it and its arguments.",children:t.jsx("input",{required:!0,spellCheck:!1,autoComplete:"off",className:"mono",value:u,placeholder:"npx",onChange:I=>h(I.target.value),onBlur:S})})]}),t.jsx(le,{label:"Arguments",group:!0,hint:"One per row, exactly as the server's docs give them. No shell: quotes and $VARIABLES are passed as they are.",children:t.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[m.map((I,F)=>t.jsxs("div",{className:"connections-row",children:[t.jsx("input",{"aria-label":`Argument ${F+1}`,className:"mono",spellCheck:!1,autoComplete:"off",value:I.value,onChange:U=>R(I.key,U.target.value)}),t.jsx($,{size:"sm",variant:"ghost",onClick:()=>f(U=>U.filter(L=>L.key!==I.key)),"aria-label":`Remove argument ${F+1}`,children:"Remove"})]},I.key)),t.jsx(te,{children:t.jsx($,{size:"sm",onClick:()=>f(I=>[...I,{key:l(),value:""}]),children:"Add an argument"})})]})}),t.jsx(le,{label:"Environment variables",group:!0,hint:"A secret is kept in buddi's vault and handed to the program only when it starts. Names with TOKEN, KEY, SECRET or PASSWORD start as secrets.",children:t.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[p.map((I,F)=>t.jsxs("div",{className:"connections-row","data-kind":"env",children:[t.jsx("input",{"aria-label":`Variable ${F+1} name`,className:"mono",spellCheck:!1,autoComplete:"off",placeholder:"NAME",value:I.name,onChange:U=>{const L=U.target.value;P(I.key,I.value===""&&!I.kept?{name:L,secret:TO(L)}:{name:L})}}),t.jsx("input",{"aria-label":`Variable ${F+1} value`,type:I.secret?"password":"text",spellCheck:!1,autoComplete:"off",placeholder:I.kept&&I.value===""?"Kept. Type to replace it.":"value",value:I.value,onChange:U=>P(I.key,{value:U.target.value})}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:I.secret,onChange:U=>P(I.key,{secret:U.target.checked,kept:U.target.checked&&I.kept})}),t.jsx("span",{children:"Secret"})]}),t.jsx($,{size:"sm",variant:"ghost",onClick:()=>x(U=>U.filter(L=>L.key!==I.key)),"aria-label":`Remove variable ${F+1}`,children:"Remove"})]},I.key)),t.jsx(te,{children:t.jsx($,{size:"sm",onClick:()=>x(I=>[...I,{key:l(),name:"",value:"",secret:!1,kept:!1}]),children:"Add a variable"})})]})}),E.length>0?t.jsxs(Q,{tone:"accent",children:["Your config had a placeholder for ",E.join(", "),". Type the value itself."]}):null,!s&&p.some(I=>I.secret)?t.jsx(Q,{tone:"warning",children:"This installation has no vault, so a secret cannot be kept. Turn the vault on first, or switch Secret off."}):null,t.jsx("p",{className:"ui-card-meta",children:"A server that signs you in through a browser opens it on this computer, so it needs a screen. On a machine without one, give it a token as a secret variable instead."}),t.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[t.jsx("span",{className:"ui-field-label",children:"It will run"}),t.jsx(Zt,{label:"The command line",children:C||"…"})]}),t.jsx(re,{message:v}),t.jsx(te,{align:"end",children:t.jsx($,{type:"submit",variant:"accent",disabled:g||o.trim()===""||u.trim()===""||A.length>0,title:A.length>0?`Give ${A.join(", ")} a value.`:void 0,children:g?"Saving…":e?"Save":"Continue"})})]})}function Vne({connection:e,onKept:n}){const s=je(()=>T.connectionReview(e.id),[e.id]),[r,a]=d.useState(null),[i,l]=d.useState(!1),[o,c]=d.useState(null),u=s.data,h=r??(u==null?void 0:u.slug)??"",m=async()=>{var p;if(u){l(!0),c(null);try{n(await T.saveConnectionReview(e.id,{hash:u.hash,...u.slugEditable?{slug:h}:{}}))}catch(x){x instanceof pe&&((p=x.detail)==null?void 0:p.code)==="changed"&&s.reload(),c(_r(x))}finally{l(!1)}}};if(!u)return s.error?t.jsx(re,{message:s.error}):e.transport==="stdio"?t.jsxs(Ee,{children:["Starting ",e.name,"… The first start can take a minute or two while it downloads."]}):t.jsxs(Ee,{children:["Reading what ",e.name," offers…"]});const f=u.tools.filter(p=>p.problem===null).length;return t.jsxs("div",{className:"ui-stack",children:[t.jsxs("p",{children:["Read what ",e.name," brings before it brings it. Each tool gets a buddi name and a tier from what the server says it does; anything that changes something asks you first, on the same approval card as every other tool."]}),u.program?t.jsx(Q,{tone:"warning",title:"This runs on this computer as you",children:t.jsxs(ue,{gap:"sm",children:[t.jsx(Zt,{label:"The command",children:u.program.line}),t.jsx("p",{children:"It can read and change what you can, and reach the network. buddi starts it with only the variables below, stops it after ten quiet minutes, and asks you again if its command changes."}),u.program.env.length>0?t.jsxs("p",{className:"ui-card-meta",children:["Variables: ",u.program.env.map(p=>`${p.name}${p.secret?" (secret)":""}`).join(", ")]}):null]})}):t.jsxs("p",{className:"ui-card-meta",children:["buddi talks to ",t.jsx("span",{className:"mono",children:u.host})," for these tools, and nowhere else."]}),u.annotatedNothing?t.jsxs(Q,{tone:"warning",children:[e.name," says nothing about what its tools do, so every one of them asks you first."]}):null,u.changes&&u.changes.added.length+u.changes.changed.length+u.changes.removed.length>0?t.jsxs(Q,{tone:"warning",title:`${e.name} changed its tools since your last review.`,children:[t.jsxs("ul",{className:"connections-changes","aria-label":"What changed",children:[u.changes.added.length>0?t.jsxs("li",{children:["New: ",t.jsx("span",{className:"mono",children:u.changes.added.join(", ")})]}):null,u.changes.changed.length>0?t.jsxs("li",{children:["Changed: ",t.jsx("span",{className:"mono",children:u.changes.changed.join(", ")})]}):null,u.changes.removed.length>0?t.jsxs("li",{children:["Gone: ",t.jsx("span",{className:"mono",children:u.changes.removed.join(", ")})]}):null]}),t.jsx("p",{children:"Until you keep this list, the new and changed tools wait; the others keep working."})]}):null,u.slugEditable?t.jsx(le,{label:"Its name in buddi",hint:`Tools are called mcp.${h||"…"}.<tool>. Lower case, letters, digits, _ and -.`,children:t.jsx("input",{required:!0,spellCheck:!1,maxLength:24,value:h,onChange:p=>a(p.target.value.toLowerCase())})}):null,u.tools.length===0?t.jsxs(Ee,{children:[e.name," lists no tools."]}):t.jsx("div",{className:"ui-list","aria-label":"Tools",children:u.tools.map(p=>{const x=Nne(p),g=u.slugEditable?p.fullName.replace(/^mcp\.[^.]+\./,`mcp.${h||u.slug}.`):p.fullName;return t.jsx("div",{className:"ui-list-row connections-tool",children:t.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[t.jsxs("div",{className:"ui-card-head",children:[t.jsx("span",{className:"mono",children:g}),p.problem?t.jsx($e,{tone:"muted",children:"Cannot be used"}):t.jsx($e,{tone:x.tone,children:x.label}),p.change==="added"?t.jsx(Po,{children:"New"}):p.change==="changed"?t.jsx(Po,{children:"Changed"}):null]}),p.description?t.jsx("p",{className:"ui-card-meta",children:p.description}):null,!p.problem&&p.tier==="gated"?t.jsx("p",{className:"ui-card-meta",children:p.destructive?kne:"You can remember its approval for an agent when you give it the tools, or later on the agent’s Tools tab."}):null,p.problem?t.jsxs("p",{className:"ui-card-meta",children:["Left out: ",p.problem,"."]}):null]})},p.name)})}),t.jsx(re,{message:o}),t.jsx(te,{align:"end",children:t.jsx($,{variant:"accent",onClick:()=>void m(),disabled:i||u.slugEditable&&h.trim()==="",children:f===1?"Keep this tool":`Keep these ${f} tools`})})]})}function Gne({connection:e,agents:n,onDone:s}){var w;const r=n.find(v=>v.frontDesk)??n[0],[a,i]=d.useState(()=>new Set(r?[r.id]:[])),o=(((w=je(()=>T.connectionTools(e.id),[e.id]).data)==null?void 0:w.tools)??[]).filter(v=>v.tier==="gated"),[c,u]=d.useState(()=>new Set),[h,m]=d.useState(!1),[f,p]=d.useState(null),x=(v,j)=>{i(y=>{const k=new Set(y);return j?k.add(v):k.delete(v),k})},g=async()=>{m(!0),p(null);try{const v=await T.grantConnection(e.id,[...a]);if(v.failed.length>0){p(v.failed.map(j=>`${j.agent}: ${j.message}`).join(" "));return}for(const j of v.granted)for(const y of c)await T.setRememberedApproval(j,y,!0);s()}catch(v){p(_r(v))}finally{m(!1)}};return t.jsxs("div",{className:"ui-stack",children:[t.jsxs("p",{children:[r?`Give these tools to ${r.name}?`:"Which agents get these tools?"," Each one you tick gets ",t.jsx("span",{className:"mono",children:e.grant})," on its tools line."]}),t.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Agents",children:n.map(v=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:a.has(v.id),onChange:j=>x(v.id,j.target.checked)}),t.jsxs("span",{children:[v.name,v.frontDesk?" (front desk)":""]})]},v.id))}),t.jsx("p",{className:"ui-card-meta",children:"No one is fine too: the connection waits here until you give it to someone."}),o.length>0?t.jsxs("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Remembered approval",children:[t.jsx("p",{children:"These ask you first. Tick one to remember your approval for the agents above, so it asks only once."}),o.map(v=>t.jsxs(ue,{gap:"sm",children:[t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",disabled:!v.rememberable,checked:c.has(v.tool),onChange:j=>u(y=>{const k=new Set(y);return j.target.checked?k.add(v.tool):k.delete(v.tool),k})}),t.jsx("span",{className:"mono",children:v.tool})]}),v.why?t.jsx("p",{className:"ui-card-meta",children:v.why}):null]},v.tool))]}):null,t.jsx(re,{message:f}),t.jsxs(te,{align:"end",children:[t.jsx($,{onClick:s,disabled:h,children:"Not now"}),t.jsx($,{variant:"accent",onClick:()=>void g(),disabled:h||a.size===0,children:"Give them"})]})]})}const qne=(e,n,s)=>`${e} ${e===1?n:s}`;function Yne(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 Qne({agentId:e,agentName:n,readOnly:s,version:r,onSaved:a}){const[i,l]=d.useState({}),o=je(()=>T.connections().then(y=>(l({}),y)),[r]),[c,u]=d.useState(null),[h,m]=d.useState(null),f=ze("connections"),p=async(y,k)=>{u(y.id),m(null);try{const N=await T.setConnectionHolder(y.id,e,k);l(b=>({...b,[y.id]:N.held})),a==null||a()}catch(N){m(N instanceof Error?N.message:String(N))}finally{u(null)}},x=o.data,g=(x==null?void 0:x.connections)??[],w=y=>i[y.id]??y.agents.includes(e),v=x?x.agents.some(y=>y.id===e):!0,j=g.filter(w).length;return t.jsxs(ye,{title:"Connections",aside:x&&g.length>0?`holds ${j} of ${g.length} · saved as you change them`:void 0,panel:!0,children:[t.jsx(re,{message:o.error??h}),x?g.length===0?t.jsxs("p",{className:"ui-card-meta",children:["Nothing is connected yet. ",t.jsx("a",{href:f,children:"Connect a service in Connections"})]}):v?t.jsxs(t.Fragment,{children:[s?t.jsx(Q,{tone:"warning",children:"This agent ships with buddi, so its connections are read-only here. Ask Agent Father to make it yours, then it can change."}):null,t.jsx("ul",{className:"ui-list delegate-list","aria-label":`Connections ${n} holds`,children:g.map(y=>{const k=w(y),N=Yne(y),b=y.transport==="stdio"?"on this computer":y.host,S=y.slug?qne(y.toolCount,"tool","tools"):"tools not reviewed",C=`holds-${e}-${y.id}`;return t.jsxs("li",{className:"ui-list-row",children:[t.jsx("input",{type:"checkbox",role:"switch",id:C,checked:k,"aria-checked":k,disabled:s||c!==null||N!==null&&!k,onChange:A=>void p(y,A.target.checked)}),t.jsxs("label",{htmlFor:C,className:"ui-list-main",children:[t.jsxs("span",{className:"ui-list-title",children:[y.name,N?t.jsxs(t.Fragment,{children:[" ",t.jsx($e,{tone:"warning",children:MO(y).label})]}):null]}),t.jsx("span",{className:"ui-list-sub",children:`${b} · ${S}`}),N?t.jsxs("span",{className:"ui-list-sub",children:[N," ",t.jsx("a",{href:f,children:"Open Connections"})]}):null]})]},y.id)})})]}):t.jsxs("p",{className:"ui-card-meta",children:[n," makes and changes agents, so it holds no connections."]}):o.error?null:t.jsx(Ee,{children:"Loading the connections…"})]})}const Jne=(e,n)=>!!e&&!!n&&e.kind===n.kind&&(e.kind==="mascot"?e.role===n.role:e.kind==="emoji"?e.value===n.value:!0);async function _O(e){const n=await fetch(Ti(e));if(!n.ok)throw new Error(`The picture could not be read (${n.status}).`);const s=await n.blob();return new File([s],`buddi-blob-${e}.png`,{type:"image/png"})}function Xne({face:e,onPick:n,label:s=_.assistant.face,kept:r,disabled:a,disableEmoji:i,children:l}){return t.jsxs("div",{className:"meet-faces",role:"group","aria-label":s,children:[t.jsxs("div",{className:"meet-face-row",children:[r?t.jsx("button",{type:"button",className:"meet-face","data-kind":"image","data-chosen":(e==null?void 0:e.kind)==="kept"?"true":void 0,"aria-pressed":(e==null?void 0:e.kind)==="kept","aria-label":"The current picture",disabled:a,onClick:()=>n({kind:"kept",url:r}),children:t.jsx("img",{src:r,alt:""})}):null,I5.map(o=>{const c={kind:"mascot",role:o},u=Jne(e,c);return t.jsx("button",{type:"button",className:"meet-face","data-kind":"image","data-chosen":u?"true":void 0,"aria-pressed":u,"aria-label":_.assistant.mascot(o),disabled:a,onClick:()=>n(c),children:t.jsx("img",{src:Ti(o),alt:""})},o)})]}),t.jsx("div",{className:"meet-face-row",children:M5.map(o=>{const c=(e==null?void 0:e.kind)==="emoji"&&e.value===o;return t.jsx("button",{type:"button",className:"meet-face","data-chosen":c?"true":void 0,"aria-pressed":c,disabled:a||i,onClick:()=>n({kind:"emoji",value:o}),children:o},o)})}),l]})}const Zne=["mirror","en","fr"],ese=[{value:"3h",label:"3 hours"},{value:"1d",label:"A day"},{value:"1w",label:"A week"},{value:"never",label:"Never"}],xx=10,jx=500,zO=[{id:"identity",label:"Identity"},{id:"brain",label:"Brain"},{id:"tools",label:"Tools"},{id:"team",label:"Team"}],uE=e=>{var n;return e==="access"?"tools":((n=zO.find(s=>s.id===e))==null?void 0:n.id)??"identity"};function tse({agentId:e,section:n,navigate:s}){var g,w,v;const{data:r,error:a,reload:i}=je(()=>T.agents(),[]),[l,o]=d.useState(null),[c,u]=d.useState(null),[h,m]=d.useState(uE(n));d.useEffect(()=>m(uE(n)),[n]);const f=j=>{m(j),s==null||s(Qt(e,"setup",j))},p=async j=>{o(null),u(null);try{const y=await j;u(y.changed.length===0?`No file change needed. ${y.note}.`:`Changed ${y.changed.join(", ")}. ${y.note}.`),i()}catch(y){o(y instanceof Error?y.message:String(y))}},x=r==null?void 0:r.agents.find(j=>j.id===e);return t.jsxs(ue,{gap:"lg",children:[t.jsx(ic,{level:"secondary",label:"Setup",children:zO.map(j=>t.jsx(ml,{href:Qt(e,"setup",j.id),active:h===j.id,onClick:y=>{y.preventDefault(),f(j.id)},children:j.label},j.id))}),t.jsx(re,{message:a??l}),c?t.jsx(Q,{tone:"good",role:"status",children:c}):null,r?x?t.jsx(nse,{agent:x,all:r.agents,engine:r.engines.find(j=>j.id===x.id),providers:r.providers,accounts:r.providerAccounts,shown:h,onShow:f,onRun:p,onSaved:i},`${x.id}:${(g=r.engines.find(j=>j.id===x.id))==null?void 0:g.model}:${(v=(w=r.providerAccounts)==null?void 0:w.bindings.find(j=>j.agentId===x.id))==null?void 0:v.accountId}`):t.jsx(Ee,{children:"This agent is not installed as a file."}):t.jsx(Ee,{children:"Loading…"})]})}function nse({agent:e,all:n,engine:s,providers:r,accounts:a,shown:i,onShow:l,onRun:o,onSaved:c}){const u=(s==null?void 0:s.provider)??e.provider.kind,h=r.find(b=>b.kind===u),m=(s==null?void 0:s.model)??e.model,[f,p]=d.useState(String((s==null?void 0:s.maxTurns)??e.maxTurns)),[x,g]=d.useState(null),w=b=>{o(T.setAgentEngine(e.id,b))},v=b=>{const S=r.find(C=>C.kind===b);w({provider:b,model:(S==null?void 0:S.defaultModel)??m})},j=(h==null?void 0:h.models.map(b=>b.id))??[],y=j.includes(m)?j:[m,...j],k=s?s.available:!0,N=(s==null?void 0:s.unavailableReason)??"no credential";return t.jsxs(t.Fragment,{children:[t.jsx("div",{hidden:i!=="identity",children:t.jsxs(ue,{gap:"lg",children:[k?null:t.jsxs(Q,{tone:"warning",children:["This agent cannot run right now."," ",t.jsx("a",{href:Qt(e.id,"setup","brain"),onClick:b=>{b.preventDefault(),l("brain")},children:"See Brain."})]}),t.jsx(sse,{agent:e,onSaved:c})]})}),t.jsx("div",{hidden:i!=="brain",children:t.jsxs(ue,{gap:"lg",children:[k?null:t.jsxs(Q,{tone:"warning",children:["This agent cannot run right now: ",N,"."]}),t.jsx(ye,{panel:!0,children:t.jsxs(ue,{divided:!0,children:[t.jsxs(ye,{title:"Runs on",children:[a?t.jsx(use,{agentId:e.id,accounts:a,onRun:o}):t.jsxs(Vs,{children:[t.jsx(le,{label:"Provider",children:t.jsx("select",{value:u,onChange:b=>v(b.target.value),children:r.map(b=>t.jsxs("option",{value:b.kind,children:[b.kind,b.usable?"":" (no credential)"]},b.kind))})}),t.jsxs(le,{label:"Model",children:[t.jsx("input",{list:`models-${e.id}`,defaultValue:m,onBlur:b=>{b.target.value.trim()!==""&&b.target.value.trim()!==m&&w({model:b.target.value.trim()})}}),t.jsx("datalist",{id:`models-${e.id}`,children:y.map(b=>t.jsx("option",{value:b},b))})]})]}),a?null:t.jsxs("p",{className:"ui-card-meta",children:[(s==null?void 0:s.credentialKind)??e.provider.credentialKind," from"," ",t.jsx("span",{className:"mono",children:(s==null?void 0:s.credentialEnv)??e.provider.credentialEnv}),h&&!h.usable?` · default model ${h.defaultModel} (${h.defaultFrom})`:""]}),s!=null&&s.restartRequired?t.jsx("p",{className:"warning",children:"This file has changed since the service loaded it. Run `buddi service restart`."}):null]}),t.jsx(ye,{title:"Behaviour",aside:"saved as you change them",children:t.jsxs(Vs,{children:[t.jsx(le,{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:x?t.jsx("span",{className:"critical save-error",role:"alert",children:x}):null,children:t.jsx("input",{type:"number",min:xx,max:jx,value:f,onChange:b=>{p(b.target.value),g(null)},onBlur:()=>{const b=Number(f);if(!Number.isInteger(b)||b<xx||b>jx){g(`Between ${xx} and ${jx}.`);return}b!==((s==null?void 0:s.maxTurns)??e.maxTurns)&&w({maxTurns:b})}})}),t.jsx(le,{label:"Language",hint:"Mirror answers in whatever language you write.",children:t.jsx("select",{value:(s==null?void 0:s.language)??e.language,onChange:b=>w({language:b.target.value}),children:Zne.map(b=>t.jsx("option",{value:b,children:b},b))})}),s?t.jsx(le,{label:"New chat after",hint:"Idle time before your next message starts a fresh conversation, with a carried-over note. A transcript that grows too long starts one either way.",children:t.jsx("select",{"aria-label":"New chat after",value:s.idleRollover??"3h",onChange:b=>w({idleRollover:b.target.value==="3h"?null:b.target.value}),children:ese.map(b=>t.jsx("option",{value:b.value,children:b.label},b.value))})}):null,kR(NR(s??{id:e.id,provider:u},a))?t.jsx(le,{label:"Thinking",hint:"Reasoning before the answer. Off is faster and cheaper.",children:t.jsxs("select",{"aria-label":"Thinking",value:(s==null?void 0:s.thinking)??"default",onChange:b=>w({thinking:b.target.value==="default"?null:b.target.value}),children:[t.jsx("option",{value:"default",children:"Model default"}),t.jsx("option",{value:"on",children:"On"}),t.jsx("option",{value:"off",children:"Off"})]})}):t.jsx(le,{label:"Thinking",hint:DU,children:t.jsx("span",{className:"ui-card-meta",children:"Up to the model"})})]})})]})}),t.jsx(Vt,{summary:"Built-in context",boxed:!0,children:t.jsx("p",{className:"ui-card-meta",children:"Every agent receives current time, owner timezone and server-host information. system.time and system.info are always available, without grants or approval. Host and browser access still require their own permissions."})})]})}),t.jsx("div",{hidden:i!=="tools",children:t.jsxs(ue,{gap:"lg",children:[t.jsx(rse,{agent:e,all:n,onSaved:c}),s&&e.tools.some(b=>b==="browser.*"||b.startsWith("browser."))?t.jsx(ye,{title:"Where it may look",aside:"saved as you change it",panel:!0,children:t.jsxs("div",{className:"br-adv-row",children:[t.jsxs("span",{className:"br-adv-head",children:[t.jsxs("span",{className:"br-adv-title",children:["Pages for ",e.name]}),t.jsxs("span",{className:"br-adv-hint",children:["A conversation’s Use my Chrome comes first, then this, then ",t.jsx("a",{href:tW,children:"Browser & apps"}),". A rule never allows what is off there."]})]}),t.jsx(zv,{value:s.browser??"auto",label:`Where ${e.name} may look`,apps:!1,onChange:b=>w({browser:b})})]})}):null,t.jsx(Qne,{agentId:e.id,agentName:e.name,readOnly:e.isExample===!0,version:e.tools.join(","),onSaved:c})]})}),t.jsx("div",{hidden:i!=="team",children:t.jsx(ue,{gap:"lg",children:t.jsx(mse,{agent:e,all:n,onSaved:c})})})]})}function UO({dirty:e,busy:n,failure:s,label:r,onSave:a}){return t.jsxs(t.Fragment,{children:[s?t.jsx("span",{className:"critical save-error",role:"alert",children:s}):t.jsx("span",{className:e?"warning":"muted",children:e?"Not saved yet.":"Saved. Applies to new runs."}),t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx($,{variant:"accent",disabled:!e||n,onClick:a,children:r})]})}const BO=t.jsx(Q,{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 sse({agent:e,onSaved:n}){var O;const[s,r]=d.useState(e.name),[a,i]=d.useState(e.handle),[l,o]=d.useState(e.description),[c,u]=d.useState(e.avatar??""),[h,m]=d.useState(!1),f=je(()=>T.agentFile(e.id),[e.id]),[p,x]=d.useState(null),g=((O=f.data)==null?void 0:O.persona.trim())??"",w=p??g,v=f.data!==void 0&&p!==null&&p.trim()!==g,[j,y]=d.useState(!1),[k,N]=d.useState(null),[b,S]=d.useState(null),C=s.trim()!==e.name||a.trim().replace(/^@/,"")!==e.handle||l.trim()!==e.description||c.trim()!==(e.avatar??"")||v,A=c.trim()!==""&&(c.trim()!==(e.avatar??"")||!e.picture),E=fy(A?{...e,avatar:c.trim()}:e),R={...E?{avatar:E}:{},...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...!A&&e.picture?{picture:e.picture}:{}},P=async()=>{y(!0),N(null),S(null);try{const I=await T.updateAgentFile(e.id,{name:s.trim(),handle:a.trim().replace(/^@/,""),description:l.trim(),...c.trim()===""?{}:{avatar:c.trim()},...v&&w.trim()!==""?{persona:w.trim()}:{}});e.picture&&c.trim()!==""&&c.trim()!==(e.avatar??"")&&(await T.removeAgentPicture(e.id),window.dispatchEvent(new Event(Rs))),x(null),f.reload(),S(I.message),n()}catch(I){N(I instanceof Error?I.message:String(I))}finally{y(!1)}};return t.jsx(ye,{title:"Who it is",aside:t.jsx("span",{className:"mono",children:e.id}),panel:!0,foot:e.isExample?void 0:t.jsx(UO,{dirty:C,busy:j,failure:k,label:"Save who it is",onSave:()=>void P()}),children:t.jsxs(ue,{children:[e.isExample?BO:null,b?t.jsx(Q,{tone:"good",role:"status",children:b}):null,t.jsxs(Vs,{children:[t.jsx(le,{label:"Name",hint:"What it is called, everywhere.",children:t.jsx("input",{value:s,disabled:j||e.isExample,onChange:I=>r(I.target.value)})}),t.jsx(le,{label:"Handle",hint:"What you type to reach it. One handle, one agent.",children:t.jsx("input",{value:a,disabled:j||e.isExample,onChange:I=>i(I.target.value)})})]}),t.jsxs(te,{children:[t.jsx(Bn,{id:e.id,name:s.trim()||e.name,size:"xl",face:R}),t.jsx($,{"aria-expanded":h,onClick:()=>m(I=>!I),children:h?"Hide faces":"Change face"})]}),h?t.jsx(ose,{agent:e,avatar:c,onEmoji:u,onChanged:n,disabled:j}):null,t.jsx(le,{label:"Description",hint:"One or two sentences. Its colleagues read this.",children:t.jsx("textarea",{rows:2,value:l,disabled:j||e.isExample,onChange:I=>o(I.target.value)})}),t.jsx(le,{label:"Persona",hint:t.jsxs(t.Fragment,{children:["Who it is and how it works, in its own file. It reads this before every conversation; ",t.jsx("code",{children:"{{today}}"})," is filled in with the date at run time."]}),wide:!0,children:f.error?t.jsx(re,{message:f.error}):f.data?t.jsx("textarea",{className:"setup-persona",value:w,rows:Math.max(6,w.split(`
140
- `).length+1),disabled:j||e.isExample,onChange:I=>x(I.target.value)}):t.jsx(Ee,{children:"Reading its file…"})})]})})}function rse({agent:e,all:n,onSaved:s}){var A;const r=je(()=>T.agentTools(e.id),[e.id,e.tools.join(",")]),[a,i]=d.useState(null),[l,o]=d.useState(()=>new Set((e.roles??[]).filter(AS))),[c,u]=d.useState((e.roles??[]).filter(E=>!AS(E)).join(", ")),[h,m]=d.useState(!1),[f,p]=d.useState(null),[x,g]=d.useState(null),w=(E,R)=>E.split(R).map(P=>P.trim()).filter(P=>P!==""),v=((A=r.data)==null?void 0:A.granted)??e.tools,j=a??v,y=r.data!==void 0&&!gne(j,v),k=$S(l,w(c,/[\n,]/)),N=E=>o(R=>{const P=new Set(R);return P.has(E)?P.delete(E):P.add(E),P}),S=y||!((E,R)=>E.join(",")===R.join(","))(k,$S(new Set(e.roles??[]),e.roles??[])),C=async()=>{m(!0),p(null),g(null);try{const E=await T.updateAgentFile(e.id,{...y&&r.data?{tools:pne(r.data.groups,j)}:{},roles:k});g(E.message),i(null),r.reload(),s()}catch(E){p(E instanceof Error?E.message:String(E))}finally{m(!1)}};return t.jsx(ye,{title:"Roles and tools",panel:!0,foot:e.isExample?void 0:t.jsx(UO,{dirty:S,busy:h,failure:f,label:"Save roles and tools",onSave:()=>void C()}),children:t.jsxs(ue,{children:[e.isExample?BO:null,x?t.jsx(Q,{tone:"good",role:"status",children:x}):null,t.jsxs("div",{className:"ui-field",children:[t.jsx("span",{className:"ui-field-label",id:`roles-${e.id}`,children:"Roles"}),t.jsx("div",{className:"role-chips",role:"group","aria-labelledby":`roles-${e.id}`,children:fb.map(E=>{const R=Y5(n,E.id),P=R&&R.id!==e.id?R:void 0;return t.jsxs("button",{type:"button",className:"role-chip","aria-pressed":l.has(E.id),"data-on":l.has(E.id)?"true":void 0,disabled:h||e.isExample,onClick:()=>N(E.id),children:[t.jsx("span",{className:"role-chip-label",children:E.label}),t.jsx("span",{className:"role-chip-meaning",children:E.meaning}),P?t.jsxs("span",{className:"role-chip-holder",children:["Held by ",P.name,". If both claim it, the one listed first keeps it."]}):null]},E.id)})}),t.jsx("span",{className:"ui-field-hint",children:"Where buddi sends things when you do not say who. Tools are granted below."})]}),t.jsx(le,{label:"Other roles",hint:"Only a plugin that asks for a role by name reads these. Comma separated.",children:t.jsx("input",{value:c,disabled:h||e.isExample,onChange:E=>u(E.target.value)})}),t.jsxs("div",{className:"ui-field",children:[t.jsxs("span",{className:"ui-field-label",children:["Tools · ",v.length," granted"]}),r.error?t.jsx(re,{message:r.error}):r.data?t.jsx(jne,{view:r.data,chosen:j,onChange:i,disabled:h||e.isExample}):t.jsx(Ee,{children:"Loading the installed tools…"})]}),t.jsx(ase,{agentId:e.id,version:v.join(","),disabled:h||e.isExample}),ise(v)?t.jsx(lse,{agentId:e.id}):null]})})}function ase({agentId:e,version:n,disabled:s}){var x;const r=je(()=>Promise.resolve().then(()=>T.rememberedApprovals(e)),[e,n]),a=je(()=>Promise.resolve().then(()=>T.connections()).catch(()=>null),[]),[i,l]=d.useState(null),[o,c]=d.useState(null),u=((x=r.data)==null?void 0:x.tools)??[];if(u.length===0)return null;const h=async(g,w)=>{l(g),c(null);try{await T.setRememberedApproval(e,g,w),r.reload()}catch(v){c(v instanceof Error?v.message:String(v))}finally{l(null)}},m=new Map;for(const g of u)m.set(g.connection,[...m.get(g.connection)??[],g]);const f=g=>{var w,v;return((v=(w=a.data)==null?void 0:w.connections.find(j=>j.slug===g))==null?void 0:v.name)??g},p=g=>g.tool.split(".").slice(2).join(".")||g.tool;return t.jsxs("div",{className:"ui-field",children:[t.jsx("span",{className:"ui-field-label",children:"Connection tools that ask first"}),t.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Remembered approvals",children:[...m].map(([g,w])=>{const v=w.filter(N=>N.rememberable),j=w.filter(N=>!N.rememberable),y=v.filter(N=>N.remembered),k=t.jsxs("span",{className:"remembered-summary",children:[t.jsx("span",{className:"remembered-name",children:f(g)}),t.jsxs("span",{className:"ui-card-meta",children:[` · ${w.length} ask first`,y.length>0?` · ${y.length} remembered: ${y.map(p).join(", ")}`:""]})]});return t.jsxs(Vt,{summary:k,boxed:!0,children:[t.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":`${f(g)}: remember my approval`,children:v.map(N=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:N.remembered,disabled:s||i!==null,onChange:b=>void h(N.tool,b.target.checked),"aria-label":`Remember my approval for ${N.tool}`}),t.jsx("span",{className:"mono",children:p(N)})]},N.tool))}),j.length>0?t.jsxs("p",{className:"ui-card-meta remembered-always",children:["These can delete or destroy something, so they always ask and are never remembered:"," ",t.jsx("span",{className:"mono",children:j.map(p).join(", ")})]}):null]},g)})}),t.jsx(re,{message:o}),t.jsx("span",{className:"ui-field-hint",children:"Tick a tool to remember your approval: it asks once, then runs for this agent."})]})}function ise(e){return e.some(n=>n==="owner.notify"||n==="owner.*"||n==="owner.notify?"||n==="owner.*?")}function lse({agentId:e}){var h,m;const n=je(()=>T.notificationSettings(),[]),[s,r]=d.useState(null),[a,i]=d.useState(!1),[l,o]=d.useState(null),c=s??((m=(h=n.data)==null?void 0:h.settings.agents)==null?void 0:m.muted.includes(e))??!1,u=f=>{i(!0),o(null),r(f),T.setAgentMuted(e,f).then(p=>r(p.agents.muted.includes(e))).catch(p=>{r(!f),o(p instanceof Error?p.message:String(p))}).finally(()=>i(!1))};return t.jsxs("div",{className:"ui-field",children:[t.jsx("span",{className:"ui-field-label",children:"Messages to you"}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:c,disabled:a||!n.data,onChange:f=>u(f.target.checked),"aria-label":"Mute this agent's messages"}),t.jsx("span",{children:"Mute its messages"})]}),t.jsx(re,{message:n.error??l}),t.jsx("span",{className:"ui-field-hint",children:"With owner.notify it can message you itself; muted, it is refused and told so."})]})}function fy(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 ose({agent:e,avatar:n,onEmoji:s,onChanged:r,disabled:a}){const[i,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(null),m=n.trim()!==""&&(n.trim()!==(e.avatar??"")||!e.picture),f=i??(m?{kind:"emoji",value:n.trim()}:e.picture?{kind:"kept",url:e.picture}:null),p=async x=>{if(h(null),x.kind==="emoji"){s(x.value);return}if(x.kind==="kept"){s(e.avatar??"");return}l(x),c(!0);try{await T.uploadAgentPicture(e.id,await _O(x.role)),s(e.avatar??""),r(),window.dispatchEvent(new Event(Rs))}catch(g){h(g instanceof Error?g.message:String(g))}finally{l(null),c(!1)}};return t.jsxs("div",{className:"ui-field",children:[t.jsx("span",{className:"ui-field-label",children:"Face"}),t.jsx(Xne,{face:f,label:"Face",kept:e.picture,disabled:a||o,disableEmoji:e.isExample,onPick:x=>void p(x),children:t.jsx(cse,{agent:e,onChanged:r})}),u?t.jsx("span",{className:"critical save-error",role:"alert",children:u}):null]})}function cse({agent:e,onChanged:n}){const[s,r]=d.useState(null),[a,i]=d.useState(null),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,m]=d.useState(null),[f,p]=d.useState(0);d.useEffect(()=>{if(!s)return i(null);const S=URL.createObjectURL(s);return i(S),()=>URL.revokeObjectURL(S)},[s]);const x=S=>{r(null),p(C=>C+1),m(S),n(),window.dispatchEvent(new Event(Rs))},g=async S=>{o(!0),u(null),m(null);try{x(await S())}catch(C){u(C instanceof Error?C.message:String(C))}finally{o(!1)}},w=()=>g(async()=>(await T.uploadAgentPicture(e.id,s)).note??null),v=()=>g(async()=>(await T.removeAgentPicture(e.id),null)),j={avatar:fy(e),...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...a??e.picture?{picture:a??e.picture}:{}},[y,k]=d.useState(!1),N=d.useRef(null),b=S=>{u(null),m(null),r(S??null)};return t.jsxs("div",{className:"setup-upload","data-dragging":y?"true":void 0,onDragOver:S=>{S.preventDefault(),l||k(!0)},onDragLeave:()=>k(!1),onDrop:S=>{var C;S.preventDefault(),k(!1),l||b((C=S.dataTransfer.files)==null?void 0:C[0])},children:[t.jsxs(te,{children:[t.jsx(Bn,{id:e.id,name:e.name,size:"xl",face:j}),t.jsx("input",{ref:N,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 b((C=S.target.files)==null?void 0:C[0])}},f),t.jsx($,{disabled:l,onClick:()=>{var S;return(S=N.current)==null?void 0:S.click()},children:"Upload a picture"}),t.jsx("span",{className:"setup-upload-name",children:s?s.name:"or drop one here"}),t.jsx("span",{className:"ui-toolbar-spacer"}),e.picture&&!s?t.jsx($,{variant:"ghost",disabled:l,onClick:()=>void v(),children:"Remove picture"}):null,t.jsx($,{variant:"accent",disabled:!s||l,onClick:()=>void w(),children:"Save picture"})]}),c?t.jsx("span",{className:"critical save-error",role:"alert",children:c}):t.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 use({agentId:e,accounts:n,onRun:s}){const r=n.bindings.find(p=>p.agentId===e),[a,i]=d.useState((r==null?void 0:r.accountId)??""),[l,o]=d.useState((r==null?void 0:r.model)??""),[c,u]=d.useState(!1),h=n.accounts.find(p=>p.id===a),m=a!==((r==null?void 0:r.accountId)??"")||l!==((r==null?void 0:r.model)??""),f=n.accounts.find(p=>p.id===(r==null?void 0:r.accountId));return t.jsxs("div",{className:"ui-stack",children:[t.jsxs(te,{valign:"end",children:[t.jsx(le,{label:"Account",children:t.jsxs("select",{value:a,disabled:c,onChange:p=>{var x;i(p.target.value),o(((x=n.accounts.find(g=>g.id===p.target.value))==null?void 0:x.defaultModel)??"")},children:[t.jsx("option",{value:"",children:"Choose an account"}),n.accounts.map(p=>t.jsxs("option",{value:p.id,disabled:!p.enabled,children:[p.label,p.enabled?p.configured?"":" (needs credential)":" (disabled)"]},p.id))]})}),t.jsx($k,{accountId:h!=null&&h.configured?a:void 0,label:"Model",value:l,onChange:o,disabled:c},`${a}:${h==null?void 0:h.revision}`)]}),t.jsxs(te,{children:[m&&a&&l.trim()?t.jsxs("span",{className:"warning",children:["Not saved yet. New runs still use ",f?`${f.label}, ${(r==null?void 0:r.model)??""}`:"nothing","."]}):t.jsx("span",{className:"muted",children:f?`Running on ${f.label} with ${(r==null?void 0:r.model)??"no model"}.`:"No account chosen yet: this agent cannot run until you save one."}),t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx($,{variant:"accent",disabled:c||!a||!l.trim()||!m,onClick:()=>{u(!0),s(T.assignProviderAccount(e,a,l).finally(()=>u(!1)))},children:"Save account selection"})]})]})}const dse=["platform.create_agent","platform.update_agent","platform.write_skill","platform.delete_agent","platform.accept_plugin_agent","platform.accept_plugin_skill"],vx=e=>e.tools.some(n=>dse.includes(n)),hse=["front-desk","maker"],fse={"front-desk":"Can ask: everyone, as the front desk",maker:"Can ask: everyone, as the maker",list:"Can ask: everyone"};function mse({agent:e,all:n,onSaved:s}){const[r,a]=d.useState(e.delegates),[i,l]=d.useState(!1),[o,c]=d.useState(null),[u,h]=d.useState(!1),[m,f]=d.useState(e.delegates),[p,x]=d.useState(e.asksEveryone),[g,w]=d.useState(!1),v=n.filter(E=>E.id!==e.id),j=hse.find(E=>{var R;return(R=e.roles)==null?void 0:R.includes(E)}),y=p===void 0||g,k=g||[...r].sort().join(",")!==[...m].sort().join(","),N=n.filter(E=>E.id!==e.id&&(E.delegates.includes(e.id)||E.asksEveryone!==void 0&&!vx(e))),b=E=>a(R=>R.includes(E)?R.filter(P=>P!==E):[...R,E]),S=async E=>{l(!0),c(null),h(!1);try{const R=await T.setDelegates(e.id,E);f(R.delegates),a(R.delegates),x(R.asksEveryone),w(!1),h(!0),s()}catch(R){c(R instanceof Error?R.message:String(R))}finally{l(!1)}},C=()=>{a(v.filter(E=>!vx(E)).map(E=>E.id)),w(!0),h(!1)},A=k?"Not saved yet.":u?"Saved. Applies to the next run.":y?r.length===0?"Asks nobody.":`May ask ${r.length} agent${r.length===1?"":"s"}.`:"Asks everyone.";return t.jsx(ye,{title:"Delegation",aside:e.tools.includes("agent.delegate")?"holds agent.delegate":"no agent.delegate tool: it cannot ask anyone until granted",panel:!0,foot:e.isExample?void 0:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:k?"warning":"muted",children:A}),t.jsx("span",{className:"ui-toolbar-spacer"}),y&&j!==void 0?t.jsx($,{disabled:i,onClick:()=>void S(["*"]),children:"Let it ask everyone"}):null,y?t.jsx($,{variant:"accent",disabled:!k||i,onClick:()=>void S(r),children:"Save who it can ask"}):t.jsx($,{variant:"accent",disabled:i,onClick:C,children:"Limit to…"})]}),children:t.jsxs(ue,{divided:!0,children:[t.jsxs(ye,{title:"Can ask",children:[e.isExample?t.jsx(Q,{tone:"warning",children:"This agent ships with buddi, so its allowlist is read-only here. Ask Agent Father to make it yours, then it can change."}):null,t.jsx(re,{message:o}),y?v.length===0?t.jsx(Ee,{children:"Nobody else is installed."}):t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"ui-card-meta",children:"Only the agents ticked here. New teammates must be added here before it can ask them."}),t.jsx("ul",{className:"ui-list delegate-list","aria-label":"Agents this one may ask",children:v.map(E=>{const R=vx(E);return t.jsxs("li",{className:"ui-list-row",children:[t.jsx("input",{type:"checkbox",id:`can-ask-${e.id}-${E.id}`,checked:r.includes(E.id),disabled:R||e.isExample||i,onChange:()=>b(E.id)}),t.jsxs("label",{htmlFor:`can-ask-${e.id}-${E.id}`,className:"ui-list-main",children:[t.jsxs("span",{className:"ui-list-title",children:[E.name," ",t.jsxs("span",{className:"mono muted",children:["@",E.handle]})]}),t.jsx("span",{className:"ui-list-sub",children:R?"Makes and changes agents. Never reachable by delegation.":E.description})]})]},E.id)})})]}):t.jsxs("p",{className:"ui-card-meta",children:[fse[p??"list"],". New agents are included without being added here; agents that make and change agents are never reachable by delegation."]})]}),t.jsx(ye,{title:"Asked by",children:N.length===0?t.jsxs("p",{className:"ui-card-meta",children:["No other agent may hand work to ",e.name,"."]}):t.jsx(wW,{children:N.map(E=>t.jsx($e,{children:E.name},E.id))})})]})})}const pse=[{id:"team",label:"Team"},{id:"missions",label:"Missions"},{id:"offers",label:"Offers"},{id:"reminders",label:"Reminders"},{id:"skills",label:"Skills"}],gse=[{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 xse(e){const n=q8(e.hash);return n?t.jsx(jK,{name:n.name,agents:e.agents,navigate:e.navigate,pluginPages:e.pluginPages}):t.jsx(jse,{...e})}function jse({hash:e,timezone:n,navigate:s,agents:r,attention:a,defaultAgentId:i}){var v,j,y,k,N;const l=K8(e),o=((v=/[?&]tab=([a-z]+)/.exec(e))==null?void 0:v[1])??"team",c=b=>S=>{S.preventDefault(),s(b)},u=je(()=>T.agents(),[]),h=cc(),m=je(()=>T.offers(),[],2e4),f=AP(),p=(((j=m.data)==null?void 0:j.offers.length)??0)+f.offers.length,x=((k=(y=u.data)==null?void 0:y.default)==null?void 0:k.defaultAgentId)??i??null,[g,w]=d.useState(null);return t.jsxs("div",{className:"ui-page",children:[t.jsx(nl,{title:"Agents",lede:o==="skills"?`Skills are short texts an agent follows for one kind of task. Each is a file on ${h}, or a folder when scripts and files come with it.`:`Your team. Each one is a file on ${h} — what it can reach is listed on its page.`,actions:o==="skills"?t.jsxs(t.Fragment,{children:[t.jsx($,{onClick:()=>w({kind:"upload",at:Date.now()}),children:"Upload"}),t.jsx($,{variant:"accent",onClick:()=>w({kind:"write",at:Date.now()}),children:"Write a skill"})]}):t.jsx(it,{variant:"accent",href:En(),onClick:c(En()),children:"Add a teammate"})}),t.jsx(ic,{children:pse.map(b=>t.jsx(ml,{href:b.id==="team"?Pt:`${Pt}?tab=${b.id}`,active:o===b.id,count:b.id==="offers"?p:void 0,onClick:c(b.id==="team"?Pt:`${Pt}?tab=${b.id}`),children:b.label},b.id))}),o==="missions"?t.jsx(uO,{timezone:n,embedded:!0}):null,o==="offers"?t.jsx($P,{offers:f.offers,reload:f.reload}):null,o==="offers"?t.jsx(hO,{embedded:!0}):null,o==="reminders"?t.jsx(SO,{timezone:n,embedded:!0}):null,o==="skills"?t.jsx(nne,{faces:r,navigate:s,command:g,openSkill:Uq(e),openFile:zq(e)}):null,o==="team"?t.jsx(vse,{data:u.data,error:u.error,reload:u.reload}):null,o==="team"?r.length===0?t.jsx(ps,{icon:"agents",title:"No agents yet",children:"Each agent is a file in the installation's agents folder."}):t.jsx("div",{className:"agents-grid",children:DI(r,x).map(b=>{const S=yd(a.get(b.id));return t.jsxs("div",{className:"ui-card agent-card","data-interactive":"true",...fl(sc(b)),"data-unavailable":b.available?void 0:"true",children:[t.jsx("div",{className:"agent-card-top"}),t.jsx("div",{className:"agent-card-face",children:t.jsx(Bn,{id:b.id,name:b.name,size:"xl",unavailable:!b.available,face:b})}),t.jsxs("div",{children:[t.jsxs("div",{className:"ui-card-title",children:[t.jsx("a",{className:"agent-card-link",href:Qt(b.id,"conversations"),onClick:c(Qt(b.id,"conversations")),children:b.name}),t.jsxs("span",{className:"agent-card-handle mono faint",children:["@",b.handle]})]}),t.jsx("p",{className:"ui-card-meta agent-card-desc",children:b.description})]}),t.jsxs("div",{className:"ui-row",children:[b.id===x?t.jsx(Po,{children:"front desk"}):null,S?t.jsx($e,{tone:"critical",dot:!0,children:"waiting for you"}):b.available?t.jsx($e,{tone:"good",dot:!0,children:"ready"}):t.jsx($e,{tone:"warning",children:mr(b.unavailableReason??"cannot run",60)}),t.jsx($e,{mono:!0,children:b.model}),t.jsx(it,{className:"agent-card-talk",size:"sm",href:ut(b.id),onClick:c(ut(b.id)),"aria-label":`Talk to ${b.name}`,children:"Talk"})]})]},b.id)})}):null,l?t.jsx(Ye,{title:((N=r.find(b=>b.id===l.agentId))==null?void 0:N.name)??l.agentId,size:"wide",onClose:()=>s(Pt),children:t.jsx(yse,{agentId:l.agentId,agent:r.find(b=>b.id===l.agentId),agents:r,tab:l.tab??"conversations",...l.section?{section:l.section}:{},timezone:n,navigate:s,attention:a})}):null]})}function vse({data:e,error:n,reload:s}){const r=e==null?void 0:e.default,[a,i]=d.useState(null),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,m]=d.useState(null);if(n)return t.jsx(re,{message:n});if(!r||r.choices.length===0)return null;const f=r.defaultAgentId,p=a??f??"",x=p!==""&&p!==f,g=r.problem,w=j=>j.map(y=>{var k;return((k=r.choices.find(N=>N.id===y))==null?void 0:k.name)??y}).join(" and "),v=async()=>{o(!0),u(null),m(null);try{const j=await T.setDefaultAgent(p);m(j.note),i(null),s()}catch(j){u(j instanceof Error?j.message:String(j))}finally{o(!1)}};return t.jsx(lt,{children:t.jsxs("div",{className:"ui-stack",children:[t.jsx(re,{message:c}),(g==null?void 0:g.code)==="multiple-defaults"?t.jsx(Q,{tone:"warning",role:"status",children:`Two agents claim default in their files: ${w(g.agents)}. The one chosen here wins.`}):(g==null?void 0:g.code)==="no-default-agent"?t.jsx(Q,{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?t.jsx(Q,{tone:"good",role:"status",children:h}):null,t.jsxs(te,{children:[t.jsxs("div",{className:"default-agent-text",children:[t.jsx("h3",{className:"default-agent-title",children:"Default agent"}),t.jsx("span",{className:"ui-field-hint",children:"Where a chat that names nobody lands."})]}),t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsxs("select",{"aria-label":"Default agent",value:p,disabled:l,onChange:j=>i(j.target.value),children:[p===""?t.jsx("option",{value:"",children:"Choose an agent"}):null,r.choices.map(j=>t.jsxs("option",{value:j.id,disabled:!j.available,children:[j.name," @",j.handle,j.available?"":" (cannot run)"]},j.id))]}),t.jsx($,{variant:"accent",disabled:l||!x,onClick:()=>void v(),children:"Save"})]})]})})}function yse({agentId:e,agent:n,agents:s,tab:r,section:a,timezone:i,navigate:l,attention:o}){const c=p=>x=>{x.preventDefault(),l(p)},u=yd(o.get(e)),h=(n==null?void 0:n.name)??e,m=Rte(e),f=n!==void 0&&!n.roles.includes(Pr)&&!n.roles.includes(vd);return t.jsxs("div",{className:"ui-stack","data-gap":"lg",children:[t.jsxs("header",{className:"agent-head",children:[t.jsx(Bn,{id:e,name:h,size:"xl",unavailable:n?!n.available:!1,face:n}),t.jsxs("div",{className:"agent-head-text",children:[t.jsx("p",{className:"ui-page-lede",children:(n==null?void 0:n.description)??"This agent is not in the roster right now."}),m.entry?t.jsx(Ite,{entry:m.entry,navigate:l,onUpdated:m.reload}):null,t.jsxs("div",{className:"ui-row",children:[n?t.jsxs("span",{className:"muted mono",children:["@",n.handle]}):null,n?t.jsx("span",{className:"muted",children:n.model}):null,u?t.jsx($e,{tone:"critical",children:u}):n&&!n.available?t.jsx($e,{tone:"warning",children:n.unavailableReason??"cannot run"}):null]})]}),t.jsx("div",{className:"ui-page-actions",children:t.jsxs(it,{variant:"accent",href:ut(e),onClick:c(ut(e)),children:["Talk to ",h]})})]}),n&&!n.available?t.jsxs(Q,{tone:"warning",role:"status",children:[FI(n)," ",t.jsx("a",{href:ze(iv(n).section),children:iv(n).label})]}):null,t.jsx(ic,{children:gse.map(p=>t.jsx(ml,{href:Qt(e,p.id),active:r===p.id,onClick:c(Qt(e,p.id)),children:p.label},p.id))}),r==="conversations"?t.jsx(wse,{agentId:e,navigate:l}):null,r==="missions"?t.jsx(uO,{timezone:i,embedded:!0,agentId:e}):null,r==="offers"?t.jsx(hO,{embedded:!0,agentId:e,agentName:h}):null,r==="reminders"?t.jsx(SO,{timezone:i,embedded:!0,agentId:e}):null,r==="memory"?t.jsx(pO,{embedded:!0,agents:s,timezone:i,agentId:e}):null,r==="skills"?t.jsx(dne,{agentId:e,agentName:h,faces:s,navigate:l}):null,r==="setup"?t.jsx(tse,{agentId:e,section:a,navigate:l}):null,r==="setup"&&f?t.jsx(Mte,{agentId:e,name:h,navigate:l}):null]})}function wse({agentId:e,navigate:n}){const{data:s,error:r}=je(()=>nt.conversations(e,50),[e]);if(r)return t.jsx(Ee,{children:r});const a=(s==null?void 0:s.conversations)??[];return t.jsx(lt,{flush:!0,children:s?a.length===0?t.jsx(ps,{icon:"chat",title:"No conversations yet",children:"Say hello, and the conversation shows up here."}):t.jsx(yt,{children:a.map(i=>t.jsx(pt,{href:ut(e,i.id),onClick:()=>n(ut(e,i.id)),title:mr(i.preview||i.opening||"Untitled conversation",90),sub:`${i.messageCount} message${i.messageCount===1?"":"s"}`,side:Xe(i.lastMessageAt??i.startedAt??i.createdAt??null)},i.id))}):t.jsx(Ee,{children:"Loading…"})})}const bse=3e4;function WO(){const{data:e,reload:n}=je(()=>T.recovery(),[],bse),s=d.useRef(n);return s.current=n,d.useEffect(()=>{const r=()=>{s.current()},a=()=>{document.visibilityState==="visible"&&r()};return window.addEventListener("focus",r),document.addEventListener("visibilitychange",a),()=>{window.removeEventListener("focus",r),document.removeEventListener("visibilitychange",a)}},[]),{data:e,reload:n}}function dE(e){return e.kind==="account"?e.accountId?WI(e.accountId):ze("accounts"):e.kind==="telegram"?ze("telegram"):e.kind==="connection"?e.connectionId?HI(e.connectionId):ze("connections"):e.kind==="email"?e.settingsRoute:ze("secrets")}function kse(e){return e.install?rW(e.install):ov}const Nse=ze("system");function Sse(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 HO="This buddi was restored from a backup. Nothing runs on its own until you finish the checklist.";function Cse({view:e,onLeft:n}){const{secrets:s,plugins:r,pending:a,grants:i}=e.checklist,l=e.checklist.keptTables??[],[o,c]=d.useState(!0),[u,h]=d.useState([]),[m,f]=d.useState(!1),[p,x]=d.useState(null),[g,w]=d.useState(!1),v=r.filter(N=>!N.installed||N.waiting!==void 0||N.loadsAtRestart===!0),j=a.jobs+a.missions+a.approvals+a.telegramChats,y=N=>{h(b=>b.includes(N)?b.filter(S=>S!==N):[...b,N])},k=()=>{f(!0),x(null),rc({kind:"recovery"},()=>T.leaveRecovery({dropPending:o,keepGrants:u})).then(N=>{N&&N.restarting===!1&&Ro(),w(!0),n==null||n()}).catch(N=>x(N instanceof pe?N.message:String(N))).finally(()=>f(!1))};return t.jsx(lt,{title:"Back from a backup",children:t.jsxs(ue,{divided:!0,children:[t.jsxs(ye,{children:[t.jsx(on,{items:[{label:"Restored",value:e.restoredAt??"just now"},{label:"From",value:t.jsx("span",{className:"mono",children:e.archive??"—"})}]}),t.jsx("p",{className:"ui-card-meta",children:"Nothing runs on its own yet: no schedules, no watchers, no phone. Chat works. Go through what is below, then turn this buddi back on."})]}),t.jsx(ye,{title:"Keys to paste again",children:s.length===0?t.jsx(Ee,{children:"Nothing is missing."}):t.jsx(yt,{children:s.map(N=>t.jsx(pt,{title:N.label??N.name,sub:N.name?t.jsx("span",{className:"mono",children:N.name}):void 0,side:N.signIn?t.jsx(it,{size:"sm",href:dE(N),"aria-label":`Sign in again: ${N.label??N.name}`,children:"Sign in again"}):t.jsx(it,{size:"sm",href:dE(N),"aria-label":`Fix ${N.label??N.name}`,children:"Fix"})},`${N.kind}:${N.accountId??N.name}`))})}),t.jsx(ye,{title:"Add-ons to install again",children:v.length===0&&l.length===0?t.jsx(Ee,{children:"Everything the backup named is installed."}):t.jsxs(yt,{children:[v.map(N=>t.jsx(pt,{title:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"mono",children:N.name})," ",N.version]}),sub:Sse(N),side:N.loadsAtRestart?t.jsx(it,{size:"sm",href:Nse,"aria-label":`Restart to load ${N.name}`,children:"Restart"}):N.installed?void 0:t.jsx(it,{size:"sm",href:kse(N),"aria-label":`Install ${N.name} again`,children:N.install?"Install":"Find it"})},N.name)),l.map(N=>t.jsx(pt,{title:t.jsx("span",{className:"mono",children:N.table}),sub:N.sentence},`kept:${N.table}`))]})}),t.jsx(ye,{title:"Work that was waiting",children:j===0?t.jsx(Ee,{children:"Nothing was in flight when the backup was taken."}):t.jsxs(ue,{gap:"sm",children:[t.jsx(on,{items:[{label:"Jobs",value:String(a.jobs)},{label:"Missions",value:String(a.missions)},{label:"Waiting for an answer",value:String(a.approvals)},{label:"Phones",value:String(a.telegramChats)}]}),t.jsxs("label",{className:"recovery-check",children:[t.jsx("input",{type:"checkbox",checked:o,onChange:N=>c(N.target.checked)}),t.jsx("span",{children:"Drop it. It was queued somewhere else, days ago."})]})]})}),t.jsx(ye,{title:"Standing permissions",children:i.length===0?t.jsx(Ee,{children:"No agent had a standing permission."}):t.jsxs(ue,{gap:"sm",children:[t.jsx("p",{className:"ui-card-meta",children:"Each of these lets an agent act without asking. Keep only the ones you meant."}),t.jsx("ul",{className:"recovery-list",children:i.map(N=>t.jsx("li",{children:t.jsxs("label",{className:"recovery-check",children:[t.jsx("input",{type:"checkbox",checked:u.includes(N.id),onChange:()=>y(N.id),"aria-label":`Keep ${N.tool} for ${N.agent}`}),t.jsxs("span",{children:[t.jsx("span",{className:"mono",children:N.tool})," for ",N.agent," ",t.jsx("span",{className:"ui-card-meta",children:N.scope}),N.description?t.jsxs("span",{className:"ui-card-meta",children:[" — ",N.description]}):null]})]})},N.id))})]})}),t.jsx(ye,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{message:p}),g?t.jsx(Q,{tone:"good",role:"status",children:"Turning everything back on. This page comes back in a few seconds."}):t.jsx("p",{className:"ui-card-meta",children:"Leaving starts the schedules, the watchers and the phone again. buddi restarts itself to do it."}),t.jsx(te,{align:"end",children:t.jsx($,{variant:"accent",disabled:m||g,onClick:k,children:"Leave recovery mode"})})]})})]})})}function KO(e){const n=e.map(s=>s.title);return n.length<=1?n.join(""):`${n.slice(0,-1).join(", ")} and ${n[n.length-1]}`}function VO(e){return(e??[]).filter(n=>n.state==="ready"&&n.wakesOnRestart===!0)}function Ese(e){return`${KO(e)} ${e.length===1?"is":"are"} installed; ${e.length===1?"it wakes":"they wake"} up after a restart.`}const GO="buddi.handoverWakes";function hE(e){try{window.localStorage.setItem(GO,VO(e).length>0?"1":"0")}catch{}}function Ase(){try{return window.localStorage.getItem(GO)==="0"}catch{return!1}}function qO({plugins:e,onboarding:n="open"}){const[s,r]=d.useState(null),[a,i]=d.useState(!1),[l,o]=d.useState(null);d.useEffect(()=>{if(e!==void 0){e.length>0&&hE(e);return}if(n==="unknown")return;if(n==="done"&&Ase()){r([]);return}let h=!1;return Promise.resolve().then(()=>T.takeOnProgress()).then(m=>{if(h)return;const f=(m==null?void 0:m.plugins)??[];r(f),n==="done"&&hE(f)}).catch(()=>{h||r([])}),()=>{h=!0}},[e,n]);const c=VO(e??s??[]);if(c.length===0)return null;const u=()=>{i(!0),o(null),rc({kind:"plugins",line:`Loading ${KO(c)}…`},()=>T.serviceAction("restart")).catch(h=>o(h instanceof pe?h.message:String(h))).finally(()=>i(!1))};return t.jsxs(Q,{tone:"accent",role:"status",action:t.jsx($,{size:"sm",variant:"accent",disabled:a,onClick:u,children:"Restart"}),children:[Ese(c),l?` ${l.replace(/[.\s]+$/,"")}.`:" It takes a few seconds, and this page comes back by itself."]})}const fE=3,$se=40;function Tse({agent:e,navigate:n}){var x;const s=d.useRef(null),[r,a]=d.useState(!1),[i,l]=d.useState(null),[o,c]=d.useState(null),u=je(()=>nt.conversations(e.id,fE),[e.id],3e4),h=ts(kb),m=ts("(pointer: coarse)");d.useEffect(()=>{var g;!h&&!m&&((g=s.current)==null||g.focus())},[]);const f=(g,w)=>{a(!0),l(null),(async()=>{try{const{conversationId:v}=await nt.startConversation(e.id),j=await nt.send(e.id,{conversationId:v,text:g,...w.length>0?{attachmentIds:w.map(y=>y.artifactId)}:{}});n(ut(e.id,j.conversationId))}catch(v){l(v instanceof pe?v.message:String(v)),c({text:g,at:Date.now()}),a(!1)}})()},p=(((x=u.data)==null?void 0:x.conversations)??[]).slice(0,fE);return t.jsxs("div",{className:"home-ask",children:[i?t.jsx(re,{message:i}):null,t.jsx(yk,{ref:s,disabled:r||!e.available,running:!1,onSend:f,onStop:()=>{},agentName:e.name,placeholder:`Message ${e.name}…`,draft:o,threadKey:`home.${e.id}`,slim:!0}),p.length>0?t.jsxs("div",{className:"home-continue",children:[t.jsx("span",{className:"home-continue-label",id:`home-continue-${e.id}`,children:"Continue"}),t.jsx("ul",{className:"home-continue-chips","aria-labelledby":`home-continue-${e.id}`,children:p.map(g=>{const w=ut(e.id,g.id),v=g.opening??g.preview??"Untitled conversation",j=Hw(g.lastMessageAt??g.createdAt??g.startedAt??null);return t.jsx("li",{children:t.jsxs("a",{className:"home-continue-chip",href:w,title:v,onClick:y=>{y.preventDefault(),n(w)},children:[t.jsx("span",{className:"home-continue-title",children:mr(v,$se)}),j?t.jsx("span",{className:"home-continue-when",children:j}):null]})},g.id)})})]}):null]})}function Rse(e){const n=e.indexOf("?");if(n===-1)return;const s=new URLSearchParams(e.slice(n+1)).get("tip");return s&&/^[a-z0-9-]{1,40}(,[a-z0-9-]{1,40}){0,4}$/.test(s)?s:void 0}const mE=3,Ise=320,pE=160,Pse=.3,gE=120,Mse=.06,my=14;function Ose(e,n=!1){var v,j,y,k;const s=je(()=>T.tipQueue(e,n),[e,n]),[r,a]=d.useState(new Set),[i,l]=d.useState([]),[o,c]=d.useState(!1),u=((v=s.data)==null?void 0:v.tips)??[];d.useEffect(()=>{l([])},[s.data]);const h=u.filter(N=>!r.has(N.id)),m=[...h.filter(N=>!i.includes(N.id)),...i.flatMap(N=>h.find(b=>b.id===N)??[])],f=!!(e||(j=s.data)!=null&&j.preview),p=d.useCallback((N,b)=>{b==="later"?l(S=>[...S.filter(C=>C!==N),N]):a(S=>new Set(S).add(N)),!f&&(b==="dismiss"?T.dismissTip(N):T.laterTip(N)).catch(()=>{})},[f]),{reload:x}=s,g=d.useCallback(async N=>{await T.restoreTip(N),a(S=>{const C=new Set(S);return C.delete(N),C}),c(!1),x()},[x]),w=(((y=s.data)==null?void 0:y.dismissed)??0)+[...r].filter(N=>u.some(b=>b.id===N)).length;return{tips:m,shown:u.length>0&&!(m.length===0&&o),loaded:s.data!==void 0||s.error!==null,allDismissed:m.length===0&&((((k=s.data)==null?void 0:k.dismissed)??0)>0||u.length>0),error:s.error,dismissed:w,restore:g,leave:p,folded:d.useCallback(()=>c(!0),[])}}function Dse(e){return Math.max(-my,Math.min(my,e*Mse))}function Lse({queue:e,navigate:n}){const s=ts("(prefers-reduced-motion: reduce)"),[r,a]=d.useState({kind:"rest"}),i=d.useRef(null),l=d.useRef(null),o=d.useRef(null),c=d.useRef(null),{tips:u,leave:h,folded:m}=e,f=u.length===0;d.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]),d.useEffect(()=>{if(!f||!e.shown)return;const S=setTimeout(m,pE);return()=>clearTimeout(S)},[f,e.shown,m]);const p=d.useCallback(S=>{const C=u[0];!C||r.kind==="fly"||(a({kind:"fly",id:C.id,how:S}),c.current=setTimeout(()=>{h(C.id,S),a({kind:"rest"})},s?pE:Ise))},[u,r.kind,h,s]);if(!e.shown)return null;const x=u[0],g=r.kind==="fly",w=u.slice(0,mE+(g?1:0)),v=S=>{var C,A;g||S.button>0||S.target.closest("button, a, input")||(o.current={id:S.pointerId,x:S.clientX,width:S.currentTarget.offsetWidth},(A=(C=S.currentTarget).setPointerCapture)==null||A.call(C,S.pointerId),a({kind:"drag",dx:0}))},j=S=>{const C=o.current;!C||C.id!==S.pointerId||a({kind:"drag",dx:S.clientX-C.x})},y=S=>{const C=o.current;if(!C||C.id!==S.pointerId)return;o.current=null;const A=S.type==="pointercancel"?0:S.clientX-C.x,E=C.width>0?Math.min(gE,C.width*Pse):gE;Math.abs(A)>=E?p(A<0?"later":"dismiss"):a({kind:"snap"})},k=S=>{S.key==="ArrowLeft"?(S.preventDefault(),p("later")):S.key==="ArrowRight"?(S.preventDefault(),p("dismiss")):S.key==="Enter"&&S.target===S.currentTarget&&x&&(S.preventDefault(),n(x.action.route))},N=()=>{var S;if(r.kind==="drag")return{transform:`translateX(${r.dx}px) rotate(${Dse(r.dx)}deg)`,transition:"none"};if(r.kind==="fly"&&!s){const C=r.how==="later"?-1:1,A=((S=i.current)==null?void 0:S.offsetWidth)??400;return{transform:`translateX(${C*A*.8}px) rotate(${C*my*1.3}deg)`}}},b=u.length;return t.jsx("div",{className:"tip-stack-fold","data-empty":f?"true":void 0,children:t.jsxs("div",{className:"tip-stack-fold-inner",children:[t.jsx("div",{ref:l,className:"tip-stack",role:"group","aria-roledescription":"stack of tips","aria-label":x?`Tips, 1 of ${b}. Left arrow: not now. Right arrow: not this again. Enter: ${x.action.label}.`:"Tips",tabIndex:f?-1:0,onKeyDown:k,"data-motion":s?"reduced":"full","data-depth":Math.min(b,mE)-1,"data-testid":"tip-stack",children:w.map((S,C)=>{const A=C===0,E=g&&A,R=g?Math.max(0,C-1):C;return t.jsx("div",{ref:A?i:void 0,className:"tip-stack-card","data-tip":S.id,"data-depth":E?"leaving":R,"data-dragging":A&&r.kind==="drag"?"true":void 0,"data-leaving":E?r.how:void 0,style:{zIndex:w.length-C,...A?N():{}},"aria-hidden":A?void 0:!0,...A?{}:{inert:""},...A?{onPointerDown:v,onPointerMove:j,onPointerUp:y,onPointerCancel:y}:{},children:t.jsx(Ls,{kind:"tip",tone:"accent",icon:"bulb",title:S.text,from:"A tip from buddi",actions:t.jsx($,{variant:"accent",tabIndex:A&&!E?void 0:-1,onClick:()=>n(S.action.route),children:S.action.label})})},S.id)})}),x?t.jsxs("div",{className:"tip-stack-nav",children:[t.jsxs($,{variant:"ghost",size:"sm",title:"It may come back after a while",disabled:g,onClick:()=>p("later"),children:[t.jsx(ne,{name:"chevron-left",size:14}),"Not now"]}),t.jsxs("span",{className:"tip-stack-count","aria-live":"polite",children:["1 of ",b]}),t.jsxs($,{variant:"ghost",size:"sm",title:"Never show this tip again",disabled:g,onClick:()=>p("dismiss"),children:["Not this again",t.jsx(ne,{name:"chevron-right",size:14})]})]}):null]})})}const py="buddi.tipsOpen",gy="buddi.tipsSeen";function Fse(){try{return window.localStorage.getItem(py)==="1"}catch{return!1}}function _se(){try{const e=JSON.parse(window.localStorage.getItem(gy)??"[]");return Array.isArray(e)?e.filter(n=>typeof n=="string"):[]}catch{return[]}}function zse(e){try{e.length?window.localStorage.setItem(gy,JSON.stringify(e)):window.localStorage.removeItem(gy)}catch{}}function Use(e){const[n,s]=d.useState(()=>!!e||Fse());d.useEffect(()=>{e&&s(!0)},[e]);const r=d.useCallback(u=>{if(s(u),!e)try{u?window.localStorage.setItem(py,"1"):window.localStorage.removeItem(py)}catch{}},[e]),a=Ose(e,!n),[i,l]=d.useState(_se),o=a.tips.map(u=>u.id).join(",");d.useEffect(()=>{if(e||!a.loaded||a.error)return;const u=o?o.split(","):[],h=n?u:i.filter(m=>u.includes(m));h.join(",")!==i.join(",")&&(l(h),zse(h))},[n,o,e,a.loaded,a.error,i]);const c=!n&&!e&&a.tips.some(u=>!i.includes(u.id));return{open:n,setOpen:r,queue:a,unseen:c,preview:!!e}}function Bse({tips:e}){const{open:n,setOpen:s,unseen:r}=e,a=r?"A new tip":"Tips";return t.jsxs("button",{type:"button",className:"ui-icon-btn home-tips-btn","aria-label":a,"aria-pressed":n,title:a,"data-open":n,onClick:()=>s(!n),children:[t.jsx(ne,{name:"bulb"}),r?t.jsx("span",{className:"home-tips-dot","data-testid":"tips-dot"}):null]})}function Wse({tips:e,navigate:n}){const{open:s,setOpen:r,queue:a}=e;if(!s)return null;const i=a.loaded&&!a.shown;return t.jsx("div",{className:"home-tips","data-testid":"tips-section",children:t.jsxs(ye,{title:"Tips",actions:t.jsx($,{variant:"ghost",size:"sm",onClick:()=>r(!1),children:"Close"}),children:[t.jsx(re,{message:a.error}),i&&!a.error?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"home-tips-empty",children:a.allDismissed?"You've turned off every tip that applies.":"No tips right now. New ones appear as you use buddi."}),a.dismissed>0&&!e.preview?t.jsx(Hse,{queue:a}):null]}):t.jsx(Lse,{queue:a,navigate:n})]})})}function Hse({queue:e}){const[n,s]=d.useState(!1),r=e.dismissed;return n?t.jsx(Kse,{queue:e}):t.jsxs("p",{className:"home-tips-dismissed",children:[t.jsxs("span",{children:[r," dismissed"]}),t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx($,{variant:"ghost",size:"sm",onClick:()=>s(!0),children:"Show"})]})}function Kse({queue:e}){var h;const n=je(()=>T.dismissedTips(),[]),[s,r]=d.useState(new Set),[a,i]=d.useState(null),[l,o]=d.useState(null),c=(((h=n.data)==null?void 0:h.tips)??[]).filter(m=>!s.has(m.id)),u=async m=>{i(m),o(null);try{await e.restore(m),r(f=>new Set(f).add(m))}catch(f){o(f instanceof Error?f.message:String(f))}finally{i(null)}};return t.jsxs("div",{className:"home-tips-dismissed-list","data-testid":"tips-dismissed",children:[t.jsx(re,{message:n.error??l}),n.data&&c.length===0?null:t.jsx(yt,{children:c.map(m=>t.jsx(pt,{title:m.text,side:t.jsx($,{size:"sm",disabled:a!==null,onClick:()=>void u(m.id),children:"Bring back"})},m.id))})]})}function Vse(e){return e.length<=1?e[0]??"":e.length<=4?`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`:`${e.slice(0,3).join(", ")} and ${e.length-3} more`}function Gse({glance:e,team:n,onClose:s}){if(!e.today||!e.note)return null;const r=n.filter(a=>a.available).slice(0,8);return t.jsxs("section",{className:"bd-card","aria-label":"Your birthday",children:[e.image?t.jsxs("figure",{className:"bd-art",children:[t.jsx("img",{src:Dr(e.image),alt:"A picture your team made for your birthday"}),t.jsx("figcaption",{children:"Made for you"})]}):null,t.jsxs("div",{className:"bd-body",children:[t.jsx("p",{className:"bd-kicker",children:"From your team"}),t.jsx("p",{className:"bd-note",children:e.note}),r.length>0?t.jsxs("div",{className:"bd-foot",children:[t.jsx("span",{className:"bd-faces",children:r.slice(0,4).map(a=>t.jsx(vn,{agents:n,id:a.id,size:"sm"},a.id))}),t.jsx("span",{className:"bd-sign",children:Vse(r.map(a=>a.name))})]}):null]}),t.jsx("button",{type:"button",className:"ui-icon-btn bd-close","data-size":"sm","aria-label":"Put it away for today",title:"Put it away for today",onClick:s,children:t.jsx(ne,{name:"close"})})]})}const qse="Write these down; they open your backups and only you have them.";function Yse(){var r;const e=je(()=>T.passphraseNotice(),[]),[n,s]=d.useState(!1);return{data:e.data,shown:!n&&!!((r=e.data)!=null&&r.show),gone:()=>s(!0)}}function Qse({notice:e}){const[n,s]=d.useState(null),[r,a]=d.useState(!1),[i,l]=d.useState(null),[o,c]=d.useState(""),[u,h]=d.useState(null),m=e.data;if(!e.shown||!m||!m.show)return null;const f="passphrase"in m?m.passphrase:u,p=()=>{f!==null&&navigator.clipboard.writeText(f).then(()=>s("done"),()=>s("failed"))},x=()=>{a(!0),l(null),T.revealBackupPassphrase(o).then(w=>{h(w.passphrase),c("")}).catch(w=>l(w instanceof pe?w.message:String(w))).finally(()=>a(!1))},g=()=>{a(!0),l(null),T.acknowledgePassphrase().then(()=>e.gone()).catch(w=>l(w instanceof pe?w.message:String(w))).finally(()=>a(!1))};return t.jsxs(Ls,{kind:"passphrase",tone:"accent",icon:"key",title:"Your backup passphrase",from:"buddi · after your first backup",actions:f!==null?t.jsxs(t.Fragment,{children:[t.jsx($,{onClick:p,children:n==="done"?"Copied":n==="failed"?"Could not copy":"Copy"}),t.jsx($,{variant:"accent",disabled:r,onClick:g,children:"I saved it"})]}):t.jsx($,{variant:"accent",disabled:r||o==="",onClick:x,children:"Show the words"}),children:[t.jsx(re,{message:i}),t.jsx("p",{children:qse}),f!==null?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"backup-phrase mono","aria-label":"Your backup passphrase",children:f}),t.jsx("p",{className:"ui-card-meta",children:"Later, Settings → Backup shows them again behind your PIN."})]}):t.jsx(le,{label:"Your PIN",hint:"The one that unlocks this dashboard.",children:t.jsx("input",{type:"password",inputMode:"numeric",autoComplete:"off",value:o,onChange:w=>c(w.target.value),onKeyDown:w=>{w.key==="Enter"&&o!==""&&x()}})})]})}const YO="buddi.needsYouView";function Jse(){try{return window.localStorage.getItem(YO)==="list"?"list":"deck"}catch{return"deck"}}function Xse(e){try{window.localStorage.setItem(YO,e)}catch{}}function Zse(e,n,s){const r=(n.alsoFrom??[]).filter(a=>a!==n.agentId).map(s);return r.length===0?e:`${e} · also ${r.join(", ")}`}function ere({rows:e,agents:n,label:s,onOpen:r,onDone:a}){const[i,l]=d.useState(0);if(e.length===0)return t.jsx(Ee,{mascot:!0,children:"Nothing needs you. Your agents are on it."});const o=Math.min(i,e.length-1),c=e[o],u=e.length>1,h=x=>l((o+x+e.length)%e.length),m=()=>r(c),f=()=>a(c),p=x=>{const g=x.target;g.closest('input, textarea, select, [contenteditable="true"]')||(x.key==="ArrowRight"&&u?(x.preventDefault(),h(1)):x.key==="ArrowLeft"&&u?(x.preventDefault(),h(-1)):x.key==="Enter"&&!g.closest("button, a")?(x.preventDefault(),(c.link||c.agentId)&&m()):(x.key==="d"||x.key==="Delete")&&!x.metaKey&&!x.ctrlKey&&!x.altKey&&(x.preventDefault(),f()))};return t.jsx("div",{className:"home-deck","data-depth":Math.min(e.length-1,2),role:"region","aria-label":"Needs you, one at a time","aria-roledescription":"deck",tabIndex:0,onKeyDown:p,children:t.jsx(Ls,{kind:"request",tone:"accent",title:Pu(c),time:c.state==="held"?"today":Xe(c.createdAt),from:t.jsx(Ku,{face:c.agentId?t.jsx(vn,{agents:n,id:c.agentId,size:"sm"}):void 0,children:s(c)}),lead:t.jsxs("span",{className:"home-deck-nav",children:[t.jsx($,{size:"sm",variant:"ghost","aria-label":"Previous",disabled:!u,onClick:()=>h(-1),children:t.jsx(ne,{name:"chevron-left"})}),t.jsxs("span",{className:"home-deck-count","aria-live":"polite",children:[o+1," of ",e.length]}),t.jsx($,{size:"sm",variant:"ghost","aria-label":"Next",disabled:!u,onClick:()=>h(1),children:t.jsx(ne,{name:"chevron-right"})})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx($,{onClick:f,children:"Done"}),c.link||c.agentId?t.jsx($,{variant:"accent",onClick:m,children:"Open"}):null]}),children:c.text||c.action?t.jsxs("div",{className:"home-deck-body",children:[c.text?t.jsx("p",{className:"home-deck-text",children:c.text}):null,c.action?t.jsx("p",{className:"home-deck-text",children:t.jsx("strong",{children:c.action})}):null]}):null})})}function tre({row:e,agents:n,label:s,onOpen:r,onDone:a}){const i=!!(e.link||e.agentId);return t.jsx(Ls,{kind:"request",tone:"accent",compact:!0,title:Pu(e),...i?{href:e.link??"#",onOpen:()=>r(e)}:{},time:e.state==="held"?"today":Xe(e.createdAt),from:t.jsx(Ku,{face:e.agentId?t.jsx(vn,{agents:n,id:e.agentId,size:"sm"}):void 0,children:e.action?`${s(e)} · ${e.action}`:s(e)}),actions:t.jsxs(t.Fragment,{children:[t.jsx($,{size:"sm",onClick:()=>a(e),children:"Done"}),i?t.jsx($,{size:"sm",variant:"accent",onClick:()=>r(e),children:"Open"}):null]})})}function nre({timezone:e,navigate:n,agents:s,defaultAgentId:r,attention:a,update:i,connectionSignals:l=[],hash:o="",pluginPages:c,onboarding:u}){var Ve,Qe,wt,dt,qt,vt,Dt,bn,sn,ce,Me,tt,Tt,bt,Pe,st,_e,en;const h=je(()=>T.overview(),[],15e3),m=je(()=>T.approvals(),[],1e4),f=je(()=>T.missions(),[],6e4),p=je(()=>T.reminders(),[],6e4),x=je(()=>T.conversations(),[],3e4),g=je(()=>T.offers(),[],3e4),w=je(()=>T.proposals(),[],6e4),v=je(()=>T.agentOffers(),[],6e4),j=je(()=>T.owner(),[]),y=je(()=>T.birthday(),[],5*6e4),k=je(()=>T.notificationsNeedingYou(),[],3e4),N=d.useMemo(()=>DI(s,r??null),[s,r]),b=SK(s,r),{busy:S,note:C,failure:A,decide:E}=Pb(()=>{m.reload(),h.reload()}),R=h.data,P=s.find(ee=>ee.id===r)??null,O=ee=>vW(ee,s),I=ee=>rt=>{rt.preventDefault(),n(ee)},F=((Ve=m.data)==null?void 0:Ve.pending)??[],U=((Qe=R==null?void 0:R.jobs)==null?void 0:Qe.failed)??0,L=((wt=R==null?void 0:R.sentinels)==null?void 0:wt.openUrgent)??0,M=((dt=w.data)==null?void 0:dt.open.length)??0,z=(((qt=v.data)==null?void 0:qt.offers)??[]).filter(ee=>!F.some(rt=>EP(rt,ee.plugin,ee.agent))),D=rre(((vt=k.data)==null?void 0:vt.notifications)??[],F),[K,B]=d.useState(new Set),[se,W]=d.useState(Jse),xe=D.filter(ee=>!K.has(ee.id)),me=ee=>{B(rt=>new Set(rt).add(ee.id)),T.notificationSeen(ee.id).catch(()=>{})},ie=ee=>{me(ee);const rt=ee.link??(ee.agentId?ut(ee.agentId):null);rt&&n(rt)},H=ee=>Zse(ee.agentId?O(ee.agentId):ee.pluginId?av(ee.pluginId,c==null?void 0:c.all):sre[ee.kind],ee,O),de=ore(R==null?void 0:R.dismissed,()=>h.reload()),ge=(((Dt=R==null?void 0:R.sentinels)==null?void 0:Dt.errors)??[]).filter(ee=>!de.is(`watcher-error:${ee.sentinelId}`,ee.error)),Ue=((R==null?void 0:R.mail)??[]).filter(ee=>ee.lastError&&!de.is(`source-error:${ee.sourceId}`,ee.lastError)),G=are(a),ae=l.filter(ee=>!de.is(`connection:${ee.id}`,ee.sentence)),J=(((bn=R==null?void 0:R.needsYou)==null?void 0:bn.recovery)??0)>0,Ne=Use(Rse(o)),Ie=Yse(),Y=!!(i&&i.updateAvailable&&!i.checkout&&i.latest&&!de.is("update",i.latest)),X=F.length+G.length+z.length+D.length+ae.length+(J?1:0)+(Ie.shown?1:0)+(Y?1:0)+ge.length+Ue.length;d.useEffect(()=>{var ee,rt;o===Io&&((rt=(ee=document.getElementById(xy))==null?void 0:ee.scrollIntoView)==null||rt.call(ee,{behavior:"smooth",block:"start"}))},[o]);const oe=d.useMemo(()=>{var ee,rt;return hre(((ee=f.data)==null?void 0:ee.missions)??[],((rt=p.data)==null?void 0:rt.reminders)??[])},[f.data,p.data]),ve=(((sn=x.data)==null?void 0:sn.conversations)??[]).slice(0,5),be=((ce=g.data)==null?void 0:ce.offers)??[],Ce=be.slice(0,cre),we=be.length-Ce.length,He=H2(()=>h.reload()),Ze=tee(),Se=d.useMemo(()=>nee(Ze.answer),[Ze.answer]),Le=vre((R==null?void 0:R.needsYou)??{approvals:F.length,questions:G.length,failed:U,urgent:L,proposals:M,agentsToSetUp:z.length,asks:D.length,signIns:ae.length,recovery:J?1:0},(R==null?void 0:R.paused)??!1).map(ee=>{var rt;return ee.key==="urgent"?{...ee,hint:jre(ee.count??0,((rt=R==null?void 0:R.sentinels)==null?void 0:rt.decisions)??[])}:ee});return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"home-band",children:[t.jsxs("header",{className:"home-top",children:[t.jsxs("div",{className:"home-top-text",children:[t.jsxs("p",{className:"home-date",children:[t.jsx("span",{children:gre(R==null?void 0:R.now,e)}),t.jsx(IZ,{glances:R==null?void 0:R.glances,navigate:n,except:Se,hiding:He}),t.jsx(Bse,{tips:Ne})]}),t.jsx("h1",{className:"home-greeting",children:(Me=y.data)!=null&&Me.today?mre(y.data.name??((tt=j.data)==null?void 0:tt.preferredName)??((Tt=j.data)==null?void 0:Tt.displayName)):pre(R==null?void 0:R.now,e,((bt=j.data)==null?void 0:bt.preferredName)||((Pe=j.data)==null?void 0:Pe.displayName))}),t.jsx(yre,{items:Le,navigate:n})]}),t.jsx("div",{className:"home-side",children:t.jsx(XI,{size:"lg",anim:"idle"})})]}),(st=y.data)!=null&&st.today&&y.data.note&&!de.is("birthday",y.data.date)?t.jsx(Gse,{glance:y.data,team:N,onClose:()=>de.close("birthday",y.data.date)}):null]}),t.jsxs("div",{className:"home",children:[P?t.jsx(Tse,{agent:P,navigate:n},P.id):null,t.jsx(Wse,{tips:Ne,navigate:n}),t.jsx(re,{message:h.error??m.error??A}),C?t.jsx("p",{className:"home-note muted",role:"status",children:C}):null,X>0?t.jsx("div",{id:xy,className:"home-needs",children:t.jsx(ye,{title:"Needs you",aside:t.jsx("a",{href:uv,onClick:I(uv),children:"All notifications"}),actions:D.length>0?t.jsx(cn,{label:"Show what needs you as",options:[{value:"list",label:"List"},{value:"deck",label:"Deck"}],value:se,onChange:ee=>{W(ee),Xse(ee)}}):void 0,children:t.jsxs(ue,{children:[F.map(ee=>t.jsx(Mb,{action:ee,timezone:e,busy:S===ee.id,onDecide:E,agentName:O(ee.agentId),agents:s},ee.id)),G.map(ee=>t.jsx(Ls,{kind:"question",tone:"accent",icon:"chat",title:"Asked you a question",href:ee.route,onOpen:()=>n(ee.route),time:Xe(ee.at),from:t.jsxs(Ku,{face:t.jsx(vn,{agents:s,id:ee.agentId,size:"sm"}),children:[O(ee.agentId)," · waiting for your answer"]}),actions:t.jsx($,{variant:"accent",onClick:()=>n(ee.route),children:"Answer"})},ee.agentId)),D.length>0&&se==="list"?t.jsx(ue,{gap:"sm",children:xe.map(ee=>t.jsx(tre,{row:ee,agents:s,label:H,onOpen:ie,onDone:me},ee.id))}):null,D.length>0&&se==="deck"?t.jsx(ere,{rows:xe,agents:s,label:H,onOpen:ie,onDone:me}):null,t.jsx(Qse,{notice:Ie}),Y&&i?t.jsx(Ls,{kind:"update",tone:"accent",icon:"download",title:t.jsxs(t.Fragment,{children:["A newer buddi is ready: ",t.jsx("span",{className:"mono",children:i.latest})]}),from:`buddi · you have ${i.current}`,dismiss:{onClick:()=>de.close("update",i.latest),hint:"Tell me at the next version"},actions:t.jsx(it,{variant:"accent",href:ze("system"),onClick:I(ze("system")),children:"Upgrade from Settings"})}):null,ge.map(ee=>t.jsx(Ls,{kind:"watcher-error",tone:"warning",icon:"alert",title:`Watcher ${ee.sentinelId} failed`,from:"buddi · your watchers",dismiss:{onClick:()=>de.close(`watcher-error:${ee.sentinelId}`,ee.error),hint:"Hide until the error changes"},actions:t.jsx(it,{href:ze("watchers"),onClick:I(ze("watchers")),children:"Open Watchers"}),children:t.jsx("p",{children:ee.error})},ee.sentinelId)),Ue.map(ee=>t.jsx(Ls,{kind:"source-error",tone:"warning",icon:"alert",title:`Source ${ee.sourceId} cannot be read`,from:"buddi · your sources",dismiss:{onClick:()=>de.close(`source-error:${ee.sourceId}`,ee.lastError),hint:"Hide until the error changes"},children:t.jsx("p",{children:ee.lastError})},ee.sourceId)),ae.map(ee=>t.jsx(Ls,{kind:"sign-in",tone:"accent",icon:"plug",title:ee.sentence,from:`${ee.name} · a connection`,dismiss:{onClick:()=>de.close(`connection:${ee.id}`,ee.sentence),hint:"Tell me if it changes"},actions:t.jsx(it,{variant:"accent",href:ze("connections"),onClick:I(ze("connections")),children:"Open Connections"})},ee.id)),z.map(ee=>t.jsx(Db,{plugin:ee.plugin,agent:ee.agent,text:ee.text,label:`Create @${ee.handle}`,handle:ee.handle,card:{from:av(ee.plugin,c==null?void 0:c.all)},onDismiss:()=>{T.dismissAgentOffer(ee.plugin,ee.agent).then(()=>v.reload())}},`${ee.plugin}/${ee.agent}`)),J?t.jsx(Ls,{kind:"recovery",tone:"warning",icon:"archive",title:"Finish restoring this buddi",from:"buddi · restored from a backup",actions:t.jsx(it,{variant:"accent",href:dv,onClick:I(dv),children:"Open the checklist"}),children:t.jsx("p",{children:HO})}):null]})})}):null,t.jsx(qO,{...u?{onboarding:u}:{}}),t.jsx(iee,{widgets:Ze,navigate:n}),t.jsxs(ye,{title:"Your team",aside:b?t.jsx("a",{href:En(),onClick:I(En()),children:"See all teammates"}):t.jsx("a",{href:Pt,onClick:I(Pt),children:"All agents"}),children:[s.length===0?t.jsx(Ee,{mascot:!0,children:"No agents yet. Add one under Agents."}):t.jsxs("div",{className:"home-team",children:[N.map(ee=>{const rt=yd(a.get(ee.id));return t.jsxs("a",{className:"home-face",...fl(sc(ee)),href:ut(ee.id),onClick:I(ut(ee.id)),"data-waiting":rt?"true":void 0,"data-unavailable":ee.available?void 0:"true",children:[t.jsx(Bn,{id:ee.id,name:ee.name,size:"lg",unavailable:!ee.available,face:ee}),t.jsxs("span",{className:"home-face-text",children:[t.jsx("span",{className:"home-face-name",children:ee.name}),t.jsx("span",{className:"home-face-status",children:rt?wre(rt):ee.available?mr(ee.description,60):ee.unavailableReason??"Cannot run right now."})]})]},ee.id)}),b?null:t.jsxs("a",{className:"team-add",href:En(),onClick:I(En()),"data-testid":"team-add",children:[t.jsx(ne,{name:"plus",size:14}),"Add a teammate"]})]}),t.jsx(TK,{navigate:n,newTeam:b,closed:de})]}),Ce.length>0?t.jsx(ye,{title:"On offer",aside:t.jsxs("span",{className:"ui-row",children:[we>0?t.jsxs("a",{href:`${Pt}?tab=offers`,onClick:I(`${Pt}?tab=offers`),children:[we," more"]}):null,t.jsx(dO,{ids:be.map(ee=>ee.id),onDone:()=>g.reload()})]}),children:t.jsx("div",{className:"home-offers",children:Ce.map(ee=>t.jsx(dre,{offer:ee,agents:s,open:I(Qt(ee.agentId,"offers")),onDismissed:()=>g.reload()},ee.id))})}):null,t.jsx(dZ,{}),(en=(_e=w.data)==null?void 0:_e.digest)!=null&&en.latest&&lre(w.data.digest.latest,R==null?void 0:R.now,de.is)?t.jsx(xre,{digest:w.data.digest.latest,go:I,onClose:()=>de.close(QO,w.data.digest.latest.at)}):null,t.jsxs("div",{className:"home-columns",children:[t.jsx(ye,{title:"Coming up",aside:t.jsx("a",{href:`${Pt}?tab=missions`,onClick:I(`${Pt}?tab=missions`),children:"All missions"}),children:t.jsx(lt,{flush:!0,children:oe.length===0?t.jsx(Ee,{mascot:!0,children:"Nothing scheduled. Missions and reminders will show here."}):t.jsx(yt,{children:oe.map(ee=>t.jsx(pt,{href:ee.route,onClick:()=>n(ee.route),lead:t.jsx(vn,{agents:s,id:ee.agentId,size:"sm"}),title:ee.title,sub:`${ee.kind} for ${O(ee.agentId)}`,side:Xe(ee.at)},ee.key))})})}),t.jsx(ye,{title:"Lately",aside:t.jsx("a",{href:ln,onClick:I(ln),children:"All activity"}),children:t.jsx(lt,{flush:!0,children:ve.length===0?t.jsx(Ee,{mascot:!0,children:"Nothing has run yet. Say hello to someone on your team."}):t.jsx(yt,{children:ve.map(ee=>t.jsx(pt,{href:ut(ee.agentId,ee.id),onClick:()=>n(ut(ee.agentId,ee.id)),lead:t.jsx(vn,{agents:s,id:ee.agentId,size:"sm"}),title:ee.opening?mr(ee.opening,80):"Untitled conversation",sub:`${O(ee.agentId)}, ${ee.messageCount} message${ee.messageCount===1?"":"s"}`,side:Xe(ee.lastMessageAt??ee.createdAt)},ee.id))})})})]}),((R==null?void 0:R.home)??[]).filter(ee=>!de.is(xE(ee.id),jE)).map(ee=>t.jsx(bre,{block:ee,onHide:()=>de.close(xE(ee.id),jE)},ee.id)),R!=null&&R.jobs&&R.missions?t.jsxs("p",{className:"home-foot muted",children:[Cn(R.jobs.pending??0)," queued, ",Cn(R.jobs.leased??0)," running, ",Cn(R.missions.enabled)," of ",Cn(R.missions.total)," missions on."," ",R.paused?t.jsx($e,{tone:"warning",children:"paused"}):t.jsx($e,{tone:"good",children:"running"})," ",t.jsx("a",{href:Fu("").replace(/\/conversations\/$/,""),onClick:I(ln),children:"Activity"})," · ",t.jsx("a",{href:ze("system"),onClick:I(ze("system")),children:"System"})]}):null]})]})}const sre={approval:"Approval",question:"Question",watcher:"Watcher",reminder:"Reminder",failure:"Failure",recap:"Report",plugin:"Plugin",agent:"Message"};function rre(e,n){const s=new Set(n.map(r=>r.id));return e.filter(r=>r.needsOwner===!0&&r.kind!=="approval"&&r.kind!=="question"&&r.actedAt===null&&r.state!=="stored"&&r.seenAt===null&&!(r.actionId&&s.has(r.actionId)))}function are(e){const n=[];for(const s of e.values())s.question&&n.push({agentId:s.agentId,at:s.question.at,route:ut(s.agentId,s.question.conversationId)});return n.sort((s,r)=>s.at.localeCompare(r.at))}const QO="digest",ire=3*864e5;function xE(e){return`block:${e}`}const jE="hidden";function lre(e,n,s){if(s(QO,e.at))return!1;const r=Date.parse(e.at),a=n?Date.parse(n):Date.now();return Number.isFinite(r)&&a-r<ire}function ore(e,n){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})),T.homeDismiss(l,o).then(n,()=>{r(c=>{const u={...c};return delete u[l],u})})}}}function JO({label:e,onClick:n}){return t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":e,title:e,onClick:n,children:t.jsx(ne,{name:"close"})})}const cre=6,ure=500;function dre({offer:e,agents:n,open:s,onDismissed:r}){const[a,i]=d.useState(!1),l=d.useRef(null),o=d.useRef(!1),c=()=>{a||(i(!0),T.dismissOffer(e.id).then(r).finally(()=>i(!1)))},u=()=>{l.current!==null&&clearTimeout(l.current),l.current=null};return t.jsxs("span",{className:"home-offer-chip",children:[t.jsxs("a",{className:"home-offer",href:Qt(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()},ure)},onTouchEnd:u,onTouchMove:u,onTouchCancel:u,children:[t.jsx(vn,{agents:n,id:e.agentId,size:"sm"}),t.jsx("span",{children:e.label})]}),t.jsx("button",{type:"button",className:"home-offer-x","aria-label":`Dismiss ${e.label}`,disabled:a,onClick:c,children:"×"})]})}function hre(e,n){const s=[];for(const r of e)r.enabled&&r.nextRun&&s.push({key:`m-${r.id}`,at:r.nextRun,title:r.name,kind:"Mission",agentId:r.agentId,route:Qt(r.agentId,"missions")});for(const r of n)r.state==="pending"&&s.push({key:`r-${r.id}`,at:r.dueAt,title:r.text,kind:"Reminder",agentId:r.agentId,route:Qt(r.agentId,"reminders")});return s.sort((r,a)=>r.at.localeCompare(a.at)).slice(0,5)}function fre(e,n){try{const s=new Intl.DateTimeFormat("en-GB",{hour:"numeric",hourCycle:"h23",timeZone:n}).format(e?new Date(e):new Date);return Number(s)}catch{return new Date().getHours()}}function mre(e){return e?`Happy birthday, ${e}.`:"Happy birthday."}function pre(e,n,s){const r=fre(e,n),a=s!=null&&s.trim()?`, ${s.trim()}`:"";return r<5?`Still up${a}?`:r<12?`Good morning${a}.`:r<18?`Good afternoon${a}.`:`Good evening${a}.`}function gre(e,n){try{return Ks(e?new Date(e):new Date,n,{weekday:!0})}catch{return St(e??null,n)}}function xre({digest:e,go:n,onClose:s}){var i,l;const r=e.summary??[],a=Object.entries(((i=e.feedback)==null?void 0:i.byAgent)??{}).map(([o,c])=>[o,[c.up>0?`${c.up} 👍`:"",c.down>0?`${c.down} 👎`:"",c.neutral>0?`${c.neutral} other`:""].filter(Boolean).join(" ")]).filter(([,o])=>o!=="").map(([o,c])=>{var u;return`${((u=e.agentNames)==null?void 0:u[o])??o}: ${c}`});return r.length===0&&a.length===0?null:t.jsx(ye,{title:"What buddi learned this week",aside:t.jsxs("span",{className:"ui-row",children:[t.jsx("span",{className:"muted",children:Xe(e.at)}),s?t.jsx(JO,{label:"Hide until next week",onClick:s}):null]}),children:t.jsx(lt,{children:t.jsxs(ue,{divided:!0,children:[r.length>0?t.jsx("ul",{className:"home-digest-list","data-plain":"",children:r.map(o=>t.jsxs("li",{children:[o.text,o.link?t.jsxs(t.Fragment,{children:[" · ",t.jsx("a",{href:o.link.route,onClick:n(o.link.route),children:o.link.label})]}):null]},o.key))}):null,a.length>0?t.jsxs("div",{"data-testid":"digest-reactions",children:[t.jsx("p",{className:"ui-card-meta",children:"Your reactions"}),t.jsxs("ul",{className:"home-digest-list",children:[a.map(o=>t.jsx("li",{children:o},o)),(((l=e.feedback)==null?void 0:l.notes)??[]).map((o,c)=>{var u;return t.jsxs("li",{children:["What was off (",((u=e.agentNames)==null?void 0:u[o.agentId])??o.agentId,"): ",o.note]},`note-${c}`)})]})]}):null]})})})}function jre(e,n){const s=n[0];return s?e>1?`${s.title} And ${e-1} more to decide on.`:s.title:`${e} alert${e===1?"":"s"} from your watchers need${e===1?"s":""} a decision.`}const xy="home-needs";function vre(e,n=!1){const s=(a,i,l=`${i}s`)=>a===1?i:l,r=[];return e.approvals>0&&r.push({key:"approvals",count:e.approvals,label:s(e.approvals,"approval")}),e.questions>0&&r.push({key:"questions",count:e.questions,label:s(e.questions,"question")}),e.urgent>0&&r.push({key:"urgent",count:e.urgent,label:s(e.urgent,"urgent alert"),tone:"critical",route:`${ln}/alerts`}),e.failed>0&&r.push({key:"failed",count:e.failed,label:s(e.failed,"failed job"),tone:"critical",route:`${ln}/jobs?state=failed`}),n&&r.push({key:"paused",count:null,label:"Paused",route:`${ln}/jobs`}),e.proposals>0&&r.push({key:"proposals",count:e.proposals,label:s(e.proposals,"proposal"),route:ze("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 yre({items:e,navigate:n}){if(e.length===0)return t.jsx("p",{className:"home-calm",children:"Nothing needs you. Your agents are on it."});const s=()=>{var r,a;(a=(r=document.getElementById(xy))==null?void 0:r.scrollIntoView)==null||a.call(r,{behavior:"smooth",block:"start"})};return t.jsx("p",{className:"home-counts",children:e.map((r,a)=>{const i=t.jsxs(t.Fragment,{children:[r.count!==null?t.jsxs(t.Fragment,{children:[t.jsx("strong",{children:r.count})," "]}):null,r.label]});return t.jsxs(d.Fragment,{children:[a>0?t.jsx("span",{className:"home-count-sep","aria-hidden":"true",children:"·"}):null,r.route?t.jsx("a",{className:"home-count","data-tone":r.tone,title:r.hint,href:r.route,onClick:l=>{l.preventDefault(),n(r.route)},children:i}):t.jsx("button",{type:"button",className:"home-count","data-tone":r.tone,onClick:s,children:i})]},r.key)})})}function wre(e){return e.charAt(0).toUpperCase()+e.slice(1)}function bre({block:e,onHide:n}){const[s,r]=Kb(),a=e.sensitive===!0&&!s,i=t.jsxs("span",{className:"ui-row",children:[e.rows.length>0&&e.rowsTitle&&!a?t.jsxs("span",{className:"muted",children:[e.rowsTitle.toLowerCase()," below"]}):null,e.sensitive?t.jsx(Rb,{size:"sm",shown:!a,onToggle:r}):null,t.jsx(JO,{label:`Hide ${e.title} from Home`,onClick:n})]});return t.jsxs(ye,{title:e.title,aside:i,children:[e.note?t.jsx(Q,{tone:"warning",children:e.note}):null,e.stats.length>0?t.jsx(hp,{children:e.stats.map(l=>t.jsx(Zr,{label:l.label,value:a?t.jsx(NP,{}):l.value,note:a?void 0:l.note,tone:a?void 0:l.tone},l.label))}):null,e.rows.length>0?a?t.jsxs("p",{className:"muted",children:[e.rows.length," item",e.rows.length===1?"":"s"," hidden."]}):t.jsx(lt,{flush:!0,children:t.jsx(yt,{children:e.rows.map((l,o)=>t.jsx(pt,{title:l.title,sub:l.sub,side:l.side?t.jsx("span",{className:l.tone==="critical"?"critical":l.tone==="good"?"good":void 0,children:l.side}):void 0},`${l.title}-${o}`))})}):null]})}const kre="Cloudflare needs a minute or two before the first sign-in works; if its page says it can’t find the application, reload.";async function Nre(e){var n;try{await((n=navigator.clipboard)==null?void 0:n.writeText(e))}catch{}}function Fo({text:e,disabled:n}){return t.jsxs("div",{className:"tailscale-command",children:[t.jsx("code",{className:"mono",children:e}),t.jsx($,{size:"sm",disabled:n,onClick:()=>{Nre(e)},children:"Copy"})]})}function Sre({id:e}){const n=e==="tailscale"?t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"5",cy:"5",r:"1.6"}),t.jsx("circle",{cx:"10",cy:"5",r:"1.6"}),t.jsx("circle",{cx:"15",cy:"5",r:"1.6"}),t.jsx("circle",{cx:"5",cy:"10",r:"1.6"}),t.jsx("circle",{cx:"10",cy:"10",r:"1.6"}),t.jsx("circle",{cx:"15",cy:"10",r:"1.6"}),t.jsx("circle",{cx:"10",cy:"15",r:"1.6"})]}):t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M5.6 14.8h8.6a3.2 3.2 0 0 0 .4-6.4 4.6 4.6 0 0 0-8.9-.9A3.7 3.7 0 0 0 5.6 14.8Z"}),t.jsx("path",{d:"M8.4 11.4l1.4 1.4 2.8-2.8"})]});return t.jsx("span",{className:"access-glyph","aria-hidden":"true",children:t.jsx("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:n})})}const Cre={ready:t.jsx($e,{tone:"good",children:"Ready"}),waiting:t.jsx($e,{children:"Waiting"}),"needs-setup":t.jsx($e,{tone:"warning",children:"Needs setup"}),unanswered:t.jsx($e,{tone:"warning",children:"Not answering"}),off:null};function Ere(){var i,l;const e=je(()=>T.access(),[]),[n,s]=d.useState(null),r=((i=e.data)==null?void 0:i.proxied)===!0,a=(((l=e.data)==null?void 0:l.providers)??[]).filter(o=>o.id==="tailscale"||o.id==="cloudflare-access");return t.jsxs(ye,{title:"Sign in from elsewhere",aside:"checked by buddi on every visit",panel:!0,flush:!0,children:[t.jsx(re,{message:e.error}),r?t.jsx("div",{className:"access-locked",children:t.jsx(Q,{tone:"warning",children:"Change this from the computer buddi runs on."})}):null,t.jsx(yt,{children:a.map(o=>t.jsxs(d.Fragment,{children:[t.jsx(pt,{onClick:()=>s(n===o.id?null:o.id),label:`${o.title}: ${o.status.sentence}`,lead:t.jsx(Sre,{id:o.id}),title:o.title,sub:o.status.sentence,side:t.jsxs("span",{className:"access-side",children:[Cre[o.status.state],t.jsx("span",{className:"access-chevron","data-open":n===o.id?"true":void 0,children:t.jsx(ne,{name:"chevron-right",size:14})})]})}),n===o.id?t.jsx("div",{className:"access-body",children:o.id==="tailscale"?t.jsx(Are,{embedded:!0,onSaved:e.reload}):t.jsx(Rre,{enabled:o.enabled,locked:r,onSaved:e.reload})}):null]},o.id))}),t.jsxs("p",{className:"access-foot",children:["Every way in gives the same session: 12 hours idle, approvals as here, the lock screen. A sign-in link from"," ",t.jsx("span",{className:"mono",children:"buddi dashboard --token"})," works everywhere."]})]})}function Are({embedded:e,onSaved:n}={}){var g;const s=je(()=>T.tailscale(),[]),[r,a]=d.useState(null),[i,l]=d.useState(!1),[o,c]=d.useState(null),[u,h]=d.useState(!1),m=s.data,f=r??((m==null?void 0:m.login)||((g=m==null?void 0:m.self)==null?void 0:g.login)||""),p=(m==null?void 0:m.proxied)===!0,x=w=>{l(!0),c(null),h(!1),T.setTailscale({enabled:w,login:f.trim()}).then(()=>{h(!0),n==null||n()}).catch(v=>c(v instanceof pe?v.message:String(v))).finally(()=>{l(!1),s.reload()})};return t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{message:s.error??o}),t.jsx("p",{className:"ui-card-meta",children:m?m.available&&m.self?`Tailscale is running on this machine as ${m.self.login}.`:m.available?"Tailscale is running on this machine.":"Tailscale is not running here.":"…"}),p?t.jsxs(t.Fragment,{children:[e?null:t.jsx(Q,{tone:"warning",children:"Change this from the computer buddi runs on."}),t.jsx("p",{className:"ui-card-meta",children:m!=null&&m.enabled?`On, for ${f}`:"Off"})]}):null,t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:(m==null?void 0:m.enabled)??!1,disabled:i||!m||p,onChange:w=>x(w.target.checked)}),t.jsx("span",{children:"Let this Tailscale login sign in"})]}),t.jsx(le,{label:"Tailscale login",children:t.jsx("input",{type:"text",value:f,placeholder:"you@example.com",disabled:i||!m||p,onChange:w=>a(w.target.value)})}),t.jsx("p",{className:"ui-card-meta",children:"Anyone signed in to Tailscale as this login, on any device in your tailnet, is signed in to buddi. The proxy must run on this machine:"}),t.jsx(Fo,{text:(m==null?void 0:m.serveCommand)??"tailscale serve",disabled:i||!m}),t.jsx("p",{className:"ui-card-meta",children:"This gives your tailnet the trust this machine already has: buddi cannot tell the Tailscale proxy from another program running here, and any program that can reach the dashboard on this machine can already read buddi’s files."}),u?t.jsx(Q,{tone:"good",role:"status",children:"Saved."}):null,t.jsx(te,{align:"end",children:t.jsx($,{variant:"accent",disabled:i||!m||p,onClick:()=>x((m==null?void 0:m.enabled)??!1),children:"Save"})})]})}const $re=["teamDomain","aud","email","publicOrigin"];function Tre({onSaved:e,extra:n}={}){const s=je(()=>T.cloudflareAccess(),[]),[r,a]=d.useState(!1),[i,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(null),[m,f]=d.useState(null),[p,x]=d.useState(!1),g=s.data,w=i??{teamDomain:(g==null?void 0:g.teamDomain)??"",aud:(g==null?void 0:g.aud)??"",email:(g==null?void 0:g.email)??"",publicOrigin:(g==null?void 0:g.publicOrigin)??""},v=(g==null?void 0:g.proxied)===!0,j=o||!g||v,y=(A,E)=>l({...w,[A]:E}),k=[w.teamDomain.trim()===""?"the team domain":null,w.aud.trim()===""?"the AUD tag":null,w.email.trim()===""?"your email":null].filter(A=>A!==null),N=k.length>0?`To turn this on, fill in ${k.length===1?k[0]:`${k.slice(0,-1).join(", ")} and ${k[k.length-1]}`}.`:null,b=A=>{if(A&&N){a(!0);return}a(!1),c(!0),h(null),x(!1),f(null),T.setCloudflareAccess({enabled:A,...w}).then(E=>{x(!0),E.test&&f(E.test.ok?{ok:!0,sentence:`${E.teamDomain} answered with ${E.test.keys} signing key${E.test.keys===1?"":"s"}.${E.publicOrigin?` Open ${E.publicOrigin} from another device to finish.`:""}`}:{ok:!1,sentence:E.test.error??"Cloudflare’s signing keys could not be fetched."}),l(null),e==null||e()}).catch(E=>h(E instanceof pe?E.message:String(E))).finally(()=>{c(!1),s.reload()})},S=()=>{c(!0),h(null),f(null),T.testCloudflareAccess({teamDomain:w.teamDomain}).then(A=>f({ok:A.ok,sentence:A.ok&&w.publicOrigin?`${A.sentence} Open ${w.publicOrigin} from another device to finish.`:A.sentence})).catch(A=>h(A instanceof pe?A.message:String(A))).finally(()=>c(!1))},C=A=>g==null?void 0:g.setup.fields.find(E=>E.key===A);return t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{message:s.error??u}),v?t.jsx("p",{className:"ui-card-meta",children:g!=null&&g.enabled?`On, for ${g.email} at ${g.teamDomain}`:"Off"}):null,t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:(g==null?void 0:g.enabled)??!1,disabled:j,onChange:A=>b(A.target.checked)}),t.jsx("span",{children:"Let this email sign in through Cloudflare"})]}),t.jsx("ol",{className:"access-steps",children:((g==null?void 0:g.setup.steps)??[]).map(A=>t.jsxs("li",{children:[t.jsx("span",{children:A.text}),A.command?t.jsx(Fo,{text:A.command,disabled:j}):null]},A.text))}),t.jsx("div",{className:"access-grid",children:$re.map(A=>{const E=C(A);return t.jsx(le,{label:(E==null?void 0:E.label)??A,hint:E==null?void 0:E.hint,children:t.jsx("input",{type:A==="email"?"email":"text",className:A==="aud"?"mono":void 0,value:w[A],placeholder:E==null?void 0:E.placeholder,disabled:j,spellCheck:!1,autoComplete:"off",onChange:R=>y(A,R.target.value)})},A)})}),N&&!v&&!((g==null?void 0:g.enabled)??!1)?r?t.jsx(Q,{tone:"critical",role:"alert",children:N}):t.jsx("p",{className:"ui-card-meta",children:N}):null,m?t.jsx(Q,{tone:m.ok?"good":"critical",role:"status",children:m.sentence}):null,t.jsx("p",{className:"ui-card-meta",children:"buddi checks Cloudflare’s signature on every visit and never trusts a header alone. Anyone Cloudflare signs in with this email, on any device, is signed in to buddi."}),p&&!m?t.jsx(Q,{tone:"good",role:"status",children:"Saved."}):null,n??null,t.jsxs(te,{align:"end",children:[t.jsx($,{disabled:j||w.teamDomain.trim()==="",onClick:S,children:"Test my setup"}),t.jsx($,{variant:"accent",disabled:j,onClick:()=>b((g==null?void 0:g.enabled)??!1),children:"Save"})]})]})}const vE=["running","waiting","removing"];function Rre({enabled:e,locked:n,onSaved:s}){const[r,a]=d.useState(null),[i,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(!1),[m,f]=d.useState(!1);d.useEffect(()=>{n||T.cloudflareSetup().then(a).catch(()=>a(null))},[n]);const p=(r==null?void 0:r.progress.state)??"idle",x=vE.includes(p);d.useEffect(()=>{if(!x)return;const j=window.setInterval(()=>{T.cloudflareSetup().then(y=>{a(y),vE.includes(y.progress.state)||s==null||s()}).catch(()=>{})},1500);return()=>window.clearInterval(j)},[x,s]);const g=n?"manual":i??(p!=="idle"?"run":e||r!=null&&r.record?"manual":r?"offer":null),w=(j,y)=>{h(!0),c(null),j().then(k=>{a(k),y&&l(y),s==null||s()}).catch(k=>c(k instanceof pe?k.message:String(k))).finally(()=>h(!1))},v=()=>w(()=>T.removeCloudflareSetup(),"run");if(g===null)return t.jsx("p",{className:"ui-card-meta",children:"…"});if(g==="manual"){const j=r!=null&&r.record&&!n?t.jsxs("p",{className:"ui-card-meta",children:["Set up by buddi for ",r.record.host," on ",r.record.zone,"."]}):null;return t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{message:o}),t.jsx(Tre,{onSaved:s,extra:j}),r!=null&&r.record&&!n?t.jsxs(te,{align:"end",children:[t.jsx($,{disabled:u,onClick:v,children:"Remove what buddi made"}),t.jsx($,{disabled:u,onClick:()=>l("form"),children:"Set it up again"})]}):null]})}return g==="offer"?t.jsxs(ue,{gap:"sm",children:[t.jsx("p",{className:"ui-card-meta",children:"buddi can make the tunnel, the DNS record and the Access application for you, with one Cloudflare API token. You run one command; buddi does the rest and tests it."}),t.jsxs(te,{align:"end",children:[t.jsx($,{onClick:()=>l("manual"),children:"I’ll do it myself"}),t.jsx($,{variant:"accent",onClick:()=>l("form"),children:"Set it up for me"})]})]}):g==="form"?t.jsx(Pre,{setup:r,busy:u,failed:o,onCancel:()=>{c(null),l(null)},onStart:j=>w(()=>T.startCloudflareSetup(j),"run")}):t.jsx(Mre,{progress:(r==null?void 0:r.progress)??null,busy:u,failed:o,onStop:()=>w(()=>T.stopCloudflareSetup()),onRetry:()=>l("form"),onAdopt:()=>{const j=r==null?void 0:r.progress;j&&w(()=>T.startCloudflareSetup({host:j.host,email:j.email,adopt:!0}),"run")},onUseSystem:()=>{const j=r==null?void 0:r.progress;j&&w(()=>T.stopCloudflareSetup().then(()=>T.startCloudflareSetup({host:j.host,email:j.email,useSystemDaemon:!0})),"run")},onRemove:v,onAgain:()=>l("form"),tokenStored:(r==null?void 0:r.tokenStored)??!1,forgot:m,onForget:()=>w(()=>T.forgetCloudflareToken().then(j=>(f(!0),j)))})}function Ire(e,n){const s=e.trim().toLowerCase().replace(/\.$/,""),r=n.filter(a=>s.endsWith(`.${a.name.toLowerCase()}`)).sort((a,i)=>i.name.length-a.name.length)[0];return r?{name:s.slice(0,-(r.name.length+1)),zone:r.name}:null}function Pre({setup:e,busy:n,failed:s,onCancel:r,onStart:a}){var U,L;const i=((U=e==null?void 0:e.record)==null?void 0:U.host)??(e==null?void 0:e.progress.host)??"",[l,o]=d.useState(""),[c,u]=d.useState(null),[h,m]=d.useState(!1),[f,p]=d.useState(null),[x,g]=d.useState("buddi"),[w,v]=d.useState(""),[j,y]=d.useState(i),[k,N]=d.useState(((L=e==null?void 0:e.record)==null?void 0:L.email)??(e==null?void 0:e.progress.email)??""),b=d.useRef({token:"",seq:0}),S=(e==null?void 0:e.tokenStored)===!0,C=l.trim(),A=()=>{if(!C&&!S)return;const M=b.current.seq+1;b.current={token:C,seq:M},m(!0),p(null),T.cloudflareZones(C?{token:C}:{}).then(({zones:z})=>{var B;if(b.current.seq!==M)return;u(z);const D=Ire(i,z),K=(B=z.find(se=>{var W;return se.name===((W=e==null?void 0:e.record)==null?void 0:W.zone)}))==null?void 0:B.name;D?(D.name&&g(D.name),v(D.zone)):v(K??(z.length===1?z[0].name:""))}).catch(z=>{b.current.seq===M&&(u(null),p(z instanceof pe?z.message:String(z)))}).finally(()=>{b.current.seq===M&&m(!1)})};d.useEffect(()=>{S&&A()},[]);const E=M=>{o(M),u(null),p(null),m(!1),b.current={token:"",seq:b.current.seq+1}},R=c!==null&&c.length>0,P=x.trim().replace(/\.+$/,""),O=R?P&&w?`${P}.${w}`:"":j.trim(),I=c!==null&&!h&&O!==""&&k.trim()!=="",F={autoComplete:"off",spellCheck:!1,disabled:n};return t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{message:s}),t.jsx("p",{className:"ui-card-meta",children:"Open Cloudflare: the token form comes pre-filled with these permissions. Name it, create it, paste it here."}),t.jsx("ul",{className:"access-perms",children:((e==null?void 0:e.permissions)??[]).map(M=>t.jsx("li",{className:"mono",children:M},M))}),t.jsx(te,{children:t.jsx(it,{size:"sm",href:(e==null?void 0:e.tokenUrl)??"https://dash.cloudflare.com/profile/api-tokens",target:"_blank",rel:"noreferrer",children:"Open Cloudflare ↗"})}),t.jsx(le,{label:"API token",hint:"Kept as an owner secret, used only to set this up and to remove it.",action:t.jsx($,{disabled:n||h||!C&&!S,onClick:A,children:"Check the token"}),children:t.jsx("input",{type:"password",className:"mono",value:l,placeholder:S?"Kept. Paste a new one to replace it":"Paste the token",...F,onChange:M=>E(M.target.value),onBlur:()=>{C&&b.current.token!==C&&A()}})}),h?t.jsx("p",{className:"ui-card-meta",role:"status",children:"Checking the token with Cloudflare…"}):null,t.jsx(re,{message:f}),c!==null?t.jsxs("div",{className:"access-grid",children:[R?t.jsxs(t.Fragment,{children:[t.jsx(le,{label:"Name",hint:O?`Makes ${O}.`:"The part in front of the domain.",children:t.jsx("input",{type:"text",value:x,placeholder:"buddi",...F,onChange:M=>g(M.target.value)})}),t.jsx(le,{label:"Domain",hint:"One of the domains the token can edit.",children:t.jsxs("select",{value:w,disabled:n,onChange:M=>v(M.target.value),children:[w===""?t.jsx("option",{value:"",children:"Choose a domain"}):null,c.map(M=>t.jsx("option",{value:M.name,children:M.name},M.id))]})})]}):t.jsx(le,{label:"Hostname",hint:"The token lists no domain; type the full name.",children:t.jsx("input",{type:"text",value:j,placeholder:"buddi.example.com",...F,onChange:M=>y(M.target.value)})}),t.jsx(le,{label:"Your email",hint:"The one Cloudflare will let in.",children:t.jsx("input",{type:"email",value:k,placeholder:"you@example.com",...F,onChange:M=>N(M.target.value)})})]}):null,t.jsxs(te,{align:"end",children:[t.jsx($,{disabled:n,onClick:r,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:n||!I,onClick:()=>a({...C?{token:C}:{},host:O,email:k.trim(),...R?{zone:w}:{}}),children:"Set it up"})]})]})}const yE="To revoke it in Cloudflare: My Profile → API Tokens.";function Mre({progress:e,busy:n,failed:s,onStop:r,onRetry:a,onAdopt:i,onUseSystem:l,onRemove:o,onAgain:c,tokenStored:u=!1,forgot:h=!1,onForget:m}){if(!e)return t.jsx("p",{className:"ui-card-meta",children:"…"});if(e.state==="removed"||e.state==="removing"){const p=e.state==="removed"&&!e.error&&u&&m!==void 0;return t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{message:s}),e.state==="removing"?t.jsx("p",{className:"ui-card-meta",children:"Removing what buddi made…"}):null,e.state==="removed"&&e.removed.length>0?t.jsxs(Q,{tone:"good",role:"status",children:["Removed ",Dre(e.removed),". Signing in through Cloudflare is off."]}):null,e.error?t.jsx(Q,{tone:"critical",role:"alert",children:e.error}):null,e.uninstall?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"ui-card-meta",children:"Cloudflare’s system service is still installed on this computer. To remove it too:"}),t.jsx(Fo,{text:e.uninstall})]}):null,p?t.jsxs("div",{children:[t.jsx("p",{children:"Your Cloudflare API token is still kept here, and still valid in Cloudflare."}),t.jsx("p",{className:"ui-card-meta",children:yE})]}):null,e.state==="removed"&&h&&!u?t.jsxs(Q,{role:"status",children:["Forgotten here. ",yE]}):null,t.jsxs(te,{align:"end",children:[e.error&&e.state==="removed"?t.jsx($,{disabled:n,onClick:o,children:"Remove again"}):null,p?t.jsx($,{disabled:n,onClick:m,children:"Forget the token"}):null,t.jsx($,{variant:"accent",disabled:n,onClick:c,children:"Set it up again"})]})]})}const f=e.state==="running"||e.state==="waiting";return t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{message:s}),e.state==="done"&&e.url?t.jsxs(Q,{tone:"good",role:"status",children:["Done. Open ",e.url," from another device and sign in as ",e.email,". ",kre]}):null,e.state==="stopped"&&e.error?t.jsx(Q,{role:"status",children:e.error}):null,t.jsx("ol",{className:"cat-steps access-run","aria-live":"polite",children:e.steps.map(p=>{var x;return t.jsxs("li",{className:"cat-step","data-state":p.state,children:[t.jsx("span",{className:"cat-step-mark",children:p.state==="done"?t.jsx(ne,{name:"check",size:12}):p.state==="failed"?t.jsx(ne,{name:"alert",size:14}):null}),t.jsxs("div",{className:"access-run-text",children:[t.jsx("span",{children:p.state==="now"&&p.id!=="connector"?`${p.text}…`:p.text}),p.state==="failed"&&p.why?t.jsx("span",{className:"access-run-why",children:p.why}):null,p.id==="connector"&&p.state!=="done"&&e.connector?t.jsx(Ore,{connector:e.connector,live:f,busy:n,onUseSystem:l}):null,p.id==="connector"&&p.state!=="done"&&e.install?t.jsxs("div",{className:"access-run-more",children:[t.jsx("span",{className:"ui-card-meta",children:((x=e.connector)==null?void 0:x.mode)==="system"?"If the system service runs another tunnel, install it again with this tunnel’s token. buddi never runs sudo itself.":"Run this once in a terminal on this computer. buddi never runs sudo itself."}),t.jsx(Fo,{text:e.install.command}),t.jsx("span",{className:"ui-card-meta",children:e.install.note})]}):null]})]},p.id)})}),t.jsxs(te,{align:"end",children:[f?t.jsx($,{disabled:n,onClick:r,children:"Stop waiting"}):null,e.state==="failed"||e.state==="done"||e.state==="stopped"?t.jsx($,{disabled:n,onClick:o,children:"Remove what buddi made"}):null,e.state==="failed"&&e.adoptable?t.jsx($,{disabled:n,onClick:a,children:"Try again"}):null,e.state==="failed"&&e.adoptable?t.jsx($,{variant:"accent",disabled:n,onClick:i,children:"Use it anyway"}):null,e.state==="failed"&&!e.adoptable||e.state==="stopped"?t.jsx($,{variant:"accent",disabled:n,onClick:a,children:"Try again"}):null]})]})}function Ore({connector:e,live:n,busy:s,onUseSystem:r}){return e.mode==="buddi"&&e.state==="system-daemon"&&e.systemDaemon?t.jsxs("div",{className:"access-run-more",children:[t.jsx("span",{className:"ui-card-meta",children:e.systemDaemon.why}),t.jsx(Fo,{text:e.systemDaemon.command}),n&&r?t.jsx(te,{align:"end",children:t.jsx($,{disabled:s,onClick:r,children:"Use Cloudflare’s system service instead"})}):null]}):e.state==="missing-binary"?t.jsxs("div",{className:"access-run-more",children:[t.jsxs("span",{className:"ui-card-meta",children:[e.detail??"cloudflared isn’t on this computer."," ",e.brew?"Or install it with Homebrew; buddi finds it on its own:":""]}),e.brew?t.jsx(Fo,{text:e.brew}):null]}):e.detail&&e.state!=="running"?t.jsx("div",{className:"access-run-more",children:t.jsx("span",{className:"ui-card-meta",children:e.detail})}):null}function Dre(e){return e.length<=1?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}const Lre=2e3,Fre={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 jy(e){return Fre[e.phase]??e.detail??e.phase}const _re=new Set(["done","failed","rolled-back"]);function XO(e){return e!==void 0&&(_re.has(e.phase)||!!e.finishedAt)}function zre(e,n=!1){const[s,r]=d.useState(void 0),[a,i]=d.useState(!1),[l,o]=d.useState(null),c=d.useRef(!1);return d.useEffect(()=>{if(!e){r(void 0),i(!1),c.current=!1;return}let u=!1;const h=()=>{n&&c.current||T.backupJob(e).then(f=>{if(!u){if(n&&(II({step:jy(f)}),(f.phase==="failed"||f.phase==="rolled-back")&&Ro()),c.current){window.location.reload();return}r(f),o(null),XO(f)&&(u=!0)}}).catch(f=>{if(!u){if(f instanceof pe&&f.status!==0&&f.status<500){n&&Ro(),o(f.message);return}c.current=!0,n||i(!0)}})};h();const m=window.setInterval(h,Lre);return()=>{u=!0,window.clearInterval(m)}},[e,n]),{job:s,away:a,error:l}}function Ure({job:e,away:n,error:s}){return s?t.jsx(re,{message:s}):n?t.jsx(Q,{tone:"warning",role:"status",children:"buddi is restarting. This page comes back on its own when it answers again."}):e?e.phase==="rolled-back"||e.phase==="failed"?t.jsxs(Q,{tone:"critical",role:"alert",children:[jy(e)," ",e.error??""]}):t.jsxs(Q,{tone:e.phase==="done"?"good":void 0,role:"status",children:[jy(e),e.copyLate?" The backup was made, but the copy to your folder did not go through.":"",e.error?` ${e.error}`:""]}):null}function Bre(){var j,y,k,N,b,S,C;const e=je(()=>T.backups(),[],3e4),n=WO(),s=je(()=>T.service(),[]),[r,a]=d.useState(null),[i,l]=d.useState(!1),o=zre(r,i),[c,u]=d.useState(null),[h,m]=d.useState(!1),[f,p]=d.useState(null),x=((j=e.data)==null?void 0:j.supervised)??((y=s.data)==null?void 0:y.supervised),g=f!==null||x===!1,w=((k=e.data)==null?void 0:k.archives)??[],v=(A,E=!1)=>{m(!0),u(null),l(E),A().then(R=>{var P;E&&R.job&&up({kind:"restore",patienceMs:RI}),a(((P=R.job)==null?void 0:P.id)??null)}).catch(R=>{R instanceof pe&&R.status===409?p(R.message):u(R instanceof pe?R.message:String(R))}).finally(()=>{m(!1),e.reload()})};return d.useEffect(()=>{XO(o.job)&&e.reload()},[(N=o.job)==null?void 0:N.phase]),t.jsxs(ue,{gap:"lg",children:[(b=n.data)!=null&&b.active?t.jsx(Cse,{view:n.data,onLeft:n.reload}):null,t.jsx(re,{message:e.error??c}),t.jsx(Ure,{...o}),t.jsx(Hre,{onSaved:()=>e.reload()}),t.jsx(ye,{title:"Backups",panel:!0,actions:t.jsx($,{variant:"accent",size:"sm",disabled:h,onClick:()=>v(()=>T.startBackup(!0)),children:"Back up now"}),children:t.jsxs(ue,{divided:!0,children:[t.jsx(ye,{children:t.jsxs("p",{className:"ui-card-meta",children:["Kept in ",t.jsx("span",{className:"mono",children:((S=e.data)==null?void 0:S.dir)??"…"}),". A backup holds your agents, conversations, memory and files. It never holds a key."]})}),t.jsx(ye,{children:e.data&&w.length===0?t.jsx(ps,{icon:"archive",title:"No backups yet",children:"Make one now, or turn on the nightly backup."}):e.data?t.jsxs(da,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Name"}),t.jsx("th",{children:"Taken"}),t.jsx("th",{children:"Size"}),t.jsx("th",{children:"State"}),t.jsx("th",{})]})}),t.jsx("tbody",{children:w.map(A=>{var E;return t.jsx(Kre,{archive:A,busy:h,database:(E=e.data)==null?void 0:E.database,checkout:g,onVerify:()=>v(()=>T.verifyArchive(A.name)),onRestore:(R,P)=>v(()=>T.restoreArchive({name:A.name,...R?{passphrase:R}:{},...P?{confirm:P}:{}}),!0)},A.name)})})]}):t.jsx(Ee,{children:"Loading…"})})]})}),t.jsx(qre,{}),t.jsx(Yre,{busy:h,checkout:g,checkoutSaid:f,database:(C=e.data)==null?void 0:C.database,onRestore:(A,E,R)=>v(()=>T.restoreUpload(A,{passphrase:E,confirm:R}),!0)})]})}const Wre={enabled:!1,time:"03:00",keep:7,encryptLocal:!0,copyTo:null};function Hre({onSaved:e}){var p;const n=je(()=>T.backupSchedule(),[]),[s,r]=d.useState(null),[a,i]=d.useState(!1),[l,o]=d.useState(null),[c,u]=d.useState(!1);d.useEffect(()=>{n.data&&r(n.data)},[n.data]);const h={...Wre,...s??n.data??{}};if(((p=n.data)==null?void 0:p.supervised)===!1)return t.jsx(ye,{title:"Every night",panel:!0,children:t.jsx(ye,{children:t.jsx(Q,{tone:"warning",children:n.data.error??"This installation schedules its own backups."})})});const m=x=>{u(!1),r({...h,...x})},f=()=>{i(!0),o(null),T.setBackupSchedule(h).then(x=>{r(x),u(!0),e()}).catch(x=>o(x instanceof pe?x.message:String(x))).finally(()=>i(!1))};return t.jsx(ye,{title:"Every night",panel:!0,foot:t.jsx($,{variant:"accent",disabled:a,onClick:f,children:"Save"}),children:t.jsxs(ue,{divided:!0,children:[t.jsx(ye,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{message:l}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:h.enabled,onChange:x=>m({enabled:x.target.checked})}),t.jsx("span",{children:"Back this buddi up on its own"})]}),t.jsxs(Vs,{children:[t.jsx(le,{label:"At",children:t.jsx("input",{type:"time",value:h.time,onChange:x=>m({time:x.target.value})})}),t.jsx(le,{label:"Keep",hint:"How many to keep before the oldest is thrown away.",children:t.jsx("input",{type:"number",min:1,max:365,value:h.keep,onChange:x=>m({keep:Number(x.target.value)||1})})})]}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:h.encryptLocal,onChange:x=>m({encryptLocal:x.target.checked})}),t.jsx("span",{children:"Lock each one with the passphrase"})]})]})}),t.jsx(ye,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(le,{label:"Also copy to a folder",hint:"A second disk, or a folder that syncs somewhere. Left empty, backups stay on this machine.",children:t.jsx("input",{type:"text",value:h.copyTo??"",placeholder:"/Volumes/backup/buddi",onChange:x=>m({copyTo:x.target.value===""?null:x.target.value})})}),c?t.jsxs(Q,{tone:"good",role:"status",children:["Saved.",h.lastRunAt?` Last run ${Xe(h.lastRunAt)}.`:""]}):null]})})]})})}function Kre({archive:e,busy:n,database:s,checkout:r,onVerify:a,onRestore:i}){const[l,o]=d.useState(!1),[c,u]=d.useState(""),[h,m]=d.useState("");return t.jsxs(t.Fragment,{children:[t.jsxs("tr",{children:[t.jsx("td",{className:"mono",children:e.name}),t.jsx("td",{children:Xe(e.createdAt)}),t.jsx("td",{children:Yn(e.bytes)}),t.jsxs("td",{children:[e.encrypted?t.jsx($e,{tone:"good",children:"locked"}):t.jsx($e,{tone:"muted",children:"plain"})," ",e.envelopeOk===!1?t.jsx($e,{tone:"critical",children:"damaged"}):null]}),t.jsx("td",{children:t.jsxs(te,{align:"end",children:[t.jsx($,{size:"sm",disabled:n,onClick:a,children:"Verify"}),t.jsx($,{size:"sm",variant:"ghost",onClick:()=>o(!l),children:"Restore…"})]})})]}),l?t.jsx("tr",{children:t.jsx("td",{colSpan:5,children:r?t.jsx(Q,{tone:"warning",children:ZO}):t.jsx(tD,{what:`${e.name}, taken ${Xe(e.createdAt)}, ${Yn(e.bytes)}`,database:s,needsPassphrase:e.encrypted,passphrase:c,onPassphrase:u,confirm:h,onConfirm:m,busy:n,onCancel:()=>o(!1),onGo:()=>i(c,h)})})}):null]})}const ZO="Restoring needs the packaged installation. In a checkout, run: buddi backup restore <file>";function Vre(e){const n=e.split(/\r?\n/).map(r=>r.trim()).filter(r=>r!==""),s=n[0]==="buddi backup passphrase"?n[1]:n.length===1?n[0]:void 0;return s===void 0||s===""?void 0:s}function Gre(e){return new Promise((n,s)=>{const r=new FileReader;r.onload=()=>n(String(r.result??"")),r.onerror=()=>s(r.error??new Error("unreadable")),r.readAsText(e)})}function eD({archive:e,onPassphrase:n}){const[s,r]=d.useState(null);return t.jsx(le,{label:"Or read it from its .passphrase.txt",hint:s??(e?`Uninstall leaves ${e}.passphrase.txt beside the backup it took.`:"Uninstall leaves one beside the backup it took."),children:t.jsx("input",{type:"file",accept:".txt,text/plain","aria-label":"The passphrase file",onChange:a=>{var l;const i=(l=a.target.files)==null?void 0:l[0];i&&Gre(i).then(o=>{const c=Vre(o);if(c===void 0){r(`${i.name} has no passphrase in it.`);return}n(c),r(`Read from ${i.name}.`)},()=>r(`${i.name} could not be read.`))}})})}function tD({what:e,database:n,needsPassphrase:s,passphrase:r,onPassphrase:a,confirm:i,onConfirm:l,busy:o,onCancel:c,onGo:u}){const h=n??"",m=h===""?i.trim()!=="":i.trim()===h;return t.jsxs(ue,{gap:"sm",children:[t.jsxs(Q,{tone:"warning",children:["This replaces everything in this buddi with ",e,". What is here now is copied first, so a restore that fails puts it back."]}),s?t.jsxs(t.Fragment,{children:[t.jsx(le,{label:"The passphrase this one was locked with",children:t.jsx("input",{type:"password",autoComplete:"off",value:r,onChange:f=>a(f.target.value)})}),t.jsx(eD,{onPassphrase:a})]}):null,t.jsx(le,{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:t.jsx("input",{value:i,onChange:f=>l(f.target.value)})}),t.jsxs(te,{align:"end",children:[t.jsx($,{variant:"ghost",onClick:c,children:"Cancel"}),t.jsx($,{variant:"danger",disabled:o||!m||s&&r==="",onClick:u,children:"Restore"})]})]})}function qre(){const[e,n]=d.useState(null),[s,r]=d.useState(""),[a,i]=d.useState(!1),[l,o]=d.useState(null),[c,u]=d.useState(!1),[h,m]=d.useState(!1),[f,p]=d.useState(""),x=()=>{i(!0),o(null),T.revealBackupPassphrase(h?f:void 0).then(w=>{n(w.passphrase),m(!1),p("")}).catch(w=>{if(w instanceof pe&&w.status===403&&!h){m(!0);return}o(w instanceof pe?w.message:String(w))}).finally(()=>i(!1))},g=()=>{i(!0),o(null),T.setBackupPassphrase(s.trim()).then(w=>{n(w.passphrase),r(""),u(!0)}).catch(w=>o(w instanceof pe?w.message:String(w))).finally(()=>i(!1))};return t.jsx(ye,{title:"The passphrase",panel:!0,children:t.jsxs(ue,{divided:!0,children:[t.jsx(ye,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{message:l}),t.jsx("p",{className:"ui-card-meta",children:"This is the only thing that opens an encrypted backup. Write it down."}),e?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"backup-phrase mono",children:e}),t.jsx(te,{align:"end",children:t.jsx($,{variant:"ghost",onClick:()=>n(null),children:"Hide"})})]}):t.jsxs(t.Fragment,{children:[h?t.jsx(le,{label:"Your PIN",hint:"The one that unlocks this dashboard.",children:t.jsx("input",{type:"password",inputMode:"numeric",autoComplete:"off",value:f,onChange:w=>p(w.target.value),onKeyDown:w=>{w.key==="Enter"&&f!==""&&x()}})}):null,t.jsx(te,{align:"end",children:t.jsx($,{disabled:a||h&&f==="",onClick:x,children:"Reveal"})})]}),c?t.jsx(Q,{tone:"good",role:"status",children:"Saved. Backups made from now on use it; older ones keep the one they were made with."}):null]})}),t.jsx(ye,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(le,{label:"Use my own",hint:"Six words you can read out loud beat a short one nobody can.",children:t.jsx("input",{type:"text",autoComplete:"off",value:s,onChange:w=>{u(!1),r(w.target.value)}})}),t.jsx(te,{align:"end",children:t.jsx($,{variant:"accent",disabled:a||s.trim()==="",onClick:g,children:"Use this one"})})]})})]})})}function Yre({busy:e,checkout:n,checkoutSaid:s,database:r,onRestore:a}){const[i,l]=d.useState(null),[o,c]=d.useState(""),[u,h]=d.useState(""),[m,f]=d.useState(!1);return n?t.jsx(ye,{title:"Restore from a file",panel:!0,children:t.jsx(ye,{children:t.jsx(Q,{tone:"warning",children:s??ZO})})}):t.jsx(ye,{title:"Restore from a file",panel:!0,children:t.jsxs(ue,{divided:!0,children:[t.jsx(ye,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx("p",{className:"ui-card-meta",children:"A backup from another buddi, or one you keep somewhere else."}),t.jsxs(Vs,{children:[t.jsx(le,{label:"The backup file",children:t.jsx("input",{type:"file",onChange:p=>{var x;f(!1),l(((x=p.target.files)==null?void 0:x[0])??null)}})}),t.jsx(le,{label:"Its passphrase",hint:"Only if it was locked with one.",children:t.jsx("input",{type:"password",autoComplete:"off",value:o,onChange:p=>c(p.target.value)})})]}),i!=null&&i.name.endsWith(".age")?t.jsx(eD,{archive:i.name,onPassphrase:c}):null,m?null:t.jsx(te,{align:"end",children:t.jsx($,{variant:"accent",disabled:e||!i,onClick:()=>f(!0),children:"Restore"})})]})}),m&&i?t.jsx(ye,{children:t.jsx(tD,{what:`${i.name}, ${Yn(i.size)}`,database:r,needsPassphrase:!1,passphrase:o,onPassphrase:c,confirm:u,onConfirm:h,busy:e,onCancel:()=>f(!1),onGo:()=>a(i,o,u)})}):null]})})}const vy="gpt-5.5",wE="gpt-6.1-sol";function nD(e){return e.source!=="provider"?null:e.models.some(n=>n.id===wE)?wE:null}const sD="gemini-2.5-pro";function Rp(e){return e.replace(/^models\//,"")}const Mk=/(image|tts|audio|live|embedding|vision|robotics|transcribe)/;function rD(e){const n=e.map(Rp);let s;for(const r of n){const a=/^gemini-(\d+(?:\.\d+)*)-pro(?:-(.+))?$/.exec(r);if(!a||Mk.test(a[2]??""))continue;const i=a[1].split(".").map(Number),l=(a[2]??"")!=="";(!s||mm(i,s.version)>0||mm(i,s.version)===0&&s.preview&&!l)&&(s={id:r,version:i,preview:l})}return(s==null?void 0:s.id)??n.find(r=>r.startsWith("gemini-"))}function aD(e){let n;for(const s of e.map(Rp)){const r=/^gemini-(\d+(?:\.\d+)*)-flash(?:-(.+))?$/.exec(s);if(!r||/lite/.test(r[2]??"")||Mk.test(r[2]??""))continue;const a=r[1].split(".").map(Number),i=(r[2]??"")!=="";(!n||mm(a,n.version)>0||mm(a,n.version)===0&&n.preview&&!i)&&(n={id:s,version:a,preview:i})}return n==null?void 0:n.id}function iD(e){return/^gemini-[\d.]+-pro(?:-|$)/.test(Rp(e))}function Qre(e){return[...new Set(e.map(Rp).filter(n=>n.startsWith("gemini-")&&!Mk.test(n)))]}function lD(e){return e.httpStatus===429||e.state==="rate-limited"||e.state==="quota-exhausted"}function mm(e,n){for(let s=0;s<Math.max(e.length,n.length);s+=1){const r=(e[s]??0)-(n[s]??0);if(r!==0)return r}return 0}function oD(e,n){if(!n||e.kind!=="openai-compatible")return!1;const s=r=>r.replace(/\/+$/,"");return s(e.baseUrl)===s(n)}function Jre({embedded:e,account:n}={}){const{data:s,error:r,reload:a,loading:i}=je(()=>T.providerAccounts(),[]),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,m]=d.useState(""),[f,p]=d.useState(!1),[x,g]=d.useState(!1),[w,v]=d.useState(n??null);d.useEffect(()=>{n&&v(n)},[n]);const j=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(!j)return;const S=setInterval(a,2e3);return()=>clearInterval(S)},[j,a]);const y=async(S,C)=>{o(!0),u(null),m(""),g(!1);try{const A=await S();return m((A==null?void 0:A.warning)??C),a(),!0}catch(A){return u(A instanceof Error?A.message:"Could not apply change."),a(),!1}finally{o(!1)}},k=(s==null?void 0:s.accounts)??[],N=k.find(S=>S.id===w)??k[0],b=S=>{var C;return oD(S,(C=s==null?void 0:s.gemini)==null?void 0:C.baseUrl)?"Gemini":cD(S)};return t.jsxs(Is,{embedded:e,title:"Model accounts",lede:"Give each API key or subscription a name, then pick one per agent. An account never falls back to another credential on its own.",children:[t.jsx(re,{message:r??c}),h&&t.jsx(Q,{tone:"good",role:"status",children:h}),x&&t.jsx(Q,{role:"status",children:i?"Refreshing account status…":r?"Could not refresh account status. Try again.":"Account status refreshed. This checks saved credentials; it does not renew subscription tokens or test connections."}),!s&&!r&&t.jsx(Ee,{children:"Loading accounts…"}),r&&t.jsx(te,{children:t.jsx($,{onClick:a,children:"Retry"})}),s&&t.jsxs(t.Fragment,{children:[(s.vault.locked||s.vault.kind==="none")&&t.jsx(Q,{tone:"warning",children:s.vault.advice||"Run buddi init on the host to configure secure credential storage."}),f&&t.jsx(Ye,{title:"Add an account",onClose:()=>p(!1),children:t.jsx("div",{id:"new-provider-account",children:t.jsx(oae,{accounts:k,codexEnabled:s.codexEnabled,anthropicOAuthEnabled:s.anthropicOAuthEnabled,gemini:s.gemini,busy:l,run:y,onDone:S=>{p(!1),S&&v(S)}})})}),t.jsx(ye,{title:"Accounts",aside:`Secrets live in the ${Xre(s.vault.kind)}; Postgres holds names and assignments only.`,actions:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",size:"sm",disabled:l||i,onClick:()=>{u(null),m(""),g(!0),a()},children:i?"Refreshing…":"Refresh status"}),t.jsx($,{variant:"accent",size:"sm",disabled:l,"aria-expanded":f,"aria-controls":"new-provider-account",onClick:()=>p(!f),children:"Add account"})]}),panel:!0,flush:!0,children:k.length===0?t.jsx(ps,{icon:"chip",title:"No accounts yet",children:"Add one to give your agents a model to run on."}):t.jsxs("div",{className:"accounts",children:[t.jsx("nav",{className:"accounts-list","aria-label":"Accounts",children:k.map(S=>t.jsxs("button",{type:"button",className:"accounts-row","aria-pressed":(N==null?void 0:N.id)===S.id,onClick:()=>v(S.id),children:[t.jsx(Zre,{kind:S.kind,auth:S.auth}),t.jsxs("span",{className:"accounts-row-text",children:[t.jsx("span",{className:"accounts-row-name",children:S.label}),Zu(S)?t.jsxs("span",{className:"accounts-row-sub","data-tone":"warning",children:[b(S)," · back at ",Ok(Zu(S).until)]}):t.jsxs("span",{className:"accounts-row-sub",children:[b(S)," · ",S.assignedAgents.length===0?"no agents":`${S.assignedAgents.length} agent${S.assignedAgents.length===1?"":"s"}`]})]}),t.jsx(dD,{account:S})]},S.id))}),N?t.jsx(aae,{account:N,provider:b(N),anthropicOAuthEnabled:s.anthropicOAuthEnabled,busy:l,run:y},`${N.id}:${N.revision}`):null]})})]})]})}function Xre(e){return e==="keychain"?"macOS Keychain":e==="file"?"encrypted file vault":e==="none"?"vault (none configured)":e}function cD(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":Ak(e)?"mlxh":"OpenAI-compatible"}function uD(e){return e.detectedContextWindowSource==="mlxh"?mne(e.detectedContextWindowTokens):e.detectedContextWindowSource!=="provider"?"assumed":e.kind==="codex"?"from ChatGPT":"from the provider"}function Zre({kind:e,auth:n}){const s=e==="anthropic"?"A":e==="codex"?"G":e==="openai"?"O":"∞",r=e==="anthropic"?"3":e==="codex"?"2":e==="openai"?"5":"4";return t.jsx("span",{className:"ui-avatar","data-tint":r,"aria-hidden":"true",title:`${e} · ${n}`,children:s})}function eae(e){return e==="connected"?"good":["rate-limited","quota-exhausted","provider-unavailable"].includes(e)?"warning":"critical"}function Zu(e,n=Date.now()){const s=e.rateLimit;return e.enabled&&e.configured&&s&&Date.parse(s.until)>n?s:null}const tae=()=>Intl.DateTimeFormat().resolvedOptions().timeZone;function Ok(e,n=new Date,s=tae()){const r=new Date(e),a=i=>i.toLocaleDateString("en-CA",{timeZone:s});return a(r)===a(n)?Lt(r,s):a(r)===a(new Date(n.getTime()+864e5))?`tomorrow at ${Lt(r,s)}`:Ym(r,s)}function dD({account:e,long:n}){const s=Zu(e);if(s){const i=`Rate-limited until ${Ok(s.until)}`;return t.jsx("span",{title:i,children:t.jsx($e,{tone:"warning",children:n?i:"Rate-limited"})})}const r=e.enabled?e.configured?"good":"warning":void 0,a=e.enabled?e.configured?"Configured":"Needs credential":"Disabled";return t.jsx($e,{tone:r,children:a})}function nae({id:e}){const[n,s]=d.useState(!1),r=()=>{var a;(a=navigator.clipboard)==null||a.writeText(e).then(()=>{s(!0),window.setTimeout(()=>s(!1),1600)}).catch(()=>{})};return t.jsxs("span",{className:"accounts-id",children:[t.jsx("code",{className:"accounts-id-text",children:e}),t.jsx($,{variant:"ghost",size:"sm",onClick:r,"aria-label":"Copy the id of this account",children:n?"Copied":"Copy"})]})}function sae({account:e,provider:n,children:s}){const r=Zu(e);if(!r)return null;const a=r.provider??n,i=Ok(r.until);if(r.scope==="day"){const l=e.assignedAgents,o=l.length===1?l[0]:"its agents",c=r.provider==="ChatGPT",u=c?"This ChatGPT plan has reached its usage limit":r.limit!==null?`${r.freeTier?`${a}'s free tier allows`:`${a} allows this account`} ${r.limit.toLocaleString()} ${r.unit??"requests"} a day`:`${a} says this account has used today's allowance`,h=r.freeTier&&r.provider==="Gemini"?", or turn on billing for the key at aistudio.google.com":"";return t.jsxs(Q,{tone:"warning",title:u,action:l.length>0?t.jsx(it,{size:"sm",href:l.length===1?Qt(l[0],"setup","brain"):Pt,children:l.length===1?`Change ${l[0]}'s account`:"Change their accounts"}):void 0,children:[t.jsxs("p",{children:["It resets ",/^tomorrow/.test(i)?i:`at ${i}`,". Until then buddi doesn't send this account's requests to ",a,", so ",l.length?`${o}'s runs stop with this note`:"a run on it stops with this note"," instead of failing again and again. To keep going ",c?"before then":"today",", ",l.length?`give ${o} another account`:"use another account",h,"."]}),s]})}return t.jsxs(Q,{tone:"warning",title:`${a} asked buddi to slow down`,children:[t.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."]}),s]})}function bE({test:e}){return e.state==="connected"?null:t.jsx(Vt,{summary:"Details",children:t.jsx(on,{items:[...e.httpStatus?[{label:"HTTP",value:t.jsx("span",{className:"mono",children:e.httpStatus})}]:[],{label:"Retry after",value:e.retryAt?new Date(e.retryAt).toLocaleString():"not given"},...e.detail?[{label:"Provider said",value:t.jsx("span",{className:"mono",children:e.detail})}]:[],{label:"Tested",value:new Date(e.checkedAt).toLocaleString()}]})})}function rae({account:e,provider:n}){const s=e.test;return Zu(e)&&(!s||["rate-limited","quota-exhausted","connected"].includes(s.state))?t.jsx(sae,{account:e,provider:n,children:s&&t.jsx(bE,{test:s})}):s?t.jsxs(Q,{role:"status",tone:eae(s.state),children:[t.jsx("p",{children:s.message}),t.jsx(bE,{test:s})]}):null}function Dk(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 aae({account:e,provider:n,busy:s,run:r,anthropicOAuthEnabled:a}){const[i,l]=d.useState(!1),[o,c]=d.useState(!1);return t.jsxs("section",{className:"accounts-detail","aria-label":e.label,children:[t.jsxs("div",{className:"ui-card-head",children:[t.jsx("h3",{className:"ui-card-title",children:e.label}),t.jsx(dD,{account:e,long:!0})]}),t.jsx(on,{items:[{label:"Provider",value:n},{label:"Default model",value:t.jsx("span",{className:"mono",children:e.defaultModel||"—"})},{label:"Context window",value:t.jsx("span",{className:"mono",children:`${(e.contextWindowTokens??e.detectedContextWindowTokens??0).toLocaleString()} tokens${e.contextWindowTokens?"":` (${uD(e)})`}`})},...e.baseUrl?[{label:"Endpoint",value:t.jsx("span",{className:"mono",children:e.baseUrl})}]:[],{label:"Used by",value:e.assignedAgents.length?t.jsx("span",{className:"ui-row",children:e.assignedAgents.map(u=>t.jsx("a",{href:Qt(u,"setup","brain"),children:u},u))}):t.jsxs("span",{className:"ui-row",children:[t.jsx("span",{className:"muted",children:"No agents"}),t.jsx("a",{href:Pt,children:"Assign to an agent"})]})},...e.tokenExpiresAt?[{label:"Access token",value:`expires ${St(e.tokenExpiresAt,Intl.DateTimeFormat().resolvedOptions().timeZone)} (not your subscription renewal date)`}]:[],{label:"ID",value:t.jsx(nae,{id:e.id})}]}),e.removalPending&&t.jsx(Q,{tone:"warning",children:"Removal is pending. Unlock the vault, then retry Remove account."}),e.reconnectRequired&&t.jsxs(Q,{tone:"warning",children:["Token refresh did not finish. Reconnect this ",e.kind==="codex"?"ChatGPT":"Claude"," account."]}),e.auth==="anthropic-oauth"&&t.jsx(mD,{account:e,enabled:!!a,busy:s,run:r}),e.kind==="codex"&&t.jsx(hD,{account:e,busy:s,run:r}),e.auth==="device-key"&&t.jsx(fD,{account:e,busy:s,run:r}),t.jsxs(te,{children:[t.jsx($,{disabled:s||e.removalPending,onClick:()=>l(!0),children:"Edit account"}),t.jsx($,{disabled:s||e.removalPending,onClick:()=>void r(()=>T.saveProviderAccount({...Dk(e),enabled:!e.enabled}),e.enabled?"Account disabled. Subsequent model calls will stop; already-sent requests cannot be recalled.":"Account enabled."),children:e.enabled?"Disable":"Enable"}),e.kind!=="codex"&&t.jsx($,{disabled:s||!e.enabled||!e.configured,onClick:()=>void r(async()=>(await T.testProviderAccount(e.id),{warning:""}),""),children:"Test connection"}),t.jsx($,{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"})]}),t.jsx(rae,{account:e,provider:n}),i&&t.jsx(Ye,{title:`Edit ${e.label}`,onClose:()=>l(!1),children:t.jsx(iae,{account:e,busy:s,run:r,onDone:()=>l(!1)})}),o&&t.jsxs(Q,{tone:"critical",children:[t.jsxs("p",{children:["Remove “",e.label,"” and its stored credential from Buddi? This does not revoke it at the provider or remove it from backups."]}),t.jsxs(te,{children:[t.jsx($,{variant:"danger",disabled:s,onClick:()=>void r(()=>T.removeProviderAccount(e.id,e.revision),"Account removed from Buddi."),children:"Confirm removal"}),t.jsx($,{disabled:s,onClick:()=>c(!1),children:"Cancel"})]})]}),t.jsx(Vt,{summary:"Details",children:t.jsxs("div",{className:"ui-prose muted",children:[e.kind==="codex"?t.jsxs(t.Fragment,{children:[t.jsx("p",{children:"Talks to OpenAI’s Codex backend directly with your ChatGPT sign-in. The credential stays in buddi’s vault; buddi refreshes it and never reads your own Codex login."}),t.jsx("p",{children:"Native tool-step usage reporting is incomplete. Do not use Buddi’s token or API-cost estimates as subscription billing or remaining quota."}),t.jsx("p",{children:"After connecting, assign this account to an agent and send a test message. Model turns use your subscription allowance."})]}):t.jsx("p",{children:"Test connection asks the default model to reply with the single word “ready” (at most five tokens, no tools) and may incur a small charge. No conversation or files are sent. Configured does not mean verified."}),e.auth==="device-key"&&t.jsx("p",{children:"Ollama Cloud with a device key: buddi made a key pair and keeps it in the vault; ollama.com only ever saw the public half and this computer’s name. Each request to ollama.com is signed with the key, and nothing else is sent with it. Disconnect asks ollama.com to forget the device and removes the key from buddi either way."}),e.auth==="anthropic-oauth"&&t.jsx("p",{children:"Claude subscription sign-in. Tokens remain in Buddi’s vault and refresh before use. Uses your plan’s monthly Agent SDK credits; after them, an API key. Remaining credits are unknown here."}),t.jsx("p",{children:"Subscription login is separate from API-key access."})]})})]})}function hD({account:e,busy:n,run:s}){var r,a,i;return t.jsxs(t.Fragment,{children:[t.jsxs(te,{children:[t.jsx($,{disabled:n||!e.enabled||e.removalPending||((r=e.login)==null?void 0:r.state)==="pending",onClick:()=>void s(()=>T.codexAccountAction(e.id,"login",e.revision),"Complete device sign-in below."),children:e.configured?"Reconnect ChatGPT":"Connect ChatGPT"}),((a=e.login)==null?void 0:a.state)==="pending"&&t.jsx($,{disabled:n,onClick:()=>void s(()=>T.codexAccountAction(e.id,"cancel-login",e.revision),"Sign-in cancelled."),children:"Cancel sign-in"}),t.jsx($,{disabled:n||!e.configured,onClick:()=>void s(()=>T.codexAccountAction(e.id,"logout",e.revision),"Subscription disconnected from Buddi. Your regular Codex login is unchanged."),children:"Disconnect"})]}),((i=e.login)==null?void 0:i.state)==="pending"&&t.jsxs(Q,{tone:"accent",role:"status",children:[t.jsx("p",{children:"Open openai.com, type this code there and approve buddi."}),e.login.userCode&&t.jsx(Tk,{code:e.login.userCode,large:!0}),e.login.verificationUrl&&t.jsx(te,{children:t.jsx(it,{variant:"accent",href:e.login.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open openai.com"})}),e.login.expiresAt&&t.jsxs("p",{className:"muted",children:["The code works until ",Lt(new Date(e.login.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone),". Start again after that; this is the sign-in timeout, not your subscription expiry."]})]}),e.login&&e.login.state!=="pending"&&t.jsx("p",{role:"status",className:"muted",children:e.login.message??`Sign-in ${e.login.state}.`})]})}function iae({account:e,busy:n,run:s,onDone:r,codexEnabled:a,anthropicOAuthEnabled:i}){const[l,o]=d.useState((e==null?void 0:e.label)??""),[c,u]=d.useState((e==null?void 0:e.kind)??"anthropic"),[h,m]=d.useState((e==null?void 0:e.auth)??"api-key"),[f,p]=d.useState((e==null?void 0:e.baseUrl)??""),[x,g]=d.useState((e==null?void 0:e.defaultModel)??"claude-sonnet-5"),[w,v]=d.useState(""),[j,y]=d.useState(e!=null&&e.contextWindowTokens?String(e.contextWindowTokens):""),k=b=>{u(b),m(b==="codex"?"chatgpt":"api-key"),v(""),p(b==="openai-compatible"?"http://localhost:11434/v1":""),g(b==="anthropic"?"claude-sonnet-5":b==="openai"?"gpt-5":"")},N=!l.trim()||!x.trim();return t.jsxs("form",{className:"ui-stack",onSubmit:b=>{b.preventDefault();const S=w;v(""),s(()=>T.saveProviderAccount({...e?{id:e.id,revision:e.revision}:{},label:l,kind:c,auth:h,baseUrl:f,defaultModel:x,enabled:(e==null?void 0:e.enabled)??!0,contextWindowTokens:j.trim()?Number(j):null,...S.trim()?{secret:S}:{}}),"Account saved. Agent model selections are unchanged.").then(C=>{C&&r()})},children:[t.jsxs("fieldset",{disabled:n,className:"ui-fields","data-stack":"true",children:[t.jsx(le,{label:"Account name",children:t.jsx("input",{autoFocus:!0,required:!0,maxLength:100,value:l,onChange:b=>o(b.target.value),placeholder:"Anthropic — Personal"})}),t.jsx(le,{label:"Provider",children:t.jsxs("select",{disabled:!!e,value:h==="anthropic-oauth"?"anthropic-oauth":h==="device-key"?"ollama-cloud":c,onChange:b=>{b.target.value==="anthropic-oauth"?(k("anthropic"),m("anthropic-oauth")):k(b.target.value)},children:[t.jsx("option",{value:"anthropic",children:"Anthropic API"}),t.jsx("option",{value:"openai",children:"OpenAI API"}),t.jsx("option",{value:"openai-compatible",children:"OpenAI-compatible endpoint"}),(e==null?void 0:e.auth)==="device-key"&&t.jsx("option",{value:"ollama-cloud",children:"Ollama Cloud"}),(i||(e==null?void 0:e.auth)==="anthropic-oauth")&&t.jsx("option",{value:"anthropic-oauth",children:"Claude subscription"}),(a||(e==null?void 0:e.kind)==="codex")&&t.jsx("option",{value:"codex",children:"ChatGPT subscription"})]})}),c==="openai-compatible"&&h!=="device-key"&&t.jsxs(t.Fragment,{children:[t.jsx(le,{label:"API base URL",hint:"Include the API path, such as /v1 or /api/v1. Conversation data will be sent to this endpoint. The model must support tool calling to use agent tools.",children:t.jsx("input",{required:!0,type:"url",value:f,onChange:b=>p(b.target.value)})}),t.jsx(le,{label:"Authentication",children:t.jsxs("select",{disabled:!!e,value:h,onChange:b=>{m(b.target.value),v("")},children:[t.jsx("option",{value:"api-key",children:"API key"}),t.jsx("option",{value:"none",children:"No key (local/self-hosted)"})]})})]}),t.jsx(te,{valign:"end",children:t.jsx($k,{accountId:e!=null&&e.configured&&e.enabled?e.id:void 0,label:"Default model",value:x,onChange:g,disabled:n,...(e==null?void 0:e.kind)==="codex"?{origin:"from ChatGPT",suggest:nD}:{}},`${e==null?void 0:e.id}:${e==null?void 0:e.revision}`)}),t.jsx(le,{label:"Context window",hint:Ak(e)?"mlxh refuses a prompt over its max_prompt_tokens, and its model manager does not report the number, so buddi assumes 8,192. After `mlxh config max_prompt_tokens 40960`, enter the same number here.":"Tokens this endpoint actually serves. Leave blank unless you run the model yourself and set a window of your own — a conversation is ended once its history would fill half of this.",children:t.jsx("input",{type:"number",inputMode:"numeric",min:8e3,max:2e6,step:1e3,value:j,placeholder:e!=null&&e.detectedContextWindowTokens?`${e.detectedContextWindowTokens} (${uD(e)})`:"assumed from the model",onChange:b=>y(b.target.value)})}),c==="codex"&&t.jsx("p",{className:"muted",children:"Pick a model from the list once the account is connected."}),h==="anthropic-oauth"&&t.jsx("p",{className:"muted",children:"Save this account, then choose Connect Claude. You will approve in your browser and paste the authorization code here, not in chat. No existing agent assignment changes."}),h==="api-key"&&t.jsx(le,{label:e?"Replacement API key (leave blank to keep)":"API key",children:t.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,value:w,onChange:b=>v(b.target.value)})}),e&&t.jsx("p",{className:"muted",children:"Saving changes stops an active run at its next model call. Start a new turn afterward. Changing the default model does not change existing agent assignments."}),t.jsxs(te,{align:"end",children:[t.jsx($,{onClick:r,children:"Cancel"}),t.jsx($,{type:"submit",variant:"accent",disabled:N,children:"Save account"})]})]}),N&&t.jsx("p",{className:"muted",children:"Enter an account name and default model to enable Save account. The example name is a placeholder."})]})}function fD({account:e,busy:n,run:s}){var o;const r=((o=e.login)==null?void 0:o.state)==="pending"&&e.login.attemptId?e.login:null,a=d.useRef(s);a.current=s,d.useEffect(()=>{if(!(r!=null&&r.attemptId))return;let c=!1,u=!1;const h=setInterval(()=>{c||u||(u=!0,T.ollamaPoll(e.id,r.attemptId).then(m=>{c||m.state==="waiting"||(c=!0,m.state==="connected"?a.current(async()=>{},`Connected as ${m.username}, device ${m.deviceName}.`):a.current(async()=>{throw new Error(m.message)},""))}).catch(()=>{}).finally(()=>{u=!1}))},2e3);return()=>{c=!0,clearInterval(h)}},[e.id,r==null?void 0:r.attemptId]);const i=()=>{const c=typeof window.open=="function"?window.open("","_blank"):null;s(async()=>{try{const u=await T.ollamaConnect(e.id,e.revision);return c&&(c.location.href=u.verificationUrl),u}catch(u){throw c==null||c.close(),u}},"Press Connect on the ollama.com page. This card notices on its own.")},l=e.device;return t.jsxs(t.Fragment,{children:[l&&t.jsx("p",{className:"muted",role:"status",children:l.connectedAt?`Connected as ${l.username||"an ollama.com account"}, device ${l.deviceName}.`:`Not connected yet. Device ${l.deviceName}.`}),t.jsxs(te,{children:[t.jsx($,{disabled:n||!e.enabled||e.removalPending||!!r,onClick:i,children:e.configured?"Reconnect Ollama":"Connect Ollama"}),t.jsx($,{disabled:n||!l||e.removalPending,onClick:()=>void s(async()=>({warning:(await T.ollamaDisconnect(e.id,e.revision)).note}),"Disconnected."),children:"Disconnect"})]}),r&&t.jsxs(Q,{tone:"accent",role:"status",children:[t.jsxs("p",{children:[t.jsx("a",{href:r.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open the ollama.com page"})," and press Connect. Sign in there first if it asks."]}),t.jsxs("p",{className:"muted",children:["buddi stops waiting at ",r.expiresAt&&Lt(new Date(r.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone),"."]})]})]})}function mD({account:e,enabled:n,busy:s,run:r}){var l,o,c,u,h;const[a,i]=d.useState("");return d.useEffect(()=>{i("")},[(l=e.login)==null?void 0:l.attemptId,(o=e.login)==null?void 0:o.state]),t.jsxs(t.Fragment,{children:[!n&&t.jsx(Q,{tone:"warning",children:"Claude subscription sign-in is turned off on this host."}),t.jsxs(te,{children:[t.jsx($,{disabled:s||!n||!e.enabled||e.removalPending||((c=e.login)==null?void 0:c.state)==="pending",onClick:()=>void r(()=>T.anthropicAccountAction(e.id,"login",e.revision),"Open the Claude consent link below. Existing credentials remain until sign-in succeeds."),children:e.configured?"Reconnect Claude":"Connect Claude"}),((u=e.login)==null?void 0:u.state)==="pending"&&t.jsx($,{disabled:s,onClick:()=>{i(""),r(()=>T.anthropicAccountAction(e.id,"cancel-login",e.revision),"Claude sign-in cancelled.")},children:"Cancel sign-in"}),t.jsx($,{disabled:s||!e.configured||e.removalPending,onClick:()=>{i(""),r(()=>T.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"&&t.jsxs("form",{className:"ui-notice","data-tone":"accent",onSubmit:m=>{m.preventDefault();const f=a;i(""),r(()=>T.anthropicAccountAction(e.id,"complete-login",e.revision,{attemptId:e.login.attemptId,code:f}),"Claude connected. Edit account to load its model list, then assign it to an agent.")},children:[t.jsx("p",{children:t.jsx("a",{href:e.login.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open Claude consent page"})}),t.jsxs("p",{className:"muted",children:["Use the Claude account you want to connect. Paste the entire code including #state. This attempt expires at ",e.login.expiresAt&&Lt(new Date(e.login.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone),"; restarting Buddi also ends it."]}),t.jsx(le,{label:"Claude authorization code",children:t.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,maxLength:8192,value:a,onChange:m=>i(m.target.value),disabled:s})}),t.jsx(te,{align:"end",children:t.jsx($,{type:"submit",variant:"accent",disabled:s||!a.trim(),children:"Complete Claude sign-in"})})]})]})}const yx={anthropic:"claude-sonnet-5",openai:"gpt-5",codex:vy};function wx(e,n,s){return yy(e==="codex"?"ChatGPT subscription":e==="anthropic"?n==="anthropic-oauth"?"Claude subscription":"Anthropic API":e==="openai"?"OpenAI API":n==="device-key"?"Ollama Cloud":"Local endpoint",s)}function yy(e,n){const s=new Set(n.map(r=>r.trim().toLowerCase()));if(!s.has(e.toLowerCase()))return e;for(let r=2;r<100;r+=1)if(!s.has(`${e} ${r}`.toLowerCase()))return`${e} ${r}`;return e}const lae="That key was refused. Check it and paste it again.";function oae({accounts:e,busy:n,run:s,onDone:r,codexEnabled:a,anthropicOAuthEnabled:i,gemini:l}){const o=e.map(J=>J.label),[c,u]=d.useState(null),[h,m]=d.useState("anthropic"),[f,p]=d.useState("api-key"),[x,g]=d.useState(()=>wx("anthropic","api-key",o)),[w,v]=d.useState(!1),[j,y]=d.useState(""),[k,N]=d.useState(""),[b,S]=d.useState(null),[C,A]=d.useState(!1),[E,R]=d.useState(""),[P,O]=d.useState(""),[I,F]=d.useState(!1),[U,L]=d.useState(!1),[M,z]=d.useState(!1),[D,K]=d.useState(void 0),B=(J,Ne,Ie=!1)=>{m(J),p(Ne),N(""),S(null),R(""),O(""),F(!1),L(Ie),z(!1),K(void 0),y(Ie?"":J==="openai-compatible"?"http://localhost:11434/v1":""),w||g(Ie?wx(J,"device-key",o):wx(J,Ne,o))},se=J=>{B("openai-compatible",J?"api-key":"device-key",!0),J&&T.ollama().then(Ne=>y(Ne.cloudBaseUrl)).catch(()=>{})},W=()=>{l&&(B("openai-compatible","api-key"),z(!0),y(l.baseUrl),w||g(yy("Gemini",o)))},xe=()=>{B("openai-compatible","none"),K(null),w||g(yy("mlxh",o)),T.mlxh().then(J=>{K(J),y(J.baseUrl)}).catch(()=>K(void 0))},me=D!==void 0,ie=c?e.find(J=>J.id===c):void 0;if(c)return ie?t.jsx(cae,{account:ie,busy:n,run:s,anthropicOAuthEnabled:i,onDone:()=>r(ie.id)}):t.jsx(Ee,{children:"Saving…"});const H=h==="openai-compatible"&&f!=="device-key",de=h==="codex"||f==="anthropic-oauth"||f==="device-key",ge=!de&&(f==="none"||k.trim()!=="")&&(!H||j.trim()!==""),Ue=async()=>{var J,Ne;A(!0),R("");try{const Ie=await T.probeModels({kind:h,auth:f,...H?{baseUrl:j}:{},...k.trim()?{secret:k}:{}});S(Ie),P||O(((J=Ie.models.find(Y=>Y.isDefault))==null?void 0:J.id)??((Ne=Ie.models[0])==null?void 0:Ne.id)??"")}catch(Ie){R(Ie instanceof Error?Ie.message:"Could not load models. You can still enter a custom model.")}finally{A(!1)}},G=P.trim(),ae=!x.trim()||H&&!j.trim()||H&&!M&&!me&&!G||M&&!k.trim()||me&&!(D!=null&&D.running);return t.jsxs("form",{className:"ui-stack",onSubmit:J=>{var X;J.preventDefault();const Ne=k;N("");let Ie=G||(me?hy(D)??((X=D==null?void 0:D.models[0])==null?void 0:X.id):void 0)||(f==="device-key"?Vh:yx[h])||"claude-sonnet-5",Y;(async()=>{if(M){Ie=sD;try{const we=(await T.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:j,secret:Ne})).models.map(He=>He.id);Ie=rD(we)??Ie,Y=iD(Ie)?aD(we):void 0}catch{}}let oe,ve=!1;!await s(async()=>{if(oe=await T.saveProviderAccount({label:x,kind:h,auth:f,baseUrl:j,defaultModel:Ie,enabled:!0,...Ne.trim()?{secret:Ne}:{}}),f!=="api-key")return oe;const Ce=await T.testProviderAccount(oe.id);if(Ce.state==="connected")return{...oe,warning:`Account saved. ${Ce.message}`};if(Gw(Ce)){const we=oe.id;oe=void 0;try{const He=(await T.providerAccounts()).accounts.find(Ze=>Ze.id===we);He&&await T.removeProviderAccount(we,He.revision)}catch{}throw new Error(lae)}if(M&&Y&&lD(Ce)){const we=(await T.providerAccounts()).accounts.find(He=>He.id===oe.id);if(we&&(await T.saveProviderAccount({...Dk(we),defaultModel:Y}),(await T.testProviderAccount(oe.id)).state==="connected"))return{...oe,warning:`Account saved on ${Y}. Your Google AI plan covers the Gemini app, not this key. The key’s Google Cloud project has no billing, so Pro models aren’t included; enable billing on that project at aistudio.google.com to use Pro.`}}return ve=!0,{...oe,warning:`Account saved. ${Ce.message}`}},"Account saved.")||!oe||(M||me||ve?u(oe.id):G||!de?r(oe.id):u(oe.id))})()},children:[t.jsxs("fieldset",{disabled:n,className:"ui-fields","data-stack":"true",children:[t.jsx(le,{label:"Provider",children:t.jsxs("select",{value:f==="anthropic-oauth"?"anthropic-oauth":U?"ollama-cloud":M?"gemini":me?"mlxh":h,onChange:J=>{if(J.target.value==="anthropic-oauth")B("anthropic","anthropic-oauth");else if(J.target.value==="gemini")W();else if(J.target.value==="mlxh")xe();else if(J.target.value==="ollama-cloud")B("openai-compatible","device-key",!0);else{const Ne=J.target.value;B(Ne,Ne==="codex"?"chatgpt":"api-key")}},children:[t.jsx("option",{value:"anthropic",children:"Anthropic API"}),t.jsx("option",{value:"openai",children:"OpenAI API"}),l&&t.jsx("option",{value:"gemini",children:"Gemini (Google AI key)"}),t.jsx("option",{value:"ollama-cloud",children:"Ollama Cloud"}),t.jsx("option",{value:"mlxh",children:"mlxh, local MLX models on this Mac"}),t.jsx("option",{value:"openai-compatible",children:"OpenAI-compatible endpoint (Ollama, OpenRouter, vLLM…)"}),i&&t.jsx("option",{value:"anthropic-oauth",children:"Claude subscription"}),a&&t.jsx("option",{value:"codex",children:"ChatGPT subscription"})]})}),t.jsx(le,{label:"Account name",hint:"Proposed from the provider. Change it to anything you will recognise.",children:t.jsx("input",{autoFocus:!0,required:!0,maxLength:100,value:x,onChange:J=>{g(J.target.value),v(!0)},placeholder:"Anthropic — Personal"})}),U&&t.jsxs("label",{className:"ui-row",children:[t.jsx("input",{type:"checkbox",checked:f==="api-key",onChange:J=>se(J.target.checked)}),t.jsx("span",{children:"Use a key instead"})]}),H&&t.jsxs(t.Fragment,{children:[t.jsx(le,{label:"API base URL",hint:"Include the API path, such as /v1 or /api/v1. Conversation data will be sent to this endpoint. The model must support tool calling to use agent tools.",children:t.jsx("input",{required:!0,type:"url",value:j,onChange:J=>{y(J.target.value),S(null)}})}),!M&&!me&&t.jsx(le,{label:"Authentication",children:t.jsxs("select",{value:f,onChange:J=>{p(J.target.value),N(""),S(null)},children:[t.jsx("option",{value:"api-key",children:"API key"}),t.jsx("option",{value:"none",children:"No key (local/self-hosted)"})]})})]}),f==="api-key"&&t.jsx(le,{label:"API key",hint:"Stored in the vault, never shown again.",children:t.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,value:k,onChange:J=>{N(J.target.value),S(null)}})}),me?D===null?t.jsx("p",{className:"muted",children:"Looking for mlxh on this computer…"}):D!=null&&D.running?t.jsxs(ue,{gap:"sm",children:[t.jsxs("p",{className:"muted",children:["mlxh answers with ",D.models.length===1?"one model":`${D.models.length} models`,". No key: mlxh takes any. buddi starts on ",hy(D)??"the first","; the next step lists the rest. A model that is not loaded takes up to a minute on its first answer."]}),D.models.some(J=>J.kind==="image")?t.jsxs("p",{className:"muted",children:[D.models.filter(J=>J.kind==="image").map(J=>J.id).join(", "),": ",AO,"."]}):null]}):t.jsx(Q,{tone:"warning",children:EO((D==null?void 0:D.baseUrl)??j)}):M&&l?t.jsxs("p",{className:"muted",children:[t.jsx("a",{href:l.keyUrl,target:"_blank",rel:"noreferrer",children:"Get a key at aistudio.google.com"}),". buddi picks the newest Gemini Pro your key can reach; the next step lists the rest."]}):de?t.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.":f==="device-key"?"You will connect on the next step: ollama.com opens, you press Connect, and no key is typed. Free to start.":"You will connect your Claude subscription on the next step, in your browser, and pick a model then."}):t.jsxs("div",{className:"ui-field",children:[t.jsx("span",{className:"ui-field-label",children:"Model"}),b?t.jsxs("div",{className:"ui-row",children:[t.jsxs("select",{"aria-label":"Model",value:I?"__custom__":P,onChange:J=>{J.target.value==="__custom__"?(F(!0),O("")):(F(!1),O(J.target.value))},children:[b.models.map(J=>t.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)),t.jsx("option",{value:"__custom__",children:"Custom model…"})]}),t.jsx($,{size:"sm",disabled:C||!ge,onClick:()=>void Ue(),children:C?"Loading…":"Reload"})]}):t.jsxs("div",{className:"ui-row",children:[t.jsx($,{disabled:C||!ge,onClick:()=>void Ue(),children:C?"Loading models…":"Load models"}),H?t.jsx("span",{className:"muted",children:"Ask the endpoint what it serves."}):t.jsxs("span",{className:"muted",children:["Optional now: ",yx[h]," is used until you pick one."]})]}),I||H&&!b?t.jsx("input",{"aria-label":"Custom model",required:H,maxLength:150,value:P,onChange:J=>O(J.target.value),placeholder:H?"qwen3:8b":yx[h]}):null,E?t.jsx("span",{className:"ui-field-hint critical",role:"alert",children:E}):null,b!=null&&b.truncated?t.jsx("span",{className:"ui-field-hint",children:"Showing the first part of the provider’s list."}):null]}),t.jsxs(te,{align:"end",children:[t.jsx($,{onClick:()=>r(),children:"Cancel"}),t.jsx($,{type:"submit",variant:"accent",disabled:ae,children:"Save account"})]})]}),ae&&!me&&t.jsxs("p",{className:"muted",children:["Enter an account name",M?" and a key":H?", an endpoint and a model":""," to enable Save account."]})]})}function cae({account:e,busy:n,run:s,anthropicOAuthEnabled:r,onDone:a}){const[i,l]=d.useState(e.defaultModel),o=e.configured;return t.jsxs(ue,{gap:"lg",children:[t.jsxs(Q,{tone:"good",children:["Saved “",e.label,"”."]}),e.auth==="anthropic-oauth"&&!o?t.jsx(mD,{account:e,enabled:!!r,busy:n,run:s}):null,e.kind==="codex"&&!o?t.jsx(hD,{account:e,busy:n,run:s}):null,e.auth==="device-key"&&!o?t.jsx(fD,{account:e,busy:n,run:s}):null,o?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"ui-page-lede",children:"Pick the model this account offers by default. An agent can still choose another when you assign it."}),t.jsx(te,{valign:"end",children:t.jsx($k,{accountId:e.enabled?e.id:void 0,label:"Default model",value:i,onChange:l,disabled:n,...e.kind==="codex"?{origin:"from ChatGPT",suggest:nD,onSuggest:c=>l(u=>u===vy&&e.defaultModel===vy?c:u)}:{}},`${e.id}:${e.revision}`)}),t.jsxs(te,{align:"end",children:[t.jsx($,{onClick:a,children:"Skip for now"}),t.jsx($,{variant:"accent",disabled:n||!i.trim(),onClick:()=>{if(i===e.defaultModel){a();return}s(()=>T.saveProviderAccount({...Dk(e),defaultModel:i}),"Default model saved.").then(c=>{c&&a()})},children:"Done"})]})]}):t.jsx(te,{children:t.jsx($,{onClick:a,children:"Finish later"})})]})}async function jl(e,n,s,r){s(!0),r(null);try{return(await T.secretsAct(e,n)).result}catch(a){return r(a instanceof Error?a.message:String(a)),null}finally{s(!1)}}const pD="Passwords, keys and links your agents use without ever seeing them. Each goes only where you allow.";function uae(e,n){if(n==="mail")return"mail";if(n==="models")return"chip";if(n==="connections")return"plug";if(n==="plugin:calendar")return"calendar";const s=e.bindings.map(r=>r.kind);return s.some(r=>r.startsWith("browser."))?"globe":s.includes("developer.env")?"terminal":"key"}function dae({embedded:e,timezone:n,secret:s,adding:r,navigate:a}={}){const i=je(()=>T.secrets(),[]),l=je(()=>T.providerAccounts(),[]),o=d.useMemo(()=>{var x;return new Map((((x=l.data)==null?void 0:x.accounts)??[]).map(g=>[g.id,{label:g.label,provider:cD(g)}]))},[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)&&a&&a(ze("secrets"))},m=i.data,f=d.useMemo(()=>{const x=new Map;for(const g of(m==null?void 0:m.secrets)??[]){const w=Ua(g);x.set(w,[...x.get(w)??[],g])}return[...x.entries()].sort(([g],[w])=>YY(g,w))},[m]),p=c&&c.what!=="add"?(m==null?void 0:m.secrets.find(x=>x.name===c.name))??null:null;return t.jsxs(Is,{embedded:e,title:"Keys and secrets",lede:pD,actions:e?void 0:t.jsx($,{variant:"accent",size:"sm",onClick:()=>u({what:"add"}),children:"Add a secret"}),children:[t.jsxs(ue,{gap:"lg",children:[!m&&!i.error?t.jsx(Ee,{children:"Opening the vault…"}):null,i.error?t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{message:i.error}),t.jsx(te,{children:t.jsx($,{onClick:i.reload,children:"Retry"})})]}):null,m&&m.secrets.length===0?t.jsx(lt,{children:t.jsx(ps,{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,m&&m.secrets.length>0?t.jsx(lt,{flush:!0,children:f.map(([x,g])=>{const w=qY(x);return t.jsxs("section",{className:"secrets-group","aria-label":w.title,children:[t.jsxs("header",{className:"secrets-group-head",children:[t.jsx("h3",{className:"secrets-group-title",children:w.title}),t.jsx("span",{className:"secrets-group-aside",children:w.aside})]}),t.jsx(yt,{children:g.map(v=>t.jsx(fae,{secret:v,group:x,accounts:o,timezone:n,onOpen:j=>u({what:j,name:v.name})},v.name))})]},x)})}):null,m&&m.ownKeys.length>0?t.jsx(Vt,{summary:`buddi’s own keys · ${m.ownKeys.length}`,children:t.jsxs("p",{className:"secrets-note",children:["The keys buddi itself runs on, read from its environment:"," ",m.ownKeys.map((x,g)=>t.jsxs("span",{children:[g>0?", ":"",t.jsx("code",{className:"mono",children:x})]},x)),". 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"&&m?t.jsx(xae,{destinations:m.destinations,onClose:h,onChanged:i.reload}):null,p&&(c==null?void 0:c.what)==="sheet"?t.jsx(pae,{secret:p,accounts:o,timezone:n,onClose:h,onOpen:x=>u({what:x,name:p.name})}):null,p&&(c==null?void 0:c.what)==="replace"?t.jsx(jae,{secret:p,title:ru(p,o),onClose:h,onChanged:i.reload}):null,p&&(c==null?void 0:c.what)==="rename"?t.jsx(vae,{secret:p,onClose:h,onChanged:i.reload}):null,p&&(c==null?void 0:c.what)==="places"&&m?t.jsx(yae,{secret:p,title:ru(p,o),destinations:m.destinations,onClose:h,onChanged:i.reload}):null,p&&(c==null?void 0:c.what)==="delete"?t.jsx(wae,{secret:p,title:ru(p,o),onClose:h,onChanged:i.reload}):null]})}const ed=e=>n=>{n.stopPropagation(),e==null||e()};function gD({fix:e,onOpen:n}){return"href"in e?t.jsx(it,{size:"sm",href:e.href,onClick:ed(),children:e.label}):t.jsx($,{size:"sm",onClick:ed(()=>n(e.action)),children:e.label})}function hae(e,n,s){if(n==="mine")return[{label:"Replace value…",onSelect:()=>s("replace")},{label:"Rename…",onSelect:()=>s("rename")},{label:"Change where it may go…",hint:"Places, and when it asks",onSelect:()=>s("places")},{label:"Usage history",onSelect:()=>s("sheet")},"separator",{label:"Delete…",tone:"critical",onSelect:()=>s("delete")}];if(n==="mail"){const r=(e.usedBy??[]).find(a=>a.kind==="mailbox");return[r&&!e.unused?{label:"Set a new password",hint:"On the Email page, which tests it first",onSelect:()=>{window.location.hash=Bv(r.id)}}:null,{label:"Usage history",onSelect:()=>s("sheet")},oo(e)?"separator":null,oo(e)?{label:"Remove…",tone:"critical",onSelect:()=>s("delete")}:null]}return[{label:n==="plugin:calendar"?"Replace link…":"Replace value…",onSelect:()=>s("replace")},{label:"Usage history",onSelect:()=>s("sheet")},oo(e)?"separator":null,oo(e)?{label:"Remove…",tone:"critical",onSelect:()=>s("delete")}:null]}function fae({secret:e,group:n,accounts:s,timezone:r,onOpen:a}){const i=ru(e,s),l=XY(e,s),o=JY(e,r),c=[o??gk(e),o&&!e.lastUse?null:sQ(e)].filter(Boolean).join(" · "),u=m2(e),h=p2(e),m=Wv(e),f=c2(n)?h2(e):null;return t.jsx(pt,{onClick:()=>a("sheet"),label:`${i}: details`,lead:t.jsx(ss,{icon:uae(e,n)}),title:t.jsxs(t.Fragment,{children:[i,l?t.jsx("span",{className:"secrets-tag",children:l}):null]}),sub:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"secrets-line",children:c}),u?t.jsx("span",{className:"secrets-status","data-tone":"warning",children:u.text}):null,h?t.jsx("span",{className:"secrets-status",children:h}):null,m?t.jsx("span",{className:"secrets-status",children:m}):null,e.savedFrom?t.jsx(mae,{from:e.savedFrom,timezone:r}):null]}),side:t.jsxs("span",{className:"secrets-side",children:[u!=null&&u.fix?t.jsx(gD,{fix:u.fix,onOpen:a}):null,h&&oo(e)||e.login&&n==="mine"?t.jsx($,{size:"sm",variant:"ghost",onClick:ed(()=>a("delete")),children:"Remove…"}):null,f?t.jsxs("a",{className:"secrets-managed",href:f.href,onClick:ed(),children:[f.label,t.jsx(ne,{name:"chevron-right",size:12})]}):t.jsx(rs,{label:`More for ${i}`,items:hae(e,n,a),sheet:{title:i,sub:c}})]})})}function mae({from:e,timezone:n}){const s=n??Intl.DateTimeFormat().resolvedOptions().timeZone,r=new Date(e.at),a=Ks(r,s,{compact:!0}),i=Ks(new Date,s,{compact:!0}),l=Number.isNaN(r.getTime())?"":`${a===i?"today":a} at ${Lt(r,s)}`,o=[e.title,e.agentId?e.agentId.charAt(0).toUpperCase()+e.agentId.slice(1):null].filter(Boolean).join(" · ");return t.jsxs("span",{className:"ss-from",children:["Saved ",l,", ",e.agentId?t.jsx("a",{href:ut(e.agentId,e.conversationId),title:o||void 0,onClick:ed(),children:"from a conversation"}):"from a conversation"]})}function pae({secret:e,accounts:n,timezone:s,onClose:r,onOpen:a}){const i=Ua(e),l=ru(e,n),o=m2(e),c=p2(e),u=[...new Set(e.bindings.map(f=>f.rule))],h=e.lastUse,m=(e.usedBy??[]).map(f=>({label:f.kind==="mailbox"?"Mailbox":f.kind==="model-account"?"Model account":"Connection",value:t.jsx("code",{className:"mono secrets-mono",children:f.id})}));return t.jsx(Ye,{title:l,onClose:r,foot:i==="mine"?t.jsxs(te,{children:[t.jsx($,{variant:"danger-ghost",onClick:()=>a("delete"),children:"Delete…"}),t.jsx(ht,{}),t.jsx($,{onClick:()=>a("rename"),children:"Rename…"}),t.jsx($,{variant:"accent",onClick:()=>a("replace"),children:"Replace value…"})]}):void 0,children:t.jsxs(ue,{gap:"lg",children:[t.jsx(on,{items:[{label:"Where it may go",value:gk(e)||"Nowhere yet"},...u.length===1&&i==="mine"?[{label:"Asks you",value:aQ[u[0]]}]:[],{label:"Last used",value:h?`${Xe(h.at)}${h.agentId?` by ${h.agentId}`:""}`:"Never"}]}),o?t.jsx(Q,{tone:"warning",action:o.fix?t.jsx(gD,{fix:o.fix,onOpen:a}):void 0,children:o.text}):null,c?oo(e)?t.jsxs(Q,{action:t.jsx($,{size:"sm",onClick:()=>a("delete"),children:"Remove…"}),children:[c," Nothing removes it but you."]}):t.jsx(Q,{children:c}):null,Wv(e)?t.jsx(Q,{children:Wv(e)}):null,t.jsxs(ue,{gap:"sm",children:[t.jsx("h3",{className:"secrets-sheet-head",children:"Usage history"}),t.jsx(gae,{name:e.name,timezone:s})]}),t.jsx(Vt,{summary:"Details",children:t.jsxs(ue,{gap:"sm",children:[t.jsx(on,{items:[{label:"Stored as",value:t.jsx("code",{className:"mono secrets-mono",children:e.name})},...e.bindings.map((f,p)=>({key:`b${p}`,label:p===0?"Bindings":"",value:t.jsxs("code",{className:"mono secrets-mono",children:[f.kind," ",a2(f.kind,f.target)," · ",f.rule]})})),...e.totp?[{label:"One-time code",value:"buddi fills the current code, never the seed"}]:[],...m]}),t.jsx("p",{className:"secrets-note",children:"What buddi keeps for it, never the value. “Held back” means buddi declined to hand the value over — not bound to that place, no value stored, or the vault locked — so it never left."})]})})]})})}function gae({name:e,timezone:n}){const s=je(()=>T.secretUses(e,50),[e]);if(s.error)return t.jsx(re,{message:s.error});if(!s.data)return t.jsx(Ee,{children:"Reading the history…"});const r=s.data.uses;return r.length===0?t.jsx("p",{className:"secrets-note",children:"Nothing has used it yet."}):t.jsx(yt,{children:r.map((a,i)=>{const l=cQ(a);return t.jsx(pt,{title:t.jsx("span",{className:"secrets-history","data-tone":l.tone,children:l.text}),sub:`${St(a.at,n??"UTC")} · ${a.agent??(a.plugin?`the ${a.plugin} plugin`:"you")}`},i)})})}function xD({title:e,result:n,scrubbed:s,busy:r,failure:a,onScrub:i}){const l=HY(n);return t.jsxs(ue,{gap:"sm",children:[t.jsxs(Q,{tone:"good",role:"status",children:["Saved “",e,"”. Its value is never shown again."]}),t.jsx("p",{className:"secrets-note",children:l||"Nothing of the value sits where buddi already holds text."}),t.jsx(re,{message:a}),l?t.jsx(te,{children:t.jsx($,{variant:"accent",disabled:r||s!==null,onClick:i,children:s===null?"Scrub the history":KY(s)||"Nothing of it was left to replace."})}):null]})}function jD({destinations:e,bindings:n,disabled:s,onChange:r}){const a=(i,l)=>{r(n.map((o,c)=>c===i?{...o,...l}:o))};return t.jsxs(ue,{gap:"sm",children:[n.map((i,l)=>{const o=e.find(h=>h.kind===i.kind),c=(o==null?void 0:o.maxRule)??i.rule,u=o?e:[...e,{kind:i.kind,plugin:"",maxRule:i.rule}];return t.jsxs("div",{className:"secrets-place",children:[t.jsx(le,{label:"Kind of place",children:t.jsx("select",{value:i.kind,disabled:s,onChange:h=>{var p;const m=h.target.value,f=(p=e.find(x=>x.kind===m))==null?void 0:p.maxRule;a(l,{kind:m,rule:f?im(f):i.rule})},children:u.map(h=>t.jsx("option",{value:h.kind,children:iQ(h.kind)},h.kind))})}),t.jsx(le,{label:"The place",children:t.jsx("input",{type:"text",spellCheck:!1,disabled:s,value:i.target,placeholder:oQ(i.kind),onChange:h=>a(l,{target:h.target.value})})}),t.jsx(le,{label:"Asks you",children:t.jsx("select",{value:i.rule,disabled:s,onChange:h=>a(l,{rule:h.target.value}),children:s2(c).map(h=>t.jsx("option",{value:h,children:lQ[h]},h))})}),t.jsx($,{size:"sm",variant:"ghost",disabled:s,onClick:()=>r(n.filter((h,m)=>m!==l)),children:"Remove"}),t.jsxs("p",{className:"ui-field-hint secrets-place-hint",children:["The place: ",FY(i.kind),"."]})]},l)}),n.length===0?t.jsx("p",{className:"ui-field-hint",children:LY}):null,e.length?t.jsx(te,{children:t.jsx($,{size:"sm",disabled:s,onClick:()=>r([...n,{kind:e[0].kind,target:"",rule:im(e[0].maxRule)}]),children:"Add a place"})}):t.jsx("p",{className:"ui-field-hint",children:"Nothing installed here takes a secret yet, so there is nowhere to send one."})]})}function vD(e){const n=e.map(r=>BY(r.kind,r.target)),s=n.findIndex(r=>!r.ok);return s!==-1?{ok:!1,error:`Place ${s+1}: ${n[s].error}`}:{ok:!0,bindings:e.map((r,a)=>({kind:r.kind,target:n[a].target,rule:r.rule}))}}function xae({destinations:e,onClose:n,onChanged:s}){const[r,a]=d.useState(""),[i,l]=d.useState(""),[o,c]=d.useState(!1),[u,h]=d.useState(()=>e.length?[{kind:e[0].kind,target:"",rule:im(e[0].maxRule)}]:[]),[m,f]=d.useState(!1),[p,x]=d.useState(null),[g,w]=d.useState(null),[v,j]=d.useState(null),y=async()=>{const N=vD(u);if(!N.ok){x(N.error);return}const b=i;l("");const S=await jl("secrets.put",{name:r.trim(),value:b,totp:o,bindings:N.bindings},f,x);S!==null&&(w({name:r.trim(),result:S}),s())},k=async()=>{const N=await jl("secrets.scrub_history",{name:(g==null?void 0:g.name)??""},f,x);N!==null&&(j(N),s())};return g?t.jsx(Ye,{title:"Add a secret",onClose:n,foot:t.jsx(te,{align:"end",children:t.jsx($,{onClick:n,children:"Done"})}),children:t.jsx(xD,{title:g.name,result:g.result,scrubbed:v,busy:m,failure:p,onScrub:()=>void k()})}):t.jsx(Ye,{title:"Add a secret",size:"wide",onClose:n,foot:t.jsxs(te,{align:"end",children:[t.jsx($,{onClick:n,children:"Cancel"}),t.jsx($,{type:"submit",form:"secrets-add",variant:"accent",disabled:m,children:"Save secret"})]}),children:t.jsxs("form",{id:"secrets-add",className:"ui-stack","data-gap":"lg",onSubmit:N=>{N.preventDefault(),y()},children:[t.jsxs("fieldset",{disabled:m,className:"ui-stack","data-gap":"sm",children:[t.jsx(le,{label:"Name",hint:"What agents ask for it by. Saving a name that exists replaces that secret’s value.",children:t.jsx("input",{required:!0,autoFocus:!0,maxLength:200,value:r,onChange:N=>a(N.target.value),placeholder:"PNC password"})}),t.jsx(le,{label:"Value",hint:"Kept in the vault and never shown again, not even here.",children:t.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,required:!0,value:i,onChange:N=>l(N.target.value)})}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:o,onChange:N=>c(N.target.checked)}),t.jsx("span",{children:"It’s a one-time-code seed — buddi fills the current code, never the seed"})]})]}),t.jsxs("fieldset",{disabled:m,className:"ui-stack","data-gap":"sm",children:[t.jsx("h3",{className:"secrets-sheet-head",children:"Where it may go"}),t.jsx("p",{className:"secrets-note",children:"Agents can use it only in these places. Anywhere else, buddi holds it back and the row says so."}),t.jsx(jD,{destinations:e,bindings:u,disabled:m,onChange:h})]}),p?t.jsx(Q,{tone:"critical",role:"alert",children:p}):null]})})}function jae({secret:e,title:n,onClose:s,onChanged:r}){const[a,i]=d.useState(""),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,m]=d.useState(null),[f,p]=d.useState(null),x=async()=>{const w=a;i("");const v=await jl("secrets.put",{name:e.name,value:w,totp:e.totp,bindings:e.bindings.map(({kind:j,target:y,rule:k})=>({kind:j,target:y,rule:k}))},o,u);v!==null&&(m(v),r())},g=async()=>{const w=await jl("secrets.scrub_history",{name:e.name},o,u);w!==null&&(p(w),r())};return h?t.jsx(Gt,{title:`Replaced the value of “${n}”`,onClose:s,foot:t.jsx($,{variant:"accent",onClick:s,children:"Done"}),children:t.jsx(xD,{title:n,result:h,scrubbed:f,busy:l,failure:c,onScrub:()=>void g()})}):t.jsx(Gt,{title:`Replace the value of “${n}”`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx($,{type:"submit",form:"secrets-replace",variant:"accent",disabled:l||a==="",children:"Save value"})]}),children:t.jsxs("form",{id:"secrets-replace",className:"ui-stack","data-gap":"sm",onSubmit:w=>{w.preventDefault(),a!==""&&x()},children:[t.jsx(le,{label:"New value",hint:"Kept in the vault and never shown again. Where it may go stays the same.",children:t.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,required:!0,autoFocus:!0,disabled:l,value:a,onChange:w=>i(w.target.value)})}),t.jsx(re,{message:c})]})})}function vae({secret:e,onClose:n,onChanged:s}){const[r,a]=d.useState(e.name),[i,l]=d.useState(!1),[o,c]=d.useState(null),u=r.trim()!==""&&r.trim()!==e.name,h=async()=>{await jl("secrets.rename",{name:e.name,to:r.trim()},l,c)!==null&&(s(),n())};return t.jsx(Gt,{title:`Rename “${e.name}”`,onClose:n,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx($,{type:"submit",form:"secrets-rename",variant:"accent",disabled:i||!u,children:"Rename"})]}),children:t.jsxs("form",{id:"secrets-rename",className:"ui-stack","data-gap":"sm",onSubmit:m=>{m.preventDefault(),u&&h()},children:[t.jsx(le,{label:"Name",hint:"What agents ask for it by. One that uses the old name needs the new one.",children:t.jsx("input",{required:!0,autoFocus:!0,maxLength:200,disabled:i,value:r,onChange:m=>a(m.target.value)})}),t.jsx(re,{message:o})]})})}function yae({secret:e,title:n,destinations:s,onClose:r,onChanged:a}){const[i,l]=d.useState(()=>e.bindings.length?e.bindings.map(f=>({kind:f.kind,target:WY(f.target),rule:f.rule})):s.length?[{kind:s[0].kind,target:"",rule:im(s[0].maxRule)}]:[]),[o,c]=d.useState(!1),[u,h]=d.useState(null),m=async()=>{const f=vD(i);if(!f.ok){h(f.error);return}await jl("secrets.rebind",{name:e.name,bindings:f.bindings},c,h)!==null&&(a(),r())};return t.jsx(Ye,{title:`Where “${n}” may go`,size:"wide",onClose:r,foot:t.jsxs(te,{align:"end",children:[t.jsx($,{onClick:r,children:"Cancel"}),t.jsx($,{type:"submit",form:"secrets-places",variant:"accent",disabled:o,children:"Save"})]}),children:t.jsxs("form",{id:"secrets-places",className:"ui-stack","data-gap":"sm",onSubmit:f=>{f.preventDefault(),m()},children:[t.jsx("p",{className:"secrets-note",children:"Agents can use it only in these places. Anywhere else, buddi holds it back and the row says so."}),t.jsx(jD,{destinations:s,bindings:i,disabled:o,onChange:l}),u?t.jsx(Q,{tone:"critical",role:"alert",children:u}):null]})})}function wae({secret:e,title:n,onClose:s,onChanged:r}){const[a,i]=d.useState(!1),[l,o]=d.useState(null),c=!!(e.unused||e.login),u=async()=>{await jl("secrets.delete",{name:e.name},i,o)!==null&&(r(),s())};return t.jsxs(Gt,{title:`${c?"Remove":"Delete"} “${n}”?`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx($,{variant:"danger",disabled:a,onClick:()=>void u(),children:c?"Remove":"Delete"})]}),children:[t.jsxs("p",{className:"secrets-dialog-text",children:[rQ(e)," The value is gone for good; its usage history stays, under its name."]}),t.jsx(re,{message:l})]})}function bae({timezone:e,embedded:n}){var p;const{data:s,error:r,reload:a}=je(()=>T.sentinels(),[],3e4),[i,l]=d.useState(null),[o,c]=d.useState(null),u=(s==null?void 0:s.installed)??[],h=((s==null?void 0:s.runs)??[]).filter(x=>x.lastError),m=u.filter(x=>!x.enabled),f=(x,g)=>{l(x),c(null),T.setSentinelEnabled(x,g).catch(w=>c(w instanceof pe?w.message:String(w))).finally(()=>{l(null),a()})};return t.jsxs(Is,{embedded:n,title:"Watchers",children:[t.jsx(re,{message:r??o}),t.jsx(Q,{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?t.jsx(Q,{tone:"warning",children:h.length===1?"One watcher failed on its last run.":`${h.length} watchers failed on their last run.`}):null,m.length>0?t.jsxs(Q,{tone:"warning",children:[m.length===1?"One watcher is off.":`${m.length} watchers are off.`," A watcher that is off does not run, and what it already found stays as it was."]}):null,t.jsx(ye,{title:"Installed",aside:t.jsx("a",{href:`${ln}/alerts`,children:"See what they found"}),panel:!0,flush:!0,children:s?u.length===0?t.jsx(ps,{icon:"eye",title:"No watchers are installed",children:"Plugins bring their own."}):t.jsx(yt,{children:u.map(x=>{const g=s.runs.find(w=>w.sentinelId===x.id);return t.jsx(pt,{lead:t.jsx($e,{tone:x.enabled?g!=null&&g.lastError?"critical":g?"good":void 0:"muted",children:x.enabled?g!=null&&g.lastError?"failed":g?"ok":"never ran":"off"}),title:x.description,sub:`${x.id}, every ${kae(x.every)}${g!=null&&g.lastError?`. ${g.lastError}`:""}`,side:t.jsxs(t.Fragment,{children:[t.jsx("span",{title:g?St(g.lastRunAt,e):void 0,children:g?Xe(g.lastRunAt):"never ran"}),t.jsx($,{size:"sm",disabled:i===x.id,onClick:()=>f(x.id,!x.enabled),children:x.enabled?"Turn off":"Turn on"})]})},x.id)})}):t.jsx(Ee,{children:"Loading…"})}),t.jsx(hte,{mutes:((p=s==null?void 0:s.alerts)==null?void 0:p.mutes)??[],onChanged:a})]})}function kae(e){if(e%86400===0){const s=e/86400;return s===1?"day":`${s} days`}if(e%3600===0){const s=e/3600;return s===1?"hour":`${s} hours`}const n=Math.max(1,Math.round(e/60));return n===1?"minute":`${n} minutes`}const kE=4,Nae={time:"profile",date:"profile",zone:null};function Sae({data:e,phone:n}){const s=d.useRef(null),r=B2(),[a,i]=d.useState(.4),l=n?390:1280,o=n?780:800;d.useEffect(()=>{const u=s.current;if(!u)return;const h=()=>i(u.clientWidth/l||.4);if(h(),typeof ResizeObserver>"u")return;const m=new ResizeObserver(h);return m.observe(u),()=>m.disconnect()},[l]);const c=(e==null?void 0:e.owner)??null;return t.jsx("div",{ref:s,className:"lke-preview","data-phone":n?"true":void 0,style:{aspectRatio:`${l} / ${o}`},role:"img","aria-label":"Preview of the lock screen",children:t.jsxs("div",{className:"lk","data-preview":"true","data-bg":Nk(e==null?void 0:e.background,e==null?void 0:e.image),"data-phone":n?"true":void 0,"data-view":"glance",style:{width:l,height:o,transform:`scale(${a})`},"aria-hidden":"true",children:[t.jsx(X2,{data:e??null,now:r,phone:n}),t.jsx("footer",{className:"lk-unlock",children:n?t.jsxs("span",{className:"lk-chip lk-enter",children:[t.jsx(ne,{name:"lock",size:14}),t.jsx("span",{children:"Enter PIN"})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"lk-who",children:[t.jsx("span",{className:"lk-face",children:(c??"You").slice(0,1).toUpperCase()}),c?t.jsx("span",{className:"lk-owner",children:c}):null]}),t.jsxs("span",{className:"lk-pin",children:[t.jsx(ne,{name:"lock",size:15}),t.jsx("span",{className:"lke-pin-hint",children:"Enter your PIN"})]})]})})]})})}function Cae({info:e,placement:n,index:s,count:r,onSize:a,onSettings:i,onMove:l,onRemove:o}){var u;const c=n.label??e.title;return t.jsxs("li",{className:"lke-row","data-key":n.key,children:[t.jsxs("span",{className:"lke-row-text",children:[t.jsx("span",{className:"lke-row-title",children:c}),t.jsx("span",{className:"lke-row-sub",children:e.builtIn?"Built in":`${e.plugin} plugin`})]}),t.jsxs("span",{className:"lke-row-tools",children:[e.sizes.length>1?t.jsx(cn,{label:`Size of ${c}`,options:["small","medium"].filter(h=>e.sizes.includes(h)).map(h=>({value:h,label:h==="small"?"Small":"Medium"})),value:n.size,onChange:a}):null,t.jsxs("span",{className:"lke-row-acts",children:[(((u=e.settings)==null?void 0:u.length)??0)>0?t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Settings for ${c}`,title:"Settings",onClick:i,children:t.jsx(ne,{name:"settings",size:14})}):null,t.jsxs("span",{className:"lke-move",children:[t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Move ${c} earlier`,title:"Move earlier",disabled:s===0,onClick:()=>l(-1),children:t.jsx(ne,{name:"chevron-left"})}),t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Move ${c} later`,title:"Move later",disabled:s===r-1,onClick:()=>l(1),children:t.jsx(ne,{name:"chevron-right"})})]}),t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Take ${c} off the lock screen`,title:"Take off the lock screen",onClick:o,children:t.jsx(ne,{name:"close",size:12})})]})]})]})}function NE(e){return e?"place"in e?`place:${e.place}`:`town:${e.timezone}:${e.label}`:""}function Eae({clock:e,onClock:n,version:s}){var K,B,se;const r=e??Nae,a=je(()=>T.lockScreen(),[s]),i=je(()=>T.widgets("lock"),[]),l=je(()=>T.owner(),[]),[o,c]=d.useState(void 0),[u,h]=d.useState(!1),[m,f]=d.useState(null),[p,x]=d.useState(null),[g,w]=d.useState(null),[v,j]=d.useState(null);d.useEffect(()=>{i.data&&c(i.data)},[i.data]);const y=((K=a.data)==null?void 0:K.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,k=(o==null?void 0:o.lock)??[],N=new Map(((o==null?void 0:o.available)??[]).map(W=>[W.id,W])),b=k.length>=kE,S=W=>{if(!o)return Promise.resolve(!1);const xe=o;return f(null),c({...o,lock:W,arranged:{...o.arranged,lock:!0}}),T.saveWidgets("lock",W).then(me=>(c(me),a.reload(),!0),me=>(c(xe),f(`Couldn't save the lock screen's widgets: ${me instanceof Error?me.message:String(me)}`),!1))},C=(W,xe)=>{const me=k.slice(),[ie]=me.splice(W,1);me.splice(W+xe,0,ie),S(me)},A=(W,xe)=>{const me=N.get(W);!me||b||S([...k,{key:q2(),widget:W,size:me.sizes.includes("small")?"small":me.sizes[0],settings:xe}])},E=W=>{if(W==="find"){w({query:"",found:[],busy:!1});return}if(w(null),W==="")return n({...r,zone:null});if(W.startsWith("place:"))return n({...r,zone:{place:W.slice(6)}});const xe=r.zone&&!("place"in r.zone)?r.zone:v;xe&&n({...r,zone:xe})},R=()=>{if(!g||g.query.trim().length<2)return;const W=g.query.trim();w({query:g.query,found:[],busy:!0}),T.findPlace(W).then(({found:xe})=>{var de;const me=xe.filter(ge=>ge.timezone);if(me.length===0){w({query:W,found:[],busy:!1,missed:`Nothing with a timezone found for “${W}”.`});return}const ie=me[0],H={label:((de=ie.name.split(",")[0])==null?void 0:de.trim())||ie.name,timezone:ie.timezone};j(H),w(null),n({...r,zone:H})}).catch(()=>w({query:W,found:[],busy:!1,missed:"The place finder didn’t answer. Try again in a moment."}))},P=new Date,O=W=>dd({dateFormat:W},()=>Ks(P,y,{weekday:!0})),I=(((B=l.data)==null?void 0:B.places)??[]).filter(W=>W.timezone&&W.timezone!==y),F=r.zone&&!("place"in r.zone)?r.zone:v,U=((o==null?void 0:o.home)??[]).filter(W=>N.has(W.widget)&&!N.get(W.widget).sensitive),L=((o==null?void 0:o.available)??[]).filter(W=>!W.sensitive),M=((o==null?void 0:o.available)??[]).filter(W=>W.sensitive).map(W=>W.title),z=p?k.find(W=>W.key===p):void 0,D=z?N.get(z.widget):void 0;return t.jsxs(ye,{title:"What it shows",aside:"Every change is kept at once.",panel:!0,children:[t.jsxs("div",{className:"lke",children:[t.jsxs("div",{className:"lke-look",children:[t.jsx(Sae,{data:a.data,phone:u}),t.jsxs("div",{className:"lke-look-foot",children:[t.jsx(cn,{label:"Preview on",options:[{value:"desk",label:"Desk"},{value:"phone",label:"Phone"}],value:u?"phone":"desk",onChange:W=>h(W==="phone")}),t.jsxs("span",{className:"lke-look-note",children:["As it shows now",(se=a.data)!=null&&se.focus?", with your focus on":"","."]})]})]}),t.jsxs("div",{className:"lke-controls",children:[t.jsx(re,{message:m}),t.jsxs("div",{className:"lke-group",role:"group","aria-label":"Clock",children:[t.jsx("p",{className:"lke-group-title",children:"Clock"}),t.jsxs("div",{className:"wg-field",role:"group","aria-label":"Time",children:[t.jsx("span",{className:"wg-field-label",children:"Time"}),t.jsx(cn,{label:"Time",options:[{value:"profile",label:jR()},{value:"12h",label:"12-hour"},{value:"24h",label:"24-hour"}],value:r.time,onChange:W=>n({...r,time:W})})]}),t.jsx(le,{label:"Date",children:t.jsxs("select",{value:r.date,onChange:W=>n({...r,date:W.target.value}),children:[t.jsxs("option",{value:"profile",children:["Profile · ",O(null)]}),t.jsx("option",{value:"short",children:O("short")}),t.jsx("option",{value:"long",children:O("long")}),t.jsx("option",{value:"iso",children:O("iso")}),t.jsx("option",{value:"off",children:"No date"})]})}),t.jsx(le,{label:"A second clock",hint:"A place in another zone, under the time.",children:t.jsxs("select",{value:g?"find":NE(r.zone),onChange:W=>E(W.target.value),children:[t.jsx("option",{value:"",children:"None"}),I.map(W=>t.jsxs("option",{value:`place:${W.id}`,children:[W.label," — ",W.name.split(",")[0]]},W.id)),r.zone&&"place"in r.zone&&!I.some(W=>W.id===r.zone.place)?t.jsx("option",{value:NE(r.zone),children:"A place no longer in another zone"}):null,F?t.jsx("option",{value:`town:${F.timezone}:${F.label}`,children:F.label}):null,t.jsx("option",{value:"find",children:"Another town…"})]})}),g?t.jsxs("div",{className:"wg-field-stack",children:[t.jsxs("div",{className:"wg-find",children:[t.jsx("input",{autoFocus:!0,value:g.query,placeholder:"Find a town: Tokyo","aria-label":"Find a town for the second clock",onChange:W=>w({...g,query:W.target.value}),onKeyDown:W=>{W.key==="Enter"&&(W.preventDefault(),R()),W.key==="Escape"&&w(null)}}),t.jsx($,{size:"sm",disabled:g.busy||g.query.trim().length<2,onClick:R,children:g.busy?"Finding…":"Find"})]}),g.missed?t.jsx("span",{className:"ui-field-hint",children:g.missed}):null]}):null]}),t.jsxs("div",{className:"lke-group",role:"group","aria-label":"Widgets",children:[t.jsxs("div",{className:"lke-group-head",children:[t.jsxs("p",{className:"lke-group-title",children:["Widgets ",t.jsxs("span",{className:"lke-count",children:[k.length," of ",kE]})]}),b||!o?t.jsxs($,{size:"sm",disabled:!0,children:[t.jsx(ne,{name:"plus",size:12})," Add a widget"]}):t.jsx(rs,{label:"Add a widget",trigger:t.jsxs("button",{type:"button",className:"ui-btn","data-size":"sm",children:[t.jsx(ne,{name:"plus",size:12})," Add a widget"]}),items:[U.length>0?{heading:"As on Home"}:null,...U.map(W=>({label:W.label??N.get(W.widget).title,hint:"same settings",onSelect:()=>A(W.widget,W.settings)})),U.length>0?"separator":null,{heading:"Every widget"},...L.map(W=>({label:W.title,onSelect:()=>A(W.id,{})})),"separator",{label:"Get more widgets",hint:"Browse",onSelect:()=>{window.location.hash=cv("widgets")}}]})]}),o?k.length===0?t.jsx("p",{className:"lke-empty",children:"No widgets: just the clock and the counts."}):t.jsx("ul",{className:"lke-list",children:k.map((W,xe)=>{const me=N.get(W.widget);return me?t.jsx(Cae,{info:me,placement:W,index:xe,count:k.length,onSize:ie=>void S(k.map(H=>H.key===W.key?{...H,size:ie}:H)),onSettings:()=>x(W.key),onMove:ie=>C(xe,ie),onRemove:()=>void S(k.filter(ie=>ie.key!==W.key))},W.key):null})}):t.jsx("p",{className:"lke-empty","aria-busy":"true",children:"Reading the lock screen’s widgets…"}),t.jsxs("p",{className:"ui-field-hint",children:[b?"Four is the most it holds; take one off to add another. ":"","Each keeps its own settings, apart from Home’s.",M.length>0?` A sensitive widget — ${M.join(", ")} — never shows here.`:" A sensitive widget never shows here."," ","One with nothing to show right now stays off until it has."]})]}),t.jsxs("p",{className:"lke-note",children:[t.jsx(ne,{name:"moon",size:13}),t.jsx("span",{children:"Your focus shows at the top only while one is on. Approvals and what else needs you show as counts when there are some, never what they say."})]})]})]}),z&&D?t.jsx(K2,{info:D,placement:z,surface:"lock",onClose:()=>x(null),onSave:W=>S(k.map(xe=>xe.key===z.key?{...xe,settings:W}:xe)).then(xe=>(xe&&x(null),xe)),onRemove:()=>{x(null),S(k.filter(W=>W.key!==z.key))}}):null]})}const Aae=[{id:"field",label:"Buddi"},{id:"dawn",label:"Dawn"},{id:"sea",label:"Sea"},{id:"moss",label:"Moss"},{id:"dusk",label:"Dusk"}];function $ae({background:e,pictures:n}){if(e==="earth")return t.jsxs("p",{className:"lk-credit",children:["Earth: photo by ",t.jsx("a",{href:cx.authorUrl,target:"_blank",rel:"noreferrer",children:cx.author})," on ",t.jsx("a",{href:cx.photoUrl,target:"_blank",rel:"noreferrer",children:"Unsplash"})]});const s=U2(e),r=s?n==null?void 0:n.find(a=>a.id===s):void 0;return r?t.jsxs("p",{className:"lk-credit",children:[r.credit,r.landscape?null:". Made for phones: a wide screen shows it whole, in the middle."]}):null}const Tae=[{value:"1",label:"1 min"},{value:"5",label:"5 min"},{value:"15",label:"15 min"},{value:"60",label:"1 hour"},{value:"never",label:"Never"}],Rae=e=>e.delayMinutes===null?"never":String(e.delayMinutes);function wy(e){if(e instanceof pe){const n=e.detail??{};return e.status===429||n.waitUntil?"Too many wrong tries. Wait a moment, then try again.":e.status===403&&typeof n.triesLeft=="number"?`${e.message} ${n.triesLeft} ${n.triesLeft===1?"try":"tries"} left.`:e.message}return"Something went wrong. Try again."}function Iae({kind:e,onClose:n,onDone:s}){const[r,a]=d.useState(""),[i,l]=d.useState(""),[o,c]=d.useState(""),[u,h]=d.useState(null),[m,f]=d.useState(!1),p=e==="remove",x=e!=="set",g=!m&&(!x||r.length>=4)&&(p||i.length>=4&&o.length>=4),w=k=>k.replace(/\D/g,"").slice(0,8),v=e==="set"?"Set a PIN":e==="change"?"Change your PIN":"Remove the PIN?",j=k=>{if(k==null||k.preventDefault(),!g)return;if(!p&&i!==o){h("The two PINs aren’t the same.");return}f(!0),h(null),(p?T.removePin(r):T.setPin(i,x?r:void 0)).then(s).catch(b=>{f(!1),h(wy(b))})},y=(k,N,b,S)=>t.jsx(le,{label:k,children:t.jsx("input",{type:"password",inputMode:"numeric",autoComplete:k==="Current PIN"?"current-password":"new-password",maxLength:8,autoFocus:S,value:N,onChange:C=>{h(null),b(w(C.target.value))}})});return t.jsx(Gt,{title:v,onClose:n,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx($,{variant:p?"danger":"accent",disabled:!g,onClick:()=>j(),children:p?"Remove PIN":e==="set"?"Set PIN":"Change PIN"})]}),children:t.jsxs("form",{className:"lk-form",onSubmit:j,children:[t.jsx("p",{className:"lk-honest",children:p?"The dashboard stops locking, on every device. You can set a PIN again any time.":"Four to eight digits. You type it to open the dashboard after it locks, on any device signed in to it."}),x?y("Current PIN",r,a,!0):null,p?null:y(e==="set"?"PIN":"New PIN",i,l,!x),p?null:y("The same again",o,c,!1),u?t.jsx(Q,{tone:"critical",children:u}):null,t.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]})})}function Pae(e){const n=Tp(),s=je(()=>T.lockState(),[]),[r,a]=d.useState(null),[i,l]=d.useState(null),[o,c]=d.useState(null),u=d.useRef(null),h=d.useRef(null),m=z2(),f=s.data??n.state,p=j=>{n.update(j),s.reload()},x=j=>{l(null),j.then(p).catch(y=>l(wy(y)))},g=(j,y)=>{j&&(c(y),l(null),(y==="portrait"?T.uploadLockPortrait(j):T.uploadLockBackground(j)).then(p).catch(k=>l(wy(k))).finally(()=>{c(null);const k=y==="portrait"?h.current:u.current;k&&(k.value="")}))};if(!f)return t.jsx(ye,{title:"Lock screen",panel:!0,children:t.jsx(re,{message:s.error?"Couldn’t read the lock screen’s settings.":null})});const w=f.pin,v=(j,y,k)=>t.jsxs("button",{type:"button",className:"lk-swatch","data-bg":j,"aria-pressed":f.background===j,"aria-label":y,title:y,onClick:()=>x(T.setLockSettings({background:j})),children:[j==="image"&&f.image?t.jsx("img",{src:f.image,alt:""}):j==="earth"?t.jsx("img",{src:sy.thumb,alt:""}):k?t.jsx("img",{src:k,alt:""}):t.jsx("span",{className:"lk-swatch-field"}),t.jsx("span",{className:"lk-swatch-label",children:y})]},j);return t.jsxs(t.Fragment,{children:[t.jsxs(ye,{title:"Lock screen",aside:"Kept for every device signed in to this dashboard.",actions:w?t.jsxs($,{size:"sm",onClick:()=>n.lockNow(),children:[t.jsx(ne,{name:"lock",size:13})," Lock now"]}):void 0,panel:!0,children:[t.jsxs(ue,{divided:!0,gap:"lg",children:[t.jsx("p",{className:"lk-honest ui-section",children:"A privacy screen over this dashboard, on every device signed in to it: it locks when nobody has used it for a while, or when you lock it, and opens with your PIN. A new browser opens locked too. It isn’t a second sign-in — anyone who can run buddi on this computer can open it without the PIN. Telegram and buddi in your coding tools carry on as before."}),t.jsx(re,{message:i}),t.jsxs("div",{className:"lk-pref ui-section",children:[t.jsxs("div",{className:"lk-pref-text",children:[t.jsx("div",{className:"lk-pref-label",children:"PIN"}),t.jsx("div",{className:"ui-field-hint",children:w?"Set. Kept hashed on this buddi; five wrong tries, then a wait that grows.":"Four to eight digits. Until you set one, nothing locks."})]}),w?t.jsxs(te,{children:[t.jsx($,{size:"sm",variant:"ghost",onClick:()=>a("remove"),children:"Remove…"}),t.jsx($,{size:"sm",onClick:()=>a("change"),children:"Change…"})]}):t.jsx($,{size:"sm",variant:"accent",onClick:()=>a("set"),children:"Set a PIN"})]}),t.jsxs("div",{className:"lk-pref ui-section","data-off":w?void 0:"true","aria-disabled":w?void 0:"true",children:[t.jsxs("div",{className:"lk-pref-text",children:[t.jsx("div",{className:"lk-pref-label",children:"Lock after"}),t.jsx("div",{className:"ui-field-hint",children:w?t.jsxs(t.Fragment,{children:["Nobody using it for this long. Lock it yourself from your menu",t.jsxs("span",{className:"lk-shortcut",children:[", or with ",t.jsx("kbd",{className:"lk-kbd",children:n.shortcut})]}),"."]}):"Set a PIN first."})]}),t.jsx(cn,{label:"Lock after",options:Tae,value:w?Rae(f):"",onChange:j=>{w&&x(T.setLockSettings({delayMinutes:j==="never"?null:Number(j)}))}})]}),t.jsxs("div",{className:"lk-pref ui-section","data-stack":"true",children:[t.jsxs("div",{className:"lk-pref-text",children:[t.jsx("div",{className:"lk-pref-label",children:"Background"}),t.jsx("div",{className:"ui-field-hint",children:"Behind the time and your widgets, on every device. A picture is kept as a JPEG of at most 2560 pixels, without its location or other details."})]}),t.jsxs("div",{className:"lk-bg-rows",children:[t.jsxs("div",{className:"lk-bg-row",role:"group","aria-labelledby":"lk-bg-colours",children:[t.jsx("p",{className:"lk-bg-row-label",id:"lk-bg-colours",children:"Colours"}),t.jsx("div",{className:"lk-swatches",children:Aae.map(j=>v(j.id,j.label))})]}),t.jsxs("div",{className:"lk-bg-row",role:"group","aria-labelledby":"lk-bg-pictures",children:[t.jsx("p",{className:"lk-bg-row-label",id:"lk-bg-pictures",children:"Pictures"}),t.jsxs("div",{className:"lk-swatches",children:[v("earth","Earth"),(m??[]).map(j=>v(kZ(j.id),j.title,j.thumb)),f.image?v("image","Your picture"):null,t.jsxs("label",{className:"lk-swatch","data-kind":"add","aria-busy":o==="image"?"true":void 0,children:[t.jsx("input",{ref:u,type:"file",accept:"image/jpeg,image/png",className:"lk-sr","aria-label":f.image?"Replace your picture":"Add your picture",disabled:o!==null,onChange:j=>{var y;return g((y=j.target.files)==null?void 0:y[0],"image")}}),t.jsx("span",{className:"lk-swatch-field","data-kind":"add",children:t.jsx(ne,{name:"plus",size:16})}),t.jsx("span",{className:"lk-swatch-label",children:o==="image"?"Adding…":f.image?"Replace":"Add"})]})]}),t.jsx($ae,{background:f.background,pictures:m})]})]}),f.image?t.jsxs("div",{className:"lk-pref","data-sub":"true",children:[t.jsx("div",{className:"lk-pref-text",children:t.jsx("div",{className:"ui-field-hint",children:f.imagePortrait?"Phones show its portrait version.":"Phones show the middle of it. Add a portrait version to choose what they show."})}),t.jsxs(te,{align:"end",children:[t.jsx("input",{ref:h,type:"file",accept:"image/jpeg,image/png",className:"lk-sr","aria-label":"Portrait version for phones",disabled:o!==null,onChange:j=>{var y;return g((y=j.target.files)==null?void 0:y[0],"portrait")}}),t.jsx($,{size:"sm",variant:"ghost",onClick:()=>x(T.removeLockBackground()),children:"Remove picture"}),f.imagePortrait?t.jsx($,{size:"sm",variant:"ghost",onClick:()=>x(T.removeLockPortrait()),children:"Remove portrait"}):null,t.jsx($,{size:"sm",disabled:o!==null,onClick:()=>{var j;return(j=h.current)==null?void 0:j.click()},children:o==="portrait"?"Adding…":f.imagePortrait?"Replace portrait…":"Add portrait…"})]})]}):null]})]}),r?t.jsx(Iae,{kind:r,onClose:()=>a(null),onDone:j=>{a(null),p(j)}}):null]}),t.jsx(Eae,{clock:f.clock,onClock:j=>x(T.setLockSettings({clock:j})),version:`${f.background}:${f.image??""}:${f.imagePortrait??""}:${JSON.stringify(f.clock??null)}`})]})}const bx=60;function yD(e){return e instanceof pe?e.message:"Something went wrong. Try again."}function Mae(e,n,s=Date.now()){const r=`made ${Ks(new Date(e.createdAt),n,{compact:!0})} ${e.createdVia==="cli"?"in the terminal":"here"}`;return`buddi_…${e.hint} · ${r} · ${e.lastUsedAt?`last used ${Xe(e.lastUsedAt,s)}`:"never used"}`}function Oae({onClose:e,onMade:n}){const[s,r]=d.useState(""),[a,i]=d.useState(!1),[l,o]=d.useState(null),[c,u]=d.useState(null),[h,m]=d.useState(!1),f=!a&&s.trim()!==""&&s.trim().length<=bx,p=x=>{x==null||x.preventDefault(),f&&(i(!0),o(null),T.createApiToken(s.trim()).then(g=>{u({token:g.token,name:g.apiToken.name}),n()}).catch(g=>o(yD(g))).finally(()=>i(!1)))};if(c){const x=()=>{var g;(g=navigator.clipboard)==null||g.writeText(c.token).then(()=>{m(!0),window.setTimeout(()=>m(!1),1600)}).catch(()=>{})};return t.jsx(Gt,{title:`Token for ${c.name}`,onClose:e,foot:t.jsx($,{variant:"accent",onClick:e,children:"Done"}),children:t.jsxs("div",{className:"at-form",children:[t.jsxs("div",{className:"at-secret",children:[t.jsx("code",{className:"at-secret-text","aria-label":"The token",children:c.token}),t.jsx($,{size:"sm",onClick:x,children:h?"Copied":"Copy"})]}),t.jsx(Q,{tone:"warning",title:"Copy it now",children:"buddi keeps only a fingerprint of it, so it can’t show it again. Lost it? Revoke it and make another."}),t.jsx("p",{className:"at-text",children:"Send it as a header on every request:"}),t.jsx("code",{className:"at-try",children:`curl -H "Authorization: Bearer buddi_…" ${location.origin}/api/overview`})]})})}return t.jsx(Gt,{title:"Make a token",onClose:e,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:e,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:!f,onClick:()=>p(),children:"Make token"})]}),children:t.jsxs("form",{className:"at-form",onSubmit:p,children:[t.jsx("p",{className:"at-text",children:"It acts as you on buddi’s HTTP API. Anything a gated tool does still waits for your approval here or on Telegram."}),t.jsx(le,{label:"What will use it",hint:`So you can tell tokens apart later. Up to ${bx} characters.`,children:t.jsx("input",{autoFocus:!0,value:s,maxLength:bx,placeholder:"Home Assistant",onChange:x=>{o(null),r(x.target.value)}})}),l?t.jsx(Q,{tone:"critical",children:l}):null,t.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]})})}function Dae({token:e,onClose:n,onRevoked:s}){const[r,a]=d.useState(!1),[i,l]=d.useState(null),o=()=>{a(!0),l(null),T.revokeApiToken(e.id).then(()=>{s(),n()}).catch(c=>{a(!1),l(yD(c))})};return t.jsxs(Gt,{title:`Revoke “${e.name}”?`,onClose:n,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx($,{variant:"danger",disabled:r,onClick:o,children:"Revoke"})]}),children:[t.jsx("p",{className:"at-text",children:"A request carrying it is refused from now on. Whatever uses it stops working until you give it a new token."}),i?t.jsx(Q,{tone:"critical",children:i}):null]})}function Lae({timezone:e}){var o;const n=je(()=>T.apiTokens(),[]),[s,r]=d.useState(!1),[a,i]=d.useState(null),l=((o=n.data)==null?void 0:o.tokens)??[];return t.jsxs(ue,{gap:"lg",children:[t.jsx("p",{className:"ui-page-lede",children:"Let a script or another program use buddi without the dashboard. A token acts as you, minus the decisions only you make here."}),t.jsx(re,{message:n.error?"Couldn’t read the API tokens.":null}),t.jsx(ye,{title:"Tokens",aside:"Kept as a fingerprint · shown once",actions:t.jsx($,{variant:"accent",size:"sm",onClick:()=>r(!0),children:"Make a token"}),panel:!0,flush:!0,children:n.data&&l.length===0?t.jsxs(Ee,{title:"No tokens yet.",children:["Make one here, or in a terminal with ",t.jsx("code",{className:"mono",children:"buddi api-token create <name>"}),"."]}):t.jsx(yt,{children:l.map(c=>t.jsx(pt,{lead:t.jsx(ss,{icon:"key"}),title:c.name,sub:Mae(c,e),side:t.jsx($,{size:"sm",variant:"ghost",onClick:()=>i(c),children:"Revoke…"})},c.id))})}),t.jsxs(ye,{title:"What a token can’t do",panel:!0,children:[t.jsxs("ul",{className:"at-cant",children:[t.jsx("li",{children:"Approve anything, or make a change where your click is the approval. It can reject."}),t.jsx("li",{children:"Change what an agent may do without asking: its tools, who it hands work to, a connection given out, an “Always”."}),t.jsx("li",{children:"Install or run code buddi hasn’t run before: plugins, upgrades, program connections."}),t.jsx("li",{children:"Change how buddi is reached or unlocked — PIN, Tailscale, Telegram pairing, other tokens — or restore a backup."}),t.jsx("li",{children:"Read or store a secret: owner secrets, model account keys, the backup passphrase."})]}),t.jsxs("p",{className:"at-foot",children:["In a terminal: ",t.jsx("code",{className:"mono",children:"buddi api-token create"}),", ",t.jsx("code",{className:"mono",children:"list"}),", ",t.jsx("code",{className:"mono",children:"revoke"}),". Every route, and which a token may call: docs/api.md."]})]}),s?t.jsx(Oae,{onClose:()=>r(!1),onMade:()=>n.reload()}):null,a?t.jsx(Dae,{token:a,onClose:()=>i(null),onRevoked:()=>n.reload()}):null]})}function Fae({embedded:e}){const{data:n,error:s,reload:r}=je(()=>T.owner(),[]);return t.jsxs(Is,{embedded:e,title:"You",lede:"What every agent knows about the person it is talking to.",children:[t.jsx(re,{message:s}),n?t.jsxs(ue,{gap:"lg",children:[t.jsx(Uae,{initial:n,onSaved:r}),t.jsx(Kae,{initial:n})]}):null]})}const wD=new Date(Date.UTC(2026,9,1,14,5));function _ae(){return[["",`Auto (${dd({timeFormat:null},()=>Lt(wD,"UTC"))} here)`],["12h","12-hour · 2:05 PM"],["24h","24-hour · 14:05"]]}function zae(){return[["",`Auto (${dd({dateFormat:null},()=>Ks(wD,"UTC",{weekday:!0}))} here)`],["short","Thu, Oct 1"],["long","Thursday, 1 October"],["iso","2026-10-01"]]}function Uae({initial:e,onSaved:n}){var F,U,L;const[s,r]=d.useState(e.preferredName??""),[a,i]=d.useState(e.timezone??""),[l,o]=d.useState(e.timeFormat??""),[c,u]=d.useState(e.dateFormat??""),[h,m]=d.useState(e.language??""),[f,p]=d.useState(e.about??""),[x,g]=d.useState(e.fullName??""),[w,v]=d.useState(e.pronouns??""),[j,y]=d.useState(um(e.birthday)),[k,N]=d.useState(!1),[b,S]=d.useState(!1),[C,A]=d.useState(null);d.useEffect(()=>{r(e.preferredName??""),i(e.timezone??""),o(e.timeFormat??""),u(e.dateFormat??""),m(e.language??""),p(e.about??""),g(e.fullName??""),v(e.pronouns??""),y(um(e.birthday))},[e.preferredName,e.timezone,e.timeFormat,e.dateFormat,e.language,e.about,e.fullName,e.pronouns,(F=e.birthday)==null?void 0:F.day,(U=e.birthday)==null?void 0:U.month,(L=e.birthday)==null?void 0:L.year]);const E=dm(j),R=s.trim()!==(e.preferredName??"")||a!==(e.timezone??"")||l!==(e.timeFormat??"")||c!==(e.dateFormat??"")||h.trim()!==(e.language??"")||f.trim()!==(e.about??"")||x.trim()!==(e.fullName??"")||w.trim()!==(e.pronouns??"")||E!=="incomplete"&&!Ote(E,e.birthday),P=async()=>{N(!0),A(null);try{const M=await T.setOwner({preferredName:s.trim()===""?null:s.trim(),timezone:a===""?null:a,timeFormat:l===""?null:l,dateFormat:c===""?null:c,language:h.trim()===""?null:h.trim(),about:f.trim()===""?null:f.trim(),fullName:x.trim()===""?null:x.trim(),pronouns:w.trim()===""?null:w.trim(),...E!=="incomplete"?{birthday:E}:{}});Ww({timeFormat:M.timeFormat??null,dateFormat:M.dateFormat??null}),window.dispatchEvent(new Event(_j)),S(!0),n()}catch(M){A(M instanceof pe?M.message:String(M))}finally{N(!1)}},O=e.zones.length>0?e.zones:[e.detectedTimezone],I=M=>z=>{S(!1),M(z)};return t.jsx(ye,{title:"Your profile",aside:"read by every agent, as context",panel:!0,foot:t.jsxs(t.Fragment,{children:[b&&!R?t.jsx("span",{className:"muted",children:"Saved"}):null,t.jsx($,{variant:"accent",disabled:!R||k,onClick:()=>void P(),children:k?"Saving…":"Save"})]}),children:t.jsxs(ue,{divided:!0,gap:"lg",children:[t.jsx(ye,{title:"Who you are",children:t.jsxs(Vs,{children:[t.jsx(le,{label:"Full name",hint:"For letters, forms and bookings.",children:t.jsx("input",{value:x,maxLength:120,placeholder:e.displayName??"Your full name",onChange:M=>I(g)(M.target.value)})}),t.jsx(le,{label:"What the agents call you",hint:"How you like to be addressed.",children:t.jsx("input",{value:s,maxLength:80,placeholder:e.displayName??"Your name",onChange:M=>I(r)(M.target.value)})}),t.jsx(le,{label:"Pronouns",hint:"Optional.",children:t.jsx("input",{value:w,maxLength:40,placeholder:"he/him, she/her, they/them…",onChange:M=>I(v)(M.target.value)})}),t.jsx(dy,{label:"Birthday",hint:"The year is optional. Your team greets you on the day.",value:j,onChange:I(y)})]})}),t.jsx(ye,{title:"Time and language",children:t.jsxs(Vs,{children:[t.jsx(le,{label:"Timezone",hint:`This host is in ${e.detectedTimezone}. Existing schedules keep the zone they were made in.`,children:t.jsxs("select",{value:a,onChange:M=>I(i)(M.target.value),children:[t.jsx("option",{value:"",children:"Not set (use the host's)"}),O.map(M=>t.jsx("option",{value:M,children:M},M))]})}),t.jsx(le,{label:"Time",children:t.jsx("select",{value:l,onChange:M=>I(o)(M.target.value),children:_ae().map(([M,z])=>t.jsx("option",{value:M,children:z},M))})}),t.jsx(le,{label:"Dates",hint:"Auto follows this browser's language. Agents write them your way too.",children:t.jsx("select",{value:c,onChange:M=>I(u)(M.target.value),children:zae().map(([M,z])=>t.jsx("option",{value:M,children:z},M))})}),t.jsx(le,{label:"Answer me in",hint:"A language, as you would say it. Blank mirrors whatever you write in.",children:t.jsx("input",{value:h,maxLength:40,placeholder:"English, français…",onChange:M=>I(m)(M.target.value)})})]})}),t.jsxs(ye,{title:"About you",children:[t.jsx(le,{label:"In your own words",hint:"Who you are, how you like answers, anything every agent should keep in mind. A few lines is plenty.",children:t.jsx("textarea",{rows:4,maxLength:1e3,value:f,placeholder:"I run a small studio and prefer short answers with the numbers first. Call me by my first name.",onChange:M=>I(p)(M.target.value)})}),C?t.jsx(Q,{tone:"critical",children:C}):null]})]})})}const Bae=["Home","Work"];function Wae(e){const n=e.trim().toLowerCase();return n==="home"?"home":n==="work"?"briefcase":"pin"}function SE({label:e,empty:n}){return t.jsx("span",{className:"place-glyph","data-empty":n?"true":void 0,"aria-hidden":"true",children:t.jsx(ne,{name:Wae(e),size:18})})}function Hae(e){var s;const n=((s=e.name.split(",").pop())==null?void 0:s.trim())??"";return e.address?n&&!e.address.toLowerCase().includes(n.toLowerCase())?`${e.address} · ${n}`:e.address:e.name}function Kae({initial:e}){var c;const[n,s]=d.useState(e.places??[]);d.useEffect(()=>s(e.places??[]),[e]);const[r,a]=d.useState(null),i=e.timezone??e.detectedTimezone,l=Bae.filter(u=>!n.some(h=>h.label.toLowerCase()===u.toLowerCase())),o=d.useMemo(()=>new Date,[n]);return t.jsxs(ye,{title:"Places",aside:"the front desk, and plugins you allow",actions:t.jsx($,{size:"sm",onClick:()=>a({label:""}),children:"Add a place"}),panel:!0,flush:!0,children:[t.jsxs(yt,{children:[n.map(u=>t.jsx(pt,{label:`${u.label}: edit`,onClick:()=>a({place:u,label:u.label}),lead:t.jsx(SE,{label:u.label}),title:u.label,sub:Hae(u),side:u.timezone&&u.timezone!==i?t.jsxs($e,{children:[Lt(o,u.timezone)," there"]}):void 0},u.id)),l.map(u=>t.jsx(pt,{label:`${u}: add`,onClick:()=>a({label:u}),lead:t.jsx(SE,{label:u,empty:!0}),title:t.jsx("span",{className:"muted",children:u}),sub:"Not set",side:t.jsx($,{size:"sm",onClick:h=>{h.stopPropagation(),a({label:u})},children:"Add"})},u))]}),t.jsx("p",{className:"place-note",children:"Only the town is looked up, on Open-Meteo, to find where it is and its timezone. The address stays on this computer."}),r?t.jsx(Vae,{editing:r,zones:e.zones.length>0?e.zones:[e.detectedTimezone],onClose:()=>a(null),onSaved:u=>{s(u),a(null)}},((c=r.place)==null?void 0:c.id)??`new:${r.label}`):null]})}function Vae({editing:e,zones:n,onClose:s,onSaved:r}){const a=e.place,[i,l]=d.useState(e.label),[o,c]=d.useState((a==null?void 0:a.address)??""),[u,h]=d.useState(a?[{name:a.name,latitude:a.latitude,longitude:a.longitude,...a.timezone?{timezone:a.timezone}:{}}]:null),[m,f]=d.useState(0),[p,x]=d.useState((a==null?void 0:a.timezone)??""),[g,w]=d.useState(null),[v,j]=d.useState(null),[y,k]=d.useState((a==null?void 0:a.address)??""),N=u==null?void 0:u[m],b=()=>{o.trim().length<2||(w("find"),j(null),T.findPlace(o.trim()).then(R=>{var P;h(R.found),k(o.trim()),f(0),x(((P=R.found[0])==null?void 0:P.timezone)??""),R.found.length===0&&j("Nothing found by that name. Try the town, with its country.")}).catch(R=>j(R instanceof pe?R.message:String(R))).finally(()=>w(null)))},S=()=>{N&&(w("save"),j(null),T.savePlace({...a?{id:a.id}:{},label:i.trim(),address:o.trim()===""?null:o.trim(),name:N.name,latitude:N.latitude,longitude:N.longitude,timezone:p===""?null:p}).then(R=>r(R.places)).catch(R=>j(R instanceof pe?R.message:String(R))).finally(()=>w(null)))},C=()=>{a&&(w("remove"),j(null),T.removePlace(a.id).then(R=>r(R.places)).catch(R=>j(R instanceof pe?R.message:String(R))).finally(()=>w(null)))},A=a?a.label:e.label?`Add ${e.label}`:"Add a place",E=p!==""&&!n.includes(p)?[p,...n]:n;return t.jsx(Ye,{title:A,onClose:s,foot:t.jsxs(te,{children:[a?t.jsx($,{variant:"danger-ghost",disabled:g!==null,onClick:C,children:g==="remove"?"Removing…":"Remove"}):null,t.jsx(ht,{}),t.jsx($,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:!N||i.trim()===""||g!==null,onClick:S,children:g==="save"?"Saving…":"Save"})]}),children:t.jsxs(ue,{gap:"lg",children:[t.jsx(le,{label:"Name",hint:"What you call it: Home, Work, Mum's.",children:t.jsx("input",{value:i,maxLength:40,autoFocus:!e.label,onChange:R=>l(R.target.value)})}),t.jsx(le,{label:"Address",hint:"A street address, or just the town.",action:t.jsx($,{disabled:o.trim().length<2||g!==null,onClick:b,children:g==="find"?"Finding…":"Find"}),children:t.jsx("input",{value:o,maxLength:200,autoFocus:!!e.label&&!a,placeholder:"12 Elm Street, Portland, Maine",onChange:R=>c(R.target.value),onKeyDown:R=>{R.key==="Enter"&&(R.preventDefault(),b())}})}),u&&u.length>0?t.jsx("div",{className:"place-found",role:"radiogroup","aria-label":"Which place",children:u.map((R,P)=>t.jsxs("button",{type:"button",role:"radio","aria-checked":P===m,className:"place-option","data-on":P===m?"true":void 0,onClick:()=>{f(P),x(R.timezone??"")},children:[t.jsx("span",{className:"place-radio","aria-hidden":"true"}),t.jsxs("span",{className:"place-option-text",children:[t.jsx("span",{className:"place-option-name",children:R.name}),t.jsxs("span",{className:"place-option-sub",children:[R.latitude.toFixed(2),", ",R.longitude.toFixed(2),R.timezone?` · ${R.timezone}`:""]})]})]},`${R.latitude},${R.longitude}`))}):t.jsx("p",{className:"place-note-inline",children:"Find it to pin it on the map; nothing is saved until you say Save."}),a&&u&&o.trim()!==y?t.jsx("p",{className:"place-note-inline",children:"The address changed. Find it again to move the pin, or save to keep it where it is."}):null,t.jsx(le,{label:"Its timezone",hint:N?"From where it is. Change it if that is wrong.":"Filled in once the place is found.",children:t.jsxs("select",{value:p,disabled:!N,onChange:R=>x(R.target.value),children:[t.jsx("option",{value:"",children:"Not known"}),E.map(R=>t.jsx("option",{value:R,children:R},R))]})}),t.jsx(re,{message:v})]})})}const Gae=2e6;function CE(e,n){const s=e.replace(/\r\n/g,`
141
- `).replace(/\n+$/,"").split(`
142
- `),r=n.replace(/\r\n/g,`
143
- `).replace(/\n+$/,"").split(`
144
- `);if(e.trim()===n.trim())return"(no change)";if(s.length*r.length>Gae)return[...s.map(c=>`-${c}`),...r.map(c=>`+${c}`)].join(`
145
- `);const a=Array.from({length:s.length+1},()=>new Uint32Array(r.length+1));for(let c=s.length-1;c>=0;c--)for(let u=r.length-1;u>=0;u--)a[c][u]=s[c]===r[u]?a[c+1][u+1]+1:Math.max(a[c+1][u],a[c][u+1]);const i=[];let l=0,o=0;for(;l<s.length&&o<r.length;)s[l]===r[o]?(i.push(` ${s[l]}`),l++,o++):a[l+1][o]>=a[l][o+1]?i.push(`-${s[l++]}`):i.push(`+${r[o++]}`);for(;l<s.length;)i.push(`-${s[l++]}`);for(;o<r.length;)i.push(`+${r[o++]}`);return i.join(`
146
- `)}const bD={skill:"skill",policy:"rule",change:"change to itself"};function qae(e){return e===null||typeof e!="object"||Array.isArray(e)?String(e??""):Object.entries(e).filter(([n,s])=>!/Id$/.test(n)&&s!==null&&s!==void 0&&s!=="").map(([n,s])=>`${n} ${typeof s=="object"?JSON.stringify(s):String(s)}`).join(" · ")}function by(e){return[...new Set(e.split(/[,\n]/).map(n=>n.trim().replace(/^[-*]\s+/,"")).filter(n=>n!==""))]}function Yae(e,n){const s=e.change;if(!s||s.part!=="tools")return[];if(n===e.editable)return s.added;const r=new Set(by(s.current??""));return by(n).filter(a=>!r.has(a))}function Qae(e){const n=i=>i.kind==="policy"&&i.ruleKind?`${String(i.payload.plugin??"")}\0${i.ruleKind}`:null,s=new Map;for(const i of e){const l=n(i);l&&s.set(l,(s.get(l)??0)+1)}const r=new Map,a=[];for(const i of e){const l=n(i);if(!l||(s.get(l)??0)<2){a.push(i);continue}let o=r.get(l);o||(o={key:l,label:i.ruleKindLabel||i.ruleKind||"Rules",plugin:String(i.payload.plugin??""),cards:[]},r.set(l,o),a.push(o)),o.cards.push(i)}return a}function Jae(e){return"cards"in e}function EE(e,n){return!n||e.kind==="policy"&&e.payload.plugin===n}function Xae({embedded:e,plugin:n}){const{data:s,error:r,reload:a}=je(()=>T.proposals(),[],3e4),[i,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(null),[m,f]=d.useState({}),p=async(j,y,k=!1)=>{l(null),c(null),h(j),f(({[j]:N,...b})=>b);try{c(await y()),a()}catch(N){const b=N instanceof Error?N.message:String(N);k?f(S=>({...S,[j]:b})):l(b)}finally{h(null)}},x=AP(),g=((s==null?void 0:s.open)??[]).filter(j=>EE(j,n)),w=((s==null?void 0:s.closed)??[]).filter(j=>EE(j,n)),v=j=>t.jsx(sie,{proposal:j,busy:u===j.id,refusal:m[j.id]??null,onKeep:y=>void p(j.id,async()=>{const k=await T.keepProposal(j.id,y);return`${j.title}: ${k.note}`},!0),onDiscard:y=>void p(j.id,async()=>(await T.discardProposal(j.id,y),`Discarded: ${j.title}. ${j.agent} will be told once and will not propose it again for 90 days.`))},j.id);return t.jsxs(Is,{embedded:e,title:"Proposals",lede:"What your agents learned and would like to keep: a procedure, a rule, a change to their own instructions. Keep what is right, correct what is nearly right, discard the rest. A few rules apply themselves, where their plugin allows it (one you always keep, one that only quiets mail sent to many); its own page lists them, with Undo.",children:[t.jsx(re,{message:r??i}),n?t.jsxs(Q,{role:"status",children:["Showing the rules ",n," proposes. ",t.jsx("a",{href:ze("proposals"),children:"Show every proposal"})]}):null,o?t.jsx(Q,{tone:"good",role:"status",children:o}):null,n?null:t.jsx($P,{offers:x.offers,reload:x.reload}),!s||g.length===0?t.jsx(ye,{title:"Waiting",panel:!0,children:s?n?t.jsx(ps,{icon:"bulb",title:`No rule from ${n} is waiting`,children:"It proposes one when you decide the same way several times running."}):t.jsx(ps,{icon:"bulb",title:"Nothing proposed",children:"When an agent learns something worth keeping, it waits here."}):t.jsx(Ee,{children:"Loading…"})}):t.jsx(ye,{title:"Waiting",aside:`${g.length} to decide`,children:Qae(g).map(j=>Jae(j)?t.jsx(Zae,{group:j,busy:u===j.key,onKeepAll:()=>void p(j.key,async()=>{const y=await T.keepAllProposals(j.cards.map(k=>k.id));return`${j.label}: ${y.note}`}),card:y=>v(y)},j.key):v(j))}),w.length>0?t.jsx(ye,{title:`Kept, discarded and expired (${w.length})`,aside:"These stop being shown a week after they were decided.",panel:!0,flush:!0,children:t.jsx(yt,{children:w.map(j=>{var y;return t.jsx(pt,{title:j.title,sub:`${j.agent}: ${eie(j)}`,side:j.kind==="skill"&&j.state==="kept"&&((y=j.skill)!=null&&y.live)?t.jsxs(te,{align:"end",children:[t.jsx("span",{className:"muted",children:Xe(j.decidedAt??j.createdAt)}),t.jsx($,{size:"sm",variant:"ghost",disabled:u===j.id,onClick:()=>void p(j.id,async()=>{const k=j.skill;return await T.removeSkill(j.agent,k.name),`Removed ${k.name} from ${j.agent}. Its versions are kept, and ${j.agent} will not propose it again for 90 days.`}),children:"Remove this skill"})]}):Xe(j.decidedAt??j.createdAt)},j.id)})})}):null,!n&&(s!=null&&s.digest)?t.jsx(nie,{schedule:s.digest.schedule,onSaved:a}):null]})}function Zae({group:e,busy:n,onKeepAll:s,card:r}){const a=e.cards.length,i=e.cards.some(l=>l.untrusted);return t.jsx(Br,{tone:i?"warning":"accent",title:`${e.label} (${a})`,meta:t.jsxs(t.Fragment,{children:[t.jsx($e,{children:bD.policy}),t.jsx($e,{mono:!0,children:e.plugin})]}),foot:t.jsx(te,{align:"end",children:t.jsxs($,{variant:"accent",size:"sm",disabled:n,onClick:s,children:["Keep all (",a,")"]})}),children:t.jsxs(ue,{gap:"sm",children:[t.jsxs("p",{children:[a," rules of the same kind from ",e.plugin,", each learned from your own decisions. Keep all keeps every one of them as if you had kept each, in one go."]}),t.jsx(Vt,{summary:`Show each of the ${a}`,children:t.jsx(ue,{gap:"sm",children:e.cards.map(l=>r(l))})})]})})}function eie(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 tie=Array.from({length:24},(e,n)=>n),AE=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function nie({schedule:e,onSaved:n}){const[s,r]=d.useState(e.day),[a,i]=d.useState(e.hour),[l,o]=d.useState(!1),[c,u]=d.useState(null),h=s!==e.day||a!==e.hour,m=async()=>{o(!0),u(null);try{await T.setDigestSchedule(s,a),u({tone:"good",text:`The digest now runs on ${AE[s]} at ${String(a).padStart(2,"0")}:00.`}),n()}catch(f){u({tone:"critical",text:f instanceof Error?f.message:String(f)})}finally{o(!1)}};return t.jsx(ye,{title:"Weekly digest",panel:!0,foot:t.jsx($,{variant:"accent",disabled:l||!h,onClick:()=>void m(),children:"Save"}),children:t.jsxs(ue,{children:[t.jsxs("p",{className:"muted",children:["Once a week, one message on Telegram and a card on Home: what your agents learned, what waits here, and what the rules you kept stopped them doing. No message when nothing was learned and nothing waits.",e.next?` Next: ${Xe(e.next)}.`:""]}),t.jsxs(te,{children:[t.jsx(le,{label:"Day",children:t.jsx("select",{value:s,disabled:l,onChange:f=>r(Number(f.target.value)),children:AE.map((f,p)=>t.jsx("option",{value:p,children:f},f))})}),t.jsx(le,{label:`Hour (${e.timezone})`,children:t.jsx("select",{value:a,disabled:l,onChange:f=>i(Number(f.target.value)),children:tie.map(f=>t.jsxs("option",{value:f,children:[String(f).padStart(2,"0"),":00"]},f))})})]}),c?t.jsx(Q,{tone:c.tone,role:"status",children:c.text}):null]})})}function $E(e,n){return e==="tools"?by(n).join(`
147
- `):n}function sie({proposal:e,busy:n,refusal:s,onKeep:r,onDiscard:a}){const[i,l]=d.useState(e.editable??""),[o,c]=d.useState(""),u=e.editable!==null&&i!==e.editable,h=e.payload,m=e.echoes??[],f=e.kind==="change"?e.change??null:null,p=Yae(e,i);return t.jsx(Br,{tone:e.untrusted?"warning":"accent",title:e.title,meta:t.jsxs(t.Fragment,{children:[t.jsx($e,{children:bD[e.kind]}),t.jsx($e,{mono:!0,children:e.agent}),e.untrusted?t.jsx($e,{tone:"warning",children:"untrusted text in view"}):null,p.length>0?t.jsx($e,{tone:"warning",children:"widens its tools"}):null]}),foot:t.jsxs(te,{align:"end",children:[s?t.jsx("span",{className:"proposal-refusal",role:"alert",children:s}):null,t.jsx("input",{"aria-label":"Reason for discarding (optional)",placeholder:"Reason for discarding (optional)",value:o,maxLength:300,disabled:n,onChange:x=>c(x.target.value)}),t.jsx($,{variant:"ghost",size:"sm",disabled:n,onClick:()=>a(o.trim()||void 0),children:"Discard"}),t.jsx($,{variant:"accent",size:"sm",disabled:n||e.editable!==null&&i.trim()==="",onClick:()=>r(u?i:void 0),children:u?"Keep my version":"Keep"})]}),children:t.jsxs(ue,{gap:"sm",children:[e.why?t.jsx("p",{children:e.why}):null,t.jsxs("p",{className:"ui-card-meta",children:["Proposed by ",e.agent," ",Xe(e.createdAt),e.conversationId?t.jsxs(t.Fragment,{children:[" in ",t.jsx("a",{href:Fu(e.conversationId),children:e.turn?`this conversation, turn ${e.turn}`:"this conversation"})]}):null,"."]}),e.untrusted?t.jsxs(Q,{tone:"warning",title:e.kind==="policy"?"Learned from mail you received.":"Made with untrusted text in view.",children:[e.kind==="policy"?"The plugin counted this rule from your own triage decisions; no instruction in that mail can change what it does.":"Something written by someone other than you was in the agent's context when it proposed this. Read it for instructions that came from there rather than from you.",t.jsx("ul",{className:"proposal-sources",children:e.sources.map(x=>t.jsx("li",{className:"mono",children:x},x))}),m.length>0?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"proposal-echo-lede",children:"These sentences of it also appear in that text:"}),t.jsx("ul",{className:"proposal-sources","aria-label":"Sentences found in the untrusted text",children:m.map(x=>t.jsx("li",{children:t.jsx("mark",{className:"wb-diff-mark",children:x})},x))})]}):null]}):null,e.kind==="skill"?t.jsxs(t.Fragment,{children:[typeof h.when=="string"?t.jsxs("p",{className:"ui-card-meta",children:["When: ",h.when]}):null,e.skill?t.jsxs(ue,{gap:"sm",children:[t.jsxs("p",{className:"ui-card-meta",children:[e.agent," already has this skill (",t.jsxs("a",{href:Qt(e.agent,"skills"),children:[e.skill.name,", version ",e.skill.version]}),"). Keeping this writes version ",e.skill.version+1,"; the earlier ones stay readable."]}),t.jsx(sm,{text:CE(e.skill.steps,i),marks:m,label:`Version ${e.skill.version} against this proposal`})]}):null,t.jsx(le,{label:"The steps, as it would follow them",hint:"Correct them here and keep your version.",children:t.jsx("textarea",{rows:8,value:i,disabled:n,onChange:x=>l(x.target.value)})})]}):null,e.kind==="change"?t.jsxs(t.Fragment,{children:[p.length>0?t.jsxs(Q,{tone:"warning",title:`Adds: ${p.join(", ")}`,children:["Keeping this lets ",e.agent," call tools it cannot call now."]}):null,f!=null&&f.refusal&&!u?t.jsx(Q,{tone:"warning",title:"Keeping this as proposed will be refused.",children:f.refusal}):null,f&&f.current!==null?t.jsx(sm,{text:CE($E(f.part,f.current),$E(f.part,i)),marks:m,label:`${e.agent}'s ${f.part==="tools"?"tool list":"instructions"} now, against this proposal`}):typeof h.before=="string"?t.jsx(Vt,{summary:`What its ${h.part==="tools"?"tool list":"instructions"} said when proposed`,children:t.jsx(Zt,{children:h.before})}):null,t.jsx(le,{label:h.part==="tools"?"Proposed tool list":"Proposed instructions",hint:"Correct it here and keep your version.",children:t.jsx("textarea",{rows:8,value:i,disabled:n,onChange:x=>l(x.target.value)})})]}):null,e.kind==="policy"?t.jsx(on,{items:[{label:"Plugin",value:t.jsx("span",{className:"mono",children:String(h.plugin??"")})},{label:"Matches",value:t.jsx("span",{className:"mono",children:qae(h.matcher??{})})},{label:"Does",value:String(h.action??"")},...Array.isArray(h.verdicts)&&h.verdicts.length>0?[{label:"Learned from",value:`${h.verdicts.length} ${h.verdicts.length===1?"decision":"decisions"}`}]:[]]}):null]})})}function kD(e){return e.length>1?"small or medium":`${e[0]} only`}function rie(e){return["small","medium"].filter(n=>e.includes(n))}function ND({widget:e,size:n,svg:s}){var a;const r=(a=e.preview)==null?void 0:a[n];return t.jsxs("div",{className:"wg-frame","data-variant":"preview","data-size":n,"data-kind":r==null?void 0:r.kind,role:"img","aria-label":`${e.title}, ${n}: ${r?"a preview with sample data":"no preview"}`,children:[t.jsxs("div",{className:"wg-head",children:[t.jsx("span",{className:"wg-title",children:e.title}),r?t.jsx("span",{className:"wg-sample",children:"Sample"}):null]}),t.jsx("div",{className:"wg-body",children:r?t.jsx(Ap,{body:r,size:n}):t.jsxs("span",{className:"wg-state",children:[t.jsx(ss,{svg:s}),t.jsx("span",{className:"wg-state-sub",children:"No preview from this plugin."})]})})]})}function aie(e){const n=[{label:"Home",path:e.home}];if(e.path===e.home||!e.path.startsWith(`${e.home}/`))return n;let s=e.home;for(const r of e.path.slice(e.home.length+1).split("/"))s=`${s}/${r}`,n.push({label:r,path:s});return n}function iie({start:e,onPick:n,onClose:s}){const[r,a]=d.useState(null),[i,l]=d.useState(null),[o,c]=d.useState(""),u=(p,x=!1)=>{l(null),T.pluginFolders(p).then(g=>{a(g),c("")}).catch(g=>{x&&p!==void 0?u(void 0):l(g instanceof pe?g.message:String(g))})};d.useEffect(()=>{u(e,!0)},[]);const h=o.trim().toLowerCase(),m=((r==null?void 0:r.folders)??[]).filter(p=>h===""||p.name.toLowerCase().includes(h)),f=r?aie(r):[];return t.jsxs(Ye,{title:"Choose the folder",onClose:s,foot:t.jsxs(te,{children:[t.jsx("span",{className:"plugins-foot-note mono",children:(r==null?void 0:r.path)??""}),t.jsx(ht,{}),t.jsx($,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:!r,onClick:()=>r&&n(r.path),children:"Use this folder"})]}),children:[t.jsx("p",{className:"plugins-note",children:"Folders on the computer buddi runs on, inside your home directory. The one you want holds the plugin's package.json and is already built."}),r?t.jsx(Zc,{label:"Folder",items:f.map((p,x)=>x===f.length-1?{key:p.path,label:p.label,current:!0}:{key:p.path,label:p.label,onClick:()=>u(p.path)})}):null,t.jsx(fp,{label:"Find a folder here",value:o,placeholder:"Find a folder here…",onChange:c}),t.jsx(re,{message:i}),r?m.length===0?t.jsx(Ee,{children:h===""?"No folders in here.":`No folder here is called anything like “${o.trim()}”.`}):t.jsx(lt,{flush:!0,children:t.jsx(yt,{children:m.map(p=>t.jsx(pt,{onClick:()=>u(p.path),label:`Open ${p.name}`,lead:t.jsx(ss,{icon:"folder"}),title:p.name,side:p.plugin?t.jsx($e,{tone:"accent",children:"package.json"}):void 0},p.path))})}):i?null:t.jsx(Ee,{children:"Reading the folders…"}),r!=null&&r.truncated?t.jsx("p",{className:"plugins-note",children:"Only the first 500 folders are listed; find one by name above."}):null]})}const lie="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 TE(){return t.jsxs("p",{className:"plugins-quiet connections-quiet",children:[t.jsx(ne,{name:"globe",size:14}),t.jsxs("span",{children:["A plugin is code buddi installs and runs; a connection is a service or program buddi talks to."," ",t.jsx("a",{href:ze("connections"),children:"Connections"})]})]})}const oie=1500,SD={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."},cie="Restart buddi to apply it. In a checkout, stop it and run: buddi serve",CD=[{value:"npm",label:"From npm"},{value:"file",label:"A file"},{value:"directory",label:"A directory I built"}],ED="buddi.plugins.install-mode";function uie(){try{const e=window.localStorage.getItem(ED);if(CD.some(n=>n.value===e))return e}catch{}return"npm"}function die(e){try{window.localStorage.setItem(ED,e)}catch{}}const Ch=".tgz",ra=(e,n,s)=>`${e} ${e===1?n:s}`;function AD(e){const n=[];return e.tools>0&&n.push(ra(e.tools,"tool","tools")),e.sentinels>0&&n.push(`${e.sentinels} on a timer`),e.views>0&&n.push(ra(e.views,"view","views")),e.agents>0&&n.push(`${ra(e.agents,"agent","agents")} proposed`),n.length===0?"nothing on its own":n.join(", ")}function ky(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 $D(e){return e.kind==="registry"?"npm":e.kind==="tarball"?"a file":"a directory"}function Lk(e,n){return e.kind==="directory"?"you, from this machine":e.kind==="tarball"?"a file on this machine":n??"nobody npm will name"}function TD(e){return e.author?e.author.name:e.source.kind==="registry"?e.publisher??"nobody npm will name":"you"}function Ip({author:e}){return e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",children:e.name}):t.jsx(t.Fragment,{children:e.name})}function Ny({value:e}){return e===void 0||e===""?t.jsx("span",{className:"muted",children:"none — this came off a disk"}):t.jsx("span",{className:"plugins-hash",children:e})}function RD(e){return e.length===0?"none; nothing leaves this computer":t.jsx("span",{className:"mono",children:e.join(", ")})}function Fk(e){return e.length===0?"Nothing beyond its own tables, its own folder and its own tools' approvals.":e.map(n=>`It ${n.words}.`).join(" ")}const La=e=>e instanceof pe?e.message:String(e);function hie(e){const[n,s]=d.useState(void 0),[r,a]=d.useState(null);return d.useEffect(()=>{if(!e){s(void 0),a(null);return}let i=!1;a(null),s(void 0);const l=()=>{i||T.pluginJob(e).then(c=>{i||(s(c),(c.phase==="done"||c.phase==="failed")&&(i=!0))}).catch(c=>{i||(a(La(c)),i=!0)})};l();const o=window.setInterval(l,oie);return()=>{i=!0,window.clearInterval(o)}},[e]),{job:(n==null?void 0:n.id)===e?n:void 0,error:r}}function fie({plugin:e,pages:n,navigate:s,variant:r}){const a=n.filter(i=>i.plugin===e);return a.length===0?null:t.jsx(t.Fragment,{children:a.map(i=>{const l=Mr(i.plugin,i.id);return t.jsx(it,{size:"sm",variant:r,href:l,"aria-label":`Open ${i.title}`,onClick:o=>{o.stopPropagation(),s&&(o.preventDefault(),s(l))},children:a.length===1?"Open":`Open ${i.title}`},i.id)})})}const mie="buddi was updated and this plugin needs relinking. Restart buddi to repair it.";function ID({plugin:e}){var s;if(e.enabled===!1)return t.jsx($e,{children:"disabled"});const n=(s=e.needs)==null?void 0:s[0];return n?t.jsxs($e,{tone:"warning",children:["needs ",n.plugin]}):e.loadsAtRestart?t.jsx($e,{tone:"accent",children:"Waiting for restart"}):e.loaded&&e.setup?t.jsx($e,{tone:"warning",children:"needs setup"}):e.loaded?t.jsx($e,{tone:"good",dot:!0,children:"loaded"}):t.jsx($e,{tone:"critical",children:"did not load"})}function _k({entry:e}){var n;return e.trust==="by-buddi"?t.jsx($e,{tone:"accent",children:"by buddi"}):t.jsxs($e,{tone:"good",children:["reviewed ",((n=e.reviewed)==null?void 0:n.version)??e.version]})}const Sy=ze("plugins"),Eh={installed:Sy,browse:`${Sy}?tab=browse`};function pie({railPages:e=[],settingsPages:n=[],navigate:s,hash:r=""}={}){const a=je(()=>T.plugins(),[],2e4),[i,l]=d.useState(null),{job:o,error:c}=hie(i),[u,h]=d.useState(null),[m,f]=d.useState(()=>FS(r));d.useEffect(()=>f(FS(r)),[r]);const[p,x]=d.useState(()=>LS(r));d.useEffect(()=>x(LS(r)),[r]);const[g,w]=d.useState(null),[v,j]=d.useState(null),[y,k]=d.useState(null),[N,b]=d.useState(null),[S,C]=d.useState(!1),A=ce=>{C(!0),T.market(ce).then(b).catch(Me=>b({plugins:[],unavailable:La(Me)})).finally(()=>C(!1))};d.useEffect(()=>{m==="browse"&&N===null&&!S&&A(!1)},[m]);const E=ce=>{h(null),l(ce),F(!0),z(null)},R=ce=>h(La(ce)),[P,O]=d.useState(!1),[I,F]=d.useState(!1),[U,L]=d.useState("plugin"),[M,z]=d.useState(null),D=P||!c&&i!==null&&(!o||o.phase!=="done"&&o.phase!=="failed"),K=(ce,Me="plugin")=>{O(!0),h(null),l(null),z(null),L(Me),F(!0),w(null),ce.then(tt=>{l(tt.job.id)}).catch(R).finally(()=>O(!1))},B=d.useRef(null);d.useEffect(()=>{const ce=lW(r);if(!(ce===null||B.current===ce)){B.current=ce,f("installed"),K(T.stagePlugin(ce));try{window.history.replaceState(window.history.state,"",Sy)}catch{}}},[r]);const se=ce=>Me=>{Me.preventDefault(),f(ce),w(null),s==null||s(Eh[ce])};d.useEffect(()=>{((o==null?void 0:o.phase)==="done"||(o==null?void 0:o.phase)==="failed")&&a.reload()},[o==null?void 0:o.phase]);const W=a.data,xe=W?!W.canRestart:!0,me=(W==null?void 0:W.installed)??[],ie=ce=>N==null?void 0:N.plugins.find(Me=>Me.installed!==void 0&&(Me.installed.name??Me.name)===ce.name),H=ce=>e.some(Me=>Me.plugin===ce),de=(ce,Me)=>H(ce)?t.jsx(fie,{plugin:ce,pages:e,navigate:s,variant:Me}):void 0,ge=ce=>{const Me=e.find(tt=>tt.plugin===ce);Me&&s&&s(Mr(Me.plugin,Me.id))},Ue=ce=>{const Me=n.find(tt=>tt.plugin===ce);if(!(!Me||!s))return()=>s(Or(Me.plugin,Me.id))},G=((N==null?void 0:N.plugins)??[]).filter(ce=>ce.update).length,ae=(ce,Me)=>T.setPluginEnabled(ce,Me).then(tt=>{jb(),k({name:ce,notes:tt.notes??[]}),a.reload()}),J=(ce,Me,tt)=>T.uninstallPlugin(ce,Me?{purge:!0,confirm:tt}:{}).then(Tt=>{w(null),k({name:ce,notes:Tt.notes??[]}),a.reload()}),Ne=ce=>{h(null),ae(ce,!0).catch(R)},Ie=(ce,Me)=>{const tt=N==null?void 0:N.plugins.find(bt=>{var Pe;return(((Pe=bt.installed)==null?void 0:Pe.name)??bt.name)===ce&&bt.installed!==void 0}),Tt=tt&&Me?`${tt.npm}@${Me}`:void 0;K(Tt?T.updatePlugin(ce,Me,Tt):T.updatePlugin(ce,Me),ce)},Y=ce=>{h(null);const Me=tt=>{const Tt=tt.plugins.find(bt=>{var Pe;return bt.name===ce||((Pe=bt.installed)==null?void 0:Pe.name)===ce});if(!Tt){h(`${ce} is not listed on withbuddi.com. Add it from npm, a file or a directory above, then install this one.`);return}K(T.stagePlugin(`${Tt.npm}@${Tt.version}`),Tt.name)};if(N&&N.plugins.length>0)return Me(N);O(!0),T.market(!1).then(tt=>{b(tt),Me(tt)}).catch(R).finally(()=>O(!1))},X=(ce,Me)=>Me===void 0?void 0:Me.place==="settings"?Or(ce,Me.id):Mr(ce,Me.id),oe=ce=>{var tt;if(ce.enabled===!1)return;const Me=(tt=ce.needs)==null?void 0:tt[0];if(Me)switch(Me.state){case"missing":return{label:`Install ${Me.plugin}`,run:()=>Y(Me.plugin)};case"disabled":return{label:`Enable ${Me.plugin}`,run:()=>Ne(Me.plugin)};case"range":return{label:`Update ${Me.plugin}`,run:()=>Ie(Me.plugin)};case"setup":{const Tt=X(Me.plugin,Me.page),bt=Tt&&s?()=>s(Tt):Ue(Me.plugin);return bt?{label:`Set up ${Me.plugin}`,run:bt}:void 0}default:return{label:`See ${Me.plugin}`,run:()=>w({kind:"installed",name:Me.plugin})}}if(ce.loaded&&ce.setup){const Tt=X(ce.name,ce.setup.page),bt=Tt&&s?()=>s(Tt):Ue(ce.name);return bt?{label:"Set it up",run:bt}:void 0}},ve=t.jsxs(ic,{label:"Plugins",children:[t.jsx(ml,{href:Eh.installed,active:m==="installed",count:G,onClick:se("installed"),children:"Installed"}),t.jsx(ml,{href:Eh.browse,active:m==="browse",onClick:se("browse"),children:"Browse"})]}),be=(W==null?void 0:W.staged)??[],Ce=bie(be,(o==null?void 0:o.phase)==="done"?o.stagedId:void 0),we=be.find(ce=>ce.id===Ce),He=be.filter(ce=>ce.id!==Ce),Ze=ce=>{w(null),kie(ce),f("installed"),s==null||s(Eh.installed),z(ce),L(ce),F(!0),N&&A(!1),l(null),a.reload()},Se=(g==null?void 0:g.kind)==="staged"?be.find(ce=>ce.id===g.name):void 0,Le=(g==null?void 0:g.kind)==="installed"?me.find(ce=>ce.name===g.name):void 0,Ve=(g==null?void 0:g.kind)==="market"?N==null?void 0:N.plugins.find(ce=>ce.name===g.name):void 0,Qe=y&&!(Le&&Le.name===y.name)&&y.notes.length>0?y.notes:null,wt=Se?t.jsx(RE,{staged:Se,onClose:()=>w(null),onInstalled:Ze,onInstallFirst:Y,onGone:()=>{w(null),a.reload()}},Se.id):Le?t.jsx(Tie,{plugin:Le,listing:ie(Le),notes:(y==null?void 0:y.name)===Le.name?y.notes:null,canOpen:H(Le.name)&&Le.enabled!==!1,onOpen:()=>ge(Le.name),onClose:()=>w(null),onDisable:()=>j({kind:"disable",name:Le.name}),onEnable:()=>Ne(Le.name),onRemove:()=>j({kind:"remove",name:Le.name}),onUpdate:ce=>Ie(Le.name,ce),onSettings:Le.enabled===!1?void 0:Ue(Le.name),firstStep:oe(Le),onRestart:xe?void 0:()=>rc({kind:"plugins",line:`Repairing ${Le.name}…`},()=>T.serviceAction("restart")),busy:D}):Ve?t.jsx(Fie,{entry:Ve,canOpen:Ve.installed!==void 0&&H(Ve.installed.name??Ve.name),onOpen:()=>{var ce;return ge(((ce=Ve.installed)==null?void 0:ce.name)??Ve.name)},onClose:()=>w(null),onInstall:()=>K(T.stagePlugin(`${Ve.npm}@${Ve.version}`),Ve.name),onUpdate:ce=>{var Me;return Ie(((Me=Ve.installed)==null?void 0:Me.name)??Ve.name,ce)},busy:D}):null,dt=()=>F(!1),qt=(o==null?void 0:o.phase)==="done"&&o.stagedId?be.find(ce=>ce.id===o.stagedId):void 0,vt=I?M?t.jsx(kx,{checkout:xe,waiting:me.filter(ce=>ce.name===M),installedName:M,onClose:dt}):qt?t.jsx(RE,{staged:qt,onClose:dt,onInstalled:Ze,onGone:()=>{dt(),l(null),a.reload()},onInstallFirst:Y},qt.id):t.jsx(Ye,{title:`${(o==null?void 0:o.kind)==="update"?"Check":"Install"} ${U}`,onClose:dt,foot:t.jsxs(te,{children:[t.jsx(ht,{}),t.jsx($,{onClick:dt,children:"Close"})]}),children:t.jsxs(ue,{gap:"lg",children:[u||c||a.error||(o==null?void 0:o.phase)==="failed"?t.jsx(re,{message:u??c??a.error??(o==null?void 0:o.error)??"Preparation failed. Close and try again."}):o!=null&&o.upToDate?t.jsx(Q,{role:"status",children:o.upToDate}):t.jsxs("div",{className:"plugins-preparing",role:"status","aria-live":"polite","aria-busy":"true",children:[t.jsx("span",{className:"plugins-spinner","aria-hidden":"true"}),t.jsx("strong",{children:o?SD[o.phase]:"Preparing the package…"})]}),D?t.jsx("p",{className:"plugins-quiet",children:"You can close this panel. Preparation continues, and the review will wait in Plugins."}):null,o!=null&&o.upToDate&&(W!=null&&W.restartNeeded)?t.jsx(kx,{checkout:xe,waiting:me.filter(ce=>ce.loadsAtRestart)}):null]})}):null,Dt=v?me.find(ce=>ce.name===v.name):void 0,bn=v?t.jsx(Rie,{kind:v.kind,name:v.name,canDisable:(Dt==null?void 0:Dt.enabled)!==!1,onCancel:()=>j(null),onDisableInstead:()=>j({kind:"disable",name:v.name}),onDisable:()=>ae(v.name,!1).then(()=>j(null)),onRemove:(ce,Me)=>J(v.name,ce,Me).then(()=>j(null))},`${v.kind}:${v.name}`):null;if(m==="browse")return t.jsxs(ue,{gap:"lg",children:[t.jsx(TE,{}),ve,t.jsx(re,{message:u}),t.jsx(Wie,{kind:p,onKind:x,navigate:s,market:N,loading:S,busy:D,onRetry:()=>A(!0),onOpen:ce=>w({kind:"market",name:ce.name}),onInstall:ce=>K(T.stagePlugin(`${ce.npm}@${ce.version}`),ce.name),onUpdate:(ce,Me)=>{var tt;return Ie(((tt=ce.installed)==null?void 0:tt.name)??ce.name,Me)}}),wt,vt]});const sn=(W==null?void 0:W.builtIn)??[];return t.jsxs(ue,{gap:"lg",children:[t.jsx(TE,{}),ve,t.jsx(re,{message:a.error??u??c}),W!=null&&W.unavailable?t.jsx(Q,{tone:"warning",children:W.unavailable}):null,Qe?t.jsx(Q,{role:"status",children:Qe.join(" ")}):null,t.jsx(gie,{trust:(W==null?void 0:W.trust)??"",job:o,busy:D,onStaged:E,onFailed:h}),we&&!I?t.jsx(vie,{staged:we,onInstalled:Ze,onGone:()=>a.reload(),onInstallFirst:Y},we.id):null,He.length>0?t.jsx(lt,{flush:!0,title:"Waiting for you",tool:ra(He.length,"package","packages"),children:t.jsx("div",{className:"plugins-rows",children:t.jsx(yt,{children:He.map(ce=>t.jsx(yie,{staged:ce,onReview:()=>{zk(ce),w({kind:"staged",name:ce.id})},onReject:()=>{h(null),T.rejectStaged(ce.id).then(()=>a.reload()).catch(R)}},ce.id))})})}):null,W!=null&&W.restartNeeded?t.jsx(kx,{checkout:xe,waiting:me.filter(ce=>ce.loadsAtRestart)}):null,t.jsx(Sie,{list:me,firstStepFor:oe}),t.jsx(lt,{flush:!0,title:"Installed",tool:W?ra(me.length,"plugin","plugins"):void 0,children:W?me.length===0?t.jsx(Ee,{children:"Nothing installed yet. Only what buddi ships with is here."}):t.jsx("div",{className:"plugins-rows",children:t.jsx(yt,{children:me.map(ce=>t.jsx(Eie,{plugin:ce,listing:ie(ce),open:ce.enabled===!1?void 0:de(ce.name,"ghost"),canOpen:H(ce.name)&&ce.enabled!==!1,busy:D,onDetails:()=>w({kind:"installed",name:ce.name}),onOpen:()=>ge(ce.name),onSettings:ce.enabled===!1?void 0:Ue(ce.name),onDisable:()=>j({kind:"disable",name:ce.name}),onEnable:()=>Ne(ce.name),onRemove:()=>j({kind:"remove",name:ce.name}),onUpdate:Me=>Ie(ce.name,Me),firstStep:oe(ce)},ce.name))})}):t.jsx(Ee,{children:"Loading…"})}),sn.length>0?t.jsx(Iie,{plugins:sn,openFor:de}):null,wt,vt,bn]})}function gie({trust:e,job:n,busy:s,onStaged:r,onFailed:a}){const[i,l]=d.useState(uie),[o,c]=d.useState(""),[u,h]=d.useState(!1),[m,f]=d.useState(null),[p,x]=d.useState(null),[g,w]=d.useState(!1),[v,j]=d.useState(!1),y=d.useRef(null),k=C=>a(La(C)),N=C=>{l(C),die(C),x(null)},b=()=>{h(!0),T.stagePlugin(o.trim()).then(C=>{r(C.job.id),c("")}).catch(k).finally(()=>h(!1))},S=C=>{if(C){if(!C.name.toLowerCase().endsWith(Ch)){f(null),x(`${C.name} is not a ${Ch}. A packed plugin is the file npm pack writes.`);return}x(null),f(C.name),h(!0),T.uploadPlugin(C).then(A=>r(A.job.id)).catch(k).finally(()=>h(!1))}};return t.jsxs(lt,{title:"Add a plugin",actions:t.jsx(cn,{label:"Where it comes from",options:CD,value:i,onChange:N}),children:[t.jsxs("div",{className:"plugins-add",children:[i==="file"?t.jsxs("div",{className:"plugins-drop",role:"group","aria-label":"A plugin file","data-state":g?"over":p?"refused":m?"chosen":void 0,onDragOver:C=>{C.preventDefault(),w(!0)},onDragLeave:()=>w(!1),onDrop:C=>{var A,E;C.preventDefault(),w(!1),S((E=(A=C.dataTransfer)==null?void 0:A.files)==null?void 0:E[0])},children:[t.jsx(ne,{name:"drop",size:20}),t.jsx("span",{className:"plugins-drop-text",children:p??(m?`${m} — reading it.`:t.jsxs(t.Fragment,{children:["Drop a ",t.jsx("span",{className:"mono",children:Ch})," here: the file ",t.jsx("span",{className:"mono",children:"npm pack"})," ","writes. It is read the moment it lands."]}))}),t.jsx($,{variant:"accent",disabled:s||u,onClick:()=>{var C;return(C=y.current)==null?void 0:C.click()},children:"Choose a file"}),t.jsx("input",{ref:y,type:"file",accept:Ch,hidden:!0,"aria-hidden":"true",tabIndex:-1,onChange:C=>{var A;S((A=C.target.files)==null?void 0:A[0]),C.target.value=""}})]}):t.jsxs("div",{className:"plugins-add-row",children:[t.jsxs(te,{valign:"end",children:[t.jsx(le,{grow:!0,label:i==="npm"?"Package":"The directory it is in",children:t.jsx("input",{type:"text",value:o,placeholder:i==="npm"?"buddi-plugin-weather":"/home/you/code/buddi-plugin-weather",onChange:C=>c(C.target.value)})}),i==="directory"?t.jsx($,{onClick:()=>j(!0),children:"Browse…"}):null,t.jsx($,{variant:"accent",disabled:s||u||o.trim()==="",onClick:b,children:"Read it first"})]}),t.jsx("span",{className:"ui-field-hint",children:i==="npm"?"A package name, or a name@version. Reading fetches it and hashes it; nothing of it runs.":"The folder with its package.json, already built. Nothing of it runs until you say yes."})]}),n?t.jsxs("p",{className:"plugins-status",role:"status","data-tone":n.phase==="failed"?"critical":void 0,children:[n.upToDate??SD[n.phase]," ",n.error??""]}):null,t.jsx("div",{className:"plugins-trust",children:t.jsx(Q,{tone:"warning",children:e})})]}),v?t.jsx(iie,{start:o.trim().startsWith("/")?o.trim():void 0,onClose:()=>j(!1),onPick:C=>{c(C),j(!1)}}):null]})}function xie({staged:e}){var r,a;const n=((r=e.uses)==null?void 0:r.areas)??[],s=((a=e.uses)==null?void 0:a.dropped)??[];return t.jsxs("span",{className:"plugins-uses",children:[n.length===0?Fk([]):n.map(i=>t.jsxs("span",{children:["It ",i.words,". ",i.added?t.jsxs($e,{tone:"warning",children:["new in ",e.version]}):null]},i.use)),s.length>0?t.jsxs("span",{className:"muted",children:["No longer: ",s.map(i=>i.words).join("; "),"."]}):null]})}function PD(e,n,s){const[r,a]=d.useState(e.plan??null),[i,l]=d.useState(!1),[o,c]=d.useState(null);return{plan:r,busy:i,failed:o,approve:m=>{l(!0),c(null),T.approveStaged(e.id,{integrity:e.integrity??"",...m?{acknowledgeDrift:!0}:{}}).then(f=>{f.installed?n(f.installed.name):f.plan&&a(f.plan)}).catch(f=>c(La(f))).finally(()=>l(!1))},reject:()=>{l(!0),c(null),T.rejectStaged(e.id).then(()=>s()).catch(m=>c(La(m))).finally(()=>l(!1))}}}function zk(e){e.openedAt||T.openedStaged(e.id).catch(()=>{})}function jie({staged:e,onInstallFirst:n}){return t.jsxs("span",{className:"plugins-requires",children:[(e.requires??[]).map(s=>t.jsxs("span",{className:"plugins-require",children:[t.jsxs("span",{title:s.range,children:[t.jsx("span",{className:"mono",children:s.plugin})," ",s.rangeWords??s.range]}),s.state==="ok"?t.jsx("span",{className:"plugins-require-ok",children:s.installed?`${s.installed} is here`:"here"}):s.state==="missing"?t.jsxs(t.Fragment,{children:[t.jsx($e,{tone:"warning",children:"not installed"}),n?t.jsxs($,{size:"sm",onClick:()=>n(s.plugin),children:["Install ",s.plugin," first"]}):null]}):t.jsx($e,{tone:"warning",children:s.state==="disabled"?"disabled here":s.state==="range"?`${s.installed??"another version"} is here`:s.state==="failed"?"did not load here":"waiting here"})]},s.plugin)),(e.requires??[]).some(s=>s.state!=="ok")?t.jsx("span",{className:"muted",children:"It installs either way, and waits — tools and widgets off, nothing lost — until each is here and set up."}):null]})}function MD({staged:e,onInstallFirst:n}){var r,a;const s=e.dependencies;return t.jsxs(ue,{gap:"lg",children:[t.jsx("p",{className:"plugins-summary",children:e.claims.missing?"Review this plugin’s access before installing.":t.jsxs(t.Fragment,{children:["Excerpt from the author’s description: ",(r=e.claims.text.split(/\n\s*\n/).find(i=>i.trim()&&!i.trim().startsWith("#")))==null?void 0:r.slice(0,320)]})}),t.jsx(ye,{title:"What it accesses",children:t.jsx(xie,{staged:e})}),(e.requires??[]).length>0?t.jsx(jie,{staged:e,onInstallFirst:n}):null,t.jsxs(Vt,{summary:"Read full description",boxed:!0,children:[t.jsx("p",{className:"plugins-quiet",children:"Written by the plugin’s author. These are its claims."}),t.jsx(pr,{text:e.claims.missing?"No description provided.":e.claims.text})]}),t.jsx(Vt,{summary:"Technical details",boxed:!0,children:t.jsx("div",{className:"plugins-facts",children:t.jsx(on,{items:[...e.author?[{label:"By",value:t.jsx(Ip,{author:e.author})}]:[],{label:"From",value:e.uploadedName?`a file you chose · ${e.uploadedName}`:ky(e.source)},{label:"Published by",value:Lk(e.source,e.publisher)},...e.previousSource&&e.previous?[{label:"Replaces",value:`${e.previous.version}, installed from ${ky(e.previousSource)}`}]:e.source.kind==="directory"&&((a=e.previous)==null?void 0:a.version)===e.version?[{label:"Reinstalls",value:`${e.version}, the same version, its files read again from the folder`}]:[],...e.source.kind==="directory"?[]:[{label:"Installs as",value:e.installsAs?t.jsx("span",{className:"mono",children:e.installsAs}):"the name its manifest gives, read when you approve — it declares no buddi.name"}],...e.coreAsDependency?[{label:"Core",value:"It asks npm for buddi's core; buddi provides its own."}]:[],{label:"Dependencies",value:s.count===0?"none":`${s.count}${s.withScripts.length===0?", none of which run install scripts":`, of which these run install scripts: ${s.withScripts.join(", ")}`}`},{label:"Schema it owns",value:e.claims.schema??"it claims none"},{label:"Hosts it reaches",value:e.claims.hosts.join(", ")||"it claims none"},{label:"Integrity",value:t.jsx(Ny,{value:e.integrity})},...e.stagedHash?[{label:"Files on disk",value:t.jsx(Ny,{value:e.stagedHash})}]:[]]})})})]})}function OD({plan:e,busy:n,onReject:s,onInstallAnyway:r}){return t.jsxs(Br,{tone:"warning",title:"What it said, and what it does",meta:t.jsx($e,{tone:"warning",children:"read this first"}),foot:t.jsxs(te,{children:[t.jsx("span",{className:"plugins-foot-note",children:"Install anyway says you read these."}),t.jsx(ht,{}),t.jsx($,{variant:"ghost",disabled:n,onClick:s,children:"Not this one"}),t.jsx($,{variant:"danger",disabled:n,onClick:r,children:"Install anyway"})]}),children:[t.jsx("p",{className:"plugins-note",children:"Its prose and its manifest do not agree. Neither is authoritative; the manifest is what actually runs."}),t.jsx("ul",{className:"plugins-drift",children:e.drift.map(a=>t.jsx("li",{children:a},a))}),t.jsx(DD,{unlocks:e.agents??[]})]})}function vie({staged:e,onInstalled:n,onGone:s,onInstallFirst:r}){const{plan:a,busy:i,failed:l,approve:o,reject:c}=PD(e,n,s);d.useEffect(()=>zk(e),[e.id]);const u=(a==null?void 0:a.drift)??[];return t.jsxs(ue,{gap:"sm",children:[t.jsxs(Br,{tone:"accent",title:t.jsxs(t.Fragment,{children:[e.name," ",t.jsx("span",{className:"plugins-ver",children:e.version})]}),meta:t.jsx($e,{children:"read, not installed"}),foot:t.jsxs(te,{children:[t.jsx("span",{className:"plugins-foot-note",children:"Nothing of it has run."}),t.jsx(ht,{}),t.jsx($,{variant:"ghost",disabled:i,onClick:c,children:"Not this one"}),t.jsx($,{variant:"accent",disabled:i||u.length>0,onClick:()=>o(!1),children:"Install"})]}),children:[t.jsx(re,{message:l}),t.jsx(MD,{staged:e,onInstallFirst:r})]}),a&&u.length>0?t.jsx(OD,{plan:a,busy:i,onReject:c,onInstallAnyway:()=>o(!0)}):null]})}function yie({staged:e,onReview:n,onReject:s}){const r=Xe(e.createdAt);return t.jsx(pt,{onClick:n,label:`${e.name}: review`,lead:t.jsx(ss,{svg:void 0}),title:t.jsxs(t.Fragment,{children:[e.name," ",t.jsx("span",{className:"plugins-ver",children:e.version})]}),sub:`from ${$D(e.source)}${r?` · read ${r}`:""}`,side:t.jsxs("span",{className:"plugins-side",children:[t.jsxs("span",{className:"plugins-wait-extra",children:[t.jsx($e,{children:"read, not installed"}),t.jsx($,{size:"sm",variant:"ghost",onClick:_o(s),children:"Not this one"})]}),t.jsx($,{size:"sm",onClick:_o(n),children:"Review"})]})})}function RE({staged:e,onClose:n,onInstalled:s,onGone:r,onInstallFirst:a}){const{plan:i,busy:l,failed:o,approve:c,reject:u}=PD(e,s,r),h=(i==null?void 0:i.drift)??[];return d.useEffect(()=>zk(e),[e.id]),t.jsxs(Ye,{scrollBody:!0,title:t.jsx(Wk,{svg:void 0,name:e.installsAs??e.name,version:e.version,by:e.author?t.jsx(Ip,{author:e.author}):Lk(e.source,e.publisher),pills:t.jsxs(t.Fragment,{children:[" · ",t.jsx($e,{children:"read, not installed"})]})}),onClose:l?()=>{}:n,foot:t.jsxs(te,{children:[t.jsx("span",{className:"plugins-foot-note",children:l?"Installing…":"Nothing of it has run."}),t.jsx(ht,{}),t.jsx($,{variant:"ghost",disabled:l,onClick:u,children:"Not this one"}),t.jsx($,{variant:"accent",disabled:l||h.length>0,onClick:()=>c(!1),children:l?"Installing…":`Install ${e.installsAs??e.name}`})]}),children:[t.jsx(re,{message:o}),t.jsx(MD,{staged:e,onInstallFirst:a}),t.jsx(Q,{tone:"warning",children:"Only install plugins from people you trust. A plugin runs with buddi’s access to this computer and can bypass tool approvals."}),i&&h.length>0?t.jsx(OD,{plan:i,busy:l,onReject:u,onInstallAnyway:()=>c(!0)}):null]})}const wie=10*60*1e3;function bie(e,n,s=Date.now()){if(n&&e.some(i=>i.id===n))return n;const r=[...e].sort((i,l)=>(l.createdAt??"").localeCompare(i.createdAt??""))[0];if(!(r!=null&&r.createdAt))return null;const a=s-Date.parse(r.createdAt);return Number.isFinite(a)&&a<wie?r.id:null}function kx({checkout:e,waiting:n,installedName:s,onClose:r}){const[a,i]=d.useState(!1),[l,o]=d.useState(null),c=C8(n)||s,u=c?`${c} ${n.length<=1?"is":"are"} installed.`:"A plugin was installed, disabled or enabled since buddi started, and this buddi has not caught up.",h=e?void 0:t.jsx($,{size:"sm",variant:"accent",disabled:a,onClick:()=>{i(!0),o(null),rc({kind:"plugins",...c?{line:`Loading ${c}…`}:{line:"Applying your plugin changes…"}},()=>T.serviceAction("restart")).catch(f=>o(La(f))).finally(()=>i(!1))},children:"Restart to finish"}),m=t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{message:l}),t.jsxs(Q,{tone:e?"warning":"accent",role:"status",action:r?void 0:h,children:[u," ",e?cie:`${c?n.length<=1?"Its tools appear":"Their tools appear":"It takes effect"} once buddi restarts, which takes a few seconds. This page waits and comes back by itself.`]})]});return r?t.jsx(Ye,{title:`${s??"Plugin"} is installed`,onClose:r,scrollBody:!0,foot:t.jsxs(te,{children:[t.jsx(ht,{}),t.jsx($,{onClick:r,children:"Later"}),h]}),children:m}):m}const Uk="buddi.plugins.justInstalled";function kie(e){try{window.sessionStorage.setItem(Uk,e)}catch{}}function Nie(){try{return window.sessionStorage.getItem(Uk)}catch{return null}}function Sie({list:e,firstStepFor:n}){var u;const[s,r]=d.useState(()=>Nie()),a=s?e.find(h=>h.name===s):void 0,i=a!==void 0&&(a.loaded||a.needs!==void 0),l=i&&(a.needs!==void 0||a.setup!==void 0),o=()=>{try{window.sessionStorage.removeItem(Uk)}catch{}r(null)};if(d.useEffect(()=>{i&&!l&&o()},[i,l]),!a||!l)return null;const c=n(a);return t.jsx(Ye,{title:`${a.name} is ready to set up`,onClose:o,scrollBody:!0,foot:t.jsxs(te,{children:[t.jsx(ht,{}),t.jsx($,{size:"sm",variant:"ghost",onClick:o,children:"Later"}),c?t.jsx($,{size:"sm",variant:"accent",onClick:()=>{o(),c.run()},children:c.label}):null]}),children:t.jsx(Q,{tone:"accent",role:"status",children:a.needs?`${a.name} is installed and waits. ${Bk(a)}.`:`${a.name} is loaded. First: ${((u=a.setup)==null?void 0:u.note)??"set it up on its settings page."}`})})}const _o=e=>n=>{n.stopPropagation(),e()},Cie=e=>e.unlocks.filter(n=>n.drift.state==="not-accepted").length;function Bk(e){var n;return e.needs&&e.needs.length>0?e.needs.map(s=>s.state==="setup"&&s.note?`${s.words}: ${s.note}`:s.words).join(" · "):((n=e.setup)==null?void 0:n.note)??"Not set up yet. Its settings say what it needs."}function Eie({plugin:e,listing:n,open:s,canOpen:r,busy:a,onDetails:i,onOpen:l,onSettings:o,onDisable:c,onEnable:u,onRemove:h,onUpdate:m,firstStep:f}){const p=e.enabled===!1,x=Cie(e),g=!p&&(e.needs!==void 0||e.loaded&&e.setup!==void 0);return t.jsx(pt,{onClick:i,label:`${e.name}: details`,dimmed:p,lead:t.jsx(ss,{svg:n==null?void 0:n.iconSvg}),title:t.jsxs(t.Fragment,{children:[e.name," ",t.jsx("span",{className:"plugins-ver",children:e.version}),x>0?t.jsxs("span",{className:"plugins-ask",children:[ra(x,"agent","agents")," to accept"]}):null]}),sub:g?t.jsx("span",{className:"plugins-sub","data-tone":"warning",children:Bk(e)}):`by ${TD(e)} · from ${$D(e.source)} · ${e.loadsAtRestart?"Ready to load after restart":AD(e.contribution)}`,side:t.jsxs("span",{className:"plugins-side",children:[g&&f?t.jsx($,{size:"sm",onClick:_o(f.run),children:f.label}):null,n!=null&&n.update?t.jsxs($,{size:"sm",disabled:a,onClick:_o(()=>m(n.update)),children:["Update to ",n.update]}):null,g?null:s,!g&&!r&&o?t.jsx($,{size:"sm",variant:"ghost",onClick:w=>{w.stopPropagation(),o()},children:"Settings"}):null,t.jsx(ID,{plugin:e}),t.jsx(rs,{label:`More for ${e.name}`,items:[{label:"Details",onSelect:i},r?{label:"Open its page",onSelect:l}:null,o?{label:"Its settings",onSelect:o}:null,e.source.kind==="directory"&&!a?{label:"Reinstall from folder",hint:"reads its files again",onSelect:()=>m()}: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 Aie={"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 DD({plugin:e,unlocks:n}){return n.length===0?null:t.jsxs(ye,{title:"Agents it would unlock",children:[t.jsx("div",{className:"plugins-unlocks",children:t.jsx(yt,{children:n.map(s=>t.jsx($ie,{plugin:e,unlock:s},s.id))})}),t.jsxs("p",{className:"plugins-note",children:["Nothing here is created by installing. Accept creates the agent with the tools listed; change or remove it"," ",t.jsx("a",{href:Pt,children:"on the Agents page"}),"."]})]})}function $ie({plugin:e,unlock:n}){const s=Ob(e,n.id),r=s.created?"up-to-date":n.drift.state,[a,i]=Aie[r];return t.jsxs("div",{className:"plugins-unlock",children:[t.jsx(pt,{title:t.jsxs("span",{className:"plugins-handle",children:["@",n.handle]}),sub:s.created?"Accepted just now. It is on the Agents page.":n.drift.message,side:t.jsxs("span",{className:"plugins-side",children:[t.jsx($e,{tone:a,children:i}),e&&r==="not-accepted"?t.jsx($,{size:"sm",variant:"accent",disabled:s.busy,onClick:s.accept,children:"Accept"}):null]})}),t.jsx(re,{message:s.failure}),s.created?t.jsx(CP,{agent:s.created}):null]})}function Wk({svg:e,name:n,version:s,by:r,pills:a}){return t.jsxs("span",{className:"plugins-sheet-title",children:[t.jsx(ss,{svg:e,size:"lg"}),t.jsxs("span",{className:"plugins-sheet-name",children:[t.jsxs("span",{children:[n," ",t.jsx("span",{className:"plugins-ver",children:s})]}),t.jsxs("span",{className:"plugins-sheet-by",children:["by ",r,a]})]})]})}function Tie({plugin:e,listing:n,notes:s,canOpen:r,busy:a,onOpen:i,onSettings:l,onClose:o,onDisable:c,onEnable:u,onRemove:h,onUpdate:m,firstStep:f,onRestart:p}){var S,C;const x=e.enabled===!1,[g,w]=d.useState(!1),[v,j]=d.useState(null),y=e.author!==void 0&&e.source.kind==="directory",k=(n==null?void 0:n.summary)??e.description,N=(e.network??((C=(S=n==null?void 0:n.claims)==null?void 0:S.manifest)==null?void 0:C.network)??[]).map(A=>A.host),b=e.uses??(n==null?void 0:n.usesWords);return t.jsxs(Ye,{title:t.jsx(Wk,{svg:n==null?void 0:n.iconSvg,name:e.name,version:e.version,by:e.author?t.jsx(Ip,{author:e.author}):TD(e),pills:t.jsxs(t.Fragment,{children:[n?t.jsxs(t.Fragment,{children:[" · ",t.jsx(_k,{entry:n})]}):null," · ",t.jsx(ID,{plugin:e})]})}),onClose:o,foot:t.jsxs(te,{children:[t.jsx($,{variant:"danger-ghost",onClick:h,children:"Remove…"}),t.jsx(ht,{}),l?t.jsx($,{variant:"ghost",onClick:l,children:"Settings"}):null,r?t.jsx($,{onClick:i,children:"Open"}):null,x?t.jsx($,{onClick:u,children:"Enable"}):t.jsx($,{variant:"ghost",onClick:c,children:"Disable…"}),n!=null&&n.update?t.jsxs($,{variant:"accent",disabled:a,onClick:()=>m(n.update),children:["Update to ",n.update]}):t.jsx($,{disabled:a,onClick:()=>m(),children:e.source.kind==="directory"?"Reinstall from folder":"Check for an update"})]}),children:[e.error&&e.needsRelink?t.jsx(Q,{tone:"critical",action:p?t.jsx($,{size:"sm",variant:"accent",disabled:g,onClick:()=>{w(!0),j(null),p().catch(A=>j(La(A))).finally(()=>w(!1))},children:"Restart buddi"}):void 0,children:t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{message:v}),t.jsx("span",{children:mie}),t.jsx(Vt,{summary:"Technical details",children:t.jsx("code",{className:"plugins-quiet",children:e.error})})]})}):e.error?t.jsx(Q,{tone:"critical",children:e.error}):null,s&&s.length>0?t.jsx(Q,{role:"status",children:s.join(" ")}):null,x?t.jsx(Q,{children:"Disabled: its tools, pages and watchers are off and its missions are paused. Its data is kept."}):null,!x&&e.needs&&e.needs.length>0?t.jsxs(Q,{tone:"warning",action:f?t.jsx($,{size:"sm",variant:"accent",onClick:f.run,children:f.label}):void 0,children:["Waiting: ",Bk(e),". Its tools and widgets stay off until then; its data is kept."]}):!x&&e.loaded&&e.setup?t.jsxs(Q,{tone:"warning",action:f?t.jsx($,{size:"sm",variant:"accent",onClick:f.run,children:f.label}):void 0,children:["Not set up yet. ",e.setup.note??"Its settings say what it needs."]}):null,k?t.jsx("p",{className:"plugins-summary-full",children:k}):null,t.jsx("div",{className:"plugins-facts",children:t.jsx(on,{items:[{label:"From",value:ky(e.source)},...y?[]:[{label:"Published by",value:Lk(e.source,e.publisher)}],{label:"Integrity",value:t.jsx(Ny,{value:e.integrity})},{label:"Installed",value:Xe(e.installedAt)},...e.installedAs?[{label:"Installed as",value:e.installedAs}]:[],{label:"Contributes",value:AD(e.contribution)},...e.network||n?[{label:"Talks to hosts",value:RD(N)}]:[],...b?[{label:"Reaches in buddi",value:Fk(b)}]:[]]})}),t.jsx(DD,{plugin:e.name,unlocks:e.unlocks})]})}function Rie({kind:e,name:n,canDisable:s,onCancel:r,onDisableInstead:a,onDisable:i,onRemove:l}){const[o,c]=d.useState(!1),[u,h]=d.useState(""),[m,f]=d.useState(!1),[p,x]=d.useState(null),g=v=>{f(!0),x(null),v().catch(j=>x(La(j))).finally(()=>f(!1))};if(e==="disable")return t.jsxs(Gt,{title:`Disable ${n}?`,onClose:r,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",disabled:m,onClick:r,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:m,onClick:()=>g(i),children:"Disable"})]}),children:[t.jsx("p",{className:"plugins-dialog-text",children:"Its tools, pages and watchers stop now and its missions pause. Its data and the agents you accepted from it are kept; enable it to have it all back."}),t.jsx(re,{message:p})]});const w=!o||u.trim()===n;return t.jsxs(Gt,{title:`Remove ${n}?`,onClose:r,foot:t.jsxs(t.Fragment,{children:[s?t.jsx($,{variant:"ghost",size:"sm",disabled:m,onClick:a,children:"Disable instead"}):null,t.jsx(ht,{}),t.jsx($,{variant:"ghost",disabled:m,onClick:r,children:"Cancel"}),t.jsx($,{variant:"danger",disabled:m||!w,onClick:()=>g(()=>l(o,u.trim())),children:o?"Remove and drop its data":"Remove"})]}),children:[t.jsxs("p",{className:"plugins-dialog-text",children:["This takes ",n," off this machine and stops its code loading. Its tables and the agents you accepted from it stay."]}),t.jsxs("div",{className:"plugins-purge","data-on":o?"true":void 0,children:[t.jsxs("label",{className:"plugins-check",children:[t.jsx("input",{type:"checkbox",checked:o,onChange:v=>{c(v.target.checked),h("")}}),t.jsxs("span",{children:[t.jsx("span",{className:"plugins-check-title",children:"Also drop its data"}),t.jsx("span",{className:"plugins-check-hint",children:"Its tables are gone for good; there is no undo."})]})]}),o?t.jsx(le,{label:t.jsxs(t.Fragment,{children:["Type ",t.jsx("span",{className:"mono",children:n})," to confirm"]}),children:t.jsx("input",{autoFocus:!0,value:u,onChange:v=>h(v.target.value)})}):null]}),t.jsx(re,{message:p})]})}function Iie({plugins:e,openFor:n}){return t.jsxs(Vt,{boxed:!0,summary:`Ships with buddi · ${ra(e.length,"plugin","plugins")}`,children:[t.jsx("p",{className:"plugins-note",children:"Compiled into this buddi: nothing to approve, nothing to remove. An agent still reaches one only if its own tools line names it."}),t.jsx("div",{className:"plugins-builtins",children:e.map(s=>{const r=(s.network??[]).map(i=>i.host),a=[s.description,s.author?`By ${s.author.name}.`:null,r.length>0?`Talks to ${r.join(", ")}.`:null].filter(Boolean).join(" ");return t.jsxs("div",{className:"plugins-builtin",title:a||void 0,children:[t.jsx("span",{className:"mono",children:s.name}),t.jsxs("span",{className:"plugins-builtin-n",children:[n(s.name,"ghost"),ra(s.contribution.tools,"tool","tools")]})]},s.name)})})]})}const Pie=[{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 Mie(e,n){const s=n.trim().toLowerCase();return s===""?!0:[e.title,e.summary,e.npm,...(e.widgets??[]).map(r=>r.title)].some(r=>r.toLowerCase().includes(s))}function Oie({pricing:e}){return e.kind==="free"?t.jsx(t.Fragment,{children:"free"}):t.jsxs(t.Fragment,{children:[e.kind==="paid"?"paid":"a subscription",e.trialDays?` · ${e.trialDays} days to try`:"",e.note?` · ${e.note}`:"",e.vendor?t.jsxs(t.Fragment,{children:[" · ",t.jsx("a",{href:e.vendor,target:"_blank",rel:"noopener noreferrer",children:"its maker's page"})]}):null]})}function Die({entry:e,busy:n,onOpen:s,onInstall:r,onUpdate:a}){var i,l;return t.jsxs(Br,{onClick:s,label:`${e.title}: details`,children:[t.jsxs("div",{className:"plugins-card-head",children:[t.jsx(ss,{svg:e.iconSvg,size:"lg"}),t.jsxs("div",{className:"plugins-card-name",children:[t.jsx("h3",{className:"ui-card-title",children:e.title}),t.jsxs("div",{className:"plugins-card-by",children:["by ",((i=e.author)==null?void 0:i.name)??"someone who gave no name",(l=e.widgets)!=null&&l.length?` · ${ra(e.widgets.length,"widget","widgets")}`:""]})]})]}),t.jsx("p",{className:"plugins-summary",children:e.summary}),t.jsxs("div",{className:"plugins-card-foot",children:[t.jsx(_k,{entry:e}),e.installed?t.jsxs($e,{children:["installed ",e.installed.version]}):null,t.jsx(ht,{}),e.update?t.jsxs($,{size:"sm",disabled:n,onClick:_o(()=>a(e.update)),children:["Update to ",e.update]}):e.installed?null:t.jsx($,{size:"sm",variant:"accent",disabled:n,onClick:_o(r),children:"Review & install"})]})]})}function Lie(e){var o,c;const n=(o=e.claims)==null?void 0:o.manifest,s=n==null?void 0:n.tools;if(!s)return;const r=s.filter(u=>u.tier==="auto").length,a=s.length-r,i=((c=n==null?void 0:n.sentinels)==null?void 0:c.length)??0,l=[r>0?`${r} run without asking`:null,a>0?`${a} ask${a===1?"s":""} you first`:null,i>0?`${i} on a timer`:null].filter(Boolean);return l.length===0?"none":l.join(", ")}function Fie({entry:e,canOpen:n,busy:s,onOpen:r,onClose:a,onInstall:i,onUpdate:l}){var f,p,x,g,w,v,j,y;const o=(f=e.screenshots)==null?void 0:f[0],c=(((x=(p=e.claims)==null?void 0:p.manifest)==null?void 0:x.network)??[]).map(k=>k.host),u=Lie(e),h=((v=(w=(g=e.claims)==null?void 0:g.manifest)==null?void 0:w.agents)==null?void 0:v.length)??0,m=(y=(j=e.claims)==null?void 0:j.package)==null?void 0:y.dependencies;return t.jsxs(Ye,{title:t.jsx(Wk,{svg:e.iconSvg,name:e.title,version:e.version,by:e.author?t.jsx(Ip,{author:e.author}):"someone who gave no name",pills:t.jsxs(t.Fragment,{children:[" · ",t.jsx(_k,{entry:e}),e.installed?t.jsxs(t.Fragment,{children:[" · ",t.jsxs($e,{children:["installed ",e.installed.version]})]}):null]})}),onClose:a,foot:t.jsxs(te,{children:[t.jsx("span",{className:"plugins-foot-note",children:e.installed&&!e.update?"This is the version you have.":"Install reads it first. Nothing of it runs until you say yes."}),t.jsx(ht,{}),n?t.jsx($,{onClick:r,children:"Open"}):null,e.update?t.jsxs($,{variant:"accent",disabled:s,onClick:()=>l(e.update),children:["Update to ",e.update]}):e.installed?null:t.jsx($,{variant:"accent",disabled:s,onClick:i,children:"Review & install"})]}),children:[o?t.jsx("img",{className:"plugins-shot",src:T.marketAssetUrl(o),alt:`${e.title}, as it looks in buddi`}):null,t.jsx("p",{className:"plugins-summary-full",children:e.summary}),t.jsx(zie,{entry:e}),t.jsx("div",{className:"plugins-facts",children:t.jsx(on,{items:[{label:"Package",value:t.jsx("span",{className:"mono",children:`${e.npm}@${e.version}`})},...u?[{label:"Tools",value:u}]:[],...h>0?[{label:"Proposes",value:`${ra(h,"agent","agents")}, created only if you accept`}]:[],{label:"Talks to hosts",value:RD(c)},{label:"Reaches in buddi",value:Fk(e.usesWords??[])},...m?[{label:"Dependencies",value:m.count===0?"none":`${m.count}${m.withScripts.length===0?", none of which run install scripts":`, of which these run install scripts: ${m.withScripts.join(", ")}`}`}]:[],{label:"Licence",value:t.jsxs(t.Fragment,{children:[e.license??"not stated"," · ",t.jsx(Oie,{pricing:e.pricing})]})}]})})]})}function _ie(e){return[kD(e.sizes),e.settings>0?"settings per placement":null,e.sensitive?"hidden until you show it, never on the lock screen":null].filter(Boolean).join(" · ")}function zie({entry:e}){const n=e.widgets??[];return n.length===0?null:t.jsx(ye,{title:"Widgets",aside:t.jsx("span",{className:"plugins-note",children:"Sample data, drawn as Home draws it"}),children:t.jsx("div",{className:"plugins-widgets",children:n.map(s=>t.jsxs("div",{className:"plugins-widget",children:[t.jsxs("div",{className:"plugins-widget-head",children:[t.jsx("span",{className:"plugins-widget-title",children:s.title}),t.jsx("span",{className:"plugins-widget-sub",children:_ie(s)})]}),t.jsx("div",{className:"plugins-widget-frames",children:rie(s.sizes).map(r=>t.jsx(ND,{widget:s,size:r,svg:e.iconSvg},r))})]},s.id))})})}function Uie(e){var s,r,a,i,l;const n=(s=e.claims)==null?void 0:s.manifest;return(((r=e.widgets)==null?void 0:r.length)??0)>0&&(((a=n==null?void 0:n.tools)==null?void 0:a.length)??0)===0&&(((i=n==null?void 0:n.sentinels)==null?void 0:i.length)??0)===0&&(((l=n==null?void 0:n.agents)==null?void 0:l.length)??0)===0}function Bie({entries:e,busy:n,onOpen:s,onInstall:r}){return t.jsx("div",{className:"plugins-wgrid","data-testid":"browse-widgets",children:e.flatMap(a=>(a.widgets??[]).map(i=>{var o;const l=i.sizes[0]??"small";return t.jsxs("div",{className:"plugins-witem","data-size":l,children:[t.jsx("button",{type:"button",className:"plugins-witem-frame","aria-label":`${i.title}, from ${a.title}: details`,onClick:()=>s(a),children:t.jsx(ND,{widget:i,size:l,svg:a.iconSvg})}),t.jsxs("div",{className:"plugins-witem-foot",children:[t.jsxs("span",{className:"plugins-witem-text",children:[t.jsx("span",{className:"plugins-witem-title",children:i.title}),t.jsxs("span",{className:"plugins-witem-sub",children:[Uie(a)?"A widget":`${a.title} plugin`," · by ",((o=a.author)==null?void 0:o.name)??"someone who gave no name"," · ",kD(i.sizes)]})]}),a.installed?t.jsx("span",{className:"plugins-witem-have",children:"Installed"}):t.jsx($,{size:"sm",variant:"accent",disabled:n,"aria-label":`Install ${a.title}`,onClick:()=>r(a),children:"Review & install"})]})]},`${a.npm}:${i.id}`)}))})}function Wie({kind:e="all",onKind:n,navigate:s,market:r,loading:a,busy:i,onRetry:l,onOpen:o,onInstall:c,onUpdate:u}){const[h,m]=d.useState(""),[f,p]=d.useState("all"),x=(r==null?void 0:r.plugins)??[],g=[{value:"all",label:"All"},{value:"recommended",label:"Recommended"},...Pie.filter(k=>x.some(N=>N.category===k.value))],w=x.filter(k=>{var N;return e==="widgets"&&(((N=k.widgets)==null?void 0:N.length)??0)===0||f==="recommended"&&(k.trust!=="by-buddi"||k.installed)||f!=="all"&&f!=="recommended"&&k.category!==f?!1:Mie(k,h)}),v=h.trim(),j=t.jsx("div",{className:"plugins-kind",children:t.jsx(cn,{label:"Show",options:Hie,value:e,onChange:k=>n==null?void 0:n(k)})}),y=e==="plugins"||e==="widgets"?null:t.jsx(Kie,{kind:e,navigate:s});return e==="agents"?t.jsxs(ue,{gap:"lg",children:[j,t.jsxs("p",{className:"plugins-quiet",children:[t.jsx(ne,{name:"globe",size:14}),"Opening this tab fetched the list from withbuddi.com. Nothing else leaves."]}),y]}):t.jsxs(ue,{gap:"lg",children:[j,t.jsxs(te,{children:[t.jsx(fp,{grow:!0,label:e==="widgets"?"Search widgets":"Search plugins",value:h,placeholder:e==="widgets"?"Search widgets: weather, calendar, news…":"Search plugins: weather, money, calendar…",onChange:m}),t.jsx(tP,{label:"Show",options:g,value:f,onChange:p})]}),t.jsxs("p",{className:"plugins-quiet",children:[t.jsx(ne,{name:"globe",size:14}),"Opening this tab fetched the list from withbuddi.com. Nothing else leaves."," ",t.jsx("button",{type:"button",className:"plugins-link",disabled:a,onClick:l,children:"Refresh"})]}),r===null||a&&r.unavailable?t.jsx(Ee,{children:"Asking withbuddi.com…"}):r.unavailable?t.jsx(Q,{tone:"warning",action:t.jsx($,{size:"sm",disabled:a,onClick:l,children:"Try again"}),children:r.unavailable}):t.jsxs(t.Fragment,{children:[r.stale?t.jsxs(Q,{tone:"warning",action:t.jsx($,{size:"sm",disabled:a,onClick:l,children:"Try again"}),children:["withbuddi.com did not answer, so this is the list as it was",r.fetchedAt?` ${Xe(r.fetchedAt)}`:" last time","."]}):null,w.length>0&&e==="widgets"?t.jsx(Bie,{entries:w,busy:i,onOpen:o,onInstall:c}):w.length>0?t.jsx("div",{className:"plugins-grid",children:w.map(k=>t.jsx(Die,{entry:k,busy:i,onOpen:()=>o(k),onInstall:()=>c(k),onUpdate:N=>u(k,N)},k.npm))}):t.jsx(Ee,{warm:!0,title:"Nothing listed matches",children:v!==""?`No ${e==="widgets"?"widget":"plugin"} on withbuddi.com mentions “${v}”.`:e==="widgets"&&!x.some(k=>{var N;return(((N=k.widgets)==null?void 0:N.length)??0)>0})?"No plugin on withbuddi.com brings a widget yet.":x.length===0?"withbuddi.com lists no plugins yet.":"Nothing on this shelf yet."})]}),y]})}const Hie=[{value:"all",label:"All"},{value:"plugins",label:"Plugins"},{value:"widgets",label:"Widgets"},{value:"agents",label:"Agents"}];function Kie({kind:e,navigate:n}){const s=je(()=>T.catalogue(),[]),r=Ub(),a=c=>n==null?void 0:n(c),i=s.data;if(!i)return s.error?t.jsx(Q,{tone:"warning",children:s.error}):t.jsx(Ee,{children:"Asking withbuddi.com…"});if(i.unavailable)return e==="agents"?t.jsx(Q,{tone:"warning",children:i.unavailable}):null;const l=i.agents.filter(c=>Bs(c)==="ready"),o=e==="all"?l.slice(0,3):i.agents;return o.length===0?null:t.jsx(ye,{title:e==="all"?"Teammates":void 0,aside:t.jsx("a",{href:En(),onClick:c=>{c.preventDefault(),a(En())},children:e==="all"?`See all ${i.agents.length}`:"Open the catalogue"}),children:t.jsx("div",{className:"plugins-grid","data-testid":"browse-agents",children:o.map(c=>t.jsx(IP,{entry:c,loaded:r,onOpen:()=>a(En(c.name)),onAdd:()=>a(En(c.name)),onUpdate:()=>a(En(c.name))},c.name))})})}var kd={},Vie=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then},LD={},er={};let Hk;const Gie=[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];er.getSymbolSize=function(n){if(!n)throw new Error('"version" cannot be null or undefined');if(n<1||n>40)throw new Error('"version" should be in range from 1 to 40');return n*4+17};er.getSymbolTotalCodewords=function(n){return Gie[n]};er.getBCHDigit=function(e){let n=0;for(;e!==0;)n++,e>>>=1;return n};er.setToSJISFunction=function(n){if(typeof n!="function")throw new Error('"toSJISFunc" is not a valid function.');Hk=n};er.isKanjiModeEnabled=function(){return typeof Hk<"u"};er.toSJIS=function(n){return Hk(n)};var Pp={};(function(e){e.L={bit:1},e.M={bit:0},e.Q={bit:3},e.H={bit:2};function n(s){if(typeof s!="string")throw new Error("Param is not a string");switch(s.toLowerCase()){case"l":case"low":return e.L;case"m":case"medium":return e.M;case"q":case"quartile":return e.Q;case"h":case"high":return e.H;default:throw new Error("Unknown EC Level: "+s)}}e.isValid=function(r){return r&&typeof r.bit<"u"&&r.bit>=0&&r.bit<4},e.from=function(r,a){if(e.isValid(r))return r;try{return n(r)}catch{return a}}})(Pp);function FD(){this.buffer=[],this.length=0}FD.prototype={get:function(e){const n=Math.floor(e/8);return(this.buffer[n]>>>7-e%8&1)===1},put:function(e,n){for(let s=0;s<n;s++)this.putBit((e>>>n-s-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(e){const n=Math.floor(this.length/8);this.buffer.length<=n&&this.buffer.push(0),e&&(this.buffer[n]|=128>>>this.length%8),this.length++}};var qie=FD;function Nd(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)}Nd.prototype.set=function(e,n,s,r){const a=e*this.size+n;this.data[a]=s,r&&(this.reservedBit[a]=!0)};Nd.prototype.get=function(e,n){return this.data[e*this.size+n]};Nd.prototype.xor=function(e,n,s){this.data[e*this.size+n]^=s};Nd.prototype.isReserved=function(e,n){return this.reservedBit[e*this.size+n]};var Yie=Nd,_D={};(function(e){const n=er.getSymbolSize;e.getRowColCoords=function(r){if(r===1)return[];const a=Math.floor(r/7)+2,i=n(r),l=i===145?26:Math.ceil((i-13)/(2*a-2))*2,o=[i-7];for(let c=1;c<a-1;c++)o[c]=o[c-1]-l;return o.push(6),o.reverse()},e.getPositions=function(r){const a=[],i=e.getRowColCoords(r),l=i.length;for(let o=0;o<l;o++)for(let c=0;c<l;c++)o===0&&c===0||o===0&&c===l-1||o===l-1&&c===0||a.push([i[o],i[c]]);return a}})(_D);var zD={};const Qie=er.getSymbolSize,IE=7;zD.getPositions=function(n){const s=Qie(n);return[[0,0],[s-IE,0],[0,s-IE]]};var UD={};(function(e){e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const n={N1:3,N2:3,N3:40,N4:10};e.isValid=function(a){return a!=null&&a!==""&&!isNaN(a)&&a>=0&&a<=7},e.from=function(a){return e.isValid(a)?parseInt(a,10):void 0},e.getPenaltyN1=function(a){const i=a.size;let l=0,o=0,c=0,u=null,h=null;for(let m=0;m<i;m++){o=c=0,u=h=null;for(let f=0;f<i;f++){let p=a.get(m,f);p===u?o++:(o>=5&&(l+=n.N1+(o-5)),u=p,o=1),p=a.get(f,m),p===h?c++:(c>=5&&(l+=n.N1+(c-5)),h=p,c=1)}o>=5&&(l+=n.N1+(o-5)),c>=5&&(l+=n.N1+(c-5))}return l},e.getPenaltyN2=function(a){const i=a.size;let l=0;for(let o=0;o<i-1;o++)for(let c=0;c<i-1;c++){const u=a.get(o,c)+a.get(o,c+1)+a.get(o+1,c)+a.get(o+1,c+1);(u===4||u===0)&&l++}return l*n.N2},e.getPenaltyN3=function(a){const i=a.size;let l=0,o=0,c=0;for(let u=0;u<i;u++){o=c=0;for(let h=0;h<i;h++)o=o<<1&2047|a.get(u,h),h>=10&&(o===1488||o===93)&&l++,c=c<<1&2047|a.get(h,u),h>=10&&(c===1488||c===93)&&l++}return l*n.N3},e.getPenaltyN4=function(a){let i=0;const l=a.data.length;for(let c=0;c<l;c++)i+=a.data[c];return Math.abs(Math.ceil(i*100/l/5)-10)*n.N4};function s(r,a,i){switch(r){case e.Patterns.PATTERN000:return(a+i)%2===0;case e.Patterns.PATTERN001:return a%2===0;case e.Patterns.PATTERN010:return i%3===0;case e.Patterns.PATTERN011:return(a+i)%3===0;case e.Patterns.PATTERN100:return(Math.floor(a/2)+Math.floor(i/3))%2===0;case e.Patterns.PATTERN101:return a*i%2+a*i%3===0;case e.Patterns.PATTERN110:return(a*i%2+a*i%3)%2===0;case e.Patterns.PATTERN111:return(a*i%3+(a+i)%2)%2===0;default:throw new Error("bad maskPattern:"+r)}}e.applyMask=function(a,i){const l=i.size;for(let o=0;o<l;o++)for(let c=0;c<l;c++)i.isReserved(c,o)||i.xor(c,o,s(a,c,o))},e.getBestMask=function(a,i){const l=Object.keys(e.Patterns).length;let o=0,c=1/0;for(let u=0;u<l;u++){i(u),e.applyMask(u,a);const h=e.getPenaltyN1(a)+e.getPenaltyN2(a)+e.getPenaltyN3(a)+e.getPenaltyN4(a);e.applyMask(u,a),h<c&&(c=h,o=u)}return o}})(UD);var Mp={};const ni=Pp,Ah=[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],$h=[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];Mp.getBlocksCount=function(n,s){switch(s){case ni.L:return Ah[(n-1)*4+0];case ni.M:return Ah[(n-1)*4+1];case ni.Q:return Ah[(n-1)*4+2];case ni.H:return Ah[(n-1)*4+3];default:return}};Mp.getTotalCodewordsCount=function(n,s){switch(s){case ni.L:return $h[(n-1)*4+0];case ni.M:return $h[(n-1)*4+1];case ni.Q:return $h[(n-1)*4+2];case ni.H:return $h[(n-1)*4+3];default:return}};var BD={},Op={};const iu=new Uint8Array(512),pm=new Uint8Array(256);(function(){let n=1;for(let s=0;s<255;s++)iu[s]=n,pm[n]=s,n<<=1,n&256&&(n^=285);for(let s=255;s<512;s++)iu[s]=iu[s-255]})();Op.log=function(n){if(n<1)throw new Error("log("+n+")");return pm[n]};Op.exp=function(n){return iu[n]};Op.mul=function(n,s){return n===0||s===0?0:iu[pm[n]+pm[s]]};(function(e){const n=Op;e.mul=function(r,a){const i=new Uint8Array(r.length+a.length-1);for(let l=0;l<r.length;l++)for(let o=0;o<a.length;o++)i[l+o]^=n.mul(r[l],a[o]);return i},e.mod=function(r,a){let i=new Uint8Array(r);for(;i.length-a.length>=0;){const l=i[0];for(let c=0;c<a.length;c++)i[c]^=n.mul(a[c],l);let o=0;for(;o<i.length&&i[o]===0;)o++;i=i.slice(o)}return i},e.generateECPolynomial=function(r){let a=new Uint8Array([1]);for(let i=0;i<r;i++)a=e.mul(a,new Uint8Array([1,n.exp(i)]));return a}})(BD);const WD=BD;function Kk(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}Kk.prototype.initialize=function(n){this.degree=n,this.genPoly=WD.generateECPolynomial(this.degree)};Kk.prototype.encode=function(n){if(!this.genPoly)throw new Error("Encoder not initialized");const s=new Uint8Array(n.length+this.degree);s.set(n);const r=WD.mod(s,this.genPoly),a=this.degree-r.length;if(a>0){const i=new Uint8Array(this.degree);return i.set(r,a),i}return r};var Jie=Kk,HD={},Mi={},Vk={};Vk.isValid=function(n){return!isNaN(n)&&n>=1&&n<=40};var fa={};const KD="[0-9]+",Xie="[A-Z $%*+\\-./:]+";let td="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";td=td.replace(/u/g,"\\u");const Zie="(?:(?![A-Z0-9 $%*+\\-./:]|"+td+`)(?:.|[\r
148
- ]))+`;fa.KANJI=new RegExp(td,"g");fa.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");fa.BYTE=new RegExp(Zie,"g");fa.NUMERIC=new RegExp(KD,"g");fa.ALPHANUMERIC=new RegExp(Xie,"g");const ele=new RegExp("^"+td+"$"),tle=new RegExp("^"+KD+"$"),nle=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");fa.testKanji=function(n){return ele.test(n)};fa.testNumeric=function(n){return tle.test(n)};fa.testAlphanumeric=function(n){return nle.test(n)};(function(e){const n=Vk,s=fa;e.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},e.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},e.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},e.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},e.MIXED={bit:-1},e.getCharCountIndicator=function(i,l){if(!i.ccBits)throw new Error("Invalid mode: "+i);if(!n.isValid(l))throw new Error("Invalid version: "+l);return l>=1&&l<10?i.ccBits[0]:l<27?i.ccBits[1]:i.ccBits[2]},e.getBestModeForData=function(i){return s.testNumeric(i)?e.NUMERIC:s.testAlphanumeric(i)?e.ALPHANUMERIC:s.testKanji(i)?e.KANJI:e.BYTE},e.toString=function(i){if(i&&i.id)return i.id;throw new Error("Invalid mode")},e.isValid=function(i){return i&&i.bit&&i.ccBits};function r(a){if(typeof a!="string")throw new Error("Param is not a string");switch(a.toLowerCase()){case"numeric":return e.NUMERIC;case"alphanumeric":return e.ALPHANUMERIC;case"kanji":return e.KANJI;case"byte":return e.BYTE;default:throw new Error("Unknown mode: "+a)}}e.from=function(i,l){if(e.isValid(i))return i;try{return r(i)}catch{return l}}})(Mi);(function(e){const n=er,s=Mp,r=Pp,a=Mi,i=Vk,l=7973,o=n.getBCHDigit(l);function c(f,p,x){for(let g=1;g<=40;g++)if(p<=e.getCapacity(g,x,f))return g}function u(f,p){return a.getCharCountIndicator(f,p)+4}function h(f,p){let x=0;return f.forEach(function(g){const w=u(g.mode,p);x+=w+g.getBitsLength()}),x}function m(f,p){for(let x=1;x<=40;x++)if(h(f,x)<=e.getCapacity(x,p,a.MIXED))return x}e.from=function(p,x){return i.isValid(p)?parseInt(p,10):x},e.getCapacity=function(p,x,g){if(!i.isValid(p))throw new Error("Invalid QR Code version");typeof g>"u"&&(g=a.BYTE);const w=n.getSymbolTotalCodewords(p),v=s.getTotalCodewordsCount(p,x),j=(w-v)*8;if(g===a.MIXED)return j;const y=j-u(g,p);switch(g){case a.NUMERIC:return Math.floor(y/10*3);case a.ALPHANUMERIC:return Math.floor(y/11*2);case a.KANJI:return Math.floor(y/13);case a.BYTE:default:return Math.floor(y/8)}},e.getBestVersionForData=function(p,x){let g;const w=r.from(x,r.M);if(Array.isArray(p)){if(p.length>1)return m(p,w);if(p.length===0)return 1;g=p[0]}else g=p;return c(g.mode,g.getLength(),w)},e.getEncodedBits=function(p){if(!i.isValid(p)||p<7)throw new Error("Invalid QR Code version");let x=p<<12;for(;n.getBCHDigit(x)-o>=0;)x^=l<<n.getBCHDigit(x)-o;return p<<12|x}})(HD);var VD={};const Cy=er,GD=1335,sle=21522,PE=Cy.getBCHDigit(GD);VD.getEncodedBits=function(n,s){const r=n.bit<<3|s;let a=r<<10;for(;Cy.getBCHDigit(a)-PE>=0;)a^=GD<<Cy.getBCHDigit(a)-PE;return(r<<10|a)^sle};var qD={};const rle=Mi;function zo(e){this.mode=rle.NUMERIC,this.data=e.toString()}zo.getBitsLength=function(n){return 10*Math.floor(n/3)+(n%3?n%3*3+1:0)};zo.prototype.getLength=function(){return this.data.length};zo.prototype.getBitsLength=function(){return zo.getBitsLength(this.data.length)};zo.prototype.write=function(n){let s,r,a;for(s=0;s+3<=this.data.length;s+=3)r=this.data.substr(s,3),a=parseInt(r,10),n.put(a,10);const i=this.data.length-s;i>0&&(r=this.data.substr(s),a=parseInt(r,10),n.put(a,i*3+1))};var ale=zo;const ile=Mi,Nx=["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 Uo(e){this.mode=ile.ALPHANUMERIC,this.data=e}Uo.getBitsLength=function(n){return 11*Math.floor(n/2)+6*(n%2)};Uo.prototype.getLength=function(){return this.data.length};Uo.prototype.getBitsLength=function(){return Uo.getBitsLength(this.data.length)};Uo.prototype.write=function(n){let s;for(s=0;s+2<=this.data.length;s+=2){let r=Nx.indexOf(this.data[s])*45;r+=Nx.indexOf(this.data[s+1]),n.put(r,11)}this.data.length%2&&n.put(Nx.indexOf(this.data[s]),6)};var lle=Uo;const ole=Mi;function Bo(e){this.mode=ole.BYTE,typeof e=="string"?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}Bo.getBitsLength=function(n){return n*8};Bo.prototype.getLength=function(){return this.data.length};Bo.prototype.getBitsLength=function(){return Bo.getBitsLength(this.data.length)};Bo.prototype.write=function(e){for(let n=0,s=this.data.length;n<s;n++)e.put(this.data[n],8)};var cle=Bo;const ule=Mi,dle=er;function Wo(e){this.mode=ule.KANJI,this.data=e}Wo.getBitsLength=function(n){return n*13};Wo.prototype.getLength=function(){return this.data.length};Wo.prototype.getBitsLength=function(){return Wo.getBitsLength(this.data.length)};Wo.prototype.write=function(e){let n;for(n=0;n<this.data.length;n++){let s=dle.toSJIS(this.data[n]);if(s>=33088&&s<=40956)s-=33088;else if(s>=57408&&s<=60351)s-=49472;else throw new Error("Invalid SJIS character: "+this.data[n]+`
149
- Make sure your charset is UTF-8`);s=(s>>>8&255)*192+(s&255),e.put(s,13)}};var hle=Wo,YD={exports:{}};(function(e){var n={single_source_shortest_paths:function(s,r,a){var i={},l={};l[r]=0;var o=n.PriorityQueue.make();o.push(r,0);for(var c,u,h,m,f,p,x,g,w;!o.empty();){c=o.pop(),u=c.value,m=c.cost,f=s[u]||{};for(h in f)f.hasOwnProperty(h)&&(p=f[h],x=m+p,g=l[h],w=typeof l[h]>"u",(w||g>x)&&(l[h]=x,o.push(h,x),i[h]=u))}if(typeof a<"u"&&typeof l[a]>"u"){var v=["Could not find a path from ",r," to ",a,"."].join("");throw new Error(v)}return i},extract_shortest_path_from_predecessor_list:function(s,r){for(var a=[],i=r;i;)a.push(i),s[i],i=s[i];return a.reverse(),a},find_path:function(s,r,a){var i=n.single_source_shortest_paths(s,r,a);return n.extract_shortest_path_from_predecessor_list(i,a)},PriorityQueue:{make:function(s){var r=n.PriorityQueue,a={},i;s=s||{};for(i in r)r.hasOwnProperty(i)&&(a[i]=r[i]);return a.queue=[],a.sorter=s.sorter||r.default_sorter,a},default_sorter:function(s,r){return s.cost-r.cost},push:function(s,r){var a={value:s,cost:r};this.queue.push(a),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};e.exports=n})(YD);var fle=YD.exports;(function(e){const n=Mi,s=ale,r=lle,a=cle,i=hle,l=fa,o=er,c=fle;function u(v){return unescape(encodeURIComponent(v)).length}function h(v,j,y){const k=[];let N;for(;(N=v.exec(y))!==null;)k.push({data:N[0],index:N.index,mode:j,length:N[0].length});return k}function m(v){const j=h(l.NUMERIC,n.NUMERIC,v),y=h(l.ALPHANUMERIC,n.ALPHANUMERIC,v);let k,N;return o.isKanjiModeEnabled()?(k=h(l.BYTE,n.BYTE,v),N=h(l.KANJI,n.KANJI,v)):(k=h(l.BYTE_KANJI,n.BYTE,v),N=[]),j.concat(y,k,N).sort(function(S,C){return S.index-C.index}).map(function(S){return{data:S.data,mode:S.mode,length:S.length}})}function f(v,j){switch(j){case n.NUMERIC:return s.getBitsLength(v);case n.ALPHANUMERIC:return r.getBitsLength(v);case n.KANJI:return i.getBitsLength(v);case n.BYTE:return a.getBitsLength(v)}}function p(v){return v.reduce(function(j,y){const k=j.length-1>=0?j[j.length-1]:null;return k&&k.mode===y.mode?(j[j.length-1].data+=y.data,j):(j.push(y),j)},[])}function x(v){const j=[];for(let y=0;y<v.length;y++){const k=v[y];switch(k.mode){case n.NUMERIC:j.push([k,{data:k.data,mode:n.ALPHANUMERIC,length:k.length},{data:k.data,mode:n.BYTE,length:k.length}]);break;case n.ALPHANUMERIC:j.push([k,{data:k.data,mode:n.BYTE,length:k.length}]);break;case n.KANJI:j.push([k,{data:k.data,mode:n.BYTE,length:u(k.data)}]);break;case n.BYTE:j.push([{data:k.data,mode:n.BYTE,length:u(k.data)}])}}return j}function g(v,j){const y={},k={start:{}};let N=["start"];for(let b=0;b<v.length;b++){const S=v[b],C=[];for(let A=0;A<S.length;A++){const E=S[A],R=""+b+A;C.push(R),y[R]={node:E,lastCount:0},k[R]={};for(let P=0;P<N.length;P++){const O=N[P];y[O]&&y[O].node.mode===E.mode?(k[O][R]=f(y[O].lastCount+E.length,E.mode)-f(y[O].lastCount,E.mode),y[O].lastCount+=E.length):(y[O]&&(y[O].lastCount=E.length),k[O][R]=f(E.length,E.mode)+4+n.getCharCountIndicator(E.mode,j))}}N=C}for(let b=0;b<N.length;b++)k[N[b]].end=0;return{map:k,table:y}}function w(v,j){let y;const k=n.getBestModeForData(v);if(y=n.from(j,k),y!==n.BYTE&&y.bit<k.bit)throw new Error('"'+v+'" cannot be encoded with mode '+n.toString(y)+`.
150
- Suggested mode is: `+n.toString(k));switch(y===n.KANJI&&!o.isKanjiModeEnabled()&&(y=n.BYTE),y){case n.NUMERIC:return new s(v);case n.ALPHANUMERIC:return new r(v);case n.KANJI:return new i(v);case n.BYTE:return new a(v)}}e.fromArray=function(j){return j.reduce(function(y,k){return typeof k=="string"?y.push(w(k,null)):k.data&&y.push(w(k.data,k.mode)),y},[])},e.fromString=function(j,y){const k=m(j,o.isKanjiModeEnabled()),N=x(k),b=g(N,y),S=c.find_path(b.map,"start","end"),C=[];for(let A=1;A<S.length-1;A++)C.push(b.table[S[A]].node);return e.fromArray(p(C))},e.rawSplit=function(j){return e.fromArray(m(j,o.isKanjiModeEnabled()))}})(qD);const Dp=er,Sx=Pp,mle=qie,ple=Yie,gle=_D,xle=zD,Ey=UD,Ay=Mp,jle=Jie,gm=HD,vle=VD,yle=Mi,Cx=qD;function wle(e,n){const s=e.size,r=xle.getPositions(n);for(let a=0;a<r.length;a++){const i=r[a][0],l=r[a][1];for(let o=-1;o<=7;o++)if(!(i+o<=-1||s<=i+o))for(let c=-1;c<=7;c++)l+c<=-1||s<=l+c||(o>=0&&o<=6&&(c===0||c===6)||c>=0&&c<=6&&(o===0||o===6)||o>=2&&o<=4&&c>=2&&c<=4?e.set(i+o,l+c,!0,!0):e.set(i+o,l+c,!1,!0))}}function ble(e){const n=e.size;for(let s=8;s<n-8;s++){const r=s%2===0;e.set(s,6,r,!0),e.set(6,s,r,!0)}}function kle(e,n){const s=gle.getPositions(n);for(let r=0;r<s.length;r++){const a=s[r][0],i=s[r][1];for(let l=-2;l<=2;l++)for(let o=-2;o<=2;o++)l===-2||l===2||o===-2||o===2||l===0&&o===0?e.set(a+l,i+o,!0,!0):e.set(a+l,i+o,!1,!0)}}function Nle(e,n){const s=e.size,r=gm.getEncodedBits(n);let a,i,l;for(let o=0;o<18;o++)a=Math.floor(o/3),i=o%3+s-8-3,l=(r>>o&1)===1,e.set(a,i,l,!0),e.set(i,a,l,!0)}function Ex(e,n,s){const r=e.size,a=vle.getEncodedBits(n,s);let i,l;for(i=0;i<15;i++)l=(a>>i&1)===1,i<6?e.set(i,8,l,!0):i<8?e.set(i+1,8,l,!0):e.set(r-15+i,8,l,!0),i<8?e.set(8,r-i-1,l,!0):i<9?e.set(8,15-i-1+1,l,!0):e.set(8,15-i-1,l,!0);e.set(r-8,8,1,!0)}function Sle(e,n){const s=e.size;let r=-1,a=s-1,i=7,l=0;for(let o=s-1;o>0;o-=2)for(o===6&&o--;;){for(let c=0;c<2;c++)if(!e.isReserved(a,o-c)){let u=!1;l<n.length&&(u=(n[l]>>>i&1)===1),e.set(a,o-c,u),i--,i===-1&&(l++,i=7)}if(a+=r,a<0||s<=a){a-=r,r=-r;break}}}function Cle(e,n,s){const r=new mle;s.forEach(function(c){r.put(c.mode.bit,4),r.put(c.getLength(),yle.getCharCountIndicator(c.mode,e)),c.write(r)});const a=Dp.getSymbolTotalCodewords(e),i=Ay.getTotalCodewordsCount(e,n),l=(a-i)*8;for(r.getLengthInBits()+4<=l&&r.put(0,4);r.getLengthInBits()%8!==0;)r.putBit(0);const o=(l-r.getLengthInBits())/8;for(let c=0;c<o;c++)r.put(c%2?17:236,8);return Ele(r,e,n)}function Ele(e,n,s){const r=Dp.getSymbolTotalCodewords(n),a=Ay.getTotalCodewordsCount(n,s),i=r-a,l=Ay.getBlocksCount(n,s),o=r%l,c=l-o,u=Math.floor(r/l),h=Math.floor(i/l),m=h+1,f=u-h,p=new jle(f);let x=0;const g=new Array(l),w=new Array(l);let v=0;const j=new Uint8Array(e.buffer);for(let S=0;S<l;S++){const C=S<c?h:m;g[S]=j.slice(x,x+C),w[S]=p.encode(g[S]),x+=C,v=Math.max(v,C)}const y=new Uint8Array(r);let k=0,N,b;for(N=0;N<v;N++)for(b=0;b<l;b++)N<g[b].length&&(y[k++]=g[b][N]);for(N=0;N<f;N++)for(b=0;b<l;b++)y[k++]=w[b][N];return y}function Ale(e,n,s,r){let a;if(Array.isArray(e))a=Cx.fromArray(e);else if(typeof e=="string"){let u=n;if(!u){const h=Cx.rawSplit(e);u=gm.getBestVersionForData(h,s)}a=Cx.fromString(e,u||40)}else throw new Error("Invalid data");const i=gm.getBestVersionForData(a,s);if(!i)throw new Error("The amount of data is too big to be stored in a QR Code");if(!n)n=i;else if(n<i)throw new Error(`
151
- The chosen QR Code version cannot contain this amount of data.
152
- Minimum version required to store current data is: `+i+`.
153
- `);const l=Cle(n,s,a),o=Dp.getSymbolSize(n),c=new ple(o);return wle(c,n),ble(c),kle(c,n),Ex(c,s,0),n>=7&&Nle(c,n),Sle(c,l),isNaN(r)&&(r=Ey.getBestMask(c,Ex.bind(null,c,s))),Ey.applyMask(r,c),Ex(c,s,r),{modules:c,version:n,errorCorrectionLevel:s,maskPattern:r,segments:a}}LD.create=function(n,s){if(typeof n>"u"||n==="")throw new Error("No input text");let r=Sx.M,a,i;return typeof s<"u"&&(r=Sx.from(s.errorCorrectionLevel,Sx.M),a=gm.from(s.version),i=Ey.from(s.maskPattern),s.toSJISFunc&&Dp.setToSJISFunction(s.toSJISFunc)),Ale(n,a,r,i)};var QD={},Gk={};(function(e){function n(s){if(typeof s=="number"&&(s=s.toString()),typeof s!="string")throw new Error("Color should be defined as hex string");let r=s.slice().replace("#","").split("");if(r.length<3||r.length===5||r.length>8)throw new Error("Invalid hex color: "+s);(r.length===3||r.length===4)&&(r=Array.prototype.concat.apply([],r.map(function(i){return[i,i]}))),r.length===6&&r.push("F","F");const a=parseInt(r.join(""),16);return{r:a>>24&255,g:a>>16&255,b:a>>8&255,a:a&255,hex:"#"+r.slice(0,6).join("")}}e.getOptions=function(r){r||(r={}),r.color||(r.color={});const a=typeof r.margin>"u"||r.margin===null||r.margin<0?4:r.margin,i=r.width&&r.width>=21?r.width:void 0,l=r.scale||4;return{width:i,scale:i?4:l,margin:a,color:{dark:n(r.color.dark||"#000000ff"),light:n(r.color.light||"#ffffffff")},type:r.type,rendererOpts:r.rendererOpts||{}}},e.getScale=function(r,a){return a.width&&a.width>=r+a.margin*2?a.width/(r+a.margin*2):a.scale},e.getImageWidth=function(r,a){const i=e.getScale(r,a);return Math.floor((r+a.margin*2)*i)},e.qrToImageData=function(r,a,i){const l=a.modules.size,o=a.modules.data,c=e.getScale(l,i),u=Math.floor((l+i.margin*2)*c),h=i.margin*c,m=[i.color.light,i.color.dark];for(let f=0;f<u;f++)for(let p=0;p<u;p++){let x=(f*u+p)*4,g=i.color.light;if(f>=h&&p>=h&&f<u-h&&p<u-h){const w=Math.floor((f-h)/c),v=Math.floor((p-h)/c);g=m[o[w*l+v]?1:0]}r[x++]=g.r,r[x++]=g.g,r[x++]=g.b,r[x]=g.a}}})(Gk);(function(e){const n=Gk;function s(a,i,l){a.clearRect(0,0,i.width,i.height),i.style||(i.style={}),i.height=l,i.width=l,i.style.height=l+"px",i.style.width=l+"px"}function r(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}e.render=function(i,l,o){let c=o,u=l;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),l||(u=r()),c=n.getOptions(c);const h=n.getImageWidth(i.modules.size,c),m=u.getContext("2d"),f=m.createImageData(h,h);return n.qrToImageData(f.data,i,c),s(m,u,h),m.putImageData(f,0,0),u},e.renderToDataURL=function(i,l,o){let c=o;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),c||(c={});const u=e.render(i,l,c),h=c.type||"image/png",m=c.rendererOpts||{};return u.toDataURL(h,m.quality)}})(QD);var JD={};const $le=Gk;function ME(e,n){const s=e.a/255,r=n+'="'+e.hex+'"';return s<1?r+" "+n+'-opacity="'+s.toFixed(2).slice(1)+'"':r}function Ax(e,n,s){let r=e+n;return typeof s<"u"&&(r+=" "+s),r}function Tle(e,n,s){let r="",a=0,i=!1,l=0;for(let o=0;o<e.length;o++){const c=Math.floor(o%n),u=Math.floor(o/n);!c&&!i&&(i=!0),e[o]?(l++,o>0&&c>0&&e[o-1]||(r+=i?Ax("M",c+s,.5+u+s):Ax("m",a,0),a=0,i=!1),c+1<n&&e[o+1]||(r+=Ax("h",l),l=0)):a++}return r}JD.render=function(n,s,r){const a=$le.getOptions(s),i=n.modules.size,l=n.modules.data,o=i+a.margin*2,c=a.color.light.a?"<path "+ME(a.color.light,"fill")+' d="M0 0h'+o+"v"+o+'H0z"/>':"",u="<path "+ME(a.color.dark,"stroke")+' d="'+Tle(l,i,a.margin)+'"/>',h='viewBox="0 0 '+o+" "+o+'"',f='<svg xmlns="http://www.w3.org/2000/svg" '+(a.width?'width="'+a.width+'" height="'+a.width+'" ':"")+h+' shape-rendering="crispEdges">'+c+u+`</svg>
154
- `;return typeof r=="function"&&r(null,f),f};const Rle=Vie,$y=LD,XD=QD,Ile=JD;function qk(e,n,s,r,a){const i=[].slice.call(arguments,1),l=i.length,o=typeof i[l-1]=="function";if(!o&&!Rle())throw new Error("Callback required as last argument");if(o){if(l<2)throw new Error("Too few arguments provided");l===2?(a=s,s=n,n=r=void 0):l===3&&(n.getContext&&typeof a>"u"?(a=r,r=void 0):(a=r,r=s,s=n,n=void 0))}else{if(l<1)throw new Error("Too few arguments provided");return l===1?(s=n,n=r=void 0):l===2&&!n.getContext&&(r=s,s=n,n=void 0),new Promise(function(c,u){try{const h=$y.create(s,r);c(e(h,n,r))}catch(h){u(h)}})}try{const c=$y.create(s,r);a(null,e(c,n,r))}catch(c){a(c)}}kd.create=$y.create;kd.toCanvas=qk.bind(null,XD.render);kd.toDataURL=qk.bind(null,XD.renderToDataURL);kd.toString=qk.bind(null,function(e,n,s){return Ile.render(e,s)});async function Ple(e){const n=await kd.toString(e,{type:"svg",margin:4,errorCorrectionLevel:"M"});return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n)}`}const OE=10*6e4,Mle=2e3;function ZD(e,n){const[s,r]=d.useState(null),[a,i]=d.useState(null),[l,o]=d.useState(!1),[c,u]=d.useState(!1),h=d.useRef(e);h.current=e;const m=d.useRef(n);m.current=n;const f=d.useCallback(async()=>{const p=await T.telegramPairing();r(p),u(!1),o(!1),i(await Ple(p.link).catch(()=>""))},[]);return d.useEffect(()=>{if(!s||l||c)return;let p=!1;const x=Math.min(Date.parse(s.expiresAt)||Date.now()+OE,Date.now()+OE),g=window.setInterval(()=>{if(Date.now()>=x){u(!0);return}h.current().then(w=>{var v;p||!w||(o(!0),(v=m.current)==null||v.call(m))}).catch(()=>{})},Mle);return()=>{p=!0,window.clearInterval(g)}},[s,l,c]),{offer:s,square:a,paired:l,stale:c,ask:f}}function Ole({offer:e,square:n,children:s}){return t.jsxs("div",{className:"meet-pair",children:[n?t.jsx("img",{className:"meet-qr",src:n,alt:e.link}):null,t.jsx("a",{className:"meet-link",href:e.link,target:"_blank",rel:"noreferrer",children:e.link}),s]})}function Dle({offer:e,square:n,bot:s,status:r,paired:a}){const[i,l]=d.useState(!1),o=()=>{Promise.resolve().then(()=>{var c;return(c=navigator.clipboard)==null?void 0:c.writeText(e.link)}).then(()=>l(!0)).catch(()=>{})};return t.jsxs("div",{className:"tg-pair","data-testid":"pairing-tile",children:[t.jsx("div",{className:"tg-pair-tile",children:n?t.jsx("img",{className:"tg-pair-qr",src:n,alt:s?`QR code for @${s}`:"QR code for your buddi bot"}):null}),s?t.jsxs("span",{className:"tg-pair-bot",children:["@",s]}):null,t.jsxs("div",{className:"tg-pair-actions",children:[t.jsx($,{onClick:o,children:i?"Copied":"Copy link"}),t.jsx(it,{variant:"accent",href:e.link,target:"_blank",rel:"noreferrer",children:"Open in Telegram"})]}),t.jsxs("p",{className:"tg-pair-status",role:"status","data-paired":a?"true":void 0,children:[a?null:t.jsxs("span",{className:"wiz-pulse","aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]}),r]})]})}const eL=new Set(["approval","question"]),af={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."}},Lle=new Set(["agent"]),Fle={maxUrgency:"now",muted:[]};function _le(e,n){var a;const s=af[e.kind].label.toLowerCase();return e.kind!=="agent"||!e.agentId?s:`from ${((a=n.find(i=>i.id===e.agentId))==null?void 0:a.name)??e.agentId}`}function zle({timezone:e}){var j,y,k;const n=je(()=>T.notificationSettings(),[]),s=je(()=>T.agents(),[]),r=je(()=>T.notifications(20),[],3e4),a=je(()=>T.telegram(),[]),i=d.useRef(!1);d.useEffect(()=>{var N,b;i.current||!r.data||window.location.hash!==uv||(i.current=!0,(b=(N=document.getElementById("notifications-recent"))==null?void 0:N.scrollIntoView)==null||b.call(N,{block:"start"}))},[r.data]);const[l,o]=d.useState(null),[c,u]=d.useState(!1),[h,m]=d.useState(!1),[f,p]=d.useState(null),x=((j=n.data)==null?void 0:j.channels)??[],g=l??((y=n.data)==null?void 0:y.settings),w=N=>{g&&(m(!1),o({...g,...N}))},v=()=>{g&&(u(!0),m(!1),p(null),T.saveNotificationSettings(g).then(()=>{m(!0),o(null),n.reload()}).catch(N=>p(N instanceof pe?N.message:String(N))).finally(()=>u(!1)))};return t.jsxs(ue,{gap:"lg",children:[t.jsx(ye,{title:"Notifications",aside:"What buddi tells you when you are not looking at this page.",panel:!0,foot:t.jsx($,{variant:"accent",disabled:c||!g,onClick:v,children:"Save"}),children:t.jsxs(ue,{divided:!0,children:[t.jsx(re,{message:n.error??f}),t.jsx(ye,{title:"Where buddi reaches you",children:g?x.length===0?t.jsxs("p",{className:"ui-card-meta",children:["No channel yet, so everything waits for you here. ",t.jsx("a",{href:ze("telegram"),children:"Set up Telegram"})," and buddi can reach you on your phone."]}):t.jsxs(ue,{gap:"sm",children:[x.map(N=>{var b;return t.jsx(Gle,{channel:N,checked:(g.defaultChannel??((b=x[0])==null?void 0:b.kind))===N.kind,onPick:()=>w({defaultChannel:N.kind})},N.kind)}),t.jsx(Vle,{status:a.data,listed:x.some(N=>N.kind.startsWith("telegram"))})]}):t.jsx(Ee,{children:"Loading…"})}),t.jsx(ye,{title:"By kind",children:g?t.jsxs(ue,{gap:"sm",children:[xU.filter(N=>!Lle.has(N)).map(N=>t.jsxs("div",{className:"pref-row nt-kind",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:af[N].label}),t.jsx("span",{className:"ui-field-hint",children:af[N].hint})]}),t.jsxs("select",{"aria-label":af[N].label,value:qle(g,N,x),onChange:b=>{const S={...g.perKind};b.target.value==="default"?delete S[N]:S[N]=b.target.value,w({perKind:S})},children:[t.jsx("option",{value:"default",children:"Default"}),x.map(b=>t.jsx("option",{value:b.kind,children:b.label},b.kind)),eL.has(N)?null:t.jsx("option",{value:"off",children:"Off"})]})]},N)),t.jsx("p",{className:"ui-field-hint",children:"Off keeps it in the list below and never sends it."})]}):null}),t.jsx(ye,{title:"Messages from your agents",children:g?t.jsx(Ule,{settings:g,agents:((k=s.data)==null?void 0:k.agents)??[],onChange:w}):null}),t.jsx(ye,{title:"Focus schedules",children:g?t.jsxs(ue,{gap:"sm",children:[t.jsx(Jle,{schedules:g.schedules,onChange:N=>w({schedules:N})}),t.jsxs("p",{className:"ui-field-hint",children:["Do not disturb holds everything but approvals and questions; Urgent only also lets watchers and failures through. What waited comes in one message when the focus ends. Switch a focus by hand from your initial at the foot of the rail, or /focus on Telegram. Times are on your clock (",e,")."]}),t.jsx("div",{className:"nt-times",children:t.jsx(le,{label:"End of the day",children:t.jsx("input",{type:"time",value:g.endOfDay,onChange:N=>w({endOfDay:N.target.value})})})}),t.jsx("p",{className:"ui-field-hint",children:"At the end of the day, what could wait goes out as one message."})]}):null}),h?t.jsx(Q,{tone:"good",role:"status",children:"Saved."}):null]})}),t.jsx("div",{id:"notifications-recent",className:"notifications-recent",children:t.jsxs(ye,{title:"The last twenty",panel:!0,flush:!0,children:[t.jsx(re,{message:r.error}),r.data?r.data.notifications.length===0?t.jsx(Ee,{children:"Nothing yet. What buddi tells you will be listed here."}):t.jsx(yt,{children:r.data.notifications.map(N=>{var b;return t.jsx(pt,{title:Pu(N),sub:`${St(N.createdAt,e)} · ${_le(N,((b=s.data)==null?void 0:b.agents)??[])} · ${Yle(N,x)}`,side:t.jsx(Qle,{row:N})},N.id)})}):t.jsx(Ee,{children:"Loading…"})]})})]})}function Ule({settings:e,agents:n,onChange:s}){const r=e.perKind.agent!=="off",a=e.agents??Fle,i=o=>{const c={...e.perKind};o?delete c.agent:c.agent="off",s({perKind:c})},l=(o,c)=>s({agents:{...a,muted:c?[...new Set([...a.muted,o])]:a.muted.filter(u=>u!==o)}});return t.jsxs(ue,{gap:"sm",children:[t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:r,onChange:o=>i(o.target.checked)}),t.jsx("span",{children:"Agents may message you"})]}),t.jsxs("div",{className:"pref-row nt-kind",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:"Highest urgency"}),t.jsx("span",{className:"ui-field-hint",children:"End of the day holds every message for the end-of-day message."})]}),t.jsxs("select",{"aria-label":"Highest urgency for agents",value:a.maxUrgency,disabled:!r,onChange:o=>s({agents:{...a,maxUrgency:o.target.value==="today"?"today":"now"}}),children:[t.jsx("option",{value:"now",children:"Now"}),t.jsx("option",{value:"today",children:"End of the day"})]})]}),n.length>0?t.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Muted agents",children:n.map(o=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:a.muted.includes(o.id),disabled:!r,onChange:c=>l(o.id,c.target.checked),"aria-label":`Mute @${o.handle}`}),t.jsxs("span",{children:["Mute ",o.name," (@",o.handle,")"]})]},o.id))}):null,t.jsx("p",{className:"ui-field-hint",children:'An agent given the owner.notify tool can message you itself, signed "@agent: title" on Telegram; here the agent is named beside it. Each agent may send 6 urgent messages an hour and 20 a day. Off keeps them in the list below and never sends them.'})]})}function Ble({timezone:e}){return t.jsx(Wle,{timezone:e,onChange:()=>{}})}function Wle({timezone:e,onChange:n}){var C,A;const s=je(()=>T.telegramBot(),[]),r=je(()=>T.telegramDevices(),[]),[a,i]=d.useState(!1),[l,o]=d.useState(""),[c,u]=d.useState(!1),[h,m]=d.useState(null),[f,p]=d.useState(null),x=d.useRef(new Set),g=ZD(()=>T.telegramDevices().then(E=>E.devices.some(R=>!x.current.has(R.id))),()=>{r.reload(),n()}),w=((C=s.data)==null?void 0:C.configured)??!1,v=!w||a,j=()=>{var R;if(l.trim()===""||c)return;u(!0),m(null);const E=a&&(((R=s.data)==null?void 0:R.running)??!1);T.saveTelegramToken(l.trim()).then(P=>{o(""),i(!1),m(P.restartNeeded?{ok:!1,text:P.note??"Saved. It will be ready the next time buddi starts."}:E?{ok:!0,text:"Saved. The new bot takes over the next time buddi starts."}:{ok:!0,text:"Saved."}),s.reload(),n()}).catch(P=>m({ok:!1,text:P instanceof pe?P.message:String(P)})).finally(()=>u(!1))},y=()=>{var E;p(null),x.current=new Set((((E=r.data)==null?void 0:E.devices)??[]).map(R=>R.id)),g.ask().catch(R=>p(R instanceof pe?R.message:String(R)))},{offer:k,square:N,paired:b,stale:S}=g;return t.jsx(ye,{title:"Telegram",aside:"Talk to buddi from your phone.",panel:!0,children:t.jsxs(ue,{divided:!0,children:[t.jsx(ye,{title:"The bot",foot:v?t.jsxs(t.Fragment,{children:[a?t.jsx($,{variant:"ghost",onClick:()=>{i(!1),o("")},children:"Cancel"}):null,t.jsx($,{variant:"accent",disabled:c||l.trim()==="",onClick:j,children:"Save token"})]}):void 0,children:t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{message:s.error}),!s.data&&!s.error?t.jsx(Ee,{children:"Loading…"}):w&&!a?t.jsxs("div",{className:"nt-channel",children:[t.jsx("span",{className:"pref-label",children:(A=s.data)!=null&&A.username?`Bot: @${s.data.username}`:"A bot token is saved."}),t.jsx($,{variant:"ghost",size:"sm",onClick:()=>{i(!0),m(null)},children:"Replace token"})]}):null,v?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"ui-card-meta",children:"Ask @BotFather for a bot and paste its token here."}),t.jsx(le,{label:"Bot token",grow:!0,children:t.jsx("input",{type:"password",value:l,autoComplete:"off",spellCheck:!1,onChange:E=>o(E.target.value),onKeyDown:E=>{E.key==="Enter"&&(E.preventDefault(),j())}})})]}):null,h?t.jsx(Q,{tone:h.ok?"good":"warning",role:"status",children:h.text}):null]})}),t.jsxs(ye,{title:"Your devices",children:[t.jsx(re,{message:r.error}),r.data?r.data.devices.length===0?t.jsx("p",{className:"ui-card-meta",children:"No phone is paired yet."}):t.jsx(yt,{children:r.data.devices.map(E=>t.jsx(pt,{title:E.name??`Telegram user ${E.userId}`,sub:`Paired ${St(E.pairedAt,e)} · ${E.lastSeenAt?`last spoke ${Xe(E.lastSeenAt)}`:"has not spoken yet"}`,side:t.jsx(Hle,{id:E.id,onGone:()=>{r.reload(),n()}})},E.id))}):r.error?null:t.jsx(Ee,{children:"Loading…"})]}),t.jsx(ye,{title:"Pair a device",foot:w&&(!k||b)?t.jsx($,{variant:k?void 0:"accent",onClick:y,children:"Pair a phone"}):w&&S?t.jsx($,{variant:"accent",onClick:y,children:"New code"}):void 0,children:t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{message:f}),w?b?t.jsx(Q,{tone:"good",role:"status",children:"Paired."}):k&&S?t.jsx("p",{className:"ui-card-meta",children:"That code has run out."}):k?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"ui-card-meta",children:"Open this on your phone, then send /start to the bot."}),t.jsx(Ole,{offer:k,square:N,children:t.jsx(Kle,{text:k.link})}),t.jsxs("p",{className:"ui-field-hint",children:["The code works until ",St(k.expiresAt,e),"."]})]}):t.jsx("p",{className:"ui-card-meta",children:"Pair another phone, or the first one if you skipped it."}):t.jsx("p",{className:"ui-card-meta",children:"Save a bot token first."})]})})]})})}function Hle({id:e,onGone:n}){const[s,r]=d.useState(!1),[a,i]=d.useState(!1),[l,o]=d.useState(null);if(!s)return t.jsx($,{size:"sm",onClick:()=>r(!0),children:"Unpair"});const c=()=>{i(!0),o(null),T.unpairTelegramDevice(e).then(n).catch(u=>o(u instanceof pe?u.message:String(u))).finally(()=>i(!1))};return t.jsxs("span",{className:"nt-channel",children:[t.jsx("span",{className:"ui-field-hint",role:l?"alert":void 0,children:l??"It will no longer reach your agents."}),t.jsx($,{size:"sm",variant:"ghost",disabled:a,onClick:()=>r(!1),children:"Keep"}),t.jsx($,{size:"sm",variant:"danger",disabled:a,onClick:c,children:"Unpair"})]})}function Kle({text:e}){const[n,s]=d.useState(null),r=()=>{var a;if(!((a=navigator.clipboard)!=null&&a.writeText)){s("Select the link to copy it.");return}navigator.clipboard.writeText(e).then(()=>s("Copied."),()=>s("Select the link to copy it."))};return t.jsxs("span",{className:"nt-channel",children:[t.jsx($,{size:"sm",onClick:r,children:"Copy"}),n?t.jsx("span",{className:"ui-field-hint",role:"status",children:n}):null]})}function Vle({status:e,listed:n}){const s=ze("telegram");return e!=null&&e.running&&e.paired?t.jsx("p",{className:"ui-card-meta",children:"Telegram: paired with your phone"}):e!=null&&e.running?t.jsxs("p",{className:"ui-card-meta",children:["Telegram is running; ",t.jsx("a",{href:s,children:"pair your phone"})]}):e!=null&&e.configured?t.jsxs("p",{className:"ui-card-meta",children:["Telegram's token is saved but the bot isn't running. ",t.jsx("a",{href:s,children:"Open Telegram"})]}):e||!n?t.jsxs("p",{className:"ui-card-meta",children:["Telegram is not set up. ",t.jsx("a",{href:s,children:"Set up Telegram"})]}):null}function Gle({channel:e,checked:n,onPick:s}){const[r,a]=d.useState(!1),[i,l]=d.useState(null),o=()=>{a(!0),l(null),T.testChannel(e.kind).then(()=>l({ok:!0,text:"Sent. Check that it arrived."})).catch(c=>l({ok:!1,text:c instanceof pe?c.message:String(c)})).finally(()=>a(!1))};return t.jsxs("div",{className:"nt-channel",children:[t.jsxs("label",{children:[t.jsx("input",{type:"radio",name:"nt-default-channel",checked:n,onChange:s}),t.jsxs("span",{className:"nt-channel-text",children:[t.jsxs("span",{className:"pref-label",children:[e.label,e.where?`, ${e.where}`:""]}),t.jsxs("span",{className:"ui-field-hint",children:["The title and a few lines of each message go to ",e.label,"."]}),i?t.jsx("span",{className:"nt-channel-sent","data-tone":i.ok?void 0:"critical",role:"status",children:i.text}):null]})]}),t.jsx($,{size:"sm",disabled:r,onClick:o,children:"Send a test"})]})}function qle(e,n,s){const r=e.perKind[n];return r==="off"?eL.has(n)?"default":"off":r&&s.some(a=>a.kind===r)?r:"default"}function Yle(e,n){var s;return e.channel&&e.channel!=="dashboard"?((s=n.find(r=>r.kind===e.channel))==null?void 0:s.label)??e.channel:"dashboard"}function Qle({row:e}){return e.state==="failed"?t.jsxs("span",{className:"nt-state","data-tone":"critical",children:["Failed: ",e.error??"no reason given"]}):e.actedAt?t.jsx("span",{className:"nt-state",children:"Acted on"}):e.seenAt?t.jsx("span",{className:"nt-state",children:"Seen"}):e.state==="held"?t.jsx("span",{className:"nt-state",children:"Waiting"}):e.state==="stored"?t.jsx("span",{className:"nt-state",children:"Kept"}):e.state==="sent"?t.jsx("span",{className:"nt-state",children:"Sent"}):t.jsx("span",{className:"nt-state",children:"Not seen"})}const DE={mon:"Mon",tue:"Tue",wed:"Wed",thu:"Thu",fri:"Fri",sat:"Sat",sun:"Sun"},LE={mode:"do-not-disturb",days:[...Hj],from:"22:00",to:"07:00"};function Jle({schedules:e,onChange:n}){const s=(r,a)=>n(e.map((i,l)=>l===r?{...i,...a}:i));return t.jsxs(ue,{gap:"sm",children:[e.length===0?t.jsx("p",{className:"ui-card-meta",children:"No schedule: a focus is on only when you switch one on."}):null,e.map((r,a)=>{const i=a+1;return t.jsxs("div",{className:"nt-schedule",role:"group","aria-label":`Schedule ${i}`,children:[t.jsxs("select",{"aria-label":`Schedule ${i} mode`,value:r.mode,onChange:l=>s(a,{mode:l.target.value}),children:[t.jsx("option",{value:"do-not-disturb",children:"Do not disturb"}),t.jsx("option",{value:"urgent-only",children:"Urgent only"})]}),t.jsx("span",{className:"nt-days",children:Hj.map(l=>{const o=r.days.includes(l);return t.jsx("button",{type:"button",className:"nt-day","aria-pressed":o,"aria-label":`Schedule ${i} ${DE[l]}`,onClick:()=>s(a,{days:o?r.days.filter(c=>c!==l):Hj.filter(c=>c===l||r.days.includes(c))}),children:DE[l]},l)})}),t.jsx(le,{label:"From",children:t.jsx("input",{type:"time","aria-label":`Schedule ${i} from`,value:r.from,onChange:l=>s(a,{from:l.target.value})})}),t.jsx(le,{label:"To",children:t.jsx("input",{type:"time","aria-label":`Schedule ${i} to`,value:r.to,onChange:l=>s(a,{to:l.target.value})})}),t.jsx($,{size:"sm",variant:"ghost","aria-label":`Remove schedule ${i}`,onClick:()=>n(e.filter((l,o)=>o!==a)),children:"Remove"})]},a)}),t.jsx("div",{className:"nt-schedule-add",children:t.jsx($,{size:"sm",onClick:()=>n([...e,{...LE,days:[...LE.days]}]),children:"Add a schedule"})})]})}function Xle(e){return`Remove buddi from ${e}?`}function Zle(){const e=cc(),[n,s]=d.useState(null),[r,a]=d.useState(!1),[i,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(!1),m=()=>{h(!0),c(null),T.uninstallPlan().then(f=>{if(!f.available){l(f.reason);return}s(f),a(!0)}).catch(f=>c(f instanceof pe?f.message:String(f))).finally(()=>h(!1))};return t.jsxs(ye,{title:"Remove buddi",children:[t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{message:o}),i?t.jsx(Q,{children:i}):t.jsx("p",{className:"ui-card-meta",children:"Takes a last backup and gives you its passphrase first; nothing is deleted before you have both."}),t.jsx(te,{align:"end",children:t.jsxs($,{variant:"danger",disabled:u||i!==null,onClick:m,children:["Remove buddi from ",e,"…"]})})]}),r&&n?t.jsx(noe,{plan:n,machine:e,onClose:()=>a(!1)}):null]})}function eoe(e,n){const s=[];return e.service&&s.push(`The background service (${e.service}).`),n||(s.push(`Your data: agents, chats, memory, files and the database, in ${e.data}.`),e.keychain&&s.push(`The passwords and keys buddi keeps in the keychain (${e.keychain}).`)),e.app&&s.push(`buddi.app, moved to the Trash (${e.app}).`),s}const toe=1e3;function noe({plan:e,machine:n,onClose:s}){const[r,a]=d.useState("plan"),[i,l]=d.useState(!1),[o,c]=d.useState(!1),[u,h]=d.useState(null),[m,f]=d.useState(null),[p,x]=d.useState(null),[g,w]=d.useState(!1),v=d.useRef(null);d.useEffect(()=>()=>{v.current!==null&&window.clearTimeout(v.current)},[]);const j=S=>{T.uninstallJob(S).then(C=>{if(f(C.detail??C.phase),!C.finishedAt){v.current=window.setTimeout(()=>j(S),toe);return}if(C.phase!=="done"||!C.report){h(`The last backup did not finish: ${C.error??"no reason given"}. Nothing was removed.`),a("plan");return}x(C.report),a("words")}).catch(C=>{h(C instanceof pe?C.message:String(C)),a("plan")})},y=()=>{h(null),a("backup"),T.uninstallBackup(e.token).then(S=>j(S.job.id)).catch(S=>{h(S instanceof pe?S.message:String(S)),a("plan")})},k=()=>{h(null),a("removing"),T.uninstall({token:e.token,wroteItDown:!0,keepData:i}).catch(S=>{S instanceof pe&&S.status===0||(h(S instanceof pe?S.message:String(S)),a("words"))})},N=eoe(e,i),b=r==="plan"?t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx($,{variant:"accent",onClick:y,children:"Take the last backup"})]}):r==="words"?t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx($,{variant:"danger",disabled:!o&&(p==null?void 0:p.passphrase)!==void 0,onClick:k,children:"Remove buddi"})]}):null;return t.jsx(Gt,{title:Xle(n),onClose:r==="removing"?()=>{}:s,foot:b,children:t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{message:u}),r==="plan"||r==="backup"?t.jsxs(t.Fragment,{children:[t.jsx("p",{children:"This removes:"}),t.jsx("ul",{className:"remove-list",children:N.map(S=>t.jsx("li",{children:S},S))}),t.jsxs("p",{className:"ui-card-meta",children:["First, one last backup goes to ",t.jsx("span",{className:"mono",children:e.backups}),", where it stays."]}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:i,disabled:r!=="plan",onChange:S=>l(S.target.checked)}),t.jsx("span",{children:"Keep my data for a reinstall"})]}),r==="backup"?t.jsxs(Q,{role:"status",children:["Taking the last backup",m?`: ${m}`:"","…"]}):null]}):null,r==="words"&&p?t.jsxs(t.Fragment,{children:[t.jsxs("p",{children:["The last backup is ",t.jsx("span",{className:"mono",children:p.archive}),"."]}),p.passphrase?t.jsxs(t.Fragment,{children:[t.jsxs("p",{children:["These six words open it. They leave ",n==="this Mac"?"this Mac’s keychain":"buddi’s secret store"," with the rest, so write them down now:"]}),t.jsx("p",{className:"backup-phrase mono","aria-label":"Your backup passphrase",children:p.passphrase}),p.passphraseFile?t.jsxs("p",{className:"ui-card-meta",children:["They are also in ",t.jsx("span",{className:"mono",children:p.passphraseFile}),", which only you can read. Delete it once they are written down."]}):null,t.jsx(te,{align:"end",children:t.jsx($,{onClick:()=>{navigator.clipboard.writeText(p.passphrase).then(()=>w(!0),()=>w(!1))},children:g?"Copied":"Copy"})}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:o,onChange:S=>c(S.target.checked)}),t.jsx("span",{children:"I wrote it down"})]})]}):null,t.jsx("ul",{className:"remove-list",children:N.map(S=>t.jsx("li",{children:S},S))})]}):null,r==="removing"?t.jsx(Q,{role:"status",children:e.appFinishes?"Removing buddi. The app quits when it is done.":`Removing buddi. This page stops answering in a moment; what was removed is written to a log in ${e.backups}.`}):null]})})}function soe(){const e=je(()=>T.cliTool(),[]),[n,s]=d.useState(!1),[r,a]=d.useState(null),[i,l]=d.useState(null),o=e.data;if(!(o!=null&&o.available))return null;const c=()=>{s(!0),a(null),l(null),T.installCliTool().then(h=>{l(h.lines),e.reload()}).catch(h=>a(h instanceof pe?h.message:String(h))).finally(()=>s(!1))},u=o.installed[0];return t.jsx(ye,{title:"Command line",panel:!0,children:t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{message:r}),t.jsx("p",{className:"ui-card-meta",children:u?t.jsxs(t.Fragment,{children:["Terminal's ",t.jsx("span",{className:"mono",children:"buddi"})," is ",t.jsx("span",{className:"mono",children:u}),", and runs this app's buddi."]}):t.jsxs(t.Fragment,{children:["Use ",t.jsx("span",{className:"mono",children:"buddi"})," in Terminal: it runs this app's buddi and keeps working after updates. macOS asks for your password once."]})}),i?t.jsx(Q,{tone:"good",role:"status",children:i.join(" ")}):null,t.jsx(te,{align:"end",children:t.jsx($,{disabled:n,onClick:c,children:u?"Install Again":"Install Command Line Tool"})})]})})}const roe={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 aoe(e){const n=uW.map(r=>({id:r.id,route:ze(r.id),label:r.label,icon:roe[r.id],group:r.group})),s=[...e].sort((r,a)=>r.title.localeCompare(a.title,void 0,{sensitivity:"base"})||r.plugin.localeCompare(a.plugin)||r.id.localeCompare(a.id)).map(r=>({id:BI(r.plugin,r.id),route:Or(r.plugin,r.id),label:r.title,icon:F2(r.icon),group:"plugins"}));return[...n,...s]}function tL(e){return cW.map(n=>({id:n.id,label:n.label,entries:e.filter(s=>s.group===n.id)})).filter(n=>n.entries.length>0)}function nL(e,n,s){return n?`${e}, ${n} open`:s?`${e}, ${s}`:void 0}function ioe({entries:e,active:n,counts:s={},dots:r={},navigate:a}){var u;const i=d.useRef(null),l=tL(e),o=e.some(h=>h.id===n)?n:(u=e[0])==null?void 0:u.id,c=h=>{var x;const m=[...((x=i.current)==null?void 0:x.querySelectorAll("a.settings-nav-link"))??[]],f=m.indexOf(document.activeElement);if(f===-1)return;const p=g=>{var w;h.preventDefault(),(w=m[Math.max(0,Math.min(m.length-1,g))])==null||w.focus()};if(h.key==="ArrowDown")p(f+1);else if(h.key==="ArrowUp")p(f-1);else if(h.key==="Home")p(0);else if(h.key==="End")p(m.length-1);else if(h.key==="Enter"||h.key===" "){h.preventDefault();const g=m[f].getAttribute("href");g&&a(g)}};return t.jsx("nav",{className:"settings-nav","aria-label":"Settings sections",ref:i,onKeyDown:c,children:l.map(h=>t.jsxs("div",{className:"settings-nav-group",role:"group","aria-labelledby":`settings-nav-${h.id}`,children:[t.jsx("div",{className:"settings-nav-label",id:`settings-nav-${h.id}`,children:h.label}),h.entries.map(m=>{const f=m.id===n,p=s[m.id],x=r[m.id];return t.jsxs("a",{className:"settings-nav-link",href:m.route,"data-active":f?"true":void 0,"aria-current":f?"page":void 0,"aria-label":nL(m.label,p,x),tabIndex:m.id===o?0:-1,onClick:g=>{g.preventDefault(),a(m.route)},children:[t.jsx(ne,{name:m.icon,className:"settings-nav-icon"}),t.jsx("span",{className:"settings-nav-text",children:m.label}),p?t.jsx("span",{className:"ui-badge settings-nav-count","aria-hidden":"true",children:p>99?"99+":p}):x?t.jsx("span",{className:"ui-badge settings-nav-dot","data-kind":"dot","data-testid":"settings-nav-dot","aria-hidden":"true"}):null]},m.id)})]},h.id))})}function loe({entries:e,active:n,counts:s={},dots:r={},navigate:a}){const i=tL(e),l=e.find(o=>o.id===n)??e[0];return t.jsx("nav",{className:"settings-menu","aria-label":"Settings sections",children:t.jsxs(pd,{modal:!1,children:[t.jsx(gd,{asChild:!0,children:t.jsxs("button",{type:"button",className:"settings-menu-trigger","aria-label":`Settings section: ${(l==null?void 0:l.label)??""}`,children:[l?t.jsx(ne,{name:l.icon,className:"settings-nav-icon"}):null,t.jsx("span",{className:"settings-nav-text",children:l==null?void 0:l.label}),t.jsx(ne,{name:"chevron-down",className:"settings-menu-chevron"})]})}),t.jsx(tc,{children:t.jsx(xd,{className:"ui-menu settings-menu-list",align:"start",sideOffset:6,children:t.jsx(YB,{value:n,onValueChange:o=>{const c=e.find(u=>u.id===o);c&&a(c.route)},children:i.map((o,c)=>t.jsxs(ab,{children:[c>0?t.jsx(Xr,{className:"ui-menu-sep"}):null,t.jsx(hl,{className:"ui-menu-label",children:o.label}),o.entries.map(u=>{const h=s[u.id],m=r[u.id];return t.jsxs(QB,{value:u.id,className:"ui-menu-item settings-menu-item","data-active":u.id===n?"true":void 0,"aria-label":nL(u.label,h,m),children:[t.jsxs("span",{className:"settings-menu-entry",children:[t.jsx(ne,{name:u.icon,className:"settings-nav-icon"}),t.jsx("span",{className:"settings-nav-text",children:u.label})]}),h?t.jsx("span",{className:"ui-badge settings-nav-count","aria-hidden":"true",children:h>99?"99+":h}):m?t.jsx("span",{className:"ui-badge settings-nav-dot","data-kind":"dot","aria-hidden":"true"}):null]},u.id)})]},o.id))})})})]})})}function ooe({hash:e,timezone:n,navigate:s,agents:r,pluginPages:a}){var y,k,N;const i=dW(e),l=MI(a!==void 0),o=a??l,c=UI(e),u=c?o.find(c.plugin,c.page):void 0,h=u?null:J8(e,o.settings);d.useEffect(()=>{h&&s(h,!0)},[h,s]);const m=ts(kb),f=aoe(o.settings),x={proposals:((k=(y=je(()=>Promise.resolve().then(()=>T.proposals()),[],3e4).data)==null?void 0:y.open)==null?void 0:k.length)??0},g=je(()=>T.version(),[]),w=je(()=>Promise.resolve().then(()=>T.connectionSignals()),[],6e4),v={};g.data&&!g.data.checkout&&g.data.updateAvailable&&(v.system="a newer buddi is ready"),(((N=w.data)==null?void 0:N.signals)??[]).length>0&&(v.connections=tO);const j={entries:f,active:i,counts:x,dots:v,navigate:b=>s(b)};return t.jsxs("div",{className:"settings",children:[m?null:t.jsx(ioe,{...j}),t.jsx("div",{className:"settings-body",children:t.jsxs("div",{className:"ui-page",children:[i==="secrets"?t.jsx(nl,{before:t.jsx(Zc,{inline:!0,items:[{label:"Settings",href:Nn,onClick:()=>s(Nn)}]}),title:"Keys and secrets",lede:pD,actions:t.jsx(it,{variant:"accent",size:"sm",href:lv,onClick:b=>{b.preventDefault(),s(lv)},children:"Add a secret"})}):i==="computer"?t.jsx(nl,{before:t.jsx(Zc,{inline:!0,items:[{label:"Settings",href:Nn,onClick:()=>s(Nn)}]}),title:"Browser & apps",lede:"Where agents may look"}):i==="plugins"||i==="connections"?t.jsx(nl,{before:t.jsx(Zc,{inline:!0,items:[{label:"Settings",href:Nn,onClick:()=>s(Nn)}]}),title:i==="plugins"?"Plugins":"Connections",lede:i==="plugins"?lie:DO}):t.jsxs("header",{className:"ui-page-head",children:[t.jsx("h2",{className:"ui-page-title",children:"Settings"}),t.jsx("p",{className:"ui-page-lede",children:"How this installation runs, and where it reaches."})]}),m?t.jsx(loe,{...j}):null,u?t.jsx(DP,{plugin:u.plugin,title:u.title,navigate:s},u.plugin):null,u?t.jsx(NV,{page:u,params:wb(e),navigate:s,timezone:n,siblings:o.all.filter(b=>b.plugin===u.plugin)}):null,i==="you"?t.jsx(Fae,{embedded:!0}):null,i==="appearance"?t.jsx(coe,{railPages:o.rail}):null,i==="notifications"?t.jsx(zle,{timezone:n}):null,i==="telegram"?t.jsx(Ble,{timezone:n}):null,i==="memory"?t.jsx(pO,{embedded:!0,agents:r,timezone:n,initialTab:Aoe(e)}):null,i==="proposals"?t.jsx(Xae,{embedded:!0,plugin:iW(e)}):null,i==="accounts"?t.jsx(Jre,{embedded:!0,account:X8(e)}):null,i==="computer"?t.jsx(mY,{embedded:!0,timezone:n,navigate:s}):null,i==="secrets"?t.jsx(dae,{embedded:!0,timezone:n,secret:nW(e),adding:sW(e),navigate:s}):null,i==="connections"?t.jsx(Ane,{embedded:!0,timezone:n,connection:eW(e)}):null,i==="lock"?t.jsx(Pae,{navigate:s}):null,i==="api"?t.jsx(Lae,{timezone:n}):null,i==="watchers"?t.jsx(bae,{timezone:n,embedded:!0}):null,i==="backup"?t.jsx(Bre,{}):null,i==="plugins"?t.jsx(pie,{railPages:o.rail,settingsPages:o.settings,navigate:s,hash:e}):null,i==="system"?t.jsx(hoe,{timezone:n}):null]})})]})}function coe({railPages:e}){const[n,s]=oO();return t.jsx(ye,{title:"Appearance",aside:"Kept in this browser only. Another browser keeps its own.",panel:!0,children:t.jsxs(ue,{divided:!0,gap:"lg",children:[t.jsx($x,{label:"Theme",hint:"System follows your Mac.",children:t.jsx(cn,{label:"Theme",options:[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}],value:n.theme,onChange:r=>s({theme:r})})}),t.jsx($x,{label:"Background",hint:"Blue carries the first-run colours through the app. Sand is quieter.",children:t.jsx(cn,{label:"Background",options:[{value:"blue",label:"Blue"},{value:"sand",label:"Sand"}],value:n.ground,onChange:r=>s({ground:r})})}),t.jsx($x,{label:"Page width",hint:"How far pages stretch on a wide screen.",children:t.jsx(cn,{label:"Page width",options:[{value:"narrow",label:"Narrow"},{value:"wide",label:"Wide"},{value:"full",label:"Full"}],value:n.width,onChange:r=>s({width:r})})}),t.jsx(doe,{pages:e}),t.jsx(uoe,{})]})})}function uoe(){var c,u,h;const e=je(()=>T.overview(),[]),[n,s]=d.useState(null),r=((c=e.data)==null?void 0:c.glances)??[],a=((u=e.data)==null?void 0:u.home)??[],i=((h=e.data)==null?void 0:h.dismissed)??{};if(r.length===0&&a.length===0)return null;const l=(m,f)=>{s(m),T.setGlanceHidden(m,!f).then(()=>e.reload()).finally(()=>s(null))},o=(m,f)=>{s(`block:${m}`),T.homeDismiss(`block:${m}`,f?null:"hidden").then(()=>e.reload()).finally(()=>s(null))};return t.jsxs(t.Fragment,{children:[r.length>0?t.jsxs("div",{className:"pref-row ui-section",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:"Home glances"}),t.jsx("span",{className:"ui-field-hint",children:"The lines beside the date on Home, at most three. Kept for every browser."})]}),t.jsx(ue,{gap:"sm",children:r.map(m=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:!m.hidden,disabled:n===m.id,onChange:f=>l(m.id,f.target.checked)}),t.jsx("span",{children:m.title})]},m.id))})]}):null,a.length>0?t.jsxs("div",{className:"pref-row ui-section",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:"Home sections"}),t.jsx("span",{className:"ui-field-hint",children:"What the plugins put on Home. Kept for every browser."})]}),t.jsx(ue,{gap:"sm",children:a.map(m=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:i[`block:${m.id}`]!=="hidden",disabled:n===`block:${m.id}`,onChange:f=>o(m.id,f.target.checked)}),t.jsx("span",{children:m.title})]},m.id))})]}):null]})}function doe({pages:e}){const n=nO(),[s,r]=d.useState(null);if(e.length===0)return null;const a=(i,l)=>{r(null),Qee(i,!l).catch(o=>r(o instanceof Error?o.message:String(o)))};return t.jsxs("div",{className:"pref-row ui-section",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:"In the rail"}),t.jsx("span",{className:"ui-field-hint",children:"The plugin pages beside Home and Chat. One you turn off still opens from Settings → Plugins. Kept for every browser."})]}),t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{message:s}),e.map(i=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:!n.has(Xu(i)),onChange:l=>a(i,l.target.checked)}),t.jsx("span",{children:i.title})]},Xu(i)))]})]})}function $x({label:e,hint:n,children:s}){return t.jsxs("div",{className:"pref-row ui-section",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:e}),t.jsx("span",{className:"ui-field-hint",children:n})]}),s]})}function hoe({timezone:e}){const n=je(()=>T.overview(),[],15e3),s=je(()=>T.session(),[]),r=je(()=>T.providerAccounts(),[]),a=n.data;return t.jsxs(ue,{gap:"lg",children:[t.jsx(re,{message:n.error}),t.jsx(Soe,{}),a?t.jsx(ye,{title:"The queue",panel:!0,actions:t.jsx($,{size:"sm",variant:a.paused?"accent":void 0,onClick:()=>{T.setPaused(!a.paused).then(()=>n.reload())},children:a.paused?"Resume the queue":"Pause the queue"}),children:t.jsxs("p",{className:"ui-card-meta",children:[a.paused?"Paused. Nothing is being claimed until you resume.":"Running. Jobs are claimed as they come due."," ",a.paused?t.jsx($e,{tone:"warning",children:"paused"}):t.jsx($e,{tone:"good",children:"running"})]})}):null,t.jsxs(ye,{title:"This host",panel:!0,children:[t.jsx(on,{items:[{label:"Time zone",value:e},{label:"Server time",value:a?St(a.now,e):"…"},{label:"Bound to",value:s.data?`${s.data.host}:${s.data.port}`:"…"},{label:"Credential vault",value:r.data?poe(r.data.vault.kind):"…"}]}),r.data&&(r.data.vault.locked||r.data.vault.kind==="none")?t.jsx(Q,{tone:"warning",children:r.data.vault.advice||"Run buddi init on the host to configure secure credential storage."}):null]}),t.jsx(moe,{}),t.jsx(foe,{}),t.jsx(hZ,{}),t.jsx(soe,{}),t.jsx(Ere,{}),t.jsx(ye,{title:"Mail and sources",panel:!0,children:a?a.mail.length===0?t.jsx(Ee,{children:"No sources are installed."}):t.jsx(on,{items:a.mail.map(i=>({key:i.sourceId,label:t.jsx("span",{className:"mono",children:i.sourceId}),value:i.lastError?t.jsx("span",{className:"critical",children:i.lastError}):t.jsxs("span",{children:["polled ",Xe(i.lastRunAt)]})}))}):t.jsx(Ee,{children:"Loading…"})}),t.jsx(Zle,{})]})}function Hl(e){return e>=1e9?`${(e/1e9).toFixed(1)} GB`:e>=1e6?`${Math.round(e/1e6)} MB`:`${Math.max(1,Math.round(e/1e3))} KB`}const FE={ready:"good",downloading:"muted",absent:"muted",failed:"critical"},_E={ready:"ready",downloading:"downloading",absent:"not downloaded",failed:"failed"};function foe(){const e=je(()=>T.runtimes(),[],1e4),[n,s]=d.useState(null),[r,a]=d.useState(!1),[i,l]=d.useState(!1),o=e.data;if(!o)return null;const{onnx:c,models:u}=o,h=f=>{a(!0),s(null),f().then(()=>e.reload()).catch(p=>{s(p.message)}).finally(()=>{a(!1)})},m=c.available?t.jsxs("span",{children:[t.jsx($e,{tone:FE[c.state],children:_E[c.state]})," ",t.jsxs("span",{className:"ui-card-meta",children:["ONNX Runtime ",c.version," · ",c.state==="downloading"&&c.receivedBytes!==void 0?`${Hl(c.receivedBytes)} of ${Hl(c.downloadBytes)}`:`${Hl(c.sizeBytes)} on disk (${Hl(c.downloadBytes)} download)`]})]}):t.jsxs("span",{className:"ui-card-meta",children:["Not available on this platform (",c.platform,")."]});return t.jsx(ye,{title:"Local models",panel:!0,actions:c.available&&(c.state==="ready"||c.state==="failed")?t.jsx($,{size:"sm",variant:"ghost",disabled:r,onClick:()=>{c.state==="ready"?l(!0):h(()=>T.removeEngine())},children:"Remove"}):void 0,children:t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{message:n}),i?t.jsx(Gt,{title:"Remove the engine?",onClose:()=>l(!1),foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:()=>l(!1),children:"Keep it"}),t.jsx($,{variant:"danger",disabled:r,onClick:()=>{l(!1),h(()=>T.removeEngine())},children:"Remove"})]}),children:t.jsxs("p",{children:["Plugins that use it will ask you again, and it downloads again (",Hl(c.downloadBytes),") once you say yes."]})}):null,t.jsx(on,{items:[{label:"Engine",value:m},...u.map(f=>({key:f.id,label:t.jsx("span",{className:"mono",children:f.id}),value:t.jsxs("span",{children:[t.jsx($e,{tone:FE[f.state],children:_E[f.state]})," ",t.jsx("span",{className:"ui-card-meta",children:f.state==="failed"?f.reason:Hl(f.sizeBytes)})," ",f.state==="ready"||f.state==="failed"?t.jsx($,{size:"sm",variant:"ghost",disabled:r,onClick:()=>{h(()=>T.removeModel(f.id))},children:"Remove"}):null]})}))]}),c.state==="failed"&&c.available?t.jsx(Q,{tone:"warning",children:c.reason}):null,t.jsx("p",{className:"ui-card-meta",children:"Plugins that run models on this computer share one engine. It is downloaded for this platform only, after you approve a plugin's card, and checked against its pinned checksum."})]})})}function moe(){var u;const e=je(()=>T.service(),[],1e4),[n,s]=d.useState(null),[r,a]=d.useState(!1),[i,l]=d.useState(null),o=(u=e.data)!=null&&u.supervised?e.data.status:void 0;if(!o)return null;const c=h=>{a(!0),l(null),rc({kind:h},()=>T.serviceAction(h)).then(()=>{s(null)}).catch(m=>{l(m.message),e.reload()}).finally(()=>{a(!1)})};return t.jsx(ye,{title:"Service",panel:!0,children:t.jsxs(ue,{divided:!0,children:[t.jsx(ye,{children:t.jsx(on,{items:[{label:"Database",value:t.jsx(zE,{state:o.database,pid:o.databasePid})},{label:"Gateway",value:t.jsx(zE,{state:o.gateway,pid:o.gatewayPid})},{label:"Supervisor",value:t.jsxs("span",{className:"mono",children:["pid ",o.supervisorPid]})}]})}),t.jsx(ye,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{message:i}),n?t.jsx(Q,{tone:"warning",role:"alert",children:n==="stop"?"Stopping the gateway closes this dashboard. The database keeps running; run buddi in a terminal to bring the dashboard back.":"Restarting the gateway takes a few seconds. This page waits for it and comes back by itself."}):t.jsx("p",{className:"ui-card-meta",children:"Stopping the gateway ends this dashboard until buddi is run again."}),t.jsx(te,{align:"end",children:n?t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",disabled:r,onClick:()=>{s(null),l(null)},children:"Cancel"}),t.jsx($,{variant:n==="stop"?"danger":"accent",disabled:r,onClick:()=>{c(n)},children:n==="stop"?"Stop it":"Restart it"})]}):t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:()=>{s("stop")},children:"Stop gateway"}),t.jsx($,{variant:"accent",onClick:()=>{s("restart")},children:"Restart gateway"})]})})]})})]})})}function zE({state:e,pid:n}){return t.jsxs("span",{children:[t.jsx($e,{tone:e==="running"?"good":e==="stopped"?"warning":e==="failed"?"critical":"muted",children:e})," ",n===null?t.jsx("span",{className:"ui-card-meta",children:"no process"}):t.jsxs("span",{className:"mono",children:["pid ",n]})]})}function poe(e){return e==="keychain"?"macOS Keychain":e==="file"?"Encrypted file vault":e==="none"?"None":e}const goe=2e3,xm={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."},xoe=new Set(["done","failed","rolled-back"]),joe="The check asks the npm registry for the newest version and sends nothing else.",voe="This takes a backup, installs the new version and restarts buddi. This page waits for it and comes back by itself.",yoe=6e4;function Tx(e,n){return e?{button:n?`Update to ${n}`:"Update",warning:`buddi takes a backup first, installs ${n??"the new version"} and restarts; it takes a minute or two. This page waits for it and comes back by itself.`}:{button:n?`Upgrade to ${n}`:"Upgrade",warning:voe}}const woe="A checkout upgrades with git pull, then buddi upgrade in a terminal.",boe=15*6e4;function koe(e,n=!1){const s=e.step==="starting"?"while starting":`at ${e.step??"an unknown step"}`,r=`The upgrade to ${e.to} failed ${s}: ${e.error??"no reason given"}. The backup taken first is ${e.backup??"not available"}. `;return n?r+`To go back to ${e.from}, choose Advanced → Restart with the Previous Version in the buddi menu.`:r+"Run buddi doctor in a terminal; it prints the way back."}function UE(e,n=Date.now()){const s=e[e.length-1];if((s==null?void 0:s.outcome)!=="failed")return null;const r=Date.parse(s.finishedAt??s.startedAt);return Number.isFinite(r)&&n-r<boe?s:null}function Noe(e,n){const[s,r]=d.useState(void 0),[a,i]=d.useState(null),l=d.useRef(n);return l.current=n,d.useEffect(()=>{if(!e){r(void 0);return}let o=!1,c=!1;const u=()=>{o||c||T.upgradeJob(e).then(m=>{var f;o||(r(m),i(null),II({step:xm[m.phase]??m.detail??m.phase}),(xoe.has(m.phase)||m.finishedAt)&&(o=!0,m.phase==="failed"&&(Ro(),(f=l.current)==null||f.call(l,m))))}).catch(m=>{o||(m instanceof pe&&m.status!==0&&m.status<500?(o=!0,Ro(),i(m.message)):c=!0)})};u();const h=window.setInterval(u,goe);return()=>{o=!0,window.clearInterval(h)}},[e]),{job:s,error:a}}function Soe(){var y;const[e,n]=d.useState(!1),s=je(()=>T.version(),[],e?yoe:void 0);d.useEffect(()=>{var k;((k=s.data)==null?void 0:k.app)===!0&&n(!0)},[(y=s.data)==null?void 0:y.app]);const[r,a]=d.useState(null),[i,l]=d.useState(!1),[o,c]=d.useState(!1),[u,h]=d.useState(null),[m,f]=d.useState(null),p=d.useCallback(k=>{a(null),f(k)},[]),x=Noe(r,p),g=s.data,w=()=>{c(!0),h(null),T.checkVersion().catch(k=>h(k instanceof pe?k.message:String(k))).finally(()=>{c(!1),s.reload()})},v=k=>{c(!0),h(null),T.setVersionCheck(k).catch(N=>h(N instanceof pe?N.message:String(N))).finally(()=>{c(!1),s.reload()})},j=()=>{c(!0),h(null),f(null),rc({kind:"upgrade",line:g!=null&&g.latest?`Upgrading to ${g.latest}…`:"Upgrading…",step:xm.starting,patienceMs:RI},()=>T.startUpgrade(g==null?void 0:g.latest)).then(k=>{var N;l(!1),a(((N=k==null?void 0:k.job)==null?void 0:N.id)??null)}).catch(k=>h(k instanceof pe?k.message:String(k))).finally(()=>c(!1))};return g!=null&&g.checkout?t.jsx(ye,{title:"Version",panel:!0,children:t.jsxs(ue,{divided:!0,children:[t.jsx(ye,{children:t.jsx(on,{items:[{label:"Running",value:t.jsx("span",{className:"mono",children:g.current})}]})}),t.jsx(ye,{children:t.jsx("p",{className:"ui-card-meta",children:woe})})]})}):t.jsx(ye,{title:"Version",panel:!0,children:t.jsxs(ue,{divided:!0,children:[t.jsx(ye,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{message:s.error??u}),t.jsx(on,{items:[{label:"Running",value:g?t.jsx("span",{className:"mono",children:g.current}):"…"},{label:"Newest",value:g?g.updateAvailable&&g.latest?t.jsxs("span",{children:["A newer buddi is available: ",t.jsx("span",{className:"mono",children:g.latest})]}):g.processing?t.jsx("span",{children:g.processing.message}):g.checkedAt?t.jsxs("span",{children:["This is the latest, as of ",Xe(g.checkedAt),"."]}):t.jsx("span",{children:"Not checked yet."}):"…"}]}),g!=null&&g.error?t.jsxs(Q,{tone:"warning",children:["The last check did not get an answer: ",g.error]}):null,t.jsx(te,{align:"end",children:t.jsx($,{disabled:o,onClick:w,children:"Check now"})})]})}),t.jsx(ye,{children:t.jsxs(ue,{gap:"sm",children:[t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:(g==null?void 0:g.checkEnabled)??!1,disabled:o||!g,onChange:k=>v(k.target.checked)}),t.jsx("span",{children:"Check once a day"})]}),t.jsx("p",{className:"ui-card-meta",children:joe})]})}),g!=null&&g.updateAvailable&&g.latest&&g.latestNotes?t.jsx(ye,{title:`What changes in ${g.latest}`,children:t.jsx(pr,{text:g.latestNotes})}):null,t.jsx(ye,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(Coe,{...x,job:x.job??m??void 0}),!x.job&&!m&&!x.error&&g&&UE(g.history)?t.jsx(Q,{tone:"critical",role:"alert",children:koe(UE(g.history),g.app===!0)}):null,i?t.jsx(Q,{tone:"warning",role:"alert",children:Tx((g==null?void 0:g.app)===!0,g==null?void 0:g.latest).warning}):null,t.jsx(te,{align:"end",children:i?t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",disabled:o,onClick:()=>l(!1),children:"Cancel"}),t.jsx($,{variant:"accent",disabled:o,onClick:j,children:Tx((g==null?void 0:g.app)===!0,g==null?void 0:g.latest).button})]}):g!=null&&g.processing&&r===null?null:t.jsx($,{variant:"accent",disabled:o||r!==null||!(g!=null&&g.updateAvailable),onClick:()=>l(!0),children:Tx((g==null?void 0:g.app)===!0,g!=null&&g.updateAvailable?g.latest:void 0).button})})]})}),g&&g.history.length>0?t.jsx(ye,{title:"Upgrades so far",children:t.jsx(on,{items:g.history.slice().reverse().map(k=>({key:k.startedAt,label:t.jsxs("span",{className:"mono",children:[k.from," → ",k.to]}),value:t.jsx(Eoe,{attempt:k})}))})}):null]})})}function Coe({job:e,error:n}){return n?t.jsx(re,{message:n}):e?e.phase==="failed"?t.jsxs(Q,{tone:"critical",role:"alert",children:[xm.failed," ",e.error??""," buddi is still running on the version it had."]}):t.jsx(Q,{tone:e.phase==="done"?"good":void 0,role:"status",children:xm[e.phase]??e.detail??e.phase}):null}function Eoe({attempt:e}){return t.jsxs("span",{children:[t.jsx($e,{tone:e.outcome==="done"?"good":e.outcome==="failed"?"critical":"warning",children:e.outcome})," ",Xe(e.startedAt),e.step?`, at ${e.step}`:"",e.error?`: ${e.error}`:"",e.backup?t.jsxs("span",{className:"ui-card-meta",children:[" Backup: ",t.jsx("span",{className:"mono",children:e.backup})]}):null]})}function Aoe(e){var s;return((s=/[?&]tab=(people|preferences|notes)\b/.exec(e))==null?void 0:s[1])??"people"}const at={back:"Back",checking:"Checking…",mailbox:{sheet:"Add a mailbox",which:"Which mailbox?",providers:{gmail:{name:"Gmail",line:"Google Mail, or Google Workspace.",mark:"G"},icloud:{name:"iCloud",line:"An @icloud.com, @me.com or @mac.com address.",mark:"i"},fastmail:{name:"Fastmail",line:"Fastmail, with your own domain or theirs.",mark:"F"},other:{name:"Other",line:"Any mailbox that offers IMAP.",mark:"@"}},address:"Address",password:"App password",otherPassword:"Password",how:{gmail:{text:"Google wants an app password, not your usual one. 2-Step Verification must be on.",link:"Make one",href:"https://myaccount.google.com/apppasswords"},icloud:{text:"Apple wants an app-specific password, made under Sign-In and Security.",link:"How",href:"https://support.apple.com/en-us/102654"},fastmail:{text:"Fastmail wants an app password with Mail (IMAP/SMTP) access.",link:"How",href:"https://www.fastmail.help/hc/en-us/articles/360058752854"},other:null},server:"Server details",serverHint:"Left empty, buddi tries imap. and smtp. at your domain.",imapHost:"IMAP host",smtpHost:"SMTP host",submit:"Add it",reading:"Mail Triage is reading it.",brings:"Adding it also brings in Mail Triage, who reads what arrives and sorts it for you.",noTriage:e=>`Saved. Mail Triage didn’t start (${e.replace(/[.\s]+$/,"")}); it waits for you on Home.`,later:"More in Mail settings later."},calendar:{sheet:"Link your calendar",ask:"Your calendar’s private link",google:"Sign in with Google",googleLine:"Reads and, when you approve, changes your Google calendars.",or:"or paste a private link",field:"Private link",placeholder:"Paste the whole link",where:"Where do I find it?",help:[{name:"iCloud",text:"In the Calendar app or at icloud.com/calendar, share the calendar, tick Public Calendar, then copy the link."},{name:"Google",text:"Google Calendar on the web → Settings → pick the calendar → Integrate calendar → copy “Secret address in iCal format”."},{name:"Fastmail",text:"Settings → Calendars → Share beside the calendar → turn on the iCal link for anyone with it → copy it."}],submit:"Link it",starting:"Starting…",continue:"Continue to Google",waiting:"Waiting for Google… This finishes by itself when Google sends you back.",reading:"Signed in. Reading your calendars…",again:"Try again",found:e=>`Found ${e} ${e===1?"calendar":"calendars"}.`,events:e=>`Found your calendar: ${e} ${e===1?"event":"events"}.`,later:"More in Calendar settings later."},bank:{sheet:"Your bank",ask:"Statements, not a bank sign-in",line:"Finance never signs in to a bank, so nothing leaves this computer. Once we are done, hand me a statement — a PDF, a photo or your bank’s CSV export — and I read your accounts in.",ok:"Got it"}};function lu(e){return e instanceof pe||e instanceof Error?e.message:String(e)}function Ji({state:e,children:n}){return e==="bad"?t.jsx("p",{className:"frs-line","data-tone":"bad",role:"alert",children:n}):t.jsxs("div",{className:"wiz-busy",role:"status","aria-live":"polite",children:[t.jsxs("span",{className:"wiz-pulse","data-done":e==="good"?"true":void 0,"aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]}),t.jsx("span",{children:n})]})}const $oe=1400;function sL(e,n){const s=d.useRef(n);s.current=n,d.useEffect(()=>{if(!e)return;const r=window.setTimeout(()=>s.current(),$oe);return()=>window.clearTimeout(r)},[e])}function rL(){const e=d.useRef(null);return d.useEffect(()=>{const n=window.requestAnimationFrame(()=>{var s;return(s=e.current)==null?void 0:s.focus()});return()=>window.cancelAnimationFrame(n)},[]),e}const Toe={gmail:{imapHost:"imap.gmail.com",imapPort:993,smtpHost:"smtp.gmail.com",smtpPort:465},icloud:{imapHost:"imap.mail.me.com",imapPort:993,smtpHost:"smtp.mail.me.com",smtpPort:587},fastmail:{imapHost:"imap.fastmail.com",imapPort:993,smtpHost:"smtp.fastmail.com",smtpPort:465}},Roe=["gmail","icloud","fastmail","other"],Rx={plugin:"email",agent:"mail-triage"};function Ioe({onClose:e,onAdded:n}){const[s,r]=d.useState(null);return t.jsx(Ye,{title:at.mailbox.sheet,onClose:e,children:s===null?t.jsxs("div",{className:"wiz-sheet-body",children:[t.jsx("h3",{className:"frs-ask",children:at.mailbox.which}),t.jsx("div",{className:"frs-choices",role:"group","aria-label":at.mailbox.which,children:Roe.map(a=>{const i=at.mailbox.providers[a];return t.jsxs("button",{type:"button",className:"wiz-opt frs-choice",onClick:()=>r(a),children:[t.jsx("span",{className:"frs-mark","data-provider":a,"aria-hidden":"true",children:i.mark}),t.jsxs("span",{className:"frs-choice-text",children:[t.jsx("span",{className:"wiz-opt-title",children:i.name}),t.jsx("span",{className:"wiz-opt-line",children:i.line})]}),t.jsx(ne,{name:"chevron-right"})]},a)})}),t.jsx("p",{className:"frs-later",children:at.mailbox.later})]}):t.jsx(Poe,{provider:s,onBack:()=>r(null),onClose:e,onAdded:n},s)})}function Poe({provider:e,onBack:n,onClose:s,onAdded:r}){const a=rL(),[i,l]=d.useState(""),[o,c]=d.useState(""),[u,h]=d.useState(""),[m,f]=d.useState(""),[p,x]=d.useState({kind:"idle"});sL(p.kind==="good",s);const[g,w]=d.useState(!1);d.useEffect(()=>{let N=!1;return Promise.resolve().then(()=>nt.agents()).then(b=>{N||w(!((b==null?void 0:b.agents)??[]).some(S=>S.id===Rx.agent))}).catch(()=>{N||w(!1)}),()=>{N=!0}},[]);const v=at.mailbox.providers[e],j=at.mailbox.how[e],y=i.trim()!==""&&o.trim()!==""&&p.kind!=="busy"&&p.kind!=="good",k=()=>{if(!y)return;x({kind:"busy"});const N=e==="other"?{...u.trim()?{imapHost:u.trim()}:{},...m.trim()?{smtpHost:m.trim()}:{}}:Toe[e];Promise.resolve().then(()=>T.pageAct("email",{tool:"email.add_account",args:{address:i.trim(),password:o,...N}})).then(async b=>{const S=b.result??{};c("");let C=at.mailbox.reading;S.triage==="needs-agent"&&(C=await Promise.resolve().then(()=>T.acceptPluginAgent(Rx.plugin,Rx.agent)).then(()=>(window.dispatchEvent(new Event(Rs)),at.mailbox.reading)).catch(A=>at.mailbox.noTriage(lu(A)))),x({kind:"good",line:C}),r(S.address??i.trim().toLowerCase())}).catch(b=>x({kind:"bad",line:lu(b)}))};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"wiz-sheet-body",children:[t.jsxs("h3",{className:"frs-ask",children:[t.jsx("span",{className:"frs-mark","data-provider":e,"aria-hidden":"true",children:v.mark}),v.name]}),t.jsxs("form",{className:"frs-form",onSubmit:N=>{N.preventDefault(),k()},children:[t.jsx(le,{label:at.mailbox.address,children:t.jsx("input",{ref:a,type:"email",autoComplete:"email",spellCheck:!1,value:i,onChange:N=>l(N.target.value)})}),t.jsx(le,{label:e==="other"?at.mailbox.otherPassword:at.mailbox.password,hint:j?t.jsxs(t.Fragment,{children:[j.text," ",t.jsx("a",{href:j.href,target:"_blank",rel:"noreferrer",children:j.link})]}):void 0,children:t.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,value:o,onChange:N=>c(N.target.value)})}),e==="other"?t.jsx(Vt,{summary:at.mailbox.server,children:t.jsxs("div",{className:"frs-form",children:[t.jsx("p",{className:"frs-later",children:at.mailbox.serverHint}),t.jsx(le,{label:at.mailbox.imapHost,children:t.jsx("input",{spellCheck:!1,placeholder:"imap.example.com",value:u,onChange:N=>h(N.target.value)})}),t.jsx(le,{label:at.mailbox.smtpHost,children:t.jsx("input",{spellCheck:!1,placeholder:"smtp.example.com",value:m,onChange:N=>f(N.target.value)})})]})}):null,t.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]}),p.kind==="busy"?t.jsx(Ji,{state:"busy",children:at.checking}):null,p.kind==="good"?t.jsx(Ji,{state:"good",children:p.line}):null,p.kind==="bad"?t.jsx(Ji,{state:"bad",children:p.line}):null,p.kind==="idle"&&g?t.jsx("p",{className:"frs-later",children:at.mailbox.brings}):null,t.jsx("p",{className:"frs-later",children:at.mailbox.later})]}),t.jsx("div",{className:"ui-sheet-foot",children:t.jsxs(te,{children:[t.jsxs($,{variant:"ghost",onClick:n,disabled:p.kind==="busy",children:[t.jsx(ne,{name:"chevron-left"}),at.back]}),t.jsx(ht,{}),t.jsx($,{variant:"accent",disabled:!y,onClick:k,children:at.mailbox.submit})]})})]})}const aL=2e3,BE=8*6e4;function Moe(e,n){let s="";try{s=new URL(e.trim().replace(/^webcals?:\/\//i,"https://")).hostname.toLowerCase()}catch{s=""}const r=/google\./.test(s)?"Google calendar":/icloud\.com$|me\.com$/.test(s)?"iCloud calendar":/fastmail\./.test(s)?"Fastmail calendar":/outlook\.|office365\.|live\.com$/.test(s)?"Outlook calendar":"My calendar",a=new Set(n.map(i=>i.toLowerCase()));if(!a.has(r.toLowerCase()))return r;for(let i=2;;i++)if(!a.has(`${r} ${i}`.toLowerCase()))return`${r} ${i}`}function Ooe({onClose:e,onLinked:n}){var L,M,z;const s=rL(),[r,a]=d.useState(null),[i,l]=d.useState(""),[o,c]=d.useState({kind:"idle"});sL(o.kind==="good",e);const u=()=>T.pageQuery("calendar","settings").then(D=>D.data??{});d.useEffect(()=>{let D=!1;return u().then(K=>{D||a(K)}).catch(()=>{D||a({})}),()=>{D=!0}},[]);const h=D=>{c({kind:"good",line:D}),n(D)},m=((L=r==null?void 0:r.calendars)==null?void 0:L.length)??0,f=()=>{if(i.trim()===""||o.kind==="busy"||o.kind==="good")return;c({kind:"busy",line:at.checking});const D=Moe(i,((r==null?void 0:r.calendars)??[]).map(K=>K.name));Promise.resolve().then(()=>T.pageAct("calendar",{tool:"calendar.add",args:{name:D,link:i.trim()}})).then(K=>{var W;l("");const B=((W=K.result)==null?void 0:W.note)??"",se=/(\d+) events? read/.exec(B);h(se?at.calendar.events(Number(se[1])):at.calendar.found(1))}).catch(K=>c({kind:"bad",line:lu(K)}))},[p,x]=d.useState(null),[g,w]=d.useState(!1),[v,j]=d.useState(0),y=d.useRef(!1),k=d.useRef(void 0),N=(r==null?void 0:r.googleAvailable)===!0,b=d.useRef(null);d.useEffect(()=>{if(!N)return;let D=!1;const K=async se=>{var W,xe;if(!(D||y.current)){window.clearTimeout(k.current);try{const me=H=>{const de=H==null?void 0:H[0];return de&&de.state==="waiting"&&de.url?de:void 0};let ie=se?void 0:me((W=(await T.pageQuery("calendar","sign_in")).data)==null?void 0:W.rows);if(!ie){if(D||y.current)return;await T.pageAct("calendar",{tool:"calendar.google_sign_in",args:{}}),ie=me((xe=(await T.pageQuery("calendar","sign_in")).data)==null?void 0:xe.rows)}if(D||y.current)return;if(!ie)throw new Error("no address to open");b.current={id:ie.id,at:Date.now()},x({id:ie.id,url:ie.url}),w(!1),k.current=window.setTimeout(()=>void K(!0),BE)}catch{D||(b.current=null,x(null),w(!0))}}},B=()=>{const se=b.current;document.visibilityState!=="visible"||!se||y.current||Date.now()-se.at>=BE&&K(!0)};return document.addEventListener("visibilitychange",B),K(!1),()=>{D=!0,window.clearTimeout(k.current),document.removeEventListener("visibilitychange",B);const se=b.current;b.current=null,se&&!y.current&&T.pageAct("calendar",{tool:"calendar.google_cancel",args:{id:se.id}}).catch(()=>{})}},[N,v]);const S=D=>{c({kind:"bad",line:D}),y.current=!1,x(null),j(K=>K+1)},[C,A]=d.useState(0),E=o.kind==="google"?((M=o.signIn)==null?void 0:M.id)??null:null;d.useEffect(()=>{if(C===0)return;let D=!1,K=!1,B=!1;const se=()=>{D=!0,window.clearInterval(xe)},W=()=>{D||K||(K=!0,T.pageQuery("calendar","sign_in").then(async me=>{var ge,Ue,G,ae;if(D)return;const ie=((Ue=(ge=me.data)==null?void 0:ge.rows)==null?void 0:Ue[0])??null;if(!ie)return;if(ie.state==="waiting"){c(J=>{var Ne;return J.kind==="google"&&((Ne=J.signIn)==null?void 0:Ne.url)===ie.url?J:{kind:"google",signIn:ie}});return}if(ie.state==="failed"){se(),S(ie.problem||ie.note);return}se(),ie.state==="received"&&!B&&(B=!0,c({kind:"busy",line:at.calendar.reading}),await T.pageAct("calendar",{tool:"calendar.google_finish",args:{id:ie.id}}));const H=await u();await T.pageAct("calendar",{tool:"calendar.google_dismiss",args:{id:ie.id}}).catch(()=>{});const de=(((G=H.calendars)==null?void 0:G.length)??0)-m;h(at.calendar.found(de>0?de:((ae=H.calendars)==null?void 0:ae.length)??0))}).catch(me=>{se(),S(lu(me))}).finally(()=>{K=!1}))},xe=window.setInterval(W,aL);return W(),()=>{D=!0,window.clearInterval(xe)}},[C]);const R=()=>{!p||o.kind==="google"||(y.current=!0,window.clearTimeout(k.current),c({kind:"google",signIn:{id:p.id,url:p.url,state:"waiting",note:"",problem:""}}),A(D=>D+1))},P=()=>{y.current=!0,window.clearTimeout(k.current),c({kind:"busy",line:at.calendar.starting}),Promise.resolve().then(()=>T.pageAct("calendar",{tool:"calendar.google_sign_in",args:{}})).then(()=>{c({kind:"google",signIn:null}),A(D=>D+1)}).catch(D=>S(lu(D)))},O=()=>{const D=E??(o.kind!=="good"?p==null?void 0:p.id:void 0);window.clearTimeout(k.current),D&&T.pageAct("calendar",{tool:"calendar.google_cancel",args:{id:D}}).catch(()=>{}),e()},I=o.kind==="busy"||o.kind==="google"||o.kind==="good",F=o.kind==="google"?(z=o.signIn)==null?void 0:z.url:o.kind==="busy"||o.kind==="good"||p==null?void 0:p.url,U=o.kind==="google"&&p===null;return t.jsxs(Ye,{title:at.calendar.sheet,onClose:O,children:[t.jsxs("div",{className:"wiz-sheet-body",children:[t.jsx("h3",{className:"frs-ask",children:at.calendar.ask}),r!=null&&r.googleAvailable?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"frs-google",children:[F?t.jsxs(it,{variant:"accent",size:"lg",href:F,target:"_blank",rel:"noreferrer",onClick:R,children:[U?at.calendar.continue:at.calendar.google,t.jsx(ne,{name:"external"})]}):t.jsxs($,{variant:"accent",size:"lg",disabled:I||!g,onClick:P,children:[at.calendar.google,t.jsx(ne,{name:"external"})]}),t.jsx("span",{className:"wiz-opt-line",children:at.calendar.googleLine})]}),t.jsx("div",{className:"frs-or",children:at.calendar.or})]}):null,t.jsxs("form",{className:"frs-form",onSubmit:D=>{D.preventDefault(),f()},children:[t.jsx(le,{label:at.calendar.field,children:t.jsx("input",{ref:s,type:"url",inputMode:"url",autoComplete:"off",spellCheck:!1,placeholder:at.calendar.placeholder,value:i,disabled:I,onChange:D=>l(D.target.value)})}),t.jsx(Vt,{summary:at.calendar.where,children:t.jsx("dl",{className:"frs-help",children:at.calendar.help.map(D=>t.jsxs("div",{children:[t.jsx("dt",{children:D.name}),t.jsx("dd",{children:D.text})]},D.name))})}),t.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]}),o.kind==="busy"?t.jsx(Ji,{state:"busy",children:o.line}):null,o.kind==="google"?t.jsx(Ji,{state:"busy",children:at.calendar.waiting}):null,o.kind==="good"?t.jsx(Ji,{state:"good",children:o.line}):null,o.kind==="bad"?t.jsx(Ji,{state:"bad",children:o.line}):null,t.jsx("p",{className:"frs-later",children:at.calendar.later})]}),t.jsx("div",{className:"ui-sheet-foot",children:t.jsx(te,{align:"end",children:t.jsx($,{variant:"accent",disabled:I||i.trim()==="",onClick:f,children:at.calendar.submit})})})]})}function Doe({onClose:e,onUnderstood:n}){return t.jsxs(Ye,{title:at.bank.sheet,onClose:e,children:[t.jsxs("div",{className:"wiz-sheet-body",children:[t.jsx("h3",{className:"frs-ask",children:at.bank.ask}),t.jsx("p",{className:"frs-text",children:at.bank.line})]}),t.jsx("div",{className:"ui-sheet-foot",children:t.jsx(te,{align:"end",children:t.jsx($,{variant:"accent",onClick:()=>{n(),e()},children:at.bank.ok})})})]})}function Loe(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 Foe({progress:e}){return t.jsxs(ue,{gap:"sm",children:[t.jsx("span",{role:"status",children:Loe(e)}),t.jsx(Sb,{value:(e==null?void 0:e.percent)??0,label:"Fetching the browser"})]})}const jm=["hello","brain","takeOn","reach","assistant","handover"],iL={hello:"you",brain:"model",takeOn:"take-on",reach:"reach",assistant:"agent",handover:"hello"};function lL(e){return((e==null?void 0:e.accounts)??[]).filter(n=>n.enabled&&n.configured&&n.removalPending!==!0)}function _oe(e){var i,l,o;const n=lL(e.accounts),s=e.assistant?(((i=e.accounts)==null?void 0:i.bindings)??[]).find(c=>c.agentId===e.assistant.id):void 0,r=(s==null?void 0:s.accountId)??((o=(l=e.onboarding)==null?void 0:l.details)==null?void 0:o.accountId);if(!r)return;const a=n.find(c=>c.id===r);if(a)return{accountId:a.id,label:a.label,model:(s==null?void 0:s.model)??a.defaultModel}}function oL(e){var i,l,o,c,u;const n=_oe(e),s=e.onboarding&&!e.onboarding.needs.agent?e.assistant:void 0,r=((i=e.onboarding)==null?void 0:i.details)??{},a=((l=e.onboarding)==null?void 0:l.stepsDone)??[];return{...(o=e.owner)!=null&&o.preferredName?{name:e.owner.preferredName}:{},...(c=e.owner)!=null&&c.timezone?{clock:e.owner.timezone}:{},...n?{brain:n}:{},...Array.isArray(r.takeOn)?{takeOn:r.takeOn}:s?{takeOn:[]}:{},...r.reach?{reach:r.reach}:a.includes("reach")||s?{reach:{}}:{},...a.includes("browser")||((u=r.reach)==null?void 0:u.browser)===!0?{browser:e.browser??"other"}:{},...s?{assistant:s}:{}}}function cL(e,n){return n==="hello"?typeof e.name=="string"&&e.name!==""&&typeof e.clock=="string"&&e.clock!=="":n==="brain"?e.brain!==void 0:n==="takeOn"?e.takeOn!==void 0:n==="reach"?e.reach!==void 0:n==="assistant"?e.assistant!==void 0:!1}function lf(e){return jm.find(n=>!cL(e,n))??"handover"}function zoe(e){const n=jm.indexOf(e);return n>0?jm[n-1]:null}function WE(e,n,s){return s===n?"now":cL(e,s)?"done":"todo"}function Uoe(e,n){return{...e}}const Ty="buddi.firstRun.restore";function Ry(e){try{e===null?window.sessionStorage.removeItem(Ty):window.sessionStorage.setItem(Ty,e)}catch{}}function uL(){try{return window.sessionStorage.getItem(Ty)}catch{return null}}function Boe(e){const n=oL(e),s=lf(n);return{answers:n,open:s,stay:s!=="handover"}}function Woe(e){return e.trim().startsWith("sk-ant-")?"anthropic":"openai"}function Hoe(e){const n=e.normalize("NFKD").replace(/[̀-ͯ]/g,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^[^a-z]+/,"").replace(/-+$/,"").slice(0,20).replace(/-+$/,"");return n===""?"assistant":n}const Koe=6e4,Voe=5*6e4,dL=1500,Goe=2e3,qoe="(max-width: 720px)";function dc(){const e=d.useRef(null);return d.useEffect(()=>{let n=0,s=0;const r=l=>{const o=l.ownerDocument.activeElement;if(o===null||o===l.ownerDocument.body||o===l.ownerDocument.documentElement)return!0;const c=l.closest('[role="dialog"]');return c!==null&&o.tagName==="BUTTON"&&o.closest('[role="dialog"]')===c},a=()=>{const l=e.current;l&&r(l)&&l.focus()},i=()=>{a(),s=window.setTimeout(a,0)};return typeof window.requestAnimationFrame=="function"?n=window.requestAnimationFrame(i):i(),window.addEventListener("focus",a),()=>{n&&window.cancelAnimationFrame(n),window.clearTimeout(s),window.removeEventListener("focus",a)}},[]),e}const Yk=d.createContext({busy:0,report:()=>{}});function Yoe({children:e}){const[n,s]=d.useState(0),r=d.useCallback(i=>s(l=>Math.max(0,l+(i?1:-1))),[]),a=d.useMemo(()=>({busy:n,report:r}),[n,r]);return t.jsx(Yk.Provider,{value:a,children:e})}function $t({children:e}){const{busy:n}=d.useContext(Yk);return t.jsxs("div",{className:"wiz-say",children:[t.jsx(jd,{state:n>0?"working":"idle",size:"sm",className:"wiz-say-face"}),t.jsx("div",{className:"wiz-bubble",children:e})]})}function xt({children:e}){return t.jsx(t.Fragment,{children:e})}function Ts({line:e}){const{report:n}=d.useContext(Yk);return d.useEffect(()=>(n(!0),()=>n(!1)),[n]),t.jsxs("div",{className:"wiz-busy",role:"status","aria-live":"polite",children:[t.jsxs("span",{className:"wiz-pulse","aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]}),e]})}const Qk=d.createContext(null);function Pn({children:e,actions:n}){const s=d.useContext(Qk),r=n==null?null:s?qo.createPortal(n,s):t.jsx("div",{className:"wiz-dock-inline",children:n});return t.jsxs(t.Fragment,{children:[e?t.jsx("div",{className:"wiz-ask",children:e}):null,r]})}function Gs({onClick:e,disabled:n}){return t.jsxs($,{variant:"ghost",size:"lg",onClick:e,disabled:n,children:[t.jsx(ne,{name:"chevron-left"}),_.back]})}function hc({children:e,onClick:n,disabled:s}){return t.jsxs($,{variant:"accent",size:"lg",onClick:n,disabled:s,children:[e,t.jsx(ne,{name:"arrow"})]})}function Qoe({navigate:e,timezone:n}){var bn,sn,ce,Me,tt,Tt,bt;const s=ts(qoe),[r,a]=d.useState(void 0);d.useEffect(()=>{T.session().then(Pe=>a(Pe.platform)).catch(()=>{})},[]);const[i,l]=d.useState({}),[o,c]=d.useState(null),[u,h]=d.useState(void 0),[m,f]=d.useState(void 0),[p,x]=d.useState([]),[g,w]=d.useState(null),[v,j]=d.useState(null),[y,k]=d.useState(!1),[N,b]=d.useState(null),[S,C]=d.useState(null),[A,E]=d.useState(null),[R,P]=d.useState(null),[O,I]=d.useState(()=>uL()?"running":"idle"),[F,U]=d.useState({}),[L,M]=d.useState([]),[z,D]=d.useState(0),K=d.useRef(void 0),[B,se]=d.useState(null),[W,xe]=d.useState(null),me=d.useCallback(()=>{Promise.resolve().then(()=>T.takeOnProgress()).then(Pe=>{Pe&&Array.isArray(Pe.plugins)&&se(Pe)}).catch(()=>{})},[]);d.useEffect(()=>{if(!(B!=null&&B.running))return;const Pe=window.setInterval(me,Goe);return()=>window.clearInterval(Pe)},[B==null?void 0:B.running,me]);const ie=d.useMemo(()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone||n}catch{return n}},[n]),H=d.useRef(e);H.current=e;const de=d.useCallback(async(Pe=!0,st=!1)=>{var Dn,as,js,Ps,Wn,ft,fe,ct,Et;const[_e,en,ee,rt,On,$n]=await Promise.all([T.onboarding().catch(()=>{}),T.owner().catch(()=>{}),T.providerAccounts().catch(()=>{}),nt.agents().catch(()=>{}),T.browser().catch(()=>{}),T.providers().catch(()=>{})]);h(ee),Array.isArray(_e==null?void 0:_e.offers)&&xe(_e.offers);const Ae=(as=(Dn=$n==null?void 0:$n.providers.find(gn=>gn.kind==="anthropic"))==null?void 0:Dn.defaultModel)==null?void 0:as.trim();f(Ae||void 0),x((en==null?void 0:en.zones)??[]),b(((js=_e==null?void 0:_e.details)==null?void 0:js.conversationId)??null);const De=(rt==null?void 0:rt.agents.find(gn=>gn.id===rt.defaultAgentId))??(rt==null?void 0:rt.agents[0]);De&&w(De),C(_e&&!_e.needs.agent&&De?{id:De.id,name:De.name,avatar:((Ps=De.avatar)==null?void 0:Ps.kind)==="emoji"?De.avatar.value:"",description:De.description,...De.picture?{picture:De.picture}:{}}:null),Array.isArray((Wn=_e==null?void 0:_e.details)==null?void 0:Wn.takeOn)&&me();const gt={onboarding:_e,owner:en,accounts:ee,browser:(ft=On==null?void 0:On.browser)==null?void 0:ft.engine,...De?{assistant:{id:De.id,name:De.name,avatar:((fe=De.avatar)==null?void 0:fe.kind)==="emoji"?De.avatar.value:""}}:{}};if(st){const gn=Boe(gt);if(l(gn.answers),c(gn.open),!gn.stay){const is=(ct=_e==null?void 0:_e.details)==null?void 0:ct.conversationId;H.current(is&&De?ut(De.id,is):Un,!0)}return}if(Pe&&(_e==null?void 0:_e.state)==="done"){const gn=(Et=_e.details)==null?void 0:Et.conversationId;H.current(gn&&De?ut(De.id,gn):Un,!0);return}if(!Pe)return;const Mt=oL(gt);l(Mt),c(gn=>gn??lf(Mt))},[]);d.useEffect(()=>{de()},[de]);const ge=(Pe,st={})=>{Promise.resolve().then(()=>T.onboardingStep(iL[Pe],st)).catch(()=>{})},Ue=Pe=>lf(Pe)==="brain"&&F.brain?{...Pe,brain:F.brain}:Pe,G=(Pe,st)=>{const _e=Ue(st);_e.brain&&(K.current=_e.brain),j(null),M([]),l(_e),Pe==="brain"&&_e.brain?ge(Pe,{accountId:_e.brain.accountId}):Pe==="reach"?ge(Pe,_e.reach?{reach:_e.reach}:{}):Pe!=="takeOn"&&ge(Pe),c(lf(_e))},ae=(Pe,st)=>{j(null),l(st),st.brain&&(K.current=st.brain),Pe==="brain"&&st.brain&&ge(Pe,{accountId:st.brain.accountId})},J=Pe=>{j(null),l(st=>Uoe(st)),c(Pe)},Ne=()=>{if(!o)return;const Pe=zoe(o==="handover"?"handover":o);Pe&&J(Pe)},Ie=()=>{const Pe=i.brain??K.current,st=((B==null?void 0:B.plugins)??[]).filter(_e=>_e.state==="ready").map(_e=>_e.title);j(null),U({}),M([]),l({}),c("hello"),D(_e=>_e+1),(async()=>{var Ae;const[_e,en,ee]=await Promise.all([Promise.resolve().then(()=>T.providerAccounts()).catch(()=>{}),Promise.resolve().then(()=>T.telegram()).catch(()=>{}),Promise.resolve().then(()=>T.browser()).catch(()=>{})]),rt=lL(_e),On=Pe&&rt.some(De=>De.id===Pe.accountId)?Pe:void 0;_e&&h(_e),U(On?{brain:On}:{});const $n=[...new Set(rt.map(De=>De.label)),...en!=null&&en.paired?[_.startOver.telegram]:[],...((Ae=ee==null?void 0:ee.browser)==null?void 0:Ae.engine)==="chromium"?[_.startOver.browser]:[],...st];M($n.length>0?[_.startOver.said($n.join(", "))]:[])})()},Y=()=>{k(!0),T.skipOnboarding().then(()=>e(Un)).catch(Pe=>j(Pe instanceof pe?Pe.message:String(Pe))).finally(()=>k(!1))},X=je(()=>T.version().catch(()=>({current:""})),[]),oe=d.useRef(null);d.useEffect(()=>{oe.current&&(oe.current.scrollTop=0)},[o]);const ve=O==="running",be=Object.keys(i).length===0,Ce={answers:i,accounts:u,claudeModel:m,zones:p,browserZone:ie,assistantAgent:g,met:N,onMet:b,existing:S,progress:B,offers:W,onProgress:me,navigate:e,onSettled:Pe=>o&&G(o,Pe),onKept:Pe=>o&&ae(o,Pe),onBack:Ne,onTrouble:j,onReload:()=>void de(!1),onPickAnotherBrain:()=>J("brain"),onSpoken:P},we=(i.takeOn??[]).map(Pe=>{var st;return((st=_f.find(_e=>_e.id===Pe))==null?void 0:st.title)??Pe}),He=(B==null?void 0:B.plugins)??[],Ze=He.filter(Pe=>Pe.state==="ready").length,Se=He.length===0?null:B!=null&&B.running?_.takeOn.installing(Ze,He.length):Ze===He.length?_.takeOn.installed:null,Le=[(bn=i.reach)!=null&&bn.phone?_.reach.done.phone:null,(sn=i.reach)!=null&&sn.mailbox?_.reach.done.mailbox:null,(ce=i.reach)!=null&&ce.app||(Me=i.reach)!=null&&Me.browser?_.reach.done.app:null].filter(Pe=>Pe!==null),Ve={hello:{answer:_.hello.answer(i.name??""),sub:i.clock??null},brain:{answer:_.brain.answer(((tt=i.brain)==null?void 0:tt.label)??"")},takeOn:{answer:_.takeOn.answer(we),sub:Se},reach:{answer:_.reach.answer(Le)},assistant:{answer:((Tt=i.assistant)==null?void 0:Tt.name)??""}},Qe=jm.filter(Pe=>Pe!=="handover"),wt=o===null||o==="handover"?Qe.length:Qe.indexOf(o),dt=Math.min(wt,Qe.length-1),qt=R?null:t.jsxs("div",{className:"wiz-map-out",children:[t.jsx("button",{type:"button",className:"wiz-link",disabled:y,onClick:Y,children:_.later}),o==="hello"&&be&&O==="idle"?t.jsx("button",{type:"button",className:"wiz-link",onClick:()=>I("form"),children:_.restore.offer}):!ve&&o!==null&&!(o==="hello"&&be)?t.jsx("button",{type:"button",className:"wiz-link",disabled:y,onClick:Ie,children:_.startOver.link}):null]}),vt=r===void 0||r==="darwin"?_.tagline:_.taglineElsewhere,Dt=o&&o!=="handover"?t.jsx("span",{className:"wiz-count",children:_.count(wt+1)}):t.jsx("span",{className:"wiz-count"});return t.jsx(Qk.Provider,{value:A,children:t.jsx(Yoe,{children:t.jsxs(sP,{className:"wiz-ground",children:[t.jsx("div",{className:"wiz",ref:oe,"data-phone":s?"true":void 0,"data-testid":"meet",children:t.jsxs("div",{className:"wiz-frame",children:[s?t.jsxs("div",{className:"wiz-strip",children:[t.jsx(Bu,{size:"sm"}),t.jsx("span",{className:"wiz-dots","aria-label":o&&o!=="handover"?_.count(wt+1):void 0,children:Qe.map(Pe=>t.jsx("i",{"data-state":WE(i,o,Pe)},Pe))}),t.jsx("span",{className:"wiz-strip-name",children:o&&o!=="handover"?_.strip(wt+1,_.chapters[wt]??""):_.handover.starterLabel})]}):t.jsxs("nav",{className:"wiz-map","aria-label":"Chapters",children:[t.jsxs("div",{className:"wiz-head",children:[t.jsx(Bu,{size:"lg"}),t.jsxs("div",{children:[t.jsx("div",{className:"wiz-head-name",children:"buddi"}),t.jsx("div",{className:"wiz-head-line",children:vt}),(bt=X.data)!=null&&bt.current?t.jsxs("div",{className:"wiz-head-version mono",children:["buddi ",X.data.current]}):null]})]}),Qe.map((Pe,st)=>{const _e=ve?Pe==="hello"?"now":"todo":WE(i,o,Pe),en=Ve[Pe];return t.jsxs("div",{className:"wiz-ch","data-state":_e,"aria-current":_e==="now"?"step":void 0,children:[t.jsx("span",{className:"wiz-num","data-state":_e,children:_e==="done"?t.jsx(ne,{name:"check",size:12}):st+1}),t.jsxs("span",{className:"wiz-ch-label",children:[_e==="done"?en.answer:_.chapters[st],_e==="done"&&en.sub?t.jsx("span",{className:"wiz-ch-sub",children:en.sub}):null]}),_e==="done"&&!ve?t.jsx("button",{type:"button",className:"wiz-link",onClick:()=>J(Pe),children:_.change}):null]},Pe)}),t.jsx("div",{className:"wiz-map-spacer"}),t.jsx("div",{className:"wiz-map-note",children:_.mapNotes[dt]}),qt]}),t.jsx("div",{className:"wiz-stage",role:"main",children:t.jsxs("div",{className:"wiz-column","data-width":o==="hello"?"narrow":o==="brain"?"mid":"wide",children:[t.jsxs(AW,{dock:t.jsxs(t.Fragment,{children:[Dt,t.jsx("div",{className:"wiz-dock-actions",ref:E})]}),children:[ve?t.jsx(Ace,{onDone:Pe=>{I("idle"),M([...Pe?[_.restore.welcome(Pe)]:[],_.restore.keys]),de(!0,!0)},onFailed:Pe=>{I("idle"),j(Pe)}}):o==="hello"?t.jsx(Joe,{...Ce}):o==="brain"?t.jsx(Zoe,{...Ce}):o==="takeOn"?t.jsx(gce,{...Ce}):o==="reach"?t.jsx(xce,{...Ce}):o==="assistant"?t.jsx(Nce,{...Ce}):o==="handover"?t.jsx(Sce,{...Ce}):t.jsx(Ts,{}),L.length>0||v?t.jsxs(xt,{children:[L.map(Pe=>t.jsx($t,{children:Pe},Pe)),v?t.jsx($t,{children:v}):null]}):null]},`${z}-${o??""}-${ve?"r":""}`),s?t.jsx("div",{className:"wiz-phone-out",children:qt}):null]})})]})}),O==="form"?t.jsx(Ece,{onCancel:()=>I("idle"),onStarted:()=>I("running"),onTrouble:j}):null]})})})}function fc({children:e}){return t.jsx("h1",{className:"wiz-title",children:e})}function HE(e){try{return Lt(new Date,e)}catch{return""}}function Joe({answers:e,zones:n,browserZone:s,onSettled:r,onTrouble:a}){const i=dc(),[l,o]=d.useState(e.name??""),[c,u]=d.useState(e.clock??s),[h,m]=d.useState(!1),[f,p]=d.useState(!1),x=()=>{const g=l.trim();g===""||f||(p(!0),T.setOwner({preferredName:g,timezone:c}).then(()=>r({...e,name:g,clock:c})).catch(w=>a(w instanceof pe?w.message:String(w))).finally(()=>p(!1)))};return t.jsxs(t.Fragment,{children:[t.jsx(fc,{children:_.hello.title}),t.jsx(xt,{children:_.hello.opening.map(g=>t.jsx($t,{children:g},g))}),t.jsxs(Pn,{actions:t.jsx(hc,{onClick:x,disabled:f||l.trim()==="",children:_.hello.submit}),children:[t.jsxs("div",{className:"wiz-pair",children:[t.jsx(le,{label:_.name.label,children:t.jsx("input",{ref:i,placeholder:_.name.placeholder,maxLength:80,value:l,onChange:g=>o(g.target.value),onKeyDown:g=>{g.key==="Enter"&&(g.preventDefault(),x())}})}),h?t.jsx(le,{label:_.clock.label,hint:_.clock.hint(HE(c)),children:t.jsx("select",{value:c,onChange:g=>u(g.target.value),children:(n.includes(c)?n:[c,...n]).map(g=>t.jsx("option",{value:g,children:g},g))})}):t.jsx(le,{label:_.clock.label,hint:_.clock.hint(HE(c)),action:t.jsx($,{size:"lg",onClick:()=>m(!0),children:_.clock.change}),children:t.jsx("input",{value:c,readOnly:!0})})]}),t.jsx("div",{className:"wiz-foot",children:_.hello.foot})]})]})}const Xoe={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 Zoe(e){const{accounts:n,answers:s,onSettled:r,onKept:a,onReload:i,onBack:l}=e,[o,c]=d.useState(null),[u,h]=d.useState("key"),[m,f]=d.useState(null),[p,x]=d.useState(!1),[g,w]=d.useState(null),[v,j]=d.useState(null),[y,k]=d.useState(null),N=(n==null?void 0:n.anthropicOAuthEnabled)===!0,b=(n==null?void 0:n.codexEnabled)===!0,S=n==null?void 0:n.gemini,[C,A]=d.useState(null);d.useEffect(()=>{let z=!1;const D=()=>{Promise.resolve().then(()=>T.ollama()).then(B=>{!z&&B&&w(B)}).catch(()=>{}),Promise.resolve().then(()=>T.mlxh()).then(B=>{!z&&B&&j(B)}).catch(()=>{z||j({running:!1,baseUrl:"",manager:!1,models:[]})})};D();const K=window.setInterval(D,4e3);return()=>{z=!0,window.clearInterval(K)}},[]);const E=async z=>{if(s.assistant??e.existing)try{await T.bindBrain({accountId:z.accountId,model:z.model})}catch(D){return D instanceof pe?D.message:String(D)}return i(),a({...s,brain:z}),C==null||C.close(),A(null),c(null),k(null),null},R=async(z,D,K)=>{x(!0),f(null);try{const B=await T.saveProviderAccount(z);let se=await T.testProviderAccount(B.id),W=z.defaultModel,xe=!1;if(se.state!=="connected"&&K&&K!==W&&lD(se)){const ie=(await T.providerAccounts()).accounts.find(H=>H.id===B.id);ie&&(await T.saveProviderAccount({id:ie.id,revision:ie.revision,label:ie.label,kind:ie.kind,auth:ie.auth,baseUrl:ie.baseUrl,defaultModel:K,enabled:ie.enabled}),se=await T.testProviderAccount(B.id),se.state==="connected"&&(W=K,xe=!0))}if(se.state!=="connected"){try{const ie=(await T.providerAccounts()).accounts.find(H=>H.id===B.id);ie&&await T.removeProviderAccount(B.id,ie.revision)}catch{}return f(se.message),se}const me=await E({accountId:B.id,label:D,model:W,...xe?{freeTier:xe}:{}});return me&&f(me),se}catch(B){return f(B instanceof pe?B.message:String(B)),null}finally{x(!1)}},P=async z=>{x(!0),f(null);try{const D=await T.saveProviderAccount(z);let K;try{K=await T.testProviderAccount(D.id)}finally{try{const B=(await T.providerAccounts()).accounts.find(se=>se.id===D.id);B&&await T.removeProviderAccount(D.id,B.revision)}catch{}}return K.state!=="connected"&&f(K.message),K}catch(D){return f(D instanceof pe?D.message:String(D)),null}finally{x(!1)}},O=(z,D,K)=>{if(z.length<=1){R(D(z[0]??""),K);return}k({models:z,make:D,label:K})},I=z=>{if(z===o)return;C==null||C.close(),A(z==="free"&&typeof window.open=="function"?window.open("","_blank"):null),f(null),k(null),h("key"),c(z)},F=()=>{C==null||C.close(),A(null),k(null),f(null),c(null)},U=fL(g,v),L=["free",...N?["claude"]:[],...b?["chatgpt"]:[],"key","local"];let M=null;return y?M=t.jsxs(t.Fragment,{children:[t.jsx(xt,{children:t.jsx($t,{children:_.brain.model.ask})}),p?t.jsx(Ts,{line:_.brain.checking.service}):m?t.jsx(xt,{children:t.jsx($t,{children:m})}):null,t.jsx(ece,{busy:p,models:y.models,onBack:F,onUse:z=>void R(y.make(z),y.label)})]}):o==="key"?M=t.jsxs(t.Fragment,{children:[t.jsx(cn,{label:_.brain.keyKinds.label,value:u,onChange:z=>{f(null),h(z)},options:[{value:"key",label:_.brain.keyKinds.key},...S?[{value:"gemini",label:_.brain.keyKinds.gemini}]:[],{value:"service",label:_.brain.keyKinds.service}]}),u==="gemini"&&S?t.jsx(nce,{busy:p,problem:m,preset:S,onBack:F,onUse:R},"gemini"):u==="service"?t.jsx(ace,{busy:p,problem:m,address:(g==null?void 0:g.cloudBaseUrl)??"",onBack:F,onOffer:O,onTrial:P,onUse:R},"service"):t.jsx(tce,{busy:p,problem:m,onBack:F,onUse:R},"key")]}):o==="local"?M=t.jsx(rce,{busy:p,problem:m,probe:g,mlxh:v,onBack:F,onOffer:O,onUse:R,onCloud:()=>I("free")}):o==="free"?M=t.jsx(lce,{...e,busy:p,consent:C,onBack:F,onConnected:E}):o==="chatgpt"?M=t.jsx(uce,{...e,busy:p,consent:C,onBack:F,onConnected:E}):o==="claude"&&(M=t.jsx(hce,{...e,busy:p,problem:m,onBack:F,onConnected:E})),t.jsxs(t.Fragment,{children:[t.jsx(fc,{children:_.brain.title}),t.jsx(xt,{children:t.jsx($t,{children:_.brain.ask})}),t.jsx("div",{className:"wiz-grid",role:"group","aria-label":_.brain.ask,children:L.map(z=>{const D=Xoe[z],K=_.brain.cards[z];return t.jsxs("button",{type:"button",className:"wiz-opt","aria-pressed":o===z,"data-wide":D.wide?"true":void 0,onClick:()=>I(z),children:[t.jsx("span",{className:"wiz-glyph","data-tone":D.tone,"aria-hidden":"true",children:t.jsx(ne,{name:D.icon})}),t.jsxs("span",{children:[t.jsx("span",{className:"wiz-opt-title",children:K.title}),t.jsx("span",{className:"wiz-opt-line",children:z==="local"?U:K.line}),"pill"in K?t.jsx($e,{tone:"good",children:K.pill}):null]})]},z)})}),M,M===null&&s.brain?t.jsxs(xt,{children:[t.jsx($t,{children:s.brain.freeTier?_.brain.worksOnFlash(s.brain.model):_.brain.works(s.brain.model)}),t.jsx(oce,{...e}),s.brain.label===_.brain.ollama.label||s.brain.label===_.brain.mlxh.label?t.jsx(Q,{tone:"warm",title:_.brain.ollama.honestTitle,children:_.brain.ollama.honest}):null]}):null,M===null?t.jsx(Pn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Gs,{onClick:l}),t.jsx(hc,{onClick:()=>s.brain&&r(s),disabled:!s.brain,children:_.brain.submit})]})}):null]})}function ece({busy:e,models:n,onBack:s,onUse:r}){const[a,i]=d.useState(n[0]??"");return t.jsx(Pn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Gs,{onClick:s,disabled:e}),t.jsx($,{variant:"accent",size:"lg",disabled:e||a==="",onClick:()=>r(a),children:_.brain.model.submit})]}),children:t.jsx(le,{label:_.brain.model.label,grow:!0,children:t.jsx("select",{value:a,onChange:l=>i(l.target.value),children:n.map(l=>t.jsx("option",{value:l,children:l},l))})})})}function hL({models:e,picked:n,disabled:s,onPick:r}){return t.jsx(le,{label:_.brain.model.label,grow:!0,children:t.jsx("select",{value:n,disabled:s,onChange:a=>r(a.target.value),children:e.map(a=>t.jsx("option",{value:a,children:a},a))})})}function tce({busy:e,problem:n,onBack:s,onUse:r}){const a=dc(),[i,l]=d.useState(""),[o,c]=d.useState(null),[u,h]=d.useState(!1),[m,f]=d.useState([]),[p,x]=d.useState(""),[g,w]=d.useState(!1),v=e||u,j=!g&&n!==null&&m.length>0,y=o??Woe(i),k=()=>{const N=i.trim();N===""||v||(h(!0),w(!1),(async()=>{var A;let b=y==="anthropic"?"claude-sonnet-5":"gpt-5",S=m;if(j&&p!=="")b=p;else try{const E=await T.probeModels({kind:y,auth:"api-key",secret:N});b=((A=E.models.find(R=>R.isDefault))==null?void 0:A.id)??b,S=E.models.map(R=>R.id)}catch{S=[]}h(!1);const C=await r({label:y==="anthropic"?_.brain.key.anthropic:_.brain.key.openai,kind:y,auth:"api-key",baseUrl:"",defaultModel:b,enabled:!0,secret:N},y==="anthropic"?_.brain.key.anthropic:_.brain.key.openai);if(!(!C||C.state==="connected")){if(Gw(C)){w(!0),f([]);return}f(S.includes(b)||S.length===0?S:[b,...S]),x(b)}})())};return t.jsxs(t.Fragment,{children:[v?t.jsx(xt,{children:t.jsx(Ts,{line:_.brain.checking.key})}):g?t.jsx(xt,{children:t.jsx($t,{children:_.brain.key.refused})}):n?t.jsx(xt,{children:t.jsx($t,{children:n})}):null,t.jsxs(Pn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Gs,{onClick:s,disabled:v}),t.jsx($,{variant:"accent",size:"lg",disabled:v||i.trim()==="",onClick:k,children:j?_.brain.model.retry:_.brain.key.submit})]}),children:[t.jsx(le,{label:_.brain.key.field,grow:!0,children:t.jsx("input",{ref:a,type:"password",autoComplete:"off",spellCheck:!1,placeholder:_.brain.key.placeholder,value:i,onChange:N=>{l(N.target.value),f([])},onKeyDown:N=>{N.key==="Enter"&&(N.preventDefault(),k())}})}),j?t.jsx(hL,{models:m,picked:p,disabled:v,onPick:x}):null,t.jsxs("button",{type:"button",className:"wiz-link",onClick:()=>c(y==="anthropic"?"openai":"anthropic"),children:[y==="anthropic"?_.brain.key.anthropic:_.brain.key.openai," · ",_.brain.key.which]})]})]})}function nce({busy:e,problem:n,preset:s,onBack:r,onUse:a}){const i=dc(),[l,o]=d.useState(""),[c,u]=d.useState(!1),[h,m]=d.useState([]),[f,p]=d.useState(""),x=e||c,g=n!==null&&h.length>0,w=()=>{const v=l.trim();v===""||x||(u(!0),(async()=>{let j=sD,y;if(g&&f!=="")j=f;else try{const N=(await T.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,secret:v})).models.map(b=>b.id);j=rD(N)??j,y=iD(j)?aD(N):void 0,m(Qre(N)),p(y??j)}catch{}u(!1),await a({label:_.brain.gemini.label,kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,defaultModel:j,enabled:!0,secret:v},_.brain.gemini.label,y)})())};return t.jsxs(t.Fragment,{children:[x?t.jsx(xt,{children:t.jsx(Ts,{line:_.brain.checking.gemini})}):n?t.jsx(xt,{children:t.jsx($t,{children:n})}):null,t.jsxs(Pn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Gs,{onClick:r,disabled:x}),t.jsx($,{variant:"accent",size:"lg",disabled:x||l.trim()==="",onClick:w,children:_.brain.gemini.submit})]}),children:[t.jsx(le,{label:_.brain.gemini.field,grow:!0,children:t.jsx("input",{ref:i,type:"password",autoComplete:"off",spellCheck:!1,placeholder:_.brain.gemini.placeholder,value:l,onChange:v=>o(v.target.value),onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),w())}})}),g?t.jsx(le,{label:_.brain.model.label,grow:!0,children:t.jsx("select",{value:f,disabled:x,onChange:v=>p(v.target.value),children:h.map(v=>t.jsx("option",{value:v,children:v},v))})}):null,t.jsx("a",{className:"wiz-link",href:s.keyUrl,target:"_blank",rel:"noreferrer",children:_.brain.gemini.get})]})]})}function fL(e,n){return e===null||n===null?_.brain.local.looking:!e.running&&!n.running?_.brain.local.missing:_.brain.local.found({...e.running?{ollama:e.models.length}:{},...n.running?{mlxh:n.models.length}:{}})}const sce=1e3;function KE({command:e}){const[n,s]=d.useState(!1);return d.useEffect(()=>{if(!n)return;const r=window.setTimeout(()=>s(!1),1600);return()=>window.clearTimeout(r)},[n]),t.jsxs("div",{className:"rs-cmd",children:[t.jsx("code",{className:"rs-cmd-text",children:e}),t.jsx($,{size:"sm",onClick:()=>{var r;return void((r=navigator.clipboard)==null?void 0:r.writeText(e).then(()=>s(!0),()=>{}))},children:n?_.brain.ollama.copied:_.brain.ollama.copy})]})}const VE=e=>(e/1e9).toFixed(1);function rce({busy:e,problem:n,probe:s,mlxh:r,onBack:a,onOffer:i,onUse:l,onCloud:o}){const c=(s==null?void 0:s.models)??[],u=hy(r),h=s==null?void 0:s.machine,[m,f]=d.useState(null),[p,x]=d.useState(null),g=d.useRef(null),w=m??(s==null?void 0:s.pull)??null,v=(w==null?void 0:w.state)==="pulling",j=O=>({label:_.brain.ollama.label,kind:"openai-compatible",auth:"none",baseUrl:(s==null?void 0:s.baseUrl)??"",defaultModel:O,enabled:!0});d.useEffect(()=>{if(!v)return;let O=!1;const I=window.setInterval(()=>{T.ollamaPullState().then(F=>{!O&&F.pull&&f(F.pull)},()=>{})},sce);return()=>{O=!0,window.clearInterval(I)}},[v]),d.useEffect(()=>{(m==null?void 0:m.state)!=="done"||!s||g.current===m.model||(g.current=m.model,l(j(m.model),_.brain.ollama.label))},[m==null?void 0:m.state,m==null?void 0:m.model,s]);const y=O=>{x(null),g.current=null,T.ollamaPull(O).then(I=>f(I.pull),I=>x(I instanceof pe?I.message:String(I)))},k=()=>{!(r!=null&&r.running)||!u||l({label:_.brain.mlxh.label,kind:"openai-compatible",auth:"none",baseUrl:r.baseUrl,defaultModel:u,enabled:!0},_.brain.mlxh.label)},N=s!==null&&r!==null&&!s.running&&!r.running,b=()=>{s&&i(c,j,_.brain.ollama.label)},S=(h==null?void 0:h.platform)==="darwin"?"this Mac":"this computer",C=(s==null?void 0:s.running)===!0&&c.length===0,A=h!==void 0&&!(r!=null&&r.running)&&(C||N||v),E=h!=null&&h.cloudSuggested?h.memoryGb<7?"memory":"gpu":null,R=h?t.jsxs("div",{className:"wiz-foot",children:[_.brain.ollama.cloud(E,h.memoryGb)," ",t.jsx("button",{type:"button",className:"wiz-link",onClick:o,children:_.brain.ollama.useCloud})]}):null;let P=null;if(A&&h){const O=(w==null?void 0:w.state)==="failed"?w:null;if(v&&w){const I=w.total>0?w.completed/w.total:0;P=t.jsxs("div",{className:"wiz-stack",children:[t.jsxs("div",{className:"wiz-busy","data-boxed":"true",children:[t.jsxs("span",{className:"wiz-pulse","aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]}),t.jsx("span",{children:_.brain.ollama.fetching(w.model,VE(w.completed),w.total>0?VE(w.total):"")}),t.jsxs("span",{className:"wiz-busy-side",children:[Math.round(I*100),"%"]})]}),t.jsx(Sb,{value:I*100,label:_.brain.ollama.fetch(w.model)}),t.jsx("div",{className:"wiz-foot",children:_.brain.ollama.fetchingFoot})]})}else if(C){const I=(O==null?void 0:O.model)??h.recommended.model;P=t.jsxs("div",{className:"wiz-stack",children:[t.jsx(xt,{children:t.jsx($t,{children:O?_.brain.ollama.failed(O.error??""):_.brain.ollama.empty(S,h.memoryGb,h.recommended.model,h.recommended.sizeGb)})}),p?t.jsx(Q,{tone:"critical",children:p}):null,t.jsxs(te,{children:[t.jsx("span",{className:"wiz-foot",children:_.brain.ollama.emptyFoot(S)}),t.jsx(ht,{}),t.jsx($,{variant:"accent",size:"lg",disabled:e,onClick:()=>y(I),children:O?_.brain.ollama.again:_.brain.ollama.fetch(I)})]}),R]})}else h.installed?P=t.jsxs("div",{className:"wiz-stack",children:[t.jsx(xt,{children:t.jsx($t,{children:_.brain.ollama.stopped(h.platform)})}),h.platform==="linux"?t.jsx(KE,{command:"ollama serve"}):null,R]}):P=t.jsxs("div",{className:"wiz-stack",children:[t.jsx(xt,{children:t.jsx($t,{children:_.brain.ollama.missing(S)})}),h.install.command?t.jsx(KE,{command:h.install.command}):null,t.jsxs(te,{children:[t.jsx("span",{className:"wiz-foot",children:_.brain.ollama.missingHow(h.platform,S)}),t.jsx(ht,{}),h.platform==="linux"?null:t.jsx(it,{size:"lg",href:h.install.url,target:"_blank",rel:"noreferrer",children:_.brain.ollama.download})]}),R]})}return t.jsxs(t.Fragment,{children:[e?t.jsx(xt,{children:t.jsx(Ts,{line:_.brain.checking.ollama})}):n?t.jsx(xt,{children:t.jsx($t,{children:n})}):null,P,t.jsx(Pn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Gs,{onClick:a,disabled:e}),s!=null&&s.running&&c.length>0?t.jsx($,{variant:r!=null&&r.running?void 0:"accent",size:"lg",disabled:e,onClick:b,children:_.brain.ollama.connect}):null,r!=null&&r.running?t.jsx($,{variant:"accent",size:"lg",disabled:e||!u,onClick:k,children:_.brain.mlxh.connect}):null,N&&s&&!h?t.jsx(it,{variant:"accent",size:"lg",href:s.downloadUrl,target:"_blank",rel:"noreferrer",children:_.brain.ollama.download}):null]}),children:A?null:t.jsxs("span",{className:"wiz-foot",children:[fL(s,r),r!=null&&r.running&&!u?` ${_.brain.mlxh.noBrain}`:"",N&&(r!=null&&r.baseUrl)?` ${EO(r.baseUrl)}`:""]})})]})}function ace({busy:e,problem:n,address:s,onBack:r,onOffer:a,onTrial:i,onUse:l}){const o=dc(),[c,u]=d.useState(s),[h,m]=d.useState(""),[f,p]=d.useState(!1),[x,g]=d.useState([]),[w,v]=d.useState(""),[j,y]=d.useState(!1),k=e||f,N=!j&&n!==null&&x.length>0,b=()=>{c.trim()===""||k||(p(!0),y(!1),(async()=>{var F;const S=h.trim()?"api-key":"none",C=U=>({label:_.brain.service.label,kind:"openai-compatible",auth:S,baseUrl:c.trim(),defaultModel:U,enabled:!0,...h.trim()?{secret:h.trim()}:{}}),A=(U,L,M)=>{if(!(!U||U.state==="connected")){if(Gw(U)){y(!0),g([]);return}g(L),v(M)}};if(S==="api-key"&&N&&w!==""){p(!1),A(await l(C(w),_.brain.service.label),x,w);return}let E=[],R;try{const U=await T.probeModels({kind:"openai-compatible",auth:S,baseUrl:c.trim(),...h.trim()?{secret:h.trim()}:{}});E=U.models.map(L=>L.id),R=(F=U.models.find(L=>L.isDefault))==null?void 0:F.id}catch{}p(!1);const P=R?[R]:E;if(S==="none"){a(P,C,_.brain.service.label);return}const O=P[0]??"";if(P.length<=1){A(await l(C(O),_.brain.service.label),E,O);return}const I=await i(C(O));(I==null?void 0:I.state)==="connected"?a(P,C,_.brain.service.label):A(I,E,O)})())};return t.jsxs(t.Fragment,{children:[k?t.jsx(xt,{children:t.jsx(Ts,{line:_.brain.checking.service})}):j?t.jsx(xt,{children:t.jsx($t,{children:_.brain.key.refused})}):n?t.jsx(xt,{children:t.jsx($t,{children:n})}):null,t.jsxs(Pn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Gs,{onClick:r,disabled:k}),t.jsx($,{variant:"accent",size:"lg",disabled:k||c.trim()==="",onClick:b,children:N?_.brain.model.retry:_.brain.service.submit})]}),children:[t.jsx(le,{label:_.brain.service.address,grow:!0,children:t.jsx("input",{ref:o,value:c,placeholder:_.brain.service.addressPlaceholder,onChange:S=>{u(S.target.value),g([])}})}),t.jsx(le,{label:_.brain.service.key,children:t.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,value:h,onChange:S=>{m(S.target.value),g([])}})}),N?t.jsx(hL,{models:x,picked:w,disabled:k,onPick:v}):null]})]})}const ice=2e3;function lce({busy:e,consent:n,onBack:s,onConnected:r,accounts:a}){const[i,l]=d.useState(!0),[o,c]=d.useState(null),[u,h]=d.useState(null),[m,f]=d.useState(0),p=d.useRef(-1),x=d.useRef(null),g=_.brain.cloud.label;d.useEffect(()=>{if(p.current===m)return;p.current=m,l(!0),c(null);const v=m===0?n:x.current;(async()=>{try{const j=((a==null?void 0:a.accounts)??[]).find(b=>b.auth==="device-key"),y=j?{id:j.id}:await T.saveProviderAccount({label:g,kind:"openai-compatible",auth:"device-key",baseUrl:"",defaultModel:Vh,enabled:!0}),k=(await T.providerAccounts()).accounts.find(b=>b.id===y.id),N=await T.ollamaConnect(k.id,k.revision);h({id:k.id,attemptId:N.attemptId,url:N.verificationUrl}),v&&(v.location.href=N.verificationUrl)}catch(j){v==null||v.close(),c(j instanceof pe?j.message:String(j))}finally{l(!1)}})()},[m]),d.useEffect(()=>{if(!u)return;let v=!1,j=!1;const y=async()=>{if(!(v||j)){j=!0;try{const N=await T.ollamaPoll(u.id,u.attemptId);if(v||N.state==="waiting")return;if(v=!0,h(null),N.state==="failed"){c(N.message);return}l(!0),c(await w(u.id)),l(!1)}catch{}finally{j=!1}}},k=window.setInterval(()=>void y(),ice);return()=>{v=!0,window.clearInterval(k)}},[u]);const w=async v=>{try{const j=(await T.accountModels(v).catch(()=>({models:[]}))).models.map(b=>b.id),y=j.length===0||j.includes(Vh)?Vh:j[0],k=(await T.providerAccounts()).accounts.find(b=>b.id===v);k&&k.defaultModel!==y&&await T.saveProviderAccount({id:k.id,revision:k.revision,label:k.label,kind:k.kind,auth:k.auth,baseUrl:k.baseUrl,defaultModel:y,enabled:k.enabled});const N=await T.testProviderAccount(v);return N.state!=="connected"?N.message:await r({accountId:v,label:g,model:y})}catch(j){return j instanceof pe?j.message:String(j)}};return t.jsxs(t.Fragment,{children:[i||e?t.jsx(xt,{children:t.jsx(Ts,{line:_.brain.checking.cloud})}):o?t.jsx(xt,{children:t.jsx($t,{children:o})}):u?t.jsx(xt,{children:t.jsx($t,{children:_.brain.cloud.waiting})}):null,t.jsx(Pn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Gs,{onClick:s,disabled:i||e}),u?t.jsx(it,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",children:_.brain.cloud.open}):o?t.jsx($,{variant:"accent",size:"lg",disabled:i||e,onClick:()=>{x.current=typeof window.open=="function"?window.open("","_blank"):null,f(v=>v+1)},children:_.brain.cloud.again}):null]})})]})}function oce({answers:e,accounts:n,onKept:s,onTrouble:r}){var p;const a=e.brain,i=a?((n==null?void 0:n.accounts)??[]).find(x=>x.id===a.accountId):void 0,[l,o]=d.useState([]),[c,u]=d.useState(!1),h=Ak(i),m=(i==null?void 0:i.auth)==="device-key"||(i==null?void 0:i.kind)==="codex"||h||!!i&&oD(i,(p=n==null?void 0:n.gemini)==null?void 0:p.baseUrl);if(d.useEffect(()=>{if(!m||!i)return;let x=!1;return T.accountModels(i.id).then(g=>{const w=h?g.models.filter(v=>!CO({id:v.id,...v.image?{kind:"image"}:{}})):g.models;x||o(w.map(v=>v.id))}).catch(()=>{}),()=>{x=!0}},[m,i==null?void 0:i.id]),!m||!i||!a||l.length<2)return null;const f=x=>{x===a.model||c||(u(!0),r(null),(async()=>{try{await T.saveProviderAccount({id:i.id,revision:i.revision,label:i.label,kind:i.kind,auth:i.auth,baseUrl:i.baseUrl,defaultModel:x,enabled:i.enabled}),e.assistant&&await T.bindBrain({accountId:i.id,model:x}),s({...e,brain:{accountId:a.accountId,label:a.label,model:x}})}catch(g){r(g instanceof pe?g.message:String(g))}finally{u(!1)}})())};return t.jsx($t,{children:t.jsx(le,{label:_.brain.model.change,children:t.jsx("select",{value:a.model,disabled:c,onChange:x=>f(x.target.value),children:(l.includes(a.model)?l:[a.model,...l]).map(x=>t.jsx("option",{value:x,children:x},x))})})})}const GE="gpt-5.5",cce=2e3;function uce({busy:e,consent:n,onBack:s,onConnected:r,accounts:a}){const[i,l]=d.useState(!0),[o,c]=d.useState(null),[u,h]=d.useState(null),[m,f]=d.useState(!1),[p,x]=d.useState(void 0),[g,w]=d.useState(0),v=d.useRef(-1),j=d.useRef(null),y=d.useRef(null),k=_.brain.chatgpt.label;d.useEffect(()=>()=>{const S=y.current;y.current=null,S&&T.codexAccountAction(S.id,"cancel-login",S.revision).catch(()=>{})},[]),d.useEffect(()=>{if(v.current===g)return;v.current=g,l(!0),c(null);const S=g===0?n:j.current;(async()=>{try{const C=((a==null?void 0:a.accounts)??[]).find(P=>P.kind==="codex"),A=C?{id:C.id}:await T.saveProviderAccount({label:k,kind:"codex",auth:"chatgpt",baseUrl:"",defaultModel:GE,enabled:!0}),E=(await T.providerAccounts()).accounts.find(P=>P.id===A.id),R=await T.codexAccountAction(E.id,"login",E.revision);if(!(R!=null&&R.verificationUrl)||!R.userCode)throw new Error((R==null?void 0:R.message)??_.brain.chatgpt.failed);y.current={id:E.id,revision:E.revision},h({id:E.id,revision:E.revision,url:R.verificationUrl,code:R.userCode}),f(!!S),S&&(S.location.href=R.verificationUrl)}catch(C){S==null||S.close(),c(C instanceof pe||C instanceof Error?C.message:String(C))}finally{l(!1)}})()},[g]),d.useEffect(()=>{if(!u)return;let S=!1,C=!1;const A=async()=>{if(!(S||C)){C=!0;try{const R=(await T.providerAccounts()).accounts.find(O=>O.id===u.id);if(S)return;const P=R==null?void 0:R.login;if(!P||P.state==="pending")return;if(S=!0,y.current=null,h(null),P.state!=="connected"){c(P.message??_.brain.chatgpt.failed);return}x(P.account??null),l(!0),c(await N(u.id)),l(!1),x(void 0)}catch{}finally{C=!1}}},E=window.setInterval(()=>void A(),cce);return()=>{S=!0,window.clearInterval(E)}},[u]);const N=async S=>{var C,A;try{const E=(await T.accountModels(S).catch(()=>({models:[]}))).models,R=((C=E.find(O=>O.isDefault))==null?void 0:C.id)??((A=E[0])==null?void 0:A.id)??GE,P=(await T.providerAccounts()).accounts.find(O=>O.id===S);return P&&P.defaultModel!==R&&await T.saveProviderAccount({id:P.id,revision:P.revision,label:P.label,kind:P.kind,auth:P.auth,baseUrl:P.baseUrl,defaultModel:R,enabled:P.enabled}),await r({accountId:S,label:k,model:R})}catch(E){return E instanceof pe?E.message:String(E)}},b=()=>{const S=y.current;y.current=null,S&&T.codexAccountAction(S.id,"cancel-login",S.revision).catch(()=>{}),s()};return t.jsxs(t.Fragment,{children:[p!==void 0?t.jsxs(xt,{children:[t.jsx($t,{children:_.brain.chatgpt.signedIn(p)}),t.jsx(Ts,{line:_.brain.checking.chatgpt})]}):i||e?t.jsx(xt,{children:t.jsx(Ts,{line:_.brain.checking.chatgpt})}):o?t.jsx(xt,{children:t.jsx($t,{children:o})}):u?t.jsx(xt,{children:m?t.jsx(Ts,{line:_.brain.chatgpt.waiting}):t.jsx($t,{children:_.brain.chatgpt.instruct})}):null,t.jsx(Pn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Gs,{onClick:b,disabled:i||e}),u?t.jsx(it,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",onClick:()=>f(!0),children:_.brain.chatgpt.open}):o?t.jsx($,{variant:"accent",size:"lg",disabled:i||e,onClick:()=>{j.current=typeof window.open=="function"?window.open("","_blank"):null,w(S=>S+1)},children:_.brain.chatgpt.again}):null]}),children:u?t.jsx(Tk,{code:u.code,label:_.brain.chatgpt.code,large:!0}):null})]})}const dce="claude-sonnet-5";function hce({busy:e,problem:n,onBack:s,onConnected:r,accounts:a,claudeModel:i}){const[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,m]=d.useState(null),[f,p]=d.useState(""),x=d.useRef(null);d.useEffect(()=>()=>{const y=x.current;x.current=null,y&&T.anthropicAccountAction(y.id,"cancel-login",y.revision).catch(()=>{})},[]);const g=()=>{const y=x.current;x.current=null,y&&T.anthropicAccountAction(y.id,"cancel-login",y.revision).catch(()=>{}),s()},w=i??dce,v=()=>{o(!0),u(null);const y=typeof window.open=="function"?window.open("","_blank"):null;(async()=>{try{const k=((a==null?void 0:a.accounts)??[]).find(A=>A.auth==="anthropic-oauth"),N=k?{id:k.id}:await T.saveProviderAccount({label:_.brain.claude.label,kind:"anthropic",auth:"anthropic-oauth",baseUrl:"",defaultModel:w,enabled:!0}),S=(await T.providerAccounts()).accounts.find(A=>A.id===N.id),C=await T.anthropicAccountAction(S.id,"login",S.revision);x.current={id:S.id,revision:S.revision+1},m({id:S.id,revision:S.revision+1,url:C.verificationUrl??"",attemptId:C.attemptId??""}),y&&C.verificationUrl?y.location.href=C.verificationUrl:y==null||y.close()}catch(k){y==null||y.close(),u(k instanceof pe?k.message:String(k))}finally{o(!1)}})()},j=()=>{!h||f.trim()===""||(x.current=null,o(!0),(async()=>{try{await T.anthropicAccountAction(h.id,"complete-login",h.revision,{attemptId:h.attemptId,code:f.trim()});const y=await T.testProviderAccount(h.id);if(y.state!=="connected"){u(y.message);return}u(await r({accountId:h.id,label:_.brain.claude.label,model:w}))}catch(y){u(y instanceof pe?y.message:String(y))}finally{o(!1)}})())};return t.jsxs(t.Fragment,{children:[l||e?t.jsx(xt,{children:t.jsx(Ts,{line:_.brain.checking.claude})}):n??c?t.jsx(xt,{children:t.jsx($t,{children:n??c})}):null,h?t.jsxs(t.Fragment,{children:[t.jsx(xt,{children:t.jsx($t,{children:_.brain.claude.waiting})}),t.jsx(Pn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Gs,{onClick:g,disabled:l}),t.jsx(it,{size:"lg",href:h.url,target:"_blank",rel:"noreferrer",children:_.brain.claude.open}),t.jsx($,{variant:"accent",size:"lg",disabled:l||f.trim()==="",onClick:j,children:_.brain.claude.finish})]}),children:t.jsx(le,{label:_.brain.claude.paste,grow:!0,children:t.jsx(fce,{value:f,onChange:p})})})]}):t.jsx(Pn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Gs,{onClick:g,disabled:e||l}),t.jsx($,{variant:"accent",size:"lg",disabled:e||l,onClick:v,children:_.brain.claude.start})]})})]})}function fce({value:e,onChange:n}){const s=dc();return t.jsx("input",{ref:s,type:"password",autoComplete:"off",spellCheck:!1,value:e,onChange:r=>n(r.target.value)})}const mce={days:"calendar",mail:"mail",money:"money",voice:"bulb",code:"monitor",pictures:"files"};function pce(e){const n=(e==null?void 0:e.plugins)??[];if(n.length===0)return null;const s=n.map(a=>a.title),r=n.filter(a=>a.state==="failed");if(e!=null&&e.running){const a=n.filter(i=>i.state==="ready"||i.state==="failed").length;return{line:_.takeOn.fetching(s,Math.min(a+1,n.length),n.length),done:!1}}return r.length>0?{line:r.map(a=>_.takeOn.failed(a.title,a.reason??"")).join(" "),done:!0}:{line:_.takeOn.ready(s),done:!0}}function gce({answers:e,progress:n,offers:s,onProgress:r,onSettled:a,onBack:i,onTrouble:l}){const o=s?_f.filter(w=>s.includes(w.id)):_f,[c,u]=d.useState(()=>e.takeOn??[...F5]),[h,m]=d.useState(!1),f=o.filter(w=>c.includes(w.id)),p=w=>u(v=>v.includes(w)?v.filter(j=>j!==w):[...v,w]),x=w=>{h||(m(!0),Promise.resolve().then(()=>T.takeOn(w)).then(()=>{r(),a({...e,takeOn:w})}).catch(v=>l(v instanceof pe?v.message:String(v))).finally(()=>m(!1)))},g=pce(n);return t.jsxs(t.Fragment,{children:[t.jsx(fc,{children:_.takeOn.title}),t.jsx(xt,{children:t.jsx($t,{children:_.takeOn.ask})}),t.jsxs(Pn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Gs,{onClick:i,disabled:h}),t.jsx($,{variant:"ghost",size:"lg",disabled:h,onClick:()=>x([]),children:_.takeOn.none}),t.jsx(hc,{onClick:()=>x(f.map(w=>w.id)),disabled:h||f.length===0,children:_.takeOn.submit})]}),children:[t.jsx("div",{className:"wiz-grid","data-cols":"3",role:"group","aria-label":_.takeOn.title,children:o.map(w=>{const v=c.includes(w.id);return t.jsxs("button",{type:"button",className:"wiz-opt","data-tile":"true","aria-pressed":v,onClick:()=>p(w.id),children:[t.jsxs("span",{className:"wiz-tile-top",children:[t.jsx("span",{className:"wiz-glyph","aria-hidden":"true",children:t.jsx(ne,{name:mce[w.id]})}),t.jsx("span",{className:"wiz-tick","aria-hidden":"true",children:v?t.jsx(ne,{name:"check",size:12}):null})]}),t.jsxs("span",{children:[t.jsx("span",{className:"wiz-opt-title",children:w.title}),t.jsx("span",{className:"wiz-opt-plugins",children:w.plugins})]}),t.jsx("span",{className:"wiz-opt-line",children:w.line})]},w.id)})}),f.length>0?t.jsxs("div",{className:"wiz-stack",children:[g?t.jsxs("div",{className:"wiz-busy","data-boxed":"true",role:"status",children:[t.jsxs("span",{className:"wiz-pulse","data-done":g.done?"true":void 0,"aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]}),t.jsx("span",{children:g.line}),c.includes("mail")?t.jsx("span",{className:"wiz-busy-side",children:_.takeOn.builtIn}):null]}):null,t.jsx("div",{className:"wiz-foot",children:f.map(w=>w.note).join(" ")})]}):t.jsx("div",{className:"wiz-foot",children:_.takeOn.nothing})]})]})}function xce({answers:e,progress:n,onSettled:s,onBack:r}){var g,w,v;const[a,i]=d.useState(((g=e.reach)==null?void 0:g.phone)===!0),[l,o]=d.useState(((w=e.reach)==null?void 0:w.mailbox)===!0),[c,u]=d.useState(((v=e.reach)==null?void 0:v.app)===!0),[h,m]=d.useState(e.browser),f=e.takeOn??[],p=f.includes("mail"),x=()=>{const j={phone:a,mailbox:l,app:c,browser:h==="chrome"||h==="chromium"||h==="installed"};h!==void 0&&Promise.resolve().then(()=>T.onboardingStep("browser")).catch(()=>{}),s({...e,reach:j,...h!==void 0?{browser:h}:{}})};return t.jsxs(t.Fragment,{children:[t.jsx(fc,{children:_.reach.title}),t.jsx(xt,{children:t.jsx($t,{children:_.reach.ask})}),t.jsx(Pn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Gs,{onClick:r}),t.jsx(hc,{onClick:x,children:_.reach.submit})]}),children:t.jsxs("div",{className:"wiz-rows",children:[t.jsx(jce,{paired:a,owner:e.name,onPaired:()=>i(!0)}),t.jsx(vce,{wanted:p,added:l,onAdded:o}),f.includes("days")?t.jsx(yce,{progress:n}):null,f.includes("money")?t.jsx(bce,{}):null,t.jsx(kce,{app:c,onApp:()=>u(!0),browser:h,onBrowser:m}),a?t.jsx(Q,{tone:"good",role:"status",children:_.reach.phone.hello}):null]})})]})}function jce({paired:e,owner:n,onPaired:s}){const[r,a]=d.useState(null),[i,l]=d.useState(!1),o=d.useRef(s);o.current=s,d.useEffect(()=>{let u=!1;return Promise.resolve().then(()=>T.telegram()).then(h=>{u||!h||(a(h),h.paired&&o.current())}).catch(()=>{u||a({configured:!1,running:!1,paired:!1})}),()=>{u=!0}},[]);const c=(r==null?void 0:r.configured)===!0&&r.running===!0;return t.jsxs("div",{className:"wiz-row",children:[t.jsx("span",{className:"wiz-glyph","aria-hidden":"true",children:t.jsx(ne,{name:"chat"})}),t.jsxs("span",{className:"wiz-row-text",children:[t.jsx("span",{className:"wiz-opt-title",children:_.reach.phone.title}),t.jsx("span",{className:"wiz-opt-line",children:_.reach.phone.line})]}),t.jsx("span",{className:"wiz-row-side",children:e?t.jsx($e,{tone:"good",dot:!0,children:_.reach.phone.paired}):t.jsx($,{size:"lg",disabled:r===null,onClick:()=>l(!0),children:c?_.reach.phone.pair:_.reach.phone.setUp})}),i?t.jsx(Ye,{title:_.telegram.sheet,onClose:()=>l(!1),children:t.jsx($ce,{ready:c,owner:n,onPaired:s,onDismiss:()=>l(!1)})}):null]})}function vce({wanted:e,added:n,onAdded:s}){const r=mL("email"),[a,i]=d.useState(!1),[l,o]=d.useState(null);return d.useEffect(()=>{Promise.resolve().then(()=>T.pageQuery("email","accounts")).then(c=>{var h,m,f;const u=((f=(m=(h=c==null?void 0:c.data)==null?void 0:h.accounts)==null?void 0:m[0])==null?void 0:f.address)??null;o(u),s(u!==null)}).catch(()=>{})},[]),t.jsxs("div",{className:"wiz-row",children:[t.jsx("span",{className:"wiz-glyph","data-tone":"mail","aria-hidden":"true",children:t.jsx(ne,{name:"mail"})}),t.jsxs("span",{className:"wiz-row-text",children:[t.jsx("span",{className:"wiz-opt-title",children:e?_.reach.mailbox.forTriage:_.reach.mailbox.title}),t.jsx("span",{className:"wiz-opt-line",children:r===!1?_.reach.mailbox.unavailable:_.reach.mailbox.line})]}),t.jsx("span",{className:"wiz-row-side",children:n||l?t.jsx($e,{tone:"good",dot:!0,mono:l!==null,children:l??_.reach.mailbox.added}):r?t.jsx($,{size:"lg",onClick:()=>i(!0),children:_.reach.mailbox.add}):null}),a?t.jsx(Ioe,{onClose:()=>i(!1),onAdded:c=>{o(c),s(!0)}}):null]})}function mL(e,n){const[s,r]=d.useState(void 0),a=(n==null?void 0:n.plugins.map(i=>`${i.title}:${i.state}`).join(","))??"";return d.useEffect(()=>{if(s)return;let i=!1;return Promise.resolve().then(()=>T.pages()).then(l=>{i||r(((l==null?void 0:l.pages)??[]).some(o=>o.plugin===e&&o.id==="settings"))}).catch(()=>{i||r(!1)}),()=>{i=!0}},[e,a]),s}function yce({progress:e}){const n=mL("calendar",e),[s,r]=d.useState(!1),[a,i]=d.useState(null),[l,o]=d.useState(!1),[c,u]=d.useState(0);d.useEffect(()=>{if(!n)return;let f=!1;return Promise.all([T.pageQuery("calendar","settings").then(p=>(p==null?void 0:p.data)??{}),T.pageQuery("calendar","sign_in").then(p=>(p==null?void 0:p.data)??{}).catch(()=>({}))]).then(([p,x])=>{f||i(wce(p,x))}).catch(()=>{}),()=>{f=!0}},[n,c,s]),d.useEffect(()=>{if((a==null?void 0:a.kind)!=="waiting")return;const f=window.setTimeout(()=>u(p=>p+1),aL);return()=>window.clearTimeout(f)},[a,c]);const h=a??(l?{kind:"linked",tone:"good",label:_.reach.calendar.linked}:null),m=h!==null&&h.kind!=="expired";return t.jsxs("div",{className:"wiz-row",children:[t.jsx("span",{className:"wiz-glyph","data-tone":"calendar","aria-hidden":"true",children:t.jsx(ne,{name:"calendar"})}),t.jsxs("span",{className:"wiz-row-text",children:[t.jsx("span",{className:"wiz-opt-title",children:_.reach.calendar.title}),t.jsx("span",{className:"wiz-opt-line",children:n===!1?_.reach.calendar.waiting:_.reach.calendar.line})]}),t.jsxs("span",{className:"wiz-row-side",children:[h!==null?t.jsx($e,{tone:h.tone,dot:!0,mono:h.kind==="google"||h.kind==="expired",children:h.label}):null,m?null:t.jsx($,{size:"lg",disabled:!n,onClick:()=>r(!0),children:_.reach.calendar.add})]}),s?t.jsx(Ooe,{onClose:()=>r(!1),onLinked:()=>{o(!0),u(f=>f+1)}}):null]})}function wce(e,n){var i;const s=(e.accounts??[]).filter(l=>l.kind==="google"),r=s.filter(l=>l.needsSignIn===!0),a=s.filter(l=>l.needsSignIn!==!0);return n.waiting===!0?{kind:"waiting",tone:"accent",label:_.reach.calendar.googleWaiting}:a.length>0?{kind:"google",tone:"good",label:_.reach.calendar.google(a.map(l=>l.username??"").filter(Boolean).join(", ")||"signed in")}:r.length>0?{kind:"expired",tone:"warning",label:_.reach.calendar.googleExpired(r.map(l=>l.username??"").filter(Boolean).join(", "))}:(((i=e.calendars)==null?void 0:i.length)??0)>0?{kind:"linked",tone:"good",label:_.reach.calendar.linked}:null}function bce(){const[e,n]=d.useState(!1),[s,r]=d.useState(!1);return t.jsxs("div",{className:"wiz-row",children:[t.jsx("span",{className:"wiz-glyph","data-tone":"finance","aria-hidden":"true",children:t.jsx(ne,{name:"money"})}),t.jsxs("span",{className:"wiz-row-text",children:[t.jsx("span",{className:"wiz-opt-title",children:_.reach.bank.title}),t.jsx("span",{className:"wiz-opt-line",children:_.reach.bank.line})]}),t.jsx("span",{className:"wiz-row-side",children:s?t.jsx($e,{dot:!0,children:_.reach.bank.later}):t.jsx($,{size:"lg",onClick:()=>n(!0),children:_.reach.bank.add})}),e?t.jsx(Doe,{onClose:()=>n(!1),onUnderstood:()=>r(!0)}):null]})}function kce({app:e,onApp:n,browser:s,onBrowser:r}){const a=kk(),i=Ep(),l=a?null:i,o=typeof navigator>"u"?null:L2(navigator.userAgent),[c,u]=d.useState(null),[h,m]=d.useState("idle"),[f,p]=d.useState(null),[x,g]=d.useState(null),[w,v]=d.useState(void 0),j=d.useRef(!1),y=d.useRef(!0);d.useEffect(()=>(y.current=!0,Promise.resolve().then(()=>T.browser()).then(E=>{var P;if(!y.current)return;const R=E==null?void 0:E.browser;R?((P=R.install)==null?void 0:P.state)==="running"?(u("none"),j.current=!0,m("installing"),b()):u(R.engine):u("other")}).catch(()=>{y.current&&u("other")}),()=>{y.current=!1}),[]);const k=(E,R)=>{y.current&&(j.current=!1,m("failed"),p(E),g(R??null))},N=async E=>{m("launching");let R;try{R=await T.browserCheck()}catch(P){return k(P instanceof pe?P.message:String(P))}if(y.current){if(R.ok){m("idle"),u(E),r(j.current?"installed":E);return}k(R.message,R.command)}},b=async()=>{var P,O;let E;try{E=await T.browser()}catch(I){return k(I instanceof pe?I.message:String(I))}if(!y.current)return;const R=E.browser;if(!R)return k(_.browser.failed(""));if(((P=R.install)==null?void 0:P.state)==="running"){m("installing"),v(R.install.progress),window.setTimeout(()=>void b(),1e3);return}return R.engine!=="none"?N(R.engine):k(((O=R.install)==null?void 0:O.line)??"")},S=()=>{if(g(null),c==="chrome"||c==="chromium"){N(c);return}j.current=!0,m("installing"),v(void 0),Promise.resolve().then(()=>T.browserInstall()).then(()=>{y.current&&window.setTimeout(()=>void b(),1e3)}).catch(E=>k(E instanceof pe?E.message:String(E)))},C=s==="chrome"||s==="chromium"||s==="installed",A=h==="installing"||h==="launching";return t.jsxs("div",{className:"wiz-row","data-wrap":h!=="idle"?"true":void 0,children:[t.jsx("span",{className:"wiz-glyph","data-tone":"good","aria-hidden":"true",children:t.jsx(ne,{name:"globe"})}),t.jsxs("span",{className:"wiz-row-text",children:[t.jsx("span",{className:"wiz-opt-title",children:a?_.reach.app.inApp.title:_.reach.app.title}),t.jsx("span",{className:"wiz-opt-line",children:a?_.reach.app.inApp.line:_.reach.app.line})]}),t.jsxs("span",{className:"wiz-row-side",children:[a?t.jsx(it,{size:"lg",href:n2,target:"_blank",rel:"noreferrer",children:_.reach.app.inApp.extension}):e?t.jsx($e,{tone:"good",dot:!0,children:_.reach.app.installed}):l?t.jsx($,{size:"lg",onClick:()=>{l.prompt().then(()=>l.userChoice).then(E=>{(!E||E.outcome==="accepted")&&n()}).catch(()=>{})},children:_.reach.app.install}):null,C?t.jsx($e,{tone:"good",dot:!0,children:_.reach.app.ready(s==="chrome"?"chrome":"chromium")}):c===null||c==="other"?null:t.jsx($,{size:"lg",disabled:A,onClick:S,children:A?_.browser.installing:h==="failed"?_.browser.retry:c==="chrome"?_.reach.app.chrome:c==="chromium"?_.reach.app.chromium:_.reach.app.fetch})]}),!e&&!l&&o?t.jsx("span",{className:"wiz-row-note",children:o}):null,h==="installing"?t.jsxs("div",{className:"wiz-row-more",children:[t.jsx("span",{className:"wiz-opt-line",children:_.browser.needs}),t.jsx(Foe,{progress:w})]}):h==="launching"?t.jsx("div",{className:"wiz-row-more",children:t.jsx(Ts,{line:_.browser.launching})}):h==="failed"?t.jsxs("div",{className:"wiz-row-more",children:[t.jsx("span",{className:"wiz-opt-line",children:_.browser.failed(f??"")}),x?t.jsx(Cce,{command:x}):null]}):null]})}function Nce({answers:e,existing:n,navigate:s,onSettled:r,onTrouble:a,onReload:i,onBack:l}){const[o,c]=d.useState(()=>(n==null?void 0:n.name)??R5),[u,h]=d.useState(()=>n!=null&&n.picture||n!=null&&n.avatar?null:"buddi"),[m,f]=d.useState(n?null:_.assistant.purposeValue),[p,x]=d.useState(n?"":_.assistant.purposeValue);d.useEffect(()=>{if(!n)return;let b=!1;return T.firstAgentPersona().then(S=>{b||(f(S.persona),x(S.persona))},S=>{b||a(S instanceof pe?S.message:String(S))}),()=>{b=!0}},[n==null?void 0:n.id]);const[g,w]=d.useState(!1),[v,j]=d.useState(null),y=_f.filter(b=>(e.takeOn??[]).includes(b.id)&&"mate"in b).map(b=>b.mate),k=kS.find(b=>b.id===u),N=()=>{if(o.trim()===""||g)return;w(!0);const b=!n||m!==null&&p.trim()!==""&&p.trim()!==m.trim()?{instructions:p.trim()}:{},S=n?T.updateFirstAgent({name:o.trim(),...b}):T.createFirstAgent({name:o.trim(),handle:Hoe(o),description:"",...b,...e.brain?{accountId:e.brain.accountId}:{}});(async()=>{var E;let C;try{C=await S}catch(R){R instanceof pe&&R.status===409&&((E=R.detail)==null?void 0:E.code)==="assistant-exists"?(j(R.message),a(null)):a(R instanceof pe?R.message:String(R)),w(!1);return}let A=null;try{k&&await T.uploadAgentPicture(C.id,await _O(k.role))}catch(R){A=R instanceof pe?R.message:String(R)}w(!1),i(),r({...e,assistant:{id:C.id,name:o.trim(),avatar:k?"":(n==null?void 0:n.avatar)??""}}),A&&a(A)})()};return t.jsxs(t.Fragment,{children:[t.jsx(fc,{children:_.assistant.title}),t.jsx(xt,{children:t.jsxs($t,{children:[_.assistant.ask,y.length>0?_.assistant.team(y):""]})}),t.jsxs(Pn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Gs,{onClick:l,disabled:g}),t.jsx(hc,{onClick:N,disabled:g||v!==null||o.trim()===""||m===null,children:_.assistant.submit})]}),children:[t.jsxs("div",{className:"wiz-meet",children:[t.jsxs("div",{className:"wiz-face",children:[t.jsx("span",{className:"wiz-face-tile","data-agent":(k==null?void 0:k.id)??"buddi","aria-hidden":"true",children:k?t.jsx("img",{src:Ti(k.role),alt:""}):n!=null&&n.picture?t.jsx("img",{src:n.picture,alt:""}):t.jsx("span",{className:"wiz-face-emoji",children:(n==null?void 0:n.avatar)??""})}),t.jsx("div",{className:"wiz-swatches",role:"group","aria-label":_.assistant.colour,children:kS.map(b=>t.jsx("button",{type:"button",className:"wiz-swatch","data-agent":b.id,"aria-label":_.assistant.swatch(b.label),"aria-pressed":u===b.id,onClick:()=>h(b.id)},b.id))}),t.jsx("span",{className:"wiz-face-cap",children:_.assistant.colour})]}),t.jsxs("div",{className:"wiz-stack",children:[t.jsx(le,{label:_.assistant.name,children:t.jsx("input",{value:o,maxLength:60,onChange:b=>c(b.target.value)})}),t.jsx(le,{label:_.assistant.purpose,hint:_.assistant.purposeHint,children:t.jsx("textarea",{className:"wiz-persona",value:p,maxLength:8e3,rows:7,onChange:b=>x(b.target.value)})})]})]}),v?t.jsx(Q,{tone:"warm",role:"status",title:_.assistant.refusedTitle,action:t.jsx(it,{href:Pt,onClick:b=>{b.preventDefault(),s(Pt)},children:_.assistant.toAgents}),children:v}):null]})]})}function Sce({answers:e,assistantAgent:n,met:s,onMet:r,navigate:a,onPickAnotherBrain:i,onSpoken:l,progress:o,onProgress:c}){var U,L;const u=e.assistant,[h,m]=d.useState(s),[f,p]=d.useState([]),[x,g]=d.useState(!1),[w,v]=d.useState(!1),[j,y]=d.useState(!0),[k,N]=d.useState(!1),b=d.useRef(!1),S=d.useMemo(()=>n?[n]:[],[n]);d.useEffect(()=>{c()},[]),d.useEffect(()=>{if(!u||b.current)return;if(b.current=!0,s){m(s);return}let M=!1;return(async()=>{try{const z=await nt.startConversation(u.id);if(M)return;m(z.conversationId),r(z.conversationId),await T.onboardingStep(iL.handover,{conversationId:z.conversationId}).catch(()=>{}),await nt.send(u.id,{conversationId:z.conversationId,text:O5,opening:!0})}catch{M||(y(!1),g(!0))}})(),()=>{M=!0}},[u==null?void 0:u.id,s]),d.useEffect(()=>{if(!h)return;let M=!1;const z=Date.now(),D=()=>{nt.conversation(h).then(B=>{if(M)return;p(B.messages);const se=Date.now()-z;if(B.messages.some(qE)){y(!1),g(!1),v(!1);return}const W=B.runs??[],xe=W.some(ie=>ie.finishedAt===null),me=W.length>0&&!xe;v(xe&&se>=Koe),(me||se>=Voe)&&(y(!1),g(!0))}).catch(()=>{})};D();const K=window.setInterval(D,dL);return()=>{M=!0,window.clearInterval(K)}},[h]);const C=u&&h?ut(u.id,h):null,A=f.some(qE);d.useEffect(()=>{A&&C&&l(C)},[A,C,l]);const E=o!=null&&o.tiles&&o.tiles.length>0?o.tiles:e.takeOn??[],R=_.handover.starters({days:E.includes("days"),mail:E.includes("mail"),mailbox:((U=e.reach)==null?void 0:U.mailbox)===!0}),P={days:E.includes("days"),mailbox:((L=e.reach)==null?void 0:L.mailbox)===!0,mail:E.includes("mail"),money:E.includes("money"),pictures:E.includes("pictures")},O=(o==null?void 0:o.waiting)??[],I=M=>{jb(),a(M,!0)},F=M=>{!u||!h||k||(N(!0),Promise.resolve().then(()=>nt.send(u.id,{conversationId:h,text:M})).then(()=>I(ut(u.id,h))).catch(()=>N(!1)))};return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"wiz-hello",children:t.jsx(rk,{messages:f,live:[],now:Date.now(),onOpen:()=>{},working:j,agents:S,agentName:(u==null?void 0:u.name)??"",...u?{agentId:u.id}:{},emptyHint:_.handover.waiting,plain:!0,workingLine:_.handover.looking((u==null?void 0:u.name)??"")})}),w&&!x?t.jsx(xt,{children:t.jsx($t,{children:_.handover.slow})}):null,x?t.jsxs(t.Fragment,{children:[t.jsx(xt,{children:t.jsx($t,{children:_.handover.silent})}),t.jsx(Pn,{actions:t.jsx(hc,{onClick:i,children:_.handover.again})})]}):null,A?t.jsx("div",{className:"wiz-starters",role:"group","aria-label":_.handover.starterLabel,children:R.map(M=>t.jsx("button",{type:"button",className:"wiz-starter",disabled:k,onClick:()=>F(M),children:M},M))}):null,A?t.jsx(IK,{setUp:P,navigate:I}):null,A?t.jsx(qO,{plugins:(o==null?void 0:o.plugins)??[]}):null,A&&O.length>0?t.jsx(Q,{tone:"warm",title:_.handover.waitingTitle(O.length),action:t.jsx($,{variant:"accent",onClick:()=>I(Un),children:_.handover.home}),children:_.handover.waitingBody(O)}):null,A&&C?t.jsx(Pn,{actions:t.jsx(it,{variant:"accent",size:"lg",href:C,onClick:M=>{M.preventDefault(),I(C)},children:_.done.open})}):null]})}function Cce({command:e}){const[n,s]=d.useState("idle"),r=()=>{var a;if(!((a=navigator.clipboard)!=null&&a.writeText)){s("failed");return}navigator.clipboard.writeText(e).then(()=>s("done"),()=>s("failed"))};return t.jsxs(ue,{gap:"sm",children:[t.jsx(Zt,{label:"The command to run",children:e}),t.jsxs(te,{align:"end",children:[n==="failed"?t.jsx("span",{className:"ui-toolbar-note",children:"Select it to copy."}):null,t.jsx($,{size:"sm",onClick:r,children:n==="done"?"Copied":"Copy"})]})]})}function qE(e){return e.role==="assistant"&&(e.blocks??[]).some(n=>n.type==="text"&&n.text.trim()!=="")}function Ece({onCancel:e,onStarted:n,onTrouble:s}){const[r,a]=d.useState(null),[i,l]=d.useState(""),[o,c]=d.useState(!1),u=()=>{!r||o||(c(!0),s(null),T.firstRunRestore(r,i.trim()).then(h=>{Ry(h.job.id),n()}).catch(h=>s(h instanceof pe?h.message:String(h))).finally(()=>c(!1)))};return t.jsx(Ye,{title:_.restore.sheet,onClose:e,children:t.jsxs("div",{className:"wiz-restore",children:[t.jsx("p",{className:"wiz-foot",children:_.restore.lede}),t.jsx(le,{label:_.restore.file,children:t.jsx("input",{type:"file",onChange:h=>{var m;return a(((m=h.target.files)==null?void 0:m[0])??null)}})}),t.jsx(le,{label:_.restore.passphrase,hint:_.restore.passphraseHint,children:t.jsx("input",{type:"password",autoComplete:"off",value:i,onChange:h=>l(h.target.value)})}),t.jsxs(te,{align:"end",children:[t.jsx($,{variant:"ghost",onClick:e,children:_.restore.cancel}),t.jsx($,{variant:"accent",disabled:o||!r,onClick:u,children:_.restore.submit})]})]})})}function Ace({onDone:e,onFailed:n}){const[s,r]=d.useState([]),a=d.useRef({onDone:e,onFailed:n});a.current={onDone:e,onFailed:n},d.useEffect(()=>{const l=uL();if(!l)return;let o=!1;const c=()=>{T.backupJob(l).then(h=>{o||(r(m=>m.includes(h.phase)?m:[...m,h.phase]),h.phase==="done"?(o=!0,Ry(null),T.owner().then(m=>a.current.onDone(m.preferredName??void 0),()=>a.current.onDone(void 0))):(h.phase==="rolled-back"||h.phase==="failed")&&(o=!0,Ry(null),a.current.onFailed(h.error??_.restore.phases[h.phase])))}).catch(()=>{})};c();const u=window.setInterval(c,dL);return()=>{o=!0,window.clearInterval(u)}},[]);const i=s.filter(l=>l in _.restore.phases);return t.jsxs(t.Fragment,{children:[t.jsx(fc,{children:_.restore.title}),t.jsxs(xt,{children:[t.jsx($t,{children:_.restore.started}),i.map(l=>t.jsx($t,{children:_.restore.phases[l]},l))]}),t.jsx(Ts,{})]})}function $ce(e){return t.jsx(Qk.Provider,{value:null,children:t.jsx("div",{className:"wiz-sheet-body",children:t.jsx(Rce,{...e})})})}const Tce=1600;function Rce({ready:e,owner:n,onPaired:s,onDismiss:r}){const a=dc(),[i,l]=d.useState(""),[o,c]=d.useState(!1),[u,h]=d.useState(null),[m,f]=d.useState(null),{offer:p,square:x,paired:g,stale:w,ask:v}=ZD(()=>T.telegram().then(b=>b.paired),s),j=d.useRef(!1);d.useEffect(()=>{!e||j.current||(j.current=!0,Promise.resolve().then(()=>T.telegramBot()).then(b=>f((b==null?void 0:b.username)??null)).catch(()=>{}),v().catch(b=>h(b instanceof pe?b.message:String(b))))},[e,v]);const y=d.useRef(r);y.current=r,d.useEffect(()=>{if(!g)return;const b=window.setTimeout(()=>y.current(),Tce);return()=>window.clearTimeout(b)},[g]);const k=()=>{i.trim()===""||o||(c(!0),h(null),(async()=>{try{const b=await T.saveTelegramToken(i.trim());if(l(""),f(b.botUsername??null),b.restartNeeded){h(b.note??_.telegram.restart);return}await v()}catch(b){h(b instanceof pe?b.message:String(b))}finally{c(!1)}})())},N=()=>{h(null),v().catch(b=>h(b instanceof pe?b.message:String(b)))};return p?t.jsxs(t.Fragment,{children:[t.jsx(xt,{children:t.jsx($t,{children:w&&!g?_.telegram.expired:_.telegram.scan})}),t.jsx(Pn,{actions:g?t.jsx($,{variant:"accent",onClick:r,children:_.telegram.close}):t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:r,children:_.telegram.notNow}),w?t.jsx($,{variant:"accent",onClick:N,children:_.telegram.newCode}):null]}),children:w&&!g?null:t.jsx(Dle,{offer:p,square:x,bot:m,paired:g,status:g?_.telegram.pairedWith(n):_.telegram.waiting})})]}):e&&!u?t.jsx(xt,{children:t.jsx(Ts,{line:_.telegram.making})}):e?t.jsxs(t.Fragment,{children:[t.jsx(xt,{children:t.jsx($t,{children:u})}),t.jsx(Pn,{actions:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:r,children:_.telegram.notNow}),t.jsx($,{variant:"accent",onClick:N,children:_.telegram.newCode})]})})]}):t.jsxs(t.Fragment,{children:[t.jsxs(xt,{children:[t.jsx($t,{children:_.telegram.how}),u?t.jsx($t,{children:u}):null]}),t.jsx(Pn,{actions:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:r,children:_.telegram.notNow}),t.jsx($,{variant:"accent",disabled:o||i.trim()==="",onClick:k,children:_.telegram.submit})]}),children:t.jsx(le,{label:_.telegram.field,grow:!0,children:t.jsx("input",{ref:a,type:"password",value:i,autoComplete:"off",spellCheck:!1,onChange:b=>l(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),k())}})})})]})}const Ix={recovery:0,lost:1,paused:2},Ice="Lost buddi. Retrying…",Pce="The queue is paused. Nothing is being claimed until you resume it.";function Mce(e){const n=[];return e.recovery&&n.push({id:"recovery",priority:Ix.recovery,tone:"warning",text:HO,action:{label:"Finish the checklist",href:dv}}),e.lost&&n.push({id:"lost",priority:Ix.lost,tone:"critical",text:Ice}),e.paused&&n.push({id:"paused",priority:Ix.paused,tone:"warning",text:Pce,action:{label:"Resume",onClick:()=>{T.setPaused(!1).catch(()=>{})}}}),n}function Oce({banners:e,onNavigate:n}){if(e.length===0)return null;const s=[...e].sort((l,o)=>l.priority-o.priority),r=s[0],a=s.slice(1),i=r.action;return t.jsxs("div",{className:"shell-banner",role:"status","data-tone":r.tone,"data-banner":r.id,children:[t.jsx("span",{className:"shell-banner-dot","aria-hidden":"true"}),t.jsx("span",{className:"shell-banner-text",children:r.text}),a.length>0?t.jsxs("span",{className:"shell-banner-more",title:a.map(l=>l.text).join(`
155
- `),children:["+",a.length," more"]}):null,i!=null&&i.href?t.jsx(it,{size:"sm",href:i.href,onClick:l=>{l.preventDefault(),n(i.href)},children:i.label}):i?t.jsx($,{size:"sm",onClick:i.onClick,children:i.label}):null]})}const pL=1e4,Dce=3e4,gL=6e3,Jk=/^(localhost|127(?:\.\d{1,3}){3}|\[?::1\]?)$|\.localhost$/i;function Lce(e){return Jk.test(e)?t.jsxs(t.Fragment,{children:["Is buddi running on this Mac? ",t.jsx("code",{children:"buddi status"})," says."]}):t.jsx(t.Fragment,{children:"Is Tailscale on, and the Mac it runs on awake?"})}async function xL(e){let n;const s=new Promise((r,a)=>{n=setTimeout(()=>a(new pe(0,Lf)),e)});try{return{up:!0,version:await Promise.race([T.version(),s])}}catch(r){return Ff(r)?{up:!1}:{up:!0}}finally{clearTimeout(n)}}function jL(e){var n;return e.up&&pb((n=e.version)==null?void 0:n.web)?(window.location.reload(),!1):e.up}function Fce({host:e,onRetry:n,retrying:s}){return t.jsxs("main",{className:"unreachable",role:"alert",children:[t.jsx("span",{className:"ui-blob","data-size":"lg","aria-hidden":"true",children:t.jsx("img",{src:Ti("core"),alt:""})}),t.jsxs("h1",{children:["buddi isn't answering at ",e,"."]}),t.jsx("p",{children:Lce(e.replace(/:\d+$/,""))}),t.jsx("div",{className:"unreachable-actions",children:t.jsx($,{variant:"accent",onClick:n,disabled:s,children:s?"Retrying…":"Retry"})})]})}function _ce({children:e}){const[n,s]=d.useState("checking"),[r,a]=d.useState(!1),i=d.useRef(!1),l=d.useCallback(async()=>{if(i.current)return;i.current=!0,a(!0);const o=await xL(gL);i.current=!1,a(!1),s(c=>c==="checking"?o.up?"up":"down":jL(o)?"up":"down")},[]);return d.useEffect(()=>{l()},[l]),d.useEffect(()=>{if(n!=="down")return;const o=window.setInterval(()=>void l(),pL);return()=>window.clearInterval(o)},[n,l]),n==="checking"?null:n==="down"?t.jsx(Fce,{host:window.location.host,onRetry:()=>void l(),retrying:r}):t.jsx(t.Fragment,{children:e})}function zce(e=Dce){const[n,s]=d.useState(!1);return d.useEffect(()=>{let r;const a=()=>{clearTimeout(r);const l=Mu();if(l===null)return s(!1);const o=l+e-Date.now();o<=0?s(!0):r=setTimeout(a,o)};a();const i=Kw(a);return()=>{i(),clearTimeout(r)}},[e]),n}function Uce(){const e=zce();return d.useEffect(()=>{if(!e)return;const n=window.setInterval(()=>{xL(gL).then(jL)},pL);return()=>window.clearInterval(n)},[e]),e}const Bce={local:"Local",tailnet:"Tailnet",reconnecting:"Reconnecting…"},YE=(e,n,s=`${n}s`)=>e===1?n:s;function Wce(){return Intl.DateTimeFormat().resolvedOptions().timeZone}function Hce(e){return e.includes("/")?e.split("/").pop().replace(/_/g," "):e}function Kce(e,n){return n?"reconnecting":Jk.test(e)?"local":"tailnet"}function vL(e,n,s=Wce()){const r=[],a=Bce[e.link];if(r.push({key:"link",route:ze("system"),dot:e.link==="reconnecting"?"warning":"good",text:a,label:`Connection: ${a}`}),e.focus){const u=`${Qi[e.focus.mode]} ${Ju(e.focus,e.timezone,n)}`;r.push({key:"focus",route:ze("notifications"),icon:"moon",text:u,label:`Focus: ${u}`})}const i=[];if(e.working>0&&i.push({key:"working",dot:"working",text:`${e.working} ${YE(e.working,"agent")} working`}),i.push(e.paused?{key:"queue",tone:"warning",text:"Queue paused"}:{key:"queue",text:"Queue running"}),e.failed>0&&i.push({key:"failed",tone:"critical",text:`${e.failed} failed`}),r.push({key:"work",route:e.failed>0?`${ln}/jobs?state=failed`:`${ln}/jobs`,parts:i,label:`Work: ${i.map(u=>u.text).join(", ")}`}),e.approvals>0){const u=`${YE(e.approvals,"approval")} waiting`;r.push({key:"approvals",route:Io,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:ze("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=Lt(n,l),c=l!==s;return r.push({key:"time",route:ze("you"),end:!0,time:o,...c?{zone:Hce(l)}:{},label:`Your time: ${o}${c?`, ${l}`:""}`}),r}function Vce(e){var n;return e.link==="reconnecting"||e.failed>0?"critical":e.paused?"warning":e.approvals>0||(((n=e.version)==null?void 0:n.updateAvailable)??!1)?"attention":"good"}function yL(){const[e,n]=d.useState(()=>new Date);return d.useEffect(()=>{let s;const r=()=>{s=setTimeout(()=>{n(new Date),r()},6e4-Date.now()%6e4)};return r(),()=>clearTimeout(s)},[]),e}function Gce(){const[e,n]=d.useState(()=>Mu()!==null);return d.useEffect(()=>Kw(()=>n(Mu()!==null)),[]),e}function wL({item:e}){var n;return t.jsxs(t.Fragment,{children:[e.dot?t.jsx("span",{className:"shell-status-dot","data-tone":e.dot,"aria-hidden":"true"}):null,e.icon?t.jsx(ne,{name:e.icon,size:12}):null,e.count?t.jsx("span",{className:"ui-badge","aria-hidden":"true",children:e.count>99?"99+":e.count}):null,(n=e.parts)==null?void 0:n.map((s,r)=>t.jsxs(d.Fragment,{children:[r>0?t.jsx("span",{className:"shell-status-sep","aria-hidden":"true",children:"·"}):null,s.dot?t.jsx("span",{className:"shell-status-dot","data-tone":s.dot,"aria-hidden":"true"}):null,t.jsx("span",{"data-tone":s.tone,children:s.text})]},s.key)),e.text?t.jsx("span",{children:e.text}):null,e.mono?t.jsx("span",{className:"shell-status-mono",children:e.mono}):null,e.update?t.jsx("span",{className:"ui-badge","data-kind":"dot","data-testid":"status-update-dot","aria-hidden":"true"}):null,e.time?t.jsx("span",{className:"shell-status-time",children:e.time}):null,e.zone?t.jsx("span",{className:"shell-status-zone",children:e.zone}):null]})}function qce({status:e,onNavigate:n}){const s=yL(),r=Tp(),a=vL(e,s),i=l=>t.jsx("a",{className:"shell-status-item","data-item":l.key,href:l.route,"aria-label":l.label,title:l.label,onClick:o=>{o.preventDefault(),n(l.route)},children:t.jsx(wL,{item:l})},l.key);return t.jsxs("footer",{className:"shell-status","aria-label":"Status",children:[a.filter(l=>!l.end).map(i),t.jsx("span",{className:"shell-status-spacer"}),a.filter(l=>l.end).map(i),r.pin?t.jsx("button",{type:"button",className:"shell-status-item shell-status-lock","data-item":"lock","aria-label":`Lock now (${r.shortcut})`,title:`Lock now (${r.shortcut})`,onClick:()=>r.lockNow(),children:t.jsx(ne,{name:"lock",size:13})}):null]})}function Yce({status:e,onNavigate:n}){const s=yL(),r=Tp(),a=Vce(e);return t.jsx("div",{className:"rail-status",children:t.jsxs(pd,{modal:!1,children:[t.jsx(gd,{asChild:!0,children:t.jsx("button",{type:"button",className:"rail-status-btn","aria-label":"Status",children:t.jsx("span",{className:"rail-status-dot","data-tone":a,"data-testid":"rail-status-dot","aria-hidden":"true"})})}),t.jsx(tc,{children:t.jsxs(xd,{className:"ui-menu rail-status-menu",side:"right",align:"end",sideOffset:10,children:[t.jsx(hl,{className:"ui-menu-label",children:"Status"}),vL(e,s).map(i=>t.jsx(bs,{asChild:!0,onSelect:()=>n(i.route),children:t.jsx("a",{className:"ui-menu-item rail-status-item","data-item":i.key,href:i.route,"aria-label":i.label,children:t.jsx("span",{className:"rail-status-line",children:t.jsx(wL,{item:i})})})},i.key)),r.pin?t.jsxs(t.Fragment,{children:[t.jsx(Xr,{className:"ui-menu-sep"}),t.jsx(bs,{className:"ui-menu-item rail-status-item","data-item":"lock",onSelect:()=>r.lockNow(),children:t.jsxs("span",{className:"rail-status-line",children:[t.jsx(ne,{name:"lock",size:12}),t.jsx("span",{children:"Lock now"})]})})]}):null]})})]})})}const Qce=1e4;function bL(){return d.useSyncExternalStore(w8,PS,PS)}function Jce(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 QE(e){const n=Math.max(0,Math.floor(e/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function Xce({command:e}){const[n,s]=d.useState(!1);return d.useEffect(()=>{if(!n)return;const r=window.setTimeout(()=>s(!1),1600);return()=>window.clearTimeout(r)},[n]),t.jsxs("div",{className:"rs-cmd",children:[t.jsx("code",{className:"rs-cmd-text",children:e}),t.jsx($,{size:"sm",onClick:()=>{var r;(r=navigator.clipboard)==null||r.writeText(e).then(()=>s(!0),()=>{})},children:n?"Copied":"Copy"})]})}function Zce({state:e,elapsedMs:n,hostname:s=window.location.hostname,onReload:r=()=>jo.reload()}){const a=Jce(e),i=e.kind==="stop",l=!i&&n>=(e.patienceMs??g8),o=Jk.test(s),c=d.useRef(null);d.useEffect(()=>{var h;return(h=c.current)==null?void 0:h.focus()},[]);const u=i?o?"This starts it again, in Terminal on this computer:":"On the computer buddi runs on, this starts it again:":o?"This says what it’s doing, in Terminal on this computer:":"On the computer buddi runs on, this says what it’s doing. Is that computer awake, and Tailscale on?";return t.jsx("div",{className:"ui-fieldbg rs-field","data-quiet":"true",children:t.jsx("div",{ref:c,className:"rs",role:"dialog","aria-modal":"true","aria-labelledby":"rs-title",tabIndex:-1,"data-state":i?"stopped":l?"long":"waiting",children:t.jsxs("div",{className:"rs-body",children:[t.jsx("span",{className:"ui-mascot rs-blob","data-size":"lg","aria-hidden":"true",children:t.jsx(jd,{role:"core",state:i||l?"idle":"working",className:"ui-mascot-blob"})}),t.jsx("h1",{id:"rs-title",className:"rs-title",children:a.title}),t.jsx("p",{className:"rs-line",role:"status",children:l?"Still waiting — buddi may need a hand.":a.line}),!l&&e.step?t.jsx("p",{className:"rs-step",children:e.step}):null,i||l?null:t.jsx("div",{className:"rs-track","aria-hidden":"true",children:t.jsx("span",{})}),i||l?t.jsxs("div",{className:"rs-help",children:[t.jsx("p",{className:"rs-help-line",children:u}),t.jsx(Xce,{command:i?"buddi service start":"buddi status"})]}):null,t.jsxs("div",{className:"rs-foot",children:[t.jsx("span",{className:"rs-meta",children:i?"Checking every few seconds.":l?`${QE(n)} · still checking every few seconds`:n>=Qce?`${QE(n)} · this page reloads when buddi is back`:"This page reloads when buddi is back."}),i||l?t.jsx($,{size:"sm",variant:l?"accent":void 0,onClick:r,children:"Reload"}):null]})]})})})}function eue(e){const[n,s]=d.useState(()=>jo.now());return d.useEffect(()=>{if(!e)return;s(jo.now());const r=window.setInterval(()=>s(jo.now()),1e3);return()=>window.clearInterval(r)},[e]),e?Math.max(0,n-e.startedAt):0}function tue({children:e}){const n=bL(),s=eue(n),r=d.useRef(null);return d.useEffect(()=>{k8();let a=Mu()!==null;const i=Kw(()=>{const o=Mu()!==null;a&&!o&&MS(),a=o}),l=()=>void MS();return window.addEventListener(Lu,l),()=>{i(),window.removeEventListener(Lu,l)}},[]),d.useEffect(()=>{const a=r.current;a&&(a.toggleAttribute("inert",n!==null),n?a.setAttribute("aria-hidden","true"):a.removeAttribute("aria-hidden"))},[n]),t.jsxs(t.Fragment,{children:[t.jsx("div",{ref:r,className:"rs-host",children:e}),n?t.jsx(Zce,{state:n,elapsedMs:s}):null]})}const nue="(max-width: 1080px)",sue="(max-width: 720px)";function rue(){const[e,n]=d.useState(()=>window.location.hash||Un);d.useEffect(()=>{const r=()=>n(window.location.hash||Un);return window.addEventListener("hashchange",r),()=>window.removeEventListener("hashchange",r)},[]);const s=d.useCallback((r,a=!1)=>{a?window.history.replaceState(null,"",r):window.location.hash=r,n(r)},[]);return[e,s]}function aue(){const[e,n]=oO();d.useEffect(()=>{lO(e)},[e]);const s=d.useCallback(r=>n({theme:r}),[n]);return[e.theme,s]}const JE=new Map;function iue(){var ee,rt,On,$n;const[e,n]=rue(),[s,r]=d.useState("UTC"),[a,i]=d.useState({approvals:0,failed:0,paused:!1,running:0,needs:0}),[l,o]=aue(),c=ts(kb),[u,h]=d.useState(!1),[m,f]=d.useState([]),[p,x]=d.useState(null),[g,w]=d.useState(null),[v,j]=d.useState([]),[y,k]=d.useState(!1),[N,b]=d.useState(null),[S,C]=d.useState(null),[A,E]=d.useState(0),[R,P]=d.useState(null),O=P8(),I=m.find(Ae=>Ae.id===p)??null,F=I!==null&&zX(e),[U,L]=d.useState(!1),M=d.useCallback(()=>L(!0),[]);d.useEffect(()=>{F||L(!1)},[F]),Zee(n,Yh(e)===null,F?M:void 0);const z=ts(nue),D=WO(),K=MI(),B=nO(),se=je(()=>Promise.resolve().then(()=>T.version()),[],a8),W=se.data;m8(se.reload);const xe=W&&!W.checkout&&W.updateAvailable?W:null,me=pb(W==null?void 0:W.web);p8(W==null?void 0:W.web);const ie=((ee=je(()=>Promise.resolve().then(()=>T.connectionSignals()),[],6e4).data)==null?void 0:ee.signals)??[],[H,de]=d.useState(null),ge=d.useMemo(()=>new Set(H?[H]:[]),[H]),[Ue,G]=d.useState(new Map);d.useEffect(()=>{const Ae=()=>{T.conversations().then(gt=>{const Mt=new Map;for(const Dn of gt.conversations){const as=Dn.lastMessageAt??Dn.createdAt,js=Mt.get(Dn.agentId);(!js||as>js)&&Mt.set(Dn.agentId,as)}G(Mt)}).catch(()=>{})};Ae();const De=window.setInterval(Ae,3e4);return()=>window.clearInterval(De)},[e]);const[ae,J]=d.useState(!1),[Ne,Ie]=d.useState("unknown");d.useEffect(()=>{if(ae)return;let Ae=!1;return T.onboarding().then(De=>{Ae||(J(!0),Ie(De.state==="done"||De.state==="skipped"?"done":"open"),De.state==="pending"&&De.needs.model&&!Yh(window.location.hash)&&n(B8,!0))}).catch(()=>{Ae||(J(!0),Ie("open"))}),()=>{Ae=!0}},[ae,n]),d.useEffect(()=>{const Ae=hW(e);Ae&&n(Ae,!0)},[e,n]),d.useEffect(()=>{let Ae=!1;const De=()=>{nt.agents().then(Mt=>{Ae||(f(Mt.agents),g4(Mt.commands),Z5(Mt.defaultAgentId??null),x(Mt.defaultAgentId??null),w(Dn=>{var as;return Dn??Mt.defaultAgentId??((as=Mt.agents[0])==null?void 0:as.id)??null}))}).catch(()=>{})};De();const gt=window.setInterval(De,15e3);return window.addEventListener("focus",De),window.addEventListener(Rs,De),()=>{Ae=!0,window.clearInterval(gt),window.removeEventListener("focus",De),window.removeEventListener(Rs,De)}},[e]),d.useEffect(()=>{let Ae=!1;const De=()=>{nt.groups().then(Mt=>{Ae||j(Mt.groups)}).catch(()=>{})};De();const gt=window.setInterval(De,3e4);return()=>{Ae=!0,window.clearInterval(gt)}},[e]);const Y=OI(m,p),X=H8(e),oe=_I(e),ve=oe?v.find(Ae=>Ae.id===oe.groupId)??null:null,be=oe?null:(X==null?void 0:X.agentId)??g;d.useEffect(()=>{X&&w(X.agentId)},[X==null?void 0:X.agentId]);const Ce=d.useRef(null);X&&(Ce.current=e);const we=Ae=>{w(Ae),n(ut(Ae))},He=Ae=>n(Hi(Ae)),Ze=d.useCallback((Ae,De,gt=!0)=>n(oe?Hi(oe.groupId,De):ut(Ae,De),gt),[n,oe==null?void 0:oe.groupId]),[Se,Le]=d.useState(!1),[,Ve]=d.useState(0);d.useEffect(()=>{const Ae=()=>{Ve(De=>De+1),T.session().then(De=>r(De.timezone)).catch(()=>{})};return window.addEventListener(_j,Ae),()=>window.removeEventListener(_j,Ae)},[]),d.useEffect(()=>{T.session().then(Ae=>{Ww({timeFormat:Ae.timeFormat??null,dateFormat:Ae.dateFormat??null}),r(Ae.timezone),Le(!0)}).catch(()=>{})},[]);const Qe=YX(Se);eZ(Se,Qe.refresh,()=>Le(!1)),d.useEffect(()=>{const Ae=()=>{T.overview().then(gt=>{var Mt;return i({approvals:gt.approvals.pending,failed:gt.jobs.failed??0,paused:gt.paused,running:gt.running??0,needs:((Mt=gt.needsYou)==null?void 0:Mt.total)??gt.approvals.pending+(gt.jobs.failed??0)})}).catch(()=>{})};Ae();const De=window.setInterval(Ae,2e4);return window.addEventListener(Yi,Ae),()=>{window.clearInterval(De),window.removeEventListener(Yi,Ae)}},[]);const wt=je(()=>Promise.resolve().then(()=>T.focus()),[],6e4),dt=d.useRef(wt.reload);dt.current=wt.reload,d.useEffect(()=>{const Ae=()=>{dt.current()};return window.addEventListener(Yi,Ae),()=>window.removeEventListener(Yi,Ae)},[]);const qt=Gce(),vt=Uce(),Dt=bL()!==null,bn=ts(sue);d.useEffect(()=>{if(!Se)return;if(e===fW){k(!0),n(Aa,!0);return}const Ae=mW(e),De=new Date().toDateString();!Ae||JE.get(Ae)===De||(JE.set(Ae,De),T.tipsSeenPage(Ae).catch(()=>{}))},[e,Se,n]);const sn={link:Kce(window.location.hostname,qt&&!Dt),focus:((rt=wt.data)==null?void 0:rt.focus)??null,working:a.running,paused:a.paused,failed:a.failed,approvals:a.approvals,version:W?{current:W.current,latest:W.latest,updateAvailable:!W.checkout&&W.updateAvailable}:void 0,timezone:s},ce=Mce({recovery:((On=D.data)==null?void 0:On.active)===!0,lost:vt&&!Dt,paused:a.paused}),Me=Yh(e),tt=KI(e),Tt=tt===Aa,bt=N?v.find(Ae=>Ae.id===N.groupId)??null:null,Pe=Ae=>j(De=>De.map(gt=>gt.id===Ae.id?Ae:gt)),st=()=>b(null),_e=y?t.jsx(tZ,{agents:m,onClose:()=>k(!1),onCreated:Ae=>{j(De=>[...De,Ae]),k(!1),n(Hi(Ae.id))}}):bt&&(N==null?void 0:N.kind)==="members"?t.jsx(AX,{group:bt,agents:m,onClose:st,onSaved:Pe}):bt&&(N==null?void 0:N.kind)==="rename"?t.jsx($X,{group:bt,onClose:st,onSaved:Ae=>{Pe(Ae),st()}}):bt&&(N==null?void 0:N.kind)==="clear"?t.jsx(RX,{group:bt,onClose:st,onCleared:()=>{st(),E(Ae=>Ae+1),n(Hi(bt.id),!0)}}):bt&&(N==null?void 0:N.kind)==="delete"?t.jsx(IX,{group:bt,agents:m,onClose:st,onDeleted:Ae=>{const De=v.findIndex(gt=>gt.id===bt.id);st(),j(gt=>gt.filter(Mt=>Mt.id!==bt.id)),C({group:bt,index:De,until:Ae}),n(Ce.current??Aa)}}):null,en=()=>{const Ae=S;Ae&&(C(null),nt.restoreGroup(Ae.group.id).then(De=>{j(gt=>{if(gt.some(Dn=>Dn.id===De.id))return gt;const Mt=[...gt];return Mt.splice(Math.min(Math.max(Ae.index,0),Mt.length),0,De),Mt}),n(Hi(De.id))}).catch(()=>P(Ae.group.name)))};return Me?t.jsx(cS,{delayDuration:400,children:t.jsxs(QN,{swipeDirection:"right",children:[t.jsx(Qoe,{navigate:n,timezone:s}),t.jsx(JN,{className:"ui-toasts"})]})}):t.jsx(yW,{picture:($n=m.find(Ae=>Ae.id===p))==null?void 0:$n.picture,children:t.jsx(cS,{delayDuration:400,children:t.jsxs(QN,{swipeDirection:"right",children:[_e,t.jsxs("div",{className:"wb-shell",children:[t.jsx(Oce,{banners:ce,onNavigate:n}),t.jsxs("div",{className:"wb",children:[t.jsx(Uee,{attention:a.needs,place:tt,onNavigate:n,theme:l,onTheme:o,plugins:Jee(K.rail,B),updateAvailable:xe!==null,settingsDot:ie.length>0?tO:void 0,stale:me,timezone:s,version:W&&!W.checkout?{current:W.current,latest:W.latest,updateAvailable:W.updateAvailable}:W?{current:W.current,updateAvailable:!1}:void 0,status:bn?t.jsx(Yce,{status:sn,onNavigate:n}):void 0}),Tt&&!z?t.jsx(qI,{agents:Y,currentId:be,attention:O,onSelect:we,lastActivity:Ue,working:ge,groups:v,currentGroupId:(ve==null?void 0:ve.id)??null,onSelectGroup:He,onNewGroup:()=>k(!0)}):null,Tt?t.jsx(PX,{timezone:s,agents:Y,agentId:ve?ve.coordinator:be,defaultAgentId:p,group:ve,...ve?{onGroupAction:Ae=>b({kind:Ae,groupId:ve.id})}:{},requestedConversationId:(oe==null?void 0:oe.conversationId)??(X==null?void 0:X.conversationId),requestedTab:X==null?void 0:X.tab,onConversationOpened:Ze,onSelectAgent:we,onWorking:de,attention:O,agentsInHeader:z,narrow:c,canvasOpen:u,onOpenCanvas:()=>h(!0),onCloseCanvas:()=>h(!1)},`room-${A}`):t.jsx("main",{"data-ground":lue(tt,e)?"plain":void 0,"data-layout":tt===Nn?"split":void 0,children:t.jsx(oue,{hash:e,place:tt,timezone:s,navigate:n,agents:m,defaultAgentId:p,attention:O,pluginPages:K,update:xe,connectionSignals:ie,onboarding:Ne})})]}),bn?null:t.jsx(qce,{status:sn,onNavigate:n})]}),F&&I?t.jsx(UX,{agent:I,agents:m,timezone:s,open:U,onOpenChange:L,navigate:n}):null,t.jsxs(GX,{placement:VX(F,U),children:[t.jsx(QX,{queue:Qe.queue,agents:m,navigate:n,onDismiss:Qe.dismiss}),S?t.jsx(Qu,{title:`Deleted ${S.group.name}`,body:"Its history goes for good in a few seconds.",duration:sZ,onUndo:en,onGone:()=>C(null)},S.group.id):null,R?t.jsx(Qu,{title:`${R} is gone for good`,body:"Undo came too late to bring it back.",duration:6e3,onGone:()=>P(null)},`late-${R}`):null,t.jsx(JN,{className:"ui-toasts"})]})]})})})}function lue(e,n){return yb(n)!==null}function oue({place:e,pluginPages:n,...s}){const r={...s,pluginPages:n},a=yb(s.hash);if(a){const i=n.find(a.plugin,a.page);if(i)return t.jsx(fM,{page:i,item:a.item??null,params:wb(s.hash),navigate:s.navigate,timezone:s.timezone,siblings:n.all.filter(l=>l.plugin===a.plugin)});if(n.all.length===0)return t.jsx(t.Fragment,{})}switch(e){case Pt:return t.jsx(xse,{...r});case ln:return t.jsx(jte,{...s});case Nn:return t.jsx(ooe,{...r});case Da:return t.jsx(aZ,{...s});default:return t.jsx(nre,{...r})}}function cue(){"serviceWorker"in navigator&&window.addEventListener("load",()=>{const e=`./sw.js?v=${encodeURIComponent(mb)}`;navigator.serviceWorker.register(e,{scope:"./"}).catch(()=>{})})}function uue({search:e=location.search}){const[n,s]=d.useState(null),r=d.useRef(!1);return d.useEffect(()=>{if(r.current)return;r.current=!0;const a=new URLSearchParams(e);try{history.replaceState(null,"",location.pathname)}catch{}const i=a.get("state")??"",l=a.get("code")??void 0,o=a.get("error")??void 0;T.connectionCallback({state:i,...l?{code:l}:{},...o?{error:o}:{}}).then(c=>{s({ok:!0,name:c.name,cli:c.cli===!0});try{const u=new BroadcastChannel(OO);u.postMessage({id:c.id}),u.close()}catch{}window.setTimeout(()=>{try{window.close()}catch{}},1500)}).catch(c=>s({ok:!1,message:c instanceof Error?c.message:String(c)}))},[e]),t.jsx("main",{className:"ui-page connections-callback",children:t.jsxs(ue,{gap:"lg",children:[t.jsx("h2",{className:"ui-page-title",children:"Connections"}),n===null?t.jsx(Q,{tone:"accent",role:"status",children:"Finishing the sign-in…"}):null,n!=null&&n.ok?t.jsxs(Q,{tone:"good",role:"status",title:`Signed in to ${n.name}`,children:["buddi keeps the sign-in in its vault. You can close this tab; ",n.cli?"the terminal carries on.":"the other one carries on."]}):null,n&&!n.ok?t.jsx(Q,{tone:"critical",role:"alert",title:"Nothing was connected",children:n.message}):null,n?t.jsx(it,{href:"/#/settings/connections",children:"Back to Connections"}):null]})})}const XE=document.getElementById("root");XE&&dT(XE).render(t.jsx(d.StrictMode,{children:location.pathname==="/connections/callback"?t.jsx(uue,{}):t.jsx(tue,{children:t.jsx(_ce,{children:t.jsx(zee,{children:t.jsx(iue,{})})})})}));cue();export{hue as c,FL as g};