@withbuddi/buddi 0.1.0-pre.46 → 0.1.0-pre.48

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 (418) hide show
  1. package/extension/manifest.json +2 -2
  2. package/node_modules/@buddi/cli/dist/.tsbuildinfo +1 -1
  3. package/node_modules/@buddi/core/dist/.tsbuildinfo +1 -1
  4. package/node_modules/@buddi/core/dist/agents/frontmatter.d.ts +4 -4
  5. package/node_modules/@buddi/core/dist/host/build.d.ts +8 -1
  6. package/node_modules/@buddi/core/dist/host/build.d.ts.map +1 -1
  7. package/node_modules/@buddi/core/dist/host/build.js +33 -0
  8. package/node_modules/@buddi/core/dist/host/build.js.map +1 -1
  9. package/node_modules/@buddi/core/dist/host/types.d.ts +43 -0
  10. package/node_modules/@buddi/core/dist/host/types.d.ts.map +1 -1
  11. package/node_modules/@buddi/core/dist/index.d.ts +1 -0
  12. package/node_modules/@buddi/core/dist/index.d.ts.map +1 -1
  13. package/node_modules/@buddi/core/dist/index.js +1 -0
  14. package/node_modules/@buddi/core/dist/index.js.map +1 -1
  15. package/node_modules/@buddi/core/dist/onboarding/index.d.ts +1 -0
  16. package/node_modules/@buddi/core/dist/onboarding/index.d.ts.map +1 -1
  17. package/node_modules/@buddi/core/dist/onboarding/index.js +1 -0
  18. package/node_modules/@buddi/core/dist/onboarding/index.js.map +1 -1
  19. package/node_modules/@buddi/core/dist/plugin/index.d.ts +5 -1
  20. package/node_modules/@buddi/core/dist/plugin/index.d.ts.map +1 -1
  21. package/node_modules/@buddi/core/dist/plugin/index.js.map +1 -1
  22. package/node_modules/@buddi/core/dist/plugin/uses.d.ts +1 -1
  23. package/node_modules/@buddi/core/dist/plugin/uses.d.ts.map +1 -1
  24. package/node_modules/@buddi/core/dist/plugin/uses.js +2 -0
  25. package/node_modules/@buddi/core/dist/plugin/uses.js.map +1 -1
  26. package/node_modules/@buddi/core/dist/plugin/version.d.ts +1 -1
  27. package/node_modules/@buddi/core/dist/plugin/version.js +1 -1
  28. package/node_modules/@buddi/core/dist/runtimes/__fixtures__/server.d.ts +26 -0
  29. package/node_modules/@buddi/core/dist/runtimes/__fixtures__/server.d.ts.map +1 -0
  30. package/node_modules/@buddi/core/dist/runtimes/__fixtures__/server.js +93 -0
  31. package/node_modules/@buddi/core/dist/runtimes/__fixtures__/server.js.map +1 -0
  32. package/node_modules/@buddi/core/dist/runtimes/area.d.ts +22 -0
  33. package/node_modules/@buddi/core/dist/runtimes/area.d.ts.map +1 -0
  34. package/node_modules/@buddi/core/dist/runtimes/area.js +127 -0
  35. package/node_modules/@buddi/core/dist/runtimes/area.js.map +1 -0
  36. package/node_modules/@buddi/core/dist/runtimes/config.d.ts +54 -0
  37. package/node_modules/@buddi/core/dist/runtimes/config.d.ts.map +1 -0
  38. package/node_modules/@buddi/core/dist/runtimes/config.js +57 -0
  39. package/node_modules/@buddi/core/dist/runtimes/config.js.map +1 -0
  40. package/node_modules/@buddi/core/dist/runtimes/consent.d.ts +170 -0
  41. package/node_modules/@buddi/core/dist/runtimes/consent.d.ts.map +1 -0
  42. package/node_modules/@buddi/core/dist/runtimes/consent.js +205 -0
  43. package/node_modules/@buddi/core/dist/runtimes/consent.js.map +1 -0
  44. package/node_modules/@buddi/core/dist/runtimes/download.d.ts +95 -0
  45. package/node_modules/@buddi/core/dist/runtimes/download.d.ts.map +1 -0
  46. package/node_modules/@buddi/core/dist/runtimes/download.js +333 -0
  47. package/node_modules/@buddi/core/dist/runtimes/download.js.map +1 -0
  48. package/node_modules/@buddi/core/dist/runtimes/index.d.ts +10 -0
  49. package/node_modules/@buddi/core/dist/runtimes/index.d.ts.map +1 -0
  50. package/node_modules/@buddi/core/dist/runtimes/index.js +10 -0
  51. package/node_modules/@buddi/core/dist/runtimes/index.js.map +1 -0
  52. package/node_modules/@buddi/core/dist/runtimes/models.d.ts +78 -0
  53. package/node_modules/@buddi/core/dist/runtimes/models.d.ts.map +1 -0
  54. package/node_modules/@buddi/core/dist/runtimes/models.js +240 -0
  55. package/node_modules/@buddi/core/dist/runtimes/models.js.map +1 -0
  56. package/node_modules/@buddi/core/dist/runtimes/native.d.ts +49 -0
  57. package/node_modules/@buddi/core/dist/runtimes/native.d.ts.map +1 -0
  58. package/node_modules/@buddi/core/dist/runtimes/native.js +27 -0
  59. package/node_modules/@buddi/core/dist/runtimes/native.js.map +1 -0
  60. package/node_modules/@buddi/core/dist/runtimes/onnx.d.ts +87 -0
  61. package/node_modules/@buddi/core/dist/runtimes/onnx.d.ts.map +1 -0
  62. package/node_modules/@buddi/core/dist/runtimes/onnx.js +582 -0
  63. package/node_modules/@buddi/core/dist/runtimes/onnx.js.map +1 -0
  64. package/node_modules/@buddi/core/dist/runtimes/pins.d.ts +53 -0
  65. package/node_modules/@buddi/core/dist/runtimes/pins.d.ts.map +1 -0
  66. package/node_modules/@buddi/core/dist/runtimes/pins.js +75 -0
  67. package/node_modules/@buddi/core/dist/runtimes/pins.js.map +1 -0
  68. package/node_modules/@buddi/core/dist/scheduler/missions.d.ts +9 -3
  69. package/node_modules/@buddi/core/dist/scheduler/missions.d.ts.map +1 -1
  70. package/node_modules/@buddi/core/dist/scheduler/missions.js +12 -3
  71. package/node_modules/@buddi/core/dist/scheduler/missions.js.map +1 -1
  72. package/node_modules/@buddi/core/dist/scheduler/types.d.ts +8 -3
  73. package/node_modules/@buddi/core/dist/scheduler/types.d.ts.map +1 -1
  74. package/node_modules/@buddi/core/dist/scheduler/types.js +5 -1
  75. package/node_modules/@buddi/core/dist/scheduler/types.js.map +1 -1
  76. package/node_modules/@buddi/core/dist/secrets/approval.d.ts.map +1 -1
  77. package/node_modules/@buddi/core/dist/secrets/approval.js +3 -1
  78. package/node_modules/@buddi/core/dist/secrets/approval.js.map +1 -1
  79. package/node_modules/@buddi/core/dist/secrets/use.d.ts +3 -1
  80. package/node_modules/@buddi/core/dist/secrets/use.d.ts.map +1 -1
  81. package/node_modules/@buddi/core/dist/secrets/use.js +2 -0
  82. package/node_modules/@buddi/core/dist/secrets/use.js.map +1 -1
  83. package/node_modules/@buddi/core/dist/system-context.d.ts +6 -0
  84. package/node_modules/@buddi/core/dist/system-context.d.ts.map +1 -1
  85. package/node_modules/@buddi/core/dist/tools.d.ts +16 -0
  86. package/node_modules/@buddi/core/dist/tools.d.ts.map +1 -1
  87. package/node_modules/@buddi/core/dist/tools.js.map +1 -1
  88. package/node_modules/@buddi/core/dist/views.d.ts +8 -8
  89. package/node_modules/@buddi/core/migrations/079_mission_browser_owner.sql +7 -0
  90. package/node_modules/@buddi/gateway/dist/.tsbuildinfo +1 -1
  91. package/node_modules/@buddi/gateway/dist/agents/catalog.d.ts.map +1 -1
  92. package/node_modules/@buddi/gateway/dist/agents/catalog.js +6 -3
  93. package/node_modules/@buddi/gateway/dist/agents/catalog.js.map +1 -1
  94. package/node_modules/@buddi/gateway/dist/agents/catalogue-package.d.ts +24 -10
  95. package/node_modules/@buddi/gateway/dist/agents/catalogue-package.d.ts.map +1 -1
  96. package/node_modules/@buddi/gateway/dist/agents/catalogue-package.js +6 -2
  97. package/node_modules/@buddi/gateway/dist/agents/catalogue-package.js.map +1 -1
  98. package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.d.ts +17 -4
  99. package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.d.ts.map +1 -1
  100. package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.js +25 -5
  101. package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.js.map +1 -1
  102. package/node_modules/@buddi/gateway/dist/browser-host.d.ts +7 -0
  103. package/node_modules/@buddi/gateway/dist/browser-host.d.ts.map +1 -1
  104. package/node_modules/@buddi/gateway/dist/browser-host.js +22 -0
  105. package/node_modules/@buddi/gateway/dist/browser-host.js.map +1 -1
  106. package/node_modules/@buddi/gateway/dist/missions/agent-run.d.ts +6 -0
  107. package/node_modules/@buddi/gateway/dist/missions/agent-run.d.ts.map +1 -1
  108. package/node_modules/@buddi/gateway/dist/missions/agent-run.js +2 -1
  109. package/node_modules/@buddi/gateway/dist/missions/agent-run.js.map +1 -1
  110. package/node_modules/@buddi/gateway/dist/missions/chrome-scope.d.ts +91 -0
  111. package/node_modules/@buddi/gateway/dist/missions/chrome-scope.d.ts.map +1 -0
  112. package/node_modules/@buddi/gateway/dist/missions/chrome-scope.js +194 -0
  113. package/node_modules/@buddi/gateway/dist/missions/chrome-scope.js.map +1 -0
  114. package/node_modules/@buddi/gateway/dist/missions/execute.d.ts +20 -0
  115. package/node_modules/@buddi/gateway/dist/missions/execute.d.ts.map +1 -1
  116. package/node_modules/@buddi/gateway/dist/missions/execute.js +77 -5
  117. package/node_modules/@buddi/gateway/dist/missions/execute.js.map +1 -1
  118. package/node_modules/@buddi/gateway/dist/missions/reminders.d.ts +11 -2
  119. package/node_modules/@buddi/gateway/dist/missions/reminders.d.ts.map +1 -1
  120. package/node_modules/@buddi/gateway/dist/missions/reminders.js +55 -5
  121. package/node_modules/@buddi/gateway/dist/missions/reminders.js.map +1 -1
  122. package/node_modules/@buddi/gateway/dist/owner-notify.d.ts +0 -11
  123. package/node_modules/@buddi/gateway/dist/owner-notify.d.ts.map +1 -1
  124. package/node_modules/@buddi/gateway/dist/owner-notify.js +3 -1
  125. package/node_modules/@buddi/gateway/dist/owner-notify.js.map +1 -1
  126. package/node_modules/@buddi/gateway/dist/owner-profile-edit.d.ts +3 -2
  127. package/node_modules/@buddi/gateway/dist/owner-profile-edit.d.ts.map +1 -1
  128. package/node_modules/@buddi/gateway/dist/owner-profile-edit.js +4 -2
  129. package/node_modules/@buddi/gateway/dist/owner-profile-edit.js.map +1 -1
  130. package/node_modules/@buddi/gateway/dist/serve.d.ts.map +1 -1
  131. package/node_modules/@buddi/gateway/dist/serve.js +3 -2
  132. package/node_modules/@buddi/gateway/dist/serve.js.map +1 -1
  133. package/node_modules/@buddi/gateway/dist/system-context.d.ts +10 -2
  134. package/node_modules/@buddi/gateway/dist/system-context.d.ts.map +1 -1
  135. package/node_modules/@buddi/gateway/dist/system-context.js +24 -10
  136. package/node_modules/@buddi/gateway/dist/system-context.js.map +1 -1
  137. package/node_modules/@buddi/gateway/dist/telegram/approvals.d.ts +2 -1
  138. package/node_modules/@buddi/gateway/dist/telegram/approvals.d.ts.map +1 -1
  139. package/node_modules/@buddi/gateway/dist/telegram/approvals.js +16 -4
  140. package/node_modules/@buddi/gateway/dist/telegram/approvals.js.map +1 -1
  141. package/node_modules/@buddi/gateway/dist/web/api-routes.d.ts.map +1 -1
  142. package/node_modules/@buddi/gateway/dist/web/api-routes.js +8 -0
  143. package/node_modules/@buddi/gateway/dist/web/api-routes.js.map +1 -1
  144. package/node_modules/@buddi/gateway/dist/web/approval-ask.d.ts +8 -0
  145. package/node_modules/@buddi/gateway/dist/web/approval-ask.d.ts.map +1 -1
  146. package/node_modules/@buddi/gateway/dist/web/approval-ask.js +25 -0
  147. package/node_modules/@buddi/gateway/dist/web/approval-ask.js.map +1 -1
  148. package/node_modules/@buddi/gateway/dist/web/plugins.d.ts.map +1 -1
  149. package/node_modules/@buddi/gateway/dist/web/plugins.js +3 -1
  150. package/node_modules/@buddi/gateway/dist/web/plugins.js.map +1 -1
  151. package/node_modules/@buddi/gateway/dist/web/read.d.ts +2 -0
  152. package/node_modules/@buddi/gateway/dist/web/read.d.ts.map +1 -1
  153. package/node_modules/@buddi/gateway/dist/web/read.js +1 -0
  154. package/node_modules/@buddi/gateway/dist/web/read.js.map +1 -1
  155. package/node_modules/@buddi/gateway/dist/web/runtimes.d.ts +10 -0
  156. package/node_modules/@buddi/gateway/dist/web/runtimes.d.ts.map +1 -0
  157. package/node_modules/@buddi/gateway/dist/web/runtimes.js +25 -0
  158. package/node_modules/@buddi/gateway/dist/web/runtimes.js.map +1 -0
  159. package/node_modules/@buddi/gateway/dist/web/server.d.ts.map +1 -1
  160. package/node_modules/@buddi/gateway/dist/web/server.js +20 -2
  161. package/node_modules/@buddi/gateway/dist/web/server.js.map +1 -1
  162. package/node_modules/@buddi/gateway/dist/web/write.d.ts +11 -1
  163. package/node_modules/@buddi/gateway/dist/web/write.d.ts.map +1 -1
  164. package/node_modules/@buddi/gateway/dist/web/write.js +18 -1
  165. package/node_modules/@buddi/gateway/dist/web/write.js.map +1 -1
  166. package/node_modules/@buddi/install/dist/.tsbuildinfo +1 -1
  167. package/node_modules/@buddi/runtime/dist/.tsbuildinfo +1 -1
  168. package/node_modules/@buddi/runtime/dist/delegate.d.ts.map +1 -1
  169. package/node_modules/@buddi/runtime/dist/delegate.js +1 -0
  170. package/node_modules/@buddi/runtime/dist/delegate.js.map +1 -1
  171. package/node_modules/@buddi/runtime/dist/index.d.ts +1 -0
  172. package/node_modules/@buddi/runtime/dist/index.d.ts.map +1 -1
  173. package/node_modules/@buddi/runtime/dist/index.js +1 -0
  174. package/node_modules/@buddi/runtime/dist/index.js.map +1 -1
  175. package/node_modules/@buddi/runtime/dist/language.d.ts +65 -0
  176. package/node_modules/@buddi/runtime/dist/language.d.ts.map +1 -0
  177. package/node_modules/@buddi/runtime/dist/language.js +191 -0
  178. package/node_modules/@buddi/runtime/dist/language.js.map +1 -0
  179. package/node_modules/@buddi/runtime/dist/loop.d.ts +9 -1
  180. package/node_modules/@buddi/runtime/dist/loop.d.ts.map +1 -1
  181. package/node_modules/@buddi/runtime/dist/loop.js +78 -4
  182. package/node_modules/@buddi/runtime/dist/loop.js.map +1 -1
  183. package/node_modules/@buddi/tool-artifacts/dist/.tsbuildinfo +1 -1
  184. package/node_modules/@buddi/tool-browser/dist/.tsbuildinfo +1 -1
  185. package/node_modules/@buddi/tool-browser/dist/controller.d.ts +5 -0
  186. package/node_modules/@buddi/tool-browser/dist/controller.d.ts.map +1 -1
  187. package/node_modules/@buddi/tool-browser/dist/controller.js +41 -5
  188. package/node_modules/@buddi/tool-browser/dist/controller.js.map +1 -1
  189. package/node_modules/@buddi/tool-browser/dist/routes.d.ts +6 -0
  190. package/node_modules/@buddi/tool-browser/dist/routes.d.ts.map +1 -1
  191. package/node_modules/@buddi/tool-browser/dist/routes.js +2 -2
  192. package/node_modules/@buddi/tool-browser/dist/routes.js.map +1 -1
  193. package/node_modules/@buddi/tool-email/dist/.tsbuildinfo +1 -1
  194. package/node_modules/@buddi/tool-host/dist/.tsbuildinfo +1 -1
  195. package/node_modules/@buddi/tool-mcp/dist/.tsbuildinfo +1 -1
  196. package/node_modules/@buddi/tool-memory/dist/.tsbuildinfo +1 -1
  197. package/node_modules/@buddi/tool-web/dist/.tsbuildinfo +1 -1
  198. package/node_modules/express-rate-limit/dist/index.cjs +9 -7
  199. package/node_modules/express-rate-limit/dist/index.mjs +9 -7
  200. package/node_modules/express-rate-limit/package.json +9 -9
  201. package/node_modules/imapflow/CHANGELOG.md +8 -0
  202. package/node_modules/imapflow/dist/cjs/commands/copyuid-parser.js +16 -2
  203. package/node_modules/imapflow/dist/cjs/handler/imap-compiler.js +26 -19
  204. package/node_modules/imapflow/dist/cjs/handler/token-parser.js +127 -51
  205. package/node_modules/imapflow/dist/cjs/package-info.d.ts +1 -1
  206. package/node_modules/imapflow/dist/cjs/package-info.js +1 -1
  207. package/node_modules/imapflow/dist/cjs/search-compiler.js +7 -3
  208. package/node_modules/imapflow/dist/esm/commands/copyuid-parser.js +16 -2
  209. package/node_modules/imapflow/dist/esm/handler/imap-compiler.js +26 -19
  210. package/node_modules/imapflow/dist/esm/handler/token-parser.js +127 -51
  211. package/node_modules/imapflow/dist/esm/package-info.d.ts +1 -1
  212. package/node_modules/imapflow/dist/esm/package-info.js +1 -1
  213. package/node_modules/imapflow/dist/esm/search-compiler.js +7 -3
  214. package/node_modules/imapflow/package.json +3 -2
  215. package/package.json +2 -2
  216. package/packages/cli/dist/.tsbuildinfo +1 -1
  217. package/packages/core/dist/.tsbuildinfo +1 -1
  218. package/packages/core/dist/agents/frontmatter.d.ts +4 -4
  219. package/packages/core/dist/host/build.d.ts +8 -1
  220. package/packages/core/dist/host/build.d.ts.map +1 -1
  221. package/packages/core/dist/host/build.js +33 -0
  222. package/packages/core/dist/host/build.js.map +1 -1
  223. package/packages/core/dist/host/types.d.ts +43 -0
  224. package/packages/core/dist/host/types.d.ts.map +1 -1
  225. package/packages/core/dist/index.d.ts +1 -0
  226. package/packages/core/dist/index.d.ts.map +1 -1
  227. package/packages/core/dist/index.js +1 -0
  228. package/packages/core/dist/index.js.map +1 -1
  229. package/packages/core/dist/onboarding/index.d.ts +1 -0
  230. package/packages/core/dist/onboarding/index.d.ts.map +1 -1
  231. package/packages/core/dist/onboarding/index.js +1 -0
  232. package/packages/core/dist/onboarding/index.js.map +1 -1
  233. package/packages/core/dist/plugin/index.d.ts +5 -1
  234. package/packages/core/dist/plugin/index.d.ts.map +1 -1
  235. package/packages/core/dist/plugin/index.js.map +1 -1
  236. package/packages/core/dist/plugin/uses.d.ts +1 -1
  237. package/packages/core/dist/plugin/uses.d.ts.map +1 -1
  238. package/packages/core/dist/plugin/uses.js +2 -0
  239. package/packages/core/dist/plugin/uses.js.map +1 -1
  240. package/packages/core/dist/plugin/version.d.ts +1 -1
  241. package/packages/core/dist/plugin/version.js +1 -1
  242. package/packages/core/dist/runtimes/__fixtures__/server.d.ts +26 -0
  243. package/packages/core/dist/runtimes/__fixtures__/server.d.ts.map +1 -0
  244. package/packages/core/dist/runtimes/__fixtures__/server.js +93 -0
  245. package/packages/core/dist/runtimes/__fixtures__/server.js.map +1 -0
  246. package/packages/core/dist/runtimes/area.d.ts +22 -0
  247. package/packages/core/dist/runtimes/area.d.ts.map +1 -0
  248. package/packages/core/dist/runtimes/area.js +127 -0
  249. package/packages/core/dist/runtimes/area.js.map +1 -0
  250. package/packages/core/dist/runtimes/config.d.ts +54 -0
  251. package/packages/core/dist/runtimes/config.d.ts.map +1 -0
  252. package/packages/core/dist/runtimes/config.js +57 -0
  253. package/packages/core/dist/runtimes/config.js.map +1 -0
  254. package/packages/core/dist/runtimes/consent.d.ts +170 -0
  255. package/packages/core/dist/runtimes/consent.d.ts.map +1 -0
  256. package/packages/core/dist/runtimes/consent.js +205 -0
  257. package/packages/core/dist/runtimes/consent.js.map +1 -0
  258. package/packages/core/dist/runtimes/download.d.ts +95 -0
  259. package/packages/core/dist/runtimes/download.d.ts.map +1 -0
  260. package/packages/core/dist/runtimes/download.js +333 -0
  261. package/packages/core/dist/runtimes/download.js.map +1 -0
  262. package/packages/core/dist/runtimes/index.d.ts +10 -0
  263. package/packages/core/dist/runtimes/index.d.ts.map +1 -0
  264. package/packages/core/dist/runtimes/index.js +10 -0
  265. package/packages/core/dist/runtimes/index.js.map +1 -0
  266. package/packages/core/dist/runtimes/models.d.ts +78 -0
  267. package/packages/core/dist/runtimes/models.d.ts.map +1 -0
  268. package/packages/core/dist/runtimes/models.js +240 -0
  269. package/packages/core/dist/runtimes/models.js.map +1 -0
  270. package/packages/core/dist/runtimes/native.d.ts +49 -0
  271. package/packages/core/dist/runtimes/native.d.ts.map +1 -0
  272. package/packages/core/dist/runtimes/native.js +27 -0
  273. package/packages/core/dist/runtimes/native.js.map +1 -0
  274. package/packages/core/dist/runtimes/onnx.d.ts +87 -0
  275. package/packages/core/dist/runtimes/onnx.d.ts.map +1 -0
  276. package/packages/core/dist/runtimes/onnx.js +582 -0
  277. package/packages/core/dist/runtimes/onnx.js.map +1 -0
  278. package/packages/core/dist/runtimes/pins.d.ts +53 -0
  279. package/packages/core/dist/runtimes/pins.d.ts.map +1 -0
  280. package/packages/core/dist/runtimes/pins.js +75 -0
  281. package/packages/core/dist/runtimes/pins.js.map +1 -0
  282. package/packages/core/dist/scheduler/missions.d.ts +9 -3
  283. package/packages/core/dist/scheduler/missions.d.ts.map +1 -1
  284. package/packages/core/dist/scheduler/missions.js +12 -3
  285. package/packages/core/dist/scheduler/missions.js.map +1 -1
  286. package/packages/core/dist/scheduler/types.d.ts +8 -3
  287. package/packages/core/dist/scheduler/types.d.ts.map +1 -1
  288. package/packages/core/dist/scheduler/types.js +5 -1
  289. package/packages/core/dist/scheduler/types.js.map +1 -1
  290. package/packages/core/dist/secrets/approval.d.ts.map +1 -1
  291. package/packages/core/dist/secrets/approval.js +3 -1
  292. package/packages/core/dist/secrets/approval.js.map +1 -1
  293. package/packages/core/dist/secrets/use.d.ts +3 -1
  294. package/packages/core/dist/secrets/use.d.ts.map +1 -1
  295. package/packages/core/dist/secrets/use.js +2 -0
  296. package/packages/core/dist/secrets/use.js.map +1 -1
  297. package/packages/core/dist/system-context.d.ts +6 -0
  298. package/packages/core/dist/system-context.d.ts.map +1 -1
  299. package/packages/core/dist/tools.d.ts +16 -0
  300. package/packages/core/dist/tools.d.ts.map +1 -1
  301. package/packages/core/dist/tools.js.map +1 -1
  302. package/packages/core/dist/views.d.ts +8 -8
  303. package/packages/core/migrations/079_mission_browser_owner.sql +7 -0
  304. package/packages/gateway/dist/.tsbuildinfo +1 -1
  305. package/packages/gateway/dist/agents/catalog.d.ts.map +1 -1
  306. package/packages/gateway/dist/agents/catalog.js +6 -3
  307. package/packages/gateway/dist/agents/catalog.js.map +1 -1
  308. package/packages/gateway/dist/agents/catalogue-package.d.ts +24 -10
  309. package/packages/gateway/dist/agents/catalogue-package.d.ts.map +1 -1
  310. package/packages/gateway/dist/agents/catalogue-package.js +6 -2
  311. package/packages/gateway/dist/agents/catalogue-package.js.map +1 -1
  312. package/packages/gateway/dist/agents/platform-catalogue.d.ts +17 -4
  313. package/packages/gateway/dist/agents/platform-catalogue.d.ts.map +1 -1
  314. package/packages/gateway/dist/agents/platform-catalogue.js +25 -5
  315. package/packages/gateway/dist/agents/platform-catalogue.js.map +1 -1
  316. package/packages/gateway/dist/browser-host.d.ts +7 -0
  317. package/packages/gateway/dist/browser-host.d.ts.map +1 -1
  318. package/packages/gateway/dist/browser-host.js +22 -0
  319. package/packages/gateway/dist/browser-host.js.map +1 -1
  320. package/packages/gateway/dist/missions/agent-run.d.ts +6 -0
  321. package/packages/gateway/dist/missions/agent-run.d.ts.map +1 -1
  322. package/packages/gateway/dist/missions/agent-run.js +2 -1
  323. package/packages/gateway/dist/missions/agent-run.js.map +1 -1
  324. package/packages/gateway/dist/missions/chrome-scope.d.ts +91 -0
  325. package/packages/gateway/dist/missions/chrome-scope.d.ts.map +1 -0
  326. package/packages/gateway/dist/missions/chrome-scope.js +194 -0
  327. package/packages/gateway/dist/missions/chrome-scope.js.map +1 -0
  328. package/packages/gateway/dist/missions/execute.d.ts +20 -0
  329. package/packages/gateway/dist/missions/execute.d.ts.map +1 -1
  330. package/packages/gateway/dist/missions/execute.js +77 -5
  331. package/packages/gateway/dist/missions/execute.js.map +1 -1
  332. package/packages/gateway/dist/missions/reminders.d.ts +11 -2
  333. package/packages/gateway/dist/missions/reminders.d.ts.map +1 -1
  334. package/packages/gateway/dist/missions/reminders.js +55 -5
  335. package/packages/gateway/dist/missions/reminders.js.map +1 -1
  336. package/packages/gateway/dist/owner-notify.d.ts +0 -11
  337. package/packages/gateway/dist/owner-notify.d.ts.map +1 -1
  338. package/packages/gateway/dist/owner-notify.js +3 -1
  339. package/packages/gateway/dist/owner-notify.js.map +1 -1
  340. package/packages/gateway/dist/owner-profile-edit.d.ts +3 -2
  341. package/packages/gateway/dist/owner-profile-edit.d.ts.map +1 -1
  342. package/packages/gateway/dist/owner-profile-edit.js +4 -2
  343. package/packages/gateway/dist/owner-profile-edit.js.map +1 -1
  344. package/packages/gateway/dist/serve.d.ts.map +1 -1
  345. package/packages/gateway/dist/serve.js +3 -2
  346. package/packages/gateway/dist/serve.js.map +1 -1
  347. package/packages/gateway/dist/system-context.d.ts +10 -2
  348. package/packages/gateway/dist/system-context.d.ts.map +1 -1
  349. package/packages/gateway/dist/system-context.js +24 -10
  350. package/packages/gateway/dist/system-context.js.map +1 -1
  351. package/packages/gateway/dist/telegram/approvals.d.ts +2 -1
  352. package/packages/gateway/dist/telegram/approvals.d.ts.map +1 -1
  353. package/packages/gateway/dist/telegram/approvals.js +16 -4
  354. package/packages/gateway/dist/telegram/approvals.js.map +1 -1
  355. package/packages/gateway/dist/web/api-routes.d.ts.map +1 -1
  356. package/packages/gateway/dist/web/api-routes.js +8 -0
  357. package/packages/gateway/dist/web/api-routes.js.map +1 -1
  358. package/packages/gateway/dist/web/approval-ask.d.ts +8 -0
  359. package/packages/gateway/dist/web/approval-ask.d.ts.map +1 -1
  360. package/packages/gateway/dist/web/approval-ask.js +25 -0
  361. package/packages/gateway/dist/web/approval-ask.js.map +1 -1
  362. package/packages/gateway/dist/web/plugins.d.ts.map +1 -1
  363. package/packages/gateway/dist/web/plugins.js +3 -1
  364. package/packages/gateway/dist/web/plugins.js.map +1 -1
  365. package/packages/gateway/dist/web/read.d.ts +2 -0
  366. package/packages/gateway/dist/web/read.d.ts.map +1 -1
  367. package/packages/gateway/dist/web/read.js +1 -0
  368. package/packages/gateway/dist/web/read.js.map +1 -1
  369. package/packages/gateway/dist/web/runtimes.d.ts +10 -0
  370. package/packages/gateway/dist/web/runtimes.d.ts.map +1 -0
  371. package/packages/gateway/dist/web/runtimes.js +25 -0
  372. package/packages/gateway/dist/web/runtimes.js.map +1 -0
  373. package/packages/gateway/dist/web/server.d.ts.map +1 -1
  374. package/packages/gateway/dist/web/server.js +20 -2
  375. package/packages/gateway/dist/web/server.js.map +1 -1
  376. package/packages/gateway/dist/web/write.d.ts +11 -1
  377. package/packages/gateway/dist/web/write.d.ts.map +1 -1
  378. package/packages/gateway/dist/web/write.js +18 -1
  379. package/packages/gateway/dist/web/write.js.map +1 -1
  380. package/packages/install/dist/.tsbuildinfo +1 -1
  381. package/packages/runtime/dist/.tsbuildinfo +1 -1
  382. package/packages/runtime/dist/delegate.d.ts.map +1 -1
  383. package/packages/runtime/dist/delegate.js +1 -0
  384. package/packages/runtime/dist/delegate.js.map +1 -1
  385. package/packages/runtime/dist/index.d.ts +1 -0
  386. package/packages/runtime/dist/index.d.ts.map +1 -1
  387. package/packages/runtime/dist/index.js +1 -0
  388. package/packages/runtime/dist/index.js.map +1 -1
  389. package/packages/runtime/dist/language.d.ts +65 -0
  390. package/packages/runtime/dist/language.d.ts.map +1 -0
  391. package/packages/runtime/dist/language.js +191 -0
  392. package/packages/runtime/dist/language.js.map +1 -0
  393. package/packages/runtime/dist/loop.d.ts +9 -1
  394. package/packages/runtime/dist/loop.d.ts.map +1 -1
  395. package/packages/runtime/dist/loop.js +78 -4
  396. package/packages/runtime/dist/loop.js.map +1 -1
  397. package/packages/tools/artifacts/dist/.tsbuildinfo +1 -1
  398. package/packages/tools/browser/dist/.tsbuildinfo +1 -1
  399. package/packages/tools/browser/dist/controller.d.ts +5 -0
  400. package/packages/tools/browser/dist/controller.d.ts.map +1 -1
  401. package/packages/tools/browser/dist/controller.js +41 -5
  402. package/packages/tools/browser/dist/controller.js.map +1 -1
  403. package/packages/tools/browser/dist/routes.d.ts +6 -0
  404. package/packages/tools/browser/dist/routes.d.ts.map +1 -1
  405. package/packages/tools/browser/dist/routes.js +2 -2
  406. package/packages/tools/browser/dist/routes.js.map +1 -1
  407. package/packages/tools/email/dist/.tsbuildinfo +1 -1
  408. package/packages/tools/host/dist/.tsbuildinfo +1 -1
  409. package/packages/tools/mcp/dist/.tsbuildinfo +1 -1
  410. package/packages/tools/memory/dist/.tsbuildinfo +1 -1
  411. package/packages/tools/web/dist/.tsbuildinfo +1 -1
  412. package/packages/web/dist/assets/{index-C2yWZED2.css → index-CkzsX0YQ.css} +1 -1
  413. package/packages/web/dist/assets/index-Dg5Dl0iF.js +150 -0
  414. package/packages/web/dist/assets/{lottie_light-CVXFbeEK.js → lottie_light-vNpJ-Svm.js} +1 -1
  415. package/packages/web/dist/build.json +1 -1
  416. package/packages/web/dist/index.html +2 -2
  417. package/packages/web/dist/precache.json +4 -4
  418. package/packages/web/dist/assets/index-CIhME8Ui.js +0 -150
@@ -0,0 +1,150 @@
1
+ var wD=Object.defineProperty;var _k=e=>{throw TypeError(e)};var yD=(e,n,s)=>n in e?wD(e,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[n]=s;var zk=(e,n,s)=>yD(e,typeof n!="symbol"?n+"":n,s),Uk=(e,n,s)=>n.has(e)||_k("Cannot "+s);var Wn=(e,n,s)=>(Uk(e,n,"read from private field"),s?s.call(e):n.get(e)),Bk=(e,n,s)=>n.has(e)?_k("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(e):n.set(e,s),lp=(e,n,s,r)=>(Uk(e,n,"write to private field"),r?r.call(e,s):n.set(e,s),s);function bD(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 woe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function kD(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Z1={exports:{}},Bf={},eE={exports:{}},gt={};/**
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 Mu=Symbol.for("react.element"),ND=Symbol.for("react.portal"),SD=Symbol.for("react.fragment"),CD=Symbol.for("react.strict_mode"),ED=Symbol.for("react.profiler"),AD=Symbol.for("react.provider"),$D=Symbol.for("react.context"),TD=Symbol.for("react.forward_ref"),ID=Symbol.for("react.suspense"),RD=Symbol.for("react.memo"),PD=Symbol.for("react.lazy"),Wk=Symbol.iterator;function MD(e){return e===null||typeof e!="object"?null:(e=Wk&&e[Wk]||e["@@iterator"],typeof e=="function"?e:null)}var tE={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},nE=Object.assign,sE={};function No(e,n,s){this.props=e,this.context=n,this.refs=sE,this.updater=s||tE}No.prototype.isReactComponent={};No.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")};No.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function rE(){}rE.prototype=No.prototype;function Gj(e,n,s){this.props=e,this.context=n,this.refs=sE,this.updater=s||tE}var Yj=Gj.prototype=new rE;Yj.constructor=Gj;nE(Yj,No.prototype);Yj.isPureReactComponent=!0;var Hk=Array.isArray,aE=Object.prototype.hasOwnProperty,qj={current:null},iE={key:!0,ref:!0,__self:!0,__source:!0};function lE(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)aE.call(n,r)&&!iE.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:Mu,type:e,key:i,ref:l,props:a,_owner:qj.current}}function OD(e,n){return{$$typeof:Mu,type:e.type,key:n,ref:e.ref,props:e.props,_owner:e._owner}}function Qj(e){return typeof e=="object"&&e!==null&&e.$$typeof===Mu}function DD(e){var n={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(s){return n[s]})}var Kk=/\/+/g;function op(e,n){return typeof e=="object"&&e!==null&&e.key!=null?DD(""+e.key):n.toString(36)}function Zd(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 Mu:case ND:l=!0}}if(l)return l=e,a=a(l),e=r===""?"."+op(l,0):r,Hk(a)?(s="",e!=null&&(s=e.replace(Kk,"$&/")+"/"),Zd(a,n,s,"",function(u){return u})):a!=null&&(Qj(a)&&(a=OD(a,s+(!a.key||l&&l.key===a.key?"":(""+a.key).replace(Kk,"$&/")+"/")+e)),n.push(a)),1;if(l=0,r=r===""?".":r+":",Hk(e))for(var o=0;o<e.length;o++){i=e[o];var c=r+op(i,o);l+=Zd(i,n,s,c,a)}else if(c=MD(e),typeof c=="function")for(e=c.call(e),o=0;!(i=e.next()).done;)i=i.value,c=r+op(i,o++),l+=Zd(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 Zd(e,r,"","",function(i){return n.call(s,i,a++)}),r}function LD(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 cs={current:null},eh={transition:null},FD={ReactCurrentDispatcher:cs,ReactCurrentBatchConfig:eh,ReactCurrentOwner:qj};function oE(){throw Error("act(...) is not supported in production builds of React.")}gt.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(!Qj(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};gt.Component=No;gt.Fragment=SD;gt.Profiler=ED;gt.PureComponent=Gj;gt.StrictMode=CD;gt.Suspense=ID;gt.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=FD;gt.act=oE;gt.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=nE({},e.props),a=e.key,i=e.ref,l=e._owner;if(n!=null){if(n.ref!==void 0&&(i=n.ref,l=qj.current),n.key!==void 0&&(a=""+n.key),e.type&&e.type.defaultProps)var o=e.type.defaultProps;for(c in n)aE.call(n,c)&&!iE.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:Mu,type:e.type,key:a,ref:i,props:r,_owner:l}};gt.createContext=function(e){return e={$$typeof:$D,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:AD,_context:e},e.Consumer=e};gt.createElement=lE;gt.createFactory=function(e){var n=lE.bind(null,e);return n.type=e,n};gt.createRef=function(){return{current:null}};gt.forwardRef=function(e){return{$$typeof:TD,render:e}};gt.isValidElement=Qj;gt.lazy=function(e){return{$$typeof:PD,_payload:{_status:-1,_result:e},_init:LD}};gt.memo=function(e,n){return{$$typeof:RD,type:e,compare:n===void 0?null:n}};gt.startTransition=function(e){var n=eh.transition;eh.transition={};try{e()}finally{eh.transition=n}};gt.unstable_act=oE;gt.useCallback=function(e,n){return cs.current.useCallback(e,n)};gt.useContext=function(e){return cs.current.useContext(e)};gt.useDebugValue=function(){};gt.useDeferredValue=function(e){return cs.current.useDeferredValue(e)};gt.useEffect=function(e,n){return cs.current.useEffect(e,n)};gt.useId=function(){return cs.current.useId()};gt.useImperativeHandle=function(e,n,s){return cs.current.useImperativeHandle(e,n,s)};gt.useInsertionEffect=function(e,n){return cs.current.useInsertionEffect(e,n)};gt.useLayoutEffect=function(e,n){return cs.current.useLayoutEffect(e,n)};gt.useMemo=function(e,n){return cs.current.useMemo(e,n)};gt.useReducer=function(e,n,s){return cs.current.useReducer(e,n,s)};gt.useRef=function(e){return cs.current.useRef(e)};gt.useState=function(e){return cs.current.useState(e)};gt.useSyncExternalStore=function(e,n,s){return cs.current.useSyncExternalStore(e,n,s)};gt.useTransition=function(){return cs.current.useTransition()};gt.version="18.3.1";eE.exports=gt;var d=eE.exports;const _D=kD(d),So=bD({__proto__:null,default:_D},[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 zD=d,UD=Symbol.for("react.element"),BD=Symbol.for("react.fragment"),WD=Object.prototype.hasOwnProperty,HD=zD.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,KD={key:!0,ref:!0,__self:!0,__source:!0};function cE(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)WD.call(n,r)&&!KD.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:UD,type:e,key:i,ref:l,props:a,_owner:HD.current}}Bf.Fragment=BD;Bf.jsx=cE;Bf.jsxs=cE;Z1.exports=Bf;var t=Z1.exports,uE={exports:{}},Ds={},dE={exports:{}},hE={};/**
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,L){var _=M.length;M.push(L);e:for(;0<_;){var Y=_-1>>>1,B=M[Y];if(0<a(B,L))M[Y]=L,M[_]=B,_=Y;else break e}}function s(M){return M.length===0?null:M[0]}function r(M){if(M.length===0)return null;var L=M[0],_=M.pop();if(_!==L){M[0]=_;e:for(var Y=0,B=M.length,se=B>>>1;Y<se;){var G=2*(Y+1)-1,X=M[G],K=G+1,J=M[K];if(0>a(X,_))K<B&&0>a(J,X)?(M[Y]=J,M[K]=_,Y=K):(M[Y]=X,M[G]=_,Y=G);else if(K<B&&0>a(J,_))M[Y]=J,M[K]=_,Y=K;else break e}}return L}function a(M,L){var _=M.sortIndex-L.sortIndex;return _!==0?_:M.id-L.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,f=null,m=3,p=!1,v=!1,g=!1,k=typeof setTimeout=="function"?setTimeout:null,j=typeof clearTimeout=="function"?clearTimeout:null,x=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function w(M){for(var L=s(u);L!==null;){if(L.callback===null)r(u);else if(L.startTime<=M)r(u),L.sortIndex=L.expirationTime,n(c,L);else break;L=s(u)}}function N(M){if(g=!1,w(M),!v)if(s(c)!==null)v=!0,U(y);else{var L=s(u);L!==null&&W(N,L.startTime-M)}}function y(M,L){v=!1,g&&(g=!1,j(C),C=-1),p=!0;var _=m;try{for(w(L),f=s(c);f!==null&&(!(f.expirationTime>L)||M&&!I());){var Y=f.callback;if(typeof Y=="function"){f.callback=null,m=f.priorityLevel;var B=Y(f.expirationTime<=L);L=e.unstable_now(),typeof B=="function"?f.callback=B:f===s(c)&&r(c),w(L)}else r(c);f=s(c)}if(f!==null)var se=!0;else{var G=s(u);G!==null&&W(N,G.startTime-L),se=!1}return se}finally{f=null,m=_,p=!1}}var b=!1,S=null,C=-1,A=5,$=-1;function I(){return!(e.unstable_now()-$<A)}function P(){if(S!==null){var M=e.unstable_now();$=M;var L=!0;try{L=S(!0,M)}finally{L?O():(b=!1,S=null)}}else b=!1}var O;if(typeof x=="function")O=function(){x(P)};else if(typeof MessageChannel<"u"){var R=new MessageChannel,D=R.port2;R.port1.onmessage=P,O=function(){D.postMessage(null)}}else O=function(){k(P,0)};function U(M){S=M,b||(b=!0,O())}function W(M,L){C=k(function(){M(e.unstable_now())},L)}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(){v||p||(v=!0,U(y))},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 m},e.unstable_getFirstCallbackNode=function(){return s(c)},e.unstable_next=function(M){switch(m){case 1:case 2:case 3:var L=3;break;default:L=m}var _=m;m=L;try{return M()}finally{m=_}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(M,L){switch(M){case 1:case 2:case 3:case 4:case 5:break;default:M=3}var _=m;m=M;try{return L()}finally{m=_}},e.unstable_scheduleCallback=function(M,L,_){var Y=e.unstable_now();switch(typeof _=="object"&&_!==null?(_=_.delay,_=typeof _=="number"&&0<_?Y+_:Y):_=Y,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=_+B,M={id:h++,callback:L,priorityLevel:M,startTime:_,expirationTime:B,sortIndex:-1},_>Y?(M.sortIndex=_,n(u,M),s(c)===null&&M===s(u)&&(g?(j(C),C=-1):g=!0,W(N,_-Y))):(M.sortIndex=B,n(c,M),v||p||(v=!0,U(y))),M},e.unstable_shouldYield=I,e.unstable_wrapCallback=function(M){var L=m;return function(){var _=m;m=L;try{return M.apply(this,arguments)}finally{m=_}}}})(hE);dE.exports=hE;var VD=dE.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 GD=d,Ps=VD;function Ne(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 fE=new Set,Kc={};function sl(e,n){no(e,n),no(e+"Capture",n)}function no(e,n){for(Kc[e]=n,e=0;e<n.length;e++)fE.add(n[e])}var ga=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),qg=Object.prototype.hasOwnProperty,YD=/^[: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]*$/,Vk={},Gk={};function qD(e){return qg.call(Gk,e)?!0:qg.call(Vk,e)?!1:YD.test(e)?Gk[e]=!0:(Vk[e]=!0,!1)}function QD(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 JD(e,n,s,r){if(n===null||typeof n>"u"||QD(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 us(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 Fn={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){Fn[e]=new us(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var n=e[0];Fn[n]=new us(n,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){Fn[e]=new us(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Fn[e]=new us(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){Fn[e]=new us(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){Fn[e]=new us(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){Fn[e]=new us(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){Fn[e]=new us(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){Fn[e]=new us(e,5,!1,e.toLowerCase(),null,!1,!1)});var Jj=/[\-:]([a-z])/g;function Xj(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(Jj,Xj);Fn[n]=new us(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(Jj,Xj);Fn[n]=new us(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(Jj,Xj);Fn[n]=new us(n,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){Fn[e]=new us(e,1,!1,e.toLowerCase(),null,!1,!1)});Fn.xlinkHref=new us("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){Fn[e]=new us(e,1,!1,e.toLowerCase(),null,!0,!0)});function Zj(e,n,s,r){var a=Fn.hasOwnProperty(n)?Fn[n]:null;(a!==null?a.type!==0:r||!(2<n.length)||n[0]!=="o"&&n[0]!=="O"||n[1]!=="n"&&n[1]!=="N")&&(JD(n,s,a,r)&&(s=null),r||a===null?qD(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 ka=GD.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,od=Symbol.for("react.element"),$l=Symbol.for("react.portal"),Tl=Symbol.for("react.fragment"),ew=Symbol.for("react.strict_mode"),Qg=Symbol.for("react.profiler"),mE=Symbol.for("react.provider"),pE=Symbol.for("react.context"),tw=Symbol.for("react.forward_ref"),Jg=Symbol.for("react.suspense"),Xg=Symbol.for("react.suspense_list"),nw=Symbol.for("react.memo"),Ra=Symbol.for("react.lazy"),gE=Symbol.for("react.offscreen"),Yk=Symbol.iterator;function Xo(e){return e===null||typeof e!="object"?null:(e=Yk&&e[Yk]||e["@@iterator"],typeof e=="function"?e:null)}var Zt=Object.assign,cp;function pc(e){if(cp===void 0)try{throw Error()}catch(s){var n=s.stack.trim().match(/\n( *(at )?)/);cp=n&&n[1]||""}return`
34
+ `+cp+e}var up=!1;function dp(e,n){if(!e||up)return"";up=!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{up=!1,Error.prepareStackTrace=s}return(e=e?e.displayName||e.name:"")?pc(e):""}function XD(e){switch(e.tag){case 5:return pc(e.type);case 16:return pc("Lazy");case 13:return pc("Suspense");case 19:return pc("SuspenseList");case 0:case 2:case 15:return e=dp(e.type,!1),e;case 11:return e=dp(e.type.render,!1),e;case 1:return e=dp(e.type,!0),e;default:return""}}function Zg(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 Tl:return"Fragment";case $l:return"Portal";case Qg:return"Profiler";case ew:return"StrictMode";case Jg:return"Suspense";case Xg:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case pE:return(e.displayName||"Context")+".Consumer";case mE:return(e._context.displayName||"Context")+".Provider";case tw:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case nw:return n=e.displayName||null,n!==null?n:Zg(e.type)||"Memo";case Ra:n=e._payload,e=e._init;try{return Zg(e(n))}catch{}}return null}function ZD(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 Zg(n);case 8:return n===ew?"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 Za(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function xE(e){var n=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(n==="checkbox"||n==="radio")}function eL(e){var n=xE(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 cd(e){e._valueTracker||(e._valueTracker=eL(e))}function vE(e){if(!e)return!1;var n=e._valueTracker;if(!n)return!0;var s=n.getValue(),r="";return e&&(r=xE(e)?e.checked?"true":"false":e.value),e=r,e!==s?(n.setValue(e),!0):!1}function Ah(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 ex(e,n){var s=n.checked;return Zt({},n,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:s??e._wrapperState.initialChecked})}function qk(e,n){var s=n.defaultValue==null?"":n.defaultValue,r=n.checked!=null?n.checked:n.defaultChecked;s=Za(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 jE(e,n){n=n.checked,n!=null&&Zj(e,"checked",n,!1)}function tx(e,n){jE(e,n);var s=Za(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")?nx(e,n.type,s):n.hasOwnProperty("defaultValue")&&nx(e,n.type,Za(n.defaultValue)),n.checked==null&&n.defaultChecked!=null&&(e.defaultChecked=!!n.defaultChecked)}function Qk(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 nx(e,n,s){(n!=="number"||Ah(e.ownerDocument)!==e)&&(s==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+s&&(e.defaultValue=""+s))}var gc=Array.isArray;function Hl(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=""+Za(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 sx(e,n){if(n.dangerouslySetInnerHTML!=null)throw Error(Ne(91));return Zt({},n,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function Jk(e,n){var s=n.value;if(s==null){if(s=n.children,n=n.defaultValue,s!=null){if(n!=null)throw Error(Ne(92));if(gc(s)){if(1<s.length)throw Error(Ne(93));s=s[0]}n=s}n==null&&(n=""),s=n}e._wrapperState={initialValue:Za(s)}}function wE(e,n){var s=Za(n.value),r=Za(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 Xk(e){var n=e.textContent;n===e._wrapperState.initialValue&&n!==""&&n!==null&&(e.value=n)}function yE(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 rx(e,n){return e==null||e==="http://www.w3.org/1999/xhtml"?yE(n):e==="http://www.w3.org/2000/svg"&&n==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var ud,bE=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(ud=ud||document.createElement("div"),ud.innerHTML="<svg>"+n.valueOf().toString()+"</svg>",n=ud.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;n.firstChild;)e.appendChild(n.firstChild)}});function Vc(e,n){if(n){var s=e.firstChild;if(s&&s===e.lastChild&&s.nodeType===3){s.nodeValue=n;return}}e.textContent=n}var Sc={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},tL=["Webkit","ms","Moz","O"];Object.keys(Sc).forEach(function(e){tL.forEach(function(n){n=n+e.charAt(0).toUpperCase()+e.substring(1),Sc[n]=Sc[e]})});function kE(e,n,s){return n==null||typeof n=="boolean"||n===""?"":s||typeof n!="number"||n===0||Sc.hasOwnProperty(e)&&Sc[e]?(""+n).trim():n+"px"}function NE(e,n){e=e.style;for(var s in n)if(n.hasOwnProperty(s)){var r=s.indexOf("--")===0,a=kE(s,n[s],r);s==="float"&&(s="cssFloat"),r?e.setProperty(s,a):e[s]=a}}var nL=Zt({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 ax(e,n){if(n){if(nL[e]&&(n.children!=null||n.dangerouslySetInnerHTML!=null))throw Error(Ne(137,e));if(n.dangerouslySetInnerHTML!=null){if(n.children!=null)throw Error(Ne(60));if(typeof n.dangerouslySetInnerHTML!="object"||!("__html"in n.dangerouslySetInnerHTML))throw Error(Ne(61))}if(n.style!=null&&typeof n.style!="object")throw Error(Ne(62))}}function ix(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 lx=null;function sw(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var ox=null,Kl=null,Vl=null;function Zk(e){if(e=Lu(e)){if(typeof ox!="function")throw Error(Ne(280));var n=e.stateNode;n&&(n=Gf(n),ox(e.stateNode,e.type,n))}}function SE(e){Kl?Vl?Vl.push(e):Vl=[e]:Kl=e}function CE(){if(Kl){var e=Kl,n=Vl;if(Vl=Kl=null,Zk(e),n)for(e=0;e<n.length;e++)Zk(n[e])}}function EE(e,n){return e(n)}function AE(){}var hp=!1;function $E(e,n,s){if(hp)return e(n,s);hp=!0;try{return EE(e,n,s)}finally{hp=!1,(Kl!==null||Vl!==null)&&(AE(),CE())}}function Gc(e,n){var s=e.stateNode;if(s===null)return null;var r=Gf(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(Ne(231,n,typeof s));return s}var cx=!1;if(ga)try{var Zo={};Object.defineProperty(Zo,"passive",{get:function(){cx=!0}}),window.addEventListener("test",Zo,Zo),window.removeEventListener("test",Zo,Zo)}catch{cx=!1}function sL(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 Cc=!1,$h=null,Th=!1,ux=null,rL={onError:function(e){Cc=!0,$h=e}};function aL(e,n,s,r,a,i,l,o,c){Cc=!1,$h=null,sL.apply(rL,arguments)}function iL(e,n,s,r,a,i,l,o,c){if(aL.apply(this,arguments),Cc){if(Cc){var u=$h;Cc=!1,$h=null}else throw Error(Ne(198));Th||(Th=!0,ux=u)}}function rl(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 TE(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 e0(e){if(rl(e)!==e)throw Error(Ne(188))}function lL(e){var n=e.alternate;if(!n){if(n=rl(e),n===null)throw Error(Ne(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 e0(a),e;if(i===r)return e0(a),n;i=i.sibling}throw Error(Ne(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(Ne(189))}}if(s.alternate!==r)throw Error(Ne(190))}if(s.tag!==3)throw Error(Ne(188));return s.stateNode.current===s?e:n}function IE(e){return e=lL(e),e!==null?RE(e):null}function RE(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var n=RE(e);if(n!==null)return n;e=e.sibling}return null}var PE=Ps.unstable_scheduleCallback,t0=Ps.unstable_cancelCallback,oL=Ps.unstable_shouldYield,cL=Ps.unstable_requestPaint,rn=Ps.unstable_now,uL=Ps.unstable_getCurrentPriorityLevel,rw=Ps.unstable_ImmediatePriority,ME=Ps.unstable_UserBlockingPriority,Ih=Ps.unstable_NormalPriority,dL=Ps.unstable_LowPriority,OE=Ps.unstable_IdlePriority,Wf=null,Br=null;function hL(e){if(Br&&typeof Br.onCommitFiberRoot=="function")try{Br.onCommitFiberRoot(Wf,e,void 0,(e.current.flags&128)===128)}catch{}}var hr=Math.clz32?Math.clz32:pL,fL=Math.log,mL=Math.LN2;function pL(e){return e>>>=0,e===0?32:31-(fL(e)/mL|0)|0}var dd=64,hd=4194304;function xc(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 Rh(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=xc(o):(i&=l,i!==0&&(r=xc(i)))}else l=s&~a,l!==0?r=xc(l):i!==0&&(r=xc(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-hr(n),a=1<<s,r|=e[s],n&=~a;return r}function gL(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 xL(e,n){for(var s=e.suspendedLanes,r=e.pingedLanes,a=e.expirationTimes,i=e.pendingLanes;0<i;){var l=31-hr(i),o=1<<l,c=a[l];c===-1?(!(o&s)||o&r)&&(a[l]=gL(o,n)):c<=n&&(e.expiredLanes|=o),i&=~o}}function dx(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function DE(){var e=dd;return dd<<=1,!(dd&4194240)&&(dd=64),e}function fp(e){for(var n=[],s=0;31>s;s++)n.push(e);return n}function Ou(e,n,s){e.pendingLanes|=n,n!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,n=31-hr(n),e[n]=s}function vL(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-hr(s),i=1<<a;n[a]=0,r[a]=-1,e[a]=-1,s&=~i}}function aw(e,n){var s=e.entangledLanes|=n;for(e=e.entanglements;s;){var r=31-hr(s),a=1<<r;a&n|e[r]&n&&(e[r]|=n),s&=~a}}var Nt=0;function LE(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var FE,iw,_E,zE,UE,hx=!1,fd=[],Ua=null,Ba=null,Wa=null,Yc=new Map,qc=new Map,Ma=[],jL="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 n0(e,n){switch(e){case"focusin":case"focusout":Ua=null;break;case"dragenter":case"dragleave":Ba=null;break;case"mouseover":case"mouseout":Wa=null;break;case"pointerover":case"pointerout":Yc.delete(n.pointerId);break;case"gotpointercapture":case"lostpointercapture":qc.delete(n.pointerId)}}function ec(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=Lu(n),n!==null&&iw(n)),e):(e.eventSystemFlags|=r,n=e.targetContainers,a!==null&&n.indexOf(a)===-1&&n.push(a),e)}function wL(e,n,s,r,a){switch(n){case"focusin":return Ua=ec(Ua,e,n,s,r,a),!0;case"dragenter":return Ba=ec(Ba,e,n,s,r,a),!0;case"mouseover":return Wa=ec(Wa,e,n,s,r,a),!0;case"pointerover":var i=a.pointerId;return Yc.set(i,ec(Yc.get(i)||null,e,n,s,r,a)),!0;case"gotpointercapture":return i=a.pointerId,qc.set(i,ec(qc.get(i)||null,e,n,s,r,a)),!0}return!1}function BE(e){var n=Pi(e.target);if(n!==null){var s=rl(n);if(s!==null){if(n=s.tag,n===13){if(n=TE(s),n!==null){e.blockedOn=n,UE(e.priority,function(){_E(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 th(e){if(e.blockedOn!==null)return!1;for(var n=e.targetContainers;0<n.length;){var s=fx(e.domEventName,e.eventSystemFlags,n[0],e.nativeEvent);if(s===null){s=e.nativeEvent;var r=new s.constructor(s.type,s);lx=r,s.target.dispatchEvent(r),lx=null}else return n=Lu(s),n!==null&&iw(n),e.blockedOn=s,!1;n.shift()}return!0}function s0(e,n,s){th(e)&&s.delete(n)}function yL(){hx=!1,Ua!==null&&th(Ua)&&(Ua=null),Ba!==null&&th(Ba)&&(Ba=null),Wa!==null&&th(Wa)&&(Wa=null),Yc.forEach(s0),qc.forEach(s0)}function tc(e,n){e.blockedOn===n&&(e.blockedOn=null,hx||(hx=!0,Ps.unstable_scheduleCallback(Ps.unstable_NormalPriority,yL)))}function Qc(e){function n(a){return tc(a,e)}if(0<fd.length){tc(fd[0],e);for(var s=1;s<fd.length;s++){var r=fd[s];r.blockedOn===e&&(r.blockedOn=null)}}for(Ua!==null&&tc(Ua,e),Ba!==null&&tc(Ba,e),Wa!==null&&tc(Wa,e),Yc.forEach(n),qc.forEach(n),s=0;s<Ma.length;s++)r=Ma[s],r.blockedOn===e&&(r.blockedOn=null);for(;0<Ma.length&&(s=Ma[0],s.blockedOn===null);)BE(s),s.blockedOn===null&&Ma.shift()}var Gl=ka.ReactCurrentBatchConfig,Ph=!0;function bL(e,n,s,r){var a=Nt,i=Gl.transition;Gl.transition=null;try{Nt=1,lw(e,n,s,r)}finally{Nt=a,Gl.transition=i}}function kL(e,n,s,r){var a=Nt,i=Gl.transition;Gl.transition=null;try{Nt=4,lw(e,n,s,r)}finally{Nt=a,Gl.transition=i}}function lw(e,n,s,r){if(Ph){var a=fx(e,n,s,r);if(a===null)kp(e,n,r,Mh,s),n0(e,r);else if(wL(a,e,n,s,r))r.stopPropagation();else if(n0(e,r),n&4&&-1<jL.indexOf(e)){for(;a!==null;){var i=Lu(a);if(i!==null&&FE(i),i=fx(e,n,s,r),i===null&&kp(e,n,r,Mh,s),i===a)break;a=i}a!==null&&r.stopPropagation()}else kp(e,n,r,null,s)}}var Mh=null;function fx(e,n,s,r){if(Mh=null,e=sw(r),e=Pi(e),e!==null)if(n=rl(e),n===null)e=null;else if(s=n.tag,s===13){if(e=TE(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 Mh=e,null}function WE(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(uL()){case rw:return 1;case ME:return 4;case Ih:case dL:return 16;case OE:return 536870912;default:return 16}default:return 16}}var La=null,ow=null,nh=null;function HE(){if(nh)return nh;var e,n=ow,s=n.length,r,a="value"in La?La.value:La.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 nh=a.slice(e,1<r?1-r:void 0)}function sh(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 md(){return!0}function r0(){return!1}function Ls(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)?md:r0,this.isPropagationStopped=r0,this}return Zt(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=md)},stopPropagation:function(){var s=this.nativeEvent;s&&(s.stopPropagation?s.stopPropagation():typeof s.cancelBubble!="unknown"&&(s.cancelBubble=!0),this.isPropagationStopped=md)},persist:function(){},isPersistent:md}),n}var Co={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},cw=Ls(Co),Du=Zt({},Co,{view:0,detail:0}),NL=Ls(Du),mp,pp,nc,Hf=Zt({},Du,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:uw,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!==nc&&(nc&&e.type==="mousemove"?(mp=e.screenX-nc.screenX,pp=e.screenY-nc.screenY):pp=mp=0,nc=e),mp)},movementY:function(e){return"movementY"in e?e.movementY:pp}}),a0=Ls(Hf),SL=Zt({},Hf,{dataTransfer:0}),CL=Ls(SL),EL=Zt({},Du,{relatedTarget:0}),gp=Ls(EL),AL=Zt({},Co,{animationName:0,elapsedTime:0,pseudoElement:0}),$L=Ls(AL),TL=Zt({},Co,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),IL=Ls(TL),RL=Zt({},Co,{data:0}),i0=Ls(RL),PL={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},ML={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"},OL={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function DL(e){var n=this.nativeEvent;return n.getModifierState?n.getModifierState(e):(e=OL[e])?!!n[e]:!1}function uw(){return DL}var LL=Zt({},Du,{key:function(e){if(e.key){var n=PL[e.key]||e.key;if(n!=="Unidentified")return n}return e.type==="keypress"?(e=sh(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?ML[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:uw,charCode:function(e){return e.type==="keypress"?sh(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?sh(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),FL=Ls(LL),_L=Zt({},Hf,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),l0=Ls(_L),zL=Zt({},Du,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:uw}),UL=Ls(zL),BL=Zt({},Co,{propertyName:0,elapsedTime:0,pseudoElement:0}),WL=Ls(BL),HL=Zt({},Hf,{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}),KL=Ls(HL),VL=[9,13,27,32],dw=ga&&"CompositionEvent"in window,Ec=null;ga&&"documentMode"in document&&(Ec=document.documentMode);var GL=ga&&"TextEvent"in window&&!Ec,KE=ga&&(!dw||Ec&&8<Ec&&11>=Ec),o0=" ",c0=!1;function VE(e,n){switch(e){case"keyup":return VL.indexOf(n.keyCode)!==-1;case"keydown":return n.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function GE(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Il=!1;function YL(e,n){switch(e){case"compositionend":return GE(n);case"keypress":return n.which!==32?null:(c0=!0,o0);case"textInput":return e=n.data,e===o0&&c0?null:e;default:return null}}function qL(e,n){if(Il)return e==="compositionend"||!dw&&VE(e,n)?(e=HE(),nh=ow=La=null,Il=!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 KE&&n.locale!=="ko"?null:n.data;default:return null}}var QL={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 u0(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n==="input"?!!QL[e.type]:n==="textarea"}function YE(e,n,s,r){SE(r),n=Oh(n,"onChange"),0<n.length&&(s=new cw("onChange","change",null,s,r),e.push({event:s,listeners:n}))}var Ac=null,Jc=null;function JL(e){aA(e,0)}function Kf(e){var n=Ml(e);if(vE(n))return e}function XL(e,n){if(e==="change")return n}var qE=!1;if(ga){var xp;if(ga){var vp="oninput"in document;if(!vp){var d0=document.createElement("div");d0.setAttribute("oninput","return;"),vp=typeof d0.oninput=="function"}xp=vp}else xp=!1;qE=xp&&(!document.documentMode||9<document.documentMode)}function h0(){Ac&&(Ac.detachEvent("onpropertychange",QE),Jc=Ac=null)}function QE(e){if(e.propertyName==="value"&&Kf(Jc)){var n=[];YE(n,Jc,e,sw(e)),$E(JL,n)}}function ZL(e,n,s){e==="focusin"?(h0(),Ac=n,Jc=s,Ac.attachEvent("onpropertychange",QE)):e==="focusout"&&h0()}function eF(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return Kf(Jc)}function tF(e,n){if(e==="click")return Kf(n)}function nF(e,n){if(e==="input"||e==="change")return Kf(n)}function sF(e,n){return e===n&&(e!==0||1/e===1/n)||e!==e&&n!==n}var gr=typeof Object.is=="function"?Object.is:sF;function Xc(e,n){if(gr(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(!qg.call(n,a)||!gr(e[a],n[a]))return!1}return!0}function f0(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function m0(e,n){var s=f0(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=f0(s)}}function JE(e,n){return e&&n?e===n?!0:e&&e.nodeType===3?!1:n&&n.nodeType===3?JE(e,n.parentNode):"contains"in e?e.contains(n):e.compareDocumentPosition?!!(e.compareDocumentPosition(n)&16):!1:!1}function XE(){for(var e=window,n=Ah();n instanceof e.HTMLIFrameElement;){try{var s=typeof n.contentWindow.location.href=="string"}catch{s=!1}if(s)e=n.contentWindow;else break;n=Ah(e.document)}return n}function hw(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 rF(e){var n=XE(),s=e.focusedElem,r=e.selectionRange;if(n!==s&&s&&s.ownerDocument&&JE(s.ownerDocument.documentElement,s)){if(r!==null&&hw(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=m0(s,i);var l=m0(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 aF=ga&&"documentMode"in document&&11>=document.documentMode,Rl=null,mx=null,$c=null,px=!1;function p0(e,n,s){var r=s.window===s?s.document:s.nodeType===9?s:s.ownerDocument;px||Rl==null||Rl!==Ah(r)||(r=Rl,"selectionStart"in r&&hw(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}),$c&&Xc($c,r)||($c=r,r=Oh(mx,"onSelect"),0<r.length&&(n=new cw("onSelect","select",null,n,s),e.push({event:n,listeners:r}),n.target=Rl)))}function pd(e,n){var s={};return s[e.toLowerCase()]=n.toLowerCase(),s["Webkit"+e]="webkit"+n,s["Moz"+e]="moz"+n,s}var Pl={animationend:pd("Animation","AnimationEnd"),animationiteration:pd("Animation","AnimationIteration"),animationstart:pd("Animation","AnimationStart"),transitionend:pd("Transition","TransitionEnd")},jp={},ZE={};ga&&(ZE=document.createElement("div").style,"AnimationEvent"in window||(delete Pl.animationend.animation,delete Pl.animationiteration.animation,delete Pl.animationstart.animation),"TransitionEvent"in window||delete Pl.transitionend.transition);function Vf(e){if(jp[e])return jp[e];if(!Pl[e])return e;var n=Pl[e],s;for(s in n)if(n.hasOwnProperty(s)&&s in ZE)return jp[e]=n[s];return e}var eA=Vf("animationend"),tA=Vf("animationiteration"),nA=Vf("animationstart"),sA=Vf("transitionend"),rA=new Map,g0="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 di(e,n){rA.set(e,n),sl(n,[e])}for(var wp=0;wp<g0.length;wp++){var yp=g0[wp],iF=yp.toLowerCase(),lF=yp[0].toUpperCase()+yp.slice(1);di(iF,"on"+lF)}di(eA,"onAnimationEnd");di(tA,"onAnimationIteration");di(nA,"onAnimationStart");di("dblclick","onDoubleClick");di("focusin","onFocus");di("focusout","onBlur");di(sA,"onTransitionEnd");no("onMouseEnter",["mouseout","mouseover"]);no("onMouseLeave",["mouseout","mouseover"]);no("onPointerEnter",["pointerout","pointerover"]);no("onPointerLeave",["pointerout","pointerover"]);sl("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));sl("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));sl("onBeforeInput",["compositionend","keypress","textInput","paste"]);sl("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));sl("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));sl("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var vc="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(" "),oF=new Set("cancel close invalid load scroll toggle".split(" ").concat(vc));function x0(e,n,s){var r=e.type||"unknown-event";e.currentTarget=s,iL(r,n,void 0,e),e.currentTarget=null}function aA(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;x0(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;x0(a,o,u),i=c}}}if(Th)throw e=ux,Th=!1,ux=null,e}function zt(e,n){var s=n[wx];s===void 0&&(s=n[wx]=new Set);var r=e+"__bubble";s.has(r)||(iA(n,e,2,!1),s.add(r))}function bp(e,n,s){var r=0;n&&(r|=4),iA(s,e,r,n)}var gd="_reactListening"+Math.random().toString(36).slice(2);function Zc(e){if(!e[gd]){e[gd]=!0,fE.forEach(function(s){s!=="selectionchange"&&(oF.has(s)||bp(s,!1,e),bp(s,!0,e))});var n=e.nodeType===9?e:e.ownerDocument;n===null||n[gd]||(n[gd]=!0,bp("selectionchange",!1,n))}}function iA(e,n,s,r){switch(WE(n)){case 1:var a=bL;break;case 4:a=kL;break;default:a=lw}s=a.bind(null,n,s,e),a=void 0,!cx||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 kp(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=Pi(o),l===null)return;if(c=l.tag,c===5||c===6){r=i=l;continue e}o=o.parentNode}}r=r.return}$E(function(){var u=i,h=sw(s),f=[];e:{var m=rA.get(e);if(m!==void 0){var p=cw,v=e;switch(e){case"keypress":if(sh(s)===0)break e;case"keydown":case"keyup":p=FL;break;case"focusin":v="focus",p=gp;break;case"focusout":v="blur",p=gp;break;case"beforeblur":case"afterblur":p=gp;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=a0;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":p=CL;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":p=UL;break;case eA:case tA:case nA:p=$L;break;case sA:p=WL;break;case"scroll":p=NL;break;case"wheel":p=KL;break;case"copy":case"cut":case"paste":p=IL;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":p=l0}var g=(n&4)!==0,k=!g&&e==="scroll",j=g?m!==null?m+"Capture":null:m;g=[];for(var x=u,w;x!==null;){w=x;var N=w.stateNode;if(w.tag===5&&N!==null&&(w=N,j!==null&&(N=Gc(x,j),N!=null&&g.push(eu(x,N,w)))),k)break;x=x.return}0<g.length&&(m=new p(m,v,null,s,h),f.push({event:m,listeners:g}))}}if(!(n&7)){e:{if(m=e==="mouseover"||e==="pointerover",p=e==="mouseout"||e==="pointerout",m&&s!==lx&&(v=s.relatedTarget||s.fromElement)&&(Pi(v)||v[xa]))break e;if((p||m)&&(m=h.window===h?h:(m=h.ownerDocument)?m.defaultView||m.parentWindow:window,p?(v=s.relatedTarget||s.toElement,p=u,v=v?Pi(v):null,v!==null&&(k=rl(v),v!==k||v.tag!==5&&v.tag!==6)&&(v=null)):(p=null,v=u),p!==v)){if(g=a0,N="onMouseLeave",j="onMouseEnter",x="mouse",(e==="pointerout"||e==="pointerover")&&(g=l0,N="onPointerLeave",j="onPointerEnter",x="pointer"),k=p==null?m:Ml(p),w=v==null?m:Ml(v),m=new g(N,x+"leave",p,s,h),m.target=k,m.relatedTarget=w,N=null,Pi(h)===u&&(g=new g(j,x+"enter",v,s,h),g.target=w,g.relatedTarget=k,N=g),k=N,p&&v)t:{for(g=p,j=v,x=0,w=g;w;w=xl(w))x++;for(w=0,N=j;N;N=xl(N))w++;for(;0<x-w;)g=xl(g),x--;for(;0<w-x;)j=xl(j),w--;for(;x--;){if(g===j||j!==null&&g===j.alternate)break t;g=xl(g),j=xl(j)}g=null}else g=null;p!==null&&v0(f,m,p,g,!1),v!==null&&k!==null&&v0(f,k,v,g,!0)}}e:{if(m=u?Ml(u):window,p=m.nodeName&&m.nodeName.toLowerCase(),p==="select"||p==="input"&&m.type==="file")var y=XL;else if(u0(m))if(qE)y=nF;else{y=eF;var b=ZL}else(p=m.nodeName)&&p.toLowerCase()==="input"&&(m.type==="checkbox"||m.type==="radio")&&(y=tF);if(y&&(y=y(e,u))){YE(f,y,s,h);break e}b&&b(e,m,u),e==="focusout"&&(b=m._wrapperState)&&b.controlled&&m.type==="number"&&nx(m,"number",m.value)}switch(b=u?Ml(u):window,e){case"focusin":(u0(b)||b.contentEditable==="true")&&(Rl=b,mx=u,$c=null);break;case"focusout":$c=mx=Rl=null;break;case"mousedown":px=!0;break;case"contextmenu":case"mouseup":case"dragend":px=!1,p0(f,s,h);break;case"selectionchange":if(aF)break;case"keydown":case"keyup":p0(f,s,h)}var S;if(dw)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 Il?VE(e,s)&&(C="onCompositionEnd"):e==="keydown"&&s.keyCode===229&&(C="onCompositionStart");C&&(KE&&s.locale!=="ko"&&(Il||C!=="onCompositionStart"?C==="onCompositionEnd"&&Il&&(S=HE()):(La=h,ow="value"in La?La.value:La.textContent,Il=!0)),b=Oh(u,C),0<b.length&&(C=new i0(C,e,null,s,h),f.push({event:C,listeners:b}),S?C.data=S:(S=GE(s),S!==null&&(C.data=S)))),(S=GL?YL(e,s):qL(e,s))&&(u=Oh(u,"onBeforeInput"),0<u.length&&(h=new i0("onBeforeInput","beforeinput",null,s,h),f.push({event:h,listeners:u}),h.data=S))}aA(f,n)})}function eu(e,n,s){return{instance:e,listener:n,currentTarget:s}}function Oh(e,n){for(var s=n+"Capture",r=[];e!==null;){var a=e,i=a.stateNode;a.tag===5&&i!==null&&(a=i,i=Gc(e,s),i!=null&&r.unshift(eu(e,i,a)),i=Gc(e,n),i!=null&&r.push(eu(e,i,a))),e=e.return}return r}function xl(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function v0(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=Gc(s,i),c!=null&&l.unshift(eu(s,c,o))):a||(c=Gc(s,i),c!=null&&l.push(eu(s,c,o)))),s=s.return}l.length!==0&&e.push({event:n,listeners:l})}var cF=/\r\n?/g,uF=/\u0000|\uFFFD/g;function j0(e){return(typeof e=="string"?e:""+e).replace(cF,`
38
+ `).replace(uF,"")}function xd(e,n,s){if(n=j0(n),j0(e)!==n&&s)throw Error(Ne(425))}function Dh(){}var gx=null,xx=null;function vx(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 jx=typeof setTimeout=="function"?setTimeout:void 0,dF=typeof clearTimeout=="function"?clearTimeout:void 0,w0=typeof Promise=="function"?Promise:void 0,hF=typeof queueMicrotask=="function"?queueMicrotask:typeof w0<"u"?function(e){return w0.resolve(null).then(e).catch(fF)}:jx;function fF(e){setTimeout(function(){throw e})}function Np(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),Qc(n);return}r--}else s!=="$"&&s!=="$?"&&s!=="$!"||r++;s=a}while(s);Qc(n)}function Ha(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 y0(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 Eo=Math.random().toString(36).slice(2),Dr="__reactFiber$"+Eo,tu="__reactProps$"+Eo,xa="__reactContainer$"+Eo,wx="__reactEvents$"+Eo,mF="__reactListeners$"+Eo,pF="__reactHandles$"+Eo;function Pi(e){var n=e[Dr];if(n)return n;for(var s=e.parentNode;s;){if(n=s[xa]||s[Dr]){if(s=n.alternate,n.child!==null||s!==null&&s.child!==null)for(e=y0(e);e!==null;){if(s=e[Dr])return s;e=y0(e)}return n}e=s,s=e.parentNode}return null}function Lu(e){return e=e[Dr]||e[xa],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function Ml(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(Ne(33))}function Gf(e){return e[tu]||null}var yx=[],Ol=-1;function hi(e){return{current:e}}function Ut(e){0>Ol||(e.current=yx[Ol],yx[Ol]=null,Ol--)}function Ot(e,n){Ol++,yx[Ol]=e.current,e.current=n}var ei={},qn=hi(ei),xs=hi(!1),Hi=ei;function so(e,n){var s=e.type.contextTypes;if(!s)return ei;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 vs(e){return e=e.childContextTypes,e!=null}function Lh(){Ut(xs),Ut(qn)}function b0(e,n,s){if(qn.current!==ei)throw Error(Ne(168));Ot(qn,n),Ot(xs,s)}function lA(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(Ne(108,ZD(e)||"Unknown",a));return Zt({},s,r)}function Fh(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||ei,Hi=qn.current,Ot(qn,e),Ot(xs,xs.current),!0}function k0(e,n,s){var r=e.stateNode;if(!r)throw Error(Ne(169));s?(e=lA(e,n,Hi),r.__reactInternalMemoizedMergedChildContext=e,Ut(xs),Ut(qn),Ot(qn,e)):Ut(xs),Ot(xs,s)}var ia=null,Yf=!1,Sp=!1;function oA(e){ia===null?ia=[e]:ia.push(e)}function gF(e){Yf=!0,oA(e)}function fi(){if(!Sp&&ia!==null){Sp=!0;var e=0,n=Nt;try{var s=ia;for(Nt=1;e<s.length;e++){var r=s[e];do r=r(!0);while(r!==null)}ia=null,Yf=!1}catch(a){throw ia!==null&&(ia=ia.slice(e+1)),PE(rw,fi),a}finally{Nt=n,Sp=!1}}return null}var Dl=[],Ll=0,_h=null,zh=0,Gs=[],Ys=0,Ki=null,ua=1,da="";function $i(e,n){Dl[Ll++]=zh,Dl[Ll++]=_h,_h=e,zh=n}function cA(e,n,s){Gs[Ys++]=ua,Gs[Ys++]=da,Gs[Ys++]=Ki,Ki=e;var r=ua;e=da;var a=32-hr(r)-1;r&=~(1<<a),s+=1;var i=32-hr(n)+a;if(30<i){var l=a-a%5;i=(r&(1<<l)-1).toString(32),r>>=l,a-=l,ua=1<<32-hr(n)+a|s<<a|r,da=i+e}else ua=1<<i|s<<a|r,da=e}function fw(e){e.return!==null&&($i(e,1),cA(e,1,0))}function mw(e){for(;e===_h;)_h=Dl[--Ll],Dl[Ll]=null,zh=Dl[--Ll],Dl[Ll]=null;for(;e===Ki;)Ki=Gs[--Ys],Gs[Ys]=null,da=Gs[--Ys],Gs[Ys]=null,ua=Gs[--Ys],Gs[Ys]=null}var Ts=null,As=null,Ht=!1,or=null;function uA(e,n){var s=Js(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 N0(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,Ts=e,As=Ha(n.firstChild),!0):!1;case 6:return n=e.pendingProps===""||n.nodeType!==3?null:n,n!==null?(e.stateNode=n,Ts=e,As=null,!0):!1;case 13:return n=n.nodeType!==8?null:n,n!==null?(s=Ki!==null?{id:ua,overflow:da}:null,e.memoizedState={dehydrated:n,treeContext:s,retryLane:1073741824},s=Js(18,null,null,0),s.stateNode=n,s.return=e,e.child=s,Ts=e,As=null,!0):!1;default:return!1}}function bx(e){return(e.mode&1)!==0&&(e.flags&128)===0}function kx(e){if(Ht){var n=As;if(n){var s=n;if(!N0(e,n)){if(bx(e))throw Error(Ne(418));n=Ha(s.nextSibling);var r=Ts;n&&N0(e,n)?uA(r,s):(e.flags=e.flags&-4097|2,Ht=!1,Ts=e)}}else{if(bx(e))throw Error(Ne(418));e.flags=e.flags&-4097|2,Ht=!1,Ts=e}}}function S0(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;Ts=e}function vd(e){if(e!==Ts)return!1;if(!Ht)return S0(e),Ht=!0,!1;var n;if((n=e.tag!==3)&&!(n=e.tag!==5)&&(n=e.type,n=n!=="head"&&n!=="body"&&!vx(e.type,e.memoizedProps)),n&&(n=As)){if(bx(e))throw dA(),Error(Ne(418));for(;n;)uA(e,n),n=Ha(n.nextSibling)}if(S0(e),e.tag===13){if(e=e.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(Ne(317));e:{for(e=e.nextSibling,n=0;e;){if(e.nodeType===8){var s=e.data;if(s==="/$"){if(n===0){As=Ha(e.nextSibling);break e}n--}else s!=="$"&&s!=="$!"&&s!=="$?"||n++}e=e.nextSibling}As=null}}else As=Ts?Ha(e.stateNode.nextSibling):null;return!0}function dA(){for(var e=As;e;)e=Ha(e.nextSibling)}function ro(){As=Ts=null,Ht=!1}function pw(e){or===null?or=[e]:or.push(e)}var xF=ka.ReactCurrentBatchConfig;function sc(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(Ne(309));var r=s.stateNode}if(!r)throw Error(Ne(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(Ne(284));if(!s._owner)throw Error(Ne(290,e))}return e}function jd(e,n){throw e=Object.prototype.toString.call(n),Error(Ne(31,e==="[object Object]"?"object with keys {"+Object.keys(n).join(", ")+"}":e))}function C0(e){var n=e._init;return n(e._payload)}function hA(e){function n(j,x){if(e){var w=j.deletions;w===null?(j.deletions=[x],j.flags|=16):w.push(x)}}function s(j,x){if(!e)return null;for(;x!==null;)n(j,x),x=x.sibling;return null}function r(j,x){for(j=new Map;x!==null;)x.key!==null?j.set(x.key,x):j.set(x.index,x),x=x.sibling;return j}function a(j,x){return j=Ya(j,x),j.index=0,j.sibling=null,j}function i(j,x,w){return j.index=w,e?(w=j.alternate,w!==null?(w=w.index,w<x?(j.flags|=2,x):w):(j.flags|=2,x)):(j.flags|=1048576,x)}function l(j){return e&&j.alternate===null&&(j.flags|=2),j}function o(j,x,w,N){return x===null||x.tag!==6?(x=Rp(w,j.mode,N),x.return=j,x):(x=a(x,w),x.return=j,x)}function c(j,x,w,N){var y=w.type;return y===Tl?h(j,x,w.props.children,N,w.key):x!==null&&(x.elementType===y||typeof y=="object"&&y!==null&&y.$$typeof===Ra&&C0(y)===x.type)?(N=a(x,w.props),N.ref=sc(j,x,w),N.return=j,N):(N=uh(w.type,w.key,w.props,null,j.mode,N),N.ref=sc(j,x,w),N.return=j,N)}function u(j,x,w,N){return x===null||x.tag!==4||x.stateNode.containerInfo!==w.containerInfo||x.stateNode.implementation!==w.implementation?(x=Pp(w,j.mode,N),x.return=j,x):(x=a(x,w.children||[]),x.return=j,x)}function h(j,x,w,N,y){return x===null||x.tag!==7?(x=zi(w,j.mode,N,y),x.return=j,x):(x=a(x,w),x.return=j,x)}function f(j,x,w){if(typeof x=="string"&&x!==""||typeof x=="number")return x=Rp(""+x,j.mode,w),x.return=j,x;if(typeof x=="object"&&x!==null){switch(x.$$typeof){case od:return w=uh(x.type,x.key,x.props,null,j.mode,w),w.ref=sc(j,null,x),w.return=j,w;case $l:return x=Pp(x,j.mode,w),x.return=j,x;case Ra:var N=x._init;return f(j,N(x._payload),w)}if(gc(x)||Xo(x))return x=zi(x,j.mode,w,null),x.return=j,x;jd(j,x)}return null}function m(j,x,w,N){var y=x!==null?x.key:null;if(typeof w=="string"&&w!==""||typeof w=="number")return y!==null?null:o(j,x,""+w,N);if(typeof w=="object"&&w!==null){switch(w.$$typeof){case od:return w.key===y?c(j,x,w,N):null;case $l:return w.key===y?u(j,x,w,N):null;case Ra:return y=w._init,m(j,x,y(w._payload),N)}if(gc(w)||Xo(w))return y!==null?null:h(j,x,w,N,null);jd(j,w)}return null}function p(j,x,w,N,y){if(typeof N=="string"&&N!==""||typeof N=="number")return j=j.get(w)||null,o(x,j,""+N,y);if(typeof N=="object"&&N!==null){switch(N.$$typeof){case od:return j=j.get(N.key===null?w:N.key)||null,c(x,j,N,y);case $l:return j=j.get(N.key===null?w:N.key)||null,u(x,j,N,y);case Ra:var b=N._init;return p(j,x,w,b(N._payload),y)}if(gc(N)||Xo(N))return j=j.get(w)||null,h(x,j,N,y,null);jd(x,N)}return null}function v(j,x,w,N){for(var y=null,b=null,S=x,C=x=0,A=null;S!==null&&C<w.length;C++){S.index>C?(A=S,S=null):A=S.sibling;var $=m(j,S,w[C],N);if($===null){S===null&&(S=A);break}e&&S&&$.alternate===null&&n(j,S),x=i($,x,C),b===null?y=$:b.sibling=$,b=$,S=A}if(C===w.length)return s(j,S),Ht&&$i(j,C),y;if(S===null){for(;C<w.length;C++)S=f(j,w[C],N),S!==null&&(x=i(S,x,C),b===null?y=S:b.sibling=S,b=S);return Ht&&$i(j,C),y}for(S=r(j,S);C<w.length;C++)A=p(S,j,C,w[C],N),A!==null&&(e&&A.alternate!==null&&S.delete(A.key===null?C:A.key),x=i(A,x,C),b===null?y=A:b.sibling=A,b=A);return e&&S.forEach(function(I){return n(j,I)}),Ht&&$i(j,C),y}function g(j,x,w,N){var y=Xo(w);if(typeof y!="function")throw Error(Ne(150));if(w=y.call(w),w==null)throw Error(Ne(151));for(var b=y=null,S=x,C=x=0,A=null,$=w.next();S!==null&&!$.done;C++,$=w.next()){S.index>C?(A=S,S=null):A=S.sibling;var I=m(j,S,$.value,N);if(I===null){S===null&&(S=A);break}e&&S&&I.alternate===null&&n(j,S),x=i(I,x,C),b===null?y=I:b.sibling=I,b=I,S=A}if($.done)return s(j,S),Ht&&$i(j,C),y;if(S===null){for(;!$.done;C++,$=w.next())$=f(j,$.value,N),$!==null&&(x=i($,x,C),b===null?y=$:b.sibling=$,b=$);return Ht&&$i(j,C),y}for(S=r(j,S);!$.done;C++,$=w.next())$=p(S,j,C,$.value,N),$!==null&&(e&&$.alternate!==null&&S.delete($.key===null?C:$.key),x=i($,x,C),b===null?y=$:b.sibling=$,b=$);return e&&S.forEach(function(P){return n(j,P)}),Ht&&$i(j,C),y}function k(j,x,w,N){if(typeof w=="object"&&w!==null&&w.type===Tl&&w.key===null&&(w=w.props.children),typeof w=="object"&&w!==null){switch(w.$$typeof){case od:e:{for(var y=w.key,b=x;b!==null;){if(b.key===y){if(y=w.type,y===Tl){if(b.tag===7){s(j,b.sibling),x=a(b,w.props.children),x.return=j,j=x;break e}}else if(b.elementType===y||typeof y=="object"&&y!==null&&y.$$typeof===Ra&&C0(y)===b.type){s(j,b.sibling),x=a(b,w.props),x.ref=sc(j,b,w),x.return=j,j=x;break e}s(j,b);break}else n(j,b);b=b.sibling}w.type===Tl?(x=zi(w.props.children,j.mode,N,w.key),x.return=j,j=x):(N=uh(w.type,w.key,w.props,null,j.mode,N),N.ref=sc(j,x,w),N.return=j,j=N)}return l(j);case $l:e:{for(b=w.key;x!==null;){if(x.key===b)if(x.tag===4&&x.stateNode.containerInfo===w.containerInfo&&x.stateNode.implementation===w.implementation){s(j,x.sibling),x=a(x,w.children||[]),x.return=j,j=x;break e}else{s(j,x);break}else n(j,x);x=x.sibling}x=Pp(w,j.mode,N),x.return=j,j=x}return l(j);case Ra:return b=w._init,k(j,x,b(w._payload),N)}if(gc(w))return v(j,x,w,N);if(Xo(w))return g(j,x,w,N);jd(j,w)}return typeof w=="string"&&w!==""||typeof w=="number"?(w=""+w,x!==null&&x.tag===6?(s(j,x.sibling),x=a(x,w),x.return=j,j=x):(s(j,x),x=Rp(w,j.mode,N),x.return=j,j=x),l(j)):s(j,x)}return k}var ao=hA(!0),fA=hA(!1),Uh=hi(null),Bh=null,Fl=null,gw=null;function xw(){gw=Fl=Bh=null}function vw(e){var n=Uh.current;Ut(Uh),e._currentValue=n}function Nx(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 Yl(e,n){Bh=e,gw=Fl=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&n&&(ps=!0),e.firstContext=null)}function er(e){var n=e._currentValue;if(gw!==e)if(e={context:e,memoizedValue:n,next:null},Fl===null){if(Bh===null)throw Error(Ne(308));Fl=e,Bh.dependencies={lanes:0,firstContext:e}}else Fl=Fl.next=e;return n}var Mi=null;function jw(e){Mi===null?Mi=[e]:Mi.push(e)}function mA(e,n,s,r){var a=n.interleaved;return a===null?(s.next=s,jw(n)):(s.next=a.next,a.next=s),n.interleaved=s,va(e,r)}function va(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 Pa=!1;function ww(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function pA(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 ha(e,n){return{eventTime:e,lane:n,tag:0,payload:null,callback:null,next:null}}function Ka(e,n,s){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,wt&2){var a=r.pending;return a===null?n.next=n:(n.next=a.next,a.next=n),r.pending=n,va(e,s)}return a=r.interleaved,a===null?(n.next=n,jw(r)):(n.next=a.next,a.next=n),r.interleaved=n,va(e,s)}function rh(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,aw(e,s)}}function E0(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 Wh(e,n,s,r){var a=e.updateQueue;Pa=!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 f=a.baseState;l=0,h=u=c=null,o=i;do{var m=o.lane,p=o.eventTime;if((r&m)===m){h!==null&&(h=h.next={eventTime:p,lane:0,tag:o.tag,payload:o.payload,callback:o.callback,next:null});e:{var v=e,g=o;switch(m=n,p=s,g.tag){case 1:if(v=g.payload,typeof v=="function"){f=v.call(p,f,m);break e}f=v;break e;case 3:v.flags=v.flags&-65537|128;case 0:if(v=g.payload,m=typeof v=="function"?v.call(p,f,m):v,m==null)break e;f=Zt({},f,m);break e;case 2:Pa=!0}}o.callback!==null&&o.lane!==0&&(e.flags|=64,m=a.effects,m===null?a.effects=[o]:m.push(o))}else p={eventTime:p,lane:m,tag:o.tag,payload:o.payload,callback:o.callback,next:null},h===null?(u=h=p,c=f):h=h.next=p,l|=m;if(o=o.next,o===null){if(o=a.shared.pending,o===null)break;m=o,o=m.next,m.next=null,a.lastBaseUpdate=m,a.shared.pending=null}}while(!0);if(h===null&&(c=f),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);Gi|=l,e.lanes=l,e.memoizedState=f}}function A0(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(Ne(191,a));a.call(r)}}}var Fu={},Wr=hi(Fu),nu=hi(Fu),su=hi(Fu);function Oi(e){if(e===Fu)throw Error(Ne(174));return e}function yw(e,n){switch(Ot(su,n),Ot(nu,e),Ot(Wr,Fu),e=n.nodeType,e){case 9:case 11:n=(n=n.documentElement)?n.namespaceURI:rx(null,"");break;default:e=e===8?n.parentNode:n,n=e.namespaceURI||null,e=e.tagName,n=rx(n,e)}Ut(Wr),Ot(Wr,n)}function io(){Ut(Wr),Ut(nu),Ut(su)}function gA(e){Oi(su.current);var n=Oi(Wr.current),s=rx(n,e.type);n!==s&&(Ot(nu,e),Ot(Wr,s))}function bw(e){nu.current===e&&(Ut(Wr),Ut(nu))}var qt=hi(0);function Hh(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 Cp=[];function kw(){for(var e=0;e<Cp.length;e++)Cp[e]._workInProgressVersionPrimary=null;Cp.length=0}var ah=ka.ReactCurrentDispatcher,Ep=ka.ReactCurrentBatchConfig,Vi=0,Qt=null,jn=null,Cn=null,Kh=!1,Tc=!1,ru=0,vF=0;function Hn(){throw Error(Ne(321))}function Nw(e,n){if(n===null)return!1;for(var s=0;s<n.length&&s<e.length;s++)if(!gr(e[s],n[s]))return!1;return!0}function Sw(e,n,s,r,a,i){if(Vi=i,Qt=n,n.memoizedState=null,n.updateQueue=null,n.lanes=0,ah.current=e===null||e.memoizedState===null?bF:kF,e=s(r,a),Tc){i=0;do{if(Tc=!1,ru=0,25<=i)throw Error(Ne(301));i+=1,Cn=jn=null,n.updateQueue=null,ah.current=NF,e=s(r,a)}while(Tc)}if(ah.current=Vh,n=jn!==null&&jn.next!==null,Vi=0,Cn=jn=Qt=null,Kh=!1,n)throw Error(Ne(300));return e}function Cw(){var e=ru!==0;return ru=0,e}function Mr(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return Cn===null?Qt.memoizedState=Cn=e:Cn=Cn.next=e,Cn}function tr(){if(jn===null){var e=Qt.alternate;e=e!==null?e.memoizedState:null}else e=jn.next;var n=Cn===null?Qt.memoizedState:Cn.next;if(n!==null)Cn=n,jn=e;else{if(e===null)throw Error(Ne(310));jn=e,e={memoizedState:jn.memoizedState,baseState:jn.baseState,baseQueue:jn.baseQueue,queue:jn.queue,next:null},Cn===null?Qt.memoizedState=Cn=e:Cn=Cn.next=e}return Cn}function au(e,n){return typeof n=="function"?n(e):n}function Ap(e){var n=tr(),s=n.queue;if(s===null)throw Error(Ne(311));s.lastRenderedReducer=e;var r=jn,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((Vi&h)===h)c!==null&&(c=c.next={lane:0,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null}),r=u.hasEagerState?u.eagerState:e(r,u.action);else{var f={lane:h,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null};c===null?(o=c=f,l=r):c=c.next=f,Qt.lanes|=h,Gi|=h}u=u.next}while(u!==null&&u!==i);c===null?l=r:c.next=o,gr(r,n.memoizedState)||(ps=!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,Qt.lanes|=i,Gi|=i,a=a.next;while(a!==e)}else a===null&&(s.lanes=0);return[n.memoizedState,s.dispatch]}function $p(e){var n=tr(),s=n.queue;if(s===null)throw Error(Ne(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);gr(i,n.memoizedState)||(ps=!0),n.memoizedState=i,n.baseQueue===null&&(n.baseState=i),s.lastRenderedState=i}return[i,r]}function xA(){}function vA(e,n){var s=Qt,r=tr(),a=n(),i=!gr(r.memoizedState,a);if(i&&(r.memoizedState=a,ps=!0),r=r.queue,Ew(yA.bind(null,s,r,e),[e]),r.getSnapshot!==n||i||Cn!==null&&Cn.memoizedState.tag&1){if(s.flags|=2048,iu(9,wA.bind(null,s,r,a,n),void 0,null),$n===null)throw Error(Ne(349));Vi&30||jA(s,n,a)}return a}function jA(e,n,s){e.flags|=16384,e={getSnapshot:n,value:s},n=Qt.updateQueue,n===null?(n={lastEffect:null,stores:null},Qt.updateQueue=n,n.stores=[e]):(s=n.stores,s===null?n.stores=[e]:s.push(e))}function wA(e,n,s,r){n.value=s,n.getSnapshot=r,bA(n)&&kA(e)}function yA(e,n,s){return s(function(){bA(n)&&kA(e)})}function bA(e){var n=e.getSnapshot;e=e.value;try{var s=n();return!gr(e,s)}catch{return!0}}function kA(e){var n=va(e,1);n!==null&&fr(n,e,1,-1)}function $0(e){var n=Mr();return typeof e=="function"&&(e=e()),n.memoizedState=n.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:au,lastRenderedState:e},n.queue=e,e=e.dispatch=yF.bind(null,Qt,e),[n.memoizedState,e]}function iu(e,n,s,r){return e={tag:e,create:n,destroy:s,deps:r,next:null},n=Qt.updateQueue,n===null?(n={lastEffect:null,stores:null},Qt.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 NA(){return tr().memoizedState}function ih(e,n,s,r){var a=Mr();Qt.flags|=e,a.memoizedState=iu(1|n,s,void 0,r===void 0?null:r)}function qf(e,n,s,r){var a=tr();r=r===void 0?null:r;var i=void 0;if(jn!==null){var l=jn.memoizedState;if(i=l.destroy,r!==null&&Nw(r,l.deps)){a.memoizedState=iu(n,s,i,r);return}}Qt.flags|=e,a.memoizedState=iu(1|n,s,i,r)}function T0(e,n){return ih(8390656,8,e,n)}function Ew(e,n){return qf(2048,8,e,n)}function SA(e,n){return qf(4,2,e,n)}function CA(e,n){return qf(4,4,e,n)}function EA(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 AA(e,n,s){return s=s!=null?s.concat([e]):null,qf(4,4,EA.bind(null,n,e),s)}function Aw(){}function $A(e,n){var s=tr();n=n===void 0?null:n;var r=s.memoizedState;return r!==null&&n!==null&&Nw(n,r[1])?r[0]:(s.memoizedState=[e,n],e)}function TA(e,n){var s=tr();n=n===void 0?null:n;var r=s.memoizedState;return r!==null&&n!==null&&Nw(n,r[1])?r[0]:(e=e(),s.memoizedState=[e,n],e)}function IA(e,n,s){return Vi&21?(gr(s,n)||(s=DE(),Qt.lanes|=s,Gi|=s,e.baseState=!0),n):(e.baseState&&(e.baseState=!1,ps=!0),e.memoizedState=s)}function jF(e,n){var s=Nt;Nt=s!==0&&4>s?s:4,e(!0);var r=Ep.transition;Ep.transition={};try{e(!1),n()}finally{Nt=s,Ep.transition=r}}function RA(){return tr().memoizedState}function wF(e,n,s){var r=Ga(e);if(s={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null},PA(e))MA(n,s);else if(s=mA(e,n,s,r),s!==null){var a=as();fr(s,e,r,a),OA(s,n,r)}}function yF(e,n,s){var r=Ga(e),a={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null};if(PA(e))MA(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,gr(o,l)){var c=n.interleaved;c===null?(a.next=a,jw(n)):(a.next=c.next,c.next=a),n.interleaved=a;return}}catch{}finally{}s=mA(e,n,a,r),s!==null&&(a=as(),fr(s,e,r,a),OA(s,n,r))}}function PA(e){var n=e.alternate;return e===Qt||n!==null&&n===Qt}function MA(e,n){Tc=Kh=!0;var s=e.pending;s===null?n.next=n:(n.next=s.next,s.next=n),e.pending=n}function OA(e,n,s){if(s&4194240){var r=n.lanes;r&=e.pendingLanes,s|=r,n.lanes=s,aw(e,s)}}var Vh={readContext:er,useCallback:Hn,useContext:Hn,useEffect:Hn,useImperativeHandle:Hn,useInsertionEffect:Hn,useLayoutEffect:Hn,useMemo:Hn,useReducer:Hn,useRef:Hn,useState:Hn,useDebugValue:Hn,useDeferredValue:Hn,useTransition:Hn,useMutableSource:Hn,useSyncExternalStore:Hn,useId:Hn,unstable_isNewReconciler:!1},bF={readContext:er,useCallback:function(e,n){return Mr().memoizedState=[e,n===void 0?null:n],e},useContext:er,useEffect:T0,useImperativeHandle:function(e,n,s){return s=s!=null?s.concat([e]):null,ih(4194308,4,EA.bind(null,n,e),s)},useLayoutEffect:function(e,n){return ih(4194308,4,e,n)},useInsertionEffect:function(e,n){return ih(4,2,e,n)},useMemo:function(e,n){var s=Mr();return n=n===void 0?null:n,e=e(),s.memoizedState=[e,n],e},useReducer:function(e,n,s){var r=Mr();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=wF.bind(null,Qt,e),[r.memoizedState,e]},useRef:function(e){var n=Mr();return e={current:e},n.memoizedState=e},useState:$0,useDebugValue:Aw,useDeferredValue:function(e){return Mr().memoizedState=e},useTransition:function(){var e=$0(!1),n=e[0];return e=jF.bind(null,e[1]),Mr().memoizedState=e,[n,e]},useMutableSource:function(){},useSyncExternalStore:function(e,n,s){var r=Qt,a=Mr();if(Ht){if(s===void 0)throw Error(Ne(407));s=s()}else{if(s=n(),$n===null)throw Error(Ne(349));Vi&30||jA(r,n,s)}a.memoizedState=s;var i={value:s,getSnapshot:n};return a.queue=i,T0(yA.bind(null,r,i,e),[e]),r.flags|=2048,iu(9,wA.bind(null,r,i,s,n),void 0,null),s},useId:function(){var e=Mr(),n=$n.identifierPrefix;if(Ht){var s=da,r=ua;s=(r&~(1<<32-hr(r)-1)).toString(32)+s,n=":"+n+"R"+s,s=ru++,0<s&&(n+="H"+s.toString(32)),n+=":"}else s=vF++,n=":"+n+"r"+s.toString(32)+":";return e.memoizedState=n},unstable_isNewReconciler:!1},kF={readContext:er,useCallback:$A,useContext:er,useEffect:Ew,useImperativeHandle:AA,useInsertionEffect:SA,useLayoutEffect:CA,useMemo:TA,useReducer:Ap,useRef:NA,useState:function(){return Ap(au)},useDebugValue:Aw,useDeferredValue:function(e){var n=tr();return IA(n,jn.memoizedState,e)},useTransition:function(){var e=Ap(au)[0],n=tr().memoizedState;return[e,n]},useMutableSource:xA,useSyncExternalStore:vA,useId:RA,unstable_isNewReconciler:!1},NF={readContext:er,useCallback:$A,useContext:er,useEffect:Ew,useImperativeHandle:AA,useInsertionEffect:SA,useLayoutEffect:CA,useMemo:TA,useReducer:$p,useRef:NA,useState:function(){return $p(au)},useDebugValue:Aw,useDeferredValue:function(e){var n=tr();return jn===null?n.memoizedState=e:IA(n,jn.memoizedState,e)},useTransition:function(){var e=$p(au)[0],n=tr().memoizedState;return[e,n]},useMutableSource:xA,useSyncExternalStore:vA,useId:RA,unstable_isNewReconciler:!1};function ir(e,n){if(e&&e.defaultProps){n=Zt({},n),e=e.defaultProps;for(var s in e)n[s]===void 0&&(n[s]=e[s]);return n}return n}function Sx(e,n,s,r){n=e.memoizedState,s=s(r,n),s=s==null?n:Zt({},n,s),e.memoizedState=s,e.lanes===0&&(e.updateQueue.baseState=s)}var Qf={isMounted:function(e){return(e=e._reactInternals)?rl(e)===e:!1},enqueueSetState:function(e,n,s){e=e._reactInternals;var r=as(),a=Ga(e),i=ha(r,a);i.payload=n,s!=null&&(i.callback=s),n=Ka(e,i,a),n!==null&&(fr(n,e,a,r),rh(n,e,a))},enqueueReplaceState:function(e,n,s){e=e._reactInternals;var r=as(),a=Ga(e),i=ha(r,a);i.tag=1,i.payload=n,s!=null&&(i.callback=s),n=Ka(e,i,a),n!==null&&(fr(n,e,a,r),rh(n,e,a))},enqueueForceUpdate:function(e,n){e=e._reactInternals;var s=as(),r=Ga(e),a=ha(s,r);a.tag=2,n!=null&&(a.callback=n),n=Ka(e,a,r),n!==null&&(fr(n,e,r,s),rh(n,e,r))}};function I0(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?!Xc(s,r)||!Xc(a,i):!0}function DA(e,n,s){var r=!1,a=ei,i=n.contextType;return typeof i=="object"&&i!==null?i=er(i):(a=vs(n)?Hi:qn.current,r=n.contextTypes,i=(r=r!=null)?so(e,a):ei),n=new n(s,i),e.memoizedState=n.state!==null&&n.state!==void 0?n.state:null,n.updater=Qf,e.stateNode=n,n._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=a,e.__reactInternalMemoizedMaskedChildContext=i),n}function R0(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&&Qf.enqueueReplaceState(n,n.state,null)}function Cx(e,n,s,r){var a=e.stateNode;a.props=s,a.state=e.memoizedState,a.refs={},ww(e);var i=n.contextType;typeof i=="object"&&i!==null?a.context=er(i):(i=vs(n)?Hi:qn.current,a.context=so(e,i)),a.state=e.memoizedState,i=n.getDerivedStateFromProps,typeof i=="function"&&(Sx(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&&Qf.enqueueReplaceState(a,a.state,null),Wh(e,s,a,r),a.state=e.memoizedState),typeof a.componentDidMount=="function"&&(e.flags|=4194308)}function lo(e,n){try{var s="",r=n;do s+=XD(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 Tp(e,n,s){return{value:e,source:null,stack:s??null,digest:n??null}}function Ex(e,n){try{console.error(n.value)}catch(s){setTimeout(function(){throw s})}}var SF=typeof WeakMap=="function"?WeakMap:Map;function LA(e,n,s){s=ha(-1,s),s.tag=3,s.payload={element:null};var r=n.value;return s.callback=function(){Yh||(Yh=!0,Lx=r),Ex(e,n)},s}function FA(e,n,s){s=ha(-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(){Ex(e,n)}}var i=e.stateNode;return i!==null&&typeof i.componentDidCatch=="function"&&(s.callback=function(){Ex(e,n),typeof r!="function"&&(Va===null?Va=new Set([this]):Va.add(this));var l=n.stack;this.componentDidCatch(n.value,{componentStack:l!==null?l:""})}),s}function P0(e,n,s){var r=e.pingCache;if(r===null){r=e.pingCache=new SF;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=_F.bind(null,e,n,s),n.then(e,e))}function M0(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 O0(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=ha(-1,1),n.tag=2,Ka(s,n,1))),s.lanes|=1),e)}var CF=ka.ReactCurrentOwner,ps=!1;function ns(e,n,s,r){n.child=e===null?fA(n,null,s,r):ao(n,e.child,s,r)}function D0(e,n,s,r,a){s=s.render;var i=n.ref;return Yl(n,a),r=Sw(e,n,s,r,i,a),s=Cw(),e!==null&&!ps?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~a,ja(e,n,a)):(Ht&&s&&fw(n),n.flags|=1,ns(e,n,r,a),n.child)}function L0(e,n,s,r,a){if(e===null){var i=s.type;return typeof i=="function"&&!Dw(i)&&i.defaultProps===void 0&&s.compare===null&&s.defaultProps===void 0?(n.tag=15,n.type=i,_A(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:Xc,s(l,r)&&e.ref===n.ref)return ja(e,n,a)}return n.flags|=1,e=Ya(i,r),e.ref=n.ref,e.return=n,n.child=e}function _A(e,n,s,r,a){if(e!==null){var i=e.memoizedProps;if(Xc(i,r)&&e.ref===n.ref)if(ps=!1,n.pendingProps=r=i,(e.lanes&a)!==0)e.flags&131072&&(ps=!0);else return n.lanes=e.lanes,ja(e,n,a)}return Ax(e,n,s,r,a)}function zA(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},Ot(zl,Ss),Ss|=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,Ot(zl,Ss),Ss|=e,null;n.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=i!==null?i.baseLanes:s,Ot(zl,Ss),Ss|=r}else i!==null?(r=i.baseLanes|s,n.memoizedState=null):r=s,Ot(zl,Ss),Ss|=r;return ns(e,n,a,s),n.child}function UA(e,n){var s=n.ref;(e===null&&s!==null||e!==null&&e.ref!==s)&&(n.flags|=512,n.flags|=2097152)}function Ax(e,n,s,r,a){var i=vs(s)?Hi:qn.current;return i=so(n,i),Yl(n,a),s=Sw(e,n,s,r,i,a),r=Cw(),e!==null&&!ps?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~a,ja(e,n,a)):(Ht&&r&&fw(n),n.flags|=1,ns(e,n,s,a),n.child)}function F0(e,n,s,r,a){if(vs(s)){var i=!0;Fh(n)}else i=!1;if(Yl(n,a),n.stateNode===null)lh(e,n),DA(n,s,r),Cx(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=er(u):(u=vs(s)?Hi:qn.current,u=so(n,u));var h=s.getDerivedStateFromProps,f=typeof h=="function"||typeof l.getSnapshotBeforeUpdate=="function";f||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==r||c!==u)&&R0(n,l,r,u),Pa=!1;var m=n.memoizedState;l.state=m,Wh(n,r,l,a),c=n.memoizedState,o!==r||m!==c||xs.current||Pa?(typeof h=="function"&&(Sx(n,s,h,r),c=n.memoizedState),(o=Pa||I0(n,s,o,r,m,c,u))?(f||typeof l.UNSAFE_componentWillMount!="function"&&typeof l.componentWillMount!="function"||(typeof l.componentWillMount=="function"&&l.componentWillMount(),typeof l.UNSAFE_componentWillMount=="function"&&l.UNSAFE_componentWillMount()),typeof l.componentDidMount=="function"&&(n.flags|=4194308)):(typeof l.componentDidMount=="function"&&(n.flags|=4194308),n.memoizedProps=r,n.memoizedState=c),l.props=r,l.state=c,l.context=u,r=o):(typeof l.componentDidMount=="function"&&(n.flags|=4194308),r=!1)}else{l=n.stateNode,pA(e,n),o=n.memoizedProps,u=n.type===n.elementType?o:ir(n.type,o),l.props=u,f=n.pendingProps,m=l.context,c=s.contextType,typeof c=="object"&&c!==null?c=er(c):(c=vs(s)?Hi:qn.current,c=so(n,c));var p=s.getDerivedStateFromProps;(h=typeof p=="function"||typeof l.getSnapshotBeforeUpdate=="function")||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==f||m!==c)&&R0(n,l,r,c),Pa=!1,m=n.memoizedState,l.state=m,Wh(n,r,l,a);var v=n.memoizedState;o!==f||m!==v||xs.current||Pa?(typeof p=="function"&&(Sx(n,s,p,r),v=n.memoizedState),(u=Pa||I0(n,s,u,r,m,v,c)||!1)?(h||typeof l.UNSAFE_componentWillUpdate!="function"&&typeof l.componentWillUpdate!="function"||(typeof l.componentWillUpdate=="function"&&l.componentWillUpdate(r,v,c),typeof l.UNSAFE_componentWillUpdate=="function"&&l.UNSAFE_componentWillUpdate(r,v,c)),typeof l.componentDidUpdate=="function"&&(n.flags|=4),typeof l.getSnapshotBeforeUpdate=="function"&&(n.flags|=1024)):(typeof l.componentDidUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(n.flags|=4),typeof l.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(n.flags|=1024),n.memoizedProps=r,n.memoizedState=v),l.props=r,l.state=v,l.context=c,r=u):(typeof l.componentDidUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(n.flags|=4),typeof l.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(n.flags|=1024),r=!1)}return $x(e,n,s,r,i,a)}function $x(e,n,s,r,a,i){UA(e,n);var l=(n.flags&128)!==0;if(!r&&!l)return a&&k0(n,s,!1),ja(e,n,i);r=n.stateNode,CF.current=n;var o=l&&typeof s.getDerivedStateFromError!="function"?null:r.render();return n.flags|=1,e!==null&&l?(n.child=ao(n,e.child,null,i),n.child=ao(n,null,o,i)):ns(e,n,o,i),n.memoizedState=r.state,a&&k0(n,s,!0),n.child}function BA(e){var n=e.stateNode;n.pendingContext?b0(e,n.pendingContext,n.pendingContext!==n.context):n.context&&b0(e,n.context,!1),yw(e,n.containerInfo)}function _0(e,n,s,r,a){return ro(),pw(a),n.flags|=256,ns(e,n,s,r),n.child}var Tx={dehydrated:null,treeContext:null,retryLane:0};function Ix(e){return{baseLanes:e,cachePool:null,transitions:null}}function WA(e,n,s){var r=n.pendingProps,a=qt.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),Ot(qt,a&1),e===null)return kx(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=Zf(l,r,0,null),e=zi(e,r,s,null),i.return=n,e.return=n,i.sibling=e,n.child=i,n.child.memoizedState=Ix(s),n.memoizedState=Tx,e):$w(n,l));if(a=e.memoizedState,a!==null&&(o=a.dehydrated,o!==null))return EF(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=Ya(a,c),r.subtreeFlags=a.subtreeFlags&14680064),o!==null?i=Ya(o,i):(i=zi(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?Ix(s):{baseLanes:l.baseLanes|s,cachePool:null,transitions:l.transitions},i.memoizedState=l,i.childLanes=e.childLanes&~s,n.memoizedState=Tx,r}return i=e.child,e=i.sibling,r=Ya(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 $w(e,n){return n=Zf({mode:"visible",children:n},e.mode,0,null),n.return=e,e.child=n}function wd(e,n,s,r){return r!==null&&pw(r),ao(n,e.child,null,s),e=$w(n,n.pendingProps.children),e.flags|=2,n.memoizedState=null,e}function EF(e,n,s,r,a,i,l){if(s)return n.flags&256?(n.flags&=-257,r=Tp(Error(Ne(422))),wd(e,n,l,r)):n.memoizedState!==null?(n.child=e.child,n.flags|=128,null):(i=r.fallback,a=n.mode,r=Zf({mode:"visible",children:r.children},a,0,null),i=zi(i,a,l,null),i.flags|=2,r.return=n,i.return=n,r.sibling=i,n.child=r,n.mode&1&&ao(n,e.child,null,l),n.child.memoizedState=Ix(l),n.memoizedState=Tx,i);if(!(n.mode&1))return wd(e,n,l,null);if(a.data==="$!"){if(r=a.nextSibling&&a.nextSibling.dataset,r)var o=r.dgst;return r=o,i=Error(Ne(419)),r=Tp(i,r,void 0),wd(e,n,l,r)}if(o=(l&e.childLanes)!==0,ps||o){if(r=$n,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,va(e,a),fr(r,e,a,-1))}return Ow(),r=Tp(Error(Ne(421))),wd(e,n,l,r)}return a.data==="$?"?(n.flags|=128,n.child=e.child,n=zF.bind(null,e),a._reactRetry=n,null):(e=i.treeContext,As=Ha(a.nextSibling),Ts=n,Ht=!0,or=null,e!==null&&(Gs[Ys++]=ua,Gs[Ys++]=da,Gs[Ys++]=Ki,ua=e.id,da=e.overflow,Ki=n),n=$w(n,r.children),n.flags|=4096,n)}function z0(e,n,s){e.lanes|=n;var r=e.alternate;r!==null&&(r.lanes|=n),Nx(e.return,n,s)}function Ip(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 HA(e,n,s){var r=n.pendingProps,a=r.revealOrder,i=r.tail;if(ns(e,n,r.children,s),r=qt.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&&z0(e,s,n);else if(e.tag===19)z0(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(Ot(qt,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&&Hh(e)===null&&(a=s),s=s.sibling;s=a,s===null?(a=n.child,n.child=null):(a=s.sibling,s.sibling=null),Ip(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&&Hh(e)===null){n.child=a;break}e=a.sibling,a.sibling=s,s=a,a=e}Ip(n,!0,s,null,i);break;case"together":Ip(n,!1,null,null,void 0);break;default:n.memoizedState=null}return n.child}function lh(e,n){!(n.mode&1)&&e!==null&&(e.alternate=null,n.alternate=null,n.flags|=2)}function ja(e,n,s){if(e!==null&&(n.dependencies=e.dependencies),Gi|=n.lanes,!(s&n.childLanes))return null;if(e!==null&&n.child!==e.child)throw Error(Ne(153));if(n.child!==null){for(e=n.child,s=Ya(e,e.pendingProps),n.child=s,s.return=n;e.sibling!==null;)e=e.sibling,s=s.sibling=Ya(e,e.pendingProps),s.return=n;s.sibling=null}return n.child}function AF(e,n,s){switch(n.tag){case 3:BA(n),ro();break;case 5:gA(n);break;case 1:vs(n.type)&&Fh(n);break;case 4:yw(n,n.stateNode.containerInfo);break;case 10:var r=n.type._context,a=n.memoizedProps.value;Ot(Uh,r._currentValue),r._currentValue=a;break;case 13:if(r=n.memoizedState,r!==null)return r.dehydrated!==null?(Ot(qt,qt.current&1),n.flags|=128,null):s&n.child.childLanes?WA(e,n,s):(Ot(qt,qt.current&1),e=ja(e,n,s),e!==null?e.sibling:null);Ot(qt,qt.current&1);break;case 19:if(r=(s&n.childLanes)!==0,e.flags&128){if(r)return HA(e,n,s);n.flags|=128}if(a=n.memoizedState,a!==null&&(a.rendering=null,a.tail=null,a.lastEffect=null),Ot(qt,qt.current),r)break;return null;case 22:case 23:return n.lanes=0,zA(e,n,s)}return ja(e,n,s)}var KA,Rx,VA,GA;KA=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}};Rx=function(){};VA=function(e,n,s,r){var a=e.memoizedProps;if(a!==r){e=n.stateNode,Oi(Wr.current);var i=null;switch(s){case"input":a=ex(e,a),r=ex(e,r),i=[];break;case"select":a=Zt({},a,{value:void 0}),r=Zt({},r,{value:void 0}),i=[];break;case"textarea":a=sx(e,a),r=sx(e,r),i=[];break;default:typeof a.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=Dh)}ax(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"&&(Kc.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"&&(Kc.hasOwnProperty(u)?(c!=null&&u==="onScroll"&&zt("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)}};GA=function(e,n,s,r){s!==r&&(n.flags|=4)};function rc(e,n){if(!Ht)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 Kn(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 $F(e,n,s){var r=n.pendingProps;switch(mw(n),n.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Kn(n),null;case 1:return vs(n.type)&&Lh(),Kn(n),null;case 3:return r=n.stateNode,io(),Ut(xs),Ut(qn),kw(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(vd(n)?n.flags|=4:e===null||e.memoizedState.isDehydrated&&!(n.flags&256)||(n.flags|=1024,or!==null&&(zx(or),or=null))),Rx(e,n),Kn(n),null;case 5:bw(n);var a=Oi(su.current);if(s=n.type,e!==null&&n.stateNode!=null)VA(e,n,s,r,a),e.ref!==n.ref&&(n.flags|=512,n.flags|=2097152);else{if(!r){if(n.stateNode===null)throw Error(Ne(166));return Kn(n),null}if(e=Oi(Wr.current),vd(n)){r=n.stateNode,s=n.type;var i=n.memoizedProps;switch(r[Dr]=n,r[tu]=i,e=(n.mode&1)!==0,s){case"dialog":zt("cancel",r),zt("close",r);break;case"iframe":case"object":case"embed":zt("load",r);break;case"video":case"audio":for(a=0;a<vc.length;a++)zt(vc[a],r);break;case"source":zt("error",r);break;case"img":case"image":case"link":zt("error",r),zt("load",r);break;case"details":zt("toggle",r);break;case"input":qk(r,i),zt("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!i.multiple},zt("invalid",r);break;case"textarea":Jk(r,i),zt("invalid",r)}ax(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&&xd(r.textContent,o,e),a=["children",o]):typeof o=="number"&&r.textContent!==""+o&&(i.suppressHydrationWarning!==!0&&xd(r.textContent,o,e),a=["children",""+o]):Kc.hasOwnProperty(l)&&o!=null&&l==="onScroll"&&zt("scroll",r)}switch(s){case"input":cd(r),Qk(r,i,!0);break;case"textarea":cd(r),Xk(r);break;case"select":case"option":break;default:typeof i.onClick=="function"&&(r.onclick=Dh)}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=yE(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[Dr]=n,e[tu]=r,KA(e,n,!1,!1),n.stateNode=e;e:{switch(l=ix(s,r),s){case"dialog":zt("cancel",e),zt("close",e),a=r;break;case"iframe":case"object":case"embed":zt("load",e),a=r;break;case"video":case"audio":for(a=0;a<vc.length;a++)zt(vc[a],e);a=r;break;case"source":zt("error",e),a=r;break;case"img":case"image":case"link":zt("error",e),zt("load",e),a=r;break;case"details":zt("toggle",e),a=r;break;case"input":qk(e,r),a=ex(e,r),zt("invalid",e);break;case"option":a=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},a=Zt({},r,{value:void 0}),zt("invalid",e);break;case"textarea":Jk(e,r),a=sx(e,r),zt("invalid",e);break;default:a=r}ax(s,a),o=a;for(i in o)if(o.hasOwnProperty(i)){var c=o[i];i==="style"?NE(e,c):i==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,c!=null&&bE(e,c)):i==="children"?typeof c=="string"?(s!=="textarea"||c!=="")&&Vc(e,c):typeof c=="number"&&Vc(e,""+c):i!=="suppressContentEditableWarning"&&i!=="suppressHydrationWarning"&&i!=="autoFocus"&&(Kc.hasOwnProperty(i)?c!=null&&i==="onScroll"&&zt("scroll",e):c!=null&&Zj(e,i,c,l))}switch(s){case"input":cd(e),Qk(e,r,!1);break;case"textarea":cd(e),Xk(e);break;case"option":r.value!=null&&e.setAttribute("value",""+Za(r.value));break;case"select":e.multiple=!!r.multiple,i=r.value,i!=null?Hl(e,!!r.multiple,i,!1):r.defaultValue!=null&&Hl(e,!!r.multiple,r.defaultValue,!0);break;default:typeof a.onClick=="function"&&(e.onclick=Dh)}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 Kn(n),null;case 6:if(e&&n.stateNode!=null)GA(e,n,e.memoizedProps,r);else{if(typeof r!="string"&&n.stateNode===null)throw Error(Ne(166));if(s=Oi(su.current),Oi(Wr.current),vd(n)){if(r=n.stateNode,s=n.memoizedProps,r[Dr]=n,(i=r.nodeValue!==s)&&(e=Ts,e!==null))switch(e.tag){case 3:xd(r.nodeValue,s,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&xd(r.nodeValue,s,(e.mode&1)!==0)}i&&(n.flags|=4)}else r=(s.nodeType===9?s:s.ownerDocument).createTextNode(r),r[Dr]=n,n.stateNode=r}return Kn(n),null;case 13:if(Ut(qt),r=n.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(Ht&&As!==null&&n.mode&1&&!(n.flags&128))dA(),ro(),n.flags|=98560,i=!1;else if(i=vd(n),r!==null&&r.dehydrated!==null){if(e===null){if(!i)throw Error(Ne(318));if(i=n.memoizedState,i=i!==null?i.dehydrated:null,!i)throw Error(Ne(317));i[Dr]=n}else ro(),!(n.flags&128)&&(n.memoizedState=null),n.flags|=4;Kn(n),i=!1}else or!==null&&(zx(or),or=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||qt.current&1?yn===0&&(yn=3):Ow())),n.updateQueue!==null&&(n.flags|=4),Kn(n),null);case 4:return io(),Rx(e,n),e===null&&Zc(n.stateNode.containerInfo),Kn(n),null;case 10:return vw(n.type._context),Kn(n),null;case 17:return vs(n.type)&&Lh(),Kn(n),null;case 19:if(Ut(qt),i=n.memoizedState,i===null)return Kn(n),null;if(r=(n.flags&128)!==0,l=i.rendering,l===null)if(r)rc(i,!1);else{if(yn!==0||e!==null&&e.flags&128)for(e=n.child;e!==null;){if(l=Hh(e),l!==null){for(n.flags|=128,rc(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 Ot(qt,qt.current&1|2),n.child}e=e.sibling}i.tail!==null&&rn()>oo&&(n.flags|=128,r=!0,rc(i,!1),n.lanes=4194304)}else{if(!r)if(e=Hh(l),e!==null){if(n.flags|=128,r=!0,s=e.updateQueue,s!==null&&(n.updateQueue=s,n.flags|=4),rc(i,!0),i.tail===null&&i.tailMode==="hidden"&&!l.alternate&&!Ht)return Kn(n),null}else 2*rn()-i.renderingStartTime>oo&&s!==1073741824&&(n.flags|=128,r=!0,rc(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=rn(),n.sibling=null,s=qt.current,Ot(qt,r?s&1|2:s&1),n):(Kn(n),null);case 22:case 23:return Mw(),r=n.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(n.flags|=8192),r&&n.mode&1?Ss&1073741824&&(Kn(n),n.subtreeFlags&6&&(n.flags|=8192)):Kn(n),null;case 24:return null;case 25:return null}throw Error(Ne(156,n.tag))}function TF(e,n){switch(mw(n),n.tag){case 1:return vs(n.type)&&Lh(),e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 3:return io(),Ut(xs),Ut(qn),kw(),e=n.flags,e&65536&&!(e&128)?(n.flags=e&-65537|128,n):null;case 5:return bw(n),null;case 13:if(Ut(qt),e=n.memoizedState,e!==null&&e.dehydrated!==null){if(n.alternate===null)throw Error(Ne(340));ro()}return e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 19:return Ut(qt),null;case 4:return io(),null;case 10:return vw(n.type._context),null;case 22:case 23:return Mw(),null;case 24:return null;default:return null}}var yd=!1,Gn=!1,IF=typeof WeakSet=="function"?WeakSet:Set,Le=null;function _l(e,n){var s=e.ref;if(s!==null)if(typeof s=="function")try{s(null)}catch(r){tn(e,n,r)}else s.current=null}function Px(e,n,s){try{s()}catch(r){tn(e,n,r)}}var U0=!1;function RF(e,n){if(gx=Ph,e=XE(),hw(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,f=e,m=null;t:for(;;){for(var p;f!==s||a!==0&&f.nodeType!==3||(o=l+a),f!==i||r!==0&&f.nodeType!==3||(c=l+r),f.nodeType===3&&(l+=f.nodeValue.length),(p=f.firstChild)!==null;)m=f,f=p;for(;;){if(f===e)break t;if(m===s&&++u===a&&(o=l),m===i&&++h===r&&(c=l),(p=f.nextSibling)!==null)break;f=m,m=f.parentNode}f=p}s=o===-1||c===-1?null:{start:o,end:c}}else s=null}s=s||{start:0,end:0}}else s=null;for(xx={focusedElem:e,selectionRange:s},Ph=!1,Le=n;Le!==null;)if(n=Le,e=n.child,(n.subtreeFlags&1028)!==0&&e!==null)e.return=n,Le=e;else for(;Le!==null;){n=Le;try{var v=n.alternate;if(n.flags&1024)switch(n.tag){case 0:case 11:case 15:break;case 1:if(v!==null){var g=v.memoizedProps,k=v.memoizedState,j=n.stateNode,x=j.getSnapshotBeforeUpdate(n.elementType===n.type?g:ir(n.type,g),k);j.__reactInternalSnapshotBeforeUpdate=x}break;case 3:var w=n.stateNode.containerInfo;w.nodeType===1?w.textContent="":w.nodeType===9&&w.documentElement&&w.removeChild(w.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(Ne(163))}}catch(N){tn(n,n.return,N)}if(e=n.sibling,e!==null){e.return=n.return,Le=e;break}Le=n.return}return v=U0,U0=!1,v}function Ic(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&&Px(n,s,i)}a=a.next}while(a!==r)}}function Jf(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 Mx(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 YA(e){var n=e.alternate;n!==null&&(e.alternate=null,YA(n)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(n=e.stateNode,n!==null&&(delete n[Dr],delete n[tu],delete n[wx],delete n[mF],delete n[pF])),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 qA(e){return e.tag===5||e.tag===3||e.tag===4}function B0(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||qA(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 Ox(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=Dh));else if(r!==4&&(e=e.child,e!==null))for(Ox(e,n,s),e=e.sibling;e!==null;)Ox(e,n,s),e=e.sibling}function Dx(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(Dx(e,n,s),e=e.sibling;e!==null;)Dx(e,n,s),e=e.sibling}var Dn=null,lr=!1;function $a(e,n,s){for(s=s.child;s!==null;)QA(e,n,s),s=s.sibling}function QA(e,n,s){if(Br&&typeof Br.onCommitFiberUnmount=="function")try{Br.onCommitFiberUnmount(Wf,s)}catch{}switch(s.tag){case 5:Gn||_l(s,n);case 6:var r=Dn,a=lr;Dn=null,$a(e,n,s),Dn=r,lr=a,Dn!==null&&(lr?(e=Dn,s=s.stateNode,e.nodeType===8?e.parentNode.removeChild(s):e.removeChild(s)):Dn.removeChild(s.stateNode));break;case 18:Dn!==null&&(lr?(e=Dn,s=s.stateNode,e.nodeType===8?Np(e.parentNode,s):e.nodeType===1&&Np(e,s),Qc(e)):Np(Dn,s.stateNode));break;case 4:r=Dn,a=lr,Dn=s.stateNode.containerInfo,lr=!0,$a(e,n,s),Dn=r,lr=a;break;case 0:case 11:case 14:case 15:if(!Gn&&(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)&&Px(s,n,l),a=a.next}while(a!==r)}$a(e,n,s);break;case 1:if(!Gn&&(_l(s,n),r=s.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=s.memoizedProps,r.state=s.memoizedState,r.componentWillUnmount()}catch(o){tn(s,n,o)}$a(e,n,s);break;case 21:$a(e,n,s);break;case 22:s.mode&1?(Gn=(r=Gn)||s.memoizedState!==null,$a(e,n,s),Gn=r):$a(e,n,s);break;default:$a(e,n,s)}}function W0(e){var n=e.updateQueue;if(n!==null){e.updateQueue=null;var s=e.stateNode;s===null&&(s=e.stateNode=new IF),n.forEach(function(r){var a=UF.bind(null,e,r);s.has(r)||(s.add(r),r.then(a,a))})}}function rr(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:Dn=o.stateNode,lr=!1;break e;case 3:Dn=o.stateNode.containerInfo,lr=!0;break e;case 4:Dn=o.stateNode.containerInfo,lr=!0;break e}o=o.return}if(Dn===null)throw Error(Ne(160));QA(i,l,a),Dn=null,lr=!1;var c=a.alternate;c!==null&&(c.return=null),a.return=null}catch(u){tn(a,n,u)}}if(n.subtreeFlags&12854)for(n=n.child;n!==null;)JA(n,e),n=n.sibling}function JA(e,n){var s=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(rr(n,e),Ir(e),r&4){try{Ic(3,e,e.return),Jf(3,e)}catch(g){tn(e,e.return,g)}try{Ic(5,e,e.return)}catch(g){tn(e,e.return,g)}}break;case 1:rr(n,e),Ir(e),r&512&&s!==null&&_l(s,s.return);break;case 5:if(rr(n,e),Ir(e),r&512&&s!==null&&_l(s,s.return),e.flags&32){var a=e.stateNode;try{Vc(a,"")}catch(g){tn(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&&jE(a,i),ix(o,l);var u=ix(o,i);for(l=0;l<c.length;l+=2){var h=c[l],f=c[l+1];h==="style"?NE(a,f):h==="dangerouslySetInnerHTML"?bE(a,f):h==="children"?Vc(a,f):Zj(a,h,f,u)}switch(o){case"input":tx(a,i);break;case"textarea":wE(a,i);break;case"select":var m=a._wrapperState.wasMultiple;a._wrapperState.wasMultiple=!!i.multiple;var p=i.value;p!=null?Hl(a,!!i.multiple,p,!1):m!==!!i.multiple&&(i.defaultValue!=null?Hl(a,!!i.multiple,i.defaultValue,!0):Hl(a,!!i.multiple,i.multiple?[]:"",!1))}a[tu]=i}catch(g){tn(e,e.return,g)}}break;case 6:if(rr(n,e),Ir(e),r&4){if(e.stateNode===null)throw Error(Ne(162));a=e.stateNode,i=e.memoizedProps;try{a.nodeValue=i}catch(g){tn(e,e.return,g)}}break;case 3:if(rr(n,e),Ir(e),r&4&&s!==null&&s.memoizedState.isDehydrated)try{Qc(n.containerInfo)}catch(g){tn(e,e.return,g)}break;case 4:rr(n,e),Ir(e);break;case 13:rr(n,e),Ir(e),a=e.child,a.flags&8192&&(i=a.memoizedState!==null,a.stateNode.isHidden=i,!i||a.alternate!==null&&a.alternate.memoizedState!==null||(Rw=rn())),r&4&&W0(e);break;case 22:if(h=s!==null&&s.memoizedState!==null,e.mode&1?(Gn=(u=Gn)||h,rr(n,e),Gn=u):rr(n,e),Ir(e),r&8192){if(u=e.memoizedState!==null,(e.stateNode.isHidden=u)&&!h&&e.mode&1)for(Le=e,h=e.child;h!==null;){for(f=Le=h;Le!==null;){switch(m=Le,p=m.child,m.tag){case 0:case 11:case 14:case 15:Ic(4,m,m.return);break;case 1:_l(m,m.return);var v=m.stateNode;if(typeof v.componentWillUnmount=="function"){r=m,s=m.return;try{n=r,v.props=n.memoizedProps,v.state=n.memoizedState,v.componentWillUnmount()}catch(g){tn(r,s,g)}}break;case 5:_l(m,m.return);break;case 22:if(m.memoizedState!==null){K0(f);continue}}p!==null?(p.return=m,Le=p):K0(f)}h=h.sibling}e:for(h=null,f=e;;){if(f.tag===5){if(h===null){h=f;try{a=f.stateNode,u?(i=a.style,typeof i.setProperty=="function"?i.setProperty("display","none","important"):i.display="none"):(o=f.stateNode,c=f.memoizedProps.style,l=c!=null&&c.hasOwnProperty("display")?c.display:null,o.style.display=kE("display",l))}catch(g){tn(e,e.return,g)}}}else if(f.tag===6){if(h===null)try{f.stateNode.nodeValue=u?"":f.memoizedProps}catch(g){tn(e,e.return,g)}}else if((f.tag!==22&&f.tag!==23||f.memoizedState===null||f===e)&&f.child!==null){f.child.return=f,f=f.child;continue}if(f===e)break e;for(;f.sibling===null;){if(f.return===null||f.return===e)break e;h===f&&(h=null),f=f.return}h===f&&(h=null),f.sibling.return=f.return,f=f.sibling}}break;case 19:rr(n,e),Ir(e),r&4&&W0(e);break;case 21:break;default:rr(n,e),Ir(e)}}function Ir(e){var n=e.flags;if(n&2){try{e:{for(var s=e.return;s!==null;){if(qA(s)){var r=s;break e}s=s.return}throw Error(Ne(160))}switch(r.tag){case 5:var a=r.stateNode;r.flags&32&&(Vc(a,""),r.flags&=-33);var i=B0(e);Dx(e,i,a);break;case 3:case 4:var l=r.stateNode.containerInfo,o=B0(e);Ox(e,o,l);break;default:throw Error(Ne(161))}}catch(c){tn(e,e.return,c)}e.flags&=-3}n&4096&&(e.flags&=-4097)}function PF(e,n,s){Le=e,XA(e)}function XA(e,n,s){for(var r=(e.mode&1)!==0;Le!==null;){var a=Le,i=a.child;if(a.tag===22&&r){var l=a.memoizedState!==null||yd;if(!l){var o=a.alternate,c=o!==null&&o.memoizedState!==null||Gn;o=yd;var u=Gn;if(yd=l,(Gn=c)&&!u)for(Le=a;Le!==null;)l=Le,c=l.child,l.tag===22&&l.memoizedState!==null?V0(a):c!==null?(c.return=l,Le=c):V0(a);for(;i!==null;)Le=i,XA(i),i=i.sibling;Le=a,yd=o,Gn=u}H0(e)}else a.subtreeFlags&8772&&i!==null?(i.return=a,Le=i):H0(e)}}function H0(e){for(;Le!==null;){var n=Le;if(n.flags&8772){var s=n.alternate;try{if(n.flags&8772)switch(n.tag){case 0:case 11:case 15:Gn||Jf(5,n);break;case 1:var r=n.stateNode;if(n.flags&4&&!Gn)if(s===null)r.componentDidMount();else{var a=n.elementType===n.type?s.memoizedProps:ir(n.type,s.memoizedProps);r.componentDidUpdate(a,s.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var i=n.updateQueue;i!==null&&A0(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}A0(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 f=h.dehydrated;f!==null&&Qc(f)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(Ne(163))}Gn||n.flags&512&&Mx(n)}catch(m){tn(n,n.return,m)}}if(n===e){Le=null;break}if(s=n.sibling,s!==null){s.return=n.return,Le=s;break}Le=n.return}}function K0(e){for(;Le!==null;){var n=Le;if(n===e){Le=null;break}var s=n.sibling;if(s!==null){s.return=n.return,Le=s;break}Le=n.return}}function V0(e){for(;Le!==null;){var n=Le;try{switch(n.tag){case 0:case 11:case 15:var s=n.return;try{Jf(4,n)}catch(c){tn(n,s,c)}break;case 1:var r=n.stateNode;if(typeof r.componentDidMount=="function"){var a=n.return;try{r.componentDidMount()}catch(c){tn(n,a,c)}}var i=n.return;try{Mx(n)}catch(c){tn(n,i,c)}break;case 5:var l=n.return;try{Mx(n)}catch(c){tn(n,l,c)}}}catch(c){tn(n,n.return,c)}if(n===e){Le=null;break}var o=n.sibling;if(o!==null){o.return=n.return,Le=o;break}Le=n.return}}var MF=Math.ceil,Gh=ka.ReactCurrentDispatcher,Tw=ka.ReactCurrentOwner,Xs=ka.ReactCurrentBatchConfig,wt=0,$n=null,fn=null,Ln=0,Ss=0,zl=hi(0),yn=0,lu=null,Gi=0,Xf=0,Iw=0,Rc=null,fs=null,Rw=0,oo=1/0,ra=null,Yh=!1,Lx=null,Va=null,bd=!1,Fa=null,qh=0,Pc=0,Fx=null,oh=-1,ch=0;function as(){return wt&6?rn():oh!==-1?oh:oh=rn()}function Ga(e){return e.mode&1?wt&2&&Ln!==0?Ln&-Ln:xF.transition!==null?(ch===0&&(ch=DE()),ch):(e=Nt,e!==0||(e=window.event,e=e===void 0?16:WE(e.type)),e):1}function fr(e,n,s,r){if(50<Pc)throw Pc=0,Fx=null,Error(Ne(185));Ou(e,s,r),(!(wt&2)||e!==$n)&&(e===$n&&(!(wt&2)&&(Xf|=s),yn===4&&Oa(e,Ln)),js(e,r),s===1&&wt===0&&!(n.mode&1)&&(oo=rn()+500,Yf&&fi()))}function js(e,n){var s=e.callbackNode;xL(e,n);var r=Rh(e,e===$n?Ln:0);if(r===0)s!==null&&t0(s),e.callbackNode=null,e.callbackPriority=0;else if(n=r&-r,e.callbackPriority!==n){if(s!=null&&t0(s),n===1)e.tag===0?gF(G0.bind(null,e)):oA(G0.bind(null,e)),hF(function(){!(wt&6)&&fi()}),s=null;else{switch(LE(r)){case 1:s=rw;break;case 4:s=ME;break;case 16:s=Ih;break;case 536870912:s=OE;break;default:s=Ih}s=i$(s,ZA.bind(null,e))}e.callbackPriority=n,e.callbackNode=s}}function ZA(e,n){if(oh=-1,ch=0,wt&6)throw Error(Ne(327));var s=e.callbackNode;if(ql()&&e.callbackNode!==s)return null;var r=Rh(e,e===$n?Ln:0);if(r===0)return null;if(r&30||r&e.expiredLanes||n)n=Qh(e,r);else{n=r;var a=wt;wt|=2;var i=t$();($n!==e||Ln!==n)&&(ra=null,oo=rn()+500,_i(e,n));do try{LF();break}catch(o){e$(e,o)}while(!0);xw(),Gh.current=i,wt=a,fn!==null?n=0:($n=null,Ln=0,n=yn)}if(n!==0){if(n===2&&(a=dx(e),a!==0&&(r=a,n=_x(e,a))),n===1)throw s=lu,_i(e,0),Oa(e,r),js(e,rn()),s;if(n===6)Oa(e,r);else{if(a=e.current.alternate,!(r&30)&&!OF(a)&&(n=Qh(e,r),n===2&&(i=dx(e),i!==0&&(r=i,n=_x(e,i))),n===1))throw s=lu,_i(e,0),Oa(e,r),js(e,rn()),s;switch(e.finishedWork=a,e.finishedLanes=r,n){case 0:case 1:throw Error(Ne(345));case 2:Ti(e,fs,ra);break;case 3:if(Oa(e,r),(r&130023424)===r&&(n=Rw+500-rn(),10<n)){if(Rh(e,0)!==0)break;if(a=e.suspendedLanes,(a&r)!==r){as(),e.pingedLanes|=e.suspendedLanes&a;break}e.timeoutHandle=jx(Ti.bind(null,e,fs,ra),n);break}Ti(e,fs,ra);break;case 4:if(Oa(e,r),(r&4194240)===r)break;for(n=e.eventTimes,a=-1;0<r;){var l=31-hr(r);i=1<<l,l=n[l],l>a&&(a=l),r&=~i}if(r=a,r=rn()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*MF(r/1960))-r,10<r){e.timeoutHandle=jx(Ti.bind(null,e,fs,ra),r);break}Ti(e,fs,ra);break;case 5:Ti(e,fs,ra);break;default:throw Error(Ne(329))}}}return js(e,rn()),e.callbackNode===s?ZA.bind(null,e):null}function _x(e,n){var s=Rc;return e.current.memoizedState.isDehydrated&&(_i(e,n).flags|=256),e=Qh(e,n),e!==2&&(n=fs,fs=s,n!==null&&zx(n)),e}function zx(e){fs===null?fs=e:fs.push.apply(fs,e)}function OF(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(!gr(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 Oa(e,n){for(n&=~Iw,n&=~Xf,e.suspendedLanes|=n,e.pingedLanes&=~n,e=e.expirationTimes;0<n;){var s=31-hr(n),r=1<<s;e[s]=-1,n&=~r}}function G0(e){if(wt&6)throw Error(Ne(327));ql();var n=Rh(e,0);if(!(n&1))return js(e,rn()),null;var s=Qh(e,n);if(e.tag!==0&&s===2){var r=dx(e);r!==0&&(n=r,s=_x(e,r))}if(s===1)throw s=lu,_i(e,0),Oa(e,n),js(e,rn()),s;if(s===6)throw Error(Ne(345));return e.finishedWork=e.current.alternate,e.finishedLanes=n,Ti(e,fs,ra),js(e,rn()),null}function Pw(e,n){var s=wt;wt|=1;try{return e(n)}finally{wt=s,wt===0&&(oo=rn()+500,Yf&&fi())}}function Yi(e){Fa!==null&&Fa.tag===0&&!(wt&6)&&ql();var n=wt;wt|=1;var s=Xs.transition,r=Nt;try{if(Xs.transition=null,Nt=1,e)return e()}finally{Nt=r,Xs.transition=s,wt=n,!(wt&6)&&fi()}}function Mw(){Ss=zl.current,Ut(zl)}function _i(e,n){e.finishedWork=null,e.finishedLanes=0;var s=e.timeoutHandle;if(s!==-1&&(e.timeoutHandle=-1,dF(s)),fn!==null)for(s=fn.return;s!==null;){var r=s;switch(mw(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Lh();break;case 3:io(),Ut(xs),Ut(qn),kw();break;case 5:bw(r);break;case 4:io();break;case 13:Ut(qt);break;case 19:Ut(qt);break;case 10:vw(r.type._context);break;case 22:case 23:Mw()}s=s.return}if($n=e,fn=e=Ya(e.current,null),Ln=Ss=n,yn=0,lu=null,Iw=Xf=Gi=0,fs=Rc=null,Mi!==null){for(n=0;n<Mi.length;n++)if(s=Mi[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}Mi=null}return e}function e$(e,n){do{var s=fn;try{if(xw(),ah.current=Vh,Kh){for(var r=Qt.memoizedState;r!==null;){var a=r.queue;a!==null&&(a.pending=null),r=r.next}Kh=!1}if(Vi=0,Cn=jn=Qt=null,Tc=!1,ru=0,Tw.current=null,s===null||s.return===null){yn=1,lu=n,fn=null;break}e:{var i=e,l=s.return,o=s,c=n;if(n=Ln,o.flags|=32768,c!==null&&typeof c=="object"&&typeof c.then=="function"){var u=c,h=o,f=h.tag;if(!(h.mode&1)&&(f===0||f===11||f===15)){var m=h.alternate;m?(h.updateQueue=m.updateQueue,h.memoizedState=m.memoizedState,h.lanes=m.lanes):(h.updateQueue=null,h.memoizedState=null)}var p=M0(l);if(p!==null){p.flags&=-257,O0(p,l,o,i,n),p.mode&1&&P0(i,u,n),n=p,c=u;var v=n.updateQueue;if(v===null){var g=new Set;g.add(c),n.updateQueue=g}else v.add(c);break e}else{if(!(n&1)){P0(i,u,n),Ow();break e}c=Error(Ne(426))}}else if(Ht&&o.mode&1){var k=M0(l);if(k!==null){!(k.flags&65536)&&(k.flags|=256),O0(k,l,o,i,n),pw(lo(c,o));break e}}i=c=lo(c,o),yn!==4&&(yn=2),Rc===null?Rc=[i]:Rc.push(i),i=l;do{switch(i.tag){case 3:i.flags|=65536,n&=-n,i.lanes|=n;var j=LA(i,c,n);E0(i,j);break e;case 1:o=c;var x=i.type,w=i.stateNode;if(!(i.flags&128)&&(typeof x.getDerivedStateFromError=="function"||w!==null&&typeof w.componentDidCatch=="function"&&(Va===null||!Va.has(w)))){i.flags|=65536,n&=-n,i.lanes|=n;var N=FA(i,o,n);E0(i,N);break e}}i=i.return}while(i!==null)}s$(s)}catch(y){n=y,fn===s&&s!==null&&(fn=s=s.return);continue}break}while(!0)}function t$(){var e=Gh.current;return Gh.current=Vh,e===null?Vh:e}function Ow(){(yn===0||yn===3||yn===2)&&(yn=4),$n===null||!(Gi&268435455)&&!(Xf&268435455)||Oa($n,Ln)}function Qh(e,n){var s=wt;wt|=2;var r=t$();($n!==e||Ln!==n)&&(ra=null,_i(e,n));do try{DF();break}catch(a){e$(e,a)}while(!0);if(xw(),wt=s,Gh.current=r,fn!==null)throw Error(Ne(261));return $n=null,Ln=0,yn}function DF(){for(;fn!==null;)n$(fn)}function LF(){for(;fn!==null&&!oL();)n$(fn)}function n$(e){var n=a$(e.alternate,e,Ss);e.memoizedProps=e.pendingProps,n===null?s$(e):fn=n,Tw.current=null}function s$(e){var n=e;do{var s=n.alternate;if(e=n.return,n.flags&32768){if(s=TF(s,n),s!==null){s.flags&=32767,fn=s;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{yn=6,fn=null;return}}else if(s=$F(s,n,Ss),s!==null){fn=s;return}if(n=n.sibling,n!==null){fn=n;return}fn=n=e}while(n!==null);yn===0&&(yn=5)}function Ti(e,n,s){var r=Nt,a=Xs.transition;try{Xs.transition=null,Nt=1,FF(e,n,s,r)}finally{Xs.transition=a,Nt=r}return null}function FF(e,n,s,r){do ql();while(Fa!==null);if(wt&6)throw Error(Ne(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(Ne(177));e.callbackNode=null,e.callbackPriority=0;var i=s.lanes|s.childLanes;if(vL(e,i),e===$n&&(fn=$n=null,Ln=0),!(s.subtreeFlags&2064)&&!(s.flags&2064)||bd||(bd=!0,i$(Ih,function(){return ql(),null})),i=(s.flags&15990)!==0,s.subtreeFlags&15990||i){i=Xs.transition,Xs.transition=null;var l=Nt;Nt=1;var o=wt;wt|=4,Tw.current=null,RF(e,s),JA(s,e),rF(xx),Ph=!!gx,xx=gx=null,e.current=s,PF(s),cL(),wt=o,Nt=l,Xs.transition=i}else e.current=s;if(bd&&(bd=!1,Fa=e,qh=a),i=e.pendingLanes,i===0&&(Va=null),hL(s.stateNode),js(e,rn()),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(Yh)throw Yh=!1,e=Lx,Lx=null,e;return qh&1&&e.tag!==0&&ql(),i=e.pendingLanes,i&1?e===Fx?Pc++:(Pc=0,Fx=e):Pc=0,fi(),null}function ql(){if(Fa!==null){var e=LE(qh),n=Xs.transition,s=Nt;try{if(Xs.transition=null,Nt=16>e?16:e,Fa===null)var r=!1;else{if(e=Fa,Fa=null,qh=0,wt&6)throw Error(Ne(331));var a=wt;for(wt|=4,Le=e.current;Le!==null;){var i=Le,l=i.child;if(Le.flags&16){var o=i.deletions;if(o!==null){for(var c=0;c<o.length;c++){var u=o[c];for(Le=u;Le!==null;){var h=Le;switch(h.tag){case 0:case 11:case 15:Ic(8,h,i)}var f=h.child;if(f!==null)f.return=h,Le=f;else for(;Le!==null;){h=Le;var m=h.sibling,p=h.return;if(YA(h),h===u){Le=null;break}if(m!==null){m.return=p,Le=m;break}Le=p}}}var v=i.alternate;if(v!==null){var g=v.child;if(g!==null){v.child=null;do{var k=g.sibling;g.sibling=null,g=k}while(g!==null)}}Le=i}}if(i.subtreeFlags&2064&&l!==null)l.return=i,Le=l;else e:for(;Le!==null;){if(i=Le,i.flags&2048)switch(i.tag){case 0:case 11:case 15:Ic(9,i,i.return)}var j=i.sibling;if(j!==null){j.return=i.return,Le=j;break e}Le=i.return}}var x=e.current;for(Le=x;Le!==null;){l=Le;var w=l.child;if(l.subtreeFlags&2064&&w!==null)w.return=l,Le=w;else e:for(l=x;Le!==null;){if(o=Le,o.flags&2048)try{switch(o.tag){case 0:case 11:case 15:Jf(9,o)}}catch(y){tn(o,o.return,y)}if(o===l){Le=null;break e}var N=o.sibling;if(N!==null){N.return=o.return,Le=N;break e}Le=o.return}}if(wt=a,fi(),Br&&typeof Br.onPostCommitFiberRoot=="function")try{Br.onPostCommitFiberRoot(Wf,e)}catch{}r=!0}return r}finally{Nt=s,Xs.transition=n}}return!1}function Y0(e,n,s){n=lo(s,n),n=LA(e,n,1),e=Ka(e,n,1),n=as(),e!==null&&(Ou(e,1,n),js(e,n))}function tn(e,n,s){if(e.tag===3)Y0(e,e,s);else for(;n!==null;){if(n.tag===3){Y0(n,e,s);break}else if(n.tag===1){var r=n.stateNode;if(typeof n.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(Va===null||!Va.has(r))){e=lo(s,e),e=FA(n,e,1),n=Ka(n,e,1),e=as(),n!==null&&(Ou(n,1,e),js(n,e));break}}n=n.return}}function _F(e,n,s){var r=e.pingCache;r!==null&&r.delete(n),n=as(),e.pingedLanes|=e.suspendedLanes&s,$n===e&&(Ln&s)===s&&(yn===4||yn===3&&(Ln&130023424)===Ln&&500>rn()-Rw?_i(e,0):Iw|=s),js(e,n)}function r$(e,n){n===0&&(e.mode&1?(n=hd,hd<<=1,!(hd&130023424)&&(hd=4194304)):n=1);var s=as();e=va(e,n),e!==null&&(Ou(e,n,s),js(e,s))}function zF(e){var n=e.memoizedState,s=0;n!==null&&(s=n.retryLane),r$(e,s)}function UF(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(Ne(314))}r!==null&&r.delete(n),r$(e,s)}var a$;a$=function(e,n,s){if(e!==null)if(e.memoizedProps!==n.pendingProps||xs.current)ps=!0;else{if(!(e.lanes&s)&&!(n.flags&128))return ps=!1,AF(e,n,s);ps=!!(e.flags&131072)}else ps=!1,Ht&&n.flags&1048576&&cA(n,zh,n.index);switch(n.lanes=0,n.tag){case 2:var r=n.type;lh(e,n),e=n.pendingProps;var a=so(n,qn.current);Yl(n,s),a=Sw(null,n,r,e,a,s);var i=Cw();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,vs(r)?(i=!0,Fh(n)):i=!1,n.memoizedState=a.state!==null&&a.state!==void 0?a.state:null,ww(n),a.updater=Qf,n.stateNode=a,a._reactInternals=n,Cx(n,r,e,s),n=$x(null,n,r,!0,i,s)):(n.tag=0,Ht&&i&&fw(n),ns(null,n,a,s),n=n.child),n;case 16:r=n.elementType;e:{switch(lh(e,n),e=n.pendingProps,a=r._init,r=a(r._payload),n.type=r,a=n.tag=WF(r),e=ir(r,e),a){case 0:n=Ax(null,n,r,e,s);break e;case 1:n=F0(null,n,r,e,s);break e;case 11:n=D0(null,n,r,e,s);break e;case 14:n=L0(null,n,r,ir(r.type,e),s);break e}throw Error(Ne(306,r,""))}return n;case 0:return r=n.type,a=n.pendingProps,a=n.elementType===r?a:ir(r,a),Ax(e,n,r,a,s);case 1:return r=n.type,a=n.pendingProps,a=n.elementType===r?a:ir(r,a),F0(e,n,r,a,s);case 3:e:{if(BA(n),e===null)throw Error(Ne(387));r=n.pendingProps,i=n.memoizedState,a=i.element,pA(e,n),Wh(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=lo(Error(Ne(423)),n),n=_0(e,n,r,s,a);break e}else if(r!==a){a=lo(Error(Ne(424)),n),n=_0(e,n,r,s,a);break e}else for(As=Ha(n.stateNode.containerInfo.firstChild),Ts=n,Ht=!0,or=null,s=fA(n,null,r,s),n.child=s;s;)s.flags=s.flags&-3|4096,s=s.sibling;else{if(ro(),r===a){n=ja(e,n,s);break e}ns(e,n,r,s)}n=n.child}return n;case 5:return gA(n),e===null&&kx(n),r=n.type,a=n.pendingProps,i=e!==null?e.memoizedProps:null,l=a.children,vx(r,a)?l=null:i!==null&&vx(r,i)&&(n.flags|=32),UA(e,n),ns(e,n,l,s),n.child;case 6:return e===null&&kx(n),null;case 13:return WA(e,n,s);case 4:return yw(n,n.stateNode.containerInfo),r=n.pendingProps,e===null?n.child=ao(n,null,r,s):ns(e,n,r,s),n.child;case 11:return r=n.type,a=n.pendingProps,a=n.elementType===r?a:ir(r,a),D0(e,n,r,a,s);case 7:return ns(e,n,n.pendingProps,s),n.child;case 8:return ns(e,n,n.pendingProps.children,s),n.child;case 12:return ns(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,Ot(Uh,r._currentValue),r._currentValue=l,i!==null)if(gr(i.value,l)){if(i.children===a.children&&!xs.current){n=ja(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=ha(-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),Nx(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(Ne(341));l.lanes|=s,o=l.alternate,o!==null&&(o.lanes|=s),Nx(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}ns(e,n,a.children,s),n=n.child}return n;case 9:return a=n.type,r=n.pendingProps.children,Yl(n,s),a=er(a),r=r(a),n.flags|=1,ns(e,n,r,s),n.child;case 14:return r=n.type,a=ir(r,n.pendingProps),a=ir(r.type,a),L0(e,n,r,a,s);case 15:return _A(e,n,n.type,n.pendingProps,s);case 17:return r=n.type,a=n.pendingProps,a=n.elementType===r?a:ir(r,a),lh(e,n),n.tag=1,vs(r)?(e=!0,Fh(n)):e=!1,Yl(n,s),DA(n,r,a),Cx(n,r,a,s),$x(null,n,r,!0,e,s);case 19:return HA(e,n,s);case 22:return zA(e,n,s)}throw Error(Ne(156,n.tag))};function i$(e,n){return PE(e,n)}function BF(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 Js(e,n,s,r){return new BF(e,n,s,r)}function Dw(e){return e=e.prototype,!(!e||!e.isReactComponent)}function WF(e){if(typeof e=="function")return Dw(e)?1:0;if(e!=null){if(e=e.$$typeof,e===tw)return 11;if(e===nw)return 14}return 2}function Ya(e,n){var s=e.alternate;return s===null?(s=Js(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")Dw(e)&&(l=1);else if(typeof e=="string")l=5;else e:switch(e){case Tl:return zi(s.children,a,i,n);case ew:l=8,a|=8;break;case Qg:return e=Js(12,s,n,a|2),e.elementType=Qg,e.lanes=i,e;case Jg:return e=Js(13,s,n,a),e.elementType=Jg,e.lanes=i,e;case Xg:return e=Js(19,s,n,a),e.elementType=Xg,e.lanes=i,e;case gE:return Zf(s,a,i,n);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case mE:l=10;break e;case pE:l=9;break e;case tw:l=11;break e;case nw:l=14;break e;case Ra:l=16,r=null;break e}throw Error(Ne(130,e==null?e:typeof e,""))}return n=Js(l,s,n,a),n.elementType=e,n.type=r,n.lanes=i,n}function zi(e,n,s,r){return e=Js(7,e,r,n),e.lanes=s,e}function Zf(e,n,s,r){return e=Js(22,e,r,n),e.elementType=gE,e.lanes=s,e.stateNode={isHidden:!1},e}function Rp(e,n,s){return e=Js(6,e,null,n),e.lanes=s,e}function Pp(e,n,s){return n=Js(4,e.children!==null?e.children:[],e.key,n),n.lanes=s,n.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},n}function HF(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=fp(0),this.expirationTimes=fp(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=fp(0),this.identifierPrefix=r,this.onRecoverableError=a,this.mutableSourceEagerHydrationData=null}function Lw(e,n,s,r,a,i,l,o,c){return e=new HF(e,n,s,o,c),n===1?(n=1,i===!0&&(n|=8)):n=0,i=Js(3,null,null,n),e.current=i,i.stateNode=e,i.memoizedState={element:r,isDehydrated:s,cache:null,transitions:null,pendingSuspenseBoundaries:null},ww(i),e}function KF(e,n,s){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:$l,key:r==null?null:""+r,children:e,containerInfo:n,implementation:s}}function l$(e){if(!e)return ei;e=e._reactInternals;e:{if(rl(e)!==e||e.tag!==1)throw Error(Ne(170));var n=e;do{switch(n.tag){case 3:n=n.stateNode.context;break e;case 1:if(vs(n.type)){n=n.stateNode.__reactInternalMemoizedMergedChildContext;break e}}n=n.return}while(n!==null);throw Error(Ne(171))}if(e.tag===1){var s=e.type;if(vs(s))return lA(e,s,n)}return n}function o$(e,n,s,r,a,i,l,o,c){return e=Lw(s,r,!0,e,a,i,l,o,c),e.context=l$(null),s=e.current,r=as(),a=Ga(s),i=ha(r,a),i.callback=n??null,Ka(s,i,a),e.current.lanes=a,Ou(e,a,r),js(e,r),e}function em(e,n,s,r){var a=n.current,i=as(),l=Ga(a);return s=l$(s),n.context===null?n.context=s:n.pendingContext=s,n=ha(i,l),n.payload={element:e},r=r===void 0?null:r,r!==null&&(n.callback=r),e=Ka(a,n,l),e!==null&&(fr(e,a,l,i),rh(e,a,l)),l}function Jh(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 q0(e,n){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var s=e.retryLane;e.retryLane=s!==0&&s<n?s:n}}function Fw(e,n){q0(e,n),(e=e.alternate)&&q0(e,n)}function VF(){return null}var c$=typeof reportError=="function"?reportError:function(e){console.error(e)};function _w(e){this._internalRoot=e}tm.prototype.render=_w.prototype.render=function(e){var n=this._internalRoot;if(n===null)throw Error(Ne(409));em(e,n,null,null)};tm.prototype.unmount=_w.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var n=e.containerInfo;Yi(function(){em(null,e,null,null)}),n[xa]=null}};function tm(e){this._internalRoot=e}tm.prototype.unstable_scheduleHydration=function(e){if(e){var n=zE();e={blockedOn:null,target:e,priority:n};for(var s=0;s<Ma.length&&n!==0&&n<Ma[s].priority;s++);Ma.splice(s,0,e),s===0&&BE(e)}};function zw(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function nm(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function Q0(){}function GF(e,n,s,r,a){if(a){if(typeof r=="function"){var i=r;r=function(){var u=Jh(l);i.call(u)}}var l=o$(n,r,e,0,null,!1,!1,"",Q0);return e._reactRootContainer=l,e[xa]=l.current,Zc(e.nodeType===8?e.parentNode:e),Yi(),l}for(;a=e.lastChild;)e.removeChild(a);if(typeof r=="function"){var o=r;r=function(){var u=Jh(c);o.call(u)}}var c=Lw(e,0,!1,null,null,!1,!1,"",Q0);return e._reactRootContainer=c,e[xa]=c.current,Zc(e.nodeType===8?e.parentNode:e),Yi(function(){em(n,c,s,r)}),c}function sm(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=Jh(l);o.call(c)}}em(n,l,e,a)}else l=GF(s,n,e,a,r);return Jh(l)}FE=function(e){switch(e.tag){case 3:var n=e.stateNode;if(n.current.memoizedState.isDehydrated){var s=xc(n.pendingLanes);s!==0&&(aw(n,s|1),js(n,rn()),!(wt&6)&&(oo=rn()+500,fi()))}break;case 13:Yi(function(){var r=va(e,1);if(r!==null){var a=as();fr(r,e,1,a)}}),Fw(e,1)}};iw=function(e){if(e.tag===13){var n=va(e,134217728);if(n!==null){var s=as();fr(n,e,134217728,s)}Fw(e,134217728)}};_E=function(e){if(e.tag===13){var n=Ga(e),s=va(e,n);if(s!==null){var r=as();fr(s,e,n,r)}Fw(e,n)}};zE=function(){return Nt};UE=function(e,n){var s=Nt;try{return Nt=e,n()}finally{Nt=s}};ox=function(e,n,s){switch(n){case"input":if(tx(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=Gf(r);if(!a)throw Error(Ne(90));vE(r),tx(r,a)}}}break;case"textarea":wE(e,s);break;case"select":n=s.value,n!=null&&Hl(e,!!s.multiple,n,!1)}};EE=Pw;AE=Yi;var YF={usingClientEntryPoint:!1,Events:[Lu,Ml,Gf,SE,CE,Pw]},ac={findFiberByHostInstance:Pi,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},qF={bundleType:ac.bundleType,version:ac.version,rendererPackageName:ac.rendererPackageName,rendererConfig:ac.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:ka.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=IE(e),e===null?null:e.stateNode},findFiberByHostInstance:ac.findFiberByHostInstance||VF,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 kd=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!kd.isDisabled&&kd.supportsFiber)try{Wf=kd.inject(qF),Br=kd}catch{}}Ds.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=YF;Ds.createPortal=function(e,n){var s=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!zw(n))throw Error(Ne(200));return KF(e,n,null,s)};Ds.createRoot=function(e,n){if(!zw(e))throw Error(Ne(299));var s=!1,r="",a=c$;return n!=null&&(n.unstable_strictMode===!0&&(s=!0),n.identifierPrefix!==void 0&&(r=n.identifierPrefix),n.onRecoverableError!==void 0&&(a=n.onRecoverableError)),n=Lw(e,1,!1,null,null,s,!1,r,a),e[xa]=n.current,Zc(e.nodeType===8?e.parentNode:e),new _w(n)};Ds.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(Ne(188)):(e=Object.keys(e).join(","),Error(Ne(268,e)));return e=IE(n),e=e===null?null:e.stateNode,e};Ds.flushSync=function(e){return Yi(e)};Ds.hydrate=function(e,n,s){if(!nm(n))throw Error(Ne(200));return sm(null,e,n,!0,s)};Ds.hydrateRoot=function(e,n,s){if(!zw(e))throw Error(Ne(405));var r=s!=null&&s.hydratedSources||null,a=!1,i="",l=c$;if(s!=null&&(s.unstable_strictMode===!0&&(a=!0),s.identifierPrefix!==void 0&&(i=s.identifierPrefix),s.onRecoverableError!==void 0&&(l=s.onRecoverableError)),n=o$(n,null,e,1,s??null,a,!1,i,l),e[xa]=n.current,Zc(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 tm(n)};Ds.render=function(e,n,s){if(!nm(n))throw Error(Ne(200));return sm(null,e,n,!1,s)};Ds.unmountComponentAtNode=function(e){if(!nm(e))throw Error(Ne(40));return e._reactRootContainer?(Yi(function(){sm(null,null,e,!1,function(){e._reactRootContainer=null,e[xa]=null})}),!0):!1};Ds.unstable_batchedUpdates=Pw;Ds.unstable_renderSubtreeIntoContainer=function(e,n,s,r){if(!nm(s))throw Error(Ne(200));if(e==null||e._reactInternals===void 0)throw Error(Ne(38));return sm(e,n,s,!1,r)};Ds.version="18.3.1-next-f1338f8080-20240426";function u$(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(u$)}catch(e){console.error(e)}}u$(),uE.exports=Ds;var Ao=uE.exports,d$,J0=Ao;d$=J0.createRoot,J0.hydrateRoot;const QF=["use","new","stop","quiet"];function X0(e){return QF.includes(e)}function JF(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 XF=e=>e.replace(/^plugin-/,"").replace(/[-_]+/g," ").replace(/^./,n=>n.toUpperCase());function ZF(e){return e.map(n=>({group:`From ${XF(n.plugin)}`,name:n.name,...n.args?{args:n.args}:{},desc:n.description,source:"plugin"}))}const e_=e=>!!(e.args&&e.args.startsWith("<"));let Xh=[];const Ux=new Set;function t_(e){const n=e??[];JSON.stringify(n)!==JSON.stringify(Xh)&&(Xh=n,Ux.forEach(s=>s()))}function n_(){return d.useSyncExternalStore(e=>(Ux.add(e),()=>Ux.delete(e)),()=>Xh,()=>Xh)}var s_=Object.defineProperty,$o=(e,n)=>s_(e,"name",{value:n,configurable:!0}),h$=!!(typeof window<"u"&&window.document&&window.document.createElement);function He(e,n,{checkForDefaultPrevented:s=!0}={}){return $o(function(a){if(e==null||e(a),s===!1||!a||!a.defaultPrevented)return n==null?void 0:n(a)},"handleEvent")}$o(He,"composeEventHandlers");function r_(e){var n;if(!h$)throw new Error("Cannot access window outside of the DOM");return((n=e==null?void 0:e.ownerDocument)==null?void 0:n.defaultView)??window}$o(r_,"getOwnerWindow");function Bx(e){if(!h$)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}$o(Bx,"getOwnerDocument");function f$(e,n=!1){const{activeElement:s}=Bx(e);if(!(s!=null&&s.nodeName))return null;if(m$(s)&&s.contentDocument)return f$(s.contentDocument.body,n);if(n){const r=s.getAttribute("aria-activedescendant");if(r){const a=Bx(s).getElementById(r);if(a)return a}}return s}$o(f$,"getActiveElement");function m$(e){return e.tagName==="IFRAME"}$o(m$,"isFrame");var a_=Object.defineProperty,Uw=(e,n)=>a_(e,"name",{value:n,configurable:!0});function Wx(e,n){if(typeof e=="function")return e(n);e!=null&&(e.current=n)}Uw(Wx,"setRef");function p$(...e){return n=>{let s=!1;const r=e.map(a=>{const i=Wx(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():Wx(e[a],null)}}}}Uw(p$,"composeRefs");function It(...e){return d.useCallback(p$(...e),e)}Uw(It,"useComposedRefs");var i_=Object.defineProperty,Qs=(e,n)=>i_(e,"name",{value:n,configurable:!0});function l_(e,n){const s=d.createContext(n);s.displayName=e+"Context";const r=Qs(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 Qs(a,"useContext"),[r,a]}Qs(l_,"createContext");function Sr(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=Qs(f=>{var j;const{scope:m,children:p,...v}=f,g=((j=m==null?void 0:m[e])==null?void 0:j[c])||o,k=d.useMemo(()=>v,Object.values(v));return t.jsx(g.Provider,{value:k,children:p})},"Provider");u.displayName=i+"Provider";function h(f,m,p={}){var j;const{optional:v=!1}=p,g=((j=m==null?void 0:m[e])==null?void 0:j[c])||o,k=d.useContext(g);if(k)return k;if(l!==void 0)return l;if(!v)throw new Error(`\`${f}\` must be used within \`${i}\``)}return Qs(h,"useContext"),[u,h]}Qs(r,"createContext");const a=Qs(()=>{const i=s.map(l=>d.createContext(l));return Qs(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,g$(a,...n)]}Qs(Sr,"createContextScope");function g$(...e){const n=e[0];if(e.length===1)return n;const s=Qs(()=>{const r=e.map(a=>({useScope:a(),scopeName:a.scopeName}));return Qs(function(i){const l=r.reduce((o,{useScope:c,scopeName:u})=>{const f=c(i)[`__scope${u}`];return{...o,...f}},{});return d.useMemo(()=>({[`__scope${n.scopeName}`]:l}),[l])},"useComposedScopes")},"createScope");return s.scopeName=n.scopeName,s}Qs(g$,"composeContextScopes");var o_=Object.defineProperty,Cr=(e,n)=>o_(e,"name",{value:n,configurable:!0});function ti(e){const n=d.forwardRef((s,r)=>{let{children:a,...i}=s,l=null,o=!1;const c=[];Hx(a)&&typeof Nd=="function"&&(a=Nd(a._payload)),d.Children.forEach(a,m=>{var p;if(y$(m)){o=!0;const v=m;let g="child"in v.props?v.props.child:v.props.children;Hx(g)&&typeof Nd=="function"&&(g=Nd(g._payload)),l=c_(v,g),c.push((p=l==null?void 0:l.props)==null?void 0:p.children)}else c.push(m)}),l?l=d.cloneElement(l,void 0,c):!o&&d.Children.count(a)===1&&d.isValidElement(a)&&(l=a);const u=l?w$(l):void 0,h=It(r,u);if(!l){if(a||a===0)throw new Error(o?h_(e):d_(e));return a}const f=j$(i,l.props??{});return l.type!==d.Fragment&&(f.ref=r?h:u),d.cloneElement(l,f)});return n.displayName=`${e}.Slot`,n}Cr(ti,"createSlot");var x$=Symbol.for("radix.slottable");function v$(e){const n=Cr(s=>"child"in s?s.children(s.child):s.children,"Slottable");return n.displayName=`${e}.Slottable`,n.__radixId=x$,n}Cr(v$,"createSlottable");var c_=Cr((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 j$(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}}Cr(j$,"mergeProps");function w$(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)}Cr(w$,"getElementRef");function y$(e){return d.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===x$}Cr(y$,"isSlottable");var u_=Symbol.for("react.lazy");function Hx(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===u_&&"_payload"in e&&b$(e._payload)}Cr(Hx,"isLazyComponent");function b$(e){return typeof e=="object"&&e!==null&&"then"in e}Cr(b$,"isPromiseLike");var d_=Cr(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),h_=Cr(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Nd=So[" use ".trim().toString()],f_=Object.defineProperty,En=(e,n)=>f_(e,"name",{value:n,configurable:!0});function rm(e){const n=e+"CollectionProvider",[s,r]=Sr(n),[a,i]=s(n,{collectionRef:{current:null},itemMap:new Map}),l=En(g=>{const{scope:k,children:j}=g,x=d.useRef(null),w=d.useRef(new Map).current;return t.jsx(a,{scope:k,itemMap:w,collectionRef:x,children:j})},"CollectionProvider");l.displayName=n;const o=e+"CollectionSlot",c=ti(o),u=d.forwardRef((g,k)=>{const{scope:j,children:x}=g,w=i(o,j),N=It(k,w.collectionRef);return t.jsx(c,{ref:N,children:x})});u.displayName=o;const h=e+"CollectionItemSlot",f="data-radix-collection-item",m=ti(h),p=d.forwardRef((g,k)=>{const{scope:j,children:x,...w}=g,N=d.useRef(null),y=It(k,N),b=i(h,j);return d.useEffect(()=>(b.itemMap.set(N,{ref:N,...w}),()=>void b.itemMap.delete(N))),t.jsx(m,{[f]:"",ref:y,children:x})});p.displayName=h;function v(g){const k=i(e+"CollectionConsumer",g);return d.useCallback(()=>{const x=k.collectionRef.current;if(!x)return[];const w=Array.from(x.querySelectorAll(`[${f}]`));return Array.from(k.itemMap.values()).sort((b,S)=>w.indexOf(b.ref.current)-w.indexOf(S.ref.current))},[k.collectionRef,k.itemMap])}return En(v,"useCollection"),[{Provider:l,Slot:u,ItemSlot:p},v,r]}En(rm,"createCollection");var Z0=new WeakMap,dn,Cs,Mp=(Cs=class extends Map{constructor(s){super(s);Bk(this,dn);lp(this,dn,[...super.keys()]),Z0.set(this,!0)}set(s,r){return Z0.get(this)&&(this.has(s)?Wn(this,dn)[Wn(this,dn).indexOf(s)]=s:Wn(this,dn).push(s)),super.set(s,r),this}insert(s,r,a){const i=this.has(r),l=Wn(this,dn).length,o=Bw(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 f=[...Wn(this,dn)];let m,p=!1;for(let v=c;v<h;v++)if(c===v){let g=f[v];f[v]===r&&(g=f[v+1]),i&&this.delete(r),m=this.get(g),this.set(r,a)}else{!p&&f[v-1]===r&&(p=!0);const g=f[p?v:v-1],k=m;m=this.get(g),this.delete(g),this.set(g,k)}return this}with(s,r,a){const i=new Cs(this);return i.insert(s,r,a),i}before(s){const r=Wn(this,dn).indexOf(s)-1;if(!(r<0))return this.entryAt(r)}setBefore(s,r,a){const i=Wn(this,dn).indexOf(s);return i===-1?this:this.insert(i,r,a)}after(s){let r=Wn(this,dn).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=Wn(this,dn).indexOf(s);return i===-1?this:this.insert(i+1,r,a)}first(){return this.entryAt(0)}last(){return this.entryAt(-1)}clear(){return lp(this,dn,[]),super.clear()}delete(s){const r=super.delete(s);return r&&Wn(this,dn).splice(Wn(this,dn).indexOf(s),1),r}deleteAt(s){const r=this.keyAt(s);return r!==void 0?this.delete(r):!1}at(s){const r=dh(Wn(this,dn),s);if(r!==void 0)return this.get(r)}entryAt(s){const r=dh(Wn(this,dn),s);if(r!==void 0)return[r,this.get(r)]}indexOf(s){return Wn(this,dn).indexOf(s)}keyAt(s){return dh(Wn(this,dn),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 Cs(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 Cs(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 Cs(r)}toReversed(){const s=new Cs;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 Cs(r)}slice(s,r){const a=new Cs;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}},dn=new WeakMap,En(Cs,"OrderedDict"),Cs);function dh(e,n){if("at"in Array.prototype)return Array.prototype.at.call(e,n);const s=k$(e,n);return s===-1?void 0:e[s]}En(dh,"at");function k$(e,n){const s=e.length,r=Bw(n),a=r>=0?r:s+r;return a<0||a>=s?-1:a}En(k$,"toSafeIndex");function Bw(e){return e!==e||e===0?0:Math.trunc(e)}En(Bw,"toSafeInteger");function m_(e){const n=e+"CollectionProvider",[s,r]=Sr(n),[a,i]=s(n,{collectionElement:null,collectionRef:{current:null},collectionRefObject:{current:null},itemMap:new Mp,setItemMap:En(()=>{},"setItemMap")}),l=En(({state:w,...N})=>w?t.jsx(c,{...N,state:w}):t.jsx(o,{...N}),"CollectionProvider");l.displayName=n;const o=En(w=>{const N=k();return t.jsx(c,{...w,state:N})},"CollectionInit");o.displayName=n+"Init";const c=En(w=>{const{scope:N,children:y,state:b}=w,S=d.useRef(null),[C,A]=d.useState(null),$=It(S,A),[I,P]=b;return d.useEffect(()=>{if(!C)return;const O=C$(()=>{});return O.observe(C,{childList:!0,subtree:!0}),()=>{O.disconnect()}},[C]),t.jsx(a,{scope:N,itemMap:I,setItemMap:P,collectionRef:$,collectionRefObject:S,collectionElement:C,children:y})},"CollectionProviderImpl");c.displayName=n+"Impl";const u=e+"CollectionSlot",h=ti(u),f=d.forwardRef((w,N)=>{const{scope:y,children:b}=w,S=i(u,y),C=It(N,S.collectionRef);return t.jsx(h,{ref:C,children:b})});f.displayName=u;const m=e+"CollectionItemSlot",p="data-radix-collection-item",v=ti(m),g=d.forwardRef((w,N)=>{const{scope:y,children:b,...S}=w,C=d.useRef(null),[A,$]=d.useState(null),I=It(N,C,$),P=i(m,y),{setItemMap:O}=P,R=d.useRef(S);N$(R.current,S)||(R.current=S);const D=R.current;return d.useEffect(()=>{const U=D;return O(W=>A?W.has(A)?W.set(A,{...U,element:A}).toSorted(Kx):(W.set(A,{...U,element:A}),W.toSorted(Kx)):W),()=>{O(W=>!A||!W.has(A)?W:(W.delete(A),new Mp(W)))}},[A,D,O]),t.jsx(v,{[p]:"",ref:I,children:b})});g.displayName=m;function k(){return d.useState(new Mp)}En(k,"useInitCollection");function j(w){const{itemMap:N}=i(e+"CollectionConsumer",w);return N}return En(j,"useCollection"),[{Provider:l,Slot:f,ItemSlot:g},{createCollectionScope:r,useCollection:j,useInitCollection:k}]}En(m_,"createCollection");function N$(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}En(N$,"shallowEqual");function S$(e,n){return!!(n.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_PRECEDING)}En(S$,"isElementPreceding");function Kx(e,n){return!e[1].element||!n[1].element?0:S$(e[1].element,n[1].element)?-1:1}En(Kx,"sortByDocumentPosition");function C$(e){return new MutationObserver(s=>{for(const r of s)if(r.type==="childList"){e();return}})}En(C$,"getChildListObserver");var p_=Object.defineProperty,g_=(e,n)=>p_(e,"name",{value:n,configurable:!0}),x_=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],St=x_.reduce((e,n)=>{const s=ti(`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 am(e,n){e&&Ao.flushSync(()=>e.dispatchEvent(n))}g_(am,"dispatchDiscreteCustomEvent");var v_=Object.defineProperty,j_=(e,n)=>v_(e,"name",{value:n,configurable:!0});function is(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)},[])}j_(is,"useCallbackRef");var w_=Object.defineProperty,wn=(e,n)=>w_(e,"name",{value:n,configurable:!0}),Vx="dismissableLayer.update",y_="dismissableLayer.pointerDownOutside",b_="dismissableLayer.focusOutside",eN,Ww=d.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),im=d.forwardRef(wn(function(n,s){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:a=!1,onEscapeKeyDown:i,onPointerDownOutside:l,onFocusOutside:o,onInteractOutside:c,onDismiss:u,...h}=n,f=d.useContext(Ww),[m,p]=d.useState(null),v=(m==null?void 0:m.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,g]=d.useState({}),k=It(s,p),j=Array.from(f.layers),[x]=[...f.layersWithOutsidePointerEventsDisabled].slice(-1),w=x?j.indexOf(x):-1,N=m?j.indexOf(m):-1,y=f.layersWithOutsidePointerEventsDisabled.size>0,b=N>=w,S=d.useRef(!1),C=A$(P=>{l==null||l(P),c==null||c(P),P.defaultPrevented||u==null||u()},{ownerDocument:v,deferPointerDownOutside:a,isDeferredPointerDownOutsideRef:S,dismissableSurfaces:f.dismissableSurfaces,shouldHandlePointerDownOutside:d.useCallback(P=>{if(!(P instanceof Node))return!1;const O=[...f.branches].some(R=>R.contains(P));return b&&!O},[f.branches,b])}),A=$$(P=>{if(a&&S.current)return;const O=P.target;[...f.branches].some(D=>D.contains(O))||(o==null||o(P),c==null||c(P),P.defaultPrevented||u==null||u())},v),$=m?N===j.length-1:!1,I=is(P=>{P.key==="Escape"&&(i==null||i(P),!P.defaultPrevented&&u&&(P.preventDefault(),u()))});return d.useEffect(()=>{if($)return v.addEventListener("keydown",I,{capture:!0}),()=>v.removeEventListener("keydown",I,{capture:!0})},[v,$,I]),d.useEffect(()=>{if(m)return r&&(f.layersWithOutsidePointerEventsDisabled.size===0&&(eN=v.body.style.pointerEvents,v.body.style.pointerEvents="none"),f.layersWithOutsidePointerEventsDisabled.add(m)),f.layers.add(m),Gx(),()=>{r&&(f.layersWithOutsidePointerEventsDisabled.delete(m),f.layersWithOutsidePointerEventsDisabled.size===0&&(v.body.style.pointerEvents=eN))}},[m,v,r,f]),d.useEffect(()=>()=>{m&&(f.layers.delete(m),f.layersWithOutsidePointerEventsDisabled.delete(m),Gx())},[m,f]),d.useEffect(()=>{const P=wn(()=>g({}),"handleUpdate");return document.addEventListener(Vx,P),()=>document.removeEventListener(Vx,P)},[]),t.jsx(St.div,{...h,ref:k,style:{pointerEvents:y?b?"auto":"none":void 0,...n.style},onFocusCapture:He(n.onFocusCapture,A.onFocusCapture),onBlurCapture:He(n.onBlurCapture,A.onBlurCapture),onPointerDownCapture:He(n.onPointerDownCapture,C.onPointerDownCapture)})},"DismissableLayer")),k_=d.forwardRef(wn(function(n,s){const r=d.useContext(Ww),a=d.useRef(null),i=It(s,a);return d.useEffect(()=>{const l=a.current;if(l)return r.branches.add(l),()=>{r.branches.delete(l)}},[r.branches]),t.jsx(St.div,{...n,ref:i})},"DismissableLayerBranch"));function E$(){const e=d.useContext(Ww),[n,s]=d.useState(null);return d.useEffect(()=>{if(n)return e.dismissableSurfaces.add(n),()=>{e.dismissableSurfaces.delete(n)}},[n,e.dismissableSurfaces]),s}wn(E$,"useDismissableLayerSurface");var N_=wn(()=>!0,"IS_TRUE");function A$(e,n){const{ownerDocument:s=globalThis==null?void 0:globalThis.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:a,dismissableSurfaces:i,shouldHandlePointerDownOutside:l=N_}=n,o=is(e),c=d.useRef(!1),u=d.useRef(!1),h=d.useRef(new Map),f=d.useRef(()=>{});return d.useEffect(()=>{function m(){u.current=!1,a.current=!1,h.current.clear()}wn(m,"resetOutsideInteraction");function p(){return Array.from(h.current.values()).some(Boolean)}wn(p,"isOutsideInteractionIntercepted");function v(w){if(!u.current)return;const N=w.target;N instanceof Node&&[...i].some(b=>b.contains(N))||h.current.set(w.type,!0),w.type==="click"&&window.setTimeout(()=>{u.current&&f.current()},0)}wn(v,"handleInteractionCapture");function g(w){u.current&&h.current.set(w.type,!1)}wn(g,"handleInteractionBubble");const k=wn(w=>{if(w.target&&!c.current){let N=function(){s.removeEventListener("click",f.current);const b=p();m(),b||Hw(y_,o,y,{discrete:!0})};if(wn(N,"handleAndDispatchPointerDownOutsideEvent"),!l(w.target)){s.removeEventListener("click",f.current),m(),c.current=!1;return}const y={originalEvent:w};u.current=!0,a.current=r&&w.button===0,h.current.clear(),!r||w.button!==0?N():(s.removeEventListener("click",f.current),f.current=N,s.addEventListener("click",f.current,{once:!0}))}else s.removeEventListener("click",f.current),m();c.current=!1},"handlePointerDown"),j=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const w of j)s.addEventListener(w,v,!0),s.addEventListener(w,g);const x=window.setTimeout(()=>{s.addEventListener("pointerdown",k)},0);return()=>{window.clearTimeout(x),s.removeEventListener("pointerdown",k),s.removeEventListener("click",f.current);for(const w of j)s.removeEventListener(w,v,!0),s.removeEventListener(w,g)}},[s,o,r,a,i,l]),{onPointerDownCapture:wn(()=>c.current=!0,"onPointerDownCapture")}}wn(A$,"usePointerDownOutside");function $$(e,n=globalThis==null?void 0:globalThis.document){const s=is(e),r=d.useRef(!1);return d.useEffect(()=>{const a=wn(i=>{i.target&&!r.current&&Hw(b_,s,{originalEvent:i},{discrete:!1})},"handleFocus");return n.addEventListener("focusin",a),()=>n.removeEventListener("focusin",a)},[n,s]),{onFocusCapture:wn(()=>r.current=!0,"onFocusCapture"),onBlurCapture:wn(()=>r.current=!1,"onBlurCapture")}}wn($$,"useFocusOutside");function Gx(){const e=new CustomEvent(Vx);document.dispatchEvent(e)}wn(Gx,"dispatchUpdate");function Hw(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?am(a,i):a.dispatchEvent(i)}wn(Hw,"handleAndDispatchCustomEvent");var S_=im,C_=k_,ws=globalThis!=null&&globalThis.document?d.useLayoutEffect:()=>{},E_=Object.defineProperty,A_=(e,n)=>E_(e,"name",{value:n,configurable:!0}),lm=d.forwardRef(A_(function(n,s){var c;const{container:r,...a}=n,[i,l]=d.useState(!1);ws(()=>l(!0),[]);const o=r||i&&((c=globalThis==null?void 0:globalThis.document)==null?void 0:c.body);return o?Ao.createPortal(t.jsx(St.div,{...a,ref:s}),o):null},"Portal")),$_=Object.defineProperty,wa=(e,n)=>$_(e,"name",{value:n,configurable:!0});function T$(e,n){return d.useReducer((s,r)=>n[s][r]??s,e)}wa(T$,"useStateMachine");var Jr=wa(e=>{const{present:n,children:s}=e,r=I$(n),a=typeof s=="function"?s({present:r.isPresent}):d.Children.only(s),i=R$(r.ref,P$(a));return typeof s=="function"||r.isPresent?d.cloneElement(a,{ref:i}):null},"Presence");function I$(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]=T$(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??Al(r.current),l.current=void 0):i.current="none"},[c]),ws(()=>{const h=r.current,f=a.current;if(f!==e){const p=i.current,v=Al(h);e?(l.current=v,u("MOUNT")):v==="none"||(h==null?void 0:h.display)==="none"?u("UNMOUNT"):u(f&&p!==v?"ANIMATION_OUT":"UNMOUNT"),a.current=e}},[e,u]),ws(()=>{if(n){let h;const f=n.ownerDocument.defaultView??window,m=wa(v=>{const k=Al(r.current).includes(CSS.escape(v.animationName));if(v.target===n&&k&&(u("ANIMATION_END"),!a.current)){const j=n.style.animationFillMode;n.style.animationFillMode="forwards",h=f.setTimeout(()=>{n.style.animationFillMode==="forwards"&&(n.style.animationFillMode=j)})}},"handleAnimationEnd"),p=wa(v=>{v.target===n&&(i.current=Al(r.current))},"handleAnimationStart");return n.addEventListener("animationstart",p),n.addEventListener("animationcancel",m),n.addEventListener("animationend",m),()=>{f.clearTimeout(h),n.removeEventListener("animationstart",p),n.removeEventListener("animationcancel",m),n.removeEventListener("animationend",m)}}else u("ANIMATION_END")},[n,u]),{isPresent:["mounted","unmountSuspended"].includes(c),ref:d.useCallback(h=>{if(h){const f=getComputedStyle(h);r.current=f,l.current=Al(f)}else r.current=null;s(h)},[])}}wa(I$,"usePresence");function Yx(e,n){if(typeof e=="function")return e(n);e!=null&&(e.current=n)}wa(Yx,"setRef");function R$(...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=Yx(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():Yx(r[l],null)}}},[])}wa(R$,"useStableComposedRefs");function Al(e){return(e==null?void 0:e.animationName)||"none"}wa(Al,"getAnimationName");function P$(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)}wa(P$,"getElementRef");var T_=Object.defineProperty,I_=(e,n)=>T_(e,"name",{value:n,configurable:!0}),tN=So[" useEffectEvent ".trim().toString()],nN=So[" useInsertionEffect ".trim().toString()];function M$(e){if(typeof tN=="function")return tN(e);const n=d.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof nN=="function"?nN(()=>{n.current=e}):ws(()=>{n.current=e}),d.useMemo(()=>(...s)=>{var r;return(r=n.current)==null?void 0:r.call(n,...s)},[])}I_(M$,"useEffectEvent");var R_=Object.defineProperty,_u=(e,n)=>R_(e,"name",{value:n,configurable:!0}),P_=So[" useInsertionEffect ".trim().toString()]||ws;function mi({prop:e,defaultProp:n,onChange:s=_u(()=>{},"onChange"),caller:r}){const[a,i,l]=O$({defaultProp:n,onChange:s}),o=e!==void 0,c=o?e:a,u=d.useCallback(h=>{var f;if(o){const m=D$(h)?h(e):h;m!==e&&((f=l.current)==null||f.call(l,m))}else i(h)},[o,e,i,l]);return[c,u]}_u(mi,"useControllableState");function O$({defaultProp:e,onChange:n}){const[s,r]=d.useState(e),a=d.useRef(s),i=d.useRef(n);return P_(()=>{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]}_u(O$,"useUncontrolledState");function D$(e){return typeof e=="function"}_u(D$,"isFunction");var sN=Symbol("RADIX:SYNC_STATE");function M_(e,n,s,r){const{prop:a,defaultProp:i,onChange:l,caller:o}=n,c=a!==void 0,u=M$(l),h=[{...s,state:i}];r&&h.push(r);const[f,m]=d.useReducer((k,j)=>{if(j.type===sN)return{...k,state:j.state};const x=e(k,j);return c&&!Object.is(x.state,k.state)&&u(x.state),x},...h),p=f.state,v=d.useRef(p);d.useEffect(()=>{v.current!==p&&(v.current=p,c||u(p))},[p,v,c]);const g=d.useMemo(()=>a!==void 0?{...f,state:a}:f,[f,a]);return d.useEffect(()=>{c&&!Object.is(a,f.state)&&m({type:sN,state:a})},[a,f.state,c]),[g,m]}_u(M_,"useControllableStateReducer");var O_=Object.defineProperty,D_=(e,n)=>O_(e,"name",{value:n,configurable:!0}),L_=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"}),Kw=d.forwardRef(D_(function(n,s){return t.jsx(St.span,{...n,ref:s,style:{...L_,...n.style}})},"VisuallyHidden")),F_=Kw,__=Object.defineProperty,$t=(e,n)=>__(e,"name",{value:n,configurable:!0}),L$="ToastProvider",[Vw,F$,z_]=rm("Toast"),[_$,yoe]=Sr("Toast",[z_]),[U_,om]=_$(L$),B_=$t(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,f]=d.useState(0),m=d.useRef(!1);return s.trim()||console.error(`Invalid prop \`label\` supplied to \`${L$}\`. Expected non-empty \`string\`.`),t.jsx(Vw.Provider,{scope:n,children:t.jsx(U_,{scope:n,label:s,duration:r,swipeDirection:a,swipeThreshold:i,toastCount:h,viewport:c,onViewportChange:u,onToastAdd:d.useCallback(()=>f(p=>p+1),[]),onToastRemove:d.useCallback(()=>f(p=>p-1),[]),isClosePausedRef:m,announcerContainer:l,children:o})})},"ToastProvider"),W_="ToastViewport",H_=["F8"],qx="toast.viewportPause",Qx="toast.viewportResume",K_=d.forwardRef($t(function(n,s){const{__scopeToast:r,hotkey:a=H_,label:i="Notifications ({hotkey})",...l}=n,o=om(W_,r),c=F$(r),u=d.useRef(null),h=d.useRef(null),f=d.useRef(null),m=d.useRef(null),p=It(s,m,o.onViewportChange),v=a.join("+").replace(/Key/g,"").replace(/Digit/g,""),g=o.toastCount>0;d.useEffect(()=>{const j=$t(x=>{var N;a.length!==0&&a.every(y=>x[y]||x.code===y)&&((N=m.current)==null||N.focus())},"handleKeyDown");return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[a]),d.useEffect(()=>{const j=u.current,x=m.current;if(g&&j&&x){const w=$t(()=>{if(!o.isClosePausedRef.current){const S=new CustomEvent(qx);x.dispatchEvent(S),o.isClosePausedRef.current=!0}},"handlePause"),N=$t(()=>{if(o.isClosePausedRef.current){const S=new CustomEvent(Qx);x.dispatchEvent(S),o.isClosePausedRef.current=!1}},"handleResume"),y=$t(S=>{!j.contains(S.relatedTarget)&&N()},"handleFocusOutResume"),b=$t(()=>{j.contains(document.activeElement)||N()},"handlePointerLeaveResume");return j.addEventListener("focusin",w),j.addEventListener("focusout",y),j.addEventListener("pointermove",w),j.addEventListener("pointerleave",b),window.addEventListener("blur",w),window.addEventListener("focus",N),()=>{j.removeEventListener("focusin",w),j.removeEventListener("focusout",y),j.removeEventListener("pointermove",w),j.removeEventListener("pointerleave",b),window.removeEventListener("blur",w),window.removeEventListener("focus",N)}}},[g,o.isClosePausedRef]);const k=d.useCallback(({tabbingDirection:j})=>{const w=c().map(N=>{const y=N.ref.current,b=[y,...W$(y)];return j==="forwards"?b:b.reverse()});return(j==="forwards"?w.reverse():w).flat()},[c]);return d.useEffect(()=>{const j=m.current;if(j){const x=$t(w=>{var b,S,C;const N=w.altKey||w.ctrlKey||w.metaKey;if(w.key==="Tab"&&!N){const A=document.activeElement,$=w.shiftKey;if(w.target===j&&$){(b=h.current)==null||b.focus();return}const O=k({tabbingDirection:$?"backwards":"forwards"}),R=O.findIndex(D=>D===A);hh(O.slice(R+1))?w.preventDefault():$?(S=h.current)==null||S.focus():(C=f.current)==null||C.focus()}},"handleKeyDown");return j.addEventListener("keydown",x),()=>j.removeEventListener("keydown",x)}},[c,k]),t.jsxs(C_,{ref:u,role:"region","aria-label":i.replace("{hotkey}",v),tabIndex:-1,style:{pointerEvents:g?void 0:"none"},children:[g&&t.jsx(rN,{ref:h,onFocusFromOutsideViewport:()=>{const j=k({tabbingDirection:"forwards"});hh(j)}}),t.jsx(Vw.Slot,{scope:r,children:t.jsx(St.ol,{tabIndex:-1,...l,ref:p})}),g&&t.jsx(rN,{ref:f,onFocusFromOutsideViewport:()=>{const j=k({tabbingDirection:"backwards"});hh(j)}})]})},"ToastViewport")),V_="ToastFocusProxy",rN=d.forwardRef($t(function(n,s){const{__scopeToast:r,onFocusFromOutsideViewport:a,...i}=n,l=om(V_,r);return t.jsx(Kw,{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")),cm="Toast",G_="toast.swipeStart",Y_="toast.swipeMove",q_="toast.swipeCancel",Q_="toast.swipeEnd",J_=d.forwardRef($t(function(n,s){const{forceMount:r,open:a,defaultOpen:i,onOpenChange:l,...o}=n,[c,u]=mi({prop:a,defaultProp:i??!0,onChange:l,caller:cm});return t.jsx(Jr,{present:r||c,children:t.jsx(e4,{open:c,...o,ref:s,onClose:()=>u(!1),onPause:is(n.onPause),onResume:is(n.onResume),onSwipeStart:He(n.onSwipeStart,h=>{h.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:He(n.onSwipeMove,h=>{const{x:f,y:m}=h.detail.delta;h.currentTarget.setAttribute("data-swipe","move"),h.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${f}px`),h.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${m}px`)}),onSwipeCancel:He(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:He(n.onSwipeEnd,h=>{const{x:f,y:m}=h.detail.delta;h.currentTarget.setAttribute("data-swipe","end"),h.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),h.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),h.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${f}px`),h.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${m}px`),u(!1)})})})},"Toast")),[X_,Z_]=_$(cm,{onClose(){}}),e4=d.forwardRef($t(function(n,s){const{__scopeToast:r,type:a="foreground",duration:i,open:l,onClose:o,onEscapeKeyDown:c,onPause:u,onResume:h,onSwipeStart:f,onSwipeMove:m,onSwipeCancel:p,onSwipeEnd:v,...g}=n,k=om(cm,r),j=F$(r),[x,w]=d.useState(null),N=It(s,w),y=d.useRef(null),b=d.useRef(null),S=i||k.duration,C=d.useRef(0),A=d.useRef(S),$=d.useRef(0),{onToastAdd:I,onToastRemove:P}=k,O=is(()=>{var W;(x==null?void 0:x.contains(document.activeElement))&&((W=k.viewport)==null||W.focus()),o()}),R=d.useCallback(U=>{!U||U===1/0||(window.clearTimeout($.current),C.current=new Date().getTime(),$.current=window.setTimeout(O,U))},[O]);d.useEffect(()=>{const U=k.viewport;if(U){const W=$t(()=>{R(A.current),h==null||h()},"handleResume"),M=$t(()=>{const L=new Date().getTime()-C.current;A.current=A.current-L,window.clearTimeout($.current),u==null||u()},"handlePause");return U.addEventListener(qx,M),U.addEventListener(Qx,W),()=>{U.removeEventListener(qx,M),U.removeEventListener(Qx,W)}}},[k.viewport,S,u,h,R]),d.useEffect(()=>{l&&!k.isClosePausedRef.current&&R(S)},[l,S,k.isClosePausedRef,R]),d.useEffect(()=>()=>{window.clearTimeout($.current)},[]),d.useEffect(()=>(I(),()=>P()),[I,P]);const D=d.useMemo(()=>x?Gw(x):null,[x]);return k.viewport?t.jsxs(t.Fragment,{children:[D&&t.jsx(t4,{__scopeToast:r,role:"status","aria-live":a==="foreground"?"assertive":"polite",children:D}),t.jsx(X_,{scope:r,onClose:O,children:Ao.createPortal(t.jsx(Vw.ItemSlot,{scope:r,children:t.jsx(S_,{asChild:!0,onEscapeKeyDown:He(c,U=>{j().some(M=>{var L;return(L=M.ref.current)==null?void 0:L.contains(U.target)})||O()}),children:t.jsx(St.li,{tabIndex:0,"data-state":l?"open":"closed","data-swipe-direction":k.swipeDirection,...g,ref:N,style:{userSelect:"none",touchAction:"none",...n.style},onKeyDown:He(n.onKeyDown,U=>{U.key==="Escape"&&(c==null||c(U.nativeEvent),U.nativeEvent.defaultPrevented||O())}),onPointerDown:He(n.onPointerDown,U=>{U.button===0&&(y.current={x:U.clientX,y:U.clientY})}),onPointerMove:He(n.onPointerMove,U=>{if(!y.current)return;const W=U.clientX-y.current.x,M=U.clientY-y.current.y,L=!!b.current,_=["left","right"].includes(k.swipeDirection),Y=["left","up"].includes(k.swipeDirection)?Math.min:Math.max,B=_?Y(0,W):0,se=_?0:Y(0,M),G=U.pointerType==="touch"?10:2,X={x:B,y:se},K={originalEvent:U,delta:X};L?(b.current=X,jc(Y_,m,K,{discrete:!1})):aN(X,k.swipeDirection,G)?(b.current=X,jc(G_,f,K,{discrete:!1}),U.target.setPointerCapture(U.pointerId)):(Math.abs(W)>G||Math.abs(M)>G)&&(y.current=null)}),onPointerUp:He(n.onPointerUp,U=>{const W=b.current,M=U.target;if(M.hasPointerCapture(U.pointerId)&&M.releasePointerCapture(U.pointerId),b.current=null,y.current=null,W){const L=U.currentTarget,_={originalEvent:U,delta:W};aN(W,k.swipeDirection,k.swipeThreshold)?jc(Q_,v,_,{discrete:!0}):jc(q_,p,_,{discrete:!0}),L.addEventListener("click",Y=>Y.preventDefault(),{once:!0})}})})})}),k.viewport)})]}):null},"ToastImpl")),t4=$t(e=>{const{__scopeToast:n,children:s,...r}=e,a=om(cm,n),[i,l]=d.useState(!1),[o,c]=d.useState(!1);return U$(()=>l(!0)),d.useEffect(()=>{const u=window.setTimeout(()=>c(!0),1e3);return()=>window.clearTimeout(u)},[]),o?null:t.jsx(lm,{asChild:!0,container:a.announcerContainer||void 0,children:t.jsx(Kw,{...r,children:i&&t.jsxs(t.Fragment,{children:[a.label," ",s]})})})},"ToastAnnounce"),n4=d.forwardRef($t(function(n,s){const{__scopeToast:r,...a}=n;return t.jsx(St.div,{...a,ref:s})},"ToastTitle")),s4=d.forwardRef($t(function(n,s){const{__scopeToast:r,...a}=n;return t.jsx(St.div,{...a,ref:s})},"ToastDescription")),r4="ToastAction",a4=d.forwardRef($t(function(n,s){const{altText:r,...a}=n;return r.trim()?t.jsx(z$,{altText:r,asChild:!0,children:t.jsx(l4,{...a,ref:s})}):(console.error(`Invalid prop \`altText\` supplied to \`${r4}\`. Expected non-empty \`string\`.`),null)},"ToastAction")),i4="ToastClose",l4=d.forwardRef($t(function(n,s){const{__scopeToast:r,...a}=n,i=Z_(i4,r);return t.jsx(z$,{asChild:!0,children:t.jsx(St.button,{type:"button",...a,ref:s,onClick:He(n.onClick,i.onClose)})})},"ToastClose")),z$=d.forwardRef($t(function(n,s){const{__scopeToast:r,altText:a,...i}=n;return t.jsx(St.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":a||void 0,...i,ref:s})},"ToastAnnounceExclude"));function Gw(e){const n=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&n.push(r.textContent),B$(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(...Gw(r))}}),n}$t(Gw,"getAnnounceTextContent");function jc(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?am(a,i):a.dispatchEvent(i)}$t(jc,"handleAndDispatchCustomEvent");var aN=$t((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 U$(e=()=>{}){const n=is(e);ws(()=>{let s=0,r=0;return s=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(n)),()=>{window.cancelAnimationFrame(s),window.cancelAnimationFrame(r)}},[n])}$t(U$,"useNextFrame");function B$(e){return e.nodeType===e.ELEMENT_NODE}$t(B$,"isHTMLElement");function W$(e){const n=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:$t(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}$t(W$,"getTabbableCandidates");function hh(e){const n=document.activeElement;return e.some(s=>s===n?!0:(s.focus(),document.activeElement!==n))}$t(hh,"focusFirst");var iN=B_,lN=K_,o4=J_,c4=n4,u4=s4,d4=a4,h4=Object.defineProperty,f4=(e,n)=>h4(e,"name",{value:n,configurable:!0}),m4=So[" useId ".trim().toString()]||(()=>{}),p4=0;function mr(e){const[n,s]=d.useState(m4());return ws(()=>{e||s(r=>r??String(p4++))},[e]),e||(n?`radix-${n}`:"")}f4(mr,"useId");const g4=["top","right","bottom","left"],ni=Math.min,fa=Math.max,Zh=Math.round,Sd=Math.floor,ma=e=>({x:e,y:e}),x4={left:"right",right:"left",bottom:"top",top:"bottom"};function H$(e,n,s){return fa(e,ni(n,s))}function ya(e,n){return typeof e=="function"?e(n):e}function si(e){return e.split("-")[0]}function To(e){return e.split("-")[1]}function Yw(e){return e==="x"?"y":"x"}function qw(e){return e==="y"?"height":"width"}function Fr(e){const n=e[0];return n==="t"||n==="b"?"y":"x"}function Qw(e){return Yw(Fr(e))}function v4(e,n,s){s===void 0&&(s=!1);const r=To(e),a=Qw(e),i=qw(a);let l=a==="x"?r===(s?"end":"start")?"right":"left":r==="start"?"bottom":"top";return n.reference[i]>n.floating[i]&&(l=ef(l)),[l,ef(l)]}function j4(e){const n=ef(e);return[Jx(e),n,Jx(n)]}function Jx(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const oN=["left","right"],cN=["right","left"],w4=["top","bottom"],y4=["bottom","top"];function b4(e,n,s){switch(e){case"top":case"bottom":return s?n?cN:oN:n?oN:cN;case"left":case"right":return n?w4:y4;default:return[]}}function k4(e,n,s,r){const a=To(e);let i=b4(si(e),s==="start",r);return a&&(i=i.map(l=>l+"-"+a),n&&(i=i.concat(i.map(Jx)))),i}function ef(e){const n=si(e);return x4[n]+e.slice(n.length)}function N4(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 K$(e){return typeof e!="number"?N4(e):{top:e,right:e,bottom:e,left:e}}function tf(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 uN(e,n,s){let{reference:r,floating:a}=e;const i=Fr(n),l=Qw(n),o=qw(l),c=si(n),u=i==="y",h=r.x+r.width/2-a.width/2,f=r.y+r.height/2-a.height/2,m=r[o]/2-a[o]/2;let p;switch(c){case"top":p={x: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:f};break;case"left":p={x:r.x-a.width,y:f};break;default:p={x:r.x,y:r.y}}const v=To(n);return v&&(p[l]+=m*(v==="end"?1:-1)*(s&&u?-1:1)),p}async function S4(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:f="floating",altBoundary:m=!1,padding:p=0}=ya(n,e),v=K$(p),k=o[m?f==="floating"?"reference":"floating":f],j=tf(await i.getClippingRect({element:(s=await(i.isElement==null?void 0:i.isElement(k)))==null||s?k:k.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:u,rootBoundary:h,strategy:c})),x=f==="floating"?{x:r,y:a,width:l.floating.width,height:l.floating.height}:l.reference,w=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),N=await(i.isElement==null?void 0:i.isElement(w))&&await(i.getScale==null?void 0:i.getScale(w))||{x:1,y:1},y=tf(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:x,offsetParent:w,strategy:c}):x);return{top:(j.top-y.top+v.top)/N.y,bottom:(y.bottom-j.bottom+v.bottom)/N.y,left:(j.left-y.left+v.left)/N.x,right:(y.right-j.right+v.right)/N.x}}const C4=50,E4=async(e,n,s)=>{const{placement:r="bottom",strategy:a="absolute",middleware:i=[],platform:l}=s,o=l.detectOverflow?l:{...l,detectOverflow:S4},c=await(l.isRTL==null?void 0:l.isRTL(n));let u=await l.getElementRects({reference:e,floating:n,strategy:a}),{x:h,y:f}=uN(u,r,c),m=r,p=0;const v={};for(let g=0;g<i.length;g++){const k=i[g];if(!k)continue;const{name:j,fn:x}=k,{x:w,y:N,data:y,reset:b}=await x({x:h,y:f,initialPlacement:r,placement:m,strategy:a,middlewareData:v,rects:u,platform:o,elements:{reference:e,floating:n}});h=w??h,f=N??f,v[j]={...v[j],...y},b&&p<C4&&(p++,typeof b=="object"&&(b.placement&&(m=b.placement),b.rects&&(u=b.rects===!0?await l.getElementRects({reference:e,floating:n,strategy:a}):b.rects),{x:h,y:f}=uN(u,m,c)),g=-1)}return{x:h,y:f,placement:m,strategy:a,middlewareData:v}},A4=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}=ya(e,n)||{};if(u==null)return{};const f=K$(h),m={x:s,y:r},p=Qw(a),v=qw(p),g=await l.getDimensions(u),k=p==="y",j=k?"top":"left",x=k?"bottom":"right",w=k?"clientHeight":"clientWidth",N=i.reference[v]+i.reference[p]-m[p]-i.floating[v],y=m[p]-i.reference[p],b=await(l.getOffsetParent==null?void 0:l.getOffsetParent(u));let S=b?b[w]:0;(!S||!await(l.isElement==null?void 0:l.isElement(b)))&&(S=o.floating[w]||i.floating[v]);const C=N/2-y/2,A=S/2-g[v]/2-1,$=ni(f[j],A),I=ni(f[x],A),P=S-g[v]-I,O=S/2-g[v]/2+C,R=H$($,O,P),D=!c.arrow&&To(a)!=null&&O!==R&&i.reference[v]/2-(O<$?$:I)-g[v]/2<0,U=D?O<$?O-$:O-P:0;return{[p]:m[p]+U,data:{[p]:R,centerOffset:O-R-U,...D&&{alignmentOffset:U}},reset:D}}}),$4=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:f=!0,fallbackPlacements:m,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:v="none",flipAlignment:g=!0,...k}=ya(e,n);if((s=i.arrow)!=null&&s.alignmentOffset)return{};const j=si(a),x=Fr(o),w=si(o)===o,N=await(c.isRTL==null?void 0:c.isRTL(u.floating)),y=m||(w||!g?[ef(o)]:j4(o)),b=v!=="none";!m&&b&&y.push(...k4(o,g,v,N));const S=[o,...y],C=await c.detectOverflow(n,k),A=[];let $=((r=i.flip)==null?void 0:r.overflows)||[];if(h&&A.push(C[j]),f){const R=v4(a,l,N);A.push(C[R[0]],C[R[1]])}if($=[...$,{placement:a,overflows:A}],!A.every(R=>R<=0)){var I,P;const R=(((I=i.flip)==null?void 0:I.index)||0)+1,D=S[R];if(D&&(!(f==="alignment"?x!==Fr(D):!1)||$.every(M=>Fr(M.placement)===x?M.overflows[0]>0:!0)))return{data:{index:R,overflows:$},reset:{placement:D}};let U=(P=$.filter(W=>W.overflows[0]<=0).sort((W,M)=>W.overflows[1]-M.overflows[1])[0])==null?void 0:P.placement;if(!U)switch(p){case"bestFit":{var O;const W=(O=$.filter(M=>{if(b){const L=Fr(M.placement);return L===x||L==="y"}return!0}).map(M=>[M.placement,M.overflows.filter(L=>L>0).reduce((L,_)=>L+_,0)]).sort((M,L)=>M[1]-L[1])[0])==null?void 0:O[0];W&&(U=W);break}case"initialPlacement":U=o;break}if(a!==U)return{reset:{placement:U}}}return{}}}};function dN(e,n){return{top:e.top-n.height,right:e.right-n.width,bottom:e.bottom-n.height,left:e.left-n.width}}function hN(e){return g4.some(n=>e[n]>=0)}const T4=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(n){const{rects:s,platform:r}=n,{strategy:a="referenceHidden",...i}=ya(e,n);switch(a){case"referenceHidden":{const l=await r.detectOverflow(n,{...i,elementContext:"reference"}),o=dN(l,s.reference);return{data:{referenceHiddenOffsets:o,referenceHidden:hN(o)}}}case"escaped":{const l=await r.detectOverflow(n,{...i,altBoundary:!0}),o=dN(l,s.floating);return{data:{escapedOffsets:o,escaped:hN(o)}}}default:return{}}}}},V$=new Set(["left","top"]);async function I4(e,n){const{placement:s,platform:r,elements:a}=e,i=await(r.isRTL==null?void 0:r.isRTL(a.floating)),l=si(s),o=To(s),c=Fr(s)==="y",u=V$.has(l)?-1:1,h=i&&c?-1:1,f=ya(n,e);let{mainAxis:m,crossAxis:p,alignmentAxis:v}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return o&&typeof v=="number"&&(p=o==="end"?v*-1:v),c?{x:p*h,y:m*u}:{x:m*u,y:p*h}}const R4=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 I4(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}}}}},P4=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(n){const{x:s,y:r,placement:a,platform:i}=n,{mainAxis:l=!0,crossAxis:o=!1,limiter:c={fn:x=>{let{x:w,y:N}=x;return{x:w,y:N}}},...u}=ya(e,n),h={x:s,y:r},f=await i.detectOverflow(n,u),m=Fr(a),p=Yw(m);let v=h[p],g=h[m];const k=(x,w)=>H$(w+f[x==="y"?"top":"left"],w,w-f[x==="y"?"bottom":"right"]);l&&(v=k(p,v)),o&&(g=k(m,g));const j=c.fn({...n,[p]:v,[m]:g});return{...j,data:{x:j.x-s,y:j.y-r,enabled:{[p]:l,[m]:o}}}}}},M4=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:f=!0}=ya(e,n),m={x:a,y:i},p=Fr(l),v=Yw(p);let g=m[v],k=m[p];const j=ya(u,n),x=typeof j=="number"?{mainAxis:j,crossAxis:0}:{mainAxis:(s=j.mainAxis)!=null?s:0,crossAxis:(r=j.crossAxis)!=null?r:0};if(h){const y=v==="y"?"height":"width",b=o.reference[v]-o.floating[y]+x.mainAxis,S=o.reference[v]+o.reference[y]-x.mainAxis;g<b?g=b:g>S&&(g=S)}if(f){var w,N;const y=v==="y"?"width":"height",b=V$.has(si(l)),S=o.reference[p]-o.floating[y]+(b&&((w=c.offset)==null?void 0:w[p])||0)+(b?0:x.crossAxis),C=o.reference[p]+o.reference[y]+(b?0:((N=c.offset)==null?void 0:N[p])||0)-(b?x.crossAxis:0);k<S?k=S:k>C&&(k=C)}return{[v]:g,[p]:k}}}},O4=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}=ya(e,n),c=await a.detectOverflow(n,o),u=si(s),h=To(s),f=Fr(s)==="y",{width:m,height:p}=r.floating;let v,g;u==="top"||u==="bottom"?(v=u,g=h===(await(a.isRTL==null?void 0:a.isRTL(i.floating))?"start":"end")?"left":"right"):(g=u,v=h==="end"?"top":"bottom");const k=p-c.top-c.bottom,j=m-c.left-c.right,x=ni(p-c[v],k),w=ni(m-c[g],j),N=n.middlewareData.shift,y=!N;let b=x,S=w;N!=null&&N.enabled.x&&(S=j),N!=null&&N.enabled.y&&(b=k),y&&!h&&(f?S=m-2*fa(c.left,c.right):b=p-2*fa(c.top,c.bottom)),await l({...n,availableWidth:S,availableHeight:b});const C=await a.getDimensions(i.floating);return m!==C.width||p!==C.height?{reset:{rects:!0}}:{}}}};function um(){return typeof window<"u"}function Io(e){return G$(e)?(e.nodeName||"").toLowerCase():"#document"}function ys(e){var n;return(e==null||(n=e.ownerDocument)==null?void 0:n.defaultView)||window}function Na(e){var n;return(n=(G$(e)?e.ownerDocument:e.document)||window.document)==null?void 0:n.documentElement}function G$(e){return um()?e instanceof Node||e instanceof ys(e).Node:!1}function Vr(e){return um()?e instanceof Element||e instanceof ys(e).Element:!1}function pi(e){return um()?e instanceof HTMLElement||e instanceof ys(e).HTMLElement:!1}function fN(e){return!um()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof ys(e).ShadowRoot}function dm(e){const{overflow:n,overflowX:s,overflowY:r,display:a}=Gr(e);return/auto|scroll|overlay|hidden|clip/.test(n+r+s)&&a!=="inline"&&a!=="contents"}function D4(e){return/^(table|td|th)$/.test(Io(e))}function hm(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const L4=/transform|translate|scale|rotate|perspective|filter/,F4=/paint|layout|strict|content/,Ci=e=>!!e&&e!=="none";let Op;function Jw(e){const n=Vr(e)?Gr(e):e;return Ci(n.transform)||Ci(n.translate)||Ci(n.scale)||Ci(n.rotate)||Ci(n.perspective)||!Xw()&&(Ci(n.backdropFilter)||Ci(n.filter))||L4.test(n.willChange||"")||F4.test(n.contain||"")}function _4(e){let n=qi(e);for(;pi(n)&&!ou(n);){if(Jw(n))return n;if(hm(n))return null;n=qi(n)}return null}function Xw(){return Op==null&&(Op=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Op}function ou(e){return/^(html|body|#document)$/.test(Io(e))}function Gr(e){return ys(e).getComputedStyle(e)}function fm(e){return Vr(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function qi(e){if(Io(e)==="html")return e;const n=e.assignedSlot||e.parentNode||fN(e)&&e.host||Na(e);return fN(n)?n.host:n}function Y$(e){const n=qi(e);return ou(n)?(e.ownerDocument||e).body:pi(n)&&dm(n)?n:Y$(n)}function cu(e,n,s){var r;n===void 0&&(n=[]),s===void 0&&(s=!0);const a=Y$(e),i=a===((r=e.ownerDocument)==null?void 0:r.body),l=ys(a);if(i){const o=Xx(l);return n.concat(l,l.visualViewport||[],dm(a)?a:[],o&&s?cu(o):[])}else return n.concat(a,cu(a,[],s))}function Xx(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function q$(e){const n=Gr(e);let s=parseFloat(n.width)||0,r=parseFloat(n.height)||0;const a=pi(e),i=a?e.offsetWidth:s,l=a?e.offsetHeight:r,o=Zh(s)!==i||Zh(r)!==l;return o&&(s=i,r=l),{width:s,height:r,$:o}}function Zw(e){return Vr(e)?e:e.contextElement}function Ql(e){const n=Zw(e);if(!pi(n))return ma(1);const s=n.getBoundingClientRect(),{width:r,height:a,$:i}=q$(n);let l=(i?Zh(s.width):s.width)/r,o=(i?Zh(s.height):s.height)/a;return(!l||!Number.isFinite(l))&&(l=1),(!o||!Number.isFinite(o))&&(o=1),{x:l,y:o}}const z4=ma(0);function Q$(e){const n=ys(e);return!Xw()||!n.visualViewport?z4:{x:n.visualViewport.offsetLeft,y:n.visualViewport.offsetTop}}function U4(e,n,s){return n===void 0&&(n=!1),!!s&&n&&s===ys(e)}function Qi(e,n,s,r){n===void 0&&(n=!1),s===void 0&&(s=!1);const a=e.getBoundingClientRect(),i=Zw(e);let l=ma(1);n&&(r?Vr(r)&&(l=Ql(r)):l=Ql(e));const o=U4(i,s,r)?Q$(i):ma(0);let c=(a.left+o.x)/l.x,u=(a.top+o.y)/l.y,h=a.width/l.x,f=a.height/l.y;if(i&&r){const m=ys(i),p=Vr(r)?ys(r):r;let v=m,g=Xx(v);for(;g&&p!==v;){const k=Ql(g),j=g.getBoundingClientRect(),x=Gr(g),w=j.left+(g.clientLeft+parseFloat(x.paddingLeft))*k.x,N=j.top+(g.clientTop+parseFloat(x.paddingTop))*k.y;c*=k.x,u*=k.y,h*=k.x,f*=k.y,c+=w,u+=N,v=ys(g),g=Xx(v)}}return tf({width:h,height:f,x:c,y:u})}function mm(e,n){const s=fm(e).scrollLeft;return n?n.left+s:Qi(Na(e)).left+s}function J$(e,n){const s=e.getBoundingClientRect(),r=s.left+n.scrollLeft-mm(e,s),a=s.top+n.scrollTop;return{x:r,y:a}}function B4(e){let{elements:n,rect:s,offsetParent:r,strategy:a}=e;const i=a==="fixed",l=Na(r),o=n?hm(n.floating):!1;if(r===l||o&&i)return s;let c={scrollLeft:0,scrollTop:0},u=ma(1);const h=ma(0),f=pi(r);if((f||!i)&&((Io(r)!=="body"||dm(l))&&(c=fm(r)),f)){const p=Qi(r);u=Ql(r),h.x=p.x+r.clientLeft,h.y=p.y+r.clientTop}const m=l&&!f&&!i?J$(l,c):ma(0);return{width:s.width*u.x,height:s.height*u.y,x:s.x*u.x-c.scrollLeft*u.x+h.x+m.x,y:s.y*u.y-c.scrollTop*u.y+h.y+m.y}}function W4(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function H4(e){const n=fm(e),s=e.ownerDocument.body,r=fa(e.scrollWidth,e.clientWidth,s.scrollWidth,s.clientWidth),a=fa(e.scrollHeight,e.clientHeight,s.scrollHeight,s.clientHeight);let i=-n.scrollLeft+mm(e);const l=-n.scrollTop;return Gr(s).direction==="rtl"&&(i+=fa(e.clientWidth,s.clientWidth)-r),{width:r,height:a,x:i,y:l}}const K4=25;function V4(e,n,s){s===void 0&&(s="viewport");const r=s==="layoutViewport",a=ys(e),i=Na(e),l=a.visualViewport;let o=i.clientWidth,c=i.clientHeight,u=0,h=0;if(l){const m=!Xw()||n==="fixed";r?m||(u=-l.offsetLeft,h=-l.offsetTop):(o=l.width,c=l.height,m&&(u=l.offsetLeft,h=l.offsetTop))}if(mm(i)<=0){const m=i.ownerDocument,p=m.body,v=getComputedStyle(p),g=m.compatMode==="CSS1Compat"&&parseFloat(v.marginLeft)+parseFloat(v.marginRight)||0,k=Math.abs(i.clientWidth-p.clientWidth-g),j=getComputedStyle(i).scrollbarGutter==="stable both-edges"?k/2:k;j<=K4&&(o-=j)}return{width:o,height:c,x:u,y:h}}function G4(e,n){const s=Qi(e,!0,n==="fixed"),r=s.top+e.clientTop,a=s.left+e.clientLeft,i=Ql(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 mN(e,n,s){let r;if(n==="viewport"||n==="layoutViewport")r=V4(e,s,n);else if(n==="document")r=H4(Na(e));else if(Vr(n))r=G4(n,s);else{const a=Q$(e);r={x:n.x-a.x,y:n.y-a.y,width:n.width,height:n.height}}return tf(r)}function Y4(e,n){const s=n.get(e);if(s)return s;let r=cu(e,[],!1).filter(o=>Vr(o)&&Io(o)!=="body"),a=null;const i=Gr(e).position==="fixed";let l=i?qi(e):e;for(;Vr(l)&&!ou(l);){const o=Gr(l),c=Jw(l),u=a?a.position:i?"fixed":"";!c&&(u==="fixed"||u==="absolute"&&o.position==="static")?r=r.filter(f=>f!==l):a=o,l=qi(l)}return n.set(e,r),r}function q4(e){let{element:n,boundary:s,rootBoundary:r,strategy:a}=e;const l=[...s==="clippingAncestors"?hm(n)?[]:Y4(n,this._c):[].concat(s),r],o=mN(n,l[0],a);let c=o.top,u=o.right,h=o.bottom,f=o.left;for(let m=1;m<l.length;m++){const p=mN(n,l[m],a);c=fa(p.top,c),u=ni(p.right,u),h=ni(p.bottom,h),f=fa(p.left,f)}return{width:u-f,height:h-c,x:f,y:c}}function Q4(e){const{width:n,height:s}=q$(e);return{width:n,height:s}}function J4(e,n,s){const r=pi(n),a=Na(n),i=s==="fixed",l=Qi(e,!0,i,n);let o={scrollLeft:0,scrollTop:0};const c=ma(0);if((r||!i)&&((Io(n)!=="body"||dm(a))&&(o=fm(n)),r)){const m=Qi(n,!0,i,n);c.x=m.x+n.clientLeft,c.y=m.y+n.clientTop}!r&&a&&(c.x=mm(a));const u=a&&!r&&!i?J$(a,o):ma(0),h=l.left+o.scrollLeft-c.x-u.x,f=l.top+o.scrollTop-c.y-u.y;return{x:h,y:f,width:l.width,height:l.height}}function Dp(e){return Gr(e).position==="static"}function pN(e,n){if(!pi(e)||Gr(e).position==="fixed")return null;if(n)return n(e);let s=e.offsetParent;return Na(e)===s&&(s=s.ownerDocument.body),s}function X$(e,n){const s=ys(e);if(hm(e))return s;if(!pi(e)){let a=qi(e);for(;a&&!ou(a);){if(Vr(a)&&!Dp(a))return a;a=qi(a)}return s}let r=pN(e,n);for(;r&&D4(r)&&Dp(r);)r=pN(r,n);return r&&ou(r)&&Dp(r)&&!Jw(r)?s:r||_4(e)||s}const X4=async function(e){const n=this.getOffsetParent||X$,s=this.getDimensions,r=await s(e.floating);return{reference:J4(e.reference,await n(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Z4(e){return Gr(e).direction==="rtl"}const ez={convertOffsetParentRelativeRectToViewportRelativeRect:B4,getDocumentElement:Na,getClippingRect:q4,getOffsetParent:X$,getElementRects:X4,getClientRects:W4,getDimensions:Q4,getScale:Ql,isElement:Vr,isRTL:Z4};function Z$(e,n){return e.x===n.x&&e.y===n.y&&e.width===n.width&&e.height===n.height}function tz(e,n,s){let r=null,a;const i=Na(e);function l(){var h;clearTimeout(a),(h=r)==null||h.disconnect(),r=null}function o(h,f){h===void 0&&(h=!1),f===void 0&&(f=1),l();const m=e.getBoundingClientRect(),{left:p,top:v,width:g,height:k}=m;if(h||n(),!g||!k)return;const j=Sd(v),x=Sd(i.clientWidth-(p+g)),w=Sd(i.clientHeight-(v+k)),N=Sd(p),b={rootMargin:-j+"px "+-x+"px "+-w+"px "+-N+"px",threshold:fa(0,ni(1,f))||1};let S=!0;function C(A){const $=A[0].intersectionRatio;if(!Z$(m,e.getBoundingClientRect()))return o();if($!==f){if(!S)return o();$?o(!1,$):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=ys(e),u=()=>o(s);return c.addEventListener("resize",u),o(!0),()=>{c.removeEventListener("resize",u),l()}}function nz(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=Zw(e),h=a||i?[...u?cu(u):[],...n?cu(n):[]]:[];h.forEach(j=>{a&&j.addEventListener("scroll",s),i&&j.addEventListener("resize",s)});const f=u&&o?tz(u,s,i):null;let m=-1,p=null;l&&(p=new ResizeObserver(j=>{let[x]=j;x&&x.target===u&&p&&n&&(p.unobserve(n),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var w;(w=p)==null||w.observe(n)})),s()}),u&&!c&&p.observe(u),n&&p.observe(n));let v,g=c?Qi(e):null;c&&k();function k(){const j=Qi(e);g&&!Z$(g,j)&&s(),g=j,v=requestAnimationFrame(k)}return s(),()=>{var j;h.forEach(x=>{a&&x.removeEventListener("scroll",s),i&&x.removeEventListener("resize",s)}),f==null||f(),(j=p)==null||j.disconnect(),p=null,c&&cancelAnimationFrame(v)}}const sz=R4,rz=P4,az=$4,iz=O4,lz=T4,gN=A4,oz=M4,cz=(e,n,s)=>{const r=new Map,a=s??{},i={...ez,...a.platform,_c:r};return E4(e,n,{...a,platform:i})};var uz=typeof document<"u",dz=function(){},fh=uz?d.useLayoutEffect:dz;function nf(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(!nf(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)&&!nf(e[i],n[i]))return!1}return!0}return e!==e&&n!==n}function eT(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function xN(e,n){const s=eT(e);return Math.round(n*s)/s}function Lp(e){const n=d.useRef(e);return fh(()=>{n.current=e}),n}function hz(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,f]=d.useState({x:0,y:0,strategy:s,placement:n,middlewareData:{},isPositioned:!1}),[m,p]=d.useState(r);nf(m,r)||p(r);const[v,g]=d.useState(null),[k,j]=d.useState(null),x=d.useCallback(M=>{M!==b.current&&(b.current=M,g(M))},[]),w=d.useCallback(M=>{M!==S.current&&(S.current=M,j(M))},[]),N=i||v,y=l||k,b=d.useRef(null),S=d.useRef(null),C=d.useRef(h),A=c!=null,$=Lp(c),I=Lp(a),P=Lp(u),O=d.useCallback(()=>{if(!b.current||!S.current)return;const M={placement:n,strategy:s,middleware:m};I.current&&(M.platform=I.current),cz(b.current,S.current,M).then(L=>{const _={...L,isPositioned:P.current!==!1};R.current&&!nf(C.current,_)&&(C.current=_,Ao.flushSync(()=>{f(_)}))})},[m,n,s,I,P]);fh(()=>{u===!1&&C.current.isPositioned&&(C.current.isPositioned=!1,f(M=>({...M,isPositioned:!1})))},[u]);const R=d.useRef(!1);fh(()=>(R.current=!0,()=>{R.current=!1}),[]),fh(()=>{if(N&&(b.current=N),y&&(S.current=y),N&&y){if($.current)return $.current(N,y,O);O()}},[N,y,O,$,A]);const D=d.useMemo(()=>({reference:b,floating:S,setReference:x,setFloating:w}),[x,w]),U=d.useMemo(()=>({reference:N,floating:y}),[N,y]),W=d.useMemo(()=>{const M={position:s,left:0,top:0};if(!U.floating)return M;const L=xN(U.floating,h.x),_=xN(U.floating,h.y);return o?{...M,transform:"translate("+L+"px, "+_+"px)",...eT(U.floating)>=1.5&&{willChange:"transform"}}:{position:s,left:L,top:_}},[s,o,U.floating,h.x,h.y]);return d.useMemo(()=>({...h,update:O,refs:D,elements:U,floatingStyles:W}),[h,O,D,U,W])}const fz=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?gN({element:r.current,padding:a}).fn(s):{}:r?gN({element:r,padding:a}).fn(s):{}}}},mz=(e,n)=>{const s=sz(e);return{name:s.name,fn:s.fn,options:[e,n]}},pz=(e,n)=>{const s=rz(e);return{name:s.name,fn:s.fn,options:[e,n]}},gz=(e,n)=>({fn:oz(e).fn,options:[e,n]}),xz=(e,n)=>{const s=az(e);return{name:s.name,fn:s.fn,options:[e,n]}},vz=(e,n)=>{const s=iz(e);return{name:s.name,fn:s.fn,options:[e,n]}},jz=(e,n)=>{const s=lz(e);return{name:s.name,fn:s.fn,options:[e,n]}},wz=(e,n)=>{const s=fz(e);return{name:s.name,fn:s.fn,options:[e,n]}};var yz=Object.defineProperty,bz=(e,n)=>yz(e,"name",{value:n,configurable:!0});function tT(e){const[n,s]=d.useState(void 0);return ws(()=>{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}bz(tT,"useSize");var kz=Object.defineProperty,qa=(e,n)=>kz(e,"name",{value:n,configurable:!0}),nT="Popper",[sT,pm]=Sr(nT),[Nz,rT]=sT(nT),Sz=qa(e=>{const{__scopePopper:n,children:s}=e,[r,a]=d.useState(null),[i,l]=d.useState(void 0);return t.jsx(Nz,{scope:n,anchor:r,onAnchorChange:a,placementState:i,setPlacementState:l,children:s})},"Popper"),Cz="PopperAnchor",Ez=d.forwardRef(qa(function(n,s){const{__scopePopper:r,virtualRef:a,...i}=n,l=rT(Cz,r),o=d.useRef(null),c=l.onAnchorChange,u=d.useCallback(g=>{o.current=g,g&&c(g)},[c]),h=It(s,u),f=d.useRef(null);d.useEffect(()=>{if(!a)return;const g=f.current;f.current=a.current,g!==f.current&&c(f.current)});const m=l.placementState&&gm(l.placementState),p=m==null?void 0:m[0],v=m==null?void 0:m[1];return a?null:t.jsx(St.div,{"data-radix-popper-side":p,"data-radix-popper-align":v,...i,ref:h})},"PopperAnchor")),aT="PopperContent",[Az,boe]=sT(aT),$z=d.forwardRef(qa(function(n,s){var ce,xe,Me,H,ne,Z,ye;const{__scopePopper:r,side:a="bottom",sideOffset:i=0,align:l="center",alignOffset:o=0,arrowPadding:c=0,avoidCollisions:u=!0,collisionBoundary:h=[],collisionPadding:f=0,sticky:m="partial",hideWhenDetached:p=!1,updatePositionStrategy:v="optimized",onPlaced:g,...k}=n,j=rT(aT,r),[x,w]=d.useState(null),N=It(s,w),[y,b]=d.useState(null),S=tT(y),C=(S==null?void 0:S.width)??0,A=(S==null?void 0:S.height)??0,$=a+(l!=="center"?"-"+l:""),I=typeof f=="number"?f:{top:0,right:0,bottom:0,left:0,...f},P=Array.isArray(h)?h:[h],O=P.length>0,R={padding:I,boundary:P.filter(iT),altBoundary:O},{refs:D,floatingStyles:U,placement:W,isPositioned:M,middlewareData:L}=hz({strategy:"fixed",placement:$,whileElementsMounted:qa((...Ce)=>nz(...Ce,{animationFrame:v==="always"}),"whileElementsMounted"),elements:{reference:j.anchor},middleware:[mz({mainAxis:i+A,alignmentAxis:o}),u&&pz({mainAxis:!0,crossAxis:!1,limiter:m==="partial"?gz():void 0,...R}),u&&xz({...R}),vz({...R,apply:qa(({elements:Ce,rects:ke,availableWidth:we,availableHeight:ve})=>{const{width:Ie,height:Re}=ke.reference,de=Ce.floating.style;de.setProperty("--radix-popper-available-width",`${we}px`),de.setProperty("--radix-popper-available-height",`${ve}px`),de.setProperty("--radix-popper-anchor-width",`${Ie}px`),de.setProperty("--radix-popper-anchor-height",`${Re}px`)},"apply")}),y&&wz({element:y,padding:c}),Tz({arrowWidth:C,arrowHeight:A}),p&&jz({strategy:"referenceHidden",...R,boundary:O?R.boundary:void 0})]}),_=j.setPlacementState;ws(()=>(_(W),()=>{_(void 0)}),[W,_]);const[Y,B]=gm(W),se=is(g);ws(()=>{M&&(se==null||se())},[M,se]);const G=(ce=L.arrow)==null?void 0:ce.x,X=(xe=L.arrow)==null?void 0:xe.y,K=((Me=L.arrow)==null?void 0:Me.centerOffset)!==0,[J,q]=d.useState();return ws(()=>{x&&q(window.getComputedStyle(x).zIndex)},[x]),t.jsx("div",{ref:D.setFloating,"data-radix-popper-content-wrapper":"",style:{...U,transform:M?U.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:J,"--radix-popper-transform-origin":[(H=L.transformOrigin)==null?void 0:H.x,(ne=L.transformOrigin)==null?void 0:ne.y].join(" "),...((Z=L.hide)==null?void 0:Z.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:n.dir,children:t.jsx(Az,{scope:r,placedSide:Y,placedAlign:B,onArrowChange:b,arrowX:G,arrowY:X,shouldHideArrow:K,children:t.jsx(St.div,{"data-side":Y,"data-align":B,...k,ref:N,style:{...k.style,animation:M?(ye=k.style)==null?void 0:ye.animation:"none"}})})})},"PopperContent"));function iT(e){return e!==null}qa(iT,"isNotNull");var Tz=qa(e=>({name:"transformOrigin",options:e,fn(n){var k,j,x;const{placement:s,rects:r,middlewareData:a}=n,l=((k=a.arrow)==null?void 0:k.centerOffset)!==0,o=l?0:e.arrowWidth,c=l?0:e.arrowHeight,[u,h]=gm(s),f={start:"0%",center:"50%",end:"100%"}[h],m=(((j=a.arrow)==null?void 0:j.x)??0)+o/2,p=(((x=a.arrow)==null?void 0:x.y)??0)+c/2;let v="",g="";return u==="bottom"?(v=l?f:`${m}px`,g=`${-c}px`):u==="top"?(v=l?f:`${m}px`,g=`${r.floating.height+c}px`):u==="right"?(v=`${-c}px`,g=l?f:`${p}px`):u==="left"&&(v=`${r.floating.width+c}px`,g=l?f:`${p}px`),{data:{x:v,y:g}}}}),"transformOrigin");function gm(e){const[n,s="center"]=e.split("-");return[n,s]}qa(gm,"getSideAndAlignFromPlacement");var ey=Sz,lT=Ez,oT=$z,Iz=Object.defineProperty,An=(e,n)=>Iz(e,"name",{value:n,configurable:!0}),[ty,koe]=Sr("Tooltip",[pm]),ny=pm(),Rz="TooltipProvider",Pz=700,Zx="tooltip.open",[Mz,sy]=ty(Rz),Oz=An(e=>{const{__scopeTooltip:n,delayDuration:s=Pz,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(Mz,{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"),ev="Tooltip",[Dz,zu]=ty(ev),Lz=An(e=>{const{__scopeTooltip:n,children:s,open:r,defaultOpen:a,onOpenChange:i,disableHoverableContent:l,delayDuration:o}=e,c=sy(ev,e.__scopeTooltip),u=ny(n),[h,f]=d.useState(null),[m,p]=d.useState(void 0),v=mr(),g=d.useRef(0),k=l??c.disableHoverableContent,j=o??c.delayDuration,x=d.useRef(!1),[w,N]=mi({prop:r,defaultProp:a??!1,onChange:An($=>{$?(c.onOpen(),document.dispatchEvent(new CustomEvent(Zx))):c.onClose(),i==null||i($)},"onChange"),caller:ev}),y=d.useMemo(()=>w?x.current?"delayed-open":"instant-open":"closed",[w]),b=d.useCallback(()=>{window.clearTimeout(g.current),g.current=0,x.current=!1,N(!0)},[N]),S=d.useCallback(()=>{window.clearTimeout(g.current),g.current=0,N(!1)},[N]),C=d.useCallback(()=>{window.clearTimeout(g.current),g.current=window.setTimeout(()=>{x.current=!0,N(!0),g.current=0},j)},[j,N]);d.useEffect(()=>()=>{g.current&&(window.clearTimeout(g.current),g.current=0)},[]);const A=m??v;return t.jsx(ey,{...u,children:t.jsx(Dz,{scope:n,contentId:A,setContentId:p,open:w,stateAttribute:y,trigger:h,onTriggerChange:f,onTriggerEnter:d.useCallback(()=>{c.isOpenDelayedRef.current?C():b()},[c.isOpenDelayedRef,C,b]),onTriggerLeave:d.useCallback(()=>{k?S():(window.clearTimeout(g.current),g.current=0)},[S,k]),onOpen:b,onClose:S,disableHoverableContent:k,children:s})})},"Tooltip"),vN="TooltipTrigger",Fz=d.forwardRef(An(function(n,s){const{__scopeTooltip:r,...a}=n,i=zu(vN,r),l=sy(vN,r),o=ny(r),c=d.useRef(null),u=It(s,c,i.onTriggerChange),h=d.useRef(!1),f=d.useRef(!1),m=d.useCallback(()=>h.current=!1,[]);return d.useEffect(()=>()=>document.removeEventListener("pointerup",m),[m]),t.jsx(lT,{asChild:!0,...o,children:t.jsx(St.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...a,ref:u,onPointerMove:He(n.onPointerMove,p=>{p.pointerType!=="touch"&&!f.current&&!l.isPointerInTransitRef.current&&(i.onTriggerEnter(),f.current=!0)}),onPointerLeave:He(n.onPointerLeave,()=>{i.onTriggerLeave(),f.current=!1}),onPointerDown:He(n.onPointerDown,()=>{i.open&&i.onClose(),h.current=!0,document.addEventListener("pointerup",m,{once:!0})}),onFocus:He(n.onFocus,()=>{h.current||i.onOpen()}),onBlur:He(n.onBlur,i.onClose),onClick:He(n.onClick,i.onClose)})})},"TooltipTrigger")),cT="TooltipPortal",[_z,zz]=ty(cT,{forceMount:void 0}),Uz=An(e=>{const{__scopeTooltip:n,forceMount:s,children:r,container:a}=e,i=zu(cT,n);return t.jsx(_z,{scope:n,forceMount:s,children:t.jsx(Jr,{present:s||i.open,children:t.jsx(lm,{asChild:!0,container:a,children:r})})})},"TooltipPortal"),uu="TooltipContent",Bz=d.forwardRef(An(function(n,s){const r=zz(uu,n.__scopeTooltip),{forceMount:a=r.forceMount,side:i="top",...l}=n,o=zu(uu,n.__scopeTooltip);return t.jsx(Jr,{present:a||o.open,children:o.disableHoverableContent?t.jsx(uT,{side:i,...l,ref:s}):t.jsx(Wz,{side:i,...l,ref:s})})},"TooltipContent")),Wz=d.forwardRef(An(function(n,s){const r=zu(uu,n.__scopeTooltip),a=sy(uu,n.__scopeTooltip),i=d.useRef(null),l=It(s,i),[o,c]=d.useState(null),{trigger:u,onClose:h}=r,f=i.current,{onPointerInTransitChange:m}=a,p=d.useCallback(()=>{c(null),m(!1)},[m]),v=d.useCallback((g,k)=>{const j=g.currentTarget,x={x:g.clientX,y:g.clientY},w=dT(x,j.getBoundingClientRect()),N=hT(x,w),y=fT(k.getBoundingClientRect()),b=pT([...N,...y]);c(b),m(!0)},[m]);return d.useEffect(()=>()=>p(),[p]),d.useEffect(()=>{if(u&&f){const g=An(j=>v(j,f),"handleTriggerLeave"),k=An(j=>v(j,u),"handleContentLeave");return u.addEventListener("pointerleave",g),f.addEventListener("pointerleave",k),()=>{u.removeEventListener("pointerleave",g),f.removeEventListener("pointerleave",k)}}},[u,f,v,p]),d.useEffect(()=>{if(o){const g=An(k=>{const j=k.target,x={x:k.clientX,y:k.clientY},w=(u==null?void 0:u.contains(j))||(f==null?void 0:f.contains(j)),N=!mT(x,o);w?p():N&&(p(),h())},"handleTrackPointerGrace");return document.addEventListener("pointermove",g),()=>document.removeEventListener("pointermove",g)}},[u,f,o,h,p]),t.jsx(uT,{...n,ref:l})},"TooltipContentHoverable")),Hz=v$("TooltipContent"),uT=d.forwardRef(An(function(n,s){const{__scopeTooltip:r,children:a,"aria-label":i,id:l,onEscapeKeyDown:o,onPointerDownOutside:c,...u}=n,h=zu(uu,r),f=ny(r),{onClose:m}=h;d.useEffect(()=>(document.addEventListener(Zx,m),()=>document.removeEventListener(Zx,m)),[m]),d.useEffect(()=>{if(h.trigger){const v=An(g=>{g.target instanceof Node&&g.target.contains(h.trigger)&&m()},"handleScroll");return window.addEventListener("scroll",v,{capture:!0}),()=>window.removeEventListener("scroll",v,{capture:!0})}},[h.trigger,m]);const{setContentId:p}=h;return ws(()=>(p(l),()=>{p(void 0)}),[l,p]),t.jsx(im,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:o,onPointerDownOutside:c,onFocusOutside:v=>v.preventDefault(),onDismiss:m,children:t.jsxs(oT,{"data-state":h.stateAttribute,role:i?void 0:"tooltip",id:i?void 0:h.contentId,...f,...u,ref:s,style:{...u.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[t.jsx(Hz,{children:a}),i?t.jsx(F_,{id:h.contentId,role:"tooltip",children:i}):null]})})},"TooltipContentImpl"));function dT(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")}}An(dT,"getExitSideFromRect");function hT(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}An(hT,"getPaddedExitPoints");function fT(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}]}An(fT,"getPointsFromRect");function mT(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,f=c.x,m=c.y;h>r!=m>r&&s<(f-u)*(r-h)/(m-h)+u&&(a=!a)}return a}An(mT,"isPointInPolygon");function pT(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),gT(n)}An(pT,"getHull");function gT(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)}An(gT,"getHullPresorted");var jN=Oz,du=Lz,hu=Fz,fu=Uz,mu=Bz;let gn={time:"auto",date:"auto",locale:void 0};function ry(e){const n=e.timeFormat===void 0?gn.time:e.timeFormat==="12h"||e.timeFormat==="24h"?e.timeFormat:"auto",s=e.dateFormat===void 0?gn.date:e.dateFormat==="short"||e.dateFormat==="long"||e.dateFormat==="iso"?e.dateFormat:"auto";gn={time:n,date:s,locale:e.locale??gn.locale}}function xT(){return{time:gn.time,date:gn.date}}function Uu(e,n){const s=gn;ry(e);try{return n()}finally{gn=s}}const tv="buddi:formats";function Bu(){if(gn.locale)return gn.locale;try{return typeof navigator<"u"&&navigator.language?navigator.language:"en-US"}catch{return"en-US"}}const wN=new Map;function Ro(e,n){const s=`${e}|${JSON.stringify(n)}`;let r=wN.get(s);if(!r){try{r=new Intl.DateTimeFormat(e,n)}catch{r=new Intl.DateTimeFormat(e,{...n,timeZone:"UTC"})}wN.set(s,r)}return r}function Fp(e,n,s,r){return Object.fromEntries(Ro(s,{timeZone:n,...r}).formatToParts(e).map(a=>[a.type,a.value]))}function Kz(){return gn.time==="12h"?{hour:"numeric",minute:"2-digit",hourCycle:"h12"}:gn.time==="24h"?{hour:"2-digit",minute:"2-digit",hourCycle:"h23"}:{hour:xm()?"numeric":"2-digit",minute:"2-digit"}}function Vz(){return gn.time==="auto"?Bu():"en-US"}function Tt(e,n){return Number.isNaN(e.getTime())?"—":Ro(Vz(),{timeZone:n,...Kz()}).format(e)}function Gz(e){return e>=1440&&!xm()?"24:00":Tt(new Date(Date.UTC(2026,0,1,Math.floor(e/60)%24,e%60)),"UTC")}function xm(){var e;return gn.time!=="auto"?gn.time==="12h":((e=Ro(Bu(),{hour:"numeric"}).resolvedOptions().hourCycle)==null?void 0:e.startsWith("h1"))===!0}function vT(){return`Profile (${xm()?"12-hour":"24-hour"})`}function Yz(){if(gn.date!=="auto")return gn.date==="short";const e=Ro(Bu(),{month:"short",day:"numeric"}).formatToParts(new Date(Date.UTC(2026,9,1))).map(n=>n.type);return e.indexOf("month")<e.indexOf("day")}function Er(e,n,s={}){return qz(e,n,s).replace(/\bSept\b/g,"Sep")}function qz(e,n,s){if(Number.isNaN(e.getTime()))return"—";const{weekday:r=!1,year:a=!1,compact:i=!1}=s;switch(gn.date){case"iso":{const l=Fp(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=Fp(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=Fp(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 Ro(Bu(),{timeZone:n,month:i?"short":"long",day:"numeric",...a?{year:"numeric"}:{},...r?{weekday:i?"short":"long"}:{}}).format(e)}}function jT(e,n){if(gn.date==="iso")return`${e}-${String(n).padStart(2,"0")}`;const s=new Date(Date.UTC(e,n-1,15)),r=gn.date==="auto"?Bu():"en-GB";return Ro(r,{timeZone:"UTC",month:"long",year:"numeric"}).format(s)}function Po(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:Er(r,"UTC",n)}function mt(e,n){if(!e)return"—";const s=new Date(e);return Number.isNaN(s.getTime())?String(e):`${Er(s,n,{year:!0,compact:!0})}, ${Tt(s,n)}`}function vm(e,n){return`${Er(e,n,{weekday:!0,compact:!0})}, ${Tt(e,n)}`}function Ye(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 ay(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 wT(e,n=Date.now()){const s=ay(e,n);return s===""?"":s==="now"||new Date(e).getTime()>n?"just now":s==="1 d"?"yesterday":`${s} ago`}function Qz(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 mn(e){return new Intl.NumberFormat("en-US").format(e)}function nv(e){return[...e.cacheRead?[`cached ${mn(e.cacheRead)}`]:[],...e.cacheWrite?[`cache write ${mn(e.cacheWrite)}`]:[]].join(", ")}function Jz(e){const n=nv(e);return`${mn(e.input)} in${n?` (${n})`:""} / ${mn(e.output)} out`}function ls(e){try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function pu(e,n=8){return e.length<=n?e:e.slice(0,n)}function xr(e,n){return e.length<=n?e:`${e.slice(0,n-1)}…`}function gu(e){if(e.kind!=="agent")return e.title;const n=e.title.replace(/^@[^\s:]+:\s+/,"");return n.trim()===""?e.title:n}const yN="buddi_csrf",Mo="x-buddi-csrf",ks="buddi:agents-changed",Di="buddi:status-changed",ic=e=>(window.dispatchEvent(new Event(Di)),e),sv="buddi:locked",Xz="This page's sign-in no longer matches its cookies. Reload the page and try again.";class he extends Error{constructor(n,s,r){super(s),this.status=n,this.detail=r,this.name="ApiError"}}function al(){var r;const e=Number(location.port)||(location.protocol==="https:"?443:80),n=document.cookie.match(new RegExp(`(?:^|; )${yN}_${e}=([^;]*)`));if(n!=null&&n[1])return decodeURIComponent(n[1]);const s=[...document.cookie.matchAll(new RegExp(`(?:^|; )${yN}(?:_\\d+)?=([^;]*)`,"g"))];return s.length===1&&((r=s[0])!=null&&r[1])?decodeURIComponent(s[0][1]):""}const sf="buddi isn't answering.";let rv=null;const av=new Set;function lc(e){if(e!==(rv===null)){rv=e?null:Date.now();for(const n of av)n()}}function xu(){return rv}function iy(e){return av.add(e),()=>av.delete(e)}function rf(e){return e instanceof he&&(e.status===0||e.status===502||e.status===503)&&e.message===sf}async function il(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:(lc(!1),new he(0,sf,o))}if(s.status===401)throw lc(!0),new he(401,"This session has expired. Run `buddi dashboard` for a fresh link.");if(s.status===423)throw lc(!0),window.dispatchEvent(new Event(sv)),new he(423,"This dashboard is locked.");const r=await s.text(),a=r===""?null:Zz(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 lc(!1),new he(s.status,sf,a);if(lc(!0),!s.ok){const o=(n.method??"GET").toUpperCase(),c=i??(s.status===403&&o!=="GET"&&o!=="HEAD"?Xz:`request failed (${s.status})`);throw new he(s.status,c,a)}return a}function Zz(e){try{return JSON.parse(e)}catch{return null}}function _p(){return xT().time==="auto"?{hour:xm()?"12":"24"}:{}}function ge(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 il(`/api${e}${r?`?${r}`:""}`)}function mh(e,n){return il(`/api${e}`,{method:"POST",headers:{[Mo]:al()},body:n})}function hs(e){return il(`/api${e}`,{method:"DELETE",headers:{[Mo]:al()}})}function te(e,n={}){return il(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/json",[Mo]:al()},body:JSON.stringify(n??{})})}function ly(e,n,s,r={}){const a=n.name.replace(/[^\w.-]+/g,"_").slice(-120)||s;return il(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/octet-stream",[Mo]:al(),"X-Filename":a,...r},body:n})}function bN(e,n,s){return ly(e,n,"backup.tar.gz",{...s.passphrase?{"X-Backup-Passphrase":s.passphrase}:{},...s.confirm?{"X-Backup-Confirm":s.confirm}:{}})}function e3(e,n={}){return il(`/api${e}`,{method:"PATCH",headers:{"Content-Type":"application/json",[Mo]:al()},body:JSON.stringify(n??{})})}function ar(e,n={}){return il(`/api${e}`,{method:"PUT",headers:{"Content-Type":"application/json",[Mo]:al()},body:JSON.stringify(n??{})})}function t3(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 ph="gpt-oss:120b",n3=["approval","question","watcher","reminder","failure","recap","plugin","agent"],iv=["mon","tue","wed","thu","fri","sat","sun"],Qe={agents:()=>ge("/chat/agents"),views:()=>ge("/chat/views"),conversations:(e,n)=>ge(`/chat/${encodeURIComponent(e)}/conversations`,{limit:n}),startConversation:e=>te(`/chat/${encodeURIComponent(e)}/conversations`),conversation:e=>ge(`/chat/conversations/${encodeURIComponent(e)}`),deleteCarryOver:e=>hs(`/chat/conversations/${encodeURIComponent(e)}/carry-over`),canvasTabs:e=>ge(`/chat/conversations/${encodeURIComponent(e)}/canvas-tabs`),saveCanvasTabs:(e,n)=>ar(`/chat/conversations/${encodeURIComponent(e)}/canvas-tabs`,n),send:(e,n)=>te(`/chat/${encodeURIComponent(e)}/messages`,n),answerQuestion:(e,n)=>te(`/chat/questions/${encodeURIComponent(e)}/answer`,n),cancel:e=>te(`/chat/conversations/${encodeURIComponent(e)}/cancel`),attach:e=>{const n=new FormData;return n.append("file",e,e.name),mh("/chat/attachments",n)},transcribe:e=>te("/speech/transcribe",e),say:e=>te("/speech/say",e),discardAttachment:e=>hs(`/artifacts/${encodeURIComponent(e)}`),groups:()=>ge("/groups"),group:e=>ge(`/groups/${encodeURIComponent(e)}`),createGroup:e=>te("/groups",e),updateGroup:(e,n)=>e3(`/groups/${encodeURIComponent(e)}`,n),deleteGroup:e=>hs(`/groups/${encodeURIComponent(e)}`),restoreGroup:e=>te(`/groups/${encodeURIComponent(e)}/restore`),clearGroup:e=>te(`/groups/${encodeURIComponent(e)}/clear`),groupConversations:e=>ge(`/groups/${encodeURIComponent(e)}/conversations`),startGroupConversation:e=>te(`/groups/${encodeURIComponent(e)}/conversations`),sendToGroup:(e,n)=>te(`/groups/${encodeURIComponent(e)}/messages`,n),streamUrl:e=>`/api/chat/conversations/${encodeURIComponent(e)}/stream`};function oy(e){return e.httpStatus===401||e.httpStatus===403||e.state==="authentication-error"||e.state==="access-denied"}const T={providers:()=>ge("/providers"),providerAccounts:()=>ge("/provider-accounts"),probeModels:e=>te("/provider-accounts/probe-models",e),accountModels:(e,n=!1)=>te(`/provider-accounts/${encodeURIComponent(e)}/models`,{refresh:n}),saveProviderAccount:e=>te("/provider-accounts/save",e),testProviderAccount:e=>te(`/provider-accounts/${encodeURIComponent(e)}/test`),removeProviderAccount:(e,n)=>te(`/provider-accounts/${encodeURIComponent(e)}/remove`,{revision:n}),codexAccountAction:(e,n,s)=>te(`/provider-accounts/${encodeURIComponent(e)}/${n}`,{revision:s}),ollamaConnect:(e,n)=>te(`/provider-accounts/${encodeURIComponent(e)}/ollama/connect`,{revision:n}),ollamaPoll:(e,n)=>te(`/provider-accounts/${encodeURIComponent(e)}/ollama/poll`,{attemptId:n}),ollamaDisconnect:(e,n)=>te(`/provider-accounts/${encodeURIComponent(e)}/ollama/disconnect`,{revision:n}),anthropicAccountAction:(e,n,s,r)=>te(`/provider-accounts/${encodeURIComponent(e)}/anthropic/${n}`,{revision:s,...r}),assignProviderAccount:(e,n,s)=>te(`/agents/${encodeURIComponent(e)}/account`,{accountId:n,model:s}),configureProvider:(e,n)=>te(`/providers/${encodeURIComponent(e)}/settings`,n),saveCredential:(e,n)=>te(`/providers/credentials/${encodeURIComponent(e)}/save`,{value:n}),removeCredential:e=>te(`/providers/credentials/${encodeURIComponent(e)}/remove`),testProvider:e=>te(`/providers/${encodeURIComponent(e)}/test`),browser:e=>ge(`/browser${e?`?agentId=${encodeURIComponent(e.agentId)}&conversationId=${encodeURIComponent(e.conversationId)}`:""}`),browserControl:(e,n,s)=>te(`/browser/${e}`,{...n===void 0?{}:{sessionId:n},...s!=null&&s.forever?{forever:!0}:{}}),browserSettings:e=>te("/browser/settings",e),browserPin:(e,n)=>te("/browser/pin",{conversationId:e,route:n}),browserLogin:(e,n)=>te("/browser/login",{id:e,decision:n}),browserCard:(e,n)=>te("/browser/card",{conversationId:e,answer:n}),browserInstall:()=>te("/browser/install",{}),browserCheck:()=>te("/browser/check",{}),browserDownloads:()=>ge("/browser/downloads"),clearBrowserDownloads:()=>te("/browser/downloads/clear",{}),fileBrowserDownload:e=>te("/browser/downloads/file",{id:e}),previewLink:(e,n)=>ge(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(n)}/link`),previewCheck:(e,n)=>ge(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(n)}/check`),extension:()=>ge("/extension"),pairExtension:e=>te("/extension/pair",{code:e}),forgetExtension:()=>hs("/extension/pair"),session:()=>ge("/session"),overview:()=>ge("/overview"),events:e=>ge("/events",e),eventKinds:()=>ge("/events/kinds"),conversations:()=>ge("/conversations"),conversation:e=>ge(`/conversations/${encodeURIComponent(e)}`),missions:()=>ge("/missions"),jobs:(e={})=>ge("/jobs",e),approvals:()=>ge("/approvals"),approval:e=>ge(`/approvals/${encodeURIComponent(e)}`).then(n=>n.action),offers:()=>ge("/offers"),dismissOffer:e=>te(`/offers/${encodeURIComponent(e)}/dismiss`,{}),dismissOffers:e=>te("/offers/dismiss-all",{ids:e}),agentOffers:()=>ge("/agent-offers"),catalogue:(e=!1)=>ge(`/catalogue${e?"?refresh=1":""}`),cataloguePlan:(e,n={})=>te(`/catalogue/${encodeURIComponent(e)}/plan`,n),catalogueInstall:(e,n)=>te(`/catalogue/${encodeURIComponent(e)}/install`,n),catalogueJob:e=>ge(`/catalogue/jobs/${encodeURIComponent(e)}`),catalogueConfirm:(e,n)=>te(`/catalogue/jobs/${encodeURIComponent(e)}/confirm`,{approve:n}),catalogueUpdatePlan:(e,n)=>te(`/catalogue/${encodeURIComponent(e)}/update/plan`,{agentId:n}),catalogueUpdate:(e,n,s,r=!1)=>te(`/catalogue/${encodeURIComponent(e)}/update`,{agentId:n,plan:s,...r?{replace:!0}:{}}),agentRemovePreview:e=>ge(`/agents/${encodeURIComponent(e)}/remove`),removeAgent:e=>te(`/agents/${encodeURIComponent(e)}/remove`),dismissAgentOffer:(e,n)=>te(`/agent-offers/${encodeURIComponent(e)}/${encodeURIComponent(n)}/dismiss`,{}),proposals:()=>ge("/proposals"),setDigestSchedule:(e,n)=>te("/proposals/digest-schedule",{day:e,hour:n}),keepProposal:(e,n)=>te(`/proposals/${encodeURIComponent(e)}/keep`,n===void 0?{}:{text:n}),keepAllProposals:e=>te("/proposals/keep-all",{ids:e}),discardProposal:(e,n)=>te(`/proposals/${encodeURIComponent(e)}/discard`,n?{reason:n}:{}),reminders:()=>ge("/reminders"),sentinels:()=>ge("/sentinels"),setSentinelEnabled:(e,n)=>te(`/sentinels/${encodeURIComponent(e)}/enabled`,{enabled:n}),widgets:(e="home")=>ge("/widgets",{...e==="lock"?{surface:e}:{},..._p()}),saveWidgets:(e,n)=>ar(`/widgets/${e}`,{placements:n.map(({key:s,widget:r,size:a,settings:i})=>({...s?{key:s}:{},widget:r,size:a,settings:i}))}),widgetSettings:e=>ge(`/widgets/settings/${encodeURIComponent(e)}`),previewWidget:e=>te("/widgets/preview",{...e,..._p()}),refreshWidget:(e,n="home")=>te(`/widgets/${encodeURIComponent(e)}/refresh${n==="lock"?"?surface=lock":""}`),homeDismiss:(e,n)=>te("/home/dismiss",{slot:e,token:n}),setGlanceHidden:(e,n)=>te(`/home/glances/${encodeURIComponent(e)}/hidden`,{hidden:n}),rail:()=>ge("/rail"),setRailHidden:(e,n,s)=>te(`/rail/pages/${encodeURIComponent(e)}/${encodeURIComponent(n)}/hidden`,{hidden:s}),snoozeAlerts:(e,n,s)=>te("/alerts/snooze",{keys:e,snoozed:n,...s!==void 0?{days:s}:{}}),muteAlert:(e,n)=>te("/alerts/mute",{key:e,scope:n}),unmuteAlert:e=>te(`/alerts/mutes/${encodeURIComponent(e)}/remove`,{}),actOnAlerts:e=>te("/alerts/act",{entries:e}),askAboutAlerts:e=>te("/alerts/ask",{keys:e}),agents:()=>ge("/agents"),library:e=>ge("/artifacts",e),libraryEntry:(e,n=0)=>ge(`/artifacts/${encodeURIComponent(e)}`,n?{contexts:n}:{}),onboarding:()=>ge("/onboarding"),onboardingStep:(e,n={})=>te("/onboarding/step",{step:e,...n}),takeOn:e=>te("/onboarding/take-on",{tiles:e}),takeOnProgress:()=>ge("/onboarding/take-on"),completeOnboarding:()=>te("/onboarding/complete"),skipOnboarding:()=>te("/onboarding/skip"),createFirstAgent:e=>te("/onboarding/agent",e),ollama:()=>ge("/onboarding/ollama"),ollamaPull:e=>te("/onboarding/ollama/pull",{model:e}),ollamaPullState:()=>ge("/onboarding/ollama/pull"),mlxh:()=>ge("/onboarding/mlxh"),firstAgentPersona:()=>ge("/onboarding/agent"),updateFirstAgent:e=>te("/onboarding/agent/update",e),bindBrain:e=>te("/onboarding/brain",e),pages:()=>ge("/pages"),pageQuery:(e,n,s={})=>ge(`/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)=>te(`/pages/${encodeURIComponent(e)}/act`,n),telegram:()=>ge("/telegram"),saveTelegramToken:e=>te("/telegram/token",{token:e}),telegramPairing:()=>te("/telegram/pairing"),telegramBot:()=>ge("/telegram/bot"),telegramDevices:()=>ge("/telegram/devices"),unpairTelegramDevice:e=>hs(`/telegram/devices/${encodeURIComponent(e)}`),notifications:(e=20)=>ge("/notifications",{limit:e}),notificationsNeedingYou:()=>ge("/notifications",{needs:1}),notificationSeen:e=>te(`/notifications/${encodeURIComponent(e)}/seen`),notificationSettings:()=>ge("/notifications/settings"),saveNotificationSettings:e=>ar("/notifications/settings",e),focus:()=>ge("/notifications/focus"),lockState:()=>ge("/lock"),lockScreen:()=>ge("/lock/screen",_p()),lockNow:(e="owner",n)=>te("/lock",{reason:e,...e==="idle"&&n!==void 0?{idleForMs:Math.max(0,Math.round(n))}:{}}),unlock:e=>te("/lock/unlock",{pin:e}),lockActivity:()=>te("/lock/activity"),setPin:(e,n)=>ar("/lock/pin",n===void 0?{pin:e}:{pin:e,current:n}),removePin:e=>te("/lock/pin/remove",{current:e}),setLockSettings:e=>ar("/lock/settings",e),uploadLockBackground:e=>{const n=new FormData;return n.append("file",e),mh("/lock/background",n)},removeLockBackground:()=>hs("/lock/background"),uploadLockPortrait:e=>{const n=new FormData;return n.append("file",e),mh("/lock/background/portrait",n)},removeLockPortrait:()=>hs("/lock/background/portrait"),setFocus:(e,n)=>ar("/notifications/focus",n?{mode:e,duration:n}:{mode:e}).then(ic),testChannel:e=>te("/notifications/test",{channel:e}),setAgentMuted:(e,n)=>te("/notifications/agent-mute",{agentId:e,muted:n}),currentTip:e=>ge(e?`/tips/current?preview=${encodeURIComponent(e)}`:"/tips/current"),tipQueue:(e,n)=>ge(e?`/tips/queue?preview=${encodeURIComponent(e)}`:n?"/tips/queue?peek=1":"/tips/queue"),tips:()=>ge("/tips"),dismissedTips:()=>ge("/tips/dismissed"),restoreTip:e=>te(`/tips/${encodeURIComponent(e)}/restore`),dismissTip:e=>te(`/tips/${encodeURIComponent(e)}/dismiss`),laterTip:e=>te(`/tips/${encodeURIComponent(e)}/later`),tipsSeenPage:e=>te("/tips/seen-page",{page:e}),presence:e=>te("/presence",{state:e}),owner:()=>ge("/owner"),setOwner:e=>te("/owner",e),findPlace:e=>te("/owner/places/find",{address:e}),savePlace:e=>te("/owner/places",e),removePlace:e=>te("/owner/places/remove",{id:e}),memory:e=>ge(e?`/memory?agent=${encodeURIComponent(e)}`:"/memory"),setPreference:e=>te("/memory/preferences",e),forgetPreference:e=>te("/memory/preferences/forget",e),updateNote:(e,n)=>te(`/memory/notes/${encodeURIComponent(e)}`,n),forgetNote:e=>te(`/memory/notes/${encodeURIComponent(e)}/forget`),people:()=>ge("/memory/people"),savePerson:e=>te("/memory/people",e),forgetPerson:e=>te(`/memory/people/${encodeURIComponent(e)}/forget`),restorePerson:e=>te(`/memory/people/${encodeURIComponent(e)}/restore`),birthday:()=>ge("/owner/birthday"),agentIntro:e=>ge(`/agents/${encodeURIComponent(e)}/intro`),dismissAgentIntro:e=>te(`/agents/${encodeURIComponent(e)}/intro/dismiss`),setDelegates:(e,n)=>te(`/agents/${encodeURIComponent(e)}/delegates`,{delegates:n}),agentProfile:e=>ge(`/agents/${encodeURIComponent(e)}/profile`),agentSkills:e=>ge(`/agents/${encodeURIComponent(e)}/skills`),removeSkill:(e,n)=>te(`/agents/${encodeURIComponent(e)}/skills/${encodeURIComponent(n)}/remove`,{}),host:(e,n)=>ge("/host",{agentId:e,conversationId:n}),connections:()=>ge("/connections"),connection:e=>ge(`/connections/${e}`),addConnection:(e,n)=>te("/connections",{url:e,...n?{name:n}:{}}),addProgram:e=>te("/connections",{transport:"stdio",...e}),updateProgram:(e,n)=>te(`/connections/${e}/program`,n),connectionConsent:(e,n)=>te(`/connections/${e}/consent`,n?{clientId:n}:{}),connectionToken:(e,n)=>te(`/connections/${e}/token`,n),connectionDevice:e=>te(`/connections/${e}/device`,{}),connectionCallback:e=>te("/connections/callback",e),connectionReview:e=>ge(`/connections/${e}/review`),saveConnectionReview:(e,n)=>te(`/connections/${e}/review`,n),grantConnection:(e,n,s=!1)=>te(`/connections/${e}/grant`,s?{agents:n,exact:!0}:{agents:n}),setConnectionHolder:(e,n,s)=>te(`/connections/${e}/holders/${encodeURIComponent(n)}`,{held:s}),disconnect:e=>hs(`/connections/${e}`),connectionSignals:()=>ge("/connections/signals"),connectionTools:e=>ge(`/connections/${e}/tools`),rememberedApprovals:e=>ge(`/connections/remembered/${encodeURIComponent(e)}`),setRememberedApproval:(e,n,s)=>te("/connections/remembered",{agent:e,tool:n,remember:s}),secrets:()=>ge("/secrets"),secretUses:(e,n)=>ge("/secrets/uses",{name:e,limit:n}),secretsAct:(e,n)=>te("/secrets/act",{tool:e,args:n}),stopHost:(e,n)=>te("/host/stop",{agentId:e,conversationId:n}),revokeHost:e=>te("/host/revoke",{id:e}),decide:(e,n,s,r)=>te(`/approvals/${encodeURIComponent(e)}/${n}`,s||r?{...s?{permissionScope:s}:{},...r?{ownerChoices:r}:{}}:void 0),setPaused:e=>te("/pause",{paused:e}).then(ic),service:()=>ge("/service"),runtimes:()=>ge("/runtimes"),removeEngine:()=>hs("/runtimes/onnx"),removeModel:e=>hs(`/runtimes/models/${encodeURIComponent(e)}`),serviceAction:e=>te(`/service/${e}`),version:()=>ge("/version"),checkVersion:()=>te("/version/check"),setVersionCheck:e=>ar("/version/check",{enabled:e}),tailscale:()=>ge("/access/tailscale"),setTailscale:e=>ar("/access/tailscale",e),access:()=>ge("/access"),cloudflareAccess:()=>ge("/access/cloudflare-access"),setCloudflareAccess:e=>ar("/access/cloudflare-access",e),testCloudflareAccess:e=>te("/access/cloudflare-access/test",e),cloudflareSetup:()=>ge("/access/cloudflare-access/setup"),cloudflareZones:(e={})=>te("/access/cloudflare-access/zones",e),startCloudflareSetup:e=>te("/access/cloudflare-access/setup",e),stopCloudflareSetup:()=>te("/access/cloudflare-access/setup/stop"),removeCloudflareSetup:(e={})=>te("/access/cloudflare-access/setup/remove",e),forgetCloudflareToken:()=>te("/access/cloudflare-access/setup/forget-token"),apiTokens:()=>ge("/api-tokens"),createApiToken:e=>te("/api-tokens",{name:e}),revokeApiToken:e=>hs(`/api-tokens/${encodeURIComponent(e)}`),startUpgrade:e=>te("/upgrade",e===void 0?{}:{version:e}),upgradeJob:e=>ge(`/upgrade/jobs/${encodeURIComponent(e)}`),backups:()=>ge("/backups"),startBackup:e=>te("/backups",{encrypt:e}),verifyArchive:e=>te("/backups/verify",{name:e}),restoreArchive:e=>te("/backups/restore",e),restoreUpload:(e,n)=>bN("/backups/restore",e,n),backupJob:e=>ge(`/backups/jobs/${encodeURIComponent(e)}`),backupSchedule:()=>ge("/backups/schedule"),setBackupSchedule:e=>ar("/backups/schedule",e),backupPassphrase:()=>ge("/backups/passphrase"),revealBackupPassphrase:e=>te("/backups/passphrase/reveal",e===void 0?{}:{pin:e}),cliTool:()=>ge("/system/cli"),installCliTool:()=>te("/system/cli",{}),uninstallPlan:()=>ge("/system/uninstall"),uninstallBackup:e=>te("/system/uninstall/backup",{token:e}),uninstallJob:e=>ge(`/system/uninstall/jobs/${encodeURIComponent(e)}`),uninstall:e=>te("/system/uninstall",e),passphraseNotice:()=>ge("/backups/passphrase/notice"),acknowledgePassphrase:()=>te("/backups/passphrase/notice",{}),setBackupPassphrase:e=>ar("/backups/passphrase",{passphrase:e}),plugins:()=>ge("/plugins"),market:(e=!1)=>ge(`/market${e?"?refresh=1":""}`),marketAssetUrl:e=>`/api/market/asset?url=${encodeURIComponent(e)}`,pluginFolders:e=>ge("/plugins/folders",e?{path:e}:{}),stagePlugin:e=>te("/plugins/stage",{spec:e}),uploadPlugin:e=>ly("/plugins/upload",e,"plugin.tgz"),pluginJob:e=>ge(`/plugins/jobs/${encodeURIComponent(e)}`),approveStaged:(e,n)=>te(`/plugins/staged/${encodeURIComponent(e)}/approve`,n),rejectStaged:e=>te(`/plugins/staged/${encodeURIComponent(e)}/reject`),openedStaged:e=>te(`/plugins/staged/${encodeURIComponent(e)}/opened`),updatePlugin:(e,n,s)=>te(`/plugins/${encodeURIComponent(e)}/update`,{...n?{version:n}:{},...s?{from:s}:{}}),setPluginEnabled:(e,n)=>te(`/plugins/${encodeURIComponent(e)}/${n?"enable":"disable"}`,{}),uninstallPlugin:(e,n)=>te(`/plugins/${encodeURIComponent(e)}/uninstall`,n),acceptPluginAgent:(e,n)=>te(`/plugins/${encodeURIComponent(e)}/agents/${encodeURIComponent(n)}/accept`),recovery:()=>ge("/recovery"),leaveRecovery:e=>te("/recovery/leave",e),firstRunRestore:(e,n)=>bN("/onboarding/restore",e,{passphrase:n}),setMissionEnabled:(e,n)=>te(`/missions/${encodeURIComponent(e)}/enabled`,{enabled:n}),setMissionChrome:(e,n)=>te(`/missions/${encodeURIComponent(e)}/browser`,{chrome:n}),keepMission:e=>te(`/missions/${encodeURIComponent(e)}/keep`,{}),answerStillUseful:(e,n)=>te(`/missions/${encodeURIComponent(e)}/still-useful`,{answer:n}),setMisfirePolicy:(e,n,s)=>te(`/missions/${encodeURIComponent(e)}/schedule`,{misfirePolicy:n,...s===void 0?{}:{deadlineMinutes:s}}),retryJob:e=>te(`/jobs/${encodeURIComponent(e)}/retry`),cancelJob:e=>te(`/jobs/${encodeURIComponent(e)}/cancel`),jobFailures:()=>ge("/jobs/failures"),dismissJobs:e=>te("/jobs/dismiss",e).then(ic),undismissJobs:e=>te("/jobs/undismiss",{ids:e}).then(ic),retryJobs:e=>te("/jobs/retry",e).then(ic),setDefaultAgent:e=>te("/agents/default",{agentId:e}),agentTools:e=>ge(`/agents/${encodeURIComponent(e)}/tools`),agentFile:e=>ge(`/agents/${encodeURIComponent(e)}/file`),uploadAgentPicture:(e,n)=>{const s=new FormData;return s.append("file",n,n.name),mh(`/agents/${encodeURIComponent(e)}/avatar`,s)},removeAgentPicture:e=>hs(`/agents/${encodeURIComponent(e)}/avatar`),updateAgentFile:(e,n)=>te(`/agents/${encodeURIComponent(e)}/file`,n),setAgentEngine:(e,n)=>te(`/agents/${encodeURIComponent(e)}/engine`,n),quiet:e=>te("/quiet",{arg:e}),takeOffer:(e,n)=>te(`/offers/${encodeURIComponent(e)}/take`,n?{conversationId:n}:{}),cancelReminder:e=>te(`/reminders/${encodeURIComponent(e)}/cancel`,{reason:"cancelled from the dashboard"})},lv="buddi.chatDraft";function Wu(e,n){try{window.sessionStorage.setItem(lv,JSON.stringify({agentId:e,text:n}))}catch{}}function s3(e){try{const n=window.sessionStorage.getItem(lv);if(!n)return null;const s=JSON.parse(n);return s.agentId!==e||typeof s.text!="string"?null:(window.sessionStorage.removeItem(lv),s.text)}catch{return null}}const r3=4e3,a3={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"},yT=e=>a3[e.toLowerCase()]??e;function jm(e,n){const s=e.lastIndexOf(`
41
+ `,n-1)+1,r=e.indexOf(`
42
+ `,n),a=r<0?e.length:r;return{start:s,end:a,text:e.slice(s,a)}}function Mc(e,n){return(e.slice(0,jm(e,n).start).match(/^```/gm)??[]).length%2===1}function i3(e,n){const s=e.slice(0,n),r=/(^|[\s(])@([a-z0-9-]*)$/i.exec(s);return!r||Mc(e,n)?null:{start:n-r[2].length-1,query:r[2]}}function l3(e,n){const s=/^\/([a-z0-9-]*)$/i.exec(e.slice(0,n));return s?{query:s[1]}:null}function o3(e,n){return/^\/use @?[a-z0-9-]*$/i.test(e.slice(0,n))}function c3(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 u3(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 d3=/^(\s*)([-*]|\d+\.)( )(.*)$/;function cy(e,n){if(Mc(e,n))return null;const s=d3.exec(jm(e,n).text);return s?{indent:s[1],mark:s[2],body:s[4]}:null}function h3(e,n){const s=cy(e,n);if(!s)return null;const r=jm(e,n);if(s.body.trim()==="")return{value:e.slice(0,r.start)+e.slice(r.end),caret:r.start};const a=/\d/.test(s.mark)?`${parseInt(s.mark,10)+1}.`:s.mark,i=`
43
+ ${s.indent}${a} `;return{value:e.slice(0,n)+i+e.slice(n),caret:n+i.length}}function f3(e,n,s){if(!cy(e,n))return null;const r=jm(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 m3(e){const n=e.replace(/\n$/,"").split(`
44
+ `);return n.length<3||/^```/m.test(e)?!1:n.filter(r=>/[;{}()=<>]\s*$|^\s{2,}\S|^\t+\S|^\s*(const|let|var|function|def|import|from|export|return|if|for|while|class|SELECT|INSERT|UPDATE|<\w)/.test(r)).length/n.length>.5}function p3(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 g3(e,n,s,r){const i=`${n>0&&e[n-1]!==`
45
+ `?`
46
+ `:""}\`\`\`${r}
47
+ ${s.replace(/\n$/,"")}
48
+ \`\`\`
49
+ `;return{value:e.slice(0,n)+i+e.slice(n),caret:n+i.length}}function x3(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 bT(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 kT(e){return e==="anthropic"||e==="openai"}function NT(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 v3="Thinking is up to this model. What it writes while thinking is shown apart and kept out of the answer.";var j3=Object.defineProperty,w3=(e,n)=>j3(e,"name",{value:n,configurable:!0}),y3=d.createContext(void 0);function wm(e){const n=d.useContext(y3);return e||n||"ltr"}w3(wm,"useDirection");var b3=Object.defineProperty,uy=(e,n)=>b3(e,"name",{value:n,configurable:!0}),Cd=0,Rr=null;function k3(e){return ym(),e.children}uy(k3,"FocusGuards");function ym(){d.useEffect(()=>{Rr||(Rr={start:ov(),end:ov()});const{start:e,end:n}=Rr;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==n&&document.body.insertAdjacentElement("beforeend",n),Cd++,()=>{Cd===1&&(Rr==null||Rr.start.remove(),Rr==null||Rr.end.remove(),Rr=null),Cd=Math.max(0,Cd-1)}},[])}uy(ym,"useFocusGuards");function ov(){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}uy(ov,"createFocusGuard");var N3=Object.defineProperty,rs=(e,n)=>N3(e,"name",{value:n,configurable:!0}),zp="focusScope.autoFocusOnMount",Up="focusScope.autoFocusOnUnmount",kN={bubbles:!1,cancelable:!0},ST=d.forwardRef(rs(function(n,s){const{loop:r=!1,trapped:a=!1,onMountAutoFocus:i,onUnmountAutoFocus:l,...o}=n,[c,u]=d.useState(null),h=is(i),f=is(l),m=d.useRef(null),p=It(s,u),v=d.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;d.useEffect(()=>{if(a){let k=function(N){if(v.paused||!c)return;const y=N.target;c.contains(y)?m.current=y:aa(m.current,{select:!0})},j=function(N){if(v.paused||!c)return;const y=N.relatedTarget;y!==null&&(c.contains(y)||aa(m.current,{select:!0}))},x=function(N){if(document.activeElement===document.body)for(const b of N)b.removedNodes.length>0&&aa(c)};rs(k,"handleFocusIn"),rs(j,"handleFocusOut"),rs(x,"handleMutations"),document.addEventListener("focusin",k),document.addEventListener("focusout",j);const w=new MutationObserver(x);return c&&w.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",k),document.removeEventListener("focusout",j),w.disconnect()}}},[a,c,v.paused]),d.useEffect(()=>{if(c){NN.add(v);const k=document.activeElement;if(!c.contains(k)){const x=new CustomEvent(zp,kN);c.addEventListener(zp,h),c.dispatchEvent(x),x.defaultPrevented||(CT(IT(dy(c)),{select:!0}),document.activeElement===k&&aa(c))}return()=>{c.removeEventListener(zp,h),setTimeout(()=>{const x=new CustomEvent(Up,kN);c.addEventListener(Up,f),c.dispatchEvent(x),x.defaultPrevented||aa(k??document.body,{select:!0}),c.removeEventListener(Up,f),NN.remove(v)},0)}}},[c,h,f,v]);const g=d.useCallback(k=>{if(!r&&!a||v.paused)return;const j=k.key==="Tab"&&!k.altKey&&!k.ctrlKey&&!k.metaKey,x=document.activeElement;if(j&&x){const w=k.currentTarget,[N,y]=ET(w);N&&y?!k.shiftKey&&x===y?(k.preventDefault(),r&&aa(N,{select:!0})):k.shiftKey&&x===N&&(k.preventDefault(),r&&aa(y,{select:!0})):x===w&&k.preventDefault()}},[r,a,v.paused]);return t.jsx(St.div,{tabIndex:-1,...o,ref:p,onKeyDown:g})},"FocusScope"));function CT(e,{select:n=!1}={}){const s=document.activeElement;for(const r of e)if(aa(r,{select:n}),document.activeElement!==s)return}rs(CT,"focusFirst");function ET(e){const n=dy(e),s=cv(n,e),r=cv(n.reverse(),e);return[s,r]}rs(ET,"getTabbableEdges");function dy(e){const n=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:rs(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}rs(dy,"getTabbableCandidates");function cv(e,n){const s=typeof n.checkVisibility=="function"&&n.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(s?!r.checkVisibility({checkVisibilityCSS:!0}):AT(r,{upTo:n})))return r}rs(cv,"findVisible");function AT(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}rs(AT,"isHidden");function $T(e){return e instanceof HTMLInputElement&&"select"in e}rs($T,"isSelectableInput");function aa(e,{select:n=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&$T(e)&&n&&e.select()}}rs(aa,"focus");var NN=TT();function TT(){let e=[];return{add(n){const s=e[0];n!==s&&(s==null||s.pause()),e=uv(e,n),e.unshift(n)},remove(n){var s;e=uv(e,n),(s=e[0])==null||s.resume()}}}rs(TT,"createFocusScopesStack");function uv(e,n){const s=[...e],r=s.indexOf(n);return r!==-1&&s.splice(r,1),s}rs(uv,"arrayRemove");function IT(e){return e.filter(n=>n.tagName!=="A")}rs(IT,"removeLinks");var S3=Object.defineProperty,hy=(e,n)=>S3(e,"name",{value:n,configurable:!0}),Bp=!1;function RT(){const[e,n]=d.useState(Bp);return d.useEffect(()=>{Bp||(Bp=!0,n(!0))},[]),e}hy(RT,"useIsHydrated");var PT=So[" useSyncExternalStore ".trim().toString()];function MT(){return()=>{}}hy(MT,"subscribe");function OT(){return PT(MT,()=>!0,()=>!1)}hy(OT,"useIsHydratedModern");var C3=typeof PT=="function"?OT:RT,E3=Object.defineProperty,ll=(e,n)=>E3(e,"name",{value:n,configurable:!0}),Wp="rovingFocusGroup.onEntryFocus",A3={bubbles:!1,cancelable:!0},bm="RovingFocusGroup",[dv,DT,$3]=rm(bm),[T3,km]=Sr(bm,[$3]),[I3,R3]=T3(bm),P3=d.forwardRef(ll(function(n,s){return t.jsx(dv.Provider,{scope:n.__scopeRovingFocusGroup,children:t.jsx(dv.Slot,{scope:n.__scopeRovingFocusGroup,children:t.jsx(M3,{...n,ref:s})})})},"RovingFocusGroup")),M3=d.forwardRef(ll(function(n,s){const{__scopeRovingFocusGroup:r,orientation:a,loop:i=!1,dir:l,currentTabStopId:o,defaultCurrentTabStopId:c,onCurrentTabStopIdChange:u,onEntryFocus:h,preventScrollOnEntryFocus:f=!1,...m}=n,p=d.useRef(null),v=It(s,p),g=wm(l),[k,j]=mi({prop:o,defaultProp:c??null,onChange:u,caller:bm}),[x,w]=d.useState(!1),N=is(h),y=DT(r),b=d.useRef(!1),[S,C]=d.useState(0);return d.useEffect(()=>{const A=p.current;if(A)return A.addEventListener(Wp,N),()=>A.removeEventListener(Wp,N)},[N]),t.jsx(I3,{scope:r,orientation:a,dir:g,loop:i,currentTabStopId:k,onItemFocus:d.useCallback(A=>j(A),[j]),onItemShiftTab:d.useCallback(()=>w(!0),[]),onFocusableItemAdd:d.useCallback(()=>C(A=>A+1),[]),onFocusableItemRemove:d.useCallback(()=>C(A=>A-1),[]),children:t.jsx(St.div,{tabIndex:x||S===0?-1:0,"data-orientation":a,...m,ref:v,style:{outline:"none",...n.style},onMouseDown:He(n.onMouseDown,()=>{b.current=!0}),onFocus:He(n.onFocus,A=>{const $=!b.current;if(A.target===A.currentTarget&&$&&!x){const I=new CustomEvent(Wp,A3);if(A.currentTarget.dispatchEvent(I),!I.defaultPrevented){const P=y().filter(W=>W.focusable),O=P.find(W=>W.active),R=P.find(W=>W.id===k),U=[O,R,...P].filter(Boolean).map(W=>W.ref.current);fy(U,f)}}b.current=!1}),onBlur:He(n.onBlur,()=>w(!1))})})},"RovingFocusGroupImpl")),O3="RovingFocusGroupItem",D3=d.forwardRef(ll(function(n,s){const{__scopeRovingFocusGroup:r,focusable:a=!0,active:i=!1,tabStopId:l,children:o,...c}=n,u=mr(),h=l||u,f=R3(O3,r),m=f.currentTabStopId===h,p=DT(r),{onFocusableItemAdd:v,onFocusableItemRemove:g,currentTabStopId:k}=f,j=C3();return ws(()=>{if(!(!j||!a))return v(),()=>g()},[j,a,v,g]),d.useEffect(()=>{if(!(j||!a))return v(),()=>g()},[j,a,v,g]),t.jsx(dv.ItemSlot,{scope:r,id:h,focusable:a,active:i,children:t.jsx(St.span,{tabIndex:m?0:-1,"data-orientation":f.orientation,...c,ref:s,onMouseDown:He(n.onMouseDown,x=>{a?f.onItemFocus(h):x.preventDefault()}),onFocus:He(n.onFocus,()=>f.onItemFocus(h)),onKeyDown:He(n.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){f.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const w=FT(x,f.orientation,f.dir);if(w!==void 0){if(x.metaKey||x.ctrlKey||x.altKey||x.shiftKey)return;x.preventDefault();let y=p().filter(b=>b.focusable).map(b=>b.ref.current);if(w==="last")y.reverse();else if(w==="prev"||w==="next"){w==="prev"&&y.reverse();const b=y.indexOf(x.currentTarget);y=f.loop?_T(y,b+1):y.slice(b+1)}setTimeout(()=>fy(y))}}),children:typeof o=="function"?o({isCurrentTabStop:m,hasTabStop:k!=null}):o})})},"RovingFocusGroupItem")),L3={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function LT(e,n){return n!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}ll(LT,"getDirectionAwareKey");function FT(e,n,s){const r=LT(e.key,s);if(!(n==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(n==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return L3[r]}ll(FT,"getFocusIntent");function fy(e,n=!1){const s=document.activeElement;for(const r of e)if(r===s||(r.focus({preventScroll:n}),document.activeElement!==s))return}ll(fy,"focusFirst");function _T(e,n){return e.map((s,r)=>e[(n+r)%e.length])}ll(_T,"wrapArray");var zT=P3,UT=D3,F3=function(e){if(typeof document>"u")return null;var n=Array.isArray(e)?e[0]:e;return n.ownerDocument.body},vl=new WeakMap,Ed=new WeakMap,Ad={},Hp=0,BT=function(e){return e&&(e.host||BT(e.parentNode))},_3=function(e,n){return n.map(function(s){if(e.contains(s))return s;var r=BT(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})},z3=function(e,n,s,r){var a=_3(n,Array.isArray(e)?e:[e]);Ad[s]||(Ad[s]=new WeakMap);var i=Ad[s],l=[],o=new Set,c=new Set(a),u=function(f){!f||o.has(f)||(o.add(f),u(f.parentNode))};a.forEach(u);var h=function(f){!f||c.has(f)||Array.prototype.forEach.call(f.children,function(m){if(o.has(m))h(m);else try{var p=m.getAttribute(r),v=p!==null&&p!=="false",g=(vl.get(m)||0)+1,k=(i.get(m)||0)+1;vl.set(m,g),i.set(m,k),l.push(m),g===1&&v&&Ed.set(m,!0),k===1&&m.setAttribute(s,"true"),v||m.setAttribute(r,"true")}catch(j){console.error("aria-hidden: cannot operate on ",m,j)}})};return h(n),o.clear(),Hp++,function(){l.forEach(function(f){var m=vl.get(f)-1,p=i.get(f)-1;vl.set(f,m),i.set(f,p),m||(Ed.has(f)||f.removeAttribute(r),Ed.delete(f)),p||f.removeAttribute(s)}),Hp--,Hp||(vl=new WeakMap,vl=new WeakMap,Ed=new WeakMap,Ad={})}},WT=function(e,n,s){s===void 0&&(s="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),a=F3(e);return a?(r.push.apply(r,Array.from(a.querySelectorAll("[aria-live], script"))),z3(r,a,s,"aria-hidden")):function(){return null}},Lr=function(){return Lr=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},Lr.apply(this,arguments)};function HT(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 U3(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",xh="width-before-scroll-bar",B3="with-scroll-bars-hidden",W3="--removed-body-scroll-bar-size";function Kp(e,n){return typeof e=="function"?e(n):e&&(e.current=n),e}function H3(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 K3=typeof window<"u"?d.useLayoutEffect:d.useEffect,SN=new WeakMap;function V3(e,n){var s=H3(null,function(r){return e.forEach(function(a){return Kp(a,r)})});return K3(function(){var r=SN.get(s);if(r){var a=new Set(r),i=new Set(e),l=s.current;a.forEach(function(o){i.has(o)||Kp(o,null)}),i.forEach(function(o){a.has(o)||Kp(o,l)})}SN.set(s,e)},[e]),s}function G3(e){return e}function Y3(e,n){n===void 0&&(n=G3);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 q3(e){e===void 0&&(e={});var n=Y3(null);return n.options=Lr({async:!0,ssr:!1},e),n}var KT=function(e){var n=e.sideCar,s=HT(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,Lr({},s))};KT.isSideCarExport=!0;function Q3(e,n){return e.useMedium(n),KT}var VT=q3(),Vp=function(){},Nm=d.forwardRef(function(e,n){var s=d.useRef(null),r=d.useState({onScrollCapture:Vp,onWheelCapture:Vp,onTouchMoveCapture:Vp}),a=r[0],i=r[1],l=e.forwardProps,o=e.children,c=e.className,u=e.removeScrollBar,h=e.enabled,f=e.shards,m=e.sideCar,p=e.noRelative,v=e.noIsolation,g=e.inert,k=e.allowPinchZoom,j=e.as,x=j===void 0?"div":j,w=e.gapMode,N=HT(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),y=m,b=V3([s,n]),S=Lr(Lr({},N),a);return d.createElement(d.Fragment,null,h&&d.createElement(y,{sideCar:VT,removeScrollBar:u,shards:f,noRelative:p,noIsolation:v,inert:g,setCallbacks:i,allowPinchZoom:!!k,lockRef:s,gapMode:w}),l?d.cloneElement(d.Children.only(o),Lr(Lr({},S),{ref:b})):d.createElement(x,Lr({},S,{className:c,ref:b}),o))});Nm.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};Nm.classNames={fullWidth:xh,zeroRight:gh};var J3=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function X3(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var n=J3();return n&&e.setAttribute("nonce",n),e}function Z3(e,n){e.styleSheet?e.styleSheet.cssText=n:e.appendChild(document.createTextNode(n))}function eU(e){var n=document.head||document.getElementsByTagName("head")[0];n.appendChild(e)}var tU=function(){var e=0,n=null;return{add:function(s){e==0&&(n=X3())&&(Z3(n,s),eU(n)),e++},remove:function(){e--,!e&&n&&(n.parentNode&&n.parentNode.removeChild(n),n=null)}}},nU=function(){var e=tU();return function(n,s){d.useEffect(function(){return e.add(n),function(){e.remove()}},[n&&s])}},GT=function(){var e=nU(),n=function(s){var r=s.styles,a=s.dynamic;return e(r,a),null};return n},sU={left:0,top:0,right:0,gap:0},Gp=function(e){return parseInt(e||"",10)||0},rU=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[Gp(s),Gp(r),Gp(a)]},aU=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return sU;var n=rU(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])}},iU=GT(),Jl="data-scroll-locked",lU=function(e,n,s,r){var a=e.left,i=e.top,l=e.right,o=e.gap;return s===void 0&&(s="margin"),`
50
+ .`.concat(B3,` {
51
+ overflow: hidden `).concat(r,`;
52
+ padding-right: `).concat(o,"px ").concat(r,`;
53
+ }
54
+ body[`).concat(Jl,`] {
55
+ overflow: hidden `).concat(r,`;
56
+ overscroll-behavior: contain;
57
+ `).concat([n&&"position: relative ".concat(r,";"),s==="margin"&&`
58
+ padding-left: `.concat(a,`px;
59
+ padding-top: `).concat(i,`px;
60
+ padding-right: `).concat(l,`px;
61
+ margin-left:0;
62
+ margin-top:0;
63
+ margin-right: `).concat(o,"px ").concat(r,`;
64
+ `),s==="padding"&&"padding-right: ".concat(o,"px ").concat(r,";")].filter(Boolean).join(""),`
65
+ }
66
+
67
+ .`).concat(gh,` {
68
+ right: `).concat(o,"px ").concat(r,`;
69
+ }
70
+
71
+ .`).concat(xh,` {
72
+ margin-right: `).concat(o,"px ").concat(r,`;
73
+ }
74
+
75
+ .`).concat(gh," .").concat(gh,` {
76
+ right: 0 `).concat(r,`;
77
+ }
78
+
79
+ .`).concat(xh," .").concat(xh,` {
80
+ margin-right: 0 `).concat(r,`;
81
+ }
82
+
83
+ body[`).concat(Jl,`] {
84
+ `).concat(W3,": ").concat(o,`px;
85
+ }
86
+ `)},CN=function(){var e=parseInt(document.body.getAttribute(Jl)||"0",10);return isFinite(e)?e:0},oU=function(){d.useEffect(function(){return document.body.setAttribute(Jl,(CN()+1).toString()),function(){var e=CN()-1;e<=0?document.body.removeAttribute(Jl):document.body.setAttribute(Jl,e.toString())}},[])},cU=function(e){var n=e.noRelative,s=e.noImportant,r=e.gapMode,a=r===void 0?"margin":r;oU();var i=d.useMemo(function(){return aU(a)},[a]);return d.createElement(iU,{styles:lU(i,!n,a,s?"":"!important")})},hv=!1;if(typeof window<"u")try{var $d=Object.defineProperty({},"passive",{get:function(){return hv=!0,!0}});window.addEventListener("test",$d,$d),window.removeEventListener("test",$d,$d)}catch{hv=!1}var jl=hv?{passive:!1}:!1,uU=function(e){return e.tagName==="TEXTAREA"},YT=function(e,n){if(!(e instanceof Element))return!1;var s=window.getComputedStyle(e);return s[n]!=="hidden"&&!(s.overflowY===s.overflowX&&!uU(e)&&s[n]==="visible")},dU=function(e){return YT(e,"overflowY")},hU=function(e){return YT(e,"overflowX")},EN=function(e,n){var s=n.ownerDocument,r=n;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var a=qT(e,r);if(a){var i=QT(e,r),l=i[1],o=i[2];if(l>o)return!0}r=r.parentNode}while(r&&r!==s.body);return!1},fU=function(e){var n=e.scrollTop,s=e.scrollHeight,r=e.clientHeight;return[n,s,r]},mU=function(e){var n=e.scrollLeft,s=e.scrollWidth,r=e.clientWidth;return[n,s,r]},qT=function(e,n){return e==="v"?dU(n):hU(n)},QT=function(e,n){return e==="v"?fU(n):mU(n)},pU=function(e,n){return e==="h"&&n==="rtl"?-1:1},gU=function(e,n,s,r,a){var i=pU(e,window.getComputedStyle(n).direction),l=i*r,o=s.target,c=n.contains(o),u=!1,h=l>0,f=0,m=0;do{if(!o)break;var p=QT(e,o),v=p[0],g=p[1],k=p[2],j=g-k-i*v;(v||j)&&qT(e,o)&&(f+=j,m+=v);var x=o.parentNode;o=x&&x.nodeType===Node.DOCUMENT_FRAGMENT_NODE?x.host:x}while(!c&&o!==document.body||c&&(n.contains(o)||n===o));return(h&&Math.abs(f)<1||!h&&Math.abs(m)<1)&&(u=!0),u},Td=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},AN=function(e){return[e.deltaX,e.deltaY]},$N=function(e){return e&&"current"in e?e.current:e},xU=function(e,n){return e[0]===n[0]&&e[1]===n[1]},vU=function(e){return`
87
+ .block-interactivity-`.concat(e,` {pointer-events: none;}
88
+ .allow-interactivity-`).concat(e,` {pointer-events: all;}
89
+ `)},jU=0,wl=[];function wU(e){var n=d.useRef([]),s=d.useRef([0,0]),r=d.useRef(),a=d.useState(jU++)[0],i=d.useState(GT)[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=U3([e.lockRef.current],(e.shards||[]).map($N),!0).filter(Boolean);return g.forEach(function(k){return k.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),g.forEach(function(k){return k.classList.remove("allow-interactivity-".concat(a))})}}},[e.inert,e.lockRef.current,e.shards]);var o=d.useCallback(function(g,k){if("touches"in g&&g.touches.length===2||g.type==="wheel"&&g.ctrlKey)return!l.current.allowPinchZoom;var j=Td(g),x=s.current,w="deltaX"in g?g.deltaX:x[0]-j[0],N="deltaY"in g?g.deltaY:x[1]-j[1],y,b=g.target,S=Math.abs(w)>Math.abs(N)?"h":"v";if("touches"in g&&S==="h"&&b.type==="range")return!1;var C=window.getSelection(),A=C&&C.anchorNode,$=A?A===b||A.contains(b):!1;if($)return!1;var I=EN(S,b);if(!I)return!0;if(I?y=S:(y=S==="v"?"h":"v",I=EN(S,b)),!I)return!1;if(!r.current&&"changedTouches"in g&&(w||N)&&(r.current=y),!y)return!0;var P=r.current||y;return gU(P,k,g,P==="h"?w:N)},[]),c=d.useCallback(function(g){var k=g;if(!(!wl.length||wl[wl.length-1]!==i)){var j="deltaY"in k?AN(k):Td(k),x=n.current.filter(function(y){return y.name===k.type&&(y.target===k.target||k.target===y.shadowParent)&&xU(y.delta,j)})[0];if(x&&x.should){k.cancelable&&k.preventDefault();return}if(!x){var w=(l.current.shards||[]).map($N).filter(Boolean).filter(function(y){return y.contains(k.target)}),N=w.length>0?o(k,w[0]):!l.current.noIsolation;N&&k.cancelable&&k.preventDefault()}}},[]),u=d.useCallback(function(g,k,j,x){var w={name:g,delta:k,target:j,should:x,shadowParent:yU(j)};n.current.push(w),setTimeout(function(){n.current=n.current.filter(function(N){return N!==w})},1)},[]),h=d.useCallback(function(g){s.current=Td(g),r.current=void 0},[]),f=d.useCallback(function(g){u(g.type,AN(g),g.target,o(g,e.lockRef.current))},[]),m=d.useCallback(function(g){u(g.type,Td(g),g.target,o(g,e.lockRef.current))},[]);d.useEffect(function(){return wl.push(i),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:m}),document.addEventListener("wheel",c,jl),document.addEventListener("touchmove",c,jl),document.addEventListener("touchstart",h,jl),function(){wl=wl.filter(function(g){return g!==i}),document.removeEventListener("wheel",c,jl),document.removeEventListener("touchmove",c,jl),document.removeEventListener("touchstart",h,jl)}},[]);var p=e.removeScrollBar,v=e.inert;return d.createElement(d.Fragment,null,v?d.createElement(i,{styles:vU(a)}):null,p?d.createElement(cU,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function yU(e){for(var n=null;e!==null;)e instanceof ShadowRoot&&(n=e.host,e=e.host),e=e.parentNode;return n}const bU=Q3(VT,wU);var my=d.forwardRef(function(e,n){return d.createElement(Nm,Lr({},e,{ref:n,sideCar:bU}))});my.classNames=Nm.classNames;var kU=Object.defineProperty,yt=(e,n)=>kU(e,"name",{value:n,configurable:!0}),fv=["Enter"," "],NU=["ArrowDown","PageUp","Home"],JT=["ArrowUp","PageDown","End"],SU=[...NU,...JT],CU={ltr:[...fv,"ArrowRight"],rtl:[...fv,"ArrowLeft"]},EU={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Sm="Menu",[vu,AU,$U]=rm(Sm),[ol,XT]=Sr(Sm,[$U,pm,km]),Cm=pm(),ZT=km(),[eI,gi]=ol(Sm),[TU,Hu]=ol(Sm),IU=yt(e=>{const{__scopeMenu:n,open:s=!1,children:r,dir:a,onOpenChange:i,modal:l=!0}=e,o=Cm(n),[c,u]=d.useState(null),h=d.useRef(!1),f=is(i),m=wm(a);return d.useEffect(()=>{const p=yt(()=>{h.current=!0,document.addEventListener("pointerdown",v,{capture:!0,once:!0}),document.addEventListener("pointermove",v,{capture:!0,once:!0})},"handleKeyDown"),v=yt(()=>h.current=!1,"handlePointer");return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",v,{capture:!0}),document.removeEventListener("pointermove",v,{capture:!0})}},[]),d.useEffect(()=>{if(!s)return;const p=yt(()=>f(!1),"handleBlur");return window.addEventListener("blur",p),()=>window.removeEventListener("blur",p)},[s,f]),t.jsx(ey,{...o,children:t.jsx(eI,{scope:n,open:s,onOpenChange:f,content:c,onContentChange:u,children:t.jsx(TU,{scope:n,onClose:d.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:h,dir:m,modal:l,children:r})})})},"Menu"),tI=d.forwardRef(yt(function(n,s){const{__scopeMenu:r,...a}=n,i=Cm(r);return t.jsx(lT,{...i,...a,ref:s})},"MenuAnchor")),nI="MenuPortal",[RU,sI]=ol(nI,{forceMount:void 0}),PU=yt(e=>{const{__scopeMenu:n,forceMount:s,children:r,container:a}=e,i=gi(nI,n);return t.jsx(RU,{scope:n,forceMount:s,children:t.jsx(Jr,{present:s||i.open,children:t.jsx(lm,{asChild:!0,container:a,children:r})})})},"MenuPortal"),pr="MenuContent",[MU,py]=ol(pr),OU=d.forwardRef(yt(function(n,s){const r=sI(pr,n.__scopeMenu),{forceMount:a=r.forceMount,...i}=n,l=gi(pr,n.__scopeMenu),o=Hu(pr,n.__scopeMenu);return t.jsx(vu.Provider,{scope:n.__scopeMenu,children:t.jsx(Jr,{present:a||l.open,children:t.jsx(vu.Slot,{scope:n.__scopeMenu,children:o.modal?t.jsx(DU,{...i,ref:s}):t.jsx(LU,{...i,ref:s})})})})},"MenuContent")),DU=d.forwardRef(yt(function(n,s){const r=gi(pr,n.__scopeMenu),a=d.useRef(null),i=It(s,a);return d.useEffect(()=>{const l=a.current;if(l)return WT(l)},[]),t.jsx(gy,{...n,ref:i,trapFocus:r.open,disableOutsidePointerEvents:r.open,disableOutsideScroll:!0,onFocusOutside:He(n.onFocusOutside,l=>l.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentModal")),LU=d.forwardRef(yt(function(n,s){const r=gi(pr,n.__scopeMenu);return t.jsx(gy,{...n,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentNonModal")),FU=ti("MenuContent.ScrollLock"),gy=d.forwardRef(yt(function(n,s){const{__scopeMenu:r,loop:a=!1,trapFocus:i,onOpenAutoFocus:l,onCloseAutoFocus:o,disableOutsidePointerEvents:c,onEntryFocus:u,onEscapeKeyDown:h,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:p,onDismiss:v,disableOutsideScroll:g,...k}=n,j=gi(pr,r),x=Hu(pr,r),w=Cm(r),N=ZT(r),y=AU(r),[b,S]=d.useState(null),C=d.useRef(null),A=It(s,C,j.onContentChange),$=d.useRef(0),I=d.useRef(""),P=d.useRef(0),O=d.useRef(null),R=d.useRef("right"),D=d.useRef(0),U=g?my:d.Fragment,W=g?{as:FU,allowPinchZoom:!0}:void 0,M=yt(_=>{var q,ce;const Y=I.current+_,B=y().filter(xe=>!xe.disabled),se=document.activeElement,G=(q=B.find(xe=>xe.ref.current===se))==null?void 0:q.textValue,X=B.map(xe=>xe.textValue),K=fI(X,Y,G),J=(ce=B.find(xe=>xe.textValue===K))==null?void 0:ce.ref.current;yt(function xe(Me){I.current=Me,window.clearTimeout($.current),Me!==""&&($.current=window.setTimeout(()=>xe(""),1e3))},"updateSearch")(Y),J&&setTimeout(()=>J.focus())},"handleTypeaheadSearch");d.useEffect(()=>()=>window.clearTimeout($.current),[]),ym();const L=d.useCallback(_=>{var B,se;return R.current===((B=O.current)==null?void 0:B.side)&&pI(_,(se=O.current)==null?void 0:se.area)},[]);return t.jsx(MU,{scope:r,searchRef:I,onItemEnter:d.useCallback(_=>{L(_)&&_.preventDefault()},[L]),onItemLeave:d.useCallback(_=>{var Y;L(_)||((Y=C.current)==null||Y.focus(),S(null))},[L]),onTriggerLeave:d.useCallback(_=>{L(_)&&_.preventDefault()},[L]),pointerGraceTimerRef:P,onPointerGraceIntentChange:d.useCallback(_=>{O.current=_},[]),children:t.jsx(U,{...W,children:t.jsx(ST,{asChild:!0,trapped:i,onMountAutoFocus:He(l,_=>{var Y;_.preventDefault(),(Y=C.current)==null||Y.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:t.jsx(im,{asChild:!0,disableOutsidePointerEvents:c,onEscapeKeyDown:h,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:p,onDismiss:v,children:t.jsx(zT,{asChild:!0,...N,dir:x.dir,orientation:"vertical",loop:a,currentTabStopId:b,onCurrentTabStopIdChange:S,onEntryFocus:He(u,_=>{x.isUsingKeyboardRef.current||_.preventDefault()}),preventScrollOnEntryFocus:!0,children:t.jsx(oT,{role:"menu","aria-orientation":"vertical","data-state":xy(j.open),"data-radix-menu-content":"",dir:x.dir,...w,...k,ref:A,style:{outline:"none",...k.style},onKeyDown:He(k.onKeyDown,_=>{const B=_.target.closest("[data-radix-menu-content]")===_.currentTarget,se=_.ctrlKey||_.altKey||_.metaKey,G=_.key.length===1;B&&(_.key==="Tab"&&_.preventDefault(),!se&&G&&M(_.key));const X=C.current;if(_.target!==X||!SU.includes(_.key))return;_.preventDefault();const J=y().filter(q=>!q.disabled).map(q=>q.ref.current);JT.includes(_.key)&&J.reverse(),dI(J)}),onBlur:He(n.onBlur,_=>{_.currentTarget.contains(_.target)||(window.clearTimeout($.current),I.current="")}),onPointerMove:He(n.onPointerMove,co(_=>{const Y=_.target,B=D.current!==_.clientX;if(_.currentTarget.contains(Y)&&B){const se=_.clientX>D.current?"right":"left";R.current=se,D.current=_.clientX}}))})})})})})})},"MenuContentImpl")),rI=d.forwardRef(yt(function(n,s){const{__scopeMenu:r,...a}=n;return t.jsx(St.div,{role:"group",...a,ref:s})},"MenuGroup")),_U=d.forwardRef(yt(function(n,s){const{__scopeMenu:r,...a}=n;return t.jsx(St.div,{...a,ref:s})},"MenuLabel")),mv="MenuItem",TN="menu.itemSelect",aI=d.forwardRef(yt(function(n,s){const{disabled:r=!1,onSelect:a,...i}=n,l=d.useRef(null),o=Hu(mv,n.__scopeMenu),c=py(mv,n.__scopeMenu),u=It(s,l),h=d.useRef(!1),f=yt(()=>{const m=l.current;if(!r&&m){const p=new CustomEvent(TN,{bubbles:!0,cancelable:!0});m.addEventListener(TN,v=>a==null?void 0:a(v),{once:!0}),am(m,p),p.defaultPrevented?h.current=!1:o.onClose()}},"handleSelect");return t.jsx(iI,{...i,ref:u,disabled:r,onClick:He(n.onClick,f),onPointerDown:m=>{var p;(p=n.onPointerDown)==null||p.call(n,m),h.current=!0},onPointerUp:He(n.onPointerUp,m=>{var p;h.current||(p=m.currentTarget)==null||p.click()}),onKeyDown:He(n.onKeyDown,m=>{r||m.target!==m.currentTarget||c.searchRef.current!==""&&m.key===" "||fv.includes(m.key)&&(m.currentTarget.click(),m.preventDefault())})})},"MenuItem")),iI=d.forwardRef(yt(function(n,s){const{__scopeMenu:r,disabled:a=!1,textValue:i,...l}=n,o=py(mv,r),c=ZT(r),u=d.useRef(null),h=It(s,u),[f,m]=d.useState(!1),[p,v]=d.useState("");return d.useEffect(()=>{const g=u.current;g&&v((g.textContent??"").trim())},[l.children]),t.jsx(vu.ItemSlot,{scope:r,disabled:a,textValue:i??p,children:t.jsx(UT,{asChild:!0,...c,focusable:!a,children:t.jsx(St.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":a||void 0,"data-disabled":a?"":void 0,...l,ref:h,onPointerMove:He(n.onPointerMove,co(g=>{a?o.onItemLeave(g):(o.onItemEnter(g),g.defaultPrevented||g.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:He(n.onPointerLeave,co(g=>o.onItemLeave(g))),onFocus:He(n.onFocus,()=>m(!0)),onBlur:He(n.onBlur,()=>m(!1))})})})},"MenuItemImpl")),zU="MenuRadioGroup",[UU,BU]=ol(zU,{value:void 0,onValueChange:yt(()=>{},"onValueChange")}),WU=d.forwardRef(yt(function(n,s){const{value:r,onValueChange:a,...i}=n,l=is(a);return t.jsx(UU,{scope:n.__scopeMenu,value:r,onValueChange:l,children:t.jsx(rI,{...i,ref:s})})},"MenuRadioGroup")),HU="MenuRadioItem",KU=d.forwardRef(yt(function(n,s){const{value:r,...a}=n,i=BU(HU,n.__scopeMenu),l=r===i.value;return t.jsx(GU,{scope:n.__scopeMenu,checked:l,children:t.jsx(aI,{role:"menuitemradio","aria-checked":l,...a,ref:s,"data-state":uI(l),onSelect:He(a.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,r)},{checkForDefaultPrevented:!1})})})},"MenuRadioItem")),VU="MenuItemIndicator",[GU,Noe]=ol(VU,{checked:!1}),YU=d.forwardRef(yt(function(n,s){const{__scopeMenu:r,...a}=n;return t.jsx(St.div,{role:"separator","aria-orientation":"horizontal",...a,ref:s})},"MenuSeparator")),lI="MenuSub",[qU,oI]=ol(lI),QU=yt(e=>{const{__scopeMenu:n,children:s,open:r=!1,onOpenChange:a}=e,i=gi(lI,n),l=Cm(n),[o,c]=d.useState(null),[u,h]=d.useState(null),f=is(a);return d.useEffect(()=>(i.open===!1&&f(!1),()=>f(!1)),[i.open,f]),t.jsx(ey,{...l,children:t.jsx(eI,{scope:n,open:r,onOpenChange:f,content:u,onContentChange:h,children:t.jsx(qU,{scope:n,contentId:mr(),triggerId:mr(),trigger:o,onTriggerChange:c,children:s})})})},"MenuSub"),Id="MenuSubTrigger",JU=d.forwardRef(yt(function(n,s){const r=gi(Id,n.__scopeMenu),a=Hu(Id,n.__scopeMenu),i=oI(Id,n.__scopeMenu),l=py(Id,n.__scopeMenu),o=d.useRef(null),{pointerGraceTimerRef:c,onPointerGraceIntentChange:u}=l,h={__scopeMenu:n.__scopeMenu},f=d.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);d.useEffect(()=>f,[f]),d.useEffect(()=>{const p=c.current;return()=>{window.clearTimeout(p),u(null)}},[c,u]);const m=It(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":xy(r.open),...n,ref:m,onClick:p=>{var v;(v=n.onClick)==null||v.call(n,p),!(n.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),r.open||r.onOpenChange(!0))},onPointerMove:He(n.onPointerMove,co(p=>{l.onItemEnter(p),!p.defaultPrevented&&!n.disabled&&!r.open&&!o.current&&(l.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{r.onOpenChange(!0),f()},100))})),onPointerLeave:He(n.onPointerLeave,co(p=>{var g,k;f();const v=(g=r.content)==null?void 0:g.getBoundingClientRect();if(v){const j=(k=r.content)==null?void 0:k.dataset.side,x=j==="right",w=x?-5:5,N=v[x?"left":"right"],y=v[x?"right":"left"];l.onPointerGraceIntentChange({area:[{x:p.clientX+w,y:p.clientY},{x:N,y:v.top},{x:y,y:v.top},{x:y,y:v.bottom},{x:N,y:v.bottom}],side:j}),window.clearTimeout(c.current),c.current=window.setTimeout(()=>l.onPointerGraceIntentChange(null),300)}else{if(l.onTriggerLeave(p),p.defaultPrevented)return;l.onPointerGraceIntentChange(null)}})),onKeyDown:He(n.onKeyDown,p=>{var g;n.disabled||p.target!==p.currentTarget||l.searchRef.current!==""&&p.key===" "||CU[a.dir].includes(p.key)&&(r.onOpenChange(!0),(g=r.content)==null||g.focus(),p.preventDefault())})})})},"MenuSubTrigger")),XU="MenuSubContent",ZU=d.forwardRef(yt(function(n,s){const r=sI(pr,n.__scopeMenu),{forceMount:a=r.forceMount,align:i="start",...l}=n,o=gi(pr,n.__scopeMenu),c=Hu(pr,n.__scopeMenu),u=oI(XU,n.__scopeMenu),h=d.useRef(null),f=It(s,h);return t.jsx(vu.Provider,{scope:n.__scopeMenu,children:t.jsx(Jr,{present:a||o.open,children:t.jsx(vu.Slot,{scope:n.__scopeMenu,children:t.jsx(gy,{id:u.contentId,"aria-labelledby":u.triggerId,...l,ref:f,align:i,side:c.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:m=>{var p;c.isUsingKeyboardRef.current&&((p=h.current)==null||p.focus()),m.preventDefault()},onCloseAutoFocus:m=>m.preventDefault(),onFocusOutside:He(n.onFocusOutside,m=>{m.target!==u.trigger&&o.onOpenChange(!1)}),onEscapeKeyDown:He(n.onEscapeKeyDown,m=>{c.onClose(),m.preventDefault()}),onKeyDown:He(n.onKeyDown,m=>{var g;const p=m.currentTarget.contains(m.target),v=EU[c.dir].includes(m.key);p&&v&&(o.onOpenChange(!1),(g=u.trigger)==null||g.focus(),m.preventDefault())})})})})})},"MenuSubContent"));function xy(e){return e?"open":"closed"}yt(xy,"getOpenState");function cI(e){return e==="indeterminate"}yt(cI,"isIndeterminate");function uI(e){return cI(e)?"indeterminate":e?"checked":"unchecked"}yt(uI,"getCheckedState");function dI(e){const n=document.activeElement;for(const s of e)if(s===n||(s.focus(),document.activeElement!==n))return}yt(dI,"focusFirst");function hI(e,n){return e.map((s,r)=>e[(n+r)%e.length])}yt(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}yt(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,f=c.x,m=c.y;h>r!=m>r&&s<(f-u)*(r-h)/(m-h)+u&&(a=!a)}return a}yt(mI,"isPointInPolygon");function pI(e,n){if(!n)return!1;const s={x:e.clientX,y:e.clientY};return mI(s,n)}yt(pI,"isPointerInGraceArea");function co(e){return n=>n.pointerType==="mouse"?e(n):void 0}yt(co,"whenMouse");var e6=IU,t6=tI,n6=PU,s6=OU,r6=rI,a6=_U,i6=aI,l6=WU,o6=KU,c6=YU,u6=QU,d6=JU,h6=ZU,f6=Object.defineProperty,Fs=(e,n)=>f6(e,"name",{value:n,configurable:!0}),vy="DropdownMenu",[m6,Soe]=Sr(vy,[XT]),_s=XT(),[p6,gI]=m6(vy),g6=Fs(e=>{const{__scopeDropdownMenu:n,children:s,dir:r,open:a,defaultOpen:i,onOpenChange:l,modal:o=!0}=e,c=_s(n),u=d.useRef(null),[h,f]=mi({prop:a,defaultProp:i??!1,onChange:l,caller:vy});return t.jsx(p6,{scope:n,triggerId:mr(),triggerRef:u,contentId:mr(),open:h,onOpenChange:f,onOpenToggle:d.useCallback(()=>f(m=>!m),[f]),modal:o,children:t.jsx(e6,{...c,open:h,onOpenChange:f,dir:r,modal:o,children:s})})},"DropdownMenu"),x6="DropdownMenuTrigger",v6=d.forwardRef(Fs(function(n,s){const{__scopeDropdownMenu:r,disabled:a=!1,...i}=n,l=gI(x6,r),o=_s(r),c=It(s,l.triggerRef);return t.jsx(t6,{asChild:!0,...o,children:t.jsx(St.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:He(n.onPointerDown,u=>{!a&&u.button===0&&u.ctrlKey===!1&&(l.onOpenToggle(),l.open||u.preventDefault())}),onKeyDown:He(n.onKeyDown,u=>{a||(["Enter"," "].includes(u.key)&&l.onOpenToggle(),u.key==="ArrowDown"&&l.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(u.key)&&u.preventDefault())})})})},"DropdownMenuTrigger")),j6=Fs(e=>{const{__scopeDropdownMenu:n,...s}=e,r=_s(n);return t.jsx(n6,{...r,...s})},"DropdownMenuPortal"),w6="DropdownMenuContent",y6=d.forwardRef(Fs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=gI(w6,r),l=_s(r),o=d.useRef(!1);return t.jsx(s6,{id:i.contentId,"aria-labelledby":i.triggerId,...l,...a,ref:s,onCloseAutoFocus:He(n.onCloseAutoFocus,c=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,c.preventDefault()}),onInteractOutside:He(n.onInteractOutside,c=>{const u=c.detail.originalEvent,h=u.button===0&&u.ctrlKey===!0,f=u.button===2||h;(!i.modal||f)&&(o.current=!0)}),style:{...n.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})},"DropdownMenuContent")),b6=d.forwardRef(Fs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=_s(r);return t.jsx(r6,{...i,...a,ref:s})},"DropdownMenuGroup")),k6=d.forwardRef(Fs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=_s(r);return t.jsx(a6,{...i,...a,ref:s})},"DropdownMenuLabel")),N6=d.forwardRef(Fs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=_s(r);return t.jsx(i6,{...i,...a,ref:s})},"DropdownMenuItem")),S6=d.forwardRef(Fs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=_s(r);return t.jsx(l6,{...i,...a,ref:s})},"DropdownMenuRadioGroup")),C6=d.forwardRef(Fs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=_s(r);return t.jsx(o6,{...i,...a,ref:s})},"DropdownMenuRadioItem")),E6=d.forwardRef(Fs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=_s(r);return t.jsx(c6,{...i,...a,ref:s})},"DropdownMenuSeparator")),A6=Fs(e=>{const{__scopeDropdownMenu:n,children:s,open:r,onOpenChange:a,defaultOpen:i}=e,l=_s(n),[o,c]=mi({prop:r,defaultProp:i??!1,onChange:a,caller:"DropdownMenuSub"});return t.jsx(u6,{...l,open:o,onOpenChange:c,children:s})},"DropdownMenuSub"),$6=d.forwardRef(Fs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=_s(r);return t.jsx(d6,{...i,...a,ref:s})},"DropdownMenuSubTrigger")),T6=d.forwardRef(Fs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=_s(r);return t.jsx(h6,{...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")),Ku=g6,Vu=v6,Oo=j6,Gu=y6,jy=b6,Ji=k6,ms=N6,I6=S6,R6=C6,_r=E6,P6=A6,M6=$6,O6=T6,D6=Object.defineProperty,Do=(e,n)=>D6(e,"name",{value:n,configurable:!0}),wy="Tabs",[L6,Coe]=Sr(wy,[km]),xI=km(),[F6,yy]=L6(wy),_6=d.forwardRef(Do(function(n,s){const{__scopeTabs:r,value:a,onValueChange:i,defaultValue:l,orientation:o="horizontal",dir:c,activationMode:u="automatic",...h}=n,f=wm(c),[m,p]=mi({prop:a,onChange:i,defaultProp:l??"",caller:wy});return t.jsx(F6,{scope:r,baseId:mr(),value:m,onValueChange:p,orientation:o,dir:f,activationMode:u,children:t.jsx(St.div,{dir:f,"data-orientation":o,...h,ref:s})})},"Tabs")),z6="TabsList",U6=d.forwardRef(Do(function(n,s){const{__scopeTabs:r,loop:a=!0,...i}=n,l=yy(z6,r),o=xI(r);return t.jsx(zT,{asChild:!0,...o,orientation:l.orientation,dir:l.dir,loop:a,children:t.jsx(St.div,{role:"tablist","aria-orientation":l.orientation,...i,ref:s})})},"TabsList")),B6="TabsTrigger",W6=d.forwardRef(Do(function(n,s){const{__scopeTabs:r,value:a,disabled:i=!1,...l}=n,o=yy(B6,r),c=xI(r),u=by(o.baseId,a),h=ky(o.baseId,a),f=a===o.value;return t.jsx(UT,{asChild:!0,...c,focusable:!i,active:f,children:t.jsx(St.button,{type:"button",role:"tab","aria-selected":f,"aria-controls":h,"data-state":f?"active":"inactive","data-disabled":i?"":void 0,disabled:i,id:u,...l,ref:s,onMouseDown:He(n.onMouseDown,m=>{!i&&m.button===0&&m.ctrlKey===!1?o.onValueChange(a):m.preventDefault()}),onKeyDown:He(n.onKeyDown,m=>{i||m.target!==m.currentTarget||[" ","Enter"].includes(m.key)&&o.onValueChange(a)}),onFocus:He(n.onFocus,()=>{const m=o.activationMode!=="manual";!f&&!i&&m&&o.onValueChange(a)})})})},"TabsTrigger")),H6="TabsContent",K6=d.forwardRef(Do(function(n,s){const{__scopeTabs:r,value:a,forceMount:i,children:l,...o}=n,c=yy(H6,r),u=by(c.baseId,a),h=ky(c.baseId,a),f=a===c.value,m=d.useRef(f);return d.useEffect(()=>{const p=requestAnimationFrame(()=>m.current=!1);return()=>cancelAnimationFrame(p)},[]),t.jsx(Jr,{present:i||f,children:({present:p})=>t.jsx(St.div,{"data-state":f?"active":"inactive","data-orientation":c.orientation,role:"tabpanel","aria-labelledby":u,hidden:!p,id:h,tabIndex:0,...o,ref:s,style:{...n.style,animationDuration:m.current?"0s":void 0},children:p&&l})})},"TabsContent"));function by(e,n){return`${e}-trigger-${n}`}Do(by,"makeTriggerId");function ky(e,n){return`${e}-content-${n}`}Do(ky,"makeContentId");var V6=_6,G6=U6,Y6=W6,q6=K6;function kn(e,n,s){if(e==null)return"—";switch(n){case"currency":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?Q6(r,s):String(e)}case"percent":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?`${IN(r)}%`:String(e)}case"number":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?Number.isInteger(r)?mn(r):IN(r):String(e)}case"date":return J6(String(e));default:return typeof e=="string"?e:typeof e=="number"?mn(e):typeof e=="boolean"?e?"yes":"no":JSON.stringify(e)??String(e)}}function Q6(e,n){if(!(Math.abs(e)<1e3&&!Number.isInteger(e)))return Qz(e,n);try{return new Intl.NumberFormat("en-US",{style:"currency",currency:n??"USD",maximumFractionDigits:2}).format(e)}catch{return e.toFixed(2)}}function J6(e){const n=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);return n?Po(n[0],{year:!0,compact:!0}):e}function pv(e){const n=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);return n?Po(n[0],{compact:!0}):e}function IN(e){return String(Math.round(e*100)/100)}function af(e,n,s=4){if(!Number.isFinite(e)||!Number.isFinite(n))return[];if(e===n)return[e];const r=(n-e)/Math.max(1,s),a=10**Math.floor(Math.log10(r)),i=[1,2,2.5,5,10].map(o=>o*a).find(o=>o>=r)??a*10,l=[];for(let o=Math.ceil(e/i)*i;o<=n+i/1e3;o+=i)l.push(Math.round(o*1e6)/1e6);return l.filter(o=>o>=e&&o<=n)}function X6({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:kn(i.value,e.unit,e.currency)})]},i.category)})})}const Z6=/^(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 )/,eB=/^(… |\.\.\. |\(no change\)$|\)/;function tB(e){return e.replace(/\n$/,"").split(`
90
+ `).map(s=>({kind:nB(s),text:s}))}function nB(e){return e.startsWith("@@")?"hunk":Z6.test(e)||eB.test(e)?"meta":e.startsWith("+")?"add":e.startsWith("-")?"del":"context"}function sB({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 lf({text:e,limit:n,more:s,label:r="Diff",marks:a}){const i=tB(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(sB,{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 rB({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:kn(n.value,n.unit,null)})]},n.label))}):null,e.diff?t.jsx(lf,{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 Tn="#/",uo="#/needs",pa="#/chat",bt="#/agents",Jt="#/activity",hn="#/settings",ba="#/files",aB="#/welcome";function vh(e){const n=/^#\/welcome(?:\?(.*))?$/.exec(e);if(!n)return null;try{return{step:new URLSearchParams(n[1]??"").get("step")}}catch{return{step:null}}}function wc(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`${ba}${e?`/${encodeURIComponent(e)}`:""}${r?`?${r}`:""}`}function iB(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 lt(e,n,s){return`#/chat/${encodeURIComponent(e)}${n?`/${encodeURIComponent(n)}`:""}${s?`?tab=${s}`:""}`}function lB(e){if(vI(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 Ii(e,n){return`#/chat/g/${encodeURIComponent(e)}${n?`/${encodeURIComponent(n)}`:""}`}function vI(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 Dt(e,n,s){return`${bt}/${encodeURIComponent(e)}${n?`/${n}${s?`/${s}`:""}`:""}`}function oB(e){const n=/^#\/agents\/([^/]+)(?:\/([a-z-]+)(?:\/([a-z-]+))?)?$/.exec(e);if(!n||n[1]===jI)return null;try{return{agentId:decodeURIComponent(n[1]),...n[2]?{tab:n[2]}:{},...n[3]?{section:n[3]}:{}}}catch{return null}}const jI="catalogue",RN=`${bt}/${jI}`;function pn(e){return e?`${RN}/${encodeURIComponent(e)}`:RN}function cB(e){return`${pn(e)}?add=1`}function uB(e,n){const s=/^#\/agents\/catalogue\/([a-z0-9-]+)\?(?:.*&)?add=1(?:&|$)/.exec(e);return(s==null?void 0:s[1])===n}function dB(e){const n=/^#\/agents\/catalogue(?:\/([a-z0-9-]+))?(?:\?.*)?$/.exec(e);return n?n[1]?{name:n[1]}:{}:null}function ju(e){return`${Jt}/conversations/${encodeURIComponent(e)}`}const hB="#/p";function Yr(e,n,s){const r=`${hB}/${encodeURIComponent(e)}/${encodeURIComponent(n)}`;return s?`${r}/${encodeURIComponent(s)}`:r}function Ny(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 fB="p.";function vr(e,n=e,s){const r=s?new URLSearchParams(s).toString():"";return`${hn}/${encodeURIComponent(yI(e,n))}${r?`?${r}`:""}`}function mB(e,n){const s=wI(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=Sy(e);return vr(s.plugin,r[0].id,Object.keys(a).length>0?a:void 0)}function Sy(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 wI(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 yI(e,n){return`${fB}${e}${n===e?"":`.${n}`}`}function _e(e){return e?`${hn}/${e}`:hn}function bI(e){return`${_e("accounts")}?account=${encodeURIComponent(e)}`}function pB(e){const n=/^#\/settings\/accounts\?(.*)$/.exec(e);if(!n)return null;try{return new URLSearchParams(n[1]).get("account")||null}catch{return null}}function wu(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 kI(e){return`${_e("connections")}?connection=${encodeURIComponent(e)}`}function PN(e){const n=(wu(e,"computer","code")??wu(e,"browser","code")??"").replace(/[\s-]/g,"");return/^\d{6}$/.test(n)?n:null}function gB(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 xB(e){return wu(e,"connections","connection")}const vB=_e("computer");function jB(e){return wu(e,"secrets","secret")}const gv=`${_e("secrets")}?add=1`;function wB(e){return wu(e,"secrets","add")==="1"}function yB(e){return`${_e("plugins")}?install=${encodeURIComponent(e)}`}const xv=`${_e("plugins")}?tab=browse`;function vv(e="all"){return e==="all"?xv:`${xv}&kind=${e}`}function bB(e){return`${_e("proposals")}${e?`?plugin=${encodeURIComponent(e)}`:""}`}function kB(e){const n=/^#\/settings\/proposals\?(.*)$/.exec(e);if(!n)return null;try{return new URLSearchParams(n[1]).get("plugin")||null}catch{return null}}function Cy(e){const n=/^#\/settings\/plugins\?(.*)$/.exec(e);if(!n)return null;try{return new URLSearchParams(n[1])}catch{return null}}function NB(e){var s,r;const n=(r=(s=Cy(e))==null?void 0:s.get("install"))==null?void 0:r.trim();return n||null}function MN(e){var s;const n=(s=Cy(e))==null?void 0:s.get("kind");return n==="plugins"||n==="widgets"||n==="agents"?n:"all"}function ON(e){const n=Cy(e);return n!=null&&n.get("install")?"installed":(n==null?void 0:n.get("tab"))==="browse"?"browse":"installed"}const SB=[{route:Tn,label:"Home"},{route:pa,label:"Chat"},{route:bt,label:"Agents"},{route:Jt,label:"Activity"},{route:ba,label:"Files"},{route:hn,label:"Settings"}],CB=[{id:"you",label:"You"},{id:"access",label:"Models and access"},{id:"running",label:"Running"},{id:"plugins",label:"Plugins"}],EB=[{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 AB(e){var n;return((n=/^#\/settings\/([a-z0-9.-]+)/.exec(e))==null?void 0:n[1])??"you"}const jv="#/settings/notifications/recent",wv=_e("backup");function $B(e){const n=/^#\/conversations\/(.+)$/.exec(e);if(n)return ju(decodeURIComponent(n[1]));const s=/^#\/email(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(s)try{return Yr("email","mail",s[1]?decodeURIComponent(s[1]):null)}catch{return Yr("email","mail")}if(e==="#/settings/email")return vr("email","settings");const r=/^#\/settings\/browser(\?.*)?$/.exec(e);return r?`${_e("computer")}${r[1]??""}`:{"#/overview":Tn,"#/approvals":Tn,"#/events":`${Jt}/events`,"#/jobs":`${Jt}/jobs`,"#/conversations":Jt,"#/missions":`${bt}?tab=missions`,"#/offers":`${bt}?tab=offers`,"#/reminders":`${bt}?tab=reminders`,"#/providers":_e("accounts"),"#/browser":_e("computer"),"#/sentinels":_e("watchers"),"#/settings/sentinels":_e("watchers")}[e]??null}function NI(e){if(e===""||e==="#"||e===Tn)return Tn;if(e.startsWith(pa))return pa;if(e.startsWith(bt))return bt;if(e.startsWith(Jt))return Jt;if(e.startsWith(ba))return ba;if(e.startsWith(hn))return hn;const n=Ny(e);return n?Yr(n.plugin,n.page):Tn}const TB="#/chat?group=new";function IB(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 Yu="front-desk",Ey=[{id:Yu,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."}],SI=new Set(Ey.map(e=>e.id)),DN=e=>SI.has(e);function LN(e,n){const s=n.filter(r=>!SI.has(r));return[...Ey.filter(r=>e.has(r.id)).map(r=>r.id),...s.filter((r,a)=>s.indexOf(r)===a)]}function RB(e,n){return e.find(s=>(s.roles??[]).includes(n))}const FN=["coding","finance","mail","research","calendar","files","memory"],PB={developer:"coding",coding:"coding",finance:"finance",credit:"finance",mail:"mail",email:"mail",research:"research",calendar:"calendar",files:"files",memory:"memory",[Yu]:"buddi"},MB=[["mail",["email"]],["finance",["finance"]],["coding",["developer"]],["research",["web","browser"]],["art",["image"]]];function OB(e){const n=new Set(e.map(s=>s.split(".")[0]??s));for(const[s,r]of MB)if(r.some(a=>n.has(a)))return s;return n.size>0&&[...n].every(s=>s==="memory")?"memory":null}let yv=null;function DB(e){yv=e}function Lo(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=PB[s];if(r)return{key:r}}const n=OB(e.tools??[]);return n?{key:n}:yv!==null&&e.id===yv?{key:"buddi"}:{key:FN[LB(e.id)%FN.length]??"coding"}}function Xi(e){return e.key==="own"?{"data-agent":"own",style:{"--agent-fill":e.hex}}:{"data-agent":e.key}}function LB(e){let n=0;for(const s of e)n=(n*31+s.charCodeAt(0))%997;return n}const FB=["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 _B(e){const s=e.replace(/\r\n/g,`
91
+ `).split(`
92
+
93
+ `),r=s.pop()??"",a=[];for(const i of s){let l=null,o="message";const c=[];for(const u of i.split(`
94
+ `)){if(u===""||u.startsWith(":"))continue;const h=u.indexOf(":"),f=h===-1?u:u.slice(0,h),m=h===-1?"":u.slice(h+1).replace(/^ /,"");f==="id"?l=m:f==="event"?o=m:f==="data"&&c.push(m)}c.length===0&&o==="message"||a.push({id:l,name:FB.includes(o)?o:"ping",data:zB(c.join(`
95
+ `))})}return{events:a,rest:r}}function zB(e){if(e==="")return{};try{const n=JSON.parse(e);return n!==null&&typeof n=="object"?n:{value:n}}catch{return{value:e}}}function Em(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,f,m,p;for(;!i;){(u=e.onStatus)==null||u.call(e,"connecting"),o=new AbortController;try{const v=await n(e.url,{credentials:"same-origin",signal:o.signal,headers:{Accept:"text/event-stream",...a===null?{}:{"Last-Event-ID":a}}});if(!v.ok||!v.body)throw new Error(`stream ${v.status}`);(h=e.onStatus)==null||h.call(e,"open"),l&&((f=e.onReconnect)==null||f.call(e));const g=v.body.getReader(),k=new TextDecoder;let j="";for(;;){const{done:x,value:w}=await g.read();if(x)break;j+=k.decode(w,{stream:!0});const{events:N,rest:y}=_B(j);j=y;for(const b of N)e.onEvent(b),b.id!==null&&(a=b.id);if(i)break}}catch{}if(i)break;l=!0,(m=e.onStatus)==null||m.call(e,"closed"),await s(r)}(p=e.onStatus)==null||p.call(e,"closed")})(),{close:()=>{i=!0,o==null||o.abort()},lastEventId:()=>a}}const Ay="0.1.0+249fc27";function $y(e,n=Ay){return typeof e=="string"&&e!==""&&typeof n=="string"&&n!==""&&e!==n}function UB(){var e;try{if((e=window.matchMedia)!=null&&e.call(window,"(display-mode: standalone)").matches)return!0}catch{}return window.navigator.standalone===!0}const BB=5*6e4,WB=6e4,HB=5e3,yu="buddi:stream-reconnected",CI="buddi.autoReloadedFor";function KB(){window.dispatchEvent(new Event(yu))}const _N=["keydown","pointerdown","pointermove","wheel","touchstart","input"];let Ty=Date.now(),Rd=0;const zN=()=>{Ty=Date.now()};function VB(){if(Rd===0){Ty=Date.now();for(const e of _N)window.addEventListener(e,zN,{capture:!0,passive:!0})}return Rd+=1,()=>{if(Rd-=1,Rd===0)for(const e of _N)window.removeEventListener(e,zN,{capture:!0})}}function GB(e=Date.now()){return e-Ty}function EI(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 YB(e){return e.hidden?!0:e.idleMs>=WB&&!e.busy}function qB(e){try{return window.sessionStorage.getItem(CI)===e}catch{return!1}}function QB(e){try{window.sessionStorage.setItem(CI,e)}catch{}}function JB(e){const n=d.useRef(e);n.current=e,d.useEffect(()=>{const s=()=>n.current();return window.addEventListener(yu,s),()=>window.removeEventListener(yu,s)},[])}function XB(e,n=()=>window.location.reload(),s=Ay){const r=$y(e,s),a=d.useRef(n);a.current=n,d.useEffect(()=>VB(),[]),d.useEffect(()=>{if(!r||e===void 0||qB(e))return;let i=!1;const l=()=>{if(i)return;const c=document.visibilityState==="hidden";YB({hidden:c,idleMs:GB(),busy:EI()})&&(i=!0,QB(e),a.current())};l();const o=window.setInterval(l,HB);return document.addEventListener("visibilitychange",l),()=>{window.clearInterval(o),document.removeEventListener("visibilitychange",l)}},[r,e])}const ZB=9e4,AI=5*6e4,e5=500,t5=2e3,n5=3e3,s5="/_buddi/ready",Xl={reload:()=>window.location.reload(),now:()=>Date.now()};let ri=null,Ul=null,yc=null;const bv=new Set;function of(e){ri=e;for(const n of bv)n()}function UN(){return ri}function r5(e){return bv.add(e),()=>bv.delete(e)}function a5(){const e=new Uint8Array(32);return crypto.getRandomValues(e),[...e].map(n=>n.toString(16).padStart(2,"0")).join("")}async function Iy(e=n5){const n=new AbortController,s=setTimeout(()=>n.abort(),e);try{const r=await fetch(`${s5}?challenge=${a5()}`,{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 i5(){const e=await Iy();e&&(Ul=e)}function l5(){let e=Ul,n=!1,s=!1,r=e5,a;const i=async()=>{if(n)return;const l=await Iy();if(!n){if(l===null)s=!0;else if(e!==null?l!==e:s){n=!0,Xl.reload();return}else e===null&&l!==""&&(e=l);r=Math.min(Math.round(r*1.5),t5),a=setTimeout(()=>void i(),r)}};return a=setTimeout(()=>void i(),r),()=>{n=!0,clearTimeout(a)}}function Am(e){if(ri){if(e.kind==="detected")return;of({...ri,...e});return}of({...e,startedAt:Xl.now()}),yc=l5()}function $I(e){ri&&of({...ri,...e})}function ho(){yc==null||yc(),yc=null,of(null)}async function qu(e,n){Am(e);try{return await n()}catch(s){if(rf(s))return;throw ho(),s}}function o5(e){Am({kind:e.for==="stop"?"stop":"detected"})}async function BN(){if(ri)return;const e=await Iy();if(Ul===null){e&&(Ul=e);return}if(!(!e||e===Ul||ri)){if(EI()){Ul=e;return}Am({kind:"detected"})}}function c5(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 cf(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 uf="buddi:plugin-pages-changed";function Ry(){window.dispatchEvent(new Event(uf))}const kv="buddi:plugin-data-changed",u5=500;function d5(e){window.dispatchEvent(new CustomEvent(kv,{detail:e}))}function h5(e,n,s=u5){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(kv,i),()=>{window.removeEventListener(kv,i),a!==void 0&&clearTimeout(a)}},[e,s])}function TI(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(uf,a),document.addEventListener("visibilitychange",i),()=>{r=!0,window.removeEventListener(uf,a),document.removeEventListener("visibilitychange",i)}},[e]),{all:n,rail:cf(n,"rail"),settings:cf(n,"settings"),find:(r,a)=>n.find(i=>i.plugin===r&&i.id===a)}}function Nv(e,n){const s=(n??[]).filter(i=>i.plugin===e),r=cf(s,"rail")[0]??cf(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 f5="/api/chat/attention/stream";function II(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 RI(e,n){const s=II(e,n);return[...s.top,...s.middle,...s.bottom]}function Qu(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 m5(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 p5(e,n){return e&&(e.approvals>0||e.question)?"needs":n?"working":null}function g5(e){return new Map(((e==null?void 0:e.agents)??[]).map(n=>[n.agentId,n]))}function x5(){const[e,n]=d.useState(null);return d.useEffect(()=>{let s=!1;const r=()=>{ge("/chat/attention").then(i=>{s||n(i)}).catch(()=>{})};r();const a=Em({url:f5,onEvent:i=>{i.name==="closing"?o5(i.data):i.name==="plugins-changed"?Ry():i.name==="pages.changed"?typeof i.data.plugin=="string"&&d5(i.data.plugin):r()},onReconnect:KB});return()=>{s=!0,a.close()}},[]),g5(e)}const jr="maker";function Py(e){return e.filter(n=>n.available&&!n.roles.includes(jr))}function PI(e){return Py(e).length>=2}function v5(e){var n;return((n=e.find(s=>s.roles.includes(jr)))==null?void 0:n.name)??"the agent maker"}const j5="{{default}}";function w5(e,n){return e.split(j5).join(n??"your assistant")}function y5(e,n){return((e==null?void 0:e.starters)??[]).slice(0,3).map(s=>w5(s,n))}function b5(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 k5(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 MI(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 N5="Settings → Model accounts",S5="Install it in Settings → Plugins";function Sv(e){return e!=null&&e.heldBack?{section:"plugins",label:S5}:{section:"accounts",label:N5}}const C5={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 ie({name:e,size:n,className:s,...r}){const[a,i,l,o]=C5[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 OI="buddi.rosterHidden",DI=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform||navigator.userAgent),WN=DI?"⌘\\":"Ctrl+\\",HN=DI?"Meta+\\":"Control+\\";function E5(){try{return window.localStorage.getItem(OI)==="1"}catch{return!1}}function KN(e){try{window.localStorage.setItem(OI,e?"1":"0")}catch{}}function LI({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 f=[...e.top,...e.middle,...e.bottom],m=a==="vertical"?"right":"bottom",[p,v]=d.useState(E5),g=j=>t.jsx(A5,{agent:j,active:j.id===n,attention:s.get(j.id),side:m,onSelect:r,lastAt:(i==null?void 0:i.get(j.id))??null,working:(l==null?void 0:l.has(j.id))??!1},j.id),k=()=>v(j=>(KN(!j),!j));if(d.useEffect(()=>{if(a!=="vertical")return;const j=x=>{x.key!=="\\"||!(x.metaKey||x.ctrlKey)||x.altKey||x.shiftKey||(x.preventDefault(),v(w=>(KN(!w),!w)))};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[a]),a==="vertical"&&p){const j=f.some(x=>Qu(s.get(x.id))!==null);return t.jsxs("button",{type:"button",className:"wb-roster-tab","data-testid":"agent-rail-tab","aria-label":j?"Show the list — someone is waiting for you":"Show the list","aria-keyshortcuts":HN,title:`Show the list (${WN})`,onClick:k,children:[t.jsx(ie,{name:"chevron-right"}),j?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":HN,title:`Hide the list (${WN})`,onClick:k,children:t.jsx(ie,{name:"chevron-left"})})]}):null,t.jsxs("div",{className:"wb-agent-scroll",children:[e.middle.map(g),u&&PI(f)?t.jsxs("div",{className:"wb-groups","data-testid":"group-rail",children:[t.jsx("span",{className:"wb-agent-sep","aria-hidden":"true"}),t.jsxs("div",{className:"wb-groups-head",children:[t.jsx("span",{className:"wb-groups-label",children:"Groups"}),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(ie,{name:"plus"})}):null]}),o.map(j=>t.jsxs("button",{type:"button",className:"wb-face wb-group-face","data-active":j.id===c?"true":void 0,"aria-current":j.id===c?"true":void 0,"aria-label":`${j.name}, ${j.members.length} agents`,onClick:()=>u(j.id),children:[t.jsx("span",{className:"wb-group-stack","aria-hidden":"true",children:j.members.slice(0,2).map(x=>{const w=f.find(N=>N.id===x);return t.jsx($m,{className:"wb-group-chip",id:x,name:(w==null?void 0:w.name)??"?",face:w,initials:1},x)})}),t.jsxs("span",{className:"wb-face-text",children:[t.jsx("span",{className:"wb-face-name",children:j.name}),t.jsx("span",{className:"wb-face-status",children:j.members.map(x=>{var w;return((w=f.find(N=>N.id===x))==null?void 0:w.name)??x}).join(", ")})]})]},j.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:bt,children:"add a teammate"}),"."]})]}):null]}),e.bottom.map(g)]})}function A5({agent:e,active:n,attention:s,side:r,onSelect:a,lastAt:i=null,working:l=!1}){const o=Qu(s),c=m5(s)??(e.available?i?wT(i):e.description:e.unavailableReason??"Cannot run right now"),u=p5(s,l&&e.available),h=e.unavailableReason??"This agent cannot run on this machine right now.",f=[`${e.name} @${e.handle}`,e.available?null:"unavailable",o,u==="working"?"working now":null,n?"current":null].filter(m=>m!==null&&m!=="").join(" — ");return t.jsxs(du,{children:[t.jsx(hu,{asChild:!0,children:t.jsxs("button",{className:"wb-face",...Xi(Lo(e)),"data-active":n?"true":void 0,"data-unavailable":e.available?void 0:"true","data-testid":`agent-face-${e.id}`,"aria-label":f,"aria-current":n?"true":void 0,disabled:!e.available,onClick:()=>e.available&&a(e.id),children:[t.jsxs("span",{className:"wb-face-frame",children:[t.jsx($m,{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(ie,{name:"out"})})]})}),t.jsx(fu,{children:t.jsxs(mu,{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:$5(o)}):null]})})]})}function $5(e){return`${e.slice(0,1).toUpperCase()}${e.slice(1)}.`}function T5(e){let n=0;for(const s of e)n=(n*31+s.charCodeAt(0))%997;return n%6+1}const I5="modulepreload",R5=function(e,n){return new URL(e,n).href},VN={},P5=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=R5(u,r),u in VN)return;VN[u]=!0;const h=u.endsWith(".css"),f=h?'[rel="stylesheet"]':"";if(!!r)for(let v=l.length-1;v>=0;v--){const g=l[v];if(g.href===u&&(!h||g.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${u}"]${f}`))return;const p=document.createElement("link");if(p.rel=h?"stylesheet":I5,h||(p.as="script"),p.crossOrigin="",p.href=u,c&&p.setAttribute("nonce",c),document.head.appendChild(p),h)return new Promise((v,g)=>{p.addEventListener("load",v),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)})},M5="buddi",O5=["core","coding","finance","garage","mail","maker","playground","research"],xi=e=>`./mascot/${e}.png`,D5=["core"],Cv=(e,n)=>D5.includes(e)?`./mascot/anim/${e}-${n}.json`:null,L5=["🙂","📚","🧭","🦊","🛟","🌿","🛠️","🎧"],F5="Introduce yourself by name and say one thing you can do today.",_5=["Hello","A brain","What I take on","Reach me","Your assistant"],Pd=(e,n=!1)=>e.length<2?e.join(""):`${e.slice(0,-1).join(", ")}${n&&e.length>2?", and ":" and "}${e[e.length-1]}`,Yp=e=>e.charAt(0).toUpperCase()+e.slice(1),z5=["No","One","Two","Three","Four","Five","Six","Seven","Eight"],df=[{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."}],U5=["days","mail"],GN=[{id:"buddi",role:"core",label:"Blue"},{id:"mail",role:"mail",label:"Orange"},{id:"finance",role:"finance",label:"Green"},{id:"coding",role:"coding",label:"Violet"},{id:"research",role:"research",label:"Purple"}],z={tagline:"Setting up, on this Mac.",taglineElsewhere:"Setting up, on this computer.",chapters:_5,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 ${Pd(e)} from withbuddi.com and reading them. ${n} of ${s}.`,ready:e=>`${Pd(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":Yp(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":Yp(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: ${Pd(e)}, waiting to be introduced.`,name:"Name",face:"A face",colour:"A colour for the face",swatch:e=>`Colour: ${e.toLowerCase()}`,mascot:e=>e==="core"?"Buddi Blob":`Buddi Blob, ${e}`,purpose:"How it works",purposeHint:"Plain text. It becomes the assistant’s file, which is yours from then on.",purposeValue:["You're not a chatbot. You're becoming someone this person can count on.","","Some starting truths:","",`- Help for real. No "Great question", no "I'd be happy to". Do the thing, then say what you did.`,"- Have a view. Prefer things, disagree when you should, say when something is a bad idea. A search engine with manners is not a colleague.","- Look before you ask. Read the file, check what you remember, try it. Come back with an answer and one question at most.","- You are a guest here. You can see messages, files and a calendar. Treat that with care, keep what you learn to yourself, and never lecture.","- Remember what matters. Names, preferences, the things they said once and expect you to keep.","- When you change how you work, say so. This file is yours to grow, and the owner should always know what it says."].join(`
96
+ `),submit:"Introduce us",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=>`${z5[e]??String(e)} ${e===1?"thing":"things"} still waiting.`,waitingBody:e=>`${Yp(Pd(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 Md=null;const YN=new Map;function B5(){return Md??(Md=P5(()=>import("./lottie_light-vNpJ-Svm.js").then(e=>e.l),[],import.meta.url).then(e=>e.default)),Md.catch(()=>{Md=null}),Md}function W5(e){let n=YN.get(e);return n||(n=fetch(e).then(s=>s.ok?s.text():null).catch(()=>null),YN.set(e,n)),n}const qN="(prefers-reduced-motion: reduce)";function FI(){const[e,n]=d.useState(()=>typeof window.matchMedia=="function"&&!window.matchMedia(qN).matches);return d.useEffect(()=>{var a;if(typeof window.matchMedia!="function")return;const s=window.matchMedia(qN),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 Ju({role:e="core",state:n,size:s,still:r,className:a,onStillError:i}){const l=d.useRef(null),o=FI(),[c,u]=d.useState(!1),h=s==="xs"?null:Cv(e,n);return d.useEffect(()=>{if(u(!1),!o||!h)return;let f=!1,m=null;return Promise.all([B5(),W5(h)]).then(([p,v])=>{if(f||!v||!l.current)return;const g=p.loadAnimation({container:l.current,renderer:"svg",loop:!0,autoplay:!document.hidden,animationData:JSON.parse(v),rendererSettings:{preserveAspectRatio:"xMidYMid meet"}}),k=()=>{document.hidden?g.pause():g.play()};document.addEventListener("visibilitychange",k),m=()=>{document.removeEventListener("visibilitychange",k),g.destroy()},u(!0)}).catch(()=>{}),()=>{f=!0,m==null||m()}},[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??xi(e),alt:"",onError:i})})}async function QN(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 _I(e,n="core"){const s=FI(),r=e!==null&&H5(e,n),[a,i]=d.useState(!1);return d.useEffect(()=>{if(i(!1),!e||r||!s||!Cv(n,"idle"))return;let l=!1;return Promise.all([QN(e),QN(xi(n))]).then(([o,c])=>{if(l||!o||!c||o.length!==c.length)return;const u=o.reduce((h,f,m)=>h+Math.abs(f-c[m]),0)/o.length;i(u<12)}).catch(()=>{}),()=>{l=!0}},[e,r,s,n]),s&&Cv(n,"idle")!==null&&(r||a)}function H5(e,n){const s=xi(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 $m({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,f=r==null?void 0:r.avatar,m=h?"image":f==null?void 0:f.kind,p=n?Xi(Lo({id:n,accent:r==null?void 0:r.accent,roles:r==null?void 0:r.roles,tools:r==null?void 0:r.tools})):void 0;return t.jsx("span",{className:e,"data-tint":p?void 0:a,"data-size":i,"data-kind":m,"data-unavailable":l?"true":void 0,...p,"aria-hidden":"true",children:h?t.jsx("img",{src:h,alt:"",onError:()=>u(h)}):(f==null?void 0:f.kind)==="image"?t.jsx("img",{src:f.url,alt:""}):(f==null?void 0:f.kind)==="emoji"?f.value:k5(s).slice(0,o)})}function In({id:e,name:n,size:s,unavailable:r,face:a}){return t.jsx($m,{className:"ui-avatar",id:e,tint:T5(e),name:n,size:s,unavailable:r,face:a})}const zI="owner",Tm="buddi";function Im(e){return e===zI}function K5(e,n=[]){var s;return Im(e)?Tm:((s=n.find(r=>r.id===e))==null?void 0:s.name)??e}function UI({size:e}){return t.jsx(In,{id:zI,name:Tm,size:e,face:{picture:xi("core")}})}function an({agents:e,id:n,size:s}){if(Im(n))return t.jsx(UI,{size:s});const r=e.find(a=>a.id===n);return t.jsx(In,{id:n,name:(r==null?void 0:r.name)??n,size:s,unavailable:r?!r.available:!1,face:r})}const BI=d.createContext(null);function V5({picture:e,children:n}){return t.jsx(BI.Provider,{value:e??null,children:n})}function WI({size:e,anim:n}){const s=d.useContext(BI),[r,a]=d.useState(null),i=_I(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(Ju,{state:n,still:s,className:"ui-mascot-blob",onStillError:()=>a(s)}):t.jsx("img",{src:s,alt:"",onError:()=>a(s)})})}const HI=d.createContext([]);function wr({text:e,className:n}){const s=Ev(e.replace(/\r\n/g,`
97
+ `).split(`
98
+ `));return t.jsx("div",{className:n??"wb-md",children:s.map((r,a)=>t.jsx(Av,{block:r},a))})}const JN=/^(\s*)(```|~~~)\s*([\w+-]*)\s*$/,XN=/^(#{1,6})\s+(.*?)\s*#*\s*$/,ZN=/^\s*([-*_])(\s*\1){2,}\s*$/,Od=/^(\s*)([-*+])\s+(.*)$/,oc=/^(\s*)(\d{1,9})[.)]\s+(.*)$/,Dd=/^\s*>\s?(.*)$/,qp=/^\s*\|.*\|\s*$/,eS=/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/;function Ev(e){const n=[];let s=0;for(;s<e.length;){const r=e[s];if(r.trim()===""){s+=1;continue}const a=JN.exec(r);if(a){const o=a[2],c=[];for(s+=1;s<e.length&&!new RegExp(`^\\s*${o}\\s*$`).test(e[s]);)c.push(e[s]),s+=1;s+=1,n.push({type:"code",lang:a[3]||null,text:c.join(`
99
+ `)});continue}const i=XN.exec(r);if(i){n.push({type:"h",level:i[1].length,text:i[2]}),s+=1;continue}if(ZN.test(r)){n.push({type:"hr"}),s+=1;continue}if(Dd.test(r)){const o=[];for(;s<e.length&&Dd.test(e[s]);)o.push(Dd.exec(e[s])[1]),s+=1;n.push({type:"quote",blocks:Ev(o),raw:o.join(`
100
+ `)});continue}if(qp.test(r)&&s+1<e.length&&eS.test(e[s+1])){const o=Jp(r),c=Jp(e[s+1]).map(h=>{const f=h.startsWith(":"),m=h.endsWith(":");return f&&m?"center":m?"right":f?"left":null});s+=2;const u=[];for(;s<e.length&&qp.test(e[s]);)u.push(Jp(e[s])),s+=1;n.push({type:"table",head:o,rows:u,align:c});continue}if(Od.test(r)||oc.test(r)){const o=oc.exec(r)??Od.exec(r),c=oc.test(r),u=o[1].length,h=c?Number(o[2]):1,f=[];for(;s<e.length;){const m=c?oc.exec(e[s]):Od.exec(e[s]);if(!m||m[1].length!==u)break;const p=[m[3]];for(s+=1;s<e.length;){const v=e[s],g=v.trim()!==""&&Qp(v)>u,k=v.trim()===""&&s+1<e.length&&e[s+1].trim()!==""&&Qp(e[s+1])>u;if(!g&&!k)break;p.push(v.trim()===""?"":v.slice(Math.min(Qp(v),u+2))),s+=1}f.push(Ev(p))}n.push({type:"list",ordered:c,start:h,items:f});continue}const l=[];for(;s<e.length;){const o=e[s];if(o.trim()===""||JN.test(o)||XN.test(o)||ZN.test(o)||Dd.test(o)||Od.test(o)||oc.test(o)||qp.test(o)&&s+1<e.length&&eS.test(e[s+1]))break;l.push(o.trim()),s+=1}l.length>0&&n.push({type:"p",text:l.join(`
101
+ `)})}return n}function Qp(e){return e.length-e.trimStart().length}function Jp(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 Av({block:e}){switch(e.type){case"p":return t.jsx("p",{children:cr(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:cr(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(tS,{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(Av,{block:n},s))}),t.jsx(tS,{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:cr(a.text)},i):t.jsx(Av,{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:cr(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:cr(r)},a))},s))})]})})}}function tS({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 G5({handle:e}){const s=d.useContext(HI).find(r=>r.handle.toLowerCase()===e.toLowerCase());return s?t.jsxs(du,{children:[t.jsx(hu,{asChild:!0,children:t.jsxs("a",{className:"wb-mention-link",href:lt(s.id),children:["@",s.handle]})}),t.jsx(fu,{children:t.jsxs(mu,{className:"wb-agent-card",sideOffset:6,children:[t.jsx(In,{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 Y5=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 cr(e){const n=[];let s=e,r=0;for(;s!=="";){const a=Y5.exec(s);if(!a){n.push(...nS(s,r));break}a.index>0&&n.push(...nS(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:cr(a[3])},r)):a[4]!==void 0?n.push(t.jsx("strong",{children:cr(a[4])},r)):a[5]!==void 0?n.push(t.jsx("s",{children:cr(a[5])},r)):a[6]!==void 0?n.push(t.jsx("em",{children:cr(a[6])},r)):a[7]!==void 0?n.push(t.jsx("em",{children:cr(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:cr(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(G5,{handle:a[11]},r)),s=s.slice(a.index+a[0].length)}return n}function nS(e,n){return e.split(`
102
+ `).flatMap((r,a)=>a===0?[r]:[t.jsx("br",{},`${n}-br-${a}`),r])}function q5({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:kn(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(wr,{text:e.text})}):t.jsx("p",{className:"wb-empty",children:"This document came back with no body."})]})}const Q5=["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 Ae(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 Ve(e,n){if(n)return"const"in n?n.const:Ae(e,n.path)}function Is(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 kt(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):null}function Qa(e){return Array.isArray(e)?e:[]}function J5(e,n){const s=Qa(Ae(e,n.points)).map(a=>{const i=Is(Ae(a,n.y)),l=kt(Ae(a,n.x));return i===null||l===null?null:{x:l,y:i}}).filter(a=>a!==null),r=(n.referenceLines??[]).map(a=>{const i=Is(Ve(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:kt(Ve(e,n.currency)),label:kt(Ve(e,n.label)),referenceLines:r,mark:n.mark??null,shadeBelow:Is(Ve(e,n.shadeBelow)),events:X5(e,n)}}function X5(e,n){const s=n.events;if(!s)return[];const r=[],a=(i,l)=>{const o=kt(Ae(i,s.label));if(o===null)return;const c=kt(Ae(i,s.at))??l;c!==null&&r.push({at:c,label:o,amount:s.amount?Is(Ae(i,s.amount)):null})};if(s.parent){for(const i of Qa(Ae(e,n.points))){const l=kt(Ae(i,n.x));for(const o of Qa(Ae(i,s.parent)))a(o,l)}return r}for(const i of Qa(Ae(e,s.path??n.points)))a(i,null);return r}function Z5(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=Ae(o,c.key);let h=null;if(c.bar){const f=Is(Ve(o,c.bar.max))??Is(Ve(e,c.bar.max)),m=Is(u);if(f!==null&&f>0&&m!==null){const p=Math.max(0,Math.min(1,m/f));h={fraction:p,tone:t8(p*100,c.bar.thresholds)}}}return{value:u,type:c.type??"text",currency:kt(Ve(o,c.currency))??kt(Ve(e,c.currency)),bar:h}}),a=Qa(Ae(e,n.rows)),i=n.groupBy?e8(a,n.groupBy,r):[{label:null,rows:a.map(r)}],l=(n.summary??[]).map(o=>({label:o.label,value:Ve(e,o.value),unit:o.unit??"text",currency:kt(Ve(e,o.currency)),tone:o.tone??"neutral"}));return{columns:s,groups:i,summary:l,empty:n.empty??"Nothing to show."}}function e8(e,n,s){const r=new Map;for(const a of e){const i=String(Ae(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 t8(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 n8(e,n){return{bars:Qa(Ae(e,n.bars)).map(r=>{const a=Is(Ae(r,n.value)),i=kt(Ae(r,n.category));return a===null||i===null?null:{category:i,value:a}}).filter(r=>r!==null),unit:n.unit??"number",currency:kt(Ve(e,n.currency))}}function s8(e,n){if(n.pairs)return{pairs:n.pairs.map(r=>({label:r.label,value:Ve(e,r.value),unit:r.unit??"text",currency:kt(Ve(e,r.currency)),tone:r.tone??"neutral"}))};const s=Ae(e,n.from??"$");return s===null||typeof s!="object"||Array.isArray(s)?{pairs:[]}:{pairs:Object.entries(s).map(([r,a])=>({label:Kt(r),value:a,unit:"text",currency:null,tone:"neutral"}))}}const r8=new Set(["good","warning","critical","neutral","accent"]),a8=new Set(Q5);function $v(e){return typeof e=="string"&&a8.has(e)?e:null}function My(e,n,s=""){const r=n.empty??"Nothing to show.",a=s.split(".")[0]??"";if(n.notice){const l=kt(Ae(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:$v(n.notice.icon??"bell"),value:"",label:l.trim(),lines:[],tone:"neutral",link:o}],notice:!0,empty:r}}}return{tiles:Qa(Ae(e,n.items)).map(l=>{const o=kt(Ae(l,n.value))??"",c=kt(Ae(l,n.label))??"";if(o===""&&c==="")return null;const u=n.tone?kt(Ae(l,n.tone)):null;return{icon:$v(Ve(l,n.icon)),value:o,label:c,lines:(n.lines??[]).slice(0,2).map(h=>kt(Ae(l,h))).filter(h=>h!==null&&h.trim()!==""),tone:u!==null&&r8.has(u)?u:"neutral",link:null}}).filter(l=>l!==null),notice:!1,empty:r}}function i8(e,n){const s=kt(Ve(e,n.kind)),r=s==="image"||s==="pdf"?s:"text",a=n.src?kt(Ae(e,n.src)):null;return{kind:r,text:n.text?kt(Ae(e,n.text)):null,src:a&&VI(a)?a:null,title:kt(Ve(e,n.title)),metadata:(n.metadata??[]).map(i=>({label:i.label,value:Ve(e,i.value),unit:i.unit??"text"}))}}function l8(e,n){const s=n.diff?Ae(e,n.diff):void 0;return{diff:typeof s=="string"&&s.trim()!==""?s:null,title:kt(Ve(e,n.title)),metadata:(n.metadata??[]).map(r=>({label:r.label,value:Ve(e,r.value),unit:r.unit??"text"}))}}function o8(e,n){const s=n.output?Ae(e,n.output):void 0,r=l=>{const o=l?Ae(e,l):void 0;return typeof o=="number"&&Number.isInteger(o)?o:null},a=r(n.omittedBytes),i=n.elapsedMs?Ae(e,n.elapsedMs):void 0;return{command:kt(Ve(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:Ve(e,l.value),unit:l.unit??"text"}))}}const c8=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function KI(e){const n=e!==null&&typeof e=="object"&&!Array.isArray(e)?e.artifactId??e.id:e;return typeof n=="string"&&c8.test(n)?n.toLowerCase():null}function u8(e,n){return{artifactId:n.src?KI(Ae(e,n.src)):null,title:kt(Ve(e,n.title)),caption:kt(Ve(e,n.caption)),...n.captionLabel?{captionLabel:kt(Ve(e,n.captionLabel))}:{}}}function sS(e){if(!VI(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 d8(e,n){const s=n.src?kt(Ae(e,n.src)):null,r=n.port?Ae(e,n.port):null,a=n.awaiting?kt(Ae(e,n.awaiting)):null;return{target:s?sS(s):null,title:kt(Ve(e,n.title)),output:n.output?kt(Ae(e,n.output)):null,port:typeof r=="number"&&Number.isInteger(r)&&r>0&&r<=65535?r:null,awaiting:a?sS(a):null,reloadsItself:n.reloadsItself?Ae(e,n.reloadsItself)===!0:!1,ports:n.ports?h8(Ae(e,n.ports)):[]}}function h8(e){const n=Qa(e).filter(s=>typeof s=="number"&&Number.isInteger(s)&&s>0&&s<=65535);return[...new Set(n)].sort((s,r)=>s-r)}function VI(e){return e.startsWith("/")&&!e.startsWith("//")}function Kt(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 GI(e,n){const s=e.map??{};switch(e.renderer){case"timeseries":return{renderer:"timeseries",props:J5(n,s)};case"table":return{renderer:"table",props:Z5(n,s)};case"bars":return{renderer:"bars",props:n8(n,s)};case"keyvalue":return{renderer:"keyvalue",props:s8(n,s)};case"tiles":return{renderer:"tiles",props:My(n,s,e.tool)};case"document":return{renderer:"document",props:i8(n,s)};case"diff":return{renderer:"diff",props:l8(n,s)};case"terminal":return{renderer:"terminal",props:o8(n,s)};case"image":return{renderer:"image",props:u8(n,s)};case"preview":return{renderer:"preview",props:d8(n,s)};default:return{renderer:"structured",props:{value:n}}}}var f8=Object.defineProperty,nr=(e,n)=>f8(e,"name",{value:n,configurable:!0}),Oy="Dialog",[YI,Eoe]=Sr(Oy),[m8,Xr]=YI(Oy),Rm=nr(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]=mi({prop:r,defaultProp:a??!1,onChange:i,caller:Oy}),[f,m]=d.useState(0),[p,v]=d.useState(0);return t.jsx(m8,{scope:n,triggerRef:o,contentRef:c,contentId:mr(),titleId:mr(),descriptionId:mr(),titlePresent:f>0,descriptionPresent:p>0,setTitleCount:m,setDescriptionCount:v,open:u,onOpenChange:h,onOpenToggle:d.useCallback(()=>h(g=>!g),[h]),modal:l,children:s})},"Dialog"),p8="DialogTrigger",g8=d.forwardRef(nr(function(n,s){const{__scopeDialog:r,...a}=n,i=Xr(p8,r),l=It(s,i.triggerRef);return t.jsx(St.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":Dm(i.open),...a,ref:l,onClick:He(n.onClick,i.onOpenToggle)})},"DialogTrigger")),qI="DialogPortal",[x8,QI]=YI(qI,{forceMount:void 0}),Pm=nr(e=>{const{__scopeDialog:n,forceMount:s,children:r,container:a}=e,i=Xr(qI,n);return t.jsx(x8,{scope:n,forceMount:s,children:d.Children.map(r,l=>t.jsx(Jr,{present:s||i.open,children:t.jsx(lm,{asChild:!0,container:a,children:l})}))})},"DialogPortal"),Tv="DialogOverlay",Dy=d.forwardRef(nr(function(n,s){const r=QI(Tv,n.__scopeDialog),{forceMount:a=r.forceMount,...i}=n,l=Xr(Tv,n.__scopeDialog);return l.modal?t.jsx(Jr,{present:a||l.open,children:t.jsx(j8,{...i,ref:s})}):null},"DialogOverlay")),v8=ti("DialogOverlay.RemoveScroll"),j8=d.forwardRef(nr(function(n,s){const{__scopeDialog:r,...a}=n,i=Xr(Tv,r),l=E$(),o=It(s,l);return t.jsx(my,{as:v8,allowPinchZoom:!0,shards:[i.contentRef],children:t.jsx(St.div,{"data-state":Dm(i.open),...a,ref:o,style:{pointerEvents:"auto",...a.style}})})},"DialogOverlayImpl")),bu="DialogContent",Mm=d.forwardRef(nr(function(n,s){const r=QI(bu,n.__scopeDialog),{forceMount:a=r.forceMount,...i}=n,l=Xr(bu,n.__scopeDialog);return t.jsx(Jr,{present:a||l.open,children:l.modal?t.jsx(w8,{...i,ref:s}):t.jsx(y8,{...i,ref:s})})},"DialogContent")),w8=d.forwardRef(nr(function(n,s){const r=Xr(bu,n.__scopeDialog),a=d.useRef(null),i=It(s,r.contentRef,a);return d.useEffect(()=>{const l=a.current;if(l)return WT(l)},[]),t.jsx(JI,{...n,ref:i,trapFocus:r.open,disableOutsidePointerEvents:r.open,onCloseAutoFocus:He(n.onCloseAutoFocus,l=>{var o;l.preventDefault(),(o=r.triggerRef.current)==null||o.focus()}),onPointerDownOutside:He(n.onPointerDownOutside,l=>{const o=l.detail.originalEvent,c=o.button===0&&o.ctrlKey===!0;(o.button===2||c)&&l.preventDefault()}),onFocusOutside:He(n.onFocusOutside,l=>l.preventDefault())})},"DialogContentModal")),y8=d.forwardRef(nr(function(n,s){const r=Xr(bu,n.__scopeDialog),a=d.useRef(!1),i=d.useRef(!1);return t.jsx(JI,{...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")),JI=d.forwardRef(nr(function(n,s){const{__scopeDialog:r,trapFocus:a,onOpenAutoFocus:i,onCloseAutoFocus:l,...o}=n,c=Xr(bu,r);return ym(),t.jsx(t.Fragment,{children:t.jsx(ST,{asChild:!0,loop:!0,trapped:a,onMountAutoFocus:i,onUnmountAutoFocus:l,children:t.jsx(im,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionPresent?c.descriptionId:void 0,"aria-labelledby":c.titlePresent?c.titleId:void 0,"data-state":Dm(c.open),...o,ref:s,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})},"DialogContentImpl")),b8="DialogTitle",Om=d.forwardRef(nr(function(n,s){const{__scopeDialog:r,...a}=n,i=Xr(b8,r),{setTitleCount:l}=i;return ws(()=>(l(o=>o+1),()=>l(o=>o-1)),[l]),t.jsx(St.h2,{id:i.titleId,...a,ref:s})},"DialogTitle")),k8="DialogClose",Ly=d.forwardRef(nr(function(n,s){const{__scopeDialog:r,...a}=n,i=Xr(k8,r);return t.jsx(St.button,{type:"button",...a,ref:s,onClick:He(n.onClick,()=>i.onOpenChange(!1))})},"DialogClose"));function Dm(e){return e?"open":"closed"}nr(Dm,"getState");const N8=5;function me(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),[f,m]=d.useState(0),p=d.useRef(e);return p.current=e,d.useEffect(()=>{let v=!1;return c(!0),p.current().then(g=>{v||(a(g),l(null),m(0))}).catch(g=>{v||(l(g instanceof he?g.message:String(g)),m(k=>k+1))}).finally(()=>{v||c(!1)}),()=>{v=!0}},[...n,u]),d.useEffect(()=>{if(!s||f>=N8)return;const v=window.setTimeout(()=>h(g=>g+1),s*2**f);return()=>window.clearTimeout(v)},[s,f,u]),{data:r,error:i,loading:o,reload:()=>{m(0),h(v=>v+1)}}}const XI={width:480,height:160,top:10,right:10,bottom:22,left:40},ZI={width:1200,height:180,top:10,right:40,bottom:22,left:40};function S8({xs:e,series:n}){const s=ZI,r=s.width-s.left-s.right,a=s.height-s.top-s.bottom,i=O=>O.filter(R=>R!==null&&Number.isFinite(R)),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 f=u,m=h;if(f===m)f-=1,m+=1;else{const O=(m-f)*.08;f-=O,m+=O}const p=O=>qs(s.top+a-(O-f)/(m-f)*a),v=o.length>0&&o.every(O=>O.unit==="percent"),g=v?100:Math.max(1,...o.flatMap(O=>i(O.values))),k=O=>qs(s.top+a-Math.max(0,O)/g*a),j=e.length,x=j>0?r/j:r,w=O=>qs(s.left+x*(O+.5)),N=n.map(O=>{if(O.type==="bar")return"";let R="M";const D=[];return O.values.forEach((U,W)=>{if(U===null||!Number.isFinite(U)){R="M";return}D.push(`${R}${w(W)},${p(U)}`),R="L"}),D.join(" ")}),y=[],b=x*.6/Math.max(1,o.length),S=s.height-s.bottom;let C=0;n.forEach((O,R)=>{if(O.type!=="bar")return;const D=C++;O.values.forEach((U,W)=>{if(U===null||!Number.isFinite(U)||U<=0)return;const M=k(U);y.push({series:R,index:W,x:qs(w(W)-x*.3+b*D),y:M,width:qs(b),height:qs(S-M)})})});const A=c.length>0?af(u,h,2).map(O=>({value:O,y:p(O)})):[],$=o.length===0?[]:(v?[0,50,100]:af(0,g,2)).map(O=>({value:O,y:k(O),percent:v})),I=Math.max(1,Math.ceil(j/8)),P=e.flatMap((O,R)=>R%I===0?[{index:R,x:w(R)}]:[]);return{lines:N,bars:y,targetY:null,ticks:A,xLabels:P,rightTicks:$}}function C8({xs:e,series:n,type:s="line",target:r=null}){const a=XI,i=a.width-a.left-a.right,l=a.height-a.top-a.bottom,o=n.flatMap(w=>w.values.filter(N=>N!==null&&Number.isFinite(N)));r!==null&&Number.isFinite(r)&&o.push(r),s==="bar"&&o.push(0);let c=o.length>0?Math.min(...o):0,u=o.length>0?Math.max(...o):1;if(c===u)c-=1,u+=1;else if(s==="line"){const w=(u-c)*.08;c-=w,u+=w}const h=w=>qs(a.top+l-(w-c)/(u-c)*l),f=e.length,m=f>0?i/f:i,p=w=>qs(s==="bar"?a.left+m*(w+.5):a.left+(f<=1?i/2:w/(f-1)*i)),v=s==="line"?n.map(w=>{let N="M";const y=[];return w.values.forEach((b,S)=>{if(b===null||!Number.isFinite(b)){N="M";return}y.push(`${N}${p(S)},${h(b)}`),N="L"}),y.join(" ")}):[],g=[];if(s==="bar"&&f>0){const w=m*.7,N=w/Math.max(1,n.length),y=h(0);n.forEach((b,S)=>{b.values.forEach((C,A)=>{if(C===null||!Number.isFinite(C))return;const $=h(C);g.push({series:S,index:A,x:qs(a.left+m*A+(m-w)/2+N*S),y:Math.min($,y),width:qs(N),height:qs(Math.abs(y-$))})})})}const j=(o.length>0?af(Math.min(...o),Math.max(...o),2):[]).map(w=>({value:w,y:h(w)})),x=f===0?[]:f===1?[0]:f<5?[0,f-1]:[0,Math.floor((f-1)/2),f-1];return{lines:v,bars:g,targetY:r!==null&&Number.isFinite(r)?h(r):null,ticks:j,xLabels:x.map(w=>({index:w,x:p(w)}))}}function E8(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 A8({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?ZI:XI,u=o?S8({xs:e,series:n}):C8({xs:e,series:n,type:s,target:r}),h=E8({xs:e,series:n,target:r,...a?{label:a}:{},formatX:i,formatY:l});return t.jsxs("figure",{className:"ui-chart","data-type":s,children:[t.jsxs("svg",{viewBox:`0 0 ${c.width} ${c.height}`,"aria-hidden":"true",focusable:"false","data-testid":"chart-svg",children:[u.ticks.map(f=>t.jsxs("g",{children:[t.jsx("line",{className:"ui-chart-grid",x1:c.left,x2:c.width-c.right,y1:f.y,y2:f.y}),t.jsx("text",{x:c.left-6,y:f.y,textAnchor:"end",dominantBaseline:"middle",children:l(f.value)})]},f.value)),(u.rightTicks??[]).map(f=>t.jsx("text",{x:c.width-c.right+6,y:f.y,textAnchor:"start",dominantBaseline:"middle",children:f.percent?`${f.value}%`:l(f.value)},`r-${f.value}`)),t.jsx("line",{className:"ui-chart-axis",x1:c.left,x2:c.width-c.right,y1:c.height-c.bottom,y2:c.height-c.bottom}),u.bars.map(f=>t.jsx("rect",{className:"ui-chart-bar","data-series":f.series,x:f.x,y:f.y,width:f.width,height:f.height},`${f.series}-${f.index}`)),u.lines.map((f,m)=>f?t.jsx("path",{className:"ui-chart-line","data-series":m,d:f},m):null),u.targetY!==null?t.jsx("line",{className:"ui-chart-target","data-testid":"chart-target",x1:c.left,x2:c.width-c.right,y1:u.targetY,y2:u.targetY}):null,u.xLabels.map(f=>t.jsx("text",{x:f.x,y:c.height-6,textAnchor:o?"middle":u.xLabels.length>1&&f.index===0?"start":f.index===e.length-1&&e.length>1?"end":"middle",children:i(e[f.index])},f.index))]}),t.jsx("figcaption",{className:"sr-only",children:h}),n.length>1?t.jsx("ul",{className:"ui-chart-legend","aria-hidden":"true",children:n.map((f,m)=>t.jsx("li",{"data-series":m,"data-type":o?f.type??"line":void 0,children:f.label},f.label))}):null]})}function qs(e){return Math.round(e*10)/10}const Fy="(max-width: 900px)";function Yn(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 vi(...e){return e.filter(Boolean).join(" ")}function E({variant:e,size:n,className:s,type:r="button",...a}){return t.jsx("button",{type:r,className:vi("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":n,...a})}function nt({variant:e,size:n,className:s,...r}){return t.jsx("a",{className:vi("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":n,...r})}function Fo({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 re({children:e,align:n,valign:s,className:r}){return t.jsx("div",{className:vi("ui-toolbar",r),"data-align":n,"data-valign":s,children:e})}function pt(){return t.jsx("span",{className:"ui-toolbar-spacer"})}function oe({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 Ms({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 Se({tone:e,mono:n,dot:s,children:r,className:a,title:i}){return t.jsxs("span",{className:vi("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 fo({children:e}){return t.jsx("span",{className:"ui-tag",children:e})}function Xu({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(Se,{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 ae({message:e}){return e?t.jsx(Q,{tone:"critical",role:"alert",children:e}):null}function be({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(WI,{size:"sm"}),t.jsx("p",{children:a})]}):t.jsx("p",{className:"ui-empty",children:a})}function os({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(ie,{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 _y({children:e}){return t.jsx("div",{className:"ui-page",children:e})}function Ui({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 Ns({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(_y,{children:[t.jsx(Ui,{title:n,lede:s,actions:r}),a]})}function pe({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 st({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 Ar({tone:e,title:n,meta:s,actions:r,children:a,foot:i,onClick:l,label:o,as:c="div",labelledBy:u,density:h}){const f=l?{"data-interactive":"true",tabIndex:0,"aria-label":o,onClick:l,onKeyDown:m=>{m.target!==m.currentTarget||m.key!=="Enter"&&m.key!==" "||(m.preventDefault(),l())}}:{};return t.jsxs(c,{className:"ui-card","data-tone":e,"data-density":h,"aria-labelledby":u,...f,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 $8({children:e}){return t.jsx("div",{className:"ui-row",children:e})}function Lm({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 Vt({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 Zr({children:e}){return t.jsx("div",{className:"ui-table-wrap",children:t.jsx("table",{className:"ui-table",children:e})})}function zy({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 Bt({children:e,label:n}){return t.jsx("pre",{className:"ui-code","aria-label":n,children:e})}function Gt({summary:e,boxed:n,open:s,className:r,onToggle:a,children:i}){return t.jsxs("details",{className:vi("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 Je({title:e,onClose:n,size:s,foot:r,children:a}){return t.jsx(Rm,{open:!0,onOpenChange:i=>{i||n()},children:t.jsxs(Pm,{children:[t.jsx(Dy,{className:"ui-sheet-overlay"}),t.jsxs(Mm,{className:"ui-sheet","data-size":s,"aria-describedby":void 0,children:[t.jsxs("div",{className:"ui-sheet-head",children:[t.jsx(Om,{className:"ui-sheet-title",children:e}),t.jsx(Ly,{asChild:!0,children:t.jsx(E,{size:"sm",children:"Close"})})]}),a,r?t.jsx("div",{className:"ui-sheet-foot",children:r}):null]})]})})}function Rt({title:e,onClose:n,foot:s,children:r}){return t.jsx(Rm,{open:!0,onOpenChange:a=>{a||n()},children:t.jsxs(Pm,{children:[t.jsx(Dy,{className:"ui-sheet-overlay","data-layer":"modal"}),t.jsxs(Mm,{className:"ui-modal",role:"alertdialog","aria-describedby":void 0,children:[t.jsx(Om,{className:"ui-modal-title",children:e}),r,s?t.jsx("div",{className:"ui-modal-foot",children:s}):null]})]})})}function Jn({label:e,items:n,note:s,trigger:r,sheet:a,stacked:i}){const l=Yn(T8);return a&&l&&!r?t.jsx(I8,{label:e,items:n,title:a.title,sub:a.sub}):t.jsx(R8,{label:e,items:n,note:s,trigger:r,stacked:i})}const T8="(max-width: 720px)";function I8({label:e,items:n,title:s,sub:r}){const[a,i]=d.useState(!1);return t.jsxs(Rm,{open:a,onOpenChange:i,children:[t.jsx(g8,{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(ie,{name:"more"})})}),t.jsxs(Pm,{children:[t.jsx(Dy,{className:"ui-sheet-overlay",onClick:l=>l.stopPropagation()}),t.jsxs(Mm,{className:"ui-action-sheet","aria-describedby":void 0,onClick:l=>l.stopPropagation(),children:[t.jsxs("div",{className:"ui-action-sheet-head",children:[t.jsx(Om,{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(Ly,{asChild:!0,children:t.jsx(E,{className:"ui-action-sheet-cancel",children:"Cancel"})})]})]})]})}function R8({label:e,items:n,note:s,trigger:r,stacked:a}){const i=o=>o.stopPropagation(),l=d.useRef(!1);return t.jsxs(Ku,{modal:!1,onOpenChange:o=>{o&&(l.current=!1)},children:[t.jsx(Vu,{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(ie,{name:"more"})})}),t.jsx(Oo,{children:t.jsxs(Gu,{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(Ji,{className:"ui-menu-label",children:s}):null,n.map((o,c)=>o?o==="separator"?t.jsx(_r,{className:"ui-menu-sep"},`sep-${c}`):"heading"in o?t.jsx(Ji,{className:"ui-menu-label",children:o.heading},`head-${c}`):t.jsxs(ms,{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 P8({title:e,actions:n,onClose:s,onCloseAutoFocus:r,onOpenAutoFocus:a,label:i,children:l}){return t.jsx(Rm,{open:!0,modal:!1,onOpenChange:o=>{o||s()},children:t.jsx(Pm,{children:t.jsxs(Mm,{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(Om,{className:"ui-dock-title",children:e}),t.jsxs("div",{className:"ui-dock-actions",children:[n,t.jsx(Ly,{asChild:!0,children:t.jsx(E,{size:"sm",variant:"ghost",children:"Close"})})]})]}),t.jsx("div",{className:"ui-dock-body",children:l})]})})})}function _o({level:e,label:n,children:s}){return t.jsx("nav",{className:"ui-tabs","data-level":e,"aria-label":n,children:s})}function Zi({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 Xt({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 dt({children:e}){return t.jsx("div",{className:"ui-list",children:e})}function ot({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 eR({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 tR({list:e,detail:n,empty:s,label:r,className:a}){return t.jsxs("div",{className:vi("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 M8=8;function O8({label:e,options:n,value:s,onChange:r,max:a,disabled:i,id:l}){const[o,c]=d.useState(!1),[u,h]=d.useState(""),[f,m]=d.useState(0),p=d.useRef(null),v=d.useRef(null),g=d.useRef(null),k=d.useRef(null),j=d.useId(),x=R=>{var D;return((D=n.find(U=>U.value===R))==null?void 0:D.label)??R},w=a!==void 0&&s.length>=a,N=n.filter(R=>!s.includes(R.value)),y=n.length>M8,b=u.trim().toLowerCase(),S=b===""?N:N.filter(R=>R.label.toLowerCase().includes(b)),C=Math.min(f,Math.max(0,S.length-1)),A=R=>{var D;c(!1),h(""),m(0),R&&((D=v.current)==null||D.focus())};d.useEffect(()=>{var D;if(!o)return;(D=y?g.current:k.current)==null||D.focus();const R=U=>{p.current&&!p.current.contains(U.target)&&A(!1)};return document.addEventListener("mousedown",R),()=>document.removeEventListener("mousedown",R)},[o,y]);const $=R=>{const D=[...s,R];r(D),h(""),m(0);const U=a!==void 0&&D.length>=a;(U||D.length>=n.length)&&A(!U)},I=R=>{if(R.key==="Escape")R.preventDefault(),A(!0);else if(R.key==="ArrowDown")R.preventDefault(),m(S.length===0?0:(C+1)%S.length);else if(R.key==="ArrowUp")R.preventDefault(),m(S.length===0?0:(C-1+S.length)%S.length);else if(R.key==="Enter"){R.preventDefault();const D=S[C];D&&$(D.value)}else R.key==="Backspace"&&u===""&&s.length>0&&(R.preventDefault(),r(s.slice(0,-1)))},P=R=>`${j}-${R}`,O=o&&S.length>0?P(C):void 0;return t.jsxs("div",{className:"ui-chippicker",ref:p,id:l,children:[s.map(R=>t.jsx(hf,{label:x(R),disabled:i,onRemove:()=>r(s.filter(D=>D!==R)),children:x(R)},R)),t.jsxs("div",{className:"ui-chippicker-add",children:[t.jsx("button",{ref:v,type:"button",className:"ui-btn","data-size":"sm","data-variant":"ghost","aria-haspopup":"listbox","aria-expanded":o,"aria-controls":o?j:void 0,disabled:i||w||N.length===0,onClick:()=>o?A(!1):c(!0),children:"Add…"}),o?t.jsxs("div",{className:"ui-menu ui-chippicker-menu",onKeyDown:I,children:[y?t.jsx("input",{ref:g,type:"search",className:"ui-chippicker-filter","aria-label":`Filter ${e}`,"aria-controls":j,"aria-activedescendant":O,value:u,onChange:R=>{h(R.target.value),m(0)}}):null,t.jsxs("div",{ref:k,id:j,role:"listbox","aria-multiselectable":"true","aria-label":e,"aria-activedescendant":y?void 0:O,tabIndex:y?-1:0,className:"ui-chippicker-list",children:[S.map((R,D)=>t.jsx("div",{id:P(D),role:"option","aria-selected":"false",className:"ui-menu-item","data-highlighted":D===C?"":void 0,onMouseEnter:()=>m(D),onMouseDown:U=>U.preventDefault(),onClick:()=>$(R.value),children:R.label},R.value)),S.length===0?t.jsx("p",{className:"ui-menu-empty",children:"Nothing matches"}):null]})]}):null]})]})}function nR({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 Fm({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 Qn({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(ie,{name:n})})}function Oc({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(ie,{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 sR({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(E,{"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 ku({size:e}){return t.jsx("span",{className:"ui-mark","data-size":e,"aria-hidden":"true",children:"b"})}function rR({quiet:e,still:n,className:s,children:r}){return t.jsx("div",{className:vi("ui-fieldbg",s),"data-quiet":e?"true":void 0,"data-still":n?"true":void 0,children:r})}function D8({dock:e,className:n,children:s}){return t.jsxs("div",{className:vi("ui-float",n),children:[t.jsx("div",{className:"ui-float-body",children:s}),e?t.jsx("div",{className:"ui-float-dock",children:e}):null]})}function L8(e){const n={};for(const s of e??[])n[s.key]=s.default;return n}function Uy(e){const[n,s]=d.useState({}),r=e??[],a={...L8(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(oe,{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 F8({props:e,timezone:n="UTC",onDecided:s}){var w;const[r,a]=d.useState(null),[i,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(null);d.useEffect(()=>{let N=!1;return a(null),l(null),T.approval(e.approvalId).then(y=>{N||a(y)}).catch(y=>{N||l(y instanceof he?y.message:String(y))}),()=>{N=!0}},[e.approvalId]);const{values:f,controls:m}=Uy(r==null?void 0:r.choices),p=(N,y)=>{h(N),l(null),(f&&N==="approve"?T.decide(e.approvalId,N,y,f):T.decide(e.approvalId,N,y)).then(b=>{a(b.action),s==null||s(b.action)}).catch(b=>l(b instanceof he?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 v=r.state==="pending",g=(w=r.permissionScopes)==null?void 0:w.includes("always"),k=_8(r),j=(r.preview??"").split(`
103
+ `).length>12||(r.preview??"").length>900,x=[r.decidedBy?`by ${r.decidedBy}`:"",r.decidedVia?`via ${r.decidedVia}`:""].filter(Boolean).join(" ");return t.jsxs("div",{className:"wb-envelope",children:[t.jsxs("div",{className:"envelope",children:[t.jsxs("dl",{className:"envelope-head",children:[t.jsx("dt",{children:"Action"}),t.jsx("dd",{className:"wb-envelope-action",children:r.tool.split(".").map(N=>Kt(N)).join(" · ")}),t.jsx("dt",{children:"Status"}),t.jsxs("dd",{children:[v?t.jsx(Se,{tone:"warning",dot:!0,children:"waiting for you"}):t.jsx(Xu,{state:r.state}),!v&&x?t.jsxs("span",{className:"wb-envelope-note",children:[" ",x]}):null]}),t.jsx("dt",{children:v?"Expires":"Decided"}),t.jsx("dd",{children:mt(v?r.expiresAt:r.decidedAt,n)})]}),t.jsxs("div",{className:"envelope-body","data-clamp":j&&!o?"true":void 0,children:[r.preview||"(this tool wrote no preview)",j&&!o?t.jsx("button",{type:"button",className:"wb-doc-more",onClick:()=>c(!0),children:"Show the whole preview"}):null]})]}),t.jsx(ae,{message:i}),v?m:null,v?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:k.map(N=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:N.label}),N.block?t.jsx("dd",{className:"wb-envelope-block",children:t.jsx("pre",{className:"mono",children:N.value})}):t.jsx("dd",{className:N.mono?"mono":void 0,children:N.value})]},N.label))})]})]})}function _8(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(rS(Kt(a),i));else s!=null&&n.push({label:"Envelope",value:By(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 · ${Kt(a)}`;n.some(o=>o.label===l)||n.push(rS(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 rS(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:By(n)}}function By(e){return e==null?"—":Array.isArray(e)?e.map(n=>By(n)).join(", ")||"—":typeof e=="object"?JSON.stringify(e):kn(e,"text",null)}const z8=new Set(["image/png","image/jpeg","image/gif","image/webp"]),U8=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function ff(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"||!U8.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 Wy(e){return z8.has(e.toLowerCase())}function yr(e){return`/api/artifacts/${encodeURIComponent(e)}/preview`}function ai(e){return`/api/artifacts/${encodeURIComponent(e)}/download`}function _n(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 Hy(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 Bi={image:"Image",pdf:"PDF",table:"Spreadsheet",text:"Document",code:"Code",audio:"Audio",video:"Video",archive:"Archive",file:"File"};function jh(e){return`artifact:${e}`}function B8(e){const n=Hy(e.mime,e.filename);return{id:jh(e.artifactId),tool:Bi[n],title:e.filename??"Untitled file",renderer:"artifact",props:{attachment:e},at:null,source:"artifact",substantial:!1}}function W8({props:e}){const n=KI(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(f=>{h&&r({filename:f.entry.filename,sizeBytes:f.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?_n(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:yr(n),className:"wb-image-link",title:"Open at full size",children:t.jsx("img",{src:yr(n),alt:e.caption??c,onLoad:h=>{const f=h.currentTarget;f.naturalWidth>0&&i({width:f.naturalWidth,height:f.naturalHeight})},onError:()=>o(!0)})})}),t.jsxs("figcaption",{className:"wb-image-caption",children:[t.jsxs(re,{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(nt,{size:"sm",href:ai(n),download:(s==null?void 0:s.filename)??c,children:"Download"})]}),e.caption&&e.captionLabel?t.jsx(Gt,{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 H8({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:kn(n.value,n.unit,n.currency)})]},n.label))})}const K8=8;function aR({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<=K8},children:e})}function V8(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 G8({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(E,{size:"sm",onClick:()=>{var r;if(s(""),!((r=navigator.clipboard)!=null&&r.writeText)){s("Copy unavailable; select the text to copy.");return}navigator.clipboard.writeText(e).then(()=>s("Copied"),()=>s("Copy failed; select the text to copy."))},children:"Copy"})]})}function Y8({props:e}){const n=e.output??"";return t.jsxs("div",{className:"wb-terminal",children:[t.jsxs(re,{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(Se,{tone:e.exitCode===0?"good":"critical",mono:!0,children:["exit ",e.exitCode]}):null,e.elapsedMs!==null?t.jsx("span",{className:"wb-terminal-fact",children:V8(e.elapsedMs)}):null,t.jsx("span",{className:"ui-toolbar-spacer"}),n!==""?t.jsx(G8,{text:n}):null]}),e.omittedBytes!==null?t.jsxs("p",{className:"wb-terminal-note",children:["First ",_n(e.omittedBytes)," not shown."]}):null,n!==""?t.jsx(aR,{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:kn(s.value,s.unit,null)})]},s.label))}):null]})}function q8(){const e=window.location.hostname.replace(/^\[|\]$/g,"").toLowerCase();return e==="127.0.0.1"||e==="::1"||e==="localhost"}function aS(e){try{const n=new URL(e);return n.searchParams.delete("ticket"),n.toString()}catch{return e}}function Q8(e){const n=new Set(e.ports??[]);return e.port!==null&&n.add(e.port),[...n].sort((s,r)=>s-r)}function J8({props:e}){var y;const[n,s]=d.useState(null),[r,a]=d.useState(null),[i,l]=d.useState(null),[o,c]=d.useState(!1),u=((y=e.target)==null?void 0:y.plugin)??null,h=Q8(e),[f,m]=d.useState(null),p=f!==null&&h.includes(f)?f:e.port,v=e.target?p!==null&&p!==e.port?`${e.target.name}.${p}`:e.target.name:null,g=e.changes??0,k=d.useRef(g),[j,x]=d.useState(0);d.useEffect(()=>{g<=k.current||(k.current=g,e.reloadsItself||x(b=>b+1))},[g,e.reloadsItself]),d.useEffect(()=>{if(u===null||v===null)return;let b=!0;return s(null),a(null),l(null),x(0),T.previewLink(u,v).then(S=>{b&&(s(S.url),a(aS(S.url)))}).catch(S=>{b&&l(S instanceof Error?S.message:"That preview could not be opened.")}),()=>{b=!1}},[u,v]);const w=()=>{u===null||v===null||T.previewLink(u,v).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 N=!(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=>m(Number(b.target.value)),children:h.map(b=>t.jsxs("option",{value:b,children:[":",b]},b))}):null,N?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:w,onFocus:w,title:"Through buddi: works from anywhere the dashboard does, including the tailnet.",children:"Open in a tab"}):null,p!==null&&q8()?t.jsxs("a",{className:"wb-preview-direct",href:`http://localhost:${p}/`,target:"_blank",rel:"noreferrer noopener",title:"The process itself, on this machine only.",children:["localhost:",p]}):null]}),t.jsxs("div",{className:"wb-preview-body",children:[n?t.jsx("iframe",{className:"wb-preview-frame",src:j===0?n:aS(n),title:e.title??"Preview",sandbox:"allow-scripts allow-forms allow-same-origin allow-modals allow-downloads"},j):t.jsx("p",{className:"wb-empty wb-preview-frame",children:i??"Opening the preview…"}),N&&o?t.jsx(aR,{text:e.output??"",className:"wb-preview-output"}):null]})]})}const X8=50,Z8=9,eW=24,tW=.6,nW=48,sW=/(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,rW=/^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}|$)/,aW=/^id$|(^|[a-z0-9])Id$|_id$/;function Bl(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 iR(...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 lR(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&&sW.test(e)?"currency":"number":r.every(a=>typeof a=="string"&&rW.test(a))?"date":"text"}function iW(e,n){if(!aW.test(e))return!1;const s=n.filter(r=>!qr(r));return s.length<2?!1:new Set(s.map(r=>String(r))).size===s.length}function qr(e){return e==null||e===""?!0:Array.isArray(e)?e.length===0:$s(e)?Object.keys(e).length===0:!1}function iS(e,n){const s=e.filter($s);if(s.length===0||s.length/e.length<.8)return null;const r=s.slice(0,X8),a=new Map,i=[];for(const h of r)for(const f of Object.keys(h))a.has(f)||i.push(f),a.set(f,(a.get(f)??0)+1);if(a.size===0||a.size>eW||[...a.values()].reduce((h,f)=>h+f,0)/(a.size*r.length)<tW)return null;const o=[...a.keys()].sort((h,f)=>{const m=(a.get(f)??0)-(a.get(h)??0);return m!==0?m:i.indexOf(h)-i.indexOf(f)}),c=[],u=[];for(const h of o){const f=r.map(g=>g[h]),m=f.filter(g=>!qr(g));if(m.length===0||iW(h,f))continue;const p=iR(r[0],n),v=lR(h,f,p);if(r.length>=4&&m.length===f.length&&f.every(g=>Bl(g)&&g===f[0])){u.push({label:Kt(h),value:f[0],type:v,currency:p});continue}if(c.push({key:h,label:Kt(h),type:v,currency:v==="currency"?p:null}),c.length===Z8)break}return c.length===0?null:{columns:c,rows:s,constants:u}}function lW(e,n,s){const r=iR(s);return{label:Kt(e),value:n,type:lR(e,[n],r),currency:r}}function oR(e){return typeof e=="string"&&e.length>nW}function oW(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 Iv(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=Iv(s);if(r!=="The call failed with no reason given.")return r}}return"The call failed with no reason given."}function Ky(e,n={}){if(n.failed){let f=e;if(typeof e=="string")try{const m=JSON.parse(e.replace(/^tool-error:\s*/,""));$s(m)&&(f=m)}catch{}return{kind:"error",summary:Iv(f),detail:lS(f)}}if($s(e)){const f=e.error,m=e.ok;if(typeof f=="string"&&f.trim()!==""||m===!1)return{kind:"error",summary:Iv(e),detail:lS(e)}}const s=oW(e);if(s)return{kind:"empty",note:s,stats:[]};if(Array.isArray(e)){const f=iS(e,e);return f?{kind:"table",label:null,columns:f.columns,rows:f.rows,total:f.rows.length,stats:f.constants,notes:[],asides:[]}:e.every(Bl)?{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[f,m]of r){if(!Array.isArray(m))continue;const p=iS(m,e);if(p){(!a||p.rows.length>a.candidate.rows.length)&&(a={key:f,candidate:p});continue}m.length>0&&m.every(Bl)&&(!i||m.length>i.items.length)&&(i={key:f,items:m})}const l=(a==null?void 0:a.key)??(i==null?void 0:i.key)??null,o=[],c=[],u=[];for(const[f,m]of r)if(f!==l){if(oR(m)){c.push(m);continue}if(Bl(m)){if(m==="")continue;o.push(lW(f,m,e));continue}m!==void 0&&u.push({label:Kt(f),value:m})}if(a)return{kind:"table",label:Kt(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:Kt(i.key),items:i.items,total:i.items.length,stats:o,notes:c,asides:u};const h=r.filter(([,f])=>Array.isArray(f)&&f.length===0);return h.length>0&&h.length===r.filter(([,f])=>Array.isArray(f)).length?{kind:"empty",note:`No ${h.map(([m])=>Kt(m).toLowerCase()).join(", ")} to show.`,stats:o}:r.every(([,f])=>Bl(f)||$s(f)||Array.isArray(f))?{kind:"record",pairs:o,notes:c,asides:u}:{kind:"tree",value:e}}function lS(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 mf=25,cW=3,Rv=8,cR=6;function Pv(e,n=0){if(n>cR||qr(e)||oR(e))return 0;if(Bl(e))return 1;if(Array.isArray(e)){let s=0;for(const r of e)if(s+=Pv(r,n+1),s>=Rv)return s;return s}if($s(e)){let s=0;for(const r of Object.values(e))if(s+=Pv(r,n+1),s>=Rv)return s;return s}return 0}function Mv(e,n=0){if(n>cR)return!1;if(Array.isArray(e))return e.some(i=>Mv(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=>Mv(i,n+1))}function uW(e){if(Mv(e))return!0;const n=Ky(e);switch(n.kind){case"table":return n.rows.length>0;case"list":return n.items.length>=cW;case"record":case"tree":return Pv(e)>=Rv;default:return!1}}function Xp(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function _m(e){const n=Xp(e);if(!n)return null;const s=Xp(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:Xp(n.input),a=(r==null?void 0:r.command)??s.command;return{command:typeof a=="string"?a:null,input:r,result:s}}function dW({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 Zp({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(dW,{text:n,label:`Copy ${e.toLowerCase()}`})]}),t.jsx("pre",{className:"wb-command-text","aria-label":e,tabIndex:0,children:n})]})}function hW({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,f])=>!["stdout","stderr","state","exitCode","artifacts","outputErrors","command"].includes(h)&&f!==null&&f!==void 0&&f!=="")),u=Array.isArray(s.outputErrors)?s.outputErrors.filter(h=>typeof h=="string"):[];return 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(Zp,{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(Zp,{title:"Output",text:s.stdout}):t.jsx("p",{className:"wb-note",children:"No standard output."}),s.stderr?t.jsx(Zp,{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,f)=>t.jsx("p",{className:"wb-fail",children:h},f))]}),n,(Object.keys(c).length>0||a!==null)&&t.jsxs("details",{className:"wb-aside",children:[t.jsx("summary",{children:"Execution details"}),t.jsx("pre",{children:ls({...c,...a?{input:a}:{}})})]})]})}const Ld=2,oS=64;function uR({props:e,bare:n=!1}){const[s,r]=d.useState(!1),a=_m(e.value),i=fW((a==null?void 0:a.result)??e.value),l=d.useMemo(()=>Ky(e.value,{failed:e.failed??!1}),[e.value,e.failed]);return t.jsxs("div",{children:[!a&&t.jsx(cS,{files:i}),s?t.jsx("pre",{className:"ui-code",children:ls(e.value)}):a?t.jsx(hW,{value:a,children:i.length>0&&t.jsxs("section",{children:[t.jsx("h4",{children:"Generated files"}),t.jsx(cS,{files:i})]})}):i.length?t.jsxs("details",{className:"wb-aside",children:[t.jsx("summary",{children:"Tool details"}),t.jsx(uS,{shape:l})]}):t.jsx(uS,{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 fW(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 cS({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(mW,{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 mW({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 uS({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:Nu(e.detail,1)})]})]});case"empty":return t.jsxs("div",{children:[t.jsx(eg,{stats:e.stats}),t.jsx("p",{className:"wb-note",children:e.note})]});case"table":{const n=wW(e.columns,e.rows);return t.jsxs("div",{children:[t.jsx(eg,{stats:e.stats}),t.jsx(tg,{notes:e.notes}),n?t.jsx(yW,{label:e.label,plan:n,rows:e.rows,total:e.total}):t.jsx(gW,{label:e.label,columns:e.columns,rows:e.rows,total:e.total}),t.jsx(ng,{asides:e.asides})]})}case"list":return t.jsxs("div",{children:[t.jsx(eg,{stats:e.stats}),t.jsx(tg,{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:kn(n,"text",null)},s))}),e.total>100?t.jsxs("p",{className:"wb-note",children:["Showing 100 of ",e.total,"."]}):null,t.jsx(ng,{asides:e.asides})]});case"record":return t.jsxs("div",{children:[t.jsx(tg,{notes:e.notes}),t.jsx(pW,{pairs:e.pairs}),t.jsx(ng,{asides:e.asides})]});default:return t.jsx("div",{className:"wb-tree",children:Nu(e.value,0)})}}function eg({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:Vy(n.value,n.type,n.currency)})]},n.label))})}const dS=200;function tg({notes:e}){if(e.length===0)return null;const n=e.filter(r=>r.length<=dS),s=e.filter(r=>r.length>dS);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 pW({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:Vy(n.value,n.type,n.currency)})]},n.label))})}function ng({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:Nu(n.value,1)})]},n.label))})}function gW({label:e,columns:n,rows:s,total:r}){const[a,i]=d.useState(!1),l=r<=mf+5?r:mf,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:hR(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(bW,{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 xW=/^(title|name|headline|subject|label|heading)$/i,vW=/^(url|link|href|uri|permalink)$/i;function pf(e){return typeof e=="string"&&/^https?:\/\/[^\s]+$/i.test(e.trim())}function jW(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function dR(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 Fd(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 wW(e,n){if(n.length===0)return null;const s=e.filter(h=>h.type==="text"),r=s.find(h=>vW.test(h.key)&&n.some(f=>pf(f[h.key])))??s.find(h=>{const f=n.map(m=>m[h.key]).filter(m=>!qr(m));return f.length>0&&f.filter(pf).length/f.length>=.6});if(!r)return null;const a=s.filter(h=>h.key!==r.key),i=a.find(h=>xW.test(h.key))??a.find(h=>Fd(n,h.key)>0);if(!i)return null;const o=[...a.filter(h=>h.key!==i.key)].sort((h,f)=>Fd(n,f.key)-Fd(n,h.key)),c=o[0]&&Fd(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 yW({label:e,plan:n,rows:s,total:r}){const[a,i]=d.useState(!1),l=r<=mf+5?r:mf,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],f=pf(h)?h.trim():null,m=typeof c[n.title]=="string"&&c[n.title].trim()!==""?c[n.title]:f?dR(f):"Untitled",p=n.description&&typeof c[n.description]=="string"?c[n.description]:null,v=f?jW(f):null,g=n.meta.map(k=>c[k]).filter(k=>!qr(k)&&typeof k!="object").map(k=>String(k)).filter(k=>v===null||k.replace(/^www\./,"")!==v);return t.jsxs("li",{className:"wb-record",children:[f?t.jsx("a",{className:"wb-record-title",href:f,target:"_blank",rel:"noopener noreferrer",children:m}):t.jsx("span",{className:"wb-record-title",children:m}),t.jsxs("div",{className:"wb-record-meta",children:[v?t.jsx("span",{className:"wb-record-host",title:f??void 0,children:v}):null,g.map((k,j)=>t.jsx("span",{children:k.length>60?`${k.slice(0,59)}…`:k},j))]}),p?t.jsx("p",{className:"wb-record-desc",children:p.length>280?`${p.slice(0,279)}…`:p}):null]},u)})}),r>o.length?t.jsxs("p",{className:"wb-note wb-note-row",children:[t.jsxs("span",{children:["Showing ",o.length," of ",r]}),t.jsxs("button",{className:"ui-btn",onClick:()=>i(!0),children:["Show all ",r]})]}):null]})}function bW({value:e,column:n}){if(qr(e))return t.jsx("td",{className:"wb-cell-soft",children:"—"});if(pf(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:dR(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:ls(e),children:a})}const s=Vy(e,n.type,n.currency),r=s.length>oS?`${s.slice(0,oS-1)}…`:s;return t.jsx("td",{className:hR(n.type)?"num":"wb-cell-text",...r===s?{}:{title:s},children:r})}function hR(e){return e==="number"||e==="currency"}function Vy(e,n,s){return e==null?"—":n==="boolean"?e?"yes":"no":kn(e,n==="text"?"text":n,s)}function Nu(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,". "]}),Nu(i,n+1)]},l)),e.length>50?t.jsxs("div",{className:"wb-tree-key",children:["…and ",e.length-50," more"]}):null]});return n>=Ld?t.jsx(hS,{summary:`${e.length} items`,open:n===Ld,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:[Kt(a),": "]}),Nu(i,n+1)]},a))});return n>=Ld?t.jsx(hS,{summary:`${s.length} fields`,open:n===Ld,children:r}):r}function hS({summary:e,open:n,children:s}){return t.jsxs("details",{open:n,children:[t.jsx("summary",{className:"wb-tree-key",children:e}),s]})}function kW({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:kn(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:fR(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(NW,{cell:l},((c=e.columns[o])==null?void 0:c.key)??o)})},i))})]})})]},s.label??r))]})}function NW({cell:e}){const n=kn(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:fR(e.type)?"num":void 0,"data-type":e.type,title:n.length>40?n:void 0,children:n})}function fR(e){return e==="number"||e==="currency"||e==="percent"}const fS={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 zo(e){return(e&&Object.prototype.hasOwnProperty.call(fS,e)?fS[e]:void 0)??"dot"}let wh=null;typeof window<"u"&&window.addEventListener(uf,()=>{wh=null});function SW(){return wh??(wh=Promise.resolve().then(()=>T.pages()).then(e=>Array.isArray(e==null?void 0:e.pages)?e.pages:[]).catch(()=>(wh=null,[]))),wh}function Gy(e,n,s){return s==="settings"?vr(e,n):Yr(e,n)}function CW(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 SW().then(l=>{const o=l.find(c=>c.plugin===r&&c.id===a);i||s(o?{href:Gy(r,a,o.place),label:o.place==="settings"?`Settings → ${o.title}`:o.title}:null)}),()=>{i=!0}},[r,a]),n}const ii="••••",mR=new WeakMap;function Ja(e){return e===null||typeof e!="object"?e:mR.get(e)??e}function EW(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 mS(e,n){return mR.set(e,Ja(n)),e}function Ov(e,[n,...s]){if(e==null)return e;if(n===void 0)return ii;if("each"in n)return Array.isArray(e)?mS(e.map(a=>Ov(a,s)),e):e;if(typeof e!="object"||Array.isArray(e)||!Object.prototype.hasOwnProperty.call(e,n.key))return e;const r=e;return mS({...r,[n.key]:Ov(r[n.key],s)},r)}function AW(e,n){if(!n||n.length===0)return e;let s=e;for(const r of n)s=Ov(s,EW(r));return s}function pR(){return t.jsx("span",{className:"pp-masked",role:"img","aria-label":"hidden",children:[...ii].map((e,n)=>t.jsx("span",{className:"pp-mask-dot",children:e},n))})}function Yy({shown:e,onToggle:n,show:s="Show",hide:r="Hide",size:a}){return t.jsxs(E,{className:"pp-reveal",size:a,onClick:n,children:[t.jsx(ie,{name:"eye",size:a==="sm"?14:16}),t.jsx("span",{children:e?r:s})]})}function Ur({text:e}){if(e==null)return null;if(!e.includes(ii))return t.jsx(t.Fragment,{children:e});const n=e.split(ii),s=[];return n.forEach((r,a)=>{r&&s.push(r),a<n.length-1&&s.push(t.jsx(pR,{},a))}),t.jsx(t.Fragment,{children:s})}function zm(e){return e===ii?!0:Array.isArray(e)?e.some(zm):!1}function gR({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($W,{tile:a,...r?{picked:i===s,onPick:()=>r(i)}:{}},`${i}-${a.label}`))})}function $W({tile:e,picked:n,onPick:s}){const r=CW(e.link),a=[e.label,e.value,...e.lines].filter(l=>l!=="").map(l=>l.split(ii).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(ie,{name:zo(e.icon),size:22})}),e.value!==""?t.jsx("span",{className:"wb-tile-value tnum",children:t.jsx(Ur,{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(Ur,{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(Ar,{tone:e.tone==="neutral"?void 0:e.tone,children:[i,r?t.jsx("a",{className:"wb-tile-link",href:r.href,children:r.label}):null]})]})}const yl=760,sg=400,sn={top:18,right:18,bottom:36,left:66},TW=5;function IW({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(N=>N.y),...s.map(N=>N.value)],l=Math.min(...i),o=Math.max(...i),c=o-l||Math.abs(o)||1,u=l-c*.08,h=o+c*.08,f=yl-sn.left-sn.right,m=sg-sn.top-sn.bottom,p=N=>sn.left+(n.length===1?f/2:N/(n.length-1)*f),v=N=>sn.top+m-(N-u)/(h-u)*m,g=af(l,o,4),k=PW(n.map(N=>N.y),e.mark),j=e.shadeBelow===null?[]:MW(n.map(N=>N.y),e.shadeBelow),x=n.map((N,y)=>`${y===0?"M":"L"}${p(y)},${v(N.y)}`).join(" "),w=N=>kn(N,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 ${yl} ${sg}`,role:"img","aria-label":RW(e,w),preserveAspectRatio:"xMidYMid meet",children:[j.map(N=>t.jsx("rect",{className:"wb-chart-breach",x:p(N.from),width:Math.max(2,p(N.to)-p(N.from)),y:sn.top,height:m},`band-${N.from}`)),g.map(N=>t.jsxs("g",{children:[t.jsx("line",{className:"wb-chart-grid",x1:sn.left,x2:yl-sn.right,y1:v(N),y2:v(N)}),t.jsx("text",{x:sn.left-8,y:v(N)+4,textAnchor:"end",children:w(N)})]},`tick-${N}`)),s.map(N=>t.jsxs("g",{children:[t.jsx("line",{className:"wb-chart-floor",x1:sn.left,x2:yl-sn.right,y1:v(N.value),y2:v(N.value)}),t.jsxs("text",{x:yl-sn.right,y:v(N.value)-6,textAnchor:"end",children:[N.label," ",w(N.value)]})]},`rule-${N.label}`)),t.jsx("line",{className:"wb-chart-axis",x1:sn.left,x2:sn.left,y1:sn.top,y2:sn.top+m}),t.jsx("line",{className:"wb-chart-axis",x1:sn.left,x2:yl-sn.right,y1:sn.top+m,y2:sn.top+m}),t.jsx("path",{className:"wb-chart-series",d:x}),k!==null?t.jsxs("g",{children:[t.jsx("circle",{className:"wb-chart-min",cx:p(k),cy:v(n[k].y),r:4.5}),t.jsx("text",{x:p(k),y:v(n[k].y)+20,textAnchor:"middle",children:w(n[k].y)})]}):null,OW(n.length).map(N=>t.jsx("text",{x:p(N),y:sg-10,textAnchor:"middle",children:pv(n[N].x)},`x-${N}`))]})}),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((N,y)=>t.jsxs("li",{className:"wb-chart-event",children:[t.jsxs("span",{children:[t.jsx("span",{className:"wb-chart-event-day",children:pv(N.at)}),N.label]}),N.amount===null?null:t.jsx("span",{className:N.amount<0?"tnum critical":"tnum good",children:kn(N.amount,r,a)})]},`${N.at}-${N.label}-${y}`))})]}):null]})]})}function RW(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 PW(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 MW(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 OW(e,n=TW){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 Hs=e=>e,Dv={timeseries:Hs(IW),table:Hs(kW),bars:Hs(X6),keyvalue:Hs(H8),tiles:Hs(gR),document:Hs(q5),diff:Hs(rB),terminal:Hs(Y8),image:Hs(W8),preview:Hs(J8),envelope:Hs(F8),structured:Hs(uR)},DW="structured";function LW(e){return(gf(e)?Dv[e]:void 0)??Dv[DW]}function gf(e){return Object.prototype.hasOwnProperty.call(Dv,e)}function FW({renderer:e,props:n,timezone:s,onDecided:r}){const a=LW(e),l=gf(e)?n:{value:n};return t.jsx(a,{props:l,timezone:s,onDecided:r})}function li(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}const _W=["preferredName","displayName","fullName","name","title","label","subject","username","email"],zW=/^(name|title|label|subject|displayName|display_name|heading)$/i,UW=/^(url|link|href|uri|permalink)$/i,BW=/^(id|uuid|_id)$|(Id|_id)$/;function Lv(e){return e===null||["string","number","boolean"].includes(typeof e)}function qy(e){return _W.find(n=>typeof e[n]=="string"&&e[n].trim()!=="")??null}const WW=6;function xR(e){let n=e,s=null,r=[];if(li(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])=>Lv(h)))return null;[s,n]=[Kt(c[0][0]),c[0][1]],r=u.filter(([,h])=>!qr(h))}if(!Array.isArray(n)||n.length===0||!n.every(li))return null;const a=n,i=[...new Set(a.flatMap(c=>Object.keys(c)))];if(i.length>WW||i.some(c=>UW.test(c)))return null;const l=i.find(c=>zW.test(c)&&a.filter(u=>typeof u[c]=="string").length>=a.length*.8);if(!l)return null;const o=i.filter(c=>c!==l&&!BW.test(c)).filter(c=>a.some(u=>Lv(u[c])&&!qr(u[c]))).sort((c,u)=>pS(a,u)-pS(a,c)).slice(0,2);return{label:s,rows:a,name:l,facts:o,extras:r}}function pS(e,n){return e.filter(s=>!qr(s[n])).length}function HW(e){return li(e)&&qy(e)!==null&&Object.keys(e).length>=3}const KW=60;function VW(e){if(!li(e))return!1;const n=Object.values(e);return n.length>=2&&n.every(s=>Lv(s)&&(typeof s!="string"||s.length<=KW))}const GW=[{name:"items",matches:e=>xR(e)!==null},{name:"profile",matches:HW},{name:"settings",matches:VW},{name:"fields",matches:e=>li(e)&&Object.keys(e).length>0}];function YW(e){var n;return((n=GW.find(s=>s.matches(e)))==null?void 0:n.name)??"other"}const vR=8,qW=32,QW=/^\d{4}-\d{2}-\d{2}$/,JW=/^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?$/,XW=/^[a-z]+([_-][a-z]+)*$/,ZW=/(name|title|label|email|subject|text|note|message|description|summary|path|file)$/i;function jR(e,n){if(qr(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 QW.test(s)?{kind:"day",value:s}:JW.test(s)&&!Number.isNaN(Date.parse(s))?{kind:"moment",value:s}:/^https?:\/\/\S+$/i.test(s)?{kind:"link",value:s}:s.length<=24&&XW.test(s)&&!ZW.test(e)?{kind:"enum",value:s}:{kind:"text",value:n}}return Array.isArray(n)?n.length<=vR&&n.every(s=>typeof s=="string"&&s.length<=qW)?{kind:"chips",values:n}:{kind:"rows",values:n}:li(n)?{kind:"group",value:n}:{kind:"text",value:String(n)}}function eH({value:e,title:n,tool:s,face:r,timezone:a}){const[i,l]=d.useState(!1),o=_m(e)||tH(e)?"other":YW(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(Jn,{label:`More for ${n}`,items:[{label:i?"Show readable":"Raw JSON",onSelect:()=>l(c=>!c)}]})]}),i?t.jsx("pre",{className:"ui-code",children:ls(e)}):t.jsx(nH,{view:o,value:e,timezone:a})]})}function tH(e){return li(e)&&Array.isArray(e.artifacts)}function nH({view:e,value:n,timezone:s}){switch(e){case"items":return t.jsx(rH,{shape:xR(n),timezone:s});case"profile":return t.jsx(sH,{value:n,timezone:s});case"settings":return t.jsx(aH,{value:n,timezone:s});case"fields":return t.jsx(Qy,{value:n,timezone:s,depth:0});default:return t.jsx(uR,{props:{value:n},bare:!0})}}function sH({value:e,timezone:n}){const s=qy(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:Kt(s)}),t.jsx("span",{className:"wb-result-lead-v",children:String(e[s])})]}),t.jsx(Qy,{value:r,timezone:n,depth:0})]})}function rH({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:[Kt(l)," ",t.jsx(mo,{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:Kt(c),children:t.jsx(mo,{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 aH({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:Kt(s)}),t.jsx("dd",{children:t.jsx(mo,{field:s,value:r,timezone:n})})]},s))})}const iH=3;function Qy({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=jR(a,i);if(l.kind==="group"){const o=Object.keys(l.value).length;return t.jsx("div",{className:"wb-result-group",children:t.jsx(Gt,{summary:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"wb-result-group-k",children:Kt(a)})," ",t.jsxs("span",{className:"wb-result-group-n",children:[o," ",o===1?"field":"fields"]})]}),open:s===0&&o<=4,children:s+1>=iH?t.jsx("pre",{className:"ui-code",children:ls(l.value)}):t.jsx(Qy,{value:l.value,timezone:n,depth:s+1})})},a)}return t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:Kt(a)}),t.jsx("dd",{children:t.jsx(mo,{field:a,value:i,timezone:n})})]},a)})})}function mo({field:e,value:n,timezone:s}){const r=jR(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(Se,{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)?mn(r.value):String(Math.round(r.value*100)/100)});case"day":return t.jsx("span",{children:Po(r.value,{year:!0})});case"moment":return t.jsx("time",{dateTime:r.value,children:mt(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(Se,{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(Se,{children:a},`${a}-${i}`))});case"rows":return t.jsx(lH,{values:r.values,timezone:s});case"group":return t.jsxs("span",{className:"wb-result-empty",children:[Object.keys(r.value).length," fields"]})}}function lH({values:e,timezone:n}){const[s,r]=d.useState(!1),a=s?e:e.slice(0,vR);return t.jsxs("span",{className:"wb-result-compact",children:[t.jsx("ul",{children:a.map((i,l)=>t.jsx("li",{children:oH(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 oH(e,n){if(li(e)){const s=qy(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:Kt(a),children:[" ",t.jsx(mo,{field:a,value:i,timezone:n})]},a))]})}return t.jsx(mo,{field:"",value:e,timezone:n})}function cH({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(rg,{children:"Opens by default"}):null,t.jsx(rg,{children:e.source==="example"?"Shipped with buddi":"Yours"}),e.roles.map(s=>t.jsx(rg,{title:`A surface command that asks for "${s}" lands on this agent.`,children:Kt(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(cc,{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(wR,{}),"Exact action"]})]})]})}),t.jsx(cc,{title:"What it can do",note:uH(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(dH,{family:s},s.family))}),t.jsx(cc,{title:"What it runs on",children:t.jsxs("dl",{className:"wb-prof-kv",children:[t.jsx(uc,{label:"Provider",children:e.engine.provider}),t.jsx(uc,{label:"Model",children:t.jsx("span",{className:"mono",children:e.engine.model})}),t.jsxs(uc,{label:"Credential",children:[e.engine.credentialKind," from"," ",t.jsx("span",{className:"mono",children:e.engine.credentialEnv})]}),t.jsxs(uc,{label:"Turn budget",children:[e.engine.maxTurns," ",e.engine.maxTurns===1?"turn":"turns"," per message"]}),t.jsx(uc,{label:"Language",children:gH(e.engine.language)})]})}),e.skills.length>0?t.jsx(cc,{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(cc,{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 uH(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 dH({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:Kt(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(hH,{tool:s},s.name))})]})}function hH({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:pH(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(wR,{}),"Needs your approval"]}):t.jsx("span",{className:"wb-prof-auto",title:mH(e.tier),children:fH(e.tier)})]})}function fH(e){return e==="auto"?"Runs on its own":e==="gated"?"Needs your approval":"Not runnable here"}function mH(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 pH(e){const n=e.split(".");return(n[n.length-1]??e).replace(/_/g," ")}function gH(e){return e==="mirror"?"Mirrors whichever language you write in":e==="en"?"Always English":e==="fr"?"Always French":e}function cc({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 uc({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 rg({children:e,title:n}){return t.jsx("span",{className:"wb-prof-tag",title:n,children:e})}function wR(){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 gS=16e3,xH=10*6e4,vH="The microphone is blocked for this page: allow it in the browser’s site settings to talk.",yR="This browser cannot record here: talking needs a microphone and a secure page (https or localhost).";function jH(){const e=window;return e.AudioContext??e.webkitAudioContext}function wH(e){const n=e&&typeof e=="object"&&"name"in e?String(e.name):"";return n==="NotAllowedError"||n==="SecurityError"||n==="PermissionDeniedError"?vH:n==="NotFoundError"||n==="DevicesNotFoundError"?"No microphone was found on this computer.":n==="NotReadableError"?"The microphone is in use by another app.":yR}async function yH(e){var c;const n=jH();if(!((c=navigator.mediaDevices)!=null&&c.getUserMedia)||!n)throw Object.assign(new Error(yR),{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 f=0;for(let m=0;m<h.length;m++)f+=h[m]*h[m];e(Math.min(1,Math.sqrt(f/h.length)*6))},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(),NH(kH(bH(l),u,gS),gS)},cancel:o}}function bH(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 kH(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 NH(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 Fv="buddi.readAloud";function bR(){try{return window.localStorage.getItem(Fv)==="on"}catch{return!1}}function kR(e){try{e?window.localStorage.setItem(Fv,"on"):window.localStorage.removeItem(Fv)}catch{}}let Or=null,Dc=null,Su=0,_v=null;const zv=new Set;function xf(e){_v!==e&&(_v=e,zv.forEach(n=>n()))}function SH(){return _v}function CH(e){return zv.add(e),()=>zv.delete(e)}function NR(e){return Uo(),xf(e),Su}function xS(e){return e===Su}function Uo(){Su++,Or&&(Or.pause(),Or.removeAttribute("src")),Dc&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(Dc),Dc=null,xf(null)}async function EH(e,n,s=null){var a;const r=NR(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!==Su)return;Or||(Or=new Audio,(a=Or.addEventListener)==null||a.call(Or,"ended",()=>xf(null))),Dc=URL.createObjectURL(l),Or.src=Dc,await Or.play()}catch(i){throw r===Su&&xf(null),i}}const AH=new Set(["audio/ogg","audio/mpeg","audio/mp4","audio/wav","audio/x-wav","audio/webm"]);function Jy(e){return AH.has(e.toLowerCase().split(";")[0].trim())}function Lc(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 SR(e,n){const s=d.useRef(null),r=d.useRef(null),[a,i]=d.useState(!1),[l,o]=d.useState(!1),[c,u]=d.useState(!1),[h,f]=d.useState(0),[m,p]=d.useState(null);return d.useEffect(()=>()=>{var k;(k=s.current)==null||k.pause(),r.current&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(r.current)},[]),{playing:a,loading:l,failed:c,position:h,duration:m,toggle:async()=>{const k=s.current;if(k){if(a){k.pause();return}Uo(),u(!1);try{if(!r.current){o(!0);const j=await fetch(ai(e),{credentials:"same-origin"});if(!j.ok)throw new Error(String(j.status));r.current=URL.createObjectURL(new Blob([await j.arrayBuffer()],{type:n})),k.src=r.current}await k.play()}catch{u(!0)}finally{o(!1)}}},bind:{ref:s,preload:"none",onPlay:()=>i(!0),onPause:()=>i(!1),onEnded:()=>{i(!1),f(0)},onTimeUpdate:k=>f(k.currentTarget.currentTime),onLoadedMetadata:k=>p(Number.isFinite(k.currentTarget.duration)?k.currentTarget.duration:null),onDurationChange:k=>p(Number.isFinite(k.currentTarget.duration)?k.currentTarget.duration:null)}}}function Um({artifactId:e,name:n,mime:s,sizeBytes:r}){const{playing:a,loading:i,failed:l,position:o,duration:c,toggle:u,bind:h}=SR(e,s),f=l?"Could not play. Download it instead.":`${Lc(o)} / ${Lc(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(ie,{name:a?"pause":"play",size:14})}),t.jsxs("span",{className:"wb-file-text",children:[t.jsx("span",{className:"wb-file-name",title:n,children:n}),t.jsxs("span",{className:"wb-file-meta","data-testid":"audio-time",children:[i?"Loading…":f,!l&&_n(r)?` · ${_n(r)}`:""]})]}),t.jsx("a",{className:"ui-icon-btn wb-audio-download","data-size":"sm",href:ai(e),download:n,"aria-label":`Download ${n}`,title:"Download",children:t.jsx(ie,{name:"download",size:14})}),t.jsx("audio",{...h})]})}const ag=1e5,ig=200,lg=30;function CR({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:yr(e),alt:n??"Image",onError:()=>l(!0)})}):r==="audio"&&Jy(s)?t.jsx("div",{className:"file-preview file-preview-audio",children:t.jsx(Um,{artifactId:e,name:n??"Audio",mime:s})}):r==="pdf"?t.jsx("div",{className:"file-preview file-preview-pdf",children:t.jsx("object",{data:yr(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($H,{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 $H({artifactId:e,filename:n,mime:s,family:r}){const[a,i]=d.useState("loading");if(d.useEffect(()=>{let o=!1;return i("loading"),fetch(yr(e),{credentials:"same-origin"}).then(async c=>{if(!c.ok)throw new Error(String(c.status));const u=await c.text();o||i({text:u.slice(0,ag),truncated:c.headers.get("X-Preview-Truncated")==="1"||u.length>ag})}).catch(()=>{o||i("failed")}),()=>{o=!0}},[e]),a==="loading")return t.jsx("div",{className:"file-preview",children:t.jsx(be,{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(IH,{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 ",ag.toLocaleString()," characters. The download has the whole file."]}):null]})}function TH(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=""},f=()=>{h(),a.push(i),i=[]};let m=0;for(;m<e.length;m+=1){if(a.length>=s){u=e.slice(m).trim()!=="";break}const p=e[m];if(o){p==='"'?e[m+1]==='"'?(l+='"',m+=1):o=!1:l+=p;continue}if(p==='"'){o=!0;continue}if(p===n){h();continue}if(p!=="\r"){if(p===`
104
+ `){f();continue}l+=p}}return a.length<s&&(l!==""||i.length>0)&&f(),{rows:a,truncatedRows:u,truncatedCols:c}}function IH({text:e,delimiter:n}){const s=d.useMemo(()=>TH(e,n,ig+1,lg),[e,n]),[r,...a]=s.rows;if(!r)return t.jsx("p",{className:"muted",children:"The file is empty."});const i=Math.min(lg,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,ig).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 ",ig," rows",s.truncatedCols?` and ${lg} columns`:"",". The download has the whole file."]}):null]})}function RH(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 PH(e,n){return`/api/artifacts/${encodeURIComponent(e)}/export/${n}`}function MH(e,n){return`${(e??"document").replace(/\.[a-z0-9]{1,8}$/i,"")||"document"}.${n}`}function vS(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 ER({artifactId:e,filename:n,mime:s,accent:r=!0}){const a=n??"download",i=RH(s,n),l=r?"accent":void 0;if(i.length===0)return t.jsx("a",{className:"ui-btn","data-variant":l,href:ai(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?vS(ai(e),a):vS(PH(e,h.format),MH(n,h.format))});return t.jsx(Jn,{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(ie,{name:"chevron-down"})]})})}function OH({attachment:e}){const n=Hy(e.mime,e.filename);return t.jsxs("div",{className:"wb-artifact","data-family":n,"data-testid":"artifact-view",children:[t.jsx(CR,{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:[Bi[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:_n(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(ER,{artifactId:e.artifactId,filename:e.filename,mime:e.mime})})]})}const jS=80,DH=["query","path","url","dir"],LH=["message","task"];function Xy(e,n){const s=FH(n);if(!s)return null;const r=bl(s.command);if(r!==null){const l=bl(s.name);return _d(l===null?r:`${l}: ${r}`)}for(const l of DH){const o=bl(s[l]);if(o!==null)return _d(o)}const a=bl(s.action);if(a!==null){const l=LH.map(o=>bl(s[o])).find(o=>o!==null)??null;return _d(l===null?a:`${a} · ${l}`)}const i=Object.values(s).filter(l=>typeof l=="string");return i.length===1?_d(bl(i[0])):null}function bl(e){if(typeof e!="string")return null;const n=e.replace(/\s+/g," ").trim();return n===""?null:n}function _d(e){return e===null?null:e.length>jS?`${e.slice(0,jS-1)}…`:e}function FH(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const AR="owner.notify",la=e=>typeof e=="string"&&e.trim()!==""?e:null;function _H(e){const n=e!==null&&typeof e=="object"?e:{};return{title:la(n.title)??"(no title)",text:la(n.text),urgency:la(n.urgency)??"now",key:la(n.key),link:la(n.link)}}function $R(e){if(e===null||typeof e!="object")return la(e);const n=e;return la(n.delivered)??la(n.message)??la(n.error)}function zH(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 UH=/^[a-z0-9](?:[a-z0-9._-]{0,94}[a-z0-9])?$/,BH=/^[a-z][a-z0-9_-]{0,63}$/;function Zu(e,n,s=64){return!BH.test(e)||typeof n!="string"||!UH.test(n)||n.includes("..")?null:`/api/plugin-assets/${e}/${n}?size=${s}`}function TR(e){return typeof e=="string"&&/^\/api\/plugin-assets\/[a-z][a-z0-9_-]{0,63}\/[a-z0-9._-]+(\?size=(64|128))?$/.test(e)}function WH(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 Bo({src:e,label:n,className:s}){const[r,a]=d.useState(!1),i=e!==null&&TR(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)}):WH(n)})}const yh="news",HH="edition";function IR(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 Wt=e=>typeof e=="string"?e:"",KH=e=>/^https?:\/\/[^\s]+$/i.test(e),wS=/^[a-z][a-z0-9_]*\.[a-z][a-z0-9_]*$/,vf=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null;function yS(e){const n=vf(e);if(!n)return null;const s={};for(const[r,a]of Object.entries(n)){const i=vf(a);if(!i||!("const"in i))return null;s[r]=i.const}return s}function VH(e){return(Array.isArray(e)?e:[]).flatMap(n=>{const s=vf(n);if(!s)return[];const r=Wt(s.label).trim(),a=Wt(s.tool),i=yS(s.args??{});if(r===""||!wS.test(a)||!i)return[];const l=vf(s.undo),o=l?yS(l.args??{}):null,c=l&&wS.test(Wt(l.tool))&&o?{tool:Wt(l.tool),label:Wt(l.label).trim()||"Undo",args:o}:null,u=Wt(s.hint).trim(),h=Wt(s.group).trim(),f=Wt(s.confirm).trim();return[{label:r,tool:a,args:i,...u?{hint:u}:{},...h?{group:h}:{},...f?{confirm:f}:{},done:Wt(s.done).trim()||"Done.",...c?{undo:c}:{}}]}).slice(0,12)}function GH(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=Wt(c.title).trim();if(u==="")return[];const h=c.link!==null&&typeof c.link=="object"?c.link:null,f=h?Wt(h.url):"",m=c.mark==="update"||c.mark==="opinion"?c.mark:void 0,p=Wt(c.topicName).trim(),v=VH(c.actions);return[{...m?{mark:m,markLabel:Wt(c.markLabel)||void 0}:{},title:u,lead:Wt(c.lead),outlet:Wt(c.outlet),more:typeof c.more=="number"&&Number.isFinite(c.more)&&c.more>0?Math.floor(c.more):0,...KH(f)?{link:{url:f,label:Wt(h.label)||f}}:{},logos:(Array.isArray(c.logos)?c.logos:[]).flatMap(g=>{if(g===null||typeof g!="object")return[];const k=Wt(g.name),j=Wt(g.logo);return k?[{name:k,...j?{logo:j}:{}}]:[]}),...p?{topicName:p}:{},...v.length>0?{actions:v}:{}}]});return l.length>0?[{topic:Wt(i.topic),stories:l}]:[]});if(r.length===0)return null;const a=Wt(s.next);return{id:Wt(s.id),name:Wt(s.name)||"Edition",when:Wt(s.when),lede:Wt(s.lede),groups:r,notes:(Array.isArray(s.notes)?s.notes:[]).filter(i=>typeof i=="string"&&i.trim()!==""),.../^\d{1,2}:\d{2}$/.test(a)?{next:a}:{}}}function YH(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 qH({s:e}){const[n,s]=d.useState(null),r=e.logos[0]??{name:e.outlet||e.title},a=e.outlet||r.name,[i,l]=d.useState(null),o=e.actions??[],c=async f=>{try{const m=await T.pageAct(yh,{tool:f.tool,args:f.args});s(m.approvalId?{text:"Waiting for your approval."}:{text:f.done,...f.undo?{undo:f.undo}:{}})}catch(m){s({text:m instanceof Error&&m.message?`That did not work: ${m.message}`:"That did not work."})}},u=async f=>{try{await T.pageAct(yh,{tool:f.tool,args:f.args}),s(null)}catch{s({text:"Could not take it back. Undo it in News → Sources."})}};if(n)return t.jsxs("li",{className:"ed-story ed-story-gone",role:"status",children:[t.jsx("span",{children:n.text}),n.undo?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"pl-story-gone-sep","aria-hidden":"true",children:"·"}),t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>void u(n.undo),children:n.undo.label})]}):null]});const h=[e.topicName,a?e.more>0?`${a} and ${e.more} more`:a:""].filter(Boolean).join(" · ");return t.jsxs("li",{className:"ed-story",children:[o.length>0?t.jsx("span",{className:"ed-more-btn",children:t.jsx(Jn,{label:`Ways out for ${e.title}`,items:YH(o,f=>f.confirm?l(f):void c(f)),sheet:{title:e.title,sub:h},stacked:!0})}):null,i?t.jsx(Rt,{title:i.confirm??i.label,onClose:()=>l(null),foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:()=>l(null),children:"Cancel"}),t.jsx(E,{variant:"accent",onClick:()=>{const f=i;l(null),c(f)},children:i.label})]})}):null,t.jsx(Bo,{src:r.logo?Zu(yh,r.logo):null,label:r.name,className:"pl-logo-md"}),t.jsxs("span",{className:"ed-story-text",children:[t.jsxs("span",{className:"ed-story-title",children:[e.mark?t.jsx("span",{className:"ed-mark","data-kind":e.mark==="update"?"update":void 0,children:e.mark==="update"?"Update":"Opinion"}):null,e.title]}),e.lead?t.jsx("span",{className:"ed-story-line",children:e.lead}):null,a?t.jsxs("span",{className:"ed-story-src",children:[e.link?t.jsxs("a",{className:"wb-src-link",href:e.link.url,target:"_blank",rel:"noopener noreferrer",title:e.link.label,children:[a,t.jsx("span",{className:"wb-src-out","aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:a}),e.more>0?t.jsxs("span",{className:"ed-more",children:["and ",e.more," more"]}):null]}):null]})]})}const bS=Array.from({length:64},(e,n)=>30+Math.round(Math.abs(Math.sin(n*1.7)*Math.cos(n*.4))*70));function QH({audio:e}){const{playing:n,loading:s,failed:r,position:a,duration:i,toggle:l,bind:o}=SR(e.fileId,e.mime),c=i?Math.min(1,a/i):0,u=r?"Could not play":s?"Loading…":i===null?"Listen":n||a>0?`${Lc(a)} / ${Lc(i)}`:Lc(i);return t.jsxs("button",{type:"button",className:"ed-audio","aria-label":n?"Pause the edition":"Listen to the edition","aria-pressed":n,disabled:s,onClick:()=>void l(),"data-testid":"edition-audio",children:[t.jsx("span",{className:"ed-play","aria-hidden":"true",children:n?t.jsxs("svg",{viewBox:"0 0 16 16",width:"12",height:"12",fill:"currentColor",children:[t.jsx("rect",{x:"4",y:"3",width:"3",height:"10",rx:"1"}),t.jsx("rect",{x:"9",y:"3",width:"3",height:"10",rx:"1"})]}):t.jsx("svg",{viewBox:"0 0 16 16",width:"12",height:"12",fill:"currentColor",children:t.jsx("path",{d:"M5 3.2v9.6c0 .5.5.8.9.5l7.2-4.8a.6.6 0 0 0 0-1L5.9 2.7c-.4-.3-.9 0-.9.5Z"})})}),t.jsx("span",{className:"ed-wave","aria-hidden":"true",children:bS.map((h,f)=>t.jsx("i",{style:{"--h":`${h}%`},"data-on":(n||a>0)&&f<Math.round(c*bS.length)?"true":void 0},f))}),t.jsx("span",{className:"ed-dur",children:u}),t.jsx("audio",{...o})]})}function JH({edition:e,audio:n}){const s=[...e.notes,`${e.next?`Next edition at ${e.next}. `:""}Tell me what to leave out, or mute anything from News.`];return t.jsxs("div",{className:"ed","data-testid":"edition-card",children:[t.jsxs("div",{className:"ed-head",children:[t.jsx("span",{className:"ed-kicker",children:e.name}),e.when?t.jsx("span",{className:"ed-when",children:e.when}):null]}),n,e.lede?t.jsx("p",{className:"ed-lede",children:e.lede}):null,e.groups.map((r,a)=>t.jsxs("section",{className:"ed-group",children:[r.topic?t.jsx("h4",{className:"ed-topic",children:r.topic}):null,t.jsx("ul",{className:"ed-list",children:r.stories.map((i,l)=>t.jsx(qH,{s:i},l))})]},a)),t.jsx("p",{className:"ed-foot",children:s.join(" ")})]})}function XH({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(yh,HH,{id:e}).then(h=>{u&&i(GH(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(JH,{edition:a,audio:s?t.jsx(QH,{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(Um,{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(E,{size:"sm",variant:"ghost","aria-pressed":l,onClick:()=>o(!l),children:l?"Show as card":"Show as text"}):null,t.jsx(nt,{className:"wb-report-link",size:"sm",href:r.route,children:r.label})]})]})}const ZH="mission.report",kl=e=>typeof e=="string"&&e.trim()!==""?e.trim():null,eK=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function tK(e,n){const s=e!==null&&typeof e=="object"?e:{},r=n!==null&&typeof n=="object"?n:{},a=kl(r.link),i=r.audio!==null&&typeof r.audio=="object"?r.audio:null,l=i?kl(i.fileId):null,o=i?kl(i.mime):null;return{text:kl(s.text),link:a&&a.startsWith("#/")?{route:a,label:kl(r.linkLabel)??"Open"}:null,audio:l&&eK.test(l)&&o&&Jy(o)?{fileId:l,mime:o,filename:i?kl(i.filename):null,sizeBytes:i&&typeof i.sizeBytes=="number"?i.sizeBytes:null}:null}}function nK(e){return!!(e.text&&e.link&&IR(e.link.route))}function kS({view:e}){var a;if(!e.text&&!e.audio)return null;const n=e.audio?t.jsx(Um,{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(wr,{text:e.text})}):null,r=IR((a=e.link)==null?void 0:a.route);return r&&e.link&&e.text?t.jsx(XH,{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 RR=3,sK=2*6e4,NS=40,rK=["filename","fileName","file_name","file","filePath","file_path","path"],aK=["accountName","account_name","account"],iK=["pageId","page_id","page"],lK=["url","href","link"],oK=new Set(["conversationId","agentId","runId","toolUseId","ownerId","requestId"]);function PR(e){return e.length>NS?`${e.slice(0,NS-1)}…`:e}function bh(e){const n=e.trim();return n===""?null:{key:n,label:PR(n)}}function SS(e){const n=(e.split(/[?#]/)[0]??"").trim(),s=(n.split(/[\\/]/).filter(Boolean).at(-1)??"").trim();return s===""?null:{key:n,label:PR(s)}}function cK(e){try{const n=new URL(e);return n.host?bh(n.host.replace(/^www\./,"")):null}catch{return null}}function og(e){if(typeof e=="string")return bh(e);if(typeof e=="number"&&Number.isFinite(e))return bh(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 bh(n[s])}return null}function CS(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;const n=e;for(const s of rK){const r=n[s];if(typeof r=="string"){const a=SS(r);if(a)return a}else if(s==="file"){const a=og(r);if(a)return SS(a.key)}}for(const s of aK){const r=og(n[s]);if(r)return r}for(const s of iK){const r=og(n[s]);if(r)return r}for(const s of lK){const r=n[s];if(typeof r=="string"){const a=cK(r);if(a)return a}}return null}function uK(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;for(const[n,s]of Object.entries(e))if(!(oK.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 dK(e,n){return CS(e)??CS(n)??uK(e)}function ES(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 Zy(e){var n;return((n=e.versions)==null?void 0:n.at(-1))??null}function zd(e){var n;return((n=Zy(e))==null?void 0:n.id)??e.id}function AS(e,n){return e.find(s=>s.id!==n&&(s.versions??[]).some(r=>r.id===n))??null}function hK(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 Uv(e){if(!e)return 0;const n=Date.parse(e);return Number.isNaN(n)?0:n}function fK(e,n){var s;return Math.max(Uv(((s=Zy(e))==null?void 0:s.at)??e.at),n[e.id]??0)}function MR(e,n={}){return e.map((s,r)=>({item:s,index:r,at:fK(s,n)})).sort((s,r)=>r.at-s.at||r.index-s.index).map(({item:s})=>s)}function mK(e,n,s=RR,r={}){const a=MR(e,r),i=new Set(e.filter(o=>o.id===n||o.source==="approval"||o.pinned===!0).map(o=>o.id));for(const o of a){if(i.size>=s)break;o.parked||i.add(o.id)}const l=a.filter(o=>i.has(o.id));return{shown:[...l.filter(o=>o.pinned===!0),...l.filter(o=>o.pinned!==!0)],hidden:a.filter(o=>!i.has(o.id))}}function pK(e,{now:n,turnStartedAt:s,touched:r={}}){var l;const a=Uv(s),i=[{label:"Now",items:[]},{label:"Earlier this turn",items:[]},{label:"Earlier",items:[]}];for(const o of MR(e,r)){const c=Uv(((l=Zy(o))==null?void 0:l.at)??o.at),u=a>0&&c>=a;c>0&&c>=n-sK&&(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 oi="agent.delegate";function gK(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 xK(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 Bv="canvas.show",$S="canvas.clear",TS=12;function vK(e){return`sources:${e}`}function jK(e){return`tab:${e}`}function OR(e){return e.role==="user"&&(e.blocks??[]).some(n=>n.type==="text"&&n.text.trim()!==""||n.type==="attachment")}function Zl(e){return`${e.plugin}/${e.name}`}function wK(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;const n=e.diff;return typeof n=="string"&&n.trim()!==""}function yK({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=GI(o,jf(l.output)).props;c.target===null&&c.awaiting!==null&&a.push({...c.awaiting,at:i.at??null})}return a}function DR({messages:e,descriptors:n,awaiting:s,folded:r,served:a,gathered:i,quiet:l,titles:o}){var k;const c=j=>_R(j,o),u=new Map(n.map(j=>[j.tool,j])),h=new Map;let f=[],m=0,p=null;const v=j=>{p||(p={id:vK(j.id),tool:j.tool,title:"Sources",renderer:"sources",source:"sources",props:{entries:[]},at:j.at,substantial:!1,count:0},f.push(p));const x=p.props,w=x.entries.some(y=>y.id===j.id)?x.entries.map(y=>y.id===j.id?{...j,input:j.input??y.input}:y):[...x.entries,j],N=[...new Set(w.map(y=>y.tool))];p.props={entries:w},p.tool=N.join(" · "),p.count=w.length,p.substantial=w.some(y=>y.ok===!0),p.tone=w.every(y=>y.ok===!1)?"critical":void 0},g=(j,x,w)=>{if(w&&(j.expiresAt=w),!x){f.push(j);return}j.subject=x.label,j.subjectKey=x.key,j.title=`${j.title} · ${x.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}:{}},y=f.find(S=>S.subjectKey===x.key&&S.tool===j.tool&&(S.source==="descriptor"||S.source==="fallback"));if(!y){f.push({...j,id:jK(j.id),versions:[N]});return}f=f.filter(S=>S!==y);const b={...j,id:y.id,versions:[...y.versions??[],N]};j.tone||delete b.tone,w||delete b.expiresAt,f.push(b)};for(const j of e){OR(j)&&(p=null);for(const x of j.blocks??[]){if(x.type==="tool_use"){if(h.set(x.id,{name:x.name,input:x.input,at:j.at??null}),i!=null&&i.has(x.name)){v({id:x.id,tool:x.name,input:x.input,output:null,ok:null,at:j.at??null});continue}if(x.name===Bv){const P=kK(x.id,x.input,j.at??null);P&&f.push(P)}if(x.name===$S&&(f=[],p=null),x.name===oi){const P=gK(x.input);P&&f.push({id:x.id,tool:oi,title:"Delegation",renderer:"delegate",props:{...P,result:null},at:j.at??null,source:"delegate",substantial:!0})}continue}if(x.type!=="tool_result"||x.name===Bv||x.name===$S)continue;const w=h.get(x.toolUseId),N=j.at??(w==null?void 0:w.at)??null,y=x.name||(w==null?void 0:w.name)||"tool",b=f.find(P=>P.source==="delegate"&&P.id===x.toolUseId);if(b&&((k=x.delegation)==null?void 0:k.state)==="waiting"){b.props={...b.props,result:null,waiting:{approvalId:x.delegation.approvalId}},x.delegation.approvalId&&(b.tone="warning");continue}if(b){b.props={...b.props,result:{ok:x.ok,text:xK(x.ok?x.output:x.error??x.output),...x.ok&&ff(x.output).length>0?{files:ff(x.output)}:{}}},x.ok||(b.tone="critical");continue}const S=x.approval?Hv(x):(s==null?void 0:s.get(x.toolUseId))??Hv(x);if(S){f.push({id:x.toolUseId,tool:y,title:"Approval",renderer:"envelope",props:{approvalId:S},at:N,tone:"warning",source:"approval",substantial:!0});continue}if(r!=null&&r.has(y)||l!=null&&l.has(y)&&x.ok!==!1)continue;if(i!=null&&i.has(y)){v({id:x.toolUseId,tool:y,input:(w==null?void 0:w.input)??null,output:jf(x.output)??null,ok:x.ok!==!1,...x.error===void 0?{}:{error:x.error},at:N});continue}if(y===AR){f.push({id:x.toolUseId,tool:y,title:"Message to you",renderer:"notify",props:{input:(w==null?void 0:w.input)??null,output:x.output??null,ok:x.ok!==!1},at:N,tone:x.ok===!1?"critical":void 0,source:"notify",substantial:!1});continue}const C=jf(x.output),A=dK((w==null?void 0:w.input)??null,C);if(x.ok===!1){g({id:x.toolUseId,tool:y,title:c(y),renderer:"structured",props:{value:x.error??C??null,failed:!0},at:N,tone:"critical",source:"fallback",substantial:!1},A,null);continue}wK(C)&&(m+=1);const $=u.get(y);if($){const P=GI($,C),{renderer:O}=P;let{props:R}=P;if(O==="preview"){const U=R,W=U.target??(U.awaiting&&(a!=null&&a.has(Zl(U.awaiting)))?U.awaiting:null);if(W===null)continue;R={...U,target:W,awaiting:null};const M=Zl(W);f=f.filter(L=>!(L.source==="descriptor"&&L.renderer==="preview"&&L.props.target!==null&&Zl(L.props.target)===M))}const D={id:x.toolUseId,tool:y,title:$.title??c(y),renderer:O,props:R,at:N,source:"descriptor",substantial:Wv(O,R)};O==="preview"?f.push(D):g(D,A,ES(C));continue}const I={value:_m(C)?{input:w==null?void 0:w.input,output:C}:C};NK("structured",I)&&g({id:x.toolUseId,tool:y,title:c(y),renderer:"structured",props:I,at:N,source:"fallback",substantial:Wv("structured",I)},A,ES(C))}}for(const j of f)j.source==="descriptor"&&j.renderer==="preview"&&(j.props={...j.props,changes:m});return bK(f)}const IS="forAgent";function jf(e){if(e===null||typeof e!="object"||Array.isArray(e)||!(IS in e))return e;const{[IS]:n,...s}=e;return s}function bK(e){if(e.length<=TS)return e;const n=e.length-TS;return[...e.slice(0,n).filter(r=>r.source==="approval"),...e.slice(n)]}function kK(e,n,s){if(n===null||typeof n!="object")return null;const{renderer:r,title:a,data:i}=n,l=typeof r=="string"&&gf(r)?r:"structured";return{id:e,tool:Bv,title:typeof a=="string"&&a.trim()!==""?a:"Shown",renderer:l,props:l==="structured"&&!gf(String(r))?{value:i}:i,at:s,substantial:!0,source:"canvas"}}function NK(e,n){const s=n??{};return!!(s.failed===!0||Wv(e,n)||Ky(s.value).kind==="error")}function Wv(e,n){const s=n??{};switch(e){case"timeseries":return dc(s.points)>0;case"bars":return dc(s.bars)>0;case"keyvalue":return dc(s.pairs)>0;case"tiles":return s.notice!==!0&&dc(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=>dc(a.rows)>0);default:return _m(s.value)?!0:s.failed===!0?!1:uW(s.value)}}function dc(e){return Array.isArray(e)?e.length:0}function Hv(e){if(e.approval)return e.approval.state==="pending"?e.approval.id:null;for(const n of[e.error,e.output]){const s=FR(n,0);if(s)return s}return null}function SK(e,n,s={}){var c,u,h;const r=f=>_R(f,s.titles),a=e.flatMap(f=>f.blocks),i=a.find(f=>f.type==="tool_use"&&f.id===n);if((i==null?void 0:i.type)!=="tool_use")return null;const l=a.find(f=>f.type==="tool_result"&&f.toolUseId===n);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:jf(l.output)??null},at:null,source:"fallback",substantial:!1};const o=(u=s.redactInputOf)!=null&&u.has(i.name)?LR(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 CK=new Set(["value","text","password","secret","code"]);function LR(e){if(e===null||typeof e!="object"||Array.isArray(e))return e;const n={};for(const[s,r]of Object.entries(e))n[s]=CK.has(s)&&typeof r=="string"?"— withheld —":LR(r);return n}function FR(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=FR(i,n+1);if(l)return l}return null}function el(e){const n=e.split(".");return n.length===1?Kt(e):n.map(s=>Kt(s)).join(" · ")}function _R(e,n){return(n==null?void 0:n.get(e))??el(e)}function RS(e,n){return e.find(s=>s.source==="sources"&&s.props.entries.some(r=>r.id===n))??null}function ed({name:e,mime:n,sizeBytes:s,thumbnail:r,state:a,error:i,onOpen:l,onRemove:o,size:c="md",detail:u}){const h=Hy(n,e),f=u??[Bi[h],_n(s)].filter(Boolean).join(" · "),m=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(eb,{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":f})]})]});return t.jsxs("span",{className:"wb-file","data-size":c,"data-state":a,"data-thumb":r?"true":void 0,title:a==="failed"?i:void 0,children:[l?t.jsx("button",{type:"button",className:"wb-file-open",onClick:l,"aria-label":`Open ${e}`,children:m}):t.jsx("span",{className:"wb-file-open",children:m}),o?t.jsx("button",{type:"button",className:"wb-file-x","aria-label":`Remove ${e}`,onClick:o,children:t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:t.jsx("path",{d:"M2.5 2.5l5 5M7.5 2.5l-5 5"})})}):null]})}function eb({family:e}){const n={width:20,height:20,viewBox:"0 0 20 20","aria-hidden":!0,fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"};switch(e){case"image":return t.jsxs("svg",{...n,children:[t.jsx("rect",{x:"3",y:"4",width:"14",height:"12",rx:"2"}),t.jsx("circle",{cx:"7.5",cy:"8.5",r:"1.4"}),t.jsx("path",{d:"M17 13l-3.6-3.6a1 1 0 0 0-1.4 0L6 15.5"})]});case"pdf":return t.jsxs("svg",{...n,children:[t.jsx("path",{d:"M6 2.5h5.5L16 7v9.5a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-13a1 1 0 0 1 1-1z"}),t.jsx("path",{d:"M11.5 2.5V7H16"}),t.jsx("path",{d:"M7.5 13.5h5M7.5 11h5"})]});case"table":return t.jsxs("svg",{...n,children:[t.jsx("rect",{x:"3",y:"4",width:"14",height:"12",rx:"1.5"}),t.jsx("path",{d:"M3 8.5h14M3 12.5h14M8 4v12M13 4v12"})]});case"text":return t.jsxs("svg",{...n,children:[t.jsx("path",{d:"M6 2.5h5.5L16 7v9.5a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-13a1 1 0 0 1 1-1z"}),t.jsx("path",{d:"M11.5 2.5V7H16"}),t.jsx("path",{d:"M7.5 10.5h5M7.5 13.5h3.5"})]});case"code":return t.jsx("svg",{...n,children:t.jsx("path",{d:"M7 6l-4 4 4 4M13 6l4 4-4 4M11.5 4l-3 12"})});case"audio":return t.jsx("svg",{...n,children:t.jsx("path",{d:"M4 8v4M7.5 5.5v9M11 3.5v13M14.5 6.5v7M18 8.5v3"})});case"video":return t.jsxs("svg",{...n,children:[t.jsx("rect",{x:"3",y:"5",width:"10",height:"10",rx:"1.5"}),t.jsx("path",{d:"M13 9l4-2.5v7L13 11"})]});case"archive":return t.jsxs("svg",{...n,children:[t.jsx("rect",{x:"4",y:"3",width:"12",height:"14",rx:"1.5"}),t.jsx("path",{d:"M10 3v3M10 8v2M10 12v2M8.5 14h3"})]});default:return t.jsxs("svg",{...n,children:[t.jsx("path",{d:"M6 2.5h5.5L16 7v9.5a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-13a1 1 0 0 1 1-1z"}),t.jsx("path",{d:"M11.5 2.5V7H16"})]})}}function EK(e,n,s){const r=MS(e),a=MS(n==null?void 0:n.input),i=Ei(r==null?void 0:r.name)??RK(Ei(r==null?void 0:r.handle))??Ei(r==null?void 0:r.agent)??Ei(a==null?void 0:a.agent),l=typeof e=="string"?e.trim()||null:Ei(r==null?void 0:r.text)??Ei(r==null?void 0:r.note),o=PS(r==null?void 0:r.durationMs)??PS(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:Ei(a==null?void 0:a.task),answer:l,files:ff(e),durationMs:o??h}}function AK(e,n){var r;let s=null;for(const a of e)for(const i of a.blocks??[])i.type==="tool_result"&&i.name===oi&&((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 $K({block:e,messages:n,answeredAt:s}){const r=EK(e.output,AK(n,e.actionId),s),a=[r.who?`Asked ${r.who}`:null,r.durationMs===null?null:`took ${TK(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(wr,{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:ai(i.artifactId),download:!0,children:t.jsx(ed,{name:i.filename??"Untitled file",mime:i.mime,sizeBytes:i.sizeBytes,thumbnail:Wy(i.mime)?yr(i.artifactId):null,size:"sm"})},i.artifactId))}):null,t.jsx(Gt,{summary:"Raw JSON",children:t.jsx("pre",{className:"wb-approval-output mono",children:IK(e.output)})})]})}function TK(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 IK(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function RK(e){return e===null?null:`@${e.replace(/^@/,"")}`}function Ei(e){return typeof e=="string"&&e.trim()!==""?e:null}function PS(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function MS(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const PK=1e3;function MK({messageId:e,text:n,onReadAloud:s}){const[r,a]=d.useState(!1),i=d.useRef(null),l=d.useSyncExternalStore(CH,SH)===e;d.useEffect(()=>()=>{i.current&&clearTimeout(i.current)},[]);const o=()=>{var c;(c=navigator.clipboard)==null||c.writeText(n).then(()=>{a(!0),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>a(!1),PK)},()=>{})};return t.jsxs("div",{className:"wb-reply-actions","data-testid":"reply-actions",children:[t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":r?"Copied":"Copy",title:r?"Copied":"Copy",onClick:o,children:t.jsx(ie,{name:r?"check":"copy",size:14})}),r?t.jsx("span",{className:"wb-reply-copied",role:"status",children:"Copied"}):null,s?t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":l?"Stop reading aloud":"Read aloud",title:l?"Stop reading aloud":"Read aloud","aria-pressed":l,onClick:()=>l?Uo():s(e,n),children:t.jsx(ie,{name:l?"stop":"play",size:14})}):null]})}function OK(e){const n=DK(e);if(!n)return null;const s=cg(n.diff);if(s!==null)return{kind:"diff",diff:s};const r=cg(n.command),a=cg(n.plain),i=ug(n.exitCode);return r!==null&&(a!==null||i!==null||ug(n.pid)!==null)?{kind:"command",command:r,output:a,exitCode:i,elapsedMs:ug(n.elapsedMs)}:null}function cg(e){return typeof e=="string"&&e.trim()!==""?e:null}function ug(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function DK(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const OS="offer:",zR="owner:interjection";function LK(e){return e===zR}function FK(e){if(typeof e!="string"||!e.startsWith(OS))return null;const n=e.slice(OS.length).trim();return n===""?null:n}const DS="brief:";function _K(e){if(typeof e!="string"||!e.startsWith(DS))return null;const n=e.slice(DS.length).trim();return n===""?null:n}function tb({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:f,onReadAloud:m,children:p,agentName:v,emptyHint:g,empty:k,plain:j=!1,workingLine:x,runs:w,onContinue:N}){var X;const y=d.useRef(null);d.useEffect(()=>{var K;(K=y.current)==null||K.scrollIntoView({block:"end"})},[e.length,n.length,a,i==null?void 0:i.text.length,i==null?void 0:i.thinking.length,!!p]);const b=i&&!i.settled&&(i.text!==""||i.thinking!==""),S=e.filter(K=>(K.blocks??[]).some(ZK)).map(UR),C=qK(S,w??[]),A=JK(S,w??[]),$=c??l??[],I=K=>(o&&!c?$.find(J=>J.id===o):void 0)??$.find(J=>J.name===K)??null,P=o?$.find(K=>K.id===o)??null:null,O=a||n.length>0,R=O||!!b,D=!!b&&i.text!=="",U=O&&!D,W=S.at(-1),M=(W==null?void 0:W.role)!=="assistant"||!!h,L=h??v??"Assistant",_=S.filter((K,J)=>{var q;return J===0||(c?(((q=S[J-1])==null?void 0:q.speaker)??null)!==(K.speaker??null):S[J-1].role!==K.role)}),Y=R&&!M?((X=_.at(-1))==null?void 0:X.id)??null:null,B=(w??[]).reduce((K,J)=>K===null||(J.startedAt??"")>(K.startedAt??"")?J:K,null),se=(w??[]).some(K=>K.finishedAt===null),G=N&&!R&&!se&&W&&(B==null?void 0:B.stopped)==="max_turns"&&C.get(W.id)===B?W.id:null;return t.jsx(HI.Provider,{value:l??c??[],children:t.jsxs("div",{className:"wb-messages","data-testid":"messages",children:[S.length===0&&n.length===0?k??t.jsx("p",{className:"wb-chat-empty",children:g}):null,S.map((K,J)=>{const q=K.speaker??null,ce=c?q==="owner"||q===null&&K.role==="user":K.role==="user",xe=c&&q==="room",Me=c&&q&&q!=="owner"&&q!=="room"?c.find(de=>de.id===q)??null:null,H=S[J-1],ne=J===0||(c?((H==null?void 0:H.speaker)??null)!==q:H.role!==K.role);if(xe)return t.jsx("div",{className:"wb-msg wb-msg-room","data-role":"room",children:(K.blocks??[]).filter(de=>de.type==="text").map((de,Ee)=>t.jsx("span",{children:de.text},Ee))},K.id);const Z=(K.blocks??[]).filter(de=>de.type==="approval_result");if(Z.length>0)return t.jsx("div",{className:"wb-msg","data-role":"assistant","data-testid":"approval-result",children:Z.map((de,Ee)=>t.jsx(e9,{block:de,messages:e,at:K.at||null},Ee))},K.id);const ye=K.role==="user"&&LK(q),Ce=K.role==="user"?_K(q):null;if(Ce)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:Ce})},K.id);const ke=K.role==="user"?FK(q):null;if(ke){const de=(K.blocks??[]).filter(Ee=>Ee.type==="text").map(Ee=>Ee.text).join(`
105
+ `);return t.jsx("div",{className:"wb-msg","data-role":"user","data-testid":"offer-turn",children:t.jsx("div",{className:"wb-bubble wb-bubble-offer",title:de,children:ke})},K.id)}const we=c&&Me&&K.role==="user"?KK(K):null;if(we){const de=S.slice(J+1).find(ze=>ze.role==="assistant"&&ze.speaker&&ze.speaker!==Me.id),Ee=de!=null&&de.speaker?c.find(ze=>ze.id===de.speaker):void 0;return t.jsxs("details",{className:"wb-msg wb-msg-room wb-msg-ask","data-role":"room",children:[t.jsxs("summary",{children:[Me.name," asked ",(Ee==null?void 0:Ee.name)??"a member",we.request?`: ${we.request.length>120?`${we.request.slice(0,119)}…`:we.request}`:""]}),we.request?t.jsx("p",{children:we.request}):null]},K.id)}const ve=C.get(K.id)??null,Ie=YK(K,e),Re=!ce&&!ye&&!j?GK(K):"";return t.jsxs("div",{className:"wb-msg","data-role":ce||ye?"user":"assistant",children:[ye?t.jsx("div",{className:"wb-msg-added","data-testid":"added-while-working",children:Ie.length>0?`Queued with ${Ie.length} file${Ie.length===1?"":"s"}`:"added while working"}):null,ne&&!ce&&!ye?t.jsx(LS,{name:Me?Me.name:c&&q&&q!=="owner"&&q!=="room"?q:v??"Assistant",face:Me??P??I(v),moving:U&&Y===K.id,children:Me&&u===Me.id?t.jsx("span",{className:"wb-msg-role",children:"coordinator"}):null}):null,Ie.length>0?t.jsx("div",{className:"wb-msg-files",role:"list","aria-label":"Files sent with this message",children:Ie.map(de=>t.jsx("span",{role:"listitem",children:Jy(de.mime)?t.jsx(Um,{artifactId:de.artifactId,name:de.filename??"Untitled file",mime:de.mime,sizeBytes:de.sizeBytes}):t.jsx(ed,{name:de.filename??"Untitled file",mime:de.mime,sizeBytes:de.sizeBytes,thumbnail:Wy(de.mime)?yr(de.artifactId):null,...f?{onOpen:()=>f(de)}:{}})},de.artifactId))}):null,(K.blocks??[]).map((de,Ee)=>{const ze=BK(K.blocks??[],Ee,e);if(ze==="inside")return null;if(ze)return t.jsx(WK,{refusals:ze.refusals},Ee);if(de.type==="thinking")return j||de.text.trim()===""?null:t.jsx(Kv,{text:de.text},Ee);if(de.type==="text")return de.text.trim()===""?null:ce?t.jsx("div",{className:"wb-bubble",children:de.text},Ee):t.jsx("div",{className:"wb-bubble","data-rich":"true",children:t.jsx(wr,{text:de.text})},Ee);if(de.type==="attachment")return null;if(de.type==="tool_use"){if(j)return null;const qe=nb(e,de.id),ht=qe?s9(qe):null,le=!ht&&de.name===AR&&qe?$R(qe.output):null,je=!ht&&de.name===ZH&&(qe!=null&&qe.ok)?tK(de.input,qe.output):null;return je&&nK(je)?t.jsx(kS,{view:je},Ee):t.jsxs(d.Fragment,{children:[t.jsx(Vv,{label:ht&&!(qe!=null&&qe.delegation)?`Approval · ${de.name}`:el(de.name),tool:de.name,ok:(qe==null?void 0:qe.ok)??null,running:qe===null,...ht?{status:ht.status,waiting:ht.waiting,approval:!0}:le?{status:le}:{},gist:Xy(de.name,de.input),body:qe?OK(qe.output):null,opens:!0,onOpen:()=>r(de.id)},Ee),je?t.jsx(kS,{view:je}):null]},Ee)}return null}),ve?t.jsxs("div",{className:"wb-msg-budget","data-testid":"budget-stop",children:[t.jsx("span",{children:XK(ve)}),G===K.id?t.jsx(E,{size:"sm",className:"wb-msg-budget-continue","data-testid":"budget-continue",onClick:N,children:"Continue"}):null]}):null,A.has(K.id)?t.jsx("div",{className:"wb-msg-unchecked","data-testid":"unchecked-answer",children:QK}):null,K.feedback&&!ce&&!ye?t.jsx(i9,{feedback:K.feedback}):null,Re!==""?t.jsx(MK,{messageId:K.id,text:Re,onReadAloud:m}):null]},K.id)}),R?t.jsxs("div",{className:"wb-msg","data-role":"assistant","data-testid":"live-turn",children:[M?t.jsx(LS,{name:L,face:I(L)??P,moving:U}):null,b&&i.thinking!==""&&!j?t.jsx(Kv,{text:i.thinking,live:i.text==="",seconds:HK(i.thinkingStartedAt,i.textStartedAt??s)}):null,D?t.jsxs("div",{className:"wb-bubble","data-live":"true","data-rich":"true",children:[t.jsx(wr,{text:i.text}),t.jsx("span",{className:"wb-caret","aria-hidden":"true"})]}):null,a&&n.length===0&&!b?t.jsxs("span",{className:"wb-working",role:"status","aria-live":"polite","data-testid":"working",children:[x??`${h??v??"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(K=>t.jsx(Vv,{label:el(K.name),tool:K.name,ok:null,running:!0,elapsed:Math.max(0,Math.round((s-K.startedAt)/1e3)),opens:!1,onOpen:()=>r(K.toolUseId)},K.toolUseId))]}):null,p,t.jsx("div",{ref:y})]})})}function LS({name:e,face:n,moving:s=!1,children:r}){const a=(n==null?void 0:n.picture)??null,i=_I(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(Ju,{state:"working",size:"sm",still:a,className:"wb-msg-blob"}):t.jsx(In,{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 zK(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 UK="delegation refused:";function BK(e,n,s){const r=i=>{const l=e[i];if(!l||l.type!=="tool_use"||l.name!==oi)return null;const o=nb(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(UK))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 WK({refusals:e}){const[n,s]=d.useState(!1),r=e.map(o=>zK(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(ie,{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:[el(oi)," · ",o.target]}),t.jsx("span",{className:"wb-tool-elapsed",children:"refused"})]}),t.jsx("p",{className:"wb-refusal-why",children:o.message})]},c))}):null]})}function HK(e,n){return e===null?null:Math.max(0,Math.round((n-e)/1e3))}function Kv({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(ie,{name:"thought"}),t.jsx("span",{children:i}),t.jsx(ie,{name:"arrow",className:"wb-tool-arrow"})]}),r?t.jsx("div",{className:"wb-thought-text",children:t.jsx(wr,{text:e})}):null]})}function KK(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 UR(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+VK(i.text,a.text)+a.text},r=!0):s.push(a)}return r?{...e,blocks:s}:e}function VK(e,n){return e===""||n===""||/\s$/.test(e)||/^\s/.test(n)||/^[.,;:!?)\]}»”’'"]/.test(n)?"":/[.!?:…)"”»]$/.test(e)?`
106
+
107
+ `:""}function GK(e){return(UR(e).blocks??[]).filter(n=>n.type==="text").map(n=>n.text.trim()).filter(n=>n!=="").join(`
108
+
109
+ `)}function YK(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===oi){const l=nb(n,i.id);l!=null&&l.ok&&ff(l.output).forEach(a)}return s}function qK(e,n){return BR(e,n,s=>(s.stopped==="max_turns"||s.stopped==="max_tokens")&&s.noticed===!0)}const QK="Answered from memory, not checked";function JK(e,n){return BR(e,n,s=>s.unchecked===!0)}function BR(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 XK(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 ZK(e){return e.type==="text"||e.type==="thinking"?e.text.trim()!=="":e.type==="tool_use"||e.type==="attachment"||e.type==="approval_result"}function e9({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":el(e.name)}),t.jsx("span",{className:"wb-tool-elapsed",children:e.state}),t.jsx(ie,{name:"arrow",className:"wb-tool-arrow"})]}),r&&e.name===oi?t.jsx($K,{block:e,messages:n,answeredAt:s}):null,r&&e.name!==oi?t.jsx("pre",{className:"wb-approval-output mono",children:t9(e.output)}):null]})}function t9(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}const n9=40;function s9(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(Hv(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 Vv({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:f=null}){const[m,p]=d.useState(!1),v=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 f?t.jsxs("div",{className:"wb-toolcall","data-open":m||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":m,onClick:()=>p(k=>!k),children:[t.jsx(ie,{name:"chevron",className:"wb-tool-chevron"}),v]}),i?t.jsxs(du,{children:[t.jsx(hu,{asChild:!0,children:t.jsx("button",{type:"button",className:"wb-tool-open","aria-label":"Open on the canvas",onClick:l,children:t.jsx(ie,{name:"arrow",className:"wb-tool-arrow"})})}),t.jsx(fu,{children:t.jsxs(mu,{className:"ui-tip",sideOffset:6,children:[t.jsx("span",{className:"ui-tip-title",children:"Open on the canvas"}),t.jsx("span",{className:"ui-tip-hint mono",children:n})]})})]}):null]}),m?t.jsx(r9,{body:f,onOpen:i?l:null}):null]}):i?t.jsxs(du,{children:[t.jsx(hu,{asChild:!0,children:t.jsxs("button",{className:"wb-tool",...g,onClick:l,children:[v,t.jsx(ie,{name:"arrow",className:"wb-tool-arrow"})]})}),t.jsx(fu,{children:t.jsxs(mu,{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:v})}function r9({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(lf,{text:e.diff,limit:n9,...s?{more:s}:{}})});const r=[e.exitCode===null?null:`exit ${e.exitCode}`,e.elapsedMs===null?null:a9(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 a9(e){return e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(1)}s`}function nb(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 i9({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 l9=20*1024*1024,o9=500,Ta=e=>`/skills/${encodeURIComponent(e)}`,Ud=e=>`/skills/bundles/${encodeURIComponent(e)}`;async function c9(e){var n;try{const{staged:s}=await ly("/skills/bundles",e,"bundle.zip");return s}catch(s){const r=s instanceof he?(n=s.detail)==null?void 0:n.refusal:void 0;throw r?new WR({...r,filename:e.name,error:s instanceof Error?s.message:void 0}):s}}class WR extends Error{constructor(s){super(s.error??`“${s.filename}” was refused.`);zk(this,"name","BundleRefused");this.refusal=s}}const nn={list:()=>ge("/skills"),detail:e=>ge(Ta(e)),downloadUrl:e=>`/api${Ta(e)}/download`,create:e=>te("/skills",e),saveText:(e,n)=>te(`${Ta(e)}/text`,{text:n}),grant:(e,n)=>te(`${Ta(e)}/grants`,n),trust:e=>te(`${Ta(e)}/trust`),remove:e=>hs(Ta(e)),file:(e,n)=>ge(`${Ta(e)}/file`,{path:n}),imageUrl:(e,n)=>`/api${Ta(e)}/image?path=${encodeURIComponent(n)}`,uploadBundle:c9,stagedFile:(e,n)=>ge(`${Ud(e)}/file`,{path:n}),stagedImageUrl:(e,n)=>`/api${Ud(e)}/image?path=${encodeURIComponent(n)}`,acceptBundle:(e,n)=>te(Ud(e),n),discardBundle:e=>hs(Ud(e))};function HR(e,n){return`${bt}?tab=skills${e?`&skill=${encodeURIComponent(e)}`:""}${e&&n?`&skfile=${encodeURIComponent(n)}`:""}`}function u9(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 d9(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 KR(e){const n=document.createElement("a");n.href=nn.downloadUrl(e),n.download="",document.body.appendChild(n),n.click(),n.remove()}const sb=[{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 ci(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function Zs(e,n){var s;return((s=e.find(r=>r.id===n))==null?void 0:s.name)??n}function rb(e){return e.charAt(0).toUpperCase()+e.slice(1)}function ab(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 ${ci(r)} (${s.length===1?"has its own":"each has its own"})`}function VR(e,n){return e.holders.some(s=>s.agent===n)}function h9(e,n){if(e.every)return ab(e,n);const s=e.holders.map(r=>Zs(n,r.agent));return s.length?ci(s):"No agent uses it yet"}function f9(e){return!e.every&&e.holders.length===0}function m9(){const e=new Date;return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}function FS(e){return e.slice(0,10)===m9()?"today":`on ${Po(e,{compact:!0})}`}function Fc(e,n,s=!1){var l,o;if(e.learned){const c=e.learned.by,u=s&&e.holders.some(f=>f.agent===c),h=e.learned.keptAt?` · kept ${Ye(e.learned.keptAt)}`:"";return`${u?"":`learned by ${Zs(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 ${rb(r.plugin)} ${r.version}`;if((r==null?void 0:r.kind)==="catalogue")return`came with ${Zs(n,r.agent)} ${r.version}`;if((r==null?void 0:r.kind)==="upload")return`uploaded${e.created?` ${FS(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 ${FS(a)}`:e.updatedAt?`edited by you ${Ye(e.updatedAt)}`:"written by you"}function GR(e){return e.charAt(0).toUpperCase()+e.slice(1)}function ib(e,n){var s;return e.untrusted==="page"?`Untrusted: a web page was in view when ${Zs(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 Hr(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 YR(e,n){return e.every?n.filter(s=>!(e.shadowedBy??[]).includes(s.id)).map(s=>s.id):e.holders.map(s=>s.agent)}function p9(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=YR(e,n),i=u=>{var h;return((h=n.find(f=>f.id===u))==null?void 0:h.canRunScripts)===!0},l=a.filter(i).map(u=>Zs(n,u)),o=a.filter(u=>!i(u)).map(u=>Zs(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} · ${ci(l)} can run them, asking first${o.length?`; ${ci(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 g9(e){var n;switch(e.kind){case"big":return{title:`“${e.filename}” is too big`,body:`${e.size?`It’s ${Hr(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 ${o9}.`};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 _S(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 lb(e){return e.every?[]:e.holders.map(n=>n.agent)}function x9(e,n){var s;if(e.learned){const r=Zs(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"?`${Zs(n,e.from.agent)}’s next update will ask before it replaces your change.`:null}function v9(e,n,s){var o;const r=n.stops.map(c=>Zs(s,c)),a=e.learned?Zs(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.":`${ci(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"?Zs(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 j9(e,n){var c,u;const s=n.replace(/\r\n/g,`
110
+ `),r=/^---\n([\s\S]*?)\n---\n*/.exec(s),a=h=>{var m;return(r?((m=new RegExp(`^${h}:\\s*(.*)$`,"m").exec(r[1]))==null?void 0:m[1])??"":"").trim().replace(/^(['"])(.*)\1$/,"$2")},i=r?s.slice(r[0].length):s,l=(u=(c=/^#\s+(.+)$/m.exec(i))==null?void 0:c[1])==null?void 0:u.trim(),o=a("name");return{title:l||(o?GR(o.replace(/-/g," ")):e.replace(/\.md$/i,"")),description:a("description"),body:i}}function w9(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 dg(e){return/[\s"'\\]/.test(e)||e===""?JSON.stringify(e):e}function y9(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(`${dg(r)} ${dg(a)}`),s+=1):n.push(dg(r))}return n}function b9({action:e,run:n,agentName:s,count:r,busy:a,error:i,onDecide:l}){const o=a!==null||e.state!=="pending",c=y9(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(Vt,{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(ae,{message:i}),t.jsx("div",{className:"wb-dock-section",children:t.jsxs(re,{children:[t.jsx("span",{className:"skb-dock-note",children:"Scripts ask every time."}),t.jsx(pt,{}),t.jsx(E,{variant:"ghost",size:"sm",disabled:o,onClick:()=>l("reject"),children:a==="reject"?"Rejecting…":"Reject"}),t.jsx(E,{size:"sm",onClick:()=>{window.location.hash=HR(n.bundle,n.script)},children:"Show the script"}),t.jsx(E,{variant:"good",size:"sm",disabled:o,onClick:()=>l("approve"),children:a==="approve"?"Allowing…":"Allow once"})]})})]})}const qR="approval-dock";function k9(){var n;const e=document.getElementById(qR);e&&((n=e.scrollIntoView)==null||n.call(e,{block:"nearest"}),e.focus())}const N9=["workspace","cwd","workdir","root"];function QR({approvals:e,timezone:n,now:s,version:r,onDecided:a,onSay:i,onOpenFull:l}){const[o,c]=d.useState([]),u=e.filter(m=>!o.includes(m.approvalId)),h=u[0];if(!h)return null;const f=m=>c(p=>p.includes(m)?p:[...p,m]);return t.jsx(S9,{item:h,count:u.length,timezone:n,now:s,version:r,onSettled:m=>{f(h.approvalId),m&&a(m)},onSay:i,onOpenFull:()=>l(h.toolUseId)},h.approvalId)}function S9({item:e,count:n,timezone:s,now:r,version:a,onSettled:i,onSay:l,onOpenFull:o}){var A,$,I;const[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(null),[v,g]=d.useState("");d.useEffect(()=>{let P=!1;return T.approval(e.approvalId).then(O=>{P||(u(O),O.state!=="pending"&&i(O))}).catch(O=>{P||f(O instanceof he?O.message:String(O))}),()=>{P=!0}},[e.approvalId,a]);const k=c!==null&&c.state==="pending"&&Date.parse(c.expiresAt)<=r;d.useEffect(()=>{k&&c&&i({...c,state:"expired"})},[k]);const{values:j,controls:x}=Uy(c==null?void 0:c.choices),w=(P,O)=>{const R=v.trim();p(P),f(null),(j&&P==="approve"?T.decide(e.approvalId,P,O,j):T.decide(e.approvalId,P,O)).then(D=>{i(D.action),R&&l(R)}).catch(D=>{f(D instanceof he?D.message:String(D)),p(null)})},N=w9(c);if(c&&N){const P=Im(c.agentId)?Tm:c.agentId?c.agentId.charAt(0).toUpperCase()+c.agentId.slice(1):"An agent";return t.jsx(b9,{action:c,run:N,agentName:P,count:n,busy:m,error:h,onDecide:O=>w(O)})}const y=m!==null||c===null||c.state!=="pending",b=((A=c==null?void 0:c.permissionScopes)==null?void 0:A.includes("always"))??!1,S=c?Xy(c.tool,c.canonicalArgs)??E9(c.preview):null,C=c?C9(c):null;return t.jsxs("section",{id:qR,tabIndex:-1,className:"wb-question","data-kind":"approval","aria-label":"Approval needed","data-testid":"approval-dock",children:[t.jsxs("div",{className:"wb-question-head",children:[t.jsx("span",{className:"wb-question-kicker",children:"Needs your OK"}),n>1?t.jsxs("span",{className:"wb-dock-count","data-testid":"approval-dock-count",children:["1 of ",n]}):null,t.jsx("strong",{children:c?el(c.tool):"Loading the request…"}),e.askedBy?t.jsx("span",{className:"wb-dock-asker","data-testid":"approval-dock-asker",children:e.askedBy}):null]}),S||C?t.jsxs("div",{className:"wb-dock-section wb-dock-subject",children:[S?t.jsx("code",{className:"wb-dock-gist",children:S}):null,C?t.jsxs("span",{className:"wb-dock-where",children:["in ",t.jsx("span",{className:"mono",children:C})]}):null]}):null,x?t.jsx("div",{className:"wb-dock-section",children:x}):null,t.jsx(ae,{message:h}),t.jsx("div",{className:"wb-dock-section",children:t.jsx("input",{className:"wb-dock-instead",value:v,onChange:P=>g(P.target.value),onKeyDown:P=>{P.key==="Enter"&&P.preventDefault()},placeholder:"Tell the agent what to do instead (optional)","aria-label":"Tell the agent what to do instead (optional)",disabled:m!==null})}),t.jsxs("div",{className:"wb-dock-section wb-dock-actions",children:[t.jsxs("span",{className:"wb-dock-meta",children:[c?t.jsxs(t.Fragment,{children:["Expires ",mt(c.expiresAt,s)," · "]}):null,t.jsx("button",{type:"button",className:"wb-link",onClick:o,children:"See the full request on the Canvas"})]}),t.jsx(E,{variant:"ghost",size:"sm",disabled:y,onClick:()=>w("reject"),children:m==="reject"?"Rejecting…":(($=c==null?void 0:c.answers)==null?void 0:$.reject)??"Reject"}),b?t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",size:"sm",disabled:y,onClick:()=>w("approve","conversation"),children:"Auto: this conversation"}),t.jsx(E,{size:"sm",disabled:y,onClick:()=>w("approve","always"),children:"Always: this agent"})]}):null,t.jsx(E,{variant:"good",size:"sm",disabled:y,onClick:()=>w("approve"),children:m==="approve"?"Approving…":((I=c==null?void 0:c.answers)==null?void 0:I.approve)??(b?"Allow once":"Approve")})]})]})}function C9(e){for(const n of[e.canonicalArgs,e.envelope])if(!(n===null||typeof n!="object"||Array.isArray(n)))for(const s of N9){const r=n[s];if(typeof r=="string"&&r.trim()!=="")return r.trim()}return null}function E9(e){const n=(e??"").split(`
111
+ `).map(s=>s.trim()).find(Boolean);return n?n.length>160?`${n.slice(0,157)}…`:n:null}const A9=2e3;function $9({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:f}=me(()=>Qe.conversation(e),[e,o,(a==null?void 0:a.approvalId)??null],u?A9:void 0),m=(h==null?void 0:h.runs)??[],p=s===null?null:m.find(N=>N.runId===s)??null,v=l||a===null&&(s!==null?p!==null&&p.finishedAt!==null:m.length>0&&m.every(N=>N.finishedAt!==null));d.useEffect(()=>{v&&c(!0)},[v]);const g=r?r.ok?"done":"failed":a!=null&&a.approvalId?"waiting":v?"done":"working",k=i.find(N=>N.id===n)??null,j=(k==null?void 0:k.name)??(h==null?void 0:h.agentId)??n,x=(h==null?void 0:h.messages)??[],w=(r==null?void 0:r.text)??T9(x);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(an,{agents:i,id:n}),t.jsxs("div",{className:"wb-delegate-who",children:[t.jsx("strong",{children:j}),t.jsx("span",{className:"wb-delegate-status","data-status":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"})]})]}),f?t.jsx("p",{className:"muted",children:f}):null,t.jsx("div",{className:"wb-delegate-work",children:x.map((N,y)=>t.jsx("div",{className:"wb-delegate-turn",children:(N.blocks??[]).map((b,S)=>{if(b.type==="thinking")return b.text.trim()===""?null:t.jsx(Kv,{text:b.text},S);if(b.type==="tool_use"){const C=R9(I9(x,b.id));return t.jsx(Vv,{label:el(b.name),tool:b.name,ok:C.ok,running:C.running,waiting:C.waiting,status:C.status,gist:Xy(b.name,b.input),opens:!1,onOpen:()=>{}},S)}return null})},N.id??y))}),w?t.jsx("div",{className:"wb-delegate-answer","data-testid":"delegate-answer",children:t.jsx(wr,{text:w})}):g==="working"||g==="waiting"?t.jsxs("p",{className:"muted",children:[j," has not answered yet."]}):null,r!=null&&r.files&&r.files.length>0?t.jsx("div",{className:"wb-msg-files",role:"list","aria-label":`Files ${j} made`,"data-testid":"delegate-files",children:r.files.map(N=>t.jsx("a",{role:"listitem",href:ai(N.artifactId),download:!0,children:t.jsx(ed,{name:N.filename??"Untitled file",mime:N.mime,sizeBytes:N.sizeBytes,thumbnail:Wy(N.mime)?yr(N.artifactId):null})},N.artifactId))}):null,t.jsxs("div",{className:"wb-delegate-actions",children:[g==="waiting"?t.jsx(E,{variant:"accent",onClick:()=>k9(),"data-testid":"delegate-to-approval",children:"Go to the approval"}):null,t.jsx("a",{className:"ui-btn",href:lt(n||(h==null?void 0:h.agentId)||"",e),children:"Open this conversation"})]})]})}function T9(e){for(let n=e.length-1;n>=0;n-=1){const s=e[n];if(s.role!=="assistant")continue;const r=(s.blocks??[]).filter(a=>a.type==="text").map(a=>a.text.trim()).filter(a=>a!=="").join(`
112
+
113
+ `);if(r!=="")return r}return null}function I9(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 R9(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 zS=1024*1024;function P9({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(M9,{files:e,agentId:n,root:s,path:a.path,revision:r,go:i}):t.jsx(O9,{files:e,agentId:n,root:s,path:a.path,revision:r,go:i})})}function JR({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 M9({files:e,agentId:n,root:s,path:r,revision:a,go:i}){const[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(!1),[m,p]=d.useState(null);d.useEffect(()=>{let k=!1;return u(null),T.pageQuery(e.plugin,e.list,{agent:n,...r?{path:r}:{}}).then(j=>{k||o(j.data)}).catch(j=>{k||u(j instanceof Error?j.message:String(j))}),()=>{k=!0}},[e.plugin,e.list,n,r,a]),d.useEffect(()=>p(null),[r]);const v=async()=>{f(!0),p(null);try{const k=await fetch(T.pageFileUrl(e.plugin,e.archive,{agent:n,...r?{path:r}:{}}),{credentials:"same-origin"});if(!k.ok){const N=await k.json().catch(()=>null);p((N==null?void 0:N.error)??"The archive could not be made.");return}const j=await k.blob(),x=URL.createObjectURL(j),w=document.createElement("a");w.href=x,w.download=`${r===""?s:r.split("/").at(-1)}.zip`,w.click(),window.setTimeout(()=>URL.revokeObjectURL(x),1e4)}catch{p("The archive could not be made.")}finally{f(!1)}},g=l&&l.path===r?l.entries:null;return t.jsxs(t.Fragment,{children:[t.jsxs(re,{children:[t.jsx(JR,{root:s,path:r,go:i}),t.jsx(pt,{}),t.jsx(E,{size:"sm",onClick:()=>void v(),disabled:h||g===null||g.length===0,children:h?"Packing…":"Download as archive"})]}),m?t.jsx(Q,{tone:"warning",role:"alert",children:m}):null,c?t.jsx(Q,{tone:"critical",role:"alert",children:c}):null,g===null?c?null:t.jsx(be,{children:"Reading the folder…"}):g.length===0?t.jsx(be,{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:ba,children:"Files library"})," and mention it here."]}):"This folder is empty."}):t.jsx(dt,{children:g.map(k=>t.jsx(ot,{href:"#",onClick:()=>i({kind:k.kind,path:k.path}),lead:t.jsx(L9,{kind:k.kind}),title:t.jsxs("span",{className:"mono",children:[k.name,k.kind==="dir"?"/":""]}),side:k.kind==="file"?_n(k.bytes):void 0},k.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 O9({files:e,agentId:n,root:s,path:r,revision:a,go:i}){const[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(!1);d.useEffect(()=>{let j=!1;return u(null),T.pageQuery(e.plugin,e.stat,{agent:n,path:r}).then(x=>{j||o(x.data)}).catch(x=>{j||u(x instanceof Error?x.message:String(x))}),()=>{j=!0}},[e.plugin,e.stat,n,r,a]);const m=l&&l.path===r?l:null,p=m?`${m.bytes}-${Math.round(m.mtimeMs)}`:"",v=m?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"}),k=(m==null?void 0:m.type)==="text"&&m.bytes<=zS;return t.jsxs(t.Fragment,{children:[t.jsxs(re,{children:[t.jsx(JR,{root:s,path:r,go:i}),t.jsx(pt,{}),k?t.jsx(E,{size:"sm","aria-pressed":h,onClick:()=>f(j=>!j),children:"Wrap"}):null,t.jsx(nt,{size:"sm",href:g,download:(m==null?void 0:m.name)??r.split("/").at(-1),children:"Download"})]}),c?t.jsx(Q,{tone:"critical",role:"alert",children:c}):null,m===null?c?null:t.jsx(be,{children:"Reading the file…"}):m.type==="image"?t.jsx("figure",{className:"wb-files-picture",children:t.jsx("img",{src:v,alt:m.name})}):m.type==="pdf"?t.jsx("div",{className:"file-preview file-preview-pdf",children:t.jsx("object",{data:v,type:"application/pdf","aria-label":m.name,children:t.jsx(Q,{children:"Your browser cannot show this PDF here. Download it to open it."})})}):k?t.jsx(D9,{src:v,wrap:h}):t.jsxs(t.Fragment,{children:[t.jsx(Q,{children:m.type==="text"?`This file is over ${_n(zS)}, 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(Vt,{items:[{label:"Size",value:_n(m.bytes)},{label:"Type",value:t.jsx("span",{className:"mono",children:m.mime})}]})]})]})}function D9({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(be,{children:"Reading the file…"}):s===""?t.jsx(be,{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 L9({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 F9({input:e,output:n,ok:s}){const r=_H(e),a=$R(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(Se,{tone:zH(a,s),dot:!0,children:a})})]}),t.jsxs("div",{className:"envelope-body",children:[t.jsx("strong",{children:r.title}),r.text?`
114
+
115
+ ${r.text}`:null]})]}),t.jsx(Gt,{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 bc=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)?e:{},en=e=>typeof e=="string"&&e.trim()!==""?e:null,_9={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 z9(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 hg(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function U9(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 US(e){var n;return((n=e.match(/[\p{L}\p{N}]/u))==null?void 0:n[0])??"?"}function XR(e){const n=bc(e.input),s=bc(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=en(e.error)??en(bc(e.error).message);if(Array.isArray(s.results)||en(n.query)&&!en(n.url)){const f=(Array.isArray(s.results)?s.results:[]).map(p=>bc(p)).flatMap(p=>{const v=en(p.url);return v?[{title:en(p.title)??hg(v),url:v,host:en(p.source)??hg(v),snippet:en(p.snippet)}]:[]}),m=s.available===!1;return{kind:"search",id:e.id,raw:r,query:en(s.query)??en(n.query)??"",state:e.ok===null?"pending":a||m?"failed":"ok",provider:en(s.provider),results:f,why:a?`The search failed${i?`: ${i}`:"."}`:m?en(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=en(s.url)??en(n.url)??"",o=!a&&s.ok!==!1&&z9(en(s.text)??""),c=a||s.ok===!1||o,u=o?"unreadable":en(s.problem),h=en(s.message);return{kind:"page",id:e.id,url:l,raw:r,host:en(s.source)??hg(l),state:e.ok===null?"pending":c?"failed":"ok",title:en(s.title),text:o?null:en(s.text),truncated:s.truncated===!0,retrievedAt:en(s.retrievedAt)??e.at,why:c?(u&&_9[u])??(h?h.charAt(0).toUpperCase()+h.slice(1)+(/[.!?]$/.test(h)?"":"."):null)??`The read failed${i?`: ${i}`:"."}`:null}}function B9(e){const n=e.entries.map(XR),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 W9(e){return e.split(/\s+/).filter(Boolean).length}function H9(e){return e>=1e3?`${(e/1e3).toFixed(1).replace(/\.0$/,"")}k words`:`${e} ${e===1?"word":"words"}`}function K9(e,n){if(!e)return null;const s=new Date(e);return Number.isNaN(s.getTime())?null:Tt(s,n??Intl.DateTimeFormat().resolvedOptions().timeZone)}function ZR({url:e,className:n,children:s}){const r=U9(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 eP({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 V9({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 m,p;n&&(a(!0),(p=(m=o.current)==null?void 0:m.scrollIntoView)==null||p.call(m,{block:"nearest"}))},[n]),e.state==="pending")return t.jsx("li",{className:"wb-src-page","data-state":"pending",ref:o,children:t.jsxs("div",{className:"wb-src-row",children:[t.jsx("span",{className:"wb-src-tile","data-state":"pending","aria-hidden":"true",children:US(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?W9(e.text):0,h=K9(e.retrievedAt,s),f=[e.host,h?`read ${h}`:null,u?H9(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?"!":US(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(ZR,{url:e.url,className:"wb-src-title",children:e.title??e.host}),c?t.jsx("span",{className:"wb-src-why",children:e.why}):t.jsx("span",{className:"wb-src-meta",children:f})]}),t.jsx("button",{type:"button",className:"wb-src-toggle","aria-expanded":r,"aria-label":r?`Hide what was read from ${e.host}`:`Show what was read from ${e.host}`,onClick:()=>a(!r),children:t.jsx(ie,{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(eP,{value:e.raw})]})]}):null]})}const BS=3;function G9({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,BS),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(eP,{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(ZR,{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(Se,{tone:"good",children:"Read"})}):null]},c.url))}):null,e.results.length>BS?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 Y9({entries:e,focus:n,timezone:s}){const r=e.map(XR),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=en(bc(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(V9,{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(G9,{search:o,read:l,focused:n===o.id},o.id))]}):null]})}const q9=3,Q9=152,J9=104,X9=100,Z9=2,fg=RR;function eV({renderables:e,activeId:n,onActivate:s,timezone:r,onDecided:a,onChangeAgent:i,face:l,cardFace:o,descriptors:c,grantedTools:u,agentName:h,maxTabs:f,browserPanel:m,browserMenu:p,agents:v,onClose:g,onCloseMany:k,touched:j,turnStartedAt:x,now:w=Date.now,loading:N=!1}){var R;const[y,b]=tV(f),[S,C]=d.useState({}),A=d.useMemo(()=>sV(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:y,"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:lV(h,oV(c??[],u??[]))})]})})]});const $=e.some(D=>D.id===n)?n:e[e.length-1].id,{shown:I,hidden:P}=mK(e,$,b,j),O=e.filter(mg).map(D=>D.id);return t.jsx("div",{className:"wb-canvas","data-testid":"canvas",children:t.jsxs(V6,{value:$,onValueChange:s,className:"contents",children:[t.jsxs("div",{className:"wb-canvas-tabs",ref:y,children:[t.jsx("span",{className:"wb-canvas-label","aria-hidden":"true",children:"Canvas"}),t.jsx(G6,{className:"wb-tabstrip","aria-label":"Canvas",children:I.map(D=>t.jsxs("div",{className:"wb-tab-item",children:[t.jsxs(Y6,{value:D.id,className:"wb-tab","data-tone":D.tone,onKeyDown:U=>{U.key==="Delete"&&g&&mg(D)&&(U.preventDefault(),g(D.id))},children:[D.tone==="warning"||D.tone==="critical"?t.jsx("span",{className:"wb-tab-dot","data-tone":D.tone,"aria-hidden":"true"}):null,t.jsx("span",{className:"wb-tab-text",children:A.get(D.id)??D.title}),D.count?t.jsx("span",{className:"wb-tab-count",children:D.count}):null]}),g&&mg(D)?t.jsx("button",{className:"wb-tab-close","aria-label":`Close ${A.get(D.id)??D.title} tab`,title:"Dismiss panel; keep conversation history",onClick:()=>g(D.id),children:"×"}):null]},D.id))}),t.jsx(aV,{items:P,onActivate:s,timezone:r,labels:A,groups:pK(P,{now:w(),turnStartedAt:x??null,...j?{touched:j}:{}}),...k?{onCloseAll:O.length>0?()=>k(O):void 0,onCloseOthers:O.some(D=>D!==$)?()=>k(O.filter(D=>D!==$)):void 0}:{}}),p&&((R=e.find(D=>D.id===$))==null?void 0:R.source)==="browser"?t.jsx("span",{className:"wb-canvas-menu",children:p}):null]}),e.map(D=>{const U=D.versions??[],W=S[`${D.id}:${U.length}:${D.focus??""}`]??(D.focus&&U.some(_=>_.id===D.focus)?D.focus:null),M=W?U.find(_=>_.id===W)??null:null,L=M?nV(D,M):D;return t.jsxs(q6,{value:D.id,className:"wb-canvas-body","data-renderer":L.source==="descriptor"&&L.renderer==="preview"?"preview":void 0,"data-dense":uV.has(L.renderer)?"true":void 0,"data-page":L.source==="browser"?"true":void 0,children:[U.length>1?t.jsx(rV,{versions:U,current:L.id===D.id&&!M?U.at(-1).id:(M==null?void 0:M.id)??U.at(-1).id,timezone:r,onPick:_=>C(Y=>({...Y,[`${D.id}:${U.length}:${D.focus??""}`]:_}))}):null,L.source==="browser"?m:t.jsxs("section",{className:"ui-panel","data-flush":L.source==="descriptor"&&L.renderer==="preview"?"true":void 0,children:[L.source!=="files"&&!WS(L)&&!(L.source==="descriptor"&&L.renderer==="preview")?t.jsxs("header",{className:"ui-panel-head",children:[t.jsx("h2",{className:"ui-panel-title",children:L.title}),t.jsx("span",{className:"ui-panel-tool mono",children:L.source==="sources"?B9(L.props):L.tool})]}):null,L.tone==="critical"?t.jsxs("p",{className:"muted",children:["Recorded tool failure",L.at?` · ${mt(L.at,Intl.DateTimeFormat().resolvedOptions().timeZone)}`:"",". This is history, not live session status."]}):null,WS(L)?t.jsx(eH,{value:L.props.value,title:L.title,tool:L.tool,face:o,timezone:r}):L.source==="profile"?t.jsx(cH,{...L.props,...i?{onChange:i}:{}}):L.source==="artifact"?t.jsx(OH,{...L.props}):L.source==="files"?t.jsx(P9,{...L.props}):L.source==="sources"?t.jsx(Y9,{...L.props,timezone:r}):L.source==="notify"?t.jsx(F9,{...L.props}):L.source==="delegate"?t.jsx($9,{...L.props,agents:v??[]}):t.jsx(FW,{renderer:L.renderer,props:L.props,timezone:r,onDecided:a})]})]},D.id)})]})})}function WS(e){var n;return e.renderer==="structured"&&(e.source==="fallback"||e.source==="descriptor")&&!((n=e.props)!=null&&n.failed)}function mg(e){return e.source==="approval"?!1:e.source==="browser"?e.pinned!==!0:e.source!=="files"}function tV(e){const[n,s]=d.useState(fg),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-X9-J9)/Q9);s(Math.max(Z9,Math.min(fg,u)))};l(),r.current=new ResizeObserver(l),r.current.observe(i)},[e]),e===void 0?n:Math.min(fg,e)]}function nV(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 sV(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:ob(a.at,n);r.set(a.id,i?`${a.title} · ${i}`:a.title)}return r}function rV({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=ob(i.at,s);return t.jsxs("div",{className:"wb-versions",role:"group","aria-label":"Earlier results",children:[t.jsx(E,{variant:"ghost",size:"sm","aria-label":"Earlier result",disabled:a===0,onClick:()=>r(e[a-1].id),children:t.jsx(ie,{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(E,{variant:"ghost",size:"sm","aria-label":"Later result",disabled:l,onClick:()=>r(e[a+1].id),children:t.jsx(ie,{name:"chevron-right"})})]})}function aV({items:e,groups:n,labels:s,onActivate:r,onCloseAll:a,onCloseOthers:i,timezone:l}){if(e.length===0&&!a&&!i)return null;const o=e.some(c=>c.tone==="critical")?"critical":e.some(c=>c.tone==="warning")?"warning":null;return t.jsxs(Ku,{modal:!1,children:[t.jsx(Vu,{asChild:!0,children:t.jsxs("button",{className:"wb-tab wb-tab-more","data-tone":o??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:[o?t.jsx("span",{className:"wb-tab-dot","data-tone":o,"aria-hidden":"true"}):null,e.length>0?t.jsxs("span",{className:"wb-tab-text",children:[e.length," more"]}):null,t.jsx(ie,{name:"chevron-down"})]})}),t.jsx(Oo,{children:t.jsxs(Gu,{className:"ui-menu","data-wide":"true",align:"end",sideOffset:6,children:[n.length>0?t.jsx("div",{className:"wb-tab-timeline",children:n.map(c=>t.jsxs(jy,{children:[t.jsx(Ji,{className:"ui-menu-label",children:c.label}),c.items.map(u=>{var h,f;return t.jsxs(ms,{className:"ui-menu-item",onSelect:()=>r(u.id),children:[t.jsxs("span",{className:"ui-menu-item-text",children:[u.tone==="warning"||u.tone==="critical"?t.jsx("span",{className:"wb-tab-dot","data-tone":u.tone,"aria-hidden":"true"}):null,s.get(u.id)??u.title]}),t.jsx("span",{className:"ui-menu-note mono",children:ob(((f=(h=u.versions)==null?void 0:h.at(-1))==null?void 0:f.at)??u.at,l)??u.tool})]},u.id)})]},c.label))}):null,a||i?t.jsxs(t.Fragment,{children:[n.length>0?t.jsx(_r,{className:"ui-menu-sep"}):null,t.jsx(ms,{className:"ui-menu-item",disabled:!i,onSelect:()=>i==null?void 0:i(),children:t.jsx("span",{className:"ui-menu-item-text",children:"Close others"})}),t.jsx(ms,{className:"ui-menu-item",disabled:!a,onSelect:()=>a==null?void 0:a(),children:t.jsx("span",{className:"ui-menu-item-text",children:"Close all"})})]}):null]})})]})}function ob(e,n){if(!e)return null;const s=new Date(e);return Number.isNaN(s.getTime())?null:Tt(s,n)}const iV={timeseries:"charts",table:"tables",bars:"comparisons",keyvalue:"figures",tiles:"cards",document:"pages it read",diff:"diffs",terminal:"command output",image:"pictures",preview:"running apps",envelope:"drafts",structured:"results"};function lV(e,n){const s=e?`What ${e} shows you`:"What your agent shows you",r=[...new Set(n.map(a=>iV[a.renderer]??"results"))].slice(0,3);return r.length>0?`${s} lands here: ${r.join(", ")}.`:`${s} lands here.`}function oV(e,n){const s=new Set(n),r=new Set,a=e.filter(c=>{if(!s.has(c.tool))return!1;const u=cV(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,q9)}function cV(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 uV=new Set(["table","diff","files"]),Da=320,dV=280,HS=24,hV=12,fV=[1/3,1/2,2/3],Yv="buddi.chatWidth";function wf(e){return{min:Da,max:Math.max(Da,Math.round(e)-dV)}}function mV(e,n,s){return Math.max(0,Math.round(e+n-Math.max(0,s)))}function pV(e,n){return yf(e,n)}function yf(e,n){const{min:s,max:r}=wf(n);return Number.isFinite(e)?n<=0?Math.max(s,Math.round(e)):Math.min(r,Math.max(s,Math.round(e))):s}function gV(e,n){if(n<=0)return e;for(const s of fV){const r=Math.round(n*s);if(Math.abs(e-r)<=hV)return r}return e}function xV(e,n){return yf(gV(e,n),n)}function vV(e,n,s){const{min:r,max:a}=wf(s);switch(n){case"ArrowLeft":return yf(e-HS,s);case"ArrowRight":return yf(e+HS,s);case"Home":return r;case"End":return s>0?a:null;default:return null}}function jV(){try{const e=window.localStorage.getItem(Yv);if(e===null)return null;const n=Number(e);return Number.isFinite(n)&&n>=Da?Math.round(n):null}catch{return null}}function wV(e){try{e===null?window.localStorage.removeItem(Yv):window.localStorage.setItem(Yv,String(Math.round(e)))}catch{}}const qv="--wb-chat-w";function yV({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??Da,max:Da}),h=()=>{var y;const g=e.current,k=(y=a.current)==null?void 0:y.nextElementSibling,j=(g==null?void 0:g.getBoundingClientRect().width)||(g==null?void 0:g.offsetWidth)||n||Da,x=g==null?void 0:g.parentElement,w=x?x.scrollWidth-x.clientWidth:0;return{shared:mV((g==null?void 0:g.getBoundingClientRect().width)??0,(k==null?void 0:k.getBoundingClientRect().width)??0,w),current:j,left:(g==null?void 0:g.getBoundingClientRect().left)??0}},f=g=>{const{shared:k,current:j}=h();u({now:Math.round(g??j),max:wf(k).max})};d.useEffect(()=>{f(n??void 0)},[n]);const m=g=>{const k=e.current;k&&(g===null?(k.style.removeProperty(qv),delete k.dataset.sized):(k.style.setProperty(qv,`${g}px`),k.dataset.sized="true"))},p=g=>{m(g),wV(g),s(g)},v=()=>{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 x;if(n===null)return;const g=(x=e.current)==null?void 0:x.parentElement;if(!g)return;const k=()=>{if(i.current)return;const{shared:w}=h();if(w<=0)return;const N=pV(n,w);m(N),u({now:N,max:wf(w).max})};k();const j=typeof ResizeObserver>"u"?null:new ResizeObserver(k);return j==null||j.observe(g),window.addEventListener("resize",k),()=>{j==null||j.disconnect(),window.removeEventListener("resize",k)}},[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":Da,"aria-valuemax":Math.max(Da,c.max),"aria-valuenow":c.now,title:"Drag to resize · double-click to reset","data-dragging":l?"true":void 0,onPointerDown:g=>{var x,w;if(g.pointerType==="mouse"&&g.button!==0)return;g.preventDefault(),(w=(x=g.currentTarget).setPointerCapture)==null||w.call(x,g.pointerId);const{shared:k,left:j}=h();i.current={pointerId:g.pointerId,left:j,shared:k,next:null,frame:null},o(!0),document.documentElement.setAttribute("data-resizing","true")},onPointerMove:g=>{const k=i.current;!k||k.pointerId!==g.pointerId||(k.next=xV(g.clientX-k.left,k.shared),k.frame===null&&(k.frame=requestAnimationFrame(()=>{const j=i.current;j&&(j.frame=null,j.next!==null&&m(j.next))})))},onPointerUp:v,onPointerCancel:v,onLostPointerCapture:v,onDoubleClick:()=>{p(null),f()},onKeyDown:g=>{const{shared:k,current:j}=h(),x=vV(n??j,g.key,k);x!==null&&(g.preventDefault(),p(x))}})}const bV=3.5*6e4,kV=2e3;function NV(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??kV,c=e.map(u=>`${Zl(u)}@${u.at??""}`).join("|");return d.useEffect(()=>{const u=new Map;for(const p of e){const v=Zl(p);if(i.current.has(v))continue;const g=p.at===null?Number.NaN:Date.parse(p.at),k=Number.isNaN(g)?0:g+bV,j=u.get(v);(!j||k>j.until)&&u.set(v,{plugin:p.plugin,name:p.name,until:k})}if(u.size===0)return;let h=!1,f;const m=async()=>{const p=Date.now();for(const[v,g]of[...u]){const k=await l(g.plugin,g.name).catch(()=>null);if(h)return;const j=p<=g.until;k!=null&&k.ok?(u.delete(v),a(x=>{const w={served:new Set(x.served).add(v),live:j?new Set(x.live).add(v):x.live,scope:x.scope};return i.current=w.served,w})):j||u.delete(v)}!h&&u.size>0&&(f=setTimeout(()=>void m(),o))};return m(),()=>{h=!0,f!==void 0&&clearTimeout(f)}},[c,n,l,o]),r}const Qv="workspace-files";function SV(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 CV(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 EV(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 AV(e){return{id:Jv(e.id),tool:`@${e.handle}`,title:"Properties",renderer:"profile",props:{profile:e},at:null,source:"profile",substantial:!1}}function $V(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,f)=>Math.max(0,Math.min(Math.round(h),Math.round(f)));return{x:u(o,n.deviceWidth),y:u(c,n.deviceHeight)}}function pg(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}function KS(e){return[...e].length===1&&e.codePointAt(0)>=32&&e.codePointAt(0)!==127}const TV=4e3;function IV(e){return e.replace(/\r\n?/g,`
116
+ `).replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g,"").slice(0,TV)}const RV=["left","middle","right"],PV=33;function MV(e,n){return e.deviceWidth===n.deviceWidth&&e.deviceHeight===n.deviceHeight&&e.pageScaleFactor===n.pageScaleFactor&&e.offsetTop===n.offsetTop&&e.url===n.url}function OV(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 DV(e=window.location){return`${e.protocol==="https:"?"wss":"ws"}://${e.host}/api/browser/hand`}const LV=d.forwardRef(function({sessionId:n,csrf:s,onGiveBack:r,connect:a,bare:i=!1,typing:l,onTyping:o,onLocation:c,onLoginSeen:u},h){const[f,m]=d.useState("connecting"),[p,v]=d.useState(null),[g,k]=d.useState(!1),[j,x]=d.useState(null),[w,N]=d.useState(!1),y=l??w,b=X=>{o?o(X):N(X)},[S,C]=d.useState(0),A=d.useRef(null),$=d.useRef(u);$.current=u;const I=d.useRef(null),P=d.useRef(null),O=d.useRef({at:0});d.useEffect(()=>{var X,K,J,q;l!==void 0&&(l?(K=(X=P.current)==null?void 0:X.focus)==null||K.call(X):(q=(J=P.current)==null?void 0:J.blur)==null||q.call(J))},[l]),d.useEffect(()=>{const X=a??(q=>new WebSocket(q));let K=!0,J;try{J=X(DV())}catch{m("lost");return}return J.binaryType="arraybuffer",A.current=J,J.onopen=()=>J.send(JSON.stringify({type:"hello",csrf:s,sessionId:n})),J.onmessage=q=>{var xe;if(!K)return;if(typeof q.data!="string"){const Me=OV(q.data);if(!Me||(x(H=>H&&MV(H,Me.metadata)?H:Me.metadata),k(!0),typeof createImageBitmap!="function"))return;createImageBitmap(Me.jpeg).then(H=>{var Z,ye,Ce;const ne=I.current;if(!K||!ne){(Z=H.close)==null||Z.call(H);return}(ne.width!==H.width||ne.height!==H.height)&&(ne.width=H.width,ne.height=H.height),(ye=ne.getContext("2d"))==null||ye.drawImage(H,0,0),(Ce=H.close)==null||Ce.call(H)}).catch(()=>{});return}const ce=JSON.parse(q.data);if(ce.type==="driving"){m("driving"),v(null);return}if(ce.type==="loginSeen"){typeof ce.id=="string"&&typeof ce.site=="string"&&typeof ce.username=="string"&&((xe=$.current)==null||xe.call($,{id:ce.id,site:ce.site,username:ce.username,...ce.update===!0?{update:!0}:{}}));return}(ce.type==="refused"||ce.type==="ended")&&(v(ce.error??"The screen cannot be driven from here."),m("refused"))},J.onclose=()=>{K&&m(q=>q==="refused"?q:"lost")},J.onerror=()=>{K&&m(q=>q==="refused"?q:"lost")},()=>{K=!1,A.current=null;try{J.close()}catch{}}},[n,s,S,a]),d.useEffect(()=>()=>{clearTimeout(O.current.timer)},[]);const R=j==null?void 0:j.url;d.useEffect(()=>{R&&(c==null||c(R))},[R]);const D=d.useCallback(X=>{const K=A.current;if(K)try{K.send(JSON.stringify({type:"input",input:X}))}catch{}},[]);d.useImperativeHandle(h,()=>({nav:(X,K)=>A.current?(D({kind:"nav",action:X,...X==="navigate"&&K?{url:K}:{}}),!0):!1}),[D]);const U=X=>{var q;const K=I.current;if(!K||!j)return null;const J=(q=K.getBoundingClientRect)==null?void 0:q.call(K);return J?$V(J,j,X.clientX,X.clientY):null},W=X=>{const K=O.current,J=Date.now();clearTimeout(K.timer),K.timer=void 0;const q=K.at+PV-J;if(q<=0){K.at=J,K.pending=void 0,D(X);return}K.pending=X,K.timer=setTimeout(()=>{const ce=O.current.pending;O.current.timer=void 0,O.current.pending=void 0,O.current.at=Date.now(),ce&&D(ce)},q)},M=()=>{const X=O.current;clearTimeout(X.timer),X.timer=void 0;const K=X.pending;X.pending=void 0,K&&(X.at=Date.now(),D(K))},L=X=>K=>{var ce,xe;const J=U(K);if(!J)return;X==="mousePressed"&&(K.preventDefault(),(xe=(ce=I.current)==null?void 0:ce.focus)==null||xe.call(ce));const q={kind:"mouse",type:X,x:J.x,y:J.y,button:RV[K.button]??"left",clickCount:X==="mouseMoved"?0:Math.min(3,Math.max(1,K.detail||1)),modifiers:pg(K)};if(X==="mouseMoved"){W(q);return}M(),D(q)},_=X=>{const K=U(X);K&&(M(),D({kind:"wheel",x:K.x,y:K.y,deltaX:Math.round(X.deltaX),deltaY:Math.round(X.deltaY)}))},Y=X=>X.ctrlKey||X.metaKey||X.altKey,B=X=>{var J,q;if(X.key==="Escape"&&Y(X)){b(!1),(q=(J=X.target).blur)==null||q.call(J);return}if(X.preventDefault(),(X.metaKey||X.ctrlKey)&&(X.key==="v"||X.key==="V"))return;const K=pg(X);if(KS(X.key)&&!Y(X)){D({kind:"key",type:"char",key:X.key,code:X.code,text:X.key,modifiers:K});return}D({kind:"key",type:"keyDown",key:X.key,code:X.code,modifiers:K})},se=X=>{X.key==="Escape"&&Y(X)||(X.preventDefault(),!((X.metaKey||X.ctrlKey)&&(X.key==="v"||X.key==="V"))&&(KS(X.key)&&!Y(X)||D({kind:"key",type:"keyUp",key:X.key,code:X.code,modifiers:pg(X)})))},G=X=>{var J;X.preventDefault();const K=IV(((J=X.clipboardData)==null?void 0:J.getData("text/plain"))??"");K!==""&&D({kind:"text",text:K})};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(re,{align:"end",children:[t.jsx(E,{size:"sm",variant:y?"accent":"ghost","aria-pressed":y,onClick:()=>{var K,J,q,ce;const X=!y;b(X),X?(J=(K=P.current)==null?void 0:K.focus)==null||J.call(K):(ce=(q=P.current)==null?void 0:q.blur)==null||ce.call(q)},children:"Keyboard"}),t.jsx(E,{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(re,{align:"end",children:t.jsx(E,{size:"sm",variant:"accent",onClick:()=>{m("connecting"),C(X=>X+1)},children:"Reconnect"})})]}):null,f==="refused"&&p?t.jsx(Q,{tone:"warning",role:"status",children:p}):null,t.jsx("div",{className:"hand-screen",children:g?t.jsx("canvas",{ref:I,className:"hand-picture",role:"img","aria-label":"The host browser, live","data-testid":"hand-picture",tabIndex:0,onMouseDown:L("mousePressed"),onMouseUp:L("mouseReleased"),onMouseMove:L("mouseMoved"),onWheel:_,onKeyDown:B,onKeyUp:se,onPaste:G,onContextMenu:X=>X.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:P,className:"hand-typing","aria-label":"Type into the host browser",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,value:"",onChange:()=>{},onKeyDown:B,onKeyUp:se,onPaste:G,onBlur:()=>b(!1)})]})});function FV(e){return e==="darwin"?"this Mac":"this computer"}let gg=null;function Bm(){const[e,n]=d.useState(void 0);return d.useEffect(()=>{let s=!0;return gg??(gg=T.session().then(r=>r.platform,()=>{gg=null})),gg.then(r=>{s&&n(r)}),()=>{s=!1}},[]),FV(e)}const _V="sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0";function zV({timezone:e,navigate:n}={}){var u;const{data:s,error:r,reload:a}=me(()=>T.browser(),[],3e3),i=me(()=>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(ae,{message:r}),!s||!o?t.jsx(be,{children:"Checking where agents may look…"}):t.jsx(VV,{data:s,macOS:l,reload:a,timezone:e,go:c})]})}function cb({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 ur({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 UV({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(E,{size:"sm",variant:"ghost",onClick:()=>{var r;(r=navigator.clipboard)==null||r.writeText(e).then(()=>s(!0),()=>{})},children:n?"Copied":"Copy"})]})}function Bd({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 Wm(e){const n=e.split(".").filter(Boolean).at(-1)??e;return n.charAt(0).toUpperCase()+n.slice(1)}function BV(e){return e.length<=2?e.join(" and "):`${e.slice(0,2).join(", ")} and ${e.length-2} more`}const WV=[{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 Xv({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:WV.filter(i=>s||i.value!=="apps"||e==="apps").map(i=>t.jsx("option",{value:i.value,children:i.label},i.value))})}function HV(e){return(e==null?void 0:e.installed)===!0}function KV(e,n){return e?e.pending?"pair":e.pairedAt?e.connected?"connected":n&&n.state!=="paired"&&rP(n.gateway)?"broken":"notrunning":n&&n.state!=="paired"?"pair":"none":"none"}function VV({data:e,macOS:n,reload:s,timezone:r,go:a}){var j,x;const[i,l]=d.useState(!1),[o,c]=d.useState(null),u=async w=>{l(!0),c(null);try{await w()}catch(N){c(N instanceof Error?N.message:String(N))}finally{l(!1),s()}},h=e.settings,f=w=>void u(()=>T.browserSettings(w)),m=r??Intl.DateTimeFormat().resolvedOptions().timeZone,p=e.learnedSignInSites??[],v=(j=e.routes)==null?void 0:j.find(w=>w.kind==="apps"),g=HV(v),k=(x=e.sessions)!=null&&x.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(ae,{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(E,{size:"sm",variant:"accent",disabled:i,onClick:()=>void u(()=>T.browserControl("resume")),children:"Resume"}),children:`Agents’ browsing is paused since ${Tt(new Date(e.stop.at),m)}, by you from the Canvas, ${e.stop.until?`until ${Tt(new Date(e.stop.until),m)}`:"until you resume it"}. An agent that needs a page asks you in its chat.`}):null,t.jsx(st,{title:"Browsers and apps",flush:!0,children:t.jsxs("div",{className:"ui-list",children:[t.jsx(QV,{data:e,busy:i,run:u}),h?t.jsx(JV,{settings:h,learned:p,busy:i||!e.enabled,save:f,zone:m}):null,g&&h?t.jsx(XV,{route:v,settings:h,busy:i||!e.enabled,save:f,run:u,onSettings:()=>a(vr(v.provider||"computer"))}):null]})}),t.jsx(qV,{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,k.length>0?t.jsx(st,{title:"Looking now",flush:!0,actions:t.jsx(E,{size:"sm",disabled:i,onClick:()=>void u(()=>T.browserControl("stop")),children:"Stop agents’ browsing"}),children:t.jsx("div",{className:"ui-list",children:k.map(w=>{var N;return t.jsxs("a",{className:"ui-list-row",href:lt(w.session.agentId,w.session.conversationId,"browser"),children:[t.jsx(In,{id:w.session.agentId,name:w.session.agentId,size:"sm"}),t.jsxs("span",{className:"ui-list-main",children:[t.jsx("span",{className:"ui-list-title",children:((N=w.page)==null?void 0:N.title)||w.session.task}),t.jsx("span",{className:"ui-list-sub",children:tP(w)})]}),t.jsx("span",{className:"ui-list-side",children:"Open the Canvas"})]},w.session.id)})})}):null,h?t.jsx(ZV,{settings:h,learned:p,busy:i,save:f,run:u,showApps:g}):null]})}function GV(e){return`${e.files===0?"Nothing waiting":`${e.files} ${e.files===1?"file":"files"} waiting · ${_n(e.bytes)}`} · kept ${e.retentionDays} days, at most ${_n(e.fileCap)} a file`}function YV(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 qV({busy:e,run:n}){var f;const s=me(()=>T.browserDownloads(),[],3e4),r=me(()=>T.agents(),[]),[a,i]=d.useState(!1),l=s.data,o=(l==null?void 0:l.waiting)??[],c=new Map((((f=r.data)==null?void 0:f.agents)??[]).map(m=>[m.id,m.name])),u=m=>void n(async()=>{await T.fileBrowserDownload(m),s.reload()}),h=()=>void n(async()=>{i(!1),await T.clearBrowserDownloads(),s.reload()});return t.jsxs(st,{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?GV(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(E,{size:"sm",disabled:e||!l||l.files===0,onClick:()=>i(!0),children:"Clear"})})]}),o.map(m=>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:m.name}),t.jsx("span",{className:"ui-list-sub",children:`${c.get(m.agent)??m.agent} · ${Po(m.day)} · ${_n(m.size)} · not in Files yet`})]}),t.jsx("span",{className:"ui-list-side",children:t.jsx(E,{size:"sm",variant:"accent",disabled:e,onClick:()=>u(m.id),children:"File it"})})]},m.id))]}),a&&l?t.jsx(Rt,{title:`Clear ${l.files} ${l.files===1?"download":"downloads"}?`,onClose:()=>i(!1),foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:()=>i(!1),children:l.files===1?"Keep it":"Keep them"}),t.jsx(E,{variant:"danger",disabled:e,onClick:h,children:`Clear ${l.files}`})]}),children:t.jsx("p",{children:YV(l.files)})}):null]})}function tP(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?Wm(e.page.appId):"an app"} · its own window`:`Looking at ${ub((r=e.page)==null?void 0:r.url)??"a page"} · ${e.route==="chrome"?"in your Chrome · background tab":"in buddi’s browser"}`}function ub(e){if(e)try{return new URL(e).hostname.replace(/^www\./,"")||void 0}catch{return}}function QV({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 f=(u=a.progress)==null?void 0:u.percent;l=t.jsx(ur,{line:i,status:t.jsxs("span",{className:"br-installing",children:[t.jsx("span",{className:"pl-spin","aria-hidden":"true"}),`Installing Chromium…${f!==void 0?` ${Math.round(f)}%`:""}`]})}),o=null}else(r==null?void 0:r.engine)==="none"?(l=t.jsx(ur,{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(E,{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(ur,{line:i,tone:"critical",status:"Linux blocks its sandbox (AppArmor). Run this once, then Check again:",children:t.jsx(UV,{text:_V})}),o=t.jsx(E,{size:"sm",disabled:n,onClick:()=>void s(()=>T.browserCheck()),children:"Check again"})):r!=null&&r.problem?(l=t.jsx(ur,{line:i,tone:"critical",status:r.message??"It doesn’t start on this machine."}),o=t.jsx(E,{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(Se,{tone:"good",dot:!0,children:"ready"}):null);return t.jsxs("div",{className:"ui-list-row",children:[t.jsx(cb,{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 VS=1e4;async function GS(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>=-VS&&r-i<=VS))throw s}nP()}function nP(){if(typeof window>"u")return;const e=window.location.hash,n=gB(e);if(n!==e)try{window.history.replaceState(window.history.state,"",`${window.location.pathname}${window.location.search}${n}`)}catch{}}function JV({settings:e,learned:n,busy:s,save:r,zone:a}){var _,Y,B,se,G,X,K,J,q,ce;const i=me(()=>T.extension(),[],3e3),l=me(()=>rG(),[],3e3).data??null,o=Bm(),[c,u]=d.useState(()=>PN(typeof window>"u"?"":window.location.hash)??"");d.useEffect(()=>{const xe=()=>{const Me=PN(window.location.hash);Me&&u(Me)};return window.addEventListener("hashchange",xe),()=>window.removeEventListener("hashchange",xe)},[]);const[h,f]=d.useState(!1),[m,p]=d.useState(null),[v,g]=d.useState(!1),[k,j]=d.useState(!1),x=KV(i.data,l),w=aG(),N=async xe=>{f(!0),p(null);try{await xe()}catch(Me){p(Me instanceof Error?Me.message:String(Me))}finally{f(!1),i.reload()}},y=(_=i.data)!=null&&_.pending&&(l==null?void 0:l.state)==="pairing"?l.code??"":"",b=d.useRef("");d.useEffect(()=>{!y||b.current===y||h||(b.current=y,N(async()=>{await T.pairExtension(y),nP()}))},[y]);const S=s||h,C=(Y=i.data)!=null&&Y.pairedAt?`paired ${mt(i.data.pairedAt,a)}`:null,A=(l==null?void 0:l.version)??((B=i.data)==null?void 0:B.extension),$=t.jsx(Jn,{label:"More for your Chrome",items:[C||x==="broken"||x==="notrunning"||x==="connected"?{label:"Pair again",hint:[A?`Extension ${A}`:null,C].filter(Boolean).join(" · ")||void 0,onSelect:()=>void N(()=>T.forgetExtension())}:null,(se=i.data)!=null&&se.checkout?{label:"Install unpacked…",hint:"For a developer build of the extension",onSelect:()=>j(!0)}:null,(G=i.data)!=null&&G.pairedAt?"separator":null,(X=i.data)!=null&&X.pairedAt?{label:"Forget this Chrome…",tone:"critical",onSelect:()=>g(!0)}:null]}),I=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:xe=>u(xe.target.value),onKeyDown:xe=>{xe.key==="Enter"&&c.replace(/[^0-9]/g,"").length===6&&!S&&N(async()=>{await GS(c),u("")})}}),t.jsx(E,{size:"sm",variant:"accent",disabled:S||c.replace(/[^0-9]/g,"").length!==6,onClick:()=>void N(async()=>{await GS(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"}),I]}),O=[...e.signInSites,...n],R=O.length>0?`Always for ${BV(O)}`:null;let D,U;if(x==="none")D=t.jsx(ur,{line:"For sites that need your sign-in",status:w==="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:[w==="chromium"?t.jsxs(nt,{size:"sm",variant:"accent",href:sP,target:"_blank",rel:"noopener noreferrer",children:["Add to Chrome ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):null,$]});else if(x==="pair"){const xe=l?`Extension ${l.version} found in Chrome`:"The buddi extension asks to pair";D=y?t.jsx(ur,{line:xe,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:y.replace(/^(\d{3})(\d{3})$/,"$1 · $2")})}):(K=i.data)!=null&&K.pending?t.jsx(ur,{line:xe,status:"Type the six digits the extension shows.",children:I}):t.jsx(ur,{line:xe,status:"Open the extension and press Connect: it shows a code, and this page pairs with it.",children:P}),U=$}else if(x==="broken")D=t.jsx(ur,{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(E,{size:"sm",variant:"accent",disabled:S,onClick:()=>void N(()=>T.forgetExtension()),children:"Pair again"}),$]});else{const xe=e.yourChrome?x==="notrunning"?`Used only for sites that need your sign-in · Chrome isn’t open on ${o}; agents wait or use their own browser`:"Used only for sites that need your sign-in · background tabs in a buddi group":"Off. Sites that need a sign-in use your saved logins, or ask you.";D=R&&e.yourChrome?t.jsx(ur,{line:xe,status:R}):xe,U=t.jsxs(t.Fragment,{children:[e.yourChrome?x==="notrunning"?t.jsx(Se,{children:"Chrome closed"}):t.jsx(Se,{tone:"good",dot:!0,children:"connected"}):null,t.jsx(Fo,{checked:e.yourChrome,label:"Let agents use your Chrome",disabled:S,onChange:Me=>r({yourChrome:Me})}),$]})}const W=l&&((J=i.data)!=null&&J.extensionMinimum)&&sG(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&&!rP(l.gateway)?`The extension is pointed at ${l.gateway}; set it to ${window.location.origin} in its popup.`:null,L=(q=i.data)!=null&&q.portMoved&&x!=="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 set the address to http://127.0.0.1:${i.data.portMoved.to} and press Connect.`:null;return L&&x!=="broken"&&x!=="none"&&(U=t.jsxs(t.Fragment,{children:[t.jsx(E,{size:"sm",variant:"accent",disabled:S,onClick:()=>void N(()=>T.forgetExtension()),children:"Pair again"}),$]})),t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"ui-list-row",children:[t.jsx(cb,{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:[D,W?t.jsx("span",{className:"pl-row-status","data-tone":"warning",children:W}):null,M?t.jsx("span",{className:"pl-row-status","data-tone":"warning",children:M}):null,L?t.jsx("span",{className:"pl-row-status","data-tone":"warning",children:L}):null,m??i.error?t.jsx("span",{className:"pl-row-status","data-tone":"critical",children:m??i.error}):null]})]}),t.jsx("span",{className:"ui-list-side",children:t.jsx("span",{className:"br-side",children:U})})]}),v?t.jsx("div",{className:"br-confirm",children:t.jsx(Q,{tone:"warning",action:t.jsxs(re,{align:"end",children:[t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>g(!1),children:"Cancel"}),t.jsx(E,{size:"sm",variant:"danger",disabled:S,onClick:()=>{g(!1),N(()=>T.forgetExtension())},children:"Forget"})]}),children:"Forget this Chrome? Agents stop using it until you pair it again."})}):null,k?t.jsxs(Je,{title:"Install the extension unpacked",onClose:()=>j(!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(Bt,{label:"The unpacked extension",children:((ce=i.data)==null?void 0:ce.path)??"…"})]}):null]})}function XV({route:e,settings:n,busy:s,save:r,run:a,onSettings:i}){const l=n.yourApps!=="off",o=`From the ${e.label??Wm(e.provider.replace(/^@withbuddi\/plugin-/,""))} plugin`,c=l&&!e.available&&!!e.message,u=c?t.jsx(ur,{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(cb,{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(E,{size:"sm",variant:"accent",onClick:i,children:"Allow in macOS"}):null,!c&&l?t.jsx(Se,{tone:"good",dot:!0,children:"ready"}):null,c&&e.repair==="permissions"?null:t.jsx(Fo,{checked:l,label:"Let agents use your apps",disabled:s,onChange:h=>r({yourApps:h?"on":"off"})}),t.jsxs(E,{size:"sm",variant:"ghost","aria-label":"Manage apps",onClick:i,children:["Settings",t.jsx(ie,{name:"chevron-right",size:12})]})]})})]})}function ZV({settings:e,learned:n,busy:s,save:r,run:a,showApps:i}){var b;const l=me(()=>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,f]=d.useState(!1),[m,p]=d.useState(""),[v,g]=d.useState("own"),[k,j]=d.useState(""),x=(S,C)=>void a(async()=>{await T.setAgentEngine(S,{browser:C}),l.reload()}),w=e.defaultRoute==="apps"?"auto":e.defaultRoute,N=[1,3,5].includes(e.maxOwnPages)?[1,3,5]:[1,3,5,e.maxOwnPages].sort((S,C)=>S-C),y=()=>{const S=k.trim().toLowerCase().replace(/^https?:\/\//,"").replace(/\/.*$/,"").replace(/^www\./,"");if(!S||e.signInSites.includes(S)||n.includes(S)){j("");return}r({signInSites:[...e.signInSites,S]}),j("")};return t.jsx(Gt,{boxed:!0,summary:"Advanced",children:t.jsxs("div",{className:"br-adv",children:[t.jsx(Bd,{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(Xt,{label:"First choice for every agent",value:w,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(In,{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(Xv,{value:S.browser??"auto",label:`Where ${S.name} may look`,apps:i,disabled:s,onChange:C=>x(S.id,C)}),t.jsx(E,{size:"sm",variant:"ghost",disabled:s,onClick:()=>x(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(re,{children:[t.jsxs("select",{className:"br-select","aria-label":"Agent",value:m,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(Xv,{value:v,label:"Its rule",apps:i,onChange:g}),t.jsx(pt,{}),t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>f(!1),children:"Cancel"}),t.jsx(E,{size:"sm",variant:"accent","aria-label":"Add this rule",disabled:s||!m||v==="auto",onClick:()=>{x(m,v),f(!1),p("")},children:"Add"})]}):t.jsx(re,{children:t.jsxs(E,{size:"sm",disabled:u.length===0,onClick:()=>f(!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(),y()},children:[t.jsx("input",{"aria-label":"A site that needs your sign-in",placeholder:"amazon.com",value:k,onChange:S=>j(S.target.value)}),t.jsx(E,{size:"sm",type:"submit",disabled:s||!k.trim(),children:"Add"})]})]}),t.jsx(Bd,{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(Xt,{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(Bd,{label:"Pages open at once",hint:"In buddi’s own browser. One more waits its turn; nothing is refused.",children:t.jsx(Xt,{label:"Pages open at once",value:String(e.maxOwnPages),onChange:S=>r({maxOwnPages:Number(S)}),options:N.map(S=>({value:String(S),label:String(S)}))})}),t.jsx(Bd,{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(Fo,{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 eG="kmbckpnnjfggeffkkbmkggojnolkdokb",tG="pbfpjefkiijjgefblpnlnlpmeaddfbah",sP="https://chromewebstore.google.com/detail/pbfpjefkiijjgefblpnlnlpmeaddfbah",nG=[eG,tG].filter(Boolean);function sG(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 rG(){var e;try{if(typeof chrome>"u"||!((e=chrome==null?void 0:chrome.runtime)!=null&&e.sendMessage))return null;for(const n of nG)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 aG(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 rP(e){try{return new URL(e).origin===window.location.origin}catch{return!1}}const YS=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 iG(e){const n=e.toLowerCase().replace(/\.$/,"");if(!n.includes(".")||YS.has(n))return!0;const s=n.slice(n.indexOf(".")+1);return YS.has(`*.${s}`)}function lG(e){return typeof e=="string"&&e.includes("*")}function oG(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"}:iG(i)?{ok:!1,reason:"public-suffix"}:{ok:!0,value:{pattern:`${a.protocol}//*.${a.host}`,protocol:a.protocol,suffix:i,port:a.port}}}const qS=["every-time","first-time","pre-approved"];function aP(e){const n=qS.indexOf(e);return qS.slice(0,n<0?1:n+1)}function cl(e){return e.endsWith(".account")}const cG="Stored, not usable until it has a binding.";function uG(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":cl(e)?"the account id, e.g. acct-1":'the place, as JSON — e.g. {"host":"localhost","header":"Authorization"}'}const iP={"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})}},dG="A wildcard may only stand for the leftmost part of a site, like *.wikimedia.org.",hG=e=>`That is a public suffix; ${e} would match every site.`,QS="Give the site as an origin, like https://en.wikipedia.org.";function JS(e){const n=/^[a-z][a-z0-9+.-]*:\/\//i.test(e)?e:["https:","//",e].join("");if(lG(e)){const s=oG(n);if(s.ok)return{ok:!0,target:s.value.pattern};if(s.reason==="placement")return{ok:!1,error:dG};if(s.reason==="public-suffix"){const r=n.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/[/?#:].*$/,"").toLowerCase();return{ok:!1,error:hG(r)}}return{ok:!1,error:QS}}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:QS}}}function fG(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 mG(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 JS(s);if(e==="browser.native.type"||cl(e))return{ok:!0,target:s};const r=iP[e];if(r===void 0)return{ok:!0,target:s};const a=fG(s);if(a===null)return{ok:!1,error:`${e} needs both: ${r.hint}.`};if(e==="browser.form.data"){const i=JS(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 pG(e){if(typeof e=="string")return e;try{return JSON.stringify(e)??""}catch{return""}}function lP(e,n){if(typeof n=="string")return n;if(n!==null&&typeof n=="object"&&!Array.isArray(n)){const s=n,r=iP[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 Wo="accounts.provider";function oP(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 cP(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 gG(e){const n=oP(e,"found");return n.length?`The value already sits in ${cP(n)}.`:""}function xG(e){const n=oP(e,"scrubbed");return n.length?`Replaced with ‹secret:…› in ${cP(n)}.`:""}const vG=/^(PROVIDER_ACCOUNT_|CODEX_ACCOUNT_|ANTHROPIC_ACCOUNT_|OLLAMA_DEVICE_)/,jG=/^MCP_(TOKEN|ENV|CONNECTION)_/,uP="GMAIL_APP_PASSWORD";function Sa(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===uP)return"mail";if(n.some(r=>r.kind==="model-account")||s.includes(Wo)||vG.test(e.name))return"models";if(n.some(r=>r.kind==="connection")||s.includes("mcp.env")||jG.test(e.name))return"connections";for(const r of e.bindings){if((r.kind==="http.url"||r.kind==="http.basic"||r.kind==="http.bearer")&&db(r.target)&&typeof r.target.plugin=="string")return`plugin:${r.target.plugin}`;if(cl(r.kind))return`plugin:${r.kind.slice(0,-8)}`}return"mine"}function wG(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 yG(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 dP(e){return e==="models"||e==="connections"}function db(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function XS(e){const n=e.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/\/.*$/,"").replace(/^www\./,"");return n.startsWith("*.")?`any ${n.slice(2)} site`:n}const hb=e=>(e.usedBy??[]).flatMap(n=>n.kind==="mailbox"?[n]:[]),Hm=e=>(e.usedBy??[]).find(n=>n.kind==="model-account"),fb=e=>(e.usedBy??[]).find(n=>n.kind==="connection");function _c(e,n=new Map){var r,a;const s=Sa(e);if(s==="mail"){const i=hb(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=Hm(e),l=(i==null?void 0:i.id)??((r=e.bindings.find(c=>c.kind===Wo&&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=fb(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 hP(e){const n=e.indexOf("@");return n>0?`${e.slice(0,Math.min(n,24))}@…`:e.length>24?`${e.slice(0,23)}…`:e}function bG(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 kG(e,n){const s=e.login;if(!s)return null;const r=bG(s.savedAt,n);return[s.username?`for ${hP(s.username)}`:null,r?`saved ${r}`:null].filter(Boolean).join(" · ")}function NG(e,n){var r,a,i;if(Sa(e)!=="models")return null;const s=((r=Hm(e))==null?void 0:r.id)??((a=e.bindings.find(l=>l.kind===Wo&&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 fP(e,n){const s=db(n)?n:{},r=a=>typeof s[a]=="string"?s[a]:"";return e==="browser.field"&&typeof n=="string"?`Filled on ${XS(n)}`:e==="browser.form.data"&&r("origin")?`Filled into “${r("field")}” on ${XS(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===Wo?"Used by a model account":cl(e)?`Used by a ${e.slice(0,-8)} account`:`Goes to ${lP(e,n)}`}function SG(e,n){return cl(e)||e===Wo?"Signed in":fP(e,n).replace(/^Sent only to/,"Sent to")}const CG={"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 EG(e){return e.length<=1?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function mb(e){const n=Sa(e);if(n==="mail"){const i=hb(e).map(l=>l.address);return i.length?`Used by the ${i.length===1?"mailbox":"mailboxes"} ${EG(i)}`:e.name===uP?"From the old .env setup":"No mailbox uses it"}if(n==="models"){const i=Hm(e);return i?CG[i.auth]??"Key for this model account":"No model account uses it"}if(n==="connections"){const i=fb(e);if(i!=null&&i.variable)return`Given to the program as ${i.variable}`;const l=e.bindings.find(c=>c.kind==="http.header"),o=l&&db(l.target)&&typeof l.target.host=="string"?l.target.host:null;return o?`Sign-in token · sent only to ${o}`:i?"Sign-in for this connection":"No connection uses it"}if(e.bindings.length===0)return"";const s=e.bindings.map(i=>fP(i.kind,i.target));let r=s.length<=2?s.join(" · "):`${s[0]} and ${s.length-1} more places`;const a=new Set(e.bindings.map(i=>i.rule==="first-time"&&i.firstApprovedAt!==null?"pre-approved":i.rule));return a.size===1&&a.has("every-time")&&(r+=" · asks you every time"),a.size===1&&a.has("first-time")&&(r+=" · asks you the first time"),e.totp&&(r+=" · a fresh code each time"),r}function AG(e,n=Date.now()){return e.lastUse?`Last used ${Ye(e.lastUse.at,n)}`:"Never used"}function Zv(e){return vr("email","settings",{account:e,set:"password"})}function mP(e){var s,r;const n=Sa(e);if(n==="models"){const a=(s=Hm(e))==null?void 0:s.id;return{label:"Managed in Model accounts",href:a?bI(a):_e("accounts")}}if(n==="connections"){const a=(r=fb(e))==null?void 0:r.id;return{label:"Managed in Connections",href:a?kI(a):_e("connections")}}return null}function pP(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 gP(e,n=Date.now()){if(e.unused)return null;const s=Sa(e),r=hb(e)[0],a=mP(e),i=()=>r?{label:"Set password",href:Zv(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?Ye(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 ${Ye(r.loginFailedAt,n)}.`,fix:{label:"Set password",href:Zv(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"?pP(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}: ${vP(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:uo}}: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 xP(e){if(!e.unused)return"";const n=Sa(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 ej(e){return e.usageUnknown&&!e.unused?"Couldn’t check what uses it just now.":""}function Wl(e){return!!e.unused&&!dP(Sa(e))}function $G(e){if(e.unused||e.bindings.length===0)return"Nothing uses it, so nothing stops working.";const n=mb(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 TG={"every-time":"Every time","first-time":"The first time, then not again","pre-approved":"Never — allowed ahead of time"};function IG(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",[Wo]:"A model account"};return n[e]?n[e]:cl(e)?`A ${e.slice(0,-8)} account`:e}const RG={"every-time":"Every time","first-time":"The first time","pre-approved":"Never"};function vP(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)?pP(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 PG(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":cl(e)?"acct-1":'{"host":"localhost","header":"Authorization"}'}function bf(e){return aP(e).includes("first-time")?"first-time":e}function MG(e){const n=SG(e.kind,e.target);return e.outcome==="refused"?{text:`Held back — ${vP(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 OG=2*6e4,DG=2e3;function LG({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 f=window.setTimeout(n,OG);return()=>window.clearTimeout(f)},[e.id]),d.useEffect(()=>{if(!l)return;const f=window.setTimeout(n,DG);return()=>window.clearTimeout(f)},[l]);const c=async f=>{r(!0),i(null);try{const m=await T.browserLogin(e.id,f);if(f==="save"&&m.outcome==="saved"){o(!0);return}if(f==="save"&&m.outcome==="gone"){i({reason:"That sign-in is no longer held. Add it in Keys and secrets.",retry:!1});return}n()}catch(m){i({reason:m instanceof Error?m.message:String(m),retry:f==="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:_e("secrets"),children:"Keys and secrets"}),"."]});const h=e.username?`For ${hP(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(re,{align:"end",children:[t.jsx(E,{size:"sm",variant:"ghost",disabled:s,onClick:()=>void c("never"),children:"Never for this site"}),t.jsx(E,{size:"sm",disabled:s,onClick:()=>void c("later"),children:"Not now"}),t.jsx(E,{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(E,{size:"sm",disabled:s,onClick:()=>void c("save"),children:"Try again"}):void 0,children:a.reason}):null]})}const FG=2e3,_G=5,zG="(hover: none) and (pointer: coarse)",tj="buddi:browser-enlarge",UG=8e3,BG="https:";function WG(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:`${BG}//${n}`;try{const r=new URL(s);return r.protocol==="https:"||r.protocol==="http:"?r.toString():null}catch{return null}}function HG(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 ZS(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 KG(e){var s,r,a;return(e==null?void 0:e.route)==="apps"&&((s=e.page)!=null&&s.appId)?Wm(e.page.appId).charAt(0).toUpperCase():(ub((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 VG({status:e,error:n,reload:s,live:r,agentName:a="The agent",timezone:i,paused:l=null}){var Rn,zn,Yt,Un,xn,vn,Xn,_t,Te,rt,De,tt;const o=i??Intl.DateTimeFormat().resolvedOptions().timeZone,[c,u]=d.useState(0),[h,f]=d.useState(0),m=h>=_G;d.useEffect(()=>{if(!r||m)return;const F=window.setInterval(()=>{typeof document<"u"&&document.hidden||u(Fe=>Fe+1)},FG);return()=>window.clearInterval(F)},[r,m]);const p=d.useRef(null);r&&(e!=null&&e.session)&&(p.current=e);const[v,g]=d.useState(null);d.useEffect(()=>{!r&&p.current&&v===null&&g(Date.now()),r&&g(null)},[r]);const[k,j]=d.useState(null),x=d.useRef(null),w=((Rn=e==null?void 0:e.page)==null?void 0:Rn.id)??null;d.useEffect(()=>{const F=r&&e?ZS(e):null;if(!F||typeof fetch!="function"||typeof(URL==null?void 0:URL.createObjectURL)!="function")return;let Fe=!1;return(async()=>{try{const Ct=await fetch(F);if(!Ct.ok||Fe)return;const on=await Ct.blob();if(Fe)return;const $e=URL.createObjectURL(on);x.current&&URL.revokeObjectURL(x.current),x.current=$e,j($e)}catch{}})(),()=>{Fe=!0}},[r,w]),d.useEffect(()=>()=>{x.current&&typeof(URL==null?void 0:URL.revokeObjectURL)=="function"&&URL.revokeObjectURL(x.current)},[]);const N=p.current,y=r?e:N??e,[b,S]=d.useState(!1),[C,A]=d.useState(null),[$,I]=d.useState(null),[P,O]=d.useState(!1),[R,D]=d.useState(null),[U,W]=d.useState(!1),M=Bm(),L=Yn(zG),_=d.useRef(null),[Y,B]=d.useState(null),se=d.useRef(null),G=y==null?void 0:y.session,X=async F=>{S(!0),A(null);try{await F()}catch(Fe){A(Fe instanceof Error?Fe.message:String(Fe))}finally{S(!1),s()}},K=()=>void X(async()=>{var Ct;D(null),W(!1);const F=G==null?void 0:G.id;F&&(se.current=F);const Fe=await T.browserControl("takeover",F);((Ct=Fe.held)==null?void 0:Ct.where)!=="chrome"&&(Fe.hand&&Fe.session&&(!F||Fe.session.id===F)?I(Fe.session.id):Fe.handReason==="browser-offline"?W(!0):D(Fe.handMessage??null))}),J=()=>void X(async()=>{I(null),O(!1),await T.browserControl("resume",G==null?void 0:G.id)}),q=()=>void X(async()=>{I(null),await T.browserControl("stop",G==null?void 0:G.id)}),ce=()=>void X(async()=>{G&&(await T.browserPin(G.conversationId,"own"),await T.browserControl("release",G.id),W(!1),D("This conversation uses buddi’s browser now. Send the agent a message and it opens the page there."))}),xe=r&&!!(e!=null&&e.session)&&e.state==="paused",Me=xe&&((zn=e==null?void 0:e.held)==null?void 0:zn.where)==="chrome",H=xe&&!Me&&$&&((Yt=e==null?void 0:e.session)==null?void 0:Yt.id)===$?$:null,ne=xe?((Un=e==null?void 0:e.session)==null?void 0:Un.id)??null:null;d.useEffect(()=>{!ne||$===ne||L||b||(e==null?void 0:e.route)==="apps"||Me||se.current!==ne&&K()},[ne,$,L]),d.useEffect(()=>{xe||(se.current=null)},[xe]);const[Z,ye]=d.useState(!1);d.useEffect(()=>{const F=()=>ye(!0);return window.addEventListener(tj,F),()=>window.removeEventListener(tj,F)},[]),d.useEffect(()=>{if(!Z)return;const F=Fe=>{Fe.key==="Escape"&&!Fe.defaultPrevented&&ye(!1)};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[Z]);const[Ce,ke]=d.useState(null),[we,ve]=d.useState(!1);d.useEffect(()=>{ke(null),ve(!1)},[H]),d.useEffect(()=>{if(!we)return;const F=window.setTimeout(()=>ve(!1),UG);return()=>window.clearTimeout(F)},[we]);const Ie=F=>{ke(F),ve(!1)},Re=(F,Fe)=>{var Ct;A(null),(Ct=_.current)!=null&&Ct.nav(F,Fe)&&ve(!0)},de=xe,Ee=r&&!!(y!=null&&y.needsOwner),ze=!r&&!l,qe=ub((xn=y==null?void 0:y.page)==null?void 0:xn.url)??((vn=y==null?void 0:y.page)!=null&&vn.appId?Wm(y.page.appId):"the page"),ht=(y==null?void 0:y.route)==="chrome"?"in your Chrome · background tab":(y==null?void 0:y.route)==="apps"?`in ${qe}`:"in buddi’s browser",le=l?"Browsing is paused":((Xn=y==null?void 0:y.page)==null?void 0:Xn.title)||qe,je=l?`By you at ${Tt(new Date(l.at),o)} · ${l.until?`until ${Tt(new Date(l.until),o)}`:"until you resume it"}`:Me?"You have the page · in your Chrome · it’s in front":de?`You have the page · ${ht}`:ze?`${a} looked at ${qe} · done${v?` at ${Tt(new Date(v),o)}`:""}`:y?tP(y):"Opening the page…",et=r?y?ZS(y,c):null:k,ft=(y==null?void 0:y.route)==="apps",Et=H?Ce??((_t=y==null?void 0:y.page)==null?void 0:_t.url):(Te=y==null?void 0:y.page)==null?void 0:Te.url,Ft=r&&(we||!de&&!!(e!=null&&e.busy)),Pt=y||r?t.jsx("button",{type:"button",className:"ui-icon-btn br-enlarge","data-size":"sm","aria-label":Z?"Back to the side":"Enlarge the page",title:Z?"Back to the side (Esc)":"Enlarge the page",onClick:()=>ye(!Z),children:t.jsx(ie,{name:Z?"collapse":"expand"})}):null;return t.jsxs("div",{className:"br-canvas","data-testid":"browser-view","data-live":r?"true":"false","data-enlarged":Z?"true":void 0,...Z?{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(YG,{}):KG(y)}),t.jsxs("span",{className:"br-head-text",children:[t.jsx("span",{className:"br-head-title",children:le}),t.jsxs("span",{className:"br-head-line",role:"status",children:[r&&!Ee&&!de&&!l?t.jsx("span",{className:"br-live","aria-hidden":"true"}):null,je]})]}),de?t.jsxs(re,{align:"end",children:[Me?null:H?L?t.jsx(E,{size:"sm",variant:P?"accent":"ghost","aria-pressed":P,onClick:()=>O(!P),children:"Type into the page"}):null:t.jsx(E,{size:"sm",variant:"ghost",disabled:b,onClick:K,children:"Drive it here"}),t.jsx(E,{size:"sm",variant:"accent",disabled:b,onClick:J,children:"Give it back"}),Pt]}):l?t.jsx(E,{size:"sm",variant:"accent",disabled:b,onClick:()=>void X(async()=>{await T.browserControl("resume")}),children:"Resume"}):ze||!G?Pt?t.jsx(re,{align:"end",children:Pt}):null:t.jsxs(re,{align:"end",children:[t.jsx(E,{size:"sm",disabled:b||!(y!=null&&y.enabled),onClick:q,children:"Stop"}),t.jsx(E,{size:"sm",variant:Ee?"accent":void 0,disabled:b||!(y!=null&&y.enabled)||(y==null?void 0:y.state)==="paused",onClick:K,children:"Take over"}),Pt]})]}),de?t.jsx("p",{className:"br-hand-said",role:"status",children:Me?"Finish in Chrome, then give it back.":H?`Nothing you type here is kept. ${a} carries on when you give it back.${L?" 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,R?t.jsx(Q,{tone:"warning",role:"status",children:R}):null,U?t.jsx(Q,{tone:"warning",role:"status",title:"Your Chrome isn’t connected.",action:t.jsxs(re,{align:"end",children:[t.jsx(E,{size:"sm",disabled:b,onClick:ce,children:"Use buddi’s browser"}),t.jsx(E,{size:"sm",variant:"accent",disabled:b,onClick:K,children:"Try again"})]}),children:`Open Chrome on ${M} and try again, or let this conversation use buddi’s own browser.`}):null,Y?t.jsx(LG,{login:Y,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 ${Tt(new Date(l.until),o)}`:""}.`})}):t.jsxs("div",{className:"br-window","data-state":H?"yours":Ee?"waiting":ze?"done":"live",children:[t.jsx(GG,{app:ft?qe:null,title:((rt=y==null?void 0:y.page)==null?void 0:rt.title)||void 0,address:Et,held:!!H,loading:Ft,onNav:Re,onRefused:F=>A(F)}),H?t.jsx("div",{className:"br-frame","data-state":"yours",children:t.jsx(LV,{ref:_,sessionId:H,csrf:al(),onGiveBack:J,bare:!0,typing:P,onTyping:O,onLocation:Ie,onLoginSeen:B})}):t.jsx("div",{className:"br-frame","data-state":Ee?"waiting":ze?"done":"live",children:et?t.jsx("img",{className:"br-shot",src:et,alt:`What ${a} sees: ${((De=y==null?void 0:y.page)==null?void 0:De.title)||qe}`,onError:()=>f(F=>F+1),onLoad:()=>f(0)},r?((tt=y==null?void 0:y.page)==null?void 0:tt.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."})})]}),ze?t.jsx("p",{className:"br-ended",role:"status",children:"The page is closed. This is the last thing it showed."}):r&&m?t.jsx("p",{className:"br-ended",role:"status",children:"The newest picture didn’t load. Showing the one before it."}):null]})}function GG({app:e,title:n,address:s,held:r,loading:a,onNav:i,onRefused:l}){const[o,c]=d.useState(null),[u,h]=d.useState(!1);d.useEffect(()=>{c(null)},[s,r]),d.useEffect(()=>{if(!u)return;const g=window.setTimeout(()=>h(!1),1500);return()=>window.clearTimeout(g)},[u]);const f=HG(s),m=()=>{var g;s&&((g=navigator.clipboard)==null||g.writeText(s).then(()=>h(!0),()=>{}))},p=g=>{var j,x;if(g.preventDefault(),o===null)return;const k=WG(o);if(!k){l("That isn’t a web address. Type one like amazon.com/orders.");return}c(null),i("navigate",k),(x=(j=document.activeElement)==null?void 0:j.blur)==null||x.call(j)},v=g=>{g.key==="Escape"&&(g.preventDefault(),c(null),g.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:()=>i("back"),children:t.jsx(ie,{name:"back"})}),t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"Forward",title:"Forward",disabled:!r,onClick:()=>i("forward"),children:t.jsx(ie,{name:"forward"})}),t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"Reload",title:"Reload",disabled:!r,onClick:()=>i("reload"),children:t.jsx(ie,{name:"reload"})})]}),r?t.jsxs("form",{className:"br-address","data-editable":"true",onSubmit:p,children:[t.jsx(eC,{secure:(f==null?void 0:f.secure)??!1}),t.jsx("input",{className:"br-address-input","aria-label":"Address",value:o??s??"",spellCheck:!1,autoCapitalize:"off",autoCorrect:"off",onFocus:g=>g.currentTarget.select(),onChange:g=>c(g.target.value),onKeyDown:v}),t.jsx("button",{type:"button",className:"br-address-copy","aria-label":u?"Copied":"Copy the address",title:u?"Copied":"Copy the address",disabled:!s,onClick:m,children:t.jsx(ie,{name:u?"check":"copy",size:14})})]}):t.jsxs("button",{type:"button",className:"br-address","aria-label":u?"Address copied":"Copy the address",title:u?"Copied":"Copy the address",disabled:!s,onClick:m,children:[t.jsx(eC,{secure:(f==null?void 0:f.secure)??!1}),t.jsx("span",{className:"br-address-text",children:f?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"br-address-host",children:f.host}),t.jsx("span",{className:"br-address-rest",children:f.rest})]}):t.jsx("span",{className:"br-address-rest",children:"No address yet"})}),u?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-progress",role:"progressbar","aria-label":"Loading"}):null]})}function eC({secure:e}){return t.jsx("span",{className:"br-address-mark","aria-hidden":"true",children:t.jsx(ie,{name:e?"lock":"globe",size:12})})}function YG(){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 qG({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=Tt(new Date(Date.now()+(a||60)*6e4),r),l=c=>void c().catch(()=>{}).finally(s);return t.jsx(Jn,{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(tj))}}]})}function QG({agentId:e,conversationId:n}){const{data:s,error:r,reload:a}=me(()=>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(v){l(v instanceof Error?v.message:String(v))}finally{c(!1)}},h=(s==null?void 0:s.permissions)??[],f=(s==null?void 0:s.runs)??[],m=h.some(p=>!p.conversationId)?"Always allowed":h.length?"Conversation auto-mode":"Ask each time";return t.jsx(Gt,{className:"host-controls",summary:`Host execution · ${r?"Status unavailable":m}${f.length?` · ${f.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(ae,{message:i??r}),h.map(p=>t.jsxs(re,{children:[t.jsxs("span",{children:[p.agentId,": ",p.conversationId?"conversation auto-mode":"always allowed"]}),t.jsx(E,{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."}),f.map(p=>t.jsxs(ue,{gap:"sm",children:[t.jsxs("p",{children:[p.agentId," · ",t.jsx("span",{className:"mono",children:p.cwd})]}),t.jsx(Bt,{children:p.command}),t.jsx(Bt,{label:"Command output",children:p.stdout||p.stderr?`${p.stdout}
117
+ ${p.stderr}`:"Waiting for output…"}),t.jsx(re,{children:t.jsx(E,{size:"sm",variant:"danger",disabled:o,onClick:()=>void u(()=>T.stopHost(p.agentId,p.conversationId)),children:"Stop command"})})]},p.actionId))]})})}const JG="browser.act",XG="browser.status",kh=new Set([JG,XG]);function ZG(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 e7(e,n){return{...e,title:"Page",pinned:!1}}function t7(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 tC(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=kh.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 xg="Save a login for next time",n7=new Set(["Skip this site","Skip it","Keep paused","Leave it stopped"]),s7=["Use my Chrome","Use Chrome when it’s open","Open Chrome and I'll use it there"];function nj(e){if(!e||e.allowOther)return null;const n=new Set(e.options.map(h=>h.label)),s=(...h)=>h.some(f=>n.has(f)),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(xg,...s7)||/sign-in|asks for a code/i.test(e.question))?"signin":null;if(!r)return null;const[a,...i]=e.question.split(`
118
+ `),l=(a??"").trim().replace(/\.$/,""),o=e.options.find(h=>h.label===xg)??null,c=e.options.filter(h=>h.label!==xg),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 jP({card:e,disabled:n,onAnswer:s,site:r}){const a=`${gv}${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(re,{align:"end",children:[e.saveLogin?t.jsxs(t.Fragment,{children:[t.jsx("a",{className:"wb-link",href:a,children:e.saveLogin.label}),t.jsx(pt,{})]}):null,e.actions.map(i=>t.jsx(E,{size:"sm",variant:i.recommended?"accent":n7.has(i.label)?"ghost":void 0,disabled:n,title:i.hint??void 0,onClick:()=>s(i.label,i.id),children:i.label},i.id))]})})]})}const r7="web.read",a7="web.search",i7=new Set([r7,a7]),nC=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"]),sC=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 l7({agentId:e,groupId:n,currentId:s,timezone:r,onSelect:a,onNew:i}){const[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(0);return d.useEffect(()=>{let m=!1;return o(null),u(null),(n?Qe.groupConversations(n):Qe.conversations(e,100)).then(p=>{m||o(p.conversations)}).catch(p=>{m||u(p instanceof Error?p.message:String(p))}),()=>{m=!0}},[e,n,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:()=>f(m=>m+1),children:"Retry"})]}):l===null?t.jsx("p",{className:"muted",children:"Loading conversations…"}):l.length===0?t.jsx("p",{className:"muted",children:"No conversations yet."}):t.jsx("ul",{children:l.map(m=>t.jsx("li",{children:t.jsxs("a",{href:n?Ii(n,m.id):lt(e,m.id),"aria-current":m.id===s?"page":void 0,onClick:p=>{p.button===0&&!p.metaKey&&!p.ctrlKey&&!p.shiftKey&&!p.altKey&&(p.preventDefault(),a(m.id))},children:[t.jsx("span",{children:m.preview||m.opening||"Untitled conversation"}),t.jsxs("small",{children:[mt(m.lastMessageAt??m.startedAt??m.createdAt??null,r)," · ",m.messageCount," messages",m.id===s?" · Current":""]})]})},m.id))}),t.jsx("a",{href:"#/conversations",children:"View all agents’ conversation records ↗"}),(l==null?void 0:l.length)===100?t.jsx("p",{className:"muted",children:"Showing the 100 most recent conversations."}):null]})}const o7=600,Nl={closed:[],touched:{}},rC=/^[\w:./-]{1,200}$/;function c7(e){return{closed:e.closed.filter(n=>rC.test(n)).slice(-200),touched:Object.fromEntries(Object.entries(e.touched).filter(([n])=>rC.test(n)).sort((n,s)=>n[1]-s[1]).slice(-200))}}function u7(e,n=Date.now){const[s,r]=d.useState({id:null,value:Nl}),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&&Qe.saveCanvasTabs(g.id,g.value).catch(()=>{})},[]);d.useEffect(()=>{if(c(),l.current=[],o.current=null,r({id:e,value:Nl}),!e)return;let g=!0;return Promise.resolve().then(()=>Qe.canvasTabs(e)).catch(()=>Nl).then(k=>{if(!g)return;const j=k&&Array.isArray(k.closed)&&k.touched&&typeof k.touched=="object"?k:Nl,x=l.current.reduce((N,y)=>y(N),j),w=l.current.length>0;l.current=[],o.current=e,r({id:e,value:x,ready:!0}),w&&(i.current={id:e,value:x},c())}),()=>{g=!1}},[e,c]),d.useEffect(()=>()=>c(),[c]);const u=d.useCallback(g=>{e&&(o.current!==e&&l.current.push(g),r(k=>{const j=c7(g(k.id===e?k.value:Nl));return o.current===e&&(i.current={id:e,value:j},a.current&&clearTimeout(a.current),a.current=setTimeout(c,o7)),{id:e,value:j,ready:k.id===e&&k.ready===!0}}))},[e,c]),h=d.useCallback(g=>u(k=>({...k,closed:[...k.closed.filter(j=>!g.includes(j)),...g]})),[u]),f=d.useCallback(g=>u(k=>k.closed.some(j=>g.includes(j))?{...k,closed:k.closed.filter(j=>!g.includes(j))}:k),[u]),m=d.useCallback(g=>u(k=>({...k,touched:{...k.touched,[g]:n()}})),[u,n]),p=s.id===e?s.value:Nl;return{ready:e===null||s.id===e&&s.ready===!0,closed:p.closed,touched:p.touched,close:h,reopen:f,touch:m}}const aC=3;function d7(e){return e.frontDesk?"the front desk":`@${e.handle}`}function iC(e){const n=e.slice(0,aC).map(d7);return e.length>aC?`${n.join(", ")}, …`:n.join(", ")}function h7(e){const n=e.asks==="everyone"?"may ask everyone":e.asks.length===0?"asks nobody yet":`may ask ${iC(e.asks)}`,s=e.askedBy.length===0?"and nobody asks it yet":`and can be asked by ${iC(e.askedBy)}`;return`New here. @${e.handle} ${n}, ${s}.`}function f7({agentId:e}){const n=me(()=>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:h7(a)}),t.jsx(nt,{variant:"ghost",size:"sm",href:Dt(e,"setup","team"),onClick:i,children:"Adjust"}),t.jsx(E,{variant:"ghost",size:"sm",className:"ui-icon-btn","aria-label":"Close",title:"Close",onClick:i,children:t.jsx(ie,{name:"close",size:14})})]})}const sj="​",vg=/(`[^`\n]+`)|(\*\*[^*\n]+\*\*)|(\*[^*\s][^*\n]*\*|_[^_\s][^_\n]*_)|(\[[^\]\n]+\]\([^)\s]+\))|(https?:\/\/[^\s)]+)|(@[a-z][a-z0-9-]*)/gi;function jg(e,n,s){const r=[];let a=0,i=0;vg.lastIndex=0;for(let l=vg.exec(e);l;l=vg.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(f=>f.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 m7(e,n){const s=e.split(`
119
+ `);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:yT(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||sj})},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:jg(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],jg(c[4],n,String(i))]},i):t.jsx("div",{className:"cv-line",children:a?jg(a,n,String(i)):sj},i)})}const pb=(e,n)=>`${e}-opt-${n}`;function p7({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:pb(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(In,{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 g7({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:pb(e,u),role:"option","aria-selected":u===s,"aria-disabled":c.off||void 0,"aria-label":`/${c.name}${c.args?` ${c.args}`:""}: ${c.desc}`,className:"cv-pop-row","data-cmd":"true","data-active":u===s||void 0,"data-off":c.off||void 0,onMouseDown:f=>{f.preventDefault(),c.off||r(c)},children:[t.jsxs("span",{className:"cv-pop-cmd",children:["/",c.name,c.args?t.jsxs("span",{className:"cv-pop-args",children:[" ",c.args]}):null]}),t.jsx("span",{className:"cv-pop-desc",children:c.desc}),a?null:c.key?t.jsx("kbd",{className:"cv-kbd",children:c.key}):u===s?t.jsx("kbd",{className:"cv-kbd",children:"↵"}):null]})]},`${c.group}/${c.name}`)})}),a?null:t.jsxs("div",{className:"cv-pop-foot","aria-hidden":"true",children:[t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"↑"}),t.jsx("kbd",{className:"cv-kbd",children:"↓"})," choose"]}),t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"↵"})," run"]}),t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"Tab"})," add words"]}),t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"Esc"})," close"]})]})]})}const x7=350,v7=60;function j7({conversationId:e,onText:n,onNotice:s}){const[r,a]=d.useState("idle"),i=d.useRef("idle"),l=x=>{i.current=x,a(x)},o=d.useRef(null),c=d.useRef(null),u=d.useRef(null),h=d.useRef(null),f=d.useRef(null),m=d.useRef({onText:n,onNotice:s,conversationId:e});m.current={onText:n,onNotice:s,conversationId:e};const p=()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null)},v=async()=>{if(i.current!=="idle")return;m.current.onNotice(null),l("starting"),c.current=null;let x;try{x=await yH(y=>{var b;return(b=f.current)==null?void 0:b.call(f,y)})}catch(y){h.current=null,l("idle"),m.current.onNotice(wH(y));return}const w=c.current;c.current=null;const N=i.current;if(w==="discard"||N!=="starting"){x.cancel(),N==="starting"&&l("idle");return}o.current=x,l("recording"),u.current=window.setTimeout(()=>void g(!1),xH),w&&g(w.sendNow)},g=async x=>{h.current=null;const w=o.current;if(!w){i.current==="starting"&&(c.current={sendNow:x});return}o.current=null,p(),l("transcribing");try{const N=await w.stop();if(N.size<=44){m.current.onNotice("Nothing was recorded.");return}const y=new File([N],`recording-${new Date().toISOString().slice(0,19).replace(/[:T]/g,"-")}.wav`,{type:"audio/wav"}),b=await Qe.attach(y),S=m.current.conversationId,C=await Qe.transcribe({artifactId:b.artifactId,...S?{conversationId:S}:{}});m.current.onText(C.text,x)}catch(N){m.current.onNotice(N instanceof he||N instanceof Error?N.message:String(N))}finally{l("idle")}},k=()=>{h.current=null;const x=o.current;if(!x){i.current==="starting"&&(c.current="discard");return}o.current=null,p(),x.cancel(),l("idle")};d.useEffect(()=>{const x=w=>{if(h.current===null)return;const N=Date.now()-h.current;h.current=null,N>=x7&&g(w.shiftKey)};return window.addEventListener("pointerup",x),()=>window.removeEventListener("pointerup",x)},[]);const j=r==="starting"||r==="recording";return d.useEffect(()=>{if(!j)return;const x=w=>{w.isComposing||w.repeat||(w.key==="Escape"?(w.preventDefault(),w.stopPropagation(),k()):w.key==="Enter"&&(w.preventDefault(),w.stopPropagation(),g(w.shiftKey)))};return window.addEventListener("keydown",x,!0),()=>window.removeEventListener("keydown",x,!0)},[j]),d.useEffect(()=>()=>{var x;(x=o.current)==null||x.cancel(),p()},[]),{state:r,hold:()=>{h.current=Date.now(),v()},start:()=>{h.current=null,v()},finish:x=>void g(x),discard:k,levels:f}}function w7({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(ie,{name:"mic"})})}function y7({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(b7,{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(ie,{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(ie,{name:"check"})})]})]})}function b7({sink:e,frozen:n}){const[s,r]=d.useState(()=>Array(v7).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 k7="This browser cannot capture a tab. Chrome, Safari and Firefox can, on a secure address.",Wd="The tab could not be captured. Try again, and pick the tab itself rather than the whole screen.",N7=e=>e instanceof Error&&(e.name==="NotAllowedError"||e.name==="AbortError");async function S7(e={}){var r;const n=e.media??(typeof navigator>"u"?void 0:navigator.mediaDevices);if(!n||typeof n.getDisplayMedia!="function")throw new Error(k7);let s;try{s=await n.getDisplayMedia({video:{displaySurface:"browser"},audio:!1,selfBrowserSurface:"exclude",surfaceSwitching:"exclude",preferCurrentTab:!1})}catch(a){if(N7(a))return null;throw new Error(Wd)}try{const a=e.document??document,i=a.createElement("video");i.muted=!0,i.playsInline=!0,i.srcObject=s,await new Promise((h,f)=>{i.onloadedmetadata=()=>h(),i.onerror=()=>f(new Error(Wd))}),await i.play(),await new Promise(h=>{const f=i.requestVideoFrameCallback;typeof f=="function"?f.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(Wd);o.drawImage(i,0,0);const c=await new Promise(h=>l.toBlob(h,"image/png"));if(!c)throw new Error(Wd);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 C7(e,n){return`${e} picks up ${n===1?"the file":"the files"} between steps, or right after this answer.`}const rj="wb-composer-input",E7="(max-width: 720px)",lC={desk:288,phone:240};function A7(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?lC.phone:lC.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 gb=d.forwardRef(function({disabled:n,running:s,onSend:r,onStop:a,agentName:i,draft:l,model:o,chrome:c,setupHref:u,thinking:h,onThinking:f,onOpenFile:m,mentions:p,team:v,onCommand:g,history:k,threadKey:j,conversationId:x,readAloud:w,onReadAloud:N,placeholder:y,slim:b},S){var qo,cn,rd;const C=j?`buddi.draft.${j}`:null,A=V=>{if(!V)return"";try{return window.localStorage.getItem(V)??""}catch{return""}},[$,I]=d.useState(()=>A(C)),[P,O]=d.useState(()=>$.length),[R,D]=d.useState([]),[U,W]=d.useState(!1),[M,L]=d.useState(null),[_,Y]=d.useState(!1),[B,se]=d.useState(null),G=d.useRef(null),X=d.useRef(null),K=d.useRef(null),J=Yn(E7),q=`cv-pop-${d.useId().replace(/[^a-zA-Z0-9_-]/g,"")}`,ce=n_(),xe=d.useMemo(()=>{const V=Be=>v==null?void 0:v.agents.find(un=>un.id===Be),We=(Be,un)=>Xi(Lo(Be??{id:un}));if(p)return p.map(Be=>{const un=Be.id??Be.handle,ds=V(un);return{id:un,handle:Be.handle,name:Be.name,effect:`Asks @${Be.handle} in this room`,group:"In this room",accent:We(ds,un),...ds?{face:ds}:{}}});if(!v)return[];const Ke=v.agents.find(Be=>Be.roles.includes(jr)&&Be.id!==v.selfId),Mt=v.agents.filter(Be=>Be.id!==v.selfId&&Be!==Ke);return[...Ke?[{id:Ke.id,handle:Ke.handle,name:Ke.name,effect:`Borrows ${Ke.name} for this message`,group:"Borrow",accent:Xi({key:"buddi"}),face:Ke}]:[],...Mt.map(Be=>({id:Be.id,handle:Be.handle,name:Be.name,effect:`${i} asks @${Be.handle}`,group:"Ask a teammate",accent:We(Be,Be.id),face:Be}))]},[p,v,i]),Me=!p&&v?((qo=v.agents.find(V=>V.roles.includes(jr)&&V.id!==v.selfId))==null?void 0:qo.handle)??null:null,[H,ne]=d.useState(!1),[Z,ye]=d.useState(0),Ce=!!g,ke=Ce&&o3($,P),we=!H&&xe.length>0?i3($,P):null,ve=!H&&Ce&&!we?l3($,P):null,Ie=we?xe.filter(V=>!ke||V.group!=="Borrow").filter(V=>V.handle.toLowerCase().startsWith(we.query.toLowerCase())||V.name.toLowerCase().startsWith(we.query.toLowerCase())).map(V=>ke?{...V,group:"Talk to",effect:`Talk to ${V.name} from here on`}:V).slice(0,8):[],Re=d.useMemo(()=>[...JF(i,s),...ZF(ce)],[i,s,ce]),de=ve?Re.filter(V=>V.name.startsWith(ve.query.toLowerCase())):[],Ee=we&&Ie.length>0?"mention":ve?"slash":null,ze=Ee==="mention"?Ie:Ee==="slash"?de:[],qe=ze.length>0?Math.min(Z,ze.length-1):-1,ht=A7(K,Ee!==null,J),le=k??[],[je,et]=d.useState(-1),ft=d.useRef($),Et=d.useRef(C);if(Et.current!==C){Et.current=C;const V=A(C);ft.current=V,V!==$&&(I(V),O(V.length),et(-1),se(null))}const Ft=V=>{if(ft.current=V,!!C)try{V===""?window.localStorage.removeItem(C):window.localStorage.setItem(C,V)}catch{}},Pt=V=>{I(V.value),O(V.caret),ne(!1),ye(0),je<0&&Ft(V.value);const We=X.current;We&&(We.value=V.value,We.setSelectionRange(V.caret,V.caret),window.requestAnimationFrame(()=>{We.focus(),We.setSelectionRange(V.caret,V.caret)}))},Rn=V=>{I(V),O(V.length),ne(!1);const We=X.current;We&&(We.value=V,We.setSelectionRange(V.length,V.length))},zn=V=>!V.value.slice(0,V.selectionStart??V.value.length).includes(`
120
+ `),Yt=()=>$===""||je>=0&&$===le[je],Un=()=>{je<0||(et(-1),Rn(ft.current))},xn=R.some(V=>V.state==="uploading"),vn=R.length>0,Xn=s&&vn,_t=R.some(V=>V.state==="ready"&&V.uploaded),Te=!n&&!xn&&($.trim()!==""||_t),rt=V=>{const We=[];for(const Ke of Array.from(V??[])){const Mt=`${Ke.name}:${Ke.size}:${Math.random().toString(36).slice(2,8)}`;We.push(Mt);const Be=Ke.type.startsWith("image/")&&typeof URL.createObjectURL=="function"?URL.createObjectURL(Ke):null;D(un=>[...un,{key:Mt,filename:Ke.name||"Pasted image",mime:Ke.type||"application/octet-stream",sizeBytes:Ke.size,thumbnail:Be,state:"uploading"}]),Qe.attach(Ke).then(un=>D(ds=>ds.map(es=>es.key===Mt?{...es,state:"ready",uploaded:un}:es))).catch(un=>D(ds=>ds.map(es=>es.key===Mt?{...es,state:"failed",error:un instanceof he?un.message:String(un)}:es)))}return We},De=V=>{V.thumbnail&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(V.thumbnail)},tt=V=>{const We=R.find(Ke=>Ke.key===V);We&&(De(We),We.state==="ready"&&We.uploaded&&Qe.discardAttachment(We.uploaded.artifactId).catch(()=>{})),D(Ke=>Ke.filter(Mt=>Mt.key!==V)),(B==null?void 0:B.kind)==="long"&&B.key===V&&se(null)};d.useImperativeHandle(S,()=>({addFiles:V=>{var We;rt(V),(We=X.current)==null||We.focus()},focus:()=>{var V;return(V=X.current)==null?void 0:V.focus()}}));const F=d.useRef(R);F.current=R,d.useEffect(()=>()=>F.current.forEach(De),[]);const Fe=d.useRef(0);d.useEffect(()=>{if(!l||l.at===Fe.current)return;Fe.current=l.at;const V=$.trim()==="";I(Ke=>Ke.trim()===""?l.text:Ke),je<0&&V&&Ft(l.text);const We=X.current;We&&(We.focus(),window.requestAnimationFrame(()=>{We.setSelectionRange(We.value.length,We.value.length),O(We.value.length)}))},[l]);const Ct=()=>{et(-1),Ft(""),I(""),O(0),se(null),ne(!1)},on=(V,We)=>{if(g){if(V==="stop"&&!s){Ct();return}Ct(),g(V,We)}},$e=V=>{const We=(V??$).trim();if(V===void 0?!Te:n||xn||We==="")return;const Ke=V===void 0&&g?c3(We):null;if(Ke&&X0(Ke.name)&&R.length===0){if(Ke.name==="use"&&Ke.arg===""){Pt({value:"/use @",caret:6});return}on(Ke.name,Ke.arg.replace(/^@/,""));return}const Mt=R.filter(Be=>Be.state==="ready"&&Be.uploaded).map(Be=>Be.uploaded);r(We,Mt),R.forEach(De),Ct(),D([])},Oe=V=>{if(we){if(ke&&g){on("use",V.handle);return}Pt(u3($,P,we.start,V.handle))}},it=(V,We)=>{if(V.off)return;const Ke=$.slice(P);if(We||e_(V)){const Be=`/${V.name} ${V.name==="use"?"@":""}`;Pt({value:Be+Ke.replace(/^\S*/,"").replace(/^ /,""),caret:Be.length});return}if(V.source==="chat"&&X0(V.name)){on(V.name,"");return}const Mt=`/${V.name}`;if(n||xn){Pt({value:`${Mt} `,caret:Mt.length+1});return}$e(Mt)},jt=V=>{if(V.nativeEvent.isComposing)return;if(Ee&&ze.length>0){if(V.key==="ArrowDown"){V.preventDefault(),ye((qe+1)%ze.length);return}if(V.key==="ArrowUp"){V.preventDefault(),ye((qe-1+ze.length)%ze.length);return}if(V.key==="Enter"&&!V.shiftKey||V.key==="Tab"){V.preventDefault();const Be=ze[qe];Ee==="mention"?Oe(Be):it(Be,V.key==="Tab");return}}if(Ee&&V.key==="Escape"){V.preventDefault(),ne(!0);return}if(V.key==="ArrowUp"&&!V.shiftKey&&!V.altKey&&!V.metaKey&&!V.ctrlKey){const Be=V.currentTarget;if(le.length>0&&je+1<le.length&&zn(Be)&&Yt()){V.preventDefault(),je<0&&(ft.current=$),et(je+1),Rn(le[je+1]);return}}if(V.key==="ArrowDown"&&!V.shiftKey&&!V.altKey&&!V.metaKey&&!V.ctrlKey&&je>=0&&$===le[je]){if(V.preventDefault(),je===0){Un();return}et(je-1),Rn(le[je-1]);return}if(V.key==="Escape"&&je>=0){V.preventDefault(),Un();return}if(V.key==="Escape"&&s&&g){V.preventDefault(),a();return}const We=V.currentTarget,Ke=We.selectionStart??P,Mt=We.selectionStart===We.selectionEnd;if(V.key==="Tab"&&Mt&&!V.altKey&&!V.metaKey&&!V.ctrlKey){const Be=f3($,Ke,V.shiftKey);if(Be){V.preventDefault(),Pt(Be);return}}if(V.key==="Enter"&&!V.shiftKey&&!V.metaKey&&!V.ctrlKey&&!V.altKey){const Be=Mt?h3($,Ke):null;if(Be){V.preventDefault(),Pt(Be);return}if(Mc($,Ke))return;V.preventDefault(),$e();return}V.key==="Enter"&&(V.metaKey||V.ctrlKey)&&(V.preventDefault(),$e())},ut=V=>{var es,fl;const We=Array.from(((es=V.clipboardData)==null?void 0:es.files)??[]);if(We.length>0){V.preventDefault(),rt(We);return}const Ke=typeof((fl=V.clipboardData)==null?void 0:fl.getData)=="function"?V.clipboardData.getData("text/plain"):"";if(Ke==="")return;const Mt=V.currentTarget,Be=Mt.selectionStart??P,un=Mt.selectionEnd??Be,ds=$.slice(0,Be)+$.slice(un);if(Ke.length>r3){V.preventDefault();const ki=new File([Ke],"pasted-text.txt",{type:"text/plain"}),[na]=rt([ki]),Qo=Ke.replace(/\n$/,"").split(`
121
+ `).length,Ni=`${Qo} ${Qo===1?"line":"lines"} · ${Math.ceil(Ke.length/1024)} KB`;D(Jo=>Jo.map(ml=>ml.key===na?{...ml,detail:Ni}:ml)),ds!==$&&Pt({value:ds,caret:Be}),se({kind:"long",key:na,text:Ke,caret:Be});return}if(m3(Ke)&&!Mc(ds,Be)){V.preventDefault();const ki=p3(Ke),na=g3(ds,Be,Ke,ki);se({kind:"fenced",lang:ki,block:na.value.slice(Be,na.caret),text:Ke}),Pt(na)}},Bn=()=>{if(B){if(B.kind==="fenced"){const V=$.indexOf(B.block);V>=0&&Pt({value:$.slice(0,V)+B.text+$.slice(V+B.block.length),caret:V+B.text.length})}else{tt(B.key);const V=Math.min(B.caret,$.length);Pt({value:$.slice(0,V)+B.text+$.slice(V),caret:V+B.text.length})}se(null)}},Sn=R.filter(V=>V.state==="failed"),Zn=Sn.length,Ws=j7({conversationId:x??null,onNotice:L,onText:(V,We)=>{const Ke=$.trim()===""?V:`${$.replace(/\s+$/,"")} ${V}`;if(We){$e(Ke);return}Rn(Ke),je<0&&Ft(Ke)}}),Pn=Ws.state!=="idle",bi=d.useRef(!1);d.useEffect(()=>{var V;bi.current&&!Pn&&((V=X.current)==null||V.focus()),bi.current=Pn},[Pn]);const sr=Ee!==null&&!Pn&&!n,$r=cy($,P),Mn=Mc($,P),At=x3($).map(V=>xe.find(We=>We.handle.toLowerCase()===V)).filter(V=>!!V),hl=Me!==null&&((cn=bT($))==null?void 0:cn.handle)===Me.toLowerCase(),rp=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform||navigator.userAgent),dk=V=>V.group==="Borrow"?hl?`borrows ${V.name} for this message`:`${i} asks them`:V.group==="In this room"?"is asked in this room":`${i} asks them`,Ea=Zn>0?Zn===1&&((rd=Sn[0])!=null&&rd.error)?Sn[0].error:`${Zn} files failed to upload and will not be sent`:M,sd=Ea??(s||sr?null:$r?"Enter continues the list · Enter on an empty item ends it · Tab indents":Mn?`In a code block Enter adds a line · ${rp?"⌘":"Ctrl+"}Enter sends`:At.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"cv-chip",...At[0].accent,children:["@",At[0].handle]})," ",dk(At[0]),At.length>1?` · and ${At.length-1} more`:""]}):$!==""?"Enter sends, Shift+Enter for a new line":null),Aa=y??(s?`${i} is working…`:p?"Message the room · @ to ask someone":v&&Ce?`Message ${i} · @ to mention, / for commands`:`Message ${i}`),Go=d.useMemo(()=>xe.map(V=>({handle:V.handle,accent:V.accent})),[xe]),Yo=V=>O(V.selectionStart??V.value.length);return t.jsxs("div",{className:"wb-composer cv","data-testid":"composer","data-slim":b||void 0,"data-phone":J?"true":void 0,"data-busy":$.trim()!==""||vn||Pn?"true":void 0,children:[t.jsxs("div",{className:"cv-anchor",children:[sr&&Ee==="mention"?t.jsx(p7,{id:q,items:Ie,active:qe,onPick:Oe,phone:J,maxHeight:ht}):null,sr&&Ee==="slash"?t.jsx(g7,{id:q,items:de,active:qe,onPick:V=>it(V,!1),phone:J,query:(ve==null?void 0:ve.query)??"",maxHeight:ht}):null,t.jsxs("div",{ref:K,className:"wb-composer-box cv-box","data-focused":_||Pn,"data-disabled":n,"data-listening":Pn||void 0,children:[R.length>0?t.jsx("div",{className:"wb-composer-files",role:"list","aria-label":"Files to send",children:R.map(V=>t.jsx("span",{role:"listitem",children:t.jsx(ed,{name:V.filename,mime:V.mime,sizeBytes:V.sizeBytes,thumbnail:V.thumbnail,state:V.state,error:V.error,onRemove:()=>tt(V.key),...m&&V.state==="ready"&&V.uploaded?{onOpen:()=>m(T7(V.uploaded))}:{},size:"sm",detail:V.detail})},V.key))}):null,t.jsxs("label",{className:"sr-only",htmlFor:rj,children:["Message ",i]}),t.jsxs("div",{className:"cv-field",hidden:Pn,children:[t.jsxs("div",{className:"cv-paint","aria-hidden":"true","data-testid":"composer-paint",children:[m7($,Go),t.jsx("span",{className:"cv-tail",children:sj})]}),t.jsx("textarea",{id:rj,ref:X,value:$,rows:1,spellCheck:!1,placeholder:Aa,"aria-controls":sr?q:void 0,"aria-expanded":sr?!0:void 0,"aria-autocomplete":xe.length>0||Ce?"list":void 0,"aria-activedescendant":sr&&qe>=0?pb(q,qe):void 0,onChange:V=>{I(V.target.value),Yo(V.target),ne(!1),ye(0),je<0&&Ft(V.target.value)},onSelect:V=>Yo(V.currentTarget),onFocus:()=>Y(!0),onBlur:()=>Y(!1),onKeyDown:jt,onPaste:ut,disabled:n,hidden:Pn})]}),Pn?t.jsx(y7,{voice:Ws}):null,B&&!Pn?t.jsxs("div",{className:"cv-note",role:"status",children:[t.jsx("span",{className:"cv-note-icon",children:t.jsx(ie,{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 · ",yT(B.lang)]}):t.jsx(t.Fragment,{children:"Long paste, attached as a file"})}),t.jsx(E,{size:"sm",variant:"ghost",onClick:Bn,children:B.kind==="fenced"?"Undo":"Put it in the message"})]}):null,t.jsxs("div",{className:"wb-composer-row",hidden:Pn,children:[t.jsx("input",{ref:G,type:"file",multiple:!0,hidden:!0,"data-testid":"file-input",onChange:V=>{rt(V.target.files),V.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 V;return(V=G.current)==null?void 0:V.click()},disabled:n,children:t.jsx(ie,{name:"clip"})}),t.jsx(w7,{disabled:n,voice:Ws}),J?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:()=>{L(null),W(!0),S7().then(V=>{var We;V&&(rt([V]),(We=X.current)==null||We.focus())}).catch(V=>L(V instanceof Error?V.message:String(V))).finally(()=>W(!1))},disabled:n||U,children:t.jsx(ie,{name:"camera"})}),o&&!J?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(oC,{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(oC,{model:o})]}):null,f?t.jsxs("button",{type:"button",className:"ui-icon-btn wb-composer-thinking","data-size":"sm","aria-label":"Thinking","aria-pressed":Hd(h),disabled:n||s,title:s?`Thinking: ${Hd(h)?"on":"off"} — wait for ${i} to finish to change it`:`Thinking: ${Hd(h)?"on":"off"}`,onClick:()=>f(Hd(h)?"off":"on"),children:[t.jsx(ie,{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:[J?null:t.jsx("span",{className:"wb-composer-chip-lead",children:"Use my "}),"Chrome"]})]}):null,N?t.jsx("button",{type:"button",className:"ui-icon-btn wb-read-aloud","data-size":"sm","aria-label":"Read replies aloud","aria-pressed":!!w,title:w?"Replies are read aloud. Click to stop.":"Read replies aloud, through the voice chosen in Settings → Speech",onClick:()=>N(!w),children:t.jsx(ie,{name:"speaker"})}):null,t.jsx("span",{className:"wb-hint cv-hint","data-shown":!!sd&&(!J||Ea!==null),"data-tone":Zn>0||M!==null?"critical":void 0,children:J&&Ea===null?null:sd}),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:xn?"Waiting for the upload to finish":s?`Send — ${i} picks it up between steps`:"Send",onClick:()=>$e(),disabled:!Te,children:t.jsx(ie,{name:"send"})})]})]})]}),Xn?t.jsx("p",{className:"cv-wait",role:"status","data-testid":"files-wait",children:C7(i,R.length)}):null]})});function $7(e){const s=e.slice(e.lastIndexOf("/")+1).replace(/[:@].*$/,"").replace(/^claude-/,"").replace(/-\d{8}$/,"");return s===""?e:s}function oC({model:e}){const n=$7(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 Hd(e){return(e??"on")==="on"}function T7(e){return{type:"attachment",artifactId:e.artifactId,filename:e.filename,mime:e.mime,kind:e.kind,sizeBytes:e.sizeBytes}}function wP({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(E,{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:I7(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 I7(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 R7(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 P7(e,n,s){return e?[...DR({messages:e.messages,descriptors:[],...s?{awaiting:new Map(s)}:{}}).filter(a=>a.source==="approval").map(a=>({approvalId:a.props.approvalId,toolUseId:a.id})),...yP(e,n)]:[]}function yP(e,n){return((e==null?void 0:e.delegatedApprovals)??[]).map(s=>({approvalId:s.approvalId,toolUseId:s.toolUseId??"",askedBy:R7(s.chain,n)}))}function cC(e){return e instanceof he||e instanceof Error?e.message:String(e)}function bP({conversation:e,conversationId:n,agentId:s,now:r,refresh:a,onRunStarted:i,onError:l,navigate:o}){const[c,u]=d.useState(null),[h,f]=d.useState([]),[m,p]=d.useState(!1),v=((e==null?void 0:e.offers)??[]).filter(j=>!h.includes(j.id)&&Date.parse(j.expiresAt)>r),g=j=>{var w;const x=v.find(N=>N.id===j);if(((w=x==null?void 0:x.handoff)==null?void 0:w.kind)==="install"){o(cB(x.handoff.package));return}l(null),u(j),f(N=>[...N,j]),T.takeOffer(j,n??void 0).then(N=>{if(N.agentId&&N.agentId!==s){o(lt(N.agentId,N.conversationId??null));return}N.runId&&i(),n&&a(n)}).catch(N=>{f(y=>y.filter(b=>b!==j)),l(cC(N)),n&&a(n)}).finally(()=>u(null))},k=j=>{const x=e==null?void 0:e.question;x&&(l(null),p(!0),i(),Qe.answerQuestion(x.id,j).then(()=>{if(n)return a(n)}).catch(w=>l(cC(w),!0)).finally(()=>p(!1)))};return{openOffers:v,takingOffer:c,takeOffer:g,answeringQuestion:m,answerQuestion:(j,x)=>k({answer:j,...x?{optionId:x}:{}}),skipQuestion:()=>k({answer:"",skipped:!0})}}function kP({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 M7(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 O7(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 D7(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 ${O7(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(M7(n,r))return{text:`${o} · your next message starts a fresh one`,title:l,tone:"note"};const c=s?Ye(s,r):"";return{text:c===""?o:`${o} · started ${c}`,title:s?`Started ${mt(s,a)}. ${l}`:l,tone:"quiet"}}function L7({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(Gt,{summary:"Carried over from the previous conversation",children:[t.jsx("p",{className:"wb-carryover-text",children:e}),t.jsxs(re,{align:"end",children:[a?t.jsx("span",{className:"critical",role:"alert",children:a}):null,t.jsx(E,{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 NP(e){return e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function SP(e,n){return e.members.map(s=>n.find(r=>r.id===s)).filter(s=>s!==void 0)}function F7(e,n){var a;const s=SP(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 _7(){return t.jsx("span",{className:"ui-avatar group-gone-face","aria-hidden":"true",children:"?"})}function z7({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(v=>v!==e.coordinator)],u=e.members.length>2,h=Py(n).filter(v=>!e.members.includes(v.id)),f=!n.some(v=>v.id===e.coordinator),m=async v=>{i(!0),o(null);try{r(await Qe.updateGroup(e.id,v))}catch(g){o(g instanceof he?g.message:String(g))}finally{i(!1)}},p=v=>void m({members:e.members.filter(g=>g!==v)});return t.jsxs(Je,{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."]}),f?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(dt,{children:c.map(v=>{const g=n.find(j=>j.id===v),k=v===e.coordinator;return g?t.jsx(ot,{lead:t.jsx(an,{agents:n,id:v}),title:g.name,sub:g.description,side:t.jsxs(t.Fragment,{children:[k?t.jsx(Se,{tone:"accent",children:"Coordinator"}):null,f&&g.available?t.jsx(E,{size:"sm",disabled:a,onClick:()=>void m({coordinator:v}),children:"Make coordinator"}):null,t.jsx(Jn,{label:`More for ${g.name}`,...k?{note:"Coordinates the group"}:{},items:[!k&&g.available&&{label:"Make coordinator",hint:"Reads your requests, answers for the room",onSelect:()=>void m({coordinator:v})},{label:`Open ${g.name}'s page`,onSelect:()=>{window.location.hash=Dt(v)}},!k&&"separator",!k&&{label:"Remove from group",hint:u?"What it said stays":"A group needs two",tone:"critical",onSelect:()=>{u?p(v):o("A group needs two agents. Add someone before taking this one out.")}}]})]})},v):t.jsx(ot,{lead:t.jsx(_7,{}),title:t.jsx("span",{className:"group-gone-id",children:v}),sub:t.jsxs("span",{className:"group-gone-line",children:["No longer in buddi",k?" · was the coordinator":u?"":" · add a member to take it out"]}),side:u&&!k?t.jsx(E,{size:"sm",disabled:a,onClick:()=>p(v),children:"Remove"}):void 0},v)})}),t.jsxs("div",{className:"group-add",children:[t.jsx("h3",{className:"group-add-title",children:"Add a member"}),h.length>0?t.jsx(dt,{children:h.map(v=>t.jsx(ot,{lead:t.jsx(an,{agents:n,id:v.id,size:"sm"}),title:v.name,sub:v.description,side:t.jsx(E,{size:"sm",disabled:a,onClick:()=>void m({members:[...e.members,v.id]}),children:"Add"})},v.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 U7({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 Qe.updateGroup(e.id,{name:r.trim()}))}catch(f){c(f instanceof he?f.message:String(f)),l(!1)}}};return t.jsx(Rt,{title:"Rename group",onClose:n,foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:!u,onClick:()=>void h(),children:i?"Renaming…":"Rename"})]}),children:t.jsx("form",{onSubmit:f=>{f.preventDefault(),h()},children:t.jsxs(ue,{children:[t.jsx(oe,{label:"Name",hint:"What this team is for: Household finances, The move, Tax season.",children:t.jsx("input",{value:r,autoFocus:!0,maxLength:80,onFocus:f=>f.currentTarget.select(),onChange:f=>a(f.target.value)})}),o?t.jsx(Q,{tone:"critical",children:o}):null]})})})}function CP(e){const[n,s]=d.useState(null);return d.useEffect(()=>{let r=!0;return Qe.group(e).then(a=>{var i;r&&s(((i=a.history)==null?void 0:i.conversations)??null)}).catch(()=>{}),()=>{r=!1}},[e]),n}function B7(e){return e===null?"Its conversations":e===0?"Nothing has been said yet, and its next conversation":`Its ${e} ${e===1?"conversation":"conversations"}`}function W7({group:e,onClose:n,onCleared:s}){const r=CP(e.id),[a,i]=d.useState(!1),[l,o]=d.useState(null),c=async()=>{i(!0),o(null);try{await Qe.clearGroup(e.id),s()}catch(h){o(h instanceof he?h.message:String(h)),i(!1)}},u=r===0;return t.jsxs(Rt,{title:`Clear the history of ${e.name}?`,onClose:n,foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx(E,{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.":`${B7(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 H7({group:e,agents:n,onClose:s,onDeleted:r}){const a=CP(e.id),[i,l]=d.useState(!1),[o,c]=d.useState(null),u=SP(e,n).map(m=>m.name),h=async()=>{l(!0),c(null);try{const{undoUntil:m}=await Qe.deleteGroup(e.id);r(m)}catch(m){c(m instanceof he?m.message:String(m)),l(!1)}},f=a===null?"its conversations":a===0?"nothing said yet":`its ${a} ${a===1?"conversation":"conversations"}`;return t.jsxs(Rt,{title:`Delete ${e.name}?`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx(E,{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 ",f," and what it remembers."," ",u.length>0?`${NP(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 uC(){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 K7({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:f,onOpenCanvas:m,onCloseCanvas:p,newConversationSignal:v,requestedConversationId:g,requestedTab:k,onConversationOpened:j}){var Ek,Ak,$k,Tk,Ik,Rk,Pk,Mk,Ok,Dk,Lk,Fk;const x=Bm(),[w,N]=d.useState([]),[y,b]=d.useState(null),[S,C]=d.useState(null),[A,$]=d.useState(null),[I,P]=d.useState([]),[O,R]=d.useState([]),[D,U]=d.useState(null),[W,M]=d.useState(!1),[L,_]=d.useState(new Map),[Y,B]=d.useState(null),se=u7(y??null),[G,X]=d.useState(()=>Date.now());d.useEffect(()=>{const ee=setInterval(()=>X(Date.now()),6e4);return()=>clearInterval(ee)},[]);const[K,J]=d.useState([]),[q,ce]=d.useState(!1),xe=d.useRef(0),Me=d.useRef(null),[H,ne]=d.useState(!1),Z=d.useRef(v??0),ye=d.useRef(s),Ce=d.useRef({agentId:s,conversationId:y});Ce.current={agentId:s,conversationId:y};const ke=se.closed,[we,ve]=d.useState(null),[Ie,Re]=d.useState(null),[de,Ee]=d.useState(()=>Date.now()),[ze,qe]=d.useState(jV),ht=d.useRef(null),[le,je]=d.useState(null),[et,ft]=d.useState(!1),[Et,Ft]=d.useState(null),[Pt,Rn]=d.useState(bR),zn=d.useRef(Pt);zn.current=Pt;const Yt=d.useRef(null),[Un,xn]=d.useState(null),vn=d.useCallback(ee=>{Rn(ee),kR(ee),ee||Uo()},[]),[Xn,_t]=d.useState(null),[Te,rt]=d.useState(null);d.useEffect(()=>{if(!s)return;const ee=s3(s);ee&&Ft({text:ee,at:Date.now()})},[s]);const De=a?`group:${a.id}`:s??null,tt=[...n.top,...n.middle,...n.bottom],F=tt.find(ee=>ee.id===s)??null,Fe=me(()=>T.providerAccounts(),[]),Ct=a?a.members.map(ee=>tt.find(fe=>fe.id===ee)).filter(ee=>!!ee):[],[on,$e]=d.useState(null),Oe=W?on??s??null:null;d.useEffect(()=>{o==null||o(Oe)},[Oe,o]),d.useEffect(()=>()=>o==null?void 0:o(null),[o]),d.useEffect(()=>{let ee=!1;return Qe.views().then(fe=>{ee||N(fe.views??[])}).catch(()=>{}),()=>{ee=!0}},[]),d.useEffect(()=>{if(!s)return;const ee=ye.current===s;if(ye.current=s,ee&&g&&g===Ce.current.conversationId)return;let fe=!1;return b(null),C(null),$(null),P([]),ve(null),M(!1),B(null),J([]),Ea(null),ne(!1),je(null),g?(g!=="new"?b(g):$(De),()=>{fe=!0}):((a?Qe.groupConversations(a.id):Qe.conversations(s)).then(Pe=>{if(fe)return;const at=[...Pe.conversations??[]].sort(V7)[0];at?(b(at.id),j==null||j(s,at.id)):$(De)}).catch(()=>{fe||$(De)}),()=>{fe=!0})},[s,a==null?void 0:a.id,De,g,j]);const it=d.useCallback(ee=>Qe.conversation(ee).then(fe=>{if(Ce.current.conversationId===ee){if(fe.agentId!==Ce.current.agentId)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(fe),P(Pe=>Pe.filter(at=>!wg(fe,at)))}}).catch(fe=>{Ce.current.conversationId===ee&&ve(Ia(fe))}),[]);d.useEffect(()=>{if(!y)return;let ee=!1;return _(new Map),R([]),Qe.conversation(y).then(fe=>{if(!ee){if(fe.agentId!==s)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(fe),P(Pe=>Pe.filter(at=>!wg(fe,at)))}}).catch(fe=>{ee||ve(Ia(fe))}),()=>{ee=!0}},[y,s]),d.useEffect(()=>{if(!y)return;let ee=!1;const fe=window.setInterval(()=>{Qe.conversation(y).then(Pe=>{ee||Pe.agentId!==Ce.current.agentId||(C(Pe),P(at=>at.filter(Ge=>!wg(Pe,Ge))))}).catch(()=>{})},3e3);return()=>{ee=!0,window.clearInterval(fe)}},[y,s]),d.useEffect(()=>{if(!y)return;const ee=Em({url:Qe.streamUrl(y),onEvent:fe=>{var Pe,at;switch(fe.name){case"run.started":Yt.current=null,M(!0),U(null),$e(On(fe.data.agentId));break;case"live":{const Ge=On(fe.data.runId)??"",Xe=Number(fe.data.turn??0),Ue=fe.data.kind==="thinking"?"thinking":"text",ts=On(fe.data.text)??"",sa=Date.now();if(Ue==="text"){const Tr=Yt.current;Yt.current=Tr&&Tr.runId===Ge&&Tr.turn===Xe?{...Tr,text:Tr.text+ts}:{runId:Ge,turn:Xe,text:ts}}U(Tr=>{const gl=Tr&&Tr.runId===Ge&&Tr.turn===Xe?Tr:{runId:Ge,turn:Xe,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return Ue==="thinking"?{...gl,thinking:gl.thinking+ts,thinkingStartedAt:gl.thinkingStartedAt??sa}:{...gl,text:gl.text+ts,textStartedAt:gl.textStartedAt??sa}});break}case"live.snapshot":{const Ge=On(fe.data.runId)??"",Xe=Number(fe.data.turn??0),Ue=On(fe.data.text)??"",ts=On(fe.data.thinking)??"",sa=Number(fe.data.startedAt??Date.now());Yt.current={runId:Ge,turn:Xe,text:Ue},U({runId:Ge,turn:Xe,text:Ue,thinking:ts,thinkingStartedAt:ts?sa:null,textStartedAt:Ue?sa:null,settled:!1});break}case"live.settle":{const Ge=On(fe.data.runId)??"",Xe=Number(fe.data.turn??0);if(fe.data.retracted===!0){((Pe=Yt.current)==null?void 0:Pe.runId)===Ge&&Yt.current.turn===Xe&&(Yt.current=null),U(Ue=>Ue&&Ue.runId===Ge&&Ue.turn===Xe?null:Ue);break}U(Ue=>Ue&&Ue.runId===Ge&&Ue.turn===Xe?{...Ue,settled:!0}:Ue);break}case"tool.called":{const Ge=On(fe.data.toolUseId)??On(fe.data.id),Xe=On(fe.data.name)??On(fe.data.tool)??"tool";Ge&&R(Ue=>[...Ue.filter(ts=>ts.toolUseId!==Ge),{toolUseId:Ge,name:Xe,startedAt:Date.now()}]);break}case"tool.result":{const Ge=On(fe.data.toolUseId)??On(fe.data.id);Ge&&R(Xe=>Xe.filter(Ue=>Ue.toolUseId!==Ge)),it(y);break}case"reaction":it(y);break;case"message.appended":it(y).then(()=>{U(Ge=>Ge!=null&&Ge.settled?null:Ge)});break;case"awaiting-approval":{const Ge=On(fe.data.approvalId)??On(fe.data.actionId),Xe=On(fe.data.toolUseId);Ge&&Xe&&_(Ue=>new Map(Ue).set(Xe,Ge)),R(Ue=>Ue.filter(ts=>ts.toolUseId!==Xe)),it(y);break}case"run.finished":{M(!1),R([]),U(null),$e(null);const Ge=On(fe.data.message);ve(Ge??null);const Xe=((at=Yt.current)==null?void 0:at.text.trim())??"";Yt.current=null,!Ge&&Xe!==""&&zn.current&&kf(Xe,y).then(Ue=>{Ue&&xn(Ue)}),it(y);break}}}});return()=>ee.close()},[y,it]),d.useEffect(()=>{const ee=window.setInterval(()=>Ee(Date.now()),O.length===0?6e4:1e3);return()=>window.clearInterval(ee)},[O.length]);const jt=me(()=>s&&y?T.browser({agentId:s,conversationId:y}):Promise.resolve(void 0),[s,y],1500),ut=jt.error?void 0:jt.data,Bn=ut!=null&&ut.session&&ut.session.agentId===s&&ut.session.conversationId===y?ut:void 0,Sn=ZG(Bn,s,y),Zn=(Sn==null?void 0:Sn.id)??null,[Ws,Pn]=d.useState(null),bi=Bn==null?void 0:Bn.mode;d.useEffect(()=>{Sn&&s&&y&&Pn({agentId:s,conversationId:y,tab:e7(Sn)})},[Zn,bi,s,y]);const sr=Ws&&Ws.agentId===s&&Ws.conversationId===y&&!ke.includes(Ws.tab.id)?Ws.tab:null,$r=nj(S==null?void 0:S.question),Mn=Sn?null:t7(ut,y??null,($r==null?void 0:$r.kind)==="paused"),At=Sn??Mn??sr,hl=(Ek=ut==null?void 0:ut.routes)==null?void 0:Ek.find(ee=>ee.kind==="chrome"),rp=!a&&y&&(hl!=null&&hl.allowed)&&hl.paired?{on:(ut==null?void 0:ut.pin)==="chrome",onChange:ee=>{T.browserPin(y,ee?"chrome":"auto").catch(()=>{}).finally(jt.reload)}}:void 0,[dk,Ea]=d.useState(null),sd=d.useMemo(()=>yK({messages:(S==null?void 0:S.messages)??[],descriptors:w}),[S,w]),Aa=NV(sd,y??null),Go=CV(a?null:s),Yo=d.useMemo(()=>SV((S==null?void 0:S.messages)??[]),[S]),qo=d.useRef([]),cn=d.useMemo(()=>{const ee=DR({messages:(S==null?void 0:S.messages)??[],descriptors:w,awaiting:L,served:Aa.served,...At?{folded:kh}:{},gathered:i7,quiet:nC,titles:sC});qo.current=ee;const fe=Xe=>Y!==null&&(Xe.id===Y||(Xe.versions??[]).some(Ue=>Ue.id===Y)),Pe=[];for(const Xe of se.ready?ee:ee.filter(Ue=>Ue.source==="approval")){if(Xe.source!=="approval"&&ke.includes(zd(Xe))&&!fe(Xe))continue;const Ue=hK(Xe,G);Ue==="gone"&&!fe(Xe)||Pe.push(Ue==="parked"?{...Xe,parked:!0}:Xe)}const at=Y?RS(Pe,Y):null;at&&(at.props={...at.props,focus:Y});const Ge=Y&&!at?AS(Pe,Y):null;if(Ge&&(Ge.focus=Y),Y&&!at&&!Ge&&!ke.includes(Y)&&!Pe.some(Xe=>Xe.id===Y)){const Xe=SK((S==null?void 0:S.messages)??[],Y,{redactInputOf:kh,resultOf:nC,titles:sC});Xe&&!kh.has(Xe.tool)&&Pe.push(Xe)}At&&Pe.push(At);for(const Xe of K)Pe.push(B8(Xe));return Go&&Pe.unshift(EV(Go,Yo)),le?[...Pe,AV(le)]:Pe},[S,w,L,le,Zn,At==null?void 0:At.title,Y,se.closed,se.ready,G,y,K,Aa.served,Go,Yo]),rd=d.useMemo(()=>{var fe;const ee=[];for(const Pe of(S==null?void 0:S.messages)??[]){if(Pe.role!=="user"||Pe.speaker&&Pe.speaker!=="owner")continue;const at=(fe=Pe.blocks.find(Ge=>Ge.type==="text"))==null?void 0:fe.text.trim();at&&ee.unshift(at)}return ee},[S]),V=d.useMemo(()=>cn.filter(ee=>ee.source==="approval"),[cn]),We=V.at(-1)??null,Ke=d.useMemo(()=>[...V.map(ee=>({approvalId:ee.props.approvalId,toolUseId:ee.id})),...yP(S,tt)],[V,S==null?void 0:S.delegatedApprovals]),Mt=d.useMemo(()=>{for(let ee=cn.length-1;ee>=0;ee-=1){const fe=cn[ee];if(fe!=null&&fe.substantial)return zd(fe)}return null},[cn]),Be=(Y?((Ak=RS(cn,Y))==null?void 0:Ak.id)??(($k=AS(cn,Y))==null?void 0:$k.id):null)??Y,un=se.touch;d.useEffect(()=>{Be&&cn.some(ee=>ee.id===Be)&&un(Be)},[Be,un]);const ds=d.useMemo(()=>{const ee=(S==null?void 0:S.messages)??[];for(let fe=ee.length-1;fe>=0;fe-=1){const Pe=ee[fe];if((!Pe.speaker||Pe.speaker==="owner")&&OR(Pe))return Pe.at??null}return null},[S]),es=d.useRef(null),fl=((Tk=cn.filter(ee=>(ee.source!=="browser"||ee.pinned===!0)&&ee.id!==Qv).at(-1))==null?void 0:Tk.id)??((Ik=cn.filter(ee=>ee.id!==Qv).at(-1))==null?void 0:Ik.id)??null;d.useEffect(()=>{if(Mt&&Mt!==es.current){es.current=Mt,B(Mt);return}Y===null&&fl&&B(fl)},[Mt,Y,fl]);const ki=d.useRef(Aa.live);d.useEffect(()=>{const ee=ki.current;ki.current=Aa.live;const fe=[...Aa.live].filter(Ge=>!ee.has(Ge));if(fe.length===0||We||Y!==null&&Y!==es.current)return;const at=[...cn].reverse().find(Ge=>Ge.source==="descriptor"&&Ge.renderer==="preview"&&Ge.props.target!==null&&fe.includes(Zl(Ge.props.target)));at&&B(at.id)},[Aa.live,cn,We,Y]);const na=d.useRef(null);d.useEffect(()=>{Zn!==na.current&&(na.current=Zn,Zn&&!We&&B(Zn))},[Zn,We]);const Qo=d.useRef(null),Ni=k==="browser"?(At==null?void 0:At.id)??null:null;d.useEffect(()=>{!Ni||Qo.current===Ni||(Qo.current=Ni,B(Ni))},[Ni]);const Jo=(At==null?void 0:At.id)??null;d.useEffect(()=>{!Jo||!Y||tC((S==null?void 0:S.messages)??[],Y)!==null&&(Ea(Y),B(Jo))},[Jo,Y,S]);const ml=ee=>{J(fe=>fe.some(Pe=>Pe.artifactId===ee.artifactId)?fe:[...fe,ee]),B(jh(ee.artifactId)),h&&(m==null||m())},ad=!a&&F&&!F.available?MI(F):null,hk=a?t.jsx("span",{className:"wb-group-stack","aria-hidden":"true",children:a.members.slice(0,2).map(ee=>{const fe=tt.find(Pe=>Pe.id===ee);return t.jsx($m,{className:"wb-group-chip",id:ee,name:(fe==null?void 0:fe.name)??"?",face:fe,initials:1},ee)})}):null,Si=a&&tt.length>0?F7(a,tt):null,fk=(Si==null?void 0:Si.kind)==="coordinator",mk=Sv(a?null:F),pk=Ke.length>0||!!(S!=null&&S.question),ap=d.useRef(pk);ap.current=pk,d.useEffect(()=>{if(ap.current||uC())return;const ee=window.requestAnimationFrame(()=>{var fe;ap.current||uC()||(fe=Me.current)==null||fe.focus()});return()=>window.cancelAnimationFrame(ee)},[s,a==null?void 0:a.id,y,v]);const uD=F&&Te===F.id?Xn:(F==null?void 0:F.thinking)??null,dD=ee=>{if(!F)return;const fe=F.id;rt(fe),_t(ee),T.setAgentEngine(fe,{thinking:ee}).catch(Pe=>{rt(null),ve(Pe instanceof he?Pe.message:String(Pe))})},ip=(ee,fe)=>{if(!s)return;const Pe=a?null:J7(ee,tt,s);if(Pe){ve(null),Qe.send(Pe.agent.id,{text:Pe.rest,attachmentIds:fe.map(Ue=>Ue.artifactId)}).then(Ue=>{window.location.hash=lt(Pe.agent.id,Ue.conversationId)}).catch(Ue=>ve(Ia(Ue)));return}const at=fe.map(Ue=>Ue.artifactId),Ge=W,Xe={id:`optimistic:${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[...ee.trim()===""?[]:[{type:"text",text:ee}],...fe.map(Ue=>({type:"attachment",artifactId:Ue.artifactId,filename:Ue.filename,mime:Ue.mime,kind:Ue.kind,sizeBytes:Ue.sizeBytes}))],...Ge?{speaker:zR}:{}};P(Ue=>Ge?[...Ue,Xe]:[Xe]),ve(null),Re(null),M(!0),(a?Qe.sendToGroup(a.id,{...y?{conversationId:y}:{},text:ee,attachmentIds:at}):Qe.send(s,{...y?{conversationId:y}:{},text:ee,attachmentIds:at})).then(async Ue=>{Ce.current.agentId!==s||Ce.current.conversationId!==y||(Re(Ue.rolledOver===!0?"(New thread — the room had grown long. Where it stopped carries over as a summary.)":null),Ue.conversationId!==y?(C(null),b(Ue.conversationId)):await it(Ue.conversationId),Ue.queued===!0&&P(ts=>ts.filter(sa=>sa.id!==Xe.id)),j==null||j(s,Ue.conversationId))}).catch(Ue=>{P(ts=>ts.filter(sa=>sa.id!==Xe.id)),ve(Ia(Ue)),M(!1)})},{openOffers:hD,takingOffer:fD,takeOffer:mD,answeringQuestion:gk,answerQuestion:xk,skipQuestion:pD}=bP({conversation:S,conversationId:y??null,agentId:(F==null?void 0:F.id)??null,now:de,refresh:it,onRunStarted:()=>{Re(null),M(!0)},onError:(ee,fe)=>{ve(ee),fe&&M(!1)},navigate:ee=>{window.location.hash=ee}}),gD=()=>{if(s){if(le){je(null);return}ft(!0),T.agentProfile(s).then(ee=>{je(ee),B(Jv(ee.id)),h&&(m==null||m())}).catch(ee=>ve(Ia(ee))).finally(()=>ft(!1))}},xD=ee=>{Ft({text:ee.prompt,at:Date.now()}),l(ee.agentId),h&&(p==null||p())},vk=()=>{y&&Qe.cancel(y).catch(ee=>ve(Ia(ee))).finally(()=>{M(!1),R([])})},vD=(ee,fe)=>{if(ve(null),ee==="stop"){vk();return}if(ee==="use"){const Pe=fe.replace(/^@/,"").toLowerCase(),at=tt.find(Ge=>Ge.handle.toLowerCase()===Pe||Ge.id===Pe);if(!at){Re(Pe?`No agent called @${Pe}.`:"Say who: /use @handle.");return}Re(null),l(at.id);return}if(ee==="new"){const Pe=tt.find(at=>at.roles.includes(jr));if(!Pe){Re("There is no agent here that makes agents.");return}fe.trim()&&Wu(Pe.id,`I'd like a teammate for this: ${fe.trim()}`),l(Pe.id);return}T.quiet(fe).then(Pe=>Re(Pe.text)).catch(Pe=>ve(Ia(Pe)))},id=d.useCallback(()=>{if(b(null),C(null),P([]),M(!1),ve(null),Re(null),R([]),_(new Map),B(null),J([]),Ea(null),es.current=null,a){Qe.startGroupConversation(a.id).then(({conversationId:ee})=>{b(ee),s&&(j==null||j(s,ee))}).catch(ee=>ve(Ia(ee)));return}$(De),s&&(j==null||j(s,"new"))},[s,a,De,j]);d.useEffect(()=>{v&&v!==Z.current&&(Z.current=v,id())},[v,id]);const jk=ee=>{y&&it(y),T.overview().catch(()=>{}),ee.state!=="pending"&&_(fe=>new Map([...fe].filter(([,Pe])=>Pe!==ee.id)))},jD=((Rk=tt.find(ee=>ee.id===r))==null?void 0:Rk.name)??null,wk=a?[]:y5(F,jD),yk=!(S&&S.conversationId===y)&&!(!y&&A!==null&&A===De),bk=yk?t.jsx("div",{className:"wb-chat-loading","data-testid":"chat-loading","aria-busy":"true"}):!a&&F?t.jsx(rR,{quiet:!0,still:!0,className:"wb-chat-field",children:t.jsxs("div",{className:"wb-chat-opening","data-testid":"chat-opening",children:[t.jsx(an,{agents:tt,id:F.id,size:"xl"}),t.jsx("h2",{className:"wb-chat-hello",children:`Hi, I'm ${F.name}.`}),t.jsx("p",{className:"wb-chat-intro",children:b5(F)}),wk.length>0?t.jsx("div",{className:"wb-starters",role:"group","aria-label":`Things to ask ${F.name}`,children:wk.map(ee=>t.jsx("button",{type:"button",className:"wb-starter",onClick:()=>{var fe;Ft({text:ee,at:Date.now()}),(fe=Me.current)==null||fe.focus()},children:ee},ee))}):null]})}):null,kk=ee=>{const fe=[];for(const Pe of ee)if(le&&Pe===Jv(le.id))je(null);else if(K.some(at=>jh(at.artifactId)===Pe))J(at=>at.filter(Ge=>jh(Ge.artifactId)!==Pe));else{const at=cn.find(Ge=>Ge.id===Pe);fe.push(at?zd(at):Pe)}fe.length>0&&se.close(fe),Y!==null&&(ee.includes(Y)||ee.includes(Be??""))&&B(null)},Nk=t.jsx(eV,{renderables:cn,activeId:Be,onActivate:B,onClose:ee=>kk([ee]),onCloseMany:kk,touched:se.touched,turnStartedAt:ds,timezone:e,onDecided:jk,onChangeAgent:xD,agents:tt,browserPanel:At?t.jsx(VG,{status:Bn,error:jt.error,reload:jt.reload,live:Sn!==null,agentName:(F==null?void 0:F.name)??"The agent",timezone:e,paused:Mn&&(ut!=null&&ut.stop)?ut.stop:null},At.id):null,browserMenu:At?t.jsx(qG,{status:ut,timezone:e,reload:jt.reload}):null,descriptors:w,grantedTools:a?Ct.flatMap(ee=>ee.tools??[]):(F==null?void 0:F.tools)??[],...F?{agentName:F.name}:{},loading:yk,...!a&&F?{face:t.jsx(an,{agents:tt,id:F.id,size:"xl"}),cardFace:t.jsx(an,{agents:tt,id:F.id,size:"sm"})}:{}}),Sk=(Mk=(Pk=[...(S==null?void 0:S.messages)??[],...I].find(ee=>ee.role==="user"))==null?void 0:Pk.blocks.find(ee=>ee.type==="text"))==null?void 0:Mk.text.trim(),Ck=Sk?Sk.split(`
122
+ `)[0]:"New conversation",pl=D7({lifetime:(S==null?void 0:S.lifetime)??null,startedAt:(S==null?void 0:S.startedAt)??null,now:de,timezone:e});return t.jsxs(t.Fragment,{children:[t.jsxs("section",{className:"wb-chat",ref:ht,style:h||ze===null?void 0:{[qv]:`${ze}px`},"data-sized":!h&&ze!==null?"true":void 0,"data-testid":"chat-column","data-dropping":q||void 0,onDragEnter:ee=>{Kd(ee)&&(ee.preventDefault(),xe.current+=1,ce(!0))},onDragOver:ee=>{Kd(ee)&&(ee.preventDefault(),ee.dataTransfer.dropEffect="copy")},onDragLeave:ee=>{Kd(ee)&&(xe.current=Math.max(0,xe.current-1),xe.current===0&&ce(!1))},onDrop:ee=>{var fe;Kd(ee)&&(ee.preventDefault(),xe.current=0,ce(!1),s&&((fe=Me.current)==null||fe.addFiles(ee.dataTransfer.files)))},children:[q?t.jsx("div",{className:"wb-drop","aria-hidden":"true",children:t.jsxs("div",{className:"wb-drop-card",children:[t.jsx(G7,{}),t.jsx("strong",{children:"Drop to attach"}),t.jsx("span",{children:F?`It goes with your next message to ${F.name}`:"Pick an agent first"})]})}):null,t.jsxs("header",{className:"wb-chat-head","data-testid":"chat-head",...!a&&F?Xi(Lo(F)):{},children:[t.jsxs("div",{className:"wb-head-row",children:[a?t.jsx("span",{className:"wb-head-face","aria-hidden":"true",children:hk}):F?t.jsx("a",{className:"wb-head-face",href:Dt(F.id),"aria-label":`${F.name}'s page`,children:t.jsx(an,{agents:tt,id:F.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:Ck,children:Ck}),t.jsx("span",{className:"wb-head-meta","data-tone":pl.tone,title:a?`${Ct.map(ee=>ee.name).join(", ")}. Coordinator: ${(F==null?void 0:F.name)??a.coordinator}.`:pl.title,children:a?`${Ct.map(ee=>ee.name).join(", ")} · ${pl.text}`:F?t.jsxs(t.Fragment,{children:[t.jsx("a",{className:"wb-head-name",href:Dt(F.id),title:`${F.name}'s page`,children:F.name})," ",t.jsxs("span",{className:"wb-head-handle",children:["@",F.handle]}),` · ${pl.tone==="quiet"&&pl.text==="New conversation"?`on ${x}`: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:()=>{ne(!1),id()},children:t.jsx(ie,{name:"plus",size:16})}),t.jsx("button",{className:"ui-icon-btn wb-head-more","aria-label":"History",title:"Earlier conversations","aria-expanded":H,"data-open":H?"true":void 0,disabled:!s,onClick:()=>ne(ee=>!ee),children:t.jsx(Y7,{})}),h?t.jsxs("button",{className:"ui-btn",onClick:m,disabled:cn.length===0,children:["Canvas",cn.length>0?` (${cn.length})`:""]}):null,a?t.jsx(dC,{disabled:!1,label:"More about this group",title:a.name,sub:NP(Ct.map(ee=>ee.name)),face:hk,items:[{label:"Members",hint:`${a.members.length} agents · ${F?`${F.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(dC,{disabled:!s,label:"More about this agent",title:(F==null?void 0:F.name)??"Agent",...F?{sub:`@${F.handle}`,face:t.jsx(an,{agents:tt,id:F.id,size:"sm"})}:{},items:[{label:le?"Close properties":"Properties",hint:"What this agent can do, on the Canvas",testId:"agent-properties",disabled:et,onSelect:gD},...F?[{label:"Set up",hint:"Identity, model and access",href:Dt(F.id,"setup")},{label:"Open agent page",hint:"Profile, activity and setup",href:Dt(F.id)}]:[]]})]}),u?t.jsx(LI,{agents:n,currentId:s,attention:c,onSelect:l,orientation:"horizontal",...Oe?{working:new Set([Oe])}:{}}):null]}),!a&&F?t.jsx(f7,{agentId:F.id},F.id):null,H&&s?t.jsx(l7,{agentId:s,...a?{groupId:a.id}:{},currentId:y,timezone:e,onNew:()=>{ne(!1),id()},onSelect:ee=>{if(ee===y){ne(!1);return}ne(!1),C(null),P([]),M(!1),B(null),ve(null),Re(null),J([]),b(ee),j==null||j(s,ee,!1)}}):null,s&&y?t.jsx(QG,{agentId:s,conversationId:y},`${s}:${y}`):null,we?t.jsx("div",{className:"wb-chat-notice",children:t.jsx(ae,{message:we})}):null,Ie?t.jsx("div",{className:"wb-chat-notice","data-testid":"chat-notice",children:Ie}):null,S!=null&&S.carriedOver?t.jsx(L7,{text:S.carriedOver,onDelete:async()=>{const ee=S.conversationId;await Qe.deleteCarryOver(ee),C(fe=>{if(!fe||fe.conversationId!==ee)return fe;const{carriedOver:Pe,...at}=fe;return at})}},S.conversationId):null,t.jsx(tb,{messages:[...(S==null?void 0:S.messages)??[],...I],live:O,now:de,working:W,partial:D,agents:tt,...S!=null&&S.runs?{runs:S.runs}:{},...s&&y?{onContinue:()=>ip("continue",[])}:{},...a?{speakers:tt,coordinatorId:a.coordinator}:{},...on?{workingAs:((Ok=tt.find(ee=>ee.id===on))==null?void 0:Ok.name)??on}:{},onOpenFile:ml,onReadAloud:(ee,fe)=>{xn(null),kf(fe,y??void 0,ee).then(Pe=>{Pe&&xn(Pe)})},onOpen:ee=>{if(At){const Pe=tC([...(S==null?void 0:S.messages)??[],...I],ee);if(Pe){Ea(Pe),B(At.id),h&&(m==null||m());return}}const fe=qo.current.find(Pe=>Pe.id===ee||(Pe.versions??[]).some(at=>at.id===ee));se.reopen(fe?[ee,zd(fe)]:[ee]),B(ee),h&&(m==null||m())},...F?{agentName:F.name,agentId:F.id}:{},...bk?{empty:bk}:{},emptyHint:a?`Give the team a task once; ${F?F.name:"the coordinator"} brings members in. @ addresses one of them.`:F?`Nothing here yet. Ask ${F.name} for something.`:"Loading agents…"}),t.jsx(kP,{offers:hD,disabled:fD!==null,onTake:mD}),Si?t.jsx("div",{className:"wb-composer-blocked","data-testid":"group-problem","data-kind":Si.kind,children:t.jsx(Q,{tone:fk?"warning":void 0,role:"status",children:t.jsxs("span",{children:[Si.text," ",t.jsx("button",{type:"button",className:"wb-link-btn",onClick:()=>i==null?void 0:i("members"),children:Si.action})]})})}):null,ad?t.jsx("div",{className:"wb-composer-blocked","data-testid":"composer-blocked",children:t.jsxs(Q,{tone:"warning",role:"status",children:[ad," ",t.jsx("a",{href:_e(mk.section),children:mk.label})]})}):Ke.length>0?t.jsx(QR,{approvals:Ke,timezone:e,now:de,version:S,onDecided:jk,onSay:ee=>ip(ee,[]),onOpenFull:ee=>{B(ee),h&&(m==null||m())}}):null,ad||Ke.length>0?null:S!=null&&S.question&&$r?t.jsx(jP,{card:$r,disabled:gk||W,onAnswer:xk,site:((Dk=ut==null?void 0:ut.needsOwner)==null?void 0:Dk.site)??((Fk=(Lk=ut==null?void 0:ut.page)==null?void 0:Lk.url)==null?void 0:Fk.replace(/^https?:\/\/(www\.)?([^/]+).*$/,"$2"))},S.question.id):S!=null&&S.question?t.jsx(wP,{question:S.question,disabled:gk||W,onAnswer:xk,onSkip:pD},S.question.id):null,ad||fk?null:t.jsxs("div",{hidden:Ke.length>0||!!(S!=null&&S.question),"data-testid":"composer-slot",children:[t.jsx(gb,{ref:Me,disabled:!s,running:W,onSend:ip,onStop:vk,agentName:a?a.name:(F==null?void 0:F.name)??"the agent",draft:Et,history:rd,threadKey:y??(a?`group:${a.id}`:s),model:a?null:(F==null?void 0:F.model)??null,chrome:rp,setupHref:a?null:F?Dt(F.id,"setup","brain"):null,thinking:uD,...!a&&F&&kT(NT(F,Fe.data))?{onThinking:dD}:{},...a?{mentions:Ct.map(ee=>({id:ee.id,handle:ee.handle,name:ee.name})),team:{agents:tt,selfId:""}}:s?{team:{agents:tt,selfId:s}}:{},onCommand:vD,onOpenFile:ml,conversationId:y??null,readAloud:Pt,onReadAloud:vn}),Un?t.jsx("p",{className:"wb-voice-note",role:"status",children:Un}):null]})]}),h?f?t.jsxs("div",{className:"wb-sheet",role:"dialog","aria-label":"Canvas",children:[t.jsxs("div",{className:"wb-sheet-head",children:[t.jsx("strong",{children:"Canvas"}),t.jsx("button",{className:"ui-btn",onClick:p,children:"Close"})]}),Nk]}):null:t.jsxs(t.Fragment,{children:[t.jsx(yV,{columnRef:ht,width:ze,onChange:qe}),Nk]})]})}function V7(e,n){return Date.parse(n.lastMessageAt??n.startedAt??n.createdAt??"")-Date.parse(e.lastMessageAt??e.startedAt??e.createdAt??"")}function On(e){return typeof e=="string"&&e!==""?e:null}function Ia(e){return e instanceof he||e instanceof Error?e.message:String(e)}function wg(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 Kd(e){var s;const n=(s=e.dataTransfer)==null?void 0:s.types;return!!(n&&Array.from(n).includes("Files"))}function G7(){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 Y7(){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 q7(){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 dC({items:e,disabled:n,label:s,title:r,sub:a,face:i}){const[l,o]=d.useState(!1),c=d.useRef(null);d.useEffect(()=>{if(!l)return;const h=m=>{c.current&&!c.current.contains(m.target)&&o(!1)},f=m=>{m.key==="Escape"&&o(!1)};return window.addEventListener("mousedown",h),window.addEventListener("keydown",f),()=>{window.removeEventListener("mousedown",h),window.removeEventListener("keydown",f)}},[l]);const u=h=>{const f=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"ui-menu-item-text",children:h.label}),h.hint?t.jsx("span",{className:"ui-menu-item-hint",children:h.hint}):null]});return h.href?t.jsx("a",{className:"ui-menu-item",role:"menuitem",href:h.href,"data-tone":h.tone,onClick:()=>o(!1),children:f},h.label):t.jsx("button",{className:"ui-menu-item",role:"menuitem","data-testid":h.testId,"data-tone":h.tone,disabled:h.disabled,onClick:()=>{var m;o(!1),(m=h.onSelect)==null||m.call(h)},children:f},h.label)};return t.jsxs("div",{className:"wb-head-menu",ref:c,children:[t.jsx("button",{className:"ui-icon-btn wb-head-more","data-testid":"chat-menu","aria-label":s,"aria-haspopup":"menu","aria-expanded":l,"data-open":l?"true":void 0,disabled:n,onClick:()=>o(h=>!h),children:t.jsx(q7,{})}),l?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"wb-head-menu-scrim","aria-hidden":"true",onClick:()=>o(!1)}),t.jsxs("div",{className:"ui-menu wb-head-menu-list",role:"menu","aria-label":r,children:[t.jsxs("div",{className:"wb-head-menu-head","aria-hidden":"true",children:[i,t.jsxs("span",{className:"wb-head-menu-heading",children:[t.jsx("span",{className:"wb-head-menu-title",children:r}),a?t.jsx("span",{className:"wb-head-menu-sub",children:a}):null]})]}),e.map((h,f)=>h==="separator"?t.jsx("div",{className:"ui-menu-sep",role:"separator"},`sep-${f}`):u(h)),t.jsx("button",{type:"button",className:"ui-btn wb-head-menu-cancel",onClick:()=>o(!1),children:"Cancel"})]})]}):null]})}let hC=!1;const Q7=new Set(["missing","unconfigured","not-english"]);async function kf(e,n,s=null){const r=NR(s);try{const a=await Qe.say({text:e,...n?{conversationId:n}:{}});return xS(r)&&await EH(a.audioUrl,a.mime,s),null}catch(a){xS(r)&&Uo();const i=a instanceof he&&a.detail&&typeof a.detail=="object"?a.detail.reason:void 0;return typeof i=="string"&&Q7.has(i)&&(s!==null||!hC)?(hC=!0,a.message):null}}function J7(e,n,s){const r=bT(e);if(!r||r.rest==="")return null;const a=n.find(i=>i.roles.includes(jr));return!a||a.id===s||a.handle.toLowerCase()!==r.handle?null:{agent:a,rest:r.rest}}const aj="buddi:ask";function X7(e){const n={text:e,handled:!1};return window.dispatchEvent(new CustomEvent(aj,{detail:n})),n.handled}let Ks=null;function Z7(e){if(vh(e)!==null)return!1;const n=NI(e);return n!==Tn&&n!==pa}function eY({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),[f,m]=d.useState(null);return d.useEffect(()=>{const p=v=>{const g=v.detail;!g||typeof g.text!="string"||(g.handled=!0,m({text:g.text,at:Date.now()}),r(!0))};return window.addEventListener(aj,p),()=>window.removeEventListener(aj,p)},[r]),d.useEffect(()=>{if(s||!u||!Ks)return;const p=Em({url:Qe.streamUrl(Ks.conversationId),lastEventId:Ks.lastEventId??null,onEvent:v=>{v.name==="run.finished"&&h(!1)}});return()=>p.close()},[s,u]),d.useEffect(()=>{const p=v=>{!v.altKey||v.ctrlKey||v.metaKey||v.code!=="Slash"||(v.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(nY,{agent:e,agents:n,timezone:i,navigate:a,onClose:()=>r(!1),onBusy:h,prefill:f}):t.jsxs(du,{children:[t.jsx(hu,{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(tY,{busy:u})})}),t.jsx(fu,{children:t.jsx(mu,{className:"ui-tip",side:"left",sideOffset:8,children:c})})]})}function tY({busy:e}){const[n,s]=d.useState(!1);return n?t.jsx(ku,{size:"lg"}):t.jsx(Ju,{state:e?"working":"idle",className:"wb-ask-fab-face",onStillError:()=>s(!0)})}function nY({agent:e,agents:n,timezone:s,navigate:r,onClose:a,onBusy:i,prefill:l}){const o=d.useRef(null),[c,u]=d.useState(Ks&&Ks.agentId===e.id?Ks.conversationId:null),[h,f]=d.useState(null),[m,p]=d.useState([]),[v,g]=d.useState([]),[k,j]=d.useState(null),[x,w]=d.useState(!1),[N,y]=d.useState(!1),[b,S]=d.useState(null),[C,A]=d.useState(l??null);d.useEffect(()=>{l&&A(l)},[l]);const[$,I]=d.useState(Date.now()),[P,O]=d.useState(bR),R=d.useRef(P);R.current=P;const[D,U]=d.useState(null),[W,M]=d.useState(new Map),L=d.useRef(null),_=d.useCallback(async ke=>{try{const we=await Qe.conversation(ke);f(we),p(ve=>ve.filter(Ie=>!sY(we,Ie)))}catch{}},[]);d.useEffect(()=>{c&&_(c)},[c,_]),d.useEffect(()=>{if(!c)return;const ke=Em({url:Qe.streamUrl(c),onEvent:we=>{var ve,Ie;switch(we.name){case"run.started":L.current=null,w(!0),j(null);break;case"live":{const Re=Vn(we.data.runId)??"",de=Number(we.data.turn??0),Ee=we.data.kind==="thinking"?"thinking":"text",ze=Vn(we.data.text)??"",qe=Date.now();if(Ee==="text"){const ht=L.current;L.current=ht&&ht.runId===Re&&ht.turn===de?{...ht,text:ht.text+ze}:{runId:Re,turn:de,text:ze}}j(ht=>{const le=ht&&ht.runId===Re&&ht.turn===de?ht:{runId:Re,turn:de,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return Ee==="thinking"?{...le,thinking:le.thinking+ze,thinkingStartedAt:le.thinkingStartedAt??qe}:{...le,text:le.text+ze,textStartedAt:le.textStartedAt??qe}});break}case"live.snapshot":{const Re=Vn(we.data.runId)??"",de=Number(we.data.turn??0),Ee=Vn(we.data.text)??"",ze=Vn(we.data.thinking)??"",qe=Number(we.data.startedAt??Date.now());L.current={runId:Re,turn:de,text:Ee},w(!0),j({runId:Re,turn:de,text:Ee,thinking:ze,thinkingStartedAt:ze?qe:null,textStartedAt:Ee?qe:null,settled:!1});break}case"live.settle":{const Re=Vn(we.data.runId)??"",de=Number(we.data.turn??0);if(we.data.retracted===!0){((ve=L.current)==null?void 0:ve.runId)===Re&&L.current.turn===de&&(L.current=null),j(Ee=>Ee&&Ee.runId===Re&&Ee.turn===de?null:Ee);break}j(Ee=>Ee&&Ee.runId===Re&&Ee.turn===de?{...Ee,settled:!0}:Ee);break}case"tool.called":{const Re=Vn(we.data.toolUseId)??Vn(we.data.id),de=Vn(we.data.name)??Vn(we.data.tool)??"tool";Re&&g(Ee=>[...Ee.filter(ze=>ze.toolUseId!==Re),{toolUseId:Re,name:de,startedAt:Date.now()}]);break}case"tool.result":{const Re=Vn(we.data.toolUseId)??Vn(we.data.id);Re&&g(de=>de.filter(Ee=>Ee.toolUseId!==Re)),_(c);break}case"awaiting-approval":{const Re=Vn(we.data.approvalId)??Vn(we.data.actionId),de=Vn(we.data.toolUseId);Re&&de&&M(Ee=>new Map(Ee).set(de,Re)),de&&g(Ee=>Ee.filter(ze=>ze.toolUseId!==de)),_(c).then(()=>j(Ee=>Ee!=null&&Ee.settled?null:Ee));break}case"message.appended":_(c).then(()=>j(Re=>Re!=null&&Re.settled?null:Re));break;case"run.finished":{w(!1),g([]),j(null);const Re=Vn(we.data.message);S(Re??null);const de=((Ie=L.current)==null?void 0:Ie.text.trim())??"";L.current=null,!Re&&de!==""&&R.current&&kf(de,c).then(Ee=>{Ee&&U(Ee)}),_(c);break}}}});return()=>{Ks&&Ks.conversationId===c&&(Ks.lastEventId=ke.lastEventId()),ke.close()}},[c,_]),d.useEffect(()=>{i(x||N)},[x,N,i]),d.useEffect(()=>{if(v.length===0)return;const ke=window.setInterval(()=>I(Date.now()),1e3);return()=>window.clearInterval(ke)},[v.length]);const Y=(ke,we)=>{y(!0),S(null);const ve={id:`local-${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[...ke.trim()===""?[]:[{type:"text",text:ke}],...we.map(Ie=>({type:"attachment",artifactId:Ie.artifactId,filename:Ie.filename,mime:Ie.mime,kind:Ie.kind,sizeBytes:Ie.sizeBytes}))]};p(Ie=>[...Ie,ve]),(async()=>{try{const Ie=c??(await Qe.startConversation(e.id)).conversationId;Ie!==c&&(Ks={agentId:e.id,conversationId:Ie},u(Ie));const Re=await Qe.send(e.id,{conversationId:Ie,text:ke,...we.length>0?{attachmentIds:we.map(de=>de.artifactId)}:{}});Re.conversationId!==Ie&&(Ks={agentId:e.id,conversationId:Re.conversationId},u(Re.conversationId)),w(!0),_(Re.conversationId)}catch(Ie){p(Re=>Re.filter(de=>de.id!==ve.id)),S(Ie instanceof he?Ie.message:String(Ie)),A({text:ke,at:Date.now()})}finally{y(!1)}})()},B=(ke,we)=>{if(S(null),ke==="stop"){se();return}if(ke==="use"){const ve=we.replace(/^@/,"").toLowerCase(),Ie=n.find(Re=>Re.handle.toLowerCase()===ve||Re.id===ve);if(!Ie){U(ve?`No agent called @${ve}.`:"Say who: /use @handle.");return}r(lt(Ie.id));return}if(ke==="new"){const ve=n.find(Ie=>Ie.roles.includes(jr));if(!ve){U("There is no agent here that makes agents.");return}we.trim()&&Wu(ve.id,`I'd like a teammate for this: ${we.trim()}`),r(lt(ve.id));return}T.quiet(we).then(ve=>U(ve.text)).catch(ve=>S(ve instanceof Error?ve.message:String(ve)))},se=()=>{c&&Qe.cancel(c).catch(ke=>S(String(ke))).finally(()=>w(!1))},G=()=>{var ke;Ks=null,u(null),f(null),p([]),g([]),j(null),w(!1),S(null),M(new Map),(ke=o.current)==null||ke.focus()},X=ke=>{O(ke),kR(ke),ke||Uo()},K=c?lt(e.id,c):lt(e.id),J=[...(h==null?void 0:h.messages)??[],...m],{openOffers:q,takingOffer:ce,takeOffer:xe,answeringQuestion:Me,answerQuestion:H,skipQuestion:ne}=bP({conversation:h,conversationId:c,agentId:e.id,now:$,refresh:_,onRunStarted:()=>w(!0),onError:(ke,we)=>{S(ke),we&&w(!1)},navigate:r}),Z=d.useMemo(()=>P7(h,n,W),[h,n,W]),ye=Z.length===0?(h==null?void 0:h.question)??null:null,Ce=ke=>{c&&_(c),T.overview().catch(()=>{}),ke.state!=="pending"&&M(we=>new Map([...we].filter(([,ve])=>ve!==ke.id)))};return t.jsxs(P8,{title:e.name,label:`${e.name}, a quick chat`,onClose:a,onOpenAutoFocus:ke=>{var we;ke.preventDefault(),(we=o.current)==null||we.focus()},onCloseAutoFocus:ke=>ke.preventDefault(),actions:t.jsxs(t.Fragment,{children:[t.jsx(E,{size:"sm",variant:"ghost",onClick:G,disabled:c===null&&m.length===0,children:"New"}),t.jsx(nt,{size:"sm",variant:"ghost",href:K,onClick:ke=>{ke.preventDefault(),r(K)},children:"Open in Chat"})]}),children:[t.jsx("div",{className:"wb-ask-thread",children:t.jsx(tb,{messages:J,live:v,now:$,working:x||N,partial:k,agents:n,agentName:e.name,agentId:e.id,onOpen:()=>r(K),onReadAloud:(ke,we)=>{U(null),kf(we,c??void 0,ke).then(ve=>{ve&&U(ve)})},emptyHint:`Ask ${e.name} anything, without leaving this page.`})}),t.jsxs("div",{className:"wb-ask-compose",children:[b?t.jsx(ae,{message:b}):null,t.jsx(kP,{offers:q,disabled:ce!==null,onTake:xe}),Z.length>0?t.jsx(QR,{approvals:Z,timezone:s,now:$,version:h,onDecided:Ce,onSay:ke=>Y(ke,[]),onOpenFull:()=>r(K)}):ye&&nj(ye)?t.jsx(jP,{card:nj(ye),disabled:Me||x,onAnswer:H},ye.id):ye?t.jsx(wP,{question:ye,disabled:Me||x,onAnswer:H,onSkip:ne},ye.id):null,t.jsxs("div",{hidden:Z.length>0||ye!==null,"data-testid":"composer-slot",children:[t.jsx(gb,{ref:o,disabled:N||!e.available,running:x,onSend:Y,onStop:se,agentName:e.name,placeholder:`Message ${e.name}…`,draft:C,threadKey:`dock.${c??e.id}`,conversationId:c,readAloud:P,onReadAloud:X,team:{agents:n,selfId:e.id},onCommand:B}),D?t.jsx("p",{className:"wb-voice-note",role:"status",children:D}):null]})]})]})}function Vn(e){return typeof e=="string"?e:null}function sY(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 EP=3;function rY(e){if(e==="approval"||e==="question")return"accent";if(e==="watcher"||e==="reminder")return"warm";if(e==="failure")return"critical"}function aY(e,n){return e?n?"above-dock":"above-button":"corner"}function iY({placement:e,children:n}){return t.jsx("div",{className:"wb-toast-stack","data-placement":e,children:n})}function lY(e){return e.state==="shown"&&e.seenAt===null}function oY(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=>lY(u)&&!r.current.has(u.id));s(u=>{const h=new Set(u.map(m=>m.id)),f=c.filter(m=>!h.has(m.id));return f.length===0?u:[...u,...f].sort((m,p)=>p.createdAt.localeCompare(m.createdAt))})}).catch(()=>{})},[e]);d.useEffect(()=>{for(const o of n.slice(0,EP))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 cY({queue:e,agents:n,navigate:s,onDismiss:r}){if(e.length===0)return null;const a=e.slice(0,EP),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":rY(l.kind),role:"status",children:[l.agentId?t.jsx(an,{agents:n,id:l.agentId,size:"sm"}):null,t.jsxs("div",{className:"nt-toast-main",children:[t.jsx("div",{className:"ui-toast-title",children:gu(l)}),l.text?t.jsx("div",{className:"ui-toast-body nt-toast-line",children:uY(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 ${gu(l)}`,onClick:()=>r(l.id),children:"×"})]},l.id)),i>0?t.jsxs("p",{className:"nt-toasts-more",children:["and ",i," more"]}):null]})}function uY(e){var n;return((n=e.split(`
123
+ `).find(s=>s.trim()!==""))==null?void 0:n.trim())??""}const dY=3e4,hY=1e3;function fY(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",f=j=>{var x;l=Date.now(),T.presence(j).catch(w=>{var N;w instanceof he&&w.status===401&&(i=!0,(N=a.current)==null||N.call(a))}),j==="active"&&((x=r.current)==null||x.call(r))},m=j=>{if(i||(o=j,c!==null))return;const x=l+hY-Date.now();if(x<=0){o=null,f(j);return}c=window.setTimeout(()=>{if(c=null,i||o===null)return;const w=o;o=null,f(w)},x)},p=()=>{u=!0,h()&&m("active")},v=()=>{u=!1,m("away")},g=()=>m(h()?"active":"away");h()&&m("active");const k=window.setInterval(()=>{h()&&u&&m("active")},dY);return window.addEventListener("focus",p),window.addEventListener("blur",v),document.addEventListener("visibilitychange",g),()=>{i=!0,window.clearInterval(k),c!==null&&window.clearTimeout(c),window.removeEventListener("focus",p),window.removeEventListener("blur",v),document.removeEventListener("visibilitychange",g)}},[e])}function mY({agents:e,onClose:n,onCreated:s}){return PI(e)?t.jsx(pY,{agents:Py(e),onClose:n,...s?{onCreated:s}:{}}):t.jsx(Je,{title:"A new group",onClose:n,children:t.jsxs(Q,{children:["A group needs two agents. Make another one with ",v5(e)," first."]})})}function pY({agents:e,onClose:n,onCreated:s}){var j,x;const[r,a]=d.useState(""),[i,l]=d.useState([]),[o,c]=d.useState(((j=e.find(w=>w.roles.includes(Yu)))==null?void 0:j.id)??((x=e[0])==null?void 0:x.id)??""),[u,h]=d.useState(!1),[f,m]=d.useState(null),p=[...new Set([o,...i])].filter(Boolean),v=r.trim()!==""&&o!==""&&p.length>=2,g=w=>l(N=>N.includes(w)?N.filter(y=>y!==w):[...N,w]),k=async()=>{h(!0),m(null);try{s==null||s(await Qe.createGroup({name:r.trim(),coordinator:o,members:p.filter(w=>w!==o)}))}catch(w){m(w instanceof he?w.message:String(w))}finally{h(!1)}};return t.jsx(Je,{title:"A new group",onClose:n,children:t.jsxs(ue,{children:[t.jsx(oe,{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:w=>a(w.target.value),placeholder:"Household finances"})}),t.jsx(oe,{label:"Coordinator",hint:"Reads your request, brings members in, and answers for the group. Concierge by default.",children:t.jsx("select",{value:o,onChange:w=>c(w.target.value),children:e.map(w=>t.jsx("option",{value:w.id,children:w.name},w.id))})}),t.jsx(oe,{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(w=>w.id!==o).map(w=>t.jsxs("label",{className:"group-pick-row","data-on":i.includes(w.id)||void 0,children:[t.jsx("input",{type:"checkbox",checked:i.includes(w.id),onChange:()=>g(w.id)}),t.jsx(an,{agents:e,id:w.id,size:"sm"}),t.jsxs("span",{className:"group-pick-text",children:[t.jsx("span",{className:"group-pick-name",children:w.name}),t.jsx("span",{className:"group-pick-desc",children:w.description})]})]},w.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."}),f?t.jsx(Q,{tone:"critical",children:f}):null,t.jsxs(re,{align:"end",children:[t.jsx(E,{onClick:n,children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:!v||u,onClick:()=>void k(),children:u?"Creating…":"Create group"})]})]})})}const gY=1e4;function Cu({title:e,body:n,duration:s,onUndo:r,onGone:a}){return t.jsxs(o4,{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(c4,{className:"ui-toast-title",children:e}),n?t.jsx(u4,{className:"ui-toast-body",children:n}):null]}),r?t.jsx(d4,{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 xY=6e5,vY=5e3,jY=32,wY=256*1024,yY=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"]),bY=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"]),kY={center:"div",font:"span",big:"span",tt:"code",strike:"s",section:"div",article:"div",header:"div",footer:"div",main:"div",aside:"div",address:"div"},NY=new Set(["br","hr","wbr","col","img"]),SY=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"]),CY=new Set(["block","inline","inline-block","none","table","table-row","table-cell","list-item","flex"]),EY=/url\s*\(|expression|javascript:|vbscript:|@import|\\|behavior|binding|attr\s*\(|var\s*\(/i,AY=["gmail_quote","yahoo_quoted","protonmail_quote","moz-cite-prefix","reply-head"],$Y=/^data:image\/(png|gif|jpeg|jpg|webp);base64,[a-z0-9+/=\s]+$/i;function TY(e){return e.replace(/-([a-z])/g,(n,s)=>s.toUpperCase())}function fC(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 mC(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 IY=/(^|[\s(,])-\s*(\d|\.\d)/,RY=new Set(["width","max-width","min-width","height","max-height","min-height"]);function PY(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 MY(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(!SY.has(a))continue;const i=s.getPropertyValue(a).trim();if(i===""||i.length>200||EY.test(i)||a==="display"&&!CY.has(i.toLowerCase())||IY.test(i)||/calc\s*\(/i.test(i))continue;const l=RY.has(a)?PY(i):i;l!==null&&(n[TY(a)]=l)}return n}function pC(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 AP(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 gC(e,n){if(n==="blockquote"&&(e.getAttribute("type")??"").toLowerCase()==="cite")return!0;const s=(e.getAttribute("class")??"").split(/\s+/);return AY.some(r=>s.includes(r))?!0:(e.getAttribute("id")??"")==="divRplyFwdMsg"}function xC(e){return(e.getAttribute("class")??"").split(/\s+/).includes("reply-head")||(e.getAttribute("id")??"")==="divRplyFwdMsg"}function OY(e){if(typeof e!="string"||e.trim()===""||e.length>xY)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=[],f=Array.from(o.childNodes);for(let m=0;m<f.length;m+=1){const p=f[m];if(p.nodeType===1&&gC(p,p.tagName.toLowerCase())&&xC(p)){const g=f.slice(m).flatMap(k=>i(k,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 y=o.nodeValue??"";return y===""?[]:[{t:"text",v:y}]}if(o.nodeType!==1)return[];const h=o,f=h.tagName.toLowerCase();if(yY.has(f))return[];if(s.nodes>=vY)return s.truncated=!0,[];if(c>jY)return s.truncated=!0,r(h);if(s.nodes+=1,!u&&gC(h,f)&&!xC(h)){const y=a(h,c+1,!0);return y.length>0?[{t:"quote",kids:y}]:[]}if(!bY.has(f))return a(h,c+1);const m=MY(h),p=mC(h.getAttribute("bgcolor"));if(p&&!m.backgroundColor&&(m.backgroundColor=p),f==="font"){const y=mC(h.getAttribute("color"));y&&!m.color&&(m.color=y);const b=h.getAttribute("face");b&&/^[\w\s,'"-]{1,80}$/.test(b)&&!m.fontFamily&&(m.fontFamily=b)}const v=(h.getAttribute("align")??"").toLowerCase();["left","right","center","justify"].includes(v)&&!m.textAlign&&f!=="img"&&f!=="table"&&(m.textAlign=v),f==="table"&&v==="center"&&(m.marginLeft=m.marginLeft??"auto",m.marginRight=m.marginRight??"auto");const g=(h.getAttribute("valign")??"").toLowerCase();if(["top","middle","bottom","baseline"].includes(g)&&!m.verticalAlign&&(m.verticalAlign=g),["table","td","th","img","col"].includes(f)){const y=fC(h.getAttribute("width")),b=fC(h.getAttribute("height"));y&&!m.width&&(m.width=y),b&&!m.height&&f!=="table"&&(m.height=b)}const k=Object.keys(m).length>0?{style:m}:{};if(f==="img"){const y=(h.getAttribute("src")??"").trim(),b=(h.getAttribute("alt")??"").slice(0,200);return/^https?:\/\//i.test(y)?pC(h,m)?(s.pixels+=1,[]):(s.remoteImages+=1,[{t:"img",kind:"remote",src:y,alt:b,...k}]):/^cid:/i.test(y)?[{t:"img",kind:"cid",src:y.slice(4).replace(/^<|>$/g,""),alt:b,...k}]:$Y.test(y)&&y.length<=wY?pC(h,m)?(s.pixels+=1,[]):[{t:"img",kind:"data",src:y,alt:b,...k}]:b?[{t:"text",v:b}]:[]}const j=NY.has(f)?[]:a(h,c+1);if(f==="a"){const y=AP(h.getAttribute("href"));return y?[{t:"link",href:y.href,outside:y.outside,...k,kids:j}]:j.length>0?[{t:"el",tag:"span",...k,kids:j}]:[]}const x={};if(f==="td"||f==="th"){const y=Number.parseInt(h.getAttribute("colspan")??"",10),b=Number.parseInt(h.getAttribute("rowspan")??"",10);y>1&&y<=100&&(x.colSpan=y),b>1&&b<=100&&(x.rowSpan=b)}if(f==="ol"){const y=Number.parseInt(h.getAttribute("start")??"",10);Number.isFinite(y)&&(x.start=y)}if(f==="table"){const y=Number.parseInt(h.getAttribute("cellpadding")??"",10),b=Number.parseInt(h.getAttribute("cellspacing")??"",10);Number.isFinite(y)&&y>=0&&y<=40&&(x.cellPadding=y),Number.isFinite(b)&&b>=0&&b<=40&&(x.cellSpacing=b)}const w=h.getAttribute("title");w&&(x.title=w.slice(0,200));const N=(h.getAttribute("dir")??"").toLowerCase();return(N==="rtl"||N==="ltr"||N==="auto")&&(x.dir=N),[{t:"el",tag:kY[f]??f,...k,...Object.keys(x).length>0?{attrs:x}:{},kids:j}]};return{nodes:a(n.body,0),remoteImages:s.remoteImages,pixels:s.pixels,truncated:s.truncated}}const DY=/(wrote|a écrit|schrieb|escribió|scrisse|schreef|написал)\s*:\s*$/i,LY=/^(-{2,}\s*(original message|forwarded message|message d'origine)\s*-{2,}|_{10,})\s*$/i,vC=2e5;function FY(e){const n=e.split(/\r?\n/),s=[];let r=[];const a=()=>{r.length>0&&s.push({t:"text",v:r.join(`
124
+ `)}),r=[]},i=()=>{let l=r.length-1;for(;l>=0&&r[l].trim()==="";)l-=1;if(l<0||!DY.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(LY.test(o.trim())){const c=i();return a(),s.push({t:"quote",head:c,inner:n.slice(l+1).join(`
125
+ `)}),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(`
126
+ `)}),l=u-1;continue}r.push(o)}return a(),s}const _Y=/\bhttps?:\/\/[^\s<>"'`]+/gi;function zY(e){var r,a;const n=[];let s=0;for(const i of e.matchAll(_Y)){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=AP(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 $P="buddi.mail.images.v1";function TP(){try{const e=window.localStorage.getItem($P),n=e?JSON.parse(e):[];return new Set(Array.isArray(n)?n.filter(s=>typeof s=="string"):[])}catch{return new Set}}function jC(e,n){const s=e.trim().toLowerCase();if(s!=="")try{const r=TP();n?r.add(s):r.delete(s),window.localStorage.setItem($P,JSON.stringify([...r].slice(-500)))}catch{}}const UY=8;function IP({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 Nh(e,n,s=""){return e.map((r,a)=>BY(r,n,`${s}${a}`))}function BY(e,n,s){switch(e.t){case"text":return e.v;case"quote":return t.jsx(IP,{children:Nh(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:Nh(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?Nh(e.kids,n,`${s}.`):[])}}function RP({text:e,depth:n=0}){const s=n>=UY?[{t:"text",v:e}]:FY(e);return t.jsx(t.Fragment,{children:s.map((r,a)=>r.t==="text"?t.jsx("div",{className:"pl-mail-text",children:zY(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(IP,{head:r.head,children:t.jsx(RP,{text:r.inner,depth:n+1})},a))})}function WY({html:e,text:n,sender:s,attachments:r,cidSrc:a}){const i=d.useMemo(()=>e?OY(e):null,[e]),l=s.trim().toLowerCase(),o=d.useMemo(()=>TP().has(l),[l]),[c,u]=d.useState(null),h=c!==null&&c.who===l?c.show:o,f=p=>u({who:l,show:p}),m=p=>{const v=p.trim().replace(/^<|>$/g,"").toLowerCase(),g=(r??[]).find(k=>typeof k.contentId=="string"&&k.contentId.trim().replace(/^<|>$/g,"").toLowerCase()===v);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(E,{size:"sm",variant:"ghost",onClick:()=>{jC(s,!1),f(!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(E,{size:"sm",onClick:()=>{jC(s,!0),f(!0)},children:"Show images"})]})}):null,t.jsx("div",{className:"pl-mail-html",children:Nh(i.nodes,{showImages:h,cid:m})}),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>vC;return t.jsxs("div",{className:"pl-mail-body",children:[t.jsx(RP,{text:p?n.slice(0,vC):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}function Es({tone:e="accent",icon:n,title:s,href:r,onOpen:a,from:i,time:l,dismiss:o,extraDismiss:c,lead:u,actions:h,compact:f,kind:m,children:p}){const g=`${d.useId()}-title`,k=(x,w)=>t.jsx(E,{variant:"ghost",size:f?"sm":void 0,title:x.hint,disabled:x.disabled,onClick:x.onClick,children:x.label??w}),j=!!(o||c||u||h);return t.jsx(Ar,{as:"article",labelledBy:g,...f?{density:"compact"}:{},children:t.jsxs("div",{className:"needs-card","data-tone":e,"data-compact":f?"true":void 0,"data-kind":m,children:[t.jsx("span",{className:"needs-card-mark","aria-hidden":"true",children:n?t.jsx(ie,{name:n,size:f?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:x=>{a&&(x.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,j?t.jsxs("div",{className:"needs-card-actions",children:[o||c||u?t.jsxs("div",{className:"needs-card-out",children:[o?k(o,"Not now"):null,c?k(c,"Not this again"):null,u]}):null,h?t.jsx("div",{className:"needs-card-do",children:h}):null]}):null]})]})})}function Eu({face:e,children:n}){return t.jsxs(t.Fragment,{children:[e,t.jsx("span",{className:"needs-card-from-text",children:n})]})}function xb(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,f)=>{var p,v,g,k;s(c),l(null),a(null);let m;try{const j=f?await T.decide(c,u,h,f):await T.decide(c,u,h);m={decision:u,...(p=j.execution)!=null&&p.state?{state:j.execution.state}:{},...j.execution&&"result"in j.execution?{result:j.execution.result}:{}},a(u==="reject"?`Rejected ${j.action.tool}.`:((v=j.execution)==null?void 0:v.state)==="succeeded"?`Approved and done: ${j.action.tool}.`:`Approved ${j.action.tool}: ${((g=j.execution)==null?void 0:g.state)??"no execution"}${(k=j.execution)!=null&&k.message?` (${j.execution.message})`:""}`)}catch(j){l(j instanceof Error?j.message:String(j))}finally{s(null),e(m)}}}}function HY(e){var r;if((r=e.ask)!=null&&r.trim())return e.ask.trim();const s=(e.preview.split(`
127
+ `).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 KY(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 vb({action:e,timezone:n,busy:s,onDecide:r,agentName:a,agents:i}){var v,g,k;const[l,o]=d.useState(!1),{values:c,controls:u}=Uy(e.choices),h=j=>c?r(e.id,"approve",j,c):r(e.id,"approve",j),f=!!((v=e.permissionScopes)!=null&&v.length),m=HY(e),p=KY(e.preview,m);return t.jsxs(Es,{kind:"approval",tone:"accent",icon:"lock",title:m,time:Ye(e.createdAt),from:Im(e.agentId)?t.jsxs(Eu,{face:t.jsx(UI,{size:"sm"}),children:["Asked by ",Tm]}):t.jsxs(Eu,{face:i?t.jsx(an,{agents:i,id:e.agentId,size:"sm"}):void 0,children:["Asked by ",a??e.agentId]}),lead:t.jsx(E,{variant:"ghost",onClick:()=>o(j=>!j),"aria-expanded":l,children:l?"Hide envelope":"Show envelope"}),actions:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:e.answers?"ghost":"danger",disabled:s,onClick:()=>r(e.id,"reject"),children:((g=e.answers)==null?void 0:g.reject)??"Reject"}),f?t.jsxs(t.Fragment,{children:[t.jsx(E,{disabled:s,onClick:()=>h("conversation"),children:"Auto: this conversation"}),t.jsx(E,{disabled:s,onClick:()=>h("always"),children:"Always: this agent"})]}):null,t.jsx(E,{variant:"accent",disabled:s,onClick:()=>h(),children:((k=e.answers)==null?void 0:k.approve)??(f?"Allow once":"Approve")})]}),children:[p?t.jsx(Bt,{children:p}):null,t.jsxs("p",{className:"ui-card-meta",children:[t.jsx("span",{className:"mono",children:e.tool})," v",e.toolVersion,". Expires ",mt(e.expiresAt,n)," (",Ye(e.expiresAt),"). Policy v",e.policyVersion,", args ",pu(e.argsHash,12),e.jobId?`, job ${pu(e.jobId)}`:"","."]}),u,l?t.jsxs("div",{className:"ui-card-foot",children:[t.jsx(pe,{title:"Envelope: everything that decides what the world will see",children:t.jsx(Bt,{children:ls(e.envelope)})}),t.jsx(pe,{title:"Canonical arguments",children:t.jsx(Bt,{children:ls(e.canonicalArgs)})})]}):null]})}function jb(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 he?h.message:String(h))).finally(()=>a(!1)))},busy:r,created:i,failure:o}}function PP({agent:e}){return t.jsxs(Q,{tone:"good",role:"status",children:["@",e.handle," is ready. ",t.jsxs("a",{href:lt(e.id),children:["Talk to @",e.handle]})]})}function MP(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 VY(e,n){var a;const s=me(()=>T.approvals(),[e,n],15e3);return{action:((a=s.data)==null?void 0:a.pending.find(i=>MP(i,e,n)))??null,reload:s.reload}}function wC({action:e,onDecided:n}){const{busy:s,failure:r,decide:a}=xb(i=>n(i));return t.jsxs(ue,{gap:"sm",children:[t.jsx(vb,{action:e,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,busy:s===e.id,onDecide:(i,l,o,c)=>{a(i,l,o,c)}}),t.jsx(ae,{message:r})]})}function wb({plugin:e,agent:n,text:s,label:r,handle:a,onDismiss:i,card:l}){var p;const o=jb(e,n),c=VY(e,n),[u,h]=d.useState(null),f=o.created??u,m=a??((p=/@(\S+)/.exec(r))==null?void 0:p[1])??n;if(f&&l)return t.jsx(Es,{kind:"offer",tone:"accent",icon:"check",title:`@${f.handle} is ready`,from:l.from,actions:t.jsxs(nt,{variant:"accent",href:lt(f.id),children:["Talk to @",f.handle]})});if(f)return t.jsx(PP,{agent:f});if(c.action){const v=g=>{(g==null?void 0:g.decision)==="approve"&&g.state==="succeeded"?h({id:n,handle:m,name:m}):c.reload()};return l?t.jsx(wC,{action:c.action,onDecided:v}):t.jsxs(ue,{gap:"sm",children:[t.jsx("span",{children:s}),t.jsx(wC,{action:c.action,onDecided:v})]})}return l?t.jsxs(Es,{kind:"offer",tone:"accent",icon:"agents",title:`Set up @${m}`,from:l.from,...i?{dismiss:{onClick:i,disabled:o.busy,hint:"Hide this offer"}}:{},actions:t.jsx(E,{variant:"accent",disabled:o.busy,onClick:o.accept,children:r}),children:[t.jsx("p",{children:s}),t.jsx(ae,{message:o.failure})]}):t.jsxs(ue,{gap:"sm",children:[t.jsxs(re,{children:[t.jsx("span",{children:s}),t.jsx(pt,{}),i?t.jsx(E,{variant:"ghost",disabled:o.busy,onClick:i,children:"Not now"}):null,t.jsx(E,{variant:"accent",disabled:o.busy,onClick:o.accept,children:r})]}),t.jsx(ae,{message:o.failure})]})}function OP(){var n;const e=me(()=>T.agentOffers(),[],6e4);return{offers:((n=e.data)==null?void 0:n.offers)??[],reload:e.reload}}function DP({offers:e,reload:n}){return e.length===0?null:t.jsx(pe,{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(wb,{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 GY={work:"Work",money:"Money",home:"Home",health:"Health",learning:"Learning",life:"Life"},yb=e=>GY[e]??Km(e);function Km(e){return e.charAt(0).toUpperCase()+e.slice(1)}function ln(e){return e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function po(e){return e.replace(/\.0$/,"")}function YY(e){return e.avatar?T.marketAssetUrl(e.avatar):void 0}const qY={mailbox:{title:"your mailbox",fix:"Add a mailbox",route:vr("email","settings")},"image-account":{title:"a drawing account",fix:"Choose a drawing account",route:vr("image","settings")}};function bb(e){return qY[e.replace(/\?$/,"")]??{title:e,fix:"Set it up",route:_e()}}const Vm=e=>Km(e);function kb(e){return e.kind==="plugin"?e.title:bb(e.name).title}function Nf(e){if(e.kind==="need"){const n=bb(e.name);return{label:n.fix,route:n.route}}return e.fix==="enable"?{label:`Turn on ${e.title}`,route:_e("plugins")}:e.fix==="update"?{label:`Update ${e.title}`,route:_e("plugins")}:e.byBuddi?null:{label:`Install ${e.title}`,route:_e("plugins")}}function QY(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(Vm),l=e.needs.includes("mailbox")||e.needs.includes("mailbox?");return s===!0&&l&&!r.has("mailbox")&&i.push("your mailbox"),i}function yg(e){return Km(e.replace(/\.md$/i,"").replace(/[-_]+/g," ").trim())}const yC=(e,n)=>e.includes(n),JY={email:{title:"Mail",line:e=>yC(e,"email.draft")||yC(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."}},XY={schedule:"reminder",browser:"web"};function Sf(e,n=new Map){const s=[],r=new Map;for(const a of e){const i=a.replace(/\?$/,""),l=i.split(".")[0]??i,o=XY[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=JY[a],o=i.some(u=>n.get(u)==="gated"||u.endsWith(".*")&&[...n].some(([h,f])=>f==="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)??Km(a),o&&!/asks you/i.test(c)?`${c} Asks you first before it changes anything.`:c]})}function bC(e){return e.length===0?"Nothing beyond its own chat.":`Reaches ${ln(e.map(([n])=>n))}.`}function Cf(e){return new Map((e??[]).filter(n=>n.tier).map(n=>[n.name,n.tier]))}function ul({entry:e,size:n}){const s=YY(e);return t.jsx("span",{className:"cat-face","data-size":n,children:t.jsx(In,{id:e.name,name:e.title,size:n==="xxl"?"xl":n,face:{tools:e.tools,...s?{picture:s}:{}}})})}const LP=800,ZY=e=>{var n;return((n=/^.*?[.!?](?=\s|$)/.exec(e.trim()))==null?void 0:n[0])??e.trim()},eo=e=>e instanceof he?e.message:String(e);function oa({entry:e,children:n}){return t.jsxs("span",{className:"plugins-sheet-title",children:[t.jsx(ul,{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(Se,{tone:"accent",children:"by buddi"})]}):null]})]})]})}function bg({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(ie,{name:"check",size:12}):e==="failed"?t.jsx(ie,{name:"alert",size:14}):null}),t.jsx("span",{children:n})]})}function kg(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 eq(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,LP)))}).catch(c=>{i||a(eo(c))})};return o(),()=>{i=!0,l!==void 0&&window.clearTimeout(l)}},[e]),{job:n,error:r,setJob:s}}function Nb({entry:e,navigate:n,onClose:s,onAdded:r}){var Me;const a=Yn("(max-width: 720px)"),[i,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState({}),[f,m]=d.useState(""),[p,v]=d.useState([]),[g,k]=d.useState(!1),[j,x]=d.useState(null),[w,N]=d.useState(!1),[y,b]=d.useState(null),{job:S,error:C,setJob:A}=eq(j),[$,I]=d.useState(!1),[P,O]=d.useState(null),[R,D]=d.useState(!1),U=d.useRef(!1),[W,M]=d.useState([]);d.useEffect(()=>{if(!i||i.plugins.length===0)return;let H=!1;return Promise.resolve().then(()=>T.market()).then(ne=>{H||M((ne==null?void 0:ne.plugins)??[])}).catch(()=>{}),()=>{H=!0}},[i]),d.useEffect(()=>{let H=!1;return T.cataloguePlan(e.name).then(ne=>{H||(l(ne),h(Object.fromEntries(ne.fills.map(Z=>[Z.id,Z.value]))),m(ne.handle))}).catch(ne=>{H||c(eo(ne))}),()=>{H=!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 L=()=>{i&&(N(!0),b(null),U.current=!1,T.catalogueInstall(e.name,{version:i.version,fills:u,handle:f,missionsOn:p,tools:i.tools.map(H=>H.name)}).then(H=>x(H.jobId)).catch(H=>b(eo(H))).finally(()=>N(!1)))},_=()=>{x(null),L()},Y=e.title,B=S==null?void 0:S.agent,se=H=>{B&&(H&&Wu(B.id,H),s(),n(lt(B.id)))},G=H=>{S&&(I(!0),O(null),T.catalogueConfirm(S.id,H).then(ne=>{A(ne),H||s()}).catch(ne=>O(eo(ne))).finally(()=>I(!1)))};if((S==null?void 0:S.state)==="confirm"&&S.confirm){const H=Sf(S.confirm.tools.map(Z=>Z.name),Cf(S.confirm.tools)),ne=S.steps.filter(Z=>Z.kind==="plugin"&&Z.state==="done").map(Z=>Z.title);return t.jsxs(Je,{title:t.jsxs(oa,{entry:e,children:["Add ",Y]}),onClose:s,foot:t.jsxs(re,{children:[t.jsx(pt,{}),t.jsx(E,{variant:"ghost",disabled:$,onClick:()=>G(!1),children:"Don’t add it"}),t.jsxs(E,{variant:"accent",disabled:$,onClick:()=>G(!0),children:["Add ",Y]})]}),children:[t.jsx("ol",{className:"cat-steps","data-testid":"cat-confirm",children:S.steps.filter(Z=>Z.kind==="plugin").map(Z=>{const{state:ye,words:Ce}=kg(Z);return t.jsx(bg,{state:ye,children:Ce},`${Z.kind}-${Z.name}`)})}),t.jsxs(Q,{tone:"warning",title:`${Y} would get more than the list showed.`,children:[ne.length>0?`With ${ln(ne)} installed, `:"","its tools resolved to a different set",S.confirm.unshown.length>0?`, including ${ln(S.confirm.unshown)}`:"",". Look at what it can reach before you add it."]}),t.jsx(ae,{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:[bC(H)," ",t.jsx("button",{type:"button",className:"plugins-link cat-link",onClick:()=>D(!R),children:R?"Hide":"See all"})]}),R?t.jsx("dl",{className:"cat-reach",children:H.map(([Z,ye])=>t.jsxs("div",{className:"cat-reach-row",children:[t.jsx("dt",{children:Z}),t.jsx("dd",{children:ye})]},Z))}):null]}),t.jsx("p",{className:"cat-small",children:"The plugins stay installed either way; Settings → Plugins removes them."})]})}if(j&&(!S||S.state==="running")){const H=S==null?void 0:S.steps[S.steps.length-1],ne=(S==null?void 0:S.approvalId)&&(H==null?void 0:H.state)==="adding";return t.jsxs(Je,{title:t.jsxs(oa,{entry:e,children:["Add ",Y]}),onClose:s,foot:t.jsx(re,{align:"end",children:t.jsx(E,{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(Z=>{const{state:ye,words:Ce}=kg(Z);return t.jsx(bg,{state:ye,children:Ce},`${Z.kind}-${Z.name}`)})}),ne?t.jsxs(Q,{tone:"accent",action:t.jsx(E,{size:"sm",onClick:()=>{s(),n(uo)},children:"Open it"}),children:["Adding ",Y," waits for your approval in Needs you."]}):null,t.jsx(ae,{message:C}),t.jsxs("p",{className:"cat-small",children:["You can close this; it carries on, and ",Y," joins the team when it’s done."]})]})}if((S==null?void 0:S.state)==="done"){const H=S.steps.filter(ye=>ye.kind==="plugin").map(ye=>ye.title),ne=(i==null?void 0:i.missions.length)??e.missions.length,Z=p.length;return t.jsxs(Je,{title:t.jsx(oa,{entry:e,children:Y}),onClose:s,foot:t.jsxs(re,{children:[t.jsx(E,{variant:"ghost",onClick:()=>{s(),n(pn())},children:"Back to teammates"}),t.jsx(pt,{}),t.jsx(E,{variant:"accent",onClick:()=>se(),children:"Say hello"})]}),children:[t.jsxs("div",{className:"cat-done","data-testid":"cat-done",children:[t.jsx(ul,{entry:e,size:"xxl"}),t.jsxs("p",{className:"cat-done-title",children:[Y," is on your team."]}),t.jsxs("p",{className:"cat-small",children:["@",(B==null?void 0:B.handle)??f,H.length?` · ${ln(H)} installed`:"",ne>0&&Z<ne?` · ${ne-Z===1?"a mission":"missions"} off until you turn ${ne-Z===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(ye=>t.jsx("button",{type:"button",className:"wb-starter",onClick:()=>se(ye),children:ye},ye))})]}):null]})}if((S==null?void 0:S.state)==="failed"){const H=S.steps.find(ne=>ne.kind==="plugin"&&ne.state==="failed");return t.jsxs(Je,{title:t.jsxs(oa,{entry:e,children:[Y," wasn’t added"]}),onClose:s,foot:t.jsxs(re,{children:[t.jsx(pt,{}),t.jsx(E,{variant:"ghost",onClick:s,children:"Close"}),t.jsx(E,{variant:"accent",disabled:w,onClick:_,children:"Try again"})]}),children:[t.jsx("ol",{className:"cat-steps","data-testid":"cat-failed",children:S.steps.map(ne=>{const{state:Z,words:ye}=kg(ne);return t.jsx(bg,{state:Z==="now"?"next":Z,children:Z==="now"?ye.replace(/…$/,""):ye},`${ne.kind}-${ne.name}`)})}),t.jsx(Q,{tone:"critical",title:`${S.error??"It stopped before it finished"}.`,action:S.approvalId?t.jsx(E,{size:"sm",onClick:()=>{s(),n(uo)},children:"Open the approval"}):void 0,children:t.jsxs("p",{children:["Nothing was added and nothing else changed.",H?t.jsxs(t.Fragment,{children:[" ",H.title," waits in"," ",t.jsx("a",{href:_e("plugins"),onClick:ne=>{ne.preventDefault(),s(),n(_e("plugins"))},children:"Settings → Plugins"})," ","if you’d rather look at it there."]}):null]})}),t.jsx(ae,{message:y})]})}const X=(i==null?void 0:i.plugins.filter(H=>H.fix==="install"&&H.byBuddi))??[],K=(i==null?void 0:i.blocked)??[],J=K[0],q=J?Nf(J):null,ce=Sf(i?i.tools.map(H=>H.name):e.tools,Cf([...((Me=e.claims)==null?void 0:Me.tools)??[],...((i==null?void 0:i.tools)??[]).filter(H=>H.tier!=="unknown")])),xe=H=>{var ne;return((ne=e.missions.find(Z=>Z.id===H))==null?void 0:ne.when)??""};return t.jsxs(Je,{title:t.jsxs(oa,{entry:e,children:["Add ",Y]}),onClose:s,foot:t.jsxs(re,{children:[a?null:t.jsx("span",{className:"plugins-foot-note",children:X.length?`Installs ${ln(X.map(H=>H.title))}, then adds ${Y}.`:"Nothing runs until you add it."}),t.jsx(pt,{}),t.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsxs(E,{variant:"accent",disabled:!i||K.length>0||w||f.length<2,onClick:L,children:["Add ",Y]})]}),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(ae,{message:o??y}),!i&&!o?t.jsx(be,{children:"Reading what it needs…"}):i?t.jsxs(ue,{divided:!0,gap:"lg",children:[X.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:X.map(H=>{const ne=W.find(Z=>Z.name===H.name);return t.jsxs("li",{children:[t.jsx(Qn,{svg:ne==null?void 0:ne.iconSvg}),t.jsxs("span",{className:"cat-plugin-text",children:[t.jsxs("span",{className:"cat-plugin-name",children:[H.title," ",H.version?t.jsx("span",{className:"plugins-ver",children:H.version}):null]}),t.jsx("span",{className:"cat-small",children:ne!=null&&ne.summary?ZY(ne.summary):"Made by buddi; installed only if it matches what withbuddi.com lists."})]}),t.jsx(Se,{tone:"accent",children:"by buddi"})]},H.name)})})]}):null,J?t.jsxs(Q,{tone:"warning",action:q?t.jsx(E,{size:"sm",onClick:()=>{s(),n(q.route)},children:q.label}):void 0,children:[Y," needs ",ln(K.map(kb))," first. Add ",K.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(H=>t.jsx(oe,{label:t.jsxs(t.Fragment,{children:[H.label,H.optional?t.jsx("span",{className:"faint",children:" · optional"}):null]}),children:H.choices&&H.choices.length>0?t.jsxs("select",{value:u[H.id]??"",onChange:ne=>h({...u,[H.id]:ne.target.value}),children:[H.kind==="calendar"?t.jsx("option",{value:"",children:"All of them"}):null,H.choices.map(ne=>t.jsx("option",{value:ne,children:ne},ne))]}):H.kind==="time"?t.jsx("input",{type:"time",value:u[H.id]??"",onChange:ne=>h({...u,[H.id]:ne.target.value})}):t.jsx("input",{value:u[H.id]??"",onChange:ne=>h({...u,[H.id]:ne.target.value})})},H.id))})]}):null,t.jsx("div",{className:"cat-block",children:t.jsx(oe,{label:"Handle",hint:"How you call it in chat and on Telegram.",children:t.jsxs("span",{className:"cat-handle",children:[t.jsx("span",{className:"mono faint",children:"@"}),t.jsx("input",{className:"mono","aria-label":"Handle",value:f,onChange:H=>m(H.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(H=>t.jsxs("li",{children:[t.jsx("span",{className:"cat-mission-name",children:H.name}),t.jsx("span",{className:"cat-mission-when",children:xe(H.id)}),t.jsx(Fo,{checked:p.includes(H.id),label:`Turn on ${H.name}`,onChange:ne=>v(ne?[...p,H.id]:p.filter(Z=>Z!==H.id))})]},H.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:[bC(ce)," ",t.jsx("button",{type:"button",className:"plugins-link cat-link",onClick:()=>k(!g),children:g?"Hide":"See all"})]}),g?t.jsx("dl",{className:"cat-reach",children:ce.map(([H,ne])=>t.jsxs("div",{className:"cat-reach-row",children:[t.jsx("dt",{children:H}),t.jsx("dd",{children:ne})]},H))}):null]})]}):null]})}function tq(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 kC({lines:e,label:n}){return t.jsx("div",{className:"cat-diff",role:"region","aria-label":n,children:tq(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 FP({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,f]=d.useState(!1),[m,p]=d.useState(!1);d.useEffect(()=>{let w=!1;return T.catalogueUpdatePlan(e.name,n).then(N=>{w||i(N)}).catch(N=>{w||o(eo(N))}),()=>{w=!0}},[e.name,n]);const v=po((a==null?void 0:a.version)??e.version),g=w=>{a&&(f(!0),o(null),T.catalogueUpdate(e.name,n,a.plan,w).then(()=>{p(!0),r==null||r()}).catch(N=>{o(eo(N)),T.catalogueUpdatePlan(e.name,n).then(i).catch(()=>{})}).finally(()=>f(!1)))};if(m)return t.jsx(Je,{title:t.jsxs(oa,{entry:e,children:[e.title," ",v]}),onClose:s,foot:t.jsx(re,{align:"end",children:t.jsx(E,{variant:"accent",onClick:s,children:"Done"})}),children:t.jsx(Q,{tone:"good",title:`${e.title} is on ${v}.`,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(Je,{title:t.jsxs(oa,{entry:e,children:["Update ",e.title]}),onClose:s,children:[t.jsx(ae,{message:l}),l?null:t.jsx(be,{children:"Reading what changed…"})]});const k=a.personaDiff.filter(w=>w.startsWith("+ ")).length,j=a.personaDiff.filter(w=>w.startsWith("- ")).length;if(a.edited)return t.jsxs(Je,{title:t.jsxs(oa,{entry:e,children:[e.title," ",v," is out"]}),onClose:s,foot:t.jsxs(re,{children:[c?null:t.jsx(E,{variant:"ghost",onClick:()=>u(!0),children:"See what changed"}),t.jsx(pt,{}),t.jsx(E,{variant:"ghost",onClick:s,children:"Keep mine"}),t.jsx(E,{variant:"danger",disabled:h,onClick:()=>g(!0),children:"Replace my changes"})]}),children:[t.jsx(Q,{tone:"accent",children:a.replacesOwn&&a.replacesOwn.length>0?`${v} brings ${a.replacesOwn.length===1?"a skill":"skills"} named like your own (${ln(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(ae,{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 ",v]}),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 ",v," ",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(kC,{lines:a.personaDiff,label:`Your ${e.title} against ${v}`}),t.jsxs("p",{className:"cat-small",children:["Lines marked − are in your file and not in ",v,"; + is new in ",v,". Replacing keeps your picks, and drops what you wrote by hand."]})]}):t.jsxs("p",{className:"cat-small",children:[j===1?"1 line":`${j} lines`," only in your file, ",k===1?"1 line":`${k} lines`," new in ",v,"."]})]})]})]});const x=a.added.length>0?`New: ${ln(Sf(a.added.map(w=>w.name),Cf(a.added)).map(([w])=>w))}. The approval lists each tool.`:"No new tools. It reaches what it reaches today.";return t.jsxs(Je,{title:t.jsxs(oa,{entry:e,children:["Update ",e.title," to ",v]}),onClose:s,foot:t.jsxs(re,{children:[t.jsx("span",{className:"plugins-foot-note",children:"Your picks and handle stay."}),t.jsx(pt,{}),t.jsx(E,{variant:"ghost",onClick:s,children:"Not now"}),t.jsxs(E,{variant:"accent",disabled:h,onClick:()=>g(!1),children:["Update ",e.title]})]}),children:[t.jsx("p",{className:"cat-lede",children:a.changes}),t.jsx(ae,{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(kC,{lines:a.personaDiff,label:a.via?`@${a.handle} against ${e.title} ${v}`:`${e.title} ${po(a.fromVersion)} against ${v}`}):t.jsx("p",{className:"cat-prose",children:"Its persona stays word for word."})]}),t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"What it can reach"}),t.jsxs("p",{className:"cat-prose",children:[x,a.removed.length>0?` No longer: ${a.removed.join(", ")}.`:""]})]}),t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"Missions"}),t.jsxs("p",{className:"cat-prose",children:[a.missionsAdded.length>0?`${ln(a.missionsAdded.map(w=>w.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(w=>t.jsxs("p",{className:"cat-prose",children:[w.name,": new settings — ",w.words,"."]},w.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:[v," no longer has ",ln(a.retires),"; ",a.retires.length===1?"it goes":"they go"," to the trash folder."]})]}):null]})]})}function Rs(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 Sb(){const e=me(()=>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 Cb(){return t.jsx(ie,{name:"check",size:14})}function nq({entry:e,loaded:n,mailbox:s}){const r=Rs(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 ",ln(a.map(kb))]})});if(r!=="ready")return null;const i=QY(e,n,s);if(i.length===0)return null;const l=`Uses ${ln(i)}`;return t.jsx("span",{className:"cat-uses",title:l,children:l})}function sq({entry:e,onAdd:n,onUpdate:s}){const r=Rs(e),a=i=>l=>{l.stopPropagation(),i()};return r==="added"?t.jsxs("span",{className:"cat-added",children:[t.jsx(Cb,{}),"Added"]}):r==="update"?t.jsx(E,{size:"sm",onClick:a(s),"aria-label":`Update ${e.title}`,children:"Update"}):r==="edited"?t.jsx(E,{size:"sm",onClick:a(s),children:"See what changed"}):r==="unavailable"?null:t.jsx(E,{size:"sm",variant:"accent",onClick:a(n),"aria-label":`Add ${e.title}`,children:"Add"})}function rq({entry:e}){var a,i,l,o;const n=Rs(e),s=po(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 _P({entry:e,loaded:n,mailbox:s,onOpen:r,onAdd:a,onUpdate:i}){return t.jsx("div",{className:"cat-card","data-state":Rs(e),"data-testid":`cat-card-${e.name}`,children:t.jsxs(Ar,{onClick:r,label:`${e.title}: details`,children:[t.jsxs("div",{className:"cat-card-head",children:[t.jsx(ul,{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:yb(e.category)})]})]}),t.jsx("p",{className:"cat-pitch",children:e.pitch}),t.jsx(rq,{entry:e}),t.jsxs("div",{className:"cat-card-foot",children:[t.jsx(nq,{entry:e,loaded:n,mailbox:s}),t.jsx(pt,{}),t.jsx(sq,{entry:e,onAdd:a,onUpdate:i})]})]})})}function aq({row:e,agents:n,navigate:s,pages:r}){const a=jb(e.plugin,e.agent,()=>window.dispatchEvent(new Event(ks))),i=a.created??(e.state==="installed"?{id:e.agent,handle:e.handle,name:e.name}:null),l=r?Nv(e.plugin,r.all):Vm(e.plugin);return t.jsx("div",{className:"cat-card","data-state":i?"added":"ready","data-testid":`cat-card-${e.agent}`,children:t.jsxs(Ar,{onClick:i?()=>s(Dt(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(In,{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(ae,{message:a.failure}),t.jsx(pt,{}),i?t.jsxs("span",{className:"cat-added",children:[t.jsx(Cb,{}),"Added"]}):t.jsx(E,{size:"sm",variant:"accent",disabled:a.busy,onClick:o=>{o.stopPropagation(),a.accept()},"aria-label":`Add ${e.name}`,children:"Add"})]})]})})}function iq({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 lq(e,n,s){const r=e.find(a=>a.roles.includes(jr));r&&(s.trim()&&Wu(r.id,`I'd like a teammate for this: ${s.trim()}`),n(lt(r.id)))}function oq({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(FP,{entry:i,agentId:i.installed.agentId,onClose:r,onUpdated:a}):t.jsx(Nb,{entry:i,navigate:s,onClose:r,onAdded:a})}const cq=[{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 uq(e,n){return[e.title,e.pitch,e.about,e.description,yb(e.category)].some(s=>s.toLowerCase().includes(n))}function dq({name:e,agents:n,navigate:s,pluginPages:r}){const[a,i]=d.useState(0),l=me(()=>T.catalogue(a>0),[a]),o=Sb(),[c,u]=d.useState(""),[h,f]=d.useState("all"),[m,p]=d.useState(null),v=l.data,g=()=>{l.reload(),window.dispatchEvent(new Event(ks))},k=()=>i(A=>A+1),j=t.jsx(oq,{sheet:m,view:v,navigate:s,onClose:()=>p(null),onChanged:g}),x=e?v==null?void 0:v.agents.find(A=>A.name===e):void 0,w=d.useRef(!1);if(d.useEffect(()=>{w.current||!x||!uB(window.location.hash,x.name)||(w.current=!0,Rs(x)==="ready"&&p({kind:"install",name:x.name}))},[x]),e&&v&&!v.unavailable&&x)return t.jsxs(t.Fragment,{children:[t.jsx(mq,{entry:x,loaded:o,agents:n,navigate:s,onAdd:()=>p({kind:"install",name:x.name}),onUpdate:()=>p({kind:"update",name:x.name})}),j]});const N=c.trim().toLowerCase(),b=((v==null?void 0:v.agents)??[]).filter(A=>(h==="all"||A.category===h)&&(!N||uq(A,N))),S=((v==null?void 0:v.fromPlugins)??[]).filter(A=>h==="all"&&(!N||[A.name,A.text,A.description].some($=>$.toLowerCase().includes(N)))),C=A=>()=>s(A);return t.jsxs(_y,{children:[t.jsx(Ui,{before:t.jsx(Oc,{inline:!0,items:[{label:"Agents",href:bt,onClick:C(bt)}]}),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&&v&&!v.unavailable&&!x?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(ie,{name:"search",size:16}),t.jsx(Fm,{label:"Search teammates",value:c,placeholder:"Search: meals, money, a language…",onChange:u})]}),t.jsx("div",{className:"cat-cats",children:t.jsx(nR,{label:"Category",options:cq,value:h,onChange:f})})]}),v&&!v.unavailable?v.stale?t.jsxs("p",{className:"plugins-quiet","data-testid":"cat-stale",children:[t.jsx(ie,{name:"globe",size:14}),"From the list kept ",v.fetchedAt?hq(v.fetchedAt):"earlier",": withbuddi.com didn’t answer just now."," ",t.jsx("button",{type:"button",className:"plugins-link",onClick:k,children:"Try again"})]}):t.jsxs("p",{className:"plugins-quiet",children:[t.jsx(ie,{name:"globe",size:14}),"Opening this page fetched the list from withbuddi.com. Nothing else leaves."]}):null,l.error&&!v?t.jsx(be,{warm:!0,title:"The catalogue didn’t load",action:t.jsx(E,{variant:"accent",size:"sm",onClick:k,children:"Try again"}),children:l.error}):v?v.unavailable?t.jsx(be,{warm:!0,title:"The catalogue needs withbuddi.com",action:t.jsx(E,{variant:"accent",size:"sm",disabled:l.loading,onClick:k,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(_P,{entry:A,loaded:o,mailbox:v.mailbox,onOpen:()=>s(pn(A.name)),onAdd:()=>p({kind:"install",name:A.name}),onUpdate:()=>p({kind:"update",name:A.name})},A.name)),S.map(A=>t.jsx(aq,{row:A,agents:n,navigate:s,pages:r},`${A.plugin}/${A.agent}`))]}):t.jsx(be,{warm:!0,title:"No teammate for that yet",action:t.jsxs("span",{className:"cat-empty-acts",children:[t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>{u(""),f("all")},children:"Show all"}),t.jsx(E,{size:"sm",variant:"accent",onClick:()=>lq(n,s,c),children:"Ask Agent Father"})]}),children:N?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(iq,{}),v&&!v.unavailable&&v.delisted.length>0?t.jsx(st,{title:"No longer in the catalogue",children:t.jsx("ul",{className:"cat-plugins","data-testid":"cat-delisted",children:v.delisted.map(A=>t.jsxs("li",{children:[t.jsx(an,{agents:n,id:A.agentId,size:"sm"}),t.jsxs("span",{className:"cat-plugin-text",children:[t.jsx("a",{className:"cat-plugin-name",href:Dt(A.agentId),onClick:$=>{$.preventDefault(),s(Dt(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,j]})}function hq(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 Ai({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 fq({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?Nf(c):null,h=o?bb(i).title:(c==null?void 0:c.kind)==="plugin"?c.title:Vm(i),f=o?l&&!c:n.has(i);return t.jsxs("li",{children:[t.jsx("span",{className:"ui-app-icon","aria-hidden":"true",children:t.jsx(ie,{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(E,{size:"sm",onClick:()=>s(u.route),children:u.label}):c?t.jsx("span",{className:"cat-small",children:"Installed when you add it"}):f?t.jsxs("span",{className:"cat-added",children:[t.jsx(Cb,{}),o?"You have one":"Installed"]}):t.jsx("span",{className:"cat-small",children:o?"Optional":"Not installed"})]},`${o?"need":"plugin"}-${i}`)})})}function mq({entry:e,loaded:n,agents:s,navigate:r,onAdd:a,onUpdate:i}){var v,g,k,j;const l=Rs(e),c=(v=e.installed)==null?void 0:v.agentId,u=po(e.version),h=(g=e.installed)!=null&&g.via?e.installed:void 0,f=x=>{c&&(x&&Wu(c,x),r(lt(c)))},m=Sf(e.tools,Cf((k=e.claims)==null?void 0:k.tools)),p=e.replaces.map(x=>yg(x.split("/")[1]??x));return t.jsxs(_y,{children:[t.jsxs("a",{className:"cat-back",href:pn(),onClick:x=>{x.preventDefault(),r(pn())},children:[t.jsx(ie,{name:"chevron-left",size:12}),"Teammates"]}),t.jsxs("header",{className:"cat-hero",children:[t.jsx(ul,{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(Se,{tone:"accent",children:"by buddi"}):null,t.jsx("span",{children:yb(e.category)}),t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("span",{className:"mono",children:h?e.version:((j=e.installed)==null?void 0:j.version)??e.version}),e.installed?t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsxs("span",{children:["on your team as ",t.jsxs("span",{className:"mono",children:["@",e.installed.handle]})]})]}):null]})]}),t.jsx("div",{className:"cat-hero-act",children:l==="ready"?t.jsxs(E,{variant:"accent",onClick:a,children:["Add ",e.title]}):l==="update"?t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:()=>f(),children:"Open chat"}),t.jsx(E,{variant:"accent",onClick:i,children:h?`Update @${h.handle} to ${e.title}`:`Update to ${u}`})]}):l==="edited"?t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:()=>f(),children:"Open chat"}),t.jsx(E,{onClick:i,children:"See what changed"})]}):l==="unavailable"?null:t.jsx(E,{variant:"accent",onClick:()=>f(),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(st,{flush:!0,children:t.jsxs("div",{className:"cat-rows",children:[t.jsxs(Ai,{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 ",ln(p)," did. If you have ",ln(p)," and haven’t changed it, it’s offered as an update."]}):null]}),e.examples.length>0?t.jsxs(Ai,{title:"Ask it",children:[t.jsx("div",{className:"wb-starters",children:e.examples.map(x=>t.jsx("button",{type:"button",className:"wb-starter",disabled:!c,onClick:()=>f(x),children:x},x))}),c?null:t.jsx("p",{className:"cat-small",children:"Once it’s on your team, a tap opens a chat with it."})]}):null,t.jsx(Ai,{title:"Skills",children:e.skills.length===0?t.jsx("p",{className:"cat-small",children:"None. It works from its persona."}):t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"cat-plugins","data-testid":"cat-skills",children:e.skills.map(x=>t.jsxs("li",{children:[t.jsx("span",{className:"ui-app-icon","aria-hidden":"true",children:t.jsx(ie,{name:"files",size:14})}),t.jsxs("span",{className:"cat-plugin-text",children:[t.jsx("span",{className:"cat-plugin-name",children:yg(x.name)}),x.description?t.jsx("span",{className:"cat-small",children:x.description}):null,t.jsx(Gt,{summary:"Read it",children:t.jsx(Bt,{label:`${yg(x.name)}: the skill's text`,children:x.text})})]})]},x.name))}),t.jsxs("p",{className:"cat-small",children:["Plain text, no code."," ",c?t.jsxs(t.Fragment,{children:["Read and change them on ",t.jsx("a",{href:Dt(c,"skills"),onClick:x=>{x.preventDefault(),r(Dt(c,"skills"))},children:"its Skills tab"}),"."]}):"Once it’s on your team they’re files you can read and change."]})]})}),t.jsxs(Ai,{title:"What it can reach",children:[t.jsx("dl",{className:"cat-reach",children:m.map(([x,w])=>t.jsxs("div",{className:"cat-reach-row",children:[t.jsx("dt",{children:x}),t.jsx("dd",{children:w})]},x))}),t.jsx("p",{className:"cat-small",children:"Anything that sends or pays still asks you first, every time. You can change any of this on its page."})]}),t.jsx(Ai,{title:"Missions",children:e.missions.length>0?t.jsx("ul",{className:"cat-missions",children:e.missions.map(x=>t.jsxs("li",{children:[t.jsx("span",{className:"cat-mission-name",children:x.name}),t.jsx("span",{className:"cat-mission-when",children:x.when}),t.jsx("span",{className:"cat-off",children:"off until you turn it on"})]},x.id))}):t.jsx("p",{className:"cat-small",children:"None. It works when you ask."})}),t.jsx(Ai,{title:"Plugins",children:t.jsx(fq,{entry:e,loaded:n,navigate:r})}),t.jsxs(Ai,{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 zP({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 pq(e,n,s=4){const r=i=>!!i&&Rs(i)==="ready"&&i.addable,a=zP(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 NC=["researcher","tutor"];function SC(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 gq(e,n,s=4){const r=[];for(const a of zP(n).filter(i=>!NC.includes(i))){const i=e.find(h=>h.name===a);if(!i||Rs(i)!=="ready")continue;if(i.addable){r.push({entry:i,reason:SC(a,n)});continue}const l=i.missing??[],o=l.find(h=>Nf(h)!==null)??l[0];if(!o)continue;const c=Nf(o),u=c?c.label.charAt(0).toLowerCase()+c.label.slice(1):`${kb(o)} is here`;r.push({entry:i,reason:SC(a,n),blocked:{step:u,fix:c}})}for(const a of NC){if(r.length>=3)break;const i=e.find(l=>l.name===a);i&&Rs(i)==="ready"&&i.addable&&r.push({entry:i,reason:"popular"})}return r.slice(0,s)}const xq={image:"makes pictures",finance:"keeps your books",calendar:"looks after your days",email:"reads your mail"};function UP(e,n){const s=xq[e];return s?`Nobody ${s} yet`:`Nobody uses ${n??e.charAt(0).toUpperCase()+e.slice(1)} yet`}function BP(e,n){const s=e.filter(r=>Object.keys(r.requires??{}).includes(n));if(!s.some(r=>Rs(r)!=="ready"&&Rs(r)!=="unavailable"))return s.find(r=>Rs(r)==="ready")}function CC(e,n){const s=[];for(const r of n){const a=BP(e,r);a&&!s.some(i=>i.entry.name===a.name)&&s.push({plugin:r,entry:a})}return s}const zc=e=>`teammate:${e}`;function WP({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,f]=d.useState(!1);if(d.useEffect(()=>{let p=!1;return Promise.resolve().then(()=>T.catalogue()).then(async v=>{const g=v.unavailable?void 0:BP(v.agents,e);return!g||!r?g??null:(await Promise.resolve().then(()=>T.overview()).then(j=>j.dismissed??{},()=>({})))[zc(e)]!==g.name?g:null}).then(v=>{p||i(v)}).catch(()=>{p||i(null)}),()=>{p=!0}},[e,r]),!a||c||h)return null;const m=()=>{f(!0),T.homeDismiss(zc(e),a.name).catch(()=>f(!1))};return t.jsxs(t.Fragment,{children:[t.jsx(Q,{action:t.jsxs(re,{children:[r?t.jsx(E,{size:"sm",variant:"ghost",onClick:m,children:"Not now"}):null,t.jsxs(E,{size:"sm",onClick:()=>o(!0),children:["Add ",a.title]})]}),children:t.jsx("span",{"data-testid":"plugin-teammate",children:UP(e,n)})}),l?t.jsx(Nb,{entry:a,navigate:s,onClose:()=>o(!1),onAdded:()=>{u(!0),window.dispatchEvent(new Event(ks))}}):null]})}function vq(e,n){const s=e.filter(r=>r.id!==n&&!r.roles.includes(Yu)&&!r.roles.includes(jr));return e.length>0&&s.length<=1}async function jq(e,n=LP){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 he?s.message:String(s)}}}function wq({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(ul,{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 yq({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(ul,{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(E,{size:"sm",onClick:()=>n(a.fix.route),children:a.fix.label}):null]})}function bq({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(ul,{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(ie,{name:"check",size:14}),"Added"]}):t.jsx(E,{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(ie,{name:"close"})}):null]})}function kq({navigate:e,newTeam:n=!0,closed:s}){const[r,a]=d.useState(null),[i,l]=d.useState(null),[o,c]=d.useState([]),u=Sb();d.useEffect(()=>{let m=!1;return T.catalogue().then(p=>{m||a(p.unavailable?[]:p.agents)}).catch(()=>{m||a([])}),()=>{m=!0}},[]);const h=d.useMemo(()=>r===null?[]:CC(r,u).filter(m=>!(s!=null&&s.is(zc(m.plugin),m.entry.name))),[r,u,s]),f=d.useMemo(()=>{if(r===null)return null;const m=h.map(g=>g.entry);if(!n)return m;const p=new Set(CC(r,u).filter(g=>s==null?void 0:s.is(zc(g.plugin),g.entry.name)).map(g=>g.entry.name)),v=pq(r,{days:!0,mailbox:!0,money:u.has("finance"),pictures:u.has("image")},3+p.size).filter(g=>!m.some(k=>k.name===g.name)&&!p.has(g.name));return[...m,...v].slice(0,Math.max(3,m.length))},[r,u,h,n,s]);return!f||f.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:f.map(m=>{const p=h.find(v=>v.entry.name===m.name);return t.jsx(bq,{entry:m,added:o.includes(m.name),onOpen:()=>e(pn(m.name)),onAdd:()=>l(m),...p&&s&&!o.includes(m.name)?{onDismiss:()=>s.close(zc(p.plugin),m.name),why:UP(p.plugin)}:{}},m.name)})}),i?t.jsx(Nb,{entry:i,navigate:e,onClose:()=>l(null),onAdded:()=>{c(m=>[...m,i.name]),window.dispatchEvent(new Event(ks))}}):null]})}function Nq(){const[e,n]=d.useState(null);return d.useEffect(()=>{let s=!1;const r=()=>{Promise.resolve().then(()=>Qe.agents()).then(a=>{s||n(((a==null?void 0:a.agents)??[]).filter(i=>!i.roles.includes(jr)).map(i=>i.name))}).catch(()=>{s||n(a=>a??[])})};return r(),window.addEventListener(ks,r),()=>{s=!0,window.removeEventListener(ks,r)}},[]),e}function Sq({setUp:e,navigate:n}){var b;const s=Nq(),[r,a]=d.useState(null),[i,l]=d.useState([]),[o,c]=d.useState("picking"),[u,h]=d.useState([]),[f,m]=d.useState([]),p=JSON.stringify(e);d.useEffect(()=>{let S=!1;return T.catalogue().then(C=>{if(S)return;const A=C.unavailable?[]:gq(C.agents,e);a(A),l(A.filter($=>!$.blocked).map($=>$.entry.name))}).catch(()=>{S||a([])}),()=>{S=!0}},[p]);const v=s??[];if(!r||r.length===0&&v.length===0)return null;const g=v.length===0?null:t.jsxs("p",{className:"cat-small","data-testid":"handover-team-now",children:["On your team: ",ln(v),"."]}),k=r.filter(S=>!S.blocked).map(S=>S.entry),j=r.some(S=>!S.blocked&&S.reason!=="popular"),x=()=>n(pn()),w=async()=>{c("adding");const S=[],C=[];for(const A of k.filter($=>i.includes($.name))){const $=await jq(A);"error"in $&&!("state"in $)?C.push({entry:A,error:$.error}):$.state==="done"?S.push(A):$.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:$.error??"it stopped before it finished"})}h(S),m(C),c("added"),S.length>0&&window.dispatchEvent(new Event(ks))},N=i.length,y=o==="adding"?`Adding ${N===1?((b=k.find(S=>S.name===i[0]))==null?void 0:b.title)??"1":N}…`:N>0&&N===k.length?"Add these":N>0?`Add these ${N}`:"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:`${ln(u.map(S=>S.title))} ${u.length===1?"is":"are"} on your team.`,action:t.jsx(E,{variant:"ghost",size:"sm",onClick:x,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,f.length>0?t.jsxs(Q,{tone:"critical",role:"alert",title:`${ln(f.map(S=>S.entry.title))} ${f.length===1?"wasn’t":"weren’t"} added.`,action:u.length===0?t.jsx(E,{variant:"ghost",size:"sm",onClick:x,children:"See all teammates"}):void 0,children:[f.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:j?"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(yq,{suggestion:S,onFix:n},S.entry.name):t.jsx(wq,{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(re,{children:[t.jsx(E,{variant:"ghost",onClick:x,children:"See all teammates"}),t.jsx(pt,{}),t.jsx(E,{variant:"accent",disabled:N===0||o==="adding"||k.length===0,onClick:()=>void w(),children:y})]})})]})]})})}const Cq=512*1024,Eq=/^[A-Za-z0-9+/]*={0,2}$/;function HP(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===""||!Eq.test(r)||Math.floor(r.length*3/4)>Cq+2?null:{mime:s,data:r}}function KP(e){const n=e==null?void 0:e.message;return typeof n=="string"&&n.trim()!==""?n:null}let ca=null,Uc=null,Au=null;const ij=new Set;function VP(){for(const e of ij)e()}function kc(){ca&&(ca.onended=null,ca.onerror=null,ca.pause()),Uc&&URL.revokeObjectURL(Uc),Uc=null,Au!==null&&(Au=null,VP())}async function GP(e,n){kc();const s=atob(e.data),r=new Uint8Array(s.length);for(let a=0;a<s.length;a+=1)r[a]=s.charCodeAt(a);ca??(ca=new Audio),Uc=URL.createObjectURL(new Blob([r],{type:e.mime})),Au=n,ca.onended=kc,ca.onerror=kc,ca.src=Uc,VP();try{await ca.play()}catch{throw kc(),new Error("The browser would not play the sound.")}}function EC(e){e!==void 0&&Au!==e||kc()}function Aq(){return d.useSyncExternalStore(e=>(ij.add(e),()=>ij.delete(e)),()=>Au,()=>null)}const $q=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Pr=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],AC=/^\d{4}-\d{2}-\d{2}$/;function Wi(e){return e.split("-").map(Number)}function ji(e,n){const[s,r,a]=Wi(e);return new Date(Date.UTC(s,r-1,a+n)).toISOString().slice(0,10)}function YP(e){const[n,s,r]=Wi(e);return new Date(Date.UTC(n,s-1,r)).getUTCDay()}function qP(e){return $q[YP(e)]}function QP(e){return Wi(e)[2]}function $C(e){return ji(e,-((YP(e)+6)%7))}function ss(e){return Po(e,{weekday:!0,compact:!0})}function Tq(e,n){return e===n?`Today · ${ss(e)}`:e===ji(n,1)?`Tomorrow · ${ss(e)}`:ss(e)}function dr(e){return Gz(e)}const TC=new Map;function lj(e,n){let s=TC.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"}),TC.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 Iq(e,n=new Date){return lj(n,e).date}function Rq(e,n){return e==="week"?{from:$C(n),days:7}:e==="month"?{from:$C(`${n.slice(0,8)}01`),days:42}:{from:n,days:7}}function Pq(e,n,s){if(e!=="month")return ji(n,s*7);const[r,a]=Wi(n);return new Date(Date.UTC(r,a-1+s,1)).toISOString().slice(0,10)}function Mq(e,n,s,r){const[a,i]=Wi(n);if(e==="month")return jT(a,i);const l=ji(s,r-1),[o,c,u]=Wi(s),[h,f,m]=Wi(l);return xT().date==="iso"?`${s} – ${l}`:Yz()?c===f&&o===h?`${Pr[c-1]} ${u} – ${m}, ${h}`:o===h?`${Pr[c-1]} ${u} – ${Pr[f-1]} ${m}, ${h}`:`${Pr[c-1]} ${u}, ${o} – ${Pr[f-1]} ${m}, ${h}`:c===f&&o===h?`${u} – ${m} ${Pr[f-1]} ${h}`:o===h?`${u} ${Pr[c-1]} – ${m} ${Pr[f-1]} ${h}`:`${u} ${Pr[c-1]} ${o} – ${m} ${Pr[f-1]} ${h}`}function Sl(e){return e==null?"":String(e)}function Oq(e,n,s,r){const a=[],i=new Set;return e.forEach((l,o)=>{const c=Sl(Ae(l,n.id)),u=Sl(Ae(l,n.title)),h=Sl(Ae(l,n.start)),f=Sl(Ae(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 m=n.allDay===void 0?void 0:Ae(l,n.allDay),p=m===void 0?AC.test(h):m===!0||m==="true",v=n.tone===void 0?0:Number(Ae(l,n.tone)),g=Number.isFinite(v)?(Math.trunc(v)%4+4)%4:0,k={id:c,title:u,calendar:n.calendar===void 0?"":Sl(Ae(l,n.calendar)),tone:g,location:n.location===void 0?"":Sl(Ae(l,n.location)),row:l};if(p){const y=h.slice(0,10),b=AC.test(f.slice(0,10))&&f.slice(0,10)>y?f.slice(0,10):ji(y,1);a.push({...k,allDay:!0,startDate:y,startMin:0,endDate:b,endMin:0});return}const j=new Date(h);if(Number.isNaN(j.getTime())){console.warn(`buddi: ${r}: event ${o} starts at "${h}", which is not a time — not drawn`);return}const x=new Date(f),w=lj(j,s),N=Number.isNaN(x.getTime())||x<j?w:lj(x,s);a.push({...k,allDay:!1,startDate:w.date,startMin:w.minutes,endDate:N.date,endMin:N.minutes})}),a}function Dq(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 Eb(e,n){return e.map(s=>({event:s,part:Dq(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 Ab(e,n){if(n.allDay)return"All day";const s=e.startDate!==e.endDate;return s&&n.from===0?`until ${dr(n.to)}`:s&&n.to===1440?`from ${dr(n.from)}`:n.from===n.to?dr(n.from):`${dr(n.from)}–${dr(n.to)}`}function oj(e,n,s){return[Ab(e,n),e.title,e.location,e.calendar,ss(s)].filter(Boolean).join(", ")}const JP=30;function Lq(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+JP);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 Fq(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 _q(e){if(e.allDay){const a=ji(e.endDate,-1);return a>e.startDate?`${ss(e.startDate)} – ${ss(a)} · all day`:`${ss(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?`${ss(e.startDate)} · ${dr(e.startMin)}–${dr(e.endMin)}`:`${ss(e.startDate)} ${dr(e.startMin)} – ${ss(e.endDate)} ${dr(e.endMin)}`;return s>0?`${r} · ${Fq(s)}`:r}const zq={week:"Week",month:"Month",list:"List"},Uq=["week","month","list"],Bq="(max-width: 720px)";function Wq(e){try{return window.localStorage.getItem(e)}catch{return null}}function Hq(e,n){try{window.localStorage.setItem(e,n)}catch{}}function Kq(e){const n=e.views&&e.views.length>0?e.views:Uq,s=Yn(Bq),[r,a]=d.useState(()=>{const p=Wq(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:f,days:m}=Rq(l,o);return{views:n,view:l,setView:p=>{a(p),Hq(e.storageKey,p),h(null)},anchor:o,today:e.today,go:p=>{c(p===0?e.today:Pq(l,o,p)),h(null)},from:f,days:m,to:ji(f,m),selected:u,select:h}}function Vq({state:e,events:n,hours:s,empty:r,label:a,onEvent:i,count:l}){const{view:o,anchor:c,today:u,from:h,days:f}=e,m=d.useMemo(()=>Array.from({length:f},(j,x)=>ji(h,x)),[h,f]),p=o==="month"?"month":"week",v=e.selected??(c.slice(0,7)===u.slice(0,7)?u:`${c.slice(0,8)}01`),g=o==="month"?v:o==="week"&&!i?e.selected:null,k=j=>{if(!j.target.closest('input, textarea, select, [contenteditable="true"]')&&!(j.altKey||j.ctrlKey||j.metaKey)){if(j.key==="ArrowLeft")e.go(-1);else if(j.key==="ArrowRight")e.go(1);else if(j.key==="t"||j.key==="T")e.go(0);else return;j.preventDefault()}};return t.jsxs("div",{className:"cal",role:"region","aria-label":a,tabIndex:0,onKeyDown:k,children:[t.jsxs("div",{className:"cal-bar",children:[t.jsx(E,{size:"sm","aria-label":`Previous ${p}`,onClick:()=>e.go(-1),children:t.jsx(ie,{name:"chevron-left",size:14})}),t.jsx(E,{size:"sm",onClick:()=>e.go(0),children:"Today"}),t.jsx(E,{size:"sm","aria-label":`Next ${p}`,onClick:()=>e.go(1),children:t.jsx(ie,{name:"chevron-right",size:14})}),t.jsxs("h3",{className:"cal-title","aria-live":"polite",children:[Mq(o,c,h,f),l!==void 0?t.jsx("span",{className:"cal-count",children:l===0?"No events":l===1?"1 event":`${l} events`}):null]}),e.views.length>1?t.jsx(Xt,{label:"View",options:e.views.map(j=>({value:j,label:zq[j]})),value:o,onChange:e.setView}):null]}),o==="week"?t.jsx(Gq,{dates:m,today:u,events:n,hours:s??[7,21],onPick:e.select,onEvent:i}):null,o==="month"?t.jsx(qq,{dates:m,month:c.slice(0,7),today:u,events:n,selected:v,onPick:e.select,onEvent:i}):null,o==="list"?t.jsx("div",{className:"cal-list",children:m.map(j=>t.jsx(IC,{date:j,today:u,events:n,empty:r,onEvent:i},j))}):null,g?t.jsx(IC,{date:g,today:u,events:n,empty:r,onEvent:i}):null]})}function IC({date:e,today:n,events:s,empty:r,onEvent:a}){const i=Eb(s,e);return t.jsx(st,{flush:!0,title:Tq(e,n),children:t.jsx(dt,{children:i.length===0?t.jsx(ot,{title:t.jsx("span",{className:"muted",children:r})}):i.map(({event:l,part:o})=>t.jsx(ot,{lead:t.jsx("span",{className:"cal-dot","data-tone":l.tone,"aria-hidden":"true"}),title:l.title,sub:l.location||void 0,side:Ab(l,o),...a?{onClick:()=>a(l)}:{}},l.id))})})}function Gq({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=Qq(l),c=e.map(h=>({date:h,items:Eb(s,h)})),u=h=>h===n?"true":void 0;return t.jsx(st,{flush:!0,children:t.jsxs("div",{className:"cal-week",role:"grid","aria-label":`Week of ${ss(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":ss(h),children:[t.jsx("span",{className:"cal-wd",children:qP(h)}),t.jsx("span",{className:"cal-num",children:QP(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:f})=>t.jsx("div",{className:"cal-allday-cell",role:"gridcell","data-today":u(h),children:f.filter(m=>m.part.allDay).map(({event:m,part:p})=>t.jsx("button",{type:"button",className:"cal-chip","data-tone":m.tone,"aria-label":oj(m,p,h),onClick:()=>i?i(m):a(h),children:m.title},m.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,f)=>f+1).map(h=>t.jsx("span",{className:"cal-hour-label",style:{top:`calc(var(--cal-hour) * ${h})`},children:dr(h*60)},h))}),c.map(({date:h,items:f})=>t.jsx("div",{className:"cal-col",role:"gridcell","aria-label":ss(h),"data-today":u(h),children:Lq(f.filter(m=>!m.part.allDay)).map(({event:m,part:p,lane:v,lanes:g})=>t.jsxs("button",{type:"button",className:"cal-event","data-tone":m.tone,"data-short":p.to-p.from<60?"true":void 0,"data-lane":v,"aria-label":oj(m,p,h),onClick:()=>i?i(m):a(h),style:{top:`calc(var(--cal-hour) * ${p.from/60})`,height:`calc(var(--cal-hour) * ${Math.max(p.to-p.from,JP)/60})`,left:`calc((100% - var(--space-1)) * ${v/g} + var(--space-0))`,width:`calc((100% - var(--space-1)) / ${g} - var(--space-0))`},children:[t.jsx("span",{className:"cal-event-time",children:Ab(m,p)}),t.jsx("span",{className:"cal-event-title",children:m.title})]},m.id))},h))]})})]})})}const Yq=3;function qq({dates:e,month:n,today:s,events:r,selected:a,onPick:i,onEvent:l}){const o=Array.from({length:6},(f,m)=>e.slice(m*7,m*7+7)),[c,u]=n.split("-").map(Number),h=jT(c,u);return t.jsx(st,{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(f=>t.jsx("div",{className:"cal-wd-head",role:"columnheader",children:qP(f)},f))}),o.map(f=>t.jsx("div",{className:"cal-row",role:"row",children:f.map(m=>{const p=Eb(r,m),v=p.slice(0,Yq),g=p.length-v.length,k=p.length===0?"nothing":p.length===1?"1 event":`${p.length} events`;return t.jsxs("div",{className:"cal-cell",role:"gridcell","aria-selected":m===a,"data-date":m,"data-today":m===s?"true":void 0,"data-outside":m.slice(0,7)!==n?"true":void 0,"data-selected":m===a?"true":void 0,onClick:()=>i(m),children:[t.jsx("button",{type:"button",className:"cal-num","aria-label":`${ss(m)}, ${k}`,"aria-pressed":m===a,children:QP(m)}),v.map(({event:j,part:x})=>t.jsx("button",{type:"button",className:"cal-chip","data-tone":j.tone,"data-timed":x.allDay?void 0:"true","aria-label":oj(j,x,m),...l?{onClick:w=>{w.stopPropagation(),i(m),l(j)}}:{},children:x.allDay?j.title:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"cal-dot","data-tone":j.tone,"aria-hidden":"true"}),t.jsx("span",{className:"cal-chip-time",children:dr(x.from)})," ",j.title]})},j.id)),g>0?t.jsxs("button",{type:"button",className:"cal-more","aria-label":`${g} more on ${ss(m)}`,children:["+",g]}):null]},m)})},f[0]))]})})}function Qq(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 XP={width:1200,height:200,top:28,right:12,bottom:24,left:36};function Jq(e,n){if(n==="percent")return[0,50,100];let s=e.length>0?Math.min(...e):0,r=e.length>0?Math.max(...e):1;n!=="temp"&&(s=Math.min(0,s)),s===r&&(s-=1,r+=1);const a=10**Math.floor(Math.log10(Math.max(1,(r-s)/3))),i=c=>Math.ceil(r/c)-Math.floor(s/c);let l=[1,2,5,10].map(c=>c*a).find(c=>i(c)<=3)??a*10;i(l)<2&&(l>1?l/=2:r+=l);const o=[];for(let c=Math.floor(s/l)*l;c<=Math.ceil(r/l)*l+l/1e3;c+=l)o.push(Math.round(c*1e6)/1e6);return o}function Vd(e,n){return n==="temp"?`${e}°`:n==="percent"?`${e}%`:String(e)}function Xq(e){const n=XP,s=e.values.length,r=n.width-n.left-n.right,a=n.height-n.top-n.bottom,i=n.height-n.bottom,l=s>0?r/s:r,o=j=>Ri(n.left+l*(j+.5)),c=e.values.filter(j=>j!==null&&Number.isFinite(j)),u=Jq(c,e.unit),h=u[0],f=u[u.length-1],m=j=>Ri(n.top+a-(j-h)/(f-h)*a),p=e.values.map((j,x)=>{const w=j!==null&&Number.isFinite(j);return{index:x,x:o(x),y:w?m(j):null,value:w?j:null}}),v=[],g=[];if(e.kind==="area"){let j=[];const x=()=>{if(j.length===0)return;const w=j.map((N,y)=>`${y===0?"M":"L"}${N.x},${N.y}`).join(" ");v.push(w),g.push(`${w} L${j[j.length-1].x},${i} L${j[0].x},${i} Z`),j=[]};for(const w of p)w.y===null?x():j.push(w);x()}const k=e.kind==="bars"?p.flatMap(j=>j.y===null?[]:[{index:j.index,x:Ri(j.x-l*.28),y:j.y,width:Ri(l*.56),height:Ri(i-j.y)}]):[];return{ticks:u.map(j=>({value:j,y:m(j)})),lines:v,areas:g,bars:k,points:p,slot:l,floor:i}}function Zq({title:e,note:n,xs:s,series:r,tiles:a,labelEvery:i=3}){var y;const[l,o]=d.useState(((y=r[0])==null?void 0:y.id)??""),[c,u]=d.useState(null),[h,f]=d.useState(null),m=d.useRef(null),p=s.length,v=c??h,g=r.find(b=>b.id===l)??r[0],k=Xq(g),j=XP,x=b=>b%i===0||b===v,w=g.values.filter(b=>b!==null&&Number.isFinite(b));d.useEffect(()=>{const b=m.current,S=v===null?null:b==null?void 0:b.children[v];!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"}))},[v]);const N=b=>{var A,$,I;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(),f(C),(I=($=(A=m.current)==null?void 0:A.children[C])==null?void 0:$.querySelector("button"))==null||I.focus())};return t.jsxs(st,{...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 ${j.width} ${j.height}`,"aria-hidden":"true",focusable:"false","data-testid":"series-svg",children:[k.ticks.map(b=>t.jsxs("g",{children:[t.jsx("line",{className:"pg-series-grid",x1:j.left,x2:j.width-j.right,y1:b.y,y2:b.y}),t.jsx("text",{className:"pg-series-tick",x:j.left-8,y:b.y,textAnchor:"end",dominantBaseline:"middle",children:Vd(b.value,g.unit)})]},b.value)),k.areas.map((b,S)=>t.jsx("path",{className:"pg-series-area",d:b},`a${S}`)),k.lines.map((b,S)=>t.jsx("path",{className:"pg-series-line",d:b},`l${S}`)),k.bars.map(b=>t.jsx("rect",{className:"pg-series-bar","data-index":b.index,"data-hover":b.index===v?"true":void 0,x:b.x,y:b.y,width:b.width,height:b.height},b.index)),v!==null&&k.points[v]?t.jsx("line",{className:"pg-series-guide","data-index":v,x1:k.points[v].x,x2:k.points[v].x,y1:j.top-4,y2:k.floor}):null,g.kind==="area"?k.points.map(b=>b.y!==null&&x(b.index)?t.jsx("circle",{className:"pg-series-dot","data-index":b.index,"data-hover":b.index===v?"true":void 0,cx:b.x,cy:b.y,r:b.index===v?5:3},b.index):null):null,k.points.map(b=>b.y!==null&&b.value!==null&&x(b.index)?t.jsx("text",{className:"pg-series-value","data-index":b.index,"data-hover":b.index===v?"true":void 0,x:b.x,y:b.y-(g.kind==="area"?10:6),textAnchor:"middle",children:Vd(b.value,g.unit)},b.index):null),k.points.map(b=>b.index%i===0?t.jsx("text",{className:"pg-series-x",x:b.x,y:j.height-6,textAnchor:"middle",children:s[b.index]},b.index):null),k.points.map(b=>t.jsx("rect",{className:"pg-series-hit","data-index":b.index,x:Ri(j.left+k.slot*b.index),y:0,width:Ri(k.slot),height:j.height,onMouseEnter:()=>u(b.index),onClick:()=>f(b.index)},b.index))]}),t.jsx("figcaption",{className:"sr-only",children:w.length===0?`${g.label}: no values.`:`${g.label}, ${p} ${p===1?"point":"points"} from ${s[0]} to ${s[p-1]}: lowest ${Vd(Math.min(...w),g.unit)}, highest ${Vd(Math.max(...w),g.unit)}.`})]}),t.jsx("ul",{className:"wb-tiles","data-layout":"strip",ref:m,onKeyDown:N,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===v?"true":void 0,"aria-pressed":S===h,"aria-label":[b.label,b.value,...b.lines].filter(C=>C!=="").join(", "),onMouseEnter:()=>u(S),onClick:()=>f(S),children:t.jsxs("div",{className:"wb-tile-body","aria-hidden":"true",children:[t.jsx("span",{className:"wb-tile-icon","data-icon":b.icon??"dot",children:t.jsx(ie,{name:zo(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 Ri(e){return Math.round(e*10)/10}function ZP(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 eQ(e,n){d.useEffect(()=>{if(e)return ZP(()=>n())},[e])}function $b(){const[e,n]=d.useState(!1);return eQ(e,()=>n(!1)),[e,()=>n(s=>!s)]}const RC=5*6e4;let eM=0,Gd,hc;const cj=new Set;function tQ(){for(const e of cj)e()}function uj(e,n=Date.now()){Gd!==void 0&&clearTimeout(Gd),Gd=void 0,eM=e?n+RC:0,e&&(Gd=setTimeout(()=>uj(!1),RC)),e&&!hc&&typeof window<"u"&&(hc=ZP(()=>uj(!1))),!e&&hc&&(hc(),hc=void 0),tQ()}function Ng(){return eM>0}function nQ(e){return cj.add(e),()=>cj.delete(e)}function tM(){return[d.useSyncExternalStore(nQ,Ng,Ng),()=>uj(!Ng())]}const Tb=d.createContext(null),Ef=d.createContext(!1);function xt(){const e=d.useContext(Tb);if(!e)throw new Error("a plugin page component outside a plugin page");return e}function Af(e,n=new Set){if(Array.isArray(e))for(const s of e)Af(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))Af(r,n)}return n}function nM(e,n){if(n.size===0)return!1;for(const s of Af(e))if(n.has(s))return!0;return!1}function sQ(e,n){var s;for(const r of Af(e))if((((s=n[r])==null?void 0:s.length)??0)>0)return!0;return!1}function rQ(){const[e,n]=tM();return t.jsx(Yy,{shown:e,onToggle:n,show:"Show amounts",hide:"Hide amounts"})}function sM({revealed:e,onToggle:n}){return t.jsx(Yy,{size:"sm",shown:e,onToggle:n})}function rM(){return t.jsx("p",{className:"muted",children:"Hidden until you show it."})}function aM({children:e}){const[n,s]=$b();return t.jsxs(ue,{gap:"sm",children:[t.jsx(re,{align:"end",children:t.jsx(sM,{revealed:n,onToggle:s})}),n?t.jsx(Ef.Provider,{value:!0,children:e}):t.jsx(rM,{})]})}function Ib(e){return e===void 0||e==="neutral"?void 0:e}function dj(e){return Ib(e)}function aQ(e){const n=Ib(e);return n==="accent"?void 0:n}function Lt(e,n){if(!n)return!0;const s=Ae(e,n.path),r=n.in!==void 0?n.in.includes(s):s===n.equals;return n.not===!0?!r:r}function $f(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 iQ({plugin:e,images:n,row:s}){const a=(Array.isArray(n)?n.map(l=>({asset:Ve(s,l.asset),label:String(Ve(s,l.label)??"").trim()})):(()=>{const l=Ae(s,n.from);return(Array.isArray(l)?l:[]).map(o=>({asset:Ae(o,n.asset),label:String(Ae(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(Bo,{src:Zu(e,l.asset),label:l.label},o))}),t.jsx("span",{className:"pl-stack-words",children:i})]})}function go({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 Ca(e,n,s){if("href"in n)return $f(Ve(s,n.href))??"";if("chat"in n){const i=Ve(s,n.chat);return i==null?"":lt(String(i))}if("proposals"in n)return bB(e.plugin);const r=e.pages.find(i=>i.id===n.page);if((r==null?void 0:r.place)==="settings")return vr(e.plugin,n.page);const a=n.item===void 0?null:Ve(s,n.item);return Yr(e.plugin,n.page,a==null?null:String(a))}function gs(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=Ae(n.row,r);return a==null?"":String(a)})}function Tf(e,n){if(e===void 0)return;if(typeof e=="string")return e;const s=Ve(n,e);return s==="good"||s==="warning"||s==="critical"||s==="neutral"?s:void 0}function iM(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=Ve(Ja(n),i),!(l==null||l==="")&&(r[a]=String(l))}return r}function zs(e,n){var r,a,i;const s={};for(const[l,o]of Object.entries(e??{}))if("row"in o)s[l]=Ae(Ja(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]=Ve(Ja(n.data),o);return s}function Nn(e,n,s,r){const a=xt(),i=e?iM(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=me(()=>e?T.pageQuery(a.plugin,e.query,l).then(v=>({asked:o,data:v.data})):Promise.resolve({asked:o,data:void 0}),[c],s),h=u.data!==void 0&&u.data.asked===o,f=e&&!a.amountsShown?a.sensitivePaths[e.query]:void 0,m=h?u.data.data:void 0;return{data:d.useMemo(()=>AW(m,f),[m,f]),error:h||!u.loading?u.error:null,loading:u.loading}}function ea(){const e=xt(),n=d.useId(),[s,r]=d.useState(null),[a,i]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(0),v=(w,N)=>{if(w.done===void 0)return null;if(typeof w.done=="string")return w.done;const y=Ve(N,w.done);return y==null?null:String(y)},g=(w,N,y)=>{p(S=>S+1);const b=w??"refresh";if(typeof b=="object"){const S="href"in b.route?"":Ca(e,b.route,N);S===""?e.refresh():e.navigate(S);return}b==="close"&&(y==null||y()),e.refresh()},k=async(w,N,y)=>{r(w.tool),i(null),o(null);try{const b=await T.pageAct(e.plugin,{tool:w.tool,args:N});if(b.approvalId)return u(b.approvalId),f({then:w.then,ref:w,...y?{onDone:y}:{}}),!1;u(null),f(null);const S=HP(b.result);return o(v(w,b.result)??(S?KP(b.result):null)),S&&await GP(S,n),g(w.then,b.result,y),!0}catch(b){return i(b instanceof Error?b.message:String(b)),e.refresh(),!1}finally{r(null)}},j=w=>{if(!w){e.refresh();return}const N=h;if(u(null),f(null),N&&w.decision==="approve"&&w.state==="succeeded"){o(v(N.ref,w.result)),g(N.then,void 0,N.onDone);return}e.refresh()},x=()=>{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:j,run:k,reset:x,happened:m}}function wi({action:e,args:n,disabled:s,running:r,count:a,row:i,onRun:l}){const[o,c]=d.useState(!1),u=s===!0||fj(n),h=m=>gs(m,{...a===void 0?{}:{count:a},row:i}),f=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(E,{variant:"ghost",onClick:()=>c(!1),children:"Cancel"}),t.jsxs(E,{variant:e.tone==="danger"?"danger":"accent",disabled:u,onClick:()=>{c(!1),l(e,n)},children:["Yes, ",f.toLowerCase()]})]}):t.jsx(E,{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:f})}function If({id:e,onDecided:n}){const s=xt(),r=me(()=>T.approval(e),[e,s.version]),{busy:a,note:i,failure:l,decide:o}=xb(c=>{n?n(c):s.refresh()});return r.error?t.jsx(ae,{message:r.error}):r.data?t.jsxs(ue,{children:[t.jsx(vb,{action:r.data,timezone:s.timezone,busy:a===e,onDecide:(c,u,h,f)=>{o(c,u,h,f)}}),i?t.jsx(Q,{tone:"good",role:"status",children:i}):null,t.jsx(ae,{message:l})]}):t.jsx(be,{children:"Loading the approval…"})}function br({act:e}){return e.error?t.jsx(ae,{message:e.error}):e.approvalId?e.waiting?t.jsxs(ue,{children:[t.jsx(Q,{role:"status",children:e.waiting}),t.jsx(If,{id:e.approvalId,onDecided:e.settle})]}):t.jsx(If,{id:e.approvalId,onDecided:e.settle}):e.done?t.jsx(Q,{tone:"good",role:"status",children:e.done}):null}function hj(e,n){const s={};for(const r of e){const a=r.from===void 0?void 0:Ae(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 fj(e){return e===ii?!0:Array.isArray(e)?e.some(fj):e!==null&&typeof e=="object"?Object.values(e).some(fj):!1}function Rb(e,n){const s=hj(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 lM(e,n,s){const r=xt(),a=e.optionsFrom,i=a?{...iM(a.query.params,s,r),...Object.fromEntries((a.dependsOn??[]).map(c=>[c,String(n[c]??"")]).filter(([,c])=>c!==""))}:{},l=JSON.stringify([(a==null?void 0:a.query.query)??null,i,r.version]),o=me(()=>a?T.pageQuery(r.plugin,a.query.query,i).then(c=>c.data):Promise.resolve(void 0),[l]);return a?{options:kr(o.data,a.rows).map(c=>({value:String(Ae(c,a.value)??""),label:String(Ae(c,a.label)??"")})),loading:o.loading}:{options:e.options??[],loading:!1}}function lQ({field:e,fields:n,value:s,values:r,data:a,disabled:i,compact:l,onChange:o}){const c=lM(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 m=Array.isArray(s)?s.map(String):[],v=e.max!==void 0&&m.length>=e.max?`Up to ${e.max}; remove one to add another.`:void 0;return t.jsx(oe,{label:e.label,hint:l?void 0:[h,v].filter(Boolean).join(" ")||void 0,group:!0,children:t.jsx(O8,{id:u.id,label:e.label,options:c.options,value:m,max:e.max,disabled:i,onChange:o})})}if(e.type==="select"){const m=t.jsxs("select",{...u,value:String(s??""),onChange:p=>o(p.target.value),children:[t.jsx("option",{value:"",children:c.loading?"Loading…":"—"}),c.options.map(p=>t.jsx("option",{value:p.value,children:p.label},p.value))]});return e.action&&!l?t.jsx(oQ,{field:e,action:e.action,fields:n??[e],values:r,data:a,disabled:i,hint:h,children:m}):t.jsx(oe,{label:e.label,hint:h,children:m})}if(e.type==="textarea")return t.jsx(oe,{label:e.label,hint:h,wide:!0,children:t.jsx("textarea",{...u,value:String(s??""),onChange:m=>o(m.target.value),rows:6})});if(e.type==="checkbox")return t.jsx(oe,{label:e.label,hint:h,inline:!0,wide:!l,children:t.jsx("input",{...u,type:"checkbox",checked:s===!0,onChange:m=>o(m.target.checked)})});const f=e.type==="secret"?"password":e.type==="number"?"number":e.type;return t.jsx(oe,{label:e.label,hint:h,children:t.jsx("input",{...u,type:f,value:s==null?"":String(s),min:e.min,max:e.max,step:e.step,...l&&e.hint?{placeholder:e.hint}:{},onChange:m=>o(e.type==="number"?cQ(m.target.value):m.target.value)})})}function oQ({field:e,action:n,fields:s,values:r,data:a,disabled:i,hint:l,children:o}){const c=xt(),u=d.useId(),h=Aq()===u,[f,m]=d.useState(!1),[p,v]=d.useState(null),[g,k]=d.useState(null),[j,x]=d.useState(null);d.useEffect(()=>()=>EC(u),[u]);const w=Pb(s,r,a),N=n.args!==void 0?zs(n.args,{data:a,fields:r,shape:s,omit:w,scope:c}):Object.fromEntries(Object.entries(r).filter(([S,C])=>!w.has(S)&&C!=="")),y=async()=>{if(h){EC(u);return}m(!0),v(null),k(null),x(null);try{const S=await T.pageAct(c.plugin,{tool:n.tool,args:N});if(S.approvalId){x(S.approvalId);return}v(KP(S.result));const C=HP(S.result);C&&await GP(C,u)}catch(S){k(S instanceof Error?S.message:String(S))}finally{m(!1)}},b=h?"Stop":n.label;return t.jsx(oe,{label:e.label,hint:l,action:t.jsx(E,{"data-shape":"icon","aria-label":f?`${n.label}: working`:b,title:b,"aria-busy":f||void 0,"aria-pressed":n.icon==="play"?h:void 0,disabled:i===!0||f,onClick:()=>void y(),children:f?t.jsx("span",{className:"ui-spinner","aria-hidden":"true"}):t.jsx(ie,{name:h?"stop":n.icon??"arrow"})}),after:g?t.jsx(ae,{message:g}):j?t.jsx(If,{id:j,onDecided:()=>x(null)}):p?t.jsx("span",{className:"ui-field-hint",role:"status",children:p}):null,children:o})}function cQ(e){if(e.trim()==="")return"";const n=Number(e);return Number.isFinite(n)?n:e}function oM(e,n){return{...typeof n=="object"&&n!==null?n:{},...e}}function Pb(e,n,s){const r=oM(n,s);return new Set(e.filter(a=>a.when!==void 0&&!Lt(r,a.when)||a.disabledWhen!==void 0&&Lt(r,a.disabledWhen)).map(a=>a.name))}function Gm({fields:e,values:n,data:s,disabled:r,compact:a,columns:i,onChange:l}){const o=oM(n,s);return t.jsx(Ms,{dense:a,columns:i,children:e.filter(c=>c.when===void 0||Lt(o,c.when)).map(c=>t.jsx(lQ,{field:c,fields:e,compact:a,value:n[c.name],values:n,data:s,disabled:r===!0||c.disabledWhen!==void 0&&Lt(o,c.disabledWhen),onChange:u=>l(c.name,u)},c.name))})}const $u=d.createContext(!1),cM=d.createContext(!1),uM=d.createContext(!1);function Us({title:e,note:n,actions:s,children:r}){const a=d.useContext($u);return t.jsx(pe,{title:e,aside:n,actions:s,panel:a,children:t.jsx($u.Provider,{value:!1,children:t.jsx(cM.Provider,{value:a,children:r})})})}function Qr({component:e,data:n,choose:s,chosen:r}){const a=xt(),i=d.useContext(Ef);if(!Lt(n,e.when)||e.where!==void 0&&e.where!==(dQ()?"local":"remote"))return null;if(e.kind!=="section"&&!i&&nM(e,a.sensitive))return t.jsx(aM,{children:t.jsx(Qr,{component:e,data:n,...s?{choose:s}:{},...r===void 0?{}:{chosen:r}})});switch(e.kind){case"section":return t.jsx(uQ,{component:e,data:n});case"notice":return t.jsx(hQ,{component:e,data:n});case"link":return t.jsx(fQ,{component:e,data:n});case"progress":return t.jsx(pQ,{component:e,data:n});case"chart":return t.jsx(gQ,{component:e,data:n});case"stats":return t.jsx(xQ,{component:e,data:n});case"list":return t.jsx(wQ,{component:e,data:n,...s?{onChoose:s}:{},...r===void 0?{}:{chosen:r}});case"table":return t.jsx(SQ,{component:e,data:n});case"detail":return t.jsx($Q,{component:e,data:n});case"form":return t.jsx(TQ,{component:e,data:n});case"search":return t.jsx(PQ,{component:e,data:n});case"list-detail":return t.jsx(MQ,{component:e,data:n});case"repeat":return t.jsx(OQ,{component:e,data:n});case"calendar":return t.jsx(DQ,{component:e,data:n});case"tiles":return t.jsx(FQ,{component:e,data:n});case"series-panel":return t.jsx(_Q,{component:e,data:n});case"hero":return t.jsx(zQ,{component:e,data:n});case"tabs":return t.jsx(UQ,{component:e,data:n});case"expand":return t.jsx(BQ,{component:e,data:n});case"button":return t.jsx(xM,{component:e,data:n});case"menu":return t.jsx(dM,{component:e,data:n});case"approval":return t.jsx(ZQ,{component:e,data:n});case"artifact":return t.jsx(eJ,{component:e,data:n});case"message":return t.jsx(sJ,{component:e,data:n});case"editor":return t.jsx(aJ,{component:e,data:n});case"agent-offer":return t.jsx(WQ,{component:e});case"stories":return t.jsx(VQ,{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 uQ({component:e,data:n}){const s=xt(),r=d.useContext(Ef),[a,i]=$b(),l=!r&&nM([e.query,e.body],s.sensitive),o=l&&!a,c=Nn(o?void 0:e.query,n),u=e.query?c.data:n,h=e.heading&&!o?Ve(u,e.heading):void 0,f=h==null||h===""?e.title:String(h),m=d.useContext($u);let p=e.body.length;const v=w=>{var N;return w.kind==="button"||w.kind==="link"||w.kind==="menu"||w.kind==="form"&&((N=w.drawer)==null?void 0:N.button)!==void 0&&!w.title};for(;m&&p>0&&v(e.body[p-1]);)p-=1;const g=e.body.slice(0,p),k=[...e.actions??[],...e.body.slice(p)],[j,x]=d.useState(null);return t.jsx(mj.Provider,{value:x,children:t.jsx(Us,{title:f,note:e.note,actions:k.length>0||l?t.jsxs(t.Fragment,{children:[k.map((w,N)=>t.jsx(Qr,{component:w,data:u},N)),l?t.jsx(sM,{revealed:a,onToggle:i}):null]}):void 0,children:t.jsxs(ue,{gap:"lg",divided:m,children:[j,e.query&&!o?t.jsx(ae,{message:c.error}):null,o?t.jsx(rM,{}):e.query&&c.data===void 0&&!c.error?t.jsx(be,{children:"Loading…"}):t.jsx(Ef.Provider,{value:r||l,children:t.jsx(mj.Provider,{value:null,children:g.map((w,N)=>t.jsx(Qr,{component:w,data:u},N))})})]})})})}const mj=d.createContext(null);function dQ(){const e=typeof location>"u"?"":location.hostname;return e==="127.0.0.1"||e==="localhost"||e==="::1"||e==="[::1]"}function dM({component:e,data:n}){var c;const s=xt(),r=ea(),a=d.useContext(mj),i=e.items.filter(u=>Lt(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,zs(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(br,{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(Jn,{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(ie,{name:"chevron-down",size:12})]})}),a?null:o]})}function hQ({component:e,data:n}){const s=xt(),r=ea(),a=typeof e.text=="string"?e.text:String(Ve(n,e.text)??""),i=e.link&&Lt(n,e.link.when)?e.link:void 0,l=i?Ca(s,i.to,n):"",o=i?typeof i.label=="string"?i.label:String(Ve(n,i.label)??""):"",c=i&&l!==""&&o!==""?"href"in i.to?t.jsx(go,{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(ie,{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:Ib(e.tone),title:e.title,action:u?t.jsx(wi,{action:u,args:zs(u.args,{data:n,scope:s}),disabled:r.busy,running:r.running===u.tool,row:n,onRun:(h,f)=>void r.run(h,f)}):void 0,children:[a,c?t.jsxs(t.Fragment,{children:[" ",c]}):null]}),t.jsx(vM,{act:r})]})}function fQ({component:e,data:n}){const s=xt(),r=Ca(s,e.to,n);return r===""?null:"href"in e.to?t.jsx(re,{children:t.jsxs(nt,{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(re,{children:t.jsx(nt,{href:r,variant:e.tone==="accent"?"accent":void 0,onClick:a=>{a.preventDefault(),s.navigate(r)},children:e.label})})}function PC(e){return Math.round(e/1e6)}function mQ(e,n){const s=Is(Ve(n,e.value))??0,r=e.total?Is(Ve(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?`${PC(s)} of ${Math.max(1,PC(r))} MB · ${l}%`:`${l}%`;return{percent:l,full:o,line:c}}function pQ({component:e,data:n}){const s=c=>c===void 0?"":typeof c=="string"?c:String(Ve(n,c)??""),r=s(e.label),a=s(e.done),{percent:i,full:l,line:o}=mQ(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(zy,{value:i,label:r||"Progress"}),t.jsx("span",{role:"status",children:o})]})]})}function gQ({component:e,data:n}){const s=Nn(e.query,n),r=e.rows===void 0?Array.isArray(s.data)?s.data:[]:kr(s.data,e.rows),a=r.map(h=>String(Ae(h,e.x)??"")),i=h=>r.map(f=>Is(Ae(f,h))??null),l=e.series!==void 0,o=e.y===void 0?[]:Array.isArray(e.y)?e.y:[e.y],c=l?e.series.map(h=>({label:h.label,values: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?Is(Ve(s.data,e.target))??null:null;return t.jsxs(Us,{title:e.title,note:e.note,children:[t.jsx(ae,{message:s.error}),r.length===0?s.loading||s.data===void 0?t.jsx(be,{children:"Loading…"}):t.jsx(dl,{text:e.empty??"Nothing recorded yet."}):t.jsx(A8,{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)?pv(h):h,formatY:h=>kn(h,"number",null)})]})}function xQ({component:e,data:n}){const s=Nn(e.query,n);return t.jsxs(Us,{title:e.title,note:e.note,children:[t.jsx(ae,{message:s.error}),s.data===void 0?t.jsx(be,{children:e.empty??"Loading…"}):t.jsx(Lm,{children:e.items.map((r,a)=>t.jsx(zr,{label:r.label,value:t.jsx(Ur,{text:kn(Ve(s.data,r.value),r.unit??"text",null)}),tone:aQ(r.tone)},a))})]})}function hM(e,n,s,r){const a=(n.meta??[]).map(b=>String(Ve(s,b)??"")).filter(b=>b!==""),i=String(Ve(s,n.title)??""),l=n.to&&!r?Ca(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(iQ,{plugin:e.plugin,images:n.images,row:s}):null,f=[...n.pill?[n.pill]:[],...n.pills??[]].map((b,S)=>{const C=Ve(s,b.value);if(C==null||C==="")return null;const A=vQ(b,C,s);return t.jsx(Se,{tone:dj(A.tone),children:A.text},S)}),m=o&&c?t.jsx(go,{href:o,children:i}):o?t.jsx("a",{href:o,onClick:b=>{b.preventDefault(),e.navigate(o)},children:i}):i,p=n.tag?Ve(s,n.tag):void 0,v=p==null||p===""?null:t.jsx("span",{className:"pl-row-tag",children:String(p)}),g=n.status?Ve(s,n.status.text):void 0,k=n.status?Tf(n.status.tone,s):void 0,j=g==null||g===""?null:t.jsx("span",{className:"pl-row-status","data-tone":k,children:String(g)}),x=n.sub?String(Ve(s,n.sub)??""):"",w=n.swatch?Ae(s,n.swatch):void 0,N=n.logo?t.jsx(Bo,{className:"pl-logo-lg",src:Zu(e.plugin,Ve(s,n.logo.asset)),label:String(Ve(s,n.logo.label)??"")}):n.swatch?typeof w=="string"&&Ob.test(w)?t.jsx("span",{className:"pl-swatch","aria-hidden":"true",style:{"--swatch":w}}):t.jsx("span",{className:"pl-swatch","data-none":"true","aria-hidden":"true"}):null,y=n.preview?String(Ve(s,n.preview)??""):"";return{text:i,href:o,outside:c,lead:N,preview:y,strong:n.strong?Lt(s,n.strong):void 0,pills:t.jsx(t.Fragment,{children:f}),meta:a.length>0?t.jsx(Ur,{text:a.join(" · ")}):"",title:u?t.jsxs(t.Fragment,{children:[u,t.jsx("span",{className:"pl-row-title",children:m}),v]}):v?t.jsxs(t.Fragment,{children:[m,v]}):m,sub:j?t.jsxs(t.Fragment,{children:[x?t.jsx("span",{className:"pl-row-line",children:t.jsx(Ur,{text:x})}):null,j]}):n.sub?x&&t.jsx(Ur,{text:x}):null,side:t.jsxs(t.Fragment,{children:[f,a.length>0?t.jsxs("span",{className:"muted",children:[" ",t.jsx(Ur,{text:a.join(" · ")})]}):null]})}}function vQ(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]:Tf(e.tone,s)}}function kr(e,n){const s=Ae(e,n);return Array.isArray(s)?s:[]}function fM(e,n,s){const r=[],a=new Set;return e.forEach((i,l)=>{const o=n===void 0?void 0:Ae(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 jQ(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 wQ({component:e,data:n,onChoose:s,chosen:r}){var b;const a=xt(),i=d.useContext(uM),l=Nn(e.query,n),o=ea(),[c,u]=d.useState([]),h=i&&!e.select&&(e.actions??[]).length===0&&(e.bulk??[]).length===0,f=kr(l.data,e.rows),m=e.collapsed?kr(l.data,e.collapsed.rows):[],p=mM(e.actions,f,o),v={plugin:a.plugin,page:a.page,component:`list "${e.title??e.rows}"`},g=fM([...f,...m],e.key??((b=e.select)==null?void 0:b.key),v),k=new Map(g.map(S=>[S.row,S.key])),j=new Set(g.map(S=>S.row)),x=new Set(g.filter(({row:S})=>{var C;return((C=e.select)==null?void 0:C.disabledWhen)===void 0||!Lt(S,e.select.disabledWhen)}).map(({key:S})=>S)),w=c.filter(S=>x.has(S)),N=d.useMemo(()=>{const S=f.filter($=>j.has($));if(!e.groupBy)return[{label:null,aside:null,asideTone:void 0,rows:S}];const C=new Map;for(const $ of S){const I=String(Ae($,e.groupBy.key)??"");C.set(I,[...C.get(I)??[],$])}const A=($,I)=>{var R,D,U;const P=(D=(R=e.groupBy)==null?void 0:R.labels)==null?void 0:D[$];if(P!==void 0)return P;const O=(U=e.groupBy)!=null&&U.label?Ae(I,e.groupBy.label):void 0;return O==null||O===""?$:String(O)};return[...C].map(([$,I])=>{var R,D;const P=(R=e.groupBy)!=null&&R.aside?Ae(I[0],e.groupBy.aside):void 0,O=(D=e.groupBy)!=null&&D.asideTone?Ae(I[0],e.groupBy.asideTone):void 0;return{label:A($,I[0]),aside:P==null||P===""?null:String(P),asideTone:O==="warning"||O==="critical"?O:void 0,rows:I}})},[f,e.groupBy,g.length]),y=S=>S.map(C=>{var D;const A=hM(a,e.item,C,s),$=k.get(C);if(h&&(s||A.href&&!A.outside))return t.jsx(eR,{href:A.href??"#",current:r===$,onClick:()=>s?s($):a.navigate(A.href),title:A.text,meta:A.meta,sub:A.sub,side:A.pills,snippet:A.preview||void 0,strong:A.strong},$);const I=((D=e.select)==null?void 0:D.disabledWhen)!==void 0&&Lt(C,e.select.disabledWhen),P=(e.actions??[]).filter(U=>Lt(C,U.when)),O=P.filter(U=>U.menu!==!0),R=P.filter(U=>U.menu===!0);return t.jsx(ot,{lead:A.lead?A.lead:e.select?t.jsx("input",{type:"checkbox","aria-label":`Select ${A.text}`,disabled:I,checked:c.includes($),onClick:U=>U.stopPropagation(),onChange:U=>u(W=>U.target.checked?[...W,$]:W.filter(M=>M!==$))}):void 0,title:s?t.jsx("a",{href:"#","aria-current":r===$?"true":void 0,onClick:U=>{U.preventDefault(),s($)},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(bQ,{choice:e.item.choice,row:C,data:l.data,act:o}):null,O.map((U,W)=>t.jsx(Mb,{action:U,row:C,data:l.data,act:o,onForm:p.show},W)),R.length>0?t.jsx(pM,{actions:R,row:C,title:A.text,data:l.data,act:o,onForm:p.show}):null]})},$)});return t.jsxs(Us,{title:e.title,note:e.note,children:[t.jsx(ae,{message:l.error}),p.open?null:t.jsx(br,{act:o}),p.open?t.jsx(gM,{open:p.open,data:l.data,rows:f,act:o,onClose:p.close,onDone:p.finish}):null,N.every(S=>S.rows.length===0)?l.loading?t.jsx(be,{children:"Loading…"}):t.jsx(dl,{text:e.empty??"Nothing here yet."}):t.jsxs(dt,{children:[e.select?t.jsx(ot,{lead:t.jsx("input",{type:"checkbox","aria-label":"Select every row",checked:x.size>0&&w.length===x.size,disabled:x.size===0,onChange:S=>u(S.target.checked?[...x]:[])}),title:t.jsxs("span",{className:"muted",children:[x.size," to choose from"]})}):null,N.map((S,C)=>{var A,$;return(A=e.groupBy)!=null&&A.actions||($=e.groupBy)!=null&&$.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(yQ,{actions:e.groupBy.actions??[],row:S.rows[0],title:S.label??"",data:l.data,act:o,onForm:p.show})]}),y(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,y(S.rows)]},C)})]}),e.collapsed&&m.some(S=>j.has(S))?t.jsx(Gt,{summary:`${e.collapsed.label} (${m.filter(S=>j.has(S)).length})`,children:t.jsx(dt,{children:y(m.filter(S=>j.has(S)))})}):null,e.bulk&&e.bulk.length>0?t.jsxs(re,{align:"end",children:[t.jsxs("span",{className:"ui-toolbar-note",children:[w.length," selected"]}),e.bulk.map((S,C)=>{const A=w.length>0||S.all!==!0?w:[...x];return t.jsx(wi,{action:S,args:zs(S.args,{data:l.data,selected:A,scope:a}),count:A.length,disabled:o.busy||A.length===0,running:o.running===S.tool,onRun:($,I)=>{u([]),o.run($,I)}},C)})]}):null]})}function yQ({actions:e,row:n,title:s,data:r,act:a,onForm:i}){const l=e.filter(u=>Lt(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(Mb,{action:u,row:n,data:r,act:a,onForm:i},h)),c.length>0?t.jsx(pM,{actions:c,row:n,title:s,data:r,act:a,onForm:i}):null]})}function bQ({choice:e,row:n,data:s,act:r}){const a=xt(),i=String(Ae(n,e.value)??""),[l,o]=d.useState(null);d.useEffect(()=>o(null),[i]);const c=l??i,u=e.options.filter(h=>Lt(n,h.when));return t.jsx("span",{className:"ui-segment pl-choice",role:"radiogroup","aria-label":gs(e.label,{row:n}),"aria-busy":l!==null&&r.running===e.tool?"true":void 0,children:u.map(h=>{const f=h.disabledWhen!==void 0&&Lt(n,h.disabledWhen),m=f&&h.hint?gs(h.hint,{row:n}):void 0;return t.jsx("button",{type:"button",role:"radio",className:"ui-tab","aria-checked":c===h.value,disabled:f||r.busy,title:m,"aria-description":m,onClick:()=>{if(h.value===c)return;o(h.value);const p=zs(e.args,{data:s,row:n,choice:h.value,scope:a});r.run(e,p).then(v=>{v||o(null)})},children:h.label},h.value)})})}function kQ(e,n,s){return Object.entries(e).every(([r,a])=>{const i=typeof a=="string"?a:Ae(s,a.row);return i!=null&&n[r]===String(i)})}function mM(e,n,s){const r=xt(),[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=>Lt(h,o.when)&&kQ(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 Mb({action:e,row:n,data:s,act:r,onForm:a}){const i=xt();return e.form?t.jsx(E,{disabled:r.busy,onClick:()=>a(e,n),children:gs(e.label,{row:n})}):t.jsx(wi,{action:e,args:zs(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 pM({actions:e,row:n,title:s,data:r,act:a,onForm:i}){const l=xt(),[o,c]=d.useState(null),u=m=>void a.run(m,zs(m.args,{data:r,row:n,scope:l})),h=[];let f;return e.forEach((m,p)=>{m.group!==f?(p>0&&h.push("separator"),m.group&&h.push({heading:m.group}),f=m.group):m.tone==="danger"&&p>0&&h.push("separator"),h.push({label:gs(m.label,{row:n}),...m.hint?{hint:gs(m.hint,{row:n})}:{},...m.tone==="danger"?{tone:"critical"}:{},onSelect:()=>m.form?i(m,n):m.confirm?c(m):u(m)})}),t.jsxs(t.Fragment,{children:[t.jsx(Jn,{label:`More for ${s}`,items:h,sheet:{title:s}}),o?t.jsx(Rt,{title:gs(o.confirm??o.label,{row:n}),onClose:()=>c(null),foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:()=>c(null),children:"Cancel"}),t.jsx(E,{variant:o.tone==="danger"?"danger":"accent",onClick:()=>{const m=o;c(null),u(m)},children:gs(o.label,{row:n})})]})}):null]})}function NQ(e,n){const s=Ja(e),r=n.find(i=>Ja(i)===s);if(r!==void 0)return r;const a=JSON.stringify(s);return n.find(i=>JSON.stringify(Ja(i))===a)??e}function gM({open:e,data:n,rows:s,act:r,onClose:a,onDone:i}){const l=xt(),{action:o}=e,c=NQ(e.row,s),u=o.form,[h,f]=Rb(u.fields,c),m=u.fields.some(j=>j.from!==void 0&&zm(Ae(c,j.from))),p=u.fields.some(j=>j.required&&(h[j.name]===""||h[j.name]===void 0)),{confirm:v,...g}=o,k={...g,label:u.submit};return t.jsx(Je,{title:gs(u.title,{row:c}),onClose:a,foot:t.jsxs(re,{align:"end",children:[t.jsx(E,{variant:"ghost",onClick:a,children:"Cancel"}),t.jsx(wi,{action:k,args:zs(o.args,{data:n,row:c,fields:h,shape:u.fields,scope:l}),disabled:r.busy||p||m,running:r.running===o.tool,row:c,onRun:(j,x)=>void r.run(j,x,i)})]}),children:t.jsxs(ue,{children:[t.jsx(Gm,{fields:u.fields,values:h,data:c,onChange:f}),m?t.jsx("p",{className:"muted",children:"Show amounts to change this."}):null,t.jsx(ae,{message:r.error})]})})}function SQ({component:e,data:n}){const s=Nn(e.query,n),r=ea(),a=kr(s.data,e.rows),i=mM(e.actions,a,r);return t.jsxs(Us,{title:e.title,note:e.note,children:[t.jsx(ae,{message:s.error}),i.open?null:t.jsx(br,{act:r}),i.open?t.jsx(gM,{open:i.open,data:s.data,rows:a,act:r,onClose:i.close,onDone:i.finish}):null,a.length===0?s.loading?t.jsx(be,{children:"Loading…"}):t.jsx(dl,{text:e.empty??"Nothing here yet."}):t.jsxs(Zr,{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:kn(Ae(l,c.key),c.type??"text",null);return t.jsxs("td",{"data-fit":c.fit,title:EQ(c,l,u),children:[c.pill?null:t.jsx(CQ,{column:c,row:l}),c.pill?t.jsx(AQ,{column:c,row:l}):c.fit==="truncate"?t.jsx("span",{className:"ui-table-cut",children:t.jsx(Ur,{text:u})}):t.jsx(Ur,{text:u})]},c.key)}),e.actions&&e.actions.length>0?t.jsx("td",{children:t.jsx(re,{align:"end",children:e.actions.filter(c=>Lt(l,c.when)).map((c,u)=>t.jsx(Mb,{action:c,row:l,data:s.data,act:r,onForm:i.show},u))})}):null]},o))})]})]})}const Ob=/^#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i;function CQ({column:e,row:n}){if(!e.swatch)return null;const s=Ae(n,e.swatch);return typeof s!="string"||!Ob.test(s)?null:t.jsx("span",{className:"ui-table-swatch","aria-hidden":"true",style:{"--swatch":s}})}function EQ(e,n,s){if(e.hint){const r=Ae(n,e.hint);if(r!=null&&r!=="")return String(r)}return e.fit==="truncate"&&s?s:void 0}function AQ({column:e,row:n}){var l,o;const s=Ae(n,e.key);if(Array.isArray(s))return t.jsx(t.Fragment,{children:s.map((c,u)=>{var g;const h=c,f=typeof h=="object"&&h!==null?h.value:c;if(f==null||f==="")return null;const m=typeof h=="object"&&h!==null?h.tone:void 0,p=(g=e.pill)==null?void 0:g.labels,v=p&&Object.prototype.hasOwnProperty.call(p,String(f))?p[String(f)]:kn(f,e.type??"text",null);return t.jsx(Se,{tone:dj(Tf(typeof m=="string"?m:void 0,n)),children:v},u)})});const r=(l=e.pill)==null?void 0:l.labels,a=String(s),i=r&&Object.prototype.hasOwnProperty.call(r,a)?r[a]:kn(s,e.type??"text",null);return t.jsx(Se,{tone:dj(Tf((o=e.pill)==null?void 0:o.tone,n)),children:i})}function $Q({component:e,data:n}){const s=Nn(e.query,n);return s.error?t.jsx(ae,{message:s.error}):s.data===void 0?t.jsx(be,{children:e.empty??"Loading…"}):t.jsx(Us,{title:e.title,note:e.note,children:t.jsxs(ue,{gap:"lg",children:[e.fields.length>0?t.jsx(Vt,{items:e.fields.map(r=>({key:r.label,label:r.label,value:t.jsx(Ur,{text:kn(Ve(s.data,r.value),r.unit??"text",null)})}))}):null,e.body.map((r,a)=>t.jsx(Qr,{component:r,data:s.data},a))]})})}function TQ({component:e,data:n}){var f;const s=xt(),r=Nn(e.initial,n),a=ea(),[i,l]=d.useState(!1),o=((f=e.drawer)==null?void 0:f.id)!==void 0&&s.params.open===e.drawer.id,c=i||o,u=m=>{l(m),!m&&o&&s.setParams({open:null})},h=t.jsx(IQ,{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(br,{act:a}),c?t.jsx(Je,{title:e.drawer.title,onClose:()=>u(!1),children:h}):null]}):t.jsxs(pe,{title:e.title,aside:e.note,actions:e.drawer.button!==void 0?t.jsx(E,{variant:"accent",onClick:()=>u(!0),children:e.drawer.button}):void 0,children:[t.jsx(br,{act:a}),c?t.jsx(Je,{title:e.drawer.title,onClose:()=>u(!1),children:h}):null]}):t.jsxs(Us,{title:e.title,note:e.note,children:[t.jsx(ae,{message:r.error}),h]})}function IQ({component:e,data:n,initialData:s,act:r,onDone:a}){const i=d.useContext(cM),l=xt(),[o,c]=Rb(e.fields,s),u=Pb(e.fields,o,s),h=e.fields.some(m=>m.from!==void 0&&zm(Ae(s,m.from))),f=e.fields.some(m=>m.required&&!u.has(m.name)&&(o[m.name]===""||o[m.name]===void 0||Array.isArray(o[m.name])&&o[m.name].length===0));return t.jsxs(ue,{children:[t.jsx(Gm,{fields:e.fields,columns:e.columns,values:o,data:s,onChange:c}),e.drawer?null:t.jsx(br,{act:r}),h?t.jsx("p",{className:"muted",children:"Show amounts to change this."}):null,t.jsx(re,{align:"end",className:i?"ui-panel-foot":void 0,children:t.jsx(wi,{action:e.submit,args:zs(e.submit.args,{data:n,fields:o,shape:e.fields,omit:u,scope:l}),disabled:r.busy||f||h,running:r.running===e.submit.tool,onRun:(m,p)=>void r.run(m,p,a)})})]})}function RQ(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 MC(e){return e!=null&&e!==""&&e!==!1&&e!=="false"}function PQ({component:e,data:n}){const s=xt(),[r,a]=d.useState(()=>hj(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=Nn(i&&u?e.query:void 0,n),f=kr(h.data,e.rows),m=e.count===void 0?void 0:Ae(h.data,e.count),p=e.note===void 0?void 0:Ae(h.data,e.note),v=e.fields.find(C=>C.type==="text"||C.type==="email")??null,g=e.fields.filter(C=>C!==v),k=C=>{s.setParams(Object.fromEntries(e.fields.map(A=>[A.name,String(C[A.name]??"")||null]))),l(!0)},j=(C,A)=>{const $={...r,[C]:A};a($),e.auto&&k($)},x=()=>{const C=hj(e.fields,null);a(C),e.auto?k(C):(s.setParams(Object.fromEntries(e.fields.map(A=>[A.name,null]))),l(!1))},w=i?g.filter(C=>MC(s.params[C.name])):[],N=v?w.map(C=>t.jsx(hf,{label:C.label,onRemove:()=>{const A={...r,[C.name]:C.type==="checkbox"?!1:""};a(A),k(A)},children:RQ(C,String(s.params[C.name]))},C.name)):[],y=g.filter(C=>MC(r[C.name])).length,b=e.auto&&!e.reset?null:t.jsxs(t.Fragment,{children:[e.reset?t.jsx(E,{variant:"ghost",onClick:x,children:"Clear"}):null,e.auto?null:t.jsx(E,{type:"submit",variant:"accent",disabled:!u,children:"Search"})]}),S=e.results.to?e.results:e.to?{...e.results,to:e.to}:e.results;return t.jsx(Us,{title:e.title,children:t.jsxs(ue,{children:[t.jsx(sR,{label:e.title??"Search",onSubmit:()=>{!e.auto&&u&&k(r)},main:v?t.jsx("input",{id:`f-${v.name}`,name:v.name,type:v.type==="email"?"email":"search","aria-label":v.label,placeholder:v.hint??v.label,title:v.hint,required:v.required,value:String(r[v.name]??""),onChange:C=>j(v.name,C.target.value)}):void 0,filters:g.length>0?t.jsx(Gm,{fields:g,values:r,data:n,compact:!0,onChange:j}):void 0,...v&&g.length>0?{filtersOpen:o,onToggleFilters:()=>c(C=>!C),active:y}:{},chips:N.length>0?N:void 0,actions:b}),t.jsx(ae,{message:h.error}),i&&(m!==void 0||p!==void 0)?t.jsxs("p",{className:"ui-card-meta",children:[m===void 0?"":`${kn(m,"number",null)} in all. `,p===void 0?"":String(p)]}):null,i?f.length===0?t.jsx(be,{children:h.loading?"Searching…":e.empty??"Nothing matches."}):t.jsx("div",{className:"ui-panel","data-flush":"true",children:t.jsx(dt,{children:f.map((C,A)=>{const $=hM(s,S,C);return t.jsx(ot,{title:$.title,sub:$.sub,side:$.side},A)})})}):null]})})}function MQ({component:e,data:n}){const s=xt(),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(Qr,{component:u,data:n},h))},l??"");return t.jsx($u.Provider,{value:!1,children:t.jsx(tR,{list:t.jsx(uM.Provider,{value:!0,children:t.jsx("div",{className:"pl-picks",onKeyDown:jQ,children:t.jsx(Qr,{component:e.list,data:n,chosen:l??null,...r?{choose:i}:{}})})}),detail:l?o?t.jsx(Tb.Provider,{value:o,children:c}):c:void 0,empty:e.empty??"Choose one to see it here."})})}function OQ({component:e,data:n}){var g;const s=xt(),[r,a]=d.useState(!1),i=Nn(e.query,n,r&&e.poll?e.poll.seconds*1e3:void 0),l=e.poll!==void 0&&i.data!==void 0&&Lt(i.data,e.poll.while);d.useEffect(()=>a(l),[l]);const o=kr(i.data,e.rows),c=(g=e.poll)==null?void 0:g.finish,u=ea(),[h,f]=d.useState(()=>new Set),m=c?o.find(k=>{if(!Lt(k,c.when))return!1;const j=String(Ae(k,e.key)??"");return j!==""&&!h.has(j)}):void 0,p=m===void 0?null:String(Ae(m,e.key)??"");d.useEffect(()=>{!c||m===void 0||p===null||p===""||h.has(p)||u.busy||(f(k=>new Set([...k,p])),u.run(c.action,zs(c.action.args,{data:m,row:m,scope:s})))},[p,u.busy]);const v=c!==void 0&&u.running===c.action.tool;return t.jsxs(Us,{title:e.title,note:e.note,children:[t.jsx(ae,{message:i.error}),v?t.jsxs("p",{className:"pl-wait",role:"status",children:[t.jsx("span",{className:"pl-spin","aria-hidden":"true"}),c.action.busy??c.action.label]}):t.jsx(br,{act:u}),v?null:o.length===0?i.loading?t.jsx(be,{children:"Loading…"}):t.jsx(dl,{text:e.empty??"Nothing here yet."}):t.jsx(ue,{gap:"lg",divided:!0,children:fM(o,e.key,{plugin:s.plugin,page:s.page,component:`repeat "${e.title??e.rows}"`}).map(({key:k,row:j})=>t.jsx(pe,{children:t.jsx(ue,{children:e.body.map((x,w)=>t.jsx(Qr,{component:x,data:j},w))})},k))})]})}function DQ({component:e,data:n}){const s=xt(),r=Kq({...e.views?{views:e.views}:{},...e.default?{default:e.default}:{},today:Iq(s.timezone),storageKey:`buddi.calendar-view:${s.plugin}/${s.page}`}),a=Nn(e.query,n,void 0,{from:r.from,to:r.to}),i=d.useMemo(()=>Oq(kr(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(Us,{title:e.title,note:e.note,children:[t.jsx(ae,{message:a.error}),t.jsx(Vq,{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(LQ,{event:c,sheet:e.sheet,onClose:()=>o(null)}):null]})}function LQ({event:e,sheet:n,onClose:s}){const r=xt(),a=e.row,i=p=>{if(p===void 0)return"";const v=Ae(a,p);return v==null?"":String(v)},l=_q(e),o=i(n.color),c=i(n.notes),u=$f(i(n.mapHref)),h=n.open?$f(i(n.open.href)):null,f=n.open?i(n.open.label):"",m=p=>{const v=gs(p.replace(/\{when\}/g,l),{row:{...a,title:e.title,calendar:e.calendar,location:e.location}});s(),X7(v)||r.navigate(pa)};return t.jsx(Je,{title:e.title,onClose:s,foot:n.asks&&n.asks.length>0?t.jsx(re,{align:"end",children:n.asks.map((p,v)=>t.jsx(E,{onClick:()=>m(p.text),children:p.label},v))}):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&&Ob.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(ie,{name:"pin",size:14}),u?t.jsx(go,{href:u,children:e.location}):t.jsx("span",{children:e.location})]}):null,c?t.jsx("p",{className:"pl-event-notes",children:c}):null,h&&f?t.jsx("p",{className:"pl-event-open",children:t.jsx(go,{href:h,className:"wb-src-link",children:f})}):null]})})}function FQ({component:e,data:n}){var f;const s=xt(),r=Nn(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=kr(r.data,e.items).flatMap(m=>{const p=My([m],a).tiles[0];return p?[{tile:p,key:e.select?String(Ae(m,e.select.key)??""):""}]:[]}),l=e.select,o=l?Math.max(0,i.findIndex(m=>m.key===s.params[l.param])):null,c=((f=i[0])==null?void 0:f.key)??"",u=l?s.params[l.param]:void 0,h=i.some(m=>m.key===u);return d.useEffect(()=>{l&&c!==""&&!h&&s.setParams({[l.param]:c})},[l==null?void 0:l.param,c,h]),t.jsxs(Us,{title:e.title,note:e.note,children:[t.jsx(ae,{message:r.error}),r.data===void 0?t.jsx(be,{children:"Loading…"}):i.length===0?t.jsx(dl,{text:e.empty??"Nothing to show."}):t.jsx(gR,{props:{tiles:i.map(m=>m.tile),notice:!1,empty:""},...e.layout?{layout:e.layout}:{},...l?{selected:o,onPick:m=>{var p;return s.setParams({[l.param]:((p=i[m])==null?void 0:p.key)||null})}}:{}})]})}function _Q({component:e,data:n}){const s=Nn(e.query,n),r=kr(s.data,e.points);if(s.data===void 0||r.length===0)return t.jsxs(Us,{title:e.title,note:e.note,children:[t.jsx(ae,{message:s.error}),s.data===void 0?t.jsx(be,{children:"Loading…"}):t.jsx(dl,{text:e.empty??"Nothing to show."})]});const a=r.map(c=>String(Ae(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)=>My([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=>Is(Ae(u,c.y))??null)}));return t.jsxs(t.Fragment,{children:[t.jsx(ae,{message:s.error}),t.jsx(Zq,{...e.title?{title:e.title}:{},...e.note?{note:e.note}:{},...e.labelEvery?{labelEvery:e.labelEvery}:{},xs:a,series:o,tiles:l})]})}function zQ({component:e,data:n}){const s=Nn(e.query,n),r=o=>{const c=Ae(s.data,o);return c==null?"":String(c)};if(s.data===void 0||s.data===null)return t.jsxs(t.Fragment,{children:[t.jsx(ae,{message:s.error}),t.jsx(be,{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(ii).join("hidden"),children:[t.jsxs("div",{className:"pg-hero-main","aria-hidden":"true",children:[t.jsx("span",{className:"pg-hero-icon",children:t.jsx(ie,{name:zo($v(Ve(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 UQ({component:e,data:n}){var v;const s=xt(),[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}=lM({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]:((v=u[0])==null?void 0:v.value)??"":"",f=e.tabs.find(g=>g.id===l)??e.tabs[0],m=(c==null?void 0:c.look)==="chips",p=c!=null&&c.add?Ca(s,c.add.to,n):"";return t.jsxs("div",{className:"pg-tabs",children:[t.jsxs("div",{className:"pg-tabs-bar","data-only":e.tabs.length===1?"pick":void 0,"data-chips":m?"true":void 0,children:[c&&m&&u.length>0?t.jsxs("div",{className:"pl-chips",role:"group","aria-label":c.label,children:[u.map(g=>t.jsx(E,{size:"sm","aria-pressed":g.value===h,onClick:()=>s.setParams({[c.param]:g.value}),children:g.label},g.value)),c.add&&p!==""?t.jsxs(nt,{size:"sm",variant:"ghost",href:p,onClick:g=>{g.preventDefault(),s.navigate(p)},children:[t.jsx(ie,{name:"plus",size:12}),c.add.label]}):null]}):c&&u.length>1?t.jsx(Xt,{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(Xt,{label:e.title??"View",options:e.tabs.map(g=>({value:g.id,label:g.label})),value:f.id,onChange:o})}):null]}),f.body.map((g,k)=>t.jsx(Qr,{component:g,data:n},`${f.id}-${k}`))]})}function BQ({component:e,data:n}){const[s,r]=d.useState(!1),a=Nn(s?e.query:void 0,n),i=typeof e.label=="string"?e.label:String(Ve(n,e.label)??"");return t.jsxs(Gt,{summary:i,boxed:!0,onToggle:l=>r(l),children:[t.jsx(ae,{message:a.error}),a.data===void 0?t.jsx(be,{children:"Loading…"}):t.jsx(ue,{children:e.body.map((l,o)=>t.jsx(Qr,{component:l,data:a.data},o))})]})}function xM({component:e,data:n}){const s=xt(),r=ea();return t.jsxs(t.Fragment,{children:[t.jsx(re,{align:"end",children:t.jsx(wi,{action:e.action,args:zs(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(br,{act:r})]})}function WQ({component:e}){const n=xt();return t.jsx(wb,{plugin:n.plugin,agent:e.agent,text:e.text,label:e.label})}function HQ(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 pj(e){return e.length===0?"":e.length===1?e[0].name:`${e[0].name} and ${e.length-1} more`}function OC(e,n,s){const r={};for(const[a,i]of Object.entries(e))"row"in i?r[a]=Ae(n,i.row):"item"in i?r[a]=Ae(s,i.item):r[a]=Ve(n,i);return r}const KQ=8e3;function DC(e,n,s){const r=[];let a=null;return e.forEach((i,l)=>{if(!Lt(n,i.when))return;const o=i.each?Array.isArray(Ae(n,i.each))?Ae(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:gs(i.label,{row:c===void 0?n:c}),...i.hint?{hint:gs(i.hint,{row:n})}:{},onSelect:()=>s(i,c)})}}),r}function VQ({component:e,data:n}){var S,C;const s=xt(),r=Nn(e.query,n),a=ea(),i=e.param??"story",[l,o]=d.useState(null);d.useEffect(()=>{if(!l)return;const A=setTimeout(()=>o(null),KQ);return()=>clearTimeout(A)},[l]);const c=kr(r.data,e.rows).map(HQ).filter(A=>A!==null),u=e.ways??[],h=s.params[i],f=h?c.find(A=>A.id===h)??null:null,m=async(A,$,I,P)=>{var U;const O=OC(A.args,$,I);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===$.id&&s.setParams({[i]:null});const D=typeof A.done=="string"?gs(A.done,{row:I===void 0?$:I}):"Hidden.";o({id:$.id,group:((U=$.group)==null?void 0:U.id)??null,index:P,text:D,...A.undo?{undo:{tool:A.undo.tool,label:A.undo.label,args:OC(A.undo.args,$,I)}}:{}})},p=()=>{const A=l;o(null),A!=null&&A.undo&&a.run({tool:A.undo.tool,label:A.undo.label},A.undo.args)},v=[];for(const A of c){if(l&&A.id===l.id)continue;const $=e.groups&&A.group?A.group.id:null;let I=v.find(P=>P.id===$);I||(I={id:$,name:e.groups&&A.group?A.group.name:null,rows:[]},v.push(I)),I.rows.push(A)}l&&!v.some(A=>A.id===l.group)&&v.push({id:l.group,name:null,rows:[]});const g=(S=e.groups)==null?void 0:S.param,k=!(v.length===1&&g!==void 0&&s.params[g]===v[0].id),j=(A,$)=>t.jsx(QQ,{row:A,plugin:s.plugin,menu:DC(u,A,(I,P)=>void m(I,A,P,$)),onOpen:()=>s.setParams({[i]:A.id})},A.id),x=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(E,{size:"sm",variant:"ghost",onClick:p,children:A.undo.label})]}):null]},`gone-${A.id}`),w=A=>{const $=A.rows.map(j);return l&&l.group===A.id&&$.splice(Math.min(l.index,$.length),0,x(l)),$};let N;if(r.data===void 0&&r.loading)N=t.jsx("div",{className:"pl-story-grid","aria-busy":"true","aria-label":"Fetching stories",children:Array.from({length:6},(A,$)=>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"})]},$))});else if(c.length===0&&!l){const A=(e.emptyStates??[]).find($=>Lt(r.data,$.when));if(A){const $=P=>P===void 0?"":typeof P=="string"?P:String(Ve(r.data,P)??""),I=(A.actions??[]).map((P,O,R)=>{const D=O===R.length-1&&(R.length>1||A.warm===!0);if(P.set)return t.jsx(E,{size:"sm",variant:D?"accent":"ghost",onClick:()=>s.setParams(P.set),children:P.label},O);const U=P.to?Ca(s,P.to,r.data):"";return U===""?null:t.jsx(nt,{size:"sm",variant:D?"accent":"ghost",href:U,onClick:W=>{W.preventDefault(),s.navigate(U)},children:P.label},O)});N=t.jsx(be,{warm:A.warm===!0,title:$(A.title),action:I.length>0?t.jsx(re,{children:I}):void 0,children:$(A.text)})}else N=t.jsx(dl,{text:e.empty??"Nothing here yet."})}else N=v.map(A=>{var $;return t.jsxs("section",{className:"pl-story-group","aria-label":A.name??e.title??"Stories",children:[k&&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:I=>{I.preventDefault(),s.setParams({[g]:A.id})},children:[(($=e.groups)==null?void 0:$.label)??"See all",t.jsx(ie,{name:"arrow",size:12})]}):null]}):null,t.jsx("div",{className:"pl-story-grid",children:w(A)})]},A.id??"all")});const y=u.find(A=>A.hides&&!A.each&&Lt(f,A.when)),b=u.filter(A=>A!==y);return t.jsxs("div",{className:"pl-stories",children:[t.jsx(ae,{message:r.error}),t.jsx(vM,{act:a}),N,f?t.jsx(Je,{title:f.kicker??((C=f.group)==null?void 0:C.name)??e.title??"Story",onClose:()=>s.setParams({[i]:null}),foot:t.jsxs(re,{children:[y?t.jsx(E,{variant:"ghost",disabled:a.busy,onClick:()=>void m(y,f,void 0,0),children:gs(y.label,{row:f})}):null,b.length>0?t.jsx(Jn,{label:`Less of this: ${f.title}`,trigger:t.jsx("button",{type:"button",className:"ui-btn","data-variant":"ghost",disabled:a.busy,children:"Less of this…"}),items:DC(b,f,(A,$)=>void m(A,f,$,0)),stacked:!0}):null,t.jsx(pt,{}),e.ask&&Lt(f,e.ask.when)?t.jsx(GQ,{to:e.ask.to,row:f,label:e.ask.label,accent:!0}):null]}),children:t.jsx(JQ,{row:f,plugin:s.plugin,edition:e.edition})}):null]})}function vM({act:e}){return e.error?t.jsx(ae,{message:e.error}):e.approvalId?t.jsx(br,{act:e}):null}function GQ({to:e,row:n,label:s,accent:r}){const a=xt(),i=Ca(a,e,n);return i===""?null:"href"in e?t.jsx(nt,{variant:r?"accent":"ghost",href:i,target:"_blank",rel:"noopener noreferrer",children:s}):t.jsx(nt,{variant:r?"accent":"ghost",href:i,onClick:l=>{l.preventDefault(),a.navigate(i)},children:s})}function YQ({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(fo,{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(ie,{name:"check",size:12}),e.mark.text]}):t.jsx("span",{className:"pl-story-new",children:e.mark.text}):null]})}function qQ({plugin:e,outlets:n}){return n.length===0?null:t.jsxs("span",{className:"pl-stack","aria-label":pj(n),children:[t.jsx("span",{className:"pl-stack-logos",children:n.slice(0,3).map((s,r)=>t.jsx(Bo,{src:Zu(e,s.logo),label:s.name},r))}),t.jsx("span",{className:"pl-stack-words",children:pj(n)})]})}function QQ({row:e,plugin:n,menu:s,onOpen:r}){var i;const a=pj(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(qQ,{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(Jn,{label:`Ways out for ${e.title}`,items:s.map(l=>typeof l=="string"||"heading"in l?l:{label:l.label,...l.hint?{hint:l.hint}:{},onSelect:l.onSelect}),sheet:{title:e.title,sub:[e.kicker??((i=e.group)==null?void 0:i.name),a].filter(Boolean).join(" · ")},stacked:!0})}):null]}),t.jsx("h3",{className:"pl-story-title",children:e.title}),e.lead?t.jsx("p",{className:"pl-story-lead",children:e.lead}):null,t.jsx(YQ,{row:e})]})}function JQ({row:e,plugin:n,edition:s}){const r=Array.isArray(e.sources)?e.sources.filter(l=>l&&typeof l.title=="string"):[],a=Array.isArray(e.timeline)?e.timeline.filter(l=>l&&typeof l.text=="string"):[],i=s&&Lt(e,s.when)?s:void 0;return t.jsxs("div",{className:"pl-story-sheet",children:[t.jsxs("div",{className:"pl-story-sheet-lead",children:[e.opinion?t.jsx(fo,{children:"Opinion"}):null,t.jsx("h3",{className:"pl-story-sheet-title",children:e.title}),e.summary??e.lead?t.jsx("p",{className:"pl-story-sheet-summary",children:e.summary??e.lead}):null,e.update?t.jsxs("p",{className:"pl-story-sheet-update",children:[e.mark&&e.mark.kind==="new"?t.jsx("span",{className:"pl-story-new",children:e.mark.text}):null,e.update]}):null,e.meta||i?t.jsxs("p",{className:"pl-story-sheet-meta",children:[e.meta,i?t.jsxs(t.Fragment,{children:[e.meta?" · ":null,t.jsx(XQ,{to:i.to,row:e,label:i.label})]}):null]}):null]}),r.length>0?t.jsxs("section",{className:"pl-story-sheet-block",children:[t.jsx("h4",{className:"pl-story-sheet-head",children:"Sources"}),t.jsx("ul",{className:"pl-story-sources",children:r.map((l,o)=>{const c=$f(l.url);return t.jsxs("li",{className:"pl-story-source",children:[t.jsx(Bo,{className:"pl-logo-md",src:Zu(n,l.logo),label:l.outlet}),t.jsxs("span",{className:"pl-story-source-text",children:[c?t.jsx(go,{href:c,className:"wb-src-link pl-story-source-title",children:l.title}):t.jsx("span",{className:"pl-story-source-title",children:l.title}),l.meta?t.jsx("span",{className:"pl-story-source-meta",children:l.meta}):null]})]},o)})})]}):null,a.length>0?t.jsxs("section",{className:"pl-story-sheet-block",children:[t.jsx("h4",{className:"pl-story-sheet-head",children:"How it moved"}),t.jsx("ol",{className:"pl-story-timeline",children:a.map((l,o)=>t.jsxs("li",{className:"pl-story-tl","data-told":l.told?"true":void 0,"data-last":o===a.length-1?"true":void 0,children:[t.jsx("span",{className:"pl-story-tl-at",children:l.at}),t.jsx("span",{className:"pl-story-tl-dot","aria-hidden":"true"}),t.jsx("span",{className:"pl-story-tl-what",children:l.text})]},o))})]}):null]})}function XQ({to:e,row:n,label:s}){const r=xt(),a=Ca(r,e,n);return a===""?null:"href"in e?t.jsx(go,{href:a,children:s}):t.jsx("a",{href:a,onClick:i=>{i.preventDefault(),r.navigate(a)},children:s})}function ZQ({component:e,data:n}){const s=Ae(n,e.path);return typeof s!="string"||s===""?null:t.jsx(If,{id:s})}function eJ({component:e,data:n}){const s=Ae(n,e.path);return typeof s!="string"||s===""?null:t.jsx(re,{children:t.jsx("a",{href:ai(s),children:e.label})})}function jM(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 LC(e){return Array.isArray(e)?e.map(jM).filter(n=>n!==null):[]}function FC(e){return e.name?`${e.name} <${e.address}>`:e.address}function _C(e){if(!e||typeof e!="object")return null;const n=e,s=jM(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:LC(n.to),cc:LC(n.cc),at:r("at"),html:r("html"),text:r("text"),snippet:r("snippet"),note:r("note"),attachments:a}}function tJ(e){var s;return(((s=(e.name??e.address).replace(/^["'\s]+/,"").match(/[\p{L}\p{N}]/u))==null?void 0:s[0])??"?").toUpperCase()}function nJ(e){let n=0;for(const s of e.toLowerCase())n=n*31+s.charCodeAt(0)>>>0;return n%6+1}function sJ({component:e,data:n}){const s=xt(),r=e.path?Ae(n,e.path):n,a=e.folded!==void 0&&Lt(r,e.folded),[i,l]=d.useState(!a),[o,c]=d.useState(!1),u=Nn(i?e.query:void 0,r),h=_C(r),f=e.query?_C(u.data):h,m=f??h;if(!m)return null;const p=m.from,v=m.at?vm(new Date(m.at),s.timezone):"",g=[...m.to??[],...m.cc??[]],k=t.jsx("span",{className:"ui-avatar pl-mail-face","data-face":nJ(p.address),"aria-hidden":"true",children:tJ(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:[k,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(j=>!j),children:["to ",g.map(j=>j.name??j.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:v}):v})]}),o?t.jsxs("dl",{className:"pl-mail-recipients",children:[(m.to??[]).length>0?t.jsxs(t.Fragment,{children:[t.jsx("dt",{children:"To"}),t.jsx("dd",{children:(m.to??[]).map(FC).join(", ")})]}):null,(m.cc??[]).length>0?t.jsxs(t.Fragment,{children:[t.jsx("dt",{children:"Cc"}),t.jsx("dd",{children:(m.cc??[]).map(FC).join(", ")})]}):null]}):null,t.jsx(ae,{message:u.error}),e.query&&!f&&!u.error?t.jsx(be,{children:"Loading…"}):t.jsxs(t.Fragment,{children:[m.note?t.jsx("p",{className:"pl-mail-note",children:m.note}):null,t.jsx(WY,{html:m.html,text:m.text,sender:p.address,attachments:m.attachments,cidSrc:yr}),(m.attachments??[]).length>0?t.jsx(rJ,{attachments:m.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:[k,t.jsx("span",{className:"pl-mail-folded-who",children:p.name??p.address}),t.jsx("span",{className:"pl-mail-folded-snippet",children:m.snippet??""}),t.jsx("span",{className:"pl-mail-when",children:v})]})}function rJ({attachments:e,fetch:n}){const s=xt(),r=ea();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(ed,{name:a.name,mime:a.mime,sizeBytes:typeof a.size=="number"?a.size:null,...a.artifactId?{onOpen:()=>s.navigate(wc(a.artifactId))}:{}}),!a.artifactId&&n?t.jsx(wi,{action:n,args:zs(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(br,{act:r})]})}function aJ({component:e,data:n}){const s=Nn(e.query,n),r=ea();return s.error?t.jsx(ae,{message:s.error}):s.data===void 0?t.jsx(be,{children:e.empty??"Loading…"}):t.jsxs(t.Fragment,{children:[t.jsx(br,{act:r}),t.jsx(iJ,{component:e,data:n,loaded:s.data,act:r},JSON.stringify(Ja(s.data)))]})}function iJ({component:e,data:n,loaded:s,act:r}){const a=xt(),[i,l]=Rb(e.fields,s),o=e.fields.some(v=>v.from!==void 0&&zm(Ae(s,v.from))),c={...i,version:Ae(s,e.version)},u=Pb(e.fields,i,s),h=e.readOnlyWhen!==void 0&&Lt(s,e.readOnlyWhen),f=(e.actions??[]).filter(v=>v.placement==="leading"),m=(e.actions??[]).filter(v=>v.placement!=="leading"),p=(v,g)=>t.jsx(wi,{action:v,args:zs(v.args,{data:n,fields:c,shape:e.fields,omit:u,scope:a}),disabled:r.busy,running:r.running===v.tool,onRun:(k,j)=>void r.run(k,j)},`${v.tool}-${g}`);return t.jsx(Us,{title:e.title,note:e.note,children:t.jsxs(ue,{children:[t.jsx(Gm,{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(re,{align:"end",children:[f.map(p),f.length>0?t.jsx(pt,{}):null,p(e.save,-1),m.map(p)]}),e.footnote?t.jsx("p",{className:"ui-toolbar-note",children:e.footnote}):null]})})}const lJ={};function wM({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(j=>({...j,...l}))},[u]);const[h,f]=d.useState(0);h5(e.plugin,()=>f(j=>j+1));const[m]=tM(),p={plugin:e.plugin,page:e.id,pages:i??[e],item:n??null,params:{...o,...n?{item:n}:{},...dJ(e,n)},setParams:j=>c(x=>{const w={...x};for(const[N,y]of Object.entries(j))y===null?delete w[N]:w[N]=y;return w}),navigate:s,timezone:r,version:h,refresh:()=>f(j=>j+1),sensitive:new Set(e.sensitive??[]),sensitivePaths:e.sensitivePaths??lJ,amountsShown:m},v=e.body[0],g=!a&&(v==null?void 0:v.kind)==="notice"&&v.look!=="quiet"&&v.link===void 0&&v.action===void 0&&v.when===void 0&&v.title===void 0&&(v.tone===void 0||v.tone==="neutral")?v.text:void 0,k=g===void 0?e:{...e,body:e.body.slice(1)};return t.jsx(Tb.Provider,{value:p,children:t.jsx(oJ,{page:k,embedded:a===!0,lede:g})})}function oJ({page:e,embedded:n,lede:s}){const r=xt(),a=e.data!==void 0&&r.sensitive.has(e.data.query),i=Nn(a?void 0:e.data,null),l=i.data??null,o=s===void 0||typeof s=="string"?s:Ve(l,s),c=o==null||o===""?void 0:String(o),u=sQ([e.data,e.actions,e.body],r.sensitivePaths),h=!n&&e.actions&&e.actions.length>0,f=h||u?t.jsxs(t.Fragment,{children:[u?t.jsx(rQ,{}):null,h?e.actions.map((m,p)=>t.jsx(cJ,{component:m,data:l},p)):null]}):void 0;return t.jsxs(Ns,{embedded:n,title:e.title,lede:c,actions:f,children:[!n&&e.place==="rail"?t.jsx(WP,{plugin:e.plugin,navigate:r.navigate,dismissible:!0},e.plugin):null,t.jsx(uJ,{page:e,boxed:n,root:a?void 0:i})]})}function cJ({component:e,data:n}){const s=xt();if(!Lt(n,e.when))return null;if(e.kind==="button")return t.jsx(xM,{component:e,data:n});if(e.kind==="menu")return t.jsx(dM,{component:e,data:n});const r=Ca(s,e.to,n);if(r==="")return null;const a=e.tone==="accent"?"accent":"ghost";return"href"in e.to?t.jsxs(nt,{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(nt,{variant:a,href:r,onClick:i=>{i.preventDefault(),s.navigate(r)},children:e.label})}function uJ({page:e,boxed:n,root:s}){const r=xt();return e.data&&r.sensitive.has(e.data.query)?t.jsx(aM,{children:t.jsx(zC,{page:e,boxed:n})}):t.jsx(zC,{page:e,boxed:n,root:s})}function zC({page:e,boxed:n,root:s}){const r=Nn(s?void 0:e.data,null),a=s??r;return t.jsxs(ue,{gap:"lg",divided:!n,children:[t.jsx(ae,{message:a.error}),t.jsx($u.Provider,{value:n,children:e.body.map((i,l)=>t.jsx(Qr,{component:i,data:a.data??null},l))})]})}function dJ(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 hJ(e){return t.jsx(wM,{...e,embedded:!0})}function dl({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(os,{title:s,children:r||null})}const UC=[{id:"",label:"All files"},{id:"produced",label:"Created by agents"},{id:"uploaded",label:"Uploaded by you"}],fJ=["","image","pdf","table","text","code","audio","video","archive","file"];function mJ({hash:e,timezone:n,navigate:s,agents:r}){var O;const a=iB(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 f=(R,D=!1)=>s(wc(i,{q:c,origin:l,family:o,...R}),D);d.useEffect(()=>{if(u===c)return;const R=window.setTimeout(()=>f({q:u},!0),250);return()=>window.clearTimeout(R)},[u]);const[m,p]=d.useState(null),[v,g]=d.useState(null),[k,j]=d.useState(null),[x,w]=d.useState(!1),[N,y]=d.useState(!1),b=R=>{var D;return R?((D=r.find(U=>U.id===R))==null?void 0:D.name)??R:""},S=d.useRef(0);d.useEffect(()=>{const R=++S.current;p(null),g(null),w(!1),j(null),T.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{}}).then(D=>{S.current===R&&(p(D.entries),g(D.next))}).catch(D=>{S.current===R&&j(D instanceof he?D.message:String(D))})},[c,l,o]);const C=()=>{if(!v||x)return;w(!0);const R=S.current;T.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{},cursor:v}).then(D=>{S.current===R&&(p(U=>{const W=new Set((U??[]).map(M=>M.id));return[...U??[],...D.entries.filter(M=>!W.has(M.id))]}),g(D.next))}).catch(D=>{S.current===R&&j(D instanceof he?D.message:String(D))}).finally(()=>{S.current===R&&w(!1)})},A=(l?1:0)+(o?1:0),$=((O=UC.find(R=>R.id===l))==null?void 0:O.label)??l,I=t.jsxs(t.Fragment,{children:[m===null?t.jsx(be,{children:"Loading…"}):m.length===0?t.jsx(be,{children:"No file matches that."}):t.jsx(dt,{children:m.map(R=>t.jsx(eR,{href:wc(R.id,{q:c,origin:l,family:o}),current:R.id===i,onClick:()=>s(wc(R.id,{q:c,origin:l,family:o})),lead:t.jsx("span",{className:"files-row-visual","data-family":R.family,children:R.family==="image"&&!R.deleted?t.jsx("img",{src:yr(R.id),alt:"",loading:"lazy"}):t.jsx(eb,{family:R.family})}),title:R.filename??"Untitled file",meta:t.jsx("span",{title:mt(R.createdAt,n),children:Ye(R.createdAt)}),sub:`${R.caption&&R.origin==="produced"?`${R.caption} · `:""}${Bi[R.family]} · ${_n(R.sizeBytes)} · ${yM(R,b)}${pJ(R,b)}`},R.id))}),v?t.jsx("div",{className:"files-more",children:t.jsx(E,{size:"sm",onClick:C,disabled:x,children:x?"Loading…":"Show more"})}):null]}),P=m!==null&&m.length===0&&!c&&!l&&!o&&!u;return t.jsxs("div",{className:"ui-page files","data-selected":i?"true":void 0,children:[t.jsxs("header",{className:"ui-page-head",children:[t.jsx("h2",{className:"ui-page-title",children:"Files"}),t.jsx("p",{className:"ui-page-lede",children:"What your agents made or were given."})]}),P?t.jsx(os,{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(sR,{label:"Files",onSubmit:()=>f({q:u},!0),main:t.jsx("input",{type:"search",value:u,placeholder:"Search by name or label","aria-label":"Search files by name or label",onChange:R=>h(R.target.value)}),filters:t.jsxs(Ms,{dense:!0,children:[t.jsx(oe,{label:"Origin",children:t.jsx("select",{value:l,"aria-label":"Origin",onChange:R=>f({origin:R.target.value}),children:UC.map(R=>t.jsx("option",{value:R.id,children:R.label},R.id))})}),t.jsx(oe,{label:"Kind",children:t.jsx("select",{value:o,"aria-label":"Kind",onChange:R=>f({family:R.target.value}),children:fJ.map(R=>t.jsx("option",{value:R,children:R===""?"Any kind":Bi[R]},R))})})]}),filtersOpen:N,onToggleFilters:()=>y(R=>!R),active:A,chips:A>0?t.jsxs(t.Fragment,{children:[l?t.jsx(hf,{label:"Origin",onRemove:()=>f({origin:""}),children:$}):null,o?t.jsx(hf,{label:"Kind",onRemove:()=>f({family:""}),children:Bi[o]}):null]}):void 0}),t.jsx(ae,{message:k}),t.jsx(tR,{className:"files-split",label:"Files",list:I,detail:i?t.jsx(gJ,{id:i,timezone:n,agents:r,navigate:s,onBack:()=>s(wc(null,{q:c,origin:l,family:o}))},i):void 0,empty:"Choose a file to see it here."})]})]})}function pJ(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 yM(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 gJ({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 x=!1;return l(null),h(null),T.libraryEntry(e).then(w=>{x||l(w)}).catch(w=>{x||h(w instanceof he&&w.status===404?"This file is no longer in the library.":w instanceof he?w.message:String(w))}),()=>{x=!0}},[e]);const f=x=>{var w;return x?((w=s.find(N=>N.id===x))==null?void 0:w.name)??x:""};if(u)return t.jsxs("div",{className:"files-detail-body",children:[t.jsx(E,{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(be,{children:"Loading…"})});const{entry:m,contexts:p,contextsTotal:v,available:g}=i,k=m.filename??"Untitled file",j=()=>{c(!0),T.libraryEntry(e,p.length).then(x=>l(w=>w&&{...w,contexts:[...w.contexts,...x.contexts],contextsTotal:x.contextsTotal})).catch(()=>{}).finally(()=>c(!1))};return t.jsxs("div",{className:"files-detail-body",children:[t.jsx(E,{size:"sm",onClick:a,className:"files-back",children:"Back to Files"}),t.jsxs("header",{className:"files-detail-head",children:[t.jsx("span",{className:"files-detail-mark","data-family":m.family,"aria-hidden":"true",children:t.jsx(eb,{family:m.family})}),t.jsxs("div",{className:"files-detail-text",children:[t.jsx("h3",{className:"files-detail-name",children:k}),t.jsxs("p",{className:"files-detail-meta",children:[Bi[m.family]," · ",_n(m.sizeBytes)," · ",mt(m.createdAt,n)]})]}),g?t.jsx(ER,{artifactId:m.id,filename:m.filename,mime:m.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(CR,{artifactId:m.id,filename:m.filename,mime:m.mime,family:m.family,available:g}),t.jsx(Vt,{items:[{label:"Origin",value:yM(m,f)},...m.caption&&m.origin==="produced"?[{label:"Filed under",value:m.caption}]:[],...m.agentId&&m.origin==="produced"?[{label:"Made by",value:t.jsxs("span",{className:"files-agent",children:[t.jsx(an,{agents:s,id:m.agentId,size:"sm"}),f(m.agentId)]})}]:[],{label:"Type",value:t.jsx("span",{className:"mono",children:m.mime})},{label:"Id",value:t.jsx("span",{className:"mono",children:m.id})}]}),t.jsxs("section",{className:"files-conversations",children:[t.jsx("h4",{className:"ui-section-title",children:"Conversations"}),p.length===0?t.jsx("p",{className:"muted",children:"No conversation is recorded for this file. It may date from before the library kept track."}):t.jsx("ul",{className:"files-ctx",role:"list",children:p.map(x=>{const w=x.groupId?Ii(x.groupId,x.conversationId):lt(x.conversationAgentId,x.conversationId),N=x.groupId?x.groupName??"a group":f(x.conversationAgentId);return t.jsxs("li",{className:"files-ctx-row",children:[t.jsxs("span",{className:"files-ctx-text",children:[t.jsx("span",{children:x.groupId?`Group: ${N}`:N}),t.jsxs("span",{className:"muted",children:[" · ",x.kind==="produced"?`made by ${f(x.agentId)||"an agent"}`:x.kind==="reused"?"sent again":"sent by you"," · ",Ye(x.at)]})]}),t.jsx("a",{className:"ui-btn","data-size":"sm",href:w,onClick:y=>{y.preventDefault(),r(w)},children:"Open conversation"})]},`${x.conversationId}:${x.kind}`)})}),p.length<v?t.jsx(re,{align:"end",children:t.jsx(E,{size:"sm",onClick:j,disabled:o,children:o?"Loading…":`Show ${v-p.length} more`})}):null]})]})}const bM="buddi.keepClose";let xo=null;const gj=new Set;function xj(){for(const e of gj)e()}typeof window<"u"&&(window.addEventListener("beforeinstallprompt",e=>{e.preventDefault(),xo=e,xj()}),window.addEventListener("appinstalled",()=>{xo=null,Lb(),xj()}));function Ym(){const[e,n]=d.useState(xo);return d.useEffect(()=>{const s=()=>n(xo);return gj.add(s),s(),()=>{gj.delete(s)}},[]),kM()?null:e}async function Db(e){try{await e.prompt();const n=await e.userChoice;xo===e&&(xo=null);const s=(n==null?void 0:n.outcome)==="accepted";return s&&Lb(),xj(),s}catch{return!1}}function xJ(){try{return window.localStorage.getItem(bM)!==null}catch{return!1}}function Lb(){try{window.localStorage.setItem(bM,"dismissed")}catch{}}function kM(){var e;try{return((e=window.matchMedia)==null?void 0:e.call(window,"(display-mode: standalone)").matches)??!1}catch{return!1}}function vJ(e=window.location.hostname){const n=e.replace(/^\[|\]$/g,"").toLowerCase();return n==="127.0.0.1"||n==="::1"||n==="localhost"}function Fb(e=typeof navigator>"u"?"":navigator.userAgent){return/\bbuddi-mac\/\S+/.test(e)}function NM(e){return Fb(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 jJ(e){return/Mac|iPhone|iPad/.test(e)}function wJ(){const e=Ym(),[n,s]=d.useState(xJ);if(n||!e)return null;const r=()=>{Lb(),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(re,{align:"end",children:[t.jsx(E,{size:"sm",variant:"ghost",onClick:r,children:"Not now"}),t.jsx(E,{size:"sm",variant:"accent",onClick:()=>{Db(e).then(a=>{a&&s(!0)})},children:"Install"})]})]})}function yJ(){const e=Ym(),[n,s]=d.useState(void 0),[r]=d.useState(kM);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=vJ(),l=e?null:NM(a);return t.jsx(pe,{title:"The dashboard as an app",panel:!0,foot:e?t.jsx(re,{align:"end",children:t.jsx(E,{variant:"accent",onClick:()=>{Db(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 ",jJ(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 bJ={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 SM(e){return e&&bJ[e]||"plug"}const kJ=""+new URL("earth-2560-Ce3xs8Cb.webp",import.meta.url).href,NJ=""+new URL("earth-phone-BqC7cDhk.webp",import.meta.url).href,SJ="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=",vj={desk:kJ,phone:NJ,thumb:SJ},Sg={author:"ActionVance",authorUrl:"https://unsplash.com/@actionvance",photoUrl:"https://unsplash.com/photos/outer-space-photography-of-earth-t7EL2iG3jMc"};function CJ(e){return e?vj.phone:vj.desk}const CM="backgrounds/",EJ=`${CM}manifest.json`,AJ=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,$J=/^[\w.-]+\.jpg$/;function TJ(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"||!AJ.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"&&$J.test(u)?`${CM}${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 fc=null;function IJ(){if(!fc){const e=(async()=>{const n=await fetch(EJ,{credentials:"same-origin"});if(!n.ok)throw new Error(`manifest ${n.status}`);return TJ(await n.json())})();fc=e,e.catch(()=>{fc===e&&(fc=null)})}return fc}function EM(e=!0){const[n,s]=d.useState(null);return d.useEffect(()=>{if(!e)return;let r=!0;return IJ().then(a=>{r&&s(a)},()=>{r&&s([])}),()=>{r=!1}},[e]),n}const jj="picture:";function RJ(e){return`${jj}${e}`}function AM(e){return typeof e=="string"&&e.startsWith(jj)?e.slice(jj.length):null}function PJ(e,n){return n?{src:e.portrait??e.landscape,fit:"cover"}:e.landscape?{src:e.landscape,fit:"cover"}:{src:e.portrait,fit:"contain"}}function MJ(e,n,s){return s&&n?n:e}function $M(){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 OJ=3,TM=8e3,DJ={hiddenHere:new Set,restoredHere:new Set};function LJ(e,n){return n.hiddenHere.has(e.id)?!0:e.hidden&&!n.restoredHere.has(e.id)}function FJ(e,n=DJ){return(e??[]).filter(s=>!LJ(s,n)).slice(0,OJ)}function IM(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=(m,p)=>new Set(m).add(p),u=(m,p)=>{const v=new Set(m);return v.delete(p),v};return d.useEffect(()=>{if(!i)return;const m=window.setTimeout(()=>l(null),TM);return()=>window.clearTimeout(m)},[i]),{hiddenHere:n,restoredHere:r,justHidden:i,hide:(m,p)=>{s(v=>c(v,m.id)),a(v=>u(v,m.id)),l({glance:m,spot:p}),T.setGlanceHidden(m.id,!0).then(()=>{var v;return(v=o.current)==null?void 0:v.call(o)},()=>{s(v=>u(v,m.id)),l(v=>(v==null?void 0:v.glance.id)===m.id?null:v)})},undo:()=>{if(!i)return;const{glance:m}=i;l(null),s(p=>u(p,m.id)),a(p=>c(p,m.id)),T.setGlanceHidden(m.id,!1).then(()=>{var p;return(p=o.current)==null?void 0:p.call(o)},()=>{a(p=>u(p,m.id)),s(p=>c(p,m.id))})}}}function _J({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(E,{size:"sm",variant:"ghost",onClick:e.undo,children:"Undo"})]})}function zJ(e){return e.link?Gy(e.link.plugin,e.link.page,e.link.place):null}function UJ({glances:e,navigate:n,onChanged:s,except:r,hiding:a}){var u,h;const i=IM(s),l=a??i,o=FJ(e,l).filter(f=>!(r!=null&&r.has(f.id))),c=t.jsx(_J,{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(f=>{const m=zJ(f),p=t.jsxs(t.Fragment,{children:[t.jsx(ie,{name:zo(f.icon),size:14}),t.jsx("span",{children:f.text})]});return t.jsxs("span",{className:"home-glance",children:[t.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),m?t.jsx("a",{className:"home-glance-text",href:m,onClick:v=>{v.preventDefault(),n(m)},children:p}):t.jsx("span",{className:"home-glance-text",children:p}),t.jsx("button",{type:"button",className:"home-glance-hide","aria-label":`Hide ${f.title} from Home`,title:"Hide from Home",onClick:()=>l.hide(f,"line"),children:t.jsx(ie,{name:"close",size:10})})]},f.id)})]})}function BJ(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 WJ({points:e,className:n="wg-spark"}){const s=BJ(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 Cl=Math.PI/180;function HJ(e,n,s){const r=e.getTime()/864e5+24405875e-1-2451545,a=(357.529+.98560028*r)*Cl,l=(280.459+.98564736*r+1.915*Math.sin(a)+.02*Math.sin(2*a))*Cl,o=(23.439-36e-8*r)*Cl,c=Math.atan2(Math.cos(o)*Math.sin(l),Math.cos(l)),u=Math.asin(Math.sin(o)*Math.sin(l)),f=((18.697374558+24.06570982441908*r)*15+s)*Cl-c,m=n*Cl,p=Math.sin(m)*Math.sin(u)+Math.cos(m)*Math.cos(u)*Math.cos(f);return Math.asin(Math.max(-1,Math.min(1,p)))/Cl}function KJ(e,n,s){return HJ(e,n,s)>-.833}const VJ={small:2,medium:4},BC=new Map;function GJ(e){let n=BC.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"}),BC.set(e,n)),n}function WC(e,n){const s=Object.fromEntries(GJ(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 YJ(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 qJ(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 QJ(e,n,s,r,a){const i=WC(e,n.zone),l=WC(e,s),o=i.date===l.date?"Today":i.date>l.date?"Tomorrow":"Yesterday",c=i.offset-l.offset,u=Uu(a?{timeFormat:a}:{},()=>Tt(e,n.zone)),h=r?"your time":qJ(c);return{...i,day:o,daytime:typeof n.latitude=="number"&&typeof n.longitude=="number"?KJ(e,n.latitude,n.longitude):i.h>=6&&i.h<18,offsetText:r?"Here":YJ(c),time:u,label:`${n.label}, ${u}${o==="Today"?"":` ${o.toLowerCase()}`}, ${h}`}}function JJ(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 XJ(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 HC({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 ZJ=Array.from({length:12},(e,n)=>n);function eX({time:e,seconds:n}){const s=JJ(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"}),ZJ.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(HC,{angle:s.hour,length:24,width:4.6}),t.jsx(HC,{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 tX({body:e,size:n}){const s=Yn("(prefers-reduced-motion: reduce)"),r=XJ(!s),a=e.clocks.slice(0,VJ[n]);return t.jsx("div",{className:"wg-clocks","data-count":a.length,children:a.map((i,l)=>{let o;try{o=QJ(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(eX,{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 Cg=3,nX={small:4,medium:6};function Eg({icon:e,size:n}){return e?t.jsx("span",{className:"wg-icon",children:t.jsx(ie,{name:zo(e),size:n})}):null}function qm({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(Eg,{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(WJ,{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??Cg,n==="medium"?5:Cg));return t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"wg-list","data-dense":s.length>Cg?"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(Bo,{className:"wg-mark",src:TR(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(Eg,{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,nX[n]).map((s,r)=>t.jsxs("span",{className:"wg-tile",children:[t.jsx("span",{className:"wg-tile-label",children:s.label}),t.jsx(Eg,{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(tX,{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(ie,{name:zo(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 wj({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(ie,{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 KC(e){return"place"in e?e.place:`town:${e.latitude.toFixed(3)},${e.longitude.toFixed(3)}`}function sX(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 rX({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),[f,m]=d.useState(null),p=new Map;for(const N of s)p.set(N.id,{value:{place:N.id},label:N.label,sub:N.name});for(const N of[...a,...o])"place"in N||p.set(KC(N),{value:N,label:N.label,sub:N.name});const v=[...p.entries()].map(([N,y])=>({value:N,label:y.label,sub:y.sub})),g=a.map(KC),k=s.find(N=>N.id==="home"||N.label.toLowerCase()==="home")??s[0],j=e.multiple?g:g[0]??(k==null?void 0:k.id)??"",x=N=>{const y=(Array.isArray(N)?N:[N]).map(b=>{var S;return(S=p.get(b))==null?void 0:S.value}).filter(b=>!!b);r(e.multiple?y.slice(-3):y[0]??null)},w=()=>{const N=i.trim();N.length<2||(h(!0),m(null),T.findPlace(N).then(({found:y})=>{const b=y.slice(0,3).map(sX);c(b),b.length===0?m(`Nothing found for “${N}”.`):e.multiple?r([...a,b[0]].slice(-3)):r(b[0])}).catch(()=>m("The place finder didn’t answer. Try again in a moment.")).finally(()=>h(!1)))};return t.jsxs("div",{className:"wg-field-stack",children:[v.length>0?t.jsx(wj,{label:e.label,options:v,multiple:e.multiple,value:j,onChange:x}):null,t.jsxs("div",{className:"wg-find",children:[t.jsx("input",{value:i,placeholder:"Find a town: Tokyo","aria-label":`Find a town for ${e.label}`,onChange:N=>l(N.target.value),onKeyDown:N=>{N.key==="Enter"&&(N.preventDefault(),w())}}),t.jsx(E,{size:"sm",disabled:u||i.trim().length<2,onClick:w,children:u?"Finding…":"Find"})]}),f?t.jsx("span",{className:"ui-field-hint",children:f}):null]})}function aX({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(Xt,{label:e.label,options:l,value:o,onChange:r}):t.jsx(wj,{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(wj,{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(rX,{field:e,value:n,places:s.places,onChange:r});break;case"timeFormat":a=t.jsx(Xt,{label:e.label,options:[{value:"profile",label:vT()},{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 iX({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(qm,{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 RM({info:e,placement:n,surface:s,onSave:r,onRemove:a,onClose:i}){const l=me(()=>T.widgetSettings(e.id),[e.id]),[o,c]=d.useState(n.settings??{}),[u,h]=d.useState(null),[f,m]=d.useState(n.label??e.title),[p,v]=d.useState(!1),[g,k]=d.useState(null),j=d.useRef(0),x=d.useMemo(()=>JSON.stringify(o),[o]);d.useEffect(()=>{const y=++j.current,b=window.setTimeout(()=>{T.previewWidget({widget:e.id,size:n.size,settings:o}).then(S=>{y===j.current&&(h(S.view),m(S.label))}).catch(()=>{y===j.current&&h({state:"error",error:"the preview could not be made"})})},u?250:0);return()=>window.clearTimeout(b)},[x,e.id,n.size]);const w=()=>{v(!0),k(null),r(o).then(y=>{v(!1),y||k("Couldn’t keep these settings. Try again.")})},N=s==="lock"?"the lock screen":"Home";return t.jsx(Je,{title:f,onClose:i,foot:t.jsxs(re,{children:[t.jsxs(E,{variant:"danger-ghost",onClick:a,children:["Remove from ",s==="lock"?"lock screen":"Home"]}),t.jsx(pt,{}),t.jsx(E,{variant:"ghost",onClick:i,children:"Cancel"}),t.jsx(E,{variant:"accent",onClick:w,disabled:p||!l.data,children:p?"Saving…":"Save"})]}),children:t.jsxs("div",{className:"wg-sheet",children:[t.jsx(iX,{info:e,placement:n,surface:s,view:u,label:f}),t.jsxs("p",{className:"wg-sheet-note",children:[e.builtIn?"Built in":`From the ${e.plugin} plugin`," · on ",N,". These settings are this one’s own",s==="lock"?"; Home keeps its own":"","."]}),t.jsx(ae,{message:g??(l.error?"Couldn’t read this widget’s settings.":null)}),l.data?l.data.fields.map(y=>t.jsx(aX,{field:y,value:o[y.key],sheet:l.data,onChange:b=>c({...o,[y.key]:b})},y.key)):l.error?null:t.jsx("p",{className:"wg-sheet-note","aria-busy":"true",children:"Reading its choices…"})]})})}const lX=6e4,PM="buddi.clock",MM="buddi.home.widgets";function oX(){try{const e=Number(window.localStorage.getItem(MM));return Number.isInteger(e)&&e>0?Math.min(e,6):0}catch{return 0}}function cX(e){try{window.localStorage.setItem(MM,String(e))}catch{}}function OM(){const e=new Uint8Array(4);return crypto.getRandomValues(e),`w-${Array.from(e,n=>n.toString(16).padStart(2,"0")).join("")}`}function DM(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 uX(){const e=me(()=>T.widgets("home"),[],lX),[n,s]=d.useState(void 0);return d.useEffect(()=>{e.data&&s(e.data)},[e.data]),d.useEffect(()=>{n&&cX(n.home.length)},[n]),DM((n==null?void 0:n.home.some(r=>{var a,i;return r.widget===PM&&((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 dX(e){return new Set(((e==null?void 0:e.home)??[]).map(n=>n.widget))}function hX(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 LM=(e,n)=>e.label??(n==null?void 0:n.title)??e.widget;function fX({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[f,m]=hX(e.sensitive===!0),p=(s==null?void 0:s.state)??"error",v=e.sensitive===!0&&!f,g=e.link?Gy(e.link.plugin,e.link.page,e.link.place):null,k=g!==null&&!i&&p!=="error"&&!v,j=n.size==="small"?"medium":"small",x=LM(n,e),w=n.key,N=(((S=e.settings)==null?void 0:S.length)??0)>0;let y;!s&&i?y=t.jsx("span",{className:"wg-state",children:t.jsx("span",{className:"wg-state-sub",children:"Fills in when you press Done."})}):p==="error"||!s?y=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:[mX(s.error),"."]}):null,i?null:t.jsx(E,{size:"sm",onClick:c,disabled:u,children:u?"Trying…":"Try again"})]}):p==="empty"||!s.body?y=t.jsx("span",{className:"wg-state",children:t.jsx("span",{className:"wg-state-sub",children:"Nothing to show right now."})}):v?y=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(E,{size:"sm",onClick:()=>m(!0),children:"Show"})]}):y=t.jsx(qm,{body:s.body,size:n.size});const b=C=>{C.dataTransfer.effectAllowed="move",C.dataTransfer.setData("text/plain",w),h.start(w)};return t.jsxs("div",{className:"wg-frame",role:"group","aria-label":x,"data-id":e.id,"data-key":w,"data-size":n.size,"data-kind":s!=null&&s.body&&!v&&p!=="error"?s.body.kind:void 0,"data-state":p==="ok"?void 0:p,"data-linked":k?"true":void 0,"data-dragging":h.dragging===w?"true":void 0,"data-over":h.over===w&&h.dragging!==w?"true":void 0,draggable:i?!0:void 0,onDragStart:i?b:void 0,onDragOver:i?C=>{h.dragging&&(C.preventDefault(),h.enter(w))}:void 0,onDrop:i?C=>{C.preventDefault(),h.drop(w)}: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":w,"aria-label":`Move ${x}, position ${r+1} of ${a}: arrow keys`,title:"Drag, or use the arrow keys",onKeyDown:C=>{(C.key==="ArrowLeft"||C.key==="ArrowUp")&&(C.preventDefault(),o("earlier")),(C.key==="ArrowRight"||C.key==="ArrowDown")&&(C.preventDefault(),o("later"))},children:t.jsx(ie,{name:"grip",size:14})}):null,t.jsx("span",{className:"wg-title",children:x}),p==="stale"?t.jsx("span",{className:"wg-stale",title:s!=null&&s.error?`Couldn't refresh: ${s.error}.`:void 0,children:s!=null&&s.updatedAt?`${ay(s.updatedAt)} old`:"Not current"}):null,i&&N?t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Settings for ${x}`,title:"Settings",onClick:()=>o("settings"),children:t.jsx(ie,{name:"settings",size:14})}):null,i?t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Take ${x} off Home`,title:"Take off Home",onClick:()=>o("hide"),children:t.jsx(ie,{name:"close",size:12})}):t.jsx("span",{className:"wg-more",children:t.jsx(Jn,{label:`More for ${x}`,note:s!=null&&s.updatedAt?`${e.builtIn?"Built in":e.plugin} · ${Ye(s.updatedAt)}`:e.builtIn?"Built in":e.plugin,items:[N?{label:"Settings…",onSelect:()=>o("settings")}:null,r>0?{label:"Move earlier",onSelect:()=>o("earlier")}:null,r<a-1?{label:"Move later",onSelect:()=>o("later")}:null,e.sizes.includes(j)?{label:`Make it ${j}`,onSelect:()=>o("size",j)}:null,{label:"Edit widgets",onSelect:()=>o("edit")},"separator",{label:"Hide from Home",onSelect:()=>o("hide")}]})})]}),k?t.jsx("a",{className:"wg-body",href:g,onClick:C=>{C.preventDefault(),l(g)},children:y}):t.jsx("div",{className:"wg-body",children:y}),i?t.jsxs("div",{className:"wg-edit-bar",children:[e.sizes.length>1?t.jsx("span",{className:"ui-segment",role:"radiogroup","aria-label":`Size of ${x}`,children:["small","medium"].filter(C=>e.sizes.includes(C)).map(C=>t.jsx("button",{type:"button",className:"ui-tab",role:"radio","aria-checked":n.size===C,onClick:()=>o("size",C),children:C==="small"?"Small":"Medium"},C))}):t.jsx("span",{className:"wg-edit-note",children:e.sizes[0]==="small"?"Small only":"Medium only"}),t.jsxs("span",{className:"wg-edit-move",children:[t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","data-move":`${w}:earlier`,"aria-label":`Move ${x} earlier`,title:"Move earlier",disabled:r===0,onClick:()=>o("earlier"),children:t.jsx(ie,{name:"chevron-left"})}),t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","data-move":`${w}:later`,"aria-label":`Move ${x} later`,title:"Move later",disabled:r===a-1,onClick:()=>o("later"),children:t.jsx(ie,{name:"chevron-right"})})]})]}):null]})}function mX(e){const n=e.replace(/\.$/,"");return n.charAt(0).toUpperCase()+n.slice(1)}function pX({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,f]=d.useState(""),[m,p]=d.useState(null),[v,g]=d.useState(!1),[k,j]=d.useState(null),[x,w]=d.useState(null),[N,y]=d.useState(null),[b,S]=d.useState(null),[C,A]=d.useState(new Set),[$]=d.useState(oX),I=d.useRef(null);if(d.useEffect(()=>{if(!c)return;const H=window.setTimeout(()=>u(null),TM);return()=>window.clearTimeout(H)},[c]),d.useEffect(()=>{var ne;const H=I.current;H&&(I.current=null,(ne=document.querySelector(`[data-grip="${CSS.escape(H)}"], [data-move="${CSS.escape(H)}"]`))==null||ne.focus())}),!s)return $===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:$},(H,ne)=>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"})]})]},ne))})]});if(s.available.every(H=>H.builtIn)&&s.home.length===0)return null;const P=new Map(s.available.map(H=>[H.id,H])),O=a?l:s.home,R=H=>LM(H,P.get(H.widget)),D=(H,ne)=>(p(null),r({...ne,home:H,arranged:{...ne.arranged,home:!0}}),T.saveWidgets("home",H).then(Z=>(r(Z),!0),Z=>(r(ne),p(`Couldn't save your widgets: ${Z instanceof Error?Z.message:String(Z)}`),!1))),U=(H,ne,Z)=>{if(Z<0||Z>=H.length||ne===Z)return null;const ye=H.slice(),[Ce]=ye.splice(ne,1);return ye.splice(Z,0,Ce),f(`${R(Ce)}, position ${Z+1} of ${ye.length}.`),ye},W=()=>{o(s.home),A(new Set),u(null),p(null),i(!0)},M=H=>(ne,Z)=>{const ye=O[H];if(ne==="edit"){W();return}if(ne==="settings"){S(ye.key);return}if(a){if(ne==="earlier"||ne==="later"){const Ce=U(l,H,ne==="earlier"?H-1:H+1);if(Ce){const ke=document.activeElement;I.current=(ke==null?void 0:ke.dataset.grip)??(ke==null?void 0:ke.dataset.move)??null,o(Ce)}}ne==="size"&&Z&&(o(l.map((Ce,ke)=>ke===H?{...Ce,size:Z}:Ce)),A(new Set([...C,ye.key]))),ne==="hide"&&(o(l.filter((Ce,ke)=>ke!==H)),f(`${R(ye)} taken off.`));return}if(ne==="earlier"||ne==="later"){const Ce=U(s.home,H,ne==="earlier"?H-1:H+1);Ce&&D(Ce,s)}ne==="size"&&Z&&D(s.home.map((Ce,ke)=>ke===H?{...Ce,size:Z}:Ce),s),ne==="hide"&&D(s.home.filter((Ce,ke)=>ke!==H),s).then(Ce=>{Ce&&u({item:ye,at:H})})},L=()=>{if(!c)return;const H=s.home.filter(ne=>ne.key!==c.item.key);H.splice(Math.min(c.at,H.length),0,c.item),u(null),D(H,s)},_=()=>{g(!0),D(l,s).then(H=>{g(!1),H&&(i(!1),f("Widgets saved."))})},Y=H=>{j(H),T.refreshWidget(H).then(r,()=>{}).finally(()=>j(null))},B=H=>{var ye;const ne={key:OM(),widget:H.id,size:H.sizes[0],settings:{}},Z=l.some(Ce=>Ce.widget===H.id);o([...l,ne]),f(`${H.title} added.`),Z&&(((ye=H.settings)==null?void 0:ye.length)??0)>0&&S(ne.key)},se=(H,ne)=>a?(o(l.map(Z=>{if(Z.key!==H)return Z;const{label:ye,...Ce}=Z;return{...Ce,settings:ne}})),A(new Set([...C,H])),S(null),Promise.resolve(!0)):D(s.home.map(Z=>Z.key===H?{...Z,settings:ne}:Z),s).then(Z=>(Z&&(S(null),f("Settings saved.")),Z)),G=H=>{S(null);const ne=O.findIndex(Z=>Z.key===H);ne>=0&&M(ne)("hide")},X={dragging:x,over:N,start:H=>w(H),enter:H=>{N!==H&&y(H)},end:()=>{w(null),y(null)},drop:H=>{const ne=l.findIndex(Ce=>Ce.key===x),Z=l.findIndex(Ce=>Ce.key===H),ye=ne>=0&&Z>=0?U(l,ne,Z):null;ye&&o(ye),w(null),y(null)}},K=c?t.jsxs("div",{className:"wg-undo","data-size":c.item.size,role:"status","aria-live":"polite",children:[t.jsxs("span",{children:[R(c.item)," hidden"]}),t.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),t.jsx(E,{size:"sm",variant:"ghost",onClick:L,children:"Undo"})]},"undo"):null,J=[];O.forEach((H,ne)=>{const Z=P.get(H.widget);if(!Z)return;c&&!a&&c.at===ne&&J.push(K);const ye=a&&(C.has(H.key)||!s.home.some(Ce=>Ce.key===H.key));J.push(t.jsx(fX,{info:Z,placement:H,view:ye?void 0:s.views[H.key],index:ne,count:O.length,editing:a,navigate:n,act:M(ne),onRetry:()=>Y(H.key),retrying:k===H.key,drag:X},H.key))}),c&&!a&&c.at>=O.length&&J.push(K);const q=s.available.filter(H=>!H.builtIn),ce=q.length-2,xe=b?O.find(H=>H.key===b):void 0,Me=xe?P.get(xe.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(E,{size:"sm",variant:"ghost",onClick:()=>{i(!1),o([])},disabled:v,children:"Cancel"}),t.jsx(E,{size:"sm",variant:"accent",onClick:_,disabled:v,children:v?"Saving…":"Done"})]}):O.length>0?t.jsx("div",{className:"ui-toolbar","data-align":"end",children:t.jsx(E,{size:"sm",variant:"ghost",onClick:W,children:"Edit"})}):null]}),t.jsx("p",{className:"sr-only","aria-live":"polite",children:h}),m?t.jsx(Q,{tone:"critical",role:"alert",children:m}):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:"," ",(q.length>0?q:s.available).slice(0,2).map(H=>H.title).join(", "),ce>0?` and ${ce} more`:"","."]})]}),t.jsx(E,{size:"sm",variant:"accent",onClick:W,children:"Add widgets"})]}):J.length>0?t.jsx("div",{className:"wg-grid","data-editing":a?"true":void 0,children:J}):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:_e("lock"),onClick:H=>{H.preventDefault(),n(_e("lock"))},children:"The lock screen has its own pick"})]}),t.jsx("ul",{className:"wg-gallery-list",children:s.available.map(H=>{var we;const ne=l.filter(ve=>ve.widget===H.id).length,Z=(((we=H.settings)==null?void 0:we.length)??0)>0,ye=H.builtIn?"Built in":`${H.plugin} plugin`,Ce=H.sizes.length>1?"small or medium":`${H.sizes[0]} only`,ke=ne>1?` · ${ne} on Home`:ne===1&&Z?" · 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:H.title}),t.jsxs("span",{className:"wg-add-sub",children:[ye," · ",Ce,H.sensitive?" · hidden until you show it":"",ke]})]}),ne>0&&!Z?t.jsx("span",{className:"wg-add-note",children:"On Home"}):t.jsxs(E,{size:"sm","aria-label":`${ne>0?"Add another":"Add"} ${H.title}`,onClick:()=>B(H),children:[t.jsx(ie,{name:"plus",size:12})," ",ne>0?"Add another":"Add"]})]},H.id)})}),t.jsxs("a",{className:"wg-gallery-more",href:vv("widgets"),onClick:H=>{H.preventDefault(),n(vv("widgets"))},children:[t.jsx(ie,{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,xe&&Me?t.jsx(RM,{info:Me,placement:xe,surface:"home",onClose:()=>S(null),onSave:H=>se(xe.key,H),onRemove:()=>G(xe.key)}):null]})}function _b(e,n){return!e||e==="image"&&!n?"earth":e}const gX="(max-width: 720px)",xX="(orientation: portrait)",vX=3e4,jX=5e3,wX={1:"a minute",5:"5 minutes",15:"15 minutes",60:"an hour"};function Ag(e,n){return{time:Tt(e,n),day:Er(e,n,{weekday:!0})}}function Qm(e,n){return e?Uu({timeFormat:e.time,...e.date==="off"?{}:{dateFormat:e.date}},n):n()}function yX(e,n,s=new Date,r){return Qm(r,()=>bX(e,n,s))}function bX(e,n,s){if(!e.lockedAt)return"Locked";const r=new Date(e.lockedAt),i=Ag(r,n).day===Ag(s,n).day?Ag(r,n).time:vm(r,n);return e.reason==="idle"?`Locked after ${e.delayMinutes?wX[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 kX(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 NX=e=>`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`;function VC({size:e=16}){return t.jsx(ie,{name:"lock",size:e})}function FM({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 SX(){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 GC({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(E,{size:"sm",onClick:r,children:n?"Copied":"Copy"})]})}function CX({onClose:e}){return t.jsx(Rt,{title:"Forgot your PIN?",onClose:e,foot:t.jsx(E,{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(GC,{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(GC,{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 EX({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 AX(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 $X(e){return e.filter(n=>!(n.view.body.kind==="text"&&!n.view.body.sub))}function YC(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 TX(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 ${Qm(s,()=>{const i=Tt(a,n),l=YC(r,n)-YC(a,n);return l<=0?i:l===1?`yesterday ${i}`:l<7?`${new Intl.DateTimeFormat("en-US",{timeZone:n,weekday:"short"}).format(a)} ${i}`:`${Er(a,n,{compact:!0})} ${i}`})}`}function IX({widgets:e,phone:n,timezone:s,clockView:r,now:a}){const i=$X(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=AX(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=TX(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(qm,{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 RX({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 qC(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 PX(e,n,s){try{const r=qC(e,n)-qC(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 MX(e,n,s){const r=s??{date:null,zone:null};return Qm(s,()=>({time:Tt(e,n),day:r.date==="off"?null:Er(e,n,{weekday:!0}),zone:r.zone?{label:r.zone.label,time:Tt(e,r.zone.timezone),offset:PX(e,r.zone.timezone,n)}:null}))}function OX({background:e,image:n,imagePortrait:s,phone:r,portrait:a}){const i=AM(e),l=EM(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:CJ(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:MJ(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}=PJ(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 _M({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=MX(n,o,e==null?void 0:e.clockView),u=_b(e==null?void 0:e.background,e==null?void 0:e.image),h=(e==null?void 0:e.focus)??null,f=h?Qm(e==null?void 0:e.clockView,()=>s?_X(Tu(h,o,n)):`${Li[h.mode]} ${Tu(h,o,n)}`):"";return t.jsxs(t.Fragment,{children:[t.jsx(OX,{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(ku,{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(ie,{name:"moon",size:13}),t.jsx("span",{children:f})]}):null]}),t.jsxs("div",{className:"lk-main",children:[c.day?t.jsx("p",{className:"lk-date",children:c.day}):null,t.jsx(RX,{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(EX,{approvals:e.approvals,needs:e.needs??0,after:i??null,...l?{onPick:l}:{}}),a||!e?null:t.jsx(IX,{widgets:e.widgets,phone:s,timezone:o,clockView:e.clockView,now:n})]})]})}function DX({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(SX,{})}),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(FM,{size:18})})]})}function LX({initial:e,onUnlocked:n}){const s=Yn(gX),r=Yn(xX)||s,a=$M(),[i,l]=d.useState(null),o=i??e,[c,u]=d.useState(""),[h,f]=d.useState(null),[m,p]=d.useState((e==null?void 0:e.waitUntil)??null),[v,g]=d.useState(!1),[k,j]=d.useState(!1),[x,w]=d.useState(!1),[N,y]=d.useState(!1),[b,S]=d.useState(!1),[C,A]=d.useState(null),$=d.useRef(null),I=kX(m),P=I>0,O=d.useRef(n),R=d.useRef(C);R.current=C,O.current=J=>{R.current&&(window.location.hash=uo),n(J)};const D=J=>{var q;A(J),s&&J?y(!0):(q=$.current)==null||q.focus()},U=d.useRef(0),W=d.useRef(0),M=d.useRef(0),L=d.useCallback(()=>{const J=++U.current;M.current=Date.now(),T.lockScreen().then(q=>{J<W.current||(W.current=J,j(!1),l(q),p(q.waitUntil),q.locked||O.current(q))}).catch(q=>{q instanceof he&&q.status===401?window.location.reload():rf(q)&&j(!0)})},[]);d.useEffect(()=>{L();const J=window.setInterval(L,vX),q=()=>{document.visibilityState==="visible"&&L()},ce=()=>{Date.now()-M.current>=jX&&L()};return document.addEventListener("visibilitychange",q),document.addEventListener("resume",ce),window.addEventListener("focus",ce),window.addEventListener("pageshow",ce),window.addEventListener("online",L),()=>{window.clearInterval(J),document.removeEventListener("visibilitychange",q),document.removeEventListener("resume",ce),window.removeEventListener("focus",ce),window.removeEventListener("pageshow",ce),window.removeEventListener("online",L)}},[L]),DM((i==null?void 0:i.widgets.some(J=>J.id===PM&&J.view.body.kind!=="clocks"))??!1,L),d.useEffect(()=>{var J;!s&&!x&&!P&&((J=$.current)==null||J.focus())},[s,x,P,v]),d.useEffect(()=>{!P&&m&&f(null)},[P,m]);const _=J=>{J==null||J.preventDefault(),!(v||P||c.length<4)&&(g(!0),T.unlock(c).then(q=>{var xe;if(u(""),q.locked){g(!1);return}if((xe=window.matchMedia)==null?void 0:xe.call(window,"(prefers-reduced-motion: reduce)").matches){O.current(q);return}S(!0),window.setTimeout(()=>O.current(q),240)}).catch(q=>{if(g(!1),u(""),!(q instanceof he))return f("Something went wrong. Try again.");const ce=q.detail??{};if(q.status===403||q.status===429){ce.waitUntil&&p(ce.waitUntil);const xe=ce.triesLeft??0;f(ce.waitUntil?"That PIN isn’t right.":`That PIN isn’t right. ${xe} ${xe===1?"try":"tries"} left.`)}else rf(q)?f("buddi isn’t answering. Try again in a moment."):f(q.message)}))},Y=(i==null?void 0:i.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,B=_b(o==null?void 0:o.background,o==null?void 0:o.image),se=(i==null?void 0:i.owner)??null,G=k?{tone:"critical",text:"buddi isn’t answering. The lock stays until it does."}:P?{tone:"critical",text:`Too many tries. Try again in ${NX(I)}.`}: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?yX(o,Y,a,i==null?void 0:i.clockView):"Locked"},X=J=>J.replace(/\D/g,"").slice(0,8),K=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":N?"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(_M,{data:i??(o?{...zX(o)}:null),now:a,phone:s,portrait:r,pad:N,after:C,onPick:D}),t.jsx("footer",{className:"lk-unlock",children:s&&!N?t.jsxs(t.Fragment,{children:[t.jsxs("button",{type:"button",className:"lk-chip lk-enter",onClick:()=>y(!0),children:[t.jsx(VC,{size:14}),t.jsx("span",{children:"Enter PIN"})]}),t.jsx("p",{className:"lk-note","data-tone":G.tone,role:"status","aria-live":"polite",children:G.text})]}):s?t.jsxs(t.Fragment,{children:[K,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((J,q)=>t.jsx("span",{className:"lk-dot"},q))}),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":G.tone,role:"status","aria-live":"polite",children:G.text}),t.jsx(DX,{value:c,disabled:P||v,onDigit:J=>{f(null),u(X(c+J))},onBack:()=>u(c.slice(0,-1)),onSubmit:()=>_()}),t.jsxs("div",{className:"lk-pad-foot",children:[t.jsx("button",{type:"button",className:"lk-link",onClick:()=>w(!0),children:"Forgot PIN?"}),t.jsx("button",{type:"button",className:"lk-link",onClick:()=>{y(!1),u(""),f(null)},children:"Cancel"})]})]}):t.jsxs(t.Fragment,{children:[K,t.jsxs("form",{className:"lk-pin","data-state":h&&!P?"wrong":P?"wait":void 0,onSubmit:_,children:[t.jsx(VC,{size:15}),t.jsx("input",{ref:$,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:J=>{f(null),u(X(J.target.value))}}),t.jsx("button",{type:"submit",className:"lk-go","aria-label":"Unlock",disabled:v||P||c.length<4,children:t.jsx(FM,{})})]}),t.jsx("p",{className:"lk-note",id:"lk-note","data-tone":G.tone,role:"status","aria-live":"polite",children:G.text}),t.jsx("button",{type:"button",className:"lk-link",onClick:()=>w(!0),children:"Forgot PIN?"})]})}),i!=null&&i.version?t.jsx("p",{className:"lk-version",children:FX(i.version)}):null,x?t.jsx(CX,{onClose:()=>w(!1)}):null]})}function FX(e){return`buddi ${e.current}${e.updateAvailable?" · update ready":""}`}function _X(e){return e.slice(0,1).toUpperCase()+e.slice(1)}function zX(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 UX=3e4,BX=5e3,WX="buddi-lock",yj="buddi-locked",HX=_e("lock");function zM(){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 KX(e=zM()){return e?"⌃⌘L":"Ctrl+Alt+L"}function VX(e,n=zM()){return!(e.code==="KeyL"||e.key.toLowerCase()==="l")||!e.ctrlKey||e.shiftKey?!1:n?e.metaKey&&!e.altKey:e.altKey&&!e.metaKey}const UM=d.createContext({pin:!1,state:null,lockNow:()=>{},update:()=>{},shortcut:"⌃⌘L"});function Jm(){return d.useContext(UM)}function Yd(e){try{e?localStorage.setItem(yj,"1"):localStorage.removeItem(yj)}catch{}}function GX(){try{return localStorage.getItem(yj)==="1"}catch{return!1}}function YX(){try{return typeof BroadcastChannel>"u"?null:new BroadcastChannel(WX)}catch{return null}}function qX({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,k)=>{g&&a(g),s(k?"locked":"open"),Yd(k),k||(l.current=Date.now())},[]),f=d.useCallback(()=>{T.lockState().then(g=>h(g,g.locked)).catch(g=>{if(g instanceof he&&g.status===401)return s("open");h(null,GX())})},[h]);d.useEffect(()=>{f()},[f]);const m=d.useCallback((g="owner")=>{var k;if(!(r!=null&&r.pin)){window.location.hash=HX;return}s("locked"),Yd(!0),g==="owner"&&((k=i.current)==null||k.postMessage({type:"locked"})),(g==="idle"?T.lockNow("idle",Date.now()-l.current):T.lockNow(g)).then(j=>{var x;g==="idle"&&j.locked&&((x=i.current)==null||x.postMessage({type:"locked"})),h(j,j.locked)}).catch(()=>f())},[r==null?void 0:r.pin,h,f]);d.useEffect(()=>{const g=()=>{s("locked"),Yd(!0),f()};return window.addEventListener(sv,g),()=>window.removeEventListener(sv,g)},[f]),d.useEffect(()=>{const g=YX();if(i.current=g,!!g)return g.onmessage=k=>{const j=k.data;(j==null?void 0:j.type)==="locked"?(s("locked"),Yd(!0)):(j==null?void 0:j.type)==="unlocked"?f():(j==null?void 0:j.type)==="activity"&&typeof j.at=="number"&&(l.current=Math.max(l.current,j.at))},()=>{g.close(),i.current=null}},[f]),d.useEffect(()=>{const g=k=>{VX(k)&&(k.preventDefault(),n==="open"&&m("owner"))};return window.addEventListener("keydown",g,!0),()=>window.removeEventListener("keydown",g,!0)},[n,m]);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 y=Date.now();l.current=y,y-u.current>1e4&&(u.current=y,(b=i.current)==null||b.postMessage({type:"activity",at:y}))},k=()=>{const y=Date.now();l.current<=c.current||y-o.current<UX||(o.current=y,c.current=l.current,T.lockActivity().catch(()=>{}))},j=()=>{if(p!==null&&Date.now()-l.current>=p*6e4){m("idle");return}k()},x=["pointerdown","pointermove","keydown","wheel","touchstart"];for(const y of x)window.addEventListener(y,g,{passive:!0,capture:!0});const w=window.setInterval(j,BX),N=()=>{document.visibilityState==="visible"&&j()};return document.addEventListener("visibilitychange",N),()=>{for(const y of x)window.removeEventListener(y,g,{capture:!0});window.clearInterval(w),document.removeEventListener("visibilitychange",N)}},[n,r==null?void 0:r.pin,p,m]);const v=d.useMemo(()=>({pin:(r==null?void 0:r.pin)===!0,state:r,lockNow:()=>m("owner"),update:g=>h(g,g.locked),shortcut:KX()}),[r,m,h]);return n==="checking"?null:n==="locked"?t.jsx(LX,{initial:r,onUnlocked:g=>{var k;(k=i.current)==null||k.postMessage({type:"unlocked"}),h(g,!1)}}):t.jsx(UM.Provider,{value:v,children:e})}const BM="a connection needs you";function QX({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:f,status:m}){return t.jsxs("nav",{className:"rail","aria-label":"Places",children:[t.jsx("a",{className:"rail-mark",href:Tn,onClick:p=>{p.preventDefault(),s(Tn)},"aria-label":"buddi home",children:t.jsx(ku,{})}),SB.filter(p=>p.route!==hn).map(p=>t.jsx($g,{label:p.label,href:p.route,active:n===p.route,badge:p.route===Tn?e:0,onClick:()=>s(p.route),children:QC[p.route]},p.route)),i.map(p=>{const v=Yr(p.plugin,p.id);return t.jsx($g,{label:p.title,href:v,active:n===v,badge:0,onClick:()=>s(v),children:t.jsx(ie,{name:SM(p.icon)})},v)}),t.jsx("div",{className:"rail-spacer"}),t.jsx($g,{label:"Settings",href:hn,active:n===hn,badge:0,dot:l?"a newer buddi is ready":o,onClick:()=>s(hn),children:QC[hn]}),m,t.jsx(XX,{theme:r,onTheme:a,onNavigate:s,version:c,stale:u,reload:h,timezone:f})]})}const JX=[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}];function XX({theme:e,onTheme:n,onNavigate:s,version:r,stale:a,reload:i=()=>window.location.reload(),timezone:l}){var N,y,b;const o=me(()=>T.owner(),[]),c=Jm(),u=me(()=>T.focus(),[],6e4),h=((N=u.data)==null?void 0:N.focus)??null,f=(S,C)=>{T.setFocus(S,C).finally(()=>u.reload())},m=((b=(y=o.data)==null?void 0:y.preferredName)==null?void 0:b.trim())||null,p=(m??"You").slice(0,1).toUpperCase(),[v]=d.useState(()=>UB()||Fb()),[g]=d.useState(tZ),k=Ym(),j=m?`You: ${m}`:"You",x=h?`${Li[h.mode]} ${Tu(h,l)}`:null,w=[j,x,a?"reload to update":null].filter(Boolean).join(", ");return t.jsx("div",{className:"rail-owner",children:t.jsxs(Ku,{modal:!1,children:[t.jsx(Vu,{asChild:!0,children:t.jsxs("button",{type:"button",className:"rail-owner-btn","aria-label":w,children:[t.jsx("span",{className:"rail-owner-face","aria-hidden":"true",children:p}),a?t.jsx("span",{className:"ui-badge rail-dot","data-kind":"dot","data-testid":"owner-dot","aria-hidden":"true"}):null,h?t.jsx("span",{className:"rail-focus","data-testid":"owner-focus","aria-hidden":"true",children:t.jsx(ie,{name:"moon",size:10})}):null]})}),t.jsx(Oo,{children:t.jsxs(Gu,{className:"ui-menu rail-owner-menu",side:"right",align:"end",sideOffset:10,children:[t.jsxs("div",{className:"rail-owner-head",children:[t.jsx("span",{className:"rail-owner-face","data-size":"lg","aria-hidden":"true",children:p}),t.jsxs("span",{className:"rail-owner-who",children:[t.jsx("span",{className:"rail-owner-name",children:m??"You"}),t.jsx("span",{className:"rail-owner-sub",children:"On this Mac"})]})]}),t.jsx(_r,{className:"ui-menu-sep"}),t.jsx(eZ,{focus:h,timezone:l,onSwitch:f}),t.jsx(_r,{className:"ui-menu-sep"}),t.jsx(Ji,{className:"ui-menu-label",children:"Theme"}),t.jsx("div",{className:"rail-owner-theme",children:t.jsx(Xt,{label:"Theme",options:JX,value:e,onChange:n})}),t.jsx(_r,{className:"ui-menu-sep"}),c.pin?t.jsxs(ms,{className:"ui-menu-item rail-owner-reload",onSelect:()=>c.lockNow(),children:[t.jsx("span",{children:"Lock now"}),t.jsx("kbd",{className:"rail-owner-kbd",children:c.shortcut})]}):t.jsx(ms,{className:"ui-menu-item",onSelect:()=>s(_e("lock")),children:"Set up a lock screen…"}),t.jsx(ms,{className:"ui-menu-item",onSelect:()=>s(_e("appearance")),children:"Change appearance"}),k?t.jsx(ms,{className:"ui-menu-item",onSelect:()=>{Db(k)},children:"Install the app"}):null,v||a?t.jsxs(ms,{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"}),g?t.jsx("kbd",{className:"rail-owner-kbd",children:g}):null]}):null,r?t.jsxs(t.Fragment,{children:[t.jsx(_r,{className:"ui-menu-sep"}),t.jsxs(ms,{className:"ui-menu-item rail-owner-version","data-update":r.updateAvailable?"true":void 0,onSelect:()=>s(_e("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 Li={normal:"Off","urgent-only":"Urgent only","do-not-disturb":"Do not disturb"},ZX=[{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 Tu(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=Tt(r,a);return i(r)===i(s)?`until ${l}`:`until ${new Intl.DateTimeFormat("en-US",{timeZone:a,weekday:"short"}).format(r)} ${l}`}function eZ({focus:e,timezone:n,onSwitch:s}){return t.jsxs(P6,{children:[t.jsxs(M6,{className:"ui-menu-item rail-owner-focus",children:[t.jsx("span",{children:"Focus"}),t.jsx("span",{className:"rail-owner-kbd",children:e?Li[e.mode]:"Off"})]}),t.jsx(Oo,{children:t.jsxs(O6,{className:"ui-menu rail-owner-menu",sideOffset:6,children:[t.jsx("p",{className:"ui-menu-empty",role:"status",children:e?`${Li[e.mode]} ${Tu(e,n)}${e.by==="schedule"?", from a schedule":""}.`:"No focus is on."}),["do-not-disturb","urgent-only"].map(r=>t.jsxs(jy,{children:[t.jsx(_r,{className:"ui-menu-sep"}),t.jsx(Ji,{className:"ui-menu-label",children:Li[r]}),ZX.map(a=>t.jsx(ms,{className:"ui-menu-item","aria-label":`${Li[r]} ${a.label.toLowerCase()}`,onSelect:()=>s(r,a.value),children:a.label},a.value))]},r)),e?t.jsxs(t.Fragment,{children:[t.jsx(_r,{className:"ui-menu-sep"}),t.jsx(ms,{className:"ui-menu-item",onSelect:()=>s("normal"),children:"Turn off"})]}):null]})})]})}function tZ(){const e=window.navigator.userAgent;return/iPhone|iPad|Android|Mobile/.test(e)?null:/Mac/.test(e)?"⌘R":"Ctrl+R"}function $g({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 QC={[ba]:t.jsx(ie,{name:"files"}),[Tn]:t.jsx(ie,{name:"home"}),[pa]:t.jsx(ie,{name:"chat"}),[bt]:t.jsx(ie,{name:"agents"}),[Jt]:t.jsx(ie,{name:"activity"}),[hn]:t.jsx(ie,{name:"settings"})},Iu=e=>`${e.plugin}:${e.id}`,nZ=new Set;let zb=nZ,JC=!1;const bj=new Set;function kj(e){zb=e;for(const n of bj)n()}function sZ(e){return bj.add(e),()=>bj.delete(e)}const XC=()=>zb;function rZ(){JC||(JC=!0,Promise.resolve().then(()=>T.rail()).then(e=>kj(new Set(Array.isArray(e==null?void 0:e.hidden)?e.hidden.filter(n=>typeof n=="string"):[]))).catch(()=>{}))}async function aZ(e,n){const s=zb,r=new Set(s);n?r.add(Iu(e)):r.delete(Iu(e)),kj(r);try{await T.setRailHidden(e.plugin,e.id,n)}catch(a){throw kj(s),a}}function WM(){return d.useEffect(rZ,[]),d.useSyncExternalStore(sZ,XC,XC)}function iZ(e,n){return e.filter(s=>!n.has(Iu(s)))}function lZ(e){return e instanceof HTMLElement?e.isContentEditable?!0:e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.tagName==="SELECT":!1}function oZ(e,n=!0,s){d.useEffect(()=>{if(!n)return;const r=a=>{if(a.key!=="/"||a.defaultPrevented||a.ctrlKey||a.metaKey||a.altKey||lZ(a.target))return;a.preventDefault();const i=document.getElementById(rj);if(i instanceof HTMLTextAreaElement){!i.disabled&&!i.hidden&&i.focus();return}s?s():e(Tn)};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,n,s])}const HM="buddi.theme";function cZ(e=KM()){try{const n=e==null?void 0:e.getItem(HM);return n==="light"||n==="dark"||n==="system"?n:"system"}catch{return"system"}}function uZ(e,n=KM()){try{n==null||n.setItem(HM,e)}catch{}}function dZ(e,n=document.documentElement){n&&(e==="system"?n.removeAttribute("data-theme"):n.setAttribute("data-theme",e))}function KM(){try{return window.localStorage}catch{return}}const VM="buddi.ground",GM="buddi.pageWidth";function hZ(e=QM()){const n=a=>{try{return(e==null?void 0:e.getItem(a))??null}catch{return null}},s=n(VM),r=n(GM);return{theme:cZ(e),ground:s==="sand"?"sand":"blue",width:r==="narrow"||r==="full"?r:"wide"}}function YM(e,n=document.documentElement){n&&(dZ(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 fZ(e,n=QM()){uZ(e.theme,n);try{n==null||n.setItem(VM,e.ground),n==null||n.setItem(GM,e.width)}catch{}}let to=null;const Nj=new Set;function Sj(){return to||(to=hZ()),to}function mZ(e){return Nj.add(e),()=>Nj.delete(e)}function pZ(e){to={...Sj(),...e},YM(to),fZ(to);for(const n of Nj)n()}function qM(){return[d.useSyncExternalStore(mZ,Sj,Sj),pZ]}function QM(){try{return window.localStorage}catch{return}}const ZC=7,gZ=1e4;function xZ({timezone:e,embedded:n,agents:s=[],navigate:r}){const{data:a,error:i,reload:l}=me(()=>T.sentinels(),[],3e4),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(null),[p,v]=d.useState(null),[g,k]=d.useState(!1),[j,x]=d.useState(null),w=a==null?void 0:a.alerts,N=(w==null?void 0:w.open)??[],y=W=>{r?r(W):window.location.hash=W},b=W=>{var M;return W?((M=s.find(L=>L.id===W))==null?void 0:M.name)??null:null},S=async W=>{c(null);try{await W()}catch(M){c(M instanceof he||M instanceof Error?M.message:String(M))}finally{l()}},C=W=>h({...W,id:Date.now()}),A=(W,M,L)=>S(async()=>{const{keys:_}=await T.snoozeAlerts(W,!0,L);C({title:M,undo:()=>T.snoozeAlerts(_,!1)})}),$=W=>S(async()=>{const{id:M}=await T.muteAlert(W.keys[0],W.stop.scope);C({title:"You won’t hear about this again",body:"Turn it back on in Settings → Watchers.",undo:()=>T.unmuteAlert(M)})}),I=W=>S(async()=>{const{agentId:M,conversationId:L}=await T.askAboutAlerts(W.keys);y(lt(M,L))}),P=W=>S(async()=>{const[M]=(await T.actOnAlerts([{key:W.key,action:W.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:`${W.label}: done`})}),O=(W,M)=>{M.kind==="open"?y(M.place==="files"?ba:M.plugin&&M.page?Yr(M.plugin,M.page,M.item):ba):M.kind==="ask"?I(W):M.kind==="dismiss"?A(W.keys,"Set aside until it changes"):M.kind==="fill"?m(M):M.confirm?v(M):P(M)},R=()=>{const W=N.flatMap(M=>M.keys);A(W,`Cleared ${N.length} for a week`,ZC)},D=w==null?void 0:w.recap,U=vZ((D==null?void 0:D.nextAt)??null,e);return t.jsxs(Ns,{embedded:n,title:"Alerts",lede:"What needs a decision from you.",children:[t.jsx(ae,{message:i??o}),t.jsxs(st,{flush:!0,title:"Needs a decision",tool:N.length>0?String(N.length):void 0,actions:N.length>1?t.jsx(E,{size:"sm",variant:"ghost",onClick:R,children:"Clear all"}):void 0,children:[a?N.length===0?t.jsxs("div",{className:"al-empty",children:[t.jsx(ie,{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:N.map(W=>t.jsx(e1,{group:W,agentName:b(W.agentId),onAct:O,onStop:$,onNotNow:M=>void A(M.keys,"Snoozed for a week",ZC)},W.id))}):null,D&&D.count>0?t.jsxs("p",{className:"al-recap","data-testid":"recap-line",children:[t.jsxs("span",{children:[D.count," ",D.count===1?"note":"notes"," saved for ",U]}),t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("button",{type:"button",className:"wb-link",onClick:()=>k(!0),children:"Preview"})]}):null]}),w&&(w.snoozed.length>0||w.resolved.length>0)?t.jsxs("p",{className:"al-quiet",children:[w.snoozed.length>0?t.jsxs("button",{type:"button",className:"wb-link","aria-expanded":j==="snoozed",onClick:()=>x(j==="snoozed"?null:"snoozed"),children:[w.snoozed.length," snoozed"]}):null,w.snoozed.length>0&&w.resolved.length>0?t.jsx("span",{"aria-hidden":"true",children:"·"}):null,w.resolved.length>0?t.jsxs("button",{type:"button",className:"wb-link","aria-expanded":j==="resolved",onClick:()=>x(j==="resolved"?null:"resolved"),children:[w.resolved.length," resolved this week"]}):null]}):null,j==="snoozed"&&w?t.jsx(st,{flush:!0,title:"Snoozed",children:t.jsx("ul",{className:"al-list",children:w.snoozed.map(W=>t.jsxs("li",{className:"al-row",children:[t.jsxs("div",{className:"al-main",children:[t.jsx("p",{className:"al-title",children:W.title}),t.jsx("p",{className:"al-sub",children:W.snoozedUntil?`Back ${Ye(W.snoozedUntil)}`:"Until it changes"})]}),t.jsx("div",{className:"al-actions",children:t.jsx(E,{size:"sm",onClick:()=>void S(async()=>{await T.snoozeAlerts(W.keys,!1)}),children:"Bring back"})})]},W.id))})}):null,j==="resolved"&&w?t.jsx(st,{flush:!0,title:"Resolved this week",children:t.jsx("ul",{className:"al-list",children:w.resolved.map(W=>t.jsx("li",{className:"al-row",children:t.jsxs("div",{className:"al-main",children:[t.jsx("p",{className:"al-title",children:W.title}),t.jsx("p",{className:"al-sub",children:W.resolvedAt?`Resolved ${Ye(W.resolvedAt)}`:null})]})},W.id))})}):null,g&&D?t.jsxs(Je,{title:jZ(U),onClose:()=>k(!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:D.groups.map(W=>t.jsx(e1,{group:W,agentName:b(W.agentId),recap:!0,onAct:(M,L)=>{L.kind!=="fill"&&k(!1),O(M,L)},onStop:M=>{$(M)}},W.id))})]}):null,f?t.jsx(wZ,{action:f,onClose:()=>m(null),onSaved:W=>{m(null),k(!1),C({title:`Saved ${W}`}),l()}}):null,p?t.jsx(Rt,{title:p.label,onClose:()=>v(null),foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:()=>v(null),children:"Cancel"}),t.jsx(E,{variant:p.tone==="danger"?"danger":"accent",onClick:()=>{const W=p;v(null),P(W)},children:p.label})]}),children:t.jsx("p",{children:p.confirm})}):null,u?t.jsx(Cu,{title:u.title,...u.body?{body:u.body}:{},duration:gZ,...u.undo?{onUndo:()=>{const W=u.undo;S(async()=>{await W()})}}:{},onGone:()=>h(null)},u.id):null]})}function vZ(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 jZ(e){return e.charAt(0).toUpperCase()+e.slice(1)}function qd(e,n){return e.kind==="ask"?e.label??(n?`Ask ${n}`:"Ask about it"):e.label}function e1({group:e,agentName:n,recap:s,onAct:r,onNotNow:a,onStop:i}){const[l,o]=d.useState(!1),[c,u,...h]=e.actions,f=e.actions.some(p=>p.kind==="ask"),m=e.items.length>1;return 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 ",Ye(e.since)]}),m?t.jsxs(t.Fragment,{children:[n||!s?t.jsx("span",{"aria-hidden":"true",children:"·"}):null,t.jsx("button",{type:"button",className:"wb-link al-toggle","aria-expanded":l,onClick:()=>o(p=>!p),children:l?"Hide":`Show the ${e.items.length}`})]}):null]}),l&&m?t.jsx("ul",{className:"al-items",children:e.items.map(p=>t.jsxs("li",{className:"al-item",children:[p.subject?t.jsx("span",{className:"al-item-who",children:p.subject.label}):null,t.jsx("span",{className:"al-item-note",children:p.subject?p.note:p.line}),p.actions&&p.actions.length>0?t.jsx("span",{className:"al-item-actions",children:p.actions.map((v,g)=>t.jsx(E,{size:"sm",variant:v.kind==="run"&&v.tone==="danger"?"danger-ghost":"ghost",onClick:()=>r(e,v),children:qd(v,n)},g))}):null]},p.key))}):null]}),t.jsxs("div",{className:"al-actions",children:[c?t.jsx(E,{size:"sm",variant:"accent",onClick:()=>r(e,c),children:qd(c,n)}):null,u?t.jsx(E,{size:"sm",variant:u.kind==="run"&&u.tone==="danger"?"danger-ghost":void 0,onClick:()=>r(e,u),children:qd(u,n)}):null,a?t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>a(e),children:"Not now"}):null,t.jsx("span",{className:"al-more",children:t.jsx(Jn,{label:`More for ${e.title}`,sheet:{title:e.title},items:[...h.map(p=>({label:qd(p,n),...p.kind==="run"&&p.tone==="danger"?{tone:"critical"}:{},onSelect:()=>r(e,p)})),!f&&{label:n?`Ask ${n}`:"Ask about it",onSelect:()=>r(e,{kind:"ask",label:null})},"separator",{label:"Stop telling me this",hint:"Undo in Settings → Watchers",onSelect:()=>i(e)}]})})]})]})}function wZ({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,f]=d.useState(null),m=async()=>{const p=e.fields.filter(v=>(a[v.key]??"").trim()!=="").map(v=>({key:v.key,action:v.index,value:(a[v.key]??"").trim()}));if(p.length===0){n();return}u(!0),f(null);try{const{results:v}=await T.actOnAlerts(p),g=Object.fromEntries(v.filter(k=>k.error).map(k=>[k.key,k.error]));o(g),Object.keys(g).length===0&&s(p.length)}catch(v){f(v instanceof Error?v.message:String(v))}finally{u(!1)}};return t.jsx(Je,{title:e.title,onClose:n,foot:t.jsxs("div",{className:"al-form-foot",children:[t.jsx(E,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:c,onClick:()=>void m(),children:c?"Saving…":"Save"})]}),children:t.jsxs("div",{className:"al-form",children:[t.jsx(ae,{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:v=>i(g=>({...g,[p.key]:v.target.value}))}),l[p.key]?t.jsx("span",{className:"al-form-error",children:l[p.key]}):null]},p.key))})]})})}function yZ({mutes:e,onChanged:n}){const[s,r]=d.useState(null);return e.length===0?null:t.jsxs(st,{flush:!0,title:"Silenced",tool:String(e.length),children:[t.jsx(ae,{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” ",Ye(a.createdAt)]})]}),t.jsx("div",{className:"al-actions",children:t.jsx(E,{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 t1=5e3,n1=50;function bZ({timezone:e,embedded:n}){var j;const[s,r]=d.useState(""),[a,i]=d.useState(""),[l,o]=d.useState(null),c=me(()=>T.eventKinds(),[]),{data:u,error:h}=me(()=>T.events({kind:s||void 0,q:a||void 0,limit:n1}),[s,a],t1),[f,m]=d.useState({events:[],cursor:null,busy:!1,error:null});d.useEffect(()=>{m({events:[],cursor:null,busy:!1,error:null})},[s,a]);const p=f.events.length>0?f.cursor:(u==null?void 0:u.nextCursor)??null,v=async()=>{if(p){m(x=>({...x,busy:!0,error:null}));try{const x=await T.events({kind:s||void 0,q:a||void 0,before:p,limit:n1});m(w=>({events:[...w.events,...x.events],cursor:x.nextCursor,busy:!1,error:null}))}catch(x){m(w=>({...w,busy:!1,error:x instanceof Error?x.message:String(x)}))}}},g=new Set(((u==null?void 0:u.events)??[]).map(x=>x.id)),k=[...(u==null?void 0:u.events)??[],...f.events.filter(x=>!g.has(x.id))];return t.jsxs(Ns,{embedded:n,title:"Events",lede:"The append-only log. Everything the installation did, including what you do here.",children:[t.jsxs(re,{children:[t.jsxs("select",{"aria-label":"Event kind",value:s,onChange:x=>r(x.target.value),children:[t.jsx("option",{value:"",children:"every kind"}),(((j=c.data)==null?void 0:j.kinds)??[]).map(x=>t.jsxs("option",{value:x.kind,children:[x.kind," (",x.count,")"]},x.kind))]}),t.jsx("input",{"aria-label":"Payload contains",placeholder:"payload contains…",value:a,onChange:x=>i(x.target.value),size:28}),s||a?t.jsx(E,{onClick:()=>{r(""),i("")},children:"Clear"}):null,t.jsxs("span",{className:"muted",children:["refreshes every ",t1/1e3,"s"]})]}),t.jsx(ae,{message:h}),t.jsx(st,{flush:!0,children:!u||k.length===0?t.jsx(be,{children:"No events match."}):t.jsxs(Zr,{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:k.map(x=>t.jsxs("tr",{"data-clickable":"true",onClick:()=>o(x),children:[t.jsx("td",{className:"mono muted",children:x.id}),t.jsxs("td",{className:"nowrap",children:[mt(x.createdAt,e),t.jsx("div",{className:"sub",children:Ye(x.createdAt)})]}),t.jsx("td",{className:"mono nowrap",children:x.kind}),t.jsx("td",{className:"mono muted",children:xr(ls(x.payload).replace(/\s+/g," "),120)})]},x.id))})]})}),p||f.error?t.jsxs(re,{children:[t.jsxs("span",{className:"muted",children:[k.length," shown",p?", older ones are kept":"","."]}),t.jsx("span",{className:"ui-toolbar-spacer"}),f.error?t.jsx("span",{className:"critical",children:f.error}):null,p?t.jsx(E,{disabled:f.busy,onClick:()=>void v(),children:f.busy?"Loading…":"Load older"}):null]}):null,l?t.jsxs(Je,{title:l.kind,onClose:()=>o(null),children:[t.jsxs("p",{className:"muted",children:["Event ",l.id," · ",mt(l.createdAt,e),l.conversationId?t.jsxs(t.Fragment,{children:[" · ",t.jsx("a",{href:`#/conversations/${l.conversationId}`,children:"conversation"})]}):null]}),t.jsx(Bt,{children:ls(l.payload)})]}):null]})}const s1=["pending","leased","suspended","failed","succeeded","cancelled"],mc=50,kZ=1e4,NZ=(e,n,s=`${n}s`)=>e===1?n:s;function SZ({timezone:e,embedded:n,initialState:s}){var _,Y;const[r,a]=d.useState(s??""),[i,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(!1),p=r==="failed",{data:v,error:g,reload:k}=me(()=>T.jobs({...r?{state:r}:{},...r?{}:{dismissed:"0"},limit:String(mc)}),[r],1e4),j=me(()=>T.jobFailures(),[],1e4),[x,w]=d.useState({jobs:[],done:!1,busy:!1});d.useEffect(()=>{w({jobs:[],done:!1,busy:!1})},[r]);const N=async()=>{w(B=>({...B,busy:!0}));try{const B=await T.jobs({...r?{state:r}:{dismissed:"0"},limit:String(mc),offset:String(mc+x.jobs.length)});w(se=>({jobs:[...se.jobs,...B.jobs],done:B.jobs.length<mc,busy:!1}))}catch(B){c(B instanceof Error?B.message:String(B)),w(se=>({...se,busy:!1}))}},y=new Set(((v==null?void 0:v.jobs)??[]).map(B=>B.id)),b=[...(v==null?void 0:v.jobs)??[],...x.jobs.filter(B=>!y.has(B.id))],S=(v==null?void 0:v.counts)??{},C=r?S[r]??0:s1.reduce((B,se)=>B+(S[se]??0),0),A=!x.done&&b.length<C&&((v==null?void 0:v.jobs.length)??0)>=mc,$=((_=j.data)==null?void 0:_.open)??[],I=((Y=j.data)==null?void 0:Y.dismissed)??[],P=$.reduce((B,se)=>B+se.count,0),O=I.reduce((B,se)=>B+se.count,0),R=()=>{k(),j.reload()},D=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{R()}},W=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&&D({title:`Dismissed ${se.length===1?"it":se.length}`,body:"Kept under Dismissed, below.",undo:()=>T.undismissJobs(se)})}),L=(B,se)=>U(async()=>{const{jobs:G}=await T.retryJobs({ids:B});if(G.length===0)return;const X=G.length===1;D({title:`Retrying ${X?"it":G.length}`,body:se?`${X?"It runs":"They run"} as soon as a worker is free.`:`If what broke ${X?"it":"them"} hasn’t changed, ${X?"it":"they"} will fail the same way.`})});return t.jsxs(Ns,{embedded:n,title:"Jobs",lede:`${v!=null&&v.paused?"Paused: nothing is being claimed. ":""}Bounded retries with backoff; past the budget a job waits for you.`,actions:n?void 0:t.jsx(E,{size:"sm",variant:v!=null&&v.paused?"accent":void 0,onClick:()=>W(T.setPaused(!((v==null?void 0:v.paused)??!1))),children:v!=null&&v.paused?"Resume the queue":"Pause the queue"}),children:[t.jsx(ae,{message:g??j.error??o}),$.length>0?t.jsxs(st,{flush:!0,title:"Gave up",tool:String(P),actions:P>1?t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>void M("all"),children:"Dismiss all"}):void 0,children:[t.jsx("ul",{className:"al-list",children:$.map(B=>t.jsx(a1,{group:B,timezone:e,onOpen:l,onRetry:se=>void L(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&&j.data?t.jsx(st,{flush:!0,children:t.jsxs("div",{className:"al-empty",children:[t.jsx(ie,{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":f,onClick:()=>m(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,f&&I.length>0?t.jsx(st,{flush:!0,title:"Dismissed",children:t.jsx("ul",{className:"al-list",children:I.map(B=>t.jsx(a1,{group:B,timezone:e,dismissed:!0,onOpen:l,onRetry:se=>void L(se,B.likelyFixed)},B.key))})}):null,p?null:t.jsx(st,{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"}),s1.map(B=>t.jsxs("option",{value:B,children:[B," (",S[B]??0,")"]},B))]}),children:!v||b.length===0?t.jsx(be,{children:"No jobs match."}):t.jsxs(Zr,{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:pu(B.id)})]}),t.jsxs("td",{children:[t.jsx(Xu,{state:B.state}),B.suspendedReason?t.jsx("div",{className:"sub",children:xr(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?xr(B.lastError,80):"—"}),t.jsxs("td",{className:"nowrap",children:[mt(B.updatedAt,e),t.jsx("div",{className:"sub",children:Ye(B.updatedAt)})]}),t.jsx("td",{children:t.jsxs(re,{align:"end",children:[["failed","cancelled","suspended"].includes(B.state)?t.jsx(E,{size:"sm",onClick:()=>W(T.retryJob(B.id)),children:"Retry"}):null,["pending","leased","suspended","failed"].includes(B.state)?t.jsx(E,{size:"sm",variant:"danger",onClick:()=>W(T.cancelJob(B.id)),children:"Cancel"}):null]})})]},B.id))})]})}),A&&!p?t.jsxs(re,{children:[t.jsxs("span",{className:"muted",children:[b.length," of ",C," shown."]}),t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx(E,{disabled:x.busy,onClick:()=>void N(),children:x.busy?"Loading…":"Load older"})]}):null,i?t.jsxs(Je,{title:i.kind,onClose:()=>l(null),children:[t.jsx("p",{className:"muted mono",children:i.id}),i.lastError?t.jsx(pe,{title:"Last error",children:t.jsx(Bt,{children:i.lastError})}):null,t.jsx(pe,{title:"Payload",children:t.jsx(Bt,{children:ls(i.payload)})}),t.jsx(pe,{title:"Result",children:t.jsx(Bt,{children:ls(i.result)})}),i.conversationId?t.jsx("p",{children:t.jsx("a",{href:`#/conversations/${i.conversationId}`,children:"open the transcript"})}):null]}):null,u?t.jsx(Cu,{title:u.title,...u.body?{body:u.body}:{},duration:kZ,...u.undo?{onUndo:()=>{const B=u.undo;U(async()=>{await B()})}}:{},onGone:()=>h(null)},u.id):null]})}function r1(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()!==""?xr(n.trim().split(`
128
+ `)[0],48):e.job.kind==="agent-run"?"Agent run":e.job.kind}function a1({group:e,timezone:n,dismissed:s,onOpen:r,onRetry:a,onDismiss:i}){var v;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),f=e.jobs[0],m=e.jobs.every(g=>g.job.acknowledgedBy==="auto"),p=s?m?"dismissed on its own after 14 days":`dismissed ${Ye(((v=e.jobs[0])==null?void 0:v.job.acknowledgedAt)??e.lastAt)}`:`gave up ${Ye(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&&f?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:"wb-link",onClick:()=>r(f.job),children:r1(f)}),t.jsx("span",{"aria-hidden":"true",children:"·"})]}):null,t.jsx("span",{title:mt(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:r1(g)})," · ",vm(new Date(g.job.updatedAt),n)," · tried ",g.job.attempts," ",NZ(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(E,{size:"sm",variant:e.likelyFixed&&!s?"accent":void 0,onClick:()=>a(u),children:c?"Retry all":"Retry"}),i?t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>i(u),children:"Dismiss"}):null]})]})}const CZ=[{id:"conversations",label:"Conversations"},{id:"jobs",label:"Jobs"},{id:"approvals",label:"Approvals"},{id:"alerts",label:"Alerts"},{id:"events",label:"Events"}];function EZ({hash:e,timezone:n,navigate:s,agents:r}){var u,h;const a=/^#\/activity\/conversations\/(.+)$/.exec(e),i=f=>{var m;return((m=r.find(p=>p.id===f))==null?void 0:m.name)??f};if(a){let f=a[1];try{f=decodeURIComponent(f)}catch{}return t.jsx(TZ,{id:f,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=f=>m=>{m.preventDefault(),s(f)};return t.jsxs("div",{className:"ui-page",children:[t.jsx(Ui,{title:"Activity",lede:"Everything your agents ran, newest first.",actions:t.jsx(PZ,{})}),t.jsx(MZ,{}),t.jsx(_o,{children:CZ.map(f=>{const m=f.id==="conversations"?Jt:`${Jt}/${f.id}`;return t.jsx(Zi,{href:m,active:l===f.id,onClick:c(m),children:f.label},f.id)})}),l==="conversations"?t.jsx(AZ,{timezone:n,navigate:s,nameOf:i,agents:r}):null,l==="jobs"?t.jsx(SZ,{timezone:n,embedded:!0,initialState:o},o??""):null,l==="approvals"?t.jsx($Z,{timezone:n,nameOf:i}):null,l==="alerts"?t.jsx(xZ,{timezone:n,embedded:!0,agents:r,navigate:s}):null,l==="events"?t.jsx(bZ,{timezone:n,embedded:!0}):null]})}function AZ({timezone:e,navigate:n,nameOf:s,agents:r}){const{data:a,error:i}=me(()=>T.conversations(),[],3e4);return t.jsxs(t.Fragment,{children:[t.jsx(ae,{message:i}),t.jsx(st,{flush:!0,children:a?a.conversations.length===0?t.jsx(os,{icon:"activity",title:"Nothing has run yet",children:"Conversations and runs show up here as your agents work."}):t.jsx(dt,{children:a.conversations.map(l=>t.jsx(ot,{href:ju(l.id),onClick:()=>n(ju(l.id)),lead:t.jsx(an,{agents:r,id:l.agentId,size:"sm"}),title:l.opening?xr(l.opening,100):"Untitled conversation",sub:`${s(l.agentId)}, ${l.messageCount} message${l.messageCount===1?"":"s"}, ${l.runs} run${l.runs===1?"":"s"}, ${Jz(l.usage)}`,side:t.jsx("span",{title:mt(l.lastMessageAt??l.createdAt,e),children:Ye(l.lastMessageAt??l.createdAt)})},l.id))}):t.jsx(be,{children:"Loading…"})})]})}function $Z({timezone:e,nameOf:n}){const{data:s,error:r}=me(()=>T.approvals(),[],1e4),a=[...(s==null?void 0:s.pending)??[],...(s==null?void 0:s.recent)??[]];return t.jsxs(t.Fragment,{children:[t.jsx(ae,{message:r}),t.jsx(st,{flush:!0,children:s?a.length===0?t.jsx(os,{icon:"bell",title:"No approvals yet",children:"When an agent asks before acting, the request and your answer are kept here."}):t.jsxs(Zr,{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:pu(i.id)})]}),t.jsx("td",{children:t.jsx(Xu,{state:i.state})}),t.jsx("td",{children:n(i.agentId)}),t.jsx("td",{className:"nowrap",children:i.decidedAt?t.jsxs(t.Fragment,{children:[mt(i.decidedAt,e),t.jsxs("div",{className:"sub",children:["via ",i.decidedVia??"—"]})]}):t.jsx("span",{className:"muted",children:"—"})}),t.jsxs("td",{className:"nowrap",children:[mt(i.createdAt,e),t.jsx("div",{className:"sub",children:Ye(i.createdAt)})]})]},i.id))})]}):t.jsx(be,{children:"Loading…"})})]})}function TZ({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:Jt,onClick:c(Jt),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(E,{size:"sm",onClick:()=>s(Jt),children:"← Back"}),t.jsx("span",{children:"Transcript"})]}),a?t.jsx("div",{className:"ui-page-actions",children:t.jsx(nt,{size:"sm",href:lt(a.agentId,e),onClick:c(lt(a.agentId,e)),children:"Open in chat"})}):null]}),t.jsx("p",{className:"ui-page-lede mono",children:e})]}),t.jsx(ae,{message:l}),a?t.jsxs(t.Fragment,{children:[t.jsxs(Lm,{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:`${mn(a.usage.input)} / ${mn(a.usage.output)}`,note:nv(a.usage)?`input / output, ${nv(a.usage)}`:"input / output"}),t.jsx(zr,{label:"Started",value:mt(a.createdAt,n),size:"sm"})]}),a.runs.length>0?t.jsx(st,{title:"Runs",flush:!0,children:t.jsxs(Zr,{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:[mt(u.startedAt,n)," ",u.resumed?t.jsx(Se,{children:"resumed"}):null]}),t.jsx("td",{className:"nowrap",children:mt(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 ",pu(u.actionId)]}):null]}),t.jsxs("td",{className:"num muted nowrap",children:[mn(u.usage.input)," / ",mn(u.usage.output)]}),t.jsx("td",{className:"num muted nowrap",children:u.usage.cacheRead||u.usage.cacheWrite?mn((u.usage.cacheRead??0)+(u.usage.cacheWrite??0)):"—"})]},h))})]})}):null,t.jsx(pe,{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===i1?"approved action, result":u.role,", ",mt(u.createdAt,n)]}),t.jsxs("div",{className:"transcript-body",children:[u.blocks.length===0?t.jsx("span",{className:"muted",children:"(empty)"}):null,u.speaker===i1?u.blocks.map((h,f)=>t.jsx(IZ,{block:h},f)):u.blocks.map((h,f)=>t.jsx(RZ,{block:h},f))]})]},u.id))})})]}):t.jsx(be,{children:"Loading…"})]})}const i1="approval:resume";function IZ({block:e}){return t.jsxs("div",{className:"transcript-tool",children:[t.jsx("div",{className:"transcript-tool-name mono",children:"← approved action"}),t.jsx(Bt,{children:e.type==="text"?e.text??"":ls(e)})]})}function RZ({block:e}){return e.type==="text"?t.jsx("div",{className:"transcript-text",children:t.jsx(wr,{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(wr,{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(Bt,{children:ls(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(Bt,{children:e.content??""})]}):t.jsxs("div",{className:"transcript-tool",children:[t.jsx("div",{className:"transcript-tool-name mono",children:e.type}),t.jsx(Bt,{children:ls(e.ref)})]})}function PZ(){const{data:e,reload:n}=me(()=>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(E,{size:"sm",variant:e.paused?"accent":void 0,disabled:s,onClick:a,children:e.paused?"Resume all":"Pause all"})}function MZ(){const{data:e,reload:n}=me(()=>T.overview(),[],1e4);if(d.useEffect(()=>(window.addEventListener(Di,n),()=>window.removeEventListener(Di,n)),[n]),!e)return null;const s=a=>e.jobs[a]??0,r=s("leased");return t.jsxs(Lm,{children:[t.jsx(zr,{label:"Jobs done",value:mn(s("succeeded"))}),t.jsx(zr,{label:"Failed",value:mn(s("failed")),...s("failed")>0?{tone:"critical"}:{}}),t.jsx(zr,{label:"Queued",value:mn(s("pending")),note:`${r} running`}),t.jsx(zr,{label:"Approvals",value:mn(e.approvals.pending),note:"waiting for you"})]})}const OZ=["replay-all","coalesce","latest-only","skip-after-deadline"];function JM({timezone:e,embedded:n,agentId:s}){const{data:r,error:a,reload:i}=me(()=>T.missions(),[],3e4),l=((r==null?void 0:r.missions)??[]).filter(h=>!s||h.agentId===s),[o,c]=d.useState(null),u=async h=>{c(null);try{await h,i()}catch(f){c(f instanceof Error?f.message:String(f))}};return t.jsxs(Ns,{embedded:n,title:"Missions",lede:"Standing schedules. A disabled mission materializes nothing.",children:[t.jsx(ae,{message:a??o}),!r||l.length===0?t.jsxs(os,{icon:"calendar",title:"No missions yet",children:["Run ",t.jsx("code",{children:"buddi missions add-defaults"})," for the standard set."]}):t.jsx(ue,{children:l.map(h=>t.jsx(DZ,{mission:h,timezone:e,onRun:u},h.id))})]})}function DZ({mission:e,timezone:n,onRun:s}){const[r,a]=d.useState(!1);return t.jsxs(Ar,{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(Se,{mono:!0,children:e.agentId}),e.alwaysDeliver?t.jsx(Se,{children:"always delivers"}):null,e.enabled?null:t.jsx(Se,{tone:"warning",children:e.endedAt?"ended":"disabled"}),e.pausedReason?t.jsx(Se,{tone:"warning",children:e.pausedReason}):null]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(E,{size:"sm",onClick:()=>s(T.setMissionEnabled(e.id,!e.enabled)),children:e.enabled?"Disable":"Enable"}),t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>a(i=>!i),"aria-expanded":r,children:r?"Less":"More"})]}),children:[e.stillUsefulAskedAt?t.jsx(Q,{tone:"warning",title:"Still useful?",action:t.jsxs(re,{align:"end",children:[t.jsx(E,{size:"sm",onClick:()=>s(T.answerStillUseful(e.id,"stop")),children:"Stop"}),t.jsx(E,{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(re,{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(pt,{}),t.jsx(Fo,{checked:e.browser==="owner",label:`Let ${e.name} use your Chrome`,onChange:i=>s(T.setMissionChrome(e.id,i))})]}):null,e.stopWhen||e.endsAt?t.jsxs("p",{className:"ui-card-meta",children:[e.stopWhen?`Stops itself when ${e.stopWhen}. `:"",e.endedAt?`Ended ${mt(e.endedAt,n)}.`:e.endsAt?`Ends ${mt(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?`${mt(e.nextRun,n)} (${Ye(e.nextRun)})`:"—"]}):"no schedule — enqueued by hand or by a sentinel",t.jsx("br",{}),"Last notification:"," ",e.lastNotification?`${e.lastNotification.kind==="mission.delivered"?"delivered":"silent"} ${Ye(e.lastNotification.at)}${e.lastNotification.reason?` — ${e.lastNotification.reason}`:""}`:"none"]}),r?t.jsxs("div",{className:"ui-card-foot",children:[e.schedule?t.jsxs(re,{children:[t.jsx(oe,{inline:!0,label:"Misfire policy",children:t.jsx("select",{value:e.schedule.misfirePolicy,onChange:i=>s(T.setMisfirePolicy(e.id,i.target.value)),children:OZ.map(i=>t.jsx("option",{value:i,children:i},i))})}),t.jsx("span",{className:"muted",children:"What a week asleep does: replay every instant, coalesce into one, keep only the latest, or skip past a deadline."})]}):null,t.jsx(pe,{title:"Prompt",children:t.jsx(Bt,{children:e.prompt})}),t.jsx(pe,{title:"Recent occurrences",children:t.jsx(st,{flush:!0,children:e.occurrences.length===0?t.jsx(be,{children:"Never run."}):t.jsxs(Zr,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Scheduled"}),t.jsx("th",{children:"State"}),t.jsx("th",{children:"Finished"}),t.jsx("th",{children:"Detail"})]})}),t.jsx("tbody",{children:e.occurrences.map(i=>t.jsxs("tr",{children:[t.jsx("td",{className:"nowrap",children:mt(i.scheduledAt,n)}),t.jsx("td",{children:t.jsx(Xu,{state:i.state})}),t.jsx("td",{className:"nowrap",children:mt(i.finishedAt,n)}),t.jsxs("td",{className:i.error?"critical":"muted",children:[i.error?xr(i.error,120):null,i.runConversationId?t.jsx("a",{href:`#/conversations/${i.runConversationId}`,children:"transcript"}):null]})]},i.id))})]})})})]}):null]})}function LZ(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 XM({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:LZ(r,n)}),t.jsx(E,{size:"sm",variant:"danger",disabled:l,onClick:()=>{o(!0),T.dismissOffers(e).then(()=>{i(!1),s()}).finally(()=>o(!1))},children:`Dismiss ${r}`}),t.jsx(E,{size:"sm",variant:"ghost",disabled:l,onClick:()=>i(!1),children:"Keep them"})]}):t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>i(!0),children:"Dismiss all"})}function ZM({embedded:e,agentId:n,agentName:s}){const{data:r,error:a,reload:i}=me(()=>T.offers(),[],2e4),l=j=>!n||j.agentId===n,o=((r==null?void 0:r.offers)??[]).filter(l),c=((r==null?void 0:r.closed)??[]).filter(l),[u,h]=d.useState(null),[f,m]=d.useState(null),[p,v]=d.useState(null),g=async(j,x)=>{h(null),m(j);try{const w=await T.takeOffer(j);v(w.jobId?`On it — ${x}. Started as job ${w.jobId}.`:`Taken — ${x}. No worker is running here, so nothing has started yet.`),i()}catch(w){h(w instanceof Error?w.message:String(w))}finally{m(null)}},k=async(j,x)=>{h(null),m(j);try{await T.dismissOffer(j),v(`Dismissed — ${x}. It will not come back.`),i()}catch(w){h(w instanceof Error?w.message:String(w))}finally{m(null)}};return t.jsxs(Ns,{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(ae,{message:a??u}),p?t.jsx(Q,{tone:"good",role:"status",children:p}):null,o.length>0?t.jsxs(re,{children:[t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx(XM,{ids:o.map(j=>j.id),agentName:s,onDone:()=>{v(null),i()}})]}):null,!r||o.length===0?t.jsx(os,{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(j=>t.jsx(Ar,{tone:"accent",title:j.label,meta:t.jsxs(t.Fragment,{children:[t.jsx(Se,{mono:!0,children:j.agentId}),t.jsxs("span",{className:"muted",children:["expires ",Ye(j.expiresAt)]})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(E,{size:"sm",variant:"ghost",disabled:f===j.id,onClick:()=>void k(j.id,j.label),children:"Not now"}),t.jsx(E,{variant:"accent",size:"sm",disabled:f===j.id,onClick:()=>void g(j.id,j.label),children:"Take"})]}),children:t.jsx("p",{className:"ui-card-meta",children:j.prompt})},j.id))}),c.length>0?t.jsxs(Gt,{summary:`Dismissed and lapsed (${c.length})`,boxed:!0,children:[t.jsx(st,{flush:!0,children:t.jsx(dt,{children:c.map(j=>t.jsx(ot,{title:j.label,sub:`${j.agentId} — ${t3(j)}`,side:Ye(j.dismissedAt??j.lapsedAt??j.createdAt)},j.id))})}),t.jsx("p",{className:"muted",children:"These stop being shown a week after they closed."})]}):null]})}function FZ(e){var r,a;const n=me(()=>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 _Z({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(f=>{const m=f.agents.find(p=>p.name===e.package);m?a(m):l(f.unavailable??`The catalogue no longer lists ${e.title}.`)}).catch(f=>l(f instanceof he?f.message:String(f))).finally(()=>c(!1))};return t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:"agent-catalogue-line","data-testid":"agent-catalogue-line","data-delisted":e.delisted?"true":void 0,children:[e.delisted?t.jsx("span",{children:"No longer in the catalogue"}):t.jsx("a",{href:pn(e.package),onClick:f=>{f.preventDefault(),n(pn(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})`:po(e.version)]}),e.delisted?t.jsx("span",{className:"muted",children:" · it keeps working; no updates will come"}):null,u?t.jsx(E,{size:"sm",variant:u==="update"?"accent":void 0,disabled:o,onClick:h,children:u==="update"&&e.latest?`Update to ${po(e.latest)}`:u==="update"?"Update":"See what changed"}):null]}),i?t.jsx(ae,{message:i}):null,r?t.jsx(FP,{entry:r,agentId:e.agentId,onClose:()=>a(null),onUpdated:s}):null]})}function zZ(e){return typeof e=="string"?e:e.name??e.id??"a mission"}function UZ({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),[f,m]=d.useState(null),p=()=>{a(!1),m(null),s(bt)},v=N=>N instanceof he?N.message:String(N),g=()=>{a(!0),c(null),l(null),T.agentRemovePreview(e).then(l).catch(N=>c(v(N)))},k=()=>{h(!0),c(null),T.removeAgent(e).then(N=>{var b;window.dispatchEvent(new Event(ks));const y=(b=N.result)==null?void 0:b.delegateListsNotUpdated;if(Array.isArray(y)&&y.length>0){m(y.map(S=>String((S==null?void 0:S.handle)??(S==null?void 0:S.id)??"")));return}a(!1),s(bt)}).catch(N=>c(v(N))).finally(()=>h(!1))},j=(i==null?void 0:i.pausesMissions.map(zZ))??[],x=(i==null?void 0:i.unusedPlugins)??[],w=((i==null?void 0:i.handedWorkBy)??[]).map(N=>`@${N}`);return t.jsxs(st,{children:[t.jsxs(re,{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(E,{variant:"danger-ghost",onClick:g,children:["Remove ",n,"…"]})]}),r&&f?t.jsx(Rt,{title:`${n} is off your team`,onClose:p,foot:t.jsx(E,{variant:"accent",onClick:p,children:"Done"}),children:t.jsxs(Q,{tone:"warning",title:"Cleanup is incomplete",role:"status",children:["The delegate list of ",ln(f.map(N=>`@${N}`))," could not be updated and still names it. That entry reaches nobody; edit the list to remove it."]})}):r?t.jsxs(Rt,{title:`Remove ${n} from your team?`,onClose:()=>a(!1),foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:()=>a(!1),children:"Cancel"}),t.jsx(E,{variant:"danger",disabled:u||!i,onClick:k,children:"Remove from team"})]}),children:[t.jsx(ae,{message:o}),i?t.jsxs("div",{className:"ui-stack","data-testid":"remove-preview",children:[t.jsxs("p",{children:["@",i.handle,"’s folder moves to the trash folder, so it can be brought back by hand."]}),j.length>0?t.jsxs("p",{children:["Its ",j.length===1?"mission":"missions"," ",ln(j)," ",j.length===1?"is":"are"," paused."]}):null,w.length>0?t.jsxs("p",{children:[ln(w)," will stop handing work to it."]}):null,x.length>0?t.jsxs("p",{children:["No other agent uses ",ln(x.map(Vm)),"; it stays installed."," ",t.jsxs("a",{href:_e("plugins"),onClick:N=>{N.preventDefault(),a(!1),s(_e("plugins"))},children:["Remove ",x.length===1?"it":"them"," in Settings → Plugins"]}),"."]}):null]}):o?null:t.jsx("p",{className:"muted",children:"Reading what it would change…"})]}):null]})}const e2=["January","February","March","April","May","June","July","August","September","October","November","December"],Rf=e=>e?{day:String(e.day),month:String(e.month),year:e.year?String(e.year):""}:{day:"",month:"",year:""};function Pf(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 BZ=(e,n)=>(e??null)===(n??null)||!!e&&!!n&&e.day===n.day&&e.month===n.month&&(e.year??null)===(n.year??null),t2=(e,n=!0)=>`${e.day} ${e2[e.month-1]}${n&&e.year?` ${e.year}`:""}`;function Cj({label:e,hint:n,value:s,onChange:r}){const a=Pf(s)==="incomplete";return t.jsx(oe,{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"}),e2.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 WZ=8e3;function HZ(e){return e.kind==="policy"&&e.state==="open"&&String(e.payload.plugin??"")==="memory"&&e.ruleKind==="person"}function KZ(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} ${t2(r,!1)}`:null}function l1({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 VZ(){var k,j;const e=me(()=>T.people(),[],6e4),n=me(()=>T.proposals(),[],6e4),[s,r]=d.useState(null),[a,i]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(null),m=async(x,w)=>{f(x),u(null);try{return await w(),e.reload(),n.reload(),!0}catch(N){return u(N instanceof he?N.message:String(N)),!1}finally{f(null)}},p=(((k=n.data)==null?void 0:k.open)??[]).filter(HZ),v=((j=e.data)==null?void 0:j.people)??[],g=x=>[x.relationship,x.birthday?`born ${t2(x.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(st,{flush:!0,children:t.jsx(dt,{children:p.map(x=>{var w;return t.jsx(ot,{lead:t.jsx(l1,{name:String(((w=x.payload.matcher)==null?void 0:w.person)??"?"),small:!0}),title:String(x.payload.action??""),sub:t.jsx("span",{className:"person-from",children:x.why}),side:t.jsxs("span",{className:"person-side",children:[t.jsx(E,{variant:"ghost",size:"sm",disabled:h!==null,onClick:()=>void m(`discard:${x.id}`,()=>T.discardProposal(x.id,"Not a person")),children:"Not a person"}),t.jsx(E,{size:"sm",disabled:h!==null,onClick:()=>void m(`keep:${x.id}`,()=>T.keepProposal(x.id)),children:"Keep"})]})},x.id)})})}),p.length>1?t.jsx(re,{align:"end",children:t.jsxs(E,{variant:"accent",size:"sm",disabled:h!==null,onClick:()=>void m("keep-all",()=>T.keepAllProposals(p.map(x=>x.id))),children:["Keep all (",p.length,")"]})}):null]}):null,t.jsxs(pe,{title:"People",aside:"every agent knows who they are",panel:!0,flush:!0,actions:t.jsx(E,{variant:"accent",size:"sm",onClick:()=>r("new"),children:"Add a person"}),children:[e.data?v.length===0?t.jsx(be,{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(dt,{children:v.map(x=>{const w=KZ(x);return t.jsx(ot,{label:`${x.name}: edit`,onClick:()=>r(x),lead:t.jsx(l1,{name:x.name}),title:x.name,sub:g(x),side:t.jsxs("span",{className:"person-side",children:[w?t.jsx(Se,{tone:x.next&&x.next.inDays<=7?"accent":void 0,children:w}):null,x.reminders?t.jsx("span",{className:"person-bell",title:"Reminders on","aria-label":"Reminders on",children:t.jsx(ie,{name:"bell",size:14})}):null]})},x.id)})}):t.jsx(be,{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(GZ,{person:s==="new"?null:s,onClose:()=>r(null),onSaved:()=>{r(null),e.reload()},onForget:x=>{r(null),i(x)}}):null,a?t.jsx(Je,{title:`Forget ${a.name}?`,onClose:()=>i(null),foot:t.jsxs(re,{children:[t.jsx(pt,{}),t.jsx(E,{variant:"ghost",onClick:()=>i(null),children:"Cancel"}),t.jsx(E,{variant:"danger",disabled:h!==null,onClick:()=>{const x=a;m(`forget:${x.id}`,()=>T.forgetPerson(x.id)).then(w=>{i(null),w&&o({id:Date.now(),person:x})})},children:"Forget"})]}),children:t.jsxs("p",{children:["Every agent stops knowing who ",a.name," is",a.reminders!==null?", and the reminders for their dates are removed":"",". Notes that mention them stay in Notes."]})}):null,l?t.jsx(Cu,{title:`Forgot ${l.person.name}.`,duration:WZ,onUndo:()=>{const x=l.person;m(`restore:${x.id}`,()=>T.restorePerson(x.id))},onGone:()=>o(null)},l.id):null]})}function GZ({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,f]=d.useState(Rf(e==null?void 0:e.birthday)),[m,p]=d.useState(Rf(e==null?void 0:e.anniversary)),[v,g]=d.useState((e==null?void 0:e.notes)??""),[k,j]=d.useState((e==null?void 0:e.reminders)===!0),[x,w]=d.useState(!1),[N,y]=d.useState(null),b=Pf(h),S=Pf(m),C=b==="incomplete"||S==="incomplete",A=b!==null&&b!=="incomplete"||S!==null&&S!=="incomplete",$=async()=>{if(!C){w(!0),y(null);try{const I=P=>P.trim()===""?null:P.trim();await T.savePerson({...e?{id:e.id}:{},name:a.trim(),relationship:I(l),addressAs:I(c),birthday:b,anniversary:S,notes:I(v),reminders:A&&k}),s()}catch(I){y(I instanceof he?I.message:String(I))}finally{w(!1)}}};return t.jsx(Je,{title:e?e.name:"Add a person",onClose:n,foot:t.jsxs(re,{children:[e?t.jsx(E,{variant:"danger-ghost",disabled:x,onClick:()=>r(e),children:"Forget…"}):null,t.jsx(pt,{}),t.jsx(E,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:x||a.trim()===""||C,onClick:()=>void $(),children:x?"Saving…":"Save"})]}),children:t.jsxs(ue,{gap:"lg",children:[t.jsxs(Ms,{children:[t.jsx(oe,{label:"Name",children:t.jsx("input",{value:a,maxLength:80,placeholder:"Marion",autoFocus:!e,onChange:I=>i(I.target.value)})}),t.jsx(oe,{label:"Who they are to you",children:t.jsx("input",{value:l,maxLength:60,placeholder:"wife, brother, accountant…",onChange:I=>o(I.target.value)})})]}),t.jsx(oe,{label:"How to address them",hint:"What agents call them when they write to you about them, or to them for you.",children:t.jsx("input",{value:c,maxLength:80,placeholder:a.trim()||"Mum, Dr Lee…",onChange:I=>u(I.target.value)})}),t.jsx(Cj,{label:"Birthday",hint:"The year is optional.",value:h,onChange:f}),t.jsx(Cj,{label:"Anniversary",hint:"A wedding, the day you met: the year is optional.",value:m,onChange:p}),t.jsx(oe,{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:v,onChange:I=>g(I.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(Fo,{checked:A&&k,disabled:!A,onChange:j,label:"Remind me of their dates"})]}),N?t.jsx(Q,{tone:"critical",children:N}):null]})})}const YZ=["fact","observation","todo"];function n2({embedded:e,agents:n,timezone:s,agentId:r,initialTab:a="people"}){const{data:i,error:l,reload:o}=me(()=>T.memory(r),[r],3e4),[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(null),[v,g]=d.useState(a),k=S=>{var C;return S==="shared"?"Everyone":((C=n.find(A=>A.id===S))==null?void 0:C.name)??S},j=async S=>{p(null);try{await S,o()}catch(C){p(C instanceof he?C.message:String(C))}},x={nameOf:k,timezone:s,onChangePreference:S=>u({key:S.key,scope:S.scope}),onForgetPreference:S=>void j(T.forgetPreference({key:S.key,scope:S.scope})),onEditNote:S=>f(S),onForgetNote:S=>void j(T.forgetNote(S.id))},w=r?k(r):"",N=r&&i?{preferences:i.preferences.filter(S=>S.scope===r),notes:i.notes.filter(S=>S.scope===r)}:null,y=r&&i?{preferences:i.preferences.filter(S=>S.scope==="shared"),notes:i.notes.filter(S=>S.scope==="shared")}:null,b=t.jsx(E,{variant:"accent",size:"sm",onClick:()=>u({key:"",scope:r??"shared"}),children:"Add a preference"});return t.jsxs(Ns,{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(ae,{message:l??m}),N&&y?t.jsxs(ue,{gap:"lg",children:[t.jsx(pe,{title:"Preferences",aside:`what you told ${w} alone`,actions:b,panel:!0,flush:!0,children:t.jsx(Tg,{preferences:N.preferences,empty:`Nothing stated to ${w} alone yet.`,...x})}),t.jsx(pe,{title:"Notes",aside:`what ${w} wrote down for itself`,panel:!0,flush:!0,children:t.jsx(Ig,{notes:N.notes,empty:`${w} has kept no private notes yet.`,...x})}),t.jsx(Gt,{summary:`Shared with every agent, which ${w} also reads · ${y.preferences.length} preferences, ${y.notes.length} notes`,children:t.jsxs(ue,{gap:"lg",children:[t.jsx(pe,{title:"Shared preferences",panel:!0,flush:!0,children:t.jsx(Tg,{preferences:y.preferences,empty:"No shared preferences.",...x})}),t.jsx(pe,{title:"Shared notes",panel:!0,flush:!0,children:t.jsx(Ig,{notes:y.notes,empty:"No shared notes.",...x})})]})})]}):t.jsxs(ue,{gap:"lg",children:[t.jsx(_o,{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(Zi,{href:`${_e("memory")}?tab=${S}`,active:v===S,...A?{count:A}:{},onClick:$=>{$.preventDefault(),g(S)},children:C},S))}),v==="people"?t.jsx(VZ,{}):null,v==="preferences"?t.jsx(pe,{title:"Preferences",aside:"what you said you want, one current value each",actions:b,panel:!0,flush:!0,children:i?t.jsx(Tg,{preferences:i.preferences,empty:'Nothing stated yet. Tell any agent "from now on…" or add one here.',...x}):t.jsx(be,{children:"Loading…"})}):null,v==="notes"?t.jsx(pe,{title:"Notes",aside:"what an agent wrote down, with who wrote it",panel:!0,flush:!0,children:i?t.jsx(Ig,{notes:i.notes,empty:"No notes yet. An agent writes one when you state something durable about your life.",...x}):t.jsx(be,{children:"Loading…"})}):null]}),c?t.jsx(qZ,{agents:n,existing:(i==null?void 0:i.preferences)??[],initial:c,onClose:()=>u(null),onSave:async S=>{await j((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(QZ,{note:h,agents:n,onClose:()=>f(null),onSave:S=>j(T.updateNote(h.id,S)).then(()=>f(null))}):null]})}function Tg({preferences:e,empty:n,nameOf:s,onChangePreference:r,onForgetPreference:a}){return e.length===0?t.jsx(be,{children:n}):t.jsxs(Zr,{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(s2,{scope:i.scope,name:s(i.scope)})}),t.jsxs("td",{className:"num muted",title:i.updatedAt??"",children:[i.updatedAt?Ye(i.updatedAt,Date.now()):"",i.revision>1?` · rev ${i.revision}`:""]}),t.jsx("td",{className:"num",children:t.jsxs(re,{align:"end",children:[t.jsx(E,{size:"sm",onClick:()=>r(i),title:"Store a new value for this key",children:"Change"}),t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>a(i),children:"Forget"})]})})]},`${i.scope}:${i.key}`))})]})}function Ig({notes:e,empty:n,nameOf:s,timezone:r,onEditNote:a,onForgetNote:i}){return e.length===0?t.jsx(be,{children:n}):t.jsxs(Zr,{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(Se,{tone:l.kind==="todo"?"warning":l.kind==="fact"?"good":void 0,children:l.kind})}),t.jsx("td",{children:t.jsx(s2,{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?Ye(l.createdAt,Date.now()):"",l.expiresAt?t.jsxs("span",{className:"memory-expires",children:[" · until ",Er(new Date(l.expiresAt),r,{year:!0,compact:!0})]}):null]}),t.jsx("td",{className:"num",children:t.jsxs(re,{align:"end",children:[t.jsx(E,{size:"sm",onClick:()=>a(l),children:"Edit"}),t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>i(l),children:"Forget"})]})})]},l.id))})]})}function s2({scope:e,name:n}){return t.jsx(Se,{tone:e==="shared"?"accent":void 0,title:e==="shared"?"Every agent reads this":`Only ${n} reads this`,children:n})}function r2({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 qZ({agents:e,existing:n,initial:s,onClose:r,onSave:a}){const i=n.find(x=>x.key===s.key&&x.scope===s.scope),[l,o]=d.useState(s.key),[c,u]=d.useState((i==null?void 0:i.value)??""),[h,f]=d.useState(s.scope),[m,p]=d.useState(!1),v=l.trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),g=n.find(x=>x.key===v&&x.scope===h),k=!i||v!==i.key||c.trim()!==i.value||h!==i.scope,j=v!==""&&c.trim()!==""&&k;return t.jsx(Je,{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(oe,{label:"Key",hint:v&&v!==l?`Stored as ${v}`:"Short and stable, like reporting_currency or tone.",children:t.jsx("input",{value:l,autoFocus:s.key==="",onChange:x=>o(x.target.value),placeholder:"reporting_currency"})}),t.jsx(oe,{label:"Value",children:t.jsx("textarea",{rows:3,value:c,maxLength:2e3,autoFocus:s.key!=="",onChange:x=>u(x.target.value),placeholder:"EUR"})}),t.jsx(oe,{label:"Who should know",hint:"Shared reaches every agent. Private stays with one.",children:t.jsx(r2,{value:h,agents:e,onChange:f})}),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(re,{align:"end",children:[t.jsx(E,{onClick:r,children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:!j||m,onClick:()=>{p(!0),a({key:v,value:c.trim(),scope:h}).finally(()=>p(!1))},children:i?"Save change":"Save"})]})]})})}function QZ({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,f]=d.useState(!1),m=a.trim()!==e.content||l!==e.scope||c!==e.kind;return t.jsx(Je,{title:"A note",onClose:s,children:t.jsxs(ue,{children:[t.jsx(oe,{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:v=>i(v.target.value)})}),t.jsxs(Ms,{children:[t.jsx(oe,{label:"Kind",children:t.jsx("select",{value:c,onChange:v=>u(v.target.value),children:YZ.map(v=>t.jsx("option",{value:v,children:v},v))})}),t.jsx(oe,{label:"Who sees it",children:t.jsx(r2,{value:l,agents:n,onChange:o})})]}),e.createdByAgent?t.jsxs("p",{className:"muted",children:["Written by ",((p=n.find(v=>v.id===e.createdByAgent))==null?void 0:p.name)??e.createdByAgent,e.createdAt?`, ${Ye(e.createdAt,Date.now())}`:"",". Editing keeps that record."]}):null,t.jsxs(re,{align:"end",children:[t.jsx(E,{onClick:s,children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:!m||a.trim()===""||h,onClick:()=>{f(!0);const v={};a.trim()!==e.content&&(v.content=a.trim()),l!==e.scope&&(v.scope=l),c!==e.kind&&(v.kind=c),r(v).finally(()=>f(!1))},children:"Save"})]})]})})}const Mf="host.exec",JZ={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 Xa({name:e,size:n}){const[s,r,a]=JZ[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 Ub({size:e}){return t.jsx("span",{className:"ui-app-icon","data-size":e,"aria-hidden":"true",children:t.jsx(Xa,{name:"bundle",size:e?22:18})})}const XZ={skill:"doc",script:"script",font:"font",image:"image",data:"doc",template:"doc",other:"doc"},ZZ={skill:"The skill",script:"Script",font:"Font",image:"Picture",data:"Data",template:"Template",other:"File"};function eee(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 a2({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:eee(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(Xa,{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(Xa,{name:XZ[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:Hr(r.file.size)})]},r.file.path))})}function tee(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 ${Mf}, and asks you first.`:n.run.length?`${s}It runs only when ${ci(n.run)} ${n.run.length>1?"run":"runs"} it with ${Mf}, 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 i2({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 he?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:[ZZ[e.kind]," · ",Hr(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(Xa,{name:"shield",size:14}),t.jsx("span",{children:tee(e,a)})]}):null,i!=null&&i.error?t.jsx(ae,{message:i.error}):e.kind==="font"?t.jsxs("div",{className:"skb-blank",children:[t.jsx(Xa,{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(Xa,{name:"doc",size:20}),t.jsxs("span",{children:["Not text, so there’s nothing to read here. ",Hr(e.size),"."]})]}):t.jsx(Bt,{label:e.path,children:o.text}):t.jsx("p",{className:"skills-note",children:"Reading the file…"})]})}function l2({children:e}){return t.jsx("div",{className:"skb-files",children:e})}function o2({children:e}){return t.jsxs("p",{className:"skb-promise",children:[t.jsx(Xa,{name:"shield",size:16}),t.jsx("span",{children:e})]})}const nee="Up to 20 MB and 500 files. Nothing in it runs when you upload it.";function see({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,f]=d.useState(null),m=d.useRef(null),p=k=>{if(!(!k||c)){if(f(null),/\.md$/i.test(k.name)){s(k);return}if(!/\.zip$/i.test(k.name)){o({kind:"notzip",filename:k.name});return}if(k.size>l9){o({kind:"big",filename:k.name,size:k.size});return}u(k.name),nn.uploadBundle(k).then(j=>r(j),j=>{u(null),j instanceof WR?o(j.refusal):f(j instanceof he?j.message:String(j))})}},v=l?g9(l):null;return t.jsxs(Je,{title:"Upload a skill",onClose:n,children:[t.jsx("input",{ref:m,type:"file",accept:".zip,.md,application/zip,text/markdown",hidden:!0,"data-testid":"skill-drop-file",onChange:k=>{var j;p((j=k.target.files)==null?void 0:j[0]),k.target.value=""}}),t.jsxs("div",{className:"skills-sheet skb-drop-sheet",children:[v?t.jsx(Q,{tone:"critical",title:v.title,role:"alert",children:t.jsxs("div",{className:"skb-refusal",children:[v.body,(g=v.items)!=null&&g.length?t.jsx("ul",{className:"skb-refused",children:v.items.map(k=>t.jsxs("li",{children:[t.jsx("span",{className:"mono",children:k.path})," ",k.rest]},k.path))}):null]})}):null,t.jsx(ae,{message:h}),t.jsxs("div",{className:"skb-drop","data-over":a?"true":void 0,"data-testid":"skill-drop",onDragOver:k=>{k.preventDefault(),i(!0)},onDragLeave:()=>i(!1),onDrop:k=>{var j;k.preventDefault(),i(!1),p((j=k.dataTransfer.files)==null?void 0:j[0])},children:[t.jsx("span",{className:"skb-drop-glyph",children:t.jsx(Xa,{name:"upload",size:24})}),t.jsx("span",{className:"skb-drop-title",children:c?`Reading “${c}”…`:a?"Drop to read it":v?"Drop another file here":"Drop a .zip or a .md here"}),t.jsx(E,{variant:v?void 0:"accent",disabled:c!==null,onClick:()=>{var k;return(k=m.current)==null?void 0:k.click()},children:v?"Choose another file":"Choose a file"}),t.jsx("span",{className:"skb-drop-limits",children:nee})]}),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 ree({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 aee({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([]),[f,m]=d.useState(!1),[p,v]=d.useState(!1),[g,k]=d.useState(null),j=n.filter(C=>C.canRunScripts).map(C=>C.name),x=e.files.find(C=>C.path===o)??e.files[0],w=C=>{nn.discardBundle(e.id).catch(()=>{}),C()},N=async()=>{v(!0),k(null);try{const{skill:C}=await nn.acceptBundle(e.id,{agents:u,mine:f});i(C)}catch(C){k(C instanceof he?C.message:String(C)),v(!1)}},y=l.some(C=>C.setup);return t.jsxs(Je,{size:"wide",title:t.jsxs("span",{className:"skills-sheet-title",children:[t.jsx(Ub,{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 · ",Hr(e.size)," unpacked · read, not saved yet"]})]})]}),onClose:()=>w(r),foot:t.jsxs(re,{children:[t.jsx(E,{variant:"ghost",onClick:()=>w(a),children:"Choose another file"}),t.jsx(pt,{}),t.jsx(E,{variant:"ghost",onClick:()=>w(r),children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:p,onClick:()=>void N(),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",y?" — setup scripts too.":"."]}):null,t.jsx(ae,{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(Vt,{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:[Hr(e.size)," unpacked · ",Hr(e.packed)," as a .zip"]})]}),t.jsxs(l2,{children:[t.jsx(a2,{files:e.files,selected:x.path,onSelect:c}),t.jsx(i2,{file:x,read:C=>nn.stagedFile(e.id,C),imageUrl:C=>nn.stagedImageUrl(e.id,C),reach:{run:[],held:!1,untrusted:!1},skillView:t.jsx(iee,{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(ree,{checked:u.includes(C.id),onChange:A=>h(A?[...u,C.id]:u.filter($=>$!==C.id)),lead:t.jsx(In,{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?j.length?`Only ${ci(j)} ${j.length>1?"have":"has"} a tool that runs scripts; the others read the text. You can change this later.`:"No agent has a tool that runs scripts, so they all read the text only. You can change this later.":"You can change this later. With nobody ticked it’s kept and does nothing."})]}),t.jsx("section",{className:"skills-sec",children:t.jsxs("label",{className:"plugins-check",children:[t.jsx("input",{type:"checkbox",checked:f,onChange:C=>m(C.target.checked)}),t.jsxs("span",{children:[t.jsx("span",{className:"plugins-check-title",children:"Mark as mine"}),t.jsx("span",{className:"plugins-check-hint",children:l.length?"I wrote it, or I’ve read it and its scripts and trust them. Otherwise agents read its text as outside text and its scripts can’t run.":"I wrote it, or I’ve read it and trust it. Otherwise agents read its text as outside text."})]})]})})]})]})}function iee({staged:e}){const[n,s]=d.useState(null);return d.useEffect(()=>{let r=!0;return nn.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(Bt,{label:"SKILL.md",children:n})]})}const lee=5e4,tl=e=>e instanceof he?e.message:String(e),oee=e=>n=>{n.stopPropagation(),e==null||e()};function cee({faces:e,navigate:n,command:s,openSkill:r,openFile:a}){const i=me(()=>nn.list(),[]),[l,o]=d.useState(r?{id:r,...a?{file:a}:{}}:null),[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(null),[v,g]=d.useState(null),k=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 j=y=>{var S;const b=(S=y.target.files)==null?void 0:S[0];y.target.value="",b&&x(b)},x=y=>{if(!/\.md$/i.test(y.name)){f(`“${y.name}” isn’t a .md file. A skill is one Markdown file.`);return}if(y.size>lee){f(`“${y.name}” is over 50 KB. A skill is a short text.`);return}const b=new FileReader;b.onload=()=>{f(null),u({kind:"upload",file:{name:y.name,size:y.size,...j9(y.name,String(b.result))}})},b.readAsText(y)},w=y=>{p(null),y!==void 0&&g(y),i.reload()};return t.jsxs(t.Fragment,{children:[t.jsx("input",{ref:k,type:"file",accept:".md,text/markdown",hidden:!0,"data-testid":"skill-file",onChange:j}),h?t.jsx(Q,{tone:"warning",action:t.jsx(E,{size:"sm",onClick:()=>{f(null),u({kind:"drop"})},children:"Pick another file"}),children:h}):null,t.jsx(ae,{message:m}),v?t.jsx(Q,{tone:"good",role:"status",children:v}):null,t.jsx(uee,{view:i,onOpen:y=>o({id:y.id}),onAct:(y,b)=>N(y,b)}),t.jsx(c2,{view:i.data,faces:e,open:l,setOpen:o,dialog:c,setDialog:u,navigate:n,onChanged:w,onFailed:p}),(c==null?void 0:c.kind)==="write"&&i.data?t.jsx(c1,{agents:i.data.agents,faces:e,onClose:()=>u(null),onSaved:y=>{u(null),w(`Saved “${y.title}”.`)}}):null,(c==null?void 0:c.kind)==="drop"?t.jsx(see,{onClose:()=>u(null),onMd:y=>{u(null),x(y)},onStaged:y=>u({kind:"zip",staged:y})}):null,(c==null?void 0:c.kind)==="zip"&&i.data?t.jsx(aee,{staged:c.staged,agents:i.data.agents,faces:e,onClose:()=>u(null),onBack:()=>u({kind:"drop"}),onAdded:y=>{u(null),w(`Added “${y.title}”.`),o({id:y.id})}}):null,(c==null?void 0:c.kind)==="upload"&&i.data?t.jsx(c1,{agents:i.data.agents,faces:e,upload:c.file,onClose:()=>u(null),onSaved:y=>{u(null),w(`Saved “${y.title}”.`)}}):null]});function N(y,b){g(null),b==="trust"?nn.trust(y.id).then(()=>w(),S=>p(tl(S))):b==="download"?KR(y.id):b==="plugin"?n(_e("plugins")):b==="edit"?(u(null),o({id:y.id,edit:!0})):u({kind:b,id:y.id})}}function uee({view:e,onOpen:n,onAct:s}){if(!e.data&&e.error)return t.jsx(be,{warm:!0,title:"Couldn’t load your skills",action:t.jsx(E,{variant:"accent",size:"sm",onClick:e.reload,children:"Try again"}),children:"buddi didn’t answer. Your skill files are untouched."});if(!e.data)return t.jsx(hee,{});const{skills:r,agents:a}=e.data;return r.length===0?t.jsx(be,{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(st,{flush:!0,children:sb.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(dt,{children:l.map(o=>t.jsx(dee,{row:o,agents:a,onOpen:n,onAct:s},o.id))})]},i.id):null})})}function dee({row:e,agents:n,onOpen:s,onAct:r}){var o,c,u;const a=e.untrusted?["trust","Mark as mine"]:f9(e)?["picker","Choose agents"]:null,i=h9(e,n),l=p9(e,n);return t.jsx(ot,{onClick:()=>s(e),label:`${e.title}: details`,lead:e.bundle?t.jsx(Ub,{}):t.jsx(Qn,{icon:"files"}),title:e.bundle?t.jsxs("span",{className:"skb-title",children:[e.title,t.jsx(fo,{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," · ",Fc(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:ib(e,n)}):null]}),side:t.jsxs("span",{className:"skills-side",children:[a?t.jsx(E,{size:"sm",onClick:oee(()=>r(e,a[0])),children:a[1]}):null,t.jsx(Jn,{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 ${rb(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 hee(){return t.jsx(st,{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(dt,{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 c2({view:e,faces:n,open:s,setOpen:r,dialog:a,setDialog:i,navigate:l,onChanged:o,onFailed:c}){if(!e)return null;const u=m=>e.skills.find(p=>p.id===m),h=s?u(s.id):void 0,f=a&&"id"in a?u(a.id):void 0;return t.jsxs(t.Fragment,{children:[h?t.jsx(fee,{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"&&f?t.jsx(mee,{row:f,agents:e.agents,faces:n,onCancel:()=>i(null),onSaved:()=>{i(null),o()}}):null,(a==null?void 0:a.kind)==="delete"&&f?t.jsx(gee,{row:f,agents:e.agents,onCancel:()=>i(null),onDeleted:m=>{i(null),r(null),o(m)}}):null]})}function u2({title:e,sub:n}){return t.jsxs("span",{className:"skills-sheet-title",children:[t.jsx(Qn,{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 Nc({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 o1({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(Xt,{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(wr,{className:"wb-md skills-md",text:n}):t.jsx(Bt,{label:e,children:s})]})}function fee({row:e,agents:n,faces:s,initialEdit:r,initialFile:a,onClose:i,onPicker:l,onDelete:o,onChanged:c,onFailed:u,navigate:h}){var G,X,K,J;const f=me(()=>nn.detail(e.id),[e.id,e.updatedAt,e.untrusted,(G=e.learned)==null?void 0:G.version]),[m,p]=d.useState(!!r&&e.editable),[v,g]=d.useState(null),[k,j]=d.useState(!1),[x,w]=d.useState(null),[N,y]=d.useState(r?"SKILL.md":a??"SKILL.md"),b=((X=f.data)==null?void 0:X.text)??"",S=GR(Fc(e,n)),C=x9(e,n),A=((K=e.from)==null?void 0:K.kind)==="plugin"?rb(e.from.plugin):null,$=q=>s.find(ce=>ce.id===q),I=e.bundle??null,P=((J=f.data)==null?void 0:J.bundle)??null,O=(I==null?void 0:I.scripts.length)??0,R=q=>{var ce;return((ce=n.find(xe=>xe.id===q))==null?void 0:ce.canRunScripts)===!0},D=YR(e,n).filter(R).map(q=>Zs(n,q)),U=async(q,ce)=>{j(!0),w(null);try{await q(),ce==null||ce(),c()}catch(xe){w(tl(xe)),u(tl(xe))}finally{j(!1)}},W=q=>{U(()=>nn.grant(e.id,{agents:lb(e).filter(ce=>ce!==q)}))},M=()=>{U(()=>nn.saveText(e.id,v??b),()=>{p(!1),g(null)})},L=()=>{y("SKILL.md"),p(!0)},_=(q,ce)=>{var xe,Me;if(I)return O?R(q)?t.jsxs("span",{className:"skb-can",children:["Can run its scripts with ",t.jsx("span",{className:"mono",children:Mf}),", asking each time"]}):"Reads the text only: it has no tool that runs scripts":"Uses the text and its files";if(((xe=e.learned)==null?void 0:xe.by)===q)return"Proposed it";if(((Me=e.from)==null?void 0:Me.kind)==="catalogue"&&e.from.agent===q)return"Came with it";if(ce==="home")return"In its own folder"},Y=t.jsx("textarea",{className:"skills-editor",value:v??b,onChange:q=>g(q.target.value),"aria-label":`Text of ${e.title}`,spellCheck:!1,autoFocus:!0}),B=I&&P?`Bundle · ${P.files.length} files · ${Hr(P.size)} · ${Fc(e,n)}`:I?`Bundle · ${I.files+1} files · ${Hr(I.size)} · ${Fc(e,n)}`:S,se=(P==null?void 0:P.files.find(q=>q.path===N))??(P==null?void 0:P.files[0]);return t.jsxs(Je,{size:"wide",title:I?t.jsxs("span",{className:"skills-sheet-title",children:[t.jsx(Ub,{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(u2,{title:e.title,sub:S}),onClose:i,foot:m?t.jsxs(re,{align:"end",children:[t.jsx(E,{variant:"ghost",disabled:k,onClick:()=>{p(!1),g(null)},children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:k||!f.data,onClick:M,children:I?"Save SKILL.md":"Save"})]}):t.jsxs(re,{children:[e.deletable&&!A?t.jsx(E,{variant:"danger-ghost",onClick:o,children:"Delete…"}):null,t.jsx(pt,{}),t.jsx(E,{onClick:()=>KR(e.id),children:I?"Download .zip":"Download"}),e.editable?t.jsx(E,{variant:e.untrusted?void 0:"accent",onClick:L,children:I?"Edit SKILL.md":"Edit text"}):null]}),children:[e.untrusted?t.jsxs(Q,{tone:"warning",action:t.jsx(E,{size:"sm",variant:"accent",disabled:k,onClick:()=>void U(()=>nn.trust(e.id)),children:"Mark as mine"}),children:[ib(e,n)," Mark it as yours once you’ve read it",O?" and its scripts":"","."]}):null,t.jsx(ae,{message:x}),t.jsxs("div",{className:"skills-sheet",children:[t.jsx(Nc,{title:"When it’s used",children:t.jsx("p",{className:"skills-desc",children:e.description})}),t.jsxs(Nc,{title:"Used by",aside:t.jsx(E,{size:"sm",onClick:l,children:"Change…"}),children:[O?t.jsx(o2,{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(dt,{children:t.jsx(ot,{lead:t.jsx(Qn,{icon:"agents"}),title:ab(e,n),sub:O?D.length?`Now, and any you add later. ${ci(D)} can run its scripts, asking each time.`:"Now, and any you add later. None of them can run its scripts.":"Now, and any you add later."})}):e.holders.length?t.jsx("div",{className:I?"skb-holders":void 0,children:t.jsx(dt,{children:e.holders.map(q=>{const ce=n.find(xe=>xe.id===q.agent);return t.jsx(ot,{lead:t.jsx(In,{id:q.agent,name:(ce==null?void 0:ce.name)??q.agent,size:"sm",face:$(q.agent)}),title:t.jsxs(t.Fragment,{children:[(ce==null?void 0:ce.name)??q.agent," ",t.jsxs("span",{className:"skills-handle",children:["@",(ce==null?void 0:ce.handle)??q.agent]})]}),sub:_(q.agent,q.how),side:q.how==="home"?void 0:t.jsx(E,{size:"sm",variant:"ghost",disabled:k,onClick:()=>W(q.agent),"aria-label":`Take away from ${(ce==null?void 0:ce.name)??q.agent}`,children:"Take away"})},q.agent)})})}):t.jsx("p",{className:"skills-note",children:"No agent uses it yet, so it does nothing. Choose who should."})]}),I?t.jsxs(Nc,{title:"Files",aside:P?t.jsxs("span",{className:"skills-note",children:[P.files.length," files · ",Hr(P.size)]}):void 0,children:[!f.data||!P||!se?f.error?t.jsx(ae,{message:f.error}):t.jsx(be,{children:"Reading the bundle…"}):t.jsxs(l2,{children:[t.jsx(a2,{files:P.files,selected:se.path,onSelect:m?null:y}),t.jsx(i2,{file:se,read:q=>nn.file(e.id,q),imageUrl:q=>nn.imageUrl(e.id,q),reach:{run:D,held:e.every||e.holders.length>0,untrusted:e.untrusted!==null},skillView:m?Y:t.jsx(o1,{file:_S(e),body:f.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(Nc,{title:"The text",children:[f.data?m?Y:t.jsx(o1,{file:_S(e),body:f.data.body,text:b}):f.error?t.jsx(ae,{message:f.error}):t.jsx(be,{children:"Reading the file…"}),m&&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:_e("plugins"),onClick:q=>{q.preventDefault(),h(_e("plugins"))},children:"Open Plugins"})]}):null]})]})]})}function Of({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 d2({label:e,value:n,onChange:s}){return t.jsxs("div",{className:"cat-search",children:[t.jsx(ie,{name:"search",size:16}),t.jsx(Fm,{label:e,value:n,placeholder:e,onChange:s})]})}function mee({row:e,agents:n,faces:s,onCancel:r,onSaved:a}){var y;const[i,l]=d.useState(e.every),[o,c]=d.useState(lb(e)),[u,h]=d.useState(""),[f,m]=d.useState(!1),[p,v]=d.useState(null),g=u.trim().toLowerCase(),k=n.filter(b=>!g||`${b.name} ${b.handle}`.toLowerCase().includes(g)),j=(b,S)=>c(S?[...o,b]:o.filter(C=>C!==b)),x=((y=e.bundle)==null?void 0:y.scripts.length)??0,w=x?[["Can run its scripts",k.filter(b=>b.canRunScripts)],["Text only",k.filter(b=>!b.canRunScripts)]]:[[null,k]],N=async()=>{m(!0),v(null);try{await nn.grant(e.id,i?{every:!0,agents:[]}:{agents:o}),a()}catch(b){v(tl(b))}finally{m(!1)}};return t.jsx(Rt,{title:`Who uses “${e.title}”?`,onClose:r,foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:r,children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:f,onClick:()=>void N(),children:"Save"})]}),children:t.jsxs("div",{className:"skills-pick",children:[x?t.jsxs(o2,{children:[x," script",x>1?"s":""," come",x>1?"":"s"," with it. Only an agent with a tool that runs commands can run them, and it asks you each time",e.untrusted?", once you’ve marked it as yours":"","."]}):null,t.jsx(d2,{label:"Find an agent",value:u,onChange:h}),t.jsx(ae,{message:p}),t.jsxs("div",{className:"skills-pick-list",children:[g||!e.shareable?null:t.jsx(Of,{checked:i,onChange:l,lead:t.jsx(Qn,{icon:"agents"}),title:"Every agent",sub:x?"Now and later. Scripts still ask each time.":"Now, and any you add later."}),w.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.shadowedBy??[]).includes(C.id),I=A||$||!C.writable;return t.jsx(Of,{checked:!$&&(i||A||o.includes(C.id)),disabled:i||I,onChange:P=>j(C.id,P),lead:t.jsx(In,{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":$?"Has its own skill of this name, and uses that":C.writable?x&&C.canRunScripts?t.jsxs("span",{className:"skb-can",children:["With ",t.jsx("span",{className:"mono",children:Mf})]}):void 0:"Ships with buddi, so its file doesn’t change"},C.id)})]},b??"all"):null),k.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 pee({agent:e,view:n,onCancel:s,onSaved:r}){const a=x=>VR(x,e.id),[i,l]=d.useState(n.skills.filter(a).map(x=>x.id)),[o,c]=d.useState(""),[u,h]=d.useState(!1),[f,m]=d.useState(null),p=o.trim().toLowerCase(),v=x=>!p||`${x.title} ${x.description}`.toLowerCase().includes(p),g=x=>x.every||x.home===e.id||!e.writable,k=async()=>{h(!0),m(null);try{for(const x of n.skills){if(g(x))continue;const w=i.includes(x.id);if(w===a(x))continue;const N=lb(x);await nn.grant(x.id,{agents:w?[...N,e.id]:N.filter(y=>y!==e.id)})}r()}catch(x){m(tl(x))}finally{h(!1)}},j=n.skills.some(v);return t.jsx(Rt,{title:`Skills ${e.name} uses`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:u||!e.writable,onClick:()=>void k(),children:"Save"})]}),children:t.jsxs("div",{className:"skills-pick",children:[t.jsx(d2,{label:"Find a skill",value:o,onChange:c}),t.jsx(ae,{message:f}),e.writable?null:t.jsxs("p",{className:"skills-note",children:[e.name," ships with buddi, so its file doesn’t change. Ask Agent Father to make it yours first."]}),t.jsxs("div",{className:"skills-pick-list",children:[sb.map(x=>{const w=n.skills.filter(N=>N.group===x.id&&v(N));return w.length?t.jsxs("div",{className:"skills-pick-group",role:"group","aria-label":x.title,children:[t.jsx("div",{className:"skills-pick-group-title",children:x.title}),w.map(N=>t.jsx(Of,{checked:i.includes(N.id),disabled:g(N),onChange:y=>l(y?[...i,N.id]:i.filter(b=>b!==N.id)),title:N.title,sub:N.every?a(N)?"Every agent uses it":ab(N,n.agents):N.home===e.id?"Its own skill, in its folder":N.description},N.id))]},x.id):null}),j?null:t.jsxs("p",{className:"skills-note skills-pick-none",children:["No skill matches “",o.trim(),"”."]})]})]})})}function c1({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)??""),[f,m]=d.useState([]),[p,v]=d.useState(!1),[g,k]=d.useState(!1),[j,x]=d.useState(null),w=i.trim()!==""&&o.trim()!==""&&u.trim()!=="",N=s?`${Math.max(1,Math.round(s.size/1024))} KB`:"",y=async()=>{k(!0),x(null);try{const{skill:b}=await nn.create({title:i.trim(),description:o.trim(),body:u,agents:f,...s?{upload:{filename:s.name,mine:p}}:{}});a(b)}catch(b){x(tl(b))}finally{k(!1)}};return t.jsxs(Je,{size:"wide",title:s?t.jsx(u2,{title:s.name,sub:`${N} · read, not saved yet`}):"Write a skill",onClose:r,foot:t.jsxs(re,{align:"end",children:[t.jsx(E,{variant:"ghost",onClick:r,children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:!w||g,onClick:()=>void y(),children:"Save skill"})]}),children:[t.jsx(ae,{message:j}),t.jsxs("div",{className:"skills-sheet",children:[t.jsxs("section",{className:"skills-sec skills-form",children:[t.jsx(oe,{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(oe,{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(oe,{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.
129
+ 2. The three biggest charges.
130
+ 3. Anything odd.`})})]}),t.jsxs(Nc,{title:"Who uses it",children:[t.jsx("div",{className:"skills-who",children:e.map(b=>t.jsx(Of,{checked:f.includes(b.id),disabled:!b.writable,onChange:S=>m(S?[...f,b.id]:f.filter(C=>C!==b.id)),lead:t.jsx(In,{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=>v(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 gee({row:e,agents:n,onCancel:s,onDeleted:r}){const a=me(()=>nn.detail(e.id),[e.id]),[i,l]=d.useState(!1),[o,c]=d.useState(null),u=d.useMemo(()=>a.data?v9(e,a.data.onDelete,n):null,[a.data,e,n]),h=async()=>{l(!0),c(null);try{const f=await nn.remove(e.id);r(`Deleted “${e.title}”.${f.movedTo?" The file is in the trash folder.":f.versionsKept?" Its earlier versions are kept.":""}`)}catch(f){c(tl(f)),l(!1)}};return t.jsxs(Rt,{title:`Delete “${e.title}”?`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx(E,{variant:"danger",disabled:i||!a.data,onClick:()=>void h(),children:"Delete"})]}),children:[t.jsx(ae,{message:o??a.error}),t.jsx("p",{className:"skills-dialog-text",children:u??"Checking who uses it…"})]})}function xee(e){var n;return((n=sb.find(s=>s.id===e.group))==null?void 0:n.title)??""}function vee({agentId:e,agentName:n,faces:s=[],navigate:r}){const a=me(()=>nn.list(),[e]),[i,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(!1),[f,m]=d.useState(null),[p,v]=d.useState(null),g=y=>{m(null),v(y??null),a.reload()},k=y=>{nn.trust(y.id).then(()=>g(),b=>m(b instanceof Error?b.message:String(b)))};if(!a.data)return a.error?t.jsx(be,{warm:!0,title:"Couldn’t load the skills",action:t.jsx(E,{variant:"accent",size:"sm",onClick:a.reload,children:"Try again"}),children:"buddi didn’t answer. The skill files are untouched."}):t.jsx(be,{children:"Loading…"});const j=a.data,x=j.agents.find(y=>y.id===e)??{id:e,handle:e,name:n,writable:!1},w=j.skills.filter(y=>VR(y,e)),N=HR();return t.jsxs(t.Fragment,{children:[t.jsx(ae,{message:f}),p?t.jsx(Q,{tone:"good",role:"status",children:p}):null,t.jsx(st,{flush:!0,title:"Skills",actions:t.jsxs(t.Fragment,{children:[t.jsxs("a",{className:"skills-all",href:N,onClick:y=>{y.preventDefault(),r(N)},children:["All skills",t.jsx(ie,{name:"chevron-right",size:12})]}),t.jsx(E,{size:"sm",onClick:()=>h(!0),children:"Choose skills…"})]}),children:w.length?t.jsx("div",{className:"skills-group",children:t.jsx(dt,{children:w.map(y=>t.jsx(ot,{onClick:()=>l({id:y.id}),label:`${y.title}: details`,lead:t.jsx(Qn,{icon:"files"}),title:y.title,sub:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"skills-line",children:y.description}),t.jsxs("span",{className:"skills-line skills-meta",children:[xee(y)," · ",y.every?"every agent uses it":Fc(y,j.agents,!0)]}),y.untrusted?t.jsx("span",{className:"skills-status","data-tone":"warning",children:ib(y,j.agents)}):null]}),side:t.jsx("span",{className:"skills-side",children:y.untrusted?t.jsx(E,{size:"sm",onClick:b=>{b.stopPropagation(),k(y)},children:"Mark as mine"}):t.jsx("span",{className:"skills-chevron","aria-hidden":"true",children:t.jsx(ie,{name:"chevron-right",size:14})})})},y.id))})}):t.jsxs(be,{children:[n," uses no skills yet. Choose some, or write one on the Skills page."]})}),t.jsx(c2,{view:j,faces:s,open:i,setOpen:l,dialog:o,setDialog:c,navigate:r,onChanged:g,onFailed:m}),u?t.jsx(pee,{agent:x,view:j,onCancel:()=>h(!1),onSaved:()=>{h(!1),g()}}):null]})}function h2({timezone:e,embedded:n,agentId:s}){const{data:r,error:a,reload:i}=me(()=>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(f){c(f instanceof Error?f.message:String(f))}};return t.jsxs(Ns,{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(ae,{message:a??o}),t.jsx(st,{flush:!0,children:r?l.length===0?t.jsx(os,{icon:"bell",title:"No reminders",children:"Ask any agent to remind you of something, and it shows up here."}):t.jsxs(Zr,{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:[mt(h.dueAt,e),t.jsx("div",{className:"sub",children:Ye(h.dueAt)})]}),t.jsx("td",{className:"mono",children:h.agentId}),t.jsxs("td",{children:[h.text,h.context?t.jsx(Gt,{summary:"context",children:t.jsx(Bt,{children:ls(h.context)})}):null]}),t.jsxs("td",{children:[t.jsx(Xu,{state:h.state}),h.cancelReason?t.jsx("div",{className:"sub",children:h.cancelReason}):null]}),t.jsx("td",{children:h.state==="pending"?t.jsx(E,{size:"sm",variant:"danger",onClick:()=>u(h.id),children:"Cancel"}):null})]},h.id))})]}):t.jsx(be,{children:"Loading…"})})]})}const jee=/(flux|klein|schnell|qwen[-_]?image|image)/i;function f2(e){return e.kind==="image"||e.kind===void 0&&jee.test(e.id)}function wee(e){const n=((e==null?void 0:e.models)??[]).filter(s=>!f2(s));return[...n.filter(s=>s.loaded),...n.filter(s=>!s.loaded)].map(s=>s.id)}function Ej(e){return wee(e)[0]}function Bb(e){return(e==null?void 0:e.detectedContextWindowSource)==="mlxh"}function yee(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 m2(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 p2="an image model; pick it in the Image plugin, not here";function Wb({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,f]=d.useState(!1),[m,p]=d.useState(""),[v,g]=d.useState(!1),k=d.useRef(0),j=async S=>{if(!e)return;const C=++k.current;f(!0),p("");try{const A=await T.accountModels(e,S);if(C===k.current){u(A);const $=(l==null?void 0:l(A))??null;$&&(o==null||o($))}}catch(A){C===k.current&&p(A instanceof Error?A.message:"Could not load models. Custom entry is still available.")}finally{C===k.current&&f(!1)}};if(d.useEffect(()=>(u(null),g(!1),p(""),j(!1),()=>{k.current++}),[e]),!e)return t.jsxs(t.Fragment,{children:[t.jsx(oe,{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 x=(c==null?void 0:c.models)??[],w=c&&l?l(c):null,N=!!s&&!x.some(S=>S.id===s),y=[c&&!x.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 ${wT(c.fetchedAt)}`:""].filter(Boolean).join(" · "):"";return t.jsxs(t.Fragment,{children:[t.jsx(oe,{label:n,children:t.jsxs("select",{value:v?"__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"}),N&&t.jsxs("option",{value:s,children:[s," (current",c?", not listed":"",")"]}),x.map(S=>t.jsxs("option",{value:S.id,children:[S.name===S.id?S.id:`${S.name} — ${S.id}`,S.id===w?" (suggested)":S.isDefault?" (provider default)":"",S.image?` — ${p2}`:""]},S.id)),t.jsx("option",{value:"__buddi_custom__",children:"Custom model…"})]})}),t.jsx(E,{disabled:a||h,onClick:()=>void j(!0),children:h?"Loading models…":"Refresh models"}),v&&t.jsx(oe,{label:`Custom ${n.toLowerCase()}`,children:t.jsx("input",{required:!0,maxLength:150,value:s,disabled:a,onChange:S=>r(S.target.value)})}),m&&t.jsx("p",{role:"alert",className:"ui-toolbar-note critical",children:m}),y.length>0&&t.jsx("p",{className:"ui-toolbar-note",children:y.join(" ")}),b&&t.jsx("p",{className:"ui-toolbar-note muted","data-testid":"model-list-source",children:b})]})}function bee(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 kee(e,n){return[...e].sort().join(",")===[...n].sort().join(",")}const Nee="This agent will not remember anything between conversations.";function See({view:e,chosen:n,onChange:s,disabled:r}){var y;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}),f=b=>{i(b),u(new Set)},m=d.useId(),p=new Set(n),v=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=>v.has(A))){o({plugin:b,names:C});return}s(n.filter(A=>!C.includes(A)))}},k=b=>{s([...n,...b.filter(S=>!p.has(S))])},j=a.trim().toLowerCase(),x=(b,S)=>j===""||b.toLowerCase().includes(j)||S.toLowerCase().includes(j),w=e.groups.map(b=>({group:b,tools:b.tools.filter(S=>x(S.name,S.description))})).filter(b=>b.tools.length>0),N=(((y=e.suggested)==null?void 0:y.tools)??[]).filter(b=>!p.has(b.name));return t.jsxs("div",{className:"tool-picker",children:[e.suggested&&N.length>0?t.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":`${m}-suggested`,children:[t.jsx("div",{className:"tool-picker-head",children:t.jsx("span",{id:`${m}-suggested`,className:"tool-picker-plugin",children:e.suggested.label})}),t.jsx("ul",{className:"ui-list tool-picker-list","aria-label":e.suggested.label,children:N.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(E,{size:"sm",disabled:r,"aria-label":`Add ${b.name}`,onClick:()=>k([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=>f(b.target.value)})]}),w.length===0?t.jsxs(be,{children:["No installed tool matches “",a.trim(),"”."]}):null,w.map(({group:b,tools:S})=>{const C=b.tools.filter(R=>R.grantable).map(R=>R.name),A=b.tools.filter(R=>p.has(R.name)).length,$=!!b.glob&&A===b.tools.length,I=`${m}-${b.plugin}`,P=`${m}-${b.plugin}-list`,O=j!==""?!c.has(b.plugin):c.has(b.plugin);return t.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":I,"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(Cee,{}),t.jsx("span",{id:I,className:"tool-picker-plugin",children:b.plugin}),t.jsx("span",{className:"muted",children:$?`all ${b.tools.length}`:`${A} of ${b.tools.length} granted`})]}),t.jsx(E,{size:"sm",variant:"ghost","aria-label":`All ${b.plugin} tools`,disabled:r||C.every(R=>p.has(R)),onClick:()=>k(C),children:"all"}),t.jsx(E,{size:"sm",variant:"ghost","aria-label":`No ${b.plugin} tools`,disabled:r||!C.some(R=>p.has(R)),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:Nee}),t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx(E,{size:"sm",onClick:()=>o(null),children:"Keep"}),t.jsx(E,{size:"sm",variant:"danger",onClick:()=>{s(n.filter(R=>!l.names.includes(R))),o(null)},children:"Remove"})]})}):null,t.jsx("ul",{id:P,className:"ui-list tool-picker-list",hidden:!O,children:S.map(R=>{const D=`${m}-${R.name}`;return t.jsxs("li",{className:"ui-list-row",children:[t.jsx("input",{type:"checkbox",id:D,checked:p.has(R.name),disabled:r||!R.grantable,onChange:U=>U.target.checked?k([R.name]):g(b.plugin,[R.name])}),t.jsxs("label",{htmlFor:D,className:"ui-list-main",children:[t.jsxs("span",{className:"ui-list-title",children:[t.jsx("span",{className:"mono",children:R.name}),R.core?t.jsx(Se,{tone:"accent",children:"core"}):null,R.gated?t.jsx(Se,{tone:"warning",children:"asks you"}):null]}),t.jsx("span",{className:"ui-list-sub",children:R.grantable?R.description:`${R.description} Granted only by editing the file by hand.`})]})]},R.name)})})]},b.plugin)})]})}function Cee(){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 Vs={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."},_a=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function g2(e){let n;try{n=JSON.parse(e.trim())}catch{throw new Error(Vs.json)}if(!_a(n))throw new Error(Vs.json);let s,r=n;if("mcpServers"in n){const u=n.mcpServers;if(!_a(u))throw new Error(Vs.empty);const h=Object.keys(u);if(h.length===0)throw new Error(Vs.empty);if(h.length>1)throw new Error(`It names ${h.length} servers (${h.join(", ")}). Paste one at a time.`);s=h[0];const f=u[s];if(!_a(f))throw new Error(Vs.url);r=f}if("command"in r)throw new Error(Vs.command);if(typeof r.type=="string"&&r.type.toLowerCase()==="sse")throw new Error(Vs.sse);const a=typeof r.url=="string"?r.url.trim():"";if(a==="")throw new Error(Vs.url);const i=_a(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,f=/^(Bearer|Basic)\s+/i.exec(h.trim()),m=f?`${f[1].charAt(0).toUpperCase()}${f[1].slice(1).toLowerCase()} `:"";let p=f?h.trim().slice(f[0].length).trim():h.trim();/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$/i.test(p)&&(c=!0,p=""),o={name:u.trim(),prefix:m,value:p}}return{url:a,...s?{name:s}:{},...o?{header:o}:{},dropped:i.filter(u=>u!==l).map(([u])=>u),placeholder:c}}const Bc={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 x2(e){return/TOKEN|KEY|SECRET|PASSWORD|PASSWD|CREDENTIAL|AUTH/i.test(e)}const v2=/^[A-Za-z_][A-Za-z0-9_]*$/;function Eee(e){return/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$|^your[_-]/i.test(e.trim())}function j2(e,n){const s=Eee(n);return{name:e,value:s?"":n,secret:x2(e),placeholder:s}}function w2(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!==`
131
+ `&&(s+=o)}else s+=l;continue}if(l==="\\"){const o=e[i+1];if(o===void 0)continue;if(i+=1,o===`
132
+ `||o==="\r"&&e[i+1]===`
133
+ `){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(Bc.quote);return r&&n.push(s),n}function Aee(e){const n=w2(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 f=h.indexOf("="),m=f>0?h.slice(0,f).trim():"";if(!v2.test(m))throw new Error(Bc.env);r.push(j2(m,h.slice(f+1)))},u=[];for(;s<n.length;s+=1){const h=n[s];if(h==="--"){o=n.slice(s+1);break}const[f,m]=h.startsWith("--")&&h.includes("=")?[h.slice(0,h.indexOf("=")),h.slice(h.indexOf("=")+1)]:[h,void 0];if(f==="-e"||f==="--env"){if(m!==void 0){c(m);continue}let p=!1;for(;s+1<n.length&&/^[A-Za-z_][A-Za-z0-9_]*=/.test(n[s+1]);)c(n[++s]),p=!0;if(!p)throw new Error(Bc.env);continue}if(f==="-s"||f==="--scope"){m===void 0&&(s+=1);continue}if(f==="-t"||f==="--transport"){i=(m??n[++s]??"stdio").toLowerCase();continue}if(f==="-H"||f==="--header"){const p=m??n[++s];p&&a.push(p);continue}if(!(f.startsWith("-")&&l===void 0)){if(l===void 0){l=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(Vs.url);const f={};for(const m of a){const p=m.indexOf(":");p>0&&(f[m.slice(0,p).trim()]=m.slice(p+1).trim())}return{kind:"remote",config:g2(JSON.stringify({mcpServers:{[l??"server"]:{type:i,url:h,headers:f}}}))}}if(!l||o.length===0)throw new Error(Bc.claude);return{kind:"program",program:{name:l,command:o[0],args:o.slice(1),env:r}}}function $ee(e){const n=e.trim();if(/^claude\s+mcp\s+add\b/.test(n))return Aee(n);let s;try{s=JSON.parse(n)}catch{throw new Error(Vs.json)}if(!_a(s))throw new Error(Vs.json);let r,a=s;if("mcpServers"in s){const c=s.mcpServers;if(!_a(c))throw new Error(Vs.empty);const u=Object.keys(c);u.length===1&&_a(c[u[0]])&&(r=u[0],a=c[r])}if(!("command"in a))return{kind:"remote",config:g2(n)};const i=typeof a.command=="string"?a.command.trim():"";if(i==="")throw new Error(Bc.command);const l=Array.isArray(a.args)?a.args.map(c=>String(c)):[],o=_a(a.env)?Object.entries(a.env).filter(([c])=>v2.test(c)).map(([c,u])=>j2(c,String(u??""))):[];return{kind:"program",program:{...r?{name:r}:{},command:i,args:l,env:o}}}function Hb({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(re,{valign:"end",children:[t.jsx(oe,{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(E,{onClick:()=>void i(),children:r?"Copied":"Copy"})]})}function y2(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 Tee="It can delete or destroy something, so it asks you every time and is never remembered.";function Iee(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 b2="buddi-connections",Ree="/connections/callback",Pee="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.",k2="Services and programs your team can use, and the tools each one brings.",Kb=(e,n,s)=>`${e} ${e===1?n:s}`;function u1(e,n){return e.transport==="stdio"?void 0:n.find(s=>Gb(s.url,e.url))}function Vb({connection:e,card:n,size:s}){return n?t.jsx(Qn,{letter:n.name.slice(0,1).toUpperCase(),size:s}):t.jsx(Qn,{icon:(e==null?void 0:e.transport)==="stdio"?"terminal":"globe",size:s})}function N2({connection:e}){const n=y2(e);return t.jsx(Se,{tone:n.tone,dot:n.dot,children:n.label})}const Rg=e=>n=>{n.stopPropagation(),e()},Sh=[{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"}],S2="buddi.connections.add-way";function Mee(){try{const e=window.localStorage.getItem(S2);return Sh.some(n=>n.value===e)?e:"address"}catch{return"address"}}function Oee({embedded:e,timezone:n,connection:s}={}){const r=me(()=>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,f]=d.useState(null),m=r.data,p=b=>{var S;return((S=m==null?void 0:m.agents.find(C=>C.id===b))==null?void 0:S.name)??b},v=n??Intl.DateTimeFormat().resolvedOptions().timeZone,g=(m==null?void 0:m.connections)??[],k=(m==null?void 0:m.catalog)??[],j=k.filter(b=>!g.some(S=>S.transport!=="stdio"&&Gb(b.url,S.url))),x=l?g.find(b=>b.id===l):void 0,w=c?g.find(b=>b.id===c):void 0,N=h?g.find(b=>b.id===h):void 0,y=b=>{o(null),i(b)};return t.jsxs(Ns,{embedded:e,title:"Connections",lede:k2,children:[t.jsxs(ue,{gap:"lg",children:[t.jsxs("p",{className:"plugins-quiet connections-quiet",children:[t.jsx(ie,{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:_e("plugins"),children:"Plugins"})]})]}),!m&&!r.error?t.jsx(be,{children:"Reading your connections…"}):null,t.jsx(ae,{message:r.error}),m&&!m.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,m?t.jsx(st,{flush:!0,title:"Your connections",tool:g.length>0?Kb(g.length,"connection","connections"):void 0,children:g.length===0?t.jsx(be,{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(dt,{children:g.map(b=>t.jsx(Dee,{connection:b,card:u1(b,k),twin:b.slug!==null&&g.some(S=>S.id!==b.id&&S.name===b.name),onOpen:()=>o(b.id),onFlow:y},b.id))})})}):null,m&&j.length>0?t.jsx(st,{title:"Connect a service",children:t.jsx("div",{className:"connections-tiles",children:j.map(b=>t.jsxs("div",{className:"connections-tile",children:[t.jsx(Vb,{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(E,{size:"sm",onClick:()=>y({step:"address",card:b}),"aria-label":`Connect ${b.name}`,children:"Connect"})]},b.id))})}):null,m?t.jsx(Uee,{onFlow:b=>y({step:b})}):null]}),x?t.jsx(Fee,{connection:x,card:u1(x,k),agentName:p,timezone:v,onClose:()=>o(null),onFlow:y,onDisconnect:()=>u(x.id),onHolders:()=>f(x.id)}):null,N&&m?t.jsx(_ee,{connection:N,agents:m.agents,onCancel:()=>f(null),onDone:()=>{f(null),r.reload()}},N.id):null,w?t.jsx(zee,{connection:w,agentName:p,onCancel:()=>u(null),onDone:()=>{u(null),o(null),r.reload()}},w.id):null,a&&m?t.jsx(Bee,{start:a,agents:m.agents,catalog:m.catalog,tokens:m.tokens??m.vault,onClose:()=>{i(null),r.reload()}}):null]})}function Dee({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":Kb(e.toolCount,"tool","tools");return t.jsx(ot,{onClick:r,label:`${l}: details`,lead:t.jsx(Vb,{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(E,{size:"sm",variant:"accent",onClick:Rg(()=>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(E,{size:"sm",onClick:Rg(()=>a({step:"consent",connection:e,keepGrants:!0})),children:"Sign in"})}):e.state==="needs-review"?t.jsx("span",{className:"connections-act",children:t.jsx(E,{size:"sm",onClick:Rg(()=>a({step:"review",connection:e,keepGrants:!0})),children:"Review"})}):null,t.jsx(N2,{connection:e}),t.jsx(ie,{name:"chevron-right",size:14})]})})}const Lee={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 Fee({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}),f=()=>i({step:"review",connection:e,keepGrants:!0}),m=()=>i({step:e.signedIn?"review":"consent",connection:e});return t.jsxs(Je,{title:t.jsxs("span",{className:"plugins-sheet-title",children:[t.jsx(Vb,{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(N2,{connection:e})]})]})]}),onClose:a,foot:t.jsxs(re,{children:[t.jsx(E,{variant:"danger-ghost",onClick:o,children:"Disconnect…"}),t.jsx(pt,{}),u?t.jsx(E,{onClick:()=>i({step:"program",connection:e,keepGrants:!0}),children:"Change"}):null,e.authKind!=="none"&&!c?t.jsx(E,{variant:e.state==="needs-reconnect"?"accent":void 0,onClick:h,children:"Reconnect"}):null,c?t.jsx(E,{variant:"accent",onClick:m,children:"Finish"}):t.jsx(E,{variant:e.state==="needs-review"?"accent":void 0,onClick:f,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(E,{size:"sm",variant:"accent",onClick:h,children:"Sign in again"}):void 0,children:"Its sign-in ran out or was refused. Until you reconnect, each of its tools answers with one sentence instead of running."}):null,e.state==="needs-review"?t.jsxs(Q,{tone:"warning",action:t.jsx(E,{size:"sm",variant:"accent",onClick:f,children:"Review it"}),children:["It changed its tools since you reviewed them. The new and changed ones wait until you review it again",e.heldTools?` (${e.heldTools} of the ones you kept ${e.heldTools===1?"waits":"wait"})`:"","; the others keep working."]}):null,e.state==="unreachable"&&e.unreachableSince?t.jsx(Q,{tone:"critical",children:u?`It stopped answering at ${mt(e.unreachableSince,r)}; the next call starts it again.`:`Unreachable since ${mt(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(Vt,{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:Lee[e.authKind]}],{label:"Tools",value:c?"Not reviewed yet":`${Kb(e.toolCount,"tool","tools")}${e.reviewedAt?` · reviewed ${Ye(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(E,{size:"sm",onClick:l,"aria-label":"Change who holds it",children:e.agents.length===0?"Give them":"Change"})]})}]]})}),e.stderr&&e.stderr.length>0?t.jsx(pe,{title:"What the program last said",children:t.jsx(Bt,{label:"Its last lines on stderr",children:e.stderr.join(`
134
+ `)})}):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(E,{size:"sm",onClick:()=>i({step:"address",card:n}),children:"Add another account"})]}):null]})}function _ee({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,v)=>i(g=>{const k=new Set(g);return v?k.add(p):k.delete(p),k}),f=a.size===e.agents.length&&e.agents.every(p=>a.has(p)),m=async()=>{o(!0),u(null);try{const p=await T.grantConnection(e.id,[...a],!0);p.failed.length>0?u(p.failed.map(v=>`${v.agent}: ${v.message}`).join("; ")):r()}catch(p){u(Nr(p))}finally{o(!1)}};return t.jsxs(Rt,{title:`Who holds ${e.name}`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",disabled:l,onClick:s,children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:l||f,onClick:()=>void m(),children:"Save"})]}),children:[t.jsx("p",{className:"plugins-dialog-text",children:"Each agent you tick can use its tools; untick one to take them away. Approvals still ask as before."}),t.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Agents",children:n.map(p=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:a.has(p.id),onChange:v=>h(p.id,v.target.checked)}),t.jsxs("span",{children:[p.name,p.frontDesk?" (front desk)":""]})]},p.id))}),t.jsx(ae,{message:c})]})}function zee({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(Nr(h))}finally{i(!1)}};return t.jsxs(Rt,{title:`Disconnect ${e.name}?`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",disabled:a,onClick:s,children:"Cancel"}),t.jsx(E,{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(ae,{message:l})]})}function Uee({onFlow:e}){const[n,s]=d.useState(Mee),r=Sh.find(i=>i.value===n)??Sh[0],a=i=>{s(i);try{window.localStorage.setItem(S2,i)}catch{}};return t.jsx(st,{title:"Add your own",actions:t.jsx(Xt,{label:"How to add it",options:Sh.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(E,{variant:"accent",onClick:()=>e(n),children:r.button})]})})}function Bee({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,f]=d.useState("unknown"),[m,p]=d.useState(null),[v,g]=d.useState(null),k=(m==null?void 0:m.url)??(c==null?void 0:c.url),j=e.card??s.find(N=>k!==void 0&&Gb(N.url,k)),x=(c==null?void 0:c.name)??(j==null?void 0:j.name)??(m==null?void 0:m.name)??"the service",w=l==="paste"?"Paste a config":l==="address"?"Connect a service":l==="program"?c?`Change ${c.name}`:"A program on this computer":l==="consent"?`Sign in to ${x}`:l==="review"?`What ${x} brings`:"Who gets these tools";return t.jsxs(Je,{title:w,onClose:a,size:"wide",children:[l==="paste"?t.jsx(Wee,{onRead:N=>{N.kind==="program"?(g(N.program),o("program")):(p(N.config),o("address"))}}):null,l==="address"?t.jsx(Hee,{card:j,pasted:m,onDone:(N,y)=>{u(N),y==="none"?o("review"):(f(y),o("consent"))}}):null,l==="program"?t.jsx(Xee,{connection:c,pasted:v,tokens:r,onDone:N=>{var y;g(null),u(N),e.keepGrants&&!((y=N.program)!=null&&y.changedSinceReview)&&N.state!=="pending-review"?a():o("review")}}):null,l==="consent"&&c?t.jsx(Gee,{connection:c,signIn:h,card:j,pasted:m==null?void 0:m.header,placeholder:(m==null?void 0:m.placeholder)??!1,tokens:r,pollMs:i,onSignedIn:N=>{p(null),u(N),e.keepGrants?a():o("review")}}):null,l==="review"&&c?t.jsx(Zee,{connection:c,onKept:N=>{u(N),e.keepGrants?a():o("grant")}}):null,l==="grant"&&c?t.jsx(ete,{connection:c,agents:n,onDone:a}):null]})}function Gb(e,n){const s=r=>r.trim().replace(/\/+$/,"").toLowerCase();return s(e)===s(n)}function Nr(e){return e instanceof Error?e.message:String(e)}function Wee({onRead:e}){const[n,s]=d.useState(""),[r,a]=d.useState(null),i=()=>{try{const l=$ee(n);s(""),a(null),e(l)}catch(l){a(Nr(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(oe,{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(ae,{message:r}),t.jsx(re,{align:"end",children:t.jsx(E,{type:"submit",variant:"accent",disabled:n.trim()==="",children:"Read it"})})]})}function Hee({card:e,pasted:n,onDone:s}){var m,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 v=await T.addConnection(r.trim(),(e==null?void 0:e.name)??(n==null?void 0:n.name));s(v.connection,v.signIn)}catch(v){c(Nr(v))}finally{l(!1)}},h=((m=e==null?void 0:e.auth)==null?void 0:m.recommended)==="token",f=((p=e==null?void 0:e.auth)==null?void 0:p.recommended)==="device"&&e.auth.device!==void 0;return t.jsxs("form",{className:"ui-stack",onSubmit:v=>{v.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(oe,{label:"Address",hint:"An https:// address. A server you start with npx, uvx or a local command is “A program on this computer” instead.",children:t.jsx("input",{required:!0,autoFocus:!e&&!n,spellCheck:!1,value:r,placeholder:"https://",onChange:v=>a(v.target.value)})}),e&&!e.verified?t.jsxs("p",{className:"ui-card-meta",children:["This address is the one ",e.name," published; buddi has not checked it since."]}):null,f?t.jsxs("p",{className:"ui-card-meta",children:[e.name," signs in with a code you type on its site. The next screen shows it."]}):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(ae,{message:o}),t.jsx(re,{align:"end",children:t.jsx(E,{type:"submit",variant:"accent",disabled:i||r.trim()==="",children:i?"Opening…":"Continue"})})]})}const Kee={device:"Device",oauth:"Sign in",token:"Token",client:"Client id"};function Vee(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 Gee({connection:e,signIn:n,card:s,pasted:r,placeholder:a,tokens:i,pollMs:l,onSignedIn:o}){var L,_;const[c,u]=d.useState(n),h=(L=s==null?void 0:s.auth)!=null&&L.device?s.auth.recommended==="device"?"first":"offered":"none",f=Vee(c,i,h),m=r!==void 0||h!=="first"&&(e.authKind==="token"||((_=s==null?void 0:s.auth)==null?void 0:_.recommended)==="token"),[p,v]=d.useState(()=>m&&f.includes("token")?"token":f[0]),g=f.includes(p)?p:f[0],[k,j]=d.useState(Pee),[x,w]=d.useState(""),[N,y]=d.useState(null),[b,S]=d.useState(!1),[C,A]=d.useState(null),[$,I]=d.useState(!1),[P,O]=d.useState(null),R=`${location.origin}${Ree}`,D=d.useRef(o);D.current=o,d.useEffect(()=>{if(!$)return;let Y=!1;const B=async()=>{if(!Y){Y=!0;try{D.current(await T.connection(e.id))}catch(J){A(Nr(J))}}},se=typeof BroadcastChannel=="function"?new BroadcastChannel(b2):null;se&&(se.onmessage=J=>{var q;((q=J.data)==null?void 0:q.id)===e.id&&B()});let G;const X=Date.now(),K=async()=>{if(!Y){try{const J=await T.connection(e.id);if((!e.signedIn||e.authKind==="token")&&J.signedIn&&J.authKind==="oauth"){B();return}}catch{}if(Date.now()-X>10*6e4){I(!1),A("The sign-in did not come back within ten minutes. Start it again.");return}G=window.setTimeout(()=>void K(),l)}};return G=window.setTimeout(()=>void K(),l),()=>{Y=!0,se==null||se.close(),window.clearTimeout(G)}},[$,e,l]);const U=async Y=>{var B;S(!0),A(null);try{const{authorizeUrl:se}=await T.connectionConsent(e.id,Y);y(se)}catch(se){se instanceof he&&((B=se.detail)==null?void 0:B.code)==="client-id"?(j(se.message),u("manual"),v("client")):A(Nr(se))}finally{S(!1)}};d.useEffect(()=>{g!=="oauth"||N!==null||U()},[g]);const W=Y=>{const B=window.open(Y,"_blank");B?(B.opener=null,O(null)):O(Y),I(!0)},M=Y=>{v(Y),y(null),A(null),I(!1),O(null)};return t.jsxs("div",{className:"ui-stack",children:[f.length>1?t.jsx(Xt,{label:"How to sign in",options:f.map(Y=>({value:Y,label:Kee[Y]})),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(be,{children:["Getting ",e.name,"’s sign-in page…"]}):null]}):null,g==="client"?t.jsxs(t.Fragment,{children:[t.jsx(Q,{tone:"warning",children:k}),t.jsx(oe,{label:"Client id",children:t.jsx("input",{required:!0,spellCheck:!1,value:x,onChange:Y=>{w(Y.target.value),y(null),I(!1)}})}),t.jsxs("p",{className:"ui-card-meta",children:["Its redirect address: ",t.jsx("span",{className:"mono",children:R})]})]}):null,g==="token"?t.jsx(Qee,{connection:e,card:s,pasted:r,placeholder:a,onSignedIn:o}):null,g==="device"?t.jsx(qee,{connection:e,service:(s==null?void 0:s.name)??e.name,pollMs:l,onSignedIn:o}):null,(g==="oauth"||g==="client")&&$?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(ae,{message:C}):null,g==="oauth"?t.jsx(re,{align:"end",children:t.jsx(E,{variant:"accent",onClick:()=>{N&&W(N)},disabled:N===null,children:$?"Open it again":`Sign in to ${e.name}`})}):null,g==="client"?t.jsx(re,{align:"end",children:N===null?t.jsx(E,{variant:"accent",onClick:()=>void U(x.trim()),disabled:b||x.trim()==="",children:b?"Checking…":"Continue"}):t.jsx(E,{variant:"accent",onClick:()=>W(N),children:$?"Open it again":`Open ${e.name}’s sign-in page`})}):null]})}function Yee(e){try{const n=new URL(e);return`${n.host}${n.pathname==="/"?"":n.pathname.replace(/\/$/,"")}`}catch{return e}}function qee({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,f]=d.useState(null),[m,p]=d.useState(!1),v=d.useRef(r);v.current=r,d.useEffect(()=>{let j=!1,x;i(null),o(null),f(null),p(!1);const w=async()=>{var N,y;if(!j){try{const b=await T.connection(e.id);if(j)return;if(((N=b.device)==null?void 0:N.state)==="done"){v.current(b);return}if(((y=b.device)==null?void 0:y.state)==="failed"){o(b.device.reason??"The sign-in did not finish. Start again.");return}}catch{}x=window.setTimeout(()=>void w(),s)}};return(async()=>{try{const N=await T.connectionDevice(e.id);if(j)return;i({userCode:N.userCode,verificationUri:N.verificationUri}),x=window.setTimeout(()=>void w(),s)}catch(N){j||o(Nr(N))}})(),()=>{j=!0,window.clearTimeout(x)}},[e.id,s,c]);const g=j=>{const x=window.open(j,"_blank");p(!0),x?(x.opener=null,f(null)):f(j)},k=a?Yee(a.verificationUri):"";return t.jsxs(t.Fragment,{children:[t.jsxs("p",{children:[a?`Open ${k}, 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(be,{children:["Asking ",n," for a code…"]}):null,a&&l===null?t.jsxs(t.Fragment,{children:[t.jsx(Hb,{code:a.userCode,label:`Your code for ${n}`,large:!0}),m?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 ",k]})}):null,t.jsx(re,{align:"end",children:t.jsxs(E,{variant:"accent",onClick:()=>g(a.verificationUri),children:["Open ",k]})})]}):null,l!==null?t.jsxs(t.Fragment,{children:[t.jsx(ae,{message:l}),t.jsx(re,{align:"end",children:t.jsx(E,{variant:"accent",onClick:()=>u(j=>j+1),children:"Start again"})})]}):null]})}function Qee({connection:e,card:n,pasted:s,placeholder:r,onSignedIn:a}){var j,x;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 ")),[f,m]=d.useState(!1),[p,v]=d.useState(null),g=async()=>{m(!0),v(null);try{const w=await T.connectionToken(e.id,{token:i.trim(),header:o.trim(),prefix:u});l(""),a(w.connection)}catch(w){v(Nr(w))}finally{m(!1)}},k=(j=n==null?void 0:n.auth)==null?void 0:j.tokenPage;return t.jsxs("form",{className:"ui-stack",onSubmit:w=>{w.preventDefault(),g()},children:[t.jsxs("p",{children:[k?`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."]}),k?t.jsx("p",{children:t.jsxs("a",{href:k,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(oe,{label:"Token",hint:(x=n==null?void 0:n.auth)==null?void 0:x.tokenHint,children:t.jsx("input",{type:"password",required:!0,autoFocus:!(s!=null&&s.value),autoComplete:"off",spellCheck:!1,value:i,onChange:w=>l(w.target.value)})}),t.jsxs(Ms,{columns:2,dense:!0,children:[t.jsx(oe,{label:"Header",hint:"Most services want Authorization.",children:t.jsx("input",{required:!0,spellCheck:!1,value:o,onChange:w=>c(w.target.value)})}),t.jsx(oe,{label:"Before the token",hint:"Usually “Bearer ”, with its space. Empty for none.",children:t.jsx("input",{spellCheck:!1,value:u,onChange:w=>h(w.target.value)})})]}),t.jsx(ae,{message:p}),t.jsx(re,{align:"end",children:t.jsx(E,{type:"submit",variant:"accent",disabled:f||i.trim()===""||o.trim()==="",children:f?"Trying it…":"Try it and keep it"})})]})}function Jee(e){return e!==""&&/^[A-Za-z0-9_@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function Xee({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)??""),[f,m]=d.useState(()=>((a==null?void 0:a.args)??(n==null?void 0:n.args)??[]).map(R=>({key:l(),value:R}))),[p,v]=d.useState(()=>a?a.env.map(R=>({key:l(),name:R.name,value:R.value??"",secret:R.secret,kept:R.secret})):((n==null?void 0:n.env)??[]).map(R=>({key:l(),name:R.name,value:R.value,secret:R.secret,kept:!1}))),[g,k]=d.useState(!1),[j,x]=d.useState(null),w=/\s/.test(u.trim())?w2(u.trim()):[u.trim()],N=w[0]??"",y=[...w.slice(1),...f.map(R=>R.value)],b=[N,...y].filter((R,D)=>D>0||R!==""),S=()=>{w.length<2||(h(N),m(R=>[...w.slice(1).map(D=>({key:l(),value:D})),...R]))},C=b.map(Jee).join(" "),A=p.filter(R=>R.secret&&R.value===""&&!R.kept).map(R=>R.name||"a variable"),$=((n==null?void 0:n.env)??[]).filter(R=>R.placeholder).map(R=>R.name),I=(R,D)=>m(U=>U.map(W=>W.key===R?{...W,value:D}:W)),P=(R,D)=>v(U=>U.map(W=>W.key===R?{...W,...D}:W)),O=async()=>{k(!0),x(null);const R={name:o.trim(),command:N,args:y,env:p.filter(D=>D.name.trim()!=="").map(D=>({name:D.name.trim(),value:D.value,secret:D.secret}))};try{r(e?await T.updateProgram(e.id,R):(await T.addProgram(R)).connection),v(D=>D.map(U=>U.secret?{...U,value:""}:U))}catch(D){x(Nr(D))}finally{k(!1)}};return t.jsxs("form",{className:"ui-stack",onSubmit:R=>{R.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(Ms,{columns:2,children:[t.jsx(oe,{label:"Name",children:t.jsx("input",{required:!0,autoFocus:!n&&!e,maxLength:80,spellCheck:!1,value:o,onChange:R=>c(R.target.value)})}),t.jsx(oe,{label:"Command",hint:"The program that starts the server: npx, uvx, node, or a full path. A whole line is split into it and its arguments.",children:t.jsx("input",{required:!0,spellCheck:!1,autoComplete:"off",className:"mono",value:u,placeholder:"npx",onChange:R=>h(R.target.value),onBlur:S})})]}),t.jsx(oe,{label:"Arguments",group:!0,hint:"One per row, exactly as the server's docs give them. No shell: quotes and $VARIABLES are passed as they are.",children:t.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[f.map((R,D)=>t.jsxs("div",{className:"connections-row",children:[t.jsx("input",{"aria-label":`Argument ${D+1}`,className:"mono",spellCheck:!1,autoComplete:"off",value:R.value,onChange:U=>I(R.key,U.target.value)}),t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>m(U=>U.filter(W=>W.key!==R.key)),"aria-label":`Remove argument ${D+1}`,children:"Remove"})]},R.key)),t.jsx(re,{children:t.jsx(E,{size:"sm",onClick:()=>m(R=>[...R,{key:l(),value:""}]),children:"Add an argument"})})]})}),t.jsx(oe,{label:"Environment variables",group:!0,hint:"A secret is kept in buddi's vault and handed to the program only when it starts. Names with TOKEN, KEY, SECRET or PASSWORD start as secrets.",children:t.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[p.map((R,D)=>t.jsxs("div",{className:"connections-row","data-kind":"env",children:[t.jsx("input",{"aria-label":`Variable ${D+1} name`,className:"mono",spellCheck:!1,autoComplete:"off",placeholder:"NAME",value:R.name,onChange:U=>{const W=U.target.value;P(R.key,R.value===""&&!R.kept?{name:W,secret:x2(W)}:{name:W})}}),t.jsx("input",{"aria-label":`Variable ${D+1} value`,type:R.secret?"password":"text",spellCheck:!1,autoComplete:"off",placeholder:R.kept&&R.value===""?"Kept. Type to replace it.":"value",value:R.value,onChange:U=>P(R.key,{value:U.target.value})}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:R.secret,onChange:U=>P(R.key,{secret:U.target.checked,kept:U.target.checked&&R.kept})}),t.jsx("span",{children:"Secret"})]}),t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>v(U=>U.filter(W=>W.key!==R.key)),"aria-label":`Remove variable ${D+1}`,children:"Remove"})]},R.key)),t.jsx(re,{children:t.jsx(E,{size:"sm",onClick:()=>v(R=>[...R,{key:l(),name:"",value:"",secret:!1,kept:!1}]),children:"Add a variable"})})]})}),$.length>0?t.jsxs(Q,{tone:"accent",children:["Your config had a placeholder for ",$.join(", "),". Type the value itself."]}):null,!s&&p.some(R=>R.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(Bt,{label:"The command line",children:C||"…"})]}),t.jsx(ae,{message:j}),t.jsx(re,{align:"end",children:t.jsx(E,{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 Zee({connection:e,onKept:n}){const s=me(()=>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)??"",f=async()=>{var p;if(u){l(!0),c(null);try{n(await T.saveConnectionReview(e.id,{hash:u.hash,...u.slugEditable?{slug:h}:{}}))}catch(v){v instanceof he&&((p=v.detail)==null?void 0:p.code)==="changed"&&s.reload(),c(Nr(v))}finally{l(!1)}}};if(!u)return s.error?t.jsx(ae,{message:s.error}):e.transport==="stdio"?t.jsxs(be,{children:["Starting ",e.name,"… The first start can take a minute or two while it downloads."]}):t.jsxs(be,{children:["Reading what ",e.name," offers…"]});const m=u.tools.filter(p=>p.problem===null).length;return t.jsxs("div",{className:"ui-stack",children:[t.jsxs("p",{children:["Read what ",e.name," brings before it brings it. Each tool gets a buddi name and a tier from what the server says it does; anything that changes something asks you first, on the same approval card as every other tool."]}),u.program?t.jsx(Q,{tone:"warning",title:"This runs on this computer as you",children:t.jsxs(ue,{gap:"sm",children:[t.jsx(Bt,{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(oe,{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(be,{children:[e.name," lists no tools."]}):t.jsx("div",{className:"ui-list","aria-label":"Tools",children:u.tools.map(p=>{const v=Iee(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(Se,{tone:"muted",children:"Cannot be used"}):t.jsx(Se,{tone:v.tone,children:v.label}),p.change==="added"?t.jsx(fo,{children:"New"}):p.change==="changed"?t.jsx(fo,{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?Tee:"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(ae,{message:o}),t.jsx(re,{align:"end",children:t.jsx(E,{variant:"accent",onClick:()=>void f(),disabled:i||u.slugEditable&&h.trim()==="",children:m===1?"Keep this tool":`Keep these ${m} tools`})})]})}function ete({connection:e,agents:n,onDone:s}){var k;const r=n.find(j=>j.frontDesk)??n[0],[a,i]=d.useState(()=>new Set(r?[r.id]:[])),o=(((k=me(()=>T.connectionTools(e.id),[e.id]).data)==null?void 0:k.tools)??[]).filter(j=>j.tier==="gated"),[c,u]=d.useState(()=>new Set),[h,f]=d.useState(!1),[m,p]=d.useState(null),v=(j,x)=>{i(w=>{const N=new Set(w);return x?N.add(j):N.delete(j),N})},g=async()=>{f(!0),p(null);try{const j=await T.grantConnection(e.id,[...a]);if(j.failed.length>0){p(j.failed.map(x=>`${x.agent}: ${x.message}`).join(" "));return}for(const x of j.granted)for(const w of c)await T.setRememberedApproval(x,w,!0);s()}catch(j){p(Nr(j))}finally{f(!1)}};return t.jsxs("div",{className:"ui-stack",children:[t.jsxs("p",{children:[r?`Give these tools to ${r.name}?`:"Which agents get these tools?"," Each one you tick gets ",t.jsx("span",{className:"mono",children:e.grant})," on its tools line."]}),t.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Agents",children:n.map(j=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:a.has(j.id),onChange:x=>v(j.id,x.target.checked)}),t.jsxs("span",{children:[j.name,j.frontDesk?" (front desk)":""]})]},j.id))}),t.jsx("p",{className:"ui-card-meta",children:"No one is fine too: the connection waits here until you give it to someone."}),o.length>0?t.jsxs("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Remembered approval",children:[t.jsx("p",{children:"These ask you first. Tick one to remember your approval for the agents above, so it asks only once."}),o.map(j=>t.jsxs(ue,{gap:"sm",children:[t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",disabled:!j.rememberable,checked:c.has(j.tool),onChange:x=>u(w=>{const N=new Set(w);return x.target.checked?N.add(j.tool):N.delete(j.tool),N})}),t.jsx("span",{className:"mono",children:j.tool})]}),j.why?t.jsx("p",{className:"ui-card-meta",children:j.why}):null]},j.tool))]}):null,t.jsx(ae,{message:m}),t.jsxs(re,{align:"end",children:[t.jsx(E,{onClick:s,disabled:h,children:"Not now"}),t.jsx(E,{variant:"accent",onClick:()=>void g(),disabled:h||a.size===0,children:"Give them"})]})]})}const tte=(e,n,s)=>`${e} ${e===1?n:s}`;function nte(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 ste({agentId:e,agentName:n,readOnly:s,version:r,onSaved:a}){const[i,l]=d.useState({}),o=me(()=>T.connections().then(w=>(l({}),w)),[r]),[c,u]=d.useState(null),[h,f]=d.useState(null),m=_e("connections"),p=async(w,N)=>{u(w.id),f(null);try{const y=await T.setConnectionHolder(w.id,e,N);l(b=>({...b,[w.id]:y.held})),a==null||a()}catch(y){f(y instanceof Error?y.message:String(y))}finally{u(null)}},v=o.data,g=(v==null?void 0:v.connections)??[],k=w=>i[w.id]??w.agents.includes(e),j=v?v.agents.some(w=>w.id===e):!0,x=g.filter(k).length;return t.jsxs(pe,{title:"Connections",aside:v&&g.length>0?`holds ${x} of ${g.length} · saved as you change them`:void 0,panel:!0,children:[t.jsx(ae,{message:o.error??h}),v?g.length===0?t.jsxs("p",{className:"ui-card-meta",children:["Nothing is connected yet. ",t.jsx("a",{href:m,children:"Connect a service in Connections"})]}):j?t.jsxs(t.Fragment,{children:[s?t.jsx(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(w=>{const N=k(w),y=nte(w),b=w.transport==="stdio"?"on this computer":w.host,S=w.slug?tte(w.toolCount,"tool","tools"):"tools not reviewed",C=`holds-${e}-${w.id}`;return t.jsxs("li",{className:"ui-list-row",children:[t.jsx("input",{type:"checkbox",role:"switch",id:C,checked:N,"aria-checked":N,disabled:s||c!==null||y!==null&&!N,onChange:A=>void p(w,A.target.checked)}),t.jsxs("label",{htmlFor:C,className:"ui-list-main",children:[t.jsxs("span",{className:"ui-list-title",children:[w.name,y?t.jsxs(t.Fragment,{children:[" ",t.jsx(Se,{tone:"warning",children:y2(w).label})]}):null]}),t.jsx("span",{className:"ui-list-sub",children:`${b} · ${S}`}),y?t.jsxs("span",{className:"ui-list-sub",children:[y," ",t.jsx("a",{href:m,children:"Open Connections"})]}):null]})]},w.id)})})]}):t.jsxs("p",{className:"ui-card-meta",children:[n," makes and changes agents, so it holds no connections."]}):o.error?null:t.jsx(be,{children:"Loading the connections…"})]})}const rte=(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 C2(e){const n=await fetch(xi(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 ate({face:e,onPick:n,label:s=z.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,O5.map(o=>{const c={kind:"mascot",role:o},u=rte(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":z.assistant.mascot(o),disabled:a,onClick:()=>n(c),children:t.jsx("img",{src:xi(o),alt:""})},o)})]}),t.jsx("div",{className:"meet-face-row",children:L5.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 ite=["mirror","en","fr"],lte=[{value:"3h",label:"3 hours"},{value:"1d",label:"A day"},{value:"1w",label:"A week"},{value:"never",label:"Never"}],Pg=10,Mg=500,E2=[{id:"identity",label:"Identity"},{id:"brain",label:"Brain"},{id:"tools",label:"Tools"},{id:"team",label:"Team"}],d1=e=>{var n;return e==="access"?"tools":((n=E2.find(s=>s.id===e))==null?void 0:n.id)??"identity"};function ote({agentId:e,section:n,navigate:s}){var g,k,j;const{data:r,error:a,reload:i}=me(()=>T.agents(),[]),[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(d1(n));d.useEffect(()=>f(d1(n)),[n]);const m=x=>{f(x),s==null||s(Dt(e,"setup",x))},p=async x=>{o(null),u(null);try{const w=await x;u(w.changed.length===0?`No file change needed. ${w.note}.`:`Changed ${w.changed.join(", ")}. ${w.note}.`),i()}catch(w){o(w instanceof Error?w.message:String(w))}},v=r==null?void 0:r.agents.find(x=>x.id===e);return t.jsxs(ue,{gap:"lg",children:[t.jsx(_o,{level:"secondary",label:"Setup",children:E2.map(x=>t.jsx(Zi,{href:Dt(e,"setup",x.id),active:h===x.id,onClick:w=>{w.preventDefault(),m(x.id)},children:x.label},x.id))}),t.jsx(ae,{message:a??l}),c?t.jsx(Q,{tone:"good",role:"status",children:c}):null,r?v?t.jsx(cte,{agent:v,all:r.agents,engine:r.engines.find(x=>x.id===v.id),providers:r.providers,accounts:r.providerAccounts,shown:h,onShow:m,onRun:p,onSaved:i},`${v.id}:${(g=r.engines.find(x=>x.id===v.id))==null?void 0:g.model}:${(j=(k=r.providerAccounts)==null?void 0:k.bindings.find(x=>x.agentId===v.id))==null?void 0:j.accountId}`):t.jsx(be,{children:"This agent is not installed as a file."}):t.jsx(be,{children:"Loading…"})]})}function cte({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),f=(s==null?void 0:s.model)??e.model,[m,p]=d.useState(String((s==null?void 0:s.maxTurns)??e.maxTurns)),[v,g]=d.useState(null),k=b=>{o(T.setAgentEngine(e.id,b))},j=b=>{const S=r.find(C=>C.kind===b);k({provider:b,model:(S==null?void 0:S.defaultModel)??f})},x=(h==null?void 0:h.models.map(b=>b.id))??[],w=x.includes(f)?x:[f,...x],N=s?s.available:!0,y=(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:[N?null:t.jsxs(Q,{tone:"warning",children:["This agent cannot run right now."," ",t.jsx("a",{href:Dt(e.id,"setup","brain"),onClick:b=>{b.preventDefault(),l("brain")},children:"See Brain."})]}),t.jsx(ute,{agent:e,onSaved:c})]})}),t.jsx("div",{hidden:i!=="brain",children:t.jsxs(ue,{gap:"lg",children:[N?null:t.jsxs(Q,{tone:"warning",children:["This agent cannot run right now: ",y,"."]}),t.jsx(pe,{panel:!0,children:t.jsxs(ue,{divided:!0,children:[t.jsxs(pe,{title:"Runs on",children:[a?t.jsx(xte,{agentId:e.id,accounts:a,onRun:o}):t.jsxs(Ms,{children:[t.jsx(oe,{label:"Provider",children:t.jsx("select",{value:u,onChange:b=>j(b.target.value),children:r.map(b=>t.jsxs("option",{value:b.kind,children:[b.kind,b.usable?"":" (no credential)"]},b.kind))})}),t.jsxs(oe,{label:"Model",children:[t.jsx("input",{list:`models-${e.id}`,defaultValue:f,onBlur:b=>{b.target.value.trim()!==""&&b.target.value.trim()!==f&&k({model:b.target.value.trim()})}}),t.jsx("datalist",{id:`models-${e.id}`,children:w.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(pe,{title:"Behaviour",aside:"saved as you change them",children:t.jsxs(Ms,{children:[t.jsx(oe,{label:"Steps per reply",hint:`${s!=null&&s.maxTurnsIsDefault?`Default ${s.defaultMaxTurns??40}. `:""}Each tool call is a step; a reply that uses them all stops and offers Continue.`,after:v?t.jsx("span",{className:"critical save-error",role:"alert",children:v}):null,children:t.jsx("input",{type:"number",min:Pg,max:Mg,value:m,onChange:b=>{p(b.target.value),g(null)},onBlur:()=>{const b=Number(m);if(!Number.isInteger(b)||b<Pg||b>Mg){g(`Between ${Pg} and ${Mg}.`);return}b!==((s==null?void 0:s.maxTurns)??e.maxTurns)&&k({maxTurns:b})}})}),t.jsx(oe,{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=>k({language:b.target.value}),children:ite.map(b=>t.jsx("option",{value:b,children:b},b))})}),s?t.jsx(oe,{label:"New chat after",hint:"Idle time before your next message starts a fresh conversation, with a carried-over note. A transcript that grows too long starts one either way.",children:t.jsx("select",{"aria-label":"New chat after",value:s.idleRollover??"3h",onChange:b=>k({idleRollover:b.target.value==="3h"?null:b.target.value}),children:lte.map(b=>t.jsx("option",{value:b.value,children:b.label},b.value))})}):null,kT(NT(s??{id:e.id,provider:u},a))?t.jsx(oe,{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=>k({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(oe,{label:"Thinking",hint:v3,children:t.jsx("span",{className:"ui-card-meta",children:"Up to the model"})})]})})]})}),t.jsx(Gt,{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(dte,{agent:e,all:n,onSaved:c}),s&&e.tools.some(b=>b==="browser.*"||b.startsWith("browser."))?t.jsx(pe,{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:vB,children:"Browser & apps"}),". A rule never allows what is off there."]})]}),t.jsx(Xv,{value:s.browser??"auto",label:`Where ${e.name} may look`,apps:!1,onChange:b=>k({browser:b})})]})}):null,t.jsx(ste,{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(yte,{agent:e,all:n,onSaved:c})})})]})}function A2({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(E,{variant:"accent",disabled:!e||n,onClick:a,children:r})]})}const $2=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 ute({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,f]=d.useState(!1),m=me(()=>T.agentFile(e.id),[e.id]),[p,v]=d.useState(null),g=((O=m.data)==null?void 0:O.persona.trim())??"",k=p??g,j=m.data!==void 0&&p!==null&&p.trim()!==g,[x,w]=d.useState(!1),[N,y]=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??"")||j,A=c.trim()!==""&&(c.trim()!==(e.avatar??"")||!e.picture),$=Aj(A?{...e,avatar:c.trim()}:e),I={...$?{avatar:$}:{},...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...!A&&e.picture?{picture:e.picture}:{}},P=async()=>{w(!0),y(null),S(null);try{const R=await T.updateAgentFile(e.id,{name:s.trim(),handle:a.trim().replace(/^@/,""),description:l.trim(),...c.trim()===""?{}:{avatar:c.trim()},...j&&k.trim()!==""?{persona:k.trim()}:{}});e.picture&&c.trim()!==""&&c.trim()!==(e.avatar??"")&&(await T.removeAgentPicture(e.id),window.dispatchEvent(new Event(ks))),v(null),m.reload(),S(R.message),n()}catch(R){y(R instanceof Error?R.message:String(R))}finally{w(!1)}};return t.jsx(pe,{title:"Who it is",aside:t.jsx("span",{className:"mono",children:e.id}),panel:!0,foot:e.isExample?void 0:t.jsx(A2,{dirty:C,busy:x,failure:N,label:"Save who it is",onSave:()=>void P()}),children:t.jsxs(ue,{children:[e.isExample?$2:null,b?t.jsx(Q,{tone:"good",role:"status",children:b}):null,t.jsxs(Ms,{children:[t.jsx(oe,{label:"Name",hint:"What it is called, everywhere.",children:t.jsx("input",{value:s,disabled:x||e.isExample,onChange:R=>r(R.target.value)})}),t.jsx(oe,{label:"Handle",hint:"What you type to reach it. One handle, one agent.",children:t.jsx("input",{value:a,disabled:x||e.isExample,onChange:R=>i(R.target.value)})})]}),t.jsxs(re,{children:[t.jsx(In,{id:e.id,name:s.trim()||e.name,size:"xl",face:I}),t.jsx(E,{"aria-expanded":h,onClick:()=>f(R=>!R),children:h?"Hide faces":"Change face"})]}),h?t.jsx(pte,{agent:e,avatar:c,onEmoji:u,onChanged:n,disabled:x}):null,t.jsx(oe,{label:"Description",hint:"One or two sentences. Its colleagues read this.",children:t.jsx("textarea",{rows:2,value:l,disabled:x||e.isExample,onChange:R=>o(R.target.value)})}),t.jsx(oe,{label:"Persona",hint:t.jsxs(t.Fragment,{children:["Who it is and how it works, in its own file. It reads this before every conversation; ",t.jsx("code",{children:"{{today}}"})," is filled in with the date at run time."]}),wide:!0,children:m.error?t.jsx(ae,{message:m.error}):m.data?t.jsx("textarea",{className:"setup-persona",value:k,rows:Math.max(6,k.split(`
135
+ `).length+1),disabled:x||e.isExample,onChange:R=>v(R.target.value)}):t.jsx(be,{children:"Reading its file…"})})]})})}function dte({agent:e,all:n,onSaved:s}){var A;const r=me(()=>T.agentTools(e.id),[e.id,e.tools.join(",")]),[a,i]=d.useState(null),[l,o]=d.useState(()=>new Set((e.roles??[]).filter(DN))),[c,u]=d.useState((e.roles??[]).filter($=>!DN($)).join(", ")),[h,f]=d.useState(!1),[m,p]=d.useState(null),[v,g]=d.useState(null),k=($,I)=>$.split(I).map(P=>P.trim()).filter(P=>P!==""),j=((A=r.data)==null?void 0:A.granted)??e.tools,x=a??j,w=r.data!==void 0&&!kee(x,j),N=LN(l,k(c,/[\n,]/)),y=$=>o(I=>{const P=new Set(I);return P.has($)?P.delete($):P.add($),P}),S=w||!(($,I)=>$.join(",")===I.join(","))(N,LN(new Set(e.roles??[]),e.roles??[])),C=async()=>{f(!0),p(null),g(null);try{const $=await T.updateAgentFile(e.id,{...w&&r.data?{tools:bee(r.data.groups,x)}:{},roles:N});g($.message),i(null),r.reload(),s()}catch($){p($ instanceof Error?$.message:String($))}finally{f(!1)}};return t.jsx(pe,{title:"Roles and tools",panel:!0,foot:e.isExample?void 0:t.jsx(A2,{dirty:S,busy:h,failure:m,label:"Save roles and tools",onSave:()=>void C()}),children:t.jsxs(ue,{children:[e.isExample?$2:null,v?t.jsx(Q,{tone:"good",role:"status",children:v}):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:Ey.map($=>{const I=RB(n,$.id),P=I&&I.id!==e.id?I:void 0;return t.jsxs("button",{type:"button",className:"role-chip","aria-pressed":l.has($.id),"data-on":l.has($.id)?"true":void 0,disabled:h||e.isExample,onClick:()=>y($.id),children:[t.jsx("span",{className:"role-chip-label",children:$.label}),t.jsx("span",{className:"role-chip-meaning",children:$.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]},$.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(oe,{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:$=>u($.target.value)})}),t.jsxs("div",{className:"ui-field",children:[t.jsxs("span",{className:"ui-field-label",children:["Tools · ",j.length," granted"]}),r.error?t.jsx(ae,{message:r.error}):r.data?t.jsx(See,{view:r.data,chosen:x,onChange:i,disabled:h||e.isExample}):t.jsx(be,{children:"Loading the installed tools…"})]}),t.jsx(hte,{agentId:e.id,version:j.join(","),disabled:h||e.isExample}),fte(j)?t.jsx(mte,{agentId:e.id}):null]})})}function hte({agentId:e,version:n,disabled:s}){var v;const r=me(()=>Promise.resolve().then(()=>T.rememberedApprovals(e)),[e,n]),a=me(()=>Promise.resolve().then(()=>T.connections()).catch(()=>null),[]),[i,l]=d.useState(null),[o,c]=d.useState(null),u=((v=r.data)==null?void 0:v.tools)??[];if(u.length===0)return null;const h=async(g,k)=>{l(g),c(null);try{await T.setRememberedApproval(e,g,k),r.reload()}catch(j){c(j instanceof Error?j.message:String(j))}finally{l(null)}},f=new Map;for(const g of u)f.set(g.connection,[...f.get(g.connection)??[],g]);const m=g=>{var k,j;return((j=(k=a.data)==null?void 0:k.connections.find(x=>x.slug===g))==null?void 0:j.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:[...f].map(([g,k])=>{const j=k.filter(y=>y.rememberable),x=k.filter(y=>!y.rememberable),w=j.filter(y=>y.remembered),N=t.jsxs("span",{className:"remembered-summary",children:[t.jsx("span",{className:"remembered-name",children:m(g)}),t.jsxs("span",{className:"ui-card-meta",children:[` · ${k.length} ask first`,w.length>0?` · ${w.length} remembered: ${w.map(p).join(", ")}`:""]})]});return t.jsxs(Gt,{summary:N,boxed:!0,children:[t.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":`${m(g)}: remember my approval`,children:j.map(y=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:y.remembered,disabled:s||i!==null,onChange:b=>void h(y.tool,b.target.checked),"aria-label":`Remember my approval for ${y.tool}`}),t.jsx("span",{className:"mono",children:p(y)})]},y.tool))}),x.length>0?t.jsxs("p",{className:"ui-card-meta remembered-always",children:["These can delete or destroy something, so they always ask and are never remembered:"," ",t.jsx("span",{className:"mono",children:x.map(p).join(", ")})]}):null]},g)})}),t.jsx(ae,{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 fte(e){return e.some(n=>n==="owner.notify"||n==="owner.*"||n==="owner.notify?"||n==="owner.*?")}function mte({agentId:e}){var h,f;const n=me(()=>T.notificationSettings(),[]),[s,r]=d.useState(null),[a,i]=d.useState(!1),[l,o]=d.useState(null),c=s??((f=(h=n.data)==null?void 0:h.settings.agents)==null?void 0:f.muted.includes(e))??!1,u=m=>{i(!0),o(null),r(m),T.setAgentMuted(e,m).then(p=>r(p.agents.muted.includes(e))).catch(p=>{r(!m),o(p instanceof Error?p.message:String(p))}).finally(()=>i(!1))};return t.jsxs("div",{className:"ui-field",children:[t.jsx("span",{className:"ui-field-label",children:"Messages to you"}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:c,disabled:a||!n.data,onChange:m=>u(m.target.checked),"aria-label":"Mute this agent's messages"}),t.jsx("span",{children:"Mute its messages"})]}),t.jsx(ae,{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 Aj(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 pte({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),f=n.trim()!==""&&(n.trim()!==(e.avatar??"")||!e.picture),m=i??(f?{kind:"emoji",value:n.trim()}:e.picture?{kind:"kept",url:e.picture}:null),p=async v=>{if(h(null),v.kind==="emoji"){s(v.value);return}if(v.kind==="kept"){s(e.avatar??"");return}l(v),c(!0);try{await T.uploadAgentPicture(e.id,await C2(v.role)),s(e.avatar??""),r(),window.dispatchEvent(new Event(ks))}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(ate,{face:m,label:"Face",kept:e.picture,disabled:a||o,disableEmoji:e.isExample,onPick:v=>void p(v),children:t.jsx(gte,{agent:e,onChanged:r})}),u?t.jsx("span",{className:"critical save-error",role:"alert",children:u}):null]})}function gte({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,f]=d.useState(null),[m,p]=d.useState(0);d.useEffect(()=>{if(!s)return i(null);const S=URL.createObjectURL(s);return i(S),()=>URL.revokeObjectURL(S)},[s]);const v=S=>{r(null),p(C=>C+1),f(S),n(),window.dispatchEvent(new Event(ks))},g=async S=>{o(!0),u(null),f(null);try{v(await S())}catch(C){u(C instanceof Error?C.message:String(C))}finally{o(!1)}},k=()=>g(async()=>(await T.uploadAgentPicture(e.id,s)).note??null),j=()=>g(async()=>(await T.removeAgentPicture(e.id),null)),x={avatar:Aj(e),...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...a??e.picture?{picture:a??e.picture}:{}},[w,N]=d.useState(!1),y=d.useRef(null),b=S=>{u(null),f(null),r(S??null)};return t.jsxs("div",{className:"setup-upload","data-dragging":w?"true":void 0,onDragOver:S=>{S.preventDefault(),l||N(!0)},onDragLeave:()=>N(!1),onDrop:S=>{var C;S.preventDefault(),N(!1),l||b((C=S.dataTransfer.files)==null?void 0:C[0])},children:[t.jsxs(re,{children:[t.jsx(In,{id:e.id,name:e.name,size:"xl",face:x}),t.jsx("input",{ref:y,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])}},m),t.jsx(E,{disabled:l,onClick:()=>{var S;return(S=y.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(E,{variant:"ghost",disabled:l,onClick:()=>void j(),children:"Remove picture"}):null,t.jsx(E,{variant:"accent",disabled:!s||l,onClick:()=>void k(),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 xte({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),f=a!==((r==null?void 0:r.accountId)??"")||l!==((r==null?void 0:r.model)??""),m=n.accounts.find(p=>p.id===(r==null?void 0:r.accountId));return t.jsxs("div",{className:"ui-stack",children:[t.jsxs(re,{valign:"end",children:[t.jsx(oe,{label:"Account",children:t.jsxs("select",{value:a,disabled:c,onChange:p=>{var v;i(p.target.value),o(((v=n.accounts.find(g=>g.id===p.target.value))==null?void 0:v.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(Wb,{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(re,{children:[f&&a&&l.trim()?t.jsxs("span",{className:"warning",children:["Not saved yet. New runs still use ",m?`${m.label}, ${(r==null?void 0:r.model)??""}`:"nothing","."]}):t.jsx("span",{className:"muted",children:m?`Running on ${m.label} with ${(r==null?void 0:r.model)??"no model"}.`:"No account chosen yet: this agent cannot run until you save one."}),t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx(E,{variant:"accent",disabled:c||!a||!l.trim()||!f,onClick:()=>{u(!0),s(T.assignProviderAccount(e,a,l).finally(()=>u(!1)))},children:"Save account selection"})]})]})}const vte=["platform.create_agent","platform.update_agent","platform.write_skill","platform.delete_agent","platform.accept_plugin_agent","platform.accept_plugin_skill"],Og=e=>e.tools.some(n=>vte.includes(n)),jte=["front-desk","maker"],wte={"front-desk":"Can ask: everyone, as the front desk",maker:"Can ask: everyone, as the maker",list:"Can ask: everyone"};function yte({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),[f,m]=d.useState(e.delegates),[p,v]=d.useState(e.asksEveryone),[g,k]=d.useState(!1),j=n.filter($=>$.id!==e.id),x=jte.find($=>{var I;return(I=e.roles)==null?void 0:I.includes($)}),w=p===void 0||g,N=g||[...r].sort().join(",")!==[...f].sort().join(","),y=n.filter($=>$.id!==e.id&&($.delegates.includes(e.id)||$.asksEveryone!==void 0&&!Og(e))),b=$=>a(I=>I.includes($)?I.filter(P=>P!==$):[...I,$]),S=async $=>{l(!0),c(null),h(!1);try{const I=await T.setDelegates(e.id,$);m(I.delegates),a(I.delegates),v(I.asksEveryone),k(!1),h(!0),s()}catch(I){c(I instanceof Error?I.message:String(I))}finally{l(!1)}},C=()=>{a(j.filter($=>!Og($)).map($=>$.id)),k(!0),h(!1)},A=N?"Not saved yet.":u?"Saved. Applies to the next run.":w?r.length===0?"Asks nobody.":`May ask ${r.length} agent${r.length===1?"":"s"}.`:"Asks everyone.";return t.jsx(pe,{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:N?"warning":"muted",children:A}),t.jsx("span",{className:"ui-toolbar-spacer"}),w&&x!==void 0?t.jsx(E,{disabled:i,onClick:()=>void S(["*"]),children:"Let it ask everyone"}):null,w?t.jsx(E,{variant:"accent",disabled:!N||i,onClick:()=>void S(r),children:"Save who it can ask"}):t.jsx(E,{variant:"accent",disabled:i,onClick:C,children:"Limit to…"})]}),children:t.jsxs(ue,{divided:!0,children:[t.jsxs(pe,{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(ae,{message:o}),w?j.length===0?t.jsx(be,{children:"Nobody else is installed."}):t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"ui-card-meta",children:"Only the agents ticked here. New teammates must be added here before it can ask them."}),t.jsx("ul",{className:"ui-list delegate-list","aria-label":"Agents this one may ask",children:j.map($=>{const I=Og($);return t.jsxs("li",{className:"ui-list-row",children:[t.jsx("input",{type:"checkbox",id:`can-ask-${e.id}-${$.id}`,checked:r.includes($.id),disabled:I||e.isExample||i,onChange:()=>b($.id)}),t.jsxs("label",{htmlFor:`can-ask-${e.id}-${$.id}`,className:"ui-list-main",children:[t.jsxs("span",{className:"ui-list-title",children:[$.name," ",t.jsxs("span",{className:"mono muted",children:["@",$.handle]})]}),t.jsx("span",{className:"ui-list-sub",children:I?"Makes and changes agents. Never reachable by delegation.":$.description})]})]},$.id)})})]}):t.jsxs("p",{className:"ui-card-meta",children:[wte[p??"list"],". New agents are included without being added here; agents that make and change agents are never reachable by delegation."]})]}),t.jsx(pe,{title:"Asked by",children:y.length===0?t.jsxs("p",{className:"ui-card-meta",children:["No other agent may hand work to ",e.name,"."]}):t.jsx($8,{children:y.map($=>t.jsx(Se,{children:$.name},$.id))})})]})})}const bte=[{id:"team",label:"Team"},{id:"missions",label:"Missions"},{id:"offers",label:"Offers"},{id:"reminders",label:"Reminders"},{id:"skills",label:"Skills"}],kte=[{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 Nte(e){const n=dB(e.hash);return n?t.jsx(dq,{name:n.name,agents:e.agents,navigate:e.navigate,pluginPages:e.pluginPages}):t.jsx(Ste,{...e})}function Ste({hash:e,timezone:n,navigate:s,agents:r,attention:a,defaultAgentId:i}){var j,x,w,N,y;const l=oB(e),o=((j=/[?&]tab=([a-z]+)/.exec(e))==null?void 0:j[1])??"team",c=b=>S=>{S.preventDefault(),s(b)},u=me(()=>T.agents(),[]),h=Bm(),f=me(()=>T.offers(),[],2e4),m=OP(),p=(((x=f.data)==null?void 0:x.offers.length)??0)+m.offers.length,v=((N=(w=u.data)==null?void 0:w.default)==null?void 0:N.defaultAgentId)??i??null,[g,k]=d.useState(null);return t.jsxs("div",{className:"ui-page",children:[t.jsx(Ui,{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(E,{onClick:()=>k({kind:"upload",at:Date.now()}),children:"Upload"}),t.jsx(E,{variant:"accent",onClick:()=>k({kind:"write",at:Date.now()}),children:"Write a skill"})]}):t.jsx(nt,{variant:"accent",href:pn(),onClick:c(pn()),children:"Add a teammate"})}),t.jsx(_o,{children:bte.map(b=>t.jsx(Zi,{href:b.id==="team"?bt:`${bt}?tab=${b.id}`,active:o===b.id,count:b.id==="offers"?p:void 0,onClick:c(b.id==="team"?bt:`${bt}?tab=${b.id}`),children:b.label},b.id))}),o==="missions"?t.jsx(JM,{timezone:n,embedded:!0}):null,o==="offers"?t.jsx(DP,{offers:m.offers,reload:m.reload}):null,o==="offers"?t.jsx(ZM,{embedded:!0}):null,o==="reminders"?t.jsx(h2,{timezone:n,embedded:!0}):null,o==="skills"?t.jsx(cee,{faces:r,navigate:s,command:g,openSkill:d9(e),openFile:u9(e)}):null,o==="team"?t.jsx(Cte,{data:u.data,error:u.error,reload:u.reload}):null,o==="team"?r.length===0?t.jsx(os,{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:RI(r,v).map(b=>{const S=Qu(a.get(b.id));return t.jsxs("div",{className:"ui-card agent-card","data-interactive":"true",...Xi(Lo(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(In,{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:Dt(b.id,"conversations"),onClick:c(Dt(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===v?t.jsx(fo,{children:"front desk"}):null,S?t.jsx(Se,{tone:"critical",dot:!0,children:"waiting for you"}):b.available?t.jsx(Se,{tone:"good",dot:!0,children:"ready"}):t.jsx(Se,{tone:"warning",children:xr(b.unavailableReason??"cannot run",60)}),t.jsx(Se,{mono:!0,children:b.model}),t.jsx(nt,{className:"agent-card-talk",size:"sm",href:lt(b.id),onClick:c(lt(b.id)),"aria-label":`Talk to ${b.name}`,children:"Talk"})]})]},b.id)})}):null,l?t.jsx(Je,{title:((y=r.find(b=>b.id===l.agentId))==null?void 0:y.name)??l.agentId,size:"wide",onClose:()=>s(bt),children:t.jsx(Ete,{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 Cte({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,f]=d.useState(null);if(n)return t.jsx(ae,{message:n});if(!r||r.choices.length===0)return null;const m=r.defaultAgentId,p=a??m??"",v=p!==""&&p!==m,g=r.problem,k=x=>x.map(w=>{var N;return((N=r.choices.find(y=>y.id===w))==null?void 0:N.name)??w}).join(" and "),j=async()=>{o(!0),u(null),f(null);try{const x=await T.setDefaultAgent(p);f(x.note),i(null),s()}catch(x){u(x instanceof Error?x.message:String(x))}finally{o(!1)}};return t.jsx(st,{children:t.jsxs("div",{className:"ui-stack",children:[t.jsx(ae,{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: ${k(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(re,{children:[t.jsxs("div",{className:"default-agent-text",children:[t.jsx("h3",{className:"default-agent-title",children:"Default agent"}),t.jsx("span",{className:"ui-field-hint",children:"Where a chat that names nobody lands."})]}),t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsxs("select",{"aria-label":"Default agent",value:p,disabled:l,onChange:x=>i(x.target.value),children:[p===""?t.jsx("option",{value:"",children:"Choose an agent"}):null,r.choices.map(x=>t.jsxs("option",{value:x.id,disabled:!x.available,children:[x.name," @",x.handle,x.available?"":" (cannot run)"]},x.id))]}),t.jsx(E,{variant:"accent",disabled:l||!v,onClick:()=>void j(),children:"Save"})]})]})})}function Ete({agentId:e,agent:n,agents:s,tab:r,section:a,timezone:i,navigate:l,attention:o}){const c=p=>v=>{v.preventDefault(),l(p)},u=Qu(o.get(e)),h=(n==null?void 0:n.name)??e,f=FZ(e),m=n!==void 0&&!n.roles.includes(jr)&&!n.roles.includes(Yu);return t.jsxs("div",{className:"ui-stack","data-gap":"lg",children:[t.jsxs("header",{className:"agent-head",children:[t.jsx(In,{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."}),f.entry?t.jsx(_Z,{entry:f.entry,navigate:l,onUpdated:f.reload}):null,t.jsxs("div",{className:"ui-row",children:[n?t.jsxs("span",{className:"muted mono",children:["@",n.handle]}):null,n?t.jsx("span",{className:"muted",children:n.model}):null,u?t.jsx(Se,{tone:"critical",children:u}):n&&!n.available?t.jsx(Se,{tone:"warning",children:n.unavailableReason??"cannot run"}):null]})]}),t.jsx("div",{className:"ui-page-actions",children:t.jsxs(nt,{variant:"accent",href:lt(e),onClick:c(lt(e)),children:["Talk to ",h]})})]}),n&&!n.available?t.jsxs(Q,{tone:"warning",role:"status",children:[MI(n)," ",t.jsx("a",{href:_e(Sv(n).section),children:Sv(n).label})]}):null,t.jsx(_o,{children:kte.map(p=>t.jsx(Zi,{href:Dt(e,p.id),active:r===p.id,onClick:c(Dt(e,p.id)),children:p.label},p.id))}),r==="conversations"?t.jsx(Ate,{agentId:e,navigate:l}):null,r==="missions"?t.jsx(JM,{timezone:i,embedded:!0,agentId:e}):null,r==="offers"?t.jsx(ZM,{embedded:!0,agentId:e,agentName:h}):null,r==="reminders"?t.jsx(h2,{timezone:i,embedded:!0,agentId:e}):null,r==="memory"?t.jsx(n2,{embedded:!0,agents:s,timezone:i,agentId:e}):null,r==="skills"?t.jsx(vee,{agentId:e,agentName:h,faces:s,navigate:l}):null,r==="setup"?t.jsx(ote,{agentId:e,section:a,navigate:l}):null,r==="setup"&&m?t.jsx(UZ,{agentId:e,name:h,navigate:l}):null]})}function Ate({agentId:e,navigate:n}){const{data:s,error:r}=me(()=>Qe.conversations(e,50),[e]);if(r)return t.jsx(be,{children:r});const a=(s==null?void 0:s.conversations)??[];return t.jsx(st,{flush:!0,children:s?a.length===0?t.jsx(os,{icon:"chat",title:"No conversations yet",children:"Say hello, and the conversation shows up here."}):t.jsx(dt,{children:a.map(i=>t.jsx(ot,{href:lt(e,i.id),onClick:()=>n(lt(e,i.id)),title:xr(i.preview||i.opening||"Untitled conversation",90),sub:`${i.messageCount} message${i.messageCount===1?"":"s"}`,side:Ye(i.lastMessageAt??i.startedAt??i.createdAt??null)},i.id))}):t.jsx(be,{children:"Loading…"})})}const $te=3e4;function T2(){const{data:e,reload:n}=me(()=>T.recovery(),[],$te),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 h1(e){return e.kind==="account"?e.accountId?bI(e.accountId):_e("accounts"):e.kind==="telegram"?_e("telegram"):e.kind==="connection"?e.connectionId?kI(e.connectionId):_e("connections"):e.kind==="email"?e.settingsRoute:_e("secrets")}function Tte(e){return e.install?yB(e.install):xv}const Ite=_e("system");function Rte(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 I2="This buddi was restored from a backup. Nothing runs on its own until you finish the checklist.";function Pte({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([]),[f,m]=d.useState(!1),[p,v]=d.useState(null),[g,k]=d.useState(!1),j=r.filter(y=>!y.installed||y.waiting!==void 0||y.loadsAtRestart===!0),x=a.jobs+a.missions+a.approvals+a.telegramChats,w=y=>{h(b=>b.includes(y)?b.filter(S=>S!==y):[...b,y])},N=()=>{m(!0),v(null),qu({kind:"recovery"},()=>T.leaveRecovery({dropPending:o,keepGrants:u})).then(y=>{y&&y.restarting===!1&&ho(),k(!0),n==null||n()}).catch(y=>v(y instanceof he?y.message:String(y))).finally(()=>m(!1))};return t.jsx(st,{title:"Back from a backup",children:t.jsxs(ue,{divided:!0,children:[t.jsxs(pe,{children:[t.jsx(Vt,{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(pe,{title:"Keys to paste again",children:s.length===0?t.jsx(be,{children:"Nothing is missing."}):t.jsx(dt,{children:s.map(y=>t.jsx(ot,{title:y.label??y.name,sub:y.name?t.jsx("span",{className:"mono",children:y.name}):void 0,side:y.signIn?t.jsx(nt,{size:"sm",href:h1(y),"aria-label":`Sign in again: ${y.label??y.name}`,children:"Sign in again"}):t.jsx(nt,{size:"sm",href:h1(y),"aria-label":`Fix ${y.label??y.name}`,children:"Fix"})},`${y.kind}:${y.accountId??y.name}`))})}),t.jsx(pe,{title:"Add-ons to install again",children:j.length===0&&l.length===0?t.jsx(be,{children:"Everything the backup named is installed."}):t.jsxs(dt,{children:[j.map(y=>t.jsx(ot,{title:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"mono",children:y.name})," ",y.version]}),sub:Rte(y),side:y.loadsAtRestart?t.jsx(nt,{size:"sm",href:Ite,"aria-label":`Restart to load ${y.name}`,children:"Restart"}):y.installed?void 0:t.jsx(nt,{size:"sm",href:Tte(y),"aria-label":`Install ${y.name} again`,children:y.install?"Install":"Find it"})},y.name)),l.map(y=>t.jsx(ot,{title:t.jsx("span",{className:"mono",children:y.table}),sub:y.sentence},`kept:${y.table}`))]})}),t.jsx(pe,{title:"Work that was waiting",children:x===0?t.jsx(be,{children:"Nothing was in flight when the backup was taken."}):t.jsxs(ue,{gap:"sm",children:[t.jsx(Vt,{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:y=>c(y.target.checked)}),t.jsx("span",{children:"Drop it. It was queued somewhere else, days ago."})]})]})}),t.jsx(pe,{title:"Standing permissions",children:i.length===0?t.jsx(be,{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(y=>t.jsx("li",{children:t.jsxs("label",{className:"recovery-check",children:[t.jsx("input",{type:"checkbox",checked:u.includes(y.id),onChange:()=>w(y.id),"aria-label":`Keep ${y.tool} for ${y.agent}`}),t.jsxs("span",{children:[t.jsx("span",{className:"mono",children:y.tool})," for ",y.agent," ",t.jsx("span",{className:"ui-card-meta",children:y.scope}),y.description?t.jsxs("span",{className:"ui-card-meta",children:[" — ",y.description]}):null]})]})},y.id))})]})}),t.jsx(pe,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{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(re,{align:"end",children:t.jsx(E,{variant:"accent",disabled:f||g,onClick:N,children:"Leave recovery mode"})})]})})]})})}function R2(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 P2(e){return(e??[]).filter(n=>n.state==="ready"&&n.wakesOnRestart===!0)}function Mte(e){return`${R2(e)} ${e.length===1?"is":"are"} installed; ${e.length===1?"it wakes":"they wake"} up after a restart.`}const M2="buddi.handoverWakes";function f1(e){try{window.localStorage.setItem(M2,P2(e).length>0?"1":"0")}catch{}}function Ote(){try{return window.localStorage.getItem(M2)==="0"}catch{return!1}}function O2({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&&f1(e);return}if(n==="unknown")return;if(n==="done"&&Ote()){r([]);return}let h=!1;return Promise.resolve().then(()=>T.takeOnProgress()).then(f=>{if(h)return;const m=(f==null?void 0:f.plugins)??[];r(m),n==="done"&&f1(m)}).catch(()=>{h||r([])}),()=>{h=!0}},[e,n]);const c=P2(e??s??[]);if(c.length===0)return null;const u=()=>{i(!0),o(null),qu({kind:"plugins",line:`Loading ${R2(c)}…`},()=>T.serviceAction("restart")).catch(h=>o(h instanceof he?h.message:String(h))).finally(()=>i(!1))};return t.jsxs(Q,{tone:"accent",role:"status",action:t.jsx(E,{size:"sm",variant:"accent",disabled:a,onClick:u,children:"Restart"}),children:[Mte(c),l?` ${l.replace(/[.\s]+$/,"")}.`:" It takes a few seconds, and this page comes back by itself."]})}const m1=3,Dte=40;function Lte({agent:e,navigate:n}){var v;const s=d.useRef(null),[r,a]=d.useState(!1),[i,l]=d.useState(null),[o,c]=d.useState(null),u=me(()=>Qe.conversations(e.id,m1),[e.id],3e4),h=Yn(Fy),f=Yn("(pointer: coarse)");d.useEffect(()=>{var g;!h&&!f&&((g=s.current)==null||g.focus())},[]);const m=(g,k)=>{a(!0),l(null),(async()=>{try{const{conversationId:j}=await Qe.startConversation(e.id),x=await Qe.send(e.id,{conversationId:j,text:g,...k.length>0?{attachmentIds:k.map(w=>w.artifactId)}:{}});n(lt(e.id,x.conversationId))}catch(j){l(j instanceof he?j.message:String(j)),c({text:g,at:Date.now()}),a(!1)}})()},p=(((v=u.data)==null?void 0:v.conversations)??[]).slice(0,m1);return t.jsxs("div",{className:"home-ask",children:[i?t.jsx(ae,{message:i}):null,t.jsx(gb,{ref:s,disabled:r||!e.available,running:!1,onSend:m,onStop:()=>{},agentName:e.name,placeholder:`Message ${e.name}…`,draft:o,threadKey:`home.${e.id}`,slim:!0}),p.length>0?t.jsxs("div",{className:"home-continue",children:[t.jsx("span",{className:"home-continue-label",id:`home-continue-${e.id}`,children:"Continue"}),t.jsx("ul",{className:"home-continue-chips","aria-labelledby":`home-continue-${e.id}`,children:p.map(g=>{const k=lt(e.id,g.id),j=g.opening??g.preview??"Untitled conversation",x=ay(g.lastMessageAt??g.createdAt??g.startedAt??null);return t.jsx("li",{children:t.jsxs("a",{className:"home-continue-chip",href:k,title:j,onClick:w=>{w.preventDefault(),n(k)},children:[t.jsx("span",{className:"home-continue-title",children:xr(j,Dte)}),x?t.jsx("span",{className:"home-continue-when",children:x}):null]})},g.id)})})]}):null]})}function Fte(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 p1=3,_te=320,g1=160,zte=.3,x1=120,Ute=.06,$j=14;function Bte(e,n=!1){var j,x,w,N;const s=me(()=>T.tipQueue(e,n),[e,n]),[r,a]=d.useState(new Set),[i,l]=d.useState([]),[o,c]=d.useState(!1),u=((j=s.data)==null?void 0:j.tips)??[];d.useEffect(()=>{l([])},[s.data]);const h=u.filter(y=>!r.has(y.id)),f=[...h.filter(y=>!i.includes(y.id)),...i.flatMap(y=>h.find(b=>b.id===y)??[])],m=!!(e||(x=s.data)!=null&&x.preview),p=d.useCallback((y,b)=>{b==="later"?l(S=>[...S.filter(C=>C!==y),y]):a(S=>new Set(S).add(y)),!m&&(b==="dismiss"?T.dismissTip(y):T.laterTip(y)).catch(()=>{})},[m]),{reload:v}=s,g=d.useCallback(async y=>{await T.restoreTip(y),a(S=>{const C=new Set(S);return C.delete(y),C}),c(!1),v()},[v]),k=(((w=s.data)==null?void 0:w.dismissed)??0)+[...r].filter(y=>u.some(b=>b.id===y)).length;return{tips:f,shown:u.length>0&&!(f.length===0&&o),loaded:s.data!==void 0||s.error!==null,allDismissed:f.length===0&&((((N=s.data)==null?void 0:N.dismissed)??0)>0||u.length>0),error:s.error,dismissed:k,restore:g,leave:p,folded:d.useCallback(()=>c(!0),[])}}function Wte(e){return Math.max(-$j,Math.min($j,e*Ute))}function Hte({queue:e,navigate:n}){const s=Yn("(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:f}=e,m=u.length===0;d.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]),d.useEffect(()=>{if(!m||!e.shown)return;const S=setTimeout(f,g1);return()=>clearTimeout(S)},[m,e.shown,f]);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?g1:_te))},[u,r.kind,h,s]);if(!e.shown)return null;const v=u[0],g=r.kind==="fly",k=u.slice(0,p1+(g?1:0)),j=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}))},x=S=>{const C=o.current;!C||C.id!==S.pointerId||a({kind:"drag",dx:S.clientX-C.x})},w=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,$=C.width>0?Math.min(x1,C.width*zte):x1;Math.abs(A)>=$?p(A<0?"later":"dismiss"):a({kind:"snap"})},N=S=>{S.key==="ArrowLeft"?(S.preventDefault(),p("later")):S.key==="ArrowRight"?(S.preventDefault(),p("dismiss")):S.key==="Enter"&&S.target===S.currentTarget&&v&&(S.preventDefault(),n(v.action.route))},y=()=>{var S;if(r.kind==="drag")return{transform:`translateX(${r.dx}px) rotate(${Wte(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*$j*1.3}deg)`}}},b=u.length;return t.jsx("div",{className:"tip-stack-fold","data-empty":m?"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":v?`Tips, 1 of ${b}. Left arrow: not now. Right arrow: not this again. Enter: ${v.action.label}.`:"Tips",tabIndex:m?-1:0,onKeyDown:N,"data-motion":s?"reduced":"full","data-depth":Math.min(b,p1)-1,"data-testid":"tip-stack",children:k.map((S,C)=>{const A=C===0,$=g&&A,I=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":$?"leaving":I,"data-dragging":A&&r.kind==="drag"?"true":void 0,"data-leaving":$?r.how:void 0,style:{zIndex:k.length-C,...A?y():{}},"aria-hidden":A?void 0:!0,...A?{}:{inert:""},...A?{onPointerDown:j,onPointerMove:x,onPointerUp:w,onPointerCancel:w}:{},children:t.jsx(Es,{kind:"tip",tone:"accent",icon:"bulb",title:S.text,from:"A tip from buddi",actions:t.jsx(E,{variant:"accent",tabIndex:A&&!$?void 0:-1,onClick:()=>n(S.action.route),children:S.action.label})})},S.id)})}),v?t.jsxs("div",{className:"tip-stack-nav",children:[t.jsxs(E,{variant:"ghost",size:"sm",title:"It may come back after a while",disabled:g,onClick:()=>p("later"),children:[t.jsx(ie,{name:"chevron-left",size:14}),"Not now"]}),t.jsxs("span",{className:"tip-stack-count","aria-live":"polite",children:["1 of ",b]}),t.jsxs(E,{variant:"ghost",size:"sm",title:"Never show this tip again",disabled:g,onClick:()=>p("dismiss"),children:["Not this again",t.jsx(ie,{name:"chevron-right",size:14})]})]}):null]})})}const Tj="buddi.tipsOpen",Ij="buddi.tipsSeen";function Kte(){try{return window.localStorage.getItem(Tj)==="1"}catch{return!1}}function Vte(){try{const e=JSON.parse(window.localStorage.getItem(Ij)??"[]");return Array.isArray(e)?e.filter(n=>typeof n=="string"):[]}catch{return[]}}function Gte(e){try{e.length?window.localStorage.setItem(Ij,JSON.stringify(e)):window.localStorage.removeItem(Ij)}catch{}}function Yte(e){const[n,s]=d.useState(()=>!!e||Kte());d.useEffect(()=>{e&&s(!0)},[e]);const r=d.useCallback(u=>{if(s(u),!e)try{u?window.localStorage.setItem(Tj,"1"):window.localStorage.removeItem(Tj)}catch{}},[e]),a=Bte(e,!n),[i,l]=d.useState(Vte),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(f=>u.includes(f));h.join(",")!==i.join(",")&&(l(h),Gte(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 qte({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(ie,{name:"bulb"}),r?t.jsx("span",{className:"home-tips-dot","data-testid":"tips-dot"}):null]})}function Qte({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(pe,{title:"Tips",actions:t.jsx(E,{variant:"ghost",size:"sm",onClick:()=>r(!1),children:"Close"}),children:[t.jsx(ae,{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(Jte,{queue:a}):null]}):t.jsx(Hte,{queue:a,navigate:n})]})})}function Jte({queue:e}){const[n,s]=d.useState(!1),r=e.dismissed;return n?t.jsx(Xte,{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(E,{variant:"ghost",size:"sm",onClick:()=>s(!0),children:"Show"})]})}function Xte({queue:e}){var h;const n=me(()=>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(f=>!s.has(f.id)),u=async f=>{i(f),o(null);try{await e.restore(f),r(m=>new Set(m).add(f))}catch(m){o(m instanceof Error?m.message:String(m))}finally{i(null)}};return t.jsxs("div",{className:"home-tips-dismissed-list","data-testid":"tips-dismissed",children:[t.jsx(ae,{message:n.error??l}),n.data&&c.length===0?null:t.jsx(dt,{children:c.map(f=>t.jsx(ot,{title:f.text,side:t.jsx(E,{size:"sm",disabled:a!==null,onClick:()=>void u(f.id),children:"Bring back"})},f.id))})]})}function Zte(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 ene({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:yr(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(an,{agents:n,id:a.id,size:"sm"},a.id))}),t.jsx("span",{className:"bd-sign",children:Zte(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(ie,{name:"close"})})]})}const tne="Write these down; they open your backups and only you have them.";function nne(){var r;const e=me(()=>T.passphraseNotice(),[]),[n,s]=d.useState(!1);return{data:e.data,shown:!n&&!!((r=e.data)!=null&&r.show),gone:()=>s(!0)}}function sne({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),f=e.data;if(!e.shown||!f||!f.show)return null;const m="passphrase"in f?f.passphrase:u,p=()=>{m!==null&&navigator.clipboard.writeText(m).then(()=>s("done"),()=>s("failed"))},v=()=>{a(!0),l(null),T.revealBackupPassphrase(o).then(k=>{h(k.passphrase),c("")}).catch(k=>l(k instanceof he?k.message:String(k))).finally(()=>a(!1))},g=()=>{a(!0),l(null),T.acknowledgePassphrase().then(()=>e.gone()).catch(k=>l(k instanceof he?k.message:String(k))).finally(()=>a(!1))};return t.jsxs(Es,{kind:"passphrase",tone:"accent",icon:"key",title:"Your backup passphrase",from:"buddi · after your first backup",actions:m!==null?t.jsxs(t.Fragment,{children:[t.jsx(E,{onClick:p,children:n==="done"?"Copied":n==="failed"?"Could not copy":"Copy"}),t.jsx(E,{variant:"accent",disabled:r,onClick:g,children:"I saved it"})]}):t.jsx(E,{variant:"accent",disabled:r||o==="",onClick:v,children:"Show the words"}),children:[t.jsx(ae,{message:i}),t.jsx("p",{children:tne}),m!==null?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"backup-phrase mono","aria-label":"Your backup passphrase",children:m}),t.jsx("p",{className:"ui-card-meta",children:"Later, Settings → Backup shows them again behind your PIN."})]}):t.jsx(oe,{label:"Your PIN",hint:"The one that unlocks this dashboard.",children:t.jsx("input",{type:"password",inputMode:"numeric",autoComplete:"off",value:o,onChange:k=>c(k.target.value),onKeyDown:k=>{k.key==="Enter"&&o!==""&&v()}})})]})}const D2="buddi.needsYouView";function rne(){try{return window.localStorage.getItem(D2)==="list"?"list":"deck"}catch{return"deck"}}function ane(e){try{window.localStorage.setItem(D2,e)}catch{}}function ine(e,n,s){const r=(n.alsoFrom??[]).filter(a=>a!==n.agentId).map(s);return r.length===0?e:`${e} · also ${r.join(", ")}`}function lne({rows:e,agents:n,label:s,onOpen:r,onDone:a}){const[i,l]=d.useState(0);if(e.length===0)return t.jsx(be,{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=v=>l((o+v+e.length)%e.length),f=()=>r(c),m=()=>a(c),p=v=>{const g=v.target;g.closest('input, textarea, select, [contenteditable="true"]')||(v.key==="ArrowRight"&&u?(v.preventDefault(),h(1)):v.key==="ArrowLeft"&&u?(v.preventDefault(),h(-1)):v.key==="Enter"&&!g.closest("button, a")?(v.preventDefault(),(c.link||c.agentId)&&f()):(v.key==="d"||v.key==="Delete")&&!v.metaKey&&!v.ctrlKey&&!v.altKey&&(v.preventDefault(),m()))};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(Es,{kind:"request",tone:"accent",title:gu(c),time:c.state==="held"?"today":Ye(c.createdAt),from:t.jsx(Eu,{face:c.agentId?t.jsx(an,{agents:n,id:c.agentId,size:"sm"}):void 0,children:s(c)}),lead:t.jsxs("span",{className:"home-deck-nav",children:[t.jsx(E,{size:"sm",variant:"ghost","aria-label":"Previous",disabled:!u,onClick:()=>h(-1),children:t.jsx(ie,{name:"chevron-left"})}),t.jsxs("span",{className:"home-deck-count","aria-live":"polite",children:[o+1," of ",e.length]}),t.jsx(E,{size:"sm",variant:"ghost","aria-label":"Next",disabled:!u,onClick:()=>h(1),children:t.jsx(ie,{name:"chevron-right"})})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(E,{onClick:m,children:"Done"}),c.link||c.agentId?t.jsx(E,{variant:"accent",onClick:f,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 one({row:e,agents:n,label:s,onOpen:r,onDone:a}){const i=!!(e.link||e.agentId);return t.jsx(Es,{kind:"request",tone:"accent",compact:!0,title:gu(e),...i?{href:e.link??"#",onOpen:()=>r(e)}:{},time:e.state==="held"?"today":Ye(e.createdAt),from:t.jsx(Eu,{face:e.agentId?t.jsx(an,{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(E,{size:"sm",onClick:()=>a(e),children:"Done"}),i?t.jsx(E,{size:"sm",variant:"accent",onClick:()=>r(e),children:"Open"}):null]})})}function cne({timezone:e,navigate:n,agents:s,defaultAgentId:r,attention:a,update:i,connectionSignals:l=[],hash:o="",pluginPages:c,onboarding:u}){var je,et,ft,Et,Ft,Pt,Rn,zn,Yt,Un,xn,vn,Xn,_t,Te,rt,De,tt;const h=me(()=>T.overview(),[],15e3),f=me(()=>T.approvals(),[],1e4),m=me(()=>T.missions(),[],6e4),p=me(()=>T.reminders(),[],6e4),v=me(()=>T.conversations(),[],3e4),g=me(()=>T.offers(),[],3e4),k=me(()=>T.proposals(),[],6e4),j=me(()=>T.agentOffers(),[],6e4),x=me(()=>T.owner(),[]),w=me(()=>T.birthday(),[],5*6e4),N=me(()=>T.notificationsNeedingYou(),[],3e4),y=d.useMemo(()=>RI(s,r??null),[s,r]),b=vq(s,r),{busy:S,note:C,failure:A,decide:$}=xb(()=>{f.reload(),h.reload()}),I=h.data,P=s.find(F=>F.id===r)??null,O=F=>K5(F,s),R=F=>Fe=>{Fe.preventDefault(),n(F)},D=((je=f.data)==null?void 0:je.pending)??[],U=((et=I==null?void 0:I.jobs)==null?void 0:et.failed)??0,W=((ft=I==null?void 0:I.sentinels)==null?void 0:ft.openUrgent)??0,M=((Et=k.data)==null?void 0:Et.open.length)??0,L=(((Ft=j.data)==null?void 0:Ft.offers)??[]).filter(F=>!D.some(Fe=>MP(Fe,F.plugin,F.agent))),_=dne(((Pt=N.data)==null?void 0:Pt.notifications)??[],D),[Y,B]=d.useState(new Set),[se,G]=d.useState(rne),X=_.filter(F=>!Y.has(F.id)),K=F=>{B(Fe=>new Set(Fe).add(F.id)),T.notificationSeen(F.id).catch(()=>{})},J=F=>{K(F);const Fe=F.link??(F.agentId?lt(F.agentId):null);Fe&&n(Fe)},q=F=>ine(F.agentId?O(F.agentId):F.pluginId?Nv(F.pluginId,c==null?void 0:c.all):une[F.kind],F,O),ce=pne(I==null?void 0:I.dismissed,()=>h.reload()),xe=(((Rn=I==null?void 0:I.sentinels)==null?void 0:Rn.errors)??[]).filter(F=>!ce.is(`watcher-error:${F.sentinelId}`,F.error)),Me=((I==null?void 0:I.mail)??[]).filter(F=>F.lastError&&!ce.is(`source-error:${F.sourceId}`,F.lastError)),H=hne(a),ne=l.filter(F=>!ce.is(`connection:${F.id}`,F.sentence)),Z=(((zn=I==null?void 0:I.needsYou)==null?void 0:zn.recovery)??0)>0,ye=Yte(Fte(o)),Ce=nne(),ke=!!(i&&i.updateAvailable&&!i.checkout&&i.latest&&!ce.is("update",i.latest)),we=D.length+H.length+L.length+_.length+ne.length+(Z?1:0)+(Ce.shown?1:0)+(ke?1:0)+xe.length+Me.length;d.useEffect(()=>{var F,Fe;o===uo&&((Fe=(F=document.getElementById(Rj))==null?void 0:F.scrollIntoView)==null||Fe.call(F,{behavior:"smooth",block:"start"}))},[o]);const ve=d.useMemo(()=>{var F,Fe;return jne(((F=m.data)==null?void 0:F.missions)??[],((Fe=p.data)==null?void 0:Fe.reminders)??[])},[m.data,p.data]),Ie=(((Yt=v.data)==null?void 0:Yt.conversations)??[]).slice(0,5),Re=((Un=g.data)==null?void 0:Un.offers)??[],de=Re.slice(0,gne),Ee=Re.length-de.length,ze=IM(()=>h.reload()),qe=uX(),ht=d.useMemo(()=>dX(qe.answer),[qe.answer]),le=Cne((I==null?void 0:I.needsYou)??{approvals:D.length,questions:H.length,failed:U,urgent:W,proposals:M,agentsToSetUp:L.length,asks:_.length,signIns:ne.length,recovery:Z?1:0},(I==null?void 0:I.paused)??!1).map(F=>{var Fe;return F.key==="urgent"?{...F,hint:Sne(F.count??0,((Fe=I==null?void 0:I.sentinels)==null?void 0:Fe.decisions)??[])}:F});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:kne(I==null?void 0:I.now,e)}),t.jsx(UJ,{glances:I==null?void 0:I.glances,navigate:n,except:ht,hiding:ze}),t.jsx(qte,{tips:ye})]}),t.jsx("h1",{className:"home-greeting",children:(xn=w.data)!=null&&xn.today?yne(w.data.name??((vn=x.data)==null?void 0:vn.preferredName)??((Xn=x.data)==null?void 0:Xn.displayName)):bne(I==null?void 0:I.now,e,((_t=x.data)==null?void 0:_t.preferredName)||((Te=x.data)==null?void 0:Te.displayName))}),t.jsx(Ene,{items:le,navigate:n})]}),t.jsx("div",{className:"home-side",children:t.jsx(WI,{size:"lg",anim:"idle"})})]}),(rt=w.data)!=null&&rt.today&&w.data.note&&!ce.is("birthday",w.data.date)?t.jsx(ene,{glance:w.data,team:y,onClose:()=>ce.close("birthday",w.data.date)}):null]}),t.jsxs("div",{className:"home",children:[P?t.jsx(Lte,{agent:P,navigate:n},P.id):null,t.jsx(Qte,{tips:ye,navigate:n}),t.jsx(ae,{message:h.error??f.error??A}),C?t.jsx("p",{className:"home-note muted",role:"status",children:C}):null,we>0?t.jsx("div",{id:Rj,className:"home-needs",children:t.jsx(pe,{title:"Needs you",aside:t.jsx("a",{href:jv,onClick:R(jv),children:"All notifications"}),actions:_.length>0?t.jsx(Xt,{label:"Show what needs you as",options:[{value:"list",label:"List"},{value:"deck",label:"Deck"}],value:se,onChange:F=>{G(F),ane(F)}}):void 0,children:t.jsxs(ue,{children:[D.map(F=>t.jsx(vb,{action:F,timezone:e,busy:S===F.id,onDecide:$,agentName:O(F.agentId),agents:s},F.id)),H.map(F=>t.jsx(Es,{kind:"question",tone:"accent",icon:"chat",title:"Asked you a question",href:F.route,onOpen:()=>n(F.route),time:Ye(F.at),from:t.jsxs(Eu,{face:t.jsx(an,{agents:s,id:F.agentId,size:"sm"}),children:[O(F.agentId)," · waiting for your answer"]}),actions:t.jsx(E,{variant:"accent",onClick:()=>n(F.route),children:"Answer"})},F.agentId)),_.length>0&&se==="list"?t.jsx(ue,{gap:"sm",children:X.map(F=>t.jsx(one,{row:F,agents:s,label:q,onOpen:J,onDone:K},F.id))}):null,_.length>0&&se==="deck"?t.jsx(lne,{rows:X,agents:s,label:q,onOpen:J,onDone:K}):null,t.jsx(sne,{notice:Ce}),ke&&i?t.jsx(Es,{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:()=>ce.close("update",i.latest),hint:"Tell me at the next version"},actions:t.jsx(nt,{variant:"accent",href:_e("system"),onClick:R(_e("system")),children:"Upgrade from Settings"})}):null,xe.map(F=>t.jsx(Es,{kind:"watcher-error",tone:"warning",icon:"alert",title:`Watcher ${F.sentinelId} failed`,from:"buddi · your watchers",dismiss:{onClick:()=>ce.close(`watcher-error:${F.sentinelId}`,F.error),hint:"Hide until the error changes"},actions:t.jsx(nt,{href:_e("watchers"),onClick:R(_e("watchers")),children:"Open Watchers"}),children:t.jsx("p",{children:F.error})},F.sentinelId)),Me.map(F=>t.jsx(Es,{kind:"source-error",tone:"warning",icon:"alert",title:`Source ${F.sourceId} cannot be read`,from:"buddi · your sources",dismiss:{onClick:()=>ce.close(`source-error:${F.sourceId}`,F.lastError),hint:"Hide until the error changes"},children:t.jsx("p",{children:F.lastError})},F.sourceId)),ne.map(F=>t.jsx(Es,{kind:"sign-in",tone:"accent",icon:"plug",title:F.sentence,from:`${F.name} · a connection`,dismiss:{onClick:()=>ce.close(`connection:${F.id}`,F.sentence),hint:"Tell me if it changes"},actions:t.jsx(nt,{variant:"accent",href:_e("connections"),onClick:R(_e("connections")),children:"Open Connections"})},F.id)),L.map(F=>t.jsx(wb,{plugin:F.plugin,agent:F.agent,text:F.text,label:`Create @${F.handle}`,handle:F.handle,card:{from:Nv(F.plugin,c==null?void 0:c.all)},onDismiss:()=>{T.dismissAgentOffer(F.plugin,F.agent).then(()=>j.reload())}},`${F.plugin}/${F.agent}`)),Z?t.jsx(Es,{kind:"recovery",tone:"warning",icon:"archive",title:"Finish restoring this buddi",from:"buddi · restored from a backup",actions:t.jsx(nt,{variant:"accent",href:wv,onClick:R(wv),children:"Open the checklist"}),children:t.jsx("p",{children:I2})}):null]})})}):null,t.jsx(O2,{...u?{onboarding:u}:{}}),t.jsx(pX,{widgets:qe,navigate:n}),t.jsxs(pe,{title:"Your team",aside:b?t.jsx("a",{href:pn(),onClick:R(pn()),children:"See all teammates"}):t.jsx("a",{href:bt,onClick:R(bt),children:"All agents"}),children:[s.length===0?t.jsx(be,{mascot:!0,children:"No agents yet. Add one under Agents."}):t.jsxs("div",{className:"home-team",children:[y.map(F=>{const Fe=Qu(a.get(F.id));return t.jsxs("a",{className:"home-face",...Xi(Lo(F)),href:lt(F.id),onClick:R(lt(F.id)),"data-waiting":Fe?"true":void 0,"data-unavailable":F.available?void 0:"true",children:[t.jsx(In,{id:F.id,name:F.name,size:"lg",unavailable:!F.available,face:F}),t.jsxs("span",{className:"home-face-text",children:[t.jsx("span",{className:"home-face-name",children:F.name}),t.jsx("span",{className:"home-face-status",children:Fe?Ane(Fe):F.available?xr(F.description,60):F.unavailableReason??"Cannot run right now."})]})]},F.id)}),b?null:t.jsxs("a",{className:"team-add",href:pn(),onClick:R(pn()),"data-testid":"team-add",children:[t.jsx(ie,{name:"plus",size:14}),"Add a teammate"]})]}),t.jsx(kq,{navigate:n,newTeam:b,closed:ce})]}),de.length>0?t.jsx(pe,{title:"On offer",aside:t.jsxs("span",{className:"ui-row",children:[Ee>0?t.jsxs("a",{href:`${bt}?tab=offers`,onClick:R(`${bt}?tab=offers`),children:[Ee," more"]}):null,t.jsx(XM,{ids:Re.map(F=>F.id),onDone:()=>g.reload()})]}),children:t.jsx("div",{className:"home-offers",children:de.map(F=>t.jsx(vne,{offer:F,agents:s,open:R(Dt(F.agentId,"offers")),onDismissed:()=>g.reload()},F.id))})}):null,t.jsx(wJ,{}),(tt=(De=k.data)==null?void 0:De.digest)!=null&&tt.latest&&mne(k.data.digest.latest,I==null?void 0:I.now,ce.is)?t.jsx(Nne,{digest:k.data.digest.latest,go:R,onClose:()=>ce.close(L2,k.data.digest.latest.at)}):null,t.jsxs("div",{className:"home-columns",children:[t.jsx(pe,{title:"Coming up",aside:t.jsx("a",{href:`${bt}?tab=missions`,onClick:R(`${bt}?tab=missions`),children:"All missions"}),children:t.jsx(st,{flush:!0,children:ve.length===0?t.jsx(be,{mascot:!0,children:"Nothing scheduled. Missions and reminders will show here."}):t.jsx(dt,{children:ve.map(F=>t.jsx(ot,{href:F.route,onClick:()=>n(F.route),lead:t.jsx(an,{agents:s,id:F.agentId,size:"sm"}),title:F.title,sub:`${F.kind} for ${O(F.agentId)}`,side:Ye(F.at)},F.key))})})}),t.jsx(pe,{title:"Lately",aside:t.jsx("a",{href:Jt,onClick:R(Jt),children:"All activity"}),children:t.jsx(st,{flush:!0,children:Ie.length===0?t.jsx(be,{mascot:!0,children:"Nothing has run yet. Say hello to someone on your team."}):t.jsx(dt,{children:Ie.map(F=>t.jsx(ot,{href:lt(F.agentId,F.id),onClick:()=>n(lt(F.agentId,F.id)),lead:t.jsx(an,{agents:s,id:F.agentId,size:"sm"}),title:F.opening?xr(F.opening,80):"Untitled conversation",sub:`${O(F.agentId)}, ${F.messageCount} message${F.messageCount===1?"":"s"}`,side:Ye(F.lastMessageAt??F.createdAt)},F.id))})})})]}),((I==null?void 0:I.home)??[]).filter(F=>!ce.is(v1(F.id),j1)).map(F=>t.jsx($ne,{block:F,onHide:()=>ce.close(v1(F.id),j1)},F.id)),I!=null&&I.jobs&&I.missions?t.jsxs("p",{className:"home-foot muted",children:[mn(I.jobs.pending??0)," queued, ",mn(I.jobs.leased??0)," running, ",mn(I.missions.enabled)," of ",mn(I.missions.total)," missions on."," ",I.paused?t.jsx(Se,{tone:"warning",children:"paused"}):t.jsx(Se,{tone:"good",children:"running"})," ",t.jsx("a",{href:ju("").replace(/\/conversations\/$/,""),onClick:R(Jt),children:"Activity"})," · ",t.jsx("a",{href:_e("system"),onClick:R(_e("system")),children:"System"})]}):null]})]})}const une={approval:"Approval",question:"Question",watcher:"Watcher",reminder:"Reminder",failure:"Failure",recap:"Report",plugin:"Plugin",agent:"Message"};function dne(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 hne(e){const n=[];for(const s of e.values())s.question&&n.push({agentId:s.agentId,at:s.question.at,route:lt(s.agentId,s.question.conversationId)});return n.sort((s,r)=>s.at.localeCompare(r.at))}const L2="digest",fne=3*864e5;function v1(e){return`block:${e}`}const j1="hidden";function mne(e,n,s){if(s(L2,e.at))return!1;const r=Date.parse(e.at),a=n?Date.parse(n):Date.now();return Number.isFinite(r)&&a-r<fne}function pne(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 F2({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(ie,{name:"close"})})}const gne=6,xne=500;function vne({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:Dt(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()},xne)},onTouchEnd:u,onTouchMove:u,onTouchCancel:u,children:[t.jsx(an,{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 jne(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:Dt(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:Dt(r.agentId,"reminders")});return s.sort((r,a)=>r.at.localeCompare(a.at)).slice(0,5)}function wne(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 yne(e){return e?`Happy birthday, ${e}.`:"Happy birthday."}function bne(e,n,s){const r=wne(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 kne(e,n){try{return Er(e?new Date(e):new Date,n,{weekday:!0})}catch{return mt(e??null,n)}}function Nne({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(pe,{title:"What buddi learned this week",aside:t.jsxs("span",{className:"ui-row",children:[t.jsx("span",{className:"muted",children:Ye(e.at)}),s?t.jsx(F2,{label:"Hide until next week",onClick:s}):null]}),children:t.jsx(st,{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 Sne(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 Rj="home-needs";function Cne(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:`${Jt}/alerts`}),e.failed>0&&r.push({key:"failed",count:e.failed,label:s(e.failed,"failed job"),tone:"critical",route:`${Jt}/jobs?state=failed`}),n&&r.push({key:"paused",count:null,label:"Paused",route:`${Jt}/jobs`}),e.proposals>0&&r.push({key:"proposals",count:e.proposals,label:s(e.proposals,"proposal"),route:_e("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 Ene({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(Rj))==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 Ane(e){return e.charAt(0).toUpperCase()+e.slice(1)}function $ne({block:e,onHide:n}){const[s,r]=$b(),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(Yy,{size:"sm",shown:!a,onToggle:r}):null,t.jsx(F2,{label:`Hide ${e.title} from Home`,onClick:n})]});return t.jsxs(pe,{title:e.title,aside:i,children:[e.note?t.jsx(Q,{tone:"warning",children:e.note}):null,e.stats.length>0?t.jsx(Lm,{children:e.stats.map(l=>t.jsx(zr,{label:l.label,value:a?t.jsx(pR,{}):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(st,{flush:!0,children:t.jsx(dt,{children:e.rows.map((l,o)=>t.jsx(ot,{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 Tne="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 Ine(e){var n;try{await((n=navigator.clipboard)==null?void 0:n.writeText(e))}catch{}}function vo({text:e,disabled:n}){return t.jsxs("div",{className:"tailscale-command",children:[t.jsx("code",{className:"mono",children:e}),t.jsx(E,{size:"sm",disabled:n,onClick:()=>{Ine(e)},children:"Copy"})]})}function Rne({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 Pne={ready:t.jsx(Se,{tone:"good",children:"Ready"}),waiting:t.jsx(Se,{children:"Waiting"}),"needs-setup":t.jsx(Se,{tone:"warning",children:"Needs setup"}),unanswered:t.jsx(Se,{tone:"warning",children:"Not answering"}),off:null};function Mne(){var i,l;const e=me(()=>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(pe,{title:"Sign in from elsewhere",aside:"checked by buddi on every visit",panel:!0,flush:!0,children:[t.jsx(ae,{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(dt,{children:a.map(o=>t.jsxs(d.Fragment,{children:[t.jsx(ot,{onClick:()=>s(n===o.id?null:o.id),label:`${o.title}: ${o.status.sentence}`,lead:t.jsx(Rne,{id:o.id}),title:o.title,sub:o.status.sentence,side:t.jsxs("span",{className:"access-side",children:[Pne[o.status.state],t.jsx("span",{className:"access-chevron","data-open":n===o.id?"true":void 0,children:t.jsx(ie,{name:"chevron-right",size:14})})]})}),n===o.id?t.jsx("div",{className:"access-body",children:o.id==="tailscale"?t.jsx(One,{embedded:!0,onSaved:e.reload}):t.jsx(Fne,{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 One({embedded:e,onSaved:n}={}){var g;const s=me(()=>T.tailscale(),[]),[r,a]=d.useState(null),[i,l]=d.useState(!1),[o,c]=d.useState(null),[u,h]=d.useState(!1),f=s.data,m=r??((f==null?void 0:f.login)||((g=f==null?void 0:f.self)==null?void 0:g.login)||""),p=(f==null?void 0:f.proxied)===!0,v=k=>{l(!0),c(null),h(!1),T.setTailscale({enabled:k,login:m.trim()}).then(()=>{h(!0),n==null||n()}).catch(j=>c(j instanceof he?j.message:String(j))).finally(()=>{l(!1),s.reload()})};return t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:s.error??o}),t.jsx("p",{className:"ui-card-meta",children:f?f.available&&f.self?`Tailscale is running on this machine as ${f.self.login}.`:f.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:f!=null&&f.enabled?`On, for ${m}`:"Off"})]}):null,t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:(f==null?void 0:f.enabled)??!1,disabled:i||!f||p,onChange:k=>v(k.target.checked)}),t.jsx("span",{children:"Let this Tailscale login sign in"})]}),t.jsx(oe,{label:"Tailscale login",children:t.jsx("input",{type:"text",value:m,placeholder:"you@example.com",disabled:i||!f||p,onChange:k=>a(k.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(vo,{text:(f==null?void 0:f.serveCommand)??"tailscale serve",disabled:i||!f}),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(re,{align:"end",children:t.jsx(E,{variant:"accent",disabled:i||!f||p,onClick:()=>v((f==null?void 0:f.enabled)??!1),children:"Save"})})]})}const Dne=["teamDomain","aud","email","publicOrigin"];function Lne({onSaved:e,extra:n}={}){const s=me(()=>T.cloudflareAccess(),[]),[r,a]=d.useState(!1),[i,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(null),[f,m]=d.useState(null),[p,v]=d.useState(!1),g=s.data,k=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)??""},j=(g==null?void 0:g.proxied)===!0,x=o||!g||j,w=(A,$)=>l({...k,[A]:$}),N=[k.teamDomain.trim()===""?"the team domain":null,k.aud.trim()===""?"the AUD tag":null,k.email.trim()===""?"your email":null].filter(A=>A!==null),y=N.length>0?`To turn this on, fill in ${N.length===1?N[0]:`${N.slice(0,-1).join(", ")} and ${N[N.length-1]}`}.`:null,b=A=>{if(A&&y){a(!0);return}a(!1),c(!0),h(null),v(!1),m(null),T.setCloudflareAccess({enabled:A,...k}).then($=>{v(!0),$.test&&m($.test.ok?{ok:!0,sentence:`${$.teamDomain} answered with ${$.test.keys} signing key${$.test.keys===1?"":"s"}.${$.publicOrigin?` Open ${$.publicOrigin} from another device to finish.`:""}`}:{ok:!1,sentence:$.test.error??"Cloudflare’s signing keys could not be fetched."}),l(null),e==null||e()}).catch($=>h($ instanceof he?$.message:String($))).finally(()=>{c(!1),s.reload()})},S=()=>{c(!0),h(null),m(null),T.testCloudflareAccess({teamDomain:k.teamDomain}).then(A=>m({ok:A.ok,sentence:A.ok&&k.publicOrigin?`${A.sentence} Open ${k.publicOrigin} from another device to finish.`:A.sentence})).catch(A=>h(A instanceof he?A.message:String(A))).finally(()=>c(!1))},C=A=>g==null?void 0:g.setup.fields.find($=>$.key===A);return t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:s.error??u}),j?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:x,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(vo,{text:A.command,disabled:x}):null]},A.text))}),t.jsx("div",{className:"access-grid",children:Dne.map(A=>{const $=C(A);return t.jsx(oe,{label:($==null?void 0:$.label)??A,hint:$==null?void 0:$.hint,children:t.jsx("input",{type:A==="email"?"email":"text",className:A==="aud"?"mono":void 0,value:k[A],placeholder:$==null?void 0:$.placeholder,disabled:x,spellCheck:!1,autoComplete:"off",onChange:I=>w(A,I.target.value)})},A)})}),y&&!j&&!((g==null?void 0:g.enabled)??!1)?r?t.jsx(Q,{tone:"critical",role:"alert",children:y}):t.jsx("p",{className:"ui-card-meta",children:y}):null,f?t.jsx(Q,{tone:f.ok?"good":"critical",role:"status",children:f.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&&!f?t.jsx(Q,{tone:"good",role:"status",children:"Saved."}):null,n??null,t.jsxs(re,{align:"end",children:[t.jsx(E,{disabled:x||k.teamDomain.trim()==="",onClick:S,children:"Test my setup"}),t.jsx(E,{variant:"accent",disabled:x,onClick:()=>b((g==null?void 0:g.enabled)??!1),children:"Save"})]})]})}const w1=["running","waiting","removing"];function Fne({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),[f,m]=d.useState(!1);d.useEffect(()=>{n||T.cloudflareSetup().then(a).catch(()=>a(null))},[n]);const p=(r==null?void 0:r.progress.state)??"idle",v=w1.includes(p);d.useEffect(()=>{if(!v)return;const x=window.setInterval(()=>{T.cloudflareSetup().then(w=>{a(w),w1.includes(w.progress.state)||s==null||s()}).catch(()=>{})},1500);return()=>window.clearInterval(x)},[v,s]);const g=n?"manual":i??(p!=="idle"?"run":e||r!=null&&r.record?"manual":r?"offer":null),k=(x,w)=>{h(!0),c(null),x().then(N=>{a(N),w&&l(w),s==null||s()}).catch(N=>c(N instanceof he?N.message:String(N))).finally(()=>h(!1))},j=()=>k(()=>T.removeCloudflareSetup(),"run");if(g===null)return t.jsx("p",{className:"ui-card-meta",children:"…"});if(g==="manual"){const x=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(ae,{message:o}),t.jsx(Lne,{onSaved:s,extra:x}),r!=null&&r.record&&!n?t.jsxs(re,{align:"end",children:[t.jsx(E,{disabled:u,onClick:j,children:"Remove what buddi made"}),t.jsx(E,{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(re,{align:"end",children:[t.jsx(E,{onClick:()=>l("manual"),children:"I’ll do it myself"}),t.jsx(E,{variant:"accent",onClick:()=>l("form"),children:"Set it up for me"})]})]}):g==="form"?t.jsx(zne,{setup:r,busy:u,failed:o,onCancel:()=>{c(null),l(null)},onStart:x=>k(()=>T.startCloudflareSetup(x),"run")}):t.jsx(Une,{progress:(r==null?void 0:r.progress)??null,busy:u,failed:o,onStop:()=>k(()=>T.stopCloudflareSetup()),onRetry:()=>l("form"),onAdopt:()=>{const x=r==null?void 0:r.progress;x&&k(()=>T.startCloudflareSetup({host:x.host,email:x.email,adopt:!0}),"run")},onUseSystem:()=>{const x=r==null?void 0:r.progress;x&&k(()=>T.stopCloudflareSetup().then(()=>T.startCloudflareSetup({host:x.host,email:x.email,useSystemDaemon:!0})),"run")},onRemove:j,onAgain:()=>l("form"),tokenStored:(r==null?void 0:r.tokenStored)??!1,forgot:f,onForget:()=>k(()=>T.forgetCloudflareToken().then(x=>(m(!0),x)))})}function _ne(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 zne({setup:e,busy:n,failed:s,onCancel:r,onStart:a}){var U,W;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,f]=d.useState(!1),[m,p]=d.useState(null),[v,g]=d.useState("buddi"),[k,j]=d.useState(""),[x,w]=d.useState(i),[N,y]=d.useState(((W=e==null?void 0:e.record)==null?void 0:W.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},f(!0),p(null),T.cloudflareZones(C?{token:C}:{}).then(({zones:L})=>{var B;if(b.current.seq!==M)return;u(L);const _=_ne(i,L),Y=(B=L.find(se=>{var G;return se.name===((G=e==null?void 0:e.record)==null?void 0:G.zone)}))==null?void 0:B.name;_?(_.name&&g(_.name),j(_.zone)):j(Y??(L.length===1?L[0].name:""))}).catch(L=>{b.current.seq===M&&(u(null),p(L instanceof he?L.message:String(L)))}).finally(()=>{b.current.seq===M&&f(!1)})};d.useEffect(()=>{S&&A()},[]);const $=M=>{o(M),u(null),p(null),f(!1),b.current={token:"",seq:b.current.seq+1}},I=c!==null&&c.length>0,P=v.trim().replace(/\.+$/,""),O=I?P&&k?`${P}.${k}`:"":x.trim(),R=c!==null&&!h&&O!==""&&N.trim()!=="",D={autoComplete:"off",spellCheck:!1,disabled:n};return t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{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(re,{children:t.jsx(nt,{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(oe,{label:"API token",hint:"Kept as an owner secret, used only to set this up and to remove it.",action:t.jsx(E,{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",...D,onChange:M=>$(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(ae,{message:m}),c!==null?t.jsxs("div",{className:"access-grid",children:[I?t.jsxs(t.Fragment,{children:[t.jsx(oe,{label:"Name",hint:O?`Makes ${O}.`:"The part in front of the domain.",children:t.jsx("input",{type:"text",value:v,placeholder:"buddi",...D,onChange:M=>g(M.target.value)})}),t.jsx(oe,{label:"Domain",hint:"One of the domains the token can edit.",children:t.jsxs("select",{value:k,disabled:n,onChange:M=>j(M.target.value),children:[k===""?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(oe,{label:"Hostname",hint:"The token lists no domain; type the full name.",children:t.jsx("input",{type:"text",value:x,placeholder:"buddi.example.com",...D,onChange:M=>w(M.target.value)})}),t.jsx(oe,{label:"Your email",hint:"The one Cloudflare will let in.",children:t.jsx("input",{type:"email",value:N,placeholder:"you@example.com",...D,onChange:M=>y(M.target.value)})})]}):null,t.jsxs(re,{align:"end",children:[t.jsx(E,{disabled:n,onClick:r,children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:n||!R,onClick:()=>a({...C?{token:C}:{},host:O,email:N.trim(),...I?{zone:k}:{}}),children:"Set it up"})]})]})}const y1="To revoke it in Cloudflare: My Profile → API Tokens.";function Une({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:f}){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&&f!==void 0;return t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{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 ",Wne(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(vo,{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:y1})]}):null,e.state==="removed"&&h&&!u?t.jsxs(Q,{role:"status",children:["Forgotten here. ",y1]}):null,t.jsxs(re,{align:"end",children:[e.error&&e.state==="removed"?t.jsx(E,{disabled:n,onClick:o,children:"Remove again"}):null,p?t.jsx(E,{disabled:n,onClick:f,children:"Forget the token"}):null,t.jsx(E,{variant:"accent",disabled:n,onClick:c,children:"Set it up again"})]})]})}const m=e.state==="running"||e.state==="waiting";return t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{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,". ",Tne]}):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 v;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(ie,{name:"check",size:12}):p.state==="failed"?t.jsx(ie,{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(Bne,{connector:e.connector,live:m,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:((v=e.connector)==null?void 0:v.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(vo,{text:e.install.command}),t.jsx("span",{className:"ui-card-meta",children:e.install.note})]}):null]})]},p.id)})}),t.jsxs(re,{align:"end",children:[m?t.jsx(E,{disabled:n,onClick:r,children:"Stop waiting"}):null,e.state==="failed"||e.state==="done"||e.state==="stopped"?t.jsx(E,{disabled:n,onClick:o,children:"Remove what buddi made"}):null,e.state==="failed"&&e.adoptable?t.jsx(E,{disabled:n,onClick:a,children:"Try again"}):null,e.state==="failed"&&e.adoptable?t.jsx(E,{variant:"accent",disabled:n,onClick:i,children:"Use it anyway"}):null,e.state==="failed"&&!e.adoptable||e.state==="stopped"?t.jsx(E,{variant:"accent",disabled:n,onClick:a,children:"Try again"}):null]})]})}function Bne({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(vo,{text:e.systemDaemon.command}),n&&r?t.jsx(re,{align:"end",children:t.jsx(E,{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(vo,{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 Wne(e){return e.length<=1?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}const Hne=2e3,Kne={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 Pj(e){return Kne[e.phase]??e.detail??e.phase}const Vne=new Set(["done","failed","rolled-back"]);function _2(e){return e!==void 0&&(Vne.has(e.phase)||!!e.finishedAt)}function Gne(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(m=>{if(!u){if(n&&($I({step:Pj(m)}),(m.phase==="failed"||m.phase==="rolled-back")&&ho()),c.current){window.location.reload();return}r(m),o(null),_2(m)&&(u=!0)}}).catch(m=>{if(!u){if(m instanceof he&&m.status!==0&&m.status<500){n&&ho(),o(m.message);return}c.current=!0,n||i(!0)}})};h();const f=window.setInterval(h,Hne);return()=>{u=!0,window.clearInterval(f)}},[e,n]),{job:s,away:a,error:l}}function Yne({job:e,away:n,error:s}){return s?t.jsx(ae,{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:[Pj(e)," ",e.error??""]}):t.jsxs(Q,{tone:e.phase==="done"?"good":void 0,role:"status",children:[Pj(e),e.copyLate?" The backup was made, but the copy to your folder did not go through.":"",e.error?` ${e.error}`:""]}):null}function qne(){var x,w,N,y,b,S,C;const e=me(()=>T.backups(),[],3e4),n=T2(),s=me(()=>T.service(),[]),[r,a]=d.useState(null),[i,l]=d.useState(!1),o=Gne(r,i),[c,u]=d.useState(null),[h,f]=d.useState(!1),[m,p]=d.useState(null),v=((x=e.data)==null?void 0:x.supervised)??((w=s.data)==null?void 0:w.supervised),g=m!==null||v===!1,k=((N=e.data)==null?void 0:N.archives)??[],j=(A,$=!1)=>{f(!0),u(null),l($),A().then(I=>{var P;$&&I.job&&Am({kind:"restore",patienceMs:AI}),a(((P=I.job)==null?void 0:P.id)??null)}).catch(I=>{I instanceof he&&I.status===409?p(I.message):u(I instanceof he?I.message:String(I))}).finally(()=>{f(!1),e.reload()})};return d.useEffect(()=>{_2(o.job)&&e.reload()},[(y=o.job)==null?void 0:y.phase]),t.jsxs(ue,{gap:"lg",children:[(b=n.data)!=null&&b.active?t.jsx(Pte,{view:n.data,onLeft:n.reload}):null,t.jsx(ae,{message:e.error??c}),t.jsx(Yne,{...o}),t.jsx(Jne,{onSaved:()=>e.reload()}),t.jsx(pe,{title:"Backups",panel:!0,actions:t.jsx(E,{variant:"accent",size:"sm",disabled:h,onClick:()=>j(()=>T.startBackup(!0)),children:"Back up now"}),children:t.jsxs(ue,{divided:!0,children:[t.jsx(pe,{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(pe,{children:e.data&&k.length===0?t.jsx(os,{icon:"archive",title:"No backups yet",children:"Make one now, or turn on the nightly backup."}):e.data?t.jsxs(Zr,{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:k.map(A=>{var $;return t.jsx(Xne,{archive:A,busy:h,database:($=e.data)==null?void 0:$.database,checkout:g,onVerify:()=>j(()=>T.verifyArchive(A.name)),onRestore:(I,P)=>j(()=>T.restoreArchive({name:A.name,...I?{passphrase:I}:{},...P?{confirm:P}:{}}),!0)},A.name)})})]}):t.jsx(be,{children:"Loading…"})})]})}),t.jsx(tse,{}),t.jsx(nse,{busy:h,checkout:g,checkoutSaid:m,database:(C=e.data)==null?void 0:C.database,onRestore:(A,$,I)=>j(()=>T.restoreUpload(A,{passphrase:$,confirm:I}),!0)})]})}const Qne={enabled:!1,time:"03:00",keep:7,encryptLocal:!0,copyTo:null};function Jne({onSaved:e}){var p;const n=me(()=>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={...Qne,...s??n.data??{}};if(((p=n.data)==null?void 0:p.supervised)===!1)return t.jsx(pe,{title:"Every night",panel:!0,children:t.jsx(pe,{children:t.jsx(Q,{tone:"warning",children:n.data.error??"This installation schedules its own backups."})})});const f=v=>{u(!1),r({...h,...v})},m=()=>{i(!0),o(null),T.setBackupSchedule(h).then(v=>{r(v),u(!0),e()}).catch(v=>o(v instanceof he?v.message:String(v))).finally(()=>i(!1))};return t.jsx(pe,{title:"Every night",panel:!0,foot:t.jsx(E,{variant:"accent",disabled:a,onClick:m,children:"Save"}),children:t.jsxs(ue,{divided:!0,children:[t.jsx(pe,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:l}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:h.enabled,onChange:v=>f({enabled:v.target.checked})}),t.jsx("span",{children:"Back this buddi up on its own"})]}),t.jsxs(Ms,{children:[t.jsx(oe,{label:"At",children:t.jsx("input",{type:"time",value:h.time,onChange:v=>f({time:v.target.value})})}),t.jsx(oe,{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:v=>f({keep:Number(v.target.value)||1})})})]}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:h.encryptLocal,onChange:v=>f({encryptLocal:v.target.checked})}),t.jsx("span",{children:"Lock each one with the passphrase"})]})]})}),t.jsx(pe,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(oe,{label:"Also copy to a folder",hint:"A second disk, or a folder that syncs somewhere. Left empty, backups stay on this machine.",children:t.jsx("input",{type:"text",value:h.copyTo??"",placeholder:"/Volumes/backup/buddi",onChange:v=>f({copyTo:v.target.value===""?null:v.target.value})})}),c?t.jsxs(Q,{tone:"good",role:"status",children:["Saved.",h.lastRunAt?` Last run ${Ye(h.lastRunAt)}.`:""]}):null]})})]})})}function Xne({archive:e,busy:n,database:s,checkout:r,onVerify:a,onRestore:i}){const[l,o]=d.useState(!1),[c,u]=d.useState(""),[h,f]=d.useState("");return t.jsxs(t.Fragment,{children:[t.jsxs("tr",{children:[t.jsx("td",{className:"mono",children:e.name}),t.jsx("td",{children:Ye(e.createdAt)}),t.jsx("td",{children:_n(e.bytes)}),t.jsxs("td",{children:[e.encrypted?t.jsx(Se,{tone:"good",children:"locked"}):t.jsx(Se,{tone:"muted",children:"plain"})," ",e.envelopeOk===!1?t.jsx(Se,{tone:"critical",children:"damaged"}):null]}),t.jsx("td",{children:t.jsxs(re,{align:"end",children:[t.jsx(E,{size:"sm",disabled:n,onClick:a,children:"Verify"}),t.jsx(E,{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:z2}):t.jsx(B2,{what:`${e.name}, taken ${Ye(e.createdAt)}, ${_n(e.bytes)}`,database:s,needsPassphrase:e.encrypted,passphrase:c,onPassphrase:u,confirm:h,onConfirm:f,busy:n,onCancel:()=>o(!1),onGo:()=>i(c,h)})})}):null]})}const z2="Restoring needs the packaged installation. In a checkout, run: buddi backup restore <file>";function Zne(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 ese(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 U2({archive:e,onPassphrase:n}){const[s,r]=d.useState(null);return t.jsx(oe,{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&&ese(i).then(o=>{const c=Zne(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 B2({what:e,database:n,needsPassphrase:s,passphrase:r,onPassphrase:a,confirm:i,onConfirm:l,busy:o,onCancel:c,onGo:u}){const h=n??"",f=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(oe,{label:"The passphrase this one was locked with",children:t.jsx("input",{type:"password",autoComplete:"off",value:r,onChange:m=>a(m.target.value)})}),t.jsx(U2,{onPassphrase:a})]}):null,t.jsx(oe,{label:h?`Type ${h} to confirm`:"Type the name of this database to confirm",hint:h?void 0:"The same name buddi shows on the System tab.",children:t.jsx("input",{value:i,onChange:m=>l(m.target.value)})}),t.jsxs(re,{align:"end",children:[t.jsx(E,{variant:"ghost",onClick:c,children:"Cancel"}),t.jsx(E,{variant:"danger",disabled:o||!f||s&&r==="",onClick:u,children:"Restore"})]})]})}function tse(){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,f]=d.useState(!1),[m,p]=d.useState(""),v=()=>{i(!0),o(null),T.revealBackupPassphrase(h?m:void 0).then(k=>{n(k.passphrase),f(!1),p("")}).catch(k=>{if(k instanceof he&&k.status===403&&!h){f(!0);return}o(k instanceof he?k.message:String(k))}).finally(()=>i(!1))},g=()=>{i(!0),o(null),T.setBackupPassphrase(s.trim()).then(k=>{n(k.passphrase),r(""),u(!0)}).catch(k=>o(k instanceof he?k.message:String(k))).finally(()=>i(!1))};return t.jsx(pe,{title:"The passphrase",panel:!0,children:t.jsxs(ue,{divided:!0,children:[t.jsx(pe,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{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(re,{align:"end",children:t.jsx(E,{variant:"ghost",onClick:()=>n(null),children:"Hide"})})]}):t.jsxs(t.Fragment,{children:[h?t.jsx(oe,{label:"Your PIN",hint:"The one that unlocks this dashboard.",children:t.jsx("input",{type:"password",inputMode:"numeric",autoComplete:"off",value:m,onChange:k=>p(k.target.value),onKeyDown:k=>{k.key==="Enter"&&m!==""&&v()}})}):null,t.jsx(re,{align:"end",children:t.jsx(E,{disabled:a||h&&m==="",onClick:v,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(pe,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(oe,{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:k=>{u(!1),r(k.target.value)}})}),t.jsx(re,{align:"end",children:t.jsx(E,{variant:"accent",disabled:a||s.trim()==="",onClick:g,children:"Use this one"})})]})})]})})}function nse({busy:e,checkout:n,checkoutSaid:s,database:r,onRestore:a}){const[i,l]=d.useState(null),[o,c]=d.useState(""),[u,h]=d.useState(""),[f,m]=d.useState(!1);return n?t.jsx(pe,{title:"Restore from a file",panel:!0,children:t.jsx(pe,{children:t.jsx(Q,{tone:"warning",children:s??z2})})}):t.jsx(pe,{title:"Restore from a file",panel:!0,children:t.jsxs(ue,{divided:!0,children:[t.jsx(pe,{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(Ms,{children:[t.jsx(oe,{label:"The backup file",children:t.jsx("input",{type:"file",onChange:p=>{var v;m(!1),l(((v=p.target.files)==null?void 0:v[0])??null)}})}),t.jsx(oe,{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(U2,{archive:i.name,onPassphrase:c}):null,f?null:t.jsx(re,{align:"end",children:t.jsx(E,{variant:"accent",disabled:e||!i,onClick:()=>m(!0),children:"Restore"})})]})}),f&&i?t.jsx(pe,{children:t.jsx(B2,{what:`${i.name}, ${_n(i.size)}`,database:r,needsPassphrase:!1,passphrase:o,onPassphrase:c,confirm:u,onConfirm:h,busy:e,onCancel:()=>m(!1),onGo:()=>a(i,o,u)})}):null]})})}const Mj="gpt-5.5",b1="gpt-6.1-sol";function W2(e){return e.source!=="provider"?null:e.models.some(n=>n.id===b1)?b1:null}const H2="gemini-2.5-pro";function Xm(e){return e.replace(/^models\//,"")}const Yb=/(image|tts|audio|live|embedding|vision|robotics|transcribe)/;function K2(e){const n=e.map(Xm);let s;for(const r of n){const a=/^gemini-(\d+(?:\.\d+)*)-pro(?:-(.+))?$/.exec(r);if(!a||Yb.test(a[2]??""))continue;const i=a[1].split(".").map(Number),l=(a[2]??"")!=="";(!s||Df(i,s.version)>0||Df(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 V2(e){let n;for(const s of e.map(Xm)){const r=/^gemini-(\d+(?:\.\d+)*)-flash(?:-(.+))?$/.exec(s);if(!r||/lite/.test(r[2]??"")||Yb.test(r[2]??""))continue;const a=r[1].split(".").map(Number),i=(r[2]??"")!=="";(!n||Df(a,n.version)>0||Df(a,n.version)===0&&n.preview&&!i)&&(n={id:s,version:a,preview:i})}return n==null?void 0:n.id}function G2(e){return/^gemini-[\d.]+-pro(?:-|$)/.test(Xm(e))}function sse(e){return[...new Set(e.map(Xm).filter(n=>n.startsWith("gemini-")&&!Yb.test(n)))]}function Y2(e){return e.httpStatus===429||e.state==="rate-limited"||e.state==="quota-exhausted"}function Df(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 q2(e,n){if(!n||e.kind!=="openai-compatible")return!1;const s=r=>r.replace(/\/+$/,"");return s(e.baseUrl)===s(n)}function rse({embedded:e,account:n}={}){const{data:s,error:r,reload:a,loading:i}=me(()=>T.providerAccounts(),[]),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(""),[m,p]=d.useState(!1),[v,g]=d.useState(!1),[k,j]=d.useState(n??null);d.useEffect(()=>{n&&j(n)},[n]);const x=s==null?void 0:s.accounts.some(S=>{var C;return((C=S.login)==null?void 0:C.state)==="pending"&&S.login.expiresAt&&Date.parse(S.login.expiresAt)>Date.now()});d.useEffect(()=>{if(!x)return;const S=setInterval(a,2e3);return()=>clearInterval(S)},[x,a]);const w=async(S,C)=>{o(!0),u(null),f(""),g(!1);try{const A=await S();return f((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)}},N=(s==null?void 0:s.accounts)??[],y=N.find(S=>S.id===k)??N[0],b=S=>{var C;return q2(S,(C=s==null?void 0:s.gemini)==null?void 0:C.baseUrl)?"Gemini":Q2(S)};return t.jsxs(Ns,{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(ae,{message:r??c}),h&&t.jsx(Q,{tone:"good",role:"status",children:h}),v&&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(be,{children:"Loading accounts…"}),r&&t.jsx(re,{children:t.jsx(E,{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."}),m&&t.jsx(Je,{title:"Add an account",onClose:()=>p(!1),children:t.jsx("div",{id:"new-provider-account",children:t.jsx(pse,{accounts:N,codexEnabled:s.codexEnabled,anthropicOAuthEnabled:s.anthropicOAuthEnabled,gemini:s.gemini,busy:l,run:w,onDone:S=>{p(!1),S&&j(S)}})})}),t.jsx(pe,{title:"Accounts",aside:`Secrets live in the ${ase(s.vault.kind)}; Postgres holds names and assignments only.`,actions:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",size:"sm",disabled:l||i,onClick:()=>{u(null),f(""),g(!0),a()},children:i?"Refreshing…":"Refresh status"}),t.jsx(E,{variant:"accent",size:"sm",disabled:l,"aria-expanded":m,"aria-controls":"new-provider-account",onClick:()=>p(!m),children:"Add account"})]}),panel:!0,flush:!0,children:N.length===0?t.jsx(os,{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:N.map(S=>t.jsxs("button",{type:"button",className:"accounts-row","aria-pressed":(y==null?void 0:y.id)===S.id,onClick:()=>j(S.id),children:[t.jsx(ise,{kind:S.kind,auth:S.auth}),t.jsxs("span",{className:"accounts-row-text",children:[t.jsx("span",{className:"accounts-row-name",children:S.label}),Ru(S)?t.jsxs("span",{className:"accounts-row-sub","data-tone":"warning",children:[b(S)," · back at ",qb(Ru(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(X2,{account:S})]},S.id))}),y?t.jsx(hse,{account:y,provider:b(y),anthropicOAuthEnabled:s.anthropicOAuthEnabled,busy:l,run:w},`${y.id}:${y.revision}`):null]})})]})]})}function ase(e){return e==="keychain"?"macOS Keychain":e==="file"?"encrypted file vault":e==="none"?"vault (none configured)":e}function Q2(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":Bb(e)?"mlxh":"OpenAI-compatible"}function J2(e){return e.detectedContextWindowSource==="mlxh"?yee(e.detectedContextWindowTokens):e.detectedContextWindowSource!=="provider"?"assumed":e.kind==="codex"?"from ChatGPT":"from the provider"}function ise({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 lse(e){return e==="connected"?"good":["rate-limited","quota-exhausted","provider-unavailable"].includes(e)?"warning":"critical"}function Ru(e,n=Date.now()){const s=e.rateLimit;return e.enabled&&e.configured&&s&&Date.parse(s.until)>n?s:null}const ose=()=>Intl.DateTimeFormat().resolvedOptions().timeZone;function qb(e,n=new Date,s=ose()){const r=new Date(e),a=i=>i.toLocaleDateString("en-CA",{timeZone:s});return a(r)===a(n)?Tt(r,s):a(r)===a(new Date(n.getTime()+864e5))?`tomorrow at ${Tt(r,s)}`:vm(r,s)}function X2({account:e,long:n}){const s=Ru(e);if(s){const i=`Rate-limited until ${qb(s.until)}`;return t.jsx("span",{title:i,children:t.jsx(Se,{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(Se,{tone:r,children:a})}function cse({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(E,{variant:"ghost",size:"sm",onClick:r,"aria-label":"Copy the id of this account",children:n?"Copied":"Copy"})]})}function use({account:e,provider:n,children:s}){const r=Ru(e);if(!r)return null;const a=r.provider??n,i=qb(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(nt,{size:"sm",href:l.length===1?Dt(l[0],"setup","brain"):bt,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 k1({test:e}){return e.state==="connected"?null:t.jsx(Gt,{summary:"Details",children:t.jsx(Vt,{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 dse({account:e,provider:n}){const s=e.test;return Ru(e)&&(!s||["rate-limited","quota-exhausted","connected"].includes(s.state))?t.jsx(use,{account:e,provider:n,children:s&&t.jsx(k1,{test:s})}):s?t.jsxs(Q,{role:"status",tone:lse(s.state),children:[t.jsx("p",{children:s.message}),t.jsx(k1,{test:s})]}):null}function Qb(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 hse({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(X2,{account:e,long:!0})]}),t.jsx(Vt,{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?"":` (${J2(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:Dt(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:bt,children:"Assign to an agent"})]})},...e.tokenExpiresAt?[{label:"Access token",value:`expires ${mt(e.tokenExpiresAt,Intl.DateTimeFormat().resolvedOptions().timeZone)} (not your subscription renewal date)`}]:[],{label:"ID",value:t.jsx(cse,{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(tO,{account:e,enabled:!!a,busy:s,run:r}),e.kind==="codex"&&t.jsx(Z2,{account:e,busy:s,run:r}),e.auth==="device-key"&&t.jsx(eO,{account:e,busy:s,run:r}),t.jsxs(re,{children:[t.jsx(E,{disabled:s||e.removalPending,onClick:()=>l(!0),children:"Edit account"}),t.jsx(E,{disabled:s||e.removalPending,onClick:()=>void r(()=>T.saveProviderAccount({...Qb(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(E,{disabled:s||!e.enabled||!e.configured,onClick:()=>void r(async()=>(await T.testProviderAccount(e.id),{warning:""}),""),children:"Test connection"}),t.jsx(E,{variant:"danger",disabled:s||e.assignedAgents.length>0,title:e.assignedAgents.length?"Reassign its agents before removing this account":void 0,onClick:()=>c(!0),children:"Remove account"})]}),t.jsx(dse,{account:e,provider:n}),i&&t.jsx(Je,{title:`Edit ${e.label}`,onClose:()=>l(!1),children:t.jsx(fse,{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(re,{children:[t.jsx(E,{variant:"danger",disabled:s,onClick:()=>void r(()=>T.removeProviderAccount(e.id,e.revision),"Account removed from Buddi."),children:"Confirm removal"}),t.jsx(E,{disabled:s,onClick:()=>c(!1),children:"Cancel"})]})]}),t.jsx(Gt,{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 Z2({account:e,busy:n,run:s}){var r,a,i;return t.jsxs(t.Fragment,{children:[t.jsxs(re,{children:[t.jsx(E,{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(E,{disabled:n,onClick:()=>void s(()=>T.codexAccountAction(e.id,"cancel-login",e.revision),"Sign-in cancelled."),children:"Cancel sign-in"}),t.jsx(E,{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(Hb,{code:e.login.userCode,large:!0}),e.login.verificationUrl&&t.jsx(re,{children:t.jsx(nt,{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 ",Tt(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 fse({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,f]=d.useState((e==null?void 0:e.auth)??"api-key"),[m,p]=d.useState((e==null?void 0:e.baseUrl)??""),[v,g]=d.useState((e==null?void 0:e.defaultModel)??"claude-sonnet-5"),[k,j]=d.useState(""),[x,w]=d.useState(e!=null&&e.contextWindowTokens?String(e.contextWindowTokens):""),N=b=>{u(b),f(b==="codex"?"chatgpt":"api-key"),j(""),p(b==="openai-compatible"?"http://localhost:11434/v1":""),g(b==="anthropic"?"claude-sonnet-5":b==="openai"?"gpt-5":"")},y=!l.trim()||!v.trim();return t.jsxs("form",{className:"ui-stack",onSubmit:b=>{b.preventDefault();const S=k;j(""),s(()=>T.saveProviderAccount({...e?{id:e.id,revision:e.revision}:{},label:l,kind:c,auth:h,baseUrl:m,defaultModel:v,enabled:(e==null?void 0:e.enabled)??!0,contextWindowTokens:x.trim()?Number(x):null,...S.trim()?{secret:S}:{}}),"Account saved. Agent model selections are unchanged.").then(C=>{C&&r()})},children:[t.jsxs("fieldset",{disabled:n,className:"ui-fields","data-stack":"true",children:[t.jsx(oe,{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(oe,{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"?(N("anthropic"),f("anthropic-oauth")):N(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(oe,{label:"API base URL",hint:"Include the API path, such as /v1 or /api/v1. Conversation data will be sent to this endpoint. The model must support tool calling to use agent tools.",children:t.jsx("input",{required:!0,type:"url",value:m,onChange:b=>p(b.target.value)})}),t.jsx(oe,{label:"Authentication",children:t.jsxs("select",{disabled:!!e,value:h,onChange:b=>{f(b.target.value),j("")},children:[t.jsx("option",{value:"api-key",children:"API key"}),t.jsx("option",{value:"none",children:"No key (local/self-hosted)"})]})})]}),t.jsx(re,{valign:"end",children:t.jsx(Wb,{accountId:e!=null&&e.configured&&e.enabled?e.id:void 0,label:"Default model",value:v,onChange:g,disabled:n,...(e==null?void 0:e.kind)==="codex"?{origin:"from ChatGPT",suggest:W2}:{}},`${e==null?void 0:e.id}:${e==null?void 0:e.revision}`)}),t.jsx(oe,{label:"Context window",hint:Bb(e)?"mlxh refuses a prompt over its max_prompt_tokens, and its model manager does not report the number, so buddi assumes 8,192. After `mlxh config max_prompt_tokens 40960`, enter the same number here.":"Tokens this endpoint actually serves. Leave blank unless you run the model yourself and set a window of your own — a conversation is ended once its history would fill half of this.",children:t.jsx("input",{type:"number",inputMode:"numeric",min:8e3,max:2e6,step:1e3,value:x,placeholder:e!=null&&e.detectedContextWindowTokens?`${e.detectedContextWindowTokens} (${J2(e)})`:"assumed from the model",onChange:b=>w(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(oe,{label:e?"Replacement API key (leave blank to keep)":"API key",children:t.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,value:k,onChange:b=>j(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(re,{align:"end",children:[t.jsx(E,{onClick:r,children:"Cancel"}),t.jsx(E,{type:"submit",variant:"accent",disabled:y,children:"Save account"})]})]}),y&&t.jsx("p",{className:"muted",children:"Enter an account name and default model to enable Save account. The example name is a placeholder."})]})}function eO({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(f=>{c||f.state==="waiting"||(c=!0,f.state==="connected"?a.current(async()=>{},`Connected as ${f.username}, device ${f.deviceName}.`):a.current(async()=>{throw new Error(f.message)},""))}).catch(()=>{}).finally(()=>{u=!1}))},2e3);return()=>{c=!0,clearInterval(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(re,{children:[t.jsx(E,{disabled:n||!e.enabled||e.removalPending||!!r,onClick:i,children:e.configured?"Reconnect Ollama":"Connect Ollama"}),t.jsx(E,{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&&Tt(new Date(r.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone),"."]})]})]})}function tO({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(re,{children:[t.jsx(E,{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(E,{disabled:s,onClick:()=>{i(""),r(()=>T.anthropicAccountAction(e.id,"cancel-login",e.revision),"Claude sign-in cancelled.")},children:"Cancel sign-in"}),t.jsx(E,{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:f=>{f.preventDefault();const m=a;i(""),r(()=>T.anthropicAccountAction(e.id,"complete-login",e.revision,{attemptId:e.login.attemptId,code:m}),"Claude connected. Edit account to load its model list, then assign it to an agent.")},children:[t.jsx("p",{children:t.jsx("a",{href:e.login.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open Claude consent page"})}),t.jsxs("p",{className:"muted",children:["Use the Claude account you want to connect. Paste the entire code including #state. This attempt expires at ",e.login.expiresAt&&Tt(new Date(e.login.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone),"; restarting Buddi also ends it."]}),t.jsx(oe,{label:"Claude authorization code",children:t.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,maxLength:8192,value:a,onChange:f=>i(f.target.value),disabled:s})}),t.jsx(re,{align:"end",children:t.jsx(E,{type:"submit",variant:"accent",disabled:s||!a.trim(),children:"Complete Claude sign-in"})})]})]})}const Dg={anthropic:"claude-sonnet-5",openai:"gpt-5",codex:Mj};function Lg(e,n,s){return Oj(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 Oj(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 mse="That key was refused. Check it and paste it again.";function pse({accounts:e,busy:n,run:s,onDone:r,codexEnabled:a,anthropicOAuthEnabled:i,gemini:l}){const o=e.map(Z=>Z.label),[c,u]=d.useState(null),[h,f]=d.useState("anthropic"),[m,p]=d.useState("api-key"),[v,g]=d.useState(()=>Lg("anthropic","api-key",o)),[k,j]=d.useState(!1),[x,w]=d.useState(""),[N,y]=d.useState(""),[b,S]=d.useState(null),[C,A]=d.useState(!1),[$,I]=d.useState(""),[P,O]=d.useState(""),[R,D]=d.useState(!1),[U,W]=d.useState(!1),[M,L]=d.useState(!1),[_,Y]=d.useState(void 0),B=(Z,ye,Ce=!1)=>{f(Z),p(ye),y(""),S(null),I(""),O(""),D(!1),W(Ce),L(!1),Y(void 0),w(Ce?"":Z==="openai-compatible"?"http://localhost:11434/v1":""),k||g(Ce?Lg(Z,"device-key",o):Lg(Z,ye,o))},se=Z=>{B("openai-compatible",Z?"api-key":"device-key",!0),Z&&T.ollama().then(ye=>w(ye.cloudBaseUrl)).catch(()=>{})},G=()=>{l&&(B("openai-compatible","api-key"),L(!0),w(l.baseUrl),k||g(Oj("Gemini",o)))},X=()=>{B("openai-compatible","none"),Y(null),k||g(Oj("mlxh",o)),T.mlxh().then(Z=>{Y(Z),w(Z.baseUrl)}).catch(()=>Y(void 0))},K=_!==void 0,J=c?e.find(Z=>Z.id===c):void 0;if(c)return J?t.jsx(gse,{account:J,busy:n,run:s,anthropicOAuthEnabled:i,onDone:()=>r(J.id)}):t.jsx(be,{children:"Saving…"});const q=h==="openai-compatible"&&m!=="device-key",ce=h==="codex"||m==="anthropic-oauth"||m==="device-key",xe=!ce&&(m==="none"||N.trim()!=="")&&(!q||x.trim()!==""),Me=async()=>{var Z,ye;A(!0),I("");try{const Ce=await T.probeModels({kind:h,auth:m,...q?{baseUrl:x}:{},...N.trim()?{secret:N}:{}});S(Ce),P||O(((Z=Ce.models.find(ke=>ke.isDefault))==null?void 0:Z.id)??((ye=Ce.models[0])==null?void 0:ye.id)??"")}catch(Ce){I(Ce instanceof Error?Ce.message:"Could not load models. You can still enter a custom model.")}finally{A(!1)}},H=P.trim(),ne=!v.trim()||q&&!x.trim()||q&&!M&&!K&&!H||M&&!N.trim()||K&&!(_!=null&&_.running);return t.jsxs("form",{className:"ui-stack",onSubmit:Z=>{var we;Z.preventDefault();const ye=N;y("");let Ce=H||(K?Ej(_)??((we=_==null?void 0:_.models[0])==null?void 0:we.id):void 0)||(m==="device-key"?ph:Dg[h])||"claude-sonnet-5",ke;(async()=>{if(M){Ce=H2;try{const Ee=(await T.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:x,secret:ye})).models.map(ze=>ze.id);Ce=K2(Ee)??Ce,ke=G2(Ce)?V2(Ee):void 0}catch{}}let ve,Ie=!1;!await s(async()=>{if(ve=await T.saveProviderAccount({label:v,kind:h,auth:m,baseUrl:x,defaultModel:Ce,enabled:!0,...ye.trim()?{secret:ye}:{}}),m!=="api-key")return ve;const de=await T.testProviderAccount(ve.id);if(de.state==="connected")return{...ve,warning:`Account saved. ${de.message}`};if(oy(de)){const Ee=ve.id;ve=void 0;try{const ze=(await T.providerAccounts()).accounts.find(qe=>qe.id===Ee);ze&&await T.removeProviderAccount(Ee,ze.revision)}catch{}throw new Error(mse)}if(M&&ke&&Y2(de)){const Ee=(await T.providerAccounts()).accounts.find(ze=>ze.id===ve.id);if(Ee&&(await T.saveProviderAccount({...Qb(Ee),defaultModel:ke}),(await T.testProviderAccount(ve.id)).state==="connected"))return{...ve,warning:`Account saved on ${ke}. 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 Ie=!0,{...ve,warning:`Account saved. ${de.message}`}},"Account saved.")||!ve||(M||K||Ie?u(ve.id):H||!ce?r(ve.id):u(ve.id))})()},children:[t.jsxs("fieldset",{disabled:n,className:"ui-fields","data-stack":"true",children:[t.jsx(oe,{label:"Provider",children:t.jsxs("select",{value:m==="anthropic-oauth"?"anthropic-oauth":U?"ollama-cloud":M?"gemini":K?"mlxh":h,onChange:Z=>{if(Z.target.value==="anthropic-oauth")B("anthropic","anthropic-oauth");else if(Z.target.value==="gemini")G();else if(Z.target.value==="mlxh")X();else if(Z.target.value==="ollama-cloud")B("openai-compatible","device-key",!0);else{const ye=Z.target.value;B(ye,ye==="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(oe,{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:v,onChange:Z=>{g(Z.target.value),j(!0)},placeholder:"Anthropic — Personal"})}),U&&t.jsxs("label",{className:"ui-row",children:[t.jsx("input",{type:"checkbox",checked:m==="api-key",onChange:Z=>se(Z.target.checked)}),t.jsx("span",{children:"Use a key instead"})]}),q&&t.jsxs(t.Fragment,{children:[t.jsx(oe,{label:"API base URL",hint:"Include the API path, such as /v1 or /api/v1. Conversation data will be sent to this endpoint. The model must support tool calling to use agent tools.",children:t.jsx("input",{required:!0,type:"url",value:x,onChange:Z=>{w(Z.target.value),S(null)}})}),!M&&!K&&t.jsx(oe,{label:"Authentication",children:t.jsxs("select",{value:m,onChange:Z=>{p(Z.target.value),y(""),S(null)},children:[t.jsx("option",{value:"api-key",children:"API key"}),t.jsx("option",{value:"none",children:"No key (local/self-hosted)"})]})})]}),m==="api-key"&&t.jsx(oe,{label:"API key",hint:"Stored in the vault, never shown again.",children:t.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,value:N,onChange:Z=>{y(Z.target.value),S(null)}})}),K?_===null?t.jsx("p",{className:"muted",children:"Looking for mlxh on this computer…"}):_!=null&&_.running?t.jsxs(ue,{gap:"sm",children:[t.jsxs("p",{className:"muted",children:["mlxh answers with ",_.models.length===1?"one model":`${_.models.length} models`,". No key: mlxh takes any. buddi starts on ",Ej(_)??"the first","; the next step lists the rest. A model that is not loaded takes up to a minute on its first answer."]}),_.models.some(Z=>Z.kind==="image")?t.jsxs("p",{className:"muted",children:[_.models.filter(Z=>Z.kind==="image").map(Z=>Z.id).join(", "),": ",p2,"."]}):null]}):t.jsx(Q,{tone:"warning",children:m2((_==null?void 0:_.baseUrl)??x)}):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."]}):ce?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.":m==="device-key"?"You will connect on the next step: ollama.com opens, you press Connect, and no key is typed. Free to start.":"You will connect your Claude subscription on the next step, in your browser, and pick a model then."}):t.jsxs("div",{className:"ui-field",children:[t.jsx("span",{className:"ui-field-label",children:"Model"}),b?t.jsxs("div",{className:"ui-row",children:[t.jsxs("select",{"aria-label":"Model",value:R?"__custom__":P,onChange:Z=>{Z.target.value==="__custom__"?(D(!0),O("")):(D(!1),O(Z.target.value))},children:[b.models.map(Z=>t.jsxs("option",{value:Z.id,children:[Z.name===Z.id?Z.id:`${Z.name} — ${Z.id}`,Z.isDefault?" (provider default)":"",Z.thinks?" · thinks":""]},Z.id)),t.jsx("option",{value:"__custom__",children:"Custom model…"})]}),t.jsx(E,{size:"sm",disabled:C||!xe,onClick:()=>void Me(),children:C?"Loading…":"Reload"})]}):t.jsxs("div",{className:"ui-row",children:[t.jsx(E,{disabled:C||!xe,onClick:()=>void Me(),children:C?"Loading models…":"Load models"}),q?t.jsx("span",{className:"muted",children:"Ask the endpoint what it serves."}):t.jsxs("span",{className:"muted",children:["Optional now: ",Dg[h]," is used until you pick one."]})]}),R||q&&!b?t.jsx("input",{"aria-label":"Custom model",required:q,maxLength:150,value:P,onChange:Z=>O(Z.target.value),placeholder:q?"qwen3:8b":Dg[h]}):null,$?t.jsx("span",{className:"ui-field-hint critical",role:"alert",children:$}):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(re,{align:"end",children:[t.jsx(E,{onClick:()=>r(),children:"Cancel"}),t.jsx(E,{type:"submit",variant:"accent",disabled:ne,children:"Save account"})]})]}),ne&&!K&&t.jsxs("p",{className:"muted",children:["Enter an account name",M?" and a key":q?", an endpoint and a model":""," to enable Save account."]})]})}function gse({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(tO,{account:e,enabled:!!r,busy:n,run:s}):null,e.kind==="codex"&&!o?t.jsx(Z2,{account:e,busy:n,run:s}):null,e.auth==="device-key"&&!o?t.jsx(eO,{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(re,{valign:"end",children:t.jsx(Wb,{accountId:e.enabled?e.id:void 0,label:"Default model",value:i,onChange:l,disabled:n,...e.kind==="codex"?{origin:"from ChatGPT",suggest:W2,onSuggest:c=>l(u=>u===Mj&&e.defaultModel===Mj?c:u)}:{}},`${e.id}:${e.revision}`)}),t.jsxs(re,{align:"end",children:[t.jsx(E,{onClick:a,children:"Skip for now"}),t.jsx(E,{variant:"accent",disabled:n||!i.trim(),onClick:()=>{if(i===e.defaultModel){a();return}s(()=>T.saveProviderAccount({...Qb(e),defaultModel:i}),"Default model saved.").then(c=>{c&&a()})},children:"Done"})]})]}):t.jsx(re,{children:t.jsx(E,{onClick:a,children:"Finish later"})})]})}async function nl(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 nO="Passwords, keys and links your agents use without ever seeing them. Each goes only where you allow.";function xse(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 vse({embedded:e,timezone:n,secret:s,adding:r,navigate:a}={}){const i=me(()=>T.secrets(),[]),l=me(()=>T.providerAccounts(),[]),o=d.useMemo(()=>{var v;return new Map((((v=l.data)==null?void 0:v.accounts)??[]).map(g=>[g.id,{label:g.label,provider:Q2(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(_e("secrets"))},f=i.data,m=d.useMemo(()=>{const v=new Map;for(const g of(f==null?void 0:f.secrets)??[]){const k=Sa(g);v.set(k,[...v.get(k)??[],g])}return[...v.entries()].sort(([g],[k])=>yG(g,k))},[f]),p=c&&c.what!=="add"?(f==null?void 0:f.secrets.find(v=>v.name===c.name))??null:null;return t.jsxs(Ns,{embedded:e,title:"Keys and secrets",lede:nO,actions:e?void 0:t.jsx(E,{variant:"accent",size:"sm",onClick:()=>u({what:"add"}),children:"Add a secret"}),children:[t.jsxs(ue,{gap:"lg",children:[!f&&!i.error?t.jsx(be,{children:"Opening the vault…"}):null,i.error?t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:i.error}),t.jsx(re,{children:t.jsx(E,{onClick:i.reload,children:"Retry"})})]}):null,f&&f.secrets.length===0?t.jsx(st,{children:t.jsx(os,{icon:"lock",title:"Nothing stored yet.",children:"Add a site password or an API token, and say where an agent may use it. Mailbox passwords and calendar links show up here as you add them."})}):null,f&&f.secrets.length>0?t.jsx(st,{flush:!0,children:m.map(([v,g])=>{const k=wG(v);return t.jsxs("section",{className:"secrets-group","aria-label":k.title,children:[t.jsxs("header",{className:"secrets-group-head",children:[t.jsx("h3",{className:"secrets-group-title",children:k.title}),t.jsx("span",{className:"secrets-group-aside",children:k.aside})]}),t.jsx(dt,{children:g.map(j=>t.jsx(wse,{secret:j,group:v,accounts:o,timezone:n,onOpen:x=>u({what:x,name:j.name})},j.name))})]},v)})}):null,f&&f.ownKeys.length>0?t.jsx(Gt,{summary:`buddi’s own keys · ${f.ownKeys.length}`,children:t.jsxs("p",{className:"secrets-note",children:["The keys buddi itself runs on, read from its environment:"," ",f.ownKeys.map((v,g)=>t.jsxs("span",{children:[g>0?", ":"",t.jsx("code",{className:"mono",children:v})]},v)),". They aren’t changed here, and buddi hides them in whatever it sends out, like your own."]})}):null]}),(c==null?void 0:c.what)==="add"&&f?t.jsx(kse,{destinations:f.destinations,onClose:h,onChanged:i.reload}):null,p&&(c==null?void 0:c.what)==="sheet"?t.jsx(yse,{secret:p,accounts:o,timezone:n,onClose:h,onOpen:v=>u({what:v,name:p.name})}):null,p&&(c==null?void 0:c.what)==="replace"?t.jsx(Nse,{secret:p,title:_c(p,o),onClose:h,onChanged:i.reload}):null,p&&(c==null?void 0:c.what)==="rename"?t.jsx(Sse,{secret:p,onClose:h,onChanged:i.reload}):null,p&&(c==null?void 0:c.what)==="places"&&f?t.jsx(Cse,{secret:p,title:_c(p,o),destinations:f.destinations,onClose:h,onChanged:i.reload}):null,p&&(c==null?void 0:c.what)==="delete"?t.jsx(Ese,{secret:p,title:_c(p,o),onClose:h,onChanged:i.reload}):null]})}const Lf=e=>n=>{n.stopPropagation(),e==null||e()};function sO({fix:e,onOpen:n}){return"href"in e?t.jsx(nt,{size:"sm",href:e.href,onClick:Lf(),children:e.label}):t.jsx(E,{size:"sm",onClick:Lf(()=>n(e.action)),children:e.label})}function jse(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=Zv(r.id)}}:null,{label:"Usage history",onSelect:()=>s("sheet")},Wl(e)?"separator":null,Wl(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")},Wl(e)?"separator":null,Wl(e)?{label:"Remove…",tone:"critical",onSelect:()=>s("delete")}:null]}function wse({secret:e,group:n,accounts:s,timezone:r,onOpen:a}){const i=_c(e,s),l=NG(e,s),o=kG(e,r),c=[o??mb(e),o&&!e.lastUse?null:AG(e)].filter(Boolean).join(" · "),u=gP(e),h=xP(e),f=ej(e),m=dP(n)?mP(e):null;return t.jsx(ot,{onClick:()=>a("sheet"),label:`${i}: details`,lead:t.jsx(Qn,{icon:xse(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,f?t.jsx("span",{className:"secrets-status",children:f}):null]}),side:t.jsxs("span",{className:"secrets-side",children:[u!=null&&u.fix?t.jsx(sO,{fix:u.fix,onOpen:a}):null,h&&Wl(e)||e.login&&n==="mine"?t.jsx(E,{size:"sm",variant:"ghost",onClick:Lf(()=>a("delete")),children:"Remove…"}):null,m?t.jsxs("a",{className:"secrets-managed",href:m.href,onClick:Lf(),children:[m.label,t.jsx(ie,{name:"chevron-right",size:12})]}):t.jsx(Jn,{label:`More for ${i}`,items:jse(e,n,a),sheet:{title:i,sub:c}})]})})}function yse({secret:e,accounts:n,timezone:s,onClose:r,onOpen:a}){const i=Sa(e),l=_c(e,n),o=gP(e),c=xP(e),u=[...new Set(e.bindings.map(m=>m.rule))],h=e.lastUse,f=(e.usedBy??[]).map(m=>({label:m.kind==="mailbox"?"Mailbox":m.kind==="model-account"?"Model account":"Connection",value:t.jsx("code",{className:"mono secrets-mono",children:m.id})}));return t.jsx(Je,{title:l,onClose:r,foot:i==="mine"?t.jsxs(re,{children:[t.jsx(E,{variant:"danger-ghost",onClick:()=>a("delete"),children:"Delete…"}),t.jsx(pt,{}),t.jsx(E,{onClick:()=>a("rename"),children:"Rename…"}),t.jsx(E,{variant:"accent",onClick:()=>a("replace"),children:"Replace value…"})]}):void 0,children:t.jsxs(ue,{gap:"lg",children:[t.jsx(Vt,{items:[{label:"Where it may go",value:mb(e)||"Nowhere yet"},...u.length===1&&i==="mine"?[{label:"Asks you",value:TG[u[0]]}]:[],{label:"Last used",value:h?`${Ye(h.at)}${h.agentId?` by ${h.agentId}`:""}`:"Never"}]}),o?t.jsx(Q,{tone:"warning",action:o.fix?t.jsx(sO,{fix:o.fix,onOpen:a}):void 0,children:o.text}):null,c?Wl(e)?t.jsxs(Q,{action:t.jsx(E,{size:"sm",onClick:()=>a("delete"),children:"Remove…"}),children:[c," Nothing removes it but you."]}):t.jsx(Q,{children:c}):null,ej(e)?t.jsx(Q,{children:ej(e)}):null,t.jsxs(ue,{gap:"sm",children:[t.jsx("h3",{className:"secrets-sheet-head",children:"Usage history"}),t.jsx(bse,{name:e.name,timezone:s})]}),t.jsx(Gt,{summary:"Details",children:t.jsxs(ue,{gap:"sm",children:[t.jsx(Vt,{items:[{label:"Stored as",value:t.jsx("code",{className:"mono secrets-mono",children:e.name})},...e.bindings.map((m,p)=>({key:`b${p}`,label:p===0?"Bindings":"",value:t.jsxs("code",{className:"mono secrets-mono",children:[m.kind," ",lP(m.kind,m.target)," · ",m.rule]})})),...e.totp?[{label:"One-time code",value:"buddi fills the current code, never the seed"}]:[],...f]}),t.jsx("p",{className:"secrets-note",children:"What buddi keeps for it, never the value. “Held back” means buddi declined to hand the value over — not bound to that place, no value stored, or the vault locked — so it never left."})]})})]})})}function bse({name:e,timezone:n}){const s=me(()=>T.secretUses(e,50),[e]);if(s.error)return t.jsx(ae,{message:s.error});if(!s.data)return t.jsx(be,{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(dt,{children:r.map((a,i)=>{const l=MG(a);return t.jsx(ot,{title:t.jsx("span",{className:"secrets-history","data-tone":l.tone,children:l.text}),sub:`${mt(a.at,n??"UTC")} · ${a.agent??(a.plugin?`the ${a.plugin} plugin`:"you")}`},i)})})}function rO({title:e,result:n,scrubbed:s,busy:r,failure:a,onScrub:i}){const l=gG(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(ae,{message:a}),l?t.jsx(re,{children:t.jsx(E,{variant:"accent",disabled:r||s!==null,onClick:i,children:s===null?"Scrub the history":xG(s)||"Nothing of it was left to replace."})}):null]})}function aO({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(oe,{label:"Kind of place",children:t.jsx("select",{value:i.kind,disabled:s,onChange:h=>{var p;const f=h.target.value,m=(p=e.find(v=>v.kind===f))==null?void 0:p.maxRule;a(l,{kind:f,rule:m?bf(m):i.rule})},children:u.map(h=>t.jsx("option",{value:h.kind,children:IG(h.kind)},h.kind))})}),t.jsx(oe,{label:"The place",children:t.jsx("input",{type:"text",spellCheck:!1,disabled:s,value:i.target,placeholder:PG(i.kind),onChange:h=>a(l,{target:h.target.value})})}),t.jsx(oe,{label:"Asks you",children:t.jsx("select",{value:i.rule,disabled:s,onChange:h=>a(l,{rule:h.target.value}),children:aP(c).map(h=>t.jsx("option",{value:h,children:RG[h]},h))})}),t.jsx(E,{size:"sm",variant:"ghost",disabled:s,onClick:()=>r(n.filter((h,f)=>f!==l)),children:"Remove"}),t.jsxs("p",{className:"ui-field-hint secrets-place-hint",children:["The place: ",uG(i.kind),"."]})]},l)}),n.length===0?t.jsx("p",{className:"ui-field-hint",children:cG}):null,e.length?t.jsx(re,{children:t.jsx(E,{size:"sm",disabled:s,onClick:()=>r([...n,{kind:e[0].kind,target:"",rule:bf(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 iO(e){const n=e.map(r=>mG(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 kse({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:bf(e[0].maxRule)}]:[]),[f,m]=d.useState(!1),[p,v]=d.useState(null),[g,k]=d.useState(null),[j,x]=d.useState(null),w=async()=>{const y=iO(u);if(!y.ok){v(y.error);return}const b=i;l("");const S=await nl("secrets.put",{name:r.trim(),value:b,totp:o,bindings:y.bindings},m,v);S!==null&&(k({name:r.trim(),result:S}),s())},N=async()=>{const y=await nl("secrets.scrub_history",{name:(g==null?void 0:g.name)??""},m,v);y!==null&&(x(y),s())};return g?t.jsx(Je,{title:"Add a secret",onClose:n,foot:t.jsx(re,{align:"end",children:t.jsx(E,{onClick:n,children:"Done"})}),children:t.jsx(rO,{title:g.name,result:g.result,scrubbed:j,busy:f,failure:p,onScrub:()=>void N()})}):t.jsx(Je,{title:"Add a secret",size:"wide",onClose:n,foot:t.jsxs(re,{align:"end",children:[t.jsx(E,{onClick:n,children:"Cancel"}),t.jsx(E,{type:"submit",form:"secrets-add",variant:"accent",disabled:f,children:"Save secret"})]}),children:t.jsxs("form",{id:"secrets-add",className:"ui-stack","data-gap":"lg",onSubmit:y=>{y.preventDefault(),w()},children:[t.jsxs("fieldset",{disabled:f,className:"ui-stack","data-gap":"sm",children:[t.jsx(oe,{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:y=>a(y.target.value),placeholder:"PNC password"})}),t.jsx(oe,{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:y=>l(y.target.value)})}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:o,onChange:y=>c(y.target.checked)}),t.jsx("span",{children:"It’s a one-time-code seed — buddi fills the current code, never the seed"})]})]}),t.jsxs("fieldset",{disabled:f,className:"ui-stack","data-gap":"sm",children:[t.jsx("h3",{className:"secrets-sheet-head",children:"Where it may go"}),t.jsx("p",{className:"secrets-note",children:"Agents can use it only in these places. Anywhere else, buddi holds it back and the row says so."}),t.jsx(aO,{destinations:e,bindings:u,disabled:f,onChange:h})]}),p?t.jsx(Q,{tone:"critical",role:"alert",children:p}):null]})})}function Nse({secret:e,title:n,onClose:s,onChanged:r}){const[a,i]=d.useState(""),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(null),v=async()=>{const k=a;i("");const j=await nl("secrets.put",{name:e.name,value:k,totp:e.totp,bindings:e.bindings.map(({kind:x,target:w,rule:N})=>({kind:x,target:w,rule:N}))},o,u);j!==null&&(f(j),r())},g=async()=>{const k=await nl("secrets.scrub_history",{name:e.name},o,u);k!==null&&(p(k),r())};return h?t.jsx(Rt,{title:`Replaced the value of “${n}”`,onClose:s,foot:t.jsx(E,{variant:"accent",onClick:s,children:"Done"}),children:t.jsx(rO,{title:n,result:h,scrubbed:m,busy:l,failure:c,onScrub:()=>void g()})}):t.jsx(Rt,{title:`Replace the value of “${n}”`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx(E,{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:k=>{k.preventDefault(),a!==""&&v()},children:[t.jsx(oe,{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:k=>i(k.target.value)})}),t.jsx(ae,{message:c})]})})}function Sse({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 nl("secrets.rename",{name:e.name,to:r.trim()},l,c)!==null&&(s(),n())};return t.jsx(Rt,{title:`Rename “${e.name}”`,onClose:n,foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx(E,{type:"submit",form:"secrets-rename",variant:"accent",disabled:i||!u,children:"Rename"})]}),children:t.jsxs("form",{id:"secrets-rename",className:"ui-stack","data-gap":"sm",onSubmit:f=>{f.preventDefault(),u&&h()},children:[t.jsx(oe,{label:"Name",hint:"What agents ask for it by. One that uses the old name needs the new one.",children:t.jsx("input",{required:!0,autoFocus:!0,maxLength:200,disabled:i,value:r,onChange:f=>a(f.target.value)})}),t.jsx(ae,{message:o})]})})}function Cse({secret:e,title:n,destinations:s,onClose:r,onChanged:a}){const[i,l]=d.useState(()=>e.bindings.length?e.bindings.map(m=>({kind:m.kind,target:pG(m.target),rule:m.rule})):s.length?[{kind:s[0].kind,target:"",rule:bf(s[0].maxRule)}]:[]),[o,c]=d.useState(!1),[u,h]=d.useState(null),f=async()=>{const m=iO(i);if(!m.ok){h(m.error);return}await nl("secrets.rebind",{name:e.name,bindings:m.bindings},c,h)!==null&&(a(),r())};return t.jsx(Je,{title:`Where “${n}” may go`,size:"wide",onClose:r,foot:t.jsxs(re,{align:"end",children:[t.jsx(E,{onClick:r,children:"Cancel"}),t.jsx(E,{type:"submit",form:"secrets-places",variant:"accent",disabled:o,children:"Save"})]}),children:t.jsxs("form",{id:"secrets-places",className:"ui-stack","data-gap":"sm",onSubmit:m=>{m.preventDefault(),f()},children:[t.jsx("p",{className:"secrets-note",children:"Agents can use it only in these places. Anywhere else, buddi holds it back and the row says so."}),t.jsx(aO,{destinations:s,bindings:i,disabled:o,onChange:l}),u?t.jsx(Q,{tone:"critical",role:"alert",children:u}):null]})})}function Ese({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 nl("secrets.delete",{name:e.name},i,o)!==null&&(r(),s())};return t.jsxs(Rt,{title:`${c?"Remove":"Delete"} “${n}”?`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx(E,{variant:"danger",disabled:a,onClick:()=>void u(),children:c?"Remove":"Delete"})]}),children:[t.jsxs("p",{className:"secrets-dialog-text",children:[$G(e)," The value is gone for good; its usage history stays, under its name."]}),t.jsx(ae,{message:l})]})}function Ase({timezone:e,embedded:n}){var p;const{data:s,error:r,reload:a}=me(()=>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(v=>v.lastError),f=u.filter(v=>!v.enabled),m=(v,g)=>{l(v),c(null),T.setSentinelEnabled(v,g).catch(k=>c(k instanceof he?k.message:String(k))).finally(()=>{l(null),a()})};return t.jsxs(Ns,{embedded:n,title:"Watchers",children:[t.jsx(ae,{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,f.length>0?t.jsxs(Q,{tone:"warning",children:[f.length===1?"One watcher is off.":`${f.length} watchers are off.`," A watcher that is off does not run, and what it already found stays as it was."]}):null,t.jsx(pe,{title:"Installed",aside:t.jsx("a",{href:`${Jt}/alerts`,children:"See what they found"}),panel:!0,flush:!0,children:s?u.length===0?t.jsx(os,{icon:"eye",title:"No watchers are installed",children:"Plugins bring their own."}):t.jsx(dt,{children:u.map(v=>{const g=s.runs.find(k=>k.sentinelId===v.id);return t.jsx(ot,{lead:t.jsx(Se,{tone:v.enabled?g!=null&&g.lastError?"critical":g?"good":void 0:"muted",children:v.enabled?g!=null&&g.lastError?"failed":g?"ok":"never ran":"off"}),title:v.description,sub:`${v.id}, every ${$se(v.every)}${g!=null&&g.lastError?`. ${g.lastError}`:""}`,side:t.jsxs(t.Fragment,{children:[t.jsx("span",{title:g?mt(g.lastRunAt,e):void 0,children:g?Ye(g.lastRunAt):"never ran"}),t.jsx(E,{size:"sm",disabled:i===v.id,onClick:()=>m(v.id,!v.enabled),children:v.enabled?"Turn off":"Turn on"})]})},v.id)})}):t.jsx(be,{children:"Loading…"})}),t.jsx(yZ,{mutes:((p=s==null?void 0:s.alerts)==null?void 0:p.mutes)??[],onChanged:a})]})}function $se(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 N1=4,Tse={time:"profile",date:"profile",zone:null};function Ise({data:e,phone:n}){const s=d.useRef(null),r=$M(),[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 f=new ResizeObserver(h);return f.observe(u),()=>f.disconnect()},[l]);const c=(e==null?void 0:e.owner)??null;return t.jsx("div",{ref:s,className:"lke-preview","data-phone":n?"true":void 0,style:{aspectRatio:`${l} / ${o}`},role:"img","aria-label":"Preview of the lock screen",children:t.jsxs("div",{className:"lk","data-preview":"true","data-bg":_b(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(_M,{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(ie,{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(ie,{name:"lock",size:15}),t.jsx("span",{className:"lke-pin-hint",children:"Enter your PIN"})]})]})})]})})}function Rse({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(Xt,{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(ie,{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(ie,{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(ie,{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(ie,{name:"close",size:12})})]})]})]})}function S1(e){return e?"place"in e?`place:${e.place}`:`town:${e.timezone}:${e.label}`:""}function Pse({clock:e,onClock:n,version:s}){var Y,B,se;const r=e??Tse,a=me(()=>T.lockScreen(),[s]),i=me(()=>T.widgets("lock"),[]),l=me(()=>T.owner(),[]),[o,c]=d.useState(void 0),[u,h]=d.useState(!1),[f,m]=d.useState(null),[p,v]=d.useState(null),[g,k]=d.useState(null),[j,x]=d.useState(null);d.useEffect(()=>{i.data&&c(i.data)},[i.data]);const w=((Y=a.data)==null?void 0:Y.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,N=(o==null?void 0:o.lock)??[],y=new Map(((o==null?void 0:o.available)??[]).map(G=>[G.id,G])),b=N.length>=N1,S=G=>{if(!o)return Promise.resolve(!1);const X=o;return m(null),c({...o,lock:G,arranged:{...o.arranged,lock:!0}}),T.saveWidgets("lock",G).then(K=>(c(K),a.reload(),!0),K=>(c(X),m(`Couldn't save the lock screen's widgets: ${K instanceof Error?K.message:String(K)}`),!1))},C=(G,X)=>{const K=N.slice(),[J]=K.splice(G,1);K.splice(G+X,0,J),S(K)},A=(G,X)=>{const K=y.get(G);!K||b||S([...N,{key:OM(),widget:G,size:K.sizes.includes("small")?"small":K.sizes[0],settings:X}])},$=G=>{if(G==="find"){k({query:"",found:[],busy:!1});return}if(k(null),G==="")return n({...r,zone:null});if(G.startsWith("place:"))return n({...r,zone:{place:G.slice(6)}});const X=r.zone&&!("place"in r.zone)?r.zone:j;X&&n({...r,zone:X})},I=()=>{if(!g||g.query.trim().length<2)return;const G=g.query.trim();k({query:g.query,found:[],busy:!0}),T.findPlace(G).then(({found:X})=>{var ce;const K=X.filter(xe=>xe.timezone);if(K.length===0){k({query:G,found:[],busy:!1,missed:`Nothing with a timezone found for “${G}”.`});return}const J=K[0],q={label:((ce=J.name.split(",")[0])==null?void 0:ce.trim())||J.name,timezone:J.timezone};x(q),k(null),n({...r,zone:q})}).catch(()=>k({query:G,found:[],busy:!1,missed:"The place finder didn’t answer. Try again in a moment."}))},P=new Date,O=G=>Uu({dateFormat:G},()=>Er(P,w,{weekday:!0})),R=(((B=l.data)==null?void 0:B.places)??[]).filter(G=>G.timezone&&G.timezone!==w),D=r.zone&&!("place"in r.zone)?r.zone:j,U=((o==null?void 0:o.home)??[]).filter(G=>y.has(G.widget)&&!y.get(G.widget).sensitive),W=((o==null?void 0:o.available)??[]).filter(G=>!G.sensitive),M=((o==null?void 0:o.available)??[]).filter(G=>G.sensitive).map(G=>G.title),L=p?N.find(G=>G.key===p):void 0,_=L?y.get(L.widget):void 0;return t.jsxs(pe,{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(Ise,{data:a.data,phone:u}),t.jsxs("div",{className:"lke-look-foot",children:[t.jsx(Xt,{label:"Preview on",options:[{value:"desk",label:"Desk"},{value:"phone",label:"Phone"}],value:u?"phone":"desk",onChange:G=>h(G==="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(ae,{message:f}),t.jsxs("div",{className:"lke-group",role:"group","aria-label":"Clock",children:[t.jsx("p",{className:"lke-group-title",children:"Clock"}),t.jsxs("div",{className:"wg-field",role:"group","aria-label":"Time",children:[t.jsx("span",{className:"wg-field-label",children:"Time"}),t.jsx(Xt,{label:"Time",options:[{value:"profile",label:vT()},{value:"12h",label:"12-hour"},{value:"24h",label:"24-hour"}],value:r.time,onChange:G=>n({...r,time:G})})]}),t.jsx(oe,{label:"Date",children:t.jsxs("select",{value:r.date,onChange:G=>n({...r,date:G.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(oe,{label:"A second clock",hint:"A place in another zone, under the time.",children:t.jsxs("select",{value:g?"find":S1(r.zone),onChange:G=>$(G.target.value),children:[t.jsx("option",{value:"",children:"None"}),R.map(G=>t.jsxs("option",{value:`place:${G.id}`,children:[G.label," — ",G.name.split(",")[0]]},G.id)),r.zone&&"place"in r.zone&&!R.some(G=>G.id===r.zone.place)?t.jsx("option",{value:S1(r.zone),children:"A place no longer in another zone"}):null,D?t.jsx("option",{value:`town:${D.timezone}:${D.label}`,children:D.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:G=>k({...g,query:G.target.value}),onKeyDown:G=>{G.key==="Enter"&&(G.preventDefault(),I()),G.key==="Escape"&&k(null)}}),t.jsx(E,{size:"sm",disabled:g.busy||g.query.trim().length<2,onClick:I,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:[N.length," of ",N1]})]}),b||!o?t.jsxs(E,{size:"sm",disabled:!0,children:[t.jsx(ie,{name:"plus",size:12})," Add a widget"]}):t.jsx(Jn,{label:"Add a widget",trigger:t.jsxs("button",{type:"button",className:"ui-btn","data-size":"sm",children:[t.jsx(ie,{name:"plus",size:12})," Add a widget"]}),items:[U.length>0?{heading:"As on Home"}:null,...U.map(G=>({label:G.label??y.get(G.widget).title,hint:"same settings",onSelect:()=>A(G.widget,G.settings)})),U.length>0?"separator":null,{heading:"Every widget"},...W.map(G=>({label:G.title,onSelect:()=>A(G.id,{})})),"separator",{label:"Get more widgets",hint:"Browse",onSelect:()=>{window.location.hash=vv("widgets")}}]})]}),o?N.length===0?t.jsx("p",{className:"lke-empty",children:"No widgets: just the clock and the counts."}):t.jsx("ul",{className:"lke-list",children:N.map((G,X)=>{const K=y.get(G.widget);return K?t.jsx(Rse,{info:K,placement:G,index:X,count:N.length,onSize:J=>void S(N.map(q=>q.key===G.key?{...q,size:J}:q)),onSettings:()=>v(G.key),onMove:J=>C(X,J),onRemove:()=>void S(N.filter(J=>J.key!==G.key))},G.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(ie,{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."})]})]})]}),L&&_?t.jsx(RM,{info:_,placement:L,surface:"lock",onClose:()=>v(null),onSave:G=>S(N.map(X=>X.key===L.key?{...X,settings:G}:X)).then(X=>(X&&v(null),X)),onRemove:()=>{v(null),S(N.filter(G=>G.key!==L.key))}}):null]})}const Mse=[{id:"field",label:"Buddi"},{id:"dawn",label:"Dawn"},{id:"sea",label:"Sea"},{id:"moss",label:"Moss"},{id:"dusk",label:"Dusk"}];function Ose({background:e,pictures:n}){if(e==="earth")return t.jsxs("p",{className:"lk-credit",children:["Earth: photo by ",t.jsx("a",{href:Sg.authorUrl,target:"_blank",rel:"noreferrer",children:Sg.author})," on ",t.jsx("a",{href:Sg.photoUrl,target:"_blank",rel:"noreferrer",children:"Unsplash"})]});const s=AM(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 Dse=[{value:"1",label:"1 min"},{value:"5",label:"5 min"},{value:"15",label:"15 min"},{value:"60",label:"1 hour"},{value:"never",label:"Never"}],Lse=e=>e.delayMinutes===null?"never":String(e.delayMinutes);function Dj(e){if(e instanceof he){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 Fse({kind:e,onClose:n,onDone:s}){const[r,a]=d.useState(""),[i,l]=d.useState(""),[o,c]=d.useState(""),[u,h]=d.useState(null),[f,m]=d.useState(!1),p=e==="remove",v=e!=="set",g=!f&&(!v||r.length>=4)&&(p||i.length>=4&&o.length>=4),k=N=>N.replace(/\D/g,"").slice(0,8),j=e==="set"?"Set a PIN":e==="change"?"Change your PIN":"Remove the PIN?",x=N=>{if(N==null||N.preventDefault(),!g)return;if(!p&&i!==o){h("The two PINs aren’t the same.");return}m(!0),h(null),(p?T.removePin(r):T.setPin(i,v?r:void 0)).then(s).catch(b=>{m(!1),h(Dj(b))})},w=(N,y,b,S)=>t.jsx(oe,{label:N,children:t.jsx("input",{type:"password",inputMode:"numeric",autoComplete:N==="Current PIN"?"current-password":"new-password",maxLength:8,autoFocus:S,value:y,onChange:C=>{h(null),b(k(C.target.value))}})});return t.jsx(Rt,{title:j,onClose:n,foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx(E,{variant:p?"danger":"accent",disabled:!g,onClick:()=>x(),children:p?"Remove PIN":e==="set"?"Set PIN":"Change PIN"})]}),children:t.jsxs("form",{className:"lk-form",onSubmit:x,children:[t.jsx("p",{className:"lk-honest",children:p?"The dashboard stops locking, on every device. You can set a PIN again any time.":"Four to eight digits. You type it to open the dashboard after it locks, on any device signed in to it."}),v?w("Current PIN",r,a,!0):null,p?null:w(e==="set"?"PIN":"New PIN",i,l,!v),p?null:w("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 _se(e){const n=Jm(),s=me(()=>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),f=EM(),m=s.data??n.state,p=x=>{n.update(x),s.reload()},v=x=>{l(null),x.then(p).catch(w=>l(Dj(w)))},g=(x,w)=>{x&&(c(w),l(null),(w==="portrait"?T.uploadLockPortrait(x):T.uploadLockBackground(x)).then(p).catch(N=>l(Dj(N))).finally(()=>{c(null);const N=w==="portrait"?h.current:u.current;N&&(N.value="")}))};if(!m)return t.jsx(pe,{title:"Lock screen",panel:!0,children:t.jsx(ae,{message:s.error?"Couldn’t read the lock screen’s settings.":null})});const k=m.pin,j=(x,w,N)=>t.jsxs("button",{type:"button",className:"lk-swatch","data-bg":x,"aria-pressed":m.background===x,"aria-label":w,title:w,onClick:()=>v(T.setLockSettings({background:x})),children:[x==="image"&&m.image?t.jsx("img",{src:m.image,alt:""}):x==="earth"?t.jsx("img",{src:vj.thumb,alt:""}):N?t.jsx("img",{src:N,alt:""}):t.jsx("span",{className:"lk-swatch-field"}),t.jsx("span",{className:"lk-swatch-label",children:w})]},x);return t.jsxs(t.Fragment,{children:[t.jsxs(pe,{title:"Lock screen",aside:"Kept for every device signed in to this dashboard.",actions:k?t.jsxs(E,{size:"sm",onClick:()=>n.lockNow(),children:[t.jsx(ie,{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(ae,{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:k?"Set. Kept hashed on this buddi; five wrong tries, then a wait that grows.":"Four to eight digits. Until you set one, nothing locks."})]}),k?t.jsxs(re,{children:[t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>a("remove"),children:"Remove…"}),t.jsx(E,{size:"sm",onClick:()=>a("change"),children:"Change…"})]}):t.jsx(E,{size:"sm",variant:"accent",onClick:()=>a("set"),children:"Set a PIN"})]}),t.jsxs("div",{className:"lk-pref ui-section","data-off":k?void 0:"true","aria-disabled":k?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:k?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(Xt,{label:"Lock after",options:Dse,value:k?Lse(m):"",onChange:x=>{k&&v(T.setLockSettings({delayMinutes:x==="never"?null:Number(x)}))}})]}),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:Mse.map(x=>j(x.id,x.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:[j("earth","Earth"),(f??[]).map(x=>j(RJ(x.id),x.title,x.thumb)),m.image?j("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":m.image?"Replace your picture":"Add your picture",disabled:o!==null,onChange:x=>{var w;return g((w=x.target.files)==null?void 0:w[0],"image")}}),t.jsx("span",{className:"lk-swatch-field","data-kind":"add",children:t.jsx(ie,{name:"plus",size:16})}),t.jsx("span",{className:"lk-swatch-label",children:o==="image"?"Adding…":m.image?"Replace":"Add"})]})]}),t.jsx(Ose,{background:m.background,pictures:f})]})]}),m.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:m.imagePortrait?"Phones show its portrait version.":"Phones show the middle of it. Add a portrait version to choose what they show."})}),t.jsxs(re,{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:x=>{var w;return g((w=x.target.files)==null?void 0:w[0],"portrait")}}),t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>v(T.removeLockBackground()),children:"Remove picture"}),m.imagePortrait?t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>v(T.removeLockPortrait()),children:"Remove portrait"}):null,t.jsx(E,{size:"sm",disabled:o!==null,onClick:()=>{var x;return(x=h.current)==null?void 0:x.click()},children:o==="portrait"?"Adding…":m.imagePortrait?"Replace portrait…":"Add portrait…"})]})]}):null]})]}),r?t.jsx(Fse,{kind:r,onClose:()=>a(null),onDone:x=>{a(null),p(x)}}):null]}),t.jsx(Pse,{clock:m.clock,onClock:x=>v(T.setLockSettings({clock:x})),version:`${m.background}:${m.image??""}:${m.imagePortrait??""}:${JSON.stringify(m.clock??null)}`})]})}const Fg=60;function lO(e){return e instanceof he?e.message:"Something went wrong. Try again."}function zse(e,n,s=Date.now()){const r=`made ${Er(new Date(e.createdAt),n,{compact:!0})} ${e.createdVia==="cli"?"in the terminal":"here"}`;return`buddi_…${e.hint} · ${r} · ${e.lastUsedAt?`last used ${Ye(e.lastUsedAt,s)}`:"never used"}`}function Use({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,f]=d.useState(!1),m=!a&&s.trim()!==""&&s.trim().length<=Fg,p=v=>{v==null||v.preventDefault(),m&&(i(!0),o(null),T.createApiToken(s.trim()).then(g=>{u({token:g.token,name:g.apiToken.name}),n()}).catch(g=>o(lO(g))).finally(()=>i(!1)))};if(c){const v=()=>{var g;(g=navigator.clipboard)==null||g.writeText(c.token).then(()=>{f(!0),window.setTimeout(()=>f(!1),1600)}).catch(()=>{})};return t.jsx(Rt,{title:`Token for ${c.name}`,onClose:e,foot:t.jsx(E,{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(E,{size:"sm",onClick:v,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(Rt,{title:"Make a token",onClose:e,foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:e,children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:!m,onClick:()=>p(),children:"Make token"})]}),children:t.jsxs("form",{className:"at-form",onSubmit:p,children:[t.jsx("p",{className:"at-text",children:"It acts as you on buddi’s HTTP API. Anything a gated tool does still waits for your approval here or on Telegram."}),t.jsx(oe,{label:"What will use it",hint:`So you can tell tokens apart later. Up to ${Fg} characters.`,children:t.jsx("input",{autoFocus:!0,value:s,maxLength:Fg,placeholder:"Home Assistant",onChange:v=>{o(null),r(v.target.value)}})}),l?t.jsx(Q,{tone:"critical",children:l}):null,t.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]})})}function Bse({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(lO(c))})};return t.jsxs(Rt,{title:`Revoke “${e.name}”?`,onClose:n,foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx(E,{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 Wse({timezone:e}){var o;const n=me(()=>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(ae,{message:n.error?"Couldn’t read the API tokens.":null}),t.jsx(pe,{title:"Tokens",aside:"Kept as a fingerprint · shown once",actions:t.jsx(E,{variant:"accent",size:"sm",onClick:()=>r(!0),children:"Make a token"}),panel:!0,flush:!0,children:n.data&&l.length===0?t.jsxs(be,{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(dt,{children:l.map(c=>t.jsx(ot,{lead:t.jsx(Qn,{icon:"key"}),title:c.name,sub:zse(c,e),side:t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>i(c),children:"Revoke…"})},c.id))})}),t.jsxs(pe,{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(Use,{onClose:()=>r(!1),onMade:()=>n.reload()}):null,a?t.jsx(Bse,{token:a,onClose:()=>i(null),onRevoked:()=>n.reload()}):null]})}function Hse({embedded:e}){const{data:n,error:s,reload:r}=me(()=>T.owner(),[]);return t.jsxs(Ns,{embedded:e,title:"You",lede:"What every agent knows about the person it is talking to.",children:[t.jsx(ae,{message:s}),n?t.jsxs(ue,{gap:"lg",children:[t.jsx(Gse,{initial:n,onSaved:r}),t.jsx(Jse,{initial:n})]}):null]})}const oO=new Date(Date.UTC(2026,9,1,14,5));function Kse(){return[["",`Auto (${Uu({timeFormat:null},()=>Tt(oO,"UTC"))} here)`],["12h","12-hour · 2:05 PM"],["24h","24-hour · 14:05"]]}function Vse(){return[["",`Auto (${Uu({dateFormat:null},()=>Er(oO,"UTC",{weekday:!0}))} here)`],["short","Thu, Oct 1"],["long","Thursday, 1 October"],["iso","2026-10-01"]]}function Gse({initial:e,onSaved:n}){var D,U,W;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,f]=d.useState(e.language??""),[m,p]=d.useState(e.about??""),[v,g]=d.useState(e.fullName??""),[k,j]=d.useState(e.pronouns??""),[x,w]=d.useState(Rf(e.birthday)),[N,y]=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??""),f(e.language??""),p(e.about??""),g(e.fullName??""),j(e.pronouns??""),w(Rf(e.birthday))},[e.preferredName,e.timezone,e.timeFormat,e.dateFormat,e.language,e.about,e.fullName,e.pronouns,(D=e.birthday)==null?void 0:D.day,(U=e.birthday)==null?void 0:U.month,(W=e.birthday)==null?void 0:W.year]);const $=Pf(x),I=s.trim()!==(e.preferredName??"")||a!==(e.timezone??"")||l!==(e.timeFormat??"")||c!==(e.dateFormat??"")||h.trim()!==(e.language??"")||m.trim()!==(e.about??"")||v.trim()!==(e.fullName??"")||k.trim()!==(e.pronouns??"")||$!=="incomplete"&&!BZ($,e.birthday),P=async()=>{y(!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:m.trim()===""?null:m.trim(),fullName:v.trim()===""?null:v.trim(),pronouns:k.trim()===""?null:k.trim(),...$!=="incomplete"?{birthday:$}:{}});ry({timeFormat:M.timeFormat??null,dateFormat:M.dateFormat??null}),window.dispatchEvent(new Event(tv)),S(!0),n()}catch(M){A(M instanceof he?M.message:String(M))}finally{y(!1)}},O=e.zones.length>0?e.zones:[e.detectedTimezone],R=M=>L=>{S(!1),M(L)};return t.jsx(pe,{title:"Your profile",aside:"read by every agent, as context",panel:!0,foot:t.jsxs(t.Fragment,{children:[b&&!I?t.jsx("span",{className:"muted",children:"Saved"}):null,t.jsx(E,{variant:"accent",disabled:!I||N,onClick:()=>void P(),children:N?"Saving…":"Save"})]}),children:t.jsxs(ue,{divided:!0,gap:"lg",children:[t.jsx(pe,{title:"Who you are",children:t.jsxs(Ms,{children:[t.jsx(oe,{label:"Full name",hint:"For letters, forms and bookings.",children:t.jsx("input",{value:v,maxLength:120,placeholder:e.displayName??"Your full name",onChange:M=>R(g)(M.target.value)})}),t.jsx(oe,{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=>R(r)(M.target.value)})}),t.jsx(oe,{label:"Pronouns",hint:"Optional.",children:t.jsx("input",{value:k,maxLength:40,placeholder:"he/him, she/her, they/them…",onChange:M=>R(j)(M.target.value)})}),t.jsx(Cj,{label:"Birthday",hint:"The year is optional. Your team greets you on the day.",value:x,onChange:R(w)})]})}),t.jsx(pe,{title:"Time and language",children:t.jsxs(Ms,{children:[t.jsx(oe,{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=>R(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(oe,{label:"Time",children:t.jsx("select",{value:l,onChange:M=>R(o)(M.target.value),children:Kse().map(([M,L])=>t.jsx("option",{value:M,children:L},M))})}),t.jsx(oe,{label:"Dates",hint:"Auto follows this browser's language. Agents write them your way too.",children:t.jsx("select",{value:c,onChange:M=>R(u)(M.target.value),children:Vse().map(([M,L])=>t.jsx("option",{value:M,children:L},M))})}),t.jsx(oe,{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=>R(f)(M.target.value)})})]})}),t.jsxs(pe,{title:"About you",children:[t.jsx(oe,{label:"In your own words",hint:"Who you are, how you like answers, anything every agent should keep in mind. A few lines is plenty.",children:t.jsx("textarea",{rows:4,maxLength:1e3,value:m,placeholder:"I run a small studio and prefer short answers with the numbers first. Call me by my first name.",onChange:M=>R(p)(M.target.value)})}),C?t.jsx(Q,{tone:"critical",children:C}):null]})]})})}const Yse=["Home","Work"];function qse(e){const n=e.trim().toLowerCase();return n==="home"?"home":n==="work"?"briefcase":"pin"}function C1({label:e,empty:n}){return t.jsx("span",{className:"place-glyph","data-empty":n?"true":void 0,"aria-hidden":"true",children:t.jsx(ie,{name:qse(e),size:18})})}function Qse(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 Jse({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=Yse.filter(u=>!n.some(h=>h.label.toLowerCase()===u.toLowerCase())),o=d.useMemo(()=>new Date,[n]);return t.jsxs(pe,{title:"Places",aside:"the front desk, and plugins you allow",actions:t.jsx(E,{size:"sm",onClick:()=>a({label:""}),children:"Add a place"}),panel:!0,flush:!0,children:[t.jsxs(dt,{children:[n.map(u=>t.jsx(ot,{label:`${u.label}: edit`,onClick:()=>a({place:u,label:u.label}),lead:t.jsx(C1,{label:u.label}),title:u.label,sub:Qse(u),side:u.timezone&&u.timezone!==i?t.jsxs(Se,{children:[Tt(o,u.timezone)," there"]}):void 0},u.id)),l.map(u=>t.jsx(ot,{label:`${u}: add`,onClick:()=>a({label:u}),lead:t.jsx(C1,{label:u,empty:!0}),title:t.jsx("span",{className:"muted",children:u}),sub:"Not set",side:t.jsx(E,{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(Xse,{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 Xse({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),[f,m]=d.useState(0),[p,v]=d.useState((a==null?void 0:a.timezone)??""),[g,k]=d.useState(null),[j,x]=d.useState(null),[w,N]=d.useState((a==null?void 0:a.address)??""),y=u==null?void 0:u[f],b=()=>{o.trim().length<2||(k("find"),x(null),T.findPlace(o.trim()).then(I=>{var P;h(I.found),N(o.trim()),m(0),v(((P=I.found[0])==null?void 0:P.timezone)??""),I.found.length===0&&x("Nothing found by that name. Try the town, with its country.")}).catch(I=>x(I instanceof he?I.message:String(I))).finally(()=>k(null)))},S=()=>{y&&(k("save"),x(null),T.savePlace({...a?{id:a.id}:{},label:i.trim(),address:o.trim()===""?null:o.trim(),name:y.name,latitude:y.latitude,longitude:y.longitude,timezone:p===""?null:p}).then(I=>r(I.places)).catch(I=>x(I instanceof he?I.message:String(I))).finally(()=>k(null)))},C=()=>{a&&(k("remove"),x(null),T.removePlace(a.id).then(I=>r(I.places)).catch(I=>x(I instanceof he?I.message:String(I))).finally(()=>k(null)))},A=a?a.label:e.label?`Add ${e.label}`:"Add a place",$=p!==""&&!n.includes(p)?[p,...n]:n;return t.jsx(Je,{title:A,onClose:s,foot:t.jsxs(re,{children:[a?t.jsx(E,{variant:"danger-ghost",disabled:g!==null,onClick:C,children:g==="remove"?"Removing…":"Remove"}):null,t.jsx(pt,{}),t.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:!y||i.trim()===""||g!==null,onClick:S,children:g==="save"?"Saving…":"Save"})]}),children:t.jsxs(ue,{gap:"lg",children:[t.jsx(oe,{label:"Name",hint:"What you call it: Home, Work, Mum's.",children:t.jsx("input",{value:i,maxLength:40,autoFocus:!e.label,onChange:I=>l(I.target.value)})}),t.jsx(oe,{label:"Address",hint:"A street address, or just the town.",action:t.jsx(E,{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:I=>c(I.target.value),onKeyDown:I=>{I.key==="Enter"&&(I.preventDefault(),b())}})}),u&&u.length>0?t.jsx("div",{className:"place-found",role:"radiogroup","aria-label":"Which place",children:u.map((I,P)=>t.jsxs("button",{type:"button",role:"radio","aria-checked":P===f,className:"place-option","data-on":P===f?"true":void 0,onClick:()=>{m(P),v(I.timezone??"")},children:[t.jsx("span",{className:"place-radio","aria-hidden":"true"}),t.jsxs("span",{className:"place-option-text",children:[t.jsx("span",{className:"place-option-name",children:I.name}),t.jsxs("span",{className:"place-option-sub",children:[I.latitude.toFixed(2),", ",I.longitude.toFixed(2),I.timezone?` · ${I.timezone}`:""]})]})]},`${I.latitude},${I.longitude}`))}):t.jsx("p",{className:"place-note-inline",children:"Find it to pin it on the map; nothing is saved until you say Save."}),a&&u&&o.trim()!==w?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(oe,{label:"Its timezone",hint:y?"From where it is. Change it if that is wrong.":"Filled in once the place is found.",children:t.jsxs("select",{value:p,disabled:!y,onChange:I=>v(I.target.value),children:[t.jsx("option",{value:"",children:"Not known"}),$.map(I=>t.jsx("option",{value:I,children:I},I))]})}),t.jsx(ae,{message:j})]})})}const Zse=2e6;function E1(e,n){const s=e.replace(/\r\n/g,`
136
+ `).replace(/\n+$/,"").split(`
137
+ `),r=n.replace(/\r\n/g,`
138
+ `).replace(/\n+$/,"").split(`
139
+ `);if(e.trim()===n.trim())return"(no change)";if(s.length*r.length>Zse)return[...s.map(c=>`-${c}`),...r.map(c=>`+${c}`)].join(`
140
+ `);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(`
141
+ `)}const cO={skill:"skill",policy:"rule",change:"change to itself"};function ere(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 Lj(e){return[...new Set(e.split(/[,\n]/).map(n=>n.trim().replace(/^[-*]\s+/,"")).filter(n=>n!==""))]}function tre(e,n){const s=e.change;if(!s||s.part!=="tools")return[];if(n===e.editable)return s.added;const r=new Set(Lj(s.current??""));return Lj(n).filter(a=>!r.has(a))}function nre(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 sre(e){return"cards"in e}function A1(e,n){return!n||e.kind==="policy"&&e.payload.plugin===n}function rre({embedded:e,plugin:n}){const{data:s,error:r,reload:a}=me(()=>T.proposals(),[],3e4),[i,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState({}),p=async(x,w,N=!1)=>{l(null),c(null),h(x),m(({[x]:y,...b})=>b);try{c(await w()),a()}catch(y){const b=y instanceof Error?y.message:String(y);N?m(S=>({...S,[x]:b})):l(b)}finally{h(null)}},v=OP(),g=((s==null?void 0:s.open)??[]).filter(x=>A1(x,n)),k=((s==null?void 0:s.closed)??[]).filter(x=>A1(x,n)),j=x=>t.jsx(cre,{proposal:x,busy:u===x.id,refusal:f[x.id]??null,onKeep:w=>void p(x.id,async()=>{const N=await T.keepProposal(x.id,w);return`${x.title}: ${N.note}`},!0),onDiscard:w=>void p(x.id,async()=>(await T.discardProposal(x.id,w),`Discarded: ${x.title}. ${x.agent} will be told once and will not propose it again for 90 days.`))},x.id);return t.jsxs(Ns,{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(ae,{message:r??i}),n?t.jsxs(Q,{role:"status",children:["Showing the rules ",n," proposes. ",t.jsx("a",{href:_e("proposals"),children:"Show every proposal"})]}):null,o?t.jsx(Q,{tone:"good",role:"status",children:o}):null,n?null:t.jsx(DP,{offers:v.offers,reload:v.reload}),!s||g.length===0?t.jsx(pe,{title:"Waiting",panel:!0,children:s?n?t.jsx(os,{icon:"bulb",title:`No rule from ${n} is waiting`,children:"It proposes one when you decide the same way several times running."}):t.jsx(os,{icon:"bulb",title:"Nothing proposed",children:"When an agent learns something worth keeping, it waits here."}):t.jsx(be,{children:"Loading…"})}):t.jsx(pe,{title:"Waiting",aside:`${g.length} to decide`,children:nre(g).map(x=>sre(x)?t.jsx(are,{group:x,busy:u===x.key,onKeepAll:()=>void p(x.key,async()=>{const w=await T.keepAllProposals(x.cards.map(N=>N.id));return`${x.label}: ${w.note}`}),card:w=>j(w)},x.key):j(x))}),k.length>0?t.jsx(pe,{title:`Kept, discarded and expired (${k.length})`,aside:"These stop being shown a week after they were decided.",panel:!0,flush:!0,children:t.jsx(dt,{children:k.map(x=>{var w;return t.jsx(ot,{title:x.title,sub:`${x.agent}: ${ire(x)}`,side:x.kind==="skill"&&x.state==="kept"&&((w=x.skill)!=null&&w.live)?t.jsxs(re,{align:"end",children:[t.jsx("span",{className:"muted",children:Ye(x.decidedAt??x.createdAt)}),t.jsx(E,{size:"sm",variant:"ghost",disabled:u===x.id,onClick:()=>void p(x.id,async()=>{const N=x.skill;return await T.removeSkill(x.agent,N.name),`Removed ${N.name} from ${x.agent}. Its versions are kept, and ${x.agent} will not propose it again for 90 days.`}),children:"Remove this skill"})]}):Ye(x.decidedAt??x.createdAt)},x.id)})})}):null,!n&&(s!=null&&s.digest)?t.jsx(ore,{schedule:s.digest.schedule,onSaved:a}):null]})}function are({group:e,busy:n,onKeepAll:s,card:r}){const a=e.cards.length,i=e.cards.some(l=>l.untrusted);return t.jsx(Ar,{tone:i?"warning":"accent",title:`${e.label} (${a})`,meta:t.jsxs(t.Fragment,{children:[t.jsx(Se,{children:cO.policy}),t.jsx(Se,{mono:!0,children:e.plugin})]}),foot:t.jsx(re,{align:"end",children:t.jsxs(E,{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(Gt,{summary:`Show each of the ${a}`,children:t.jsx(ue,{gap:"sm",children:e.cards.map(l=>r(l))})})]})})}function ire(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 lre=Array.from({length:24},(e,n)=>n),$1=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function ore({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,f=async()=>{o(!0),u(null);try{await T.setDigestSchedule(s,a),u({tone:"good",text:`The digest now runs on ${$1[s]} at ${String(a).padStart(2,"0")}:00.`}),n()}catch(m){u({tone:"critical",text:m instanceof Error?m.message:String(m)})}finally{o(!1)}};return t.jsx(pe,{title:"Weekly digest",panel:!0,foot:t.jsx(E,{variant:"accent",disabled:l||!h,onClick:()=>void f(),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: ${Ye(e.next)}.`:""]}),t.jsxs(re,{children:[t.jsx(oe,{label:"Day",children:t.jsx("select",{value:s,disabled:l,onChange:m=>r(Number(m.target.value)),children:$1.map((m,p)=>t.jsx("option",{value:p,children:m},m))})}),t.jsx(oe,{label:`Hour (${e.timezone})`,children:t.jsx("select",{value:a,disabled:l,onChange:m=>i(Number(m.target.value)),children:lre.map(m=>t.jsxs("option",{value:m,children:[String(m).padStart(2,"0"),":00"]},m))})})]}),c?t.jsx(Q,{tone:c.tone,role:"status",children:c.text}):null]})})}function T1(e,n){return e==="tools"?Lj(n).join(`
142
+ `):n}function cre({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,f=e.echoes??[],m=e.kind==="change"?e.change??null:null,p=tre(e,i);return t.jsx(Ar,{tone:e.untrusted?"warning":"accent",title:e.title,meta:t.jsxs(t.Fragment,{children:[t.jsx(Se,{children:cO[e.kind]}),t.jsx(Se,{mono:!0,children:e.agent}),e.untrusted?t.jsx(Se,{tone:"warning",children:"untrusted text in view"}):null,p.length>0?t.jsx(Se,{tone:"warning",children:"widens its tools"}):null]}),foot:t.jsxs(re,{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:v=>c(v.target.value)}),t.jsx(E,{variant:"ghost",size:"sm",disabled:n,onClick:()=>a(o.trim()||void 0),children:"Discard"}),t.jsx(E,{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," ",Ye(e.createdAt),e.conversationId?t.jsxs(t.Fragment,{children:[" in ",t.jsx("a",{href:ju(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(v=>t.jsx("li",{className:"mono",children:v},v))}),f.length>0?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"proposal-echo-lede",children:"These sentences of it also appear in that text:"}),t.jsx("ul",{className:"proposal-sources","aria-label":"Sentences found in the untrusted text",children:f.map(v=>t.jsx("li",{children:t.jsx("mark",{className:"wb-diff-mark",children:v})},v))})]}):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:Dt(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(lf,{text:E1(e.skill.steps,i),marks:f,label:`Version ${e.skill.version} against this proposal`})]}):null,t.jsx(oe,{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:v=>l(v.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,m!=null&&m.refusal&&!u?t.jsx(Q,{tone:"warning",title:"Keeping this as proposed will be refused.",children:m.refusal}):null,m&&m.current!==null?t.jsx(lf,{text:E1(T1(m.part,m.current),T1(m.part,i)),marks:f,label:`${e.agent}'s ${m.part==="tools"?"tool list":"instructions"} now, against this proposal`}):typeof h.before=="string"?t.jsx(Gt,{summary:`What its ${h.part==="tools"?"tool list":"instructions"} said when proposed`,children:t.jsx(Bt,{children:h.before})}):null,t.jsx(oe,{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:v=>l(v.target.value)})})]}):null,e.kind==="policy"?t.jsx(Vt,{items:[{label:"Plugin",value:t.jsx("span",{className:"mono",children:String(h.plugin??"")})},{label:"Matches",value:t.jsx("span",{className:"mono",children:ere(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 uO(e){return e.length>1?"small or medium":`${e[0]} only`}function ure(e){return["small","medium"].filter(n=>e.includes(n))}function dO({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(qm,{body:r,size:n}):t.jsxs("span",{className:"wg-state",children:[t.jsx(Qn,{svg:s}),t.jsx("span",{className:"wg-state-sub",children:"No preview from this plugin."})]})})]})}function dre(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 hre({start:e,onPick:n,onClose:s}){const[r,a]=d.useState(null),[i,l]=d.useState(null),[o,c]=d.useState(""),u=(p,v=!1)=>{l(null),T.pluginFolders(p).then(g=>{a(g),c("")}).catch(g=>{v&&p!==void 0?u(void 0):l(g instanceof he?g.message:String(g))})};d.useEffect(()=>{u(e,!0)},[]);const h=o.trim().toLowerCase(),f=((r==null?void 0:r.folders)??[]).filter(p=>h===""||p.name.toLowerCase().includes(h)),m=r?dre(r):[];return t.jsxs(Je,{title:"Choose the folder",onClose:s,foot:t.jsxs(re,{children:[t.jsx("span",{className:"plugins-foot-note mono",children:(r==null?void 0:r.path)??""}),t.jsx(pt,{}),t.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx(E,{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(Oc,{label:"Folder",items:m.map((p,v)=>v===m.length-1?{key:p.path,label:p.label,current:!0}:{key:p.path,label:p.label,onClick:()=>u(p.path)})}):null,t.jsx(Fm,{label:"Find a folder here",value:o,placeholder:"Find a folder here…",onChange:c}),t.jsx(ae,{message:i}),r?f.length===0?t.jsx(be,{children:h===""?"No folders in here.":`No folder here is called anything like “${o.trim()}”.`}):t.jsx(st,{flush:!0,children:t.jsx(dt,{children:f.map(p=>t.jsx(ot,{onClick:()=>u(p.path),label:`Open ${p.name}`,lead:t.jsx(Qn,{icon:"folder"}),title:p.name,side:p.plugin?t.jsx(Se,{tone:"accent",children:"package.json"}):void 0},p.path))})}):i?null:t.jsx(be,{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 fre="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 I1(){return t.jsxs("p",{className:"plugins-quiet connections-quiet",children:[t.jsx(ie,{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:_e("connections"),children:"Connections"})]})]})}const mre=1500,pre={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."},gre="Restart buddi to apply it. In a checkout, stop it and run: buddi serve",hO=[{value:"npm",label:"From npm"},{value:"file",label:"A file"},{value:"directory",label:"A directory I built"}],fO="buddi.plugins.install-mode";function xre(){try{const e=window.localStorage.getItem(fO);if(hO.some(n=>n.value===e))return e}catch{}return"npm"}function vre(e){try{window.localStorage.setItem(fO,e)}catch{}}const Qd=".tgz",Kr=(e,n,s)=>`${e} ${e===1?n:s}`;function mO(e){const n=[];return e.tools>0&&n.push(Kr(e.tools,"tool","tools")),e.sentinels>0&&n.push(`${e.sentinels} on a timer`),e.views>0&&n.push(Kr(e.views,"view","views")),e.agents>0&&n.push(`${Kr(e.agents,"agent","agents")} proposed`),n.length===0?"nothing on its own":n.join(", ")}function Fj(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 pO(e){return e.kind==="registry"?"npm":e.kind==="tarball"?"a file":"a directory"}function Jb(e,n){return e.kind==="directory"?"you, from this machine":e.kind==="tarball"?"a file on this machine":n??"nobody npm will name"}function gO(e){return e.author?e.author.name:e.source.kind==="registry"?e.publisher??"nobody npm will name":"you"}function Zm({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 _j({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 xO(e){return e.length===0?"none; nothing leaves this computer":t.jsx("span",{className:"mono",children:e.join(", ")})}function Xb(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 ui=e=>e instanceof he?e.message:String(e);function jre(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;const l=()=>{T.pluginJob(e).then(c=>{i||(s(c),(c.phase==="done"||c.phase==="failed")&&(i=!0))}).catch(c=>{i||(a(ui(c)),i=!0)})};l();const o=window.setInterval(l,mre);return()=>{i=!0,window.clearInterval(o)}},[e]),{job:n,error:r}}function wre({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=Yr(i.plugin,i.id);return t.jsx(nt,{size:"sm",variant:r,href:l,"aria-label":`Open ${i.title}`,onClick:o=>{o.stopPropagation(),s&&(o.preventDefault(),s(l))},children:a.length===1?"Open":`Open ${i.title}`},i.id)})})}function vO({plugin:e}){var s;if(e.enabled===!1)return t.jsx(Se,{children:"disabled"});const n=(s=e.needs)==null?void 0:s[0];return n?t.jsxs(Se,{tone:"warning",children:["needs ",n.plugin]}):e.loadsAtRestart?t.jsx(Se,{tone:"accent",children:"loads at restart"}):e.loaded&&e.setup?t.jsx(Se,{tone:"warning",children:"needs setup"}):e.loaded?t.jsx(Se,{tone:"good",dot:!0,children:"loaded"}):t.jsx(Se,{tone:"critical",children:"did not load"})}function Zb({entry:e}){var n;return e.trust==="by-buddi"?t.jsx(Se,{tone:"accent",children:"by buddi"}):t.jsxs(Se,{tone:"good",children:["reviewed ",((n=e.reviewed)==null?void 0:n.version)??e.version]})}const zj=_e("plugins"),_g={installed:zj,browse:`${zj}?tab=browse`};function yre({railPages:e=[],settingsPages:n=[],navigate:s,hash:r=""}={}){const a=me(()=>T.plugins(),[],2e4),[i,l]=d.useState(null),{job:o,error:c}=jre(i),[u,h]=d.useState(null),[f,m]=d.useState(()=>ON(r));d.useEffect(()=>m(ON(r)),[r]);const[p,v]=d.useState(()=>MN(r));d.useEffect(()=>v(MN(r)),[r]);const[g,k]=d.useState(null),[j,x]=d.useState(null),[w,N]=d.useState(null),[y,b]=d.useState(null),[S,C]=d.useState(!1),A=le=>{C(!0),T.market(le).then(b).catch(je=>b({plugins:[],unavailable:ui(je)})).finally(()=>C(!1))};d.useEffect(()=>{f==="browse"&&y===null&&!S&&A(!1)},[f]);const $=le=>{h(null),l(le)},I=le=>h(ui(le)),[P,O]=d.useState(!1),R=le=>{O(!0),k(null),le.then(je=>{$(je.job.id),m("installed")}).catch(I).finally(()=>O(!1))},D=d.useRef(null);d.useEffect(()=>{const le=NB(r);if(!(le===null||D.current===le)){D.current=le,m("installed"),R(T.stagePlugin(le));try{window.history.replaceState(window.history.state,"",zj)}catch{}}},[r]);const U=le=>je=>{je.preventDefault(),m(le),k(null),s==null||s(_g[le])};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,M=(W==null?void 0:W.checkout)??!0,L=(W==null?void 0:W.installed)??[],_=le=>y==null?void 0:y.plugins.find(je=>je.installed!==void 0&&(je.installed.name??je.name)===le.name),Y=le=>e.some(je=>je.plugin===le),B=(le,je)=>Y(le)?t.jsx(wre,{plugin:le,pages:e,navigate:s,variant:je}):void 0,se=le=>{const je=e.find(et=>et.plugin===le);je&&s&&s(Yr(je.plugin,je.id))},G=le=>{const je=n.find(et=>et.plugin===le);if(!(!je||!s))return()=>s(vr(je.plugin,je.id))},X=((y==null?void 0:y.plugins)??[]).filter(le=>le.update).length,K=(le,je)=>T.setPluginEnabled(le,je).then(et=>{Ry(),N({name:le,notes:et.notes??[]}),a.reload()}),J=(le,je,et)=>T.uninstallPlugin(le,je?{purge:!0,confirm:et}:{}).then(ft=>{k(null),N({name:le,notes:ft.notes??[]}),a.reload()}),q=le=>{h(null),K(le,!0).catch(I)},ce=(le,je)=>{const et=y==null?void 0:y.plugins.find(Et=>{var Ft;return(((Ft=Et.installed)==null?void 0:Ft.name)??Et.name)===le&&Et.installed!==void 0}),ft=et&&je?`${et.npm}@${je}`:void 0;R(ft?T.updatePlugin(le,je,ft):T.updatePlugin(le,je))},xe=le=>{h(null);const je=et=>{const ft=et.plugins.find(Et=>{var Ft;return Et.name===le||((Ft=Et.installed)==null?void 0:Ft.name)===le});if(!ft){h(`${le} is not listed on withbuddi.com. Add it from npm, a file or a directory above, then install this one.`);return}R(T.stagePlugin(`${ft.npm}@${ft.version}`))};if(y&&y.plugins.length>0)return je(y);O(!0),T.market(!1).then(et=>{b(et),je(et)}).catch(I).finally(()=>O(!1))},Me=(le,je)=>je===void 0?void 0:je.place==="settings"?vr(le,je.id):Yr(le,je.id),H=le=>{var et;if(le.enabled===!1)return;const je=(et=le.needs)==null?void 0:et[0];if(je)switch(je.state){case"missing":return{label:`Install ${je.plugin}`,run:()=>xe(je.plugin)};case"disabled":return{label:`Enable ${je.plugin}`,run:()=>q(je.plugin)};case"range":return{label:`Update ${je.plugin}`,run:()=>ce(je.plugin)};case"setup":{const ft=Me(je.plugin,je.page),Et=ft&&s?()=>s(ft):G(je.plugin);return Et?{label:`Set up ${je.plugin}`,run:Et}:void 0}default:return{label:`See ${je.plugin}`,run:()=>k({kind:"installed",name:je.plugin})}}if(le.loaded&&le.setup){const ft=Me(le.name,le.setup.page),Et=ft&&s?()=>s(ft):G(le.name);return Et?{label:"Set it up",run:Et}:void 0}},ne=t.jsxs(_o,{label:"Plugins",children:[t.jsx(Zi,{href:_g.installed,active:f==="installed",count:X,onClick:U("installed"),children:"Installed"}),t.jsx(Zi,{href:_g.browse,active:f==="browse",onClick:U("browse"),children:"Browse"})]}),Z=(W==null?void 0:W.staged)??[],ye=$re(Z,(o==null?void 0:o.phase)==="done"?o.stagedId:void 0),Ce=Z.find(le=>le.id===ye),ke=Z.filter(le=>le.id!==ye),we=le=>{k(null),Ire(le),l(null),a.reload()},ve=(g==null?void 0:g.kind)==="staged"?ke.find(le=>le.id===g.name):void 0,Ie=(g==null?void 0:g.kind)==="installed"?L.find(le=>le.name===g.name):void 0,Re=(g==null?void 0:g.kind)==="market"?y==null?void 0:y.plugins.find(le=>le.name===g.name):void 0,de=w&&!(Ie&&Ie.name===w.name)&&w.notes.length>0?w.notes:null,Ee=ve?t.jsx(Ere,{staged:ve,onClose:()=>k(null),onInstalled:we,onInstallFirst:xe,onGone:()=>{k(null),a.reload()}},ve.id):Ie?t.jsx(Fre,{plugin:Ie,listing:_(Ie),notes:(w==null?void 0:w.name)===Ie.name?w.notes:null,canOpen:Y(Ie.name)&&Ie.enabled!==!1,onOpen:()=>se(Ie.name),onClose:()=>k(null),onDisable:()=>x({kind:"disable",name:Ie.name}),onEnable:()=>q(Ie.name),onRemove:()=>x({kind:"remove",name:Ie.name}),onUpdate:le=>ce(Ie.name,le),onSettings:Ie.enabled===!1?void 0:G(Ie.name),firstStep:H(Ie),busy:P}):Re?t.jsx(Vre,{entry:Re,canOpen:Re.installed!==void 0&&Y(Re.installed.name??Re.name),onOpen:()=>{var le;return se(((le=Re.installed)==null?void 0:le.name)??Re.name)},onClose:()=>k(null),onInstall:()=>R(T.stagePlugin(`${Re.npm}@${Re.version}`)),onUpdate:le=>{var je;return ce(((je=Re.installed)==null?void 0:je.name)??Re.name,le)},busy:P}):null,ze=j?L.find(le=>le.name===j.name):void 0,qe=j?t.jsx(_re,{kind:j.kind,name:j.name,canDisable:(ze==null?void 0:ze.enabled)!==!1,onCancel:()=>x(null),onDisableInstead:()=>x({kind:"disable",name:j.name}),onDisable:()=>K(j.name,!1).then(()=>x(null)),onRemove:(le,je)=>J(j.name,le,je).then(()=>x(null))},`${j.kind}:${j.name}`):null;if(f==="browse")return t.jsxs(ue,{gap:"lg",children:[t.jsx(I1,{}),ne,t.jsx(ae,{message:u}),t.jsx(Jre,{kind:p,onKind:v,navigate:s,market:y,loading:S,busy:P,onRetry:()=>A(!0),onOpen:le=>k({kind:"market",name:le.name}),onInstall:le=>R(T.stagePlugin(`${le.npm}@${le.version}`)),onUpdate:(le,je)=>{var et;return ce(((et=le.installed)==null?void 0:et.name)??le.name,je)}}),Ee]});const ht=(W==null?void 0:W.builtIn)??[];return t.jsxs(ue,{gap:"lg",children:[t.jsx(I1,{}),ne,t.jsx(ae,{message:a.error??u??c}),W!=null&&W.unavailable?t.jsx(Q,{tone:"warning",children:W.unavailable}):null,de?t.jsx(Q,{role:"status",children:de.join(" ")}):null,t.jsx(bre,{trust:(W==null?void 0:W.trust)??"",job:o,busy:o!==void 0&&o.phase!=="done"&&o.phase!=="failed",onStaged:$,onFailed:h}),Ce?t.jsx(Sre,{staged:Ce,onInstalled:we,onGone:()=>a.reload(),onInstallFirst:xe},Ce.id):null,ke.length>0?t.jsx(st,{flush:!0,title:"Waiting for you",tool:Kr(ke.length,"package","packages"),children:t.jsx("div",{className:"plugins-rows",children:t.jsx(dt,{children:ke.map(le=>t.jsx(Cre,{staged:le,onReview:()=>{wO(le),k({kind:"staged",name:le.id})},onReject:()=>{h(null),T.rejectStaged(le.id).then(()=>a.reload()).catch(I)}},le.id))})})}):null,W!=null&&W.restartNeeded?t.jsx(Tre,{checkout:M,waiting:L.filter(le=>le.loadsAtRestart)}):null,t.jsx(Pre,{list:L,firstStepFor:H}),t.jsx(st,{flush:!0,title:"Installed",tool:W?Kr(L.length,"plugin","plugins"):void 0,children:W?L.length===0?t.jsx(be,{children:"Nothing installed yet. Only what buddi ships with is here."}):t.jsx("div",{className:"plugins-rows",children:t.jsx(dt,{children:L.map(le=>t.jsx(Ore,{plugin:le,listing:_(le),open:le.enabled===!1?void 0:B(le.name,"ghost"),canOpen:Y(le.name)&&le.enabled!==!1,busy:P,onDetails:()=>k({kind:"installed",name:le.name}),onOpen:()=>se(le.name),onSettings:le.enabled===!1?void 0:G(le.name),onDisable:()=>x({kind:"disable",name:le.name}),onEnable:()=>q(le.name),onRemove:()=>x({kind:"remove",name:le.name}),onUpdate:je=>ce(le.name,je),firstStep:H(le)},le.name))})}):t.jsx(be,{children:"Loading…"})}),ht.length>0?t.jsx(zre,{plugins:ht,openFor:B}):null,Ee,qe]})}function bre({trust:e,job:n,busy:s,onStaged:r,onFailed:a}){const[i,l]=d.useState(xre),[o,c]=d.useState(""),[u,h]=d.useState(!1),[f,m]=d.useState(null),[p,v]=d.useState(null),[g,k]=d.useState(!1),[j,x]=d.useState(!1),w=d.useRef(null),N=C=>a(ui(C)),y=C=>{l(C),vre(C),v(null)},b=()=>{h(!0),T.stagePlugin(o.trim()).then(C=>{r(C.job.id),c("")}).catch(N).finally(()=>h(!1))},S=C=>{if(C){if(!C.name.toLowerCase().endsWith(Qd)){m(null),v(`${C.name} is not a ${Qd}. A packed plugin is the file npm pack writes.`);return}v(null),m(C.name),h(!0),T.uploadPlugin(C).then(A=>r(A.job.id)).catch(N).finally(()=>h(!1))}};return t.jsxs(st,{title:"Add a plugin",actions:t.jsx(Xt,{label:"Where it comes from",options:hO,value:i,onChange:y}),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":f?"chosen":void 0,onDragOver:C=>{C.preventDefault(),k(!0)},onDragLeave:()=>k(!1),onDrop:C=>{var A,$;C.preventDefault(),k(!1),S(($=(A=C.dataTransfer)==null?void 0:A.files)==null?void 0:$[0])},children:[t.jsx(ie,{name:"drop",size:20}),t.jsx("span",{className:"plugins-drop-text",children:p??(f?`${f} — reading it.`:t.jsxs(t.Fragment,{children:["Drop a ",t.jsx("span",{className:"mono",children:Qd})," here: the file ",t.jsx("span",{className:"mono",children:"npm pack"})," ","writes. It is read the moment it lands."]}))}),t.jsx(E,{variant:"accent",disabled:s||u,onClick:()=>{var C;return(C=w.current)==null?void 0:C.click()},children:"Choose a file"}),t.jsx("input",{ref:w,type:"file",accept:Qd,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(re,{valign:"end",children:[t.jsx(oe,{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(E,{onClick:()=>x(!0),children:"Browse…"}):null,t.jsx(E,{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:[pre[n.phase]," ",n.error??""]}):null,t.jsx("div",{className:"plugins-trust",children:t.jsx(Q,{tone:"warning",children:e})})]}),j?t.jsx(hre,{start:o.trim().startsWith("/")?o.trim():void 0,onClose:()=>x(!1),onPick:C=>{c(C),x(!1)}}):null]})}function kre({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?Xb([]):n.map(i=>t.jsxs("span",{children:["It ",i.words,". ",i.added?t.jsxs(Se,{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 jO(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:f=>{l(!0),c(null),T.approveStaged(e.id,{integrity:e.integrity??"",...f?{acknowledgeDrift:!0}:{}}).then(m=>{m.installed?n(e.name):m.plan&&a(m.plan)}).catch(m=>c(ui(m))).finally(()=>l(!1))},reject:()=>{l(!0),c(null),T.rejectStaged(e.id).then(()=>s()).catch(f=>c(ui(f))).finally(()=>l(!1))}}}function wO(e){e.openedAt||T.openedStaged(e.id).catch(()=>{})}function Nre({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(Se,{tone:"warning",children:"not installed"}),n?t.jsxs(E,{size:"sm",onClick:()=>n(s.plugin),children:["Install ",s.plugin," first"]}):null]}):t.jsx(Se,{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 yO({staged:e,inSheet:n,onInstallFirst:s}){var a;const r=e.dependencies;return t.jsxs("div",{className:"plugins-staged","data-in":n?"sheet":void 0,children:[t.jsx("div",{className:"plugins-facts",children:t.jsx(Vt,{items:[...e.author?[{label:"By",value:t.jsx(Zm,{author:e.author})}]:[],{label:"From",value:e.uploadedName?`a file you chose · ${e.uploadedName}`:Fj(e.source)},{label:"Published by",value:Jb(e.source,e.publisher)},...e.previousSource&&e.previous?[{label:"Replaces",value:`${e.previous.version}, installed from ${Fj(e.previousSource)}`}]:e.source.kind==="directory"&&((a=e.previous)==null?void 0:a.version)===e.version?[{label:"Reinstalls",value:`${e.version}, the same version, its files read again from the folder`}]:[],...e.source.kind==="directory"?[]:[{label:"Installs as",value:e.installsAs?t.jsx("span",{className:"mono",children:e.installsAs}):"the name its manifest gives, read when you approve — it declares no buddi.name"}],...e.coreAsDependency?[{label:"Core",value:"It asks npm for buddi's core; buddi provides its own."}]:[],{label:"Dependencies",value:r.count===0?"none":`${r.count}${r.withScripts.length===0?", none of which run install scripts":`, of which these run install scripts: ${r.withScripts.join(", ")}`}`},{label:"What it reaches",value:t.jsx(kre,{staged:e})},...(e.requires??[]).length>0?[{label:"Needs",value:t.jsx(Nre,{staged:e,onInstallFirst:s})}]:[],{label:"Integrity",value:t.jsx(_j,{value:e.integrity})},...e.stagedHash?[{label:"Files on disk",value:t.jsx(_j,{value:e.stagedHash})}]:[]]})}),t.jsxs("div",{className:"plugins-claim",children:[t.jsx("div",{className:"plugins-claim-head",children:"What it says about itself"}),t.jsx("div",{className:"plugins-claim-note",children:"From its own buddi.md. Nothing has checked it yet."}),e.claims.missing?t.jsx("p",{className:"plugins-claim-text",children:"It ships no buddi.md, so it says nothing about itself at all."}):t.jsxs("p",{className:"plugins-claim-text",children:["“",e.claims.text,"”"]}),t.jsx("div",{className:"plugins-facts",children:t.jsx(Vt,{items:[{label:"Schema it owns",value:e.claims.schema?t.jsx("span",{className:"mono",children:e.claims.schema}):"it claims none"},{label:"Hosts it reaches",value:e.claims.hosts.length===0?"it claims none":t.jsx("span",{className:"mono",children:e.claims.hosts.join(", ")})}]})})]})]})}function bO({plan:e,busy:n,onReject:s,onInstallAnyway:r}){return t.jsxs(Ar,{tone:"warning",title:"What it said, and what it does",meta:t.jsx(Se,{tone:"warning",children:"read this first"}),foot:t.jsxs(re,{children:[t.jsx("span",{className:"plugins-foot-note",children:"Install anyway says you read these."}),t.jsx(pt,{}),t.jsx(E,{variant:"ghost",disabled:n,onClick:s,children:"Not this one"}),t.jsx(E,{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(kO,{unlocks:e.agents??[]})]})}function Sre({staged:e,onInstalled:n,onGone:s,onInstallFirst:r}){const{plan:a,busy:i,failed:l,approve:o,reject:c}=jO(e,n,s);d.useEffect(()=>wO(e),[e.id]);const u=(a==null?void 0:a.drift)??[];return t.jsxs(ue,{gap:"sm",children:[t.jsxs(Ar,{tone:"accent",title:t.jsxs(t.Fragment,{children:[e.name," ",t.jsx("span",{className:"plugins-ver",children:e.version})]}),meta:t.jsx(Se,{children:"read, not installed"}),foot:t.jsxs(re,{children:[t.jsx("span",{className:"plugins-foot-note",children:"Nothing of it has run."}),t.jsx(pt,{}),t.jsx(E,{variant:"ghost",disabled:i,onClick:c,children:"Not this one"}),t.jsx(E,{variant:"accent",disabled:i||u.length>0,onClick:()=>o(!1),children:"Install"})]}),children:[t.jsx(ae,{message:l}),t.jsx(yO,{staged:e,onInstallFirst:r})]}),a&&u.length>0?t.jsx(bO,{plan:a,busy:i,onReject:c,onInstallAnyway:()=>o(!0)}):null]})}function Cre({staged:e,onReview:n,onReject:s}){const r=Ye(e.createdAt);return t.jsx(ot,{onClick:n,label:`${e.name}: review`,lead:t.jsx(Qn,{svg:void 0}),title:t.jsxs(t.Fragment,{children:[e.name," ",t.jsx("span",{className:"plugins-ver",children:e.version})]}),sub:`from ${pO(e.source)}${r?` · read ${r}`:""}`,side:t.jsxs("span",{className:"plugins-side",children:[t.jsxs("span",{className:"plugins-wait-extra",children:[t.jsx(Se,{children:"read, not installed"}),t.jsx(E,{size:"sm",variant:"ghost",onClick:jo(s),children:"Not this one"})]}),t.jsx(E,{size:"sm",onClick:jo(n),children:"Review"})]})})}function Ere({staged:e,onClose:n,onInstalled:s,onGone:r,onInstallFirst:a}){const{plan:i,busy:l,failed:o,approve:c,reject:u}=jO(e,s,r),h=(i==null?void 0:i.drift)??[];return t.jsxs(Je,{title:t.jsx(nk,{svg:void 0,name:e.name,version:e.version,by:e.author?t.jsx(Zm,{author:e.author}):Jb(e.source,e.publisher),pills:t.jsxs(t.Fragment,{children:[" · ",t.jsx(Se,{children:"read, not installed"})]})}),onClose:n,foot:t.jsxs(re,{children:[t.jsx("span",{className:"plugins-foot-note",children:"Nothing of it has run."}),t.jsx(pt,{}),t.jsx(E,{variant:"ghost",disabled:l,onClick:u,children:"Not this one"}),t.jsx(E,{variant:"accent",disabled:l||h.length>0,onClick:()=>c(!1),children:"Install"})]}),children:[t.jsx(ae,{message:o}),t.jsx(yO,{staged:e,inSheet:!0,onInstallFirst:a}),i&&h.length>0?t.jsx(bO,{plan:i,busy:l,onReject:u,onInstallAnyway:()=>c(!0)}):null]})}const Are=10*60*1e3;function $re(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<Are?r.id:null}function Tre({checkout:e,waiting:n}){const[s,r]=d.useState(!1),[a,i]=d.useState(null),l=c5(n),o=l?`${l} ${n.length===1?"is":"are"} installed.`:"A plugin was installed, disabled or enabled since buddi started, and this buddi has not caught up.";return t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:a}),t.jsxs(Q,{tone:e?"warning":"accent",role:"status",action:e?void 0:t.jsx(E,{size:"sm",variant:"accent",disabled:s,onClick:()=>{r(!0),i(null),qu({kind:"plugins",...l?{line:`Loading ${l}…`}:{line:"Applying your plugin changes…"}},()=>T.serviceAction("restart")).catch(c=>i(ui(c))).finally(()=>r(!1))},children:"Restart to load it"}),children:[o," ",e?gre:`${l?n.length===1?"Its tools appear":"Their tools appear":"It takes effect"} once buddi restarts, which takes a few seconds. This page waits and comes back by itself.`]})]})}const ek="buddi.plugins.justInstalled";function Ire(e){try{window.sessionStorage.setItem(ek,e)}catch{}}function Rre(){try{return window.sessionStorage.getItem(ek)}catch{return null}}function Pre({list:e,firstStepFor:n}){var u;const[s,r]=d.useState(()=>Rre()),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(ek)}catch{}r(null)};if(d.useEffect(()=>{i&&!l&&o()},[i,l]),!a||!l)return null;const c=n(a);return t.jsx(Q,{tone:"accent",role:"status",action:t.jsxs(t.Fragment,{children:[t.jsx(E,{size:"sm",variant:"ghost",onClick:o,children:"Later"}),c?t.jsx(E,{size:"sm",variant:"accent",onClick:()=>{o(),c.run()},children:c.label}):null]}),children:a.needs?`${a.name} is installed and waits. ${tk(a)}.`:`${a.name} is loaded. First: ${((u=a.setup)==null?void 0:u.note)??"set it up on its settings page."}`})}const jo=e=>n=>{n.stopPropagation(),e()},Mre=e=>e.unlocks.filter(n=>n.drift.state==="not-accepted").length;function tk(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 Ore({plugin:e,listing:n,open:s,canOpen:r,busy:a,onDetails:i,onOpen:l,onSettings:o,onDisable:c,onEnable:u,onRemove:h,onUpdate:f,firstStep:m}){const p=e.enabled===!1,v=Mre(e),g=!p&&(e.needs!==void 0||e.loaded&&e.setup!==void 0);return t.jsx(ot,{onClick:i,label:`${e.name}: details`,dimmed:p,lead:t.jsx(Qn,{svg:n==null?void 0:n.iconSvg}),title:t.jsxs(t.Fragment,{children:[e.name," ",t.jsx("span",{className:"plugins-ver",children:e.version}),v>0?t.jsxs("span",{className:"plugins-ask",children:[Kr(v,"agent","agents")," to accept"]}):null]}),sub:g?t.jsx("span",{className:"plugins-sub","data-tone":"warning",children:tk(e)}):`by ${gO(e)} · from ${pO(e.source)} · ${mO(e.contribution)}`,side:t.jsxs("span",{className:"plugins-side",children:[g&&m?t.jsx(E,{size:"sm",onClick:jo(m.run),children:m.label}):null,n!=null&&n.update?t.jsxs(E,{size:"sm",disabled:a,onClick:jo(()=>f(n.update)),children:["Update to ",n.update]}):null,g?null:s,!g&&!r&&o?t.jsx(E,{size:"sm",variant:"ghost",onClick:k=>{k.stopPropagation(),o()},children:"Settings"}):null,t.jsx(vO,{plugin:e}),t.jsx(Jn,{label:`More for ${e.name}`,items:[{label:"Details",onSelect:i},r?{label:"Open its page",onSelect:l}:null,o?{label:"Its settings",onSelect:o}:null,e.source.kind==="directory"&&!a?{label:"Reinstall from folder",hint:"reads its files again",onSelect:()=>f()}:null,p?{label:"Enable",hint:"all of it comes back",onSelect:u}:{label:"Disable…",hint:"keeps its data",onSelect:c},"separator",{label:"Remove…",tone:"critical",onSelect:h}]})]})})}const Dre={"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 kO({plugin:e,unlocks:n}){return n.length===0?null:t.jsxs(pe,{title:"Agents it would unlock",children:[t.jsx("div",{className:"plugins-unlocks",children:t.jsx(dt,{children:n.map(s=>t.jsx(Lre,{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:bt,children:"on the Agents page"}),"."]})]})}function Lre({plugin:e,unlock:n}){const s=jb(e,n.id),r=s.created?"up-to-date":n.drift.state,[a,i]=Dre[r];return t.jsxs("div",{className:"plugins-unlock",children:[t.jsx(ot,{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(Se,{tone:a,children:i}),e&&r==="not-accepted"?t.jsx(E,{size:"sm",variant:"accent",disabled:s.busy,onClick:s.accept,children:"Accept"}):null]})}),t.jsx(ae,{message:s.failure}),s.created?t.jsx(PP,{agent:s.created}):null]})}function nk({svg:e,name:n,version:s,by:r,pills:a}){return t.jsxs("span",{className:"plugins-sheet-title",children:[t.jsx(Qn,{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 Fre({plugin:e,listing:n,notes:s,canOpen:r,busy:a,onOpen:i,onSettings:l,onClose:o,onDisable:c,onEnable:u,onRemove:h,onUpdate:f,firstStep:m}){var x,w;const p=e.enabled===!1,v=e.author!==void 0&&e.source.kind==="directory",g=(n==null?void 0:n.summary)??e.description,k=(e.network??((w=(x=n==null?void 0:n.claims)==null?void 0:x.manifest)==null?void 0:w.network)??[]).map(N=>N.host),j=e.uses??(n==null?void 0:n.usesWords);return t.jsxs(Je,{title:t.jsx(nk,{svg:n==null?void 0:n.iconSvg,name:e.name,version:e.version,by:e.author?t.jsx(Zm,{author:e.author}):gO(e),pills:t.jsxs(t.Fragment,{children:[n?t.jsxs(t.Fragment,{children:[" · ",t.jsx(Zb,{entry:n})]}):null," · ",t.jsx(vO,{plugin:e})]})}),onClose:o,foot:t.jsxs(re,{children:[t.jsx(E,{variant:"danger-ghost",onClick:h,children:"Remove…"}),t.jsx(pt,{}),l?t.jsx(E,{variant:"ghost",onClick:l,children:"Settings"}):null,r?t.jsx(E,{onClick:i,children:"Open"}):null,p?t.jsx(E,{onClick:u,children:"Enable"}):t.jsx(E,{variant:"ghost",onClick:c,children:"Disable…"}),n!=null&&n.update?t.jsxs(E,{variant:"accent",disabled:a,onClick:()=>f(n.update),children:["Update to ",n.update]}):t.jsx(E,{disabled:a,onClick:()=>f(),children:e.source.kind==="directory"?"Reinstall from folder":"Check for an update"})]}),children:[e.error?t.jsx(Q,{tone:"critical",children:e.error}):null,s&&s.length>0?t.jsx(Q,{role:"status",children:s.join(" ")}):null,p?t.jsx(Q,{children:"Disabled: its tools, pages and watchers are off and its missions are paused. Its data is kept."}):null,!p&&e.needs&&e.needs.length>0?t.jsxs(Q,{tone:"warning",action:m?t.jsx(E,{size:"sm",variant:"accent",onClick:m.run,children:m.label}):void 0,children:["Waiting: ",tk(e),". Its tools and widgets stay off until then; its data is kept."]}):!p&&e.loaded&&e.setup?t.jsxs(Q,{tone:"warning",action:m?t.jsx(E,{size:"sm",variant:"accent",onClick:m.run,children:m.label}):void 0,children:["Not set up yet. ",e.setup.note??"Its settings say what it needs."]}):null,g?t.jsx("p",{className:"plugins-summary-full",children:g}):null,t.jsx("div",{className:"plugins-facts",children:t.jsx(Vt,{items:[{label:"From",value:Fj(e.source)},...v?[]:[{label:"Published by",value:Jb(e.source,e.publisher)}],{label:"Integrity",value:t.jsx(_j,{value:e.integrity})},{label:"Installed",value:Ye(e.installedAt)},...e.installedAs?[{label:"Installed as",value:e.installedAs}]:[],{label:"Contributes",value:mO(e.contribution)},...e.network||n?[{label:"Talks to hosts",value:xO(k)}]:[],...j?[{label:"Reaches in buddi",value:Xb(j)}]:[]]})}),t.jsx(kO,{plugin:e.name,unlocks:e.unlocks})]})}function _re({kind:e,name:n,canDisable:s,onCancel:r,onDisableInstead:a,onDisable:i,onRemove:l}){const[o,c]=d.useState(!1),[u,h]=d.useState(""),[f,m]=d.useState(!1),[p,v]=d.useState(null),g=j=>{m(!0),v(null),j().catch(x=>v(ui(x))).finally(()=>m(!1))};if(e==="disable")return t.jsxs(Rt,{title:`Disable ${n}?`,onClose:r,foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",disabled:f,onClick:r,children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:f,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(ae,{message:p})]});const k=!o||u.trim()===n;return t.jsxs(Rt,{title:`Remove ${n}?`,onClose:r,foot:t.jsxs(t.Fragment,{children:[s?t.jsx(E,{variant:"ghost",size:"sm",disabled:f,onClick:a,children:"Disable instead"}):null,t.jsx(pt,{}),t.jsx(E,{variant:"ghost",disabled:f,onClick:r,children:"Cancel"}),t.jsx(E,{variant:"danger",disabled:f||!k,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:j=>{c(j.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(oe,{label:t.jsxs(t.Fragment,{children:["Type ",t.jsx("span",{className:"mono",children:n})," to confirm"]}),children:t.jsx("input",{autoFocus:!0,value:u,onChange:j=>h(j.target.value)})}):null]}),t.jsx(ae,{message:p})]})}function zre({plugins:e,openFor:n}){return t.jsxs(Gt,{boxed:!0,summary:`Ships with buddi · ${Kr(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"),Kr(s.contribution.tools,"tool","tools")]})]},s.name)})})]})}const Ure=[{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 Bre(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 Wre({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 Hre({entry:e,busy:n,onOpen:s,onInstall:r,onUpdate:a}){var i,l;return t.jsxs(Ar,{onClick:s,label:`${e.title}: details`,children:[t.jsxs("div",{className:"plugins-card-head",children:[t.jsx(Qn,{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?` · ${Kr(e.widgets.length,"widget","widgets")}`:""]})]})]}),t.jsx("p",{className:"plugins-summary",children:e.summary}),t.jsxs("div",{className:"plugins-card-foot",children:[t.jsx(Zb,{entry:e}),e.installed?t.jsxs(Se,{children:["installed ",e.installed.version]}):null,t.jsx(pt,{}),e.update?t.jsxs(E,{size:"sm",disabled:n,onClick:jo(()=>a(e.update)),children:["Update to ",e.update]}):e.installed?null:t.jsx(E,{size:"sm",variant:"accent",disabled:n,onClick:jo(r),children:"Install"})]})]})}function Kre(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 Vre({entry:e,canOpen:n,busy:s,onOpen:r,onClose:a,onInstall:i,onUpdate:l}){var m,p,v,g,k,j,x,w;const o=(m=e.screenshots)==null?void 0:m[0],c=(((v=(p=e.claims)==null?void 0:p.manifest)==null?void 0:v.network)??[]).map(N=>N.host),u=Kre(e),h=((j=(k=(g=e.claims)==null?void 0:g.manifest)==null?void 0:k.agents)==null?void 0:j.length)??0,f=(w=(x=e.claims)==null?void 0:x.package)==null?void 0:w.dependencies;return t.jsxs(Je,{title:t.jsx(nk,{svg:e.iconSvg,name:e.title,version:e.version,by:e.author?t.jsx(Zm,{author:e.author}):"someone who gave no name",pills:t.jsxs(t.Fragment,{children:[" · ",t.jsx(Zb,{entry:e}),e.installed?t.jsxs(t.Fragment,{children:[" · ",t.jsxs(Se,{children:["installed ",e.installed.version]})]}):null]})}),onClose:a,foot:t.jsxs(re,{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(pt,{}),n?t.jsx(E,{onClick:r,children:"Open"}):null,e.update?t.jsxs(E,{variant:"accent",disabled:s,onClick:()=>l(e.update),children:["Update to ",e.update]}):e.installed?null:t.jsx(E,{variant:"accent",disabled:s,onClick:i,children:"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(Yre,{entry:e}),t.jsx("div",{className:"plugins-facts",children:t.jsx(Vt,{items:[{label:"Package",value:t.jsx("span",{className:"mono",children:`${e.npm}@${e.version}`})},...u?[{label:"Tools",value:u}]:[],...h>0?[{label:"Proposes",value:`${Kr(h,"agent","agents")}, created only if you accept`}]:[],{label:"Talks to hosts",value:xO(c)},{label:"Reaches in buddi",value:Xb(e.usesWords??[])},...f?[{label:"Dependencies",value:f.count===0?"none":`${f.count}${f.withScripts.length===0?", none of which run install scripts":`, of which these run install scripts: ${f.withScripts.join(", ")}`}`}]:[],{label:"Licence",value:t.jsxs(t.Fragment,{children:[e.license??"not stated"," · ",t.jsx(Wre,{pricing:e.pricing})]})}]})})]})}function Gre(e){return[uO(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 Yre({entry:e}){const n=e.widgets??[];return n.length===0?null:t.jsx(pe,{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:Gre(s)})]}),t.jsx("div",{className:"plugins-widget-frames",children:ure(s.sizes).map(r=>t.jsx(dO,{widget:s,size:r,svg:e.iconSvg},r))})]},s.id))})})}function qre(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 Qre({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(dO,{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:[qre(a)?"A widget":`${a.title} plugin`," · by ",((o=a.author)==null?void 0:o.name)??"someone who gave no name"," · ",uO(i.sizes)]})]}),a.installed?t.jsx("span",{className:"plugins-witem-have",children:"Installed"}):t.jsx(E,{size:"sm",variant:"accent",disabled:n,"aria-label":`Install ${a.title}`,onClick:()=>r(a),children:"Install"})]})]},`${a.npm}:${i.id}`)}))})}function Jre({kind:e="all",onKind:n,navigate:s,market:r,loading:a,busy:i,onRetry:l,onOpen:o,onInstall:c,onUpdate:u}){const[h,f]=d.useState(""),[m,p]=d.useState("all"),v=(r==null?void 0:r.plugins)??[],g=[{value:"all",label:"All"},{value:"recommended",label:"Recommended"},...Ure.filter(N=>v.some(y=>y.category===N.value))],k=v.filter(N=>{var y;return e==="widgets"&&(((y=N.widgets)==null?void 0:y.length)??0)===0||m==="recommended"&&(N.trust!=="by-buddi"||N.installed)||m!=="all"&&m!=="recommended"&&N.category!==m?!1:Bre(N,h)}),j=h.trim(),x=t.jsx("div",{className:"plugins-kind",children:t.jsx(Xt,{label:"Show",options:Xre,value:e,onChange:N=>n==null?void 0:n(N)})}),w=e==="plugins"||e==="widgets"?null:t.jsx(Zre,{kind:e,navigate:s});return e==="agents"?t.jsxs(ue,{gap:"lg",children:[x,t.jsxs("p",{className:"plugins-quiet",children:[t.jsx(ie,{name:"globe",size:14}),"Opening this tab fetched the list from withbuddi.com. Nothing else leaves."]}),w]}):t.jsxs(ue,{gap:"lg",children:[x,t.jsxs(re,{children:[t.jsx(Fm,{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:f}),t.jsx(nR,{label:"Show",options:g,value:m,onChange:p})]}),t.jsxs("p",{className:"plugins-quiet",children:[t.jsx(ie,{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(be,{children:"Asking withbuddi.com…"}):r.unavailable?t.jsx(Q,{tone:"warning",action:t.jsx(E,{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(E,{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?` ${Ye(r.fetchedAt)}`:" last time","."]}):null,k.length>0&&e==="widgets"?t.jsx(Qre,{entries:k,busy:i,onOpen:o,onInstall:c}):k.length>0?t.jsx("div",{className:"plugins-grid",children:k.map(N=>t.jsx(Hre,{entry:N,busy:i,onOpen:()=>o(N),onInstall:()=>c(N),onUpdate:y=>u(N,y)},N.npm))}):t.jsx(be,{warm:!0,title:"Nothing listed matches",children:j!==""?`No ${e==="widgets"?"widget":"plugin"} on withbuddi.com mentions “${j}”.`:e==="widgets"&&!v.some(N=>{var y;return(((y=N.widgets)==null?void 0:y.length)??0)>0})?"No plugin on withbuddi.com brings a widget yet.":v.length===0?"withbuddi.com lists no plugins yet.":"Nothing on this shelf yet."})]}),w]})}const Xre=[{value:"all",label:"All"},{value:"plugins",label:"Plugins"},{value:"widgets",label:"Widgets"},{value:"agents",label:"Agents"}];function Zre({kind:e,navigate:n}){const s=me(()=>T.catalogue(),[]),r=Sb(),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(be,{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=>Rs(c)==="ready"),o=e==="all"?l.slice(0,3):i.agents;return o.length===0?null:t.jsx(pe,{title:e==="all"?"Teammates":void 0,aside:t.jsx("a",{href:pn(),onClick:c=>{c.preventDefault(),a(pn())},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(_P,{entry:c,loaded:r,onOpen:()=>a(pn(c.name)),onAdd:()=>a(pn(c.name)),onUpdate:()=>a(pn(c.name))},c.name))})})}var td={},eae=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then},NO={},Bs={};let sk;const tae=[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];Bs.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};Bs.getSymbolTotalCodewords=function(n){return tae[n]};Bs.getBCHDigit=function(e){let n=0;for(;e!==0;)n++,e>>>=1;return n};Bs.setToSJISFunction=function(n){if(typeof n!="function")throw new Error('"toSJISFunc" is not a valid function.');sk=n};Bs.isKanjiModeEnabled=function(){return typeof sk<"u"};Bs.toSJIS=function(n){return sk(n)};var ep={};(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}}})(ep);function SO(){this.buffer=[],this.length=0}SO.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 nae=SO;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 sae=nd,CO={};(function(e){const n=Bs.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}})(CO);var EO={};const rae=Bs.getSymbolSize,R1=7;EO.getPositions=function(n){const s=rae(n);return[[0,0],[s-R1,0],[0,s-R1]]};var AO={};(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 f=0;f<i;f++){o=c=0,u=h=null;for(let m=0;m<i;m++){let p=a.get(f,m);p===u?o++:(o>=5&&(l+=n.N1+(o-5)),u=p,o=1),p=a.get(m,f),p===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}})(AO);var tp={};const za=ep,Jd=[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],Xd=[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];tp.getBlocksCount=function(n,s){switch(s){case za.L:return Jd[(n-1)*4+0];case za.M:return Jd[(n-1)*4+1];case za.Q:return Jd[(n-1)*4+2];case za.H:return Jd[(n-1)*4+3];default:return}};tp.getTotalCodewordsCount=function(n,s){switch(s){case za.L:return Xd[(n-1)*4+0];case za.M:return Xd[(n-1)*4+1];case za.Q:return Xd[(n-1)*4+2];case za.H:return Xd[(n-1)*4+3];default:return}};var $O={},np={};const Wc=new Uint8Array(512),Ff=new Uint8Array(256);(function(){let n=1;for(let s=0;s<255;s++)Wc[s]=n,Ff[n]=s,n<<=1,n&256&&(n^=285);for(let s=255;s<512;s++)Wc[s]=Wc[s-255]})();np.log=function(n){if(n<1)throw new Error("log("+n+")");return Ff[n]};np.exp=function(n){return Wc[n]};np.mul=function(n,s){return n===0||s===0?0:Wc[Ff[n]+Ff[s]]};(function(e){const n=np;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}})($O);const TO=$O;function rk(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}rk.prototype.initialize=function(n){this.degree=n,this.genPoly=TO.generateECPolynomial(this.degree)};rk.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=TO.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 aae=rk,IO={},yi={},ak={};ak.isValid=function(n){return!isNaN(n)&&n>=1&&n<=40};var ta={};const RO="[0-9]+",iae="[A-Z $%*+\\-./:]+";let Pu="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";Pu=Pu.replace(/u/g,"\\u");const lae="(?:(?![A-Z0-9 $%*+\\-./:]|"+Pu+`)(?:.|[\r
143
+ ]))+`;ta.KANJI=new RegExp(Pu,"g");ta.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");ta.BYTE=new RegExp(lae,"g");ta.NUMERIC=new RegExp(RO,"g");ta.ALPHANUMERIC=new RegExp(iae,"g");const oae=new RegExp("^"+Pu+"$"),cae=new RegExp("^"+RO+"$"),uae=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");ta.testKanji=function(n){return oae.test(n)};ta.testNumeric=function(n){return cae.test(n)};ta.testAlphanumeric=function(n){return uae.test(n)};(function(e){const n=ak,s=ta;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}}})(yi);(function(e){const n=Bs,s=tp,r=ep,a=yi,i=ak,l=7973,o=n.getBCHDigit(l);function c(m,p,v){for(let g=1;g<=40;g++)if(p<=e.getCapacity(g,v,m))return g}function u(m,p){return a.getCharCountIndicator(m,p)+4}function h(m,p){let v=0;return m.forEach(function(g){const k=u(g.mode,p);v+=k+g.getBitsLength()}),v}function f(m,p){for(let v=1;v<=40;v++)if(h(m,v)<=e.getCapacity(v,p,a.MIXED))return v}e.from=function(p,v){return i.isValid(p)?parseInt(p,10):v},e.getCapacity=function(p,v,g){if(!i.isValid(p))throw new Error("Invalid QR Code version");typeof g>"u"&&(g=a.BYTE);const k=n.getSymbolTotalCodewords(p),j=s.getTotalCodewordsCount(p,v),x=(k-j)*8;if(g===a.MIXED)return x;const w=x-u(g,p);switch(g){case a.NUMERIC:return Math.floor(w/10*3);case a.ALPHANUMERIC:return Math.floor(w/11*2);case a.KANJI:return Math.floor(w/13);case a.BYTE:default:return Math.floor(w/8)}},e.getBestVersionForData=function(p,v){let g;const k=r.from(v,r.M);if(Array.isArray(p)){if(p.length>1)return f(p,k);if(p.length===0)return 1;g=p[0]}else g=p;return c(g.mode,g.getLength(),k)},e.getEncodedBits=function(p){if(!i.isValid(p)||p<7)throw new Error("Invalid QR Code version");let v=p<<12;for(;n.getBCHDigit(v)-o>=0;)v^=l<<n.getBCHDigit(v)-o;return p<<12|v}})(IO);var PO={};const Uj=Bs,MO=1335,dae=21522,P1=Uj.getBCHDigit(MO);PO.getEncodedBits=function(n,s){const r=n.bit<<3|s;let a=r<<10;for(;Uj.getBCHDigit(a)-P1>=0;)a^=MO<<Uj.getBCHDigit(a)-P1;return(r<<10|a)^dae};var OO={};const hae=yi;function wo(e){this.mode=hae.NUMERIC,this.data=e.toString()}wo.getBitsLength=function(n){return 10*Math.floor(n/3)+(n%3?n%3*3+1:0)};wo.prototype.getLength=function(){return this.data.length};wo.prototype.getBitsLength=function(){return wo.getBitsLength(this.data.length)};wo.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 fae=wo;const mae=yi,zg=["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 yo(e){this.mode=mae.ALPHANUMERIC,this.data=e}yo.getBitsLength=function(n){return 11*Math.floor(n/2)+6*(n%2)};yo.prototype.getLength=function(){return this.data.length};yo.prototype.getBitsLength=function(){return yo.getBitsLength(this.data.length)};yo.prototype.write=function(n){let s;for(s=0;s+2<=this.data.length;s+=2){let r=zg.indexOf(this.data[s])*45;r+=zg.indexOf(this.data[s+1]),n.put(r,11)}this.data.length%2&&n.put(zg.indexOf(this.data[s]),6)};var pae=yo;const gae=yi;function bo(e){this.mode=gae.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 xae=bo;const vae=yi,jae=Bs;function ko(e){this.mode=vae.KANJI,this.data=e}ko.getBitsLength=function(n){return n*13};ko.prototype.getLength=function(){return this.data.length};ko.prototype.getBitsLength=function(){return ko.getBitsLength(this.data.length)};ko.prototype.write=function(e){let n;for(n=0;n<this.data.length;n++){let s=jae.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]+`
144
+ Make sure your charset is UTF-8`);s=(s>>>8&255)*192+(s&255),e.put(s,13)}};var wae=ko,DO={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,f,m,p,v,g,k;!o.empty();){c=o.pop(),u=c.value,f=c.cost,m=s[u]||{};for(h in m)m.hasOwnProperty(h)&&(p=m[h],v=f+p,g=l[h],k=typeof l[h]>"u",(k||g>v)&&(l[h]=v,o.push(h,v),i[h]=u))}if(typeof a<"u"&&typeof l[a]>"u"){var j=["Could not find a path from ",r," to ",a,"."].join("");throw new Error(j)}return i},extract_shortest_path_from_predecessor_list:function(s,r){for(var a=[],i=r;i;)a.push(i),s[i],i=s[i];return a.reverse(),a},find_path:function(s,r,a){var i=n.single_source_shortest_paths(s,r,a);return n.extract_shortest_path_from_predecessor_list(i,a)},PriorityQueue:{make:function(s){var r=n.PriorityQueue,a={},i;s=s||{};for(i in r)r.hasOwnProperty(i)&&(a[i]=r[i]);return a.queue=[],a.sorter=s.sorter||r.default_sorter,a},default_sorter:function(s,r){return s.cost-r.cost},push:function(s,r){var a={value:s,cost:r};this.queue.push(a),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};e.exports=n})(DO);var yae=DO.exports;(function(e){const n=yi,s=fae,r=pae,a=xae,i=wae,l=ta,o=Bs,c=yae;function u(j){return unescape(encodeURIComponent(j)).length}function h(j,x,w){const N=[];let y;for(;(y=j.exec(w))!==null;)N.push({data:y[0],index:y.index,mode:x,length:y[0].length});return N}function f(j){const x=h(l.NUMERIC,n.NUMERIC,j),w=h(l.ALPHANUMERIC,n.ALPHANUMERIC,j);let N,y;return o.isKanjiModeEnabled()?(N=h(l.BYTE,n.BYTE,j),y=h(l.KANJI,n.KANJI,j)):(N=h(l.BYTE_KANJI,n.BYTE,j),y=[]),x.concat(w,N,y).sort(function(S,C){return S.index-C.index}).map(function(S){return{data:S.data,mode:S.mode,length:S.length}})}function m(j,x){switch(x){case n.NUMERIC:return s.getBitsLength(j);case n.ALPHANUMERIC:return r.getBitsLength(j);case n.KANJI:return i.getBitsLength(j);case n.BYTE:return a.getBitsLength(j)}}function p(j){return j.reduce(function(x,w){const N=x.length-1>=0?x[x.length-1]:null;return N&&N.mode===w.mode?(x[x.length-1].data+=w.data,x):(x.push(w),x)},[])}function v(j){const x=[];for(let w=0;w<j.length;w++){const N=j[w];switch(N.mode){case n.NUMERIC:x.push([N,{data:N.data,mode:n.ALPHANUMERIC,length:N.length},{data:N.data,mode:n.BYTE,length:N.length}]);break;case n.ALPHANUMERIC:x.push([N,{data:N.data,mode:n.BYTE,length:N.length}]);break;case n.KANJI:x.push([N,{data:N.data,mode:n.BYTE,length:u(N.data)}]);break;case n.BYTE:x.push([{data:N.data,mode:n.BYTE,length:u(N.data)}])}}return x}function g(j,x){const w={},N={start:{}};let y=["start"];for(let b=0;b<j.length;b++){const S=j[b],C=[];for(let A=0;A<S.length;A++){const $=S[A],I=""+b+A;C.push(I),w[I]={node:$,lastCount:0},N[I]={};for(let P=0;P<y.length;P++){const O=y[P];w[O]&&w[O].node.mode===$.mode?(N[O][I]=m(w[O].lastCount+$.length,$.mode)-m(w[O].lastCount,$.mode),w[O].lastCount+=$.length):(w[O]&&(w[O].lastCount=$.length),N[O][I]=m($.length,$.mode)+4+n.getCharCountIndicator($.mode,x))}}y=C}for(let b=0;b<y.length;b++)N[y[b]].end=0;return{map:N,table:w}}function k(j,x){let w;const N=n.getBestModeForData(j);if(w=n.from(x,N),w!==n.BYTE&&w.bit<N.bit)throw new Error('"'+j+'" cannot be encoded with mode '+n.toString(w)+`.
145
+ Suggested mode is: `+n.toString(N));switch(w===n.KANJI&&!o.isKanjiModeEnabled()&&(w=n.BYTE),w){case n.NUMERIC:return new s(j);case n.ALPHANUMERIC:return new r(j);case n.KANJI:return new i(j);case n.BYTE:return new a(j)}}e.fromArray=function(x){return x.reduce(function(w,N){return typeof N=="string"?w.push(k(N,null)):N.data&&w.push(k(N.data,N.mode)),w},[])},e.fromString=function(x,w){const N=f(x,o.isKanjiModeEnabled()),y=v(N),b=g(y,w),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(x){return e.fromArray(f(x,o.isKanjiModeEnabled()))}})(OO);const sp=Bs,Ug=ep,bae=nae,kae=sae,Nae=CO,Sae=EO,Bj=AO,Wj=tp,Cae=aae,_f=IO,Eae=PO,Aae=yi,Bg=OO;function $ae(e,n){const s=e.size,r=Sae.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 Tae(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 Iae(e,n){const s=Nae.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 Rae(e,n){const s=e.size,r=_f.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 Wg(e,n,s){const r=e.size,a=Eae.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 Pae(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 Mae(e,n,s){const r=new bae;s.forEach(function(c){r.put(c.mode.bit,4),r.put(c.getLength(),Aae.getCharCountIndicator(c.mode,e)),c.write(r)});const a=sp.getSymbolTotalCodewords(e),i=Wj.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 Oae(r,e,n)}function Oae(e,n,s){const r=sp.getSymbolTotalCodewords(n),a=Wj.getTotalCodewordsCount(n,s),i=r-a,l=Wj.getBlocksCount(n,s),o=r%l,c=l-o,u=Math.floor(r/l),h=Math.floor(i/l),f=h+1,m=u-h,p=new Cae(m);let v=0;const g=new Array(l),k=new Array(l);let j=0;const x=new Uint8Array(e.buffer);for(let S=0;S<l;S++){const C=S<c?h:f;g[S]=x.slice(v,v+C),k[S]=p.encode(g[S]),v+=C,j=Math.max(j,C)}const w=new Uint8Array(r);let N=0,y,b;for(y=0;y<j;y++)for(b=0;b<l;b++)y<g[b].length&&(w[N++]=g[b][y]);for(y=0;y<m;y++)for(b=0;b<l;b++)w[N++]=k[b][y];return w}function Dae(e,n,s,r){let a;if(Array.isArray(e))a=Bg.fromArray(e);else if(typeof e=="string"){let u=n;if(!u){const h=Bg.rawSplit(e);u=_f.getBestVersionForData(h,s)}a=Bg.fromString(e,u||40)}else throw new Error("Invalid data");const i=_f.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(`
146
+ The chosen QR Code version cannot contain this amount of data.
147
+ Minimum version required to store current data is: `+i+`.
148
+ `);const l=Mae(n,s,a),o=sp.getSymbolSize(n),c=new kae(o);return $ae(c,n),Tae(c),Iae(c,n),Wg(c,s,0),n>=7&&Rae(c,n),Pae(c,l),isNaN(r)&&(r=Bj.getBestMask(c,Wg.bind(null,c,s))),Bj.applyMask(r,c),Wg(c,s,r),{modules:c,version:n,errorCorrectionLevel:s,maskPattern:r,segments:a}}NO.create=function(n,s){if(typeof n>"u"||n==="")throw new Error("No input text");let r=Ug.M,a,i;return typeof s<"u"&&(r=Ug.from(s.errorCorrectionLevel,Ug.M),a=_f.from(s.version),i=Bj.from(s.maskPattern),s.toSJISFunc&&sp.setToSJISFunction(s.toSJISFunc)),Dae(n,a,r,i)};var LO={},ik={};(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,f=[i.color.light,i.color.dark];for(let m=0;m<u;m++)for(let p=0;p<u;p++){let v=(m*u+p)*4,g=i.color.light;if(m>=h&&p>=h&&m<u-h&&p<u-h){const k=Math.floor((m-h)/c),j=Math.floor((p-h)/c);g=f[o[k*l+j]?1:0]}r[v++]=g.r,r[v++]=g.g,r[v++]=g.b,r[v]=g.a}}})(ik);(function(e){const n=ik;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),f=u.getContext("2d"),m=f.createImageData(h,h);return n.qrToImageData(m.data,i,c),s(f,u,h),f.putImageData(m,0,0),u},e.renderToDataURL=function(i,l,o){let c=o;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),c||(c={});const u=e.render(i,l,c),h=c.type||"image/png",f=c.rendererOpts||{};return u.toDataURL(h,f.quality)}})(LO);var FO={};const Lae=ik;function M1(e,n){const s=e.a/255,r=n+'="'+e.hex+'"';return s<1?r+" "+n+'-opacity="'+s.toFixed(2).slice(1)+'"':r}function Hg(e,n,s){let r=e+n;return typeof s<"u"&&(r+=" "+s),r}function Fae(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?Hg("M",c+s,.5+u+s):Hg("m",a,0),a=0,i=!1),c+1<n&&e[o+1]||(r+=Hg("h",l),l=0)):a++}return r}FO.render=function(n,s,r){const a=Lae.getOptions(s),i=n.modules.size,l=n.modules.data,o=i+a.margin*2,c=a.color.light.a?"<path "+M1(a.color.light,"fill")+' d="M0 0h'+o+"v"+o+'H0z"/>':"",u="<path "+M1(a.color.dark,"stroke")+' d="'+Fae(l,i,a.margin)+'"/>',h='viewBox="0 0 '+o+" "+o+'"',m='<svg xmlns="http://www.w3.org/2000/svg" '+(a.width?'width="'+a.width+'" height="'+a.width+'" ':"")+h+' shape-rendering="crispEdges">'+c+u+`</svg>
149
+ `;return typeof r=="function"&&r(null,m),m};const _ae=eae,Hj=NO,_O=LO,zae=FO;function lk(e,n,s,r,a){const i=[].slice.call(arguments,1),l=i.length,o=typeof i[l-1]=="function";if(!o&&!_ae())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=Hj.create(s,r);c(e(h,n,r))}catch(h){u(h)}})}try{const c=Hj.create(s,r);a(null,e(c,n,r))}catch(c){a(c)}}td.create=Hj.create;td.toCanvas=lk.bind(null,_O.render);td.toDataURL=lk.bind(null,_O.renderToDataURL);td.toString=lk.bind(null,function(e,n,s){return zae.render(e,s)});async function Uae(e){const n=await td.toString(e,{type:"svg",margin:4,errorCorrectionLevel:"M"});return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n)}`}const O1=10*6e4,Bae=2e3;function zO(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 f=d.useRef(n);f.current=n;const m=d.useCallback(async()=>{const p=await T.telegramPairing();r(p),u(!1),o(!1),i(await Uae(p.link).catch(()=>""))},[]);return d.useEffect(()=>{if(!s||l||c)return;let p=!1;const v=Math.min(Date.parse(s.expiresAt)||Date.now()+O1,Date.now()+O1),g=window.setInterval(()=>{if(Date.now()>=v){u(!0);return}h.current().then(k=>{var j;p||!k||(o(!0),(j=f.current)==null||j.call(f))}).catch(()=>{})},Bae);return()=>{p=!0,window.clearInterval(g)}},[s,l,c]),{offer:s,square:a,paired:l,stale:c,ask:m}}function Wae({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 Hae({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(E,{onClick:o,children:i?"Copied":"Copy link"}),t.jsx(nt,{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 UO=new Set(["approval","question"]),Ch={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."}},Kae=new Set(["agent"]),Vae={maxUrgency:"now",muted:[]};function Gae(e,n){var a;const s=Ch[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 Yae({timezone:e}){var x,w,N;const n=me(()=>T.notificationSettings(),[]),s=me(()=>T.agents(),[]),r=me(()=>T.notifications(20),[],3e4),a=me(()=>T.telegram(),[]),i=d.useRef(!1);d.useEffect(()=>{var y,b;i.current||!r.data||window.location.hash!==jv||(i.current=!0,(b=(y=document.getElementById("notifications-recent"))==null?void 0:y.scrollIntoView)==null||b.call(y,{block:"start"}))},[r.data]);const[l,o]=d.useState(null),[c,u]=d.useState(!1),[h,f]=d.useState(!1),[m,p]=d.useState(null),v=((x=n.data)==null?void 0:x.channels)??[],g=l??((w=n.data)==null?void 0:w.settings),k=y=>{g&&(f(!1),o({...g,...y}))},j=()=>{g&&(u(!0),f(!1),p(null),T.saveNotificationSettings(g).then(()=>{f(!0),o(null),n.reload()}).catch(y=>p(y instanceof he?y.message:String(y))).finally(()=>u(!1)))};return t.jsxs(ue,{gap:"lg",children:[t.jsx(pe,{title:"Notifications",aside:"What buddi tells you when you are not looking at this page.",panel:!0,foot:t.jsx(E,{variant:"accent",disabled:c||!g,onClick:j,children:"Save"}),children:t.jsxs(ue,{divided:!0,children:[t.jsx(ae,{message:n.error??m}),t.jsx(pe,{title:"Where buddi reaches you",children:g?v.length===0?t.jsxs("p",{className:"ui-card-meta",children:["No channel yet, so everything waits for you here. ",t.jsx("a",{href:_e("telegram"),children:"Set up Telegram"})," and buddi can reach you on your phone."]}):t.jsxs(ue,{gap:"sm",children:[v.map(y=>{var b;return t.jsx(tie,{channel:y,checked:(g.defaultChannel??((b=v[0])==null?void 0:b.kind))===y.kind,onPick:()=>k({defaultChannel:y.kind})},y.kind)}),t.jsx(eie,{status:a.data,listed:v.some(y=>y.kind.startsWith("telegram"))})]}):t.jsx(be,{children:"Loading…"})}),t.jsx(pe,{title:"By kind",children:g?t.jsxs(ue,{gap:"sm",children:[n3.filter(y=>!Kae.has(y)).map(y=>t.jsxs("div",{className:"pref-row nt-kind",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:Ch[y].label}),t.jsx("span",{className:"ui-field-hint",children:Ch[y].hint})]}),t.jsxs("select",{"aria-label":Ch[y].label,value:nie(g,y,v),onChange:b=>{const S={...g.perKind};b.target.value==="default"?delete S[y]:S[y]=b.target.value,k({perKind:S})},children:[t.jsx("option",{value:"default",children:"Default"}),v.map(b=>t.jsx("option",{value:b.kind,children:b.label},b.kind)),UO.has(y)?null:t.jsx("option",{value:"off",children:"Off"})]})]},y)),t.jsx("p",{className:"ui-field-hint",children:"Off keeps it in the list below and never sends it."})]}):null}),t.jsx(pe,{title:"Messages from your agents",children:g?t.jsx(qae,{settings:g,agents:((N=s.data)==null?void 0:N.agents)??[],onChange:k}):null}),t.jsx(pe,{title:"Focus schedules",children:g?t.jsxs(ue,{gap:"sm",children:[t.jsx(aie,{schedules:g.schedules,onChange:y=>k({schedules:y})}),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(oe,{label:"End of the day",children:t.jsx("input",{type:"time",value:g.endOfDay,onChange:y=>k({endOfDay:y.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(pe,{title:"The last twenty",panel:!0,flush:!0,children:[t.jsx(ae,{message:r.error}),r.data?r.data.notifications.length===0?t.jsx(be,{children:"Nothing yet. What buddi tells you will be listed here."}):t.jsx(dt,{children:r.data.notifications.map(y=>{var b;return t.jsx(ot,{title:gu(y),sub:`${mt(y.createdAt,e)} · ${Gae(y,((b=s.data)==null?void 0:b.agents)??[])} · ${sie(y,v)}`,side:t.jsx(rie,{row:y})},y.id)})}):t.jsx(be,{children:"Loading…"})]})})]})}function qae({settings:e,agents:n,onChange:s}){const r=e.perKind.agent!=="off",a=e.agents??Vae,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 Qae({timezone:e}){return t.jsx(Jae,{timezone:e,onChange:()=>{}})}function Jae({timezone:e,onChange:n}){var C,A;const s=me(()=>T.telegramBot(),[]),r=me(()=>T.telegramDevices(),[]),[a,i]=d.useState(!1),[l,o]=d.useState(""),[c,u]=d.useState(!1),[h,f]=d.useState(null),[m,p]=d.useState(null),v=d.useRef(new Set),g=zO(()=>T.telegramDevices().then($=>$.devices.some(I=>!v.current.has(I.id))),()=>{r.reload(),n()}),k=((C=s.data)==null?void 0:C.configured)??!1,j=!k||a,x=()=>{var I;if(l.trim()===""||c)return;u(!0),f(null);const $=a&&(((I=s.data)==null?void 0:I.running)??!1);T.saveTelegramToken(l.trim()).then(P=>{o(""),i(!1),f(P.restartNeeded?{ok:!1,text:P.note??"Saved. It will be ready the next time buddi starts."}:$?{ok:!0,text:"Saved. The new bot takes over the next time buddi starts."}:{ok:!0,text:"Saved."}),s.reload(),n()}).catch(P=>f({ok:!1,text:P instanceof he?P.message:String(P)})).finally(()=>u(!1))},w=()=>{var $;p(null),v.current=new Set(((($=r.data)==null?void 0:$.devices)??[]).map(I=>I.id)),g.ask().catch(I=>p(I instanceof he?I.message:String(I)))},{offer:N,square:y,paired:b,stale:S}=g;return t.jsx(pe,{title:"Telegram",aside:"Talk to buddi from your phone.",panel:!0,children:t.jsxs(ue,{divided:!0,children:[t.jsx(pe,{title:"The bot",foot:j?t.jsxs(t.Fragment,{children:[a?t.jsx(E,{variant:"ghost",onClick:()=>{i(!1),o("")},children:"Cancel"}):null,t.jsx(E,{variant:"accent",disabled:c||l.trim()==="",onClick:x,children:"Save token"})]}):void 0,children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:s.error}),!s.data&&!s.error?t.jsx(be,{children:"Loading…"}):k&&!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(E,{variant:"ghost",size:"sm",onClick:()=>{i(!0),f(null)},children:"Replace token"})]}):null,j?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"ui-card-meta",children:"Ask @BotFather for a bot and paste its token here."}),t.jsx(oe,{label:"Bot token",grow:!0,children:t.jsx("input",{type:"password",value:l,autoComplete:"off",spellCheck:!1,onChange:$=>o($.target.value),onKeyDown:$=>{$.key==="Enter"&&($.preventDefault(),x())}})})]}):null,h?t.jsx(Q,{tone:h.ok?"good":"warning",role:"status",children:h.text}):null]})}),t.jsxs(pe,{title:"Your devices",children:[t.jsx(ae,{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(dt,{children:r.data.devices.map($=>t.jsx(ot,{title:$.name??`Telegram user ${$.userId}`,sub:`Paired ${mt($.pairedAt,e)} · ${$.lastSeenAt?`last spoke ${Ye($.lastSeenAt)}`:"has not spoken yet"}`,side:t.jsx(Xae,{id:$.id,onGone:()=>{r.reload(),n()}})},$.id))}):r.error?null:t.jsx(be,{children:"Loading…"})]}),t.jsx(pe,{title:"Pair a device",foot:k&&(!N||b)?t.jsx(E,{variant:N?void 0:"accent",onClick:w,children:"Pair a phone"}):k&&S?t.jsx(E,{variant:"accent",onClick:w,children:"New code"}):void 0,children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:m}),k?b?t.jsx(Q,{tone:"good",role:"status",children:"Paired."}):N&&S?t.jsx("p",{className:"ui-card-meta",children:"That code has run out."}):N?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(Wae,{offer:N,square:y,children:t.jsx(Zae,{text:N.link})}),t.jsxs("p",{className:"ui-field-hint",children:["The code works until ",mt(N.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 Xae({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(E,{size:"sm",onClick:()=>r(!0),children:"Unpair"});const c=()=>{i(!0),o(null),T.unpairTelegramDevice(e).then(n).catch(u=>o(u instanceof he?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(E,{size:"sm",variant:"ghost",disabled:a,onClick:()=>r(!1),children:"Keep"}),t.jsx(E,{size:"sm",variant:"danger",disabled:a,onClick:c,children:"Unpair"})]})}function Zae({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(E,{size:"sm",onClick:r,children:"Copy"}),n?t.jsx("span",{className:"ui-field-hint",role:"status",children:n}):null]})}function eie({status:e,listed:n}){const s=_e("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 tie({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 he?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(E,{size:"sm",disabled:r,onClick:o,children:"Send a test"})]})}function nie(e,n,s){const r=e.perKind[n];return r==="off"?UO.has(n)?"default":"off":r&&s.some(a=>a.kind===r)?r:"default"}function sie(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 rie({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 D1={mon:"Mon",tue:"Tue",wed:"Wed",thu:"Thu",fri:"Fri",sat:"Sat",sun:"Sun"},L1={mode:"do-not-disturb",days:[...iv],from:"22:00",to:"07:00"};function aie({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:iv.map(l=>{const o=r.days.includes(l);return t.jsx("button",{type:"button",className:"nt-day","aria-pressed":o,"aria-label":`Schedule ${i} ${D1[l]}`,onClick:()=>s(a,{days:o?r.days.filter(c=>c!==l):iv.filter(c=>c===l||r.days.includes(c))}),children:D1[l]},l)})}),t.jsx(oe,{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(oe,{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(E,{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(E,{size:"sm",onClick:()=>n([...e,{...L1,days:[...L1.days]}]),children:"Add a schedule"})})]})}const iie="Remove buddi from this Mac?";function lie(){const[e,n]=d.useState(null),[s,r]=d.useState(!1),[a,i]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(!1),h=()=>{u(!0),o(null),T.uninstallPlan().then(f=>{if(!f.available){i(f.reason);return}n(f),r(!0)}).catch(f=>o(f instanceof he?f.message:String(f))).finally(()=>u(!1))};return t.jsxs(pe,{title:"Remove buddi",children:[t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:l}),a?t.jsx(Q,{children:a}):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(re,{align:"end",children:t.jsx(E,{variant:"danger",disabled:c||a!==null,onClick:h,children:"Remove buddi from this Mac…"})})]}),s&&e?t.jsx(uie,{plan:e,onClose:()=>r(!1)}):null]})}function oie(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 cie=1e3;function uie({plan:e,onClose:n}){const[s,r]=d.useState("plan"),[a,i]=d.useState(!1),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(null),[v,g]=d.useState(!1),k=d.useRef(null);d.useEffect(()=>()=>{k.current!==null&&window.clearTimeout(k.current)},[]);const j=b=>{T.uninstallJob(b).then(S=>{if(f(S.detail??S.phase),!S.finishedAt){k.current=window.setTimeout(()=>j(b),cie);return}if(S.phase!=="done"||!S.report){u(`The last backup did not finish: ${S.error??"no reason given"}. Nothing was removed.`),r("plan");return}p(S.report),r("words")}).catch(S=>{u(S instanceof he?S.message:String(S)),r("plan")})},x=()=>{u(null),r("backup"),T.uninstallBackup(e.token).then(b=>j(b.job.id)).catch(b=>{u(b instanceof he?b.message:String(b)),r("plan")})},w=()=>{u(null),r("removing"),T.uninstall({token:e.token,wroteItDown:!0,keepData:a}).catch(b=>{b instanceof he&&b.status===0||(u(b instanceof he?b.message:String(b)),r("words"))})},N=oie(e,a),y=s==="plan"?t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx(E,{variant:"accent",onClick:x,children:"Take the last backup"})]}):s==="words"?t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx(E,{variant:"danger",disabled:!l&&(m==null?void 0:m.passphrase)!==void 0,onClick:w,children:"Remove buddi"})]}):null;return t.jsx(Rt,{title:iie,onClose:s==="removing"?()=>{}:n,foot:y,children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:c}),s==="plan"||s==="backup"?t.jsxs(t.Fragment,{children:[t.jsx("p",{children:"This removes:"}),t.jsx("ul",{className:"remove-list",children:N.map(b=>t.jsx("li",{children:b},b))}),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:a,disabled:s!=="plan",onChange:b=>i(b.target.checked)}),t.jsx("span",{children:"Keep my data for a reinstall"})]}),s==="backup"?t.jsxs(Q,{role:"status",children:["Taking the last backup",h?`: ${h}`:"","…"]}):null]}):null,s==="words"&&m?t.jsxs(t.Fragment,{children:[t.jsxs("p",{children:["The last backup is ",t.jsx("span",{className:"mono",children:m.archive}),"."]}),m.passphrase?t.jsxs(t.Fragment,{children:[t.jsx("p",{children:"These six words open it. They leave this Mac's keychain with the rest, so write them down now:"}),t.jsx("p",{className:"backup-phrase mono","aria-label":"Your backup passphrase",children:m.passphrase}),m.passphraseFile?t.jsxs("p",{className:"ui-card-meta",children:["They are also in ",t.jsx("span",{className:"mono",children:m.passphraseFile}),", which only you can read. Delete it once they are written down."]}):null,t.jsx(re,{align:"end",children:t.jsx(E,{onClick:()=>{navigator.clipboard.writeText(m.passphrase).then(()=>g(!0),()=>g(!1))},children:v?"Copied":"Copy"})}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:l,onChange:b=>o(b.target.checked)}),t.jsx("span",{children:"I wrote it down"})]})]}):null,t.jsx("ul",{className:"remove-list",children:N.map(b=>t.jsx("li",{children:b},b))})]}):null,s==="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 die(){const e=me(()=>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 he?h.message:String(h))).finally(()=>s(!1))},u=o.installed[0];return t.jsx(pe,{title:"Command line",panel:!0,children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{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(re,{align:"end",children:t.jsx(E,{disabled:n,onClick:c,children:u?"Install Again":"Install Command Line Tool"})})]})})}const hie={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 fie(e){const n=EB.map(r=>({id:r.id,route:_e(r.id),label:r.label,icon:hie[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:yI(r.plugin,r.id),route:vr(r.plugin,r.id),label:r.title,icon:SM(r.icon),group:"plugins"}));return[...n,...s]}function BO(e){return CB.map(n=>({id:n.id,label:n.label,entries:e.filter(s=>s.group===n.id)})).filter(n=>n.entries.length>0)}function WO(e,n,s){return n?`${e}, ${n} open`:s?`${e}, ${s}`:void 0}function mie({entries:e,active:n,counts:s={},dots:r={},navigate:a}){var u;const i=d.useRef(null),l=BO(e),o=e.some(h=>h.id===n)?n:(u=e[0])==null?void 0:u.id,c=h=>{var v;const f=[...((v=i.current)==null?void 0:v.querySelectorAll("a.settings-nav-link"))??[]],m=f.indexOf(document.activeElement);if(m===-1)return;const p=g=>{var k;h.preventDefault(),(k=f[Math.max(0,Math.min(f.length-1,g))])==null||k.focus()};if(h.key==="ArrowDown")p(m+1);else if(h.key==="ArrowUp")p(m-1);else if(h.key==="Home")p(0);else if(h.key==="End")p(f.length-1);else if(h.key==="Enter"||h.key===" "){h.preventDefault();const g=f[m].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(f=>{const m=f.id===n,p=s[f.id],v=r[f.id];return t.jsxs("a",{className:"settings-nav-link",href:f.route,"data-active":m?"true":void 0,"aria-current":m?"page":void 0,"aria-label":WO(f.label,p,v),tabIndex:f.id===o?0:-1,onClick:g=>{g.preventDefault(),a(f.route)},children:[t.jsx(ie,{name:f.icon,className:"settings-nav-icon"}),t.jsx("span",{className:"settings-nav-text",children:f.label}),p?t.jsx("span",{className:"ui-badge settings-nav-count","aria-hidden":"true",children:p>99?"99+":p}):v?t.jsx("span",{className:"ui-badge settings-nav-dot","data-kind":"dot","data-testid":"settings-nav-dot","aria-hidden":"true"}):null]},f.id)})]},h.id))})}function pie({entries:e,active:n,counts:s={},dots:r={},navigate:a}){const i=BO(e),l=e.find(o=>o.id===n)??e[0];return t.jsx("nav",{className:"settings-menu","aria-label":"Settings sections",children:t.jsxs(Ku,{modal:!1,children:[t.jsx(Vu,{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(ie,{name:l.icon,className:"settings-nav-icon"}):null,t.jsx("span",{className:"settings-nav-text",children:l==null?void 0:l.label}),t.jsx(ie,{name:"chevron-down",className:"settings-menu-chevron"})]})}),t.jsx(Oo,{children:t.jsx(Gu,{className:"ui-menu settings-menu-list",align:"start",sideOffset:6,children:t.jsx(I6,{value:n,onValueChange:o=>{const c=e.find(u=>u.id===o);c&&a(c.route)},children:i.map((o,c)=>t.jsxs(jy,{children:[c>0?t.jsx(_r,{className:"ui-menu-sep"}):null,t.jsx(Ji,{className:"ui-menu-label",children:o.label}),o.entries.map(u=>{const h=s[u.id],f=r[u.id];return t.jsxs(R6,{value:u.id,className:"ui-menu-item settings-menu-item","data-active":u.id===n?"true":void 0,"aria-label":WO(u.label,h,f),children:[t.jsxs("span",{className:"settings-menu-entry",children:[t.jsx(ie,{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}):f?t.jsx("span",{className:"ui-badge settings-nav-dot","data-kind":"dot","aria-hidden":"true"}):null]},u.id)})]},o.id))})})})]})})}function gie({hash:e,timezone:n,navigate:s,agents:r,pluginPages:a}){var w,N,y;const i=AB(e),l=TI(a!==void 0),o=a??l,c=wI(e),u=c?o.find(c.plugin,c.page):void 0,h=u?null:mB(e,o.settings);d.useEffect(()=>{h&&s(h,!0)},[h,s]);const f=Yn(Fy),m=fie(o.settings),v={proposals:((N=(w=me(()=>Promise.resolve().then(()=>T.proposals()),[],3e4).data)==null?void 0:w.open)==null?void 0:N.length)??0},g=me(()=>T.version(),[]),k=me(()=>Promise.resolve().then(()=>T.connectionSignals()),[],6e4),j={};g.data&&!g.data.checkout&&g.data.updateAvailable&&(j.system="a newer buddi is ready"),(((y=k.data)==null?void 0:y.signals)??[]).length>0&&(j.connections=BM);const x={entries:m,active:i,counts:v,dots:j,navigate:b=>s(b)};return t.jsxs("div",{className:"settings",children:[f?null:t.jsx(mie,{...x}),t.jsx("div",{className:"settings-body",children:t.jsxs("div",{className:"ui-page",children:[i==="secrets"?t.jsx(Ui,{before:t.jsx(Oc,{inline:!0,items:[{label:"Settings",href:hn,onClick:()=>s(hn)}]}),title:"Keys and secrets",lede:nO,actions:t.jsx(nt,{variant:"accent",size:"sm",href:gv,onClick:b=>{b.preventDefault(),s(gv)},children:"Add a secret"})}):i==="computer"?t.jsx(Ui,{before:t.jsx(Oc,{inline:!0,items:[{label:"Settings",href:hn,onClick:()=>s(hn)}]}),title:"Browser & apps",lede:"Where agents may look"}):i==="plugins"||i==="connections"?t.jsx(Ui,{before:t.jsx(Oc,{inline:!0,items:[{label:"Settings",href:hn,onClick:()=>s(hn)}]}),title:i==="plugins"?"Plugins":"Connections",lede:i==="plugins"?fre:k2}):t.jsxs("header",{className:"ui-page-head",children:[t.jsx("h2",{className:"ui-page-title",children:"Settings"}),t.jsx("p",{className:"ui-page-lede",children:"How this installation runs, and where it reaches."})]}),f?t.jsx(pie,{...x}):null,u?t.jsx(WP,{plugin:u.plugin,title:u.title,navigate:s},u.plugin):null,u?t.jsx(hJ,{page:u,params:Sy(e),navigate:s,timezone:n,siblings:o.all.filter(b=>b.plugin===u.plugin)}):null,i==="you"?t.jsx(Hse,{embedded:!0}):null,i==="appearance"?t.jsx(xie,{railPages:o.rail}):null,i==="notifications"?t.jsx(Yae,{timezone:n}):null,i==="telegram"?t.jsx(Qae,{timezone:n}):null,i==="memory"?t.jsx(n2,{embedded:!0,agents:r,timezone:n,initialTab:Die(e)}):null,i==="proposals"?t.jsx(rre,{embedded:!0,plugin:kB(e)}):null,i==="accounts"?t.jsx(rse,{embedded:!0,account:pB(e)}):null,i==="computer"?t.jsx(zV,{embedded:!0,timezone:n,navigate:s}):null,i==="secrets"?t.jsx(vse,{embedded:!0,timezone:n,secret:jB(e),adding:wB(e),navigate:s}):null,i==="connections"?t.jsx(Oee,{embedded:!0,timezone:n,connection:xB(e)}):null,i==="lock"?t.jsx(_se,{navigate:s}):null,i==="api"?t.jsx(Wse,{timezone:n}):null,i==="watchers"?t.jsx(Ase,{timezone:n,embedded:!0}):null,i==="backup"?t.jsx(qne,{}):null,i==="plugins"?t.jsx(yre,{railPages:o.rail,settingsPages:o.settings,navigate:s,hash:e}):null,i==="system"?t.jsx(wie,{timezone:n}):null]})})]})}function xie({railPages:e}){const[n,s]=qM();return t.jsx(pe,{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(Kg,{label:"Theme",hint:"System follows your Mac.",children:t.jsx(Xt,{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(Kg,{label:"Background",hint:"Blue carries the first-run colours through the app. Sand is quieter.",children:t.jsx(Xt,{label:"Background",options:[{value:"blue",label:"Blue"},{value:"sand",label:"Sand"}],value:n.ground,onChange:r=>s({ground:r})})}),t.jsx(Kg,{label:"Page width",hint:"How far pages stretch on a wide screen.",children:t.jsx(Xt,{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(jie,{pages:e}),t.jsx(vie,{})]})})}function vie(){var c,u,h;const e=me(()=>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=(f,m)=>{s(f),T.setGlanceHidden(f,!m).then(()=>e.reload()).finally(()=>s(null))},o=(f,m)=>{s(`block:${f}`),T.homeDismiss(`block:${f}`,m?null:"hidden").then(()=>e.reload()).finally(()=>s(null))};return t.jsxs(t.Fragment,{children:[r.length>0?t.jsxs("div",{className:"pref-row ui-section",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:"Home glances"}),t.jsx("span",{className:"ui-field-hint",children:"The lines beside the date on Home, at most three. Kept for every browser."})]}),t.jsx(ue,{gap:"sm",children:r.map(f=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:!f.hidden,disabled:n===f.id,onChange:m=>l(f.id,m.target.checked)}),t.jsx("span",{children:f.title})]},f.id))})]}):null,a.length>0?t.jsxs("div",{className:"pref-row ui-section",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:"Home sections"}),t.jsx("span",{className:"ui-field-hint",children:"What the plugins put on Home. Kept for every browser."})]}),t.jsx(ue,{gap:"sm",children:a.map(f=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:i[`block:${f.id}`]!=="hidden",disabled:n===`block:${f.id}`,onChange:m=>o(f.id,m.target.checked)}),t.jsx("span",{children:f.title})]},f.id))})]}):null]})}function jie({pages:e}){const n=WM(),[s,r]=d.useState(null);if(e.length===0)return null;const a=(i,l)=>{r(null),aZ(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(ae,{message:s}),e.map(i=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:!n.has(Iu(i)),onChange:l=>a(i,l.target.checked)}),t.jsx("span",{children:i.title})]},Iu(i)))]})]})}function Kg({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 wie({timezone:e}){const n=me(()=>T.overview(),[],15e3),s=me(()=>T.session(),[]),r=me(()=>T.providerAccounts(),[]),a=n.data;return t.jsxs(ue,{gap:"lg",children:[t.jsx(ae,{message:n.error}),t.jsx(Pie,{}),a?t.jsx(pe,{title:"The queue",panel:!0,actions:t.jsx(E,{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(Se,{tone:"warning",children:"paused"}):t.jsx(Se,{tone:"good",children:"running"})]})}):null,t.jsxs(pe,{title:"This host",panel:!0,children:[t.jsx(Vt,{items:[{label:"Time zone",value:e},{label:"Server time",value:a?mt(a.now,e):"…"},{label:"Bound to",value:s.data?`${s.data.host}:${s.data.port}`:"…"},{label:"Credential vault",value:r.data?kie(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(bie,{}),t.jsx(yie,{}),t.jsx(yJ,{}),t.jsx(die,{}),t.jsx(Mne,{}),t.jsx(pe,{title:"Mail and sources",panel:!0,children:a?a.mail.length===0?t.jsx(be,{children:"No sources are installed."}):t.jsx(Vt,{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 ",Ye(i.lastRunAt)]})}))}):t.jsx(be,{children:"Loading…"})}),t.jsx(lie,{})]})}function El(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 F1={ready:"good",downloading:"muted",absent:"muted",failed:"critical"},_1={ready:"ready",downloading:"downloading",absent:"not downloaded",failed:"failed"};function yie(){const e=me(()=>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=m=>{a(!0),s(null),m().then(()=>e.reload()).catch(p=>{s(p.message)}).finally(()=>{a(!1)})},f=c.available?t.jsxs("span",{children:[t.jsx(Se,{tone:F1[c.state],children:_1[c.state]})," ",t.jsxs("span",{className:"ui-card-meta",children:["ONNX Runtime ",c.version," · ",c.state==="downloading"&&c.receivedBytes!==void 0?`${El(c.receivedBytes)} of ${El(c.downloadBytes)}`:`${El(c.sizeBytes)} on disk (${El(c.downloadBytes)} download)`]})]}):t.jsxs("span",{className:"ui-card-meta",children:["Not available on this platform (",c.platform,")."]});return t.jsx(pe,{title:"Local models",panel:!0,actions:c.available&&(c.state==="ready"||c.state==="failed")?t.jsx(E,{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(ae,{message:n}),i?t.jsx(Rt,{title:"Remove the engine?",onClose:()=>l(!1),foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:()=>l(!1),children:"Keep it"}),t.jsx(E,{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 (",El(c.downloadBytes),") once you say yes."]})}):null,t.jsx(Vt,{items:[{label:"Engine",value:f},...u.map(m=>({key:m.id,label:t.jsx("span",{className:"mono",children:m.id}),value:t.jsxs("span",{children:[t.jsx(Se,{tone:F1[m.state],children:_1[m.state]})," ",t.jsx("span",{className:"ui-card-meta",children:m.state==="failed"?m.reason:El(m.sizeBytes)})," ",m.state==="ready"||m.state==="failed"?t.jsx(E,{size:"sm",variant:"ghost",disabled:r,onClick:()=>{h(()=>T.removeModel(m.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 bie(){var u;const e=me(()=>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),qu({kind:h},()=>T.serviceAction(h)).then(()=>{s(null)}).catch(f=>{l(f.message),e.reload()}).finally(()=>{a(!1)})};return t.jsx(pe,{title:"Service",panel:!0,children:t.jsxs(ue,{divided:!0,children:[t.jsx(pe,{children:t.jsx(Vt,{items:[{label:"Database",value:t.jsx(z1,{state:o.database,pid:o.databasePid})},{label:"Gateway",value:t.jsx(z1,{state:o.gateway,pid:o.gatewayPid})},{label:"Supervisor",value:t.jsxs("span",{className:"mono",children:["pid ",o.supervisorPid]})}]})}),t.jsx(pe,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{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(re,{align:"end",children:n?t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",disabled:r,onClick:()=>{s(null),l(null)},children:"Cancel"}),t.jsx(E,{variant:n==="stop"?"danger":"accent",disabled:r,onClick:()=>{c(n)},children:n==="stop"?"Stop it":"Restart it"})]}):t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:()=>{s("stop")},children:"Stop gateway"}),t.jsx(E,{variant:"accent",onClick:()=>{s("restart")},children:"Restart gateway"})]})})]})})]})})}function z1({state:e,pid:n}){return t.jsxs("span",{children:[t.jsx(Se,{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 kie(e){return e==="keychain"?"macOS Keychain":e==="file"?"Encrypted file vault":e==="none"?"None":e}const Nie=2e3,zf={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."},Sie=new Set(["done","failed","rolled-back"]),Cie="The check asks the npm registry for the newest version and sends nothing else.",Eie="This takes a backup, installs the new version and restarts buddi. This page waits for it and comes back by itself.",Aie=6e4;function Vg(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:Eie}}const $ie="A checkout upgrades with git pull, then buddi upgrade in a terminal.",Tie=15*6e4;function Iie(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 U1(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<Tie?s:null}function Rie(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(f=>{var m;o||(r(f),i(null),$I({step:zf[f.phase]??f.detail??f.phase}),(Sie.has(f.phase)||f.finishedAt)&&(o=!0,f.phase==="failed"&&(ho(),(m=l.current)==null||m.call(l,f))))}).catch(f=>{o||(f instanceof he&&f.status!==0&&f.status<500?(o=!0,ho(),i(f.message)):c=!0)})};u();const h=window.setInterval(u,Nie);return()=>{o=!0,window.clearInterval(h)}},[e]),{job:s,error:a}}function Pie(){var w;const[e,n]=d.useState(!1),s=me(()=>T.version(),[],e?Aie:void 0);d.useEffect(()=>{var N;((N=s.data)==null?void 0:N.app)===!0&&n(!0)},[(w=s.data)==null?void 0:w.app]);const[r,a]=d.useState(null),[i,l]=d.useState(!1),[o,c]=d.useState(!1),[u,h]=d.useState(null),[f,m]=d.useState(null),p=d.useCallback(N=>{a(null),m(N)},[]),v=Rie(r,p),g=s.data,k=()=>{c(!0),h(null),T.checkVersion().catch(N=>h(N instanceof he?N.message:String(N))).finally(()=>{c(!1),s.reload()})},j=N=>{c(!0),h(null),T.setVersionCheck(N).catch(y=>h(y instanceof he?y.message:String(y))).finally(()=>{c(!1),s.reload()})},x=()=>{c(!0),h(null),m(null),qu({kind:"upgrade",line:g!=null&&g.latest?`Upgrading to ${g.latest}…`:"Upgrading…",step:zf.starting,patienceMs:AI},()=>T.startUpgrade(g==null?void 0:g.latest)).then(N=>{var y;l(!1),a(((y=N==null?void 0:N.job)==null?void 0:y.id)??null)}).catch(N=>h(N instanceof he?N.message:String(N))).finally(()=>c(!1))};return g!=null&&g.checkout?t.jsx(pe,{title:"Version",panel:!0,children:t.jsxs(ue,{divided:!0,children:[t.jsx(pe,{children:t.jsx(Vt,{items:[{label:"Running",value:t.jsx("span",{className:"mono",children:g.current})}]})}),t.jsx(pe,{children:t.jsx("p",{className:"ui-card-meta",children:$ie})})]})}):t.jsx(pe,{title:"Version",panel:!0,children:t.jsxs(ue,{divided:!0,children:[t.jsx(pe,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:s.error??u}),t.jsx(Vt,{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 ",Ye(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(re,{align:"end",children:t.jsx(E,{disabled:o,onClick:k,children:"Check now"})})]})}),t.jsx(pe,{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:N=>j(N.target.checked)}),t.jsx("span",{children:"Check once a day"})]}),t.jsx("p",{className:"ui-card-meta",children:Cie})]})}),g!=null&&g.updateAvailable&&g.latest&&g.latestNotes?t.jsx(pe,{title:`What changes in ${g.latest}`,children:t.jsx(wr,{text:g.latestNotes})}):null,t.jsx(pe,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(Mie,{...v,job:v.job??f??void 0}),!v.job&&!f&&!v.error&&g&&U1(g.history)?t.jsx(Q,{tone:"critical",role:"alert",children:Iie(U1(g.history),g.app===!0)}):null,i?t.jsx(Q,{tone:"warning",role:"alert",children:Vg((g==null?void 0:g.app)===!0,g==null?void 0:g.latest).warning}):null,t.jsx(re,{align:"end",children:i?t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",disabled:o,onClick:()=>l(!1),children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:o,onClick:x,children:Vg((g==null?void 0:g.app)===!0,g==null?void 0:g.latest).button})]}):g!=null&&g.processing&&r===null?null:t.jsx(E,{variant:"accent",disabled:o||r!==null||!(g!=null&&g.updateAvailable),onClick:()=>l(!0),children:Vg((g==null?void 0:g.app)===!0,g!=null&&g.updateAvailable?g.latest:void 0).button})})]})}),g&&g.history.length>0?t.jsx(pe,{title:"Upgrades so far",children:t.jsx(Vt,{items:g.history.slice().reverse().map(N=>({key:N.startedAt,label:t.jsxs("span",{className:"mono",children:[N.from," → ",N.to]}),value:t.jsx(Oie,{attempt:N})}))})}):null]})})}function Mie({job:e,error:n}){return n?t.jsx(ae,{message:n}):e?e.phase==="failed"?t.jsxs(Q,{tone:"critical",role:"alert",children:[zf.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:zf[e.phase]??e.detail??e.phase}):null}function Oie({attempt:e}){return t.jsxs("span",{children:[t.jsx(Se,{tone:e.outcome==="done"?"good":e.outcome==="failed"?"critical":"warning",children:e.outcome})," ",Ye(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 Die(e){var s;return((s=/[?&]tab=(people|preferences|notes)\b/.exec(e))==null?void 0:s[1])??"people"}const Ze={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 Hc(e){return e instanceof he||e instanceof Error?e.message:String(e)}function Fi({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 Lie=1400;function HO(e,n){const s=d.useRef(n);s.current=n,d.useEffect(()=>{if(!e)return;const r=window.setTimeout(()=>s.current(),Lie);return()=>window.clearTimeout(r)},[e])}function KO(){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 Fie={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}},_ie=["gmail","icloud","fastmail","other"],Gg={plugin:"email",agent:"mail-triage"};function zie({onClose:e,onAdded:n}){const[s,r]=d.useState(null);return t.jsx(Je,{title:Ze.mailbox.sheet,onClose:e,children:s===null?t.jsxs("div",{className:"wiz-sheet-body",children:[t.jsx("h3",{className:"frs-ask",children:Ze.mailbox.which}),t.jsx("div",{className:"frs-choices",role:"group","aria-label":Ze.mailbox.which,children:_ie.map(a=>{const i=Ze.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(ie,{name:"chevron-right"})]},a)})}),t.jsx("p",{className:"frs-later",children:Ze.mailbox.later})]}):t.jsx(Uie,{provider:s,onBack:()=>r(null),onClose:e,onAdded:n},s)})}function Uie({provider:e,onBack:n,onClose:s,onAdded:r}){const a=KO(),[i,l]=d.useState(""),[o,c]=d.useState(""),[u,h]=d.useState(""),[f,m]=d.useState(""),[p,v]=d.useState({kind:"idle"});HO(p.kind==="good",s);const[g,k]=d.useState(!1);d.useEffect(()=>{let y=!1;return Promise.resolve().then(()=>Qe.agents()).then(b=>{y||k(!((b==null?void 0:b.agents)??[]).some(S=>S.id===Gg.agent))}).catch(()=>{y||k(!1)}),()=>{y=!0}},[]);const j=Ze.mailbox.providers[e],x=Ze.mailbox.how[e],w=i.trim()!==""&&o.trim()!==""&&p.kind!=="busy"&&p.kind!=="good",N=()=>{if(!w)return;v({kind:"busy"});const y=e==="other"?{...u.trim()?{imapHost:u.trim()}:{},...f.trim()?{smtpHost:f.trim()}:{}}:Fie[e];Promise.resolve().then(()=>T.pageAct("email",{tool:"email.add_account",args:{address:i.trim(),password:o,...y}})).then(async b=>{const S=b.result??{};c("");let C=Ze.mailbox.reading;S.triage==="needs-agent"&&(C=await Promise.resolve().then(()=>T.acceptPluginAgent(Gg.plugin,Gg.agent)).then(()=>(window.dispatchEvent(new Event(ks)),Ze.mailbox.reading)).catch(A=>Ze.mailbox.noTriage(Hc(A)))),v({kind:"good",line:C}),r(S.address??i.trim().toLowerCase())}).catch(b=>v({kind:"bad",line:Hc(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:j.mark}),j.name]}),t.jsxs("form",{className:"frs-form",onSubmit:y=>{y.preventDefault(),N()},children:[t.jsx(oe,{label:Ze.mailbox.address,children:t.jsx("input",{ref:a,type:"email",autoComplete:"email",spellCheck:!1,value:i,onChange:y=>l(y.target.value)})}),t.jsx(oe,{label:e==="other"?Ze.mailbox.otherPassword:Ze.mailbox.password,hint:x?t.jsxs(t.Fragment,{children:[x.text," ",t.jsx("a",{href:x.href,target:"_blank",rel:"noreferrer",children:x.link})]}):void 0,children:t.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,value:o,onChange:y=>c(y.target.value)})}),e==="other"?t.jsx(Gt,{summary:Ze.mailbox.server,children:t.jsxs("div",{className:"frs-form",children:[t.jsx("p",{className:"frs-later",children:Ze.mailbox.serverHint}),t.jsx(oe,{label:Ze.mailbox.imapHost,children:t.jsx("input",{spellCheck:!1,placeholder:"imap.example.com",value:u,onChange:y=>h(y.target.value)})}),t.jsx(oe,{label:Ze.mailbox.smtpHost,children:t.jsx("input",{spellCheck:!1,placeholder:"smtp.example.com",value:f,onChange:y=>m(y.target.value)})})]})}):null,t.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]}),p.kind==="busy"?t.jsx(Fi,{state:"busy",children:Ze.checking}):null,p.kind==="good"?t.jsx(Fi,{state:"good",children:p.line}):null,p.kind==="bad"?t.jsx(Fi,{state:"bad",children:p.line}):null,p.kind==="idle"&&g?t.jsx("p",{className:"frs-later",children:Ze.mailbox.brings}):null,t.jsx("p",{className:"frs-later",children:Ze.mailbox.later})]}),t.jsx("div",{className:"ui-sheet-foot",children:t.jsxs(re,{children:[t.jsxs(E,{variant:"ghost",onClick:n,disabled:p.kind==="busy",children:[t.jsx(ie,{name:"chevron-left"}),Ze.back]}),t.jsx(pt,{}),t.jsx(E,{variant:"accent",disabled:!w,onClick:N,children:Ze.mailbox.submit})]})})]})}const VO=2e3,B1=8*6e4;function Bie(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 Wie({onClose:e,onLinked:n}){var W,M,L;const s=KO(),[r,a]=d.useState(null),[i,l]=d.useState(""),[o,c]=d.useState({kind:"idle"});HO(o.kind==="good",e);const u=()=>T.pageQuery("calendar","settings").then(_=>_.data??{});d.useEffect(()=>{let _=!1;return u().then(Y=>{_||a(Y)}).catch(()=>{_||a({})}),()=>{_=!0}},[]);const h=_=>{c({kind:"good",line:_}),n(_)},f=((W=r==null?void 0:r.calendars)==null?void 0:W.length)??0,m=()=>{if(i.trim()===""||o.kind==="busy"||o.kind==="good")return;c({kind:"busy",line:Ze.checking});const _=Bie(i,((r==null?void 0:r.calendars)??[]).map(Y=>Y.name));Promise.resolve().then(()=>T.pageAct("calendar",{tool:"calendar.add",args:{name:_,link:i.trim()}})).then(Y=>{var G;l("");const B=((G=Y.result)==null?void 0:G.note)??"",se=/(\d+) events? read/.exec(B);h(se?Ze.calendar.events(Number(se[1])):Ze.calendar.found(1))}).catch(Y=>c({kind:"bad",line:Hc(Y)}))},[p,v]=d.useState(null),[g,k]=d.useState(!1),[j,x]=d.useState(0),w=d.useRef(!1),N=d.useRef(void 0),y=(r==null?void 0:r.googleAvailable)===!0,b=d.useRef(null);d.useEffect(()=>{if(!y)return;let _=!1;const Y=async se=>{var G,X;if(!(_||w.current)){window.clearTimeout(N.current);try{const K=q=>{const ce=q==null?void 0:q[0];return ce&&ce.state==="waiting"&&ce.url?ce:void 0};let J=se?void 0:K((G=(await T.pageQuery("calendar","sign_in")).data)==null?void 0:G.rows);if(!J){if(_||w.current)return;await T.pageAct("calendar",{tool:"calendar.google_sign_in",args:{}}),J=K((X=(await T.pageQuery("calendar","sign_in")).data)==null?void 0:X.rows)}if(_||w.current)return;if(!J)throw new Error("no address to open");b.current={id:J.id,at:Date.now()},v({id:J.id,url:J.url}),k(!1),N.current=window.setTimeout(()=>void Y(!0),B1)}catch{_||(b.current=null,v(null),k(!0))}}},B=()=>{const se=b.current;document.visibilityState!=="visible"||!se||w.current||Date.now()-se.at>=B1&&Y(!0)};return document.addEventListener("visibilitychange",B),Y(!1),()=>{_=!0,window.clearTimeout(N.current),document.removeEventListener("visibilitychange",B);const se=b.current;b.current=null,se&&!w.current&&T.pageAct("calendar",{tool:"calendar.google_cancel",args:{id:se.id}}).catch(()=>{})}},[y,j]);const S=_=>{c({kind:"bad",line:_}),w.current=!1,v(null),x(Y=>Y+1)},[C,A]=d.useState(0),$=o.kind==="google"?((M=o.signIn)==null?void 0:M.id)??null:null;d.useEffect(()=>{if(C===0)return;let _=!1,Y=!1,B=!1;const se=()=>{_=!0,window.clearInterval(X)},G=()=>{_||Y||(Y=!0,T.pageQuery("calendar","sign_in").then(async K=>{var xe,Me,H,ne;if(_)return;const J=((Me=(xe=K.data)==null?void 0:xe.rows)==null?void 0:Me[0])??null;if(!J)return;if(J.state==="waiting"){c(Z=>{var ye;return Z.kind==="google"&&((ye=Z.signIn)==null?void 0:ye.url)===J.url?Z:{kind:"google",signIn:J}});return}if(J.state==="failed"){se(),S(J.problem||J.note);return}se(),J.state==="received"&&!B&&(B=!0,c({kind:"busy",line:Ze.calendar.reading}),await T.pageAct("calendar",{tool:"calendar.google_finish",args:{id:J.id}}));const q=await u();await T.pageAct("calendar",{tool:"calendar.google_dismiss",args:{id:J.id}}).catch(()=>{});const ce=(((H=q.calendars)==null?void 0:H.length)??0)-f;h(Ze.calendar.found(ce>0?ce:((ne=q.calendars)==null?void 0:ne.length)??0))}).catch(K=>{se(),S(Hc(K))}).finally(()=>{Y=!1}))},X=window.setInterval(G,VO);return G(),()=>{_=!0,window.clearInterval(X)}},[C]);const I=()=>{!p||o.kind==="google"||(w.current=!0,window.clearTimeout(N.current),c({kind:"google",signIn:{id:p.id,url:p.url,state:"waiting",note:"",problem:""}}),A(_=>_+1))},P=()=>{w.current=!0,window.clearTimeout(N.current),c({kind:"busy",line:Ze.calendar.starting}),Promise.resolve().then(()=>T.pageAct("calendar",{tool:"calendar.google_sign_in",args:{}})).then(()=>{c({kind:"google",signIn:null}),A(_=>_+1)}).catch(_=>S(Hc(_)))},O=()=>{const _=$??(o.kind!=="good"?p==null?void 0:p.id:void 0);window.clearTimeout(N.current),_&&T.pageAct("calendar",{tool:"calendar.google_cancel",args:{id:_}}).catch(()=>{}),e()},R=o.kind==="busy"||o.kind==="google"||o.kind==="good",D=o.kind==="google"?(L=o.signIn)==null?void 0:L.url:o.kind==="busy"||o.kind==="good"||p==null?void 0:p.url,U=o.kind==="google"&&p===null;return t.jsxs(Je,{title:Ze.calendar.sheet,onClose:O,children:[t.jsxs("div",{className:"wiz-sheet-body",children:[t.jsx("h3",{className:"frs-ask",children:Ze.calendar.ask}),r!=null&&r.googleAvailable?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"frs-google",children:[D?t.jsxs(nt,{variant:"accent",size:"lg",href:D,target:"_blank",rel:"noreferrer",onClick:I,children:[U?Ze.calendar.continue:Ze.calendar.google,t.jsx(ie,{name:"external"})]}):t.jsxs(E,{variant:"accent",size:"lg",disabled:R||!g,onClick:P,children:[Ze.calendar.google,t.jsx(ie,{name:"external"})]}),t.jsx("span",{className:"wiz-opt-line",children:Ze.calendar.googleLine})]}),t.jsx("div",{className:"frs-or",children:Ze.calendar.or})]}):null,t.jsxs("form",{className:"frs-form",onSubmit:_=>{_.preventDefault(),m()},children:[t.jsx(oe,{label:Ze.calendar.field,children:t.jsx("input",{ref:s,type:"url",inputMode:"url",autoComplete:"off",spellCheck:!1,placeholder:Ze.calendar.placeholder,value:i,disabled:R,onChange:_=>l(_.target.value)})}),t.jsx(Gt,{summary:Ze.calendar.where,children:t.jsx("dl",{className:"frs-help",children:Ze.calendar.help.map(_=>t.jsxs("div",{children:[t.jsx("dt",{children:_.name}),t.jsx("dd",{children:_.text})]},_.name))})}),t.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]}),o.kind==="busy"?t.jsx(Fi,{state:"busy",children:o.line}):null,o.kind==="google"?t.jsx(Fi,{state:"busy",children:Ze.calendar.waiting}):null,o.kind==="good"?t.jsx(Fi,{state:"good",children:o.line}):null,o.kind==="bad"?t.jsx(Fi,{state:"bad",children:o.line}):null,t.jsx("p",{className:"frs-later",children:Ze.calendar.later})]}),t.jsx("div",{className:"ui-sheet-foot",children:t.jsx(re,{align:"end",children:t.jsx(E,{variant:"accent",disabled:R||i.trim()==="",onClick:m,children:Ze.calendar.submit})})})]})}function Hie({onClose:e,onUnderstood:n}){return t.jsxs(Je,{title:Ze.bank.sheet,onClose:e,children:[t.jsxs("div",{className:"wiz-sheet-body",children:[t.jsx("h3",{className:"frs-ask",children:Ze.bank.ask}),t.jsx("p",{className:"frs-text",children:Ze.bank.line})]}),t.jsx("div",{className:"ui-sheet-foot",children:t.jsx(re,{align:"end",children:t.jsx(E,{variant:"accent",onClick:()=>{n(),e()},children:Ze.bank.ok})})})]})}function Kie(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 Vie({progress:e}){return t.jsxs(ue,{gap:"sm",children:[t.jsx("span",{role:"status",children:Kie(e)}),t.jsx(zy,{value:(e==null?void 0:e.percent)??0,label:"Fetching the browser"})]})}const Uf=["hello","brain","takeOn","reach","assistant","handover"],GO={hello:"you",brain:"model",takeOn:"take-on",reach:"reach",assistant:"agent",handover:"hello"};function YO(e){return((e==null?void 0:e.accounts)??[]).filter(n=>n.enabled&&n.configured&&n.removalPending!==!0)}function Gie(e){var i,l,o;const n=YO(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 qO(e){var i,l,o,c,u;const n=Gie(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 QO(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 Eh(e){return Uf.find(n=>!QO(e,n))??"handover"}function Yie(e){const n=Uf.indexOf(e);return n>0?Uf[n-1]:null}function W1(e,n,s){return s===n?"now":QO(e,s)?"done":"todo"}function qie(e,n){return{...e}}const Kj="buddi.firstRun.restore";function Vj(e){try{e===null?window.sessionStorage.removeItem(Kj):window.sessionStorage.setItem(Kj,e)}catch{}}function JO(){try{return window.sessionStorage.getItem(Kj)}catch{return null}}function Qie(e){const n=qO(e),s=Eh(n);return{answers:n,open:s,stay:s!=="handover"}}function Jie(e){return e.trim().startsWith("sk-ant-")?"anthropic":"openai"}function Xie(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 Zie=6e4,ele=5*6e4,XO=1500,tle=2e3,nle="(max-width: 720px)";function Ho(){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 ok=d.createContext({busy:0,report:()=>{}});function sle({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(ok.Provider,{value:a,children:e})}function vt({children:e}){const{busy:n}=d.useContext(ok);return t.jsxs("div",{className:"wiz-say",children:[t.jsx(Ju,{state:n>0?"working":"idle",size:"sm",className:"wiz-say-face"}),t.jsx("div",{className:"wiz-bubble",children:e})]})}function ct({children:e}){return t.jsx(t.Fragment,{children:e})}function bs({line:e}){const{report:n}=d.useContext(ok);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 ck=d.createContext(null);function bn({children:e,actions:n}){const s=d.useContext(ck),r=n==null?null:s?Ao.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 Os({onClick:e,disabled:n}){return t.jsxs(E,{variant:"ghost",size:"lg",onClick:e,disabled:n,children:[t.jsx(ie,{name:"chevron-left"}),z.back]})}function Ko({children:e,onClick:n,disabled:s}){return t.jsxs(E,{variant:"accent",size:"lg",onClick:n,disabled:s,children:[e,t.jsx(ie,{name:"arrow"})]})}function rle({navigate:e,timezone:n}){var zn,Yt,Un,xn,vn,Xn,_t;const s=Yn(nle),[r,a]=d.useState(void 0);d.useEffect(()=>{T.session().then(Te=>a(Te.platform)).catch(()=>{})},[]);const[i,l]=d.useState({}),[o,c]=d.useState(null),[u,h]=d.useState(void 0),[f,m]=d.useState(void 0),[p,v]=d.useState([]),[g,k]=d.useState(null),[j,x]=d.useState(null),[w,N]=d.useState(!1),[y,b]=d.useState(null),[S,C]=d.useState(null),[A,$]=d.useState(null),[I,P]=d.useState(null),[O,R]=d.useState(()=>JO()?"running":"idle"),[D,U]=d.useState({}),[W,M]=d.useState([]),[L,_]=d.useState(0),Y=d.useRef(void 0),[B,se]=d.useState(null),[G,X]=d.useState(null),K=d.useCallback(()=>{Promise.resolve().then(()=>T.takeOnProgress()).then(Te=>{Te&&Array.isArray(Te.plugins)&&se(Te)}).catch(()=>{})},[]);d.useEffect(()=>{if(!(B!=null&&B.running))return;const Te=window.setInterval(K,tle);return()=>window.clearInterval(Te)},[B==null?void 0:B.running,K]);const J=d.useMemo(()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone||n}catch{return n}},[n]),q=d.useRef(e);q.current=e;const ce=d.useCallback(async(Te=!0,rt=!1)=>{var ut,Bn,Sn,Zn,Ws,Pn,bi,sr,$r;const[De,tt,F,Fe,Ct,on]=await Promise.all([T.onboarding().catch(()=>{}),T.owner().catch(()=>{}),T.providerAccounts().catch(()=>{}),Qe.agents().catch(()=>{}),T.browser().catch(()=>{}),T.providers().catch(()=>{})]);h(F),Array.isArray(De==null?void 0:De.offers)&&X(De.offers);const $e=(Bn=(ut=on==null?void 0:on.providers.find(Mn=>Mn.kind==="anthropic"))==null?void 0:ut.defaultModel)==null?void 0:Bn.trim();m($e||void 0),v((tt==null?void 0:tt.zones)??[]),b(((Sn=De==null?void 0:De.details)==null?void 0:Sn.conversationId)??null);const Oe=(Fe==null?void 0:Fe.agents.find(Mn=>Mn.id===Fe.defaultAgentId))??(Fe==null?void 0:Fe.agents[0]);Oe&&k(Oe),C(De&&!De.needs.agent&&Oe?{id:Oe.id,name:Oe.name,avatar:((Zn=Oe.avatar)==null?void 0:Zn.kind)==="emoji"?Oe.avatar.value:"",description:Oe.description,...Oe.picture?{picture:Oe.picture}:{}}:null),Array.isArray((Ws=De==null?void 0:De.details)==null?void 0:Ws.takeOn)&&K();const it={onboarding:De,owner:tt,accounts:F,browser:(Pn=Ct==null?void 0:Ct.browser)==null?void 0:Pn.engine,...Oe?{assistant:{id:Oe.id,name:Oe.name,avatar:((bi=Oe.avatar)==null?void 0:bi.kind)==="emoji"?Oe.avatar.value:""}}:{}};if(rt){const Mn=Qie(it);if(l(Mn.answers),c(Mn.open),!Mn.stay){const At=(sr=De==null?void 0:De.details)==null?void 0:sr.conversationId;q.current(At&&Oe?lt(Oe.id,At):Tn,!0)}return}if(Te&&(De==null?void 0:De.state)==="done"){const Mn=($r=De.details)==null?void 0:$r.conversationId;q.current(Mn&&Oe?lt(Oe.id,Mn):Tn,!0);return}if(!Te)return;const jt=qO(it);l(jt),c(Mn=>Mn??Eh(jt))},[]);d.useEffect(()=>{ce()},[ce]);const xe=(Te,rt={})=>{Promise.resolve().then(()=>T.onboardingStep(GO[Te],rt)).catch(()=>{})},Me=Te=>Eh(Te)==="brain"&&D.brain?{...Te,brain:D.brain}:Te,H=(Te,rt)=>{const De=Me(rt);De.brain&&(Y.current=De.brain),x(null),M([]),l(De),Te==="brain"&&De.brain?xe(Te,{accountId:De.brain.accountId}):Te==="reach"?xe(Te,De.reach?{reach:De.reach}:{}):Te!=="takeOn"&&xe(Te),c(Eh(De))},ne=(Te,rt)=>{x(null),l(rt),rt.brain&&(Y.current=rt.brain),Te==="brain"&&rt.brain&&xe(Te,{accountId:rt.brain.accountId})},Z=Te=>{x(null),l(rt=>qie(rt)),c(Te)},ye=()=>{if(!o)return;const Te=Yie(o==="handover"?"handover":o);Te&&Z(Te)},Ce=()=>{const Te=i.brain??Y.current,rt=((B==null?void 0:B.plugins)??[]).filter(De=>De.state==="ready").map(De=>De.title);x(null),U({}),M([]),l({}),c("hello"),_(De=>De+1),(async()=>{var $e;const[De,tt,F]=await Promise.all([Promise.resolve().then(()=>T.providerAccounts()).catch(()=>{}),Promise.resolve().then(()=>T.telegram()).catch(()=>{}),Promise.resolve().then(()=>T.browser()).catch(()=>{})]),Fe=YO(De),Ct=Te&&Fe.some(Oe=>Oe.id===Te.accountId)?Te:void 0;De&&h(De),U(Ct?{brain:Ct}:{});const on=[...new Set(Fe.map(Oe=>Oe.label)),...tt!=null&&tt.paired?[z.startOver.telegram]:[],...(($e=F==null?void 0:F.browser)==null?void 0:$e.engine)==="chromium"?[z.startOver.browser]:[],...rt];M(on.length>0?[z.startOver.said(on.join(", "))]:[])})()},ke=()=>{N(!0),T.skipOnboarding().then(()=>e(Tn)).catch(Te=>x(Te instanceof he?Te.message:String(Te))).finally(()=>N(!1))},we=me(()=>T.version().catch(()=>({current:""})),[]),ve=d.useRef(null);d.useEffect(()=>{ve.current&&(ve.current.scrollTop=0)},[o]);const Ie=O==="running",Re=Object.keys(i).length===0,de={answers:i,accounts:u,claudeModel:f,zones:p,browserZone:J,assistantAgent:g,met:y,onMet:b,existing:S,progress:B,offers:G,onProgress:K,navigate:e,onSettled:Te=>o&&H(o,Te),onKept:Te=>o&&ne(o,Te),onBack:ye,onTrouble:x,onReload:()=>void ce(!1),onPickAnotherBrain:()=>Z("brain"),onSpoken:P},Ee=(i.takeOn??[]).map(Te=>{var rt;return((rt=df.find(De=>De.id===Te))==null?void 0:rt.title)??Te}),ze=(B==null?void 0:B.plugins)??[],qe=ze.filter(Te=>Te.state==="ready").length,ht=ze.length===0?null:B!=null&&B.running?z.takeOn.installing(qe,ze.length):qe===ze.length?z.takeOn.installed:null,le=[(zn=i.reach)!=null&&zn.phone?z.reach.done.phone:null,(Yt=i.reach)!=null&&Yt.mailbox?z.reach.done.mailbox:null,(Un=i.reach)!=null&&Un.app||(xn=i.reach)!=null&&xn.browser?z.reach.done.app:null].filter(Te=>Te!==null),je={hello:{answer:z.hello.answer(i.name??""),sub:i.clock??null},brain:{answer:z.brain.answer(((vn=i.brain)==null?void 0:vn.label)??"")},takeOn:{answer:z.takeOn.answer(Ee),sub:ht},reach:{answer:z.reach.answer(le)},assistant:{answer:((Xn=i.assistant)==null?void 0:Xn.name)??""}},et=Uf.filter(Te=>Te!=="handover"),ft=o===null||o==="handover"?et.length:et.indexOf(o),Et=Math.min(ft,et.length-1),Ft=I?null:t.jsxs("div",{className:"wiz-map-out",children:[t.jsx("button",{type:"button",className:"wiz-link",disabled:w,onClick:ke,children:z.later}),o==="hello"&&Re&&O==="idle"?t.jsx("button",{type:"button",className:"wiz-link",onClick:()=>R("form"),children:z.restore.offer}):!Ie&&o!==null&&!(o==="hello"&&Re)?t.jsx("button",{type:"button",className:"wiz-link",disabled:w,onClick:Ce,children:z.startOver.link}):null]}),Pt=r===void 0||r==="darwin"?z.tagline:z.taglineElsewhere,Rn=o&&o!=="handover"?t.jsx("span",{className:"wiz-count",children:z.count(ft+1)}):t.jsx("span",{className:"wiz-count"});return t.jsx(ck.Provider,{value:A,children:t.jsx(sle,{children:t.jsxs(rR,{className:"wiz-ground",children:[t.jsx("div",{className:"wiz",ref:ve,"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(ku,{size:"sm"}),t.jsx("span",{className:"wiz-dots","aria-label":o&&o!=="handover"?z.count(ft+1):void 0,children:et.map(Te=>t.jsx("i",{"data-state":W1(i,o,Te)},Te))}),t.jsx("span",{className:"wiz-strip-name",children:o&&o!=="handover"?z.strip(ft+1,z.chapters[ft]??""):z.handover.starterLabel})]}):t.jsxs("nav",{className:"wiz-map","aria-label":"Chapters",children:[t.jsxs("div",{className:"wiz-head",children:[t.jsx(ku,{size:"lg"}),t.jsxs("div",{children:[t.jsx("div",{className:"wiz-head-name",children:"buddi"}),t.jsx("div",{className:"wiz-head-line",children:Pt}),(_t=we.data)!=null&&_t.current?t.jsxs("div",{className:"wiz-head-version mono",children:["buddi ",we.data.current]}):null]})]}),et.map((Te,rt)=>{const De=Ie?Te==="hello"?"now":"todo":W1(i,o,Te),tt=je[Te];return t.jsxs("div",{className:"wiz-ch","data-state":De,"aria-current":De==="now"?"step":void 0,children:[t.jsx("span",{className:"wiz-num","data-state":De,children:De==="done"?t.jsx(ie,{name:"check",size:12}):rt+1}),t.jsxs("span",{className:"wiz-ch-label",children:[De==="done"?tt.answer:z.chapters[rt],De==="done"&&tt.sub?t.jsx("span",{className:"wiz-ch-sub",children:tt.sub}):null]}),De==="done"&&!Ie?t.jsx("button",{type:"button",className:"wiz-link",onClick:()=>Z(Te),children:z.change}):null]},Te)}),t.jsx("div",{className:"wiz-map-spacer"}),t.jsx("div",{className:"wiz-map-note",children:z.mapNotes[Et]}),Ft]}),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(D8,{dock:t.jsxs(t.Fragment,{children:[Rn,t.jsx("div",{className:"wiz-dock-actions",ref:$})]}),children:[Ie?t.jsx(Dle,{onDone:Te=>{R("idle"),M([...Te?[z.restore.welcome(Te)]:[],z.restore.keys]),ce(!0,!0)},onFailed:Te=>{R("idle"),x(Te)}}):o==="hello"?t.jsx(ale,{...de}):o==="brain"?t.jsx(lle,{...de}):o==="takeOn"?t.jsx(Nle,{...de}):o==="reach"?t.jsx(Sle,{...de}):o==="assistant"?t.jsx(Rle,{...de}):o==="handover"?t.jsx(Ple,{...de}):t.jsx(bs,{}),W.length>0||j?t.jsxs(ct,{children:[W.map(Te=>t.jsx(vt,{children:Te},Te)),j?t.jsx(vt,{children:j}):null]}):null]},`${L}-${o??""}-${Ie?"r":""}`),s?t.jsx("div",{className:"wiz-phone-out",children:Ft}):null]})})]})}),O==="form"?t.jsx(Ole,{onCancel:()=>R("idle"),onStarted:()=>R("running"),onTrouble:x}):null]})})})}function Vo({children:e}){return t.jsx("h1",{className:"wiz-title",children:e})}function H1(e){try{return Tt(new Date,e)}catch{return""}}function ale({answers:e,zones:n,browserZone:s,onSettled:r,onTrouble:a}){const i=Ho(),[l,o]=d.useState(e.name??""),[c,u]=d.useState(e.clock??s),[h,f]=d.useState(!1),[m,p]=d.useState(!1),v=()=>{const g=l.trim();g===""||m||(p(!0),T.setOwner({preferredName:g,timezone:c}).then(()=>r({...e,name:g,clock:c})).catch(k=>a(k instanceof he?k.message:String(k))).finally(()=>p(!1)))};return t.jsxs(t.Fragment,{children:[t.jsx(Vo,{children:z.hello.title}),t.jsx(ct,{children:z.hello.opening.map(g=>t.jsx(vt,{children:g},g))}),t.jsxs(bn,{actions:t.jsx(Ko,{onClick:v,disabled:m||l.trim()==="",children:z.hello.submit}),children:[t.jsxs("div",{className:"wiz-pair",children:[t.jsx(oe,{label:z.name.label,children:t.jsx("input",{ref:i,placeholder:z.name.placeholder,maxLength:80,value:l,onChange:g=>o(g.target.value),onKeyDown:g=>{g.key==="Enter"&&(g.preventDefault(),v())}})}),h?t.jsx(oe,{label:z.clock.label,hint:z.clock.hint(H1(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(oe,{label:z.clock.label,hint:z.clock.hint(H1(c)),action:t.jsx(E,{size:"lg",onClick:()=>f(!0),children:z.clock.change}),children:t.jsx("input",{value:c,readOnly:!0})})]}),t.jsx("div",{className:"wiz-foot",children:z.hello.foot})]})]})}const ile={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 lle(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"),[f,m]=d.useState(null),[p,v]=d.useState(!1),[g,k]=d.useState(null),[j,x]=d.useState(null),[w,N]=d.useState(null),y=(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 L=!1;const _=()=>{Promise.resolve().then(()=>T.ollama()).then(B=>{!L&&B&&k(B)}).catch(()=>{}),Promise.resolve().then(()=>T.mlxh()).then(B=>{!L&&B&&x(B)}).catch(()=>{L||x({running:!1,baseUrl:"",manager:!1,models:[]})})};_();const Y=window.setInterval(_,4e3);return()=>{L=!0,window.clearInterval(Y)}},[]);const $=async L=>{if(s.assistant??e.existing)try{await T.bindBrain({accountId:L.accountId,model:L.model})}catch(_){return _ instanceof he?_.message:String(_)}return i(),a({...s,brain:L}),C==null||C.close(),A(null),c(null),N(null),null},I=async(L,_,Y)=>{v(!0),m(null);try{const B=await T.saveProviderAccount(L);let se=await T.testProviderAccount(B.id),G=L.defaultModel,X=!1;if(se.state!=="connected"&&Y&&Y!==G&&Y2(se)){const J=(await T.providerAccounts()).accounts.find(q=>q.id===B.id);J&&(await T.saveProviderAccount({id:J.id,revision:J.revision,label:J.label,kind:J.kind,auth:J.auth,baseUrl:J.baseUrl,defaultModel:Y,enabled:J.enabled}),se=await T.testProviderAccount(B.id),se.state==="connected"&&(G=Y,X=!0))}if(se.state!=="connected"){try{const J=(await T.providerAccounts()).accounts.find(q=>q.id===B.id);J&&await T.removeProviderAccount(B.id,J.revision)}catch{}return m(se.message),se}const K=await $({accountId:B.id,label:_,model:G,...X?{freeTier:X}:{}});return K&&m(K),se}catch(B){return m(B instanceof he?B.message:String(B)),null}finally{v(!1)}},P=async L=>{v(!0),m(null);try{const _=await T.saveProviderAccount(L);let Y;try{Y=await T.testProviderAccount(_.id)}finally{try{const B=(await T.providerAccounts()).accounts.find(se=>se.id===_.id);B&&await T.removeProviderAccount(_.id,B.revision)}catch{}}return Y.state!=="connected"&&m(Y.message),Y}catch(_){return m(_ instanceof he?_.message:String(_)),null}finally{v(!1)}},O=(L,_,Y)=>{if(L.length<=1){I(_(L[0]??""),Y);return}N({models:L,make:_,label:Y})},R=L=>{if(L===o)return;C==null||C.close(),A(L==="free"&&typeof window.open=="function"?window.open("","_blank"):null),m(null),N(null),h("key"),c(L)},D=()=>{C==null||C.close(),A(null),N(null),m(null),c(null)},U=eD(g,j),W=["free",...y?["claude"]:[],...b?["chatgpt"]:[],"key","local"];let M=null;return w?M=t.jsxs(t.Fragment,{children:[t.jsx(ct,{children:t.jsx(vt,{children:z.brain.model.ask})}),p?t.jsx(bs,{line:z.brain.checking.service}):f?t.jsx(ct,{children:t.jsx(vt,{children:f})}):null,t.jsx(ole,{busy:p,models:w.models,onBack:D,onUse:L=>void I(w.make(L),w.label)})]}):o==="key"?M=t.jsxs(t.Fragment,{children:[t.jsx(Xt,{label:z.brain.keyKinds.label,value:u,onChange:L=>{m(null),h(L)},options:[{value:"key",label:z.brain.keyKinds.key},...S?[{value:"gemini",label:z.brain.keyKinds.gemini}]:[],{value:"service",label:z.brain.keyKinds.service}]}),u==="gemini"&&S?t.jsx(ule,{busy:p,problem:f,preset:S,onBack:D,onUse:I},"gemini"):u==="service"?t.jsx(fle,{busy:p,problem:f,address:(g==null?void 0:g.cloudBaseUrl)??"",onBack:D,onOffer:O,onTrial:P,onUse:I},"service"):t.jsx(cle,{busy:p,problem:f,onBack:D,onUse:I},"key")]}):o==="local"?M=t.jsx(hle,{busy:p,problem:f,probe:g,mlxh:j,onBack:D,onOffer:O,onUse:I,onCloud:()=>R("free")}):o==="free"?M=t.jsx(ple,{...e,busy:p,consent:C,onBack:D,onConnected:$}):o==="chatgpt"?M=t.jsx(vle,{...e,busy:p,consent:C,onBack:D,onConnected:$}):o==="claude"&&(M=t.jsx(wle,{...e,busy:p,problem:f,onBack:D,onConnected:$})),t.jsxs(t.Fragment,{children:[t.jsx(Vo,{children:z.brain.title}),t.jsx(ct,{children:t.jsx(vt,{children:z.brain.ask})}),t.jsx("div",{className:"wiz-grid",role:"group","aria-label":z.brain.ask,children:W.map(L=>{const _=ile[L],Y=z.brain.cards[L];return t.jsxs("button",{type:"button",className:"wiz-opt","aria-pressed":o===L,"data-wide":_.wide?"true":void 0,onClick:()=>R(L),children:[t.jsx("span",{className:"wiz-glyph","data-tone":_.tone,"aria-hidden":"true",children:t.jsx(ie,{name:_.icon})}),t.jsxs("span",{children:[t.jsx("span",{className:"wiz-opt-title",children:Y.title}),t.jsx("span",{className:"wiz-opt-line",children:L==="local"?U:Y.line}),"pill"in Y?t.jsx(Se,{tone:"good",children:Y.pill}):null]})]},L)})}),M,M===null&&s.brain?t.jsxs(ct,{children:[t.jsx(vt,{children:s.brain.freeTier?z.brain.worksOnFlash(s.brain.model):z.brain.works(s.brain.model)}),t.jsx(gle,{...e}),s.brain.label===z.brain.ollama.label||s.brain.label===z.brain.mlxh.label?t.jsx(Q,{tone:"warm",title:z.brain.ollama.honestTitle,children:z.brain.ollama.honest}):null]}):null,M===null?t.jsx(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Os,{onClick:l}),t.jsx(Ko,{onClick:()=>s.brain&&r(s),disabled:!s.brain,children:z.brain.submit})]})}):null]})}function ole({busy:e,models:n,onBack:s,onUse:r}){const[a,i]=d.useState(n[0]??"");return t.jsx(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Os,{onClick:s,disabled:e}),t.jsx(E,{variant:"accent",size:"lg",disabled:e||a==="",onClick:()=>r(a),children:z.brain.model.submit})]}),children:t.jsx(oe,{label:z.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 ZO({models:e,picked:n,disabled:s,onPick:r}){return t.jsx(oe,{label:z.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 cle({busy:e,problem:n,onBack:s,onUse:r}){const a=Ho(),[i,l]=d.useState(""),[o,c]=d.useState(null),[u,h]=d.useState(!1),[f,m]=d.useState([]),[p,v]=d.useState(""),[g,k]=d.useState(!1),j=e||u,x=!g&&n!==null&&f.length>0,w=o??Jie(i),N=()=>{const y=i.trim();y===""||j||(h(!0),k(!1),(async()=>{var A;let b=w==="anthropic"?"claude-sonnet-5":"gpt-5",S=f;if(x&&p!=="")b=p;else try{const $=await T.probeModels({kind:w,auth:"api-key",secret:y});b=((A=$.models.find(I=>I.isDefault))==null?void 0:A.id)??b,S=$.models.map(I=>I.id)}catch{S=[]}h(!1);const C=await r({label:w==="anthropic"?z.brain.key.anthropic:z.brain.key.openai,kind:w,auth:"api-key",baseUrl:"",defaultModel:b,enabled:!0,secret:y},w==="anthropic"?z.brain.key.anthropic:z.brain.key.openai);if(!(!C||C.state==="connected")){if(oy(C)){k(!0),m([]);return}m(S.includes(b)||S.length===0?S:[b,...S]),v(b)}})())};return t.jsxs(t.Fragment,{children:[j?t.jsx(ct,{children:t.jsx(bs,{line:z.brain.checking.key})}):g?t.jsx(ct,{children:t.jsx(vt,{children:z.brain.key.refused})}):n?t.jsx(ct,{children:t.jsx(vt,{children:n})}):null,t.jsxs(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Os,{onClick:s,disabled:j}),t.jsx(E,{variant:"accent",size:"lg",disabled:j||i.trim()==="",onClick:N,children:x?z.brain.model.retry:z.brain.key.submit})]}),children:[t.jsx(oe,{label:z.brain.key.field,grow:!0,children:t.jsx("input",{ref:a,type:"password",autoComplete:"off",spellCheck:!1,placeholder:z.brain.key.placeholder,value:i,onChange:y=>{l(y.target.value),m([])},onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),N())}})}),x?t.jsx(ZO,{models:f,picked:p,disabled:j,onPick:v}):null,t.jsxs("button",{type:"button",className:"wiz-link",onClick:()=>c(w==="anthropic"?"openai":"anthropic"),children:[w==="anthropic"?z.brain.key.anthropic:z.brain.key.openai," · ",z.brain.key.which]})]})]})}function ule({busy:e,problem:n,preset:s,onBack:r,onUse:a}){const i=Ho(),[l,o]=d.useState(""),[c,u]=d.useState(!1),[h,f]=d.useState([]),[m,p]=d.useState(""),v=e||c,g=n!==null&&h.length>0,k=()=>{const j=l.trim();j===""||v||(u(!0),(async()=>{let x=H2,w;if(g&&m!=="")x=m;else try{const y=(await T.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,secret:j})).models.map(b=>b.id);x=K2(y)??x,w=G2(x)?V2(y):void 0,f(sse(y)),p(w??x)}catch{}u(!1),await a({label:z.brain.gemini.label,kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,defaultModel:x,enabled:!0,secret:j},z.brain.gemini.label,w)})())};return t.jsxs(t.Fragment,{children:[v?t.jsx(ct,{children:t.jsx(bs,{line:z.brain.checking.gemini})}):n?t.jsx(ct,{children:t.jsx(vt,{children:n})}):null,t.jsxs(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Os,{onClick:r,disabled:v}),t.jsx(E,{variant:"accent",size:"lg",disabled:v||l.trim()==="",onClick:k,children:z.brain.gemini.submit})]}),children:[t.jsx(oe,{label:z.brain.gemini.field,grow:!0,children:t.jsx("input",{ref:i,type:"password",autoComplete:"off",spellCheck:!1,placeholder:z.brain.gemini.placeholder,value:l,onChange:j=>o(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),k())}})}),g?t.jsx(oe,{label:z.brain.model.label,grow:!0,children:t.jsx("select",{value:m,disabled:v,onChange:j=>p(j.target.value),children:h.map(j=>t.jsx("option",{value:j,children:j},j))})}):null,t.jsx("a",{className:"wiz-link",href:s.keyUrl,target:"_blank",rel:"noreferrer",children:z.brain.gemini.get})]})]})}function eD(e,n){return e===null||n===null?z.brain.local.looking:!e.running&&!n.running?z.brain.local.missing:z.brain.local.found({...e.running?{ollama:e.models.length}:{},...n.running?{mlxh:n.models.length}:{}})}const dle=1e3;function K1({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(E,{size:"sm",onClick:()=>{var r;return void((r=navigator.clipboard)==null?void 0:r.writeText(e).then(()=>s(!0),()=>{}))},children:n?z.brain.ollama.copied:z.brain.ollama.copy})]})}const V1=e=>(e/1e9).toFixed(1);function hle({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=Ej(r),h=s==null?void 0:s.machine,[f,m]=d.useState(null),[p,v]=d.useState(null),g=d.useRef(null),k=f??(s==null?void 0:s.pull)??null,j=(k==null?void 0:k.state)==="pulling",x=O=>({label:z.brain.ollama.label,kind:"openai-compatible",auth:"none",baseUrl:(s==null?void 0:s.baseUrl)??"",defaultModel:O,enabled:!0});d.useEffect(()=>{if(!j)return;let O=!1;const R=window.setInterval(()=>{T.ollamaPullState().then(D=>{!O&&D.pull&&m(D.pull)},()=>{})},dle);return()=>{O=!0,window.clearInterval(R)}},[j]),d.useEffect(()=>{(f==null?void 0:f.state)!=="done"||!s||g.current===f.model||(g.current=f.model,l(x(f.model),z.brain.ollama.label))},[f==null?void 0:f.state,f==null?void 0:f.model,s]);const w=O=>{v(null),g.current=null,T.ollamaPull(O).then(R=>m(R.pull),R=>v(R instanceof he?R.message:String(R)))},N=()=>{!(r!=null&&r.running)||!u||l({label:z.brain.mlxh.label,kind:"openai-compatible",auth:"none",baseUrl:r.baseUrl,defaultModel:u,enabled:!0},z.brain.mlxh.label)},y=s!==null&&r!==null&&!s.running&&!r.running,b=()=>{s&&i(c,x,z.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||y||j),$=h!=null&&h.cloudSuggested?h.memoryGb<7?"memory":"gpu":null,I=h?t.jsxs("div",{className:"wiz-foot",children:[z.brain.ollama.cloud($,h.memoryGb)," ",t.jsx("button",{type:"button",className:"wiz-link",onClick:o,children:z.brain.ollama.useCloud})]}):null;let P=null;if(A&&h){const O=(k==null?void 0:k.state)==="failed"?k:null;if(j&&k){const R=k.total>0?k.completed/k.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:z.brain.ollama.fetching(k.model,V1(k.completed),k.total>0?V1(k.total):"")}),t.jsxs("span",{className:"wiz-busy-side",children:[Math.round(R*100),"%"]})]}),t.jsx(zy,{value:R*100,label:z.brain.ollama.fetch(k.model)}),t.jsx("div",{className:"wiz-foot",children:z.brain.ollama.fetchingFoot})]})}else if(C){const R=(O==null?void 0:O.model)??h.recommended.model;P=t.jsxs("div",{className:"wiz-stack",children:[t.jsx(ct,{children:t.jsx(vt,{children:O?z.brain.ollama.failed(O.error??""):z.brain.ollama.empty(S,h.memoryGb,h.recommended.model,h.recommended.sizeGb)})}),p?t.jsx(Q,{tone:"critical",children:p}):null,t.jsxs(re,{children:[t.jsx("span",{className:"wiz-foot",children:z.brain.ollama.emptyFoot(S)}),t.jsx(pt,{}),t.jsx(E,{variant:"accent",size:"lg",disabled:e,onClick:()=>w(R),children:O?z.brain.ollama.again:z.brain.ollama.fetch(R)})]}),I]})}else h.installed?P=t.jsxs("div",{className:"wiz-stack",children:[t.jsx(ct,{children:t.jsx(vt,{children:z.brain.ollama.stopped(h.platform)})}),h.platform==="linux"?t.jsx(K1,{command:"ollama serve"}):null,I]}):P=t.jsxs("div",{className:"wiz-stack",children:[t.jsx(ct,{children:t.jsx(vt,{children:z.brain.ollama.missing(S)})}),h.install.command?t.jsx(K1,{command:h.install.command}):null,t.jsxs(re,{children:[t.jsx("span",{className:"wiz-foot",children:z.brain.ollama.missingHow(h.platform,S)}),t.jsx(pt,{}),h.platform==="linux"?null:t.jsx(nt,{size:"lg",href:h.install.url,target:"_blank",rel:"noreferrer",children:z.brain.ollama.download})]}),I]})}return t.jsxs(t.Fragment,{children:[e?t.jsx(ct,{children:t.jsx(bs,{line:z.brain.checking.ollama})}):n?t.jsx(ct,{children:t.jsx(vt,{children:n})}):null,P,t.jsx(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Os,{onClick:a,disabled:e}),s!=null&&s.running&&c.length>0?t.jsx(E,{variant:r!=null&&r.running?void 0:"accent",size:"lg",disabled:e,onClick:b,children:z.brain.ollama.connect}):null,r!=null&&r.running?t.jsx(E,{variant:"accent",size:"lg",disabled:e||!u,onClick:N,children:z.brain.mlxh.connect}):null,y&&s&&!h?t.jsx(nt,{variant:"accent",size:"lg",href:s.downloadUrl,target:"_blank",rel:"noreferrer",children:z.brain.ollama.download}):null]}),children:A?null:t.jsxs("span",{className:"wiz-foot",children:[eD(s,r),r!=null&&r.running&&!u?` ${z.brain.mlxh.noBrain}`:"",y&&(r!=null&&r.baseUrl)?` ${m2(r.baseUrl)}`:""]})})]})}function fle({busy:e,problem:n,address:s,onBack:r,onOffer:a,onTrial:i,onUse:l}){const o=Ho(),[c,u]=d.useState(s),[h,f]=d.useState(""),[m,p]=d.useState(!1),[v,g]=d.useState([]),[k,j]=d.useState(""),[x,w]=d.useState(!1),N=e||m,y=!x&&n!==null&&v.length>0,b=()=>{c.trim()===""||N||(p(!0),w(!1),(async()=>{var D;const S=h.trim()?"api-key":"none",C=U=>({label:z.brain.service.label,kind:"openai-compatible",auth:S,baseUrl:c.trim(),defaultModel:U,enabled:!0,...h.trim()?{secret:h.trim()}:{}}),A=(U,W,M)=>{if(!(!U||U.state==="connected")){if(oy(U)){w(!0),g([]);return}g(W),j(M)}};if(S==="api-key"&&y&&k!==""){p(!1),A(await l(C(k),z.brain.service.label),v,k);return}let $=[],I;try{const U=await T.probeModels({kind:"openai-compatible",auth:S,baseUrl:c.trim(),...h.trim()?{secret:h.trim()}:{}});$=U.models.map(W=>W.id),I=(D=U.models.find(W=>W.isDefault))==null?void 0:D.id}catch{}p(!1);const P=I?[I]:$;if(S==="none"){a(P,C,z.brain.service.label);return}const O=P[0]??"";if(P.length<=1){A(await l(C(O),z.brain.service.label),$,O);return}const R=await i(C(O));(R==null?void 0:R.state)==="connected"?a(P,C,z.brain.service.label):A(R,$,O)})())};return t.jsxs(t.Fragment,{children:[N?t.jsx(ct,{children:t.jsx(bs,{line:z.brain.checking.service})}):x?t.jsx(ct,{children:t.jsx(vt,{children:z.brain.key.refused})}):n?t.jsx(ct,{children:t.jsx(vt,{children:n})}):null,t.jsxs(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Os,{onClick:r,disabled:N}),t.jsx(E,{variant:"accent",size:"lg",disabled:N||c.trim()==="",onClick:b,children:y?z.brain.model.retry:z.brain.service.submit})]}),children:[t.jsx(oe,{label:z.brain.service.address,grow:!0,children:t.jsx("input",{ref:o,value:c,placeholder:z.brain.service.addressPlaceholder,onChange:S=>{u(S.target.value),g([])}})}),t.jsx(oe,{label:z.brain.service.key,children:t.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,value:h,onChange:S=>{f(S.target.value),g([])}})}),y?t.jsx(ZO,{models:v,picked:k,disabled:N,onPick:j}):null]})]})}const mle=2e3;function ple({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),[f,m]=d.useState(0),p=d.useRef(-1),v=d.useRef(null),g=z.brain.cloud.label;d.useEffect(()=>{if(p.current===f)return;p.current=f,l(!0),c(null);const j=f===0?n:v.current;(async()=>{try{const x=((a==null?void 0:a.accounts)??[]).find(b=>b.auth==="device-key"),w=x?{id:x.id}:await T.saveProviderAccount({label:g,kind:"openai-compatible",auth:"device-key",baseUrl:"",defaultModel:ph,enabled:!0}),N=(await T.providerAccounts()).accounts.find(b=>b.id===w.id),y=await T.ollamaConnect(N.id,N.revision);h({id:N.id,attemptId:y.attemptId,url:y.verificationUrl}),j&&(j.location.href=y.verificationUrl)}catch(x){j==null||j.close(),c(x instanceof he?x.message:String(x))}finally{l(!1)}})()},[f]),d.useEffect(()=>{if(!u)return;let j=!1,x=!1;const w=async()=>{if(!(j||x)){x=!0;try{const y=await T.ollamaPoll(u.id,u.attemptId);if(j||y.state==="waiting")return;if(j=!0,h(null),y.state==="failed"){c(y.message);return}l(!0),c(await k(u.id)),l(!1)}catch{}finally{x=!1}}},N=window.setInterval(()=>void w(),mle);return()=>{j=!0,window.clearInterval(N)}},[u]);const k=async j=>{try{const x=(await T.accountModels(j).catch(()=>({models:[]}))).models.map(b=>b.id),w=x.length===0||x.includes(ph)?ph:x[0],N=(await T.providerAccounts()).accounts.find(b=>b.id===j);N&&N.defaultModel!==w&&await T.saveProviderAccount({id:N.id,revision:N.revision,label:N.label,kind:N.kind,auth:N.auth,baseUrl:N.baseUrl,defaultModel:w,enabled:N.enabled});const y=await T.testProviderAccount(j);return y.state!=="connected"?y.message:await r({accountId:j,label:g,model:w})}catch(x){return x instanceof he?x.message:String(x)}};return t.jsxs(t.Fragment,{children:[i||e?t.jsx(ct,{children:t.jsx(bs,{line:z.brain.checking.cloud})}):o?t.jsx(ct,{children:t.jsx(vt,{children:o})}):u?t.jsx(ct,{children:t.jsx(vt,{children:z.brain.cloud.waiting})}):null,t.jsx(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Os,{onClick:s,disabled:i||e}),u?t.jsx(nt,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",children:z.brain.cloud.open}):o?t.jsx(E,{variant:"accent",size:"lg",disabled:i||e,onClick:()=>{v.current=typeof window.open=="function"?window.open("","_blank"):null,m(j=>j+1)},children:z.brain.cloud.again}):null]})})]})}function gle({answers:e,accounts:n,onKept:s,onTrouble:r}){var p;const a=e.brain,i=a?((n==null?void 0:n.accounts)??[]).find(v=>v.id===a.accountId):void 0,[l,o]=d.useState([]),[c,u]=d.useState(!1),h=Bb(i),f=(i==null?void 0:i.auth)==="device-key"||(i==null?void 0:i.kind)==="codex"||h||!!i&&q2(i,(p=n==null?void 0:n.gemini)==null?void 0:p.baseUrl);if(d.useEffect(()=>{if(!f||!i)return;let v=!1;return T.accountModels(i.id).then(g=>{const k=h?g.models.filter(j=>!f2({id:j.id,...j.image?{kind:"image"}:{}})):g.models;v||o(k.map(j=>j.id))}).catch(()=>{}),()=>{v=!0}},[f,i==null?void 0:i.id]),!f||!i||!a||l.length<2)return null;const m=v=>{v===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:v,enabled:i.enabled}),e.assistant&&await T.bindBrain({accountId:i.id,model:v}),s({...e,brain:{accountId:a.accountId,label:a.label,model:v}})}catch(g){r(g instanceof he?g.message:String(g))}finally{u(!1)}})())};return t.jsx(vt,{children:t.jsx(oe,{label:z.brain.model.change,children:t.jsx("select",{value:a.model,disabled:c,onChange:v=>m(v.target.value),children:(l.includes(a.model)?l:[a.model,...l]).map(v=>t.jsx("option",{value:v,children:v},v))})})})}const G1="gpt-5.5",xle=2e3;function vle({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),[f,m]=d.useState(!1),[p,v]=d.useState(void 0),[g,k]=d.useState(0),j=d.useRef(-1),x=d.useRef(null),w=d.useRef(null),N=z.brain.chatgpt.label;d.useEffect(()=>()=>{const S=w.current;w.current=null,S&&T.codexAccountAction(S.id,"cancel-login",S.revision).catch(()=>{})},[]),d.useEffect(()=>{if(j.current===g)return;j.current=g,l(!0),c(null);const S=g===0?n:x.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:N,kind:"codex",auth:"chatgpt",baseUrl:"",defaultModel:G1,enabled:!0}),$=(await T.providerAccounts()).accounts.find(P=>P.id===A.id),I=await T.codexAccountAction($.id,"login",$.revision);if(!(I!=null&&I.verificationUrl)||!I.userCode)throw new Error((I==null?void 0:I.message)??z.brain.chatgpt.failed);w.current={id:$.id,revision:$.revision},h({id:$.id,revision:$.revision,url:I.verificationUrl,code:I.userCode}),m(!!S),S&&(S.location.href=I.verificationUrl)}catch(C){S==null||S.close(),c(C instanceof he||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 I=(await T.providerAccounts()).accounts.find(O=>O.id===u.id);if(S)return;const P=I==null?void 0:I.login;if(!P||P.state==="pending")return;if(S=!0,w.current=null,h(null),P.state!=="connected"){c(P.message??z.brain.chatgpt.failed);return}v(P.account??null),l(!0),c(await y(u.id)),l(!1),v(void 0)}catch{}finally{C=!1}}},$=window.setInterval(()=>void A(),xle);return()=>{S=!0,window.clearInterval($)}},[u]);const y=async S=>{var C,A;try{const $=(await T.accountModels(S).catch(()=>({models:[]}))).models,I=((C=$.find(O=>O.isDefault))==null?void 0:C.id)??((A=$[0])==null?void 0:A.id)??G1,P=(await T.providerAccounts()).accounts.find(O=>O.id===S);return P&&P.defaultModel!==I&&await T.saveProviderAccount({id:P.id,revision:P.revision,label:P.label,kind:P.kind,auth:P.auth,baseUrl:P.baseUrl,defaultModel:I,enabled:P.enabled}),await r({accountId:S,label:N,model:I})}catch($){return $ instanceof he?$.message:String($)}},b=()=>{const S=w.current;w.current=null,S&&T.codexAccountAction(S.id,"cancel-login",S.revision).catch(()=>{}),s()};return t.jsxs(t.Fragment,{children:[p!==void 0?t.jsxs(ct,{children:[t.jsx(vt,{children:z.brain.chatgpt.signedIn(p)}),t.jsx(bs,{line:z.brain.checking.chatgpt})]}):i||e?t.jsx(ct,{children:t.jsx(bs,{line:z.brain.checking.chatgpt})}):o?t.jsx(ct,{children:t.jsx(vt,{children:o})}):u?t.jsx(ct,{children:f?t.jsx(bs,{line:z.brain.chatgpt.waiting}):t.jsx(vt,{children:z.brain.chatgpt.instruct})}):null,t.jsx(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Os,{onClick:b,disabled:i||e}),u?t.jsx(nt,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",onClick:()=>m(!0),children:z.brain.chatgpt.open}):o?t.jsx(E,{variant:"accent",size:"lg",disabled:i||e,onClick:()=>{x.current=typeof window.open=="function"?window.open("","_blank"):null,k(S=>S+1)},children:z.brain.chatgpt.again}):null]}),children:u?t.jsx(Hb,{code:u.code,label:z.brain.chatgpt.code,large:!0}):null})]})}const jle="claude-sonnet-5";function wle({busy:e,problem:n,onBack:s,onConnected:r,accounts:a,claudeModel:i}){const[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(""),v=d.useRef(null);d.useEffect(()=>()=>{const w=v.current;v.current=null,w&&T.anthropicAccountAction(w.id,"cancel-login",w.revision).catch(()=>{})},[]);const g=()=>{const w=v.current;v.current=null,w&&T.anthropicAccountAction(w.id,"cancel-login",w.revision).catch(()=>{}),s()},k=i??jle,j=()=>{o(!0),u(null);const w=typeof window.open=="function"?window.open("","_blank"):null;(async()=>{try{const N=((a==null?void 0:a.accounts)??[]).find(A=>A.auth==="anthropic-oauth"),y=N?{id:N.id}:await T.saveProviderAccount({label:z.brain.claude.label,kind:"anthropic",auth:"anthropic-oauth",baseUrl:"",defaultModel:k,enabled:!0}),S=(await T.providerAccounts()).accounts.find(A=>A.id===y.id),C=await T.anthropicAccountAction(S.id,"login",S.revision);v.current={id:S.id,revision:S.revision+1},f({id:S.id,revision:S.revision+1,url:C.verificationUrl??"",attemptId:C.attemptId??""}),w&&C.verificationUrl?w.location.href=C.verificationUrl:w==null||w.close()}catch(N){w==null||w.close(),u(N instanceof he?N.message:String(N))}finally{o(!1)}})()},x=()=>{!h||m.trim()===""||(v.current=null,o(!0),(async()=>{try{await T.anthropicAccountAction(h.id,"complete-login",h.revision,{attemptId:h.attemptId,code:m.trim()});const w=await T.testProviderAccount(h.id);if(w.state!=="connected"){u(w.message);return}u(await r({accountId:h.id,label:z.brain.claude.label,model:k}))}catch(w){u(w instanceof he?w.message:String(w))}finally{o(!1)}})())};return t.jsxs(t.Fragment,{children:[l||e?t.jsx(ct,{children:t.jsx(bs,{line:z.brain.checking.claude})}):n??c?t.jsx(ct,{children:t.jsx(vt,{children:n??c})}):null,h?t.jsxs(t.Fragment,{children:[t.jsx(ct,{children:t.jsx(vt,{children:z.brain.claude.waiting})}),t.jsx(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Os,{onClick:g,disabled:l}),t.jsx(nt,{size:"lg",href:h.url,target:"_blank",rel:"noreferrer",children:z.brain.claude.open}),t.jsx(E,{variant:"accent",size:"lg",disabled:l||m.trim()==="",onClick:x,children:z.brain.claude.finish})]}),children:t.jsx(oe,{label:z.brain.claude.paste,grow:!0,children:t.jsx(yle,{value:m,onChange:p})})})]}):t.jsx(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Os,{onClick:g,disabled:e||l}),t.jsx(E,{variant:"accent",size:"lg",disabled:e||l,onClick:j,children:z.brain.claude.start})]})})]})}function yle({value:e,onChange:n}){const s=Ho();return t.jsx("input",{ref:s,type:"password",autoComplete:"off",spellCheck:!1,value:e,onChange:r=>n(r.target.value)})}const ble={days:"calendar",mail:"mail",money:"money",voice:"bulb",code:"monitor",pictures:"files"};function kle(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:z.takeOn.fetching(s,Math.min(a+1,n.length),n.length),done:!1}}return r.length>0?{line:r.map(a=>z.takeOn.failed(a.title,a.reason??"")).join(" "),done:!0}:{line:z.takeOn.ready(s),done:!0}}function Nle({answers:e,progress:n,offers:s,onProgress:r,onSettled:a,onBack:i,onTrouble:l}){const o=s?df.filter(k=>s.includes(k.id)):df,[c,u]=d.useState(()=>e.takeOn??[...U5]),[h,f]=d.useState(!1),m=o.filter(k=>c.includes(k.id)),p=k=>u(j=>j.includes(k)?j.filter(x=>x!==k):[...j,k]),v=k=>{h||(f(!0),Promise.resolve().then(()=>T.takeOn(k)).then(()=>{r(),a({...e,takeOn:k})}).catch(j=>l(j instanceof he?j.message:String(j))).finally(()=>f(!1)))},g=kle(n);return t.jsxs(t.Fragment,{children:[t.jsx(Vo,{children:z.takeOn.title}),t.jsx(ct,{children:t.jsx(vt,{children:z.takeOn.ask})}),t.jsxs(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Os,{onClick:i,disabled:h}),t.jsx(E,{variant:"ghost",size:"lg",disabled:h,onClick:()=>v([]),children:z.takeOn.none}),t.jsx(Ko,{onClick:()=>v(m.map(k=>k.id)),disabled:h||m.length===0,children:z.takeOn.submit})]}),children:[t.jsx("div",{className:"wiz-grid","data-cols":"3",role:"group","aria-label":z.takeOn.title,children:o.map(k=>{const j=c.includes(k.id);return t.jsxs("button",{type:"button",className:"wiz-opt","data-tile":"true","aria-pressed":j,onClick:()=>p(k.id),children:[t.jsxs("span",{className:"wiz-tile-top",children:[t.jsx("span",{className:"wiz-glyph","aria-hidden":"true",children:t.jsx(ie,{name:ble[k.id]})}),t.jsx("span",{className:"wiz-tick","aria-hidden":"true",children:j?t.jsx(ie,{name:"check",size:12}):null})]}),t.jsxs("span",{children:[t.jsx("span",{className:"wiz-opt-title",children:k.title}),t.jsx("span",{className:"wiz-opt-plugins",children:k.plugins})]}),t.jsx("span",{className:"wiz-opt-line",children:k.line})]},k.id)})}),m.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:z.takeOn.builtIn}):null]}):null,t.jsx("div",{className:"wiz-foot",children:m.map(k=>k.note).join(" ")})]}):t.jsx("div",{className:"wiz-foot",children:z.takeOn.nothing})]})]})}function Sle({answers:e,progress:n,onSettled:s,onBack:r}){var g,k,j;const[a,i]=d.useState(((g=e.reach)==null?void 0:g.phone)===!0),[l,o]=d.useState(((k=e.reach)==null?void 0:k.mailbox)===!0),[c,u]=d.useState(((j=e.reach)==null?void 0:j.app)===!0),[h,f]=d.useState(e.browser),m=e.takeOn??[],p=m.includes("mail"),v=()=>{const x={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:x,...h!==void 0?{browser:h}:{}})};return t.jsxs(t.Fragment,{children:[t.jsx(Vo,{children:z.reach.title}),t.jsx(ct,{children:t.jsx(vt,{children:z.reach.ask})}),t.jsx(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Os,{onClick:r}),t.jsx(Ko,{onClick:v,children:z.reach.submit})]}),children:t.jsxs("div",{className:"wiz-rows",children:[t.jsx(Cle,{paired:a,owner:e.name,onPaired:()=>i(!0)}),t.jsx(Ele,{wanted:p,added:l,onAdded:o}),m.includes("days")?t.jsx(Ale,{progress:n}):null,m.includes("money")?t.jsx(Tle,{}):null,t.jsx(Ile,{app:c,onApp:()=>u(!0),browser:h,onBrowser:f}),a?t.jsx(Q,{tone:"good",role:"status",children:z.reach.phone.hello}):null]})})]})}function Cle({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(ie,{name:"chat"})}),t.jsxs("span",{className:"wiz-row-text",children:[t.jsx("span",{className:"wiz-opt-title",children:z.reach.phone.title}),t.jsx("span",{className:"wiz-opt-line",children:z.reach.phone.line})]}),t.jsx("span",{className:"wiz-row-side",children:e?t.jsx(Se,{tone:"good",dot:!0,children:z.reach.phone.paired}):t.jsx(E,{size:"lg",disabled:r===null,onClick:()=>l(!0),children:c?z.reach.phone.pair:z.reach.phone.setUp})}),i?t.jsx(Je,{title:z.telegram.sheet,onClose:()=>l(!1),children:t.jsx(Lle,{ready:c,owner:n,onPaired:s,onDismiss:()=>l(!1)})}):null]})}function Ele({wanted:e,added:n,onAdded:s}){const r=tD("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,f,m;const u=((m=(f=(h=c==null?void 0:c.data)==null?void 0:h.accounts)==null?void 0:f[0])==null?void 0:m.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(ie,{name:"mail"})}),t.jsxs("span",{className:"wiz-row-text",children:[t.jsx("span",{className:"wiz-opt-title",children:e?z.reach.mailbox.forTriage:z.reach.mailbox.title}),t.jsx("span",{className:"wiz-opt-line",children:r===!1?z.reach.mailbox.unavailable:z.reach.mailbox.line})]}),t.jsx("span",{className:"wiz-row-side",children:n||l?t.jsx(Se,{tone:"good",dot:!0,mono:l!==null,children:l??z.reach.mailbox.added}):r?t.jsx(E,{size:"lg",onClick:()=>i(!0),children:z.reach.mailbox.add}):null}),a?t.jsx(zie,{onClose:()=>i(!1),onAdded:c=>{o(c),s(!0)}}):null]})}function tD(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 Ale({progress:e}){const n=tD("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 m=!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,v])=>{m||i($le(p,v))}).catch(()=>{}),()=>{m=!0}},[n,c,s]),d.useEffect(()=>{if((a==null?void 0:a.kind)!=="waiting")return;const m=window.setTimeout(()=>u(p=>p+1),VO);return()=>window.clearTimeout(m)},[a,c]);const h=a??(l?{kind:"linked",tone:"good",label:z.reach.calendar.linked}:null),f=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(ie,{name:"calendar"})}),t.jsxs("span",{className:"wiz-row-text",children:[t.jsx("span",{className:"wiz-opt-title",children:z.reach.calendar.title}),t.jsx("span",{className:"wiz-opt-line",children:n===!1?z.reach.calendar.waiting:z.reach.calendar.line})]}),t.jsxs("span",{className:"wiz-row-side",children:[h!==null?t.jsx(Se,{tone:h.tone,dot:!0,mono:h.kind==="google"||h.kind==="expired",children:h.label}):null,f?null:t.jsx(E,{size:"lg",disabled:!n,onClick:()=>r(!0),children:z.reach.calendar.add})]}),s?t.jsx(Wie,{onClose:()=>r(!1),onLinked:()=>{o(!0),u(m=>m+1)}}):null]})}function $le(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:z.reach.calendar.googleWaiting}:a.length>0?{kind:"google",tone:"good",label:z.reach.calendar.google(a.map(l=>l.username??"").filter(Boolean).join(", ")||"signed in")}:r.length>0?{kind:"expired",tone:"warning",label:z.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:z.reach.calendar.linked}:null}function Tle(){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(ie,{name:"money"})}),t.jsxs("span",{className:"wiz-row-text",children:[t.jsx("span",{className:"wiz-opt-title",children:z.reach.bank.title}),t.jsx("span",{className:"wiz-opt-line",children:z.reach.bank.line})]}),t.jsx("span",{className:"wiz-row-side",children:s?t.jsx(Se,{dot:!0,children:z.reach.bank.later}):t.jsx(E,{size:"lg",onClick:()=>n(!0),children:z.reach.bank.add})}),e?t.jsx(Hie,{onClose:()=>n(!1),onUnderstood:()=>r(!0)}):null]})}function Ile({app:e,onApp:n,browser:s,onBrowser:r}){const a=Fb(),i=Ym(),l=a?null:i,o=typeof navigator>"u"?null:NM(navigator.userAgent),[c,u]=d.useState(null),[h,f]=d.useState("idle"),[m,p]=d.useState(null),[v,g]=d.useState(null),[k,j]=d.useState(void 0),x=d.useRef(!1),w=d.useRef(!0);d.useEffect(()=>(w.current=!0,Promise.resolve().then(()=>T.browser()).then($=>{var P;if(!w.current)return;const I=$==null?void 0:$.browser;I?((P=I.install)==null?void 0:P.state)==="running"?(u("none"),x.current=!0,f("installing"),b()):u(I.engine):u("other")}).catch(()=>{w.current&&u("other")}),()=>{w.current=!1}),[]);const N=($,I)=>{w.current&&(x.current=!1,f("failed"),p($),g(I??null))},y=async $=>{f("launching");let I;try{I=await T.browserCheck()}catch(P){return N(P instanceof he?P.message:String(P))}if(w.current){if(I.ok){f("idle"),u($),r(x.current?"installed":$);return}N(I.message,I.command)}},b=async()=>{var P,O;let $;try{$=await T.browser()}catch(R){return N(R instanceof he?R.message:String(R))}if(!w.current)return;const I=$.browser;if(!I)return N(z.browser.failed(""));if(((P=I.install)==null?void 0:P.state)==="running"){f("installing"),j(I.install.progress),window.setTimeout(()=>void b(),1e3);return}return I.engine!=="none"?y(I.engine):N(((O=I.install)==null?void 0:O.line)??"")},S=()=>{if(g(null),c==="chrome"||c==="chromium"){y(c);return}x.current=!0,f("installing"),j(void 0),Promise.resolve().then(()=>T.browserInstall()).then(()=>{w.current&&window.setTimeout(()=>void b(),1e3)}).catch($=>N($ instanceof he?$.message:String($)))},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(ie,{name:"globe"})}),t.jsxs("span",{className:"wiz-row-text",children:[t.jsx("span",{className:"wiz-opt-title",children:a?z.reach.app.inApp.title:z.reach.app.title}),t.jsx("span",{className:"wiz-opt-line",children:a?z.reach.app.inApp.line:z.reach.app.line})]}),t.jsxs("span",{className:"wiz-row-side",children:[a?t.jsx(nt,{size:"lg",href:sP,target:"_blank",rel:"noreferrer",children:z.reach.app.inApp.extension}):e?t.jsx(Se,{tone:"good",dot:!0,children:z.reach.app.installed}):l?t.jsx(E,{size:"lg",onClick:()=>{l.prompt().then(()=>l.userChoice).then($=>{(!$||$.outcome==="accepted")&&n()}).catch(()=>{})},children:z.reach.app.install}):null,C?t.jsx(Se,{tone:"good",dot:!0,children:z.reach.app.ready(s==="chrome"?"chrome":"chromium")}):c===null||c==="other"?null:t.jsx(E,{size:"lg",disabled:A,onClick:S,children:A?z.browser.installing:h==="failed"?z.browser.retry:c==="chrome"?z.reach.app.chrome:c==="chromium"?z.reach.app.chromium:z.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:z.browser.needs}),t.jsx(Vie,{progress:k})]}):h==="launching"?t.jsx("div",{className:"wiz-row-more",children:t.jsx(bs,{line:z.browser.launching})}):h==="failed"?t.jsxs("div",{className:"wiz-row-more",children:[t.jsx("span",{className:"wiz-opt-line",children:z.browser.failed(m??"")}),v?t.jsx(Mle,{command:v}):null]}):null]})}function Rle({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)??M5),[u,h]=d.useState(()=>n!=null&&n.picture||n!=null&&n.avatar?null:"buddi"),[f,m]=d.useState(n?null:z.assistant.purposeValue),[p,v]=d.useState(n?"":z.assistant.purposeValue);d.useEffect(()=>{if(!n)return;let b=!1;return T.firstAgentPersona().then(S=>{b||(m(S.persona),v(S.persona))},S=>{b||a(S instanceof he?S.message:String(S))}),()=>{b=!0}},[n==null?void 0:n.id]);const[g,k]=d.useState(!1),[j,x]=d.useState(null),w=df.filter(b=>(e.takeOn??[]).includes(b.id)&&"mate"in b).map(b=>b.mate),N=GN.find(b=>b.id===u),y=()=>{if(o.trim()===""||g)return;k(!0);const b=!n||f!==null&&p.trim()!==""&&p.trim()!==f.trim()?{instructions:p.trim()}:{},S=n?T.updateFirstAgent({name:o.trim(),...b}):T.createFirstAgent({name:o.trim(),handle:Xie(o),description:"",...b,...e.brain?{accountId:e.brain.accountId}:{}});(async()=>{var $;let C;try{C=await S}catch(I){I instanceof he&&I.status===409&&(($=I.detail)==null?void 0:$.code)==="assistant-exists"?(x(I.message),a(null)):a(I instanceof he?I.message:String(I)),k(!1);return}let A=null;try{N&&await T.uploadAgentPicture(C.id,await C2(N.role))}catch(I){A=I instanceof he?I.message:String(I)}k(!1),i(),r({...e,assistant:{id:C.id,name:o.trim(),avatar:N?"":(n==null?void 0:n.avatar)??""}}),A&&a(A)})()};return t.jsxs(t.Fragment,{children:[t.jsx(Vo,{children:z.assistant.title}),t.jsx(ct,{children:t.jsxs(vt,{children:[z.assistant.ask,w.length>0?z.assistant.team(w):""]})}),t.jsxs(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Os,{onClick:l,disabled:g}),t.jsx(Ko,{onClick:y,disabled:g||j!==null||o.trim()===""||f===null,children:z.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":(N==null?void 0:N.id)??"buddi","aria-hidden":"true",children:N?t.jsx("img",{src:xi(N.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":z.assistant.colour,children:GN.map(b=>t.jsx("button",{type:"button",className:"wiz-swatch","data-agent":b.id,"aria-label":z.assistant.swatch(b.label),"aria-pressed":u===b.id,onClick:()=>h(b.id)},b.id))}),t.jsx("span",{className:"wiz-face-cap",children:z.assistant.colour})]}),t.jsxs("div",{className:"wiz-stack",children:[t.jsx(oe,{label:z.assistant.name,children:t.jsx("input",{value:o,maxLength:60,onChange:b=>c(b.target.value)})}),t.jsx(oe,{label:z.assistant.purpose,hint:z.assistant.purposeHint,children:t.jsx("textarea",{className:"wiz-persona",value:p,maxLength:8e3,rows:7,onChange:b=>v(b.target.value)})})]})]}),j?t.jsx(Q,{tone:"warm",role:"status",title:z.assistant.refusedTitle,action:t.jsx(nt,{href:bt,onClick:b=>{b.preventDefault(),s(bt)},children:z.assistant.toAgents}),children:j}):null]})]})}function Ple({answers:e,assistantAgent:n,met:s,onMet:r,navigate:a,onPickAnotherBrain:i,onSpoken:l,progress:o,onProgress:c}){var U,W;const u=e.assistant,[h,f]=d.useState(s),[m,p]=d.useState([]),[v,g]=d.useState(!1),[k,j]=d.useState(!1),[x,w]=d.useState(!0),[N,y]=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){f(s);return}let M=!1;return(async()=>{try{const L=await Qe.startConversation(u.id);if(M)return;f(L.conversationId),r(L.conversationId),await T.onboardingStep(GO.handover,{conversationId:L.conversationId}).catch(()=>{}),await Qe.send(u.id,{conversationId:L.conversationId,text:F5,opening:!0})}catch{M||(w(!1),g(!0))}})(),()=>{M=!0}},[u==null?void 0:u.id,s]),d.useEffect(()=>{if(!h)return;let M=!1;const L=Date.now(),_=()=>{Qe.conversation(h).then(B=>{if(M)return;p(B.messages);const se=Date.now()-L;if(B.messages.some(Y1)){w(!1),g(!1),j(!1);return}const G=B.runs??[],X=G.some(J=>J.finishedAt===null),K=G.length>0&&!X;j(X&&se>=Zie),(K||se>=ele)&&(w(!1),g(!0))}).catch(()=>{})};_();const Y=window.setInterval(_,XO);return()=>{M=!0,window.clearInterval(Y)}},[h]);const C=u&&h?lt(u.id,h):null,A=m.some(Y1);d.useEffect(()=>{A&&C&&l(C)},[A,C,l]);const $=o!=null&&o.tiles&&o.tiles.length>0?o.tiles:e.takeOn??[],I=z.handover.starters({days:$.includes("days"),mail:$.includes("mail"),mailbox:((U=e.reach)==null?void 0:U.mailbox)===!0}),P={days:$.includes("days"),mailbox:((W=e.reach)==null?void 0:W.mailbox)===!0,mail:$.includes("mail"),money:$.includes("money"),pictures:$.includes("pictures")},O=(o==null?void 0:o.waiting)??[],R=M=>{Ry(),a(M,!0)},D=M=>{!u||!h||N||(y(!0),Promise.resolve().then(()=>Qe.send(u.id,{conversationId:h,text:M})).then(()=>R(lt(u.id,h))).catch(()=>y(!1)))};return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"wiz-hello",children:t.jsx(tb,{messages:m,live:[],now:Date.now(),onOpen:()=>{},working:x,agents:S,agentName:(u==null?void 0:u.name)??"",...u?{agentId:u.id}:{},emptyHint:z.handover.waiting,plain:!0,workingLine:z.handover.looking((u==null?void 0:u.name)??"")})}),k&&!v?t.jsx(ct,{children:t.jsx(vt,{children:z.handover.slow})}):null,v?t.jsxs(t.Fragment,{children:[t.jsx(ct,{children:t.jsx(vt,{children:z.handover.silent})}),t.jsx(bn,{actions:t.jsx(Ko,{onClick:i,children:z.handover.again})})]}):null,A?t.jsx("div",{className:"wiz-starters",role:"group","aria-label":z.handover.starterLabel,children:I.map(M=>t.jsx("button",{type:"button",className:"wiz-starter",disabled:N,onClick:()=>D(M),children:M},M))}):null,A?t.jsx(Sq,{setUp:P,navigate:R}):null,A?t.jsx(O2,{plugins:(o==null?void 0:o.plugins)??[]}):null,A&&O.length>0?t.jsx(Q,{tone:"warm",title:z.handover.waitingTitle(O.length),action:t.jsx(E,{variant:"accent",onClick:()=>R(Tn),children:z.handover.home}),children:z.handover.waitingBody(O)}):null,A&&C?t.jsx(bn,{actions:t.jsx(nt,{variant:"accent",size:"lg",href:C,onClick:M=>{M.preventDefault(),R(C)},children:z.done.open})}):null]})}function Mle({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(Bt,{label:"The command to run",children:e}),t.jsxs(re,{align:"end",children:[n==="failed"?t.jsx("span",{className:"ui-toolbar-note",children:"Select it to copy."}):null,t.jsx(E,{size:"sm",onClick:r,children:n==="done"?"Copied":"Copy"})]})]})}function Y1(e){return e.role==="assistant"&&(e.blocks??[]).some(n=>n.type==="text"&&n.text.trim()!=="")}function Ole({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=>{Vj(h.job.id),n()}).catch(h=>s(h instanceof he?h.message:String(h))).finally(()=>c(!1)))};return t.jsx(Je,{title:z.restore.sheet,onClose:e,children:t.jsxs("div",{className:"wiz-restore",children:[t.jsx("p",{className:"wiz-foot",children:z.restore.lede}),t.jsx(oe,{label:z.restore.file,children:t.jsx("input",{type:"file",onChange:h=>{var f;return a(((f=h.target.files)==null?void 0:f[0])??null)}})}),t.jsx(oe,{label:z.restore.passphrase,hint:z.restore.passphraseHint,children:t.jsx("input",{type:"password",autoComplete:"off",value:i,onChange:h=>l(h.target.value)})}),t.jsxs(re,{align:"end",children:[t.jsx(E,{variant:"ghost",onClick:e,children:z.restore.cancel}),t.jsx(E,{variant:"accent",disabled:o||!r,onClick:u,children:z.restore.submit})]})]})})}function Dle({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=JO();if(!l)return;let o=!1;const c=()=>{T.backupJob(l).then(h=>{o||(r(f=>f.includes(h.phase)?f:[...f,h.phase]),h.phase==="done"?(o=!0,Vj(null),T.owner().then(f=>a.current.onDone(f.preferredName??void 0),()=>a.current.onDone(void 0))):(h.phase==="rolled-back"||h.phase==="failed")&&(o=!0,Vj(null),a.current.onFailed(h.error??z.restore.phases[h.phase])))}).catch(()=>{})};c();const u=window.setInterval(c,XO);return()=>{o=!0,window.clearInterval(u)}},[]);const i=s.filter(l=>l in z.restore.phases);return t.jsxs(t.Fragment,{children:[t.jsx(Vo,{children:z.restore.title}),t.jsxs(ct,{children:[t.jsx(vt,{children:z.restore.started}),i.map(l=>t.jsx(vt,{children:z.restore.phases[l]},l))]}),t.jsx(bs,{})]})}function Lle(e){return t.jsx(ck.Provider,{value:null,children:t.jsx("div",{className:"wiz-sheet-body",children:t.jsx(_le,{...e})})})}const Fle=1600;function _le({ready:e,owner:n,onPaired:s,onDismiss:r}){const a=Ho(),[i,l]=d.useState(""),[o,c]=d.useState(!1),[u,h]=d.useState(null),[f,m]=d.useState(null),{offer:p,square:v,paired:g,stale:k,ask:j}=zO(()=>T.telegram().then(b=>b.paired),s),x=d.useRef(!1);d.useEffect(()=>{!e||x.current||(x.current=!0,Promise.resolve().then(()=>T.telegramBot()).then(b=>m((b==null?void 0:b.username)??null)).catch(()=>{}),j().catch(b=>h(b instanceof he?b.message:String(b))))},[e,j]);const w=d.useRef(r);w.current=r,d.useEffect(()=>{if(!g)return;const b=window.setTimeout(()=>w.current(),Fle);return()=>window.clearTimeout(b)},[g]);const N=()=>{i.trim()===""||o||(c(!0),h(null),(async()=>{try{const b=await T.saveTelegramToken(i.trim());if(l(""),m(b.botUsername??null),b.restartNeeded){h(b.note??z.telegram.restart);return}await j()}catch(b){h(b instanceof he?b.message:String(b))}finally{c(!1)}})())},y=()=>{h(null),j().catch(b=>h(b instanceof he?b.message:String(b)))};return p?t.jsxs(t.Fragment,{children:[t.jsx(ct,{children:t.jsx(vt,{children:k&&!g?z.telegram.expired:z.telegram.scan})}),t.jsx(bn,{actions:g?t.jsx(E,{variant:"accent",onClick:r,children:z.telegram.close}):t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:r,children:z.telegram.notNow}),k?t.jsx(E,{variant:"accent",onClick:y,children:z.telegram.newCode}):null]}),children:k&&!g?null:t.jsx(Hae,{offer:p,square:v,bot:f,paired:g,status:g?z.telegram.pairedWith(n):z.telegram.waiting})})]}):e&&!u?t.jsx(ct,{children:t.jsx(bs,{line:z.telegram.making})}):e?t.jsxs(t.Fragment,{children:[t.jsx(ct,{children:t.jsx(vt,{children:u})}),t.jsx(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:r,children:z.telegram.notNow}),t.jsx(E,{variant:"accent",onClick:y,children:z.telegram.newCode})]})})]}):t.jsxs(t.Fragment,{children:[t.jsxs(ct,{children:[t.jsx(vt,{children:z.telegram.how}),u?t.jsx(vt,{children:u}):null]}),t.jsx(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:r,children:z.telegram.notNow}),t.jsx(E,{variant:"accent",disabled:o||i.trim()==="",onClick:N,children:z.telegram.submit})]}),children:t.jsx(oe,{label:z.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(),N())}})})})]})}const Yg={recovery:0,lost:1,paused:2},zle="Lost buddi. Retrying…",Ule="The queue is paused. Nothing is being claimed until you resume it.";function Ble(e){const n=[];return e.recovery&&n.push({id:"recovery",priority:Yg.recovery,tone:"warning",text:I2,action:{label:"Finish the checklist",href:wv}}),e.lost&&n.push({id:"lost",priority:Yg.lost,tone:"critical",text:zle}),e.paused&&n.push({id:"paused",priority:Yg.paused,tone:"warning",text:Ule,action:{label:"Resume",onClick:()=>{T.setPaused(!1).catch(()=>{})}}}),n}function Wle({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(`
150
+ `),children:["+",a.length," more"]}):null,i!=null&&i.href?t.jsx(nt,{size:"sm",href:i.href,onClick:l=>{l.preventDefault(),n(i.href)},children:i.label}):i?t.jsx(E,{size:"sm",onClick:i.onClick,children:i.label}):null]})}const nD=1e4,Hle=3e4,sD=6e3,uk=/^(localhost|127(?:\.\d{1,3}){3}|\[?::1\]?)$|\.localhost$/i;function Kle(e){return uk.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 rD(e){let n;const s=new Promise((r,a)=>{n=setTimeout(()=>a(new he(0,sf)),e)});try{return{up:!0,version:await Promise.race([T.version(),s])}}catch(r){return rf(r)?{up:!1}:{up:!0}}finally{clearTimeout(n)}}function aD(e){var n;return e.up&&$y((n=e.version)==null?void 0:n.web)?(window.location.reload(),!1):e.up}function Vle({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:xi("core"),alt:""})}),t.jsxs("h1",{children:["buddi isn't answering at ",e,"."]}),t.jsx("p",{children:Kle(e.replace(/:\d+$/,""))}),t.jsx("div",{className:"unreachable-actions",children:t.jsx(E,{variant:"accent",onClick:n,disabled:s,children:s?"Retrying…":"Retry"})})]})}function Gle({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 rD(sD);i.current=!1,a(!1),s(c=>c==="checking"?o.up?"up":"down":aD(o)?"up":"down")},[]);return d.useEffect(()=>{l()},[l]),d.useEffect(()=>{if(n!=="down")return;const o=window.setInterval(()=>void l(),nD);return()=>window.clearInterval(o)},[n,l]),n==="checking"?null:n==="down"?t.jsx(Vle,{host:window.location.host,onRetry:()=>void l(),retrying:r}):t.jsx(t.Fragment,{children:e})}function Yle(e=Hle){const[n,s]=d.useState(!1);return d.useEffect(()=>{let r;const a=()=>{clearTimeout(r);const l=xu();if(l===null)return s(!1);const o=l+e-Date.now();o<=0?s(!0):r=setTimeout(a,o)};a();const i=iy(a);return()=>{i(),clearTimeout(r)}},[e]),n}function qle(){const e=Yle();return d.useEffect(()=>{if(!e)return;const n=window.setInterval(()=>{rD(sD).then(aD)},nD);return()=>window.clearInterval(n)},[e]),e}const Qle={local:"Local",tailnet:"Tailnet",reconnecting:"Reconnecting…"},q1=(e,n,s=`${n}s`)=>e===1?n:s;function Jle(){return Intl.DateTimeFormat().resolvedOptions().timeZone}function Xle(e){return e.includes("/")?e.split("/").pop().replace(/_/g," "):e}function Zle(e,n){return n?"reconnecting":uk.test(e)?"local":"tailnet"}function iD(e,n,s=Jle()){const r=[],a=Qle[e.link];if(r.push({key:"link",route:_e("system"),dot:e.link==="reconnecting"?"warning":"good",text:a,label:`Connection: ${a}`}),e.focus){const u=`${Li[e.focus.mode]} ${Tu(e.focus,e.timezone,n)}`;r.push({key:"focus",route:_e("notifications"),icon:"moon",text:u,label:`Focus: ${u}`})}const i=[];if(e.working>0&&i.push({key:"working",dot:"working",text:`${e.working} ${q1(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?`${Jt}/jobs?state=failed`:`${Jt}/jobs`,parts:i,label:`Work: ${i.map(u=>u.text).join(", ")}`}),e.approvals>0){const u=`${q1(e.approvals,"approval")} waiting`;r.push({key:"approvals",route:uo,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:_e("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=Tt(n,l),c=l!==s;return r.push({key:"time",route:_e("you"),end:!0,time:o,...c?{zone:Xle(l)}:{},label:`Your time: ${o}${c?`, ${l}`:""}`}),r}function eoe(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 lD(){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 toe(){const[e,n]=d.useState(()=>xu()!==null);return d.useEffect(()=>iy(()=>n(xu()!==null)),[]),e}function oD({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(ie,{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 noe({status:e,onNavigate:n}){const s=lD(),r=Jm(),a=iD(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(oD,{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(ie,{name:"lock",size:13})}):null]})}function soe({status:e,onNavigate:n}){const s=lD(),r=Jm(),a=eoe(e);return t.jsx("div",{className:"rail-status",children:t.jsxs(Ku,{modal:!1,children:[t.jsx(Vu,{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(Oo,{children:t.jsxs(Gu,{className:"ui-menu rail-status-menu",side:"right",align:"end",sideOffset:10,children:[t.jsx(Ji,{className:"ui-menu-label",children:"Status"}),iD(e,s).map(i=>t.jsx(ms,{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(oD,{item:i})})})},i.key)),r.pin?t.jsxs(t.Fragment,{children:[t.jsx(_r,{className:"ui-menu-sep"}),t.jsx(ms,{className:"ui-menu-item rail-status-item","data-item":"lock",onSelect:()=>r.lockNow(),children:t.jsxs("span",{className:"rail-status-line",children:[t.jsx(ie,{name:"lock",size:12}),t.jsx("span",{children:"Lock now"})]})})]}):null]})})]})})}const roe=1e4;function cD(){return d.useSyncExternalStore(r5,UN,UN)}function aoe(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 Q1(e){const n=Math.max(0,Math.floor(e/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function ioe({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(E,{size:"sm",onClick:()=>{var r;(r=navigator.clipboard)==null||r.writeText(e).then(()=>s(!0),()=>{})},children:n?"Copied":"Copy"})]})}function loe({state:e,elapsedMs:n,hostname:s=window.location.hostname,onReload:r=()=>Xl.reload()}){const a=aoe(e),i=e.kind==="stop",l=!i&&n>=(e.patienceMs??ZB),o=uk.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(Ju,{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(ioe,{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?`${Q1(n)} · still checking every few seconds`:n>=roe?`${Q1(n)} · this page reloads when buddi is back`:"This page reloads when buddi is back."}),i||l?t.jsx(E,{size:"sm",variant:l?"accent":void 0,onClick:r,children:"Reload"}):null]})]})})})}function ooe(e){const[n,s]=d.useState(()=>Xl.now());return d.useEffect(()=>{if(!e)return;s(Xl.now());const r=window.setInterval(()=>s(Xl.now()),1e3);return()=>window.clearInterval(r)},[e]),e?Math.max(0,n-e.startedAt):0}function coe({children:e}){const n=cD(),s=ooe(n),r=d.useRef(null);return d.useEffect(()=>{i5();let a=xu()!==null;const i=iy(()=>{const o=xu()!==null;a&&!o&&BN(),a=o}),l=()=>void BN();return window.addEventListener(yu,l),()=>{i(),window.removeEventListener(yu,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(loe,{state:n,elapsedMs:s}):null]})}const uoe="(max-width: 1080px)",doe="(max-width: 720px)";function hoe(){const[e,n]=d.useState(()=>window.location.hash||Tn);d.useEffect(()=>{const r=()=>n(window.location.hash||Tn);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 foe(){const[e,n]=qM();d.useEffect(()=>{YM(e)},[e]);const s=d.useCallback(r=>n({theme:r}),[n]);return[e.theme,s]}const J1=new Map;function moe(){var F,Fe,Ct,on;const[e,n]=hoe(),[s,r]=d.useState("UTC"),[a,i]=d.useState({approvals:0,failed:0,paused:!1,running:0,needs:0}),[l,o]=foe(),c=Yn(Fy),[u,h]=d.useState(!1),[f,m]=d.useState([]),[p,v]=d.useState(null),[g,k]=d.useState(null),[j,x]=d.useState([]),[w,N]=d.useState(!1),[y,b]=d.useState(null),[S,C]=d.useState(null),[A,$]=d.useState(0),[I,P]=d.useState(null),O=x5(),R=f.find($e=>$e.id===p)??null,D=R!==null&&Z7(e),[U,W]=d.useState(!1),M=d.useCallback(()=>W(!0),[]);d.useEffect(()=>{D||W(!1)},[D]),oZ(n,vh(e)===null,D?M:void 0);const L=Yn(uoe),_=T2(),Y=TI(),B=WM(),se=me(()=>Promise.resolve().then(()=>T.version()),[],BB),G=se.data;JB(se.reload);const X=G&&!G.checkout&&G.updateAvailable?G:null,K=$y(G==null?void 0:G.web);XB(G==null?void 0:G.web);const J=((F=me(()=>Promise.resolve().then(()=>T.connectionSignals()),[],6e4).data)==null?void 0:F.signals)??[],[q,ce]=d.useState(null),xe=d.useMemo(()=>new Set(q?[q]:[]),[q]),[Me,H]=d.useState(new Map);d.useEffect(()=>{const $e=()=>{T.conversations().then(it=>{const jt=new Map;for(const ut of it.conversations){const Bn=ut.lastMessageAt??ut.createdAt,Sn=jt.get(ut.agentId);(!Sn||Bn>Sn)&&jt.set(ut.agentId,Bn)}H(jt)}).catch(()=>{})};$e();const Oe=window.setInterval($e,3e4);return()=>window.clearInterval(Oe)},[e]);const[ne,Z]=d.useState(!1),[ye,Ce]=d.useState("unknown");d.useEffect(()=>{if(ne)return;let $e=!1;return T.onboarding().then(Oe=>{$e||(Z(!0),Ce(Oe.state==="done"||Oe.state==="skipped"?"done":"open"),Oe.state==="pending"&&Oe.needs.model&&!vh(window.location.hash)&&n(aB,!0))}).catch(()=>{$e||(Z(!0),Ce("open"))}),()=>{$e=!0}},[ne,n]),d.useEffect(()=>{const $e=$B(e);$e&&n($e,!0)},[e,n]),d.useEffect(()=>{let $e=!1;const Oe=()=>{Qe.agents().then(jt=>{$e||(m(jt.agents),t_(jt.commands),DB(jt.defaultAgentId??null),v(jt.defaultAgentId??null),k(ut=>{var Bn;return ut??jt.defaultAgentId??((Bn=jt.agents[0])==null?void 0:Bn.id)??null}))}).catch(()=>{})};Oe();const it=window.setInterval(Oe,15e3);return window.addEventListener("focus",Oe),window.addEventListener(ks,Oe),()=>{$e=!0,window.clearInterval(it),window.removeEventListener("focus",Oe),window.removeEventListener(ks,Oe)}},[e]),d.useEffect(()=>{let $e=!1;const Oe=()=>{Qe.groups().then(jt=>{$e||x(jt.groups)}).catch(()=>{})};Oe();const it=window.setInterval(Oe,3e4);return()=>{$e=!0,window.clearInterval(it)}},[e]);const ke=II(f,p),we=lB(e),ve=vI(e),Ie=ve?j.find($e=>$e.id===ve.groupId)??null:null,Re=ve?null:(we==null?void 0:we.agentId)??g;d.useEffect(()=>{we&&k(we.agentId)},[we==null?void 0:we.agentId]);const de=d.useRef(null);we&&(de.current=e);const Ee=$e=>{k($e),n(lt($e))},ze=$e=>n(Ii($e)),qe=d.useCallback(($e,Oe,it=!0)=>n(ve?Ii(ve.groupId,Oe):lt($e,Oe),it),[n,ve==null?void 0:ve.groupId]),[ht,le]=d.useState(!1),[,je]=d.useState(0);d.useEffect(()=>{const $e=()=>{je(Oe=>Oe+1),T.session().then(Oe=>r(Oe.timezone)).catch(()=>{})};return window.addEventListener(tv,$e),()=>window.removeEventListener(tv,$e)},[]),d.useEffect(()=>{T.session().then($e=>{ry({timeFormat:$e.timeFormat??null,dateFormat:$e.dateFormat??null}),r($e.timezone),le(!0)}).catch(()=>{})},[]);const et=oY(ht);fY(ht,et.refresh,()=>le(!1)),d.useEffect(()=>{const $e=()=>{T.overview().then(it=>{var jt;return i({approvals:it.approvals.pending,failed:it.jobs.failed??0,paused:it.paused,running:it.running??0,needs:((jt=it.needsYou)==null?void 0:jt.total)??it.approvals.pending+(it.jobs.failed??0)})}).catch(()=>{})};$e();const Oe=window.setInterval($e,2e4);return window.addEventListener(Di,$e),()=>{window.clearInterval(Oe),window.removeEventListener(Di,$e)}},[]);const ft=me(()=>Promise.resolve().then(()=>T.focus()),[],6e4),Et=d.useRef(ft.reload);Et.current=ft.reload,d.useEffect(()=>{const $e=()=>Et.current();return window.addEventListener(Di,$e),()=>window.removeEventListener(Di,$e)},[]);const Ft=toe(),Pt=qle(),Rn=cD()!==null,zn=Yn(doe);d.useEffect(()=>{if(!ht)return;if(e===TB){N(!0),n(pa,!0);return}const $e=IB(e),Oe=new Date().toDateString();!$e||J1.get($e)===Oe||(J1.set($e,Oe),T.tipsSeenPage($e).catch(()=>{}))},[e,ht,n]);const Yt={link:Zle(window.location.hostname,Ft&&!Rn),focus:((Fe=ft.data)==null?void 0:Fe.focus)??null,working:a.running,paused:a.paused,failed:a.failed,approvals:a.approvals,version:G?{current:G.current,latest:G.latest,updateAvailable:!G.checkout&&G.updateAvailable}:void 0,timezone:s},Un=Ble({recovery:((Ct=_.data)==null?void 0:Ct.active)===!0,lost:Pt&&!Rn,paused:a.paused}),xn=vh(e),vn=NI(e),Xn=vn===pa,_t=y?j.find($e=>$e.id===y.groupId)??null:null,Te=$e=>x(Oe=>Oe.map(it=>it.id===$e.id?$e:it)),rt=()=>b(null),De=w?t.jsx(mY,{agents:f,onClose:()=>N(!1),onCreated:$e=>{x(Oe=>[...Oe,$e]),N(!1),n(Ii($e.id))}}):_t&&(y==null?void 0:y.kind)==="members"?t.jsx(z7,{group:_t,agents:f,onClose:rt,onSaved:Te}):_t&&(y==null?void 0:y.kind)==="rename"?t.jsx(U7,{group:_t,onClose:rt,onSaved:$e=>{Te($e),rt()}}):_t&&(y==null?void 0:y.kind)==="clear"?t.jsx(W7,{group:_t,onClose:rt,onCleared:()=>{rt(),$($e=>$e+1),n(Ii(_t.id),!0)}}):_t&&(y==null?void 0:y.kind)==="delete"?t.jsx(H7,{group:_t,agents:f,onClose:rt,onDeleted:$e=>{const Oe=j.findIndex(it=>it.id===_t.id);rt(),x(it=>it.filter(jt=>jt.id!==_t.id)),C({group:_t,index:Oe,until:$e}),n(de.current??pa)}}):null,tt=()=>{const $e=S;$e&&(C(null),Qe.restoreGroup($e.group.id).then(Oe=>{x(it=>{if(it.some(ut=>ut.id===Oe.id))return it;const jt=[...it];return jt.splice(Math.min(Math.max($e.index,0),jt.length),0,Oe),jt}),n(Ii(Oe.id))}).catch(()=>P($e.group.name)))};return xn?t.jsx(jN,{delayDuration:400,children:t.jsxs(iN,{swipeDirection:"right",children:[t.jsx(rle,{navigate:n,timezone:s}),t.jsx(lN,{className:"ui-toasts"})]})}):t.jsx(V5,{picture:(on=f.find($e=>$e.id===p))==null?void 0:on.picture,children:t.jsx(jN,{delayDuration:400,children:t.jsxs(iN,{swipeDirection:"right",children:[De,t.jsxs("div",{className:"wb-shell",children:[t.jsx(Wle,{banners:Un,onNavigate:n}),t.jsxs("div",{className:"wb",children:[t.jsx(QX,{attention:a.needs,place:vn,onNavigate:n,theme:l,onTheme:o,plugins:iZ(Y.rail,B),updateAvailable:X!==null,settingsDot:J.length>0?BM:void 0,stale:K,timezone:s,version:G&&!G.checkout?{current:G.current,latest:G.latest,updateAvailable:G.updateAvailable}:G?{current:G.current,updateAvailable:!1}:void 0,status:zn?t.jsx(soe,{status:Yt,onNavigate:n}):void 0}),Xn&&!L?t.jsx(LI,{agents:ke,currentId:Re,attention:O,onSelect:Ee,lastActivity:Me,working:xe,groups:j,currentGroupId:(Ie==null?void 0:Ie.id)??null,onSelectGroup:ze,onNewGroup:()=>N(!0)}):null,Xn?t.jsx(K7,{timezone:s,agents:ke,agentId:Ie?Ie.coordinator:Re,defaultAgentId:p,group:Ie,...Ie?{onGroupAction:$e=>b({kind:$e,groupId:Ie.id})}:{},requestedConversationId:(ve==null?void 0:ve.conversationId)??(we==null?void 0:we.conversationId),requestedTab:we==null?void 0:we.tab,onConversationOpened:qe,onSelectAgent:Ee,onWorking:ce,attention:O,agentsInHeader:L,narrow:c,canvasOpen:u,onOpenCanvas:()=>h(!0),onCloseCanvas:()=>h(!1)},`room-${A}`):t.jsx("main",{"data-ground":poe(vn,e)?"plain":void 0,"data-layout":vn===hn?"split":void 0,children:t.jsx(goe,{hash:e,place:vn,timezone:s,navigate:n,agents:f,defaultAgentId:p,attention:O,pluginPages:Y,update:X,connectionSignals:J,onboarding:ye})})]}),zn?null:t.jsx(noe,{status:Yt,onNavigate:n})]}),D&&R?t.jsx(eY,{agent:R,agents:f,timezone:s,open:U,onOpenChange:W,navigate:n}):null,t.jsxs(iY,{placement:aY(D,U),children:[t.jsx(cY,{queue:et.queue,agents:f,navigate:n,onDismiss:et.dismiss}),S?t.jsx(Cu,{title:`Deleted ${S.group.name}`,body:"Its history goes for good in a few seconds.",duration:gY,onUndo:tt,onGone:()=>C(null)},S.group.id):null,I?t.jsx(Cu,{title:`${I} is gone for good`,body:"Undo came too late to bring it back.",duration:6e3,onGone:()=>P(null)},`late-${I}`):null,t.jsx(lN,{className:"ui-toasts"})]})]})})})}function poe(e,n){return Ny(n)!==null}function goe({place:e,pluginPages:n,...s}){const r={...s,pluginPages:n},a=Ny(s.hash);if(a){const i=n.find(a.plugin,a.page);if(i)return t.jsx(wM,{page:i,item:a.item??null,params:Sy(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 bt:return t.jsx(Nte,{...r});case Jt:return t.jsx(EZ,{...s});case hn:return t.jsx(gie,{...r});case ba:return t.jsx(mJ,{...s});default:return t.jsx(cne,{...r})}}function xoe(){"serviceWorker"in navigator&&window.addEventListener("load",()=>{const e=`./sw.js?v=${encodeURIComponent(Ay)}`;navigator.serviceWorker.register(e,{scope:"./"}).catch(()=>{})})}function voe({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(b2);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(nt,{href:"/#/settings/connections",children:"Back to Connections"}):null]})})}const X1=document.getElementById("root");X1&&d$(X1).render(t.jsx(d.StrictMode,{children:location.pathname==="/connections/callback"?t.jsx(voe,{}):t.jsx(coe,{children:t.jsx(Gle,{children:t.jsx(qX,{children:t.jsx(moe,{})})})})}));xoe();export{woe as c,kD as g};