@withbuddi/buddi 0.1.0-pre.43 → 0.1.0-pre.45

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 (695) hide show
  1. package/examples/agents/agent-father/agent.md +12 -5
  2. package/examples/agents/concierge/agent.md +11 -3
  3. package/extension/icons/128.png +0 -0
  4. package/extension/icons/16.png +0 -0
  5. package/extension/icons/32.png +0 -0
  6. package/extension/icons/48.png +0 -0
  7. package/extension/manifest.json +7 -3
  8. package/node_modules/@buddi/cli/dist/.tsbuildinfo +1 -1
  9. package/node_modules/@buddi/cli/dist/access-cmd.d.ts +2 -1
  10. package/node_modules/@buddi/cli/dist/access-cmd.d.ts.map +1 -1
  11. package/node_modules/@buddi/cli/dist/access-cmd.js +40 -7
  12. package/node_modules/@buddi/cli/dist/access-cmd.js.map +1 -1
  13. package/node_modules/@buddi/cli/dist/args.d.ts +2 -1
  14. package/node_modules/@buddi/cli/dist/args.d.ts.map +1 -1
  15. package/node_modules/@buddi/cli/dist/args.js +7 -3
  16. package/node_modules/@buddi/cli/dist/args.js.map +1 -1
  17. package/node_modules/@buddi/cli/dist/commands.d.ts.map +1 -1
  18. package/node_modules/@buddi/cli/dist/commands.js +3 -2
  19. package/node_modules/@buddi/cli/dist/commands.js.map +1 -1
  20. package/node_modules/@buddi/cli/dist/main.js +1 -1
  21. package/node_modules/@buddi/cli/dist/main.js.map +1 -1
  22. package/node_modules/@buddi/cli/dist/mcp/server.js +1 -1
  23. package/node_modules/@buddi/cli/dist/mcp/server.js.map +1 -1
  24. package/node_modules/@buddi/cli/dist/mcp/tools.d.ts.map +1 -1
  25. package/node_modules/@buddi/cli/dist/mcp/tools.js +60 -0
  26. package/node_modules/@buddi/cli/dist/mcp/tools.js.map +1 -1
  27. package/node_modules/@buddi/core/dist/.tsbuildinfo +1 -1
  28. package/node_modules/@buddi/core/dist/lock.d.ts +15 -1
  29. package/node_modules/@buddi/core/dist/lock.d.ts.map +1 -1
  30. package/node_modules/@buddi/core/dist/lock.js +15 -1
  31. package/node_modules/@buddi/core/dist/lock.js.map +1 -1
  32. package/node_modules/@buddi/core/dist/pages.d.ts +75 -0
  33. package/node_modules/@buddi/core/dist/pages.d.ts.map +1 -1
  34. package/node_modules/@buddi/core/dist/pages.js +14 -0
  35. package/node_modules/@buddi/core/dist/pages.js.map +1 -1
  36. package/node_modules/@buddi/core/dist/plugin/index.d.ts +2 -2
  37. package/node_modules/@buddi/core/dist/plugin/index.d.ts.map +1 -1
  38. package/node_modules/@buddi/core/dist/plugin/index.js.map +1 -1
  39. package/node_modules/@buddi/core/dist/plugin/version.d.ts +1 -1
  40. package/node_modules/@buddi/core/dist/plugin/version.js +1 -1
  41. package/node_modules/@buddi/core/dist/provider-accounts.d.ts +32 -0
  42. package/node_modules/@buddi/core/dist/provider-accounts.d.ts.map +1 -1
  43. package/node_modules/@buddi/core/dist/provider-accounts.js +22 -0
  44. package/node_modules/@buddi/core/dist/provider-accounts.js.map +1 -1
  45. package/node_modules/@buddi/core/dist/tools.d.ts +6 -1
  46. package/node_modules/@buddi/core/dist/tools.d.ts.map +1 -1
  47. package/node_modules/@buddi/core/dist/tools.js.map +1 -1
  48. package/node_modules/@buddi/core/migrations/077_lock_background_portrait.sql +5 -0
  49. package/node_modules/@buddi/gateway/dist/.tsbuildinfo +1 -1
  50. package/node_modules/@buddi/gateway/dist/agents/agent-intro.d.ts +31 -0
  51. package/node_modules/@buddi/gateway/dist/agents/agent-intro.d.ts.map +1 -0
  52. package/node_modules/@buddi/gateway/dist/agents/agent-intro.js +116 -0
  53. package/node_modules/@buddi/gateway/dist/agents/agent-intro.js.map +1 -0
  54. package/node_modules/@buddi/gateway/dist/agents/delegation.d.ts +10 -0
  55. package/node_modules/@buddi/gateway/dist/agents/delegation.d.ts.map +1 -1
  56. package/node_modules/@buddi/gateway/dist/agents/delegation.js +18 -1
  57. package/node_modules/@buddi/gateway/dist/agents/delegation.js.map +1 -1
  58. package/node_modules/@buddi/gateway/dist/agents/owner-tools.d.ts +21 -8
  59. package/node_modules/@buddi/gateway/dist/agents/owner-tools.d.ts.map +1 -1
  60. package/node_modules/@buddi/gateway/dist/agents/owner-tools.js +201 -36
  61. package/node_modules/@buddi/gateway/dist/agents/owner-tools.js.map +1 -1
  62. package/node_modules/@buddi/gateway/dist/agents/platform.d.ts +14 -1
  63. package/node_modules/@buddi/gateway/dist/agents/platform.d.ts.map +1 -1
  64. package/node_modules/@buddi/gateway/dist/agents/platform.js +44 -11
  65. package/node_modules/@buddi/gateway/dist/agents/platform.js.map +1 -1
  66. package/node_modules/@buddi/gateway/dist/bootstrap.d.ts.map +1 -1
  67. package/node_modules/@buddi/gateway/dist/bootstrap.js +2 -0
  68. package/node_modules/@buddi/gateway/dist/bootstrap.js.map +1 -1
  69. package/node_modules/@buddi/gateway/dist/edition-origin.d.ts +57 -0
  70. package/node_modules/@buddi/gateway/dist/edition-origin.d.ts.map +1 -0
  71. package/node_modules/@buddi/gateway/dist/edition-origin.js +156 -0
  72. package/node_modules/@buddi/gateway/dist/edition-origin.js.map +1 -0
  73. package/node_modules/@buddi/gateway/dist/evals/golden.d.ts +5 -0
  74. package/node_modules/@buddi/gateway/dist/evals/golden.d.ts.map +1 -1
  75. package/node_modules/@buddi/gateway/dist/evals/golden.js +48 -0
  76. package/node_modules/@buddi/gateway/dist/evals/golden.js.map +1 -1
  77. package/node_modules/@buddi/gateway/dist/mcp/requests.d.ts +8 -2
  78. package/node_modules/@buddi/gateway/dist/mcp/requests.d.ts.map +1 -1
  79. package/node_modules/@buddi/gateway/dist/mcp/requests.js +74 -1
  80. package/node_modules/@buddi/gateway/dist/mcp/requests.js.map +1 -1
  81. package/node_modules/@buddi/gateway/dist/owner-profile-edit.d.ts +160 -0
  82. package/node_modules/@buddi/gateway/dist/owner-profile-edit.d.ts.map +1 -0
  83. package/node_modules/@buddi/gateway/dist/owner-profile-edit.js +296 -0
  84. package/node_modules/@buddi/gateway/dist/owner-profile-edit.js.map +1 -0
  85. package/node_modules/@buddi/gateway/dist/provider-accounts.d.ts.map +1 -1
  86. package/node_modules/@buddi/gateway/dist/provider-accounts.js +2 -1
  87. package/node_modules/@buddi/gateway/dist/provider-accounts.js.map +1 -1
  88. package/node_modules/@buddi/gateway/dist/system-context.d.ts +9 -0
  89. package/node_modules/@buddi/gateway/dist/system-context.d.ts.map +1 -1
  90. package/node_modules/@buddi/gateway/dist/system-context.js +28 -2
  91. package/node_modules/@buddi/gateway/dist/system-context.js.map +1 -1
  92. package/node_modules/@buddi/gateway/dist/telegram/approvals.d.ts +6 -0
  93. package/node_modules/@buddi/gateway/dist/telegram/approvals.d.ts.map +1 -1
  94. package/node_modules/@buddi/gateway/dist/telegram/approvals.js +10 -2
  95. package/node_modules/@buddi/gateway/dist/telegram/approvals.js.map +1 -1
  96. package/node_modules/@buddi/gateway/dist/telegram/main.d.ts.map +1 -1
  97. package/node_modules/@buddi/gateway/dist/telegram/main.js +10 -3
  98. package/node_modules/@buddi/gateway/dist/telegram/main.js.map +1 -1
  99. package/node_modules/@buddi/gateway/dist/telegram/outbound.d.ts +9 -0
  100. package/node_modules/@buddi/gateway/dist/telegram/outbound.d.ts.map +1 -1
  101. package/node_modules/@buddi/gateway/dist/telegram/outbound.js +43 -0
  102. package/node_modules/@buddi/gateway/dist/telegram/outbound.js.map +1 -1
  103. package/node_modules/@buddi/gateway/dist/telegram/surface.d.ts +2 -0
  104. package/node_modules/@buddi/gateway/dist/telegram/surface.d.ts.map +1 -1
  105. package/node_modules/@buddi/gateway/dist/telegram/surface.js +2 -1
  106. package/node_modules/@buddi/gateway/dist/telegram/surface.js.map +1 -1
  107. package/node_modules/@buddi/gateway/dist/tips/engine.d.ts +32 -0
  108. package/node_modules/@buddi/gateway/dist/tips/engine.d.ts.map +1 -1
  109. package/node_modules/@buddi/gateway/dist/tips/engine.js +69 -0
  110. package/node_modules/@buddi/gateway/dist/tips/engine.js.map +1 -1
  111. package/node_modules/@buddi/gateway/dist/tips/route.d.ts +1 -3
  112. package/node_modules/@buddi/gateway/dist/tips/route.d.ts.map +1 -1
  113. package/node_modules/@buddi/gateway/dist/tips/route.js +54 -30
  114. package/node_modules/@buddi/gateway/dist/tips/route.js.map +1 -1
  115. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-connector.d.ts +63 -0
  116. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-connector.d.ts.map +1 -0
  117. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-connector.js +87 -0
  118. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-connector.js.map +1 -0
  119. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-setup.d.ts +39 -4
  120. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-setup.d.ts.map +1 -1
  121. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-setup.js +99 -11
  122. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-setup.js.map +1 -1
  123. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-token.js +1 -1
  124. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-token.js.map +1 -1
  125. package/node_modules/@buddi/gateway/dist/web/access/index.d.ts +1 -0
  126. package/node_modules/@buddi/gateway/dist/web/access/index.d.ts.map +1 -1
  127. package/node_modules/@buddi/gateway/dist/web/access/index.js +1 -0
  128. package/node_modules/@buddi/gateway/dist/web/access/index.js.map +1 -1
  129. package/node_modules/@buddi/gateway/dist/web/agent-offers.d.ts +10 -1
  130. package/node_modules/@buddi/gateway/dist/web/agent-offers.d.ts.map +1 -1
  131. package/node_modules/@buddi/gateway/dist/web/agent-offers.js +14 -1
  132. package/node_modules/@buddi/gateway/dist/web/agent-offers.js.map +1 -1
  133. package/node_modules/@buddi/gateway/dist/web/api-routes.d.ts.map +1 -1
  134. package/node_modules/@buddi/gateway/dist/web/api-routes.js +37 -8
  135. package/node_modules/@buddi/gateway/dist/web/api-routes.js.map +1 -1
  136. package/node_modules/@buddi/gateway/dist/web/approval-ask.d.ts +16 -0
  137. package/node_modules/@buddi/gateway/dist/web/approval-ask.d.ts.map +1 -0
  138. package/node_modules/@buddi/gateway/dist/web/approval-ask.js +51 -0
  139. package/node_modules/@buddi/gateway/dist/web/approval-ask.js.map +1 -0
  140. package/node_modules/@buddi/gateway/dist/web/chat.d.ts +6 -0
  141. package/node_modules/@buddi/gateway/dist/web/chat.d.ts.map +1 -1
  142. package/node_modules/@buddi/gateway/dist/web/chat.js +4 -0
  143. package/node_modules/@buddi/gateway/dist/web/chat.js.map +1 -1
  144. package/node_modules/@buddi/gateway/dist/web/live.d.ts +7 -0
  145. package/node_modules/@buddi/gateway/dist/web/live.d.ts.map +1 -1
  146. package/node_modules/@buddi/gateway/dist/web/live.js +12 -0
  147. package/node_modules/@buddi/gateway/dist/web/live.js.map +1 -1
  148. package/node_modules/@buddi/gateway/dist/web/lock-backgrounds.d.ts +9 -0
  149. package/node_modules/@buddi/gateway/dist/web/lock-backgrounds.d.ts.map +1 -0
  150. package/node_modules/@buddi/gateway/dist/web/lock-backgrounds.js +60 -0
  151. package/node_modules/@buddi/gateway/dist/web/lock-backgrounds.js.map +1 -0
  152. package/node_modules/@buddi/gateway/dist/web/lock.d.ts +13 -1
  153. package/node_modules/@buddi/gateway/dist/web/lock.d.ts.map +1 -1
  154. package/node_modules/@buddi/gateway/dist/web/lock.js +84 -23
  155. package/node_modules/@buddi/gateway/dist/web/lock.js.map +1 -1
  156. package/node_modules/@buddi/gateway/dist/web/places.d.ts +5 -0
  157. package/node_modules/@buddi/gateway/dist/web/places.d.ts.map +1 -1
  158. package/node_modules/@buddi/gateway/dist/web/places.js +11 -4
  159. package/node_modules/@buddi/gateway/dist/web/places.js.map +1 -1
  160. package/node_modules/@buddi/gateway/dist/web/server.d.ts +3 -0
  161. package/node_modules/@buddi/gateway/dist/web/server.d.ts.map +1 -1
  162. package/node_modules/@buddi/gateway/dist/web/server.js +63 -50
  163. package/node_modules/@buddi/gateway/dist/web/server.js.map +1 -1
  164. package/node_modules/@buddi/install/dist/.tsbuildinfo +1 -1
  165. package/node_modules/@buddi/install/dist/cloudflared.d.ts +121 -0
  166. package/node_modules/@buddi/install/dist/cloudflared.d.ts.map +1 -0
  167. package/node_modules/@buddi/install/dist/cloudflared.js +451 -0
  168. package/node_modules/@buddi/install/dist/cloudflared.js.map +1 -0
  169. package/node_modules/@buddi/install/dist/index.d.ts +1 -0
  170. package/node_modules/@buddi/install/dist/index.d.ts.map +1 -1
  171. package/node_modules/@buddi/install/dist/index.js +1 -0
  172. package/node_modules/@buddi/install/dist/index.js.map +1 -1
  173. package/node_modules/@buddi/install/dist/supervisor.d.ts +6 -1
  174. package/node_modules/@buddi/install/dist/supervisor.d.ts.map +1 -1
  175. package/node_modules/@buddi/install/dist/supervisor.js +51 -5
  176. package/node_modules/@buddi/install/dist/supervisor.js.map +1 -1
  177. package/node_modules/@buddi/runtime/dist/.tsbuildinfo +1 -1
  178. package/node_modules/@buddi/runtime/dist/codex-direct.d.ts +1 -1
  179. package/node_modules/@buddi/runtime/dist/codex-direct.js +1 -1
  180. package/node_modules/@buddi/runtime/dist/grounding.d.ts +54 -0
  181. package/node_modules/@buddi/runtime/dist/grounding.d.ts.map +1 -0
  182. package/node_modules/@buddi/runtime/dist/grounding.js +158 -0
  183. package/node_modules/@buddi/runtime/dist/grounding.js.map +1 -0
  184. package/node_modules/@buddi/runtime/dist/index.d.ts +1 -0
  185. package/node_modules/@buddi/runtime/dist/index.d.ts.map +1 -1
  186. package/node_modules/@buddi/runtime/dist/index.js +1 -0
  187. package/node_modules/@buddi/runtime/dist/index.js.map +1 -1
  188. package/node_modules/@buddi/runtime/dist/loop.d.ts +13 -0
  189. package/node_modules/@buddi/runtime/dist/loop.d.ts.map +1 -1
  190. package/node_modules/@buddi/runtime/dist/loop.js +98 -3
  191. package/node_modules/@buddi/runtime/dist/loop.js.map +1 -1
  192. package/node_modules/@buddi/tool-artifacts/dist/.tsbuildinfo +1 -1
  193. package/node_modules/@buddi/tool-browser/dist/.tsbuildinfo +1 -1
  194. package/node_modules/@buddi/tool-email/dist/.tsbuildinfo +1 -1
  195. package/node_modules/@buddi/tool-email/dist/agent.d.ts +6 -1
  196. package/node_modules/@buddi/tool-email/dist/agent.d.ts.map +1 -1
  197. package/node_modules/@buddi/tool-email/dist/agent.js +6 -1
  198. package/node_modules/@buddi/tool-email/dist/agent.js.map +1 -1
  199. package/node_modules/@buddi/tool-email/dist/html.d.ts +16 -0
  200. package/node_modules/@buddi/tool-email/dist/html.d.ts.map +1 -0
  201. package/node_modules/@buddi/tool-email/dist/html.js +273 -0
  202. package/node_modules/@buddi/tool-email/dist/html.js.map +1 -0
  203. package/node_modules/@buddi/tool-email/dist/imap/fake.d.ts +8 -0
  204. package/node_modules/@buddi/tool-email/dist/imap/fake.d.ts.map +1 -1
  205. package/node_modules/@buddi/tool-email/dist/imap/fake.js +15 -0
  206. package/node_modules/@buddi/tool-email/dist/imap/fake.js.map +1 -1
  207. package/node_modules/@buddi/tool-email/dist/imap/imapflow-client.d.ts +7 -0
  208. package/node_modules/@buddi/tool-email/dist/imap/imapflow-client.d.ts.map +1 -1
  209. package/node_modules/@buddi/tool-email/dist/imap/imapflow-client.js +79 -17
  210. package/node_modules/@buddi/tool-email/dist/imap/imapflow-client.js.map +1 -1
  211. package/node_modules/@buddi/tool-email/dist/index.d.ts +5 -1
  212. package/node_modules/@buddi/tool-email/dist/index.d.ts.map +1 -1
  213. package/node_modules/@buddi/tool-email/dist/index.js +11 -3
  214. package/node_modules/@buddi/tool-email/dist/index.js.map +1 -1
  215. package/node_modules/@buddi/tool-email/dist/mail.d.ts.map +1 -1
  216. package/node_modules/@buddi/tool-email/dist/mail.js +7 -0
  217. package/node_modules/@buddi/tool-email/dist/mail.js.map +1 -1
  218. package/node_modules/@buddi/tool-email/dist/pages/descriptors.d.ts.map +1 -1
  219. package/node_modules/@buddi/tool-email/dist/pages/descriptors.js +208 -176
  220. package/node_modules/@buddi/tool-email/dist/pages/descriptors.js.map +1 -1
  221. package/node_modules/@buddi/tool-email/dist/pages/index.d.ts +3 -1
  222. package/node_modules/@buddi/tool-email/dist/pages/index.d.ts.map +1 -1
  223. package/node_modules/@buddi/tool-email/dist/pages/index.js +5 -2
  224. package/node_modules/@buddi/tool-email/dist/pages/index.js.map +1 -1
  225. package/node_modules/@buddi/tool-email/dist/pages/queries.d.ts +17 -3
  226. package/node_modules/@buddi/tool-email/dist/pages/queries.d.ts.map +1 -1
  227. package/node_modules/@buddi/tool-email/dist/pages/queries.js +283 -62
  228. package/node_modules/@buddi/tool-email/dist/pages/queries.js.map +1 -1
  229. package/node_modules/@buddi/tool-email/dist/pages/thread-tools.d.ts +25 -0
  230. package/node_modules/@buddi/tool-email/dist/pages/thread-tools.d.ts.map +1 -0
  231. package/node_modules/@buddi/tool-email/dist/pages/thread-tools.js +33 -0
  232. package/node_modules/@buddi/tool-email/dist/pages/thread-tools.js.map +1 -0
  233. package/node_modules/@buddi/tool-email/dist/ports.d.ts +25 -0
  234. package/node_modules/@buddi/tool-email/dist/ports.d.ts.map +1 -1
  235. package/node_modules/@buddi/tool-email/dist/ports.js.map +1 -1
  236. package/node_modules/@buddi/tool-email/dist/retention.d.ts.map +1 -1
  237. package/node_modules/@buddi/tool-email/dist/retention.js +1 -0
  238. package/node_modules/@buddi/tool-email/dist/retention.js.map +1 -1
  239. package/node_modules/@buddi/tool-email/dist/sources/inbox-poll.d.ts +9 -1
  240. package/node_modules/@buddi/tool-email/dist/sources/inbox-poll.d.ts.map +1 -1
  241. package/node_modules/@buddi/tool-email/dist/sources/inbox-poll.js +5 -2
  242. package/node_modules/@buddi/tool-email/dist/sources/inbox-poll.js.map +1 -1
  243. package/node_modules/@buddi/tool-email/dist/text-cleanup.d.ts +69 -0
  244. package/node_modules/@buddi/tool-email/dist/text-cleanup.d.ts.map +1 -0
  245. package/node_modules/@buddi/tool-email/dist/text-cleanup.js +96 -0
  246. package/node_modules/@buddi/tool-email/dist/text-cleanup.js.map +1 -0
  247. package/node_modules/@buddi/tool-email/dist/text.d.ts +29 -0
  248. package/node_modules/@buddi/tool-email/dist/text.d.ts.map +1 -0
  249. package/node_modules/@buddi/tool-email/dist/text.js +153 -0
  250. package/node_modules/@buddi/tool-email/dist/text.js.map +1 -0
  251. package/node_modules/@buddi/tool-email/dist/worker.d.ts +64 -0
  252. package/node_modules/@buddi/tool-email/dist/worker.d.ts.map +1 -0
  253. package/node_modules/@buddi/tool-email/dist/worker.js +123 -0
  254. package/node_modules/@buddi/tool-email/dist/worker.js.map +1 -0
  255. package/node_modules/@buddi/tool-email/migrations/028_reading.sql +23 -0
  256. package/node_modules/@buddi/tool-email/package.json +1 -0
  257. package/node_modules/@buddi/tool-host/dist/.tsbuildinfo +1 -1
  258. package/node_modules/@buddi/tool-mcp/dist/.tsbuildinfo +1 -1
  259. package/node_modules/@buddi/tool-memory/dist/.tsbuildinfo +1 -1
  260. package/node_modules/@buddi/tool-web/dist/.tsbuildinfo +1 -1
  261. package/node_modules/entities/LICENSE +11 -0
  262. package/node_modules/entities/decode.d.ts +1 -0
  263. package/node_modules/entities/decode.js +3 -0
  264. package/node_modules/entities/dist/commonjs/decode-codepoint.d.ts +19 -0
  265. package/node_modules/entities/dist/commonjs/decode-codepoint.d.ts.map +1 -0
  266. package/node_modules/entities/dist/commonjs/decode-codepoint.js +77 -0
  267. package/node_modules/entities/dist/commonjs/decode-codepoint.js.map +1 -0
  268. package/node_modules/entities/dist/commonjs/decode.d.ts +209 -0
  269. package/node_modules/entities/dist/commonjs/decode.d.ts.map +1 -0
  270. package/node_modules/entities/dist/commonjs/decode.js +511 -0
  271. package/node_modules/entities/dist/commonjs/decode.js.map +1 -0
  272. package/node_modules/entities/dist/commonjs/encode.d.ts +22 -0
  273. package/node_modules/entities/dist/commonjs/encode.d.ts.map +1 -0
  274. package/node_modules/entities/dist/commonjs/encode.js +73 -0
  275. package/node_modules/entities/dist/commonjs/encode.js.map +1 -0
  276. package/node_modules/entities/dist/commonjs/escape.d.ts +43 -0
  277. package/node_modules/entities/dist/commonjs/escape.d.ts.map +1 -0
  278. package/node_modules/entities/dist/commonjs/escape.js +121 -0
  279. package/node_modules/entities/dist/commonjs/escape.js.map +1 -0
  280. package/node_modules/entities/dist/commonjs/generated/decode-data-html.d.ts +2 -0
  281. package/node_modules/entities/dist/commonjs/generated/decode-data-html.d.ts.map +1 -0
  282. package/node_modules/entities/dist/commonjs/generated/decode-data-html.js +10 -0
  283. package/node_modules/entities/dist/commonjs/generated/decode-data-html.js.map +1 -0
  284. package/node_modules/entities/dist/commonjs/generated/decode-data-xml.d.ts +2 -0
  285. package/node_modules/entities/dist/commonjs/generated/decode-data-xml.d.ts.map +1 -0
  286. package/node_modules/entities/dist/commonjs/generated/decode-data-xml.js +10 -0
  287. package/node_modules/entities/dist/commonjs/generated/decode-data-xml.js.map +1 -0
  288. package/node_modules/entities/dist/commonjs/generated/encode-html.d.ts +8 -0
  289. package/node_modules/entities/dist/commonjs/generated/encode-html.d.ts.map +1 -0
  290. package/node_modules/entities/dist/commonjs/generated/encode-html.js +13 -0
  291. package/node_modules/entities/dist/commonjs/generated/encode-html.js.map +1 -0
  292. package/node_modules/entities/dist/commonjs/index.d.ts +96 -0
  293. package/node_modules/entities/dist/commonjs/index.d.ts.map +1 -0
  294. package/node_modules/entities/dist/commonjs/index.js +131 -0
  295. package/node_modules/entities/dist/commonjs/index.js.map +1 -0
  296. package/node_modules/entities/dist/commonjs/package.json +3 -0
  297. package/node_modules/entities/dist/esm/decode-codepoint.d.ts +19 -0
  298. package/node_modules/entities/dist/esm/decode-codepoint.d.ts.map +1 -0
  299. package/node_modules/entities/dist/esm/decode-codepoint.js +72 -0
  300. package/node_modules/entities/dist/esm/decode-codepoint.js.map +1 -0
  301. package/node_modules/entities/dist/esm/decode.d.ts +209 -0
  302. package/node_modules/entities/dist/esm/decode.d.ts.map +1 -0
  303. package/node_modules/entities/dist/esm/decode.js +497 -0
  304. package/node_modules/entities/dist/esm/decode.js.map +1 -0
  305. package/node_modules/entities/dist/esm/encode.d.ts +22 -0
  306. package/node_modules/entities/dist/esm/encode.d.ts.map +1 -0
  307. package/node_modules/entities/dist/esm/encode.js +69 -0
  308. package/node_modules/entities/dist/esm/encode.js.map +1 -0
  309. package/node_modules/entities/dist/esm/escape.d.ts +43 -0
  310. package/node_modules/entities/dist/esm/escape.d.ts.map +1 -0
  311. package/node_modules/entities/dist/esm/escape.js +117 -0
  312. package/node_modules/entities/dist/esm/escape.js.map +1 -0
  313. package/node_modules/entities/dist/esm/generated/decode-data-html.d.ts +2 -0
  314. package/node_modules/entities/dist/esm/generated/decode-data-html.d.ts.map +1 -0
  315. package/node_modules/entities/dist/esm/generated/decode-data-html.js +7 -0
  316. package/node_modules/entities/dist/esm/generated/decode-data-html.js.map +1 -0
  317. package/node_modules/entities/dist/esm/generated/decode-data-xml.d.ts +2 -0
  318. package/node_modules/entities/dist/esm/generated/decode-data-xml.d.ts.map +1 -0
  319. package/node_modules/entities/dist/esm/generated/decode-data-xml.js +7 -0
  320. package/node_modules/entities/dist/esm/generated/decode-data-xml.js.map +1 -0
  321. package/node_modules/entities/dist/esm/generated/encode-html.d.ts +8 -0
  322. package/node_modules/entities/dist/esm/generated/encode-html.d.ts.map +1 -0
  323. package/node_modules/entities/dist/esm/generated/encode-html.js +10 -0
  324. package/node_modules/entities/dist/esm/generated/encode-html.js.map +1 -0
  325. package/node_modules/entities/dist/esm/index.d.ts +96 -0
  326. package/node_modules/entities/dist/esm/index.d.ts.map +1 -0
  327. package/node_modules/entities/dist/esm/index.js +107 -0
  328. package/node_modules/entities/dist/esm/index.js.map +1 -0
  329. package/node_modules/entities/dist/esm/package.json +3 -0
  330. package/node_modules/entities/escape.d.ts +1 -0
  331. package/node_modules/entities/escape.js +3 -0
  332. package/node_modules/entities/package.json +118 -0
  333. package/node_modules/entities/readme.md +122 -0
  334. package/node_modules/entities/src/decode-codepoint.ts +81 -0
  335. package/node_modules/entities/src/decode.spec.ts +320 -0
  336. package/node_modules/entities/src/decode.ts +620 -0
  337. package/node_modules/entities/src/encode.spec.ts +78 -0
  338. package/node_modules/entities/src/encode.ts +77 -0
  339. package/node_modules/entities/src/escape.spec.ts +14 -0
  340. package/node_modules/entities/src/escape.ts +148 -0
  341. package/node_modules/entities/src/generated/.eslintrc.json +10 -0
  342. package/node_modules/entities/src/generated/decode-data-html.ts +8 -0
  343. package/node_modules/entities/src/generated/decode-data-xml.ts +8 -0
  344. package/node_modules/entities/src/generated/encode-html.ts +17 -0
  345. package/node_modules/entities/src/index.spec.ts +125 -0
  346. package/node_modules/entities/src/index.ts +188 -0
  347. package/node_modules/marked/bin/main.js +1 -1
  348. package/node_modules/marked/lib/marked.d.ts +7 -0
  349. package/node_modules/marked/lib/marked.esm.js +14 -14
  350. package/node_modules/marked/lib/marked.esm.js.map +3 -3
  351. package/node_modules/marked/lib/marked.umd.js +19 -19
  352. package/node_modules/marked/lib/marked.umd.js.map +3 -3
  353. package/node_modules/marked/man/marked.1 +1 -1
  354. package/node_modules/marked/package.json +1 -1
  355. package/node_modules/parse5/LICENSE +19 -0
  356. package/node_modules/parse5/README.md +38 -0
  357. package/node_modules/parse5/dist/cjs/common/doctype.d.ts +4 -0
  358. package/node_modules/parse5/dist/cjs/common/doctype.js +118 -0
  359. package/node_modules/parse5/dist/cjs/common/error-codes.d.ts +67 -0
  360. package/node_modules/parse5/dist/cjs/common/error-codes.js +66 -0
  361. package/node_modules/parse5/dist/cjs/common/foreign-content.d.ts +9 -0
  362. package/node_modules/parse5/dist/cjs/common/foreign-content.js +237 -0
  363. package/node_modules/parse5/dist/cjs/common/html.d.ts +289 -0
  364. package/node_modules/parse5/dist/cjs/common/html.js +528 -0
  365. package/node_modules/parse5/dist/cjs/common/token.d.ts +84 -0
  366. package/node_modules/parse5/dist/cjs/common/token.js +24 -0
  367. package/node_modules/parse5/dist/cjs/common/unicode.d.ts +42 -0
  368. package/node_modules/parse5/dist/cjs/common/unicode.js +70 -0
  369. package/node_modules/parse5/dist/cjs/index.d.ts +71 -0
  370. package/node_modules/parse5/dist/cjs/index.js +54 -0
  371. package/node_modules/parse5/dist/cjs/package.json +1 -0
  372. package/node_modules/parse5/dist/cjs/parser/formatting-element-list.d.ts +36 -0
  373. package/node_modules/parse5/dist/cjs/parser/formatting-element-list.js +114 -0
  374. package/node_modules/parse5/dist/cjs/parser/index.d.ts +221 -0
  375. package/node_modules/parse5/dist/cjs/parser/index.js +3240 -0
  376. package/node_modules/parse5/dist/cjs/parser/open-element-stack.d.ts +53 -0
  377. package/node_modules/parse5/dist/cjs/parser/open-element-stack.js +328 -0
  378. package/node_modules/parse5/dist/cjs/serializer/index.d.ts +60 -0
  379. package/node_modules/parse5/dist/cjs/serializer/index.js +172 -0
  380. package/node_modules/parse5/dist/cjs/tokenizer/index.d.ts +247 -0
  381. package/node_modules/parse5/dist/cjs/tokenizer/index.js +2714 -0
  382. package/node_modules/parse5/dist/cjs/tokenizer/preprocessor.d.ts +36 -0
  383. package/node_modules/parse5/dist/cjs/tokenizer/preprocessor.js +200 -0
  384. package/node_modules/parse5/dist/cjs/tree-adapters/default.d.ts +84 -0
  385. package/node_modules/parse5/dist/cjs/tree-adapters/default.js +176 -0
  386. package/node_modules/parse5/dist/cjs/tree-adapters/interface.d.ts +255 -0
  387. package/node_modules/parse5/dist/cjs/tree-adapters/interface.js +2 -0
  388. package/node_modules/parse5/dist/common/doctype.d.ts +4 -0
  389. package/node_modules/parse5/dist/common/doctype.js +114 -0
  390. package/node_modules/parse5/dist/common/error-codes.d.ts +67 -0
  391. package/node_modules/parse5/dist/common/error-codes.js +63 -0
  392. package/node_modules/parse5/dist/common/foreign-content.d.ts +9 -0
  393. package/node_modules/parse5/dist/common/foreign-content.js +228 -0
  394. package/node_modules/parse5/dist/common/html.d.ts +289 -0
  395. package/node_modules/parse5/dist/common/html.js +523 -0
  396. package/node_modules/parse5/dist/common/token.d.ts +84 -0
  397. package/node_modules/parse5/dist/common/token.js +20 -0
  398. package/node_modules/parse5/dist/common/unicode.d.ts +42 -0
  399. package/node_modules/parse5/dist/common/unicode.js +62 -0
  400. package/node_modules/parse5/dist/index.d.ts +71 -0
  401. package/node_modules/parse5/dist/index.js +42 -0
  402. package/node_modules/parse5/dist/parser/formatting-element-list.d.ts +36 -0
  403. package/node_modules/parse5/dist/parser/formatting-element-list.js +110 -0
  404. package/node_modules/parse5/dist/parser/index.d.ts +221 -0
  405. package/node_modules/parse5/dist/parser/index.js +3245 -0
  406. package/node_modules/parse5/dist/parser/open-element-stack.d.ts +53 -0
  407. package/node_modules/parse5/dist/parser/open-element-stack.js +324 -0
  408. package/node_modules/parse5/dist/serializer/index.d.ts +60 -0
  409. package/node_modules/parse5/dist/serializer/index.js +168 -0
  410. package/node_modules/parse5/dist/tokenizer/index.d.ts +247 -0
  411. package/node_modules/parse5/dist/tokenizer/index.js +2710 -0
  412. package/node_modules/parse5/dist/tokenizer/preprocessor.d.ts +36 -0
  413. package/node_modules/parse5/dist/tokenizer/preprocessor.js +196 -0
  414. package/node_modules/parse5/dist/tree-adapters/default.d.ts +84 -0
  415. package/node_modules/parse5/dist/tree-adapters/default.js +173 -0
  416. package/node_modules/parse5/dist/tree-adapters/interface.d.ts +255 -0
  417. package/node_modules/parse5/dist/tree-adapters/interface.js +1 -0
  418. package/node_modules/parse5/package.json +50 -0
  419. package/package.json +2 -2
  420. package/packages/cli/dist/.tsbuildinfo +1 -1
  421. package/packages/cli/dist/access-cmd.d.ts +2 -1
  422. package/packages/cli/dist/access-cmd.d.ts.map +1 -1
  423. package/packages/cli/dist/access-cmd.js +40 -7
  424. package/packages/cli/dist/access-cmd.js.map +1 -1
  425. package/packages/cli/dist/args.d.ts +2 -1
  426. package/packages/cli/dist/args.d.ts.map +1 -1
  427. package/packages/cli/dist/args.js +7 -3
  428. package/packages/cli/dist/args.js.map +1 -1
  429. package/packages/cli/dist/commands.d.ts.map +1 -1
  430. package/packages/cli/dist/commands.js +3 -2
  431. package/packages/cli/dist/commands.js.map +1 -1
  432. package/packages/cli/dist/main.js +1 -1
  433. package/packages/cli/dist/main.js.map +1 -1
  434. package/packages/cli/dist/mcp/server.js +1 -1
  435. package/packages/cli/dist/mcp/server.js.map +1 -1
  436. package/packages/cli/dist/mcp/tools.d.ts.map +1 -1
  437. package/packages/cli/dist/mcp/tools.js +60 -0
  438. package/packages/cli/dist/mcp/tools.js.map +1 -1
  439. package/packages/core/dist/.tsbuildinfo +1 -1
  440. package/packages/core/dist/lock.d.ts +15 -1
  441. package/packages/core/dist/lock.d.ts.map +1 -1
  442. package/packages/core/dist/lock.js +15 -1
  443. package/packages/core/dist/lock.js.map +1 -1
  444. package/packages/core/dist/pages.d.ts +75 -0
  445. package/packages/core/dist/pages.d.ts.map +1 -1
  446. package/packages/core/dist/pages.js +14 -0
  447. package/packages/core/dist/pages.js.map +1 -1
  448. package/packages/core/dist/plugin/index.d.ts +2 -2
  449. package/packages/core/dist/plugin/index.d.ts.map +1 -1
  450. package/packages/core/dist/plugin/index.js.map +1 -1
  451. package/packages/core/dist/plugin/version.d.ts +1 -1
  452. package/packages/core/dist/plugin/version.js +1 -1
  453. package/packages/core/dist/provider-accounts.d.ts +32 -0
  454. package/packages/core/dist/provider-accounts.d.ts.map +1 -1
  455. package/packages/core/dist/provider-accounts.js +22 -0
  456. package/packages/core/dist/provider-accounts.js.map +1 -1
  457. package/packages/core/dist/tools.d.ts +6 -1
  458. package/packages/core/dist/tools.d.ts.map +1 -1
  459. package/packages/core/dist/tools.js.map +1 -1
  460. package/packages/core/migrations/077_lock_background_portrait.sql +5 -0
  461. package/packages/gateway/dist/.tsbuildinfo +1 -1
  462. package/packages/gateway/dist/agents/agent-intro.d.ts +31 -0
  463. package/packages/gateway/dist/agents/agent-intro.d.ts.map +1 -0
  464. package/packages/gateway/dist/agents/agent-intro.js +116 -0
  465. package/packages/gateway/dist/agents/agent-intro.js.map +1 -0
  466. package/packages/gateway/dist/agents/delegation.d.ts +10 -0
  467. package/packages/gateway/dist/agents/delegation.d.ts.map +1 -1
  468. package/packages/gateway/dist/agents/delegation.js +18 -1
  469. package/packages/gateway/dist/agents/delegation.js.map +1 -1
  470. package/packages/gateway/dist/agents/owner-tools.d.ts +21 -8
  471. package/packages/gateway/dist/agents/owner-tools.d.ts.map +1 -1
  472. package/packages/gateway/dist/agents/owner-tools.js +201 -36
  473. package/packages/gateway/dist/agents/owner-tools.js.map +1 -1
  474. package/packages/gateway/dist/agents/platform.d.ts +14 -1
  475. package/packages/gateway/dist/agents/platform.d.ts.map +1 -1
  476. package/packages/gateway/dist/agents/platform.js +44 -11
  477. package/packages/gateway/dist/agents/platform.js.map +1 -1
  478. package/packages/gateway/dist/bootstrap.d.ts.map +1 -1
  479. package/packages/gateway/dist/bootstrap.js +2 -0
  480. package/packages/gateway/dist/bootstrap.js.map +1 -1
  481. package/packages/gateway/dist/edition-origin.d.ts +57 -0
  482. package/packages/gateway/dist/edition-origin.d.ts.map +1 -0
  483. package/packages/gateway/dist/edition-origin.js +156 -0
  484. package/packages/gateway/dist/edition-origin.js.map +1 -0
  485. package/packages/gateway/dist/evals/golden.d.ts +5 -0
  486. package/packages/gateway/dist/evals/golden.d.ts.map +1 -1
  487. package/packages/gateway/dist/evals/golden.js +48 -0
  488. package/packages/gateway/dist/evals/golden.js.map +1 -1
  489. package/packages/gateway/dist/mcp/requests.d.ts +8 -2
  490. package/packages/gateway/dist/mcp/requests.d.ts.map +1 -1
  491. package/packages/gateway/dist/mcp/requests.js +74 -1
  492. package/packages/gateway/dist/mcp/requests.js.map +1 -1
  493. package/packages/gateway/dist/owner-profile-edit.d.ts +160 -0
  494. package/packages/gateway/dist/owner-profile-edit.d.ts.map +1 -0
  495. package/packages/gateway/dist/owner-profile-edit.js +296 -0
  496. package/packages/gateway/dist/owner-profile-edit.js.map +1 -0
  497. package/packages/gateway/dist/provider-accounts.d.ts.map +1 -1
  498. package/packages/gateway/dist/provider-accounts.js +2 -1
  499. package/packages/gateway/dist/provider-accounts.js.map +1 -1
  500. package/packages/gateway/dist/system-context.d.ts +9 -0
  501. package/packages/gateway/dist/system-context.d.ts.map +1 -1
  502. package/packages/gateway/dist/system-context.js +28 -2
  503. package/packages/gateway/dist/system-context.js.map +1 -1
  504. package/packages/gateway/dist/telegram/approvals.d.ts +6 -0
  505. package/packages/gateway/dist/telegram/approvals.d.ts.map +1 -1
  506. package/packages/gateway/dist/telegram/approvals.js +10 -2
  507. package/packages/gateway/dist/telegram/approvals.js.map +1 -1
  508. package/packages/gateway/dist/telegram/main.d.ts.map +1 -1
  509. package/packages/gateway/dist/telegram/main.js +10 -3
  510. package/packages/gateway/dist/telegram/main.js.map +1 -1
  511. package/packages/gateway/dist/telegram/outbound.d.ts +9 -0
  512. package/packages/gateway/dist/telegram/outbound.d.ts.map +1 -1
  513. package/packages/gateway/dist/telegram/outbound.js +43 -0
  514. package/packages/gateway/dist/telegram/outbound.js.map +1 -1
  515. package/packages/gateway/dist/telegram/surface.d.ts +2 -0
  516. package/packages/gateway/dist/telegram/surface.d.ts.map +1 -1
  517. package/packages/gateway/dist/telegram/surface.js +2 -1
  518. package/packages/gateway/dist/telegram/surface.js.map +1 -1
  519. package/packages/gateway/dist/tips/engine.d.ts +32 -0
  520. package/packages/gateway/dist/tips/engine.d.ts.map +1 -1
  521. package/packages/gateway/dist/tips/engine.js +69 -0
  522. package/packages/gateway/dist/tips/engine.js.map +1 -1
  523. package/packages/gateway/dist/tips/route.d.ts +1 -3
  524. package/packages/gateway/dist/tips/route.d.ts.map +1 -1
  525. package/packages/gateway/dist/tips/route.js +54 -30
  526. package/packages/gateway/dist/tips/route.js.map +1 -1
  527. package/packages/gateway/dist/web/access/cloudflare-connector.d.ts +63 -0
  528. package/packages/gateway/dist/web/access/cloudflare-connector.d.ts.map +1 -0
  529. package/packages/gateway/dist/web/access/cloudflare-connector.js +87 -0
  530. package/packages/gateway/dist/web/access/cloudflare-connector.js.map +1 -0
  531. package/packages/gateway/dist/web/access/cloudflare-setup.d.ts +39 -4
  532. package/packages/gateway/dist/web/access/cloudflare-setup.d.ts.map +1 -1
  533. package/packages/gateway/dist/web/access/cloudflare-setup.js +99 -11
  534. package/packages/gateway/dist/web/access/cloudflare-setup.js.map +1 -1
  535. package/packages/gateway/dist/web/access/cloudflare-token.js +1 -1
  536. package/packages/gateway/dist/web/access/cloudflare-token.js.map +1 -1
  537. package/packages/gateway/dist/web/access/index.d.ts +1 -0
  538. package/packages/gateway/dist/web/access/index.d.ts.map +1 -1
  539. package/packages/gateway/dist/web/access/index.js +1 -0
  540. package/packages/gateway/dist/web/access/index.js.map +1 -1
  541. package/packages/gateway/dist/web/agent-offers.d.ts +10 -1
  542. package/packages/gateway/dist/web/agent-offers.d.ts.map +1 -1
  543. package/packages/gateway/dist/web/agent-offers.js +14 -1
  544. package/packages/gateway/dist/web/agent-offers.js.map +1 -1
  545. package/packages/gateway/dist/web/api-routes.d.ts.map +1 -1
  546. package/packages/gateway/dist/web/api-routes.js +37 -8
  547. package/packages/gateway/dist/web/api-routes.js.map +1 -1
  548. package/packages/gateway/dist/web/approval-ask.d.ts +16 -0
  549. package/packages/gateway/dist/web/approval-ask.d.ts.map +1 -0
  550. package/packages/gateway/dist/web/approval-ask.js +51 -0
  551. package/packages/gateway/dist/web/approval-ask.js.map +1 -0
  552. package/packages/gateway/dist/web/chat.d.ts +6 -0
  553. package/packages/gateway/dist/web/chat.d.ts.map +1 -1
  554. package/packages/gateway/dist/web/chat.js +4 -0
  555. package/packages/gateway/dist/web/chat.js.map +1 -1
  556. package/packages/gateway/dist/web/live.d.ts +7 -0
  557. package/packages/gateway/dist/web/live.d.ts.map +1 -1
  558. package/packages/gateway/dist/web/live.js +12 -0
  559. package/packages/gateway/dist/web/live.js.map +1 -1
  560. package/packages/gateway/dist/web/lock-backgrounds.d.ts +9 -0
  561. package/packages/gateway/dist/web/lock-backgrounds.d.ts.map +1 -0
  562. package/packages/gateway/dist/web/lock-backgrounds.js +60 -0
  563. package/packages/gateway/dist/web/lock-backgrounds.js.map +1 -0
  564. package/packages/gateway/dist/web/lock.d.ts +13 -1
  565. package/packages/gateway/dist/web/lock.d.ts.map +1 -1
  566. package/packages/gateway/dist/web/lock.js +84 -23
  567. package/packages/gateway/dist/web/lock.js.map +1 -1
  568. package/packages/gateway/dist/web/places.d.ts +5 -0
  569. package/packages/gateway/dist/web/places.d.ts.map +1 -1
  570. package/packages/gateway/dist/web/places.js +11 -4
  571. package/packages/gateway/dist/web/places.js.map +1 -1
  572. package/packages/gateway/dist/web/server.d.ts +3 -0
  573. package/packages/gateway/dist/web/server.d.ts.map +1 -1
  574. package/packages/gateway/dist/web/server.js +63 -50
  575. package/packages/gateway/dist/web/server.js.map +1 -1
  576. package/packages/install/dist/.tsbuildinfo +1 -1
  577. package/packages/install/dist/cloudflared.d.ts +121 -0
  578. package/packages/install/dist/cloudflared.d.ts.map +1 -0
  579. package/packages/install/dist/cloudflared.js +451 -0
  580. package/packages/install/dist/cloudflared.js.map +1 -0
  581. package/packages/install/dist/index.d.ts +1 -0
  582. package/packages/install/dist/index.d.ts.map +1 -1
  583. package/packages/install/dist/index.js +1 -0
  584. package/packages/install/dist/index.js.map +1 -1
  585. package/packages/install/dist/supervisor.d.ts +6 -1
  586. package/packages/install/dist/supervisor.d.ts.map +1 -1
  587. package/packages/install/dist/supervisor.js +51 -5
  588. package/packages/install/dist/supervisor.js.map +1 -1
  589. package/packages/runtime/dist/.tsbuildinfo +1 -1
  590. package/packages/runtime/dist/codex-direct.d.ts +1 -1
  591. package/packages/runtime/dist/codex-direct.js +1 -1
  592. package/packages/runtime/dist/grounding.d.ts +54 -0
  593. package/packages/runtime/dist/grounding.d.ts.map +1 -0
  594. package/packages/runtime/dist/grounding.js +158 -0
  595. package/packages/runtime/dist/grounding.js.map +1 -0
  596. package/packages/runtime/dist/index.d.ts +1 -0
  597. package/packages/runtime/dist/index.d.ts.map +1 -1
  598. package/packages/runtime/dist/index.js +1 -0
  599. package/packages/runtime/dist/index.js.map +1 -1
  600. package/packages/runtime/dist/loop.d.ts +13 -0
  601. package/packages/runtime/dist/loop.d.ts.map +1 -1
  602. package/packages/runtime/dist/loop.js +98 -3
  603. package/packages/runtime/dist/loop.js.map +1 -1
  604. package/packages/tools/artifacts/dist/.tsbuildinfo +1 -1
  605. package/packages/tools/browser/dist/.tsbuildinfo +1 -1
  606. package/packages/tools/email/dist/.tsbuildinfo +1 -1
  607. package/packages/tools/email/dist/agent.d.ts +6 -1
  608. package/packages/tools/email/dist/agent.d.ts.map +1 -1
  609. package/packages/tools/email/dist/agent.js +6 -1
  610. package/packages/tools/email/dist/agent.js.map +1 -1
  611. package/packages/tools/email/dist/html.d.ts +16 -0
  612. package/packages/tools/email/dist/html.d.ts.map +1 -0
  613. package/packages/tools/email/dist/html.js +273 -0
  614. package/packages/tools/email/dist/html.js.map +1 -0
  615. package/packages/tools/email/dist/imap/fake.d.ts +8 -0
  616. package/packages/tools/email/dist/imap/fake.d.ts.map +1 -1
  617. package/packages/tools/email/dist/imap/fake.js +15 -0
  618. package/packages/tools/email/dist/imap/fake.js.map +1 -1
  619. package/packages/tools/email/dist/imap/imapflow-client.d.ts +7 -0
  620. package/packages/tools/email/dist/imap/imapflow-client.d.ts.map +1 -1
  621. package/packages/tools/email/dist/imap/imapflow-client.js +79 -17
  622. package/packages/tools/email/dist/imap/imapflow-client.js.map +1 -1
  623. package/packages/tools/email/dist/index.d.ts +5 -1
  624. package/packages/tools/email/dist/index.d.ts.map +1 -1
  625. package/packages/tools/email/dist/index.js +11 -3
  626. package/packages/tools/email/dist/index.js.map +1 -1
  627. package/packages/tools/email/dist/mail.d.ts.map +1 -1
  628. package/packages/tools/email/dist/mail.js +7 -0
  629. package/packages/tools/email/dist/mail.js.map +1 -1
  630. package/packages/tools/email/dist/pages/descriptors.d.ts.map +1 -1
  631. package/packages/tools/email/dist/pages/descriptors.js +208 -176
  632. package/packages/tools/email/dist/pages/descriptors.js.map +1 -1
  633. package/packages/tools/email/dist/pages/index.d.ts +3 -1
  634. package/packages/tools/email/dist/pages/index.d.ts.map +1 -1
  635. package/packages/tools/email/dist/pages/index.js +5 -2
  636. package/packages/tools/email/dist/pages/index.js.map +1 -1
  637. package/packages/tools/email/dist/pages/queries.d.ts +17 -3
  638. package/packages/tools/email/dist/pages/queries.d.ts.map +1 -1
  639. package/packages/tools/email/dist/pages/queries.js +283 -62
  640. package/packages/tools/email/dist/pages/queries.js.map +1 -1
  641. package/packages/tools/email/dist/pages/thread-tools.d.ts +25 -0
  642. package/packages/tools/email/dist/pages/thread-tools.d.ts.map +1 -0
  643. package/packages/tools/email/dist/pages/thread-tools.js +33 -0
  644. package/packages/tools/email/dist/pages/thread-tools.js.map +1 -0
  645. package/packages/tools/email/dist/ports.d.ts +25 -0
  646. package/packages/tools/email/dist/ports.d.ts.map +1 -1
  647. package/packages/tools/email/dist/ports.js.map +1 -1
  648. package/packages/tools/email/dist/retention.d.ts.map +1 -1
  649. package/packages/tools/email/dist/retention.js +1 -0
  650. package/packages/tools/email/dist/retention.js.map +1 -1
  651. package/packages/tools/email/dist/sources/inbox-poll.d.ts +9 -1
  652. package/packages/tools/email/dist/sources/inbox-poll.d.ts.map +1 -1
  653. package/packages/tools/email/dist/sources/inbox-poll.js +5 -2
  654. package/packages/tools/email/dist/sources/inbox-poll.js.map +1 -1
  655. package/packages/tools/email/dist/text-cleanup.d.ts +69 -0
  656. package/packages/tools/email/dist/text-cleanup.d.ts.map +1 -0
  657. package/packages/tools/email/dist/text-cleanup.js +96 -0
  658. package/packages/tools/email/dist/text-cleanup.js.map +1 -0
  659. package/packages/tools/email/dist/text.d.ts +29 -0
  660. package/packages/tools/email/dist/text.d.ts.map +1 -0
  661. package/packages/tools/email/dist/text.js +153 -0
  662. package/packages/tools/email/dist/text.js.map +1 -0
  663. package/packages/tools/email/dist/worker.d.ts +64 -0
  664. package/packages/tools/email/dist/worker.d.ts.map +1 -0
  665. package/packages/tools/email/dist/worker.js +123 -0
  666. package/packages/tools/email/dist/worker.js.map +1 -0
  667. package/packages/tools/email/migrations/028_reading.sql +23 -0
  668. package/packages/tools/email/package.json +1 -0
  669. package/packages/tools/host/dist/.tsbuildinfo +1 -1
  670. package/packages/tools/mcp/dist/.tsbuildinfo +1 -1
  671. package/packages/tools/memory/dist/.tsbuildinfo +1 -1
  672. package/packages/tools/web/dist/.tsbuildinfo +1 -1
  673. package/packages/web/dist/apple-touch-icon.png +0 -0
  674. package/packages/web/dist/assets/index-CPFSREcP.css +1 -0
  675. package/packages/web/dist/assets/index-DYUn1V0x.js +150 -0
  676. package/packages/web/dist/assets/{lottie_light-CHWAvOde.js → lottie_light-DxWeiVDC.js} +1 -1
  677. package/packages/web/dist/backgrounds/golden-streak-portrait.jpg +0 -0
  678. package/packages/web/dist/backgrounds/golden-streak-thumb.jpg +0 -0
  679. package/packages/web/dist/backgrounds/manifest.json +18 -0
  680. package/packages/web/dist/backgrounds/peoria-autumn-waterfront-thumb.jpg +0 -0
  681. package/packages/web/dist/backgrounds/peoria-autumn-waterfront.jpg +0 -0
  682. package/packages/web/dist/build.json +1 -1
  683. package/packages/web/dist/favicon-16.png +0 -0
  684. package/packages/web/dist/favicon-32.png +0 -0
  685. package/packages/web/dist/favicon.ico +0 -0
  686. package/packages/web/dist/icon-192.png +0 -0
  687. package/packages/web/dist/icon-512.png +0 -0
  688. package/packages/web/dist/index.html +6 -3
  689. package/packages/web/dist/manifest.webmanifest +1 -1
  690. package/packages/web/dist/maskable-512.png +0 -0
  691. package/packages/web/dist/precache.json +7 -5
  692. package/packages/web/dist/assets/index-BB52n8Fa.js +0 -146
  693. package/packages/web/dist/assets/index-CY4cPN4I.css +0 -1
  694. package/packages/web/dist/favicon.png +0 -0
  695. package/packages/web/dist/icon-maskable-512.png +0 -0
@@ -0,0 +1,150 @@
1
+ var $O=Object.defineProperty;var ik=e=>{throw TypeError(e)};var TO=(e,n,s)=>n in e?$O(e,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[n]=s;var lk=(e,n,s)=>TO(e,typeof n!="symbol"?n+"":n,s),ok=(e,n,s)=>n.has(e)||ik("Cannot "+s);var Bn=(e,n,s)=>(ok(e,n,"read from private field"),s?s.call(e):n.get(e)),ck=(e,n,s)=>n.has(e)?ik("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(e):n.set(e,s),qm=(e,n,s,r)=>(ok(e,n,"write to private field"),r?r.call(e,s):n.set(e,s),s);function IO(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 Qie=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function RO(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var m1={exports:{}},Tf={},p1={exports:{}},mt={};/**
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 Nd=Symbol.for("react.element"),PO=Symbol.for("react.portal"),MO=Symbol.for("react.fragment"),OO=Symbol.for("react.strict_mode"),DO=Symbol.for("react.profiler"),LO=Symbol.for("react.provider"),FO=Symbol.for("react.context"),_O=Symbol.for("react.forward_ref"),zO=Symbol.for("react.suspense"),UO=Symbol.for("react.memo"),BO=Symbol.for("react.lazy"),dk=Symbol.iterator;function WO(e){return e===null||typeof e!="object"?null:(e=dk&&e[dk]||e["@@iterator"],typeof e=="function"?e:null)}var g1={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},x1=Object.assign,v1={};function jo(e,n,s){this.props=e,this.context=n,this.refs=v1,this.updater=s||g1}jo.prototype.isReactComponent={};jo.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")};jo.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function j1(){}j1.prototype=jo.prototype;function Nj(e,n,s){this.props=e,this.context=n,this.refs=v1,this.updater=s||g1}var Sj=Nj.prototype=new j1;Sj.constructor=Nj;x1(Sj,jo.prototype);Sj.isPureReactComponent=!0;var uk=Array.isArray,w1=Object.prototype.hasOwnProperty,Cj={current:null},y1={key:!0,ref:!0,__self:!0,__source:!0};function b1(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)w1.call(n,r)&&!y1.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),d=0;d<o;d++)c[d]=arguments[d+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:Nd,type:e,key:i,ref:l,props:a,_owner:Cj.current}}function HO(e,n){return{$$typeof:Nd,type:e.type,key:n,ref:e.ref,props:e.props,_owner:e._owner}}function Ej(e){return typeof e=="object"&&e!==null&&e.$$typeof===Nd}function KO(e){var n={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(s){return n[s]})}var hk=/\/+/g;function Ym(e,n){return typeof e=="object"&&e!==null&&e.key!=null?KO(""+e.key):n.toString(36)}function Wu(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 Nd:case PO:l=!0}}if(l)return l=e,a=a(l),e=r===""?"."+Ym(l,0):r,uk(a)?(s="",e!=null&&(s=e.replace(hk,"$&/")+"/"),Wu(a,n,s,"",function(d){return d})):a!=null&&(Ej(a)&&(a=HO(a,s+(!a.key||l&&l.key===a.key?"":(""+a.key).replace(hk,"$&/")+"/")+e)),n.push(a)),1;if(l=0,r=r===""?".":r+":",uk(e))for(var o=0;o<e.length;o++){i=e[o];var c=r+Ym(i,o);l+=Wu(i,n,s,c,a)}else if(c=WO(e),typeof c=="function")for(e=c.call(e),o=0;!(i=e.next()).done;)i=i.value,c=r+Ym(i,o++),l+=Wu(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 Zd(e,n,s){if(e==null)return e;var r=[],a=0;return Wu(e,r,"","",function(i){return n.call(s,i,a++)}),r}function VO(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 is={current:null},Hu={transition:null},GO={ReactCurrentDispatcher:is,ReactCurrentBatchConfig:Hu,ReactCurrentOwner:Cj};function k1(){throw Error("act(...) is not supported in production builds of React.")}mt.Children={map:Zd,forEach:function(e,n,s){Zd(e,function(){n.apply(this,arguments)},s)},count:function(e){var n=0;return Zd(e,function(){n++}),n},toArray:function(e){return Zd(e,function(n){return n})||[]},only:function(e){if(!Ej(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};mt.Component=jo;mt.Fragment=MO;mt.Profiler=DO;mt.PureComponent=Nj;mt.StrictMode=OO;mt.Suspense=zO;mt.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=GO;mt.act=k1;mt.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=x1({},e.props),a=e.key,i=e.ref,l=e._owner;if(n!=null){if(n.ref!==void 0&&(i=n.ref,l=Cj.current),n.key!==void 0&&(a=""+n.key),e.type&&e.type.defaultProps)var o=e.type.defaultProps;for(c in n)w1.call(n,c)&&!y1.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 d=0;d<c;d++)o[d]=arguments[d+2];r.children=o}return{$$typeof:Nd,type:e.type,key:a,ref:i,props:r,_owner:l}};mt.createContext=function(e){return e={$$typeof:FO,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:LO,_context:e},e.Consumer=e};mt.createElement=b1;mt.createFactory=function(e){var n=b1.bind(null,e);return n.type=e,n};mt.createRef=function(){return{current:null}};mt.forwardRef=function(e){return{$$typeof:_O,render:e}};mt.isValidElement=Ej;mt.lazy=function(e){return{$$typeof:BO,_payload:{_status:-1,_result:e},_init:VO}};mt.memo=function(e,n){return{$$typeof:UO,type:e,compare:n===void 0?null:n}};mt.startTransition=function(e){var n=Hu.transition;Hu.transition={};try{e()}finally{Hu.transition=n}};mt.unstable_act=k1;mt.useCallback=function(e,n){return is.current.useCallback(e,n)};mt.useContext=function(e){return is.current.useContext(e)};mt.useDebugValue=function(){};mt.useDeferredValue=function(e){return is.current.useDeferredValue(e)};mt.useEffect=function(e,n){return is.current.useEffect(e,n)};mt.useId=function(){return is.current.useId()};mt.useImperativeHandle=function(e,n,s){return is.current.useImperativeHandle(e,n,s)};mt.useInsertionEffect=function(e,n){return is.current.useInsertionEffect(e,n)};mt.useLayoutEffect=function(e,n){return is.current.useLayoutEffect(e,n)};mt.useMemo=function(e,n){return is.current.useMemo(e,n)};mt.useReducer=function(e,n,s){return is.current.useReducer(e,n,s)};mt.useRef=function(e){return is.current.useRef(e)};mt.useState=function(e){return is.current.useState(e)};mt.useSyncExternalStore=function(e,n,s){return is.current.useSyncExternalStore(e,n,s)};mt.useTransition=function(){return is.current.useTransition()};mt.version="18.3.1";p1.exports=mt;var u=p1.exports;const qO=RO(u),wo=IO({__proto__:null,default:qO},[u]);/**
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 YO=u,QO=Symbol.for("react.element"),JO=Symbol.for("react.fragment"),XO=Object.prototype.hasOwnProperty,ZO=YO.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,eD={key:!0,ref:!0,__self:!0,__source:!0};function N1(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)XO.call(n,r)&&!eD.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:QO,type:e,key:i,ref:l,props:a,_owner:ZO.current}}Tf.Fragment=JO;Tf.jsx=N1;Tf.jsxs=N1;m1.exports=Tf;var t=m1.exports,S1={exports:{}},Rs={},C1={exports:{}},E1={};/**
18
+ * @license React
19
+ * scheduler.production.min.js
20
+ *
21
+ * Copyright (c) Facebook, Inc. and its affiliates.
22
+ *
23
+ * This source code is licensed under the MIT license found in the
24
+ * LICENSE file in the root directory of this source tree.
25
+ */(function(e){function n(P,W){var L=P.length;P.push(W);e:for(;0<L;){var Q=L-1>>>1,F=P[Q];if(0<a(F,W))P[Q]=W,P[L]=F,L=Q;else break e}}function s(P){return P.length===0?null:P[0]}function r(P){if(P.length===0)return null;var W=P[0],L=P.pop();if(L!==W){P[0]=L;e:for(var Q=0,F=P.length,ae=F>>>1;Q<ae;){var V=2*(Q+1)-1,J=P[V],H=V+1,X=P[H];if(0>a(J,L))H<F&&0>a(X,J)?(P[Q]=X,P[H]=L,Q=H):(P[Q]=J,P[V]=L,Q=V);else if(H<F&&0>a(X,L))P[Q]=X,P[H]=L,Q=H;else break e}}return W}function a(P,W){var L=P.sortIndex-W.sortIndex;return L!==0?L:P.id-W.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=[],d=[],h=1,f=null,m=3,p=!1,x=!1,g=!1,y=typeof setTimeout=="function"?setTimeout:null,j=typeof clearTimeout=="function"?clearTimeout:null,v=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(P){for(var W=s(d);W!==null;){if(W.callback===null)r(d);else if(W.startTime<=P)r(d),W.sortIndex=W.expirationTime,n(c,W);else break;W=s(d)}}function N(P){if(g=!1,w(P),!x)if(s(c)!==null)x=!0,z(k);else{var W=s(d);W!==null&&U(N,W.startTime-P)}}function k(P,W){x=!1,g&&(g=!1,j(C),C=-1),p=!0;var L=m;try{for(w(W),f=s(c);f!==null&&(!(f.expirationTime>W)||P&&!I());){var Q=f.callback;if(typeof Q=="function"){f.callback=null,m=f.priorityLevel;var F=Q(f.expirationTime<=W);W=e.unstable_now(),typeof F=="function"?f.callback=F:f===s(c)&&r(c),w(W)}else r(c);f=s(c)}if(f!==null)var ae=!0;else{var V=s(d);V!==null&&U(N,V.startTime-W),ae=!1}return ae}finally{f=null,m=L,p=!1}}var S=!1,b=null,C=-1,$=5,A=-1;function I(){return!(e.unstable_now()-A<$)}function M(){if(b!==null){var P=e.unstable_now();A=P;var W=!0;try{W=b(!0,P)}finally{W?O():(S=!1,b=null)}}else S=!1}var O;if(typeof v=="function")O=function(){v(M)};else if(typeof MessageChannel<"u"){var R=new MessageChannel,_=R.port2;R.port1.onmessage=M,O=function(){_.postMessage(null)}}else O=function(){y(M,0)};function z(P){b=P,S||(S=!0,O())}function U(P,W){C=y(function(){P(e.unstable_now())},W)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(P){P.callback=null},e.unstable_continueExecution=function(){x||p||(x=!0,z(k))},e.unstable_forceFrameRate=function(P){0>P||125<P?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):$=0<P?Math.floor(1e3/P):5},e.unstable_getCurrentPriorityLevel=function(){return m},e.unstable_getFirstCallbackNode=function(){return s(c)},e.unstable_next=function(P){switch(m){case 1:case 2:case 3:var W=3;break;default:W=m}var L=m;m=W;try{return P()}finally{m=L}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(P,W){switch(P){case 1:case 2:case 3:case 4:case 5:break;default:P=3}var L=m;m=P;try{return W()}finally{m=L}},e.unstable_scheduleCallback=function(P,W,L){var Q=e.unstable_now();switch(typeof L=="object"&&L!==null?(L=L.delay,L=typeof L=="number"&&0<L?Q+L:Q):L=Q,P){case 1:var F=-1;break;case 2:F=250;break;case 5:F=1073741823;break;case 4:F=1e4;break;default:F=5e3}return F=L+F,P={id:h++,callback:W,priorityLevel:P,startTime:L,expirationTime:F,sortIndex:-1},L>Q?(P.sortIndex=L,n(d,P),s(c)===null&&P===s(d)&&(g?(j(C),C=-1):g=!0,U(N,L-Q))):(P.sortIndex=F,n(c,P),x||p||(x=!0,z(k))),P},e.unstable_shouldYield=I,e.unstable_wrapCallback=function(P){var W=m;return function(){var L=m;m=W;try{return P.apply(this,arguments)}finally{m=L}}}})(E1);C1.exports=E1;var tD=C1.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 nD=u,$s=tD;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 A1=new Set,Mc={};function tl(e,n){Jl(e,n),Jl(e+"Capture",n)}function Jl(e,n){for(Mc[e]=n,e=0;e<n.length;e++)A1.add(n[e])}var pa=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Rg=Object.prototype.hasOwnProperty,sD=/^[: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]*$/,fk={},mk={};function rD(e){return Rg.call(mk,e)?!0:Rg.call(fk,e)?!1:sD.test(e)?mk[e]=!0:(fk[e]=!0,!1)}function aD(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 iD(e,n,s,r){if(n===null||typeof n>"u"||aD(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 ls(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 zn={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){zn[e]=new ls(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var n=e[0];zn[n]=new ls(n,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){zn[e]=new ls(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){zn[e]=new ls(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){zn[e]=new ls(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){zn[e]=new ls(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){zn[e]=new ls(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){zn[e]=new ls(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){zn[e]=new ls(e,5,!1,e.toLowerCase(),null,!1,!1)});var Aj=/[\-:]([a-z])/g;function $j(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(Aj,$j);zn[n]=new ls(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(Aj,$j);zn[n]=new ls(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(Aj,$j);zn[n]=new ls(n,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){zn[e]=new ls(e,1,!1,e.toLowerCase(),null,!1,!1)});zn.xlinkHref=new ls("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){zn[e]=new ls(e,1,!1,e.toLowerCase(),null,!0,!0)});function Tj(e,n,s,r){var a=zn.hasOwnProperty(n)?zn[n]:null;(a!==null?a.type!==0:r||!(2<n.length)||n[0]!=="o"&&n[0]!=="O"||n[1]!=="n"&&n[1]!=="N")&&(iD(n,s,a,r)&&(s=null),r||a===null?rD(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 ba=nD.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,eu=Symbol.for("react.element"),Nl=Symbol.for("react.portal"),Sl=Symbol.for("react.fragment"),Ij=Symbol.for("react.strict_mode"),Pg=Symbol.for("react.profiler"),$1=Symbol.for("react.provider"),T1=Symbol.for("react.context"),Rj=Symbol.for("react.forward_ref"),Mg=Symbol.for("react.suspense"),Og=Symbol.for("react.suspense_list"),Pj=Symbol.for("react.memo"),Pa=Symbol.for("react.lazy"),I1=Symbol.for("react.offscreen"),pk=Symbol.iterator;function Bo(e){return e===null||typeof e!="object"?null:(e=pk&&e[pk]||e["@@iterator"],typeof e=="function"?e:null)}var Xt=Object.assign,Qm;function rc(e){if(Qm===void 0)try{throw Error()}catch(s){var n=s.stack.trim().match(/\n( *(at )?)/);Qm=n&&n[1]||""}return`
34
+ `+Qm+e}var Jm=!1;function Xm(e,n){if(!e||Jm)return"";Jm=!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(d){var r=d}Reflect.construct(e,[],n)}else{try{n.call()}catch(d){r=d}e.call(n.prototype)}else{try{throw Error()}catch(d){r=d}e()}}catch(d){if(d&&r&&typeof d.stack=="string"){for(var a=d.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{Jm=!1,Error.prepareStackTrace=s}return(e=e?e.displayName||e.name:"")?rc(e):""}function lD(e){switch(e.tag){case 5:return rc(e.type);case 16:return rc("Lazy");case 13:return rc("Suspense");case 19:return rc("SuspenseList");case 0:case 2:case 15:return e=Xm(e.type,!1),e;case 11:return e=Xm(e.type.render,!1),e;case 1:return e=Xm(e.type,!0),e;default:return""}}function Dg(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 Sl:return"Fragment";case Nl:return"Portal";case Pg:return"Profiler";case Ij:return"StrictMode";case Mg:return"Suspense";case Og:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case T1:return(e.displayName||"Context")+".Consumer";case $1:return(e._context.displayName||"Context")+".Provider";case Rj:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Pj:return n=e.displayName||null,n!==null?n:Dg(e.type)||"Memo";case Pa:n=e._payload,e=e._init;try{return Dg(e(n))}catch{}}return null}function oD(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 Dg(n);case 8:return n===Ij?"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 R1(e){var n=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(n==="checkbox"||n==="radio")}function cD(e){var n=R1(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 tu(e){e._valueTracker||(e._valueTracker=cD(e))}function P1(e){if(!e)return!1;var n=e._valueTracker;if(!n)return!0;var s=n.getValue(),r="";return e&&(r=R1(e)?e.checked?"true":"false":e.value),e=r,e!==s?(n.setValue(e),!0):!1}function xh(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 Lg(e,n){var s=n.checked;return Xt({},n,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:s??e._wrapperState.initialChecked})}function gk(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 M1(e,n){n=n.checked,n!=null&&Tj(e,"checked",n,!1)}function Fg(e,n){M1(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")?_g(e,n.type,s):n.hasOwnProperty("defaultValue")&&_g(e,n.type,Za(n.defaultValue)),n.checked==null&&n.defaultChecked!=null&&(e.defaultChecked=!!n.defaultChecked)}function xk(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 _g(e,n,s){(n!=="number"||xh(e.ownerDocument)!==e)&&(s==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+s&&(e.defaultValue=""+s))}var ac=Array.isArray;function _l(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 zg(e,n){if(n.dangerouslySetInnerHTML!=null)throw Error(Ne(91));return Xt({},n,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function vk(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(ac(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 O1(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 jk(e){var n=e.textContent;n===e._wrapperState.initialValue&&n!==""&&n!==null&&(e.value=n)}function D1(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 Ug(e,n){return e==null||e==="http://www.w3.org/1999/xhtml"?D1(n):e==="http://www.w3.org/2000/svg"&&n==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var nu,L1=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(nu=nu||document.createElement("div"),nu.innerHTML="<svg>"+n.valueOf().toString()+"</svg>",n=nu.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;n.firstChild;)e.appendChild(n.firstChild)}});function Oc(e,n){if(n){var s=e.firstChild;if(s&&s===e.lastChild&&s.nodeType===3){s.nodeValue=n;return}}e.textContent=n}var mc={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},dD=["Webkit","ms","Moz","O"];Object.keys(mc).forEach(function(e){dD.forEach(function(n){n=n+e.charAt(0).toUpperCase()+e.substring(1),mc[n]=mc[e]})});function F1(e,n,s){return n==null||typeof n=="boolean"||n===""?"":s||typeof n!="number"||n===0||mc.hasOwnProperty(e)&&mc[e]?(""+n).trim():n+"px"}function _1(e,n){e=e.style;for(var s in n)if(n.hasOwnProperty(s)){var r=s.indexOf("--")===0,a=F1(s,n[s],r);s==="float"&&(s="cssFloat"),r?e.setProperty(s,a):e[s]=a}}var uD=Xt({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 Bg(e,n){if(n){if(uD[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 Wg(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 Hg=null;function Mj(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Kg=null,zl=null,Ul=null;function wk(e){if(e=Ed(e)){if(typeof Kg!="function")throw Error(Ne(280));var n=e.stateNode;n&&(n=Of(n),Kg(e.stateNode,e.type,n))}}function z1(e){zl?Ul?Ul.push(e):Ul=[e]:zl=e}function U1(){if(zl){var e=zl,n=Ul;if(Ul=zl=null,wk(e),n)for(e=0;e<n.length;e++)wk(n[e])}}function B1(e,n){return e(n)}function W1(){}var Zm=!1;function H1(e,n,s){if(Zm)return e(n,s);Zm=!0;try{return B1(e,n,s)}finally{Zm=!1,(zl!==null||Ul!==null)&&(W1(),U1())}}function Dc(e,n){var s=e.stateNode;if(s===null)return null;var r=Of(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 Vg=!1;if(pa)try{var Wo={};Object.defineProperty(Wo,"passive",{get:function(){Vg=!0}}),window.addEventListener("test",Wo,Wo),window.removeEventListener("test",Wo,Wo)}catch{Vg=!1}function hD(e,n,s,r,a,i,l,o,c){var d=Array.prototype.slice.call(arguments,3);try{n.apply(s,d)}catch(h){this.onError(h)}}var pc=!1,vh=null,jh=!1,Gg=null,fD={onError:function(e){pc=!0,vh=e}};function mD(e,n,s,r,a,i,l,o,c){pc=!1,vh=null,hD.apply(fD,arguments)}function pD(e,n,s,r,a,i,l,o,c){if(mD.apply(this,arguments),pc){if(pc){var d=vh;pc=!1,vh=null}else throw Error(Ne(198));jh||(jh=!0,Gg=d)}}function nl(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 K1(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 yk(e){if(nl(e)!==e)throw Error(Ne(188))}function gD(e){var n=e.alternate;if(!n){if(n=nl(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 yk(a),e;if(i===r)return yk(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 V1(e){return e=gD(e),e!==null?G1(e):null}function G1(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var n=G1(e);if(n!==null)return n;e=e.sibling}return null}var q1=$s.unstable_scheduleCallback,bk=$s.unstable_cancelCallback,xD=$s.unstable_shouldYield,vD=$s.unstable_requestPaint,rn=$s.unstable_now,jD=$s.unstable_getCurrentPriorityLevel,Oj=$s.unstable_ImmediatePriority,Y1=$s.unstable_UserBlockingPriority,wh=$s.unstable_NormalPriority,wD=$s.unstable_LowPriority,Q1=$s.unstable_IdlePriority,If=null,Fr=null;function yD(e){if(Fr&&typeof Fr.onCommitFiberRoot=="function")try{Fr.onCommitFiberRoot(If,e,void 0,(e.current.flags&128)===128)}catch{}}var cr=Math.clz32?Math.clz32:ND,bD=Math.log,kD=Math.LN2;function ND(e){return e>>>=0,e===0?32:31-(bD(e)/kD|0)|0}var su=64,ru=4194304;function ic(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 yh(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=ic(o):(i&=l,i!==0&&(r=ic(i)))}else l=s&~a,l!==0?r=ic(l):i!==0&&(r=ic(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-cr(n),a=1<<s,r|=e[s],n&=~a;return r}function SD(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 CD(e,n){for(var s=e.suspendedLanes,r=e.pingedLanes,a=e.expirationTimes,i=e.pendingLanes;0<i;){var l=31-cr(i),o=1<<l,c=a[l];c===-1?(!(o&s)||o&r)&&(a[l]=SD(o,n)):c<=n&&(e.expiredLanes|=o),i&=~o}}function qg(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function J1(){var e=su;return su<<=1,!(su&4194240)&&(su=64),e}function ep(e){for(var n=[],s=0;31>s;s++)n.push(e);return n}function Sd(e,n,s){e.pendingLanes|=n,n!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,n=31-cr(n),e[n]=s}function ED(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-cr(s),i=1<<a;n[a]=0,r[a]=-1,e[a]=-1,s&=~i}}function Dj(e,n){var s=e.entangledLanes|=n;for(e=e.entanglements;s;){var r=31-cr(s),a=1<<r;a&n|e[r]&n&&(e[r]|=n),s&=~a}}var Nt=0;function X1(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var Z1,Lj,eE,tE,nE,Yg=!1,au=[],Ba=null,Wa=null,Ha=null,Lc=new Map,Fc=new Map,Oa=[],AD="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 kk(e,n){switch(e){case"focusin":case"focusout":Ba=null;break;case"dragenter":case"dragleave":Wa=null;break;case"mouseover":case"mouseout":Ha=null;break;case"pointerover":case"pointerout":Lc.delete(n.pointerId);break;case"gotpointercapture":case"lostpointercapture":Fc.delete(n.pointerId)}}function Ho(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=Ed(n),n!==null&&Lj(n)),e):(e.eventSystemFlags|=r,n=e.targetContainers,a!==null&&n.indexOf(a)===-1&&n.push(a),e)}function $D(e,n,s,r,a){switch(n){case"focusin":return Ba=Ho(Ba,e,n,s,r,a),!0;case"dragenter":return Wa=Ho(Wa,e,n,s,r,a),!0;case"mouseover":return Ha=Ho(Ha,e,n,s,r,a),!0;case"pointerover":var i=a.pointerId;return Lc.set(i,Ho(Lc.get(i)||null,e,n,s,r,a)),!0;case"gotpointercapture":return i=a.pointerId,Fc.set(i,Ho(Fc.get(i)||null,e,n,s,r,a)),!0}return!1}function sE(e){var n=Ii(e.target);if(n!==null){var s=nl(n);if(s!==null){if(n=s.tag,n===13){if(n=K1(s),n!==null){e.blockedOn=n,nE(e.priority,function(){eE(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 Ku(e){if(e.blockedOn!==null)return!1;for(var n=e.targetContainers;0<n.length;){var s=Qg(e.domEventName,e.eventSystemFlags,n[0],e.nativeEvent);if(s===null){s=e.nativeEvent;var r=new s.constructor(s.type,s);Hg=r,s.target.dispatchEvent(r),Hg=null}else return n=Ed(s),n!==null&&Lj(n),e.blockedOn=s,!1;n.shift()}return!0}function Nk(e,n,s){Ku(e)&&s.delete(n)}function TD(){Yg=!1,Ba!==null&&Ku(Ba)&&(Ba=null),Wa!==null&&Ku(Wa)&&(Wa=null),Ha!==null&&Ku(Ha)&&(Ha=null),Lc.forEach(Nk),Fc.forEach(Nk)}function Ko(e,n){e.blockedOn===n&&(e.blockedOn=null,Yg||(Yg=!0,$s.unstable_scheduleCallback($s.unstable_NormalPriority,TD)))}function _c(e){function n(a){return Ko(a,e)}if(0<au.length){Ko(au[0],e);for(var s=1;s<au.length;s++){var r=au[s];r.blockedOn===e&&(r.blockedOn=null)}}for(Ba!==null&&Ko(Ba,e),Wa!==null&&Ko(Wa,e),Ha!==null&&Ko(Ha,e),Lc.forEach(n),Fc.forEach(n),s=0;s<Oa.length;s++)r=Oa[s],r.blockedOn===e&&(r.blockedOn=null);for(;0<Oa.length&&(s=Oa[0],s.blockedOn===null);)sE(s),s.blockedOn===null&&Oa.shift()}var Bl=ba.ReactCurrentBatchConfig,bh=!0;function ID(e,n,s,r){var a=Nt,i=Bl.transition;Bl.transition=null;try{Nt=1,Fj(e,n,s,r)}finally{Nt=a,Bl.transition=i}}function RD(e,n,s,r){var a=Nt,i=Bl.transition;Bl.transition=null;try{Nt=4,Fj(e,n,s,r)}finally{Nt=a,Bl.transition=i}}function Fj(e,n,s,r){if(bh){var a=Qg(e,n,s,r);if(a===null)dp(e,n,r,kh,s),kk(e,r);else if($D(a,e,n,s,r))r.stopPropagation();else if(kk(e,r),n&4&&-1<AD.indexOf(e)){for(;a!==null;){var i=Ed(a);if(i!==null&&Z1(i),i=Qg(e,n,s,r),i===null&&dp(e,n,r,kh,s),i===a)break;a=i}a!==null&&r.stopPropagation()}else dp(e,n,r,null,s)}}var kh=null;function Qg(e,n,s,r){if(kh=null,e=Mj(r),e=Ii(e),e!==null)if(n=nl(e),n===null)e=null;else if(s=n.tag,s===13){if(e=K1(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 kh=e,null}function rE(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(jD()){case Oj:return 1;case Y1:return 4;case wh:case wD:return 16;case Q1:return 536870912;default:return 16}default:return 16}}var Fa=null,_j=null,Vu=null;function aE(){if(Vu)return Vu;var e,n=_j,s=n.length,r,a="value"in Fa?Fa.value:Fa.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 Vu=a.slice(e,1<r?1-r:void 0)}function Gu(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 iu(){return!0}function Sk(){return!1}function Ps(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)?iu:Sk,this.isPropagationStopped=Sk,this}return Xt(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=iu)},stopPropagation:function(){var s=this.nativeEvent;s&&(s.stopPropagation?s.stopPropagation():typeof s.cancelBubble!="unknown"&&(s.cancelBubble=!0),this.isPropagationStopped=iu)},persist:function(){},isPersistent:iu}),n}var yo={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},zj=Ps(yo),Cd=Xt({},yo,{view:0,detail:0}),PD=Ps(Cd),tp,np,Vo,Rf=Xt({},Cd,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:Uj,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!==Vo&&(Vo&&e.type==="mousemove"?(tp=e.screenX-Vo.screenX,np=e.screenY-Vo.screenY):np=tp=0,Vo=e),tp)},movementY:function(e){return"movementY"in e?e.movementY:np}}),Ck=Ps(Rf),MD=Xt({},Rf,{dataTransfer:0}),OD=Ps(MD),DD=Xt({},Cd,{relatedTarget:0}),sp=Ps(DD),LD=Xt({},yo,{animationName:0,elapsedTime:0,pseudoElement:0}),FD=Ps(LD),_D=Xt({},yo,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),zD=Ps(_D),UD=Xt({},yo,{data:0}),Ek=Ps(UD),BD={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},WD={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"},HD={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function KD(e){var n=this.nativeEvent;return n.getModifierState?n.getModifierState(e):(e=HD[e])?!!n[e]:!1}function Uj(){return KD}var VD=Xt({},Cd,{key:function(e){if(e.key){var n=BD[e.key]||e.key;if(n!=="Unidentified")return n}return e.type==="keypress"?(e=Gu(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?WD[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:Uj,charCode:function(e){return e.type==="keypress"?Gu(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?Gu(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),GD=Ps(VD),qD=Xt({},Rf,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),Ak=Ps(qD),YD=Xt({},Cd,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:Uj}),QD=Ps(YD),JD=Xt({},yo,{propertyName:0,elapsedTime:0,pseudoElement:0}),XD=Ps(JD),ZD=Xt({},Rf,{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}),eL=Ps(ZD),tL=[9,13,27,32],Bj=pa&&"CompositionEvent"in window,gc=null;pa&&"documentMode"in document&&(gc=document.documentMode);var nL=pa&&"TextEvent"in window&&!gc,iE=pa&&(!Bj||gc&&8<gc&&11>=gc),$k=" ",Tk=!1;function lE(e,n){switch(e){case"keyup":return tL.indexOf(n.keyCode)!==-1;case"keydown":return n.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function oE(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Cl=!1;function sL(e,n){switch(e){case"compositionend":return oE(n);case"keypress":return n.which!==32?null:(Tk=!0,$k);case"textInput":return e=n.data,e===$k&&Tk?null:e;default:return null}}function rL(e,n){if(Cl)return e==="compositionend"||!Bj&&lE(e,n)?(e=aE(),Vu=_j=Fa=null,Cl=!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 iE&&n.locale!=="ko"?null:n.data;default:return null}}var aL={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 Ik(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n==="input"?!!aL[e.type]:n==="textarea"}function cE(e,n,s,r){z1(r),n=Nh(n,"onChange"),0<n.length&&(s=new zj("onChange","change",null,s,r),e.push({event:s,listeners:n}))}var xc=null,zc=null;function iL(e){wE(e,0)}function Pf(e){var n=$l(e);if(P1(n))return e}function lL(e,n){if(e==="change")return n}var dE=!1;if(pa){var rp;if(pa){var ap="oninput"in document;if(!ap){var Rk=document.createElement("div");Rk.setAttribute("oninput","return;"),ap=typeof Rk.oninput=="function"}rp=ap}else rp=!1;dE=rp&&(!document.documentMode||9<document.documentMode)}function Pk(){xc&&(xc.detachEvent("onpropertychange",uE),zc=xc=null)}function uE(e){if(e.propertyName==="value"&&Pf(zc)){var n=[];cE(n,zc,e,Mj(e)),H1(iL,n)}}function oL(e,n,s){e==="focusin"?(Pk(),xc=n,zc=s,xc.attachEvent("onpropertychange",uE)):e==="focusout"&&Pk()}function cL(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return Pf(zc)}function dL(e,n){if(e==="click")return Pf(n)}function uL(e,n){if(e==="input"||e==="change")return Pf(n)}function hL(e,n){return e===n&&(e!==0||1/e===1/n)||e!==e&&n!==n}var fr=typeof Object.is=="function"?Object.is:hL;function Uc(e,n){if(fr(e,n))return!0;if(typeof e!="object"||e===null||typeof n!="object"||n===null)return!1;var s=Object.keys(e),r=Object.keys(n);if(s.length!==r.length)return!1;for(r=0;r<s.length;r++){var a=s[r];if(!Rg.call(n,a)||!fr(e[a],n[a]))return!1}return!0}function Mk(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function Ok(e,n){var s=Mk(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=Mk(s)}}function hE(e,n){return e&&n?e===n?!0:e&&e.nodeType===3?!1:n&&n.nodeType===3?hE(e,n.parentNode):"contains"in e?e.contains(n):e.compareDocumentPosition?!!(e.compareDocumentPosition(n)&16):!1:!1}function fE(){for(var e=window,n=xh();n instanceof e.HTMLIFrameElement;){try{var s=typeof n.contentWindow.location.href=="string"}catch{s=!1}if(s)e=n.contentWindow;else break;n=xh(e.document)}return n}function Wj(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 fL(e){var n=fE(),s=e.focusedElem,r=e.selectionRange;if(n!==s&&s&&s.ownerDocument&&hE(s.ownerDocument.documentElement,s)){if(r!==null&&Wj(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=Ok(s,i);var l=Ok(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 mL=pa&&"documentMode"in document&&11>=document.documentMode,El=null,Jg=null,vc=null,Xg=!1;function Dk(e,n,s){var r=s.window===s?s.document:s.nodeType===9?s:s.ownerDocument;Xg||El==null||El!==xh(r)||(r=El,"selectionStart"in r&&Wj(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}),vc&&Uc(vc,r)||(vc=r,r=Nh(Jg,"onSelect"),0<r.length&&(n=new zj("onSelect","select",null,n,s),e.push({event:n,listeners:r}),n.target=El)))}function lu(e,n){var s={};return s[e.toLowerCase()]=n.toLowerCase(),s["Webkit"+e]="webkit"+n,s["Moz"+e]="moz"+n,s}var Al={animationend:lu("Animation","AnimationEnd"),animationiteration:lu("Animation","AnimationIteration"),animationstart:lu("Animation","AnimationStart"),transitionend:lu("Transition","TransitionEnd")},ip={},mE={};pa&&(mE=document.createElement("div").style,"AnimationEvent"in window||(delete Al.animationend.animation,delete Al.animationiteration.animation,delete Al.animationstart.animation),"TransitionEvent"in window||delete Al.transitionend.transition);function Mf(e){if(ip[e])return ip[e];if(!Al[e])return e;var n=Al[e],s;for(s in n)if(n.hasOwnProperty(s)&&s in mE)return ip[e]=n[s];return e}var pE=Mf("animationend"),gE=Mf("animationiteration"),xE=Mf("animationstart"),vE=Mf("transitionend"),jE=new Map,Lk="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){jE.set(e,n),tl(n,[e])}for(var lp=0;lp<Lk.length;lp++){var op=Lk[lp],pL=op.toLowerCase(),gL=op[0].toUpperCase()+op.slice(1);di(pL,"on"+gL)}di(pE,"onAnimationEnd");di(gE,"onAnimationIteration");di(xE,"onAnimationStart");di("dblclick","onDoubleClick");di("focusin","onFocus");di("focusout","onBlur");di(vE,"onTransitionEnd");Jl("onMouseEnter",["mouseout","mouseover"]);Jl("onMouseLeave",["mouseout","mouseover"]);Jl("onPointerEnter",["pointerout","pointerover"]);Jl("onPointerLeave",["pointerout","pointerover"]);tl("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));tl("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));tl("onBeforeInput",["compositionend","keypress","textInput","paste"]);tl("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));tl("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));tl("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var lc="abort canplay canplaythrough durationchange emptied encrypted ended error loadeddata loadedmetadata loadstart pause play playing progress ratechange resize seeked seeking stalled suspend timeupdate volumechange waiting".split(" "),xL=new Set("cancel close invalid load scroll toggle".split(" ").concat(lc));function Fk(e,n,s){var r=e.type||"unknown-event";e.currentTarget=s,pD(r,n,void 0,e),e.currentTarget=null}function wE(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,d=o.currentTarget;if(o=o.listener,c!==i&&a.isPropagationStopped())break e;Fk(a,o,d),i=c}else for(l=0;l<r.length;l++){if(o=r[l],c=o.instance,d=o.currentTarget,o=o.listener,c!==i&&a.isPropagationStopped())break e;Fk(a,o,d),i=c}}}if(jh)throw e=Gg,jh=!1,Gg=null,e}function Lt(e,n){var s=n[sx];s===void 0&&(s=n[sx]=new Set);var r=e+"__bubble";s.has(r)||(yE(n,e,2,!1),s.add(r))}function cp(e,n,s){var r=0;n&&(r|=4),yE(s,e,r,n)}var ou="_reactListening"+Math.random().toString(36).slice(2);function Bc(e){if(!e[ou]){e[ou]=!0,A1.forEach(function(s){s!=="selectionchange"&&(xL.has(s)||cp(s,!1,e),cp(s,!0,e))});var n=e.nodeType===9?e:e.ownerDocument;n===null||n[ou]||(n[ou]=!0,cp("selectionchange",!1,n))}}function yE(e,n,s,r){switch(rE(n)){case 1:var a=ID;break;case 4:a=RD;break;default:a=Fj}s=a.bind(null,n,s,e),a=void 0,!Vg||n!=="touchstart"&&n!=="touchmove"&&n!=="wheel"||(a=!0),r?a!==void 0?e.addEventListener(n,s,{capture:!0,passive:a}):e.addEventListener(n,s,!0):a!==void 0?e.addEventListener(n,s,{passive:a}):e.addEventListener(n,s,!1)}function dp(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=Ii(o),l===null)return;if(c=l.tag,c===5||c===6){r=i=l;continue e}o=o.parentNode}}r=r.return}H1(function(){var d=i,h=Mj(s),f=[];e:{var m=jE.get(e);if(m!==void 0){var p=zj,x=e;switch(e){case"keypress":if(Gu(s)===0)break e;case"keydown":case"keyup":p=GD;break;case"focusin":x="focus",p=sp;break;case"focusout":x="blur",p=sp;break;case"beforeblur":case"afterblur":p=sp;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=Ck;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":p=OD;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":p=QD;break;case pE:case gE:case xE:p=FD;break;case vE:p=XD;break;case"scroll":p=PD;break;case"wheel":p=eL;break;case"copy":case"cut":case"paste":p=zD;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":p=Ak}var g=(n&4)!==0,y=!g&&e==="scroll",j=g?m!==null?m+"Capture":null:m;g=[];for(var v=d,w;v!==null;){w=v;var N=w.stateNode;if(w.tag===5&&N!==null&&(w=N,j!==null&&(N=Dc(v,j),N!=null&&g.push(Wc(v,N,w)))),y)break;v=v.return}0<g.length&&(m=new p(m,x,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!==Hg&&(x=s.relatedTarget||s.fromElement)&&(Ii(x)||x[ga]))break e;if((p||m)&&(m=h.window===h?h:(m=h.ownerDocument)?m.defaultView||m.parentWindow:window,p?(x=s.relatedTarget||s.toElement,p=d,x=x?Ii(x):null,x!==null&&(y=nl(x),x!==y||x.tag!==5&&x.tag!==6)&&(x=null)):(p=null,x=d),p!==x)){if(g=Ck,N="onMouseLeave",j="onMouseEnter",v="mouse",(e==="pointerout"||e==="pointerover")&&(g=Ak,N="onPointerLeave",j="onPointerEnter",v="pointer"),y=p==null?m:$l(p),w=x==null?m:$l(x),m=new g(N,v+"leave",p,s,h),m.target=y,m.relatedTarget=w,N=null,Ii(h)===d&&(g=new g(j,v+"enter",x,s,h),g.target=w,g.relatedTarget=y,N=g),y=N,p&&x)t:{for(g=p,j=x,v=0,w=g;w;w=ml(w))v++;for(w=0,N=j;N;N=ml(N))w++;for(;0<v-w;)g=ml(g),v--;for(;0<w-v;)j=ml(j),w--;for(;v--;){if(g===j||j!==null&&g===j.alternate)break t;g=ml(g),j=ml(j)}g=null}else g=null;p!==null&&_k(f,m,p,g,!1),x!==null&&y!==null&&_k(f,y,x,g,!0)}}e:{if(m=d?$l(d):window,p=m.nodeName&&m.nodeName.toLowerCase(),p==="select"||p==="input"&&m.type==="file")var k=lL;else if(Ik(m))if(dE)k=uL;else{k=cL;var S=oL}else(p=m.nodeName)&&p.toLowerCase()==="input"&&(m.type==="checkbox"||m.type==="radio")&&(k=dL);if(k&&(k=k(e,d))){cE(f,k,s,h);break e}S&&S(e,m,d),e==="focusout"&&(S=m._wrapperState)&&S.controlled&&m.type==="number"&&_g(m,"number",m.value)}switch(S=d?$l(d):window,e){case"focusin":(Ik(S)||S.contentEditable==="true")&&(El=S,Jg=d,vc=null);break;case"focusout":vc=Jg=El=null;break;case"mousedown":Xg=!0;break;case"contextmenu":case"mouseup":case"dragend":Xg=!1,Dk(f,s,h);break;case"selectionchange":if(mL)break;case"keydown":case"keyup":Dk(f,s,h)}var b;if(Bj)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 Cl?lE(e,s)&&(C="onCompositionEnd"):e==="keydown"&&s.keyCode===229&&(C="onCompositionStart");C&&(iE&&s.locale!=="ko"&&(Cl||C!=="onCompositionStart"?C==="onCompositionEnd"&&Cl&&(b=aE()):(Fa=h,_j="value"in Fa?Fa.value:Fa.textContent,Cl=!0)),S=Nh(d,C),0<S.length&&(C=new Ek(C,e,null,s,h),f.push({event:C,listeners:S}),b?C.data=b:(b=oE(s),b!==null&&(C.data=b)))),(b=nL?sL(e,s):rL(e,s))&&(d=Nh(d,"onBeforeInput"),0<d.length&&(h=new Ek("onBeforeInput","beforeinput",null,s,h),f.push({event:h,listeners:d}),h.data=b))}wE(f,n)})}function Wc(e,n,s){return{instance:e,listener:n,currentTarget:s}}function Nh(e,n){for(var s=n+"Capture",r=[];e!==null;){var a=e,i=a.stateNode;a.tag===5&&i!==null&&(a=i,i=Dc(e,s),i!=null&&r.unshift(Wc(e,i,a)),i=Dc(e,n),i!=null&&r.push(Wc(e,i,a))),e=e.return}return r}function ml(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function _k(e,n,s,r,a){for(var i=n._reactName,l=[];s!==null&&s!==r;){var o=s,c=o.alternate,d=o.stateNode;if(c!==null&&c===r)break;o.tag===5&&d!==null&&(o=d,a?(c=Dc(s,i),c!=null&&l.unshift(Wc(s,c,o))):a||(c=Dc(s,i),c!=null&&l.push(Wc(s,c,o)))),s=s.return}l.length!==0&&e.push({event:n,listeners:l})}var vL=/\r\n?/g,jL=/\u0000|\uFFFD/g;function zk(e){return(typeof e=="string"?e:""+e).replace(vL,`
38
+ `).replace(jL,"")}function cu(e,n,s){if(n=zk(n),zk(e)!==n&&s)throw Error(Ne(425))}function Sh(){}var Zg=null,ex=null;function tx(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 nx=typeof setTimeout=="function"?setTimeout:void 0,wL=typeof clearTimeout=="function"?clearTimeout:void 0,Uk=typeof Promise=="function"?Promise:void 0,yL=typeof queueMicrotask=="function"?queueMicrotask:typeof Uk<"u"?function(e){return Uk.resolve(null).then(e).catch(bL)}:nx;function bL(e){setTimeout(function(){throw e})}function up(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),_c(n);return}r--}else s!=="$"&&s!=="$?"&&s!=="$!"||r++;s=a}while(s);_c(n)}function Ka(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 Bk(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 bo=Math.random().toString(36).slice(2),Mr="__reactFiber$"+bo,Hc="__reactProps$"+bo,ga="__reactContainer$"+bo,sx="__reactEvents$"+bo,kL="__reactListeners$"+bo,NL="__reactHandles$"+bo;function Ii(e){var n=e[Mr];if(n)return n;for(var s=e.parentNode;s;){if(n=s[ga]||s[Mr]){if(s=n.alternate,n.child!==null||s!==null&&s.child!==null)for(e=Bk(e);e!==null;){if(s=e[Mr])return s;e=Bk(e)}return n}e=s,s=e.parentNode}return null}function Ed(e){return e=e[Mr]||e[ga],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function $l(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(Ne(33))}function Of(e){return e[Hc]||null}var rx=[],Tl=-1;function ui(e){return{current:e}}function Ft(e){0>Tl||(e.current=rx[Tl],rx[Tl]=null,Tl--)}function Rt(e,n){Tl++,rx[Tl]=e.current,e.current=n}var ei={},qn=ui(ei),us=ui(!1),Bi=ei;function Xl(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 hs(e){return e=e.childContextTypes,e!=null}function Ch(){Ft(us),Ft(qn)}function Wk(e,n,s){if(qn.current!==ei)throw Error(Ne(168));Rt(qn,n),Rt(us,s)}function bE(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,oD(e)||"Unknown",a));return Xt({},s,r)}function Eh(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||ei,Bi=qn.current,Rt(qn,e),Rt(us,us.current),!0}function Hk(e,n,s){var r=e.stateNode;if(!r)throw Error(Ne(169));s?(e=bE(e,n,Bi),r.__reactInternalMemoizedMergedChildContext=e,Ft(us),Ft(qn),Rt(qn,e)):Ft(us),Rt(us,s)}var ra=null,Df=!1,hp=!1;function kE(e){ra===null?ra=[e]:ra.push(e)}function SL(e){Df=!0,kE(e)}function hi(){if(!hp&&ra!==null){hp=!0;var e=0,n=Nt;try{var s=ra;for(Nt=1;e<s.length;e++){var r=s[e];do r=r(!0);while(r!==null)}ra=null,Df=!1}catch(a){throw ra!==null&&(ra=ra.slice(e+1)),q1(Oj,hi),a}finally{Nt=n,hp=!1}}return null}var Il=[],Rl=0,Ah=null,$h=0,Hs=[],Ks=0,Wi=null,oa=1,ca="";function Ei(e,n){Il[Rl++]=$h,Il[Rl++]=Ah,Ah=e,$h=n}function NE(e,n,s){Hs[Ks++]=oa,Hs[Ks++]=ca,Hs[Ks++]=Wi,Wi=e;var r=oa;e=ca;var a=32-cr(r)-1;r&=~(1<<a),s+=1;var i=32-cr(n)+a;if(30<i){var l=a-a%5;i=(r&(1<<l)-1).toString(32),r>>=l,a-=l,oa=1<<32-cr(n)+a|s<<a|r,ca=i+e}else oa=1<<i|s<<a|r,ca=e}function Hj(e){e.return!==null&&(Ei(e,1),NE(e,1,0))}function Kj(e){for(;e===Ah;)Ah=Il[--Rl],Il[Rl]=null,$h=Il[--Rl],Il[Rl]=null;for(;e===Wi;)Wi=Hs[--Ks],Hs[Ks]=null,ca=Hs[--Ks],Hs[Ks]=null,oa=Hs[--Ks],Hs[Ks]=null}var Cs=null,Ns=null,Wt=!1,ar=null;function SE(e,n){var s=Ys(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 Kk(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,Cs=e,Ns=Ka(n.firstChild),!0):!1;case 6:return n=e.pendingProps===""||n.nodeType!==3?null:n,n!==null?(e.stateNode=n,Cs=e,Ns=null,!0):!1;case 13:return n=n.nodeType!==8?null:n,n!==null?(s=Wi!==null?{id:oa,overflow:ca}:null,e.memoizedState={dehydrated:n,treeContext:s,retryLane:1073741824},s=Ys(18,null,null,0),s.stateNode=n,s.return=e,e.child=s,Cs=e,Ns=null,!0):!1;default:return!1}}function ax(e){return(e.mode&1)!==0&&(e.flags&128)===0}function ix(e){if(Wt){var n=Ns;if(n){var s=n;if(!Kk(e,n)){if(ax(e))throw Error(Ne(418));n=Ka(s.nextSibling);var r=Cs;n&&Kk(e,n)?SE(r,s):(e.flags=e.flags&-4097|2,Wt=!1,Cs=e)}}else{if(ax(e))throw Error(Ne(418));e.flags=e.flags&-4097|2,Wt=!1,Cs=e}}}function Vk(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;Cs=e}function du(e){if(e!==Cs)return!1;if(!Wt)return Vk(e),Wt=!0,!1;var n;if((n=e.tag!==3)&&!(n=e.tag!==5)&&(n=e.type,n=n!=="head"&&n!=="body"&&!tx(e.type,e.memoizedProps)),n&&(n=Ns)){if(ax(e))throw CE(),Error(Ne(418));for(;n;)SE(e,n),n=Ka(n.nextSibling)}if(Vk(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){Ns=Ka(e.nextSibling);break e}n--}else s!=="$"&&s!=="$!"&&s!=="$?"||n++}e=e.nextSibling}Ns=null}}else Ns=Cs?Ka(e.stateNode.nextSibling):null;return!0}function CE(){for(var e=Ns;e;)e=Ka(e.nextSibling)}function Zl(){Ns=Cs=null,Wt=!1}function Vj(e){ar===null?ar=[e]:ar.push(e)}var CL=ba.ReactCurrentBatchConfig;function Go(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 uu(e,n){throw e=Object.prototype.toString.call(n),Error(Ne(31,e==="[object Object]"?"object with keys {"+Object.keys(n).join(", ")+"}":e))}function Gk(e){var n=e._init;return n(e._payload)}function EE(e){function n(j,v){if(e){var w=j.deletions;w===null?(j.deletions=[v],j.flags|=16):w.push(v)}}function s(j,v){if(!e)return null;for(;v!==null;)n(j,v),v=v.sibling;return null}function r(j,v){for(j=new Map;v!==null;)v.key!==null?j.set(v.key,v):j.set(v.index,v),v=v.sibling;return j}function a(j,v){return j=Ya(j,v),j.index=0,j.sibling=null,j}function i(j,v,w){return j.index=w,e?(w=j.alternate,w!==null?(w=w.index,w<v?(j.flags|=2,v):w):(j.flags|=2,v)):(j.flags|=1048576,v)}function l(j){return e&&j.alternate===null&&(j.flags|=2),j}function o(j,v,w,N){return v===null||v.tag!==6?(v=jp(w,j.mode,N),v.return=j,v):(v=a(v,w),v.return=j,v)}function c(j,v,w,N){var k=w.type;return k===Sl?h(j,v,w.props.children,N,w.key):v!==null&&(v.elementType===k||typeof k=="object"&&k!==null&&k.$$typeof===Pa&&Gk(k)===v.type)?(N=a(v,w.props),N.ref=Go(j,v,w),N.return=j,N):(N=eh(w.type,w.key,w.props,null,j.mode,N),N.ref=Go(j,v,w),N.return=j,N)}function d(j,v,w,N){return v===null||v.tag!==4||v.stateNode.containerInfo!==w.containerInfo||v.stateNode.implementation!==w.implementation?(v=wp(w,j.mode,N),v.return=j,v):(v=a(v,w.children||[]),v.return=j,v)}function h(j,v,w,N,k){return v===null||v.tag!==7?(v=Fi(w,j.mode,N,k),v.return=j,v):(v=a(v,w),v.return=j,v)}function f(j,v,w){if(typeof v=="string"&&v!==""||typeof v=="number")return v=jp(""+v,j.mode,w),v.return=j,v;if(typeof v=="object"&&v!==null){switch(v.$$typeof){case eu:return w=eh(v.type,v.key,v.props,null,j.mode,w),w.ref=Go(j,null,v),w.return=j,w;case Nl:return v=wp(v,j.mode,w),v.return=j,v;case Pa:var N=v._init;return f(j,N(v._payload),w)}if(ac(v)||Bo(v))return v=Fi(v,j.mode,w,null),v.return=j,v;uu(j,v)}return null}function m(j,v,w,N){var k=v!==null?v.key:null;if(typeof w=="string"&&w!==""||typeof w=="number")return k!==null?null:o(j,v,""+w,N);if(typeof w=="object"&&w!==null){switch(w.$$typeof){case eu:return w.key===k?c(j,v,w,N):null;case Nl:return w.key===k?d(j,v,w,N):null;case Pa:return k=w._init,m(j,v,k(w._payload),N)}if(ac(w)||Bo(w))return k!==null?null:h(j,v,w,N,null);uu(j,w)}return null}function p(j,v,w,N,k){if(typeof N=="string"&&N!==""||typeof N=="number")return j=j.get(w)||null,o(v,j,""+N,k);if(typeof N=="object"&&N!==null){switch(N.$$typeof){case eu:return j=j.get(N.key===null?w:N.key)||null,c(v,j,N,k);case Nl:return j=j.get(N.key===null?w:N.key)||null,d(v,j,N,k);case Pa:var S=N._init;return p(j,v,w,S(N._payload),k)}if(ac(N)||Bo(N))return j=j.get(w)||null,h(v,j,N,k,null);uu(v,N)}return null}function x(j,v,w,N){for(var k=null,S=null,b=v,C=v=0,$=null;b!==null&&C<w.length;C++){b.index>C?($=b,b=null):$=b.sibling;var A=m(j,b,w[C],N);if(A===null){b===null&&(b=$);break}e&&b&&A.alternate===null&&n(j,b),v=i(A,v,C),S===null?k=A:S.sibling=A,S=A,b=$}if(C===w.length)return s(j,b),Wt&&Ei(j,C),k;if(b===null){for(;C<w.length;C++)b=f(j,w[C],N),b!==null&&(v=i(b,v,C),S===null?k=b:S.sibling=b,S=b);return Wt&&Ei(j,C),k}for(b=r(j,b);C<w.length;C++)$=p(b,j,C,w[C],N),$!==null&&(e&&$.alternate!==null&&b.delete($.key===null?C:$.key),v=i($,v,C),S===null?k=$:S.sibling=$,S=$);return e&&b.forEach(function(I){return n(j,I)}),Wt&&Ei(j,C),k}function g(j,v,w,N){var k=Bo(w);if(typeof k!="function")throw Error(Ne(150));if(w=k.call(w),w==null)throw Error(Ne(151));for(var S=k=null,b=v,C=v=0,$=null,A=w.next();b!==null&&!A.done;C++,A=w.next()){b.index>C?($=b,b=null):$=b.sibling;var I=m(j,b,A.value,N);if(I===null){b===null&&(b=$);break}e&&b&&I.alternate===null&&n(j,b),v=i(I,v,C),S===null?k=I:S.sibling=I,S=I,b=$}if(A.done)return s(j,b),Wt&&Ei(j,C),k;if(b===null){for(;!A.done;C++,A=w.next())A=f(j,A.value,N),A!==null&&(v=i(A,v,C),S===null?k=A:S.sibling=A,S=A);return Wt&&Ei(j,C),k}for(b=r(j,b);!A.done;C++,A=w.next())A=p(b,j,C,A.value,N),A!==null&&(e&&A.alternate!==null&&b.delete(A.key===null?C:A.key),v=i(A,v,C),S===null?k=A:S.sibling=A,S=A);return e&&b.forEach(function(M){return n(j,M)}),Wt&&Ei(j,C),k}function y(j,v,w,N){if(typeof w=="object"&&w!==null&&w.type===Sl&&w.key===null&&(w=w.props.children),typeof w=="object"&&w!==null){switch(w.$$typeof){case eu:e:{for(var k=w.key,S=v;S!==null;){if(S.key===k){if(k=w.type,k===Sl){if(S.tag===7){s(j,S.sibling),v=a(S,w.props.children),v.return=j,j=v;break e}}else if(S.elementType===k||typeof k=="object"&&k!==null&&k.$$typeof===Pa&&Gk(k)===S.type){s(j,S.sibling),v=a(S,w.props),v.ref=Go(j,S,w),v.return=j,j=v;break e}s(j,S);break}else n(j,S);S=S.sibling}w.type===Sl?(v=Fi(w.props.children,j.mode,N,w.key),v.return=j,j=v):(N=eh(w.type,w.key,w.props,null,j.mode,N),N.ref=Go(j,v,w),N.return=j,j=N)}return l(j);case Nl:e:{for(S=w.key;v!==null;){if(v.key===S)if(v.tag===4&&v.stateNode.containerInfo===w.containerInfo&&v.stateNode.implementation===w.implementation){s(j,v.sibling),v=a(v,w.children||[]),v.return=j,j=v;break e}else{s(j,v);break}else n(j,v);v=v.sibling}v=wp(w,j.mode,N),v.return=j,j=v}return l(j);case Pa:return S=w._init,y(j,v,S(w._payload),N)}if(ac(w))return x(j,v,w,N);if(Bo(w))return g(j,v,w,N);uu(j,w)}return typeof w=="string"&&w!==""||typeof w=="number"?(w=""+w,v!==null&&v.tag===6?(s(j,v.sibling),v=a(v,w),v.return=j,j=v):(s(j,v),v=jp(w,j.mode,N),v.return=j,j=v),l(j)):s(j,v)}return y}var eo=EE(!0),AE=EE(!1),Th=ui(null),Ih=null,Pl=null,Gj=null;function qj(){Gj=Pl=Ih=null}function Yj(e){var n=Th.current;Ft(Th),e._currentValue=n}function lx(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 Wl(e,n){Ih=e,Gj=Pl=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&n&&(cs=!0),e.firstContext=null)}function Xs(e){var n=e._currentValue;if(Gj!==e)if(e={context:e,memoizedValue:n,next:null},Pl===null){if(Ih===null)throw Error(Ne(308));Pl=e,Ih.dependencies={lanes:0,firstContext:e}}else Pl=Pl.next=e;return n}var Ri=null;function Qj(e){Ri===null?Ri=[e]:Ri.push(e)}function $E(e,n,s,r){var a=n.interleaved;return a===null?(s.next=s,Qj(n)):(s.next=a.next,a.next=s),n.interleaved=s,xa(e,r)}function xa(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 Ma=!1;function Jj(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function TE(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 ua(e,n){return{eventTime:e,lane:n,tag:0,payload:null,callback:null,next:null}}function Va(e,n,s){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,jt&2){var a=r.pending;return a===null?n.next=n:(n.next=a.next,a.next=n),r.pending=n,xa(e,s)}return a=r.interleaved,a===null?(n.next=n,Qj(r)):(n.next=a.next,a.next=n),r.interleaved=n,xa(e,s)}function qu(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,Dj(e,s)}}function qk(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 Rh(e,n,s,r){var a=e.updateQueue;Ma=!1;var i=a.firstBaseUpdate,l=a.lastBaseUpdate,o=a.shared.pending;if(o!==null){a.shared.pending=null;var c=o,d=c.next;c.next=null,l===null?i=d:l.next=d,l=c;var h=e.alternate;h!==null&&(h=h.updateQueue,o=h.lastBaseUpdate,o!==l&&(o===null?h.firstBaseUpdate=d:o.next=d,h.lastBaseUpdate=c))}if(i!==null){var f=a.baseState;l=0,h=d=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 x=e,g=o;switch(m=n,p=s,g.tag){case 1:if(x=g.payload,typeof x=="function"){f=x.call(p,f,m);break e}f=x;break e;case 3:x.flags=x.flags&-65537|128;case 0:if(x=g.payload,m=typeof x=="function"?x.call(p,f,m):x,m==null)break e;f=Xt({},f,m);break e;case 2:Ma=!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?(d=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=d,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);Ki|=l,e.lanes=l,e.memoizedState=f}}function Yk(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 Ad={},_r=ui(Ad),Kc=ui(Ad),Vc=ui(Ad);function Pi(e){if(e===Ad)throw Error(Ne(174));return e}function Xj(e,n){switch(Rt(Vc,n),Rt(Kc,e),Rt(_r,Ad),e=n.nodeType,e){case 9:case 11:n=(n=n.documentElement)?n.namespaceURI:Ug(null,"");break;default:e=e===8?n.parentNode:n,n=e.namespaceURI||null,e=e.tagName,n=Ug(n,e)}Ft(_r),Rt(_r,n)}function to(){Ft(_r),Ft(Kc),Ft(Vc)}function IE(e){Pi(Vc.current);var n=Pi(_r.current),s=Ug(n,e.type);n!==s&&(Rt(Kc,e),Rt(_r,s))}function Zj(e){Kc.current===e&&(Ft(_r),Ft(Kc))}var Gt=ui(0);function Ph(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 fp=[];function ew(){for(var e=0;e<fp.length;e++)fp[e]._workInProgressVersionPrimary=null;fp.length=0}var Yu=ba.ReactCurrentDispatcher,mp=ba.ReactCurrentBatchConfig,Hi=0,qt=null,jn=null,En=null,Mh=!1,jc=!1,Gc=0,EL=0;function Wn(){throw Error(Ne(321))}function tw(e,n){if(n===null)return!1;for(var s=0;s<n.length&&s<e.length;s++)if(!fr(e[s],n[s]))return!1;return!0}function nw(e,n,s,r,a,i){if(Hi=i,qt=n,n.memoizedState=null,n.updateQueue=null,n.lanes=0,Yu.current=e===null||e.memoizedState===null?IL:RL,e=s(r,a),jc){i=0;do{if(jc=!1,Gc=0,25<=i)throw Error(Ne(301));i+=1,En=jn=null,n.updateQueue=null,Yu.current=PL,e=s(r,a)}while(jc)}if(Yu.current=Oh,n=jn!==null&&jn.next!==null,Hi=0,En=jn=qt=null,Mh=!1,n)throw Error(Ne(300));return e}function sw(){var e=Gc!==0;return Gc=0,e}function Rr(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return En===null?qt.memoizedState=En=e:En=En.next=e,En}function Zs(){if(jn===null){var e=qt.alternate;e=e!==null?e.memoizedState:null}else e=jn.next;var n=En===null?qt.memoizedState:En.next;if(n!==null)En=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},En===null?qt.memoizedState=En=e:En=En.next=e}return En}function qc(e,n){return typeof n=="function"?n(e):n}function pp(e){var n=Zs(),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,d=i;do{var h=d.lane;if((Hi&h)===h)c!==null&&(c=c.next={lane:0,action:d.action,hasEagerState:d.hasEagerState,eagerState:d.eagerState,next:null}),r=d.hasEagerState?d.eagerState:e(r,d.action);else{var f={lane:h,action:d.action,hasEagerState:d.hasEagerState,eagerState:d.eagerState,next:null};c===null?(o=c=f,l=r):c=c.next=f,qt.lanes|=h,Ki|=h}d=d.next}while(d!==null&&d!==i);c===null?l=r:c.next=o,fr(r,n.memoizedState)||(cs=!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,Ki|=i,a=a.next;while(a!==e)}else a===null&&(s.lanes=0);return[n.memoizedState,s.dispatch]}function gp(e){var n=Zs(),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);fr(i,n.memoizedState)||(cs=!0),n.memoizedState=i,n.baseQueue===null&&(n.baseState=i),s.lastRenderedState=i}return[i,r]}function RE(){}function PE(e,n){var s=qt,r=Zs(),a=n(),i=!fr(r.memoizedState,a);if(i&&(r.memoizedState=a,cs=!0),r=r.queue,rw(DE.bind(null,s,r,e),[e]),r.getSnapshot!==n||i||En!==null&&En.memoizedState.tag&1){if(s.flags|=2048,Yc(9,OE.bind(null,s,r,a,n),void 0,null),Tn===null)throw Error(Ne(349));Hi&30||ME(s,n,a)}return a}function ME(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 OE(e,n,s,r){n.value=s,n.getSnapshot=r,LE(n)&&FE(e)}function DE(e,n,s){return s(function(){LE(n)&&FE(e)})}function LE(e){var n=e.getSnapshot;e=e.value;try{var s=n();return!fr(e,s)}catch{return!0}}function FE(e){var n=xa(e,1);n!==null&&dr(n,e,1,-1)}function Qk(e){var n=Rr();return typeof e=="function"&&(e=e()),n.memoizedState=n.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:qc,lastRenderedState:e},n.queue=e,e=e.dispatch=TL.bind(null,qt,e),[n.memoizedState,e]}function Yc(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 _E(){return Zs().memoizedState}function Qu(e,n,s,r){var a=Rr();qt.flags|=e,a.memoizedState=Yc(1|n,s,void 0,r===void 0?null:r)}function Lf(e,n,s,r){var a=Zs();r=r===void 0?null:r;var i=void 0;if(jn!==null){var l=jn.memoizedState;if(i=l.destroy,r!==null&&tw(r,l.deps)){a.memoizedState=Yc(n,s,i,r);return}}qt.flags|=e,a.memoizedState=Yc(1|n,s,i,r)}function Jk(e,n){return Qu(8390656,8,e,n)}function rw(e,n){return Lf(2048,8,e,n)}function zE(e,n){return Lf(4,2,e,n)}function UE(e,n){return Lf(4,4,e,n)}function BE(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 WE(e,n,s){return s=s!=null?s.concat([e]):null,Lf(4,4,BE.bind(null,n,e),s)}function aw(){}function HE(e,n){var s=Zs();n=n===void 0?null:n;var r=s.memoizedState;return r!==null&&n!==null&&tw(n,r[1])?r[0]:(s.memoizedState=[e,n],e)}function KE(e,n){var s=Zs();n=n===void 0?null:n;var r=s.memoizedState;return r!==null&&n!==null&&tw(n,r[1])?r[0]:(e=e(),s.memoizedState=[e,n],e)}function VE(e,n,s){return Hi&21?(fr(s,n)||(s=J1(),qt.lanes|=s,Ki|=s,e.baseState=!0),n):(e.baseState&&(e.baseState=!1,cs=!0),e.memoizedState=s)}function AL(e,n){var s=Nt;Nt=s!==0&&4>s?s:4,e(!0);var r=mp.transition;mp.transition={};try{e(!1),n()}finally{Nt=s,mp.transition=r}}function GE(){return Zs().memoizedState}function $L(e,n,s){var r=qa(e);if(s={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null},qE(e))YE(n,s);else if(s=$E(e,n,s,r),s!==null){var a=ns();dr(s,e,r,a),QE(s,n,r)}}function TL(e,n,s){var r=qa(e),a={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null};if(qE(e))YE(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,fr(o,l)){var c=n.interleaved;c===null?(a.next=a,Qj(n)):(a.next=c.next,c.next=a),n.interleaved=a;return}}catch{}finally{}s=$E(e,n,a,r),s!==null&&(a=ns(),dr(s,e,r,a),QE(s,n,r))}}function qE(e){var n=e.alternate;return e===qt||n!==null&&n===qt}function YE(e,n){jc=Mh=!0;var s=e.pending;s===null?n.next=n:(n.next=s.next,s.next=n),e.pending=n}function QE(e,n,s){if(s&4194240){var r=n.lanes;r&=e.pendingLanes,s|=r,n.lanes=s,Dj(e,s)}}var Oh={readContext:Xs,useCallback:Wn,useContext:Wn,useEffect:Wn,useImperativeHandle:Wn,useInsertionEffect:Wn,useLayoutEffect:Wn,useMemo:Wn,useReducer:Wn,useRef:Wn,useState:Wn,useDebugValue:Wn,useDeferredValue:Wn,useTransition:Wn,useMutableSource:Wn,useSyncExternalStore:Wn,useId:Wn,unstable_isNewReconciler:!1},IL={readContext:Xs,useCallback:function(e,n){return Rr().memoizedState=[e,n===void 0?null:n],e},useContext:Xs,useEffect:Jk,useImperativeHandle:function(e,n,s){return s=s!=null?s.concat([e]):null,Qu(4194308,4,BE.bind(null,n,e),s)},useLayoutEffect:function(e,n){return Qu(4194308,4,e,n)},useInsertionEffect:function(e,n){return Qu(4,2,e,n)},useMemo:function(e,n){var s=Rr();return n=n===void 0?null:n,e=e(),s.memoizedState=[e,n],e},useReducer:function(e,n,s){var r=Rr();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=$L.bind(null,qt,e),[r.memoizedState,e]},useRef:function(e){var n=Rr();return e={current:e},n.memoizedState=e},useState:Qk,useDebugValue:aw,useDeferredValue:function(e){return Rr().memoizedState=e},useTransition:function(){var e=Qk(!1),n=e[0];return e=AL.bind(null,e[1]),Rr().memoizedState=e,[n,e]},useMutableSource:function(){},useSyncExternalStore:function(e,n,s){var r=qt,a=Rr();if(Wt){if(s===void 0)throw Error(Ne(407));s=s()}else{if(s=n(),Tn===null)throw Error(Ne(349));Hi&30||ME(r,n,s)}a.memoizedState=s;var i={value:s,getSnapshot:n};return a.queue=i,Jk(DE.bind(null,r,i,e),[e]),r.flags|=2048,Yc(9,OE.bind(null,r,i,s,n),void 0,null),s},useId:function(){var e=Rr(),n=Tn.identifierPrefix;if(Wt){var s=ca,r=oa;s=(r&~(1<<32-cr(r)-1)).toString(32)+s,n=":"+n+"R"+s,s=Gc++,0<s&&(n+="H"+s.toString(32)),n+=":"}else s=EL++,n=":"+n+"r"+s.toString(32)+":";return e.memoizedState=n},unstable_isNewReconciler:!1},RL={readContext:Xs,useCallback:HE,useContext:Xs,useEffect:rw,useImperativeHandle:WE,useInsertionEffect:zE,useLayoutEffect:UE,useMemo:KE,useReducer:pp,useRef:_E,useState:function(){return pp(qc)},useDebugValue:aw,useDeferredValue:function(e){var n=Zs();return VE(n,jn.memoizedState,e)},useTransition:function(){var e=pp(qc)[0],n=Zs().memoizedState;return[e,n]},useMutableSource:RE,useSyncExternalStore:PE,useId:GE,unstable_isNewReconciler:!1},PL={readContext:Xs,useCallback:HE,useContext:Xs,useEffect:rw,useImperativeHandle:WE,useInsertionEffect:zE,useLayoutEffect:UE,useMemo:KE,useReducer:gp,useRef:_E,useState:function(){return gp(qc)},useDebugValue:aw,useDeferredValue:function(e){var n=Zs();return jn===null?n.memoizedState=e:VE(n,jn.memoizedState,e)},useTransition:function(){var e=gp(qc)[0],n=Zs().memoizedState;return[e,n]},useMutableSource:RE,useSyncExternalStore:PE,useId:GE,unstable_isNewReconciler:!1};function sr(e,n){if(e&&e.defaultProps){n=Xt({},n),e=e.defaultProps;for(var s in e)n[s]===void 0&&(n[s]=e[s]);return n}return n}function ox(e,n,s,r){n=e.memoizedState,s=s(r,n),s=s==null?n:Xt({},n,s),e.memoizedState=s,e.lanes===0&&(e.updateQueue.baseState=s)}var Ff={isMounted:function(e){return(e=e._reactInternals)?nl(e)===e:!1},enqueueSetState:function(e,n,s){e=e._reactInternals;var r=ns(),a=qa(e),i=ua(r,a);i.payload=n,s!=null&&(i.callback=s),n=Va(e,i,a),n!==null&&(dr(n,e,a,r),qu(n,e,a))},enqueueReplaceState:function(e,n,s){e=e._reactInternals;var r=ns(),a=qa(e),i=ua(r,a);i.tag=1,i.payload=n,s!=null&&(i.callback=s),n=Va(e,i,a),n!==null&&(dr(n,e,a,r),qu(n,e,a))},enqueueForceUpdate:function(e,n){e=e._reactInternals;var s=ns(),r=qa(e),a=ua(s,r);a.tag=2,n!=null&&(a.callback=n),n=Va(e,a,r),n!==null&&(dr(n,e,r,s),qu(n,e,r))}};function Xk(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?!Uc(s,r)||!Uc(a,i):!0}function JE(e,n,s){var r=!1,a=ei,i=n.contextType;return typeof i=="object"&&i!==null?i=Xs(i):(a=hs(n)?Bi:qn.current,r=n.contextTypes,i=(r=r!=null)?Xl(e,a):ei),n=new n(s,i),e.memoizedState=n.state!==null&&n.state!==void 0?n.state:null,n.updater=Ff,e.stateNode=n,n._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=a,e.__reactInternalMemoizedMaskedChildContext=i),n}function Zk(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&&Ff.enqueueReplaceState(n,n.state,null)}function cx(e,n,s,r){var a=e.stateNode;a.props=s,a.state=e.memoizedState,a.refs={},Jj(e);var i=n.contextType;typeof i=="object"&&i!==null?a.context=Xs(i):(i=hs(n)?Bi:qn.current,a.context=Xl(e,i)),a.state=e.memoizedState,i=n.getDerivedStateFromProps,typeof i=="function"&&(ox(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&&Ff.enqueueReplaceState(a,a.state,null),Rh(e,s,a,r),a.state=e.memoizedState),typeof a.componentDidMount=="function"&&(e.flags|=4194308)}function no(e,n){try{var s="",r=n;do s+=lD(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 xp(e,n,s){return{value:e,source:null,stack:s??null,digest:n??null}}function dx(e,n){try{console.error(n.value)}catch(s){setTimeout(function(){throw s})}}var ML=typeof WeakMap=="function"?WeakMap:Map;function XE(e,n,s){s=ua(-1,s),s.tag=3,s.payload={element:null};var r=n.value;return s.callback=function(){Lh||(Lh=!0,wx=r),dx(e,n)},s}function ZE(e,n,s){s=ua(-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(){dx(e,n)}}var i=e.stateNode;return i!==null&&typeof i.componentDidCatch=="function"&&(s.callback=function(){dx(e,n),typeof r!="function"&&(Ga===null?Ga=new Set([this]):Ga.add(this));var l=n.stack;this.componentDidCatch(n.value,{componentStack:l!==null?l:""})}),s}function e0(e,n,s){var r=e.pingCache;if(r===null){r=e.pingCache=new ML;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=qL.bind(null,e,n,s),n.then(e,e))}function t0(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 n0(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=ua(-1,1),n.tag=2,Va(s,n,1))),s.lanes|=1),e)}var OL=ba.ReactCurrentOwner,cs=!1;function Zn(e,n,s,r){n.child=e===null?AE(n,null,s,r):eo(n,e.child,s,r)}function s0(e,n,s,r,a){s=s.render;var i=n.ref;return Wl(n,a),r=nw(e,n,s,r,i,a),s=sw(),e!==null&&!cs?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~a,va(e,n,a)):(Wt&&s&&Hj(n),n.flags|=1,Zn(e,n,r,a),n.child)}function r0(e,n,s,r,a){if(e===null){var i=s.type;return typeof i=="function"&&!fw(i)&&i.defaultProps===void 0&&s.compare===null&&s.defaultProps===void 0?(n.tag=15,n.type=i,eA(e,n,i,r,a)):(e=eh(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:Uc,s(l,r)&&e.ref===n.ref)return va(e,n,a)}return n.flags|=1,e=Ya(i,r),e.ref=n.ref,e.return=n,n.child=e}function eA(e,n,s,r,a){if(e!==null){var i=e.memoizedProps;if(Uc(i,r)&&e.ref===n.ref)if(cs=!1,n.pendingProps=r=i,(e.lanes&a)!==0)e.flags&131072&&(cs=!0);else return n.lanes=e.lanes,va(e,n,a)}return ux(e,n,s,r,a)}function tA(e,n,s){var r=n.pendingProps,a=r.children,i=e!==null?e.memoizedState:null;if(r.mode==="hidden")if(!(n.mode&1))n.memoizedState={baseLanes:0,cachePool:null,transitions:null},Rt(Ol,ys),ys|=s;else{if(!(s&1073741824))return e=i!==null?i.baseLanes|s:s,n.lanes=n.childLanes=1073741824,n.memoizedState={baseLanes:e,cachePool:null,transitions:null},n.updateQueue=null,Rt(Ol,ys),ys|=e,null;n.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=i!==null?i.baseLanes:s,Rt(Ol,ys),ys|=r}else i!==null?(r=i.baseLanes|s,n.memoizedState=null):r=s,Rt(Ol,ys),ys|=r;return Zn(e,n,a,s),n.child}function nA(e,n){var s=n.ref;(e===null&&s!==null||e!==null&&e.ref!==s)&&(n.flags|=512,n.flags|=2097152)}function ux(e,n,s,r,a){var i=hs(s)?Bi:qn.current;return i=Xl(n,i),Wl(n,a),s=nw(e,n,s,r,i,a),r=sw(),e!==null&&!cs?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~a,va(e,n,a)):(Wt&&r&&Hj(n),n.flags|=1,Zn(e,n,s,a),n.child)}function a0(e,n,s,r,a){if(hs(s)){var i=!0;Eh(n)}else i=!1;if(Wl(n,a),n.stateNode===null)Ju(e,n),JE(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,d=s.contextType;typeof d=="object"&&d!==null?d=Xs(d):(d=hs(s)?Bi:qn.current,d=Xl(n,d));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!==d)&&Zk(n,l,r,d),Ma=!1;var m=n.memoizedState;l.state=m,Rh(n,r,l,a),c=n.memoizedState,o!==r||m!==c||us.current||Ma?(typeof h=="function"&&(ox(n,s,h,r),c=n.memoizedState),(o=Ma||Xk(n,s,o,r,m,c,d))?(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=d,r=o):(typeof l.componentDidMount=="function"&&(n.flags|=4194308),r=!1)}else{l=n.stateNode,TE(e,n),o=n.memoizedProps,d=n.type===n.elementType?o:sr(n.type,o),l.props=d,f=n.pendingProps,m=l.context,c=s.contextType,typeof c=="object"&&c!==null?c=Xs(c):(c=hs(s)?Bi:qn.current,c=Xl(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)&&Zk(n,l,r,c),Ma=!1,m=n.memoizedState,l.state=m,Rh(n,r,l,a);var x=n.memoizedState;o!==f||m!==x||us.current||Ma?(typeof p=="function"&&(ox(n,s,p,r),x=n.memoizedState),(d=Ma||Xk(n,s,d,r,m,x,c)||!1)?(h||typeof l.UNSAFE_componentWillUpdate!="function"&&typeof l.componentWillUpdate!="function"||(typeof l.componentWillUpdate=="function"&&l.componentWillUpdate(r,x,c),typeof l.UNSAFE_componentWillUpdate=="function"&&l.UNSAFE_componentWillUpdate(r,x,c)),typeof l.componentDidUpdate=="function"&&(n.flags|=4),typeof l.getSnapshotBeforeUpdate=="function"&&(n.flags|=1024)):(typeof l.componentDidUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(n.flags|=4),typeof l.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(n.flags|=1024),n.memoizedProps=r,n.memoizedState=x),l.props=r,l.state=x,l.context=c,r=d):(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 hx(e,n,s,r,i,a)}function hx(e,n,s,r,a,i){nA(e,n);var l=(n.flags&128)!==0;if(!r&&!l)return a&&Hk(n,s,!1),va(e,n,i);r=n.stateNode,OL.current=n;var o=l&&typeof s.getDerivedStateFromError!="function"?null:r.render();return n.flags|=1,e!==null&&l?(n.child=eo(n,e.child,null,i),n.child=eo(n,null,o,i)):Zn(e,n,o,i),n.memoizedState=r.state,a&&Hk(n,s,!0),n.child}function sA(e){var n=e.stateNode;n.pendingContext?Wk(e,n.pendingContext,n.pendingContext!==n.context):n.context&&Wk(e,n.context,!1),Xj(e,n.containerInfo)}function i0(e,n,s,r,a){return Zl(),Vj(a),n.flags|=256,Zn(e,n,s,r),n.child}var fx={dehydrated:null,treeContext:null,retryLane:0};function mx(e){return{baseLanes:e,cachePool:null,transitions:null}}function rA(e,n,s){var r=n.pendingProps,a=Gt.current,i=!1,l=(n.flags&128)!==0,o;if((o=l)||(o=e!==null&&e.memoizedState===null?!1:(a&2)!==0),o?(i=!0,n.flags&=-129):(e===null||e.memoizedState!==null)&&(a|=1),Rt(Gt,a&1),e===null)return ix(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=Uf(l,r,0,null),e=Fi(e,r,s,null),i.return=n,e.return=n,i.sibling=e,n.child=i,n.child.memoizedState=mx(s),n.memoizedState=fx,e):iw(n,l));if(a=e.memoizedState,a!==null&&(o=a.dehydrated,o!==null))return DL(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=Fi(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?mx(s):{baseLanes:l.baseLanes|s,cachePool:null,transitions:l.transitions},i.memoizedState=l,i.childLanes=e.childLanes&~s,n.memoizedState=fx,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 iw(e,n){return n=Uf({mode:"visible",children:n},e.mode,0,null),n.return=e,e.child=n}function hu(e,n,s,r){return r!==null&&Vj(r),eo(n,e.child,null,s),e=iw(n,n.pendingProps.children),e.flags|=2,n.memoizedState=null,e}function DL(e,n,s,r,a,i,l){if(s)return n.flags&256?(n.flags&=-257,r=xp(Error(Ne(422))),hu(e,n,l,r)):n.memoizedState!==null?(n.child=e.child,n.flags|=128,null):(i=r.fallback,a=n.mode,r=Uf({mode:"visible",children:r.children},a,0,null),i=Fi(i,a,l,null),i.flags|=2,r.return=n,i.return=n,r.sibling=i,n.child=r,n.mode&1&&eo(n,e.child,null,l),n.child.memoizedState=mx(l),n.memoizedState=fx,i);if(!(n.mode&1))return hu(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=xp(i,r,void 0),hu(e,n,l,r)}if(o=(l&e.childLanes)!==0,cs||o){if(r=Tn,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,xa(e,a),dr(r,e,a,-1))}return hw(),r=xp(Error(Ne(421))),hu(e,n,l,r)}return a.data==="$?"?(n.flags|=128,n.child=e.child,n=YL.bind(null,e),a._reactRetry=n,null):(e=i.treeContext,Ns=Ka(a.nextSibling),Cs=n,Wt=!0,ar=null,e!==null&&(Hs[Ks++]=oa,Hs[Ks++]=ca,Hs[Ks++]=Wi,oa=e.id,ca=e.overflow,Wi=n),n=iw(n,r.children),n.flags|=4096,n)}function l0(e,n,s){e.lanes|=n;var r=e.alternate;r!==null&&(r.lanes|=n),lx(e.return,n,s)}function vp(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 aA(e,n,s){var r=n.pendingProps,a=r.revealOrder,i=r.tail;if(Zn(e,n,r.children,s),r=Gt.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&&l0(e,s,n);else if(e.tag===19)l0(e,s,n);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===n)break e;for(;e.sibling===null;){if(e.return===null||e.return===n)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}if(Rt(Gt,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&&Ph(e)===null&&(a=s),s=s.sibling;s=a,s===null?(a=n.child,n.child=null):(a=s.sibling,s.sibling=null),vp(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&&Ph(e)===null){n.child=a;break}e=a.sibling,a.sibling=s,s=a,a=e}vp(n,!0,s,null,i);break;case"together":vp(n,!1,null,null,void 0);break;default:n.memoizedState=null}return n.child}function Ju(e,n){!(n.mode&1)&&e!==null&&(e.alternate=null,n.alternate=null,n.flags|=2)}function va(e,n,s){if(e!==null&&(n.dependencies=e.dependencies),Ki|=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 LL(e,n,s){switch(n.tag){case 3:sA(n),Zl();break;case 5:IE(n);break;case 1:hs(n.type)&&Eh(n);break;case 4:Xj(n,n.stateNode.containerInfo);break;case 10:var r=n.type._context,a=n.memoizedProps.value;Rt(Th,r._currentValue),r._currentValue=a;break;case 13:if(r=n.memoizedState,r!==null)return r.dehydrated!==null?(Rt(Gt,Gt.current&1),n.flags|=128,null):s&n.child.childLanes?rA(e,n,s):(Rt(Gt,Gt.current&1),e=va(e,n,s),e!==null?e.sibling:null);Rt(Gt,Gt.current&1);break;case 19:if(r=(s&n.childLanes)!==0,e.flags&128){if(r)return aA(e,n,s);n.flags|=128}if(a=n.memoizedState,a!==null&&(a.rendering=null,a.tail=null,a.lastEffect=null),Rt(Gt,Gt.current),r)break;return null;case 22:case 23:return n.lanes=0,tA(e,n,s)}return va(e,n,s)}var iA,px,lA,oA;iA=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}};px=function(){};lA=function(e,n,s,r){var a=e.memoizedProps;if(a!==r){e=n.stateNode,Pi(_r.current);var i=null;switch(s){case"input":a=Lg(e,a),r=Lg(e,r),i=[];break;case"select":a=Xt({},a,{value:void 0}),r=Xt({},r,{value:void 0}),i=[];break;case"textarea":a=zg(e,a),r=zg(e,r),i=[];break;default:typeof a.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=Sh)}Bg(s,r);var l;s=null;for(d in a)if(!r.hasOwnProperty(d)&&a.hasOwnProperty(d)&&a[d]!=null)if(d==="style"){var o=a[d];for(l in o)o.hasOwnProperty(l)&&(s||(s={}),s[l]="")}else d!=="dangerouslySetInnerHTML"&&d!=="children"&&d!=="suppressContentEditableWarning"&&d!=="suppressHydrationWarning"&&d!=="autoFocus"&&(Mc.hasOwnProperty(d)?i||(i=[]):(i=i||[]).push(d,null));for(d in r){var c=r[d];if(o=a!=null?a[d]:void 0,r.hasOwnProperty(d)&&c!==o&&(c!=null||o!=null))if(d==="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(d,s)),s=c;else d==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,o=o?o.__html:void 0,c!=null&&o!==c&&(i=i||[]).push(d,c)):d==="children"?typeof c!="string"&&typeof c!="number"||(i=i||[]).push(d,""+c):d!=="suppressContentEditableWarning"&&d!=="suppressHydrationWarning"&&(Mc.hasOwnProperty(d)?(c!=null&&d==="onScroll"&&Lt("scroll",e),i||o===c||(i=[])):(i=i||[]).push(d,c))}s&&(i=i||[]).push("style",s);var d=i;(n.updateQueue=d)&&(n.flags|=4)}};oA=function(e,n,s,r){s!==r&&(n.flags|=4)};function qo(e,n){if(!Wt)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 Hn(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 FL(e,n,s){var r=n.pendingProps;switch(Kj(n),n.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Hn(n),null;case 1:return hs(n.type)&&Ch(),Hn(n),null;case 3:return r=n.stateNode,to(),Ft(us),Ft(qn),ew(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(du(n)?n.flags|=4:e===null||e.memoizedState.isDehydrated&&!(n.flags&256)||(n.flags|=1024,ar!==null&&(kx(ar),ar=null))),px(e,n),Hn(n),null;case 5:Zj(n);var a=Pi(Vc.current);if(s=n.type,e!==null&&n.stateNode!=null)lA(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 Hn(n),null}if(e=Pi(_r.current),du(n)){r=n.stateNode,s=n.type;var i=n.memoizedProps;switch(r[Mr]=n,r[Hc]=i,e=(n.mode&1)!==0,s){case"dialog":Lt("cancel",r),Lt("close",r);break;case"iframe":case"object":case"embed":Lt("load",r);break;case"video":case"audio":for(a=0;a<lc.length;a++)Lt(lc[a],r);break;case"source":Lt("error",r);break;case"img":case"image":case"link":Lt("error",r),Lt("load",r);break;case"details":Lt("toggle",r);break;case"input":gk(r,i),Lt("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!i.multiple},Lt("invalid",r);break;case"textarea":vk(r,i),Lt("invalid",r)}Bg(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&&cu(r.textContent,o,e),a=["children",o]):typeof o=="number"&&r.textContent!==""+o&&(i.suppressHydrationWarning!==!0&&cu(r.textContent,o,e),a=["children",""+o]):Mc.hasOwnProperty(l)&&o!=null&&l==="onScroll"&&Lt("scroll",r)}switch(s){case"input":tu(r),xk(r,i,!0);break;case"textarea":tu(r),jk(r);break;case"select":case"option":break;default:typeof i.onClick=="function"&&(r.onclick=Sh)}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=D1(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[Mr]=n,e[Hc]=r,iA(e,n,!1,!1),n.stateNode=e;e:{switch(l=Wg(s,r),s){case"dialog":Lt("cancel",e),Lt("close",e),a=r;break;case"iframe":case"object":case"embed":Lt("load",e),a=r;break;case"video":case"audio":for(a=0;a<lc.length;a++)Lt(lc[a],e);a=r;break;case"source":Lt("error",e),a=r;break;case"img":case"image":case"link":Lt("error",e),Lt("load",e),a=r;break;case"details":Lt("toggle",e),a=r;break;case"input":gk(e,r),a=Lg(e,r),Lt("invalid",e);break;case"option":a=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},a=Xt({},r,{value:void 0}),Lt("invalid",e);break;case"textarea":vk(e,r),a=zg(e,r),Lt("invalid",e);break;default:a=r}Bg(s,a),o=a;for(i in o)if(o.hasOwnProperty(i)){var c=o[i];i==="style"?_1(e,c):i==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,c!=null&&L1(e,c)):i==="children"?typeof c=="string"?(s!=="textarea"||c!=="")&&Oc(e,c):typeof c=="number"&&Oc(e,""+c):i!=="suppressContentEditableWarning"&&i!=="suppressHydrationWarning"&&i!=="autoFocus"&&(Mc.hasOwnProperty(i)?c!=null&&i==="onScroll"&&Lt("scroll",e):c!=null&&Tj(e,i,c,l))}switch(s){case"input":tu(e),xk(e,r,!1);break;case"textarea":tu(e),jk(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?_l(e,!!r.multiple,i,!1):r.defaultValue!=null&&_l(e,!!r.multiple,r.defaultValue,!0);break;default:typeof a.onClick=="function"&&(e.onclick=Sh)}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 Hn(n),null;case 6:if(e&&n.stateNode!=null)oA(e,n,e.memoizedProps,r);else{if(typeof r!="string"&&n.stateNode===null)throw Error(Ne(166));if(s=Pi(Vc.current),Pi(_r.current),du(n)){if(r=n.stateNode,s=n.memoizedProps,r[Mr]=n,(i=r.nodeValue!==s)&&(e=Cs,e!==null))switch(e.tag){case 3:cu(r.nodeValue,s,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&cu(r.nodeValue,s,(e.mode&1)!==0)}i&&(n.flags|=4)}else r=(s.nodeType===9?s:s.ownerDocument).createTextNode(r),r[Mr]=n,n.stateNode=r}return Hn(n),null;case 13:if(Ft(Gt),r=n.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(Wt&&Ns!==null&&n.mode&1&&!(n.flags&128))CE(),Zl(),n.flags|=98560,i=!1;else if(i=du(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[Mr]=n}else Zl(),!(n.flags&128)&&(n.memoizedState=null),n.flags|=4;Hn(n),i=!1}else ar!==null&&(kx(ar),ar=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||Gt.current&1?yn===0&&(yn=3):hw())),n.updateQueue!==null&&(n.flags|=4),Hn(n),null);case 4:return to(),px(e,n),e===null&&Bc(n.stateNode.containerInfo),Hn(n),null;case 10:return Yj(n.type._context),Hn(n),null;case 17:return hs(n.type)&&Ch(),Hn(n),null;case 19:if(Ft(Gt),i=n.memoizedState,i===null)return Hn(n),null;if(r=(n.flags&128)!==0,l=i.rendering,l===null)if(r)qo(i,!1);else{if(yn!==0||e!==null&&e.flags&128)for(e=n.child;e!==null;){if(l=Ph(e),l!==null){for(n.flags|=128,qo(i,!1),r=l.updateQueue,r!==null&&(n.updateQueue=r,n.flags|=4),n.subtreeFlags=0,r=s,s=n.child;s!==null;)i=s,e=r,i.flags&=14680066,l=i.alternate,l===null?(i.childLanes=0,i.lanes=e,i.child=null,i.subtreeFlags=0,i.memoizedProps=null,i.memoizedState=null,i.updateQueue=null,i.dependencies=null,i.stateNode=null):(i.childLanes=l.childLanes,i.lanes=l.lanes,i.child=l.child,i.subtreeFlags=0,i.deletions=null,i.memoizedProps=l.memoizedProps,i.memoizedState=l.memoizedState,i.updateQueue=l.updateQueue,i.type=l.type,e=l.dependencies,i.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext}),s=s.sibling;return Rt(Gt,Gt.current&1|2),n.child}e=e.sibling}i.tail!==null&&rn()>so&&(n.flags|=128,r=!0,qo(i,!1),n.lanes=4194304)}else{if(!r)if(e=Ph(l),e!==null){if(n.flags|=128,r=!0,s=e.updateQueue,s!==null&&(n.updateQueue=s,n.flags|=4),qo(i,!0),i.tail===null&&i.tailMode==="hidden"&&!l.alternate&&!Wt)return Hn(n),null}else 2*rn()-i.renderingStartTime>so&&s!==1073741824&&(n.flags|=128,r=!0,qo(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=Gt.current,Rt(Gt,r?s&1|2:s&1),n):(Hn(n),null);case 22:case 23:return uw(),r=n.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(n.flags|=8192),r&&n.mode&1?ys&1073741824&&(Hn(n),n.subtreeFlags&6&&(n.flags|=8192)):Hn(n),null;case 24:return null;case 25:return null}throw Error(Ne(156,n.tag))}function _L(e,n){switch(Kj(n),n.tag){case 1:return hs(n.type)&&Ch(),e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 3:return to(),Ft(us),Ft(qn),ew(),e=n.flags,e&65536&&!(e&128)?(n.flags=e&-65537|128,n):null;case 5:return Zj(n),null;case 13:if(Ft(Gt),e=n.memoizedState,e!==null&&e.dehydrated!==null){if(n.alternate===null)throw Error(Ne(340));Zl()}return e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 19:return Ft(Gt),null;case 4:return to(),null;case 10:return Yj(n.type._context),null;case 22:case 23:return uw(),null;case 24:return null;default:return null}}var fu=!1,Vn=!1,zL=typeof WeakSet=="function"?WeakSet:Set,Fe=null;function Ml(e,n){var s=e.ref;if(s!==null)if(typeof s=="function")try{s(null)}catch(r){en(e,n,r)}else s.current=null}function gx(e,n,s){try{s()}catch(r){en(e,n,r)}}var o0=!1;function UL(e,n){if(Zg=bh,e=fE(),Wj(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,d=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&&++d===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(ex={focusedElem:e,selectionRange:s},bh=!1,Fe=n;Fe!==null;)if(n=Fe,e=n.child,(n.subtreeFlags&1028)!==0&&e!==null)e.return=n,Fe=e;else for(;Fe!==null;){n=Fe;try{var x=n.alternate;if(n.flags&1024)switch(n.tag){case 0:case 11:case 15:break;case 1:if(x!==null){var g=x.memoizedProps,y=x.memoizedState,j=n.stateNode,v=j.getSnapshotBeforeUpdate(n.elementType===n.type?g:sr(n.type,g),y);j.__reactInternalSnapshotBeforeUpdate=v}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){en(n,n.return,N)}if(e=n.sibling,e!==null){e.return=n.return,Fe=e;break}Fe=n.return}return x=o0,o0=!1,x}function wc(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&&gx(n,s,i)}a=a.next}while(a!==r)}}function _f(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 xx(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 cA(e){var n=e.alternate;n!==null&&(e.alternate=null,cA(n)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(n=e.stateNode,n!==null&&(delete n[Mr],delete n[Hc],delete n[sx],delete n[kL],delete n[NL])),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 dA(e){return e.tag===5||e.tag===3||e.tag===4}function c0(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||dA(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 vx(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=Sh));else if(r!==4&&(e=e.child,e!==null))for(vx(e,n,s),e=e.sibling;e!==null;)vx(e,n,s),e=e.sibling}function jx(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(jx(e,n,s),e=e.sibling;e!==null;)jx(e,n,s),e=e.sibling}var Fn=null,rr=!1;function Ta(e,n,s){for(s=s.child;s!==null;)uA(e,n,s),s=s.sibling}function uA(e,n,s){if(Fr&&typeof Fr.onCommitFiberUnmount=="function")try{Fr.onCommitFiberUnmount(If,s)}catch{}switch(s.tag){case 5:Vn||Ml(s,n);case 6:var r=Fn,a=rr;Fn=null,Ta(e,n,s),Fn=r,rr=a,Fn!==null&&(rr?(e=Fn,s=s.stateNode,e.nodeType===8?e.parentNode.removeChild(s):e.removeChild(s)):Fn.removeChild(s.stateNode));break;case 18:Fn!==null&&(rr?(e=Fn,s=s.stateNode,e.nodeType===8?up(e.parentNode,s):e.nodeType===1&&up(e,s),_c(e)):up(Fn,s.stateNode));break;case 4:r=Fn,a=rr,Fn=s.stateNode.containerInfo,rr=!0,Ta(e,n,s),Fn=r,rr=a;break;case 0:case 11:case 14:case 15:if(!Vn&&(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)&&gx(s,n,l),a=a.next}while(a!==r)}Ta(e,n,s);break;case 1:if(!Vn&&(Ml(s,n),r=s.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=s.memoizedProps,r.state=s.memoizedState,r.componentWillUnmount()}catch(o){en(s,n,o)}Ta(e,n,s);break;case 21:Ta(e,n,s);break;case 22:s.mode&1?(Vn=(r=Vn)||s.memoizedState!==null,Ta(e,n,s),Vn=r):Ta(e,n,s);break;default:Ta(e,n,s)}}function d0(e){var n=e.updateQueue;if(n!==null){e.updateQueue=null;var s=e.stateNode;s===null&&(s=e.stateNode=new zL),n.forEach(function(r){var a=QL.bind(null,e,r);s.has(r)||(s.add(r),r.then(a,a))})}}function nr(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:Fn=o.stateNode,rr=!1;break e;case 3:Fn=o.stateNode.containerInfo,rr=!0;break e;case 4:Fn=o.stateNode.containerInfo,rr=!0;break e}o=o.return}if(Fn===null)throw Error(Ne(160));uA(i,l,a),Fn=null,rr=!1;var c=a.alternate;c!==null&&(c.return=null),a.return=null}catch(d){en(a,n,d)}}if(n.subtreeFlags&12854)for(n=n.child;n!==null;)hA(n,e),n=n.sibling}function hA(e,n){var s=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(nr(n,e),Ar(e),r&4){try{wc(3,e,e.return),_f(3,e)}catch(g){en(e,e.return,g)}try{wc(5,e,e.return)}catch(g){en(e,e.return,g)}}break;case 1:nr(n,e),Ar(e),r&512&&s!==null&&Ml(s,s.return);break;case 5:if(nr(n,e),Ar(e),r&512&&s!==null&&Ml(s,s.return),e.flags&32){var a=e.stateNode;try{Oc(a,"")}catch(g){en(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&&M1(a,i),Wg(o,l);var d=Wg(o,i);for(l=0;l<c.length;l+=2){var h=c[l],f=c[l+1];h==="style"?_1(a,f):h==="dangerouslySetInnerHTML"?L1(a,f):h==="children"?Oc(a,f):Tj(a,h,f,d)}switch(o){case"input":Fg(a,i);break;case"textarea":O1(a,i);break;case"select":var m=a._wrapperState.wasMultiple;a._wrapperState.wasMultiple=!!i.multiple;var p=i.value;p!=null?_l(a,!!i.multiple,p,!1):m!==!!i.multiple&&(i.defaultValue!=null?_l(a,!!i.multiple,i.defaultValue,!0):_l(a,!!i.multiple,i.multiple?[]:"",!1))}a[Hc]=i}catch(g){en(e,e.return,g)}}break;case 6:if(nr(n,e),Ar(e),r&4){if(e.stateNode===null)throw Error(Ne(162));a=e.stateNode,i=e.memoizedProps;try{a.nodeValue=i}catch(g){en(e,e.return,g)}}break;case 3:if(nr(n,e),Ar(e),r&4&&s!==null&&s.memoizedState.isDehydrated)try{_c(n.containerInfo)}catch(g){en(e,e.return,g)}break;case 4:nr(n,e),Ar(e);break;case 13:nr(n,e),Ar(e),a=e.child,a.flags&8192&&(i=a.memoizedState!==null,a.stateNode.isHidden=i,!i||a.alternate!==null&&a.alternate.memoizedState!==null||(cw=rn())),r&4&&d0(e);break;case 22:if(h=s!==null&&s.memoizedState!==null,e.mode&1?(Vn=(d=Vn)||h,nr(n,e),Vn=d):nr(n,e),Ar(e),r&8192){if(d=e.memoizedState!==null,(e.stateNode.isHidden=d)&&!h&&e.mode&1)for(Fe=e,h=e.child;h!==null;){for(f=Fe=h;Fe!==null;){switch(m=Fe,p=m.child,m.tag){case 0:case 11:case 14:case 15:wc(4,m,m.return);break;case 1:Ml(m,m.return);var x=m.stateNode;if(typeof x.componentWillUnmount=="function"){r=m,s=m.return;try{n=r,x.props=n.memoizedProps,x.state=n.memoizedState,x.componentWillUnmount()}catch(g){en(r,s,g)}}break;case 5:Ml(m,m.return);break;case 22:if(m.memoizedState!==null){h0(f);continue}}p!==null?(p.return=m,Fe=p):h0(f)}h=h.sibling}e:for(h=null,f=e;;){if(f.tag===5){if(h===null){h=f;try{a=f.stateNode,d?(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=F1("display",l))}catch(g){en(e,e.return,g)}}}else if(f.tag===6){if(h===null)try{f.stateNode.nodeValue=d?"":f.memoizedProps}catch(g){en(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:nr(n,e),Ar(e),r&4&&d0(e);break;case 21:break;default:nr(n,e),Ar(e)}}function Ar(e){var n=e.flags;if(n&2){try{e:{for(var s=e.return;s!==null;){if(dA(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&&(Oc(a,""),r.flags&=-33);var i=c0(e);jx(e,i,a);break;case 3:case 4:var l=r.stateNode.containerInfo,o=c0(e);vx(e,o,l);break;default:throw Error(Ne(161))}}catch(c){en(e,e.return,c)}e.flags&=-3}n&4096&&(e.flags&=-4097)}function BL(e,n,s){Fe=e,fA(e)}function fA(e,n,s){for(var r=(e.mode&1)!==0;Fe!==null;){var a=Fe,i=a.child;if(a.tag===22&&r){var l=a.memoizedState!==null||fu;if(!l){var o=a.alternate,c=o!==null&&o.memoizedState!==null||Vn;o=fu;var d=Vn;if(fu=l,(Vn=c)&&!d)for(Fe=a;Fe!==null;)l=Fe,c=l.child,l.tag===22&&l.memoizedState!==null?f0(a):c!==null?(c.return=l,Fe=c):f0(a);for(;i!==null;)Fe=i,fA(i),i=i.sibling;Fe=a,fu=o,Vn=d}u0(e)}else a.subtreeFlags&8772&&i!==null?(i.return=a,Fe=i):u0(e)}}function u0(e){for(;Fe!==null;){var n=Fe;if(n.flags&8772){var s=n.alternate;try{if(n.flags&8772)switch(n.tag){case 0:case 11:case 15:Vn||_f(5,n);break;case 1:var r=n.stateNode;if(n.flags&4&&!Vn)if(s===null)r.componentDidMount();else{var a=n.elementType===n.type?s.memoizedProps:sr(n.type,s.memoizedProps);r.componentDidUpdate(a,s.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var i=n.updateQueue;i!==null&&Yk(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}Yk(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 d=n.alternate;if(d!==null){var h=d.memoizedState;if(h!==null){var f=h.dehydrated;f!==null&&_c(f)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(Ne(163))}Vn||n.flags&512&&xx(n)}catch(m){en(n,n.return,m)}}if(n===e){Fe=null;break}if(s=n.sibling,s!==null){s.return=n.return,Fe=s;break}Fe=n.return}}function h0(e){for(;Fe!==null;){var n=Fe;if(n===e){Fe=null;break}var s=n.sibling;if(s!==null){s.return=n.return,Fe=s;break}Fe=n.return}}function f0(e){for(;Fe!==null;){var n=Fe;try{switch(n.tag){case 0:case 11:case 15:var s=n.return;try{_f(4,n)}catch(c){en(n,s,c)}break;case 1:var r=n.stateNode;if(typeof r.componentDidMount=="function"){var a=n.return;try{r.componentDidMount()}catch(c){en(n,a,c)}}var i=n.return;try{xx(n)}catch(c){en(n,i,c)}break;case 5:var l=n.return;try{xx(n)}catch(c){en(n,l,c)}}}catch(c){en(n,n.return,c)}if(n===e){Fe=null;break}var o=n.sibling;if(o!==null){o.return=n.return,Fe=o;break}Fe=n.return}}var WL=Math.ceil,Dh=ba.ReactCurrentDispatcher,lw=ba.ReactCurrentOwner,Qs=ba.ReactCurrentBatchConfig,jt=0,Tn=null,hn=null,_n=0,ys=0,Ol=ui(0),yn=0,Qc=null,Ki=0,zf=0,ow=0,yc=null,os=null,cw=0,so=1/0,na=null,Lh=!1,wx=null,Ga=null,mu=!1,_a=null,Fh=0,bc=0,yx=null,Xu=-1,Zu=0;function ns(){return jt&6?rn():Xu!==-1?Xu:Xu=rn()}function qa(e){return e.mode&1?jt&2&&_n!==0?_n&-_n:CL.transition!==null?(Zu===0&&(Zu=J1()),Zu):(e=Nt,e!==0||(e=window.event,e=e===void 0?16:rE(e.type)),e):1}function dr(e,n,s,r){if(50<bc)throw bc=0,yx=null,Error(Ne(185));Sd(e,s,r),(!(jt&2)||e!==Tn)&&(e===Tn&&(!(jt&2)&&(zf|=s),yn===4&&Da(e,_n)),fs(e,r),s===1&&jt===0&&!(n.mode&1)&&(so=rn()+500,Df&&hi()))}function fs(e,n){var s=e.callbackNode;CD(e,n);var r=yh(e,e===Tn?_n:0);if(r===0)s!==null&&bk(s),e.callbackNode=null,e.callbackPriority=0;else if(n=r&-r,e.callbackPriority!==n){if(s!=null&&bk(s),n===1)e.tag===0?SL(m0.bind(null,e)):kE(m0.bind(null,e)),yL(function(){!(jt&6)&&hi()}),s=null;else{switch(X1(r)){case 1:s=Oj;break;case 4:s=Y1;break;case 16:s=wh;break;case 536870912:s=Q1;break;default:s=wh}s=yA(s,mA.bind(null,e))}e.callbackPriority=n,e.callbackNode=s}}function mA(e,n){if(Xu=-1,Zu=0,jt&6)throw Error(Ne(327));var s=e.callbackNode;if(Hl()&&e.callbackNode!==s)return null;var r=yh(e,e===Tn?_n:0);if(r===0)return null;if(r&30||r&e.expiredLanes||n)n=_h(e,r);else{n=r;var a=jt;jt|=2;var i=gA();(Tn!==e||_n!==n)&&(na=null,so=rn()+500,Li(e,n));do try{VL();break}catch(o){pA(e,o)}while(!0);qj(),Dh.current=i,jt=a,hn!==null?n=0:(Tn=null,_n=0,n=yn)}if(n!==0){if(n===2&&(a=qg(e),a!==0&&(r=a,n=bx(e,a))),n===1)throw s=Qc,Li(e,0),Da(e,r),fs(e,rn()),s;if(n===6)Da(e,r);else{if(a=e.current.alternate,!(r&30)&&!HL(a)&&(n=_h(e,r),n===2&&(i=qg(e),i!==0&&(r=i,n=bx(e,i))),n===1))throw s=Qc,Li(e,0),Da(e,r),fs(e,rn()),s;switch(e.finishedWork=a,e.finishedLanes=r,n){case 0:case 1:throw Error(Ne(345));case 2:Ai(e,os,na);break;case 3:if(Da(e,r),(r&130023424)===r&&(n=cw+500-rn(),10<n)){if(yh(e,0)!==0)break;if(a=e.suspendedLanes,(a&r)!==r){ns(),e.pingedLanes|=e.suspendedLanes&a;break}e.timeoutHandle=nx(Ai.bind(null,e,os,na),n);break}Ai(e,os,na);break;case 4:if(Da(e,r),(r&4194240)===r)break;for(n=e.eventTimes,a=-1;0<r;){var l=31-cr(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*WL(r/1960))-r,10<r){e.timeoutHandle=nx(Ai.bind(null,e,os,na),r);break}Ai(e,os,na);break;case 5:Ai(e,os,na);break;default:throw Error(Ne(329))}}}return fs(e,rn()),e.callbackNode===s?mA.bind(null,e):null}function bx(e,n){var s=yc;return e.current.memoizedState.isDehydrated&&(Li(e,n).flags|=256),e=_h(e,n),e!==2&&(n=os,os=s,n!==null&&kx(n)),e}function kx(e){os===null?os=e:os.push.apply(os,e)}function HL(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(!fr(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 Da(e,n){for(n&=~ow,n&=~zf,e.suspendedLanes|=n,e.pingedLanes&=~n,e=e.expirationTimes;0<n;){var s=31-cr(n),r=1<<s;e[s]=-1,n&=~r}}function m0(e){if(jt&6)throw Error(Ne(327));Hl();var n=yh(e,0);if(!(n&1))return fs(e,rn()),null;var s=_h(e,n);if(e.tag!==0&&s===2){var r=qg(e);r!==0&&(n=r,s=bx(e,r))}if(s===1)throw s=Qc,Li(e,0),Da(e,n),fs(e,rn()),s;if(s===6)throw Error(Ne(345));return e.finishedWork=e.current.alternate,e.finishedLanes=n,Ai(e,os,na),fs(e,rn()),null}function dw(e,n){var s=jt;jt|=1;try{return e(n)}finally{jt=s,jt===0&&(so=rn()+500,Df&&hi())}}function Vi(e){_a!==null&&_a.tag===0&&!(jt&6)&&Hl();var n=jt;jt|=1;var s=Qs.transition,r=Nt;try{if(Qs.transition=null,Nt=1,e)return e()}finally{Nt=r,Qs.transition=s,jt=n,!(jt&6)&&hi()}}function uw(){ys=Ol.current,Ft(Ol)}function Li(e,n){e.finishedWork=null,e.finishedLanes=0;var s=e.timeoutHandle;if(s!==-1&&(e.timeoutHandle=-1,wL(s)),hn!==null)for(s=hn.return;s!==null;){var r=s;switch(Kj(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Ch();break;case 3:to(),Ft(us),Ft(qn),ew();break;case 5:Zj(r);break;case 4:to();break;case 13:Ft(Gt);break;case 19:Ft(Gt);break;case 10:Yj(r.type._context);break;case 22:case 23:uw()}s=s.return}if(Tn=e,hn=e=Ya(e.current,null),_n=ys=n,yn=0,Qc=null,ow=zf=Ki=0,os=yc=null,Ri!==null){for(n=0;n<Ri.length;n++)if(s=Ri[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}Ri=null}return e}function pA(e,n){do{var s=hn;try{if(qj(),Yu.current=Oh,Mh){for(var r=qt.memoizedState;r!==null;){var a=r.queue;a!==null&&(a.pending=null),r=r.next}Mh=!1}if(Hi=0,En=jn=qt=null,jc=!1,Gc=0,lw.current=null,s===null||s.return===null){yn=1,Qc=n,hn=null;break}e:{var i=e,l=s.return,o=s,c=n;if(n=_n,o.flags|=32768,c!==null&&typeof c=="object"&&typeof c.then=="function"){var d=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=t0(l);if(p!==null){p.flags&=-257,n0(p,l,o,i,n),p.mode&1&&e0(i,d,n),n=p,c=d;var x=n.updateQueue;if(x===null){var g=new Set;g.add(c),n.updateQueue=g}else x.add(c);break e}else{if(!(n&1)){e0(i,d,n),hw();break e}c=Error(Ne(426))}}else if(Wt&&o.mode&1){var y=t0(l);if(y!==null){!(y.flags&65536)&&(y.flags|=256),n0(y,l,o,i,n),Vj(no(c,o));break e}}i=c=no(c,o),yn!==4&&(yn=2),yc===null?yc=[i]:yc.push(i),i=l;do{switch(i.tag){case 3:i.flags|=65536,n&=-n,i.lanes|=n;var j=XE(i,c,n);qk(i,j);break e;case 1:o=c;var v=i.type,w=i.stateNode;if(!(i.flags&128)&&(typeof v.getDerivedStateFromError=="function"||w!==null&&typeof w.componentDidCatch=="function"&&(Ga===null||!Ga.has(w)))){i.flags|=65536,n&=-n,i.lanes|=n;var N=ZE(i,o,n);qk(i,N);break e}}i=i.return}while(i!==null)}vA(s)}catch(k){n=k,hn===s&&s!==null&&(hn=s=s.return);continue}break}while(!0)}function gA(){var e=Dh.current;return Dh.current=Oh,e===null?Oh:e}function hw(){(yn===0||yn===3||yn===2)&&(yn=4),Tn===null||!(Ki&268435455)&&!(zf&268435455)||Da(Tn,_n)}function _h(e,n){var s=jt;jt|=2;var r=gA();(Tn!==e||_n!==n)&&(na=null,Li(e,n));do try{KL();break}catch(a){pA(e,a)}while(!0);if(qj(),jt=s,Dh.current=r,hn!==null)throw Error(Ne(261));return Tn=null,_n=0,yn}function KL(){for(;hn!==null;)xA(hn)}function VL(){for(;hn!==null&&!xD();)xA(hn)}function xA(e){var n=wA(e.alternate,e,ys);e.memoizedProps=e.pendingProps,n===null?vA(e):hn=n,lw.current=null}function vA(e){var n=e;do{var s=n.alternate;if(e=n.return,n.flags&32768){if(s=_L(s,n),s!==null){s.flags&=32767,hn=s;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{yn=6,hn=null;return}}else if(s=FL(s,n,ys),s!==null){hn=s;return}if(n=n.sibling,n!==null){hn=n;return}hn=n=e}while(n!==null);yn===0&&(yn=5)}function Ai(e,n,s){var r=Nt,a=Qs.transition;try{Qs.transition=null,Nt=1,GL(e,n,s,r)}finally{Qs.transition=a,Nt=r}return null}function GL(e,n,s,r){do Hl();while(_a!==null);if(jt&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(ED(e,i),e===Tn&&(hn=Tn=null,_n=0),!(s.subtreeFlags&2064)&&!(s.flags&2064)||mu||(mu=!0,yA(wh,function(){return Hl(),null})),i=(s.flags&15990)!==0,s.subtreeFlags&15990||i){i=Qs.transition,Qs.transition=null;var l=Nt;Nt=1;var o=jt;jt|=4,lw.current=null,UL(e,s),hA(s,e),fL(ex),bh=!!Zg,ex=Zg=null,e.current=s,BL(s),vD(),jt=o,Nt=l,Qs.transition=i}else e.current=s;if(mu&&(mu=!1,_a=e,Fh=a),i=e.pendingLanes,i===0&&(Ga=null),yD(s.stateNode),fs(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(Lh)throw Lh=!1,e=wx,wx=null,e;return Fh&1&&e.tag!==0&&Hl(),i=e.pendingLanes,i&1?e===yx?bc++:(bc=0,yx=e):bc=0,hi(),null}function Hl(){if(_a!==null){var e=X1(Fh),n=Qs.transition,s=Nt;try{if(Qs.transition=null,Nt=16>e?16:e,_a===null)var r=!1;else{if(e=_a,_a=null,Fh=0,jt&6)throw Error(Ne(331));var a=jt;for(jt|=4,Fe=e.current;Fe!==null;){var i=Fe,l=i.child;if(Fe.flags&16){var o=i.deletions;if(o!==null){for(var c=0;c<o.length;c++){var d=o[c];for(Fe=d;Fe!==null;){var h=Fe;switch(h.tag){case 0:case 11:case 15:wc(8,h,i)}var f=h.child;if(f!==null)f.return=h,Fe=f;else for(;Fe!==null;){h=Fe;var m=h.sibling,p=h.return;if(cA(h),h===d){Fe=null;break}if(m!==null){m.return=p,Fe=m;break}Fe=p}}}var x=i.alternate;if(x!==null){var g=x.child;if(g!==null){x.child=null;do{var y=g.sibling;g.sibling=null,g=y}while(g!==null)}}Fe=i}}if(i.subtreeFlags&2064&&l!==null)l.return=i,Fe=l;else e:for(;Fe!==null;){if(i=Fe,i.flags&2048)switch(i.tag){case 0:case 11:case 15:wc(9,i,i.return)}var j=i.sibling;if(j!==null){j.return=i.return,Fe=j;break e}Fe=i.return}}var v=e.current;for(Fe=v;Fe!==null;){l=Fe;var w=l.child;if(l.subtreeFlags&2064&&w!==null)w.return=l,Fe=w;else e:for(l=v;Fe!==null;){if(o=Fe,o.flags&2048)try{switch(o.tag){case 0:case 11:case 15:_f(9,o)}}catch(k){en(o,o.return,k)}if(o===l){Fe=null;break e}var N=o.sibling;if(N!==null){N.return=o.return,Fe=N;break e}Fe=o.return}}if(jt=a,hi(),Fr&&typeof Fr.onPostCommitFiberRoot=="function")try{Fr.onPostCommitFiberRoot(If,e)}catch{}r=!0}return r}finally{Nt=s,Qs.transition=n}}return!1}function p0(e,n,s){n=no(s,n),n=XE(e,n,1),e=Va(e,n,1),n=ns(),e!==null&&(Sd(e,1,n),fs(e,n))}function en(e,n,s){if(e.tag===3)p0(e,e,s);else for(;n!==null;){if(n.tag===3){p0(n,e,s);break}else if(n.tag===1){var r=n.stateNode;if(typeof n.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(Ga===null||!Ga.has(r))){e=no(s,e),e=ZE(n,e,1),n=Va(n,e,1),e=ns(),n!==null&&(Sd(n,1,e),fs(n,e));break}}n=n.return}}function qL(e,n,s){var r=e.pingCache;r!==null&&r.delete(n),n=ns(),e.pingedLanes|=e.suspendedLanes&s,Tn===e&&(_n&s)===s&&(yn===4||yn===3&&(_n&130023424)===_n&&500>rn()-cw?Li(e,0):ow|=s),fs(e,n)}function jA(e,n){n===0&&(e.mode&1?(n=ru,ru<<=1,!(ru&130023424)&&(ru=4194304)):n=1);var s=ns();e=xa(e,n),e!==null&&(Sd(e,n,s),fs(e,s))}function YL(e){var n=e.memoizedState,s=0;n!==null&&(s=n.retryLane),jA(e,s)}function QL(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),jA(e,s)}var wA;wA=function(e,n,s){if(e!==null)if(e.memoizedProps!==n.pendingProps||us.current)cs=!0;else{if(!(e.lanes&s)&&!(n.flags&128))return cs=!1,LL(e,n,s);cs=!!(e.flags&131072)}else cs=!1,Wt&&n.flags&1048576&&NE(n,$h,n.index);switch(n.lanes=0,n.tag){case 2:var r=n.type;Ju(e,n),e=n.pendingProps;var a=Xl(n,qn.current);Wl(n,s),a=nw(null,n,r,e,a,s);var i=sw();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,hs(r)?(i=!0,Eh(n)):i=!1,n.memoizedState=a.state!==null&&a.state!==void 0?a.state:null,Jj(n),a.updater=Ff,n.stateNode=a,a._reactInternals=n,cx(n,r,e,s),n=hx(null,n,r,!0,i,s)):(n.tag=0,Wt&&i&&Hj(n),Zn(null,n,a,s),n=n.child),n;case 16:r=n.elementType;e:{switch(Ju(e,n),e=n.pendingProps,a=r._init,r=a(r._payload),n.type=r,a=n.tag=XL(r),e=sr(r,e),a){case 0:n=ux(null,n,r,e,s);break e;case 1:n=a0(null,n,r,e,s);break e;case 11:n=s0(null,n,r,e,s);break e;case 14:n=r0(null,n,r,sr(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:sr(r,a),ux(e,n,r,a,s);case 1:return r=n.type,a=n.pendingProps,a=n.elementType===r?a:sr(r,a),a0(e,n,r,a,s);case 3:e:{if(sA(n),e===null)throw Error(Ne(387));r=n.pendingProps,i=n.memoizedState,a=i.element,TE(e,n),Rh(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=no(Error(Ne(423)),n),n=i0(e,n,r,s,a);break e}else if(r!==a){a=no(Error(Ne(424)),n),n=i0(e,n,r,s,a);break e}else for(Ns=Ka(n.stateNode.containerInfo.firstChild),Cs=n,Wt=!0,ar=null,s=AE(n,null,r,s),n.child=s;s;)s.flags=s.flags&-3|4096,s=s.sibling;else{if(Zl(),r===a){n=va(e,n,s);break e}Zn(e,n,r,s)}n=n.child}return n;case 5:return IE(n),e===null&&ix(n),r=n.type,a=n.pendingProps,i=e!==null?e.memoizedProps:null,l=a.children,tx(r,a)?l=null:i!==null&&tx(r,i)&&(n.flags|=32),nA(e,n),Zn(e,n,l,s),n.child;case 6:return e===null&&ix(n),null;case 13:return rA(e,n,s);case 4:return Xj(n,n.stateNode.containerInfo),r=n.pendingProps,e===null?n.child=eo(n,null,r,s):Zn(e,n,r,s),n.child;case 11:return r=n.type,a=n.pendingProps,a=n.elementType===r?a:sr(r,a),s0(e,n,r,a,s);case 7:return Zn(e,n,n.pendingProps,s),n.child;case 8:return Zn(e,n,n.pendingProps.children,s),n.child;case 12:return Zn(e,n,n.pendingProps.children,s),n.child;case 10:e:{if(r=n.type._context,a=n.pendingProps,i=n.memoizedProps,l=a.value,Rt(Th,r._currentValue),r._currentValue=l,i!==null)if(fr(i.value,l)){if(i.children===a.children&&!us.current){n=va(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=ua(-1,s&-s),c.tag=2;var d=i.updateQueue;if(d!==null){d=d.shared;var h=d.pending;h===null?c.next=c:(c.next=h.next,h.next=c),d.pending=c}}i.lanes|=s,c=i.alternate,c!==null&&(c.lanes|=s),lx(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),lx(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}Zn(e,n,a.children,s),n=n.child}return n;case 9:return a=n.type,r=n.pendingProps.children,Wl(n,s),a=Xs(a),r=r(a),n.flags|=1,Zn(e,n,r,s),n.child;case 14:return r=n.type,a=sr(r,n.pendingProps),a=sr(r.type,a),r0(e,n,r,a,s);case 15:return eA(e,n,n.type,n.pendingProps,s);case 17:return r=n.type,a=n.pendingProps,a=n.elementType===r?a:sr(r,a),Ju(e,n),n.tag=1,hs(r)?(e=!0,Eh(n)):e=!1,Wl(n,s),JE(n,r,a),cx(n,r,a,s),hx(null,n,r,!0,e,s);case 19:return aA(e,n,s);case 22:return tA(e,n,s)}throw Error(Ne(156,n.tag))};function yA(e,n){return q1(e,n)}function JL(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 Ys(e,n,s,r){return new JL(e,n,s,r)}function fw(e){return e=e.prototype,!(!e||!e.isReactComponent)}function XL(e){if(typeof e=="function")return fw(e)?1:0;if(e!=null){if(e=e.$$typeof,e===Rj)return 11;if(e===Pj)return 14}return 2}function Ya(e,n){var s=e.alternate;return s===null?(s=Ys(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 eh(e,n,s,r,a,i){var l=2;if(r=e,typeof e=="function")fw(e)&&(l=1);else if(typeof e=="string")l=5;else e:switch(e){case Sl:return Fi(s.children,a,i,n);case Ij:l=8,a|=8;break;case Pg:return e=Ys(12,s,n,a|2),e.elementType=Pg,e.lanes=i,e;case Mg:return e=Ys(13,s,n,a),e.elementType=Mg,e.lanes=i,e;case Og:return e=Ys(19,s,n,a),e.elementType=Og,e.lanes=i,e;case I1:return Uf(s,a,i,n);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case $1:l=10;break e;case T1:l=9;break e;case Rj:l=11;break e;case Pj:l=14;break e;case Pa:l=16,r=null;break e}throw Error(Ne(130,e==null?e:typeof e,""))}return n=Ys(l,s,n,a),n.elementType=e,n.type=r,n.lanes=i,n}function Fi(e,n,s,r){return e=Ys(7,e,r,n),e.lanes=s,e}function Uf(e,n,s,r){return e=Ys(22,e,r,n),e.elementType=I1,e.lanes=s,e.stateNode={isHidden:!1},e}function jp(e,n,s){return e=Ys(6,e,null,n),e.lanes=s,e}function wp(e,n,s){return n=Ys(4,e.children!==null?e.children:[],e.key,n),n.lanes=s,n.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},n}function ZL(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=ep(0),this.expirationTimes=ep(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=ep(0),this.identifierPrefix=r,this.onRecoverableError=a,this.mutableSourceEagerHydrationData=null}function mw(e,n,s,r,a,i,l,o,c){return e=new ZL(e,n,s,o,c),n===1?(n=1,i===!0&&(n|=8)):n=0,i=Ys(3,null,null,n),e.current=i,i.stateNode=e,i.memoizedState={element:r,isDehydrated:s,cache:null,transitions:null,pendingSuspenseBoundaries:null},Jj(i),e}function eF(e,n,s){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:Nl,key:r==null?null:""+r,children:e,containerInfo:n,implementation:s}}function bA(e){if(!e)return ei;e=e._reactInternals;e:{if(nl(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(hs(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(hs(s))return bE(e,s,n)}return n}function kA(e,n,s,r,a,i,l,o,c){return e=mw(s,r,!0,e,a,i,l,o,c),e.context=bA(null),s=e.current,r=ns(),a=qa(s),i=ua(r,a),i.callback=n??null,Va(s,i,a),e.current.lanes=a,Sd(e,a,r),fs(e,r),e}function Bf(e,n,s,r){var a=n.current,i=ns(),l=qa(a);return s=bA(s),n.context===null?n.context=s:n.pendingContext=s,n=ua(i,l),n.payload={element:e},r=r===void 0?null:r,r!==null&&(n.callback=r),e=Va(a,n,l),e!==null&&(dr(e,a,l,i),qu(e,a,l)),l}function zh(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 g0(e,n){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var s=e.retryLane;e.retryLane=s!==0&&s<n?s:n}}function pw(e,n){g0(e,n),(e=e.alternate)&&g0(e,n)}function tF(){return null}var NA=typeof reportError=="function"?reportError:function(e){console.error(e)};function gw(e){this._internalRoot=e}Wf.prototype.render=gw.prototype.render=function(e){var n=this._internalRoot;if(n===null)throw Error(Ne(409));Bf(e,n,null,null)};Wf.prototype.unmount=gw.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var n=e.containerInfo;Vi(function(){Bf(null,e,null,null)}),n[ga]=null}};function Wf(e){this._internalRoot=e}Wf.prototype.unstable_scheduleHydration=function(e){if(e){var n=tE();e={blockedOn:null,target:e,priority:n};for(var s=0;s<Oa.length&&n!==0&&n<Oa[s].priority;s++);Oa.splice(s,0,e),s===0&&sE(e)}};function xw(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function Hf(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function x0(){}function nF(e,n,s,r,a){if(a){if(typeof r=="function"){var i=r;r=function(){var d=zh(l);i.call(d)}}var l=kA(n,r,e,0,null,!1,!1,"",x0);return e._reactRootContainer=l,e[ga]=l.current,Bc(e.nodeType===8?e.parentNode:e),Vi(),l}for(;a=e.lastChild;)e.removeChild(a);if(typeof r=="function"){var o=r;r=function(){var d=zh(c);o.call(d)}}var c=mw(e,0,!1,null,null,!1,!1,"",x0);return e._reactRootContainer=c,e[ga]=c.current,Bc(e.nodeType===8?e.parentNode:e),Vi(function(){Bf(n,c,s,r)}),c}function Kf(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=zh(l);o.call(c)}}Bf(n,l,e,a)}else l=nF(s,n,e,a,r);return zh(l)}Z1=function(e){switch(e.tag){case 3:var n=e.stateNode;if(n.current.memoizedState.isDehydrated){var s=ic(n.pendingLanes);s!==0&&(Dj(n,s|1),fs(n,rn()),!(jt&6)&&(so=rn()+500,hi()))}break;case 13:Vi(function(){var r=xa(e,1);if(r!==null){var a=ns();dr(r,e,1,a)}}),pw(e,1)}};Lj=function(e){if(e.tag===13){var n=xa(e,134217728);if(n!==null){var s=ns();dr(n,e,134217728,s)}pw(e,134217728)}};eE=function(e){if(e.tag===13){var n=qa(e),s=xa(e,n);if(s!==null){var r=ns();dr(s,e,n,r)}pw(e,n)}};tE=function(){return Nt};nE=function(e,n){var s=Nt;try{return Nt=e,n()}finally{Nt=s}};Kg=function(e,n,s){switch(n){case"input":if(Fg(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=Of(r);if(!a)throw Error(Ne(90));P1(r),Fg(r,a)}}}break;case"textarea":O1(e,s);break;case"select":n=s.value,n!=null&&_l(e,!!s.multiple,n,!1)}};B1=dw;W1=Vi;var sF={usingClientEntryPoint:!1,Events:[Ed,$l,Of,z1,U1,dw]},Yo={findFiberByHostInstance:Ii,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},rF={bundleType:Yo.bundleType,version:Yo.version,rendererPackageName:Yo.rendererPackageName,rendererConfig:Yo.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:ba.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=V1(e),e===null?null:e.stateNode},findFiberByHostInstance:Yo.findFiberByHostInstance||tF,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 pu=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!pu.isDisabled&&pu.supportsFiber)try{If=pu.inject(rF),Fr=pu}catch{}}Rs.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=sF;Rs.createPortal=function(e,n){var s=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!xw(n))throw Error(Ne(200));return eF(e,n,null,s)};Rs.createRoot=function(e,n){if(!xw(e))throw Error(Ne(299));var s=!1,r="",a=NA;return n!=null&&(n.unstable_strictMode===!0&&(s=!0),n.identifierPrefix!==void 0&&(r=n.identifierPrefix),n.onRecoverableError!==void 0&&(a=n.onRecoverableError)),n=mw(e,1,!1,null,null,s,!1,r,a),e[ga]=n.current,Bc(e.nodeType===8?e.parentNode:e),new gw(n)};Rs.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=V1(n),e=e===null?null:e.stateNode,e};Rs.flushSync=function(e){return Vi(e)};Rs.hydrate=function(e,n,s){if(!Hf(n))throw Error(Ne(200));return Kf(null,e,n,!0,s)};Rs.hydrateRoot=function(e,n,s){if(!xw(e))throw Error(Ne(405));var r=s!=null&&s.hydratedSources||null,a=!1,i="",l=NA;if(s!=null&&(s.unstable_strictMode===!0&&(a=!0),s.identifierPrefix!==void 0&&(i=s.identifierPrefix),s.onRecoverableError!==void 0&&(l=s.onRecoverableError)),n=kA(n,null,e,1,s??null,a,!1,i,l),e[ga]=n.current,Bc(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 Wf(n)};Rs.render=function(e,n,s){if(!Hf(n))throw Error(Ne(200));return Kf(null,e,n,!1,s)};Rs.unmountComponentAtNode=function(e){if(!Hf(e))throw Error(Ne(40));return e._reactRootContainer?(Vi(function(){Kf(null,null,e,!1,function(){e._reactRootContainer=null,e[ga]=null})}),!0):!1};Rs.unstable_batchedUpdates=dw;Rs.unstable_renderSubtreeIntoContainer=function(e,n,s,r){if(!Hf(s))throw Error(Ne(200));if(e==null||e._reactInternals===void 0)throw Error(Ne(38));return Kf(e,n,s,!1,r)};Rs.version="18.3.1-next-f1338f8080-20240426";function SA(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(SA)}catch(e){console.error(e)}}SA(),S1.exports=Rs;var ko=S1.exports,CA,v0=ko;CA=v0.createRoot,v0.hydrateRoot;const aF=["use","new","stop","quiet"];function j0(e){return aF.includes(e)}function iF(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 lF=e=>e.replace(/^plugin-/,"").replace(/[-_]+/g," ").replace(/^./,n=>n.toUpperCase());function oF(e){return e.map(n=>({group:`From ${lF(n.plugin)}`,name:n.name,...n.args?{args:n.args}:{},desc:n.description,source:"plugin"}))}const cF=e=>!!(e.args&&e.args.startsWith("<"));let Uh=[];const Nx=new Set;function dF(e){const n=e??[];JSON.stringify(n)!==JSON.stringify(Uh)&&(Uh=n,Nx.forEach(s=>s()))}function uF(){return u.useSyncExternalStore(e=>(Nx.add(e),()=>Nx.delete(e)),()=>Uh,()=>Uh)}var hF=Object.defineProperty,No=(e,n)=>hF(e,"name",{value:n,configurable:!0}),EA=!!(typeof window<"u"&&window.document&&window.document.createElement);function We(e,n,{checkForDefaultPrevented:s=!0}={}){return No(function(a){if(e==null||e(a),s===!1||!a||!a.defaultPrevented)return n==null?void 0:n(a)},"handleEvent")}No(We,"composeEventHandlers");function fF(e){var n;if(!EA)throw new Error("Cannot access window outside of the DOM");return((n=e==null?void 0:e.ownerDocument)==null?void 0:n.defaultView)??window}No(fF,"getOwnerWindow");function Sx(e){if(!EA)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}No(Sx,"getOwnerDocument");function AA(e,n=!1){const{activeElement:s}=Sx(e);if(!(s!=null&&s.nodeName))return null;if($A(s)&&s.contentDocument)return AA(s.contentDocument.body,n);if(n){const r=s.getAttribute("aria-activedescendant");if(r){const a=Sx(s).getElementById(r);if(a)return a}}return s}No(AA,"getActiveElement");function $A(e){return e.tagName==="IFRAME"}No($A,"isFrame");var mF=Object.defineProperty,vw=(e,n)=>mF(e,"name",{value:n,configurable:!0});function Cx(e,n){if(typeof e=="function")return e(n);e!=null&&(e.current=n)}vw(Cx,"setRef");function TA(...e){return n=>{let s=!1;const r=e.map(a=>{const i=Cx(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():Cx(e[a],null)}}}}vw(TA,"composeRefs");function Tt(...e){return u.useCallback(TA(...e),e)}vw(Tt,"useComposedRefs");var pF=Object.defineProperty,qs=(e,n)=>pF(e,"name",{value:n,configurable:!0});function gF(e,n){const s=u.createContext(n);s.displayName=e+"Context";const r=qs(i=>{const{children:l,...o}=i,c=u.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=u.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(gF,"createContext");function br(e,n=[]){let s=[];function r(i,l){const o=u.createContext(l);o.displayName=i+"Context";const c=s.length;s=[...s,l];const d=qs(f=>{var j;const{scope:m,children:p,...x}=f,g=((j=m==null?void 0:m[e])==null?void 0:j[c])||o,y=u.useMemo(()=>x,Object.values(x));return t.jsx(g.Provider,{value:y,children:p})},"Provider");d.displayName=i+"Provider";function h(f,m,p={}){var j;const{optional:x=!1}=p,g=((j=m==null?void 0:m[e])==null?void 0:j[c])||o,y=u.useContext(g);if(y)return y;if(l!==void 0)return l;if(!x)throw new Error(`\`${f}\` must be used within \`${i}\``)}return qs(h,"useContext"),[d,h]}qs(r,"createContext");const a=qs(()=>{const i=s.map(l=>u.createContext(l));return qs(function(o){const c=(o==null?void 0:o[e])||i;return u.useMemo(()=>({[`__scope${e}`]:{...o,[e]:c}}),[o,c])},"useScope")},"createScope");return a.scopeName=e,[r,IA(a,...n)]}qs(br,"createContextScope");function IA(...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:d})=>{const f=c(i)[`__scope${d}`];return{...o,...f}},{});return u.useMemo(()=>({[`__scope${n.scopeName}`]:l}),[l])},"useComposedScopes")},"createScope");return s.scopeName=n.scopeName,s}qs(IA,"composeContextScopes");var xF=Object.defineProperty,kr=(e,n)=>xF(e,"name",{value:n,configurable:!0});function ti(e){const n=u.forwardRef((s,r)=>{let{children:a,...i}=s,l=null,o=!1;const c=[];Ex(a)&&typeof gu=="function"&&(a=gu(a._payload)),u.Children.forEach(a,m=>{var p;if(DA(m)){o=!0;const x=m;let g="child"in x.props?x.props.child:x.props.children;Ex(g)&&typeof gu=="function"&&(g=gu(g._payload)),l=vF(x,g),c.push((p=l==null?void 0:l.props)==null?void 0:p.children)}else c.push(m)}),l?l=u.cloneElement(l,void 0,c):!o&&u.Children.count(a)===1&&u.isValidElement(a)&&(l=a);const d=l?OA(l):void 0,h=Tt(r,d);if(!l){if(a||a===0)throw new Error(o?yF(e):wF(e));return a}const f=MA(i,l.props??{});return l.type!==u.Fragment&&(f.ref=r?h:d),u.cloneElement(l,f)});return n.displayName=`${e}.Slot`,n}kr(ti,"createSlot");var RA=Symbol.for("radix.slottable");function PA(e){const n=kr(s=>"child"in s?s.children(s.child):s.children,"Slottable");return n.displayName=`${e}.Slottable`,n.__radixId=RA,n}kr(PA,"createSlottable");var vF=kr((e,n)=>{if("child"in e.props){const s=e.props.child;return u.isValidElement(s)?u.cloneElement(s,void 0,e.props.children(s.props.children)):null}return u.isValidElement(n)?n:null},"getSlottableElementFromSlottable");function MA(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}}kr(MA,"mergeProps");function OA(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)}kr(OA,"getElementRef");function DA(e){return u.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===RA}kr(DA,"isSlottable");var jF=Symbol.for("react.lazy");function Ex(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===jF&&"_payload"in e&&LA(e._payload)}kr(Ex,"isLazyComponent");function LA(e){return typeof e=="object"&&e!==null&&"then"in e}kr(LA,"isPromiseLike");var wF=kr(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),yF=kr(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),gu=wo[" use ".trim().toString()],bF=Object.defineProperty,An=(e,n)=>bF(e,"name",{value:n,configurable:!0});function Vf(e){const n=e+"CollectionProvider",[s,r]=br(n),[a,i]=s(n,{collectionRef:{current:null},itemMap:new Map}),l=An(g=>{const{scope:y,children:j}=g,v=u.useRef(null),w=u.useRef(new Map).current;return t.jsx(a,{scope:y,itemMap:w,collectionRef:v,children:j})},"CollectionProvider");l.displayName=n;const o=e+"CollectionSlot",c=ti(o),d=u.forwardRef((g,y)=>{const{scope:j,children:v}=g,w=i(o,j),N=Tt(y,w.collectionRef);return t.jsx(c,{ref:N,children:v})});d.displayName=o;const h=e+"CollectionItemSlot",f="data-radix-collection-item",m=ti(h),p=u.forwardRef((g,y)=>{const{scope:j,children:v,...w}=g,N=u.useRef(null),k=Tt(y,N),S=i(h,j);return u.useEffect(()=>(S.itemMap.set(N,{ref:N,...w}),()=>void S.itemMap.delete(N))),t.jsx(m,{[f]:"",ref:k,children:v})});p.displayName=h;function x(g){const y=i(e+"CollectionConsumer",g);return u.useCallback(()=>{const v=y.collectionRef.current;if(!v)return[];const w=Array.from(v.querySelectorAll(`[${f}]`));return Array.from(y.itemMap.values()).sort((S,b)=>w.indexOf(S.ref.current)-w.indexOf(b.ref.current))},[y.collectionRef,y.itemMap])}return An(x,"useCollection"),[{Provider:l,Slot:d,ItemSlot:p},x,r]}An(Vf,"createCollection");var w0=new WeakMap,dn,bs,yp=(bs=class extends Map{constructor(s){super(s);ck(this,dn);qm(this,dn,[...super.keys()]),w0.set(this,!0)}set(s,r){return w0.get(this)&&(this.has(s)?Bn(this,dn)[Bn(this,dn).indexOf(s)]=s:Bn(this,dn).push(s)),super.set(s,r),this}insert(s,r,a){const i=this.has(r),l=Bn(this,dn).length,o=jw(s);let c=o>=0?o:l+o;const d=c<0||c>=l?-1:c;if(d===this.size||i&&d===this.size-1||d===-1)return this.set(r,a),this;const h=this.size+(i?0:1);o<0&&c++;const f=[...Bn(this,dn)];let m,p=!1;for(let x=c;x<h;x++)if(c===x){let g=f[x];f[x]===r&&(g=f[x+1]),i&&this.delete(r),m=this.get(g),this.set(r,a)}else{!p&&f[x-1]===r&&(p=!0);const g=f[p?x:x-1],y=m;m=this.get(g),this.delete(g),this.set(g,y)}return this}with(s,r,a){const i=new bs(this);return i.insert(s,r,a),i}before(s){const r=Bn(this,dn).indexOf(s)-1;if(!(r<0))return this.entryAt(r)}setBefore(s,r,a){const i=Bn(this,dn).indexOf(s);return i===-1?this:this.insert(i,r,a)}after(s){let r=Bn(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=Bn(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 qm(this,dn,[]),super.clear()}delete(s){const r=super.delete(s);return r&&Bn(this,dn).splice(Bn(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=th(Bn(this,dn),s);if(r!==void 0)return this.get(r)}entryAt(s){const r=th(Bn(this,dn),s);if(r!==void 0)return[r,this.get(r)]}indexOf(s){return Bn(this,dn).indexOf(s)}keyAt(s){return th(Bn(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 bs(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 bs(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 bs(r)}toReversed(){const s=new bs;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 bs(r)}slice(s,r){const a=new bs;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,An(bs,"OrderedDict"),bs);function th(e,n){if("at"in Array.prototype)return Array.prototype.at.call(e,n);const s=FA(e,n);return s===-1?void 0:e[s]}An(th,"at");function FA(e,n){const s=e.length,r=jw(n),a=r>=0?r:s+r;return a<0||a>=s?-1:a}An(FA,"toSafeIndex");function jw(e){return e!==e||e===0?0:Math.trunc(e)}An(jw,"toSafeInteger");function kF(e){const n=e+"CollectionProvider",[s,r]=br(n),[a,i]=s(n,{collectionElement:null,collectionRef:{current:null},collectionRefObject:{current:null},itemMap:new yp,setItemMap:An(()=>{},"setItemMap")}),l=An(({state:w,...N})=>w?t.jsx(c,{...N,state:w}):t.jsx(o,{...N}),"CollectionProvider");l.displayName=n;const o=An(w=>{const N=y();return t.jsx(c,{...w,state:N})},"CollectionInit");o.displayName=n+"Init";const c=An(w=>{const{scope:N,children:k,state:S}=w,b=u.useRef(null),[C,$]=u.useState(null),A=Tt(b,$),[I,M]=S;return u.useEffect(()=>{if(!C)return;const O=UA(()=>{});return O.observe(C,{childList:!0,subtree:!0}),()=>{O.disconnect()}},[C]),t.jsx(a,{scope:N,itemMap:I,setItemMap:M,collectionRef:A,collectionRefObject:b,collectionElement:C,children:k})},"CollectionProviderImpl");c.displayName=n+"Impl";const d=e+"CollectionSlot",h=ti(d),f=u.forwardRef((w,N)=>{const{scope:k,children:S}=w,b=i(d,k),C=Tt(N,b.collectionRef);return t.jsx(h,{ref:C,children:S})});f.displayName=d;const m=e+"CollectionItemSlot",p="data-radix-collection-item",x=ti(m),g=u.forwardRef((w,N)=>{const{scope:k,children:S,...b}=w,C=u.useRef(null),[$,A]=u.useState(null),I=Tt(N,C,A),M=i(m,k),{setItemMap:O}=M,R=u.useRef(b);_A(R.current,b)||(R.current=b);const _=R.current;return u.useEffect(()=>{const z=_;return O(U=>$?U.has($)?U.set($,{...z,element:$}).toSorted(Ax):(U.set($,{...z,element:$}),U.toSorted(Ax)):U),()=>{O(U=>!$||!U.has($)?U:(U.delete($),new yp(U)))}},[$,_,O]),t.jsx(x,{[p]:"",ref:I,children:S})});g.displayName=m;function y(){return u.useState(new yp)}An(y,"useInitCollection");function j(w){const{itemMap:N}=i(e+"CollectionConsumer",w);return N}return An(j,"useCollection"),[{Provider:l,Slot:f,ItemSlot:g},{createCollectionScope:r,useCollection:j,useInitCollection:y}]}An(kF,"createCollection");function _A(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}An(_A,"shallowEqual");function zA(e,n){return!!(n.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_PRECEDING)}An(zA,"isElementPreceding");function Ax(e,n){return!e[1].element||!n[1].element?0:zA(e[1].element,n[1].element)?-1:1}An(Ax,"sortByDocumentPosition");function UA(e){return new MutationObserver(s=>{for(const r of s)if(r.type==="childList"){e();return}})}An(UA,"getChildListObserver");var NF=Object.defineProperty,SF=(e,n)=>NF(e,"name",{value:n,configurable:!0}),CF=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],St=CF.reduce((e,n)=>{const s=ti(`Primitive.${n}`),r=u.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 Gf(e,n){e&&ko.flushSync(()=>e.dispatchEvent(n))}SF(Gf,"dispatchDiscreteCustomEvent");var EF=Object.defineProperty,AF=(e,n)=>EF(e,"name",{value:n,configurable:!0});function ss(e){const n=u.useRef(e);return u.useEffect(()=>{n.current=e}),u.useMemo(()=>(...s)=>{var r;return(r=n.current)==null?void 0:r.call(n,...s)},[])}AF(ss,"useCallbackRef");var $F=Object.defineProperty,wn=(e,n)=>$F(e,"name",{value:n,configurable:!0}),$x="dismissableLayer.update",TF="dismissableLayer.pointerDownOutside",IF="dismissableLayer.focusOutside",y0,ww=u.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),qf=u.forwardRef(wn(function(n,s){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:a=!1,onEscapeKeyDown:i,onPointerDownOutside:l,onFocusOutside:o,onInteractOutside:c,onDismiss:d,...h}=n,f=u.useContext(ww),[m,p]=u.useState(null),x=(m==null?void 0:m.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,g]=u.useState({}),y=Tt(s,p),j=Array.from(f.layers),[v]=[...f.layersWithOutsidePointerEventsDisabled].slice(-1),w=v?j.indexOf(v):-1,N=m?j.indexOf(m):-1,k=f.layersWithOutsidePointerEventsDisabled.size>0,S=N>=w,b=u.useRef(!1),C=WA(M=>{l==null||l(M),c==null||c(M),M.defaultPrevented||d==null||d()},{ownerDocument:x,deferPointerDownOutside:a,isDeferredPointerDownOutsideRef:b,dismissableSurfaces:f.dismissableSurfaces,shouldHandlePointerDownOutside:u.useCallback(M=>{if(!(M instanceof Node))return!1;const O=[...f.branches].some(R=>R.contains(M));return S&&!O},[f.branches,S])}),$=HA(M=>{if(a&&b.current)return;const O=M.target;[...f.branches].some(_=>_.contains(O))||(o==null||o(M),c==null||c(M),M.defaultPrevented||d==null||d())},x),A=m?N===j.length-1:!1,I=ss(M=>{M.key==="Escape"&&(i==null||i(M),!M.defaultPrevented&&d&&(M.preventDefault(),d()))});return u.useEffect(()=>{if(A)return x.addEventListener("keydown",I,{capture:!0}),()=>x.removeEventListener("keydown",I,{capture:!0})},[x,A,I]),u.useEffect(()=>{if(m)return r&&(f.layersWithOutsidePointerEventsDisabled.size===0&&(y0=x.body.style.pointerEvents,x.body.style.pointerEvents="none"),f.layersWithOutsidePointerEventsDisabled.add(m)),f.layers.add(m),Tx(),()=>{r&&(f.layersWithOutsidePointerEventsDisabled.delete(m),f.layersWithOutsidePointerEventsDisabled.size===0&&(x.body.style.pointerEvents=y0))}},[m,x,r,f]),u.useEffect(()=>()=>{m&&(f.layers.delete(m),f.layersWithOutsidePointerEventsDisabled.delete(m),Tx())},[m,f]),u.useEffect(()=>{const M=wn(()=>g({}),"handleUpdate");return document.addEventListener($x,M),()=>document.removeEventListener($x,M)},[]),t.jsx(St.div,{...h,ref:y,style:{pointerEvents:k?S?"auto":"none":void 0,...n.style},onFocusCapture:We(n.onFocusCapture,$.onFocusCapture),onBlurCapture:We(n.onBlurCapture,$.onBlurCapture),onPointerDownCapture:We(n.onPointerDownCapture,C.onPointerDownCapture)})},"DismissableLayer")),RF=u.forwardRef(wn(function(n,s){const r=u.useContext(ww),a=u.useRef(null),i=Tt(s,a);return u.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 BA(){const e=u.useContext(ww),[n,s]=u.useState(null);return u.useEffect(()=>{if(n)return e.dismissableSurfaces.add(n),()=>{e.dismissableSurfaces.delete(n)}},[n,e.dismissableSurfaces]),s}wn(BA,"useDismissableLayerSurface");var PF=wn(()=>!0,"IS_TRUE");function WA(e,n){const{ownerDocument:s=globalThis==null?void 0:globalThis.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:a,dismissableSurfaces:i,shouldHandlePointerDownOutside:l=PF}=n,o=ss(e),c=u.useRef(!1),d=u.useRef(!1),h=u.useRef(new Map),f=u.useRef(()=>{});return u.useEffect(()=>{function m(){d.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 x(w){if(!d.current)return;const N=w.target;N instanceof Node&&[...i].some(S=>S.contains(N))||h.current.set(w.type,!0),w.type==="click"&&window.setTimeout(()=>{d.current&&f.current()},0)}wn(x,"handleInteractionCapture");function g(w){d.current&&h.current.set(w.type,!1)}wn(g,"handleInteractionBubble");const y=wn(w=>{if(w.target&&!c.current){let N=function(){s.removeEventListener("click",f.current);const S=p();m(),S||yw(TF,o,k,{discrete:!0})};if(wn(N,"handleAndDispatchPointerDownOutsideEvent"),!l(w.target)){s.removeEventListener("click",f.current),m(),c.current=!1;return}const k={originalEvent:w};d.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,x,!0),s.addEventListener(w,g);const v=window.setTimeout(()=>{s.addEventListener("pointerdown",y)},0);return()=>{window.clearTimeout(v),s.removeEventListener("pointerdown",y),s.removeEventListener("click",f.current);for(const w of j)s.removeEventListener(w,x,!0),s.removeEventListener(w,g)}},[s,o,r,a,i,l]),{onPointerDownCapture:wn(()=>c.current=!0,"onPointerDownCapture")}}wn(WA,"usePointerDownOutside");function HA(e,n=globalThis==null?void 0:globalThis.document){const s=ss(e),r=u.useRef(!1);return u.useEffect(()=>{const a=wn(i=>{i.target&&!r.current&&yw(IF,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(HA,"useFocusOutside");function Tx(){const e=new CustomEvent($x);document.dispatchEvent(e)}wn(Tx,"dispatchUpdate");function yw(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?Gf(a,i):a.dispatchEvent(i)}wn(yw,"handleAndDispatchCustomEvent");var MF=qf,OF=RF,ms=globalThis!=null&&globalThis.document?u.useLayoutEffect:()=>{},DF=Object.defineProperty,LF=(e,n)=>DF(e,"name",{value:n,configurable:!0}),Yf=u.forwardRef(LF(function(n,s){var c;const{container:r,...a}=n,[i,l]=u.useState(!1);ms(()=>l(!0),[]);const o=r||i&&((c=globalThis==null?void 0:globalThis.document)==null?void 0:c.body);return o?ko.createPortal(t.jsx(St.div,{...a,ref:s}),o):null},"Portal")),FF=Object.defineProperty,ja=(e,n)=>FF(e,"name",{value:n,configurable:!0});function KA(e,n){return u.useReducer((s,r)=>n[s][r]??s,e)}ja(KA,"useStateMachine");var Gr=ja(e=>{const{present:n,children:s}=e,r=VA(n),a=typeof s=="function"?s({present:r.isPresent}):u.Children.only(s),i=GA(r.ref,qA(a));return typeof s=="function"||r.isPresent?u.cloneElement(a,{ref:i}):null},"Presence");function VA(e){const[n,s]=u.useState(),r=u.useRef(null),a=u.useRef(e),i=u.useRef("none"),l=u.useRef(void 0),o=e?"mounted":"unmounted",[c,d]=KA(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return u.useEffect(()=>{c==="mounted"?(i.current=l.current??kl(r.current),l.current=void 0):i.current="none"},[c]),ms(()=>{const h=r.current,f=a.current;if(f!==e){const p=i.current,x=kl(h);e?(l.current=x,d("MOUNT")):x==="none"||(h==null?void 0:h.display)==="none"?d("UNMOUNT"):d(f&&p!==x?"ANIMATION_OUT":"UNMOUNT"),a.current=e}},[e,d]),ms(()=>{if(n){let h;const f=n.ownerDocument.defaultView??window,m=ja(x=>{const y=kl(r.current).includes(CSS.escape(x.animationName));if(x.target===n&&y&&(d("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=ja(x=>{x.target===n&&(i.current=kl(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 d("ANIMATION_END")},[n,d]),{isPresent:["mounted","unmountSuspended"].includes(c),ref:u.useCallback(h=>{if(h){const f=getComputedStyle(h);r.current=f,l.current=kl(f)}else r.current=null;s(h)},[])}}ja(VA,"usePresence");function Ix(e,n){if(typeof e=="function")return e(n);e!=null&&(e.current=n)}ja(Ix,"setRef");function GA(...e){const n=u.useRef(e);return n.current=e,u.useCallback(s=>{const r=n.current;let a=!1;const i=r.map(l=>{const o=Ix(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():Ix(r[l],null)}}},[])}ja(GA,"useStableComposedRefs");function kl(e){return(e==null?void 0:e.animationName)||"none"}ja(kl,"getAnimationName");function qA(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)}ja(qA,"getElementRef");var _F=Object.defineProperty,zF=(e,n)=>_F(e,"name",{value:n,configurable:!0}),b0=wo[" useEffectEvent ".trim().toString()],k0=wo[" useInsertionEffect ".trim().toString()];function YA(e){if(typeof b0=="function")return b0(e);const n=u.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof k0=="function"?k0(()=>{n.current=e}):ms(()=>{n.current=e}),u.useMemo(()=>(...s)=>{var r;return(r=n.current)==null?void 0:r.call(n,...s)},[])}zF(YA,"useEffectEvent");var UF=Object.defineProperty,$d=(e,n)=>UF(e,"name",{value:n,configurable:!0}),BF=wo[" useInsertionEffect ".trim().toString()]||ms;function fi({prop:e,defaultProp:n,onChange:s=$d(()=>{},"onChange"),caller:r}){const[a,i,l]=QA({defaultProp:n,onChange:s}),o=e!==void 0,c=o?e:a,d=u.useCallback(h=>{var f;if(o){const m=JA(h)?h(e):h;m!==e&&((f=l.current)==null||f.call(l,m))}else i(h)},[o,e,i,l]);return[c,d]}$d(fi,"useControllableState");function QA({defaultProp:e,onChange:n}){const[s,r]=u.useState(e),a=u.useRef(s),i=u.useRef(n);return BF(()=>{i.current=n},[n]),u.useEffect(()=>{var l;a.current!==s&&((l=i.current)==null||l.call(i,s),a.current=s)},[s,a]),[s,r,i]}$d(QA,"useUncontrolledState");function JA(e){return typeof e=="function"}$d(JA,"isFunction");var N0=Symbol("RADIX:SYNC_STATE");function WF(e,n,s,r){const{prop:a,defaultProp:i,onChange:l,caller:o}=n,c=a!==void 0,d=YA(l),h=[{...s,state:i}];r&&h.push(r);const[f,m]=u.useReducer((y,j)=>{if(j.type===N0)return{...y,state:j.state};const v=e(y,j);return c&&!Object.is(v.state,y.state)&&d(v.state),v},...h),p=f.state,x=u.useRef(p);u.useEffect(()=>{x.current!==p&&(x.current=p,c||d(p))},[p,x,c]);const g=u.useMemo(()=>a!==void 0?{...f,state:a}:f,[f,a]);return u.useEffect(()=>{c&&!Object.is(a,f.state)&&m({type:N0,state:a})},[a,f.state,c]),[g,m]}$d(WF,"useControllableStateReducer");var HF=Object.defineProperty,KF=(e,n)=>HF(e,"name",{value:n,configurable:!0}),VF=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"}),bw=u.forwardRef(KF(function(n,s){return t.jsx(St.span,{...n,ref:s,style:{...VF,...n.style}})},"VisuallyHidden")),GF=bw,qF=Object.defineProperty,At=(e,n)=>qF(e,"name",{value:n,configurable:!0}),XA="ToastProvider",[kw,ZA,YF]=Vf("Toast"),[e$,Jie]=br("Toast",[YF]),[QF,Qf]=e$(XA),JF=At(e=>{const{__scopeToast:n,label:s="Notification",duration:r=5e3,swipeDirection:a="right",swipeThreshold:i=50,announcerContainer:l,children:o}=e,[c,d]=u.useState(null),[h,f]=u.useState(0),m=u.useRef(!1);return s.trim()||console.error(`Invalid prop \`label\` supplied to \`${XA}\`. Expected non-empty \`string\`.`),t.jsx(kw.Provider,{scope:n,children:t.jsx(QF,{scope:n,label:s,duration:r,swipeDirection:a,swipeThreshold:i,toastCount:h,viewport:c,onViewportChange:d,onToastAdd:u.useCallback(()=>f(p=>p+1),[]),onToastRemove:u.useCallback(()=>f(p=>p-1),[]),isClosePausedRef:m,announcerContainer:l,children:o})})},"ToastProvider"),XF="ToastViewport",ZF=["F8"],Rx="toast.viewportPause",Px="toast.viewportResume",e_=u.forwardRef(At(function(n,s){const{__scopeToast:r,hotkey:a=ZF,label:i="Notifications ({hotkey})",...l}=n,o=Qf(XF,r),c=ZA(r),d=u.useRef(null),h=u.useRef(null),f=u.useRef(null),m=u.useRef(null),p=Tt(s,m,o.onViewportChange),x=a.join("+").replace(/Key/g,"").replace(/Digit/g,""),g=o.toastCount>0;u.useEffect(()=>{const j=At(v=>{var N;a.length!==0&&a.every(k=>v[k]||v.code===k)&&((N=m.current)==null||N.focus())},"handleKeyDown");return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[a]),u.useEffect(()=>{const j=d.current,v=m.current;if(g&&j&&v){const w=At(()=>{if(!o.isClosePausedRef.current){const b=new CustomEvent(Rx);v.dispatchEvent(b),o.isClosePausedRef.current=!0}},"handlePause"),N=At(()=>{if(o.isClosePausedRef.current){const b=new CustomEvent(Px);v.dispatchEvent(b),o.isClosePausedRef.current=!1}},"handleResume"),k=At(b=>{!j.contains(b.relatedTarget)&&N()},"handleFocusOutResume"),S=At(()=>{j.contains(document.activeElement)||N()},"handlePointerLeaveResume");return j.addEventListener("focusin",w),j.addEventListener("focusout",k),j.addEventListener("pointermove",w),j.addEventListener("pointerleave",S),window.addEventListener("blur",w),window.addEventListener("focus",N),()=>{j.removeEventListener("focusin",w),j.removeEventListener("focusout",k),j.removeEventListener("pointermove",w),j.removeEventListener("pointerleave",S),window.removeEventListener("blur",w),window.removeEventListener("focus",N)}}},[g,o.isClosePausedRef]);const y=u.useCallback(({tabbingDirection:j})=>{const w=c().map(N=>{const k=N.ref.current,S=[k,...r$(k)];return j==="forwards"?S:S.reverse()});return(j==="forwards"?w.reverse():w).flat()},[c]);return u.useEffect(()=>{const j=m.current;if(j){const v=At(w=>{var S,b,C;const N=w.altKey||w.ctrlKey||w.metaKey;if(w.key==="Tab"&&!N){const $=document.activeElement,A=w.shiftKey;if(w.target===j&&A){(S=h.current)==null||S.focus();return}const O=y({tabbingDirection:A?"backwards":"forwards"}),R=O.findIndex(_=>_===$);nh(O.slice(R+1))?w.preventDefault():A?(b=h.current)==null||b.focus():(C=f.current)==null||C.focus()}},"handleKeyDown");return j.addEventListener("keydown",v),()=>j.removeEventListener("keydown",v)}},[c,y]),t.jsxs(OF,{ref:d,role:"region","aria-label":i.replace("{hotkey}",x),tabIndex:-1,style:{pointerEvents:g?void 0:"none"},children:[g&&t.jsx(S0,{ref:h,onFocusFromOutsideViewport:()=>{const j=y({tabbingDirection:"forwards"});nh(j)}}),t.jsx(kw.Slot,{scope:r,children:t.jsx(St.ol,{tabIndex:-1,...l,ref:p})}),g&&t.jsx(S0,{ref:f,onFocusFromOutsideViewport:()=>{const j=y({tabbingDirection:"backwards"});nh(j)}})]})},"ToastViewport")),t_="ToastFocusProxy",S0=u.forwardRef(At(function(n,s){const{__scopeToast:r,onFocusFromOutsideViewport:a,...i}=n,l=Qf(t_,r);return t.jsx(bw,{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")),Jf="Toast",n_="toast.swipeStart",s_="toast.swipeMove",r_="toast.swipeCancel",a_="toast.swipeEnd",i_=u.forwardRef(At(function(n,s){const{forceMount:r,open:a,defaultOpen:i,onOpenChange:l,...o}=n,[c,d]=fi({prop:a,defaultProp:i??!0,onChange:l,caller:Jf});return t.jsx(Gr,{present:r||c,children:t.jsx(c_,{open:c,...o,ref:s,onClose:()=>d(!1),onPause:ss(n.onPause),onResume:ss(n.onResume),onSwipeStart:We(n.onSwipeStart,h=>{h.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:We(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:We(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:We(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`),d(!1)})})})},"Toast")),[l_,o_]=e$(Jf,{onClose(){}}),c_=u.forwardRef(At(function(n,s){const{__scopeToast:r,type:a="foreground",duration:i,open:l,onClose:o,onEscapeKeyDown:c,onPause:d,onResume:h,onSwipeStart:f,onSwipeMove:m,onSwipeCancel:p,onSwipeEnd:x,...g}=n,y=Qf(Jf,r),j=ZA(r),[v,w]=u.useState(null),N=Tt(s,w),k=u.useRef(null),S=u.useRef(null),b=i||y.duration,C=u.useRef(0),$=u.useRef(b),A=u.useRef(0),{onToastAdd:I,onToastRemove:M}=y,O=ss(()=>{var U;(v==null?void 0:v.contains(document.activeElement))&&((U=y.viewport)==null||U.focus()),o()}),R=u.useCallback(z=>{!z||z===1/0||(window.clearTimeout(A.current),C.current=new Date().getTime(),A.current=window.setTimeout(O,z))},[O]);u.useEffect(()=>{const z=y.viewport;if(z){const U=At(()=>{R($.current),h==null||h()},"handleResume"),P=At(()=>{const W=new Date().getTime()-C.current;$.current=$.current-W,window.clearTimeout(A.current),d==null||d()},"handlePause");return z.addEventListener(Rx,P),z.addEventListener(Px,U),()=>{z.removeEventListener(Rx,P),z.removeEventListener(Px,U)}}},[y.viewport,b,d,h,R]),u.useEffect(()=>{l&&!y.isClosePausedRef.current&&R(b)},[l,b,y.isClosePausedRef,R]),u.useEffect(()=>()=>{window.clearTimeout(A.current)},[]),u.useEffect(()=>(I(),()=>M()),[I,M]);const _=u.useMemo(()=>v?Nw(v):null,[v]);return y.viewport?t.jsxs(t.Fragment,{children:[_&&t.jsx(d_,{__scopeToast:r,role:"status","aria-live":a==="foreground"?"assertive":"polite",children:_}),t.jsx(l_,{scope:r,onClose:O,children:ko.createPortal(t.jsx(kw.ItemSlot,{scope:r,children:t.jsx(MF,{asChild:!0,onEscapeKeyDown:We(c,z=>{j().some(P=>{var W;return(W=P.ref.current)==null?void 0:W.contains(z.target)})||O()}),children:t.jsx(St.li,{tabIndex:0,"data-state":l?"open":"closed","data-swipe-direction":y.swipeDirection,...g,ref:N,style:{userSelect:"none",touchAction:"none",...n.style},onKeyDown:We(n.onKeyDown,z=>{z.key==="Escape"&&(c==null||c(z.nativeEvent),z.nativeEvent.defaultPrevented||O())}),onPointerDown:We(n.onPointerDown,z=>{z.button===0&&(k.current={x:z.clientX,y:z.clientY})}),onPointerMove:We(n.onPointerMove,z=>{if(!k.current)return;const U=z.clientX-k.current.x,P=z.clientY-k.current.y,W=!!S.current,L=["left","right"].includes(y.swipeDirection),Q=["left","up"].includes(y.swipeDirection)?Math.min:Math.max,F=L?Q(0,U):0,ae=L?0:Q(0,P),V=z.pointerType==="touch"?10:2,J={x:F,y:ae},H={originalEvent:z,delta:J};W?(S.current=J,oc(s_,m,H,{discrete:!1})):C0(J,y.swipeDirection,V)?(S.current=J,oc(n_,f,H,{discrete:!1}),z.target.setPointerCapture(z.pointerId)):(Math.abs(U)>V||Math.abs(P)>V)&&(k.current=null)}),onPointerUp:We(n.onPointerUp,z=>{const U=S.current,P=z.target;if(P.hasPointerCapture(z.pointerId)&&P.releasePointerCapture(z.pointerId),S.current=null,k.current=null,U){const W=z.currentTarget,L={originalEvent:z,delta:U};C0(U,y.swipeDirection,y.swipeThreshold)?oc(a_,x,L,{discrete:!0}):oc(r_,p,L,{discrete:!0}),W.addEventListener("click",Q=>Q.preventDefault(),{once:!0})}})})})}),y.viewport)})]}):null},"ToastImpl")),d_=At(e=>{const{__scopeToast:n,children:s,...r}=e,a=Qf(Jf,n),[i,l]=u.useState(!1),[o,c]=u.useState(!1);return n$(()=>l(!0)),u.useEffect(()=>{const d=window.setTimeout(()=>c(!0),1e3);return()=>window.clearTimeout(d)},[]),o?null:t.jsx(Yf,{asChild:!0,container:a.announcerContainer||void 0,children:t.jsx(bw,{...r,children:i&&t.jsxs(t.Fragment,{children:[a.label," ",s]})})})},"ToastAnnounce"),u_=u.forwardRef(At(function(n,s){const{__scopeToast:r,...a}=n;return t.jsx(St.div,{...a,ref:s})},"ToastTitle")),h_=u.forwardRef(At(function(n,s){const{__scopeToast:r,...a}=n;return t.jsx(St.div,{...a,ref:s})},"ToastDescription")),f_="ToastAction",m_=u.forwardRef(At(function(n,s){const{altText:r,...a}=n;return r.trim()?t.jsx(t$,{altText:r,asChild:!0,children:t.jsx(g_,{...a,ref:s})}):(console.error(`Invalid prop \`altText\` supplied to \`${f_}\`. Expected non-empty \`string\`.`),null)},"ToastAction")),p_="ToastClose",g_=u.forwardRef(At(function(n,s){const{__scopeToast:r,...a}=n,i=o_(p_,r);return t.jsx(t$,{asChild:!0,children:t.jsx(St.button,{type:"button",...a,ref:s,onClick:We(n.onClick,i.onClose)})})},"ToastClose")),t$=u.forwardRef(At(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 Nw(e){const n=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&n.push(r.textContent),s$(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(...Nw(r))}}),n}At(Nw,"getAnnounceTextContent");function oc(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?Gf(a,i):a.dispatchEvent(i)}At(oc,"handleAndDispatchCustomEvent");var C0=At((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 n$(e=()=>{}){const n=ss(e);ms(()=>{let s=0,r=0;return s=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(n)),()=>{window.cancelAnimationFrame(s),window.cancelAnimationFrame(r)}},[n])}At(n$,"useNextFrame");function s$(e){return e.nodeType===e.ELEMENT_NODE}At(s$,"isHTMLElement");function r$(e){const n=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:At(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}At(r$,"getTabbableCandidates");function nh(e){const n=document.activeElement;return e.some(s=>s===n?!0:(s.focus(),document.activeElement!==n))}At(nh,"focusFirst");var E0=JF,A0=e_,x_=i_,v_=u_,j_=h_,w_=m_,y_=Object.defineProperty,b_=(e,n)=>y_(e,"name",{value:n,configurable:!0}),k_=wo[" useId ".trim().toString()]||(()=>{}),N_=0;function ur(e){const[n,s]=u.useState(k_());return ms(()=>{e||s(r=>r??String(N_++))},[e]),e||(n?`radix-${n}`:"")}b_(ur,"useId");const S_=["top","right","bottom","left"],ni=Math.min,ha=Math.max,Bh=Math.round,xu=Math.floor,fa=e=>({x:e,y:e}),C_={left:"right",right:"left",bottom:"top",top:"bottom"};function a$(e,n,s){return ha(e,ni(n,s))}function wa(e,n){return typeof e=="function"?e(n):e}function si(e){return e.split("-")[0]}function So(e){return e.split("-")[1]}function Sw(e){return e==="x"?"y":"x"}function Cw(e){return e==="y"?"height":"width"}function Dr(e){const n=e[0];return n==="t"||n==="b"?"y":"x"}function Ew(e){return Sw(Dr(e))}function E_(e,n,s){s===void 0&&(s=!1);const r=So(e),a=Ew(e),i=Cw(a);let l=a==="x"?r===(s?"end":"start")?"right":"left":r==="start"?"bottom":"top";return n.reference[i]>n.floating[i]&&(l=Wh(l)),[l,Wh(l)]}function A_(e){const n=Wh(e);return[Mx(e),n,Mx(n)]}function Mx(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const $0=["left","right"],T0=["right","left"],$_=["top","bottom"],T_=["bottom","top"];function I_(e,n,s){switch(e){case"top":case"bottom":return s?n?T0:$0:n?$0:T0;case"left":case"right":return n?$_:T_;default:return[]}}function R_(e,n,s,r){const a=So(e);let i=I_(si(e),s==="start",r);return a&&(i=i.map(l=>l+"-"+a),n&&(i=i.concat(i.map(Mx)))),i}function Wh(e){const n=si(e);return C_[n]+e.slice(n.length)}function P_(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 i$(e){return typeof e!="number"?P_(e):{top:e,right:e,bottom:e,left:e}}function Hh(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 I0(e,n,s){let{reference:r,floating:a}=e;const i=Dr(n),l=Ew(n),o=Cw(l),c=si(n),d=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 x=So(n);return x&&(p[l]+=m*(x==="end"?1:-1)*(s&&d?-1:1)),p}async function M_(e,n){var s;n===void 0&&(n={});const{x:r,y:a,platform:i,rects:l,elements:o,strategy:c}=e,{boundary:d="clippingAncestors",rootBoundary:h="viewport",elementContext:f="floating",altBoundary:m=!1,padding:p=0}=wa(n,e),x=i$(p),y=o[m?f==="floating"?"reference":"floating":f],j=Hh(await i.getClippingRect({element:(s=await(i.isElement==null?void 0:i.isElement(y)))==null||s?y:y.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:d,rootBoundary:h,strategy:c})),v=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},k=Hh(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:v,offsetParent:w,strategy:c}):v);return{top:(j.top-k.top+x.top)/N.y,bottom:(k.bottom-j.bottom+x.bottom)/N.y,left:(j.left-k.left+x.left)/N.x,right:(k.right-j.right+x.right)/N.x}}const O_=50,D_=async(e,n,s)=>{const{placement:r="bottom",strategy:a="absolute",middleware:i=[],platform:l}=s,o=l.detectOverflow?l:{...l,detectOverflow:M_},c=await(l.isRTL==null?void 0:l.isRTL(n));let d=await l.getElementRects({reference:e,floating:n,strategy:a}),{x:h,y:f}=I0(d,r,c),m=r,p=0;const x={};for(let g=0;g<i.length;g++){const y=i[g];if(!y)continue;const{name:j,fn:v}=y,{x:w,y:N,data:k,reset:S}=await v({x:h,y:f,initialPlacement:r,placement:m,strategy:a,middlewareData:x,rects:d,platform:o,elements:{reference:e,floating:n}});h=w??h,f=N??f,x[j]={...x[j],...k},S&&p<O_&&(p++,typeof S=="object"&&(S.placement&&(m=S.placement),S.rects&&(d=S.rects===!0?await l.getElementRects({reference:e,floating:n,strategy:a}):S.rects),{x:h,y:f}=I0(d,m,c)),g=-1)}return{x:h,y:f,placement:m,strategy:a,middlewareData:x}},L_=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:d,padding:h=0}=wa(e,n)||{};if(d==null)return{};const f=i$(h),m={x:s,y:r},p=Ew(a),x=Cw(p),g=await l.getDimensions(d),y=p==="y",j=y?"top":"left",v=y?"bottom":"right",w=y?"clientHeight":"clientWidth",N=i.reference[x]+i.reference[p]-m[p]-i.floating[x],k=m[p]-i.reference[p],S=await(l.getOffsetParent==null?void 0:l.getOffsetParent(d));let b=S?S[w]:0;(!b||!await(l.isElement==null?void 0:l.isElement(S)))&&(b=o.floating[w]||i.floating[x]);const C=N/2-k/2,$=b/2-g[x]/2-1,A=ni(f[j],$),I=ni(f[v],$),M=b-g[x]-I,O=b/2-g[x]/2+C,R=a$(A,O,M),_=!c.arrow&&So(a)!=null&&O!==R&&i.reference[x]/2-(O<A?A:I)-g[x]/2<0,z=_?O<A?O-A:O-M:0;return{[p]:m[p]+z,data:{[p]:R,centerOffset:O-R-z,..._&&{alignmentOffset:z}},reset:_}}}),F_=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:d}=n,{mainAxis:h=!0,crossAxis:f=!0,fallbackPlacements:m,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:x="none",flipAlignment:g=!0,...y}=wa(e,n);if((s=i.arrow)!=null&&s.alignmentOffset)return{};const j=si(a),v=Dr(o),w=si(o)===o,N=await(c.isRTL==null?void 0:c.isRTL(d.floating)),k=m||(w||!g?[Wh(o)]:A_(o)),S=x!=="none";!m&&S&&k.push(...R_(o,g,x,N));const b=[o,...k],C=await c.detectOverflow(n,y),$=[];let A=((r=i.flip)==null?void 0:r.overflows)||[];if(h&&$.push(C[j]),f){const R=E_(a,l,N);$.push(C[R[0]],C[R[1]])}if(A=[...A,{placement:a,overflows:$}],!$.every(R=>R<=0)){var I,M;const R=(((I=i.flip)==null?void 0:I.index)||0)+1,_=b[R];if(_&&(!(f==="alignment"?v!==Dr(_):!1)||A.every(P=>Dr(P.placement)===v?P.overflows[0]>0:!0)))return{data:{index:R,overflows:A},reset:{placement:_}};let z=(M=A.filter(U=>U.overflows[0]<=0).sort((U,P)=>U.overflows[1]-P.overflows[1])[0])==null?void 0:M.placement;if(!z)switch(p){case"bestFit":{var O;const U=(O=A.filter(P=>{if(S){const W=Dr(P.placement);return W===v||W==="y"}return!0}).map(P=>[P.placement,P.overflows.filter(W=>W>0).reduce((W,L)=>W+L,0)]).sort((P,W)=>P[1]-W[1])[0])==null?void 0:O[0];U&&(z=U);break}case"initialPlacement":z=o;break}if(a!==z)return{reset:{placement:z}}}return{}}}};function R0(e,n){return{top:e.top-n.height,right:e.right-n.width,bottom:e.bottom-n.height,left:e.left-n.width}}function P0(e){return S_.some(n=>e[n]>=0)}const __=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(n){const{rects:s,platform:r}=n,{strategy:a="referenceHidden",...i}=wa(e,n);switch(a){case"referenceHidden":{const l=await r.detectOverflow(n,{...i,elementContext:"reference"}),o=R0(l,s.reference);return{data:{referenceHiddenOffsets:o,referenceHidden:P0(o)}}}case"escaped":{const l=await r.detectOverflow(n,{...i,altBoundary:!0}),o=R0(l,s.floating);return{data:{escapedOffsets:o,escaped:P0(o)}}}default:return{}}}}},l$=new Set(["left","top"]);async function z_(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=So(s),c=Dr(s)==="y",d=l$.has(l)?-1:1,h=i&&c?-1:1,f=wa(n,e);let{mainAxis:m,crossAxis:p,alignmentAxis:x}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return o&&typeof x=="number"&&(p=o==="end"?x*-1:x),c?{x:p*h,y:m*d}:{x:m*d,y:p*h}}const U_=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 z_(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}}}}},B_=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:v=>{let{x:w,y:N}=v;return{x:w,y:N}}},...d}=wa(e,n),h={x:s,y:r},f=await i.detectOverflow(n,d),m=Dr(a),p=Sw(m);let x=h[p],g=h[m];const y=(v,w)=>a$(w+f[v==="y"?"top":"left"],w,w-f[v==="y"?"bottom":"right"]);l&&(x=y(p,x)),o&&(g=y(m,g));const j=c.fn({...n,[p]:x,[m]:g});return{...j,data:{x:j.x-s,y:j.y-r,enabled:{[p]:l,[m]:o}}}}}},W_=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:d=0,mainAxis:h=!0,crossAxis:f=!0}=wa(e,n),m={x:a,y:i},p=Dr(l),x=Sw(p);let g=m[x],y=m[p];const j=wa(d,n),v=typeof j=="number"?{mainAxis:j,crossAxis:0}:{mainAxis:(s=j.mainAxis)!=null?s:0,crossAxis:(r=j.crossAxis)!=null?r:0};if(h){const k=x==="y"?"height":"width",S=o.reference[x]-o.floating[k]+v.mainAxis,b=o.reference[x]+o.reference[k]-v.mainAxis;g<S?g=S:g>b&&(g=b)}if(f){var w,N;const k=x==="y"?"width":"height",S=l$.has(si(l)),b=o.reference[p]-o.floating[k]+(S&&((w=c.offset)==null?void 0:w[p])||0)+(S?0:v.crossAxis),C=o.reference[p]+o.reference[k]+(S?0:((N=c.offset)==null?void 0:N[p])||0)-(S?v.crossAxis:0);y<b?y=b:y>C&&(y=C)}return{[x]:g,[p]:y}}}},H_=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}=wa(e,n),c=await a.detectOverflow(n,o),d=si(s),h=So(s),f=Dr(s)==="y",{width:m,height:p}=r.floating;let x,g;d==="top"||d==="bottom"?(x=d,g=h===(await(a.isRTL==null?void 0:a.isRTL(i.floating))?"start":"end")?"left":"right"):(g=d,x=h==="end"?"top":"bottom");const y=p-c.top-c.bottom,j=m-c.left-c.right,v=ni(p-c[x],y),w=ni(m-c[g],j),N=n.middlewareData.shift,k=!N;let S=v,b=w;N!=null&&N.enabled.x&&(b=j),N!=null&&N.enabled.y&&(S=y),k&&!h&&(f?b=m-2*ha(c.left,c.right):S=p-2*ha(c.top,c.bottom)),await l({...n,availableWidth:b,availableHeight:S});const C=await a.getDimensions(i.floating);return m!==C.width||p!==C.height?{reset:{rects:!0}}:{}}}};function Xf(){return typeof window<"u"}function Co(e){return o$(e)?(e.nodeName||"").toLowerCase():"#document"}function ps(e){var n;return(e==null||(n=e.ownerDocument)==null?void 0:n.defaultView)||window}function ka(e){var n;return(n=(o$(e)?e.ownerDocument:e.document)||window.document)==null?void 0:n.documentElement}function o$(e){return Xf()?e instanceof Node||e instanceof ps(e).Node:!1}function Br(e){return Xf()?e instanceof Element||e instanceof ps(e).Element:!1}function mi(e){return Xf()?e instanceof HTMLElement||e instanceof ps(e).HTMLElement:!1}function M0(e){return!Xf()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof ps(e).ShadowRoot}function Zf(e){const{overflow:n,overflowX:s,overflowY:r,display:a}=Wr(e);return/auto|scroll|overlay|hidden|clip/.test(n+r+s)&&a!=="inline"&&a!=="contents"}function K_(e){return/^(table|td|th)$/.test(Co(e))}function em(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const V_=/transform|translate|scale|rotate|perspective|filter/,G_=/paint|layout|strict|content/,Ni=e=>!!e&&e!=="none";let bp;function Aw(e){const n=Br(e)?Wr(e):e;return Ni(n.transform)||Ni(n.translate)||Ni(n.scale)||Ni(n.rotate)||Ni(n.perspective)||!$w()&&(Ni(n.backdropFilter)||Ni(n.filter))||V_.test(n.willChange||"")||G_.test(n.contain||"")}function q_(e){let n=Gi(e);for(;mi(n)&&!Jc(n);){if(Aw(n))return n;if(em(n))return null;n=Gi(n)}return null}function $w(){return bp==null&&(bp=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),bp}function Jc(e){return/^(html|body|#document)$/.test(Co(e))}function Wr(e){return ps(e).getComputedStyle(e)}function tm(e){return Br(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Gi(e){if(Co(e)==="html")return e;const n=e.assignedSlot||e.parentNode||M0(e)&&e.host||ka(e);return M0(n)?n.host:n}function c$(e){const n=Gi(e);return Jc(n)?(e.ownerDocument||e).body:mi(n)&&Zf(n)?n:c$(n)}function Xc(e,n,s){var r;n===void 0&&(n=[]),s===void 0&&(s=!0);const a=c$(e),i=a===((r=e.ownerDocument)==null?void 0:r.body),l=ps(a);if(i){const o=Ox(l);return n.concat(l,l.visualViewport||[],Zf(a)?a:[],o&&s?Xc(o):[])}else return n.concat(a,Xc(a,[],s))}function Ox(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function d$(e){const n=Wr(e);let s=parseFloat(n.width)||0,r=parseFloat(n.height)||0;const a=mi(e),i=a?e.offsetWidth:s,l=a?e.offsetHeight:r,o=Bh(s)!==i||Bh(r)!==l;return o&&(s=i,r=l),{width:s,height:r,$:o}}function Tw(e){return Br(e)?e:e.contextElement}function Kl(e){const n=Tw(e);if(!mi(n))return fa(1);const s=n.getBoundingClientRect(),{width:r,height:a,$:i}=d$(n);let l=(i?Bh(s.width):s.width)/r,o=(i?Bh(s.height):s.height)/a;return(!l||!Number.isFinite(l))&&(l=1),(!o||!Number.isFinite(o))&&(o=1),{x:l,y:o}}const Y_=fa(0);function u$(e){const n=ps(e);return!$w()||!n.visualViewport?Y_:{x:n.visualViewport.offsetLeft,y:n.visualViewport.offsetTop}}function Q_(e,n,s){return n===void 0&&(n=!1),!!s&&n&&s===ps(e)}function qi(e,n,s,r){n===void 0&&(n=!1),s===void 0&&(s=!1);const a=e.getBoundingClientRect(),i=Tw(e);let l=fa(1);n&&(r?Br(r)&&(l=Kl(r)):l=Kl(e));const o=Q_(i,s,r)?u$(i):fa(0);let c=(a.left+o.x)/l.x,d=(a.top+o.y)/l.y,h=a.width/l.x,f=a.height/l.y;if(i&&r){const m=ps(i),p=Br(r)?ps(r):r;let x=m,g=Ox(x);for(;g&&p!==x;){const y=Kl(g),j=g.getBoundingClientRect(),v=Wr(g),w=j.left+(g.clientLeft+parseFloat(v.paddingLeft))*y.x,N=j.top+(g.clientTop+parseFloat(v.paddingTop))*y.y;c*=y.x,d*=y.y,h*=y.x,f*=y.y,c+=w,d+=N,x=ps(g),g=Ox(x)}}return Hh({width:h,height:f,x:c,y:d})}function nm(e,n){const s=tm(e).scrollLeft;return n?n.left+s:qi(ka(e)).left+s}function h$(e,n){const s=e.getBoundingClientRect(),r=s.left+n.scrollLeft-nm(e,s),a=s.top+n.scrollTop;return{x:r,y:a}}function J_(e){let{elements:n,rect:s,offsetParent:r,strategy:a}=e;const i=a==="fixed",l=ka(r),o=n?em(n.floating):!1;if(r===l||o&&i)return s;let c={scrollLeft:0,scrollTop:0},d=fa(1);const h=fa(0),f=mi(r);if((f||!i)&&((Co(r)!=="body"||Zf(l))&&(c=tm(r)),f)){const p=qi(r);d=Kl(r),h.x=p.x+r.clientLeft,h.y=p.y+r.clientTop}const m=l&&!f&&!i?h$(l,c):fa(0);return{width:s.width*d.x,height:s.height*d.y,x:s.x*d.x-c.scrollLeft*d.x+h.x+m.x,y:s.y*d.y-c.scrollTop*d.y+h.y+m.y}}function X_(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function Z_(e){const n=tm(e),s=e.ownerDocument.body,r=ha(e.scrollWidth,e.clientWidth,s.scrollWidth,s.clientWidth),a=ha(e.scrollHeight,e.clientHeight,s.scrollHeight,s.clientHeight);let i=-n.scrollLeft+nm(e);const l=-n.scrollTop;return Wr(s).direction==="rtl"&&(i+=ha(e.clientWidth,s.clientWidth)-r),{width:r,height:a,x:i,y:l}}const e4=25;function t4(e,n,s){s===void 0&&(s="viewport");const r=s==="layoutViewport",a=ps(e),i=ka(e),l=a.visualViewport;let o=i.clientWidth,c=i.clientHeight,d=0,h=0;if(l){const m=!$w()||n==="fixed";r?m||(d=-l.offsetLeft,h=-l.offsetTop):(o=l.width,c=l.height,m&&(d=l.offsetLeft,h=l.offsetTop))}if(nm(i)<=0){const m=i.ownerDocument,p=m.body,x=getComputedStyle(p),g=m.compatMode==="CSS1Compat"&&parseFloat(x.marginLeft)+parseFloat(x.marginRight)||0,y=Math.abs(i.clientWidth-p.clientWidth-g),j=getComputedStyle(i).scrollbarGutter==="stable both-edges"?y/2:y;j<=e4&&(o-=j)}return{width:o,height:c,x:d,y:h}}function n4(e,n){const s=qi(e,!0,n==="fixed"),r=s.top+e.clientTop,a=s.left+e.clientLeft,i=Kl(e),l=e.clientWidth*i.x,o=e.clientHeight*i.y,c=a*i.x,d=r*i.y;return{width:l,height:o,x:c,y:d}}function O0(e,n,s){let r;if(n==="viewport"||n==="layoutViewport")r=t4(e,s,n);else if(n==="document")r=Z_(ka(e));else if(Br(n))r=n4(n,s);else{const a=u$(e);r={x:n.x-a.x,y:n.y-a.y,width:n.width,height:n.height}}return Hh(r)}function s4(e,n){const s=n.get(e);if(s)return s;let r=Xc(e,[],!1).filter(o=>Br(o)&&Co(o)!=="body"),a=null;const i=Wr(e).position==="fixed";let l=i?Gi(e):e;for(;Br(l)&&!Jc(l);){const o=Wr(l),c=Aw(l),d=a?a.position:i?"fixed":"";!c&&(d==="fixed"||d==="absolute"&&o.position==="static")?r=r.filter(f=>f!==l):a=o,l=Gi(l)}return n.set(e,r),r}function r4(e){let{element:n,boundary:s,rootBoundary:r,strategy:a}=e;const l=[...s==="clippingAncestors"?em(n)?[]:s4(n,this._c):[].concat(s),r],o=O0(n,l[0],a);let c=o.top,d=o.right,h=o.bottom,f=o.left;for(let m=1;m<l.length;m++){const p=O0(n,l[m],a);c=ha(p.top,c),d=ni(p.right,d),h=ni(p.bottom,h),f=ha(p.left,f)}return{width:d-f,height:h-c,x:f,y:c}}function a4(e){const{width:n,height:s}=d$(e);return{width:n,height:s}}function i4(e,n,s){const r=mi(n),a=ka(n),i=s==="fixed",l=qi(e,!0,i,n);let o={scrollLeft:0,scrollTop:0};const c=fa(0);if((r||!i)&&((Co(n)!=="body"||Zf(a))&&(o=tm(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=nm(a));const d=a&&!r&&!i?h$(a,o):fa(0),h=l.left+o.scrollLeft-c.x-d.x,f=l.top+o.scrollTop-c.y-d.y;return{x:h,y:f,width:l.width,height:l.height}}function kp(e){return Wr(e).position==="static"}function D0(e,n){if(!mi(e)||Wr(e).position==="fixed")return null;if(n)return n(e);let s=e.offsetParent;return ka(e)===s&&(s=s.ownerDocument.body),s}function f$(e,n){const s=ps(e);if(em(e))return s;if(!mi(e)){let a=Gi(e);for(;a&&!Jc(a);){if(Br(a)&&!kp(a))return a;a=Gi(a)}return s}let r=D0(e,n);for(;r&&K_(r)&&kp(r);)r=D0(r,n);return r&&Jc(r)&&kp(r)&&!Aw(r)?s:r||q_(e)||s}const l4=async function(e){const n=this.getOffsetParent||f$,s=this.getDimensions,r=await s(e.floating);return{reference:i4(e.reference,await n(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function o4(e){return Wr(e).direction==="rtl"}const c4={convertOffsetParentRelativeRectToViewportRelativeRect:J_,getDocumentElement:ka,getClippingRect:r4,getOffsetParent:f$,getElementRects:l4,getClientRects:X_,getDimensions:a4,getScale:Kl,isElement:Br,isRTL:o4};function m$(e,n){return e.x===n.x&&e.y===n.y&&e.width===n.width&&e.height===n.height}function d4(e,n,s){let r=null,a;const i=ka(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:x,width:g,height:y}=m;if(h||n(),!g||!y)return;const j=xu(x),v=xu(i.clientWidth-(p+g)),w=xu(i.clientHeight-(x+y)),N=xu(p),S={rootMargin:-j+"px "+-v+"px "+-w+"px "+-N+"px",threshold:ha(0,ni(1,f))||1};let b=!0;function C($){const A=$[0].intersectionRatio;if(!m$(m,e.getBoundingClientRect()))return o();if(A!==f){if(!b)return o();A?o(!1,A):a=setTimeout(()=>{o(!1,1e-7)},1e3)}b=!1}try{r=new IntersectionObserver(C,{...S,root:i.ownerDocument})}catch{r=new IntersectionObserver(C,S)}r.observe(e)}const c=ps(e),d=()=>o(s);return c.addEventListener("resize",d),o(!0),()=>{c.removeEventListener("resize",d),l()}}function u4(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,d=Tw(e),h=a||i?[...d?Xc(d):[],...n?Xc(n):[]]:[];h.forEach(j=>{a&&j.addEventListener("scroll",s),i&&j.addEventListener("resize",s)});const f=d&&o?d4(d,s,i):null;let m=-1,p=null;l&&(p=new ResizeObserver(j=>{let[v]=j;v&&v.target===d&&p&&n&&(p.unobserve(n),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var w;(w=p)==null||w.observe(n)})),s()}),d&&!c&&p.observe(d),n&&p.observe(n));let x,g=c?qi(e):null;c&&y();function y(){const j=qi(e);g&&!m$(g,j)&&s(),g=j,x=requestAnimationFrame(y)}return s(),()=>{var j;h.forEach(v=>{a&&v.removeEventListener("scroll",s),i&&v.removeEventListener("resize",s)}),f==null||f(),(j=p)==null||j.disconnect(),p=null,c&&cancelAnimationFrame(x)}}const h4=U_,f4=B_,m4=F_,p4=H_,g4=__,L0=L_,x4=W_,v4=(e,n,s)=>{const r=new Map,a=s??{},i={...c4,...a.platform,_c:r};return D_(e,n,{...a,platform:i})};var j4=typeof document<"u",w4=function(){},sh=j4?u.useLayoutEffect:w4;function Kh(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(!Kh(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)&&!Kh(e[i],n[i]))return!1}return!0}return e!==e&&n!==n}function p$(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function F0(e,n){const s=p$(e);return Math.round(n*s)/s}function Np(e){const n=u.useRef(e);return sh(()=>{n.current=e}),n}function y4(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:d}=e,[h,f]=u.useState({x:0,y:0,strategy:s,placement:n,middlewareData:{},isPositioned:!1}),[m,p]=u.useState(r);Kh(m,r)||p(r);const[x,g]=u.useState(null),[y,j]=u.useState(null),v=u.useCallback(P=>{P!==S.current&&(S.current=P,g(P))},[]),w=u.useCallback(P=>{P!==b.current&&(b.current=P,j(P))},[]),N=i||x,k=l||y,S=u.useRef(null),b=u.useRef(null),C=u.useRef(h),$=c!=null,A=Np(c),I=Np(a),M=Np(d),O=u.useCallback(()=>{if(!S.current||!b.current)return;const P={placement:n,strategy:s,middleware:m};I.current&&(P.platform=I.current),v4(S.current,b.current,P).then(W=>{const L={...W,isPositioned:M.current!==!1};R.current&&!Kh(C.current,L)&&(C.current=L,ko.flushSync(()=>{f(L)}))})},[m,n,s,I,M]);sh(()=>{d===!1&&C.current.isPositioned&&(C.current.isPositioned=!1,f(P=>({...P,isPositioned:!1})))},[d]);const R=u.useRef(!1);sh(()=>(R.current=!0,()=>{R.current=!1}),[]),sh(()=>{if(N&&(S.current=N),k&&(b.current=k),N&&k){if(A.current)return A.current(N,k,O);O()}},[N,k,O,A,$]);const _=u.useMemo(()=>({reference:S,floating:b,setReference:v,setFloating:w}),[v,w]),z=u.useMemo(()=>({reference:N,floating:k}),[N,k]),U=u.useMemo(()=>{const P={position:s,left:0,top:0};if(!z.floating)return P;const W=F0(z.floating,h.x),L=F0(z.floating,h.y);return o?{...P,transform:"translate("+W+"px, "+L+"px)",...p$(z.floating)>=1.5&&{willChange:"transform"}}:{position:s,left:W,top:L}},[s,o,z.floating,h.x,h.y]);return u.useMemo(()=>({...h,update:O,refs:_,elements:z,floatingStyles:U}),[h,O,_,z,U])}const b4=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?L0({element:r.current,padding:a}).fn(s):{}:r?L0({element:r,padding:a}).fn(s):{}}}},k4=(e,n)=>{const s=h4(e);return{name:s.name,fn:s.fn,options:[e,n]}},N4=(e,n)=>{const s=f4(e);return{name:s.name,fn:s.fn,options:[e,n]}},S4=(e,n)=>({fn:x4(e).fn,options:[e,n]}),C4=(e,n)=>{const s=m4(e);return{name:s.name,fn:s.fn,options:[e,n]}},E4=(e,n)=>{const s=p4(e);return{name:s.name,fn:s.fn,options:[e,n]}},A4=(e,n)=>{const s=g4(e);return{name:s.name,fn:s.fn,options:[e,n]}},$4=(e,n)=>{const s=b4(e);return{name:s.name,fn:s.fn,options:[e,n]}};var T4=Object.defineProperty,I4=(e,n)=>T4(e,"name",{value:n,configurable:!0});function g$(e){const[n,s]=u.useState(void 0);return ms(()=>{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,d=Array.isArray(c)?c[0]:c;l=d.inlineSize,o=d.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}I4(g$,"useSize");var R4=Object.defineProperty,Qa=(e,n)=>R4(e,"name",{value:n,configurable:!0}),x$="Popper",[v$,sm]=br(x$),[P4,j$]=v$(x$),M4=Qa(e=>{const{__scopePopper:n,children:s}=e,[r,a]=u.useState(null),[i,l]=u.useState(void 0);return t.jsx(P4,{scope:n,anchor:r,onAnchorChange:a,placementState:i,setPlacementState:l,children:s})},"Popper"),O4="PopperAnchor",D4=u.forwardRef(Qa(function(n,s){const{__scopePopper:r,virtualRef:a,...i}=n,l=j$(O4,r),o=u.useRef(null),c=l.onAnchorChange,d=u.useCallback(g=>{o.current=g,g&&c(g)},[c]),h=Tt(s,d),f=u.useRef(null);u.useEffect(()=>{if(!a)return;const g=f.current;f.current=a.current,g!==f.current&&c(f.current)});const m=l.placementState&&rm(l.placementState),p=m==null?void 0:m[0],x=m==null?void 0:m[1];return a?null:t.jsx(St.div,{"data-radix-popper-side":p,"data-radix-popper-align":x,...i,ref:h})},"PopperAnchor")),w$="PopperContent",[L4,Xie]=v$(w$),F4=u.forwardRef(Qa(function(n,s){var ce,xe,De,B,ne,Z,ve;const{__scopePopper:r,side:a="bottom",sideOffset:i=0,align:l="center",alignOffset:o=0,arrowPadding:c=0,avoidCollisions:d=!0,collisionBoundary:h=[],collisionPadding:f=0,sticky:m="partial",hideWhenDetached:p=!1,updatePositionStrategy:x="optimized",onPlaced:g,...y}=n,j=j$(w$,r),[v,w]=u.useState(null),N=Tt(s,w),[k,S]=u.useState(null),b=g$(k),C=(b==null?void 0:b.width)??0,$=(b==null?void 0:b.height)??0,A=a+(l!=="center"?"-"+l:""),I=typeof f=="number"?f:{top:0,right:0,bottom:0,left:0,...f},M=Array.isArray(h)?h:[h],O=M.length>0,R={padding:I,boundary:M.filter(y$),altBoundary:O},{refs:_,floatingStyles:z,placement:U,isPositioned:P,middlewareData:W}=y4({strategy:"fixed",placement:A,whileElementsMounted:Qa((...$e)=>u4(...$e,{animationFrame:x==="always"}),"whileElementsMounted"),elements:{reference:j.anchor},middleware:[k4({mainAxis:i+$,alignmentAxis:o}),d&&N4({mainAxis:!0,crossAxis:!1,limiter:m==="partial"?S4():void 0,...R}),d&&C4({...R}),E4({...R,apply:Qa(({elements:$e,rects:Se,availableWidth:me,availableHeight:Ee})=>{const{width:Pe,height:Me}=Se.reference,he=$e.floating.style;he.setProperty("--radix-popper-available-width",`${me}px`),he.setProperty("--radix-popper-available-height",`${Ee}px`),he.setProperty("--radix-popper-anchor-width",`${Pe}px`),he.setProperty("--radix-popper-anchor-height",`${Me}px`)},"apply")}),k&&$4({element:k,padding:c}),_4({arrowWidth:C,arrowHeight:$}),p&&A4({strategy:"referenceHidden",...R,boundary:O?R.boundary:void 0})]}),L=j.setPlacementState;ms(()=>(L(U),()=>{L(void 0)}),[U,L]);const[Q,F]=rm(U),ae=ss(g);ms(()=>{P&&(ae==null||ae())},[P,ae]);const V=(ce=W.arrow)==null?void 0:ce.x,J=(xe=W.arrow)==null?void 0:xe.y,H=((De=W.arrow)==null?void 0:De.centerOffset)!==0,[X,G]=u.useState();return ms(()=>{v&&G(window.getComputedStyle(v).zIndex)},[v]),t.jsx("div",{ref:_.setFloating,"data-radix-popper-content-wrapper":"",style:{...z,transform:P?z.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:X,"--radix-popper-transform-origin":[(B=W.transformOrigin)==null?void 0:B.x,(ne=W.transformOrigin)==null?void 0:ne.y].join(" "),...((Z=W.hide)==null?void 0:Z.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:n.dir,children:t.jsx(L4,{scope:r,placedSide:Q,placedAlign:F,onArrowChange:S,arrowX:V,arrowY:J,shouldHideArrow:H,children:t.jsx(St.div,{"data-side":Q,"data-align":F,...y,ref:N,style:{...y.style,animation:P?(ve=y.style)==null?void 0:ve.animation:"none"}})})})},"PopperContent"));function y$(e){return e!==null}Qa(y$,"isNotNull");var _4=Qa(e=>({name:"transformOrigin",options:e,fn(n){var y,j,v;const{placement:s,rects:r,middlewareData:a}=n,l=((y=a.arrow)==null?void 0:y.centerOffset)!==0,o=l?0:e.arrowWidth,c=l?0:e.arrowHeight,[d,h]=rm(s),f={start:"0%",center:"50%",end:"100%"}[h],m=(((j=a.arrow)==null?void 0:j.x)??0)+o/2,p=(((v=a.arrow)==null?void 0:v.y)??0)+c/2;let x="",g="";return d==="bottom"?(x=l?f:`${m}px`,g=`${-c}px`):d==="top"?(x=l?f:`${m}px`,g=`${r.floating.height+c}px`):d==="right"?(x=`${-c}px`,g=l?f:`${p}px`):d==="left"&&(x=`${r.floating.width+c}px`,g=l?f:`${p}px`),{data:{x,y:g}}}}),"transformOrigin");function rm(e){const[n,s="center"]=e.split("-");return[n,s]}Qa(rm,"getSideAndAlignFromPlacement");var Iw=M4,b$=D4,k$=F4,z4=Object.defineProperty,$n=(e,n)=>z4(e,"name",{value:n,configurable:!0}),[Rw,Zie]=br("Tooltip",[sm]),Pw=sm(),U4="TooltipProvider",B4=700,Dx="tooltip.open",[W4,Mw]=Rw(U4),H4=$n(e=>{const{__scopeTooltip:n,delayDuration:s=B4,skipDelayDuration:r=300,disableHoverableContent:a=!1,children:i}=e,l=u.useRef(!0),o=u.useRef(!1),c=u.useRef(0);return u.useEffect(()=>{const d=c.current;return()=>window.clearTimeout(d)},[]),t.jsx(W4,{scope:n,isOpenDelayedRef:l,delayDuration:s,onOpen:u.useCallback(()=>{r<=0||(window.clearTimeout(c.current),l.current=!1)},[r]),onClose:u.useCallback(()=>{r<=0||(window.clearTimeout(c.current),c.current=window.setTimeout(()=>l.current=!0,r))},[r]),isPointerInTransitRef:o,onPointerInTransitChange:u.useCallback(d=>{o.current=d},[]),disableHoverableContent:a,children:i})},"TooltipProvider"),Lx="Tooltip",[K4,Td]=Rw(Lx),V4=$n(e=>{const{__scopeTooltip:n,children:s,open:r,defaultOpen:a,onOpenChange:i,disableHoverableContent:l,delayDuration:o}=e,c=Mw(Lx,e.__scopeTooltip),d=Pw(n),[h,f]=u.useState(null),[m,p]=u.useState(void 0),x=ur(),g=u.useRef(0),y=l??c.disableHoverableContent,j=o??c.delayDuration,v=u.useRef(!1),[w,N]=fi({prop:r,defaultProp:a??!1,onChange:$n(A=>{A?(c.onOpen(),document.dispatchEvent(new CustomEvent(Dx))):c.onClose(),i==null||i(A)},"onChange"),caller:Lx}),k=u.useMemo(()=>w?v.current?"delayed-open":"instant-open":"closed",[w]),S=u.useCallback(()=>{window.clearTimeout(g.current),g.current=0,v.current=!1,N(!0)},[N]),b=u.useCallback(()=>{window.clearTimeout(g.current),g.current=0,N(!1)},[N]),C=u.useCallback(()=>{window.clearTimeout(g.current),g.current=window.setTimeout(()=>{v.current=!0,N(!0),g.current=0},j)},[j,N]);u.useEffect(()=>()=>{g.current&&(window.clearTimeout(g.current),g.current=0)},[]);const $=m??x;return t.jsx(Iw,{...d,children:t.jsx(K4,{scope:n,contentId:$,setContentId:p,open:w,stateAttribute:k,trigger:h,onTriggerChange:f,onTriggerEnter:u.useCallback(()=>{c.isOpenDelayedRef.current?C():S()},[c.isOpenDelayedRef,C,S]),onTriggerLeave:u.useCallback(()=>{y?b():(window.clearTimeout(g.current),g.current=0)},[b,y]),onOpen:S,onClose:b,disableHoverableContent:y,children:s})})},"Tooltip"),_0="TooltipTrigger",G4=u.forwardRef($n(function(n,s){const{__scopeTooltip:r,...a}=n,i=Td(_0,r),l=Mw(_0,r),o=Pw(r),c=u.useRef(null),d=Tt(s,c,i.onTriggerChange),h=u.useRef(!1),f=u.useRef(!1),m=u.useCallback(()=>h.current=!1,[]);return u.useEffect(()=>()=>document.removeEventListener("pointerup",m),[m]),t.jsx(b$,{asChild:!0,...o,children:t.jsx(St.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...a,ref:d,onPointerMove:We(n.onPointerMove,p=>{p.pointerType!=="touch"&&!f.current&&!l.isPointerInTransitRef.current&&(i.onTriggerEnter(),f.current=!0)}),onPointerLeave:We(n.onPointerLeave,()=>{i.onTriggerLeave(),f.current=!1}),onPointerDown:We(n.onPointerDown,()=>{i.open&&i.onClose(),h.current=!0,document.addEventListener("pointerup",m,{once:!0})}),onFocus:We(n.onFocus,()=>{h.current||i.onOpen()}),onBlur:We(n.onBlur,i.onClose),onClick:We(n.onClick,i.onClose)})})},"TooltipTrigger")),N$="TooltipPortal",[q4,Y4]=Rw(N$,{forceMount:void 0}),Q4=$n(e=>{const{__scopeTooltip:n,forceMount:s,children:r,container:a}=e,i=Td(N$,n);return t.jsx(q4,{scope:n,forceMount:s,children:t.jsx(Gr,{present:s||i.open,children:t.jsx(Yf,{asChild:!0,container:a,children:r})})})},"TooltipPortal"),Zc="TooltipContent",J4=u.forwardRef($n(function(n,s){const r=Y4(Zc,n.__scopeTooltip),{forceMount:a=r.forceMount,side:i="top",...l}=n,o=Td(Zc,n.__scopeTooltip);return t.jsx(Gr,{present:a||o.open,children:o.disableHoverableContent?t.jsx(S$,{side:i,...l,ref:s}):t.jsx(X4,{side:i,...l,ref:s})})},"TooltipContent")),X4=u.forwardRef($n(function(n,s){const r=Td(Zc,n.__scopeTooltip),a=Mw(Zc,n.__scopeTooltip),i=u.useRef(null),l=Tt(s,i),[o,c]=u.useState(null),{trigger:d,onClose:h}=r,f=i.current,{onPointerInTransitChange:m}=a,p=u.useCallback(()=>{c(null),m(!1)},[m]),x=u.useCallback((g,y)=>{const j=g.currentTarget,v={x:g.clientX,y:g.clientY},w=C$(v,j.getBoundingClientRect()),N=E$(v,w),k=A$(y.getBoundingClientRect()),S=T$([...N,...k]);c(S),m(!0)},[m]);return u.useEffect(()=>()=>p(),[p]),u.useEffect(()=>{if(d&&f){const g=$n(j=>x(j,f),"handleTriggerLeave"),y=$n(j=>x(j,d),"handleContentLeave");return d.addEventListener("pointerleave",g),f.addEventListener("pointerleave",y),()=>{d.removeEventListener("pointerleave",g),f.removeEventListener("pointerleave",y)}}},[d,f,x,p]),u.useEffect(()=>{if(o){const g=$n(y=>{const j=y.target,v={x:y.clientX,y:y.clientY},w=(d==null?void 0:d.contains(j))||(f==null?void 0:f.contains(j)),N=!$$(v,o);w?p():N&&(p(),h())},"handleTrackPointerGrace");return document.addEventListener("pointermove",g),()=>document.removeEventListener("pointermove",g)}},[d,f,o,h,p]),t.jsx(S$,{...n,ref:l})},"TooltipContentHoverable")),Z4=PA("TooltipContent"),S$=u.forwardRef($n(function(n,s){const{__scopeTooltip:r,children:a,"aria-label":i,id:l,onEscapeKeyDown:o,onPointerDownOutside:c,...d}=n,h=Td(Zc,r),f=Pw(r),{onClose:m}=h;u.useEffect(()=>(document.addEventListener(Dx,m),()=>document.removeEventListener(Dx,m)),[m]),u.useEffect(()=>{if(h.trigger){const x=$n(g=>{g.target instanceof Node&&g.target.contains(h.trigger)&&m()},"handleScroll");return window.addEventListener("scroll",x,{capture:!0}),()=>window.removeEventListener("scroll",x,{capture:!0})}},[h.trigger,m]);const{setContentId:p}=h;return ms(()=>(p(l),()=>{p(void 0)}),[l,p]),t.jsx(qf,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:o,onPointerDownOutside:c,onFocusOutside:x=>x.preventDefault(),onDismiss:m,children:t.jsxs(k$,{"data-state":h.stateAttribute,role:i?void 0:"tooltip",id:i?void 0:h.contentId,...f,...d,ref:s,style:{...d.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(Z4,{children:a}),i?t.jsx(GF,{id:h.contentId,role:"tooltip",children:i}):null]})})},"TooltipContentImpl"));function C$(e,n){const s=Math.abs(n.top-e.y),r=Math.abs(n.bottom-e.y),a=Math.abs(n.right-e.x),i=Math.abs(n.left-e.x);switch(Math.min(s,r,a,i)){case i:return"left";case a:return"right";case s:return"top";case r:return"bottom";default:throw new Error("unreachable")}}$n(C$,"getExitSideFromRect");function E$(e,n,s=5){const r=[];switch(n){case"top":r.push({x:e.x-s,y:e.y+s},{x:e.x+s,y:e.y+s});break;case"bottom":r.push({x:e.x-s,y:e.y-s},{x:e.x+s,y:e.y-s});break;case"left":r.push({x:e.x+s,y:e.y-s},{x:e.x+s,y:e.y+s});break;case"right":r.push({x:e.x-s,y:e.y-s},{x:e.x-s,y:e.y+s});break}return r}$n(E$,"getPaddedExitPoints");function A$(e){const{top:n,right:s,bottom:r,left:a}=e;return[{x:a,y:n},{x:s,y:n},{x:s,y:r},{x:a,y:r}]}$n(A$,"getPointsFromRect");function $$(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],d=o.x,h=o.y,f=c.x,m=c.y;h>r!=m>r&&s<(f-d)*(r-h)/(m-h)+d&&(a=!a)}return a}$n($$,"isPointInPolygon");function T$(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),I$(n)}$n(T$,"getHull");function I$(e){if(e.length<=1)return e.slice();const n=[];for(let r=0;r<e.length;r++){const a=e[r];for(;n.length>=2;){const i=n[n.length-1],l=n[n.length-2];if((i.x-l.x)*(a.y-l.y)>=(i.y-l.y)*(a.x-l.x))n.pop();else break}n.push(a)}n.pop();const s=[];for(let r=e.length-1;r>=0;r--){const a=e[r];for(;s.length>=2;){const i=s[s.length-1],l=s[s.length-2];if((i.x-l.x)*(a.y-l.y)>=(i.y-l.y)*(a.x-l.x))s.pop();else break}s.push(a)}return s.pop(),n.length===1&&s.length===1&&n[0].x===s[0].x&&n[0].y===s[0].y?n:n.concat(s)}$n(I$,"getHullPresorted");var z0=H4,ed=V4,td=G4,nd=Q4,sd=J4;let pn={time:"auto",date:"auto",locale:void 0};function Ow(e){const n=e.timeFormat===void 0?pn.time:e.timeFormat==="12h"||e.timeFormat==="24h"?e.timeFormat:"auto",s=e.dateFormat===void 0?pn.date:e.dateFormat==="short"||e.dateFormat==="long"||e.dateFormat==="iso"?e.dateFormat:"auto";pn={time:n,date:s,locale:e.locale??pn.locale}}function R$(){return{time:pn.time,date:pn.date}}function Id(e,n){const s=pn;Ow(e);try{return n()}finally{pn=s}}const Fx="buddi:formats";function Rd(){if(pn.locale)return pn.locale;try{return typeof navigator<"u"&&navigator.language?navigator.language:"en-US"}catch{return"en-US"}}const U0=new Map;function Eo(e,n){const s=`${e}|${JSON.stringify(n)}`;let r=U0.get(s);if(!r){try{r=new Intl.DateTimeFormat(e,n)}catch{r=new Intl.DateTimeFormat(e,{...n,timeZone:"UTC"})}U0.set(s,r)}return r}function Sp(e,n,s,r){return Object.fromEntries(Eo(s,{timeZone:n,...r}).formatToParts(e).map(a=>[a.type,a.value]))}function ez(){return pn.time==="12h"?{hour:"numeric",minute:"2-digit",hourCycle:"h12"}:pn.time==="24h"?{hour:"2-digit",minute:"2-digit",hourCycle:"h23"}:{hour:am()?"numeric":"2-digit",minute:"2-digit"}}function tz(){return pn.time==="auto"?Rd():"en-US"}function $t(e,n){return Number.isNaN(e.getTime())?"—":Eo(tz(),{timeZone:n,...ez()}).format(e)}function nz(e){return e>=1440&&!am()?"24:00":$t(new Date(Date.UTC(2026,0,1,Math.floor(e/60)%24,e%60)),"UTC")}function am(){var e;return pn.time!=="auto"?pn.time==="12h":((e=Eo(Rd(),{hour:"numeric"}).resolvedOptions().hourCycle)==null?void 0:e.startsWith("h1"))===!0}function P$(){return`Profile (${am()?"12-hour":"24-hour"})`}function sz(){if(pn.date!=="auto")return pn.date==="short";const e=Eo(Rd(),{month:"short",day:"numeric"}).formatToParts(new Date(Date.UTC(2026,9,1))).map(n=>n.type);return e.indexOf("month")<e.indexOf("day")}function Nr(e,n,s={}){return rz(e,n,s).replace(/\bSept\b/g,"Sep")}function rz(e,n,s){if(Number.isNaN(e.getTime()))return"—";const{weekday:r=!1,year:a=!1,compact:i=!1}=s;switch(pn.date){case"iso":{const l=Sp(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=Sp(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=Sp(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 Eo(Rd(),{timeZone:n,month:i?"short":"long",day:"numeric",...a?{year:"numeric"}:{},...r?{weekday:i?"short":"long"}:{}}).format(e)}}function M$(e,n){if(pn.date==="iso")return`${e}-${String(n).padStart(2,"0")}`;const s=new Date(Date.UTC(e,n-1,15)),r=pn.date==="auto"?Rd():"en-GB";return Eo(r,{timeZone:"UTC",month:"long",year:"numeric"}).format(s)}function Pd(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:Nr(r,"UTC",n)}function ft(e,n){if(!e)return"—";const s=new Date(e);return Number.isNaN(s.getTime())?String(e):`${Nr(s,n,{year:!0,compact:!0})}, ${$t(s,n)}`}function im(e,n){return`${Nr(e,n,{weekday:!0,compact:!0})}, ${$t(e,n)}`}function Ge(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 Dw(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 O$(e,n=Date.now()){const s=Dw(e,n);return s===""?"":s==="now"||new Date(e).getTime()>n?"just now":s==="1 d"?"yesterday":`${s} ago`}function az(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 fn(e){return new Intl.NumberFormat("en-US").format(e)}function _x(e){return[...e.cacheRead?[`cached ${fn(e.cacheRead)}`]:[],...e.cacheWrite?[`cache write ${fn(e.cacheWrite)}`]:[]].join(", ")}function iz(e){const n=_x(e);return`${fn(e.input)} in${n?` (${n})`:""} / ${fn(e.output)} out`}function rs(e){try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function rd(e,n=8){return e.length<=n?e:e.slice(0,n)}function mr(e,n){return e.length<=n?e:`${e.slice(0,n-1)}…`}function ad(e){if(e.kind!=="agent")return e.title;const n=e.title.replace(/^@[^\s:]+:\s+/,"");return n.trim()===""?e.title:n}const B0="buddi_csrf",Ao="x-buddi-csrf",xs="buddi:agents-changed",Mi="buddi:status-changed",Qo=e=>(window.dispatchEvent(new Event(Mi)),e),zx="buddi:locked",lz="This page's sign-in no longer matches its cookies. Reload the page and try again.";class fe extends Error{constructor(n,s,r){super(s),this.status=n,this.detail=r,this.name="ApiError"}}function sl(){var r;const e=Number(location.port)||(location.protocol==="https:"?443:80),n=document.cookie.match(new RegExp(`(?:^|; )${B0}_${e}=([^;]*)`));if(n!=null&&n[1])return decodeURIComponent(n[1]);const s=[...document.cookie.matchAll(new RegExp(`(?:^|; )${B0}(?:_\\d+)?=([^;]*)`,"g"))];return s.length===1&&((r=s[0])!=null&&r[1])?decodeURIComponent(s[0][1]):""}const Vh="buddi isn't answering.";let Ux=null;const Bx=new Set;function Jo(e){if(e!==(Ux===null)){Ux=e?null:Date.now();for(const n of Bx)n()}}function id(){return Ux}function Lw(e){return Bx.add(e),()=>Bx.delete(e)}function Gh(e){return e instanceof fe&&(e.status===0||e.status===502||e.status===503)&&e.message===Vh}async function rl(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:(Jo(!1),new fe(0,Vh,o))}if(s.status===401)throw Jo(!0),new fe(401,"This session has expired. Run `buddi dashboard` for a fresh link.");if(s.status===423)throw Jo(!0),window.dispatchEvent(new Event(zx)),new fe(423,"This dashboard is locked.");const r=await s.text(),a=r===""?null:oz(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 Jo(!1),new fe(s.status,Vh,a);if(Jo(!0),!s.ok){const o=(n.method??"GET").toUpperCase(),c=i??(s.status===403&&o!=="GET"&&o!=="HEAD"?lz:`request failed (${s.status})`);throw new fe(s.status,c,a)}return a}function oz(e){try{return JSON.parse(e)}catch{return null}}function Cp(){return R$().time==="auto"?{hour:am()?"12":"24"}:{}}function je(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 rl(`/api${e}${r?`?${r}`:""}`)}function rh(e,n){return rl(`/api${e}`,{method:"POST",headers:{[Ao]:sl()},body:n})}function Ws(e){return rl(`/api${e}`,{method:"DELETE",headers:{[Ao]:sl()}})}function te(e,n={}){return rl(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/json",[Ao]:sl()},body:JSON.stringify(n??{})})}function Fw(e,n,s,r={}){const a=n.name.replace(/[^\w.-]+/g,"_").slice(-120)||s;return rl(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/octet-stream",[Ao]:sl(),"X-Filename":a,...r},body:n})}function W0(e,n,s){return Fw(e,n,"backup.tar.gz",{...s.passphrase?{"X-Backup-Passphrase":s.passphrase}:{},...s.confirm?{"X-Backup-Confirm":s.confirm}:{}})}function cz(e,n={}){return rl(`/api${e}`,{method:"PATCH",headers:{"Content-Type":"application/json",[Ao]:sl()},body:JSON.stringify(n??{})})}function $r(e,n={}){return rl(`/api${e}`,{method:"PUT",headers:{"Content-Type":"application/json",[Ao]:sl()},body:JSON.stringify(n??{})})}function dz(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 ah="gpt-oss:120b",uz=["approval","question","watcher","reminder","failure","recap","plugin","agent"],Wx=["mon","tue","wed","thu","fri","sat","sun"],Xe={agents:()=>je("/chat/agents"),views:()=>je("/chat/views"),conversations:(e,n)=>je(`/chat/${encodeURIComponent(e)}/conversations`,{limit:n}),startConversation:e=>te(`/chat/${encodeURIComponent(e)}/conversations`),conversation:e=>je(`/chat/conversations/${encodeURIComponent(e)}`),deleteCarryOver:e=>Ws(`/chat/conversations/${encodeURIComponent(e)}/carry-over`),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),rh("/chat/attachments",n)},transcribe:e=>te("/speech/transcribe",e),say:e=>te("/speech/say",e),discardAttachment:e=>Ws(`/artifacts/${encodeURIComponent(e)}`),groups:()=>je("/groups"),group:e=>je(`/groups/${encodeURIComponent(e)}`),createGroup:e=>te("/groups",e),updateGroup:(e,n)=>cz(`/groups/${encodeURIComponent(e)}`,n),deleteGroup:e=>Ws(`/groups/${encodeURIComponent(e)}`),restoreGroup:e=>te(`/groups/${encodeURIComponent(e)}/restore`),clearGroup:e=>te(`/groups/${encodeURIComponent(e)}/clear`),groupConversations:e=>je(`/groups/${encodeURIComponent(e)}/conversations`),startGroupConversation:e=>te(`/groups/${encodeURIComponent(e)}/conversations`),sendToGroup:(e,n)=>te(`/groups/${encodeURIComponent(e)}/messages`,n),streamUrl:e=>`/api/chat/conversations/${encodeURIComponent(e)}/stream`};function _w(e){return e.httpStatus===401||e.httpStatus===403||e.state==="authentication-error"||e.state==="access-denied"}const T={providers:()=>je("/providers"),providerAccounts:()=>je("/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=>je(`/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",{}),previewLink:(e,n)=>je(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(n)}/link`),previewCheck:(e,n)=>je(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(n)}/check`),extension:()=>je("/extension"),pairExtension:e=>te("/extension/pair",{code:e}),forgetExtension:()=>Ws("/extension/pair"),session:()=>je("/session"),overview:()=>je("/overview"),events:e=>je("/events",e),eventKinds:()=>je("/events/kinds"),conversations:()=>je("/conversations"),conversation:e=>je(`/conversations/${encodeURIComponent(e)}`),missions:()=>je("/missions"),jobs:(e={})=>je("/jobs",e),approvals:()=>je("/approvals"),approval:e=>je(`/approvals/${encodeURIComponent(e)}`).then(n=>n.action),offers:()=>je("/offers"),dismissOffer:e=>te(`/offers/${encodeURIComponent(e)}/dismiss`,{}),dismissOffers:e=>te("/offers/dismiss-all",{ids:e}),agentOffers:()=>je("/agent-offers"),catalogue:(e=!1)=>je(`/catalogue${e?"?refresh=1":""}`),cataloguePlan:(e,n={})=>te(`/catalogue/${encodeURIComponent(e)}/plan`,n),catalogueInstall:(e,n)=>te(`/catalogue/${encodeURIComponent(e)}/install`,n),catalogueJob:e=>je(`/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=>je(`/agents/${encodeURIComponent(e)}/remove`),removeAgent:e=>te(`/agents/${encodeURIComponent(e)}/remove`),dismissAgentOffer:(e,n)=>te(`/agent-offers/${encodeURIComponent(e)}/${encodeURIComponent(n)}/dismiss`,{}),proposals:()=>je("/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:()=>je("/reminders"),sentinels:()=>je("/sentinels"),setSentinelEnabled:(e,n)=>te(`/sentinels/${encodeURIComponent(e)}/enabled`,{enabled:n}),widgets:(e="home")=>je("/widgets",{...e==="lock"?{surface:e}:{},...Cp()}),saveWidgets:(e,n)=>$r(`/widgets/${e}`,{placements:n.map(({key:s,widget:r,size:a,settings:i})=>({...s?{key:s}:{},widget:r,size:a,settings:i}))}),widgetSettings:e=>je(`/widgets/settings/${encodeURIComponent(e)}`),previewWidget:e=>te("/widgets/preview",{...e,...Cp()}),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:()=>je("/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:()=>je("/agents"),library:e=>je("/artifacts",e),libraryEntry:(e,n=0)=>je(`/artifacts/${encodeURIComponent(e)}`,n?{contexts:n}:{}),onboarding:()=>je("/onboarding"),onboardingStep:(e,n={})=>te("/onboarding/step",{step:e,...n}),takeOn:e=>te("/onboarding/take-on",{tiles:e}),takeOnProgress:()=>je("/onboarding/take-on"),completeOnboarding:()=>te("/onboarding/complete"),skipOnboarding:()=>te("/onboarding/skip"),createFirstAgent:e=>te("/onboarding/agent",e),ollama:()=>je("/onboarding/ollama"),ollamaPull:e=>te("/onboarding/ollama/pull",{model:e}),ollamaPullState:()=>je("/onboarding/ollama/pull"),mlxh:()=>je("/onboarding/mlxh"),firstAgentPersona:()=>je("/onboarding/agent"),updateFirstAgent:e=>te("/onboarding/agent/update",e),bindBrain:e=>te("/onboarding/brain",e),pages:()=>je("/pages"),pageQuery:(e,n,s={})=>je(`/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:()=>je("/telegram"),saveTelegramToken:e=>te("/telegram/token",{token:e}),telegramPairing:()=>te("/telegram/pairing"),telegramBot:()=>je("/telegram/bot"),telegramDevices:()=>je("/telegram/devices"),unpairTelegramDevice:e=>Ws(`/telegram/devices/${encodeURIComponent(e)}`),notifications:(e=20)=>je("/notifications",{limit:e}),notificationsNeedingYou:()=>je("/notifications",{needs:1}),notificationSeen:e=>te(`/notifications/${encodeURIComponent(e)}/seen`),notificationSettings:()=>je("/notifications/settings"),saveNotificationSettings:e=>$r("/notifications/settings",e),focus:()=>je("/notifications/focus"),lockState:()=>je("/lock"),lockScreen:()=>je("/lock/screen",Cp()),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)=>$r("/lock/pin",n===void 0?{pin:e}:{pin:e,current:n}),removePin:e=>te("/lock/pin/remove",{current:e}),setLockSettings:e=>$r("/lock/settings",e),uploadLockBackground:e=>{const n=new FormData;return n.append("file",e),rh("/lock/background",n)},removeLockBackground:()=>Ws("/lock/background"),uploadLockPortrait:e=>{const n=new FormData;return n.append("file",e),rh("/lock/background/portrait",n)},removeLockPortrait:()=>Ws("/lock/background/portrait"),setFocus:(e,n)=>$r("/notifications/focus",n?{mode:e,duration:n}:{mode:e}).then(Qo),testChannel:e=>te("/notifications/test",{channel:e}),setAgentMuted:(e,n)=>te("/notifications/agent-mute",{agentId:e,muted:n}),currentTip:e=>je(e?`/tips/current?preview=${encodeURIComponent(e)}`:"/tips/current"),tipQueue:(e,n)=>je(e?`/tips/queue?preview=${encodeURIComponent(e)}`:n?"/tips/queue?peek=1":"/tips/queue"),tips:()=>je("/tips"),dismissedTips:()=>je("/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:()=>je("/owner"),setOwner:e=>te("/owner",e),findPlace:e=>te("/owner/places/find",{address:e}),savePlace:e=>te("/owner/places",e),removePlace:e=>te("/owner/places/remove",{id:e}),memory:e=>je(e?`/memory?agent=${encodeURIComponent(e)}`:"/memory"),setPreference:e=>te("/memory/preferences",e),forgetPreference:e=>te("/memory/preferences/forget",e),updateNote:(e,n)=>te(`/memory/notes/${encodeURIComponent(e)}`,n),forgetNote:e=>te(`/memory/notes/${encodeURIComponent(e)}/forget`),people:()=>je("/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:()=>je("/owner/birthday"),agentIntro:e=>je(`/agents/${encodeURIComponent(e)}/intro`),dismissAgentIntro:e=>te(`/agents/${encodeURIComponent(e)}/intro/dismiss`),setDelegates:(e,n)=>te(`/agents/${encodeURIComponent(e)}/delegates`,{delegates:n}),agentProfile:e=>je(`/agents/${encodeURIComponent(e)}/profile`),agentSkills:e=>je(`/agents/${encodeURIComponent(e)}/skills`),removeSkill:(e,n)=>te(`/agents/${encodeURIComponent(e)}/skills/${encodeURIComponent(n)}/remove`,{}),host:(e,n)=>je("/host",{agentId:e,conversationId:n}),connections:()=>je("/connections"),connection:e=>je(`/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=>je(`/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=>Ws(`/connections/${e}`),connectionSignals:()=>je("/connections/signals"),connectionTools:e=>je(`/connections/${e}/tools`),rememberedApprovals:e=>je(`/connections/remembered/${encodeURIComponent(e)}`),setRememberedApproval:(e,n,s)=>te("/connections/remembered",{agent:e,tool:n,remember:s}),secrets:()=>je("/secrets"),secretUses:(e,n)=>je("/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(Qo),service:()=>je("/service"),serviceAction:e=>te(`/service/${e}`),version:()=>je("/version"),checkVersion:()=>te("/version/check"),setVersionCheck:e=>$r("/version/check",{enabled:e}),tailscale:()=>je("/access/tailscale"),setTailscale:e=>$r("/access/tailscale",e),access:()=>je("/access"),cloudflareAccess:()=>je("/access/cloudflare-access"),setCloudflareAccess:e=>$r("/access/cloudflare-access",e),testCloudflareAccess:e=>te("/access/cloudflare-access/test",e),cloudflareSetup:()=>je("/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:()=>je("/api-tokens"),createApiToken:e=>te("/api-tokens",{name:e}),revokeApiToken:e=>Ws(`/api-tokens/${encodeURIComponent(e)}`),startUpgrade:e=>te("/upgrade",e===void 0?{}:{version:e}),upgradeJob:e=>je(`/upgrade/jobs/${encodeURIComponent(e)}`),backups:()=>je("/backups"),startBackup:e=>te("/backups",{encrypt:e}),verifyArchive:e=>te("/backups/verify",{name:e}),restoreArchive:e=>te("/backups/restore",e),restoreUpload:(e,n)=>W0("/backups/restore",e,n),backupJob:e=>je(`/backups/jobs/${encodeURIComponent(e)}`),backupSchedule:()=>je("/backups/schedule"),setBackupSchedule:e=>$r("/backups/schedule",e),backupPassphrase:()=>je("/backups/passphrase"),revealBackupPassphrase:e=>te("/backups/passphrase/reveal",e===void 0?{}:{pin:e}),cliTool:()=>je("/system/cli"),installCliTool:()=>te("/system/cli",{}),uninstallPlan:()=>je("/system/uninstall"),uninstallBackup:e=>te("/system/uninstall/backup",{token:e}),uninstallJob:e=>je(`/system/uninstall/jobs/${encodeURIComponent(e)}`),uninstall:e=>te("/system/uninstall",e),passphraseNotice:()=>je("/backups/passphrase/notice"),acknowledgePassphrase:()=>te("/backups/passphrase/notice",{}),setBackupPassphrase:e=>$r("/backups/passphrase",{passphrase:e}),plugins:()=>je("/plugins"),market:(e=!1)=>je(`/market${e?"?refresh=1":""}`),marketAssetUrl:e=>`/api/market/asset?url=${encodeURIComponent(e)}`,pluginFolders:e=>je("/plugins/folders",e?{path:e}:{}),stagePlugin:e=>te("/plugins/stage",{spec:e}),uploadPlugin:e=>Fw("/plugins/upload",e,"plugin.tgz"),pluginJob:e=>je(`/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:()=>je("/recovery"),leaveRecovery:e=>te("/recovery/leave",e),firstRunRestore:(e,n)=>W0("/onboarding/restore",e,{passphrase:n}),setMissionEnabled:(e,n)=>te(`/missions/${encodeURIComponent(e)}/enabled`,{enabled: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:()=>je("/jobs/failures"),dismissJobs:e=>te("/jobs/dismiss",e).then(Qo),undismissJobs:e=>te("/jobs/undismiss",{ids:e}).then(Qo),retryJobs:e=>te("/jobs/retry",e).then(Qo),setDefaultAgent:e=>te("/agents/default",{agentId:e}),agentTools:e=>je(`/agents/${encodeURIComponent(e)}/tools`),agentFile:e=>je(`/agents/${encodeURIComponent(e)}/file`),uploadAgentPicture:(e,n)=>{const s=new FormData;return s.append("file",n,n.name),rh(`/agents/${encodeURIComponent(e)}/avatar`,s)},removeAgentPicture:e=>Ws(`/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"})},Hx="buddi.chatDraft";function Md(e,n){try{window.sessionStorage.setItem(Hx,JSON.stringify({agentId:e,text:n}))}catch{}}function hz(e){try{const n=window.sessionStorage.getItem(Hx);if(!n)return null;const s=JSON.parse(n);return s.agentId!==e||typeof s.text!="string"?null:(window.sessionStorage.removeItem(Hx),s.text)}catch{return null}}const fz=4e3,mz={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"},D$=e=>mz[e.toLowerCase()]??e;function lm(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 kc(e,n){return(e.slice(0,lm(e,n).start).match(/^```/gm)??[]).length%2===1}function pz(e,n){const s=e.slice(0,n),r=/(^|[\s(])@([a-z0-9-]*)$/i.exec(s);return!r||kc(e,n)?null:{start:n-r[2].length-1,query:r[2]}}function gz(e,n){const s=/^\/([a-z0-9-]*)$/i.exec(e.slice(0,n));return s?{query:s[1]}:null}function xz(e,n){return/^\/use @?[a-z0-9-]*$/i.test(e.slice(0,n))}function vz(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 jz(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 wz=/^(\s*)([-*]|\d+\.)( )(.*)$/;function zw(e,n){if(kc(e,n))return null;const s=wz.exec(lm(e,n).text);return s?{indent:s[1],mark:s[2],body:s[4]}:null}function yz(e,n){const s=zw(e,n);if(!s)return null;const r=lm(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 bz(e,n,s){if(!zw(e,n))return null;const r=lm(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 kz(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 Nz(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 Sz(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 Cz(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 L$(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 F$(e){return e==="anthropic"||e==="openai"}function _$(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 Ez="Thinking is up to this model. What it writes while thinking is shown apart and kept out of the answer.";var Az=Object.defineProperty,$z=(e,n)=>Az(e,"name",{value:n,configurable:!0}),Tz=u.createContext(void 0);function om(e){const n=u.useContext(Tz);return e||n||"ltr"}$z(om,"useDirection");var Iz=Object.defineProperty,Uw=(e,n)=>Iz(e,"name",{value:n,configurable:!0}),vu=0,Tr=null;function Rz(e){return cm(),e.children}Uw(Rz,"FocusGuards");function cm(){u.useEffect(()=>{Tr||(Tr={start:Kx(),end:Kx()});const{start:e,end:n}=Tr;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==n&&document.body.insertAdjacentElement("beforeend",n),vu++,()=>{vu===1&&(Tr==null||Tr.start.remove(),Tr==null||Tr.end.remove(),Tr=null),vu=Math.max(0,vu-1)}},[])}Uw(cm,"useFocusGuards");function Kx(){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}Uw(Kx,"createFocusGuard");var Pz=Object.defineProperty,ts=(e,n)=>Pz(e,"name",{value:n,configurable:!0}),Ep="focusScope.autoFocusOnMount",Ap="focusScope.autoFocusOnUnmount",H0={bubbles:!1,cancelable:!0},z$=u.forwardRef(ts(function(n,s){const{loop:r=!1,trapped:a=!1,onMountAutoFocus:i,onUnmountAutoFocus:l,...o}=n,[c,d]=u.useState(null),h=ss(i),f=ss(l),m=u.useRef(null),p=Tt(s,d),x=u.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;u.useEffect(()=>{if(a){let y=function(N){if(x.paused||!c)return;const k=N.target;c.contains(k)?m.current=k:sa(m.current,{select:!0})},j=function(N){if(x.paused||!c)return;const k=N.relatedTarget;k!==null&&(c.contains(k)||sa(m.current,{select:!0}))},v=function(N){if(document.activeElement===document.body)for(const S of N)S.removedNodes.length>0&&sa(c)};ts(y,"handleFocusIn"),ts(j,"handleFocusOut"),ts(v,"handleMutations"),document.addEventListener("focusin",y),document.addEventListener("focusout",j);const w=new MutationObserver(v);return c&&w.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",y),document.removeEventListener("focusout",j),w.disconnect()}}},[a,c,x.paused]),u.useEffect(()=>{if(c){K0.add(x);const y=document.activeElement;if(!c.contains(y)){const v=new CustomEvent(Ep,H0);c.addEventListener(Ep,h),c.dispatchEvent(v),v.defaultPrevented||(U$(V$(Bw(c)),{select:!0}),document.activeElement===y&&sa(c))}return()=>{c.removeEventListener(Ep,h),setTimeout(()=>{const v=new CustomEvent(Ap,H0);c.addEventListener(Ap,f),c.dispatchEvent(v),v.defaultPrevented||sa(y??document.body,{select:!0}),c.removeEventListener(Ap,f),K0.remove(x)},0)}}},[c,h,f,x]);const g=u.useCallback(y=>{if(!r&&!a||x.paused)return;const j=y.key==="Tab"&&!y.altKey&&!y.ctrlKey&&!y.metaKey,v=document.activeElement;if(j&&v){const w=y.currentTarget,[N,k]=B$(w);N&&k?!y.shiftKey&&v===k?(y.preventDefault(),r&&sa(N,{select:!0})):y.shiftKey&&v===N&&(y.preventDefault(),r&&sa(k,{select:!0})):v===w&&y.preventDefault()}},[r,a,x.paused]);return t.jsx(St.div,{tabIndex:-1,...o,ref:p,onKeyDown:g})},"FocusScope"));function U$(e,{select:n=!1}={}){const s=document.activeElement;for(const r of e)if(sa(r,{select:n}),document.activeElement!==s)return}ts(U$,"focusFirst");function B$(e){const n=Bw(e),s=Vx(n,e),r=Vx(n.reverse(),e);return[s,r]}ts(B$,"getTabbableEdges");function Bw(e){const n=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:ts(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}ts(Bw,"getTabbableCandidates");function Vx(e,n){const s=typeof n.checkVisibility=="function"&&n.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(s?!r.checkVisibility({checkVisibilityCSS:!0}):W$(r,{upTo:n})))return r}ts(Vx,"findVisible");function W$(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}ts(W$,"isHidden");function H$(e){return e instanceof HTMLInputElement&&"select"in e}ts(H$,"isSelectableInput");function sa(e,{select:n=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&H$(e)&&n&&e.select()}}ts(sa,"focus");var K0=K$();function K$(){let e=[];return{add(n){const s=e[0];n!==s&&(s==null||s.pause()),e=Gx(e,n),e.unshift(n)},remove(n){var s;e=Gx(e,n),(s=e[0])==null||s.resume()}}}ts(K$,"createFocusScopesStack");function Gx(e,n){const s=[...e],r=s.indexOf(n);return r!==-1&&s.splice(r,1),s}ts(Gx,"arrayRemove");function V$(e){return e.filter(n=>n.tagName!=="A")}ts(V$,"removeLinks");var Mz=Object.defineProperty,Ww=(e,n)=>Mz(e,"name",{value:n,configurable:!0}),$p=!1;function G$(){const[e,n]=u.useState($p);return u.useEffect(()=>{$p||($p=!0,n(!0))},[]),e}Ww(G$,"useIsHydrated");var q$=wo[" useSyncExternalStore ".trim().toString()];function Y$(){return()=>{}}Ww(Y$,"subscribe");function Q$(){return q$(Y$,()=>!0,()=>!1)}Ww(Q$,"useIsHydratedModern");var Oz=typeof q$=="function"?Q$:G$,Dz=Object.defineProperty,al=(e,n)=>Dz(e,"name",{value:n,configurable:!0}),Tp="rovingFocusGroup.onEntryFocus",Lz={bubbles:!1,cancelable:!0},dm="RovingFocusGroup",[qx,J$,Fz]=Vf(dm),[_z,um]=br(dm,[Fz]),[zz,Uz]=_z(dm),Bz=u.forwardRef(al(function(n,s){return t.jsx(qx.Provider,{scope:n.__scopeRovingFocusGroup,children:t.jsx(qx.Slot,{scope:n.__scopeRovingFocusGroup,children:t.jsx(Wz,{...n,ref:s})})})},"RovingFocusGroup")),Wz=u.forwardRef(al(function(n,s){const{__scopeRovingFocusGroup:r,orientation:a,loop:i=!1,dir:l,currentTabStopId:o,defaultCurrentTabStopId:c,onCurrentTabStopIdChange:d,onEntryFocus:h,preventScrollOnEntryFocus:f=!1,...m}=n,p=u.useRef(null),x=Tt(s,p),g=om(l),[y,j]=fi({prop:o,defaultProp:c??null,onChange:d,caller:dm}),[v,w]=u.useState(!1),N=ss(h),k=J$(r),S=u.useRef(!1),[b,C]=u.useState(0);return u.useEffect(()=>{const $=p.current;if($)return $.addEventListener(Tp,N),()=>$.removeEventListener(Tp,N)},[N]),t.jsx(zz,{scope:r,orientation:a,dir:g,loop:i,currentTabStopId:y,onItemFocus:u.useCallback($=>j($),[j]),onItemShiftTab:u.useCallback(()=>w(!0),[]),onFocusableItemAdd:u.useCallback(()=>C($=>$+1),[]),onFocusableItemRemove:u.useCallback(()=>C($=>$-1),[]),children:t.jsx(St.div,{tabIndex:v||b===0?-1:0,"data-orientation":a,...m,ref:x,style:{outline:"none",...n.style},onMouseDown:We(n.onMouseDown,()=>{S.current=!0}),onFocus:We(n.onFocus,$=>{const A=!S.current;if($.target===$.currentTarget&&A&&!v){const I=new CustomEvent(Tp,Lz);if($.currentTarget.dispatchEvent(I),!I.defaultPrevented){const M=k().filter(U=>U.focusable),O=M.find(U=>U.active),R=M.find(U=>U.id===y),z=[O,R,...M].filter(Boolean).map(U=>U.ref.current);Hw(z,f)}}S.current=!1}),onBlur:We(n.onBlur,()=>w(!1))})})},"RovingFocusGroupImpl")),Hz="RovingFocusGroupItem",Kz=u.forwardRef(al(function(n,s){const{__scopeRovingFocusGroup:r,focusable:a=!0,active:i=!1,tabStopId:l,children:o,...c}=n,d=ur(),h=l||d,f=Uz(Hz,r),m=f.currentTabStopId===h,p=J$(r),{onFocusableItemAdd:x,onFocusableItemRemove:g,currentTabStopId:y}=f,j=Oz();return ms(()=>{if(!(!j||!a))return x(),()=>g()},[j,a,x,g]),u.useEffect(()=>{if(!(j||!a))return x(),()=>g()},[j,a,x,g]),t.jsx(qx.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:We(n.onMouseDown,v=>{a?f.onItemFocus(h):v.preventDefault()}),onFocus:We(n.onFocus,()=>f.onItemFocus(h)),onKeyDown:We(n.onKeyDown,v=>{if(v.key==="Tab"&&v.shiftKey){f.onItemShiftTab();return}if(v.target!==v.currentTarget)return;const w=Z$(v,f.orientation,f.dir);if(w!==void 0){if(v.metaKey||v.ctrlKey||v.altKey||v.shiftKey)return;v.preventDefault();let k=p().filter(S=>S.focusable).map(S=>S.ref.current);if(w==="last")k.reverse();else if(w==="prev"||w==="next"){w==="prev"&&k.reverse();const S=k.indexOf(v.currentTarget);k=f.loop?eT(k,S+1):k.slice(S+1)}setTimeout(()=>Hw(k))}}),children:typeof o=="function"?o({isCurrentTabStop:m,hasTabStop:y!=null}):o})})},"RovingFocusGroupItem")),Vz={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function X$(e,n){return n!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}al(X$,"getDirectionAwareKey");function Z$(e,n,s){const r=X$(e.key,s);if(!(n==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(n==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Vz[r]}al(Z$,"getFocusIntent");function Hw(e,n=!1){const s=document.activeElement;for(const r of e)if(r===s||(r.focus({preventScroll:n}),document.activeElement!==s))return}al(Hw,"focusFirst");function eT(e,n){return e.map((s,r)=>e[(n+r)%e.length])}al(eT,"wrapArray");var tT=Bz,nT=Kz,Gz=function(e){if(typeof document>"u")return null;var n=Array.isArray(e)?e[0]:e;return n.ownerDocument.body},pl=new WeakMap,ju=new WeakMap,wu={},Ip=0,sT=function(e){return e&&(e.host||sT(e.parentNode))},qz=function(e,n){return n.map(function(s){if(e.contains(s))return s;var r=sT(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})},Yz=function(e,n,s,r){var a=qz(n,Array.isArray(e)?e:[e]);wu[s]||(wu[s]=new WeakMap);var i=wu[s],l=[],o=new Set,c=new Set(a),d=function(f){!f||o.has(f)||(o.add(f),d(f.parentNode))};a.forEach(d);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),x=p!==null&&p!=="false",g=(pl.get(m)||0)+1,y=(i.get(m)||0)+1;pl.set(m,g),i.set(m,y),l.push(m),g===1&&x&&ju.set(m,!0),y===1&&m.setAttribute(s,"true"),x||m.setAttribute(r,"true")}catch(j){console.error("aria-hidden: cannot operate on ",m,j)}})};return h(n),o.clear(),Ip++,function(){l.forEach(function(f){var m=pl.get(f)-1,p=i.get(f)-1;pl.set(f,m),i.set(f,p),m||(ju.has(f)||f.removeAttribute(r),ju.delete(f)),p||f.removeAttribute(s)}),Ip--,Ip||(pl=new WeakMap,pl=new WeakMap,ju=new WeakMap,wu={})}},rT=function(e,n,s){s===void 0&&(s="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),a=Gz(e);return a?(r.push.apply(r,Array.from(a.querySelectorAll("[aria-live], script"))),Yz(r,a,s,"aria-hidden")):function(){return null}},Or=function(){return Or=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},Or.apply(this,arguments)};function aT(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 Qz(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 ih="right-scroll-bar-position",lh="width-before-scroll-bar",Jz="with-scroll-bars-hidden",Xz="--removed-body-scroll-bar-size";function Rp(e,n){return typeof e=="function"?e(n):e&&(e.current=n),e}function Zz(e,n){var s=u.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 e3=typeof window<"u"?u.useLayoutEffect:u.useEffect,V0=new WeakMap;function t3(e,n){var s=Zz(null,function(r){return e.forEach(function(a){return Rp(a,r)})});return e3(function(){var r=V0.get(s);if(r){var a=new Set(r),i=new Set(e),l=s.current;a.forEach(function(o){i.has(o)||Rp(o,null)}),i.forEach(function(o){a.has(o)||Rp(o,l)})}V0.set(s,e)},[e]),s}function n3(e){return e}function s3(e,n){n===void 0&&(n=n3);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)},d=function(){return Promise.resolve().then(c)};d(),s={push:function(h){l.push(h),d()},filter:function(h){return l=l.filter(h),s}}}};return a}function r3(e){e===void 0&&(e={});var n=s3(null);return n.options=Or({async:!0,ssr:!1},e),n}var iT=function(e){var n=e.sideCar,s=aT(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 u.createElement(r,Or({},s))};iT.isSideCarExport=!0;function a3(e,n){return e.useMedium(n),iT}var lT=r3(),Pp=function(){},hm=u.forwardRef(function(e,n){var s=u.useRef(null),r=u.useState({onScrollCapture:Pp,onWheelCapture:Pp,onTouchMoveCapture:Pp}),a=r[0],i=r[1],l=e.forwardProps,o=e.children,c=e.className,d=e.removeScrollBar,h=e.enabled,f=e.shards,m=e.sideCar,p=e.noRelative,x=e.noIsolation,g=e.inert,y=e.allowPinchZoom,j=e.as,v=j===void 0?"div":j,w=e.gapMode,N=aT(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=m,S=t3([s,n]),b=Or(Or({},N),a);return u.createElement(u.Fragment,null,h&&u.createElement(k,{sideCar:lT,removeScrollBar:d,shards:f,noRelative:p,noIsolation:x,inert:g,setCallbacks:i,allowPinchZoom:!!y,lockRef:s,gapMode:w}),l?u.cloneElement(u.Children.only(o),Or(Or({},b),{ref:S})):u.createElement(v,Or({},b,{className:c,ref:S}),o))});hm.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};hm.classNames={fullWidth:lh,zeroRight:ih};var i3=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function l3(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var n=i3();return n&&e.setAttribute("nonce",n),e}function o3(e,n){e.styleSheet?e.styleSheet.cssText=n:e.appendChild(document.createTextNode(n))}function c3(e){var n=document.head||document.getElementsByTagName("head")[0];n.appendChild(e)}var d3=function(){var e=0,n=null;return{add:function(s){e==0&&(n=l3())&&(o3(n,s),c3(n)),e++},remove:function(){e--,!e&&n&&(n.parentNode&&n.parentNode.removeChild(n),n=null)}}},u3=function(){var e=d3();return function(n,s){u.useEffect(function(){return e.add(n),function(){e.remove()}},[n&&s])}},oT=function(){var e=u3(),n=function(s){var r=s.styles,a=s.dynamic;return e(r,a),null};return n},h3={left:0,top:0,right:0,gap:0},Mp=function(e){return parseInt(e||"",10)||0},f3=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[Mp(s),Mp(r),Mp(a)]},m3=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return h3;var n=f3(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])}},p3=oT(),Vl="data-scroll-locked",g3=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(Jz,` {
51
+ overflow: hidden `).concat(r,`;
52
+ padding-right: `).concat(o,"px ").concat(r,`;
53
+ }
54
+ body[`).concat(Vl,`] {
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(ih,` {
68
+ right: `).concat(o,"px ").concat(r,`;
69
+ }
70
+
71
+ .`).concat(lh,` {
72
+ margin-right: `).concat(o,"px ").concat(r,`;
73
+ }
74
+
75
+ .`).concat(ih," .").concat(ih,` {
76
+ right: 0 `).concat(r,`;
77
+ }
78
+
79
+ .`).concat(lh," .").concat(lh,` {
80
+ margin-right: 0 `).concat(r,`;
81
+ }
82
+
83
+ body[`).concat(Vl,`] {
84
+ `).concat(Xz,": ").concat(o,`px;
85
+ }
86
+ `)},G0=function(){var e=parseInt(document.body.getAttribute(Vl)||"0",10);return isFinite(e)?e:0},x3=function(){u.useEffect(function(){return document.body.setAttribute(Vl,(G0()+1).toString()),function(){var e=G0()-1;e<=0?document.body.removeAttribute(Vl):document.body.setAttribute(Vl,e.toString())}},[])},v3=function(e){var n=e.noRelative,s=e.noImportant,r=e.gapMode,a=r===void 0?"margin":r;x3();var i=u.useMemo(function(){return m3(a)},[a]);return u.createElement(p3,{styles:g3(i,!n,a,s?"":"!important")})},Yx=!1;if(typeof window<"u")try{var yu=Object.defineProperty({},"passive",{get:function(){return Yx=!0,!0}});window.addEventListener("test",yu,yu),window.removeEventListener("test",yu,yu)}catch{Yx=!1}var gl=Yx?{passive:!1}:!1,j3=function(e){return e.tagName==="TEXTAREA"},cT=function(e,n){if(!(e instanceof Element))return!1;var s=window.getComputedStyle(e);return s[n]!=="hidden"&&!(s.overflowY===s.overflowX&&!j3(e)&&s[n]==="visible")},w3=function(e){return cT(e,"overflowY")},y3=function(e){return cT(e,"overflowX")},q0=function(e,n){var s=n.ownerDocument,r=n;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var a=dT(e,r);if(a){var i=uT(e,r),l=i[1],o=i[2];if(l>o)return!0}r=r.parentNode}while(r&&r!==s.body);return!1},b3=function(e){var n=e.scrollTop,s=e.scrollHeight,r=e.clientHeight;return[n,s,r]},k3=function(e){var n=e.scrollLeft,s=e.scrollWidth,r=e.clientWidth;return[n,s,r]},dT=function(e,n){return e==="v"?w3(n):y3(n)},uT=function(e,n){return e==="v"?b3(n):k3(n)},N3=function(e,n){return e==="h"&&n==="rtl"?-1:1},S3=function(e,n,s,r,a){var i=N3(e,window.getComputedStyle(n).direction),l=i*r,o=s.target,c=n.contains(o),d=!1,h=l>0,f=0,m=0;do{if(!o)break;var p=uT(e,o),x=p[0],g=p[1],y=p[2],j=g-y-i*x;(x||j)&&dT(e,o)&&(f+=j,m+=x);var v=o.parentNode;o=v&&v.nodeType===Node.DOCUMENT_FRAGMENT_NODE?v.host:v}while(!c&&o!==document.body||c&&(n.contains(o)||n===o));return(h&&Math.abs(f)<1||!h&&Math.abs(m)<1)&&(d=!0),d},bu=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Y0=function(e){return[e.deltaX,e.deltaY]},Q0=function(e){return e&&"current"in e?e.current:e},C3=function(e,n){return e[0]===n[0]&&e[1]===n[1]},E3=function(e){return`
87
+ .block-interactivity-`.concat(e,` {pointer-events: none;}
88
+ .allow-interactivity-`).concat(e,` {pointer-events: all;}
89
+ `)},A3=0,xl=[];function $3(e){var n=u.useRef([]),s=u.useRef([0,0]),r=u.useRef(),a=u.useState(A3++)[0],i=u.useState(oT)[0],l=u.useRef(e);u.useEffect(function(){l.current=e},[e]),u.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(a));var g=Qz([e.lockRef.current],(e.shards||[]).map(Q0),!0).filter(Boolean);return g.forEach(function(y){return y.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),g.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(a))})}}},[e.inert,e.lockRef.current,e.shards]);var o=u.useCallback(function(g,y){if("touches"in g&&g.touches.length===2||g.type==="wheel"&&g.ctrlKey)return!l.current.allowPinchZoom;var j=bu(g),v=s.current,w="deltaX"in g?g.deltaX:v[0]-j[0],N="deltaY"in g?g.deltaY:v[1]-j[1],k,S=g.target,b=Math.abs(w)>Math.abs(N)?"h":"v";if("touches"in g&&b==="h"&&S.type==="range")return!1;var C=window.getSelection(),$=C&&C.anchorNode,A=$?$===S||$.contains(S):!1;if(A)return!1;var I=q0(b,S);if(!I)return!0;if(I?k=b:(k=b==="v"?"h":"v",I=q0(b,S)),!I)return!1;if(!r.current&&"changedTouches"in g&&(w||N)&&(r.current=k),!k)return!0;var M=r.current||k;return S3(M,y,g,M==="h"?w:N)},[]),c=u.useCallback(function(g){var y=g;if(!(!xl.length||xl[xl.length-1]!==i)){var j="deltaY"in y?Y0(y):bu(y),v=n.current.filter(function(k){return k.name===y.type&&(k.target===y.target||y.target===k.shadowParent)&&C3(k.delta,j)})[0];if(v&&v.should){y.cancelable&&y.preventDefault();return}if(!v){var w=(l.current.shards||[]).map(Q0).filter(Boolean).filter(function(k){return k.contains(y.target)}),N=w.length>0?o(y,w[0]):!l.current.noIsolation;N&&y.cancelable&&y.preventDefault()}}},[]),d=u.useCallback(function(g,y,j,v){var w={name:g,delta:y,target:j,should:v,shadowParent:T3(j)};n.current.push(w),setTimeout(function(){n.current=n.current.filter(function(N){return N!==w})},1)},[]),h=u.useCallback(function(g){s.current=bu(g),r.current=void 0},[]),f=u.useCallback(function(g){d(g.type,Y0(g),g.target,o(g,e.lockRef.current))},[]),m=u.useCallback(function(g){d(g.type,bu(g),g.target,o(g,e.lockRef.current))},[]);u.useEffect(function(){return xl.push(i),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:m}),document.addEventListener("wheel",c,gl),document.addEventListener("touchmove",c,gl),document.addEventListener("touchstart",h,gl),function(){xl=xl.filter(function(g){return g!==i}),document.removeEventListener("wheel",c,gl),document.removeEventListener("touchmove",c,gl),document.removeEventListener("touchstart",h,gl)}},[]);var p=e.removeScrollBar,x=e.inert;return u.createElement(u.Fragment,null,x?u.createElement(i,{styles:E3(a)}):null,p?u.createElement(v3,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function T3(e){for(var n=null;e!==null;)e instanceof ShadowRoot&&(n=e.host,e=e.host),e=e.parentNode;return n}const I3=a3(lT,$3);var Kw=u.forwardRef(function(e,n){return u.createElement(hm,Or({},e,{ref:n,sideCar:I3}))});Kw.classNames=hm.classNames;var R3=Object.defineProperty,wt=(e,n)=>R3(e,"name",{value:n,configurable:!0}),Qx=["Enter"," "],P3=["ArrowDown","PageUp","Home"],hT=["ArrowUp","PageDown","End"],M3=[...P3,...hT],O3={ltr:[...Qx,"ArrowRight"],rtl:[...Qx,"ArrowLeft"]},D3={ltr:["ArrowLeft"],rtl:["ArrowRight"]},fm="Menu",[ld,L3,F3]=Vf(fm),[il,fT]=br(fm,[F3,sm,um]),mm=sm(),mT=um(),[pT,pi]=il(fm),[_3,Od]=il(fm),z3=wt(e=>{const{__scopeMenu:n,open:s=!1,children:r,dir:a,onOpenChange:i,modal:l=!0}=e,o=mm(n),[c,d]=u.useState(null),h=u.useRef(!1),f=ss(i),m=om(a);return u.useEffect(()=>{const p=wt(()=>{h.current=!0,document.addEventListener("pointerdown",x,{capture:!0,once:!0}),document.addEventListener("pointermove",x,{capture:!0,once:!0})},"handleKeyDown"),x=wt(()=>h.current=!1,"handlePointer");return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",x,{capture:!0}),document.removeEventListener("pointermove",x,{capture:!0})}},[]),u.useEffect(()=>{if(!s)return;const p=wt(()=>f(!1),"handleBlur");return window.addEventListener("blur",p),()=>window.removeEventListener("blur",p)},[s,f]),t.jsx(Iw,{...o,children:t.jsx(pT,{scope:n,open:s,onOpenChange:f,content:c,onContentChange:d,children:t.jsx(_3,{scope:n,onClose:u.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:h,dir:m,modal:l,children:r})})})},"Menu"),gT=u.forwardRef(wt(function(n,s){const{__scopeMenu:r,...a}=n,i=mm(r);return t.jsx(b$,{...i,...a,ref:s})},"MenuAnchor")),xT="MenuPortal",[U3,vT]=il(xT,{forceMount:void 0}),B3=wt(e=>{const{__scopeMenu:n,forceMount:s,children:r,container:a}=e,i=pi(xT,n);return t.jsx(U3,{scope:n,forceMount:s,children:t.jsx(Gr,{present:s||i.open,children:t.jsx(Yf,{asChild:!0,container:a,children:r})})})},"MenuPortal"),hr="MenuContent",[W3,Vw]=il(hr),H3=u.forwardRef(wt(function(n,s){const r=vT(hr,n.__scopeMenu),{forceMount:a=r.forceMount,...i}=n,l=pi(hr,n.__scopeMenu),o=Od(hr,n.__scopeMenu);return t.jsx(ld.Provider,{scope:n.__scopeMenu,children:t.jsx(Gr,{present:a||l.open,children:t.jsx(ld.Slot,{scope:n.__scopeMenu,children:o.modal?t.jsx(K3,{...i,ref:s}):t.jsx(V3,{...i,ref:s})})})})},"MenuContent")),K3=u.forwardRef(wt(function(n,s){const r=pi(hr,n.__scopeMenu),a=u.useRef(null),i=Tt(s,a);return u.useEffect(()=>{const l=a.current;if(l)return rT(l)},[]),t.jsx(Gw,{...n,ref:i,trapFocus:r.open,disableOutsidePointerEvents:r.open,disableOutsideScroll:!0,onFocusOutside:We(n.onFocusOutside,l=>l.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentModal")),V3=u.forwardRef(wt(function(n,s){const r=pi(hr,n.__scopeMenu);return t.jsx(Gw,{...n,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentNonModal")),G3=ti("MenuContent.ScrollLock"),Gw=u.forwardRef(wt(function(n,s){const{__scopeMenu:r,loop:a=!1,trapFocus:i,onOpenAutoFocus:l,onCloseAutoFocus:o,disableOutsidePointerEvents:c,onEntryFocus:d,onEscapeKeyDown:h,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:p,onDismiss:x,disableOutsideScroll:g,...y}=n,j=pi(hr,r),v=Od(hr,r),w=mm(r),N=mT(r),k=L3(r),[S,b]=u.useState(null),C=u.useRef(null),$=Tt(s,C,j.onContentChange),A=u.useRef(0),I=u.useRef(""),M=u.useRef(0),O=u.useRef(null),R=u.useRef("right"),_=u.useRef(0),z=g?Kw:u.Fragment,U=g?{as:G3,allowPinchZoom:!0}:void 0,P=wt(L=>{var G,ce;const Q=I.current+L,F=k().filter(xe=>!xe.disabled),ae=document.activeElement,V=(G=F.find(xe=>xe.ref.current===ae))==null?void 0:G.textValue,J=F.map(xe=>xe.textValue),H=AT(J,Q,V),X=(ce=F.find(xe=>xe.textValue===H))==null?void 0:ce.ref.current;wt(function xe(De){I.current=De,window.clearTimeout(A.current),De!==""&&(A.current=window.setTimeout(()=>xe(""),1e3))},"updateSearch")(Q),X&&setTimeout(()=>X.focus())},"handleTypeaheadSearch");u.useEffect(()=>()=>window.clearTimeout(A.current),[]),cm();const W=u.useCallback(L=>{var F,ae;return R.current===((F=O.current)==null?void 0:F.side)&&TT(L,(ae=O.current)==null?void 0:ae.area)},[]);return t.jsx(W3,{scope:r,searchRef:I,onItemEnter:u.useCallback(L=>{W(L)&&L.preventDefault()},[W]),onItemLeave:u.useCallback(L=>{var Q;W(L)||((Q=C.current)==null||Q.focus(),b(null))},[W]),onTriggerLeave:u.useCallback(L=>{W(L)&&L.preventDefault()},[W]),pointerGraceTimerRef:M,onPointerGraceIntentChange:u.useCallback(L=>{O.current=L},[]),children:t.jsx(z,{...U,children:t.jsx(z$,{asChild:!0,trapped:i,onMountAutoFocus:We(l,L=>{var Q;L.preventDefault(),(Q=C.current)==null||Q.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:t.jsx(qf,{asChild:!0,disableOutsidePointerEvents:c,onEscapeKeyDown:h,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:p,onDismiss:x,children:t.jsx(tT,{asChild:!0,...N,dir:v.dir,orientation:"vertical",loop:a,currentTabStopId:S,onCurrentTabStopIdChange:b,onEntryFocus:We(d,L=>{v.isUsingKeyboardRef.current||L.preventDefault()}),preventScrollOnEntryFocus:!0,children:t.jsx(k$,{role:"menu","aria-orientation":"vertical","data-state":qw(j.open),"data-radix-menu-content":"",dir:v.dir,...w,...y,ref:$,style:{outline:"none",...y.style},onKeyDown:We(y.onKeyDown,L=>{const F=L.target.closest("[data-radix-menu-content]")===L.currentTarget,ae=L.ctrlKey||L.altKey||L.metaKey,V=L.key.length===1;F&&(L.key==="Tab"&&L.preventDefault(),!ae&&V&&P(L.key));const J=C.current;if(L.target!==J||!M3.includes(L.key))return;L.preventDefault();const X=k().filter(G=>!G.disabled).map(G=>G.ref.current);hT.includes(L.key)&&X.reverse(),CT(X)}),onBlur:We(n.onBlur,L=>{L.currentTarget.contains(L.target)||(window.clearTimeout(A.current),I.current="")}),onPointerMove:We(n.onPointerMove,ro(L=>{const Q=L.target,F=_.current!==L.clientX;if(L.currentTarget.contains(Q)&&F){const ae=L.clientX>_.current?"right":"left";R.current=ae,_.current=L.clientX}}))})})})})})})},"MenuContentImpl")),jT=u.forwardRef(wt(function(n,s){const{__scopeMenu:r,...a}=n;return t.jsx(St.div,{role:"group",...a,ref:s})},"MenuGroup")),q3=u.forwardRef(wt(function(n,s){const{__scopeMenu:r,...a}=n;return t.jsx(St.div,{...a,ref:s})},"MenuLabel")),Jx="MenuItem",J0="menu.itemSelect",wT=u.forwardRef(wt(function(n,s){const{disabled:r=!1,onSelect:a,...i}=n,l=u.useRef(null),o=Od(Jx,n.__scopeMenu),c=Vw(Jx,n.__scopeMenu),d=Tt(s,l),h=u.useRef(!1),f=wt(()=>{const m=l.current;if(!r&&m){const p=new CustomEvent(J0,{bubbles:!0,cancelable:!0});m.addEventListener(J0,x=>a==null?void 0:a(x),{once:!0}),Gf(m,p),p.defaultPrevented?h.current=!1:o.onClose()}},"handleSelect");return t.jsx(yT,{...i,ref:d,disabled:r,onClick:We(n.onClick,f),onPointerDown:m=>{var p;(p=n.onPointerDown)==null||p.call(n,m),h.current=!0},onPointerUp:We(n.onPointerUp,m=>{var p;h.current||(p=m.currentTarget)==null||p.click()}),onKeyDown:We(n.onKeyDown,m=>{r||m.target!==m.currentTarget||c.searchRef.current!==""&&m.key===" "||Qx.includes(m.key)&&(m.currentTarget.click(),m.preventDefault())})})},"MenuItem")),yT=u.forwardRef(wt(function(n,s){const{__scopeMenu:r,disabled:a=!1,textValue:i,...l}=n,o=Vw(Jx,r),c=mT(r),d=u.useRef(null),h=Tt(s,d),[f,m]=u.useState(!1),[p,x]=u.useState("");return u.useEffect(()=>{const g=d.current;g&&x((g.textContent??"").trim())},[l.children]),t.jsx(ld.ItemSlot,{scope:r,disabled:a,textValue:i??p,children:t.jsx(nT,{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:We(n.onPointerMove,ro(g=>{a?o.onItemLeave(g):(o.onItemEnter(g),g.defaultPrevented||g.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:We(n.onPointerLeave,ro(g=>o.onItemLeave(g))),onFocus:We(n.onFocus,()=>m(!0)),onBlur:We(n.onBlur,()=>m(!1))})})})},"MenuItemImpl")),Y3="MenuRadioGroup",[Q3,J3]=il(Y3,{value:void 0,onValueChange:wt(()=>{},"onValueChange")}),X3=u.forwardRef(wt(function(n,s){const{value:r,onValueChange:a,...i}=n,l=ss(a);return t.jsx(Q3,{scope:n.__scopeMenu,value:r,onValueChange:l,children:t.jsx(jT,{...i,ref:s})})},"MenuRadioGroup")),Z3="MenuRadioItem",eU=u.forwardRef(wt(function(n,s){const{value:r,...a}=n,i=J3(Z3,n.__scopeMenu),l=r===i.value;return t.jsx(nU,{scope:n.__scopeMenu,checked:l,children:t.jsx(wT,{role:"menuitemradio","aria-checked":l,...a,ref:s,"data-state":ST(l),onSelect:We(a.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,r)},{checkForDefaultPrevented:!1})})})},"MenuRadioItem")),tU="MenuItemIndicator",[nU,ele]=il(tU,{checked:!1}),sU=u.forwardRef(wt(function(n,s){const{__scopeMenu:r,...a}=n;return t.jsx(St.div,{role:"separator","aria-orientation":"horizontal",...a,ref:s})},"MenuSeparator")),bT="MenuSub",[rU,kT]=il(bT),aU=wt(e=>{const{__scopeMenu:n,children:s,open:r=!1,onOpenChange:a}=e,i=pi(bT,n),l=mm(n),[o,c]=u.useState(null),[d,h]=u.useState(null),f=ss(a);return u.useEffect(()=>(i.open===!1&&f(!1),()=>f(!1)),[i.open,f]),t.jsx(Iw,{...l,children:t.jsx(pT,{scope:n,open:r,onOpenChange:f,content:d,onContentChange:h,children:t.jsx(rU,{scope:n,contentId:ur(),triggerId:ur(),trigger:o,onTriggerChange:c,children:s})})})},"MenuSub"),ku="MenuSubTrigger",iU=u.forwardRef(wt(function(n,s){const r=pi(ku,n.__scopeMenu),a=Od(ku,n.__scopeMenu),i=kT(ku,n.__scopeMenu),l=Vw(ku,n.__scopeMenu),o=u.useRef(null),{pointerGraceTimerRef:c,onPointerGraceIntentChange:d}=l,h={__scopeMenu:n.__scopeMenu},f=u.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);u.useEffect(()=>f,[f]),u.useEffect(()=>{const p=c.current;return()=>{window.clearTimeout(p),d(null)}},[c,d]);const m=Tt(s,i.onTriggerChange);return t.jsx(gT,{asChild:!0,...h,children:t.jsx(yT,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":r.open,"aria-controls":r.open?i.contentId:void 0,"data-state":qw(r.open),...n,ref:m,onClick:p=>{var x;(x=n.onClick)==null||x.call(n,p),!(n.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),r.open||r.onOpenChange(!0))},onPointerMove:We(n.onPointerMove,ro(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:We(n.onPointerLeave,ro(p=>{var g,y;f();const x=(g=r.content)==null?void 0:g.getBoundingClientRect();if(x){const j=(y=r.content)==null?void 0:y.dataset.side,v=j==="right",w=v?-5:5,N=x[v?"left":"right"],k=x[v?"right":"left"];l.onPointerGraceIntentChange({area:[{x:p.clientX+w,y:p.clientY},{x:N,y:x.top},{x:k,y:x.top},{x:k,y:x.bottom},{x:N,y:x.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:We(n.onKeyDown,p=>{var g;n.disabled||p.target!==p.currentTarget||l.searchRef.current!==""&&p.key===" "||O3[a.dir].includes(p.key)&&(r.onOpenChange(!0),(g=r.content)==null||g.focus(),p.preventDefault())})})})},"MenuSubTrigger")),lU="MenuSubContent",oU=u.forwardRef(wt(function(n,s){const r=vT(hr,n.__scopeMenu),{forceMount:a=r.forceMount,align:i="start",...l}=n,o=pi(hr,n.__scopeMenu),c=Od(hr,n.__scopeMenu),d=kT(lU,n.__scopeMenu),h=u.useRef(null),f=Tt(s,h);return t.jsx(ld.Provider,{scope:n.__scopeMenu,children:t.jsx(Gr,{present:a||o.open,children:t.jsx(ld.Slot,{scope:n.__scopeMenu,children:t.jsx(Gw,{id:d.contentId,"aria-labelledby":d.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:We(n.onFocusOutside,m=>{m.target!==d.trigger&&o.onOpenChange(!1)}),onEscapeKeyDown:We(n.onEscapeKeyDown,m=>{c.onClose(),m.preventDefault()}),onKeyDown:We(n.onKeyDown,m=>{var g;const p=m.currentTarget.contains(m.target),x=D3[c.dir].includes(m.key);p&&x&&(o.onOpenChange(!1),(g=d.trigger)==null||g.focus(),m.preventDefault())})})})})})},"MenuSubContent"));function qw(e){return e?"open":"closed"}wt(qw,"getOpenState");function NT(e){return e==="indeterminate"}wt(NT,"isIndeterminate");function ST(e){return NT(e)?"indeterminate":e?"checked":"unchecked"}wt(ST,"getCheckedState");function CT(e){const n=document.activeElement;for(const s of e)if(s===n||(s.focus(),document.activeElement!==n))return}wt(CT,"focusFirst");function ET(e,n){return e.map((s,r)=>e[(n+r)%e.length])}wt(ET,"wrapArray");function AT(e,n,s){const a=n.length>1&&Array.from(n).every(d=>d===n[0])?n[0]:n,i=s?e.indexOf(s):-1;let l=ET(e,Math.max(i,0));a.length===1&&(l=l.filter(d=>d!==s));const c=l.find(d=>d.toLowerCase().startsWith(a.toLowerCase()));return c!==s?c:void 0}wt(AT,"getNextMatch");function $T(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],d=o.x,h=o.y,f=c.x,m=c.y;h>r!=m>r&&s<(f-d)*(r-h)/(m-h)+d&&(a=!a)}return a}wt($T,"isPointInPolygon");function TT(e,n){if(!n)return!1;const s={x:e.clientX,y:e.clientY};return $T(s,n)}wt(TT,"isPointerInGraceArea");function ro(e){return n=>n.pointerType==="mouse"?e(n):void 0}wt(ro,"whenMouse");var cU=z3,dU=gT,uU=B3,hU=H3,fU=jT,mU=q3,pU=wT,gU=X3,xU=eU,vU=sU,jU=aU,wU=iU,yU=oU,bU=Object.defineProperty,Ms=(e,n)=>bU(e,"name",{value:n,configurable:!0}),Yw="DropdownMenu",[kU,tle]=br(Yw,[fT]),Os=fT(),[NU,IT]=kU(Yw),SU=Ms(e=>{const{__scopeDropdownMenu:n,children:s,dir:r,open:a,defaultOpen:i,onOpenChange:l,modal:o=!0}=e,c=Os(n),d=u.useRef(null),[h,f]=fi({prop:a,defaultProp:i??!1,onChange:l,caller:Yw});return t.jsx(NU,{scope:n,triggerId:ur(),triggerRef:d,contentId:ur(),open:h,onOpenChange:f,onOpenToggle:u.useCallback(()=>f(m=>!m),[f]),modal:o,children:t.jsx(cU,{...c,open:h,onOpenChange:f,dir:r,modal:o,children:s})})},"DropdownMenu"),CU="DropdownMenuTrigger",EU=u.forwardRef(Ms(function(n,s){const{__scopeDropdownMenu:r,disabled:a=!1,...i}=n,l=IT(CU,r),o=Os(r),c=Tt(s,l.triggerRef);return t.jsx(dU,{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:We(n.onPointerDown,d=>{!a&&d.button===0&&d.ctrlKey===!1&&(l.onOpenToggle(),l.open||d.preventDefault())}),onKeyDown:We(n.onKeyDown,d=>{a||(["Enter"," "].includes(d.key)&&l.onOpenToggle(),d.key==="ArrowDown"&&l.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(d.key)&&d.preventDefault())})})})},"DropdownMenuTrigger")),AU=Ms(e=>{const{__scopeDropdownMenu:n,...s}=e,r=Os(n);return t.jsx(uU,{...r,...s})},"DropdownMenuPortal"),$U="DropdownMenuContent",TU=u.forwardRef(Ms(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=IT($U,r),l=Os(r),o=u.useRef(!1);return t.jsx(hU,{id:i.contentId,"aria-labelledby":i.triggerId,...l,...a,ref:s,onCloseAutoFocus:We(n.onCloseAutoFocus,c=>{var d;o.current||(d=i.triggerRef.current)==null||d.focus(),o.current=!1,c.preventDefault()}),onInteractOutside:We(n.onInteractOutside,c=>{const d=c.detail.originalEvent,h=d.button===0&&d.ctrlKey===!0,f=d.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")),IU=u.forwardRef(Ms(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Os(r);return t.jsx(fU,{...i,...a,ref:s})},"DropdownMenuGroup")),RU=u.forwardRef(Ms(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Os(r);return t.jsx(mU,{...i,...a,ref:s})},"DropdownMenuLabel")),PU=u.forwardRef(Ms(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Os(r);return t.jsx(pU,{...i,...a,ref:s})},"DropdownMenuItem")),MU=u.forwardRef(Ms(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Os(r);return t.jsx(gU,{...i,...a,ref:s})},"DropdownMenuRadioGroup")),OU=u.forwardRef(Ms(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Os(r);return t.jsx(xU,{...i,...a,ref:s})},"DropdownMenuRadioItem")),DU=u.forwardRef(Ms(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Os(r);return t.jsx(vU,{...i,...a,ref:s})},"DropdownMenuSeparator")),LU=Ms(e=>{const{__scopeDropdownMenu:n,children:s,open:r,onOpenChange:a,defaultOpen:i}=e,l=Os(n),[o,c]=fi({prop:r,defaultProp:i??!1,onChange:a,caller:"DropdownMenuSub"});return t.jsx(jU,{...l,open:o,onOpenChange:c,children:s})},"DropdownMenuSub"),FU=u.forwardRef(Ms(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Os(r);return t.jsx(wU,{...i,...a,ref:s})},"DropdownMenuSubTrigger")),_U=u.forwardRef(Ms(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Os(r);return t.jsx(yU,{...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")),Dd=SU,Ld=EU,$o=AU,Fd=TU,RT=IU,Yi=RU,Vs=PU,zU=MU,UU=OU,da=DU,BU=LU,WU=FU,HU=_U,KU=Object.defineProperty,To=(e,n)=>KU(e,"name",{value:n,configurable:!0}),Qw="Tabs",[VU,nle]=br(Qw,[um]),PT=um(),[GU,Jw]=VU(Qw),qU=u.forwardRef(To(function(n,s){const{__scopeTabs:r,value:a,onValueChange:i,defaultValue:l,orientation:o="horizontal",dir:c,activationMode:d="automatic",...h}=n,f=om(c),[m,p]=fi({prop:a,onChange:i,defaultProp:l??"",caller:Qw});return t.jsx(GU,{scope:r,baseId:ur(),value:m,onValueChange:p,orientation:o,dir:f,activationMode:d,children:t.jsx(St.div,{dir:f,"data-orientation":o,...h,ref:s})})},"Tabs")),YU="TabsList",QU=u.forwardRef(To(function(n,s){const{__scopeTabs:r,loop:a=!0,...i}=n,l=Jw(YU,r),o=PT(r);return t.jsx(tT,{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")),JU="TabsTrigger",XU=u.forwardRef(To(function(n,s){const{__scopeTabs:r,value:a,disabled:i=!1,...l}=n,o=Jw(JU,r),c=PT(r),d=Xw(o.baseId,a),h=Zw(o.baseId,a),f=a===o.value;return t.jsx(nT,{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:d,...l,ref:s,onMouseDown:We(n.onMouseDown,m=>{!i&&m.button===0&&m.ctrlKey===!1?o.onValueChange(a):m.preventDefault()}),onKeyDown:We(n.onKeyDown,m=>{i||m.target!==m.currentTarget||[" ","Enter"].includes(m.key)&&o.onValueChange(a)}),onFocus:We(n.onFocus,()=>{const m=o.activationMode!=="manual";!f&&!i&&m&&o.onValueChange(a)})})})},"TabsTrigger")),ZU="TabsContent",e6=u.forwardRef(To(function(n,s){const{__scopeTabs:r,value:a,forceMount:i,children:l,...o}=n,c=Jw(ZU,r),d=Xw(c.baseId,a),h=Zw(c.baseId,a),f=a===c.value,m=u.useRef(f);return u.useEffect(()=>{const p=requestAnimationFrame(()=>m.current=!1);return()=>cancelAnimationFrame(p)},[]),t.jsx(Gr,{present:i||f,children:({present:p})=>t.jsx(St.div,{"data-state":f?"active":"inactive","data-orientation":c.orientation,role:"tabpanel","aria-labelledby":d,hidden:!p,id:h,tabIndex:0,...o,ref:s,style:{...n.style,animationDuration:m.current?"0s":void 0},children:p&&l})})},"TabsContent"));function Xw(e,n){return`${e}-trigger-${n}`}To(Xw,"makeTriggerId");function Zw(e,n){return`${e}-content-${n}`}To(Zw,"makeContentId");var t6=qU,n6=QU,s6=XU,r6=e6;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)?a6(r,s):String(e)}case"percent":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?`${X0(r)}%`:String(e)}case"number":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?Number.isInteger(r)?fn(r):X0(r):String(e)}case"date":return i6(String(e));default:return typeof e=="string"?e:typeof e=="number"?fn(e):typeof e=="boolean"?e?"yes":"no":JSON.stringify(e)??String(e)}}function a6(e,n){if(!(Math.abs(e)<1e3&&!Number.isInteger(e)))return az(e,n);try{return new Intl.NumberFormat("en-US",{style:"currency",currency:n??"USD",maximumFractionDigits:2}).format(e)}catch{return e.toFixed(2)}}function i6(e){const n=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);return n?Pd(n[0],{year:!0,compact:!0}):e}function Xx(e){const n=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);return n?Pd(n[0],{compact:!0}):e}function X0(e){return String(Math.round(e*100)/100)}function qh(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 l6({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 o6=/^(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 )/,c6=/^(… |\.\.\. |\(no change\)$|\)/;function d6(e){return e.replace(/\n$/,"").split(`
90
+ `).map(s=>({kind:u6(s),text:s}))}function u6(e){return e.startsWith("@@")?"hunk":o6.test(e)||c6.test(e)?"meta":e.startsWith("+")?"add":e.startsWith("-")?"del":"context"}function h6({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 Yh({text:e,limit:n,more:s,label:r="Diff",marks:a}){const i=d6(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,d)=>t.jsx("span",{className:"wb-diff-line","data-kind":c.kind,children:a&&a.length>0?t.jsx(h6,{text:c.text,marks:a}):c.text===""?" ":c.text},d))}),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 f6({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(Yh,{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 In="#/",ao="#/needs",ma="#/chat",yt="#/agents",Yt="#/activity",un="#/settings",ya="#/files",m6="#/welcome";function oh(e){const n=/^#\/welcome(?:\?(.*))?$/.exec(e);if(!n)return null;try{return{step:new URLSearchParams(n[1]??"").get("step")}}catch{return{step:null}}}function cc(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`${ya}${e?`/${encodeURIComponent(e)}`:""}${r?`?${r}`:""}`}function p6(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 g6(e){if(MT(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 $i(e,n){return`#/chat/g/${encodeURIComponent(e)}${n?`/${encodeURIComponent(n)}`:""}`}function MT(e){const n=/^#\/chat\/g\/([^/?]+)(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(!n)return null;try{return{groupId:decodeURIComponent(n[1]),...n[2]?{conversationId:decodeURIComponent(n[2])}:{}}}catch{return null}}function Pt(e,n,s){return`${yt}/${encodeURIComponent(e)}${n?`/${n}${s?`/${s}`:""}`:""}`}function x6(e){const n=/^#\/agents\/([^/]+)(?:\/([a-z-]+)(?:\/([a-z-]+))?)?$/.exec(e);if(!n||n[1]===OT)return null;try{return{agentId:decodeURIComponent(n[1]),...n[2]?{tab:n[2]}:{},...n[3]?{section:n[3]}:{}}}catch{return null}}const OT="catalogue",Z0=`${yt}/${OT}`;function mn(e){return e?`${Z0}/${encodeURIComponent(e)}`:Z0}function v6(e){return`${mn(e)}?add=1`}function j6(e,n){const s=/^#\/agents\/catalogue\/([a-z0-9-]+)\?(?:.*&)?add=1(?:&|$)/.exec(e);return(s==null?void 0:s[1])===n}function w6(e){const n=/^#\/agents\/catalogue(?:\/([a-z0-9-]+))?(?:\?.*)?$/.exec(e);return n?n[1]?{name:n[1]}:{}:null}function od(e){return`${Yt}/conversations/${encodeURIComponent(e)}`}const y6="#/p";function Hr(e,n,s){const r=`${y6}/${encodeURIComponent(e)}/${encodeURIComponent(n)}`;return s?`${r}/${encodeURIComponent(s)}`:r}function ey(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 b6="p.";function pr(e,n=e,s){const r=s?new URLSearchParams(s).toString():"";return`${un}/${encodeURIComponent(LT(e,n))}${r?`?${r}`:""}`}function k6(e,n){const s=DT(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=ty(e);return pr(s.plugin,r[0].id,Object.keys(a).length>0?a:void 0)}function ty(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 DT(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 LT(e,n){return`${b6}${e}${n===e?"":`.${n}`}`}function ze(e){return e?`${un}/${e}`:un}function FT(e){return`${ze("accounts")}?account=${encodeURIComponent(e)}`}function N6(e){const n=/^#\/settings\/accounts\?(.*)$/.exec(e);if(!n)return null;try{return new URLSearchParams(n[1]).get("account")||null}catch{return null}}function cd(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 _T(e){return`${ze("connections")}?connection=${encodeURIComponent(e)}`}function eN(e){const n=(cd(e,"computer","code")??cd(e,"browser","code")??"").replace(/[\s-]/g,"");return/^\d{6}$/.test(n)?n:null}function S6(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 C6(e){return cd(e,"connections","connection")}const E6=ze("computer");function A6(e){return cd(e,"secrets","secret")}const Zx=`${ze("secrets")}?add=1`;function $6(e){return cd(e,"secrets","add")==="1"}function T6(e){return`${ze("plugins")}?install=${encodeURIComponent(e)}`}const ev=`${ze("plugins")}?tab=browse`;function tv(e="all"){return e==="all"?ev:`${ev}&kind=${e}`}function I6(e){return`${ze("proposals")}${e?`?plugin=${encodeURIComponent(e)}`:""}`}function R6(e){const n=/^#\/settings\/proposals\?(.*)$/.exec(e);if(!n)return null;try{return new URLSearchParams(n[1]).get("plugin")||null}catch{return null}}function ny(e){const n=/^#\/settings\/plugins\?(.*)$/.exec(e);if(!n)return null;try{return new URLSearchParams(n[1])}catch{return null}}function P6(e){var s,r;const n=(r=(s=ny(e))==null?void 0:s.get("install"))==null?void 0:r.trim();return n||null}function tN(e){var s;const n=(s=ny(e))==null?void 0:s.get("kind");return n==="plugins"||n==="widgets"||n==="agents"?n:"all"}function nN(e){const n=ny(e);return n!=null&&n.get("install")?"installed":(n==null?void 0:n.get("tab"))==="browse"?"browse":"installed"}const M6=[{route:In,label:"Home"},{route:ma,label:"Chat"},{route:yt,label:"Agents"},{route:Yt,label:"Activity"},{route:ya,label:"Files"},{route:un,label:"Settings"}],O6=[{id:"you",label:"You"},{id:"access",label:"Models and access"},{id:"running",label:"Running"},{id:"plugins",label:"Plugins"}],D6=[{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 L6(e){var n;return((n=/^#\/settings\/([a-z0-9.-]+)/.exec(e))==null?void 0:n[1])??"you"}const nv="#/settings/notifications/recent",sv=ze("backup");function F6(e){const n=/^#\/conversations\/(.+)$/.exec(e);if(n)return od(decodeURIComponent(n[1]));const s=/^#\/email(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(s)try{return Hr("email","mail",s[1]?decodeURIComponent(s[1]):null)}catch{return Hr("email","mail")}if(e==="#/settings/email")return pr("email","settings");const r=/^#\/settings\/browser(\?.*)?$/.exec(e);return r?`${ze("computer")}${r[1]??""}`:{"#/overview":In,"#/approvals":In,"#/events":`${Yt}/events`,"#/jobs":`${Yt}/jobs`,"#/conversations":Yt,"#/missions":`${yt}?tab=missions`,"#/offers":`${yt}?tab=offers`,"#/reminders":`${yt}?tab=reminders`,"#/providers":ze("accounts"),"#/browser":ze("computer"),"#/sentinels":ze("watchers"),"#/settings/sentinels":ze("watchers")}[e]??null}function zT(e){if(e===""||e==="#"||e===In)return In;if(e.startsWith(ma))return ma;if(e.startsWith(yt))return yt;if(e.startsWith(Yt))return Yt;if(e.startsWith(ya))return ya;if(e.startsWith(un))return un;const n=ey(e);return n?Hr(n.plugin,n.page):In}const _6="#/chat?group=new";function z6(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 _d="front-desk",sy=[{id:_d,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."}],UT=new Set(sy.map(e=>e.id)),sN=e=>UT.has(e);function rN(e,n){const s=n.filter(r=>!UT.has(r));return[...sy.filter(r=>e.has(r.id)).map(r=>r.id),...s.filter((r,a)=>s.indexOf(r)===a)]}function U6(e,n){return e.find(s=>(s.roles??[]).includes(n))}const aN=["coding","finance","mail","research","calendar","files","memory"],B6={developer:"coding",coding:"coding",finance:"finance",credit:"finance",mail:"mail",email:"mail",research:"research",calendar:"calendar",files:"files",memory:"memory",[_d]:"buddi"},W6=[["mail",["email"]],["finance",["finance"]],["coding",["developer"]],["research",["web","browser"]],["art",["image"]]];function H6(e){const n=new Set(e.map(s=>s.split(".")[0]??s));for(const[s,r]of W6)if(r.some(a=>n.has(a)))return s;return n.size>0&&[...n].every(s=>s==="memory")?"memory":null}let rv=null;function K6(e){rv=e}function Io(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=B6[s];if(r)return{key:r}}const n=H6(e.tools??[]);return n?{key:n}:rv!==null&&e.id===rv?{key:"buddi"}:{key:aN[V6(e.id)%aN.length]??"coding"}}function Qi(e){return e.key==="own"?{"data-agent":"own",style:{"--agent-fill":e.hex}}:{"data-agent":e.key}}function V6(e){let n=0;for(const s of e)n=(n*31+s.charCodeAt(0))%997;return n}const G6=["run.started","tool.called","tool.result","message.appended","awaiting-approval","run.finished","reaction","live","live.settle","live.snapshot","attention","plugins-changed","closing","ping"];function q6(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 d of i.split(`
94
+ `)){if(d===""||d.startsWith(":"))continue;const h=d.indexOf(":"),f=h===-1?d:d.slice(0,h),m=h===-1?"":d.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:G6.includes(o)?o:"ping",data:Y6(c.join(`
95
+ `))})}return{events:a,rest:r}}function Y6(e){if(e==="")return{};try{const n=JSON.parse(e);return n!==null&&typeof n=="object"?n:{value:n}}catch{return{value:e}}}function pm(e){const n=e.fetchImpl??globalThis.fetch.bind(globalThis),s=e.wait??(d=>new Promise(h=>setTimeout(h,d))),r=e.retryMs??1500;let a=e.lastEventId??null,i=!1,l=!1,o=null;return(async()=>{var d,h,f,m,p;for(;!i;){(d=e.onStatus)==null||d.call(e,"connecting"),o=new AbortController;try{const x=await n(e.url,{credentials:"same-origin",signal:o.signal,headers:{Accept:"text/event-stream",...a===null?{}:{"Last-Event-ID":a}}});if(!x.ok||!x.body)throw new Error(`stream ${x.status}`);(h=e.onStatus)==null||h.call(e,"open"),l&&((f=e.onReconnect)==null||f.call(e));const g=x.body.getReader(),y=new TextDecoder;let j="";for(;;){const{done:v,value:w}=await g.read();if(v)break;j+=y.decode(w,{stream:!0});const{events:N,rest:k}=q6(j);j=k;for(const S of N)e.onEvent(S),S.id!==null&&(a=S.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 ry="0.1.0+1ceafc8";function ay(e,n=ry){return typeof e=="string"&&e!==""&&typeof n=="string"&&n!==""&&e!==n}function Q6(){var e;try{if((e=window.matchMedia)!=null&&e.call(window,"(display-mode: standalone)").matches)return!0}catch{}return window.navigator.standalone===!0}const J6=5*6e4,X6=6e4,Z6=5e3,dd="buddi:stream-reconnected",BT="buddi.autoReloadedFor";function eB(){window.dispatchEvent(new Event(dd))}const iN=["keydown","pointerdown","pointermove","wheel","touchstart","input"];let iy=Date.now(),Nu=0;const lN=()=>{iy=Date.now()};function tB(){if(Nu===0){iy=Date.now();for(const e of iN)window.addEventListener(e,lN,{capture:!0,passive:!0})}return Nu+=1,()=>{if(Nu-=1,Nu===0)for(const e of iN)window.removeEventListener(e,lN,{capture:!0})}}function nB(e=Date.now()){return e-iy}function WT(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 sB(e){return e.hidden?!0:e.idleMs>=X6&&!e.busy}function rB(e){try{return window.sessionStorage.getItem(BT)===e}catch{return!1}}function aB(e){try{window.sessionStorage.setItem(BT,e)}catch{}}function iB(e){const n=u.useRef(e);n.current=e,u.useEffect(()=>{const s=()=>n.current();return window.addEventListener(dd,s),()=>window.removeEventListener(dd,s)},[])}function lB(e,n=()=>window.location.reload(),s=ry){const r=ay(e,s),a=u.useRef(n);a.current=n,u.useEffect(()=>tB(),[]),u.useEffect(()=>{if(!r||e===void 0||rB(e))return;let i=!1;const l=()=>{if(i)return;const c=document.visibilityState==="hidden";sB({hidden:c,idleMs:nB(),busy:WT()})&&(i=!0,aB(e),a.current())};l();const o=window.setInterval(l,Z6);return document.addEventListener("visibilitychange",l),()=>{window.clearInterval(o),document.removeEventListener("visibilitychange",l)}},[r,e])}const oB=9e4,HT=5*6e4,cB=500,dB=2e3,uB=3e3,hB="/_buddi/ready",Gl={reload:()=>window.location.reload(),now:()=>Date.now()};let ri=null,Dl=null,dc=null;const av=new Set;function Qh(e){ri=e;for(const n of av)n()}function oN(){return ri}function fB(e){return av.add(e),()=>av.delete(e)}function mB(){const e=new Uint8Array(32);return crypto.getRandomValues(e),[...e].map(n=>n.toString(16).padStart(2,"0")).join("")}async function ly(e=uB){const n=new AbortController,s=setTimeout(()=>n.abort(),e);try{const r=await fetch(`${hB}?challenge=${mB()}`,{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 pB(){const e=await ly();e&&(Dl=e)}function gB(){let e=Dl,n=!1,s=!1,r=cB,a;const i=async()=>{if(n)return;const l=await ly();if(!n){if(l===null)s=!0;else if(e!==null?l!==e:s){n=!0,Gl.reload();return}else e===null&&l!==""&&(e=l);r=Math.min(Math.round(r*1.5),dB),a=setTimeout(()=>void i(),r)}};return a=setTimeout(()=>void i(),r),()=>{n=!0,clearTimeout(a)}}function gm(e){if(ri){if(e.kind==="detected")return;Qh({...ri,...e});return}Qh({...e,startedAt:Gl.now()}),dc=gB()}function KT(e){ri&&Qh({...ri,...e})}function io(){dc==null||dc(),dc=null,Qh(null)}async function zd(e,n){gm(e);try{return await n()}catch(s){if(Gh(s))return;throw io(),s}}function xB(e){gm({kind:e.for==="stop"?"stop":"detected"})}async function cN(){if(ri)return;const e=await ly();if(Dl===null){e&&(Dl=e);return}if(!(!e||e===Dl||ri)){if(WT()){Dl=e;return}gm({kind:"detected"})}}function vB(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 Jh(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 Xh="buddi:plugin-pages-changed";function oy(){window.dispatchEvent(new Event(Xh))}function VT(e=!1){const[n,s]=u.useState([]);return u.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(Xh,a),document.addEventListener("visibilitychange",i),()=>{r=!0,window.removeEventListener(Xh,a),document.removeEventListener("visibilitychange",i)}},[e]),{all:n,rail:Jh(n,"rail"),settings:Jh(n,"settings"),find:(r,a)=>n.find(i=>i.plugin===r&&i.id===a)}}function iv(e,n){const s=(n??[]).filter(i=>i.plugin===e),r=Jh(s,"rail")[0]??Jh(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 jB="/api/chat/attention/stream";function GT(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 qT(e,n){const s=GT(e,n);return[...s.top,...s.middle,...s.bottom]}function Ud(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 wB(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 yB(e,n){return e&&(e.approvals>0||e.question)?"needs":n?"working":null}function bB(e){return new Map(((e==null?void 0:e.agents)??[]).map(n=>[n.agentId,n]))}function kB(){const[e,n]=u.useState(null);return u.useEffect(()=>{let s=!1;const r=()=>{je("/chat/attention").then(i=>{s||n(i)}).catch(()=>{})};r();const a=pm({url:jB,onEvent:i=>{i.name==="closing"?xB(i.data):i.name==="plugins-changed"?oy():r()},onReconnect:eB});return()=>{s=!0,a.close()}},[]),bB(e)}const gr="maker";function cy(e){return e.filter(n=>n.available&&!n.roles.includes(gr))}function YT(e){return cy(e).length>=2}function NB(e){var n;return((n=e.find(s=>s.roles.includes(gr)))==null?void 0:n.name)??"the agent maker"}const SB="{{default}}";function CB(e,n){return e.split(SB).join(n??"your assistant")}function EB(e,n){return((e==null?void 0:e.starters)??[]).slice(0,3).map(s=>CB(s,n))}function AB(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 $B(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 QT(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 TB="Settings → Model accounts",IB="Install it in Settings → Plugins";function lv(e){return e!=null&&e.heldBack?{section:"plugins",label:IB}:{section:"accounts",label:TB}}const RB={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]=RB[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 JT="buddi.rosterHidden",XT=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform||navigator.userAgent),dN=XT?"⌘\\":"Ctrl+\\",uN=XT?"Meta+\\":"Control+\\";function PB(){try{return window.localStorage.getItem(JT)==="1"}catch{return!1}}function hN(e){try{window.localStorage.setItem(JT,e?"1":"0")}catch{}}function ZT({agents:e,currentId:n,attention:s,onSelect:r,orientation:a="vertical",lastActivity:i,working:l,groups:o=[],currentGroupId:c=null,onSelectGroup:d,onNewGroup:h}){const f=[...e.top,...e.middle,...e.bottom],m=a==="vertical"?"right":"bottom",[p,x]=u.useState(PB),g=j=>t.jsx(MB,{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),y=()=>x(j=>(hN(!j),!j));if(u.useEffect(()=>{if(a!=="vertical")return;const j=v=>{v.key!=="\\"||!(v.metaKey||v.ctrlKey)||v.altKey||v.shiftKey||(v.preventDefault(),x(w=>(hN(!w),!w)))};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[a]),a==="vertical"&&p){const j=f.some(v=>Ud(s.get(v.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":uN,title:`Show the list (${dN})`,onClick:y,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":uN,title:`Hide the list (${dN})`,onClick:y,children:t.jsx(ie,{name:"chevron-left"})})]}):null,t.jsxs("div",{className:"wb-agent-scroll",children:[e.middle.map(g),d&&YT(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:()=>d(j.id),children:[t.jsx("span",{className:"wb-group-stack","aria-hidden":"true",children:j.members.slice(0,2).map(v=>{const w=f.find(N=>N.id===v);return t.jsx(xm,{className:"wb-group-chip",id:v,name:(w==null?void 0:w.name)??"?",face:w,initials:1},v)})}),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(v=>{var w;return((w=f.find(N=>N.id===v))==null?void 0:w.name)??v}).join(", ")})]})]},j.id))]}):d?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:yt,children:"add a teammate"}),"."]})]}):null]}),e.bottom.map(g)]})}function MB({agent:e,active:n,attention:s,side:r,onSelect:a,lastAt:i=null,working:l=!1}){const o=Ud(s),c=wB(s)??(e.available?i?O$(i):e.description:e.unavailableReason??"Cannot run right now"),d=yB(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,d==="working"?"working now":null,n?"current":null].filter(m=>m!==null&&m!=="").join(" — ");return t.jsxs(ed,{children:[t.jsx(td,{asChild:!0,children:t.jsxs("button",{className:"wb-face",...Qi(Io(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(xm,{className:"wb-face-mark",id:e.id,name:e.name,face:e}),d?t.jsx("span",{className:"wb-face-dot","data-state":d,"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(nd,{children:t.jsxs(sd,{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:OB(o)}):null]})})]})}function OB(e){return`${e.slice(0,1).toUpperCase()}${e.slice(1)}.`}function DB(e){let n=0;for(const s of e)n=(n*31+s.charCodeAt(0))%997;return n%6+1}const LB="modulepreload",FB=function(e,n){return new URL(e,n).href},fN={},_B=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(d=>{if(d=FB(d,r),d in fN)return;fN[d]=!0;const h=d.endsWith(".css"),f=h?'[rel="stylesheet"]':"";if(!!r)for(let x=l.length-1;x>=0;x--){const g=l[x];if(g.href===d&&(!h||g.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${d}"]${f}`))return;const p=document.createElement("link");if(p.rel=h?"stylesheet":LB,h||(p.as="script"),p.crossOrigin="",p.href=d,c&&p.setAttribute("nonce",c),document.head.appendChild(p),h)return new Promise((x,g)=>{p.addEventListener("load",x),p.addEventListener("error",()=>g(new Error(`Unable to preload CSS for ${d}`)))})}))}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)})},zB="buddi",UB=["core","coding","finance","garage","mail","maker","playground","research"],gi=e=>`./mascot/${e}.png`,BB=["core"],ov=(e,n)=>BB.includes(e)?`./mascot/anim/${e}-${n}.json`:null,WB=["🙂","📚","🧭","🦊","🛟","🌿","🛠️","🎧"],HB="Introduce yourself by name and say one thing you can do today.",KB=["Hello","A brain","What I take on","Reach me","Your assistant"],Su=(e,n=!1)=>e.length<2?e.join(""):`${e.slice(0,-1).join(", ")}${n&&e.length>2?", and ":" and "}${e[e.length-1]}`,Op=e=>e.charAt(0).toUpperCase()+e.slice(1),VB=["No","One","Two","Three","Four","Five","Six","Seven","Eight"],Zh=[{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."}],GB=["days","mail"],mN=[{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"}],D={tagline:"Setting up, on this Mac.",taglineElsewhere:"Setting up, on this computer.",chapters:KB,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 ${Su(e)} from withbuddi.com and reading them. ${n} of ${s}.`,ready:e=>`${Su(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":Op(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":Op(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: ${Su(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=>`${VB[e]??String(e)} ${e===1?"thing":"things"} still waiting.`,waitingBody:e=>`${Op(Su(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 Cu=null;const pN=new Map;function qB(){return Cu??(Cu=_B(()=>import("./lottie_light-DxWeiVDC.js").then(e=>e.l),[],import.meta.url).then(e=>e.default)),Cu.catch(()=>{Cu=null}),Cu}function YB(e){let n=pN.get(e);return n||(n=fetch(e).then(s=>s.ok?s.text():null).catch(()=>null),pN.set(e,n)),n}const gN="(prefers-reduced-motion: reduce)";function eI(){const[e,n]=u.useState(()=>typeof window.matchMedia=="function"&&!window.matchMedia(gN).matches);return u.useEffect(()=>{var a;if(typeof window.matchMedia!="function")return;const s=window.matchMedia(gN),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 Bd({role:e="core",state:n,size:s,still:r,className:a,onStillError:i}){const l=u.useRef(null),o=eI(),[c,d]=u.useState(!1),h=s==="xs"?null:ov(e,n);return u.useEffect(()=>{if(d(!1),!o||!h)return;let f=!1,m=null;return Promise.all([qB(),YB(h)]).then(([p,x])=>{if(f||!x||!l.current)return;const g=p.loadAnimation({container:l.current,renderer:"svg",loop:!0,autoplay:!document.hidden,animationData:JSON.parse(x),rendererSettings:{preserveAspectRatio:"xMidYMid meet"}}),y=()=>{document.hidden?g.pause():g.play()};document.addEventListener("visibilitychange",y),m=()=>{document.removeEventListener("visibilitychange",y),g.destroy()},d(!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??gi(e),alt:"",onError:i})})}async function xN(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 tI(e,n="core"){const s=eI(),r=e!==null&&QB(e,n),[a,i]=u.useState(!1);return u.useEffect(()=>{if(i(!1),!e||r||!s||!ov(n,"idle"))return;let l=!1;return Promise.all([xN(e),xN(gi(n))]).then(([o,c])=>{if(l||!o||!c||o.length!==c.length)return;const d=o.reduce((h,f,m)=>h+Math.abs(f-c[m]),0)/o.length;i(d<12)}).catch(()=>{}),()=>{l=!0}},[e,r,s,n]),s&&ov(n,"idle")!==null&&(r||a)}function QB(e,n){const s=gi(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 xm({className:e,id:n,name:s,face:r,tint:a,size:i,unavailable:l,initials:o=2}){const[c,d]=u.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?Qi(Io({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:()=>d(h)}):(f==null?void 0:f.kind)==="image"?t.jsx("img",{src:f.url,alt:""}):(f==null?void 0:f.kind)==="emoji"?f.value:$B(s).slice(0,o)})}function Rn({id:e,name:n,size:s,unavailable:r,face:a}){return t.jsx(xm,{className:"ui-avatar",id:e,tint:DB(e),name:n,size:s,unavailable:r,face:a})}const nI="owner",vm="buddi";function jm(e){return e===nI}function JB(e,n=[]){var s;return jm(e)?vm:((s=n.find(r=>r.id===e))==null?void 0:s.name)??e}function sI({size:e}){return t.jsx(Rn,{id:nI,name:vm,size:e,face:{picture:gi("core")}})}function an({agents:e,id:n,size:s}){if(jm(n))return t.jsx(sI,{size:s});const r=e.find(a=>a.id===n);return t.jsx(Rn,{id:n,name:(r==null?void 0:r.name)??n,size:s,unavailable:r?!r.available:!1,face:r})}const rI=u.createContext(null);function XB({picture:e,children:n}){return t.jsx(rI.Provider,{value:e??null,children:n})}function aI({size:e,anim:n}){const s=u.useContext(rI),[r,a]=u.useState(null),i=tI(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(Bd,{state:n,still:s,className:"ui-mascot-blob",onStillError:()=>a(s)}):t.jsx("img",{src:s,alt:"",onError:()=>a(s)})})}const iI=u.createContext([]);function xr({text:e,className:n}){const s=cv(e.replace(/\r\n/g,`
97
+ `).split(`
98
+ `));return t.jsx("div",{className:n??"wb-md",children:s.map((r,a)=>t.jsx(dv,{block:r},a))})}const vN=/^(\s*)(```|~~~)\s*([\w+-]*)\s*$/,jN=/^(#{1,6})\s+(.*?)\s*#*\s*$/,wN=/^\s*([-*_])(\s*\1){2,}\s*$/,Eu=/^(\s*)([-*+])\s+(.*)$/,Xo=/^(\s*)(\d{1,9})[.)]\s+(.*)$/,Au=/^\s*>\s?(.*)$/,Dp=/^\s*\|.*\|\s*$/,yN=/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/;function cv(e){const n=[];let s=0;for(;s<e.length;){const r=e[s];if(r.trim()===""){s+=1;continue}const a=vN.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=jN.exec(r);if(i){n.push({type:"h",level:i[1].length,text:i[2]}),s+=1;continue}if(wN.test(r)){n.push({type:"hr"}),s+=1;continue}if(Au.test(r)){const o=[];for(;s<e.length&&Au.test(e[s]);)o.push(Au.exec(e[s])[1]),s+=1;n.push({type:"quote",blocks:cv(o),raw:o.join(`
100
+ `)});continue}if(Dp.test(r)&&s+1<e.length&&yN.test(e[s+1])){const o=Fp(r),c=Fp(e[s+1]).map(h=>{const f=h.startsWith(":"),m=h.endsWith(":");return f&&m?"center":m?"right":f?"left":null});s+=2;const d=[];for(;s<e.length&&Dp.test(e[s]);)d.push(Fp(e[s])),s+=1;n.push({type:"table",head:o,rows:d,align:c});continue}if(Eu.test(r)||Xo.test(r)){const o=Xo.exec(r)??Eu.exec(r),c=Xo.test(r),d=o[1].length,h=c?Number(o[2]):1,f=[];for(;s<e.length;){const m=c?Xo.exec(e[s]):Eu.exec(e[s]);if(!m||m[1].length!==d)break;const p=[m[3]];for(s+=1;s<e.length;){const x=e[s],g=x.trim()!==""&&Lp(x)>d,y=x.trim()===""&&s+1<e.length&&e[s+1].trim()!==""&&Lp(e[s+1])>d;if(!g&&!y)break;p.push(x.trim()===""?"":x.slice(Math.min(Lp(x),d+2))),s+=1}f.push(cv(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()===""||vN.test(o)||jN.test(o)||wN.test(o)||Au.test(o)||Eu.test(o)||Xo.test(o)||Dp.test(o)&&s+1<e.length&&yN.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 Lp(e){return e.length-e.trimStart().length}function Fp(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 dv({block:e}){switch(e.type){case"p":return t.jsx("p",{children:ir(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:ir(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(bN,{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(dv,{block:n},s))}),t.jsx(bN,{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(u.Fragment,{children:ir(a.text)},i):t.jsx(dv,{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:ir(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:ir(r)},a))},s))})]})})}}function bN({text:e,what:n,always:s=!1}){const[r,a]=u.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 ZB({handle:e}){const s=u.useContext(iI).find(r=>r.handle.toLowerCase()===e.toLowerCase());return s?t.jsxs(ed,{children:[t.jsx(td,{asChild:!0,children:t.jsxs("a",{className:"wb-mention-link",href:lt(s.id),children:["@",s.handle]})}),t.jsx(nd,{children:t.jsxs(sd,{className:"wb-agent-card",sideOffset:6,children:[t.jsx(Rn,{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 e5=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 ir(e){const n=[];let s=e,r=0;for(;s!=="";){const a=e5.exec(s);if(!a){n.push(...kN(s,r));break}a.index>0&&n.push(...kN(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:ir(a[3])},r)):a[4]!==void 0?n.push(t.jsx("strong",{children:ir(a[4])},r)):a[5]!==void 0?n.push(t.jsx("s",{children:ir(a[5])},r)):a[6]!==void 0?n.push(t.jsx("em",{children:ir(a[6])},r)):a[7]!==void 0?n.push(t.jsx("em",{children:ir(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:ir(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(ZB,{handle:a[11]},r)),s=s.slice(a.index+a[0].length)}return n}function kN(e,n){return e.split(`
102
+ `).flatMap((r,a)=>a===0?[r]:[t.jsx("br",{},`${n}-br-${a}`),r])}function t5({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(xr,{text:e.text})}):t.jsx("p",{className:"wb-empty",children:"This document came back with no body."})]})}const n5=["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 Ie(e,n){if(n===""||n==="$")return e;let s=e;for(const r of n.split(".")){const a=/^([^[\]]*)((?:\[\d+\])*)$/.exec(r);if(!a)return;const[,i="",l=""]=a;if(i!==""){if(s===null||typeof s!="object")return;s=s[i]}for(const o of l.match(/\d+/g)??[]){if(!Array.isArray(s))return;s=s[Number(o)]}if(s===void 0)return}return s}function Ke(e,n){if(n)return"const"in n?n.const:Ie(e,n.path)}function Es(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 bt(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):null}function Ja(e){return Array.isArray(e)?e:[]}function s5(e,n){const s=Ja(Ie(e,n.points)).map(a=>{const i=Es(Ie(a,n.y)),l=bt(Ie(a,n.x));return i===null||l===null?null:{x:l,y:i}}).filter(a=>a!==null),r=(n.referenceLines??[]).map(a=>{const i=Es(Ke(e,a.value));return i===null?null:{value:i,label:a.label,tone:a.tone??"neutral"}}).filter(a=>a!==null);return{points:s,unit:n.unit??"number",currency:bt(Ke(e,n.currency)),label:bt(Ke(e,n.label)),referenceLines:r,mark:n.mark??null,shadeBelow:Es(Ke(e,n.shadeBelow)),events:r5(e,n)}}function r5(e,n){const s=n.events;if(!s)return[];const r=[],a=(i,l)=>{const o=bt(Ie(i,s.label));if(o===null)return;const c=bt(Ie(i,s.at))??l;c!==null&&r.push({at:c,label:o,amount:s.amount?Es(Ie(i,s.amount)):null})};if(s.parent){for(const i of Ja(Ie(e,n.points))){const l=bt(Ie(i,n.x));for(const o of Ja(Ie(i,s.parent)))a(o,l)}return r}for(const i of Ja(Ie(e,s.path??n.points)))a(i,null);return r}function a5(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 d=Ie(o,c.key);let h=null;if(c.bar){const f=Es(Ke(o,c.bar.max))??Es(Ke(e,c.bar.max)),m=Es(d);if(f!==null&&f>0&&m!==null){const p=Math.max(0,Math.min(1,m/f));h={fraction:p,tone:l5(p*100,c.bar.thresholds)}}}return{value:d,type:c.type??"text",currency:bt(Ke(o,c.currency))??bt(Ke(e,c.currency)),bar:h}}),a=Ja(Ie(e,n.rows)),i=n.groupBy?i5(a,n.groupBy,r):[{label:null,rows:a.map(r)}],l=(n.summary??[]).map(o=>({label:o.label,value:Ke(e,o.value),unit:o.unit??"text",currency:bt(Ke(e,o.currency)),tone:o.tone??"neutral"}));return{columns:s,groups:i,summary:l,empty:n.empty??"Nothing to show."}}function i5(e,n,s){const r=new Map;for(const a of e){const i=String(Ie(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 l5(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 o5(e,n){return{bars:Ja(Ie(e,n.bars)).map(r=>{const a=Es(Ie(r,n.value)),i=bt(Ie(r,n.category));return a===null||i===null?null:{category:i,value:a}}).filter(r=>r!==null),unit:n.unit??"number",currency:bt(Ke(e,n.currency))}}function c5(e,n){if(n.pairs)return{pairs:n.pairs.map(r=>({label:r.label,value:Ke(e,r.value),unit:r.unit??"text",currency:bt(Ke(e,r.currency)),tone:r.tone??"neutral"}))};const s=Ie(e,n.from??"$");return s===null||typeof s!="object"||Array.isArray(s)?{pairs:[]}:{pairs:Object.entries(s).map(([r,a])=>({label:Ht(r),value:a,unit:"text",currency:null,tone:"neutral"}))}}const d5=new Set(["good","warning","critical","neutral","accent"]),u5=new Set(n5);function uv(e){return typeof e=="string"&&u5.has(e)?e:null}function dy(e,n,s=""){const r=n.empty??"Nothing to show.",a=s.split(".")[0]??"";if(n.notice){const l=bt(Ie(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:uv(n.notice.icon??"bell"),value:"",label:l.trim(),lines:[],tone:"neutral",link:o}],notice:!0,empty:r}}}return{tiles:Ja(Ie(e,n.items)).map(l=>{const o=bt(Ie(l,n.value))??"",c=bt(Ie(l,n.label))??"";if(o===""&&c==="")return null;const d=n.tone?bt(Ie(l,n.tone)):null;return{icon:uv(Ke(l,n.icon)),value:o,label:c,lines:(n.lines??[]).slice(0,2).map(h=>bt(Ie(l,h))).filter(h=>h!==null&&h.trim()!==""),tone:d!==null&&d5.has(d)?d:"neutral",link:null}}).filter(l=>l!==null),notice:!1,empty:r}}function h5(e,n){const s=bt(Ke(e,n.kind)),r=s==="image"||s==="pdf"?s:"text",a=n.src?bt(Ie(e,n.src)):null;return{kind:r,text:n.text?bt(Ie(e,n.text)):null,src:a&&oI(a)?a:null,title:bt(Ke(e,n.title)),metadata:(n.metadata??[]).map(i=>({label:i.label,value:Ke(e,i.value),unit:i.unit??"text"}))}}function f5(e,n){const s=n.diff?Ie(e,n.diff):void 0;return{diff:typeof s=="string"&&s.trim()!==""?s:null,title:bt(Ke(e,n.title)),metadata:(n.metadata??[]).map(r=>({label:r.label,value:Ke(e,r.value),unit:r.unit??"text"}))}}function m5(e,n){const s=n.output?Ie(e,n.output):void 0,r=l=>{const o=l?Ie(e,l):void 0;return typeof o=="number"&&Number.isInteger(o)?o:null},a=r(n.omittedBytes),i=n.elapsedMs?Ie(e,n.elapsedMs):void 0;return{command:bt(Ke(e,n.command)),output:typeof s=="string"?s:null,exitCode:r(n.exitCode),elapsedMs:typeof i=="number"&&Number.isFinite(i)&&i>=0?i:null,omittedBytes:a!==null&&a>0?a:null,metadata:(n.metadata??[]).map(l=>({label:l.label,value:Ke(e,l.value),unit:l.unit??"text"}))}}const p5=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function lI(e){const n=e!==null&&typeof e=="object"&&!Array.isArray(e)?e.artifactId??e.id:e;return typeof n=="string"&&p5.test(n)?n.toLowerCase():null}function g5(e,n){return{artifactId:n.src?lI(Ie(e,n.src)):null,title:bt(Ke(e,n.title)),caption:bt(Ke(e,n.caption)),...n.captionLabel?{captionLabel:bt(Ke(e,n.captionLabel))}:{}}}function NN(e){if(!oI(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 x5(e,n){const s=n.src?bt(Ie(e,n.src)):null,r=n.port?Ie(e,n.port):null,a=n.awaiting?bt(Ie(e,n.awaiting)):null;return{target:s?NN(s):null,title:bt(Ke(e,n.title)),output:n.output?bt(Ie(e,n.output)):null,port:typeof r=="number"&&Number.isInteger(r)&&r>0&&r<=65535?r:null,awaiting:a?NN(a):null,reloadsItself:n.reloadsItself?Ie(e,n.reloadsItself)===!0:!1,ports:n.ports?v5(Ie(e,n.ports)):[]}}function v5(e){const n=Ja(e).filter(s=>typeof s=="number"&&Number.isInteger(s)&&s>0&&s<=65535);return[...new Set(n)].sort((s,r)=>s-r)}function oI(e){return e.startsWith("/")&&!e.startsWith("//")}function Ht(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 cI(e,n){const s=e.map??{};switch(e.renderer){case"timeseries":return{renderer:"timeseries",props:s5(n,s)};case"table":return{renderer:"table",props:a5(n,s)};case"bars":return{renderer:"bars",props:o5(n,s)};case"keyvalue":return{renderer:"keyvalue",props:c5(n,s)};case"tiles":return{renderer:"tiles",props:dy(n,s,e.tool)};case"document":return{renderer:"document",props:h5(n,s)};case"diff":return{renderer:"diff",props:f5(n,s)};case"terminal":return{renderer:"terminal",props:m5(n,s)};case"image":return{renderer:"image",props:g5(n,s)};case"preview":return{renderer:"preview",props:x5(n,s)};default:return{renderer:"structured",props:{value:n}}}}var j5=Object.defineProperty,er=(e,n)=>j5(e,"name",{value:n,configurable:!0}),uy="Dialog",[dI,sle]=br(uy),[w5,qr]=dI(uy),wm=er(e=>{const{__scopeDialog:n,children:s,open:r,defaultOpen:a,onOpenChange:i,modal:l=!0}=e,o=u.useRef(null),c=u.useRef(null),[d,h]=fi({prop:r,defaultProp:a??!1,onChange:i,caller:uy}),[f,m]=u.useState(0),[p,x]=u.useState(0);return t.jsx(w5,{scope:n,triggerRef:o,contentRef:c,contentId:ur(),titleId:ur(),descriptionId:ur(),titlePresent:f>0,descriptionPresent:p>0,setTitleCount:m,setDescriptionCount:x,open:d,onOpenChange:h,onOpenToggle:u.useCallback(()=>h(g=>!g),[h]),modal:l,children:s})},"Dialog"),y5="DialogTrigger",b5=u.forwardRef(er(function(n,s){const{__scopeDialog:r,...a}=n,i=qr(y5,r),l=Tt(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":Nm(i.open),...a,ref:l,onClick:We(n.onClick,i.onOpenToggle)})},"DialogTrigger")),uI="DialogPortal",[k5,hI]=dI(uI,{forceMount:void 0}),ym=er(e=>{const{__scopeDialog:n,forceMount:s,children:r,container:a}=e,i=qr(uI,n);return t.jsx(k5,{scope:n,forceMount:s,children:u.Children.map(r,l=>t.jsx(Gr,{present:s||i.open,children:t.jsx(Yf,{asChild:!0,container:a,children:l})}))})},"DialogPortal"),hv="DialogOverlay",hy=u.forwardRef(er(function(n,s){const r=hI(hv,n.__scopeDialog),{forceMount:a=r.forceMount,...i}=n,l=qr(hv,n.__scopeDialog);return l.modal?t.jsx(Gr,{present:a||l.open,children:t.jsx(S5,{...i,ref:s})}):null},"DialogOverlay")),N5=ti("DialogOverlay.RemoveScroll"),S5=u.forwardRef(er(function(n,s){const{__scopeDialog:r,...a}=n,i=qr(hv,r),l=BA(),o=Tt(s,l);return t.jsx(Kw,{as:N5,allowPinchZoom:!0,shards:[i.contentRef],children:t.jsx(St.div,{"data-state":Nm(i.open),...a,ref:o,style:{pointerEvents:"auto",...a.style}})})},"DialogOverlayImpl")),ud="DialogContent",bm=u.forwardRef(er(function(n,s){const r=hI(ud,n.__scopeDialog),{forceMount:a=r.forceMount,...i}=n,l=qr(ud,n.__scopeDialog);return t.jsx(Gr,{present:a||l.open,children:l.modal?t.jsx(C5,{...i,ref:s}):t.jsx(E5,{...i,ref:s})})},"DialogContent")),C5=u.forwardRef(er(function(n,s){const r=qr(ud,n.__scopeDialog),a=u.useRef(null),i=Tt(s,r.contentRef,a);return u.useEffect(()=>{const l=a.current;if(l)return rT(l)},[]),t.jsx(fI,{...n,ref:i,trapFocus:r.open,disableOutsidePointerEvents:r.open,onCloseAutoFocus:We(n.onCloseAutoFocus,l=>{var o;l.preventDefault(),(o=r.triggerRef.current)==null||o.focus()}),onPointerDownOutside:We(n.onPointerDownOutside,l=>{const o=l.detail.originalEvent,c=o.button===0&&o.ctrlKey===!0;(o.button===2||c)&&l.preventDefault()}),onFocusOutside:We(n.onFocusOutside,l=>l.preventDefault())})},"DialogContentModal")),E5=u.forwardRef(er(function(n,s){const r=qr(ud,n.__scopeDialog),a=u.useRef(!1),i=u.useRef(!1);return t.jsx(fI,{...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 d,h;(d=n.onInteractOutside)==null||d.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")),fI=u.forwardRef(er(function(n,s){const{__scopeDialog:r,trapFocus:a,onOpenAutoFocus:i,onCloseAutoFocus:l,...o}=n,c=qr(ud,r);return cm(),t.jsx(t.Fragment,{children:t.jsx(z$,{asChild:!0,loop:!0,trapped:a,onMountAutoFocus:i,onUnmountAutoFocus:l,children:t.jsx(qf,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionPresent?c.descriptionId:void 0,"aria-labelledby":c.titlePresent?c.titleId:void 0,"data-state":Nm(c.open),...o,ref:s,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})},"DialogContentImpl")),A5="DialogTitle",km=u.forwardRef(er(function(n,s){const{__scopeDialog:r,...a}=n,i=qr(A5,r),{setTitleCount:l}=i;return ms(()=>(l(o=>o+1),()=>l(o=>o-1)),[l]),t.jsx(St.h2,{id:i.titleId,...a,ref:s})},"DialogTitle")),$5="DialogClose",fy=u.forwardRef(er(function(n,s){const{__scopeDialog:r,...a}=n,i=qr($5,r);return t.jsx(St.button,{type:"button",...a,ref:s,onClick:We(n.onClick,()=>i.onOpenChange(!1))})},"DialogClose"));function Nm(e){return e?"open":"closed"}er(Nm,"getState");const T5=5;function pe(e,n,s){const[r,a]=u.useState(void 0),[i,l]=u.useState(null),[o,c]=u.useState(!0),[d,h]=u.useState(0),[f,m]=u.useState(0),p=u.useRef(e);return p.current=e,u.useEffect(()=>{let x=!1;return c(!0),p.current().then(g=>{x||(a(g),l(null),m(0))}).catch(g=>{x||(l(g instanceof fe?g.message:String(g)),m(y=>y+1))}).finally(()=>{x||c(!1)}),()=>{x=!0}},[...n,d]),u.useEffect(()=>{if(!s||f>=T5)return;const x=window.setTimeout(()=>h(g=>g+1),s*2**f);return()=>window.clearTimeout(x)},[s,f,d]),{data:r,error:i,loading:o,reload:()=>{m(0),h(x=>x+1)}}}const mI={width:480,height:160,top:10,right:10,bottom:22,left:40},pI={width:1200,height:180,top:10,right:40,bottom:22,left:40};function I5({xs:e,series:n}){const s=pI,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)),d=c.length>0?Math.min(...c):0,h=c.length>0?Math.max(...c):1;let f=d,m=h;if(f===m)f-=1,m+=1;else{const O=(m-f)*.08;f-=O,m+=O}const p=O=>Gs(s.top+a-(O-f)/(m-f)*a),x=o.length>0&&o.every(O=>O.unit==="percent"),g=x?100:Math.max(1,...o.flatMap(O=>i(O.values))),y=O=>Gs(s.top+a-Math.max(0,O)/g*a),j=e.length,v=j>0?r/j:r,w=O=>Gs(s.left+v*(O+.5)),N=n.map(O=>{if(O.type==="bar")return"";let R="M";const _=[];return O.values.forEach((z,U)=>{if(z===null||!Number.isFinite(z)){R="M";return}_.push(`${R}${w(U)},${p(z)}`),R="L"}),_.join(" ")}),k=[],S=v*.6/Math.max(1,o.length),b=s.height-s.bottom;let C=0;n.forEach((O,R)=>{if(O.type!=="bar")return;const _=C++;O.values.forEach((z,U)=>{if(z===null||!Number.isFinite(z)||z<=0)return;const P=y(z);k.push({series:R,index:U,x:Gs(w(U)-v*.3+S*_),y:P,width:Gs(S),height:Gs(b-P)})})});const $=c.length>0?qh(d,h,2).map(O=>({value:O,y:p(O)})):[],A=o.length===0?[]:(x?[0,50,100]:qh(0,g,2)).map(O=>({value:O,y:y(O),percent:x})),I=Math.max(1,Math.ceil(j/8)),M=e.flatMap((O,R)=>R%I===0?[{index:R,x:w(R)}]:[]);return{lines:N,bars:k,targetY:null,ticks:$,xLabels:M,rightTicks:A}}function R5({xs:e,series:n,type:s="line",target:r=null}){const a=mI,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,d=o.length>0?Math.max(...o):1;if(c===d)c-=1,d+=1;else if(s==="line"){const w=(d-c)*.08;c-=w,d+=w}const h=w=>Gs(a.top+l-(w-c)/(d-c)*l),f=e.length,m=f>0?i/f:i,p=w=>Gs(s==="bar"?a.left+m*(w+.5):a.left+(f<=1?i/2:w/(f-1)*i)),x=s==="line"?n.map(w=>{let N="M";const k=[];return w.values.forEach((S,b)=>{if(S===null||!Number.isFinite(S)){N="M";return}k.push(`${N}${p(b)},${h(S)}`),N="L"}),k.join(" ")}):[],g=[];if(s==="bar"&&f>0){const w=m*.7,N=w/Math.max(1,n.length),k=h(0);n.forEach((S,b)=>{S.values.forEach((C,$)=>{if(C===null||!Number.isFinite(C))return;const A=h(C);g.push({series:b,index:$,x:Gs(a.left+m*$+(m-w)/2+N*b),y:Math.min(A,k),width:Gs(N),height:Gs(Math.abs(k-A))})})})}const j=(o.length>0?qh(Math.min(...o),Math.max(...o),2):[]).map(w=>({value:w,y:h(w)})),v=f===0?[]:f===1?[0]:f<5?[0,f-1]:[0,Math.floor((f-1)/2),f-1];return{lines:x,bars:g,targetY:r!==null&&Number.isFinite(r)?h(r):null,ticks:j,xLabels:v.map(w=>({index:w,x:p(w)}))}}function P5(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 d=c[c.length-1];return`${o.label}: latest ${s(d)}, 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 M5({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?pI:mI,d=o?I5({xs:e,series:n}):R5({xs:e,series:n,type:s,target:r}),h=P5({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:[d.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)),(d.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}),d.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}`)),d.lines.map((f,m)=>f?t.jsx("path",{className:"ui-chart-line","data-series":m,d:f},m):null),d.targetY!==null?t.jsx("line",{className:"ui-chart-target","data-testid":"chart-target",x1:c.left,x2:c.width-c.right,y1:d.targetY,y2:d.targetY}):null,d.xLabels.map(f=>t.jsx("text",{x:f.x,y:c.height-6,textAnchor:o?"middle":d.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 Gs(e){return Math.round(e*10)/10}const my="(max-width: 900px)";function Gn(e){const[n,s]=u.useState(()=>{try{return window.matchMedia(e).matches}catch{return!1}});return u.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 xi(...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:xi("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":n,...a})}function st({variant:e,size:n,className:s,...r}){return t.jsx("a",{className:xi("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":n,...r})}function Wd({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 se({children:e,align:n,valign:s,className:r}){return t.jsx("div",{className:xi("ui-toolbar",r),"data-align":n,"data-valign":s,children:e})}function gt(){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 d=u.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":d,children:[t.jsx("span",{className:"ui-field-label",id:d,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 Ts({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 Ce({tone:e,mono:n,dot:s,children:r,className:a,title:i}){return t.jsxs("span",{className:xi("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 lo({children:e}){return t.jsx("span",{className:"ui-tag",children:e})}function Hd({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(Ce,{tone:n,children:e})}function q({tone:e,title:n,children:s,role:r,action:a}){return a?t.jsx("div",{className:"ui-notice","data-tone":e,role:r,children:t.jsxs("div",{className:"ui-notice-row",children:[t.jsxs("div",{className:"ui-notice-body",children:[n?t.jsx("div",{className:"ui-notice-title",children:n}):null,s]}),a]})}):t.jsxs("div",{className:"ui-notice","data-tone":e,role:r,children:[n?t.jsx("div",{className:"ui-notice-title",children:n}):null,s]})}function re({message:e}){return e?t.jsx(q,{tone:"critical",role:"alert",children:e}):null}function 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(aI,{size:"sm"}),t.jsx("p",{children:a})]}):t.jsx("p",{className:"ui-empty",children:a})}function as({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 py({children:e}){return t.jsx("div",{className:"ui-page",children:e})}function _i({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 js({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(py,{children:[t.jsx(_i,{title:n,lede:s,actions:r}),a]})}function ge({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 rt({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 Sr({tone:e,title:n,meta:s,actions:r,children:a,foot:i,onClick:l,label:o,as:c="div",labelledBy:d,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":d,...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 de({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 O5({children:e}){return t.jsx("div",{className:"ui-row",children:e})}function Sm({inline:e,children:n}){return t.jsx("div",{className:"ui-stats","data-inline":e?"true":void 0,children:n})}function Lr({label:e,value:n,note:s,tone:r,size:a}){return t.jsxs("div",{className:"ui-stat",children:[t.jsx("div",{className:"ui-stat-k",children:e}),t.jsx("div",{className:"ui-stat-v","data-tone":r,"data-size":a,children:n}),s?t.jsx("div",{className:"ui-stat-n",children:s}):null]})}function Qt({items:e}){return t.jsx("dl",{className:"ui-kv",children:e.map((n,s)=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:n.label}),t.jsx("dd",{children:n.value})]},n.key??s))})}function Yr({children:e}){return t.jsx("div",{className:"ui-table-wrap",children:t.jsx("table",{className:"ui-table",children:e})})}function gy({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 _t({children:e,label:n}){return t.jsx("pre",{className:"ui-code","aria-label":n,children:e})}function Kt({summary:e,boxed:n,open:s,className:r,onToggle:a,children:i}){return t.jsxs("details",{className:xi("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(wm,{open:!0,onOpenChange:i=>{i||n()},children:t.jsxs(ym,{children:[t.jsx(hy,{className:"ui-sheet-overlay"}),t.jsxs(bm,{className:"ui-sheet","data-size":s,"aria-describedby":void 0,children:[t.jsxs("div",{className:"ui-sheet-head",children:[t.jsx(km,{className:"ui-sheet-title",children:e}),t.jsx(fy,{asChild:!0,children:t.jsx(E,{size:"sm",children:"Close"})})]}),a,r?t.jsx("div",{className:"ui-sheet-foot",children:r}):null]})]})})}function zt({title:e,onClose:n,foot:s,children:r}){return t.jsx(wm,{open:!0,onOpenChange:a=>{a||n()},children:t.jsxs(ym,{children:[t.jsx(hy,{className:"ui-sheet-overlay","data-layer":"modal"}),t.jsxs(bm,{className:"ui-modal",role:"alertdialog","aria-describedby":void 0,children:[t.jsx(km,{className:"ui-modal-title",children:e}),r,s?t.jsx("div",{className:"ui-modal-foot",children:s}):null]})]})})}function Qn({label:e,items:n,note:s,trigger:r,sheet:a,stacked:i}){const l=Gn(D5);return a&&l&&!r?t.jsx(L5,{label:e,items:n,title:a.title,sub:a.sub}):t.jsx(F5,{label:e,items:n,note:s,trigger:r,stacked:i})}const D5="(max-width: 720px)";function L5({label:e,items:n,title:s,sub:r}){const[a,i]=u.useState(!1);return t.jsxs(wm,{open:a,onOpenChange:i,children:[t.jsx(b5,{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(ym,{children:[t.jsx(hy,{className:"ui-sheet-overlay",onClick:l=>l.stopPropagation()}),t.jsxs(bm,{className:"ui-action-sheet","aria-describedby":void 0,onClick:l=>l.stopPropagation(),children:[t.jsxs("div",{className:"ui-action-sheet-head",children:[t.jsx(km,{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(fy,{asChild:!0,children:t.jsx(E,{className:"ui-action-sheet-cancel",children:"Cancel"})})]})]})]})}function F5({label:e,items:n,note:s,trigger:r,stacked:a}){const i=o=>o.stopPropagation(),l=u.useRef(!1);return t.jsxs(Dd,{modal:!1,onOpenChange:o=>{o&&(l.current=!1)},children:[t.jsx(Ld,{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($o,{children:t.jsxs(Fd,{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(Yi,{className:"ui-menu-label",children:s}):null,n.map((o,c)=>o?o==="separator"?t.jsx(da,{className:"ui-menu-sep"},`sep-${c}`):"heading"in o?t.jsx(Yi,{className:"ui-menu-label",children:o.heading},`head-${c}`):t.jsxs(Vs,{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 _5({title:e,actions:n,onClose:s,onCloseAutoFocus:r,onOpenAutoFocus:a,label:i,children:l}){return t.jsx(wm,{open:!0,modal:!1,onOpenChange:o=>{o||s()},children:t.jsx(ym,{children:t.jsxs(bm,{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(km,{className:"ui-dock-title",children:e}),t.jsxs("div",{className:"ui-dock-actions",children:[n,t.jsx(fy,{asChild:!0,children:t.jsx(E,{size:"sm",variant:"ghost",children:"Close"})})]})]}),t.jsx("div",{className:"ui-dock-body",children:l})]})})})}function Ro({level:e,label:n,children:s}){return t.jsx("nav",{className:"ui-tabs","data-level":e,"aria-label":n,children:s})}function Ji({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 Jt({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 ut({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]}),d=l?"true":void 0;return e?t.jsx("a",{className:"ui-list-row","data-dimmed":d,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":d,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":d,children:c})}function gI({href:e,onClick:n,current:s,lead:r,title:a,meta:i,sub:l,snippet:o,side:c,strong:d}){return t.jsxs("a",{className:"ui-pick",href:e,"data-strong":d===void 0?void 0:String(d),"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 xI({list:e,detail:n,empty:s,label:r,className:a}){return t.jsxs("div",{className:xi("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 ef({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 z5=8;function U5({label:e,options:n,value:s,onChange:r,max:a,disabled:i,id:l}){const[o,c]=u.useState(!1),[d,h]=u.useState(""),[f,m]=u.useState(0),p=u.useRef(null),x=u.useRef(null),g=u.useRef(null),y=u.useRef(null),j=u.useId(),v=R=>{var _;return((_=n.find(z=>z.value===R))==null?void 0:_.label)??R},w=a!==void 0&&s.length>=a,N=n.filter(R=>!s.includes(R.value)),k=n.length>z5,S=d.trim().toLowerCase(),b=S===""?N:N.filter(R=>R.label.toLowerCase().includes(S)),C=Math.min(f,Math.max(0,b.length-1)),$=R=>{var _;c(!1),h(""),m(0),R&&((_=x.current)==null||_.focus())};u.useEffect(()=>{var _;if(!o)return;(_=k?g.current:y.current)==null||_.focus();const R=z=>{p.current&&!p.current.contains(z.target)&&$(!1)};return document.addEventListener("mousedown",R),()=>document.removeEventListener("mousedown",R)},[o,k]);const A=R=>{const _=[...s,R];r(_),h(""),m(0);const z=a!==void 0&&_.length>=a;(z||_.length>=n.length)&&$(!z)},I=R=>{if(R.key==="Escape")R.preventDefault(),$(!0);else if(R.key==="ArrowDown")R.preventDefault(),m(b.length===0?0:(C+1)%b.length);else if(R.key==="ArrowUp")R.preventDefault(),m(b.length===0?0:(C-1+b.length)%b.length);else if(R.key==="Enter"){R.preventDefault();const _=b[C];_&&A(_.value)}else R.key==="Backspace"&&d===""&&s.length>0&&(R.preventDefault(),r(s.slice(0,-1)))},M=R=>`${j}-${R}`,O=o&&b.length>0?M(C):void 0;return t.jsxs("div",{className:"ui-chippicker",ref:p,id:l,children:[s.map(R=>t.jsx(ef,{label:v(R),disabled:i,onRemove:()=>r(s.filter(_=>_!==R)),children:v(R)},R)),t.jsxs("div",{className:"ui-chippicker-add",children:[t.jsx("button",{ref:x,type:"button",className:"ui-btn","data-size":"sm","data-variant":"ghost","aria-haspopup":"listbox","aria-expanded":o,"aria-controls":o?j:void 0,disabled:i||w||N.length===0,onClick:()=>o?$(!1):c(!0),children:"Add…"}),o?t.jsxs("div",{className:"ui-menu ui-chippicker-menu",onKeyDown:I,children:[k?t.jsx("input",{ref:g,type:"search",className:"ui-chippicker-filter","aria-label":`Filter ${e}`,"aria-controls":j,"aria-activedescendant":O,value:d,onChange:R=>{h(R.target.value),m(0)}}):null,t.jsxs("div",{ref:y,id:j,role:"listbox","aria-multiselectable":"true","aria-label":e,"aria-activedescendant":k?void 0:O,tabIndex:k?-1:0,className:"ui-chippicker-list",children:[b.map((R,_)=>t.jsx("div",{id:M(_),role:"option","aria-selected":"false",className:"ui-menu-item","data-highlighted":_===C?"":void 0,onMouseEnter:()=>m(_),onMouseDown:z=>z.preventDefault(),onClick:()=>A(R.value),children:R.label},R.value)),b.length===0?t.jsx("p",{className:"ui-menu-empty",children:"Nothing matches"}):null]})]}):null]})]})}function vI({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 Cm({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 Yn({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 Nc({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 d;c.preventDefault(),(d=a.onClick)==null||d.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 jI({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:d=>{d.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 hd({size:e}){return t.jsx("span",{className:"ui-mark","data-size":e,"aria-hidden":"true",children:"b"})}function wI({quiet:e,still:n,className:s,children:r}){return t.jsx("div",{className:xi("ui-fieldbg",s),"data-quiet":e?"true":void 0,"data-still":n?"true":void 0,children:r})}function B5({dock:e,className:n,children:s}){return t.jsxs("div",{className:xi("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 W5(e){const n={};for(const s of e??[])n[s.key]=s.default;return n}function xy(e){const[n,s]=u.useState({}),r=e??[],a={...W5(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 H5({props:e,timezone:n="UTC",onDecided:s}){var w;const[r,a]=u.useState(null),[i,l]=u.useState(null),[o,c]=u.useState(!1),[d,h]=u.useState(null);u.useEffect(()=>{let N=!1;return a(null),l(null),T.approval(e.approvalId).then(k=>{N||a(k)}).catch(k=>{N||l(k instanceof fe?k.message:String(k))}),()=>{N=!0}},[e.approvalId]);const{values:f,controls:m}=xy(r==null?void 0:r.choices),p=(N,k)=>{h(N),l(null),(f&&N==="approve"?T.decide(e.approvalId,N,k,f):T.decide(e.approvalId,N,k)).then(S=>{a(S.action),s==null||s(S.action)}).catch(S=>l(S instanceof fe?S.message:String(S))).finally(()=>h(null))};if(i&&!r)return t.jsx("p",{className:"wb-empty",children:i});if(!r)return t.jsx("p",{className:"wb-empty",children:"Loading the envelope…"});const x=r.state==="pending",g=(w=r.permissionScopes)==null?void 0:w.includes("always"),y=K5(r),j=(r.preview??"").split(`
103
+ `).length>12||(r.preview??"").length>900,v=[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=>Ht(N)).join(" · ")}),t.jsx("dt",{children:"Status"}),t.jsxs("dd",{children:[x?t.jsx(Ce,{tone:"warning",dot:!0,children:"waiting for you"}):t.jsx(Hd,{state:r.state}),!x&&v?t.jsxs("span",{className:"wb-envelope-note",children:[" ",v]}):null]}),t.jsx("dt",{children:x?"Expires":"Decided"}),t.jsx("dd",{children:ft(x?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(re,{message:i}),x?m:null,x?t.jsxs("div",{className:"wb-envelope-decide",children:[t.jsx("p",{className:"wb-envelope-note",children:g?"Auto and Always also approve later calls to this tool in that scope; you can take it back on the agent's Tools tab.":"This runs the action exactly as shown above."}),t.jsxs("div",{className:"wb-envelope-buttons",children:[t.jsx("button",{className:"ui-btn","data-variant":"danger",disabled:d!==null,onClick:()=>p("reject"),children:d==="reject"?"Rejecting…":"Reject"}),g?t.jsxs(t.Fragment,{children:[t.jsx("button",{className:"ui-btn",disabled:d!==null,onClick:()=>p("approve","conversation"),children:"Auto: this conversation"}),t.jsx("button",{className:"ui-btn",disabled:d!==null,onClick:()=>p("approve","always"),children:"Always: this agent"})]}):null,t.jsx("button",{className:"ui-btn","data-variant":"good",disabled:d!==null,onClick:()=>p("approve"),children:d==="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:y.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 K5(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(SN(Ht(a),i));else s!=null&&n.push({label:"Envelope",value:vy(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 · ${Ht(a)}`;n.some(o=>o.label===l)||n.push(SN(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 SN(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:vy(n)}}function vy(e){return e==null?"—":Array.isArray(e)?e.map(n=>vy(n)).join(", ")||"—":typeof e=="object"?JSON.stringify(e):kn(e,"text",null)}const V5=new Set(["image/png","image/jpeg","image/gif","image/webp"]),G5=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function tf(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"||!G5.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 jy(e){return V5.has(e.toLowerCase())}function vr(e){return`/api/artifacts/${encodeURIComponent(e)}/preview`}function ai(e){return`/api/artifacts/${encodeURIComponent(e)}/download`}function vs(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 wy(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 zi={image:"Image",pdf:"PDF",table:"Spreadsheet",text:"Document",code:"Code",audio:"Audio",video:"Video",archive:"Archive",file:"File"};function ch(e){return`artifact:${e}`}function q5(e){const n=wy(e.mime,e.filename);return{id:ch(e.artifactId),tool:zi[n],title:e.filename??"Untitled file",renderer:"artifact",props:{attachment:e},at:null,source:"artifact",substantial:!1}}function Y5({props:e}){const n=lI(e.artifactId),[s,r]=u.useState(null),[a,i]=u.useState(null),[l,o]=u.useState(!1);if(u.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",d=[a?`${a.width} × ${a.height}`:null,s!=null&&s.sizeBytes?vs(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:vr(n),className:"wb-image-link",title:"Open at full size",children:t.jsx("img",{src:vr(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(se,{children:[t.jsx("span",{className:"wb-image-name",children:c}),d.length>0?t.jsx("span",{className:"wb-image-facts",children:d.join(" · ")}):null,t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx(st,{size:"sm",href:ai(n),download:(s==null?void 0:s.filename)??c,children:"Download"})]}),e.caption&&e.captionLabel?t.jsx(Kt,{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 Q5({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 J5=8;function yI({text:e,label:n="Output",className:s}){const r=u.useRef(null),a=u.useRef(!0);return u.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<=J5},children:e})}function X5(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 Z5({text:e}){const[n,s]=u.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 e8({props:e}){const n=e.output??"";return t.jsxs("div",{className:"wb-terminal",children:[t.jsxs(se,{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(Ce,{tone:e.exitCode===0?"good":"critical",mono:!0,children:["exit ",e.exitCode]}):null,e.elapsedMs!==null?t.jsx("span",{className:"wb-terminal-fact",children:X5(e.elapsedMs)}):null,t.jsx("span",{className:"ui-toolbar-spacer"}),n!==""?t.jsx(Z5,{text:n}):null]}),e.omittedBytes!==null?t.jsxs("p",{className:"wb-terminal-note",children:["First ",vs(e.omittedBytes)," not shown."]}):null,n!==""?t.jsx(yI,{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 t8(){const e=window.location.hostname.replace(/^\[|\]$/g,"").toLowerCase();return e==="127.0.0.1"||e==="::1"||e==="localhost"}function CN(e){try{const n=new URL(e);return n.searchParams.delete("ticket"),n.toString()}catch{return e}}function n8(e){const n=new Set(e.ports??[]);return e.port!==null&&n.add(e.port),[...n].sort((s,r)=>s-r)}function s8({props:e}){var k;const[n,s]=u.useState(null),[r,a]=u.useState(null),[i,l]=u.useState(null),[o,c]=u.useState(!1),d=((k=e.target)==null?void 0:k.plugin)??null,h=n8(e),[f,m]=u.useState(null),p=f!==null&&h.includes(f)?f:e.port,x=e.target?p!==null&&p!==e.port?`${e.target.name}.${p}`:e.target.name:null,g=e.changes??0,y=u.useRef(g),[j,v]=u.useState(0);u.useEffect(()=>{g<=y.current||(y.current=g,e.reloadsItself||v(S=>S+1))},[g,e.reloadsItself]),u.useEffect(()=>{if(d===null||x===null)return;let S=!0;return s(null),a(null),l(null),v(0),T.previewLink(d,x).then(b=>{S&&(s(b.url),a(CN(b.url)))}).catch(b=>{S&&l(b instanceof Error?b.message:"That preview could not be opened.")}),()=>{S=!1}},[d,x]);const w=()=>{d===null||x===null||T.previewLink(d,x).then(S=>a(S.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:S=>m(Number(S.target.value)),children:h.map(S=>t.jsxs("option",{value:S,children:[":",S]},S))}):null,N?t.jsx("button",{type:"button",className:"ui-btn wb-preview-toggle","data-variant":"ghost","data-size":"sm","aria-pressed":o,onClick:()=>c(S=>!S),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&&t8()?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:CN(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(yI,{text:e.output??"",className:"wb-preview-output"}):null]})]})}const r8=50,a8=9,i8=24,l8=.6,o8=48,c8=/(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,d8=/^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}|$)/,u8=/^id$|(^|[a-z0-9])Id$|_id$/;function Ll(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function Ss(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function bI(...e){for(const n of e)if(Ss(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 kI(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&&c8.test(e)?"currency":"number":r.every(a=>typeof a=="string"&&d8.test(a))?"date":"text"}function h8(e,n){if(!u8.test(e))return!1;const s=n.filter(r=>!Kr(r));return s.length<2?!1:new Set(s.map(r=>String(r))).size===s.length}function Kr(e){return e==null||e===""?!0:Array.isArray(e)?e.length===0:Ss(e)?Object.keys(e).length===0:!1}function EN(e,n){const s=e.filter(Ss);if(s.length===0||s.length/e.length<.8)return null;const r=s.slice(0,r8),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>i8||[...a.values()].reduce((h,f)=>h+f,0)/(a.size*r.length)<l8)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=[],d=[];for(const h of o){const f=r.map(g=>g[h]),m=f.filter(g=>!Kr(g));if(m.length===0||h8(h,f))continue;const p=bI(r[0],n),x=kI(h,f,p);if(r.length>=4&&m.length===f.length&&f.every(g=>Ll(g)&&g===f[0])){d.push({label:Ht(h),value:f[0],type:x,currency:p});continue}if(c.push({key:h,label:Ht(h),type:x,currency:x==="currency"?p:null}),c.length===a8)break}return c.length===0?null:{columns:c,rows:s,constants:d}}function f8(e,n,s){const r=bI(s);return{label:Ht(e),value:n,type:kI(e,[n],r),currency:r}}function NI(e){return typeof e=="string"&&e.length>o8}function m8(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.":Ss(e)&&Object.keys(e).length===0?"This tool returned an empty result.":null}function fv(e){if(typeof e=="string"&&e.trim()!=="")return e;if(Ss(e))for(const n of["message","error","reason","detail","description"]){const s=e[n];if(typeof s=="string"&&s.trim()!=="")return s;if(Ss(s)){const r=fv(s);if(r!=="The call failed with no reason given.")return r}}return"The call failed with no reason given."}function yy(e,n={}){if(n.failed){let f=e;if(typeof e=="string")try{const m=JSON.parse(e.replace(/^tool-error:\s*/,""));Ss(m)&&(f=m)}catch{}return{kind:"error",summary:fv(f),detail:AN(f)}}if(Ss(e)){const f=e.error,m=e.ok;if(typeof f=="string"&&f.trim()!==""||m===!1)return{kind:"error",summary:fv(e),detail:AN(e)}}const s=m8(e);if(s)return{kind:"empty",note:s,stats:[]};if(Array.isArray(e)){const f=EN(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(Ll)?{kind:"list",label:null,items:e,total:e.length,stats:[],notes:[],asides:[]}:{kind:"tree",value:e}}if(!Ss(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=EN(m,e);if(p){(!a||p.rows.length>a.candidate.rows.length)&&(a={key:f,candidate:p});continue}m.length>0&&m.every(Ll)&&(!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=[],d=[];for(const[f,m]of r)if(f!==l){if(NI(m)){c.push(m);continue}if(Ll(m)){if(m==="")continue;o.push(f8(f,m,e));continue}m!==void 0&&d.push({label:Ht(f),value:m})}if(a)return{kind:"table",label:Ht(a.key),columns:a.candidate.columns,rows:a.candidate.rows,total:a.candidate.rows.length,stats:[...o,...a.candidate.constants],notes:c,asides:d};if(i)return{kind:"list",label:Ht(i.key),items:i.items,total:i.items.length,stats:o,notes:c,asides:d};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])=>Ht(m).toLowerCase()).join(", ")} to show.`,stats:o}:r.every(([,f])=>Ll(f)||Ss(f)||Array.isArray(f))?{kind:"record",pairs:o,notes:c,asides:d}:{kind:"tree",value:e}}function AN(e){if(!Ss(e))return null;const n=Object.entries(e).filter(([s])=>s!=="message"&&s!=="error");return n.length===0?null:Object.fromEntries(n)}const nf=25,p8=3,mv=8,SI=6;function pv(e,n=0){if(n>SI||Kr(e)||NI(e))return 0;if(Ll(e))return 1;if(Array.isArray(e)){let s=0;for(const r of e)if(s+=pv(r,n+1),s>=mv)return s;return s}if(Ss(e)){let s=0;for(const r of Object.values(e))if(s+=pv(r,n+1),s>=mv)return s;return s}return 0}function gv(e,n=0){if(n>SI)return!1;if(Array.isArray(e))return e.some(i=>gv(i,n+1));if(!Ss(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=>gv(i,n+1))}function g8(e){if(gv(e))return!0;const n=yy(e);switch(n.kind){case"table":return n.rows.length>0;case"list":return n.items.length>=p8;case"record":case"tree":return pv(e)>=mv;default:return!1}}function _p(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function Em(e){const n=_p(e);if(!n)return null;const s=_p(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:_p(n.input),a=(r==null?void 0:r.command)??s.command;return{command:typeof a=="string"?a:null,input:r,result:s}}function x8({text:e,label:n}){const[s,r]=u.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(x8,{text:n,label:`Copy ${e.toLowerCase()}`})]}),t.jsx("pre",{className:"wb-command-text","aria-label":e,tabIndex:0,children:n})]})}function v8({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!=="")),d=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,d.length>0&&t.jsxs("section",{children:[t.jsx("h4",{children:"File export errors"}),d.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:rs({...c,...a?{input:a}:{}})})]})]})}const $u=2,$N=64;function CI({props:e,bare:n=!1}){const[s,r]=u.useState(!1),a=Em(e.value),i=j8((a==null?void 0:a.result)??e.value),l=u.useMemo(()=>yy(e.value,{failed:e.failed??!1}),[e.value,e.failed]);return t.jsxs("div",{children:[!a&&t.jsx(TN,{files:i}),s?t.jsx("pre",{className:"ui-code",children:rs(e.value)}):a?t.jsx(v8,{value:a,children:i.length>0&&t.jsxs("section",{children:[t.jsx("h4",{children:"Generated files"}),t.jsx(TN,{files:i})]})}):i.length?t.jsxs("details",{className:"wb-aside",children:[t.jsx("summary",{children:"Tool details"}),t.jsx(IN,{shape:l})]}):t.jsx(IN,{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 j8(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 TN({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(w8,{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 w8({file:e}){const[n,s]=u.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 IN({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:fd(e.detail,1)})]})]});case"empty":return t.jsxs("div",{children:[t.jsx(Up,{stats:e.stats}),t.jsx("p",{className:"wb-note",children:e.note})]});case"table":{const n=C8(e.columns,e.rows);return t.jsxs("div",{children:[t.jsx(Up,{stats:e.stats}),t.jsx(Bp,{notes:e.notes}),n?t.jsx(E8,{label:e.label,plan:n,rows:e.rows,total:e.total}):t.jsx(b8,{label:e.label,columns:e.columns,rows:e.rows,total:e.total}),t.jsx(Wp,{asides:e.asides})]})}case"list":return t.jsxs("div",{children:[t.jsx(Up,{stats:e.stats}),t.jsx(Bp,{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(Wp,{asides:e.asides})]});case"record":return t.jsxs("div",{children:[t.jsx(Bp,{notes:e.notes}),t.jsx(y8,{pairs:e.pairs}),t.jsx(Wp,{asides:e.asides})]});default:return t.jsx("div",{className:"wb-tree",children:fd(e.value,0)})}}function Up({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:by(n.value,n.type,n.currency)})]},n.label))})}const RN=200;function Bp({notes:e}){if(e.length===0)return null;const n=e.filter(r=>r.length<=RN),s=e.filter(r=>r.length>RN);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 y8({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:by(n.value,n.type,n.currency)})]},n.label))})}function Wp({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:fd(n.value,1)})]},n.label))})}function b8({label:e,columns:n,rows:s,total:r}){const[a,i]=u.useState(!1),l=r<=nf+5?r:nf,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:AI(c.type)?"num":void 0,children:c.label},c.key))})}),t.jsx("tbody",{children:o.map((c,d)=>t.jsx("tr",{children:n.map(h=>t.jsx(A8,{value:c[h.key],column:h},h.key))},d))})]})}),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 k8=/^(title|name|headline|subject|label|heading)$/i,N8=/^(url|link|href|uri|permalink)$/i;function sf(e){return typeof e=="string"&&/^https?:\/\/[^\s]+$/i.test(e.trim())}function S8(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function EI(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 Tu(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 C8(e,n){if(n.length===0)return null;const s=e.filter(h=>h.type==="text"),r=s.find(h=>N8.test(h.key)&&n.some(f=>sf(f[h.key])))??s.find(h=>{const f=n.map(m=>m[h.key]).filter(m=>!Kr(m));return f.length>0&&f.filter(sf).length/f.length>=.6});if(!r)return null;const a=s.filter(h=>h.key!==r.key),i=a.find(h=>k8.test(h.key))??a.find(h=>Tu(n,h.key)>0);if(!i)return null;const o=[...a.filter(h=>h.key!==i.key)].sort((h,f)=>Tu(n,f.key)-Tu(n,h.key)),c=o[0]&&Tu(n,o[0].key)>40?o[0]:null,d=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:d}}function E8({label:e,plan:n,rows:s,total:r}){const[a,i]=u.useState(!1),l=r<=nf+5?r:nf,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,d)=>{const h=c[n.url],f=sf(h)?h.trim():null,m=typeof c[n.title]=="string"&&c[n.title].trim()!==""?c[n.title]:f?EI(f):"Untitled",p=n.description&&typeof c[n.description]=="string"?c[n.description]:null,x=f?S8(f):null,g=n.meta.map(y=>c[y]).filter(y=>!Kr(y)&&typeof y!="object").map(y=>String(y)).filter(y=>x===null||y.replace(/^www\./,"")!==x);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:[x?t.jsx("span",{className:"wb-record-host",title:f??void 0,children:x}):null,g.map((y,j)=>t.jsx("span",{children:y.length>60?`${y.slice(0,59)}…`:y},j))]}),p?t.jsx("p",{className:"wb-record-desc",children:p.length>280?`${p.slice(0,279)}…`:p}):null]},d)})}),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 A8({value:e,column:n}){if(Kr(e))return t.jsx("td",{className:"wb-cell-soft",children:"—"});if(sf(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:EI(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:rs(e),children:a})}const s=by(e,n.type,n.currency),r=s.length>$N?`${s.slice(0,$N-1)}…`:s;return t.jsx("td",{className:AI(n.type)?"num":"wb-cell-text",...r===s?{}:{title:s},children:r})}function AI(e){return e==="number"||e==="currency"}function by(e,n,s){return e==null?"—":n==="boolean"?e?"yes":"no":kn(e,n==="text"?"text":n,s)}function fd(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,". "]}),fd(i,n+1)]},l)),e.length>50?t.jsxs("div",{className:"wb-tree-key",children:["…and ",e.length-50," more"]}):null]});return n>=$u?t.jsx(PN,{summary:`${e.length} items`,open:n===$u,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:[Ht(a),": "]}),fd(i,n+1)]},a))});return n>=$u?t.jsx(PN,{summary:`${s.length} fields`,open:n===$u,children:r}):r}function PN({summary:e,open:n,children:s}){return t.jsxs("details",{open:n,children:[t.jsx("summary",{className:"wb-tree-key",children:e}),s]})}function $8({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:$I(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(T8,{cell:l},((c=e.columns[o])==null?void 0:c.key)??o)})},i))})]})})]},s.label??r))]})}function T8({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:$I(e.type)?"num":void 0,"data-type":e.type,title:n.length>40?n:void 0,children:n})}function $I(e){return e==="number"||e==="currency"||e==="percent"}const MN={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 Po(e){return(e&&Object.prototype.hasOwnProperty.call(MN,e)?MN[e]:void 0)??"dot"}let dh=null;typeof window<"u"&&window.addEventListener(Xh,()=>{dh=null});function I8(){return dh??(dh=Promise.resolve().then(()=>T.pages()).then(e=>Array.isArray(e==null?void 0:e.pages)?e.pages:[]).catch(()=>(dh=null,[]))),dh}function ky(e,n,s){return s==="settings"?pr(e,n):Hr(e,n)}function R8(e){const[n,s]=u.useState(null),r=e==null?void 0:e.plugin,a=e==null?void 0:e.page;return u.useEffect(()=>{if(!r||!a)return;let i=!1;return I8().then(l=>{const o=l.find(c=>c.plugin===r&&c.id===a);i||s(o?{href:ky(r,a,o.place),label:o.place==="settings"?`Settings → ${o.title}`:o.title}:null)}),()=>{i=!0}},[r,a]),n}function TI({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(P8,{tile:a,...r?{picked:i===s,onPick:()=>r(i)}:{}},`${i}-${a.label}`))})}function P8({tile:e,picked:n,onPick:s}){const r=R8(e.link),a=[e.label,e.value,...e.lines].filter(l=>l!=="").join(", "),i=t.jsxs("div",{className:"wb-tile-body","aria-hidden":"true",children:[t.jsx("span",{className:"wb-tile-icon","data-icon":e.icon??"dot",children:t.jsx(ie,{name:Po(e.icon),size:22})}),e.value!==""?t.jsx("span",{className:"wb-tile-value tnum",children:e.value}):null,t.jsx("span",{className:"wb-tile-label",children:e.label}),e.lines.map((l,o)=>t.jsx("span",{className:"wb-tile-line",children:l},o))]});return s?t.jsx("li",{className:"wb-tile",children:t.jsx("button",{type:"button",className:"ui-card","data-tone":n?"accent":e.tone==="neutral"?void 0:e.tone,"data-selected":n?"true":void 0,"aria-pressed":n===!0,"aria-label":a,onClick:s,children:i})}):t.jsxs("li",{className:"wb-tile",children:[t.jsx("span",{className:"sr-only",children:a}),t.jsxs(Sr,{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 vl=760,Hp=400,sn={top:18,right:18,bottom:36,left:66},M8=5;function O8({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,d=l-c*.08,h=o+c*.08,f=vl-sn.left-sn.right,m=Hp-sn.top-sn.bottom,p=N=>sn.left+(n.length===1?f/2:N/(n.length-1)*f),x=N=>sn.top+m-(N-d)/(h-d)*m,g=qh(l,o,4),y=L8(n.map(N=>N.y),e.mark),j=e.shadeBelow===null?[]:F8(n.map(N=>N.y),e.shadeBelow),v=n.map((N,k)=>`${k===0?"M":"L"}${p(k)},${x(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 ${vl} ${Hp}`,role:"img","aria-label":D8(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:vl-sn.right,y1:x(N),y2:x(N)}),t.jsx("text",{x:sn.left-8,y:x(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:vl-sn.right,y1:x(N.value),y2:x(N.value)}),t.jsxs("text",{x:vl-sn.right,y:x(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:vl-sn.right,y1:sn.top+m,y2:sn.top+m}),t.jsx("path",{className:"wb-chart-series",d:v}),y!==null?t.jsxs("g",{children:[t.jsx("circle",{className:"wb-chart-min",cx:p(y),cy:x(n[y].y),r:4.5}),t.jsx("text",{x:p(y),y:x(n[y].y)+20,textAnchor:"middle",children:w(n[y].y)})]}):null,_8(n.length).map(N=>t.jsx("text",{x:p(N),y:Hp-10,textAnchor:"middle",children:Xx(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,k)=>t.jsxs("li",{className:"wb-chart-event",children:[t.jsxs("span",{children:[t.jsx("span",{className:"wb-chart-event-day",children:Xx(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}-${k}`))})]}):null]})]})}function D8(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 L8(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 F8(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 _8(e,n=M8){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 zs=e=>e,xv={timeseries:zs(O8),table:zs($8),bars:zs(l6),keyvalue:zs(Q5),tiles:zs(TI),document:zs(t5),diff:zs(f6),terminal:zs(e8),image:zs(Y5),preview:zs(s8),envelope:zs(H5),structured:zs(CI)},z8="structured";function U8(e){return(rf(e)?xv[e]:void 0)??xv[z8]}function rf(e){return Object.prototype.hasOwnProperty.call(xv,e)}function B8({renderer:e,props:n,timezone:s,onDecided:r}){const a=U8(e),l=rf(e)?n:{value:n};return t.jsx(a,{props:l,timezone:s,onDecided:r})}function ii(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}const W8=["preferredName","displayName","fullName","name","title","label","subject","username","email"],H8=/^(name|title|label|subject|displayName|display_name|heading)$/i,K8=/^(url|link|href|uri|permalink)$/i,V8=/^(id|uuid|_id)$|(Id|_id)$/;function vv(e){return e===null||["string","number","boolean"].includes(typeof e)}function Ny(e){return W8.find(n=>typeof e[n]=="string"&&e[n].trim()!=="")??null}const G8=6;function II(e){let n=e,s=null,r=[];if(ii(e)){const c=Object.entries(e).filter(([,h])=>Array.isArray(h)),d=Object.entries(e).filter(([,h])=>!Array.isArray(h));if(c.length!==1||!d.every(([,h])=>vv(h)))return null;[s,n]=[Ht(c[0][0]),c[0][1]],r=d.filter(([,h])=>!Kr(h))}if(!Array.isArray(n)||n.length===0||!n.every(ii))return null;const a=n,i=[...new Set(a.flatMap(c=>Object.keys(c)))];if(i.length>G8||i.some(c=>K8.test(c)))return null;const l=i.find(c=>H8.test(c)&&a.filter(d=>typeof d[c]=="string").length>=a.length*.8);if(!l)return null;const o=i.filter(c=>c!==l&&!V8.test(c)).filter(c=>a.some(d=>vv(d[c])&&!Kr(d[c]))).sort((c,d)=>ON(a,d)-ON(a,c)).slice(0,2);return{label:s,rows:a,name:l,facts:o,extras:r}}function ON(e,n){return e.filter(s=>!Kr(s[n])).length}function q8(e){return ii(e)&&Ny(e)!==null&&Object.keys(e).length>=3}const Y8=60;function Q8(e){if(!ii(e))return!1;const n=Object.values(e);return n.length>=2&&n.every(s=>vv(s)&&(typeof s!="string"||s.length<=Y8))}const J8=[{name:"items",matches:e=>II(e)!==null},{name:"profile",matches:q8},{name:"settings",matches:Q8},{name:"fields",matches:e=>ii(e)&&Object.keys(e).length>0}];function X8(e){var n;return((n=J8.find(s=>s.matches(e)))==null?void 0:n.name)??"other"}const RI=8,Z8=32,eW=/^\d{4}-\d{2}-\d{2}$/,tW=/^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?$/,nW=/^[a-z]+([_-][a-z]+)*$/,sW=/(name|title|label|email|subject|text|note|message|description|summary|path|file)$/i;function PI(e,n){if(Kr(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 eW.test(s)?{kind:"day",value:s}:tW.test(s)&&!Number.isNaN(Date.parse(s))?{kind:"moment",value:s}:/^https?:\/\/\S+$/i.test(s)?{kind:"link",value:s}:s.length<=24&&nW.test(s)&&!sW.test(e)?{kind:"enum",value:s}:{kind:"text",value:n}}return Array.isArray(n)?n.length<=RI&&n.every(s=>typeof s=="string"&&s.length<=Z8)?{kind:"chips",values:n}:{kind:"rows",values:n}:ii(n)?{kind:"group",value:n}:{kind:"text",value:String(n)}}function rW({value:e,title:n,tool:s,face:r,timezone:a}){const[i,l]=u.useState(!1),o=Em(e)||aW(e)?"other":X8(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(Qn,{label:`More for ${n}`,items:[{label:i?"Show readable":"Raw JSON",onSelect:()=>l(c=>!c)}]})]}),i?t.jsx("pre",{className:"ui-code",children:rs(e)}):t.jsx(iW,{view:o,value:e,timezone:a})]})}function aW(e){return ii(e)&&Array.isArray(e.artifacts)}function iW({view:e,value:n,timezone:s}){switch(e){case"items":return t.jsx(oW,{shape:II(n),timezone:s});case"profile":return t.jsx(lW,{value:n,timezone:s});case"settings":return t.jsx(cW,{value:n,timezone:s});case"fields":return t.jsx(Sy,{value:n,timezone:s,depth:0});default:return t.jsx(CI,{props:{value:n},bare:!0})}}function lW({value:e,timezone:n}){const s=Ny(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:Ht(s)}),t.jsx("span",{className:"wb-result-lead-v",children:String(e[s])})]}),t.jsx(Sy,{value:r,timezone:n,depth:0})]})}function oW({shape:e,timezone:n}){const[s,r]=u.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:[Ht(l)," ",t.jsx(oo,{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:Ht(c),children:t.jsx(oo,{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 cW({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:Ht(s)}),t.jsx("dd",{children:t.jsx(oo,{field:s,value:r,timezone:n})})]},s))})}const dW=3;function Sy({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=PI(a,i);if(l.kind==="group"){const o=Object.keys(l.value).length;return t.jsx("div",{className:"wb-result-group",children:t.jsx(Kt,{summary:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"wb-result-group-k",children:Ht(a)})," ",t.jsxs("span",{className:"wb-result-group-n",children:[o," ",o===1?"field":"fields"]})]}),open:s===0&&o<=4,children:s+1>=dW?t.jsx("pre",{className:"ui-code",children:rs(l.value)}):t.jsx(Sy,{value:l.value,timezone:n,depth:s+1})})},a)}return t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:Ht(a)}),t.jsx("dd",{children:t.jsx(oo,{field:a,value:i,timezone:n})})]},a)})})}function oo({field:e,value:n,timezone:s}){const r=PI(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(Ce,{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)?fn(r.value):String(Math.round(r.value*100)/100)});case"day":return t.jsx("span",{children:Pd(r.value,{year:!0})});case"moment":return t.jsx("time",{dateTime:r.value,children:ft(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(Ce,{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(Ce,{children:a},`${a}-${i}`))});case"rows":return t.jsx(uW,{values:r.values,timezone:s});case"group":return t.jsxs("span",{className:"wb-result-empty",children:[Object.keys(r.value).length," fields"]})}}function uW({values:e,timezone:n}){const[s,r]=u.useState(!1),a=s?e:e.slice(0,RI);return t.jsxs("span",{className:"wb-result-compact",children:[t.jsx("ul",{children:a.map((i,l)=>t.jsx("li",{children:hW(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 hW(e,n){if(ii(e)){const s=Ny(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:Ht(a),children:[" ",t.jsx(oo,{field:a,value:i,timezone:n})]},a))]})}return t.jsx(oo,{field:"",value:e,timezone:n})}function fW({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(Kp,{children:"Opens by default"}):null,t.jsx(Kp,{children:e.source==="example"?"Shipped with buddi":"Yours"}),e.roles.map(s=>t.jsx(Kp,{title:`A surface command that asks for "${s}" lands on this agent.`,children:Ht(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(Zo,{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(MI,{}),"Exact action"]})]})]})}),t.jsx(Zo,{title:"What it can do",note:mW(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(pW,{family:s},s.family))}),t.jsx(Zo,{title:"What it runs on",children:t.jsxs("dl",{className:"wb-prof-kv",children:[t.jsx(ec,{label:"Provider",children:e.engine.provider}),t.jsx(ec,{label:"Model",children:t.jsx("span",{className:"mono",children:e.engine.model})}),t.jsxs(ec,{label:"Credential",children:[e.engine.credentialKind," from"," ",t.jsx("span",{className:"mono",children:e.engine.credentialEnv})]}),t.jsxs(ec,{label:"Turn budget",children:[e.engine.maxTurns," ",e.engine.maxTurns===1?"turn":"turns"," per message"]}),t.jsx(ec,{label:"Language",children:wW(e.engine.language)})]})}),e.skills.length>0?t.jsx(Zo,{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(Zo,{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 mW(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 pW({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:Ht(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(gW,{tool:s},s.name))})]})}function gW({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:jW(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(MI,{}),"Needs your approval"]}):t.jsx("span",{className:"wb-prof-auto",title:vW(e.tier),children:xW(e.tier)})]})}function xW(e){return e==="auto"?"Runs on its own":e==="gated"?"Needs your approval":"Not runnable here"}function vW(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 jW(e){const n=e.split(".");return(n[n.length-1]??e).replace(/_/g," ")}function wW(e){return e==="mirror"?"Mirrors whichever language you write in":e==="en"?"Always English":e==="fr"?"Always French":e}function Zo({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 ec({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 Kp({children:e,title:n}){return t.jsx("span",{className:"wb-prof-tag",title:n,children:e})}function MI(){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 DN=16e3,yW=10*6e4,bW="The microphone is blocked for this page: allow it in the browser’s site settings to talk.",OI="This browser cannot record here: talking needs a microphone and a secure page (https or localhost).";function kW(){const e=window;return e.AudioContext??e.webkitAudioContext}function NW(e){const n=e&&typeof e=="object"&&"name"in e?String(e.name):"";return n==="NotAllowedError"||n==="SecurityError"||n==="PermissionDeniedError"?bW:n==="NotFoundError"||n==="DevicesNotFoundError"?"No microphone was found on this computer.":n==="NotReadableError"?"The microphone is in use by another app.":OI}async function SW(e){var c;const n=kW();if(!((c=navigator.mediaDevices)!=null&&c.getUserMedia)||!n)throw Object.assign(new Error(OI),{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=d=>{const h=d.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(d=>d.stop()),r.close().catch(()=>{})};return{async stop(){const d=r.sampleRate;return o(),AW(EW(CW(l),d,DN),DN)},cancel:o}}function CW(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 EW(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 d=l;d<o;d++)c+=e[d];a[i]=o>l?c/(o-l):0}return a}function AW(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 jv="buddi.readAloud";function DI(){try{return window.localStorage.getItem(jv)==="on"}catch{return!1}}function LI(e){try{e?window.localStorage.setItem(jv,"on"):window.localStorage.removeItem(jv)}catch{}}let Pr=null,Sc=null,md=0,wv=null;const yv=new Set;function af(e){wv!==e&&(wv=e,yv.forEach(n=>n()))}function $W(){return wv}function TW(e){return yv.add(e),()=>yv.delete(e)}function FI(e){return Mo(),af(e),md}function LN(e){return e===md}function Mo(){md++,Pr&&(Pr.pause(),Pr.removeAttribute("src")),Sc&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(Sc),Sc=null,af(null)}async function IW(e,n,s=null){var a;const r=FI(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!==md)return;Pr||(Pr=new Audio,(a=Pr.addEventListener)==null||a.call(Pr,"ended",()=>af(null))),Sc=URL.createObjectURL(l),Pr.src=Sc,await Pr.play()}catch(i){throw r===md&&af(null),i}}const RW=new Set(["audio/ogg","audio/mpeg","audio/mp4","audio/wav","audio/x-wav","audio/webm"]);function Cy(e){return RW.has(e.toLowerCase().split(";")[0].trim())}function Cc(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 _I(e,n){const s=u.useRef(null),r=u.useRef(null),[a,i]=u.useState(!1),[l,o]=u.useState(!1),[c,d]=u.useState(!1),[h,f]=u.useState(0),[m,p]=u.useState(null);return u.useEffect(()=>()=>{var y;(y=s.current)==null||y.pause(),r.current&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(r.current)},[]),{playing:a,loading:l,failed:c,position:h,duration:m,toggle:async()=>{const y=s.current;if(y){if(a){y.pause();return}Mo(),d(!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})),y.src=r.current}await y.play()}catch{d(!0)}finally{o(!1)}}},bind:{ref:s,preload:"none",onPlay:()=>i(!0),onPause:()=>i(!1),onEnded:()=>{i(!1),f(0)},onTimeUpdate:y=>f(y.currentTarget.currentTime),onLoadedMetadata:y=>p(Number.isFinite(y.currentTarget.duration)?y.currentTarget.duration:null),onDurationChange:y=>p(Number.isFinite(y.currentTarget.duration)?y.currentTarget.duration:null)}}}function Am({artifactId:e,name:n,mime:s,sizeBytes:r}){const{playing:a,loading:i,failed:l,position:o,duration:c,toggle:d,bind:h}=_I(e,s),f=l?"Could not play. Download it instead.":`${Cc(o)} / ${Cc(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 d(),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&&vs(r)?` · ${vs(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 Vp=1e5,Gp=200,qp=30;function zI({artifactId:e,filename:n,mime:s,family:r,available:a=!0}){const[i,l]=u.useState(!1);return a?r==="image"&&!i?t.jsx("figure",{className:"file-preview file-preview-image",children:t.jsx("img",{src:vr(e),alt:n??"Image",onError:()=>l(!0)})}):r==="audio"&&Cy(s)?t.jsx("div",{className:"file-preview file-preview-audio",children:t.jsx(Am,{artifactId:e,name:n??"Audio",mime:s})}):r==="pdf"?t.jsx("div",{className:"file-preview file-preview-pdf",children:t.jsx("object",{data:vr(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(PW,{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 PW({artifactId:e,filename:n,mime:s,family:r}){const[a,i]=u.useState("loading");if(u.useEffect(()=>{let o=!1;return i("loading"),fetch(vr(e),{credentials:"same-origin"}).then(async c=>{if(!c.ok)throw new Error(String(c.status));const d=await c.text();o||i({text:d.slice(0,Vp),truncated:c.headers.get("X-Preview-Truncated")==="1"||d.length>Vp})}).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(OW,{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 ",Vp.toLocaleString()," characters. The download has the whole file."]}):null]})}function MW(e,n,s,r){const a=[];let i=[],l="",o=!1,c=!1,d=!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){d=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:d,truncatedCols:c}}function OW({text:e,delimiter:n}){const s=u.useMemo(()=>MW(e,n,Gp+1,qp),[e,n]),[r,...a]=s.rows;if(!r)return t.jsx("p",{className:"muted",children:"The file is empty."});const i=Math.min(qp,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,Gp).map((o,c)=>t.jsx("tr",{children:l.map(d=>t.jsx("td",{children:o[d]??""},d))},c))})]}),s.truncatedRows||s.truncatedCols?t.jsxs("p",{className:"muted",children:["Showing the first ",Gp," rows",s.truncatedCols?` and ${qp} columns`:"",". The download has the whole file."]}):null]})}function DW(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 LW(e,n){return`/api/artifacts/${encodeURIComponent(e)}/export/${n}`}function FW(e,n){return`${(e??"document").replace(/\.[a-z0-9]{1,8}$/i,"")||"document"}.${n}`}function FN(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 UI({artifactId:e,filename:n,mime:s,accent:r=!0}){const a=n??"download",i=DW(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),d=h=>({label:h.label,hint:h.hint,onSelect:()=>h.asWritten?FN(ai(e),a):FN(LW(e,h.format),FW(n,h.format))});return t.jsx(Qn,{label:`Download ${a}`,note:"Download as",items:[...o.map(d),"separator",...c.map(d)],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 _W({attachment:e}){const n=wy(e.mime,e.filename);return t.jsxs("div",{className:"wb-artifact","data-family":n,"data-testid":"artifact-view",children:[t.jsx(zI,{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:[zi[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:vs(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(UI,{artifactId:e.artifactId,filename:e.filename,mime:e.mime})})]})}const _N=80,zW=["query","path","url","dir"],UW=["message","task"];function Ey(e,n){const s=BW(n);if(!s)return null;const r=jl(s.command);if(r!==null){const l=jl(s.name);return Iu(l===null?r:`${l}: ${r}`)}for(const l of zW){const o=jl(s[l]);if(o!==null)return Iu(o)}const a=jl(s.action);if(a!==null){const l=UW.map(o=>jl(s[o])).find(o=>o!==null)??null;return Iu(l===null?a:`${a} · ${l}`)}const i=Object.values(s).filter(l=>typeof l=="string");return i.length===1?Iu(jl(i[0])):null}function jl(e){if(typeof e!="string")return null;const n=e.replace(/\s+/g," ").trim();return n===""?null:n}function Iu(e){return e===null?null:e.length>_N?`${e.slice(0,_N-1)}…`:e}function BW(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const BI="owner.notify",aa=e=>typeof e=="string"&&e.trim()!==""?e:null;function WW(e){const n=e!==null&&typeof e=="object"?e:{};return{title:aa(n.title)??"(no title)",text:aa(n.text),urgency:aa(n.urgency)??"now",key:aa(n.key),link:aa(n.link)}}function WI(e){if(e===null||typeof e!="object")return aa(e);const n=e;return aa(n.delivered)??aa(n.message)??aa(n.error)}function HW(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 KW=/^[a-z0-9](?:[a-z0-9._-]{0,94}[a-z0-9])?$/,VW=/^[a-z][a-z0-9_-]{0,63}$/;function Kd(e,n,s=64){return!VW.test(e)||typeof n!="string"||!KW.test(n)||n.includes("..")?null:`/api/plugin-assets/${e}/${n}?size=${s}`}function HI(e){return typeof e=="string"&&/^\/api\/plugin-assets\/[a-z][a-z0-9_-]{0,63}\/[a-z0-9._-]+(\?size=(64|128))?$/.test(e)}function GW(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 Oo({src:e,label:n,className:s}){const[r,a]=u.useState(!1),i=e!==null&&HI(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)}):GW(n)})}const uh="news",qW="edition";function KI(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 Bt=e=>typeof e=="string"?e:"",YW=e=>/^https?:\/\/[^\s]+$/i.test(e),zN=/^[a-z][a-z0-9_]*\.[a-z][a-z0-9_]*$/,lf=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null;function UN(e){const n=lf(e);if(!n)return null;const s={};for(const[r,a]of Object.entries(n)){const i=lf(a);if(!i||!("const"in i))return null;s[r]=i.const}return s}function QW(e){return(Array.isArray(e)?e:[]).flatMap(n=>{const s=lf(n);if(!s)return[];const r=Bt(s.label).trim(),a=Bt(s.tool),i=UN(s.args??{});if(r===""||!zN.test(a)||!i)return[];const l=lf(s.undo),o=l?UN(l.args??{}):null,c=l&&zN.test(Bt(l.tool))&&o?{tool:Bt(l.tool),label:Bt(l.label).trim()||"Undo",args:o}:null,d=Bt(s.hint).trim(),h=Bt(s.group).trim(),f=Bt(s.confirm).trim();return[{label:r,tool:a,args:i,...d?{hint:d}:{},...h?{group:h}:{},...f?{confirm:f}:{},done:Bt(s.done).trim()||"Done.",...c?{undo:c}:{}}]}).slice(0,12)}function JW(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,d=Bt(c.title).trim();if(d==="")return[];const h=c.link!==null&&typeof c.link=="object"?c.link:null,f=h?Bt(h.url):"",m=c.mark==="update"||c.mark==="opinion"?c.mark:void 0,p=Bt(c.topicName).trim(),x=QW(c.actions);return[{...m?{mark:m,markLabel:Bt(c.markLabel)||void 0}:{},title:d,lead:Bt(c.lead),outlet:Bt(c.outlet),more:typeof c.more=="number"&&Number.isFinite(c.more)&&c.more>0?Math.floor(c.more):0,...YW(f)?{link:{url:f,label:Bt(h.label)||f}}:{},logos:(Array.isArray(c.logos)?c.logos:[]).flatMap(g=>{if(g===null||typeof g!="object")return[];const y=Bt(g.name),j=Bt(g.logo);return y?[{name:y,...j?{logo:j}:{}}]:[]}),...p?{topicName:p}:{},...x.length>0?{actions:x}:{}}]});return l.length>0?[{topic:Bt(i.topic),stories:l}]:[]});if(r.length===0)return null;const a=Bt(s.next);return{id:Bt(s.id),name:Bt(s.name)||"Edition",when:Bt(s.when),lede:Bt(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 XW(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 ZW({s:e}){const[n,s]=u.useState(null),r=e.logos[0]??{name:e.outlet||e.title},a=e.outlet||r.name,[i,l]=u.useState(null),o=e.actions??[],c=async f=>{try{const m=await T.pageAct(uh,{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."})}},d=async f=>{try{await T.pageAct(uh,{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 d(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(Qn,{label:`Ways out for ${e.title}`,items:XW(o,f=>f.confirm?l(f):void c(f)),sheet:{title:e.title,sub:h},stacked:!0})}):null,i?t.jsx(zt,{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(Oo,{src:r.logo?Kd(uh,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 BN=Array.from({length:64},(e,n)=>30+Math.round(Math.abs(Math.sin(n*1.7)*Math.cos(n*.4))*70));function eH({audio:e}){const{playing:n,loading:s,failed:r,position:a,duration:i,toggle:l,bind:o}=_I(e.fileId,e.mime),c=i?Math.min(1,a/i):0,d=r?"Could not play":s?"Loading…":i===null?"Listen":n||a>0?`${Cc(a)} / ${Cc(i)}`:Cc(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:BN.map((h,f)=>t.jsx("i",{style:{"--h":`${h}%`},"data-on":(n||a>0)&&f<Math.round(c*BN.length)?"true":void 0},f))}),t.jsx("span",{className:"ed-dur",children:d}),t.jsx("audio",{...o})]})}function tH({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(ZW,{s:i},l))})]},a)),t.jsx("p",{className:"ed-foot",children:s.join(" ")})]})}function nH({editionId:e,text:n,audio:s,link:r}){const[a,i]=u.useState(void 0),[l,o]=u.useState(!1);u.useEffect(()=>{let d=!0;return i(void 0),T.pageQuery(uh,qW,{id:e}).then(h=>{d&&i(JW(h.data))}).catch(()=>{d&&i(null)}),()=>{d=!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(tH,{edition:a,audio:s?t.jsx(eH,{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(Am,{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(st,{className:"wb-report-link",size:"sm",href:r.route,children:r.label})]})]})}const sH="mission.report",wl=e=>typeof e=="string"&&e.trim()!==""?e.trim():null,rH=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function aH(e,n){const s=e!==null&&typeof e=="object"?e:{},r=n!==null&&typeof n=="object"?n:{},a=wl(r.link),i=r.audio!==null&&typeof r.audio=="object"?r.audio:null,l=i?wl(i.fileId):null,o=i?wl(i.mime):null;return{text:wl(s.text),link:a&&a.startsWith("#/")?{route:a,label:wl(r.linkLabel)??"Open"}:null,audio:l&&rH.test(l)&&o&&Cy(o)?{fileId:l,mime:o,filename:i?wl(i.filename):null,sizeBytes:i&&typeof i.sizeBytes=="number"?i.sizeBytes:null}:null}}function iH(e){return!!(e.text&&e.link&&KI(e.link.route))}function WN({view:e}){var a;if(!e.text&&!e.audio)return null;const n=e.audio?t.jsx(Am,{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(xr,{text:e.text})}):null,r=KI((a=e.link)==null?void 0:a.route);return r&&e.link&&e.text?t.jsx(nH,{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 li="agent.delegate";function lH(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 oH(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",HN="canvas.clear",KN=12;function cH(e){return`sources:${e}`}function dH(e){return e.role==="user"&&(e.blocks??[]).some(n=>n.type==="text"&&n.text.trim()!=="")}function ql(e){return`${e.plugin}/${e.name}`}function uH(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;const n=e.diff;return typeof n=="string"&&n.trim()!==""}function hH({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=cI(o,of(l.output)).props;c.target===null&&c.awaiting!==null&&a.push({...c.awaiting,at:i.at??null})}return a}function VI({messages:e,descriptors:n,awaiting:s,folded:r,served:a,gathered:i,quiet:l,titles:o}){var g;const c=y=>YI(y,o),d=new Map(n.map(y=>[y.tool,y])),h=new Map;let f=[],m=0,p=null;const x=y=>{p||(p={id:cH(y.id),tool:y.tool,title:"Sources",renderer:"sources",source:"sources",props:{entries:[]},at:y.at,substantial:!1,count:0},f.push(p));const j=p.props,v=j.entries.some(N=>N.id===y.id)?j.entries.map(N=>N.id===y.id?{...y,input:y.input??N.input}:N):[...j.entries,y],w=[...new Set(v.map(N=>N.tool))];p.props={entries:v},p.tool=w.join(" · "),p.count=v.length,p.substantial=v.some(N=>N.ok===!0),p.tone=v.every(N=>N.ok===!1)?"critical":void 0};for(const y of e){dH(y)&&(p=null);for(const j of y.blocks??[]){if(j.type==="tool_use"){if(h.set(j.id,{name:j.name,input:j.input,at:y.at??null}),i!=null&&i.has(j.name)){x({id:j.id,tool:j.name,input:j.input,output:null,ok:null,at:y.at??null});continue}if(j.name===bv){const A=mH(j.id,j.input,y.at??null);A&&f.push(A)}if(j.name===HN&&(f=[],p=null),j.name===li){const A=lH(j.input);A&&f.push({id:j.id,tool:li,title:"Delegation",renderer:"delegate",props:{...A,result:null},at:y.at??null,source:"delegate",substantial:!0})}continue}if(j.type!=="tool_result"||j.name===bv||j.name===HN)continue;const v=h.get(j.toolUseId),w=y.at??(v==null?void 0:v.at)??null,N=j.name||(v==null?void 0:v.name)||"tool",k=f.find(A=>A.source==="delegate"&&A.id===j.toolUseId);if(k&&((g=j.delegation)==null?void 0:g.state)==="waiting"){k.props={...k.props,result:null,waiting:{approvalId:j.delegation.approvalId}},j.delegation.approvalId&&(k.tone="warning");continue}if(k){k.props={...k.props,result:{ok:j.ok,text:oH(j.ok?j.output:j.error??j.output),...j.ok&&tf(j.output).length>0?{files:tf(j.output)}:{}}},j.ok||(k.tone="critical");continue}const S=j.approval?Nv(j):(s==null?void 0:s.get(j.toolUseId))??Nv(j);if(S){f.push({id:j.toolUseId,tool:N,title:"Approval",renderer:"envelope",props:{approvalId:S},at:w,tone:"warning",source:"approval",substantial:!0});continue}if(r!=null&&r.has(N)||l!=null&&l.has(N)&&j.ok!==!1)continue;if(i!=null&&i.has(N)){x({id:j.toolUseId,tool:N,input:(v==null?void 0:v.input)??null,output:of(j.output)??null,ok:j.ok!==!1,...j.error===void 0?{}:{error:j.error},at:w});continue}if(N===BI){f.push({id:j.toolUseId,tool:N,title:"Message to you",renderer:"notify",props:{input:(v==null?void 0:v.input)??null,output:j.output??null,ok:j.ok!==!1},at:w,tone:j.ok===!1?"critical":void 0,source:"notify",substantial:!1});continue}const b=of(j.output);if(j.ok===!1){f.push({id:j.toolUseId,tool:N,title:c(N),renderer:"structured",props:{value:j.error??b??null,failed:!0},at:w,tone:"critical",source:"fallback",substantial:!1});continue}uH(b)&&(m+=1);const C=d.get(N);if(C){const A=cI(C,b),{renderer:I}=A;let{props:M}=A;if(I==="preview"){const O=M,R=O.target??(O.awaiting&&(a!=null&&a.has(ql(O.awaiting)))?O.awaiting:null);if(R===null)continue;M={...O,target:R,awaiting:null};const _=ql(R);f=f.filter(z=>!(z.source==="descriptor"&&z.renderer==="preview"&&z.props.target!==null&&ql(z.props.target)===_))}f.push({id:j.toolUseId,tool:N,title:C.title??c(N),renderer:I,props:M,at:w,source:"descriptor",substantial:kv(I,M)});continue}const $={value:Em(b)?{input:v==null?void 0:v.input,output:b}:b};pH("structured",$)&&f.push({id:j.toolUseId,tool:N,title:c(N),renderer:"structured",props:$,at:w,source:"fallback",substantial:kv("structured",$)})}}for(const y of f)y.source==="descriptor"&&y.renderer==="preview"&&(y.props={...y.props,changes:m});return fH(f)}const VN="forAgent";function of(e){if(e===null||typeof e!="object"||Array.isArray(e)||!(VN in e))return e;const{[VN]:n,...s}=e;return s}function fH(e){if(e.length<=KN)return e;const n=e.length-KN;return[...e.slice(0,n).filter(r=>r.source==="approval"),...e.slice(n)]}function mH(e,n,s){if(n===null||typeof n!="object")return null;const{renderer:r,title:a,data:i}=n,l=typeof r=="string"&&rf(r)?r:"structured";return{id:e,tool:bv,title:typeof a=="string"&&a.trim()!==""?a:"Shown",renderer:l,props:l==="structured"&&!rf(String(r))?{value:i}:i,at:s,substantial:!0,source:"canvas"}}function pH(e,n){const s=n??{};return!!(s.failed===!0||kv(e,n)||yy(s.value).kind==="error")}function kv(e,n){const s=n??{};switch(e){case"timeseries":return tc(s.points)>0;case"bars":return tc(s.bars)>0;case"keyvalue":return tc(s.pairs)>0;case"tiles":return s.notice!==!0&&tc(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=>tc(a.rows)>0);default:return Em(s.value)?!0:s.failed===!0?!1:g8(s.value)}}function tc(e){return Array.isArray(e)?e.length:0}function Nv(e){if(e.approval)return e.approval.state==="pending"?e.approval.id:null;for(const n of[e.error,e.output]){const s=qI(n,0);if(s)return s}return null}function gH(e,n,s={}){var c,d,h;const r=f=>YI(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:of(l.output)??null},at:null,source:"fallback",substantial:!1};const o=(d=s.redactInputOf)!=null&&d.has(i.name)?GI(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 xH=new Set(["value","text","password","secret","code"]);function GI(e){if(e===null||typeof e!="object"||Array.isArray(e))return e;const n={};for(const[s,r]of Object.entries(e))n[s]=xH.has(s)&&typeof r=="string"?"— withheld —":GI(r);return n}function qI(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=qI(i,n+1);if(l)return l}return null}function Xi(e){const n=e.split(".");return n.length===1?Ht(e):n.map(s=>Ht(s)).join(" · ")}function YI(e,n){return(n==null?void 0:n.get(e))??Xi(e)}function GN(e,n){return e.find(s=>s.source==="sources"&&s.props.entries.some(r=>r.id===n))??null}function Vd({name:e,mime:n,sizeBytes:s,thumbnail:r,state:a,error:i,onOpen:l,onRemove:o,size:c="md",detail:d}){const h=wy(n,e),f=d??[zi[h],vs(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(Ay,{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 Ay({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 vH(e,n,s){const r=YN(e),a=YN(n==null?void 0:n.input),i=Si(r==null?void 0:r.name)??kH(Si(r==null?void 0:r.handle))??Si(r==null?void 0:r.agent)??Si(a==null?void 0:a.agent),l=typeof e=="string"?e.trim()||null:Si(r==null?void 0:r.text)??Si(r==null?void 0:r.note),o=qN(r==null?void 0:r.durationMs)??qN(r==null?void 0:r.elapsedMs),c=n!=null&&n.at?Date.parse(n.at):NaN,d=s?Date.parse(s):NaN,h=Number.isFinite(c)&&Number.isFinite(d)&&d>=c?d-c:null;return{who:i,question:Si(a==null?void 0:a.task),answer:l,files:tf(e),durationMs:o??h}}function jH(e,n){var r;let s=null;for(const a of e)for(const i of a.blocks??[])i.type==="tool_result"&&i.name===li&&((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 wH({block:e,messages:n,answeredAt:s}){const r=vH(e.output,jH(n,e.actionId),s),a=[r.who?`Asked ${r.who}`:null,r.durationMs===null?null:`took ${yH(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(xr,{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(Vd,{name:i.filename??"Untitled file",mime:i.mime,sizeBytes:i.sizeBytes,thumbnail:jy(i.mime)?vr(i.artifactId):null,size:"sm"})},i.artifactId))}):null,t.jsx(Kt,{summary:"Raw JSON",children:t.jsx("pre",{className:"wb-approval-output mono",children:bH(e.output)})})]})}function yH(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 bH(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function kH(e){return e===null?null:`@${e.replace(/^@/,"")}`}function Si(e){return typeof e=="string"&&e.trim()!==""?e:null}function qN(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function YN(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const NH=1e3;function SH({messageId:e,text:n,onReadAloud:s}){const[r,a]=u.useState(!1),i=u.useRef(null),l=u.useSyncExternalStore(TW,$W)===e;u.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),NH)},()=>{})};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?Mo():s(e,n),children:t.jsx(ie,{name:l?"stop":"play",size:14})}):null]})}function CH(e){const n=EH(e);if(!n)return null;const s=Yp(n.diff);if(s!==null)return{kind:"diff",diff:s};const r=Yp(n.command),a=Yp(n.plain),i=Qp(n.exitCode);return r!==null&&(a!==null||i!==null||Qp(n.pid)!==null)?{kind:"command",command:r,output:a,exitCode:i,elapsedMs:Qp(n.elapsedMs)}:null}function Yp(e){return typeof e=="string"&&e.trim()!==""?e:null}function Qp(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function EH(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const QN="offer:",QI="owner:interjection";function AH(e){return e===QI}function $H(e){if(typeof e!="string"||!e.startsWith(QN))return null;const n=e.slice(QN.length).trim();return n===""?null:n}const JN="brief:";function TH(e){if(typeof e!="string"||!e.startsWith(JN))return null;const n=e.slice(JN.length).trim();return n===""?null:n}function $y({messages:e,live:n,now:s,onOpen:r,working:a=!1,partial:i=null,agents:l,agentId:o,speakers:c,coordinatorId:d,workingAs:h,onOpenFile:f,onReadAloud:m,children:p,agentName:x,emptyHint:g,empty:y,plain:j=!1,workingLine:v,runs:w,onContinue:N}){var J;const k=u.useRef(null);u.useEffect(()=>{var H;(H=k.current)==null||H.scrollIntoView({block:"end"})},[e.length,n.length,a,i==null?void 0:i.text.length,i==null?void 0:i.thinking.length,!!p]);const S=i&&!i.settled&&(i.text!==""||i.thinking!==""),b=e.filter(H=>(H.blocks??[]).some(HH)).map(JI),C=zH(b,w??[]),$=BH(b,w??[]),A=c??l??[],I=H=>(o&&!c?A.find(X=>X.id===o):void 0)??A.find(X=>X.name===H)??null,M=o?A.find(H=>H.id===o)??null:null,O=a||n.length>0,R=O||!!S,_=!!S&&i.text!=="",z=O&&!_,U=b.at(-1),P=(U==null?void 0:U.role)!=="assistant"||!!h,W=h??x??"Assistant",L=b.filter((H,X)=>{var G;return X===0||(c?(((G=b[X-1])==null?void 0:G.speaker)??null)!==(H.speaker??null):b[X-1].role!==H.role)}),Q=R&&!P?((J=L.at(-1))==null?void 0:J.id)??null:null,F=(w??[]).reduce((H,X)=>H===null||(X.startedAt??"")>(H.startedAt??"")?X:H,null),ae=(w??[]).some(H=>H.finishedAt===null),V=N&&!R&&!ae&&U&&(F==null?void 0:F.stopped)==="max_turns"&&C.get(U.id)===F?U.id:null;return t.jsx(iI.Provider,{value:l??c??[],children:t.jsxs("div",{className:"wb-messages","data-testid":"messages",children:[b.length===0&&n.length===0?y??t.jsx("p",{className:"wb-chat-empty",children:g}):null,b.map((H,X)=>{const G=H.speaker??null,ce=c?G==="owner"||G===null&&H.role==="user":H.role==="user",xe=c&&G==="room",De=c&&G&&G!=="owner"&&G!=="room"?c.find(he=>he.id===G)??null:null,B=b[X-1],ne=X===0||(c?((B==null?void 0:B.speaker)??null)!==G:B.role!==H.role);if(xe)return t.jsx("div",{className:"wb-msg wb-msg-room","data-role":"room",children:(H.blocks??[]).filter(he=>he.type==="text").map((he,ke)=>t.jsx("span",{children:he.text},ke))},H.id);const Z=(H.blocks??[]).filter(he=>he.type==="approval_result");if(Z.length>0)return t.jsx("div",{className:"wb-msg","data-role":"assistant","data-testid":"approval-result",children:Z.map((he,ke)=>t.jsx(KH,{block:he,messages:e,at:H.at||null},ke))},H.id);const ve=H.role==="user"&&AH(G),$e=H.role==="user"?TH(G):null;if($e)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:$e})},H.id);const Se=H.role==="user"?$H(G):null;if(Se){const he=(H.blocks??[]).filter(ke=>ke.type==="text").map(ke=>ke.text).join(`
105
+ `);return t.jsx("div",{className:"wb-msg","data-role":"user","data-testid":"offer-turn",children:t.jsx("div",{className:"wb-bubble wb-bubble-offer",title:he,children:Se})},H.id)}const me=c&&De&&H.role==="user"?DH(H):null;if(me){const he=b.slice(X+1).find(Be=>Be.role==="assistant"&&Be.speaker&&Be.speaker!==De.id),ke=he!=null&&he.speaker?c.find(Be=>Be.id===he.speaker):void 0;return t.jsxs("details",{className:"wb-msg wb-msg-room wb-msg-ask","data-role":"room",children:[t.jsxs("summary",{children:[De.name," asked ",(ke==null?void 0:ke.name)??"a member",me.request?`: ${me.request.length>120?`${me.request.slice(0,119)}…`:me.request}`:""]}),me.request?t.jsx("p",{children:me.request}):null]},H.id)}const Ee=C.get(H.id)??null,Pe=_H(H,e),Me=!ce&&!ve&&!j?FH(H):"";return t.jsxs("div",{className:"wb-msg","data-role":ce||ve?"user":"assistant",children:[ve?t.jsx("div",{className:"wb-msg-added","data-testid":"added-while-working",children:"added while working"}):null,ne&&!ce&&!ve?t.jsx(XN,{name:De?De.name:c&&G&&G!=="owner"&&G!=="room"?G:x??"Assistant",face:De??M??I(x),moving:z&&Q===H.id,children:De&&d===De.id?t.jsx("span",{className:"wb-msg-role",children:"coordinator"}):null}):null,Pe.length>0?t.jsx("div",{className:"wb-msg-files",role:"list","aria-label":"Files sent with this message",children:Pe.map(he=>t.jsx("span",{role:"listitem",children:Cy(he.mime)?t.jsx(Am,{artifactId:he.artifactId,name:he.filename??"Untitled file",mime:he.mime,sizeBytes:he.sizeBytes}):t.jsx(Vd,{name:he.filename??"Untitled file",mime:he.mime,sizeBytes:he.sizeBytes,thumbnail:jy(he.mime)?vr(he.artifactId):null,...f?{onOpen:()=>f(he)}:{}})},he.artifactId))}):null,(H.blocks??[]).map((he,ke)=>{const Be=PH(H.blocks??[],ke,e);if(Be==="inside")return null;if(Be)return t.jsx(MH,{refusals:Be.refusals},ke);if(he.type==="thinking")return j||he.text.trim()===""?null:t.jsx(Sv,{text:he.text},ke);if(he.type==="text")return he.text.trim()===""?null:ce?t.jsx("div",{className:"wb-bubble",children:he.text},ke):t.jsx("div",{className:"wb-bubble","data-rich":"true",children:t.jsx(xr,{text:he.text})},ke);if(he.type==="attachment")return null;if(he.type==="tool_use"){if(j)return null;const qe=Ty(e,he.id),at=qe?qH(qe):null,le=!at&&he.name===BI&&qe?WI(qe.output):null,ye=!at&&he.name===sH&&(qe!=null&&qe.ok)?aH(he.input,qe.output):null;return ye&&iH(ye)?t.jsx(WN,{view:ye},ke):t.jsxs(u.Fragment,{children:[t.jsx(Cv,{label:at&&!(qe!=null&&qe.delegation)?`Approval · ${he.name}`:Xi(he.name),tool:he.name,ok:(qe==null?void 0:qe.ok)??null,running:qe===null,...at?{status:at.status,waiting:at.waiting,approval:!0}:le?{status:le}:{},gist:Ey(he.name,he.input),body:qe?CH(qe.output):null,opens:!0,onOpen:()=>r(he.id)},ke),ye?t.jsx(WN,{view:ye}):null]},ke)}return null}),Ee?t.jsxs("div",{className:"wb-msg-budget","data-testid":"budget-stop",children:[t.jsx("span",{children:WH(Ee)}),V===H.id?t.jsx(E,{size:"sm",className:"wb-msg-budget-continue","data-testid":"budget-continue",onClick:N,children:"Continue"}):null]}):null,$.has(H.id)?t.jsx("div",{className:"wb-msg-unchecked","data-testid":"unchecked-answer",children:UH}):null,H.feedback&&!ce&&!ve?t.jsx(JH,{feedback:H.feedback}):null,Me!==""?t.jsx(SH,{messageId:H.id,text:Me,onReadAloud:m}):null]},H.id)}),R?t.jsxs("div",{className:"wb-msg","data-role":"assistant","data-testid":"live-turn",children:[P?t.jsx(XN,{name:W,face:I(W)??M,moving:z}):null,S&&i.thinking!==""&&!j?t.jsx(Sv,{text:i.thinking,live:i.text==="",seconds:OH(i.thinkingStartedAt,i.textStartedAt??s)}):null,_?t.jsxs("div",{className:"wb-bubble","data-live":"true","data-rich":"true",children:[t.jsx(xr,{text:i.text}),t.jsx("span",{className:"wb-caret","aria-hidden":"true"})]}):null,a&&n.length===0&&!S?t.jsxs("span",{className:"wb-working",role:"status","aria-live":"polite","data-testid":"working",children:[v??`${h??x??"The agent"} is working`,t.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]})]}):null,n.map(H=>t.jsx(Cv,{label:Xi(H.name),tool:H.name,ok:null,running:!0,elapsed:Math.max(0,Math.round((s-H.startedAt)/1e3)),opens:!1,onOpen:()=>r(H.toolUseId)},H.toolUseId))]}):null,p,t.jsx("div",{ref:k})]})})}function XN({name:e,face:n,moving:s=!1,children:r}){const a=(n==null?void 0:n.picture)??null,i=tI(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(Bd,{state:"working",size:"sm",still:a,className:"wb-msg-blob"}):t.jsx(Rn,{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 IH(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 RH="delegation refused:";function PH(e,n,s){const r=i=>{const l=e[i];if(!l||l.type!=="tool_use"||l.name!==li)return null;const o=Ty(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(RH))return null;const d=l.input??{};return{target:typeof d.agent=="string"&&d.agent!==""?d.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 MH({refusals:e}){const[n,s]=u.useState(!1),r=e.map(o=>IH(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:[Xi(li)," · ",o.target]}),t.jsx("span",{className:"wb-tool-elapsed",children:"refused"})]}),t.jsx("p",{className:"wb-refusal-why",children:o.message})]},c))}):null]})}function OH(e,n){return e===null?null:Math.max(0,Math.round((n-e)/1e3))}function Sv({text:e,live:n=!1,seconds:s=null}){const[r,a]=u.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(xr,{text:e})}):null]})}function DH(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 JI(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+LH(i.text,a.text)+a.text},r=!0):s.push(a)}return r?{...e,blocks:s}:e}function LH(e,n){return e===""||n===""||/\s$/.test(e)||/^\s/.test(n)||/^[.,;:!?)\]}»”’'"]/.test(n)?"":/[.!?:…)"”»]$/.test(e)?`
106
+
107
+ `:""}function FH(e){return(JI(e).blocks??[]).filter(n=>n.type==="text").map(n=>n.text.trim()).filter(n=>n!=="").join(`
108
+
109
+ `)}function _H(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===li){const l=Ty(n,i.id);l!=null&&l.ok&&tf(l.output).forEach(a)}return s}function zH(e,n){return XI(e,n,s=>(s.stopped==="max_turns"||s.stopped==="max_tokens")&&s.noticed===!0)}const UH="Answered from memory, not checked";function BH(e,n){return XI(e,n,s=>s.unchecked===!0)}function XI(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 d of e)d.role!=="assistant"||!a(o,d)||(c=d);c===null||r.some(d=>i(d,o)&&a(d,c))||l.has(c.id)||l.set(c.id,o)}return l}function WH(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 HH(e){return e.type==="text"||e.type==="thinking"?e.text.trim()!=="":e.type==="tool_use"||e.type==="attachment"||e.type==="approval_result"}function KH({block:e,messages:n,at:s}){const[r,a]=u.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":Xi(e.name)}),t.jsx("span",{className:"wb-tool-elapsed",children:e.state}),t.jsx(ie,{name:"arrow",className:"wb-tool-arrow"})]}),r&&e.name===li?t.jsx(wH,{block:e,messages:n,answeredAt:s}):null,r&&e.name!==li?t.jsx("pre",{className:"wb-approval-output mono",children:VH(e.output)}):null]})}function VH(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}const GH=40;function qH(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(Nv(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 Cv({label:e,tool:n,ok:s,running:r,elapsed:a,opens:i,onOpen:l,status:o,waiting:c=!1,approval:d=!1,gist:h=null,body:f=null}){const[m,p]=u.useState(!1),x=t.jsxs(t.Fragment,{children:[r?t.jsx("span",{className:"wb-pulse","aria-hidden":"true"}):t.jsx("span",{className:"wb-tool-mark","data-ok":c?"pending":s===!1?"false":"true","aria-hidden":"true"}),t.jsx("span",{className:"wb-tool-label",children:e}),h?t.jsx("span",{className:"wb-tool-gist mono","data-testid":"tool-gist",children:h}):null,a===void 0?null:t.jsxs("span",{className:"wb-tool-elapsed",children:[a,"s"]}),o||s===!1?t.jsx("span",{className:"wb-tool-elapsed",children:o??"failed"}):null]}),g={"data-ok":s===null?void 0:s,"data-running":r,"data-gist":h?!0:void 0,"data-approval":d||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(y=>!y),children:[t.jsx(ie,{name:"chevron",className:"wb-tool-chevron"}),x]}),i?t.jsxs(ed,{children:[t.jsx(td,{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(nd,{children:t.jsxs(sd,{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(YH,{body:f,onOpen:i?l:null}):null]}):i?t.jsxs(ed,{children:[t.jsx(td,{asChild:!0,children:t.jsxs("button",{className:"wb-tool",...g,onClick:l,children:[x,t.jsx(ie,{name:"arrow",className:"wb-tool-arrow"})]})}),t.jsx(nd,{children:t.jsxs(sd,{className:"ui-tip",sideOffset:6,children:[t.jsx("span",{className:"ui-tip-title",children:"Open on the canvas"}),t.jsx("span",{className:"ui-tip-hint mono",children:n})]})})]}):t.jsx("span",{className:"wb-tool","data-static":"true",...g,children:x})}function YH({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(Yh,{text:e.diff,limit:GH,...s?{more:s}:{}})});const r=[e.exitCode===null?null:`exit ${e.exitCode}`,e.elapsedMs===null?null:QH(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 QH(e){return e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(1)}s`}function Ty(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 JH({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 XH=20*1024*1024,ZH=500,Ia=e=>`/skills/${encodeURIComponent(e)}`,Ru=e=>`/skills/bundles/${encodeURIComponent(e)}`;async function eK(e){var n;try{const{staged:s}=await Fw("/skills/bundles",e,"bundle.zip");return s}catch(s){const r=s instanceof fe?(n=s.detail)==null?void 0:n.refusal:void 0;throw r?new ZI({...r,filename:e.name,error:s instanceof Error?s.message:void 0}):s}}class ZI extends Error{constructor(s){super(s.error??`“${s.filename}” was refused.`);lk(this,"name","BundleRefused");this.refusal=s}}const tn={list:()=>je("/skills"),detail:e=>je(Ia(e)),downloadUrl:e=>`/api${Ia(e)}/download`,create:e=>te("/skills",e),saveText:(e,n)=>te(`${Ia(e)}/text`,{text:n}),grant:(e,n)=>te(`${Ia(e)}/grants`,n),trust:e=>te(`${Ia(e)}/trust`),remove:e=>Ws(Ia(e)),file:(e,n)=>je(`${Ia(e)}/file`,{path:n}),imageUrl:(e,n)=>`/api${Ia(e)}/image?path=${encodeURIComponent(n)}`,uploadBundle:eK,stagedFile:(e,n)=>je(`${Ru(e)}/file`,{path:n}),stagedImageUrl:(e,n)=>`/api${Ru(e)}/image?path=${encodeURIComponent(n)}`,acceptBundle:(e,n)=>te(Ru(e),n),discardBundle:e=>Ws(Ru(e))};function eR(e,n){return`${yt}?tab=skills${e?`&skill=${encodeURIComponent(e)}`:""}${e&&n?`&skfile=${encodeURIComponent(n)}`:""}`}function tK(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 nK(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 tR(e){const n=document.createElement("a");n.href=tn.downloadUrl(e),n.download="",document.body.appendChild(n),n.click(),n.remove()}const Iy=[{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 oi(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function Js(e,n){var s;return((s=e.find(r=>r.id===n))==null?void 0:s.name)??n}function Ry(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Py(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 ${oi(r)} (${s.length===1?"has its own":"each has its own"})`}function nR(e,n){return e.holders.some(s=>s.agent===n)}function sK(e,n){if(e.every)return Py(e,n);const s=e.holders.map(r=>Js(n,r.agent));return s.length?oi(s):"No agent uses it yet"}function rK(e){return!e.every&&e.holders.length===0}function aK(){const e=new Date;return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}function ZN(e){return e.slice(0,10)===aK()?"today":`on ${Pd(e,{compact:!0})}`}function Ec(e,n,s=!1){var l,o;if(e.learned){const c=e.learned.by,d=s&&e.holders.some(f=>f.agent===c),h=e.learned.keptAt?` · kept ${Ge(e.learned.keptAt)}`:"";return`${d?"":`learned by ${Js(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 ${Ry(r.plugin)} ${r.version}`;if((r==null?void 0:r.kind)==="catalogue")return`came with ${Js(n,r.agent)} ${r.version}`;if((r==null?void 0:r.kind)==="upload")return`uploaded${e.created?` ${ZN(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 ${ZN(a)}`:e.updatedAt?`edited by you ${Ge(e.updatedAt)}`:"written by you"}function sR(e){return e.charAt(0).toUpperCase()+e.slice(1)}function My(e,n){var s;return e.untrusted==="page"?`Untrusted: a web page was in view when ${Js(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 zr(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 rR(e,n){return e.every?n.filter(s=>!(e.shadowedBy??[]).includes(s.id)).map(s=>s.id):e.holders.map(s=>s.agent)}function iK(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=rR(e,n),i=d=>{var h;return((h=n.find(f=>f.id===d))==null?void 0:h.canRunScripts)===!0},l=a.filter(i).map(d=>Js(n,d)),o=a.filter(d=>!i(d)).map(d=>Js(n,d)),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} · ${oi(l)} can run them, asking first${o.length?`; ${oi(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 lK(e){var n;switch(e.kind){case"big":return{title:`“${e.filename}” is too big`,body:`${e.size?`It’s ${zr(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 ${ZH}.`};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 eS(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 Oy(e){return e.every?[]:e.holders.map(n=>n.agent)}function oK(e,n){var s;if(e.learned){const r=Js(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"?`${Js(n,e.from.agent)}’s next update will ask before it replaces your change.`:null}function cK(e,n,s){var o;const r=n.stops.map(c=>Js(s,c)),a=e.learned?Js(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.":`${oi(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"?Js(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 dK(e,n){var c,d;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=(d=(c=/^#\s+(.+)$/m.exec(i))==null?void 0:c[1])==null?void 0:d.trim(),o=a("name");return{title:l||(o?sR(o.replace(/-/g," ")):e.replace(/\.md$/i,"")),description:a("description"),body:i}}function uK(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 Jp(e){return/[\s"'\\]/.test(e)||e===""?JSON.stringify(e):e}function hK(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(`${Jp(r)} ${Jp(a)}`),s+=1):n.push(Jp(r))}return n}function fK({action:e,run:n,agentName:s,count:r,busy:a,error:i,onDecide:l}){const o=a!==null||e.state!=="pending",c=hK(n.args);return t.jsxs("section",{id:"approval-dock",tabIndex:-1,className:"wb-question skb-dock","data-kind":"approval","aria-label":"Approval needed","data-testid":"approval-dock",children:[t.jsxs("div",{className:"wb-question-head",children:[t.jsx("span",{className:"wb-question-kicker",children:"Needs your OK"}),r>1?t.jsxs("span",{className:"wb-dock-count","data-testid":"approval-dock-count",children:["1 of ",r]}):null,t.jsxs("strong",{children:[s," wants to run a script from ",n.title]})]}),t.jsxs("div",{className:"wb-dock-section wb-dock-subject",children:[t.jsx("code",{className:"wb-dock-gist",children:[n.interpreter,n.script].filter(Boolean).join(" ")}),t.jsx("span",{className:"wb-dock-where",children:"From a bundle you marked as yours."})]}),t.jsx("div",{className:"wb-dock-section",children:t.jsx(Qt,{items:[{label:"Arguments",value:c.length?t.jsx("span",{className:"mono skb-args",children:c.map((d,h)=>t.jsx("span",{children:d},`${h}:${d}`))}):"None"},{label:"Working folder",value:t.jsx("span",{className:"mono skb-path",children:n.writes})},{label:"What it may touch",value:`Reads ${n.title}’s ${n.files} file${n.files===1?"":"s"} without changing them, and the working folder. Writes only in the working folder.`}]})}),t.jsx(re,{message:i}),t.jsx("div",{className:"wb-dock-section",children:t.jsxs(se,{children:[t.jsx("span",{className:"skb-dock-note",children:"Scripts ask every time."}),t.jsx(gt,{}),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=eR(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 aR="approval-dock";function mK(){var n;const e=document.getElementById(aR);e&&((n=e.scrollIntoView)==null||n.call(e,{block:"nearest"}),e.focus())}const pK=["workspace","cwd","workdir","root"];function iR({approvals:e,timezone:n,now:s,version:r,onDecided:a,onSay:i,onOpenFull:l}){const[o,c]=u.useState([]),d=e.filter(m=>!o.includes(m.approvalId)),h=d[0];if(!h)return null;const f=m=>c(p=>p.includes(m)?p:[...p,m]);return t.jsx(gK,{item:h,count:d.length,timezone:n,now:s,version:r,onSettled:m=>{f(h.approvalId),m&&a(m)},onSay:i,onOpenFull:()=>l(h.toolUseId)},h.approvalId)}function gK({item:e,count:n,timezone:s,now:r,version:a,onSettled:i,onSay:l,onOpenFull:o}){var $;const[c,d]=u.useState(null),[h,f]=u.useState(null),[m,p]=u.useState(null),[x,g]=u.useState("");u.useEffect(()=>{let A=!1;return T.approval(e.approvalId).then(I=>{A||(d(I),I.state!=="pending"&&i(I))}).catch(I=>{A||f(I instanceof fe?I.message:String(I))}),()=>{A=!0}},[e.approvalId,a]);const y=c!==null&&c.state==="pending"&&Date.parse(c.expiresAt)<=r;u.useEffect(()=>{y&&c&&i({...c,state:"expired"})},[y]);const{values:j,controls:v}=xy(c==null?void 0:c.choices),w=(A,I)=>{const M=x.trim();p(A),f(null),(j&&A==="approve"?T.decide(e.approvalId,A,I,j):T.decide(e.approvalId,A,I)).then(O=>{i(O.action),M&&l(M)}).catch(O=>{f(O instanceof fe?O.message:String(O)),p(null)})},N=uK(c);if(c&&N){const A=jm(c.agentId)?vm:c.agentId?c.agentId.charAt(0).toUpperCase()+c.agentId.slice(1):"An agent";return t.jsx(fK,{action:c,run:N,agentName:A,count:n,busy:m,error:h,onDecide:I=>w(I)})}const k=m!==null||c===null||c.state!=="pending",S=(($=c==null?void 0:c.permissionScopes)==null?void 0:$.includes("always"))??!1,b=c?Ey(c.tool,c.canonicalArgs)??vK(c.preview):null,C=c?xK(c):null;return t.jsxs("section",{id:aR,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?Xi(c.tool):"Loading the request…"}),e.askedBy?t.jsx("span",{className:"wb-dock-asker","data-testid":"approval-dock-asker",children:e.askedBy}):null]}),b||C?t.jsxs("div",{className:"wb-dock-section wb-dock-subject",children:[b?t.jsx("code",{className:"wb-dock-gist",children:b}):null,C?t.jsxs("span",{className:"wb-dock-where",children:["in ",t.jsx("span",{className:"mono",children:C})]}):null]}):null,v?t.jsx("div",{className:"wb-dock-section",children:v}):null,t.jsx(re,{message:h}),t.jsx("div",{className:"wb-dock-section",children:t.jsx("input",{className:"wb-dock-instead",value:x,onChange:A=>g(A.target.value),onKeyDown:A=>{A.key==="Enter"&&A.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 ",ft(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:k,onClick:()=>w("reject"),children:m==="reject"?"Rejecting…":"Reject"}),S?t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",size:"sm",disabled:k,onClick:()=>w("approve","conversation"),children:"Auto: this conversation"}),t.jsx(E,{size:"sm",disabled:k,onClick:()=>w("approve","always"),children:"Always: this agent"})]}):null,t.jsx(E,{variant:"good",size:"sm",disabled:k,onClick:()=>w("approve"),children:m==="approve"?"Approving…":S?"Allow once":"Approve"})]})]})}function xK(e){for(const n of[e.canonicalArgs,e.envelope])if(!(n===null||typeof n!="object"||Array.isArray(n)))for(const s of pK){const r=n[s];if(typeof r=="string"&&r.trim()!=="")return r.trim()}return null}function vK(e){const n=(e??"").split(`
111
+ `).map(s=>s.trim()).find(Boolean);return n?n.length>160?`${n.slice(0,157)}…`:n:null}const jK=2e3;function wK({conversationId:e,agentId:n,runId:s=null,result:r=null,waiting:a=null,agents:i=[]}){const l=r!==null,[o,c]=u.useState(l),d=!o||a!==null,{data:h,error:f}=pe(()=>Xe.conversation(e),[e,o,(a==null?void 0:a.approvalId)??null],d?jK:void 0),m=(h==null?void 0:h.runs)??[],p=s===null?null:m.find(N=>N.runId===s)??null,x=l||a===null&&(s!==null?p!==null&&p.finishedAt!==null:m.length>0&&m.every(N=>N.finishedAt!==null));u.useEffect(()=>{x&&c(!0)},[x]);const g=r?r.ok?"done":"failed":a!=null&&a.approvalId?"waiting":x?"done":"working",y=i.find(N=>N.id===n)??null,j=(y==null?void 0:y.name)??(h==null?void 0:h.agentId)??n,v=(h==null?void 0:h.messages)??[],w=(r==null?void 0:r.text)??yK(v);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:v.map((N,k)=>t.jsx("div",{className:"wb-delegate-turn",children:(N.blocks??[]).map((S,b)=>{if(S.type==="thinking")return S.text.trim()===""?null:t.jsx(Sv,{text:S.text},b);if(S.type==="tool_use"){const C=kK(bK(v,S.id));return t.jsx(Cv,{label:Xi(S.name),tool:S.name,ok:C.ok,running:C.running,waiting:C.waiting,status:C.status,gist:Ey(S.name,S.input),opens:!1,onOpen:()=>{}},b)}return null})},N.id??k))}),w?t.jsx("div",{className:"wb-delegate-answer","data-testid":"delegate-answer",children:t.jsx(xr,{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(Vd,{name:N.filename??"Untitled file",mime:N.mime,sizeBytes:N.sizeBytes,thumbnail:jy(N.mime)?vr(N.artifactId):null})},N.artifactId))}):null,t.jsxs("div",{className:"wb-delegate-actions",children:[g==="waiting"?t.jsx(E,{variant:"accent",onClick:()=>mK(),"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 yK(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 bK(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 kK(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 tS=1024*1024;function NK({files:e,agentId:n,root:s,revision:r}){const[a,i]=u.useState({kind:"dir",path:""});return u.useEffect(()=>i({kind:"dir",path:""}),[e.plugin,n]),t.jsx("div",{className:"wb-files","data-testid":"files-view",children:a.kind==="dir"?t.jsx(SK,{files:e,agentId:n,root:s,path:a.path,revision:r,go:i}):t.jsx(CK,{files:e,agentId:n,root:s,path:a.path,revision:r,go:i})})}function lR({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 SK({files:e,agentId:n,root:s,path:r,revision:a,go:i}){const[l,o]=u.useState(null),[c,d]=u.useState(null),[h,f]=u.useState(!1),[m,p]=u.useState(null);u.useEffect(()=>{let y=!1;return d(null),T.pageQuery(e.plugin,e.list,{agent:n,...r?{path:r}:{}}).then(j=>{y||o(j.data)}).catch(j=>{y||d(j instanceof Error?j.message:String(j))}),()=>{y=!0}},[e.plugin,e.list,n,r,a]),u.useEffect(()=>p(null),[r]);const x=async()=>{f(!0),p(null);try{const y=await fetch(T.pageFileUrl(e.plugin,e.archive,{agent:n,...r?{path:r}:{}}),{credentials:"same-origin"});if(!y.ok){const N=await y.json().catch(()=>null);p((N==null?void 0:N.error)??"The archive could not be made.");return}const j=await y.blob(),v=URL.createObjectURL(j),w=document.createElement("a");w.href=v,w.download=`${r===""?s:r.split("/").at(-1)}.zip`,w.click(),window.setTimeout(()=>URL.revokeObjectURL(v),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(se,{children:[t.jsx(lR,{root:s,path:r,go:i}),t.jsx(gt,{}),t.jsx(E,{size:"sm",onClick:()=>void x(),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:ya,children:"Files library"})," and mention it here."]}):"This folder is empty."}):t.jsx(ut,{children:g.map(y=>t.jsx(ot,{href:"#",onClick:()=>i({kind:y.kind,path:y.path}),lead:t.jsx(AK,{kind:y.kind}),title:t.jsxs("span",{className:"mono",children:[y.name,y.kind==="dir"?"/":""]}),side:y.kind==="file"?vs(y.bytes):void 0},y.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 CK({files:e,agentId:n,root:s,path:r,revision:a,go:i}){const[l,o]=u.useState(null),[c,d]=u.useState(null),[h,f]=u.useState(!1);u.useEffect(()=>{let j=!1;return d(null),T.pageQuery(e.plugin,e.stat,{agent:n,path:r}).then(v=>{j||o(v.data)}).catch(v=>{j||d(v instanceof Error?v.message:String(v))}),()=>{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)}`:"",x=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"}),y=(m==null?void 0:m.type)==="text"&&m.bytes<=tS;return t.jsxs(t.Fragment,{children:[t.jsxs(se,{children:[t.jsx(lR,{root:s,path:r,go:i}),t.jsx(gt,{}),y?t.jsx(E,{size:"sm","aria-pressed":h,onClick:()=>f(j=>!j),children:"Wrap"}):null,t.jsx(st,{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:x,alt:m.name})}):m.type==="pdf"?t.jsx("div",{className:"file-preview file-preview-pdf",children:t.jsx("object",{data:x,type:"application/pdf","aria-label":m.name,children:t.jsx(q,{children:"Your browser cannot show this PDF here. Download it to open it."})})}):y?t.jsx(EK,{src:x,wrap:h}):t.jsxs(t.Fragment,{children:[t.jsx(q,{children:m.type==="text"?`This file is over ${vs(tS)}, too long to read here. Download it to open it.`:"This kind of file is not shown here. Download it to open it."}),t.jsx(Qt,{items:[{label:"Size",value:vs(m.bytes)},{label:"Type",value:t.jsx("span",{className:"mono",children:m.mime})}]})]})]})}function EK({src:e,wrap:n}){const[s,r]=u.useState(null),[a,i]=u.useState(!1);return u.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 AK({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 $K({input:e,output:n,ok:s}){const r=WW(e),a=WI(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(Ce,{tone:HW(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(Kt,{summary:"The call",children:t.jsxs("dl",{className:"ui-kv wb-envelope-fields",children:[t.jsx("dt",{children:"Urgency"}),t.jsx("dd",{children:r.urgency}),r.link?t.jsxs(t.Fragment,{children:[t.jsx("dt",{children:"Link"}),t.jsx("dd",{className:"mono",children:r.link})]}):null,r.key?t.jsxs(t.Fragment,{children:[t.jsx("dt",{children:"Key"}),t.jsx("dd",{className:"mono",children:r.key})]}):null]})})]})}const uc=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)?e:{},Zt=e=>typeof e=="string"&&e.trim()!==""?e:null,TK={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 IK(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 Xp(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function RK(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 Ev(e){try{const n=new URL(e);return`${n.hostname.replace(/^www\./,"")}${n.pathname.replace(/\/+$/,"")}${n.search}`}catch{return e}}function nS(e){var n;return((n=e.match(/[\p{L}\p{N}]/u))==null?void 0:n[0])??"?"}function oR(e){const n=uc(e.input),s=uc(e.output),r={input:e.input,...e.ok===null?{status:"Awaiting result"}:{output:e.output},...e.error===void 0?{}:{error:e.error}},a=e.ok===!1,i=Zt(e.error)??Zt(uc(e.error).message);if(Array.isArray(s.results)||Zt(n.query)&&!Zt(n.url)){const f=(Array.isArray(s.results)?s.results:[]).map(p=>uc(p)).flatMap(p=>{const x=Zt(p.url);return x?[{title:Zt(p.title)??Xp(x),url:x,host:Zt(p.source)??Xp(x),snippet:Zt(p.snippet)}]:[]}),m=s.available===!1;return{kind:"search",id:e.id,raw:r,query:Zt(s.query)??Zt(n.query)??"",state:e.ok===null?"pending":a||m?"failed":"ok",provider:Zt(s.provider),results:f,why:a?`The search failed${i?`: ${i}`:"."}`:m?Zt(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=Zt(s.url)??Zt(n.url)??"",o=!a&&s.ok!==!1&&IK(Zt(s.text)??""),c=a||s.ok===!1||o,d=o?"unreadable":Zt(s.problem),h=Zt(s.message);return{kind:"page",id:e.id,url:l,raw:r,host:Zt(s.source)??Xp(l),state:e.ok===null?"pending":c?"failed":"ok",title:Zt(s.title),text:o?null:Zt(s.text),truncated:s.truncated===!0,retrievedAt:Zt(s.retrievedAt)??e.at,why:c?(d&&TK[d])??(h?h.charAt(0).toUpperCase()+h.slice(1)+(/[.!?]$/.test(h)?"":"."):null)??`The read failed${i?`: ${i}`:"."}`:null}}function PK(e){const n=e.entries.map(oR),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 MK(e){return e.split(/\s+/).filter(Boolean).length}function OK(e){return e>=1e3?`${(e/1e3).toFixed(1).replace(/\.0$/,"")}k words`:`${e} ${e===1?"word":"words"}`}function DK(e,n){if(!e)return null;const s=new Date(e);return Number.isNaN(s.getTime())?null:$t(s,n??Intl.DateTimeFormat().resolvedOptions().timeZone)}function cR({url:e,className:n,children:s}){const r=RK(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 dR({value:e}){const[n,s]=u.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 LK({page:e,focused:n,timezone:s}){const[r,a]=u.useState(n),[i,l]=u.useState(!1),o=u.useRef(null);if(u.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:nS(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",d=e.text?MK(e.text):0,h=DK(e.retrievedAt,s),f=[e.host,h?`read ${h}`:null,d?OK(d):null,d?`${Math.max(1,Math.round(d/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?"!":nS(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(cR,{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(dR,{value:e.raw})]})]}):null]})}const sS=3;function FK({search:e,read:n,focused:s}){const[r,a]=u.useState(!1),i=u.useRef(null);u.useEffect(()=>{var c,d;s&&((d=(c=i.current)==null?void 0:c.scrollIntoView)==null||d.call(c,{block:"nearest"}))},[s]);const l=r?e.results:e.results.slice(0,sS),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(dR,{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(cR,{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(Ev(c.url))?t.jsx("span",{className:"wb-src-result-side",children:t.jsx(Ce,{tone:"good",children:"Read"})}):null]},c.url))}):null,e.results.length>sS?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 _K({entries:e,focus:n,timezone:s}){const r=e.map(oR),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),d=Zt(uc(c==null?void 0:c.input).url);return[Ev(o.url),...d?[Ev(d)]:[]]}));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(LK,{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(FK,{search:o,read:l,focused:n===o.id},o.id))]}):null]})}const zK=3,UK=152,BK=104,WK=100,HK=2,rS=5;function KK({renderables:e,activeId:n,onActivate:s,timezone:r,onDecided:a,onChangeAgent:i,face:l,cardFace:o,descriptors:c,grantedTools:d,agentName:h,maxTabs:f,browserPanel:m,browserMenu:p,agents:x,onClose:g,loading:y=!1}){var S;const[j,v]=VK(f);if(e.length===0)return t.jsxs("div",{className:"wb-canvas","data-testid":"canvas",children:[t.jsx("div",{className:"wb-canvas-tabs",ref:j,"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:y?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:JK(h,XK(c??[],d??[]))})]})})]});const w=e.some(b=>b.id===n)?n:e[e.length-1].id,{shown:N,hidden:k}=GK(e,w,v);return t.jsx("div",{className:"wb-canvas","data-testid":"canvas",children:t.jsxs(t6,{value:w,onValueChange:s,className:"contents",children:[t.jsxs("div",{className:"wb-canvas-tabs",ref:j,children:[t.jsx("span",{className:"wb-canvas-label","aria-hidden":"true",children:"Canvas"}),t.jsx(n6,{className:"wb-tabstrip","aria-label":"Canvas",children:N.map(b=>t.jsxs("div",{className:"wb-tab-item",children:[t.jsxs(s6,{value:b.id,className:"wb-tab","data-tone":b.tone,onKeyDown:C=>{C.key==="Delete"&&g&&iS(b)&&(C.preventDefault(),g(b.id))},children:[b.tone==="warning"||b.tone==="critical"?t.jsx("span",{className:"wb-tab-dot","data-tone":b.tone,"aria-hidden":"true"}):null,t.jsx("span",{className:"wb-tab-text",children:b.title}),b.count?t.jsx("span",{className:"wb-tab-count",children:b.count}):null]}),g&&iS(b)?t.jsx("button",{className:"wb-tab-close","aria-label":`Close ${b.title} tab`,title:"Dismiss panel; keep conversation history",onClick:()=>g(b.id),children:"×"}):null]},b.id))}),t.jsx(qK,{items:k,onActivate:s,timezone:r}),p&&((S=e.find(b=>b.id===w))==null?void 0:S.source)==="browser"?t.jsx("span",{className:"wb-canvas-menu",children:p}):null]}),e.map(b=>t.jsx(r6,{value:b.id,className:"wb-canvas-body","data-renderer":b.source==="descriptor"&&b.renderer==="preview"?"preview":void 0,"data-dense":e9.has(b.renderer)?"true":void 0,"data-page":b.source==="browser"?"true":void 0,children:b.source==="browser"?m:t.jsxs("section",{className:"ui-panel","data-flush":b.source==="descriptor"&&b.renderer==="preview"?"true":void 0,children:[b.source!=="files"&&!aS(b)&&!(b.source==="descriptor"&&b.renderer==="preview")?t.jsxs("header",{className:"ui-panel-head",children:[t.jsx("h2",{className:"ui-panel-title",children:b.title}),t.jsx("span",{className:"ui-panel-tool mono",children:b.source==="sources"?PK(b.props):b.tool})]}):null,b.tone==="critical"?t.jsxs("p",{className:"muted",children:["Recorded tool failure",b.at?` · ${ft(b.at,Intl.DateTimeFormat().resolvedOptions().timeZone)}`:"",". This is history, not live session status."]}):null,aS(b)?t.jsx(rW,{value:b.props.value,title:b.title,tool:b.tool,face:o,timezone:r}):b.source==="profile"?t.jsx(fW,{...b.props,...i?{onChange:i}:{}}):b.source==="artifact"?t.jsx(_W,{...b.props}):b.source==="files"?t.jsx(NK,{...b.props}):b.source==="sources"?t.jsx(_K,{...b.props,timezone:r}):b.source==="notify"?t.jsx($K,{...b.props}):b.source==="delegate"?t.jsx(wK,{...b.props,agents:x??[]}):t.jsx(B8,{renderer:b.renderer,props:b.props,timezone:r,onDecided:a})]})},b.id))]})})}function aS(e){var n;return e.renderer==="structured"&&(e.source==="fallback"||e.source==="descriptor")&&!((n=e.props)!=null&&n.failed)}function iS(e){return e.source==="approval"?!1:e.source==="browser"?e.pinned!==!0:e.source!=="files"}function VK(e){const[n,s]=u.useState(rS),r=u.useRef(null);return[u.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 d=Math.floor((c-WK-BK)/UK);s(Math.max(HK,Math.min(rS,d)))};l(),r.current=new ResizeObserver(l),r.current.observe(i)},[e]),e??n]}function GK(e,n,s){const r=new Set(e.filter(i=>i.id===n||i.source==="approval"||i.pinned===!0).map(i=>i.id)),a=new Set(r);for(let i=e.length-1;i>=0&&a.size<s;i-=1)a.add(e[i].id);return{shown:e.filter(i=>a.has(i.id)),hidden:e.filter(i=>!a.has(i.id))}}function qK({items:e,onActivate:n,timezone:s}){if(e.length===0)return null;const r=e.some(a=>a.tone==="critical")?"critical":e.some(a=>a.tone==="warning")?"warning":null;return t.jsxs(Dd,{modal:!1,children:[t.jsx(Ld,{asChild:!0,children:t.jsxs("button",{className:"wb-tab wb-tab-more","data-tone":r??void 0,"aria-label":`${e.length} more ${e.length===1?"view":"views"} in this conversation`,children:[r?t.jsx("span",{className:"wb-tab-dot","data-tone":r,"aria-hidden":"true"}):null,t.jsxs("span",{className:"wb-tab-text",children:[e.length," more"]}),t.jsx(ie,{name:"chevron-down"})]})}),t.jsx($o,{children:t.jsxs(Fd,{className:"ui-menu","data-wide":"true",align:"end",sideOffset:6,children:[t.jsx(Yi,{className:"ui-menu-label",children:"Earlier in this conversation"}),[...e].reverse().map(a=>t.jsxs(Vs,{className:"ui-menu-item",onSelect:()=>n(a.id),children:[t.jsxs("span",{className:"ui-menu-item-text",children:[a.tone==="warning"||a.tone==="critical"?t.jsx("span",{className:"wb-tab-dot","data-tone":a.tone,"aria-hidden":"true"}):null,a.title]}),t.jsx("span",{className:"ui-menu-note mono",children:YK(a.at,s)??a.tool})]},a.id))]})})]})}function YK(e,n){if(!e)return null;const s=new Date(e);return Number.isNaN(s.getTime())?null:$t(s,n)}const QK={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 JK(e,n){const s=e?`What ${e} shows you`:"What your agent shows you",r=[...new Set(n.map(a=>QK[a.renderer]??"results"))].slice(0,3);return r.length>0?`${s} lands here: ${r.join(", ")}.`:`${s} lands here.`}function XK(e,n){const s=new Set(n),r=new Set,a=e.filter(c=>{if(!s.has(c.tool))return!1;const d=ZK(c);return r.has(d)?!1:(r.add(d),!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,zK)}function ZK(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 e9=new Set(["table","diff","files"]),La=320,t9=280,lS=24,n9=12,s9=[1/3,1/2,2/3],Av="buddi.chatWidth";function cf(e){return{min:La,max:Math.max(La,Math.round(e)-t9)}}function r9(e,n,s){return Math.max(0,Math.round(e+n-Math.max(0,s)))}function a9(e,n){return df(e,n)}function df(e,n){const{min:s,max:r}=cf(n);return Number.isFinite(e)?n<=0?Math.max(s,Math.round(e)):Math.min(r,Math.max(s,Math.round(e))):s}function i9(e,n){if(n<=0)return e;for(const s of s9){const r=Math.round(n*s);if(Math.abs(e-r)<=n9)return r}return e}function l9(e,n){return df(i9(e,n),n)}function o9(e,n,s){const{min:r,max:a}=cf(s);switch(n){case"ArrowLeft":return df(e-lS,s);case"ArrowRight":return df(e+lS,s);case"Home":return r;case"End":return s>0?a:null;default:return null}}function c9(){try{const e=window.localStorage.getItem(Av);if(e===null)return null;const n=Number(e);return Number.isFinite(n)&&n>=La?Math.round(n):null}catch{return null}}function d9(e){try{e===null?window.localStorage.removeItem(Av):window.localStorage.setItem(Av,String(Math.round(e)))}catch{}}const $v="--wb-chat-w";function u9({columnRef:e,width:n,onChange:s,label:r="Resize the conversation column"}){const a=u.useRef(null),i=u.useRef(null),[l,o]=u.useState(!1),[c,d]=u.useState({now:n??La,max:La}),h=()=>{var k;const g=e.current,y=(k=a.current)==null?void 0:k.nextElementSibling,j=(g==null?void 0:g.getBoundingClientRect().width)||(g==null?void 0:g.offsetWidth)||n||La,v=g==null?void 0:g.parentElement,w=v?v.scrollWidth-v.clientWidth:0;return{shared:r9((g==null?void 0:g.getBoundingClientRect().width)??0,(y==null?void 0:y.getBoundingClientRect().width)??0,w),current:j,left:(g==null?void 0:g.getBoundingClientRect().left)??0}},f=g=>{const{shared:y,current:j}=h();d({now:Math.round(g??j),max:cf(y).max})};u.useEffect(()=>{f(n??void 0)},[n]);const m=g=>{const y=e.current;y&&(g===null?(y.style.removeProperty($v),delete y.dataset.sized):(y.style.setProperty($v,`${g}px`),y.dataset.sized="true"))},p=g=>{m(g),d9(g),s(g)},x=()=>{const g=i.current;g&&(g.frame!==null&&cancelAnimationFrame(g.frame),i.current=null,o(!1),document.documentElement.removeAttribute("data-resizing"),g.next!==null&&p(g.next))};return u.useEffect(()=>{var v;if(n===null)return;const g=(v=e.current)==null?void 0:v.parentElement;if(!g)return;const y=()=>{if(i.current)return;const{shared:w}=h();if(w<=0)return;const N=a9(n,w);m(N),d({now:N,max:cf(w).max})};y();const j=typeof ResizeObserver>"u"?null:new ResizeObserver(y);return j==null||j.observe(g),window.addEventListener("resize",y),()=>{j==null||j.disconnect(),window.removeEventListener("resize",y)}},[n]),u.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":La,"aria-valuemax":Math.max(La,c.max),"aria-valuenow":c.now,title:"Drag to resize · double-click to reset","data-dragging":l?"true":void 0,onPointerDown:g=>{var v,w;if(g.pointerType==="mouse"&&g.button!==0)return;g.preventDefault(),(w=(v=g.currentTarget).setPointerCapture)==null||w.call(v,g.pointerId);const{shared:y,left:j}=h();i.current={pointerId:g.pointerId,left:j,shared:y,next:null,frame:null},o(!0),document.documentElement.setAttribute("data-resizing","true")},onPointerMove:g=>{const y=i.current;!y||y.pointerId!==g.pointerId||(y.next=l9(g.clientX-y.left,y.shared),y.frame===null&&(y.frame=requestAnimationFrame(()=>{const j=i.current;j&&(j.frame=null,j.next!==null&&m(j.next))})))},onPointerUp:x,onPointerCancel:x,onLostPointerCapture:x,onDoubleClick:()=>{p(null),f()},onKeyDown:g=>{const{shared:y,current:j}=h(),v=o9(n??j,g.key,y);v!==null&&(g.preventDefault(),p(v))}})}const h9=3.5*6e4,f9=2e3;function m9(e,n,s={}){const[r,a]=u.useState({served:new Set,live:new Set,scope:n}),i=u.useRef(r.served);if(r.scope!==n){const d={served:new Set,live:new Set,scope:n};i.current=d.served,a(d)}const l=s.check??T.previewCheck,o=s.everyMs??f9,c=e.map(d=>`${ql(d)}@${d.at??""}`).join("|");return u.useEffect(()=>{const d=new Map;for(const p of e){const x=ql(p);if(i.current.has(x))continue;const g=p.at===null?Number.NaN:Date.parse(p.at),y=Number.isNaN(g)?0:g+h9,j=d.get(x);(!j||y>j.until)&&d.set(x,{plugin:p.plugin,name:p.name,until:y})}if(d.size===0)return;let h=!1,f;const m=async()=>{const p=Date.now();for(const[x,g]of[...d]){const y=await l(g.plugin,g.name).catch(()=>null);if(h)return;const j=p<=g.until;y!=null&&y.ok?(d.delete(x),a(v=>{const w={served:new Set(v.served).add(x),live:j?new Set(v.live).add(x):v.live,scope:v.scope};return i.current=w.served,w})):j||d.delete(x)}!h&&d.size>0&&(f=setTimeout(()=>void m(),o))};return m(),()=>{h=!0,f!==void 0&&clearTimeout(f)}},[c,n,l,o]),r}const Tv="workspace-files";function p9(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 g9(e){const[n,s]=u.useState(null);return u.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 x9(e,n){return{id:Tv,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 Iv(e){return`agent-properties:${e}`}function v9(e){return{id:Iv(e.id),tool:`@${e.handle}`,title:"Properties",renderer:"profile",props:{profile:e},at:null,source:"profile",substantial:!1}}function j9(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,d=(h,f)=>Math.max(0,Math.min(Math.round(h),Math.round(f)));return{x:d(o,n.deviceWidth),y:d(c,n.deviceHeight)}}function Zp(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}function oS(e){return[...e].length===1&&e.codePointAt(0)>=32&&e.codePointAt(0)!==127}const w9=4e3;function y9(e){return e.replace(/\r\n?/g,`
116
+ `).replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g,"").slice(0,w9)}const b9=["left","middle","right"],k9=33;function N9(e,n){return e.deviceWidth===n.deviceWidth&&e.deviceHeight===n.deviceHeight&&e.pageScaleFactor===n.pageScaleFactor&&e.offsetTop===n.offsetTop&&e.url===n.url}function S9(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 C9(e=window.location){return`${e.protocol==="https:"?"wss":"ws"}://${e.host}/api/browser/hand`}const E9=u.forwardRef(function({sessionId:n,csrf:s,onGiveBack:r,connect:a,bare:i=!1,typing:l,onTyping:o,onLocation:c,onLoginSeen:d},h){const[f,m]=u.useState("connecting"),[p,x]=u.useState(null),[g,y]=u.useState(!1),[j,v]=u.useState(null),[w,N]=u.useState(!1),k=l??w,S=J=>{o?o(J):N(J)},[b,C]=u.useState(0),$=u.useRef(null),A=u.useRef(d);A.current=d;const I=u.useRef(null),M=u.useRef(null),O=u.useRef({at:0});u.useEffect(()=>{var J,H,X,G;l!==void 0&&(l?(H=(J=M.current)==null?void 0:J.focus)==null||H.call(J):(G=(X=M.current)==null?void 0:X.blur)==null||G.call(X))},[l]),u.useEffect(()=>{const J=a??(G=>new WebSocket(G));let H=!0,X;try{X=J(C9())}catch{m("lost");return}return X.binaryType="arraybuffer",$.current=X,X.onopen=()=>X.send(JSON.stringify({type:"hello",csrf:s,sessionId:n})),X.onmessage=G=>{var xe;if(!H)return;if(typeof G.data!="string"){const De=S9(G.data);if(!De||(v(B=>B&&N9(B,De.metadata)?B:De.metadata),y(!0),typeof createImageBitmap!="function"))return;createImageBitmap(De.jpeg).then(B=>{var Z,ve,$e;const ne=I.current;if(!H||!ne){(Z=B.close)==null||Z.call(B);return}(ne.width!==B.width||ne.height!==B.height)&&(ne.width=B.width,ne.height=B.height),(ve=ne.getContext("2d"))==null||ve.drawImage(B,0,0),($e=B.close)==null||$e.call(B)}).catch(()=>{});return}const ce=JSON.parse(G.data);if(ce.type==="driving"){m("driving"),x(null);return}if(ce.type==="loginSeen"){typeof ce.id=="string"&&typeof ce.site=="string"&&typeof ce.username=="string"&&((xe=A.current)==null||xe.call(A,{id:ce.id,site:ce.site,username:ce.username,...ce.update===!0?{update:!0}:{}}));return}(ce.type==="refused"||ce.type==="ended")&&(x(ce.error??"The screen cannot be driven from here."),m("refused"))},X.onclose=()=>{H&&m(G=>G==="refused"?G:"lost")},X.onerror=()=>{H&&m(G=>G==="refused"?G:"lost")},()=>{H=!1,$.current=null;try{X.close()}catch{}}},[n,s,b,a]),u.useEffect(()=>()=>{clearTimeout(O.current.timer)},[]);const R=j==null?void 0:j.url;u.useEffect(()=>{R&&(c==null||c(R))},[R]);const _=u.useCallback(J=>{const H=$.current;if(H)try{H.send(JSON.stringify({type:"input",input:J}))}catch{}},[]);u.useImperativeHandle(h,()=>({nav:(J,H)=>$.current?(_({kind:"nav",action:J,...J==="navigate"&&H?{url:H}:{}}),!0):!1}),[_]);const z=J=>{var G;const H=I.current;if(!H||!j)return null;const X=(G=H.getBoundingClientRect)==null?void 0:G.call(H);return X?j9(X,j,J.clientX,J.clientY):null},U=J=>{const H=O.current,X=Date.now();clearTimeout(H.timer),H.timer=void 0;const G=H.at+k9-X;if(G<=0){H.at=X,H.pending=void 0,_(J);return}H.pending=J,H.timer=setTimeout(()=>{const ce=O.current.pending;O.current.timer=void 0,O.current.pending=void 0,O.current.at=Date.now(),ce&&_(ce)},G)},P=()=>{const J=O.current;clearTimeout(J.timer),J.timer=void 0;const H=J.pending;J.pending=void 0,H&&(J.at=Date.now(),_(H))},W=J=>H=>{var ce,xe;const X=z(H);if(!X)return;J==="mousePressed"&&(H.preventDefault(),(xe=(ce=I.current)==null?void 0:ce.focus)==null||xe.call(ce));const G={kind:"mouse",type:J,x:X.x,y:X.y,button:b9[H.button]??"left",clickCount:J==="mouseMoved"?0:Math.min(3,Math.max(1,H.detail||1)),modifiers:Zp(H)};if(J==="mouseMoved"){U(G);return}P(),_(G)},L=J=>{const H=z(J);H&&(P(),_({kind:"wheel",x:H.x,y:H.y,deltaX:Math.round(J.deltaX),deltaY:Math.round(J.deltaY)}))},Q=J=>J.ctrlKey||J.metaKey||J.altKey,F=J=>{var X,G;if(J.key==="Escape"&&Q(J)){S(!1),(G=(X=J.target).blur)==null||G.call(X);return}if(J.preventDefault(),(J.metaKey||J.ctrlKey)&&(J.key==="v"||J.key==="V"))return;const H=Zp(J);if(oS(J.key)&&!Q(J)){_({kind:"key",type:"char",key:J.key,code:J.code,text:J.key,modifiers:H});return}_({kind:"key",type:"keyDown",key:J.key,code:J.code,modifiers:H})},ae=J=>{J.key==="Escape"&&Q(J)||(J.preventDefault(),!((J.metaKey||J.ctrlKey)&&(J.key==="v"||J.key==="V"))&&(oS(J.key)&&!Q(J)||_({kind:"key",type:"keyUp",key:J.key,code:J.code,modifiers:Zp(J)})))},V=J=>{var X;J.preventDefault();const H=y9(((X=J.clipboardData)==null?void 0:X.getData("text/plain"))??"");H!==""&&_({kind:"text",text:H})};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(se,{align:"end",children:[t.jsx(E,{size:"sm",variant:k?"accent":"ghost","aria-pressed":k,onClick:()=>{var H,X,G,ce;const J=!k;S(J),J?(X=(H=M.current)==null?void 0:H.focus)==null||X.call(H):(ce=(G=M.current)==null?void 0:G.blur)==null||ce.call(G)},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(se,{align:"end",children:t.jsx(E,{size:"sm",variant:"accent",onClick:()=>{m("connecting"),C(J=>J+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:W("mousePressed"),onMouseUp:W("mouseReleased"),onMouseMove:W("mouseMoved"),onWheel:L,onKeyDown:F,onKeyUp:ae,onPaste:V,onContextMenu:J=>J.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:M,className:"hand-typing","aria-label":"Type into the host browser",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,value:"",onChange:()=>{},onKeyDown:F,onKeyUp:ae,onPaste:V,onBlur:()=>S(!1)})]})});function A9(e){return e==="darwin"?"this Mac":"this computer"}let eg=null;function $m(){const[e,n]=u.useState(void 0);return u.useEffect(()=>{let s=!0;return eg??(eg=T.session().then(r=>r.platform,()=>{eg=null})),eg.then(r=>{s&&n(r)}),()=>{s=!1}},[]),A9(e)}const $9="sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0";function T9({timezone:e,navigate:n}={}){var d;const{data:s,error:r,reload:a}=pe(()=>T.browser(),[],3e3),i=pe(()=>T.session(),[]),l=(d=i.data)!=null&&d.platform?i.data.platform==="darwin":!0,o=!!i.data||!!i.error,c=h=>{n?n(h):window.location.hash=h};return t.jsxs("div",{className:"ui-stack br-looking","data-gap":"lg",children:[t.jsx(re,{message:r}),!s||!o?t.jsx(be,{children:"Checking where agents may look…"}):t.jsx(D9,{data:s,macOS:l,reload:a,timezone:e,go:c})]})}function Dy({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 lr({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 I9({text:e}){const[n,s]=u.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 Pu({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 Tm(e){const n=e.split(".").filter(Boolean).at(-1)??e;return n.charAt(0).toUpperCase()+n.slice(1)}function R9(e){return e.length<=2?e.join(" and "):`${e.slice(0,2).join(", ")} and ${e.length-2} more`}const P9=[{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 Rv({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:P9.filter(i=>s||i.value!=="apps"||e==="apps").map(i=>t.jsx("option",{value:i.value,children:i.label},i.value))})}function M9(e){return(e==null?void 0:e.installed)===!0}function O9(e,n){return e?e.pending?"pair":e.pairedAt?e.connected?"connected":n&&n.state!=="paired"&&mR(n.gateway)?"broken":"notrunning":n&&n.state!=="paired"?"pair":"none":"none"}function D9({data:e,macOS:n,reload:s,timezone:r,go:a}){var j,v;const[i,l]=u.useState(!1),[o,c]=u.useState(null),d=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 d(()=>T.browserSettings(w)),m=r??Intl.DateTimeFormat().resolvedOptions().timeZone,p=e.learnedSignInSites??[],x=(j=e.routes)==null?void 0:j.find(w=>w.kind==="apps"),g=M9(x),y=(v=e.sessions)!=null&&v.length?e.sessions:e.session?[e]:[];return t.jsxs(t.Fragment,{children:[t.jsx(q,{children:"Agents pick where to look for each task: their own browser first, your Chrome for a site that needs your sign-in, an app when you name one. You don’t choose each time; here you say what they may use."}),t.jsx(re,{message:o}),e.enabled?null:t.jsx(q,{tone:"warning",children:"Agents can’t look at pages from here. Start buddi serve on the machine buddi runs on."}),e.stop?t.jsx(q,{tone:"warning",role:"status",action:t.jsx(E,{size:"sm",variant:"accent",disabled:i,onClick:()=>void d(()=>T.browserControl("resume")),children:"Resume"}),children:`Agents’ browsing is paused since ${$t(new Date(e.stop.at),m)}, by you from the Canvas, ${e.stop.until?`until ${$t(new Date(e.stop.until),m)}`:"until you resume it"}. An agent that needs a page asks you in its chat.`}):null,t.jsx(rt,{title:"Browsers and apps",flush:!0,children:t.jsxs("div",{className:"ui-list",children:[t.jsx(L9,{data:e,busy:i,run:d}),h?t.jsx(F9,{settings:h,learned:p,busy:i||!e.enabled,save:f,zone:m}):null,g&&h?t.jsx(_9,{route:x,settings:h,busy:i||!e.enabled,save:f,run:d,onSettings:()=>a(pr(x.provider||"computer"))}):null]})}),!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,y.length>0?t.jsx(rt,{title:"Looking now",flush:!0,actions:t.jsx(E,{size:"sm",disabled:i,onClick:()=>void d(()=>T.browserControl("stop")),children:"Stop agents’ browsing"}),children:t.jsx("div",{className:"ui-list",children:y.map(w=>{var N;return t.jsxs("a",{className:"ui-list-row",href:lt(w.session.agentId,w.session.conversationId,"browser"),children:[t.jsx(Rn,{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:uR(w)})]}),t.jsx("span",{className:"ui-list-side",children:"Open the Canvas"})]},w.session.id)})})}):null,h?t.jsx(z9,{settings:h,learned:p,busy:i,save:f,run:d,showApps:g}):null]})}function uR(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?Tm(e.page.appId):"an app"} · its own window`:`Looking at ${Ly((r=e.page)==null?void 0:r.url)??"a page"} · ${e.route==="chrome"?"in your Chrome · background tab":"in buddi’s browser"}`}function Ly(e){if(e)try{return new URL(e).hostname.replace(/^www\./,"")||void 0}catch{return}}function L9({data:e,busy:n,run:s}){var c,d,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=(d=a.progress)==null?void 0:d.percent;l=t.jsx(lr,{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(lr,{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(lr,{line:i,tone:"critical",status:"Linux blocks its sandbox (AppArmor). Run this once, then Check again:",children:t.jsx(I9,{text:$9})}),o=t.jsx(E,{size:"sm",disabled:n,onClick:()=>void s(()=>T.browserCheck()),children:"Check again"})):r!=null&&r.problem?(l=t.jsx(lr,{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(Ce,{tone:"good",dot:!0,children:"ready"}):null);return t.jsxs("div",{className:"ui-list-row",children:[t.jsx(Dy,{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 cS=1e4;async function dS(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>=-cS&&r-i<=cS))throw s}hR()}function hR(){if(typeof window>"u")return;const e=window.location.hash,n=S6(e);if(n!==e)try{window.history.replaceState(window.history.state,"",`${window.location.pathname}${window.location.search}${n}`)}catch{}}function F9({settings:e,learned:n,busy:s,save:r,zone:a}){var L,Q,F,ae,V,J,H,X,G,ce;const i=pe(()=>T.extension(),[],3e3),l=pe(()=>K9(),[],3e3).data??null,o=$m(),[c,d]=u.useState(()=>eN(typeof window>"u"?"":window.location.hash)??"");u.useEffect(()=>{const xe=()=>{const De=eN(window.location.hash);De&&d(De)};return window.addEventListener("hashchange",xe),()=>window.removeEventListener("hashchange",xe)},[]);const[h,f]=u.useState(!1),[m,p]=u.useState(null),[x,g]=u.useState(!1),[y,j]=u.useState(!1),v=O9(i.data,l),w=V9(),N=async xe=>{f(!0),p(null);try{await xe()}catch(De){p(De instanceof Error?De.message:String(De))}finally{f(!1),i.reload()}},k=(L=i.data)!=null&&L.pending&&(l==null?void 0:l.state)==="pairing"?l.code??"":"",S=u.useRef("");u.useEffect(()=>{!k||S.current===k||h||(S.current=k,N(async()=>{await T.pairExtension(k),hR()}))},[k]);const b=s||h,C=(Q=i.data)!=null&&Q.pairedAt?`paired ${ft(i.data.pairedAt,a)}`:null,$=(l==null?void 0:l.version)??((F=i.data)==null?void 0:F.extension),A=t.jsx(Qn,{label:"More for your Chrome",items:[C||v==="broken"||v==="notrunning"||v==="connected"?{label:"Pair again",hint:[$?`Extension ${$}`:null,C].filter(Boolean).join(" · ")||void 0,onSelect:()=>void N(()=>T.forgetExtension())}:null,(ae=i.data)!=null&&ae.checkout?{label:"Install unpacked…",hint:"For a developer build of the extension",onSelect:()=>j(!0)}:null,(V=i.data)!=null&&V.pairedAt?"separator":null,(J=i.data)!=null&&J.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=>d(xe.target.value),onKeyDown:xe=>{xe.key==="Enter"&&c.replace(/[^0-9]/g,"").length===6&&!b&&N(async()=>{await dS(c),d("")})}}),t.jsx(E,{size:"sm",variant:"accent",disabled:b||c.replace(/[^0-9]/g,"").length!==6,onClick:()=>void N(async()=>{await dS(c),d("")}),children:"Pair"})]}),M=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 ${R9(O)}`:null;let _,z;if(v==="none")_=t.jsx(lr,{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:M}),z=t.jsxs(t.Fragment,{children:[w==="chromium"?t.jsxs(st,{size:"sm",variant:"accent",href:fR,target:"_blank",rel:"noopener noreferrer",children:["Add to Chrome ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):null,A]});else if(v==="pair"){const xe=l?`Extension ${l.version} found in Chrome`:"The buddi extension asks to pair";_=k?t.jsx(lr,{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:k.replace(/^(\d{3})(\d{3})$/,"$1 · $2")})}):(H=i.data)!=null&&H.pending?t.jsx(lr,{line:xe,status:"Type the six digits the extension shows.",children:I}):t.jsx(lr,{line:xe,status:"Open the extension and press Connect: it shows a code, and this page pairs with it.",children:M}),z=A}else if(v==="broken")_=t.jsx(lr,{line:"Used only for sites that need your sign-in",tone:"critical",status:"Chrome forgot the pairing, so agents use their own browser instead."}),z=t.jsxs(t.Fragment,{children:[t.jsx(E,{size:"sm",variant:"accent",disabled:b,onClick:()=>void N(()=>T.forgetExtension()),children:"Pair again"}),A]});else{const xe=e.yourChrome?v==="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.";_=R&&e.yourChrome?t.jsx(lr,{line:xe,status:R}):xe,z=t.jsxs(t.Fragment,{children:[e.yourChrome?v==="notrunning"?t.jsx(Ce,{children:"Chrome closed"}):t.jsx(Ce,{tone:"good",dot:!0,children:"connected"}):null,t.jsx(Wd,{checked:e.yourChrome,label:"Let agents use your Chrome",disabled:b,onChange:De=>r({yourChrome:De})}),A]})}const U=l&&((X=i.data)!=null&&X.extensionMinimum)&&H9(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,P=l&&!mR(l.gateway)?`The extension is pointed at ${l.gateway}; set it to ${window.location.origin} in its popup.`:null,W=(G=i.data)!=null&&G.portMoved&&v!=="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 W&&v!=="broken"&&v!=="none"&&(z=t.jsxs(t.Fragment,{children:[t.jsx(E,{size:"sm",variant:"accent",disabled:b,onClick:()=>void N(()=>T.forgetExtension()),children:"Pair again"}),A]})),t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"ui-list-row",children:[t.jsx(Dy,{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:[_,U?t.jsx("span",{className:"pl-row-status","data-tone":"warning",children:U}):null,P?t.jsx("span",{className:"pl-row-status","data-tone":"warning",children:P}):null,W?t.jsx("span",{className:"pl-row-status","data-tone":"warning",children:W}):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:z})})]}),x?t.jsx("div",{className:"br-confirm",children:t.jsx(q,{tone:"warning",action:t.jsxs(se,{align:"end",children:[t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>g(!1),children:"Cancel"}),t.jsx(E,{size:"sm",variant:"danger",disabled:b,onClick:()=>{g(!1),N(()=>T.forgetExtension())},children:"Forget"})]}),children:"Forget this Chrome? Agents stop using it until you pair it again."})}):null,y?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(_t,{label:"The unpacked extension",children:((ce=i.data)==null?void 0:ce.path)??"…"})]}):null]})}function _9({route:e,settings:n,busy:s,save:r,run:a,onSettings:i}){const l=n.yourApps!=="off",o=`From the ${e.label??Tm(e.provider.replace(/^@withbuddi\/plugin-/,""))} plugin`,c=l&&!e.available&&!!e.message,d=c?t.jsx(lr,{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(Dy,{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:d})]}),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(Ce,{tone:"good",dot:!0,children:"ready"}):null,c&&e.repair==="permissions"?null:t.jsx(Wd,{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 z9({settings:e,learned:n,busy:s,save:r,run:a,showApps:i}){var S;const l=pe(()=>T.agents(),[]),o=((S=l.data)==null?void 0:S.engines)??[],c=o.filter(b=>b.browser&&b.browser!=="auto"),d=o.filter(b=>!b.browser||b.browser==="auto"),[h,f]=u.useState(!1),[m,p]=u.useState(""),[x,g]=u.useState("own"),[y,j]=u.useState(""),v=(b,C)=>void a(async()=>{await T.setAgentEngine(b,{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((b,C)=>b-C),k=()=>{const b=y.trim().toLowerCase().replace(/^https?:\/\//,"").replace(/\/.*$/,"").replace(/^www\./,"");if(!b||e.signInSites.includes(b)||n.includes(b)){j("");return}r({signInSites:[...e.signInSites,b]}),j("")};return t.jsx(Kt,{boxed:!0,summary:"Advanced",children:t.jsxs("div",{className:"br-adv",children:[t.jsx(Pu,{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(Jt,{label:"First choice for every agent",value:w,onChange:b=>r({defaultRoute:b}),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(b=>t.jsxs("div",{className:"ui-list-row",children:[t.jsx(Rn,{id:b.id,name:b.name,size:"sm"}),t.jsx("span",{className:"ui-list-main",children:t.jsx("span",{className:"ui-list-title",children:b.name})}),t.jsxs("span",{className:"ui-list-side",children:[t.jsx(Rv,{value:b.browser??"auto",label:`Where ${b.name} may look`,apps:i,disabled:s,onChange:C=>v(b.id,C)}),t.jsx(E,{size:"sm",variant:"ghost",disabled:s,onClick:()=>v(b.id,"auto"),children:"Remove"})]})]},b.id))}):t.jsx("p",{className:"br-adv-empty",children:"No agent has its own rule. Every agent follows the first choice."}),h?t.jsxs(se,{children:[t.jsxs("select",{className:"br-select","aria-label":"Agent",value:m,onChange:b=>p(b.target.value),children:[t.jsx("option",{value:"",children:"Choose an agent"}),d.map(b=>t.jsx("option",{value:b.id,children:b.name},b.id))]}),t.jsx(Rv,{value:x,label:"Its rule",apps:i,onChange:g}),t.jsx(gt,{}),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||x==="auto",onClick:()=>{v(m,x),f(!1),p("")},children:"Add"})]}):t.jsx(se,{children:t.jsxs(E,{size:"sm",disabled:d.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(b=>t.jsxs("span",{className:"br-site-chip mono",children:[b,t.jsx("button",{type:"button","aria-label":`Remove ${b}`,disabled:s,onClick:()=>r({forgetSignInSite:b}),children:"×"})]},b)),n.map(b=>t.jsxs("span",{className:"br-site-chip mono","data-learned":"true",title:"buddi added this when it met its sign-in page",children:[b,t.jsx("button",{type:"button","aria-label":`Remove ${b}`,disabled:s,onClick:()=>r({forgetSignInSite:b}),children:"×"})]},b))]}):t.jsx("p",{className:"br-adv-empty",children:"None yet."}),t.jsxs("form",{className:"br-site-add",onSubmit:b=>{b.preventDefault(),k()},children:[t.jsx("input",{"aria-label":"A site that needs your sign-in",placeholder:"amazon.com",value:y,onChange:b=>j(b.target.value)}),t.jsx(E,{size:"sm",type:"submit",disabled:s||!y.trim(),children:"Add"})]})]}),t.jsx(Pu,{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(Jt,{label:"Stop agents’ browsing lasts",value:e.stopExpiryMinutes===0?"until":"hour",onChange:b=>r({stopExpiryMinutes:b==="until"?0:60}),options:[{value:"hour",label:"An hour"},{value:"until",label:"Until I say"}]})}),t.jsx(Pu,{label:"Pages open at once",hint:"In buddi’s own browser. One more waits its turn; nothing is refused.",children:t.jsx(Jt,{label:"Pages open at once",value:String(e.maxOwnPages),onChange:b=>r({maxOwnPages:Number(b)}),options:N.map(b=>({value:String(b),label:String(b)}))})}),t.jsx(Pu,{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(Wd,{checked:e.showWindow,label:"Show buddi’s browser as a window",disabled:s,onChange:b=>r({showWindow:b})})}),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 U9="kmbckpnnjfggeffkkbmkggojnolkdokb",B9="pbfpjefkiijjgefblpnlnlpmeaddfbah",fR="https://chromewebstore.google.com/detail/pbfpjefkiijjgefblpnlnlpmeaddfbah",W9=[U9,B9].filter(Boolean);function H9(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 K9(){var e;try{if(typeof chrome>"u"||!((e=chrome==null?void 0:chrome.runtime)!=null&&e.sendMessage))return null;for(const n of W9)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 V9(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 mR(e){try{return new URL(e).origin===window.location.origin}catch{return!1}}const uS=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 G9(e){const n=e.toLowerCase().replace(/\.$/,"");if(!n.includes(".")||uS.has(n))return!0;const s=n.slice(n.indexOf(".")+1);return uS.has(`*.${s}`)}function q9(e){return typeof e=="string"&&e.includes("*")}function Y9(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"}:G9(i)?{ok:!1,reason:"public-suffix"}:{ok:!0,value:{pattern:`${a.protocol}//*.${a.host}`,protocol:a.protocol,suffix:i,port:a.port}}}const hS=["every-time","first-time","pre-approved"];function pR(e){const n=hS.indexOf(e);return hS.slice(0,n<0?1:n+1)}function ll(e){return e.endsWith(".account")}const Q9="Stored, not usable until it has a binding.";function J9(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":ll(e)?"the account id, e.g. acct-1":'the place, as JSON — e.g. {"host":"localhost","header":"Authorization"}'}const gR={"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})}},X9="A wildcard may only stand for the leftmost part of a site, like *.wikimedia.org.",Z9=e=>`That is a public suffix; ${e} would match every site.`,fS="Give the site as an origin, like https://en.wikipedia.org.";function mS(e){const n=/^[a-z][a-z0-9+.-]*:\/\//i.test(e)?e:["https:","//",e].join("");if(q9(e)){const s=Y9(n);if(s.ok)return{ok:!0,target:s.value.pattern};if(s.reason==="placement")return{ok:!1,error:X9};if(s.reason==="public-suffix"){const r=n.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/[/?#:].*$/,"").toLowerCase();return{ok:!1,error:Z9(r)}}return{ok:!1,error:fS}}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:fS}}}function eV(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 tV(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 mS(s);if(e==="browser.native.type"||ll(e))return{ok:!0,target:s};const r=gR[e];if(r===void 0)return{ok:!0,target:s};const a=eV(s);if(a===null)return{ok:!1,error:`${e} needs both: ${r.hint}.`};if(e==="browser.form.data"){const i=mS(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 nV(e){if(typeof e=="string")return e;try{return JSON.stringify(e)??""}catch{return""}}function xR(e,n){if(typeof n=="string")return n;if(n!==null&&typeof n=="object"&&!Array.isArray(n)){const s=n,r=gR[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 Do="accounts.provider";function vR(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 jR(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 sV(e){const n=vR(e,"found");return n.length?`The value already sits in ${jR(n)}.`:""}function rV(e){const n=vR(e,"scrubbed");return n.length?`Replaced with ‹secret:…› in ${jR(n)}.`:""}const aV=/^(PROVIDER_ACCOUNT_|CODEX_ACCOUNT_|ANTHROPIC_ACCOUNT_|OLLAMA_DEVICE_)/,iV=/^MCP_(TOKEN|ENV|CONNECTION)_/,wR="GMAIL_APP_PASSWORD";function Na(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===wR)return"mail";if(n.some(r=>r.kind==="model-account")||s.includes(Do)||aV.test(e.name))return"models";if(n.some(r=>r.kind==="connection")||s.includes("mcp.env")||iV.test(e.name))return"connections";for(const r of e.bindings){if((r.kind==="http.url"||r.kind==="http.basic"||r.kind==="http.bearer")&&Fy(r.target)&&typeof r.target.plugin=="string")return`plugin:${r.target.plugin}`;if(ll(r.kind))return`plugin:${r.kind.slice(0,-8)}`}return"mine"}function lV(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 oV(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 yR(e){return e==="models"||e==="connections"}function Fy(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function pS(e){const n=e.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/\/.*$/,"").replace(/^www\./,"");return n.startsWith("*.")?`any ${n.slice(2)} site`:n}const _y=e=>(e.usedBy??[]).flatMap(n=>n.kind==="mailbox"?[n]:[]),Im=e=>(e.usedBy??[]).find(n=>n.kind==="model-account"),zy=e=>(e.usedBy??[]).find(n=>n.kind==="connection");function Ac(e,n=new Map){var r,a;const s=Na(e);if(s==="mail"){const i=_y(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=Im(e),l=(i==null?void 0:i.id)??((r=e.bindings.find(c=>c.kind===Do&&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=zy(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 bR(e){const n=e.indexOf("@");return n>0?`${e.slice(0,Math.min(n,24))}@…`:e.length>24?`${e.slice(0,23)}…`:e}function cV(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 dV(e,n){const s=e.login;if(!s)return null;const r=cV(s.savedAt,n);return[s.username?`for ${bR(s.username)}`:null,r?`saved ${r}`:null].filter(Boolean).join(" · ")}function uV(e,n){var r,a,i;if(Na(e)!=="models")return null;const s=((r=Im(e))==null?void 0:r.id)??((a=e.bindings.find(l=>l.kind===Do&&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 kR(e,n){const s=Fy(n)?n:{},r=a=>typeof s[a]=="string"?s[a]:"";return e==="browser.field"&&typeof n=="string"?`Filled on ${pS(n)}`:e==="browser.form.data"&&r("origin")?`Filled into “${r("field")}” on ${pS(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===Do?"Used by a model account":ll(e)?`Used by a ${e.slice(0,-8)} account`:`Goes to ${xR(e,n)}`}function hV(e,n){return ll(e)||e===Do?"Signed in":kR(e,n).replace(/^Sent only to/,"Sent to")}const fV={"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 mV(e){return e.length<=1?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function Uy(e){const n=Na(e);if(n==="mail"){const i=_y(e).map(l=>l.address);return i.length?`Used by the ${i.length===1?"mailbox":"mailboxes"} ${mV(i)}`:e.name===wR?"From the old .env setup":"No mailbox uses it"}if(n==="models"){const i=Im(e);return i?fV[i.auth]??"Key for this model account":"No model account uses it"}if(n==="connections"){const i=zy(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&&Fy(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=>kR(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 pV(e,n=Date.now()){return e.lastUse?`Last used ${Ge(e.lastUse.at,n)}`:"Never used"}function Pv(e){return pr("email","settings",{account:e,set:"password"})}function NR(e){var s,r;const n=Na(e);if(n==="models"){const a=(s=Im(e))==null?void 0:s.id;return{label:"Managed in Model accounts",href:a?FT(a):ze("accounts")}}if(n==="connections"){const a=(r=zy(e))==null?void 0:r.id;return{label:"Managed in Connections",href:a?_T(a):ze("connections")}}return null}function SR(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 CR(e,n=Date.now()){if(e.unused)return null;const s=Na(e),r=_y(e)[0],a=NR(e),i=()=>r?{label:"Set password",href:Pv(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?Ge(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 ${Ge(r.loginFailedAt,n)}.`,fix:{label:"Set password",href:Pv(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 d=s==="mine"?SR(c):null;return{text:d?`Held back ${o}: it was asked for at ${d}, 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}: ${AR(c||null)}.`,fix:null}}if((l==null?void 0:l.outcome)==="failed"){const d=r?i():a?null:{label:"Replace value",action:"replace"};return{text:`Didn’t go through ${o}${c?`: ${c.replace(/\.$/,"")}`:""}.`,fix:d}}return(l==null?void 0:l.outcome)==="pending"?{text:`Waiting for your approval since ${o}.`,fix:{label:"Review",href:ao}}: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 ER(e){if(!e.unused)return"";const n=Na(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 Mv(e){return e.usageUnknown&&!e.unused?"Couldn’t check what uses it just now.":""}function Fl(e){return!!e.unused&&!yR(Na(e))}function gV(e){if(e.unused||e.bindings.length===0)return"Nothing uses it, so nothing stops working.";const n=Uy(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 xV={"every-time":"Every time","first-time":"The first time, then not again","pre-approved":"Never — allowed ahead of time"};function vV(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",[Do]:"A model account"};return n[e]?n[e]:ll(e)?`A ${e.slice(0,-8)} account`:e}const jV={"every-time":"Every time","first-time":"The first time","pre-approved":"Never"};function AR(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)?SR(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 wV(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":ll(e)?"acct-1":'{"host":"localhost","header":"Authorization"}'}function uf(e){return pR(e).includes("first-time")?"first-time":e}function yV(e){const n=hV(e.kind,e.target);return e.outcome==="refused"?{text:`Held back — ${AR(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 bV=2*6e4,kV=2e3;function NV({login:e,onDone:n}){const[s,r]=u.useState(!1),[a,i]=u.useState(null),[l,o]=u.useState(!1);u.useEffect(()=>{o(!1),i(null);const f=window.setTimeout(n,bV);return()=>window.clearTimeout(f)},[e.id]),u.useEffect(()=>{if(!l)return;const f=window.setTimeout(n,kV);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)}},d=e.update===!0;if(l)return t.jsxs(q,{tone:"good",role:"status",title:d?`Updated the login for ${e.site}`:`Saved the login for ${e.site}`,children:["Agents can sign in there now without seeing it. It’s under ",t.jsx("a",{className:"wb-link",href:ze("secrets"),children:"Keys and secrets"}),"."]});const h=e.username?`For ${bR(e.username)}. `:"";return t.jsxs("section",{className:"br-login","data-testid":"save-login","aria-label":d?"Update this login":"Save this login",children:[t.jsx(q,{tone:"accent",role:"status",title:d?`Update the login for ${e.site}?`:`Save this login for ${e.site}?`,action:t.jsxs(se,{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:d?"Update":"Save"})]}),children:d?`${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 SV=2e3,CV=5,EV="(hover: none) and (pointer: coarse)",Ov="buddi:browser-enlarge",AV=8e3,$V="https:";function TV(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:`${$V}//${n}`;try{const r=new URL(s);return r.protocol==="https:"||r.protocol==="http:"?r.toString():null}catch{return null}}function IV(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 gS(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 RV(e){var s,r,a;return(e==null?void 0:e.route)==="apps"&&((s=e.page)!=null&&s.appId)?Tm(e.page.appId).charAt(0).toUpperCase():(Ly((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 PV({status:e,error:n,reload:s,live:r,agentName:a="The agent",timezone:i,paused:l=null}){var Sn,Vt,Un,Pn,Mn,gn,xn,It,Ae,Ze,Re,we;const o=i??Intl.DateTimeFormat().resolvedOptions().timeZone,[c,d]=u.useState(0),[h,f]=u.useState(0),m=h>=CV;u.useEffect(()=>{if(!r||m)return;const Y=window.setInterval(()=>{typeof document<"u"&&document.hidden||d(Le=>Le+1)},SV);return()=>window.clearInterval(Y)},[r,m]);const p=u.useRef(null);r&&(e!=null&&e.session)&&(p.current=e);const[x,g]=u.useState(null);u.useEffect(()=>{!r&&p.current&&x===null&&g(Date.now()),r&&g(null)},[r]);const[y,j]=u.useState(null),v=u.useRef(null),w=((Sn=e==null?void 0:e.page)==null?void 0:Sn.id)??null;u.useEffect(()=>{const Y=r&&e?gS(e):null;if(!Y||typeof fetch!="function"||typeof(URL==null?void 0:URL.createObjectURL)!="function")return;let Le=!1;return(async()=>{try{const Ct=await fetch(Y);if(!Ct.ok||Le)return;const on=await Ct.blob();if(Le)return;const Te=URL.createObjectURL(on);v.current&&URL.revokeObjectURL(v.current),v.current=Te,j(Te)}catch{}})(),()=>{Le=!0}},[r,w]),u.useEffect(()=>()=>{v.current&&typeof(URL==null?void 0:URL.revokeObjectURL)=="function"&&URL.revokeObjectURL(v.current)},[]);const N=p.current,k=r?e:N??e,[S,b]=u.useState(!1),[C,$]=u.useState(null),[A,I]=u.useState(null),[M,O]=u.useState(!1),[R,_]=u.useState(null),[z,U]=u.useState(!1),P=$m(),W=Gn(EV),L=u.useRef(null),[Q,F]=u.useState(null),ae=u.useRef(null),V=k==null?void 0:k.session,J=async Y=>{b(!0),$(null);try{await Y()}catch(Le){$(Le instanceof Error?Le.message:String(Le))}finally{b(!1),s()}},H=()=>void J(async()=>{var Ct;_(null),U(!1);const Y=V==null?void 0:V.id;Y&&(ae.current=Y);const Le=await T.browserControl("takeover",Y);((Ct=Le.held)==null?void 0:Ct.where)!=="chrome"&&(Le.hand&&Le.session&&(!Y||Le.session.id===Y)?I(Le.session.id):Le.handReason==="browser-offline"?U(!0):_(Le.handMessage??null))}),X=()=>void J(async()=>{I(null),O(!1),await T.browserControl("resume",V==null?void 0:V.id)}),G=()=>void J(async()=>{I(null),await T.browserControl("stop",V==null?void 0:V.id)}),ce=()=>void J(async()=>{V&&(await T.browserPin(V.conversationId,"own"),await T.browserControl("release",V.id),U(!1),_("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",De=xe&&((Vt=e==null?void 0:e.held)==null?void 0:Vt.where)==="chrome",B=xe&&!De&&A&&((Un=e==null?void 0:e.session)==null?void 0:Un.id)===A?A:null,ne=xe?((Pn=e==null?void 0:e.session)==null?void 0:Pn.id)??null:null;u.useEffect(()=>{!ne||A===ne||W||S||(e==null?void 0:e.route)==="apps"||De||ae.current!==ne&&H()},[ne,A,W]),u.useEffect(()=>{xe||(ae.current=null)},[xe]);const[Z,ve]=u.useState(!1);u.useEffect(()=>{const Y=()=>ve(!0);return window.addEventListener(Ov,Y),()=>window.removeEventListener(Ov,Y)},[]),u.useEffect(()=>{if(!Z)return;const Y=Le=>{Le.key==="Escape"&&!Le.defaultPrevented&&ve(!1)};return window.addEventListener("keydown",Y),()=>window.removeEventListener("keydown",Y)},[Z]);const[$e,Se]=u.useState(null),[me,Ee]=u.useState(!1);u.useEffect(()=>{Se(null),Ee(!1)},[B]),u.useEffect(()=>{if(!me)return;const Y=window.setTimeout(()=>Ee(!1),AV);return()=>window.clearTimeout(Y)},[me]);const Pe=Y=>{Se(Y),Ee(!1)},Me=(Y,Le)=>{var Ct;$(null),(Ct=L.current)!=null&&Ct.nav(Y,Le)&&Ee(!0)},he=xe,ke=r&&!!(k!=null&&k.needsOwner),Be=!r&&!l,qe=Ly((Mn=k==null?void 0:k.page)==null?void 0:Mn.url)??((gn=k==null?void 0:k.page)!=null&&gn.appId?Tm(k.page.appId):"the page"),at=(k==null?void 0:k.route)==="chrome"?"in your Chrome · background tab":(k==null?void 0:k.route)==="apps"?`in ${qe}`:"in buddi’s browser",le=l?"Browsing is paused":((xn=k==null?void 0:k.page)==null?void 0:xn.title)||qe,ye=l?`By you at ${$t(new Date(l.at),o)} · ${l.until?`until ${$t(new Date(l.until),o)}`:"until you resume it"}`:De?"You have the page · in your Chrome · it’s in front":he?`You have the page · ${at}`:Be?`${a} looked at ${qe} · done${x?` at ${$t(new Date(x),o)}`:""}`:k?uR(k):"Opening the page…",et=r?k?gS(k,c):null:y,pt=(k==null?void 0:k.route)==="apps",kt=B?$e??((It=k==null?void 0:k.page)==null?void 0:It.url):(Ae=k==null?void 0:k.page)==null?void 0:Ae.url,Ot=r&&(me||!he&&!!(e!=null&&e.busy)),Ut=k||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:()=>ve(!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(OV,{}):RV(k)}),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&&!ke&&!he&&!l?t.jsx("span",{className:"br-live","aria-hidden":"true"}):null,ye]})]}),he?t.jsxs(se,{align:"end",children:[De?null:B?W?t.jsx(E,{size:"sm",variant:M?"accent":"ghost","aria-pressed":M,onClick:()=>O(!M),children:"Type into the page"}):null:t.jsx(E,{size:"sm",variant:"ghost",disabled:S,onClick:H,children:"Drive it here"}),t.jsx(E,{size:"sm",variant:"accent",disabled:S,onClick:X,children:"Give it back"}),Ut]}):l?t.jsx(E,{size:"sm",variant:"accent",disabled:S,onClick:()=>void J(async()=>{await T.browserControl("resume")}),children:"Resume"}):Be||!V?Ut?t.jsx(se,{align:"end",children:Ut}):null:t.jsxs(se,{align:"end",children:[t.jsx(E,{size:"sm",disabled:S||!(k!=null&&k.enabled),onClick:G,children:"Stop"}),t.jsx(E,{size:"sm",variant:ke?"accent":void 0,disabled:S||!(k!=null&&k.enabled)||(k==null?void 0:k.state)==="paused",onClick:H,children:"Take over"}),Ut]})]}),he?t.jsx("p",{className:"br-hand-said",role:"status",children:De?"Finish in Chrome, then give it back.":B?`Nothing you type here is kept. ${a} carries on when you give it back.${W?" 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,z?t.jsx(q,{tone:"warning",role:"status",title:"Your Chrome isn’t connected.",action:t.jsxs(se,{align:"end",children:[t.jsx(E,{size:"sm",disabled:S,onClick:ce,children:"Use buddi’s browser"}),t.jsx(E,{size:"sm",variant:"accent",disabled:S,onClick:H,children:"Try again"})]}),children:`Open Chrome on ${P} and try again, or let this conversation use buddi’s own browser.`}):null,Q?t.jsx(NV,{login:Q,onDone:()=>F(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 ${$t(new Date(l.until),o)}`:""}.`})}):t.jsxs("div",{className:"br-window","data-state":B?"yours":ke?"waiting":Be?"done":"live",children:[t.jsx(MV,{app:pt?qe:null,title:((Ze=k==null?void 0:k.page)==null?void 0:Ze.title)||void 0,address:kt,held:!!B,loading:Ot,onNav:Me,onRefused:Y=>$(Y)}),B?t.jsx("div",{className:"br-frame","data-state":"yours",children:t.jsx(E9,{ref:L,sessionId:B,csrf:sl(),onGiveBack:X,bare:!0,typing:M,onTyping:O,onLocation:Pe,onLoginSeen:F})}):t.jsx("div",{className:"br-frame","data-state":ke?"waiting":Be?"done":"live",children:et?t.jsx("img",{className:"br-shot",src:et,alt:`What ${a} sees: ${((Re=k==null?void 0:k.page)==null?void 0:Re.title)||qe}`,onError:()=>f(Y=>Y+1),onLoad:()=>f(0)},r?((we=k==null?void 0:k.page)==null?void 0:we.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."})})]}),Be?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 MV({app:e,title:n,address:s,held:r,loading:a,onNav:i,onRefused:l}){const[o,c]=u.useState(null),[d,h]=u.useState(!1);u.useEffect(()=>{c(null)},[s,r]),u.useEffect(()=>{if(!d)return;const g=window.setTimeout(()=>h(!1),1500);return()=>window.clearTimeout(g)},[d]);const f=IV(s),m=()=>{var g;s&&((g=navigator.clipboard)==null||g.writeText(s).then(()=>h(!0),()=>{}))},p=g=>{var j,v;if(g.preventDefault(),o===null)return;const y=TV(o);if(!y){l("That isn’t a web address. Type one like amazon.com/orders.");return}c(null),i("navigate",y),(v=(j=document.activeElement)==null?void 0:j.blur)==null||v.call(j)},x=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(xS,{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:x}),t.jsx("button",{type:"button",className:"br-address-copy","aria-label":d?"Copied":"Copy the address",title:d?"Copied":"Copy the address",disabled:!s,onClick:m,children:t.jsx(ie,{name:d?"check":"copy",size:14})})]}):t.jsxs("button",{type:"button",className:"br-address","aria-label":d?"Address copied":"Copy the address",title:d?"Copied":"Copy the address",disabled:!s,onClick:m,children:[t.jsx(xS,{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"})}),d?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 xS({secure:e}){return t.jsx("span",{className:"br-address-mark","aria-hidden":"true",children:t.jsx(ie,{name:e?"lock":"globe",size:12})})}function OV(){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 DV({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=$t(new Date(Date.now()+(a||60)*6e4),r),l=c=>void c().catch(()=>{}).finally(s);return t.jsx(Qn,{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(Ov))}}]})}function LV({agentId:e,conversationId:n}){const{data:s,error:r,reload:a}=pe(()=>T.host(e,n),[e,n],2e3),[i,l]=u.useState(null),[o,c]=u.useState(!1),d=async p=>{c(!0),l(null);try{await p(),a()}catch(x){l(x instanceof Error?x.message:String(x))}finally{c(!1)}},h=(s==null?void 0:s.permissions)??[],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(Kt,{className:"host-controls",summary:`Host execution · ${r?"Status unavailable":m}${f.length?` · ${f.length} running`:""}`,children:t.jsxs(de,{gap:"sm",children:[t.jsx("p",{className:"muted",children:"Commands run as your user, not in a sandbox. Auto-mode covers all commands within its scope. Stop interrupts a command; revoke also ends the permission. Neither undoes completed changes."}),t.jsx(re,{message:i??r}),h.map(p=>t.jsxs(se,{children:[t.jsxs("span",{children:[p.agentId,": ",p.conversationId?"conversation auto-mode":"always allowed"]}),t.jsx(E,{size:"sm",disabled:o,onClick:()=>void d(()=>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(de,{gap:"sm",children:[t.jsxs("p",{children:[p.agentId," · ",t.jsx("span",{className:"mono",children:p.cwd})]}),t.jsx(_t,{children:p.command}),t.jsx(_t,{label:"Command output",children:p.stdout||p.stderr?`${p.stdout}
117
+ ${p.stderr}`:"Waiting for output…"}),t.jsx(se,{children:t.jsx(E,{size:"sm",variant:"danger",disabled:o,onClick:()=>void d(()=>T.stopHost(p.agentId,p.conversationId)),children:"Stop command"})})]},p.actionId))]})})}const FV="browser.act",_V="browser.status",hh=new Set([FV,_V]);function zV(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 UV(e,n){return{...e,title:"Page",pinned:!1}}function BV(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 vS(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=hh.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 tg="Save a login for next time",WV=new Set(["Skip this site","Skip it","Keep paused","Leave it stopped"]),HV=["Use my Chrome","Use Chrome when it’s open","Open Chrome and I'll use it there"];function Dv(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(tg,...HV)||/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===tg)??null,c=e.options.filter(h=>h.label!==tg),d=[...c.filter(h=>!h.recommended),...c.filter(h=>h.recommended)];return{kind:r,title:l,line:i.join(" ").trim(),saveLogin:o,actions:d}}function $R({card:e,disabled:n,onAnswer:s,site:r}){const a=`${Zx}${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(se,{align:"end",children:[e.saveLogin?t.jsxs(t.Fragment,{children:[t.jsx("a",{className:"wb-link",href:a,children:e.saveLogin.label}),t.jsx(gt,{})]}):null,e.actions.map(i=>t.jsx(E,{size:"sm",variant:i.recommended?"accent":WV.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 KV="web.read",VV="web.search",GV=new Set([KV,VV]),jS=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"]),wS=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 qV({agentId:e,groupId:n,currentId:s,timezone:r,onSelect:a,onNew:i}){const[l,o]=u.useState(null),[c,d]=u.useState(null),[h,f]=u.useState(0);return u.useEffect(()=>{let m=!1;return o(null),d(null),(n?Xe.groupConversations(n):Xe.conversations(e,100)).then(p=>{m||o(p.conversations)}).catch(p=>{m||d(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?$i(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:[ft(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 TR="buddi.dismissedTabs";function YV(){try{const e=JSON.parse(sessionStorage.getItem(TR)??"{}");return!e||typeof e!="object"||Array.isArray(e)?{}:Object.fromEntries(Object.entries(e).filter(([,n])=>Array.isArray(n)&&n.every(s=>typeof s=="string")))}catch{return{}}}function yS(e){try{sessionStorage.setItem(TR,JSON.stringify(Object.fromEntries(Object.entries(e).slice(-100))))}catch{}}const bS=3;function QV(e){return e.frontDesk?"the front desk":`@${e.handle}`}function kS(e){const n=e.slice(0,bS).map(QV);return e.length>bS?`${n.join(", ")}, …`:n.join(", ")}function JV(e){const n=e.asks==="everyone"?"may ask everyone":e.asks.length===0?"asks nobody yet":`may ask ${kS(e.asks)}`,s=e.askedBy.length===0?"and nobody asks it yet":`and can be asked by ${kS(e.askedBy)}`;return`New here. @${e.handle} ${n}, ${s}.`}function XV({agentId:e}){const n=pe(()=>T.agentIntro(e),[e]),[s,r]=u.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:JV(a)}),t.jsx(st,{variant:"ghost",size:"sm",href:Pt(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 Lv="​",ng=/(`[^`\n]+`)|(\*\*[^*\n]+\*\*)|(\*[^*\s][^*\n]*\*|_[^_\s][^_\n]*_)|(\[[^\]\n]+\]\([^)\s]+\))|(https?:\/\/[^\s)]+)|(@[a-z][a-z0-9-]*)/gi;function sg(e,n,s){const r=[];let a=0,i=0;ng.lastIndex=0;for(let l=ng.exec(e);l;l=ng.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 d=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,d)}),t.jsx("span",{className:"cv-mark",children:o.slice(d)})]},c))}else if(l[5])r.push(t.jsx("span",{className:"cv-link",children:o},c));else{const d=l.index>0?e[l.index-1]:" ",h=/[\s(]/.test(d)?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 ZV(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 d=s.slice(i+1).some(h=>/^```\s*$/.test(h));return t.jsxs("div",{className:"cv-line","data-code":"open","data-unclosed":d?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:D$(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||Lv})},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:sg(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],sg(c[4],n,String(i))]},i):t.jsx("div",{className:"cv-line",children:a?sg(a,n,String(i)):Lv},i)})}const By=(e,n)=>`${e}-opt-${n}`;function eG({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 d=o.group!==l?l=o.group:null;return t.jsxs(u.Fragment,{children:[d?t.jsx("div",{className:"cv-pop-group",role:"presentation",children:d}):null,t.jsxs("div",{id:By(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(Rn,{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 tG({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,d)=>{const h=c.group!==o?o=c.group:null;return t.jsxs(u.Fragment,{children:[h?t.jsx("div",{className:"cv-pop-group",role:"presentation",children:h}):null,t.jsxs("div",{id:By(e,d),role:"option","aria-selected":d===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":d===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}):d===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 nG=350,sG=60;function rG({conversationId:e,onText:n,onNotice:s}){const[r,a]=u.useState("idle"),i=u.useRef("idle"),l=v=>{i.current=v,a(v)},o=u.useRef(null),c=u.useRef(null),d=u.useRef(null),h=u.useRef(null),f=u.useRef(null),m=u.useRef({onText:n,onNotice:s,conversationId:e});m.current={onText:n,onNotice:s,conversationId:e};const p=()=>{d.current!==null&&(window.clearTimeout(d.current),d.current=null)},x=async()=>{if(i.current!=="idle")return;m.current.onNotice(null),l("starting"),c.current=null;let v;try{v=await SW(k=>{var S;return(S=f.current)==null?void 0:S.call(f,k)})}catch(k){h.current=null,l("idle"),m.current.onNotice(NW(k));return}const w=c.current;c.current=null;const N=i.current;if(w==="discard"||N!=="starting"){v.cancel(),N==="starting"&&l("idle");return}o.current=v,l("recording"),d.current=window.setTimeout(()=>void g(!1),yW),w&&g(w.sendNow)},g=async v=>{h.current=null;const w=o.current;if(!w){i.current==="starting"&&(c.current={sendNow:v});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 k=new File([N],`recording-${new Date().toISOString().slice(0,19).replace(/[:T]/g,"-")}.wav`,{type:"audio/wav"}),S=await Xe.attach(k),b=m.current.conversationId,C=await Xe.transcribe({artifactId:S.artifactId,...b?{conversationId:b}:{}});m.current.onText(C.text,v)}catch(N){m.current.onNotice(N instanceof fe||N instanceof Error?N.message:String(N))}finally{l("idle")}},y=()=>{h.current=null;const v=o.current;if(!v){i.current==="starting"&&(c.current="discard");return}o.current=null,p(),v.cancel(),l("idle")};u.useEffect(()=>{const v=w=>{if(h.current===null)return;const N=Date.now()-h.current;h.current=null,N>=nG&&g(w.shiftKey)};return window.addEventListener("pointerup",v),()=>window.removeEventListener("pointerup",v)},[]);const j=r==="starting"||r==="recording";return u.useEffect(()=>{if(!j)return;const v=w=>{w.isComposing||w.repeat||(w.key==="Escape"?(w.preventDefault(),w.stopPropagation(),y()):w.key==="Enter"&&(w.preventDefault(),w.stopPropagation(),g(w.shiftKey)))};return window.addEventListener("keydown",v,!0),()=>window.removeEventListener("keydown",v,!0)},[j]),u.useEffect(()=>()=>{var v;(v=o.current)==null||v.cancel(),p()},[]),{state:r,hold:()=>{h.current=Date.now(),x()},start:()=>{h.current=null,x()},finish:v=>void g(v),discard:y,levels:f}}function aG({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 iG({voice:e}){const n=u.useRef(null),s=e.state==="transcribing";return u.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(lG,{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 lG({sink:e,frozen:n}){const[s,r]=u.useState(()=>Array(sG).fill(0));return u.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 oG="This browser cannot capture a tab. Chrome, Safari and Firefox can, on a secure address.",Mu="The tab could not be captured. Try again, and pick the tab itself rather than the whole screen.",cG=e=>e instanceof Error&&(e.name==="NotAllowedError"||e.name==="AbortError");async function dG(e={}){var r;const n=e.media??(typeof navigator>"u"?void 0:navigator.mediaDevices);if(!n||typeof n.getDisplayMedia!="function")throw new Error(oG);let s;try{s=await n.getDisplayMedia({video:{displaySurface:"browser"},audio:!1,selfBrowserSurface:"exclude",surfaceSwitching:"exclude",preferCurrentTab:!1})}catch(a){if(cG(a))return null;throw new Error(Mu)}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(Mu))}),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(Mu);o.drawImage(i,0,0);const c=await new Promise(h=>l.toBlob(h,"image/png"));if(!c)throw new Error(Mu);const d=(((r=e.now)==null?void 0:r.call(e))??new Date).toISOString().slice(0,19).replace("T"," ").replace(/:/g,".");return new File([c],`Tab ${d}.png`,{type:"image/png"})}finally{s.getTracks().forEach(a=>a.stop())}}const NS="Send files once the agent has answered.",Fv="wb-composer-input",uG="(max-width: 720px)",SS={desk:288,phone:240};function hG(e,n,s){const[r,a]=u.useState(void 0);return u.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),d=Math.floor(c-(s?16:64)),h=s?SS.phone:SS.desk;a(d>0&&d<h?Math.max(d,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 Wy=u.forwardRef(function({disabled:n,running:s,onSend:r,onStop:a,agentName:i,draft:l,model:o,chrome:c,setupHref:d,thinking:h,onThinking:f,onOpenFile:m,mentions:p,team:x,onCommand:g,history:y,threadKey:j,conversationId:v,readAloud:w,onReadAloud:N,placeholder:k,slim:S},b){var Dn,Qd,dl;const C=j?`buddi.draft.${j}`:null,$=K=>{if(!K)return"";try{return window.localStorage.getItem(K)??""}catch{return""}},[A,I]=u.useState(()=>$(C)),[M,O]=u.useState(()=>A.length),[R,_]=u.useState([]),[z,U]=u.useState(!1),[P,W]=u.useState(null),[L,Q]=u.useState(!1),[F,ae]=u.useState(null),V=u.useRef(null),J=u.useRef(null),H=u.useRef(null),X=Gn(uG),G=`cv-pop-${u.useId().replace(/[^a-zA-Z0-9_-]/g,"")}`,ce=uF(),xe=u.useMemo(()=>{const K=Ve=>x==null?void 0:x.agents.find(cn=>cn.id===Ve),Ue=(Ve,cn)=>Qi(Io(Ve??{id:cn}));if(p)return p.map(Ve=>{const cn=Ve.id??Ve.handle,Jn=K(cn);return{id:cn,handle:Ve.handle,name:Ve.name,effect:`Asks @${Ve.handle} in this room`,group:"In this room",accent:Ue(Jn,cn),...Jn?{face:Jn}:{}}});if(!x)return[];const He=x.agents.find(Ve=>Ve.roles.includes(gr)&&Ve.id!==x.selfId),Dt=x.agents.filter(Ve=>Ve.id!==x.selfId&&Ve!==He);return[...He?[{id:He.id,handle:He.handle,name:He.name,effect:`Borrows ${He.name} for this message`,group:"Borrow",accent:Qi({key:"buddi"}),face:He}]:[],...Dt.map(Ve=>({id:Ve.id,handle:Ve.handle,name:Ve.name,effect:`${i} asks @${Ve.handle}`,group:"Ask a teammate",accent:Ue(Ve,Ve.id),face:Ve}))]},[p,x,i]),De=!p&&x?((Dn=x.agents.find(K=>K.roles.includes(gr)&&K.id!==x.selfId))==null?void 0:Dn.handle)??null:null,[B,ne]=u.useState(!1),[Z,ve]=u.useState(0),$e=!!g,Se=$e&&xz(A,M),me=!B&&xe.length>0?pz(A,M):null,Ee=!B&&$e&&!me?gz(A,M):null,Pe=me?xe.filter(K=>!Se||K.group!=="Borrow").filter(K=>K.handle.toLowerCase().startsWith(me.query.toLowerCase())||K.name.toLowerCase().startsWith(me.query.toLowerCase())).map(K=>Se?{...K,group:"Talk to",effect:`Talk to ${K.name} from here on`}:K).slice(0,8):[],Me=u.useMemo(()=>[...iF(i,s),...oF(ce)],[i,s,ce]),he=Ee?Me.filter(K=>K.name.startsWith(Ee.query.toLowerCase())):[],ke=me&&Pe.length>0?"mention":Ee?"slash":null,Be=ke==="mention"?Pe:ke==="slash"?he:[],qe=Be.length>0?Math.min(Z,Be.length-1):-1,at=hG(H,ke!==null,X),le=y??[],[ye,et]=u.useState(-1),pt=u.useRef(A),kt=u.useRef(C);if(kt.current!==C){kt.current=C;const K=$(C);pt.current=K,K!==A&&(I(K),O(K.length),et(-1),ae(null))}const Ot=K=>{if(pt.current=K,!!C)try{K===""?window.localStorage.removeItem(C):window.localStorage.setItem(C,K)}catch{}},Ut=K=>{I(K.value),O(K.caret),ne(!1),ve(0),ye<0&&Ot(K.value);const Ue=J.current;Ue&&(Ue.value=K.value,Ue.setSelectionRange(K.caret,K.caret),window.requestAnimationFrame(()=>{Ue.focus(),Ue.setSelectionRange(K.caret,K.caret)}))},Sn=K=>{I(K),O(K.length),ne(!1);const Ue=J.current;Ue&&(Ue.value=K,Ue.setSelectionRange(K.length,K.length))},Vt=K=>!K.value.slice(0,K.selectionStart??K.value.length).includes(`
120
+ `),Un=()=>A===""||ye>=0&&A===le[ye],Pn=()=>{ye<0||(et(-1),Sn(pt.current))},Mn=R.some(K=>K.state==="uploading"),gn=R.length>0,xn=s&&gn,It=!n&&!Mn&&!xn&&A.trim()!=="",Ae=K=>{const Ue=[];for(const He of Array.from(K??[])){const Dt=`${He.name}:${He.size}:${Math.random().toString(36).slice(2,8)}`;Ue.push(Dt);const Ve=He.type.startsWith("image/")&&typeof URL.createObjectURL=="function"?URL.createObjectURL(He):null;_(cn=>[...cn,{key:Dt,filename:He.name||"Pasted image",mime:He.type||"application/octet-stream",sizeBytes:He.size,thumbnail:Ve,state:"uploading"}]),Xe.attach(He).then(cn=>_(Jn=>Jn.map(ws=>ws.key===Dt?{...ws,state:"ready",uploaded:cn}:ws))).catch(cn=>_(Jn=>Jn.map(ws=>ws.key===Dt?{...ws,state:"failed",error:cn instanceof fe?cn.message:String(cn)}:ws)))}return Ue},Ze=K=>{K.thumbnail&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(K.thumbnail)},Re=K=>{const Ue=R.find(He=>He.key===K);Ue&&(Ze(Ue),Ue.state==="ready"&&Ue.uploaded&&Xe.discardAttachment(Ue.uploaded.artifactId).catch(()=>{})),_(He=>He.filter(Dt=>Dt.key!==K)),(F==null?void 0:F.kind)==="long"&&F.key===K&&ae(null)};u.useImperativeHandle(b,()=>({addFiles:K=>{var Ue;Ae(K),(Ue=J.current)==null||Ue.focus()},focus:()=>{var K;return(K=J.current)==null?void 0:K.focus()}}));const we=u.useRef(R);we.current=R,u.useEffect(()=>()=>we.current.forEach(Ze),[]);const Y=u.useRef(0);u.useEffect(()=>{if(!l||l.at===Y.current)return;Y.current=l.at;const K=A.trim()==="";I(He=>He.trim()===""?l.text:He),ye<0&&K&&Ot(l.text);const Ue=J.current;Ue&&(Ue.focus(),window.requestAnimationFrame(()=>{Ue.setSelectionRange(Ue.value.length,Ue.value.length),O(Ue.value.length)}))},[l]);const Le=()=>{et(-1),Ot(""),I(""),O(0),ae(null),ne(!1)},Ct=(K,Ue)=>{if(g){if(K==="stop"&&!s){Le();return}Le(),g(K,Ue)}},on=K=>{const Ue=(K??A).trim();if(K===void 0?!It:n||Mn||xn||Ue==="")return;const He=K===void 0&&g?vz(Ue):null;if(He&&j0(He.name)&&R.length===0){if(He.name==="use"&&He.arg===""){Ut({value:"/use @",caret:6});return}Ct(He.name,He.arg.replace(/^@/,""));return}const Dt=R.filter(Ve=>Ve.state==="ready"&&Ve.uploaded).map(Ve=>Ve.uploaded);r(Ue,Dt),R.forEach(Ze),Le(),_([])},Te=K=>{if(me){if(Se&&g){Ct("use",K.handle);return}Ut(jz(A,M,me.start,K.handle))}},Oe=(K,Ue)=>{if(K.off)return;const He=A.slice(M);if(Ue||cF(K)){const Ve=`/${K.name} ${K.name==="use"?"@":""}`;Ut({value:Ve+He.replace(/^\S*/,"").replace(/^ /,""),caret:Ve.length});return}if(K.source==="chat"&&j0(K.name)){Ct(K.name,"");return}const Dt=`/${K.name}`;if(n||Mn||xn){Ut({value:`${Dt} `,caret:Dt.length+1});return}on(Dt)},dt=K=>{if(K.nativeEvent.isComposing)return;if(ke&&Be.length>0){if(K.key==="ArrowDown"){K.preventDefault(),ve((qe+1)%Be.length);return}if(K.key==="ArrowUp"){K.preventDefault(),ve((qe-1+Be.length)%Be.length);return}if(K.key==="Enter"&&!K.shiftKey||K.key==="Tab"){K.preventDefault();const Ve=Be[qe];ke==="mention"?Te(Ve):Oe(Ve,K.key==="Tab");return}}if(ke&&K.key==="Escape"){K.preventDefault(),ne(!0);return}if(K.key==="ArrowUp"&&!K.shiftKey&&!K.altKey&&!K.metaKey&&!K.ctrlKey){const Ve=K.currentTarget;if(le.length>0&&ye+1<le.length&&Vt(Ve)&&Un()){K.preventDefault(),ye<0&&(pt.current=A),et(ye+1),Sn(le[ye+1]);return}}if(K.key==="ArrowDown"&&!K.shiftKey&&!K.altKey&&!K.metaKey&&!K.ctrlKey&&ye>=0&&A===le[ye]){if(K.preventDefault(),ye===0){Pn();return}et(ye-1),Sn(le[ye-1]);return}if(K.key==="Escape"&&ye>=0){K.preventDefault(),Pn();return}if(K.key==="Escape"&&s&&g){K.preventDefault(),a();return}const Ue=K.currentTarget,He=Ue.selectionStart??M,Dt=Ue.selectionStart===Ue.selectionEnd;if(K.key==="Tab"&&Dt&&!K.altKey&&!K.metaKey&&!K.ctrlKey){const Ve=bz(A,He,K.shiftKey);if(Ve){K.preventDefault(),Ut(Ve);return}}if(K.key==="Enter"&&!K.shiftKey&&!K.metaKey&&!K.ctrlKey&&!K.altKey){const Ve=Dt?yz(A,He):null;if(Ve){K.preventDefault(),Ut(Ve);return}if(kc(A,He))return;K.preventDefault(),on();return}K.key==="Enter"&&(K.metaKey||K.ctrlKey)&&(K.preventDefault(),on())},Qe=K=>{var ws,Aa;const Ue=Array.from(((ws=K.clipboardData)==null?void 0:ws.files)??[]);if(Ue.length>0){K.preventDefault(),Ae(Ue);return}const He=typeof((Aa=K.clipboardData)==null?void 0:Aa.getData)=="function"?K.clipboardData.getData("text/plain"):"";if(He==="")return;const Dt=K.currentTarget,Ve=Dt.selectionStart??M,cn=Dt.selectionEnd??Ve,Jn=A.slice(0,Ve)+A.slice(cn);if(He.length>fz){K.preventDefault();const $a=new File([He],"pasted-text.txt",{type:"text/plain"}),[Zr]=Ae([$a]),ki=He.replace(/\n$/,"").split(`
121
+ `).length,Jd=`${ki} ${ki===1?"line":"lines"} · ${Math.ceil(He.length/1024)} KB`;_(ea=>ea.map(ul=>ul.key===Zr?{...ul,detail:Jd}:ul)),Jn!==A&&Ut({value:Jn,caret:Ve}),ae({kind:"long",key:Zr,text:He,caret:Ve});return}if(kz(He)&&!kc(Jn,Ve)){K.preventDefault();const $a=Nz(He),Zr=Sz(Jn,Ve,He,$a);ae({kind:"fenced",lang:$a,block:Zr.value.slice(Ve,Zr.caret),text:He}),Ut(Zr)}},vn=()=>{if(F){if(F.kind==="fenced"){const K=A.indexOf(F.block);K>=0&&Ut({value:A.slice(0,K)+F.text+A.slice(K+F.block.length),caret:K+F.text.length})}else{Re(F.key);const K=Math.min(F.caret,A.length);Ut({value:A.slice(0,K)+F.text+A.slice(K),caret:K+F.text.length})}ae(null)}},nn=R.filter(K=>K.state==="failed"),Cn=nn.length,_s=rG({conversationId:v??null,onNotice:W,onText:(K,Ue)=>{const He=A.trim()===""?K:`${A.replace(/\s+$/,"")} ${K}`;if(Ue){on(He);return}Sn(He),ye<0&&Ot(He)}}),On=_s.state!=="idle",yi=u.useRef(!1);u.useEffect(()=>{var K;yi.current&&!On&&((K=J.current)==null||K.focus()),yi.current=On},[On]);const tr=ke!==null&&!On&&!n,Cr=zw(A,M),bi=kc(A,M),ht=Cz(A).map(K=>xe.find(Ue=>Ue.handle.toLowerCase()===K)).filter(K=>!!K),Xr=De!==null&&((Qd=L$(A))==null?void 0:Qd.handle)===De.toLowerCase(),Km=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform||navigator.userAgent),Db=K=>K.group==="Borrow"?Xr?`borrows ${K.name} for this message`:`${i} asks them`:K.group==="In this room"?"is asked in this room":`${i} asks them`,Ca=Cn>0?Cn===1&&((dl=nn[0])!=null&&dl.error)?nn[0].error:`${Cn} files failed to upload and will not be sent`:P??(xn?NS:null),Yd=Ca??(s||tr?null:Cr?"Enter continues the list · Enter on an empty item ends it · Tab indents":bi?`In a code block Enter adds a line · ${Km?"⌘":"Ctrl+"}Enter sends`:ht.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"cv-chip",...ht[0].accent,children:["@",ht[0].handle]})," ",Db(ht[0]),ht.length>1?` · and ${ht.length-1} more`:""]}):A!==""?"Enter sends, Shift+Enter for a new line":null),Ea=k??(s?`${i} is working…`:p?"Message the room · @ to ask someone":x&&$e?`Message ${i} · @ to mention, / for commands`:`Message ${i}`),zo=u.useMemo(()=>xe.map(K=>({handle:K.handle,accent:K.accent})),[xe]),Uo=K=>O(K.selectionStart??K.value.length);return t.jsx("div",{className:"wb-composer cv","data-testid":"composer","data-slim":S||void 0,"data-phone":X?"true":void 0,"data-busy":A.trim()!==""||gn||On?"true":void 0,children:t.jsxs("div",{className:"cv-anchor",children:[tr&&ke==="mention"?t.jsx(eG,{id:G,items:Pe,active:qe,onPick:Te,phone:X,maxHeight:at}):null,tr&&ke==="slash"?t.jsx(tG,{id:G,items:he,active:qe,onPick:K=>Oe(K,!1),phone:X,query:(Ee==null?void 0:Ee.query)??"",maxHeight:at}):null,t.jsxs("div",{ref:H,className:"wb-composer-box cv-box","data-focused":L||On,"data-disabled":n,"data-listening":On||void 0,children:[R.length>0?t.jsx("div",{className:"wb-composer-files",role:"list","aria-label":"Files to send",children:R.map(K=>t.jsx("span",{role:"listitem",children:t.jsx(Vd,{name:K.filename,mime:K.mime,sizeBytes:K.sizeBytes,thumbnail:K.thumbnail,state:K.state,error:K.error,onRemove:()=>Re(K.key),...m&&K.state==="ready"&&K.uploaded?{onOpen:()=>m(mG(K.uploaded))}:{},size:"sm",detail:K.detail})},K.key))}):null,t.jsxs("label",{className:"sr-only",htmlFor:Fv,children:["Message ",i]}),t.jsxs("div",{className:"cv-field",hidden:On,children:[t.jsxs("div",{className:"cv-paint","aria-hidden":"true","data-testid":"composer-paint",children:[ZV(A,zo),t.jsx("span",{className:"cv-tail",children:Lv})]}),t.jsx("textarea",{id:Fv,ref:J,value:A,rows:1,spellCheck:!1,placeholder:Ea,"aria-controls":tr?G:void 0,"aria-expanded":tr?!0:void 0,"aria-autocomplete":xe.length>0||$e?"list":void 0,"aria-activedescendant":tr&&qe>=0?By(G,qe):void 0,onChange:K=>{I(K.target.value),Uo(K.target),ne(!1),ve(0),ye<0&&Ot(K.target.value)},onSelect:K=>Uo(K.currentTarget),onFocus:()=>Q(!0),onBlur:()=>Q(!1),onKeyDown:dt,onPaste:Qe,disabled:n,hidden:On})]}),On?t.jsx(iG,{voice:_s}):null,F&&!On?t.jsxs("div",{className:"cv-note",role:"status",children:[t.jsx("span",{className:"cv-note-icon",children:t.jsx(ie,{name:F.kind==="long"?"pasted-doc":"code"})}),t.jsx("span",{className:"cv-note-text",children:F.kind==="fenced"?t.jsxs(t.Fragment,{children:["Pasted as code · ",D$(F.lang)]}):t.jsx(t.Fragment,{children:"Long paste, attached as a file"})}),t.jsx(E,{size:"sm",variant:"ghost",onClick:vn,children:F.kind==="fenced"?"Undo":"Put it in the message"})]}):null,t.jsxs("div",{className:"wb-composer-row",hidden:On,children:[t.jsx("input",{ref:V,type:"file",multiple:!0,hidden:!0,"data-testid":"file-input",onChange:K=>{Ae(K.target.files),K.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 K;return(K=V.current)==null?void 0:K.click()},disabled:n,children:t.jsx(ie,{name:"clip"})}),t.jsx(aG,{disabled:n,voice:_s}),X?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:()=>{W(null),U(!0),dG().then(K=>{var Ue;K&&(Ae([K]),(Ue=J.current)==null||Ue.focus())}).catch(K=>W(K instanceof Error?K.message:String(K))).finally(()=>U(!1))},disabled:n||z,children:t.jsx(ie,{name:"camera"})}),o&&!X?d?t.jsxs("a",{className:"wb-composer-model",href:d,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(CS,{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(CS,{model:o})]}):null,f?t.jsxs("button",{type:"button",className:"ui-icon-btn wb-composer-thinking","data-size":"sm","aria-label":"Thinking","aria-pressed":Ou(h),disabled:n||s,title:s?`Thinking: ${Ou(h)?"on":"off"} — wait for ${i} to finish to change it`:`Thinking: ${Ou(h)?"on":"off"}`,onClick:()=>f(Ou(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:[X?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":!!Yd&&(!X||Ca!==null),"data-tone":Cn>0||P!==null?"critical":void 0,children:X&&Ca===null?null:Yd}),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?NS:Mn?"Waiting for the upload to finish":s?`Send — ${i} picks it up between steps`:"Send",onClick:()=>on(),disabled:!It,children:t.jsx(ie,{name:"send"})})]})]})]})})});function fG(e){const s=e.slice(e.lastIndexOf("/")+1).replace(/[:@].*$/,"").replace(/^claude-/,"").replace(/-\d{8}$/,"");return s===""?e:s}function CS({model:e}){const n=fG(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 Ou(e){return(e??"on")==="on"}function mG(e){return{type:"attachment",artifactId:e.artifactId,filename:e.filename,mime:e.mime,kind:e.kind,sizeBytes:e.sizeBytes}}function IR({question:e,disabled:n,onAnswer:s,onSkip:r}){const[a,i]=u.useState("");return u.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:pG(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 pG(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 gG(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 xG(e,n,s){return e?[...VI({messages:e.messages,descriptors:[],...s?{awaiting:new Map(s)}:{}}).filter(a=>a.source==="approval").map(a=>({approvalId:a.props.approvalId,toolUseId:a.id})),...RR(e,n)]:[]}function RR(e,n){return((e==null?void 0:e.delegatedApprovals)??[]).map(s=>({approvalId:s.approvalId,toolUseId:s.toolUseId??"",askedBy:gG(s.chain,n)}))}function ES(e){return e instanceof fe||e instanceof Error?e.message:String(e)}function PR({conversation:e,conversationId:n,agentId:s,now:r,refresh:a,onRunStarted:i,onError:l,navigate:o}){const[c,d]=u.useState(null),[h,f]=u.useState([]),[m,p]=u.useState(!1),x=((e==null?void 0:e.offers)??[]).filter(j=>!h.includes(j.id)&&Date.parse(j.expiresAt)>r),g=j=>{var w;const v=x.find(N=>N.id===j);if(((w=v==null?void 0:v.handoff)==null?void 0:w.kind)==="install"){o(v6(v.handoff.package));return}l(null),d(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(k=>k.filter(S=>S!==j)),l(ES(N)),n&&a(n)}).finally(()=>d(null))},y=j=>{const v=e==null?void 0:e.question;v&&(l(null),p(!0),i(),Xe.answerQuestion(v.id,j).then(()=>{if(n)return a(n)}).catch(w=>l(ES(w),!0)).finally(()=>p(!1)))};return{openOffers:x,takingOffer:c,takeOffer:g,answeringQuestion:m,answerQuestion:(j,v)=>y({answer:j,...v?{optionId:v}:{}}),skipQuestion:()=>y({answer:"",skipped:!0})}}function MR({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 vG(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 jG(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 wG(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 ${jG(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(vG(n,r))return{text:`${o} · your next message starts a fresh one`,title:l,tone:"note"};const c=s?Ge(s,r):"";return{text:c===""?o:`${o} · started ${c}`,title:s?`Started ${ft(s,a)}. ${l}`:l,tone:"quiet"}}function yG({text:e,onDelete:n}){const[s,r]=u.useState(!1),[a,i]=u.useState(null);return t.jsx("div",{className:"wb-carryover","data-testid":"chat-carryover",children:t.jsxs(Kt,{summary:"Carried over from the previous conversation",children:[t.jsx("p",{className:"wb-carryover-text",children:e}),t.jsxs(se,{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 OR(e){return e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function DR(e,n){return e.members.map(s=>n.find(r=>r.id===s)).filter(s=>s!==void 0)}function bG(e,n){var a;const s=DR(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 kG(){return t.jsx("span",{className:"ui-avatar group-gone-face","aria-hidden":"true",children:"?"})}function NG({group:e,agents:n,onClose:s,onSaved:r}){const[a,i]=u.useState(!1),[l,o]=u.useState(null),c=[e.coordinator,...e.members.filter(x=>x!==e.coordinator)],d=e.members.length>2,h=cy(n).filter(x=>!e.members.includes(x.id)),f=!n.some(x=>x.id===e.coordinator),m=async x=>{i(!0),o(null);try{r(await Xe.updateGroup(e.id,x))}catch(g){o(g instanceof fe?g.message:String(g))}finally{i(!1)}},p=x=>void m({members:e.members.filter(g=>g!==x)});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(ut,{children:c.map(x=>{const g=n.find(j=>j.id===x),y=x===e.coordinator;return g?t.jsx(ot,{lead:t.jsx(an,{agents:n,id:x}),title:g.name,sub:g.description,side:t.jsxs(t.Fragment,{children:[y?t.jsx(Ce,{tone:"accent",children:"Coordinator"}):null,f&&g.available?t.jsx(E,{size:"sm",disabled:a,onClick:()=>void m({coordinator:x}),children:"Make coordinator"}):null,t.jsx(Qn,{label:`More for ${g.name}`,...y?{note:"Coordinates the group"}:{},items:[!y&&g.available&&{label:"Make coordinator",hint:"Reads your requests, answers for the room",onSelect:()=>void m({coordinator:x})},{label:`Open ${g.name}'s page`,onSelect:()=>{window.location.hash=Pt(x)}},!y&&"separator",!y&&{label:"Remove from group",hint:d?"What it said stays":"A group needs two",tone:"critical",onSelect:()=>{d?p(x):o("A group needs two agents. Add someone before taking this one out.")}}]})]})},x):t.jsx(ot,{lead:t.jsx(kG,{}),title:t.jsx("span",{className:"group-gone-id",children:x}),sub:t.jsxs("span",{className:"group-gone-line",children:["No longer in buddi",y?" · was the coordinator":d?"":" · add a member to take it out"]}),side:d&&!y?t.jsx(E,{size:"sm",disabled:a,onClick:()=>p(x),children:"Remove"}):void 0},x)})}),t.jsxs("div",{className:"group-add",children:[t.jsx("h3",{className:"group-add-title",children:"Add a member"}),h.length>0?t.jsx(ut,{children:h.map(x=>t.jsx(ot,{lead:t.jsx(an,{agents:n,id:x.id,size:"sm"}),title:x.name,sub:x.description,side:t.jsx(E,{size:"sm",disabled:a,onClick:()=>void m({members:[...e.members,x.id]}),children:"Add"})},x.id))}):t.jsx("p",{className:"group-quiet",children:"Everyone who can join a group is here."})]}),t.jsx("p",{className:"group-quiet",children:"Members read what is said here and what they recall from shared and group memory; nothing an agent knows privately comes in on its own. Taking a member out leaves what it said in the history."})]})}function SG({group:e,onClose:n,onSaved:s}){const[r,a]=u.useState(e.name),[i,l]=u.useState(!1),[o,c]=u.useState(null),d=r.trim()!==""&&r.trim()!==e.name&&!i,h=async()=>{if(d){l(!0),c(null);try{s(await Xe.updateGroup(e.id,{name:r.trim()}))}catch(f){c(f instanceof fe?f.message:String(f)),l(!1)}}};return t.jsx(zt,{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:!d,onClick:()=>void h(),children:i?"Renaming…":"Rename"})]}),children:t.jsx("form",{onSubmit:f=>{f.preventDefault(),h()},children:t.jsxs(de,{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 LR(e){const[n,s]=u.useState(null);return u.useEffect(()=>{let r=!0;return Xe.group(e).then(a=>{var i;r&&s(((i=a.history)==null?void 0:i.conversations)??null)}).catch(()=>{}),()=>{r=!1}},[e]),n}function CG(e){return e===null?"Its conversations":e===0?"Nothing has been said yet, and its next conversation":`Its ${e} ${e===1?"conversation":"conversations"}`}function EG({group:e,onClose:n,onCleared:s}){const r=LR(e.id),[a,i]=u.useState(!1),[l,o]=u.useState(null),c=async()=>{i(!0),o(null);try{await Xe.clearGroup(e.id),s()}catch(h){o(h instanceof fe?h.message:String(h)),i(!1)}},d=r===0;return t.jsxs(zt,{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||d,"data-testid":"group-clear-confirm",onClick:()=>void c(),children:a?"Clearing…":"Clear history"})]}),children:[t.jsx("p",{className:"group-dialog-text",children:d?"Nothing has been said in this group yet, so there is nothing to clear.":`${CG(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 AG({group:e,agents:n,onClose:s,onDeleted:r}){const a=LR(e.id),[i,l]=u.useState(!1),[o,c]=u.useState(null),d=DR(e,n).map(m=>m.name),h=async()=>{l(!0),c(null);try{const{undoUntil:m}=await Xe.deleteGroup(e.id);r(m)}catch(m){c(m instanceof fe?m.message:String(m)),l(!1)}},f=a===null?"its conversations":a===0?"nothing said yet":`its ${a} ${a===1?"conversation":"conversations"}`;return t.jsxs(zt,{title:`Delete ${e.name}?`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx(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."," ",d.length>0?`${OR(d)} ${d.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 AS(){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 $G({timezone:e,agents:n,agentId:s,defaultAgentId:r=null,group:a=null,onGroupAction:i,onSelectAgent:l,onWorking:o,attention:c,agentsInHeader:d,narrow:h,canvasOpen:f,onOpenCanvas:m,onCloseCanvas:p,newConversationSignal:x,requestedConversationId:g,requestedTab:y,onConversationOpened:j}){var Yb,Qb,Jb,Xb,Zb,ek,tk,nk,sk,rk,ak;const v=$m(),[w,N]=u.useState([]),[k,S]=u.useState(null),[b,C]=u.useState(null),[$,A]=u.useState(null),[I,M]=u.useState([]),[O,R]=u.useState([]),[_,z]=u.useState(null),[U,P]=u.useState(!1),[W,L]=u.useState(new Map),[Q,F]=u.useState(null),[ae,V]=u.useState(YV),[J,H]=u.useState([]),[X,G]=u.useState(!1),ce=u.useRef(0),xe=u.useRef(null),[De,B]=u.useState(!1),ne=u.useRef(x??0),Z=u.useRef(s),ve=u.useRef({agentId:s,conversationId:k});ve.current={agentId:s,conversationId:k};const $e=ae[k??""]??[],[Se,me]=u.useState(null),[Ee,Pe]=u.useState(null),[Me,he]=u.useState(()=>Date.now()),[ke,Be]=u.useState(c9),qe=u.useRef(null),[at,le]=u.useState(null),[ye,et]=u.useState(!1),[pt,kt]=u.useState(null),[Ot,Ut]=u.useState(DI),Sn=u.useRef(Ot);Sn.current=Ot;const Vt=u.useRef(null),[Un,Pn]=u.useState(null),Mn=u.useCallback(ee=>{Ut(ee),LI(ee),ee||Mo()},[]),[gn,xn]=u.useState(null),[It,Ae]=u.useState(null);u.useEffect(()=>{if(!s)return;const ee=hz(s);ee&&kt({text:ee,at:Date.now()})},[s]);const Ze=a?`group:${a.id}`:s??null,Re=[...n.top,...n.middle,...n.bottom],we=Re.find(ee=>ee.id===s)??null,Y=pe(()=>T.providerAccounts(),[]),Le=a?a.members.map(ee=>Re.find(ue=>ue.id===ee)).filter(ee=>!!ee):[],[Ct,on]=u.useState(null),Te=U?Ct??s??null:null;u.useEffect(()=>{o==null||o(Te)},[Te,o]),u.useEffect(()=>()=>o==null?void 0:o(null),[o]),u.useEffect(()=>{let ee=!1;return Xe.views().then(ue=>{ee||N(ue.views??[])}).catch(()=>{}),()=>{ee=!0}},[]),u.useEffect(()=>{if(!s)return;const ee=Z.current===s;if(Z.current=s,ee&&g&&g===ve.current.conversationId)return;let ue=!1;return S(null),C(null),A(null),M([]),me(null),P(!1),F(null),H([]),Ca(null),B(!1),le(null),g?(g!=="new"?S(g):A(Ze),()=>{ue=!0}):((a?Xe.groupConversations(a.id):Xe.conversations(s)).then(_e=>{if(ue)return;const it=[..._e.conversations??[]].sort(TG)[0];it?(S(it.id),j==null||j(s,it.id)):A(Ze)}).catch(()=>{ue||A(Ze)}),()=>{ue=!0})},[s,a==null?void 0:a.id,Ze,g,j]);const Oe=u.useCallback(ee=>Xe.conversation(ee).then(ue=>{if(ve.current.conversationId===ee){if(ue.agentId!==ve.current.agentId)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(ue),M(_e=>_e.filter(it=>!rg(ue,it)))}}).catch(ue=>{ve.current.conversationId===ee&&me(Ra(ue))}),[]);u.useEffect(()=>{if(!k)return;let ee=!1;return L(new Map),R([]),Xe.conversation(k).then(ue=>{if(!ee){if(ue.agentId!==s)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(ue),M(_e=>_e.filter(it=>!rg(ue,it)))}}).catch(ue=>{ee||me(Ra(ue))}),()=>{ee=!0}},[k,s]),u.useEffect(()=>{if(!k)return;let ee=!1;const ue=window.setInterval(()=>{Xe.conversation(k).then(_e=>{ee||_e.agentId!==ve.current.agentId||(C(_e),M(it=>it.filter(tt=>!rg(_e,tt))))}).catch(()=>{})},3e3);return()=>{ee=!0,window.clearInterval(ue)}},[k,s]),u.useEffect(()=>{if(!k)return;const ee=pm({url:Xe.streamUrl(k),onEvent:ue=>{var _e,it;switch(ue.name){case"run.started":Vt.current=null,P(!0),z(null),on(Ln(ue.data.agentId));break;case"live":{const tt=Ln(ue.data.runId)??"",Et=Number(ue.data.turn??0),Ye=ue.data.kind==="thinking"?"thinking":"text",Xn=Ln(ue.data.text)??"",ta=Date.now();if(Ye==="text"){const Er=Vt.current;Vt.current=Er&&Er.runId===tt&&Er.turn===Et?{...Er,text:Er.text+Xn}:{runId:tt,turn:Et,text:Xn}}z(Er=>{const fl=Er&&Er.runId===tt&&Er.turn===Et?Er:{runId:tt,turn:Et,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return Ye==="thinking"?{...fl,thinking:fl.thinking+Xn,thinkingStartedAt:fl.thinkingStartedAt??ta}:{...fl,text:fl.text+Xn,textStartedAt:fl.textStartedAt??ta}});break}case"live.snapshot":{const tt=Ln(ue.data.runId)??"",Et=Number(ue.data.turn??0),Ye=Ln(ue.data.text)??"",Xn=Ln(ue.data.thinking)??"",ta=Number(ue.data.startedAt??Date.now());Vt.current={runId:tt,turn:Et,text:Ye},z({runId:tt,turn:Et,text:Ye,thinking:Xn,thinkingStartedAt:Xn?ta:null,textStartedAt:Ye?ta:null,settled:!1});break}case"live.settle":{const tt=Ln(ue.data.runId)??"",Et=Number(ue.data.turn??0);if(ue.data.retracted===!0){((_e=Vt.current)==null?void 0:_e.runId)===tt&&Vt.current.turn===Et&&(Vt.current=null),z(Ye=>Ye&&Ye.runId===tt&&Ye.turn===Et?null:Ye);break}z(Ye=>Ye&&Ye.runId===tt&&Ye.turn===Et?{...Ye,settled:!0}:Ye);break}case"tool.called":{const tt=Ln(ue.data.toolUseId)??Ln(ue.data.id),Et=Ln(ue.data.name)??Ln(ue.data.tool)??"tool";tt&&R(Ye=>[...Ye.filter(Xn=>Xn.toolUseId!==tt),{toolUseId:tt,name:Et,startedAt:Date.now()}]);break}case"tool.result":{const tt=Ln(ue.data.toolUseId)??Ln(ue.data.id);tt&&R(Et=>Et.filter(Ye=>Ye.toolUseId!==tt)),Oe(k);break}case"reaction":Oe(k);break;case"message.appended":Oe(k).then(()=>{z(tt=>tt!=null&&tt.settled?null:tt)});break;case"awaiting-approval":{const tt=Ln(ue.data.approvalId)??Ln(ue.data.actionId),Et=Ln(ue.data.toolUseId);tt&&Et&&L(Ye=>new Map(Ye).set(Et,tt)),R(Ye=>Ye.filter(Xn=>Xn.toolUseId!==Et)),Oe(k);break}case"run.finished":{P(!1),R([]),z(null),on(null);const tt=Ln(ue.data.message);me(tt??null);const Et=((it=Vt.current)==null?void 0:it.text.trim())??"";Vt.current=null,!tt&&Et!==""&&Sn.current&&hf(Et,k).then(Ye=>{Ye&&Pn(Ye)}),Oe(k);break}}}});return()=>ee.close()},[k,Oe]),u.useEffect(()=>{const ee=window.setInterval(()=>he(Date.now()),O.length===0?6e4:1e3);return()=>window.clearInterval(ee)},[O.length]);const dt=pe(()=>s&&k?T.browser({agentId:s,conversationId:k}):Promise.resolve(void 0),[s,k],1500),Qe=dt.error?void 0:dt.data,vn=Qe!=null&&Qe.session&&Qe.session.agentId===s&&Qe.session.conversationId===k?Qe:void 0,nn=zV(vn,s,k),Cn=(nn==null?void 0:nn.id)??null,[_s,On]=u.useState(null),yi=vn==null?void 0:vn.mode;u.useEffect(()=>{nn&&s&&k&&On({agentId:s,conversationId:k,tab:UV(nn)})},[Cn,yi,s,k]);const tr=_s&&_s.agentId===s&&_s.conversationId===k&&!$e.includes(_s.tab.id)?_s.tab:null,Cr=Dv(b==null?void 0:b.question),bi=nn?null:BV(Qe,k??null,(Cr==null?void 0:Cr.kind)==="paused"),ht=nn??bi??tr,Xr=(Yb=Qe==null?void 0:Qe.routes)==null?void 0:Yb.find(ee=>ee.kind==="chrome"),Km=!a&&k&&(Xr!=null&&Xr.allowed)&&Xr.paired?{on:(Qe==null?void 0:Qe.pin)==="chrome",onChange:ee=>{T.browserPin(k,ee?"chrome":"auto").catch(()=>{}).finally(dt.reload)}}:void 0,[Db,Ca]=u.useState(null),Yd=u.useMemo(()=>hH({messages:(b==null?void 0:b.messages)??[],descriptors:w}),[b,w]),Ea=m9(Yd,k??null),zo=g9(a?null:s),Uo=u.useMemo(()=>p9((b==null?void 0:b.messages)??[]),[b]),Dn=u.useMemo(()=>{const ue=VI({messages:(b==null?void 0:b.messages)??[],descriptors:w,awaiting:W,served:Ea.served,...ht?{folded:hh}:{},gathered:GV,quiet:jS,titles:wS}).filter(it=>it.source==="approval"||!$e.includes(it.id)),_e=Q?GN(ue,Q):null;if(_e&&(_e.props={..._e.props,focus:Q}),Q&&!_e&&!$e.includes(Q)&&!ue.some(it=>it.id===Q)){const it=gH((b==null?void 0:b.messages)??[],Q,{redactInputOf:hh,resultOf:jS,titles:wS});it&&!hh.has(it.tool)&&ue.push(it)}ht&&ue.push(ht);for(const it of J)ue.push(q5(it));return zo&&ue.unshift(x9(zo,Uo)),at?[...ue,v9(at)]:ue},[b,w,W,at,Cn,ht==null?void 0:ht.title,Q,ae,k,J,Ea.served,zo,Uo]),Qd=u.useMemo(()=>{var ue;const ee=[];for(const _e of(b==null?void 0:b.messages)??[]){if(_e.role!=="user"||_e.speaker&&_e.speaker!=="owner")continue;const it=(ue=_e.blocks.find(tt=>tt.type==="text"))==null?void 0:ue.text.trim();it&&ee.unshift(it)}return ee},[b]),dl=u.useMemo(()=>Dn.filter(ee=>ee.source==="approval"),[Dn]),K=dl.at(-1)??null,Ue=u.useMemo(()=>[...dl.map(ee=>({approvalId:ee.props.approvalId,toolUseId:ee.id})),...RR(b,Re)],[dl,b==null?void 0:b.delegatedApprovals]),He=u.useMemo(()=>{for(let ee=Dn.length-1;ee>=0;ee-=1){const ue=Dn[ee];if(ue!=null&&ue.substantial)return ue.id}return null},[Dn]),Dt=u.useRef(null),Ve=((Qb=Dn.filter(ee=>(ee.source!=="browser"||ee.pinned===!0)&&ee.id!==Tv).at(-1))==null?void 0:Qb.id)??((Jb=Dn.filter(ee=>ee.id!==Tv).at(-1))==null?void 0:Jb.id)??null;u.useEffect(()=>{if(He&&He!==Dt.current){Dt.current=He,F(He);return}Q===null&&Ve&&F(Ve)},[He,Q,Ve]);const cn=u.useRef(Ea.live);u.useEffect(()=>{const ee=cn.current;cn.current=Ea.live;const ue=[...Ea.live].filter(tt=>!ee.has(tt));if(ue.length===0||K||Q!==null&&Q!==Dt.current)return;const it=[...Dn].reverse().find(tt=>tt.source==="descriptor"&&tt.renderer==="preview"&&tt.props.target!==null&&ue.includes(ql(tt.props.target)));it&&F(it.id)},[Ea.live,Dn,K,Q]);const Jn=u.useRef(null);u.useEffect(()=>{Cn!==Jn.current&&(Jn.current=Cn,Cn&&!K&&F(Cn))},[Cn,K]);const ws=u.useRef(null),Aa=y==="browser"?(ht==null?void 0:ht.id)??null:null;u.useEffect(()=>{!Aa||ws.current===Aa||(ws.current=Aa,F(Aa))},[Aa]);const $a=(ht==null?void 0:ht.id)??null;u.useEffect(()=>{!$a||!Q||vS((b==null?void 0:b.messages)??[],Q)!==null&&(Ca(Q),F($a))},[$a,Q,b]);const Zr=ee=>{H(ue=>ue.some(_e=>_e.artifactId===ee.artifactId)?ue:[...ue,ee]),F(ch(ee.artifactId)),h&&(m==null||m())},ki=!a&&we&&!we.available?QT(we):null,Jd=a?t.jsx("span",{className:"wb-group-stack","aria-hidden":"true",children:a.members.slice(0,2).map(ee=>{const ue=Re.find(_e=>_e.id===ee);return t.jsx(xm,{className:"wb-group-chip",id:ee,name:(ue==null?void 0:ue.name)??"?",face:ue,initials:1},ee)})}):null,ea=a&&Re.length>0?bG(a,Re):null,ul=(ea==null?void 0:ea.kind)==="coordinator",Lb=lv(a?null:we),Fb=Ue.length>0||!!(b!=null&&b.question),Vm=u.useRef(Fb);Vm.current=Fb,u.useEffect(()=>{if(Vm.current||AS())return;const ee=window.requestAnimationFrame(()=>{var ue;Vm.current||AS()||(ue=xe.current)==null||ue.focus()});return()=>window.cancelAnimationFrame(ee)},[s,a==null?void 0:a.id,k,x]);const jO=we&&It===we.id?gn:(we==null?void 0:we.thinking)??null,wO=ee=>{if(!we)return;const ue=we.id;Ae(ue),xn(ee),T.setAgentEngine(ue,{thinking:ee}).catch(_e=>{Ae(null),me(_e instanceof fe?_e.message:String(_e))})},Gm=(ee,ue)=>{if(!s)return;const _e=a?null:OG(ee,Re,s);if(_e){me(null),Xe.send(_e.agent.id,{text:_e.rest,attachmentIds:ue.map(Ye=>Ye.artifactId)}).then(Ye=>{window.location.hash=lt(_e.agent.id,Ye.conversationId)}).catch(Ye=>me(Ra(Ye)));return}const it=ue.map(Ye=>Ye.artifactId),tt=U,Et={id:`optimistic:${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:ee},...ue.map(Ye=>({type:"attachment",artifactId:Ye.artifactId,filename:Ye.filename,mime:Ye.mime,kind:Ye.kind,sizeBytes:Ye.sizeBytes}))],...tt?{speaker:QI}:{}};M(Ye=>tt?[...Ye,Et]:[Et]),me(null),Pe(null),P(!0),(a?Xe.sendToGroup(a.id,{...k?{conversationId:k}:{},text:ee,attachmentIds:it}):Xe.send(s,{...k?{conversationId:k}:{},text:ee,attachmentIds:it})).then(async Ye=>{ve.current.agentId!==s||ve.current.conversationId!==k||(Pe(Ye.rolledOver===!0?"(New thread — the room had grown long. Where it stopped carries over as a summary.)":null),Ye.conversationId!==k?(C(null),S(Ye.conversationId)):await Oe(Ye.conversationId),Ye.queued===!0&&M(Xn=>Xn.filter(ta=>ta.id!==Et.id)),j==null||j(s,Ye.conversationId))}).catch(Ye=>{M(Xn=>Xn.filter(ta=>ta.id!==Et.id)),me(Ra(Ye)),P(!1)})},{openOffers:yO,takingOffer:bO,takeOffer:kO,answeringQuestion:_b,answerQuestion:zb,skipQuestion:NO}=PR({conversation:b,conversationId:k??null,agentId:(we==null?void 0:we.id)??null,now:Me,refresh:Oe,onRunStarted:()=>{Pe(null),P(!0)},onError:(ee,ue)=>{me(ee),ue&&P(!1)},navigate:ee=>{window.location.hash=ee}}),SO=()=>{if(s){if(at){le(null);return}et(!0),T.agentProfile(s).then(ee=>{le(ee),F(Iv(ee.id)),h&&(m==null||m())}).catch(ee=>me(Ra(ee))).finally(()=>et(!1))}},CO=ee=>{kt({text:ee.prompt,at:Date.now()}),l(ee.agentId),h&&(p==null||p())},Ub=()=>{k&&Xe.cancel(k).catch(ee=>me(Ra(ee))).finally(()=>{P(!1),R([])})},EO=(ee,ue)=>{if(me(null),ee==="stop"){Ub();return}if(ee==="use"){const _e=ue.replace(/^@/,"").toLowerCase(),it=Re.find(tt=>tt.handle.toLowerCase()===_e||tt.id===_e);if(!it){Pe(_e?`No agent called @${_e}.`:"Say who: /use @handle.");return}Pe(null),l(it.id);return}if(ee==="new"){const _e=Re.find(it=>it.roles.includes(gr));if(!_e){Pe("There is no agent here that makes agents.");return}ue.trim()&&Md(_e.id,`I'd like a teammate for this: ${ue.trim()}`),l(_e.id);return}T.quiet(ue).then(_e=>Pe(_e.text)).catch(_e=>me(Ra(_e)))},Xd=u.useCallback(()=>{if(S(null),C(null),M([]),P(!1),me(null),Pe(null),R([]),L(new Map),F(null),H([]),Ca(null),Dt.current=null,a){Xe.startGroupConversation(a.id).then(({conversationId:ee})=>{S(ee),s&&(j==null||j(s,ee))}).catch(ee=>me(Ra(ee)));return}A(Ze),s&&(j==null||j(s,"new"))},[s,a,Ze,j]);u.useEffect(()=>{x&&x!==ne.current&&(ne.current=x,Xd())},[x,Xd]);const Bb=ee=>{k&&Oe(k),T.overview().catch(()=>{}),ee.state!=="pending"&&L(ue=>new Map([...ue].filter(([,_e])=>_e!==ee.id)))},AO=((Xb=Re.find(ee=>ee.id===r))==null?void 0:Xb.name)??null,Wb=a?[]:EB(we,AO),Hb=!(b&&b.conversationId===k)&&!(!k&&$!==null&&$===Ze),Kb=Hb?t.jsx("div",{className:"wb-chat-loading","data-testid":"chat-loading","aria-busy":"true"}):!a&&we?t.jsx(wI,{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:Re,id:we.id,size:"xl"}),t.jsx("h2",{className:"wb-chat-hello",children:`Hi, I'm ${we.name}.`}),t.jsx("p",{className:"wb-chat-intro",children:AB(we)}),Wb.length>0?t.jsx("div",{className:"wb-starters",role:"group","aria-label":`Things to ask ${we.name}`,children:Wb.map(ee=>t.jsx("button",{type:"button",className:"wb-starter",onClick:()=>{var ue;kt({text:ee,at:Date.now()}),(ue=xe.current)==null||ue.focus()},children:ee},ee))}):null]})}):null,Vb=t.jsx(KK,{renderables:Dn,activeId:(Q?(Zb=GN(Dn,Q))==null?void 0:Zb.id:null)??Q,onActivate:F,onClose:ee=>{at&&ee===Iv(at.id)?le(null):J.some(ue=>ch(ue.artifactId)===ee)?H(ue=>ue.filter(_e=>ch(_e.artifactId)!==ee)):k&&V(ue=>{const _e={...ue,[k]:[...new Set([...ue[k]??[],ee])]};return yS(_e),_e}),Q===ee&&F(null)},timezone:e,onDecided:Bb,onChangeAgent:CO,agents:Re,browserPanel:ht?t.jsx(PV,{status:vn,error:dt.error,reload:dt.reload,live:nn!==null,agentName:(we==null?void 0:we.name)??"The agent",timezone:e,paused:bi&&(Qe!=null&&Qe.stop)?Qe.stop:null},ht.id):null,browserMenu:ht?t.jsx(DV,{status:Qe,timezone:e,reload:dt.reload}):null,descriptors:w,grantedTools:a?Le.flatMap(ee=>ee.tools??[]):(we==null?void 0:we.tools)??[],...we?{agentName:we.name}:{},loading:Hb,...!a&&we?{face:t.jsx(an,{agents:Re,id:we.id,size:"xl"}),cardFace:t.jsx(an,{agents:Re,id:we.id,size:"sm"})}:{}}),Gb=(tk=(ek=[...(b==null?void 0:b.messages)??[],...I].find(ee=>ee.role==="user"))==null?void 0:ek.blocks.find(ee=>ee.type==="text"))==null?void 0:tk.text.trim(),qb=Gb?Gb.split(`
122
+ `)[0]:"New conversation",hl=wG({lifetime:(b==null?void 0:b.lifetime)??null,startedAt:(b==null?void 0:b.startedAt)??null,now:Me,timezone:e});return t.jsxs(t.Fragment,{children:[t.jsxs("section",{className:"wb-chat",ref:qe,style:h||ke===null?void 0:{[$v]:`${ke}px`},"data-sized":!h&&ke!==null?"true":void 0,"data-testid":"chat-column","data-dropping":X||void 0,onDragEnter:ee=>{Du(ee)&&(ee.preventDefault(),ce.current+=1,G(!0))},onDragOver:ee=>{Du(ee)&&(ee.preventDefault(),ee.dataTransfer.dropEffect="copy")},onDragLeave:ee=>{Du(ee)&&(ce.current=Math.max(0,ce.current-1),ce.current===0&&G(!1))},onDrop:ee=>{var ue;Du(ee)&&(ee.preventDefault(),ce.current=0,G(!1),s&&((ue=xe.current)==null||ue.addFiles(ee.dataTransfer.files)))},children:[X?t.jsx("div",{className:"wb-drop","aria-hidden":"true",children:t.jsxs("div",{className:"wb-drop-card",children:[t.jsx(IG,{}),t.jsx("strong",{children:"Drop to attach"}),t.jsx("span",{children:we?`It goes with your next message to ${we.name}`:"Pick an agent first"})]})}):null,t.jsxs("header",{className:"wb-chat-head","data-testid":"chat-head",...!a&&we?Qi(Io(we)):{},children:[t.jsxs("div",{className:"wb-head-row",children:[a?t.jsx("span",{className:"wb-head-face","aria-hidden":"true",children:Jd}):we?t.jsx("a",{className:"wb-head-face",href:Pt(we.id),"aria-label":`${we.name}'s page`,children:t.jsx(an,{agents:Re,id:we.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:qb,children:qb}),t.jsx("span",{className:"wb-head-meta","data-tone":hl.tone,title:a?`${Le.map(ee=>ee.name).join(", ")}. Coordinator: ${(we==null?void 0:we.name)??a.coordinator}.`:hl.title,children:a?`${Le.map(ee=>ee.name).join(", ")} · ${hl.text}`:we?t.jsxs(t.Fragment,{children:[t.jsx("a",{className:"wb-head-name",href:Pt(we.id),title:`${we.name}'s page`,children:we.name})," ",t.jsxs("span",{className:"wb-head-handle",children:["@",we.handle]}),` · ${hl.tone==="quiet"&&hl.text==="New conversation"?`on ${v}`:hl.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:()=>{B(!1),Xd()},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":De,"data-open":De?"true":void 0,disabled:!s,onClick:()=>B(ee=>!ee),children:t.jsx(RG,{})}),h?t.jsxs("button",{className:"ui-btn",onClick:m,disabled:Dn.length===0,children:["Canvas",Dn.length>0?` (${Dn.length})`:""]}):null,a?t.jsx($S,{disabled:!1,label:"More about this group",title:a.name,sub:OR(Le.map(ee=>ee.name)),face:Jd,items:[{label:"Members",hint:`${a.members.length} agents · ${we?`${we.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($S,{disabled:!s,label:"More about this agent",title:(we==null?void 0:we.name)??"Agent",...we?{sub:`@${we.handle}`,face:t.jsx(an,{agents:Re,id:we.id,size:"sm"})}:{},items:[{label:at?"Close properties":"Properties",hint:"What this agent can do, on the Canvas",testId:"agent-properties",disabled:ye,onSelect:SO},...we?[{label:"Set up",hint:"Identity, model and access",href:Pt(we.id,"setup")},{label:"Open agent page",hint:"Profile, activity and setup",href:Pt(we.id)}]:[]]})]}),d?t.jsx(ZT,{agents:n,currentId:s,attention:c,onSelect:l,orientation:"horizontal",...Te?{working:new Set([Te])}:{}}):null]}),!a&&we?t.jsx(XV,{agentId:we.id},we.id):null,De&&s?t.jsx(qV,{agentId:s,...a?{groupId:a.id}:{},currentId:k,timezone:e,onNew:()=>{B(!1),Xd()},onSelect:ee=>{if(ee===k){B(!1);return}B(!1),C(null),M([]),P(!1),F(null),me(null),Pe(null),H([]),S(ee),j==null||j(s,ee,!1)}}):null,s&&k?t.jsx(LV,{agentId:s,conversationId:k},`${s}:${k}`):null,Se?t.jsx("div",{className:"wb-chat-notice",children:t.jsx(re,{message:Se})}):null,Ee?t.jsx("div",{className:"wb-chat-notice","data-testid":"chat-notice",children:Ee}):null,b!=null&&b.carriedOver?t.jsx(yG,{text:b.carriedOver,onDelete:async()=>{const ee=b.conversationId;await Xe.deleteCarryOver(ee),C(ue=>{if(!ue||ue.conversationId!==ee)return ue;const{carriedOver:_e,...it}=ue;return it})}},b.conversationId):null,t.jsx($y,{messages:[...(b==null?void 0:b.messages)??[],...I],live:O,now:Me,working:U,partial:_,agents:Re,...b!=null&&b.runs?{runs:b.runs}:{},...s&&k?{onContinue:()=>Gm("continue",[])}:{},...a?{speakers:Re,coordinatorId:a.coordinator}:{},...Ct?{workingAs:((nk=Re.find(ee=>ee.id===Ct))==null?void 0:nk.name)??Ct}:{},onOpenFile:Zr,onReadAloud:(ee,ue)=>{Pn(null),hf(ue,k??void 0,ee).then(_e=>{_e&&Pn(_e)})},onOpen:ee=>{if(ht){const ue=vS([...(b==null?void 0:b.messages)??[],...I],ee);if(ue){Ca(ue),F(ht.id),h&&(m==null||m());return}}k&&V(ue=>{const _e={...ue,[k]:(ue[k]??[]).filter(it=>it!==ee)};return yS(_e),_e}),F(ee),h&&(m==null||m())},...we?{agentName:we.name,agentId:we.id}:{},...Kb?{empty:Kb}:{},emptyHint:a?`Give the team a task once; ${we?we.name:"the coordinator"} brings members in. @ addresses one of them.`:we?`Nothing here yet. Ask ${we.name} for something.`:"Loading agents…"}),t.jsx(MR,{offers:yO,disabled:bO!==null,onTake:kO}),ea?t.jsx("div",{className:"wb-composer-blocked","data-testid":"group-problem","data-kind":ea.kind,children:t.jsx(q,{tone:ul?"warning":void 0,role:"status",children:t.jsxs("span",{children:[ea.text," ",t.jsx("button",{type:"button",className:"wb-link-btn",onClick:()=>i==null?void 0:i("members"),children:ea.action})]})})}):null,ki?t.jsx("div",{className:"wb-composer-blocked","data-testid":"composer-blocked",children:t.jsxs(q,{tone:"warning",role:"status",children:[ki," ",t.jsx("a",{href:ze(Lb.section),children:Lb.label})]})}):Ue.length>0?t.jsx(iR,{approvals:Ue,timezone:e,now:Me,version:b,onDecided:Bb,onSay:ee=>Gm(ee,[]),onOpenFull:ee=>{F(ee),h&&(m==null||m())}}):null,ki||Ue.length>0?null:b!=null&&b.question&&Cr?t.jsx($R,{card:Cr,disabled:_b||U,onAnswer:zb,site:((sk=Qe==null?void 0:Qe.needsOwner)==null?void 0:sk.site)??((ak=(rk=Qe==null?void 0:Qe.page)==null?void 0:rk.url)==null?void 0:ak.replace(/^https?:\/\/(www\.)?([^/]+).*$/,"$2"))},b.question.id):b!=null&&b.question?t.jsx(IR,{question:b.question,disabled:_b||U,onAnswer:zb,onSkip:NO},b.question.id):null,ki||ul?null:t.jsxs("div",{hidden:Ue.length>0||!!(b!=null&&b.question),"data-testid":"composer-slot",children:[t.jsx(Wy,{ref:xe,disabled:!s,running:U,onSend:Gm,onStop:Ub,agentName:a?a.name:(we==null?void 0:we.name)??"the agent",draft:pt,history:Qd,threadKey:k??(a?`group:${a.id}`:s),model:a?null:(we==null?void 0:we.model)??null,chrome:Km,setupHref:a?null:we?Pt(we.id,"setup","brain"):null,thinking:jO,...!a&&we&&F$(_$(we,Y.data))?{onThinking:wO}:{},...a?{mentions:Le.map(ee=>({id:ee.id,handle:ee.handle,name:ee.name})),team:{agents:Re,selfId:""}}:s?{team:{agents:Re,selfId:s}}:{},onCommand:EO,onOpenFile:Zr,conversationId:k??null,readAloud:Ot,onReadAloud:Mn}),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"})]}),Vb]}):null:t.jsxs(t.Fragment,{children:[t.jsx(u9,{columnRef:qe,width:ke,onChange:Be}),Vb]})]})}function TG(e,n){return Date.parse(n.lastMessageAt??n.startedAt??n.createdAt??"")-Date.parse(e.lastMessageAt??e.startedAt??e.createdAt??"")}function Ln(e){return typeof e=="string"&&e!==""?e:null}function Ra(e){return e instanceof fe||e instanceof Error?e.message:String(e)}function rg(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 Du(e){var s;const n=(s=e.dataTransfer)==null?void 0:s.types;return!!(n&&Array.from(n).includes("Files"))}function IG(){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 RG(){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 PG(){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 $S({items:e,disabled:n,label:s,title:r,sub:a,face:i}){const[l,o]=u.useState(!1),c=u.useRef(null);u.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 d=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(PG,{})}),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}`):d(h)),t.jsx("button",{type:"button",className:"ui-btn wb-head-menu-cancel",onClick:()=>o(!1),children:"Cancel"})]})]}):null]})}let TS=!1;const MG=new Set(["missing","unconfigured","not-english"]);async function hf(e,n,s=null){const r=FI(s);try{const a=await Xe.say({text:e,...n?{conversationId:n}:{}});return LN(r)&&await IW(a.audioUrl,a.mime,s),null}catch(a){LN(r)&&Mo();const i=a instanceof fe&&a.detail&&typeof a.detail=="object"?a.detail.reason:void 0;return typeof i=="string"&&MG.has(i)&&(s!==null||!TS)?(TS=!0,a.message):null}}function OG(e,n,s){const r=L$(e);if(!r||r.rest==="")return null;const a=n.find(i=>i.roles.includes(gr));return!a||a.id===s||a.handle.toLowerCase()!==r.handle?null:{agent:a,rest:r.rest}}const _v="buddi:ask";function DG(e){const n={text:e,handled:!1};return window.dispatchEvent(new CustomEvent(_v,{detail:n})),n.handled}let Us=null;function LG(e){if(oh(e)!==null)return!1;const n=zT(e);return n!==In&&n!==ma}function FG({agent:e,agents:n,open:s,onOpenChange:r,navigate:a,timezone:i}){const l=u.useRef(null),o=u.useRef(s),c=`Ask ${e.name}`,[d,h]=u.useState(!1),[f,m]=u.useState(null);return u.useEffect(()=>{const p=x=>{const g=x.detail;!g||typeof g.text!="string"||(g.handled=!0,m({text:g.text,at:Date.now()}),r(!0))};return window.addEventListener(_v,p),()=>window.removeEventListener(_v,p)},[r]),u.useEffect(()=>{if(s||!d||!Us)return;const p=pm({url:Xe.streamUrl(Us.conversationId),lastEventId:Us.lastEventId??null,onEvent:x=>{x.name==="run.finished"&&h(!1)}});return()=>p.close()},[s,d]),u.useEffect(()=>{const p=x=>{!x.altKey||x.ctrlKey||x.metaKey||x.code!=="Slash"||(x.preventDefault(),r(!s))};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[s,r]),u.useEffect(()=>{var p;o.current&&!s&&((p=l.current)==null||p.focus()),o.current=s},[s]),s?t.jsx(zG,{agent:e,agents:n,timezone:i,navigate:a,onClose:()=>r(!1),onBusy:h,prefill:f}):t.jsxs(ed,{children:[t.jsx(td,{asChild:!0,children:t.jsx("button",{ref:l,type:"button",className:"wb-ask-fab","data-busy":d?"true":void 0,"aria-label":c,onClick:()=>r(!0),children:t.jsx(_G,{busy:d})})}),t.jsx(nd,{children:t.jsx(sd,{className:"ui-tip",side:"left",sideOffset:8,children:c})})]})}function _G({busy:e}){const[n,s]=u.useState(!1);return n?t.jsx(hd,{size:"lg"}):t.jsx(Bd,{state:e?"working":"idle",className:"wb-ask-fab-face",onStillError:()=>s(!0)})}function zG({agent:e,agents:n,timezone:s,navigate:r,onClose:a,onBusy:i,prefill:l}){const o=u.useRef(null),[c,d]=u.useState(Us&&Us.agentId===e.id?Us.conversationId:null),[h,f]=u.useState(null),[m,p]=u.useState([]),[x,g]=u.useState([]),[y,j]=u.useState(null),[v,w]=u.useState(!1),[N,k]=u.useState(!1),[S,b]=u.useState(null),[C,$]=u.useState(l??null);u.useEffect(()=>{l&&$(l)},[l]);const[A,I]=u.useState(Date.now()),[M,O]=u.useState(DI),R=u.useRef(M);R.current=M;const[_,z]=u.useState(null),[U,P]=u.useState(new Map),W=u.useRef(null),L=u.useCallback(async Se=>{try{const me=await Xe.conversation(Se);f(me),p(Ee=>Ee.filter(Pe=>!UG(me,Pe)))}catch{}},[]);u.useEffect(()=>{c&&L(c)},[c,L]),u.useEffect(()=>{if(!c)return;const Se=pm({url:Xe.streamUrl(c),onEvent:me=>{var Ee,Pe;switch(me.name){case"run.started":W.current=null,w(!0),j(null);break;case"live":{const Me=Kn(me.data.runId)??"",he=Number(me.data.turn??0),ke=me.data.kind==="thinking"?"thinking":"text",Be=Kn(me.data.text)??"",qe=Date.now();if(ke==="text"){const at=W.current;W.current=at&&at.runId===Me&&at.turn===he?{...at,text:at.text+Be}:{runId:Me,turn:he,text:Be}}j(at=>{const le=at&&at.runId===Me&&at.turn===he?at:{runId:Me,turn:he,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return ke==="thinking"?{...le,thinking:le.thinking+Be,thinkingStartedAt:le.thinkingStartedAt??qe}:{...le,text:le.text+Be,textStartedAt:le.textStartedAt??qe}});break}case"live.snapshot":{const Me=Kn(me.data.runId)??"",he=Number(me.data.turn??0),ke=Kn(me.data.text)??"",Be=Kn(me.data.thinking)??"",qe=Number(me.data.startedAt??Date.now());W.current={runId:Me,turn:he,text:ke},w(!0),j({runId:Me,turn:he,text:ke,thinking:Be,thinkingStartedAt:Be?qe:null,textStartedAt:ke?qe:null,settled:!1});break}case"live.settle":{const Me=Kn(me.data.runId)??"",he=Number(me.data.turn??0);if(me.data.retracted===!0){((Ee=W.current)==null?void 0:Ee.runId)===Me&&W.current.turn===he&&(W.current=null),j(ke=>ke&&ke.runId===Me&&ke.turn===he?null:ke);break}j(ke=>ke&&ke.runId===Me&&ke.turn===he?{...ke,settled:!0}:ke);break}case"tool.called":{const Me=Kn(me.data.toolUseId)??Kn(me.data.id),he=Kn(me.data.name)??Kn(me.data.tool)??"tool";Me&&g(ke=>[...ke.filter(Be=>Be.toolUseId!==Me),{toolUseId:Me,name:he,startedAt:Date.now()}]);break}case"tool.result":{const Me=Kn(me.data.toolUseId)??Kn(me.data.id);Me&&g(he=>he.filter(ke=>ke.toolUseId!==Me)),L(c);break}case"awaiting-approval":{const Me=Kn(me.data.approvalId)??Kn(me.data.actionId),he=Kn(me.data.toolUseId);Me&&he&&P(ke=>new Map(ke).set(he,Me)),he&&g(ke=>ke.filter(Be=>Be.toolUseId!==he)),L(c).then(()=>j(ke=>ke!=null&&ke.settled?null:ke));break}case"message.appended":L(c).then(()=>j(Me=>Me!=null&&Me.settled?null:Me));break;case"run.finished":{w(!1),g([]),j(null);const Me=Kn(me.data.message);b(Me??null);const he=((Pe=W.current)==null?void 0:Pe.text.trim())??"";W.current=null,!Me&&he!==""&&R.current&&hf(he,c).then(ke=>{ke&&z(ke)}),L(c);break}}}});return()=>{Us&&Us.conversationId===c&&(Us.lastEventId=Se.lastEventId()),Se.close()}},[c,L]),u.useEffect(()=>{i(v||N)},[v,N,i]),u.useEffect(()=>{if(x.length===0)return;const Se=window.setInterval(()=>I(Date.now()),1e3);return()=>window.clearInterval(Se)},[x.length]);const Q=(Se,me)=>{k(!0),b(null);const Ee={id:`local-${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:Se}]};p(Pe=>[...Pe,Ee]),(async()=>{try{const Pe=c??(await Xe.startConversation(e.id)).conversationId;Pe!==c&&(Us={agentId:e.id,conversationId:Pe},d(Pe));const Me=await Xe.send(e.id,{conversationId:Pe,text:Se,...me.length>0?{attachmentIds:me.map(he=>he.artifactId)}:{}});Me.conversationId!==Pe&&(Us={agentId:e.id,conversationId:Me.conversationId},d(Me.conversationId)),w(!0),L(Me.conversationId)}catch(Pe){p(Me=>Me.filter(he=>he.id!==Ee.id)),b(Pe instanceof fe?Pe.message:String(Pe)),$({text:Se,at:Date.now()})}finally{k(!1)}})()},F=(Se,me)=>{if(b(null),Se==="stop"){ae();return}if(Se==="use"){const Ee=me.replace(/^@/,"").toLowerCase(),Pe=n.find(Me=>Me.handle.toLowerCase()===Ee||Me.id===Ee);if(!Pe){z(Ee?`No agent called @${Ee}.`:"Say who: /use @handle.");return}r(lt(Pe.id));return}if(Se==="new"){const Ee=n.find(Pe=>Pe.roles.includes(gr));if(!Ee){z("There is no agent here that makes agents.");return}me.trim()&&Md(Ee.id,`I'd like a teammate for this: ${me.trim()}`),r(lt(Ee.id));return}T.quiet(me).then(Ee=>z(Ee.text)).catch(Ee=>b(Ee instanceof Error?Ee.message:String(Ee)))},ae=()=>{c&&Xe.cancel(c).catch(Se=>b(String(Se))).finally(()=>w(!1))},V=()=>{var Se;Us=null,d(null),f(null),p([]),g([]),j(null),w(!1),b(null),P(new Map),(Se=o.current)==null||Se.focus()},J=Se=>{O(Se),LI(Se),Se||Mo()},H=c?lt(e.id,c):lt(e.id),X=[...(h==null?void 0:h.messages)??[],...m],{openOffers:G,takingOffer:ce,takeOffer:xe,answeringQuestion:De,answerQuestion:B,skipQuestion:ne}=PR({conversation:h,conversationId:c,agentId:e.id,now:A,refresh:L,onRunStarted:()=>w(!0),onError:(Se,me)=>{b(Se),me&&w(!1)},navigate:r}),Z=u.useMemo(()=>xG(h,n,U),[h,n,U]),ve=Z.length===0?(h==null?void 0:h.question)??null:null,$e=Se=>{c&&L(c),T.overview().catch(()=>{}),Se.state!=="pending"&&P(me=>new Map([...me].filter(([,Ee])=>Ee!==Se.id)))};return t.jsxs(_5,{title:e.name,label:`${e.name}, a quick chat`,onClose:a,onOpenAutoFocus:Se=>{var me;Se.preventDefault(),(me=o.current)==null||me.focus()},onCloseAutoFocus:Se=>Se.preventDefault(),actions:t.jsxs(t.Fragment,{children:[t.jsx(E,{size:"sm",variant:"ghost",onClick:V,disabled:c===null&&m.length===0,children:"New"}),t.jsx(st,{size:"sm",variant:"ghost",href:H,onClick:Se=>{Se.preventDefault(),r(H)},children:"Open in Chat"})]}),children:[t.jsx("div",{className:"wb-ask-thread",children:t.jsx($y,{messages:X,live:x,now:A,working:v||N,partial:y,agents:n,agentName:e.name,agentId:e.id,onOpen:()=>r(H),onReadAloud:(Se,me)=>{z(null),hf(me,c??void 0,Se).then(Ee=>{Ee&&z(Ee)})},emptyHint:`Ask ${e.name} anything, without leaving this page.`})}),t.jsxs("div",{className:"wb-ask-compose",children:[S?t.jsx(re,{message:S}):null,t.jsx(MR,{offers:G,disabled:ce!==null,onTake:xe}),Z.length>0?t.jsx(iR,{approvals:Z,timezone:s,now:A,version:h,onDecided:$e,onSay:Se=>Q(Se,[]),onOpenFull:()=>r(H)}):ve&&Dv(ve)?t.jsx($R,{card:Dv(ve),disabled:De||v,onAnswer:B},ve.id):ve?t.jsx(IR,{question:ve,disabled:De||v,onAnswer:B,onSkip:ne},ve.id):null,t.jsxs("div",{hidden:Z.length>0||ve!==null,"data-testid":"composer-slot",children:[t.jsx(Wy,{ref:o,disabled:N||!e.available,running:v,onSend:Q,onStop:ae,agentName:e.name,placeholder:`Message ${e.name}…`,draft:C,threadKey:`dock.${c??e.id}`,conversationId:c,readAloud:M,onReadAloud:J,team:{agents:n,selfId:e.id},onCommand:F}),_?t.jsx("p",{className:"wb-voice-note",role:"status",children:_}):null]})]})]})}function Kn(e){return typeof e=="string"?e:null}function UG(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 FR=3;function BG(e){if(e==="approval"||e==="question")return"accent";if(e==="watcher"||e==="reminder")return"warm";if(e==="failure")return"critical"}function WG(e,n){return e?n?"above-dock":"above-button":"corner"}function HG({placement:e,children:n}){return t.jsx("div",{className:"wb-toast-stack","data-placement":e,children:n})}function KG(e){return e.state==="shown"&&e.seenAt===null}function VG(e){const[n,s]=u.useState([]),r=u.useRef(new Set),a=u.useRef(new Set),i=u.useCallback(()=>{e&&T.notifications(20).then(({notifications:o})=>{const c=o.filter(d=>KG(d)&&!r.current.has(d.id));s(d=>{const h=new Set(d.map(m=>m.id)),f=c.filter(m=>!h.has(m.id));return f.length===0?d:[...d,...f].sort((m,p)=>p.createdAt.localeCompare(m.createdAt))})}).catch(()=>{})},[e]);u.useEffect(()=>{for(const o of n.slice(0,FR))a.current.has(o.id)||(a.current.add(o.id),T.notificationSeen(o.id).catch(()=>{}))},[n]);const l=u.useCallback(o=>{r.current.add(o),s(c=>c.filter(d=>d.id!==o))},[]);return{queue:n,refresh:i,dismiss:l}}function GG({queue:e,agents:n,navigate:s,onDismiss:r}){if(e.length===0)return null;const a=e.slice(0,FR),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":BG(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:ad(l)}),l.text?t.jsx("div",{className:"ui-toast-body nt-toast-line",children:qG(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 ${ad(l)}`,onClick:()=>r(l.id),children:"×"})]},l.id)),i>0?t.jsxs("p",{className:"nt-toasts-more",children:["and ",i," more"]}):null]})}function qG(e){var n;return((n=e.split(`
123
+ `).find(s=>s.trim()!==""))==null?void 0:n.trim())??""}const YG=3e4,QG=1e3;function JG(e,n,s){const r=u.useRef(n);r.current=n;const a=u.useRef(s);a.current=s,u.useEffect(()=>{if(!e)return;let i=!1,l=-1/0,o=null,c=null,d=!0;const h=()=>document.visibilityState!=="hidden",f=j=>{var v;l=Date.now(),T.presence(j).catch(w=>{var N;w instanceof fe&&w.status===401&&(i=!0,(N=a.current)==null||N.call(a))}),j==="active"&&((v=r.current)==null||v.call(r))},m=j=>{if(i||(o=j,c!==null))return;const v=l+QG-Date.now();if(v<=0){o=null,f(j);return}c=window.setTimeout(()=>{if(c=null,i||o===null)return;const w=o;o=null,f(w)},v)},p=()=>{d=!0,h()&&m("active")},x=()=>{d=!1,m("away")},g=()=>m(h()?"active":"away");h()&&m("active");const y=window.setInterval(()=>{h()&&d&&m("active")},YG);return window.addEventListener("focus",p),window.addEventListener("blur",x),document.addEventListener("visibilitychange",g),()=>{i=!0,window.clearInterval(y),c!==null&&window.clearTimeout(c),window.removeEventListener("focus",p),window.removeEventListener("blur",x),document.removeEventListener("visibilitychange",g)}},[e])}function XG({agents:e,onClose:n,onCreated:s}){return YT(e)?t.jsx(ZG,{agents:cy(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 ",NB(e)," first."]})})}function ZG({agents:e,onClose:n,onCreated:s}){var j,v;const[r,a]=u.useState(""),[i,l]=u.useState([]),[o,c]=u.useState(((j=e.find(w=>w.roles.includes(_d)))==null?void 0:j.id)??((v=e[0])==null?void 0:v.id)??""),[d,h]=u.useState(!1),[f,m]=u.useState(null),p=[...new Set([o,...i])].filter(Boolean),x=r.trim()!==""&&o!==""&&p.length>=2,g=w=>l(N=>N.includes(w)?N.filter(k=>k!==w):[...N,w]),y=async()=>{h(!0),m(null);try{s==null||s(await Xe.createGroup({name:r.trim(),coordinator:o,members:p.filter(w=>w!==o)}))}catch(w){m(w instanceof fe?w.message:String(w))}finally{h(!1)}};return t.jsx(Je,{title:"A new group",onClose:n,children:t.jsxs(de,{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(se,{align:"end",children:[t.jsx(E,{onClick:n,children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:!x||d,onClick:()=>void y(),children:d?"Creating…":"Create group"})]})]})})}const e7=1e4;function pd({title:e,body:n,duration:s,onUndo:r,onGone:a}){return t.jsxs(x_,{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(v_,{className:"ui-toast-title",children:e}),n?t.jsx(j_,{className:"ui-toast-body",children:n}):null]}),r?t.jsx(w_,{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 t7=6e5,n7=5e3,s7=32,r7=256*1024,a7=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"]),i7=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"]),l7={center:"div",font:"span",big:"span",tt:"code",strike:"s",section:"div",article:"div",header:"div",footer:"div",main:"div",aside:"div",address:"div"},o7=new Set(["br","hr","wbr","col","img"]),c7=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"]),d7=new Set(["block","inline","inline-block","none","table","table-row","table-cell","list-item","flex"]),u7=/url\s*\(|expression|javascript:|vbscript:|@import|\\|behavior|binding|attr\s*\(|var\s*\(/i,h7=["gmail_quote","yahoo_quoted","protonmail_quote","moz-cite-prefix","reply-head"],f7=/^data:image\/(png|gif|jpeg|jpg|webp);base64,[a-z0-9+/=\s]+$/i;function m7(e){return e.replace(/-([a-z])/g,(n,s)=>s.toUpperCase())}function IS(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 RS(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 p7=/(^|[\s(,])-\s*(\d|\.\d)/,g7=new Set(["width","max-width","min-width","height","max-height","min-height"]);function x7(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 v7(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(!c7.has(a))continue;const i=s.getPropertyValue(a).trim();if(i===""||i.length>200||u7.test(i)||a==="display"&&!d7.has(i.toLowerCase())||p7.test(i)||/calc\s*\(/i.test(i))continue;const l=g7.has(a)?x7(i):i;l!==null&&(n[m7(a)]=l)}return n}function PS(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 _R(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 MS(e,n){if(n==="blockquote"&&(e.getAttribute("type")??"").toLowerCase()==="cite")return!0;const s=(e.getAttribute("class")??"").split(/\s+/);return h7.some(r=>s.includes(r))?!0:(e.getAttribute("id")??"")==="divRplyFwdMsg"}function OS(e){return(e.getAttribute("class")??"").split(/\s+/).includes("reply-head")||(e.getAttribute("id")??"")==="divRplyFwdMsg"}function j7(e){if(typeof e!="string"||e.trim()===""||e.length>t7)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,d=!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&&MS(p,p.tagName.toLowerCase())&&OS(p)){const g=f.slice(m).flatMap(y=>i(y,c+1,!0));g.length>0&&h.push({t:"quote",kids:g});break}h.push(...i(p,c,d))}return h},i=(o,c,d)=>{if(o.nodeType===3){const k=o.nodeValue??"";return k===""?[]:[{t:"text",v:k}]}if(o.nodeType!==1)return[];const h=o,f=h.tagName.toLowerCase();if(a7.has(f))return[];if(s.nodes>=n7)return s.truncated=!0,[];if(c>s7)return s.truncated=!0,r(h);if(s.nodes+=1,!d&&MS(h,f)&&!OS(h)){const k=a(h,c+1,!0);return k.length>0?[{t:"quote",kids:k}]:[]}if(!i7.has(f))return a(h,c+1);const m=v7(h),p=RS(h.getAttribute("bgcolor"));if(p&&!m.backgroundColor&&(m.backgroundColor=p),f==="font"){const k=RS(h.getAttribute("color"));k&&!m.color&&(m.color=k);const S=h.getAttribute("face");S&&/^[\w\s,'"-]{1,80}$/.test(S)&&!m.fontFamily&&(m.fontFamily=S)}const x=(h.getAttribute("align")??"").toLowerCase();["left","right","center","justify"].includes(x)&&!m.textAlign&&f!=="img"&&f!=="table"&&(m.textAlign=x),f==="table"&&x==="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 k=IS(h.getAttribute("width")),S=IS(h.getAttribute("height"));k&&!m.width&&(m.width=k),S&&!m.height&&f!=="table"&&(m.height=S)}const y=Object.keys(m).length>0?{style:m}:{};if(f==="img"){const k=(h.getAttribute("src")??"").trim(),S=(h.getAttribute("alt")??"").slice(0,200);return/^https?:\/\//i.test(k)?PS(h,m)?(s.pixels+=1,[]):(s.remoteImages+=1,[{t:"img",kind:"remote",src:k,alt:S,...y}]):/^cid:/i.test(k)?[{t:"img",kind:"cid",src:k.slice(4).replace(/^<|>$/g,""),alt:S,...y}]:f7.test(k)&&k.length<=r7?PS(h,m)?(s.pixels+=1,[]):[{t:"img",kind:"data",src:k,alt:S,...y}]:S?[{t:"text",v:S}]:[]}const j=o7.has(f)?[]:a(h,c+1);if(f==="a"){const k=_R(h.getAttribute("href"));return k?[{t:"link",href:k.href,outside:k.outside,...y,kids:j}]:j.length>0?[{t:"el",tag:"span",...y,kids:j}]:[]}const v={};if(f==="td"||f==="th"){const k=Number.parseInt(h.getAttribute("colspan")??"",10),S=Number.parseInt(h.getAttribute("rowspan")??"",10);k>1&&k<=100&&(v.colSpan=k),S>1&&S<=100&&(v.rowSpan=S)}if(f==="ol"){const k=Number.parseInt(h.getAttribute("start")??"",10);Number.isFinite(k)&&(v.start=k)}if(f==="table"){const k=Number.parseInt(h.getAttribute("cellpadding")??"",10),S=Number.parseInt(h.getAttribute("cellspacing")??"",10);Number.isFinite(k)&&k>=0&&k<=40&&(v.cellPadding=k),Number.isFinite(S)&&S>=0&&S<=40&&(v.cellSpacing=S)}const w=h.getAttribute("title");w&&(v.title=w.slice(0,200));const N=(h.getAttribute("dir")??"").toLowerCase();return(N==="rtl"||N==="ltr"||N==="auto")&&(v.dir=N),[{t:"el",tag:l7[f]??f,...y,...Object.keys(v).length>0?{attrs:v}:{},kids:j}]};return{nodes:a(n.body,0),remoteImages:s.remoteImages,pixels:s.pixels,truncated:s.truncated}}const w7=/(wrote|a écrit|schrieb|escribió|scrisse|schreef|написал)\s*:\s*$/i,y7=/^(-{2,}\s*(original message|forwarded message|message d'origine)\s*-{2,}|_{10,})\s*$/i,DS=2e5;function b7(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||!w7.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(y7.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 d=l;for(;d<n.length&&(n[d].startsWith(">")||n[d].trim()===""&&(n[d+1]??"").startsWith(">"));)c.push(n[d].replace(/^> ?/,"")),d+=1;const h=i();a(),s.push({t:"quote",head:h,inner:c.join(`
126
+ `)}),l=d-1;continue}r.push(o)}return a(),s}const k7=/\bhttps?:\/\/[^\s<>"'`]+/gi;function N7(e){var r,a;const n=[];let s=0;for(const i of e.matchAll(k7)){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=_R(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 zR="buddi.mail.images.v1";function UR(){try{const e=window.localStorage.getItem(zR),n=e?JSON.parse(e):[];return new Set(Array.isArray(n)?n.filter(s=>typeof s=="string"):[])}catch{return new Set}}function LS(e,n){const s=e.trim().toLowerCase();if(s!=="")try{const r=UR();n?r.add(s):r.delete(s),window.localStorage.setItem(zR,JSON.stringify([...r].slice(-500)))}catch{}}const S7=8;function BR({children:e,head:n}){const[s,r]=u.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 fh(e,n,s=""){return e.map((r,a)=>C7(r,n,`${s}${a}`))}function C7(e,n,s){switch(e.t){case"text":return e.v;case"quote":return t.jsx(BR,{children:fh(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:fh(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 u.createElement(e.tag,{key:s,...e.style?{style:e.style}:{},...e.attrs??{}},...e.kids.length>0?fh(e.kids,n,`${s}.`):[])}}function WR({text:e,depth:n=0}){const s=n>=S7?[{t:"text",v:e}]:b7(e);return t.jsx(t.Fragment,{children:s.map((r,a)=>r.t==="text"?t.jsx("div",{className:"pl-mail-text",children:N7(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(BR,{head:r.head,children:t.jsx(WR,{text:r.inner,depth:n+1})},a))})}function E7({html:e,text:n,sender:s,attachments:r,cidSrc:a}){const i=u.useMemo(()=>e?j7(e):null,[e]),l=s.trim().toLowerCase(),o=u.useMemo(()=>UR().has(l),[l]),[c,d]=u.useState(null),h=c!==null&&c.who===l?c.show:o,f=p=>d({who:l,show:p}),m=p=>{const x=p.trim().replace(/^<|>$/g,"").toLowerCase(),g=(r??[]).find(y=>typeof y.contentId=="string"&&y.contentId.trim().replace(/^<|>$/g,"").toLowerCase()===x);return g!=null&&g.artifactId?a(g.artifactId):null};if(i&&i.nodes.length>0)return t.jsxs("div",{className:"pl-mail-body",children:[i.remoteImages>0?t.jsx("div",{className:"pl-mail-images",role:"status",children:h?t.jsxs(t.Fragment,{children:[t.jsxs("span",{children:["Pictures from ",s," are shown."]}),t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>{LS(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:()=>{LS(s,!0),f(!0)},children:"Show images"})]})}):null,t.jsx("div",{className:"pl-mail-html",children:fh(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>DS;return t.jsxs("div",{className:"pl-mail-body",children:[t.jsx(WR,{text:p?n.slice(0,DS):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 ks({tone:e="accent",icon:n,title:s,href:r,onOpen:a,from:i,time:l,dismiss:o,extraDismiss:c,lead:d,actions:h,compact:f,kind:m,children:p}){const g=`${u.useId()}-title`,y=(v,w)=>t.jsx(E,{variant:"ghost",size:f?"sm":void 0,title:v.hint,disabled:v.disabled,onClick:v.onClick,children:v.label??w}),j=!!(o||c||d||h);return t.jsx(Sr,{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:v=>{a&&(v.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||d?t.jsxs("div",{className:"needs-card-out",children:[o?y(o,"Not now"):null,c?y(c,"Not this again"):null,d]}):null,h?t.jsx("div",{className:"needs-card-do",children:h}):null]}):null]})]})})}function gd({face:e,children:n}){return t.jsxs(t.Fragment,{children:[e,t.jsx("span",{className:"needs-card-from-text",children:n})]})}function Hy(e){const[n,s]=u.useState(null),[r,a]=u.useState(null),[i,l]=u.useState(null);return{busy:n,note:r,failure:i,decide:async(c,d,h,f)=>{var p,x,g,y;s(c),l(null),a(null);let m;try{const j=f?await T.decide(c,d,h,f):await T.decide(c,d,h);m={decision:d,...(p=j.execution)!=null&&p.state?{state:j.execution.state}:{},...j.execution&&"result"in j.execution?{result:j.execution.result}:{}},a(d==="reject"?`Rejected ${j.action.tool}.`:((x=j.execution)==null?void 0:x.state)==="succeeded"?`Approved and done: ${j.action.tool}.`:`Approved ${j.action.tool}: ${((g=j.execution)==null?void 0:g.state)??"no execution"}${(y=j.execution)!=null&&y.message?` (${j.execution.message})`:""}`)}catch(j){l(j instanceof Error?j.message:String(j))}finally{s(null),e(m)}}}}function A7(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 $7(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 Ky({action:e,timezone:n,busy:s,onDecide:r,agentName:a,agents:i}){var x;const[l,o]=u.useState(!1),{values:c,controls:d}=xy(e.choices),h=g=>c?r(e.id,"approve",g,c):r(e.id,"approve",g),f=!!((x=e.permissionScopes)!=null&&x.length),m=A7(e),p=$7(e.preview,m);return t.jsxs(ks,{kind:"approval",tone:"accent",icon:"lock",title:m,time:Ge(e.createdAt),from:jm(e.agentId)?t.jsxs(gd,{face:t.jsx(sI,{size:"sm"}),children:["Asked by ",vm]}):t.jsxs(gd,{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(g=>!g),"aria-expanded":l,children:l?"Hide envelope":"Show envelope"}),actions:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"danger",disabled:s,onClick:()=>r(e.id,"reject"),children:"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:f?"Allow once":"Approve"})]}),children:[p?t.jsx(_t,{children:p}):null,t.jsxs("p",{className:"ui-card-meta",children:[t.jsx("span",{className:"mono",children:e.tool})," v",e.toolVersion,". Expires ",ft(e.expiresAt,n)," (",Ge(e.expiresAt),"). Policy v",e.policyVersion,", args ",rd(e.argsHash,12),e.jobId?`, job ${rd(e.jobId)}`:"","."]}),d,l?t.jsxs("div",{className:"ui-card-foot",children:[t.jsx(ge,{title:"Envelope: everything that decides what the world will see",children:t.jsx(_t,{children:rs(e.envelope)})}),t.jsx(ge,{title:"Canonical arguments",children:t.jsx(_t,{children:rs(e.canonicalArgs)})})]}):null]})}function Vy(e,n,s){const[r,a]=u.useState(!1),[i,l]=u.useState(null),[o,c]=u.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 fe?h.message:String(h))).finally(()=>a(!1)))},busy:r,created:i,failure:o}}function HR({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 KR(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 T7(e,n){var a;const s=pe(()=>T.approvals(),[e,n],15e3);return{action:((a=s.data)==null?void 0:a.pending.find(i=>KR(i,e,n)))??null,reload:s.reload}}function FS({action:e,onDecided:n}){const{busy:s,failure:r,decide:a}=Hy(i=>n(i));return t.jsxs(de,{gap:"sm",children:[t.jsx(Ky,{action:e,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,busy:s===e.id,onDecide:(i,l,o,c)=>{a(i,l,o,c)}}),t.jsx(re,{message:r})]})}function Gy({plugin:e,agent:n,text:s,label:r,handle:a,onDismiss:i,card:l}){var p;const o=Vy(e,n),c=T7(e,n),[d,h]=u.useState(null),f=o.created??d,m=a??((p=/@(\S+)/.exec(r))==null?void 0:p[1])??n;if(f&&l)return t.jsx(ks,{kind:"offer",tone:"accent",icon:"check",title:`@${f.handle} is ready`,from:l.from,actions:t.jsxs(st,{variant:"accent",href:lt(f.id),children:["Talk to @",f.handle]})});if(f)return t.jsx(HR,{agent:f});if(c.action){const x=g=>{(g==null?void 0:g.decision)==="approve"&&g.state==="succeeded"?h({id:n,handle:m,name:m}):c.reload()};return l?t.jsx(FS,{action:c.action,onDecided:x}):t.jsxs(de,{gap:"sm",children:[t.jsx("span",{children:s}),t.jsx(FS,{action:c.action,onDecided:x})]})}return l?t.jsxs(ks,{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(re,{message:o.failure})]}):t.jsxs(de,{gap:"sm",children:[t.jsxs(se,{children:[t.jsx("span",{children:s}),t.jsx(gt,{}),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(re,{message:o.failure})]})}function VR(){var n;const e=pe(()=>T.agentOffers(),[],6e4);return{offers:((n=e.data)==null?void 0:n.offers)??[],reload:e.reload}}function GR({offers:e,reload:n}){return e.length===0?null:t.jsx(ge,{title:"From your plugins",aside:`${e.length} to decide`,panel:!0,children:t.jsx(de,{gap:"sm",divided:!0,children:e.map(s=>t.jsx(Gy,{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 I7={work:"Work",money:"Money",home:"Home",health:"Health",learning:"Learning",life:"Life"},qy=e=>I7[e]??Rm(e);function Rm(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 co(e){return e.replace(/\.0$/,"")}function R7(e){return e.avatar?T.marketAssetUrl(e.avatar):void 0}const P7={mailbox:{title:"your mailbox",fix:"Add a mailbox",route:pr("email","settings")},"image-account":{title:"a drawing account",fix:"Choose a drawing account",route:pr("image","settings")}};function Yy(e){return P7[e.replace(/\?$/,"")]??{title:e,fix:"Set it up",route:ze()}}const Pm=e=>Rm(e);function Qy(e){return e.kind==="plugin"?e.title:Yy(e.name).title}function ff(e){if(e.kind==="need"){const n=Yy(e.name);return{label:n.fix,route:n.route}}return e.fix==="enable"?{label:`Turn on ${e.title}`,route:ze("plugins")}:e.fix==="update"?{label:`Update ${e.title}`,route:ze("plugins")}:e.byBuddi?null:{label:`Install ${e.title}`,route:ze("plugins")}}function M7(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(Pm),l=e.needs.includes("mailbox")||e.needs.includes("mailbox?");return s===!0&&l&&!r.has("mailbox")&&i.push("your mailbox"),i}function ag(e){return Rm(e.replace(/\.md$/i,"").replace(/[-_]+/g," ").trim())}const _S=(e,n)=>e.includes(n),O7={email:{title:"Mail",line:e=>_S(e,"email.draft")||_S(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."}},D7={schedule:"reminder",browser:"web"};function mf(e,n=new Map){const s=[],r=new Map;for(const a of e){const i=a.replace(/\?$/,""),l=i.split(".")[0]??i,o=D7[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=O7[a],o=i.some(d=>n.get(d)==="gated"||d.endsWith(".*")&&[...n].some(([h,f])=>f==="gated"&&h.startsWith(d.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)??Rm(a),o&&!/asks you/i.test(c)?`${c} Asks you first before it changes anything.`:c]})}function zS(e){return e.length===0?"Nothing beyond its own chat.":`Reaches ${ln(e.map(([n])=>n))}.`}function pf(e){return new Map((e??[]).filter(n=>n.tier).map(n=>[n.name,n.tier]))}function ol({entry:e,size:n}){const s=R7(e);return t.jsx("span",{className:"cat-face","data-size":n,children:t.jsx(Rn,{id:e.name,name:e.title,size:n==="xxl"?"xl":n,face:{tools:e.tools,...s?{picture:s}:{}}})})}const qR=800,L7=e=>{var n;return((n=/^.*?[.!?](?=\s|$)/.exec(e.trim()))==null?void 0:n[0])??e.trim()},Yl=e=>e instanceof fe?e.message:String(e);function ia({entry:e,children:n}){return t.jsxs("span",{className:"plugins-sheet-title",children:[t.jsx(ol,{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(Ce,{tone:"accent",children:"by buddi"})]}):null]})]})]})}function ig({state:e,children:n}){return t.jsxs("li",{className:"cat-step","data-state":e,children:[t.jsx("span",{className:"cat-step-mark",children:e==="done"?t.jsx(ie,{name:"check",size:12}):e==="failed"?t.jsx(ie,{name:"alert",size:14}):null}),t.jsx("span",{children:n})]})}function lg(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 F7(e){const[n,s]=u.useState(null),[r,a]=u.useState(null);return u.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,qR)))}).catch(c=>{i||a(Yl(c))})};return o(),()=>{i=!0,l!==void 0&&window.clearTimeout(l)}},[e]),{job:n,error:r,setJob:s}}function Jy({entry:e,navigate:n,onClose:s,onAdded:r}){var De;const a=Gn("(max-width: 720px)"),[i,l]=u.useState(null),[o,c]=u.useState(null),[d,h]=u.useState({}),[f,m]=u.useState(""),[p,x]=u.useState([]),[g,y]=u.useState(!1),[j,v]=u.useState(null),[w,N]=u.useState(!1),[k,S]=u.useState(null),{job:b,error:C,setJob:$}=F7(j),[A,I]=u.useState(!1),[M,O]=u.useState(null),[R,_]=u.useState(!1),z=u.useRef(!1),[U,P]=u.useState([]);u.useEffect(()=>{if(!i||i.plugins.length===0)return;let B=!1;return Promise.resolve().then(()=>T.market()).then(ne=>{B||P((ne==null?void 0:ne.plugins)??[])}).catch(()=>{}),()=>{B=!0}},[i]),u.useEffect(()=>{let B=!1;return T.cataloguePlan(e.name).then(ne=>{B||(l(ne),h(Object.fromEntries(ne.fills.map(Z=>[Z.id,Z.value]))),m(ne.handle))}).catch(ne=>{B||c(Yl(ne))}),()=>{B=!0}},[e.name]),u.useEffect(()=>{(b==null?void 0:b.state)==="done"&&b.agent&&!z.current&&(z.current=!0,r==null||r(b.agent))},[b,r]);const W=()=>{i&&(N(!0),S(null),z.current=!1,T.catalogueInstall(e.name,{version:i.version,fills:d,handle:f,missionsOn:p,tools:i.tools.map(B=>B.name)}).then(B=>v(B.jobId)).catch(B=>S(Yl(B))).finally(()=>N(!1)))},L=()=>{v(null),W()},Q=e.title,F=b==null?void 0:b.agent,ae=B=>{F&&(B&&Md(F.id,B),s(),n(lt(F.id)))},V=B=>{b&&(I(!0),O(null),T.catalogueConfirm(b.id,B).then(ne=>{$(ne),B||s()}).catch(ne=>O(Yl(ne))).finally(()=>I(!1)))};if((b==null?void 0:b.state)==="confirm"&&b.confirm){const B=mf(b.confirm.tools.map(Z=>Z.name),pf(b.confirm.tools)),ne=b.steps.filter(Z=>Z.kind==="plugin"&&Z.state==="done").map(Z=>Z.title);return t.jsxs(Je,{title:t.jsxs(ia,{entry:e,children:["Add ",Q]}),onClose:s,foot:t.jsxs(se,{children:[t.jsx(gt,{}),t.jsx(E,{variant:"ghost",disabled:A,onClick:()=>V(!1),children:"Don’t add it"}),t.jsxs(E,{variant:"accent",disabled:A,onClick:()=>V(!0),children:["Add ",Q]})]}),children:[t.jsx("ol",{className:"cat-steps","data-testid":"cat-confirm",children:b.steps.filter(Z=>Z.kind==="plugin").map(Z=>{const{state:ve,words:$e}=lg(Z);return t.jsx(ig,{state:ve,children:$e},`${Z.kind}-${Z.name}`)})}),t.jsxs(q,{tone:"warning",title:`${Q} would get more than the list showed.`,children:[ne.length>0?`With ${ln(ne)} installed, `:"","its tools resolved to a different set",b.confirm.unshown.length>0?`, including ${ln(b.confirm.unshown)}`:"",". Look at what it can reach before you add it."]}),t.jsx(re,{message:M}),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:[zS(B)," ",t.jsx("button",{type:"button",className:"plugins-link cat-link",onClick:()=>_(!R),children:R?"Hide":"See all"})]}),R?t.jsx("dl",{className:"cat-reach",children:B.map(([Z,ve])=>t.jsxs("div",{className:"cat-reach-row",children:[t.jsx("dt",{children:Z}),t.jsx("dd",{children:ve})]},Z))}):null]}),t.jsx("p",{className:"cat-small",children:"The plugins stay installed either way; Settings → Plugins removes them."})]})}if(j&&(!b||b.state==="running")){const B=b==null?void 0:b.steps[b.steps.length-1],ne=(b==null?void 0:b.approvalId)&&(B==null?void 0:B.state)==="adding";return t.jsxs(Je,{title:t.jsxs(ia,{entry:e,children:["Add ",Q]}),onClose:s,foot:t.jsx(se,{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:((b==null?void 0:b.steps)??[]).map(Z=>{const{state:ve,words:$e}=lg(Z);return t.jsx(ig,{state:ve,children:$e},`${Z.kind}-${Z.name}`)})}),ne?t.jsxs(q,{tone:"accent",action:t.jsx(E,{size:"sm",onClick:()=>{s(),n(ao)},children:"Open it"}),children:["Adding ",Q," waits for your approval in Needs you."]}):null,t.jsx(re,{message:C}),t.jsxs("p",{className:"cat-small",children:["You can close this; it carries on, and ",Q," joins the team when it’s done."]})]})}if((b==null?void 0:b.state)==="done"){const B=b.steps.filter(ve=>ve.kind==="plugin").map(ve=>ve.title),ne=(i==null?void 0:i.missions.length)??e.missions.length,Z=p.length;return t.jsxs(Je,{title:t.jsx(ia,{entry:e,children:Q}),onClose:s,foot:t.jsxs(se,{children:[t.jsx(E,{variant:"ghost",onClick:()=>{s(),n(mn())},children:"Back to teammates"}),t.jsx(gt,{}),t.jsx(E,{variant:"accent",onClick:()=>ae(),children:"Say hello"})]}),children:[t.jsxs("div",{className:"cat-done","data-testid":"cat-done",children:[t.jsx(ol,{entry:e,size:"xxl"}),t.jsxs("p",{className:"cat-done-title",children:[Q," is on your team."]}),t.jsxs("p",{className:"cat-small",children:["@",(F==null?void 0:F.handle)??f,B.length?` · ${ln(B)} 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(ve=>t.jsx("button",{type:"button",className:"wb-starter",onClick:()=>ae(ve),children:ve},ve))})]}):null]})}if((b==null?void 0:b.state)==="failed"){const B=b.steps.find(ne=>ne.kind==="plugin"&&ne.state==="failed");return t.jsxs(Je,{title:t.jsxs(ia,{entry:e,children:[Q," wasn’t added"]}),onClose:s,foot:t.jsxs(se,{children:[t.jsx(gt,{}),t.jsx(E,{variant:"ghost",onClick:s,children:"Close"}),t.jsx(E,{variant:"accent",disabled:w,onClick:L,children:"Try again"})]}),children:[t.jsx("ol",{className:"cat-steps","data-testid":"cat-failed",children:b.steps.map(ne=>{const{state:Z,words:ve}=lg(ne);return t.jsx(ig,{state:Z==="now"?"next":Z,children:Z==="now"?ve.replace(/…$/,""):ve},`${ne.kind}-${ne.name}`)})}),t.jsx(q,{tone:"critical",title:`${b.error??"It stopped before it finished"}.`,action:b.approvalId?t.jsx(E,{size:"sm",onClick:()=>{s(),n(ao)},children:"Open the approval"}):void 0,children:t.jsxs("p",{children:["Nothing was added and nothing else changed.",B?t.jsxs(t.Fragment,{children:[" ",B.title," waits in"," ",t.jsx("a",{href:ze("plugins"),onClick:ne=>{ne.preventDefault(),s(),n(ze("plugins"))},children:"Settings → Plugins"})," ","if you’d rather look at it there."]}):null]})}),t.jsx(re,{message:k})]})}const J=(i==null?void 0:i.plugins.filter(B=>B.fix==="install"&&B.byBuddi))??[],H=(i==null?void 0:i.blocked)??[],X=H[0],G=X?ff(X):null,ce=mf(i?i.tools.map(B=>B.name):e.tools,pf([...((De=e.claims)==null?void 0:De.tools)??[],...((i==null?void 0:i.tools)??[]).filter(B=>B.tier!=="unknown")])),xe=B=>{var ne;return((ne=e.missions.find(Z=>Z.id===B))==null?void 0:ne.when)??""};return t.jsxs(Je,{title:t.jsxs(ia,{entry:e,children:["Add ",Q]}),onClose:s,foot:t.jsxs(se,{children:[a?null:t.jsx("span",{className:"plugins-foot-note",children:J.length?`Installs ${ln(J.map(B=>B.title))}, then adds ${Q}.`:"Nothing runs until you add it."}),t.jsx(gt,{}),t.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsxs(E,{variant:"accent",disabled:!i||H.length>0||w||f.length<2,onClick:W,children:["Add ",Q]})]}),children:[t.jsxs("p",{className:"cat-lede",children:[e.pitch," One approval adds it; you can change or remove it from its page."]}),t.jsx(re,{message:o??k}),!i&&!o?t.jsx(be,{children:"Reading what it needs…"}):i?t.jsxs(de,{divided:!0,gap:"lg",children:[J.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:J.map(B=>{const ne=U.find(Z=>Z.name===B.name);return t.jsxs("li",{children:[t.jsx(Yn,{svg:ne==null?void 0:ne.iconSvg}),t.jsxs("span",{className:"cat-plugin-text",children:[t.jsxs("span",{className:"cat-plugin-name",children:[B.title," ",B.version?t.jsx("span",{className:"plugins-ver",children:B.version}):null]}),t.jsx("span",{className:"cat-small",children:ne!=null&&ne.summary?L7(ne.summary):"Made by buddi; installed only if it matches what withbuddi.com lists."})]}),t.jsx(Ce,{tone:"accent",children:"by buddi"})]},B.name)})})]}):null,X?t.jsxs(q,{tone:"warning",action:G?t.jsx(E,{size:"sm",onClick:()=>{s(),n(G.route)},children:G.label}):void 0,children:[Q," needs ",ln(H.map(Qy))," first. Add ",H.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(B=>t.jsx(oe,{label:t.jsxs(t.Fragment,{children:[B.label,B.optional?t.jsx("span",{className:"faint",children:" · optional"}):null]}),children:B.choices&&B.choices.length>0?t.jsxs("select",{value:d[B.id]??"",onChange:ne=>h({...d,[B.id]:ne.target.value}),children:[B.kind==="calendar"?t.jsx("option",{value:"",children:"All of them"}):null,B.choices.map(ne=>t.jsx("option",{value:ne,children:ne},ne))]}):B.kind==="time"?t.jsx("input",{type:"time",value:d[B.id]??"",onChange:ne=>h({...d,[B.id]:ne.target.value})}):t.jsx("input",{value:d[B.id]??"",onChange:ne=>h({...d,[B.id]:ne.target.value})})},B.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:B=>m(B.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(B=>t.jsxs("li",{children:[t.jsx("span",{className:"cat-mission-name",children:B.name}),t.jsx("span",{className:"cat-mission-when",children:xe(B.id)}),t.jsx(Wd,{checked:p.includes(B.id),label:`Turn on ${B.name}`,onChange:ne=>x(ne?[...p,B.id]:p.filter(Z=>Z!==B.id))})]},B.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:[zS(ce)," ",t.jsx("button",{type:"button",className:"plugins-link cat-link",onClick:()=>y(!g),children:g?"Hide":"See all"})]}),g?t.jsx("dl",{className:"cat-reach",children:ce.map(([B,ne])=>t.jsxs("div",{className:"cat-reach-row",children:[t.jsx("dt",{children:B}),t.jsx("dd",{children:ne})]},B))}):null]})]}):null]})}function _7(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 US({lines:e,label:n}){return t.jsx("div",{className:"cat-diff",role:"region","aria-label":n,children:_7(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 YR({entry:e,agentId:n,onClose:s,onUpdated:r}){const[a,i]=u.useState(null),[l,o]=u.useState(null),[c,d]=u.useState(!1),[h,f]=u.useState(!1),[m,p]=u.useState(!1);u.useEffect(()=>{let w=!1;return T.catalogueUpdatePlan(e.name,n).then(N=>{w||i(N)}).catch(N=>{w||o(Yl(N))}),()=>{w=!0}},[e.name,n]);const x=co((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(Yl(N)),T.catalogueUpdatePlan(e.name,n).then(i).catch(()=>{})}).finally(()=>f(!1)))};if(m)return t.jsx(Je,{title:t.jsxs(ia,{entry:e,children:[e.title," ",x]}),onClose:s,foot:t.jsx(se,{align:"end",children:t.jsx(E,{variant:"accent",onClick:s,children:"Done"})}),children:t.jsx(q,{tone:"good",title:`${e.title} is on ${x}.`,role:"status",children:a!=null&&a.edited?"Your version is in the trash folder if you want any of it back.":"Your picks and missions are as they were."})});if(!a)return t.jsxs(Je,{title:t.jsxs(ia,{entry:e,children:["Update ",e.title]}),onClose:s,children:[t.jsx(re,{message:l}),l?null:t.jsx(be,{children:"Reading what changed…"})]});const y=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(ia,{entry:e,children:[e.title," ",x," is out"]}),onClose:s,foot:t.jsxs(se,{children:[c?null:t.jsx(E,{variant:"ghost",onClick:()=>d(!0),children:"See what changed"}),t.jsx(gt,{}),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?`${x} 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(re,{message:l}),t.jsxs(de,{divided:!0,gap:"lg",children:[t.jsxs("div",{className:"cat-block",children:[t.jsxs("h3",{className:"cat-block-title",children:["New in ",x]}),t.jsx("p",{className:"cat-prose",children:a.changes})]}),t.jsxs("div",{className:"cat-block",children:[t.jsxs("h3",{className:"cat-block-title",children:["Your file and ",x," ",t.jsx("button",{type:"button",className:"cat-block-aside plugins-link",onClick:()=>d(!c),children:c?"Hide":"See what changed"})]}),c?t.jsxs(t.Fragment,{children:[t.jsx(US,{lines:a.personaDiff,label:`Your ${e.title} against ${x}`}),t.jsxs("p",{className:"cat-small",children:["Lines marked − are in your file and not in ",x,"; + is new in ",x,". Replacing keeps your picks, and drops what you wrote by hand."]})]}):t.jsxs("p",{className:"cat-small",children:[j===1?"1 line":`${j} lines`," only in your file, ",y===1?"1 line":`${y} lines`," new in ",x,"."]})]})]})]});const v=a.added.length>0?`New: ${ln(mf(a.added.map(w=>w.name),pf(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(ia,{entry:e,children:["Update ",e.title," to ",x]}),onClose:s,foot:t.jsxs(se,{children:[t.jsx("span",{className:"plugins-foot-note",children:"Your picks and handle stay."}),t.jsx(gt,{}),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(re,{message:l}),t.jsxs(de,{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(US,{lines:a.personaDiff,label:a.via?`@${a.handle} against ${e.title} ${x}`:`${e.title} ${co(a.fromVersion)} against ${x}`}):t.jsx("p",{className:"cat-prose",children:"Its persona stays word for word."})]}),t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"What it can reach"}),t.jsxs("p",{className:"cat-prose",children:[v,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:[x," no longer has ",ln(a.retires),"; ",a.retires.length===1?"it goes":"they go"," to the trash folder."]})]}):null]})]})}function As(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 Xy(){const e=pe(()=>T.plugins(),[]);return u.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 Zy(){return t.jsx(ie,{name:"check",size:14})}function z7({entry:e,loaded:n,mailbox:s}){const r=As(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(Qy))]})});if(r!=="ready")return null;const i=M7(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 U7({entry:e,onAdd:n,onUpdate:s}){const r=As(e),a=i=>l=>{l.stopPropagation(),i()};return r==="added"?t.jsxs("span",{className:"cat-added",children:[t.jsx(Zy,{}),"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 B7({entry:e}){var a,i,l,o;const n=As(e),s=co(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 QR({entry:e,loaded:n,mailbox:s,onOpen:r,onAdd:a,onUpdate:i}){return t.jsx("div",{className:"cat-card","data-state":As(e),"data-testid":`cat-card-${e.name}`,children:t.jsxs(Sr,{onClick:r,label:`${e.title}: details`,children:[t.jsxs("div",{className:"cat-card-head",children:[t.jsx(ol,{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:qy(e.category)})]})]}),t.jsx("p",{className:"cat-pitch",children:e.pitch}),t.jsx(B7,{entry:e}),t.jsxs("div",{className:"cat-card-foot",children:[t.jsx(z7,{entry:e,loaded:n,mailbox:s}),t.jsx(gt,{}),t.jsx(U7,{entry:e,onAdd:a,onUpdate:i})]})]})})}function W7({row:e,agents:n,navigate:s,pages:r}){const a=Vy(e.plugin,e.agent,()=>window.dispatchEvent(new Event(xs))),i=a.created??(e.state==="installed"?{id:e.agent,handle:e.handle,name:e.name}:null),l=r?iv(e.plugin,r.all):Pm(e.plugin);return t.jsx("div",{className:"cat-card","data-state":i?"added":"ready","data-testid":`cat-card-${e.agent}`,children:t.jsxs(Sr,{onClick:i?()=>s(Pt(i.id)):void 0,label:i?`Open @${i.handle}`:void 0,children:[t.jsxs("div",{className:"cat-card-head",children:[t.jsx("span",{className:"cat-face","data-size":"lg",children:t.jsx(Rn,{id:e.agent,name:e.name,size:"lg",face:n.find(o=>o.id===e.agent)})}),t.jsxs("div",{className:"cat-card-name",children:[t.jsx("h3",{className:"ui-card-title",children:e.name}),t.jsxs("div",{className:"cat-card-kind",children:["From ",l]})]})]}),t.jsx("p",{className:"cat-pitch",children:e.text}),i?t.jsxs("p",{className:"cat-note","data-quiet":"true",children:["On your team as @",i.handle]}):null,t.jsxs("div",{className:"cat-card-foot",children:[t.jsx(re,{message:a.failure}),t.jsx(gt,{}),i?t.jsxs("span",{className:"cat-added",children:[t.jsx(Zy,{}),"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 H7({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 K7(e,n,s){const r=e.find(a=>a.roles.includes(gr));r&&(s.trim()&&Md(r.id,`I'd like a teammate for this: ${s.trim()}`),n(lt(r.id)))}function V7({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(YR,{entry:i,agentId:i.installed.agentId,onClose:r,onUpdated:a}):t.jsx(Jy,{entry:i,navigate:s,onClose:r,onAdded:a})}const G7=[{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 q7(e,n){return[e.title,e.pitch,e.about,e.description,qy(e.category)].some(s=>s.toLowerCase().includes(n))}function Y7({name:e,agents:n,navigate:s,pluginPages:r}){const[a,i]=u.useState(0),l=pe(()=>T.catalogue(a>0),[a]),o=Xy(),[c,d]=u.useState(""),[h,f]=u.useState("all"),[m,p]=u.useState(null),x=l.data,g=()=>{l.reload(),window.dispatchEvent(new Event(xs))},y=()=>i($=>$+1),j=t.jsx(V7,{sheet:m,view:x,navigate:s,onClose:()=>p(null),onChanged:g}),v=e?x==null?void 0:x.agents.find($=>$.name===e):void 0,w=u.useRef(!1);if(u.useEffect(()=>{w.current||!v||!j6(window.location.hash,v.name)||(w.current=!0,As(v)==="ready"&&p({kind:"install",name:v.name}))},[v]),e&&x&&!x.unavailable&&v)return t.jsxs(t.Fragment,{children:[t.jsx(X7,{entry:v,loaded:o,agents:n,navigate:s,onAdd:()=>p({kind:"install",name:v.name}),onUpdate:()=>p({kind:"update",name:v.name})}),j]});const N=c.trim().toLowerCase(),S=((x==null?void 0:x.agents)??[]).filter($=>(h==="all"||$.category===h)&&(!N||q7($,N))),b=((x==null?void 0:x.fromPlugins)??[]).filter($=>h==="all"&&(!N||[$.name,$.text,$.description].some(A=>A.toLowerCase().includes(N)))),C=$=>()=>s($);return t.jsxs(py,{children:[t.jsx(_i,{before:t.jsx(Nc,{inline:!0,items:[{label:"Agents",href:yt,onClick:C(yt)}]}),title:"Add a teammate",lede:"Agents tested with the plugins they use. Adding one is one approval, and it becomes a file on this computer you can change."}),e&&x&&!x.unavailable&&!v?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(Cm,{label:"Search teammates",value:c,placeholder:"Search: meals, money, a language…",onChange:d})]}),t.jsx("div",{className:"cat-cats",children:t.jsx(vI,{label:"Category",options:G7,value:h,onChange:f})})]}),x&&!x.unavailable?x.stale?t.jsxs("p",{className:"plugins-quiet","data-testid":"cat-stale",children:[t.jsx(ie,{name:"globe",size:14}),"From the list kept ",x.fetchedAt?Q7(x.fetchedAt):"earlier",": withbuddi.com didn’t answer just now."," ",t.jsx("button",{type:"button",className:"plugins-link",onClick:y,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&&!x?t.jsx(be,{warm:!0,title:"The catalogue didn’t load",action:t.jsx(E,{variant:"accent",size:"sm",onClick:y,children:"Try again"}),children:l.error}):x?x.unavailable?t.jsx(be,{warm:!0,title:"The catalogue needs withbuddi.com",action:t.jsx(E,{variant:"accent",size:"sm",disabled:l.loading,onClick:y,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."}):S.length+b.length>0?t.jsxs("div",{className:"cat-grid","data-testid":"cat-grid",children:[S.map($=>t.jsx(QR,{entry:$,loaded:o,mailbox:x.mailbox,onOpen:()=>s(mn($.name)),onAdd:()=>p({kind:"install",name:$.name}),onUpdate:()=>p({kind:"update",name:$.name})},$.name)),b.map($=>t.jsx(W7,{row:$,agents:n,navigate:s,pages:r},`${$.plugin}/${$.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:()=>{d(""),f("all")},children:"Show all"}),t.jsx(E,{size:"sm",variant:"accent",onClick:()=>K7(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(H7,{}),x&&!x.unavailable&&x.delisted.length>0?t.jsx(rt,{title:"No longer in the catalogue",children:t.jsx("ul",{className:"cat-plugins","data-testid":"cat-delisted",children:x.delisted.map($=>t.jsxs("li",{children:[t.jsx(an,{agents:n,id:$.agentId,size:"sm"}),t.jsxs("span",{className:"cat-plugin-text",children:[t.jsx("a",{className:"cat-plugin-name",href:Pt($.agentId),onClick:A=>{A.preventDefault(),s(Pt($.agentId))},children:$.name??`@${$.handle}`}),t.jsxs("span",{className:"cat-small",children:["@",$.handle," keeps working as it is; no updates will come."]})]})]},$.agentId))})}):null,j]})}function Q7(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 Ci({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 J7({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),d=c?ff(c):null,h=o?Yy(i).title:(c==null?void 0:c.kind)==="plugin"?c.title:Pm(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"})]}),d?t.jsx(E,{size:"sm",onClick:()=>s(d.route),children:d.label}):c?t.jsx("span",{className:"cat-small",children:"Installed when you add it"}):f?t.jsxs("span",{className:"cat-added",children:[t.jsx(Zy,{}),o?"You have one":"Installed"]}):t.jsx("span",{className:"cat-small",children:o?"Optional":"Not installed"})]},`${o?"need":"plugin"}-${i}`)})})}function X7({entry:e,loaded:n,agents:s,navigate:r,onAdd:a,onUpdate:i}){var x,g,y,j;const l=As(e),c=(x=e.installed)==null?void 0:x.agentId,d=co(e.version),h=(g=e.installed)!=null&&g.via?e.installed:void 0,f=v=>{c&&(v&&Md(c,v),r(lt(c)))},m=mf(e.tools,pf((y=e.claims)==null?void 0:y.tools)),p=e.replaces.map(v=>ag(v.split("/")[1]??v));return t.jsxs(py,{children:[t.jsxs("a",{className:"cat-back",href:mn(),onClick:v=>{v.preventDefault(),r(mn())},children:[t.jsx(ie,{name:"chevron-left",size:12}),"Teammates"]}),t.jsxs("header",{className:"cat-hero",children:[t.jsx(ol,{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(Ce,{tone:"accent",children:"by buddi"}):null,t.jsx("span",{children:qy(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 ${d}`})]}):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 ",d," 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(rt,{flush:!0,children:t.jsxs("div",{className:"cat-rows",children:[t.jsxs(Ci,{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(Ci,{title:"Ask it",children:[t.jsx("div",{className:"wb-starters",children:e.examples.map(v=>t.jsx("button",{type:"button",className:"wb-starter",disabled:!c,onClick:()=>f(v),children:v},v))}),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(Ci,{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(v=>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:ag(v.name)}),v.description?t.jsx("span",{className:"cat-small",children:v.description}):null,t.jsx(Kt,{summary:"Read it",children:t.jsx(_t,{label:`${ag(v.name)}: the skill's text`,children:v.text})})]})]},v.name))}),t.jsxs("p",{className:"cat-small",children:["Plain text, no code."," ",c?t.jsxs(t.Fragment,{children:["Read and change them on ",t.jsx("a",{href:Pt(c,"skills"),onClick:v=>{v.preventDefault(),r(Pt(c,"skills"))},children:"its Skills tab"}),"."]}):"Once it’s on your team they’re files you can read and change."]})]})}),t.jsxs(Ci,{title:"What it can reach",children:[t.jsx("dl",{className:"cat-reach",children:m.map(([v,w])=>t.jsxs("div",{className:"cat-reach-row",children:[t.jsx("dt",{children:v}),t.jsx("dd",{children:w})]},v))}),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(Ci,{title:"Missions",children:e.missions.length>0?t.jsx("ul",{className:"cat-missions",children:e.missions.map(v=>t.jsxs("li",{children:[t.jsx("span",{className:"cat-mission-name",children:v.name}),t.jsx("span",{className:"cat-mission-when",children:v.when}),t.jsx("span",{className:"cat-off",children:"off until you turn it on"})]},v.id))}):t.jsx("p",{className:"cat-small",children:"None. It works when you ask."})}),t.jsx(Ci,{title:"Plugins",children:t.jsx(J7,{entry:e,loaded:n,navigate:r})}),t.jsxs(Ci,{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 JR({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 Z7(e,n,s=4){const r=i=>!!i&&As(i)==="ready"&&i.addable,a=JR(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 BS=["researcher","tutor"];function WS(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 eq(e,n,s=4){const r=[];for(const a of JR(n).filter(i=>!BS.includes(i))){const i=e.find(h=>h.name===a);if(!i||As(i)!=="ready")continue;if(i.addable){r.push({entry:i,reason:WS(a,n)});continue}const l=i.missing??[],o=l.find(h=>ff(h)!==null)??l[0];if(!o)continue;const c=ff(o),d=c?c.label.charAt(0).toLowerCase()+c.label.slice(1):`${Qy(o)} is here`;r.push({entry:i,reason:WS(a,n),blocked:{step:d,fix:c}})}for(const a of BS){if(r.length>=3)break;const i=e.find(l=>l.name===a);i&&As(i)==="ready"&&i.addable&&r.push({entry:i,reason:"popular"})}return r.slice(0,s)}const tq={image:"makes pictures",finance:"keeps your books",calendar:"looks after your days",email:"reads your mail"};function XR(e,n){const s=tq[e];return s?`Nobody ${s} yet`:`Nobody uses ${n??e.charAt(0).toUpperCase()+e.slice(1)} yet`}function ZR(e,n){const s=e.filter(r=>Object.keys(r.requires??{}).includes(n));if(!s.some(r=>As(r)!=="ready"&&As(r)!=="unavailable"))return s.find(r=>As(r)==="ready")}function HS(e,n){const s=[];for(const r of n){const a=ZR(e,r);a&&!s.some(i=>i.entry.name===a.name)&&s.push({plugin:r,entry:a})}return s}const $c=e=>`teammate:${e}`;function eP({plugin:e,title:n,navigate:s,dismissible:r=!1}){const[a,i]=u.useState(null),[l,o]=u.useState(!1),[c,d]=u.useState(!1),[h,f]=u.useState(!1);if(u.useEffect(()=>{let p=!1;return Promise.resolve().then(()=>T.catalogue()).then(async x=>{const g=x.unavailable?void 0:ZR(x.agents,e);return!g||!r?g??null:(await Promise.resolve().then(()=>T.overview()).then(j=>j.dismissed??{},()=>({})))[$c(e)]!==g.name?g:null}).then(x=>{p||i(x)}).catch(()=>{p||i(null)}),()=>{p=!0}},[e,r]),!a||c||h)return null;const m=()=>{f(!0),T.homeDismiss($c(e),a.name).catch(()=>f(!1))};return t.jsxs(t.Fragment,{children:[t.jsx(q,{action:t.jsxs(se,{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:XR(e,n)})}),l?t.jsx(Jy,{entry:a,navigate:s,onClose:()=>o(!1),onAdded:()=>{d(!0),window.dispatchEvent(new Event(xs))}}):null]})}function nq(e,n){const s=e.filter(r=>r.id!==n&&!r.roles.includes(_d)&&!r.roles.includes(gr));return e.length>0&&s.length<=1}async function sq(e,n=qR){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 fe?s.message:String(s)}}}function rq({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(ol,{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 aq({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(ol,{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 iq({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(ol,{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 lq({navigate:e,newTeam:n=!0,closed:s}){const[r,a]=u.useState(null),[i,l]=u.useState(null),[o,c]=u.useState([]),d=Xy();u.useEffect(()=>{let m=!1;return T.catalogue().then(p=>{m||a(p.unavailable?[]:p.agents)}).catch(()=>{m||a([])}),()=>{m=!0}},[]);const h=u.useMemo(()=>r===null?[]:HS(r,d).filter(m=>!(s!=null&&s.is($c(m.plugin),m.entry.name))),[r,d,s]),f=u.useMemo(()=>{if(r===null)return null;const m=h.map(g=>g.entry);if(!n)return m;const p=new Set(HS(r,d).filter(g=>s==null?void 0:s.is($c(g.plugin),g.entry.name)).map(g=>g.entry.name)),x=Z7(r,{days:!0,mailbox:!0,money:d.has("finance"),pictures:d.has("image")},3+p.size).filter(g=>!m.some(y=>y.name===g.name)&&!p.has(g.name));return[...m,...x].slice(0,Math.max(3,m.length))},[r,d,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(x=>x.entry.name===m.name);return t.jsx(iq,{entry:m,added:o.includes(m.name),onOpen:()=>e(mn(m.name)),onAdd:()=>l(m),...p&&s&&!o.includes(m.name)?{onDismiss:()=>s.close($c(p.plugin),m.name),why:XR(p.plugin)}:{}},m.name)})}),i?t.jsx(Jy,{entry:i,navigate:e,onClose:()=>l(null),onAdded:()=>{c(m=>[...m,i.name]),window.dispatchEvent(new Event(xs))}}):null]})}function oq(){const[e,n]=u.useState(null);return u.useEffect(()=>{let s=!1;const r=()=>{Promise.resolve().then(()=>Xe.agents()).then(a=>{s||n(((a==null?void 0:a.agents)??[]).filter(i=>!i.roles.includes(gr)).map(i=>i.name))}).catch(()=>{s||n(a=>a??[])})};return r(),window.addEventListener(xs,r),()=>{s=!0,window.removeEventListener(xs,r)}},[]),e}function cq({setUp:e,navigate:n}){var S;const s=oq(),[r,a]=u.useState(null),[i,l]=u.useState([]),[o,c]=u.useState("picking"),[d,h]=u.useState([]),[f,m]=u.useState([]),p=JSON.stringify(e);u.useEffect(()=>{let b=!1;return T.catalogue().then(C=>{if(b)return;const $=C.unavailable?[]:eq(C.agents,e);a($),l($.filter(A=>!A.blocked).map(A=>A.entry.name))}).catch(()=>{b||a([])}),()=>{b=!0}},[p]);const x=s??[];if(!r||r.length===0&&x.length===0)return null;const g=x.length===0?null:t.jsxs("p",{className:"cat-small","data-testid":"handover-team-now",children:["On your team: ",ln(x),"."]}),y=r.filter(b=>!b.blocked).map(b=>b.entry),j=r.some(b=>!b.blocked&&b.reason!=="popular"),v=()=>n(mn()),w=async()=>{c("adding");const b=[],C=[];for(const $ of y.filter(A=>i.includes(A.name))){const A=await sq($);"error"in A&&!("state"in A)?C.push({entry:$,error:A.error}):A.state==="done"?b.push($):A.state==="confirm"?C.push({entry:$,error:"it gets more than its card showed, so it waits for your approval in Needs you"}):C.push({entry:$,error:A.error??"it stopped before it finished"})}h(b),m(C),c("added"),b.length>0&&window.dispatchEvent(new Event(xs))},N=i.length,k=o==="adding"?`Adding ${N===1?((S=y.find(b=>b.name===i[0]))==null?void 0:S.title)??"1":N}…`:N>0&&N===y.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:[d.length>0?t.jsxs(q,{tone:"good",role:"status",title:`${ln(d.map(b=>b.title))} ${d.length===1?"is":"are"} on your team.`,action:t.jsx(E,{variant:"ghost",size:"sm",onClick:v,children:"See all teammates"}),children:["Say hello in Chat. ",d.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(b=>b.entry.title))} ${f.length===1?"wasn’t":"weren’t"} added.`,action:d.length===0?t.jsx(E,{variant:"ghost",size:"sm",onClick:v,children:"See all teammates"}):void 0,children:[f.map(b=>`${b.entry.title}: ${b.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(b=>b.blocked?t.jsx(aq,{suggestion:b,onFix:n},b.entry.name):t.jsx(rq,{entry:b.entry,reason:b.reason,checked:i.includes(b.entry.name),onChange:C=>l(C?[...i,b.entry.name]:i.filter($=>$!==b.entry.name))},b.entry.name))}),t.jsx("div",{className:"handover-team-foot",children:t.jsxs(se,{children:[t.jsx(E,{variant:"ghost",onClick:v,children:"See all teammates"}),t.jsx(gt,{}),t.jsx(E,{variant:"accent",disabled:N===0||o==="adding"||y.length===0,onClick:()=>void w(),children:k})]})})]})]})})}const dq=512*1024,uq=/^[A-Za-z0-9+/]*={0,2}$/;function tP(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===""||!uq.test(r)||Math.floor(r.length*3/4)>dq+2?null:{mime:s,data:r}}function nP(e){const n=e==null?void 0:e.message;return typeof n=="string"&&n.trim()!==""?n:null}let la=null,Tc=null,xd=null;const zv=new Set;function sP(){for(const e of zv)e()}function hc(){la&&(la.onended=null,la.onerror=null,la.pause()),Tc&&URL.revokeObjectURL(Tc),Tc=null,xd!==null&&(xd=null,sP())}async function rP(e,n){hc();const s=atob(e.data),r=new Uint8Array(s.length);for(let a=0;a<s.length;a+=1)r[a]=s.charCodeAt(a);la??(la=new Audio),Tc=URL.createObjectURL(new Blob([r],{type:e.mime})),xd=n,la.onended=hc,la.onerror=hc,la.src=Tc,sP();try{await la.play()}catch{throw hc(),new Error("The browser would not play the sound.")}}function KS(e){e!==void 0&&xd!==e||hc()}function hq(){return u.useSyncExternalStore(e=>(zv.add(e),()=>zv.delete(e)),()=>xd,()=>null)}const fq=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Ir=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],VS=/^\d{4}-\d{2}-\d{2}$/;function Ui(e){return e.split("-").map(Number)}function vi(e,n){const[s,r,a]=Ui(e);return new Date(Date.UTC(s,r-1,a+n)).toISOString().slice(0,10)}function aP(e){const[n,s,r]=Ui(e);return new Date(Date.UTC(n,s-1,r)).getUTCDay()}function iP(e){return fq[aP(e)]}function lP(e){return Ui(e)[2]}function GS(e){return vi(e,-((aP(e)+6)%7))}function es(e){return Pd(e,{weekday:!0,compact:!0})}function mq(e,n){return e===n?`Today · ${es(e)}`:e===vi(n,1)?`Tomorrow · ${es(e)}`:es(e)}function or(e){return nz(e)}const qS=new Map;function Uv(e,n){let s=qS.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"}),qS.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 pq(e,n=new Date){return Uv(n,e).date}function gq(e,n){return e==="week"?{from:GS(n),days:7}:e==="month"?{from:GS(`${n.slice(0,8)}01`),days:42}:{from:n,days:7}}function xq(e,n,s){if(e!=="month")return vi(n,s*7);const[r,a]=Ui(n);return new Date(Date.UTC(r,a-1+s,1)).toISOString().slice(0,10)}function vq(e,n,s,r){const[a,i]=Ui(n);if(e==="month")return M$(a,i);const l=vi(s,r-1),[o,c,d]=Ui(s),[h,f,m]=Ui(l);return R$().date==="iso"?`${s} – ${l}`:sz()?c===f&&o===h?`${Ir[c-1]} ${d} – ${m}, ${h}`:o===h?`${Ir[c-1]} ${d} – ${Ir[f-1]} ${m}, ${h}`:`${Ir[c-1]} ${d}, ${o} – ${Ir[f-1]} ${m}, ${h}`:c===f&&o===h?`${d} – ${m} ${Ir[f-1]} ${h}`:o===h?`${d} ${Ir[c-1]} – ${m} ${Ir[f-1]} ${h}`:`${d} ${Ir[c-1]} ${o} – ${m} ${Ir[f-1]} ${h}`}function yl(e){return e==null?"":String(e)}function jq(e,n,s,r){const a=[],i=new Set;return e.forEach((l,o)=>{const c=yl(Ie(l,n.id)),d=yl(Ie(l,n.title)),h=yl(Ie(l,n.start)),f=yl(Ie(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:Ie(l,n.allDay),p=m===void 0?VS.test(h):m===!0||m==="true",x=n.tone===void 0?0:Number(Ie(l,n.tone)),g=Number.isFinite(x)?(Math.trunc(x)%4+4)%4:0,y={id:c,title:d,calendar:n.calendar===void 0?"":yl(Ie(l,n.calendar)),tone:g,location:n.location===void 0?"":yl(Ie(l,n.location)),row:l};if(p){const k=h.slice(0,10),S=VS.test(f.slice(0,10))&&f.slice(0,10)>k?f.slice(0,10):vi(k,1);a.push({...y,allDay:!0,startDate:k,startMin:0,endDate:S,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 v=new Date(f),w=Uv(j,s),N=Number.isNaN(v.getTime())||v<j?w:Uv(v,s);a.push({...y,allDay:!1,startDate:w.date,startMin:w.minutes,endDate:N.date,endMin:N.minutes})}),a}function wq(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:wq(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 tb(e,n){if(n.allDay)return"All day";const s=e.startDate!==e.endDate;return s&&n.from===0?`until ${or(n.to)}`:s&&n.to===1440?`from ${or(n.from)}`:n.from===n.to?or(n.from):`${or(n.from)}–${or(n.to)}`}function Bv(e,n,s){return[tb(e,n),e.title,e.location,e.calendar,es(s)].filter(Boolean).join(", ")}const oP=30;function yq(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+oP);s.length>0&&l.part.from>=r&&i();let c=a.findIndex(d=>d<=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 bq(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 kq(e){if(e.allDay){const a=vi(e.endDate,-1);return a>e.startDate?`${es(e.startDate)} – ${es(a)} · all day`:`${es(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?`${es(e.startDate)} · ${or(e.startMin)}–${or(e.endMin)}`:`${es(e.startDate)} ${or(e.startMin)} – ${es(e.endDate)} ${or(e.endMin)}`;return s>0?`${r} · ${bq(s)}`:r}const Nq={week:"Week",month:"Month",list:"List"},Sq=["week","month","list"],Cq="(max-width: 720px)";function Eq(e){try{return window.localStorage.getItem(e)}catch{return null}}function Aq(e,n){try{window.localStorage.setItem(e,n)}catch{}}function $q(e){const n=e.views&&e.views.length>0?e.views:Sq,s=Gn(Cq),[r,a]=u.useState(()=>{const p=Eq(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]=u.useState(e.today),[d,h]=u.useState(null),{from:f,days:m}=gq(l,o);return{views:n,view:l,setView:p=>{a(p),Aq(e.storageKey,p),h(null)},anchor:o,today:e.today,go:p=>{c(p===0?e.today:xq(l,o,p)),h(null)},from:f,days:m,to:vi(f,m),selected:d,select:h}}function Tq({state:e,events:n,hours:s,empty:r,label:a,onEvent:i,count:l}){const{view:o,anchor:c,today:d,from:h,days:f}=e,m=u.useMemo(()=>Array.from({length:f},(j,v)=>vi(h,v)),[h,f]),p=o==="month"?"month":"week",x=e.selected??(c.slice(0,7)===d.slice(0,7)?d:`${c.slice(0,8)}01`),g=o==="month"?x:o==="week"&&!i?e.selected:null,y=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:y,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:[vq(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(Jt,{label:"View",options:e.views.map(j=>({value:j,label:Nq[j]})),value:o,onChange:e.setView}):null]}),o==="week"?t.jsx(Iq,{dates:m,today:d,events:n,hours:s??[7,21],onPick:e.select,onEvent:i}):null,o==="month"?t.jsx(Pq,{dates:m,month:c.slice(0,7),today:d,events:n,selected:x,onPick:e.select,onEvent:i}):null,o==="list"?t.jsx("div",{className:"cal-list",children:m.map(j=>t.jsx(YS,{date:j,today:d,events:n,empty:r,onEvent:i},j))}):null,g?t.jsx(YS,{date:g,today:d,events:n,empty:r,onEvent:i}):null]})}function YS({date:e,today:n,events:s,empty:r,onEvent:a}){const i=eb(s,e);return t.jsx(rt,{flush:!0,title:mq(e,n),children:t.jsx(ut,{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:tb(l,o),...a?{onClick:()=>a(l)}:{}},l.id))})})}function Iq({dates:e,today:n,events:s,hours:r,onPick:a,onEvent:i}){const l=u.useRef(null);u.useLayoutEffect(()=>{const h=l.current;h&&(h.scrollTop=h.scrollHeight/24*r[0])},[r[0]]);const o=Mq(l),c=e.map(h=>({date:h,items:eb(s,h)})),d=h=>h===n?"true":void 0;return t.jsx(rt,{flush:!0,children:t.jsxs("div",{className:"cal-week",role:"grid","aria-label":`Week of ${es(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":d(h),"aria-label":es(h),children:[t.jsx("span",{className:"cal-wd",children:iP(h)}),t.jsx("span",{className:"cal-num",children:lP(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":d(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":Bv(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:or(h*60)},h))}),c.map(({date:h,items:f})=>t.jsx("div",{className:"cal-col",role:"gridcell","aria-label":es(h),"data-today":d(h),children:yq(f.filter(m=>!m.part.allDay)).map(({event:m,part:p,lane:x,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":x,"aria-label":Bv(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,oP)/60})`,left:`calc((100% - var(--space-1)) * ${x/g} + var(--space-0))`,width:`calc((100% - var(--space-1)) / ${g} - var(--space-0))`},children:[t.jsx("span",{className:"cal-event-time",children:tb(m,p)}),t.jsx("span",{className:"cal-event-title",children:m.title})]},m.id))},h))]})})]})})}const Rq=3;function Pq({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,d]=n.split("-").map(Number),h=M$(c,d);return t.jsx(rt,{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:iP(f)},f))}),o.map(f=>t.jsx("div",{className:"cal-row",role:"row",children:f.map(m=>{const p=eb(r,m),x=p.slice(0,Rq),g=p.length-x.length,y=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":`${es(m)}, ${y}`,"aria-pressed":m===a,children:lP(m)}),x.map(({event:j,part:v})=>t.jsx("button",{type:"button",className:"cal-chip","data-tone":j.tone,"data-timed":v.allDay?void 0:"true","aria-label":Bv(j,v,m),...l?{onClick:w=>{w.stopPropagation(),i(m),l(j)}}:{},children:v.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:or(v.from)})," ",j.title]})},j.id)),g>0?t.jsxs("button",{type:"button",className:"cal-more","aria-label":`${g} more on ${es(m)}`,children:["+",g]}):null]},m)})},f[0]))]})})}function Mq(e){const[n,s]=u.useState(0);return u.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 cP={width:1200,height:200,top:28,right:12,bottom:24,left:36};function Oq(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 Lu(e,n){return n==="temp"?`${e}°`:n==="percent"?`${e}%`:String(e)}function Dq(e){const n=cP,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=>Ti(n.left+l*(j+.5)),c=e.values.filter(j=>j!==null&&Number.isFinite(j)),d=Oq(c,e.unit),h=d[0],f=d[d.length-1],m=j=>Ti(n.top+a-(j-h)/(f-h)*a),p=e.values.map((j,v)=>{const w=j!==null&&Number.isFinite(j);return{index:v,x:o(v),y:w?m(j):null,value:w?j:null}}),x=[],g=[];if(e.kind==="area"){let j=[];const v=()=>{if(j.length===0)return;const w=j.map((N,k)=>`${k===0?"M":"L"}${N.x},${N.y}`).join(" ");x.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?v():j.push(w);v()}const y=e.kind==="bars"?p.flatMap(j=>j.y===null?[]:[{index:j.index,x:Ti(j.x-l*.28),y:j.y,width:Ti(l*.56),height:Ti(i-j.y)}]):[];return{ticks:d.map(j=>({value:j,y:m(j)})),lines:x,areas:g,bars:y,points:p,slot:l,floor:i}}function Lq({title:e,note:n,xs:s,series:r,tiles:a,labelEvery:i=3}){var k;const[l,o]=u.useState(((k=r[0])==null?void 0:k.id)??""),[c,d]=u.useState(null),[h,f]=u.useState(null),m=u.useRef(null),p=s.length,x=c??h,g=r.find(S=>S.id===l)??r[0],y=Dq(g),j=cP,v=S=>S%i===0||S===x,w=g.values.filter(S=>S!==null&&Number.isFinite(S));u.useEffect(()=>{const S=m.current,b=x===null?null:S==null?void 0:S.children[x];!S||!b||typeof S.scrollTo!="function"||(b.offsetLeft<S.scrollLeft?S.scrollTo({left:b.offsetLeft,behavior:"smooth"}):b.offsetLeft+b.offsetWidth>S.scrollLeft+S.clientWidth&&S.scrollTo({left:b.offsetLeft+b.offsetWidth-S.clientWidth,behavior:"smooth"}))},[x]);const N=S=>{var $,A,I;const b=S.key==="ArrowRight"?1:S.key==="ArrowLeft"?-1:0,C=S.key==="Home"?0:S.key==="End"?p-1:b===0?null:Math.max(0,Math.min(p-1,(h??-b)+b));C!==null&&(S.preventDefault(),f(C),(I=(A=($=m.current)==null?void 0:$.children[C])==null?void 0:A.querySelector("button"))==null||I.focus())};return t.jsxs(rt,{...e?{title:e}:{},children:[n?t.jsx("p",{className:"ui-panel-sub",children:n}):null,t.jsxs("div",{className:"pg-series",onMouseLeave:()=>d(null),children:[r.length>1?t.jsx("div",{className:"pg-series-tabs",role:"tablist","aria-label":"Series",children:r.map(S=>t.jsx("button",{type:"button",role:"tab",className:"ui-tab","aria-selected":S.id===g.id,onClick:()=>o(S.id),children:S.label},S.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:[y.ticks.map(S=>t.jsxs("g",{children:[t.jsx("line",{className:"pg-series-grid",x1:j.left,x2:j.width-j.right,y1:S.y,y2:S.y}),t.jsx("text",{className:"pg-series-tick",x:j.left-8,y:S.y,textAnchor:"end",dominantBaseline:"middle",children:Lu(S.value,g.unit)})]},S.value)),y.areas.map((S,b)=>t.jsx("path",{className:"pg-series-area",d:S},`a${b}`)),y.lines.map((S,b)=>t.jsx("path",{className:"pg-series-line",d:S},`l${b}`)),y.bars.map(S=>t.jsx("rect",{className:"pg-series-bar","data-index":S.index,"data-hover":S.index===x?"true":void 0,x:S.x,y:S.y,width:S.width,height:S.height},S.index)),x!==null&&y.points[x]?t.jsx("line",{className:"pg-series-guide","data-index":x,x1:y.points[x].x,x2:y.points[x].x,y1:j.top-4,y2:y.floor}):null,g.kind==="area"?y.points.map(S=>S.y!==null&&v(S.index)?t.jsx("circle",{className:"pg-series-dot","data-index":S.index,"data-hover":S.index===x?"true":void 0,cx:S.x,cy:S.y,r:S.index===x?5:3},S.index):null):null,y.points.map(S=>S.y!==null&&S.value!==null&&v(S.index)?t.jsx("text",{className:"pg-series-value","data-index":S.index,"data-hover":S.index===x?"true":void 0,x:S.x,y:S.y-(g.kind==="area"?10:6),textAnchor:"middle",children:Lu(S.value,g.unit)},S.index):null),y.points.map(S=>S.index%i===0?t.jsx("text",{className:"pg-series-x",x:S.x,y:j.height-6,textAnchor:"middle",children:s[S.index]},S.index):null),y.points.map(S=>t.jsx("rect",{className:"pg-series-hit","data-index":S.index,x:Ti(j.left+y.slot*S.index),y:0,width:Ti(y.slot),height:j.height,onMouseEnter:()=>d(S.index),onClick:()=>f(S.index)},S.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 ${Lu(Math.min(...w),g.unit)}, highest ${Lu(Math.max(...w),g.unit)}.`})]}),t.jsx("ul",{className:"wb-tiles","data-layout":"strip",ref:m,onKeyDown:N,children:a.map((S,b)=>t.jsx("li",{className:"wb-tile",children:t.jsx("button",{type:"button",className:"ui-card","data-index":b,"data-hover":b===x?"true":void 0,"aria-pressed":b===h,"aria-label":[S.label,S.value,...S.lines].filter(C=>C!=="").join(", "),onMouseEnter:()=>d(b),onClick:()=>f(b),children:t.jsxs("div",{className:"wb-tile-body","aria-hidden":"true",children:[t.jsx("span",{className:"wb-tile-icon","data-icon":S.icon??"dot",children:t.jsx(ie,{name:Po(S.icon),size:22})}),S.value!==""?t.jsx("span",{className:"wb-tile-value tnum",children:S.value}):null,t.jsx("span",{className:"wb-tile-label",children:S.label}),S.lines.map((C,$)=>t.jsx("span",{className:"wb-tile-line",children:C},$))]})})},b))})]})]})}function Ti(e){return Math.round(e*10)/10}const nb=u.createContext(null),gf=u.createContext(!1);function xt(){const e=u.useContext(nb);if(!e)throw new Error("a plugin page component outside a plugin page");return e}function Wv(e,n=new Set){if(Array.isArray(e))for(const s of e)Wv(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))Wv(r,n)}return n}function dP(e,n){if(n.size===0)return!1;for(const s of Wv(e))if(n.has(s))return!0;return!1}function uP(){const[e,n]=u.useState(!1);return u.useEffect(()=>{if(!e)return;const s=()=>{document.visibilityState==="hidden"&&n(!1)};return document.addEventListener("visibilitychange",s),window.addEventListener("blur",s),()=>{document.removeEventListener("visibilitychange",s),window.removeEventListener("blur",s)}},[e]),[e,()=>n(s=>!s)]}function hP({revealed:e,onToggle:n}){return t.jsx(E,{size:"sm",variant:"ghost","aria-pressed":e,onClick:n,children:e?"Hide":"Show"})}function fP(){return t.jsx("p",{className:"muted",children:"Hidden until you show it."})}function mP({children:e}){const[n,s]=uP();return t.jsxs(de,{gap:"sm",children:[t.jsx(se,{align:"end",children:t.jsx(hP,{revealed:n,onToggle:s})}),n?t.jsx(gf.Provider,{value:!0,children:e}):t.jsx(fP,{})]})}function sb(e){return e===void 0||e==="neutral"?void 0:e}function Hv(e){return sb(e)}function Fq(e){const n=sb(e);return n==="accent"?void 0:n}function Mt(e,n){if(!n)return!0;const s=Ie(e,n.path),r=n.in!==void 0?n.in.includes(s):s===n.equals;return n.not===!0?!r:r}function xf(e){if(typeof e!="string"||e.length>2048)return null;try{const n=new URL(e);return n.protocol==="https:"&&n.hostname!==""&&n.username===""&&n.password===""?n.href:null}catch{return null}}function _q({plugin:e,images:n,row:s}){const a=(Array.isArray(n)?n.map(l=>({asset:Ke(s,l.asset),label:String(Ke(s,l.label)??"").trim()})):(()=>{const l=Ie(s,n.from);return(Array.isArray(l)?l:[]).map(o=>({asset:Ie(o,n.asset),label:String(Ie(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(Oo,{src:Kd(e,l.asset),label:l.label},o))}),t.jsx("span",{className:"pl-stack-words",children:i})]})}function uo({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 Sa(e,n,s){if("href"in n)return xf(Ke(s,n.href))??"";if("chat"in n){const i=Ke(s,n.chat);return i==null?"":lt(String(i))}if("proposals"in n)return I6(e.plugin);const r=e.pages.find(i=>i.id===n.page);if((r==null?void 0:r.place)==="settings")return pr(e.plugin,n.page);const a=n.item===void 0?null:Ke(s,n.item);return Hr(e.plugin,n.page,a==null?null:String(a))}function ds(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=Ie(n.row,r);return a==null?"":String(a)})}function vf(e,n){if(e===void 0)return;if(typeof e=="string")return e;const s=Ke(n,e);return s==="good"||s==="warning"||s==="critical"||s==="neutral"?s:void 0}function pP(e,n,s){const r={};for(const[a,i]of Object.entries(e??{})){let l;"param"in i?l=s.params[i.param]:"route"in i?l=i.route==="plugin"?s.plugin:i.route==="page"?s.page:s.item:l=Ke(n,i),!(l==null||l==="")&&(r[a]=String(l))}return r}function Ds(e,n){var r,a,i;const s={};for(const[l,o]of Object.entries(e??{}))if("row"in o)s[l]=Ie(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],d=(i=n.shape)==null?void 0:i.find(h=>h.name===o.field);if(c===""&&(d==null?void 0:d.required)!==!0&&(d===void 0||d.type==="number"))continue;s[l]=c}else"selected"in o?s[l]=n.selected??[]:"param"in o?s[l]=n.scope.params[o.param]:s[l]=Ke(n.data,o);return s}function Nn(e,n,s,r){const a=xt(),i=e?pP(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]),d=pe(()=>e?T.pageQuery(a.plugin,e.query,l).then(f=>({asked:o,data:f.data})):Promise.resolve({asked:o,data:void 0}),[c],s),h=d.data!==void 0&&d.data.asked===o;return{data:h?d.data.data:void 0,error:h||!d.loading?d.error:null,loading:d.loading}}function Qr(){const e=xt(),n=u.useId(),[s,r]=u.useState(null),[a,i]=u.useState(null),[l,o]=u.useState(null),[c,d]=u.useState(null),[h,f]=u.useState(null),m=(j,v)=>{if(j.done===void 0)return null;if(typeof j.done=="string")return j.done;const w=Ke(v,j.done);return w==null?null:String(w)},p=(j,v,w)=>{const N=j??"refresh";if(typeof N=="object"){const k="href"in N.route?"":Sa(e,N.route,v);k===""?e.refresh():e.navigate(k);return}N==="close"&&(w==null||w()),e.refresh()},x=async(j,v,w)=>{r(j.tool),i(null),o(null);try{const N=await T.pageAct(e.plugin,{tool:j.tool,args:v});if(N.approvalId)return d(N.approvalId),f({then:j.then,ref:j,...w?{onDone:w}:{}}),!1;d(null),f(null);const k=tP(N.result);return o(m(j,N.result)??(k?nP(N.result):null)),k&&await rP(k,n),p(j.then,N.result,w),!0}catch(N){return i(N instanceof Error?N.message:String(N)),e.refresh(),!1}finally{r(null)}},g=j=>{if(!j){e.refresh();return}const v=h;if(d(null),f(null),v&&j.decision==="approve"&&j.state==="succeeded"){o(m(v.ref,j.result)),p(v.then,void 0,v.onDone);return}e.refresh()},y=()=>{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:g,run:x,reset:y}}function ji({action:e,args:n,disabled:s,running:r,count:a,row:i,onRun:l}){const[o,c]=u.useState(!1),d=f=>ds(f,{...a===void 0?{}:{count:a},row:i}),h=d(e.label);return o&&e.confirm?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"ui-toolbar-note",children:d(e.confirm)}),t.jsx(E,{variant:"ghost",onClick:()=>c(!1),children:"Cancel"}),t.jsxs(E,{variant:e.tone==="danger"?"danger":"accent",disabled:s,onClick:()=>{c(!1),l(e,n)},children:["Yes, ",h.toLowerCase()]})]}):t.jsx(E,{variant:e.tone==="danger"?"danger":e.tone==="accent"?"accent":void 0,disabled:s,onClick:()=>e.confirm?c(!0):l(e,n),children:r&&e.busy?e.busy:h})}function jf({id:e,onDecided:n}){const s=xt(),r=pe(()=>T.approval(e),[e,s.version]),{busy:a,note:i,failure:l,decide:o}=Hy(c=>{n?n(c):s.refresh()});return r.error?t.jsx(re,{message:r.error}):r.data?t.jsxs(de,{children:[t.jsx(Ky,{action:r.data,timezone:s.timezone,busy:a===e,onDecide:(c,d,h,f)=>{o(c,d,h,f)}}),i?t.jsx(q,{tone:"good",role:"status",children:i}):null,t.jsx(re,{message:l})]}):t.jsx(be,{children:"Loading the approval…"})}function jr({act:e}){return e.error?t.jsx(re,{message:e.error}):e.approvalId?e.waiting?t.jsxs(de,{children:[t.jsx(q,{role:"status",children:e.waiting}),t.jsx(jf,{id:e.approvalId,onDecided:e.settle})]}):t.jsx(jf,{id:e.approvalId,onDecided:e.settle}):e.done?t.jsx(q,{tone:"good",role:"status",children:e.done}):null}function vd(e,n){const s={};for(const r of e){const a=r.from===void 0?void 0:Ie(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 gP(e,n,s){const r=xt(),a=e.optionsFrom,i=a?{...pP(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=pe(()=>a?T.pageQuery(r.plugin,a.query.query,i).then(c=>c.data):Promise.resolve(void 0),[l]);return a?{options:wr(o.data,a.rows).map(c=>({value:String(Ie(c,a.value)??""),label:String(Ie(c,a.label)??"")})),loading:o.loading}:{options:e.options??[],loading:!1}}function zq({field:e,fields:n,value:s,values:r,data:a,disabled:i,compact:l,onChange:o}){const c=gP(e,r,a),d={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):[],x=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,x].filter(Boolean).join(" ")||void 0,group:!0,children:t.jsx(U5,{id:d.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",{...d,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(Uq,{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",{...d,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",{...d,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",{...d,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"?Bq(m.target.value):m.target.value)})})}function Uq({field:e,action:n,fields:s,values:r,data:a,disabled:i,hint:l,children:o}){const c=xt(),d=u.useId(),h=hq()===d,[f,m]=u.useState(!1),[p,x]=u.useState(null),[g,y]=u.useState(null),[j,v]=u.useState(null);u.useEffect(()=>()=>KS(d),[d]);const w=rb(s,r,a),N=n.args!==void 0?Ds(n.args,{data:a,fields:r,shape:s,omit:w,scope:c}):Object.fromEntries(Object.entries(r).filter(([b,C])=>!w.has(b)&&C!=="")),k=async()=>{if(h){KS(d);return}m(!0),x(null),y(null),v(null);try{const b=await T.pageAct(c.plugin,{tool:n.tool,args:N});if(b.approvalId){v(b.approvalId);return}x(nP(b.result));const C=tP(b.result);C&&await rP(C,d)}catch(b){y(b instanceof Error?b.message:String(b))}finally{m(!1)}},S=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`:S,title:S,"aria-busy":f||void 0,"aria-pressed":n.icon==="play"?h:void 0,disabled:i===!0||f,onClick:()=>void k(),children:f?t.jsx("span",{className:"ui-spinner","aria-hidden":"true"}):t.jsx(ie,{name:h?"stop":n.icon??"arrow"})}),after:g?t.jsx(re,{message:g}):j?t.jsx(jf,{id:j,onDecided:()=>v(null)}):p?t.jsx("span",{className:"ui-field-hint",role:"status",children:p}):null,children:o})}function Bq(e){if(e.trim()==="")return"";const n=Number(e);return Number.isFinite(n)?n:e}function xP(e,n){return{...typeof n=="object"&&n!==null?n:{},...e}}function rb(e,n,s){const r=xP(n,s);return new Set(e.filter(a=>a.when!==void 0&&!Mt(r,a.when)||a.disabledWhen!==void 0&&Mt(r,a.disabledWhen)).map(a=>a.name))}function Mm({fields:e,values:n,data:s,disabled:r,compact:a,columns:i,onChange:l}){const o=xP(n,s);return t.jsx(Ts,{dense:a,columns:i,children:e.filter(c=>c.when===void 0||Mt(o,c.when)).map(c=>t.jsx(zq,{field:c,fields:e,compact:a,value:n[c.name],values:n,data:s,disabled:r===!0||c.disabledWhen!==void 0&&Mt(o,c.disabledWhen),onChange:d=>l(c.name,d)},c.name))})}const jd=u.createContext(!1),vP=u.createContext(!1),jP=u.createContext(!1);function Ls({title:e,note:n,actions:s,children:r}){const a=u.useContext(jd);return t.jsx(ge,{title:e,aside:n,actions:s,panel:a,children:t.jsx(jd.Provider,{value:!1,children:t.jsx(vP.Provider,{value:a,children:r})})})}function Vr({component:e,data:n,choose:s,chosen:r}){const a=xt(),i=u.useContext(gf);if(!Mt(n,e.when)||e.where!==void 0&&e.where!==(Hq()?"local":"remote"))return null;if(e.kind!=="section"&&!i&&dP(e,a.sensitive))return t.jsx(mP,{children:t.jsx(Vr,{component:e,data:n,...s?{choose:s}:{},...r===void 0?{}:{chosen:r}})});switch(e.kind){case"section":return t.jsx(Wq,{component:e,data:n});case"notice":return t.jsx(Kq,{component:e,data:n});case"link":return t.jsx(Vq,{component:e,data:n});case"progress":return t.jsx(qq,{component:e,data:n});case"chart":return t.jsx(Yq,{component:e,data:n});case"stats":return t.jsx(Qq,{component:e,data:n});case"list":return t.jsx(Zq,{component:e,data:n,...s?{onChoose:s}:{},...r===void 0?{}:{chosen:r}});case"table":return t.jsx(sY,{component:e,data:n});case"detail":return t.jsx(lY,{component:e,data:n});case"form":return t.jsx(oY,{component:e,data:n});case"search":return t.jsx(uY,{component:e,data:n});case"list-detail":return t.jsx(hY,{component:e,data:n});case"repeat":return t.jsx(fY,{component:e,data:n});case"calendar":return t.jsx(mY,{component:e,data:n});case"tiles":return t.jsx(gY,{component:e,data:n});case"series-panel":return t.jsx(xY,{component:e,data:n});case"hero":return t.jsx(vY,{component:e,data:n});case"tabs":return t.jsx(jY,{component:e,data:n});case"expand":return t.jsx(wY,{component:e,data:n});case"button":return t.jsx(CP,{component:e,data:n});case"menu":return t.jsx(wP,{component:e,data:n});case"approval":return t.jsx(IY,{component:e,data:n});case"artifact":return t.jsx(RY,{component:e,data:n});case"message":return t.jsx(OY,{component:e,data:n});case"editor":return t.jsx(LY,{component:e,data:n});case"agent-offer":return t.jsx(yY,{component:e});case"stories":return t.jsx(NY,{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 Wq({component:e,data:n}){const s=xt(),r=u.useContext(gf),[a,i]=uP(),l=!r&&dP([e.query,e.body],s.sensitive),o=l&&!a,c=Nn(o?void 0:e.query,n),d=e.query?c.data:n,h=e.heading&&!o?Ke(d,e.heading):void 0,f=h==null||h===""?e.title:String(h),m=u.useContext(jd);let p=e.body.length;const x=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&&x(e.body[p-1]);)p-=1;const g=e.body.slice(0,p),y=[...e.actions??[],...e.body.slice(p)],[j,v]=u.useState(null);return t.jsx(Kv.Provider,{value:v,children:t.jsx(Ls,{title:f,note:e.note,actions:y.length>0||l?t.jsxs(t.Fragment,{children:[y.map((w,N)=>t.jsx(Vr,{component:w,data:d},N)),l?t.jsx(hP,{revealed:a,onToggle:i}):null]}):void 0,children:t.jsxs(de,{gap:"lg",divided:m,children:[j,e.query&&!o?t.jsx(re,{message:c.error}):null,o?t.jsx(fP,{}):e.query&&c.data===void 0&&!c.error?t.jsx(be,{children:"Loading…"}):t.jsx(gf.Provider,{value:r||l,children:t.jsx(Kv.Provider,{value:null,children:g.map((w,N)=>t.jsx(Vr,{component:w,data:d},N))})})]})})})}const Kv=u.createContext(null);function Hq(){const e=typeof location>"u"?"":location.hostname;return e==="127.0.0.1"||e==="localhost"||e==="::1"||e==="[::1]"}function wP({component:e,data:n}){var c;const s=xt(),r=Qr(),a=u.useContext(Kv),i=e.items.filter(d=>Mt(n,d.when)).map(d=>({label:d.label,...d.hint?{hint:d.hint}:{},onSelect:()=>{d.open!==void 0?s.setParams({open:d.open}):d.action&&r.run(d.action,Ds(d.action.args,{data:n,row:n,scope:s}))}})),l=(c=e.items.find(d=>{var h;return((h=d.action)==null?void 0:h.tool)===r.running}))==null?void 0:c.action,o=r.error||r.done||r.approvalId?t.jsx(jr,{act:r}):null;return u.useEffect(()=>{a&&a(o)},[r.error,r.done,r.approvalId,r.waiting]),u.useEffect(()=>()=>a==null?void 0:a(null),[a]),t.jsxs(t.Fragment,{children:[t.jsx(Qn,{label:e.label,items:i,stacked:e.items.some(d=>d.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 Kq({component:e,data:n}){const s=xt(),r=Qr(),a=typeof e.text=="string"?e.text:String(Ke(n,e.text)??""),i=e.link&&Mt(n,e.link.when)?e.link:void 0,l=i?Sa(s,i.to,n):"",o=i?typeof i.label=="string"?i.label:String(Ke(n,i.label)??""):"",c=i&&l!==""&&o!==""?"href"in i.to?t.jsx(uo,{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 d=e.action;return t.jsxs(t.Fragment,{children:[t.jsxs(q,{tone:sb(e.tone),title:e.title,action:d?t.jsx(ji,{action:d,args:Ds(d.args,{data:n,scope:s}),disabled:r.busy,running:r.running===d.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(EP,{act:r})]})}function Vq({component:e,data:n}){const s=xt(),r=Sa(s,e.to,n);return r===""?null:"href"in e.to?t.jsx(se,{children:t.jsxs(st,{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(se,{children:t.jsx(st,{href:r,variant:e.tone==="accent"?"accent":void 0,onClick:a=>{a.preventDefault(),s.navigate(r)},children:e.label})})}function QS(e){return Math.round(e/1e6)}function Gq(e,n){const s=Es(Ke(n,e.value))??0,r=e.total?Es(Ke(n,e.total)):null,a=e.total?r&&r>0?s/r:0:s,i=Math.max(0,Math.min(1,a)),l=Math.floor(i*100),o=a>=1,c=e.total&&r&&r>0?`${QS(s)} of ${Math.max(1,QS(r))} MB · ${l}%`:`${l}%`;return{percent:l,full:o,line:c}}function qq({component:e,data:n}){const s=c=>c===void 0?"":typeof c=="string"?c:String(Ke(n,c)??""),r=s(e.label),a=s(e.done),{percent:i,full:l,line:o}=Gq(e,n);return t.jsxs(de,{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(gy,{value:i,label:r||"Progress"}),t.jsx("span",{role:"status",children:o})]})]})}function Yq({component:e,data:n}){const s=Nn(e.query,n),r=e.rows===void 0?Array.isArray(s.data)?s.data:[]:wr(s.data,e.rows),a=r.map(h=>String(Ie(h,e.x)??"")),i=h=>r.map(f=>Es(Ie(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)})),d=e.target?Es(Ke(s.data,e.target))??null:null;return t.jsxs(Ls,{title:e.title,note:e.note,children:[t.jsx(re,{message:s.error}),r.length===0?s.loading||s.data===void 0?t.jsx(be,{children:"Loading…"}):t.jsx(cl,{text:e.empty??"Nothing recorded yet."}):t.jsx(M5,{xs:a,series:c,type:l?"mixed":e.type??"line",target:d,...e.label?{label:e.label}:{},formatX:h=>/^\d{4}-\d{2}-\d{2}/.test(h)?Xx(h):h,formatY:h=>kn(h,"number",null)})]})}function Qq({component:e,data:n}){const s=Nn(e.query,n);return t.jsxs(Ls,{title:e.title,note:e.note,children:[t.jsx(re,{message:s.error}),s.data===void 0?t.jsx(be,{children:e.empty??"Loading…"}):t.jsx(Sm,{children:e.items.map((r,a)=>t.jsx(Lr,{label:r.label,value:kn(Ke(s.data,r.value),r.unit??"text",null),tone:Fq(r.tone)},a))})]})}function yP(e,n,s,r){const a=(n.meta??[]).map(S=>String(Ke(s,S)??"")).filter(S=>S!==""),i=String(Ke(s,n.title)??""),l=n.to&&!r?Sa(e,n.to,s):null,o=l===""?null:l,c=o!==null&&n.to!==void 0&&"href"in n.to,d=n.images?t.jsx(_q,{plugin:e.plugin,images:n.images,row:s}):null,f=[...n.pill?[n.pill]:[],...n.pills??[]].map((S,b)=>{const C=Ke(s,S.value);if(C==null||C==="")return null;const $=Jq(S,C,s);return t.jsx(Ce,{tone:Hv($.tone),children:$.text},b)}),m=o&&c?t.jsx(uo,{href:o,children:i}):o?t.jsx("a",{href:o,onClick:S=>{S.preventDefault(),e.navigate(o)},children:i}):i,p=n.tag?Ke(s,n.tag):void 0,x=p==null||p===""?null:t.jsx("span",{className:"pl-row-tag",children:String(p)}),g=n.status?Ke(s,n.status.text):void 0,y=n.status?vf(n.status.tone,s):void 0,j=g==null||g===""?null:t.jsx("span",{className:"pl-row-status","data-tone":y,children:String(g)}),v=n.sub?String(Ke(s,n.sub)??""):"",w=n.swatch?Ie(s,n.swatch):void 0,N=n.logo?t.jsx(Oo,{className:"pl-logo-lg",src:Kd(e.plugin,Ke(s,n.logo.asset)),label:String(Ke(s,n.logo.label)??"")}):n.swatch?typeof w=="string"&&ib.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,k=n.preview?String(Ke(s,n.preview)??""):"";return{text:i,href:o,outside:c,lead:N,preview:k,strong:n.strong?Mt(s,n.strong):void 0,pills:t.jsx(t.Fragment,{children:f}),meta:a.join(" · "),title:d?t.jsxs(t.Fragment,{children:[d,t.jsx("span",{className:"pl-row-title",children:m}),x]}):x?t.jsxs(t.Fragment,{children:[m,x]}):m,sub:j?t.jsxs(t.Fragment,{children:[v?t.jsx("span",{className:"pl-row-line",children:v}):null,j]}):n.sub?v:null,side:t.jsxs(t.Fragment,{children:[f,a.length>0?t.jsxs("span",{className:"muted",children:[" ",a.join(" · ")]}):null]})}}function Jq(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]:vf(e.tone,s)}}function wr(e,n){const s=Ie(e,n);return Array.isArray(s)?s:[]}function bP(e,n,s){const r=[],a=new Set;return e.forEach((i,l)=>{const o=n===void 0?void 0:Ie(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 Xq(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 Zq({component:e,data:n,onChoose:s,chosen:r}){var S;const a=xt(),i=u.useContext(jP),l=Nn(e.query,n),o=Qr(),[c,d]=u.useState([]),h=i&&!e.select&&(e.actions??[]).length===0&&(e.bulk??[]).length===0,f=wr(l.data,e.rows),m=e.collapsed?wr(l.data,e.collapsed.rows):[],p=kP(e.actions,f,o),x={plugin:a.plugin,page:a.page,component:`list "${e.title??e.rows}"`},g=bP([...f,...m],e.key??((S=e.select)==null?void 0:S.key),x),y=new Map(g.map(b=>[b.row,b.key])),j=new Set(g.map(b=>b.row)),v=new Set(g.filter(({row:b})=>{var C;return((C=e.select)==null?void 0:C.disabledWhen)===void 0||!Mt(b,e.select.disabledWhen)}).map(({key:b})=>b)),w=c.filter(b=>v.has(b)),N=u.useMemo(()=>{const b=f.filter(A=>j.has(A));if(!e.groupBy)return[{label:null,aside:null,asideTone:void 0,rows:b}];const C=new Map;for(const A of b){const I=String(Ie(A,e.groupBy.key)??"");C.set(I,[...C.get(I)??[],A])}const $=(A,I)=>{var R,_,z;const M=(_=(R=e.groupBy)==null?void 0:R.labels)==null?void 0:_[A];if(M!==void 0)return M;const O=(z=e.groupBy)!=null&&z.label?Ie(I,e.groupBy.label):void 0;return O==null||O===""?A:String(O)};return[...C].map(([A,I])=>{var R,_;const M=(R=e.groupBy)!=null&&R.aside?Ie(I[0],e.groupBy.aside):void 0,O=(_=e.groupBy)!=null&&_.asideTone?Ie(I[0],e.groupBy.asideTone):void 0;return{label:$(A,I[0]),aside:M==null||M===""?null:String(M),asideTone:O==="warning"||O==="critical"?O:void 0,rows:I}})},[f,e.groupBy,g.length]),k=b=>b.map(C=>{var _;const $=yP(a,e.item,C,s),A=y.get(C);if(h&&(s||$.href&&!$.outside))return t.jsx(gI,{href:$.href??"#",current:r===A,onClick:()=>s?s(A):a.navigate($.href),title:$.text,meta:$.meta,sub:$.sub,side:$.pills,snippet:$.preview||void 0,strong:$.strong},A);const I=((_=e.select)==null?void 0:_.disabledWhen)!==void 0&&Mt(C,e.select.disabledWhen),M=(e.actions??[]).filter(z=>Mt(C,z.when)),O=M.filter(z=>z.menu!==!0),R=M.filter(z=>z.menu===!0);return t.jsx(ot,{lead:$.lead?$.lead:e.select?t.jsx("input",{type:"checkbox","aria-label":`Select ${$.text}`,disabled:I,checked:c.includes(A),onClick:z=>z.stopPropagation(),onChange:z=>d(U=>z.target.checked?[...U,A]:U.filter(P=>P!==A))}):void 0,title:s?t.jsx("a",{href:"#","aria-current":r===A?"true":void 0,onClick:z=>{z.preventDefault(),s(A)},children:$.text}):$.title,sub:$.preview?t.jsxs(t.Fragment,{children:[$.sub?t.jsx("span",{className:"pl-row-line",children:$.sub}):null,t.jsx("span",{className:"pl-row-preview",children:$.preview})]}):$.sub,side:t.jsxs(t.Fragment,{children:[$.side,e.item.choice?t.jsx(tY,{choice:e.item.choice,row:C,data:l.data,act:o}):null,O.map((z,U)=>t.jsx(ab,{action:z,row:C,data:l.data,act:o,onForm:p.show},U)),R.length>0?t.jsx(NP,{actions:R,row:C,title:$.text,data:l.data,act:o,onForm:p.show}):null]})},A)});return t.jsxs(Ls,{title:e.title,note:e.note,children:[t.jsx(re,{message:l.error}),p.open?null:t.jsx(jr,{act:o}),p.open?t.jsx(SP,{open:p.open,data:l.data,act:o,onClose:p.close,onDone:p.finish}):null,N.every(b=>b.rows.length===0)?l.loading?t.jsx(be,{children:"Loading…"}):t.jsx(cl,{text:e.empty??"Nothing here yet."}):t.jsxs(ut,{children:[e.select?t.jsx(ot,{lead:t.jsx("input",{type:"checkbox","aria-label":"Select every row",checked:v.size>0&&w.length===v.size,disabled:v.size===0,onChange:b=>d(b.target.checked?[...v]:[])}),title:t.jsxs("span",{className:"muted",children:[v.size," to choose from"]})}):null,N.map((b,C)=>{var $,A;return($=e.groupBy)!=null&&$.actions||(A=e.groupBy)!=null&&A.asideTone?t.jsxs("section",{className:"pl-group","aria-label":b.label??void 0,children:[t.jsxs("header",{className:"pl-group-head",children:[t.jsx("span",{className:"pl-group-title",children:b.label}),b.aside?t.jsx("span",{className:"pl-group-aside","data-tone":b.asideTone,children:b.aside}):null,t.jsx(eY,{actions:e.groupBy.actions??[],row:b.rows[0],title:b.label??"",data:l.data,act:o,onForm:p.show})]}),k(b.rows)]},C):t.jsxs("div",{children:[b.label?t.jsxs("div",{className:"ui-list-group","data-aside":b.aside?"true":void 0,children:[b.label,b.aside?t.jsx("span",{className:"pl-group-aside",children:b.aside}):null]}):null,k(b.rows)]},C)})]}),e.collapsed&&m.some(b=>j.has(b))?t.jsx(Kt,{summary:`${e.collapsed.label} (${m.filter(b=>j.has(b)).length})`,children:t.jsx(ut,{children:k(m.filter(b=>j.has(b)))})}):null,e.bulk&&e.bulk.length>0?t.jsxs(se,{align:"end",children:[t.jsxs("span",{className:"ui-toolbar-note",children:[w.length," selected"]}),e.bulk.map((b,C)=>{const $=w.length>0||b.all!==!0?w:[...v];return t.jsx(ji,{action:b,args:Ds(b.args,{data:l.data,selected:$,scope:a}),count:$.length,disabled:o.busy||$.length===0,running:o.running===b.tool,onRun:(A,I)=>{d([]),o.run(A,I)}},C)})]}):null]})}function eY({actions:e,row:n,title:s,data:r,act:a,onForm:i}){const l=e.filter(d=>Mt(n,d.when));if(l.length===0)return null;const o=l.filter(d=>d.menu!==!0),c=l.filter(d=>d.menu===!0);return t.jsxs("span",{className:"pl-group-act",children:[o.map((d,h)=>t.jsx(ab,{action:d,row:n,data:r,act:a,onForm:i},h)),c.length>0?t.jsx(NP,{actions:c,row:n,title:s,data:r,act:a,onForm:i}):null]})}function tY({choice:e,row:n,data:s,act:r}){const a=xt(),i=String(Ie(n,e.value)??""),[l,o]=u.useState(null);u.useEffect(()=>o(null),[i]);const c=l??i,d=e.options.filter(h=>Mt(n,h.when));return t.jsx("span",{className:"ui-segment pl-choice",role:"radiogroup","aria-label":ds(e.label,{row:n}),"aria-busy":l!==null&&r.running===e.tool?"true":void 0,children:d.map(h=>{const f=h.disabledWhen!==void 0&&Mt(n,h.disabledWhen),m=f&&h.hint?ds(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=Ds(e.args,{data:s,row:n,choice:h.value,scope:a});r.run(e,p).then(x=>{x||o(null)})},children:h.label},h.value)})})}function nY(e,n,s){return Object.entries(e).every(([r,a])=>{const i=typeof a=="string"?a:Ie(s,a.row);return i!=null&&n[r]===String(i)})}function kP(e,n,s){const r=xt(),[a,i]=u.useState(null);return u.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 d=n.find(h=>Mt(h,o.when)&&nY(c,r.params,h));if(d!==void 0){i({action:o,row:d}),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 ab({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:ds(e.label,{row:n})}):t.jsx(ji,{action:e,args:Ds(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 NP({actions:e,row:n,title:s,data:r,act:a,onForm:i}){const l=xt(),[o,c]=u.useState(null),d=m=>void a.run(m,Ds(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:ds(m.label,{row:n}),...m.hint?{hint:ds(m.hint,{row:n})}:{},...m.tone==="danger"?{tone:"critical"}:{},onSelect:()=>m.form?i(m,n):m.confirm?c(m):d(m)})}),t.jsxs(t.Fragment,{children:[t.jsx(Qn,{label:`More for ${s}`,items:h,sheet:{title:s}}),o?t.jsx(zt,{title:ds(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),d(m)},children:ds(o.label,{row:n})})]})}):null]})}function SP({open:e,data:n,act:s,onClose:r,onDone:a}){const i=xt(),{action:l,row:o}=e,c=l.form,[d,h]=u.useState(()=>vd(c.fields,o)),f=c.fields.some(g=>g.required&&(d[g.name]===""||d[g.name]===void 0)),{confirm:m,...p}=l,x={...p,label:c.submit};return t.jsx(Je,{title:ds(c.title,{row:o}),onClose:r,foot:t.jsxs(se,{align:"end",children:[t.jsx(E,{variant:"ghost",onClick:r,children:"Cancel"}),t.jsx(ji,{action:x,args:Ds(l.args,{data:n,row:o,fields:d,shape:c.fields,scope:i}),disabled:s.busy||f,running:s.running===l.tool,row:o,onRun:(g,y)=>void s.run(g,y,a)})]}),children:t.jsxs(de,{children:[t.jsx(Mm,{fields:c.fields,values:d,data:o,onChange:(g,y)=>h(j=>({...j,[g]:y}))}),t.jsx(re,{message:s.error})]})})}function sY({component:e,data:n}){const s=Nn(e.query,n),r=Qr(),a=wr(s.data,e.rows),i=kP(e.actions,a,r);return t.jsxs(Ls,{title:e.title,note:e.note,children:[t.jsx(re,{message:s.error}),i.open?null:t.jsx(jr,{act:r}),i.open?t.jsx(SP,{open:i.open,data:s.data,act:r,onClose:i.close,onDone:i.finish}):null,a.length===0?s.loading?t.jsx(be,{children:"Loading…"}):t.jsx(cl,{text:e.empty??"Nothing here yet."}):t.jsxs(Yr,{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 d=c.pill?null:kn(Ie(l,c.key),c.type??"text",null);return t.jsxs("td",{"data-fit":c.fit,title:aY(c,l,d),children:[c.pill?null:t.jsx(rY,{column:c,row:l}),c.pill?t.jsx(iY,{column:c,row:l}):c.fit==="truncate"?t.jsx("span",{className:"ui-table-cut",children:d}):d]},c.key)}),e.actions&&e.actions.length>0?t.jsx("td",{children:t.jsx(se,{align:"end",children:e.actions.filter(c=>Mt(l,c.when)).map((c,d)=>t.jsx(ab,{action:c,row:l,data:s.data,act:r,onForm:i.show},d))})}):null]},o))})]})]})}const ib=/^#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i;function rY({column:e,row:n}){if(!e.swatch)return null;const s=Ie(n,e.swatch);return typeof s!="string"||!ib.test(s)?null:t.jsx("span",{className:"ui-table-swatch","aria-hidden":"true",style:{"--swatch":s}})}function aY(e,n,s){if(e.hint){const r=Ie(n,e.hint);if(r!=null&&r!=="")return String(r)}return e.fit==="truncate"&&s?s:void 0}function iY({column:e,row:n}){var l,o;const s=Ie(n,e.key);if(Array.isArray(s))return t.jsx(t.Fragment,{children:s.map((c,d)=>{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,x=p&&Object.prototype.hasOwnProperty.call(p,String(f))?p[String(f)]:kn(f,e.type??"text",null);return t.jsx(Ce,{tone:Hv(vf(typeof m=="string"?m:void 0,n)),children:x},d)})});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(Ce,{tone:Hv(vf((o=e.pill)==null?void 0:o.tone,n)),children:i})}function lY({component:e,data:n}){const s=Nn(e.query,n);return s.error?t.jsx(re,{message:s.error}):s.data===void 0?t.jsx(be,{children:e.empty??"Loading…"}):t.jsx(Ls,{title:e.title,note:e.note,children:t.jsxs(de,{gap:"lg",children:[e.fields.length>0?t.jsx(Qt,{items:e.fields.map(r=>({key:r.label,label:r.label,value:kn(Ke(s.data,r.value),r.unit??"text",null)}))}):null,e.body.map((r,a)=>t.jsx(Vr,{component:r,data:s.data},a))]})})}function oY({component:e,data:n}){var m;const s=xt(),r=Nn(e.initial,n),a=Qr(),[i,l]=u.useState(!1),o=((m=e.drawer)==null?void 0:m.id)!==void 0&&s.params.open===e.drawer.id,c=i||o,d=p=>{l(p),!p&&o&&s.setParams({open:null})},h=JSON.stringify([r.data??null,s.version]),f=t.jsx(cY,{component:e,data:n,initialData:r.data,act:a,onDone:()=>d(!1)},h);return e.drawer?e.drawer.button===void 0&&!e.title?t.jsxs(t.Fragment,{children:[t.jsx(jr,{act:a}),c?t.jsx(Je,{title:e.drawer.title,onClose:()=>d(!1),children:f}):null]}):t.jsxs(ge,{title:e.title,aside:e.note,actions:e.drawer.button!==void 0?t.jsx(E,{variant:"accent",onClick:()=>d(!0),children:e.drawer.button}):void 0,children:[t.jsx(jr,{act:a}),c?t.jsx(Je,{title:e.drawer.title,onClose:()=>d(!1),children:f}):null]}):t.jsxs(Ls,{title:e.title,note:e.note,children:[t.jsx(re,{message:r.error}),f]})}function cY({component:e,data:n,initialData:s,act:r,onDone:a}){const i=u.useContext(vP),l=xt(),[o,c]=u.useState(()=>vd(e.fields,s)),d=rb(e.fields,o,s),h=e.fields.some(f=>f.required&&!d.has(f.name)&&(o[f.name]===""||o[f.name]===void 0||Array.isArray(o[f.name])&&o[f.name].length===0));return t.jsxs(de,{children:[t.jsx(Mm,{fields:e.fields,columns:e.columns,values:o,data:s,onChange:(f,m)=>c(p=>({...p,[f]:m}))}),e.drawer?null:t.jsx(jr,{act:r}),t.jsx(se,{align:"end",className:i?"ui-panel-foot":void 0,children:t.jsx(ji,{action:e.submit,args:Ds(e.submit.args,{data:n,fields:o,shape:e.fields,omit:d,scope:l}),disabled:r.busy||h,running:r.running===e.submit.tool,onRun:(f,m)=>void r.run(f,m,a)})})]})}function dY(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 JS(e){return e!=null&&e!==""&&e!==!1&&e!=="false"}function uY({component:e,data:n}){const s=xt(),[r,a]=u.useState(()=>vd(e.fields,n)),[i,l]=u.useState(e.auto===!0),[o,c]=u.useState(!1),d=e.fields.every(C=>!C.required||String(r[C.name]??"")!==""),h=Nn(i&&d?e.query:void 0,n),f=wr(h.data,e.rows),m=e.count===void 0?void 0:Ie(h.data,e.count),p=e.note===void 0?void 0:Ie(h.data,e.note),x=e.fields.find(C=>C.type==="text"||C.type==="email")??null,g=e.fields.filter(C=>C!==x),y=C=>{s.setParams(Object.fromEntries(e.fields.map($=>[$.name,String(C[$.name]??"")||null]))),l(!0)},j=(C,$)=>{const A={...r,[C]:$};a(A),e.auto&&y(A)},v=()=>{const C=vd(e.fields,null);a(C),e.auto?y(C):(s.setParams(Object.fromEntries(e.fields.map($=>[$.name,null]))),l(!1))},w=i?g.filter(C=>JS(s.params[C.name])):[],N=x?w.map(C=>t.jsx(ef,{label:C.label,onRemove:()=>{const $={...r,[C.name]:C.type==="checkbox"?!1:""};a($),y($)},children:dY(C,String(s.params[C.name]))},C.name)):[],k=g.filter(C=>JS(r[C.name])).length,S=e.auto&&!e.reset?null:t.jsxs(t.Fragment,{children:[e.reset?t.jsx(E,{variant:"ghost",onClick:v,children:"Clear"}):null,e.auto?null:t.jsx(E,{type:"submit",variant:"accent",disabled:!d,children:"Search"})]}),b=e.results.to?e.results:e.to?{...e.results,to:e.to}:e.results;return t.jsx(Ls,{title:e.title,children:t.jsxs(de,{children:[t.jsx(jI,{label:e.title??"Search",onSubmit:()=>{!e.auto&&d&&y(r)},main:x?t.jsx("input",{id:`f-${x.name}`,name:x.name,type:x.type==="email"?"email":"search","aria-label":x.label,placeholder:x.hint??x.label,title:x.hint,required:x.required,value:String(r[x.name]??""),onChange:C=>j(x.name,C.target.value)}):void 0,filters:g.length>0?t.jsx(Mm,{fields:g,values:r,data:n,compact:!0,onChange:j}):void 0,...x&&g.length>0?{filtersOpen:o,onToggleFilters:()=>c(C=>!C),active:k}:{},chips:N.length>0?N:void 0,actions:S}),t.jsx(re,{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(ut,{children:f.map((C,$)=>{const A=yP(s,b,C);return t.jsx(ot,{title:A.title,sub:A.sub,side:A.side},$)})})}):null]})})}function hY({component:e,data:n}){const s=xt(),r=e.selection==="local",[a,i]=u.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(de,{gap:"lg",divided:!0,children:e.detail.map((d,h)=>t.jsx(Vr,{component:d,data:n},h))},l??"");return t.jsx(jd.Provider,{value:!1,children:t.jsx(xI,{list:t.jsx(jP.Provider,{value:!0,children:t.jsx("div",{className:"pl-picks",onKeyDown:Xq,children:t.jsx(Vr,{component:e.list,data:n,chosen:l??null,...r?{choose:i}:{}})})}),detail:l?o?t.jsx(nb.Provider,{value:o,children:c}):c:void 0,empty:e.empty??"Choose one to see it here."})})}function fY({component:e,data:n}){var g;const s=xt(),[r,a]=u.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&&Mt(i.data,e.poll.while);u.useEffect(()=>a(l),[l]);const o=wr(i.data,e.rows),c=(g=e.poll)==null?void 0:g.finish,d=Qr(),[h,f]=u.useState(()=>new Set),m=c?o.find(y=>{if(!Mt(y,c.when))return!1;const j=String(Ie(y,e.key)??"");return j!==""&&!h.has(j)}):void 0,p=m===void 0?null:String(Ie(m,e.key)??"");u.useEffect(()=>{!c||m===void 0||p===null||p===""||h.has(p)||d.busy||(f(y=>new Set([...y,p])),d.run(c.action,Ds(c.action.args,{data:m,row:m,scope:s})))},[p,d.busy]);const x=c!==void 0&&d.running===c.action.tool;return t.jsxs(Ls,{title:e.title,note:e.note,children:[t.jsx(re,{message:i.error}),x?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(jr,{act:d}),x?null:o.length===0?i.loading?t.jsx(be,{children:"Loading…"}):t.jsx(cl,{text:e.empty??"Nothing here yet."}):t.jsx(de,{gap:"lg",divided:!0,children:bP(o,e.key,{plugin:s.plugin,page:s.page,component:`repeat "${e.title??e.rows}"`}).map(({key:y,row:j})=>t.jsx(ge,{children:t.jsx(de,{children:e.body.map((v,w)=>t.jsx(Vr,{component:v,data:j},w))})},y))})]})}function mY({component:e,data:n}){const s=xt(),r=$q({...e.views?{views:e.views}:{},...e.default?{default:e.default}:{},today:pq(s.timezone),storageKey:`buddi.calendar-view:${s.plugin}/${s.page}`}),a=Nn(e.query,n,void 0,{from:r.from,to:r.to}),i=u.useMemo(()=>jq(wr(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]=u.useState(null),c=e.sheet&&l!==null?i.find(d=>d.id===l)??null:null;return t.jsxs(Ls,{title:e.title,note:e.note,children:[t.jsx(re,{message:a.error}),t.jsx(Tq,{state:r,events:i,hours:e.hours,empty:e.empty??"Nothing.",label:e.title??"Calendar",onEvent:e.sheet?d=>o(d.id):void 0,count:e.count&&a.data!==void 0?i.length:void 0}),c&&e.sheet?t.jsx(pY,{event:c,sheet:e.sheet,onClose:()=>o(null)}):null]})}function pY({event:e,sheet:n,onClose:s}){const r=xt(),a=e.row,i=p=>{if(p===void 0)return"";const x=Ie(a,p);return x==null?"":String(x)},l=kq(e),o=i(n.color),c=i(n.notes),d=xf(i(n.mapHref)),h=n.open?xf(i(n.open.href)):null,f=n.open?i(n.open.label):"",m=p=>{const x=ds(p.replace(/\{when\}/g,l),{row:{...a,title:e.title,calendar:e.calendar,location:e.location}});s(),DG(x)||r.navigate(ma)};return t.jsx(Je,{title:e.title,onClose:s,foot:n.asks&&n.asks.length>0?t.jsx(se,{align:"end",children:n.asks.map((p,x)=>t.jsx(E,{onClick:()=>m(p.text),children:p.label},x))}):void 0,children:t.jsxs("div",{className:"pl-event-sheet",children:[t.jsx("p",{className:"pl-event-when",children:l}),e.calendar?t.jsxs("p",{className:"pl-event-cal",children:[o&&ib.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}),d?t.jsx(uo,{href:d,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(uo,{href:h,className:"wb-src-link",children:f})}):null]})})}function gY({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=wr(r.data,e.items).flatMap(m=>{const p=dy([m],a).tiles[0];return p?[{tile:p,key:e.select?String(Ie(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)??"",d=l?s.params[l.param]:void 0,h=i.some(m=>m.key===d);return u.useEffect(()=>{l&&c!==""&&!h&&s.setParams({[l.param]:c})},[l==null?void 0:l.param,c,h]),t.jsxs(Ls,{title:e.title,note:e.note,children:[t.jsx(re,{message:r.error}),r.data===void 0?t.jsx(be,{children:"Loading…"}):i.length===0?t.jsx(cl,{text:e.empty??"Nothing to show."}):t.jsx(TI,{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 xY({component:e,data:n}){const s=Nn(e.query,n),r=wr(s.data,e.points);if(s.data===void 0||r.length===0)return t.jsxs(Ls,{title:e.title,note:e.note,children:[t.jsx(re,{message:s.error}),s.data===void 0?t.jsx(be,{children:"Loading…"}):t.jsx(cl,{text:e.empty??"Nothing to show."})]});const a=r.map(c=>String(Ie(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,d)=>dy([c],i).tiles[0]??{icon:null,value:"",label:a[d]??"",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(d=>Es(Ie(d,c.y))??null)}));return t.jsxs(t.Fragment,{children:[t.jsx(re,{message:s.error}),t.jsx(Lq,{...e.title?{title:e.title}:{},...e.note?{note:e.note}:{},...e.labelEvery?{labelEvery:e.labelEvery}:{},xs:a,series:o,tiles:l})]})}function vY({component:e,data:n}){const s=Nn(e.query,n),r=o=>{const c=Ie(s.data,o);return c==null?"":String(c)};if(s.data===void 0||s.data===null)return t.jsxs(t.Fragment,{children:[t.jsx(re,{message:s.error}),t.jsx(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(", "),children:[t.jsxs("div",{className:"pg-hero-main","aria-hidden":"true",children:[t.jsx("span",{className:"pg-hero-icon",children:t.jsx(ie,{name:Po(uv(Ke(s.data,e.icon))),size:44})}),t.jsx("span",{className:"pg-hero-value",children:a}),i?t.jsx("span",{className:"pg-hero-title",children:i}):null]}),l.length>0?t.jsx("dl",{className:"pg-hero-facts","aria-hidden":"true",children:l.map(o=>t.jsxs("div",{className:"pg-hero-fact",children:[t.jsx("dt",{children:o.label}),t.jsx("dd",{children:o.value})]},o.label))}):null]})}function jY({component:e,data:n}){var x;const s=xt(),[r,a]=u.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:d}=gP({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?d.some(g=>g.value===s.params[c.param])?s.params[c.param]:((x=d[0])==null?void 0:x.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?Sa(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&&d.length>0?t.jsxs("div",{className:"pl-chips",role:"group","aria-label":c.label,children:[d.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(st,{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&&d.length>1?t.jsx(Jt,{label:c.label,options:d,value:h,onChange:g=>s.setParams({[c.param]:g})}):null,e.tabs.length>1?t.jsx("span",{className:"pg-tabs-switch",children:t.jsx(Jt,{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,y)=>t.jsx(Vr,{component:g,data:n},`${f.id}-${y}`))]})}function wY({component:e,data:n}){const[s,r]=u.useState(!1),a=Nn(s?e.query:void 0,n),i=typeof e.label=="string"?e.label:String(Ke(n,e.label)??"");return t.jsxs(Kt,{summary:i,boxed:!0,onToggle:l=>r(l),children:[t.jsx(re,{message:a.error}),a.data===void 0?t.jsx(be,{children:"Loading…"}):t.jsx(de,{children:e.body.map((l,o)=>t.jsx(Vr,{component:l,data:a.data},o))})]})}function CP({component:e,data:n}){const s=xt(),r=Qr();return t.jsxs(t.Fragment,{children:[t.jsx(se,{align:"end",children:t.jsx(ji,{action:e.action,args:Ds(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(jr,{act:r})]})}function yY({component:e}){const n=xt();return t.jsx(Gy,{plugin:n.plugin,agent:e.agent,text:e.text,label:e.label})}function bY(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 Vv(e){return e.length===0?"":e.length===1?e[0].name:`${e[0].name} and ${e.length-1} more`}function XS(e,n,s){const r={};for(const[a,i]of Object.entries(e))"row"in i?r[a]=Ie(n,i.row):"item"in i?r[a]=Ie(s,i.item):r[a]=Ke(n,i);return r}const kY=8e3;function ZS(e,n,s){const r=[];let a=null;return e.forEach((i,l)=>{if(!Mt(n,i.when))return;const o=i.each?Array.isArray(Ie(n,i.each))?Ie(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:ds(i.label,{row:c===void 0?n:c}),...i.hint?{hint:ds(i.hint,{row:n})}:{},onSelect:()=>s(i,c)})}}),r}function NY({component:e,data:n}){var b,C;const s=xt(),r=Nn(e.query,n),a=Qr(),i=e.param??"story",[l,o]=u.useState(null);u.useEffect(()=>{if(!l)return;const $=setTimeout(()=>o(null),kY);return()=>clearTimeout($)},[l]);const c=wr(r.data,e.rows).map(bY).filter($=>$!==null),d=e.ways??[],h=s.params[i],f=h?c.find($=>$.id===h)??null:null,m=async($,A,I,M)=>{var z;const O=XS($.args,A,I);if(!await a.run({tool:$.tool,label:$.label,...$.done!==void 0?{done:$.done}:{},...$.then?{then:$.then}:{}},O)||!$.hides)return;h===A.id&&s.setParams({[i]:null});const _=typeof $.done=="string"?ds($.done,{row:I===void 0?A:I}):"Hidden.";o({id:A.id,group:((z=A.group)==null?void 0:z.id)??null,index:M,text:_,...$.undo?{undo:{tool:$.undo.tool,label:$.undo.label,args:XS($.undo.args,A,I)}}:{}})},p=()=>{const $=l;o(null),$!=null&&$.undo&&a.run({tool:$.undo.tool,label:$.undo.label},$.undo.args)},x=[];for(const $ of c){if(l&&$.id===l.id)continue;const A=e.groups&&$.group?$.group.id:null;let I=x.find(M=>M.id===A);I||(I={id:A,name:e.groups&&$.group?$.group.name:null,rows:[]},x.push(I)),I.rows.push($)}l&&!x.some($=>$.id===l.group)&&x.push({id:l.group,name:null,rows:[]});const g=(b=e.groups)==null?void 0:b.param,y=!(x.length===1&&g!==void 0&&s.params[g]===x[0].id),j=($,A)=>t.jsx(AY,{row:$,plugin:s.plugin,menu:ZS(d,$,(I,M)=>void m(I,$,M,A)),onOpen:()=>s.setParams({[i]:$.id})},$.id),v=$=>t.jsxs("div",{className:"pl-story-gone",role:"status",children:[t.jsx("span",{children:$.text}),$.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:$.undo.label})]}):null]},`gone-${$.id}`),w=$=>{const A=$.rows.map(j);return l&&l.group===$.id&&A.splice(Math.min(l.index,A.length),0,v(l)),A};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"})]},A))});else if(c.length===0&&!l){const $=(e.emptyStates??[]).find(A=>Mt(r.data,A.when));if($){const A=M=>M===void 0?"":typeof M=="string"?M:String(Ke(r.data,M)??""),I=($.actions??[]).map((M,O,R)=>{const _=O===R.length-1&&(R.length>1||$.warm===!0);if(M.set)return t.jsx(E,{size:"sm",variant:_?"accent":"ghost",onClick:()=>s.setParams(M.set),children:M.label},O);const z=M.to?Sa(s,M.to,r.data):"";return z===""?null:t.jsx(st,{size:"sm",variant:_?"accent":"ghost",href:z,onClick:U=>{U.preventDefault(),s.navigate(z)},children:M.label},O)});N=t.jsx(be,{warm:$.warm===!0,title:A($.title),action:I.length>0?t.jsx(se,{children:I}):void 0,children:A($.text)})}else N=t.jsx(cl,{text:e.empty??"Nothing here yet."})}else N=x.map($=>{var A;return t.jsxs("section",{className:"pl-story-group","aria-label":$.name??e.title??"Stories",children:[y&&$.name?t.jsxs("header",{className:"pl-story-group-head",children:[t.jsx("h2",{className:"pl-story-group-title",children:$.name}),g&&$.id?t.jsxs("a",{href:"#",className:"pl-story-group-aside",onClick:I=>{I.preventDefault(),s.setParams({[g]:$.id})},children:[((A=e.groups)==null?void 0:A.label)??"See all",t.jsx(ie,{name:"arrow",size:12})]}):null]}):null,t.jsx("div",{className:"pl-story-grid",children:w($)})]},$.id??"all")});const k=d.find($=>$.hides&&!$.each&&Mt(f,$.when)),S=d.filter($=>$!==k);return t.jsxs("div",{className:"pl-stories",children:[t.jsx(re,{message:r.error}),t.jsx(EP,{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(se,{children:[k?t.jsx(E,{variant:"ghost",disabled:a.busy,onClick:()=>void m(k,f,void 0,0),children:ds(k.label,{row:f})}):null,S.length>0?t.jsx(Qn,{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:ZS(S,f,($,A)=>void m($,f,A,0)),stacked:!0}):null,t.jsx(gt,{}),e.ask&&Mt(f,e.ask.when)?t.jsx(SY,{to:e.ask.to,row:f,label:e.ask.label,accent:!0}):null]}),children:t.jsx($Y,{row:f,plugin:s.plugin,edition:e.edition})}):null]})}function EP({act:e}){return e.error?t.jsx(re,{message:e.error}):e.approvalId?t.jsx(jr,{act:e}):null}function SY({to:e,row:n,label:s,accent:r}){const a=xt(),i=Sa(a,e,n);return i===""?null:"href"in e?t.jsx(st,{variant:r?"accent":"ghost",href:i,target:"_blank",rel:"noopener noreferrer",children:s}):t.jsx(st,{variant:r?"accent":"ghost",href:i,onClick:l=>{l.preventDefault(),a.navigate(i)},children:s})}function CY({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(lo,{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 EY({plugin:e,outlets:n}){return n.length===0?null:t.jsxs("span",{className:"pl-stack","aria-label":Vv(n),children:[t.jsx("span",{className:"pl-stack-logos",children:n.slice(0,3).map((s,r)=>t.jsx(Oo,{src:Kd(e,s.logo),label:s.name},r))}),t.jsx("span",{className:"pl-stack-words",children:Vv(n)})]})}function AY({row:e,plugin:n,menu:s,onOpen:r}){var i;const a=Vv(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(EY,{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(Qn,{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(CY,{row:e})]})}function $Y({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&&Mt(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(lo,{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(TY,{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=xf(l.url);return t.jsxs("li",{className:"pl-story-source",children:[t.jsx(Oo,{className:"pl-logo-md",src:Kd(n,l.logo),label:l.outlet}),t.jsxs("span",{className:"pl-story-source-text",children:[c?t.jsx(uo,{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 TY({to:e,row:n,label:s}){const r=xt(),a=Sa(r,e,n);return a===""?null:"href"in e?t.jsx(uo,{href:a,children:s}):t.jsx("a",{href:a,onClick:i=>{i.preventDefault(),r.navigate(a)},children:s})}function IY({component:e,data:n}){const s=Ie(n,e.path);return typeof s!="string"||s===""?null:t.jsx(jf,{id:s})}function RY({component:e,data:n}){const s=Ie(n,e.path);return typeof s!="string"||s===""?null:t.jsx(se,{children:t.jsx("a",{href:ai(s),children:e.label})})}function AP(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 eC(e){return Array.isArray(e)?e.map(AP).filter(n=>n!==null):[]}function tC(e){return e.name?`${e.name} <${e.address}>`:e.address}function nC(e){if(!e||typeof e!="object")return null;const n=e,s=AP(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:eC(n.to),cc:eC(n.cc),at:r("at"),html:r("html"),text:r("text"),snippet:r("snippet"),note:r("note"),attachments:a}}function PY(e){var s;return(((s=(e.name??e.address).replace(/^["'\s]+/,"").match(/[\p{L}\p{N}]/u))==null?void 0:s[0])??"?").toUpperCase()}function MY(e){let n=0;for(const s of e.toLowerCase())n=n*31+s.charCodeAt(0)>>>0;return n%6+1}function OY({component:e,data:n}){const s=xt(),r=e.path?Ie(n,e.path):n,a=e.folded!==void 0&&Mt(r,e.folded),[i,l]=u.useState(!a),[o,c]=u.useState(!1),d=Nn(i?e.query:void 0,r),h=nC(r),f=e.query?nC(d.data):h,m=f??h;if(!m)return null;const p=m.from,x=m.at?im(new Date(m.at),s.timezone):"",g=[...m.to??[],...m.cc??[]],y=t.jsx("span",{className:"ui-avatar pl-mail-face","data-face":MY(p.address),"aria-hidden":"true",children:PY(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:[y,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:x}):x})]}),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(tC).join(", ")})]}):null,(m.cc??[]).length>0?t.jsxs(t.Fragment,{children:[t.jsx("dt",{children:"Cc"}),t.jsx("dd",{children:(m.cc??[]).map(tC).join(", ")})]}):null]}):null,t.jsx(re,{message:d.error}),e.query&&!f&&!d.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(E7,{html:m.html,text:m.text,sender:p.address,attachments:m.attachments,cidSrc:vr}),(m.attachments??[]).length>0?t.jsx(DY,{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:[y,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:x})]})}function DY({attachments:e,fetch:n}){const s=xt(),r=Qr();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(Vd,{name:a.name,mime:a.mime,sizeBytes:typeof a.size=="number"?a.size:null,...a.artifactId?{onOpen:()=>s.navigate(cc(a.artifactId))}:{}}),!a.artifactId&&n?t.jsx(ji,{action:n,args:Ds(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(jr,{act:r})]})}function LY({component:e,data:n}){const s=Nn(e.query,n),r=Qr();return s.error?t.jsx(re,{message:s.error}):s.data===void 0?t.jsx(be,{children:e.empty??"Loading…"}):t.jsxs(t.Fragment,{children:[t.jsx(jr,{act:r}),t.jsx(FY,{component:e,data:n,loaded:s.data,act:r},JSON.stringify(s.data))]})}function FY({component:e,data:n,loaded:s,act:r}){const a=xt(),[i,l]=u.useState(()=>vd(e.fields,s)),o={...i,version:Ie(s,e.version)},c=rb(e.fields,i,s),d=e.readOnlyWhen!==void 0&&Mt(s,e.readOnlyWhen),h=(e.actions??[]).filter(p=>p.placement==="leading"),f=(e.actions??[]).filter(p=>p.placement!=="leading"),m=(p,x)=>t.jsx(ji,{action:p,args:Ds(p.args,{data:n,fields:o,shape:e.fields,omit:c,scope:a}),disabled:r.busy,running:r.running===p.tool,onRun:(g,y)=>void r.run(g,y)},`${p.tool}-${x}`);return t.jsx(Ls,{title:e.title,note:e.note,children:t.jsxs(de,{children:[t.jsx(Mm,{fields:e.fields,values:i,data:s,disabled:d,onChange:(p,x)=>l(g=>({...g,[p]:x}))}),d?null:t.jsxs(se,{align:"end",children:[h.map(m),h.length>0?t.jsx(gt,{}):null,m(e.save,-1),f.map(m)]}),e.footnote?t.jsx("p",{className:"ui-toolbar-note",children:e.footnote}):null]})})}function $P({page:e,item:n,navigate:s,timezone:r,embedded:a,siblings:i,params:l}){const[o,c]=u.useState(()=>({...l})),d=JSON.stringify(l??{});u.useEffect(()=>{l&&Object.keys(l).length>0&&c(y=>({...y,...l}))},[d]);const[h,f]=u.useState(0),m={plugin:e.plugin,page:e.id,pages:i??[e],item:n??null,params:{...o,...n?{item:n}:{},...BY(e,n)},setParams:y=>c(j=>{const v={...j};for(const[w,N]of Object.entries(y))N===null?delete v[w]:v[w]=N;return v}),navigate:s,timezone:r,version:h,refresh:()=>f(y=>y+1),sensitive:new Set(e.sensitive??[])},p=e.body[0],x=!a&&(p==null?void 0:p.kind)==="notice"&&p.look!=="quiet"&&p.link===void 0&&p.action===void 0&&p.when===void 0&&p.title===void 0&&(p.tone===void 0||p.tone==="neutral")?p.text:void 0,g=x===void 0?e:{...e,body:e.body.slice(1)};return t.jsx(nb.Provider,{value:m,children:t.jsx(_Y,{page:g,embedded:a===!0,lede:x})})}function _Y({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:Ke(l,s),c=o==null||o===""?void 0:String(o),d=!n&&e.actions&&e.actions.length>0?t.jsx(t.Fragment,{children:e.actions.map((h,f)=>t.jsx(zY,{component:h,data:l},f))}):void 0;return t.jsxs(js,{embedded:n,title:e.title,lede:c,actions:d,children:[!n&&e.place==="rail"?t.jsx(eP,{plugin:e.plugin,navigate:r.navigate,dismissible:!0},e.plugin):null,t.jsx(UY,{page:e,boxed:n,root:a?void 0:i})]})}function zY({component:e,data:n}){const s=xt();if(!Mt(n,e.when))return null;if(e.kind==="button")return t.jsx(CP,{component:e,data:n});if(e.kind==="menu")return t.jsx(wP,{component:e,data:n});const r=Sa(s,e.to,n);if(r==="")return null;const a=e.tone==="accent"?"accent":"ghost";return"href"in e.to?t.jsxs(st,{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(st,{variant:a,href:r,onClick:i=>{i.preventDefault(),s.navigate(r)},children:e.label})}function UY({page:e,boxed:n,root:s}){const r=xt();return e.data&&r.sensitive.has(e.data.query)?t.jsx(mP,{children:t.jsx(sC,{page:e,boxed:n})}):t.jsx(sC,{page:e,boxed:n,root:s})}function sC({page:e,boxed:n,root:s}){const r=Nn(s?void 0:e.data,null),a=s??r;return t.jsxs(de,{gap:"lg",divided:!n,children:[t.jsx(re,{message:a.error}),t.jsx(jd.Provider,{value:n,children:e.body.map((i,l)=>t.jsx(Vr,{component:i,data:a.data??null},l))})]})}function BY(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 WY(e){return t.jsx($P,{...e,embedded:!0})}function cl({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(as,{title:s,children:r||null})}const rC=[{id:"",label:"All files"},{id:"produced",label:"Created by agents"},{id:"uploaded",label:"Uploaded by you"}],HY=["","image","pdf","table","text","code","audio","video","archive","file"];function KY({hash:e,timezone:n,navigate:s,agents:r}){var O;const a=p6(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)??"",[d,h]=u.useState(c);u.useEffect(()=>{h(c)},[c]);const f=(R,_=!1)=>s(cc(i,{q:c,origin:l,family:o,...R}),_);u.useEffect(()=>{if(d===c)return;const R=window.setTimeout(()=>f({q:d},!0),250);return()=>window.clearTimeout(R)},[d]);const[m,p]=u.useState(null),[x,g]=u.useState(null),[y,j]=u.useState(null),[v,w]=u.useState(!1),[N,k]=u.useState(!1),S=R=>{var _;return R?((_=r.find(z=>z.id===R))==null?void 0:_.name)??R:""},b=u.useRef(0);u.useEffect(()=>{const R=++b.current;p(null),g(null),w(!1),j(null),T.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{}}).then(_=>{b.current===R&&(p(_.entries),g(_.next))}).catch(_=>{b.current===R&&j(_ instanceof fe?_.message:String(_))})},[c,l,o]);const C=()=>{if(!x||v)return;w(!0);const R=b.current;T.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{},cursor:x}).then(_=>{b.current===R&&(p(z=>{const U=new Set((z??[]).map(P=>P.id));return[...z??[],..._.entries.filter(P=>!U.has(P.id))]}),g(_.next))}).catch(_=>{b.current===R&&j(_ instanceof fe?_.message:String(_))}).finally(()=>{b.current===R&&w(!1)})},$=(l?1:0)+(o?1:0),A=((O=rC.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(ut,{children:m.map(R=>t.jsx(gI,{href:cc(R.id,{q:c,origin:l,family:o}),current:R.id===i,onClick:()=>s(cc(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:vr(R.id),alt:"",loading:"lazy"}):t.jsx(Ay,{family:R.family})}),title:R.filename??"Untitled file",meta:t.jsx("span",{title:ft(R.createdAt,n),children:Ge(R.createdAt)}),sub:`${R.caption&&R.origin==="produced"?`${R.caption} · `:""}${zi[R.family]} · ${vs(R.sizeBytes)} · ${TP(R,S)}${VY(R,S)}`},R.id))}),x?t.jsx("div",{className:"files-more",children:t.jsx(E,{size:"sm",onClick:C,disabled:v,children:v?"Loading…":"Show more"})}):null]}),M=m!==null&&m.length===0&&!c&&!l&&!o&&!d;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."})]}),M?t.jsx(as,{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(jI,{label:"Files",onSubmit:()=>f({q:d},!0),main:t.jsx("input",{type:"search",value:d,placeholder:"Search by name or label","aria-label":"Search files by name or label",onChange:R=>h(R.target.value)}),filters:t.jsxs(Ts,{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:rC.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:HY.map(R=>t.jsx("option",{value:R,children:R===""?"Any kind":zi[R]},R))})})]}),filtersOpen:N,onToggleFilters:()=>k(R=>!R),active:$,chips:$>0?t.jsxs(t.Fragment,{children:[l?t.jsx(ef,{label:"Origin",onRemove:()=>f({origin:""}),children:A}):null,o?t.jsx(ef,{label:"Kind",onRemove:()=>f({family:""}),children:zi[o]}):null]}):void 0}),t.jsx(re,{message:y}),t.jsx(xI,{className:"files-split",label:"Files",list:I,detail:i?t.jsx(GY,{id:i,timezone:n,agents:r,navigate:s,onBack:()=>s(cc(null,{q:c,origin:l,family:o}))},i):void 0,empty:"Choose a file to see it here."})]})]})}function VY(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 TP(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 GY({id:e,timezone:n,agents:s,navigate:r,onBack:a}){const[i,l]=u.useState(null),[o,c]=u.useState(!1),[d,h]=u.useState(null);u.useEffect(()=>{let v=!1;return l(null),h(null),T.libraryEntry(e).then(w=>{v||l(w)}).catch(w=>{v||h(w instanceof fe&&w.status===404?"This file is no longer in the library.":w instanceof fe?w.message:String(w))}),()=>{v=!0}},[e]);const f=v=>{var w;return v?((w=s.find(N=>N.id===v))==null?void 0:w.name)??v:""};if(d)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:d})]});if(!i)return t.jsx("div",{className:"files-detail-body",children:t.jsx(be,{children:"Loading…"})});const{entry:m,contexts:p,contextsTotal:x,available:g}=i,y=m.filename??"Untitled file",j=()=>{c(!0),T.libraryEntry(e,p.length).then(v=>l(w=>w&&{...w,contexts:[...w.contexts,...v.contexts],contextsTotal:v.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(Ay,{family:m.family})}),t.jsxs("div",{className:"files-detail-text",children:[t.jsx("h3",{className:"files-detail-name",children:y}),t.jsxs("p",{className:"files-detail-meta",children:[zi[m.family]," · ",vs(m.sizeBytes)," · ",ft(m.createdAt,n)]})]}),g?t.jsx(UI,{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(zI,{artifactId:m.id,filename:m.filename,mime:m.mime,family:m.family,available:g}),t.jsx(Qt,{items:[{label:"Origin",value:TP(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(v=>{const w=v.groupId?$i(v.groupId,v.conversationId):lt(v.conversationAgentId,v.conversationId),N=v.groupId?v.groupName??"a group":f(v.conversationAgentId);return t.jsxs("li",{className:"files-ctx-row",children:[t.jsxs("span",{className:"files-ctx-text",children:[t.jsx("span",{children:v.groupId?`Group: ${N}`:N}),t.jsxs("span",{className:"muted",children:[" · ",v.kind==="produced"?`made by ${f(v.agentId)||"an agent"}`:v.kind==="reused"?"sent again":"sent by you"," · ",Ge(v.at)]})]}),t.jsx("a",{className:"ui-btn","data-size":"sm",href:w,onClick:k=>{k.preventDefault(),r(w)},children:"Open conversation"})]},`${v.conversationId}:${v.kind}`)})}),p.length<x?t.jsx(se,{align:"end",children:t.jsx(E,{size:"sm",onClick:j,disabled:o,children:o?"Loading…":`Show ${x-p.length} more`})}):null]})]})}const IP="buddi.keepClose";let ho=null;const Gv=new Set;function qv(){for(const e of Gv)e()}typeof window<"u"&&(window.addEventListener("beforeinstallprompt",e=>{e.preventDefault(),ho=e,qv()}),window.addEventListener("appinstalled",()=>{ho=null,ob(),qv()}));function Om(){const[e,n]=u.useState(ho);return u.useEffect(()=>{const s=()=>n(ho);return Gv.add(s),s(),()=>{Gv.delete(s)}},[]),RP()?null:e}async function lb(e){try{await e.prompt();const n=await e.userChoice;ho===e&&(ho=null);const s=(n==null?void 0:n.outcome)==="accepted";return s&&ob(),qv(),s}catch{return!1}}function qY(){try{return window.localStorage.getItem(IP)!==null}catch{return!1}}function ob(){try{window.localStorage.setItem(IP,"dismissed")}catch{}}function RP(){var e;try{return((e=window.matchMedia)==null?void 0:e.call(window,"(display-mode: standalone)").matches)??!1}catch{return!1}}function YY(e=window.location.hostname){const n=e.replace(/^\[|\]$/g,"").toLowerCase();return n==="127.0.0.1"||n==="::1"||n==="localhost"}function cb(e=typeof navigator>"u"?"":navigator.userAgent){return/\bbuddi-mac\/\S+/.test(e)}function PP(e){return cb(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 QY(e){return/Mac|iPhone|iPad/.test(e)}function JY(){const e=Om(),[n,s]=u.useState(qY);if(n||!e)return null;const r=()=>{ob(),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(se,{align:"end",children:[t.jsx(E,{size:"sm",variant:"ghost",onClick:r,children:"Not now"}),t.jsx(E,{size:"sm",variant:"accent",onClick:()=>{lb(e).then(a=>{a&&s(!0)})},children:"Install"})]})]})}function XY(){const e=Om(),[n,s]=u.useState(void 0),[r]=u.useState(RP);if(u.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=YY(),l=e?null:PP(a);return t.jsx(ge,{title:"The dashboard as an app",panel:!0,foot:e?t.jsx(se,{align:"end",children:t.jsx(E,{variant:"accent",onClick:()=>{lb(e)},children:"Install the app"})}):void 0,children:t.jsxs(de,{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 ",QY(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 ZY={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 MP(e){return e&&ZY[e]||"plug"}const eQ=""+new URL("earth-2560-Ce3xs8Cb.webp",import.meta.url).href,tQ=""+new URL("earth-phone-BqC7cDhk.webp",import.meta.url).href,nQ="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=",Yv={desk:eQ,phone:tQ,thumb:nQ},og={author:"ActionVance",authorUrl:"https://unsplash.com/@actionvance",photoUrl:"https://unsplash.com/photos/outer-space-photography-of-earth-t7EL2iG3jMc"};function sQ(e){return e?Yv.phone:Yv.desk}const OP="backgrounds/",rQ=`${OP}manifest.json`,aQ=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,iQ=/^[\w.-]+\.jpg$/;function lQ(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"||!aQ.test(a.id)||a.id.length>64||s.some(d=>d.id===a.id)||typeof a.title!="string"||!a.title.trim()||typeof a.credit!="string"||!a.credit.trim())continue;const i=d=>d===void 0?null:typeof d=="string"&&iQ.test(d)?`${OP}${d}`: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 nc=null;function oQ(){if(!nc){const e=(async()=>{const n=await fetch(rQ,{credentials:"same-origin"});if(!n.ok)throw new Error(`manifest ${n.status}`);return lQ(await n.json())})();nc=e,e.catch(()=>{nc===e&&(nc=null)})}return nc}function DP(e=!0){const[n,s]=u.useState(null);return u.useEffect(()=>{if(!e)return;let r=!0;return oQ().then(a=>{r&&s(a)},()=>{r&&s([])}),()=>{r=!1}},[e]),n}const Qv="picture:";function cQ(e){return`${Qv}${e}`}function LP(e){return typeof e=="string"&&e.startsWith(Qv)?e.slice(Qv.length):null}function dQ(e,n){return n?{src:e.portrait??e.landscape,fit:"cover"}:e.landscape?{src:e.landscape,fit:"cover"}:{src:e.portrait,fit:"contain"}}function uQ(e,n,s){return s&&n?n:e}function FP(){const[e,n]=u.useState(()=>new Date);return u.useEffect(()=>{let s;const r=()=>{s=setTimeout(()=>{n(new Date),r()},6e4-Date.now()%6e4+50)};return r(),()=>clearTimeout(s)},[]),e}const hQ=3,_P=8e3,fQ={hiddenHere:new Set,restoredHere:new Set};function mQ(e,n){return n.hiddenHere.has(e.id)?!0:e.hidden&&!n.restoredHere.has(e.id)}function pQ(e,n=fQ){return(e??[]).filter(s=>!mQ(s,n)).slice(0,hQ)}function zP(e){const[n,s]=u.useState(new Set),[r,a]=u.useState(new Set),[i,l]=u.useState(null),o=u.useRef(e);o.current=e;const c=(m,p)=>new Set(m).add(p),d=(m,p)=>{const x=new Set(m);return x.delete(p),x};return u.useEffect(()=>{if(!i)return;const m=window.setTimeout(()=>l(null),_P);return()=>window.clearTimeout(m)},[i]),{hiddenHere:n,restoredHere:r,justHidden:i,hide:(m,p)=>{s(x=>c(x,m.id)),a(x=>d(x,m.id)),l({glance:m,spot:p}),T.setGlanceHidden(m.id,!0).then(()=>{var x;return(x=o.current)==null?void 0:x.call(o)},()=>{s(x=>d(x,m.id)),l(x=>(x==null?void 0:x.glance.id)===m.id?null:x)})},undo:()=>{if(!i)return;const{glance:m}=i;l(null),s(p=>d(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=>d(p,m.id)),s(p=>c(p,m.id))})}}}function gQ({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 xQ(e){return e.link?ky(e.link.plugin,e.link.page,e.link.place):null}function vQ({glances:e,navigate:n,onChanged:s,except:r,hiding:a}){var d,h;const i=zP(s),l=a??i,o=pQ(e,l).filter(f=>!(r!=null&&r.has(f.id))),c=t.jsx(gQ,{hiding:l,spot:"line"});return o.length===0&&((d=l.justHidden)==null?void 0:d.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=xQ(f),p=t.jsxs(t.Fragment,{children:[t.jsx(ie,{name:Po(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:x=>{x.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 jQ(e){const a=Math.min(...e),l=Math.max(...e)-a||1,o=Math.max(e.length-1,1);return e.map((c,d)=>[d/o*100,2+(1-(c-a)/l)*(24-2*2)])}function wQ({points:e,className:n="wg-spark"}){const s=jQ(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 bl=Math.PI/180;function yQ(e,n,s){const r=e.getTime()/864e5+24405875e-1-2451545,a=(357.529+.98560028*r)*bl,l=(280.459+.98564736*r+1.915*Math.sin(a)+.02*Math.sin(2*a))*bl,o=(23.439-36e-8*r)*bl,c=Math.atan2(Math.cos(o)*Math.sin(l),Math.cos(l)),d=Math.asin(Math.sin(o)*Math.sin(l)),f=((18.697374558+24.06570982441908*r)*15+s)*bl-c,m=n*bl,p=Math.sin(m)*Math.sin(d)+Math.cos(m)*Math.cos(d)*Math.cos(f);return Math.asin(Math.max(-1,Math.min(1,p)))/bl}function bQ(e,n,s){return yQ(e,n,s)>-.833}const kQ={small:2,medium:4},aC=new Map;function NQ(e){let n=aC.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"}),aC.set(e,n)),n}function iC(e,n){const s=Object.fromEntries(NQ(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 SQ(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 CQ(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 EQ(e,n,s,r,a){const i=iC(e,n.zone),l=iC(e,s),o=i.date===l.date?"Today":i.date>l.date?"Tomorrow":"Yesterday",c=i.offset-l.offset,d=Id(a?{timeFormat:a}:{},()=>$t(e,n.zone)),h=r?"your time":CQ(c);return{...i,day:o,daytime:typeof n.latitude=="number"&&typeof n.longitude=="number"?bQ(e,n.latitude,n.longitude):i.h>=6&&i.h<18,offsetText:r?"Here":SQ(c),time:d,label:`${n.label}, ${d}${o==="Today"?"":` ${o.toLowerCase()}`}, ${h}`}}function AQ(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 $Q(e){const[n,s]=u.useState(()=>new Date);return u.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 lC({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 TQ=Array.from({length:12},(e,n)=>n);function IQ({time:e,seconds:n}){const s=AQ(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"}),TQ.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(lC,{angle:s.hour,length:24,width:4.6}),t.jsx(lC,{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 RQ({body:e,size:n}){const s=Gn("(prefers-reduced-motion: reduce)"),r=$Q(!s),a=e.clocks.slice(0,kQ[n]);return t.jsx("div",{className:"wg-clocks","data-count":a.length,children:a.map((i,l)=>{let o;try{o=EQ(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(IQ,{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,PQ={small:4,medium:6};function dg({icon:e,size:n}){return e?t.jsx("span",{className:"wg-icon",children:t.jsx(ie,{name:Po(e),size:n})}):null}function Dm({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(dg,{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(wQ,{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(Oo,{className:"wg-mark",src:HI(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(dg,{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,PQ[n]).map((s,r)=>t.jsxs("span",{className:"wg-tile",children:[t.jsx("span",{className:"wg-tile-label",children:s.label}),t.jsx(dg,{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(RQ,{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:Po(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 Jv({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(d=>d!==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 oC(e){return"place"in e?e.place:`town:${e.latitude.toFixed(3)},${e.longitude.toFixed(3)}`}function MQ(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 OQ({field:e,value:n,places:s,onChange:r}){const a=Array.isArray(n)?n:n?[n]:[],[i,l]=u.useState(""),[o,c]=u.useState([]),[d,h]=u.useState(!1),[f,m]=u.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(oC(N),{value:N,label:N.label,sub:N.name});const x=[...p.entries()].map(([N,k])=>({value:N,label:k.label,sub:k.sub})),g=a.map(oC),y=s.find(N=>N.id==="home"||N.label.toLowerCase()==="home")??s[0],j=e.multiple?g:g[0]??(y==null?void 0:y.id)??"",v=N=>{const k=(Array.isArray(N)?N:[N]).map(S=>{var b;return(b=p.get(S))==null?void 0:b.value}).filter(S=>!!S);r(e.multiple?k.slice(-3):k[0]??null)},w=()=>{const N=i.trim();N.length<2||(h(!0),m(null),T.findPlace(N).then(({found:k})=>{const S=k.slice(0,3).map(MQ);c(S),S.length===0?m(`Nothing found for “${N}”.`):e.multiple?r([...a,S[0]].slice(-3)):r(S[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:[x.length>0?t.jsx(Jv,{label:e.label,options:x,multiple:e.multiple,value:j,onChange:v}):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:d||i.trim().length<2,onClick:w,children:d?"Finding…":"Find"})]}),f?t.jsx("span",{className:"ui-field-hint",children:f}):null]})}function DQ({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(d=>d.label.length<=14);a=l.length===0?t.jsx("span",{className:"ui-field-hint",children:"Nothing to choose from yet."}):c?t.jsx(Jt,{label:e.label,options:l,value:o,onChange:r}):t.jsx(Jv,{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(Jv,{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(OQ,{field:e,value:n,places:s.places,onChange:r});break;case"timeFormat":a=t.jsx(Jt,{label:e.label,options:[{value:"profile",label:P$()},{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 LQ({info:e,placement:n,surface:s,view:r,label:a}){var d;const i=s==="lock",l=((d=r==null?void 0:r.body)==null?void 0:d.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(Dm,{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 UP({info:e,placement:n,surface:s,onSave:r,onRemove:a,onClose:i}){const l=pe(()=>T.widgetSettings(e.id),[e.id]),[o,c]=u.useState(n.settings??{}),[d,h]=u.useState(null),[f,m]=u.useState(n.label??e.title),[p,x]=u.useState(!1),[g,y]=u.useState(null),j=u.useRef(0),v=u.useMemo(()=>JSON.stringify(o),[o]);u.useEffect(()=>{const k=++j.current,S=window.setTimeout(()=>{T.previewWidget({widget:e.id,size:n.size,settings:o}).then(b=>{k===j.current&&(h(b.view),m(b.label))}).catch(()=>{k===j.current&&h({state:"error",error:"the preview could not be made"})})},d?250:0);return()=>window.clearTimeout(S)},[v,e.id,n.size]);const w=()=>{x(!0),y(null),r(o).then(k=>{x(!1),k||y("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(se,{children:[t.jsxs(E,{variant:"danger-ghost",onClick:a,children:["Remove from ",s==="lock"?"lock screen":"Home"]}),t.jsx(gt,{}),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(LQ,{info:e,placement:n,surface:s,view:d,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(re,{message:g??(l.error?"Couldn’t read this widget’s settings.":null)}),l.data?l.data.fields.map(k=>t.jsx(DQ,{field:k,value:o[k.key],sheet:l.data,onChange:S=>c({...o,[k.key]:S})},k.key)):l.error?null:t.jsx("p",{className:"wg-sheet-note","aria-busy":"true",children:"Reading its choices…"})]})})}const FQ=6e4,BP="buddi.clock",WP="buddi.home.widgets";function _Q(){try{const e=Number(window.localStorage.getItem(WP));return Number.isInteger(e)&&e>0?Math.min(e,6):0}catch{return 0}}function zQ(e){try{window.localStorage.setItem(WP,String(e))}catch{}}function HP(){const e=new Uint8Array(4);return crypto.getRandomValues(e),`w-${Array.from(e,n=>n.toString(16).padStart(2,"0")).join("")}`}function KP(e,n){const s=u.useRef(n);s.current=n,u.useEffect(()=>{if(!e)return;let r;const a=()=>{r=setTimeout(()=>{s.current(),a()},6e4-Date.now()%6e4+1e3)};return a(),()=>clearTimeout(r)},[e])}function UQ(){const e=pe(()=>T.widgets("home"),[],FQ),[n,s]=u.useState(void 0);return u.useEffect(()=>{e.data&&s(e.data)},[e.data]),u.useEffect(()=>{n&&zQ(n.home.length)},[n]),KP((n==null?void 0:n.home.some(r=>{var a,i;return r.widget===BP&&((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 BQ(e){return new Set(((e==null?void 0:e.home)??[]).map(n=>n.widget))}function WQ(e){const[n,s]=u.useState(!1);return u.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 VP=(e,n)=>e.label??(n==null?void 0:n.title)??e.widget;function HQ({info:e,placement:n,view:s,index:r,count:a,editing:i,navigate:l,act:o,onRetry:c,retrying:d,drag:h}){var b;const[f,m]=WQ(e.sensitive===!0),p=(s==null?void 0:s.state)??"error",x=e.sensitive===!0&&!f,g=e.link?ky(e.link.plugin,e.link.page,e.link.place):null,y=g!==null&&!i&&p!=="error"&&!x,j=n.size==="small"?"medium":"small",v=VP(n,e),w=n.key,N=(((b=e.settings)==null?void 0:b.length)??0)>0;let k;!s&&i?k=t.jsx("span",{className:"wg-state",children:t.jsx("span",{className:"wg-state-sub",children:"Fills in when you press Done."})}):p==="error"||!s?k=t.jsxs("span",{className:"wg-state",children:[t.jsx("span",{className:"wg-state-title",children:"Couldn't load this."}),s!=null&&s.error?t.jsxs("span",{className:"wg-state-sub",children:[KQ(s.error),"."]}):null,i?null:t.jsx(E,{size:"sm",onClick:c,disabled:d,children:d?"Trying…":"Try again"})]}):p==="empty"||!s.body?k=t.jsx("span",{className:"wg-state",children:t.jsx("span",{className:"wg-state-sub",children:"Nothing to show right now."})}):x?k=t.jsxs("span",{className:"wg-state",children:[t.jsx("span",{className:"wg-mask","aria-hidden":"true",children:"••••"}),t.jsx("span",{className:"wg-state-sub",children:"Hidden on this screen."}),i?null:t.jsx(E,{size:"sm",onClick:()=>m(!0),children:"Show"})]}):k=t.jsx(Dm,{body:s.body,size:n.size});const S=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":v,"data-id":e.id,"data-key":w,"data-size":n.size,"data-kind":s!=null&&s.body&&!x&&p!=="error"?s.body.kind:void 0,"data-state":p==="ok"?void 0:p,"data-linked":y?"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?S: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 ${v}, 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:v}),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?`${Dw(s.updatedAt)} old`:"Not current"}):null,i&&N?t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Settings for ${v}`,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 ${v} 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(Qn,{label:`More for ${v}`,note:s!=null&&s.updatedAt?`${e.builtIn?"Built in":e.plugin} · ${Ge(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")}]})})]}),y?t.jsx("a",{className:"wg-body",href:g,onClick:C=>{C.preventDefault(),l(g)},children:k}):t.jsx("div",{className:"wg-body",children:k}),i?t.jsxs("div",{className:"wg-edit-bar",children:[e.sizes.length>1?t.jsx("span",{className:"ui-segment",role:"radiogroup","aria-label":`Size of ${v}`,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 ${v} 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 ${v} later`,title:"Move later",disabled:r===a-1,onClick:()=>o("later"),children:t.jsx(ie,{name:"chevron-right"})})]})]}):null]})}function KQ(e){const n=e.replace(/\.$/,"");return n.charAt(0).toUpperCase()+n.slice(1)}function VQ({widgets:e,navigate:n}){const{answer:s,apply:r}=e,[a,i]=u.useState(!1),[l,o]=u.useState([]),[c,d]=u.useState(null),[h,f]=u.useState(""),[m,p]=u.useState(null),[x,g]=u.useState(!1),[y,j]=u.useState(null),[v,w]=u.useState(null),[N,k]=u.useState(null),[S,b]=u.useState(null),[C,$]=u.useState(new Set),[A]=u.useState(_Q),I=u.useRef(null);if(u.useEffect(()=>{if(!c)return;const B=window.setTimeout(()=>d(null),_P);return()=>window.clearTimeout(B)},[c]),u.useEffect(()=>{var ne;const B=I.current;B&&(I.current=null,(ne=document.querySelector(`[data-grip="${CSS.escape(B)}"], [data-move="${CSS.escape(B)}"]`))==null||ne.focus())}),!s)return A===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:A},(B,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(B=>B.builtIn)&&s.home.length===0)return null;const M=new Map(s.available.map(B=>[B.id,B])),O=a?l:s.home,R=B=>VP(B,M.get(B.widget)),_=(B,ne)=>(p(null),r({...ne,home:B,arranged:{...ne.arranged,home:!0}}),T.saveWidgets("home",B).then(Z=>(r(Z),!0),Z=>(r(ne),p(`Couldn't save your widgets: ${Z instanceof Error?Z.message:String(Z)}`),!1))),z=(B,ne,Z)=>{if(Z<0||Z>=B.length||ne===Z)return null;const ve=B.slice(),[$e]=ve.splice(ne,1);return ve.splice(Z,0,$e),f(`${R($e)}, position ${Z+1} of ${ve.length}.`),ve},U=()=>{o(s.home),$(new Set),d(null),p(null),i(!0)},P=B=>(ne,Z)=>{const ve=O[B];if(ne==="edit"){U();return}if(ne==="settings"){b(ve.key);return}if(a){if(ne==="earlier"||ne==="later"){const $e=z(l,B,ne==="earlier"?B-1:B+1);if($e){const Se=document.activeElement;I.current=(Se==null?void 0:Se.dataset.grip)??(Se==null?void 0:Se.dataset.move)??null,o($e)}}ne==="size"&&Z&&(o(l.map(($e,Se)=>Se===B?{...$e,size:Z}:$e)),$(new Set([...C,ve.key]))),ne==="hide"&&(o(l.filter(($e,Se)=>Se!==B)),f(`${R(ve)} taken off.`));return}if(ne==="earlier"||ne==="later"){const $e=z(s.home,B,ne==="earlier"?B-1:B+1);$e&&_($e,s)}ne==="size"&&Z&&_(s.home.map(($e,Se)=>Se===B?{...$e,size:Z}:$e),s),ne==="hide"&&_(s.home.filter(($e,Se)=>Se!==B),s).then($e=>{$e&&d({item:ve,at:B})})},W=()=>{if(!c)return;const B=s.home.filter(ne=>ne.key!==c.item.key);B.splice(Math.min(c.at,B.length),0,c.item),d(null),_(B,s)},L=()=>{g(!0),_(l,s).then(B=>{g(!1),B&&(i(!1),f("Widgets saved."))})},Q=B=>{j(B),T.refreshWidget(B).then(r,()=>{}).finally(()=>j(null))},F=B=>{var ve;const ne={key:HP(),widget:B.id,size:B.sizes[0],settings:{}},Z=l.some($e=>$e.widget===B.id);o([...l,ne]),f(`${B.title} added.`),Z&&(((ve=B.settings)==null?void 0:ve.length)??0)>0&&b(ne.key)},ae=(B,ne)=>a?(o(l.map(Z=>{if(Z.key!==B)return Z;const{label:ve,...$e}=Z;return{...$e,settings:ne}})),$(new Set([...C,B])),b(null),Promise.resolve(!0)):_(s.home.map(Z=>Z.key===B?{...Z,settings:ne}:Z),s).then(Z=>(Z&&(b(null),f("Settings saved.")),Z)),V=B=>{b(null);const ne=O.findIndex(Z=>Z.key===B);ne>=0&&P(ne)("hide")},J={dragging:v,over:N,start:B=>w(B),enter:B=>{N!==B&&k(B)},end:()=>{w(null),k(null)},drop:B=>{const ne=l.findIndex($e=>$e.key===v),Z=l.findIndex($e=>$e.key===B),ve=ne>=0&&Z>=0?z(l,ne,Z):null;ve&&o(ve),w(null),k(null)}},H=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:W,children:"Undo"})]},"undo"):null,X=[];O.forEach((B,ne)=>{const Z=M.get(B.widget);if(!Z)return;c&&!a&&c.at===ne&&X.push(H);const ve=a&&(C.has(B.key)||!s.home.some($e=>$e.key===B.key));X.push(t.jsx(HQ,{info:Z,placement:B,view:ve?void 0:s.views[B.key],index:ne,count:O.length,editing:a,navigate:n,act:P(ne),onRetry:()=>Q(B.key),retrying:y===B.key,drag:J},B.key))}),c&&!a&&c.at>=O.length&&X.push(H);const G=s.available.filter(B=>!B.builtIn),ce=G.length-2,xe=S?O.find(B=>B.key===S):void 0,De=xe?M.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:x,children:"Cancel"}),t.jsx(E,{size:"sm",variant:"accent",onClick:L,disabled:x,children:x?"Saving…":"Done"})]}):O.length>0?t.jsx("div",{className:"ui-toolbar","data-align":"end",children:t.jsx(E,{size:"sm",variant:"ghost",onClick:U,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:"," ",(G.length>0?G:s.available).slice(0,2).map(B=>B.title).join(", "),ce>0?` and ${ce} more`:"","."]})]}),t.jsx(E,{size:"sm",variant:"accent",onClick:U,children:"Add widgets"})]}):X.length>0?t.jsx("div",{className:"wg-grid","data-editing":a?"true":void 0,children:X}):null,a?t.jsxs("div",{className:"wg-gallery",role:"region","aria-label":"Add widgets",children:[t.jsxs("div",{className:"wg-gallery-head",children:[t.jsx("p",{className:"wg-gallery-title",children:"Add widgets"}),t.jsx("a",{className:"wg-gallery-aside",href:ze("lock"),onClick:B=>{B.preventDefault(),n(ze("lock"))},children:"The lock screen has its own pick"})]}),t.jsx("ul",{className:"wg-gallery-list",children:s.available.map(B=>{var me;const ne=l.filter(Ee=>Ee.widget===B.id).length,Z=(((me=B.settings)==null?void 0:me.length)??0)>0,ve=B.builtIn?"Built in":`${B.plugin} plugin`,$e=B.sizes.length>1?"small or medium":`${B.sizes[0]} only`,Se=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:B.title}),t.jsxs("span",{className:"wg-add-sub",children:[ve," · ",$e,B.sensitive?" · hidden until you show it":"",Se]})]}),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"} ${B.title}`,onClick:()=>F(B),children:[t.jsx(ie,{name:"plus",size:12})," ",ne>0?"Add another":"Add"]})]},B.id)})}),t.jsxs("a",{className:"wg-gallery-more",href:tv("widgets"),onClick:B=>{B.preventDefault(),n(tv("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&&De?t.jsx(UP,{info:De,placement:xe,surface:"home",onClose:()=>b(null),onSave:B=>ae(xe.key,B),onRemove:()=>V(xe.key)}):null]})}function db(e,n){return!e||e==="image"&&!n?"earth":e}const GQ="(max-width: 720px)",qQ="(orientation: portrait)",YQ=3e4,QQ=5e3,JQ={1:"a minute",5:"5 minutes",15:"15 minutes",60:"an hour"};function ug(e,n){return{time:$t(e,n),day:Nr(e,n,{weekday:!0})}}function Lm(e,n){return e?Id({timeFormat:e.time,...e.date==="off"?{}:{dateFormat:e.date}},n):n()}function XQ(e,n,s=new Date,r){return Lm(r,()=>ZQ(e,n,s))}function ZQ(e,n,s){if(!e.lockedAt)return"Locked";const r=new Date(e.lockedAt),i=ug(r,n).day===ug(s,n).day?ug(r,n).time:im(r,n);return e.reason==="idle"?`Locked after ${e.delayMinutes?JQ[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 eJ(e){const n=()=>e?Math.max(0,Math.ceil((Date.parse(e)-Date.now())/1e3)):0,[s,r]=u.useState(n);return u.useEffect(()=>{if(r(n()),!e)return;const a=window.setInterval(()=>r(n()),500);return()=>window.clearInterval(a)},[e]),s}const tJ=e=>`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`;function cC({size:e=16}){return t.jsx(ie,{name:"lock",size:e})}function GP({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 nJ(){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 dC({text:e}){const[n,s]=u.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 sJ({onClose:e}){return t.jsx(zt,{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(dC,{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(dC,{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 rJ({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 aJ(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 iJ(e){return e.filter(n=>!(n.view.body.kind==="text"&&!n.view.body.sub))}function uC(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 lJ(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 ${Lm(s,()=>{const i=$t(a,n),l=uC(r,n)-uC(a,n);return l<=0?i:l===1?`yesterday ${i}`:l<7?`${new Intl.DateTimeFormat("en-US",{timeZone:n,weekday:"short"}).format(a)} ${i}`:`${Nr(a,n,{compact:!0})} ${i}`})}`}function oJ({widgets:e,phone:n,timezone:s,clockView:r,now:a}){const i=iJ(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=aJ(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:d})=>{const h=lJ(c.view,s,r,a);return t.jsxs("div",{className:"wg-frame","data-variant":"compact","data-size":d,"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(Dm,{body:c.view.body,size:d})}),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 cJ({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 hC(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 dJ(e,n,s){try{const r=hC(e,n)-hC(e,s);if(r===0)return"Same time";const a=d=>new Intl.DateTimeFormat("en-CA",{timeZone:d,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 uJ(e,n,s){const r=s??{date:null,zone:null};return Lm(s,()=>({time:$t(e,n),day:r.date==="off"?null:Nr(e,n,{weekday:!0}),zone:r.zone?{label:r.zone.label,time:$t(e,r.zone.timezone),offset:dJ(e,r.zone.timezone,n)}:null}))}function hJ({background:e,image:n,imagePortrait:s,phone:r,portrait:a}){const i=LP(e),l=DP(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:sQ(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:uQ(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:d}=dQ(o,a);return t.jsxs("div",{className:d==="contain"?"ui-fieldbg lk-ground":"lk-ground","data-fit":d,"aria-hidden":"true",children:[t.jsx("img",{className:"lk-photo","data-fit":d,"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 qP({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=uJ(n,o,e==null?void 0:e.clockView),d=db(e==null?void 0:e.background,e==null?void 0:e.image),h=(e==null?void 0:e.focus)??null,f=h?Lm(e==null?void 0:e.clockView,()=>s?gJ(wd(h,o,n)):`${Oi[h.mode]} ${wd(h,o,n)}`):"";return t.jsxs(t.Fragment,{children:[t.jsx(hJ,{background:d,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(hd,{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(cJ,{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(rJ,{approvals:e.approvals,needs:e.needs??0,after:i??null,...l?{onPick:l}:{}}),a||!e?null:t.jsx(oJ,{widgets:e.widgets,phone:s,timezone:o,clockView:e.clockView,now:n})]})]})}function fJ({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(nJ,{})}),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(GP,{size:18})})]})}function mJ({initial:e,onUnlocked:n}){const s=Gn(GQ),r=Gn(qQ)||s,a=FP(),[i,l]=u.useState(null),o=i??e,[c,d]=u.useState(""),[h,f]=u.useState(null),[m,p]=u.useState((e==null?void 0:e.waitUntil)??null),[x,g]=u.useState(!1),[y,j]=u.useState(!1),[v,w]=u.useState(!1),[N,k]=u.useState(!1),[S,b]=u.useState(!1),[C,$]=u.useState(null),A=u.useRef(null),I=eJ(m),M=I>0,O=u.useRef(n),R=u.useRef(C);R.current=C,O.current=X=>{R.current&&(window.location.hash=ao),n(X)};const _=X=>{var G;$(X),s&&X?k(!0):(G=A.current)==null||G.focus()},z=u.useRef(0),U=u.useRef(0),P=u.useRef(0),W=u.useCallback(()=>{const X=++z.current;P.current=Date.now(),T.lockScreen().then(G=>{X<U.current||(U.current=X,j(!1),l(G),p(G.waitUntil),G.locked||O.current(G))}).catch(G=>{G instanceof fe&&G.status===401?window.location.reload():Gh(G)&&j(!0)})},[]);u.useEffect(()=>{W();const X=window.setInterval(W,YQ),G=()=>{document.visibilityState==="visible"&&W()},ce=()=>{Date.now()-P.current>=QQ&&W()};return document.addEventListener("visibilitychange",G),document.addEventListener("resume",ce),window.addEventListener("focus",ce),window.addEventListener("pageshow",ce),window.addEventListener("online",W),()=>{window.clearInterval(X),document.removeEventListener("visibilitychange",G),document.removeEventListener("resume",ce),window.removeEventListener("focus",ce),window.removeEventListener("pageshow",ce),window.removeEventListener("online",W)}},[W]),KP((i==null?void 0:i.widgets.some(X=>X.id===BP&&X.view.body.kind!=="clocks"))??!1,W),u.useEffect(()=>{var X;!s&&!v&&!M&&((X=A.current)==null||X.focus())},[s,v,M,x]),u.useEffect(()=>{!M&&m&&f(null)},[M,m]);const L=X=>{X==null||X.preventDefault(),!(x||M||c.length<4)&&(g(!0),T.unlock(c).then(G=>{var xe;if(d(""),G.locked){g(!1);return}if((xe=window.matchMedia)==null?void 0:xe.call(window,"(prefers-reduced-motion: reduce)").matches){O.current(G);return}b(!0),window.setTimeout(()=>O.current(G),240)}).catch(G=>{if(g(!1),d(""),!(G instanceof fe))return f("Something went wrong. Try again.");const ce=G.detail??{};if(G.status===403||G.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 Gh(G)?f("buddi isn’t answering. Try again in a moment."):f(G.message)}))},Q=(i==null?void 0:i.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,F=db(o==null?void 0:o.background,o==null?void 0:o.image),ae=(i==null?void 0:i.owner)??null,V=y?{tone:"critical",text:"buddi isn’t answering. The lock stays until it does."}:M?{tone:"critical",text:`Too many tries. Try again in ${tJ(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?XQ(o,Q,a,i==null?void 0:i.clockView):"Locked"},J=X=>X.replace(/\D/g,"").slice(0,8),H=t.jsxs("div",{className:"lk-who",children:[t.jsx("span",{className:"lk-face","aria-hidden":"true",children:(ae??"You").slice(0,1).toUpperCase()}),ae?t.jsx("span",{className:"lk-owner",children:ae}):null]});return t.jsxs("div",{className:"lk","data-bg":F,"data-phone":s?"true":void 0,"data-view":N?"pad":"glance","data-opening":S?"true":void 0,role:"dialog","aria-modal":"true","aria-label":"buddi is locked","data-testid":"lock-screen",children:[t.jsx(qP,{data:i??(o?{...xJ(o)}:null),now:a,phone:s,portrait:r,pad:N,after:C,onPick:_}),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:()=>k(!0),children:[t.jsx(cC,{size:14}),t.jsx("span",{children:"Enter PIN"})]}),t.jsx("p",{className:"lk-note","data-tone":V.tone,role:"status","aria-live":"polite",children:V.text})]}):s?t.jsxs(t.Fragment,{children:[H,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((X,G)=>t.jsx("span",{className:"lk-dot"},G))}),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":V.tone,role:"status","aria-live":"polite",children:V.text}),t.jsx(fJ,{value:c,disabled:M||x,onDigit:X=>{f(null),d(J(c+X))},onBack:()=>d(c.slice(0,-1)),onSubmit:()=>L()}),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:()=>{k(!1),d(""),f(null)},children:"Cancel"})]})]}):t.jsxs(t.Fragment,{children:[H,t.jsxs("form",{className:"lk-pin","data-state":h&&!M?"wrong":M?"wait":void 0,onSubmit:L,children:[t.jsx(cC,{size:15}),t.jsx("input",{ref:A,type:"password",inputMode:"numeric",autoComplete:"off",maxLength:8,"aria-label":"PIN","aria-describedby":"lk-note",placeholder:M?"Wait a moment":"Enter your PIN",disabled:M,value:c,onChange:X=>{f(null),d(J(X.target.value))}}),t.jsx("button",{type:"submit",className:"lk-go","aria-label":"Unlock",disabled:x||M||c.length<4,children:t.jsx(GP,{})})]}),t.jsx("p",{className:"lk-note",id:"lk-note","data-tone":V.tone,role:"status","aria-live":"polite",children:V.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:pJ(i.version)}):null,v?t.jsx(sJ,{onClose:()=>w(!1)}):null]})}function pJ(e){return`buddi ${e.current}${e.updateAvailable?" · update ready":""}`}function gJ(e){return e.slice(0,1).toUpperCase()+e.slice(1)}function xJ(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 vJ=3e4,jJ=5e3,wJ="buddi-lock",Xv="buddi-locked",yJ=ze("lock");function YP(){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 bJ(e=YP()){return e?"⌃⌘L":"Ctrl+Alt+L"}function kJ(e,n=YP()){return!(e.code==="KeyL"||e.key.toLowerCase()==="l")||!e.ctrlKey||e.shiftKey?!1:n?e.metaKey&&!e.altKey:e.altKey&&!e.metaKey}const QP=u.createContext({pin:!1,state:null,lockNow:()=>{},update:()=>{},shortcut:"⌃⌘L"});function Fm(){return u.useContext(QP)}function Fu(e){try{e?localStorage.setItem(Xv,"1"):localStorage.removeItem(Xv)}catch{}}function NJ(){try{return localStorage.getItem(Xv)==="1"}catch{return!1}}function SJ(){try{return typeof BroadcastChannel>"u"?null:new BroadcastChannel(wJ)}catch{return null}}function CJ({children:e}){const[n,s]=u.useState("checking"),[r,a]=u.useState(null),i=u.useRef(null),l=u.useRef(Date.now()),o=u.useRef(0),c=u.useRef(0),d=u.useRef(0),h=u.useCallback((g,y)=>{g&&a(g),s(y?"locked":"open"),Fu(y),y||(l.current=Date.now())},[]),f=u.useCallback(()=>{T.lockState().then(g=>h(g,g.locked)).catch(g=>{if(g instanceof fe&&g.status===401)return s("open");h(null,NJ())})},[h]);u.useEffect(()=>{f()},[f]);const m=u.useCallback((g="owner")=>{var y;if(!(r!=null&&r.pin)){window.location.hash=yJ;return}s("locked"),Fu(!0),g==="owner"&&((y=i.current)==null||y.postMessage({type:"locked"})),(g==="idle"?T.lockNow("idle",Date.now()-l.current):T.lockNow(g)).then(j=>{var v;g==="idle"&&j.locked&&((v=i.current)==null||v.postMessage({type:"locked"})),h(j,j.locked)}).catch(()=>f())},[r==null?void 0:r.pin,h,f]);u.useEffect(()=>{const g=()=>{s("locked"),Fu(!0),f()};return window.addEventListener(zx,g),()=>window.removeEventListener(zx,g)},[f]),u.useEffect(()=>{const g=SJ();if(i.current=g,!!g)return g.onmessage=y=>{const j=y.data;(j==null?void 0:j.type)==="locked"?(s("locked"),Fu(!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]),u.useEffect(()=>{const g=y=>{kJ(y)&&(y.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;u.useEffect(()=>{if(n!=="open"||!(r!=null&&r.pin))return;c.current=l.current;const g=()=>{var S;const k=Date.now();l.current=k,k-d.current>1e4&&(d.current=k,(S=i.current)==null||S.postMessage({type:"activity",at:k}))},y=()=>{const k=Date.now();l.current<=c.current||k-o.current<vJ||(o.current=k,c.current=l.current,T.lockActivity().catch(()=>{}))},j=()=>{if(p!==null&&Date.now()-l.current>=p*6e4){m("idle");return}y()},v=["pointerdown","pointermove","keydown","wheel","touchstart"];for(const k of v)window.addEventListener(k,g,{passive:!0,capture:!0});const w=window.setInterval(j,jJ),N=()=>{document.visibilityState==="visible"&&j()};return document.addEventListener("visibilitychange",N),()=>{for(const k of v)window.removeEventListener(k,g,{capture:!0});window.clearInterval(w),document.removeEventListener("visibilitychange",N)}},[n,r==null?void 0:r.pin,p,m]);const x=u.useMemo(()=>({pin:(r==null?void 0:r.pin)===!0,state:r,lockNow:()=>m("owner"),update:g=>h(g,g.locked),shortcut:bJ()}),[r,m,h]);return n==="checking"?null:n==="locked"?t.jsx(mJ,{initial:r,onUnlocked:g=>{var y;(y=i.current)==null||y.postMessage({type:"unlocked"}),h(g,!1)}}):t.jsx(QP.Provider,{value:x,children:e})}const JP="a connection needs you";function EJ({attention:e,place:n,onNavigate:s,theme:r,onTheme:a,plugins:i=[],updateAvailable:l=!1,settingsDot:o,version:c,stale:d=!1,reload:h,timezone:f,status:m}){return t.jsxs("nav",{className:"rail","aria-label":"Places",children:[t.jsx("a",{className:"rail-mark",href:In,onClick:p=>{p.preventDefault(),s(In)},"aria-label":"buddi home",children:t.jsx(hd,{})}),M6.filter(p=>p.route!==un).map(p=>t.jsx(hg,{label:p.label,href:p.route,active:n===p.route,badge:p.route===In?e:0,onClick:()=>s(p.route),children:fC[p.route]},p.route)),i.map(p=>{const x=Hr(p.plugin,p.id);return t.jsx(hg,{label:p.title,href:x,active:n===x,badge:0,onClick:()=>s(x),children:t.jsx(ie,{name:MP(p.icon)})},x)}),t.jsx("div",{className:"rail-spacer"}),t.jsx(hg,{label:"Settings",href:un,active:n===un,badge:0,dot:l?"a newer buddi is ready":o,onClick:()=>s(un),children:fC[un]}),m,t.jsx($J,{theme:r,onTheme:a,onNavigate:s,version:c,stale:d,reload:h,timezone:f})]})}const AJ=[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}];function $J({theme:e,onTheme:n,onNavigate:s,version:r,stale:a,reload:i=()=>window.location.reload(),timezone:l}){var N,k,S;const o=pe(()=>T.owner(),[]),c=Fm(),d=pe(()=>T.focus(),[],6e4),h=((N=d.data)==null?void 0:N.focus)??null,f=(b,C)=>{T.setFocus(b,C).finally(()=>d.reload())},m=((S=(k=o.data)==null?void 0:k.preferredName)==null?void 0:S.trim())||null,p=(m??"You").slice(0,1).toUpperCase(),[x]=u.useState(()=>Q6()||cb()),[g]=u.useState(RJ),y=Om(),j=m?`You: ${m}`:"You",v=h?`${Oi[h.mode]} ${wd(h,l)}`:null,w=[j,v,a?"reload to update":null].filter(Boolean).join(", ");return t.jsx("div",{className:"rail-owner",children:t.jsxs(Dd,{modal:!1,children:[t.jsx(Ld,{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($o,{children:t.jsxs(Fd,{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(da,{className:"ui-menu-sep"}),t.jsx(IJ,{focus:h,timezone:l,onSwitch:f}),t.jsx(da,{className:"ui-menu-sep"}),t.jsx(Yi,{className:"ui-menu-label",children:"Theme"}),t.jsx("div",{className:"rail-owner-theme",children:t.jsx(Jt,{label:"Theme",options:AJ,value:e,onChange:n})}),t.jsx(da,{className:"ui-menu-sep"}),c.pin?t.jsxs(Vs,{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(Vs,{className:"ui-menu-item",onSelect:()=>s(ze("lock")),children:"Set up a lock screen…"}),t.jsx(Vs,{className:"ui-menu-item",onSelect:()=>s(ze("appearance")),children:"Change appearance"}),y?t.jsx(Vs,{className:"ui-menu-item",onSelect:()=>{lb(y)},children:"Install the app"}):null,x||a?t.jsxs(Vs,{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(da,{className:"ui-menu-sep"}),t.jsxs(Vs,{className:"ui-menu-item rail-owner-version","data-update":r.updateAvailable?"true":void 0,onSelect:()=>s(ze("system")),children:[t.jsxs("span",{className:"mono",children:["buddi ",r.current]}),r.updateAvailable&&r.latest?t.jsxs("span",{className:"rail-owner-update",children:["A newer buddi is ready: ",r.latest]}):null]})]}):null]})})]})})}const Oi={normal:"Off","urgent-only":"Urgent only","do-not-disturb":"Do not disturb"},TJ=[{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 wd(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=$t(r,a);return i(r)===i(s)?`until ${l}`:`until ${new Intl.DateTimeFormat("en-US",{timeZone:a,weekday:"short"}).format(r)} ${l}`}function IJ({focus:e,timezone:n,onSwitch:s}){return t.jsxs(BU,{children:[t.jsxs(WU,{className:"ui-menu-item rail-owner-focus",children:[t.jsx("span",{children:"Focus"}),t.jsx("span",{className:"rail-owner-kbd",children:e?Oi[e.mode]:"Off"})]}),t.jsx($o,{children:t.jsxs(HU,{className:"ui-menu rail-owner-menu",sideOffset:6,children:[t.jsx("p",{className:"ui-menu-empty",role:"status",children:e?`${Oi[e.mode]} ${wd(e,n)}${e.by==="schedule"?", from a schedule":""}.`:"No focus is on."}),["do-not-disturb","urgent-only"].map(r=>t.jsxs(RT,{children:[t.jsx(da,{className:"ui-menu-sep"}),t.jsx(Yi,{className:"ui-menu-label",children:Oi[r]}),TJ.map(a=>t.jsx(Vs,{className:"ui-menu-item","aria-label":`${Oi[r]} ${a.label.toLowerCase()}`,onSelect:()=>s(r,a.value),children:a.label},a.value))]},r)),e?t.jsxs(t.Fragment,{children:[t.jsx(da,{className:"ui-menu-sep"}),t.jsx(Vs,{className:"ui-menu-item",onSelect:()=>s("normal"),children:"Turn off"})]}):null]})})]})}function RJ(){const e=window.navigator.userAgent;return/iPhone|iPad|Android|Mobile/.test(e)?null:/Mac/.test(e)?"⌘R":"Ctrl+R"}function hg({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 fC={[ya]:t.jsx(ie,{name:"files"}),[In]:t.jsx(ie,{name:"home"}),[ma]:t.jsx(ie,{name:"chat"}),[yt]:t.jsx(ie,{name:"agents"}),[Yt]:t.jsx(ie,{name:"activity"}),[un]:t.jsx(ie,{name:"settings"})},yd=e=>`${e.plugin}:${e.id}`,PJ=new Set;let ub=PJ,mC=!1;const Zv=new Set;function ej(e){ub=e;for(const n of Zv)n()}function MJ(e){return Zv.add(e),()=>Zv.delete(e)}const pC=()=>ub;function OJ(){mC||(mC=!0,Promise.resolve().then(()=>T.rail()).then(e=>ej(new Set(Array.isArray(e==null?void 0:e.hidden)?e.hidden.filter(n=>typeof n=="string"):[]))).catch(()=>{}))}async function DJ(e,n){const s=ub,r=new Set(s);n?r.add(yd(e)):r.delete(yd(e)),ej(r);try{await T.setRailHidden(e.plugin,e.id,n)}catch(a){throw ej(s),a}}function XP(){return u.useEffect(OJ,[]),u.useSyncExternalStore(MJ,pC,pC)}function LJ(e,n){return e.filter(s=>!n.has(yd(s)))}function FJ(e){return e instanceof HTMLElement?e.isContentEditable?!0:e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.tagName==="SELECT":!1}function _J(e,n=!0,s){u.useEffect(()=>{if(!n)return;const r=a=>{if(a.key!=="/"||a.defaultPrevented||a.ctrlKey||a.metaKey||a.altKey||FJ(a.target))return;a.preventDefault();const i=document.getElementById(Fv);if(i instanceof HTMLTextAreaElement){!i.disabled&&!i.hidden&&i.focus();return}s?s():e(In)};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,n,s])}const ZP="buddi.theme";function zJ(e=eM()){try{const n=e==null?void 0:e.getItem(ZP);return n==="light"||n==="dark"||n==="system"?n:"system"}catch{return"system"}}function UJ(e,n=eM()){try{n==null||n.setItem(ZP,e)}catch{}}function BJ(e,n=document.documentElement){n&&(e==="system"?n.removeAttribute("data-theme"):n.setAttribute("data-theme",e))}function eM(){try{return window.localStorage}catch{return}}const tM="buddi.ground",nM="buddi.pageWidth";function WJ(e=aM()){const n=a=>{try{return(e==null?void 0:e.getItem(a))??null}catch{return null}},s=n(tM),r=n(nM);return{theme:zJ(e),ground:s==="sand"?"sand":"blue",width:r==="narrow"||r==="full"?r:"wide"}}function sM(e,n=document.documentElement){n&&(BJ(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 HJ(e,n=aM()){UJ(e.theme,n);try{n==null||n.setItem(tM,e.ground),n==null||n.setItem(nM,e.width)}catch{}}let Ql=null;const tj=new Set;function nj(){return Ql||(Ql=WJ()),Ql}function KJ(e){return tj.add(e),()=>tj.delete(e)}function VJ(e){Ql={...nj(),...e},sM(Ql),HJ(Ql);for(const n of tj)n()}function rM(){return[u.useSyncExternalStore(KJ,nj,nj),VJ]}function aM(){try{return window.localStorage}catch{return}}const gC=7,GJ=1e4;function qJ({timezone:e,embedded:n,agents:s=[],navigate:r}){const{data:a,error:i,reload:l}=pe(()=>T.sentinels(),[],3e4),[o,c]=u.useState(null),[d,h]=u.useState(null),[f,m]=u.useState(null),[p,x]=u.useState(null),[g,y]=u.useState(!1),[j,v]=u.useState(null),w=a==null?void 0:a.alerts,N=(w==null?void 0:w.open)??[],k=U=>{r?r(U):window.location.hash=U},S=U=>{var P;return U?((P=s.find(W=>W.id===U))==null?void 0:P.name)??null:null},b=async U=>{c(null);try{await U()}catch(P){c(P instanceof fe||P instanceof Error?P.message:String(P))}finally{l()}},C=U=>h({...U,id:Date.now()}),$=(U,P,W)=>b(async()=>{const{keys:L}=await T.snoozeAlerts(U,!0,W);C({title:P,undo:()=>T.snoozeAlerts(L,!1)})}),A=U=>b(async()=>{const{id:P}=await T.muteAlert(U.keys[0],U.stop.scope);C({title:"You won’t hear about this again",body:"Turn it back on in Settings → Watchers.",undo:()=>T.unmuteAlert(P)})}),I=U=>b(async()=>{const{agentId:P,conversationId:W}=await T.askAboutAlerts(U.keys);k(lt(P,W))}),M=U=>b(async()=>{const[P]=(await T.actOnAlerts([{key:U.key,action:U.index}])).results;if(P!=null&&P.error)throw new Error(P.error);P!=null&&P.approvalId?C({title:"Waiting for your approval",body:"Decide it in Needs you on Home."}):C({title:`${U.label}: done`})}),O=(U,P)=>{P.kind==="open"?k(P.place==="files"?ya:P.plugin&&P.page?Hr(P.plugin,P.page,P.item):ya):P.kind==="ask"?I(U):P.kind==="dismiss"?$(U.keys,"Set aside until it changes"):P.kind==="fill"?m(P):P.confirm?x(P):M(P)},R=()=>{const U=N.flatMap(P=>P.keys);$(U,`Cleared ${N.length} for a week`,gC)},_=w==null?void 0:w.recap,z=YJ((_==null?void 0:_.nextAt)??null,e);return t.jsxs(js,{embedded:n,title:"Alerts",lede:"What needs a decision from you.",children:[t.jsx(re,{message:i??o}),t.jsxs(rt,{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 ",z,"."]})]})]}):t.jsx("ul",{className:"al-list",children:N.map(U=>t.jsx(xC,{group:U,agentName:S(U.agentId),onAct:O,onStop:A,onNotNow:P=>void $(P.keys,"Snoozed for a week",gC)},U.id))}):null,_&&_.count>0?t.jsxs("p",{className:"al-recap","data-testid":"recap-line",children:[t.jsxs("span",{children:[_.count," ",_.count===1?"note":"notes"," saved for ",z]}),t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("button",{type:"button",className:"wb-link",onClick:()=>y(!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:()=>v(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:()=>v(j==="resolved"?null:"resolved"),children:[w.resolved.length," resolved this week"]}):null]}):null,j==="snoozed"&&w?t.jsx(rt,{flush:!0,title:"Snoozed",children:t.jsx("ul",{className:"al-list",children:w.snoozed.map(U=>t.jsxs("li",{className:"al-row",children:[t.jsxs("div",{className:"al-main",children:[t.jsx("p",{className:"al-title",children:U.title}),t.jsx("p",{className:"al-sub",children:U.snoozedUntil?`Back ${Ge(U.snoozedUntil)}`:"Until it changes"})]}),t.jsx("div",{className:"al-actions",children:t.jsx(E,{size:"sm",onClick:()=>void b(async()=>{await T.snoozeAlerts(U.keys,!1)}),children:"Bring back"})})]},U.id))})}):null,j==="resolved"&&w?t.jsx(rt,{flush:!0,title:"Resolved this week",children:t.jsx("ul",{className:"al-list",children:w.resolved.map(U=>t.jsx("li",{className:"al-row",children:t.jsxs("div",{className:"al-main",children:[t.jsx("p",{className:"al-title",children:U.title}),t.jsx("p",{className:"al-sub",children:U.resolvedAt?`Resolved ${Ge(U.resolvedAt)}`:null})]})},U.id))})}):null,g&&_?t.jsxs(Je,{title:QJ(z),onClose:()=>y(!1),children:[t.jsxs("p",{className:"al-form-note",children:["What the watchers noted. buddi reads them out in ",z,"; nothing here needs you now, but you can act on one early."]}),t.jsx("ul",{className:"al-list al-list-sheet",children:_.groups.map(U=>t.jsx(xC,{group:U,agentName:S(U.agentId),recap:!0,onAct:(P,W)=>{W.kind!=="fill"&&y(!1),O(P,W)},onStop:P=>{A(P)}},U.id))})]}):null,f?t.jsx(JJ,{action:f,onClose:()=>m(null),onSaved:U=>{m(null),y(!1),C({title:`Saved ${U}`}),l()}}):null,p?t.jsx(zt,{title:p.label,onClose:()=>x(null),foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:()=>x(null),children:"Cancel"}),t.jsx(E,{variant:p.tone==="danger"?"danger":"accent",onClick:()=>{const U=p;x(null),M(U)},children:p.label})]}),children:t.jsx("p",{children:p.confirm})}):null,d?t.jsx(pd,{title:d.title,...d.body?{body:d.body}:{},duration:GJ,...d.undo?{onUndo:()=>{const U=d.undo;b(async()=>{await U()})}}:{},onGone:()=>h(null)},d.id):null]})}function YJ(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 QJ(e){return e.charAt(0).toUpperCase()+e.slice(1)}function _u(e,n){return e.kind==="ask"?e.label??(n?`Ask ${n}`:"Ask about it"):e.label}function xC({group:e,agentName:n,recap:s,onAct:r,onNotNow:a,onStop:i}){const[l,o]=u.useState(!1),[c,d,...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 ",Ge(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((x,g)=>t.jsx(E,{size:"sm",variant:x.kind==="run"&&x.tone==="danger"?"danger-ghost":"ghost",onClick:()=>r(e,x),children:_u(x,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:_u(c,n)}):null,d?t.jsx(E,{size:"sm",variant:d.kind==="run"&&d.tone==="danger"?"danger-ghost":void 0,onClick:()=>r(e,d),children:_u(d,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(Qn,{label:`More for ${e.title}`,sheet:{title:e.title},items:[...h.map(p=>({label:_u(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 JJ({action:e,onClose:n,onSaved:s}){const r=e.fields.length===1,[a,i]=u.useState(()=>Object.fromEntries(e.fields.map(p=>[p.key,r&&p.value!==null?String(p.value):""]))),[l,o]=u.useState({}),[c,d]=u.useState(!1),[h,f]=u.useState(null),m=async()=>{const p=e.fields.filter(x=>(a[x.key]??"").trim()!=="").map(x=>({key:x.key,action:x.index,value:(a[x.key]??"").trim()}));if(p.length===0){n();return}d(!0),f(null);try{const{results:x}=await T.actOnAlerts(p),g=Object.fromEntries(x.filter(y=>y.error).map(y=>[y.key,y.error]));o(g),Object.keys(g).length===0&&s(p.length)}catch(x){f(x instanceof Error?x.message:String(x))}finally{d(!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(re,{message:h}),t.jsx("p",{className:"al-form-note",children:r?"Check it and save.":"Type what each is today. Leave the ones you don’t know; they stay as they are."}),t.jsx("div",{className:"al-form-rows",children:e.fields.map(p=>t.jsxs("label",{className:"al-form-row",children:[t.jsxs("span",{className:"al-form-label",children:[t.jsx("span",{children:p.label}),p.hint?t.jsx("span",{className:"al-form-hint",children:p.hint}):null]}),t.jsx("input",{type:p.type==="date"?"date":"text",inputMode:p.type==="number"?"decimal":void 0,value:a[p.key]??"",placeholder:"—","aria-label":p.label,onChange:x=>i(g=>({...g,[p.key]:x.target.value}))}),l[p.key]?t.jsx("span",{className:"al-form-error",children:l[p.key]}):null]},p.key))})]})})}function XJ({mutes:e,onChanged:n}){const[s,r]=u.useState(null);return e.length===0?null:t.jsxs(rt,{flush:!0,title:"Silenced",tool:String(e.length),children:[t.jsx(re,{message:s}),t.jsx("ul",{className:"al-list",children:e.map(a=>t.jsxs("li",{className:"al-row",children:[t.jsxs("div",{className:"al-main",children:[t.jsx("p",{className:"al-title al-silenced-label",children:a.label}),t.jsxs("p",{className:"al-sub",children:["You said “Stop telling me this” ",Ge(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 vC=5e3,jC=50;function ZJ({timezone:e,embedded:n}){var j;const[s,r]=u.useState(""),[a,i]=u.useState(""),[l,o]=u.useState(null),c=pe(()=>T.eventKinds(),[]),{data:d,error:h}=pe(()=>T.events({kind:s||void 0,q:a||void 0,limit:jC}),[s,a],vC),[f,m]=u.useState({events:[],cursor:null,busy:!1,error:null});u.useEffect(()=>{m({events:[],cursor:null,busy:!1,error:null})},[s,a]);const p=f.events.length>0?f.cursor:(d==null?void 0:d.nextCursor)??null,x=async()=>{if(p){m(v=>({...v,busy:!0,error:null}));try{const v=await T.events({kind:s||void 0,q:a||void 0,before:p,limit:jC});m(w=>({events:[...w.events,...v.events],cursor:v.nextCursor,busy:!1,error:null}))}catch(v){m(w=>({...w,busy:!1,error:v instanceof Error?v.message:String(v)}))}}},g=new Set(((d==null?void 0:d.events)??[]).map(v=>v.id)),y=[...(d==null?void 0:d.events)??[],...f.events.filter(v=>!g.has(v.id))];return t.jsxs(js,{embedded:n,title:"Events",lede:"The append-only log. Everything the installation did, including what you do here.",children:[t.jsxs(se,{children:[t.jsxs("select",{"aria-label":"Event kind",value:s,onChange:v=>r(v.target.value),children:[t.jsx("option",{value:"",children:"every kind"}),(((j=c.data)==null?void 0:j.kinds)??[]).map(v=>t.jsxs("option",{value:v.kind,children:[v.kind," (",v.count,")"]},v.kind))]}),t.jsx("input",{"aria-label":"Payload contains",placeholder:"payload contains…",value:a,onChange:v=>i(v.target.value),size:28}),s||a?t.jsx(E,{onClick:()=>{r(""),i("")},children:"Clear"}):null,t.jsxs("span",{className:"muted",children:["refreshes every ",vC/1e3,"s"]})]}),t.jsx(re,{message:h}),t.jsx(rt,{flush:!0,children:!d||y.length===0?t.jsx(be,{children:"No events match."}):t.jsxs(Yr,{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:y.map(v=>t.jsxs("tr",{"data-clickable":"true",onClick:()=>o(v),children:[t.jsx("td",{className:"mono muted",children:v.id}),t.jsxs("td",{className:"nowrap",children:[ft(v.createdAt,e),t.jsx("div",{className:"sub",children:Ge(v.createdAt)})]}),t.jsx("td",{className:"mono nowrap",children:v.kind}),t.jsx("td",{className:"mono muted",children:mr(rs(v.payload).replace(/\s+/g," "),120)})]},v.id))})]})}),p||f.error?t.jsxs(se,{children:[t.jsxs("span",{className:"muted",children:[y.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 x(),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," · ",ft(l.createdAt,e),l.conversationId?t.jsxs(t.Fragment,{children:[" · ",t.jsx("a",{href:`#/conversations/${l.conversationId}`,children:"conversation"})]}):null]}),t.jsx(_t,{children:rs(l.payload)})]}):null]})}const wC=["pending","leased","suspended","failed","succeeded","cancelled"],sc=50,eX=1e4,tX=(e,n,s=`${n}s`)=>e===1?n:s;function nX({timezone:e,embedded:n,initialState:s}){var L,Q;const[r,a]=u.useState(s??""),[i,l]=u.useState(null),[o,c]=u.useState(null),[d,h]=u.useState(null),[f,m]=u.useState(!1),p=r==="failed",{data:x,error:g,reload:y}=pe(()=>T.jobs({...r?{state:r}:{},...r?{}:{dismissed:"0"},limit:String(sc)}),[r],1e4),j=pe(()=>T.jobFailures(),[],1e4),[v,w]=u.useState({jobs:[],done:!1,busy:!1});u.useEffect(()=>{w({jobs:[],done:!1,busy:!1})},[r]);const N=async()=>{w(F=>({...F,busy:!0}));try{const F=await T.jobs({...r?{state:r}:{dismissed:"0"},limit:String(sc),offset:String(sc+v.jobs.length)});w(ae=>({jobs:[...ae.jobs,...F.jobs],done:F.jobs.length<sc,busy:!1}))}catch(F){c(F instanceof Error?F.message:String(F)),w(ae=>({...ae,busy:!1}))}},k=new Set(((x==null?void 0:x.jobs)??[]).map(F=>F.id)),S=[...(x==null?void 0:x.jobs)??[],...v.jobs.filter(F=>!k.has(F.id))],b=(x==null?void 0:x.counts)??{},C=r?b[r]??0:wC.reduce((F,ae)=>F+(b[ae]??0),0),$=!v.done&&S.length<C&&((x==null?void 0:x.jobs.length)??0)>=sc,A=((L=j.data)==null?void 0:L.open)??[],I=((Q=j.data)==null?void 0:Q.dismissed)??[],M=A.reduce((F,ae)=>F+ae.count,0),O=I.reduce((F,ae)=>F+ae.count,0),R=()=>{y(),j.reload()},_=F=>h({...F,id:Date.now()}),z=async F=>{c(null);try{await F()}catch(ae){c(ae instanceof Error?ae.message:String(ae))}finally{R()}},U=async F=>{await z(async()=>{await F,l(null)})},P=F=>z(async()=>{const{ids:ae}=await T.dismissJobs(F==="all"?{all:!0}:{ids:F});ae.length!==0&&_({title:`Dismissed ${ae.length===1?"it":ae.length}`,body:"Kept under Dismissed, below.",undo:()=>T.undismissJobs(ae)})}),W=(F,ae)=>z(async()=>{const{jobs:V}=await T.retryJobs({ids:F});if(V.length===0)return;const J=V.length===1;_({title:`Retrying ${J?"it":V.length}`,body:ae?`${J?"It runs":"They run"} as soon as a worker is free.`:`If what broke ${J?"it":"them"} hasn’t changed, ${J?"it":"they"} will fail the same way.`})});return t.jsxs(js,{embedded:n,title:"Jobs",lede:`${x!=null&&x.paused?"Paused: nothing is being claimed. ":""}Bounded retries with backoff; past the budget a job waits for you.`,actions:n?void 0:t.jsx(E,{size:"sm",variant:x!=null&&x.paused?"accent":void 0,onClick:()=>U(T.setPaused(!((x==null?void 0:x.paused)??!1))),children:x!=null&&x.paused?"Resume the queue":"Pause the queue"}),children:[t.jsx(re,{message:g??j.error??o}),A.length>0?t.jsxs(rt,{flush:!0,title:"Gave up",tool:String(M),actions:M>1?t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>void P("all"),children:"Dismiss all"}):void 0,children:[t.jsx("ul",{className:"al-list",children:A.map(F=>t.jsx(bC,{group:F,timezone:e,onOpen:l,onRetry:ae=>void W(ae,F.likelyFixed),onDismiss:ae=>void P(ae)},F.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(rt,{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(F=>!F),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(rt,{flush:!0,title:"Dismissed",children:t.jsx("ul",{className:"al-list",children:I.map(F=>t.jsx(bC,{group:F,timezone:e,dismissed:!0,onOpen:l,onRetry:ae=>void W(ae,F.likelyFixed)},F.key))})}):null,p?null:t.jsx(rt,{flush:!0,title:"Queue",actions:t.jsxs("select",{"aria-label":"Job state",value:r,onChange:F=>a(F.target.value),children:[t.jsx("option",{value:"",children:"every state"}),wC.map(F=>t.jsxs("option",{value:F,children:[F," (",b[F]??0,")"]},F))]}),children:!x||S.length===0?t.jsx(be,{children:"No jobs match."}):t.jsxs(Yr,{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:S.map(F=>t.jsxs("tr",{children:[t.jsxs("td",{className:"clickable",onClick:()=>l(F),children:[F.kind,t.jsx("div",{className:"sub mono",children:rd(F.id)})]}),t.jsxs("td",{children:[t.jsx(Hd,{state:F.state}),F.suspendedReason?t.jsx("div",{className:"sub",children:mr(F.suspendedReason,40)}):null,F.acknowledgedAt?t.jsx("div",{className:"sub",children:"dismissed"}):null]}),t.jsxs("td",{className:"num",children:[F.attempts,"/",F.maxAttempts]}),t.jsx("td",{className:F.lastError?"critical":"muted",children:F.lastError?mr(F.lastError,80):"—"}),t.jsxs("td",{className:"nowrap",children:[ft(F.updatedAt,e),t.jsx("div",{className:"sub",children:Ge(F.updatedAt)})]}),t.jsx("td",{children:t.jsxs(se,{align:"end",children:[["failed","cancelled","suspended"].includes(F.state)?t.jsx(E,{size:"sm",onClick:()=>U(T.retryJob(F.id)),children:"Retry"}):null,["pending","leased","suspended","failed"].includes(F.state)?t.jsx(E,{size:"sm",variant:"danger",onClick:()=>U(T.cancelJob(F.id)),children:"Cancel"}):null]})})]},F.id))})]})}),$&&!p?t.jsxs(se,{children:[t.jsxs("span",{className:"muted",children:[S.length," of ",C," shown."]}),t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx(E,{disabled:v.busy,onClick:()=>void N(),children:v.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(ge,{title:"Last error",children:t.jsx(_t,{children:i.lastError})}):null,t.jsx(ge,{title:"Payload",children:t.jsx(_t,{children:rs(i.payload)})}),t.jsx(ge,{title:"Result",children:t.jsx(_t,{children:rs(i.result)})}),i.conversationId?t.jsx("p",{children:t.jsx("a",{href:`#/conversations/${i.conversationId}`,children:"open the transcript"})}):null]}):null,d?t.jsx(pd,{title:d.title,...d.body?{body:d.body}:{},duration:eX,...d.undo?{onUndo:()=>{const F=d.undo;z(async()=>{await F()})}}:{},onGone:()=>h(null)},d.id):null]})}function yC(e){var s;if(e.missionName)return e.missionName;const n=(s=e.job.payload)==null?void 0:s.prompt;return typeof n=="string"&&n.trim()!==""?mr(n.trim().split(`
128
+ `)[0],48):e.job.kind==="agent-run"?"Agent run":e.job.kind}function bC({group:e,timezone:n,dismissed:s,onOpen:r,onRetry:a,onDismiss:i}){var x;const[l,o]=u.useState(!1),c=e.jobs.length>1,d=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 ${Ge(((x=e.jobs[0])==null?void 0:x.job.acknowledgedAt)??e.lastAt)}`:`gave up ${Ge(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:yC(f)}),t.jsx("span",{"aria-hidden":"true",children:"·"})]}):null,t.jsx("span",{title:ft(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:yC(g)})," · ",im(new Date(g.job.updatedAt),n)," · tried ",g.job.attempts," ",tX(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(d),children:c?"Retry all":"Retry"}),i?t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>i(d),children:"Dismiss"}):null]})]})}const sX=[{id:"conversations",label:"Conversations"},{id:"jobs",label:"Jobs"},{id:"approvals",label:"Approvals"},{id:"alerts",label:"Alerts"},{id:"events",label:"Events"}];function rX({hash:e,timezone:n,navigate:s,agents:r}){var d,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(lX,{id:f,timezone:n,navigate:s,nameOf:i})}const l=((d=/^#\/activity\/([a-z]+)/.exec(e))==null?void 0:d[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(_i,{title:"Activity",lede:"Everything your agents ran, newest first.",actions:t.jsx(dX,{})}),t.jsx(uX,{}),t.jsx(Ro,{children:sX.map(f=>{const m=f.id==="conversations"?Yt:`${Yt}/${f.id}`;return t.jsx(Ji,{href:m,active:l===f.id,onClick:c(m),children:f.label},f.id)})}),l==="conversations"?t.jsx(aX,{timezone:n,navigate:s,nameOf:i,agents:r}):null,l==="jobs"?t.jsx(nX,{timezone:n,embedded:!0,initialState:o},o??""):null,l==="approvals"?t.jsx(iX,{timezone:n,nameOf:i}):null,l==="alerts"?t.jsx(qJ,{timezone:n,embedded:!0,agents:r,navigate:s}):null,l==="events"?t.jsx(ZJ,{timezone:n,embedded:!0}):null]})}function aX({timezone:e,navigate:n,nameOf:s,agents:r}){const{data:a,error:i}=pe(()=>T.conversations(),[],3e4);return t.jsxs(t.Fragment,{children:[t.jsx(re,{message:i}),t.jsx(rt,{flush:!0,children:a?a.conversations.length===0?t.jsx(as,{icon:"activity",title:"Nothing has run yet",children:"Conversations and runs show up here as your agents work."}):t.jsx(ut,{children:a.conversations.map(l=>t.jsx(ot,{href:od(l.id),onClick:()=>n(od(l.id)),lead:t.jsx(an,{agents:r,id:l.agentId,size:"sm"}),title:l.opening?mr(l.opening,100):"Untitled conversation",sub:`${s(l.agentId)}, ${l.messageCount} message${l.messageCount===1?"":"s"}, ${l.runs} run${l.runs===1?"":"s"}, ${iz(l.usage)}`,side:t.jsx("span",{title:ft(l.lastMessageAt??l.createdAt,e),children:Ge(l.lastMessageAt??l.createdAt)})},l.id))}):t.jsx(be,{children:"Loading…"})})]})}function iX({timezone:e,nameOf:n}){const{data:s,error:r}=pe(()=>T.approvals(),[],1e4),a=[...(s==null?void 0:s.pending)??[],...(s==null?void 0:s.recent)??[]];return t.jsxs(t.Fragment,{children:[t.jsx(re,{message:r}),t.jsx(rt,{flush:!0,children:s?a.length===0?t.jsx(as,{icon:"bell",title:"No approvals yet",children:"When an agent asks before acting, the request and your answer are kept here."}):t.jsxs(Yr,{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:rd(i.id)})]}),t.jsx("td",{children:t.jsx(Hd,{state:i.state})}),t.jsx("td",{children:n(i.agentId)}),t.jsx("td",{className:"nowrap",children:i.decidedAt?t.jsxs(t.Fragment,{children:[ft(i.decidedAt,e),t.jsxs("div",{className:"sub",children:["via ",i.decidedVia??"—"]})]}):t.jsx("span",{className:"muted",children:"—"})}),t.jsxs("td",{className:"nowrap",children:[ft(i.createdAt,e),t.jsx("div",{className:"sub",children:Ge(i.createdAt)})]})]},i.id))})]}):t.jsx(be,{children:"Loading…"})})]})}function lX({id:e,timezone:n,navigate:s,nameOf:r}){const[a,i]=u.useState(null),[l,o]=u.useState(null);u.useEffect(()=>{let d=!1;return T.conversation(e).then(h=>{d||i(h)}).catch(h=>{d||o(h instanceof Error?h.message:String(h))}),()=>{d=!0}},[e]);const c=d=>h=>{h.preventDefault(),s(d)};return t.jsxs("div",{className:"ui-page",children:[t.jsx("p",{className:"page-crumbs",children:t.jsx("a",{href:Yt,onClick:c(Yt),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(Yt),children:"← Back"}),t.jsx("span",{children:"Transcript"})]}),a?t.jsx("div",{className:"ui-page-actions",children:t.jsx(st,{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(re,{message:l}),a?t.jsxs(t.Fragment,{children:[t.jsxs(Sm,{children:[t.jsx(Lr,{label:"Agent",value:r(a.agentId),size:"sm"}),t.jsx(Lr,{label:"Runs",value:a.runs.length}),t.jsx(Lr,{label:"Tokens",value:`${fn(a.usage.input)} / ${fn(a.usage.output)}`,note:_x(a.usage)?`input / output, ${_x(a.usage)}`:"input / output"}),t.jsx(Lr,{label:"Started",value:ft(a.createdAt,n),size:"sm"})]}),a.runs.length>0?t.jsx(rt,{title:"Runs",flush:!0,children:t.jsxs(Yr,{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((d,h)=>t.jsxs("tr",{children:[t.jsxs("td",{className:"nowrap",children:[ft(d.startedAt,n)," ",d.resumed?t.jsx(Ce,{children:"resumed"}):null]}),t.jsx("td",{className:"nowrap",children:ft(d.finishedAt,n)}),t.jsx("td",{className:"num",children:d.turns??"—"}),t.jsxs("td",{children:[d.stopped??"—",d.actionId?t.jsxs("div",{className:"sub mono",children:["action ",rd(d.actionId)]}):null]}),t.jsxs("td",{className:"num muted nowrap",children:[fn(d.usage.input)," / ",fn(d.usage.output)]}),t.jsx("td",{className:"num muted nowrap",children:d.usage.cacheRead||d.usage.cacheWrite?fn((d.usage.cacheRead??0)+(d.usage.cacheWrite??0)):"—"})]},h))})]})}):null,t.jsx(ge,{title:"Messages",children:t.jsx(de,{children:a.messages.map(d=>t.jsxs("article",{className:"transcript-msg",children:[t.jsxs("header",{className:"transcript-who",children:[d.speaker===kC?"approved action, result":d.role,", ",ft(d.createdAt,n)]}),t.jsxs("div",{className:"transcript-body",children:[d.blocks.length===0?t.jsx("span",{className:"muted",children:"(empty)"}):null,d.speaker===kC?d.blocks.map((h,f)=>t.jsx(oX,{block:h},f)):d.blocks.map((h,f)=>t.jsx(cX,{block:h},f))]})]},d.id))})})]}):t.jsx(be,{children:"Loading…"})]})}const kC="approval:resume";function oX({block:e}){return t.jsxs("div",{className:"transcript-tool",children:[t.jsx("div",{className:"transcript-tool-name mono",children:"← approved action"}),t.jsx(_t,{children:e.type==="text"?e.text??"":rs(e)})]})}function cX({block:e}){return e.type==="text"?t.jsx("div",{className:"transcript-text",children:t.jsx(xr,{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(xr,{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(_t,{children:rs(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(_t,{children:e.content??""})]}):t.jsxs("div",{className:"transcript-tool",children:[t.jsx("div",{className:"transcript-tool-name mono",children:e.type}),t.jsx(_t,{children:rs(e.ref)})]})}function dX(){const{data:e,reload:n}=pe(()=>T.overview(),[],1e4),[s,r]=u.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 uX(){const{data:e,reload:n}=pe(()=>T.overview(),[],1e4);if(u.useEffect(()=>(window.addEventListener(Mi,n),()=>window.removeEventListener(Mi,n)),[n]),!e)return null;const s=a=>e.jobs[a]??0,r=s("leased");return t.jsxs(Sm,{children:[t.jsx(Lr,{label:"Jobs done",value:fn(s("succeeded"))}),t.jsx(Lr,{label:"Failed",value:fn(s("failed")),...s("failed")>0?{tone:"critical"}:{}}),t.jsx(Lr,{label:"Queued",value:fn(s("pending")),note:`${r} running`}),t.jsx(Lr,{label:"Approvals",value:fn(e.approvals.pending),note:"waiting for you"})]})}const hX=["replay-all","coalesce","latest-only","skip-after-deadline"];function iM({timezone:e,embedded:n,agentId:s}){const{data:r,error:a,reload:i}=pe(()=>T.missions(),[],3e4),l=((r==null?void 0:r.missions)??[]).filter(h=>!s||h.agentId===s),[o,c]=u.useState(null),d=async h=>{c(null);try{await h,i()}catch(f){c(f instanceof Error?f.message:String(f))}};return t.jsxs(js,{embedded:n,title:"Missions",lede:"Standing schedules. A disabled mission materializes nothing.",children:[t.jsx(re,{message:a??o}),!r||l.length===0?t.jsxs(as,{icon:"calendar",title:"No missions yet",children:["Run ",t.jsx("code",{children:"buddi missions add-defaults"})," for the standard set."]}):t.jsx(de,{children:l.map(h=>t.jsx(fX,{mission:h,timezone:e,onRun:d},h.id))})]})}function fX({mission:e,timezone:n,onRun:s}){const[r,a]=u.useState(!1);return t.jsxs(Sr,{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(Ce,{mono:!0,children:e.agentId}),e.alwaysDeliver?t.jsx(Ce,{children:"always delivers"}):null,e.enabled?null:t.jsx(Ce,{tone:"warning",children:e.endedAt?"ended":"disabled"}),e.pausedReason?t.jsx(Ce,{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(se,{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.stopWhen||e.endsAt?t.jsxs("p",{className:"ui-card-meta",children:[e.stopWhen?`Stops itself when ${e.stopWhen}. `:"",e.endedAt?`Ended ${ft(e.endedAt,n)}.`:e.endsAt?`Ends ${ft(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?`${ft(e.nextRun,n)} (${Ge(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"} ${Ge(e.lastNotification.at)}${e.lastNotification.reason?` — ${e.lastNotification.reason}`:""}`:"none"]}),r?t.jsxs("div",{className:"ui-card-foot",children:[e.schedule?t.jsxs(se,{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:hX.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(ge,{title:"Prompt",children:t.jsx(_t,{children:e.prompt})}),t.jsx(ge,{title:"Recent occurrences",children:t.jsx(rt,{flush:!0,children:e.occurrences.length===0?t.jsx(be,{children:"Never run."}):t.jsxs(Yr,{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:ft(i.scheduledAt,n)}),t.jsx("td",{children:t.jsx(Hd,{state:i.state})}),t.jsx("td",{className:"nowrap",children:ft(i.finishedAt,n)}),t.jsxs("td",{className:i.error?"critical":"muted",children:[i.error?mr(i.error,120):null,i.runConversationId?t.jsx("a",{href:`#/conversations/${i.runConversationId}`,children:"transcript"}):null]})]},i.id))})]})})})]}):null]})}function mX(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 lM({ids:e,agentName:n,onDone:s}){const r=e.length,[a,i]=u.useState(!1),[l,o]=u.useState(!1);return r<=0?null:a?t.jsxs("span",{className:"ui-row",children:[t.jsx("span",{className:"muted",children:mX(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 oM({embedded:e,agentId:n,agentName:s}){const{data:r,error:a,reload:i}=pe(()=>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),[d,h]=u.useState(null),[f,m]=u.useState(null),[p,x]=u.useState(null),g=async(j,v)=>{h(null),m(j);try{const w=await T.takeOffer(j);x(w.jobId?`On it — ${v}. Started as job ${w.jobId}.`:`Taken — ${v}. No worker is running here, so nothing has started yet.`),i()}catch(w){h(w instanceof Error?w.message:String(w))}finally{m(null)}},y=async(j,v)=>{h(null),m(j);try{await T.dismissOffer(j),x(`Dismissed — ${v}. It will not come back.`),i()}catch(w){h(w instanceof Error?w.message:String(w))}finally{m(null)}};return t.jsxs(js,{embedded:e,title:"Offers",lede:"Things an agent already worked out that you might want done. Taking one asks that agent the sentence it wrote. It authorizes nothing, and anything that would leave this machine still comes back to you as an approval.",children:[t.jsx(re,{message:a??d}),p?t.jsx(q,{tone:"good",role:"status",children:p}):null,o.length>0?t.jsxs(se,{children:[t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx(lM,{ids:o.map(j=>j.id),agentName:s,onDone:()=>{x(null),i()}})]}):null,!r||o.length===0?t.jsx(as,{icon:"bulb",title:"Nothing on offer",children:"When an agent works out something you might want done, it waits here."}):t.jsx(de,{children:o.map(j=>t.jsx(Sr,{tone:"accent",title:j.label,meta:t.jsxs(t.Fragment,{children:[t.jsx(Ce,{mono:!0,children:j.agentId}),t.jsxs("span",{className:"muted",children:["expires ",Ge(j.expiresAt)]})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(E,{size:"sm",variant:"ghost",disabled:f===j.id,onClick:()=>void y(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(Kt,{summary:`Dismissed and lapsed (${c.length})`,boxed:!0,children:[t.jsx(rt,{flush:!0,children:t.jsx(ut,{children:c.map(j=>t.jsx(ot,{title:j.label,sub:`${j.agentId} — ${dz(j)}`,side:Ge(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 pX(e){var r,a;const n=pe(()=>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 gX({entry:e,navigate:n,onUpdated:s}){const[r,a]=u.useState(null),[i,l]=u.useState(null),[o,c]=u.useState(!1),d=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 fe?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:mn(e.package),onClick:f=>{f.preventDefault(),n(mn(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})`:co(e.version)]}),e.delisted?t.jsx("span",{className:"muted",children:" · it keeps working; no updates will come"}):null,d?t.jsx(E,{size:"sm",variant:d==="update"?"accent":void 0,disabled:o,onClick:h,children:d==="update"&&e.latest?`Update to ${co(e.latest)}`:d==="update"?"Update":"See what changed"}):null]}),i?t.jsx(re,{message:i}):null,r?t.jsx(YR,{entry:r,agentId:e.agentId,onClose:()=>a(null),onUpdated:s}):null]})}function xX(e){return typeof e=="string"?e:e.name??e.id??"a mission"}function vX({agentId:e,name:n,navigate:s}){const[r,a]=u.useState(!1),[i,l]=u.useState(null),[o,c]=u.useState(null),[d,h]=u.useState(!1),[f,m]=u.useState(null),p=()=>{a(!1),m(null),s(yt)},x=N=>N instanceof fe?N.message:String(N),g=()=>{a(!0),c(null),l(null),T.agentRemovePreview(e).then(l).catch(N=>c(x(N)))},y=()=>{h(!0),c(null),T.removeAgent(e).then(N=>{var S;window.dispatchEvent(new Event(xs));const k=(S=N.result)==null?void 0:S.delegateListsNotUpdated;if(Array.isArray(k)&&k.length>0){m(k.map(b=>String((b==null?void 0:b.handle)??(b==null?void 0:b.id)??"")));return}a(!1),s(yt)}).catch(N=>c(x(N))).finally(()=>h(!1))},j=(i==null?void 0:i.pausesMissions.map(xX))??[],v=(i==null?void 0:i.unusedPlugins)??[],w=((i==null?void 0:i.handedWorkBy)??[]).map(N=>`@${N}`);return t.jsxs(rt,{children:[t.jsxs(se,{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(zt,{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(zt,{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:d||!i,onClick:y,children:"Remove from team"})]}),children:[t.jsx(re,{message:o}),i?t.jsxs("div",{className:"ui-stack","data-testid":"remove-preview",children:[t.jsxs("p",{children:["@",i.handle,"’s folder moves to the trash folder, so it can be brought back by hand."]}),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,v.length>0?t.jsxs("p",{children:["No other agent uses ",ln(v.map(Pm)),"; it stays installed."," ",t.jsxs("a",{href:ze("plugins"),onClick:N=>{N.preventDefault(),a(!1),s(ze("plugins"))},children:["Remove ",v.length===1?"it":"them"," in Settings → Plugins"]}),"."]}):null]}):o?null:t.jsx("p",{className:"muted",children:"Reading what it would change…"})]}):null]})}const cM=["January","February","March","April","May","June","July","August","September","October","November","December"],wf=e=>e?{day:String(e.day),month:String(e.month),year:e.year?String(e.year):""}:{day:"",month:"",year:""};function yf(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 jX=(e,n)=>(e??null)===(n??null)||!!e&&!!n&&e.day===n.day&&e.month===n.month&&(e.year??null)===(n.year??null),dM=(e,n=!0)=>`${e.day} ${cM[e.month-1]}${n&&e.year?` ${e.year}`:""}`;function sj({label:e,hint:n,value:s,onChange:r}){const a=yf(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"}),cM.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 wX=8e3;function yX(e){return e.kind==="policy"&&e.state==="open"&&String(e.payload.plugin??"")==="memory"&&e.ruleKind==="person"}function bX(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} ${dM(r,!1)}`:null}function NC({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 kX(){var y,j;const e=pe(()=>T.people(),[],6e4),n=pe(()=>T.proposals(),[],6e4),[s,r]=u.useState(null),[a,i]=u.useState(null),[l,o]=u.useState(null),[c,d]=u.useState(null),[h,f]=u.useState(null),m=async(v,w)=>{f(v),d(null);try{return await w(),e.reload(),n.reload(),!0}catch(N){return d(N instanceof fe?N.message:String(N)),!1}finally{f(null)}},p=(((y=n.data)==null?void 0:y.open)??[]).filter(yX),x=((j=e.data)==null?void 0:j.people)??[],g=v=>[v.relationship,v.birthday?`born ${dM(v.birthday)}`:null].filter(Boolean).join(" · ")||"No details yet";return t.jsxs(de,{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(rt,{flush:!0,children:t.jsx(ut,{children:p.map(v=>{var w;return t.jsx(ot,{lead:t.jsx(NC,{name:String(((w=v.payload.matcher)==null?void 0:w.person)??"?"),small:!0}),title:String(v.payload.action??""),sub:t.jsx("span",{className:"person-from",children:v.why}),side:t.jsxs("span",{className:"person-side",children:[t.jsx(E,{variant:"ghost",size:"sm",disabled:h!==null,onClick:()=>void m(`discard:${v.id}`,()=>T.discardProposal(v.id,"Not a person")),children:"Not a person"}),t.jsx(E,{size:"sm",disabled:h!==null,onClick:()=>void m(`keep:${v.id}`,()=>T.keepProposal(v.id)),children:"Keep"})]})},v.id)})})}),p.length>1?t.jsx(se,{align:"end",children:t.jsxs(E,{variant:"accent",size:"sm",disabled:h!==null,onClick:()=>void m("keep-all",()=>T.keepAllProposals(p.map(v=>v.id))),children:["Keep all (",p.length,")"]})}):null]}):null,t.jsxs(ge,{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?x.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(ut,{children:x.map(v=>{const w=bX(v);return t.jsx(ot,{label:`${v.name}: edit`,onClick:()=>r(v),lead:t.jsx(NC,{name:v.name}),title:v.name,sub:g(v),side:t.jsxs("span",{className:"person-side",children:[w?t.jsx(Ce,{tone:v.next&&v.next.inDays<=7?"accent":void 0,children:w}):null,v.reminders?t.jsx("span",{className:"person-bell",title:"Reminders on","aria-label":"Reminders on",children:t.jsx(ie,{name:"bell",size:14})}):null]})},v.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(NX,{person:s==="new"?null:s,onClose:()=>r(null),onSaved:()=>{r(null),e.reload()},onForget:v=>{r(null),i(v)}}):null,a?t.jsx(Je,{title:`Forget ${a.name}?`,onClose:()=>i(null),foot:t.jsxs(se,{children:[t.jsx(gt,{}),t.jsx(E,{variant:"ghost",onClick:()=>i(null),children:"Cancel"}),t.jsx(E,{variant:"danger",disabled:h!==null,onClick:()=>{const v=a;m(`forget:${v.id}`,()=>T.forgetPerson(v.id)).then(w=>{i(null),w&&o({id:Date.now(),person:v})})},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(pd,{title:`Forgot ${l.person.name}.`,duration:wX,onUndo:()=>{const v=l.person;m(`restore:${v.id}`,()=>T.restorePerson(v.id))},onGone:()=>o(null)},l.id):null]})}function NX({person:e,onClose:n,onSaved:s,onForget:r}){const[a,i]=u.useState((e==null?void 0:e.name)??""),[l,o]=u.useState((e==null?void 0:e.relationship)??""),[c,d]=u.useState((e==null?void 0:e.addressAs)??""),[h,f]=u.useState(wf(e==null?void 0:e.birthday)),[m,p]=u.useState(wf(e==null?void 0:e.anniversary)),[x,g]=u.useState((e==null?void 0:e.notes)??""),[y,j]=u.useState((e==null?void 0:e.reminders)===!0),[v,w]=u.useState(!1),[N,k]=u.useState(null),S=yf(h),b=yf(m),C=S==="incomplete"||b==="incomplete",$=S!==null&&S!=="incomplete"||b!==null&&b!=="incomplete",A=async()=>{if(!C){w(!0),k(null);try{const I=M=>M.trim()===""?null:M.trim();await T.savePerson({...e?{id:e.id}:{},name:a.trim(),relationship:I(l),addressAs:I(c),birthday:S,anniversary:b,notes:I(x),reminders:$&&y}),s()}catch(I){k(I instanceof fe?I.message:String(I))}finally{w(!1)}}};return t.jsx(Je,{title:e?e.name:"Add a person",onClose:n,foot:t.jsxs(se,{children:[e?t.jsx(E,{variant:"danger-ghost",disabled:v,onClick:()=>r(e),children:"Forget…"}):null,t.jsx(gt,{}),t.jsx(E,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:v||a.trim()===""||C,onClick:()=>void A(),children:v?"Saving…":"Save"})]}),children:t.jsxs(de,{gap:"lg",children:[t.jsxs(Ts,{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=>d(I.target.value)})}),t.jsx(sj,{label:"Birthday",hint:"The year is optional.",value:h,onChange:f}),t.jsx(sj,{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:x,onChange:I=>g(I.target.value)})}),t.jsxs("div",{className:"person-remind","data-off":$?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 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(Wd,{checked:$&&y,disabled:!$,onChange:j,label:"Remind me of their dates"})]}),N?t.jsx(q,{tone:"critical",children:N}):null]})})}const SX=["fact","observation","todo"];function uM({embedded:e,agents:n,timezone:s,agentId:r,initialTab:a="people"}){const{data:i,error:l,reload:o}=pe(()=>T.memory(r),[r],3e4),[c,d]=u.useState(null),[h,f]=u.useState(null),[m,p]=u.useState(null),[x,g]=u.useState(a),y=b=>{var C;return b==="shared"?"Everyone":((C=n.find($=>$.id===b))==null?void 0:C.name)??b},j=async b=>{p(null);try{await b,o()}catch(C){p(C instanceof fe?C.message:String(C))}},v={nameOf:y,timezone:s,onChangePreference:b=>d({key:b.key,scope:b.scope}),onForgetPreference:b=>void j(T.forgetPreference({key:b.key,scope:b.scope})),onEditNote:b=>f(b),onForgetNote:b=>void j(T.forgetNote(b.id))},w=r?y(r):"",N=r&&i?{preferences:i.preferences.filter(b=>b.scope===r),notes:i.notes.filter(b=>b.scope===r)}:null,k=r&&i?{preferences:i.preferences.filter(b=>b.scope==="shared"),notes:i.notes.filter(b=>b.scope==="shared")}:null,S=t.jsx(E,{variant:"accent",size:"sm",onClick:()=>d({key:"",scope:r??"shared"}),children:"Add a preference"});return t.jsxs(js,{embedded:e,title:"Memory",lede:"What your agents have kept about you. Correct anything here; they see the change on their next turn.",children:[t.jsx(re,{message:l??m}),N&&k?t.jsxs(de,{gap:"lg",children:[t.jsx(ge,{title:"Preferences",aside:`what you told ${w} alone`,actions:S,panel:!0,flush:!0,children:t.jsx(fg,{preferences:N.preferences,empty:`Nothing stated to ${w} alone yet.`,...v})}),t.jsx(ge,{title:"Notes",aside:`what ${w} wrote down for itself`,panel:!0,flush:!0,children:t.jsx(mg,{notes:N.notes,empty:`${w} has kept no private notes yet.`,...v})}),t.jsx(Kt,{summary:`Shared with every agent, which ${w} also reads · ${k.preferences.length} preferences, ${k.notes.length} notes`,children:t.jsxs(de,{gap:"lg",children:[t.jsx(ge,{title:"Shared preferences",panel:!0,flush:!0,children:t.jsx(fg,{preferences:k.preferences,empty:"No shared preferences.",...v})}),t.jsx(ge,{title:"Shared notes",panel:!0,flush:!0,children:t.jsx(mg,{notes:k.notes,empty:"No shared notes.",...v})})]})})]}):t.jsxs(de,{gap:"lg",children:[t.jsx(Ro,{label:"Memory",children:[["people","People"],["preferences","Preferences",i==null?void 0:i.preferences.length],["notes","Notes",i==null?void 0:i.notes.length]].map(([b,C,$])=>t.jsx(Ji,{href:`${ze("memory")}?tab=${b}`,active:x===b,...$?{count:$}:{},onClick:A=>{A.preventDefault(),g(b)},children:C},b))}),x==="people"?t.jsx(kX,{}):null,x==="preferences"?t.jsx(ge,{title:"Preferences",aside:"what you said you want, one current value each",actions:S,panel:!0,flush:!0,children:i?t.jsx(fg,{preferences:i.preferences,empty:'Nothing stated yet. Tell any agent "from now on…" or add one here.',...v}):t.jsx(be,{children:"Loading…"})}):null,x==="notes"?t.jsx(ge,{title:"Notes",aside:"what an agent wrote down, with who wrote it",panel:!0,flush:!0,children:i?t.jsx(mg,{notes:i.notes,empty:"No notes yet. An agent writes one when you state something durable about your life.",...v}):t.jsx(be,{children:"Loading…"})}):null]}),c?t.jsx(CX,{agents:n,existing:(i==null?void 0:i.preferences)??[],initial:c,onClose:()=>d(null),onSave:async b=>{await j((async()=>{await T.setPreference(b),c.key===b.key&&c.scope!==b.scope&&await T.forgetPreference({key:c.key,scope:c.scope})})()),d(null)}}):null,h?t.jsx(EX,{note:h,agents:n,onClose:()=>f(null),onSave:b=>j(T.updateNote(h.id,b)).then(()=>f(null))}):null]})}function fg({preferences:e,empty:n,nameOf:s,onChangePreference:r,onForgetPreference:a}){return e.length===0?t.jsx(be,{children:n}):t.jsxs(Yr,{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(hM,{scope:i.scope,name:s(i.scope)})}),t.jsxs("td",{className:"num muted",title:i.updatedAt??"",children:[i.updatedAt?Ge(i.updatedAt,Date.now()):"",i.revision>1?` · rev ${i.revision}`:""]}),t.jsx("td",{className:"num",children:t.jsxs(se,{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 mg({notes:e,empty:n,nameOf:s,timezone:r,onEditNote:a,onForgetNote:i}){return e.length===0?t.jsx(be,{children:n}):t.jsxs(Yr,{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(Ce,{tone:l.kind==="todo"?"warning":l.kind==="fact"?"good":void 0,children:l.kind})}),t.jsx("td",{children:t.jsx(hM,{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?Ge(l.createdAt,Date.now()):"",l.expiresAt?t.jsxs("span",{className:"memory-expires",children:[" · until ",Nr(new Date(l.expiresAt),r,{year:!0,compact:!0})]}):null]}),t.jsx("td",{className:"num",children:t.jsxs(se,{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 hM({scope:e,name:n}){return t.jsx(Ce,{tone:e==="shared"?"accent":void 0,title:e==="shared"?"Every agent reads this":`Only ${n} reads this`,children:n})}function fM({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 CX({agents:e,existing:n,initial:s,onClose:r,onSave:a}){const i=n.find(v=>v.key===s.key&&v.scope===s.scope),[l,o]=u.useState(s.key),[c,d]=u.useState((i==null?void 0:i.value)??""),[h,f]=u.useState(s.scope),[m,p]=u.useState(!1),x=l.trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),g=n.find(v=>v.key===x&&v.scope===h),y=!i||x!==i.key||c.trim()!==i.value||h!==i.scope,j=x!==""&&c.trim()!==""&&y;return t.jsx(Je,{title:"A preference",onClose:r,children:t.jsxs(de,{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:x&&x!==l?`Stored as ${x}`:"Short and stable, like reporting_currency or tone.",children:t.jsx("input",{value:l,autoFocus:s.key==="",onChange:v=>o(v.target.value),placeholder:"reporting_currency"})}),t.jsx(oe,{label:"Value",children:t.jsx("textarea",{rows:3,value:c,maxLength:2e3,autoFocus:s.key!=="",onChange:v=>d(v.target.value),placeholder:"EUR"})}),t.jsx(oe,{label:"Who should know",hint:"Shared reaches every agent. Private stays with one.",children:t.jsx(fM,{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(se,{align:"end",children:[t.jsx(E,{onClick:r,children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:!j||m,onClick:()=>{p(!0),a({key:x,value:c.trim(),scope:h}).finally(()=>p(!1))},children:i?"Save change":"Save"})]})]})})}function EX({note:e,agents:n,onClose:s,onSave:r}){var p;const[a,i]=u.useState(e.content),[l,o]=u.useState(e.scope),[c,d]=u.useState(e.kind),[h,f]=u.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(de,{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:x=>i(x.target.value)})}),t.jsxs(Ts,{children:[t.jsx(oe,{label:"Kind",children:t.jsx("select",{value:c,onChange:x=>d(x.target.value),children:SX.map(x=>t.jsx("option",{value:x,children:x},x))})}),t.jsx(oe,{label:"Who sees it",children:t.jsx(fM,{value:l,agents:n,onChange:o})})]}),e.createdByAgent?t.jsxs("p",{className:"muted",children:["Written by ",((p=n.find(x=>x.id===e.createdByAgent))==null?void 0:p.name)??e.createdByAgent,e.createdAt?`, ${Ge(e.createdAt,Date.now())}`:"",". Editing keeps that record."]}):null,t.jsxs(se,{align:"end",children:[t.jsx(E,{onClick:s,children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:!m||a.trim()===""||h,onClick:()=>{f(!0);const x={};a.trim()!==e.content&&(x.content=a.trim()),l!==e.scope&&(x.scope=l),c!==e.kind&&(x.kind=c),r(x).finally(()=>f(!1))},children:"Save"})]})]})})}const bf="host.exec",AX={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]=AX[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 hb({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 $X={skill:"doc",script:"script",font:"font",image:"image",data:"doc",template:"doc",other:"doc"},TX={skill:"The skill",script:"Script",font:"Font",image:"Picture",data:"Data",template:"Template",other:"File"};function IX(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 mM({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:IX(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:$X[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:zr(r.file.size)})]},r.file.path))})}function RX(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 ${bf}, and asks you first.`:n.run.length?`${s}It runs only when ${oi(n.run)} ${n.run.length>1?"run":"runs"} it with ${bf}, 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 pM({file:e,skillView:n,read:s,imageUrl:r,reach:a}){const[i,l]=u.useState(null);if(u.useEffect(()=>{if(e.kind==="skill")return;let c=!0;return l({path:e.path}),s(e.path).then(d=>{c&&l({path:e.path,file:d.file})},d=>{c&&l({path:e.path,error:d instanceof fe?d.message:String(d)})}),()=>{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:[TX[e.kind]," · ",zr(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:RX(e,a)})]}):null,i!=null&&i.error?t.jsx(re,{message:i.error}):e.kind==="font"?t.jsxs("div",{className:"skb-blank",children:[t.jsx(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. ",zr(e.size),"."]})]}):t.jsx(_t,{label:e.path,children:o.text}):t.jsx("p",{className:"skills-note",children:"Reading the file…"})]})}function gM({children:e}){return t.jsx("div",{className:"skb-files",children:e})}function xM({children:e}){return t.jsxs("p",{className:"skb-promise",children:[t.jsx(Xa,{name:"shield",size:16}),t.jsx("span",{children:e})]})}const PX="Up to 20 MB and 500 files. Nothing in it runs when you upload it.";function MX({initialRefusal:e,onClose:n,onMd:s,onStaged:r}){var g;const[a,i]=u.useState(!1),[l,o]=u.useState(e??null),[c,d]=u.useState(null),[h,f]=u.useState(null),m=u.useRef(null),p=y=>{if(!(!y||c)){if(f(null),/\.md$/i.test(y.name)){s(y);return}if(!/\.zip$/i.test(y.name)){o({kind:"notzip",filename:y.name});return}if(y.size>XH){o({kind:"big",filename:y.name,size:y.size});return}d(y.name),tn.uploadBundle(y).then(j=>r(j),j=>{d(null),j instanceof ZI?o(j.refusal):f(j instanceof fe?j.message:String(j))})}},x=l?lK(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:y=>{var j;p((j=y.target.files)==null?void 0:j[0]),y.target.value=""}}),t.jsxs("div",{className:"skills-sheet skb-drop-sheet",children:[x?t.jsx(q,{tone:"critical",title:x.title,role:"alert",children:t.jsxs("div",{className:"skb-refusal",children:[x.body,(g=x.items)!=null&&g.length?t.jsx("ul",{className:"skb-refused",children:x.items.map(y=>t.jsxs("li",{children:[t.jsx("span",{className:"mono",children:y.path})," ",y.rest]},y.path))}):null]})}):null,t.jsx(re,{message:h}),t.jsxs("div",{className:"skb-drop","data-over":a?"true":void 0,"data-testid":"skill-drop",onDragOver:y=>{y.preventDefault(),i(!0)},onDragLeave:()=>i(!1),onDrop:y=>{var j;y.preventDefault(),i(!1),p((j=y.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":x?"Drop another file here":"Drop a .zip or a .md here"}),t.jsx(E,{variant:x?void 0:"accent",disabled:c!==null,onClick:()=>{var y;return(y=m.current)==null?void 0:y.click()},children:x?"Choose another file":"Choose a file"}),t.jsx("span",{className:"skb-drop-limits",children:PX})]}),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 OX({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 DX({staged:e,agents:n,faces:s,onClose:r,onBack:a,onAdded:i}){var S,b;const l=e.files.filter(C=>C.kind==="script"),[o,c]=u.useState(((S=l.find(C=>C.setup))==null?void 0:S.path)??((b=l[0])==null?void 0:b.path)??"SKILL.md"),[d,h]=u.useState([]),[f,m]=u.useState(!1),[p,x]=u.useState(!1),[g,y]=u.useState(null),j=n.filter(C=>C.canRunScripts).map(C=>C.name),v=e.files.find(C=>C.path===o)??e.files[0],w=C=>{tn.discardBundle(e.id).catch(()=>{}),C()},N=async()=>{x(!0),y(null);try{const{skill:C}=await tn.acceptBundle(e.id,{agents:d,mine:f});i(C)}catch(C){y(C instanceof fe?C.message:String(C)),x(!1)}},k=l.some(C=>C.setup);return t.jsxs(Je,{size:"wide",title:t.jsxs("span",{className:"skills-sheet-title",children:[t.jsx(hb,{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 · ",zr(e.size)," unpacked · read, not saved yet"]})]})]}),onClose:()=>w(r),foot:t.jsxs(se,{children:[t.jsx(E,{variant:"ghost",onClick:()=>w(a),children:"Choose another file"}),t.jsx(gt,{}),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",k?" — setup scripts too.":"."]}):null,t.jsx(re,{message:g}),t.jsxs("div",{className:"skills-sheet",children:[t.jsxs("section",{className:"skills-sec","aria-label":"From its SKILL.md",children:[t.jsx("header",{className:"skills-sec-head",children:t.jsx("h3",{className:"skills-sec-title",children:"From its SKILL.md"})}),t.jsx(Qt,{items:[{label:"Name",value:e.skill.title},{label:"When it’s used",value:e.skill.description},{label:"First lines",value:t.jsxs("span",{className:"skb-first",children:[e.skill.firstLines,e.skill.firstLines.length>=160?"…":""]})}]})]}),t.jsxs("section",{className:"skills-sec","aria-label":"What’s inside",children:[t.jsxs("header",{className:"skills-sec-head",children:[t.jsx("h3",{className:"skills-sec-title",children:"What’s inside"}),t.jsxs("span",{className:"skills-sec-aside skills-note",children:[zr(e.size)," unpacked · ",zr(e.packed)," as a .zip"]})]}),t.jsxs(gM,{children:[t.jsx(mM,{files:e.files,selected:v.path,onSelect:c}),t.jsx(pM,{file:v,read:C=>tn.stagedFile(e.id,C),imageUrl:C=>tn.stagedImageUrl(e.id,C),reach:{run:[],held:!1,untrusted:!1},skillView:t.jsx(LX,{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(OX,{checked:d.includes(C.id),onChange:$=>h($?[...d,C.id]:d.filter(A=>A!==C.id)),lead:t.jsx(Rn,{id:C.id,name:C.name,size:"sm",face:s.find($=>$.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 ${oi(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 LX({staged:e}){const[n,s]=u.useState(null);return u.useEffect(()=>{let r=!0;return tn.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(_t,{label:"SKILL.md",children:n})]})}const FX=5e4,Zi=e=>e instanceof fe?e.message:String(e),_X=e=>n=>{n.stopPropagation(),e==null||e()};function zX({faces:e,navigate:n,command:s,openSkill:r,openFile:a}){const i=pe(()=>tn.list(),[]),[l,o]=u.useState(r?{id:r,...a?{file:a}:{}}:null),[c,d]=u.useState(null),[h,f]=u.useState(null),[m,p]=u.useState(null),[x,g]=u.useState(null),y=u.useRef(null);u.useEffect(()=>{r&&o({id:r,...a?{file:a}:{}})},[r,a]),u.useEffect(()=>{s&&d(s.kind==="write"?{kind:"write"}:{kind:"drop"})},[s]);const j=k=>{var b;const S=(b=k.target.files)==null?void 0:b[0];k.target.value="",S&&v(S)},v=k=>{if(!/\.md$/i.test(k.name)){f(`“${k.name}” isn’t a .md file. A skill is one Markdown file.`);return}if(k.size>FX){f(`“${k.name}” is over 50 KB. A skill is a short text.`);return}const S=new FileReader;S.onload=()=>{f(null),d({kind:"upload",file:{name:k.name,size:k.size,...dK(k.name,String(S.result))}})},S.readAsText(k)},w=k=>{p(null),k!==void 0&&g(k),i.reload()};return t.jsxs(t.Fragment,{children:[t.jsx("input",{ref:y,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),d({kind:"drop"})},children:"Pick another file"}),children:h}):null,t.jsx(re,{message:m}),x?t.jsx(q,{tone:"good",role:"status",children:x}):null,t.jsx(UX,{view:i,onOpen:k=>o({id:k.id}),onAct:(k,S)=>N(k,S)}),t.jsx(vM,{view:i.data,faces:e,open:l,setOpen:o,dialog:c,setDialog:d,navigate:n,onChanged:w,onFailed:p}),(c==null?void 0:c.kind)==="write"&&i.data?t.jsx(CC,{agents:i.data.agents,faces:e,onClose:()=>d(null),onSaved:k=>{d(null),w(`Saved “${k.title}”.`)}}):null,(c==null?void 0:c.kind)==="drop"?t.jsx(MX,{onClose:()=>d(null),onMd:k=>{d(null),v(k)},onStaged:k=>d({kind:"zip",staged:k})}):null,(c==null?void 0:c.kind)==="zip"&&i.data?t.jsx(DX,{staged:c.staged,agents:i.data.agents,faces:e,onClose:()=>d(null),onBack:()=>d({kind:"drop"}),onAdded:k=>{d(null),w(`Added “${k.title}”.`),o({id:k.id})}}):null,(c==null?void 0:c.kind)==="upload"&&i.data?t.jsx(CC,{agents:i.data.agents,faces:e,upload:c.file,onClose:()=>d(null),onSaved:k=>{d(null),w(`Saved “${k.title}”.`)}}):null]});function N(k,S){g(null),S==="trust"?tn.trust(k.id).then(()=>w(),b=>p(Zi(b))):S==="download"?tR(k.id):S==="plugin"?n(ze("plugins")):S==="edit"?(d(null),o({id:k.id,edit:!0})):d({kind:S,id:k.id})}}function UX({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(WX,{});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(rt,{flush:!0,children:Iy.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(ut,{children:l.map(o=>t.jsx(BX,{row:o,agents:a,onOpen:n,onAct:s},o.id))})]},i.id):null})})}function BX({row:e,agents:n,onOpen:s,onAct:r}){var o,c,d;const a=e.untrusted?["trust","Mark as mine"]:rK(e)?["picker","Choose agents"]:null,i=sK(e,n),l=iK(e,n);return t.jsx(ot,{onClick:()=>s(e),label:`${e.title}: details`,lead:e.bundle?t.jsx(hb,{}):t.jsx(Yn,{icon:"files"}),title:e.bundle?t.jsxs("span",{className:"skb-title",children:[e.title,t.jsx(lo,{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," · ",Ec(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:My(e,n)}):null]}),side:t.jsxs("span",{className:"skills-side",children:[a?t.jsx(E,{size:"sm",onClick:_X(()=>r(e,a[0])),children:a[1]}):null,t.jsx(Qn,{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 ${Ry(e.from.plugin)}`,onSelect:()=>r(e,"plugin")}:null,e.deletable&&((c=e.from)==null?void 0:c.kind)!=="plugin"?"separator":null,e.deletable&&((d=e.from)==null?void 0:d.kind)!=="plugin"?{label:"Delete…",tone:"critical",onSelect:()=>r(e,"delete")}:null]})]})})}function WX(){return t.jsx(rt,{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(ut,{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 vM({view:e,faces:n,open:s,setOpen:r,dialog:a,setDialog:i,navigate:l,onChanged:o,onFailed:c}){if(!e)return null;const d=m=>e.skills.find(p=>p.id===m),h=s?d(s.id):void 0,f=a&&"id"in a?d(a.id):void 0;return t.jsxs(t.Fragment,{children:[h?t.jsx(HX,{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(KX,{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(GX,{row:f,agents:e.agents,onCancel:()=>i(null),onDeleted:m=>{i(null),r(null),o(m)}}):null]})}function jM({title:e,sub:n}){return t.jsxs("span",{className:"skills-sheet-title",children:[t.jsx(Yn,{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 fc({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 SC({file:e,body:n,text:s}){const[r,a]=u.useState("read");return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"skills-text-bar",children:[t.jsx(Jt,{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(xr,{className:"wb-md skills-md",text:n}):t.jsx(_t,{label:e,children:s})]})}function HX({row:e,agents:n,faces:s,initialEdit:r,initialFile:a,onClose:i,onPicker:l,onDelete:o,onChanged:c,onFailed:d,navigate:h}){var V,J,H,X;const f=pe(()=>tn.detail(e.id),[e.id,e.updatedAt,e.untrusted,(V=e.learned)==null?void 0:V.version]),[m,p]=u.useState(!!r&&e.editable),[x,g]=u.useState(null),[y,j]=u.useState(!1),[v,w]=u.useState(null),[N,k]=u.useState(r?"SKILL.md":a??"SKILL.md"),S=((J=f.data)==null?void 0:J.text)??"",b=sR(Ec(e,n)),C=oK(e,n),$=((H=e.from)==null?void 0:H.kind)==="plugin"?Ry(e.from.plugin):null,A=G=>s.find(ce=>ce.id===G),I=e.bundle??null,M=((X=f.data)==null?void 0:X.bundle)??null,O=(I==null?void 0:I.scripts.length)??0,R=G=>{var ce;return((ce=n.find(xe=>xe.id===G))==null?void 0:ce.canRunScripts)===!0},_=rR(e,n).filter(R).map(G=>Js(n,G)),z=async(G,ce)=>{j(!0),w(null);try{await G(),ce==null||ce(),c()}catch(xe){w(Zi(xe)),d(Zi(xe))}finally{j(!1)}},U=G=>{z(()=>tn.grant(e.id,{agents:Oy(e).filter(ce=>ce!==G)}))},P=()=>{z(()=>tn.saveText(e.id,x??S),()=>{p(!1),g(null)})},W=()=>{k("SKILL.md"),p(!0)},L=(G,ce)=>{var xe,De;if(I)return O?R(G)?t.jsxs("span",{className:"skb-can",children:["Can run its scripts with ",t.jsx("span",{className:"mono",children:bf}),", 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)===G)return"Proposed it";if(((De=e.from)==null?void 0:De.kind)==="catalogue"&&e.from.agent===G)return"Came with it";if(ce==="home")return"In its own folder"},Q=t.jsx("textarea",{className:"skills-editor",value:x??S,onChange:G=>g(G.target.value),"aria-label":`Text of ${e.title}`,spellCheck:!1,autoFocus:!0}),F=I&&M?`Bundle · ${M.files.length} files · ${zr(M.size)} · ${Ec(e,n)}`:I?`Bundle · ${I.files+1} files · ${zr(I.size)} · ${Ec(e,n)}`:b,ae=(M==null?void 0:M.files.find(G=>G.path===N))??(M==null?void 0:M.files[0]);return t.jsxs(Je,{size:"wide",title:I?t.jsxs("span",{className:"skills-sheet-title",children:[t.jsx(hb,{size:"lg"}),t.jsxs("span",{className:"skills-sheet-name",children:[t.jsx("span",{children:e.title}),t.jsx("span",{className:"skills-sheet-by",children:F})]})]}):t.jsx(jM,{title:e.title,sub:b}),onClose:i,foot:m?t.jsxs(se,{align:"end",children:[t.jsx(E,{variant:"ghost",disabled:y,onClick:()=>{p(!1),g(null)},children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:y||!f.data,onClick:P,children:I?"Save SKILL.md":"Save"})]}):t.jsxs(se,{children:[e.deletable&&!$?t.jsx(E,{variant:"danger-ghost",onClick:o,children:"Delete…"}):null,t.jsx(gt,{}),t.jsx(E,{onClick:()=>tR(e.id),children:I?"Download .zip":"Download"}),e.editable?t.jsx(E,{variant:e.untrusted?void 0:"accent",onClick:W,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:y,onClick:()=>void z(()=>tn.trust(e.id)),children:"Mark as mine"}),children:[My(e,n)," Mark it as yours once you’ve read it",O?" and its scripts":"","."]}):null,t.jsx(re,{message:v}),t.jsxs("div",{className:"skills-sheet",children:[t.jsx(fc,{title:"When it’s used",children:t.jsx("p",{className:"skills-desc",children:e.description})}),t.jsxs(fc,{title:"Used by",aside:t.jsx(E,{size:"sm",onClick:l,children:"Change…"}),children:[O?t.jsx(xM,{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(ut,{children:t.jsx(ot,{lead:t.jsx(Yn,{icon:"agents"}),title:Py(e,n),sub:O?_.length?`Now, and any you add later. ${oi(_)} 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(ut,{children:e.holders.map(G=>{const ce=n.find(xe=>xe.id===G.agent);return t.jsx(ot,{lead:t.jsx(Rn,{id:G.agent,name:(ce==null?void 0:ce.name)??G.agent,size:"sm",face:A(G.agent)}),title:t.jsxs(t.Fragment,{children:[(ce==null?void 0:ce.name)??G.agent," ",t.jsxs("span",{className:"skills-handle",children:["@",(ce==null?void 0:ce.handle)??G.agent]})]}),sub:L(G.agent,G.how),side:G.how==="home"?void 0:t.jsx(E,{size:"sm",variant:"ghost",disabled:y,onClick:()=>U(G.agent),"aria-label":`Take away from ${(ce==null?void 0:ce.name)??G.agent}`,children:"Take away"})},G.agent)})})}):t.jsx("p",{className:"skills-note",children:"No agent uses it yet, so it does nothing. Choose who should."})]}),I?t.jsxs(fc,{title:"Files",aside:M?t.jsxs("span",{className:"skills-note",children:[M.files.length," files · ",zr(M.size)]}):void 0,children:[!f.data||!M||!ae?f.error?t.jsx(re,{message:f.error}):t.jsx(be,{children:"Reading the bundle…"}):t.jsxs(gM,{children:[t.jsx(mM,{files:M.files,selected:ae.path,onSelect:m?null:k}),t.jsx(pM,{file:ae,read:G=>tn.file(e.id,G),imageUrl:G=>tn.imageUrl(e.id,G),reach:{run:_,held:e.every||e.holders.length>0,untrusted:e.untrusted!==null},skillView:m?Q:t.jsx(SC,{file:eS(e),body:f.data.body,text:S})})]}),t.jsx("p",{className:"skills-note",children:"Read only, except SKILL.md. To change any other file, upload the bundle again."})]}):t.jsxs(fc,{title:"The text",children:[f.data?m?Q:t.jsx(SC,{file:eS(e),body:f.data.body,text:S}):f.error?t.jsx(re,{message:f.error}):t.jsx(be,{children:"Reading the file…"}),m&&C?t.jsx("p",{className:"skills-note",children:C}):null,$?t.jsxs("p",{className:"skills-note",children:["Comes with ",$,", so it’s changed there. To stop an agent using it, take it away above."," ",t.jsx("a",{href:ze("plugins"),onClick:G=>{G.preventDefault(),h(ze("plugins"))},children:"Open Plugins"})]}):null]})]})]})}function kf({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 wM({label:e,value:n,onChange:s}){return t.jsxs("div",{className:"cat-search",children:[t.jsx(ie,{name:"search",size:16}),t.jsx(Cm,{label:e,value:n,placeholder:e,onChange:s})]})}function KX({row:e,agents:n,faces:s,onCancel:r,onSaved:a}){var k;const[i,l]=u.useState(e.every),[o,c]=u.useState(Oy(e)),[d,h]=u.useState(""),[f,m]=u.useState(!1),[p,x]=u.useState(null),g=d.trim().toLowerCase(),y=n.filter(S=>!g||`${S.name} ${S.handle}`.toLowerCase().includes(g)),j=(S,b)=>c(b?[...o,S]:o.filter(C=>C!==S)),v=((k=e.bundle)==null?void 0:k.scripts.length)??0,w=v?[["Can run its scripts",y.filter(S=>S.canRunScripts)],["Text only",y.filter(S=>!S.canRunScripts)]]:[[null,y]],N=async()=>{m(!0),x(null);try{await tn.grant(e.id,i?{every:!0,agents:[]}:{agents:o}),a()}catch(S){x(Zi(S))}finally{m(!1)}};return t.jsx(zt,{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:[v?t.jsxs(xM,{children:[v," script",v>1?"s":""," come",v>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(wM,{label:"Find an agent",value:d,onChange:h}),t.jsx(re,{message:p}),t.jsxs("div",{className:"skills-pick-list",children:[g||!e.shareable?null:t.jsx(kf,{checked:i,onChange:l,lead:t.jsx(Yn,{icon:"agents"}),title:"Every agent",sub:v?"Now and later. Scripts still ask each time.":"Now, and any you add later."}),w.map(([S,b])=>b.length?t.jsxs("div",{className:"skills-pick-group",role:S?"group":void 0,"aria-label":S??void 0,children:[S?t.jsxs("div",{className:"skills-pick-group-title",children:[S,S==="Text only"?" · no tool that runs scripts":" · asking you each time"]}):null,b.map(C=>{const $=e.home===C.id,A=(e.shadowedBy??[]).includes(C.id),I=$||A||!C.writable;return t.jsx(kf,{checked:!A&&(i||$||o.includes(C.id)),disabled:i||I,onChange:M=>j(C.id,M),lead:t.jsx(Rn,{id:C.id,name:C.name,size:"sm",face:s.find(M=>M.id===C.id)}),title:t.jsxs(t.Fragment,{children:[C.name," ",t.jsxs("span",{className:"skills-handle",children:["@",C.handle]})]}),sub:$?"Its own skill, in its folder":A?"Has its own skill of this name, and uses that":C.writable?v&&C.canRunScripts?t.jsxs("span",{className:"skb-can",children:["With ",t.jsx("span",{className:"mono",children:bf})]}):void 0:"Ships with buddi, so its file doesn’t change"},C.id)})]},S??"all"):null),y.length?null:t.jsxs("p",{className:"skills-note skills-pick-none",children:["No agent called “",d.trim(),"”."]})]}),t.jsx("p",{className:"skills-note",children:"Saved in each agent’s file, so the file stays the record."})]})})}function VX({agent:e,view:n,onCancel:s,onSaved:r}){const a=v=>nR(v,e.id),[i,l]=u.useState(n.skills.filter(a).map(v=>v.id)),[o,c]=u.useState(""),[d,h]=u.useState(!1),[f,m]=u.useState(null),p=o.trim().toLowerCase(),x=v=>!p||`${v.title} ${v.description}`.toLowerCase().includes(p),g=v=>v.every||v.home===e.id||!e.writable,y=async()=>{h(!0),m(null);try{for(const v of n.skills){if(g(v))continue;const w=i.includes(v.id);if(w===a(v))continue;const N=Oy(v);await tn.grant(v.id,{agents:w?[...N,e.id]:N.filter(k=>k!==e.id)})}r()}catch(v){m(Zi(v))}finally{h(!1)}},j=n.skills.some(x);return t.jsx(zt,{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:d||!e.writable,onClick:()=>void y(),children:"Save"})]}),children:t.jsxs("div",{className:"skills-pick",children:[t.jsx(wM,{label:"Find a skill",value:o,onChange:c}),t.jsx(re,{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:[Iy.map(v=>{const w=n.skills.filter(N=>N.group===v.id&&x(N));return w.length?t.jsxs("div",{className:"skills-pick-group",role:"group","aria-label":v.title,children:[t.jsx("div",{className:"skills-pick-group-title",children:v.title}),w.map(N=>t.jsx(kf,{checked:i.includes(N.id),disabled:g(N),onChange:k=>l(k?[...i,N.id]:i.filter(S=>S!==N.id)),title:N.title,sub:N.every?a(N)?"Every agent uses it":Py(N,n.agents):N.home===e.id?"Its own skill, in its folder":N.description},N.id))]},v.id):null}),j?null:t.jsxs("p",{className:"skills-note skills-pick-none",children:["No skill matches “",o.trim(),"”."]})]})]})})}function CC({agents:e,faces:n,upload:s,onClose:r,onSaved:a}){const[i,l]=u.useState((s==null?void 0:s.title)??""),[o,c]=u.useState((s==null?void 0:s.description)??""),[d,h]=u.useState((s==null?void 0:s.body)??""),[f,m]=u.useState([]),[p,x]=u.useState(!1),[g,y]=u.useState(!1),[j,v]=u.useState(null),w=i.trim()!==""&&o.trim()!==""&&d.trim()!=="",N=s?`${Math.max(1,Math.round(s.size/1024))} KB`:"",k=async()=>{y(!0),v(null);try{const{skill:S}=await tn.create({title:i.trim(),description:o.trim(),body:d,agents:f,...s?{upload:{filename:s.name,mine:p}}:{}});a(S)}catch(S){v(Zi(S))}finally{y(!1)}};return t.jsxs(Je,{size:"wide",title:s?t.jsx(jM,{title:s.name,sub:`${N} · read, not saved yet`}):"Write a skill",onClose:r,foot:t.jsxs(se,{align:"end",children:[t.jsx(E,{variant:"ghost",onClick:r,children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:!w||g,onClick:()=>void k(),children:"Save skill"})]}),children:[t.jsx(re,{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:S=>l(S.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:S=>c(S.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:d,onChange:S=>h(S.target.value),spellCheck:!1,placeholder:`1. Total spent this week.
129
+ 2. The three biggest charges.
130
+ 3. Anything odd.`})})]}),t.jsxs(fc,{title:"Who uses it",children:[t.jsx("div",{className:"skills-who",children:e.map(S=>t.jsx(kf,{checked:f.includes(S.id),disabled:!S.writable,onChange:b=>m(b?[...f,S.id]:f.filter(C=>C!==S.id)),lead:t.jsx(Rn,{id:S.id,name:S.name,size:"sm",face:n.find(b=>b.id===S.id)}),title:S.name},S.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:S=>x(S.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 GX({row:e,agents:n,onCancel:s,onDeleted:r}){const a=pe(()=>tn.detail(e.id),[e.id]),[i,l]=u.useState(!1),[o,c]=u.useState(null),d=u.useMemo(()=>a.data?cK(e,a.data.onDelete,n):null,[a.data,e,n]),h=async()=>{l(!0),c(null);try{const f=await tn.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(Zi(f)),l(!1)}};return t.jsxs(zt,{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(re,{message:o??a.error}),t.jsx("p",{className:"skills-dialog-text",children:d??"Checking who uses it…"})]})}function qX(e){var n;return((n=Iy.find(s=>s.id===e.group))==null?void 0:n.title)??""}function YX({agentId:e,agentName:n,faces:s=[],navigate:r}){const a=pe(()=>tn.list(),[e]),[i,l]=u.useState(null),[o,c]=u.useState(null),[d,h]=u.useState(!1),[f,m]=u.useState(null),[p,x]=u.useState(null),g=k=>{m(null),x(k??null),a.reload()},y=k=>{tn.trust(k.id).then(()=>g(),S=>m(S instanceof Error?S.message:String(S)))};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,v=j.agents.find(k=>k.id===e)??{id:e,handle:e,name:n,writable:!1},w=j.skills.filter(k=>nR(k,e)),N=eR();return t.jsxs(t.Fragment,{children:[t.jsx(re,{message:f}),p?t.jsx(q,{tone:"good",role:"status",children:p}):null,t.jsx(rt,{flush:!0,title:"Skills",actions:t.jsxs(t.Fragment,{children:[t.jsxs("a",{className:"skills-all",href:N,onClick:k=>{k.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(ut,{children:w.map(k=>t.jsx(ot,{onClick:()=>l({id:k.id}),label:`${k.title}: details`,lead:t.jsx(Yn,{icon:"files"}),title:k.title,sub:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"skills-line",children:k.description}),t.jsxs("span",{className:"skills-line skills-meta",children:[qX(k)," · ",k.every?"every agent uses it":Ec(k,j.agents,!0)]}),k.untrusted?t.jsx("span",{className:"skills-status","data-tone":"warning",children:My(k,j.agents)}):null]}),side:t.jsx("span",{className:"skills-side",children:k.untrusted?t.jsx(E,{size:"sm",onClick:S=>{S.stopPropagation(),y(k)},children:"Mark as mine"}):t.jsx("span",{className:"skills-chevron","aria-hidden":"true",children:t.jsx(ie,{name:"chevron-right",size:14})})})},k.id))})}):t.jsxs(be,{children:[n," uses no skills yet. Choose some, or write one on the Skills page."]})}),t.jsx(vM,{view:j,faces:s,open:i,setOpen:l,dialog:o,setDialog:c,navigate:r,onChanged:g,onFailed:m}),d?t.jsx(VX,{agent:v,view:j,onCancel:()=>h(!1),onSaved:()=>{h(!1),g()}}):null]})}function yM({timezone:e,embedded:n,agentId:s}){const{data:r,error:a,reload:i}=pe(()=>T.reminders(),[],3e4),l=((r==null?void 0:r.reminders)??[]).filter(h=>!s||h.agentId===s),[o,c]=u.useState(null),d=async h=>{c(null);try{await T.cancelReminder(h),i()}catch(f){c(f instanceof Error?f.message:String(f))}};return t.jsxs(js,{embedded:n,title:"Reminders",lede:"A reminder wakes an agent with a note and the instruction to check before it speaks, never a message queued for delivery.",children:[t.jsx(re,{message:a??o}),t.jsx(rt,{flush:!0,children:r?l.length===0?t.jsx(as,{icon:"bell",title:"No reminders",children:"Ask any agent to remind you of something, and it shows up here."}):t.jsxs(Yr,{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:[ft(h.dueAt,e),t.jsx("div",{className:"sub",children:Ge(h.dueAt)})]}),t.jsx("td",{className:"mono",children:h.agentId}),t.jsxs("td",{children:[h.text,h.context?t.jsx(Kt,{summary:"context",children:t.jsx(_t,{children:rs(h.context)})}):null]}),t.jsxs("td",{children:[t.jsx(Hd,{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:()=>d(h.id),children:"Cancel"}):null})]},h.id))})]}):t.jsx(be,{children:"Loading…"})})]})}const QX=/(flux|klein|schnell|qwen[-_]?image|image)/i;function bM(e){return e.kind==="image"||e.kind===void 0&&QX.test(e.id)}function JX(e){const n=((e==null?void 0:e.models)??[]).filter(s=>!bM(s));return[...n.filter(s=>s.loaded),...n.filter(s=>!s.loaded)].map(s=>s.id)}function rj(e){return JX(e)[0]}function fb(e){return(e==null?void 0:e.detectedContextWindowSource)==="mlxh"}function XX(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 kM(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 NM="an image model; pick it in the Image plugin, not here";function mb({accountId:e,label:n,value:s,onChange:r,disabled:a=!1,origin:i="from the provider",suggest:l,onSuggest:o}){const[c,d]=u.useState(null),[h,f]=u.useState(!1),[m,p]=u.useState(""),[x,g]=u.useState(!1),y=u.useRef(0),j=async b=>{if(!e)return;const C=++y.current;f(!0),p("");try{const $=await T.accountModels(e,b);if(C===y.current){d($);const A=(l==null?void 0:l($))??null;A&&(o==null||o(A))}}catch($){C===y.current&&p($ instanceof Error?$.message:"Could not load models. Custom entry is still available.")}finally{C===y.current&&f(!1)}};if(u.useEffect(()=>(d(null),g(!1),p(""),j(!1),()=>{y.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:b=>r(b.target.value)})}),t.jsx("p",{className:"ui-toolbar-note",children:"Save and connect the account to load its model list. You can enter a model manually now."})]});const v=(c==null?void 0:c.models)??[],w=c&&l?l(c):null,N=!!s&&!v.some(b=>b.id===s),k=[c&&!v.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),S=(c==null?void 0:c.source)==="built-in"?"built-in list":(c==null?void 0:c.source)==="provider"?[i,c.fetchedAt?`refreshed ${O$(c.fetchedAt)}`:""].filter(Boolean).join(" · "):"";return t.jsxs(t.Fragment,{children:[t.jsx(oe,{label:n,children:t.jsxs("select",{value:x?"__buddi_custom__":s,disabled:a,onChange:b=>{b.target.value==="__buddi_custom__"?g(!0):(g(!1),r(b.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":"",")"]}),v.map(b=>t.jsxs("option",{value:b.id,children:[b.name===b.id?b.id:`${b.name} — ${b.id}`,b.id===w?" (suggested)":b.isDefault?" (provider default)":"",b.image?` — ${NM}`:""]},b.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"}),x&&t.jsx(oe,{label:`Custom ${n.toLowerCase()}`,children:t.jsx("input",{required:!0,maxLength:150,value:s,disabled:a,onChange:b=>r(b.target.value)})}),m&&t.jsx("p",{role:"alert",className:"ui-toolbar-note critical",children:m}),k.length>0&&t.jsx("p",{className:"ui-toolbar-note",children:k.join(" ")}),S&&t.jsx("p",{className:"ui-toolbar-note muted","data-testid":"model-list-source",children:S})]})}function ZX(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 eZ(e,n){return[...e].sort().join(",")===[...n].sort().join(",")}const tZ="This agent will not remember anything between conversations.";function nZ({view:e,chosen:n,onChange:s,disabled:r}){var k;const[a,i]=u.useState(""),[l,o]=u.useState(null),[c,d]=u.useState(()=>new Set),h=S=>d(b=>{const C=new Set(b);return C.has(S)?C.delete(S):C.add(S),C}),f=S=>{i(S),d(new Set)},m=u.useId(),p=new Set(n),x=new Set(e.groups.flatMap(S=>S.tools.filter(b=>b.core).map(b=>b.name))),g=(S,b)=>{const C=b.filter($=>p.has($));if(C.length!==0){if(C.some($=>x.has($))){o({plugin:S,names:C});return}s(n.filter($=>!C.includes($)))}},y=S=>{s([...n,...S.filter(b=>!p.has(b))])},j=a.trim().toLowerCase(),v=(S,b)=>j===""||S.toLowerCase().includes(j)||b.toLowerCase().includes(j),w=e.groups.map(S=>({group:S,tools:S.tools.filter(b=>v(b.name,b.description))})).filter(S=>S.tools.length>0),N=(((k=e.suggested)==null?void 0:k.tools)??[]).filter(S=>!p.has(S.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(S=>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:S.name}),t.jsx("span",{className:"ui-list-sub",children:S.description})]}),t.jsx(E,{size:"sm",disabled:r,"aria-label":`Add ${S.name}`,onClick:()=>y([S.name]),children:"Add"})]},S.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:S=>f(S.target.value)})]}),w.length===0?t.jsxs(be,{children:["No installed tool matches “",a.trim(),"”."]}):null,w.map(({group:S,tools:b})=>{const C=S.tools.filter(R=>R.grantable).map(R=>R.name),$=S.tools.filter(R=>p.has(R.name)).length,A=!!S.glob&&$===S.tools.length,I=`${m}-${S.plugin}`,M=`${m}-${S.plugin}-list`,O=j!==""?!c.has(S.plugin):c.has(S.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":M,onClick:()=>h(S.plugin),children:[t.jsx(sZ,{}),t.jsx("span",{id:I,className:"tool-picker-plugin",children:S.plugin}),t.jsx("span",{className:"muted",children:A?`all ${S.tools.length}`:`${$} of ${S.tools.length} granted`})]}),t.jsx(E,{size:"sm",variant:"ghost","aria-label":`All ${S.plugin} tools`,disabled:r||C.every(R=>p.has(R)),onClick:()=>y(C),children:"all"}),t.jsx(E,{size:"sm",variant:"ghost","aria-label":`No ${S.plugin} tools`,disabled:r||!C.some(R=>p.has(R)),onClick:()=>g(S.plugin,C),children:"none"})]}),(l==null?void 0:l.plugin)===S.plugin?t.jsx(q,{tone:"warning",role:"alert",children:t.jsxs("div",{className:"tool-picker-confirm",children:[t.jsx("span",{children:tZ}),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:M,className:"ui-list tool-picker-list",hidden:!O,children:b.map(R=>{const _=`${m}-${R.name}`;return t.jsxs("li",{className:"ui-list-row",children:[t.jsx("input",{type:"checkbox",id:_,checked:p.has(R.name),disabled:r||!R.grantable,onChange:z=>z.target.checked?y([R.name]):g(S.plugin,[R.name])}),t.jsxs("label",{htmlFor:_,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(Ce,{tone:"accent",children:"core"}):null,R.gated?t.jsx(Ce,{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)})})]},S.plugin)})]})}function sZ(){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 Bs={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."},za=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function SM(e){let n;try{n=JSON.parse(e.trim())}catch{throw new Error(Bs.json)}if(!za(n))throw new Error(Bs.json);let s,r=n;if("mcpServers"in n){const d=n.mcpServers;if(!za(d))throw new Error(Bs.empty);const h=Object.keys(d);if(h.length===0)throw new Error(Bs.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=d[s];if(!za(f))throw new Error(Bs.url);r=f}if("command"in r)throw new Error(Bs.command);if(typeof r.type=="string"&&r.type.toLowerCase()==="sse")throw new Error(Bs.sse);const a=typeof r.url=="string"?r.url.trim():"";if(a==="")throw new Error(Bs.url);const i=za(r.headers)?Object.entries(r.headers).filter(d=>typeof d[1]=="string"&&d[0].trim()!==""):[],l=i.find(([d])=>d.toLowerCase()==="authorization")??i[0];let o,c=!1;if(l){const[d,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:d.trim(),prefix:m,value:p}}return{url:a,...s?{name:s}:{},...o?{header:o}:{},dropped:i.filter(d=>d!==l).map(([d])=>d),placeholder:c}}const Ic={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 CM(e){return/TOKEN|KEY|SECRET|PASSWORD|PASSWD|CREDENTIAL|AUTH/i.test(e)}const EM=/^[A-Za-z_][A-Za-z0-9_]*$/;function rZ(e){return/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$|^your[_-]/i.test(e.trim())}function AM(e,n){const s=rZ(n);return{name:e,value:s?"":n,secret:CM(e),placeholder:s}}function $M(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(Ic.quote);return r&&n.push(s),n}function aZ(e){const n=$M(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(!EM.test(m))throw new Error(Ic.env);r.push(AM(m,h.slice(f+1)))},d=[];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(Ic.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}d.push(h)}}if(o===void 0?o=d:d.length>0&&(o=[...d,...o]),i==="http"||i==="sse"||o.length===1&&/^https?:\/\//i.test(o[0])){const h=o[0];if(!h)throw new Error(Bs.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:SM(JSON.stringify({mcpServers:{[l??"server"]:{type:i,url:h,headers:f}}}))}}if(!l||o.length===0)throw new Error(Ic.claude);return{kind:"program",program:{name:l,command:o[0],args:o.slice(1),env:r}}}function iZ(e){const n=e.trim();if(/^claude\s+mcp\s+add\b/.test(n))return aZ(n);let s;try{s=JSON.parse(n)}catch{throw new Error(Bs.json)}if(!za(s))throw new Error(Bs.json);let r,a=s;if("mcpServers"in s){const c=s.mcpServers;if(!za(c))throw new Error(Bs.empty);const d=Object.keys(c);d.length===1&&za(c[d[0]])&&(r=d[0],a=c[r])}if(!("command"in a))return{kind:"remote",config:SM(n)};const i=typeof a.command=="string"?a.command.trim():"";if(i==="")throw new Error(Ic.command);const l=Array.isArray(a.args)?a.args.map(c=>String(c)):[],o=za(a.env)?Object.entries(a.env).filter(([c])=>EM.test(c)).map(([c,d])=>AM(c,String(d??""))):[];return{kind:"program",program:{...r?{name:r}:{},command:i,args:l,env:o}}}function pb({code:e,label:n="Your code",large:s=!1}){const[r,a]=u.useState(!1),i=async()=>{var l;try{await((l=navigator.clipboard)==null?void 0:l.writeText(e)),a(!0)}catch{}};return t.jsxs(se,{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 TM(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 lZ="It can delete or destroy something, so it asks you every time and is never remembered.";function oZ(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 IM="buddi-connections",cZ="/connections/callback",dZ="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.",RM="Services and programs your team can use, and the tools each one brings.",gb=(e,n,s)=>`${e} ${e===1?n:s}`;function EC(e,n){return e.transport==="stdio"?void 0:n.find(s=>vb(s.url,e.url))}function xb({connection:e,card:n,size:s}){return n?t.jsx(Yn,{letter:n.name.slice(0,1).toUpperCase(),size:s}):t.jsx(Yn,{icon:(e==null?void 0:e.transport)==="stdio"?"terminal":"globe",size:s})}function PM({connection:e}){const n=TM(e);return t.jsx(Ce,{tone:n.tone,dot:n.dot,children:n.label})}const pg=e=>n=>{n.stopPropagation(),e()},mh=[{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"}],MM="buddi.connections.add-way";function uZ(){try{const e=window.localStorage.getItem(MM);return mh.some(n=>n.value===e)?e:"address"}catch{return"address"}}function hZ({embedded:e,timezone:n,connection:s}={}){const r=pe(()=>T.connections(),[],3e4),[a,i]=u.useState(null),[l,o]=u.useState(s??null);u.useEffect(()=>{s&&o(s)},[s]);const[c,d]=u.useState(null),[h,f]=u.useState(null),m=r.data,p=S=>{var b;return((b=m==null?void 0:m.agents.find(C=>C.id===S))==null?void 0:b.name)??S},x=n??Intl.DateTimeFormat().resolvedOptions().timeZone,g=(m==null?void 0:m.connections)??[],y=(m==null?void 0:m.catalog)??[],j=y.filter(S=>!g.some(b=>b.transport!=="stdio"&&vb(S.url,b.url))),v=l?g.find(S=>S.id===l):void 0,w=c?g.find(S=>S.id===c):void 0,N=h?g.find(S=>S.id===h):void 0,k=S=>{o(null),i(S)};return t.jsxs(js,{embedded:e,title:"Connections",lede:RM,children:[t.jsxs(de,{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:ze("plugins"),children:"Plugins"})]})]}),!m&&!r.error?t.jsx(be,{children:"Reading your connections…"}):null,t.jsx(re,{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(rt,{flush:!0,title:"Your connections",tool:g.length>0?gb(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(ut,{children:g.map(S=>t.jsx(fZ,{connection:S,card:EC(S,y),twin:S.slug!==null&&g.some(b=>b.id!==S.id&&b.name===S.name),onOpen:()=>o(S.id),onFlow:k},S.id))})})}):null,m&&j.length>0?t.jsx(rt,{title:"Connect a service",children:t.jsx("div",{className:"connections-tiles",children:j.map(S=>t.jsxs("div",{className:"connections-tile",children:[t.jsx(xb,{card:S}),t.jsxs("span",{className:"connections-tile-main",children:[t.jsx("span",{className:"connections-tile-name",children:S.name}),t.jsx("span",{className:"connections-tile-blurb",children:S.blurb})]}),t.jsx(E,{size:"sm",onClick:()=>k({step:"address",card:S}),"aria-label":`Connect ${S.name}`,children:"Connect"})]},S.id))})}):null,m?t.jsx(vZ,{onFlow:S=>k({step:S})}):null]}),v?t.jsx(pZ,{connection:v,card:EC(v,y),agentName:p,timezone:x,onClose:()=>o(null),onFlow:k,onDisconnect:()=>d(v.id),onHolders:()=>f(v.id)}):null,N&&m?t.jsx(gZ,{connection:N,agents:m.agents,onCancel:()=>f(null),onDone:()=>{f(null),r.reload()}},N.id):null,w?t.jsx(xZ,{connection:w,agentName:p,onCancel:()=>d(null),onDone:()=>{d(null),o(null),r.reload()}},w.id):null,a&&m?t.jsx(jZ,{start:a,agents:m.agents,catalog:m.catalog,tokens:m.tokens??m.vault,onClose:()=>{i(null),r.reload()}}):null]})}function fZ({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,d=i?"its tools are not reviewed yet":gb(e.toolCount,"tool","tools");return t.jsx(ot,{onClick:r,label:`${l}: details`,lead:t.jsx(xb,{connection:e,card:n}),title:l,sub:t.jsx("span",{className:"connections-sub","data-kind":o?"program":void 0,children:`${c} · ${d}`}),side:t.jsxs("span",{className:"plugins-side",children:[i?t.jsx("span",{className:"connections-act",children:t.jsx(E,{size:"sm",variant:"accent",onClick:pg(()=>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:pg(()=>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:pg(()=>a({step:"review",connection:e,keepGrants:!0})),children:"Review"})}):null,t.jsx(PM,{connection:e}),t.jsx(ie,{name:"chevron-right",size:14})]})})}const mZ={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 pZ({connection:e,card:n,agentName:s,timezone:r,onClose:a,onFlow:i,onHolders:l,onDisconnect:o}){const c=e.state==="pending-review",d=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(xb,{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:[d?"A program on this computer":"A service at an address"," · ",t.jsx(PM,{connection:e})]})]})]}),onClose:a,foot:t.jsxs(se,{children:[t.jsx(E,{variant:"danger-ghost",onClick:o,children:"Disconnect…"}),t.jsx(gt,{}),d?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:d?`It stopped answering at ${ft(e.unreachableSince,r)}; the next call starts it again.`:`Unreachable since ${ft(e.unreachableSince,r)}, retrying.`}):null,d!=null&&d.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(Qt,{items:[d?{label:"Command",value:t.jsx("span",{className:"connections-line",children:d.line})}:{label:"Address",value:t.jsx("span",{className:"connections-line",children:e.url})},...d?[{label:"Runs",value:"On this computer as you, with your PATH and only the variables you named. It stops after ten quiet minutes."}]:[],...d&&d.env.length>0?[{label:"Variables",value:t.jsx("span",{className:"mono",children:d.env.map(p=>`${p.name}${p.secret?" (secret)":""}`).join(", ")})}]:[],...d?[]:[{label:"Signs in with",value:mZ[e.authKind]}],{label:"Tools",value:c?"Not reviewed yet":`${gb(e.toolCount,"tool","tools")}${e.reviewedAt?` · reviewed ${Ge(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(ge,{title:"What the program last said",children:t.jsx(_t,{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 gZ({connection:e,agents:n,onCancel:s,onDone:r}){const[a,i]=u.useState(()=>new Set(e.agents)),[l,o]=u.useState(!1),[c,d]=u.useState(null),h=(p,x)=>i(g=>{const y=new Set(g);return x?y.add(p):y.delete(p),y}),f=a.size===e.agents.length&&e.agents.every(p=>a.has(p)),m=async()=>{o(!0),d(null);try{const p=await T.grantConnection(e.id,[...a],!0);p.failed.length>0?d(p.failed.map(x=>`${x.agent}: ${x.message}`).join("; ")):r()}catch(p){d(yr(p))}finally{o(!1)}};return t.jsxs(zt,{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:x=>h(p.id,x.target.checked)}),t.jsxs("span",{children:[p.name,p.frontDesk?" (front desk)":""]})]},p.id))}),t.jsx(re,{message:c})]})}function xZ({connection:e,agentName:n,onCancel:s,onDone:r}){const[a,i]=u.useState(!1),[l,o]=u.useState(null),c=e.agents.map(n),d=async()=>{i(!0),o(null);try{await T.disconnect(e.id),r()}catch(h){o(yr(h))}finally{i(!1)}};return t.jsxs(zt,{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 d(),children:"Disconnect"})]}),children:[t.jsxs("p",{className:"plugins-dialog-text",children:["buddi forgets its sign-in and its tools."," ",c.length>0?`${c.join(" and ")} ${c.length===1?"loses":"lose"} them.`:"No agent holds its tools."]}),t.jsx(re,{message:l})]})}function vZ({onFlow:e}){const[n,s]=u.useState(uZ),r=mh.find(i=>i.value===n)??mh[0],a=i=>{s(i);try{window.localStorage.setItem(MM,i)}catch{}};return t.jsx(rt,{title:"Add your own",actions:t.jsx(Jt,{label:"How to add it",options:mh.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 jZ({start:e,agents:n,catalog:s=[],tokens:r=!0,onClose:a,pollMs:i=2e3}){const[l,o]=u.useState(e.step),[c,d]=u.useState(e.connection),[h,f]=u.useState("unknown"),[m,p]=u.useState(null),[x,g]=u.useState(null),y=(m==null?void 0:m.url)??(c==null?void 0:c.url),j=e.card??s.find(N=>y!==void 0&&vb(N.url,y)),v=(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 ${v}`:l==="review"?`What ${v} brings`:"Who gets these tools";return t.jsxs(Je,{title:w,onClose:a,size:"wide",children:[l==="paste"?t.jsx(wZ,{onRead:N=>{N.kind==="program"?(g(N.program),o("program")):(p(N.config),o("address"))}}):null,l==="address"?t.jsx(yZ,{card:j,pasted:m,onDone:(N,k)=>{d(N),k==="none"?o("review"):(f(k),o("consent"))}}):null,l==="program"?t.jsx($Z,{connection:c,pasted:x,tokens:r,onDone:N=>{var k;g(null),d(N),e.keepGrants&&!((k=N.program)!=null&&k.changedSinceReview)&&N.state!=="pending-review"?a():o("review")}}):null,l==="consent"&&c?t.jsx(NZ,{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),d(N),e.keepGrants?a():o("review")}}):null,l==="review"&&c?t.jsx(TZ,{connection:c,onKept:N=>{d(N),e.keepGrants?a():o("grant")}}):null,l==="grant"&&c?t.jsx(IZ,{connection:c,agents:n,onDone:a}):null]})}function vb(e,n){const s=r=>r.trim().replace(/\/+$/,"").toLowerCase();return s(e)===s(n)}function yr(e){return e instanceof Error?e.message:String(e)}function wZ({onRead:e}){const[n,s]=u.useState(""),[r,a]=u.useState(null),i=()=>{try{const l=iZ(n);s(""),a(null),e(l)}catch(l){a(yr(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(re,{message:r}),t.jsx(se,{align:"end",children:t.jsx(E,{type:"submit",variant:"accent",disabled:n.trim()==="",children:"Read it"})})]})}function yZ({card:e,pasted:n,onDone:s}){var m,p;const[r,a]=u.useState((n==null?void 0:n.url)??(e==null?void 0:e.url)??""),[i,l]=u.useState(!1),[o,c]=u.useState(null),d=async()=>{l(!0),c(null);try{const x=await T.addConnection(r.trim(),(e==null?void 0:e.name)??(n==null?void 0:n.name));s(x.connection,x.signIn)}catch(x){c(yr(x))}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:x=>{x.preventDefault(),d()},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:x=>a(x.target.value)})}),e&&!e.verified?t.jsxs("p",{className:"ui-card-meta",children:["This address is the one ",e.name," published; buddi has not checked it since."]}):null,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(re,{message:o}),t.jsx(se,{align:"end",children:t.jsx(E,{type:"submit",variant:"accent",disabled:i||r.trim()==="",children:i?"Opening…":"Continue"})})]})}const bZ={device:"Device",oauth:"Sign in",token:"Token",client:"Client id"};function kZ(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 NZ({connection:e,signIn:n,card:s,pasted:r,placeholder:a,tokens:i,pollMs:l,onSignedIn:o}){var W,L;const[c,d]=u.useState(n),h=(W=s==null?void 0:s.auth)!=null&&W.device?s.auth.recommended==="device"?"first":"offered":"none",f=kZ(c,i,h),m=r!==void 0||h!=="first"&&(e.authKind==="token"||((L=s==null?void 0:s.auth)==null?void 0:L.recommended)==="token"),[p,x]=u.useState(()=>m&&f.includes("token")?"token":f[0]),g=f.includes(p)?p:f[0],[y,j]=u.useState(dZ),[v,w]=u.useState(""),[N,k]=u.useState(null),[S,b]=u.useState(!1),[C,$]=u.useState(null),[A,I]=u.useState(!1),[M,O]=u.useState(null),R=`${location.origin}${cZ}`,_=u.useRef(o);_.current=o,u.useEffect(()=>{if(!A)return;let Q=!1;const F=async()=>{if(!Q){Q=!0;try{_.current(await T.connection(e.id))}catch(X){$(yr(X))}}},ae=typeof BroadcastChannel=="function"?new BroadcastChannel(IM):null;ae&&(ae.onmessage=X=>{var G;((G=X.data)==null?void 0:G.id)===e.id&&F()});let V;const J=Date.now(),H=async()=>{if(!Q){try{const X=await T.connection(e.id);if((!e.signedIn||e.authKind==="token")&&X.signedIn&&X.authKind==="oauth"){F();return}}catch{}if(Date.now()-J>10*6e4){I(!1),$("The sign-in did not come back within ten minutes. Start it again.");return}V=window.setTimeout(()=>void H(),l)}};return V=window.setTimeout(()=>void H(),l),()=>{Q=!0,ae==null||ae.close(),window.clearTimeout(V)}},[A,e,l]);const z=async Q=>{var F;b(!0),$(null);try{const{authorizeUrl:ae}=await T.connectionConsent(e.id,Q);k(ae)}catch(ae){ae instanceof fe&&((F=ae.detail)==null?void 0:F.code)==="client-id"?(j(ae.message),d("manual"),x("client")):$(yr(ae))}finally{b(!1)}};u.useEffect(()=>{g!=="oauth"||N!==null||z()},[g]);const U=Q=>{const F=window.open(Q,"_blank");F?(F.opener=null,O(null)):O(Q),I(!0)},P=Q=>{x(Q),k(null),$(null),I(!1),O(null)};return t.jsxs("div",{className:"ui-stack",children:[f.length>1?t.jsx(Jt,{label:"How to sign in",options:f.map(Q=>({value:Q,label:bZ[Q]})),value:g,onChange:P}):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."]}),S?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:y}),t.jsx(oe,{label:"Client id",children:t.jsx("input",{required:!0,spellCheck:!1,value:v,onChange:Q=>{w(Q.target.value),k(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(EZ,{connection:e,card:s,pasted:r,placeholder:a,onSignedIn:o}):null,g==="device"?t.jsx(CZ,{connection:e,service:(s==null?void 0:s.name)??e.name,pollMs:l,onSignedIn:o}):null,(g==="oauth"||g==="client")&&A?t.jsxs(q,{tone:"accent",role:"status",children:["Waiting for you to say yes on ",e.name,"’s page…"]}):null,(g==="oauth"||g==="client")&&M?t.jsx("p",{children:t.jsxs("a",{href:M,target:"_blank",rel:"noopener noreferrer",children:["Open ",e.name,"’s sign-in page"]})}):null,g==="oauth"||g==="client"?t.jsx(re,{message:C}):null,g==="oauth"?t.jsx(se,{align:"end",children:t.jsx(E,{variant:"accent",onClick:()=>{N&&U(N)},disabled:N===null,children:A?"Open it again":`Sign in to ${e.name}`})}):null,g==="client"?t.jsx(se,{align:"end",children:N===null?t.jsx(E,{variant:"accent",onClick:()=>void z(v.trim()),disabled:S||v.trim()==="",children:S?"Checking…":"Continue"}):t.jsx(E,{variant:"accent",onClick:()=>U(N),children:A?"Open it again":`Open ${e.name}’s sign-in page`})}):null]})}function SZ(e){try{const n=new URL(e);return`${n.host}${n.pathname==="/"?"":n.pathname.replace(/\/$/,"")}`}catch{return e}}function CZ({connection:e,service:n,pollMs:s,onSignedIn:r}){const[a,i]=u.useState(null),[l,o]=u.useState(null),[c,d]=u.useState(0),[h,f]=u.useState(null),[m,p]=u.useState(!1),x=u.useRef(r);x.current=r,u.useEffect(()=>{let j=!1,v;i(null),o(null),f(null),p(!1);const w=async()=>{var N,k;if(!j){try{const S=await T.connection(e.id);if(j)return;if(((N=S.device)==null?void 0:N.state)==="done"){x.current(S);return}if(((k=S.device)==null?void 0:k.state)==="failed"){o(S.device.reason??"The sign-in did not finish. Start again.");return}}catch{}v=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}),v=window.setTimeout(()=>void w(),s)}catch(N){j||o(yr(N))}})(),()=>{j=!0,window.clearTimeout(v)}},[e.id,s,c]);const g=j=>{const v=window.open(j,"_blank");p(!0),v?(v.opener=null,f(null)):f(j)},y=a?SZ(a.verificationUri):"";return t.jsxs(t.Fragment,{children:[t.jsxs("p",{children:[a?`Open ${y}, 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(pb,{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 ",y]})}):null,t.jsx(se,{align:"end",children:t.jsxs(E,{variant:"accent",onClick:()=>g(a.verificationUri),children:["Open ",y]})})]}):null,l!==null?t.jsxs(t.Fragment,{children:[t.jsx(re,{message:l}),t.jsx(se,{align:"end",children:t.jsx(E,{variant:"accent",onClick:()=>d(j=>j+1),children:"Start again"})})]}):null]})}function EZ({connection:e,card:n,pasted:s,placeholder:r,onSignedIn:a}){var j,v;const[i,l]=u.useState((s==null?void 0:s.value)??""),[o,c]=u.useState((s==null?void 0:s.name)??"Authorization"),[d,h]=u.useState((s==null?void 0:s.prefix)??(s?"":"Bearer ")),[f,m]=u.useState(!1),[p,x]=u.useState(null),g=async()=>{m(!0),x(null);try{const w=await T.connectionToken(e.id,{token:i.trim(),header:o.trim(),prefix:d});l(""),a(w.connection)}catch(w){x(yr(w))}finally{m(!1)}},y=(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:[y?`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."]}),y?t.jsx("p",{children:t.jsxs("a",{href:y,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:(v=n==null?void 0:n.auth)==null?void 0:v.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(Ts,{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:d,onChange:w=>h(w.target.value)})})]}),t.jsx(re,{message:p}),t.jsx(se,{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 AZ(e){return e!==""&&/^[A-Za-z0-9_@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function $Z({connection:e,pasted:n,tokens:s=!0,onDone:r}){const a=e==null?void 0:e.program,i=u.useRef(0),l=()=>(i.current+=1,i.current),[o,c]=u.useState((e==null?void 0:e.name)??(n==null?void 0:n.name)??""),[d,h]=u.useState((a==null?void 0:a.command)??(n==null?void 0:n.command)??""),[f,m]=u.useState(()=>((a==null?void 0:a.args)??(n==null?void 0:n.args)??[]).map(R=>({key:l(),value:R}))),[p,x]=u.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,y]=u.useState(!1),[j,v]=u.useState(null),w=/\s/.test(d.trim())?$M(d.trim()):[d.trim()],N=w[0]??"",k=[...w.slice(1),...f.map(R=>R.value)],S=[N,...k].filter((R,_)=>_>0||R!==""),b=()=>{w.length<2||(h(N),m(R=>[...w.slice(1).map(_=>({key:l(),value:_})),...R]))},C=S.map(AZ).join(" "),$=p.filter(R=>R.secret&&R.value===""&&!R.kept).map(R=>R.name||"a variable"),A=((n==null?void 0:n.env)??[]).filter(R=>R.placeholder).map(R=>R.name),I=(R,_)=>m(z=>z.map(U=>U.key===R?{...U,value:_}:U)),M=(R,_)=>x(z=>z.map(U=>U.key===R?{...U,..._}:U)),O=async()=>{y(!0),v(null);const R={name:o.trim(),command:N,args:k,env:p.filter(_=>_.name.trim()!=="").map(_=>({name:_.name.trim(),value:_.value,secret:_.secret}))};try{r(e?await T.updateProgram(e.id,R):(await T.addProgram(R)).connection),x(_=>_.map(z=>z.secret?{...z,value:""}:z))}catch(_){v(yr(_))}finally{y(!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(Ts,{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:d,placeholder:"npx",onChange:R=>h(R.target.value),onBlur:b})})]}),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,_)=>t.jsxs("div",{className:"connections-row",children:[t.jsx("input",{"aria-label":`Argument ${_+1}`,className:"mono",spellCheck:!1,autoComplete:"off",value:R.value,onChange:z=>I(R.key,z.target.value)}),t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>m(z=>z.filter(U=>U.key!==R.key)),"aria-label":`Remove argument ${_+1}`,children:"Remove"})]},R.key)),t.jsx(se,{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,_)=>t.jsxs("div",{className:"connections-row","data-kind":"env",children:[t.jsx("input",{"aria-label":`Variable ${_+1} name`,className:"mono",spellCheck:!1,autoComplete:"off",placeholder:"NAME",value:R.name,onChange:z=>{const U=z.target.value;M(R.key,R.value===""&&!R.kept?{name:U,secret:CM(U)}:{name:U})}}),t.jsx("input",{"aria-label":`Variable ${_+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:z=>M(R.key,{value:z.target.value})}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:R.secret,onChange:z=>M(R.key,{secret:z.target.checked,kept:z.target.checked&&R.kept})}),t.jsx("span",{children:"Secret"})]}),t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>x(z=>z.filter(U=>U.key!==R.key)),"aria-label":`Remove variable ${_+1}`,children:"Remove"})]},R.key)),t.jsx(se,{children:t.jsx(E,{size:"sm",onClick:()=>x(R=>[...R,{key:l(),name:"",value:"",secret:!1,kept:!1}]),children:"Add a variable"})})]})}),A.length>0?t.jsxs(q,{tone:"accent",children:["Your config had a placeholder for ",A.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(_t,{label:"The command line",children:C||"…"})]}),t.jsx(re,{message:j}),t.jsx(se,{align:"end",children:t.jsx(E,{type:"submit",variant:"accent",disabled:g||o.trim()===""||d.trim()===""||$.length>0,title:$.length>0?`Give ${$.join(", ")} a value.`:void 0,children:g?"Saving…":e?"Save":"Continue"})})]})}function TZ({connection:e,onKept:n}){const s=pe(()=>T.connectionReview(e.id),[e.id]),[r,a]=u.useState(null),[i,l]=u.useState(!1),[o,c]=u.useState(null),d=s.data,h=r??(d==null?void 0:d.slug)??"",f=async()=>{var p;if(d){l(!0),c(null);try{n(await T.saveConnectionReview(e.id,{hash:d.hash,...d.slugEditable?{slug:h}:{}}))}catch(x){x instanceof fe&&((p=x.detail)==null?void 0:p.code)==="changed"&&s.reload(),c(yr(x))}finally{l(!1)}}};if(!d)return s.error?t.jsx(re,{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=d.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."]}),d.program?t.jsx(q,{tone:"warning",title:"This runs on this computer as you",children:t.jsxs(de,{gap:"sm",children:[t.jsx(_t,{label:"The command",children:d.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."}),d.program.env.length>0?t.jsxs("p",{className:"ui-card-meta",children:["Variables: ",d.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:d.host})," for these tools, and nowhere else."]}),d.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,d.changes&&d.changes.added.length+d.changes.changed.length+d.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:[d.changes.added.length>0?t.jsxs("li",{children:["New: ",t.jsx("span",{className:"mono",children:d.changes.added.join(", ")})]}):null,d.changes.changed.length>0?t.jsxs("li",{children:["Changed: ",t.jsx("span",{className:"mono",children:d.changes.changed.join(", ")})]}):null,d.changes.removed.length>0?t.jsxs("li",{children:["Gone: ",t.jsx("span",{className:"mono",children:d.changes.removed.join(", ")})]}):null]}),t.jsx("p",{children:"Until you keep this list, the new and changed tools wait; the others keep working."})]}):null,d.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,d.tools.length===0?t.jsxs(be,{children:[e.name," lists no tools."]}):t.jsx("div",{className:"ui-list","aria-label":"Tools",children:d.tools.map(p=>{const x=oZ(p),g=d.slugEditable?p.fullName.replace(/^mcp\.[^.]+\./,`mcp.${h||d.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(Ce,{tone:"muted",children:"Cannot be used"}):t.jsx(Ce,{tone:x.tone,children:x.label}),p.change==="added"?t.jsx(lo,{children:"New"}):p.change==="changed"?t.jsx(lo,{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?lZ:"You can remember its approval for an agent when you give it the tools, or later on the agent’s Tools tab."}):null,p.problem?t.jsxs("p",{className:"ui-card-meta",children:["Left out: ",p.problem,"."]}):null]})},p.name)})}),t.jsx(re,{message:o}),t.jsx(se,{align:"end",children:t.jsx(E,{variant:"accent",onClick:()=>void f(),disabled:i||d.slugEditable&&h.trim()==="",children:m===1?"Keep this tool":`Keep these ${m} tools`})})]})}function IZ({connection:e,agents:n,onDone:s}){var y;const r=n.find(j=>j.frontDesk)??n[0],[a,i]=u.useState(()=>new Set(r?[r.id]:[])),o=(((y=pe(()=>T.connectionTools(e.id),[e.id]).data)==null?void 0:y.tools)??[]).filter(j=>j.tier==="gated"),[c,d]=u.useState(()=>new Set),[h,f]=u.useState(!1),[m,p]=u.useState(null),x=(j,v)=>{i(w=>{const N=new Set(w);return v?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(v=>`${v.agent}: ${v.message}`).join(" "));return}for(const v of j.granted)for(const w of c)await T.setRememberedApproval(v,w,!0);s()}catch(j){p(yr(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:v=>x(j.id,v.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(de,{gap:"sm",children:[t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",disabled:!j.rememberable,checked:c.has(j.tool),onChange:v=>d(w=>{const N=new Set(w);return v.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(re,{message:m}),t.jsxs(se,{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 RZ=(e,n,s)=>`${e} ${e===1?n:s}`;function PZ(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 MZ({agentId:e,agentName:n,readOnly:s,version:r,onSaved:a}){const[i,l]=u.useState({}),o=pe(()=>T.connections().then(w=>(l({}),w)),[r]),[c,d]=u.useState(null),[h,f]=u.useState(null),m=ze("connections"),p=async(w,N)=>{d(w.id),f(null);try{const k=await T.setConnectionHolder(w.id,e,N);l(S=>({...S,[w.id]:k.held})),a==null||a()}catch(k){f(k instanceof Error?k.message:String(k))}finally{d(null)}},x=o.data,g=(x==null?void 0:x.connections)??[],y=w=>i[w.id]??w.agents.includes(e),j=x?x.agents.some(w=>w.id===e):!0,v=g.filter(y).length;return t.jsxs(ge,{title:"Connections",aside:x&&g.length>0?`holds ${v} of ${g.length} · saved as you change them`:void 0,panel:!0,children:[t.jsx(re,{message:o.error??h}),x?g.length===0?t.jsxs("p",{className:"ui-card-meta",children:["Nothing is connected yet. ",t.jsx("a",{href: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=y(w),k=PZ(w),S=w.transport==="stdio"?"on this computer":w.host,b=w.slug?RZ(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||k!==null&&!N,onChange:$=>void p(w,$.target.checked)}),t.jsxs("label",{htmlFor:C,className:"ui-list-main",children:[t.jsxs("span",{className:"ui-list-title",children:[w.name,k?t.jsxs(t.Fragment,{children:[" ",t.jsx(Ce,{tone:"warning",children:TM(w).label})]}):null]}),t.jsx("span",{className:"ui-list-sub",children:`${S} · ${b}`}),k?t.jsxs("span",{className:"ui-list-sub",children:[k," ",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 OZ=(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 OM(e){const n=await fetch(gi(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 DZ({face:e,onPick:n,label:s=D.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,UB.map(o=>{const c={kind:"mascot",role:o},d=OZ(e,c);return t.jsx("button",{type:"button",className:"meet-face","data-kind":"image","data-chosen":d?"true":void 0,"aria-pressed":d,"aria-label":D.assistant.mascot(o),disabled:a,onClick:()=>n(c),children:t.jsx("img",{src:gi(o),alt:""})},o)})]}),t.jsx("div",{className:"meet-face-row",children:WB.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 LZ=["mirror","en","fr"],FZ=[{value:"3h",label:"3 hours"},{value:"1d",label:"A day"},{value:"1w",label:"A week"},{value:"never",label:"Never"}],gg=10,xg=500,DM=[{id:"identity",label:"Identity"},{id:"brain",label:"Brain"},{id:"tools",label:"Tools"},{id:"team",label:"Team"}],AC=e=>{var n;return e==="access"?"tools":((n=DM.find(s=>s.id===e))==null?void 0:n.id)??"identity"};function _Z({agentId:e,section:n,navigate:s}){var g,y,j;const{data:r,error:a,reload:i}=pe(()=>T.agents(),[]),[l,o]=u.useState(null),[c,d]=u.useState(null),[h,f]=u.useState(AC(n));u.useEffect(()=>f(AC(n)),[n]);const m=v=>{f(v),s==null||s(Pt(e,"setup",v))},p=async v=>{o(null),d(null);try{const w=await v;d(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))}},x=r==null?void 0:r.agents.find(v=>v.id===e);return t.jsxs(de,{gap:"lg",children:[t.jsx(Ro,{level:"secondary",label:"Setup",children:DM.map(v=>t.jsx(Ji,{href:Pt(e,"setup",v.id),active:h===v.id,onClick:w=>{w.preventDefault(),m(v.id)},children:v.label},v.id))}),t.jsx(re,{message:a??l}),c?t.jsx(q,{tone:"good",role:"status",children:c}):null,r?x?t.jsx(zZ,{agent:x,all:r.agents,engine:r.engines.find(v=>v.id===x.id),providers:r.providers,accounts:r.providerAccounts,shown:h,onShow:m,onRun:p,onSaved:i},`${x.id}:${(g=r.engines.find(v=>v.id===x.id))==null?void 0:g.model}:${(j=(y=r.providerAccounts)==null?void 0:y.bindings.find(v=>v.agentId===x.id))==null?void 0:j.accountId}`):t.jsx(be,{children:"This agent is not installed as a file."}):t.jsx(be,{children:"Loading…"})]})}function zZ({agent:e,all:n,engine:s,providers:r,accounts:a,shown:i,onShow:l,onRun:o,onSaved:c}){const d=(s==null?void 0:s.provider)??e.provider.kind,h=r.find(S=>S.kind===d),f=(s==null?void 0:s.model)??e.model,[m,p]=u.useState(String((s==null?void 0:s.maxTurns)??e.maxTurns)),[x,g]=u.useState(null),y=S=>{o(T.setAgentEngine(e.id,S))},j=S=>{const b=r.find(C=>C.kind===S);y({provider:S,model:(b==null?void 0:b.defaultModel)??f})},v=(h==null?void 0:h.models.map(S=>S.id))??[],w=v.includes(f)?v:[f,...v],N=s?s.available:!0,k=(s==null?void 0:s.unavailableReason)??"no credential";return t.jsxs(t.Fragment,{children:[t.jsx("div",{hidden:i!=="identity",children:t.jsxs(de,{gap:"lg",children:[N?null:t.jsxs(q,{tone:"warning",children:["This agent cannot run right now."," ",t.jsx("a",{href:Pt(e.id,"setup","brain"),onClick:S=>{S.preventDefault(),l("brain")},children:"See Brain."})]}),t.jsx(UZ,{agent:e,onSaved:c})]})}),t.jsx("div",{hidden:i!=="brain",children:t.jsxs(de,{gap:"lg",children:[N?null:t.jsxs(q,{tone:"warning",children:["This agent cannot run right now: ",k,"."]}),t.jsx(ge,{panel:!0,children:t.jsxs(de,{divided:!0,children:[t.jsxs(ge,{title:"Runs on",children:[a?t.jsx(qZ,{agentId:e.id,accounts:a,onRun:o}):t.jsxs(Ts,{children:[t.jsx(oe,{label:"Provider",children:t.jsx("select",{value:d,onChange:S=>j(S.target.value),children:r.map(S=>t.jsxs("option",{value:S.kind,children:[S.kind,S.usable?"":" (no credential)"]},S.kind))})}),t.jsxs(oe,{label:"Model",children:[t.jsx("input",{list:`models-${e.id}`,defaultValue:f,onBlur:S=>{S.target.value.trim()!==""&&S.target.value.trim()!==f&&y({model:S.target.value.trim()})}}),t.jsx("datalist",{id:`models-${e.id}`,children:w.map(S=>t.jsx("option",{value:S},S))})]})]}),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(ge,{title:"Behaviour",aside:"saved as you change them",children:t.jsxs(Ts,{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:x?t.jsx("span",{className:"critical save-error",role:"alert",children:x}):null,children:t.jsx("input",{type:"number",min:gg,max:xg,value:m,onChange:S=>{p(S.target.value),g(null)},onBlur:()=>{const S=Number(m);if(!Number.isInteger(S)||S<gg||S>xg){g(`Between ${gg} and ${xg}.`);return}S!==((s==null?void 0:s.maxTurns)??e.maxTurns)&&y({maxTurns:S})}})}),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:S=>y({language:S.target.value}),children:LZ.map(S=>t.jsx("option",{value:S,children:S},S))})}),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:S=>y({idleRollover:S.target.value==="3h"?null:S.target.value}),children:FZ.map(S=>t.jsx("option",{value:S.value,children:S.label},S.value))})}):null,F$(_$(s??{id:e.id,provider:d},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:S=>y({thinking:S.target.value==="default"?null:S.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:Ez,children:t.jsx("span",{className:"ui-card-meta",children:"Up to the model"})})]})})]})}),t.jsx(Kt,{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(de,{gap:"lg",children:[t.jsx(BZ,{agent:e,all:n,onSaved:c}),s&&e.tools.some(S=>S==="browser.*"||S.startsWith("browser."))?t.jsx(ge,{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:E6,children:"Browser & apps"}),". A rule never allows what is off there."]})]}),t.jsx(Rv,{value:s.browser??"auto",label:`Where ${e.name} may look`,apps:!1,onChange:S=>y({browser:S})})]})}):null,t.jsx(MZ,{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(de,{gap:"lg",children:t.jsx(XZ,{agent:e,all:n,onSaved:c})})})]})}function LM({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 FM=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 UZ({agent:e,onSaved:n}){var O;const[s,r]=u.useState(e.name),[a,i]=u.useState(e.handle),[l,o]=u.useState(e.description),[c,d]=u.useState(e.avatar??""),[h,f]=u.useState(!1),m=pe(()=>T.agentFile(e.id),[e.id]),[p,x]=u.useState(null),g=((O=m.data)==null?void 0:O.persona.trim())??"",y=p??g,j=m.data!==void 0&&p!==null&&p.trim()!==g,[v,w]=u.useState(!1),[N,k]=u.useState(null),[S,b]=u.useState(null),C=s.trim()!==e.name||a.trim().replace(/^@/,"")!==e.handle||l.trim()!==e.description||c.trim()!==(e.avatar??"")||j,$=c.trim()!==""&&(c.trim()!==(e.avatar??"")||!e.picture),A=aj($?{...e,avatar:c.trim()}:e),I={...A?{avatar:A}:{},...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...!$&&e.picture?{picture:e.picture}:{}},M=async()=>{w(!0),k(null),b(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&&y.trim()!==""?{persona:y.trim()}:{}});e.picture&&c.trim()!==""&&c.trim()!==(e.avatar??"")&&(await T.removeAgentPicture(e.id),window.dispatchEvent(new Event(xs))),x(null),m.reload(),b(R.message),n()}catch(R){k(R instanceof Error?R.message:String(R))}finally{w(!1)}};return t.jsx(ge,{title:"Who it is",aside:t.jsx("span",{className:"mono",children:e.id}),panel:!0,foot:e.isExample?void 0:t.jsx(LM,{dirty:C,busy:v,failure:N,label:"Save who it is",onSave:()=>void M()}),children:t.jsxs(de,{children:[e.isExample?FM:null,S?t.jsx(q,{tone:"good",role:"status",children:S}):null,t.jsxs(Ts,{children:[t.jsx(oe,{label:"Name",hint:"What it is called, everywhere.",children:t.jsx("input",{value:s,disabled:v||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:v||e.isExample,onChange:R=>i(R.target.value)})})]}),t.jsxs(se,{children:[t.jsx(Rn,{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(VZ,{agent:e,avatar:c,onEmoji:d,onChanged:n,disabled:v}):null,t.jsx(oe,{label:"Description",hint:"One or two sentences. Its colleagues read this.",children:t.jsx("textarea",{rows:2,value:l,disabled:v||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(re,{message:m.error}):m.data?t.jsx("textarea",{className:"setup-persona",value:y,rows:Math.max(6,y.split(`
135
+ `).length+1),disabled:v||e.isExample,onChange:R=>x(R.target.value)}):t.jsx(be,{children:"Reading its file…"})})]})})}function BZ({agent:e,all:n,onSaved:s}){var $;const r=pe(()=>T.agentTools(e.id),[e.id,e.tools.join(",")]),[a,i]=u.useState(null),[l,o]=u.useState(()=>new Set((e.roles??[]).filter(sN))),[c,d]=u.useState((e.roles??[]).filter(A=>!sN(A)).join(", ")),[h,f]=u.useState(!1),[m,p]=u.useState(null),[x,g]=u.useState(null),y=(A,I)=>A.split(I).map(M=>M.trim()).filter(M=>M!==""),j=(($=r.data)==null?void 0:$.granted)??e.tools,v=a??j,w=r.data!==void 0&&!eZ(v,j),N=rN(l,y(c,/[\n,]/)),k=A=>o(I=>{const M=new Set(I);return M.has(A)?M.delete(A):M.add(A),M}),b=w||!((A,I)=>A.join(",")===I.join(","))(N,rN(new Set(e.roles??[]),e.roles??[])),C=async()=>{f(!0),p(null),g(null);try{const A=await T.updateAgentFile(e.id,{...w&&r.data?{tools:ZX(r.data.groups,v)}:{},roles:N});g(A.message),i(null),r.reload(),s()}catch(A){p(A instanceof Error?A.message:String(A))}finally{f(!1)}};return t.jsx(ge,{title:"Roles and tools",panel:!0,foot:e.isExample?void 0:t.jsx(LM,{dirty:b,busy:h,failure:m,label:"Save roles and tools",onSave:()=>void C()}),children:t.jsxs(de,{children:[e.isExample?FM:null,x?t.jsx(q,{tone:"good",role:"status",children:x}):null,t.jsxs("div",{className:"ui-field",children:[t.jsx("span",{className:"ui-field-label",id:`roles-${e.id}`,children:"Roles"}),t.jsx("div",{className:"role-chips",role:"group","aria-labelledby":`roles-${e.id}`,children:sy.map(A=>{const I=U6(n,A.id),M=I&&I.id!==e.id?I:void 0;return t.jsxs("button",{type:"button",className:"role-chip","aria-pressed":l.has(A.id),"data-on":l.has(A.id)?"true":void 0,disabled:h||e.isExample,onClick:()=>k(A.id),children:[t.jsx("span",{className:"role-chip-label",children:A.label}),t.jsx("span",{className:"role-chip-meaning",children:A.meaning}),M?t.jsxs("span",{className:"role-chip-holder",children:["Held by ",M.name,". If both claim it, the one listed first keeps it."]}):null]},A.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:A=>d(A.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(re,{message:r.error}):r.data?t.jsx(nZ,{view:r.data,chosen:v,onChange:i,disabled:h||e.isExample}):t.jsx(be,{children:"Loading the installed tools…"})]}),t.jsx(WZ,{agentId:e.id,version:j.join(","),disabled:h||e.isExample}),HZ(j)?t.jsx(KZ,{agentId:e.id}):null]})})}function WZ({agentId:e,version:n,disabled:s}){var x;const r=pe(()=>Promise.resolve().then(()=>T.rememberedApprovals(e)),[e,n]),a=pe(()=>Promise.resolve().then(()=>T.connections()).catch(()=>null),[]),[i,l]=u.useState(null),[o,c]=u.useState(null),d=((x=r.data)==null?void 0:x.tools)??[];if(d.length===0)return null;const h=async(g,y)=>{l(g),c(null);try{await T.setRememberedApproval(e,g,y),r.reload()}catch(j){c(j instanceof Error?j.message:String(j))}finally{l(null)}},f=new Map;for(const g of d)f.set(g.connection,[...f.get(g.connection)??[],g]);const m=g=>{var y,j;return((j=(y=a.data)==null?void 0:y.connections.find(v=>v.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,y])=>{const j=y.filter(k=>k.rememberable),v=y.filter(k=>!k.rememberable),w=j.filter(k=>k.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:[` · ${y.length} ask first`,w.length>0?` · ${w.length} remembered: ${w.map(p).join(", ")}`:""]})]});return t.jsxs(Kt,{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(k=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:k.remembered,disabled:s||i!==null,onChange:S=>void h(k.tool,S.target.checked),"aria-label":`Remember my approval for ${k.tool}`}),t.jsx("span",{className:"mono",children:p(k)})]},k.tool))}),v.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:v.map(p).join(", ")})]}):null]},g)})}),t.jsx(re,{message:o}),t.jsx("span",{className:"ui-field-hint",children:"Tick a tool to remember your approval: it asks once, then runs for this agent."})]})}function HZ(e){return e.some(n=>n==="owner.notify"||n==="owner.*"||n==="owner.notify?"||n==="owner.*?")}function KZ({agentId:e}){var h,f;const n=pe(()=>T.notificationSettings(),[]),[s,r]=u.useState(null),[a,i]=u.useState(!1),[l,o]=u.useState(null),c=s??((f=(h=n.data)==null?void 0:h.settings.agents)==null?void 0:f.muted.includes(e))??!1,d=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=>d(m.target.checked),"aria-label":"Mute this agent's messages"}),t.jsx("span",{children:"Mute its messages"})]}),t.jsx(re,{message:n.error??l}),t.jsx("span",{className:"ui-field-hint",children:"With owner.notify it can message you itself; muted, it is refused and told so."})]})}function 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 VZ({agent:e,avatar:n,onEmoji:s,onChanged:r,disabled:a}){const[i,l]=u.useState(null),[o,c]=u.useState(!1),[d,h]=u.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 x=>{if(h(null),x.kind==="emoji"){s(x.value);return}if(x.kind==="kept"){s(e.avatar??"");return}l(x),c(!0);try{await T.uploadAgentPicture(e.id,await OM(x.role)),s(e.avatar??""),r(),window.dispatchEvent(new Event(xs))}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(DZ,{face:m,label:"Face",kept:e.picture,disabled:a||o,disableEmoji:e.isExample,onPick:x=>void p(x),children:t.jsx(GZ,{agent:e,onChanged:r})}),d?t.jsx("span",{className:"critical save-error",role:"alert",children:d}):null]})}function GZ({agent:e,onChanged:n}){const[s,r]=u.useState(null),[a,i]=u.useState(null),[l,o]=u.useState(!1),[c,d]=u.useState(null),[h,f]=u.useState(null),[m,p]=u.useState(0);u.useEffect(()=>{if(!s)return i(null);const b=URL.createObjectURL(s);return i(b),()=>URL.revokeObjectURL(b)},[s]);const x=b=>{r(null),p(C=>C+1),f(b),n(),window.dispatchEvent(new Event(xs))},g=async b=>{o(!0),d(null),f(null);try{x(await b())}catch(C){d(C instanceof Error?C.message:String(C))}finally{o(!1)}},y=()=>g(async()=>(await T.uploadAgentPicture(e.id,s)).note??null),j=()=>g(async()=>(await T.removeAgentPicture(e.id),null)),v={avatar:aj(e),...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...a??e.picture?{picture:a??e.picture}:{}},[w,N]=u.useState(!1),k=u.useRef(null),S=b=>{d(null),f(null),r(b??null)};return t.jsxs("div",{className:"setup-upload","data-dragging":w?"true":void 0,onDragOver:b=>{b.preventDefault(),l||N(!0)},onDragLeave:()=>N(!1),onDrop:b=>{var C;b.preventDefault(),N(!1),l||S((C=b.dataTransfer.files)==null?void 0:C[0])},children:[t.jsxs(se,{children:[t.jsx(Rn,{id:e.id,name:e.name,size:"xl",face:v}),t.jsx("input",{ref:k,className:"sr-only",type:"file","aria-label":"Choose a picture",accept:"image/png,image/gif,image/svg+xml,.png,.gif,.svg",disabled:l,onChange:b=>{var C;return S((C=b.target.files)==null?void 0:C[0])}},m),t.jsx(E,{disabled:l,onClick:()=>{var b;return(b=k.current)==null?void 0:b.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 y(),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 qZ({agentId:e,accounts:n,onRun:s}){const r=n.bindings.find(p=>p.agentId===e),[a,i]=u.useState((r==null?void 0:r.accountId)??""),[l,o]=u.useState((r==null?void 0:r.model)??""),[c,d]=u.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(se,{valign:"end",children:[t.jsx(oe,{label:"Account",children:t.jsxs("select",{value:a,disabled:c,onChange:p=>{var x;i(p.target.value),o(((x=n.accounts.find(g=>g.id===p.target.value))==null?void 0:x.defaultModel)??"")},children:[t.jsx("option",{value:"",children:"Choose an account"}),n.accounts.map(p=>t.jsxs("option",{value:p.id,disabled:!p.enabled,children:[p.label,p.enabled?p.configured?"":" (needs credential)":" (disabled)"]},p.id))]})}),t.jsx(mb,{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(se,{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:()=>{d(!0),s(T.assignProviderAccount(e,a,l).finally(()=>d(!1)))},children:"Save account selection"})]})]})}const YZ=["platform.create_agent","platform.update_agent","platform.write_skill","platform.delete_agent","platform.accept_plugin_agent","platform.accept_plugin_skill"],vg=e=>e.tools.some(n=>YZ.includes(n)),QZ=["front-desk","maker"],JZ={"front-desk":"Can ask: everyone, as the front desk",maker:"Can ask: everyone, as the maker",list:"Can ask: everyone"};function XZ({agent:e,all:n,onSaved:s}){const[r,a]=u.useState(e.delegates),[i,l]=u.useState(!1),[o,c]=u.useState(null),[d,h]=u.useState(!1),[f,m]=u.useState(e.delegates),[p,x]=u.useState(e.asksEveryone),[g,y]=u.useState(!1),j=n.filter(A=>A.id!==e.id),v=QZ.find(A=>{var I;return(I=e.roles)==null?void 0:I.includes(A)}),w=p===void 0||g,N=g||[...r].sort().join(",")!==[...f].sort().join(","),k=n.filter(A=>A.id!==e.id&&(A.delegates.includes(e.id)||A.asksEveryone!==void 0&&!vg(e))),S=A=>a(I=>I.includes(A)?I.filter(M=>M!==A):[...I,A]),b=async A=>{l(!0),c(null),h(!1);try{const I=await T.setDelegates(e.id,A);m(I.delegates),a(I.delegates),x(I.asksEveryone),y(!1),h(!0),s()}catch(I){c(I instanceof Error?I.message:String(I))}finally{l(!1)}},C=()=>{a(j.filter(A=>!vg(A)).map(A=>A.id)),y(!0),h(!1)},$=N?"Not saved yet.":d?"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(ge,{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:$}),t.jsx("span",{className:"ui-toolbar-spacer"}),w&&v!==void 0?t.jsx(E,{disabled:i,onClick:()=>void b(["*"]),children:"Let it ask everyone"}):null,w?t.jsx(E,{variant:"accent",disabled:!N||i,onClick:()=>void b(r),children:"Save who it can ask"}):t.jsx(E,{variant:"accent",disabled:i,onClick:C,children:"Limit to…"})]}),children:t.jsxs(de,{divided:!0,children:[t.jsxs(ge,{title:"Can ask",children:[e.isExample?t.jsx(q,{tone:"warning",children:"This agent ships with buddi, so its allowlist is read-only here. Ask Agent Father to make it yours, then it can change."}):null,t.jsx(re,{message:o}),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(A=>{const I=vg(A);return t.jsxs("li",{className:"ui-list-row",children:[t.jsx("input",{type:"checkbox",id:`can-ask-${e.id}-${A.id}`,checked:r.includes(A.id),disabled:I||e.isExample||i,onChange:()=>S(A.id)}),t.jsxs("label",{htmlFor:`can-ask-${e.id}-${A.id}`,className:"ui-list-main",children:[t.jsxs("span",{className:"ui-list-title",children:[A.name," ",t.jsxs("span",{className:"mono muted",children:["@",A.handle]})]}),t.jsx("span",{className:"ui-list-sub",children:I?"Makes and changes agents. Never reachable by delegation.":A.description})]})]},A.id)})})]}):t.jsxs("p",{className:"ui-card-meta",children:[JZ[p??"list"],". New agents are included without being added here; agents that make and change agents are never reachable by delegation."]})]}),t.jsx(ge,{title:"Asked by",children:k.length===0?t.jsxs("p",{className:"ui-card-meta",children:["No other agent may hand work to ",e.name,"."]}):t.jsx(O5,{children:k.map(A=>t.jsx(Ce,{children:A.name},A.id))})})]})})}const ZZ=[{id:"team",label:"Team"},{id:"missions",label:"Missions"},{id:"offers",label:"Offers"},{id:"reminders",label:"Reminders"},{id:"skills",label:"Skills"}],eee=[{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 tee(e){const n=w6(e.hash);return n?t.jsx(Y7,{name:n.name,agents:e.agents,navigate:e.navigate,pluginPages:e.pluginPages}):t.jsx(nee,{...e})}function nee({hash:e,timezone:n,navigate:s,agents:r,attention:a,defaultAgentId:i}){var j,v,w,N,k;const l=x6(e),o=((j=/[?&]tab=([a-z]+)/.exec(e))==null?void 0:j[1])??"team",c=S=>b=>{b.preventDefault(),s(S)},d=pe(()=>T.agents(),[]),h=$m(),f=pe(()=>T.offers(),[],2e4),m=VR(),p=(((v=f.data)==null?void 0:v.offers.length)??0)+m.offers.length,x=((N=(w=d.data)==null?void 0:w.default)==null?void 0:N.defaultAgentId)??i??null,[g,y]=u.useState(null);return t.jsxs("div",{className:"ui-page",children:[t.jsx(_i,{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:()=>y({kind:"upload",at:Date.now()}),children:"Upload"}),t.jsx(E,{variant:"accent",onClick:()=>y({kind:"write",at:Date.now()}),children:"Write a skill"})]}):t.jsx(st,{variant:"accent",href:mn(),onClick:c(mn()),children:"Add a teammate"})}),t.jsx(Ro,{children:ZZ.map(S=>t.jsx(Ji,{href:S.id==="team"?yt:`${yt}?tab=${S.id}`,active:o===S.id,count:S.id==="offers"?p:void 0,onClick:c(S.id==="team"?yt:`${yt}?tab=${S.id}`),children:S.label},S.id))}),o==="missions"?t.jsx(iM,{timezone:n,embedded:!0}):null,o==="offers"?t.jsx(GR,{offers:m.offers,reload:m.reload}):null,o==="offers"?t.jsx(oM,{embedded:!0}):null,o==="reminders"?t.jsx(yM,{timezone:n,embedded:!0}):null,o==="skills"?t.jsx(zX,{faces:r,navigate:s,command:g,openSkill:nK(e),openFile:tK(e)}):null,o==="team"?t.jsx(see,{data:d.data,error:d.error,reload:d.reload}):null,o==="team"?r.length===0?t.jsx(as,{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:qT(r,x).map(S=>{const b=Ud(a.get(S.id));return t.jsxs("div",{className:"ui-card agent-card","data-interactive":"true",...Qi(Io(S)),"data-unavailable":S.available?void 0:"true",children:[t.jsx("div",{className:"agent-card-top"}),t.jsx("div",{className:"agent-card-face",children:t.jsx(Rn,{id:S.id,name:S.name,size:"xl",unavailable:!S.available,face:S})}),t.jsxs("div",{children:[t.jsxs("div",{className:"ui-card-title",children:[t.jsx("a",{className:"agent-card-link",href:Pt(S.id,"conversations"),onClick:c(Pt(S.id,"conversations")),children:S.name}),t.jsxs("span",{className:"agent-card-handle mono faint",children:["@",S.handle]})]}),t.jsx("p",{className:"ui-card-meta agent-card-desc",children:S.description})]}),t.jsxs("div",{className:"ui-row",children:[S.id===x?t.jsx(lo,{children:"front desk"}):null,b?t.jsx(Ce,{tone:"critical",dot:!0,children:"waiting for you"}):S.available?t.jsx(Ce,{tone:"good",dot:!0,children:"ready"}):t.jsx(Ce,{tone:"warning",children:mr(S.unavailableReason??"cannot run",60)}),t.jsx(Ce,{mono:!0,children:S.model}),t.jsx(st,{className:"agent-card-talk",size:"sm",href:lt(S.id),onClick:c(lt(S.id)),"aria-label":`Talk to ${S.name}`,children:"Talk"})]})]},S.id)})}):null,l?t.jsx(Je,{title:((k=r.find(S=>S.id===l.agentId))==null?void 0:k.name)??l.agentId,size:"wide",onClose:()=>s(yt),children:t.jsx(ree,{agentId:l.agentId,agent:r.find(S=>S.id===l.agentId),agents:r,tab:l.tab??"conversations",...l.section?{section:l.section}:{},timezone:n,navigate:s,attention:a})}):null]})}function see({data:e,error:n,reload:s}){const r=e==null?void 0:e.default,[a,i]=u.useState(null),[l,o]=u.useState(!1),[c,d]=u.useState(null),[h,f]=u.useState(null);if(n)return t.jsx(re,{message:n});if(!r||r.choices.length===0)return null;const m=r.defaultAgentId,p=a??m??"",x=p!==""&&p!==m,g=r.problem,y=v=>v.map(w=>{var N;return((N=r.choices.find(k=>k.id===w))==null?void 0:N.name)??w}).join(" and "),j=async()=>{o(!0),d(null),f(null);try{const v=await T.setDefaultAgent(p);f(v.note),i(null),s()}catch(v){d(v instanceof Error?v.message:String(v))}finally{o(!1)}};return t.jsx(rt,{children:t.jsxs("div",{className:"ui-stack",children:[t.jsx(re,{message:c}),(g==null?void 0:g.code)==="multiple-defaults"?t.jsx(q,{tone:"warning",role:"status",children:`Two agents claim default in their files: ${y(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(se,{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:v=>i(v.target.value),children:[p===""?t.jsx("option",{value:"",children:"Choose an agent"}):null,r.choices.map(v=>t.jsxs("option",{value:v.id,disabled:!v.available,children:[v.name," @",v.handle,v.available?"":" (cannot run)"]},v.id))]}),t.jsx(E,{variant:"accent",disabled:l||!x,onClick:()=>void j(),children:"Save"})]})]})})}function ree({agentId:e,agent:n,agents:s,tab:r,section:a,timezone:i,navigate:l,attention:o}){const c=p=>x=>{x.preventDefault(),l(p)},d=Ud(o.get(e)),h=(n==null?void 0:n.name)??e,f=pX(e),m=n!==void 0&&!n.roles.includes(gr)&&!n.roles.includes(_d);return t.jsxs("div",{className:"ui-stack","data-gap":"lg",children:[t.jsxs("header",{className:"agent-head",children:[t.jsx(Rn,{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(gX,{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,d?t.jsx(Ce,{tone:"critical",children:d}):n&&!n.available?t.jsx(Ce,{tone:"warning",children:n.unavailableReason??"cannot run"}):null]})]}),t.jsx("div",{className:"ui-page-actions",children:t.jsxs(st,{variant:"accent",href:lt(e),onClick:c(lt(e)),children:["Talk to ",h]})})]}),n&&!n.available?t.jsxs(q,{tone:"warning",role:"status",children:[QT(n)," ",t.jsx("a",{href:ze(lv(n).section),children:lv(n).label})]}):null,t.jsx(Ro,{children:eee.map(p=>t.jsx(Ji,{href:Pt(e,p.id),active:r===p.id,onClick:c(Pt(e,p.id)),children:p.label},p.id))}),r==="conversations"?t.jsx(aee,{agentId:e,navigate:l}):null,r==="missions"?t.jsx(iM,{timezone:i,embedded:!0,agentId:e}):null,r==="offers"?t.jsx(oM,{embedded:!0,agentId:e,agentName:h}):null,r==="reminders"?t.jsx(yM,{timezone:i,embedded:!0,agentId:e}):null,r==="memory"?t.jsx(uM,{embedded:!0,agents:s,timezone:i,agentId:e}):null,r==="skills"?t.jsx(YX,{agentId:e,agentName:h,faces:s,navigate:l}):null,r==="setup"?t.jsx(_Z,{agentId:e,section:a,navigate:l}):null,r==="setup"&&m?t.jsx(vX,{agentId:e,name:h,navigate:l}):null]})}function aee({agentId:e,navigate:n}){const{data:s,error:r}=pe(()=>Xe.conversations(e,50),[e]);if(r)return t.jsx(be,{children:r});const a=(s==null?void 0:s.conversations)??[];return t.jsx(rt,{flush:!0,children:s?a.length===0?t.jsx(as,{icon:"chat",title:"No conversations yet",children:"Say hello, and the conversation shows up here."}):t.jsx(ut,{children:a.map(i=>t.jsx(ot,{href:lt(e,i.id),onClick:()=>n(lt(e,i.id)),title:mr(i.preview||i.opening||"Untitled conversation",90),sub:`${i.messageCount} message${i.messageCount===1?"":"s"}`,side:Ge(i.lastMessageAt??i.startedAt??i.createdAt??null)},i.id))}):t.jsx(be,{children:"Loading…"})})}const iee=3e4;function _M(){const{data:e,reload:n}=pe(()=>T.recovery(),[],iee),s=u.useRef(n);return s.current=n,u.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 $C(e){return e.kind==="account"?e.accountId?FT(e.accountId):ze("accounts"):e.kind==="telegram"?ze("telegram"):e.kind==="connection"?e.connectionId?_T(e.connectionId):ze("connections"):e.kind==="email"?e.settingsRoute:ze("secrets")}function lee(e){return e.install?T6(e.install):ev}const oee=ze("system");function cee(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 zM="This buddi was restored from a backup. Nothing runs on its own until you finish the checklist.";function dee({view:e,onLeft:n}){const{secrets:s,plugins:r,pending:a,grants:i}=e.checklist,l=e.checklist.keptTables??[],[o,c]=u.useState(!0),[d,h]=u.useState([]),[f,m]=u.useState(!1),[p,x]=u.useState(null),[g,y]=u.useState(!1),j=r.filter(k=>!k.installed||k.waiting!==void 0||k.loadsAtRestart===!0),v=a.jobs+a.missions+a.approvals+a.telegramChats,w=k=>{h(S=>S.includes(k)?S.filter(b=>b!==k):[...S,k])},N=()=>{m(!0),x(null),zd({kind:"recovery"},()=>T.leaveRecovery({dropPending:o,keepGrants:d})).then(k=>{k&&k.restarting===!1&&io(),y(!0),n==null||n()}).catch(k=>x(k instanceof fe?k.message:String(k))).finally(()=>m(!1))};return t.jsx(rt,{title:"Back from a backup",children:t.jsxs(de,{divided:!0,children:[t.jsxs(ge,{children:[t.jsx(Qt,{items:[{label:"Restored",value:e.restoredAt??"just now"},{label:"From",value:t.jsx("span",{className:"mono",children:e.archive??"—"})}]}),t.jsx("p",{className:"ui-card-meta",children:"Nothing runs on its own yet: no schedules, no watchers, no phone. Chat works. Go through what is below, then turn this buddi back on."})]}),t.jsx(ge,{title:"Keys to paste again",children:s.length===0?t.jsx(be,{children:"Nothing is missing."}):t.jsx(ut,{children:s.map(k=>t.jsx(ot,{title:k.label??k.name,sub:k.name?t.jsx("span",{className:"mono",children:k.name}):void 0,side:k.signIn?t.jsx(st,{size:"sm",href:$C(k),"aria-label":`Sign in again: ${k.label??k.name}`,children:"Sign in again"}):t.jsx(st,{size:"sm",href:$C(k),"aria-label":`Fix ${k.label??k.name}`,children:"Fix"})},`${k.kind}:${k.accountId??k.name}`))})}),t.jsx(ge,{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(ut,{children:[j.map(k=>t.jsx(ot,{title:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"mono",children:k.name})," ",k.version]}),sub:cee(k),side:k.loadsAtRestart?t.jsx(st,{size:"sm",href:oee,"aria-label":`Restart to load ${k.name}`,children:"Restart"}):k.installed?void 0:t.jsx(st,{size:"sm",href:lee(k),"aria-label":`Install ${k.name} again`,children:k.install?"Install":"Find it"})},k.name)),l.map(k=>t.jsx(ot,{title:t.jsx("span",{className:"mono",children:k.table}),sub:k.sentence},`kept:${k.table}`))]})}),t.jsx(ge,{title:"Work that was waiting",children:v===0?t.jsx(be,{children:"Nothing was in flight when the backup was taken."}):t.jsxs(de,{gap:"sm",children:[t.jsx(Qt,{items:[{label:"Jobs",value:String(a.jobs)},{label:"Missions",value:String(a.missions)},{label:"Waiting for an answer",value:String(a.approvals)},{label:"Phones",value:String(a.telegramChats)}]}),t.jsxs("label",{className:"recovery-check",children:[t.jsx("input",{type:"checkbox",checked:o,onChange:k=>c(k.target.checked)}),t.jsx("span",{children:"Drop it. It was queued somewhere else, days ago."})]})]})}),t.jsx(ge,{title:"Standing permissions",children:i.length===0?t.jsx(be,{children:"No agent had a standing permission."}):t.jsxs(de,{gap:"sm",children:[t.jsx("p",{className:"ui-card-meta",children:"Each of these lets an agent act without asking. Keep only the ones you meant."}),t.jsx("ul",{className:"recovery-list",children:i.map(k=>t.jsx("li",{children:t.jsxs("label",{className:"recovery-check",children:[t.jsx("input",{type:"checkbox",checked:d.includes(k.id),onChange:()=>w(k.id),"aria-label":`Keep ${k.tool} for ${k.agent}`}),t.jsxs("span",{children:[t.jsx("span",{className:"mono",children:k.tool})," for ",k.agent," ",t.jsx("span",{className:"ui-card-meta",children:k.scope}),k.description?t.jsxs("span",{className:"ui-card-meta",children:[" — ",k.description]}):null]})]})},k.id))})]})}),t.jsx(ge,{children:t.jsxs(de,{gap:"sm",children:[t.jsx(re,{message:p}),g?t.jsx(q,{tone:"good",role:"status",children:"Turning everything back on. This page comes back in a few seconds."}):t.jsx("p",{className:"ui-card-meta",children:"Leaving starts the schedules, the watchers and the phone again. buddi restarts itself to do it."}),t.jsx(se,{align:"end",children:t.jsx(E,{variant:"accent",disabled:f||g,onClick:N,children:"Leave recovery mode"})})]})})]})})}function UM(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 BM(e){return(e??[]).filter(n=>n.state==="ready"&&n.wakesOnRestart===!0)}function uee(e){return`${UM(e)} ${e.length===1?"is":"are"} installed; ${e.length===1?"it wakes":"they wake"} up after a restart.`}const WM="buddi.handoverWakes";function TC(e){try{window.localStorage.setItem(WM,BM(e).length>0?"1":"0")}catch{}}function hee(){try{return window.localStorage.getItem(WM)==="0"}catch{return!1}}function HM({plugins:e,onboarding:n="open"}){const[s,r]=u.useState(null),[a,i]=u.useState(!1),[l,o]=u.useState(null);u.useEffect(()=>{if(e!==void 0){e.length>0&&TC(e);return}if(n==="unknown")return;if(n==="done"&&hee()){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"&&TC(m)}).catch(()=>{h||r([])}),()=>{h=!0}},[e,n]);const c=BM(e??s??[]);if(c.length===0)return null;const d=()=>{i(!0),o(null),zd({kind:"plugins",line:`Loading ${UM(c)}…`},()=>T.serviceAction("restart")).catch(h=>o(h instanceof fe?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:d,children:"Restart"}),children:[uee(c),l?` ${l.replace(/[.\s]+$/,"")}.`:" It takes a few seconds, and this page comes back by itself."]})}const IC=3,fee=40;function mee({agent:e,navigate:n}){var x;const s=u.useRef(null),[r,a]=u.useState(!1),[i,l]=u.useState(null),[o,c]=u.useState(null),d=pe(()=>Xe.conversations(e.id,IC),[e.id],3e4),h=Gn(my),f=Gn("(pointer: coarse)");u.useEffect(()=>{var g;!h&&!f&&((g=s.current)==null||g.focus())},[]);const m=(g,y)=>{a(!0),l(null),(async()=>{try{const{conversationId:j}=await Xe.startConversation(e.id),v=await Xe.send(e.id,{conversationId:j,text:g,...y.length>0?{attachmentIds:y.map(w=>w.artifactId)}:{}});n(lt(e.id,v.conversationId))}catch(j){l(j instanceof fe?j.message:String(j)),c({text:g,at:Date.now()}),a(!1)}})()},p=(((x=d.data)==null?void 0:x.conversations)??[]).slice(0,IC);return t.jsxs("div",{className:"home-ask",children:[i?t.jsx(re,{message:i}):null,t.jsx(Wy,{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 y=lt(e.id,g.id),j=g.opening??g.preview??"Untitled conversation",v=Dw(g.lastMessageAt??g.createdAt??g.startedAt??null);return t.jsx("li",{children:t.jsxs("a",{className:"home-continue-chip",href:y,title:j,onClick:w=>{w.preventDefault(),n(y)},children:[t.jsx("span",{className:"home-continue-title",children:mr(j,fee)}),v?t.jsx("span",{className:"home-continue-when",children:v}):null]})},g.id)})})]}):null]})}function pee(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 RC=3,gee=320,PC=160,xee=.3,MC=120,vee=.06,ij=14;function jee(e,n=!1){var j,v,w,N;const s=pe(()=>T.tipQueue(e,n),[e,n]),[r,a]=u.useState(new Set),[i,l]=u.useState([]),[o,c]=u.useState(!1),d=((j=s.data)==null?void 0:j.tips)??[];u.useEffect(()=>{l([])},[s.data]);const h=d.filter(k=>!r.has(k.id)),f=[...h.filter(k=>!i.includes(k.id)),...i.flatMap(k=>h.find(S=>S.id===k)??[])],m=!!(e||(v=s.data)!=null&&v.preview),p=u.useCallback((k,S)=>{S==="later"?l(b=>[...b.filter(C=>C!==k),k]):a(b=>new Set(b).add(k)),!m&&(S==="dismiss"?T.dismissTip(k):T.laterTip(k)).catch(()=>{})},[m]),{reload:x}=s,g=u.useCallback(async k=>{await T.restoreTip(k),a(b=>{const C=new Set(b);return C.delete(k),C}),c(!1),x()},[x]),y=(((w=s.data)==null?void 0:w.dismissed)??0)+[...r].filter(k=>d.some(S=>S.id===k)).length;return{tips:f,shown:d.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||d.length>0),error:s.error,dismissed:y,restore:g,leave:p,folded:u.useCallback(()=>c(!0),[])}}function wee(e){return Math.max(-ij,Math.min(ij,e*vee))}function yee({queue:e,navigate:n}){const s=Gn("(prefers-reduced-motion: reduce)"),[r,a]=u.useState({kind:"rest"}),i=u.useRef(null),l=u.useRef(null),o=u.useRef(null),c=u.useRef(null),{tips:d,leave:h,folded:f}=e,m=d.length===0;u.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]),u.useEffect(()=>{if(!m||!e.shown)return;const b=setTimeout(f,PC);return()=>clearTimeout(b)},[m,e.shown,f]);const p=u.useCallback(b=>{const C=d[0];!C||r.kind==="fly"||(a({kind:"fly",id:C.id,how:b}),c.current=setTimeout(()=>{h(C.id,b),a({kind:"rest"})},s?PC:gee))},[d,r.kind,h,s]);if(!e.shown)return null;const x=d[0],g=r.kind==="fly",y=d.slice(0,RC+(g?1:0)),j=b=>{var C,$;g||b.button>0||b.target.closest("button, a, input")||(o.current={id:b.pointerId,x:b.clientX,width:b.currentTarget.offsetWidth},($=(C=b.currentTarget).setPointerCapture)==null||$.call(C,b.pointerId),a({kind:"drag",dx:0}))},v=b=>{const C=o.current;!C||C.id!==b.pointerId||a({kind:"drag",dx:b.clientX-C.x})},w=b=>{const C=o.current;if(!C||C.id!==b.pointerId)return;o.current=null;const $=b.type==="pointercancel"?0:b.clientX-C.x,A=C.width>0?Math.min(MC,C.width*xee):MC;Math.abs($)>=A?p($<0?"later":"dismiss"):a({kind:"snap"})},N=b=>{b.key==="ArrowLeft"?(b.preventDefault(),p("later")):b.key==="ArrowRight"?(b.preventDefault(),p("dismiss")):b.key==="Enter"&&b.target===b.currentTarget&&x&&(b.preventDefault(),n(x.action.route))},k=()=>{var b;if(r.kind==="drag")return{transform:`translateX(${r.dx}px) rotate(${wee(r.dx)}deg)`,transition:"none"};if(r.kind==="fly"&&!s){const C=r.how==="later"?-1:1,$=((b=i.current)==null?void 0:b.offsetWidth)??400;return{transform:`translateX(${C*$*.8}px) rotate(${C*ij*1.3}deg)`}}},S=d.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":x?`Tips, 1 of ${S}. Left arrow: not now. Right arrow: not this again. Enter: ${x.action.label}.`:"Tips",tabIndex:m?-1:0,onKeyDown:N,"data-motion":s?"reduced":"full","data-depth":Math.min(S,RC)-1,"data-testid":"tip-stack",children:y.map((b,C)=>{const $=C===0,A=g&&$,I=g?Math.max(0,C-1):C;return t.jsx("div",{ref:$?i:void 0,className:"tip-stack-card","data-tip":b.id,"data-depth":A?"leaving":I,"data-dragging":$&&r.kind==="drag"?"true":void 0,"data-leaving":A?r.how:void 0,style:{zIndex:y.length-C,...$?k():{}},"aria-hidden":$?void 0:!0,...$?{}:{inert:""},...$?{onPointerDown:j,onPointerMove:v,onPointerUp:w,onPointerCancel:w}:{},children:t.jsx(ks,{kind:"tip",tone:"accent",icon:"bulb",title:b.text,from:"A tip from buddi",actions:t.jsx(E,{variant:"accent",tabIndex:$&&!A?void 0:-1,onClick:()=>n(b.action.route),children:b.action.label})})},b.id)})}),x?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 ",S]}),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 lj="buddi.tipsOpen",oj="buddi.tipsSeen";function bee(){try{return window.localStorage.getItem(lj)==="1"}catch{return!1}}function kee(){try{const e=JSON.parse(window.localStorage.getItem(oj)??"[]");return Array.isArray(e)?e.filter(n=>typeof n=="string"):[]}catch{return[]}}function Nee(e){try{e.length?window.localStorage.setItem(oj,JSON.stringify(e)):window.localStorage.removeItem(oj)}catch{}}function See(e){const[n,s]=u.useState(()=>!!e||bee());u.useEffect(()=>{e&&s(!0)},[e]);const r=u.useCallback(d=>{if(s(d),!e)try{d?window.localStorage.setItem(lj,"1"):window.localStorage.removeItem(lj)}catch{}},[e]),a=jee(e,!n),[i,l]=u.useState(kee),o=a.tips.map(d=>d.id).join(",");u.useEffect(()=>{if(e||!a.loaded||a.error)return;const d=o?o.split(","):[],h=n?d:i.filter(f=>d.includes(f));h.join(",")!==i.join(",")&&(l(h),Nee(h))},[n,o,e,a.loaded,a.error,i]);const c=!n&&!e&&a.tips.some(d=>!i.includes(d.id));return{open:n,setOpen:r,queue:a,unseen:c,preview:!!e}}function Cee({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 Eee({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(ge,{title:"Tips",actions:t.jsx(E,{variant:"ghost",size:"sm",onClick:()=>r(!1),children:"Close"}),children:[t.jsx(re,{message:a.error}),i&&!a.error?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"home-tips-empty",children:a.allDismissed?"You've turned off every tip that applies.":"No tips right now. New ones appear as you use buddi."}),a.dismissed>0&&!e.preview?t.jsx(Aee,{queue:a}):null]}):t.jsx(yee,{queue:a,navigate:n})]})})}function Aee({queue:e}){const[n,s]=u.useState(!1),r=e.dismissed;return n?t.jsx($ee,{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 $ee({queue:e}){var h;const n=pe(()=>T.dismissedTips(),[]),[s,r]=u.useState(new Set),[a,i]=u.useState(null),[l,o]=u.useState(null),c=(((h=n.data)==null?void 0:h.tips)??[]).filter(f=>!s.has(f.id)),d=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(re,{message:n.error??l}),n.data&&c.length===0?null:t.jsx(ut,{children:c.map(f=>t.jsx(ot,{title:f.text,side:t.jsx(E,{size:"sm",disabled:a!==null,onClick:()=>void d(f.id),children:"Bring back"})},f.id))})]})}function Tee(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 Iee({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:vr(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:Tee(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 Ree="Write these down; they open your backups and only you have them.";function Pee(){var r;const e=pe(()=>T.passphraseNotice(),[]),[n,s]=u.useState(!1);return{data:e.data,shown:!n&&!!((r=e.data)!=null&&r.show),gone:()=>s(!0)}}function Mee({notice:e}){const[n,s]=u.useState(null),[r,a]=u.useState(!1),[i,l]=u.useState(null),[o,c]=u.useState(""),[d,h]=u.useState(null),f=e.data;if(!e.shown||!f||!f.show)return null;const m="passphrase"in f?f.passphrase:d,p=()=>{m!==null&&navigator.clipboard.writeText(m).then(()=>s("done"),()=>s("failed"))},x=()=>{a(!0),l(null),T.revealBackupPassphrase(o).then(y=>{h(y.passphrase),c("")}).catch(y=>l(y instanceof fe?y.message:String(y))).finally(()=>a(!1))},g=()=>{a(!0),l(null),T.acknowledgePassphrase().then(()=>e.gone()).catch(y=>l(y instanceof fe?y.message:String(y))).finally(()=>a(!1))};return t.jsxs(ks,{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:x,children:"Show the words"}),children:[t.jsx(re,{message:i}),t.jsx("p",{children:Ree}),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:y=>c(y.target.value),onKeyDown:y=>{y.key==="Enter"&&o!==""&&x()}})})]})}const KM="buddi.needsYouView";function Oee(){try{return window.localStorage.getItem(KM)==="list"?"list":"deck"}catch{return"deck"}}function Dee(e){try{window.localStorage.setItem(KM,e)}catch{}}function Lee(e,n,s){const r=(n.alsoFrom??[]).filter(a=>a!==n.agentId).map(s);return r.length===0?e:`${e} · also ${r.join(", ")}`}function Fee({rows:e,agents:n,label:s,onOpen:r,onDone:a}){const[i,l]=u.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],d=e.length>1,h=x=>l((o+x+e.length)%e.length),f=()=>r(c),m=()=>a(c),p=x=>{const g=x.target;g.closest('input, textarea, select, [contenteditable="true"]')||(x.key==="ArrowRight"&&d?(x.preventDefault(),h(1)):x.key==="ArrowLeft"&&d?(x.preventDefault(),h(-1)):x.key==="Enter"&&!g.closest("button, a")?(x.preventDefault(),(c.link||c.agentId)&&f()):(x.key==="d"||x.key==="Delete")&&!x.metaKey&&!x.ctrlKey&&!x.altKey&&(x.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(ks,{kind:"request",tone:"accent",title:ad(c),time:c.state==="held"?"today":Ge(c.createdAt),from:t.jsx(gd,{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:!d,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:!d,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 _ee({row:e,agents:n,label:s,onOpen:r,onDone:a}){const i=!!(e.link||e.agentId);return t.jsx(ks,{kind:"request",tone:"accent",compact:!0,title:ad(e),...i?{href:e.link??"#",onOpen:()=>r(e)}:{},time:e.state==="held"?"today":Ge(e.createdAt),from:t.jsx(gd,{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 zee({timezone:e,navigate:n,agents:s,defaultAgentId:r,attention:a,update:i,connectionSignals:l=[],hash:o="",pluginPages:c,onboarding:d}){var ye,et,pt,kt,Ot,Ut,Sn,Vt,Un,Pn,Mn,gn,xn,It,Ae,Ze,Re,we;const h=pe(()=>T.overview(),[],15e3),f=pe(()=>T.approvals(),[],1e4),m=pe(()=>T.missions(),[],6e4),p=pe(()=>T.reminders(),[],6e4),x=pe(()=>T.conversations(),[],3e4),g=pe(()=>T.offers(),[],3e4),y=pe(()=>T.proposals(),[],6e4),j=pe(()=>T.agentOffers(),[],6e4),v=pe(()=>T.owner(),[]),w=pe(()=>T.birthday(),[],5*6e4),N=pe(()=>T.notificationsNeedingYou(),[],3e4),k=u.useMemo(()=>qT(s,r??null),[s,r]),S=nq(s,r),{busy:b,note:C,failure:$,decide:A}=Hy(()=>{f.reload(),h.reload()}),I=h.data,M=s.find(Y=>Y.id===r)??null,O=Y=>JB(Y,s),R=Y=>Le=>{Le.preventDefault(),n(Y)},_=((ye=f.data)==null?void 0:ye.pending)??[],z=((et=I==null?void 0:I.jobs)==null?void 0:et.failed)??0,U=((pt=I==null?void 0:I.sentinels)==null?void 0:pt.openUrgent)??0,P=((kt=y.data)==null?void 0:kt.open.length)??0,W=(((Ot=j.data)==null?void 0:Ot.offers)??[]).filter(Y=>!_.some(Le=>KR(Le,Y.plugin,Y.agent))),L=Bee(((Ut=N.data)==null?void 0:Ut.notifications)??[],_),[Q,F]=u.useState(new Set),[ae,V]=u.useState(Oee),J=L.filter(Y=>!Q.has(Y.id)),H=Y=>{F(Le=>new Set(Le).add(Y.id)),T.notificationSeen(Y.id).catch(()=>{})},X=Y=>{H(Y);const Le=Y.link??(Y.agentId?lt(Y.agentId):null);Le&&n(Le)},G=Y=>Lee(Y.agentId?O(Y.agentId):Y.pluginId?iv(Y.pluginId,c==null?void 0:c.all):Uee[Y.kind],Y,O),ce=Vee(I==null?void 0:I.dismissed,()=>h.reload()),xe=(((Sn=I==null?void 0:I.sentinels)==null?void 0:Sn.errors)??[]).filter(Y=>!ce.is(`watcher-error:${Y.sentinelId}`,Y.error)),De=((I==null?void 0:I.mail)??[]).filter(Y=>Y.lastError&&!ce.is(`source-error:${Y.sourceId}`,Y.lastError)),B=Wee(a),ne=l.filter(Y=>!ce.is(`connection:${Y.id}`,Y.sentence)),Z=(((Vt=I==null?void 0:I.needsYou)==null?void 0:Vt.recovery)??0)>0,ve=See(pee(o)),$e=Pee(),Se=!!(i&&i.updateAvailable&&!i.checkout&&i.latest&&!ce.is("update",i.latest)),me=_.length+B.length+W.length+L.length+ne.length+(Z?1:0)+($e.shown?1:0)+(Se?1:0)+xe.length+De.length;u.useEffect(()=>{var Y,Le;o===ao&&((Le=(Y=document.getElementById(cj))==null?void 0:Y.scrollIntoView)==null||Le.call(Y,{behavior:"smooth",block:"start"}))},[o]);const Ee=u.useMemo(()=>{var Y,Le;return Qee(((Y=m.data)==null?void 0:Y.missions)??[],((Le=p.data)==null?void 0:Le.reminders)??[])},[m.data,p.data]),Pe=(((Un=x.data)==null?void 0:Un.conversations)??[]).slice(0,5),Me=((Pn=g.data)==null?void 0:Pn.offers)??[],he=Me.slice(0,Gee),ke=Me.length-he.length,Be=zP(()=>h.reload()),qe=UQ(),at=u.useMemo(()=>BQ(qe.answer),[qe.answer]),le=ste((I==null?void 0:I.needsYou)??{approvals:_.length,questions:B.length,failed:z,urgent:U,proposals:P,agentsToSetUp:W.length,asks:L.length,signIns:ne.length,recovery:Z?1:0},(I==null?void 0:I.paused)??!1).map(Y=>{var Le;return Y.key==="urgent"?{...Y,hint:nte(Y.count??0,((Le=I==null?void 0:I.sentinels)==null?void 0:Le.decisions)??[])}:Y});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:ete(I==null?void 0:I.now,e)}),t.jsx(vQ,{glances:I==null?void 0:I.glances,navigate:n,except:at,hiding:Be}),t.jsx(Cee,{tips:ve})]}),t.jsx("h1",{className:"home-greeting",children:(Mn=w.data)!=null&&Mn.today?Xee(w.data.name??((gn=v.data)==null?void 0:gn.preferredName)??((xn=v.data)==null?void 0:xn.displayName)):Zee(I==null?void 0:I.now,e,((It=v.data)==null?void 0:It.preferredName)||((Ae=v.data)==null?void 0:Ae.displayName))}),t.jsx(rte,{items:le,navigate:n})]}),t.jsx("div",{className:"home-side",children:t.jsx(aI,{size:"lg",anim:"idle"})})]}),(Ze=w.data)!=null&&Ze.today&&w.data.note&&!ce.is("birthday",w.data.date)?t.jsx(Iee,{glance:w.data,team:k,onClose:()=>ce.close("birthday",w.data.date)}):null]}),t.jsxs("div",{className:"home",children:[M?t.jsx(mee,{agent:M,navigate:n},M.id):null,t.jsx(Eee,{tips:ve,navigate:n}),t.jsx(re,{message:h.error??f.error??$}),C?t.jsx("p",{className:"home-note muted",role:"status",children:C}):null,me>0?t.jsx("div",{id:cj,className:"home-needs",children:t.jsx(ge,{title:"Needs you",aside:t.jsx("a",{href:nv,onClick:R(nv),children:"All notifications"}),actions:L.length>0?t.jsx(Jt,{label:"Show what needs you as",options:[{value:"list",label:"List"},{value:"deck",label:"Deck"}],value:ae,onChange:Y=>{V(Y),Dee(Y)}}):void 0,children:t.jsxs(de,{children:[_.map(Y=>t.jsx(Ky,{action:Y,timezone:e,busy:b===Y.id,onDecide:A,agentName:O(Y.agentId),agents:s},Y.id)),B.map(Y=>t.jsx(ks,{kind:"question",tone:"accent",icon:"chat",title:"Asked you a question",href:Y.route,onOpen:()=>n(Y.route),time:Ge(Y.at),from:t.jsxs(gd,{face:t.jsx(an,{agents:s,id:Y.agentId,size:"sm"}),children:[O(Y.agentId)," · waiting for your answer"]}),actions:t.jsx(E,{variant:"accent",onClick:()=>n(Y.route),children:"Answer"})},Y.agentId)),L.length>0&&ae==="list"?t.jsx(de,{gap:"sm",children:J.map(Y=>t.jsx(_ee,{row:Y,agents:s,label:G,onOpen:X,onDone:H},Y.id))}):null,L.length>0&&ae==="deck"?t.jsx(Fee,{rows:J,agents:s,label:G,onOpen:X,onDone:H}):null,t.jsx(Mee,{notice:$e}),Se&&i?t.jsx(ks,{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(st,{variant:"accent",href:ze("system"),onClick:R(ze("system")),children:"Upgrade from Settings"})}):null,xe.map(Y=>t.jsx(ks,{kind:"watcher-error",tone:"warning",icon:"alert",title:`Watcher ${Y.sentinelId} failed`,from:"buddi · your watchers",dismiss:{onClick:()=>ce.close(`watcher-error:${Y.sentinelId}`,Y.error),hint:"Hide until the error changes"},actions:t.jsx(st,{href:ze("watchers"),onClick:R(ze("watchers")),children:"Open Watchers"}),children:t.jsx("p",{children:Y.error})},Y.sentinelId)),De.map(Y=>t.jsx(ks,{kind:"source-error",tone:"warning",icon:"alert",title:`Source ${Y.sourceId} cannot be read`,from:"buddi · your sources",dismiss:{onClick:()=>ce.close(`source-error:${Y.sourceId}`,Y.lastError),hint:"Hide until the error changes"},children:t.jsx("p",{children:Y.lastError})},Y.sourceId)),ne.map(Y=>t.jsx(ks,{kind:"sign-in",tone:"accent",icon:"plug",title:Y.sentence,from:`${Y.name} · a connection`,dismiss:{onClick:()=>ce.close(`connection:${Y.id}`,Y.sentence),hint:"Tell me if it changes"},actions:t.jsx(st,{variant:"accent",href:ze("connections"),onClick:R(ze("connections")),children:"Open Connections"})},Y.id)),W.map(Y=>t.jsx(Gy,{plugin:Y.plugin,agent:Y.agent,text:Y.text,label:`Create @${Y.handle}`,handle:Y.handle,card:{from:iv(Y.plugin,c==null?void 0:c.all)},onDismiss:()=>{T.dismissAgentOffer(Y.plugin,Y.agent).then(()=>j.reload())}},`${Y.plugin}/${Y.agent}`)),Z?t.jsx(ks,{kind:"recovery",tone:"warning",icon:"archive",title:"Finish restoring this buddi",from:"buddi · restored from a backup",actions:t.jsx(st,{variant:"accent",href:sv,onClick:R(sv),children:"Open the checklist"}),children:t.jsx("p",{children:zM})}):null]})})}):null,t.jsx(HM,{...d?{onboarding:d}:{}}),t.jsx(VQ,{widgets:qe,navigate:n}),t.jsxs(ge,{title:"Your team",aside:S?t.jsx("a",{href:mn(),onClick:R(mn()),children:"See all teammates"}):t.jsx("a",{href:yt,onClick:R(yt),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:[k.map(Y=>{const Le=Ud(a.get(Y.id));return t.jsxs("a",{className:"home-face",...Qi(Io(Y)),href:lt(Y.id),onClick:R(lt(Y.id)),"data-waiting":Le?"true":void 0,"data-unavailable":Y.available?void 0:"true",children:[t.jsx(Rn,{id:Y.id,name:Y.name,size:"lg",unavailable:!Y.available,face:Y}),t.jsxs("span",{className:"home-face-text",children:[t.jsx("span",{className:"home-face-name",children:Y.name}),t.jsx("span",{className:"home-face-status",children:Le?ate(Le):Y.available?mr(Y.description,60):Y.unavailableReason??"Cannot run right now."})]})]},Y.id)}),S?null:t.jsxs("a",{className:"team-add",href:mn(),onClick:R(mn()),"data-testid":"team-add",children:[t.jsx(ie,{name:"plus",size:14}),"Add a teammate"]})]}),t.jsx(lq,{navigate:n,newTeam:S,closed:ce})]}),he.length>0?t.jsx(ge,{title:"On offer",aside:t.jsxs("span",{className:"ui-row",children:[ke>0?t.jsxs("a",{href:`${yt}?tab=offers`,onClick:R(`${yt}?tab=offers`),children:[ke," more"]}):null,t.jsx(lM,{ids:Me.map(Y=>Y.id),onDone:()=>g.reload()})]}),children:t.jsx("div",{className:"home-offers",children:he.map(Y=>t.jsx(Yee,{offer:Y,agents:s,open:R(Pt(Y.agentId,"offers")),onDismissed:()=>g.reload()},Y.id))})}):null,t.jsx(JY,{}),(we=(Re=y.data)==null?void 0:Re.digest)!=null&&we.latest&&Kee(y.data.digest.latest,I==null?void 0:I.now,ce.is)?t.jsx(tte,{digest:y.data.digest.latest,go:R,onClose:()=>ce.close(VM,y.data.digest.latest.at)}):null,t.jsxs("div",{className:"home-columns",children:[t.jsx(ge,{title:"Coming up",aside:t.jsx("a",{href:`${yt}?tab=missions`,onClick:R(`${yt}?tab=missions`),children:"All missions"}),children:t.jsx(rt,{flush:!0,children:Ee.length===0?t.jsx(be,{mascot:!0,children:"Nothing scheduled. Missions and reminders will show here."}):t.jsx(ut,{children:Ee.map(Y=>t.jsx(ot,{href:Y.route,onClick:()=>n(Y.route),lead:t.jsx(an,{agents:s,id:Y.agentId,size:"sm"}),title:Y.title,sub:`${Y.kind} for ${O(Y.agentId)}`,side:Ge(Y.at)},Y.key))})})}),t.jsx(ge,{title:"Lately",aside:t.jsx("a",{href:Yt,onClick:R(Yt),children:"All activity"}),children:t.jsx(rt,{flush:!0,children:Pe.length===0?t.jsx(be,{mascot:!0,children:"Nothing has run yet. Say hello to someone on your team."}):t.jsx(ut,{children:Pe.map(Y=>t.jsx(ot,{href:lt(Y.agentId,Y.id),onClick:()=>n(lt(Y.agentId,Y.id)),lead:t.jsx(an,{agents:s,id:Y.agentId,size:"sm"}),title:Y.opening?mr(Y.opening,80):"Untitled conversation",sub:`${O(Y.agentId)}, ${Y.messageCount} message${Y.messageCount===1?"":"s"}`,side:Ge(Y.lastMessageAt??Y.createdAt)},Y.id))})})})]}),((I==null?void 0:I.home)??[]).filter(Y=>!ce.is(OC(Y.id),DC)).map(Y=>t.jsx(ite,{block:Y,onHide:()=>ce.close(OC(Y.id),DC)},Y.id)),I!=null&&I.jobs&&I.missions?t.jsxs("p",{className:"home-foot muted",children:[fn(I.jobs.pending??0)," queued, ",fn(I.jobs.leased??0)," running, ",fn(I.missions.enabled)," of ",fn(I.missions.total)," missions on."," ",I.paused?t.jsx(Ce,{tone:"warning",children:"paused"}):t.jsx(Ce,{tone:"good",children:"running"})," ",t.jsx("a",{href:od("").replace(/\/conversations\/$/,""),onClick:R(Yt),children:"Activity"})," · ",t.jsx("a",{href:ze("system"),onClick:R(ze("system")),children:"System"})]}):null]})]})}const Uee={approval:"Approval",question:"Question",watcher:"Watcher",reminder:"Reminder",failure:"Failure",recap:"Report",plugin:"Plugin",agent:"Message"};function Bee(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 Wee(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 VM="digest",Hee=3*864e5;function OC(e){return`block:${e}`}const DC="hidden";function Kee(e,n,s){if(s(VM,e.at))return!1;const r=Date.parse(e.at),a=n?Date.parse(n):Date.now();return Number.isFinite(r)&&a-r<Hee}function Vee(e,n){const[s,r]=u.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 d={...c};return delete d[l],d})})}}}function GM({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 Gee=6,qee=500;function Yee({offer:e,agents:n,open:s,onDismissed:r}){const[a,i]=u.useState(!1),l=u.useRef(null),o=u.useRef(!1),c=()=>{a||(i(!0),T.dismissOffer(e.id).then(r).finally(()=>i(!1)))},d=()=>{l.current!==null&&clearTimeout(l.current),l.current=null};return t.jsxs("span",{className:"home-offer-chip",children:[t.jsxs("a",{className:"home-offer",href:Pt(e.agentId,"offers"),onClick:h=>{if(o.current){o.current=!1,h.preventDefault();return}s(h)},title:e.prompt,onTouchStart:()=>{o.current=!1,d(),l.current=setTimeout(()=>{o.current=!0,c()},qee)},onTouchEnd:d,onTouchMove:d,onTouchCancel:d,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 Qee(e,n){const s=[];for(const r of e)r.enabled&&r.nextRun&&s.push({key:`m-${r.id}`,at:r.nextRun,title:r.name,kind:"Mission",agentId:r.agentId,route:Pt(r.agentId,"missions")});for(const r of n)r.state==="pending"&&s.push({key:`r-${r.id}`,at:r.dueAt,title:r.text,kind:"Reminder",agentId:r.agentId,route:Pt(r.agentId,"reminders")});return s.sort((r,a)=>r.at.localeCompare(a.at)).slice(0,5)}function Jee(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 Xee(e){return e?`Happy birthday, ${e}.`:"Happy birthday."}function Zee(e,n,s){const r=Jee(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 ete(e,n){try{return Nr(e?new Date(e):new Date,n,{weekday:!0})}catch{return ft(e??null,n)}}function tte({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 d;return`${((d=e.agentNames)==null?void 0:d[o])??o}: ${c}`});return r.length===0&&a.length===0?null:t.jsx(ge,{title:"What buddi learned this week",aside:t.jsxs("span",{className:"ui-row",children:[t.jsx("span",{className:"muted",children:Ge(e.at)}),s?t.jsx(GM,{label:"Hide until next week",onClick:s}):null]}),children:t.jsx(rt,{children:t.jsxs(de,{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 d;return t.jsxs("li",{children:["What was off (",((d=e.agentNames)==null?void 0:d[o.agentId])??o.agentId,"): ",o.note]},`note-${c}`)})]})]}):null]})})})}function nte(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 cj="home-needs";function ste(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:`${Yt}/alerts`}),e.failed>0&&r.push({key:"failed",count:e.failed,label:s(e.failed,"failed job"),tone:"critical",route:`${Yt}/jobs?state=failed`}),n&&r.push({key:"paused",count:null,label:"Paused",route:`${Yt}/jobs`}),e.proposals>0&&r.push({key:"proposals",count:e.proposals,label:s(e.proposals,"proposal"),route:ze("proposals")}),e.asks>0&&r.push({key:"asks",count:e.asks,label:s(e.asks,"request")}),e.signIns>0&&r.push({key:"signins",count:e.signIns,label:s(e.signIns,"connection to check","connections to check")}),e.agentsToSetUp>0&&r.push({key:"agents",count:e.agentsToSetUp,label:s(e.agentsToSetUp,"agent to set up","agents to set up")}),e.recovery>0&&r.push({key:"recovery",count:null,label:"Restore to finish"}),r}function rte({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(cj))==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(u.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 ate(e){return e.charAt(0).toUpperCase()+e.slice(1)}function ite({block:e,onHide:n}){const[s,r]=u.useState(!1),a=e.sensitive===!0&&!s;u.useEffect(()=>{if(!e.sensitive||!s)return;const l=()=>{document.visibilityState==="hidden"&&r(!1)};return document.addEventListener("visibilitychange",l),window.addEventListener("blur",l),()=>{document.removeEventListener("visibilitychange",l),window.removeEventListener("blur",l)}},[e.sensitive,s]);const i=t.jsxs("span",{className:"ui-row",children:[e.rows.length>0&&e.rowsTitle&&!a?t.jsxs("span",{className:"muted",children:[e.rowsTitle.toLowerCase()," below"]}):null,e.sensitive?t.jsx(E,{size:"sm",variant:"ghost","aria-pressed":!a,onClick:()=>r(l=>!l),children:a?"Show":"Hide"}):null,t.jsx(GM,{label:`Hide ${e.title} from Home`,onClick:n})]});return t.jsxs(ge,{title:e.title,aside:i,children:[e.note?t.jsx(q,{tone:"warning",children:e.note}):null,e.stats.length>0?t.jsx(Sm,{children:e.stats.map(l=>t.jsx(Lr,{label:l.label,value:a?"••••":l.value,note:a?void 0:l.note,tone:a?void 0:l.tone},l.label))}):null,e.rows.length>0?a?t.jsxs("p",{className:"muted",children:[e.rows.length," item",e.rows.length===1?"":"s"," hidden."]}):t.jsx(rt,{flush:!0,children:t.jsx(ut,{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 lte="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 ote(e){var n;try{await((n=navigator.clipboard)==null?void 0:n.writeText(e))}catch{}}function fo({text:e,disabled:n}){return t.jsxs("div",{className:"tailscale-command",children:[t.jsx("code",{className:"mono",children:e}),t.jsx(E,{size:"sm",disabled:n,onClick:()=>{ote(e)},children:"Copy"})]})}function cte({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 dte={ready:t.jsx(Ce,{tone:"good",children:"Ready"}),waiting:t.jsx(Ce,{children:"Waiting"}),"needs-setup":t.jsx(Ce,{tone:"warning",children:"Needs setup"}),unanswered:t.jsx(Ce,{tone:"warning",children:"Not answering"}),off:null};function ute(){var i,l;const e=pe(()=>T.access(),[]),[n,s]=u.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(ge,{title:"Sign in from elsewhere",aside:"checked by buddi on every visit",panel:!0,flush:!0,children:[t.jsx(re,{message:e.error}),r?t.jsx("div",{className:"access-locked",children:t.jsx(q,{tone:"warning",children:"Change this from the computer buddi runs on."})}):null,t.jsx(ut,{children:a.map(o=>t.jsxs(u.Fragment,{children:[t.jsx(ot,{onClick:()=>s(n===o.id?null:o.id),label:`${o.title}: ${o.status.sentence}`,lead:t.jsx(cte,{id:o.id}),title:o.title,sub:o.status.sentence,side:t.jsxs("span",{className:"access-side",children:[dte[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(hte,{embedded:!0,onSaved:e.reload}):t.jsx(pte,{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 hte({embedded:e,onSaved:n}={}){var g;const s=pe(()=>T.tailscale(),[]),[r,a]=u.useState(null),[i,l]=u.useState(!1),[o,c]=u.useState(null),[d,h]=u.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,x=y=>{l(!0),c(null),h(!1),T.setTailscale({enabled:y,login:m.trim()}).then(()=>{h(!0),n==null||n()}).catch(j=>c(j instanceof fe?j.message:String(j))).finally(()=>{l(!1),s.reload()})};return t.jsxs(de,{gap:"sm",children:[t.jsx(re,{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:y=>x(y.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:y=>a(y.target.value)})}),t.jsx("p",{className:"ui-card-meta",children:"Anyone signed in to Tailscale as this login, on any device in your tailnet, is signed in to buddi. The proxy must run on this machine:"}),t.jsx(fo,{text:(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."}),d?t.jsx(q,{tone:"good",role:"status",children:"Saved."}):null,t.jsx(se,{align:"end",children:t.jsx(E,{variant:"accent",disabled:i||!f||p,onClick:()=>x((f==null?void 0:f.enabled)??!1),children:"Save"})})]})}const fte=["teamDomain","aud","email","publicOrigin"];function mte({onSaved:e,extra:n}={}){const s=pe(()=>T.cloudflareAccess(),[]),[r,a]=u.useState(!1),[i,l]=u.useState(null),[o,c]=u.useState(!1),[d,h]=u.useState(null),[f,m]=u.useState(null),[p,x]=u.useState(!1),g=s.data,y=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,v=o||!g||j,w=($,A)=>l({...y,[$]:A}),N=[y.teamDomain.trim()===""?"the team domain":null,y.aud.trim()===""?"the AUD tag":null,y.email.trim()===""?"your email":null].filter($=>$!==null),k=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,S=$=>{if($&&k){a(!0);return}a(!1),c(!0),h(null),x(!1),m(null),T.setCloudflareAccess({enabled:$,...y}).then(A=>{x(!0),A.test&&m(A.test.ok?{ok:!0,sentence:`${A.teamDomain} answered with ${A.test.keys} signing key${A.test.keys===1?"":"s"}.${A.publicOrigin?` Open ${A.publicOrigin} from another device to finish.`:""}`}:{ok:!1,sentence:A.test.error??"Cloudflare’s signing keys could not be fetched."}),l(null),e==null||e()}).catch(A=>h(A instanceof fe?A.message:String(A))).finally(()=>{c(!1),s.reload()})},b=()=>{c(!0),h(null),m(null),T.testCloudflareAccess({teamDomain:y.teamDomain}).then($=>m({ok:$.ok,sentence:$.ok&&y.publicOrigin?`${$.sentence} Open ${y.publicOrigin} from another device to finish.`:$.sentence})).catch($=>h($ instanceof fe?$.message:String($))).finally(()=>c(!1))},C=$=>g==null?void 0:g.setup.fields.find(A=>A.key===$);return t.jsxs(de,{gap:"sm",children:[t.jsx(re,{message:s.error??d}),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:v,onChange:$=>S($.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($=>t.jsxs("li",{children:[t.jsx("span",{children:$.text}),$.command?t.jsx(fo,{text:$.command,disabled:v}):null]},$.text))}),t.jsx("div",{className:"access-grid",children:fte.map($=>{const A=C($);return t.jsx(oe,{label:(A==null?void 0:A.label)??$,hint:A==null?void 0:A.hint,children:t.jsx("input",{type:$==="email"?"email":"text",className:$==="aud"?"mono":void 0,value:y[$],placeholder:A==null?void 0:A.placeholder,disabled:v,spellCheck:!1,autoComplete:"off",onChange:I=>w($,I.target.value)})},$)})}),k&&!j&&!((g==null?void 0:g.enabled)??!1)?r?t.jsx(q,{tone:"critical",role:"alert",children:k}):t.jsx("p",{className:"ui-card-meta",children:k}):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(se,{align:"end",children:[t.jsx(E,{disabled:v||y.teamDomain.trim()==="",onClick:b,children:"Test my setup"}),t.jsx(E,{variant:"accent",disabled:v,onClick:()=>S((g==null?void 0:g.enabled)??!1),children:"Save"})]})]})}const LC=["running","waiting","removing"];function pte({enabled:e,locked:n,onSaved:s}){const[r,a]=u.useState(null),[i,l]=u.useState(null),[o,c]=u.useState(null),[d,h]=u.useState(!1),[f,m]=u.useState(!1);u.useEffect(()=>{n||T.cloudflareSetup().then(a).catch(()=>a(null))},[n]);const p=(r==null?void 0:r.progress.state)??"idle",x=LC.includes(p);u.useEffect(()=>{if(!x)return;const v=window.setInterval(()=>{T.cloudflareSetup().then(w=>{a(w),LC.includes(w.progress.state)||s==null||s()}).catch(()=>{})},1500);return()=>window.clearInterval(v)},[x,s]);const g=n?"manual":i??(p!=="idle"?"run":e||r!=null&&r.record?"manual":r?"offer":null),y=(v,w)=>{h(!0),c(null),v().then(N=>{a(N),w&&l(w),s==null||s()}).catch(N=>c(N instanceof fe?N.message:String(N))).finally(()=>h(!1))},j=()=>y(()=>T.removeCloudflareSetup(),"run");if(g===null)return t.jsx("p",{className:"ui-card-meta",children:"…"});if(g==="manual"){const v=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(de,{gap:"sm",children:[t.jsx(re,{message:o}),t.jsx(mte,{onSaved:s,extra:v}),r!=null&&r.record&&!n?t.jsxs(se,{align:"end",children:[t.jsx(E,{disabled:d,onClick:j,children:"Remove what buddi made"}),t.jsx(E,{disabled:d,onClick:()=>l("form"),children:"Set it up again"})]}):null]})}return g==="offer"?t.jsxs(de,{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(se,{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(xte,{setup:r,busy:d,failed:o,onCancel:()=>{c(null),l(null)},onStart:v=>y(()=>T.startCloudflareSetup(v),"run")}):t.jsx(vte,{progress:(r==null?void 0:r.progress)??null,busy:d,failed:o,onStop:()=>y(()=>T.stopCloudflareSetup()),onRetry:()=>l("form"),onAdopt:()=>{const v=r==null?void 0:r.progress;v&&y(()=>T.startCloudflareSetup({host:v.host,email:v.email,adopt:!0}),"run")},onUseSystem:()=>{const v=r==null?void 0:r.progress;v&&y(()=>T.stopCloudflareSetup().then(()=>T.startCloudflareSetup({host:v.host,email:v.email,useSystemDaemon:!0})),"run")},onRemove:j,onAgain:()=>l("form"),tokenStored:(r==null?void 0:r.tokenStored)??!1,forgot:f,onForget:()=>y(()=>T.forgetCloudflareToken().then(v=>(m(!0),v)))})}function gte(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 xte({setup:e,busy:n,failed:s,onCancel:r,onStart:a}){var z,U;const i=((z=e==null?void 0:e.record)==null?void 0:z.host)??(e==null?void 0:e.progress.host)??"",[l,o]=u.useState(""),[c,d]=u.useState(null),[h,f]=u.useState(!1),[m,p]=u.useState(null),[x,g]=u.useState("buddi"),[y,j]=u.useState(""),[v,w]=u.useState(i),[N,k]=u.useState(((U=e==null?void 0:e.record)==null?void 0:U.email)??(e==null?void 0:e.progress.email)??""),S=u.useRef({token:"",seq:0}),b=(e==null?void 0:e.tokenStored)===!0,C=l.trim(),$=()=>{if(!C&&!b)return;const P=S.current.seq+1;S.current={token:C,seq:P},f(!0),p(null),T.cloudflareZones(C?{token:C}:{}).then(({zones:W})=>{var F;if(S.current.seq!==P)return;d(W);const L=gte(i,W),Q=(F=W.find(ae=>{var V;return ae.name===((V=e==null?void 0:e.record)==null?void 0:V.zone)}))==null?void 0:F.name;L?(L.name&&g(L.name),j(L.zone)):j(Q??(W.length===1?W[0].name:""))}).catch(W=>{S.current.seq===P&&(d(null),p(W instanceof fe?W.message:String(W)))}).finally(()=>{S.current.seq===P&&f(!1)})};u.useEffect(()=>{b&&$()},[]);const A=P=>{o(P),d(null),p(null),f(!1),S.current={token:"",seq:S.current.seq+1}},I=c!==null&&c.length>0,M=x.trim().replace(/\.+$/,""),O=I?M&&y?`${M}.${y}`:"":v.trim(),R=c!==null&&!h&&O!==""&&N.trim()!=="",_={autoComplete:"off",spellCheck:!1,disabled:n};return t.jsxs(de,{gap:"sm",children:[t.jsx(re,{message:s}),t.jsx("p",{className:"ui-card-meta",children:"Open Cloudflare: the token form comes pre-filled with these permissions. Name it, create it, paste it here."}),t.jsx("ul",{className:"access-perms",children:((e==null?void 0:e.permissions)??[]).map(P=>t.jsx("li",{className:"mono",children:P},P))}),t.jsx(se,{children:t.jsx(st,{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&&!b,onClick:$,children:"Check the token"}),children:t.jsx("input",{type:"password",className:"mono",value:l,placeholder:b?"Kept. Paste a new one to replace it":"Paste the token",..._,onChange:P=>A(P.target.value),onBlur:()=>{C&&S.current.token!==C&&$()}})}),h?t.jsx("p",{className:"ui-card-meta",role:"status",children:"Checking the token with Cloudflare…"}):null,t.jsx(re,{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:x,placeholder:"buddi",..._,onChange:P=>g(P.target.value)})}),t.jsx(oe,{label:"Domain",hint:"One of the domains the token can edit.",children:t.jsxs("select",{value:y,disabled:n,onChange:P=>j(P.target.value),children:[y===""?t.jsx("option",{value:"",children:"Choose a domain"}):null,c.map(P=>t.jsx("option",{value:P.name,children:P.name},P.id))]})})]}):t.jsx(oe,{label:"Hostname",hint:"The token lists no domain; type the full name.",children:t.jsx("input",{type:"text",value:v,placeholder:"buddi.example.com",..._,onChange:P=>w(P.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",..._,onChange:P=>k(P.target.value)})})]}):null,t.jsxs(se,{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:y}:{}}),children:"Set it up"})]})]})}const FC="To revoke it in Cloudflare: My Profile → API Tokens.";function vte({progress:e,busy:n,failed:s,onStop:r,onRetry:a,onAdopt:i,onUseSystem:l,onRemove:o,onAgain:c,tokenStored:d=!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&&d&&f!==void 0;return t.jsxs(de,{gap:"sm",children:[t.jsx(re,{message:s}),e.state==="removing"?t.jsx("p",{className:"ui-card-meta",children:"Removing what buddi made…"}):null,e.state==="removed"&&e.removed.length>0?t.jsxs(q,{tone:"good",role:"status",children:["Removed ",wte(e.removed),". Signing in through Cloudflare is off."]}):null,e.error?t.jsx(q,{tone:"critical",role:"alert",children:e.error}):null,e.uninstall?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"ui-card-meta",children:"Cloudflare’s system service is still installed on this computer. To remove it too:"}),t.jsx(fo,{text:e.uninstall})]}):null,p?t.jsxs("div",{children:[t.jsx("p",{children:"Your Cloudflare API token is still kept here, and still valid in Cloudflare."}),t.jsx("p",{className:"ui-card-meta",children:FC})]}):null,e.state==="removed"&&h&&!d?t.jsxs(q,{role:"status",children:["Forgotten here. ",FC]}):null,t.jsxs(se,{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(de,{gap:"sm",children:[t.jsx(re,{message:s}),e.state==="done"&&e.url?t.jsxs(q,{tone:"good",role:"status",children:["Done. Open ",e.url," from another device and sign in as ",e.email,". ",lte]}):null,e.state==="stopped"&&e.error?t.jsx(q,{role:"status",children:e.error}):null,t.jsx("ol",{className:"cat-steps access-run","aria-live":"polite",children:e.steps.map(p=>{var x;return t.jsxs("li",{className:"cat-step","data-state":p.state,children:[t.jsx("span",{className:"cat-step-mark",children:p.state==="done"?t.jsx(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(jte,{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:((x=e.connector)==null?void 0:x.mode)==="system"?"If the system service runs another tunnel, install it again with this tunnel’s token. buddi never runs sudo itself.":"Run this once in a terminal on this computer. buddi never runs sudo itself."}),t.jsx(fo,{text:e.install.command}),t.jsx("span",{className:"ui-card-meta",children:e.install.note})]}):null]})]},p.id)})}),t.jsxs(se,{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 jte({connector:e,live:n,busy:s,onUseSystem:r}){return e.mode==="buddi"&&e.state==="system-daemon"&&e.systemDaemon?t.jsxs("div",{className:"access-run-more",children:[t.jsx("span",{className:"ui-card-meta",children:e.systemDaemon.why}),t.jsx(fo,{text:e.systemDaemon.command}),n&&r?t.jsx(se,{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(fo,{text:e.brew}):null]}):e.detail&&e.state!=="running"?t.jsx("div",{className:"access-run-more",children:t.jsx("span",{className:"ui-card-meta",children:e.detail})}):null}function wte(e){return e.length<=1?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}const yte=2e3,bte={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 dj(e){return bte[e.phase]??e.detail??e.phase}const kte=new Set(["done","failed","rolled-back"]);function qM(e){return e!==void 0&&(kte.has(e.phase)||!!e.finishedAt)}function Nte(e,n=!1){const[s,r]=u.useState(void 0),[a,i]=u.useState(!1),[l,o]=u.useState(null),c=u.useRef(!1);return u.useEffect(()=>{if(!e){r(void 0),i(!1),c.current=!1;return}let d=!1;const h=()=>{n&&c.current||T.backupJob(e).then(m=>{if(!d){if(n&&(KT({step:dj(m)}),(m.phase==="failed"||m.phase==="rolled-back")&&io()),c.current){window.location.reload();return}r(m),o(null),qM(m)&&(d=!0)}}).catch(m=>{if(!d){if(m instanceof fe&&m.status!==0&&m.status<500){n&&io(),o(m.message);return}c.current=!0,n||i(!0)}})};h();const f=window.setInterval(h,yte);return()=>{d=!0,window.clearInterval(f)}},[e,n]),{job:s,away:a,error:l}}function Ste({job:e,away:n,error:s}){return s?t.jsx(re,{message:s}):n?t.jsx(q,{tone:"warning",role:"status",children:"buddi is restarting. This page comes back on its own when it answers again."}):e?e.phase==="rolled-back"||e.phase==="failed"?t.jsxs(q,{tone:"critical",role:"alert",children:[dj(e)," ",e.error??""]}):t.jsxs(q,{tone:e.phase==="done"?"good":void 0,role:"status",children:[dj(e),e.copyLate?" The backup was made, but the copy to your folder did not go through.":"",e.error?` ${e.error}`:""]}):null}function Cte(){var v,w,N,k,S,b,C;const e=pe(()=>T.backups(),[],3e4),n=_M(),s=pe(()=>T.service(),[]),[r,a]=u.useState(null),[i,l]=u.useState(!1),o=Nte(r,i),[c,d]=u.useState(null),[h,f]=u.useState(!1),[m,p]=u.useState(null),x=((v=e.data)==null?void 0:v.supervised)??((w=s.data)==null?void 0:w.supervised),g=m!==null||x===!1,y=((N=e.data)==null?void 0:N.archives)??[],j=($,A=!1)=>{f(!0),d(null),l(A),$().then(I=>{var M;A&&I.job&&gm({kind:"restore",patienceMs:HT}),a(((M=I.job)==null?void 0:M.id)??null)}).catch(I=>{I instanceof fe&&I.status===409?p(I.message):d(I instanceof fe?I.message:String(I))}).finally(()=>{f(!1),e.reload()})};return u.useEffect(()=>{qM(o.job)&&e.reload()},[(k=o.job)==null?void 0:k.phase]),t.jsxs(de,{gap:"lg",children:[(S=n.data)!=null&&S.active?t.jsx(dee,{view:n.data,onLeft:n.reload}):null,t.jsx(re,{message:e.error??c}),t.jsx(Ste,{...o}),t.jsx(Ate,{onSaved:()=>e.reload()}),t.jsx(ge,{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(de,{divided:!0,children:[t.jsx(ge,{children:t.jsxs("p",{className:"ui-card-meta",children:["Kept in ",t.jsx("span",{className:"mono",children:((b=e.data)==null?void 0:b.dir)??"…"}),". A backup holds your agents, conversations, memory and files. It never holds a key."]})}),t.jsx(ge,{children:e.data&&y.length===0?t.jsx(as,{icon:"archive",title:"No backups yet",children:"Make one now, or turn on the nightly backup."}):e.data?t.jsxs(Yr,{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:y.map($=>{var A;return t.jsx($te,{archive:$,busy:h,database:(A=e.data)==null?void 0:A.database,checkout:g,onVerify:()=>j(()=>T.verifyArchive($.name)),onRestore:(I,M)=>j(()=>T.restoreArchive({name:$.name,...I?{passphrase:I}:{},...M?{confirm:M}:{}}),!0)},$.name)})})]}):t.jsx(be,{children:"Loading…"})})]})}),t.jsx(Rte,{}),t.jsx(Pte,{busy:h,checkout:g,checkoutSaid:m,database:(C=e.data)==null?void 0:C.database,onRestore:($,A,I)=>j(()=>T.restoreUpload($,{passphrase:A,confirm:I}),!0)})]})}const Ete={enabled:!1,time:"03:00",keep:7,encryptLocal:!0,copyTo:null};function Ate({onSaved:e}){var p;const n=pe(()=>T.backupSchedule(),[]),[s,r]=u.useState(null),[a,i]=u.useState(!1),[l,o]=u.useState(null),[c,d]=u.useState(!1);u.useEffect(()=>{n.data&&r(n.data)},[n.data]);const h={...Ete,...s??n.data??{}};if(((p=n.data)==null?void 0:p.supervised)===!1)return t.jsx(ge,{title:"Every night",panel:!0,children:t.jsx(ge,{children:t.jsx(q,{tone:"warning",children:n.data.error??"This installation schedules its own backups."})})});const f=x=>{d(!1),r({...h,...x})},m=()=>{i(!0),o(null),T.setBackupSchedule(h).then(x=>{r(x),d(!0),e()}).catch(x=>o(x instanceof fe?x.message:String(x))).finally(()=>i(!1))};return t.jsx(ge,{title:"Every night",panel:!0,foot:t.jsx(E,{variant:"accent",disabled:a,onClick:m,children:"Save"}),children:t.jsxs(de,{divided:!0,children:[t.jsx(ge,{children:t.jsxs(de,{gap:"sm",children:[t.jsx(re,{message:l}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:h.enabled,onChange:x=>f({enabled:x.target.checked})}),t.jsx("span",{children:"Back this buddi up on its own"})]}),t.jsxs(Ts,{children:[t.jsx(oe,{label:"At",children:t.jsx("input",{type:"time",value:h.time,onChange:x=>f({time:x.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:x=>f({keep:Number(x.target.value)||1})})})]}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:h.encryptLocal,onChange:x=>f({encryptLocal:x.target.checked})}),t.jsx("span",{children:"Lock each one with the passphrase"})]})]})}),t.jsx(ge,{children:t.jsxs(de,{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:x=>f({copyTo:x.target.value===""?null:x.target.value})})}),c?t.jsxs(q,{tone:"good",role:"status",children:["Saved.",h.lastRunAt?` Last run ${Ge(h.lastRunAt)}.`:""]}):null]})})]})})}function $te({archive:e,busy:n,database:s,checkout:r,onVerify:a,onRestore:i}){const[l,o]=u.useState(!1),[c,d]=u.useState(""),[h,f]=u.useState("");return t.jsxs(t.Fragment,{children:[t.jsxs("tr",{children:[t.jsx("td",{className:"mono",children:e.name}),t.jsx("td",{children:Ge(e.createdAt)}),t.jsx("td",{children:vs(e.bytes)}),t.jsxs("td",{children:[e.encrypted?t.jsx(Ce,{tone:"good",children:"locked"}):t.jsx(Ce,{tone:"muted",children:"plain"})," ",e.envelopeOk===!1?t.jsx(Ce,{tone:"critical",children:"damaged"}):null]}),t.jsx("td",{children:t.jsxs(se,{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:YM}):t.jsx(JM,{what:`${e.name}, taken ${Ge(e.createdAt)}, ${vs(e.bytes)}`,database:s,needsPassphrase:e.encrypted,passphrase:c,onPassphrase:d,confirm:h,onConfirm:f,busy:n,onCancel:()=>o(!1),onGo:()=>i(c,h)})})}):null]})}const YM="Restoring needs the packaged installation. In a checkout, run: buddi backup restore <file>";function Tte(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 Ite(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 QM({archive:e,onPassphrase:n}){const[s,r]=u.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&&Ite(i).then(o=>{const c=Tte(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 JM({what:e,database:n,needsPassphrase:s,passphrase:r,onPassphrase:a,confirm:i,onConfirm:l,busy:o,onCancel:c,onGo:d}){const h=n??"",f=h===""?i.trim()!=="":i.trim()===h;return t.jsxs(de,{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(QM,{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(se,{align:"end",children:[t.jsx(E,{variant:"ghost",onClick:c,children:"Cancel"}),t.jsx(E,{variant:"danger",disabled:o||!f||s&&r==="",onClick:d,children:"Restore"})]})]})}function Rte(){const[e,n]=u.useState(null),[s,r]=u.useState(""),[a,i]=u.useState(!1),[l,o]=u.useState(null),[c,d]=u.useState(!1),[h,f]=u.useState(!1),[m,p]=u.useState(""),x=()=>{i(!0),o(null),T.revealBackupPassphrase(h?m:void 0).then(y=>{n(y.passphrase),f(!1),p("")}).catch(y=>{if(y instanceof fe&&y.status===403&&!h){f(!0);return}o(y instanceof fe?y.message:String(y))}).finally(()=>i(!1))},g=()=>{i(!0),o(null),T.setBackupPassphrase(s.trim()).then(y=>{n(y.passphrase),r(""),d(!0)}).catch(y=>o(y instanceof fe?y.message:String(y))).finally(()=>i(!1))};return t.jsx(ge,{title:"The passphrase",panel:!0,children:t.jsxs(de,{divided:!0,children:[t.jsx(ge,{children:t.jsxs(de,{gap:"sm",children:[t.jsx(re,{message:l}),t.jsx("p",{className:"ui-card-meta",children:"This is the only thing that opens an encrypted backup. Write it down."}),e?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"backup-phrase mono",children:e}),t.jsx(se,{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:y=>p(y.target.value),onKeyDown:y=>{y.key==="Enter"&&m!==""&&x()}})}):null,t.jsx(se,{align:"end",children:t.jsx(E,{disabled:a||h&&m==="",onClick:x,children:"Reveal"})})]}),c?t.jsx(q,{tone:"good",role:"status",children:"Saved. Backups made from now on use it; older ones keep the one they were made with."}):null]})}),t.jsx(ge,{children:t.jsxs(de,{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:y=>{d(!1),r(y.target.value)}})}),t.jsx(se,{align:"end",children:t.jsx(E,{variant:"accent",disabled:a||s.trim()==="",onClick:g,children:"Use this one"})})]})})]})})}function Pte({busy:e,checkout:n,checkoutSaid:s,database:r,onRestore:a}){const[i,l]=u.useState(null),[o,c]=u.useState(""),[d,h]=u.useState(""),[f,m]=u.useState(!1);return n?t.jsx(ge,{title:"Restore from a file",panel:!0,children:t.jsx(ge,{children:t.jsx(q,{tone:"warning",children:s??YM})})}):t.jsx(ge,{title:"Restore from a file",panel:!0,children:t.jsxs(de,{divided:!0,children:[t.jsx(ge,{children:t.jsxs(de,{gap:"sm",children:[t.jsx("p",{className:"ui-card-meta",children:"A backup from another buddi, or one you keep somewhere else."}),t.jsxs(Ts,{children:[t.jsx(oe,{label:"The backup file",children:t.jsx("input",{type:"file",onChange:p=>{var x;m(!1),l(((x=p.target.files)==null?void 0:x[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(QM,{archive:i.name,onPassphrase:c}):null,f?null:t.jsx(se,{align:"end",children:t.jsx(E,{variant:"accent",disabled:e||!i,onClick:()=>m(!0),children:"Restore"})})]})}),f&&i?t.jsx(ge,{children:t.jsx(JM,{what:`${i.name}, ${vs(i.size)}`,database:r,needsPassphrase:!1,passphrase:o,onPassphrase:c,confirm:d,onConfirm:h,busy:e,onCancel:()=>m(!1),onGo:()=>a(i,o,d)})}):null]})})}const uj="gpt-5.5",_C="gpt-6.1-sol";function XM(e){return e.source!=="provider"?null:e.models.some(n=>n.id===_C)?_C:null}const ZM="gemini-2.5-pro";function _m(e){return e.replace(/^models\//,"")}const jb=/(image|tts|audio|live|embedding|vision|robotics|transcribe)/;function e2(e){const n=e.map(_m);let s;for(const r of n){const a=/^gemini-(\d+(?:\.\d+)*)-pro(?:-(.+))?$/.exec(r);if(!a||jb.test(a[2]??""))continue;const i=a[1].split(".").map(Number),l=(a[2]??"")!=="";(!s||Nf(i,s.version)>0||Nf(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 t2(e){let n;for(const s of e.map(_m)){const r=/^gemini-(\d+(?:\.\d+)*)-flash(?:-(.+))?$/.exec(s);if(!r||/lite/.test(r[2]??"")||jb.test(r[2]??""))continue;const a=r[1].split(".").map(Number),i=(r[2]??"")!=="";(!n||Nf(a,n.version)>0||Nf(a,n.version)===0&&n.preview&&!i)&&(n={id:s,version:a,preview:i})}return n==null?void 0:n.id}function n2(e){return/^gemini-[\d.]+-pro(?:-|$)/.test(_m(e))}function Mte(e){return[...new Set(e.map(_m).filter(n=>n.startsWith("gemini-")&&!jb.test(n)))]}function s2(e){return e.httpStatus===429||e.state==="rate-limited"||e.state==="quota-exhausted"}function Nf(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 r2(e,n){if(!n||e.kind!=="openai-compatible")return!1;const s=r=>r.replace(/\/+$/,"");return s(e.baseUrl)===s(n)}function Ote({embedded:e,account:n}={}){const{data:s,error:r,reload:a,loading:i}=pe(()=>T.providerAccounts(),[]),[l,o]=u.useState(!1),[c,d]=u.useState(null),[h,f]=u.useState(""),[m,p]=u.useState(!1),[x,g]=u.useState(!1),[y,j]=u.useState(n??null);u.useEffect(()=>{n&&j(n)},[n]);const v=s==null?void 0:s.accounts.some(b=>{var C;return((C=b.login)==null?void 0:C.state)==="pending"&&b.login.expiresAt&&Date.parse(b.login.expiresAt)>Date.now()});u.useEffect(()=>{if(!v)return;const b=setInterval(a,2e3);return()=>clearInterval(b)},[v,a]);const w=async(b,C)=>{o(!0),d(null),f(""),g(!1);try{const $=await b();return f(($==null?void 0:$.warning)??C),a(),!0}catch($){return d($ instanceof Error?$.message:"Could not apply change."),a(),!1}finally{o(!1)}},N=(s==null?void 0:s.accounts)??[],k=N.find(b=>b.id===y)??N[0],S=b=>{var C;return r2(b,(C=s==null?void 0:s.gemini)==null?void 0:C.baseUrl)?"Gemini":a2(b)};return t.jsxs(js,{embedded:e,title:"Model accounts",lede:"Give each API key or subscription a name, then pick one per agent. An account never falls back to another credential on its own.",children:[t.jsx(re,{message:r??c}),h&&t.jsx(q,{tone:"good",role:"status",children:h}),x&&t.jsx(q,{role:"status",children:i?"Refreshing account status…":r?"Could not refresh account status. Try again.":"Account status refreshed. This checks saved credentials; it does not renew subscription tokens or test connections."}),!s&&!r&&t.jsx(be,{children:"Loading accounts…"}),r&&t.jsx(se,{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(Vte,{accounts:N,codexEnabled:s.codexEnabled,anthropicOAuthEnabled:s.anthropicOAuthEnabled,gemini:s.gemini,busy:l,run:w,onDone:b=>{p(!1),b&&j(b)}})})}),t.jsx(ge,{title:"Accounts",aside:`Secrets live in the ${Dte(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:()=>{d(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(as,{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(b=>t.jsxs("button",{type:"button",className:"accounts-row","aria-pressed":(k==null?void 0:k.id)===b.id,onClick:()=>j(b.id),children:[t.jsx(Lte,{kind:b.kind,auth:b.auth}),t.jsxs("span",{className:"accounts-row-text",children:[t.jsx("span",{className:"accounts-row-name",children:b.label}),bd(b)?t.jsxs("span",{className:"accounts-row-sub","data-tone":"warning",children:[S(b)," · back at ",wb(bd(b).until)]}):t.jsxs("span",{className:"accounts-row-sub",children:[S(b)," · ",b.assignedAgents.length===0?"no agents":`${b.assignedAgents.length} agent${b.assignedAgents.length===1?"":"s"}`]})]}),t.jsx(l2,{account:b})]},b.id))}),k?t.jsx(Wte,{account:k,provider:S(k),anthropicOAuthEnabled:s.anthropicOAuthEnabled,busy:l,run:w},`${k.id}:${k.revision}`):null]})})]})]})}function Dte(e){return e==="keychain"?"macOS Keychain":e==="file"?"encrypted file vault":e==="none"?"vault (none configured)":e}function a2(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":fb(e)?"mlxh":"OpenAI-compatible"}function i2(e){return e.detectedContextWindowSource==="mlxh"?XX(e.detectedContextWindowTokens):e.detectedContextWindowSource!=="provider"?"assumed":e.kind==="codex"?"from ChatGPT":"from the provider"}function Lte({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 Fte(e){return e==="connected"?"good":["rate-limited","quota-exhausted","provider-unavailable"].includes(e)?"warning":"critical"}function bd(e,n=Date.now()){const s=e.rateLimit;return e.enabled&&e.configured&&s&&Date.parse(s.until)>n?s:null}const _te=()=>Intl.DateTimeFormat().resolvedOptions().timeZone;function wb(e,n=new Date,s=_te()){const r=new Date(e),a=i=>i.toLocaleDateString("en-CA",{timeZone:s});return a(r)===a(n)?$t(r,s):a(r)===a(new Date(n.getTime()+864e5))?`tomorrow at ${$t(r,s)}`:im(r,s)}function l2({account:e,long:n}){const s=bd(e);if(s){const i=`Rate-limited until ${wb(s.until)}`;return t.jsx("span",{title:i,children:t.jsx(Ce,{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(Ce,{tone:r,children:a})}function zte({id:e}){const[n,s]=u.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 Ute({account:e,provider:n,children:s}){const r=bd(e);if(!r)return null;const a=r.provider??n,i=wb(r.until);if(r.scope==="day"){const l=e.assignedAgents,o=l.length===1?l[0]:"its agents",c=r.provider==="ChatGPT",d=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:d,action:l.length>0?t.jsx(st,{size:"sm",href:l.length===1?Pt(l[0],"setup","brain"):yt,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 zC({test:e}){return e.state==="connected"?null:t.jsx(Kt,{summary:"Details",children:t.jsx(Qt,{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 Bte({account:e,provider:n}){const s=e.test;return bd(e)&&(!s||["rate-limited","quota-exhausted","connected"].includes(s.state))?t.jsx(Ute,{account:e,provider:n,children:s&&t.jsx(zC,{test:s})}):s?t.jsxs(q,{role:"status",tone:Fte(s.state),children:[t.jsx("p",{children:s.message}),t.jsx(zC,{test:s})]}):null}function yb(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 Wte({account:e,provider:n,busy:s,run:r,anthropicOAuthEnabled:a}){const[i,l]=u.useState(!1),[o,c]=u.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(l2,{account:e,long:!0})]}),t.jsx(Qt,{items:[{label:"Provider",value:n},{label:"Default model",value:t.jsx("span",{className:"mono",children:e.defaultModel||"—"})},{label:"Context window",value:t.jsx("span",{className:"mono",children:`${(e.contextWindowTokens??e.detectedContextWindowTokens??0).toLocaleString()} tokens${e.contextWindowTokens?"":` (${i2(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(d=>t.jsx("a",{href:Pt(d,"setup","brain"),children:d},d))}):t.jsxs("span",{className:"ui-row",children:[t.jsx("span",{className:"muted",children:"No agents"}),t.jsx("a",{href:yt,children:"Assign to an agent"})]})},...e.tokenExpiresAt?[{label:"Access token",value:`expires ${ft(e.tokenExpiresAt,Intl.DateTimeFormat().resolvedOptions().timeZone)} (not your subscription renewal date)`}]:[],{label:"ID",value:t.jsx(zte,{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(d2,{account:e,enabled:!!a,busy:s,run:r}),e.kind==="codex"&&t.jsx(o2,{account:e,busy:s,run:r}),e.auth==="device-key"&&t.jsx(c2,{account:e,busy:s,run:r}),t.jsxs(se,{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({...yb(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(Bte,{account:e,provider:n}),i&&t.jsx(Je,{title:`Edit ${e.label}`,onClose:()=>l(!1),children:t.jsx(Hte,{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(se,{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(Kt,{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 o2({account:e,busy:n,run:s}){var r,a,i;return t.jsxs(t.Fragment,{children:[t.jsxs(se,{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(pb,{code:e.login.userCode,large:!0}),e.login.verificationUrl&&t.jsx(se,{children:t.jsx(st,{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 ",$t(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 Hte({account:e,busy:n,run:s,onDone:r,codexEnabled:a,anthropicOAuthEnabled:i}){const[l,o]=u.useState((e==null?void 0:e.label)??""),[c,d]=u.useState((e==null?void 0:e.kind)??"anthropic"),[h,f]=u.useState((e==null?void 0:e.auth)??"api-key"),[m,p]=u.useState((e==null?void 0:e.baseUrl)??""),[x,g]=u.useState((e==null?void 0:e.defaultModel)??"claude-sonnet-5"),[y,j]=u.useState(""),[v,w]=u.useState(e!=null&&e.contextWindowTokens?String(e.contextWindowTokens):""),N=S=>{d(S),f(S==="codex"?"chatgpt":"api-key"),j(""),p(S==="openai-compatible"?"http://localhost:11434/v1":""),g(S==="anthropic"?"claude-sonnet-5":S==="openai"?"gpt-5":"")},k=!l.trim()||!x.trim();return t.jsxs("form",{className:"ui-stack",onSubmit:S=>{S.preventDefault();const b=y;j(""),s(()=>T.saveProviderAccount({...e?{id:e.id,revision:e.revision}:{},label:l,kind:c,auth:h,baseUrl:m,defaultModel:x,enabled:(e==null?void 0:e.enabled)??!0,contextWindowTokens:v.trim()?Number(v):null,...b.trim()?{secret:b}:{}}),"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:S=>o(S.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:S=>{S.target.value==="anthropic-oauth"?(N("anthropic"),f("anthropic-oauth")):N(S.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:S=>p(S.target.value)})}),t.jsx(oe,{label:"Authentication",children:t.jsxs("select",{disabled:!!e,value:h,onChange:S=>{f(S.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(se,{valign:"end",children:t.jsx(mb,{accountId:e!=null&&e.configured&&e.enabled?e.id:void 0,label:"Default model",value:x,onChange:g,disabled:n,...(e==null?void 0:e.kind)==="codex"?{origin:"from ChatGPT",suggest:XM}:{}},`${e==null?void 0:e.id}:${e==null?void 0:e.revision}`)}),t.jsx(oe,{label:"Context window",hint:fb(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:v,placeholder:e!=null&&e.detectedContextWindowTokens?`${e.detectedContextWindowTokens} (${i2(e)})`:"assumed from the model",onChange:S=>w(S.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:y,onChange:S=>j(S.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(se,{align:"end",children:[t.jsx(E,{onClick:r,children:"Cancel"}),t.jsx(E,{type:"submit",variant:"accent",disabled:k,children:"Save account"})]})]}),k&&t.jsx("p",{className:"muted",children:"Enter an account name and default model to enable Save account. The example name is a placeholder."})]})}function c2({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=u.useRef(s);a.current=s,u.useEffect(()=>{if(!(r!=null&&r.attemptId))return;let c=!1,d=!1;const h=setInterval(()=>{c||d||(d=!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(()=>{d=!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 d=await T.ollamaConnect(e.id,e.revision);return c&&(c.location.href=d.verificationUrl),d}catch(d){throw c==null||c.close(),d}},"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(se,{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&&$t(new Date(r.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone),"."]})]})]})}function d2({account:e,enabled:n,busy:s,run:r}){var l,o,c,d,h;const[a,i]=u.useState("");return u.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(se,{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"}),((d=e.login)==null?void 0:d.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&&$t(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(se,{align:"end",children:t.jsx(E,{type:"submit",variant:"accent",disabled:s||!a.trim(),children:"Complete Claude sign-in"})})]})]})}const jg={anthropic:"claude-sonnet-5",openai:"gpt-5",codex:uj};function wg(e,n,s){return hj(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 hj(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 Kte="That key was refused. Check it and paste it again.";function Vte({accounts:e,busy:n,run:s,onDone:r,codexEnabled:a,anthropicOAuthEnabled:i,gemini:l}){const o=e.map(Z=>Z.label),[c,d]=u.useState(null),[h,f]=u.useState("anthropic"),[m,p]=u.useState("api-key"),[x,g]=u.useState(()=>wg("anthropic","api-key",o)),[y,j]=u.useState(!1),[v,w]=u.useState(""),[N,k]=u.useState(""),[S,b]=u.useState(null),[C,$]=u.useState(!1),[A,I]=u.useState(""),[M,O]=u.useState(""),[R,_]=u.useState(!1),[z,U]=u.useState(!1),[P,W]=u.useState(!1),[L,Q]=u.useState(void 0),F=(Z,ve,$e=!1)=>{f(Z),p(ve),k(""),b(null),I(""),O(""),_(!1),U($e),W(!1),Q(void 0),w($e?"":Z==="openai-compatible"?"http://localhost:11434/v1":""),y||g($e?wg(Z,"device-key",o):wg(Z,ve,o))},ae=Z=>{F("openai-compatible",Z?"api-key":"device-key",!0),Z&&T.ollama().then(ve=>w(ve.cloudBaseUrl)).catch(()=>{})},V=()=>{l&&(F("openai-compatible","api-key"),W(!0),w(l.baseUrl),y||g(hj("Gemini",o)))},J=()=>{F("openai-compatible","none"),Q(null),y||g(hj("mlxh",o)),T.mlxh().then(Z=>{Q(Z),w(Z.baseUrl)}).catch(()=>Q(void 0))},H=L!==void 0,X=c?e.find(Z=>Z.id===c):void 0;if(c)return X?t.jsx(Gte,{account:X,busy:n,run:s,anthropicOAuthEnabled:i,onDone:()=>r(X.id)}):t.jsx(be,{children:"Saving…"});const G=h==="openai-compatible"&&m!=="device-key",ce=h==="codex"||m==="anthropic-oauth"||m==="device-key",xe=!ce&&(m==="none"||N.trim()!=="")&&(!G||v.trim()!==""),De=async()=>{var Z,ve;$(!0),I("");try{const $e=await T.probeModels({kind:h,auth:m,...G?{baseUrl:v}:{},...N.trim()?{secret:N}:{}});b($e),M||O(((Z=$e.models.find(Se=>Se.isDefault))==null?void 0:Z.id)??((ve=$e.models[0])==null?void 0:ve.id)??"")}catch($e){I($e instanceof Error?$e.message:"Could not load models. You can still enter a custom model.")}finally{$(!1)}},B=M.trim(),ne=!x.trim()||G&&!v.trim()||G&&!P&&!H&&!B||P&&!N.trim()||H&&!(L!=null&&L.running);return t.jsxs("form",{className:"ui-stack",onSubmit:Z=>{var me;Z.preventDefault();const ve=N;k("");let $e=B||(H?rj(L)??((me=L==null?void 0:L.models[0])==null?void 0:me.id):void 0)||(m==="device-key"?ah:jg[h])||"claude-sonnet-5",Se;(async()=>{if(P){$e=ZM;try{const ke=(await T.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:v,secret:ve})).models.map(Be=>Be.id);$e=e2(ke)??$e,Se=n2($e)?t2(ke):void 0}catch{}}let Ee,Pe=!1;!await s(async()=>{if(Ee=await T.saveProviderAccount({label:x,kind:h,auth:m,baseUrl:v,defaultModel:$e,enabled:!0,...ve.trim()?{secret:ve}:{}}),m!=="api-key")return Ee;const he=await T.testProviderAccount(Ee.id);if(he.state==="connected")return{...Ee,warning:`Account saved. ${he.message}`};if(_w(he)){const ke=Ee.id;Ee=void 0;try{const Be=(await T.providerAccounts()).accounts.find(qe=>qe.id===ke);Be&&await T.removeProviderAccount(ke,Be.revision)}catch{}throw new Error(Kte)}if(P&&Se&&s2(he)){const ke=(await T.providerAccounts()).accounts.find(Be=>Be.id===Ee.id);if(ke&&(await T.saveProviderAccount({...yb(ke),defaultModel:Se}),(await T.testProviderAccount(Ee.id)).state==="connected"))return{...Ee,warning:`Account saved on ${Se}. 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 Pe=!0,{...Ee,warning:`Account saved. ${he.message}`}},"Account saved.")||!Ee||(P||H||Pe?d(Ee.id):B||!ce?r(Ee.id):d(Ee.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":z?"ollama-cloud":P?"gemini":H?"mlxh":h,onChange:Z=>{if(Z.target.value==="anthropic-oauth")F("anthropic","anthropic-oauth");else if(Z.target.value==="gemini")V();else if(Z.target.value==="mlxh")J();else if(Z.target.value==="ollama-cloud")F("openai-compatible","device-key",!0);else{const ve=Z.target.value;F(ve,ve==="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:x,onChange:Z=>{g(Z.target.value),j(!0)},placeholder:"Anthropic — Personal"})}),z&&t.jsxs("label",{className:"ui-row",children:[t.jsx("input",{type:"checkbox",checked:m==="api-key",onChange:Z=>ae(Z.target.checked)}),t.jsx("span",{children:"Use a key instead"})]}),G&&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:v,onChange:Z=>{w(Z.target.value),b(null)}})}),!P&&!H&&t.jsx(oe,{label:"Authentication",children:t.jsxs("select",{value:m,onChange:Z=>{p(Z.target.value),k(""),b(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=>{k(Z.target.value),b(null)}})}),H?L===null?t.jsx("p",{className:"muted",children:"Looking for mlxh on this computer…"}):L!=null&&L.running?t.jsxs(de,{gap:"sm",children:[t.jsxs("p",{className:"muted",children:["mlxh answers with ",L.models.length===1?"one model":`${L.models.length} models`,". No key: mlxh takes any. buddi starts on ",rj(L)??"the first","; the next step lists the rest. A model that is not loaded takes up to a minute on its first answer."]}),L.models.some(Z=>Z.kind==="image")?t.jsxs("p",{className:"muted",children:[L.models.filter(Z=>Z.kind==="image").map(Z=>Z.id).join(", "),": ",NM,"."]}):null]}):t.jsx(q,{tone:"warning",children:kM((L==null?void 0:L.baseUrl)??v)}):P&&l?t.jsxs("p",{className:"muted",children:[t.jsx("a",{href:l.keyUrl,target:"_blank",rel:"noreferrer",children:"Get a key at aistudio.google.com"}),". buddi picks the newest Gemini Pro your key can reach; the next step lists the rest."]}):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"}),S?t.jsxs("div",{className:"ui-row",children:[t.jsxs("select",{"aria-label":"Model",value:R?"__custom__":M,onChange:Z=>{Z.target.value==="__custom__"?(_(!0),O("")):(_(!1),O(Z.target.value))},children:[S.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 De(),children:C?"Loading…":"Reload"})]}):t.jsxs("div",{className:"ui-row",children:[t.jsx(E,{disabled:C||!xe,onClick:()=>void De(),children:C?"Loading models…":"Load models"}),G?t.jsx("span",{className:"muted",children:"Ask the endpoint what it serves."}):t.jsxs("span",{className:"muted",children:["Optional now: ",jg[h]," is used until you pick one."]})]}),R||G&&!S?t.jsx("input",{"aria-label":"Custom model",required:G,maxLength:150,value:M,onChange:Z=>O(Z.target.value),placeholder:G?"qwen3:8b":jg[h]}):null,A?t.jsx("span",{className:"ui-field-hint critical",role:"alert",children:A}):null,S!=null&&S.truncated?t.jsx("span",{className:"ui-field-hint",children:"Showing the first part of the provider’s list."}):null]}),t.jsxs(se,{align:"end",children:[t.jsx(E,{onClick:()=>r(),children:"Cancel"}),t.jsx(E,{type:"submit",variant:"accent",disabled:ne,children:"Save account"})]})]}),ne&&!H&&t.jsxs("p",{className:"muted",children:["Enter an account name",P?" and a key":G?", an endpoint and a model":""," to enable Save account."]})]})}function Gte({account:e,busy:n,run:s,anthropicOAuthEnabled:r,onDone:a}){const[i,l]=u.useState(e.defaultModel),o=e.configured;return t.jsxs(de,{gap:"lg",children:[t.jsxs(q,{tone:"good",children:["Saved “",e.label,"”."]}),e.auth==="anthropic-oauth"&&!o?t.jsx(d2,{account:e,enabled:!!r,busy:n,run:s}):null,e.kind==="codex"&&!o?t.jsx(o2,{account:e,busy:n,run:s}):null,e.auth==="device-key"&&!o?t.jsx(c2,{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(se,{valign:"end",children:t.jsx(mb,{accountId:e.enabled?e.id:void 0,label:"Default model",value:i,onChange:l,disabled:n,...e.kind==="codex"?{origin:"from ChatGPT",suggest:XM,onSuggest:c=>l(d=>d===uj&&e.defaultModel===uj?c:d)}:{}},`${e.id}:${e.revision}`)}),t.jsxs(se,{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({...yb(e),defaultModel:i}),"Default model saved.").then(c=>{c&&a()})},children:"Done"})]})]}):t.jsx(se,{children:t.jsx(E,{onClick:a,children:"Finish later"})})]})}async function el(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 u2="Passwords, keys and links your agents use without ever seeing them. Each goes only where you allow.";function qte(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 Yte({embedded:e,timezone:n,secret:s,adding:r,navigate:a}={}){const i=pe(()=>T.secrets(),[]),l=pe(()=>T.providerAccounts(),[]),o=u.useMemo(()=>{var x;return new Map((((x=l.data)==null?void 0:x.accounts)??[]).map(g=>[g.id,{label:g.label,provider:a2(g)}]))},[l.data]),[c,d]=u.useState(s?{what:"replace",name:s}:r?{what:"add"}:null);u.useEffect(()=>{s&&d({what:"replace",name:s})},[s]),u.useEffect(()=>{r&&d({what:"add"})},[r]);const h=()=>{d(null),(s||r)&&a&&a(ze("secrets"))},f=i.data,m=u.useMemo(()=>{const x=new Map;for(const g of(f==null?void 0:f.secrets)??[]){const y=Na(g);x.set(y,[...x.get(y)??[],g])}return[...x.entries()].sort(([g],[y])=>oV(g,y))},[f]),p=c&&c.what!=="add"?(f==null?void 0:f.secrets.find(x=>x.name===c.name))??null:null;return t.jsxs(js,{embedded:e,title:"Keys and secrets",lede:u2,actions:e?void 0:t.jsx(E,{variant:"accent",size:"sm",onClick:()=>d({what:"add"}),children:"Add a secret"}),children:[t.jsxs(de,{gap:"lg",children:[!f&&!i.error?t.jsx(be,{children:"Opening the vault…"}):null,i.error?t.jsxs(de,{gap:"sm",children:[t.jsx(re,{message:i.error}),t.jsx(se,{children:t.jsx(E,{onClick:i.reload,children:"Retry"})})]}):null,f&&f.secrets.length===0?t.jsx(rt,{children:t.jsx(as,{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(rt,{flush:!0,children:m.map(([x,g])=>{const y=lV(x);return t.jsxs("section",{className:"secrets-group","aria-label":y.title,children:[t.jsxs("header",{className:"secrets-group-head",children:[t.jsx("h3",{className:"secrets-group-title",children:y.title}),t.jsx("span",{className:"secrets-group-aside",children:y.aside})]}),t.jsx(ut,{children:g.map(j=>t.jsx(Jte,{secret:j,group:x,accounts:o,timezone:n,onOpen:v=>d({what:v,name:j.name})},j.name))})]},x)})}):null,f&&f.ownKeys.length>0?t.jsx(Kt,{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((x,g)=>t.jsxs("span",{children:[g>0?", ":"",t.jsx("code",{className:"mono",children:x})]},x)),". They aren’t changed here, and buddi hides them in whatever it sends out, like your own."]})}):null]}),(c==null?void 0:c.what)==="add"&&f?t.jsx(ene,{destinations:f.destinations,onClose:h,onChanged:i.reload}):null,p&&(c==null?void 0:c.what)==="sheet"?t.jsx(Xte,{secret:p,accounts:o,timezone:n,onClose:h,onOpen:x=>d({what:x,name:p.name})}):null,p&&(c==null?void 0:c.what)==="replace"?t.jsx(tne,{secret:p,title:Ac(p,o),onClose:h,onChanged:i.reload}):null,p&&(c==null?void 0:c.what)==="rename"?t.jsx(nne,{secret:p,onClose:h,onChanged:i.reload}):null,p&&(c==null?void 0:c.what)==="places"&&f?t.jsx(sne,{secret:p,title:Ac(p,o),destinations:f.destinations,onClose:h,onChanged:i.reload}):null,p&&(c==null?void 0:c.what)==="delete"?t.jsx(rne,{secret:p,title:Ac(p,o),onClose:h,onChanged:i.reload}):null]})}const Sf=e=>n=>{n.stopPropagation(),e==null||e()};function h2({fix:e,onOpen:n}){return"href"in e?t.jsx(st,{size:"sm",href:e.href,onClick:Sf(),children:e.label}):t.jsx(E,{size:"sm",onClick:Sf(()=>n(e.action)),children:e.label})}function Qte(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=Pv(r.id)}}:null,{label:"Usage history",onSelect:()=>s("sheet")},Fl(e)?"separator":null,Fl(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")},Fl(e)?"separator":null,Fl(e)?{label:"Remove…",tone:"critical",onSelect:()=>s("delete")}:null]}function Jte({secret:e,group:n,accounts:s,timezone:r,onOpen:a}){const i=Ac(e,s),l=uV(e,s),o=dV(e,r),c=[o??Uy(e),o&&!e.lastUse?null:pV(e)].filter(Boolean).join(" · "),d=CR(e),h=ER(e),f=Mv(e),m=yR(n)?NR(e):null;return t.jsx(ot,{onClick:()=>a("sheet"),label:`${i}: details`,lead:t.jsx(Yn,{icon:qte(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}),d?t.jsx("span",{className:"secrets-status","data-tone":"warning",children:d.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:[d!=null&&d.fix?t.jsx(h2,{fix:d.fix,onOpen:a}):null,h&&Fl(e)||e.login&&n==="mine"?t.jsx(E,{size:"sm",variant:"ghost",onClick:Sf(()=>a("delete")),children:"Remove…"}):null,m?t.jsxs("a",{className:"secrets-managed",href:m.href,onClick:Sf(),children:[m.label,t.jsx(ie,{name:"chevron-right",size:12})]}):t.jsx(Qn,{label:`More for ${i}`,items:Qte(e,n,a),sheet:{title:i,sub:c}})]})})}function Xte({secret:e,accounts:n,timezone:s,onClose:r,onOpen:a}){const i=Na(e),l=Ac(e,n),o=CR(e),c=ER(e),d=[...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(se,{children:[t.jsx(E,{variant:"danger-ghost",onClick:()=>a("delete"),children:"Delete…"}),t.jsx(gt,{}),t.jsx(E,{onClick:()=>a("rename"),children:"Rename…"}),t.jsx(E,{variant:"accent",onClick:()=>a("replace"),children:"Replace value…"})]}):void 0,children:t.jsxs(de,{gap:"lg",children:[t.jsx(Qt,{items:[{label:"Where it may go",value:Uy(e)||"Nowhere yet"},...d.length===1&&i==="mine"?[{label:"Asks you",value:xV[d[0]]}]:[],{label:"Last used",value:h?`${Ge(h.at)}${h.agentId?` by ${h.agentId}`:""}`:"Never"}]}),o?t.jsx(q,{tone:"warning",action:o.fix?t.jsx(h2,{fix:o.fix,onOpen:a}):void 0,children:o.text}):null,c?Fl(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,Mv(e)?t.jsx(q,{children:Mv(e)}):null,t.jsxs(de,{gap:"sm",children:[t.jsx("h3",{className:"secrets-sheet-head",children:"Usage history"}),t.jsx(Zte,{name:e.name,timezone:s})]}),t.jsx(Kt,{summary:"Details",children:t.jsxs(de,{gap:"sm",children:[t.jsx(Qt,{items:[{label:"Stored as",value:t.jsx("code",{className:"mono secrets-mono",children:e.name})},...e.bindings.map((m,p)=>({key:`b${p}`,label:p===0?"Bindings":"",value:t.jsxs("code",{className:"mono secrets-mono",children:[m.kind," ",xR(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 Zte({name:e,timezone:n}){const s=pe(()=>T.secretUses(e,50),[e]);if(s.error)return t.jsx(re,{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(ut,{children:r.map((a,i)=>{const l=yV(a);return t.jsx(ot,{title:t.jsx("span",{className:"secrets-history","data-tone":l.tone,children:l.text}),sub:`${ft(a.at,n??"UTC")} · ${a.agent??(a.plugin?`the ${a.plugin} plugin`:"you")}`},i)})})}function f2({title:e,result:n,scrubbed:s,busy:r,failure:a,onScrub:i}){const l=sV(n);return t.jsxs(de,{gap:"sm",children:[t.jsxs(q,{tone:"good",role:"status",children:["Saved “",e,"”. Its value is never shown again."]}),t.jsx("p",{className:"secrets-note",children:l||"Nothing of the value sits where buddi already holds text."}),t.jsx(re,{message:a}),l?t.jsx(se,{children:t.jsx(E,{variant:"accent",disabled:r||s!==null,onClick:i,children:s===null?"Scrub the history":rV(s)||"Nothing of it was left to replace."})}):null]})}function m2({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(de,{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,d=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(x=>x.kind===f))==null?void 0:p.maxRule;a(l,{kind:f,rule:m?uf(m):i.rule})},children:d.map(h=>t.jsx("option",{value:h.kind,children:vV(h.kind)},h.kind))})}),t.jsx(oe,{label:"The place",children:t.jsx("input",{type:"text",spellCheck:!1,disabled:s,value:i.target,placeholder:wV(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:pR(c).map(h=>t.jsx("option",{value:h,children:jV[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: ",J9(i.kind),"."]})]},l)}),n.length===0?t.jsx("p",{className:"ui-field-hint",children:Q9}):null,e.length?t.jsx(se,{children:t.jsx(E,{size:"sm",disabled:s,onClick:()=>r([...n,{kind:e[0].kind,target:"",rule:uf(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 p2(e){const n=e.map(r=>tV(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 ene({destinations:e,onClose:n,onChanged:s}){const[r,a]=u.useState(""),[i,l]=u.useState(""),[o,c]=u.useState(!1),[d,h]=u.useState(()=>e.length?[{kind:e[0].kind,target:"",rule:uf(e[0].maxRule)}]:[]),[f,m]=u.useState(!1),[p,x]=u.useState(null),[g,y]=u.useState(null),[j,v]=u.useState(null),w=async()=>{const k=p2(d);if(!k.ok){x(k.error);return}const S=i;l("");const b=await el("secrets.put",{name:r.trim(),value:S,totp:o,bindings:k.bindings},m,x);b!==null&&(y({name:r.trim(),result:b}),s())},N=async()=>{const k=await el("secrets.scrub_history",{name:(g==null?void 0:g.name)??""},m,x);k!==null&&(v(k),s())};return g?t.jsx(Je,{title:"Add a secret",onClose:n,foot:t.jsx(se,{align:"end",children:t.jsx(E,{onClick:n,children:"Done"})}),children:t.jsx(f2,{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(se,{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:k=>{k.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:k=>a(k.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:k=>l(k.target.value)})}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:o,onChange:k=>c(k.target.checked)}),t.jsx("span",{children:"It’s a one-time-code seed — buddi fills the current code, never the seed"})]})]}),t.jsxs("fieldset",{disabled:f,className:"ui-stack","data-gap":"sm",children:[t.jsx("h3",{className:"secrets-sheet-head",children:"Where it may go"}),t.jsx("p",{className:"secrets-note",children:"Agents can use it only in these places. Anywhere else, buddi holds it back and the row says so."}),t.jsx(m2,{destinations:e,bindings:d,disabled:f,onChange:h})]}),p?t.jsx(q,{tone:"critical",role:"alert",children:p}):null]})})}function tne({secret:e,title:n,onClose:s,onChanged:r}){const[a,i]=u.useState(""),[l,o]=u.useState(!1),[c,d]=u.useState(null),[h,f]=u.useState(null),[m,p]=u.useState(null),x=async()=>{const y=a;i("");const j=await el("secrets.put",{name:e.name,value:y,totp:e.totp,bindings:e.bindings.map(({kind:v,target:w,rule:N})=>({kind:v,target:w,rule:N}))},o,d);j!==null&&(f(j),r())},g=async()=>{const y=await el("secrets.scrub_history",{name:e.name},o,d);y!==null&&(p(y),r())};return h?t.jsx(zt,{title:`Replaced the value of “${n}”`,onClose:s,foot:t.jsx(E,{variant:"accent",onClick:s,children:"Done"}),children:t.jsx(f2,{title:n,result:h,scrubbed:m,busy:l,failure:c,onScrub:()=>void g()})}):t.jsx(zt,{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:y=>{y.preventDefault(),a!==""&&x()},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:y=>i(y.target.value)})}),t.jsx(re,{message:c})]})})}function nne({secret:e,onClose:n,onChanged:s}){const[r,a]=u.useState(e.name),[i,l]=u.useState(!1),[o,c]=u.useState(null),d=r.trim()!==""&&r.trim()!==e.name,h=async()=>{await el("secrets.rename",{name:e.name,to:r.trim()},l,c)!==null&&(s(),n())};return t.jsx(zt,{title:`Rename “${e.name}”`,onClose:n,foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx(E,{type:"submit",form:"secrets-rename",variant:"accent",disabled:i||!d,children:"Rename"})]}),children:t.jsxs("form",{id:"secrets-rename",className:"ui-stack","data-gap":"sm",onSubmit:f=>{f.preventDefault(),d&&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(re,{message:o})]})})}function sne({secret:e,title:n,destinations:s,onClose:r,onChanged:a}){const[i,l]=u.useState(()=>e.bindings.length?e.bindings.map(m=>({kind:m.kind,target:nV(m.target),rule:m.rule})):s.length?[{kind:s[0].kind,target:"",rule:uf(s[0].maxRule)}]:[]),[o,c]=u.useState(!1),[d,h]=u.useState(null),f=async()=>{const m=p2(i);if(!m.ok){h(m.error);return}await el("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(se,{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(m2,{destinations:s,bindings:i,disabled:o,onChange:l}),d?t.jsx(q,{tone:"critical",role:"alert",children:d}):null]})})}function rne({secret:e,title:n,onClose:s,onChanged:r}){const[a,i]=u.useState(!1),[l,o]=u.useState(null),c=!!(e.unused||e.login),d=async()=>{await el("secrets.delete",{name:e.name},i,o)!==null&&(r(),s())};return t.jsxs(zt,{title:`${c?"Remove":"Delete"} “${n}”?`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx(E,{variant:"danger",disabled:a,onClick:()=>void d(),children:c?"Remove":"Delete"})]}),children:[t.jsxs("p",{className:"secrets-dialog-text",children:[gV(e)," The value is gone for good; its usage history stays, under its name."]}),t.jsx(re,{message:l})]})}function ane({timezone:e,embedded:n}){var p;const{data:s,error:r,reload:a}=pe(()=>T.sentinels(),[],3e4),[i,l]=u.useState(null),[o,c]=u.useState(null),d=(s==null?void 0:s.installed)??[],h=((s==null?void 0:s.runs)??[]).filter(x=>x.lastError),f=d.filter(x=>!x.enabled),m=(x,g)=>{l(x),c(null),T.setSentinelEnabled(x,g).catch(y=>c(y instanceof fe?y.message:String(y))).finally(()=>{l(null),a()})};return t.jsxs(js,{embedded:n,title:"Watchers",children:[t.jsx(re,{message:r??o}),t.jsx(q,{children:"Watchers are small checks that run on their own, with no model involved. An urgent finding wakes an agent, which verifies it before it tells you. The rest waits for the weekly recap."}),h.length>0?t.jsx(q,{tone:"warning",children:h.length===1?"One watcher failed on its last run.":`${h.length} watchers failed on their last run.`}):null,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(ge,{title:"Installed",aside:t.jsx("a",{href:`${Yt}/alerts`,children:"See what they found"}),panel:!0,flush:!0,children:s?d.length===0?t.jsx(as,{icon:"eye",title:"No watchers are installed",children:"Plugins bring their own."}):t.jsx(ut,{children:d.map(x=>{const g=s.runs.find(y=>y.sentinelId===x.id);return t.jsx(ot,{lead:t.jsx(Ce,{tone:x.enabled?g!=null&&g.lastError?"critical":g?"good":void 0:"muted",children:x.enabled?g!=null&&g.lastError?"failed":g?"ok":"never ran":"off"}),title:x.description,sub:`${x.id}, every ${ine(x.every)}${g!=null&&g.lastError?`. ${g.lastError}`:""}`,side:t.jsxs(t.Fragment,{children:[t.jsx("span",{title:g?ft(g.lastRunAt,e):void 0,children:g?Ge(g.lastRunAt):"never ran"}),t.jsx(E,{size:"sm",disabled:i===x.id,onClick:()=>m(x.id,!x.enabled),children:x.enabled?"Turn off":"Turn on"})]})},x.id)})}):t.jsx(be,{children:"Loading…"})}),t.jsx(XJ,{mutes:((p=s==null?void 0:s.alerts)==null?void 0:p.mutes)??[],onChanged:a})]})}function ine(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 UC=4,lne={time:"profile",date:"profile",zone:null};function one({data:e,phone:n}){const s=u.useRef(null),r=FP(),[a,i]=u.useState(.4),l=n?390:1280,o=n?780:800;u.useEffect(()=>{const d=s.current;if(!d)return;const h=()=>i(d.clientWidth/l||.4);if(h(),typeof ResizeObserver>"u")return;const f=new ResizeObserver(h);return f.observe(d),()=>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":db(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(qP,{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 cne({info:e,placement:n,index:s,count:r,onSize:a,onSettings:i,onMove:l,onRemove:o}){var d;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(Jt,{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:[(((d=e.settings)==null?void 0:d.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 BC(e){return e?"place"in e?`place:${e.place}`:`town:${e.timezone}:${e.label}`:""}function dne({clock:e,onClock:n,version:s}){var Q,F,ae;const r=e??lne,a=pe(()=>T.lockScreen(),[s]),i=pe(()=>T.widgets("lock"),[]),l=pe(()=>T.owner(),[]),[o,c]=u.useState(void 0),[d,h]=u.useState(!1),[f,m]=u.useState(null),[p,x]=u.useState(null),[g,y]=u.useState(null),[j,v]=u.useState(null);u.useEffect(()=>{i.data&&c(i.data)},[i.data]);const w=((Q=a.data)==null?void 0:Q.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,N=(o==null?void 0:o.lock)??[],k=new Map(((o==null?void 0:o.available)??[]).map(V=>[V.id,V])),S=N.length>=UC,b=V=>{if(!o)return Promise.resolve(!1);const J=o;return m(null),c({...o,lock:V,arranged:{...o.arranged,lock:!0}}),T.saveWidgets("lock",V).then(H=>(c(H),a.reload(),!0),H=>(c(J),m(`Couldn't save the lock screen's widgets: ${H instanceof Error?H.message:String(H)}`),!1))},C=(V,J)=>{const H=N.slice(),[X]=H.splice(V,1);H.splice(V+J,0,X),b(H)},$=(V,J)=>{const H=k.get(V);!H||S||b([...N,{key:HP(),widget:V,size:H.sizes.includes("small")?"small":H.sizes[0],settings:J}])},A=V=>{if(V==="find"){y({query:"",found:[],busy:!1});return}if(y(null),V==="")return n({...r,zone:null});if(V.startsWith("place:"))return n({...r,zone:{place:V.slice(6)}});const J=r.zone&&!("place"in r.zone)?r.zone:j;J&&n({...r,zone:J})},I=()=>{if(!g||g.query.trim().length<2)return;const V=g.query.trim();y({query:g.query,found:[],busy:!0}),T.findPlace(V).then(({found:J})=>{var ce;const H=J.filter(xe=>xe.timezone);if(H.length===0){y({query:V,found:[],busy:!1,missed:`Nothing with a timezone found for “${V}”.`});return}const X=H[0],G={label:((ce=X.name.split(",")[0])==null?void 0:ce.trim())||X.name,timezone:X.timezone};v(G),y(null),n({...r,zone:G})}).catch(()=>y({query:V,found:[],busy:!1,missed:"The place finder didn’t answer. Try again in a moment."}))},M=new Date,O=V=>Id({dateFormat:V},()=>Nr(M,w,{weekday:!0})),R=(((F=l.data)==null?void 0:F.places)??[]).filter(V=>V.timezone&&V.timezone!==w),_=r.zone&&!("place"in r.zone)?r.zone:j,z=((o==null?void 0:o.home)??[]).filter(V=>k.has(V.widget)&&!k.get(V.widget).sensitive),U=((o==null?void 0:o.available)??[]).filter(V=>!V.sensitive),P=((o==null?void 0:o.available)??[]).filter(V=>V.sensitive).map(V=>V.title),W=p?N.find(V=>V.key===p):void 0,L=W?k.get(W.widget):void 0;return t.jsxs(ge,{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(one,{data:a.data,phone:d}),t.jsxs("div",{className:"lke-look-foot",children:[t.jsx(Jt,{label:"Preview on",options:[{value:"desk",label:"Desk"},{value:"phone",label:"Phone"}],value:d?"phone":"desk",onChange:V=>h(V==="phone")}),t.jsxs("span",{className:"lke-look-note",children:["As it shows now",(ae=a.data)!=null&&ae.focus?", with your focus on":"","."]})]})]}),t.jsxs("div",{className:"lke-controls",children:[t.jsx(re,{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(Jt,{label:"Time",options:[{value:"profile",label:P$()},{value:"12h",label:"12-hour"},{value:"24h",label:"24-hour"}],value:r.time,onChange:V=>n({...r,time:V})})]}),t.jsx(oe,{label:"Date",children:t.jsxs("select",{value:r.date,onChange:V=>n({...r,date:V.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":BC(r.zone),onChange:V=>A(V.target.value),children:[t.jsx("option",{value:"",children:"None"}),R.map(V=>t.jsxs("option",{value:`place:${V.id}`,children:[V.label," — ",V.name.split(",")[0]]},V.id)),r.zone&&"place"in r.zone&&!R.some(V=>V.id===r.zone.place)?t.jsx("option",{value:BC(r.zone),children:"A place no longer in another zone"}):null,_?t.jsx("option",{value:`town:${_.timezone}:${_.label}`,children:_.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:V=>y({...g,query:V.target.value}),onKeyDown:V=>{V.key==="Enter"&&(V.preventDefault(),I()),V.key==="Escape"&&y(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 ",UC]})]}),S||!o?t.jsxs(E,{size:"sm",disabled:!0,children:[t.jsx(ie,{name:"plus",size:12})," Add a widget"]}):t.jsx(Qn,{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:[z.length>0?{heading:"As on Home"}:null,...z.map(V=>({label:V.label??k.get(V.widget).title,hint:"same settings",onSelect:()=>$(V.widget,V.settings)})),z.length>0?"separator":null,{heading:"Every widget"},...U.map(V=>({label:V.title,onSelect:()=>$(V.id,{})})),"separator",{label:"Get more widgets",hint:"Browse",onSelect:()=>{window.location.hash=tv("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((V,J)=>{const H=k.get(V.widget);return H?t.jsx(cne,{info:H,placement:V,index:J,count:N.length,onSize:X=>void b(N.map(G=>G.key===V.key?{...G,size:X}:G)),onSettings:()=>x(V.key),onMove:X=>C(J,X),onRemove:()=>void b(N.filter(X=>X.key!==V.key))},V.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:[S?"Four is the most it holds; take one off to add another. ":"","Each keeps its own settings, apart from Home’s.",P.length>0?` A sensitive widget — ${P.join(", ")} — never shows here.`:" A sensitive widget never shows here."," ","One with nothing to show right now stays off until it has."]})]}),t.jsxs("p",{className:"lke-note",children:[t.jsx(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."})]})]})]}),W&&L?t.jsx(UP,{info:L,placement:W,surface:"lock",onClose:()=>x(null),onSave:V=>b(N.map(J=>J.key===W.key?{...J,settings:V}:J)).then(J=>(J&&x(null),J)),onRemove:()=>{x(null),b(N.filter(V=>V.key!==W.key))}}):null]})}const une=[{id:"field",label:"Buddi"},{id:"dawn",label:"Dawn"},{id:"sea",label:"Sea"},{id:"moss",label:"Moss"},{id:"dusk",label:"Dusk"}];function hne({background:e,pictures:n}){if(e==="earth")return t.jsxs("p",{className:"lk-credit",children:["Earth: photo by ",t.jsx("a",{href:og.authorUrl,target:"_blank",rel:"noreferrer",children:og.author})," on ",t.jsx("a",{href:og.photoUrl,target:"_blank",rel:"noreferrer",children:"Unsplash"})]});const s=LP(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 fne=[{value:"1",label:"1 min"},{value:"5",label:"5 min"},{value:"15",label:"15 min"},{value:"60",label:"1 hour"},{value:"never",label:"Never"}],mne=e=>e.delayMinutes===null?"never":String(e.delayMinutes);function fj(e){if(e instanceof fe){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 pne({kind:e,onClose:n,onDone:s}){const[r,a]=u.useState(""),[i,l]=u.useState(""),[o,c]=u.useState(""),[d,h]=u.useState(null),[f,m]=u.useState(!1),p=e==="remove",x=e!=="set",g=!f&&(!x||r.length>=4)&&(p||i.length>=4&&o.length>=4),y=N=>N.replace(/\D/g,"").slice(0,8),j=e==="set"?"Set a PIN":e==="change"?"Change your PIN":"Remove the PIN?",v=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,x?r:void 0)).then(s).catch(S=>{m(!1),h(fj(S))})},w=(N,k,S,b)=>t.jsx(oe,{label:N,children:t.jsx("input",{type:"password",inputMode:"numeric",autoComplete:N==="Current PIN"?"current-password":"new-password",maxLength:8,autoFocus:b,value:k,onChange:C=>{h(null),S(y(C.target.value))}})});return t.jsx(zt,{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:()=>v(),children:p?"Remove PIN":e==="set"?"Set PIN":"Change PIN"})]}),children:t.jsxs("form",{className:"lk-form",onSubmit:v,children:[t.jsx("p",{className:"lk-honest",children:p?"The dashboard stops locking, on every device. You can set a PIN again any time.":"Four to eight digits. You type it to open the dashboard after it locks, on any device signed in to it."}),x?w("Current PIN",r,a,!0):null,p?null:w(e==="set"?"PIN":"New PIN",i,l,!x),p?null:w("The same again",o,c,!1),d?t.jsx(q,{tone:"critical",children:d}):null,t.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]})})}function gne(e){const n=Fm(),s=pe(()=>T.lockState(),[]),[r,a]=u.useState(null),[i,l]=u.useState(null),[o,c]=u.useState(null),d=u.useRef(null),h=u.useRef(null),f=DP(),m=s.data??n.state,p=v=>{n.update(v),s.reload()},x=v=>{l(null),v.then(p).catch(w=>l(fj(w)))},g=(v,w)=>{v&&(c(w),l(null),(w==="portrait"?T.uploadLockPortrait(v):T.uploadLockBackground(v)).then(p).catch(N=>l(fj(N))).finally(()=>{c(null);const N=w==="portrait"?h.current:d.current;N&&(N.value="")}))};if(!m)return t.jsx(ge,{title:"Lock screen",panel:!0,children:t.jsx(re,{message:s.error?"Couldn’t read the lock screen’s settings.":null})});const y=m.pin,j=(v,w,N)=>t.jsxs("button",{type:"button",className:"lk-swatch","data-bg":v,"aria-pressed":m.background===v,"aria-label":w,title:w,onClick:()=>x(T.setLockSettings({background:v})),children:[v==="image"&&m.image?t.jsx("img",{src:m.image,alt:""}):v==="earth"?t.jsx("img",{src:Yv.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})]},v);return t.jsxs(t.Fragment,{children:[t.jsxs(ge,{title:"Lock screen",aside:"Kept for every device signed in to this dashboard.",actions:y?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(de,{divided:!0,gap:"lg",children:[t.jsx("p",{className:"lk-honest ui-section",children:"A privacy screen over this dashboard, on every device signed in to it: it locks when nobody has used it for a while, or when you lock it, and opens with your PIN. A new browser opens locked too. It isn’t a second sign-in — anyone who can run buddi on this computer can open it without the PIN. Telegram and buddi in your coding tools carry on as before."}),t.jsx(re,{message:i}),t.jsxs("div",{className:"lk-pref ui-section",children:[t.jsxs("div",{className:"lk-pref-text",children:[t.jsx("div",{className:"lk-pref-label",children:"PIN"}),t.jsx("div",{className:"ui-field-hint",children:y?"Set. Kept hashed on this buddi; five wrong tries, then a wait that grows.":"Four to eight digits. Until you set one, nothing locks."})]}),y?t.jsxs(se,{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":y?void 0:"true","aria-disabled":y?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:y?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(Jt,{label:"Lock after",options:fne,value:y?mne(m):"",onChange:v=>{y&&x(T.setLockSettings({delayMinutes:v==="never"?null:Number(v)}))}})]}),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:une.map(v=>j(v.id,v.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(v=>j(cQ(v.id),v.title,v.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:d,type:"file",accept:"image/jpeg,image/png",className:"lk-sr","aria-label":m.image?"Replace your picture":"Add your picture",disabled:o!==null,onChange:v=>{var w;return g((w=v.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(hne,{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(se,{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:v=>{var w;return g((w=v.target.files)==null?void 0:w[0],"portrait")}}),t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>x(T.removeLockBackground()),children:"Remove picture"}),m.imagePortrait?t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>x(T.removeLockPortrait()),children:"Remove portrait"}):null,t.jsx(E,{size:"sm",disabled:o!==null,onClick:()=>{var v;return(v=h.current)==null?void 0:v.click()},children:o==="portrait"?"Adding…":m.imagePortrait?"Replace portrait…":"Add portrait…"})]})]}):null]})]}),r?t.jsx(pne,{kind:r,onClose:()=>a(null),onDone:v=>{a(null),p(v)}}):null]}),t.jsx(dne,{clock:m.clock,onClock:v=>x(T.setLockSettings({clock:v})),version:`${m.background}:${m.image??""}:${m.imagePortrait??""}:${JSON.stringify(m.clock??null)}`})]})}const yg=60;function g2(e){return e instanceof fe?e.message:"Something went wrong. Try again."}function xne(e,n,s=Date.now()){const r=`made ${Nr(new Date(e.createdAt),n,{compact:!0})} ${e.createdVia==="cli"?"in the terminal":"here"}`;return`buddi_…${e.hint} · ${r} · ${e.lastUsedAt?`last used ${Ge(e.lastUsedAt,s)}`:"never used"}`}function vne({onClose:e,onMade:n}){const[s,r]=u.useState(""),[a,i]=u.useState(!1),[l,o]=u.useState(null),[c,d]=u.useState(null),[h,f]=u.useState(!1),m=!a&&s.trim()!==""&&s.trim().length<=yg,p=x=>{x==null||x.preventDefault(),m&&(i(!0),o(null),T.createApiToken(s.trim()).then(g=>{d({token:g.token,name:g.apiToken.name}),n()}).catch(g=>o(g2(g))).finally(()=>i(!1)))};if(c){const x=()=>{var g;(g=navigator.clipboard)==null||g.writeText(c.token).then(()=>{f(!0),window.setTimeout(()=>f(!1),1600)}).catch(()=>{})};return t.jsx(zt,{title:`Token for ${c.name}`,onClose:e,foot:t.jsx(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:x,children:h?"Copied":"Copy"})]}),t.jsx(q,{tone:"warning",title:"Copy it now",children:"buddi keeps only a fingerprint of it, so it can’t show it again. Lost it? Revoke it and make another."}),t.jsx("p",{className:"at-text",children:"Send it as a header on every request:"}),t.jsx("code",{className:"at-try",children:`curl -H "Authorization: Bearer buddi_…" ${location.origin}/api/overview`})]})})}return t.jsx(zt,{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 ${yg} characters.`,children:t.jsx("input",{autoFocus:!0,value:s,maxLength:yg,placeholder:"Home Assistant",onChange:x=>{o(null),r(x.target.value)}})}),l?t.jsx(q,{tone:"critical",children:l}):null,t.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]})})}function jne({token:e,onClose:n,onRevoked:s}){const[r,a]=u.useState(!1),[i,l]=u.useState(null),o=()=>{a(!0),l(null),T.revokeApiToken(e.id).then(()=>{s(),n()}).catch(c=>{a(!1),l(g2(c))})};return t.jsxs(zt,{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 wne({timezone:e}){var o;const n=pe(()=>T.apiTokens(),[]),[s,r]=u.useState(!1),[a,i]=u.useState(null),l=((o=n.data)==null?void 0:o.tokens)??[];return t.jsxs(de,{gap:"lg",children:[t.jsx("p",{className:"ui-page-lede",children:"Let a script or another program use buddi without the dashboard. A token acts as you, minus the decisions only you make here."}),t.jsx(re,{message:n.error?"Couldn’t read the API tokens.":null}),t.jsx(ge,{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(ut,{children:l.map(c=>t.jsx(ot,{lead:t.jsx(Yn,{icon:"key"}),title:c.name,sub:xne(c,e),side:t.jsx(E,{size:"sm",variant:"ghost",onClick:()=>i(c),children:"Revoke…"})},c.id))})}),t.jsxs(ge,{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(vne,{onClose:()=>r(!1),onMade:()=>n.reload()}):null,a?t.jsx(jne,{token:a,onClose:()=>i(null),onRevoked:()=>n.reload()}):null]})}function yne({embedded:e}){const{data:n,error:s,reload:r}=pe(()=>T.owner(),[]);return t.jsxs(js,{embedded:e,title:"You",lede:"What every agent knows about the person it is talking to.",children:[t.jsx(re,{message:s}),n?t.jsxs(de,{gap:"lg",children:[t.jsx(Nne,{initial:n,onSaved:r}),t.jsx(Ane,{initial:n})]}):null]})}const x2=new Date(Date.UTC(2026,9,1,14,5));function bne(){return[["",`Auto (${Id({timeFormat:null},()=>$t(x2,"UTC"))} here)`],["12h","12-hour · 2:05 PM"],["24h","24-hour · 14:05"]]}function kne(){return[["",`Auto (${Id({dateFormat:null},()=>Nr(x2,"UTC",{weekday:!0}))} here)`],["short","Thu, Oct 1"],["long","Thursday, 1 October"],["iso","2026-10-01"]]}function Nne({initial:e,onSaved:n}){var _,z,U;const[s,r]=u.useState(e.preferredName??""),[a,i]=u.useState(e.timezone??""),[l,o]=u.useState(e.timeFormat??""),[c,d]=u.useState(e.dateFormat??""),[h,f]=u.useState(e.language??""),[m,p]=u.useState(e.about??""),[x,g]=u.useState(e.fullName??""),[y,j]=u.useState(e.pronouns??""),[v,w]=u.useState(wf(e.birthday)),[N,k]=u.useState(!1),[S,b]=u.useState(!1),[C,$]=u.useState(null);u.useEffect(()=>{r(e.preferredName??""),i(e.timezone??""),o(e.timeFormat??""),d(e.dateFormat??""),f(e.language??""),p(e.about??""),g(e.fullName??""),j(e.pronouns??""),w(wf(e.birthday))},[e.preferredName,e.timezone,e.timeFormat,e.dateFormat,e.language,e.about,e.fullName,e.pronouns,(_=e.birthday)==null?void 0:_.day,(z=e.birthday)==null?void 0:z.month,(U=e.birthday)==null?void 0:U.year]);const A=yf(v),I=s.trim()!==(e.preferredName??"")||a!==(e.timezone??"")||l!==(e.timeFormat??"")||c!==(e.dateFormat??"")||h.trim()!==(e.language??"")||m.trim()!==(e.about??"")||x.trim()!==(e.fullName??"")||y.trim()!==(e.pronouns??"")||A!=="incomplete"&&!jX(A,e.birthday),M=async()=>{k(!0),$(null);try{const P=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:x.trim()===""?null:x.trim(),pronouns:y.trim()===""?null:y.trim(),...A!=="incomplete"?{birthday:A}:{}});Ow({timeFormat:P.timeFormat??null,dateFormat:P.dateFormat??null}),window.dispatchEvent(new Event(Fx)),b(!0),n()}catch(P){$(P instanceof fe?P.message:String(P))}finally{k(!1)}},O=e.zones.length>0?e.zones:[e.detectedTimezone],R=P=>W=>{b(!1),P(W)};return t.jsx(ge,{title:"Your profile",aside:"read by every agent, as context",panel:!0,foot:t.jsxs(t.Fragment,{children:[S&&!I?t.jsx("span",{className:"muted",children:"Saved"}):null,t.jsx(E,{variant:"accent",disabled:!I||N,onClick:()=>void M(),children:N?"Saving…":"Save"})]}),children:t.jsxs(de,{divided:!0,gap:"lg",children:[t.jsx(ge,{title:"Who you are",children:t.jsxs(Ts,{children:[t.jsx(oe,{label:"Full name",hint:"For letters, forms and bookings.",children:t.jsx("input",{value:x,maxLength:120,placeholder:e.displayName??"Your full name",onChange:P=>R(g)(P.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:P=>R(r)(P.target.value)})}),t.jsx(oe,{label:"Pronouns",hint:"Optional.",children:t.jsx("input",{value:y,maxLength:40,placeholder:"he/him, she/her, they/them…",onChange:P=>R(j)(P.target.value)})}),t.jsx(sj,{label:"Birthday",hint:"The year is optional. Your team greets you on the day.",value:v,onChange:R(w)})]})}),t.jsx(ge,{title:"Time and language",children:t.jsxs(Ts,{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:P=>R(i)(P.target.value),children:[t.jsx("option",{value:"",children:"Not set (use the host's)"}),O.map(P=>t.jsx("option",{value:P,children:P},P))]})}),t.jsx(oe,{label:"Time",children:t.jsx("select",{value:l,onChange:P=>R(o)(P.target.value),children:bne().map(([P,W])=>t.jsx("option",{value:P,children:W},P))})}),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:P=>R(d)(P.target.value),children:kne().map(([P,W])=>t.jsx("option",{value:P,children:W},P))})}),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:P=>R(f)(P.target.value)})})]})}),t.jsxs(ge,{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:P=>R(p)(P.target.value)})}),C?t.jsx(q,{tone:"critical",children:C}):null]})]})})}const Sne=["Home","Work"];function Cne(e){const n=e.trim().toLowerCase();return n==="home"?"home":n==="work"?"briefcase":"pin"}function WC({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:Cne(e),size:18})})}function Ene(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 Ane({initial:e}){var c;const[n,s]=u.useState(e.places??[]);u.useEffect(()=>s(e.places??[]),[e]);const[r,a]=u.useState(null),i=e.timezone??e.detectedTimezone,l=Sne.filter(d=>!n.some(h=>h.label.toLowerCase()===d.toLowerCase())),o=u.useMemo(()=>new Date,[n]);return t.jsxs(ge,{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(ut,{children:[n.map(d=>t.jsx(ot,{label:`${d.label}: edit`,onClick:()=>a({place:d,label:d.label}),lead:t.jsx(WC,{label:d.label}),title:d.label,sub:Ene(d),side:d.timezone&&d.timezone!==i?t.jsxs(Ce,{children:[$t(o,d.timezone)," there"]}):void 0},d.id)),l.map(d=>t.jsx(ot,{label:`${d}: add`,onClick:()=>a({label:d}),lead:t.jsx(WC,{label:d,empty:!0}),title:t.jsx("span",{className:"muted",children:d}),sub:"Not set",side:t.jsx(E,{size:"sm",onClick:h=>{h.stopPropagation(),a({label:d})},children:"Add"})},d))]}),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($ne,{editing:r,zones:e.zones.length>0?e.zones:[e.detectedTimezone],onClose:()=>a(null),onSaved:d=>{s(d),a(null)}},((c=r.place)==null?void 0:c.id)??`new:${r.label}`):null]})}function $ne({editing:e,zones:n,onClose:s,onSaved:r}){const a=e.place,[i,l]=u.useState(e.label),[o,c]=u.useState((a==null?void 0:a.address)??""),[d,h]=u.useState(a?[{name:a.name,latitude:a.latitude,longitude:a.longitude,...a.timezone?{timezone:a.timezone}:{}}]:null),[f,m]=u.useState(0),[p,x]=u.useState((a==null?void 0:a.timezone)??""),[g,y]=u.useState(null),[j,v]=u.useState(null),[w,N]=u.useState((a==null?void 0:a.address)??""),k=d==null?void 0:d[f],S=()=>{o.trim().length<2||(y("find"),v(null),T.findPlace(o.trim()).then(I=>{var M;h(I.found),N(o.trim()),m(0),x(((M=I.found[0])==null?void 0:M.timezone)??""),I.found.length===0&&v("Nothing found by that name. Try the town, with its country.")}).catch(I=>v(I instanceof fe?I.message:String(I))).finally(()=>y(null)))},b=()=>{k&&(y("save"),v(null),T.savePlace({...a?{id:a.id}:{},label:i.trim(),address:o.trim()===""?null:o.trim(),name:k.name,latitude:k.latitude,longitude:k.longitude,timezone:p===""?null:p}).then(I=>r(I.places)).catch(I=>v(I instanceof fe?I.message:String(I))).finally(()=>y(null)))},C=()=>{a&&(y("remove"),v(null),T.removePlace(a.id).then(I=>r(I.places)).catch(I=>v(I instanceof fe?I.message:String(I))).finally(()=>y(null)))},$=a?a.label:e.label?`Add ${e.label}`:"Add a place",A=p!==""&&!n.includes(p)?[p,...n]:n;return t.jsx(Je,{title:$,onClose:s,foot:t.jsxs(se,{children:[a?t.jsx(E,{variant:"danger-ghost",disabled:g!==null,onClick:C,children:g==="remove"?"Removing…":"Remove"}):null,t.jsx(gt,{}),t.jsx(E,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx(E,{variant:"accent",disabled:!k||i.trim()===""||g!==null,onClick:b,children:g==="save"?"Saving…":"Save"})]}),children:t.jsxs(de,{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:S,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(),S())}})}),d&&d.length>0?t.jsx("div",{className:"place-found",role:"radiogroup","aria-label":"Which place",children:d.map((I,M)=>t.jsxs("button",{type:"button",role:"radio","aria-checked":M===f,className:"place-option","data-on":M===f?"true":void 0,onClick:()=>{m(M),x(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&&d&&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:k?"From where it is. Change it if that is wrong.":"Filled in once the place is found.",children:t.jsxs("select",{value:p,disabled:!k,onChange:I=>x(I.target.value),children:[t.jsx("option",{value:"",children:"Not known"}),A.map(I=>t.jsx("option",{value:I,children:I},I))]})}),t.jsx(re,{message:j})]})})}const Tne=2e6;function HC(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>Tne)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 d=r.length-1;d>=0;d--)a[c][d]=s[c]===r[d]?a[c+1][d+1]+1:Math.max(a[c+1][d],a[c][d+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 v2={skill:"skill",policy:"rule",change:"change to itself"};function Ine(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 mj(e){return[...new Set(e.split(/[,\n]/).map(n=>n.trim().replace(/^[-*]\s+/,"")).filter(n=>n!==""))]}function Rne(e,n){const s=e.change;if(!s||s.part!=="tools")return[];if(n===e.editable)return s.added;const r=new Set(mj(s.current??""));return mj(n).filter(a=>!r.has(a))}function Pne(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 Mne(e){return"cards"in e}function KC(e,n){return!n||e.kind==="policy"&&e.payload.plugin===n}function One({embedded:e,plugin:n}){const{data:s,error:r,reload:a}=pe(()=>T.proposals(),[],3e4),[i,l]=u.useState(null),[o,c]=u.useState(null),[d,h]=u.useState(null),[f,m]=u.useState({}),p=async(v,w,N=!1)=>{l(null),c(null),h(v),m(({[v]:k,...S})=>S);try{c(await w()),a()}catch(k){const S=k instanceof Error?k.message:String(k);N?m(b=>({...b,[v]:S})):l(S)}finally{h(null)}},x=VR(),g=((s==null?void 0:s.open)??[]).filter(v=>KC(v,n)),y=((s==null?void 0:s.closed)??[]).filter(v=>KC(v,n)),j=v=>t.jsx(zne,{proposal:v,busy:d===v.id,refusal:f[v.id]??null,onKeep:w=>void p(v.id,async()=>{const N=await T.keepProposal(v.id,w);return`${v.title}: ${N.note}`},!0),onDiscard:w=>void p(v.id,async()=>(await T.discardProposal(v.id,w),`Discarded: ${v.title}. ${v.agent} will be told once and will not propose it again for 90 days.`))},v.id);return t.jsxs(js,{embedded:e,title:"Proposals",lede:"What your agents learned and would like to keep: a procedure, a rule, a change to their own instructions. Keep what is right, correct what is nearly right, discard the rest. A few rules apply themselves, where their plugin allows it (one you always keep, one that only quiets mail sent to many); its own page lists them, with Undo.",children:[t.jsx(re,{message:r??i}),n?t.jsxs(q,{role:"status",children:["Showing the rules ",n," proposes. ",t.jsx("a",{href:ze("proposals"),children:"Show every proposal"})]}):null,o?t.jsx(q,{tone:"good",role:"status",children:o}):null,n?null:t.jsx(GR,{offers:x.offers,reload:x.reload}),!s||g.length===0?t.jsx(ge,{title:"Waiting",panel:!0,children:s?n?t.jsx(as,{icon:"bulb",title:`No rule from ${n} is waiting`,children:"It proposes one when you decide the same way several times running."}):t.jsx(as,{icon:"bulb",title:"Nothing proposed",children:"When an agent learns something worth keeping, it waits here."}):t.jsx(be,{children:"Loading…"})}):t.jsx(ge,{title:"Waiting",aside:`${g.length} to decide`,children:Pne(g).map(v=>Mne(v)?t.jsx(Dne,{group:v,busy:d===v.key,onKeepAll:()=>void p(v.key,async()=>{const w=await T.keepAllProposals(v.cards.map(N=>N.id));return`${v.label}: ${w.note}`}),card:w=>j(w)},v.key):j(v))}),y.length>0?t.jsx(ge,{title:`Kept, discarded and expired (${y.length})`,aside:"These stop being shown a week after they were decided.",panel:!0,flush:!0,children:t.jsx(ut,{children:y.map(v=>{var w;return t.jsx(ot,{title:v.title,sub:`${v.agent}: ${Lne(v)}`,side:v.kind==="skill"&&v.state==="kept"&&((w=v.skill)!=null&&w.live)?t.jsxs(se,{align:"end",children:[t.jsx("span",{className:"muted",children:Ge(v.decidedAt??v.createdAt)}),t.jsx(E,{size:"sm",variant:"ghost",disabled:d===v.id,onClick:()=>void p(v.id,async()=>{const N=v.skill;return await T.removeSkill(v.agent,N.name),`Removed ${N.name} from ${v.agent}. Its versions are kept, and ${v.agent} will not propose it again for 90 days.`}),children:"Remove this skill"})]}):Ge(v.decidedAt??v.createdAt)},v.id)})})}):null,!n&&(s!=null&&s.digest)?t.jsx(_ne,{schedule:s.digest.schedule,onSaved:a}):null]})}function Dne({group:e,busy:n,onKeepAll:s,card:r}){const a=e.cards.length,i=e.cards.some(l=>l.untrusted);return t.jsx(Sr,{tone:i?"warning":"accent",title:`${e.label} (${a})`,meta:t.jsxs(t.Fragment,{children:[t.jsx(Ce,{children:v2.policy}),t.jsx(Ce,{mono:!0,children:e.plugin})]}),foot:t.jsx(se,{align:"end",children:t.jsxs(E,{variant:"accent",size:"sm",disabled:n,onClick:s,children:["Keep all (",a,")"]})}),children:t.jsxs(de,{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(Kt,{summary:`Show each of the ${a}`,children:t.jsx(de,{gap:"sm",children:e.cards.map(l=>r(l))})})]})})}function Lne(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 Fne=Array.from({length:24},(e,n)=>n),VC=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function _ne({schedule:e,onSaved:n}){const[s,r]=u.useState(e.day),[a,i]=u.useState(e.hour),[l,o]=u.useState(!1),[c,d]=u.useState(null),h=s!==e.day||a!==e.hour,f=async()=>{o(!0),d(null);try{await T.setDigestSchedule(s,a),d({tone:"good",text:`The digest now runs on ${VC[s]} at ${String(a).padStart(2,"0")}:00.`}),n()}catch(m){d({tone:"critical",text:m instanceof Error?m.message:String(m)})}finally{o(!1)}};return t.jsx(ge,{title:"Weekly digest",panel:!0,foot:t.jsx(E,{variant:"accent",disabled:l||!h,onClick:()=>void f(),children:"Save"}),children:t.jsxs(de,{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: ${Ge(e.next)}.`:""]}),t.jsxs(se,{children:[t.jsx(oe,{label:"Day",children:t.jsx("select",{value:s,disabled:l,onChange:m=>r(Number(m.target.value)),children:VC.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:Fne.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 GC(e,n){return e==="tools"?mj(n).join(`
142
+ `):n}function zne({proposal:e,busy:n,refusal:s,onKeep:r,onDiscard:a}){const[i,l]=u.useState(e.editable??""),[o,c]=u.useState(""),d=e.editable!==null&&i!==e.editable,h=e.payload,f=e.echoes??[],m=e.kind==="change"?e.change??null:null,p=Rne(e,i);return t.jsx(Sr,{tone:e.untrusted?"warning":"accent",title:e.title,meta:t.jsxs(t.Fragment,{children:[t.jsx(Ce,{children:v2[e.kind]}),t.jsx(Ce,{mono:!0,children:e.agent}),e.untrusted?t.jsx(Ce,{tone:"warning",children:"untrusted text in view"}):null,p.length>0?t.jsx(Ce,{tone:"warning",children:"widens its tools"}):null]}),foot:t.jsxs(se,{align:"end",children:[s?t.jsx("span",{className:"proposal-refusal",role:"alert",children:s}):null,t.jsx("input",{"aria-label":"Reason for discarding (optional)",placeholder:"Reason for discarding (optional)",value:o,maxLength:300,disabled:n,onChange:x=>c(x.target.value)}),t.jsx(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(d?i:void 0),children:d?"Keep my version":"Keep"})]}),children:t.jsxs(de,{gap:"sm",children:[e.why?t.jsx("p",{children:e.why}):null,t.jsxs("p",{className:"ui-card-meta",children:["Proposed by ",e.agent," ",Ge(e.createdAt),e.conversationId?t.jsxs(t.Fragment,{children:[" in ",t.jsx("a",{href:od(e.conversationId),children:e.turn?`this conversation, turn ${e.turn}`:"this conversation"})]}):null,"."]}),e.untrusted?t.jsxs(q,{tone:"warning",title:e.kind==="policy"?"Learned from mail you received.":"Made with untrusted text in view.",children:[e.kind==="policy"?"The plugin counted this rule from your own triage decisions; no instruction in that mail can change what it does.":"Something written by someone other than you was in the agent's context when it proposed this. Read it for instructions that came from there rather than from you.",t.jsx("ul",{className:"proposal-sources",children:e.sources.map(x=>t.jsx("li",{className:"mono",children:x},x))}),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(x=>t.jsx("li",{children:t.jsx("mark",{className:"wb-diff-mark",children:x})},x))})]}):null]}):null,e.kind==="skill"?t.jsxs(t.Fragment,{children:[typeof h.when=="string"?t.jsxs("p",{className:"ui-card-meta",children:["When: ",h.when]}):null,e.skill?t.jsxs(de,{gap:"sm",children:[t.jsxs("p",{className:"ui-card-meta",children:[e.agent," already has this skill (",t.jsxs("a",{href:Pt(e.agent,"skills"),children:[e.skill.name,", version ",e.skill.version]}),"). Keeping this writes version ",e.skill.version+1,"; the earlier ones stay readable."]}),t.jsx(Yh,{text:HC(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:x=>l(x.target.value)})})]}):null,e.kind==="change"?t.jsxs(t.Fragment,{children:[p.length>0?t.jsxs(q,{tone:"warning",title:`Adds: ${p.join(", ")}`,children:["Keeping this lets ",e.agent," call tools it cannot call now."]}):null,m!=null&&m.refusal&&!d?t.jsx(q,{tone:"warning",title:"Keeping this as proposed will be refused.",children:m.refusal}):null,m&&m.current!==null?t.jsx(Yh,{text:HC(GC(m.part,m.current),GC(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(Kt,{summary:`What its ${h.part==="tools"?"tool list":"instructions"} said when proposed`,children:t.jsx(_t,{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:x=>l(x.target.value)})})]}):null,e.kind==="policy"?t.jsx(Qt,{items:[{label:"Plugin",value:t.jsx("span",{className:"mono",children:String(h.plugin??"")})},{label:"Matches",value:t.jsx("span",{className:"mono",children:Ine(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 j2(e){return e.length>1?"small or medium":`${e[0]} only`}function Une(e){return["small","medium"].filter(n=>e.includes(n))}function w2({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(Dm,{body:r,size:n}):t.jsxs("span",{className:"wg-state",children:[t.jsx(Yn,{svg:s}),t.jsx("span",{className:"wg-state-sub",children:"No preview from this plugin."})]})})]})}function Bne(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 Wne({start:e,onPick:n,onClose:s}){const[r,a]=u.useState(null),[i,l]=u.useState(null),[o,c]=u.useState(""),d=(p,x=!1)=>{l(null),T.pluginFolders(p).then(g=>{a(g),c("")}).catch(g=>{x&&p!==void 0?d(void 0):l(g instanceof fe?g.message:String(g))})};u.useEffect(()=>{d(e,!0)},[]);const h=o.trim().toLowerCase(),f=((r==null?void 0:r.folders)??[]).filter(p=>h===""||p.name.toLowerCase().includes(h)),m=r?Bne(r):[];return t.jsxs(Je,{title:"Choose the folder",onClose:s,foot:t.jsxs(se,{children:[t.jsx("span",{className:"plugins-foot-note mono",children:(r==null?void 0:r.path)??""}),t.jsx(gt,{}),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(Nc,{label:"Folder",items:m.map((p,x)=>x===m.length-1?{key:p.path,label:p.label,current:!0}:{key:p.path,label:p.label,onClick:()=>d(p.path)})}):null,t.jsx(Cm,{label:"Find a folder here",value:o,placeholder:"Find a folder here…",onChange:c}),t.jsx(re,{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(rt,{flush:!0,children:t.jsx(ut,{children:f.map(p=>t.jsx(ot,{onClick:()=>d(p.path),label:`Open ${p.name}`,lead:t.jsx(Yn,{icon:"folder"}),title:p.name,side:p.plugin?t.jsx(Ce,{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 Hne="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 qC(){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:ze("connections"),children:"Connections"})]})]})}const Kne=1500,Vne={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."},Gne="Restart buddi to apply it. In a checkout, stop it and run: buddi serve",y2=[{value:"npm",label:"From npm"},{value:"file",label:"A file"},{value:"directory",label:"A directory I built"}],b2="buddi.plugins.install-mode";function qne(){try{const e=window.localStorage.getItem(b2);if(y2.some(n=>n.value===e))return e}catch{}return"npm"}function Yne(e){try{window.localStorage.setItem(b2,e)}catch{}}const zu=".tgz",Ur=(e,n,s)=>`${e} ${e===1?n:s}`;function k2(e){const n=[];return e.tools>0&&n.push(Ur(e.tools,"tool","tools")),e.sentinels>0&&n.push(`${e.sentinels} on a timer`),e.views>0&&n.push(Ur(e.views,"view","views")),e.agents>0&&n.push(`${Ur(e.agents,"agent","agents")} proposed`),n.length===0?"nothing on its own":n.join(", ")}function pj(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 N2(e){return e.kind==="registry"?"npm":e.kind==="tarball"?"a file":"a directory"}function bb(e,n){return e.kind==="directory"?"you, from this machine":e.kind==="tarball"?"a file on this machine":n??"nobody npm will name"}function S2(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 gj({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 C2(e){return e.length===0?"none; nothing leaves this computer":t.jsx("span",{className:"mono",children:e.join(", ")})}function kb(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 ci=e=>e instanceof fe?e.message:String(e);function Qne(e){const[n,s]=u.useState(void 0),[r,a]=u.useState(null);return u.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(ci(c)),i=!0)})};l();const o=window.setInterval(l,Kne);return()=>{i=!0,window.clearInterval(o)}},[e]),{job:n,error:r}}function Jne({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=Hr(i.plugin,i.id);return t.jsx(st,{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 E2({plugin:e}){var s;if(e.enabled===!1)return t.jsx(Ce,{children:"disabled"});const n=(s=e.needs)==null?void 0:s[0];return n?t.jsxs(Ce,{tone:"warning",children:["needs ",n.plugin]}):e.loadsAtRestart?t.jsx(Ce,{tone:"accent",children:"loads at restart"}):e.loaded&&e.setup?t.jsx(Ce,{tone:"warning",children:"needs setup"}):e.loaded?t.jsx(Ce,{tone:"good",dot:!0,children:"loaded"}):t.jsx(Ce,{tone:"critical",children:"did not load"})}function Nb({entry:e}){var n;return e.trust==="by-buddi"?t.jsx(Ce,{tone:"accent",children:"by buddi"}):t.jsxs(Ce,{tone:"good",children:["reviewed ",((n=e.reviewed)==null?void 0:n.version)??e.version]})}const xj=ze("plugins"),bg={installed:xj,browse:`${xj}?tab=browse`};function Xne({railPages:e=[],settingsPages:n=[],navigate:s,hash:r=""}={}){const a=pe(()=>T.plugins(),[],2e4),[i,l]=u.useState(null),{job:o,error:c}=Qne(i),[d,h]=u.useState(null),[f,m]=u.useState(()=>nN(r));u.useEffect(()=>m(nN(r)),[r]);const[p,x]=u.useState(()=>tN(r));u.useEffect(()=>x(tN(r)),[r]);const[g,y]=u.useState(null),[j,v]=u.useState(null),[w,N]=u.useState(null),[k,S]=u.useState(null),[b,C]=u.useState(!1),$=le=>{C(!0),T.market(le).then(S).catch(ye=>S({plugins:[],unavailable:ci(ye)})).finally(()=>C(!1))};u.useEffect(()=>{f==="browse"&&k===null&&!b&&$(!1)},[f]);const A=le=>{h(null),l(le)},I=le=>h(ci(le)),[M,O]=u.useState(!1),R=le=>{O(!0),y(null),le.then(ye=>{A(ye.job.id),m("installed")}).catch(I).finally(()=>O(!1))},_=u.useRef(null);u.useEffect(()=>{const le=P6(r);if(!(le===null||_.current===le)){_.current=le,m("installed"),R(T.stagePlugin(le));try{window.history.replaceState(window.history.state,"",xj)}catch{}}},[r]);const z=le=>ye=>{ye.preventDefault(),m(le),y(null),s==null||s(bg[le])};u.useEffect(()=>{((o==null?void 0:o.phase)==="done"||(o==null?void 0:o.phase)==="failed")&&a.reload()},[o==null?void 0:o.phase]);const U=a.data,P=(U==null?void 0:U.checkout)??!0,W=(U==null?void 0:U.installed)??[],L=le=>k==null?void 0:k.plugins.find(ye=>ye.installed!==void 0&&(ye.installed.name??ye.name)===le.name),Q=le=>e.some(ye=>ye.plugin===le),F=(le,ye)=>Q(le)?t.jsx(Jne,{plugin:le,pages:e,navigate:s,variant:ye}):void 0,ae=le=>{const ye=e.find(et=>et.plugin===le);ye&&s&&s(Hr(ye.plugin,ye.id))},V=le=>{const ye=n.find(et=>et.plugin===le);if(!(!ye||!s))return()=>s(pr(ye.plugin,ye.id))},J=((k==null?void 0:k.plugins)??[]).filter(le=>le.update).length,H=(le,ye)=>T.setPluginEnabled(le,ye).then(et=>{oy(),N({name:le,notes:et.notes??[]}),a.reload()}),X=(le,ye,et)=>T.uninstallPlugin(le,ye?{purge:!0,confirm:et}:{}).then(pt=>{y(null),N({name:le,notes:pt.notes??[]}),a.reload()}),G=le=>{h(null),H(le,!0).catch(I)},ce=(le,ye)=>{const et=k==null?void 0:k.plugins.find(kt=>{var Ot;return(((Ot=kt.installed)==null?void 0:Ot.name)??kt.name)===le&&kt.installed!==void 0}),pt=et&&ye?`${et.npm}@${ye}`:void 0;R(pt?T.updatePlugin(le,ye,pt):T.updatePlugin(le,ye))},xe=le=>{h(null);const ye=et=>{const pt=et.plugins.find(kt=>{var Ot;return kt.name===le||((Ot=kt.installed)==null?void 0:Ot.name)===le});if(!pt){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(`${pt.npm}@${pt.version}`))};if(k&&k.plugins.length>0)return ye(k);O(!0),T.market(!1).then(et=>{S(et),ye(et)}).catch(I).finally(()=>O(!1))},De=(le,ye)=>ye===void 0?void 0:ye.place==="settings"?pr(le,ye.id):Hr(le,ye.id),B=le=>{var et;if(le.enabled===!1)return;const ye=(et=le.needs)==null?void 0:et[0];if(ye)switch(ye.state){case"missing":return{label:`Install ${ye.plugin}`,run:()=>xe(ye.plugin)};case"disabled":return{label:`Enable ${ye.plugin}`,run:()=>G(ye.plugin)};case"range":return{label:`Update ${ye.plugin}`,run:()=>ce(ye.plugin)};case"setup":{const pt=De(ye.plugin,ye.page),kt=pt&&s?()=>s(pt):V(ye.plugin);return kt?{label:`Set up ${ye.plugin}`,run:kt}:void 0}default:return{label:`See ${ye.plugin}`,run:()=>y({kind:"installed",name:ye.plugin})}}if(le.loaded&&le.setup){const pt=De(le.name,le.setup.page),kt=pt&&s?()=>s(pt):V(le.name);return kt?{label:"Set it up",run:kt}:void 0}},ne=t.jsxs(Ro,{label:"Plugins",children:[t.jsx(Ji,{href:bg.installed,active:f==="installed",count:J,onClick:z("installed"),children:"Installed"}),t.jsx(Ji,{href:bg.browse,active:f==="browse",onClick:z("browse"),children:"Browse"})]}),Z=(U==null?void 0:U.staged)??[],ve=ise(Z,(o==null?void 0:o.phase)==="done"?o.stagedId:void 0),$e=Z.find(le=>le.id===ve),Se=Z.filter(le=>le.id!==ve),me=le=>{y(null),ose(le),l(null),a.reload()},Ee=(g==null?void 0:g.kind)==="staged"?Se.find(le=>le.id===g.name):void 0,Pe=(g==null?void 0:g.kind)==="installed"?W.find(le=>le.name===g.name):void 0,Me=(g==null?void 0:g.kind)==="market"?k==null?void 0:k.plugins.find(le=>le.name===g.name):void 0,he=w&&!(Pe&&Pe.name===w.name)&&w.notes.length>0?w.notes:null,ke=Ee?t.jsx(rse,{staged:Ee,onClose:()=>y(null),onInstalled:me,onInstallFirst:xe,onGone:()=>{y(null),a.reload()}},Ee.id):Pe?t.jsx(pse,{plugin:Pe,listing:L(Pe),notes:(w==null?void 0:w.name)===Pe.name?w.notes:null,canOpen:Q(Pe.name)&&Pe.enabled!==!1,onOpen:()=>ae(Pe.name),onClose:()=>y(null),onDisable:()=>v({kind:"disable",name:Pe.name}),onEnable:()=>G(Pe.name),onRemove:()=>v({kind:"remove",name:Pe.name}),onUpdate:le=>ce(Pe.name,le),onSettings:Pe.enabled===!1?void 0:V(Pe.name),firstStep:B(Pe),busy:M}):Me?t.jsx(kse,{entry:Me,canOpen:Me.installed!==void 0&&Q(Me.installed.name??Me.name),onOpen:()=>{var le;return ae(((le=Me.installed)==null?void 0:le.name)??Me.name)},onClose:()=>y(null),onInstall:()=>R(T.stagePlugin(`${Me.npm}@${Me.version}`)),onUpdate:le=>{var ye;return ce(((ye=Me.installed)==null?void 0:ye.name)??Me.name,le)},busy:M}):null,Be=j?W.find(le=>le.name===j.name):void 0,qe=j?t.jsx(gse,{kind:j.kind,name:j.name,canDisable:(Be==null?void 0:Be.enabled)!==!1,onCancel:()=>v(null),onDisableInstead:()=>v({kind:"disable",name:j.name}),onDisable:()=>H(j.name,!1).then(()=>v(null)),onRemove:(le,ye)=>X(j.name,le,ye).then(()=>v(null))},`${j.kind}:${j.name}`):null;if(f==="browse")return t.jsxs(de,{gap:"lg",children:[t.jsx(qC,{}),ne,t.jsx(re,{message:d}),t.jsx(Ase,{kind:p,onKind:x,navigate:s,market:k,loading:b,busy:M,onRetry:()=>$(!0),onOpen:le=>y({kind:"market",name:le.name}),onInstall:le=>R(T.stagePlugin(`${le.npm}@${le.version}`)),onUpdate:(le,ye)=>{var et;return ce(((et=le.installed)==null?void 0:et.name)??le.name,ye)}}),ke]});const at=(U==null?void 0:U.builtIn)??[];return t.jsxs(de,{gap:"lg",children:[t.jsx(qC,{}),ne,t.jsx(re,{message:a.error??d??c}),U!=null&&U.unavailable?t.jsx(q,{tone:"warning",children:U.unavailable}):null,he?t.jsx(q,{role:"status",children:he.join(" ")}):null,t.jsx(Zne,{trust:(U==null?void 0:U.trust)??"",job:o,busy:o!==void 0&&o.phase!=="done"&&o.phase!=="failed",onStaged:A,onFailed:h}),$e?t.jsx(nse,{staged:$e,onInstalled:me,onGone:()=>a.reload(),onInstallFirst:xe},$e.id):null,Se.length>0?t.jsx(rt,{flush:!0,title:"Waiting for you",tool:Ur(Se.length,"package","packages"),children:t.jsx("div",{className:"plugins-rows",children:t.jsx(ut,{children:Se.map(le=>t.jsx(sse,{staged:le,onReview:()=>{$2(le),y({kind:"staged",name:le.id})},onReject:()=>{h(null),T.rejectStaged(le.id).then(()=>a.reload()).catch(I)}},le.id))})})}):null,U!=null&&U.restartNeeded?t.jsx(lse,{checkout:P,waiting:W.filter(le=>le.loadsAtRestart)}):null,t.jsx(dse,{list:W,firstStepFor:B}),t.jsx(rt,{flush:!0,title:"Installed",tool:U?Ur(W.length,"plugin","plugins"):void 0,children:U?W.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(ut,{children:W.map(le=>t.jsx(hse,{plugin:le,listing:L(le),open:le.enabled===!1?void 0:F(le.name,"ghost"),canOpen:Q(le.name)&&le.enabled!==!1,busy:M,onDetails:()=>y({kind:"installed",name:le.name}),onOpen:()=>ae(le.name),onSettings:le.enabled===!1?void 0:V(le.name),onDisable:()=>v({kind:"disable",name:le.name}),onEnable:()=>G(le.name),onRemove:()=>v({kind:"remove",name:le.name}),onUpdate:ye=>ce(le.name,ye),firstStep:B(le)},le.name))})}):t.jsx(be,{children:"Loading…"})}),at.length>0?t.jsx(xse,{plugins:at,openFor:F}):null,ke,qe]})}function Zne({trust:e,job:n,busy:s,onStaged:r,onFailed:a}){const[i,l]=u.useState(qne),[o,c]=u.useState(""),[d,h]=u.useState(!1),[f,m]=u.useState(null),[p,x]=u.useState(null),[g,y]=u.useState(!1),[j,v]=u.useState(!1),w=u.useRef(null),N=C=>a(ci(C)),k=C=>{l(C),Yne(C),x(null)},S=()=>{h(!0),T.stagePlugin(o.trim()).then(C=>{r(C.job.id),c("")}).catch(N).finally(()=>h(!1))},b=C=>{if(C){if(!C.name.toLowerCase().endsWith(zu)){m(null),x(`${C.name} is not a ${zu}. A packed plugin is the file npm pack writes.`);return}x(null),m(C.name),h(!0),T.uploadPlugin(C).then($=>r($.job.id)).catch(N).finally(()=>h(!1))}};return t.jsxs(rt,{title:"Add a plugin",actions:t.jsx(Jt,{label:"Where it comes from",options:y2,value:i,onChange:k}),children:[t.jsxs("div",{className:"plugins-add",children:[i==="file"?t.jsxs("div",{className:"plugins-drop",role:"group","aria-label":"A plugin file","data-state":g?"over":p?"refused":f?"chosen":void 0,onDragOver:C=>{C.preventDefault(),y(!0)},onDragLeave:()=>y(!1),onDrop:C=>{var $,A;C.preventDefault(),y(!1),b((A=($=C.dataTransfer)==null?void 0:$.files)==null?void 0:A[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:zu})," 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||d,onClick:()=>{var C;return(C=w.current)==null?void 0:C.click()},children:"Choose a file"}),t.jsx("input",{ref:w,type:"file",accept:zu,hidden:!0,"aria-hidden":"true",tabIndex:-1,onChange:C=>{var $;b(($=C.target.files)==null?void 0:$[0]),C.target.value=""}})]}):t.jsxs("div",{className:"plugins-add-row",children:[t.jsxs(se,{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:()=>v(!0),children:"Browse…"}):null,t.jsx(E,{variant:"accent",disabled:s||d||o.trim()==="",onClick:S,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:[Vne[n.phase]," ",n.error??""]}):null,t.jsx("div",{className:"plugins-trust",children:t.jsx(q,{tone:"warning",children:e})})]}),j?t.jsx(Wne,{start:o.trim().startsWith("/")?o.trim():void 0,onClose:()=>v(!1),onPick:C=>{c(C),v(!1)}}):null]})}function ese({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?kb([]):n.map(i=>t.jsxs("span",{children:["It ",i.words,". ",i.added?t.jsxs(Ce,{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 A2(e,n,s){const[r,a]=u.useState(e.plan??null),[i,l]=u.useState(!1),[o,c]=u.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(ci(m))).finally(()=>l(!1))},reject:()=>{l(!0),c(null),T.rejectStaged(e.id).then(()=>s()).catch(f=>c(ci(f))).finally(()=>l(!1))}}}function $2(e){e.openedAt||T.openedStaged(e.id).catch(()=>{})}function tse({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(Ce,{tone:"warning",children:"not installed"}),n?t.jsxs(E,{size:"sm",onClick:()=>n(s.plugin),children:["Install ",s.plugin," first"]}):null]}):t.jsx(Ce,{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 T2({staged:e,inSheet:n,onInstallFirst:s}){var a;const r=e.dependencies;return t.jsxs("div",{className:"plugins-staged","data-in":n?"sheet":void 0,children:[t.jsx("div",{className:"plugins-facts",children:t.jsx(Qt,{items:[...e.author?[{label:"By",value:t.jsx(zm,{author:e.author})}]:[],{label:"From",value:e.uploadedName?`a file you chose · ${e.uploadedName}`:pj(e.source)},{label:"Published by",value:bb(e.source,e.publisher)},...e.previousSource&&e.previous?[{label:"Replaces",value:`${e.previous.version}, installed from ${pj(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(ese,{staged:e})},...(e.requires??[]).length>0?[{label:"Needs",value:t.jsx(tse,{staged:e,onInstallFirst:s})}]:[],{label:"Integrity",value:t.jsx(gj,{value:e.integrity})},...e.stagedHash?[{label:"Files on disk",value:t.jsx(gj,{value:e.stagedHash})}]:[]]})}),t.jsxs("div",{className:"plugins-claim",children:[t.jsx("div",{className:"plugins-claim-head",children:"What it says about itself"}),t.jsx("div",{className:"plugins-claim-note",children:"From its own buddi.md. Nothing has checked it yet."}),e.claims.missing?t.jsx("p",{className:"plugins-claim-text",children:"It ships no buddi.md, so it says nothing about itself at all."}):t.jsxs("p",{className:"plugins-claim-text",children:["“",e.claims.text,"”"]}),t.jsx("div",{className:"plugins-facts",children:t.jsx(Qt,{items:[{label:"Schema it owns",value:e.claims.schema?t.jsx("span",{className:"mono",children:e.claims.schema}):"it claims none"},{label:"Hosts it reaches",value:e.claims.hosts.length===0?"it claims none":t.jsx("span",{className:"mono",children:e.claims.hosts.join(", ")})}]})})]})]})}function I2({plan:e,busy:n,onReject:s,onInstallAnyway:r}){return t.jsxs(Sr,{tone:"warning",title:"What it said, and what it does",meta:t.jsx(Ce,{tone:"warning",children:"read this first"}),foot:t.jsxs(se,{children:[t.jsx("span",{className:"plugins-foot-note",children:"Install anyway says you read these."}),t.jsx(gt,{}),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(R2,{unlocks:e.agents??[]})]})}function nse({staged:e,onInstalled:n,onGone:s,onInstallFirst:r}){const{plan:a,busy:i,failed:l,approve:o,reject:c}=A2(e,n,s);u.useEffect(()=>$2(e),[e.id]);const d=(a==null?void 0:a.drift)??[];return t.jsxs(de,{gap:"sm",children:[t.jsxs(Sr,{tone:"accent",title:t.jsxs(t.Fragment,{children:[e.name," ",t.jsx("span",{className:"plugins-ver",children:e.version})]}),meta:t.jsx(Ce,{children:"read, not installed"}),foot:t.jsxs(se,{children:[t.jsx("span",{className:"plugins-foot-note",children:"Nothing of it has run."}),t.jsx(gt,{}),t.jsx(E,{variant:"ghost",disabled:i,onClick:c,children:"Not this one"}),t.jsx(E,{variant:"accent",disabled:i||d.length>0,onClick:()=>o(!1),children:"Install"})]}),children:[t.jsx(re,{message:l}),t.jsx(T2,{staged:e,onInstallFirst:r})]}),a&&d.length>0?t.jsx(I2,{plan:a,busy:i,onReject:c,onInstallAnyway:()=>o(!0)}):null]})}function sse({staged:e,onReview:n,onReject:s}){const r=Ge(e.createdAt);return t.jsx(ot,{onClick:n,label:`${e.name}: review`,lead:t.jsx(Yn,{svg:void 0}),title:t.jsxs(t.Fragment,{children:[e.name," ",t.jsx("span",{className:"plugins-ver",children:e.version})]}),sub:`from ${N2(e.source)}${r?` · read ${r}`:""}`,side:t.jsxs("span",{className:"plugins-side",children:[t.jsxs("span",{className:"plugins-wait-extra",children:[t.jsx(Ce,{children:"read, not installed"}),t.jsx(E,{size:"sm",variant:"ghost",onClick:mo(s),children:"Not this one"})]}),t.jsx(E,{size:"sm",onClick:mo(n),children:"Review"})]})})}function rse({staged:e,onClose:n,onInstalled:s,onGone:r,onInstallFirst:a}){const{plan:i,busy:l,failed:o,approve:c,reject:d}=A2(e,s,r),h=(i==null?void 0:i.drift)??[];return t.jsxs(Je,{title:t.jsx(Eb,{svg:void 0,name:e.name,version:e.version,by:e.author?t.jsx(zm,{author:e.author}):bb(e.source,e.publisher),pills:t.jsxs(t.Fragment,{children:[" · ",t.jsx(Ce,{children:"read, not installed"})]})}),onClose:n,foot:t.jsxs(se,{children:[t.jsx("span",{className:"plugins-foot-note",children:"Nothing of it has run."}),t.jsx(gt,{}),t.jsx(E,{variant:"ghost",disabled:l,onClick:d,children:"Not this one"}),t.jsx(E,{variant:"accent",disabled:l||h.length>0,onClick:()=>c(!1),children:"Install"})]}),children:[t.jsx(re,{message:o}),t.jsx(T2,{staged:e,inSheet:!0,onInstallFirst:a}),i&&h.length>0?t.jsx(I2,{plan:i,busy:l,onReject:d,onInstallAnyway:()=>c(!0)}):null]})}const ase=10*60*1e3;function ise(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<ase?r.id:null}function lse({checkout:e,waiting:n}){const[s,r]=u.useState(!1),[a,i]=u.useState(null),l=vB(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(de,{gap:"sm",children:[t.jsx(re,{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),zd({kind:"plugins",...l?{line:`Loading ${l}…`}:{line:"Applying your plugin changes…"}},()=>T.serviceAction("restart")).catch(c=>i(ci(c))).finally(()=>r(!1))},children:"Restart to load it"}),children:[o," ",e?Gne:`${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 Sb="buddi.plugins.justInstalled";function ose(e){try{window.sessionStorage.setItem(Sb,e)}catch{}}function cse(){try{return window.sessionStorage.getItem(Sb)}catch{return null}}function dse({list:e,firstStepFor:n}){var d;const[s,r]=u.useState(()=>cse()),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(Sb)}catch{}r(null)};if(u.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. ${Cb(a)}.`:`${a.name} is loaded. First: ${((d=a.setup)==null?void 0:d.note)??"set it up on its settings page."}`})}const mo=e=>n=>{n.stopPropagation(),e()},use=e=>e.unlocks.filter(n=>n.drift.state==="not-accepted").length;function Cb(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 hse({plugin:e,listing:n,open:s,canOpen:r,busy:a,onDetails:i,onOpen:l,onSettings:o,onDisable:c,onEnable:d,onRemove:h,onUpdate:f,firstStep:m}){const p=e.enabled===!1,x=use(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(Yn,{svg:n==null?void 0:n.iconSvg}),title:t.jsxs(t.Fragment,{children:[e.name," ",t.jsx("span",{className:"plugins-ver",children:e.version}),x>0?t.jsxs("span",{className:"plugins-ask",children:[Ur(x,"agent","agents")," to accept"]}):null]}),sub:g?t.jsx("span",{className:"plugins-sub","data-tone":"warning",children:Cb(e)}):`by ${S2(e)} · from ${N2(e.source)} · ${k2(e.contribution)}`,side:t.jsxs("span",{className:"plugins-side",children:[g&&m?t.jsx(E,{size:"sm",onClick:mo(m.run),children:m.label}):null,n!=null&&n.update?t.jsxs(E,{size:"sm",disabled:a,onClick:mo(()=>f(n.update)),children:["Update to ",n.update]}):null,g?null:s,!g&&!r&&o?t.jsx(E,{size:"sm",variant:"ghost",onClick:y=>{y.stopPropagation(),o()},children:"Settings"}):null,t.jsx(E2,{plugin:e}),t.jsx(Qn,{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:d}:{label:"Disable…",hint:"keeps its data",onSelect:c},"separator",{label:"Remove…",tone:"critical",onSelect:h}]})]})})}const fse={"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 R2({plugin:e,unlocks:n}){return n.length===0?null:t.jsxs(ge,{title:"Agents it would unlock",children:[t.jsx("div",{className:"plugins-unlocks",children:t.jsx(ut,{children:n.map(s=>t.jsx(mse,{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:yt,children:"on the Agents page"}),"."]})]})}function mse({plugin:e,unlock:n}){const s=Vy(e,n.id),r=s.created?"up-to-date":n.drift.state,[a,i]=fse[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(Ce,{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(re,{message:s.failure}),s.created?t.jsx(HR,{agent:s.created}):null]})}function Eb({svg:e,name:n,version:s,by:r,pills:a}){return t.jsxs("span",{className:"plugins-sheet-title",children:[t.jsx(Yn,{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 pse({plugin:e,listing:n,notes:s,canOpen:r,busy:a,onOpen:i,onSettings:l,onClose:o,onDisable:c,onEnable:d,onRemove:h,onUpdate:f,firstStep:m}){var v,w;const p=e.enabled===!1,x=e.author!==void 0&&e.source.kind==="directory",g=(n==null?void 0:n.summary)??e.description,y=(e.network??((w=(v=n==null?void 0:n.claims)==null?void 0:v.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(Eb,{svg:n==null?void 0:n.iconSvg,name:e.name,version:e.version,by:e.author?t.jsx(zm,{author:e.author}):S2(e),pills:t.jsxs(t.Fragment,{children:[n?t.jsxs(t.Fragment,{children:[" · ",t.jsx(Nb,{entry:n})]}):null," · ",t.jsx(E2,{plugin:e})]})}),onClose:o,foot:t.jsxs(se,{children:[t.jsx(E,{variant:"danger-ghost",onClick:h,children:"Remove…"}),t.jsx(gt,{}),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:d,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: ",Cb(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(Qt,{items:[{label:"From",value:pj(e.source)},...x?[]:[{label:"Published by",value:bb(e.source,e.publisher)}],{label:"Integrity",value:t.jsx(gj,{value:e.integrity})},{label:"Installed",value:Ge(e.installedAt)},...e.installedAs?[{label:"Installed as",value:e.installedAs}]:[],{label:"Contributes",value:k2(e.contribution)},...e.network||n?[{label:"Talks to hosts",value:C2(y)}]:[],...j?[{label:"Reaches in buddi",value:kb(j)}]:[]]})}),t.jsx(R2,{plugin:e.name,unlocks:e.unlocks})]})}function gse({kind:e,name:n,canDisable:s,onCancel:r,onDisableInstead:a,onDisable:i,onRemove:l}){const[o,c]=u.useState(!1),[d,h]=u.useState(""),[f,m]=u.useState(!1),[p,x]=u.useState(null),g=j=>{m(!0),x(null),j().catch(v=>x(ci(v))).finally(()=>m(!1))};if(e==="disable")return t.jsxs(zt,{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(re,{message:p})]});const y=!o||d.trim()===n;return t.jsxs(zt,{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(gt,{}),t.jsx(E,{variant:"ghost",disabled:f,onClick:r,children:"Cancel"}),t.jsx(E,{variant:"danger",disabled:f||!y,onClick:()=>g(()=>l(o,d.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:d,onChange:j=>h(j.target.value)})}):null]}),t.jsx(re,{message:p})]})}function xse({plugins:e,openFor:n}){return t.jsxs(Kt,{boxed:!0,summary:`Ships with buddi · ${Ur(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"),Ur(s.contribution.tools,"tool","tools")]})]},s.name)})})]})}const vse=[{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 jse(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 wse({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 yse({entry:e,busy:n,onOpen:s,onInstall:r,onUpdate:a}){var i,l;return t.jsxs(Sr,{onClick:s,label:`${e.title}: details`,children:[t.jsxs("div",{className:"plugins-card-head",children:[t.jsx(Yn,{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?` · ${Ur(e.widgets.length,"widget","widgets")}`:""]})]})]}),t.jsx("p",{className:"plugins-summary",children:e.summary}),t.jsxs("div",{className:"plugins-card-foot",children:[t.jsx(Nb,{entry:e}),e.installed?t.jsxs(Ce,{children:["installed ",e.installed.version]}):null,t.jsx(gt,{}),e.update?t.jsxs(E,{size:"sm",disabled:n,onClick:mo(()=>a(e.update)),children:["Update to ",e.update]}):e.installed?null:t.jsx(E,{size:"sm",variant:"accent",disabled:n,onClick:mo(r),children:"Install"})]})]})}function bse(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(d=>d.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 kse({entry:e,canOpen:n,busy:s,onOpen:r,onClose:a,onInstall:i,onUpdate:l}){var m,p,x,g,y,j,v,w;const o=(m=e.screenshots)==null?void 0:m[0],c=(((x=(p=e.claims)==null?void 0:p.manifest)==null?void 0:x.network)??[]).map(N=>N.host),d=bse(e),h=((j=(y=(g=e.claims)==null?void 0:g.manifest)==null?void 0:y.agents)==null?void 0:j.length)??0,f=(w=(v=e.claims)==null?void 0:v.package)==null?void 0:w.dependencies;return t.jsxs(Je,{title:t.jsx(Eb,{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(Nb,{entry:e}),e.installed?t.jsxs(t.Fragment,{children:[" · ",t.jsxs(Ce,{children:["installed ",e.installed.version]})]}):null]})}),onClose:a,foot:t.jsxs(se,{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(gt,{}),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(Sse,{entry:e}),t.jsx("div",{className:"plugins-facts",children:t.jsx(Qt,{items:[{label:"Package",value:t.jsx("span",{className:"mono",children:`${e.npm}@${e.version}`})},...d?[{label:"Tools",value:d}]:[],...h>0?[{label:"Proposes",value:`${Ur(h,"agent","agents")}, created only if you accept`}]:[],{label:"Talks to hosts",value:C2(c)},{label:"Reaches in buddi",value:kb(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(wse,{pricing:e.pricing})]})}]})})]})}function Nse(e){return[j2(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 Sse({entry:e}){const n=e.widgets??[];return n.length===0?null:t.jsx(ge,{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:Nse(s)})]}),t.jsx("div",{className:"plugins-widget-frames",children:Une(s.sizes).map(r=>t.jsx(w2,{widget:s,size:r,svg:e.iconSvg},r))})]},s.id))})})}function Cse(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 Ese({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(w2,{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:[Cse(a)?"A widget":`${a.title} plugin`," · by ",((o=a.author)==null?void 0:o.name)??"someone who gave no name"," · ",j2(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 Ase({kind:e="all",onKind:n,navigate:s,market:r,loading:a,busy:i,onRetry:l,onOpen:o,onInstall:c,onUpdate:d}){const[h,f]=u.useState(""),[m,p]=u.useState("all"),x=(r==null?void 0:r.plugins)??[],g=[{value:"all",label:"All"},{value:"recommended",label:"Recommended"},...vse.filter(N=>x.some(k=>k.category===N.value))],y=x.filter(N=>{var k;return e==="widgets"&&(((k=N.widgets)==null?void 0:k.length)??0)===0||m==="recommended"&&(N.trust!=="by-buddi"||N.installed)||m!=="all"&&m!=="recommended"&&N.category!==m?!1:jse(N,h)}),j=h.trim(),v=t.jsx("div",{className:"plugins-kind",children:t.jsx(Jt,{label:"Show",options:$se,value:e,onChange:N=>n==null?void 0:n(N)})}),w=e==="plugins"||e==="widgets"?null:t.jsx(Tse,{kind:e,navigate:s});return e==="agents"?t.jsxs(de,{gap:"lg",children:[v,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(de,{gap:"lg",children:[v,t.jsxs(se,{children:[t.jsx(Cm,{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(vI,{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?` ${Ge(r.fetchedAt)}`:" last time","."]}):null,y.length>0&&e==="widgets"?t.jsx(Ese,{entries:y,busy:i,onOpen:o,onInstall:c}):y.length>0?t.jsx("div",{className:"plugins-grid",children:y.map(N=>t.jsx(yse,{entry:N,busy:i,onOpen:()=>o(N),onInstall:()=>c(N),onUpdate:k=>d(N,k)},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"&&!x.some(N=>{var k;return(((k=N.widgets)==null?void 0:k.length)??0)>0})?"No plugin on withbuddi.com brings a widget yet.":x.length===0?"withbuddi.com lists no plugins yet.":"Nothing on this shelf yet."})]}),w]})}const $se=[{value:"all",label:"All"},{value:"plugins",label:"Plugins"},{value:"widgets",label:"Widgets"},{value:"agents",label:"Agents"}];function Tse({kind:e,navigate:n}){const s=pe(()=>T.catalogue(),[]),r=Xy(),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=>As(c)==="ready"),o=e==="all"?l.slice(0,3):i.agents;return o.length===0?null:t.jsx(ge,{title:e==="all"?"Teammates":void 0,aside:t.jsx("a",{href:mn(),onClick:c=>{c.preventDefault(),a(mn())},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(QR,{entry:c,loaded:r,onOpen:()=>a(mn(c.name)),onAdd:()=>a(mn(c.name)),onUpdate:()=>a(mn(c.name))},c.name))})})}var Gd={},Ise=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then},P2={},Fs={};let Ab;const Rse=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];Fs.getSymbolSize=function(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};Fs.getSymbolTotalCodewords=function(n){return Rse[n]};Fs.getBCHDigit=function(e){let n=0;for(;e!==0;)n++,e>>>=1;return n};Fs.setToSJISFunction=function(n){if(typeof n!="function")throw new Error('"toSJISFunc" is not a valid function.');Ab=n};Fs.isKanjiModeEnabled=function(){return typeof Ab<"u"};Fs.toSJIS=function(n){return Ab(n)};var Um={};(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}}})(Um);function M2(){this.buffer=[],this.length=0}M2.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 Pse=M2;function qd(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)}qd.prototype.set=function(e,n,s,r){const a=e*this.size+n;this.data[a]=s,r&&(this.reservedBit[a]=!0)};qd.prototype.get=function(e,n){return this.data[e*this.size+n]};qd.prototype.xor=function(e,n,s){this.data[e*this.size+n]^=s};qd.prototype.isReserved=function(e,n){return this.reservedBit[e*this.size+n]};var Mse=qd,O2={};(function(e){const n=Fs.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}})(O2);var D2={};const Ose=Fs.getSymbolSize,YC=7;D2.getPositions=function(n){const s=Ose(n);return[[0,0],[s-YC,0],[0,s-YC]]};var L2={};(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,d=null,h=null;for(let f=0;f<i;f++){o=c=0,d=h=null;for(let m=0;m<i;m++){let p=a.get(f,m);p===d?o++:(o>=5&&(l+=n.N1+(o-5)),d=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 d=a.get(o,c)+a.get(o,c+1)+a.get(o+1,c)+a.get(o+1,c+1);(d===4||d===0)&&l++}return l*n.N2},e.getPenaltyN3=function(a){const i=a.size;let l=0,o=0,c=0;for(let d=0;d<i;d++){o=c=0;for(let h=0;h<i;h++)o=o<<1&2047|a.get(d,h),h>=10&&(o===1488||o===93)&&l++,c=c<<1&2047|a.get(h,d),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 d=0;d<l;d++){i(d),e.applyMask(d,a);const h=e.getPenaltyN1(a)+e.getPenaltyN2(a)+e.getPenaltyN3(a)+e.getPenaltyN4(a);e.applyMask(d,a),h<c&&(c=h,o=d)}return o}})(L2);var Bm={};const Ua=Um,Uu=[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],Bu=[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];Bm.getBlocksCount=function(n,s){switch(s){case Ua.L:return Uu[(n-1)*4+0];case Ua.M:return Uu[(n-1)*4+1];case Ua.Q:return Uu[(n-1)*4+2];case Ua.H:return Uu[(n-1)*4+3];default:return}};Bm.getTotalCodewordsCount=function(n,s){switch(s){case Ua.L:return Bu[(n-1)*4+0];case Ua.M:return Bu[(n-1)*4+1];case Ua.Q:return Bu[(n-1)*4+2];case Ua.H:return Bu[(n-1)*4+3];default:return}};var F2={},Wm={};const Rc=new Uint8Array(512),Cf=new Uint8Array(256);(function(){let n=1;for(let s=0;s<255;s++)Rc[s]=n,Cf[n]=s,n<<=1,n&256&&(n^=285);for(let s=255;s<512;s++)Rc[s]=Rc[s-255]})();Wm.log=function(n){if(n<1)throw new Error("log("+n+")");return Cf[n]};Wm.exp=function(n){return Rc[n]};Wm.mul=function(n,s){return n===0||s===0?0:Rc[Cf[n]+Cf[s]]};(function(e){const n=Wm;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}})(F2);const _2=F2;function $b(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}$b.prototype.initialize=function(n){this.degree=n,this.genPoly=_2.generateECPolynomial(this.degree)};$b.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=_2.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 Dse=$b,z2={},wi={},Tb={};Tb.isValid=function(n){return!isNaN(n)&&n>=1&&n<=40};var Jr={};const U2="[0-9]+",Lse="[A-Z $%*+\\-./:]+";let kd="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";kd=kd.replace(/u/g,"\\u");const Fse="(?:(?![A-Z0-9 $%*+\\-./:]|"+kd+`)(?:.|[\r
143
+ ]))+`;Jr.KANJI=new RegExp(kd,"g");Jr.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");Jr.BYTE=new RegExp(Fse,"g");Jr.NUMERIC=new RegExp(U2,"g");Jr.ALPHANUMERIC=new RegExp(Lse,"g");const _se=new RegExp("^"+kd+"$"),zse=new RegExp("^"+U2+"$"),Use=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");Jr.testKanji=function(n){return _se.test(n)};Jr.testNumeric=function(n){return zse.test(n)};Jr.testAlphanumeric=function(n){return Use.test(n)};(function(e){const n=Tb,s=Jr;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}}})(wi);(function(e){const n=Fs,s=Bm,r=Um,a=wi,i=Tb,l=7973,o=n.getBCHDigit(l);function c(m,p,x){for(let g=1;g<=40;g++)if(p<=e.getCapacity(g,x,m))return g}function d(m,p){return a.getCharCountIndicator(m,p)+4}function h(m,p){let x=0;return m.forEach(function(g){const y=d(g.mode,p);x+=y+g.getBitsLength()}),x}function f(m,p){for(let x=1;x<=40;x++)if(h(m,x)<=e.getCapacity(x,p,a.MIXED))return x}e.from=function(p,x){return i.isValid(p)?parseInt(p,10):x},e.getCapacity=function(p,x,g){if(!i.isValid(p))throw new Error("Invalid QR Code version");typeof g>"u"&&(g=a.BYTE);const y=n.getSymbolTotalCodewords(p),j=s.getTotalCodewordsCount(p,x),v=(y-j)*8;if(g===a.MIXED)return v;const w=v-d(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,x){let g;const y=r.from(x,r.M);if(Array.isArray(p)){if(p.length>1)return f(p,y);if(p.length===0)return 1;g=p[0]}else g=p;return c(g.mode,g.getLength(),y)},e.getEncodedBits=function(p){if(!i.isValid(p)||p<7)throw new Error("Invalid QR Code version");let x=p<<12;for(;n.getBCHDigit(x)-o>=0;)x^=l<<n.getBCHDigit(x)-o;return p<<12|x}})(z2);var B2={};const vj=Fs,W2=1335,Bse=21522,QC=vj.getBCHDigit(W2);B2.getEncodedBits=function(n,s){const r=n.bit<<3|s;let a=r<<10;for(;vj.getBCHDigit(a)-QC>=0;)a^=W2<<vj.getBCHDigit(a)-QC;return(r<<10|a)^Bse};var H2={};const Wse=wi;function po(e){this.mode=Wse.NUMERIC,this.data=e.toString()}po.getBitsLength=function(n){return 10*Math.floor(n/3)+(n%3?n%3*3+1:0)};po.prototype.getLength=function(){return this.data.length};po.prototype.getBitsLength=function(){return po.getBitsLength(this.data.length)};po.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 Hse=po;const Kse=wi,kg=["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 go(e){this.mode=Kse.ALPHANUMERIC,this.data=e}go.getBitsLength=function(n){return 11*Math.floor(n/2)+6*(n%2)};go.prototype.getLength=function(){return this.data.length};go.prototype.getBitsLength=function(){return go.getBitsLength(this.data.length)};go.prototype.write=function(n){let s;for(s=0;s+2<=this.data.length;s+=2){let r=kg.indexOf(this.data[s])*45;r+=kg.indexOf(this.data[s+1]),n.put(r,11)}this.data.length%2&&n.put(kg.indexOf(this.data[s]),6)};var Vse=go;const Gse=wi;function xo(e){this.mode=Gse.BYTE,typeof e=="string"?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}xo.getBitsLength=function(n){return n*8};xo.prototype.getLength=function(){return this.data.length};xo.prototype.getBitsLength=function(){return xo.getBitsLength(this.data.length)};xo.prototype.write=function(e){for(let n=0,s=this.data.length;n<s;n++)e.put(this.data[n],8)};var qse=xo;const Yse=wi,Qse=Fs;function vo(e){this.mode=Yse.KANJI,this.data=e}vo.getBitsLength=function(n){return n*13};vo.prototype.getLength=function(){return this.data.length};vo.prototype.getBitsLength=function(){return vo.getBitsLength(this.data.length)};vo.prototype.write=function(e){let n;for(n=0;n<this.data.length;n++){let s=Qse.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 Jse=vo,K2={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,d,h,f,m,p,x,g,y;!o.empty();){c=o.pop(),d=c.value,f=c.cost,m=s[d]||{};for(h in m)m.hasOwnProperty(h)&&(p=m[h],x=f+p,g=l[h],y=typeof l[h]>"u",(y||g>x)&&(l[h]=x,o.push(h,x),i[h]=d))}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})(K2);var Xse=K2.exports;(function(e){const n=wi,s=Hse,r=Vse,a=qse,i=Jse,l=Jr,o=Fs,c=Xse;function d(j){return unescape(encodeURIComponent(j)).length}function h(j,v,w){const N=[];let k;for(;(k=j.exec(w))!==null;)N.push({data:k[0],index:k.index,mode:v,length:k[0].length});return N}function f(j){const v=h(l.NUMERIC,n.NUMERIC,j),w=h(l.ALPHANUMERIC,n.ALPHANUMERIC,j);let N,k;return o.isKanjiModeEnabled()?(N=h(l.BYTE,n.BYTE,j),k=h(l.KANJI,n.KANJI,j)):(N=h(l.BYTE_KANJI,n.BYTE,j),k=[]),v.concat(w,N,k).sort(function(b,C){return b.index-C.index}).map(function(b){return{data:b.data,mode:b.mode,length:b.length}})}function m(j,v){switch(v){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(v,w){const N=v.length-1>=0?v[v.length-1]:null;return N&&N.mode===w.mode?(v[v.length-1].data+=w.data,v):(v.push(w),v)},[])}function x(j){const v=[];for(let w=0;w<j.length;w++){const N=j[w];switch(N.mode){case n.NUMERIC:v.push([N,{data:N.data,mode:n.ALPHANUMERIC,length:N.length},{data:N.data,mode:n.BYTE,length:N.length}]);break;case n.ALPHANUMERIC:v.push([N,{data:N.data,mode:n.BYTE,length:N.length}]);break;case n.KANJI:v.push([N,{data:N.data,mode:n.BYTE,length:d(N.data)}]);break;case n.BYTE:v.push([{data:N.data,mode:n.BYTE,length:d(N.data)}])}}return v}function g(j,v){const w={},N={start:{}};let k=["start"];for(let S=0;S<j.length;S++){const b=j[S],C=[];for(let $=0;$<b.length;$++){const A=b[$],I=""+S+$;C.push(I),w[I]={node:A,lastCount:0},N[I]={};for(let M=0;M<k.length;M++){const O=k[M];w[O]&&w[O].node.mode===A.mode?(N[O][I]=m(w[O].lastCount+A.length,A.mode)-m(w[O].lastCount,A.mode),w[O].lastCount+=A.length):(w[O]&&(w[O].lastCount=A.length),N[O][I]=m(A.length,A.mode)+4+n.getCharCountIndicator(A.mode,v))}}k=C}for(let S=0;S<k.length;S++)N[k[S]].end=0;return{map:N,table:w}}function y(j,v){let w;const N=n.getBestModeForData(j);if(w=n.from(v,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(v){return v.reduce(function(w,N){return typeof N=="string"?w.push(y(N,null)):N.data&&w.push(y(N.data,N.mode)),w},[])},e.fromString=function(v,w){const N=f(v,o.isKanjiModeEnabled()),k=x(N),S=g(k,w),b=c.find_path(S.map,"start","end"),C=[];for(let $=1;$<b.length-1;$++)C.push(S.table[b[$]].node);return e.fromArray(p(C))},e.rawSplit=function(v){return e.fromArray(f(v,o.isKanjiModeEnabled()))}})(H2);const Hm=Fs,Ng=Um,Zse=Pse,ere=Mse,tre=O2,nre=D2,jj=L2,wj=Bm,sre=Dse,Ef=z2,rre=B2,are=wi,Sg=H2;function ire(e,n){const s=e.size,r=nre.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 lre(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 ore(e,n){const s=tre.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 cre(e,n){const s=e.size,r=Ef.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 Cg(e,n,s){const r=e.size,a=rre.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 dre(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 d=!1;l<n.length&&(d=(n[l]>>>i&1)===1),e.set(a,o-c,d),i--,i===-1&&(l++,i=7)}if(a+=r,a<0||s<=a){a-=r,r=-r;break}}}function ure(e,n,s){const r=new Zse;s.forEach(function(c){r.put(c.mode.bit,4),r.put(c.getLength(),are.getCharCountIndicator(c.mode,e)),c.write(r)});const a=Hm.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 hre(r,e,n)}function hre(e,n,s){const r=Hm.getSymbolTotalCodewords(n),a=wj.getTotalCodewordsCount(n,s),i=r-a,l=wj.getBlocksCount(n,s),o=r%l,c=l-o,d=Math.floor(r/l),h=Math.floor(i/l),f=h+1,m=d-h,p=new sre(m);let x=0;const g=new Array(l),y=new Array(l);let j=0;const v=new Uint8Array(e.buffer);for(let b=0;b<l;b++){const C=b<c?h:f;g[b]=v.slice(x,x+C),y[b]=p.encode(g[b]),x+=C,j=Math.max(j,C)}const w=new Uint8Array(r);let N=0,k,S;for(k=0;k<j;k++)for(S=0;S<l;S++)k<g[S].length&&(w[N++]=g[S][k]);for(k=0;k<m;k++)for(S=0;S<l;S++)w[N++]=y[S][k];return w}function fre(e,n,s,r){let a;if(Array.isArray(e))a=Sg.fromArray(e);else if(typeof e=="string"){let d=n;if(!d){const h=Sg.rawSplit(e);d=Ef.getBestVersionForData(h,s)}a=Sg.fromString(e,d||40)}else throw new Error("Invalid data");const i=Ef.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=ure(n,s,a),o=Hm.getSymbolSize(n),c=new ere(o);return ire(c,n),lre(c),ore(c,n),Cg(c,s,0),n>=7&&cre(c,n),dre(c,l),isNaN(r)&&(r=jj.getBestMask(c,Cg.bind(null,c,s))),jj.applyMask(r,c),Cg(c,s,r),{modules:c,version:n,errorCorrectionLevel:s,maskPattern:r,segments:a}}P2.create=function(n,s){if(typeof n>"u"||n==="")throw new Error("No input text");let r=Ng.M,a,i;return typeof s<"u"&&(r=Ng.from(s.errorCorrectionLevel,Ng.M),a=Ef.from(s.version),i=jj.from(s.maskPattern),s.toSJISFunc&&Hm.setToSJISFunction(s.toSJISFunc)),fre(n,a,r,i)};var V2={},Ib={};(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),d=Math.floor((l+i.margin*2)*c),h=i.margin*c,f=[i.color.light,i.color.dark];for(let m=0;m<d;m++)for(let p=0;p<d;p++){let x=(m*d+p)*4,g=i.color.light;if(m>=h&&p>=h&&m<d-h&&p<d-h){const y=Math.floor((m-h)/c),j=Math.floor((p-h)/c);g=f[o[y*l+j]?1:0]}r[x++]=g.r,r[x++]=g.g,r[x++]=g.b,r[x]=g.a}}})(Ib);(function(e){const n=Ib;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,d=l;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),l||(d=r()),c=n.getOptions(c);const h=n.getImageWidth(i.modules.size,c),f=d.getContext("2d"),m=f.createImageData(h,h);return n.qrToImageData(m.data,i,c),s(f,d,h),f.putImageData(m,0,0),d},e.renderToDataURL=function(i,l,o){let c=o;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),c||(c={});const d=e.render(i,l,c),h=c.type||"image/png",f=c.rendererOpts||{};return d.toDataURL(h,f.quality)}})(V2);var G2={};const mre=Ib;function JC(e,n){const s=e.a/255,r=n+'="'+e.hex+'"';return s<1?r+" "+n+'-opacity="'+s.toFixed(2).slice(1)+'"':r}function Eg(e,n,s){let r=e+n;return typeof s<"u"&&(r+=" "+s),r}function pre(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),d=Math.floor(o/n);!c&&!i&&(i=!0),e[o]?(l++,o>0&&c>0&&e[o-1]||(r+=i?Eg("M",c+s,.5+d+s):Eg("m",a,0),a=0,i=!1),c+1<n&&e[o+1]||(r+=Eg("h",l),l=0)):a++}return r}G2.render=function(n,s,r){const a=mre.getOptions(s),i=n.modules.size,l=n.modules.data,o=i+a.margin*2,c=a.color.light.a?"<path "+JC(a.color.light,"fill")+' d="M0 0h'+o+"v"+o+'H0z"/>':"",d="<path "+JC(a.color.dark,"stroke")+' d="'+pre(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+d+`</svg>
149
+ `;return typeof r=="function"&&r(null,m),m};const gre=Ise,yj=P2,q2=V2,xre=G2;function Rb(e,n,s,r,a){const i=[].slice.call(arguments,1),l=i.length,o=typeof i[l-1]=="function";if(!o&&!gre())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,d){try{const h=yj.create(s,r);c(e(h,n,r))}catch(h){d(h)}})}try{const c=yj.create(s,r);a(null,e(c,n,r))}catch(c){a(c)}}Gd.create=yj.create;Gd.toCanvas=Rb.bind(null,q2.render);Gd.toDataURL=Rb.bind(null,q2.renderToDataURL);Gd.toString=Rb.bind(null,function(e,n,s){return xre.render(e,s)});async function vre(e){const n=await Gd.toString(e,{type:"svg",margin:4,errorCorrectionLevel:"M"});return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n)}`}const XC=10*6e4,jre=2e3;function Y2(e,n){const[s,r]=u.useState(null),[a,i]=u.useState(null),[l,o]=u.useState(!1),[c,d]=u.useState(!1),h=u.useRef(e);h.current=e;const f=u.useRef(n);f.current=n;const m=u.useCallback(async()=>{const p=await T.telegramPairing();r(p),d(!1),o(!1),i(await vre(p.link).catch(()=>""))},[]);return u.useEffect(()=>{if(!s||l||c)return;let p=!1;const x=Math.min(Date.parse(s.expiresAt)||Date.now()+XC,Date.now()+XC),g=window.setInterval(()=>{if(Date.now()>=x){d(!0);return}h.current().then(y=>{var j;p||!y||(o(!0),(j=f.current)==null||j.call(f))}).catch(()=>{})},jre);return()=>{p=!0,window.clearInterval(g)}},[s,l,c]),{offer:s,square:a,paired:l,stale:c,ask:m}}function wre({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 yre({offer:e,square:n,bot:s,status:r,paired:a}){const[i,l]=u.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(st,{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 Q2=new Set(["approval","question"]),ph={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."}},bre=new Set(["agent"]),kre={maxUrgency:"now",muted:[]};function Nre(e,n){var a;const s=ph[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 Sre({timezone:e}){var v,w,N;const n=pe(()=>T.notificationSettings(),[]),s=pe(()=>T.agents(),[]),r=pe(()=>T.notifications(20),[],3e4),a=pe(()=>T.telegram(),[]),i=u.useRef(!1);u.useEffect(()=>{var k,S;i.current||!r.data||window.location.hash!==nv||(i.current=!0,(S=(k=document.getElementById("notifications-recent"))==null?void 0:k.scrollIntoView)==null||S.call(k,{block:"start"}))},[r.data]);const[l,o]=u.useState(null),[c,d]=u.useState(!1),[h,f]=u.useState(!1),[m,p]=u.useState(null),x=((v=n.data)==null?void 0:v.channels)??[],g=l??((w=n.data)==null?void 0:w.settings),y=k=>{g&&(f(!1),o({...g,...k}))},j=()=>{g&&(d(!0),f(!1),p(null),T.saveNotificationSettings(g).then(()=>{f(!0),o(null),n.reload()}).catch(k=>p(k instanceof fe?k.message:String(k))).finally(()=>d(!1)))};return t.jsxs(de,{gap:"lg",children:[t.jsx(ge,{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(de,{divided:!0,children:[t.jsx(re,{message:n.error??m}),t.jsx(ge,{title:"Where buddi reaches you",children:g?x.length===0?t.jsxs("p",{className:"ui-card-meta",children:["No channel yet, so everything waits for you here. ",t.jsx("a",{href:ze("telegram"),children:"Set up Telegram"})," and buddi can reach you on your phone."]}):t.jsxs(de,{gap:"sm",children:[x.map(k=>{var S;return t.jsx(Rre,{channel:k,checked:(g.defaultChannel??((S=x[0])==null?void 0:S.kind))===k.kind,onPick:()=>y({defaultChannel:k.kind})},k.kind)}),t.jsx(Ire,{status:a.data,listed:x.some(k=>k.kind.startsWith("telegram"))})]}):t.jsx(be,{children:"Loading…"})}),t.jsx(ge,{title:"By kind",children:g?t.jsxs(de,{gap:"sm",children:[uz.filter(k=>!bre.has(k)).map(k=>t.jsxs("div",{className:"pref-row nt-kind",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:ph[k].label}),t.jsx("span",{className:"ui-field-hint",children:ph[k].hint})]}),t.jsxs("select",{"aria-label":ph[k].label,value:Pre(g,k,x),onChange:S=>{const b={...g.perKind};S.target.value==="default"?delete b[k]:b[k]=S.target.value,y({perKind:b})},children:[t.jsx("option",{value:"default",children:"Default"}),x.map(S=>t.jsx("option",{value:S.kind,children:S.label},S.kind)),Q2.has(k)?null:t.jsx("option",{value:"off",children:"Off"})]})]},k)),t.jsx("p",{className:"ui-field-hint",children:"Off keeps it in the list below and never sends it."})]}):null}),t.jsx(ge,{title:"Messages from your agents",children:g?t.jsx(Cre,{settings:g,agents:((N=s.data)==null?void 0:N.agents)??[],onChange:y}):null}),t.jsx(ge,{title:"Focus schedules",children:g?t.jsxs(de,{gap:"sm",children:[t.jsx(Dre,{schedules:g.schedules,onChange:k=>y({schedules:k})}),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:k=>y({endOfDay:k.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(ge,{title:"The last twenty",panel:!0,flush:!0,children:[t.jsx(re,{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(ut,{children:r.data.notifications.map(k=>{var S;return t.jsx(ot,{title:ad(k),sub:`${ft(k.createdAt,e)} · ${Nre(k,((S=s.data)==null?void 0:S.agents)??[])} · ${Mre(k,x)}`,side:t.jsx(Ore,{row:k})},k.id)})}):t.jsx(be,{children:"Loading…"})]})})]})}function Cre({settings:e,agents:n,onChange:s}){const r=e.perKind.agent!=="off",a=e.agents??kre,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(d=>d!==o)}});return t.jsxs(de,{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 Ere({timezone:e}){return t.jsx(Are,{timezone:e,onChange:()=>{}})}function Are({timezone:e,onChange:n}){var C,$;const s=pe(()=>T.telegramBot(),[]),r=pe(()=>T.telegramDevices(),[]),[a,i]=u.useState(!1),[l,o]=u.useState(""),[c,d]=u.useState(!1),[h,f]=u.useState(null),[m,p]=u.useState(null),x=u.useRef(new Set),g=Y2(()=>T.telegramDevices().then(A=>A.devices.some(I=>!x.current.has(I.id))),()=>{r.reload(),n()}),y=((C=s.data)==null?void 0:C.configured)??!1,j=!y||a,v=()=>{var I;if(l.trim()===""||c)return;d(!0),f(null);const A=a&&(((I=s.data)==null?void 0:I.running)??!1);T.saveTelegramToken(l.trim()).then(M=>{o(""),i(!1),f(M.restartNeeded?{ok:!1,text:M.note??"Saved. It will be ready the next time buddi starts."}:A?{ok:!0,text:"Saved. The new bot takes over the next time buddi starts."}:{ok:!0,text:"Saved."}),s.reload(),n()}).catch(M=>f({ok:!1,text:M instanceof fe?M.message:String(M)})).finally(()=>d(!1))},w=()=>{var A;p(null),x.current=new Set((((A=r.data)==null?void 0:A.devices)??[]).map(I=>I.id)),g.ask().catch(I=>p(I instanceof fe?I.message:String(I)))},{offer:N,square:k,paired:S,stale:b}=g;return t.jsx(ge,{title:"Telegram",aside:"Talk to buddi from your phone.",panel:!0,children:t.jsxs(de,{divided:!0,children:[t.jsx(ge,{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:v,children:"Save token"})]}):void 0,children:t.jsxs(de,{gap:"sm",children:[t.jsx(re,{message:s.error}),!s.data&&!s.error?t.jsx(be,{children:"Loading…"}):y&&!a?t.jsxs("div",{className:"nt-channel",children:[t.jsx("span",{className:"pref-label",children:($=s.data)!=null&&$.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:A=>o(A.target.value),onKeyDown:A=>{A.key==="Enter"&&(A.preventDefault(),v())}})})]}):null,h?t.jsx(q,{tone:h.ok?"good":"warning",role:"status",children:h.text}):null]})}),t.jsxs(ge,{title:"Your devices",children:[t.jsx(re,{message:r.error}),r.data?r.data.devices.length===0?t.jsx("p",{className:"ui-card-meta",children:"No phone is paired yet."}):t.jsx(ut,{children:r.data.devices.map(A=>t.jsx(ot,{title:A.name??`Telegram user ${A.userId}`,sub:`Paired ${ft(A.pairedAt,e)} · ${A.lastSeenAt?`last spoke ${Ge(A.lastSeenAt)}`:"has not spoken yet"}`,side:t.jsx($re,{id:A.id,onGone:()=>{r.reload(),n()}})},A.id))}):r.error?null:t.jsx(be,{children:"Loading…"})]}),t.jsx(ge,{title:"Pair a device",foot:y&&(!N||S)?t.jsx(E,{variant:N?void 0:"accent",onClick:w,children:"Pair a phone"}):y&&b?t.jsx(E,{variant:"accent",onClick:w,children:"New code"}):void 0,children:t.jsxs(de,{gap:"sm",children:[t.jsx(re,{message:m}),y?S?t.jsx(q,{tone:"good",role:"status",children:"Paired."}):N&&b?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(wre,{offer:N,square:k,children:t.jsx(Tre,{text:N.link})}),t.jsxs("p",{className:"ui-field-hint",children:["The code works until ",ft(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 $re({id:e,onGone:n}){const[s,r]=u.useState(!1),[a,i]=u.useState(!1),[l,o]=u.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(d=>o(d instanceof fe?d.message:String(d))).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 Tre({text:e}){const[n,s]=u.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 Ire({status:e,listed:n}){const s=ze("telegram");return e!=null&&e.running&&e.paired?t.jsx("p",{className:"ui-card-meta",children:"Telegram: paired with your phone"}):e!=null&&e.running?t.jsxs("p",{className:"ui-card-meta",children:["Telegram is running; ",t.jsx("a",{href:s,children:"pair your phone"})]}):e!=null&&e.configured?t.jsxs("p",{className:"ui-card-meta",children:["Telegram's token is saved but the bot isn't running. ",t.jsx("a",{href:s,children:"Open Telegram"})]}):e||!n?t.jsxs("p",{className:"ui-card-meta",children:["Telegram is not set up. ",t.jsx("a",{href:s,children:"Set up Telegram"})]}):null}function Rre({channel:e,checked:n,onPick:s}){const[r,a]=u.useState(!1),[i,l]=u.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 fe?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 Pre(e,n,s){const r=e.perKind[n];return r==="off"?Q2.has(n)?"default":"off":r&&s.some(a=>a.kind===r)?r:"default"}function Mre(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 Ore({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 ZC={mon:"Mon",tue:"Tue",wed:"Wed",thu:"Thu",fri:"Fri",sat:"Sat",sun:"Sun"},e1={mode:"do-not-disturb",days:[...Wx],from:"22:00",to:"07:00"};function Dre({schedules:e,onChange:n}){const s=(r,a)=>n(e.map((i,l)=>l===r?{...i,...a}:i));return t.jsxs(de,{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:Wx.map(l=>{const o=r.days.includes(l);return t.jsx("button",{type:"button",className:"nt-day","aria-pressed":o,"aria-label":`Schedule ${i} ${ZC[l]}`,onClick:()=>s(a,{days:o?r.days.filter(c=>c!==l):Wx.filter(c=>c===l||r.days.includes(c))}),children:ZC[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,{...e1,days:[...e1.days]}]),children:"Add a schedule"})})]})}const Lre="Remove buddi from this Mac?";function Fre(){const[e,n]=u.useState(null),[s,r]=u.useState(!1),[a,i]=u.useState(null),[l,o]=u.useState(null),[c,d]=u.useState(!1),h=()=>{d(!0),o(null),T.uninstallPlan().then(f=>{if(!f.available){i(f.reason);return}n(f),r(!0)}).catch(f=>o(f instanceof fe?f.message:String(f))).finally(()=>d(!1))};return t.jsxs(ge,{title:"Remove buddi",children:[t.jsxs(de,{gap:"sm",children:[t.jsx(re,{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(se,{align:"end",children:t.jsx(E,{variant:"danger",disabled:c||a!==null,onClick:h,children:"Remove buddi from this Mac…"})})]}),s&&e?t.jsx(Ure,{plan:e,onClose:()=>r(!1)}):null]})}function _re(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 zre=1e3;function Ure({plan:e,onClose:n}){const[s,r]=u.useState("plan"),[a,i]=u.useState(!1),[l,o]=u.useState(!1),[c,d]=u.useState(null),[h,f]=u.useState(null),[m,p]=u.useState(null),[x,g]=u.useState(!1),y=u.useRef(null);u.useEffect(()=>()=>{y.current!==null&&window.clearTimeout(y.current)},[]);const j=S=>{T.uninstallJob(S).then(b=>{if(f(b.detail??b.phase),!b.finishedAt){y.current=window.setTimeout(()=>j(S),zre);return}if(b.phase!=="done"||!b.report){d(`The last backup did not finish: ${b.error??"no reason given"}. Nothing was removed.`),r("plan");return}p(b.report),r("words")}).catch(b=>{d(b instanceof fe?b.message:String(b)),r("plan")})},v=()=>{d(null),r("backup"),T.uninstallBackup(e.token).then(S=>j(S.job.id)).catch(S=>{d(S instanceof fe?S.message:String(S)),r("plan")})},w=()=>{d(null),r("removing"),T.uninstall({token:e.token,wroteItDown:!0,keepData:a}).catch(S=>{S instanceof fe&&S.status===0||(d(S instanceof fe?S.message:String(S)),r("words"))})},N=_re(e,a),k=s==="plan"?t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx(E,{variant:"accent",onClick:v,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(zt,{title:Lre,onClose:s==="removing"?()=>{}:n,foot:k,children:t.jsxs(de,{gap:"sm",children:[t.jsx(re,{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(S=>t.jsx("li",{children:S},S))}),t.jsxs("p",{className:"ui-card-meta",children:["First, one last backup goes to ",t.jsx("span",{className:"mono",children:e.backups}),", where it stays."]}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:a,disabled:s!=="plan",onChange:S=>i(S.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(se,{align:"end",children:t.jsx(E,{onClick:()=>{navigator.clipboard.writeText(m.passphrase).then(()=>g(!0),()=>g(!1))},children:x?"Copied":"Copy"})}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:l,onChange:S=>o(S.target.checked)}),t.jsx("span",{children:"I wrote it down"})]})]}):null,t.jsx("ul",{className:"remove-list",children:N.map(S=>t.jsx("li",{children:S},S))})]}):null,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 Bre(){const e=pe(()=>T.cliTool(),[]),[n,s]=u.useState(!1),[r,a]=u.useState(null),[i,l]=u.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 fe?h.message:String(h))).finally(()=>s(!1))},d=o.installed[0];return t.jsx(ge,{title:"Command line",panel:!0,children:t.jsxs(de,{gap:"sm",children:[t.jsx(re,{message:r}),t.jsx("p",{className:"ui-card-meta",children:d?t.jsxs(t.Fragment,{children:["Terminal's ",t.jsx("span",{className:"mono",children:"buddi"})," is ",t.jsx("span",{className:"mono",children:d}),", 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(se,{align:"end",children:t.jsx(E,{disabled:n,onClick:c,children:d?"Install Again":"Install Command Line Tool"})})]})})}const Wre={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 Hre(e){const n=D6.map(r=>({id:r.id,route:ze(r.id),label:r.label,icon:Wre[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:LT(r.plugin,r.id),route:pr(r.plugin,r.id),label:r.title,icon:MP(r.icon),group:"plugins"}));return[...n,...s]}function J2(e){return O6.map(n=>({id:n.id,label:n.label,entries:e.filter(s=>s.group===n.id)})).filter(n=>n.entries.length>0)}function X2(e,n,s){return n?`${e}, ${n} open`:s?`${e}, ${s}`:void 0}function Kre({entries:e,active:n,counts:s={},dots:r={},navigate:a}){var d;const i=u.useRef(null),l=J2(e),o=e.some(h=>h.id===n)?n:(d=e[0])==null?void 0:d.id,c=h=>{var x;const f=[...((x=i.current)==null?void 0:x.querySelectorAll("a.settings-nav-link"))??[]],m=f.indexOf(document.activeElement);if(m===-1)return;const p=g=>{var y;h.preventDefault(),(y=f[Math.max(0,Math.min(f.length-1,g))])==null||y.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],x=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":X2(f.label,p,x),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}):x?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 Vre({entries:e,active:n,counts:s={},dots:r={},navigate:a}){const i=J2(e),l=e.find(o=>o.id===n)??e[0];return t.jsx("nav",{className:"settings-menu","aria-label":"Settings sections",children:t.jsxs(Dd,{modal:!1,children:[t.jsx(Ld,{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($o,{children:t.jsx(Fd,{className:"ui-menu settings-menu-list",align:"start",sideOffset:6,children:t.jsx(zU,{value:n,onValueChange:o=>{const c=e.find(d=>d.id===o);c&&a(c.route)},children:i.map((o,c)=>t.jsxs(RT,{children:[c>0?t.jsx(da,{className:"ui-menu-sep"}):null,t.jsx(Yi,{className:"ui-menu-label",children:o.label}),o.entries.map(d=>{const h=s[d.id],f=r[d.id];return t.jsxs(UU,{value:d.id,className:"ui-menu-item settings-menu-item","data-active":d.id===n?"true":void 0,"aria-label":X2(d.label,h,f),children:[t.jsxs("span",{className:"settings-menu-entry",children:[t.jsx(ie,{name:d.icon,className:"settings-nav-icon"}),t.jsx("span",{className:"settings-nav-text",children:d.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]},d.id)})]},o.id))})})})]})})}function Gre({hash:e,timezone:n,navigate:s,agents:r,pluginPages:a}){var w,N,k;const i=L6(e),l=VT(a!==void 0),o=a??l,c=DT(e),d=c?o.find(c.plugin,c.page):void 0,h=d?null:k6(e,o.settings);u.useEffect(()=>{h&&s(h,!0)},[h,s]);const f=Gn(my),m=Hre(o.settings),x={proposals:((N=(w=pe(()=>Promise.resolve().then(()=>T.proposals()),[],3e4).data)==null?void 0:w.open)==null?void 0:N.length)??0},g=pe(()=>T.version(),[]),y=pe(()=>Promise.resolve().then(()=>T.connectionSignals()),[],6e4),j={};g.data&&!g.data.checkout&&g.data.updateAvailable&&(j.system="a newer buddi is ready"),(((k=y.data)==null?void 0:k.signals)??[]).length>0&&(j.connections=JP);const v={entries:m,active:i,counts:x,dots:j,navigate:S=>s(S)};return t.jsxs("div",{className:"settings",children:[f?null:t.jsx(Kre,{...v}),t.jsx("div",{className:"settings-body",children:t.jsxs("div",{className:"ui-page",children:[i==="secrets"?t.jsx(_i,{before:t.jsx(Nc,{inline:!0,items:[{label:"Settings",href:un,onClick:()=>s(un)}]}),title:"Keys and secrets",lede:u2,actions:t.jsx(st,{variant:"accent",size:"sm",href:Zx,onClick:S=>{S.preventDefault(),s(Zx)},children:"Add a secret"})}):i==="computer"?t.jsx(_i,{before:t.jsx(Nc,{inline:!0,items:[{label:"Settings",href:un,onClick:()=>s(un)}]}),title:"Browser & apps",lede:"Where agents may look"}):i==="plugins"||i==="connections"?t.jsx(_i,{before:t.jsx(Nc,{inline:!0,items:[{label:"Settings",href:un,onClick:()=>s(un)}]}),title:i==="plugins"?"Plugins":"Connections",lede:i==="plugins"?Hne:RM}):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(Vre,{...v}):null,d?t.jsx(eP,{plugin:d.plugin,title:d.title,navigate:s},d.plugin):null,d?t.jsx(WY,{page:d,params:ty(e),navigate:s,timezone:n,siblings:o.all.filter(S=>S.plugin===d.plugin)}):null,i==="you"?t.jsx(yne,{embedded:!0}):null,i==="appearance"?t.jsx(qre,{railPages:o.rail}):null,i==="notifications"?t.jsx(Sre,{timezone:n}):null,i==="telegram"?t.jsx(Ere,{timezone:n}):null,i==="memory"?t.jsx(uM,{embedded:!0,agents:r,timezone:n,initialTab:hae(e)}):null,i==="proposals"?t.jsx(One,{embedded:!0,plugin:R6(e)}):null,i==="accounts"?t.jsx(Ote,{embedded:!0,account:N6(e)}):null,i==="computer"?t.jsx(T9,{embedded:!0,timezone:n,navigate:s}):null,i==="secrets"?t.jsx(Yte,{embedded:!0,timezone:n,secret:A6(e),adding:$6(e),navigate:s}):null,i==="connections"?t.jsx(hZ,{embedded:!0,timezone:n,connection:C6(e)}):null,i==="lock"?t.jsx(gne,{navigate:s}):null,i==="api"?t.jsx(wne,{timezone:n}):null,i==="watchers"?t.jsx(ane,{timezone:n,embedded:!0}):null,i==="backup"?t.jsx(Cte,{}):null,i==="plugins"?t.jsx(Xne,{railPages:o.rail,settingsPages:o.settings,navigate:s,hash:e}):null,i==="system"?t.jsx(Jre,{timezone:n}):null]})})]})}function qre({railPages:e}){const[n,s]=rM();return t.jsx(ge,{title:"Appearance",aside:"Kept in this browser only. Another browser keeps its own.",panel:!0,children:t.jsxs(de,{divided:!0,gap:"lg",children:[t.jsx(Ag,{label:"Theme",hint:"System follows your Mac.",children:t.jsx(Jt,{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(Ag,{label:"Background",hint:"Blue carries the first-run colours through the app. Sand is quieter.",children:t.jsx(Jt,{label:"Background",options:[{value:"blue",label:"Blue"},{value:"sand",label:"Sand"}],value:n.ground,onChange:r=>s({ground:r})})}),t.jsx(Ag,{label:"Page width",hint:"How far pages stretch on a wide screen.",children:t.jsx(Jt,{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(Qre,{pages:e}),t.jsx(Yre,{})]})})}function Yre(){var c,d,h;const e=pe(()=>T.overview(),[]),[n,s]=u.useState(null),r=((c=e.data)==null?void 0:c.glances)??[],a=((d=e.data)==null?void 0:d.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(de,{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(de,{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 Qre({pages:e}){const n=XP(),[s,r]=u.useState(null);if(e.length===0)return null;const a=(i,l)=>{r(null),DJ(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(de,{gap:"sm",children:[t.jsx(re,{message:s}),e.map(i=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:!n.has(yd(i)),onChange:l=>a(i,l.target.checked)}),t.jsx("span",{children:i.title})]},yd(i)))]})]})}function Ag({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 Jre({timezone:e}){const n=pe(()=>T.overview(),[],15e3),s=pe(()=>T.session(),[]),r=pe(()=>T.providerAccounts(),[]),a=n.data;return t.jsxs(de,{gap:"lg",children:[t.jsx(re,{message:n.error}),t.jsx(cae,{}),a?t.jsx(ge,{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(Ce,{tone:"warning",children:"paused"}):t.jsx(Ce,{tone:"good",children:"running"})]})}):null,t.jsxs(ge,{title:"This host",panel:!0,children:[t.jsx(Qt,{items:[{label:"Time zone",value:e},{label:"Server time",value:a?ft(a.now,e):"…"},{label:"Bound to",value:s.data?`${s.data.host}:${s.data.port}`:"…"},{label:"Credential vault",value:r.data?Zre(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(Xre,{}),t.jsx(XY,{}),t.jsx(Bre,{}),t.jsx(ute,{}),t.jsx(ge,{title:"Mail and sources",panel:!0,children:a?a.mail.length===0?t.jsx(be,{children:"No sources are installed."}):t.jsx(Qt,{items:a.mail.map(i=>({key:i.sourceId,label:t.jsx("span",{className:"mono",children:i.sourceId}),value:i.lastError?t.jsx("span",{className:"critical",children:i.lastError}):t.jsxs("span",{children:["polled ",Ge(i.lastRunAt)]})}))}):t.jsx(be,{children:"Loading…"})}),t.jsx(Fre,{})]})}function Xre(){var d;const e=pe(()=>T.service(),[],1e4),[n,s]=u.useState(null),[r,a]=u.useState(!1),[i,l]=u.useState(null),o=(d=e.data)!=null&&d.supervised?e.data.status:void 0;if(!o)return null;const c=h=>{a(!0),l(null),zd({kind:h},()=>T.serviceAction(h)).then(()=>{s(null)}).catch(f=>{l(f.message),e.reload()}).finally(()=>{a(!1)})};return t.jsx(ge,{title:"Service",panel:!0,children:t.jsxs(de,{divided:!0,children:[t.jsx(ge,{children:t.jsx(Qt,{items:[{label:"Database",value:t.jsx(t1,{state:o.database,pid:o.databasePid})},{label:"Gateway",value:t.jsx(t1,{state:o.gateway,pid:o.gatewayPid})},{label:"Supervisor",value:t.jsxs("span",{className:"mono",children:["pid ",o.supervisorPid]})}]})}),t.jsx(ge,{children:t.jsxs(de,{gap:"sm",children:[t.jsx(re,{message:i}),n?t.jsx(q,{tone:"warning",role:"alert",children:n==="stop"?"Stopping the gateway closes this dashboard. The database keeps running; run buddi in a terminal to bring the dashboard back.":"Restarting the gateway takes a few seconds. This page waits for it and comes back by itself."}):t.jsx("p",{className:"ui-card-meta",children:"Stopping the gateway ends this dashboard until buddi is run again."}),t.jsx(se,{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 t1({state:e,pid:n}){return t.jsxs("span",{children:[t.jsx(Ce,{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 Zre(e){return e==="keychain"?"macOS Keychain":e==="file"?"Encrypted file vault":e==="none"?"None":e}const eae=2e3,Af={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."},tae=new Set(["done","failed","rolled-back"]),nae="The check asks the npm registry for the newest version and sends nothing else.",sae="This takes a backup, installs the new version and restarts buddi. This page waits for it and comes back by itself.",rae=6e4;function $g(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:sae}}const aae="A checkout upgrades with git pull, then buddi upgrade in a terminal.",iae=15*6e4;function lae(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 n1(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<iae?s:null}function oae(e,n){const[s,r]=u.useState(void 0),[a,i]=u.useState(null),l=u.useRef(n);return l.current=n,u.useEffect(()=>{if(!e){r(void 0);return}let o=!1,c=!1;const d=()=>{o||c||T.upgradeJob(e).then(f=>{var m;o||(r(f),i(null),KT({step:Af[f.phase]??f.detail??f.phase}),(tae.has(f.phase)||f.finishedAt)&&(o=!0,f.phase==="failed"&&(io(),(m=l.current)==null||m.call(l,f))))}).catch(f=>{o||(f instanceof fe&&f.status!==0&&f.status<500?(o=!0,io(),i(f.message)):c=!0)})};d();const h=window.setInterval(d,eae);return()=>{o=!0,window.clearInterval(h)}},[e]),{job:s,error:a}}function cae(){var w;const[e,n]=u.useState(!1),s=pe(()=>T.version(),[],e?rae:void 0);u.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]=u.useState(null),[i,l]=u.useState(!1),[o,c]=u.useState(!1),[d,h]=u.useState(null),[f,m]=u.useState(null),p=u.useCallback(N=>{a(null),m(N)},[]),x=oae(r,p),g=s.data,y=()=>{c(!0),h(null),T.checkVersion().catch(N=>h(N instanceof fe?N.message:String(N))).finally(()=>{c(!1),s.reload()})},j=N=>{c(!0),h(null),T.setVersionCheck(N).catch(k=>h(k instanceof fe?k.message:String(k))).finally(()=>{c(!1),s.reload()})},v=()=>{c(!0),h(null),m(null),zd({kind:"upgrade",line:g!=null&&g.latest?`Upgrading to ${g.latest}…`:"Upgrading…",step:Af.starting,patienceMs:HT},()=>T.startUpgrade(g==null?void 0:g.latest)).then(N=>{var k;l(!1),a(((k=N==null?void 0:N.job)==null?void 0:k.id)??null)}).catch(N=>h(N instanceof fe?N.message:String(N))).finally(()=>c(!1))};return g!=null&&g.checkout?t.jsx(ge,{title:"Version",panel:!0,children:t.jsxs(de,{divided:!0,children:[t.jsx(ge,{children:t.jsx(Qt,{items:[{label:"Running",value:t.jsx("span",{className:"mono",children:g.current})}]})}),t.jsx(ge,{children:t.jsx("p",{className:"ui-card-meta",children:aae})})]})}):t.jsx(ge,{title:"Version",panel:!0,children:t.jsxs(de,{divided:!0,children:[t.jsx(ge,{children:t.jsxs(de,{gap:"sm",children:[t.jsx(re,{message:s.error??d}),t.jsx(Qt,{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 ",Ge(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(se,{align:"end",children:t.jsx(E,{disabled:o,onClick:y,children:"Check now"})})]})}),t.jsx(ge,{children:t.jsxs(de,{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:nae})]})}),g!=null&&g.updateAvailable&&g.latest&&g.latestNotes?t.jsx(ge,{title:`What changes in ${g.latest}`,children:t.jsx(xr,{text:g.latestNotes})}):null,t.jsx(ge,{children:t.jsxs(de,{gap:"sm",children:[t.jsx(dae,{...x,job:x.job??f??void 0}),!x.job&&!f&&!x.error&&g&&n1(g.history)?t.jsx(q,{tone:"critical",role:"alert",children:lae(n1(g.history),g.app===!0)}):null,i?t.jsx(q,{tone:"warning",role:"alert",children:$g((g==null?void 0:g.app)===!0,g==null?void 0:g.latest).warning}):null,t.jsx(se,{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:v,children:$g((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:$g((g==null?void 0:g.app)===!0,g!=null&&g.updateAvailable?g.latest:void 0).button})})]})}),g&&g.history.length>0?t.jsx(ge,{title:"Upgrades so far",children:t.jsx(Qt,{items:g.history.slice().reverse().map(N=>({key:N.startedAt,label:t.jsxs("span",{className:"mono",children:[N.from," → ",N.to]}),value:t.jsx(uae,{attempt:N})}))})}):null]})})}function dae({job:e,error:n}){return n?t.jsx(re,{message:n}):e?e.phase==="failed"?t.jsxs(q,{tone:"critical",role:"alert",children:[Af.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:Af[e.phase]??e.detail??e.phase}):null}function uae({attempt:e}){return t.jsxs("span",{children:[t.jsx(Ce,{tone:e.outcome==="done"?"good":e.outcome==="failed"?"critical":"warning",children:e.outcome})," ",Ge(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 hae(e){var s;return((s=/[?&]tab=(people|preferences|notes)\b/.exec(e))==null?void 0:s[1])??"people"}const nt={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 Pc(e){return e instanceof fe||e instanceof Error?e.message:String(e)}function Di({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 fae=1400;function Z2(e,n){const s=u.useRef(n);s.current=n,u.useEffect(()=>{if(!e)return;const r=window.setTimeout(()=>s.current(),fae);return()=>window.clearTimeout(r)},[e])}function eO(){const e=u.useRef(null);return u.useEffect(()=>{const n=window.requestAnimationFrame(()=>{var s;return(s=e.current)==null?void 0:s.focus()});return()=>window.cancelAnimationFrame(n)},[]),e}const mae={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}},pae=["gmail","icloud","fastmail","other"],Tg={plugin:"email",agent:"mail-triage"};function gae({onClose:e,onAdded:n}){const[s,r]=u.useState(null);return t.jsx(Je,{title:nt.mailbox.sheet,onClose:e,children:s===null?t.jsxs("div",{className:"wiz-sheet-body",children:[t.jsx("h3",{className:"frs-ask",children:nt.mailbox.which}),t.jsx("div",{className:"frs-choices",role:"group","aria-label":nt.mailbox.which,children:pae.map(a=>{const i=nt.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:nt.mailbox.later})]}):t.jsx(xae,{provider:s,onBack:()=>r(null),onClose:e,onAdded:n},s)})}function xae({provider:e,onBack:n,onClose:s,onAdded:r}){const a=eO(),[i,l]=u.useState(""),[o,c]=u.useState(""),[d,h]=u.useState(""),[f,m]=u.useState(""),[p,x]=u.useState({kind:"idle"});Z2(p.kind==="good",s);const[g,y]=u.useState(!1);u.useEffect(()=>{let k=!1;return Promise.resolve().then(()=>Xe.agents()).then(S=>{k||y(!((S==null?void 0:S.agents)??[]).some(b=>b.id===Tg.agent))}).catch(()=>{k||y(!1)}),()=>{k=!0}},[]);const j=nt.mailbox.providers[e],v=nt.mailbox.how[e],w=i.trim()!==""&&o.trim()!==""&&p.kind!=="busy"&&p.kind!=="good",N=()=>{if(!w)return;x({kind:"busy"});const k=e==="other"?{...d.trim()?{imapHost:d.trim()}:{},...f.trim()?{smtpHost:f.trim()}:{}}:mae[e];Promise.resolve().then(()=>T.pageAct("email",{tool:"email.add_account",args:{address:i.trim(),password:o,...k}})).then(async S=>{const b=S.result??{};c("");let C=nt.mailbox.reading;b.triage==="needs-agent"&&(C=await Promise.resolve().then(()=>T.acceptPluginAgent(Tg.plugin,Tg.agent)).then(()=>(window.dispatchEvent(new Event(xs)),nt.mailbox.reading)).catch($=>nt.mailbox.noTriage(Pc($)))),x({kind:"good",line:C}),r(b.address??i.trim().toLowerCase())}).catch(S=>x({kind:"bad",line:Pc(S)}))};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:k=>{k.preventDefault(),N()},children:[t.jsx(oe,{label:nt.mailbox.address,children:t.jsx("input",{ref:a,type:"email",autoComplete:"email",spellCheck:!1,value:i,onChange:k=>l(k.target.value)})}),t.jsx(oe,{label:e==="other"?nt.mailbox.otherPassword:nt.mailbox.password,hint:v?t.jsxs(t.Fragment,{children:[v.text," ",t.jsx("a",{href:v.href,target:"_blank",rel:"noreferrer",children:v.link})]}):void 0,children:t.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,value:o,onChange:k=>c(k.target.value)})}),e==="other"?t.jsx(Kt,{summary:nt.mailbox.server,children:t.jsxs("div",{className:"frs-form",children:[t.jsx("p",{className:"frs-later",children:nt.mailbox.serverHint}),t.jsx(oe,{label:nt.mailbox.imapHost,children:t.jsx("input",{spellCheck:!1,placeholder:"imap.example.com",value:d,onChange:k=>h(k.target.value)})}),t.jsx(oe,{label:nt.mailbox.smtpHost,children:t.jsx("input",{spellCheck:!1,placeholder:"smtp.example.com",value:f,onChange:k=>m(k.target.value)})})]})}):null,t.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]}),p.kind==="busy"?t.jsx(Di,{state:"busy",children:nt.checking}):null,p.kind==="good"?t.jsx(Di,{state:"good",children:p.line}):null,p.kind==="bad"?t.jsx(Di,{state:"bad",children:p.line}):null,p.kind==="idle"&&g?t.jsx("p",{className:"frs-later",children:nt.mailbox.brings}):null,t.jsx("p",{className:"frs-later",children:nt.mailbox.later})]}),t.jsx("div",{className:"ui-sheet-foot",children:t.jsxs(se,{children:[t.jsxs(E,{variant:"ghost",onClick:n,disabled:p.kind==="busy",children:[t.jsx(ie,{name:"chevron-left"}),nt.back]}),t.jsx(gt,{}),t.jsx(E,{variant:"accent",disabled:!w,onClick:N,children:nt.mailbox.submit})]})})]})}const tO=2e3,s1=8*6e4;function vae(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 jae({onClose:e,onLinked:n}){var U,P,W;const s=eO(),[r,a]=u.useState(null),[i,l]=u.useState(""),[o,c]=u.useState({kind:"idle"});Z2(o.kind==="good",e);const d=()=>T.pageQuery("calendar","settings").then(L=>L.data??{});u.useEffect(()=>{let L=!1;return d().then(Q=>{L||a(Q)}).catch(()=>{L||a({})}),()=>{L=!0}},[]);const h=L=>{c({kind:"good",line:L}),n(L)},f=((U=r==null?void 0:r.calendars)==null?void 0:U.length)??0,m=()=>{if(i.trim()===""||o.kind==="busy"||o.kind==="good")return;c({kind:"busy",line:nt.checking});const L=vae(i,((r==null?void 0:r.calendars)??[]).map(Q=>Q.name));Promise.resolve().then(()=>T.pageAct("calendar",{tool:"calendar.add",args:{name:L,link:i.trim()}})).then(Q=>{var V;l("");const F=((V=Q.result)==null?void 0:V.note)??"",ae=/(\d+) events? read/.exec(F);h(ae?nt.calendar.events(Number(ae[1])):nt.calendar.found(1))}).catch(Q=>c({kind:"bad",line:Pc(Q)}))},[p,x]=u.useState(null),[g,y]=u.useState(!1),[j,v]=u.useState(0),w=u.useRef(!1),N=u.useRef(void 0),k=(r==null?void 0:r.googleAvailable)===!0,S=u.useRef(null);u.useEffect(()=>{if(!k)return;let L=!1;const Q=async ae=>{var V,J;if(!(L||w.current)){window.clearTimeout(N.current);try{const H=G=>{const ce=G==null?void 0:G[0];return ce&&ce.state==="waiting"&&ce.url?ce:void 0};let X=ae?void 0:H((V=(await T.pageQuery("calendar","sign_in")).data)==null?void 0:V.rows);if(!X){if(L||w.current)return;await T.pageAct("calendar",{tool:"calendar.google_sign_in",args:{}}),X=H((J=(await T.pageQuery("calendar","sign_in")).data)==null?void 0:J.rows)}if(L||w.current)return;if(!X)throw new Error("no address to open");S.current={id:X.id,at:Date.now()},x({id:X.id,url:X.url}),y(!1),N.current=window.setTimeout(()=>void Q(!0),s1)}catch{L||(S.current=null,x(null),y(!0))}}},F=()=>{const ae=S.current;document.visibilityState!=="visible"||!ae||w.current||Date.now()-ae.at>=s1&&Q(!0)};return document.addEventListener("visibilitychange",F),Q(!1),()=>{L=!0,window.clearTimeout(N.current),document.removeEventListener("visibilitychange",F);const ae=S.current;S.current=null,ae&&!w.current&&T.pageAct("calendar",{tool:"calendar.google_cancel",args:{id:ae.id}}).catch(()=>{})}},[k,j]);const b=L=>{c({kind:"bad",line:L}),w.current=!1,x(null),v(Q=>Q+1)},[C,$]=u.useState(0),A=o.kind==="google"?((P=o.signIn)==null?void 0:P.id)??null:null;u.useEffect(()=>{if(C===0)return;let L=!1,Q=!1,F=!1;const ae=()=>{L=!0,window.clearInterval(J)},V=()=>{L||Q||(Q=!0,T.pageQuery("calendar","sign_in").then(async H=>{var xe,De,B,ne;if(L)return;const X=((De=(xe=H.data)==null?void 0:xe.rows)==null?void 0:De[0])??null;if(!X)return;if(X.state==="waiting"){c(Z=>{var ve;return Z.kind==="google"&&((ve=Z.signIn)==null?void 0:ve.url)===X.url?Z:{kind:"google",signIn:X}});return}if(X.state==="failed"){ae(),b(X.problem||X.note);return}ae(),X.state==="received"&&!F&&(F=!0,c({kind:"busy",line:nt.calendar.reading}),await T.pageAct("calendar",{tool:"calendar.google_finish",args:{id:X.id}}));const G=await d();await T.pageAct("calendar",{tool:"calendar.google_dismiss",args:{id:X.id}}).catch(()=>{});const ce=(((B=G.calendars)==null?void 0:B.length)??0)-f;h(nt.calendar.found(ce>0?ce:((ne=G.calendars)==null?void 0:ne.length)??0))}).catch(H=>{ae(),b(Pc(H))}).finally(()=>{Q=!1}))},J=window.setInterval(V,tO);return V(),()=>{L=!0,window.clearInterval(J)}},[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:""}}),$(L=>L+1))},M=()=>{w.current=!0,window.clearTimeout(N.current),c({kind:"busy",line:nt.calendar.starting}),Promise.resolve().then(()=>T.pageAct("calendar",{tool:"calendar.google_sign_in",args:{}})).then(()=>{c({kind:"google",signIn:null}),$(L=>L+1)}).catch(L=>b(Pc(L)))},O=()=>{const L=A??(o.kind!=="good"?p==null?void 0:p.id:void 0);window.clearTimeout(N.current),L&&T.pageAct("calendar",{tool:"calendar.google_cancel",args:{id:L}}).catch(()=>{}),e()},R=o.kind==="busy"||o.kind==="google"||o.kind==="good",_=o.kind==="google"?(W=o.signIn)==null?void 0:W.url:o.kind==="busy"||o.kind==="good"||p==null?void 0:p.url,z=o.kind==="google"&&p===null;return t.jsxs(Je,{title:nt.calendar.sheet,onClose:O,children:[t.jsxs("div",{className:"wiz-sheet-body",children:[t.jsx("h3",{className:"frs-ask",children:nt.calendar.ask}),r!=null&&r.googleAvailable?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"frs-google",children:[_?t.jsxs(st,{variant:"accent",size:"lg",href:_,target:"_blank",rel:"noreferrer",onClick:I,children:[z?nt.calendar.continue:nt.calendar.google,t.jsx(ie,{name:"external"})]}):t.jsxs(E,{variant:"accent",size:"lg",disabled:R||!g,onClick:M,children:[nt.calendar.google,t.jsx(ie,{name:"external"})]}),t.jsx("span",{className:"wiz-opt-line",children:nt.calendar.googleLine})]}),t.jsx("div",{className:"frs-or",children:nt.calendar.or})]}):null,t.jsxs("form",{className:"frs-form",onSubmit:L=>{L.preventDefault(),m()},children:[t.jsx(oe,{label:nt.calendar.field,children:t.jsx("input",{ref:s,type:"url",inputMode:"url",autoComplete:"off",spellCheck:!1,placeholder:nt.calendar.placeholder,value:i,disabled:R,onChange:L=>l(L.target.value)})}),t.jsx(Kt,{summary:nt.calendar.where,children:t.jsx("dl",{className:"frs-help",children:nt.calendar.help.map(L=>t.jsxs("div",{children:[t.jsx("dt",{children:L.name}),t.jsx("dd",{children:L.text})]},L.name))})}),t.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]}),o.kind==="busy"?t.jsx(Di,{state:"busy",children:o.line}):null,o.kind==="google"?t.jsx(Di,{state:"busy",children:nt.calendar.waiting}):null,o.kind==="good"?t.jsx(Di,{state:"good",children:o.line}):null,o.kind==="bad"?t.jsx(Di,{state:"bad",children:o.line}):null,t.jsx("p",{className:"frs-later",children:nt.calendar.later})]}),t.jsx("div",{className:"ui-sheet-foot",children:t.jsx(se,{align:"end",children:t.jsx(E,{variant:"accent",disabled:R||i.trim()==="",onClick:m,children:nt.calendar.submit})})})]})}function wae({onClose:e,onUnderstood:n}){return t.jsxs(Je,{title:nt.bank.sheet,onClose:e,children:[t.jsxs("div",{className:"wiz-sheet-body",children:[t.jsx("h3",{className:"frs-ask",children:nt.bank.ask}),t.jsx("p",{className:"frs-text",children:nt.bank.line})]}),t.jsx("div",{className:"ui-sheet-foot",children:t.jsx(se,{align:"end",children:t.jsx(E,{variant:"accent",onClick:()=>{n(),e()},children:nt.bank.ok})})})]})}function yae(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 bae({progress:e}){return t.jsxs(de,{gap:"sm",children:[t.jsx("span",{role:"status",children:yae(e)}),t.jsx(gy,{value:(e==null?void 0:e.percent)??0,label:"Fetching the browser"})]})}const $f=["hello","brain","takeOn","reach","assistant","handover"],nO={hello:"you",brain:"model",takeOn:"take-on",reach:"reach",assistant:"agent",handover:"hello"};function sO(e){return((e==null?void 0:e.accounts)??[]).filter(n=>n.enabled&&n.configured&&n.removalPending!==!0)}function kae(e){var i,l,o;const n=sO(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 rO(e){var i,l,o,c,d;const n=kae(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")||((d=r.reach)==null?void 0:d.browser)===!0?{browser:e.browser??"other"}:{},...s?{assistant:s}:{}}}function aO(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 gh(e){return $f.find(n=>!aO(e,n))??"handover"}function Nae(e){const n=$f.indexOf(e);return n>0?$f[n-1]:null}function r1(e,n,s){return s===n?"now":aO(e,s)?"done":"todo"}function Sae(e,n){return{...e}}const bj="buddi.firstRun.restore";function kj(e){try{e===null?window.sessionStorage.removeItem(bj):window.sessionStorage.setItem(bj,e)}catch{}}function iO(){try{return window.sessionStorage.getItem(bj)}catch{return null}}function Cae(e){const n=rO(e),s=gh(n);return{answers:n,open:s,stay:s!=="handover"}}function Eae(e){return e.trim().startsWith("sk-ant-")?"anthropic":"openai"}function Aae(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 $ae=6e4,Tae=5*6e4,lO=1500,Iae=2e3,Rae="(max-width: 720px)";function Lo(){const e=u.useRef(null);return u.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 Pb=u.createContext({busy:0,report:()=>{}});function Pae({children:e}){const[n,s]=u.useState(0),r=u.useCallback(i=>s(l=>Math.max(0,l+(i?1:-1))),[]),a=u.useMemo(()=>({busy:n,report:r}),[n,r]);return t.jsx(Pb.Provider,{value:a,children:e})}function vt({children:e}){const{busy:n}=u.useContext(Pb);return t.jsxs("div",{className:"wiz-say",children:[t.jsx(Bd,{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 gs({line:e}){const{report:n}=u.useContext(Pb);return u.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 Mb=u.createContext(null);function bn({children:e,actions:n}){const s=u.useContext(Mb),r=n==null?null:s?ko.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 Is({onClick:e,disabled:n}){return t.jsxs(E,{variant:"ghost",size:"lg",onClick:e,disabled:n,children:[t.jsx(ie,{name:"chevron-left"}),D.back]})}function Fo({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 Mae({navigate:e,timezone:n}){var Vt,Un,Pn,Mn,gn,xn,It;const s=Gn(Rae),[r,a]=u.useState(void 0);u.useEffect(()=>{T.session().then(Ae=>a(Ae.platform)).catch(()=>{})},[]);const[i,l]=u.useState({}),[o,c]=u.useState(null),[d,h]=u.useState(void 0),[f,m]=u.useState(void 0),[p,x]=u.useState([]),[g,y]=u.useState(null),[j,v]=u.useState(null),[w,N]=u.useState(!1),[k,S]=u.useState(null),[b,C]=u.useState(null),[$,A]=u.useState(null),[I,M]=u.useState(null),[O,R]=u.useState(()=>iO()?"running":"idle"),[_,z]=u.useState({}),[U,P]=u.useState([]),[W,L]=u.useState(0),Q=u.useRef(void 0),[F,ae]=u.useState(null),[V,J]=u.useState(null),H=u.useCallback(()=>{Promise.resolve().then(()=>T.takeOnProgress()).then(Ae=>{Ae&&Array.isArray(Ae.plugins)&&ae(Ae)}).catch(()=>{})},[]);u.useEffect(()=>{if(!(F!=null&&F.running))return;const Ae=window.setInterval(H,Iae);return()=>window.clearInterval(Ae)},[F==null?void 0:F.running,H]);const X=u.useMemo(()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone||n}catch{return n}},[n]),G=u.useRef(e);G.current=e;const ce=u.useCallback(async(Ae=!0,Ze=!1)=>{var vn,nn,Cn,_s,On,yi,tr,Cr,bi;const[Re,we,Y,Le,Ct,on]=await Promise.all([T.onboarding().catch(()=>{}),T.owner().catch(()=>{}),T.providerAccounts().catch(()=>{}),Xe.agents().catch(()=>{}),T.browser().catch(()=>{}),T.providers().catch(()=>{})]);h(Y),Array.isArray(Re==null?void 0:Re.offers)&&J(Re.offers);const Te=(nn=(vn=on==null?void 0:on.providers.find(ht=>ht.kind==="anthropic"))==null?void 0:vn.defaultModel)==null?void 0:nn.trim();m(Te||void 0),x((we==null?void 0:we.zones)??[]),S(((Cn=Re==null?void 0:Re.details)==null?void 0:Cn.conversationId)??null);const Oe=(Le==null?void 0:Le.agents.find(ht=>ht.id===Le.defaultAgentId))??(Le==null?void 0:Le.agents[0]);Oe&&y(Oe),C(Re&&!Re.needs.agent&&Oe?{id:Oe.id,name:Oe.name,avatar:((_s=Oe.avatar)==null?void 0:_s.kind)==="emoji"?Oe.avatar.value:"",description:Oe.description,...Oe.picture?{picture:Oe.picture}:{}}:null),Array.isArray((On=Re==null?void 0:Re.details)==null?void 0:On.takeOn)&&H();const dt={onboarding:Re,owner:we,accounts:Y,browser:(yi=Ct==null?void 0:Ct.browser)==null?void 0:yi.engine,...Oe?{assistant:{id:Oe.id,name:Oe.name,avatar:((tr=Oe.avatar)==null?void 0:tr.kind)==="emoji"?Oe.avatar.value:""}}:{}};if(Ze){const ht=Cae(dt);if(l(ht.answers),c(ht.open),!ht.stay){const Xr=(Cr=Re==null?void 0:Re.details)==null?void 0:Cr.conversationId;G.current(Xr&&Oe?lt(Oe.id,Xr):In,!0)}return}if(Ae&&(Re==null?void 0:Re.state)==="done"){const ht=(bi=Re.details)==null?void 0:bi.conversationId;G.current(ht&&Oe?lt(Oe.id,ht):In,!0);return}if(!Ae)return;const Qe=rO(dt);l(Qe),c(ht=>ht??gh(Qe))},[]);u.useEffect(()=>{ce()},[ce]);const xe=(Ae,Ze={})=>{Promise.resolve().then(()=>T.onboardingStep(nO[Ae],Ze)).catch(()=>{})},De=Ae=>gh(Ae)==="brain"&&_.brain?{...Ae,brain:_.brain}:Ae,B=(Ae,Ze)=>{const Re=De(Ze);Re.brain&&(Q.current=Re.brain),v(null),P([]),l(Re),Ae==="brain"&&Re.brain?xe(Ae,{accountId:Re.brain.accountId}):Ae==="reach"?xe(Ae,Re.reach?{reach:Re.reach}:{}):Ae!=="takeOn"&&xe(Ae),c(gh(Re))},ne=(Ae,Ze)=>{v(null),l(Ze),Ze.brain&&(Q.current=Ze.brain),Ae==="brain"&&Ze.brain&&xe(Ae,{accountId:Ze.brain.accountId})},Z=Ae=>{v(null),l(Ze=>Sae(Ze)),c(Ae)},ve=()=>{if(!o)return;const Ae=Nae(o==="handover"?"handover":o);Ae&&Z(Ae)},$e=()=>{const Ae=i.brain??Q.current,Ze=((F==null?void 0:F.plugins)??[]).filter(Re=>Re.state==="ready").map(Re=>Re.title);v(null),z({}),P([]),l({}),c("hello"),L(Re=>Re+1),(async()=>{var Te;const[Re,we,Y]=await Promise.all([Promise.resolve().then(()=>T.providerAccounts()).catch(()=>{}),Promise.resolve().then(()=>T.telegram()).catch(()=>{}),Promise.resolve().then(()=>T.browser()).catch(()=>{})]),Le=sO(Re),Ct=Ae&&Le.some(Oe=>Oe.id===Ae.accountId)?Ae:void 0;Re&&h(Re),z(Ct?{brain:Ct}:{});const on=[...new Set(Le.map(Oe=>Oe.label)),...we!=null&&we.paired?[D.startOver.telegram]:[],...((Te=Y==null?void 0:Y.browser)==null?void 0:Te.engine)==="chromium"?[D.startOver.browser]:[],...Ze];P(on.length>0?[D.startOver.said(on.join(", "))]:[])})()},Se=()=>{N(!0),T.skipOnboarding().then(()=>e(In)).catch(Ae=>v(Ae instanceof fe?Ae.message:String(Ae))).finally(()=>N(!1))},me=pe(()=>T.version().catch(()=>({current:""})),[]),Ee=u.useRef(null);u.useEffect(()=>{Ee.current&&(Ee.current.scrollTop=0)},[o]);const Pe=O==="running",Me=Object.keys(i).length===0,he={answers:i,accounts:d,claudeModel:f,zones:p,browserZone:X,assistantAgent:g,met:k,onMet:S,existing:b,progress:F,offers:V,onProgress:H,navigate:e,onSettled:Ae=>o&&B(o,Ae),onKept:Ae=>o&&ne(o,Ae),onBack:ve,onTrouble:v,onReload:()=>void ce(!1),onPickAnotherBrain:()=>Z("brain"),onSpoken:M},ke=(i.takeOn??[]).map(Ae=>{var Ze;return((Ze=Zh.find(Re=>Re.id===Ae))==null?void 0:Ze.title)??Ae}),Be=(F==null?void 0:F.plugins)??[],qe=Be.filter(Ae=>Ae.state==="ready").length,at=Be.length===0?null:F!=null&&F.running?D.takeOn.installing(qe,Be.length):qe===Be.length?D.takeOn.installed:null,le=[(Vt=i.reach)!=null&&Vt.phone?D.reach.done.phone:null,(Un=i.reach)!=null&&Un.mailbox?D.reach.done.mailbox:null,(Pn=i.reach)!=null&&Pn.app||(Mn=i.reach)!=null&&Mn.browser?D.reach.done.app:null].filter(Ae=>Ae!==null),ye={hello:{answer:D.hello.answer(i.name??""),sub:i.clock??null},brain:{answer:D.brain.answer(((gn=i.brain)==null?void 0:gn.label)??"")},takeOn:{answer:D.takeOn.answer(ke),sub:at},reach:{answer:D.reach.answer(le)},assistant:{answer:((xn=i.assistant)==null?void 0:xn.name)??""}},et=$f.filter(Ae=>Ae!=="handover"),pt=o===null||o==="handover"?et.length:et.indexOf(o),kt=Math.min(pt,et.length-1),Ot=I?null:t.jsxs("div",{className:"wiz-map-out",children:[t.jsx("button",{type:"button",className:"wiz-link",disabled:w,onClick:Se,children:D.later}),o==="hello"&&Me&&O==="idle"?t.jsx("button",{type:"button",className:"wiz-link",onClick:()=>R("form"),children:D.restore.offer}):!Pe&&o!==null&&!(o==="hello"&&Me)?t.jsx("button",{type:"button",className:"wiz-link",disabled:w,onClick:$e,children:D.startOver.link}):null]}),Ut=r===void 0||r==="darwin"?D.tagline:D.taglineElsewhere,Sn=o&&o!=="handover"?t.jsx("span",{className:"wiz-count",children:D.count(pt+1)}):t.jsx("span",{className:"wiz-count"});return t.jsx(Mb.Provider,{value:$,children:t.jsx(Pae,{children:t.jsxs(wI,{className:"wiz-ground",children:[t.jsx("div",{className:"wiz",ref:Ee,"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(hd,{size:"sm"}),t.jsx("span",{className:"wiz-dots","aria-label":o&&o!=="handover"?D.count(pt+1):void 0,children:et.map(Ae=>t.jsx("i",{"data-state":r1(i,o,Ae)},Ae))}),t.jsx("span",{className:"wiz-strip-name",children:o&&o!=="handover"?D.strip(pt+1,D.chapters[pt]??""):D.handover.starterLabel})]}):t.jsxs("nav",{className:"wiz-map","aria-label":"Chapters",children:[t.jsxs("div",{className:"wiz-head",children:[t.jsx(hd,{size:"lg"}),t.jsxs("div",{children:[t.jsx("div",{className:"wiz-head-name",children:"buddi"}),t.jsx("div",{className:"wiz-head-line",children:Ut}),(It=me.data)!=null&&It.current?t.jsxs("div",{className:"wiz-head-version mono",children:["buddi ",me.data.current]}):null]})]}),et.map((Ae,Ze)=>{const Re=Pe?Ae==="hello"?"now":"todo":r1(i,o,Ae),we=ye[Ae];return t.jsxs("div",{className:"wiz-ch","data-state":Re,"aria-current":Re==="now"?"step":void 0,children:[t.jsx("span",{className:"wiz-num","data-state":Re,children:Re==="done"?t.jsx(ie,{name:"check",size:12}):Ze+1}),t.jsxs("span",{className:"wiz-ch-label",children:[Re==="done"?we.answer:D.chapters[Ze],Re==="done"&&we.sub?t.jsx("span",{className:"wiz-ch-sub",children:we.sub}):null]}),Re==="done"&&!Pe?t.jsx("button",{type:"button",className:"wiz-link",onClick:()=>Z(Ae),children:D.change}):null]},Ae)}),t.jsx("div",{className:"wiz-map-spacer"}),t.jsx("div",{className:"wiz-map-note",children:D.mapNotes[kt]}),Ot]}),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(B5,{dock:t.jsxs(t.Fragment,{children:[Sn,t.jsx("div",{className:"wiz-dock-actions",ref:A})]}),children:[Pe?t.jsx(hie,{onDone:Ae=>{R("idle"),P([...Ae?[D.restore.welcome(Ae)]:[],D.restore.keys]),ce(!0,!0)},onFailed:Ae=>{R("idle"),v(Ae)}}):o==="hello"?t.jsx(Oae,{...he}):o==="brain"?t.jsx(Lae,{...he}):o==="takeOn"?t.jsx(eie,{...he}):o==="reach"?t.jsx(tie,{...he}):o==="assistant"?t.jsx(oie,{...he}):o==="handover"?t.jsx(cie,{...he}):t.jsx(gs,{}),U.length>0||j?t.jsxs(ct,{children:[U.map(Ae=>t.jsx(vt,{children:Ae},Ae)),j?t.jsx(vt,{children:j}):null]}):null]},`${W}-${o??""}-${Pe?"r":""}`),s?t.jsx("div",{className:"wiz-phone-out",children:Ot}):null]})})]})}),O==="form"?t.jsx(uie,{onCancel:()=>R("idle"),onStarted:()=>R("running"),onTrouble:v}):null]})})})}function _o({children:e}){return t.jsx("h1",{className:"wiz-title",children:e})}function a1(e){try{return $t(new Date,e)}catch{return""}}function Oae({answers:e,zones:n,browserZone:s,onSettled:r,onTrouble:a}){const i=Lo(),[l,o]=u.useState(e.name??""),[c,d]=u.useState(e.clock??s),[h,f]=u.useState(!1),[m,p]=u.useState(!1),x=()=>{const g=l.trim();g===""||m||(p(!0),T.setOwner({preferredName:g,timezone:c}).then(()=>r({...e,name:g,clock:c})).catch(y=>a(y instanceof fe?y.message:String(y))).finally(()=>p(!1)))};return t.jsxs(t.Fragment,{children:[t.jsx(_o,{children:D.hello.title}),t.jsx(ct,{children:D.hello.opening.map(g=>t.jsx(vt,{children:g},g))}),t.jsxs(bn,{actions:t.jsx(Fo,{onClick:x,disabled:m||l.trim()==="",children:D.hello.submit}),children:[t.jsxs("div",{className:"wiz-pair",children:[t.jsx(oe,{label:D.name.label,children:t.jsx("input",{ref:i,placeholder:D.name.placeholder,maxLength:80,value:l,onChange:g=>o(g.target.value),onKeyDown:g=>{g.key==="Enter"&&(g.preventDefault(),x())}})}),h?t.jsx(oe,{label:D.clock.label,hint:D.clock.hint(a1(c)),children:t.jsx("select",{value:c,onChange:g=>d(g.target.value),children:(n.includes(c)?n:[c,...n]).map(g=>t.jsx("option",{value:g,children:g},g))})}):t.jsx(oe,{label:D.clock.label,hint:D.clock.hint(a1(c)),action:t.jsx(E,{size:"lg",onClick:()=>f(!0),children:D.clock.change}),children:t.jsx("input",{value:c,readOnly:!0})})]}),t.jsx("div",{className:"wiz-foot",children:D.hello.foot})]})]})}const Dae={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 Lae(e){const{accounts:n,answers:s,onSettled:r,onKept:a,onReload:i,onBack:l}=e,[o,c]=u.useState(null),[d,h]=u.useState("key"),[f,m]=u.useState(null),[p,x]=u.useState(!1),[g,y]=u.useState(null),[j,v]=u.useState(null),[w,N]=u.useState(null),k=(n==null?void 0:n.anthropicOAuthEnabled)===!0,S=(n==null?void 0:n.codexEnabled)===!0,b=n==null?void 0:n.gemini,[C,$]=u.useState(null);u.useEffect(()=>{let W=!1;const L=()=>{Promise.resolve().then(()=>T.ollama()).then(F=>{!W&&F&&y(F)}).catch(()=>{}),Promise.resolve().then(()=>T.mlxh()).then(F=>{!W&&F&&v(F)}).catch(()=>{W||v({running:!1,baseUrl:"",manager:!1,models:[]})})};L();const Q=window.setInterval(L,4e3);return()=>{W=!0,window.clearInterval(Q)}},[]);const A=async W=>{if(s.assistant??e.existing)try{await T.bindBrain({accountId:W.accountId,model:W.model})}catch(L){return L instanceof fe?L.message:String(L)}return i(),a({...s,brain:W}),C==null||C.close(),$(null),c(null),N(null),null},I=async(W,L,Q)=>{x(!0),m(null);try{const F=await T.saveProviderAccount(W);let ae=await T.testProviderAccount(F.id),V=W.defaultModel,J=!1;if(ae.state!=="connected"&&Q&&Q!==V&&s2(ae)){const X=(await T.providerAccounts()).accounts.find(G=>G.id===F.id);X&&(await T.saveProviderAccount({id:X.id,revision:X.revision,label:X.label,kind:X.kind,auth:X.auth,baseUrl:X.baseUrl,defaultModel:Q,enabled:X.enabled}),ae=await T.testProviderAccount(F.id),ae.state==="connected"&&(V=Q,J=!0))}if(ae.state!=="connected"){try{const X=(await T.providerAccounts()).accounts.find(G=>G.id===F.id);X&&await T.removeProviderAccount(F.id,X.revision)}catch{}return m(ae.message),ae}const H=await A({accountId:F.id,label:L,model:V,...J?{freeTier:J}:{}});return H&&m(H),ae}catch(F){return m(F instanceof fe?F.message:String(F)),null}finally{x(!1)}},M=async W=>{x(!0),m(null);try{const L=await T.saveProviderAccount(W);let Q;try{Q=await T.testProviderAccount(L.id)}finally{try{const F=(await T.providerAccounts()).accounts.find(ae=>ae.id===L.id);F&&await T.removeProviderAccount(L.id,F.revision)}catch{}}return Q.state!=="connected"&&m(Q.message),Q}catch(L){return m(L instanceof fe?L.message:String(L)),null}finally{x(!1)}},O=(W,L,Q)=>{if(W.length<=1){I(L(W[0]??""),Q);return}N({models:W,make:L,label:Q})},R=W=>{if(W===o)return;C==null||C.close(),$(W==="free"&&typeof window.open=="function"?window.open("","_blank"):null),m(null),N(null),h("key"),c(W)},_=()=>{C==null||C.close(),$(null),N(null),m(null),c(null)},z=cO(g,j),U=["free",...k?["claude"]:[],...S?["chatgpt"]:[],"key","local"];let P=null;return w?P=t.jsxs(t.Fragment,{children:[t.jsx(ct,{children:t.jsx(vt,{children:D.brain.model.ask})}),p?t.jsx(gs,{line:D.brain.checking.service}):f?t.jsx(ct,{children:t.jsx(vt,{children:f})}):null,t.jsx(Fae,{busy:p,models:w.models,onBack:_,onUse:W=>void I(w.make(W),w.label)})]}):o==="key"?P=t.jsxs(t.Fragment,{children:[t.jsx(Jt,{label:D.brain.keyKinds.label,value:d,onChange:W=>{m(null),h(W)},options:[{value:"key",label:D.brain.keyKinds.key},...b?[{value:"gemini",label:D.brain.keyKinds.gemini}]:[],{value:"service",label:D.brain.keyKinds.service}]}),d==="gemini"&&b?t.jsx(zae,{busy:p,problem:f,preset:b,onBack:_,onUse:I},"gemini"):d==="service"?t.jsx(Wae,{busy:p,problem:f,address:(g==null?void 0:g.cloudBaseUrl)??"",onBack:_,onOffer:O,onTrial:M,onUse:I},"service"):t.jsx(_ae,{busy:p,problem:f,onBack:_,onUse:I},"key")]}):o==="local"?P=t.jsx(Bae,{busy:p,problem:f,probe:g,mlxh:j,onBack:_,onOffer:O,onUse:I,onCloud:()=>R("free")}):o==="free"?P=t.jsx(Kae,{...e,busy:p,consent:C,onBack:_,onConnected:A}):o==="chatgpt"?P=t.jsx(qae,{...e,busy:p,consent:C,onBack:_,onConnected:A}):o==="claude"&&(P=t.jsx(Qae,{...e,busy:p,problem:f,onBack:_,onConnected:A})),t.jsxs(t.Fragment,{children:[t.jsx(_o,{children:D.brain.title}),t.jsx(ct,{children:t.jsx(vt,{children:D.brain.ask})}),t.jsx("div",{className:"wiz-grid",role:"group","aria-label":D.brain.ask,children:U.map(W=>{const L=Dae[W],Q=D.brain.cards[W];return t.jsxs("button",{type:"button",className:"wiz-opt","aria-pressed":o===W,"data-wide":L.wide?"true":void 0,onClick:()=>R(W),children:[t.jsx("span",{className:"wiz-glyph","data-tone":L.tone,"aria-hidden":"true",children:t.jsx(ie,{name:L.icon})}),t.jsxs("span",{children:[t.jsx("span",{className:"wiz-opt-title",children:Q.title}),t.jsx("span",{className:"wiz-opt-line",children:W==="local"?z:Q.line}),"pill"in Q?t.jsx(Ce,{tone:"good",children:Q.pill}):null]})]},W)})}),P,P===null&&s.brain?t.jsxs(ct,{children:[t.jsx(vt,{children:s.brain.freeTier?D.brain.worksOnFlash(s.brain.model):D.brain.works(s.brain.model)}),t.jsx(Vae,{...e}),s.brain.label===D.brain.ollama.label||s.brain.label===D.brain.mlxh.label?t.jsx(q,{tone:"warm",title:D.brain.ollama.honestTitle,children:D.brain.ollama.honest}):null]}):null,P===null?t.jsx(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Is,{onClick:l}),t.jsx(Fo,{onClick:()=>s.brain&&r(s),disabled:!s.brain,children:D.brain.submit})]})}):null]})}function Fae({busy:e,models:n,onBack:s,onUse:r}){const[a,i]=u.useState(n[0]??"");return t.jsx(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Is,{onClick:s,disabled:e}),t.jsx(E,{variant:"accent",size:"lg",disabled:e||a==="",onClick:()=>r(a),children:D.brain.model.submit})]}),children:t.jsx(oe,{label:D.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 oO({models:e,picked:n,disabled:s,onPick:r}){return t.jsx(oe,{label:D.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 _ae({busy:e,problem:n,onBack:s,onUse:r}){const a=Lo(),[i,l]=u.useState(""),[o,c]=u.useState(null),[d,h]=u.useState(!1),[f,m]=u.useState([]),[p,x]=u.useState(""),[g,y]=u.useState(!1),j=e||d,v=!g&&n!==null&&f.length>0,w=o??Eae(i),N=()=>{const k=i.trim();k===""||j||(h(!0),y(!1),(async()=>{var $;let S=w==="anthropic"?"claude-sonnet-5":"gpt-5",b=f;if(v&&p!=="")S=p;else try{const A=await T.probeModels({kind:w,auth:"api-key",secret:k});S=(($=A.models.find(I=>I.isDefault))==null?void 0:$.id)??S,b=A.models.map(I=>I.id)}catch{b=[]}h(!1);const C=await r({label:w==="anthropic"?D.brain.key.anthropic:D.brain.key.openai,kind:w,auth:"api-key",baseUrl:"",defaultModel:S,enabled:!0,secret:k},w==="anthropic"?D.brain.key.anthropic:D.brain.key.openai);if(!(!C||C.state==="connected")){if(_w(C)){y(!0),m([]);return}m(b.includes(S)||b.length===0?b:[S,...b]),x(S)}})())};return t.jsxs(t.Fragment,{children:[j?t.jsx(ct,{children:t.jsx(gs,{line:D.brain.checking.key})}):g?t.jsx(ct,{children:t.jsx(vt,{children:D.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(Is,{onClick:s,disabled:j}),t.jsx(E,{variant:"accent",size:"lg",disabled:j||i.trim()==="",onClick:N,children:v?D.brain.model.retry:D.brain.key.submit})]}),children:[t.jsx(oe,{label:D.brain.key.field,grow:!0,children:t.jsx("input",{ref:a,type:"password",autoComplete:"off",spellCheck:!1,placeholder:D.brain.key.placeholder,value:i,onChange:k=>{l(k.target.value),m([])},onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),N())}})}),v?t.jsx(oO,{models:f,picked:p,disabled:j,onPick:x}):null,t.jsxs("button",{type:"button",className:"wiz-link",onClick:()=>c(w==="anthropic"?"openai":"anthropic"),children:[w==="anthropic"?D.brain.key.anthropic:D.brain.key.openai," · ",D.brain.key.which]})]})]})}function zae({busy:e,problem:n,preset:s,onBack:r,onUse:a}){const i=Lo(),[l,o]=u.useState(""),[c,d]=u.useState(!1),[h,f]=u.useState([]),[m,p]=u.useState(""),x=e||c,g=n!==null&&h.length>0,y=()=>{const j=l.trim();j===""||x||(d(!0),(async()=>{let v=ZM,w;if(g&&m!=="")v=m;else try{const k=(await T.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,secret:j})).models.map(S=>S.id);v=e2(k)??v,w=n2(v)?t2(k):void 0,f(Mte(k)),p(w??v)}catch{}d(!1),await a({label:D.brain.gemini.label,kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,defaultModel:v,enabled:!0,secret:j},D.brain.gemini.label,w)})())};return t.jsxs(t.Fragment,{children:[x?t.jsx(ct,{children:t.jsx(gs,{line:D.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(Is,{onClick:r,disabled:x}),t.jsx(E,{variant:"accent",size:"lg",disabled:x||l.trim()==="",onClick:y,children:D.brain.gemini.submit})]}),children:[t.jsx(oe,{label:D.brain.gemini.field,grow:!0,children:t.jsx("input",{ref:i,type:"password",autoComplete:"off",spellCheck:!1,placeholder:D.brain.gemini.placeholder,value:l,onChange:j=>o(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),y())}})}),g?t.jsx(oe,{label:D.brain.model.label,grow:!0,children:t.jsx("select",{value:m,disabled:x,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:D.brain.gemini.get})]})]})}function cO(e,n){return e===null||n===null?D.brain.local.looking:!e.running&&!n.running?D.brain.local.missing:D.brain.local.found({...e.running?{ollama:e.models.length}:{},...n.running?{mlxh:n.models.length}:{}})}const Uae=1e3;function i1({command:e}){const[n,s]=u.useState(!1);return u.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?D.brain.ollama.copied:D.brain.ollama.copy})]})}const l1=e=>(e/1e9).toFixed(1);function Bae({busy:e,problem:n,probe:s,mlxh:r,onBack:a,onOffer:i,onUse:l,onCloud:o}){const c=(s==null?void 0:s.models)??[],d=rj(r),h=s==null?void 0:s.machine,[f,m]=u.useState(null),[p,x]=u.useState(null),g=u.useRef(null),y=f??(s==null?void 0:s.pull)??null,j=(y==null?void 0:y.state)==="pulling",v=O=>({label:D.brain.ollama.label,kind:"openai-compatible",auth:"none",baseUrl:(s==null?void 0:s.baseUrl)??"",defaultModel:O,enabled:!0});u.useEffect(()=>{if(!j)return;let O=!1;const R=window.setInterval(()=>{T.ollamaPullState().then(_=>{!O&&_.pull&&m(_.pull)},()=>{})},Uae);return()=>{O=!0,window.clearInterval(R)}},[j]),u.useEffect(()=>{(f==null?void 0:f.state)!=="done"||!s||g.current===f.model||(g.current=f.model,l(v(f.model),D.brain.ollama.label))},[f==null?void 0:f.state,f==null?void 0:f.model,s]);const w=O=>{x(null),g.current=null,T.ollamaPull(O).then(R=>m(R.pull),R=>x(R instanceof fe?R.message:String(R)))},N=()=>{!(r!=null&&r.running)||!d||l({label:D.brain.mlxh.label,kind:"openai-compatible",auth:"none",baseUrl:r.baseUrl,defaultModel:d,enabled:!0},D.brain.mlxh.label)},k=s!==null&&r!==null&&!s.running&&!r.running,S=()=>{s&&i(c,v,D.brain.ollama.label)},b=(h==null?void 0:h.platform)==="darwin"?"this Mac":"this computer",C=(s==null?void 0:s.running)===!0&&c.length===0,$=h!==void 0&&!(r!=null&&r.running)&&(C||k||j),A=h!=null&&h.cloudSuggested?h.memoryGb<7?"memory":"gpu":null,I=h?t.jsxs("div",{className:"wiz-foot",children:[D.brain.ollama.cloud(A,h.memoryGb)," ",t.jsx("button",{type:"button",className:"wiz-link",onClick:o,children:D.brain.ollama.useCloud})]}):null;let M=null;if($&&h){const O=(y==null?void 0:y.state)==="failed"?y:null;if(j&&y){const R=y.total>0?y.completed/y.total:0;M=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:D.brain.ollama.fetching(y.model,l1(y.completed),y.total>0?l1(y.total):"")}),t.jsxs("span",{className:"wiz-busy-side",children:[Math.round(R*100),"%"]})]}),t.jsx(gy,{value:R*100,label:D.brain.ollama.fetch(y.model)}),t.jsx("div",{className:"wiz-foot",children:D.brain.ollama.fetchingFoot})]})}else if(C){const R=(O==null?void 0:O.model)??h.recommended.model;M=t.jsxs("div",{className:"wiz-stack",children:[t.jsx(ct,{children:t.jsx(vt,{children:O?D.brain.ollama.failed(O.error??""):D.brain.ollama.empty(b,h.memoryGb,h.recommended.model,h.recommended.sizeGb)})}),p?t.jsx(q,{tone:"critical",children:p}):null,t.jsxs(se,{children:[t.jsx("span",{className:"wiz-foot",children:D.brain.ollama.emptyFoot(b)}),t.jsx(gt,{}),t.jsx(E,{variant:"accent",size:"lg",disabled:e,onClick:()=>w(R),children:O?D.brain.ollama.again:D.brain.ollama.fetch(R)})]}),I]})}else h.installed?M=t.jsxs("div",{className:"wiz-stack",children:[t.jsx(ct,{children:t.jsx(vt,{children:D.brain.ollama.stopped(h.platform)})}),h.platform==="linux"?t.jsx(i1,{command:"ollama serve"}):null,I]}):M=t.jsxs("div",{className:"wiz-stack",children:[t.jsx(ct,{children:t.jsx(vt,{children:D.brain.ollama.missing(b)})}),h.install.command?t.jsx(i1,{command:h.install.command}):null,t.jsxs(se,{children:[t.jsx("span",{className:"wiz-foot",children:D.brain.ollama.missingHow(h.platform,b)}),t.jsx(gt,{}),h.platform==="linux"?null:t.jsx(st,{size:"lg",href:h.install.url,target:"_blank",rel:"noreferrer",children:D.brain.ollama.download})]}),I]})}return t.jsxs(t.Fragment,{children:[e?t.jsx(ct,{children:t.jsx(gs,{line:D.brain.checking.ollama})}):n?t.jsx(ct,{children:t.jsx(vt,{children:n})}):null,M,t.jsx(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Is,{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:S,children:D.brain.ollama.connect}):null,r!=null&&r.running?t.jsx(E,{variant:"accent",size:"lg",disabled:e||!d,onClick:N,children:D.brain.mlxh.connect}):null,k&&s&&!h?t.jsx(st,{variant:"accent",size:"lg",href:s.downloadUrl,target:"_blank",rel:"noreferrer",children:D.brain.ollama.download}):null]}),children:$?null:t.jsxs("span",{className:"wiz-foot",children:[cO(s,r),r!=null&&r.running&&!d?` ${D.brain.mlxh.noBrain}`:"",k&&(r!=null&&r.baseUrl)?` ${kM(r.baseUrl)}`:""]})})]})}function Wae({busy:e,problem:n,address:s,onBack:r,onOffer:a,onTrial:i,onUse:l}){const o=Lo(),[c,d]=u.useState(s),[h,f]=u.useState(""),[m,p]=u.useState(!1),[x,g]=u.useState([]),[y,j]=u.useState(""),[v,w]=u.useState(!1),N=e||m,k=!v&&n!==null&&x.length>0,S=()=>{c.trim()===""||N||(p(!0),w(!1),(async()=>{var _;const b=h.trim()?"api-key":"none",C=z=>({label:D.brain.service.label,kind:"openai-compatible",auth:b,baseUrl:c.trim(),defaultModel:z,enabled:!0,...h.trim()?{secret:h.trim()}:{}}),$=(z,U,P)=>{if(!(!z||z.state==="connected")){if(_w(z)){w(!0),g([]);return}g(U),j(P)}};if(b==="api-key"&&k&&y!==""){p(!1),$(await l(C(y),D.brain.service.label),x,y);return}let A=[],I;try{const z=await T.probeModels({kind:"openai-compatible",auth:b,baseUrl:c.trim(),...h.trim()?{secret:h.trim()}:{}});A=z.models.map(U=>U.id),I=(_=z.models.find(U=>U.isDefault))==null?void 0:_.id}catch{}p(!1);const M=I?[I]:A;if(b==="none"){a(M,C,D.brain.service.label);return}const O=M[0]??"";if(M.length<=1){$(await l(C(O),D.brain.service.label),A,O);return}const R=await i(C(O));(R==null?void 0:R.state)==="connected"?a(M,C,D.brain.service.label):$(R,A,O)})())};return t.jsxs(t.Fragment,{children:[N?t.jsx(ct,{children:t.jsx(gs,{line:D.brain.checking.service})}):v?t.jsx(ct,{children:t.jsx(vt,{children:D.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(Is,{onClick:r,disabled:N}),t.jsx(E,{variant:"accent",size:"lg",disabled:N||c.trim()==="",onClick:S,children:k?D.brain.model.retry:D.brain.service.submit})]}),children:[t.jsx(oe,{label:D.brain.service.address,grow:!0,children:t.jsx("input",{ref:o,value:c,placeholder:D.brain.service.addressPlaceholder,onChange:b=>{d(b.target.value),g([])}})}),t.jsx(oe,{label:D.brain.service.key,children:t.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,value:h,onChange:b=>{f(b.target.value),g([])}})}),k?t.jsx(oO,{models:x,picked:y,disabled:N,onPick:j}):null]})]})}const Hae=2e3;function Kae({busy:e,consent:n,onBack:s,onConnected:r,accounts:a}){const[i,l]=u.useState(!0),[o,c]=u.useState(null),[d,h]=u.useState(null),[f,m]=u.useState(0),p=u.useRef(-1),x=u.useRef(null),g=D.brain.cloud.label;u.useEffect(()=>{if(p.current===f)return;p.current=f,l(!0),c(null);const j=f===0?n:x.current;(async()=>{try{const v=((a==null?void 0:a.accounts)??[]).find(S=>S.auth==="device-key"),w=v?{id:v.id}:await T.saveProviderAccount({label:g,kind:"openai-compatible",auth:"device-key",baseUrl:"",defaultModel:ah,enabled:!0}),N=(await T.providerAccounts()).accounts.find(S=>S.id===w.id),k=await T.ollamaConnect(N.id,N.revision);h({id:N.id,attemptId:k.attemptId,url:k.verificationUrl}),j&&(j.location.href=k.verificationUrl)}catch(v){j==null||j.close(),c(v instanceof fe?v.message:String(v))}finally{l(!1)}})()},[f]),u.useEffect(()=>{if(!d)return;let j=!1,v=!1;const w=async()=>{if(!(j||v)){v=!0;try{const k=await T.ollamaPoll(d.id,d.attemptId);if(j||k.state==="waiting")return;if(j=!0,h(null),k.state==="failed"){c(k.message);return}l(!0),c(await y(d.id)),l(!1)}catch{}finally{v=!1}}},N=window.setInterval(()=>void w(),Hae);return()=>{j=!0,window.clearInterval(N)}},[d]);const y=async j=>{try{const v=(await T.accountModels(j).catch(()=>({models:[]}))).models.map(S=>S.id),w=v.length===0||v.includes(ah)?ah:v[0],N=(await T.providerAccounts()).accounts.find(S=>S.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 k=await T.testProviderAccount(j);return k.state!=="connected"?k.message:await r({accountId:j,label:g,model:w})}catch(v){return v instanceof fe?v.message:String(v)}};return t.jsxs(t.Fragment,{children:[i||e?t.jsx(ct,{children:t.jsx(gs,{line:D.brain.checking.cloud})}):o?t.jsx(ct,{children:t.jsx(vt,{children:o})}):d?t.jsx(ct,{children:t.jsx(vt,{children:D.brain.cloud.waiting})}):null,t.jsx(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Is,{onClick:s,disabled:i||e}),d?t.jsx(st,{variant:"accent",size:"lg",href:d.url,target:"_blank",rel:"noreferrer",children:D.brain.cloud.open}):o?t.jsx(E,{variant:"accent",size:"lg",disabled:i||e,onClick:()=>{x.current=typeof window.open=="function"?window.open("","_blank"):null,m(j=>j+1)},children:D.brain.cloud.again}):null]})})]})}function Vae({answers:e,accounts:n,onKept:s,onTrouble:r}){var p;const a=e.brain,i=a?((n==null?void 0:n.accounts)??[]).find(x=>x.id===a.accountId):void 0,[l,o]=u.useState([]),[c,d]=u.useState(!1),h=fb(i),f=(i==null?void 0:i.auth)==="device-key"||(i==null?void 0:i.kind)==="codex"||h||!!i&&r2(i,(p=n==null?void 0:n.gemini)==null?void 0:p.baseUrl);if(u.useEffect(()=>{if(!f||!i)return;let x=!1;return T.accountModels(i.id).then(g=>{const y=h?g.models.filter(j=>!bM({id:j.id,...j.image?{kind:"image"}:{}})):g.models;x||o(y.map(j=>j.id))}).catch(()=>{}),()=>{x=!0}},[f,i==null?void 0:i.id]),!f||!i||!a||l.length<2)return null;const m=x=>{x===a.model||c||(d(!0),r(null),(async()=>{try{await T.saveProviderAccount({id:i.id,revision:i.revision,label:i.label,kind:i.kind,auth:i.auth,baseUrl:i.baseUrl,defaultModel:x,enabled:i.enabled}),e.assistant&&await T.bindBrain({accountId:i.id,model:x}),s({...e,brain:{accountId:a.accountId,label:a.label,model:x}})}catch(g){r(g instanceof fe?g.message:String(g))}finally{d(!1)}})())};return t.jsx(vt,{children:t.jsx(oe,{label:D.brain.model.change,children:t.jsx("select",{value:a.model,disabled:c,onChange:x=>m(x.target.value),children:(l.includes(a.model)?l:[a.model,...l]).map(x=>t.jsx("option",{value:x,children:x},x))})})})}const o1="gpt-5.5",Gae=2e3;function qae({busy:e,consent:n,onBack:s,onConnected:r,accounts:a}){const[i,l]=u.useState(!0),[o,c]=u.useState(null),[d,h]=u.useState(null),[f,m]=u.useState(!1),[p,x]=u.useState(void 0),[g,y]=u.useState(0),j=u.useRef(-1),v=u.useRef(null),w=u.useRef(null),N=D.brain.chatgpt.label;u.useEffect(()=>()=>{const b=w.current;w.current=null,b&&T.codexAccountAction(b.id,"cancel-login",b.revision).catch(()=>{})},[]),u.useEffect(()=>{if(j.current===g)return;j.current=g,l(!0),c(null);const b=g===0?n:v.current;(async()=>{try{const C=((a==null?void 0:a.accounts)??[]).find(M=>M.kind==="codex"),$=C?{id:C.id}:await T.saveProviderAccount({label:N,kind:"codex",auth:"chatgpt",baseUrl:"",defaultModel:o1,enabled:!0}),A=(await T.providerAccounts()).accounts.find(M=>M.id===$.id),I=await T.codexAccountAction(A.id,"login",A.revision);if(!(I!=null&&I.verificationUrl)||!I.userCode)throw new Error((I==null?void 0:I.message)??D.brain.chatgpt.failed);w.current={id:A.id,revision:A.revision},h({id:A.id,revision:A.revision,url:I.verificationUrl,code:I.userCode}),m(!!b),b&&(b.location.href=I.verificationUrl)}catch(C){b==null||b.close(),c(C instanceof fe||C instanceof Error?C.message:String(C))}finally{l(!1)}})()},[g]),u.useEffect(()=>{if(!d)return;let b=!1,C=!1;const $=async()=>{if(!(b||C)){C=!0;try{const I=(await T.providerAccounts()).accounts.find(O=>O.id===d.id);if(b)return;const M=I==null?void 0:I.login;if(!M||M.state==="pending")return;if(b=!0,w.current=null,h(null),M.state!=="connected"){c(M.message??D.brain.chatgpt.failed);return}x(M.account??null),l(!0),c(await k(d.id)),l(!1),x(void 0)}catch{}finally{C=!1}}},A=window.setInterval(()=>void $(),Gae);return()=>{b=!0,window.clearInterval(A)}},[d]);const k=async b=>{var C,$;try{const A=(await T.accountModels(b).catch(()=>({models:[]}))).models,I=((C=A.find(O=>O.isDefault))==null?void 0:C.id)??(($=A[0])==null?void 0:$.id)??o1,M=(await T.providerAccounts()).accounts.find(O=>O.id===b);return M&&M.defaultModel!==I&&await T.saveProviderAccount({id:M.id,revision:M.revision,label:M.label,kind:M.kind,auth:M.auth,baseUrl:M.baseUrl,defaultModel:I,enabled:M.enabled}),await r({accountId:b,label:N,model:I})}catch(A){return A instanceof fe?A.message:String(A)}},S=()=>{const b=w.current;w.current=null,b&&T.codexAccountAction(b.id,"cancel-login",b.revision).catch(()=>{}),s()};return t.jsxs(t.Fragment,{children:[p!==void 0?t.jsxs(ct,{children:[t.jsx(vt,{children:D.brain.chatgpt.signedIn(p)}),t.jsx(gs,{line:D.brain.checking.chatgpt})]}):i||e?t.jsx(ct,{children:t.jsx(gs,{line:D.brain.checking.chatgpt})}):o?t.jsx(ct,{children:t.jsx(vt,{children:o})}):d?t.jsx(ct,{children:f?t.jsx(gs,{line:D.brain.chatgpt.waiting}):t.jsx(vt,{children:D.brain.chatgpt.instruct})}):null,t.jsx(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Is,{onClick:S,disabled:i||e}),d?t.jsx(st,{variant:"accent",size:"lg",href:d.url,target:"_blank",rel:"noreferrer",onClick:()=>m(!0),children:D.brain.chatgpt.open}):o?t.jsx(E,{variant:"accent",size:"lg",disabled:i||e,onClick:()=>{v.current=typeof window.open=="function"?window.open("","_blank"):null,y(b=>b+1)},children:D.brain.chatgpt.again}):null]}),children:d?t.jsx(pb,{code:d.code,label:D.brain.chatgpt.code,large:!0}):null})]})}const Yae="claude-sonnet-5";function Qae({busy:e,problem:n,onBack:s,onConnected:r,accounts:a,claudeModel:i}){const[l,o]=u.useState(!1),[c,d]=u.useState(null),[h,f]=u.useState(null),[m,p]=u.useState(""),x=u.useRef(null);u.useEffect(()=>()=>{const w=x.current;x.current=null,w&&T.anthropicAccountAction(w.id,"cancel-login",w.revision).catch(()=>{})},[]);const g=()=>{const w=x.current;x.current=null,w&&T.anthropicAccountAction(w.id,"cancel-login",w.revision).catch(()=>{}),s()},y=i??Yae,j=()=>{o(!0),d(null);const w=typeof window.open=="function"?window.open("","_blank"):null;(async()=>{try{const N=((a==null?void 0:a.accounts)??[]).find($=>$.auth==="anthropic-oauth"),k=N?{id:N.id}:await T.saveProviderAccount({label:D.brain.claude.label,kind:"anthropic",auth:"anthropic-oauth",baseUrl:"",defaultModel:y,enabled:!0}),b=(await T.providerAccounts()).accounts.find($=>$.id===k.id),C=await T.anthropicAccountAction(b.id,"login",b.revision);x.current={id:b.id,revision:b.revision+1},f({id:b.id,revision:b.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(),d(N instanceof fe?N.message:String(N))}finally{o(!1)}})()},v=()=>{!h||m.trim()===""||(x.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"){d(w.message);return}d(await r({accountId:h.id,label:D.brain.claude.label,model:y}))}catch(w){d(w instanceof fe?w.message:String(w))}finally{o(!1)}})())};return t.jsxs(t.Fragment,{children:[l||e?t.jsx(ct,{children:t.jsx(gs,{line:D.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:D.brain.claude.waiting})}),t.jsx(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Is,{onClick:g,disabled:l}),t.jsx(st,{size:"lg",href:h.url,target:"_blank",rel:"noreferrer",children:D.brain.claude.open}),t.jsx(E,{variant:"accent",size:"lg",disabled:l||m.trim()==="",onClick:v,children:D.brain.claude.finish})]}),children:t.jsx(oe,{label:D.brain.claude.paste,grow:!0,children:t.jsx(Jae,{value:m,onChange:p})})})]}):t.jsx(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Is,{onClick:g,disabled:e||l}),t.jsx(E,{variant:"accent",size:"lg",disabled:e||l,onClick:j,children:D.brain.claude.start})]})})]})}function Jae({value:e,onChange:n}){const s=Lo();return t.jsx("input",{ref:s,type:"password",autoComplete:"off",spellCheck:!1,value:e,onChange:r=>n(r.target.value)})}const Xae={days:"calendar",mail:"mail",money:"money",voice:"bulb",code:"monitor",pictures:"files"};function Zae(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:D.takeOn.fetching(s,Math.min(a+1,n.length),n.length),done:!1}}return r.length>0?{line:r.map(a=>D.takeOn.failed(a.title,a.reason??"")).join(" "),done:!0}:{line:D.takeOn.ready(s),done:!0}}function eie({answers:e,progress:n,offers:s,onProgress:r,onSettled:a,onBack:i,onTrouble:l}){const o=s?Zh.filter(y=>s.includes(y.id)):Zh,[c,d]=u.useState(()=>e.takeOn??[...GB]),[h,f]=u.useState(!1),m=o.filter(y=>c.includes(y.id)),p=y=>d(j=>j.includes(y)?j.filter(v=>v!==y):[...j,y]),x=y=>{h||(f(!0),Promise.resolve().then(()=>T.takeOn(y)).then(()=>{r(),a({...e,takeOn:y})}).catch(j=>l(j instanceof fe?j.message:String(j))).finally(()=>f(!1)))},g=Zae(n);return t.jsxs(t.Fragment,{children:[t.jsx(_o,{children:D.takeOn.title}),t.jsx(ct,{children:t.jsx(vt,{children:D.takeOn.ask})}),t.jsxs(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Is,{onClick:i,disabled:h}),t.jsx(E,{variant:"ghost",size:"lg",disabled:h,onClick:()=>x([]),children:D.takeOn.none}),t.jsx(Fo,{onClick:()=>x(m.map(y=>y.id)),disabled:h||m.length===0,children:D.takeOn.submit})]}),children:[t.jsx("div",{className:"wiz-grid","data-cols":"3",role:"group","aria-label":D.takeOn.title,children:o.map(y=>{const j=c.includes(y.id);return t.jsxs("button",{type:"button",className:"wiz-opt","data-tile":"true","aria-pressed":j,onClick:()=>p(y.id),children:[t.jsxs("span",{className:"wiz-tile-top",children:[t.jsx("span",{className:"wiz-glyph","aria-hidden":"true",children:t.jsx(ie,{name:Xae[y.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:y.title}),t.jsx("span",{className:"wiz-opt-plugins",children:y.plugins})]}),t.jsx("span",{className:"wiz-opt-line",children:y.line})]},y.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:D.takeOn.builtIn}):null]}):null,t.jsx("div",{className:"wiz-foot",children:m.map(y=>y.note).join(" ")})]}):t.jsx("div",{className:"wiz-foot",children:D.takeOn.nothing})]})]})}function tie({answers:e,progress:n,onSettled:s,onBack:r}){var g,y,j;const[a,i]=u.useState(((g=e.reach)==null?void 0:g.phone)===!0),[l,o]=u.useState(((y=e.reach)==null?void 0:y.mailbox)===!0),[c,d]=u.useState(((j=e.reach)==null?void 0:j.app)===!0),[h,f]=u.useState(e.browser),m=e.takeOn??[],p=m.includes("mail"),x=()=>{const v={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:v,...h!==void 0?{browser:h}:{}})};return t.jsxs(t.Fragment,{children:[t.jsx(_o,{children:D.reach.title}),t.jsx(ct,{children:t.jsx(vt,{children:D.reach.ask})}),t.jsx(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Is,{onClick:r}),t.jsx(Fo,{onClick:x,children:D.reach.submit})]}),children:t.jsxs("div",{className:"wiz-rows",children:[t.jsx(nie,{paired:a,owner:e.name,onPaired:()=>i(!0)}),t.jsx(sie,{wanted:p,added:l,onAdded:o}),m.includes("days")?t.jsx(rie,{progress:n}):null,m.includes("money")?t.jsx(iie,{}):null,t.jsx(lie,{app:c,onApp:()=>d(!0),browser:h,onBrowser:f}),a?t.jsx(q,{tone:"good",role:"status",children:D.reach.phone.hello}):null]})})]})}function nie({paired:e,owner:n,onPaired:s}){const[r,a]=u.useState(null),[i,l]=u.useState(!1),o=u.useRef(s);o.current=s,u.useEffect(()=>{let d=!1;return Promise.resolve().then(()=>T.telegram()).then(h=>{d||!h||(a(h),h.paired&&o.current())}).catch(()=>{d||a({configured:!1,running:!1,paired:!1})}),()=>{d=!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:D.reach.phone.title}),t.jsx("span",{className:"wiz-opt-line",children:D.reach.phone.line})]}),t.jsx("span",{className:"wiz-row-side",children:e?t.jsx(Ce,{tone:"good",dot:!0,children:D.reach.phone.paired}):t.jsx(E,{size:"lg",disabled:r===null,onClick:()=>l(!0),children:c?D.reach.phone.pair:D.reach.phone.setUp})}),i?t.jsx(Je,{title:D.telegram.sheet,onClose:()=>l(!1),children:t.jsx(fie,{ready:c,owner:n,onPaired:s,onDismiss:()=>l(!1)})}):null]})}function sie({wanted:e,added:n,onAdded:s}){const r=dO("email"),[a,i]=u.useState(!1),[l,o]=u.useState(null);return u.useEffect(()=>{Promise.resolve().then(()=>T.pageQuery("email","accounts")).then(c=>{var h,f,m;const d=((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(d),s(d!==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?D.reach.mailbox.forTriage:D.reach.mailbox.title}),t.jsx("span",{className:"wiz-opt-line",children:r===!1?D.reach.mailbox.unavailable:D.reach.mailbox.line})]}),t.jsx("span",{className:"wiz-row-side",children:n||l?t.jsx(Ce,{tone:"good",dot:!0,mono:l!==null,children:l??D.reach.mailbox.added}):r?t.jsx(E,{size:"lg",onClick:()=>i(!0),children:D.reach.mailbox.add}):null}),a?t.jsx(gae,{onClose:()=>i(!1),onAdded:c=>{o(c),s(!0)}}):null]})}function dO(e,n){const[s,r]=u.useState(void 0),a=(n==null?void 0:n.plugins.map(i=>`${i.title}:${i.state}`).join(","))??"";return u.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 rie({progress:e}){const n=dO("calendar",e),[s,r]=u.useState(!1),[a,i]=u.useState(null),[l,o]=u.useState(!1),[c,d]=u.useState(0);u.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,x])=>{m||i(aie(p,x))}).catch(()=>{}),()=>{m=!0}},[n,c,s]),u.useEffect(()=>{if((a==null?void 0:a.kind)!=="waiting")return;const m=window.setTimeout(()=>d(p=>p+1),tO);return()=>window.clearTimeout(m)},[a,c]);const h=a??(l?{kind:"linked",tone:"good",label:D.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:D.reach.calendar.title}),t.jsx("span",{className:"wiz-opt-line",children:n===!1?D.reach.calendar.waiting:D.reach.calendar.line})]}),t.jsxs("span",{className:"wiz-row-side",children:[h!==null?t.jsx(Ce,{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:D.reach.calendar.add})]}),s?t.jsx(jae,{onClose:()=>r(!1),onLinked:()=>{o(!0),d(m=>m+1)}}):null]})}function aie(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:D.reach.calendar.googleWaiting}:a.length>0?{kind:"google",tone:"good",label:D.reach.calendar.google(a.map(l=>l.username??"").filter(Boolean).join(", ")||"signed in")}:r.length>0?{kind:"expired",tone:"warning",label:D.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:D.reach.calendar.linked}:null}function iie(){const[e,n]=u.useState(!1),[s,r]=u.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:D.reach.bank.title}),t.jsx("span",{className:"wiz-opt-line",children:D.reach.bank.line})]}),t.jsx("span",{className:"wiz-row-side",children:s?t.jsx(Ce,{dot:!0,children:D.reach.bank.later}):t.jsx(E,{size:"lg",onClick:()=>n(!0),children:D.reach.bank.add})}),e?t.jsx(wae,{onClose:()=>n(!1),onUnderstood:()=>r(!0)}):null]})}function lie({app:e,onApp:n,browser:s,onBrowser:r}){const a=cb(),i=Om(),l=a?null:i,o=typeof navigator>"u"?null:PP(navigator.userAgent),[c,d]=u.useState(null),[h,f]=u.useState("idle"),[m,p]=u.useState(null),[x,g]=u.useState(null),[y,j]=u.useState(void 0),v=u.useRef(!1),w=u.useRef(!0);u.useEffect(()=>(w.current=!0,Promise.resolve().then(()=>T.browser()).then(A=>{var M;if(!w.current)return;const I=A==null?void 0:A.browser;I?((M=I.install)==null?void 0:M.state)==="running"?(d("none"),v.current=!0,f("installing"),S()):d(I.engine):d("other")}).catch(()=>{w.current&&d("other")}),()=>{w.current=!1}),[]);const N=(A,I)=>{w.current&&(v.current=!1,f("failed"),p(A),g(I??null))},k=async A=>{f("launching");let I;try{I=await T.browserCheck()}catch(M){return N(M instanceof fe?M.message:String(M))}if(w.current){if(I.ok){f("idle"),d(A),r(v.current?"installed":A);return}N(I.message,I.command)}},S=async()=>{var M,O;let A;try{A=await T.browser()}catch(R){return N(R instanceof fe?R.message:String(R))}if(!w.current)return;const I=A.browser;if(!I)return N(D.browser.failed(""));if(((M=I.install)==null?void 0:M.state)==="running"){f("installing"),j(I.install.progress),window.setTimeout(()=>void S(),1e3);return}return I.engine!=="none"?k(I.engine):N(((O=I.install)==null?void 0:O.line)??"")},b=()=>{if(g(null),c==="chrome"||c==="chromium"){k(c);return}v.current=!0,f("installing"),j(void 0),Promise.resolve().then(()=>T.browserInstall()).then(()=>{w.current&&window.setTimeout(()=>void S(),1e3)}).catch(A=>N(A instanceof fe?A.message:String(A)))},C=s==="chrome"||s==="chromium"||s==="installed",$=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?D.reach.app.inApp.title:D.reach.app.title}),t.jsx("span",{className:"wiz-opt-line",children:a?D.reach.app.inApp.line:D.reach.app.line})]}),t.jsxs("span",{className:"wiz-row-side",children:[a?t.jsx(st,{size:"lg",href:fR,target:"_blank",rel:"noreferrer",children:D.reach.app.inApp.extension}):e?t.jsx(Ce,{tone:"good",dot:!0,children:D.reach.app.installed}):l?t.jsx(E,{size:"lg",onClick:()=>{l.prompt().then(()=>l.userChoice).then(A=>{(!A||A.outcome==="accepted")&&n()}).catch(()=>{})},children:D.reach.app.install}):null,C?t.jsx(Ce,{tone:"good",dot:!0,children:D.reach.app.ready(s==="chrome"?"chrome":"chromium")}):c===null||c==="other"?null:t.jsx(E,{size:"lg",disabled:$,onClick:b,children:$?D.browser.installing:h==="failed"?D.browser.retry:c==="chrome"?D.reach.app.chrome:c==="chromium"?D.reach.app.chromium:D.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:D.browser.needs}),t.jsx(bae,{progress:y})]}):h==="launching"?t.jsx("div",{className:"wiz-row-more",children:t.jsx(gs,{line:D.browser.launching})}):h==="failed"?t.jsxs("div",{className:"wiz-row-more",children:[t.jsx("span",{className:"wiz-opt-line",children:D.browser.failed(m??"")}),x?t.jsx(die,{command:x}):null]}):null]})}function oie({answers:e,existing:n,navigate:s,onSettled:r,onTrouble:a,onReload:i,onBack:l}){const[o,c]=u.useState(()=>(n==null?void 0:n.name)??zB),[d,h]=u.useState(()=>n!=null&&n.picture||n!=null&&n.avatar?null:"buddi"),[f,m]=u.useState(n?null:D.assistant.purposeValue),[p,x]=u.useState(n?"":D.assistant.purposeValue);u.useEffect(()=>{if(!n)return;let S=!1;return T.firstAgentPersona().then(b=>{S||(m(b.persona),x(b.persona))},b=>{S||a(b instanceof fe?b.message:String(b))}),()=>{S=!0}},[n==null?void 0:n.id]);const[g,y]=u.useState(!1),[j,v]=u.useState(null),w=Zh.filter(S=>(e.takeOn??[]).includes(S.id)&&"mate"in S).map(S=>S.mate),N=mN.find(S=>S.id===d),k=()=>{if(o.trim()===""||g)return;y(!0);const S=!n||f!==null&&p.trim()!==""&&p.trim()!==f.trim()?{instructions:p.trim()}:{},b=n?T.updateFirstAgent({name:o.trim(),...S}):T.createFirstAgent({name:o.trim(),handle:Aae(o),description:"",...S,...e.brain?{accountId:e.brain.accountId}:{}});(async()=>{var A;let C;try{C=await b}catch(I){I instanceof fe&&I.status===409&&((A=I.detail)==null?void 0:A.code)==="assistant-exists"?(v(I.message),a(null)):a(I instanceof fe?I.message:String(I)),y(!1);return}let $=null;try{N&&await T.uploadAgentPicture(C.id,await OM(N.role))}catch(I){$=I instanceof fe?I.message:String(I)}y(!1),i(),r({...e,assistant:{id:C.id,name:o.trim(),avatar:N?"":(n==null?void 0:n.avatar)??""}}),$&&a($)})()};return t.jsxs(t.Fragment,{children:[t.jsx(_o,{children:D.assistant.title}),t.jsx(ct,{children:t.jsxs(vt,{children:[D.assistant.ask,w.length>0?D.assistant.team(w):""]})}),t.jsxs(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Is,{onClick:l,disabled:g}),t.jsx(Fo,{onClick:k,disabled:g||j!==null||o.trim()===""||f===null,children:D.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:gi(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":D.assistant.colour,children:mN.map(S=>t.jsx("button",{type:"button",className:"wiz-swatch","data-agent":S.id,"aria-label":D.assistant.swatch(S.label),"aria-pressed":d===S.id,onClick:()=>h(S.id)},S.id))}),t.jsx("span",{className:"wiz-face-cap",children:D.assistant.colour})]}),t.jsxs("div",{className:"wiz-stack",children:[t.jsx(oe,{label:D.assistant.name,children:t.jsx("input",{value:o,maxLength:60,onChange:S=>c(S.target.value)})}),t.jsx(oe,{label:D.assistant.purpose,hint:D.assistant.purposeHint,children:t.jsx("textarea",{className:"wiz-persona",value:p,maxLength:8e3,rows:7,onChange:S=>x(S.target.value)})})]})]}),j?t.jsx(q,{tone:"warm",role:"status",title:D.assistant.refusedTitle,action:t.jsx(st,{href:yt,onClick:S=>{S.preventDefault(),s(yt)},children:D.assistant.toAgents}),children:j}):null]})]})}function cie({answers:e,assistantAgent:n,met:s,onMet:r,navigate:a,onPickAnotherBrain:i,onSpoken:l,progress:o,onProgress:c}){var z,U;const d=e.assistant,[h,f]=u.useState(s),[m,p]=u.useState([]),[x,g]=u.useState(!1),[y,j]=u.useState(!1),[v,w]=u.useState(!0),[N,k]=u.useState(!1),S=u.useRef(!1),b=u.useMemo(()=>n?[n]:[],[n]);u.useEffect(()=>{c()},[]),u.useEffect(()=>{if(!d||S.current)return;if(S.current=!0,s){f(s);return}let P=!1;return(async()=>{try{const W=await Xe.startConversation(d.id);if(P)return;f(W.conversationId),r(W.conversationId),await T.onboardingStep(nO.handover,{conversationId:W.conversationId}).catch(()=>{}),await Xe.send(d.id,{conversationId:W.conversationId,text:HB,opening:!0})}catch{P||(w(!1),g(!0))}})(),()=>{P=!0}},[d==null?void 0:d.id,s]),u.useEffect(()=>{if(!h)return;let P=!1;const W=Date.now(),L=()=>{Xe.conversation(h).then(F=>{if(P)return;p(F.messages);const ae=Date.now()-W;if(F.messages.some(c1)){w(!1),g(!1),j(!1);return}const V=F.runs??[],J=V.some(X=>X.finishedAt===null),H=V.length>0&&!J;j(J&&ae>=$ae),(H||ae>=Tae)&&(w(!1),g(!0))}).catch(()=>{})};L();const Q=window.setInterval(L,lO);return()=>{P=!0,window.clearInterval(Q)}},[h]);const C=d&&h?lt(d.id,h):null,$=m.some(c1);u.useEffect(()=>{$&&C&&l(C)},[$,C,l]);const A=o!=null&&o.tiles&&o.tiles.length>0?o.tiles:e.takeOn??[],I=D.handover.starters({days:A.includes("days"),mail:A.includes("mail"),mailbox:((z=e.reach)==null?void 0:z.mailbox)===!0}),M={days:A.includes("days"),mailbox:((U=e.reach)==null?void 0:U.mailbox)===!0,mail:A.includes("mail"),money:A.includes("money"),pictures:A.includes("pictures")},O=(o==null?void 0:o.waiting)??[],R=P=>{oy(),a(P,!0)},_=P=>{!d||!h||N||(k(!0),Promise.resolve().then(()=>Xe.send(d.id,{conversationId:h,text:P})).then(()=>R(lt(d.id,h))).catch(()=>k(!1)))};return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"wiz-hello",children:t.jsx($y,{messages:m,live:[],now:Date.now(),onOpen:()=>{},working:v,agents:b,agentName:(d==null?void 0:d.name)??"",...d?{agentId:d.id}:{},emptyHint:D.handover.waiting,plain:!0,workingLine:D.handover.looking((d==null?void 0:d.name)??"")})}),y&&!x?t.jsx(ct,{children:t.jsx(vt,{children:D.handover.slow})}):null,x?t.jsxs(t.Fragment,{children:[t.jsx(ct,{children:t.jsx(vt,{children:D.handover.silent})}),t.jsx(bn,{actions:t.jsx(Fo,{onClick:i,children:D.handover.again})})]}):null,$?t.jsx("div",{className:"wiz-starters",role:"group","aria-label":D.handover.starterLabel,children:I.map(P=>t.jsx("button",{type:"button",className:"wiz-starter",disabled:N,onClick:()=>_(P),children:P},P))}):null,$?t.jsx(cq,{setUp:M,navigate:R}):null,$?t.jsx(HM,{plugins:(o==null?void 0:o.plugins)??[]}):null,$&&O.length>0?t.jsx(q,{tone:"warm",title:D.handover.waitingTitle(O.length),action:t.jsx(E,{variant:"accent",onClick:()=>R(In),children:D.handover.home}),children:D.handover.waitingBody(O)}):null,$&&C?t.jsx(bn,{actions:t.jsx(st,{variant:"accent",size:"lg",href:C,onClick:P=>{P.preventDefault(),R(C)},children:D.done.open})}):null]})}function die({command:e}){const[n,s]=u.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(de,{gap:"sm",children:[t.jsx(_t,{label:"The command to run",children:e}),t.jsxs(se,{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 c1(e){return e.role==="assistant"&&(e.blocks??[]).some(n=>n.type==="text"&&n.text.trim()!=="")}function uie({onCancel:e,onStarted:n,onTrouble:s}){const[r,a]=u.useState(null),[i,l]=u.useState(""),[o,c]=u.useState(!1),d=()=>{!r||o||(c(!0),s(null),T.firstRunRestore(r,i.trim()).then(h=>{kj(h.job.id),n()}).catch(h=>s(h instanceof fe?h.message:String(h))).finally(()=>c(!1)))};return t.jsx(Je,{title:D.restore.sheet,onClose:e,children:t.jsxs("div",{className:"wiz-restore",children:[t.jsx("p",{className:"wiz-foot",children:D.restore.lede}),t.jsx(oe,{label:D.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:D.restore.passphrase,hint:D.restore.passphraseHint,children:t.jsx("input",{type:"password",autoComplete:"off",value:i,onChange:h=>l(h.target.value)})}),t.jsxs(se,{align:"end",children:[t.jsx(E,{variant:"ghost",onClick:e,children:D.restore.cancel}),t.jsx(E,{variant:"accent",disabled:o||!r,onClick:d,children:D.restore.submit})]})]})})}function hie({onDone:e,onFailed:n}){const[s,r]=u.useState([]),a=u.useRef({onDone:e,onFailed:n});a.current={onDone:e,onFailed:n},u.useEffect(()=>{const l=iO();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,kj(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,kj(null),a.current.onFailed(h.error??D.restore.phases[h.phase])))}).catch(()=>{})};c();const d=window.setInterval(c,lO);return()=>{o=!0,window.clearInterval(d)}},[]);const i=s.filter(l=>l in D.restore.phases);return t.jsxs(t.Fragment,{children:[t.jsx(_o,{children:D.restore.title}),t.jsxs(ct,{children:[t.jsx(vt,{children:D.restore.started}),i.map(l=>t.jsx(vt,{children:D.restore.phases[l]},l))]}),t.jsx(gs,{})]})}function fie(e){return t.jsx(Mb.Provider,{value:null,children:t.jsx("div",{className:"wiz-sheet-body",children:t.jsx(pie,{...e})})})}const mie=1600;function pie({ready:e,owner:n,onPaired:s,onDismiss:r}){const a=Lo(),[i,l]=u.useState(""),[o,c]=u.useState(!1),[d,h]=u.useState(null),[f,m]=u.useState(null),{offer:p,square:x,paired:g,stale:y,ask:j}=Y2(()=>T.telegram().then(S=>S.paired),s),v=u.useRef(!1);u.useEffect(()=>{!e||v.current||(v.current=!0,Promise.resolve().then(()=>T.telegramBot()).then(S=>m((S==null?void 0:S.username)??null)).catch(()=>{}),j().catch(S=>h(S instanceof fe?S.message:String(S))))},[e,j]);const w=u.useRef(r);w.current=r,u.useEffect(()=>{if(!g)return;const S=window.setTimeout(()=>w.current(),mie);return()=>window.clearTimeout(S)},[g]);const N=()=>{i.trim()===""||o||(c(!0),h(null),(async()=>{try{const S=await T.saveTelegramToken(i.trim());if(l(""),m(S.botUsername??null),S.restartNeeded){h(S.note??D.telegram.restart);return}await j()}catch(S){h(S instanceof fe?S.message:String(S))}finally{c(!1)}})())},k=()=>{h(null),j().catch(S=>h(S instanceof fe?S.message:String(S)))};return p?t.jsxs(t.Fragment,{children:[t.jsx(ct,{children:t.jsx(vt,{children:y&&!g?D.telegram.expired:D.telegram.scan})}),t.jsx(bn,{actions:g?t.jsx(E,{variant:"accent",onClick:r,children:D.telegram.close}):t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:r,children:D.telegram.notNow}),y?t.jsx(E,{variant:"accent",onClick:k,children:D.telegram.newCode}):null]}),children:y&&!g?null:t.jsx(yre,{offer:p,square:x,bot:f,paired:g,status:g?D.telegram.pairedWith(n):D.telegram.waiting})})]}):e&&!d?t.jsx(ct,{children:t.jsx(gs,{line:D.telegram.making})}):e?t.jsxs(t.Fragment,{children:[t.jsx(ct,{children:t.jsx(vt,{children:d})}),t.jsx(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:r,children:D.telegram.notNow}),t.jsx(E,{variant:"accent",onClick:k,children:D.telegram.newCode})]})})]}):t.jsxs(t.Fragment,{children:[t.jsxs(ct,{children:[t.jsx(vt,{children:D.telegram.how}),d?t.jsx(vt,{children:d}):null]}),t.jsx(bn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(E,{variant:"ghost",onClick:r,children:D.telegram.notNow}),t.jsx(E,{variant:"accent",disabled:o||i.trim()==="",onClick:N,children:D.telegram.submit})]}),children:t.jsx(oe,{label:D.telegram.field,grow:!0,children:t.jsx("input",{ref:a,type:"password",value:i,autoComplete:"off",spellCheck:!1,onChange:S=>l(S.target.value),onKeyDown:S=>{S.key==="Enter"&&(S.preventDefault(),N())}})})})]})}const Ig={recovery:0,lost:1,paused:2},gie="Lost buddi. Retrying…",xie="The queue is paused. Nothing is being claimed until you resume it.";function vie(e){const n=[];return e.recovery&&n.push({id:"recovery",priority:Ig.recovery,tone:"warning",text:zM,action:{label:"Finish the checklist",href:sv}}),e.lost&&n.push({id:"lost",priority:Ig.lost,tone:"critical",text:gie}),e.paused&&n.push({id:"paused",priority:Ig.paused,tone:"warning",text:xie,action:{label:"Resume",onClick:()=>{T.setPaused(!1).catch(()=>{})}}}),n}function jie({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(st,{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 uO=1e4,wie=3e4,hO=6e3,Ob=/^(localhost|127(?:\.\d{1,3}){3}|\[?::1\]?)$|\.localhost$/i;function yie(e){return Ob.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 fO(e){let n;const s=new Promise((r,a)=>{n=setTimeout(()=>a(new fe(0,Vh)),e)});try{return{up:!0,version:await Promise.race([T.version(),s])}}catch(r){return Gh(r)?{up:!1}:{up:!0}}finally{clearTimeout(n)}}function mO(e){var n;return e.up&&ay((n=e.version)==null?void 0:n.web)?(window.location.reload(),!1):e.up}function bie({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:gi("core"),alt:""})}),t.jsxs("h1",{children:["buddi isn't answering at ",e,"."]}),t.jsx("p",{children:yie(e.replace(/:\d+$/,""))}),t.jsx("div",{className:"unreachable-actions",children:t.jsx(E,{variant:"accent",onClick:n,disabled:s,children:s?"Retrying…":"Retry"})})]})}function kie({children:e}){const[n,s]=u.useState("checking"),[r,a]=u.useState(!1),i=u.useRef(!1),l=u.useCallback(async()=>{if(i.current)return;i.current=!0,a(!0);const o=await fO(hO);i.current=!1,a(!1),s(c=>c==="checking"?o.up?"up":"down":mO(o)?"up":"down")},[]);return u.useEffect(()=>{l()},[l]),u.useEffect(()=>{if(n!=="down")return;const o=window.setInterval(()=>void l(),uO);return()=>window.clearInterval(o)},[n,l]),n==="checking"?null:n==="down"?t.jsx(bie,{host:window.location.host,onRetry:()=>void l(),retrying:r}):t.jsx(t.Fragment,{children:e})}function Nie(e=wie){const[n,s]=u.useState(!1);return u.useEffect(()=>{let r;const a=()=>{clearTimeout(r);const l=id();if(l===null)return s(!1);const o=l+e-Date.now();o<=0?s(!0):r=setTimeout(a,o)};a();const i=Lw(a);return()=>{i(),clearTimeout(r)}},[e]),n}function Sie(){const e=Nie();return u.useEffect(()=>{if(!e)return;const n=window.setInterval(()=>{fO(hO).then(mO)},uO);return()=>window.clearInterval(n)},[e]),e}const Cie={local:"Local",tailnet:"Tailnet",reconnecting:"Reconnecting…"},d1=(e,n,s=`${n}s`)=>e===1?n:s;function Eie(){return Intl.DateTimeFormat().resolvedOptions().timeZone}function Aie(e){return e.includes("/")?e.split("/").pop().replace(/_/g," "):e}function $ie(e,n){return n?"reconnecting":Ob.test(e)?"local":"tailnet"}function pO(e,n,s=Eie()){const r=[],a=Cie[e.link];if(r.push({key:"link",route:ze("system"),dot:e.link==="reconnecting"?"warning":"good",text:a,label:`Connection: ${a}`}),e.focus){const d=`${Oi[e.focus.mode]} ${wd(e.focus,e.timezone,n)}`;r.push({key:"focus",route:ze("notifications"),icon:"moon",text:d,label:`Focus: ${d}`})}const i=[];if(e.working>0&&i.push({key:"working",dot:"working",text:`${e.working} ${d1(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?`${Yt}/jobs?state=failed`:`${Yt}/jobs`,parts:i,label:`Work: ${i.map(d=>d.text).join(", ")}`}),e.approvals>0){const d=`${d1(e.approvals,"approval")} waiting`;r.push({key:"approvals",route:ao,count:e.approvals,text:d,label:`${e.approvals} ${d}`})}if(e.version){const d=e.version.updateAvailable&&e.version.latest?e.version.latest:null;r.push({key:"version",route:ze("system"),end:!0,mono:`buddi ${e.version.current}`,update:d!==null,label:`buddi ${e.version.current}${d?`, a newer buddi is ready: ${d}`:""}`})}const l=e.timezone||s,o=$t(n,l),c=l!==s;return r.push({key:"time",route:ze("you"),end:!0,time:o,...c?{zone:Aie(l)}:{},label:`Your time: ${o}${c?`, ${l}`:""}`}),r}function Tie(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 gO(){const[e,n]=u.useState(()=>new Date);return u.useEffect(()=>{let s;const r=()=>{s=setTimeout(()=>{n(new Date),r()},6e4-Date.now()%6e4)};return r(),()=>clearTimeout(s)},[]),e}function Iie(){const[e,n]=u.useState(()=>id()!==null);return u.useEffect(()=>Lw(()=>n(id()!==null)),[]),e}function xO({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(u.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 Rie({status:e,onNavigate:n}){const s=gO(),r=Fm(),a=pO(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(xO,{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 Pie({status:e,onNavigate:n}){const s=gO(),r=Fm(),a=Tie(e);return t.jsx("div",{className:"rail-status",children:t.jsxs(Dd,{modal:!1,children:[t.jsx(Ld,{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($o,{children:t.jsxs(Fd,{className:"ui-menu rail-status-menu",side:"right",align:"end",sideOffset:10,children:[t.jsx(Yi,{className:"ui-menu-label",children:"Status"}),pO(e,s).map(i=>t.jsx(Vs,{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(xO,{item:i})})})},i.key)),r.pin?t.jsxs(t.Fragment,{children:[t.jsx(da,{className:"ui-menu-sep"}),t.jsx(Vs,{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 Mie=1e4;function vO(){return u.useSyncExternalStore(fB,oN,oN)}function Oie(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 u1(e){const n=Math.max(0,Math.floor(e/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function Die({command:e}){const[n,s]=u.useState(!1);return u.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 Lie({state:e,elapsedMs:n,hostname:s=window.location.hostname,onReload:r=()=>Gl.reload()}){const a=Oie(e),i=e.kind==="stop",l=!i&&n>=(e.patienceMs??oB),o=Ob.test(s),c=u.useRef(null);u.useEffect(()=>{var h;return(h=c.current)==null?void 0:h.focus()},[]);const d=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(Bd,{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:d}),t.jsx(Die,{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?`${u1(n)} · still checking every few seconds`:n>=Mie?`${u1(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 Fie(e){const[n,s]=u.useState(()=>Gl.now());return u.useEffect(()=>{if(!e)return;s(Gl.now());const r=window.setInterval(()=>s(Gl.now()),1e3);return()=>window.clearInterval(r)},[e]),e?Math.max(0,n-e.startedAt):0}function _ie({children:e}){const n=vO(),s=Fie(n),r=u.useRef(null);return u.useEffect(()=>{pB();let a=id()!==null;const i=Lw(()=>{const o=id()!==null;a&&!o&&cN(),a=o}),l=()=>void cN();return window.addEventListener(dd,l),()=>{i(),window.removeEventListener(dd,l)}},[]),u.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(Lie,{state:n,elapsedMs:s}):null]})}const zie="(max-width: 1080px)",Uie="(max-width: 720px)";function Bie(){const[e,n]=u.useState(()=>window.location.hash||In);u.useEffect(()=>{const r=()=>n(window.location.hash||In);return window.addEventListener("hashchange",r),()=>window.removeEventListener("hashchange",r)},[]);const s=u.useCallback((r,a=!1)=>{a?window.history.replaceState(null,"",r):window.location.hash=r,n(r)},[]);return[e,s]}function Wie(){const[e,n]=rM();u.useEffect(()=>{sM(e)},[e]);const s=u.useCallback(r=>n({theme:r}),[n]);return[e.theme,s]}const h1=new Map;function Hie(){var Y,Le,Ct,on;const[e,n]=Bie(),[s,r]=u.useState("UTC"),[a,i]=u.useState({approvals:0,failed:0,paused:!1,running:0,needs:0}),[l,o]=Wie(),c=Gn(my),[d,h]=u.useState(!1),[f,m]=u.useState([]),[p,x]=u.useState(null),[g,y]=u.useState(null),[j,v]=u.useState([]),[w,N]=u.useState(!1),[k,S]=u.useState(null),[b,C]=u.useState(null),[$,A]=u.useState(0),[I,M]=u.useState(null),O=kB(),R=f.find(Te=>Te.id===p)??null,_=R!==null&&LG(e),[z,U]=u.useState(!1),P=u.useCallback(()=>U(!0),[]);u.useEffect(()=>{_||U(!1)},[_]),_J(n,oh(e)===null,_?P:void 0);const W=Gn(zie),L=_M(),Q=VT(),F=XP(),ae=pe(()=>Promise.resolve().then(()=>T.version()),[],J6),V=ae.data;iB(ae.reload);const J=V&&!V.checkout&&V.updateAvailable?V:null,H=ay(V==null?void 0:V.web);lB(V==null?void 0:V.web);const X=((Y=pe(()=>Promise.resolve().then(()=>T.connectionSignals()),[],6e4).data)==null?void 0:Y.signals)??[],[G,ce]=u.useState(null),xe=u.useMemo(()=>new Set(G?[G]:[]),[G]),[De,B]=u.useState(new Map);u.useEffect(()=>{const Te=()=>{T.conversations().then(dt=>{const Qe=new Map;for(const vn of dt.conversations){const nn=vn.lastMessageAt??vn.createdAt,Cn=Qe.get(vn.agentId);(!Cn||nn>Cn)&&Qe.set(vn.agentId,nn)}B(Qe)}).catch(()=>{})};Te();const Oe=window.setInterval(Te,3e4);return()=>window.clearInterval(Oe)},[e]);const[ne,Z]=u.useState(!1),[ve,$e]=u.useState("unknown");u.useEffect(()=>{if(ne)return;let Te=!1;return T.onboarding().then(Oe=>{Te||(Z(!0),$e(Oe.state==="done"||Oe.state==="skipped"?"done":"open"),Oe.state==="pending"&&Oe.needs.model&&!oh(window.location.hash)&&n(m6,!0))}).catch(()=>{Te||(Z(!0),$e("open"))}),()=>{Te=!0}},[ne,n]),u.useEffect(()=>{const Te=F6(e);Te&&n(Te,!0)},[e,n]),u.useEffect(()=>{let Te=!1;const Oe=()=>{Xe.agents().then(Qe=>{Te||(m(Qe.agents),dF(Qe.commands),K6(Qe.defaultAgentId??null),x(Qe.defaultAgentId??null),y(vn=>{var nn;return vn??Qe.defaultAgentId??((nn=Qe.agents[0])==null?void 0:nn.id)??null}))}).catch(()=>{})};Oe();const dt=window.setInterval(Oe,15e3);return window.addEventListener("focus",Oe),window.addEventListener(xs,Oe),()=>{Te=!0,window.clearInterval(dt),window.removeEventListener("focus",Oe),window.removeEventListener(xs,Oe)}},[e]),u.useEffect(()=>{let Te=!1;const Oe=()=>{Xe.groups().then(Qe=>{Te||v(Qe.groups)}).catch(()=>{})};Oe();const dt=window.setInterval(Oe,3e4);return()=>{Te=!0,window.clearInterval(dt)}},[e]);const Se=GT(f,p),me=g6(e),Ee=MT(e),Pe=Ee?j.find(Te=>Te.id===Ee.groupId)??null:null,Me=Ee?null:(me==null?void 0:me.agentId)??g;u.useEffect(()=>{me&&y(me.agentId)},[me==null?void 0:me.agentId]);const he=u.useRef(null);me&&(he.current=e);const ke=Te=>{y(Te),n(lt(Te))},Be=Te=>n($i(Te)),qe=u.useCallback((Te,Oe,dt=!0)=>n(Ee?$i(Ee.groupId,Oe):lt(Te,Oe),dt),[n,Ee==null?void 0:Ee.groupId]),[at,le]=u.useState(!1),[,ye]=u.useState(0);u.useEffect(()=>{const Te=()=>{ye(Oe=>Oe+1),T.session().then(Oe=>r(Oe.timezone)).catch(()=>{})};return window.addEventListener(Fx,Te),()=>window.removeEventListener(Fx,Te)},[]),u.useEffect(()=>{T.session().then(Te=>{Ow({timeFormat:Te.timeFormat??null,dateFormat:Te.dateFormat??null}),r(Te.timezone),le(!0)}).catch(()=>{})},[]);const et=VG(at);JG(at,et.refresh,()=>le(!1)),u.useEffect(()=>{const Te=()=>{T.overview().then(dt=>{var Qe;return i({approvals:dt.approvals.pending,failed:dt.jobs.failed??0,paused:dt.paused,running:dt.running??0,needs:((Qe=dt.needsYou)==null?void 0:Qe.total)??dt.approvals.pending+(dt.jobs.failed??0)})}).catch(()=>{})};Te();const Oe=window.setInterval(Te,2e4);return window.addEventListener(Mi,Te),()=>{window.clearInterval(Oe),window.removeEventListener(Mi,Te)}},[]);const pt=pe(()=>Promise.resolve().then(()=>T.focus()),[],6e4),kt=u.useRef(pt.reload);kt.current=pt.reload,u.useEffect(()=>{const Te=()=>kt.current();return window.addEventListener(Mi,Te),()=>window.removeEventListener(Mi,Te)},[]);const Ot=Iie(),Ut=Sie(),Sn=vO()!==null,Vt=Gn(Uie);u.useEffect(()=>{if(!at)return;if(e===_6){N(!0),n(ma,!0);return}const Te=z6(e),Oe=new Date().toDateString();!Te||h1.get(Te)===Oe||(h1.set(Te,Oe),T.tipsSeenPage(Te).catch(()=>{}))},[e,at,n]);const Un={link:$ie(window.location.hostname,Ot&&!Sn),focus:((Le=pt.data)==null?void 0:Le.focus)??null,working:a.running,paused:a.paused,failed:a.failed,approvals:a.approvals,version:V?{current:V.current,latest:V.latest,updateAvailable:!V.checkout&&V.updateAvailable}:void 0,timezone:s},Pn=vie({recovery:((Ct=L.data)==null?void 0:Ct.active)===!0,lost:Ut&&!Sn,paused:a.paused}),Mn=oh(e),gn=zT(e),xn=gn===ma,It=k?j.find(Te=>Te.id===k.groupId)??null:null,Ae=Te=>v(Oe=>Oe.map(dt=>dt.id===Te.id?Te:dt)),Ze=()=>S(null),Re=w?t.jsx(XG,{agents:f,onClose:()=>N(!1),onCreated:Te=>{v(Oe=>[...Oe,Te]),N(!1),n($i(Te.id))}}):It&&(k==null?void 0:k.kind)==="members"?t.jsx(NG,{group:It,agents:f,onClose:Ze,onSaved:Ae}):It&&(k==null?void 0:k.kind)==="rename"?t.jsx(SG,{group:It,onClose:Ze,onSaved:Te=>{Ae(Te),Ze()}}):It&&(k==null?void 0:k.kind)==="clear"?t.jsx(EG,{group:It,onClose:Ze,onCleared:()=>{Ze(),A(Te=>Te+1),n($i(It.id),!0)}}):It&&(k==null?void 0:k.kind)==="delete"?t.jsx(AG,{group:It,agents:f,onClose:Ze,onDeleted:Te=>{const Oe=j.findIndex(dt=>dt.id===It.id);Ze(),v(dt=>dt.filter(Qe=>Qe.id!==It.id)),C({group:It,index:Oe,until:Te}),n(he.current??ma)}}):null,we=()=>{const Te=b;Te&&(C(null),Xe.restoreGroup(Te.group.id).then(Oe=>{v(dt=>{if(dt.some(vn=>vn.id===Oe.id))return dt;const Qe=[...dt];return Qe.splice(Math.min(Math.max(Te.index,0),Qe.length),0,Oe),Qe}),n($i(Oe.id))}).catch(()=>M(Te.group.name)))};return Mn?t.jsx(z0,{delayDuration:400,children:t.jsxs(E0,{swipeDirection:"right",children:[t.jsx(Mae,{navigate:n,timezone:s}),t.jsx(A0,{className:"ui-toasts"})]})}):t.jsx(XB,{picture:(on=f.find(Te=>Te.id===p))==null?void 0:on.picture,children:t.jsx(z0,{delayDuration:400,children:t.jsxs(E0,{swipeDirection:"right",children:[Re,t.jsxs("div",{className:"wb-shell",children:[t.jsx(jie,{banners:Pn,onNavigate:n}),t.jsxs("div",{className:"wb",children:[t.jsx(EJ,{attention:a.needs,place:gn,onNavigate:n,theme:l,onTheme:o,plugins:LJ(Q.rail,F),updateAvailable:J!==null,settingsDot:X.length>0?JP:void 0,stale:H,timezone:s,version:V&&!V.checkout?{current:V.current,latest:V.latest,updateAvailable:V.updateAvailable}:V?{current:V.current,updateAvailable:!1}:void 0,status:Vt?t.jsx(Pie,{status:Un,onNavigate:n}):void 0}),xn&&!W?t.jsx(ZT,{agents:Se,currentId:Me,attention:O,onSelect:ke,lastActivity:De,working:xe,groups:j,currentGroupId:(Pe==null?void 0:Pe.id)??null,onSelectGroup:Be,onNewGroup:()=>N(!0)}):null,xn?t.jsx($G,{timezone:s,agents:Se,agentId:Pe?Pe.coordinator:Me,defaultAgentId:p,group:Pe,...Pe?{onGroupAction:Te=>S({kind:Te,groupId:Pe.id})}:{},requestedConversationId:(Ee==null?void 0:Ee.conversationId)??(me==null?void 0:me.conversationId),requestedTab:me==null?void 0:me.tab,onConversationOpened:qe,onSelectAgent:ke,onWorking:ce,attention:O,agentsInHeader:W,narrow:c,canvasOpen:d,onOpenCanvas:()=>h(!0),onCloseCanvas:()=>h(!1)},`room-${$}`):t.jsx("main",{"data-ground":Kie(gn,e)?"plain":void 0,"data-layout":gn===un?"split":void 0,children:t.jsx(Vie,{hash:e,place:gn,timezone:s,navigate:n,agents:f,defaultAgentId:p,attention:O,pluginPages:Q,update:J,connectionSignals:X,onboarding:ve})})]}),Vt?null:t.jsx(Rie,{status:Un,onNavigate:n})]}),_&&R?t.jsx(FG,{agent:R,agents:f,timezone:s,open:z,onOpenChange:U,navigate:n}):null,t.jsxs(HG,{placement:WG(_,z),children:[t.jsx(GG,{queue:et.queue,agents:f,navigate:n,onDismiss:et.dismiss}),b?t.jsx(pd,{title:`Deleted ${b.group.name}`,body:"Its history goes for good in a few seconds.",duration:e7,onUndo:we,onGone:()=>C(null)},b.group.id):null,I?t.jsx(pd,{title:`${I} is gone for good`,body:"Undo came too late to bring it back.",duration:6e3,onGone:()=>M(null)},`late-${I}`):null,t.jsx(A0,{className:"ui-toasts"})]})]})})})}function Kie(e,n){return ey(n)!==null}function Vie({place:e,pluginPages:n,...s}){const r={...s,pluginPages:n},a=ey(s.hash);if(a){const i=n.find(a.plugin,a.page);if(i)return t.jsx($P,{page:i,item:a.item??null,params:ty(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 yt:return t.jsx(tee,{...r});case Yt:return t.jsx(rX,{...s});case un:return t.jsx(Gre,{...r});case ya:return t.jsx(KY,{...s});default:return t.jsx(zee,{...r})}}function Gie(){"serviceWorker"in navigator&&window.addEventListener("load",()=>{const e=`./sw.js?v=${encodeURIComponent(ry)}`;navigator.serviceWorker.register(e,{scope:"./"}).catch(()=>{})})}function qie({search:e=location.search}){const[n,s]=u.useState(null),r=u.useRef(!1);return u.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 d=new BroadcastChannel(IM);d.postMessage({id:c.id}),d.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(de,{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(st,{href:"/#/settings/connections",children:"Back to Connections"}):null]})})}const f1=document.getElementById("root");f1&&CA(f1).render(t.jsx(u.StrictMode,{children:location.pathname==="/connections/callback"?t.jsx(qie,{}):t.jsx(_ie,{children:t.jsx(kie,{children:t.jsx(CJ,{children:t.jsx(Hie,{})})})})}));Gie();export{Qie as c,RO as g};