@withbuddi/buddi 0.1.0-pre.25 → 0.1.0-pre.26

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 (334) hide show
  1. package/examples/agents/agent-father/agent.md +1 -0
  2. package/extension/manifest.json +2 -2
  3. package/node_modules/@buddi/cli/dist/.tsbuildinfo +1 -1
  4. package/node_modules/@buddi/cli/dist/doctor-probes.d.ts.map +1 -1
  5. package/node_modules/@buddi/cli/dist/doctor-probes.js +29 -8
  6. package/node_modules/@buddi/cli/dist/doctor-probes.js.map +1 -1
  7. package/node_modules/@buddi/cli/dist/doctor.d.ts +8 -1
  8. package/node_modules/@buddi/cli/dist/doctor.d.ts.map +1 -1
  9. package/node_modules/@buddi/cli/dist/doctor.js +19 -2
  10. package/node_modules/@buddi/cli/dist/doctor.js.map +1 -1
  11. package/node_modules/@buddi/core/dist/.tsbuildinfo +1 -1
  12. package/node_modules/@buddi/core/dist/agents/catalog.d.ts.map +1 -1
  13. package/node_modules/@buddi/core/dist/agents/catalog.js +11 -2
  14. package/node_modules/@buddi/core/dist/agents/catalog.js.map +1 -1
  15. package/node_modules/@buddi/core/dist/agents/skills.d.ts +4 -4
  16. package/node_modules/@buddi/core/dist/notifications/agent.d.ts +54 -0
  17. package/node_modules/@buddi/core/dist/notifications/agent.d.ts.map +1 -0
  18. package/node_modules/@buddi/core/dist/notifications/agent.js +134 -0
  19. package/node_modules/@buddi/core/dist/notifications/agent.js.map +1 -0
  20. package/node_modules/@buddi/core/dist/notifications/index.d.ts +1 -0
  21. package/node_modules/@buddi/core/dist/notifications/index.d.ts.map +1 -1
  22. package/node_modules/@buddi/core/dist/notifications/index.js +1 -0
  23. package/node_modules/@buddi/core/dist/notifications/index.js.map +1 -1
  24. package/node_modules/@buddi/core/dist/notifications/notify.d.ts +4 -0
  25. package/node_modules/@buddi/core/dist/notifications/notify.d.ts.map +1 -1
  26. package/node_modules/@buddi/core/dist/notifications/notify.js +19 -7
  27. package/node_modules/@buddi/core/dist/notifications/notify.js.map +1 -1
  28. package/node_modules/@buddi/core/dist/notifications/store.d.ts +8 -1
  29. package/node_modules/@buddi/core/dist/notifications/store.d.ts.map +1 -1
  30. package/node_modules/@buddi/core/dist/notifications/store.js +55 -6
  31. package/node_modules/@buddi/core/dist/notifications/store.js.map +1 -1
  32. package/node_modules/@buddi/core/dist/notifications/types.d.ts +26 -2
  33. package/node_modules/@buddi/core/dist/notifications/types.d.ts.map +1 -1
  34. package/node_modules/@buddi/core/dist/notifications/types.js +1 -1
  35. package/node_modules/@buddi/core/dist/notifications/types.js.map +1 -1
  36. package/node_modules/@buddi/core/dist/vault/resolve.d.ts.map +1 -1
  37. package/node_modules/@buddi/core/dist/vault/resolve.js +0 -1
  38. package/node_modules/@buddi/core/dist/vault/resolve.js.map +1 -1
  39. package/node_modules/@buddi/core/migrations/054_agent_messages.sql +15 -0
  40. package/node_modules/@buddi/gateway/dist/.tsbuildinfo +1 -1
  41. package/node_modules/@buddi/gateway/dist/agents/owner-tools.d.ts +34 -1
  42. package/node_modules/@buddi/gateway/dist/agents/owner-tools.d.ts.map +1 -1
  43. package/node_modules/@buddi/gateway/dist/agents/owner-tools.js +87 -4
  44. package/node_modules/@buddi/gateway/dist/agents/owner-tools.js.map +1 -1
  45. package/node_modules/@buddi/gateway/dist/bootstrap.js +3 -3
  46. package/node_modules/@buddi/gateway/dist/bootstrap.js.map +1 -1
  47. package/node_modules/@buddi/gateway/dist/owner-secrets.d.ts +77 -8
  48. package/node_modules/@buddi/gateway/dist/owner-secrets.d.ts.map +1 -1
  49. package/node_modules/@buddi/gateway/dist/owner-secrets.js +142 -14
  50. package/node_modules/@buddi/gateway/dist/owner-secrets.js.map +1 -1
  51. package/node_modules/@buddi/gateway/dist/serve.d.ts.map +1 -1
  52. package/node_modules/@buddi/gateway/dist/serve.js +24 -8
  53. package/node_modules/@buddi/gateway/dist/serve.js.map +1 -1
  54. package/node_modules/@buddi/gateway/dist/system-context.d.ts +2 -0
  55. package/node_modules/@buddi/gateway/dist/system-context.d.ts.map +1 -1
  56. package/node_modules/@buddi/gateway/dist/system-context.js +5 -1
  57. package/node_modules/@buddi/gateway/dist/system-context.js.map +1 -1
  58. package/node_modules/@buddi/gateway/dist/telegram/channel.d.ts +7 -0
  59. package/node_modules/@buddi/gateway/dist/telegram/channel.d.ts.map +1 -1
  60. package/node_modules/@buddi/gateway/dist/telegram/channel.js +14 -2
  61. package/node_modules/@buddi/gateway/dist/telegram/channel.js.map +1 -1
  62. package/node_modules/@buddi/gateway/dist/web/connections.d.ts +3 -0
  63. package/node_modules/@buddi/gateway/dist/web/connections.d.ts.map +1 -1
  64. package/node_modules/@buddi/gateway/dist/web/connections.js +48 -6
  65. package/node_modules/@buddi/gateway/dist/web/connections.js.map +1 -1
  66. package/node_modules/@buddi/gateway/dist/web/notifications.d.ts +6 -0
  67. package/node_modules/@buddi/gateway/dist/web/notifications.d.ts.map +1 -1
  68. package/node_modules/@buddi/gateway/dist/web/notifications.js +14 -1
  69. package/node_modules/@buddi/gateway/dist/web/notifications.js.map +1 -1
  70. package/node_modules/@buddi/gateway/dist/web/onboarding.d.ts.map +1 -1
  71. package/node_modules/@buddi/gateway/dist/web/onboarding.js +5 -2
  72. package/node_modules/@buddi/gateway/dist/web/onboarding.js.map +1 -1
  73. package/node_modules/@buddi/gateway/dist/web/recovery.d.ts +10 -0
  74. package/node_modules/@buddi/gateway/dist/web/recovery.d.ts.map +1 -1
  75. package/node_modules/@buddi/gateway/dist/web/recovery.js +113 -33
  76. package/node_modules/@buddi/gateway/dist/web/recovery.js.map +1 -1
  77. package/node_modules/@buddi/gateway/dist/web/server.d.ts.map +1 -1
  78. package/node_modules/@buddi/gateway/dist/web/server.js +16 -5
  79. package/node_modules/@buddi/gateway/dist/web/server.js.map +1 -1
  80. package/node_modules/@buddi/gateway/dist/web/sessions.d.ts +8 -0
  81. package/node_modules/@buddi/gateway/dist/web/sessions.d.ts.map +1 -1
  82. package/node_modules/@buddi/gateway/dist/web/sessions.js +24 -1
  83. package/node_modules/@buddi/gateway/dist/web/sessions.js.map +1 -1
  84. package/node_modules/@buddi/gateway/src/agents/starter/keeper/agent.md +2 -2
  85. package/node_modules/@buddi/gateway/src/agents/starter/planner/agent.md +1 -1
  86. package/node_modules/@buddi/gateway/src/agents/starter/scout/agent.md +1 -1
  87. package/node_modules/@buddi/install/dist/.tsbuildinfo +1 -1
  88. package/node_modules/@buddi/runtime/dist/.tsbuildinfo +1 -1
  89. package/node_modules/@buddi/runtime/dist/delegate.js +1 -1
  90. package/node_modules/@buddi/runtime/dist/delegate.js.map +1 -1
  91. package/node_modules/@buddi/tool-email/dist/.tsbuildinfo +1 -1
  92. package/node_modules/@buddi/tool-email/dist/config.d.ts +13 -9
  93. package/node_modules/@buddi/tool-email/dist/config.d.ts.map +1 -1
  94. package/node_modules/@buddi/tool-email/dist/config.js +33 -40
  95. package/node_modules/@buddi/tool-email/dist/config.js.map +1 -1
  96. package/node_modules/@buddi/tool-email/dist/index.d.ts +1 -1
  97. package/node_modules/@buddi/tool-email/dist/index.d.ts.map +1 -1
  98. package/node_modules/@buddi/tool-email/dist/index.js +1 -1
  99. package/node_modules/@buddi/tool-email/dist/index.js.map +1 -1
  100. package/node_modules/@buddi/tool-email/dist/pages/accounts.d.ts +1 -2
  101. package/node_modules/@buddi/tool-email/dist/pages/accounts.d.ts.map +1 -1
  102. package/node_modules/@buddi/tool-email/dist/pages/accounts.js +42 -18
  103. package/node_modules/@buddi/tool-email/dist/pages/accounts.js.map +1 -1
  104. package/node_modules/@buddi/tool-email/dist/pages/queries.d.ts.map +1 -1
  105. package/node_modules/@buddi/tool-email/dist/pages/queries.js +7 -5
  106. package/node_modules/@buddi/tool-email/dist/pages/queries.js.map +1 -1
  107. package/node_modules/@buddi/tool-email/dist/ports.d.ts +5 -1
  108. package/node_modules/@buddi/tool-email/dist/ports.d.ts.map +1 -1
  109. package/node_modules/@buddi/tool-email/dist/tools/shared.js +1 -1
  110. package/node_modules/@buddi/tool-email/dist/tools/shared.js.map +1 -1
  111. package/node_modules/@buddi/tool-web/dist/.tsbuildinfo +1 -1
  112. package/node_modules/@buddi/tool-web/dist/providers/index.d.ts +1 -2
  113. package/node_modules/@buddi/tool-web/dist/providers/index.d.ts.map +1 -1
  114. package/node_modules/@buddi/tool-web/dist/providers/index.js +1 -2
  115. package/node_modules/@buddi/tool-web/dist/providers/index.js.map +1 -1
  116. package/node_modules/hono/dist/cjs/jsx/utils.js +1 -1
  117. package/node_modules/hono/dist/cjs/middleware/combine/index.js +3 -1
  118. package/node_modules/hono/dist/cjs/middleware/etag/index.js +2 -2
  119. package/node_modules/hono/dist/jsx/utils.js +1 -1
  120. package/node_modules/hono/dist/middleware/combine/index.js +3 -1
  121. package/node_modules/hono/dist/middleware/etag/index.js +2 -2
  122. package/node_modules/hono/dist/middleware/language/language.js +1 -1
  123. package/node_modules/hono/dist/types/adapter/aws-lambda/handler.d.ts +2 -1
  124. package/node_modules/hono/dist/types/adapter/aws-lambda/types.d.ts +2 -1
  125. package/node_modules/hono/dist/types/adapter/bun/websocket.d.ts +2 -1
  126. package/node_modules/hono/dist/types/adapter/cloudflare-pages/handler.d.ts +2 -1
  127. package/node_modules/hono/dist/types/adapter/cloudflare-workers/serve-static-module.d.ts +2 -1
  128. package/node_modules/hono/dist/types/adapter/lambda-edge/handler.d.ts +2 -1
  129. package/node_modules/hono/dist/types/adapter/service-worker/handler.d.ts +2 -1
  130. package/node_modules/hono/dist/types/adapter/service-worker/index.d.ts +2 -1
  131. package/node_modules/hono/dist/types/adapter/service-worker/types.d.ts +2 -1
  132. package/node_modules/hono/dist/types/client/types.d.ts +2 -1
  133. package/node_modules/hono/dist/types/context.d.ts +2 -1
  134. package/node_modules/hono/dist/types/helper/cookie/index.d.ts +2 -1
  135. package/node_modules/hono/dist/types/helper/css/common.d.ts +2 -1
  136. package/node_modules/hono/dist/types/helper/css/index.d.ts +2 -1
  137. package/node_modules/hono/dist/types/helper/dev/index.d.ts +2 -1
  138. package/node_modules/hono/dist/types/helper/factory/index.d.ts +2 -1
  139. package/node_modules/hono/dist/types/helper/proxy/index.d.ts +2 -1
  140. package/node_modules/hono/dist/types/helper/ssg/middleware.d.ts +2 -1
  141. package/node_modules/hono/dist/types/helper/ssg/utils.d.ts +2 -1
  142. package/node_modules/hono/dist/types/helper/testing/index.d.ts +2 -1
  143. package/node_modules/hono/dist/types/hono-base.d.ts +2 -1
  144. package/node_modules/hono/dist/types/http-exception.d.ts +2 -1
  145. package/node_modules/hono/dist/types/jsx/base.d.ts +4 -3
  146. package/node_modules/hono/dist/types/jsx/context.d.ts +2 -1
  147. package/node_modules/hono/dist/types/jsx/dom/client.d.ts +2 -1
  148. package/node_modules/hono/dist/types/jsx/dom/css.d.ts +2 -1
  149. package/node_modules/hono/dist/types/jsx/dom/hooks/index.d.ts +2 -1
  150. package/node_modules/hono/dist/types/jsx/dom/index.d.ts +2 -1
  151. package/node_modules/hono/dist/types/jsx/dom/render.d.ts +2 -1
  152. package/node_modules/hono/dist/types/jsx/dom/server.d.ts +2 -1
  153. package/node_modules/hono/dist/types/jsx/hooks/index.d.ts +2 -1
  154. package/node_modules/hono/dist/types/jsx/index.d.ts +2 -1
  155. package/node_modules/hono/dist/types/jsx/types.d.ts +2 -1
  156. package/node_modules/hono/dist/types/middleware/basic-auth/index.d.ts +2 -1
  157. package/node_modules/hono/dist/types/middleware/bearer-auth/index.d.ts +2 -1
  158. package/node_modules/hono/dist/types/middleware/body-limit/index.d.ts +2 -1
  159. package/node_modules/hono/dist/types/middleware/combine/index.d.ts +2 -1
  160. package/node_modules/hono/dist/types/middleware/compress/index.d.ts +2 -1
  161. package/node_modules/hono/dist/types/middleware/cors/index.d.ts +2 -1
  162. package/node_modules/hono/dist/types/middleware/csrf/index.d.ts +2 -1
  163. package/node_modules/hono/dist/types/middleware/etag/index.d.ts +2 -1
  164. package/node_modules/hono/dist/types/middleware/ip-restriction/index.d.ts +2 -1
  165. package/node_modules/hono/dist/types/middleware/jsx-renderer/index.d.ts +2 -1
  166. package/node_modules/hono/dist/types/middleware/jwt/index.d.ts +2 -1
  167. package/node_modules/hono/dist/types/middleware/language/index.d.ts +2 -1
  168. package/node_modules/hono/dist/types/middleware/logger/index.d.ts +2 -1
  169. package/node_modules/hono/dist/types/middleware/method-not-allowed/index.d.ts +2 -1
  170. package/node_modules/hono/dist/types/middleware/method-override/index.d.ts +2 -1
  171. package/node_modules/hono/dist/types/middleware/powered-by/index.d.ts +2 -1
  172. package/node_modules/hono/dist/types/middleware/pretty-json/index.d.ts +2 -1
  173. package/node_modules/hono/dist/types/middleware/request-id/index.d.ts +2 -1
  174. package/node_modules/hono/dist/types/middleware/secure-headers/index.d.ts +2 -1
  175. package/node_modules/hono/dist/types/middleware/secure-headers/permissions-policy.d.ts +2 -1
  176. package/node_modules/hono/dist/types/middleware/secure-headers/secure-headers.d.ts +2 -1
  177. package/node_modules/hono/dist/types/middleware/timing/index.d.ts +2 -1
  178. package/node_modules/hono/dist/types/middleware/timing/timing.d.ts +2 -1
  179. package/node_modules/hono/dist/types/middleware/trailing-slash/index.d.ts +2 -1
  180. package/node_modules/hono/dist/types/request.d.ts +2 -1
  181. package/node_modules/hono/dist/types/router/reg-exp-router/prepared-router.d.ts +2 -1
  182. package/node_modules/hono/dist/types/types.d.ts +2 -1
  183. package/node_modules/hono/dist/types/utils/body.d.ts +2 -1
  184. package/node_modules/hono/dist/types/utils/buffer.d.ts +2 -1
  185. package/node_modules/hono/dist/types/utils/cookie.d.ts +2 -1
  186. package/node_modules/hono/dist/types/utils/crypto.d.ts +2 -1
  187. package/node_modules/hono/dist/types/utils/filepath.d.ts +2 -1
  188. package/node_modules/hono/dist/types/utils/html.d.ts +2 -1
  189. package/node_modules/hono/dist/types/utils/mime.d.ts +2 -1
  190. package/node_modules/hono/dist/types/utils/types.d.ts +2 -1
  191. package/node_modules/hono/dist/types/utils/url.d.ts +2 -1
  192. package/node_modules/hono/dist/types/validator/utils.d.ts +2 -1
  193. package/node_modules/hono/dist/types/validator/validator.d.ts +2 -1
  194. package/node_modules/hono/package.json +2 -2
  195. package/node_modules/pg/lib/client.js +18 -0
  196. package/node_modules/pg/lib/connection.js +8 -1
  197. package/node_modules/pg/lib/crypto/cert-signatures.js +1 -1
  198. package/node_modules/pg/lib/native/client.js +11 -3
  199. package/node_modules/pg/lib/native/query.js +3 -1
  200. package/node_modules/pg/lib/query.js +5 -1
  201. package/node_modules/pg/lib/utils.js +19 -1
  202. package/node_modules/pg/package.json +5 -5
  203. package/node_modules/pg-connection-string/index.js +1 -1
  204. package/node_modules/pg-connection-string/package.json +2 -3
  205. package/node_modules/pg-protocol/dist/buffer-writer.d.ts +5 -1
  206. package/node_modules/pg-protocol/dist/buffer-writer.js +10 -1
  207. package/node_modules/pg-protocol/dist/buffer-writer.js.map +1 -1
  208. package/node_modules/pg-protocol/dist/serializer.js +20 -18
  209. package/node_modules/pg-protocol/dist/serializer.js.map +1 -1
  210. package/node_modules/pg-protocol/package.json +2 -2
  211. package/node_modules/pg-protocol/src/buffer-writer.ts +12 -2
  212. package/node_modules/pg-protocol/src/serializer.ts +26 -20
  213. package/package.json +2 -2
  214. package/packages/cli/dist/.tsbuildinfo +1 -1
  215. package/packages/cli/dist/doctor-probes.d.ts.map +1 -1
  216. package/packages/cli/dist/doctor-probes.js +29 -8
  217. package/packages/cli/dist/doctor-probes.js.map +1 -1
  218. package/packages/cli/dist/doctor.d.ts +8 -1
  219. package/packages/cli/dist/doctor.d.ts.map +1 -1
  220. package/packages/cli/dist/doctor.js +19 -2
  221. package/packages/cli/dist/doctor.js.map +1 -1
  222. package/packages/core/dist/.tsbuildinfo +1 -1
  223. package/packages/core/dist/agents/catalog.d.ts.map +1 -1
  224. package/packages/core/dist/agents/catalog.js +11 -2
  225. package/packages/core/dist/agents/catalog.js.map +1 -1
  226. package/packages/core/dist/agents/skills.d.ts +4 -4
  227. package/packages/core/dist/notifications/agent.d.ts +54 -0
  228. package/packages/core/dist/notifications/agent.d.ts.map +1 -0
  229. package/packages/core/dist/notifications/agent.js +134 -0
  230. package/packages/core/dist/notifications/agent.js.map +1 -0
  231. package/packages/core/dist/notifications/index.d.ts +1 -0
  232. package/packages/core/dist/notifications/index.d.ts.map +1 -1
  233. package/packages/core/dist/notifications/index.js +1 -0
  234. package/packages/core/dist/notifications/index.js.map +1 -1
  235. package/packages/core/dist/notifications/notify.d.ts +4 -0
  236. package/packages/core/dist/notifications/notify.d.ts.map +1 -1
  237. package/packages/core/dist/notifications/notify.js +19 -7
  238. package/packages/core/dist/notifications/notify.js.map +1 -1
  239. package/packages/core/dist/notifications/store.d.ts +8 -1
  240. package/packages/core/dist/notifications/store.d.ts.map +1 -1
  241. package/packages/core/dist/notifications/store.js +55 -6
  242. package/packages/core/dist/notifications/store.js.map +1 -1
  243. package/packages/core/dist/notifications/types.d.ts +26 -2
  244. package/packages/core/dist/notifications/types.d.ts.map +1 -1
  245. package/packages/core/dist/notifications/types.js +1 -1
  246. package/packages/core/dist/notifications/types.js.map +1 -1
  247. package/packages/core/dist/vault/resolve.d.ts.map +1 -1
  248. package/packages/core/dist/vault/resolve.js +0 -1
  249. package/packages/core/dist/vault/resolve.js.map +1 -1
  250. package/packages/core/migrations/054_agent_messages.sql +15 -0
  251. package/packages/gateway/dist/.tsbuildinfo +1 -1
  252. package/packages/gateway/dist/agents/owner-tools.d.ts +34 -1
  253. package/packages/gateway/dist/agents/owner-tools.d.ts.map +1 -1
  254. package/packages/gateway/dist/agents/owner-tools.js +87 -4
  255. package/packages/gateway/dist/agents/owner-tools.js.map +1 -1
  256. package/packages/gateway/dist/bootstrap.js +3 -3
  257. package/packages/gateway/dist/bootstrap.js.map +1 -1
  258. package/packages/gateway/dist/owner-secrets.d.ts +77 -8
  259. package/packages/gateway/dist/owner-secrets.d.ts.map +1 -1
  260. package/packages/gateway/dist/owner-secrets.js +142 -14
  261. package/packages/gateway/dist/owner-secrets.js.map +1 -1
  262. package/packages/gateway/dist/serve.d.ts.map +1 -1
  263. package/packages/gateway/dist/serve.js +24 -8
  264. package/packages/gateway/dist/serve.js.map +1 -1
  265. package/packages/gateway/dist/system-context.d.ts +2 -0
  266. package/packages/gateway/dist/system-context.d.ts.map +1 -1
  267. package/packages/gateway/dist/system-context.js +5 -1
  268. package/packages/gateway/dist/system-context.js.map +1 -1
  269. package/packages/gateway/dist/telegram/channel.d.ts +7 -0
  270. package/packages/gateway/dist/telegram/channel.d.ts.map +1 -1
  271. package/packages/gateway/dist/telegram/channel.js +14 -2
  272. package/packages/gateway/dist/telegram/channel.js.map +1 -1
  273. package/packages/gateway/dist/web/connections.d.ts +3 -0
  274. package/packages/gateway/dist/web/connections.d.ts.map +1 -1
  275. package/packages/gateway/dist/web/connections.js +48 -6
  276. package/packages/gateway/dist/web/connections.js.map +1 -1
  277. package/packages/gateway/dist/web/notifications.d.ts +6 -0
  278. package/packages/gateway/dist/web/notifications.d.ts.map +1 -1
  279. package/packages/gateway/dist/web/notifications.js +14 -1
  280. package/packages/gateway/dist/web/notifications.js.map +1 -1
  281. package/packages/gateway/dist/web/onboarding.d.ts.map +1 -1
  282. package/packages/gateway/dist/web/onboarding.js +5 -2
  283. package/packages/gateway/dist/web/onboarding.js.map +1 -1
  284. package/packages/gateway/dist/web/recovery.d.ts +10 -0
  285. package/packages/gateway/dist/web/recovery.d.ts.map +1 -1
  286. package/packages/gateway/dist/web/recovery.js +113 -33
  287. package/packages/gateway/dist/web/recovery.js.map +1 -1
  288. package/packages/gateway/dist/web/server.d.ts.map +1 -1
  289. package/packages/gateway/dist/web/server.js +16 -5
  290. package/packages/gateway/dist/web/server.js.map +1 -1
  291. package/packages/gateway/dist/web/sessions.d.ts +8 -0
  292. package/packages/gateway/dist/web/sessions.d.ts.map +1 -1
  293. package/packages/gateway/dist/web/sessions.js +24 -1
  294. package/packages/gateway/dist/web/sessions.js.map +1 -1
  295. package/packages/gateway/src/agents/starter/keeper/agent.md +2 -2
  296. package/packages/gateway/src/agents/starter/planner/agent.md +1 -1
  297. package/packages/gateway/src/agents/starter/scout/agent.md +1 -1
  298. package/packages/install/dist/.tsbuildinfo +1 -1
  299. package/packages/runtime/dist/.tsbuildinfo +1 -1
  300. package/packages/runtime/dist/delegate.js +1 -1
  301. package/packages/runtime/dist/delegate.js.map +1 -1
  302. package/packages/tools/email/dist/.tsbuildinfo +1 -1
  303. package/packages/tools/email/dist/config.d.ts +13 -9
  304. package/packages/tools/email/dist/config.d.ts.map +1 -1
  305. package/packages/tools/email/dist/config.js +33 -40
  306. package/packages/tools/email/dist/config.js.map +1 -1
  307. package/packages/tools/email/dist/index.d.ts +1 -1
  308. package/packages/tools/email/dist/index.d.ts.map +1 -1
  309. package/packages/tools/email/dist/index.js +1 -1
  310. package/packages/tools/email/dist/index.js.map +1 -1
  311. package/packages/tools/email/dist/pages/accounts.d.ts +1 -2
  312. package/packages/tools/email/dist/pages/accounts.d.ts.map +1 -1
  313. package/packages/tools/email/dist/pages/accounts.js +42 -18
  314. package/packages/tools/email/dist/pages/accounts.js.map +1 -1
  315. package/packages/tools/email/dist/pages/queries.d.ts.map +1 -1
  316. package/packages/tools/email/dist/pages/queries.js +7 -5
  317. package/packages/tools/email/dist/pages/queries.js.map +1 -1
  318. package/packages/tools/email/dist/ports.d.ts +5 -1
  319. package/packages/tools/email/dist/ports.d.ts.map +1 -1
  320. package/packages/tools/email/dist/tools/shared.js +1 -1
  321. package/packages/tools/email/dist/tools/shared.js.map +1 -1
  322. package/packages/tools/web/dist/.tsbuildinfo +1 -1
  323. package/packages/tools/web/dist/providers/index.d.ts +1 -2
  324. package/packages/tools/web/dist/providers/index.d.ts.map +1 -1
  325. package/packages/tools/web/dist/providers/index.js +1 -2
  326. package/packages/tools/web/dist/providers/index.js.map +1 -1
  327. package/packages/web/dist/assets/{index-DIXokQ4n.css → index-BxbiKNMS.css} +1 -1
  328. package/packages/web/dist/assets/index-Rrze3bGo.js +130 -0
  329. package/packages/web/dist/assets/{lottie_light-j3HICV9o.js → lottie_light-7wQnGwdw.js} +1 -1
  330. package/packages/web/dist/build.json +1 -1
  331. package/packages/web/dist/index.html +2 -2
  332. package/packages/web/dist/precache.json +4 -4
  333. package/packages/web/dist/sw.js +5 -3
  334. package/packages/web/dist/assets/index-uqQyuYjR.js +0 -128
@@ -1,128 +0,0 @@
1
- var qv=e=>{throw TypeError(e)};var Qv=(e,t,s)=>t.has(e)||qv("Cannot "+s);var an=(e,t,s)=>(Qv(e,t,"read from private field"),s?s.call(e):t.get(e)),Jv=(e,t,s)=>t.has(e)?qv("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),hh=(e,t,s,r)=>(Qv(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s);function FA(e,t){for(var s=0;s<t.length;s++){const r=t[s];if(typeof r!="string"&&!Array.isArray(r)){for(const i in r)if(i!=="default"&&!(i in e)){const a=Object.getOwnPropertyDescriptor(r,i);a&&Object.defineProperty(e,i,a.get?a:{enumerable:!0,get:()=>r[i]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const a of i)if(a.type==="childList")for(const l of a.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&r(l)}).observe(document,{childList:!0,subtree:!0});function s(i){const a={};return i.integrity&&(a.integrity=i.integrity),i.referrerPolicy&&(a.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?a.credentials="include":i.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function r(i){if(i.ep)return;i.ep=!0;const a=s(i);fetch(i.href,a)}})();var TK=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function zA(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Sb={exports:{}},fd={},Nb={exports:{}},ze={};/**
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 Mo=Symbol.for("react.element"),UA=Symbol.for("react.portal"),BA=Symbol.for("react.fragment"),WA=Symbol.for("react.strict_mode"),HA=Symbol.for("react.profiler"),KA=Symbol.for("react.provider"),VA=Symbol.for("react.context"),GA=Symbol.for("react.forward_ref"),YA=Symbol.for("react.suspense"),qA=Symbol.for("react.memo"),QA=Symbol.for("react.lazy"),Xv=Symbol.iterator;function JA(e){return e===null||typeof e!="object"?null:(e=Xv&&e[Xv]||e["@@iterator"],typeof e=="function"?e:null)}var Cb={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},Eb=Object.assign,Ab={};function Ja(e,t,s){this.props=e,this.context=t,this.refs=Ab,this.updater=s||Cb}Ja.prototype.isReactComponent={};Ja.prototype.setState=function(e,t){if(typeof e!="object"&&typeof e!="function"&&e!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,t,"setState")};Ja.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function Tb(){}Tb.prototype=Ja.prototype;function Vp(e,t,s){this.props=e,this.context=t,this.refs=Ab,this.updater=s||Cb}var Gp=Vp.prototype=new Tb;Gp.constructor=Vp;Eb(Gp,Ja.prototype);Gp.isPureReactComponent=!0;var Zv=Array.isArray,Rb=Object.prototype.hasOwnProperty,Yp={current:null},Ib={key:!0,ref:!0,__self:!0,__source:!0};function Pb(e,t,s){var r,i={},a=null,l=null;if(t!=null)for(r in t.ref!==void 0&&(l=t.ref),t.key!==void 0&&(a=""+t.key),t)Rb.call(t,r)&&!Ib.hasOwnProperty(r)&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=s;else if(1<o){for(var c=Array(o),u=0;u<o;u++)c[u]=arguments[u+2];i.children=c}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return{$$typeof:Mo,type:e,key:a,ref:l,props:i,_owner:Yp.current}}function XA(e,t){return{$$typeof:Mo,type:e.type,key:t,ref:e.ref,props:e.props,_owner:e._owner}}function qp(e){return typeof e=="object"&&e!==null&&e.$$typeof===Mo}function ZA(e){var t={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(s){return t[s]})}var ej=/\/+/g;function fh(e,t){return typeof e=="object"&&e!==null&&e.key!=null?ZA(""+e.key):t.toString(36)}function Yc(e,t,s,r,i){var a=typeof e;(a==="undefined"||a==="boolean")&&(e=null);var l=!1;if(e===null)l=!0;else switch(a){case"string":case"number":l=!0;break;case"object":switch(e.$$typeof){case Mo:case UA:l=!0}}if(l)return l=e,i=i(l),e=r===""?"."+fh(l,0):r,Zv(i)?(s="",e!=null&&(s=e.replace(ej,"$&/")+"/"),Yc(i,t,s,"",function(u){return u})):i!=null&&(qp(i)&&(i=XA(i,s+(!i.key||l&&l.key===i.key?"":(""+i.key).replace(ej,"$&/")+"/")+e)),t.push(i)),1;if(l=0,r=r===""?".":r+":",Zv(e))for(var o=0;o<e.length;o++){a=e[o];var c=r+fh(a,o);l+=Yc(a,t,s,c,i)}else if(c=JA(e),typeof c=="function")for(e=c.call(e),o=0;!(a=e.next()).done;)a=a.value,c=r+fh(a,o++),l+=Yc(a,t,s,c,i);else if(a==="object")throw t=String(e),Error("Objects are not valid as a React child (found: "+(t==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":t)+"). If you meant to render a collection of children, use an array instead.");return l}function ic(e,t,s){if(e==null)return e;var r=[],i=0;return Yc(e,r,"","",function(a){return t.call(s,a,i++)}),r}function eT(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(s){(e._status===0||e._status===-1)&&(e._status=1,e._result=s)},function(s){(e._status===0||e._status===-1)&&(e._status=2,e._result=s)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var jn={current:null},qc={transition:null},tT={ReactCurrentDispatcher:jn,ReactCurrentBatchConfig:qc,ReactCurrentOwner:Yp};function $b(){throw Error("act(...) is not supported in production builds of React.")}ze.Children={map:ic,forEach:function(e,t,s){ic(e,function(){t.apply(this,arguments)},s)},count:function(e){var t=0;return ic(e,function(){t++}),t},toArray:function(e){return ic(e,function(t){return t})||[]},only:function(e){if(!qp(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};ze.Component=Ja;ze.Fragment=BA;ze.Profiler=HA;ze.PureComponent=Vp;ze.StrictMode=WA;ze.Suspense=YA;ze.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=tT;ze.act=$b;ze.cloneElement=function(e,t,s){if(e==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+e+".");var r=Eb({},e.props),i=e.key,a=e.ref,l=e._owner;if(t!=null){if(t.ref!==void 0&&(a=t.ref,l=Yp.current),t.key!==void 0&&(i=""+t.key),e.type&&e.type.defaultProps)var o=e.type.defaultProps;for(c in t)Rb.call(t,c)&&!Ib.hasOwnProperty(c)&&(r[c]=t[c]===void 0&&o!==void 0?o[c]:t[c])}var c=arguments.length-2;if(c===1)r.children=s;else if(1<c){o=Array(c);for(var u=0;u<c;u++)o[u]=arguments[u+2];r.children=o}return{$$typeof:Mo,type:e.type,key:i,ref:a,props:r,_owner:l}};ze.createContext=function(e){return e={$$typeof:VA,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:KA,_context:e},e.Consumer=e};ze.createElement=Pb;ze.createFactory=function(e){var t=Pb.bind(null,e);return t.type=e,t};ze.createRef=function(){return{current:null}};ze.forwardRef=function(e){return{$$typeof:GA,render:e}};ze.isValidElement=qp;ze.lazy=function(e){return{$$typeof:QA,_payload:{_status:-1,_result:e},_init:eT}};ze.memo=function(e,t){return{$$typeof:qA,type:e,compare:t===void 0?null:t}};ze.startTransition=function(e){var t=qc.transition;qc.transition={};try{e()}finally{qc.transition=t}};ze.unstable_act=$b;ze.useCallback=function(e,t){return jn.current.useCallback(e,t)};ze.useContext=function(e){return jn.current.useContext(e)};ze.useDebugValue=function(){};ze.useDeferredValue=function(e){return jn.current.useDeferredValue(e)};ze.useEffect=function(e,t){return jn.current.useEffect(e,t)};ze.useId=function(){return jn.current.useId()};ze.useImperativeHandle=function(e,t,s){return jn.current.useImperativeHandle(e,t,s)};ze.useInsertionEffect=function(e,t){return jn.current.useInsertionEffect(e,t)};ze.useLayoutEffect=function(e,t){return jn.current.useLayoutEffect(e,t)};ze.useMemo=function(e,t){return jn.current.useMemo(e,t)};ze.useReducer=function(e,t,s){return jn.current.useReducer(e,t,s)};ze.useRef=function(e){return jn.current.useRef(e)};ze.useState=function(e){return jn.current.useState(e)};ze.useSyncExternalStore=function(e,t,s){return jn.current.useSyncExternalStore(e,t,s)};ze.useTransition=function(){return jn.current.useTransition()};ze.version="18.3.1";Nb.exports=ze;var f=Nb.exports;const nT=zA(f),Xa=FA({__proto__:null,default:nT},[f]);/**
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 sT=f,rT=Symbol.for("react.element"),iT=Symbol.for("react.fragment"),aT=Object.prototype.hasOwnProperty,lT=sT.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,oT={key:!0,ref:!0,__self:!0,__source:!0};function Mb(e,t,s){var r,i={},a=null,l=null;s!==void 0&&(a=""+s),t.key!==void 0&&(a=""+t.key),t.ref!==void 0&&(l=t.ref);for(r in t)aT.call(t,r)&&!oT.hasOwnProperty(r)&&(i[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps,t)i[r]===void 0&&(i[r]=t[r]);return{$$typeof:rT,type:e,key:a,ref:l,props:i,_owner:lT.current}}fd.Fragment=iT;fd.jsx=Mb;fd.jsxs=Mb;Sb.exports=fd;var n=Sb.exports,Ob={exports:{}},Kn={},Db={exports:{}},_b={};/**
18
- * @license React
19
- * scheduler.production.min.js
20
- *
21
- * Copyright (c) Facebook, Inc. and its affiliates.
22
- *
23
- * This source code is licensed under the MIT license found in the
24
- * LICENSE file in the root directory of this source tree.
25
- */(function(e){function t(M,W){var D=M.length;M.push(W);e:for(;0<D;){var U=D-1>>>1,V=M[U];if(0<i(V,W))M[U]=W,M[D]=V,D=U;else break e}}function s(M){return M.length===0?null:M[0]}function r(M){if(M.length===0)return null;var W=M[0],D=M.pop();if(D!==W){M[0]=D;e:for(var U=0,V=M.length,Z=V>>>1;U<Z;){var ue=2*(U+1)-1,Ae=M[ue],X=ue+1,ae=M[X];if(0>i(Ae,D))X<V&&0>i(ae,Ae)?(M[U]=ae,M[X]=D,U=X):(M[U]=Ae,M[ue]=D,U=ue);else if(X<V&&0>i(ae,D))M[U]=ae,M[X]=D,U=X;else break e}}return W}function i(M,W){var D=M.sortIndex-W.sortIndex;return D!==0?D:M.id-W.id}if(typeof performance=="object"&&typeof performance.now=="function"){var a=performance;e.unstable_now=function(){return a.now()}}else{var l=Date,o=l.now();e.unstable_now=function(){return l.now()-o}}var c=[],u=[],h=1,d=null,m=3,p=!1,x=!1,j=!1,b=typeof setTimeout=="function"?setTimeout:null,g=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(M){for(var W=s(u);W!==null;){if(W.callback===null)r(u);else if(W.startTime<=M)r(u),W.sortIndex=W.expirationTime,t(c,W);else break;W=s(u)}}function y(M){if(j=!1,w(M),!x)if(s(c)!==null)x=!0,_(N);else{var W=s(u);W!==null&&B(y,W.startTime-M)}}function N(M,W){x=!1,j&&(j=!1,g(C),C=-1),p=!0;var D=m;try{for(w(W),d=s(c);d!==null&&(!(d.expirationTime>W)||M&&!O());){var U=d.callback;if(typeof U=="function"){d.callback=null,m=d.priorityLevel;var V=U(d.expirationTime<=W);W=e.unstable_now(),typeof V=="function"?d.callback=V:d===s(c)&&r(c),w(W)}else r(c);d=s(c)}if(d!==null)var Z=!0;else{var ue=s(u);ue!==null&&B(y,ue.startTime-W),Z=!1}return Z}finally{d=null,m=D,p=!1}}var k=!1,S=null,C=-1,I=5,A=-1;function O(){return!(e.unstable_now()-A<I)}function z(){if(S!==null){var M=e.unstable_now();A=M;var W=!0;try{W=S(!0,M)}finally{W?L():(k=!1,S=null)}}else k=!1}var L;if(typeof v=="function")L=function(){v(z)};else if(typeof MessageChannel<"u"){var E=new MessageChannel,$=E.port2;E.port1.onmessage=z,L=function(){$.postMessage(null)}}else L=function(){b(z,0)};function _(M){S=M,k||(k=!0,L())}function B(M,W){C=b(function(){M(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(M){M.callback=null},e.unstable_continueExecution=function(){x||p||(x=!0,_(N))},e.unstable_forceFrameRate=function(M){0>M||125<M?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):I=0<M?Math.floor(1e3/M):5},e.unstable_getCurrentPriorityLevel=function(){return m},e.unstable_getFirstCallbackNode=function(){return s(c)},e.unstable_next=function(M){switch(m){case 1:case 2:case 3:var W=3;break;default:W=m}var D=m;m=W;try{return M()}finally{m=D}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(M,W){switch(M){case 1:case 2:case 3:case 4:case 5:break;default:M=3}var D=m;m=M;try{return W()}finally{m=D}},e.unstable_scheduleCallback=function(M,W,D){var U=e.unstable_now();switch(typeof D=="object"&&D!==null?(D=D.delay,D=typeof D=="number"&&0<D?U+D:U):D=U,M){case 1:var V=-1;break;case 2:V=250;break;case 5:V=1073741823;break;case 4:V=1e4;break;default:V=5e3}return V=D+V,M={id:h++,callback:W,priorityLevel:M,startTime:D,expirationTime:V,sortIndex:-1},D>U?(M.sortIndex=D,t(u,M),s(c)===null&&M===s(u)&&(j?(g(C),C=-1):j=!0,B(y,D-U))):(M.sortIndex=V,t(c,M),x||p||(x=!0,_(N))),M},e.unstable_shouldYield=O,e.unstable_wrapCallback=function(M){var W=m;return function(){var D=m;m=W;try{return M.apply(this,arguments)}finally{m=D}}}})(_b);Db.exports=_b;var cT=Db.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 uT=f,Wn=cT;function re(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,s=1;s<arguments.length;s++)t+="&args[]="+encodeURIComponent(arguments[s]);return"Minified React error #"+e+"; visit "+t+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var Lb=new Set,Xl={};function Ui(e,t){Ma(e,t),Ma(e+"Capture",t)}function Ma(e,t){for(Xl[e]=t,e=0;e<t.length;e++)Lb.add(t[e])}var or=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),$f=Object.prototype.hasOwnProperty,dT=/^[: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]*$/,tj={},nj={};function hT(e){return $f.call(nj,e)?!0:$f.call(tj,e)?!1:dT.test(e)?nj[e]=!0:(tj[e]=!0,!1)}function fT(e,t,s,r){if(s!==null&&s.type===0)return!1;switch(typeof t){case"function":case"symbol":return!0;case"boolean":return r?!1:s!==null?!s.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function mT(e,t,s,r){if(t===null||typeof t>"u"||fT(e,t,s,r))return!0;if(r)return!1;if(s!==null)switch(s.type){case 3:return!t;case 4:return t===!1;case 5:return isNaN(t);case 6:return isNaN(t)||1>t}return!1}function wn(e,t,s,r,i,a,l){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=r,this.attributeNamespace=i,this.mustUseProperty=s,this.propertyName=e,this.type=t,this.sanitizeURL=a,this.removeEmptyString=l}var Xt={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){Xt[e]=new wn(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];Xt[t]=new wn(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){Xt[e]=new wn(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Xt[e]=new wn(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){Xt[e]=new wn(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){Xt[e]=new wn(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){Xt[e]=new wn(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){Xt[e]=new wn(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){Xt[e]=new wn(e,5,!1,e.toLowerCase(),null,!1,!1)});var Qp=/[\-:]([a-z])/g;function Jp(e){return e[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(e){var t=e.replace(Qp,Jp);Xt[t]=new wn(t,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var t=e.replace(Qp,Jp);Xt[t]=new wn(t,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var t=e.replace(Qp,Jp);Xt[t]=new wn(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){Xt[e]=new wn(e,1,!1,e.toLowerCase(),null,!1,!1)});Xt.xlinkHref=new wn("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){Xt[e]=new wn(e,1,!1,e.toLowerCase(),null,!0,!0)});function Xp(e,t,s,r){var i=Xt.hasOwnProperty(t)?Xt[t]:null;(i!==null?i.type!==0:r||!(2<t.length)||t[0]!=="o"&&t[0]!=="O"||t[1]!=="n"&&t[1]!=="N")&&(mT(t,s,i,r)&&(s=null),r||i===null?hT(t)&&(s===null?e.removeAttribute(t):e.setAttribute(t,""+s)):i.mustUseProperty?e[i.propertyName]=s===null?i.type===3?!1:"":s:(t=i.attributeName,r=i.attributeNamespace,s===null?e.removeAttribute(t):(i=i.type,s=i===3||i===4&&s===!0?"":""+s,r?e.setAttributeNS(r,t,s):e.setAttribute(t,s))))}var gr=uT.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,ac=Symbol.for("react.element"),oa=Symbol.for("react.portal"),ca=Symbol.for("react.fragment"),Zp=Symbol.for("react.strict_mode"),Mf=Symbol.for("react.profiler"),Fb=Symbol.for("react.provider"),zb=Symbol.for("react.context"),eg=Symbol.for("react.forward_ref"),Of=Symbol.for("react.suspense"),Df=Symbol.for("react.suspense_list"),tg=Symbol.for("react.memo"),Ar=Symbol.for("react.lazy"),Ub=Symbol.for("react.offscreen"),sj=Symbol.iterator;function vl(e){return e===null||typeof e!="object"?null:(e=sj&&e[sj]||e["@@iterator"],typeof e=="function"?e:null)}var vt=Object.assign,mh;function Pl(e){if(mh===void 0)try{throw Error()}catch(s){var t=s.stack.trim().match(/\n( *(at )?)/);mh=t&&t[1]||""}return`
34
- `+mh+e}var ph=!1;function gh(e,t){if(!e||ph)return"";ph=!0;var s=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(t)if(t=function(){throw Error()},Object.defineProperty(t.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(t,[])}catch(u){var r=u}Reflect.construct(e,[],t)}else{try{t.call()}catch(u){r=u}e.call(t.prototype)}else{try{throw Error()}catch(u){r=u}e()}}catch(u){if(u&&r&&typeof u.stack=="string"){for(var i=u.stack.split(`
35
- `),a=r.stack.split(`
36
- `),l=i.length-1,o=a.length-1;1<=l&&0<=o&&i[l]!==a[o];)o--;for(;1<=l&&0<=o;l--,o--)if(i[l]!==a[o]){if(l!==1||o!==1)do if(l--,o--,0>o||i[l]!==a[o]){var c=`
37
- `+i[l].replace(" at new "," at ");return e.displayName&&c.includes("<anonymous>")&&(c=c.replace("<anonymous>",e.displayName)),c}while(1<=l&&0<=o);break}}}finally{ph=!1,Error.prepareStackTrace=s}return(e=e?e.displayName||e.name:"")?Pl(e):""}function pT(e){switch(e.tag){case 5:return Pl(e.type);case 16:return Pl("Lazy");case 13:return Pl("Suspense");case 19:return Pl("SuspenseList");case 0:case 2:case 15:return e=gh(e.type,!1),e;case 11:return e=gh(e.type.render,!1),e;case 1:return e=gh(e.type,!0),e;default:return""}}function _f(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 ca:return"Fragment";case oa:return"Portal";case Mf:return"Profiler";case Zp:return"StrictMode";case Of:return"Suspense";case Df:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case zb:return(e.displayName||"Context")+".Consumer";case Fb:return(e._context.displayName||"Context")+".Provider";case eg:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case tg:return t=e.displayName||null,t!==null?t:_f(e.type)||"Memo";case Ar:t=e._payload,e=e._init;try{return _f(e(t))}catch{}}return null}function gT(e){var t=e.type;switch(e.tag){case 24:return"Cache";case 9:return(t.displayName||"Context")+".Consumer";case 10:return(t._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=t.render,e=e.displayName||e.name||"",t.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return t;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return _f(t);case 8:return t===Zp?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t}return null}function Qr(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function Bb(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function xT(e){var t=Bb(e)?"checked":"value",s=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=""+e[t];if(!e.hasOwnProperty(t)&&typeof s<"u"&&typeof s.get=="function"&&typeof s.set=="function"){var i=s.get,a=s.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return i.call(this)},set:function(l){r=""+l,a.call(this,l)}}),Object.defineProperty(e,t,{enumerable:s.enumerable}),{getValue:function(){return r},setValue:function(l){r=""+l},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function lc(e){e._valueTracker||(e._valueTracker=xT(e))}function Wb(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var s=t.getValue(),r="";return e&&(r=Bb(e)?e.checked?"true":"false":e.value),e=r,e!==s?(t.setValue(e),!0):!1}function ju(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 Lf(e,t){var s=t.checked;return vt({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:s??e._wrapperState.initialChecked})}function rj(e,t){var s=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;s=Qr(t.value!=null?t.value:s),e._wrapperState={initialChecked:r,initialValue:s,controlled:t.type==="checkbox"||t.type==="radio"?t.checked!=null:t.value!=null}}function Hb(e,t){t=t.checked,t!=null&&Xp(e,"checked",t,!1)}function Ff(e,t){Hb(e,t);var s=Qr(t.value),r=t.type;if(s!=null)r==="number"?(s===0&&e.value===""||e.value!=s)&&(e.value=""+s):e.value!==""+s&&(e.value=""+s);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}t.hasOwnProperty("value")?zf(e,t.type,s):t.hasOwnProperty("defaultValue")&&zf(e,t.type,Qr(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function ij(e,t,s){if(t.hasOwnProperty("value")||t.hasOwnProperty("defaultValue")){var r=t.type;if(!(r!=="submit"&&r!=="reset"||t.value!==void 0&&t.value!==null))return;t=""+e._wrapperState.initialValue,s||t===e.value||(e.value=t),e.defaultValue=t}s=e.name,s!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,s!==""&&(e.name=s)}function zf(e,t,s){(t!=="number"||ju(e.ownerDocument)!==e)&&(s==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+s&&(e.defaultValue=""+s))}var $l=Array.isArray;function ba(e,t,s,r){if(e=e.options,t){t={};for(var i=0;i<s.length;i++)t["$"+s[i]]=!0;for(s=0;s<e.length;s++)i=t.hasOwnProperty("$"+e[s].value),e[s].selected!==i&&(e[s].selected=i),i&&r&&(e[s].defaultSelected=!0)}else{for(s=""+Qr(s),t=null,i=0;i<e.length;i++){if(e[i].value===s){e[i].selected=!0,r&&(e[i].defaultSelected=!0);return}t!==null||e[i].disabled||(t=e[i])}t!==null&&(t.selected=!0)}}function Uf(e,t){if(t.dangerouslySetInnerHTML!=null)throw Error(re(91));return vt({},t,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function aj(e,t){var s=t.value;if(s==null){if(s=t.children,t=t.defaultValue,s!=null){if(t!=null)throw Error(re(92));if($l(s)){if(1<s.length)throw Error(re(93));s=s[0]}t=s}t==null&&(t=""),s=t}e._wrapperState={initialValue:Qr(s)}}function Kb(e,t){var s=Qr(t.value),r=Qr(t.defaultValue);s!=null&&(s=""+s,s!==e.value&&(e.value=s),t.defaultValue==null&&e.defaultValue!==s&&(e.defaultValue=s)),r!=null&&(e.defaultValue=""+r)}function lj(e){var t=e.textContent;t===e._wrapperState.initialValue&&t!==""&&t!==null&&(e.value=t)}function Vb(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 Bf(e,t){return e==null||e==="http://www.w3.org/1999/xhtml"?Vb(t):e==="http://www.w3.org/2000/svg"&&t==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var oc,Gb=function(e){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(t,s,r,i){MSApp.execUnsafeLocalFunction(function(){return e(t,s,r,i)})}:e}(function(e,t){if(e.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in e)e.innerHTML=t;else{for(oc=oc||document.createElement("div"),oc.innerHTML="<svg>"+t.valueOf().toString()+"</svg>",t=oc.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Zl(e,t){if(t){var s=e.firstChild;if(s&&s===e.lastChild&&s.nodeType===3){s.nodeValue=t;return}}e.textContent=t}var Ll={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},vT=["Webkit","ms","Moz","O"];Object.keys(Ll).forEach(function(e){vT.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Ll[t]=Ll[e]})});function Yb(e,t,s){return t==null||typeof t=="boolean"||t===""?"":s||typeof t!="number"||t===0||Ll.hasOwnProperty(e)&&Ll[e]?(""+t).trim():t+"px"}function qb(e,t){e=e.style;for(var s in t)if(t.hasOwnProperty(s)){var r=s.indexOf("--")===0,i=Yb(s,t[s],r);s==="float"&&(s="cssFloat"),r?e.setProperty(s,i):e[s]=i}}var jT=vt({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 Wf(e,t){if(t){if(jT[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(re(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(re(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(re(61))}if(t.style!=null&&typeof t.style!="object")throw Error(re(62))}}function Hf(e,t){if(e.indexOf("-")===-1)return typeof t.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var Kf=null;function ng(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Vf=null,ka=null,Sa=null;function oj(e){if(e=_o(e)){if(typeof Vf!="function")throw Error(re(280));var t=e.stateNode;t&&(t=vd(t),Vf(e.stateNode,e.type,t))}}function Qb(e){ka?Sa?Sa.push(e):Sa=[e]:ka=e}function Jb(){if(ka){var e=ka,t=Sa;if(Sa=ka=null,oj(e),t)for(e=0;e<t.length;e++)oj(t[e])}}function Xb(e,t){return e(t)}function Zb(){}var xh=!1;function e0(e,t,s){if(xh)return e(t,s);xh=!0;try{return Xb(e,t,s)}finally{xh=!1,(ka!==null||Sa!==null)&&(Zb(),Jb())}}function eo(e,t){var s=e.stateNode;if(s===null)return null;var r=vd(s);if(r===null)return null;s=r[t];e:switch(t){case"onClick":case"onClickCapture":case"onDoubleClick":case"onDoubleClickCapture":case"onMouseDown":case"onMouseDownCapture":case"onMouseMove":case"onMouseMoveCapture":case"onMouseUp":case"onMouseUpCapture":case"onMouseEnter":(r=!r.disabled)||(e=e.type,r=!(e==="button"||e==="input"||e==="select"||e==="textarea")),e=!r;break e;default:e=!1}if(e)return null;if(s&&typeof s!="function")throw Error(re(231,t,typeof s));return s}var Gf=!1;if(or)try{var jl={};Object.defineProperty(jl,"passive",{get:function(){Gf=!0}}),window.addEventListener("test",jl,jl),window.removeEventListener("test",jl,jl)}catch{Gf=!1}function wT(e,t,s,r,i,a,l,o,c){var u=Array.prototype.slice.call(arguments,3);try{t.apply(s,u)}catch(h){this.onError(h)}}var Fl=!1,wu=null,yu=!1,Yf=null,yT={onError:function(e){Fl=!0,wu=e}};function bT(e,t,s,r,i,a,l,o,c){Fl=!1,wu=null,wT.apply(yT,arguments)}function kT(e,t,s,r,i,a,l,o,c){if(bT.apply(this,arguments),Fl){if(Fl){var u=wu;Fl=!1,wu=null}else throw Error(re(198));yu||(yu=!0,Yf=u)}}function Bi(e){var t=e,s=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(s=t.return),e=t.return;while(e)}return t.tag===3?s:null}function t0(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function cj(e){if(Bi(e)!==e)throw Error(re(188))}function ST(e){var t=e.alternate;if(!t){if(t=Bi(e),t===null)throw Error(re(188));return t!==e?null:e}for(var s=e,r=t;;){var i=s.return;if(i===null)break;var a=i.alternate;if(a===null){if(r=i.return,r!==null){s=r;continue}break}if(i.child===a.child){for(a=i.child;a;){if(a===s)return cj(i),e;if(a===r)return cj(i),t;a=a.sibling}throw Error(re(188))}if(s.return!==r.return)s=i,r=a;else{for(var l=!1,o=i.child;o;){if(o===s){l=!0,s=i,r=a;break}if(o===r){l=!0,r=i,s=a;break}o=o.sibling}if(!l){for(o=a.child;o;){if(o===s){l=!0,s=a,r=i;break}if(o===r){l=!0,r=a,s=i;break}o=o.sibling}if(!l)throw Error(re(189))}}if(s.alternate!==r)throw Error(re(190))}if(s.tag!==3)throw Error(re(188));return s.stateNode.current===s?e:t}function n0(e){return e=ST(e),e!==null?s0(e):null}function s0(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var t=s0(e);if(t!==null)return t;e=e.sibling}return null}var r0=Wn.unstable_scheduleCallback,uj=Wn.unstable_cancelCallback,NT=Wn.unstable_shouldYield,CT=Wn.unstable_requestPaint,Et=Wn.unstable_now,ET=Wn.unstable_getCurrentPriorityLevel,sg=Wn.unstable_ImmediatePriority,i0=Wn.unstable_UserBlockingPriority,bu=Wn.unstable_NormalPriority,AT=Wn.unstable_LowPriority,a0=Wn.unstable_IdlePriority,md=null,zs=null;function TT(e){if(zs&&typeof zs.onCommitFiberRoot=="function")try{zs.onCommitFiberRoot(md,e,void 0,(e.current.flags&128)===128)}catch{}}var gs=Math.clz32?Math.clz32:PT,RT=Math.log,IT=Math.LN2;function PT(e){return e>>>=0,e===0?32:31-(RT(e)/IT|0)|0}var cc=64,uc=4194304;function Ml(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 ku(e,t){var s=e.pendingLanes;if(s===0)return 0;var r=0,i=e.suspendedLanes,a=e.pingedLanes,l=s&268435455;if(l!==0){var o=l&~i;o!==0?r=Ml(o):(a&=l,a!==0&&(r=Ml(a)))}else l=s&~i,l!==0?r=Ml(l):a!==0&&(r=Ml(a));if(r===0)return 0;if(t!==0&&t!==r&&!(t&i)&&(i=r&-r,a=t&-t,i>=a||i===16&&(a&4194240)!==0))return t;if(r&4&&(r|=s&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=r;0<t;)s=31-gs(t),i=1<<s,r|=e[s],t&=~i;return r}function $T(e,t){switch(e){case 1:case 2:case 4:return t+250;case 8:case 16:case 32:case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return t+5e3;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return-1;case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function MT(e,t){for(var s=e.suspendedLanes,r=e.pingedLanes,i=e.expirationTimes,a=e.pendingLanes;0<a;){var l=31-gs(a),o=1<<l,c=i[l];c===-1?(!(o&s)||o&r)&&(i[l]=$T(o,t)):c<=t&&(e.expiredLanes|=o),a&=~o}}function qf(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function l0(){var e=cc;return cc<<=1,!(cc&4194240)&&(cc=64),e}function vh(e){for(var t=[],s=0;31>s;s++)t.push(e);return t}function Oo(e,t,s){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-gs(t),e[t]=s}function OT(e,t){var s=e.pendingLanes&~t;e.pendingLanes=t,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=t,e.mutableReadLanes&=t,e.entangledLanes&=t,t=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0<s;){var i=31-gs(s),a=1<<i;t[i]=0,r[i]=-1,e[i]=-1,s&=~a}}function rg(e,t){var s=e.entangledLanes|=t;for(e=e.entanglements;s;){var r=31-gs(s),i=1<<r;i&t|e[r]&t&&(e[r]|=t),s&=~i}}var Xe=0;function o0(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var c0,ig,u0,d0,h0,Qf=!1,dc=[],_r=null,Lr=null,Fr=null,to=new Map,no=new Map,Rr=[],DT="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 dj(e,t){switch(e){case"focusin":case"focusout":_r=null;break;case"dragenter":case"dragleave":Lr=null;break;case"mouseover":case"mouseout":Fr=null;break;case"pointerover":case"pointerout":to.delete(t.pointerId);break;case"gotpointercapture":case"lostpointercapture":no.delete(t.pointerId)}}function wl(e,t,s,r,i,a){return e===null||e.nativeEvent!==a?(e={blockedOn:t,domEventName:s,eventSystemFlags:r,nativeEvent:a,targetContainers:[i]},t!==null&&(t=_o(t),t!==null&&ig(t)),e):(e.eventSystemFlags|=r,t=e.targetContainers,i!==null&&t.indexOf(i)===-1&&t.push(i),e)}function _T(e,t,s,r,i){switch(t){case"focusin":return _r=wl(_r,e,t,s,r,i),!0;case"dragenter":return Lr=wl(Lr,e,t,s,r,i),!0;case"mouseover":return Fr=wl(Fr,e,t,s,r,i),!0;case"pointerover":var a=i.pointerId;return to.set(a,wl(to.get(a)||null,e,t,s,r,i)),!0;case"gotpointercapture":return a=i.pointerId,no.set(a,wl(no.get(a)||null,e,t,s,r,i)),!0}return!1}function f0(e){var t=bi(e.target);if(t!==null){var s=Bi(t);if(s!==null){if(t=s.tag,t===13){if(t=t0(s),t!==null){e.blockedOn=t,h0(e.priority,function(){u0(s)});return}}else if(t===3&&s.stateNode.current.memoizedState.isDehydrated){e.blockedOn=s.tag===3?s.stateNode.containerInfo:null;return}}}e.blockedOn=null}function Qc(e){if(e.blockedOn!==null)return!1;for(var t=e.targetContainers;0<t.length;){var s=Jf(e.domEventName,e.eventSystemFlags,t[0],e.nativeEvent);if(s===null){s=e.nativeEvent;var r=new s.constructor(s.type,s);Kf=r,s.target.dispatchEvent(r),Kf=null}else return t=_o(s),t!==null&&ig(t),e.blockedOn=s,!1;t.shift()}return!0}function hj(e,t,s){Qc(e)&&s.delete(t)}function LT(){Qf=!1,_r!==null&&Qc(_r)&&(_r=null),Lr!==null&&Qc(Lr)&&(Lr=null),Fr!==null&&Qc(Fr)&&(Fr=null),to.forEach(hj),no.forEach(hj)}function yl(e,t){e.blockedOn===t&&(e.blockedOn=null,Qf||(Qf=!0,Wn.unstable_scheduleCallback(Wn.unstable_NormalPriority,LT)))}function so(e){function t(i){return yl(i,e)}if(0<dc.length){yl(dc[0],e);for(var s=1;s<dc.length;s++){var r=dc[s];r.blockedOn===e&&(r.blockedOn=null)}}for(_r!==null&&yl(_r,e),Lr!==null&&yl(Lr,e),Fr!==null&&yl(Fr,e),to.forEach(t),no.forEach(t),s=0;s<Rr.length;s++)r=Rr[s],r.blockedOn===e&&(r.blockedOn=null);for(;0<Rr.length&&(s=Rr[0],s.blockedOn===null);)f0(s),s.blockedOn===null&&Rr.shift()}var Na=gr.ReactCurrentBatchConfig,Su=!0;function FT(e,t,s,r){var i=Xe,a=Na.transition;Na.transition=null;try{Xe=1,ag(e,t,s,r)}finally{Xe=i,Na.transition=a}}function zT(e,t,s,r){var i=Xe,a=Na.transition;Na.transition=null;try{Xe=4,ag(e,t,s,r)}finally{Xe=i,Na.transition=a}}function ag(e,t,s,r){if(Su){var i=Jf(e,t,s,r);if(i===null)Ah(e,t,r,Nu,s),dj(e,r);else if(_T(i,e,t,s,r))r.stopPropagation();else if(dj(e,r),t&4&&-1<DT.indexOf(e)){for(;i!==null;){var a=_o(i);if(a!==null&&c0(a),a=Jf(e,t,s,r),a===null&&Ah(e,t,r,Nu,s),a===i)break;i=a}i!==null&&r.stopPropagation()}else Ah(e,t,r,null,s)}}var Nu=null;function Jf(e,t,s,r){if(Nu=null,e=ng(r),e=bi(e),e!==null)if(t=Bi(e),t===null)e=null;else if(s=t.tag,s===13){if(e=t0(t),e!==null)return e;e=null}else if(s===3){if(t.stateNode.current.memoizedState.isDehydrated)return t.tag===3?t.stateNode.containerInfo:null;e=null}else t!==e&&(e=null);return Nu=e,null}function m0(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(ET()){case sg:return 1;case i0:return 4;case bu:case AT:return 16;case a0:return 536870912;default:return 16}default:return 16}}var Pr=null,lg=null,Jc=null;function p0(){if(Jc)return Jc;var e,t=lg,s=t.length,r,i="value"in Pr?Pr.value:Pr.textContent,a=i.length;for(e=0;e<s&&t[e]===i[e];e++);var l=s-e;for(r=1;r<=l&&t[s-r]===i[a-r];r++);return Jc=i.slice(e,1<r?1-r:void 0)}function Xc(e){var t=e.keyCode;return"charCode"in e?(e=e.charCode,e===0&&t===13&&(e=13)):e=t,e===10&&(e=13),32<=e||e===13?e:0}function hc(){return!0}function fj(){return!1}function Vn(e){function t(s,r,i,a,l){this._reactName=s,this._targetInst=i,this.type=r,this.nativeEvent=a,this.target=l,this.currentTarget=null;for(var o in e)e.hasOwnProperty(o)&&(s=e[o],this[o]=s?s(a):a[o]);return this.isDefaultPrevented=(a.defaultPrevented!=null?a.defaultPrevented:a.returnValue===!1)?hc:fj,this.isPropagationStopped=fj,this}return vt(t.prototype,{preventDefault:function(){this.defaultPrevented=!0;var s=this.nativeEvent;s&&(s.preventDefault?s.preventDefault():typeof s.returnValue!="unknown"&&(s.returnValue=!1),this.isDefaultPrevented=hc)},stopPropagation:function(){var s=this.nativeEvent;s&&(s.stopPropagation?s.stopPropagation():typeof s.cancelBubble!="unknown"&&(s.cancelBubble=!0),this.isPropagationStopped=hc)},persist:function(){},isPersistent:hc}),t}var Za={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},og=Vn(Za),Do=vt({},Za,{view:0,detail:0}),UT=Vn(Do),jh,wh,bl,pd=vt({},Do,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:cg,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!==bl&&(bl&&e.type==="mousemove"?(jh=e.screenX-bl.screenX,wh=e.screenY-bl.screenY):wh=jh=0,bl=e),jh)},movementY:function(e){return"movementY"in e?e.movementY:wh}}),mj=Vn(pd),BT=vt({},pd,{dataTransfer:0}),WT=Vn(BT),HT=vt({},Do,{relatedTarget:0}),yh=Vn(HT),KT=vt({},Za,{animationName:0,elapsedTime:0,pseudoElement:0}),VT=Vn(KT),GT=vt({},Za,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),YT=Vn(GT),qT=vt({},Za,{data:0}),pj=Vn(qT),QT={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},JT={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"},XT={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function ZT(e){var t=this.nativeEvent;return t.getModifierState?t.getModifierState(e):(e=XT[e])?!!t[e]:!1}function cg(){return ZT}var eR=vt({},Do,{key:function(e){if(e.key){var t=QT[e.key]||e.key;if(t!=="Unidentified")return t}return e.type==="keypress"?(e=Xc(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?JT[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:cg,charCode:function(e){return e.type==="keypress"?Xc(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?Xc(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),tR=Vn(eR),nR=vt({},pd,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),gj=Vn(nR),sR=vt({},Do,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:cg}),rR=Vn(sR),iR=vt({},Za,{propertyName:0,elapsedTime:0,pseudoElement:0}),aR=Vn(iR),lR=vt({},pd,{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}),oR=Vn(lR),cR=[9,13,27,32],ug=or&&"CompositionEvent"in window,zl=null;or&&"documentMode"in document&&(zl=document.documentMode);var uR=or&&"TextEvent"in window&&!zl,g0=or&&(!ug||zl&&8<zl&&11>=zl),xj=" ",vj=!1;function x0(e,t){switch(e){case"keyup":return cR.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function v0(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var ua=!1;function dR(e,t){switch(e){case"compositionend":return v0(t);case"keypress":return t.which!==32?null:(vj=!0,xj);case"textInput":return e=t.data,e===xj&&vj?null:e;default:return null}}function hR(e,t){if(ua)return e==="compositionend"||!ug&&x0(e,t)?(e=p0(),Jc=lg=Pr=null,ua=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1<t.char.length)return t.char;if(t.which)return String.fromCharCode(t.which)}return null;case"compositionend":return g0&&t.locale!=="ko"?null:t.data;default:return null}}var fR={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 jj(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t==="input"?!!fR[e.type]:t==="textarea"}function j0(e,t,s,r){Qb(r),t=Cu(t,"onChange"),0<t.length&&(s=new og("onChange","change",null,s,r),e.push({event:s,listeners:t}))}var Ul=null,ro=null;function mR(e){R0(e,0)}function gd(e){var t=fa(e);if(Wb(t))return e}function pR(e,t){if(e==="change")return t}var w0=!1;if(or){var bh;if(or){var kh="oninput"in document;if(!kh){var wj=document.createElement("div");wj.setAttribute("oninput","return;"),kh=typeof wj.oninput=="function"}bh=kh}else bh=!1;w0=bh&&(!document.documentMode||9<document.documentMode)}function yj(){Ul&&(Ul.detachEvent("onpropertychange",y0),ro=Ul=null)}function y0(e){if(e.propertyName==="value"&&gd(ro)){var t=[];j0(t,ro,e,ng(e)),e0(mR,t)}}function gR(e,t,s){e==="focusin"?(yj(),Ul=t,ro=s,Ul.attachEvent("onpropertychange",y0)):e==="focusout"&&yj()}function xR(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return gd(ro)}function vR(e,t){if(e==="click")return gd(t)}function jR(e,t){if(e==="input"||e==="change")return gd(t)}function wR(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var ys=typeof Object.is=="function"?Object.is:wR;function io(e,t){if(ys(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;var s=Object.keys(e),r=Object.keys(t);if(s.length!==r.length)return!1;for(r=0;r<s.length;r++){var i=s[r];if(!$f.call(t,i)||!ys(e[i],t[i]))return!1}return!0}function bj(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function kj(e,t){var s=bj(e);e=0;for(var r;s;){if(s.nodeType===3){if(r=e+s.textContent.length,e<=t&&r>=t)return{node:s,offset:t-e};e=r}e:{for(;s;){if(s.nextSibling){s=s.nextSibling;break e}s=s.parentNode}s=void 0}s=bj(s)}}function b0(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?b0(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function k0(){for(var e=window,t=ju();t instanceof e.HTMLIFrameElement;){try{var s=typeof t.contentWindow.location.href=="string"}catch{s=!1}if(s)e=t.contentWindow;else break;t=ju(e.document)}return t}function dg(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||t==="textarea"||e.contentEditable==="true")}function yR(e){var t=k0(),s=e.focusedElem,r=e.selectionRange;if(t!==s&&s&&s.ownerDocument&&b0(s.ownerDocument.documentElement,s)){if(r!==null&&dg(s)){if(t=r.start,e=r.end,e===void 0&&(e=t),"selectionStart"in s)s.selectionStart=t,s.selectionEnd=Math.min(e,s.value.length);else if(e=(t=s.ownerDocument||document)&&t.defaultView||window,e.getSelection){e=e.getSelection();var i=s.textContent.length,a=Math.min(r.start,i);r=r.end===void 0?a:Math.min(r.end,i),!e.extend&&a>r&&(i=r,r=a,a=i),i=kj(s,a);var l=kj(s,r);i&&l&&(e.rangeCount!==1||e.anchorNode!==i.node||e.anchorOffset!==i.offset||e.focusNode!==l.node||e.focusOffset!==l.offset)&&(t=t.createRange(),t.setStart(i.node,i.offset),e.removeAllRanges(),a>r?(e.addRange(t),e.extend(l.node,l.offset)):(t.setEnd(l.node,l.offset),e.addRange(t)))}}for(t=[],e=s;e=e.parentNode;)e.nodeType===1&&t.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof s.focus=="function"&&s.focus(),s=0;s<t.length;s++)e=t[s],e.element.scrollLeft=e.left,e.element.scrollTop=e.top}}var bR=or&&"documentMode"in document&&11>=document.documentMode,da=null,Xf=null,Bl=null,Zf=!1;function Sj(e,t,s){var r=s.window===s?s.document:s.nodeType===9?s:s.ownerDocument;Zf||da==null||da!==ju(r)||(r=da,"selectionStart"in r&&dg(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}),Bl&&io(Bl,r)||(Bl=r,r=Cu(Xf,"onSelect"),0<r.length&&(t=new og("onSelect","select",null,t,s),e.push({event:t,listeners:r}),t.target=da)))}function fc(e,t){var s={};return s[e.toLowerCase()]=t.toLowerCase(),s["Webkit"+e]="webkit"+t,s["Moz"+e]="moz"+t,s}var ha={animationend:fc("Animation","AnimationEnd"),animationiteration:fc("Animation","AnimationIteration"),animationstart:fc("Animation","AnimationStart"),transitionend:fc("Transition","TransitionEnd")},Sh={},S0={};or&&(S0=document.createElement("div").style,"AnimationEvent"in window||(delete ha.animationend.animation,delete ha.animationiteration.animation,delete ha.animationstart.animation),"TransitionEvent"in window||delete ha.transitionend.transition);function xd(e){if(Sh[e])return Sh[e];if(!ha[e])return e;var t=ha[e],s;for(s in t)if(t.hasOwnProperty(s)&&s in S0)return Sh[e]=t[s];return e}var N0=xd("animationend"),C0=xd("animationiteration"),E0=xd("animationstart"),A0=xd("transitionend"),T0=new Map,Nj="abort auxClick cancel canPlay canPlayThrough click close contextMenu copy cut drag dragEnd dragEnter dragExit dragLeave dragOver dragStart drop durationChange emptied encrypted ended error gotPointerCapture input invalid keyDown keyPress keyUp load loadedData loadedMetadata loadStart lostPointerCapture mouseDown mouseMove mouseOut mouseOver mouseUp paste pause play playing pointerCancel pointerDown pointerMove pointerOut pointerOver pointerUp progress rateChange reset resize seeked seeking stalled submit suspend timeUpdate touchCancel touchEnd touchStart volumeChange scroll toggle touchMove waiting wheel".split(" ");function ii(e,t){T0.set(e,t),Ui(t,[e])}for(var Nh=0;Nh<Nj.length;Nh++){var Ch=Nj[Nh],kR=Ch.toLowerCase(),SR=Ch[0].toUpperCase()+Ch.slice(1);ii(kR,"on"+SR)}ii(N0,"onAnimationEnd");ii(C0,"onAnimationIteration");ii(E0,"onAnimationStart");ii("dblclick","onDoubleClick");ii("focusin","onFocus");ii("focusout","onBlur");ii(A0,"onTransitionEnd");Ma("onMouseEnter",["mouseout","mouseover"]);Ma("onMouseLeave",["mouseout","mouseover"]);Ma("onPointerEnter",["pointerout","pointerover"]);Ma("onPointerLeave",["pointerout","pointerover"]);Ui("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));Ui("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));Ui("onBeforeInput",["compositionend","keypress","textInput","paste"]);Ui("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));Ui("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));Ui("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var Ol="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(" "),NR=new Set("cancel close invalid load scroll toggle".split(" ").concat(Ol));function Cj(e,t,s){var r=e.type||"unknown-event";e.currentTarget=s,kT(r,t,void 0,e),e.currentTarget=null}function R0(e,t){t=(t&4)!==0;for(var s=0;s<e.length;s++){var r=e[s],i=r.event;r=r.listeners;e:{var a=void 0;if(t)for(var l=r.length-1;0<=l;l--){var o=r[l],c=o.instance,u=o.currentTarget;if(o=o.listener,c!==a&&i.isPropagationStopped())break e;Cj(i,o,u),a=c}else for(l=0;l<r.length;l++){if(o=r[l],c=o.instance,u=o.currentTarget,o=o.listener,c!==a&&i.isPropagationStopped())break e;Cj(i,o,u),a=c}}}if(yu)throw e=Yf,yu=!1,Yf=null,e}function lt(e,t){var s=t[rm];s===void 0&&(s=t[rm]=new Set);var r=e+"__bubble";s.has(r)||(I0(t,e,2,!1),s.add(r))}function Eh(e,t,s){var r=0;t&&(r|=4),I0(s,e,r,t)}var mc="_reactListening"+Math.random().toString(36).slice(2);function ao(e){if(!e[mc]){e[mc]=!0,Lb.forEach(function(s){s!=="selectionchange"&&(NR.has(s)||Eh(s,!1,e),Eh(s,!0,e))});var t=e.nodeType===9?e:e.ownerDocument;t===null||t[mc]||(t[mc]=!0,Eh("selectionchange",!1,t))}}function I0(e,t,s,r){switch(m0(t)){case 1:var i=FT;break;case 4:i=zT;break;default:i=ag}s=i.bind(null,t,s,e),i=void 0,!Gf||t!=="touchstart"&&t!=="touchmove"&&t!=="wheel"||(i=!0),r?i!==void 0?e.addEventListener(t,s,{capture:!0,passive:i}):e.addEventListener(t,s,!0):i!==void 0?e.addEventListener(t,s,{passive:i}):e.addEventListener(t,s,!1)}function Ah(e,t,s,r,i){var a=r;if(!(t&1)&&!(t&2)&&r!==null)e:for(;;){if(r===null)return;var l=r.tag;if(l===3||l===4){var o=r.stateNode.containerInfo;if(o===i||o.nodeType===8&&o.parentNode===i)break;if(l===4)for(l=r.return;l!==null;){var c=l.tag;if((c===3||c===4)&&(c=l.stateNode.containerInfo,c===i||c.nodeType===8&&c.parentNode===i))return;l=l.return}for(;o!==null;){if(l=bi(o),l===null)return;if(c=l.tag,c===5||c===6){r=a=l;continue e}o=o.parentNode}}r=r.return}e0(function(){var u=a,h=ng(s),d=[];e:{var m=T0.get(e);if(m!==void 0){var p=og,x=e;switch(e){case"keypress":if(Xc(s)===0)break e;case"keydown":case"keyup":p=tR;break;case"focusin":x="focus",p=yh;break;case"focusout":x="blur",p=yh;break;case"beforeblur":case"afterblur":p=yh;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=mj;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":p=WT;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":p=rR;break;case N0:case C0:case E0:p=VT;break;case A0:p=aR;break;case"scroll":p=UT;break;case"wheel":p=oR;break;case"copy":case"cut":case"paste":p=YT;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":p=gj}var j=(t&4)!==0,b=!j&&e==="scroll",g=j?m!==null?m+"Capture":null:m;j=[];for(var v=u,w;v!==null;){w=v;var y=w.stateNode;if(w.tag===5&&y!==null&&(w=y,g!==null&&(y=eo(v,g),y!=null&&j.push(lo(v,y,w)))),b)break;v=v.return}0<j.length&&(m=new p(m,x,null,s,h),d.push({event:m,listeners:j}))}}if(!(t&7)){e:{if(m=e==="mouseover"||e==="pointerover",p=e==="mouseout"||e==="pointerout",m&&s!==Kf&&(x=s.relatedTarget||s.fromElement)&&(bi(x)||x[cr]))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=u,x=x?bi(x):null,x!==null&&(b=Bi(x),x!==b||x.tag!==5&&x.tag!==6)&&(x=null)):(p=null,x=u),p!==x)){if(j=mj,y="onMouseLeave",g="onMouseEnter",v="mouse",(e==="pointerout"||e==="pointerover")&&(j=gj,y="onPointerLeave",g="onPointerEnter",v="pointer"),b=p==null?m:fa(p),w=x==null?m:fa(x),m=new j(y,v+"leave",p,s,h),m.target=b,m.relatedTarget=w,y=null,bi(h)===u&&(j=new j(g,v+"enter",x,s,h),j.target=w,j.relatedTarget=b,y=j),b=y,p&&x)t:{for(j=p,g=x,v=0,w=j;w;w=Zi(w))v++;for(w=0,y=g;y;y=Zi(y))w++;for(;0<v-w;)j=Zi(j),v--;for(;0<w-v;)g=Zi(g),w--;for(;v--;){if(j===g||g!==null&&j===g.alternate)break t;j=Zi(j),g=Zi(g)}j=null}else j=null;p!==null&&Ej(d,m,p,j,!1),x!==null&&b!==null&&Ej(d,b,x,j,!0)}}e:{if(m=u?fa(u):window,p=m.nodeName&&m.nodeName.toLowerCase(),p==="select"||p==="input"&&m.type==="file")var N=pR;else if(jj(m))if(w0)N=jR;else{N=xR;var k=gR}else(p=m.nodeName)&&p.toLowerCase()==="input"&&(m.type==="checkbox"||m.type==="radio")&&(N=vR);if(N&&(N=N(e,u))){j0(d,N,s,h);break e}k&&k(e,m,u),e==="focusout"&&(k=m._wrapperState)&&k.controlled&&m.type==="number"&&zf(m,"number",m.value)}switch(k=u?fa(u):window,e){case"focusin":(jj(k)||k.contentEditable==="true")&&(da=k,Xf=u,Bl=null);break;case"focusout":Bl=Xf=da=null;break;case"mousedown":Zf=!0;break;case"contextmenu":case"mouseup":case"dragend":Zf=!1,Sj(d,s,h);break;case"selectionchange":if(bR)break;case"keydown":case"keyup":Sj(d,s,h)}var S;if(ug)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 ua?x0(e,s)&&(C="onCompositionEnd"):e==="keydown"&&s.keyCode===229&&(C="onCompositionStart");C&&(g0&&s.locale!=="ko"&&(ua||C!=="onCompositionStart"?C==="onCompositionEnd"&&ua&&(S=p0()):(Pr=h,lg="value"in Pr?Pr.value:Pr.textContent,ua=!0)),k=Cu(u,C),0<k.length&&(C=new pj(C,e,null,s,h),d.push({event:C,listeners:k}),S?C.data=S:(S=v0(s),S!==null&&(C.data=S)))),(S=uR?dR(e,s):hR(e,s))&&(u=Cu(u,"onBeforeInput"),0<u.length&&(h=new pj("onBeforeInput","beforeinput",null,s,h),d.push({event:h,listeners:u}),h.data=S))}R0(d,t)})}function lo(e,t,s){return{instance:e,listener:t,currentTarget:s}}function Cu(e,t){for(var s=t+"Capture",r=[];e!==null;){var i=e,a=i.stateNode;i.tag===5&&a!==null&&(i=a,a=eo(e,s),a!=null&&r.unshift(lo(e,a,i)),a=eo(e,t),a!=null&&r.push(lo(e,a,i))),e=e.return}return r}function Zi(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function Ej(e,t,s,r,i){for(var a=t._reactName,l=[];s!==null&&s!==r;){var o=s,c=o.alternate,u=o.stateNode;if(c!==null&&c===r)break;o.tag===5&&u!==null&&(o=u,i?(c=eo(s,a),c!=null&&l.unshift(lo(s,c,o))):i||(c=eo(s,a),c!=null&&l.push(lo(s,c,o)))),s=s.return}l.length!==0&&e.push({event:t,listeners:l})}var CR=/\r\n?/g,ER=/\u0000|\uFFFD/g;function Aj(e){return(typeof e=="string"?e:""+e).replace(CR,`
38
- `).replace(ER,"")}function pc(e,t,s){if(t=Aj(t),Aj(e)!==t&&s)throw Error(re(425))}function Eu(){}var em=null,tm=null;function nm(e,t){return e==="textarea"||e==="noscript"||typeof t.children=="string"||typeof t.children=="number"||typeof t.dangerouslySetInnerHTML=="object"&&t.dangerouslySetInnerHTML!==null&&t.dangerouslySetInnerHTML.__html!=null}var sm=typeof setTimeout=="function"?setTimeout:void 0,AR=typeof clearTimeout=="function"?clearTimeout:void 0,Tj=typeof Promise=="function"?Promise:void 0,TR=typeof queueMicrotask=="function"?queueMicrotask:typeof Tj<"u"?function(e){return Tj.resolve(null).then(e).catch(RR)}:sm;function RR(e){setTimeout(function(){throw e})}function Th(e,t){var s=t,r=0;do{var i=s.nextSibling;if(e.removeChild(s),i&&i.nodeType===8)if(s=i.data,s==="/$"){if(r===0){e.removeChild(i),so(t);return}r--}else s!=="$"&&s!=="$?"&&s!=="$!"||r++;s=i}while(s);so(t)}function zr(e){for(;e!=null;e=e.nextSibling){var t=e.nodeType;if(t===1||t===3)break;if(t===8){if(t=e.data,t==="$"||t==="$!"||t==="$?")break;if(t==="/$")return null}}return e}function Rj(e){e=e.previousSibling;for(var t=0;e;){if(e.nodeType===8){var s=e.data;if(s==="$"||s==="$!"||s==="$?"){if(t===0)return e;t--}else s==="/$"&&t++}e=e.previousSibling}return null}var el=Math.random().toString(36).slice(2),Ds="__reactFiber$"+el,oo="__reactProps$"+el,cr="__reactContainer$"+el,rm="__reactEvents$"+el,IR="__reactListeners$"+el,PR="__reactHandles$"+el;function bi(e){var t=e[Ds];if(t)return t;for(var s=e.parentNode;s;){if(t=s[cr]||s[Ds]){if(s=t.alternate,t.child!==null||s!==null&&s.child!==null)for(e=Rj(e);e!==null;){if(s=e[Ds])return s;e=Rj(e)}return t}e=s,s=e.parentNode}return null}function _o(e){return e=e[Ds]||e[cr],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function fa(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(re(33))}function vd(e){return e[oo]||null}var im=[],ma=-1;function ai(e){return{current:e}}function ot(e){0>ma||(e.current=im[ma],im[ma]=null,ma--)}function rt(e,t){ma++,im[ma]=e.current,e.current=t}var Jr={},fn=ai(Jr),Cn=ai(!1),Ri=Jr;function Oa(e,t){var s=e.type.contextTypes;if(!s)return Jr;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var i={},a;for(a in s)i[a]=t[a];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=i),i}function En(e){return e=e.childContextTypes,e!=null}function Au(){ot(Cn),ot(fn)}function Ij(e,t,s){if(fn.current!==Jr)throw Error(re(168));rt(fn,t),rt(Cn,s)}function P0(e,t,s){var r=e.stateNode;if(t=t.childContextTypes,typeof r.getChildContext!="function")return s;r=r.getChildContext();for(var i in r)if(!(i in t))throw Error(re(108,gT(e)||"Unknown",i));return vt({},s,r)}function Tu(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Jr,Ri=fn.current,rt(fn,e),rt(Cn,Cn.current),!0}function Pj(e,t,s){var r=e.stateNode;if(!r)throw Error(re(169));s?(e=P0(e,t,Ri),r.__reactInternalMemoizedMergedChildContext=e,ot(Cn),ot(fn),rt(fn,e)):ot(Cn),rt(Cn,s)}var er=null,jd=!1,Rh=!1;function $0(e){er===null?er=[e]:er.push(e)}function $R(e){jd=!0,$0(e)}function li(){if(!Rh&&er!==null){Rh=!0;var e=0,t=Xe;try{var s=er;for(Xe=1;e<s.length;e++){var r=s[e];do r=r(!0);while(r!==null)}er=null,jd=!1}catch(i){throw er!==null&&(er=er.slice(e+1)),r0(sg,li),i}finally{Xe=t,Rh=!1}}return null}var pa=[],ga=0,Ru=null,Iu=0,ts=[],ns=0,Ii=null,nr=1,sr="";function vi(e,t){pa[ga++]=Iu,pa[ga++]=Ru,Ru=e,Iu=t}function M0(e,t,s){ts[ns++]=nr,ts[ns++]=sr,ts[ns++]=Ii,Ii=e;var r=nr;e=sr;var i=32-gs(r)-1;r&=~(1<<i),s+=1;var a=32-gs(t)+i;if(30<a){var l=i-i%5;a=(r&(1<<l)-1).toString(32),r>>=l,i-=l,nr=1<<32-gs(t)+i|s<<i|r,sr=a+e}else nr=1<<a|s<<i|r,sr=e}function hg(e){e.return!==null&&(vi(e,1),M0(e,1,0))}function fg(e){for(;e===Ru;)Ru=pa[--ga],pa[ga]=null,Iu=pa[--ga],pa[ga]=null;for(;e===Ii;)Ii=ts[--ns],ts[ns]=null,sr=ts[--ns],ts[ns]=null,nr=ts[--ns],ts[ns]=null}var Un=null,Fn=null,dt=!1,ms=null;function O0(e,t){var s=is(5,null,null,0);s.elementType="DELETED",s.stateNode=t,s.return=e,t=e.deletions,t===null?(e.deletions=[s],e.flags|=16):t.push(s)}function $j(e,t){switch(e.tag){case 5:var s=e.type;return t=t.nodeType!==1||s.toLowerCase()!==t.nodeName.toLowerCase()?null:t,t!==null?(e.stateNode=t,Un=e,Fn=zr(t.firstChild),!0):!1;case 6:return t=e.pendingProps===""||t.nodeType!==3?null:t,t!==null?(e.stateNode=t,Un=e,Fn=null,!0):!1;case 13:return t=t.nodeType!==8?null:t,t!==null?(s=Ii!==null?{id:nr,overflow:sr}:null,e.memoizedState={dehydrated:t,treeContext:s,retryLane:1073741824},s=is(18,null,null,0),s.stateNode=t,s.return=e,e.child=s,Un=e,Fn=null,!0):!1;default:return!1}}function am(e){return(e.mode&1)!==0&&(e.flags&128)===0}function lm(e){if(dt){var t=Fn;if(t){var s=t;if(!$j(e,t)){if(am(e))throw Error(re(418));t=zr(s.nextSibling);var r=Un;t&&$j(e,t)?O0(r,s):(e.flags=e.flags&-4097|2,dt=!1,Un=e)}}else{if(am(e))throw Error(re(418));e.flags=e.flags&-4097|2,dt=!1,Un=e}}}function Mj(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;Un=e}function gc(e){if(e!==Un)return!1;if(!dt)return Mj(e),dt=!0,!1;var t;if((t=e.tag!==3)&&!(t=e.tag!==5)&&(t=e.type,t=t!=="head"&&t!=="body"&&!nm(e.type,e.memoizedProps)),t&&(t=Fn)){if(am(e))throw D0(),Error(re(418));for(;t;)O0(e,t),t=zr(t.nextSibling)}if(Mj(e),e.tag===13){if(e=e.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(re(317));e:{for(e=e.nextSibling,t=0;e;){if(e.nodeType===8){var s=e.data;if(s==="/$"){if(t===0){Fn=zr(e.nextSibling);break e}t--}else s!=="$"&&s!=="$!"&&s!=="$?"||t++}e=e.nextSibling}Fn=null}}else Fn=Un?zr(e.stateNode.nextSibling):null;return!0}function D0(){for(var e=Fn;e;)e=zr(e.nextSibling)}function Da(){Fn=Un=null,dt=!1}function mg(e){ms===null?ms=[e]:ms.push(e)}var MR=gr.ReactCurrentBatchConfig;function kl(e,t,s){if(e=s.ref,e!==null&&typeof e!="function"&&typeof e!="object"){if(s._owner){if(s=s._owner,s){if(s.tag!==1)throw Error(re(309));var r=s.stateNode}if(!r)throw Error(re(147,e));var i=r,a=""+e;return t!==null&&t.ref!==null&&typeof t.ref=="function"&&t.ref._stringRef===a?t.ref:(t=function(l){var o=i.refs;l===null?delete o[a]:o[a]=l},t._stringRef=a,t)}if(typeof e!="string")throw Error(re(284));if(!s._owner)throw Error(re(290,e))}return e}function xc(e,t){throw e=Object.prototype.toString.call(t),Error(re(31,e==="[object Object]"?"object with keys {"+Object.keys(t).join(", ")+"}":e))}function Oj(e){var t=e._init;return t(e._payload)}function _0(e){function t(g,v){if(e){var w=g.deletions;w===null?(g.deletions=[v],g.flags|=16):w.push(v)}}function s(g,v){if(!e)return null;for(;v!==null;)t(g,v),v=v.sibling;return null}function r(g,v){for(g=new Map;v!==null;)v.key!==null?g.set(v.key,v):g.set(v.index,v),v=v.sibling;return g}function i(g,v){return g=Hr(g,v),g.index=0,g.sibling=null,g}function a(g,v,w){return g.index=w,e?(w=g.alternate,w!==null?(w=w.index,w<v?(g.flags|=2,v):w):(g.flags|=2,v)):(g.flags|=1048576,v)}function l(g){return e&&g.alternate===null&&(g.flags|=2),g}function o(g,v,w,y){return v===null||v.tag!==6?(v=_h(w,g.mode,y),v.return=g,v):(v=i(v,w),v.return=g,v)}function c(g,v,w,y){var N=w.type;return N===ca?h(g,v,w.props.children,y,w.key):v!==null&&(v.elementType===N||typeof N=="object"&&N!==null&&N.$$typeof===Ar&&Oj(N)===v.type)?(y=i(v,w.props),y.ref=kl(g,v,w),y.return=g,y):(y=iu(w.type,w.key,w.props,null,g.mode,y),y.ref=kl(g,v,w),y.return=g,y)}function u(g,v,w,y){return v===null||v.tag!==4||v.stateNode.containerInfo!==w.containerInfo||v.stateNode.implementation!==w.implementation?(v=Lh(w,g.mode,y),v.return=g,v):(v=i(v,w.children||[]),v.return=g,v)}function h(g,v,w,y,N){return v===null||v.tag!==7?(v=Ci(w,g.mode,y,N),v.return=g,v):(v=i(v,w),v.return=g,v)}function d(g,v,w){if(typeof v=="string"&&v!==""||typeof v=="number")return v=_h(""+v,g.mode,w),v.return=g,v;if(typeof v=="object"&&v!==null){switch(v.$$typeof){case ac:return w=iu(v.type,v.key,v.props,null,g.mode,w),w.ref=kl(g,null,v),w.return=g,w;case oa:return v=Lh(v,g.mode,w),v.return=g,v;case Ar:var y=v._init;return d(g,y(v._payload),w)}if($l(v)||vl(v))return v=Ci(v,g.mode,w,null),v.return=g,v;xc(g,v)}return null}function m(g,v,w,y){var N=v!==null?v.key:null;if(typeof w=="string"&&w!==""||typeof w=="number")return N!==null?null:o(g,v,""+w,y);if(typeof w=="object"&&w!==null){switch(w.$$typeof){case ac:return w.key===N?c(g,v,w,y):null;case oa:return w.key===N?u(g,v,w,y):null;case Ar:return N=w._init,m(g,v,N(w._payload),y)}if($l(w)||vl(w))return N!==null?null:h(g,v,w,y,null);xc(g,w)}return null}function p(g,v,w,y,N){if(typeof y=="string"&&y!==""||typeof y=="number")return g=g.get(w)||null,o(v,g,""+y,N);if(typeof y=="object"&&y!==null){switch(y.$$typeof){case ac:return g=g.get(y.key===null?w:y.key)||null,c(v,g,y,N);case oa:return g=g.get(y.key===null?w:y.key)||null,u(v,g,y,N);case Ar:var k=y._init;return p(g,v,w,k(y._payload),N)}if($l(y)||vl(y))return g=g.get(w)||null,h(v,g,y,N,null);xc(v,y)}return null}function x(g,v,w,y){for(var N=null,k=null,S=v,C=v=0,I=null;S!==null&&C<w.length;C++){S.index>C?(I=S,S=null):I=S.sibling;var A=m(g,S,w[C],y);if(A===null){S===null&&(S=I);break}e&&S&&A.alternate===null&&t(g,S),v=a(A,v,C),k===null?N=A:k.sibling=A,k=A,S=I}if(C===w.length)return s(g,S),dt&&vi(g,C),N;if(S===null){for(;C<w.length;C++)S=d(g,w[C],y),S!==null&&(v=a(S,v,C),k===null?N=S:k.sibling=S,k=S);return dt&&vi(g,C),N}for(S=r(g,S);C<w.length;C++)I=p(S,g,C,w[C],y),I!==null&&(e&&I.alternate!==null&&S.delete(I.key===null?C:I.key),v=a(I,v,C),k===null?N=I:k.sibling=I,k=I);return e&&S.forEach(function(O){return t(g,O)}),dt&&vi(g,C),N}function j(g,v,w,y){var N=vl(w);if(typeof N!="function")throw Error(re(150));if(w=N.call(w),w==null)throw Error(re(151));for(var k=N=null,S=v,C=v=0,I=null,A=w.next();S!==null&&!A.done;C++,A=w.next()){S.index>C?(I=S,S=null):I=S.sibling;var O=m(g,S,A.value,y);if(O===null){S===null&&(S=I);break}e&&S&&O.alternate===null&&t(g,S),v=a(O,v,C),k===null?N=O:k.sibling=O,k=O,S=I}if(A.done)return s(g,S),dt&&vi(g,C),N;if(S===null){for(;!A.done;C++,A=w.next())A=d(g,A.value,y),A!==null&&(v=a(A,v,C),k===null?N=A:k.sibling=A,k=A);return dt&&vi(g,C),N}for(S=r(g,S);!A.done;C++,A=w.next())A=p(S,g,C,A.value,y),A!==null&&(e&&A.alternate!==null&&S.delete(A.key===null?C:A.key),v=a(A,v,C),k===null?N=A:k.sibling=A,k=A);return e&&S.forEach(function(z){return t(g,z)}),dt&&vi(g,C),N}function b(g,v,w,y){if(typeof w=="object"&&w!==null&&w.type===ca&&w.key===null&&(w=w.props.children),typeof w=="object"&&w!==null){switch(w.$$typeof){case ac:e:{for(var N=w.key,k=v;k!==null;){if(k.key===N){if(N=w.type,N===ca){if(k.tag===7){s(g,k.sibling),v=i(k,w.props.children),v.return=g,g=v;break e}}else if(k.elementType===N||typeof N=="object"&&N!==null&&N.$$typeof===Ar&&Oj(N)===k.type){s(g,k.sibling),v=i(k,w.props),v.ref=kl(g,k,w),v.return=g,g=v;break e}s(g,k);break}else t(g,k);k=k.sibling}w.type===ca?(v=Ci(w.props.children,g.mode,y,w.key),v.return=g,g=v):(y=iu(w.type,w.key,w.props,null,g.mode,y),y.ref=kl(g,v,w),y.return=g,g=y)}return l(g);case oa:e:{for(k=w.key;v!==null;){if(v.key===k)if(v.tag===4&&v.stateNode.containerInfo===w.containerInfo&&v.stateNode.implementation===w.implementation){s(g,v.sibling),v=i(v,w.children||[]),v.return=g,g=v;break e}else{s(g,v);break}else t(g,v);v=v.sibling}v=Lh(w,g.mode,y),v.return=g,g=v}return l(g);case Ar:return k=w._init,b(g,v,k(w._payload),y)}if($l(w))return x(g,v,w,y);if(vl(w))return j(g,v,w,y);xc(g,w)}return typeof w=="string"&&w!==""||typeof w=="number"?(w=""+w,v!==null&&v.tag===6?(s(g,v.sibling),v=i(v,w),v.return=g,g=v):(s(g,v),v=_h(w,g.mode,y),v.return=g,g=v),l(g)):s(g,v)}return b}var _a=_0(!0),L0=_0(!1),Pu=ai(null),$u=null,xa=null,pg=null;function gg(){pg=xa=$u=null}function xg(e){var t=Pu.current;ot(Pu),e._currentValue=t}function om(e,t,s){for(;e!==null;){var r=e.alternate;if((e.childLanes&t)!==t?(e.childLanes|=t,r!==null&&(r.childLanes|=t)):r!==null&&(r.childLanes&t)!==t&&(r.childLanes|=t),e===s)break;e=e.return}}function Ca(e,t){$u=e,pg=xa=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(Sn=!0),e.firstContext=null)}function os(e){var t=e._currentValue;if(pg!==e)if(e={context:e,memoizedValue:t,next:null},xa===null){if($u===null)throw Error(re(308));xa=e,$u.dependencies={lanes:0,firstContext:e}}else xa=xa.next=e;return t}var ki=null;function vg(e){ki===null?ki=[e]:ki.push(e)}function F0(e,t,s,r){var i=t.interleaved;return i===null?(s.next=s,vg(t)):(s.next=i.next,i.next=s),t.interleaved=s,ur(e,r)}function ur(e,t){e.lanes|=t;var s=e.alternate;for(s!==null&&(s.lanes|=t),s=e,e=e.return;e!==null;)e.childLanes|=t,s=e.alternate,s!==null&&(s.childLanes|=t),s=e,e=e.return;return s.tag===3?s.stateNode:null}var Tr=!1;function jg(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function z0(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function rr(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function Ur(e,t,s){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,He&2){var i=r.pending;return i===null?t.next=t:(t.next=i.next,i.next=t),r.pending=t,ur(e,s)}return i=r.interleaved,i===null?(t.next=t,vg(r)):(t.next=i.next,i.next=t),r.interleaved=t,ur(e,s)}function Zc(e,t,s){if(t=t.updateQueue,t!==null&&(t=t.shared,(s&4194240)!==0)){var r=t.lanes;r&=e.pendingLanes,s|=r,t.lanes=s,rg(e,s)}}function Dj(e,t){var s=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,s===r)){var i=null,a=null;if(s=s.firstBaseUpdate,s!==null){do{var l={eventTime:s.eventTime,lane:s.lane,tag:s.tag,payload:s.payload,callback:s.callback,next:null};a===null?i=a=l:a=a.next=l,s=s.next}while(s!==null);a===null?i=a=t:a=a.next=t}else i=a=t;s={baseState:r.baseState,firstBaseUpdate:i,lastBaseUpdate:a,shared:r.shared,effects:r.effects},e.updateQueue=s;return}e=s.lastBaseUpdate,e===null?s.firstBaseUpdate=t:e.next=t,s.lastBaseUpdate=t}function Mu(e,t,s,r){var i=e.updateQueue;Tr=!1;var a=i.firstBaseUpdate,l=i.lastBaseUpdate,o=i.shared.pending;if(o!==null){i.shared.pending=null;var c=o,u=c.next;c.next=null,l===null?a=u:l.next=u,l=c;var h=e.alternate;h!==null&&(h=h.updateQueue,o=h.lastBaseUpdate,o!==l&&(o===null?h.firstBaseUpdate=u:o.next=u,h.lastBaseUpdate=c))}if(a!==null){var d=i.baseState;l=0,h=u=c=null,o=a;do{var m=o.lane,p=o.eventTime;if((r&m)===m){h!==null&&(h=h.next={eventTime:p,lane:0,tag:o.tag,payload:o.payload,callback:o.callback,next:null});e:{var x=e,j=o;switch(m=t,p=s,j.tag){case 1:if(x=j.payload,typeof x=="function"){d=x.call(p,d,m);break e}d=x;break e;case 3:x.flags=x.flags&-65537|128;case 0:if(x=j.payload,m=typeof x=="function"?x.call(p,d,m):x,m==null)break e;d=vt({},d,m);break e;case 2:Tr=!0}}o.callback!==null&&o.lane!==0&&(e.flags|=64,m=i.effects,m===null?i.effects=[o]:m.push(o))}else p={eventTime:p,lane:m,tag:o.tag,payload:o.payload,callback:o.callback,next:null},h===null?(u=h=p,c=d):h=h.next=p,l|=m;if(o=o.next,o===null){if(o=i.shared.pending,o===null)break;m=o,o=m.next,m.next=null,i.lastBaseUpdate=m,i.shared.pending=null}}while(!0);if(h===null&&(c=d),i.baseState=c,i.firstBaseUpdate=u,i.lastBaseUpdate=h,t=i.shared.interleaved,t!==null){i=t;do l|=i.lane,i=i.next;while(i!==t)}else a===null&&(i.shared.lanes=0);$i|=l,e.lanes=l,e.memoizedState=d}}function _j(e,t,s){if(e=t.effects,t.effects=null,e!==null)for(t=0;t<e.length;t++){var r=e[t],i=r.callback;if(i!==null){if(r.callback=null,r=s,typeof i!="function")throw Error(re(191,i));i.call(r)}}}var Lo={},Us=ai(Lo),co=ai(Lo),uo=ai(Lo);function Si(e){if(e===Lo)throw Error(re(174));return e}function wg(e,t){switch(rt(uo,t),rt(co,e),rt(Us,Lo),e=t.nodeType,e){case 9:case 11:t=(t=t.documentElement)?t.namespaceURI:Bf(null,"");break;default:e=e===8?t.parentNode:t,t=e.namespaceURI||null,e=e.tagName,t=Bf(t,e)}ot(Us),rt(Us,t)}function La(){ot(Us),ot(co),ot(uo)}function U0(e){Si(uo.current);var t=Si(Us.current),s=Bf(t,e.type);t!==s&&(rt(co,e),rt(Us,s))}function yg(e){co.current===e&&(ot(Us),ot(co))}var ft=ai(0);function Ou(e){for(var t=e;t!==null;){if(t.tag===13){var s=t.memoizedState;if(s!==null&&(s=s.dehydrated,s===null||s.data==="$?"||s.data==="$!"))return t}else if(t.tag===19&&t.memoizedProps.revealOrder!==void 0){if(t.flags&128)return t}else if(t.child!==null){t.child.return=t,t=t.child;continue}if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return null;t=t.return}t.sibling.return=t.return,t=t.sibling}return null}var Ih=[];function bg(){for(var e=0;e<Ih.length;e++)Ih[e]._workInProgressVersionPrimary=null;Ih.length=0}var eu=gr.ReactCurrentDispatcher,Ph=gr.ReactCurrentBatchConfig,Pi=0,gt=null,Ot=null,Ut=null,Du=!1,Wl=!1,ho=0,OR=0;function ln(){throw Error(re(321))}function kg(e,t){if(t===null)return!1;for(var s=0;s<t.length&&s<e.length;s++)if(!ys(e[s],t[s]))return!1;return!0}function Sg(e,t,s,r,i,a){if(Pi=a,gt=t,t.memoizedState=null,t.updateQueue=null,t.lanes=0,eu.current=e===null||e.memoizedState===null?FR:zR,e=s(r,i),Wl){a=0;do{if(Wl=!1,ho=0,25<=a)throw Error(re(301));a+=1,Ut=Ot=null,t.updateQueue=null,eu.current=UR,e=s(r,i)}while(Wl)}if(eu.current=_u,t=Ot!==null&&Ot.next!==null,Pi=0,Ut=Ot=gt=null,Du=!1,t)throw Error(re(300));return e}function Ng(){var e=ho!==0;return ho=0,e}function Ms(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return Ut===null?gt.memoizedState=Ut=e:Ut=Ut.next=e,Ut}function cs(){if(Ot===null){var e=gt.alternate;e=e!==null?e.memoizedState:null}else e=Ot.next;var t=Ut===null?gt.memoizedState:Ut.next;if(t!==null)Ut=t,Ot=e;else{if(e===null)throw Error(re(310));Ot=e,e={memoizedState:Ot.memoizedState,baseState:Ot.baseState,baseQueue:Ot.baseQueue,queue:Ot.queue,next:null},Ut===null?gt.memoizedState=Ut=e:Ut=Ut.next=e}return Ut}function fo(e,t){return typeof t=="function"?t(e):t}function $h(e){var t=cs(),s=t.queue;if(s===null)throw Error(re(311));s.lastRenderedReducer=e;var r=Ot,i=r.baseQueue,a=s.pending;if(a!==null){if(i!==null){var l=i.next;i.next=a.next,a.next=l}r.baseQueue=i=a,s.pending=null}if(i!==null){a=i.next,r=r.baseState;var o=l=null,c=null,u=a;do{var h=u.lane;if((Pi&h)===h)c!==null&&(c=c.next={lane:0,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null}),r=u.hasEagerState?u.eagerState:e(r,u.action);else{var d={lane:h,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null};c===null?(o=c=d,l=r):c=c.next=d,gt.lanes|=h,$i|=h}u=u.next}while(u!==null&&u!==a);c===null?l=r:c.next=o,ys(r,t.memoizedState)||(Sn=!0),t.memoizedState=r,t.baseState=l,t.baseQueue=c,s.lastRenderedState=r}if(e=s.interleaved,e!==null){i=e;do a=i.lane,gt.lanes|=a,$i|=a,i=i.next;while(i!==e)}else i===null&&(s.lanes=0);return[t.memoizedState,s.dispatch]}function Mh(e){var t=cs(),s=t.queue;if(s===null)throw Error(re(311));s.lastRenderedReducer=e;var r=s.dispatch,i=s.pending,a=t.memoizedState;if(i!==null){s.pending=null;var l=i=i.next;do a=e(a,l.action),l=l.next;while(l!==i);ys(a,t.memoizedState)||(Sn=!0),t.memoizedState=a,t.baseQueue===null&&(t.baseState=a),s.lastRenderedState=a}return[a,r]}function B0(){}function W0(e,t){var s=gt,r=cs(),i=t(),a=!ys(r.memoizedState,i);if(a&&(r.memoizedState=i,Sn=!0),r=r.queue,Cg(V0.bind(null,s,r,e),[e]),r.getSnapshot!==t||a||Ut!==null&&Ut.memoizedState.tag&1){if(s.flags|=2048,mo(9,K0.bind(null,s,r,i,t),void 0,null),Ht===null)throw Error(re(349));Pi&30||H0(s,t,i)}return i}function H0(e,t,s){e.flags|=16384,e={getSnapshot:t,value:s},t=gt.updateQueue,t===null?(t={lastEffect:null,stores:null},gt.updateQueue=t,t.stores=[e]):(s=t.stores,s===null?t.stores=[e]:s.push(e))}function K0(e,t,s,r){t.value=s,t.getSnapshot=r,G0(t)&&Y0(e)}function V0(e,t,s){return s(function(){G0(t)&&Y0(e)})}function G0(e){var t=e.getSnapshot;e=e.value;try{var s=t();return!ys(e,s)}catch{return!0}}function Y0(e){var t=ur(e,1);t!==null&&xs(t,e,1,-1)}function Lj(e){var t=Ms();return typeof e=="function"&&(e=e()),t.memoizedState=t.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:fo,lastRenderedState:e},t.queue=e,e=e.dispatch=LR.bind(null,gt,e),[t.memoizedState,e]}function mo(e,t,s,r){return e={tag:e,create:t,destroy:s,deps:r,next:null},t=gt.updateQueue,t===null?(t={lastEffect:null,stores:null},gt.updateQueue=t,t.lastEffect=e.next=e):(s=t.lastEffect,s===null?t.lastEffect=e.next=e:(r=s.next,s.next=e,e.next=r,t.lastEffect=e)),e}function q0(){return cs().memoizedState}function tu(e,t,s,r){var i=Ms();gt.flags|=e,i.memoizedState=mo(1|t,s,void 0,r===void 0?null:r)}function wd(e,t,s,r){var i=cs();r=r===void 0?null:r;var a=void 0;if(Ot!==null){var l=Ot.memoizedState;if(a=l.destroy,r!==null&&kg(r,l.deps)){i.memoizedState=mo(t,s,a,r);return}}gt.flags|=e,i.memoizedState=mo(1|t,s,a,r)}function Fj(e,t){return tu(8390656,8,e,t)}function Cg(e,t){return wd(2048,8,e,t)}function Q0(e,t){return wd(4,2,e,t)}function J0(e,t){return wd(4,4,e,t)}function X0(e,t){if(typeof t=="function")return e=e(),t(e),function(){t(null)};if(t!=null)return e=e(),t.current=e,function(){t.current=null}}function Z0(e,t,s){return s=s!=null?s.concat([e]):null,wd(4,4,X0.bind(null,t,e),s)}function Eg(){}function ek(e,t){var s=cs();t=t===void 0?null:t;var r=s.memoizedState;return r!==null&&t!==null&&kg(t,r[1])?r[0]:(s.memoizedState=[e,t],e)}function tk(e,t){var s=cs();t=t===void 0?null:t;var r=s.memoizedState;return r!==null&&t!==null&&kg(t,r[1])?r[0]:(e=e(),s.memoizedState=[e,t],e)}function nk(e,t,s){return Pi&21?(ys(s,t)||(s=l0(),gt.lanes|=s,$i|=s,e.baseState=!0),t):(e.baseState&&(e.baseState=!1,Sn=!0),e.memoizedState=s)}function DR(e,t){var s=Xe;Xe=s!==0&&4>s?s:4,e(!0);var r=Ph.transition;Ph.transition={};try{e(!1),t()}finally{Xe=s,Ph.transition=r}}function sk(){return cs().memoizedState}function _R(e,t,s){var r=Wr(e);if(s={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null},rk(e))ik(t,s);else if(s=F0(e,t,s,r),s!==null){var i=vn();xs(s,e,r,i),ak(s,t,r)}}function LR(e,t,s){var r=Wr(e),i={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null};if(rk(e))ik(t,i);else{var a=e.alternate;if(e.lanes===0&&(a===null||a.lanes===0)&&(a=t.lastRenderedReducer,a!==null))try{var l=t.lastRenderedState,o=a(l,s);if(i.hasEagerState=!0,i.eagerState=o,ys(o,l)){var c=t.interleaved;c===null?(i.next=i,vg(t)):(i.next=c.next,c.next=i),t.interleaved=i;return}}catch{}finally{}s=F0(e,t,i,r),s!==null&&(i=vn(),xs(s,e,r,i),ak(s,t,r))}}function rk(e){var t=e.alternate;return e===gt||t!==null&&t===gt}function ik(e,t){Wl=Du=!0;var s=e.pending;s===null?t.next=t:(t.next=s.next,s.next=t),e.pending=t}function ak(e,t,s){if(s&4194240){var r=t.lanes;r&=e.pendingLanes,s|=r,t.lanes=s,rg(e,s)}}var _u={readContext:os,useCallback:ln,useContext:ln,useEffect:ln,useImperativeHandle:ln,useInsertionEffect:ln,useLayoutEffect:ln,useMemo:ln,useReducer:ln,useRef:ln,useState:ln,useDebugValue:ln,useDeferredValue:ln,useTransition:ln,useMutableSource:ln,useSyncExternalStore:ln,useId:ln,unstable_isNewReconciler:!1},FR={readContext:os,useCallback:function(e,t){return Ms().memoizedState=[e,t===void 0?null:t],e},useContext:os,useEffect:Fj,useImperativeHandle:function(e,t,s){return s=s!=null?s.concat([e]):null,tu(4194308,4,X0.bind(null,t,e),s)},useLayoutEffect:function(e,t){return tu(4194308,4,e,t)},useInsertionEffect:function(e,t){return tu(4,2,e,t)},useMemo:function(e,t){var s=Ms();return t=t===void 0?null:t,e=e(),s.memoizedState=[e,t],e},useReducer:function(e,t,s){var r=Ms();return t=s!==void 0?s(t):t,r.memoizedState=r.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},r.queue=e,e=e.dispatch=_R.bind(null,gt,e),[r.memoizedState,e]},useRef:function(e){var t=Ms();return e={current:e},t.memoizedState=e},useState:Lj,useDebugValue:Eg,useDeferredValue:function(e){return Ms().memoizedState=e},useTransition:function(){var e=Lj(!1),t=e[0];return e=DR.bind(null,e[1]),Ms().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,s){var r=gt,i=Ms();if(dt){if(s===void 0)throw Error(re(407));s=s()}else{if(s=t(),Ht===null)throw Error(re(349));Pi&30||H0(r,t,s)}i.memoizedState=s;var a={value:s,getSnapshot:t};return i.queue=a,Fj(V0.bind(null,r,a,e),[e]),r.flags|=2048,mo(9,K0.bind(null,r,a,s,t),void 0,null),s},useId:function(){var e=Ms(),t=Ht.identifierPrefix;if(dt){var s=sr,r=nr;s=(r&~(1<<32-gs(r)-1)).toString(32)+s,t=":"+t+"R"+s,s=ho++,0<s&&(t+="H"+s.toString(32)),t+=":"}else s=OR++,t=":"+t+"r"+s.toString(32)+":";return e.memoizedState=t},unstable_isNewReconciler:!1},zR={readContext:os,useCallback:ek,useContext:os,useEffect:Cg,useImperativeHandle:Z0,useInsertionEffect:Q0,useLayoutEffect:J0,useMemo:tk,useReducer:$h,useRef:q0,useState:function(){return $h(fo)},useDebugValue:Eg,useDeferredValue:function(e){var t=cs();return nk(t,Ot.memoizedState,e)},useTransition:function(){var e=$h(fo)[0],t=cs().memoizedState;return[e,t]},useMutableSource:B0,useSyncExternalStore:W0,useId:sk,unstable_isNewReconciler:!1},UR={readContext:os,useCallback:ek,useContext:os,useEffect:Cg,useImperativeHandle:Z0,useInsertionEffect:Q0,useLayoutEffect:J0,useMemo:tk,useReducer:Mh,useRef:q0,useState:function(){return Mh(fo)},useDebugValue:Eg,useDeferredValue:function(e){var t=cs();return Ot===null?t.memoizedState=e:nk(t,Ot.memoizedState,e)},useTransition:function(){var e=Mh(fo)[0],t=cs().memoizedState;return[e,t]},useMutableSource:B0,useSyncExternalStore:W0,useId:sk,unstable_isNewReconciler:!1};function hs(e,t){if(e&&e.defaultProps){t=vt({},t),e=e.defaultProps;for(var s in e)t[s]===void 0&&(t[s]=e[s]);return t}return t}function cm(e,t,s,r){t=e.memoizedState,s=s(r,t),s=s==null?t:vt({},t,s),e.memoizedState=s,e.lanes===0&&(e.updateQueue.baseState=s)}var yd={isMounted:function(e){return(e=e._reactInternals)?Bi(e)===e:!1},enqueueSetState:function(e,t,s){e=e._reactInternals;var r=vn(),i=Wr(e),a=rr(r,i);a.payload=t,s!=null&&(a.callback=s),t=Ur(e,a,i),t!==null&&(xs(t,e,i,r),Zc(t,e,i))},enqueueReplaceState:function(e,t,s){e=e._reactInternals;var r=vn(),i=Wr(e),a=rr(r,i);a.tag=1,a.payload=t,s!=null&&(a.callback=s),t=Ur(e,a,i),t!==null&&(xs(t,e,i,r),Zc(t,e,i))},enqueueForceUpdate:function(e,t){e=e._reactInternals;var s=vn(),r=Wr(e),i=rr(s,r);i.tag=2,t!=null&&(i.callback=t),t=Ur(e,i,r),t!==null&&(xs(t,e,r,s),Zc(t,e,r))}};function zj(e,t,s,r,i,a,l){return e=e.stateNode,typeof e.shouldComponentUpdate=="function"?e.shouldComponentUpdate(r,a,l):t.prototype&&t.prototype.isPureReactComponent?!io(s,r)||!io(i,a):!0}function lk(e,t,s){var r=!1,i=Jr,a=t.contextType;return typeof a=="object"&&a!==null?a=os(a):(i=En(t)?Ri:fn.current,r=t.contextTypes,a=(r=r!=null)?Oa(e,i):Jr),t=new t(s,a),e.memoizedState=t.state!==null&&t.state!==void 0?t.state:null,t.updater=yd,e.stateNode=t,t._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=i,e.__reactInternalMemoizedMaskedChildContext=a),t}function Uj(e,t,s,r){e=t.state,typeof t.componentWillReceiveProps=="function"&&t.componentWillReceiveProps(s,r),typeof t.UNSAFE_componentWillReceiveProps=="function"&&t.UNSAFE_componentWillReceiveProps(s,r),t.state!==e&&yd.enqueueReplaceState(t,t.state,null)}function um(e,t,s,r){var i=e.stateNode;i.props=s,i.state=e.memoizedState,i.refs={},jg(e);var a=t.contextType;typeof a=="object"&&a!==null?i.context=os(a):(a=En(t)?Ri:fn.current,i.context=Oa(e,a)),i.state=e.memoizedState,a=t.getDerivedStateFromProps,typeof a=="function"&&(cm(e,t,a,s),i.state=e.memoizedState),typeof t.getDerivedStateFromProps=="function"||typeof i.getSnapshotBeforeUpdate=="function"||typeof i.UNSAFE_componentWillMount!="function"&&typeof i.componentWillMount!="function"||(t=i.state,typeof i.componentWillMount=="function"&&i.componentWillMount(),typeof i.UNSAFE_componentWillMount=="function"&&i.UNSAFE_componentWillMount(),t!==i.state&&yd.enqueueReplaceState(i,i.state,null),Mu(e,s,i,r),i.state=e.memoizedState),typeof i.componentDidMount=="function"&&(e.flags|=4194308)}function Fa(e,t){try{var s="",r=t;do s+=pT(r),r=r.return;while(r);var i=s}catch(a){i=`
39
- Error generating stack: `+a.message+`
40
- `+a.stack}return{value:e,source:t,stack:i,digest:null}}function Oh(e,t,s){return{value:e,source:null,stack:s??null,digest:t??null}}function dm(e,t){try{console.error(t.value)}catch(s){setTimeout(function(){throw s})}}var BR=typeof WeakMap=="function"?WeakMap:Map;function ok(e,t,s){s=rr(-1,s),s.tag=3,s.payload={element:null};var r=t.value;return s.callback=function(){Fu||(Fu=!0,ym=r),dm(e,t)},s}function ck(e,t,s){s=rr(-1,s),s.tag=3;var r=e.type.getDerivedStateFromError;if(typeof r=="function"){var i=t.value;s.payload=function(){return r(i)},s.callback=function(){dm(e,t)}}var a=e.stateNode;return a!==null&&typeof a.componentDidCatch=="function"&&(s.callback=function(){dm(e,t),typeof r!="function"&&(Br===null?Br=new Set([this]):Br.add(this));var l=t.stack;this.componentDidCatch(t.value,{componentStack:l!==null?l:""})}),s}function Bj(e,t,s){var r=e.pingCache;if(r===null){r=e.pingCache=new BR;var i=new Set;r.set(t,i)}else i=r.get(t),i===void 0&&(i=new Set,r.set(t,i));i.has(s)||(i.add(s),e=nI.bind(null,e,t,s),t.then(e,e))}function Wj(e){do{var t;if((t=e.tag===13)&&(t=e.memoizedState,t=t!==null?t.dehydrated!==null:!0),t)return e;e=e.return}while(e!==null);return null}function Hj(e,t,s,r,i){return e.mode&1?(e.flags|=65536,e.lanes=i,e):(e===t?e.flags|=65536:(e.flags|=128,s.flags|=131072,s.flags&=-52805,s.tag===1&&(s.alternate===null?s.tag=17:(t=rr(-1,1),t.tag=2,Ur(s,t,1))),s.lanes|=1),e)}var WR=gr.ReactCurrentOwner,Sn=!1;function gn(e,t,s,r){t.child=e===null?L0(t,null,s,r):_a(t,e.child,s,r)}function Kj(e,t,s,r,i){s=s.render;var a=t.ref;return Ca(t,i),r=Sg(e,t,s,r,a,i),s=Ng(),e!==null&&!Sn?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,dr(e,t,i)):(dt&&s&&hg(t),t.flags|=1,gn(e,t,r,i),t.child)}function Vj(e,t,s,r,i){if(e===null){var a=s.type;return typeof a=="function"&&!Og(a)&&a.defaultProps===void 0&&s.compare===null&&s.defaultProps===void 0?(t.tag=15,t.type=a,uk(e,t,a,r,i)):(e=iu(s.type,null,r,t,t.mode,i),e.ref=t.ref,e.return=t,t.child=e)}if(a=e.child,!(e.lanes&i)){var l=a.memoizedProps;if(s=s.compare,s=s!==null?s:io,s(l,r)&&e.ref===t.ref)return dr(e,t,i)}return t.flags|=1,e=Hr(a,r),e.ref=t.ref,e.return=t,t.child=e}function uk(e,t,s,r,i){if(e!==null){var a=e.memoizedProps;if(io(a,r)&&e.ref===t.ref)if(Sn=!1,t.pendingProps=r=a,(e.lanes&i)!==0)e.flags&131072&&(Sn=!0);else return t.lanes=e.lanes,dr(e,t,i)}return hm(e,t,s,r,i)}function dk(e,t,s){var r=t.pendingProps,i=r.children,a=e!==null?e.memoizedState:null;if(r.mode==="hidden")if(!(t.mode&1))t.memoizedState={baseLanes:0,cachePool:null,transitions:null},rt(ja,_n),_n|=s;else{if(!(s&1073741824))return e=a!==null?a.baseLanes|s:s,t.lanes=t.childLanes=1073741824,t.memoizedState={baseLanes:e,cachePool:null,transitions:null},t.updateQueue=null,rt(ja,_n),_n|=e,null;t.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=a!==null?a.baseLanes:s,rt(ja,_n),_n|=r}else a!==null?(r=a.baseLanes|s,t.memoizedState=null):r=s,rt(ja,_n),_n|=r;return gn(e,t,i,s),t.child}function hk(e,t){var s=t.ref;(e===null&&s!==null||e!==null&&e.ref!==s)&&(t.flags|=512,t.flags|=2097152)}function hm(e,t,s,r,i){var a=En(s)?Ri:fn.current;return a=Oa(t,a),Ca(t,i),s=Sg(e,t,s,r,a,i),r=Ng(),e!==null&&!Sn?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,dr(e,t,i)):(dt&&r&&hg(t),t.flags|=1,gn(e,t,s,i),t.child)}function Gj(e,t,s,r,i){if(En(s)){var a=!0;Tu(t)}else a=!1;if(Ca(t,i),t.stateNode===null)nu(e,t),lk(t,s,r),um(t,s,r,i),r=!0;else if(e===null){var l=t.stateNode,o=t.memoizedProps;l.props=o;var c=l.context,u=s.contextType;typeof u=="object"&&u!==null?u=os(u):(u=En(s)?Ri:fn.current,u=Oa(t,u));var h=s.getDerivedStateFromProps,d=typeof h=="function"||typeof l.getSnapshotBeforeUpdate=="function";d||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==r||c!==u)&&Uj(t,l,r,u),Tr=!1;var m=t.memoizedState;l.state=m,Mu(t,r,l,i),c=t.memoizedState,o!==r||m!==c||Cn.current||Tr?(typeof h=="function"&&(cm(t,s,h,r),c=t.memoizedState),(o=Tr||zj(t,s,o,r,m,c,u))?(d||typeof l.UNSAFE_componentWillMount!="function"&&typeof l.componentWillMount!="function"||(typeof l.componentWillMount=="function"&&l.componentWillMount(),typeof l.UNSAFE_componentWillMount=="function"&&l.UNSAFE_componentWillMount()),typeof l.componentDidMount=="function"&&(t.flags|=4194308)):(typeof l.componentDidMount=="function"&&(t.flags|=4194308),t.memoizedProps=r,t.memoizedState=c),l.props=r,l.state=c,l.context=u,r=o):(typeof l.componentDidMount=="function"&&(t.flags|=4194308),r=!1)}else{l=t.stateNode,z0(e,t),o=t.memoizedProps,u=t.type===t.elementType?o:hs(t.type,o),l.props=u,d=t.pendingProps,m=l.context,c=s.contextType,typeof c=="object"&&c!==null?c=os(c):(c=En(s)?Ri:fn.current,c=Oa(t,c));var p=s.getDerivedStateFromProps;(h=typeof p=="function"||typeof l.getSnapshotBeforeUpdate=="function")||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==d||m!==c)&&Uj(t,l,r,c),Tr=!1,m=t.memoizedState,l.state=m,Mu(t,r,l,i);var x=t.memoizedState;o!==d||m!==x||Cn.current||Tr?(typeof p=="function"&&(cm(t,s,p,r),x=t.memoizedState),(u=Tr||zj(t,s,u,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"&&(t.flags|=4),typeof l.getSnapshotBeforeUpdate=="function"&&(t.flags|=1024)):(typeof l.componentDidUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(t.flags|=4),typeof l.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(t.flags|=1024),t.memoizedProps=r,t.memoizedState=x),l.props=r,l.state=x,l.context=c,r=u):(typeof l.componentDidUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(t.flags|=4),typeof l.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(t.flags|=1024),r=!1)}return fm(e,t,s,r,a,i)}function fm(e,t,s,r,i,a){hk(e,t);var l=(t.flags&128)!==0;if(!r&&!l)return i&&Pj(t,s,!1),dr(e,t,a);r=t.stateNode,WR.current=t;var o=l&&typeof s.getDerivedStateFromError!="function"?null:r.render();return t.flags|=1,e!==null&&l?(t.child=_a(t,e.child,null,a),t.child=_a(t,null,o,a)):gn(e,t,o,a),t.memoizedState=r.state,i&&Pj(t,s,!0),t.child}function fk(e){var t=e.stateNode;t.pendingContext?Ij(e,t.pendingContext,t.pendingContext!==t.context):t.context&&Ij(e,t.context,!1),wg(e,t.containerInfo)}function Yj(e,t,s,r,i){return Da(),mg(i),t.flags|=256,gn(e,t,s,r),t.child}var mm={dehydrated:null,treeContext:null,retryLane:0};function pm(e){return{baseLanes:e,cachePool:null,transitions:null}}function mk(e,t,s){var r=t.pendingProps,i=ft.current,a=!1,l=(t.flags&128)!==0,o;if((o=l)||(o=e!==null&&e.memoizedState===null?!1:(i&2)!==0),o?(a=!0,t.flags&=-129):(e===null||e.memoizedState!==null)&&(i|=1),rt(ft,i&1),e===null)return lm(t),e=t.memoizedState,e!==null&&(e=e.dehydrated,e!==null)?(t.mode&1?e.data==="$!"?t.lanes=8:t.lanes=1073741824:t.lanes=1,null):(l=r.children,e=r.fallback,a?(r=t.mode,a=t.child,l={mode:"hidden",children:l},!(r&1)&&a!==null?(a.childLanes=0,a.pendingProps=l):a=Sd(l,r,0,null),e=Ci(e,r,s,null),a.return=t,e.return=t,a.sibling=e,t.child=a,t.child.memoizedState=pm(s),t.memoizedState=mm,e):Ag(t,l));if(i=e.memoizedState,i!==null&&(o=i.dehydrated,o!==null))return HR(e,t,l,r,o,i,s);if(a){a=r.fallback,l=t.mode,i=e.child,o=i.sibling;var c={mode:"hidden",children:r.children};return!(l&1)&&t.child!==i?(r=t.child,r.childLanes=0,r.pendingProps=c,t.deletions=null):(r=Hr(i,c),r.subtreeFlags=i.subtreeFlags&14680064),o!==null?a=Hr(o,a):(a=Ci(a,l,s,null),a.flags|=2),a.return=t,r.return=t,r.sibling=a,t.child=r,r=a,a=t.child,l=e.child.memoizedState,l=l===null?pm(s):{baseLanes:l.baseLanes|s,cachePool:null,transitions:l.transitions},a.memoizedState=l,a.childLanes=e.childLanes&~s,t.memoizedState=mm,r}return a=e.child,e=a.sibling,r=Hr(a,{mode:"visible",children:r.children}),!(t.mode&1)&&(r.lanes=s),r.return=t,r.sibling=null,e!==null&&(s=t.deletions,s===null?(t.deletions=[e],t.flags|=16):s.push(e)),t.child=r,t.memoizedState=null,r}function Ag(e,t){return t=Sd({mode:"visible",children:t},e.mode,0,null),t.return=e,e.child=t}function vc(e,t,s,r){return r!==null&&mg(r),_a(t,e.child,null,s),e=Ag(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function HR(e,t,s,r,i,a,l){if(s)return t.flags&256?(t.flags&=-257,r=Oh(Error(re(422))),vc(e,t,l,r)):t.memoizedState!==null?(t.child=e.child,t.flags|=128,null):(a=r.fallback,i=t.mode,r=Sd({mode:"visible",children:r.children},i,0,null),a=Ci(a,i,l,null),a.flags|=2,r.return=t,a.return=t,r.sibling=a,t.child=r,t.mode&1&&_a(t,e.child,null,l),t.child.memoizedState=pm(l),t.memoizedState=mm,a);if(!(t.mode&1))return vc(e,t,l,null);if(i.data==="$!"){if(r=i.nextSibling&&i.nextSibling.dataset,r)var o=r.dgst;return r=o,a=Error(re(419)),r=Oh(a,r,void 0),vc(e,t,l,r)}if(o=(l&e.childLanes)!==0,Sn||o){if(r=Ht,r!==null){switch(l&-l){case 4:i=2;break;case 16:i=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:i=32;break;case 536870912:i=268435456;break;default:i=0}i=i&(r.suspendedLanes|l)?0:i,i!==0&&i!==a.retryLane&&(a.retryLane=i,ur(e,i),xs(r,e,i,-1))}return Mg(),r=Oh(Error(re(421))),vc(e,t,l,r)}return i.data==="$?"?(t.flags|=128,t.child=e.child,t=sI.bind(null,e),i._reactRetry=t,null):(e=a.treeContext,Fn=zr(i.nextSibling),Un=t,dt=!0,ms=null,e!==null&&(ts[ns++]=nr,ts[ns++]=sr,ts[ns++]=Ii,nr=e.id,sr=e.overflow,Ii=t),t=Ag(t,r.children),t.flags|=4096,t)}function qj(e,t,s){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),om(e.return,t,s)}function Dh(e,t,s,r,i){var a=e.memoizedState;a===null?e.memoizedState={isBackwards:t,rendering:null,renderingStartTime:0,last:r,tail:s,tailMode:i}:(a.isBackwards=t,a.rendering=null,a.renderingStartTime=0,a.last=r,a.tail=s,a.tailMode=i)}function pk(e,t,s){var r=t.pendingProps,i=r.revealOrder,a=r.tail;if(gn(e,t,r.children,s),r=ft.current,r&2)r=r&1|2,t.flags|=128;else{if(e!==null&&e.flags&128)e:for(e=t.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&qj(e,s,t);else if(e.tag===19)qj(e,s,t);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break e;for(;e.sibling===null;){if(e.return===null||e.return===t)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}if(rt(ft,r),!(t.mode&1))t.memoizedState=null;else switch(i){case"forwards":for(s=t.child,i=null;s!==null;)e=s.alternate,e!==null&&Ou(e)===null&&(i=s),s=s.sibling;s=i,s===null?(i=t.child,t.child=null):(i=s.sibling,s.sibling=null),Dh(t,!1,i,s,a);break;case"backwards":for(s=null,i=t.child,t.child=null;i!==null;){if(e=i.alternate,e!==null&&Ou(e)===null){t.child=i;break}e=i.sibling,i.sibling=s,s=i,i=e}Dh(t,!0,s,null,a);break;case"together":Dh(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function nu(e,t){!(t.mode&1)&&e!==null&&(e.alternate=null,t.alternate=null,t.flags|=2)}function dr(e,t,s){if(e!==null&&(t.dependencies=e.dependencies),$i|=t.lanes,!(s&t.childLanes))return null;if(e!==null&&t.child!==e.child)throw Error(re(153));if(t.child!==null){for(e=t.child,s=Hr(e,e.pendingProps),t.child=s,s.return=t;e.sibling!==null;)e=e.sibling,s=s.sibling=Hr(e,e.pendingProps),s.return=t;s.sibling=null}return t.child}function KR(e,t,s){switch(t.tag){case 3:fk(t),Da();break;case 5:U0(t);break;case 1:En(t.type)&&Tu(t);break;case 4:wg(t,t.stateNode.containerInfo);break;case 10:var r=t.type._context,i=t.memoizedProps.value;rt(Pu,r._currentValue),r._currentValue=i;break;case 13:if(r=t.memoizedState,r!==null)return r.dehydrated!==null?(rt(ft,ft.current&1),t.flags|=128,null):s&t.child.childLanes?mk(e,t,s):(rt(ft,ft.current&1),e=dr(e,t,s),e!==null?e.sibling:null);rt(ft,ft.current&1);break;case 19:if(r=(s&t.childLanes)!==0,e.flags&128){if(r)return pk(e,t,s);t.flags|=128}if(i=t.memoizedState,i!==null&&(i.rendering=null,i.tail=null,i.lastEffect=null),rt(ft,ft.current),r)break;return null;case 22:case 23:return t.lanes=0,dk(e,t,s)}return dr(e,t,s)}var gk,gm,xk,vk;gk=function(e,t){for(var s=t.child;s!==null;){if(s.tag===5||s.tag===6)e.appendChild(s.stateNode);else if(s.tag!==4&&s.child!==null){s.child.return=s,s=s.child;continue}if(s===t)break;for(;s.sibling===null;){if(s.return===null||s.return===t)return;s=s.return}s.sibling.return=s.return,s=s.sibling}};gm=function(){};xk=function(e,t,s,r){var i=e.memoizedProps;if(i!==r){e=t.stateNode,Si(Us.current);var a=null;switch(s){case"input":i=Lf(e,i),r=Lf(e,r),a=[];break;case"select":i=vt({},i,{value:void 0}),r=vt({},r,{value:void 0}),a=[];break;case"textarea":i=Uf(e,i),r=Uf(e,r),a=[];break;default:typeof i.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=Eu)}Wf(s,r);var l;s=null;for(u in i)if(!r.hasOwnProperty(u)&&i.hasOwnProperty(u)&&i[u]!=null)if(u==="style"){var o=i[u];for(l in o)o.hasOwnProperty(l)&&(s||(s={}),s[l]="")}else u!=="dangerouslySetInnerHTML"&&u!=="children"&&u!=="suppressContentEditableWarning"&&u!=="suppressHydrationWarning"&&u!=="autoFocus"&&(Xl.hasOwnProperty(u)?a||(a=[]):(a=a||[]).push(u,null));for(u in r){var c=r[u];if(o=i!=null?i[u]:void 0,r.hasOwnProperty(u)&&c!==o&&(c!=null||o!=null))if(u==="style")if(o){for(l in o)!o.hasOwnProperty(l)||c&&c.hasOwnProperty(l)||(s||(s={}),s[l]="");for(l in c)c.hasOwnProperty(l)&&o[l]!==c[l]&&(s||(s={}),s[l]=c[l])}else s||(a||(a=[]),a.push(u,s)),s=c;else u==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,o=o?o.__html:void 0,c!=null&&o!==c&&(a=a||[]).push(u,c)):u==="children"?typeof c!="string"&&typeof c!="number"||(a=a||[]).push(u,""+c):u!=="suppressContentEditableWarning"&&u!=="suppressHydrationWarning"&&(Xl.hasOwnProperty(u)?(c!=null&&u==="onScroll"&&lt("scroll",e),a||o===c||(a=[])):(a=a||[]).push(u,c))}s&&(a=a||[]).push("style",s);var u=a;(t.updateQueue=u)&&(t.flags|=4)}};vk=function(e,t,s,r){s!==r&&(t.flags|=4)};function Sl(e,t){if(!dt)switch(e.tailMode){case"hidden":t=e.tail;for(var s=null;t!==null;)t.alternate!==null&&(s=t),t=t.sibling;s===null?e.tail=null:s.sibling=null;break;case"collapsed":s=e.tail;for(var r=null;s!==null;)s.alternate!==null&&(r=s),s=s.sibling;r===null?t||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function on(e){var t=e.alternate!==null&&e.alternate.child===e.child,s=0,r=0;if(t)for(var i=e.child;i!==null;)s|=i.lanes|i.childLanes,r|=i.subtreeFlags&14680064,r|=i.flags&14680064,i.return=e,i=i.sibling;else for(i=e.child;i!==null;)s|=i.lanes|i.childLanes,r|=i.subtreeFlags,r|=i.flags,i.return=e,i=i.sibling;return e.subtreeFlags|=r,e.childLanes=s,t}function VR(e,t,s){var r=t.pendingProps;switch(fg(t),t.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return on(t),null;case 1:return En(t.type)&&Au(),on(t),null;case 3:return r=t.stateNode,La(),ot(Cn),ot(fn),bg(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(gc(t)?t.flags|=4:e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,ms!==null&&(Sm(ms),ms=null))),gm(e,t),on(t),null;case 5:yg(t);var i=Si(uo.current);if(s=t.type,e!==null&&t.stateNode!=null)xk(e,t,s,r,i),e.ref!==t.ref&&(t.flags|=512,t.flags|=2097152);else{if(!r){if(t.stateNode===null)throw Error(re(166));return on(t),null}if(e=Si(Us.current),gc(t)){r=t.stateNode,s=t.type;var a=t.memoizedProps;switch(r[Ds]=t,r[oo]=a,e=(t.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(i=0;i<Ol.length;i++)lt(Ol[i],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":rj(r,a),lt("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!a.multiple},lt("invalid",r);break;case"textarea":aj(r,a),lt("invalid",r)}Wf(s,a),i=null;for(var l in a)if(a.hasOwnProperty(l)){var o=a[l];l==="children"?typeof o=="string"?r.textContent!==o&&(a.suppressHydrationWarning!==!0&&pc(r.textContent,o,e),i=["children",o]):typeof o=="number"&&r.textContent!==""+o&&(a.suppressHydrationWarning!==!0&&pc(r.textContent,o,e),i=["children",""+o]):Xl.hasOwnProperty(l)&&o!=null&&l==="onScroll"&&lt("scroll",r)}switch(s){case"input":lc(r),ij(r,a,!0);break;case"textarea":lc(r),lj(r);break;case"select":case"option":break;default:typeof a.onClick=="function"&&(r.onclick=Eu)}r=i,t.updateQueue=r,r!==null&&(t.flags|=4)}else{l=i.nodeType===9?i:i.ownerDocument,e==="http://www.w3.org/1999/xhtml"&&(e=Vb(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[Ds]=t,e[oo]=r,gk(e,t,!1,!1),t.stateNode=e;e:{switch(l=Hf(s,r),s){case"dialog":lt("cancel",e),lt("close",e),i=r;break;case"iframe":case"object":case"embed":lt("load",e),i=r;break;case"video":case"audio":for(i=0;i<Ol.length;i++)lt(Ol[i],e);i=r;break;case"source":lt("error",e),i=r;break;case"img":case"image":case"link":lt("error",e),lt("load",e),i=r;break;case"details":lt("toggle",e),i=r;break;case"input":rj(e,r),i=Lf(e,r),lt("invalid",e);break;case"option":i=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},i=vt({},r,{value:void 0}),lt("invalid",e);break;case"textarea":aj(e,r),i=Uf(e,r),lt("invalid",e);break;default:i=r}Wf(s,i),o=i;for(a in o)if(o.hasOwnProperty(a)){var c=o[a];a==="style"?qb(e,c):a==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,c!=null&&Gb(e,c)):a==="children"?typeof c=="string"?(s!=="textarea"||c!=="")&&Zl(e,c):typeof c=="number"&&Zl(e,""+c):a!=="suppressContentEditableWarning"&&a!=="suppressHydrationWarning"&&a!=="autoFocus"&&(Xl.hasOwnProperty(a)?c!=null&&a==="onScroll"&&lt("scroll",e):c!=null&&Xp(e,a,c,l))}switch(s){case"input":lc(e),ij(e,r,!1);break;case"textarea":lc(e),lj(e);break;case"option":r.value!=null&&e.setAttribute("value",""+Qr(r.value));break;case"select":e.multiple=!!r.multiple,a=r.value,a!=null?ba(e,!!r.multiple,a,!1):r.defaultValue!=null&&ba(e,!!r.multiple,r.defaultValue,!0);break;default:typeof i.onClick=="function"&&(e.onclick=Eu)}switch(s){case"button":case"input":case"select":case"textarea":r=!!r.autoFocus;break e;case"img":r=!0;break e;default:r=!1}}r&&(t.flags|=4)}t.ref!==null&&(t.flags|=512,t.flags|=2097152)}return on(t),null;case 6:if(e&&t.stateNode!=null)vk(e,t,e.memoizedProps,r);else{if(typeof r!="string"&&t.stateNode===null)throw Error(re(166));if(s=Si(uo.current),Si(Us.current),gc(t)){if(r=t.stateNode,s=t.memoizedProps,r[Ds]=t,(a=r.nodeValue!==s)&&(e=Un,e!==null))switch(e.tag){case 3:pc(r.nodeValue,s,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&pc(r.nodeValue,s,(e.mode&1)!==0)}a&&(t.flags|=4)}else r=(s.nodeType===9?s:s.ownerDocument).createTextNode(r),r[Ds]=t,t.stateNode=r}return on(t),null;case 13:if(ot(ft),r=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(dt&&Fn!==null&&t.mode&1&&!(t.flags&128))D0(),Da(),t.flags|=98560,a=!1;else if(a=gc(t),r!==null&&r.dehydrated!==null){if(e===null){if(!a)throw Error(re(318));if(a=t.memoizedState,a=a!==null?a.dehydrated:null,!a)throw Error(re(317));a[Ds]=t}else Da(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;on(t),a=!1}else ms!==null&&(Sm(ms),ms=null),a=!0;if(!a)return t.flags&65536?t:null}return t.flags&128?(t.lanes=s,t):(r=r!==null,r!==(e!==null&&e.memoizedState!==null)&&r&&(t.child.flags|=8192,t.mode&1&&(e===null||ft.current&1?Lt===0&&(Lt=3):Mg())),t.updateQueue!==null&&(t.flags|=4),on(t),null);case 4:return La(),gm(e,t),e===null&&ao(t.stateNode.containerInfo),on(t),null;case 10:return xg(t.type._context),on(t),null;case 17:return En(t.type)&&Au(),on(t),null;case 19:if(ot(ft),a=t.memoizedState,a===null)return on(t),null;if(r=(t.flags&128)!==0,l=a.rendering,l===null)if(r)Sl(a,!1);else{if(Lt!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(l=Ou(e),l!==null){for(t.flags|=128,Sl(a,!1),r=l.updateQueue,r!==null&&(t.updateQueue=r,t.flags|=4),t.subtreeFlags=0,r=s,s=t.child;s!==null;)a=s,e=r,a.flags&=14680066,l=a.alternate,l===null?(a.childLanes=0,a.lanes=e,a.child=null,a.subtreeFlags=0,a.memoizedProps=null,a.memoizedState=null,a.updateQueue=null,a.dependencies=null,a.stateNode=null):(a.childLanes=l.childLanes,a.lanes=l.lanes,a.child=l.child,a.subtreeFlags=0,a.deletions=null,a.memoizedProps=l.memoizedProps,a.memoizedState=l.memoizedState,a.updateQueue=l.updateQueue,a.type=l.type,e=l.dependencies,a.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext}),s=s.sibling;return rt(ft,ft.current&1|2),t.child}e=e.sibling}a.tail!==null&&Et()>za&&(t.flags|=128,r=!0,Sl(a,!1),t.lanes=4194304)}else{if(!r)if(e=Ou(l),e!==null){if(t.flags|=128,r=!0,s=e.updateQueue,s!==null&&(t.updateQueue=s,t.flags|=4),Sl(a,!0),a.tail===null&&a.tailMode==="hidden"&&!l.alternate&&!dt)return on(t),null}else 2*Et()-a.renderingStartTime>za&&s!==1073741824&&(t.flags|=128,r=!0,Sl(a,!1),t.lanes=4194304);a.isBackwards?(l.sibling=t.child,t.child=l):(s=a.last,s!==null?s.sibling=l:t.child=l,a.last=l)}return a.tail!==null?(t=a.tail,a.rendering=t,a.tail=t.sibling,a.renderingStartTime=Et(),t.sibling=null,s=ft.current,rt(ft,r?s&1|2:s&1),t):(on(t),null);case 22:case 23:return $g(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?_n&1073741824&&(on(t),t.subtreeFlags&6&&(t.flags|=8192)):on(t),null;case 24:return null;case 25:return null}throw Error(re(156,t.tag))}function GR(e,t){switch(fg(t),t.tag){case 1:return En(t.type)&&Au(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return La(),ot(Cn),ot(fn),bg(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return yg(t),null;case 13:if(ot(ft),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(re(340));Da()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return ot(ft),null;case 4:return La(),null;case 10:return xg(t.type._context),null;case 22:case 23:return $g(),null;case 24:return null;default:return null}}var jc=!1,un=!1,YR=typeof WeakSet=="function"?WeakSet:Set,je=null;function va(e,t){var s=e.ref;if(s!==null)if(typeof s=="function")try{s(null)}catch(r){kt(e,t,r)}else s.current=null}function xm(e,t,s){try{s()}catch(r){kt(e,t,r)}}var Qj=!1;function qR(e,t){if(em=Su,e=k0(),dg(e)){if("selectionStart"in e)var s={start:e.selectionStart,end:e.selectionEnd};else e:{s=(s=e.ownerDocument)&&s.defaultView||window;var r=s.getSelection&&s.getSelection();if(r&&r.rangeCount!==0){s=r.anchorNode;var i=r.anchorOffset,a=r.focusNode;r=r.focusOffset;try{s.nodeType,a.nodeType}catch{s=null;break e}var l=0,o=-1,c=-1,u=0,h=0,d=e,m=null;t:for(;;){for(var p;d!==s||i!==0&&d.nodeType!==3||(o=l+i),d!==a||r!==0&&d.nodeType!==3||(c=l+r),d.nodeType===3&&(l+=d.nodeValue.length),(p=d.firstChild)!==null;)m=d,d=p;for(;;){if(d===e)break t;if(m===s&&++u===i&&(o=l),m===a&&++h===r&&(c=l),(p=d.nextSibling)!==null)break;d=m,m=d.parentNode}d=p}s=o===-1||c===-1?null:{start:o,end:c}}else s=null}s=s||{start:0,end:0}}else s=null;for(tm={focusedElem:e,selectionRange:s},Su=!1,je=t;je!==null;)if(t=je,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,je=e;else for(;je!==null;){t=je;try{var x=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(x!==null){var j=x.memoizedProps,b=x.memoizedState,g=t.stateNode,v=g.getSnapshotBeforeUpdate(t.elementType===t.type?j:hs(t.type,j),b);g.__reactInternalSnapshotBeforeUpdate=v}break;case 3:var w=t.stateNode.containerInfo;w.nodeType===1?w.textContent="":w.nodeType===9&&w.documentElement&&w.removeChild(w.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(re(163))}}catch(y){kt(t,t.return,y)}if(e=t.sibling,e!==null){e.return=t.return,je=e;break}je=t.return}return x=Qj,Qj=!1,x}function Hl(e,t,s){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var i=r=r.next;do{if((i.tag&e)===e){var a=i.destroy;i.destroy=void 0,a!==void 0&&xm(t,s,a)}i=i.next}while(i!==r)}}function bd(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var s=t=t.next;do{if((s.tag&e)===e){var r=s.create;s.destroy=r()}s=s.next}while(s!==t)}}function vm(e){var t=e.ref;if(t!==null){var s=e.stateNode;switch(e.tag){case 5:e=s;break;default:e=s}typeof t=="function"?t(e):t.current=e}}function jk(e){var t=e.alternate;t!==null&&(e.alternate=null,jk(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Ds],delete t[oo],delete t[rm],delete t[IR],delete t[PR])),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 wk(e){return e.tag===5||e.tag===3||e.tag===4}function Jj(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||wk(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 jm(e,t,s){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?s.nodeType===8?s.parentNode.insertBefore(e,t):s.insertBefore(e,t):(s.nodeType===8?(t=s.parentNode,t.insertBefore(e,s)):(t=s,t.appendChild(e)),s=s._reactRootContainer,s!=null||t.onclick!==null||(t.onclick=Eu));else if(r!==4&&(e=e.child,e!==null))for(jm(e,t,s),e=e.sibling;e!==null;)jm(e,t,s),e=e.sibling}function wm(e,t,s){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?s.insertBefore(e,t):s.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(wm(e,t,s),e=e.sibling;e!==null;)wm(e,t,s),e=e.sibling}var Qt=null,fs=!1;function Cr(e,t,s){for(s=s.child;s!==null;)yk(e,t,s),s=s.sibling}function yk(e,t,s){if(zs&&typeof zs.onCommitFiberUnmount=="function")try{zs.onCommitFiberUnmount(md,s)}catch{}switch(s.tag){case 5:un||va(s,t);case 6:var r=Qt,i=fs;Qt=null,Cr(e,t,s),Qt=r,fs=i,Qt!==null&&(fs?(e=Qt,s=s.stateNode,e.nodeType===8?e.parentNode.removeChild(s):e.removeChild(s)):Qt.removeChild(s.stateNode));break;case 18:Qt!==null&&(fs?(e=Qt,s=s.stateNode,e.nodeType===8?Th(e.parentNode,s):e.nodeType===1&&Th(e,s),so(e)):Th(Qt,s.stateNode));break;case 4:r=Qt,i=fs,Qt=s.stateNode.containerInfo,fs=!0,Cr(e,t,s),Qt=r,fs=i;break;case 0:case 11:case 14:case 15:if(!un&&(r=s.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){i=r=r.next;do{var a=i,l=a.destroy;a=a.tag,l!==void 0&&(a&2||a&4)&&xm(s,t,l),i=i.next}while(i!==r)}Cr(e,t,s);break;case 1:if(!un&&(va(s,t),r=s.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=s.memoizedProps,r.state=s.memoizedState,r.componentWillUnmount()}catch(o){kt(s,t,o)}Cr(e,t,s);break;case 21:Cr(e,t,s);break;case 22:s.mode&1?(un=(r=un)||s.memoizedState!==null,Cr(e,t,s),un=r):Cr(e,t,s);break;default:Cr(e,t,s)}}function Xj(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var s=e.stateNode;s===null&&(s=e.stateNode=new YR),t.forEach(function(r){var i=rI.bind(null,e,r);s.has(r)||(s.add(r),r.then(i,i))})}}function ds(e,t){var s=t.deletions;if(s!==null)for(var r=0;r<s.length;r++){var i=s[r];try{var a=e,l=t,o=l;e:for(;o!==null;){switch(o.tag){case 5:Qt=o.stateNode,fs=!1;break e;case 3:Qt=o.stateNode.containerInfo,fs=!0;break e;case 4:Qt=o.stateNode.containerInfo,fs=!0;break e}o=o.return}if(Qt===null)throw Error(re(160));yk(a,l,i),Qt=null,fs=!1;var c=i.alternate;c!==null&&(c.return=null),i.return=null}catch(u){kt(i,t,u)}}if(t.subtreeFlags&12854)for(t=t.child;t!==null;)bk(t,e),t=t.sibling}function bk(e,t){var s=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(ds(t,e),Ps(e),r&4){try{Hl(3,e,e.return),bd(3,e)}catch(j){kt(e,e.return,j)}try{Hl(5,e,e.return)}catch(j){kt(e,e.return,j)}}break;case 1:ds(t,e),Ps(e),r&512&&s!==null&&va(s,s.return);break;case 5:if(ds(t,e),Ps(e),r&512&&s!==null&&va(s,s.return),e.flags&32){var i=e.stateNode;try{Zl(i,"")}catch(j){kt(e,e.return,j)}}if(r&4&&(i=e.stateNode,i!=null)){var a=e.memoizedProps,l=s!==null?s.memoizedProps:a,o=e.type,c=e.updateQueue;if(e.updateQueue=null,c!==null)try{o==="input"&&a.type==="radio"&&a.name!=null&&Hb(i,a),Hf(o,l);var u=Hf(o,a);for(l=0;l<c.length;l+=2){var h=c[l],d=c[l+1];h==="style"?qb(i,d):h==="dangerouslySetInnerHTML"?Gb(i,d):h==="children"?Zl(i,d):Xp(i,h,d,u)}switch(o){case"input":Ff(i,a);break;case"textarea":Kb(i,a);break;case"select":var m=i._wrapperState.wasMultiple;i._wrapperState.wasMultiple=!!a.multiple;var p=a.value;p!=null?ba(i,!!a.multiple,p,!1):m!==!!a.multiple&&(a.defaultValue!=null?ba(i,!!a.multiple,a.defaultValue,!0):ba(i,!!a.multiple,a.multiple?[]:"",!1))}i[oo]=a}catch(j){kt(e,e.return,j)}}break;case 6:if(ds(t,e),Ps(e),r&4){if(e.stateNode===null)throw Error(re(162));i=e.stateNode,a=e.memoizedProps;try{i.nodeValue=a}catch(j){kt(e,e.return,j)}}break;case 3:if(ds(t,e),Ps(e),r&4&&s!==null&&s.memoizedState.isDehydrated)try{so(t.containerInfo)}catch(j){kt(e,e.return,j)}break;case 4:ds(t,e),Ps(e);break;case 13:ds(t,e),Ps(e),i=e.child,i.flags&8192&&(a=i.memoizedState!==null,i.stateNode.isHidden=a,!a||i.alternate!==null&&i.alternate.memoizedState!==null||(Ig=Et())),r&4&&Xj(e);break;case 22:if(h=s!==null&&s.memoizedState!==null,e.mode&1?(un=(u=un)||h,ds(t,e),un=u):ds(t,e),Ps(e),r&8192){if(u=e.memoizedState!==null,(e.stateNode.isHidden=u)&&!h&&e.mode&1)for(je=e,h=e.child;h!==null;){for(d=je=h;je!==null;){switch(m=je,p=m.child,m.tag){case 0:case 11:case 14:case 15:Hl(4,m,m.return);break;case 1:va(m,m.return);var x=m.stateNode;if(typeof x.componentWillUnmount=="function"){r=m,s=m.return;try{t=r,x.props=t.memoizedProps,x.state=t.memoizedState,x.componentWillUnmount()}catch(j){kt(r,s,j)}}break;case 5:va(m,m.return);break;case 22:if(m.memoizedState!==null){ew(d);continue}}p!==null?(p.return=m,je=p):ew(d)}h=h.sibling}e:for(h=null,d=e;;){if(d.tag===5){if(h===null){h=d;try{i=d.stateNode,u?(a=i.style,typeof a.setProperty=="function"?a.setProperty("display","none","important"):a.display="none"):(o=d.stateNode,c=d.memoizedProps.style,l=c!=null&&c.hasOwnProperty("display")?c.display:null,o.style.display=Yb("display",l))}catch(j){kt(e,e.return,j)}}}else if(d.tag===6){if(h===null)try{d.stateNode.nodeValue=u?"":d.memoizedProps}catch(j){kt(e,e.return,j)}}else if((d.tag!==22&&d.tag!==23||d.memoizedState===null||d===e)&&d.child!==null){d.child.return=d,d=d.child;continue}if(d===e)break e;for(;d.sibling===null;){if(d.return===null||d.return===e)break e;h===d&&(h=null),d=d.return}h===d&&(h=null),d.sibling.return=d.return,d=d.sibling}}break;case 19:ds(t,e),Ps(e),r&4&&Xj(e);break;case 21:break;default:ds(t,e),Ps(e)}}function Ps(e){var t=e.flags;if(t&2){try{e:{for(var s=e.return;s!==null;){if(wk(s)){var r=s;break e}s=s.return}throw Error(re(160))}switch(r.tag){case 5:var i=r.stateNode;r.flags&32&&(Zl(i,""),r.flags&=-33);var a=Jj(e);wm(e,a,i);break;case 3:case 4:var l=r.stateNode.containerInfo,o=Jj(e);jm(e,o,l);break;default:throw Error(re(161))}}catch(c){kt(e,e.return,c)}e.flags&=-3}t&4096&&(e.flags&=-4097)}function QR(e,t,s){je=e,kk(e)}function kk(e,t,s){for(var r=(e.mode&1)!==0;je!==null;){var i=je,a=i.child;if(i.tag===22&&r){var l=i.memoizedState!==null||jc;if(!l){var o=i.alternate,c=o!==null&&o.memoizedState!==null||un;o=jc;var u=un;if(jc=l,(un=c)&&!u)for(je=i;je!==null;)l=je,c=l.child,l.tag===22&&l.memoizedState!==null?tw(i):c!==null?(c.return=l,je=c):tw(i);for(;a!==null;)je=a,kk(a),a=a.sibling;je=i,jc=o,un=u}Zj(e)}else i.subtreeFlags&8772&&a!==null?(a.return=i,je=a):Zj(e)}}function Zj(e){for(;je!==null;){var t=je;if(t.flags&8772){var s=t.alternate;try{if(t.flags&8772)switch(t.tag){case 0:case 11:case 15:un||bd(5,t);break;case 1:var r=t.stateNode;if(t.flags&4&&!un)if(s===null)r.componentDidMount();else{var i=t.elementType===t.type?s.memoizedProps:hs(t.type,s.memoizedProps);r.componentDidUpdate(i,s.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var a=t.updateQueue;a!==null&&_j(t,a,r);break;case 3:var l=t.updateQueue;if(l!==null){if(s=null,t.child!==null)switch(t.child.tag){case 5:s=t.child.stateNode;break;case 1:s=t.child.stateNode}_j(t,l,s)}break;case 5:var o=t.stateNode;if(s===null&&t.flags&4){s=o;var c=t.memoizedProps;switch(t.type){case"button":case"input":case"select":case"textarea":c.autoFocus&&s.focus();break;case"img":c.src&&(s.src=c.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(t.memoizedState===null){var u=t.alternate;if(u!==null){var h=u.memoizedState;if(h!==null){var d=h.dehydrated;d!==null&&so(d)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(re(163))}un||t.flags&512&&vm(t)}catch(m){kt(t,t.return,m)}}if(t===e){je=null;break}if(s=t.sibling,s!==null){s.return=t.return,je=s;break}je=t.return}}function ew(e){for(;je!==null;){var t=je;if(t===e){je=null;break}var s=t.sibling;if(s!==null){s.return=t.return,je=s;break}je=t.return}}function tw(e){for(;je!==null;){var t=je;try{switch(t.tag){case 0:case 11:case 15:var s=t.return;try{bd(4,t)}catch(c){kt(t,s,c)}break;case 1:var r=t.stateNode;if(typeof r.componentDidMount=="function"){var i=t.return;try{r.componentDidMount()}catch(c){kt(t,i,c)}}var a=t.return;try{vm(t)}catch(c){kt(t,a,c)}break;case 5:var l=t.return;try{vm(t)}catch(c){kt(t,l,c)}}}catch(c){kt(t,t.return,c)}if(t===e){je=null;break}var o=t.sibling;if(o!==null){o.return=t.return,je=o;break}je=t.return}}var JR=Math.ceil,Lu=gr.ReactCurrentDispatcher,Tg=gr.ReactCurrentOwner,as=gr.ReactCurrentBatchConfig,He=0,Ht=null,Pt=null,Jt=0,_n=0,ja=ai(0),Lt=0,po=null,$i=0,kd=0,Rg=0,Kl=null,kn=null,Ig=0,za=1/0,Xs=null,Fu=!1,ym=null,Br=null,wc=!1,$r=null,zu=0,Vl=0,bm=null,su=-1,ru=0;function vn(){return He&6?Et():su!==-1?su:su=Et()}function Wr(e){return e.mode&1?He&2&&Jt!==0?Jt&-Jt:MR.transition!==null?(ru===0&&(ru=l0()),ru):(e=Xe,e!==0||(e=window.event,e=e===void 0?16:m0(e.type)),e):1}function xs(e,t,s,r){if(50<Vl)throw Vl=0,bm=null,Error(re(185));Oo(e,s,r),(!(He&2)||e!==Ht)&&(e===Ht&&(!(He&2)&&(kd|=s),Lt===4&&Ir(e,Jt)),An(e,r),s===1&&He===0&&!(t.mode&1)&&(za=Et()+500,jd&&li()))}function An(e,t){var s=e.callbackNode;MT(e,t);var r=ku(e,e===Ht?Jt:0);if(r===0)s!==null&&uj(s),e.callbackNode=null,e.callbackPriority=0;else if(t=r&-r,e.callbackPriority!==t){if(s!=null&&uj(s),t===1)e.tag===0?$R(nw.bind(null,e)):$0(nw.bind(null,e)),TR(function(){!(He&6)&&li()}),s=null;else{switch(o0(r)){case 1:s=sg;break;case 4:s=i0;break;case 16:s=bu;break;case 536870912:s=a0;break;default:s=bu}s=Ik(s,Sk.bind(null,e))}e.callbackPriority=t,e.callbackNode=s}}function Sk(e,t){if(su=-1,ru=0,He&6)throw Error(re(327));var s=e.callbackNode;if(Ea()&&e.callbackNode!==s)return null;var r=ku(e,e===Ht?Jt:0);if(r===0)return null;if(r&30||r&e.expiredLanes||t)t=Uu(e,r);else{t=r;var i=He;He|=2;var a=Ck();(Ht!==e||Jt!==t)&&(Xs=null,za=Et()+500,Ni(e,t));do try{eI();break}catch(o){Nk(e,o)}while(!0);gg(),Lu.current=a,He=i,Pt!==null?t=0:(Ht=null,Jt=0,t=Lt)}if(t!==0){if(t===2&&(i=qf(e),i!==0&&(r=i,t=km(e,i))),t===1)throw s=po,Ni(e,0),Ir(e,r),An(e,Et()),s;if(t===6)Ir(e,r);else{if(i=e.current.alternate,!(r&30)&&!XR(i)&&(t=Uu(e,r),t===2&&(a=qf(e),a!==0&&(r=a,t=km(e,a))),t===1))throw s=po,Ni(e,0),Ir(e,r),An(e,Et()),s;switch(e.finishedWork=i,e.finishedLanes=r,t){case 0:case 1:throw Error(re(345));case 2:ji(e,kn,Xs);break;case 3:if(Ir(e,r),(r&130023424)===r&&(t=Ig+500-Et(),10<t)){if(ku(e,0)!==0)break;if(i=e.suspendedLanes,(i&r)!==r){vn(),e.pingedLanes|=e.suspendedLanes&i;break}e.timeoutHandle=sm(ji.bind(null,e,kn,Xs),t);break}ji(e,kn,Xs);break;case 4:if(Ir(e,r),(r&4194240)===r)break;for(t=e.eventTimes,i=-1;0<r;){var l=31-gs(r);a=1<<l,l=t[l],l>i&&(i=l),r&=~a}if(r=i,r=Et()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*JR(r/1960))-r,10<r){e.timeoutHandle=sm(ji.bind(null,e,kn,Xs),r);break}ji(e,kn,Xs);break;case 5:ji(e,kn,Xs);break;default:throw Error(re(329))}}}return An(e,Et()),e.callbackNode===s?Sk.bind(null,e):null}function km(e,t){var s=Kl;return e.current.memoizedState.isDehydrated&&(Ni(e,t).flags|=256),e=Uu(e,t),e!==2&&(t=kn,kn=s,t!==null&&Sm(t)),e}function Sm(e){kn===null?kn=e:kn.push.apply(kn,e)}function XR(e){for(var t=e;;){if(t.flags&16384){var s=t.updateQueue;if(s!==null&&(s=s.stores,s!==null))for(var r=0;r<s.length;r++){var i=s[r],a=i.getSnapshot;i=i.value;try{if(!ys(a(),i))return!1}catch{return!1}}}if(s=t.child,t.subtreeFlags&16384&&s!==null)s.return=t,t=s;else{if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return!0;t=t.return}t.sibling.return=t.return,t=t.sibling}}return!0}function Ir(e,t){for(t&=~Rg,t&=~kd,e.suspendedLanes|=t,e.pingedLanes&=~t,e=e.expirationTimes;0<t;){var s=31-gs(t),r=1<<s;e[s]=-1,t&=~r}}function nw(e){if(He&6)throw Error(re(327));Ea();var t=ku(e,0);if(!(t&1))return An(e,Et()),null;var s=Uu(e,t);if(e.tag!==0&&s===2){var r=qf(e);r!==0&&(t=r,s=km(e,r))}if(s===1)throw s=po,Ni(e,0),Ir(e,t),An(e,Et()),s;if(s===6)throw Error(re(345));return e.finishedWork=e.current.alternate,e.finishedLanes=t,ji(e,kn,Xs),An(e,Et()),null}function Pg(e,t){var s=He;He|=1;try{return e(t)}finally{He=s,He===0&&(za=Et()+500,jd&&li())}}function Mi(e){$r!==null&&$r.tag===0&&!(He&6)&&Ea();var t=He;He|=1;var s=as.transition,r=Xe;try{if(as.transition=null,Xe=1,e)return e()}finally{Xe=r,as.transition=s,He=t,!(He&6)&&li()}}function $g(){_n=ja.current,ot(ja)}function Ni(e,t){e.finishedWork=null,e.finishedLanes=0;var s=e.timeoutHandle;if(s!==-1&&(e.timeoutHandle=-1,AR(s)),Pt!==null)for(s=Pt.return;s!==null;){var r=s;switch(fg(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Au();break;case 3:La(),ot(Cn),ot(fn),bg();break;case 5:yg(r);break;case 4:La();break;case 13:ot(ft);break;case 19:ot(ft);break;case 10:xg(r.type._context);break;case 22:case 23:$g()}s=s.return}if(Ht=e,Pt=e=Hr(e.current,null),Jt=_n=t,Lt=0,po=null,Rg=kd=$i=0,kn=Kl=null,ki!==null){for(t=0;t<ki.length;t++)if(s=ki[t],r=s.interleaved,r!==null){s.interleaved=null;var i=r.next,a=s.pending;if(a!==null){var l=a.next;a.next=i,r.next=l}s.pending=r}ki=null}return e}function Nk(e,t){do{var s=Pt;try{if(gg(),eu.current=_u,Du){for(var r=gt.memoizedState;r!==null;){var i=r.queue;i!==null&&(i.pending=null),r=r.next}Du=!1}if(Pi=0,Ut=Ot=gt=null,Wl=!1,ho=0,Tg.current=null,s===null||s.return===null){Lt=1,po=t,Pt=null;break}e:{var a=e,l=s.return,o=s,c=t;if(t=Jt,o.flags|=32768,c!==null&&typeof c=="object"&&typeof c.then=="function"){var u=c,h=o,d=h.tag;if(!(h.mode&1)&&(d===0||d===11||d===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=Wj(l);if(p!==null){p.flags&=-257,Hj(p,l,o,a,t),p.mode&1&&Bj(a,u,t),t=p,c=u;var x=t.updateQueue;if(x===null){var j=new Set;j.add(c),t.updateQueue=j}else x.add(c);break e}else{if(!(t&1)){Bj(a,u,t),Mg();break e}c=Error(re(426))}}else if(dt&&o.mode&1){var b=Wj(l);if(b!==null){!(b.flags&65536)&&(b.flags|=256),Hj(b,l,o,a,t),mg(Fa(c,o));break e}}a=c=Fa(c,o),Lt!==4&&(Lt=2),Kl===null?Kl=[a]:Kl.push(a),a=l;do{switch(a.tag){case 3:a.flags|=65536,t&=-t,a.lanes|=t;var g=ok(a,c,t);Dj(a,g);break e;case 1:o=c;var v=a.type,w=a.stateNode;if(!(a.flags&128)&&(typeof v.getDerivedStateFromError=="function"||w!==null&&typeof w.componentDidCatch=="function"&&(Br===null||!Br.has(w)))){a.flags|=65536,t&=-t,a.lanes|=t;var y=ck(a,o,t);Dj(a,y);break e}}a=a.return}while(a!==null)}Ak(s)}catch(N){t=N,Pt===s&&s!==null&&(Pt=s=s.return);continue}break}while(!0)}function Ck(){var e=Lu.current;return Lu.current=_u,e===null?_u:e}function Mg(){(Lt===0||Lt===3||Lt===2)&&(Lt=4),Ht===null||!($i&268435455)&&!(kd&268435455)||Ir(Ht,Jt)}function Uu(e,t){var s=He;He|=2;var r=Ck();(Ht!==e||Jt!==t)&&(Xs=null,Ni(e,t));do try{ZR();break}catch(i){Nk(e,i)}while(!0);if(gg(),He=s,Lu.current=r,Pt!==null)throw Error(re(261));return Ht=null,Jt=0,Lt}function ZR(){for(;Pt!==null;)Ek(Pt)}function eI(){for(;Pt!==null&&!NT();)Ek(Pt)}function Ek(e){var t=Rk(e.alternate,e,_n);e.memoizedProps=e.pendingProps,t===null?Ak(e):Pt=t,Tg.current=null}function Ak(e){var t=e;do{var s=t.alternate;if(e=t.return,t.flags&32768){if(s=GR(s,t),s!==null){s.flags&=32767,Pt=s;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{Lt=6,Pt=null;return}}else if(s=VR(s,t,_n),s!==null){Pt=s;return}if(t=t.sibling,t!==null){Pt=t;return}Pt=t=e}while(t!==null);Lt===0&&(Lt=5)}function ji(e,t,s){var r=Xe,i=as.transition;try{as.transition=null,Xe=1,tI(e,t,s,r)}finally{as.transition=i,Xe=r}return null}function tI(e,t,s,r){do Ea();while($r!==null);if(He&6)throw Error(re(327));s=e.finishedWork;var i=e.finishedLanes;if(s===null)return null;if(e.finishedWork=null,e.finishedLanes=0,s===e.current)throw Error(re(177));e.callbackNode=null,e.callbackPriority=0;var a=s.lanes|s.childLanes;if(OT(e,a),e===Ht&&(Pt=Ht=null,Jt=0),!(s.subtreeFlags&2064)&&!(s.flags&2064)||wc||(wc=!0,Ik(bu,function(){return Ea(),null})),a=(s.flags&15990)!==0,s.subtreeFlags&15990||a){a=as.transition,as.transition=null;var l=Xe;Xe=1;var o=He;He|=4,Tg.current=null,qR(e,s),bk(s,e),yR(tm),Su=!!em,tm=em=null,e.current=s,QR(s),CT(),He=o,Xe=l,as.transition=a}else e.current=s;if(wc&&(wc=!1,$r=e,zu=i),a=e.pendingLanes,a===0&&(Br=null),TT(s.stateNode),An(e,Et()),t!==null)for(r=e.onRecoverableError,s=0;s<t.length;s++)i=t[s],r(i.value,{componentStack:i.stack,digest:i.digest});if(Fu)throw Fu=!1,e=ym,ym=null,e;return zu&1&&e.tag!==0&&Ea(),a=e.pendingLanes,a&1?e===bm?Vl++:(Vl=0,bm=e):Vl=0,li(),null}function Ea(){if($r!==null){var e=o0(zu),t=as.transition,s=Xe;try{if(as.transition=null,Xe=16>e?16:e,$r===null)var r=!1;else{if(e=$r,$r=null,zu=0,He&6)throw Error(re(331));var i=He;for(He|=4,je=e.current;je!==null;){var a=je,l=a.child;if(je.flags&16){var o=a.deletions;if(o!==null){for(var c=0;c<o.length;c++){var u=o[c];for(je=u;je!==null;){var h=je;switch(h.tag){case 0:case 11:case 15:Hl(8,h,a)}var d=h.child;if(d!==null)d.return=h,je=d;else for(;je!==null;){h=je;var m=h.sibling,p=h.return;if(jk(h),h===u){je=null;break}if(m!==null){m.return=p,je=m;break}je=p}}}var x=a.alternate;if(x!==null){var j=x.child;if(j!==null){x.child=null;do{var b=j.sibling;j.sibling=null,j=b}while(j!==null)}}je=a}}if(a.subtreeFlags&2064&&l!==null)l.return=a,je=l;else e:for(;je!==null;){if(a=je,a.flags&2048)switch(a.tag){case 0:case 11:case 15:Hl(9,a,a.return)}var g=a.sibling;if(g!==null){g.return=a.return,je=g;break e}je=a.return}}var v=e.current;for(je=v;je!==null;){l=je;var w=l.child;if(l.subtreeFlags&2064&&w!==null)w.return=l,je=w;else e:for(l=v;je!==null;){if(o=je,o.flags&2048)try{switch(o.tag){case 0:case 11:case 15:bd(9,o)}}catch(N){kt(o,o.return,N)}if(o===l){je=null;break e}var y=o.sibling;if(y!==null){y.return=o.return,je=y;break e}je=o.return}}if(He=i,li(),zs&&typeof zs.onPostCommitFiberRoot=="function")try{zs.onPostCommitFiberRoot(md,e)}catch{}r=!0}return r}finally{Xe=s,as.transition=t}}return!1}function sw(e,t,s){t=Fa(s,t),t=ok(e,t,1),e=Ur(e,t,1),t=vn(),e!==null&&(Oo(e,1,t),An(e,t))}function kt(e,t,s){if(e.tag===3)sw(e,e,s);else for(;t!==null;){if(t.tag===3){sw(t,e,s);break}else if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(Br===null||!Br.has(r))){e=Fa(s,e),e=ck(t,e,1),t=Ur(t,e,1),e=vn(),t!==null&&(Oo(t,1,e),An(t,e));break}}t=t.return}}function nI(e,t,s){var r=e.pingCache;r!==null&&r.delete(t),t=vn(),e.pingedLanes|=e.suspendedLanes&s,Ht===e&&(Jt&s)===s&&(Lt===4||Lt===3&&(Jt&130023424)===Jt&&500>Et()-Ig?Ni(e,0):Rg|=s),An(e,t)}function Tk(e,t){t===0&&(e.mode&1?(t=uc,uc<<=1,!(uc&130023424)&&(uc=4194304)):t=1);var s=vn();e=ur(e,t),e!==null&&(Oo(e,t,s),An(e,s))}function sI(e){var t=e.memoizedState,s=0;t!==null&&(s=t.retryLane),Tk(e,s)}function rI(e,t){var s=0;switch(e.tag){case 13:var r=e.stateNode,i=e.memoizedState;i!==null&&(s=i.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(re(314))}r!==null&&r.delete(t),Tk(e,s)}var Rk;Rk=function(e,t,s){if(e!==null)if(e.memoizedProps!==t.pendingProps||Cn.current)Sn=!0;else{if(!(e.lanes&s)&&!(t.flags&128))return Sn=!1,KR(e,t,s);Sn=!!(e.flags&131072)}else Sn=!1,dt&&t.flags&1048576&&M0(t,Iu,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;nu(e,t),e=t.pendingProps;var i=Oa(t,fn.current);Ca(t,s),i=Sg(null,t,r,e,i,s);var a=Ng();return t.flags|=1,typeof i=="object"&&i!==null&&typeof i.render=="function"&&i.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,En(r)?(a=!0,Tu(t)):a=!1,t.memoizedState=i.state!==null&&i.state!==void 0?i.state:null,jg(t),i.updater=yd,t.stateNode=i,i._reactInternals=t,um(t,r,e,s),t=fm(null,t,r,!0,a,s)):(t.tag=0,dt&&a&&hg(t),gn(null,t,i,s),t=t.child),t;case 16:r=t.elementType;e:{switch(nu(e,t),e=t.pendingProps,i=r._init,r=i(r._payload),t.type=r,i=t.tag=aI(r),e=hs(r,e),i){case 0:t=hm(null,t,r,e,s);break e;case 1:t=Gj(null,t,r,e,s);break e;case 11:t=Kj(null,t,r,e,s);break e;case 14:t=Vj(null,t,r,hs(r.type,e),s);break e}throw Error(re(306,r,""))}return t;case 0:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:hs(r,i),hm(e,t,r,i,s);case 1:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:hs(r,i),Gj(e,t,r,i,s);case 3:e:{if(fk(t),e===null)throw Error(re(387));r=t.pendingProps,a=t.memoizedState,i=a.element,z0(e,t),Mu(t,r,null,s);var l=t.memoizedState;if(r=l.element,a.isDehydrated)if(a={element:r,isDehydrated:!1,cache:l.cache,pendingSuspenseBoundaries:l.pendingSuspenseBoundaries,transitions:l.transitions},t.updateQueue.baseState=a,t.memoizedState=a,t.flags&256){i=Fa(Error(re(423)),t),t=Yj(e,t,r,s,i);break e}else if(r!==i){i=Fa(Error(re(424)),t),t=Yj(e,t,r,s,i);break e}else for(Fn=zr(t.stateNode.containerInfo.firstChild),Un=t,dt=!0,ms=null,s=L0(t,null,r,s),t.child=s;s;)s.flags=s.flags&-3|4096,s=s.sibling;else{if(Da(),r===i){t=dr(e,t,s);break e}gn(e,t,r,s)}t=t.child}return t;case 5:return U0(t),e===null&&lm(t),r=t.type,i=t.pendingProps,a=e!==null?e.memoizedProps:null,l=i.children,nm(r,i)?l=null:a!==null&&nm(r,a)&&(t.flags|=32),hk(e,t),gn(e,t,l,s),t.child;case 6:return e===null&&lm(t),null;case 13:return mk(e,t,s);case 4:return wg(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=_a(t,null,r,s):gn(e,t,r,s),t.child;case 11:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:hs(r,i),Kj(e,t,r,i,s);case 7:return gn(e,t,t.pendingProps,s),t.child;case 8:return gn(e,t,t.pendingProps.children,s),t.child;case 12:return gn(e,t,t.pendingProps.children,s),t.child;case 10:e:{if(r=t.type._context,i=t.pendingProps,a=t.memoizedProps,l=i.value,rt(Pu,r._currentValue),r._currentValue=l,a!==null)if(ys(a.value,l)){if(a.children===i.children&&!Cn.current){t=dr(e,t,s);break e}}else for(a=t.child,a!==null&&(a.return=t);a!==null;){var o=a.dependencies;if(o!==null){l=a.child;for(var c=o.firstContext;c!==null;){if(c.context===r){if(a.tag===1){c=rr(-1,s&-s),c.tag=2;var u=a.updateQueue;if(u!==null){u=u.shared;var h=u.pending;h===null?c.next=c:(c.next=h.next,h.next=c),u.pending=c}}a.lanes|=s,c=a.alternate,c!==null&&(c.lanes|=s),om(a.return,s,t),o.lanes|=s;break}c=c.next}}else if(a.tag===10)l=a.type===t.type?null:a.child;else if(a.tag===18){if(l=a.return,l===null)throw Error(re(341));l.lanes|=s,o=l.alternate,o!==null&&(o.lanes|=s),om(l,s,t),l=a.sibling}else l=a.child;if(l!==null)l.return=a;else for(l=a;l!==null;){if(l===t){l=null;break}if(a=l.sibling,a!==null){a.return=l.return,l=a;break}l=l.return}a=l}gn(e,t,i.children,s),t=t.child}return t;case 9:return i=t.type,r=t.pendingProps.children,Ca(t,s),i=os(i),r=r(i),t.flags|=1,gn(e,t,r,s),t.child;case 14:return r=t.type,i=hs(r,t.pendingProps),i=hs(r.type,i),Vj(e,t,r,i,s);case 15:return uk(e,t,t.type,t.pendingProps,s);case 17:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:hs(r,i),nu(e,t),t.tag=1,En(r)?(e=!0,Tu(t)):e=!1,Ca(t,s),lk(t,r,i),um(t,r,i,s),fm(null,t,r,!0,e,s);case 19:return pk(e,t,s);case 22:return dk(e,t,s)}throw Error(re(156,t.tag))};function Ik(e,t){return r0(e,t)}function iI(e,t,s,r){this.tag=e,this.key=s,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function is(e,t,s,r){return new iI(e,t,s,r)}function Og(e){return e=e.prototype,!(!e||!e.isReactComponent)}function aI(e){if(typeof e=="function")return Og(e)?1:0;if(e!=null){if(e=e.$$typeof,e===eg)return 11;if(e===tg)return 14}return 2}function Hr(e,t){var s=e.alternate;return s===null?(s=is(e.tag,t,e.key,e.mode),s.elementType=e.elementType,s.type=e.type,s.stateNode=e.stateNode,s.alternate=e,e.alternate=s):(s.pendingProps=t,s.type=e.type,s.flags=0,s.subtreeFlags=0,s.deletions=null),s.flags=e.flags&14680064,s.childLanes=e.childLanes,s.lanes=e.lanes,s.child=e.child,s.memoizedProps=e.memoizedProps,s.memoizedState=e.memoizedState,s.updateQueue=e.updateQueue,t=e.dependencies,s.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},s.sibling=e.sibling,s.index=e.index,s.ref=e.ref,s}function iu(e,t,s,r,i,a){var l=2;if(r=e,typeof e=="function")Og(e)&&(l=1);else if(typeof e=="string")l=5;else e:switch(e){case ca:return Ci(s.children,i,a,t);case Zp:l=8,i|=8;break;case Mf:return e=is(12,s,t,i|2),e.elementType=Mf,e.lanes=a,e;case Of:return e=is(13,s,t,i),e.elementType=Of,e.lanes=a,e;case Df:return e=is(19,s,t,i),e.elementType=Df,e.lanes=a,e;case Ub:return Sd(s,i,a,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case Fb:l=10;break e;case zb:l=9;break e;case eg:l=11;break e;case tg:l=14;break e;case Ar:l=16,r=null;break e}throw Error(re(130,e==null?e:typeof e,""))}return t=is(l,s,t,i),t.elementType=e,t.type=r,t.lanes=a,t}function Ci(e,t,s,r){return e=is(7,e,r,t),e.lanes=s,e}function Sd(e,t,s,r){return e=is(22,e,r,t),e.elementType=Ub,e.lanes=s,e.stateNode={isHidden:!1},e}function _h(e,t,s){return e=is(6,e,null,t),e.lanes=s,e}function Lh(e,t,s){return t=is(4,e.children!==null?e.children:[],e.key,t),t.lanes=s,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function lI(e,t,s,r,i){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=vh(0),this.expirationTimes=vh(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=vh(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function Dg(e,t,s,r,i,a,l,o,c){return e=new lI(e,t,s,o,c),t===1?(t=1,a===!0&&(t|=8)):t=0,a=is(3,null,null,t),e.current=a,a.stateNode=e,a.memoizedState={element:r,isDehydrated:s,cache:null,transitions:null,pendingSuspenseBoundaries:null},jg(a),e}function oI(e,t,s){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:oa,key:r==null?null:""+r,children:e,containerInfo:t,implementation:s}}function Pk(e){if(!e)return Jr;e=e._reactInternals;e:{if(Bi(e)!==e||e.tag!==1)throw Error(re(170));var t=e;do{switch(t.tag){case 3:t=t.stateNode.context;break e;case 1:if(En(t.type)){t=t.stateNode.__reactInternalMemoizedMergedChildContext;break e}}t=t.return}while(t!==null);throw Error(re(171))}if(e.tag===1){var s=e.type;if(En(s))return P0(e,s,t)}return t}function $k(e,t,s,r,i,a,l,o,c){return e=Dg(s,r,!0,e,i,a,l,o,c),e.context=Pk(null),s=e.current,r=vn(),i=Wr(s),a=rr(r,i),a.callback=t??null,Ur(s,a,i),e.current.lanes=i,Oo(e,i,r),An(e,r),e}function Nd(e,t,s,r){var i=t.current,a=vn(),l=Wr(i);return s=Pk(s),t.context===null?t.context=s:t.pendingContext=s,t=rr(a,l),t.payload={element:e},r=r===void 0?null:r,r!==null&&(t.callback=r),e=Ur(i,t,l),e!==null&&(xs(e,i,l,a),Zc(e,i,l)),l}function Bu(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 rw(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var s=e.retryLane;e.retryLane=s!==0&&s<t?s:t}}function _g(e,t){rw(e,t),(e=e.alternate)&&rw(e,t)}function cI(){return null}var Mk=typeof reportError=="function"?reportError:function(e){console.error(e)};function Lg(e){this._internalRoot=e}Cd.prototype.render=Lg.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(re(409));Nd(e,t,null,null)};Cd.prototype.unmount=Lg.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;Mi(function(){Nd(null,e,null,null)}),t[cr]=null}};function Cd(e){this._internalRoot=e}Cd.prototype.unstable_scheduleHydration=function(e){if(e){var t=d0();e={blockedOn:null,target:e,priority:t};for(var s=0;s<Rr.length&&t!==0&&t<Rr[s].priority;s++);Rr.splice(s,0,e),s===0&&f0(e)}};function Fg(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function Ed(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function iw(){}function uI(e,t,s,r,i){if(i){if(typeof r=="function"){var a=r;r=function(){var u=Bu(l);a.call(u)}}var l=$k(t,r,e,0,null,!1,!1,"",iw);return e._reactRootContainer=l,e[cr]=l.current,ao(e.nodeType===8?e.parentNode:e),Mi(),l}for(;i=e.lastChild;)e.removeChild(i);if(typeof r=="function"){var o=r;r=function(){var u=Bu(c);o.call(u)}}var c=Dg(e,0,!1,null,null,!1,!1,"",iw);return e._reactRootContainer=c,e[cr]=c.current,ao(e.nodeType===8?e.parentNode:e),Mi(function(){Nd(t,c,s,r)}),c}function Ad(e,t,s,r,i){var a=s._reactRootContainer;if(a){var l=a;if(typeof i=="function"){var o=i;i=function(){var c=Bu(l);o.call(c)}}Nd(t,l,e,i)}else l=uI(s,t,e,i,r);return Bu(l)}c0=function(e){switch(e.tag){case 3:var t=e.stateNode;if(t.current.memoizedState.isDehydrated){var s=Ml(t.pendingLanes);s!==0&&(rg(t,s|1),An(t,Et()),!(He&6)&&(za=Et()+500,li()))}break;case 13:Mi(function(){var r=ur(e,1);if(r!==null){var i=vn();xs(r,e,1,i)}}),_g(e,1)}};ig=function(e){if(e.tag===13){var t=ur(e,134217728);if(t!==null){var s=vn();xs(t,e,134217728,s)}_g(e,134217728)}};u0=function(e){if(e.tag===13){var t=Wr(e),s=ur(e,t);if(s!==null){var r=vn();xs(s,e,t,r)}_g(e,t)}};d0=function(){return Xe};h0=function(e,t){var s=Xe;try{return Xe=e,t()}finally{Xe=s}};Vf=function(e,t,s){switch(t){case"input":if(Ff(e,s),t=s.name,s.type==="radio"&&t!=null){for(s=e;s.parentNode;)s=s.parentNode;for(s=s.querySelectorAll("input[name="+JSON.stringify(""+t)+'][type="radio"]'),t=0;t<s.length;t++){var r=s[t];if(r!==e&&r.form===e.form){var i=vd(r);if(!i)throw Error(re(90));Wb(r),Ff(r,i)}}}break;case"textarea":Kb(e,s);break;case"select":t=s.value,t!=null&&ba(e,!!s.multiple,t,!1)}};Xb=Pg;Zb=Mi;var dI={usingClientEntryPoint:!1,Events:[_o,fa,vd,Qb,Jb,Pg]},Nl={findFiberByHostInstance:bi,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},hI={bundleType:Nl.bundleType,version:Nl.version,rendererPackageName:Nl.rendererPackageName,rendererConfig:Nl.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:gr.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=n0(e),e===null?null:e.stateNode},findFiberByHostInstance:Nl.findFiberByHostInstance||cI,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 yc=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!yc.isDisabled&&yc.supportsFiber)try{md=yc.inject(hI),zs=yc}catch{}}Kn.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=dI;Kn.createPortal=function(e,t){var s=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!Fg(t))throw Error(re(200));return oI(e,t,null,s)};Kn.createRoot=function(e,t){if(!Fg(e))throw Error(re(299));var s=!1,r="",i=Mk;return t!=null&&(t.unstable_strictMode===!0&&(s=!0),t.identifierPrefix!==void 0&&(r=t.identifierPrefix),t.onRecoverableError!==void 0&&(i=t.onRecoverableError)),t=Dg(e,1,!1,null,null,s,!1,r,i),e[cr]=t.current,ao(e.nodeType===8?e.parentNode:e),new Lg(t)};Kn.findDOMNode=function(e){if(e==null)return null;if(e.nodeType===1)return e;var t=e._reactInternals;if(t===void 0)throw typeof e.render=="function"?Error(re(188)):(e=Object.keys(e).join(","),Error(re(268,e)));return e=n0(t),e=e===null?null:e.stateNode,e};Kn.flushSync=function(e){return Mi(e)};Kn.hydrate=function(e,t,s){if(!Ed(t))throw Error(re(200));return Ad(null,e,t,!0,s)};Kn.hydrateRoot=function(e,t,s){if(!Fg(e))throw Error(re(405));var r=s!=null&&s.hydratedSources||null,i=!1,a="",l=Mk;if(s!=null&&(s.unstable_strictMode===!0&&(i=!0),s.identifierPrefix!==void 0&&(a=s.identifierPrefix),s.onRecoverableError!==void 0&&(l=s.onRecoverableError)),t=$k(t,null,e,1,s??null,i,!1,a,l),e[cr]=t.current,ao(e),r)for(e=0;e<r.length;e++)s=r[e],i=s._getVersion,i=i(s._source),t.mutableSourceEagerHydrationData==null?t.mutableSourceEagerHydrationData=[s,i]:t.mutableSourceEagerHydrationData.push(s,i);return new Cd(t)};Kn.render=function(e,t,s){if(!Ed(t))throw Error(re(200));return Ad(null,e,t,!1,s)};Kn.unmountComponentAtNode=function(e){if(!Ed(e))throw Error(re(40));return e._reactRootContainer?(Mi(function(){Ad(null,null,e,!1,function(){e._reactRootContainer=null,e[cr]=null})}),!0):!1};Kn.unstable_batchedUpdates=Pg;Kn.unstable_renderSubtreeIntoContainer=function(e,t,s,r){if(!Ed(s))throw Error(re(200));if(e==null||e._reactInternals===void 0)throw Error(re(38));return Ad(e,t,s,!1,r)};Kn.version="18.3.1-next-f1338f8080-20240426";function Ok(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Ok)}catch(e){console.error(e)}}Ok(),Ob.exports=Kn;var Fo=Ob.exports,Dk,aw=Fo;Dk=aw.createRoot,aw.hydrateRoot;var fI=Object.defineProperty,tl=(e,t)=>fI(e,"name",{value:t,configurable:!0}),_k=!!(typeof window<"u"&&window.document&&window.document.createElement);function Ie(e,t,{checkForDefaultPrevented:s=!0}={}){return tl(function(i){if(e==null||e(i),s===!1||!i||!i.defaultPrevented)return t==null?void 0:t(i)},"handleEvent")}tl(Ie,"composeEventHandlers");function mI(e){var t;if(!_k)throw new Error("Cannot access window outside of the DOM");return((t=e==null?void 0:e.ownerDocument)==null?void 0:t.defaultView)??window}tl(mI,"getOwnerWindow");function Nm(e){if(!_k)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}tl(Nm,"getOwnerDocument");function Lk(e,t=!1){const{activeElement:s}=Nm(e);if(!(s!=null&&s.nodeName))return null;if(Fk(s)&&s.contentDocument)return Lk(s.contentDocument.body,t);if(t){const r=s.getAttribute("aria-activedescendant");if(r){const i=Nm(s).getElementById(r);if(i)return i}}return s}tl(Lk,"getActiveElement");function Fk(e){return e.tagName==="IFRAME"}tl(Fk,"isFrame");var pI=Object.defineProperty,zg=(e,t)=>pI(e,"name",{value:t,configurable:!0});function Cm(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}zg(Cm,"setRef");function zk(...e){return t=>{let s=!1;const r=e.map(i=>{const a=Cm(i,t);return!s&&typeof a=="function"&&(s=!0),a});if(s)return()=>{for(let i=0;i<r.length;i++){const a=r[i];typeof a=="function"?a():Cm(e[i],null)}}}}zg(zk,"composeRefs");function ct(...e){return f.useCallback(zk(...e),e)}zg(ct,"useComposedRefs");var gI=Object.defineProperty,rs=(e,t)=>gI(e,"name",{value:t,configurable:!0});function xI(e,t){const s=f.createContext(t);s.displayName=e+"Context";const r=rs(a=>{const{children:l,...o}=a,c=f.useMemo(()=>o,Object.values(o));return n.jsx(s.Provider,{value:c,children:l})},"Provider");r.displayName=e+"Provider";function i(a,l={}){const{optional:o=!1}=l,c=f.useContext(s);if(c)return c;if(t!==void 0)return t;if(!o)throw new Error(`\`${a}\` must be used within \`${e}\``)}return rs(i,"useContext"),[r,i]}rs(xI,"createContext");function Ns(e,t=[]){let s=[];function r(a,l){const o=f.createContext(l);o.displayName=a+"Context";const c=s.length;s=[...s,l];const u=rs(d=>{var g;const{scope:m,children:p,...x}=d,j=((g=m==null?void 0:m[e])==null?void 0:g[c])||o,b=f.useMemo(()=>x,Object.values(x));return n.jsx(j.Provider,{value:b,children:p})},"Provider");u.displayName=a+"Provider";function h(d,m,p={}){var g;const{optional:x=!1}=p,j=((g=m==null?void 0:m[e])==null?void 0:g[c])||o,b=f.useContext(j);if(b)return b;if(l!==void 0)return l;if(!x)throw new Error(`\`${d}\` must be used within \`${a}\``)}return rs(h,"useContext"),[u,h]}rs(r,"createContext");const i=rs(()=>{const a=s.map(l=>f.createContext(l));return rs(function(o){const c=(o==null?void 0:o[e])||a;return f.useMemo(()=>({[`__scope${e}`]:{...o,[e]:c}}),[o,c])},"useScope")},"createScope");return i.scopeName=e,[r,Uk(i,...t)]}rs(Ns,"createContextScope");function Uk(...e){const t=e[0];if(e.length===1)return t;const s=rs(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return rs(function(a){const l=r.reduce((o,{useScope:c,scopeName:u})=>{const d=c(a)[`__scope${u}`];return{...o,...d}},{});return f.useMemo(()=>({[`__scope${t.scopeName}`]:l}),[l])},"useComposedScopes")},"createScope");return s.scopeName=t.scopeName,s}rs(Uk,"composeContextScopes");var vI=Object.defineProperty,Cs=(e,t)=>vI(e,"name",{value:t,configurable:!0});function Xr(e){const t=f.forwardRef((s,r)=>{let{children:i,...a}=s,l=null,o=!1;const c=[];Em(i)&&typeof bc=="function"&&(i=bc(i._payload)),f.Children.forEach(i,m=>{var p;if(Vk(m)){o=!0;const x=m;let j="child"in x.props?x.props.child:x.props.children;Em(j)&&typeof bc=="function"&&(j=bc(j._payload)),l=jI(x,j),c.push((p=l==null?void 0:l.props)==null?void 0:p.children)}else c.push(m)}),l?l=f.cloneElement(l,void 0,c):!o&&f.Children.count(i)===1&&f.isValidElement(i)&&(l=i);const u=l?Kk(l):void 0,h=ct(r,u);if(!l){if(i||i===0)throw new Error(o?bI(e):yI(e));return i}const d=Hk(a,l.props??{});return l.type!==f.Fragment&&(d.ref=r?h:u),f.cloneElement(l,d)});return t.displayName=`${e}.Slot`,t}Cs(Xr,"createSlot");var Bk=Symbol.for("radix.slottable");function Wk(e){const t=Cs(s=>"child"in s?s.children(s.child):s.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=Bk,t}Cs(Wk,"createSlottable");var jI=Cs((e,t)=>{if("child"in e.props){const s=e.props.child;return f.isValidElement(s)?f.cloneElement(s,void 0,e.props.children(s.props.children)):null}return f.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function Hk(e,t){const s={...t};for(const r in t){const i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?s[r]=(...o)=>{const c=a(...o);return i(...o),c}:i&&(s[r]=i):r==="style"?s[r]={...i,...a}:r==="className"&&(s[r]=[i,a].filter(Boolean).join(" "))}return{...e,...s}}Cs(Hk,"mergeProps");function Kk(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,s=t&&"isReactWarning"in t&&t.isReactWarning;return s?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,s=t&&"isReactWarning"in t&&t.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}Cs(Kk,"getElementRef");function Vk(e){return f.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===Bk}Cs(Vk,"isSlottable");var wI=Symbol.for("react.lazy");function Em(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===wI&&"_payload"in e&&Gk(e._payload)}Cs(Em,"isLazyComponent");function Gk(e){return typeof e=="object"&&e!==null&&"then"in e}Cs(Gk,"isPromiseLike");var yI=Cs(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),bI=Cs(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),bc=Xa[" use ".trim().toString()],kI=Object.defineProperty,Bt=(e,t)=>kI(e,"name",{value:t,configurable:!0});function Td(e){const t=e+"CollectionProvider",[s,r]=Ns(t),[i,a]=s(t,{collectionRef:{current:null},itemMap:new Map}),l=Bt(j=>{const{scope:b,children:g}=j,v=f.useRef(null),w=f.useRef(new Map).current;return n.jsx(i,{scope:b,itemMap:w,collectionRef:v,children:g})},"CollectionProvider");l.displayName=t;const o=e+"CollectionSlot",c=Xr(o),u=f.forwardRef((j,b)=>{const{scope:g,children:v}=j,w=a(o,g),y=ct(b,w.collectionRef);return n.jsx(c,{ref:y,children:v})});u.displayName=o;const h=e+"CollectionItemSlot",d="data-radix-collection-item",m=Xr(h),p=f.forwardRef((j,b)=>{const{scope:g,children:v,...w}=j,y=f.useRef(null),N=ct(b,y),k=a(h,g);return f.useEffect(()=>(k.itemMap.set(y,{ref:y,...w}),()=>void k.itemMap.delete(y))),n.jsx(m,{[d]:"",ref:N,children:v})});p.displayName=h;function x(j){const b=a(e+"CollectionConsumer",j);return f.useCallback(()=>{const v=b.collectionRef.current;if(!v)return[];const w=Array.from(v.querySelectorAll(`[${d}]`));return Array.from(b.itemMap.values()).sort((k,S)=>w.indexOf(k.ref.current)-w.indexOf(S.ref.current))},[b.collectionRef,b.itemMap])}return Bt(x,"useCollection"),[{Provider:l,Slot:u,ItemSlot:p},x,r]}Bt(Td,"createCollection");var lw=new WeakMap,It,Ln,Fh=(Ln=class extends Map{constructor(s){super(s);Jv(this,It);hh(this,It,[...super.keys()]),lw.set(this,!0)}set(s,r){return lw.get(this)&&(this.has(s)?an(this,It)[an(this,It).indexOf(s)]=s:an(this,It).push(s)),super.set(s,r),this}insert(s,r,i){const a=this.has(r),l=an(this,It).length,o=Ug(s);let c=o>=0?o:l+o;const u=c<0||c>=l?-1:c;if(u===this.size||a&&u===this.size-1||u===-1)return this.set(r,i),this;const h=this.size+(a?0:1);o<0&&c++;const d=[...an(this,It)];let m,p=!1;for(let x=c;x<h;x++)if(c===x){let j=d[x];d[x]===r&&(j=d[x+1]),a&&this.delete(r),m=this.get(j),this.set(r,i)}else{!p&&d[x-1]===r&&(p=!0);const j=d[p?x:x-1],b=m;m=this.get(j),this.delete(j),this.set(j,b)}return this}with(s,r,i){const a=new Ln(this);return a.insert(s,r,i),a}before(s){const r=an(this,It).indexOf(s)-1;if(!(r<0))return this.entryAt(r)}setBefore(s,r,i){const a=an(this,It).indexOf(s);return a===-1?this:this.insert(a,r,i)}after(s){let r=an(this,It).indexOf(s);if(r=r===-1||r===this.size-1?-1:r+1,r!==-1)return this.entryAt(r)}setAfter(s,r,i){const a=an(this,It).indexOf(s);return a===-1?this:this.insert(a+1,r,i)}first(){return this.entryAt(0)}last(){return this.entryAt(-1)}clear(){return hh(this,It,[]),super.clear()}delete(s){const r=super.delete(s);return r&&an(this,It).splice(an(this,It).indexOf(s),1),r}deleteAt(s){const r=this.keyAt(s);return r!==void 0?this.delete(r):!1}at(s){const r=au(an(this,It),s);if(r!==void 0)return this.get(r)}entryAt(s){const r=au(an(this,It),s);if(r!==void 0)return[r,this.get(r)]}indexOf(s){return an(this,It).indexOf(s)}keyAt(s){return au(an(this,It),s)}from(s,r){const i=this.indexOf(s);if(i===-1)return;let a=i+r;return a<0&&(a=0),a>=this.size&&(a=this.size-1),this.at(a)}keyFrom(s,r){const i=this.indexOf(s);if(i===-1)return;let a=i+r;return a<0&&(a=0),a>=this.size&&(a=this.size-1),this.keyAt(a)}find(s,r){let i=0;for(const a of this){if(Reflect.apply(s,r,[a,i,this]))return a;i++}}findIndex(s,r){let i=0;for(const a of this){if(Reflect.apply(s,r,[a,i,this]))return i;i++}return-1}filter(s,r){const i=[];let a=0;for(const l of this)Reflect.apply(s,r,[l,a,this])&&i.push(l),a++;return new Ln(i)}map(s,r){const i=[];let a=0;for(const l of this)i.push([l[0],Reflect.apply(s,r,[l,a,this])]),a++;return new Ln(i)}reduce(...s){const[r,i]=s;let a=0,l=i??this.at(0);for(const o of this)a===0&&s.length===1?l=o:l=Reflect.apply(r,this,[l,o,a,this]),a++;return l}reduceRight(...s){const[r,i]=s;let a=i??this.at(-1);for(let l=this.size-1;l>=0;l--){const o=this.at(l);l===this.size-1&&s.length===1?a=o:a=Reflect.apply(r,this,[a,o,l,this])}return a}toSorted(s){const r=[...this.entries()].sort(s);return new Ln(r)}toReversed(){const s=new Ln;for(let r=this.size-1;r>=0;r--){const i=this.keyAt(r),a=this.get(i);s.set(i,a)}return s}toSpliced(...s){const r=[...this.entries()];return r.splice(...s),new Ln(r)}slice(s,r){const i=new Ln;let a=this.size-1;if(s===void 0)return i;s<0&&(s=s+this.size),r!==void 0&&r>0&&(a=r-1);for(let l=s;l<=a;l++){const o=this.keyAt(l),c=this.get(o);i.set(o,c)}return i}every(s,r){let i=0;for(const a of this){if(!Reflect.apply(s,r,[a,i,this]))return!1;i++}return!0}some(s,r){let i=0;for(const a of this){if(Reflect.apply(s,r,[a,i,this]))return!0;i++}return!1}},It=new WeakMap,Bt(Ln,"OrderedDict"),Ln);function au(e,t){if("at"in Array.prototype)return Array.prototype.at.call(e,t);const s=Yk(e,t);return s===-1?void 0:e[s]}Bt(au,"at");function Yk(e,t){const s=e.length,r=Ug(t),i=r>=0?r:s+r;return i<0||i>=s?-1:i}Bt(Yk,"toSafeIndex");function Ug(e){return e!==e||e===0?0:Math.trunc(e)}Bt(Ug,"toSafeInteger");function SI(e){const t=e+"CollectionProvider",[s,r]=Ns(t),[i,a]=s(t,{collectionElement:null,collectionRef:{current:null},collectionRefObject:{current:null},itemMap:new Fh,setItemMap:Bt(()=>{},"setItemMap")}),l=Bt(({state:w,...y})=>w?n.jsx(c,{...y,state:w}):n.jsx(o,{...y}),"CollectionProvider");l.displayName=t;const o=Bt(w=>{const y=b();return n.jsx(c,{...w,state:y})},"CollectionInit");o.displayName=t+"Init";const c=Bt(w=>{const{scope:y,children:N,state:k}=w,S=f.useRef(null),[C,I]=f.useState(null),A=ct(S,I),[O,z]=k;return f.useEffect(()=>{if(!C)return;const L=Jk(()=>{});return L.observe(C,{childList:!0,subtree:!0}),()=>{L.disconnect()}},[C]),n.jsx(i,{scope:y,itemMap:O,setItemMap:z,collectionRef:A,collectionRefObject:S,collectionElement:C,children:N})},"CollectionProviderImpl");c.displayName=t+"Impl";const u=e+"CollectionSlot",h=Xr(u),d=f.forwardRef((w,y)=>{const{scope:N,children:k}=w,S=a(u,N),C=ct(y,S.collectionRef);return n.jsx(h,{ref:C,children:k})});d.displayName=u;const m=e+"CollectionItemSlot",p="data-radix-collection-item",x=Xr(m),j=f.forwardRef((w,y)=>{const{scope:N,children:k,...S}=w,C=f.useRef(null),[I,A]=f.useState(null),O=ct(y,C,A),z=a(m,N),{setItemMap:L}=z,E=f.useRef(S);qk(E.current,S)||(E.current=S);const $=E.current;return f.useEffect(()=>{const _=$;return L(B=>I?B.has(I)?B.set(I,{..._,element:I}).toSorted(Am):(B.set(I,{..._,element:I}),B.toSorted(Am)):B),()=>{L(B=>!I||!B.has(I)?B:(B.delete(I),new Fh(B)))}},[I,$,L]),n.jsx(x,{[p]:"",ref:O,children:k})});j.displayName=m;function b(){return f.useState(new Fh)}Bt(b,"useInitCollection");function g(w){const{itemMap:y}=a(e+"CollectionConsumer",w);return y}return Bt(g,"useCollection"),[{Provider:l,Slot:d,ItemSlot:j},{createCollectionScope:r,useCollection:g,useInitCollection:b}]}Bt(SI,"createCollection");function qk(e,t){if(e===t)return!0;if(typeof e!="object"||typeof t!="object"||e==null||t==null)return!1;const s=Object.keys(e),r=Object.keys(t);if(s.length!==r.length)return!1;for(const i of s)if(!Object.prototype.hasOwnProperty.call(t,i)||e[i]!==t[i])return!1;return!0}Bt(qk,"shallowEqual");function Qk(e,t){return!!(t.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_PRECEDING)}Bt(Qk,"isElementPreceding");function Am(e,t){return!e[1].element||!t[1].element?0:Qk(e[1].element,t[1].element)?-1:1}Bt(Am,"sortByDocumentPosition");function Jk(e){return new MutationObserver(s=>{for(const r of s)if(r.type==="childList"){e();return}})}Bt(Jk,"getChildListObserver");var NI=Object.defineProperty,CI=(e,t)=>NI(e,"name",{value:t,configurable:!0}),EI=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],jt=EI.reduce((e,t)=>{const s=Xr(`Primitive.${t}`),r=f.forwardRef((i,a)=>{const{asChild:l,...o}=i,c=l?s:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),n.jsx(c,{...o,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Rd(e,t){e&&Fo.flushSync(()=>e.dispatchEvent(t))}CI(Rd,"dispatchDiscreteCustomEvent");var AI=Object.defineProperty,TI=(e,t)=>AI(e,"name",{value:t,configurable:!0});function us(e){const t=f.useRef(e);return f.useEffect(()=>{t.current=e}),f.useMemo(()=>(...s)=>{var r;return(r=t.current)==null?void 0:r.call(t,...s)},[])}TI(us,"useCallbackRef");var RI=Object.defineProperty,Dt=(e,t)=>RI(e,"name",{value:t,configurable:!0}),Tm="dismissableLayer.update",II="dismissableLayer.pointerDownOutside",PI="dismissableLayer.focusOutside",ow,Bg=f.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),Wg=f.forwardRef(Dt(function(t,s){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:i=!1,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:o,onInteractOutside:c,onDismiss:u,...h}=t,d=f.useContext(Bg),[m,p]=f.useState(null),x=(m==null?void 0:m.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,j]=f.useState({}),b=ct(s,p),g=Array.from(d.layers),[v]=[...d.layersWithOutsidePointerEventsDisabled].slice(-1),w=v?g.indexOf(v):-1,y=m?g.indexOf(m):-1,N=d.layersWithOutsidePointerEventsDisabled.size>0,k=y>=w,S=f.useRef(!1),C=Zk(z=>{l==null||l(z),c==null||c(z),z.defaultPrevented||u==null||u()},{ownerDocument:x,deferPointerDownOutside:i,isDeferredPointerDownOutsideRef:S,dismissableSurfaces:d.dismissableSurfaces,shouldHandlePointerDownOutside:f.useCallback(z=>{if(!(z instanceof Node))return!1;const L=[...d.branches].some(E=>E.contains(z));return k&&!L},[d.branches,k])}),I=eS(z=>{if(i&&S.current)return;const L=z.target;[...d.branches].some($=>$.contains(L))||(o==null||o(z),c==null||c(z),z.defaultPrevented||u==null||u())},x),A=m?y===g.length-1:!1,O=us(z=>{z.key==="Escape"&&(a==null||a(z),!z.defaultPrevented&&u&&(z.preventDefault(),u()))});return f.useEffect(()=>{if(A)return x.addEventListener("keydown",O,{capture:!0}),()=>x.removeEventListener("keydown",O,{capture:!0})},[x,A,O]),f.useEffect(()=>{if(m)return r&&(d.layersWithOutsidePointerEventsDisabled.size===0&&(ow=x.body.style.pointerEvents,x.body.style.pointerEvents="none"),d.layersWithOutsidePointerEventsDisabled.add(m)),d.layers.add(m),Rm(),()=>{r&&(d.layersWithOutsidePointerEventsDisabled.delete(m),d.layersWithOutsidePointerEventsDisabled.size===0&&(x.body.style.pointerEvents=ow))}},[m,x,r,d]),f.useEffect(()=>()=>{m&&(d.layers.delete(m),d.layersWithOutsidePointerEventsDisabled.delete(m),Rm())},[m,d]),f.useEffect(()=>{const z=Dt(()=>j({}),"handleUpdate");return document.addEventListener(Tm,z),()=>document.removeEventListener(Tm,z)},[]),n.jsx(jt.div,{...h,ref:b,style:{pointerEvents:N?k?"auto":"none":void 0,...t.style},onFocusCapture:Ie(t.onFocusCapture,I.onFocusCapture),onBlurCapture:Ie(t.onBlurCapture,I.onBlurCapture),onPointerDownCapture:Ie(t.onPointerDownCapture,C.onPointerDownCapture)})},"DismissableLayer")),$I=f.forwardRef(Dt(function(t,s){const r=f.useContext(Bg),i=f.useRef(null),a=ct(s,i);return f.useEffect(()=>{const l=i.current;if(l)return r.branches.add(l),()=>{r.branches.delete(l)}},[r.branches]),n.jsx(jt.div,{...t,ref:a})},"DismissableLayerBranch"));function Xk(){const e=f.useContext(Bg),[t,s]=f.useState(null);return f.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),s}Dt(Xk,"useDismissableLayerSurface");var MI=Dt(()=>!0,"IS_TRUE");function Zk(e,t){const{ownerDocument:s=globalThis==null?void 0:globalThis.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:i,dismissableSurfaces:a,shouldHandlePointerDownOutside:l=MI}=t,o=us(e),c=f.useRef(!1),u=f.useRef(!1),h=f.useRef(new Map),d=f.useRef(()=>{});return f.useEffect(()=>{function m(){u.current=!1,i.current=!1,h.current.clear()}Dt(m,"resetOutsideInteraction");function p(){return Array.from(h.current.values()).some(Boolean)}Dt(p,"isOutsideInteractionIntercepted");function x(w){if(!u.current)return;const y=w.target;y instanceof Node&&[...a].some(k=>k.contains(y))||h.current.set(w.type,!0),w.type==="click"&&window.setTimeout(()=>{u.current&&d.current()},0)}Dt(x,"handleInteractionCapture");function j(w){u.current&&h.current.set(w.type,!1)}Dt(j,"handleInteractionBubble");const b=Dt(w=>{if(w.target&&!c.current){let y=function(){s.removeEventListener("click",d.current);const k=p();m(),k||Hg(II,o,N,{discrete:!0})};if(Dt(y,"handleAndDispatchPointerDownOutsideEvent"),!l(w.target)){s.removeEventListener("click",d.current),m(),c.current=!1;return}const N={originalEvent:w};u.current=!0,i.current=r&&w.button===0,h.current.clear(),!r||w.button!==0?y():(s.removeEventListener("click",d.current),d.current=y,s.addEventListener("click",d.current,{once:!0}))}else s.removeEventListener("click",d.current),m();c.current=!1},"handlePointerDown"),g=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const w of g)s.addEventListener(w,x,!0),s.addEventListener(w,j);const v=window.setTimeout(()=>{s.addEventListener("pointerdown",b)},0);return()=>{window.clearTimeout(v),s.removeEventListener("pointerdown",b),s.removeEventListener("click",d.current);for(const w of g)s.removeEventListener(w,x,!0),s.removeEventListener(w,j)}},[s,o,r,i,a,l]),{onPointerDownCapture:Dt(()=>c.current=!0,"onPointerDownCapture")}}Dt(Zk,"usePointerDownOutside");function eS(e,t=globalThis==null?void 0:globalThis.document){const s=us(e),r=f.useRef(!1);return f.useEffect(()=>{const i=Dt(a=>{a.target&&!r.current&&Hg(PI,s,{originalEvent:a},{discrete:!1})},"handleFocus");return t.addEventListener("focusin",i),()=>t.removeEventListener("focusin",i)},[t,s]),{onFocusCapture:Dt(()=>r.current=!0,"onFocusCapture"),onBlurCapture:Dt(()=>r.current=!1,"onBlurCapture")}}Dt(eS,"useFocusOutside");function Rm(){const e=new CustomEvent(Tm);document.dispatchEvent(e)}Dt(Rm,"dispatchUpdate");function Hg(e,t,s,{discrete:r}){const i=s.originalEvent.target,a=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:s});t&&i.addEventListener(e,t,{once:!0}),r?Rd(i,a):i.dispatchEvent(a)}Dt(Hg,"handleAndDispatchCustomEvent");var OI=$I,Tn=globalThis!=null&&globalThis.document?f.useLayoutEffect:()=>{},DI=Object.defineProperty,_I=(e,t)=>DI(e,"name",{value:t,configurable:!0}),Kg=f.forwardRef(_I(function(t,s){var c;const{container:r,...i}=t,[a,l]=f.useState(!1);Tn(()=>l(!0),[]);const o=r||a&&((c=globalThis==null?void 0:globalThis.document)==null?void 0:c.body);return o?Fo.createPortal(n.jsx(jt.div,{...i,ref:s}),o):null},"Portal")),LI=Object.defineProperty,hr=(e,t)=>LI(e,"name",{value:t,configurable:!0});function tS(e,t){return f.useReducer((s,r)=>t[s][r]??s,e)}hr(tS,"useStateMachine");var xr=hr(e=>{const{present:t,children:s}=e,r=nS(t),i=typeof s=="function"?s({present:r.isPresent}):f.Children.only(s),a=sS(r.ref,rS(i));return typeof s=="function"||r.isPresent?f.cloneElement(i,{ref:a}):null},"Presence");function nS(e){const[t,s]=f.useState(),r=f.useRef(null),i=f.useRef(e),a=f.useRef("none"),l=f.useRef(void 0),o=e?"mounted":"unmounted",[c,u]=tS(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return f.useEffect(()=>{c==="mounted"?(a.current=l.current??aa(r.current),l.current=void 0):a.current="none"},[c]),Tn(()=>{const h=r.current,d=i.current;if(d!==e){const p=a.current,x=aa(h);e?(l.current=x,u("MOUNT")):x==="none"||(h==null?void 0:h.display)==="none"?u("UNMOUNT"):u(d&&p!==x?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,u]),Tn(()=>{if(t){let h;const d=t.ownerDocument.defaultView??window,m=hr(x=>{const b=aa(r.current).includes(CSS.escape(x.animationName));if(x.target===t&&b&&(u("ANIMATION_END"),!i.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",h=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},"handleAnimationEnd"),p=hr(x=>{x.target===t&&(a.current=aa(r.current))},"handleAnimationStart");return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",m),t.addEventListener("animationend",m),()=>{d.clearTimeout(h),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",m),t.removeEventListener("animationend",m)}}else u("ANIMATION_END")},[t,u]),{isPresent:["mounted","unmountSuspended"].includes(c),ref:f.useCallback(h=>{if(h){const d=getComputedStyle(h);r.current=d,l.current=aa(d)}else r.current=null;s(h)},[])}}hr(nS,"usePresence");function Im(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}hr(Im,"setRef");function sS(...e){const t=f.useRef(e);return t.current=e,f.useCallback(s=>{const r=t.current;let i=!1;const a=r.map(l=>{const o=Im(l,s);return!i&&typeof o=="function"&&(i=!0),o});if(i)return()=>{for(let l=0;l<a.length;l++){const o=a[l];typeof o=="function"?o():Im(r[l],null)}}},[])}hr(sS,"useStableComposedRefs");function aa(e){return(e==null?void 0:e.animationName)||"none"}hr(aa,"getAnimationName");function rS(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,s=t&&"isReactWarning"in t&&t.isReactWarning;return s?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,s=t&&"isReactWarning"in t&&t.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}hr(rS,"getElementRef");var FI=Object.defineProperty,zI=(e,t)=>FI(e,"name",{value:t,configurable:!0}),cw=Xa[" useEffectEvent ".trim().toString()],uw=Xa[" useInsertionEffect ".trim().toString()];function iS(e){if(typeof cw=="function")return cw(e);const t=f.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof uw=="function"?uw(()=>{t.current=e}):Tn(()=>{t.current=e}),f.useMemo(()=>(...s)=>{var r;return(r=t.current)==null?void 0:r.call(t,...s)},[])}zI(iS,"useEffectEvent");var UI=Object.defineProperty,zo=(e,t)=>UI(e,"name",{value:t,configurable:!0}),BI=Xa[" useInsertionEffect ".trim().toString()]||Tn;function Wi({prop:e,defaultProp:t,onChange:s=zo(()=>{},"onChange"),caller:r}){const[i,a,l]=aS({defaultProp:t,onChange:s}),o=e!==void 0,c=o?e:i,u=f.useCallback(h=>{var d;if(o){const m=lS(h)?h(e):h;m!==e&&((d=l.current)==null||d.call(l,m))}else a(h)},[o,e,a,l]);return[c,u]}zo(Wi,"useControllableState");function aS({defaultProp:e,onChange:t}){const[s,r]=f.useState(e),i=f.useRef(s),a=f.useRef(t);return BI(()=>{a.current=t},[t]),f.useEffect(()=>{var l;i.current!==s&&((l=a.current)==null||l.call(a,s),i.current=s)},[s,i]),[s,r,a]}zo(aS,"useUncontrolledState");function lS(e){return typeof e=="function"}zo(lS,"isFunction");var dw=Symbol("RADIX:SYNC_STATE");function WI(e,t,s,r){const{prop:i,defaultProp:a,onChange:l,caller:o}=t,c=i!==void 0,u=iS(l),h=[{...s,state:a}];r&&h.push(r);const[d,m]=f.useReducer((b,g)=>{if(g.type===dw)return{...b,state:g.state};const v=e(b,g);return c&&!Object.is(v.state,b.state)&&u(v.state),v},...h),p=d.state,x=f.useRef(p);f.useEffect(()=>{x.current!==p&&(x.current=p,c||u(p))},[p,x,c]);const j=f.useMemo(()=>i!==void 0?{...d,state:i}:d,[d,i]);return f.useEffect(()=>{c&&!Object.is(i,d.state)&&m({type:dw,state:i})},[i,d.state,c]),[j,m]}zo(WI,"useControllableStateReducer");var HI=Object.defineProperty,KI=(e,t)=>HI(e,"name",{value:t,configurable:!0}),VI=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"}),oS=f.forwardRef(KI(function(t,s){return n.jsx(jt.span,{...t,ref:s,style:{...VI,...t.style}})},"VisuallyHidden")),GI=oS,YI=Object.defineProperty,cn=(e,t)=>YI(e,"name",{value:t,configurable:!0}),cS="ToastProvider",[uS,qI,QI]=Td("Toast"),[dS,RK]=Ns("Toast",[QI]),[JI,hS]=dS(cS),XI=cn(e=>{const{__scopeToast:t,label:s="Notification",duration:r=5e3,swipeDirection:i="right",swipeThreshold:a=50,announcerContainer:l,children:o}=e,[c,u]=f.useState(null),[h,d]=f.useState(0),m=f.useRef(!1);return s.trim()||console.error(`Invalid prop \`label\` supplied to \`${cS}\`. Expected non-empty \`string\`.`),n.jsx(uS.Provider,{scope:t,children:n.jsx(JI,{scope:t,label:s,duration:r,swipeDirection:i,swipeThreshold:a,toastCount:h,viewport:c,onViewportChange:u,onToastAdd:f.useCallback(()=>d(p=>p+1),[]),onToastRemove:f.useCallback(()=>d(p=>p-1),[]),isClosePausedRef:m,announcerContainer:l,children:o})})},"ToastProvider"),ZI="ToastViewport",eP=["F8"],tP="toast.viewportPause",nP="toast.viewportResume",sP=f.forwardRef(cn(function(t,s){const{__scopeToast:r,hotkey:i=eP,label:a="Notifications ({hotkey})",...l}=t,o=hS(ZI,r),c=qI(r),u=f.useRef(null),h=f.useRef(null),d=f.useRef(null),m=f.useRef(null),p=ct(s,m,o.onViewportChange),x=i.join("+").replace(/Key/g,"").replace(/Digit/g,""),j=o.toastCount>0;f.useEffect(()=>{const g=cn(v=>{var y;i.length!==0&&i.every(N=>v[N]||v.code===N)&&((y=m.current)==null||y.focus())},"handleKeyDown");return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[i]),f.useEffect(()=>{const g=u.current,v=m.current;if(j&&g&&v){const w=cn(()=>{if(!o.isClosePausedRef.current){const S=new CustomEvent(tP);v.dispatchEvent(S),o.isClosePausedRef.current=!0}},"handlePause"),y=cn(()=>{if(o.isClosePausedRef.current){const S=new CustomEvent(nP);v.dispatchEvent(S),o.isClosePausedRef.current=!1}},"handleResume"),N=cn(S=>{!g.contains(S.relatedTarget)&&y()},"handleFocusOutResume"),k=cn(()=>{g.contains(document.activeElement)||y()},"handlePointerLeaveResume");return g.addEventListener("focusin",w),g.addEventListener("focusout",N),g.addEventListener("pointermove",w),g.addEventListener("pointerleave",k),window.addEventListener("blur",w),window.addEventListener("focus",y),()=>{g.removeEventListener("focusin",w),g.removeEventListener("focusout",N),g.removeEventListener("pointermove",w),g.removeEventListener("pointerleave",k),window.removeEventListener("blur",w),window.removeEventListener("focus",y)}}},[j,o.isClosePausedRef]);const b=f.useCallback(({tabbingDirection:g})=>{const w=c().map(y=>{const N=y.ref.current,k=[N,...pS(N)];return g==="forwards"?k:k.reverse()});return(g==="forwards"?w.reverse():w).flat()},[c]);return f.useEffect(()=>{const g=m.current;if(g){const v=cn(w=>{var k,S,C;const y=w.altKey||w.ctrlKey||w.metaKey;if(w.key==="Tab"&&!y){const I=document.activeElement,A=w.shiftKey;if(w.target===g&&A){(k=h.current)==null||k.focus();return}const L=b({tabbingDirection:A?"backwards":"forwards"}),E=L.findIndex($=>$===I);lu(L.slice(E+1))?w.preventDefault():A?(S=h.current)==null||S.focus():(C=d.current)==null||C.focus()}},"handleKeyDown");return g.addEventListener("keydown",v),()=>g.removeEventListener("keydown",v)}},[c,b]),n.jsxs(OI,{ref:u,role:"region","aria-label":a.replace("{hotkey}",x),tabIndex:-1,style:{pointerEvents:j?void 0:"none"},children:[j&&n.jsx(hw,{ref:h,onFocusFromOutsideViewport:()=>{const g=b({tabbingDirection:"forwards"});lu(g)}}),n.jsx(uS.Slot,{scope:r,children:n.jsx(jt.ol,{tabIndex:-1,...l,ref:p})}),j&&n.jsx(hw,{ref:d,onFocusFromOutsideViewport:()=>{const g=b({tabbingDirection:"backwards"});lu(g)}})]})},"ToastViewport")),rP="ToastFocusProxy",hw=f.forwardRef(cn(function(t,s){const{__scopeToast:r,onFocusFromOutsideViewport:i,...a}=t,l=hS(rP,r);return n.jsx(oS,{tabIndex:0,...a,ref:s,style:{position:"fixed"},onFocus:o=>{var h;const c=o.relatedTarget;!((h=l.viewport)!=null&&h.contains(c))&&i()}})},"ToastFocusProxy")),iP="Toast",[IK,PK]=dS(iP,{onClose(){}});function fS(e){const t=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&t.push(r.textContent),mS(r)){const i=r.ariaHidden||r.hidden||r.style.display==="none",a=r.dataset.radixToastAnnounceExclude==="";if(!i)if(a){const l=r.dataset.radixToastAnnounceAlt;l&&t.push(l)}else t.push(...fS(r))}}),t}cn(fS,"getAnnounceTextContent");function aP(e,t,s,{discrete:r}){const i=s.originalEvent.currentTarget,a=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:s});t&&i.addEventListener(e,t,{once:!0}),r?Rd(i,a):i.dispatchEvent(a)}cn(aP,"handleAndDispatchCustomEvent");function lP(e=()=>{}){const t=us(e);Tn(()=>{let s=0,r=0;return s=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(t)),()=>{window.cancelAnimationFrame(s),window.cancelAnimationFrame(r)}},[t])}cn(lP,"useNextFrame");function mS(e){return e.nodeType===e.ELEMENT_NODE}cn(mS,"isHTMLElement");function pS(e){const t=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:cn(r=>{const i=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||i?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;s.nextNode();)t.push(s.currentNode);return t}cn(pS,"getTabbableCandidates");function lu(e){const t=document.activeElement;return e.some(s=>s===t?!0:(s.focus(),document.activeElement!==t))}cn(lu,"focusFirst");var fw=XI,mw=sP,oP=Object.defineProperty,cP=(e,t)=>oP(e,"name",{value:t,configurable:!0}),uP=Xa[" useId ".trim().toString()]||(()=>{}),dP=0;function vs(e){const[t,s]=f.useState(uP());return Tn(()=>{e||s(r=>r??String(dP++))},[e]),e||(t?`radix-${t}`:"")}cP(vs,"useId");const hP=["top","right","bottom","left"],Zr=Math.min,ir=Math.max,Wu=Math.round,kc=Math.floor,ar=e=>({x:e,y:e}),fP={left:"right",right:"left",bottom:"top",top:"bottom"};function gS(e,t,s){return ir(e,Zr(t,s))}function fr(e,t){return typeof e=="function"?e(t):e}function ei(e){return e.split("-")[0]}function nl(e){return e.split("-")[1]}function Vg(e){return e==="x"?"y":"x"}function Gg(e){return e==="y"?"height":"width"}function Ls(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function Yg(e){return Vg(Ls(e))}function mP(e,t,s){s===void 0&&(s=!1);const r=nl(e),i=Yg(e),a=Gg(i);let l=i==="x"?r===(s?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[a]>t.floating[a]&&(l=Hu(l)),[l,Hu(l)]}function pP(e){const t=Hu(e);return[Pm(e),t,Pm(t)]}function Pm(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const pw=["left","right"],gw=["right","left"],gP=["top","bottom"],xP=["bottom","top"];function vP(e,t,s){switch(e){case"top":case"bottom":return s?t?gw:pw:t?pw:gw;case"left":case"right":return t?gP:xP;default:return[]}}function jP(e,t,s,r){const i=nl(e);let a=vP(ei(e),s==="start",r);return i&&(a=a.map(l=>l+"-"+i),t&&(a=a.concat(a.map(Pm)))),a}function Hu(e){const t=ei(e);return fP[t]+e.slice(t.length)}function wP(e){var t,s,r,i;return{top:(t=e.top)!=null?t:0,right:(s=e.right)!=null?s:0,bottom:(r=e.bottom)!=null?r:0,left:(i=e.left)!=null?i:0}}function xS(e){return typeof e!="number"?wP(e):{top:e,right:e,bottom:e,left:e}}function Ku(e){const{x:t,y:s,width:r,height:i}=e;return{width:r,height:i,top:s,left:t,right:t+r,bottom:s+i,x:t,y:s}}function xw(e,t,s){let{reference:r,floating:i}=e;const a=Ls(t),l=Yg(t),o=Gg(l),c=ei(t),u=a==="y",h=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,m=r[o]/2-i[o]/2;let p;switch(c){case"top":p={x:h,y:r.y-i.height};break;case"bottom":p={x:h,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:d};break;case"left":p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}const x=nl(t);return x&&(p[l]+=m*(x==="end"?1:-1)*(s&&u?-1:1)),p}async function yP(e,t){var s;t===void 0&&(t={});const{x:r,y:i,platform:a,rects:l,elements:o,strategy:c}=e,{boundary:u="clippingAncestors",rootBoundary:h="viewport",elementContext:d="floating",altBoundary:m=!1,padding:p=0}=fr(t,e),x=xS(p),b=o[m?d==="floating"?"reference":"floating":d],g=Ku(await a.getClippingRect({element:(s=await(a.isElement==null?void 0:a.isElement(b)))==null||s?b:b.contextElement||await(a.getDocumentElement==null?void 0:a.getDocumentElement(o.floating)),boundary:u,rootBoundary:h,strategy:c})),v=d==="floating"?{x:r,y:i,width:l.floating.width,height:l.floating.height}:l.reference,w=await(a.getOffsetParent==null?void 0:a.getOffsetParent(o.floating)),y=await(a.isElement==null?void 0:a.isElement(w))&&await(a.getScale==null?void 0:a.getScale(w))||{x:1,y:1},N=Ku(a.convertOffsetParentRelativeRectToViewportRelativeRect?await a.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:v,offsetParent:w,strategy:c}):v);return{top:(g.top-N.top+x.top)/y.y,bottom:(N.bottom-g.bottom+x.bottom)/y.y,left:(g.left-N.left+x.left)/y.x,right:(N.right-g.right+x.right)/y.x}}const bP=50,kP=async(e,t,s)=>{const{placement:r="bottom",strategy:i="absolute",middleware:a=[],platform:l}=s,o=l.detectOverflow?l:{...l,detectOverflow:yP},c=await(l.isRTL==null?void 0:l.isRTL(t));let u=await l.getElementRects({reference:e,floating:t,strategy:i}),{x:h,y:d}=xw(u,r,c),m=r,p=0;const x={};for(let j=0;j<a.length;j++){const b=a[j];if(!b)continue;const{name:g,fn:v}=b,{x:w,y,data:N,reset:k}=await v({x:h,y:d,initialPlacement:r,placement:m,strategy:i,middlewareData:x,rects:u,platform:o,elements:{reference:e,floating:t}});h=w??h,d=y??d,x[g]={...x[g],...N},k&&p<bP&&(p++,typeof k=="object"&&(k.placement&&(m=k.placement),k.rects&&(u=k.rects===!0?await l.getElementRects({reference:e,floating:t,strategy:i}):k.rects),{x:h,y:d}=xw(u,m,c)),j=-1)}return{x:h,y:d,placement:m,strategy:i,middlewareData:x}},SP=e=>({name:"arrow",options:e,async fn(t){const{x:s,y:r,placement:i,rects:a,platform:l,elements:o,middlewareData:c}=t,{element:u,padding:h=0}=fr(e,t)||{};if(u==null)return{};const d=xS(h),m={x:s,y:r},p=Yg(i),x=Gg(p),j=await l.getDimensions(u),b=p==="y",g=b?"top":"left",v=b?"bottom":"right",w=b?"clientHeight":"clientWidth",y=a.reference[x]+a.reference[p]-m[p]-a.floating[x],N=m[p]-a.reference[p],k=await(l.getOffsetParent==null?void 0:l.getOffsetParent(u));let S=k?k[w]:0;(!S||!await(l.isElement==null?void 0:l.isElement(k)))&&(S=o.floating[w]||a.floating[x]);const C=y/2-N/2,I=S/2-j[x]/2-1,A=Zr(d[g],I),O=Zr(d[v],I),z=S-j[x]-O,L=S/2-j[x]/2+C,E=gS(A,L,z),$=!c.arrow&&nl(i)!=null&&L!==E&&a.reference[x]/2-(L<A?A:O)-j[x]/2<0,_=$?L<A?L-A:L-z:0;return{[p]:m[p]+_,data:{[p]:E,centerOffset:L-E-_,...$&&{alignmentOffset:_}},reset:$}}}),NP=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var s,r;const{placement:i,middlewareData:a,rects:l,initialPlacement:o,platform:c,elements:u}=t,{mainAxis:h=!0,crossAxis:d=!0,fallbackPlacements:m,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:x="none",flipAlignment:j=!0,...b}=fr(e,t);if((s=a.arrow)!=null&&s.alignmentOffset)return{};const g=ei(i),v=Ls(o),w=ei(o)===o,y=await(c.isRTL==null?void 0:c.isRTL(u.floating)),N=m||(w||!j?[Hu(o)]:pP(o)),k=x!=="none";!m&&k&&N.push(...jP(o,j,x,y));const S=[o,...N],C=await c.detectOverflow(t,b),I=[];let A=((r=a.flip)==null?void 0:r.overflows)||[];if(h&&I.push(C[g]),d){const E=mP(i,l,y);I.push(C[E[0]],C[E[1]])}if(A=[...A,{placement:i,overflows:I}],!I.every(E=>E<=0)){var O,z;const E=(((O=a.flip)==null?void 0:O.index)||0)+1,$=S[E];if($&&(!(d==="alignment"?v!==Ls($):!1)||A.every(M=>Ls(M.placement)===v?M.overflows[0]>0:!0)))return{data:{index:E,overflows:A},reset:{placement:$}};let _=(z=A.filter(B=>B.overflows[0]<=0).sort((B,M)=>B.overflows[1]-M.overflows[1])[0])==null?void 0:z.placement;if(!_)switch(p){case"bestFit":{var L;const B=(L=A.filter(M=>{if(k){const W=Ls(M.placement);return W===v||W==="y"}return!0}).map(M=>[M.placement,M.overflows.filter(W=>W>0).reduce((W,D)=>W+D,0)]).sort((M,W)=>M[1]-W[1])[0])==null?void 0:L[0];B&&(_=B);break}case"initialPlacement":_=o;break}if(i!==_)return{reset:{placement:_}}}return{}}}};function vw(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function jw(e){return hP.some(t=>e[t]>=0)}const CP=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:s,platform:r}=t,{strategy:i="referenceHidden",...a}=fr(e,t);switch(i){case"referenceHidden":{const l=await r.detectOverflow(t,{...a,elementContext:"reference"}),o=vw(l,s.reference);return{data:{referenceHiddenOffsets:o,referenceHidden:jw(o)}}}case"escaped":{const l=await r.detectOverflow(t,{...a,altBoundary:!0}),o=vw(l,s.floating);return{data:{escapedOffsets:o,escaped:jw(o)}}}default:return{}}}}},vS=new Set(["left","top"]);async function EP(e,t){const{placement:s,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),l=ei(s),o=nl(s),c=Ls(s)==="y",u=vS.has(l)?-1:1,h=a&&c?-1:1,d=fr(t,e);let{mainAxis:m,crossAxis:p,alignmentAxis:x}=typeof d=="number"?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return o&&typeof x=="number"&&(p=o==="end"?x*-1:x),c?{x:p*h,y:m*u}:{x:m*u,y:p*h}}const AP=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var s,r;const{x:i,y:a,placement:l,middlewareData:o}=t,c=await EP(t,e);return l===((s=o.offset)==null?void 0:s.placement)&&(r=o.arrow)!=null&&r.alignmentOffset?{}:{x:i+c.x,y:a+c.y,data:{...c,placement:l}}}}},TP=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:s,y:r,placement:i,platform:a}=t,{mainAxis:l=!0,crossAxis:o=!1,limiter:c={fn:v=>{let{x:w,y}=v;return{x:w,y}}},...u}=fr(e,t),h={x:s,y:r},d=await a.detectOverflow(t,u),m=Ls(i),p=Vg(m);let x=h[p],j=h[m];const b=(v,w)=>gS(w+d[v==="y"?"top":"left"],w,w-d[v==="y"?"bottom":"right"]);l&&(x=b(p,x)),o&&(j=b(m,j));const g=c.fn({...t,[p]:x,[m]:j});return{...g,data:{x:g.x-s,y:g.y-r,enabled:{[p]:l,[m]:o}}}}}},RP=function(e){return e===void 0&&(e={}),{options:e,fn(t){var s,r;const{x:i,y:a,placement:l,rects:o,middlewareData:c}=t,{offset:u=0,mainAxis:h=!0,crossAxis:d=!0}=fr(e,t),m={x:i,y:a},p=Ls(l),x=Vg(p);let j=m[x],b=m[p];const g=fr(u,t),v=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:(s=g.mainAxis)!=null?s:0,crossAxis:(r=g.crossAxis)!=null?r:0};if(h){const N=x==="y"?"height":"width",k=o.reference[x]-o.floating[N]+v.mainAxis,S=o.reference[x]+o.reference[N]-v.mainAxis;j<k?j=k:j>S&&(j=S)}if(d){var w,y;const N=x==="y"?"width":"height",k=vS.has(ei(l)),S=o.reference[p]-o.floating[N]+(k&&((w=c.offset)==null?void 0:w[p])||0)+(k?0:v.crossAxis),C=o.reference[p]+o.reference[N]+(k?0:((y=c.offset)==null?void 0:y[p])||0)-(k?v.crossAxis:0);b<S?b=S:b>C&&(b=C)}return{[x]:j,[p]:b}}}},IP=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){const{placement:s,rects:r,platform:i,elements:a}=t,{apply:l=()=>{},...o}=fr(e,t),c=await i.detectOverflow(t,o),u=ei(s),h=nl(s),d=Ls(s)==="y",{width:m,height:p}=r.floating;let x,j;u==="top"||u==="bottom"?(x=u,j=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(j=u,x=h==="end"?"top":"bottom");const b=p-c.top-c.bottom,g=m-c.left-c.right,v=Zr(p-c[x],b),w=Zr(m-c[j],g),y=t.middlewareData.shift,N=!y;let k=v,S=w;y!=null&&y.enabled.x&&(S=g),y!=null&&y.enabled.y&&(k=b),N&&!h&&(d?S=m-2*ir(c.left,c.right):k=p-2*ir(c.top,c.bottom)),await l({...t,availableWidth:S,availableHeight:k});const C=await i.getDimensions(a.floating);return m!==C.width||p!==C.height?{reset:{rects:!0}}:{}}}};function Id(){return typeof window<"u"}function sl(e){return jS(e)?(e.nodeName||"").toLowerCase():"#document"}function Rn(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function vr(e){var t;return(t=(jS(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function jS(e){return Id()?e instanceof Node||e instanceof Rn(e).Node:!1}function Ws(e){return Id()?e instanceof Element||e instanceof Rn(e).Element:!1}function oi(e){return Id()?e instanceof HTMLElement||e instanceof Rn(e).HTMLElement:!1}function ww(e){return!Id()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Rn(e).ShadowRoot}function Pd(e){const{overflow:t,overflowX:s,overflowY:r,display:i}=Hs(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+s)&&i!=="inline"&&i!=="contents"}function PP(e){return/^(table|td|th)$/.test(sl(e))}function $d(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const $P=/transform|translate|scale|rotate|perspective|filter/,MP=/paint|layout|strict|content/,pi=e=>!!e&&e!=="none";let zh;function qg(e){const t=Ws(e)?Hs(e):e;return pi(t.transform)||pi(t.translate)||pi(t.scale)||pi(t.rotate)||pi(t.perspective)||!Qg()&&(pi(t.backdropFilter)||pi(t.filter))||$P.test(t.willChange||"")||MP.test(t.contain||"")}function OP(e){let t=Oi(e);for(;oi(t)&&!go(t);){if(qg(t))return t;if($d(t))return null;t=Oi(t)}return null}function Qg(){return zh==null&&(zh=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),zh}function go(e){return/^(html|body|#document)$/.test(sl(e))}function Hs(e){return Rn(e).getComputedStyle(e)}function Md(e){return Ws(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Oi(e){if(sl(e)==="html")return e;const t=e.assignedSlot||e.parentNode||ww(e)&&e.host||vr(e);return ww(t)?t.host:t}function wS(e){const t=Oi(e);return go(t)?(e.ownerDocument||e).body:oi(t)&&Pd(t)?t:wS(t)}function xo(e,t,s){var r;t===void 0&&(t=[]),s===void 0&&(s=!0);const i=wS(e),a=i===((r=e.ownerDocument)==null?void 0:r.body),l=Rn(i);if(a){const o=$m(l);return t.concat(l,l.visualViewport||[],Pd(i)?i:[],o&&s?xo(o):[])}else return t.concat(i,xo(i,[],s))}function $m(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function yS(e){const t=Hs(e);let s=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=oi(e),a=i?e.offsetWidth:s,l=i?e.offsetHeight:r,o=Wu(s)!==a||Wu(r)!==l;return o&&(s=a,r=l),{width:s,height:r,$:o}}function Jg(e){return Ws(e)?e:e.contextElement}function Aa(e){const t=Jg(e);if(!oi(t))return ar(1);const s=t.getBoundingClientRect(),{width:r,height:i,$:a}=yS(t);let l=(a?Wu(s.width):s.width)/r,o=(a?Wu(s.height):s.height)/i;return(!l||!Number.isFinite(l))&&(l=1),(!o||!Number.isFinite(o))&&(o=1),{x:l,y:o}}const DP=ar(0);function bS(e){const t=Rn(e);return!Qg()||!t.visualViewport?DP:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function _P(e,t,s){return t===void 0&&(t=!1),!!s&&t&&s===Rn(e)}function Di(e,t,s,r){t===void 0&&(t=!1),s===void 0&&(s=!1);const i=e.getBoundingClientRect(),a=Jg(e);let l=ar(1);t&&(r?Ws(r)&&(l=Aa(r)):l=Aa(e));const o=_P(a,s,r)?bS(a):ar(0);let c=(i.left+o.x)/l.x,u=(i.top+o.y)/l.y,h=i.width/l.x,d=i.height/l.y;if(a&&r){const m=Rn(a),p=Ws(r)?Rn(r):r;let x=m,j=$m(x);for(;j&&p!==x;){const b=Aa(j),g=j.getBoundingClientRect(),v=Hs(j),w=g.left+(j.clientLeft+parseFloat(v.paddingLeft))*b.x,y=g.top+(j.clientTop+parseFloat(v.paddingTop))*b.y;c*=b.x,u*=b.y,h*=b.x,d*=b.y,c+=w,u+=y,x=Rn(j),j=$m(x)}}return Ku({width:h,height:d,x:c,y:u})}function Od(e,t){const s=Md(e).scrollLeft;return t?t.left+s:Di(vr(e)).left+s}function kS(e,t){const s=e.getBoundingClientRect(),r=s.left+t.scrollLeft-Od(e,s),i=s.top+t.scrollTop;return{x:r,y:i}}function LP(e){let{elements:t,rect:s,offsetParent:r,strategy:i}=e;const a=i==="fixed",l=vr(r),o=t?$d(t.floating):!1;if(r===l||o&&a)return s;let c={scrollLeft:0,scrollTop:0},u=ar(1);const h=ar(0),d=oi(r);if((d||!a)&&((sl(r)!=="body"||Pd(l))&&(c=Md(r)),d)){const p=Di(r);u=Aa(r),h.x=p.x+r.clientLeft,h.y=p.y+r.clientTop}const m=l&&!d&&!a?kS(l,c):ar(0);return{width:s.width*u.x,height:s.height*u.y,x:s.x*u.x-c.scrollLeft*u.x+h.x+m.x,y:s.y*u.y-c.scrollTop*u.y+h.y+m.y}}function FP(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function zP(e){const t=Md(e),s=e.ownerDocument.body,r=ir(e.scrollWidth,e.clientWidth,s.scrollWidth,s.clientWidth),i=ir(e.scrollHeight,e.clientHeight,s.scrollHeight,s.clientHeight);let a=-t.scrollLeft+Od(e);const l=-t.scrollTop;return Hs(s).direction==="rtl"&&(a+=ir(e.clientWidth,s.clientWidth)-r),{width:r,height:i,x:a,y:l}}const UP=25;function BP(e,t,s){s===void 0&&(s="viewport");const r=s==="layoutViewport",i=Rn(e),a=vr(e),l=i.visualViewport;let o=a.clientWidth,c=a.clientHeight,u=0,h=0;if(l){const m=!Qg()||t==="fixed";r?m||(u=-l.offsetLeft,h=-l.offsetTop):(o=l.width,c=l.height,m&&(u=l.offsetLeft,h=l.offsetTop))}if(Od(a)<=0){const m=a.ownerDocument,p=m.body,x=getComputedStyle(p),j=m.compatMode==="CSS1Compat"&&parseFloat(x.marginLeft)+parseFloat(x.marginRight)||0,b=Math.abs(a.clientWidth-p.clientWidth-j),g=getComputedStyle(a).scrollbarGutter==="stable both-edges"?b/2:b;g<=UP&&(o-=g)}return{width:o,height:c,x:u,y:h}}function WP(e,t){const s=Di(e,!0,t==="fixed"),r=s.top+e.clientTop,i=s.left+e.clientLeft,a=Aa(e),l=e.clientWidth*a.x,o=e.clientHeight*a.y,c=i*a.x,u=r*a.y;return{width:l,height:o,x:c,y:u}}function yw(e,t,s){let r;if(t==="viewport"||t==="layoutViewport")r=BP(e,s,t);else if(t==="document")r=zP(vr(e));else if(Ws(t))r=WP(t,s);else{const i=bS(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Ku(r)}function HP(e,t){const s=t.get(e);if(s)return s;let r=xo(e,[],!1).filter(o=>Ws(o)&&sl(o)!=="body"),i=null;const a=Hs(e).position==="fixed";let l=a?Oi(e):e;for(;Ws(l)&&!go(l);){const o=Hs(l),c=qg(l),u=i?i.position:a?"fixed":"";!c&&(u==="fixed"||u==="absolute"&&o.position==="static")?r=r.filter(d=>d!==l):i=o,l=Oi(l)}return t.set(e,r),r}function KP(e){let{element:t,boundary:s,rootBoundary:r,strategy:i}=e;const l=[...s==="clippingAncestors"?$d(t)?[]:HP(t,this._c):[].concat(s),r],o=yw(t,l[0],i);let c=o.top,u=o.right,h=o.bottom,d=o.left;for(let m=1;m<l.length;m++){const p=yw(t,l[m],i);c=ir(p.top,c),u=Zr(p.right,u),h=Zr(p.bottom,h),d=ir(p.left,d)}return{width:u-d,height:h-c,x:d,y:c}}function VP(e){const{width:t,height:s}=yS(e);return{width:t,height:s}}function GP(e,t,s){const r=oi(t),i=vr(t),a=s==="fixed",l=Di(e,!0,a,t);let o={scrollLeft:0,scrollTop:0};const c=ar(0);if((r||!a)&&((sl(t)!=="body"||Pd(i))&&(o=Md(t)),r)){const m=Di(t,!0,a,t);c.x=m.x+t.clientLeft,c.y=m.y+t.clientTop}!r&&i&&(c.x=Od(i));const u=i&&!r&&!a?kS(i,o):ar(0),h=l.left+o.scrollLeft-c.x-u.x,d=l.top+o.scrollTop-c.y-u.y;return{x:h,y:d,width:l.width,height:l.height}}function Uh(e){return Hs(e).position==="static"}function bw(e,t){if(!oi(e)||Hs(e).position==="fixed")return null;if(t)return t(e);let s=e.offsetParent;return vr(e)===s&&(s=s.ownerDocument.body),s}function SS(e,t){const s=Rn(e);if($d(e))return s;if(!oi(e)){let i=Oi(e);for(;i&&!go(i);){if(Ws(i)&&!Uh(i))return i;i=Oi(i)}return s}let r=bw(e,t);for(;r&&PP(r)&&Uh(r);)r=bw(r,t);return r&&go(r)&&Uh(r)&&!qg(r)?s:r||OP(e)||s}const YP=async function(e){const t=this.getOffsetParent||SS,s=this.getDimensions,r=await s(e.floating);return{reference:GP(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function qP(e){return Hs(e).direction==="rtl"}const QP={convertOffsetParentRelativeRectToViewportRelativeRect:LP,getDocumentElement:vr,getClippingRect:KP,getOffsetParent:SS,getElementRects:YP,getClientRects:FP,getDimensions:VP,getScale:Aa,isElement:Ws,isRTL:qP};function NS(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function JP(e,t,s){let r=null,i;const a=vr(e);function l(){var h;clearTimeout(i),(h=r)==null||h.disconnect(),r=null}function o(h,d){h===void 0&&(h=!1),d===void 0&&(d=1),l();const m=e.getBoundingClientRect(),{left:p,top:x,width:j,height:b}=m;if(h||t(),!j||!b)return;const g=kc(x),v=kc(a.clientWidth-(p+j)),w=kc(a.clientHeight-(x+b)),y=kc(p),k={rootMargin:-g+"px "+-v+"px "+-w+"px "+-y+"px",threshold:ir(0,Zr(1,d))||1};let S=!0;function C(I){const A=I[0].intersectionRatio;if(!NS(m,e.getBoundingClientRect()))return o();if(A!==d){if(!S)return o();A?o(!1,A):i=setTimeout(()=>{o(!1,1e-7)},1e3)}S=!1}try{r=new IntersectionObserver(C,{...k,root:a.ownerDocument})}catch{r=new IntersectionObserver(C,k)}r.observe(e)}const c=Rn(e),u=()=>o(s);return c.addEventListener("resize",u),o(!0),()=>{c.removeEventListener("resize",u),l()}}function XP(e,t,s,r){r===void 0&&(r={});const{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:l=typeof ResizeObserver=="function",layoutShift:o=typeof IntersectionObserver=="function",animationFrame:c=!1}=r,u=Jg(e),h=i||a?[...u?xo(u):[],...t?xo(t):[]]:[];h.forEach(g=>{i&&g.addEventListener("scroll",s),a&&g.addEventListener("resize",s)});const d=u&&o?JP(u,s,a):null;let m=-1,p=null;l&&(p=new ResizeObserver(g=>{let[v]=g;v&&v.target===u&&p&&t&&(p.unobserve(t),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var w;(w=p)==null||w.observe(t)})),s()}),u&&!c&&p.observe(u),t&&p.observe(t));let x,j=c?Di(e):null;c&&b();function b(){const g=Di(e);j&&!NS(j,g)&&s(),j=g,x=requestAnimationFrame(b)}return s(),()=>{var g;h.forEach(v=>{i&&v.removeEventListener("scroll",s),a&&v.removeEventListener("resize",s)}),d==null||d(),(g=p)==null||g.disconnect(),p=null,c&&cancelAnimationFrame(x)}}const ZP=AP,e2=TP,t2=NP,n2=IP,s2=CP,kw=SP,r2=RP,i2=(e,t,s)=>{const r=new Map,i=s??{},a={...QP,...i.platform,_c:r};return kP(e,t,{...i,platform:a})};var a2=typeof document<"u",l2=function(){},ou=a2?f.useLayoutEffect:l2;function Vu(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let s,r,i;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(s=e.length,s!==t.length)return!1;for(r=s;r--!==0;)if(!Vu(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),s=i.length,s!==Object.keys(t).length)return!1;for(r=s;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=s;r--!==0;){const a=i[r];if(!(a==="_owner"&&e.$$typeof)&&!Vu(e[a],t[a]))return!1}return!0}return e!==e&&t!==t}function CS(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Sw(e,t){const s=CS(e);return Math.round(t*s)/s}function Bh(e){const t=f.useRef(e);return ou(()=>{t.current=e}),t}function o2(e){e===void 0&&(e={});const{placement:t="bottom",strategy:s="absolute",middleware:r=[],platform:i,elements:{reference:a,floating:l}={},transform:o=!0,whileElementsMounted:c,open:u}=e,[h,d]=f.useState({x:0,y:0,strategy:s,placement:t,middlewareData:{},isPositioned:!1}),[m,p]=f.useState(r);Vu(m,r)||p(r);const[x,j]=f.useState(null),[b,g]=f.useState(null),v=f.useCallback(M=>{M!==k.current&&(k.current=M,j(M))},[]),w=f.useCallback(M=>{M!==S.current&&(S.current=M,g(M))},[]),y=a||x,N=l||b,k=f.useRef(null),S=f.useRef(null),C=f.useRef(h),I=c!=null,A=Bh(c),O=Bh(i),z=Bh(u),L=f.useCallback(()=>{if(!k.current||!S.current)return;const M={placement:t,strategy:s,middleware:m};O.current&&(M.platform=O.current),i2(k.current,S.current,M).then(W=>{const D={...W,isPositioned:z.current!==!1};E.current&&!Vu(C.current,D)&&(C.current=D,Fo.flushSync(()=>{d(D)}))})},[m,t,s,O,z]);ou(()=>{u===!1&&C.current.isPositioned&&(C.current.isPositioned=!1,d(M=>({...M,isPositioned:!1})))},[u]);const E=f.useRef(!1);ou(()=>(E.current=!0,()=>{E.current=!1}),[]),ou(()=>{if(y&&(k.current=y),N&&(S.current=N),y&&N){if(A.current)return A.current(y,N,L);L()}},[y,N,L,A,I]);const $=f.useMemo(()=>({reference:k,floating:S,setReference:v,setFloating:w}),[v,w]),_=f.useMemo(()=>({reference:y,floating:N}),[y,N]),B=f.useMemo(()=>{const M={position:s,left:0,top:0};if(!_.floating)return M;const W=Sw(_.floating,h.x),D=Sw(_.floating,h.y);return o?{...M,transform:"translate("+W+"px, "+D+"px)",...CS(_.floating)>=1.5&&{willChange:"transform"}}:{position:s,left:W,top:D}},[s,o,_.floating,h.x,h.y]);return f.useMemo(()=>({...h,update:L,refs:$,elements:_,floatingStyles:B}),[h,L,$,_,B])}const c2=e=>{function t(s){return{}.hasOwnProperty.call(s,"current")}return{name:"arrow",options:e,fn(s){const{element:r,padding:i}=typeof e=="function"?e(s):e;return r&&t(r)?r.current!=null?kw({element:r.current,padding:i}).fn(s):{}:r?kw({element:r,padding:i}).fn(s):{}}}},u2=(e,t)=>{const s=ZP(e);return{name:s.name,fn:s.fn,options:[e,t]}},d2=(e,t)=>{const s=e2(e);return{name:s.name,fn:s.fn,options:[e,t]}},h2=(e,t)=>({fn:r2(e).fn,options:[e,t]}),f2=(e,t)=>{const s=t2(e);return{name:s.name,fn:s.fn,options:[e,t]}},m2=(e,t)=>{const s=n2(e);return{name:s.name,fn:s.fn,options:[e,t]}},p2=(e,t)=>{const s=s2(e);return{name:s.name,fn:s.fn,options:[e,t]}},g2=(e,t)=>{const s=c2(e);return{name:s.name,fn:s.fn,options:[e,t]}};var x2=Object.defineProperty,v2=(e,t)=>x2(e,"name",{value:t,configurable:!0});function ES(e){const[t,s]=f.useState(void 0);return Tn(()=>{if(e){s({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(i=>{if(!Array.isArray(i)||!i.length)return;const a=i[0];let l,o;if("borderBoxSize"in a){const c=a.borderBoxSize,u=Array.isArray(c)?c[0]:c;l=u.inlineSize,o=u.blockSize}else l=e.offsetWidth,o=e.offsetHeight;s({width:l,height:o})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else s(void 0)},[e]),t}v2(ES,"useSize");var j2=Object.defineProperty,Kr=(e,t)=>j2(e,"name",{value:t,configurable:!0}),AS="Popper",[TS,Dd]=Ns(AS),[w2,RS]=TS(AS),y2=Kr(e=>{const{__scopePopper:t,children:s}=e,[r,i]=f.useState(null),[a,l]=f.useState(void 0);return n.jsx(w2,{scope:t,anchor:r,onAnchorChange:i,placementState:a,setPlacementState:l,children:s})},"Popper"),b2="PopperAnchor",k2=f.forwardRef(Kr(function(t,s){const{__scopePopper:r,virtualRef:i,...a}=t,l=RS(b2,r),o=f.useRef(null),c=l.onAnchorChange,u=f.useCallback(j=>{o.current=j,j&&c(j)},[c]),h=ct(s,u),d=f.useRef(null);f.useEffect(()=>{if(!i)return;const j=d.current;d.current=i.current,j!==d.current&&c(d.current)});const m=l.placementState&&_d(l.placementState),p=m==null?void 0:m[0],x=m==null?void 0:m[1];return i?null:n.jsx(jt.div,{"data-radix-popper-side":p,"data-radix-popper-align":x,...a,ref:h})},"PopperAnchor")),IS="PopperContent",[S2,$K]=TS(IS),N2=f.forwardRef(Kr(function(t,s){var Pe,ke,ye,Ce,ut,fe,Me;const{__scopePopper:r,side:i="bottom",sideOffset:a=0,align:l="center",alignOffset:o=0,arrowPadding:c=0,avoidCollisions:u=!0,collisionBoundary:h=[],collisionPadding:d=0,sticky:m="partial",hideWhenDetached:p=!1,updatePositionStrategy:x="optimized",onPlaced:j,...b}=t,g=RS(IS,r),[v,w]=f.useState(null),y=ct(s,w),[N,k]=f.useState(null),S=ES(N),C=(S==null?void 0:S.width)??0,I=(S==null?void 0:S.height)??0,A=i+(l!=="center"?"-"+l:""),O=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},z=Array.isArray(h)?h:[h],L=z.length>0,E={padding:O,boundary:z.filter(PS),altBoundary:L},{refs:$,floatingStyles:_,placement:B,isPositioned:M,middlewareData:W}=o2({strategy:"fixed",placement:A,whileElementsMounted:Kr((...ce)=>XP(...ce,{animationFrame:x==="always"}),"whileElementsMounted"),elements:{reference:g.anchor},middleware:[u2({mainAxis:a+I,alignmentAxis:o}),u&&d2({mainAxis:!0,crossAxis:!1,limiter:m==="partial"?h2():void 0,...E}),u&&f2({...E}),m2({...E,apply:Kr(({elements:ce,rects:Te,availableWidth:G,availableHeight:ie})=>{const{width:$e,height:yt}=Te.reference,Ge=ce.floating.style;Ge.setProperty("--radix-popper-available-width",`${G}px`),Ge.setProperty("--radix-popper-available-height",`${ie}px`),Ge.setProperty("--radix-popper-anchor-width",`${$e}px`),Ge.setProperty("--radix-popper-anchor-height",`${yt}px`)},"apply")}),N&&g2({element:N,padding:c}),C2({arrowWidth:C,arrowHeight:I}),p&&p2({strategy:"referenceHidden",...E,boundary:L?E.boundary:void 0})]}),D=g.setPlacementState;Tn(()=>(D(B),()=>{D(void 0)}),[B,D]);const[U,V]=_d(B),Z=us(j);Tn(()=>{M&&(Z==null||Z())},[M,Z]);const ue=(Pe=W.arrow)==null?void 0:Pe.x,Ae=(ke=W.arrow)==null?void 0:ke.y,X=((ye=W.arrow)==null?void 0:ye.centerOffset)!==0,[ae,me]=f.useState();return Tn(()=>{v&&me(window.getComputedStyle(v).zIndex)},[v]),n.jsx("div",{ref:$.setFloating,"data-radix-popper-content-wrapper":"",style:{..._,transform:M?_.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ae,"--radix-popper-transform-origin":[(Ce=W.transformOrigin)==null?void 0:Ce.x,(ut=W.transformOrigin)==null?void 0:ut.y].join(" "),...((fe=W.hide)==null?void 0:fe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:n.jsx(S2,{scope:r,placedSide:U,placedAlign:V,onArrowChange:k,arrowX:ue,arrowY:Ae,shouldHideArrow:X,children:n.jsx(jt.div,{"data-side":U,"data-align":V,...b,ref:y,style:{...b.style,animation:M?(Me=b.style)==null?void 0:Me.animation:"none"}})})})},"PopperContent"));function PS(e){return e!==null}Kr(PS,"isNotNull");var C2=Kr(e=>({name:"transformOrigin",options:e,fn(t){var b,g,v;const{placement:s,rects:r,middlewareData:i}=t,l=((b=i.arrow)==null?void 0:b.centerOffset)!==0,o=l?0:e.arrowWidth,c=l?0:e.arrowHeight,[u,h]=_d(s),d={start:"0%",center:"50%",end:"100%"}[h],m=(((g=i.arrow)==null?void 0:g.x)??0)+o/2,p=(((v=i.arrow)==null?void 0:v.y)??0)+c/2;let x="",j="";return u==="bottom"?(x=l?d:`${m}px`,j=`${-c}px`):u==="top"?(x=l?d:`${m}px`,j=`${r.floating.height+c}px`):u==="right"?(x=`${-c}px`,j=l?d:`${p}px`):u==="left"&&(x=`${r.floating.width+c}px`,j=l?d:`${p}px`),{data:{x,y:j}}}}),"transformOrigin");function _d(e){const[t,s="center"]=e.split("-");return[t,s]}Kr(_d,"getSideAndAlignFromPlacement");var Xg=y2,$S=k2,MS=N2,E2=Object.defineProperty,Wt=(e,t)=>E2(e,"name",{value:t,configurable:!0}),[Zg,MK]=Ns("Tooltip",[Dd]),ex=Dd(),A2="TooltipProvider",T2=700,Mm="tooltip.open",[R2,tx]=Zg(A2),I2=Wt(e=>{const{__scopeTooltip:t,delayDuration:s=T2,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,l=f.useRef(!0),o=f.useRef(!1),c=f.useRef(0);return f.useEffect(()=>{const u=c.current;return()=>window.clearTimeout(u)},[]),n.jsx(R2,{scope:t,isOpenDelayedRef:l,delayDuration:s,onOpen:f.useCallback(()=>{r<=0||(window.clearTimeout(c.current),l.current=!1)},[r]),onClose:f.useCallback(()=>{r<=0||(window.clearTimeout(c.current),c.current=window.setTimeout(()=>l.current=!0,r))},[r]),isPointerInTransitRef:o,onPointerInTransitChange:f.useCallback(u=>{o.current=u},[]),disableHoverableContent:i,children:a})},"TooltipProvider"),Om="Tooltip",[P2,Uo]=Zg(Om),$2=Wt(e=>{const{__scopeTooltip:t,children:s,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:l,delayDuration:o}=e,c=tx(Om,e.__scopeTooltip),u=ex(t),[h,d]=f.useState(null),[m,p]=f.useState(void 0),x=vs(),j=f.useRef(0),b=l??c.disableHoverableContent,g=o??c.delayDuration,v=f.useRef(!1),[w,y]=Wi({prop:r,defaultProp:i??!1,onChange:Wt(A=>{A?(c.onOpen(),document.dispatchEvent(new CustomEvent(Mm))):c.onClose(),a==null||a(A)},"onChange"),caller:Om}),N=f.useMemo(()=>w?v.current?"delayed-open":"instant-open":"closed",[w]),k=f.useCallback(()=>{window.clearTimeout(j.current),j.current=0,v.current=!1,y(!0)},[y]),S=f.useCallback(()=>{window.clearTimeout(j.current),j.current=0,y(!1)},[y]),C=f.useCallback(()=>{window.clearTimeout(j.current),j.current=window.setTimeout(()=>{v.current=!0,y(!0),j.current=0},g)},[g,y]);f.useEffect(()=>()=>{j.current&&(window.clearTimeout(j.current),j.current=0)},[]);const I=m??x;return n.jsx(Xg,{...u,children:n.jsx(P2,{scope:t,contentId:I,setContentId:p,open:w,stateAttribute:N,trigger:h,onTriggerChange:d,onTriggerEnter:f.useCallback(()=>{c.isOpenDelayedRef.current?C():k()},[c.isOpenDelayedRef,C,k]),onTriggerLeave:f.useCallback(()=>{b?S():(window.clearTimeout(j.current),j.current=0)},[S,b]),onOpen:k,onClose:S,disableHoverableContent:b,children:s})})},"Tooltip"),Nw="TooltipTrigger",M2=f.forwardRef(Wt(function(t,s){const{__scopeTooltip:r,...i}=t,a=Uo(Nw,r),l=tx(Nw,r),o=ex(r),c=f.useRef(null),u=ct(s,c,a.onTriggerChange),h=f.useRef(!1),d=f.useRef(!1),m=f.useCallback(()=>h.current=!1,[]);return f.useEffect(()=>()=>document.removeEventListener("pointerup",m),[m]),n.jsx($S,{asChild:!0,...o,children:n.jsx(jt.button,{"aria-describedby":a.open?a.contentId:void 0,"data-state":a.stateAttribute,...i,ref:u,onPointerMove:Ie(t.onPointerMove,p=>{p.pointerType!=="touch"&&!d.current&&!l.isPointerInTransitRef.current&&(a.onTriggerEnter(),d.current=!0)}),onPointerLeave:Ie(t.onPointerLeave,()=>{a.onTriggerLeave(),d.current=!1}),onPointerDown:Ie(t.onPointerDown,()=>{a.open&&a.onClose(),h.current=!0,document.addEventListener("pointerup",m,{once:!0})}),onFocus:Ie(t.onFocus,()=>{h.current||a.onOpen()}),onBlur:Ie(t.onBlur,a.onClose),onClick:Ie(t.onClick,a.onClose)})})},"TooltipTrigger")),OS="TooltipPortal",[O2,D2]=Zg(OS,{forceMount:void 0}),_2=Wt(e=>{const{__scopeTooltip:t,forceMount:s,children:r,container:i}=e,a=Uo(OS,t);return n.jsx(O2,{scope:t,forceMount:s,children:n.jsx(xr,{present:s||a.open,children:n.jsx(Kg,{asChild:!0,container:i,children:r})})})},"TooltipPortal"),vo="TooltipContent",L2=f.forwardRef(Wt(function(t,s){const r=D2(vo,t.__scopeTooltip),{forceMount:i=r.forceMount,side:a="top",...l}=t,o=Uo(vo,t.__scopeTooltip);return n.jsx(xr,{present:i||o.open,children:o.disableHoverableContent?n.jsx(DS,{side:a,...l,ref:s}):n.jsx(F2,{side:a,...l,ref:s})})},"TooltipContent")),F2=f.forwardRef(Wt(function(t,s){const r=Uo(vo,t.__scopeTooltip),i=tx(vo,t.__scopeTooltip),a=f.useRef(null),l=ct(s,a),[o,c]=f.useState(null),{trigger:u,onClose:h}=r,d=a.current,{onPointerInTransitChange:m}=i,p=f.useCallback(()=>{c(null),m(!1)},[m]),x=f.useCallback((j,b)=>{const g=j.currentTarget,v={x:j.clientX,y:j.clientY},w=_S(v,g.getBoundingClientRect()),y=LS(v,w),N=FS(b.getBoundingClientRect()),k=US([...y,...N]);c(k),m(!0)},[m]);return f.useEffect(()=>()=>p(),[p]),f.useEffect(()=>{if(u&&d){const j=Wt(g=>x(g,d),"handleTriggerLeave"),b=Wt(g=>x(g,u),"handleContentLeave");return u.addEventListener("pointerleave",j),d.addEventListener("pointerleave",b),()=>{u.removeEventListener("pointerleave",j),d.removeEventListener("pointerleave",b)}}},[u,d,x,p]),f.useEffect(()=>{if(o){const j=Wt(b=>{const g=b.target,v={x:b.clientX,y:b.clientY},w=(u==null?void 0:u.contains(g))||(d==null?void 0:d.contains(g)),y=!zS(v,o);w?p():y&&(p(),h())},"handleTrackPointerGrace");return document.addEventListener("pointermove",j),()=>document.removeEventListener("pointermove",j)}},[u,d,o,h,p]),n.jsx(DS,{...t,ref:l})},"TooltipContentHoverable")),z2=Wk("TooltipContent"),DS=f.forwardRef(Wt(function(t,s){const{__scopeTooltip:r,children:i,"aria-label":a,id:l,onEscapeKeyDown:o,onPointerDownOutside:c,...u}=t,h=Uo(vo,r),d=ex(r),{onClose:m}=h;f.useEffect(()=>(document.addEventListener(Mm,m),()=>document.removeEventListener(Mm,m)),[m]),f.useEffect(()=>{if(h.trigger){const x=Wt(j=>{j.target instanceof Node&&j.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 Tn(()=>(p(l),()=>{p(void 0)}),[l,p]),n.jsx(Wg,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:o,onPointerDownOutside:c,onFocusOutside:x=>x.preventDefault(),onDismiss:m,children:n.jsxs(MS,{"data-state":h.stateAttribute,role:a?void 0:"tooltip",id:a?void 0:h.contentId,...d,...u,ref:s,style:{...u.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[n.jsx(z2,{children:i}),a?n.jsx(GI,{id:h.contentId,role:"tooltip",children:a}):null]})})},"TooltipContentImpl"));function _S(e,t){const s=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),a=Math.abs(t.left-e.x);switch(Math.min(s,r,i,a)){case a:return"left";case i:return"right";case s:return"top";case r:return"bottom";default:throw new Error("unreachable")}}Wt(_S,"getExitSideFromRect");function LS(e,t,s=5){const r=[];switch(t){case"top":r.push({x:e.x-s,y:e.y+s},{x:e.x+s,y:e.y+s});break;case"bottom":r.push({x:e.x-s,y:e.y-s},{x:e.x+s,y:e.y-s});break;case"left":r.push({x:e.x+s,y:e.y-s},{x:e.x+s,y:e.y+s});break;case"right":r.push({x:e.x-s,y:e.y-s},{x:e.x-s,y:e.y+s});break}return r}Wt(LS,"getPaddedExitPoints");function FS(e){const{top:t,right:s,bottom:r,left:i}=e;return[{x:i,y:t},{x:s,y:t},{x:s,y:r},{x:i,y:r}]}Wt(FS,"getPointsFromRect");function zS(e,t){const{x:s,y:r}=e;let i=!1;for(let a=0,l=t.length-1;a<t.length;l=a++){const o=t[a],c=t[l],u=o.x,h=o.y,d=c.x,m=c.y;h>r!=m>r&&s<(d-u)*(r-h)/(m-h)+u&&(i=!i)}return i}Wt(zS,"isPointInPolygon");function US(e){const t=e.slice();return t.sort((s,r)=>s.x<r.x?-1:s.x>r.x?1:s.y<r.y?-1:s.y>r.y?1:0),BS(t)}Wt(US,"getHull");function BS(e){if(e.length<=1)return e.slice();const t=[];for(let r=0;r<e.length;r++){const i=e[r];for(;t.length>=2;){const a=t[t.length-1],l=t[t.length-2];if((a.x-l.x)*(i.y-l.y)>=(a.y-l.y)*(i.x-l.x))t.pop();else break}t.push(i)}t.pop();const s=[];for(let r=e.length-1;r>=0;r--){const i=e[r];for(;s.length>=2;){const a=s[s.length-1],l=s[s.length-2];if((a.x-l.x)*(i.y-l.y)>=(a.y-l.y)*(i.x-l.x))s.pop();else break}s.push(i)}return s.pop(),t.length===1&&s.length===1&&t[0].x===s[0].x&&t[0].y===s[0].y?t:t.concat(s)}Wt(BS,"getHullPresorted");var Cw=I2,jo=$2,wo=M2,yo=_2,bo=L2;const Ew="buddi_csrf",rl="x-buddi-csrf",ko="buddi:agents-changed",U2="This page's sign-in no longer matches its cookies. Reload the page and try again.";class pe extends Error{constructor(t,s,r){super(s),this.status=t,this.detail=r,this.name="ApiError"}}function Hi(){var r;const e=Number(location.port)||(location.protocol==="https:"?443:80),t=document.cookie.match(new RegExp(`(?:^|; )${Ew}_${e}=([^;]*)`));if(t!=null&&t[1])return decodeURIComponent(t[1]);const s=[...document.cookie.matchAll(new RegExp(`(?:^|; )${Ew}(?:_\\d+)?=([^;]*)`,"g"))];return s.length===1&&((r=s[0])!=null&&r[1])?decodeURIComponent(s[0][1]):""}const Gu="buddi isn't answering.";let Dm=null;const _m=new Set;function Sc(e){if(e!==(Dm===null)){Dm=e?null:Date.now();for(const t of _m)t()}}function B2(){return Dm}function W2(e){return _m.add(e),()=>_m.delete(e)}function H2(e){return e instanceof pe&&(e.status===0||e.status===502||e.status===503)&&e.message===Gu}async function Ki(e,t={}){var l;let s;try{s=await fetch(e,{...t,credentials:"same-origin",redirect:"error",headers:{Accept:"application/json",...t.headers??{}}})}catch(o){throw(o==null?void 0:o.name)==="AbortError"||(l=t.signal)!=null&&l.aborted?o:(Sc(!1),new pe(0,Gu,o))}if(s.status===401)throw Sc(!0),new pe(401,"This session has expired. Run `buddi dashboard` for a fresh link.");const r=await s.text(),i=r===""?null:K2(r),a=i&&typeof i=="object"&&"error"in i?String(i.error):void 0;if((s.status===502||s.status===503)&&a===void 0)throw Sc(!1),new pe(s.status,Gu,i);if(Sc(!0),!s.ok){const o=(t.method??"GET").toUpperCase(),c=a??(s.status===403&&o!=="GET"&&o!=="HEAD"?U2:`request failed (${s.status})`);throw new pe(s.status,c,i)}return i}function K2(e){try{return JSON.parse(e)}catch{return null}}function he(e,t={}){const s=new URLSearchParams;for(const[i,a]of Object.entries(t))a!==void 0&&a!==""&&s.set(i,String(a));const r=s.toString();return Ki(`/api${e}${r?`?${r}`:""}`)}function WS(e,t){return Ki(`/api${e}`,{method:"POST",headers:{[rl]:Hi()},body:t})}function wa(e){return Ki(`/api${e}`,{method:"DELETE",headers:{[rl]:Hi()}})}function ne(e,t={}){return Ki(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/json",[rl]:Hi()},body:JSON.stringify(t??{})})}function HS(e,t,s,r={}){const i=t.name.replace(/[^\w.-]+/g,"_").slice(-120)||s;return Ki(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/octet-stream",[rl]:Hi(),"X-Filename":i,...r},body:t})}function Aw(e,t,s){return HS(e,t,"backup.tar.gz",{...s.passphrase?{"X-Backup-Passphrase":s.passphrase}:{},...s.confirm?{"X-Backup-Confirm":s.confirm}:{}})}function V2(e,t={}){return Ki(`/api${e}`,{method:"PATCH",headers:{"Content-Type":"application/json",[rl]:Hi()},body:JSON.stringify(t??{})})}function gi(e,t={}){return Ki(`/api${e}`,{method:"PUT",headers:{"Content-Type":"application/json",[rl]:Hi()},body:JSON.stringify(t??{})})}function G2(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 cu="gpt-oss:120b",Y2=["approval","question","watcher","reminder","failure","recap","plugin"],Lm=["mon","tue","wed","thu","fri","sat","sun"],Le={agents:()=>he("/chat/agents"),views:()=>he("/chat/views"),conversations:(e,t)=>he(`/chat/${encodeURIComponent(e)}/conversations`,{limit:t}),startConversation:e=>ne(`/chat/${encodeURIComponent(e)}/conversations`),conversation:e=>he(`/chat/conversations/${encodeURIComponent(e)}`),send:(e,t)=>ne(`/chat/${encodeURIComponent(e)}/messages`,t),answerQuestion:(e,t)=>ne(`/chat/questions/${encodeURIComponent(e)}/answer`,t),cancel:e=>ne(`/chat/conversations/${encodeURIComponent(e)}/cancel`),attach:e=>{const t=new FormData;return t.append("file",e,e.name),WS("/chat/attachments",t)},transcribe:e=>ne("/speech/transcribe",e),say:e=>ne("/speech/say",e),discardAttachment:e=>wa(`/artifacts/${encodeURIComponent(e)}`),groups:()=>he("/groups"),group:e=>he(`/groups/${encodeURIComponent(e)}`),createGroup:e=>ne("/groups",e),updateGroup:(e,t)=>V2(`/groups/${encodeURIComponent(e)}`,t),archiveGroup:e=>wa(`/groups/${encodeURIComponent(e)}`),groupConversations:e=>he(`/groups/${encodeURIComponent(e)}/conversations`),startGroupConversation:e=>ne(`/groups/${encodeURIComponent(e)}/conversations`),sendToGroup:(e,t)=>ne(`/groups/${encodeURIComponent(e)}/messages`,t),streamUrl:e=>`/api/chat/conversations/${encodeURIComponent(e)}/stream`};function nx(e){return e.httpStatus===401||e.httpStatus===403||e.state==="authentication-error"||e.state==="access-denied"}const T={providers:()=>he("/providers"),providerAccounts:()=>he("/provider-accounts"),probeModels:e=>ne("/provider-accounts/probe-models",e),accountModels:(e,t=!1)=>ne(`/provider-accounts/${encodeURIComponent(e)}/models`,{refresh:t}),saveProviderAccount:e=>ne("/provider-accounts/save",e),testProviderAccount:e=>ne(`/provider-accounts/${encodeURIComponent(e)}/test`),removeProviderAccount:(e,t)=>ne(`/provider-accounts/${encodeURIComponent(e)}/remove`,{revision:t}),codexAccountAction:(e,t,s)=>ne(`/provider-accounts/${encodeURIComponent(e)}/${t}`,{revision:s}),ollamaConnect:(e,t)=>ne(`/provider-accounts/${encodeURIComponent(e)}/ollama/connect`,{revision:t}),ollamaPoll:(e,t)=>ne(`/provider-accounts/${encodeURIComponent(e)}/ollama/poll`,{attemptId:t}),ollamaDisconnect:(e,t)=>ne(`/provider-accounts/${encodeURIComponent(e)}/ollama/disconnect`,{revision:t}),anthropicAccountAction:(e,t,s,r)=>ne(`/provider-accounts/${encodeURIComponent(e)}/anthropic/${t}`,{revision:s,...r}),assignProviderAccount:(e,t,s)=>ne(`/agents/${encodeURIComponent(e)}/account`,{accountId:t,model:s}),configureProvider:(e,t)=>ne(`/providers/${encodeURIComponent(e)}/settings`,t),saveCredential:(e,t)=>ne(`/providers/credentials/${encodeURIComponent(e)}/save`,{value:t}),removeCredential:e=>ne(`/providers/credentials/${encodeURIComponent(e)}/remove`),testProvider:e=>ne(`/providers/${encodeURIComponent(e)}/test`),browserProfiles:e=>he("/host/browser-profiles",{app:e}),installedApps:()=>he("/host/apps"),browser:e=>he(`/browser${e?`?agentId=${encodeURIComponent(e.agentId)}&conversationId=${encodeURIComponent(e.conversationId)}`:""}`),browserControl:(e,t)=>ne(`/browser/${e}`,t===void 0?{}:{sessionId:t}),browserSettings:e=>ne("/browser/settings",e),computerPermissions:(e=!1)=>ne("/browser/permissions",{prompt:e}),browserInstall:()=>ne("/browser/install",{}),browserCheck:()=>ne("/browser/check",{}),previewLink:(e,t)=>he(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(t)}/link`),previewCheck:(e,t)=>he(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(t)}/check`),extension:()=>he("/extension"),pairExtension:e=>ne("/extension/pair",{code:e}),forgetExtension:()=>wa("/extension/pair"),session:()=>he("/session"),overview:()=>he("/overview"),events:e=>he("/events",e),eventKinds:()=>he("/events/kinds"),conversations:()=>he("/conversations"),conversation:e=>he(`/conversations/${encodeURIComponent(e)}`),missions:()=>he("/missions"),jobs:(e={})=>he("/jobs",e),approvals:()=>he("/approvals"),approval:e=>he(`/approvals/${encodeURIComponent(e)}`).then(t=>t.action),offers:()=>he("/offers"),dismissOffer:e=>ne(`/offers/${encodeURIComponent(e)}/dismiss`,{}),dismissOffers:e=>ne("/offers/dismiss-all",{ids:e}),agentOffers:()=>he("/agent-offers"),teammates:()=>he("/teammates"),dismissAgentOffer:(e,t)=>ne(`/agent-offers/${encodeURIComponent(e)}/${encodeURIComponent(t)}/dismiss`,{}),proposals:()=>he("/proposals"),setDigestSchedule:(e,t)=>ne("/proposals/digest-schedule",{day:e,hour:t}),keepProposal:(e,t)=>ne(`/proposals/${encodeURIComponent(e)}/keep`,t===void 0?{}:{text:t}),discardProposal:(e,t)=>ne(`/proposals/${encodeURIComponent(e)}/discard`,t?{reason:t}:{}),reminders:()=>he("/reminders"),sentinels:()=>he("/sentinels"),setSentinelEnabled:(e,t)=>ne(`/sentinels/${encodeURIComponent(e)}/enabled`,{enabled:t}),setGlanceHidden:(e,t)=>ne(`/home/glances/${encodeURIComponent(e)}/hidden`,{hidden:t}),rail:()=>he("/rail"),setRailHidden:(e,t,s)=>ne(`/rail/pages/${encodeURIComponent(e)}/${encodeURIComponent(t)}/hidden`,{hidden:s}),snoozeAlert:(e,t)=>ne(`/alerts/${encodeURIComponent(e)}/snooze`,{snoozed:t}),agents:()=>he("/agents"),library:e=>he("/artifacts",e),libraryEntry:(e,t=0)=>he(`/artifacts/${encodeURIComponent(e)}`,t?{contexts:t}:{}),onboarding:()=>he("/onboarding"),onboardingStep:(e,t={})=>ne("/onboarding/step",{step:e,...t}),takeOn:e=>ne("/onboarding/take-on",{tiles:e}),takeOnProgress:()=>he("/onboarding/take-on"),completeOnboarding:()=>ne("/onboarding/complete"),skipOnboarding:()=>ne("/onboarding/skip"),createFirstAgent:e=>ne("/onboarding/agent",e),ollama:()=>he("/onboarding/ollama"),mlxh:()=>he("/onboarding/mlxh"),firstAgentPersona:()=>he("/onboarding/agent"),updateFirstAgent:e=>ne("/onboarding/agent/update",e),bindBrain:e=>ne("/onboarding/brain",e),pages:()=>he("/pages"),pageQuery:(e,t,s={})=>he(`/pages/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,s),pageFileUrl:(e,t,s={})=>{const r=new URLSearchParams(Object.entries(s).filter(([,i])=>i!=="")).toString();return`/api/pages/${encodeURIComponent(e)}/${encodeURIComponent(t)}${r?`?${r}`:""}`},pageAct:(e,t)=>ne(`/pages/${encodeURIComponent(e)}/act`,t),telegram:()=>he("/telegram"),saveTelegramToken:e=>ne("/telegram/token",{token:e}),telegramPairing:()=>ne("/telegram/pairing"),telegramBot:()=>he("/telegram/bot"),telegramDevices:()=>he("/telegram/devices"),unpairTelegramDevice:e=>wa(`/telegram/devices/${encodeURIComponent(e)}`),notifications:(e=20)=>he("/notifications",{limit:e}),notificationSeen:e=>ne(`/notifications/${encodeURIComponent(e)}/seen`),notificationSettings:()=>he("/notifications/settings"),saveNotificationSettings:e=>gi("/notifications/settings",e),focus:()=>he("/notifications/focus"),setFocus:(e,t)=>gi("/notifications/focus",t?{mode:e,duration:t}:{mode:e}),testChannel:e=>ne("/notifications/test",{channel:e}),currentTip:e=>he(e?`/tips/current?preview=${encodeURIComponent(e)}`:"/tips/current"),tips:()=>he("/tips"),restoreTip:e=>ne(`/tips/${encodeURIComponent(e)}/restore`),dismissTip:e=>ne(`/tips/${encodeURIComponent(e)}/dismiss`),laterTip:e=>ne(`/tips/${encodeURIComponent(e)}/later`),tipsSeenPage:e=>ne("/tips/seen-page",{page:e}),tipsSettings:()=>he("/tips/settings"),saveTipsSettings:e=>gi("/tips/settings",{enabled:e}),presence:e=>ne("/presence",{state:e}),owner:()=>he("/owner"),setOwner:e=>ne("/owner",e),memory:e=>he(e?`/memory?agent=${encodeURIComponent(e)}`:"/memory"),setPreference:e=>ne("/memory/preferences",e),forgetPreference:e=>ne("/memory/preferences/forget",e),updateNote:(e,t)=>ne(`/memory/notes/${encodeURIComponent(e)}`,t),forgetNote:e=>ne(`/memory/notes/${encodeURIComponent(e)}/forget`),setDelegates:(e,t)=>ne(`/agents/${encodeURIComponent(e)}/delegates`,{delegates:t}),agentProfile:e=>he(`/agents/${encodeURIComponent(e)}/profile`),agentSkills:e=>he(`/agents/${encodeURIComponent(e)}/skills`),removeSkill:(e,t)=>ne(`/agents/${encodeURIComponent(e)}/skills/${encodeURIComponent(t)}/remove`,{}),host:(e,t)=>he("/host",{agentId:e,conversationId:t}),connections:()=>he("/connections"),connection:e=>he(`/connections/${e}`),addConnection:(e,t)=>ne("/connections",{url:e,...t?{name:t}:{}}),addProgram:e=>ne("/connections",{transport:"stdio",...e}),updateProgram:(e,t)=>ne(`/connections/${e}/program`,t),connectionConsent:(e,t)=>ne(`/connections/${e}/consent`,t?{clientId:t}:{}),connectionToken:(e,t)=>ne(`/connections/${e}/token`,t),connectionDevice:e=>ne(`/connections/${e}/device`,{}),connectionCallback:e=>ne("/connections/callback",e),connectionReview:e=>he(`/connections/${e}/review`),saveConnectionReview:(e,t)=>ne(`/connections/${e}/review`,t),grantConnection:(e,t,s=!1)=>ne(`/connections/${e}/grant`,s?{agents:t,exact:!0}:{agents:t}),disconnect:e=>wa(`/connections/${e}`),connectionSignals:()=>he("/connections/signals"),connectionTools:e=>he(`/connections/${e}/tools`),rememberedApprovals:e=>he(`/connections/remembered/${encodeURIComponent(e)}`),setRememberedApproval:(e,t,s)=>ne("/connections/remembered",{agent:e,tool:t,remember:s}),secrets:()=>he("/secrets"),secretUses:(e,t)=>he("/secrets/uses",{name:e,limit:t}),secretsAct:(e,t)=>ne("/secrets/act",{tool:e,args:t}),stopHost:(e,t)=>ne("/host/stop",{agentId:e,conversationId:t}),revokeHost:e=>ne("/host/revoke",{id:e}),decide:(e,t,s,r)=>ne(`/approvals/${encodeURIComponent(e)}/${t}`,s||r?{...s?{permissionScope:s}:{},...r?{ownerChoices:r}:{}}:void 0),setPaused:e=>ne("/pause",{paused:e}),service:()=>he("/service"),serviceAction:e=>ne(`/service/${e}`),version:()=>he("/version"),checkVersion:()=>ne("/version/check"),setVersionCheck:e=>gi("/version/check",{enabled:e}),tailscale:()=>he("/tailscale"),setTailscale:e=>gi("/tailscale",e),startUpgrade:e=>ne("/upgrade",e===void 0?{}:{version:e}),upgradeJob:e=>he(`/upgrade/jobs/${encodeURIComponent(e)}`),backups:()=>he("/backups"),startBackup:e=>ne("/backups",{encrypt:e}),verifyArchive:e=>ne("/backups/verify",{name:e}),restoreArchive:e=>ne("/backups/restore",e),restoreUpload:(e,t)=>Aw("/backups/restore",e,t),backupJob:e=>he(`/backups/jobs/${encodeURIComponent(e)}`),backupSchedule:()=>he("/backups/schedule"),setBackupSchedule:e=>gi("/backups/schedule",e),backupPassphrase:()=>he("/backups/passphrase"),setBackupPassphrase:e=>gi("/backups/passphrase",{passphrase:e}),plugins:()=>he("/plugins"),market:(e=!1)=>he(`/market${e?"?refresh=1":""}`),marketAssetUrl:e=>`/api/market/asset?url=${encodeURIComponent(e)}`,pluginFolders:e=>he("/plugins/folders",e?{path:e}:{}),stagePlugin:e=>ne("/plugins/stage",{spec:e}),uploadPlugin:e=>HS("/plugins/upload",e,"plugin.tgz"),pluginJob:e=>he(`/plugins/jobs/${encodeURIComponent(e)}`),approveStaged:(e,t)=>ne(`/plugins/staged/${encodeURIComponent(e)}/approve`,t),rejectStaged:e=>ne(`/plugins/staged/${encodeURIComponent(e)}/reject`),updatePlugin:(e,t,s)=>ne(`/plugins/${encodeURIComponent(e)}/update`,{...t?{version:t}:{},...s?{from:s}:{}}),setPluginEnabled:(e,t)=>ne(`/plugins/${encodeURIComponent(e)}/${t?"enable":"disable"}`,{}),uninstallPlugin:(e,t)=>ne(`/plugins/${encodeURIComponent(e)}/uninstall`,t),acceptPluginAgent:(e,t)=>ne(`/plugins/${encodeURIComponent(e)}/agents/${encodeURIComponent(t)}/accept`),recovery:()=>he("/recovery"),leaveRecovery:e=>ne("/recovery/leave",e),firstRunRestore:(e,t)=>Aw("/onboarding/restore",e,{passphrase:t}),setMissionEnabled:(e,t)=>ne(`/missions/${encodeURIComponent(e)}/enabled`,{enabled:t}),setMisfirePolicy:(e,t,s)=>ne(`/missions/${encodeURIComponent(e)}/schedule`,{misfirePolicy:t,...s===void 0?{}:{deadlineMinutes:s}}),retryJob:e=>ne(`/jobs/${encodeURIComponent(e)}/retry`),cancelJob:e=>ne(`/jobs/${encodeURIComponent(e)}/cancel`),setDefaultAgent:e=>ne("/agents/default",{agentId:e}),agentTools:e=>he(`/agents/${encodeURIComponent(e)}/tools`),agentFile:e=>he(`/agents/${encodeURIComponent(e)}/file`),uploadAgentPicture:(e,t)=>{const s=new FormData;return s.append("file",t,t.name),WS(`/agents/${encodeURIComponent(e)}/avatar`,s)},removeAgentPicture:e=>wa(`/agents/${encodeURIComponent(e)}/avatar`),updateAgentFile:(e,t)=>ne(`/agents/${encodeURIComponent(e)}/file`,t),setAgentEngine:(e,t)=>ne(`/agents/${encodeURIComponent(e)}/engine`,t),takeOffer:(e,t)=>ne(`/offers/${encodeURIComponent(e)}/take`,t?{conversationId:t}:{}),cancelReminder:e=>ne(`/reminders/${encodeURIComponent(e)}/cancel`,{reason:"cancelled from the dashboard"})};function KS(e){return e==="anthropic"||e==="openai"}function VS(e,t){var i,a;if(!e)return null;const s=e.credentialEnv&&(t!=null&&t.accounts.some(l=>l.id===e.credentialEnv))?e.credentialEnv:(a=(i=t==null?void 0:t.bindings)==null?void 0:i.find(l=>l.agentId===e.id))==null?void 0:a.accountId,r=s?t==null?void 0:t.accounts.find(l=>l.id===s):void 0;return(r==null?void 0:r.kind)??e.provider}const q2="Thinking is up to this model. What it writes while thinking is shown apart and kept out of the answer.";var Q2=Object.defineProperty,J2=(e,t)=>Q2(e,"name",{value:t,configurable:!0}),X2=f.createContext(void 0);function Ld(e){const t=f.useContext(X2);return e||t||"ltr"}J2(Ld,"useDirection");var Z2=Object.defineProperty,sx=(e,t)=>Z2(e,"name",{value:t,configurable:!0}),Nc=0,$s=null;function e$(e){return Fd(),e.children}sx(e$,"FocusGuards");function Fd(){f.useEffect(()=>{$s||($s={start:Fm(),end:Fm()});const{start:e,end:t}=$s;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),Nc++,()=>{Nc===1&&($s==null||$s.start.remove(),$s==null||$s.end.remove(),$s=null),Nc=Math.max(0,Nc-1)}},[])}sx(Fd,"useFocusGuards");function Fm(){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}sx(Fm,"createFocusGuard");var t$=Object.defineProperty,xn=(e,t)=>t$(e,"name",{value:t,configurable:!0}),Wh="focusScope.autoFocusOnMount",Hh="focusScope.autoFocusOnUnmount",Tw={bubbles:!1,cancelable:!0},GS=f.forwardRef(xn(function(t,s){const{loop:r=!1,trapped:i=!1,onMountAutoFocus:a,onUnmountAutoFocus:l,...o}=t,[c,u]=f.useState(null),h=us(a),d=us(l),m=f.useRef(null),p=ct(s,u),x=f.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;f.useEffect(()=>{if(i){let b=function(y){if(x.paused||!c)return;const N=y.target;c.contains(N)?m.current=N:Zs(m.current,{select:!0})},g=function(y){if(x.paused||!c)return;const N=y.relatedTarget;N!==null&&(c.contains(N)||Zs(m.current,{select:!0}))},v=function(y){if(document.activeElement===document.body)for(const k of y)k.removedNodes.length>0&&Zs(c)};xn(b,"handleFocusIn"),xn(g,"handleFocusOut"),xn(v,"handleMutations"),document.addEventListener("focusin",b),document.addEventListener("focusout",g);const w=new MutationObserver(v);return c&&w.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",b),document.removeEventListener("focusout",g),w.disconnect()}}},[i,c,x.paused]),f.useEffect(()=>{if(c){Rw.add(x);const b=document.activeElement;if(!c.contains(b)){const v=new CustomEvent(Wh,Tw);c.addEventListener(Wh,h),c.dispatchEvent(v),v.defaultPrevented||(YS(ZS(rx(c)),{select:!0}),document.activeElement===b&&Zs(c))}return()=>{c.removeEventListener(Wh,h),setTimeout(()=>{const v=new CustomEvent(Hh,Tw);c.addEventListener(Hh,d),c.dispatchEvent(v),v.defaultPrevented||Zs(b??document.body,{select:!0}),c.removeEventListener(Hh,d),Rw.remove(x)},0)}}},[c,h,d,x]);const j=f.useCallback(b=>{if(!r&&!i||x.paused)return;const g=b.key==="Tab"&&!b.altKey&&!b.ctrlKey&&!b.metaKey,v=document.activeElement;if(g&&v){const w=b.currentTarget,[y,N]=qS(w);y&&N?!b.shiftKey&&v===N?(b.preventDefault(),r&&Zs(y,{select:!0})):b.shiftKey&&v===y&&(b.preventDefault(),r&&Zs(N,{select:!0})):v===w&&b.preventDefault()}},[r,i,x.paused]);return n.jsx(jt.div,{tabIndex:-1,...o,ref:p,onKeyDown:j})},"FocusScope"));function YS(e,{select:t=!1}={}){const s=document.activeElement;for(const r of e)if(Zs(r,{select:t}),document.activeElement!==s)return}xn(YS,"focusFirst");function qS(e){const t=rx(e),s=zm(t,e),r=zm(t.reverse(),e);return[s,r]}xn(qS,"getTabbableEdges");function rx(e){const t=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:xn(r=>{const i=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||i?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;s.nextNode();)t.push(s.currentNode);return t}xn(rx,"getTabbableCandidates");function zm(e,t){const s=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(s?!r.checkVisibility({checkVisibilityCSS:!0}):QS(r,{upTo:t})))return r}xn(zm,"findVisible");function QS(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}xn(QS,"isHidden");function JS(e){return e instanceof HTMLInputElement&&"select"in e}xn(JS,"isSelectableInput");function Zs(e,{select:t=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&JS(e)&&t&&e.select()}}xn(Zs,"focus");var Rw=XS();function XS(){let e=[];return{add(t){const s=e[0];t!==s&&(s==null||s.pause()),e=Um(e,t),e.unshift(t)},remove(t){var s;e=Um(e,t),(s=e[0])==null||s.resume()}}}xn(XS,"createFocusScopesStack");function Um(e,t){const s=[...e],r=s.indexOf(t);return r!==-1&&s.splice(r,1),s}xn(Um,"arrayRemove");function ZS(e){return e.filter(t=>t.tagName!=="A")}xn(ZS,"removeLinks");var n$=Object.defineProperty,ix=(e,t)=>n$(e,"name",{value:t,configurable:!0}),Kh=!1;function eN(){const[e,t]=f.useState(Kh);return f.useEffect(()=>{Kh||(Kh=!0,t(!0))},[]),e}ix(eN,"useIsHydrated");var tN=Xa[" useSyncExternalStore ".trim().toString()];function nN(){return()=>{}}ix(nN,"subscribe");function sN(){return tN(nN,()=>!0,()=>!1)}ix(sN,"useIsHydratedModern");var s$=typeof tN=="function"?sN:eN,r$=Object.defineProperty,Vi=(e,t)=>r$(e,"name",{value:t,configurable:!0}),Vh="rovingFocusGroup.onEntryFocus",i$={bubbles:!1,cancelable:!0},zd="RovingFocusGroup",[Bm,rN,a$]=Td(zd),[l$,Ud]=Ns(zd,[a$]),[o$,c$]=l$(zd),u$=f.forwardRef(Vi(function(t,s){return n.jsx(Bm.Provider,{scope:t.__scopeRovingFocusGroup,children:n.jsx(Bm.Slot,{scope:t.__scopeRovingFocusGroup,children:n.jsx(d$,{...t,ref:s})})})},"RovingFocusGroup")),d$=f.forwardRef(Vi(function(t,s){const{__scopeRovingFocusGroup:r,orientation:i,loop:a=!1,dir:l,currentTabStopId:o,defaultCurrentTabStopId:c,onCurrentTabStopIdChange:u,onEntryFocus:h,preventScrollOnEntryFocus:d=!1,...m}=t,p=f.useRef(null),x=ct(s,p),j=Ld(l),[b,g]=Wi({prop:o,defaultProp:c??null,onChange:u,caller:zd}),[v,w]=f.useState(!1),y=us(h),N=rN(r),k=f.useRef(!1),[S,C]=f.useState(0);return f.useEffect(()=>{const I=p.current;if(I)return I.addEventListener(Vh,y),()=>I.removeEventListener(Vh,y)},[y]),n.jsx(o$,{scope:r,orientation:i,dir:j,loop:a,currentTabStopId:b,onItemFocus:f.useCallback(I=>g(I),[g]),onItemShiftTab:f.useCallback(()=>w(!0),[]),onFocusableItemAdd:f.useCallback(()=>C(I=>I+1),[]),onFocusableItemRemove:f.useCallback(()=>C(I=>I-1),[]),children:n.jsx(jt.div,{tabIndex:v||S===0?-1:0,"data-orientation":i,...m,ref:x,style:{outline:"none",...t.style},onMouseDown:Ie(t.onMouseDown,()=>{k.current=!0}),onFocus:Ie(t.onFocus,I=>{const A=!k.current;if(I.target===I.currentTarget&&A&&!v){const O=new CustomEvent(Vh,i$);if(I.currentTarget.dispatchEvent(O),!O.defaultPrevented){const z=N().filter(B=>B.focusable),L=z.find(B=>B.active),E=z.find(B=>B.id===b),_=[L,E,...z].filter(Boolean).map(B=>B.ref.current);ax(_,d)}}k.current=!1}),onBlur:Ie(t.onBlur,()=>w(!1))})})},"RovingFocusGroupImpl")),h$="RovingFocusGroupItem",f$=f.forwardRef(Vi(function(t,s){const{__scopeRovingFocusGroup:r,focusable:i=!0,active:a=!1,tabStopId:l,children:o,...c}=t,u=vs(),h=l||u,d=c$(h$,r),m=d.currentTabStopId===h,p=rN(r),{onFocusableItemAdd:x,onFocusableItemRemove:j,currentTabStopId:b}=d,g=s$();return Tn(()=>{if(!(!g||!i))return x(),()=>j()},[g,i,x,j]),f.useEffect(()=>{if(!(g||!i))return x(),()=>j()},[g,i,x,j]),n.jsx(Bm.ItemSlot,{scope:r,id:h,focusable:i,active:a,children:n.jsx(jt.span,{tabIndex:m?0:-1,"data-orientation":d.orientation,...c,ref:s,onMouseDown:Ie(t.onMouseDown,v=>{i?d.onItemFocus(h):v.preventDefault()}),onFocus:Ie(t.onFocus,()=>d.onItemFocus(h)),onKeyDown:Ie(t.onKeyDown,v=>{if(v.key==="Tab"&&v.shiftKey){d.onItemShiftTab();return}if(v.target!==v.currentTarget)return;const w=aN(v,d.orientation,d.dir);if(w!==void 0){if(v.metaKey||v.ctrlKey||v.altKey||v.shiftKey)return;v.preventDefault();let N=p().filter(k=>k.focusable).map(k=>k.ref.current);if(w==="last")N.reverse();else if(w==="prev"||w==="next"){w==="prev"&&N.reverse();const k=N.indexOf(v.currentTarget);N=d.loop?lN(N,k+1):N.slice(k+1)}setTimeout(()=>ax(N))}}),children:typeof o=="function"?o({isCurrentTabStop:m,hasTabStop:b!=null}):o})})},"RovingFocusGroupItem")),m$={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function iN(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}Vi(iN,"getDirectionAwareKey");function aN(e,t,s){const r=iN(e.key,s);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return m$[r]}Vi(aN,"getFocusIntent");function ax(e,t=!1){const s=document.activeElement;for(const r of e)if(r===s||(r.focus({preventScroll:t}),document.activeElement!==s))return}Vi(ax,"focusFirst");function lN(e,t){return e.map((s,r)=>e[(t+r)%e.length])}Vi(lN,"wrapArray");var oN=u$,cN=f$,p$=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},ea=new WeakMap,Cc=new WeakMap,Ec={},Gh=0,uN=function(e){return e&&(e.host||uN(e.parentNode))},g$=function(e,t){return t.map(function(s){if(e.contains(s))return s;var r=uN(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})},x$=function(e,t,s,r){var i=g$(t,Array.isArray(e)?e:[e]);Ec[s]||(Ec[s]=new WeakMap);var a=Ec[s],l=[],o=new Set,c=new Set(i),u=function(d){!d||o.has(d)||(o.add(d),u(d.parentNode))};i.forEach(u);var h=function(d){!d||c.has(d)||Array.prototype.forEach.call(d.children,function(m){if(o.has(m))h(m);else try{var p=m.getAttribute(r),x=p!==null&&p!=="false",j=(ea.get(m)||0)+1,b=(a.get(m)||0)+1;ea.set(m,j),a.set(m,b),l.push(m),j===1&&x&&Cc.set(m,!0),b===1&&m.setAttribute(s,"true"),x||m.setAttribute(r,"true")}catch(g){console.error("aria-hidden: cannot operate on ",m,g)}})};return h(t),o.clear(),Gh++,function(){l.forEach(function(d){var m=ea.get(d)-1,p=a.get(d)-1;ea.set(d,m),a.set(d,p),m||(Cc.has(d)||d.removeAttribute(r),Cc.delete(d)),p||d.removeAttribute(s)}),Gh--,Gh||(ea=new WeakMap,ea=new WeakMap,Cc=new WeakMap,Ec={})}},dN=function(e,t,s){s===void 0&&(s="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),i=p$(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll("[aria-live], script"))),x$(r,i,s,"aria-hidden")):function(){return null}},_s=function(){return _s=Object.assign||function(t){for(var s,r=1,i=arguments.length;r<i;r++){s=arguments[r];for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(t[a]=s[a])}return t},_s.apply(this,arguments)};function hN(e,t){var s={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(s[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(s[r[i]]=e[r[i]]);return s}function v$(e,t,s){if(s||arguments.length===2)for(var r=0,i=t.length,a;r<i;r++)(a||!(r in t))&&(a||(a=Array.prototype.slice.call(t,0,r)),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))}var uu="right-scroll-bar-position",du="width-before-scroll-bar",j$="with-scroll-bars-hidden",w$="--removed-body-scroll-bar-size";function Yh(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function y$(e,t){var s=f.useState(function(){return{value:e,callback:t,facade:{get current(){return s.value},set current(r){var i=s.value;i!==r&&(s.value=r,s.callback(r,i))}}}})[0];return s.callback=t,s.facade}var b$=typeof window<"u"?f.useLayoutEffect:f.useEffect,Iw=new WeakMap;function k$(e,t){var s=y$(null,function(r){return e.forEach(function(i){return Yh(i,r)})});return b$(function(){var r=Iw.get(s);if(r){var i=new Set(r),a=new Set(e),l=s.current;i.forEach(function(o){a.has(o)||Yh(o,null)}),a.forEach(function(o){i.has(o)||Yh(o,l)})}Iw.set(s,e)},[e]),s}function S$(e){return e}function N$(e,t){t===void 0&&(t=S$);var s=[],r=!1,i={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return s.length?s[s.length-1]:e},useMedium:function(a){var l=t(a,r);return s.push(l),function(){s=s.filter(function(o){return o!==l})}},assignSyncMedium:function(a){for(r=!0;s.length;){var l=s;s=[],l.forEach(a)}s={push:function(o){return a(o)},filter:function(){return s}}},assignMedium:function(a){r=!0;var l=[];if(s.length){var o=s;s=[],o.forEach(a),l=s}var c=function(){var h=l;l=[],h.forEach(a)},u=function(){return Promise.resolve().then(c)};u(),s={push:function(h){l.push(h),u()},filter:function(h){return l=l.filter(h),s}}}};return i}function C$(e){e===void 0&&(e={});var t=N$(null);return t.options=_s({async:!0,ssr:!1},e),t}var fN=function(e){var t=e.sideCar,s=hN(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return f.createElement(r,_s({},s))};fN.isSideCarExport=!0;function E$(e,t){return e.useMedium(t),fN}var mN=C$(),qh=function(){},Bd=f.forwardRef(function(e,t){var s=f.useRef(null),r=f.useState({onScrollCapture:qh,onWheelCapture:qh,onTouchMoveCapture:qh}),i=r[0],a=r[1],l=e.forwardProps,o=e.children,c=e.className,u=e.removeScrollBar,h=e.enabled,d=e.shards,m=e.sideCar,p=e.noRelative,x=e.noIsolation,j=e.inert,b=e.allowPinchZoom,g=e.as,v=g===void 0?"div":g,w=e.gapMode,y=hN(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),N=m,k=k$([s,t]),S=_s(_s({},y),i);return f.createElement(f.Fragment,null,h&&f.createElement(N,{sideCar:mN,removeScrollBar:u,shards:d,noRelative:p,noIsolation:x,inert:j,setCallbacks:a,allowPinchZoom:!!b,lockRef:s,gapMode:w}),l?f.cloneElement(f.Children.only(o),_s(_s({},S),{ref:k})):f.createElement(v,_s({},S,{className:c,ref:k}),o))});Bd.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};Bd.classNames={fullWidth:du,zeroRight:uu};var A$=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function T$(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=A$();return t&&e.setAttribute("nonce",t),e}function R$(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function I$(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var P$=function(){var e=0,t=null;return{add:function(s){e==0&&(t=T$())&&(R$(t,s),I$(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},$$=function(){var e=P$();return function(t,s){f.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&s])}},pN=function(){var e=$$(),t=function(s){var r=s.styles,i=s.dynamic;return e(r,i),null};return t},M$={left:0,top:0,right:0,gap:0},Qh=function(e){return parseInt(e||"",10)||0},O$=function(e){var t=window.getComputedStyle(document.body),s=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],i=t[e==="padding"?"paddingRight":"marginRight"];return[Qh(s),Qh(r),Qh(i)]},D$=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return M$;var t=O$(e),s=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-s+t[2]-t[0])}},_$=pN(),Ta="data-scroll-locked",L$=function(e,t,s,r){var i=e.left,a=e.top,l=e.right,o=e.gap;return s===void 0&&(s="margin"),`
41
- .`.concat(j$,` {
42
- overflow: hidden `).concat(r,`;
43
- padding-right: `).concat(o,"px ").concat(r,`;
44
- }
45
- body[`).concat(Ta,`] {
46
- overflow: hidden `).concat(r,`;
47
- overscroll-behavior: contain;
48
- `).concat([t&&"position: relative ".concat(r,";"),s==="margin"&&`
49
- padding-left: `.concat(i,`px;
50
- padding-top: `).concat(a,`px;
51
- padding-right: `).concat(l,`px;
52
- margin-left:0;
53
- margin-top:0;
54
- margin-right: `).concat(o,"px ").concat(r,`;
55
- `),s==="padding"&&"padding-right: ".concat(o,"px ").concat(r,";")].filter(Boolean).join(""),`
56
- }
57
-
58
- .`).concat(uu,` {
59
- right: `).concat(o,"px ").concat(r,`;
60
- }
61
-
62
- .`).concat(du,` {
63
- margin-right: `).concat(o,"px ").concat(r,`;
64
- }
65
-
66
- .`).concat(uu," .").concat(uu,` {
67
- right: 0 `).concat(r,`;
68
- }
69
-
70
- .`).concat(du," .").concat(du,` {
71
- margin-right: 0 `).concat(r,`;
72
- }
73
-
74
- body[`).concat(Ta,`] {
75
- `).concat(w$,": ").concat(o,`px;
76
- }
77
- `)},Pw=function(){var e=parseInt(document.body.getAttribute(Ta)||"0",10);return isFinite(e)?e:0},F$=function(){f.useEffect(function(){return document.body.setAttribute(Ta,(Pw()+1).toString()),function(){var e=Pw()-1;e<=0?document.body.removeAttribute(Ta):document.body.setAttribute(Ta,e.toString())}},[])},z$=function(e){var t=e.noRelative,s=e.noImportant,r=e.gapMode,i=r===void 0?"margin":r;F$();var a=f.useMemo(function(){return D$(i)},[i]);return f.createElement(_$,{styles:L$(a,!t,i,s?"":"!important")})},Wm=!1;if(typeof window<"u")try{var Ac=Object.defineProperty({},"passive",{get:function(){return Wm=!0,!0}});window.addEventListener("test",Ac,Ac),window.removeEventListener("test",Ac,Ac)}catch{Wm=!1}var ta=Wm?{passive:!1}:!1,U$=function(e){return e.tagName==="TEXTAREA"},gN=function(e,t){if(!(e instanceof Element))return!1;var s=window.getComputedStyle(e);return s[t]!=="hidden"&&!(s.overflowY===s.overflowX&&!U$(e)&&s[t]==="visible")},B$=function(e){return gN(e,"overflowY")},W$=function(e){return gN(e,"overflowX")},$w=function(e,t){var s=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var i=xN(e,r);if(i){var a=vN(e,r),l=a[1],o=a[2];if(l>o)return!0}r=r.parentNode}while(r&&r!==s.body);return!1},H$=function(e){var t=e.scrollTop,s=e.scrollHeight,r=e.clientHeight;return[t,s,r]},K$=function(e){var t=e.scrollLeft,s=e.scrollWidth,r=e.clientWidth;return[t,s,r]},xN=function(e,t){return e==="v"?B$(t):W$(t)},vN=function(e,t){return e==="v"?H$(t):K$(t)},V$=function(e,t){return e==="h"&&t==="rtl"?-1:1},G$=function(e,t,s,r,i){var a=V$(e,window.getComputedStyle(t).direction),l=a*r,o=s.target,c=t.contains(o),u=!1,h=l>0,d=0,m=0;do{if(!o)break;var p=vN(e,o),x=p[0],j=p[1],b=p[2],g=j-b-a*x;(x||g)&&xN(e,o)&&(d+=g,m+=x);var v=o.parentNode;o=v&&v.nodeType===Node.DOCUMENT_FRAGMENT_NODE?v.host:v}while(!c&&o!==document.body||c&&(t.contains(o)||t===o));return(h&&Math.abs(d)<1||!h&&Math.abs(m)<1)&&(u=!0),u},Tc=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Mw=function(e){return[e.deltaX,e.deltaY]},Ow=function(e){return e&&"current"in e?e.current:e},Y$=function(e,t){return e[0]===t[0]&&e[1]===t[1]},q$=function(e){return`
78
- .block-interactivity-`.concat(e,` {pointer-events: none;}
79
- .allow-interactivity-`).concat(e,` {pointer-events: all;}
80
- `)},Q$=0,na=[];function J$(e){var t=f.useRef([]),s=f.useRef([0,0]),r=f.useRef(),i=f.useState(Q$++)[0],a=f.useState(pN)[0],l=f.useRef(e);f.useEffect(function(){l.current=e},[e]),f.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var j=v$([e.lockRef.current],(e.shards||[]).map(Ow),!0).filter(Boolean);return j.forEach(function(b){return b.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),j.forEach(function(b){return b.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var o=f.useCallback(function(j,b){if("touches"in j&&j.touches.length===2||j.type==="wheel"&&j.ctrlKey)return!l.current.allowPinchZoom;var g=Tc(j),v=s.current,w="deltaX"in j?j.deltaX:v[0]-g[0],y="deltaY"in j?j.deltaY:v[1]-g[1],N,k=j.target,S=Math.abs(w)>Math.abs(y)?"h":"v";if("touches"in j&&S==="h"&&k.type==="range")return!1;var C=window.getSelection(),I=C&&C.anchorNode,A=I?I===k||I.contains(k):!1;if(A)return!1;var O=$w(S,k);if(!O)return!0;if(O?N=S:(N=S==="v"?"h":"v",O=$w(S,k)),!O)return!1;if(!r.current&&"changedTouches"in j&&(w||y)&&(r.current=N),!N)return!0;var z=r.current||N;return G$(z,b,j,z==="h"?w:y)},[]),c=f.useCallback(function(j){var b=j;if(!(!na.length||na[na.length-1]!==a)){var g="deltaY"in b?Mw(b):Tc(b),v=t.current.filter(function(N){return N.name===b.type&&(N.target===b.target||b.target===N.shadowParent)&&Y$(N.delta,g)})[0];if(v&&v.should){b.cancelable&&b.preventDefault();return}if(!v){var w=(l.current.shards||[]).map(Ow).filter(Boolean).filter(function(N){return N.contains(b.target)}),y=w.length>0?o(b,w[0]):!l.current.noIsolation;y&&b.cancelable&&b.preventDefault()}}},[]),u=f.useCallback(function(j,b,g,v){var w={name:j,delta:b,target:g,should:v,shadowParent:X$(g)};t.current.push(w),setTimeout(function(){t.current=t.current.filter(function(y){return y!==w})},1)},[]),h=f.useCallback(function(j){s.current=Tc(j),r.current=void 0},[]),d=f.useCallback(function(j){u(j.type,Mw(j),j.target,o(j,e.lockRef.current))},[]),m=f.useCallback(function(j){u(j.type,Tc(j),j.target,o(j,e.lockRef.current))},[]);f.useEffect(function(){return na.push(a),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:m}),document.addEventListener("wheel",c,ta),document.addEventListener("touchmove",c,ta),document.addEventListener("touchstart",h,ta),function(){na=na.filter(function(j){return j!==a}),document.removeEventListener("wheel",c,ta),document.removeEventListener("touchmove",c,ta),document.removeEventListener("touchstart",h,ta)}},[]);var p=e.removeScrollBar,x=e.inert;return f.createElement(f.Fragment,null,x?f.createElement(a,{styles:q$(i)}):null,p?f.createElement(z$,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function X$(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Z$=E$(mN,J$);var lx=f.forwardRef(function(e,t){return f.createElement(Bd,_s({},e,{ref:t,sideCar:Z$}))});lx.classNames=Bd.classNames;var eM=Object.defineProperty,Ke=(e,t)=>eM(e,"name",{value:t,configurable:!0}),Hm=["Enter"," "],tM=["ArrowDown","PageUp","Home"],jN=["ArrowUp","PageDown","End"],nM=[...tM,...jN],sM={ltr:[...Hm,"ArrowRight"],rtl:[...Hm,"ArrowLeft"]},rM={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Wd="Menu",[So,iM,aM]=Td(Wd),[Gi,wN]=Ns(Wd,[aM,Dd,Ud]),Hd=Dd(),yN=Ud(),[bN,ci]=Gi(Wd),[lM,Bo]=Gi(Wd),oM=Ke(e=>{const{__scopeMenu:t,open:s=!1,children:r,dir:i,onOpenChange:a,modal:l=!0}=e,o=Hd(t),[c,u]=f.useState(null),h=f.useRef(!1),d=us(a),m=Ld(i);return f.useEffect(()=>{const p=Ke(()=>{h.current=!0,document.addEventListener("pointerdown",x,{capture:!0,once:!0}),document.addEventListener("pointermove",x,{capture:!0,once:!0})},"handleKeyDown"),x=Ke(()=>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})}},[]),f.useEffect(()=>{if(!s)return;const p=Ke(()=>d(!1),"handleBlur");return window.addEventListener("blur",p),()=>window.removeEventListener("blur",p)},[s,d]),n.jsx(Xg,{...o,children:n.jsx(bN,{scope:t,open:s,onOpenChange:d,content:c,onContentChange:u,children:n.jsx(lM,{scope:t,onClose:f.useCallback(()=>d(!1),[d]),isUsingKeyboardRef:h,dir:m,modal:l,children:r})})})},"Menu"),kN=f.forwardRef(Ke(function(t,s){const{__scopeMenu:r,...i}=t,a=Hd(r);return n.jsx($S,{...a,...i,ref:s})},"MenuAnchor")),SN="MenuPortal",[cM,NN]=Gi(SN,{forceMount:void 0}),uM=Ke(e=>{const{__scopeMenu:t,forceMount:s,children:r,container:i}=e,a=ci(SN,t);return n.jsx(cM,{scope:t,forceMount:s,children:n.jsx(xr,{present:s||a.open,children:n.jsx(Kg,{asChild:!0,container:i,children:r})})})},"MenuPortal"),js="MenuContent",[dM,ox]=Gi(js),hM=f.forwardRef(Ke(function(t,s){const r=NN(js,t.__scopeMenu),{forceMount:i=r.forceMount,...a}=t,l=ci(js,t.__scopeMenu),o=Bo(js,t.__scopeMenu);return n.jsx(So.Provider,{scope:t.__scopeMenu,children:n.jsx(xr,{present:i||l.open,children:n.jsx(So.Slot,{scope:t.__scopeMenu,children:o.modal?n.jsx(fM,{...a,ref:s}):n.jsx(mM,{...a,ref:s})})})})},"MenuContent")),fM=f.forwardRef(Ke(function(t,s){const r=ci(js,t.__scopeMenu),i=f.useRef(null),a=ct(s,i);return f.useEffect(()=>{const l=i.current;if(l)return dN(l)},[]),n.jsx(cx,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:r.open,disableOutsideScroll:!0,onFocusOutside:Ie(t.onFocusOutside,l=>l.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentModal")),mM=f.forwardRef(Ke(function(t,s){const r=ci(js,t.__scopeMenu);return n.jsx(cx,{...t,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentNonModal")),pM=Xr("MenuContent.ScrollLock"),cx=f.forwardRef(Ke(function(t,s){const{__scopeMenu:r,loop:i=!1,trapFocus:a,onOpenAutoFocus:l,onCloseAutoFocus:o,disableOutsidePointerEvents:c,onEntryFocus:u,onEscapeKeyDown:h,onPointerDownOutside:d,onFocusOutside:m,onInteractOutside:p,onDismiss:x,disableOutsideScroll:j,...b}=t,g=ci(js,r),v=Bo(js,r),w=Hd(r),y=yN(r),N=iM(r),[k,S]=f.useState(null),C=f.useRef(null),I=ct(s,C,g.onContentChange),A=f.useRef(0),O=f.useRef(""),z=f.useRef(0),L=f.useRef(null),E=f.useRef("right"),$=f.useRef(0),_=j?lx:f.Fragment,B=j?{as:pM,allowPinchZoom:!0}:void 0,M=Ke(D=>{var me,Pe;const U=O.current+D,V=N().filter(ke=>!ke.disabled),Z=document.activeElement,ue=(me=V.find(ke=>ke.ref.current===Z))==null?void 0:me.textValue,Ae=V.map(ke=>ke.textValue),X=ON(Ae,U,ue),ae=(Pe=V.find(ke=>ke.textValue===X))==null?void 0:Pe.ref.current;Ke(function ke(ye){O.current=ye,window.clearTimeout(A.current),ye!==""&&(A.current=window.setTimeout(()=>ke(""),1e3))},"updateSearch")(U),ae&&setTimeout(()=>ae.focus())},"handleTypeaheadSearch");f.useEffect(()=>()=>window.clearTimeout(A.current),[]),Fd();const W=f.useCallback(D=>{var V,Z;return E.current===((V=L.current)==null?void 0:V.side)&&_N(D,(Z=L.current)==null?void 0:Z.area)},[]);return n.jsx(dM,{scope:r,searchRef:O,onItemEnter:f.useCallback(D=>{W(D)&&D.preventDefault()},[W]),onItemLeave:f.useCallback(D=>{var U;W(D)||((U=C.current)==null||U.focus(),S(null))},[W]),onTriggerLeave:f.useCallback(D=>{W(D)&&D.preventDefault()},[W]),pointerGraceTimerRef:z,onPointerGraceIntentChange:f.useCallback(D=>{L.current=D},[]),children:n.jsx(_,{...B,children:n.jsx(GS,{asChild:!0,trapped:a,onMountAutoFocus:Ie(l,D=>{var U;D.preventDefault(),(U=C.current)==null||U.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:n.jsx(Wg,{asChild:!0,disableOutsidePointerEvents:c,onEscapeKeyDown:h,onPointerDownOutside:d,onFocusOutside:m,onInteractOutside:p,onDismiss:x,children:n.jsx(oN,{asChild:!0,...y,dir:v.dir,orientation:"vertical",loop:i,currentTabStopId:k,onCurrentTabStopIdChange:S,onEntryFocus:Ie(u,D=>{v.isUsingKeyboardRef.current||D.preventDefault()}),preventScrollOnEntryFocus:!0,children:n.jsx(MS,{role:"menu","aria-orientation":"vertical","data-state":ux(g.open),"data-radix-menu-content":"",dir:v.dir,...w,...b,ref:I,style:{outline:"none",...b.style},onKeyDown:Ie(b.onKeyDown,D=>{const V=D.target.closest("[data-radix-menu-content]")===D.currentTarget,Z=D.ctrlKey||D.altKey||D.metaKey,ue=D.key.length===1;V&&(D.key==="Tab"&&D.preventDefault(),!Z&&ue&&M(D.key));const Ae=C.current;if(D.target!==Ae||!nM.includes(D.key))return;D.preventDefault();const ae=N().filter(me=>!me.disabled).map(me=>me.ref.current);jN.includes(D.key)&&ae.reverse(),$N(ae)}),onBlur:Ie(t.onBlur,D=>{D.currentTarget.contains(D.target)||(window.clearTimeout(A.current),O.current="")}),onPointerMove:Ie(t.onPointerMove,Ua(D=>{const U=D.target,V=$.current!==D.clientX;if(D.currentTarget.contains(U)&&V){const Z=D.clientX>$.current?"right":"left";E.current=Z,$.current=D.clientX}}))})})})})})})},"MenuContentImpl")),CN=f.forwardRef(Ke(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(jt.div,{role:"group",...i,ref:s})},"MenuGroup")),gM=f.forwardRef(Ke(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(jt.div,{...i,ref:s})},"MenuLabel")),Km="MenuItem",Dw="menu.itemSelect",EN=f.forwardRef(Ke(function(t,s){const{disabled:r=!1,onSelect:i,...a}=t,l=f.useRef(null),o=Bo(Km,t.__scopeMenu),c=ox(Km,t.__scopeMenu),u=ct(s,l),h=f.useRef(!1),d=Ke(()=>{const m=l.current;if(!r&&m){const p=new CustomEvent(Dw,{bubbles:!0,cancelable:!0});m.addEventListener(Dw,x=>i==null?void 0:i(x),{once:!0}),Rd(m,p),p.defaultPrevented?h.current=!1:o.onClose()}},"handleSelect");return n.jsx(AN,{...a,ref:u,disabled:r,onClick:Ie(t.onClick,d),onPointerDown:m=>{var p;(p=t.onPointerDown)==null||p.call(t,m),h.current=!0},onPointerUp:Ie(t.onPointerUp,m=>{var p;h.current||(p=m.currentTarget)==null||p.click()}),onKeyDown:Ie(t.onKeyDown,m=>{r||m.target!==m.currentTarget||c.searchRef.current!==""&&m.key===" "||Hm.includes(m.key)&&(m.currentTarget.click(),m.preventDefault())})})},"MenuItem")),AN=f.forwardRef(Ke(function(t,s){const{__scopeMenu:r,disabled:i=!1,textValue:a,...l}=t,o=ox(Km,r),c=yN(r),u=f.useRef(null),h=ct(s,u),[d,m]=f.useState(!1),[p,x]=f.useState("");return f.useEffect(()=>{const j=u.current;j&&x((j.textContent??"").trim())},[l.children]),n.jsx(So.ItemSlot,{scope:r,disabled:i,textValue:a??p,children:n.jsx(cN,{asChild:!0,...c,focusable:!i,children:n.jsx(jt.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":i||void 0,"data-disabled":i?"":void 0,...l,ref:h,onPointerMove:Ie(t.onPointerMove,Ua(j=>{i?o.onItemLeave(j):(o.onItemEnter(j),j.defaultPrevented||j.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Ie(t.onPointerLeave,Ua(j=>o.onItemLeave(j))),onFocus:Ie(t.onFocus,()=>m(!0)),onBlur:Ie(t.onBlur,()=>m(!1))})})})},"MenuItemImpl")),xM="MenuRadioGroup",[vM,jM]=Gi(xM,{value:void 0,onValueChange:Ke(()=>{},"onValueChange")}),wM=f.forwardRef(Ke(function(t,s){const{value:r,onValueChange:i,...a}=t,l=us(i);return n.jsx(vM,{scope:t.__scopeMenu,value:r,onValueChange:l,children:n.jsx(CN,{...a,ref:s})})},"MenuRadioGroup")),yM="MenuRadioItem",bM=f.forwardRef(Ke(function(t,s){const{value:r,...i}=t,a=jM(yM,t.__scopeMenu),l=r===a.value;return n.jsx(SM,{scope:t.__scopeMenu,checked:l,children:n.jsx(EN,{role:"menuitemradio","aria-checked":l,...i,ref:s,"data-state":PN(l),onSelect:Ie(i.onSelect,()=>{var o;return(o=a.onValueChange)==null?void 0:o.call(a,r)},{checkForDefaultPrevented:!1})})})},"MenuRadioItem")),kM="MenuItemIndicator",[SM,OK]=Gi(kM,{checked:!1}),NM=f.forwardRef(Ke(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(jt.div,{role:"separator","aria-orientation":"horizontal",...i,ref:s})},"MenuSeparator")),TN="MenuSub",[CM,RN]=Gi(TN),EM=Ke(e=>{const{__scopeMenu:t,children:s,open:r=!1,onOpenChange:i}=e,a=ci(TN,t),l=Hd(t),[o,c]=f.useState(null),[u,h]=f.useState(null),d=us(i);return f.useEffect(()=>(a.open===!1&&d(!1),()=>d(!1)),[a.open,d]),n.jsx(Xg,{...l,children:n.jsx(bN,{scope:t,open:r,onOpenChange:d,content:u,onContentChange:h,children:n.jsx(CM,{scope:t,contentId:vs(),triggerId:vs(),trigger:o,onTriggerChange:c,children:s})})})},"MenuSub"),Rc="MenuSubTrigger",AM=f.forwardRef(Ke(function(t,s){const r=ci(Rc,t.__scopeMenu),i=Bo(Rc,t.__scopeMenu),a=RN(Rc,t.__scopeMenu),l=ox(Rc,t.__scopeMenu),o=f.useRef(null),{pointerGraceTimerRef:c,onPointerGraceIntentChange:u}=l,h={__scopeMenu:t.__scopeMenu},d=f.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);f.useEffect(()=>d,[d]),f.useEffect(()=>{const p=c.current;return()=>{window.clearTimeout(p),u(null)}},[c,u]);const m=ct(s,a.onTriggerChange);return n.jsx(kN,{asChild:!0,...h,children:n.jsx(AN,{id:a.triggerId,"aria-haspopup":"menu","aria-expanded":r.open,"aria-controls":r.open?a.contentId:void 0,"data-state":ux(r.open),...t,ref:m,onClick:p=>{var x;(x=t.onClick)==null||x.call(t,p),!(t.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),r.open||r.onOpenChange(!0))},onPointerMove:Ie(t.onPointerMove,Ua(p=>{l.onItemEnter(p),!p.defaultPrevented&&!t.disabled&&!r.open&&!o.current&&(l.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{r.onOpenChange(!0),d()},100))})),onPointerLeave:Ie(t.onPointerLeave,Ua(p=>{var j,b;d();const x=(j=r.content)==null?void 0:j.getBoundingClientRect();if(x){const g=(b=r.content)==null?void 0:b.dataset.side,v=g==="right",w=v?-5:5,y=x[v?"left":"right"],N=x[v?"right":"left"];l.onPointerGraceIntentChange({area:[{x:p.clientX+w,y:p.clientY},{x:y,y:x.top},{x:N,y:x.top},{x:N,y:x.bottom},{x:y,y:x.bottom}],side:g}),window.clearTimeout(c.current),c.current=window.setTimeout(()=>l.onPointerGraceIntentChange(null),300)}else{if(l.onTriggerLeave(p),p.defaultPrevented)return;l.onPointerGraceIntentChange(null)}})),onKeyDown:Ie(t.onKeyDown,p=>{var j;t.disabled||p.target!==p.currentTarget||l.searchRef.current!==""&&p.key===" "||sM[i.dir].includes(p.key)&&(r.onOpenChange(!0),(j=r.content)==null||j.focus(),p.preventDefault())})})})},"MenuSubTrigger")),TM="MenuSubContent",RM=f.forwardRef(Ke(function(t,s){const r=NN(js,t.__scopeMenu),{forceMount:i=r.forceMount,align:a="start",...l}=t,o=ci(js,t.__scopeMenu),c=Bo(js,t.__scopeMenu),u=RN(TM,t.__scopeMenu),h=f.useRef(null),d=ct(s,h);return n.jsx(So.Provider,{scope:t.__scopeMenu,children:n.jsx(xr,{present:i||o.open,children:n.jsx(So.Slot,{scope:t.__scopeMenu,children:n.jsx(cx,{id:u.contentId,"aria-labelledby":u.triggerId,...l,ref:d,align:a,side:c.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:m=>{var p;c.isUsingKeyboardRef.current&&((p=h.current)==null||p.focus()),m.preventDefault()},onCloseAutoFocus:m=>m.preventDefault(),onFocusOutside:Ie(t.onFocusOutside,m=>{m.target!==u.trigger&&o.onOpenChange(!1)}),onEscapeKeyDown:Ie(t.onEscapeKeyDown,m=>{c.onClose(),m.preventDefault()}),onKeyDown:Ie(t.onKeyDown,m=>{var j;const p=m.currentTarget.contains(m.target),x=rM[c.dir].includes(m.key);p&&x&&(o.onOpenChange(!1),(j=u.trigger)==null||j.focus(),m.preventDefault())})})})})})},"MenuSubContent"));function ux(e){return e?"open":"closed"}Ke(ux,"getOpenState");function IN(e){return e==="indeterminate"}Ke(IN,"isIndeterminate");function PN(e){return IN(e)?"indeterminate":e?"checked":"unchecked"}Ke(PN,"getCheckedState");function $N(e){const t=document.activeElement;for(const s of e)if(s===t||(s.focus(),document.activeElement!==t))return}Ke($N,"focusFirst");function MN(e,t){return e.map((s,r)=>e[(t+r)%e.length])}Ke(MN,"wrapArray");function ON(e,t,s){const i=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,a=s?e.indexOf(s):-1;let l=MN(e,Math.max(a,0));i.length===1&&(l=l.filter(u=>u!==s));const c=l.find(u=>u.toLowerCase().startsWith(i.toLowerCase()));return c!==s?c:void 0}Ke(ON,"getNextMatch");function DN(e,t){const{x:s,y:r}=e;let i=!1;for(let a=0,l=t.length-1;a<t.length;l=a++){const o=t[a],c=t[l],u=o.x,h=o.y,d=c.x,m=c.y;h>r!=m>r&&s<(d-u)*(r-h)/(m-h)+u&&(i=!i)}return i}Ke(DN,"isPointInPolygon");function _N(e,t){if(!t)return!1;const s={x:e.clientX,y:e.clientY};return DN(s,t)}Ke(_N,"isPointerInGraceArea");function Ua(e){return t=>t.pointerType==="mouse"?e(t):void 0}Ke(Ua,"whenMouse");var IM=oM,PM=kN,$M=uM,MM=hM,OM=CN,DM=gM,_M=EN,LM=wM,FM=bM,zM=NM,UM=EM,BM=AM,WM=RM,HM=Object.defineProperty,Gn=(e,t)=>HM(e,"name",{value:t,configurable:!0}),dx="DropdownMenu",[KM,DK]=Ns(dx,[wN]),Yn=wN(),[VM,LN]=KM(dx),GM=Gn(e=>{const{__scopeDropdownMenu:t,children:s,dir:r,open:i,defaultOpen:a,onOpenChange:l,modal:o=!0}=e,c=Yn(t),u=f.useRef(null),[h,d]=Wi({prop:i,defaultProp:a??!1,onChange:l,caller:dx});return n.jsx(VM,{scope:t,triggerId:vs(),triggerRef:u,contentId:vs(),open:h,onOpenChange:d,onOpenToggle:f.useCallback(()=>d(m=>!m),[d]),modal:o,children:n.jsx(IM,{...c,open:h,onOpenChange:d,dir:r,modal:o,children:s})})},"DropdownMenu"),YM="DropdownMenuTrigger",qM=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,disabled:i=!1,...a}=t,l=LN(YM,r),o=Yn(r),c=ct(s,l.triggerRef);return n.jsx(PM,{asChild:!0,...o,children:n.jsx(jt.button,{type:"button",id:l.triggerId,"aria-haspopup":"menu","aria-expanded":l.open,"aria-controls":l.open?l.contentId:void 0,"data-state":l.open?"open":"closed","data-disabled":i?"":void 0,disabled:i,...a,ref:c,onPointerDown:Ie(t.onPointerDown,u=>{!i&&u.button===0&&u.ctrlKey===!1&&(l.onOpenToggle(),l.open||u.preventDefault())}),onKeyDown:Ie(t.onKeyDown,u=>{i||(["Enter"," "].includes(u.key)&&l.onOpenToggle(),u.key==="ArrowDown"&&l.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(u.key)&&u.preventDefault())})})})},"DropdownMenuTrigger")),QM=Gn(e=>{const{__scopeDropdownMenu:t,...s}=e,r=Yn(t);return n.jsx($M,{...r,...s})},"DropdownMenuPortal"),JM="DropdownMenuContent",XM=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=LN(JM,r),l=Yn(r),o=f.useRef(!1);return n.jsx(MM,{id:a.contentId,"aria-labelledby":a.triggerId,...l,...i,ref:s,onCloseAutoFocus:Ie(t.onCloseAutoFocus,c=>{var u;o.current||(u=a.triggerRef.current)==null||u.focus(),o.current=!1,c.preventDefault()}),onInteractOutside:Ie(t.onInteractOutside,c=>{const u=c.detail.originalEvent,h=u.button===0&&u.ctrlKey===!0,d=u.button===2||h;(!a.modal||d)&&(o.current=!0)}),style:{...t.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})},"DropdownMenuContent")),ZM=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(OM,{...a,...i,ref:s})},"DropdownMenuGroup")),eO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(DM,{...a,...i,ref:s})},"DropdownMenuLabel")),tO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(_M,{...a,...i,ref:s})},"DropdownMenuItem")),nO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(LM,{...a,...i,ref:s})},"DropdownMenuRadioGroup")),sO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(FM,{...a,...i,ref:s})},"DropdownMenuRadioItem")),rO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(zM,{...a,...i,ref:s})},"DropdownMenuSeparator")),iO=Gn(e=>{const{__scopeDropdownMenu:t,children:s,open:r,onOpenChange:i,defaultOpen:a}=e,l=Yn(t),[o,c]=Wi({prop:r,defaultProp:a??!1,onChange:i,caller:"DropdownMenuSub"});return n.jsx(UM,{...l,open:o,onOpenChange:c,children:s})},"DropdownMenuSub"),aO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(BM,{...a,...i,ref:s})},"DropdownMenuSubTrigger")),lO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(WM,{...a,...i,ref:s,style:{...t.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})},"DropdownMenuSubContent")),Kd=GM,Vd=qM,Wo=QM,Gd=XM,FN=ZM,Yd=eO,Ei=tO,oO=nO,cO=sO,Mr=rO,uO=iO,dO=aO,hO=lO,fO=Object.defineProperty,il=(e,t)=>fO(e,"name",{value:t,configurable:!0}),hx="Tabs",[mO,_K]=Ns(hx,[Ud]),zN=Ud(),[pO,fx]=mO(hx),gO=f.forwardRef(il(function(t,s){const{__scopeTabs:r,value:i,onValueChange:a,defaultValue:l,orientation:o="horizontal",dir:c,activationMode:u="automatic",...h}=t,d=Ld(c),[m,p]=Wi({prop:i,onChange:a,defaultProp:l??"",caller:hx});return n.jsx(pO,{scope:r,baseId:vs(),value:m,onValueChange:p,orientation:o,dir:d,activationMode:u,children:n.jsx(jt.div,{dir:d,"data-orientation":o,...h,ref:s})})},"Tabs")),xO="TabsList",vO=f.forwardRef(il(function(t,s){const{__scopeTabs:r,loop:i=!0,...a}=t,l=fx(xO,r),o=zN(r);return n.jsx(oN,{asChild:!0,...o,orientation:l.orientation,dir:l.dir,loop:i,children:n.jsx(jt.div,{role:"tablist","aria-orientation":l.orientation,...a,ref:s})})},"TabsList")),jO="TabsTrigger",wO=f.forwardRef(il(function(t,s){const{__scopeTabs:r,value:i,disabled:a=!1,...l}=t,o=fx(jO,r),c=zN(r),u=mx(o.baseId,i),h=px(o.baseId,i),d=i===o.value;return n.jsx(cN,{asChild:!0,...c,focusable:!a,active:d,children:n.jsx(jt.button,{type:"button",role:"tab","aria-selected":d,"aria-controls":h,"data-state":d?"active":"inactive","data-disabled":a?"":void 0,disabled:a,id:u,...l,ref:s,onMouseDown:Ie(t.onMouseDown,m=>{!a&&m.button===0&&m.ctrlKey===!1?o.onValueChange(i):m.preventDefault()}),onKeyDown:Ie(t.onKeyDown,m=>{a||m.target!==m.currentTarget||[" ","Enter"].includes(m.key)&&o.onValueChange(i)}),onFocus:Ie(t.onFocus,()=>{const m=o.activationMode!=="manual";!d&&!a&&m&&o.onValueChange(i)})})})},"TabsTrigger")),yO="TabsContent",bO=f.forwardRef(il(function(t,s){const{__scopeTabs:r,value:i,forceMount:a,children:l,...o}=t,c=fx(yO,r),u=mx(c.baseId,i),h=px(c.baseId,i),d=i===c.value,m=f.useRef(d);return f.useEffect(()=>{const p=requestAnimationFrame(()=>m.current=!1);return()=>cancelAnimationFrame(p)},[]),n.jsx(xr,{present:a||d,children:({present:p})=>n.jsx(jt.div,{"data-state":d?"active":"inactive","data-orientation":c.orientation,role:"tabpanel","aria-labelledby":u,hidden:!p,id:h,tabIndex:0,...o,ref:s,style:{...t.style,animationDuration:m.current?"0s":void 0},children:p&&l})})},"TabsContent"));function mx(e,t){return`${e}-trigger-${t}`}il(mx,"makeTriggerId");function px(e,t){return`${e}-content-${t}`}il(px,"makeContentId");var kO=gO,SO=vO,NO=wO,CO=bO;function Be(e,t){if(!e)return"—";const s=new Date(e);return Number.isNaN(s.getTime())?String(e):new Intl.DateTimeFormat("en-GB",{timeZone:t,year:"numeric",month:"short",day:"2-digit",hour:"2-digit",minute:"2-digit"}).format(s)}function Fe(e,t=Date.now()){if(!e)return"";const s=new Date(e).getTime();if(Number.isNaN(s))return"";const r=Math.round((s-t)/1e3),i=Math.abs(r),[a,l]=i<60?[r,"second"]:i<3600?[Math.round(r/60),"minute"]:i<86400?[Math.round(r/3600),"hour"]:[Math.round(r/86400),"day"];return new Intl.RelativeTimeFormat("en",{numeric:"auto"}).format(a,l)}function UN(e,t=Date.now()){if(!e)return"";const s=new Date(e).getTime();if(Number.isNaN(s))return"";const r=Math.abs(Math.round((t-s)/1e3));return r<60?"now":r<3600?`${Math.floor(r/60)} min`:r<86400?`${Math.floor(r/3600)} h`:`${Math.floor(r/86400)} d`}function EO(e,t=Date.now()){const s=UN(e,t);return s===""?"":s==="now"||new Date(e).getTime()>t?"just now":s==="1 d"?"yesterday":`${s} ago`}function AO(e,t){if(e==null||!Number.isFinite(e))return"—";try{return new Intl.NumberFormat("en-US",{style:"currency",currency:t??"USD",maximumFractionDigits:0}).format(e)}catch{return e.toFixed(2)}}function _t(e){return new Intl.NumberFormat("en-US").format(e)}function Vm(e){return[...e.cacheRead?[`cached ${_t(e.cacheRead)}`]:[],...e.cacheWrite?[`cache write ${_t(e.cacheWrite)}`]:[]].join(", ")}function TO(e){const t=Vm(e);return`${_t(e.input)} in${t?` (${t})`:""} / ${_t(e.output)} out`}function In(e){try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function No(e,t=8){return e.length<=t?e:e.slice(0,t)}function Ks(e,t){return e.length<=t?e:`${e.slice(0,t-1)}…`}function Ba(e){return e.replace(/<<<[^<>]*>>>/g,"")}function zt(e,t,s){if(e==null)return"—";switch(t){case"currency":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?RO(r,s):String(e)}case"percent":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?`${_w(r)}%`:String(e)}case"number":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?Number.isInteger(r)?_t(r):_w(r):String(e)}case"date":return IO(String(e));default:return typeof e=="string"?e:typeof e=="number"?_t(e):typeof e=="boolean"?e?"yes":"no":JSON.stringify(e)??String(e)}}function RO(e,t){if(!(Math.abs(e)<1e3&&!Number.isInteger(e)))return AO(e,t);try{return new Intl.NumberFormat("en-US",{style:"currency",currency:t??"USD",maximumFractionDigits:2}).format(e)}catch{return e.toFixed(2)}}function IO(e){const t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);if(!t)return e;const s=new Date(`${t[0]}T00:00:00Z`);return Number.isNaN(s.getTime())?e:new Intl.DateTimeFormat("en-GB",{timeZone:"UTC",day:"numeric",month:"short",year:"numeric"}).format(s)}function Gm(e){const t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);if(!t)return e;const s=new Date(`${t[0]}T00:00:00Z`);return Number.isNaN(s.getTime())?e:new Intl.DateTimeFormat("en-GB",{timeZone:"UTC",day:"numeric",month:"short"}).format(s)}function _w(e){return String(Math.round(e*100)/100)}function Yu(e,t,s=4){if(!Number.isFinite(e)||!Number.isFinite(t))return[];if(e===t)return[e];const r=(t-e)/Math.max(1,s),i=10**Math.floor(Math.log10(r)),a=[1,2,2.5,5,10].map(o=>o*i).find(o=>o>=r)??i*10,l=[];for(let o=Math.ceil(e/a)*a;o<=t+a/1e3;o+=a)l.push(Math.round(o*1e6)/1e6);return l.filter(o=>o>=e&&o<=t)}function PO({props:e}){if(e.bars.length===0)return n.jsx("p",{className:"wb-empty",children:"No categories came back."});const t=e.bars.map(a=>a.value),s=Math.max(0,...t),r=Math.min(0,...t),i=s-r||1;return n.jsx("div",{className:"wb-bars",children:e.bars.map(a=>{const l=Math.abs(a.value)/i;return n.jsxs("div",{className:"wb-bar-row",children:[n.jsx("div",{className:"wb-bar-cat",title:a.category,children:a.category}),n.jsx("div",{className:"wb-bar-track",children:n.jsx("div",{className:"wb-bar-fill",style:{width:`${Math.max(1,l*100)}%`,background:a.value<0?"var(--chart-bar-negative)":"var(--chart-bar)"}})}),n.jsx("div",{className:"wb-bar-val",children:zt(a.value,e.unit,e.currency)})]},a.category)})})}const $O=/^(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 )/,MO=/^(… |\.\.\. |\(no change\)$|\)/;function OO(e){return e.replace(/\n$/,"").split(`
81
- `).map(s=>({kind:DO(s),text:s}))}function DO(e){return e.startsWith("@@")?"hunk":$O.test(e)||MO.test(e)?"meta":e.startsWith("+")?"add":e.startsWith("-")?"del":"context"}function _O({text:e,marks:t}){const s=e.toLowerCase(),r=[];for(const l of t){const o=l.trim().toLowerCase();if(o!=="")for(let c=s.indexOf(o);c!==-1;c=s.indexOf(o,c+o.length))r.push([c,c+o.length])}if(r.length===0)return n.jsx(n.Fragment,{children:e===""?" ":e});r.sort((l,o)=>l[0]-o[0]);const i=[];let a=0;for(const[l,o]of r)l<a||(l>a&&i.push(n.jsx("span",{children:e.slice(a,l)},`t${a}`)),i.push(n.jsx("mark",{className:"wb-diff-mark",children:e.slice(l,o)},`m${l}`)),a=o);return a<e.length&&i.push(n.jsx("span",{children:e.slice(a)},`t${a}`)),n.jsx(n.Fragment,{children:i})}function qu({text:e,limit:t,more:s,label:r="Diff",marks:i}){const a=OO(e),l=t===void 0?a:a.slice(0,t),o=a.length-l.length;return n.jsxs("div",{className:"wb-diff-wrap",children:[n.jsx("pre",{className:"wb-diff","aria-label":r,"data-testid":"diff",children:l.map((c,u)=>n.jsx("span",{className:"wb-diff-line","data-kind":c.kind,children:i&&i.length>0?n.jsx(_O,{text:c.text,marks:i}):c.text===""?" ":c.text},u))}),o>0?n.jsxs("p",{className:"wb-diff-more",children:[o," more line",o===1?"":"s",s?n.jsxs(n.Fragment,{children:[" · ",n.jsx("button",{type:"button",className:"wb-diff-open",onClick:s.onClick,children:s.label})]}):null]}):null]})}function LO({props:e}){return n.jsxs("div",{children:[e.title?n.jsx("h4",{className:"wb-doc-title mono",children:e.title}):null,e.metadata.length>0?n.jsx("dl",{className:"ui-kv wb-block",children:e.metadata.map(t=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:t.label}),n.jsx("dd",{children:zt(t.value,t.unit,null)})]},t.label))}):null,e.diff?n.jsx(qu,{text:e.diff,label:e.title?`Diff of ${e.title}`:"Diff"}):n.jsx("p",{className:"wb-empty",children:"This change came back with no diff."})]})}const Kt="#/",Vr="#/chat",mt="#/agents",St="#/activity",dn="#/settings",_i="#/files",FO="#/welcome";function hu(e){const t=/^#\/welcome(?:\?(.*))?$/.exec(e);if(!t)return null;try{return{step:new URLSearchParams(t[1]??"").get("step")}}catch{return{step:null}}}function Ic(e,t={}){const s=new URLSearchParams;t.q&&s.set("q",t.q),t.origin&&s.set("origin",t.origin),t.family&&s.set("family",t.family);const r=s.toString();return`${_i}${e?`/${encodeURIComponent(e)}`:""}${r?`?${r}`:""}`}function zO(e){const t=/^#\/files(?:\/([^/?]+))?(?:\?(.*))?$/.exec(e);if(!t)return null;try{const s=new URLSearchParams(t[2]??""),r={};return s.get("q")&&(r.q=s.get("q")),s.get("origin")&&(r.origin=s.get("origin")),s.get("family")&&(r.family=s.get("family")),{...t[1]?{artifactId:decodeURIComponent(t[1])}:{},filters:r}}catch{return null}}function Ve(e,t,s){return`#/chat/${encodeURIComponent(e)}${t?`/${encodeURIComponent(t)}`:""}`}function UO(e){if(BN(e))return null;const t=/^#\/chat\/([^/?]+)(?:\/([^/?]+))?(?:\?(.*))?$/.exec(e);if(!t)return null;try{const s=new URLSearchParams(t[3]??"").get("tab");return{agentId:decodeURIComponent(t[1]),...t[2]?{conversationId:decodeURIComponent(t[2])}:{},...s?{tab:s}:{}}}catch{return null}}function Gl(e,t){return`#/chat/g/${encodeURIComponent(e)}${t?`/${encodeURIComponent(t)}`:""}`}function BN(e){const t=/^#\/chat\/g\/([^/?]+)(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(!t)return null;try{return{groupId:decodeURIComponent(t[1]),...t[2]?{conversationId:decodeURIComponent(t[2])}:{}}}catch{return null}}function pt(e,t,s){return`${mt}/${encodeURIComponent(e)}${t?`/${t}${s?`/${s}`:""}`:""}`}function BO(e){const t=/^#\/agents\/([^/]+)(?:\/([a-z-]+)(?:\/([a-z-]+))?)?$/.exec(e);if(!t)return null;try{return{agentId:decodeURIComponent(t[1]),...t[2]?{tab:t[2]}:{},...t[3]?{section:t[3]}:{}}}catch{return null}}function Wa(e){return`${St}/conversations/${encodeURIComponent(e)}`}const WO="#/p";function ti(e,t,s){const r=`${WO}/${encodeURIComponent(e)}/${encodeURIComponent(t)}`;return s?`${r}/${encodeURIComponent(s)}`:r}function gx(e){const t=/^#\/p\/([^/?]+)\/([^/?]+)(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(!t)return null;try{return{plugin:decodeURIComponent(t[1]),page:decodeURIComponent(t[2]),...t[3]?{item:decodeURIComponent(t[3])}:{}}}catch{return null}}const HO="p.";function al(e,t){return`${dn}/${encodeURIComponent(WN(e,t))}`}function KO(e){const t=/^#\/settings\/p\.([^/?.]+)(?:\.([^/?.]+))?(?:\?.*)?$/.exec(e);if(!t)return null;const s=decodeURIComponent(t[1]);return{plugin:s,page:t[2]?decodeURIComponent(t[2]):s}}function WN(e,t){return`${HO}${e}${t===e?"":`.${t}`}`}function et(e){return e?`${dn}/${e}`:dn}function VO(e){return`${et("proposals")}${e?`?plugin=${encodeURIComponent(e)}`:""}`}function GO(e){const t=/^#\/settings\/proposals\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1]).get("plugin")||null}catch{return null}}function HN(e){const t=/^#\/settings\/plugins\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1])}catch{return null}}function YO(e){var s,r;const t=(r=(s=HN(e))==null?void 0:s.get("install"))==null?void 0:r.trim();return t||null}function Lw(e){const t=HN(e);return t!=null&&t.get("install")?"installed":(t==null?void 0:t.get("tab"))==="browse"?"browse":"installed"}const qO=[{route:Kt,label:"Home"},{route:Vr,label:"Chat"},{route:mt,label:"Agents"},{route:St,label:"Activity"},{route:_i,label:"Files"},{route:dn,label:"Settings"}],QO=[{id:"you",label:"You"},{id:"access",label:"Models and access"},{id:"running",label:"Running"},{id:"plugins",label:"Plugins"}],JO=[{id:"you",label:"Profile",group:"you"},{id:"appearance",label:"Appearance",group:"you"},{id:"notifications",label:"Notifications",group:"you"},{id:"memory",label:"Memory",group:"you"},{id:"proposals",label:"Proposals",group:"you"},{id:"accounts",label:"Model accounts",group:"access"},{id:"computer",label:"Computer & browser",group:"access"},{id:"secrets",label:"Keys and secrets",group:"access"},{id:"connections",label:"Connections",group:"access"},{id:"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 XO(e){var t;return((t=/^#\/settings\/([a-z0-9.-]+)/.exec(e))==null?void 0:t[1])??"you"}const Fw=et("backup");function ZO(e){const t=/^#\/conversations\/(.+)$/.exec(e);if(t)return Wa(decodeURIComponent(t[1]));const s=/^#\/email(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(s)try{return ti("email","mail",s[1]?decodeURIComponent(s[1]):null)}catch{return ti("email","mail")}return e==="#/settings/email"?al("email","settings"):{"#/overview":Kt,"#/approvals":Kt,"#/events":`${St}/events`,"#/jobs":`${St}/jobs`,"#/conversations":St,"#/missions":`${mt}?tab=missions`,"#/offers":`${mt}?tab=offers`,"#/reminders":`${mt}?tab=reminders`,"#/providers":et("accounts"),"#/browser":et("computer"),"#/sentinels":et("watchers"),"#/settings/sentinels":et("watchers")}[e]??null}function KN(e){if(e===""||e==="#"||e===Kt)return Kt;if(e.startsWith(Vr))return Vr;if(e.startsWith(mt))return mt;if(e.startsWith(St))return St;if(e.startsWith(_i))return _i;if(e.startsWith(dn))return dn;const t=gx(e);return t?ti(t.plugin,t.page):Kt}const eD="#/chat?group=new";function tD(e){const t=e.replace(/^#\/?/,"").split("?")[0].toLowerCase();if(t==="")return"home";const[s,r]=t.split("/");return!s||!/^[a-z0-9-]+$/.test(s)?null:(s==="settings"||s==="p")&&r&&/^[a-z0-9.-]+$/.test(r)?`${s}/${r}`:s}const xx="front-desk",vx=[{id:xx,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."}],VN=new Set(vx.map(e=>e.id)),zw=e=>VN.has(e);function Uw(e,t){const s=t.filter(r=>!VN.has(r));return[...vx.filter(r=>e.has(r.id)).map(r=>r.id),...s.filter((r,i)=>s.indexOf(r)===i)]}function nD(e,t){return e.find(s=>(s.roles??[]).includes(t))}const Bw=["coding","finance","mail","research","calendar","files","memory"],sD={developer:"coding",coding:"coding",finance:"finance",credit:"finance",mail:"mail",email:"mail",research:"research",calendar:"calendar",files:"files",memory:"memory",[xx]:"buddi"},rD=[["mail",["email"]],["finance",["finance"]],["coding",["developer"]],["research",["web","browser"]],["art",["image"]]];function iD(e){const t=new Set(e.map(s=>s.split(".")[0]??s));for(const[s,r]of rD)if(r.some(i=>t.has(i)))return s;return t.size>0&&[...t].every(s=>s==="memory")?"memory":null}let Ym=null;function aD(e){Ym=e}function Ho(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=sD[s];if(r)return{key:r}}const t=iD(e.tools??[]);return t?{key:t}:Ym!==null&&e.id===Ym?{key:"buddi"}:{key:Bw[lD(e.id)%Bw.length]??"coding"}}function Ko(e){return e.key==="own"?{"data-agent":"own",style:{"--agent-fill":e.hex}}:{"data-agent":e.key}}function lD(e){let t=0;for(const s of e)t=(t*31+s.charCodeAt(0))%997;return t}const oD=["run.started","tool.called","tool.result","message.appended","awaiting-approval","run.finished","live","live.settle","live.snapshot","attention","ping"];function cD(e){const s=e.replace(/\r\n/g,`
82
- `).split(`
83
-
84
- `),r=s.pop()??"",i=[];for(const a of s){let l=null,o="message";const c=[];for(const u of a.split(`
85
- `)){if(u===""||u.startsWith(":"))continue;const h=u.indexOf(":"),d=h===-1?u:u.slice(0,h),m=h===-1?"":u.slice(h+1).replace(/^ /,"");d==="id"?l=m:d==="event"?o=m:d==="data"&&c.push(m)}c.length===0&&o==="message"||i.push({id:l,name:oD.includes(o)?o:"ping",data:uD(c.join(`
86
- `))})}return{events:i,rest:r}}function uD(e){if(e==="")return{};try{const t=JSON.parse(e);return t!==null&&typeof t=="object"?t:{value:t}}catch{return{value:e}}}function qd(e){const t=e.fetchImpl??globalThis.fetch.bind(globalThis),s=e.wait??(u=>new Promise(h=>setTimeout(h,u))),r=e.retryMs??1500;let i=e.lastEventId??null,a=!1,l=!1,o=null;return(async()=>{var u,h,d,m,p;for(;!a;){(u=e.onStatus)==null||u.call(e,"connecting"),o=new AbortController;try{const x=await t(e.url,{credentials:"same-origin",signal:o.signal,headers:{Accept:"text/event-stream",...i===null?{}:{"Last-Event-ID":i}}});if(!x.ok||!x.body)throw new Error(`stream ${x.status}`);(h=e.onStatus)==null||h.call(e,"open"),l&&((d=e.onReconnect)==null||d.call(e));const j=x.body.getReader(),b=new TextDecoder;let g="";for(;;){const{done:v,value:w}=await j.read();if(v)break;g+=b.decode(w,{stream:!0});const{events:y,rest:N}=cD(g);g=N;for(const k of y)e.onEvent(k),k.id!==null&&(i=k.id);if(a)break}}catch{}if(a)break;l=!0,(m=e.onStatus)==null||m.call(e,"closed"),await s(r)}(p=e.onStatus)==null||p.call(e,"closed")})(),{close:()=>{a=!0,o==null||o.abort()},lastEventId:()=>i}}const jx="0.1.0+ee4bcef";function wx(e,t=jx){return typeof e=="string"&&e!==""&&typeof t=="string"&&t!==""&&e!==t}function dD(){var e;try{if((e=window.matchMedia)!=null&&e.call(window,"(display-mode: standalone)").matches)return!0}catch{}return window.navigator.standalone===!0}const hD=5*6e4,fD=6e4,mD=5e3,qm="buddi:stream-reconnected",GN="buddi.autoReloadedFor";function pD(){window.dispatchEvent(new Event(qm))}const Ww=["keydown","pointerdown","pointermove","wheel","touchstart","input"];let yx=Date.now(),Pc=0;const Hw=()=>{yx=Date.now()};function gD(){if(Pc===0){yx=Date.now();for(const e of Ww)window.addEventListener(e,Hw,{capture:!0,passive:!0})}return Pc+=1,()=>{if(Pc-=1,Pc===0)for(const e of Ww)window.removeEventListener(e,Hw,{capture:!0})}}function xD(e=Date.now()){return e-yx}function vD(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 jD(e){return e.hidden?!0:e.idleMs>=fD&&!e.busy}function wD(e){try{return window.sessionStorage.getItem(GN)===e}catch{return!1}}function yD(e){try{window.sessionStorage.setItem(GN,e)}catch{}}function bD(e){const t=f.useRef(e);t.current=e,f.useEffect(()=>{const s=()=>t.current();return window.addEventListener(qm,s),()=>window.removeEventListener(qm,s)},[])}function kD(e,t=()=>window.location.reload(),s=jx){const r=wx(e,s),i=f.useRef(t);i.current=t,f.useEffect(()=>gD(),[]),f.useEffect(()=>{if(!r||e===void 0||wD(e))return;let a=!1;const l=()=>{if(a)return;const c=document.visibilityState==="hidden";jD({hidden:c,idleMs:xD(),busy:vD()})&&(a=!0,yD(e),i.current())};l();const o=window.setInterval(l,mD);return document.addEventListener("visibilitychange",l),()=>{window.clearInterval(o),document.removeEventListener("visibilitychange",l)}},[r,e])}const SD="/api/chat/attention/stream";function YN(e,t){const s=(a,l)=>a.name.localeCompare(l.name),r=a=>e.filter(l=>l.anchor===a).sort(s),i=e.filter(a=>a.anchor!=="top"&&a.anchor!=="bottom").sort((a,l)=>a.id===t?l.id===t?0:-1:l.id===t?1:s(a,l));return{top:r("top"),middle:i,bottom:r("bottom")}}function qN(e,t){const s=YN(e,t);return[...s.top,...s.middle,...s.bottom]}function Qd(e){if(!e)return null;const t=[];return e.approvals>0&&t.push(e.approvals===1?"one approval is waiting for you":`${e.approvals} approvals are waiting for you`),e.question&&t.push("asked you a question and is holding for the answer"),t.length===0?null:t.join(", and ")}function ND(e){if(!e)return null;const t=e.approvals,s=t===1?"1 approval":`${t} approvals`;return t>0&&e.question?`${s} and a question`:t>0?`${s} waiting`:e.question?"Has a question":null}function CD(e,t){return e&&(e.approvals>0||e.question)?"needs":t?"working":null}function ED(e){return new Map(((e==null?void 0:e.agents)??[]).map(t=>[t.agentId,t]))}function AD(){const[e,t]=f.useState(null);return f.useEffect(()=>{let s=!1;const r=()=>{he("/chat/attention").then(a=>{s||t(a)}).catch(()=>{})};r();const i=qd({url:SD,onEvent:()=>r(),onReconnect:pD});return()=>{s=!0,i.close()}},[]),ED(e)}const Jd="maker";function QN(e){return e.filter(t=>t.available&&!t.roles.includes(Jd))}function JN(e){return QN(e).length>=2}function TD(e){var t;return((t=e.find(s=>s.roles.includes(Jd)))==null?void 0:t.name)??"the agent maker"}const RD="{{default}}";function ID(e,t){return e.split(RD).join(t??"your assistant")}function PD(e,t){return((e==null?void 0:e.starters)??[]).slice(0,3).map(s=>ID(s,t))}function $D(e){var s,r;const t=(s=e==null?void 0:e.intro)==null?void 0:s.trim();return t&&t!==""?t:((r=e==null?void 0:e.description)==null?void 0:r.trim())??""}function MD(e){const t=(e??"·").trim().split(/\s+/).filter(Boolean);return t.length===0?"·":t.length===1?t[0].slice(0,2).toUpperCase():(t[0][0]+t[1][0]).toUpperCase()}function XN(e){var r,i;const t=(r=e.heldBack)==null?void 0:r.message.trim();if(t!==void 0&&t!=="")return`${e.name??"This agent"} is held back. ${t}`;const s=(i=e.unavailableReason)==null?void 0:i.trim();return s&&s!==""?`${e.name??"This agent"} cannot run: ${s}`:`${e.name??"This agent"} cannot run: it has no model account yet.`}const OD="Settings → Model accounts",DD="Install it in Settings → Plugins";function Qm(e){return e!=null&&e.heldBack?{section:"plugins",label:DD}:{section:"accounts",label:OD}}const _D={home:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M3.5 9.2 10 3.6l6.5 5.6"}),n.jsx("path",{d:"M5.2 8.4v7.4a1 1 0 0 0 1 1h2.6v-4.6h2.4v4.6h2.6a1 1 0 0 0 1-1V8.4"})]})],chat:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M17 10.6a4.9 4.9 0 0 1-4.9 4.9H7.8L3.6 18l.9-3A4.9 4.9 0 0 1 3 11V8.2A4.9 4.9 0 0 1 7.9 3.3h4.2A4.9 4.9 0 0 1 17 8.2Z"}),n.jsx("path",{d:"M7 8.3h6M7 11.3h3.6"})]})],agents:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"7.5",cy:"7",r:"2.8"}),n.jsx("path",{d:"M2.8 16.2a4.7 4.7 0 0 1 9.4 0"}),n.jsx("circle",{cx:"14",cy:"7.8",r:"2.2"}),n.jsx("path",{d:"M13.2 12.5a3.9 3.9 0 0 1 4.3 3.7"})]})],activity:[20,1.6,n.jsx("path",{d:"M2.8 10.5h3.4l2-5.2 3.4 9.8 2.2-4.6h3.4"})],settings:[24,1.9,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),n.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),20],files:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M7.5 2.8h5.2L16.5 6.6v8.6a1.2 1.2 0 0 1-1.2 1.2H7.5a1.2 1.2 0 0 1-1.2-1.2V4a1.2 1.2 0 0 1 1.2-1.2z"}),n.jsx("path",{d:"M12.7 2.8v3.8h3.8"}),n.jsx("path",{d:"M4.4 6.2v9.4a1.6 1.6 0 0 0 1.6 1.6h6.6"})]})],mail:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"3",y:"5",width:"14",height:"10.5",rx:"1.4"}),n.jsx("path",{d:"M3.4 6 10 11l6.6-5"})]})],money:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.6",y:"5.2",width:"14.8",height:"9.6",rx:"1.6"}),n.jsx("circle",{cx:"10",cy:"10",r:"2.2"}),n.jsx("path",{d:"M5.4 10h.5M14.1 10h.5"})]})],calendar:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"3",y:"4.4",width:"14",height:"12.2",rx:"1.6"}),n.jsx("path",{d:"M3 8.2h14M6.8 2.9v2.6M13.2 2.9v2.6"})]})],chart:[20,1.6,n.jsx("path",{d:"M3.2 16.4V8.6M8.4 16.4V3.9M13.6 16.4v-5.8M3.2 16.4h13.6"})],bell:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M5.4 13.6V9a4.6 4.6 0 0 1 9.2 0v4.6l1.2 1.7H4.2Z"}),n.jsx("path",{d:"M8.4 17.1a1.8 1.8 0 0 0 3.2 0"})]})],plug:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M7.4 2.8v3.4M12.6 2.8v3.4"}),n.jsx("path",{d:"M5 6.2h10v3.1a5 5 0 0 1-10 0Z"}),n.jsx("path",{d:"M10 14.3v3"})]})],key:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"6.6",cy:"10",r:"3.2"}),n.jsx("path",{d:"M9.8 10h7.2M14.4 10v2.6M16.6 10v1.8"})]})],globe:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"10",cy:"10",r:"7.1"}),n.jsx("path",{d:"M2.9 10h14.2M10 2.9c3.4 3.7 3.4 10.5 0 14.2-3.4-3.7-3.4-10.5 0-14.2Z"})]})],terminal:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"12.8",rx:"1.6"}),n.jsx("path",{d:"M6.2 8l2.6 2.4-2.6 2.4M10.6 12.8h3.4"})]})],person:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"10",cy:"7",r:"3.2"}),n.jsx("path",{d:"M4 16.6a6 6 0 0 1 12 0"})]})],sun:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"10",cy:"10",r:"3.2"}),n.jsx("path",{d:"M10 2.6v1.6M10 15.8v1.6M2.6 10h1.6M15.8 10h1.6M4.8 4.8l1.1 1.1M14.1 14.1l1.1 1.1M4.8 15.2l1.1-1.1M14.1 5.9l1.1-1.1"})]})],notebook:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M5.5 3.2h8.3a1 1 0 0 1 1 1v11.6a1 1 0 0 1-1 1H5.5a1 1 0 0 1-1-1V4.2a1 1 0 0 1 1-1Z"}),n.jsx("path",{d:"M7.6 3.2v13.6M10 7h2.6M10 9.8h2.6"})]})],bulb:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M7.2 13.2a5 5 0 1 1 5.6 0v1.6H7.2Z"}),n.jsx("path",{d:"M8 17.2h4"})]})],monitor:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"10",rx:"1.4"}),n.jsx("path",{d:"M7.4 16.8h5.2M10 13.6v3.2"})]})],eye:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M2.4 10S5.2 4.8 10 4.8 17.6 10 17.6 10 14.8 15.2 10 15.2 2.4 10 2.4 10Z"}),n.jsx("circle",{cx:"10",cy:"10",r:"2.4"})]})],archive:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"3.6",rx:"1"}),n.jsx("path",{d:"M4 7.2v8a1.2 1.2 0 0 0 1.2 1.2h9.6a1.2 1.2 0 0 0 1.2-1.2v-8M8.2 10.4h3.6"})]})],chip:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"5.4",y:"5.4",width:"9.2",height:"9.2",rx:"1.4"}),n.jsx("path",{d:"M8 2.8v2.6M12 2.8v2.6M8 14.6v2.6M12 14.6v2.6M2.8 8h2.6M2.8 12h2.6M14.6 8h2.6M14.6 12h2.6"})]})],"partly-cloudy":[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"7.4",cy:"7.4",r:"2.4"}),n.jsx("path",{d:"M7.4 2.8v1M2.8 7.4h1M4.2 4.2l.7.7M10.6 4.2l-.7.7"}),n.jsx("path",{d:"M7.8 16.8h6.4a2.9 2.9 0 0 0 .3-5.8 4 4 0 0 0-7.6 1.1 2.4 2.4 0 0 0 .9 4.7Z"})]})],cloud:[20,1.6,n.jsx("path",{d:"M6 15.6h8.2a3.3 3.3 0 0 0 .4-6.6 4.6 4.6 0 0 0-8.9 1A2.8 2.8 0 0 0 6 15.6Z"})],rain:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),n.jsx("path",{d:"M7.2 14.6l-.8 2M10.4 14.6l-.8 2M13.6 14.6l-.8 2"})]})],drizzle:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),n.jsx("path",{d:"M7 15.2v.3M10 16.4v.3M13 15.2v.3"})]})],snow:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),n.jsx("path",{d:"M7.4 14.4v2.4M6.2 15.6h2.4M12.6 14.4v2.4M11.4 15.6h2.4"})]})],storm:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),n.jsx("path",{d:"M10.8 13.2 9 15.6h2.4l-1.8 2.6"})]})],fog:[20,1.6,n.jsx("path",{d:"M3.6 7.2h12.8M5.2 10.2h9.6M3.6 13.2h12.8M6.4 16.2h7.2"})],wind:[20,1.6,n.jsx("path",{d:"M3 8h9.4a2.2 2.2 0 1 0-2.2-2.2M3 12h11.6a2.2 2.2 0 1 1-2.2 2.2M3 10h5.4"})],"moon-clear":[20,1.6,n.jsx("path",{d:"M15.8 12.2A6.2 6.2 0 0 1 7.8 4.2a6.2 6.2 0 1 0 8 8Z"})],dot:[20,1.6,n.jsx("circle",{cx:"10",cy:"10",r:"2.2"})],camera:[17,1.5,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M2.6 6.2a1.4 1.4 0 0 1 1.4-1.4h2l1.1-1.6h2.8l1.1 1.6h2a1.4 1.4 0 0 1 1.4 1.4v6.4a1.4 1.4 0 0 1-1.4 1.4H4a1.4 1.4 0 0 1-1.4-1.4z"}),n.jsx("circle",{cx:"8.5",cy:"9.2",r:"2.4"})]})],clip:[17,1.5,n.jsx("path",{d:"M13.2 8 8.4 12.8a3 3 0 0 1-4.2-4.2l5.1-5.1a2 2 0 1 1 2.8 2.8l-5 5"})],mic:[17,1.5,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"6.3",y:"2.4",width:"4.4",height:"7.6",rx:"2.2"}),n.jsx("path",{d:"M3.9 8.4a4.6 4.6 0 0 0 9.2 0M8.5 13v2"})]})],speaker:[17,1.5,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M2.8 6.6h2.4l3.4-2.8v9.4l-3.4-2.8H2.8z"}),n.jsx("path",{d:"M11.2 6.2a3.2 3.2 0 0 1 0 4.6M13.2 4.4a5.8 5.8 0 0 1 0 8.2"})]})],send:[16,1.8,n.jsx("path",{d:"M8 13V3.5M3.8 7.7 8 3.5l4.2 4.2"})],check:[16,1.8,n.jsx("path",{d:"M3.5 8.4 6.6 11.4 12.5 4.8"})],close:[16,1.8,n.jsx("path",{d:"M4.5 4.5l7 7M11.5 4.5l-7 7"})],thought:[13,1.4,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M4.2 9.6a3.6 3.6 0 1 1 4.6 0v1.2H4.2z"}),n.jsx("path",{d:"M5.2 12.2h2.6"})]})],chevron:[11,1.5,n.jsx("path",{d:"M2.8 4.2 5.5 6.9l2.7-2.7"})],arrow:[13,1.5,n.jsx("path",{d:"M4.8 2.6 9 6.5l-4.2 3.9"})],copy:[16,1.5,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"5.6",y:"5.6",width:"7.6",height:"7.6",rx:"1.4"}),n.jsx("path",{d:"M10.4 5.6V4a1.2 1.2 0 0 0-1.2-1.2H4A1.2 1.2 0 0 0 2.8 4v5.2A1.2 1.2 0 0 0 4 10.4h1.6"})]})],play:[16,1.5,n.jsx("path",{d:"M5.2 3.4v9.2L12.6 8z"})],pause:[16,1.5,n.jsx("path",{d:"M5.6 3.6v8.8M10.4 3.6v8.8"})],stop:[16,1.5,n.jsx("rect",{x:"4.2",y:"4.2",width:"7.6",height:"7.6",rx:"1.2"})],download:[16,1.5,n.jsx("path",{d:"M8 2.8v7.2M4.9 7 8 10.1 11.1 7M3 12.8h10"})],out:[12,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"6",cy:"6",r:"4.4"}),n.jsx("path",{d:"M3.4 8.6 8.6 3.4"})]}),11],"chevron-left":[14,1.6,n.jsx("path",{d:"M9 2.5 4.5 7 9 11.5"})],"chevron-right":[14,1.6,n.jsx("path",{d:"M5 2.5 9.5 7 5 11.5"})],plus:[14,1.6,n.jsx("path",{d:"M7 2.5v9M2.5 7h9"})],more:[16,0,n.jsxs("g",{fill:"currentColor",stroke:"none",children:[n.jsx("circle",{cx:"8",cy:"3.4",r:"1.35"}),n.jsx("circle",{cx:"8",cy:"8",r:"1.35"}),n.jsx("circle",{cx:"8",cy:"12.6",r:"1.35"})]})],drop:[28,1.8,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M14 4v13M8.5 11.5 14 17l5.5-5.5"}),n.jsx("path",{d:"M5 19.5v2a2.5 2.5 0 0 0 2.5 2.5h13a2.5 2.5 0 0 0 2.5-2.5v-2"})]})],folder:[20,1.6,n.jsx("path",{d:"M2.8 5.6a1.4 1.4 0 0 1 1.4-1.4h3.4l1.7 1.9h6.5a1.4 1.4 0 0 1 1.4 1.4v7.3a1.4 1.4 0 0 1-1.4 1.4H4.2a1.4 1.4 0 0 1-1.4-1.4Z"})],"chevron-down":[14,1.4,n.jsx("path",{d:"M4 5.5 7 8.5l3-3"}),12],frame:[22,1.3,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.6",y:"3.6",width:"16.8",height:"14.8",rx:"2"}),n.jsx("path",{d:"M2.6 14.2 7.4 9.6l3.4 3 3-2.6 3.6 3.2"}),n.jsx("circle",{cx:"7.4",cy:"7.6",r:"1.2"})]})],"shape-timeseries":[16,1.4,n.jsx("path",{d:"M2 11.5 5.4 7.2l2.6 2.2L14 3.5"})],"shape-table":[16,1.4,n.jsx("path",{d:"M2.2 3.5h11.6v9H2.2zM2.2 6.6h11.6M6.6 6.6v5.9"})],"shape-bars":[16,1.4,n.jsx("path",{d:"M3 13V8.2M7 13V3.6M11 13V6.4M2 13.6h12"})],"shape-keyvalue":[16,1.4,n.jsx("path",{d:"M2.6 4.6h4M9.4 4.6h4M2.6 8h4M9.4 8h4M2.6 11.4h4M9.4 11.4h4"})],"shape-tiles":[16,1.4,n.jsx("path",{d:"M2.4 3.4h4.8v4.2H2.4zM8.8 3.4h4.8v4.2H8.8zM2.4 9.2h4.8v4.2H2.4zM8.8 9.2h4.8v4.2H8.8z"})],"shape-document":[16,1.4,n.jsx("path",{d:"M4 2.4h5l3 3v8.2H4zM9 2.4v3h3M6 9h4M6 11.2h3"})],"shape-diff":[16,1.4,n.jsx("path",{d:"M8 2.6v5M5.5 5.1h5M5.5 11.6h5M3 14h10"})],"shape-terminal":[16,1.4,n.jsx("path",{d:"M2.2 3.4h11.6v9.2H2.2zM4.6 6.4l2 1.6-2 1.6M8 10h3"})],"shape-image":[16,1.4,n.jsx("path",{d:"M2.2 3.4h11.6v9.2H2.2zM2.2 11l3.6-3.4 2.6 2.4 2-1.8 3.4 3M10.6 6.2h.01"})],"shape-preview":[16,1.4,n.jsx("path",{d:"M2.2 3.4h11.6v9.2H2.2zM2.2 6h11.6M4.1 4.7h.01M6 4.7h.01"})],"shape-envelope":[16,1.4,n.jsx("path",{d:"M2.2 4h11.6v8H2.2zM2.2 4.4 8 8.8l5.8-4.4"})],moon:[16,1.5,n.jsx("path",{d:"M12.9 9.7A5.3 5.3 0 0 1 6.3 3.1a5.3 5.3 0 1 0 6.6 6.6z"})],"shape-structured":[16,1.4,n.jsx("path",{d:"M4 2.6h8v10.8H4zM6.2 5.6h3.6M6.2 8h3.6M6.2 10.4h2.2"})]};function we({name:e,size:t,className:s,...r}){const[i,a,l,o]=_D[e],c=t??o??i;return n.jsx("svg",{className:s,width:c,height:c,viewBox:`0 0 ${i} ${i}`,"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:a,strokeLinecap:"round",strokeLinejoin:"round","data-icon":e,...r,children:l})}const ZN="buddi.rosterCollapsed";function LD(){try{return window.localStorage.getItem(ZN)==="1"}catch{return!1}}function FD(e){try{window.localStorage.setItem(ZN,e?"1":"0")}catch{}}function e1({agents:e,currentId:t,attention:s,onSelect:r,orientation:i="vertical",lastActivity:a,working:l,groups:o=[],currentGroupId:c=null,onSelectGroup:u,onNewGroup:h}){const d=[...e.top,...e.middle,...e.bottom],m=i==="vertical"?"right":"bottom",[p,x]=f.useState(LD),j=b=>n.jsx(zD,{agent:b,active:b.id===t,attention:s.get(b.id),side:m,onSelect:r,lastAt:(a==null?void 0:a.get(b.id))??null,working:(l==null?void 0:l.has(b.id))??!1},b.id);return n.jsxs("nav",{className:i==="vertical"?"wb-agent-rail":"wb-agent-strip","aria-label":"Agents","data-testid":"agent-rail","data-collapsed":i==="vertical"&&p?"true":void 0,children:[e.top.map(j),e.top.length>0&&e.middle.length>0?n.jsx("span",{className:"wb-agent-sep","data-testid":"agent-rail-sep","aria-hidden":"true"}):null,i==="vertical"&&!p&&e.middle.length>0?n.jsx("span",{className:"wb-roster-label",children:"Your team"}):null,n.jsxs("div",{className:"wb-agent-scroll",children:[e.middle.map(j),u&&JN(d)?n.jsxs("div",{className:"wb-groups","data-testid":"group-rail",children:[n.jsx("span",{className:"wb-agent-sep","aria-hidden":"true"}),n.jsxs("div",{className:"wb-groups-head",children:[n.jsx("span",{className:"wb-groups-label",children:"Groups"}),h?n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"New group",title:"A team of agents in one conversation",onClick:h,children:n.jsx(we,{name:"plus"})}):null]}),o.map(b=>n.jsxs("button",{type:"button",className:"wb-face wb-group-face","data-active":b.id===c?"true":void 0,"aria-current":b.id===c?"true":void 0,"aria-label":`${b.name}, ${b.members.length} agents`,onClick:()=>u(b.id),children:[n.jsx("span",{className:"wb-group-stack","aria-hidden":"true",children:b.members.slice(0,2).map(g=>{const v=d.find(w=>w.id===g);return n.jsx(bx,{className:"wb-group-chip",id:g,name:(v==null?void 0:v.name)??"?",face:v,initials:1},g)})}),n.jsxs("span",{className:"wb-face-text",children:[n.jsx("span",{className:"wb-face-name",children:b.name}),n.jsx("span",{className:"wb-face-status",children:b.members.map(g=>{var v;return((v=d.find(w=>w.id===g))==null?void 0:v.name)??g}).join(", ")})]})]},b.id))]}):u?n.jsxs("div",{className:"wb-groups","data-testid":"group-rail-hint",children:[n.jsx("span",{className:"wb-agent-sep","aria-hidden":"true"}),n.jsx("div",{className:"wb-groups-head",children:n.jsx("span",{className:"wb-groups-label",children:"Groups"})}),n.jsxs("p",{className:"wb-groups-hint",children:["A group needs two agents; ",n.jsx("a",{href:mt,children:"add a teammate"}),"."]})]}):null]}),e.bottom.map(j),i==="vertical"?n.jsx("button",{type:"button",className:"ui-icon-btn wb-roster-toggle","data-size":"sm","aria-label":p?"Show agent names":"Hide agent names","aria-pressed":p,onClick:()=>x(b=>(FD(!b),!b)),children:n.jsx(we,{name:p?"chevron-right":"chevron-left"})}):null]})}function zD({agent:e,active:t,attention:s,side:r,onSelect:i,lastAt:a=null,working:l=!1}){const o=Qd(s),c=ND(s)??(e.available?a?EO(a):e.description:e.unavailableReason??"Cannot run right now"),u=CD(s,l&&e.available),h=e.unavailableReason??"This agent cannot run on this machine right now.",d=[`${e.name} @${e.handle}`,e.available?null:"unavailable",o,u==="working"?"working now":null,t?"current":null].filter(m=>m!==null&&m!=="").join(" — ");return n.jsxs(jo,{children:[n.jsx(wo,{asChild:!0,children:n.jsxs("button",{className:"wb-face",...Ko(Ho(e)),"data-active":t?"true":void 0,"data-unavailable":e.available?void 0:"true","data-testid":`agent-face-${e.id}`,"aria-label":d,"aria-current":t?"true":void 0,disabled:!e.available,onClick:()=>e.available&&i(e.id),children:[n.jsxs("span",{className:"wb-face-frame",children:[n.jsx(bx,{className:"wb-face-mark",id:e.id,name:e.name,face:e}),u?n.jsx("span",{className:"wb-face-dot","data-state":u,"data-testid":`agent-dot-${e.id}`,"aria-hidden":"true"}):null]}),n.jsxs("span",{className:"wb-face-text","aria-hidden":"true",children:[n.jsx("span",{className:"wb-face-name",children:e.name}),n.jsx("span",{className:"wb-face-status","data-tone":o?"critical":void 0,children:c})]}),e.available?null:n.jsx("span",{className:"wb-face-out","aria-hidden":"true",children:n.jsx(we,{name:"out"})})]})}),n.jsx(yo,{children:n.jsxs(bo,{className:"ui-tip",side:r,sideOffset:8,children:[n.jsx("span",{className:"ui-tip-title",children:e.name}),n.jsx("span",{className:"ui-tip-hint",children:e.available?`@${e.handle} · ${e.model}`:h}),o?n.jsx("span",{className:"ui-tip-alert",children:UD(o)}):null]})})]})}function UD(e){return`${e.slice(0,1).toUpperCase()}${e.slice(1)}.`}function BD(e){let t=0;for(const s of e)t=(t*31+s.charCodeAt(0))%997;return t%6+1}const WD="modulepreload",HD=function(e,t){return new URL(e,t).href},Kw={},KD=function(t,s,r){let i=Promise.resolve();if(s&&s.length>0){const l=document.getElementsByTagName("link"),o=document.querySelector("meta[property=csp-nonce]"),c=(o==null?void 0:o.nonce)||(o==null?void 0:o.getAttribute("nonce"));i=Promise.allSettled(s.map(u=>{if(u=HD(u,r),u in Kw)return;Kw[u]=!0;const h=u.endsWith(".css"),d=h?'[rel="stylesheet"]':"";if(!!r)for(let x=l.length-1;x>=0;x--){const j=l[x];if(j.href===u&&(!h||j.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${u}"]${d}`))return;const p=document.createElement("link");if(p.rel=h?"stylesheet":WD,h||(p.as="script"),p.crossOrigin="",p.href=u,c&&p.setAttribute("nonce",c),document.head.appendChild(p),h)return new Promise((x,j)=>{p.addEventListener("load",x),p.addEventListener("error",()=>j(new Error(`Unable to preload CSS for ${u}`)))})}))}function a(l){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=l,window.dispatchEvent(o),!o.defaultPrevented)throw l}return i.then(l=>{for(const o of l||[])o.status==="rejected"&&a(o.reason);return t().catch(a)})},VD="buddi",GD=["core","coding","finance","garage","mail","maker","playground","research"],Yi=e=>`./mascot/${e}.png`,YD=["core"],Jm=(e,t)=>YD.includes(e)?`./mascot/anim/${e}-${t}.json`:null,qD=["🙂","📚","🧭","🦊","🛟","🌿","🛠️","🎧"],QD="Introduce yourself by name and say one thing you can do today.",JD=["Hello","A brain","What I take on","Reach me","Your assistant"],Cl=(e,t=!1)=>e.length<2?e.join(""):`${e.slice(0,-1).join(", ")}${t&&e.length>2?", and ":" and "}${e[e.length-1]}`,Jh=e=>e.charAt(0).toUpperCase()+e.slice(1),XD=["No","One","Two","Three","Four","Five","Six","Seven","Eight"],Ra=[{id:"days",title:"My days",plugins:"Weather · Calendar",line:"Weather and your calendars. A morning brief from Planner.",mate:"Planner",note:"Weather needs nothing. Calendar asks for your calendar’s private link later, on its own page."},{id:"mail",title:"My mail",plugins:"Mail Triage (built in)",line:"Mail Triage reads new mail and brings you only what needs you.",mate:"Mail Triage",note:"Mail asks for a mailbox in chapter 4."},{id:"money",title:"My money",plugins:"Finance",line:"Accounts, cards and cash flow. Ledger answers “can I afford this?”.",mate:"Ledger",note:"Finance asks for your bank on its own page."},{id:"voice",title:"Voice",plugins:"Speech",line:"Talk to me and hear me back, here and on your phone. Runs on this computer.",note:"Speech needs nothing."},{id:"code",title:"My code",plugins:"Developer",line:"Developer works in one folder you name, and shows you what it changed.",mate:"Developer",note:"Developer asks for its folder the first time you talk."},{id:"pictures",title:"Pictures",plugins:"Image",line:"Illustrator makes one image from a prompt, with an account you pick.",mate:"Illustrator",note:"Image asks which account to draw with."}],ZD=["days","mail"],Vw=[{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"}],P={tagline:"Setting up, on this Mac.",taglineElsewhere:"Setting up, on this computer.",chapters:JD,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 and proposes an agent for it. Only plugins made by buddi are installed for you; you can remove any of them later.","All three are optional. The mailbox is what “My mail” needs; the phone is how I reach you when you are away.","The persona is a plain text file the assistant grows over time. Keep it, rewrite it, or let Agent Father write one after an interview."],count:e=>`Chapter ${e} of 5`,back:"Back",change:"change",later:"Set up later",startOver:{link:"Start over",said:e=>`Starting again. What you already connected stays in Settings: ${e}.`,telegram:"Telegram",browser:"the browser"},strip:(e,t)=>`${e} · ${t}`,hello:{title:"Hi. I’m buddi.",opening:["I live on this computer and I’m about to introduce you to your first assistant. Nothing you tell me leaves this machine, except what your assistant sends to the AI you pick next.","First, what should we call you, and what time is it where you are?"],foot:"Your agents use your name in every reply, and your clock for reminders and the morning brief.",submit:"That’s me",answer:e=>e},name:{label:"Your first name",placeholder:"Sam"},clock:{label:"Your clock",hint:e=>`What this browser says. ${e} right now.`,change:"Change"},brain:{title:"Which AI should your team think with?",ask:"Pick what you already have. I test it with one small call before we go on.",submit:"Use this brain",cards:{free:{title:"Free to start, no key",line:"Ollama Cloud, one tap. Good enough to meet your assistant today.",pill:"Recommended to begin"},claude:{title:"I pay for Claude",line:"Sign in with your Claude account. Uses its extra usage."},chatgpt:{title:"I pay for ChatGPT",line:"Sign in with a code on openai.com. Uses your plan."},key:{title:"I have an API key",line:"Anthropic, OpenAI, Google AI, or another service with an address."},local:{title:"On this computer",line:"Free and private. Looking on this computer…"}},keyKinds:{label:"Which key",key:"Anthropic or OpenAI",gemini:"Google AI",service:"Another service"},claude:{label:"Claude",start:"Sign in with Claude",open:"Open the Claude sign-in page",paste:"Paste what Claude gave you",finish:"Done",waiting:"Sign in on the claude.ai page that just opened, then paste the code Claude shows you."},chatgpt:{label:"ChatGPT",codeBefore:"Here is your code: ",codeAfter:". Type it on the openai.com page that just opened and approve buddi. I’ll notice.",code:"Your code",open:"Open openai.com",again:"Try again",failed:"The sign-in did not finish. Try again."},cloud:{label:"Ollama Cloud",waiting:"Press Connect on the ollama.com page that just opened. Sign in there first if it asks. I’ll notice.",open:"Open the ollama.com page",again:"Try again"},gemini:{label:"Gemini",field:"Your Google AI key",placeholder:"Paste it here",submit:"Use this key",get:"Get a key at aistudio.google.com"},key:{field:"Your key",placeholder:"Paste it here",hint:"I can tell which AI it belongs to from the key. It stays on this computer.",submit:"Use this key",which:"Not right?",anthropic:"Anthropic",openai:"OpenAI",refused:"That key was refused. Check it and paste it again."},local:{looking:"Free and private. Looking on this computer…",found:e=>{const t=r=>r===1?"one model":`${r} models`;return`Free and private. I found ${[e.ollama!==void 0?`Ollama with ${t(e.ollama)}`:null,e.mlxh!==void 0?`mlxh with ${t(e.mlxh)}`:null].filter(Boolean).join(" and ")}; the first answer takes a minute.`},missing:"Nothing local answered; Ollama or mlxh, once installed, shows here."},mlxh:{label:"mlxh",connect:"Use mlxh",noBrain:"mlxh has no language model installed. Pull one with `mlxh pull`, then come back."},ollama:{label:"Ollama",connect:"Use Ollama",download:"Get Ollama"},model:{ask:"Which one should it think with?",label:"The model",submit:"Use this one",retry:"Try again",change:"Think with another"},checking:{key:"Checking that key…",service:"Asking the service…",ollama:"Asking the first model one small question. It can take a minute.",cloud:"Asking Ollama Cloud…",claude:"Checking with Claude…",chatgpt:"Asking ChatGPT…",gemini:"Asking Gemini…"},service:{label:"Another service",address:"Address",addressPlaceholder:"The address they gave you",key:"Key",submit:"Connect it"},works:e=>`That works. Your assistant will think with ${e}.`,worksOnFlash:e=>`That works. Google's free tier has no Pro allowance, so your assistant will think with ${e}; turn on billing at Google to use Pro.`,answer:e=>e},takeOn:{title:"What should I take on for you?",ask:"Pick a few. Each one brings a plugin and, for some, a teammate who owns that job. Skip this and I stay a plain assistant; you can add any of it later.",submit:"Take these on",none:"Just an assistant for now",nothing:"Nothing picked. I’ll be a plain assistant, and Home will offer these again.",builtIn:"Mail is built in.",nothingToFetch:"Nothing to fetch.",fetching:(e,t,s)=>`Fetching ${Cl(e)} from withbuddi.com and reading them. ${t} of ${s}.`,ready:e=>`${Cl(e)} ${e.length>1?"are":"is"} in, read and ready.`,failed:(e,t)=>`${e} did not come: ${t}.`,installing:(e,t)=>`Installing, ${e} of ${t} ready`,installed:"Installed",answer:e=>e.length===0?"Just an assistant":Jh(e.join(", ").toLowerCase())},reach:{title:"How do we reach each other?",ask:"Three things, each a minute. Do the ones you want; the rest wait in Settings.",submit:"Continue",phone:{title:"Your phone, through Telegram",line:"Scan the code with your phone and press Start. Approvals, voice notes and the morning brief land there.",setUp:"Set up Telegram",paired:"Paired",hello:"✓ That is your phone, talking to me. Approvals reach you there from now on."},mailbox:{title:"A mailbox",forTriage:"A mailbox, for Mail Triage",line:"Gmail, iCloud, Fastmail or any IMAP account. Reading only; sending always stops at a card you approve.",add:"Add a mailbox",sheet:"Add a mailbox",added:"Mailbox added",unavailable:"Mail is not ready on this computer yet. Settings → Mail can add one later."},app:{title:"buddi as an app, and a browser of its own",line:"Keep buddi in your Dock; give your assistant Chrome or its own Chromium (150 MB) so it can look at websites.",install:"Install app",installed:"App installed",chrome:"Use Chrome",chromium:"Use its Chromium",fetch:"Fetch a browser",ready:e=>e==="chrome"?"Chrome, ready":"Chromium, ready"},answer:e=>e.length===0?"Later, in Settings":Jh(e.join(", ")),done:{phone:"phone paired",mailbox:"mailbox added",app:"app and browser"}},browser:{chrome:"Your assistant will browse with Google Chrome.",chromium:"Your assistant will browse with its own Chromium.",needs:"Your assistant needs a browser of its own to look at websites. I am fetching one now, about 150 MB.",installing:"Fetching the browser…",launching:"Making sure it opens…",installed:"Installed.",failed:e=>`That did not work: ${e}`,retry:"Try again"},telegram:{sheet:"Your phone, through Telegram",how:"Two minutes: open Telegram, message @BotFather, send /newbot, paste the token it gives you here.",field:"The token",submit:"Save it",restart:"Saved. It will be ready the next time buddi starts.",scan:"Scan this with your phone and press Start.",expired:"That code has run out. I can make you another one.",newCode:"Show a new code",paired:"That is your phone, talking to me. You can close this and carry on.",close:"Done",notNow:"Not now"},assistant:{title:"Meet your assistant.",ask:"I’ve picked a name, a face and a way of working. Change any of it, or keep them.",team:e=>` Your team so far: ${Cl(e)}, waiting to be introduced.`,name:"Name",face:"A face",colour:"A colour for the face",swatch:e=>`Colour: ${e.toLowerCase()}`,mascot:e=>e==="core"?"Buddi Blob":`Buddi Blob, ${e}`,purpose:"How it works",purposeHint:"Plain text. It becomes the assistant’s file, which is yours from then on.",purposeValue:["You're not a chatbot. You're becoming someone this person can count on.","","Some starting truths:","",`- Help for real. No "Great question", no "I'd be happy to". Do the thing, then say what you did.`,"- Have a view. Prefer things, disagree when you should, say when something is a bad idea. A search engine with manners is not a colleague.","- Look before you ask. Read the file, check what you remember, try it. Come back with an answer and one question at most.","- You are a guest here. You can see messages, files and a calendar. Treat that with care, keep what you learn to yourself, and never lecture.","- Remember what matters. Names, preferences, the things they said once and expect you to keep.","- When you change how you work, say so. This file is yours to grow, and the owner should always know what it says."].join(`
87
- `),submit:"Introduce us"},restore:{offer:"I have a backup",sheet:"Restore from a backup",lede:"Pick the backup file buddi made and type its passphrase. Your agents, memory and settings come back as they were; this chapter map is skipped.",file:"Backup file",passphrase:"Passphrase",passphraseHint:"The one you typed when you turned backups on, if it was locked with one. I can’t recover it.",submit:"Restore",cancel:"Never mind",title:"Bringing your buddi back.",started:"Right. Give me a couple of minutes.",phases:{stopping:"Putting everything down for a moment.",snapshot:"Keeping a copy of what is here now, just in case.",database:"Bringing back your conversations and everything you told it to remember.",recovery:"Almost there. Nothing will run on its own until you say so.",files:"Bringing back your files.",starting:"Starting back up.",done:"That is everything.","rolled-back":"That did not work, so I put everything back the way it was.",failed:"That did not work."},welcome:e=>`Welcome back, ${e}.`,keys:"A backup never carries keys, so the AI you think with needs its key one more time."},handover:{waiting:"One moment.",looking:e=>`${e} is looking around…`,slow:"Still waking up. A brain on this computer takes a minute the first time.",silent:"Your assistant isn't answering. The AI you picked may be down; try again, or pick another brain.",again:"Pick another brain",starters:(e,t)=>[e.days?"What’s my day like?":"What can you do?",t.length>0?`Meet ${Cl(t)}`:"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=>`${XD[e]??String(e)} ${e===1?"thing":"things"} still waiting.`,waitingBody:e=>`${Jh(Cl(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 $c=null;const Gw=new Map;function e_(){return $c??($c=KD(()=>import("./lottie_light-j3HICV9o.js").then(e=>e.l),[],import.meta.url).then(e=>e.default)),$c.catch(()=>{$c=null}),$c}function t_(e){let t=Gw.get(e);return t||(t=fetch(e).then(s=>s.ok?s.text():null).catch(()=>null),Gw.set(e,t)),t}const Yw="(prefers-reduced-motion: reduce)";function t1(){const[e,t]=f.useState(()=>typeof window.matchMedia=="function"&&!window.matchMedia(Yw).matches);return f.useEffect(()=>{var i;if(typeof window.matchMedia!="function")return;const s=window.matchMedia(Yw),r=()=>t(!s.matches);return(i=s.addEventListener)==null||i.call(s,"change",r),()=>{var a;return(a=s.removeEventListener)==null?void 0:a.call(s,"change",r)}},[]),e}function Xd({role:e="core",state:t,size:s,still:r,className:i,onStillError:a}){const l=f.useRef(null),o=t1(),[c,u]=f.useState(!1),h=s==="xs"?null:Jm(e,t);return f.useEffect(()=>{if(u(!1),!o||!h)return;let d=!1,m=null;return Promise.all([e_(),t_(h)]).then(([p,x])=>{if(d||!x||!l.current)return;const j=p.loadAnimation({container:l.current,renderer:"svg",loop:!0,autoplay:!document.hidden,animationData:JSON.parse(x),rendererSettings:{preserveAspectRatio:"xMidYMid meet"}}),b=()=>{document.hidden?j.pause():j.play()};document.addEventListener("visibilitychange",b),m=()=>{document.removeEventListener("visibilitychange",b),j.destroy()},u(!0)}).catch(()=>{}),()=>{d=!0,m==null||m()}},[o,h]),n.jsx("span",{ref:l,className:i?`ui-blob ${i}`:"ui-blob","data-size":s,"data-playing":c?"true":void 0,"data-testid":"blob","data-state":t,"aria-hidden":"true",children:c?null:n.jsx("img",{src:r??Yi(e),alt:"",onError:a})})}async function qw(e){const t=new Image;t.src=e,await t.decode();const s=document.createElement("canvas");s.width=8,s.height=8;const r=s.getContext("2d");return r?(r.fillStyle="#fff",r.fillRect(0,0,8,8),r.drawImage(t,0,0,8,8),Array.from(r.getImageData(0,0,8,8).data)):null}function n1(e,t="core"){const s=t1(),r=e!==null&&n_(e,t),[i,a]=f.useState(!1);return f.useEffect(()=>{if(a(!1),!e||r||!s||!Jm(t,"idle"))return;let l=!1;return Promise.all([qw(e),qw(Yi(t))]).then(([o,c])=>{if(l||!o||!c||o.length!==c.length)return;const u=o.reduce((h,d,m)=>h+Math.abs(d-c[m]),0)/o.length;a(u<12)}).catch(()=>{}),()=>{l=!0}},[e,r,s,t]),s&&Jm(t,"idle")!==null&&(r||i)}function n_(e,t){const s=Yi(t);if(e===s)return!0;try{const r=typeof window>"u"?"http://localhost/":window.location.href;return new URL(e,r).href===new URL(s,r).href}catch{return!1}}function bx({className:e,id:t,name:s,face:r,tint:i,size:a,unavailable:l,initials:o=2}){const[c,u]=f.useState(null),h=r!=null&&r.picture&&r.picture!==c?r.picture:void 0,d=r==null?void 0:r.avatar,m=h?"image":d==null?void 0:d.kind,p=t?Ko(Ho({id:t,accent:r==null?void 0:r.accent,roles:r==null?void 0:r.roles,tools:r==null?void 0:r.tools})):void 0;return n.jsx("span",{className:e,"data-tint":p?void 0:i,"data-size":a,"data-kind":m,"data-unavailable":l?"true":void 0,...p,"aria-hidden":"true",children:h?n.jsx("img",{src:h,alt:"",onError:()=>u(h)}):(d==null?void 0:d.kind)==="image"?n.jsx("img",{src:d.url,alt:""}):(d==null?void 0:d.kind)==="emoji"?d.value:MD(s).slice(0,o)})}function Es({id:e,name:t,size:s,unavailable:r,face:i}){return n.jsx(bx,{className:"ui-avatar",id:e,tint:BD(e),name:t,size:s,unavailable:r,face:i})}function Nn({agents:e,id:t,size:s}){const r=e.find(i=>i.id===t);return n.jsx(Es,{id:t,name:(r==null?void 0:r.name)??t,size:s,unavailable:r?!r.available:!1,face:r})}const s1=f.createContext(null);function s_({picture:e,children:t}){return n.jsx(s1.Provider,{value:e??null,children:t})}function r1({size:e,anim:t}){const s=f.useContext(s1),[r,i]=f.useState(null),a=n1(t?s:null);return!s||s===r?null:n.jsx("span",{className:"ui-mascot","data-size":e,"data-testid":"mascot","aria-hidden":"true",children:t&&a?n.jsx(Xd,{state:t,still:s,className:"ui-mascot-blob",onStillError:()=>i(s)}):n.jsx("img",{src:s,alt:"",onError:()=>i(s)})})}const i1=f.createContext([]);function mr({text:e,className:t}){const s=Xm(e.replace(/\r\n/g,`
88
- `).split(`
89
- `));return n.jsx("div",{className:t??"wb-md",children:s.map((r,i)=>n.jsx(Zm,{block:r},i))})}const Qw=/^(\s*)(```|~~~)\s*([\w+-]*)\s*$/,Jw=/^(#{1,6})\s+(.*?)\s*#*\s*$/,Xw=/^\s*([-*_])(\s*\1){2,}\s*$/,Mc=/^(\s*)([-*+])\s+(.*)$/,El=/^(\s*)(\d{1,9})[.)]\s+(.*)$/,Oc=/^\s*>\s?(.*)$/,Xh=/^\s*\|.*\|\s*$/,Zw=/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/;function Xm(e){const t=[];let s=0;for(;s<e.length;){const r=e[s];if(r.trim()===""){s+=1;continue}const i=Qw.exec(r);if(i){const o=i[2],c=[];for(s+=1;s<e.length&&!new RegExp(`^\\s*${o}\\s*$`).test(e[s]);)c.push(e[s]),s+=1;s+=1,t.push({type:"code",lang:i[3]||null,text:c.join(`
90
- `)});continue}const a=Jw.exec(r);if(a){t.push({type:"h",level:a[1].length,text:a[2]}),s+=1;continue}if(Xw.test(r)){t.push({type:"hr"}),s+=1;continue}if(Oc.test(r)){const o=[];for(;s<e.length&&Oc.test(e[s]);)o.push(Oc.exec(e[s])[1]),s+=1;t.push({type:"quote",blocks:Xm(o),raw:o.join(`
91
- `)});continue}if(Xh.test(r)&&s+1<e.length&&Zw.test(e[s+1])){const o=ef(r),c=ef(e[s+1]).map(h=>{const d=h.startsWith(":"),m=h.endsWith(":");return d&&m?"center":m?"right":d?"left":null});s+=2;const u=[];for(;s<e.length&&Xh.test(e[s]);)u.push(ef(e[s])),s+=1;t.push({type:"table",head:o,rows:u,align:c});continue}if(Mc.test(r)||El.test(r)){const o=El.exec(r)??Mc.exec(r),c=El.test(r),u=o[1].length,h=c?Number(o[2]):1,d=[];for(;s<e.length;){const m=c?El.exec(e[s]):Mc.exec(e[s]);if(!m||m[1].length!==u)break;const p=[m[3]];for(s+=1;s<e.length;){const x=e[s],j=x.trim()!==""&&Zh(x)>u,b=x.trim()===""&&s+1<e.length&&e[s+1].trim()!==""&&Zh(e[s+1])>u;if(!j&&!b)break;p.push(x.trim()===""?"":x.slice(Math.min(Zh(x),u+2))),s+=1}d.push(Xm(p))}t.push({type:"list",ordered:c,start:h,items:d});continue}const l=[];for(;s<e.length;){const o=e[s];if(o.trim()===""||Qw.test(o)||Jw.test(o)||Xw.test(o)||Oc.test(o)||Mc.test(o)||El.test(o)||Xh.test(o)&&s+1<e.length&&Zw.test(e[s+1]))break;l.push(o.trim()),s+=1}l.length>0&&t.push({type:"p",text:l.join(`
92
- `)})}return t}function Zh(e){return e.length-e.trimStart().length}function ef(e){const t=e.trim().replace(/^\|/,"").replace(/\|$/,""),s=[];let r="";for(let i=0;i<t.length;i+=1){const a=t[i];if(a==="\\"&&t[i+1]==="|"){r+="|",i+=1;continue}if(a==="|"){s.push(r.trim()),r="";continue}r+=a}return s.push(r.trim()),s}function Zm({block:e}){switch(e.type){case"p":return n.jsx("p",{children:ps(e.text)});case"h":{const t=Math.min(6,Math.max(1,e.level)),s=`h${Math.min(t+2,6)}`;return n.jsx(s,{className:"wb-md-h","data-level":t,children:ps(e.text)})}case"code":return n.jsxs("div",{className:"wb-md-code-frame",children:[n.jsxs("div",{className:"wb-md-code-head",children:[n.jsx("span",{className:"wb-md-code-lang",children:e.lang??"text"}),n.jsx(ey,{text:e.text,what:"code",always:!0})]}),n.jsx("pre",{className:"wb-md-code","data-lang":e.lang??void 0,children:n.jsx("code",{children:e.text})})]});case"quote":return n.jsxs("div",{className:"wb-md-copyable",children:[n.jsx("blockquote",{children:e.blocks.map((t,s)=>n.jsx(Zm,{block:t},s))}),n.jsx(ey,{text:e.raw,what:"quote"})]});case"hr":return n.jsx("hr",{});case"list":{const t=e.items.map((s,r)=>n.jsx("li",{children:s.map((i,a)=>i.type==="p"?n.jsx(f.Fragment,{children:ps(i.text)},a):n.jsx(Zm,{block:i},a))},r));return e.ordered?n.jsx("ol",{start:e.start,children:t}):n.jsx("ul",{children:t})}case"table":return n.jsx("div",{className:"ui-table-wrap",children:n.jsxs("table",{className:"ui-table wb-md-table",children:[n.jsx("thead",{children:n.jsx("tr",{children:e.head.map((t,s)=>n.jsx("th",{style:e.align[s]?{textAlign:e.align[s]}:void 0,children:ps(t)},s))})}),n.jsx("tbody",{children:e.rows.map((t,s)=>n.jsx("tr",{children:t.map((r,i)=>n.jsx("td",{style:e.align[i]?{textAlign:e.align[i]}:void 0,children:ps(r)},i))},s))})]})})}}function ey({text:e,what:t,always:s=!1}){const[r,i]=f.useState("idle"),a=()=>{var l;if(!((l=navigator.clipboard)!=null&&l.writeText)){i("failed");return}navigator.clipboard.writeText(e).then(()=>i("done"),()=>i("failed")),window.setTimeout(()=>i("idle"),1500)};return n.jsx("button",{type:"button",className:"wb-md-copy","data-state":r,"data-always":s||void 0,"aria-label":`Copy ${t}`,title:`Copy ${t}`,onClick:a,children:r==="done"?"Copied":r==="failed"?"Select to copy":n.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 13 13","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"4.5",y:"4.5",width:"6.5",height:"6.5",rx:"1.2"}),n.jsx("path",{d:"M8.5 4.5V3a1 1 0 0 0-1-1H3a1 1 0 0 0-1 1v4.5a1 1 0 0 0 1 1h1.5"})]})})}function r_({handle:e}){const s=f.useContext(i1).find(r=>r.handle.toLowerCase()===e.toLowerCase());return s?n.jsxs(jo,{children:[n.jsx(wo,{asChild:!0,children:n.jsxs("a",{className:"wb-mention-link",href:Ve(s.id),children:["@",s.handle]})}),n.jsx(yo,{children:n.jsxs(bo,{className:"wb-agent-card",sideOffset:6,children:[n.jsx(Es,{id:s.id,name:s.name,face:s,unavailable:!s.available}),n.jsxs("span",{className:"wb-agent-card-text",children:[n.jsx("span",{className:"wb-agent-card-name",children:s.name}),n.jsx("span",{className:"wb-agent-card-desc",children:s.description}),n.jsxs("span",{className:"wb-agent-card-meta",children:[s.model,s.available?"":" · unavailable"]})]})]})})]}):n.jsxs(n.Fragment,{children:["@",e]})}const i_=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 ps(e){const t=[];let s=e,r=0;for(;s!=="";){const i=i_.exec(s);if(!i){t.push(...ty(s,r));break}i.index>0&&t.push(...ty(s.slice(0,i.index),r)),r+=100,i[2]!==void 0?t.push(n.jsx("code",{children:i[2]},r)):i[3]!==void 0?t.push(n.jsx("strong",{children:ps(i[3])},r)):i[4]!==void 0?t.push(n.jsx("strong",{children:ps(i[4])},r)):i[5]!==void 0?t.push(n.jsx("s",{children:ps(i[5])},r)):i[6]!==void 0?t.push(n.jsx("em",{children:ps(i[6])},r)):i[7]!==void 0?t.push(n.jsx("em",{children:ps(i[7])},r)):i[8]!==void 0&&i[9]!==void 0?t.push(n.jsx("a",{href:i[9],target:"_blank",rel:"noopener noreferrer",children:ps(i[8])},r)):i[10]!==void 0?t.push(n.jsx("a",{href:i[10],target:"_blank",rel:"noopener noreferrer",children:i[10]},r)):i[11]!==void 0&&t.push(n.jsx(r_,{handle:i[11]},r)),s=s.slice(i.index+i[0].length)}return t}function ty(e,t){return e.split(`
93
- `).flatMap((r,i)=>i===0?[r]:[n.jsx("br",{},`${t}-br-${i}`),r])}function a_({props:e}){return n.jsxs("div",{children:[e.title?n.jsx("h4",{className:"wb-doc-title",children:e.title}):null,e.metadata.length>0?n.jsx("dl",{className:"ui-kv wb-block",children:e.metadata.map(t=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:t.label}),n.jsx("dd",{children:zt(t.value,t.unit,null)})]},t.label))}):null,e.kind==="image"&&e.src?n.jsx("img",{src:e.src,alt:e.title??"Attached image",className:"wb-doc-image"}):e.kind==="pdf"&&e.src?n.jsx("object",{data:e.src,type:"application/pdf",className:"wb-doc-pdf",children:n.jsx("a",{href:e.src,children:"Open the PDF"})}):e.text?n.jsx("div",{className:"wb-doc",children:n.jsx(mr,{text:e.text})}):n.jsx("p",{className:"wb-empty",children:"This document came back with no body."})]})}const l_=["mail","money","calendar","people","file","chart","bell","plug","key","globe","sun","partly-cloudy","cloud","rain","drizzle","snow","storm","fog","wind","moon-clear"];function xe(e,t){if(t===""||t==="$")return e;let s=e;for(const r of t.split(".")){const i=/^([^[\]]*)((?:\[\d+\])*)$/.exec(r);if(!i)return;const[,a="",l=""]=i;if(a!==""){if(s===null||typeof s!="object")return;s=s[a]}for(const o of l.match(/\d+/g)??[]){if(!Array.isArray(s))return;s=s[Number(o)]}if(s===void 0)return}return s}function Oe(e,t){if(t)return"const"in t?t.const:xe(e,t.path)}function Bn(e){if(typeof e=="number")return Number.isFinite(e)?e:null;if(typeof e=="string"&&e.trim()!==""){const t=Number(e);return Number.isFinite(t)?t:null}return null}function Je(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):null}function Gr(e){return Array.isArray(e)?e:[]}function o_(e,t){const s=Gr(xe(e,t.points)).map(i=>{const a=Bn(xe(i,t.y)),l=Je(xe(i,t.x));return a===null||l===null?null:{x:l,y:a}}).filter(i=>i!==null),r=(t.referenceLines??[]).map(i=>{const a=Bn(Oe(e,i.value));return a===null?null:{value:a,label:i.label,tone:i.tone??"neutral"}}).filter(i=>i!==null);return{points:s,unit:t.unit??"number",currency:Je(Oe(e,t.currency)),label:Je(Oe(e,t.label)),referenceLines:r,mark:t.mark??null,shadeBelow:Bn(Oe(e,t.shadeBelow)),events:c_(e,t)}}function c_(e,t){const s=t.events;if(!s)return[];const r=[],i=(a,l)=>{const o=Je(xe(a,s.label));if(o===null)return;const c=Je(xe(a,s.at))??l;c!==null&&r.push({at:c,label:o,amount:s.amount?Bn(xe(a,s.amount)):null})};if(s.parent){for(const a of Gr(xe(e,t.points))){const l=Je(xe(a,t.x));for(const o of Gr(xe(a,s.parent)))i(o,l)}return r}for(const a of Gr(xe(e,s.path??t.points)))i(a,null);return r}function u_(e,t){const s=(t.columns??[]).map(o=>({key:o.key,label:o.label,type:o.type??"text"})),r=o=>(t.columns??[]).map(c=>{const u=xe(o,c.key);let h=null;if(c.bar){const d=Bn(Oe(o,c.bar.max))??Bn(Oe(e,c.bar.max)),m=Bn(u);if(d!==null&&d>0&&m!==null){const p=Math.max(0,Math.min(1,m/d));h={fraction:p,tone:h_(p*100,c.bar.thresholds)}}}return{value:u,type:c.type??"text",currency:Je(Oe(o,c.currency))??Je(Oe(e,c.currency)),bar:h}}),i=Gr(xe(e,t.rows)),a=t.groupBy?d_(i,t.groupBy,r):[{label:null,rows:i.map(r)}],l=(t.summary??[]).map(o=>({label:o.label,value:Oe(e,o.value),unit:o.unit??"text",currency:Je(Oe(e,o.currency)),tone:o.tone??"neutral"}));return{columns:s,groups:a,summary:l,empty:t.empty??"Nothing to show."}}function d_(e,t,s){const r=new Map;for(const i of e){const a=String(xe(i,t.key)??""),l=r.get(a);l?l.push(i):r.set(a,[i])}return[...r.entries()].map(([i,a])=>{var l;return{label:((l=t.labels)==null?void 0:l[i])??i,rows:a.map(s)}})}function h_(e,t){var r;return!t||t.length===0?"neutral":((r=[...t].sort((i,a)=>a.atLeast-i.atLeast).find(i=>e>=i.atLeast))==null?void 0:r.tone)??"neutral"}function f_(e,t){return{bars:Gr(xe(e,t.bars)).map(r=>{const i=Bn(xe(r,t.value)),a=Je(xe(r,t.category));return i===null||a===null?null:{category:a,value:i}}).filter(r=>r!==null),unit:t.unit??"number",currency:Je(Oe(e,t.currency))}}function m_(e,t){if(t.pairs)return{pairs:t.pairs.map(r=>({label:r.label,value:Oe(e,r.value),unit:r.unit??"text",currency:Je(Oe(e,r.currency)),tone:r.tone??"neutral"}))};const s=xe(e,t.from??"$");return s===null||typeof s!="object"||Array.isArray(s)?{pairs:[]}:{pairs:Object.entries(s).map(([r,i])=>({label:hn(r),value:i,unit:"text",currency:null,tone:"neutral"}))}}const p_=new Set(["good","warning","critical","neutral","accent"]),g_=new Set(l_);function ep(e){return typeof e=="string"&&g_.has(e)?e:null}function kx(e,t,s=""){const r=t.empty??"Nothing to show.",i=s.split(".")[0]??"";if(t.notice){const l=Je(xe(e,t.notice.text));if(l!==null&&l.trim()!==""){const o=t.notice.link&&i!==""?{plugin:i,page:t.notice.link.page}:null;return{tiles:[{icon:ep(t.notice.icon??"bell"),value:"",label:l.trim(),lines:[],tone:"neutral",link:o}],notice:!0,empty:r}}}return{tiles:Gr(xe(e,t.items)).map(l=>{const o=Je(xe(l,t.value))??"",c=Je(xe(l,t.label))??"";if(o===""&&c==="")return null;const u=t.tone?Je(xe(l,t.tone)):null;return{icon:ep(Oe(l,t.icon)),value:o,label:c,lines:(t.lines??[]).slice(0,2).map(h=>Je(xe(l,h))).filter(h=>h!==null&&h.trim()!==""),tone:u!==null&&p_.has(u)?u:"neutral",link:null}}).filter(l=>l!==null),notice:!1,empty:r}}function x_(e,t){const s=Je(Oe(e,t.kind)),r=s==="image"||s==="pdf"?s:"text",i=t.src?Je(xe(e,t.src)):null;return{kind:r,text:t.text?Je(xe(e,t.text)):null,src:i&&l1(i)?i:null,title:Je(Oe(e,t.title)),metadata:(t.metadata??[]).map(a=>({label:a.label,value:Oe(e,a.value),unit:a.unit??"text"}))}}function v_(e,t){const s=t.diff?xe(e,t.diff):void 0;return{diff:typeof s=="string"&&s.trim()!==""?s:null,title:Je(Oe(e,t.title)),metadata:(t.metadata??[]).map(r=>({label:r.label,value:Oe(e,r.value),unit:r.unit??"text"}))}}function j_(e,t){const s=t.output?xe(e,t.output):void 0,r=l=>{const o=l?xe(e,l):void 0;return typeof o=="number"&&Number.isInteger(o)?o:null},i=r(t.omittedBytes),a=t.elapsedMs?xe(e,t.elapsedMs):void 0;return{command:Je(Oe(e,t.command)),output:typeof s=="string"?s:null,exitCode:r(t.exitCode),elapsedMs:typeof a=="number"&&Number.isFinite(a)&&a>=0?a:null,omittedBytes:i!==null&&i>0?i:null,metadata:(t.metadata??[]).map(l=>({label:l.label,value:Oe(e,l.value),unit:l.unit??"text"}))}}const w_=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function a1(e){const t=e!==null&&typeof e=="object"&&!Array.isArray(e)?e.artifactId??e.id:e;return typeof t=="string"&&w_.test(t)?t.toLowerCase():null}function y_(e,t){return{artifactId:t.src?a1(xe(e,t.src)):null,title:Je(Oe(e,t.title)),caption:Je(Oe(e,t.caption)),...t.captionLabel?{captionLabel:Je(Oe(e,t.captionLabel))}:{}}}function ny(e){if(!l1(e))return null;let t;try{t=new URL(e,"file:///").pathname}catch{return null}const s=/^\/preview\/([A-Za-z0-9][A-Za-z0-9_.-]*)\/([A-Za-z0-9][A-Za-z0-9_.-]*)\/?$/.exec(t);return s?{plugin:s[1],name:s[2]}:null}function b_(e,t){const s=t.src?Je(xe(e,t.src)):null,r=t.port?xe(e,t.port):null,i=t.awaiting?Je(xe(e,t.awaiting)):null;return{target:s?ny(s):null,title:Je(Oe(e,t.title)),output:t.output?Je(xe(e,t.output)):null,port:typeof r=="number"&&Number.isInteger(r)&&r>0&&r<=65535?r:null,awaiting:i?ny(i):null,reloadsItself:t.reloadsItself?xe(e,t.reloadsItself)===!0:!1,ports:t.ports?k_(xe(e,t.ports)):[]}}function k_(e){const t=Gr(e).filter(s=>typeof s=="number"&&Number.isInteger(s)&&s>0&&s<=65535);return[...new Set(t)].sort((s,r)=>s-r)}function l1(e){return e.startsWith("/")&&!e.startsWith("//")}function hn(e){const t=e.replace(/[_-]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").trim().toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)}function o1(e,t){const s=e.map??{};switch(e.renderer){case"timeseries":return{renderer:"timeseries",props:o_(t,s)};case"table":return{renderer:"table",props:u_(t,s)};case"bars":return{renderer:"bars",props:f_(t,s)};case"keyvalue":return{renderer:"keyvalue",props:m_(t,s)};case"tiles":return{renderer:"tiles",props:kx(t,s,e.tool)};case"document":return{renderer:"document",props:x_(t,s)};case"diff":return{renderer:"diff",props:v_(t,s)};case"terminal":return{renderer:"terminal",props:j_(t,s)};case"image":return{renderer:"image",props:y_(t,s)};case"preview":return{renderer:"preview",props:b_(t,s)};default:return{renderer:"structured",props:{value:t}}}}var S_=Object.defineProperty,As=(e,t)=>S_(e,"name",{value:t,configurable:!0}),Sx="Dialog",[c1,LK]=Ns(Sx),[N_,jr]=c1(Sx),Nx=As(e=>{const{__scopeDialog:t,children:s,open:r,defaultOpen:i,onOpenChange:a,modal:l=!0}=e,o=f.useRef(null),c=f.useRef(null),[u,h]=Wi({prop:r,defaultProp:i??!1,onChange:a,caller:Sx}),[d,m]=f.useState(0),[p,x]=f.useState(0);return n.jsx(N_,{scope:t,triggerRef:o,contentRef:c,contentId:vs(),titleId:vs(),descriptionId:vs(),titlePresent:d>0,descriptionPresent:p>0,setTitleCount:m,setDescriptionCount:x,open:u,onOpenChange:h,onOpenToggle:f.useCallback(()=>h(j=>!j),[h]),modal:l,children:s})},"Dialog"),u1="DialogPortal",[C_,d1]=c1(u1,{forceMount:void 0}),Cx=As(e=>{const{__scopeDialog:t,forceMount:s,children:r,container:i}=e,a=jr(u1,t);return n.jsx(C_,{scope:t,forceMount:s,children:f.Children.map(r,l=>n.jsx(xr,{present:s||a.open,children:n.jsx(Kg,{asChild:!0,container:i,children:l})}))})},"DialogPortal"),tp="DialogOverlay",h1=f.forwardRef(As(function(t,s){const r=d1(tp,t.__scopeDialog),{forceMount:i=r.forceMount,...a}=t,l=jr(tp,t.__scopeDialog);return l.modal?n.jsx(xr,{present:i||l.open,children:n.jsx(A_,{...a,ref:s})}):null},"DialogOverlay")),E_=Xr("DialogOverlay.RemoveScroll"),A_=f.forwardRef(As(function(t,s){const{__scopeDialog:r,...i}=t,a=jr(tp,r),l=Xk(),o=ct(s,l);return n.jsx(lx,{as:E_,allowPinchZoom:!0,shards:[a.contentRef],children:n.jsx(jt.div,{"data-state":Tx(a.open),...i,ref:o,style:{pointerEvents:"auto",...i.style}})})},"DialogOverlayImpl")),Co="DialogContent",Ex=f.forwardRef(As(function(t,s){const r=d1(Co,t.__scopeDialog),{forceMount:i=r.forceMount,...a}=t,l=jr(Co,t.__scopeDialog);return n.jsx(xr,{present:i||l.open,children:l.modal?n.jsx(T_,{...a,ref:s}):n.jsx(R_,{...a,ref:s})})},"DialogContent")),T_=f.forwardRef(As(function(t,s){const r=jr(Co,t.__scopeDialog),i=f.useRef(null),a=ct(s,r.contentRef,i);return f.useEffect(()=>{const l=i.current;if(l)return dN(l)},[]),n.jsx(f1,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:r.open,onCloseAutoFocus:Ie(t.onCloseAutoFocus,l=>{var o;l.preventDefault(),(o=r.triggerRef.current)==null||o.focus()}),onPointerDownOutside:Ie(t.onPointerDownOutside,l=>{const o=l.detail.originalEvent,c=o.button===0&&o.ctrlKey===!0;(o.button===2||c)&&l.preventDefault()}),onFocusOutside:Ie(t.onFocusOutside,l=>l.preventDefault())})},"DialogContentModal")),R_=f.forwardRef(As(function(t,s){const r=jr(Co,t.__scopeDialog),i=f.useRef(!1),a=f.useRef(!1);return n.jsx(f1,{...t,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:l=>{var o,c;(o=t.onCloseAutoFocus)==null||o.call(t,l),l.defaultPrevented||(i.current||(c=r.triggerRef.current)==null||c.focus(),l.preventDefault()),i.current=!1,a.current=!1},onInteractOutside:l=>{var u,h;(u=t.onInteractOutside)==null||u.call(t,l),l.defaultPrevented||(i.current=!0,l.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const o=l.target;((h=r.triggerRef.current)==null?void 0:h.contains(o))&&l.preventDefault(),l.detail.originalEvent.type==="focusin"&&a.current&&l.preventDefault()}})},"DialogContentNonModal")),f1=f.forwardRef(As(function(t,s){const{__scopeDialog:r,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:l,...o}=t,c=jr(Co,r);return Fd(),n.jsx(n.Fragment,{children:n.jsx(GS,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:a,onUnmountAutoFocus:l,children:n.jsx(Wg,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionPresent?c.descriptionId:void 0,"aria-labelledby":c.titlePresent?c.titleId:void 0,"data-state":Tx(c.open),...o,ref:s,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})},"DialogContentImpl")),I_="DialogTitle",Ax=f.forwardRef(As(function(t,s){const{__scopeDialog:r,...i}=t,a=jr(I_,r),{setTitleCount:l}=a;return Tn(()=>(l(o=>o+1),()=>l(o=>o-1)),[l]),n.jsx(jt.h2,{id:a.titleId,...i,ref:s})},"DialogTitle")),P_="DialogClose",m1=f.forwardRef(As(function(t,s){const{__scopeDialog:r,...i}=t,a=jr(P_,r);return n.jsx(jt.button,{type:"button",...i,ref:s,onClick:Ie(t.onClick,()=>a.onOpenChange(!1))})},"DialogClose"));function Tx(e){return e?"open":"closed"}As(Tx,"getState");const $_=5;function le(e,t,s){const[r,i]=f.useState(void 0),[a,l]=f.useState(null),[o,c]=f.useState(!0),[u,h]=f.useState(0),[d,m]=f.useState(0),p=f.useRef(e);return p.current=e,f.useEffect(()=>{let x=!1;return c(!0),p.current().then(j=>{x||(i(j),l(null),m(0))}).catch(j=>{x||(l(j instanceof pe?j.message:String(j)),m(b=>b+1))}).finally(()=>{x||c(!1)}),()=>{x=!0}},[...t,u]),f.useEffect(()=>{if(!s||d>=$_)return;const x=window.setTimeout(()=>h(j=>j+1),s*2**d);return()=>window.clearTimeout(x)},[s,d,u]),{data:r,error:a,loading:o,reload:()=>{m(0),h(x=>x+1)}}}const p1={width:480,height:160,top:10,right:10,bottom:22,left:40},g1={width:1200,height:180,top:10,right:40,bottom:22,left:40};function M_({xs:e,series:t}){const s=g1,r=s.width-s.left-s.right,i=s.height-s.top-s.bottom,a=L=>L.filter(E=>E!==null&&Number.isFinite(E)),l=t.filter(L=>L.type!=="bar"),o=t.filter(L=>L.type==="bar"),c=l.flatMap(L=>a(L.values)),u=c.length>0?Math.min(...c):0,h=c.length>0?Math.max(...c):1;let d=u,m=h;if(d===m)d-=1,m+=1;else{const L=(m-d)*.08;d-=L,m+=L}const p=L=>ss(s.top+i-(L-d)/(m-d)*i),x=o.length>0&&o.every(L=>L.unit==="percent"),j=x?100:Math.max(1,...o.flatMap(L=>a(L.values))),b=L=>ss(s.top+i-Math.max(0,L)/j*i),g=e.length,v=g>0?r/g:r,w=L=>ss(s.left+v*(L+.5)),y=t.map(L=>{if(L.type==="bar")return"";let E="M";const $=[];return L.values.forEach((_,B)=>{if(_===null||!Number.isFinite(_)){E="M";return}$.push(`${E}${w(B)},${p(_)}`),E="L"}),$.join(" ")}),N=[],k=v*.6/Math.max(1,o.length),S=s.height-s.bottom;let C=0;t.forEach((L,E)=>{if(L.type!=="bar")return;const $=C++;L.values.forEach((_,B)=>{if(_===null||!Number.isFinite(_)||_<=0)return;const M=b(_);N.push({series:E,index:B,x:ss(w(B)-v*.3+k*$),y:M,width:ss(k),height:ss(S-M)})})});const I=c.length>0?Yu(u,h,2).map(L=>({value:L,y:p(L)})):[],A=o.length===0?[]:(x?[0,50,100]:Yu(0,j,2)).map(L=>({value:L,y:b(L),percent:x})),O=Math.max(1,Math.ceil(g/8)),z=e.flatMap((L,E)=>E%O===0?[{index:E,x:w(E)}]:[]);return{lines:y,bars:N,targetY:null,ticks:I,xLabels:z,rightTicks:A}}function O_({xs:e,series:t,type:s="line",target:r=null}){const i=p1,a=i.width-i.left-i.right,l=i.height-i.top-i.bottom,o=t.flatMap(w=>w.values.filter(y=>y!==null&&Number.isFinite(y)));r!==null&&Number.isFinite(r)&&o.push(r),s==="bar"&&o.push(0);let c=o.length>0?Math.min(...o):0,u=o.length>0?Math.max(...o):1;if(c===u)c-=1,u+=1;else if(s==="line"){const w=(u-c)*.08;c-=w,u+=w}const h=w=>ss(i.top+l-(w-c)/(u-c)*l),d=e.length,m=d>0?a/d:a,p=w=>ss(s==="bar"?i.left+m*(w+.5):i.left+(d<=1?a/2:w/(d-1)*a)),x=s==="line"?t.map(w=>{let y="M";const N=[];return w.values.forEach((k,S)=>{if(k===null||!Number.isFinite(k)){y="M";return}N.push(`${y}${p(S)},${h(k)}`),y="L"}),N.join(" ")}):[],j=[];if(s==="bar"&&d>0){const w=m*.7,y=w/Math.max(1,t.length),N=h(0);t.forEach((k,S)=>{k.values.forEach((C,I)=>{if(C===null||!Number.isFinite(C))return;const A=h(C);j.push({series:S,index:I,x:ss(i.left+m*I+(m-w)/2+y*S),y:Math.min(A,N),width:ss(y),height:ss(Math.abs(N-A))})})})}const g=(o.length>0?Yu(Math.min(...o),Math.max(...o),2):[]).map(w=>({value:w,y:h(w)})),v=d===0?[]:d===1?[0]:d<5?[0,d-1]:[0,Math.floor((d-1)/2),d-1];return{lines:x,bars:j,targetY:r!==null&&Number.isFinite(r)?h(r):null,ticks:g,xLabels:v.map(w=>({index:w,x:p(w)}))}}function D_(e){const t=e.formatX??(o=>o),s=e.formatY??(o=>String(o)),r=e.xs.length;if(r===0)return`${e.label??"Chart"}: nothing recorded yet.`;const i=r===1?`on ${t(e.xs[0])}`:`from ${t(e.xs[0])} to ${t(e.xs[r-1])}`,a=e.series.map(o=>{const c=o.values.filter(h=>h!==null&&Number.isFinite(h));if(c.length===0)return`${o.label}: no values`;const u=c[c.length-1];return`${o.label}: latest ${s(u)}, lowest ${s(Math.min(...c))}, highest ${s(Math.max(...c))}`}),l=e.target!==null&&e.target!==void 0&&Number.isFinite(e.target)?` Target ${s(e.target)}.`:"";return`${e.label??"Chart"}, ${r} ${r===1?"point":"points"} ${i}. ${a.join("; ")}.${l}`}function __({xs:e,series:t,type:s="line",target:r=null,label:i,formatX:a=o=>o,formatY:l=o=>String(o)}){const o=s==="mixed",c=o?g1:p1,u=o?M_({xs:e,series:t}):O_({xs:e,series:t,type:s,target:r}),h=D_({xs:e,series:t,target:r,...i?{label:i}:{},formatX:a,formatY:l});return n.jsxs("figure",{className:"ui-chart","data-type":s,children:[n.jsxs("svg",{viewBox:`0 0 ${c.width} ${c.height}`,"aria-hidden":"true",focusable:"false","data-testid":"chart-svg",children:[u.ticks.map(d=>n.jsxs("g",{children:[n.jsx("line",{className:"ui-chart-grid",x1:c.left,x2:c.width-c.right,y1:d.y,y2:d.y}),n.jsx("text",{x:c.left-6,y:d.y,textAnchor:"end",dominantBaseline:"middle",children:l(d.value)})]},d.value)),(u.rightTicks??[]).map(d=>n.jsx("text",{x:c.width-c.right+6,y:d.y,textAnchor:"start",dominantBaseline:"middle",children:d.percent?`${d.value}%`:l(d.value)},`r-${d.value}`)),n.jsx("line",{className:"ui-chart-axis",x1:c.left,x2:c.width-c.right,y1:c.height-c.bottom,y2:c.height-c.bottom}),u.bars.map(d=>n.jsx("rect",{className:"ui-chart-bar","data-series":d.series,x:d.x,y:d.y,width:d.width,height:d.height},`${d.series}-${d.index}`)),u.lines.map((d,m)=>d?n.jsx("path",{className:"ui-chart-line","data-series":m,d},m):null),u.targetY!==null?n.jsx("line",{className:"ui-chart-target","data-testid":"chart-target",x1:c.left,x2:c.width-c.right,y1:u.targetY,y2:u.targetY}):null,u.xLabels.map(d=>n.jsx("text",{x:d.x,y:c.height-6,textAnchor:o?"middle":u.xLabels.length>1&&d.index===0?"start":d.index===e.length-1&&e.length>1?"end":"middle",children:a(e[d.index])},d.index))]}),n.jsx("figcaption",{className:"sr-only",children:h}),t.length>1?n.jsx("ul",{className:"ui-chart-legend","aria-hidden":"true",children:t.map((d,m)=>n.jsx("li",{"data-series":m,"data-type":o?d.type??"line":void 0,children:d.label},d.label))}):null]})}function ss(e){return Math.round(e*10)/10}function ui(...e){return e.filter(Boolean).join(" ")}function R({variant:e,size:t,className:s,type:r="button",...i}){return n.jsx("button",{type:r,className:ui("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":t,...i})}function Zt({variant:e,size:t,className:s,...r}){return n.jsx("a",{className:ui("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":t,...r})}function Q({children:e,align:t,valign:s,className:r}){return n.jsx("div",{className:ui("ui-toolbar",r),"data-align":t,"data-valign":s,children:e})}function en(){return n.jsx("span",{className:"ui-toolbar-spacer"})}function ee({label:e,hint:t,inline:s,grow:r,wide:i,group:a,action:l,after:o,children:c}){const u=f.useId();return n.jsxs("div",{className:"ui-field","data-inline":s?"true":void 0,"data-grow":r?"true":void 0,"data-wide":i?"true":void 0,children:[l?n.jsxs("div",{className:"ui-field-row",children:[n.jsxs("label",{className:"ui-field-control",children:[n.jsx("span",{className:"ui-field-label",children:e}),c]}),l]}):a?n.jsxs("div",{className:"ui-field-control",role:"group","aria-labelledby":u,children:[n.jsx("span",{className:"ui-field-label",id:u,children:e}),c]}):n.jsxs("label",{className:"ui-field-control",children:[n.jsx("span",{className:"ui-field-label",children:e}),c]}),t?n.jsx("span",{className:"ui-field-hint",children:t}):null,o]})}function bs({children:e,dense:t,columns:s}){return n.jsx("div",{className:"ui-formgrid","data-dense":t?"true":void 0,"data-columns":s===3?"3":void 0,children:e})}function ge({tone:e,mono:t,dot:s,children:r,className:i,title:a}){return n.jsxs("span",{className:ui("ui-pill",t&&"mono",i),"data-tone":e,title:a,children:[s?n.jsx("span",{className:"ui-pill-dot","aria-hidden":"true"}):null,r]})}function Ia({children:e}){return n.jsx("span",{className:"ui-tag",children:e})}function Vo({state:e}){const t=e==="succeeded"||e==="approved"||e==="fired"||e==="running"||e==="leased"?"good":e==="failed"||e==="rejected"||e==="unknown"||e==="error"||e==="refused"?"critical":e==="pending"||e==="suspended"||e==="expired"||e==="paused"?"warning":void 0;return n.jsx(ge,{tone:t,children:e})}function H({tone:e,title:t,children:s,role:r,action:i}){return i?n.jsx("div",{className:"ui-notice","data-tone":e,role:r,children:n.jsxs("div",{className:"ui-notice-row",children:[n.jsxs("div",{className:"ui-notice-body",children:[t?n.jsx("div",{className:"ui-notice-title",children:t}):null,s]}),i]})}):n.jsxs("div",{className:"ui-notice","data-tone":e,role:r,children:[t?n.jsx("div",{className:"ui-notice-title",children:t}):null,s]})}function se({message:e}){return e?n.jsx(H,{tone:"critical",role:"alert",children:e}):null}function oe({mascot:e,warm:t,title:s,action:r,children:i}){return t||s?n.jsxs("div",{className:"ui-empty","data-warm":t?"true":void 0,children:[s?n.jsx("div",{className:"ui-empty-title",children:s}):null,n.jsx("div",{children:i}),r]}):e?n.jsxs("div",{className:"ui-empty","data-mascot":"true",children:[n.jsx(r1,{size:"sm"}),n.jsx("p",{children:i})]}):n.jsx("p",{className:"ui-empty",children:i})}function tn({icon:e,title:t,action:s,children:r}){return n.jsxs("div",{className:"ui-empty-state",children:[e?n.jsx("span",{className:"ui-empty-state-icon",children:typeof e=="string"?n.jsx(we,{name:e}):e}):null,n.jsx("div",{className:"ui-empty-state-title",children:t}),r?n.jsx("p",{className:"ui-empty-state-line",children:r}):null,s?n.jsx("div",{className:"ui-empty-state-action",children:s}):null]})}function L_({children:e}){return n.jsx("div",{className:"ui-page",children:e})}function Zd({title:e,lede:t,actions:s,before:r}){return n.jsxs("header",{className:"ui-page-head",children:[n.jsxs("div",{className:"ui-page-head-row",children:[n.jsxs("h2",{className:"ui-page-title",children:[r,n.jsx("span",{children:e})]}),s?n.jsx("div",{className:"ui-page-actions",children:s}):null]}),t?n.jsx("p",{className:"ui-page-lede",children:t}):null]})}function yn({embedded:e,title:t,lede:s,actions:r,children:i}){return e?n.jsxs("div",{className:"ui-stack","data-gap":"lg",children:[r?n.jsx("div",{className:"ui-toolbar","data-align":"end",children:r}):null,i]}):n.jsxs(L_,{children:[n.jsx(Zd,{title:t,lede:s,actions:r}),i]})}function te({title:e,aside:t,actions:s,panel:r,flush:i,foot:a,children:l}){const o=e||t||s?n.jsxs("div",{className:"ui-section-head",children:[e?n.jsx("h3",{className:"ui-section-title",children:e}):n.jsx("span",{}),t||s?n.jsxs("div",{className:"ui-section-side",children:[t?n.jsx("span",{className:"ui-section-aside",children:t}):null,s?n.jsx("div",{className:"ui-section-actions",children:s}):null]}):null]}):null;return n.jsxs("section",{className:"ui-section","data-panel":r?"true":void 0,children:[o,r?n.jsxs("div",{className:"ui-panel","data-flush":i?"true":void 0,children:[l,a?n.jsx("div",{className:"ui-panel-foot",children:a}):null]}):n.jsxs(n.Fragment,{children:[l,a?n.jsx("div",{className:"ui-toolbar","data-align":"end",children:a}):null]})]})}function qe({title:e,tool:t,actions:s,flush:r,children:i}){return n.jsxs("section",{className:"ui-panel","data-flush":r?"true":void 0,children:[e||t||s?n.jsxs("header",{className:"ui-panel-head",children:[e?n.jsx("h3",{className:"ui-panel-title",children:e}):n.jsx("span",{}),t?n.jsx("span",{className:"ui-panel-tool",children:t}):null,s?n.jsx("div",{className:"ui-panel-actions",children:s}):null]}):null,i]})}function ks({tone:e,title:t,meta:s,actions:r,children:i,foot:a,onClick:l,label:o,as:c="div"}){const u=l?{"data-interactive":"true",tabIndex:0,"aria-label":o,onClick:l,onKeyDown:h=>{h.target!==h.currentTarget||h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),l())}}:{};return n.jsxs(c,{className:"ui-card","data-tone":e,...u,children:[t||s||r?n.jsxs("div",{className:"ui-card-head",children:[t?n.jsx("h3",{className:"ui-card-title",children:t}):null,s,r?n.jsx("div",{className:"ui-card-actions",children:r}):null]}):null,i,a?n.jsx("div",{className:"ui-card-foot",children:a}):null]})}function J({gap:e,divided:t,children:s}){return n.jsx("div",{className:"ui-stack","data-gap":e,"data-divided":t?"true":void 0,children:s})}function F_({children:e}){return n.jsx("div",{className:"ui-row",children:e})}function eh({inline:e,children:t}){return n.jsx("div",{className:"ui-stats","data-inline":e?"true":void 0,children:t})}function Fs({label:e,value:t,note:s,tone:r,size:i}){return n.jsxs("div",{className:"ui-stat",children:[n.jsx("div",{className:"ui-stat-k",children:e}),n.jsx("div",{className:"ui-stat-v","data-tone":r,"data-size":i,children:t}),s?n.jsx("div",{className:"ui-stat-n",children:s}):null]})}function Vt({items:e}){return n.jsx("dl",{className:"ui-kv",children:e.map((t,s)=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:t.label}),n.jsx("dd",{children:t.value})]},t.key??s))})}function Pn({children:e}){return n.jsx("div",{className:"ui-table-wrap",children:n.jsx("table",{className:"ui-table",children:e})})}function x1({value:e,label:t}){const s=Math.max(0,Math.min(100,Math.round(Number.isFinite(e)?e:0)));return n.jsx("div",{className:"ui-progress",role:"progressbar","aria-label":t,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":s,"aria-valuetext":`${s}%`,children:n.jsx("div",{className:"ui-progress-fill",style:{inlineSize:`${s}%`}})})}function xt({children:e,label:t}){return n.jsx("pre",{className:"ui-code","aria-label":t,children:e})}function $t({summary:e,boxed:t,open:s,className:r,onToggle:i,children:a}){return n.jsxs("details",{className:ui("ui-details",r),"data-boxed":t?"true":void 0,open:s,onToggle:i?l=>i(l.currentTarget.open):void 0,children:[n.jsx("summary",{children:e}),a]})}function wt({title:e,onClose:t,size:s,foot:r,children:i}){return n.jsx(Nx,{open:!0,onOpenChange:a=>{a||t()},children:n.jsxs(Cx,{children:[n.jsx(h1,{className:"ui-sheet-overlay"}),n.jsxs(Ex,{className:"ui-sheet","data-size":s,"aria-describedby":void 0,children:[n.jsxs("div",{className:"ui-sheet-head",children:[n.jsx(Ax,{className:"ui-sheet-title",children:e}),n.jsx(m1,{asChild:!0,children:n.jsx(R,{size:"sm",children:"Close"})})]}),i,r?n.jsx("div",{className:"ui-sheet-foot",children:r}):null]})]})})}function Qu({title:e,onClose:t,foot:s,children:r}){return n.jsx(Nx,{open:!0,onOpenChange:i=>{i||t()},children:n.jsxs(Cx,{children:[n.jsx(h1,{className:"ui-sheet-overlay","data-layer":"modal"}),n.jsxs(Ex,{className:"ui-modal",role:"alertdialog","aria-describedby":void 0,children:[n.jsx(Ax,{className:"ui-modal-title",children:e}),r,s?n.jsx("div",{className:"ui-modal-foot",children:s}):null]})]})})}function z_({label:e,items:t}){const s=i=>i.stopPropagation(),r=f.useRef(!1);return n.jsxs(Kd,{modal:!1,onOpenChange:i=>{i&&(r.current=!1)},children:[n.jsx(Vd,{asChild:!0,children:n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":e,title:e,onClick:s,children:n.jsx(we,{name:"more"})})}),n.jsx(Wo,{children:n.jsx(Gd,{className:"ui-menu",align:"end",sideOffset:4,onClick:s,onKeyDown:s,onCloseAutoFocus:i=>{r.current&&i.preventDefault()},children:t.map((i,a)=>i?i==="separator"?n.jsx(Mr,{className:"ui-menu-sep"},`sep-${a}`):n.jsxs(Ei,{className:"ui-menu-item","data-tone":i.tone,onSelect:()=>{r.current=!0,i.onSelect()},children:[n.jsx("span",{children:i.label}),i.hint?n.jsx("span",{className:"ui-menu-item-hint",children:i.hint}):null]},a):null)})})]})}function U_({title:e,actions:t,onClose:s,onCloseAutoFocus:r,onOpenAutoFocus:i,label:a,children:l}){return n.jsx(Nx,{open:!0,modal:!1,onOpenChange:o=>{o||s()},children:n.jsx(Cx,{children:n.jsxs(Ex,{className:"ui-dock","aria-describedby":void 0,...a?{"aria-label":a}:{},onInteractOutside:o=>o.preventDefault(),...r?{onCloseAutoFocus:r}:{},...i?{onOpenAutoFocus:i}:{},children:[n.jsxs("div",{className:"ui-dock-head",children:[n.jsx(Ax,{className:"ui-dock-title",children:e}),n.jsxs("div",{className:"ui-dock-actions",children:[t,n.jsx(m1,{asChild:!0,children:n.jsx(R,{size:"sm",variant:"ghost",children:"Close"})})]})]}),n.jsx("div",{className:"ui-dock-body",children:l})]})})})}function Go({level:e,label:t,children:s}){return n.jsx("nav",{className:"ui-tabs","data-level":e,"aria-label":t,children:s})}function Ha({href:e,active:t,count:s,onClick:r,children:i}){return n.jsxs("a",{className:"ui-tab",href:e,"aria-current":t?"page":void 0,onClick:r,children:[i,s?n.jsx("span",{className:"ui-count",children:s}):null]})}function ls({label:e,options:t,value:s,onChange:r}){return n.jsx("div",{className:"ui-segment",role:"radiogroup","aria-label":e,children:t.map(i=>n.jsx("button",{type:"button",role:"radio",className:"ui-tab","aria-checked":i.value===s,onClick:()=>r(i.value),children:i.label},i.value))})}function At({children:e}){return n.jsx("div",{className:"ui-list",children:e})}function Tt({href:e,onClick:t,lead:s,title:r,sub:i,side:a,dimmed:l,label:o}){const c=n.jsxs(n.Fragment,{children:[s,n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title",children:r}),i?n.jsx("span",{className:"ui-list-sub",children:i}):null]}),a?n.jsx("span",{className:"ui-list-side",children:a}):null]}),u=l?"true":void 0;return e?n.jsx("a",{className:"ui-list-row","data-dimmed":u,href:e,onClick:t?h=>{h.preventDefault(),t()}:void 0,children:c}):t?n.jsx("div",{className:"ui-list-row","data-interactive":"true","data-dimmed":u,tabIndex:0,"aria-label":o,onClick:t,onKeyDown:h=>{h.target!==h.currentTarget||h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),t())},children:c}):n.jsx("div",{className:"ui-list-row","data-dimmed":u,children:c})}function v1({href:e,onClick:t,current:s,lead:r,title:i,meta:a,sub:l,snippet:o,side:c}){return n.jsxs("a",{className:"ui-pick",href:e,"aria-current":s?"true":void 0,onClick:t?u=>{u.preventDefault(),t()}:void 0,children:[r?n.jsx("span",{className:"ui-pick-lead",children:r}):null,n.jsxs("span",{className:"ui-pick-main",children:[n.jsxs("span",{className:"ui-pick-top",children:[n.jsx("span",{className:"ui-pick-title",children:i}),a?n.jsx("span",{className:"ui-pick-meta",children:a}):null]}),l||c?n.jsxs("span",{className:"ui-pick-line",children:[l?n.jsx("span",{className:"ui-pick-sub",children:l}):null,c?n.jsx("span",{className:"ui-pick-side",children:c}):null]}):null,o?n.jsx("span",{className:"ui-pick-snippet",children:o}):null]})]})}function j1({list:e,detail:t,empty:s,label:r,className:i}){return n.jsxs("div",{className:ui("ui-split",i),"data-open":t?"true":void 0,children:[n.jsx("section",{className:"ui-split-list","aria-label":r,children:e}),n.jsx("section",{className:"ui-split-detail","data-empty":t?void 0:"true",children:t??n.jsx("p",{className:"ui-empty ui-split-empty",children:s})})]})}function Ju({children:e,onRemove:t,label:s,disabled:r}){return n.jsxs("span",{className:"ui-chip",children:[e,n.jsx("button",{type:"button",className:"ui-chip-x","aria-label":`Remove ${s}`,onClick:t,disabled:r,children:"×"})]})}const B_=8;function W_({label:e,options:t,value:s,onChange:r,max:i,disabled:a,id:l}){const[o,c]=f.useState(!1),[u,h]=f.useState(""),[d,m]=f.useState(0),p=f.useRef(null),x=f.useRef(null),j=f.useRef(null),b=f.useRef(null),g=f.useId(),v=E=>{var $;return(($=t.find(_=>_.value===E))==null?void 0:$.label)??E},w=i!==void 0&&s.length>=i,y=t.filter(E=>!s.includes(E.value)),N=t.length>B_,k=u.trim().toLowerCase(),S=k===""?y:y.filter(E=>E.label.toLowerCase().includes(k)),C=Math.min(d,Math.max(0,S.length-1)),I=E=>{var $;c(!1),h(""),m(0),E&&(($=x.current)==null||$.focus())};f.useEffect(()=>{var $;if(!o)return;($=N?j.current:b.current)==null||$.focus();const E=_=>{p.current&&!p.current.contains(_.target)&&I(!1)};return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[o,N]);const A=E=>{const $=[...s,E];r($),h(""),m(0);const _=i!==void 0&&$.length>=i;(_||$.length>=t.length)&&I(!_)},O=E=>{if(E.key==="Escape")E.preventDefault(),I(!0);else if(E.key==="ArrowDown")E.preventDefault(),m(S.length===0?0:(C+1)%S.length);else if(E.key==="ArrowUp")E.preventDefault(),m(S.length===0?0:(C-1+S.length)%S.length);else if(E.key==="Enter"){E.preventDefault();const $=S[C];$&&A($.value)}else E.key==="Backspace"&&u===""&&s.length>0&&(E.preventDefault(),r(s.slice(0,-1)))},z=E=>`${g}-${E}`,L=o&&S.length>0?z(C):void 0;return n.jsxs("div",{className:"ui-chippicker",ref:p,id:l,children:[s.map(E=>n.jsx(Ju,{label:v(E),disabled:a,onRemove:()=>r(s.filter($=>$!==E)),children:v(E)},E)),n.jsxs("div",{className:"ui-chippicker-add",children:[n.jsx("button",{ref:x,type:"button",className:"ui-btn","data-size":"sm","data-variant":"ghost","aria-haspopup":"listbox","aria-expanded":o,"aria-controls":o?g:void 0,disabled:a||w||y.length===0,onClick:()=>o?I(!1):c(!0),children:"Add…"}),o?n.jsxs("div",{className:"ui-menu ui-chippicker-menu",onKeyDown:O,children:[N?n.jsx("input",{ref:j,type:"search",className:"ui-chippicker-filter","aria-label":`Filter ${e}`,"aria-controls":g,"aria-activedescendant":L,value:u,onChange:E=>{h(E.target.value),m(0)}}):null,n.jsxs("div",{ref:b,id:g,role:"listbox","aria-multiselectable":"true","aria-label":e,"aria-activedescendant":N?void 0:L,tabIndex:N?-1:0,className:"ui-chippicker-list",children:[S.map((E,$)=>n.jsx("div",{id:z($),role:"option","aria-selected":"false",className:"ui-menu-item","data-highlighted":$===C?"":void 0,onMouseEnter:()=>m($),onMouseDown:_=>_.preventDefault(),onClick:()=>A(E.value),children:E.label},E.value)),S.length===0?n.jsx("p",{className:"ui-menu-empty",children:"Nothing matches"}):null]})]}):null]})]})}function H_({label:e,options:t,value:s,onChange:r}){return n.jsx("div",{className:"ui-filter-chips",role:"group","aria-label":e,children:t.map(i=>n.jsx("button",{type:"button",className:"ui-btn ui-filter-chip","data-size":"sm","aria-pressed":i.value===s,onClick:()=>r(i.value),children:i.label},i.value))})}function w1({label:e,value:t,onChange:s,placeholder:r,grow:i}){return n.jsx("span",{className:"ui-search","data-grow":i?"true":void 0,children:n.jsx("input",{type:"search","aria-label":e,value:t,placeholder:r,onChange:a=>s(a.target.value)})})}function Ka({svg:e,icon:t="plug",letter:s,size:r}){return n.jsx("span",{className:"ui-app-icon","data-size":r,"data-tone":e||s?"accent":void 0,"aria-hidden":"true",children:e?n.jsx("span",{className:"ui-app-icon-svg",dangerouslySetInnerHTML:{__html:e}}):s?n.jsx("span",{className:"ui-app-icon-letter",children:s}):n.jsx(we,{name:t})})}function y1({items:e,label:t="Where this is",inline:s}){const r=e.map((i,a)=>{const l=i.key??String(a);if(i.current)return n.jsx("span",{className:"ui-crumb","aria-current":"page",children:i.label},l);const o=i.href?n.jsx("a",{className:"ui-crumb",href:i.href,onClick:i.onClick?c=>{var u;c.preventDefault(),(u=i.onClick)==null||u.call(i)}:void 0,children:i.label}):n.jsx("button",{type:"button",className:"ui-crumb",onClick:i.onClick,children:i.label});return n.jsxs("span",{className:"ui-crumb-step",children:[o,n.jsx(we,{name:"chevron-right",size:12})]},l)});return s?n.jsx("span",{className:"ui-crumbs","aria-label":t,children:r}):n.jsx("nav",{className:"ui-crumbs","aria-label":t,children:r})}function b1({main:e,filters:t,filtersOpen:s,onToggleFilters:r,active:i,chips:a,actions:l,onSubmit:o,label:c}){return n.jsxs("form",{className:"ui-panel ui-searchbar",role:"search","aria-label":c,onSubmit:u=>{u.preventDefault(),o()},children:[n.jsxs("div",{className:"ui-searchbar-row",children:[e?n.jsx("div",{className:"ui-searchbar-main",children:e}):null,t&&r?n.jsxs(R,{"aria-expanded":s===!0,"aria-pressed":s===!0,onClick:r,children:["Filters",i?n.jsx("span",{className:"ui-count",children:i}):null]}):null,!r&&t?n.jsx("div",{className:"ui-searchbar-inline",children:t}):null,l?n.jsx("div",{className:"ui-searchbar-actions",children:l}):null]}),t&&r&&s?n.jsx("div",{className:"ui-searchbar-filters",children:t}):null,a?n.jsx("div",{className:"ui-searchbar-chips",children:a}):null]})}function Xu({size:e}){return n.jsx("span",{className:"ui-mark","data-size":e,"aria-hidden":"true",children:"b"})}function k1({quiet:e,still:t,className:s,children:r}){return n.jsx("div",{className:ui("ui-fieldbg",s),"data-quiet":e?"true":void 0,"data-still":t?"true":void 0,children:r})}function K_({dock:e,className:t,children:s}){return n.jsxs("div",{className:ui("ui-float",t),children:[n.jsx("div",{className:"ui-float-body",children:s}),e?n.jsx("div",{className:"ui-float-dock",children:e}):null]})}function V_(e){const t={};for(const s of e??[])t[s.key]=s.default;return t}function Rx(e){const[t,s]=f.useState({}),r=e??[],i={...V_(r),...t};return r.length===0?{values:void 0,controls:null}:{values:i,controls:n.jsx("div",{className:"ui-choices",children:r.map(a=>n.jsx(ee,{label:a.label,inline:!0,children:n.jsx("select",{value:i[a.key],onChange:l=>s(o=>({...o,[a.key]:l.target.value})),children:a.options.map(l=>n.jsx("option",{value:l,children:l},l))})},a.key))})}}function G_({props:e,timezone:t="UTC",onDecided:s}){var w;const[r,i]=f.useState(null),[a,l]=f.useState(null),[o,c]=f.useState(!1),[u,h]=f.useState(null);f.useEffect(()=>{let y=!1;return i(null),l(null),T.approval(e.approvalId).then(N=>{y||i(N)}).catch(N=>{y||l(N instanceof pe?N.message:String(N))}),()=>{y=!0}},[e.approvalId]);const{values:d,controls:m}=Rx(r==null?void 0:r.choices),p=(y,N)=>{h(y),l(null),(d&&y==="approve"?T.decide(e.approvalId,y,N,d):T.decide(e.approvalId,y,N)).then(k=>{i(k.action),s==null||s(k.action)}).catch(k=>l(k instanceof pe?k.message:String(k))).finally(()=>h(null))};if(a&&!r)return n.jsx("p",{className:"wb-empty",children:a});if(!r)return n.jsx("p",{className:"wb-empty",children:"Loading the envelope…"});const x=r.state==="pending",j=(w=r.permissionScopes)==null?void 0:w.includes("always"),b=Y_(r),g=(r.preview??"").split(`
94
- `).length>12||(r.preview??"").length>900,v=[r.decidedBy?`by ${r.decidedBy}`:"",r.decidedVia?`via ${r.decidedVia}`:""].filter(Boolean).join(" ");return n.jsxs("div",{className:"wb-envelope",children:[n.jsxs("div",{className:"envelope",children:[n.jsxs("dl",{className:"envelope-head",children:[n.jsx("dt",{children:"Action"}),n.jsx("dd",{className:"wb-envelope-action",children:r.tool.split(".").map(y=>hn(y)).join(" · ")}),n.jsx("dt",{children:"Status"}),n.jsxs("dd",{children:[x?n.jsx(ge,{tone:"warning",dot:!0,children:"waiting for you"}):n.jsx(Vo,{state:r.state}),!x&&v?n.jsxs("span",{className:"wb-envelope-note",children:[" ",v]}):null]}),n.jsx("dt",{children:x?"Expires":"Decided"}),n.jsx("dd",{children:Be(x?r.expiresAt:r.decidedAt,t)})]}),n.jsxs("div",{className:"envelope-body","data-clamp":g&&!o?"true":void 0,children:[r.preview||"(this tool wrote no preview)",g&&!o?n.jsx("button",{type:"button",className:"wb-doc-more",onClick:()=>c(!0),children:"Show the whole preview"}):null]})]}),n.jsx(se,{message:a}),x?m:null,x?n.jsxs("div",{className:"wb-envelope-decide",children:[n.jsx("p",{className:"wb-envelope-note",children:j?"Auto and Always also approve later calls to this tool in that scope; you can take it back on the agent's Access page.":"This runs the action exactly as shown above."}),n.jsxs("div",{className:"wb-envelope-buttons",children:[n.jsx("button",{className:"ui-btn","data-variant":"danger",disabled:u!==null,onClick:()=>p("reject"),children:u==="reject"?"Rejecting…":"Reject"}),j?n.jsxs(n.Fragment,{children:[n.jsx("button",{className:"ui-btn",disabled:u!==null,onClick:()=>p("approve","conversation"),children:"Auto: this conversation"}),n.jsx("button",{className:"ui-btn",disabled:u!==null,onClick:()=>p("approve","always"),children:"Always: this agent"})]}):null,n.jsx("button",{className:"ui-btn","data-variant":"good",disabled:u!==null,onClick:()=>p("approve"),children:u==="approve"?"Approving…":j?"Allow once":"Approve"})]})]}):null,n.jsxs("details",{className:"ui-details",children:[n.jsx("summary",{children:"The envelope, field by field"}),n.jsx("dl",{className:"ui-kv wb-envelope-fields",children:b.map(y=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:y.label}),y.block?n.jsx("dd",{className:"wb-envelope-block",children:n.jsx("pre",{className:"mono",children:y.value})}):n.jsx("dd",{className:y.mono?"mono":void 0,children:y.value})]},y.label))})]})]})}function Y_(e){const t=[],s=e.envelope;if(s!==null&&typeof s=="object"&&!Array.isArray(s))for(const[i,a]of Object.entries(s))t.push(sy(hn(i),a));else s!=null&&t.push({label:"Envelope",value:Ix(s)});const r=e.canonicalArgs;if(r!==null&&typeof r=="object"&&!Array.isArray(r))for(const[i,a]of Object.entries(r)){const l=`Argument · ${hn(i)}`;t.some(o=>o.label===l)||t.push(sy(l,a))}return t.push({label:"Action id",value:e.id,mono:!0},{label:"Tool version",value:e.toolVersion,mono:!0},{label:"Agent",value:e.agentId,mono:!0},{label:"Args hash",value:e.argsHash,mono:!0},{label:"Policy version",value:String(e.policyVersion)}),e.conversationId&&t.push({label:"Conversation",value:e.conversationId,mono:!0}),e.jobId&&t.push({label:"Job",value:e.jobId,mono:!0}),t}function sy(e,t){return t!==null&&typeof t=="object"&&(!Array.isArray(t)||t.some(r=>r!==null&&typeof r=="object"))?{label:e,value:JSON.stringify(t,null,2),block:!0}:{label:e,value:Ix(t)}}function Ix(e){return e==null?"—":Array.isArray(e)?e.map(t=>Ix(t)).join(", ")||"—":typeof e=="object"?JSON.stringify(e):zt(e,"text",null)}const q_=new Set(["image/png","image/jpeg","image/gif","image/webp"]),Q_=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function Zu(e){const t=e!==null&&typeof e=="object"?e.artifacts:null;return Array.isArray(t)?t.flatMap(s=>{if(s===null||typeof s!="object")return[];const r=s;return typeof r.id!="string"||!Q_.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 Px(e){return q_.has(e.toLowerCase())}function pr(e){return`/api/artifacts/${encodeURIComponent(e)}/preview`}function ni(e){return`/api/artifacts/${encodeURIComponent(e)}/download`}function $n(e){return e==null||!Number.isFinite(e)?"":e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(e<10*1024?1:0)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function $x(e,t){const s=e.toLowerCase(),r=(t??"").toLowerCase().split(".").pop()??"";return s.startsWith("image/")?"image":s==="application/pdf"?"pdf":s.startsWith("audio/")?"audio":s.startsWith("video/")?"video":s==="text/csv"||s==="text/tab-separated-values"||s.includes("spreadsheet")||s.includes("excel")||["csv","tsv","xls","xlsx","numbers"].includes(r)?"table":s.includes("zip")||s.includes("tar")||s.includes("compressed")||["zip","gz","tgz","rar","7z"].includes(r)?"archive":s==="application/json"||s.includes("javascript")||s.includes("xml")||["ts","tsx","js","py","rb","go","rs","swift","json","yaml","yml","toml","sh","sql","html","css"].includes(r)?"code":s.startsWith("text/")||["md","txt","rtf","doc","docx"].includes(r)?"text":"file"}const Ai={image:"Image",pdf:"PDF",table:"Spreadsheet",text:"Document",code:"Code",audio:"Audio",video:"Video",archive:"Archive",file:"File"};function fu(e){return`artifact:${e}`}function J_(e){const t=$x(e.mime,e.filename);return{id:fu(e.artifactId),tool:Ai[t],title:e.filename??"Untitled file",renderer:"artifact",props:{attachment:e},at:null,source:"artifact",substantial:!1}}function X_({props:e}){const t=a1(e.artifactId),[s,r]=f.useState(null),[i,a]=f.useState(null),[l,o]=f.useState(!1);if(f.useEffect(()=>{if(t===null)return;let h=!0;return r(null),a(null),o(!1),T.libraryEntry(t).then(d=>{h&&r({filename:d.entry.filename,sizeBytes:d.entry.sizeBytes})}).catch(()=>{}),()=>{h=!1}},[t]),t===null)return n.jsx("p",{className:"wb-empty",children:"This result names no file in the Files library."});const c=e.title??(s==null?void 0:s.filename)??"Image",u=[i?`${i.width} × ${i.height}`:null,s!=null&&s.sizeBytes?$n(s.sizeBytes):null].filter(h=>h!==null);return n.jsxs("figure",{className:"wb-image",children:[n.jsx("div",{className:"wb-image-frame",children:l?n.jsx("p",{className:"wb-empty",children:"This file cannot be shown here. Download it to open it."}):n.jsx("a",{href:pr(t),className:"wb-image-link",title:"Open at full size",children:n.jsx("img",{src:pr(t),alt:e.caption??c,onLoad:h=>{const d=h.currentTarget;d.naturalWidth>0&&a({width:d.naturalWidth,height:d.naturalHeight})},onError:()=>o(!0)})})}),n.jsxs("figcaption",{className:"wb-image-caption",children:[n.jsxs(Q,{children:[n.jsx("span",{className:"wb-image-name",children:c}),u.length>0?n.jsx("span",{className:"wb-image-facts",children:u.join(" · ")}):null,n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(Zt,{size:"sm",href:ni(t),download:(s==null?void 0:s.filename)??c,children:"Download"})]}),e.caption&&e.captionLabel?n.jsx($t,{summary:e.captionLabel,className:"wb-image-note",children:n.jsx("p",{className:"wb-image-note-body",children:e.caption})}):e.caption?n.jsx("p",{className:"wb-image-note",children:e.caption}):null]})]})}function Z_({props:e}){return e.pairs.length===0?n.jsx("p",{className:"wb-empty",children:"Nothing to show."}):n.jsx("dl",{className:"ui-kv",children:e.pairs.map(t=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:t.label}),n.jsx("dd",{className:"tnum",style:t.tone==="neutral"?void 0:{color:`var(--${t.tone})`},children:zt(t.value,t.unit,t.currency)})]},t.label))})}const eL=8;function S1({text:e,label:t="Output",className:s}){const r=f.useRef(null),i=f.useRef(!0);return f.useLayoutEffect(()=>{const a=r.current;a&&i.current&&(a.scrollTop=a.scrollHeight)},[e]),n.jsx("pre",{ref:r,className:s?`wb-terminal-body ${s}`:"wb-terminal-body","aria-label":t,tabIndex:0,onScroll:a=>{const l=a.currentTarget;i.current=l.scrollHeight-l.scrollTop-l.clientHeight<=eL},children:e})}function tL(e){if(e<1e3)return`${Math.round(e)} ms`;const t=e/1e3;if(t<60)return`${t.toFixed(t<10?1:0)} s`;const s=Math.floor(t/60);return`${s} min ${Math.round(t-s*60)} s`}function nL({text:e}){const[t,s]=f.useState("");return n.jsxs(n.Fragment,{children:[t?n.jsx("span",{role:"status",className:"wb-hint",children:t}):null,n.jsx(R,{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 sL({props:e}){const t=e.output??"";return n.jsxs("div",{className:"wb-terminal",children:[n.jsxs(Q,{className:"wb-terminal-head",children:[e.command!==null?n.jsx("code",{className:"wb-terminal-command",title:e.command,children:e.command}):null,e.exitCode!==null?n.jsxs(ge,{tone:e.exitCode===0?"good":"critical",mono:!0,children:["exit ",e.exitCode]}):null,e.elapsedMs!==null?n.jsx("span",{className:"wb-terminal-fact",children:tL(e.elapsedMs)}):null,n.jsx("span",{className:"ui-toolbar-spacer"}),t!==""?n.jsx(nL,{text:t}):null]}),e.omittedBytes!==null?n.jsxs("p",{className:"wb-terminal-note",children:["First ",$n(e.omittedBytes)," not shown."]}):null,t!==""?n.jsx(S1,{text:t}):n.jsx("p",{className:"wb-empty",children:"No output."}),e.metadata.length>0?n.jsx("dl",{className:"ui-kv wb-terminal-facts",children:e.metadata.map(s=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:s.label}),n.jsx("dd",{children:zt(s.value,s.unit,null)})]},s.label))}):null]})}function rL(){const e=window.location.hostname.replace(/^\[|\]$/g,"").toLowerCase();return e==="127.0.0.1"||e==="::1"||e==="localhost"}function ry(e){try{const t=new URL(e);return t.searchParams.delete("ticket"),t.toString()}catch{return e}}function iL(e){const t=new Set(e.ports??[]);return e.port!==null&&t.add(e.port),[...t].sort((s,r)=>s-r)}function aL({props:e}){var N;const[t,s]=f.useState(null),[r,i]=f.useState(null),[a,l]=f.useState(null),[o,c]=f.useState(!1),u=((N=e.target)==null?void 0:N.plugin)??null,h=iL(e),[d,m]=f.useState(null),p=d!==null&&h.includes(d)?d:e.port,x=e.target?p!==null&&p!==e.port?`${e.target.name}.${p}`:e.target.name:null,j=e.changes??0,b=f.useRef(j),[g,v]=f.useState(0);f.useEffect(()=>{j<=b.current||(b.current=j,e.reloadsItself||v(k=>k+1))},[j,e.reloadsItself]),f.useEffect(()=>{if(u===null||x===null)return;let k=!0;return s(null),i(null),l(null),v(0),T.previewLink(u,x).then(S=>{k&&(s(S.url),i(ry(S.url)))}).catch(S=>{k&&l(S instanceof Error?S.message:"That preview could not be opened.")}),()=>{k=!1}},[u,x]);const w=()=>{u===null||x===null||T.previewLink(u,x).then(k=>i(k.url)).catch(()=>{})};if(e.target===null)return n.jsxs("p",{className:"wb-empty",children:["This panel names no preview. A preview is ",n.jsx("code",{children:"/preview/<plugin>/<name>/"}),", and nothing else is framed here."]});const y=!(e.output===null||e.output==="");return n.jsxs("div",{className:"wb-preview","data-output":o||void 0,children:[n.jsxs("div",{className:"wb-row wb-preview-head",children:[e.title?n.jsx("h4",{className:"wb-doc-title",children:e.title}):null,h.length>1?n.jsx("select",{className:"wb-preview-port","aria-label":"Port",title:"The ports this process is listening on.",value:p??"",onChange:k=>m(Number(k.target.value)),children:h.map(k=>n.jsxs("option",{value:k,children:[":",k]},k))}):null,y?n.jsx("button",{type:"button",className:"ui-btn wb-preview-toggle","data-variant":"ghost","data-size":"sm","aria-pressed":o,onClick:()=>c(k=>!k),children:o?"Hide output":"Output"}):null,r?n.jsx("a",{className:"wb-preview-open",href:r,target:"_blank",rel:"noreferrer noopener",onPointerEnter:w,onFocus:w,title:"Through buddi: works from anywhere the dashboard does, including the tailnet.",children:"Open in a tab"}):null,p!==null&&rL()?n.jsxs("a",{className:"wb-preview-direct",href:`http://localhost:${p}/`,target:"_blank",rel:"noreferrer noopener",title:"The process itself, on this machine only.",children:["localhost:",p]}):null]}),n.jsxs("div",{className:"wb-preview-body",children:[t?n.jsx("iframe",{className:"wb-preview-frame",src:g===0?t:ry(t),title:e.title??"Preview",sandbox:"allow-scripts allow-forms allow-same-origin allow-modals allow-downloads"},g):n.jsx("p",{className:"wb-empty wb-preview-frame",children:a??"Opening the preview…"}),y&&o?n.jsx(S1,{text:e.output??"",className:"wb-preview-output"}):null]})]})}const lL=50,oL=9,cL=24,uL=.6,dL=48,hL=/(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,fL=/^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}|$)/,mL=/^id$|(^|[a-z0-9])Id$|_id$/;function ya(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function zn(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function N1(...e){for(const t of e)if(zn(t))for(const s of["currency","currencyCode"]){const r=t[s];if(typeof r=="string"&&/^[A-Za-z]{3}$/.test(r))return r.toUpperCase()}return null}function C1(e,t,s){const r=t.filter(i=>i!=null&&i!=="");return r.length===0?"text":r.every(i=>typeof i=="boolean")?"boolean":r.every(i=>typeof i=="number"&&Number.isFinite(i))?s!==null&&hL.test(e)?"currency":"number":r.every(i=>typeof i=="string"&&fL.test(i))?"date":"text"}function pL(e,t){if(!mL.test(e))return!1;const s=t.filter(r=>!ll(r));return s.length<2?!1:new Set(s.map(r=>String(r))).size===s.length}function ll(e){return e==null||e===""?!0:Array.isArray(e)?e.length===0:zn(e)?Object.keys(e).length===0:!1}function iy(e,t){const s=e.filter(zn);if(s.length===0||s.length/e.length<.8)return null;const r=s.slice(0,lL),i=new Map,a=[];for(const h of r)for(const d of Object.keys(h))i.has(d)||a.push(d),i.set(d,(i.get(d)??0)+1);if(i.size===0||i.size>cL||[...i.values()].reduce((h,d)=>h+d,0)/(i.size*r.length)<uL)return null;const o=[...i.keys()].sort((h,d)=>{const m=(i.get(d)??0)-(i.get(h)??0);return m!==0?m:a.indexOf(h)-a.indexOf(d)}),c=[],u=[];for(const h of o){const d=r.map(j=>j[h]),m=d.filter(j=>!ll(j));if(m.length===0||pL(h,d))continue;const p=N1(r[0],t),x=C1(h,d,p);if(r.length>=4&&m.length===d.length&&d.every(j=>ya(j)&&j===d[0])){u.push({label:hn(h),value:d[0],type:x,currency:p});continue}if(c.push({key:h,label:hn(h),type:x,currency:x==="currency"?p:null}),c.length===oL)break}return c.length===0?null:{columns:c,rows:s,constants:u}}function gL(e,t,s){const r=N1(s);return{label:hn(e),value:t,type:C1(e,[t],r),currency:r}}function E1(e){return typeof e=="string"&&e.length>dL}function xL(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.":zn(e)&&Object.keys(e).length===0?"This tool returned an empty result.":null}function np(e){if(typeof e=="string"&&e.trim()!=="")return e;if(zn(e))for(const t of["message","error","reason","detail","description"]){const s=e[t];if(typeof s=="string"&&s.trim()!=="")return s;if(zn(s)){const r=np(s);if(r!=="The call failed with no reason given.")return r}}return"The call failed with no reason given."}function Mx(e,t={}){if(t.failed){let d=e;if(typeof e=="string")try{const m=JSON.parse(e.replace(/^tool-error:\s*/,""));zn(m)&&(d=m)}catch{}return{kind:"error",summary:np(d),detail:ay(d)}}if(zn(e)){const d=e.error,m=e.ok;if(typeof d=="string"&&d.trim()!==""||m===!1)return{kind:"error",summary:np(e),detail:ay(e)}}const s=xL(e);if(s)return{kind:"empty",note:s,stats:[]};if(Array.isArray(e)){const d=iy(e,e);return d?{kind:"table",label:null,columns:d.columns,rows:d.rows,total:d.rows.length,stats:d.constants,notes:[],asides:[]}:e.every(ya)?{kind:"list",label:null,items:e,total:e.length,stats:[],notes:[],asides:[]}:{kind:"tree",value:e}}if(!zn(e))return{kind:"tree",value:e};const r=Object.entries(e);let i=null,a=null;for(const[d,m]of r){if(!Array.isArray(m))continue;const p=iy(m,e);if(p){(!i||p.rows.length>i.candidate.rows.length)&&(i={key:d,candidate:p});continue}m.length>0&&m.every(ya)&&(!a||m.length>a.items.length)&&(a={key:d,items:m})}const l=(i==null?void 0:i.key)??(a==null?void 0:a.key)??null,o=[],c=[],u=[];for(const[d,m]of r)if(d!==l){if(E1(m)){c.push(m);continue}if(ya(m)){if(m==="")continue;o.push(gL(d,m,e));continue}m!==void 0&&u.push({label:hn(d),value:m})}if(i)return{kind:"table",label:hn(i.key),columns:i.candidate.columns,rows:i.candidate.rows,total:i.candidate.rows.length,stats:[...o,...i.candidate.constants],notes:c,asides:u};if(a)return{kind:"list",label:hn(a.key),items:a.items,total:a.items.length,stats:o,notes:c,asides:u};const h=r.filter(([,d])=>Array.isArray(d)&&d.length===0);return h.length>0&&h.length===r.filter(([,d])=>Array.isArray(d)).length?{kind:"empty",note:`No ${h.map(([m])=>hn(m).toLowerCase()).join(", ")} to show.`,stats:o}:r.every(([,d])=>ya(d)||zn(d)||Array.isArray(d))?{kind:"record",pairs:o,notes:c,asides:u}:{kind:"tree",value:e}}function ay(e){if(!zn(e))return null;const t=Object.entries(e).filter(([s])=>s!=="message"&&s!=="error");return t.length===0?null:Object.fromEntries(t)}const ed=25,vL=3,sp=8,A1=6;function rp(e,t=0){if(t>A1||ll(e)||E1(e))return 0;if(ya(e))return 1;if(Array.isArray(e)){let s=0;for(const r of e)if(s+=rp(r,t+1),s>=sp)return s;return s}if(zn(e)){let s=0;for(const r of Object.values(e))if(s+=rp(r,t+1),s>=sp)return s;return s}return 0}function ip(e,t=0){if(t>A1)return!1;if(Array.isArray(e))return e.some(a=>ip(a,t+1));if(!zn(e))return!1;const s=e.artifactId??e.artifact_id;if(typeof s=="string"&&s.trim()!=="")return!0;const r=e.mime??e.mimeType??e.contentType,i=e.url??e.src??e.downloadUrl??e.path;return typeof r=="string"&&r.includes("/")&&typeof i=="string"&&i.trim()!==""?!0:Object.values(e).some(a=>ip(a,t+1))}function jL(e){if(ip(e))return!0;const t=Mx(e);switch(t.kind){case"table":return t.rows.length>0;case"list":return t.items.length>=vL;case"record":case"tree":return rp(e)>=sp;default:return!1}}function tf(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function Ox(e){const t=tf(e);if(!t)return null;const s=tf(t.output)??t;if(typeof s.state!="string"||typeof s.stdout!="string"||typeof s.stderr!="string"||!(s.exitCode===null||typeof s.exitCode=="number"&&Number.isFinite(s.exitCode)))return null;const r=s===t?null:tf(t.input),i=(r==null?void 0:r.command)??s.command;return{command:typeof i=="string"?i:null,input:r,result:s}}function wL({text:e,label:t}){const[s,r]=f.useState("");return n.jsxs("span",{className:"wb-command-copy",children:[n.jsx("button",{className:"ui-btn",onClick:()=>{var i;if(r(""),!((i=navigator.clipboard)!=null&&i.writeText)){r("Copy unavailable; select the text to copy.");return}navigator.clipboard.writeText(e).then(()=>r("Copied"),()=>r("Copy failed; select the text to copy."))},children:t}),s&&n.jsx("span",{role:"status",className:"wb-hint",children:s})]})}function nf({title:e,text:t,error:s=!1}){return n.jsxs("section",{className:"wb-command-stream","data-error":s||void 0,children:[n.jsxs("div",{className:"wb-command-bar",children:[n.jsx("h4",{children:e}),n.jsx(wL,{text:t,label:`Copy ${e.toLowerCase()}`})]}),n.jsx("pre",{className:"wb-command-text","aria-label":e,tabIndex:0,children:t})]})}function yL({value:e,children:t}){const{result:s,command:r,input:i}=e,a=s.state==="completed"&&s.exitCode!==null&&s.exitCode!==0,l=typeof s.signal=="string"&&s.signal?s.signal:null,o=s.state==="completed"&&s.exitCode===0,c=Object.fromEntries(Object.entries(s).filter(([h,d])=>!["stdout","stderr","state","exitCode","artifacts","outputErrors","command"].includes(h)&&d!==null&&d!==void 0&&d!=="")),u=Array.isArray(s.outputErrors)?s.outputErrors.filter(h=>typeof h=="string"):[];return n.jsxs("div",{className:"wb-command-result",children:[n.jsxs("div",{className:"wb-command-bar",children:[n.jsx("span",{className:"ui-pill","data-tone":o?"good":"critical",children:a?"Failed":s.state==="completed"&&l?"Terminated":s.state}),s.exitCode!==null&&n.jsxs("span",{className:"mono",children:["Exit code ",s.exitCode]}),l&&n.jsxs("span",{className:"mono",children:["Signal ",l]}),n.jsx("span",{className:"wb-hint",children:"Recorded command result"})]}),r!==null&&n.jsx(nf,{title:"Command",text:r}),s.state==="output-limit"&&n.jsx("p",{className:"wb-fail",children:"Output limit reached. The command was stopped and the captured output may be incomplete."}),s.state==="timed-out"&&n.jsx("p",{className:"wb-fail",children:"The command exceeded its time limit. Output below may be partial."}),s.state==="cancelled"&&n.jsx("p",{className:"wb-note",children:"The command was cancelled. Completed changes were not undone."}),s.stdout?n.jsx(nf,{title:"Output",text:s.stdout}):n.jsx("p",{className:"wb-note",children:"No standard output."}),s.stderr?n.jsx(nf,{title:"Standard error",text:s.stderr,error:!0}):null,u.length>0&&n.jsxs("section",{children:[n.jsx("h4",{children:"File export errors"}),u.map((h,d)=>n.jsx("p",{className:"wb-fail",children:h},d))]}),t,(Object.keys(c).length>0||i!==null)&&n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:"Execution details"}),n.jsx("pre",{children:In({...c,...i?{input:i}:{}})})]})]})}const Dc=2,ly=64;function bL({props:e}){const[t,s]=f.useState(!1),r=Ox(e.value),i=kL((r==null?void 0:r.result)??e.value),a=f.useMemo(()=>Mx(e.value,{failed:e.failed??!1}),[e.value,e.failed]);return n.jsxs("div",{children:[!r&&n.jsx(oy,{files:i}),t?n.jsx("pre",{className:"ui-code",children:In(e.value)}):r?n.jsx(yL,{value:r,children:i.length>0&&n.jsxs("section",{children:[n.jsx("h4",{children:"Generated files"}),n.jsx(oy,{files:i})]})}):i.length?n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:"Tool details"}),n.jsx(cy,{shape:a})]}):n.jsx(cy,{shape:a}),n.jsx("div",{className:"wb-row-end wb-section",children:n.jsx("button",{className:"ui-btn","data-variant":"ghost","data-size":"sm",onClick:()=>s(l=>!l),"aria-pressed":t,children:t?"Readable":"Raw JSON"})})]})}function kL(e){const t=e&&typeof e=="object"&&"artifacts"in e?e.artifacts:null;return Array.isArray(t)?t.filter(s=>s&&typeof s.id=="string"&&/^[0-9a-f-]{36}$/i.test(s.id)&&typeof s.filename=="string"):[]}function oy({files:e}){return e.length?n.jsx("div",{className:"wb-artifacts",children:e.map(t=>{var s;return n.jsxs("div",{children:[["image/png","image/jpeg","image/gif","image/webp"].includes(t.mime??"")?n.jsx(SL,{file:t}):null,n.jsx("a",{className:"ui-btn",href:`/api/artifacts/${encodeURIComponent(t.id)}/download`,download:!0,children:(s=t.mime)!=null&&s.startsWith("image/")?`Download ${t.filename}`:t.filename})]},t.id)})}):null}function SL({file:e}){const[t,s]=f.useState(!1);return t?n.jsx("p",{className:"wb-note",children:"Preview unavailable. You can still download the file."}):n.jsx("img",{className:"wb-artifact-image",src:`/api/artifacts/${e.id}/preview`,alt:e.filename,onError:()=>s(!0)})}function cy({shape:e}){switch(e.kind){case"error":return n.jsxs("div",{children:[n.jsx("p",{className:"wb-fail",role:"status",children:e.summary}),e.detail===null?null:n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:"What came back with it"}),n.jsx("div",{className:"wb-tree",children:Eo(e.detail,1)})]})]});case"empty":return n.jsxs("div",{children:[n.jsx(sf,{stats:e.stats}),n.jsx("p",{className:"wb-note",children:e.note})]});case"table":{const t=RL(e.columns,e.rows);return n.jsxs("div",{children:[n.jsx(sf,{stats:e.stats}),n.jsx(rf,{notes:e.notes}),t?n.jsx(IL,{label:e.label,plan:t,rows:e.rows,total:e.total}):n.jsx(CL,{label:e.label,columns:e.columns,rows:e.rows,total:e.total}),n.jsx(af,{asides:e.asides})]})}case"list":return n.jsxs("div",{children:[n.jsx(sf,{stats:e.stats}),n.jsx(rf,{notes:e.notes}),e.label?n.jsx("h4",{className:"wb-sub",children:e.label}):null,n.jsx("ul",{className:"wb-list",children:e.items.slice(0,100).map((t,s)=>n.jsx("li",{children:zt(t,"text",null)},s))}),e.total>100?n.jsxs("p",{className:"wb-note",children:["Showing 100 of ",e.total,"."]}):null,n.jsx(af,{asides:e.asides})]});case"record":return n.jsxs("div",{children:[n.jsx(rf,{notes:e.notes}),n.jsx(NL,{pairs:e.pairs}),n.jsx(af,{asides:e.asides})]});default:return n.jsx("div",{className:"wb-tree",children:Eo(e.value,0)})}}function sf({stats:e}){return e.length===0?null:n.jsx("div",{className:"ui-stats","data-inline":"true",children:e.map(t=>n.jsxs("div",{children:[n.jsx("div",{className:"ui-stat-k",children:t.label}),n.jsx("div",{className:"ui-stat-v",children:Dx(t.value,t.type,t.currency)})]},t.label))})}const uy=200;function rf({notes:e}){if(e.length===0)return null;const t=e.filter(r=>r.length<=uy),s=e.filter(r=>r.length>uy);return n.jsxs(n.Fragment,{children:[t.map(r=>n.jsx("p",{className:"wb-note",children:r},r)),s.length>0?n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:s.length===1?"A note that came with this result":`${s.length} notes that came with this result`}),s.map(r=>n.jsx("p",{className:"wb-note",children:r},r))]}):null]})}function NL({pairs:e}){return e.length===0?n.jsx("p",{className:"wb-note",children:"Nothing to show."}):n.jsx("dl",{className:"ui-kv",children:e.map(t=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:t.label}),n.jsx("dd",{className:t.type==="text"?void 0:"tnum",children:Dx(t.value,t.type,t.currency)})]},t.label))})}function af({asides:e}){return e.length===0?null:n.jsx("div",{className:"wb-section",children:e.map(t=>n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:t.label}),n.jsx("div",{className:"wb-tree",children:Eo(t.value,1)})]},t.label))})}function CL({label:e,columns:t,rows:s,total:r}){const[i,a]=f.useState(!1),l=r<=ed+5?r:ed,o=i?s:s.slice(0,l);return n.jsxs("div",{children:[e?n.jsx("h4",{className:"wb-sub",children:e}):null,n.jsx("div",{className:"ui-table-wrap",children:n.jsxs("table",{className:"ui-table",children:[n.jsx("thead",{children:n.jsx("tr",{children:t.map(c=>n.jsx("th",{className:R1(c.type)?"num":void 0,children:c.label},c.key))})}),n.jsx("tbody",{children:o.map((c,u)=>n.jsx("tr",{children:t.map(h=>n.jsx(PL,{value:c[h.key],column:h},h.key))},u))})]})}),r>o.length?n.jsxs("p",{className:"wb-note wb-note-row",children:[n.jsxs("span",{children:["Showing ",o.length," of ",r]}),n.jsxs("button",{className:"ui-btn",onClick:()=>a(!0),children:["Show all ",r]})]}):null]})}const EL=/^(title|name|headline|subject|label|heading)$/i,AL=/^(url|link|href|uri|permalink)$/i;function td(e){return typeof e=="string"&&/^https?:\/\/[^\s]+$/i.test(e.trim())}function TL(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function T1(e,t=48){try{const s=new URL(e),r=s.pathname==="/"?"":s.pathname,i=`${s.hostname.replace(/^www\./,"")}${r}${s.search}`;return i.length>t?`${i.slice(0,t-1)}…`:i}catch{return e.length>t?`${e.slice(0,t-1)}…`:e}}function _c(e,t){const s=e.map(r=>r[t]).filter(r=>typeof r=="string"&&r.trim()!=="");return s.length===0?0:s.reduce((r,i)=>r+i.length,0)/s.length}function RL(e,t){if(t.length===0)return null;const s=e.filter(h=>h.type==="text"),r=s.find(h=>AL.test(h.key)&&t.some(d=>td(d[h.key])))??s.find(h=>{const d=t.map(m=>m[h.key]).filter(m=>!ll(m));return d.length>0&&d.filter(td).length/d.length>=.6});if(!r)return null;const i=s.filter(h=>h.key!==r.key),a=i.find(h=>EL.test(h.key))??i.find(h=>_c(t,h.key)>0);if(!a)return null;const o=[...i.filter(h=>h.key!==a.key)].sort((h,d)=>_c(t,d.key)-_c(t,h.key)),c=o[0]&&_c(t,o[0].key)>40?o[0]:null,u=e.filter(h=>h.key!==r.key&&h.key!==a.key&&h.key!==(c==null?void 0:c.key)).map(h=>h.key);return{url:r.key,title:a.key,description:(c==null?void 0:c.key)??null,meta:u}}function IL({label:e,plan:t,rows:s,total:r}){const[i,a]=f.useState(!1),l=r<=ed+5?r:ed,o=i?s:s.slice(0,l);return n.jsxs("div",{children:[e?n.jsx("h4",{className:"wb-sub",children:e}):null,n.jsx("ol",{className:"wb-records",children:o.map((c,u)=>{const h=c[t.url],d=td(h)?h.trim():null,m=typeof c[t.title]=="string"&&c[t.title].trim()!==""?c[t.title]:d?T1(d):"Untitled",p=t.description&&typeof c[t.description]=="string"?c[t.description]:null,x=d?TL(d):null,j=t.meta.map(b=>c[b]).filter(b=>!ll(b)&&typeof b!="object").map(b=>String(b)).filter(b=>x===null||b.replace(/^www\./,"")!==x);return n.jsxs("li",{className:"wb-record",children:[d?n.jsx("a",{className:"wb-record-title",href:d,target:"_blank",rel:"noopener noreferrer",children:m}):n.jsx("span",{className:"wb-record-title",children:m}),n.jsxs("div",{className:"wb-record-meta",children:[x?n.jsx("span",{className:"wb-record-host",title:d??void 0,children:x}):null,j.map((b,g)=>n.jsx("span",{children:b.length>60?`${b.slice(0,59)}…`:b},g))]}),p?n.jsx("p",{className:"wb-record-desc",children:p.length>280?`${p.slice(0,279)}…`:p}):null]},u)})}),r>o.length?n.jsxs("p",{className:"wb-note wb-note-row",children:[n.jsxs("span",{children:["Showing ",o.length," of ",r]}),n.jsxs("button",{className:"ui-btn",onClick:()=>a(!0),children:["Show all ",r]})]}):null]})}function PL({value:e,column:t}){if(ll(e))return n.jsx("td",{className:"wb-cell-soft",children:"—"});if(td(e)){const i=e.trim();return n.jsx("td",{className:"wb-cell-link",children:n.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",title:i,children:T1(i)})})}if(e!==null&&typeof e=="object"){const i=Array.isArray(e)?`${e.length} item${e.length===1?"":"s"}`:`${Object.keys(e).length} fields`;return n.jsx("td",{className:"wb-cell-soft",title:In(e),children:i})}const s=Dx(e,t.type,t.currency),r=s.length>ly?`${s.slice(0,ly-1)}…`:s;return n.jsx("td",{className:R1(t.type)?"num":"wb-cell-text",...r===s?{}:{title:s},children:r})}function R1(e){return e==="number"||e==="currency"}function Dx(e,t,s){return e==null?"—":t==="boolean"?e?"yes":"no":zt(e,t==="text"?"text":t,s)}function Eo(e,t){if(e===null)return n.jsx("span",{className:"wb-tree-null",children:"null"});if(e===void 0)return n.jsx("span",{className:"wb-tree-null",children:"—"});if(typeof e=="number")return n.jsx("span",{className:"wb-tree-num",children:e});if(typeof e=="boolean")return n.jsx("span",{className:"wb-tree-bool",children:e?"true":"false"});if(typeof e=="string")return n.jsx("span",{children:e===""?n.jsx("em",{className:"wb-tree-null",children:"empty"}):e});if(Array.isArray(e)){if(e.length===0)return n.jsx("span",{className:"wb-tree-null",children:"none"});const i=n.jsxs("div",{className:"wb-tree-branch",children:[e.slice(0,50).map((a,l)=>n.jsxs("div",{children:[n.jsxs("span",{className:"wb-tree-key",children:[l,". "]}),Eo(a,t+1)]},l)),e.length>50?n.jsxs("div",{className:"wb-tree-key",children:["…and ",e.length-50," more"]}):null]});return t>=Dc?n.jsx(dy,{summary:`${e.length} items`,open:t===Dc,children:i}):i}const s=Object.entries(e);if(s.length===0)return n.jsx("span",{className:"wb-tree-null",children:"empty"});const r=n.jsx("div",{className:t===0?void 0:"wb-tree-branch",children:s.map(([i,a])=>n.jsxs("div",{children:[n.jsxs("span",{className:"wb-tree-key",children:[hn(i),": "]}),Eo(a,t+1)]},i))});return t>=Dc?n.jsx(dy,{summary:`${s.length} fields`,open:t===Dc,children:r}):r}function dy({summary:e,open:t,children:s}){return n.jsxs("details",{open:t,children:[n.jsx("summary",{className:"wb-tree-key",children:e}),s]})}function $L({props:e}){const t=e.groups.every(s=>s.rows.length===0);return n.jsxs("div",{children:[e.summary.length>0?n.jsx("div",{className:"ui-stats","data-inline":"true",children:e.summary.map(s=>n.jsxs("div",{children:[n.jsx("div",{className:"ui-stat-k",children:s.label}),n.jsx("div",{className:"ui-stat-v","data-tone":s.tone,children:zt(s.value,s.unit,s.currency)})]},s.label))}):null,t?n.jsx("p",{className:"wb-empty",children:e.empty}):e.groups.map((s,r)=>n.jsxs("div",{className:r>0?"wb-section":void 0,children:[s.label?n.jsx("h4",{className:"ui-stat-k wb-label",children:s.label}):null,n.jsx("div",{className:"ui-table-wrap",children:n.jsxs("table",{className:"ui-table",children:[n.jsx("thead",{children:n.jsx("tr",{children:e.columns.map(i=>n.jsx("th",{className:I1(i.type)?"num":void 0,"data-type":i.type,children:i.label},i.key))})}),n.jsx("tbody",{children:s.rows.map((i,a)=>n.jsx("tr",{children:i.map((l,o)=>{var c;return n.jsx(ML,{cell:l},((c=e.columns[o])==null?void 0:c.key)??o)})},a))})]})})]},s.label??r))]})}function ML({cell:e}){const t=zt(e.value,e.type,e.currency);return e.bar?n.jsx("td",{className:"num",children:n.jsxs("div",{className:"wb-row wb-row-end",children:[n.jsx("div",{className:"ui-meter",role:"meter","aria-valuenow":Math.round(e.bar.fraction*100),"aria-valuemin":0,"aria-valuemax":100,"aria-label":t,children:n.jsx("div",{className:"ui-meter-fill","data-tone":e.bar.tone,style:{width:`${Math.round(e.bar.fraction*100)}%`}})}),n.jsx("span",{className:"tnum",children:t})]})}):n.jsx("td",{className:I1(e.type)?"num":void 0,"data-type":e.type,title:t.length>40?t:void 0,children:t})}function I1(e){return e==="number"||e==="currency"||e==="percent"}const hy={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"};function th(e){return(e&&Object.prototype.hasOwnProperty.call(hy,e)?hy[e]:void 0)??"dot"}function fy(e,t){return(e??[]).filter(s=>s.place===t).map((s,r)=>({page:s,index:r})).sort((s,r)=>(s.page.order??0)-(r.page.order??0)||s.index-r.index).map(s=>s.page)}const nd="buddi:plugin-pages-changed";function OL(){window.dispatchEvent(new Event(nd))}function P1(e=!1){const[t,s]=f.useState([]);return f.useEffect(()=>{if(e)return;let r=!1;const i=()=>{Promise.resolve().then(()=>T.pages()).then(l=>{r||s(Array.isArray(l==null?void 0:l.pages)?l.pages:[])}).catch(()=>{})};i();const a=()=>{document.visibilityState==="visible"&&i()};return window.addEventListener(nd,i),document.addEventListener("visibilitychange",a),()=>{r=!0,window.removeEventListener(nd,i),document.removeEventListener("visibilitychange",a)}},[e]),{all:t,rail:fy(t,"rail"),settings:fy(t,"settings"),find:(r,i)=>t.find(a=>a.plugin===r&&a.id===i)}}let mu=null;typeof window<"u"&&window.addEventListener(nd,()=>{mu=null});function DL(){return mu??(mu=Promise.resolve().then(()=>T.pages()).then(e=>Array.isArray(e==null?void 0:e.pages)?e.pages:[]).catch(()=>(mu=null,[]))),mu}function $1(e,t,s){return s==="settings"?al(e,t):ti(e,t)}function _L(e){const[t,s]=f.useState(null),r=e==null?void 0:e.plugin,i=e==null?void 0:e.page;return f.useEffect(()=>{if(!r||!i)return;let a=!1;return DL().then(l=>{const o=l.find(c=>c.plugin===r&&c.id===i);a||s(o?{href:$1(r,i,o.place),label:o.place==="settings"?`Settings → ${o.title}`:o.title}:null)}),()=>{a=!0}},[r,i]),t}function M1({props:e,layout:t,selected:s,onPick:r}){return e.tiles.length===0?n.jsx("p",{className:"wb-empty",children:e.empty}):n.jsx("ul",{className:"wb-tiles","data-notice":e.notice?"true":void 0,"data-layout":t&&t!=="grid"?t:void 0,style:t==="row"?{"--tiles-n":e.tiles.length}:void 0,children:e.tiles.map((i,a)=>n.jsx(LL,{tile:i,...r?{picked:a===s,onPick:()=>r(a)}:{}},`${a}-${i.label}`))})}function LL({tile:e,picked:t,onPick:s}){const r=_L(e.link),i=[e.label,e.value,...e.lines].filter(l=>l!=="").join(", "),a=n.jsxs("div",{className:"wb-tile-body","aria-hidden":"true",children:[n.jsx("span",{className:"wb-tile-icon","data-icon":e.icon??"dot",children:n.jsx(we,{name:th(e.icon),size:22})}),e.value!==""?n.jsx("span",{className:"wb-tile-value tnum",children:e.value}):null,n.jsx("span",{className:"wb-tile-label",children:e.label}),e.lines.map((l,o)=>n.jsx("span",{className:"wb-tile-line",children:l},o))]});return s?n.jsx("li",{className:"wb-tile",children:n.jsx("button",{type:"button",className:"ui-card","data-tone":t?"accent":e.tone==="neutral"?void 0:e.tone,"data-selected":t?"true":void 0,"aria-pressed":t===!0,"aria-label":i,onClick:s,children:a})}):n.jsxs("li",{className:"wb-tile",children:[n.jsx("span",{className:"sr-only",children:i}),n.jsxs(ks,{tone:e.tone==="neutral"?void 0:e.tone,children:[a,r?n.jsx("a",{className:"wb-tile-link",href:r.href,children:r.label}):null]})]})}const sa=760,lf=400,Ct={top:18,right:18,bottom:36,left:66},FL=5;function zL({props:e}){const{points:t,referenceLines:s,unit:r,currency:i}=e;if(t.length===0)return n.jsx("p",{className:"wb-empty",children:"This result carried no points to plot."});const a=[...t.map(y=>y.y),...s.map(y=>y.value)],l=Math.min(...a),o=Math.max(...a),c=o-l||Math.abs(o)||1,u=l-c*.08,h=o+c*.08,d=sa-Ct.left-Ct.right,m=lf-Ct.top-Ct.bottom,p=y=>Ct.left+(t.length===1?d/2:y/(t.length-1)*d),x=y=>Ct.top+m-(y-u)/(h-u)*m,j=Yu(l,o,4),b=BL(t.map(y=>y.y),e.mark),g=e.shadeBelow===null?[]:WL(t.map(y=>y.y),e.shadeBelow),v=t.map((y,N)=>`${N===0?"M":"L"}${p(N)},${x(y.y)}`).join(" "),w=y=>zt(y,r,i);return n.jsxs("div",{children:[e.label?n.jsx("p",{className:"ui-panel-sub",children:e.label}):null,n.jsxs("div",{className:"wb-chart-layout",children:[n.jsx("div",{className:"wb-chart-plot",children:n.jsxs("svg",{className:"wb-chart",viewBox:`0 0 ${sa} ${lf}`,role:"img","aria-label":UL(e,w),preserveAspectRatio:"xMidYMid meet",children:[g.map(y=>n.jsx("rect",{className:"wb-chart-breach",x:p(y.from),width:Math.max(2,p(y.to)-p(y.from)),y:Ct.top,height:m},`band-${y.from}`)),j.map(y=>n.jsxs("g",{children:[n.jsx("line",{className:"wb-chart-grid",x1:Ct.left,x2:sa-Ct.right,y1:x(y),y2:x(y)}),n.jsx("text",{x:Ct.left-8,y:x(y)+4,textAnchor:"end",children:w(y)})]},`tick-${y}`)),s.map(y=>n.jsxs("g",{children:[n.jsx("line",{className:"wb-chart-floor",x1:Ct.left,x2:sa-Ct.right,y1:x(y.value),y2:x(y.value)}),n.jsxs("text",{x:sa-Ct.right,y:x(y.value)-6,textAnchor:"end",children:[y.label," ",w(y.value)]})]},`rule-${y.label}`)),n.jsx("line",{className:"wb-chart-axis",x1:Ct.left,x2:Ct.left,y1:Ct.top,y2:Ct.top+m}),n.jsx("line",{className:"wb-chart-axis",x1:Ct.left,x2:sa-Ct.right,y1:Ct.top+m,y2:Ct.top+m}),n.jsx("path",{className:"wb-chart-series",d:v}),b!==null?n.jsxs("g",{children:[n.jsx("circle",{className:"wb-chart-min",cx:p(b),cy:x(t[b].y),r:4.5}),n.jsx("text",{x:p(b),y:x(t[b].y)+20,textAnchor:"middle",children:w(t[b].y)})]}):null,HL(t.length).map(y=>n.jsx("text",{x:p(y),y:lf-10,textAnchor:"middle",children:Gm(t[y].x)},`x-${y}`))]})}),e.events.length>0?n.jsxs("aside",{className:"wb-chart-events",children:[n.jsx("h4",{className:"ui-stat-k wb-label",children:"What happens"}),n.jsx("ul",{className:"wb-chart-event-list",children:e.events.map((y,N)=>n.jsxs("li",{className:"wb-chart-event",children:[n.jsxs("span",{children:[n.jsx("span",{className:"wb-chart-event-day",children:Gm(y.at)}),y.label]}),y.amount===null?null:n.jsx("span",{className:y.amount<0?"tnum critical":"tnum good",children:zt(y.amount,r,i)})]},`${y.at}-${y.label}-${N}`))})]}):null]})]})}function UL(e,t){const s=e.points.map(l=>l.y),r=e.points[0],i=e.points[e.points.length-1],a=e.referenceLines.map(l=>`${l.label} at ${t(l.value)}`).join(", ");return[`${e.points.length} points from ${r==null?void 0:r.x} to ${i==null?void 0:i.x}`,`low ${t(Math.min(...s))}, high ${t(Math.max(...s))}`,a].filter(Boolean).join("; ")}function BL(e,t){if(!t||e.length===0)return null;let s=0;for(let r=1;r<e.length;r+=1)(t==="min"?e[r]<e[s]:e[r]>e[s])&&(s=r);return s}function WL(e,t){const s=[];let r=null;return e.forEach((i,a)=>{i<t?r===null&&(r=a):r!==null&&(s.push({from:r,to:a}),r=null)}),r!==null&&s.push({from:r,to:e.length-1}),s}function HL(e,t=FL){if(e<=0)return[];if(e<=t)return[...Array(e).keys()];const s=e-1,r=new Set;for(let i=0;i<t;i+=1)r.add(Math.round(i/(t-1)*s));return[...r].sort((i,a)=>i-a)}const Xn=e=>e,ap={timeseries:Xn(zL),table:Xn($L),bars:Xn(PO),keyvalue:Xn(Z_),tiles:Xn(M1),document:Xn(a_),diff:Xn(LO),terminal:Xn(sL),image:Xn(X_),preview:Xn(aL),envelope:Xn(G_),structured:Xn(bL)},KL="structured";function VL(e){return(sd(e)?ap[e]:void 0)??ap[KL]}function sd(e){return Object.prototype.hasOwnProperty.call(ap,e)}function GL({renderer:e,props:t,timezone:s,onDecided:r}){const i=VL(e),l=sd(e)?t:{value:t};return n.jsx(i,{props:l,timezone:s,onDecided:r})}function YL({profile:e,onChange:t}){return n.jsxs("div",{className:"wb-prof","data-testid":"agent-profile",children:[n.jsx("p",{className:"wb-prof-lead",children:e.description}),n.jsxs("div",{className:"wb-prof-tags",children:[e.isDefault?n.jsx(of,{children:"Opens by default"}):null,n.jsx(of,{children:e.source==="example"?"Shipped with buddi":"Yours"}),e.roles.map(s=>n.jsx(of,{title:`A surface command that asks for "${s}" lands on this agent.`,children:hn(s)},s))]}),e.available?null:n.jsxs("p",{className:"wb-prof-blocked","data-testid":"agent-profile-unavailable",children:[n.jsx("strong",{children:"This agent cannot run here."})," ",e.unavailableReason]}),(e.disabled??[]).map(s=>n.jsx("p",{className:"wb-prof-blocked","data-testid":"agent-profile-disabled",children:s},s)),n.jsx(Al,{title:"How it works with you",note:"Live decisions stay in the conversation; this page explains the standing rules.",children:n.jsxs("ul",{className:"wb-prof-list",children:[n.jsxs("li",{className:"wb-prof-row",children:[n.jsxs("span",{className:"wb-prof-row-main",children:[n.jsx("span",{className:"wb-prof-row-name",children:"Quick questions"}),n.jsx("span",{className:"wb-prof-row-desc",children:"When it knows the likely answers, it can show one-tap choices in the dashboard and Telegram. You can still write a different answer when the question allows it."})]}),n.jsx("span",{className:"wb-prof-auto",children:"Answers only"})]}),n.jsxs("li",{className:"wb-prof-row","data-gated":"true",children:[n.jsxs("span",{className:"wb-prof-row-main",children:[n.jsx("span",{className:"wb-prof-row-name",children:"Action approvals"}),n.jsx("span",{className:"wb-prof-row-desc",children:"A request to send, spend, publish or otherwise affect the world appears in the conversation with the exact action. Answering a question never approves it."})]}),n.jsxs("span",{className:"wb-prof-gate",children:[n.jsx(O1,{}),"Exact action"]})]})]})}),n.jsx(Al,{title:"What it can do",note:qL(e),tone:e.gatedCount>0?"warning":void 0,children:e.tools.length===0?n.jsx("p",{className:"wb-prof-empty",children:"No tools at all. It answers from the conversation and from what it remembers, and it can change nothing."}):[...e.tools].sort((s,r)=>+(r.gated>0)-+(s.gated>0)).map(s=>n.jsx(QL,{family:s},s.family))}),n.jsx(Al,{title:"What it runs on",children:n.jsxs("dl",{className:"wb-prof-kv",children:[n.jsx(Tl,{label:"Provider",children:e.engine.provider}),n.jsx(Tl,{label:"Model",children:n.jsx("span",{className:"mono",children:e.engine.model})}),n.jsxs(Tl,{label:"Credential",children:[e.engine.credentialKind," from"," ",n.jsx("span",{className:"mono",children:e.engine.credentialEnv})]}),n.jsxs(Tl,{label:"Turn budget",children:[e.engine.maxTurns," ",e.engine.maxTurns===1?"turn":"turns"," per message"]}),n.jsx(Tl,{label:"Language",children:tF(e.engine.language)})]})}),e.skills.length>0?n.jsx(Al,{title:"What it has read",note:`${e.skills.length} ${e.skills.length===1?"skill":"skills"}, composed into every run`,children:n.jsx("ul",{className:"wb-prof-list",children:e.skills.map(s=>n.jsxs("li",{className:"wb-prof-row",children:[n.jsxs("span",{className:"wb-prof-row-main",children:[n.jsx("span",{className:"wb-prof-row-name mono",children:s.name}),s.description?n.jsx("span",{className:"wb-prof-row-desc",children:s.description}):null]}),n.jsxs("span",{className:"wb-prof-row-side",title:s.file,children:[s.scope==="private"?"its own":"shared"," · ",s.provenance]})]},s.file))})}):null,e.delegates.length>0?n.jsx(Al,{title:"Who it can hand work to",note:"A colleague's tools are reached through the colleague, never held here",children:n.jsx("ul",{className:"wb-prof-list",children:e.delegates.map(s=>n.jsxs("li",{className:"wb-prof-row",children:[n.jsxs("span",{className:"wb-prof-row-main",children:[n.jsxs("span",{className:"wb-prof-row-name mono",children:["@",s.handle]}),n.jsx("span",{className:"wb-prof-row-desc",children:s.description})]}),n.jsx("span",{className:"wb-prof-row-side",children:s.available?s.name:`${s.name} · cannot run`})]},s.id))})}):null,n.jsxs("footer",{className:"wb-prof-foot",children:[n.jsx("p",{className:"wb-prof-note",children:e.note}),n.jsx("p",{className:"wb-prof-file mono",title:e.file,children:e.file}),e.changeVia&&t?n.jsxs("button",{className:"ui-btn","data-testid":"agent-profile-change",title:e.changeVia.prompt,onClick:()=>t({agentId:e.changeVia.agentId,prompt:e.changeVia.prompt}),children:["Ask @",e.changeVia.handle," to change this"]}):null]})]})}function qL(e){if(e.toolCount===0)return"Nothing. This agent holds no tools.";const t=`${e.toolCount} ${e.toolCount===1?"tool":"tools"}`;if(e.gatedCount===0)return`${t}, every one of them running without asking you. None of them can send, spend or write to the world.`;const s=e.gatedCount===1?"one of them stops and waits for you":`${e.gatedCount} of them stop and wait for you`;return`${t}, and ${s}.`}function QL({family:e}){const t=[...e.tools].sort((s,r)=>Number(r.gated)-Number(s.gated));return n.jsxs("section",{className:"wb-prof-family",children:[n.jsxs("h4",{className:"wb-prof-family-head",children:[n.jsx("span",{className:"wb-prof-family-name",children:hn(e.family)}),n.jsxs("span",{className:"wb-prof-family-note",children:[e.tools.length," ",e.tools.length===1?"tool":"tools",e.gated>0?` · ${e.gated} needs you`:""]})]}),n.jsx("ul",{className:"wb-prof-list",children:t.map(s=>n.jsx(JL,{tool:s},s.name))})]})}function JL({tool:e}){return n.jsxs("li",{className:"wb-prof-row","data-gated":e.gated?"true":void 0,"data-testid":"agent-profile-tool",children:[n.jsxs("span",{className:"wb-prof-row-main",children:[n.jsx("span",{className:"wb-prof-row-name mono",children:eF(e.name)}),n.jsx("span",{className:"wb-prof-row-desc","data-clamp":"true",title:e.description,children:e.description})]}),e.gated?n.jsxs("span",{className:"wb-prof-gate",title:"The call is recorded and waits; nothing happens until you approve it.",children:[n.jsx(O1,{}),"Needs your approval"]}):n.jsx("span",{className:"wb-prof-auto",title:ZL(e.tier),children:XL(e.tier)})]})}function XL(e){return e==="auto"?"Runs on its own":e==="gated"?"Needs your approval":"Not runnable here"}function ZL(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 eF(e){const t=e.split(".");return(t[t.length-1]??e).replace(/_/g," ")}function tF(e){return e==="mirror"?"Mirrors whichever language you write in":e==="en"?"Always English":e==="fr"?"Always French":e}function Al({title:e,note:t,tone:s,children:r}){return n.jsxs("section",{className:"wb-prof-section",children:[n.jsx("h3",{className:"wb-prof-title",children:e}),t?n.jsx("p",{className:"wb-prof-note-lead","data-tone":s,children:t}):null,r]})}function Tl({label:e,children:t}){return n.jsxs(n.Fragment,{children:[n.jsx("dt",{className:"wb-prof-k",children:e}),n.jsx("dd",{className:"wb-prof-v",children:t})]})}function of({children:e,title:t}){return n.jsx("span",{className:"wb-prof-tag",title:t,children:e})}function O1(){return n.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 14 14","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"2.8",y:"6",width:"8.4",height:"6.2",rx:"1.4"}),n.jsx("path",{d:"M4.8 6V4.4a2.2 2.2 0 0 1 4.4 0V6"})]})}const my=16e3,nF=10*6e4,sF="The microphone is blocked for this page: allow it in the browser’s site settings to talk.",D1="This browser cannot record here: talking needs a microphone and a secure page (https or localhost).";function rF(){const e=window;return e.AudioContext??e.webkitAudioContext}function iF(e){const t=e&&typeof e=="object"&&"name"in e?String(e.name):"";return t==="NotAllowedError"||t==="SecurityError"||t==="PermissionDeniedError"?sF:t==="NotFoundError"||t==="DevicesNotFoundError"?"No microphone was found on this computer.":t==="NotReadableError"?"The microphone is in use by another app.":D1}async function aF(e){var c;const t=rF();if(!((c=navigator.mediaDevices)!=null&&c.getUserMedia)||!t)throw Object.assign(new Error(D1),{name:"Unsupported"});const s=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),r=new t,i=r.createMediaStreamSource(s),a=r.createScriptProcessor(4096,1,1),l=[];a.onaudioprocess=u=>{const h=u.inputBuffer.getChannelData(0);l.push(new Float32Array(h));let d=0;for(let m=0;m<h.length;m++)d+=h[m]*h[m];e(Math.min(1,Math.sqrt(d/h.length)*6))},i.connect(a),a.connect(r.destination),r.state==="suspended"&&await r.resume().catch(()=>{});const o=()=>{a.onaudioprocess=null;try{i.disconnect(),a.disconnect()}catch{}s.getTracks().forEach(u=>u.stop()),r.close().catch(()=>{})};return{async stop(){const u=r.sampleRate;return o(),cF(oF(lF(l),u,my),my)},cancel:o}}function lF(e){const t=new Float32Array(e.reduce((r,i)=>r+i.length,0));let s=0;for(const r of e)t.set(r,s),s+=r.length;return t}function oF(e,t,s){if(t<=s)return e;const r=t/s,i=new Float32Array(Math.floor(e.length/r));for(let a=0;a<i.length;a++){const l=Math.floor(a*r),o=Math.min(e.length,Math.floor((a+1)*r));let c=0;for(let u=l;u<o;u++)c+=e[u];i[a]=o>l?c/(o-l):0}return i}function cF(e,t){const s=new ArrayBuffer(44+e.length*2),r=new DataView(s),i=(a,l)=>{for(let o=0;o<l.length;o++)r.setUint8(a+o,l.charCodeAt(o))};i(0,"RIFF"),r.setUint32(4,36+e.length*2,!0),i(8,"WAVEfmt "),r.setUint32(16,16,!0),r.setUint16(20,1,!0),r.setUint16(22,1,!0),r.setUint32(24,t,!0),r.setUint32(28,t*2,!0),r.setUint16(32,2,!0),r.setUint16(34,16,!0),i(36,"data"),r.setUint32(40,e.length*2,!0);for(let a=0;a<e.length;a++){const l=Math.max(-1,Math.min(1,e[a]));r.setInt16(44+a*2,Math.round(l<0?l*32768:l*32767),!0)}return new Blob([s],{type:"audio/wav"})}const lp="buddi.readAloud";function _1(){try{return window.localStorage.getItem(lp)==="on"}catch{return!1}}function L1(e){try{e?window.localStorage.setItem(lp,"on"):window.localStorage.removeItem(lp)}catch{}}let Os=null,Yl=null,Ao=0,op=null;const cp=new Set;function rd(e){op!==e&&(op=e,cp.forEach(t=>t()))}function uF(){return op}function dF(e){return cp.add(e),()=>cp.delete(e)}function F1(e){return ol(),rd(e),Ao}function py(e){return e===Ao}function ol(){Ao++,Os&&(Os.pause(),Os.removeAttribute("src")),Yl&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(Yl),Yl=null,rd(null)}async function hF(e,t,s=null){var i;const r=F1(s);try{const a=await fetch(e,{credentials:"same-origin"});if(!a.ok)throw new Error(`The spoken reply could not be fetched (${a.status}).`);const l=new Blob([await a.arrayBuffer()],{type:t});if(r!==Ao)return;Os||(Os=new Audio,(i=Os.addEventListener)==null||i.call(Os,"ended",()=>rd(null))),Yl=URL.createObjectURL(l),Os.src=Yl,await Os.play()}catch(a){throw r===Ao&&rd(null),a}}const fF=new Set(["audio/ogg","audio/mpeg","audio/mp4","audio/wav","audio/x-wav","audio/webm"]);function z1(e){return fF.has(e.toLowerCase().split(";")[0].trim())}function gy(e){if(e===null||!Number.isFinite(e)||e<0)return"–:––";const t=Math.floor(e);return`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`}function U1({artifactId:e,name:t,mime:s,sizeBytes:r}){const i=f.useRef(null),a=f.useRef(null),[l,o]=f.useState(!1),[c,u]=f.useState(!1),[h,d]=f.useState(!1),[m,p]=f.useState(0),[x,j]=f.useState(null);f.useEffect(()=>()=>{var v;(v=i.current)==null||v.pause(),a.current&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(a.current)},[]);const b=async()=>{const v=i.current;if(v){if(l){v.pause();return}ol(),d(!1);try{if(!a.current){u(!0);const w=await fetch(ni(e),{credentials:"same-origin"});if(!w.ok)throw new Error(String(w.status));a.current=URL.createObjectURL(new Blob([await w.arrayBuffer()],{type:s})),v.src=a.current}await v.play()}catch{d(!0)}finally{u(!1)}}},g=h?"Could not play. Download it instead.":`${gy(m)} / ${gy(x)}`;return n.jsxs("span",{className:"wb-audio","data-testid":"audio-card","data-playing":l?"true":void 0,children:[n.jsx("button",{type:"button",className:"ui-icon-btn wb-audio-play","data-size":"sm","aria-label":l?`Pause ${t}`:`Play ${t}`,disabled:c,onClick:()=>void b(),children:n.jsx(we,{name:l?"pause":"play",size:14})}),n.jsxs("span",{className:"wb-file-text",children:[n.jsx("span",{className:"wb-file-name",title:t,children:t}),n.jsxs("span",{className:"wb-file-meta","data-testid":"audio-time",children:[c?"Loading…":g,!h&&$n(r)?` · ${$n(r)}`:""]})]}),n.jsx("a",{className:"ui-icon-btn wb-audio-download","data-size":"sm",href:ni(e),download:t,"aria-label":`Download ${t}`,title:"Download",children:n.jsx(we,{name:"download",size:14})}),n.jsx("audio",{ref:i,preload:"none",onPlay:()=>o(!0),onPause:()=>o(!1),onEnded:()=>{o(!1),p(0)},onTimeUpdate:v=>p(v.currentTarget.currentTime),onLoadedMetadata:v=>j(Number.isFinite(v.currentTarget.duration)?v.currentTarget.duration:null),onDurationChange:v=>j(Number.isFinite(v.currentTarget.duration)?v.currentTarget.duration:null)})]})}const cf=1e5,uf=200,df=30;function B1({artifactId:e,filename:t,mime:s,family:r,available:i=!0}){const[a,l]=f.useState(!1);return i?r==="image"&&!a?n.jsx("figure",{className:"file-preview file-preview-image",children:n.jsx("img",{src:pr(e),alt:t??"Image",onError:()=>l(!0)})}):r==="audio"&&z1(s)?n.jsx("div",{className:"file-preview file-preview-audio",children:n.jsx(U1,{artifactId:e,name:t??"Audio",mime:s})}):r==="pdf"?n.jsx("div",{className:"file-preview file-preview-pdf",children:n.jsx("object",{data:pr(e),type:"application/pdf","aria-label":t??"PDF",children:n.jsx(H,{children:"Your browser cannot show this PDF here. Download it to open it."})})}):r==="text"||r==="code"||r==="table"?n.jsx(mF,{artifactId:e,filename:t,mime:s,family:r}):n.jsx(H,{children:"Preview not supported for this kind of file. Download it to open it."}):n.jsx(H,{children:"The file is no longer available; its record is kept."})}function mF({artifactId:e,filename:t,mime:s,family:r}){const[i,a]=f.useState("loading");if(f.useEffect(()=>{let o=!1;return a("loading"),fetch(pr(e),{credentials:"same-origin"}).then(async c=>{if(!c.ok)throw new Error(String(c.status));const u=await c.text();o||a({text:u.slice(0,cf),truncated:c.headers.get("X-Preview-Truncated")==="1"||u.length>cf})}).catch(()=>{o||a("failed")}),()=>{o=!0}},[e]),i==="loading")return n.jsx("div",{className:"file-preview",children:n.jsx(oe,{children:"Loading preview…"})});if(i==="failed")return n.jsx(H,{children:"The preview could not be loaded. Download the file to open it."});const l=r==="table"&&(/csv|tab-separated/.test(s)||/\.(csv|tsv)$/i.test(t??""));return n.jsxs("div",{className:"file-preview",children:[l?n.jsx(gF,{text:i.text,delimiter:/tab|\.tsv$/i.test(s+(t??""))?" ":","}):n.jsx("pre",{className:"file-preview-text",children:i.text}),i.truncated?n.jsxs("p",{className:"muted",children:["Showing the first ",cf.toLocaleString()," characters. The download has the whole file."]}):null]})}function pF(e,t,s,r){const i=[];let a=[],l="",o=!1,c=!1,u=!1;const h=()=>{a.length<r?a.push(l):c=!0,l=""},d=()=>{h(),i.push(a),a=[]};let m=0;for(;m<e.length;m+=1){if(i.length>=s){u=e.slice(m).trim()!=="";break}const p=e[m];if(o){p==='"'?e[m+1]==='"'?(l+='"',m+=1):o=!1:l+=p;continue}if(p==='"'){o=!0;continue}if(p===t){h();continue}if(p!=="\r"){if(p===`
95
- `){d();continue}l+=p}}return i.length<s&&(l!==""||a.length>0)&&d(),{rows:i,truncatedRows:u,truncatedCols:c}}function gF({text:e,delimiter:t}){const s=f.useMemo(()=>pF(e,t,uf+1,df),[e,t]),[r,...i]=s.rows;if(!r)return n.jsx("p",{className:"muted",children:"The file is empty."});const a=Math.min(df,s.rows.reduce((o,c)=>Math.max(o,c.length),0)),l=Array.from({length:a},(o,c)=>c);return n.jsxs("div",{className:"ui-table-wrap file-preview-table",children:[n.jsxs("table",{className:"ui-table",children:[n.jsx("thead",{children:n.jsx("tr",{children:l.map(o=>n.jsx("th",{children:r[o]??""},o))})}),n.jsx("tbody",{children:i.slice(0,uf).map((o,c)=>n.jsx("tr",{children:l.map(u=>n.jsx("td",{children:o[u]??""},u))},c))})]}),s.truncatedRows||s.truncatedCols?n.jsxs("p",{className:"muted",children:["Showing the first ",uf," rows",s.truncatedCols?` and ${df} columns`:"",". The download has the whole file."]}):null]})}function xF({attachment:e}){const t=$x(e.mime,e.filename),s=e.filename??"Untitled file";return n.jsxs("div",{className:"wb-artifact","data-family":t,"data-testid":"artifact-view",children:[n.jsx(B1,{artifactId:e.artifactId,filename:e.filename??null,mime:e.mime,family:t}),n.jsxs("dl",{className:"ui-kv",children:[n.jsx("dt",{children:"Type"}),n.jsxs("dd",{children:[Ai[t],n.jsx("span",{className:"wb-artifact-mime mono",children:e.mime})]}),e.sizeBytes?n.jsxs(n.Fragment,{children:[n.jsx("dt",{children:"Size"}),n.jsx("dd",{children:$n(e.sizeBytes)})]}):null,n.jsx("dt",{children:"Id"}),n.jsx("dd",{className:"mono",children:e.artifactId})]}),n.jsx("div",{className:"ui-toolbar","data-align":"end",children:n.jsx("a",{className:"ui-btn",href:ni(e.artifactId),download:s,children:"Download"})})]})}const xy=80,vF=["query","path","url","dir"],jF=["message","task"];function _x(e,t){const s=wF(t);if(!s)return null;const r=ra(s.command);if(r!==null){const l=ra(s.name);return Lc(l===null?r:`${l}: ${r}`)}for(const l of vF){const o=ra(s[l]);if(o!==null)return Lc(o)}const i=ra(s.action);if(i!==null){const l=jF.map(o=>ra(s[o])).find(o=>o!==null)??null;return Lc(l===null?i:`${i} · ${l}`)}const a=Object.values(s).filter(l=>typeof l=="string");return a.length===1?Lc(ra(a[0])):null}function ra(e){if(typeof e!="string")return null;const t=e.replace(/\s+/g," ").trim();return t===""?null:t}function Lc(e){return e===null?null:e.length>xy?`${e.slice(0,xy-1)}…`:e}function wF(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const si="agent.delegate";function yF(e){if(e===null||typeof e!="object")return null;const t=e,s=t.conversationId;if(typeof s!="string"||s==="")return null;const r=t.agentId??t.agent;return{conversationId:s,agentId:typeof r=="string"?r:"",runId:typeof t.runId=="string"?t.runId:null}}function bF(e){if(typeof e=="string")return e;if(e===null||typeof e!="object")return null;const t=e.text;return typeof t=="string"?t:null}const up="canvas.show",vy="canvas.clear",jy=12;function Pa(e){return`${e.plugin}/${e.name}`}function kF(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;const t=e.diff;return typeof t=="string"&&t.trim()!==""}function SF({messages:e,descriptors:t}){const s=new Map(t.filter(a=>a.renderer==="preview").map(a=>[a.tool,a]));if(s.size===0)return[];const r=new Map,i=[];for(const a of e)for(const l of a.blocks??[]){if(l.type==="tool_use"&&r.set(l.id,l.name),l.type!=="tool_result"||l.ok===!1)continue;const o=s.get(l.name||r.get(l.toolUseId)||"");if(!o)continue;const c=o1(o,W1(l.output)).props;c.target===null&&c.awaiting!==null&&i.push({...c.awaiting,at:a.at??null})}return i}function NF({messages:e,descriptors:t,awaiting:s,folded:r,served:i}){var u;const a=new Map(t.map(h=>[h.tool,h])),l=new Map;let o=[],c=0;for(const h of e)for(const d of h.blocks??[]){if(d.type==="tool_use"){if(l.set(d.id,{name:d.name,input:d.input,at:h.at??null}),d.name===up){const y=EF(d.id,d.input,h.at??null);y&&o.push(y)}if(d.name===vy&&(o=[]),d.name===si){const y=yF(d.input);y&&o.push({id:d.id,tool:si,title:"Delegation",renderer:"delegate",props:{...y,result:null},at:h.at??null,source:"delegate",substantial:!0})}continue}if(d.type!=="tool_result"||d.name===up||d.name===vy)continue;const m=l.get(d.toolUseId),p=h.at??(m==null?void 0:m.at)??null,x=d.name||(m==null?void 0:m.name)||"tool",j=o.find(y=>y.source==="delegate"&&y.id===d.toolUseId);if(j&&((u=d.delegation)==null?void 0:u.state)==="waiting"){j.props={...j.props,result:null,waiting:{approvalId:d.delegation.approvalId}},d.delegation.approvalId&&(j.tone="warning");continue}if(j){j.props={...j.props,result:{ok:d.ok,text:bF(d.ok?d.output:d.error??d.output),...d.ok&&Zu(d.output).length>0?{files:Zu(d.output)}:{}}},d.ok||(j.tone="critical");continue}const b=d.approval?hp(d):(s==null?void 0:s.get(d.toolUseId))??hp(d);if(b){o.push({id:d.toolUseId,tool:x,title:"Approval",renderer:"envelope",props:{approvalId:b},at:p,tone:"warning",source:"approval",substantial:!0});continue}if(r!=null&&r.has(x))continue;const g=W1(d.output);if(d.ok===!1){o.push({id:d.toolUseId,tool:x,title:Bs(x),renderer:"structured",props:{value:d.error??g??null,failed:!0},at:p,tone:"critical",source:"fallback",substantial:!1});continue}kF(g)&&(c+=1);const v=a.get(x);if(v){const y=o1(v,g),{renderer:N}=y;let{props:k}=y;if(N==="preview"){const S=k,C=S.target??(S.awaiting&&(i!=null&&i.has(Pa(S.awaiting)))?S.awaiting:null);if(C===null)continue;k={...S,target:C,awaiting:null};const I=Pa(C);o=o.filter(A=>!(A.source==="descriptor"&&A.renderer==="preview"&&A.props.target!==null&&Pa(A.props.target)===I))}o.push({id:d.toolUseId,tool:x,title:v.title??Bs(x),renderer:N,props:k,at:p,source:"descriptor",substantial:dp(N,k)});continue}const w={value:Ox(g)?{input:m==null?void 0:m.input,output:g}:g};AF("structured",w)&&o.push({id:d.toolUseId,tool:x,title:Bs(x),renderer:"structured",props:w,at:p,source:"fallback",substantial:dp("structured",w)})}for(const h of o)h.source==="descriptor"&&h.renderer==="preview"&&(h.props={...h.props,changes:c});return CF(o)}const wy="forAgent";function W1(e){if(e===null||typeof e!="object"||Array.isArray(e)||!(wy in e))return e;const{[wy]:t,...s}=e;return s}function CF(e){if(e.length<=jy)return e;const t=e.length-jy;return[...e.slice(0,t).filter(r=>r.source==="approval"),...e.slice(t)]}function EF(e,t,s){if(t===null||typeof t!="object")return null;const{renderer:r,title:i,data:a}=t,l=typeof r=="string"&&sd(r)?r:"structured";return{id:e,tool:up,title:typeof i=="string"&&i.trim()!==""?i:"Shown",renderer:l,props:l==="structured"&&!sd(String(r))?{value:a}:a,at:s,substantial:!0,source:"canvas"}}function AF(e,t){const s=t??{};return!!(s.failed===!0||dp(e,t)||Mx(s.value).kind==="error")}function dp(e,t){const s=t??{};switch(e){case"timeseries":return Rl(s.points)>0;case"bars":return Rl(s.bars)>0;case"keyvalue":return Rl(s.pairs)>0;case"tiles":return s.notice!==!0&&Rl(s.tiles)>0;case"document":return!!s.text||!!s.src;case"diff":return!!s.diff;case"terminal":return!!s.output||!!s.command;case"image":return!!s.artifactId;case"preview":return!!s.target;case"envelope":return!0;case"table":return(Array.isArray(s.groups)?s.groups:[]).some(i=>Rl(i.rows)>0);default:return Ox(s.value)?!0:s.failed===!0?!1:jL(s.value)}}function Rl(e){return Array.isArray(e)?e.length:0}function hp(e){if(e.approval)return e.approval.state==="pending"?e.approval.id:null;for(const t of[e.error,e.output]){const s=K1(t,0);if(s)return s}return null}function TF(e,t,s={}){var o,c;const r=e.flatMap(u=>u.blocks),i=r.find(u=>u.type==="tool_use"&&u.id===t);if((i==null?void 0:i.type)!=="tool_use")return null;const a=r.find(u=>u.type==="tool_result"&&u.toolUseId===t),l=(o=s.redactInputOf)!=null&&o.has(i.name)?H1(i.input):i.input;return{id:t,tool:i.name,title:Bs(i.name),renderer:"structured",props:{value:{input:l,...(a==null?void 0:a.type)==="tool_result"?{status:((c=a.approval)==null?void 0:c.state)??(a.ok?"completed":"failed"),output:a.output,...a.error?{error:a.error}:{}}:{status:"Awaiting result"}}},at:null,source:"fallback",substantial:!1}}const RF=new Set(["value","text","password","secret","code"]);function H1(e){if(e===null||typeof e!="object"||Array.isArray(e))return e;const t={};for(const[s,r]of Object.entries(e))t[s]=RF.has(s)&&typeof r=="string"?"— withheld —":H1(r);return t}function K1(e,t){if(t>3||e===null||typeof e!="object")return null;const s=e,r=s.reason,i=s.actionId??s.approvalId;if(typeof i=="string"&&i!==""&&(r===void 0||r==="approval-required"))return i;for(const a of Object.values(s)){const l=K1(a,t+1);if(l)return l}return null}function Bs(e){const t=e.split(".");return t.length===1?hn(e):t.map(s=>hn(s)).join(" · ")}function nh({name:e,mime:t,sizeBytes:s,thumbnail:r,state:i,error:a,onOpen:l,onRemove:o,size:c="md"}){const u=$x(t,e),h=[Ai[u],$n(s)].filter(Boolean).join(" · "),d=n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"wb-file-visual","data-family":u,children:r?n.jsx("img",{src:r,alt:""}):n.jsx(Lx,{family:u})}),n.jsxs("span",{className:"wb-file-text",children:[n.jsx("span",{className:"wb-file-name",title:e,children:e}),n.jsx("span",{className:"wb-file-meta",children:i==="uploading"?"Uploading…":i==="failed"?"Upload failed":h})]})]});return n.jsxs("span",{className:"wb-file","data-size":c,"data-state":i,"data-thumb":r?"true":void 0,title:i==="failed"?a:void 0,children:[l?n.jsx("button",{type:"button",className:"wb-file-open",onClick:l,"aria-label":`Open ${e}`,children:d}):n.jsx("span",{className:"wb-file-open",children:d}),o?n.jsx("button",{type:"button",className:"wb-file-x","aria-label":`Remove ${e}`,onClick:o,children:n.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:n.jsx("path",{d:"M2.5 2.5l5 5M7.5 2.5l-5 5"})})}):null]})}function Lx({family:e}){const t={width:20,height:20,viewBox:"0 0 20 20","aria-hidden":!0,fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"};switch(e){case"image":return n.jsxs("svg",{...t,children:[n.jsx("rect",{x:"3",y:"4",width:"14",height:"12",rx:"2"}),n.jsx("circle",{cx:"7.5",cy:"8.5",r:"1.4"}),n.jsx("path",{d:"M17 13l-3.6-3.6a1 1 0 0 0-1.4 0L6 15.5"})]});case"pdf":return n.jsxs("svg",{...t,children:[n.jsx("path",{d:"M6 2.5h5.5L16 7v9.5a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-13a1 1 0 0 1 1-1z"}),n.jsx("path",{d:"M11.5 2.5V7H16"}),n.jsx("path",{d:"M7.5 13.5h5M7.5 11h5"})]});case"table":return n.jsxs("svg",{...t,children:[n.jsx("rect",{x:"3",y:"4",width:"14",height:"12",rx:"1.5"}),n.jsx("path",{d:"M3 8.5h14M3 12.5h14M8 4v12M13 4v12"})]});case"text":return n.jsxs("svg",{...t,children:[n.jsx("path",{d:"M6 2.5h5.5L16 7v9.5a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-13a1 1 0 0 1 1-1z"}),n.jsx("path",{d:"M11.5 2.5V7H16"}),n.jsx("path",{d:"M7.5 10.5h5M7.5 13.5h3.5"})]});case"code":return n.jsx("svg",{...t,children:n.jsx("path",{d:"M7 6l-4 4 4 4M13 6l4 4-4 4M11.5 4l-3 12"})});case"audio":return n.jsx("svg",{...t,children:n.jsx("path",{d:"M4 8v4M7.5 5.5v9M11 3.5v13M14.5 6.5v7M18 8.5v3"})});case"video":return n.jsxs("svg",{...t,children:[n.jsx("rect",{x:"3",y:"5",width:"10",height:"10",rx:"1.5"}),n.jsx("path",{d:"M13 9l4-2.5v7L13 11"})]});case"archive":return n.jsxs("svg",{...t,children:[n.jsx("rect",{x:"4",y:"3",width:"12",height:"14",rx:"1.5"}),n.jsx("path",{d:"M10 3v3M10 8v2M10 12v2M8.5 14h3"})]});default:return n.jsxs("svg",{...t,children:[n.jsx("path",{d:"M6 2.5h5.5L16 7v9.5a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-13a1 1 0 0 1 1-1z"}),n.jsx("path",{d:"M11.5 2.5V7H16"})]})}}function IF(e,t,s){const r=by(e),i=by(t==null?void 0:t.input),a=xi(r==null?void 0:r.name)??DF(xi(r==null?void 0:r.handle))??xi(r==null?void 0:r.agent)??xi(i==null?void 0:i.agent),l=typeof e=="string"?e.trim()||null:xi(r==null?void 0:r.text)??xi(r==null?void 0:r.note),o=yy(r==null?void 0:r.durationMs)??yy(r==null?void 0:r.elapsedMs),c=t!=null&&t.at?Date.parse(t.at):NaN,u=s?Date.parse(s):NaN,h=Number.isFinite(c)&&Number.isFinite(u)&&u>=c?u-c:null;return{who:a,question:xi(i==null?void 0:i.task),answer:l,files:Zu(e),durationMs:o??h}}function PF(e,t){var r;let s=null;for(const i of e)for(const a of i.blocks??[])a.type==="tool_result"&&a.name===si&&((r=a.delegation)==null?void 0:r.approvalId)===t&&(s=a.toolUseId);if(s===null)return null;for(const i of e)for(const a of i.blocks??[])if(a.type==="tool_use"&&a.id===s)return{input:a.input,at:i.at||null};return null}function $F({block:e,messages:t,answeredAt:s}){const r=IF(e.output,PF(t,e.actionId),s),i=[r.who?`Asked ${r.who}`:null,r.durationMs===null?null:`took ${MF(r.durationMs)}`].filter(a=>a!==null);return n.jsxs("div",{className:"wb-delegation-result","data-testid":"delegation-result",children:[i.length>0?n.jsx("p",{className:"wb-delegation-facts",children:i.join(" · ")}):null,r.question?n.jsx("blockquote",{className:"wb-delegation-question",children:r.question}):null,r.answer?n.jsx("div",{className:"wb-delegation-answer","data-testid":"delegation-answer",children:n.jsx(mr,{text:r.answer})}):n.jsx("p",{className:"wb-delegation-facts",children:"No answer came back."}),r.files.length>0?n.jsx("div",{className:"wb-msg-files",role:"list","aria-label":`Files ${r.who??"the colleague"} made`,children:r.files.map(a=>n.jsx("a",{role:"listitem",href:ni(a.artifactId),download:!0,children:n.jsx(nh,{name:a.filename??"Untitled file",mime:a.mime,sizeBytes:a.sizeBytes,thumbnail:Px(a.mime)?pr(a.artifactId):null,size:"sm"})},a.artifactId))}):null,n.jsx($t,{summary:"Raw JSON",children:n.jsx("pre",{className:"wb-approval-output mono",children:OF(e.output)})})]})}function MF(e){if(e<1e3)return`${Math.round(e)}ms`;const t=Math.round(e/1e3);if(t<60)return`${t}s`;const s=Math.floor(t/60);return s<60?`${s}m ${String(t%60).padStart(2,"0")}s`:`${Math.floor(s/60)}h ${String(s%60).padStart(2,"0")}m`}function OF(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function DF(e){return e===null?null:`@${e.replace(/^@/,"")}`}function xi(e){return typeof e=="string"&&e.trim()!==""?e:null}function yy(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function by(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const _F=1e3;function LF({messageId:e,text:t,onReadAloud:s}){const[r,i]=f.useState(!1),a=f.useRef(null),l=f.useSyncExternalStore(dF,uF)===e;f.useEffect(()=>()=>{a.current&&clearTimeout(a.current)},[]);const o=()=>{var c;(c=navigator.clipboard)==null||c.writeText(t).then(()=>{i(!0),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>i(!1),_F)},()=>{})};return n.jsxs("div",{className:"wb-reply-actions","data-testid":"reply-actions",children:[n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":r?"Copied":"Copy",title:r?"Copied":"Copy",onClick:o,children:n.jsx(we,{name:r?"check":"copy",size:14})}),r?n.jsx("span",{className:"wb-reply-copied",role:"status",children:"Copied"}):null,s?n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":l?"Stop reading aloud":"Read aloud",title:l?"Stop reading aloud":"Read aloud","aria-pressed":l,onClick:()=>l?ol():s(e,t),children:n.jsx(we,{name:l?"stop":"play",size:14})}):null]})}function FF(e){const t=zF(e);if(!t)return null;const s=hf(t.diff);if(s!==null)return{kind:"diff",diff:s};const r=hf(t.command),i=hf(t.plain),a=ff(t.exitCode);return r!==null&&(i!==null||a!==null||ff(t.pid)!==null)?{kind:"command",command:r,output:i,exitCode:a,elapsedMs:ff(t.elapsedMs)}:null}function hf(e){return typeof e=="string"&&e.trim()!==""?e:null}function ff(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function zF(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const ky="offer:",V1="owner:interjection";function UF(e){return e===V1}function BF(e){if(typeof e!="string"||!e.startsWith(ky))return null;const t=e.slice(ky.length).trim();return t===""?null:t}function Fx({messages:e,live:t,now:s,onOpen:r,working:i=!1,partial:a=null,agents:l,agentId:o,speakers:c,coordinatorId:u,workingAs:h,onOpenFile:d,onReadAloud:m,children:p,agentName:x,emptyHint:j,empty:b,plain:g=!1,workingLine:v,runs:w}){var D;const y=f.useRef(null);f.useEffect(()=>{var U;(U=y.current)==null||U.scrollIntoView({block:"end"})},[e.length,t.length,i,a==null?void 0:a.text.length,a==null?void 0:a.thinking.length,!!p]);const N=a&&!a.settled&&(a.text!==""||a.thinking!==""),k=e.filter(U=>(U.blocks??[]).some(ZF)),S=JF(k,w??[]),C=c??l??[],I=U=>(o&&!c?C.find(V=>V.id===o):void 0)??C.find(V=>V.name===U)??null,A=o?C.find(U=>U.id===o)??null:null,O=i||t.length>0,z=O||!!N,L=!!N&&a.text!=="",E=O&&!L,$=k.at(-1),_=($==null?void 0:$.role)!=="assistant"||!!h,B=h??x??"Assistant",M=k.filter((U,V)=>{var Z;return V===0||(c?(((Z=k[V-1])==null?void 0:Z.speaker)??null)!==(U.speaker??null):k[V-1].role!==U.role)}),W=z&&!_?((D=M.at(-1))==null?void 0:D.id)??null:null;return n.jsx(i1.Provider,{value:l??c??[],children:n.jsxs("div",{className:"wb-messages","data-testid":"messages",children:[k.length===0&&t.length===0?b??n.jsx("p",{className:"wb-chat-empty",children:j}):null,k.map((U,V)=>{const Z=U.speaker??null,ue=c?Z==="owner"||Z===null&&U.role==="user":U.role==="user",Ae=c&&Z==="room",X=c&&Z&&Z!=="owner"&&Z!=="room"?c.find(ce=>ce.id===Z)??null:null,ae=k[V-1],me=V===0||(c?((ae==null?void 0:ae.speaker)??null)!==Z:ae.role!==U.role);if(Ae)return n.jsx("div",{className:"wb-msg wb-msg-room","data-role":"room",children:(U.blocks??[]).filter(ce=>ce.type==="text").map((ce,Te)=>n.jsx("span",{children:ce.text},Te))},U.id);const Pe=(U.blocks??[]).filter(ce=>ce.type==="approval_result");if(Pe.length>0)return n.jsx("div",{className:"wb-msg","data-role":"assistant","data-testid":"approval-result",children:Pe.map((ce,Te)=>n.jsx(e4,{block:ce,messages:e,at:U.at||null},Te))},U.id);const ke=U.role==="user"&&UF(Z),ye=U.role==="user"?BF(Z):null;if(ye){const ce=(U.blocks??[]).filter(Te=>Te.type==="text").map(Te=>Te.text).join(`
96
- `);return n.jsx("div",{className:"wb-msg","data-role":"user","data-testid":"offer-turn",children:n.jsx("div",{className:"wb-bubble wb-bubble-offer",title:ce,children:ye})},U.id)}const Ce=c&&X&&U.role==="user"?YF(U):null;if(Ce){const ce=k.slice(V+1).find(G=>G.role==="assistant"&&G.speaker&&G.speaker!==X.id),Te=ce!=null&&ce.speaker?c.find(G=>G.id===ce.speaker):void 0;return n.jsxs("details",{className:"wb-msg wb-msg-room wb-msg-ask","data-role":"room",children:[n.jsxs("summary",{children:[X.name," asked ",(Te==null?void 0:Te.name)??"a member",Ce.request?`: ${Ce.request.length>120?`${Ce.request.slice(0,119)}…`:Ce.request}`:""]}),Ce.request?n.jsx("p",{children:Ce.request}):null]},U.id)}const ut=S.get(U.id)??null,fe=QF(U,e),Me=!ue&&!ke&&!g?qF(U):"";return n.jsxs("div",{className:"wb-msg","data-role":ue||ke?"user":"assistant",children:[ke?n.jsx("div",{className:"wb-msg-added","data-testid":"added-while-working",children:"added while working"}):null,me&&!ue&&!ke?n.jsx(Sy,{name:X?X.name:x??"Assistant",face:X??A??I(x),moving:E&&W===U.id,children:X&&u===X.id?n.jsx("span",{className:"wb-msg-role",children:"coordinator"}):null}):null,fe.length>0?n.jsx("div",{className:"wb-msg-files",role:"list","aria-label":"Files sent with this message",children:fe.map(ce=>n.jsx("span",{role:"listitem",children:z1(ce.mime)?n.jsx(U1,{artifactId:ce.artifactId,name:ce.filename??"Untitled file",mime:ce.mime,sizeBytes:ce.sizeBytes}):n.jsx(nh,{name:ce.filename??"Untitled file",mime:ce.mime,sizeBytes:ce.sizeBytes,thumbnail:Px(ce.mime)?pr(ce.artifactId):null,...d?{onOpen:()=>d(ce)}:{}})},ce.artifactId))}):null,(U.blocks??[]).map((ce,Te)=>{const G=KF(U.blocks??[],Te,e);if(G==="inside")return null;if(G)return n.jsx(VF,{refusals:G.refusals},Te);if(ce.type==="thinking")return g||ce.text.trim()===""?null:n.jsx(fp,{text:ce.text},Te);if(ce.type==="text")return ce.text.trim()===""?null:ue?n.jsx("div",{className:"wb-bubble",children:ce.text},Te):n.jsx("div",{className:"wb-bubble","data-rich":"true",children:n.jsx(mr,{text:ce.text})},Te);if(ce.type==="attachment")return null;if(ce.type==="tool_use"){if(g)return null;const ie=zx(e,ce.id),$e=ie?s4(ie):null;return n.jsx(mp,{label:$e&&!(ie!=null&&ie.delegation)?`Approval · ${ce.name}`:Bs(ce.name),tool:ce.name,ok:(ie==null?void 0:ie.ok)??null,running:ie===null,...$e?{status:$e.status,waiting:$e.waiting,approval:!0}:{},gist:_x(ce.name,ce.input),body:ie?FF(ie.output):null,opens:!0,onOpen:()=>r(ce.id)},Te)}return null}),ut?n.jsx("div",{className:"wb-msg-budget","data-testid":"budget-stop",children:XF(ut)}):null,Me!==""?n.jsx(LF,{messageId:U.id,text:Me,onReadAloud:m}):null]},U.id)}),z?n.jsxs("div",{className:"wb-msg","data-role":"assistant","data-testid":"live-turn",children:[_?n.jsx(Sy,{name:B,face:I(B)??A,moving:E}):null,N&&a.thinking!==""&&!g?n.jsx(fp,{text:a.thinking,live:a.text==="",seconds:GF(a.thinkingStartedAt,a.textStartedAt??s)}):null,L?n.jsxs("div",{className:"wb-bubble","data-live":"true","data-rich":"true",children:[n.jsx(mr,{text:a.text}),n.jsx("span",{className:"wb-caret","aria-hidden":"true"})]}):null,i&&t.length===0&&!N?n.jsxs("span",{className:"wb-working",role:"status","aria-live":"polite","data-testid":"working",children:[v??`${h??x??"The agent"} is working`,n.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]})]}):null,t.map(U=>n.jsx(mp,{label:Bs(U.name),tool:U.name,ok:null,running:!0,elapsed:Math.max(0,Math.round((s-U.startedAt)/1e3)),opens:!1,onOpen:()=>r(U.toolUseId)},U.toolUseId))]}):null,p,n.jsx("div",{ref:y})]})})}function Sy({name:e,face:t,moving:s=!1,children:r}){const i=(t==null?void 0:t.picture)??null,a=n1(s?i:null);return n.jsxs("div",{className:"wb-msg-who","data-testid":"turn-head",children:[n.jsx("span",{className:"wb-msg-mark","data-moving":s?a&&i?"blob":"ring":void 0,children:s&&a&&i?n.jsx(Xd,{state:"working",size:"sm",still:i,className:"wb-msg-blob"}):n.jsx(Es,{id:(t==null?void 0:t.id)??e,name:(t==null?void 0:t.name)??e,unavailable:t?!t.available:!1,...t?{face:t}:{}})}),n.jsx("span",{children:e}),r]})}function WF(e){var t,s;return((s=(t=/ may delegate to ([^;]*);/.exec(e)??/\(allowed: ([^)]*)\)/.exec(e))==null?void 0:t[1])==null?void 0:s.trim())||null}const HF="delegation refused:";function KF(e,t,s){const r=a=>{const l=e[a];if(!l||l.type!=="tool_use"||l.name!==si)return null;const o=zx(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(HF))return null;const u=l.input??{};return{target:typeof u.agent=="string"&&u.agent!==""?u.agent:"a colleague",message:c}};if(!r(t))return null;if(r(t-1))return"inside";const i=[];for(let a=t;;a+=1){const l=r(a);if(!l)break;i.push(l)}return i.length<2?null:{refusals:i}}function VF({refusals:e}){const[t,s]=f.useState(!1),r=e.map(o=>WF(o.message)).find(o=>o!==null)??null,i=e.map(o=>o.target),a=i.slice(0,3),l=`Delegation refused ${e.length} times: ${a.join(", ")}${i.length>a.length?", …":""}`+(r?` (allowed: ${r})`:"");return n.jsxs("div",{className:"wb-refusals","data-testid":"delegation-refusals","data-open":t||void 0,children:[n.jsxs("button",{type:"button",className:"wb-tool","data-ok":!1,"aria-expanded":t,onClick:()=>s(o=>!o),children:[n.jsx("span",{className:"wb-tool-mark","data-ok":"false","aria-hidden":"true"}),n.jsx("span",{className:"wb-tool-label",children:l}),n.jsx(we,{name:"arrow",className:"wb-tool-arrow"})]}),t?n.jsx("div",{className:"wb-refusals-list",children:e.map((o,c)=>n.jsxs("div",{className:"wb-refusal",children:[n.jsxs("span",{className:"wb-tool","data-static":"true","data-ok":!1,children:[n.jsx("span",{className:"wb-tool-mark","data-ok":"false","aria-hidden":"true"}),n.jsxs("span",{className:"wb-tool-label",children:[Bs(si)," · ",o.target]}),n.jsx("span",{className:"wb-tool-elapsed",children:"refused"})]}),n.jsx("p",{className:"wb-refusal-why",children:o.message})]},c))}):null]})}function GF(e,t){return e===null?null:Math.max(0,Math.round((t-e)/1e3))}function fp({text:e,live:t=!1,seconds:s=null}){const[r,i]=f.useState(!1),a=t?`Thinking${s!==null&&s>0?` · ${s}s`:""}`:s!==null&&s>0?`Thought for ${s}s`:"Thoughts";return n.jsxs("div",{className:"wb-thought","data-live":t||void 0,"data-open":r||void 0,children:[n.jsxs("button",{type:"button",className:"wb-thought-toggle","aria-expanded":r,onClick:()=>i(l=>!l),children:[t?n.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]}):n.jsx(we,{name:"thought"}),n.jsx("span",{children:a}),n.jsx(we,{name:"arrow",className:"wb-tool-arrow"})]}),r?n.jsx("div",{className:"wb-thought-text",children:n.jsx(mr,{text:e})}):null]})}function YF(e){var r;const t=((r=(e.blocks??[]).find(i=>i.type==="text"))==null?void 0:r.text)??"",s=/You are a member of the group "[^"]*"\. @([\w-]+), the coordinator, asks you now:\n\n([\s\S]*?)(?:\n\nAnswer for the room|$)/.exec(t);return s?{handle:s[1],request:s[2].trim()}:null}function qF(e){return(e.blocks??[]).filter(t=>t.type==="text").map(t=>t.text.trim()).filter(t=>t!=="").join(`
97
-
98
- `)}function QF(e,t){const s=[],r=new Set,i=a=>{r.has(a.artifactId)||(r.add(a.artifactId),s.push(a))};for(const a of e.blocks??[])if(a.type==="attachment"&&i(a),a.type==="tool_use"&&a.name===si){const l=zx(t,a.id);l!=null&&l.ok&&Zu(l.output).forEach(i)}return s}function JF(e,t){const s=t.filter(l=>l.startedAt!==null&&l.finishedAt!==null),r=(l,o)=>o.at!==""&&o.at>=l.startedAt&&o.at<=l.finishedAt,i=(l,o)=>l!==o&&l.startedAt>=o.startedAt&&l.finishedAt<=o.finishedAt&&(l.startedAt>o.startedAt||l.finishedAt<o.finishedAt),a=new Map;for(const l of s){if(l.stopped!=="max_turns"&&l.stopped!=="max_tokens"||l.noticed!==!0||l.runId===null)continue;let o=null;for(const c of e)c.role!=="assistant"||!r(l,c)||(o=c);o===null||s.some(c=>i(c,l)&&r(c,o))||a.has(o.id)||a.set(o.id,l)}return a}function XF(e){if(e.stopped==="max_tokens")return"Length limit reached · answer cut off";const t=e.turns;return t===null?"Turn budget reached":`Turn budget reached · ${t} ${t===1?"step":"steps"}`}function ZF(e){return e.type==="text"||e.type==="thinking"?e.text.trim()!=="":e.type==="tool_use"||e.type==="attachment"||e.type==="approval_result"}function e4({block:e,messages:t,at:s}){const[r,i]=f.useState(!1),a=e.state==="succeeded";return n.jsxs("div",{className:"wb-approval","data-open":r||void 0,children:[n.jsxs("button",{type:"button",className:"wb-tool","data-ok":a,"aria-expanded":r,onClick:()=>i(l=>!l),children:[n.jsx("span",{className:"wb-tool-mark","data-ok":a?"true":"false","aria-hidden":"true"}),n.jsx("span",{className:"wb-tool-label",children:e.name===""?"Approved action":Bs(e.name)}),n.jsx("span",{className:"wb-tool-elapsed",children:e.state}),n.jsx(we,{name:"arrow",className:"wb-tool-arrow"})]}),r&&e.name===si?n.jsx($F,{block:e,messages:t,answeredAt:s}):null,r&&e.name!==si?n.jsx("pre",{className:"wb-approval-output mono",children:t4(e.output)}):null]})}function t4(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}const n4=40;function s4(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(hp(e))return{status:"waiting",waiting:!0};const t=(r=e.approval)==null?void 0:r.state;return t?t==="approved"||t==="executing"?{status:"approved",waiting:!0}:t==="succeeded"?{status:"approved",waiting:!1}:{status:t,waiting:!1}:null}function mp({label:e,tool:t,ok:s,running:r,elapsed:i,opens:a,onOpen:l,status:o,waiting:c=!1,approval:u=!1,gist:h=null,body:d=null}){const[m,p]=f.useState(!1),x=n.jsxs(n.Fragment,{children:[r?n.jsx("span",{className:"wb-pulse","aria-hidden":"true"}):n.jsx("span",{className:"wb-tool-mark","data-ok":c?"pending":s===!1?"false":"true","aria-hidden":"true"}),n.jsx("span",{className:"wb-tool-label",children:e}),h?n.jsx("span",{className:"wb-tool-gist mono","data-testid":"tool-gist",children:h}):null,i===void 0?null:n.jsxs("span",{className:"wb-tool-elapsed",children:[i,"s"]}),o||s===!1?n.jsx("span",{className:"wb-tool-elapsed",children:o??"failed"}):null]}),j={"data-ok":s===null?void 0:s,"data-running":r,"data-gist":h?!0:void 0,"data-approval":u||void 0};return d?n.jsxs("div",{className:"wb-toolcall","data-open":m||void 0,children:[n.jsxs("div",{className:"wb-tool","data-split":"true",...j,children:[n.jsxs("button",{type:"button",className:"wb-tool-toggle","aria-expanded":m,onClick:()=>p(b=>!b),children:[n.jsx(we,{name:"chevron",className:"wb-tool-chevron"}),x]}),a?n.jsxs(jo,{children:[n.jsx(wo,{asChild:!0,children:n.jsx("button",{type:"button",className:"wb-tool-open","aria-label":"Open on the canvas",onClick:l,children:n.jsx(we,{name:"arrow",className:"wb-tool-arrow"})})}),n.jsx(yo,{children:n.jsxs(bo,{className:"ui-tip",sideOffset:6,children:[n.jsx("span",{className:"ui-tip-title",children:"Open on the canvas"}),n.jsx("span",{className:"ui-tip-hint mono",children:t})]})})]}):null]}),m?n.jsx(r4,{body:d,onOpen:a?l:null}):null]}):a?n.jsxs(jo,{children:[n.jsx(wo,{asChild:!0,children:n.jsxs("button",{className:"wb-tool",...j,onClick:l,children:[x,n.jsx(we,{name:"arrow",className:"wb-tool-arrow"})]})}),n.jsx(yo,{children:n.jsxs(bo,{className:"ui-tip",sideOffset:6,children:[n.jsx("span",{className:"ui-tip-title",children:"Open on the canvas"}),n.jsx("span",{className:"ui-tip-hint mono",children:t})]})})]}):n.jsx("span",{className:"wb-tool","data-static":"true",...j,children:x})}function r4({body:e,onOpen:t}){const s=t?{label:"Open on the canvas",onClick:t}:void 0;if(e.kind==="diff")return n.jsx("div",{className:"wb-tool-body","data-kind":"diff","data-testid":"tool-body",children:n.jsx(qu,{text:e.diff,limit:n4,...s?{more:s}:{}})});const r=[e.exitCode===null?null:`exit ${e.exitCode}`,e.elapsedMs===null?null:i4(e.elapsedMs)].filter(i=>i!==null);return n.jsxs("div",{className:"wb-tool-body","data-kind":"command","data-testid":"tool-body",children:[n.jsxs("div",{className:"wb-tool-command",children:[n.jsx("code",{className:"mono",children:e.command}),r.length>0?n.jsx("span",{className:"wb-tool-facts","data-failed":e.exitCode!==null&&e.exitCode!==0?!0:void 0,children:r.join(" · ")}):null]}),e.output?n.jsx("pre",{className:"wb-tool-output",children:e.output}):null]})}function i4(e){return e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(1)}s`}function zx(e,t){for(const s of e)for(const r of s.blocks??[])if(r.type==="tool_result"&&r.toolUseId===t)return r;return null}const G1="approval-dock";function a4(){var t;const e=document.getElementById(G1);e&&((t=e.scrollIntoView)==null||t.call(e,{block:"nearest"}),e.focus())}const l4=["workspace","cwd","workdir","root"];function o4({approvals:e,timezone:t,now:s,version:r,onDecided:i,onSay:a,onOpenFull:l}){const[o,c]=f.useState([]),u=e.filter(m=>!o.includes(m.approvalId)),h=u[0];if(!h)return null;const d=m=>c(p=>p.includes(m)?p:[...p,m]);return n.jsx(c4,{item:h,count:u.length,timezone:t,now:s,version:r,onSettled:m=>{d(h.approvalId),m&&i(m)},onSay:a,onOpenFull:()=>l(h.toolUseId)},h.approvalId)}function c4({item:e,count:t,timezone:s,now:r,version:i,onSettled:a,onSay:l,onOpenFull:o}){var C;const[c,u]=f.useState(null),[h,d]=f.useState(null),[m,p]=f.useState(null),[x,j]=f.useState("");f.useEffect(()=>{let I=!1;return T.approval(e.approvalId).then(A=>{I||(u(A),A.state!=="pending"&&a(A))}).catch(A=>{I||d(A instanceof pe?A.message:String(A))}),()=>{I=!0}},[e.approvalId,i]);const b=c!==null&&c.state==="pending"&&Date.parse(c.expiresAt)<=r;f.useEffect(()=>{b&&c&&a({...c,state:"expired"})},[b]);const{values:g,controls:v}=Rx(c==null?void 0:c.choices),w=(I,A)=>{const O=x.trim();p(I),d(null),(g&&I==="approve"?T.decide(e.approvalId,I,A,g):T.decide(e.approvalId,I,A)).then(z=>{a(z.action),O&&l(O)}).catch(z=>{d(z instanceof pe?z.message:String(z)),p(null)})},y=m!==null||c===null||c.state!=="pending",N=((C=c==null?void 0:c.permissionScopes)==null?void 0:C.includes("always"))??!1,k=c?_x(c.tool,c.canonicalArgs)??d4(c.preview):null,S=c?u4(c):null;return n.jsxs("section",{id:G1,tabIndex:-1,className:"wb-question","data-kind":"approval","aria-label":"Approval needed","data-testid":"approval-dock",children:[n.jsxs("div",{className:"wb-question-head",children:[n.jsx("span",{className:"wb-question-kicker",children:"Needs your OK"}),t>1?n.jsxs("span",{className:"wb-dock-count","data-testid":"approval-dock-count",children:["1 of ",t]}):null,n.jsx("strong",{children:c?Bs(c.tool):"Loading the request…"}),e.askedBy?n.jsx("span",{className:"wb-dock-asker","data-testid":"approval-dock-asker",children:e.askedBy}):null]}),k||S?n.jsxs("div",{className:"wb-dock-section wb-dock-subject",children:[k?n.jsx("code",{className:"wb-dock-gist",children:k}):null,S?n.jsxs("span",{className:"wb-dock-where",children:["in ",n.jsx("span",{className:"mono",children:S})]}):null]}):null,v?n.jsx("div",{className:"wb-dock-section",children:v}):null,n.jsx(se,{message:h}),n.jsx("div",{className:"wb-dock-section",children:n.jsx("input",{className:"wb-dock-instead",value:x,onChange:I=>j(I.target.value),onKeyDown:I=>{I.key==="Enter"&&I.preventDefault()},placeholder:"Tell the agent what to do instead (optional)","aria-label":"Tell the agent what to do instead (optional)",disabled:m!==null})}),n.jsxs("div",{className:"wb-dock-section wb-dock-actions",children:[n.jsxs("span",{className:"wb-dock-meta",children:[c?n.jsxs(n.Fragment,{children:["Expires ",Be(c.expiresAt,s)," · "]}):null,n.jsx("button",{type:"button",className:"wb-link",onClick:o,children:"See the full request on the Canvas"})]}),n.jsx(R,{variant:"ghost",size:"sm",disabled:y,onClick:()=>w("reject"),children:m==="reject"?"Rejecting…":"Reject"}),N?n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",size:"sm",disabled:y,onClick:()=>w("approve","conversation"),children:"Auto: this conversation"}),n.jsx(R,{size:"sm",disabled:y,onClick:()=>w("approve","always"),children:"Always: this agent"})]}):null,n.jsx(R,{variant:"good",size:"sm",disabled:y,onClick:()=>w("approve"),children:m==="approve"?"Approving…":N?"Allow once":"Approve"})]})]})}function u4(e){for(const t of[e.canonicalArgs,e.envelope])if(!(t===null||typeof t!="object"||Array.isArray(t)))for(const s of l4){const r=t[s];if(typeof r=="string"&&r.trim()!=="")return r.trim()}return null}function d4(e){const t=(e??"").split(`
99
- `).map(s=>s.trim()).find(Boolean);return t?t.length>160?`${t.slice(0,157)}…`:t:null}const h4=2e3;function f4({conversationId:e,agentId:t,runId:s=null,result:r=null,waiting:i=null,agents:a=[]}){const l=r!==null,[o,c]=f.useState(l),u=!o||i!==null,{data:h,error:d}=le(()=>Le.conversation(e),[e,o,(i==null?void 0:i.approvalId)??null],u?h4:void 0),m=(h==null?void 0:h.runs)??[],p=s===null?null:m.find(y=>y.runId===s)??null,x=l||i===null&&(s!==null?p!==null&&p.finishedAt!==null:m.length>0&&m.every(y=>y.finishedAt!==null));f.useEffect(()=>{x&&c(!0)},[x]);const j=r?r.ok?"done":"failed":i!=null&&i.approvalId?"waiting":x?"done":"working",b=a.find(y=>y.id===t)??null,g=(b==null?void 0:b.name)??(h==null?void 0:h.agentId)??t,v=(h==null?void 0:h.messages)??[],w=(r==null?void 0:r.text)??m4(v);return n.jsxs("div",{className:"wb-delegate","data-testid":"delegate-view","data-status":j,children:[n.jsxs("header",{className:"wb-delegate-head",children:[n.jsx(Nn,{agents:a,id:t}),n.jsxs("div",{className:"wb-delegate-who",children:[n.jsx("strong",{children:g}),n.jsx("span",{className:"wb-delegate-status","data-status":j,role:"status",children:j==="working"?n.jsxs(n.Fragment,{children:["Working",n.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]})]}):j==="waiting"?"Waiting for your approval":j==="failed"?"Failed":"Done"})]})]}),d?n.jsx("p",{className:"muted",children:d}):null,n.jsx("div",{className:"wb-delegate-work",children:v.map((y,N)=>n.jsx("div",{className:"wb-delegate-turn",children:(y.blocks??[]).map((k,S)=>{if(k.type==="thinking")return k.text.trim()===""?null:n.jsx(fp,{text:k.text},S);if(k.type==="tool_use"){const C=g4(p4(v,k.id));return n.jsx(mp,{label:Bs(k.name),tool:k.name,ok:C.ok,running:C.running,waiting:C.waiting,status:C.status,gist:_x(k.name,k.input),opens:!1,onOpen:()=>{}},S)}return null})},y.id??N))}),w?n.jsx("div",{className:"wb-delegate-answer","data-testid":"delegate-answer",children:n.jsx(mr,{text:w})}):j==="working"||j==="waiting"?n.jsxs("p",{className:"muted",children:[g," has not answered yet."]}):null,r!=null&&r.files&&r.files.length>0?n.jsx("div",{className:"wb-msg-files",role:"list","aria-label":`Files ${g} made`,"data-testid":"delegate-files",children:r.files.map(y=>n.jsx("a",{role:"listitem",href:ni(y.artifactId),download:!0,children:n.jsx(nh,{name:y.filename??"Untitled file",mime:y.mime,sizeBytes:y.sizeBytes,thumbnail:Px(y.mime)?pr(y.artifactId):null})},y.artifactId))}):null,n.jsxs("div",{className:"wb-delegate-actions",children:[j==="waiting"?n.jsx(R,{variant:"accent",onClick:()=>a4(),"data-testid":"delegate-to-approval",children:"Go to the approval"}):null,n.jsx("a",{className:"ui-btn",href:Ve(t||(h==null?void 0:h.agentId)||"",e),children:"Open this conversation"})]})]})}function m4(e){for(let t=e.length-1;t>=0;t-=1){const s=e[t];if(s.role!=="assistant")continue;const r=(s.blocks??[]).filter(i=>i.type==="text").map(i=>i.text.trim()).filter(i=>i!=="").join(`
100
-
101
- `);if(r!=="")return r}return null}function p4(e,t){for(const s of e)for(const r of s.blocks??[])if(r.type==="tool_result"&&r.toolUseId===t)return r;return null}function g4(e){var s;if(e===null)return{running:!0,ok:null,waiting:!1,status:void 0};const t=(s=e.approval)==null?void 0:s.state;return t==="pending"?{running:!1,ok:null,waiting:!0,status:"waiting approval"}:t==="approved"||t==="executing"?{running:!0,ok:null,waiting:!1,status:"running"}:t==="succeeded"?{running:!1,ok:!0,waiting:!1,status:void 0}:t?{running:!1,ok:!1,waiting:!1,status:t}:{running:!1,ok:e.ok,waiting:!1,status:void 0}}const Ny=1024*1024;function x4({files:e,agentId:t,root:s,revision:r}){const[i,a]=f.useState({kind:"dir",path:""});return f.useEffect(()=>a({kind:"dir",path:""}),[e.plugin,t]),n.jsx("div",{className:"wb-files","data-testid":"files-view",children:i.kind==="dir"?n.jsx(v4,{files:e,agentId:t,root:s,path:i.path,revision:r,go:a}):n.jsx(j4,{files:e,agentId:t,root:s,path:i.path,revision:r,go:a})})}function Y1({root:e,path:t,go:s}){const r=t===""?[]:t.split("/"),i=[{label:e,path:""},...r.map((a,l)=>({label:a,path:r.slice(0,l+1).join("/")}))];return n.jsx("nav",{className:"wb-files-crumbs","aria-label":"Where you are in the workspace",children:i.map((a,l)=>{const o=l===i.length-1;return n.jsxs("span",{className:"wb-files-crumb",children:[l>0?n.jsx("span",{className:"wb-files-sep","aria-hidden":"true",children:"/"}):null,o?n.jsx("span",{className:"wb-files-here mono","aria-current":"location",children:a.label}):n.jsx("button",{type:"button",className:"wb-files-step mono",onClick:()=>s({kind:"dir",path:a.path}),children:a.label})]},a.path)})})}function v4({files:e,agentId:t,root:s,path:r,revision:i,go:a}){const[l,o]=f.useState(null),[c,u]=f.useState(null),[h,d]=f.useState(!1),[m,p]=f.useState(null);f.useEffect(()=>{let b=!1;return u(null),T.pageQuery(e.plugin,e.list,{agent:t,...r?{path:r}:{}}).then(g=>{b||o(g.data)}).catch(g=>{b||u(g instanceof Error?g.message:String(g))}),()=>{b=!0}},[e.plugin,e.list,t,r,i]),f.useEffect(()=>p(null),[r]);const x=async()=>{d(!0),p(null);try{const b=await fetch(T.pageFileUrl(e.plugin,e.archive,{agent:t,...r?{path:r}:{}}),{credentials:"same-origin"});if(!b.ok){const y=await b.json().catch(()=>null);p((y==null?void 0:y.error)??"The archive could not be made.");return}const g=await b.blob(),v=URL.createObjectURL(g),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{d(!1)}},j=l&&l.path===r?l.entries:null;return n.jsxs(n.Fragment,{children:[n.jsxs(Q,{children:[n.jsx(Y1,{root:s,path:r,go:a}),n.jsx(en,{}),n.jsx(R,{size:"sm",onClick:()=>void x(),disabled:h||j===null||j.length===0,children:h?"Packing…":"Download as archive"})]}),m?n.jsx(H,{tone:"warning",role:"alert",children:m}):null,c?n.jsx(H,{tone:"critical",role:"alert",children:c}):null,j===null?c?null:n.jsx(oe,{children:"Reading the folder…"}):j.length===0?n.jsx(oe,{children:r===""?n.jsxs(n.Fragment,{children:["Nothing in this workspace yet. To hand the agent a file, add it to the ",n.jsx("a",{href:_i,children:"Files library"})," and mention it here."]}):"This folder is empty."}):n.jsx(At,{children:j.map(b=>n.jsx(Tt,{href:"#",onClick:()=>a({kind:b.kind,path:b.path}),lead:n.jsx(y4,{kind:b.kind}),title:n.jsxs("span",{className:"mono",children:[b.name,b.kind==="dir"?"/":""]}),side:b.kind==="file"?$n(b.bytes):void 0},b.path))}),l&&l.path===r&&(l.skipped>0||l.truncated)?n.jsxs("p",{className:"wb-files-note",children:[l.truncated?`Only the first ${l.entries.length} entries are shown. `:"",l.skipped>0?`${l.skipped} ${l.skipped===1?"entry is":"entries are"} not shown: symbolic links and protected paths are never read.`:""]}):null]})}function j4({files:e,agentId:t,root:s,path:r,revision:i,go:a}){const[l,o]=f.useState(null),[c,u]=f.useState(null),[h,d]=f.useState(!1);f.useEffect(()=>{let g=!1;return u(null),T.pageQuery(e.plugin,e.stat,{agent:t,path:r}).then(v=>{g||o(v.data)}).catch(v=>{g||u(v instanceof Error?v.message:String(v))}),()=>{g=!0}},[e.plugin,e.stat,t,r,i]);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:t,path:r,v:p}):"",j=T.pageFileUrl(e.plugin,e.read,{agent:t,path:r,download:"1"}),b=(m==null?void 0:m.type)==="text"&&m.bytes<=Ny;return n.jsxs(n.Fragment,{children:[n.jsxs(Q,{children:[n.jsx(Y1,{root:s,path:r,go:a}),n.jsx(en,{}),b?n.jsx(R,{size:"sm","aria-pressed":h,onClick:()=>d(g=>!g),children:"Wrap"}):null,n.jsx(Zt,{size:"sm",href:j,download:(m==null?void 0:m.name)??r.split("/").at(-1),children:"Download"})]}),c?n.jsx(H,{tone:"critical",role:"alert",children:c}):null,m===null?c?null:n.jsx(oe,{children:"Reading the file…"}):m.type==="image"?n.jsx("figure",{className:"wb-files-picture",children:n.jsx("img",{src:x,alt:m.name})}):m.type==="pdf"?n.jsx("div",{className:"file-preview file-preview-pdf",children:n.jsx("object",{data:x,type:"application/pdf","aria-label":m.name,children:n.jsx(H,{children:"Your browser cannot show this PDF here. Download it to open it."})})}):b?n.jsx(w4,{src:x,wrap:h}):n.jsxs(n.Fragment,{children:[n.jsx(H,{children:m.type==="text"?`This file is over ${$n(Ny)}, too long to read here. Download it to open it.`:"This kind of file is not shown here. Download it to open it."}),n.jsx(Vt,{items:[{label:"Size",value:$n(m.bytes)},{label:"Type",value:n.jsx("span",{className:"mono",children:m.mime})}]})]})]})}function w4({src:e,wrap:t}){const[s,r]=f.useState(null),[i,a]=f.useState(!1);return f.useEffect(()=>{let l=!1;return a(!1),fetch(e,{credentials:"same-origin"}).then(async o=>{if(!o.ok)throw new Error(String(o.status));const c=await o.text();l||r(c)}).catch(()=>{l||a(!0)}),()=>{l=!0}},[e]),i?n.jsx(H,{tone:"critical",children:"The file could not be read."}):s===null?n.jsx(oe,{children:"Reading the file…"}):s===""?n.jsx(oe,{children:"This file is empty."}):n.jsx("pre",{className:"wb-files-text","data-wrap":t?"true":void 0,"data-testid":"files-text",children:s})}function y4({kind:e}){return n.jsx("span",{className:"wb-files-icon","data-kind":e,"aria-hidden":"true",children:n.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.4,strokeLinecap:"round",strokeLinejoin:"round",children:e==="dir"?n.jsx("path",{d:"M2 4.2h4.2l1.4 1.6H14v7H2z"}):n.jsx("path",{d:"M4 2.4h5l3 3v8.2H4zM9 2.4v3h3"})})})}const b4=3,k4=152,S4=104,N4=100,C4=2,Cy=5;function E4({renderables:e,activeId:t,onActivate:s,timezone:r,onDecided:i,onChangeAgent:a,face:l,descriptors:o,grantedTools:c,agentName:u,maxTabs:h,browserPanel:d,agents:m,onClose:p,loading:x=!1}){const[j,b]=A4(h);if(e.length===0)return n.jsxs("div",{className:"wb-canvas","data-testid":"canvas",children:[n.jsx("div",{className:"wb-canvas-tabs",ref:j,"aria-hidden":"true",children:n.jsx("span",{className:"wb-canvas-label",children:"Canvas"})}),n.jsx("div",{className:"wb-canvas-body wb-canvas-body-empty",children:x?null:n.jsxs("div",{className:"wb-empty",children:[l?n.jsx("span",{className:"wb-empty-face",children:l}):null,n.jsx("p",{className:"ui-empty wb-empty-line",children:$4(u,M4(o??[],c??[]))})]})})]});const g=e.some(y=>y.id===t)?t:e[e.length-1].id,{shown:v,hidden:w}=T4(e,g,b);return n.jsx("div",{className:"wb-canvas","data-testid":"canvas",children:n.jsxs(kO,{value:g,onValueChange:s,className:"contents",children:[n.jsxs("div",{className:"wb-canvas-tabs",ref:j,children:[n.jsx("span",{className:"wb-canvas-label","aria-hidden":"true",children:"Canvas"}),n.jsx(SO,{className:"wb-tabstrip","aria-label":"Canvas",children:v.map(y=>n.jsxs("div",{className:"wb-tab-item",children:[n.jsxs(NO,{value:y.id,className:"wb-tab","data-tone":y.tone,onKeyDown:N=>{N.key==="Delete"&&p&&Ey(y)&&(N.preventDefault(),p(y.id))},children:[y.tone==="warning"||y.tone==="critical"?n.jsx("span",{className:"wb-tab-dot","data-tone":y.tone,"aria-hidden":"true"}):null,n.jsx("span",{className:"wb-tab-text",children:y.title})]}),p&&Ey(y)?n.jsx("button",{className:"wb-tab-close","aria-label":`Close ${y.title} tab`,title:"Dismiss panel; keep conversation history",onClick:()=>p(y.id),children:"×"}):null]},y.id))}),n.jsx(R4,{items:w,onActivate:s,timezone:r})]}),e.map(y=>n.jsx(CO,{value:y.id,className:"wb-canvas-body","data-renderer":y.source==="descriptor"&&y.renderer==="preview"?"preview":void 0,"data-dense":D4.has(y.renderer)?"true":void 0,children:n.jsxs("section",{className:"ui-panel","data-flush":y.source==="descriptor"&&y.renderer==="preview"?"true":void 0,children:[y.source!=="browser"&&y.source!=="files"&&!(y.source==="descriptor"&&y.renderer==="preview")?n.jsxs("header",{className:"ui-panel-head",children:[n.jsx("h2",{className:"ui-panel-title",children:y.title}),n.jsx("span",{className:"ui-panel-tool mono",children:y.tool})]}):null,y.tone==="critical"?n.jsxs("p",{className:"muted",children:["Recorded tool failure",y.at?` · ${new Date(y.at).toLocaleString()}`:"",". This is history, not live session status."]}):null,y.source==="browser"?d:y.source==="profile"?n.jsx(YL,{...y.props,...a?{onChange:a}:{}}):y.source==="artifact"?n.jsx(xF,{...y.props}):y.source==="files"?n.jsx(x4,{...y.props}):y.source==="delegate"?n.jsx(f4,{...y.props,agents:m??[]}):n.jsx(GL,{renderer:y.renderer,props:y.props,timezone:r,onDecided:i})]})},y.id))]})})}function Ey(e){return e.source==="approval"?!1:e.source==="browser"?e.pinned!==!0:e.source!=="files"}function A4(e){const[t,s]=f.useState(Cy),r=f.useRef(null);return[f.useCallback(a=>{var o;if((o=r.current)==null||o.disconnect(),r.current=null,!a||e!==void 0||typeof ResizeObserver>"u")return;const l=()=>{const c=a.clientWidth;if(c===0)return;const u=Math.floor((c-N4-S4)/k4);s(Math.max(C4,Math.min(Cy,u)))};l(),r.current=new ResizeObserver(l),r.current.observe(a)},[e]),e??t]}function T4(e,t,s){const r=new Set(e.filter(a=>a.id===t||a.source==="approval"||a.pinned===!0).map(a=>a.id)),i=new Set(r);for(let a=e.length-1;a>=0&&i.size<s;a-=1)i.add(e[a].id);return{shown:e.filter(a=>i.has(a.id)),hidden:e.filter(a=>!i.has(a.id))}}function R4({items:e,onActivate:t,timezone:s}){if(e.length===0)return null;const r=e.some(i=>i.tone==="critical")?"critical":e.some(i=>i.tone==="warning")?"warning":null;return n.jsxs(Kd,{modal:!1,children:[n.jsx(Vd,{asChild:!0,children:n.jsxs("button",{className:"wb-tab wb-tab-more","data-tone":r??void 0,"aria-label":`${e.length} more ${e.length===1?"view":"views"} in this conversation`,children:[r?n.jsx("span",{className:"wb-tab-dot","data-tone":r,"aria-hidden":"true"}):null,n.jsxs("span",{className:"wb-tab-text",children:[e.length," more"]}),n.jsx(we,{name:"chevron-down"})]})}),n.jsx(Wo,{children:n.jsxs(Gd,{className:"ui-menu","data-wide":"true",align:"end",sideOffset:6,children:[n.jsx(Yd,{className:"ui-menu-label",children:"Earlier in this conversation"}),[...e].reverse().map(i=>n.jsxs(Ei,{className:"ui-menu-item",onSelect:()=>t(i.id),children:[n.jsxs("span",{className:"ui-menu-item-text",children:[i.tone==="warning"||i.tone==="critical"?n.jsx("span",{className:"wb-tab-dot","data-tone":i.tone,"aria-hidden":"true"}):null,i.title]}),n.jsx("span",{className:"ui-menu-note mono",children:I4(i.at,s)??i.tool})]},i.id))]})})]})}function I4(e,t){if(!e)return null;const s=new Date(e);return Number.isNaN(s.getTime())?null:new Intl.DateTimeFormat("en-GB",{timeZone:t,hour:"2-digit",minute:"2-digit"}).format(s)}const P4={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 $4(e,t){const s=e?`What ${e} shows you`:"What your agent shows you",r=[...new Set(t.map(i=>P4[i.renderer]??"results"))].slice(0,3);return r.length>0?`${s} lands here: ${r.join(", ")}.`:`${s} lands here.`}function M4(e,t){const s=new Set(t),r=new Set,i=e.filter(c=>{if(!s.has(c.tool))return!1;const u=O4(c);return r.has(u)?!1:(r.add(u),!0)}),a=new Set,l=i.filter(c=>a.has(c.renderer)?!1:(a.add(c.renderer),!0)),o=i.filter(c=>!l.includes(c));return[...l,...o].slice(0,b4)}function O4(e){return e.title&&e.title.trim()!==""?e.title:e.tool.split(".").map(t=>t.replace(/[_-]+/g," ")).join(" · ").replace(/\b\w/,t=>t.toUpperCase())}const D4=new Set(["table","diff","files"]),_4=3.5*6e4,L4=2e3;function F4(e,t,s={}){const[r,i]=f.useState({served:new Set,live:new Set,scope:t}),a=f.useRef(r.served);if(r.scope!==t){const u={served:new Set,live:new Set,scope:t};a.current=u.served,i(u)}const l=s.check??T.previewCheck,o=s.everyMs??L4,c=e.map(u=>`${Pa(u)}@${u.at??""}`).join("|");return f.useEffect(()=>{const u=new Map;for(const p of e){const x=Pa(p);if(a.current.has(x))continue;const j=p.at===null?Number.NaN:Date.parse(p.at),b=Number.isNaN(j)?0:j+_4,g=u.get(x);(!g||b>g.until)&&u.set(x,{plugin:p.plugin,name:p.name,until:b})}if(u.size===0)return;let h=!1,d;const m=async()=>{const p=Date.now();for(const[x,j]of[...u]){const b=await l(j.plugin,j.name).catch(()=>null);if(h)return;const g=p<=j.until;b!=null&&b.ok?(u.delete(x),i(v=>{const w={served:new Set(v.served).add(x),live:g?new Set(v.live).add(x):v.live,scope:v.scope};return a.current=w.served,w})):g||u.delete(x)}!h&&u.size>0&&(d=setTimeout(()=>void m(),o))};return m(),()=>{h=!0,d!==void 0&&clearTimeout(d)}},[c,t,l,o]),r}const pp="workspace-files";function z4(e){let t=0;for(const s of e)for(const r of s.blocks??[]){if(r.type!=="tool_result"||r.ok===!1)continue;const i=r.output;if(i===null||typeof i!="object"||Array.isArray(i))continue;const{diff:a,path:l}=i;typeof a=="string"&&a.trim()!==""&&typeof l=="string"&&l!==""&&(t+=1)}return t}function U4(e){const[t,s]=f.useState(null);return f.useEffect(()=>{if(s(null),!e)return;let r=!1;return(async()=>{var a;const i=await T.pages();for(const l of Array.isArray(i==null?void 0:i.files)?i.files:[]){const o=await T.pageQuery(l.plugin,l.workspace,{agent:e}).catch(()=>null),c=(a=o==null?void 0:o.data)==null?void 0:a.workspace;if(c&&typeof c.name=="string")return{files:l,agentId:e,root:c.name}}return null})().then(i=>{r||s(i)}).catch(()=>{}),()=>{r=!0}},[e]),t&&t.agentId===e?t:null}function B4(e,t){return{id:pp,tool:"",title:"Files",renderer:"files",props:{files:e.files,agentId:e.agentId,root:e.root,revision:t},at:null,source:"files",pinned:!0,substantial:!1}}function gp(e){return`agent-properties:${e}`}function W4(e){return{id:gp(e.id),tool:`@${e.handle}`,title:"Properties",renderer:"profile",props:{profile:e},at:null,source:"profile",substantial:!1}}function H4(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 q1({progress:e}){return n.jsxs(J,{gap:"sm",children:[n.jsx("span",{role:"status",children:H4(e)}),n.jsx(x1,{value:(e==null?void 0:e.percent)??0,label:"Fetching the browser"})]})}function K4(e,t,s,r){const i=e.width||1,a=e.height||1,l=t.pageScaleFactor||1,o=(s-e.left)*(t.deviceWidth/i)/l,c=((r-e.top)*(t.deviceHeight/a)-t.offsetTop)/l,u=(h,d)=>Math.max(0,Math.min(Math.round(h),Math.round(d)));return{x:u(o,t.deviceWidth),y:u(c,t.deviceHeight)}}function mf(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}function Ay(e){return[...e].length===1&&e.codePointAt(0)>=32&&e.codePointAt(0)!==127}const V4=4e3;function G4(e){return e.replace(/\r\n?/g,`
102
- `).replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g,"").slice(0,V4)}const Y4=["left","middle","right"],q4=33;function Q4(e,t){return e.deviceWidth===t.deviceWidth&&e.deviceHeight===t.deviceHeight&&e.pageScaleFactor===t.pageScaleFactor&&e.offsetTop===t.offsetTop}function J4(e){if(e.byteLength<3)return null;const t=new DataView(e);if(t.getUint8(0)!==1)return null;const s=t.getUint16(1);if(e.byteLength<3+s)return null;try{return{metadata:JSON.parse(new TextDecoder().decode(new Uint8Array(e,3,s))),jpeg:new Blob([new Uint8Array(e,3+s)],{type:"image/jpeg"})}}catch{return null}}function X4(e=window.location){return`${e.protocol==="https:"?"wss":"ws"}://${e.host}/api/browser/hand`}function Z4({sessionId:e,csrf:t,onGiveBack:s,connect:r}){const[i,a]=f.useState("connecting"),[l,o]=f.useState(null),[c,u]=f.useState(!1),[h,d]=f.useState(null),[m,p]=f.useState(!1),[x,j]=f.useState(0),b=f.useRef(null),g=f.useRef(null),v=f.useRef(null),w=f.useRef({at:0});f.useEffect(()=>{const E=r??(B=>new WebSocket(B));let $=!0,_;try{_=E(X4())}catch{a("lost");return}return _.binaryType="arraybuffer",b.current=_,_.onopen=()=>_.send(JSON.stringify({type:"hello",csrf:t,sessionId:e})),_.onmessage=B=>{if(!$)return;if(typeof B.data!="string"){const W=J4(B.data);if(!W||(d(D=>D&&Q4(D,W.metadata)?D:W.metadata),u(!0),typeof createImageBitmap!="function"))return;createImageBitmap(W.jpeg).then(D=>{var V,Z,ue;const U=g.current;if(!$||!U){(V=D.close)==null||V.call(D);return}(U.width!==D.width||U.height!==D.height)&&(U.width=D.width,U.height=D.height),(Z=U.getContext("2d"))==null||Z.drawImage(D,0,0),(ue=D.close)==null||ue.call(D)}).catch(()=>{});return}const M=JSON.parse(B.data);if(M.type==="driving"){a("driving"),o(null);return}(M.type==="refused"||M.type==="ended")&&(o(M.error??"The screen cannot be driven from here."),a("refused"))},_.onclose=()=>{$&&a(B=>B==="refused"?B:"lost")},_.onerror=()=>{$&&a(B=>B==="refused"?B:"lost")},()=>{$=!1,b.current=null;try{_.close()}catch{}}},[e,t,x,r]),f.useEffect(()=>()=>{clearTimeout(w.current.timer)},[]);const y=f.useCallback(E=>{const $=b.current;if($)try{$.send(JSON.stringify({type:"input",input:E}))}catch{}},[]),N=E=>{var B;const $=g.current;if(!$||!h)return null;const _=(B=$.getBoundingClientRect)==null?void 0:B.call($);return _?K4(_,h,E.clientX,E.clientY):null},k=E=>{const $=w.current,_=Date.now();clearTimeout($.timer),$.timer=void 0;const B=$.at+q4-_;if(B<=0){$.at=_,$.pending=void 0,y(E);return}$.pending=E,$.timer=setTimeout(()=>{const M=w.current.pending;w.current.timer=void 0,w.current.pending=void 0,w.current.at=Date.now(),M&&y(M)},B)},S=()=>{const E=w.current;clearTimeout(E.timer),E.timer=void 0;const $=E.pending;E.pending=void 0,$&&(E.at=Date.now(),y($))},C=E=>$=>{var M,W;const _=N($);if(!_)return;E==="mousePressed"&&($.preventDefault(),(W=(M=g.current)==null?void 0:M.focus)==null||W.call(M));const B={kind:"mouse",type:E,x:_.x,y:_.y,button:Y4[$.button]??"left",clickCount:E==="mouseMoved"?0:Math.min(3,Math.max(1,$.detail||1)),modifiers:mf($)};if(E==="mouseMoved"){k(B);return}S(),y(B)},I=E=>{const $=N(E);$&&(S(),y({kind:"wheel",x:$.x,y:$.y,deltaX:Math.round(E.deltaX),deltaY:Math.round(E.deltaY)}))},A=E=>E.ctrlKey||E.metaKey||E.altKey,O=E=>{var _,B;if(E.key==="Escape"&&A(E)){p(!1),(B=(_=E.target).blur)==null||B.call(_);return}if(E.preventDefault(),(E.metaKey||E.ctrlKey)&&(E.key==="v"||E.key==="V"))return;const $=mf(E);if(Ay(E.key)&&!A(E)){y({kind:"key",type:"char",key:E.key,code:E.code,text:E.key,modifiers:$});return}y({kind:"key",type:"keyDown",key:E.key,code:E.code,modifiers:$})},z=E=>{E.key==="Escape"&&A(E)||(E.preventDefault(),!((E.metaKey||E.ctrlKey)&&(E.key==="v"||E.key==="V"))&&(Ay(E.key)&&!A(E)||y({kind:"key",type:"keyUp",key:E.key,code:E.code,modifiers:mf(E)})))},L=E=>{var _;E.preventDefault();const $=G4(((_=E.clipboardData)==null?void 0:_.getData("text/plain"))??"");$!==""&&y({kind:"text",text:$})};return n.jsxs("section",{className:"hand","data-testid":"remote-hand","data-phase":i,"aria-label":"Driving the host browser",children:[n.jsxs("div",{className:"hand-bar",children:[n.jsx("span",{className:"hand-said",role:"status",children:"You are driving. Nothing you type here is kept."}),n.jsxs(Q,{align:"end",children:[n.jsx(R,{size:"sm",variant:m?"accent":"ghost","aria-pressed":m,onClick:()=>{var $,_,B,M;const E=!m;p(E),E?(_=($=v.current)==null?void 0:$.focus)==null||_.call($):(M=(B=v.current)==null?void 0:B.blur)==null||M.call(B)},children:"Keyboard"}),n.jsx(R,{size:"sm",variant:"accent",onClick:s,children:"Give it back"})]})]}),i==="lost"?n.jsxs(H,{tone:"warning",role:"status",children:["Connection lost. The picture below is the last frame that arrived.",n.jsx(Q,{align:"end",children:n.jsx(R,{size:"sm",variant:"accent",onClick:()=>{a("connecting"),j(E=>E+1)},children:"Reconnect"})})]}):null,i==="refused"&&l?n.jsx(H,{tone:"warning",role:"status",children:l}):null,n.jsx("div",{className:"hand-screen",children:c?n.jsx("canvas",{ref:g,className:"hand-picture",role:"img","aria-label":"The host browser, live","data-testid":"hand-picture",tabIndex:0,onMouseDown:C("mousePressed"),onMouseUp:C("mouseReleased"),onMouseMove:C("mouseMoved"),onWheel:I,onKeyDown:O,onKeyUp:z,onPaste:L,onContextMenu:E=>E.preventDefault()}):n.jsx("p",{className:"muted hand-waiting",children:i==="lost"?"No picture arrived before the connection dropped.":"Waiting for the first frame…"})}),n.jsx("input",{ref:v,className:"hand-typing","aria-label":"Type into the host browser",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,value:"",onChange:()=>{},onKeyDown:O,onKeyUp:z,onPaste:L,onBlur:()=>p(!1)})]})}function e3(e){return e==="darwin"?"this Mac":"this computer"}let pf=null;function Ux(){const[e,t]=f.useState(void 0);return f.useEffect(()=>{let s=!0;return pf??(pf=T.session().then(r=>r.platform,()=>{pf=null})),pf.then(r=>{s&&t(r)}),()=>{s=!1}},[]),e3(e)}function t3({embedded:e,timezone:t}={}){var c;const{data:s,error:r,reload:i}=le(()=>T.browser(),[],3e3),a=le(()=>T.session(),[]),l=(c=a.data)!=null&&c.platform?a.data.platform==="darwin":!0,o=!!a.data||!!a.error;return n.jsxs(yn,{embedded:e,title:"Computer & browser",children:[n.jsx(se,{message:r}),!s||!o?n.jsx(oe,{children:"Checking the host…"}):n.jsx(n3,{data:s,macOS:l,reload:i,timezone:t},JSON.stringify(s.settings??null))]})}function n3({data:e,macOS:t,reload:s,timezone:r}){var S,C,I;const[i,a]=f.useState(!1),[l,o]=f.useState(null),[c,u]=f.useState(!1),h=e.settings&&!t&&e.settings.mode==="computer"?{...e.settings,mode:"playwright"}:e.settings,d=(h==null?void 0:h.mode)??(!t&&e.mode==="computer"?"playwright":e.mode),m=d==="computer",p=(S=e.sessions)!=null&&S.length?e.sessions:e.session?[e]:[],x=p.length>0||e.busy,j=async A=>{a(!0),o(null);try{await A()}catch(O){o(O instanceof Error?O.message:String(O))}finally{a(!1),s()}},b=A=>void j(()=>T.browserSettings(A)),g=e.permissions,v=d==="playwright"?e.browser:void 0,w=((C=v==null?void 0:v.install)==null?void 0:C.state)==="running",y=(v==null?void 0:v.engine)==="none",N=!!e.enabled&&!y&&!(v!=null&&v.problem)&&(!m||!(g!=null&&g.supported)||g.accessibility&&g.screenRecording),k=m?"Ready. Agents can use your computer within the apps you allow below.":d==="extension"?"Ready. Agents work in your Chrome, in background tabs, through the buddi extension.":(v==null?void 0:v.engine)==="chrome"?"Ready. Agents work in their own browser, a separate Google Chrome profile. Your apps are never touched.":"Ready. Agents work in their own browser. Your apps are never touched.";return n.jsxs(J,{gap:"lg",children:[n.jsx(se,{message:l}),n.jsx(te,{title:"Status",panel:!0,actions:n.jsxs(n.Fragment,{children:[n.jsx(R,{size:"sm",disabled:i,onClick:()=>void j(()=>T.computerPermissions(!1)),children:"Check again"}),m&&!N&&(g!=null&&g.supported)?n.jsx(R,{size:"sm",variant:"accent",disabled:i||x,onClick:()=>void j(()=>T.computerPermissions(!0)),children:"Request macOS permissions"}):null,y||w?n.jsx(R,{size:"sm",variant:"accent",disabled:i||w,onClick:()=>void j(()=>T.browserInstall()),children:w?"Installing…":"Install Chromium"}):null]}),children:n.jsxs(J,{children:[e.enabled?y?n.jsxs(H,{tone:"warning",title:"No browser installed for the agents yet",children:["Install Chromium here (about 150 MB), or run ",n.jsx("code",{children:"buddi browser install"})," on this machine."]}):v!=null&&v.problem?n.jsx(H,{tone:"warning",children:v.message}):N?n.jsx(H,{tone:"good",children:k}):n.jsx(H,{tone:"warning",children:"macOS has not granted everything yet. Grant the permissions below, then check again."}):n.jsx(H,{tone:"warning",children:"The host is not available. Start buddi serve on a machine with a desktop session."}),m?g!=null&&g.supported?n.jsxs("ul",{className:"perm-list",children:[n.jsxs("li",{className:"perm-row",children:[n.jsx(ge,{tone:g.accessibility?"good":"warning",children:g.accessibility?"Granted":"Needed"}),n.jsx("span",{className:"perm-name",children:"Accessibility"}),n.jsx("span",{className:"muted",children:"Lets agents click and type in the apps you allow."})]}),n.jsxs("li",{className:"perm-row",children:[n.jsx(ge,{tone:g.screenRecording?"good":"warning",children:g.screenRecording?"Granted":"Needed"}),n.jsx("span",{className:"perm-name",children:"Screen Recording"}),n.jsx("span",{className:"muted",children:"Lets agents see the window they are working in."})]})]}):g?n.jsx("p",{className:"muted",children:"Computer control requires macOS 14 or later."}):null:null,((I=v==null?void 0:v.install)==null?void 0:I.state)==="running"?n.jsx(q1,{progress:v.install.progress}):v!=null&&v.install?n.jsx("p",{className:"muted",role:"status",children:v.install.state==="done"?"Chromium is installed. Agents can open their browser now.":`The install did not finish: ${v.install.line??"no reason given"}`}):null,v!=null&&v.headless&&!y?n.jsx("p",{className:"muted",children:"The agents’ browser runs headless on this machine, since it has no display. Watch it and take over from the conversation’s Canvas."}):null,m&&(g!=null&&g.message)?n.jsx("p",{className:"muted",children:g.message}):null,m&&(g!=null&&g.supported)&&!N?n.jsx("p",{className:"muted",children:"macOS may ask you to restart buddi after granting them."}):null]})}),n.jsx(te,{title:"Who is driving",panel:!0,actions:p.length>0?n.jsx(R,{variant:"danger",size:"sm",disabled:i,onClick:()=>void j(()=>T.browserControl("stop")),children:m?"Stop computer control":"Stop all browsers"}):void 0,children:p.length===0?n.jsx("p",{className:"ui-card-meta",children:"Nobody right now. Ask an agent to open a website or one of the allowed apps, and you will see it working on that conversation’s Canvas."}):n.jsx("div",{className:"ui-list",children:p.map(A=>n.jsxs("a",{className:"ui-list-row",href:Ve(A.session.agentId,A.session.conversationId),children:[n.jsx(Es,{id:A.session.agentId,name:A.session.agentId,size:"sm"}),n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title",children:A.session.task}),n.jsxs("span",{className:"ui-list-sub",children:[A.session.agentId,", ",A.busy?"working":A.state,", ",A.session.steps," of ",A.session.maxSteps," steps"]})]}),n.jsx("span",{className:"ui-list-side",children:"Open the Canvas"})]},A.session.id))})}),h?n.jsxs(n.Fragment,{children:[n.jsx(te,{title:"How agents get a screen",panel:!0,children:n.jsxs(J,{divided:!0,children:[n.jsxs("div",{className:"mode-choice",role:"radiogroup","aria-label":"Control mode",children:[t?n.jsx(gf,{current:h.mode,value:"computer",disabled:i||x||!e.enabled,title:"Use my apps",body:"Agents work in your own windows, signed in as you, in the browser profile you choose below. One agent at a time. Releasing control leaves everything open.",onPick:()=>b({...h,mode:"computer"})}):null,n.jsx(gf,{current:h.mode,value:"playwright",disabled:i||x||!e.enabled,title:"Give agents their own browser",body:"A separate browser profile with its own tabs, one per conversation. Your apps are never touched.",onPick:()=>b({...h,mode:"playwright"})}),n.jsx(gf,{current:h.mode,value:"extension",disabled:i||x||!e.enabled,title:"Your browser",body:"Uses the Chrome you are signed in to, in background tabs, through the buddi extension.",onPick:()=>b({...h,mode:"extension"})})]}),t?null:n.jsx("p",{className:"muted",children:"Using your own apps is macOS-only."}),x?n.jsx("p",{className:"muted",children:"Finish or stop the current session before changing this."}):null,h.mode==="extension"?n.jsx(c3,{busy:i,timezone:r}):null]})}),t?n.jsx(te,{title:"Apps agents may use",panel:!0,children:n.jsxs(J,{children:[h.mode!=="computer"?n.jsx("p",{className:"muted",children:"Only used by “Use my apps”. The list is kept for when you switch back."}):null,n.jsx(u3,{settings:h,disabled:i||x||!e.enabled,onChange:b,onAdd:()=>u(!0)}),n.jsx($t,{summary:"Details",children:n.jsxs("div",{className:"ui-prose muted",children:[n.jsx("p",{children:"Agents see what is on screen in these apps, and what they see goes to the agent’s model provider. Allow only apps you want operated."}),n.jsx("p",{children:"Never type a password or a sign-in code in chat. Sign in yourself, in the app, while you have taken over."}),n.jsx("p",{children:"This is an allow list, not a sandbox: an allowed app’s own network traffic is not inspected."})]})})]})}):null,c?n.jsx(p3,{chosen:h.allowedApps,onClose:()=>u(!1),onPick:A=>{u(!1),h.allowedApps.includes(A)||b({...h,allowedApps:[...h.allowedApps,A]})}}):null]}):null]})}const s3="kmbckpnnjfggeffkkbmkggojnolkdokb",r3="",i3=[s3,r3].filter(Boolean);function a3(e){const t=/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?/.exec(e.trim());if(!t)return e;const s=t[4]?/^pre\.(\d+)$/.exec(t[4]):null;return[t[1],t[2],t[3],...s?[s[1]]:[]].map(Number).join(".")}async function l3(){var e;try{if(typeof chrome>"u"||!((e=chrome==null?void 0:chrome.runtime)!=null&&e.sendMessage))return null;for(const t of i3)try{const s=await chrome.runtime.sendMessage(t,{type:"buddi.status"});if(s!=null&&s.installed)return s}catch{}return null}catch{return null}}function o3(e){try{return new URL(e).origin===window.location.origin}catch{return!1}}function c3({busy:e,timezone:t}){const{data:s,error:r,reload:i}=le(()=>T.extension(),[],3e3),a=Ux(),l=le(()=>l3(),[],3e3).data??null,[o,c]=f.useState(""),[u,h]=f.useState(!1),[d,m]=f.useState(null),p=(l==null?void 0:l.state)==="pairing"?l.code??"":"";f.useEffect(()=>{p&&c(p)},[p]);const x=async v=>{h(!0),m(null);try{await v()}catch(w){m(w instanceof Error?w.message:String(w))}finally{h(!1),i()}},j=e||u,b=t??Intl.DateTimeFormat().resolvedOptions().timeZone,g=n.jsxs("div",{className:"ui-prose muted",children:[n.jsx("p",{children:"Open chrome://extensions, turn on Developer mode, choose Load unpacked, and pick this folder."}),n.jsx(xt,{label:"The unpacked extension",children:(s==null?void 0:s.path)??"…"})]});return n.jsxs(J,{divided:!0,children:[n.jsx(se,{message:r??d}),n.jsxs(Q,{children:[n.jsx(ge,{tone:s!=null&&s.connected?"good":"warning",children:s!=null&&s.connected?"Connected":"Not connected"}),n.jsxs("span",{className:"muted",children:[s!=null&&s.connected&&s.pairedAt?`Paired with Chrome on ${a} since ${Be(s.pairedAt,b)}`:s!=null&&s.pairedAt?"Paired, but Chrome is not running the extension right now.":"No browser is paired with this buddi yet.",s!=null&&s.extension?` · extension ${s.extension}`:""]})]}),n.jsxs(J,{children:[n.jsxs("p",{className:"muted",children:[l?`The browser you are reading this in has the extension, version ${l.version}.`:s!=null&&s.connected?"The browser you are reading this in has no buddi extension. You only need it here to pair this browser instead.":"The browser you are reading this in has no buddi extension yet.",(l==null?void 0:l.state)==="paired"?" It is already paired with a buddi.":"",(l==null?void 0:l.state)==="disconnected"?" It is not connected yet: press Connect in its popup.":""]}),l&&(s!=null&&s.buddi)&&a3(s.buddi)!==l.version?n.jsx("p",{className:"muted",children:`buddi is ${s.buddi}; the extension is ${l.version}. Update it from chrome://extensions or the store.`}):null,l&&!o3(l.gateway)?n.jsx(H,{tone:"warning",children:`The extension is pointed at ${l.gateway}; set it to ${window.location.origin} in the popup.`}):null]}),s!=null&&s.pending?n.jsxs(Q,{valign:"end",children:[n.jsx(ee,{grow:!0,label:"Pair your browser",hint:"Type the six digits the buddi extension is showing.",children:n.jsx("input",{"aria-label":"Pairing code",inputMode:"numeric",placeholder:"482 913",value:o,onChange:v=>c(v.target.value)})}),n.jsx(en,{}),n.jsx(R,{variant:"accent",disabled:j||o.replace(/[^0-9]/g,"").length!==6,onClick:()=>void x(async()=>{await T.pairExtension(o),c("")}),children:"Pair"})]}):null,s!=null&&s.connected?n.jsx($t,{summary:"Pair a different browser",children:g}):g,n.jsx(Q,{align:"end",children:n.jsx(R,{variant:"danger",disabled:j||!(s!=null&&s.pairedAt),onClick:()=>void x(()=>T.forgetExtension()),children:"Forget this browser"})})]})}function gf({current:e,value:t,title:s,body:r,disabled:i,onPick:a}){const l=e===t;return n.jsxs("button",{type:"button",role:"radio","aria-checked":l,className:"mode-option",disabled:i,onClick:()=>{l||a()},children:[n.jsx("span",{className:"mode-option-dot","aria-hidden":"true"}),n.jsxs("span",{className:"mode-option-text",children:[n.jsx("span",{className:"mode-option-title",children:s}),n.jsx("span",{className:"mode-option-body",children:r})]})]})}function u3({settings:e,disabled:t,onChange:s,onAdd:r}){const i=le(()=>T.installedApps(),[]),a=l=>{var o,c;return((c=(o=i.data)==null?void 0:o.apps.find(u=>u.id===l))==null?void 0:c.name)??l};return n.jsxs(n.Fragment,{children:[e.allowedApps.length===0?n.jsx(oe,{children:"No apps yet. Agents cannot touch anything until you add one."}):n.jsx("ul",{className:"ui-list","aria-label":"Allowed apps",children:e.allowedApps.map(l=>n.jsxs("li",{className:"ui-list-row",children:[n.jsx(Es,{id:l,name:a(l),size:"sm"}),n.jsxs("span",{className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[a(l),l===e.browserApp?n.jsx(ge,{tone:"accent",className:"app-role",children:"browser"}):null]}),n.jsx("span",{className:"ui-list-sub mono",children:l})]}),n.jsxs(Q,{children:[l!==e.browserApp&&m3(l)?n.jsx(R,{size:"sm",variant:"ghost",disabled:t,onClick:()=>s({...e,browserApp:l}),children:"Use as browser"}):null,l===e.browserApp?n.jsx("span",{className:"muted",children:"In use as the browser"}):n.jsx(R,{size:"sm",variant:"ghost",disabled:t,onClick:()=>s({...e,allowedApps:e.allowedApps.filter(o=>o!==l)}),children:"Remove"})]})]},l))}),n.jsxs(Q,{children:[n.jsx(R,{variant:"accent",disabled:t,onClick:r,children:"Add an app"}),n.jsx("span",{className:"muted",children:"The app marked as browser is the one agents open websites in."})]}),e.mode==="computer"&&d3.includes(e.browserApp)?n.jsx(h3,{settings:e,disabled:t,onChange:s}):null]})}const d3=["com.google.Chrome","org.chromium.Chromium","com.microsoft.edgemac","com.brave.Browser"];function h3({settings:e,disabled:t,onChange:s}){var l;const i=((l=le(()=>T.browserProfiles(e.browserApp),[e.browserApp]).data)==null?void 0:l.profiles)??[],a=e.browserProfile?i.some(o=>o.directory===e.browserProfile):!0;return n.jsx(ee,{label:"Browser profile",hint:e.browserProfile?"Websites open in this profile, signed in as it is.":"Not chosen: websites open in whichever profile’s window is in front, or the last one you used.",children:n.jsxs("select",{value:e.browserProfile??"",disabled:t,onChange:o=>{const{browserProfile:c,...u}=e;s(o.target.value?{...u,browserProfile:o.target.value}:u)},children:[n.jsx("option",{value:"",children:"Whichever is in front"}),!a&&e.browserProfile?n.jsxs("option",{value:e.browserProfile,children:[e.browserProfile," (not found)"]}):null,i.map(o=>n.jsxs("option",{value:o.directory,children:[o.name,o.directory==="Default"?"":` (${o.directory})`]},o.directory))]})})}const f3=["com.google.Chrome","com.apple.Safari","org.chromium.Chromium","com.microsoft.edgemac","com.brave.Browser","org.mozilla.firefox","company.thebrowser.Browser"];function m3(e){return f3.includes(e)}function p3({chosen:e,onClose:t,onPick:s}){const r=le(()=>T.installedApps(),[]),[i,a]=f.useState(""),[l,o]=f.useState(""),c=f.useMemo(()=>{var d;const u=((d=r.data)==null?void 0:d.apps)??[],h=i.trim().toLowerCase();return u.filter(m=>!h||m.name.toLowerCase().includes(h)||m.id.toLowerCase().includes(h)).slice(0,60)},[r.data,i]);return n.jsxs(wt,{title:"Add an app",onClose:t,children:[n.jsx("input",{autoFocus:!0,"aria-label":"Search apps",placeholder:"Search installed apps",value:i,onChange:u=>a(u.target.value)}),n.jsx(se,{message:r.error}),r.data?c.length===0?n.jsx(oe,{children:"No app matches."}):n.jsx("ul",{className:"ui-list","aria-label":"Installed apps",children:c.map(u=>{const h=e.includes(u.id);return n.jsxs("li",{className:"ui-list-row",children:[n.jsx(Es,{id:u.id,name:u.name,size:"sm"}),n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title",children:u.name}),n.jsx("span",{className:"ui-list-sub mono",children:u.id})]}),n.jsx(R,{size:"sm",disabled:h,onClick:()=>s(u.id),children:h?"Allowed":"Allow"})]},u.id)})}):n.jsx(oe,{children:"Reading your Applications folder…"}),n.jsx($t,{summary:"Add by bundle identifier instead",children:n.jsxs(Q,{children:[n.jsx("input",{"aria-label":"Bundle identifier",placeholder:"com.apple.TextEdit",value:l,onChange:u=>o(u.target.value)}),n.jsx(R,{disabled:!l.trim(),onClick:()=>s(l.trim()),children:"Allow this identifier"})]})})]})}function g3({data:e,error:t,reload:s,compact:r=!1,refresh:i,screenshotSrc:a,onScreenshotError:l,onScreenshotLoad:o,controls:c=!0}){var I,A,O;const[u,h]=f.useState(!1),[d,m]=f.useState(null),[p,x]=f.useState(null),[j,b]=f.useState(null),g=async z=>{h(!0),m(null),b(null);try{const L=z!=="stop"&&(e!=null&&e.session)?await T.browserControl(z,e.session.id):await T.browserControl(z);z==="takeover"?L.hand&&L.session?x(L.session.id):b(L.handMessage??null):x(null)}catch(L){m(L instanceof Error?L.message:String(L))}finally{h(!1),s()}},v=p&&((I=e==null?void 0:e.session)==null?void 0:I.id)===p&&e.state==="paused"?p:null,w=!!(e!=null&&e.enabled)&&!u,y=(e==null?void 0:e.mode)==="computer",N=(e==null?void 0:e.mode)==="extension",k=y?"Stop computer control interrupts native input and revokes access. Take over pauses agent input. Release ends this conversation’s control without closing your apps. Already dispatched actions cannot be undone. Avoid using the same mouse and keyboard while the agent is working.":"Stop all browsers closes every session and revokes access until you resume. Take over, Resume and Close & release affect only the selected conversation. An in-flight action is interrupted by closing its tabs. Actions already submitted cannot be undone.",S=e!=null&&e.busy?"Working":(e==null?void 0:e.state)==="running"?"Ready":(e==null?void 0:e.state)??"Connecting",C=e!=null&&e.busy||(e==null?void 0:e.state)==="running"?"good":(e==null?void 0:e.state)==="stopped"||(e==null?void 0:e.state)==="error"?"critical":void 0;return n.jsxs("section",{className:"browser-panel","data-compact":r?"true":void 0,"aria-label":"Host browser",children:[n.jsxs("div",{className:"browser-heading",children:[n.jsxs("div",{children:[r?null:n.jsx("p",{className:"browser-eyebrow",children:"On your host machine"}),n.jsx("h2",{className:"browser-title",children:y?"Computer":N?"Your browser":"Browser"})]}),n.jsx(ge,{tone:C,children:n.jsx("span",{role:"status",children:S})})]}),r?n.jsx("a",{className:"browser-full-view",href:"#/browser",children:y?"Open computer view & settings ↗":"Open full browser view ↗"}):n.jsx("p",{className:"ui-page-lede",children:y?"Your apps, operated through macOS accessibility, screenshots and input. No browser debugging connection.":N?"Your own Chrome, signed in as you, working in background tabs grouped as “buddi”. You keep browsing.":"A real browser window, driven by your assistant. You stay in control."}),n.jsx(se,{message:t??d}),c?n.jsxs(Q,{children:[n.jsx(R,{variant:"danger",disabled:!w||(e==null?void 0:e.state)==="stopped",onClick:()=>void g("stop"),children:y?"Stop computer control":"Stop all browsers"}),n.jsx(R,{disabled:!w||!(e!=null&&e.session)||(e==null?void 0:e.state)==="paused",onClick:()=>void g("takeover"),children:"Take over"}),n.jsx(R,{disabled:!w||(e==null?void 0:e.busy)||!["stopped","paused"].includes((e==null?void 0:e.state)??""),onClick:()=>void g("resume"),children:"Resume access"}),n.jsx(R,{disabled:!w||!(e!=null&&e.session),onClick:()=>void g("release"),children:y?"Release control":"Close & release"})]}):null,c?r?n.jsx($t,{summary:"About these controls",children:n.jsx("p",{className:"muted",children:k})}):n.jsx("p",{className:"muted",children:k}):null,j?n.jsx(H,{tone:"warning",role:"status",children:j}):null,e!=null&&e.message&&!v?n.jsx(H,{tone:"warning",role:"status",children:e.message}):null,e!=null&&e.session?n.jsxs("div",{className:"browser-task",children:[n.jsxs("div",{className:"ui-row",children:[n.jsx("strong",{children:e.session.agentId}),n.jsxs("span",{className:"muted",children:[e.session.steps," / ",e.session.maxSteps," steps"]})]}),r?null:n.jsx("p",{children:e.session.task}),n.jsxs("p",{className:"muted",children:["Last action: ",e.lastAction??"None"," · Access expires ",new Date(e.session.expiresAt).toLocaleTimeString()]})]}):n.jsx("p",{className:"browser-task muted",children:e!=null&&e.enabled?y?"No agent is driving. Ask an agent granted browser.* to open a website or an allowed native app.":"No agent is driving. Ask an agent granted browser.* to open a website.":"The host browser is unavailable. Start buddi serve on a machine with a desktop session."}),v?n.jsx(Z4,{sessionId:v,csrf:Hi(),onGiveBack:()=>void g("resume")}):null,n.jsxs("div",{className:"browser-window",hidden:!!v,children:[n.jsxs("div",{className:"browser-address",children:[n.jsx("span",{"aria-hidden":"true",children:"◉"}),n.jsx("span",{children:((A=e==null?void 0:e.page)==null?void 0:A.url)??(y?"Waiting for an application":"Waiting for a website")})]}),e!=null&&e.hasScreenshot&&e.page?n.jsxs("figure",{children:[n.jsx("img",{src:a??`/api/browser/screenshot?v=${encodeURIComponent(e.page.id)}${e.session?`&sessionId=${encodeURIComponent(e.session.id)}`:""}${i?`&tick=${i}`:""}`,alt:`Last browser observation: ${e.page.title||e.page.url}`,...l?{onError:l}:{},...o?{onLoad:o}:{}},a??e.page.id),n.jsxs("figcaption",{children:["Last observation · ",new Date(e.page.capturedAt).toLocaleTimeString()," · ",e.page.title||"Untitled page"]})]}):n.jsxs("div",{className:"browser-empty",children:[n.jsx("strong",{children:y?"Your selected app will appear here":"Your browser activity will appear here"}),n.jsx("p",{children:y?"Only the selected app window is captured, not the whole desktop. This preview is not interactive.":"This is a view of the host browser, not a second browser or a remote desktop."})]})]}),(((O=e==null?void 0:e.page)==null?void 0:O.tabs.length)??0)>1?n.jsx($t,{summary:`${e.page.tabs.length} open tabs`,children:n.jsx("ul",{className:"ui-prose",children:e.page.tabs.map(z=>n.jsxs("li",{children:[z.title||z.id," — ",z.url]},z.id))})}):null,n.jsxs("p",{className:"muted",children:[y?"Sign in directly in the host app during takeover. Don’t send passwords or MFA codes in chat. Native apps retain your existing logins and documents. Secure accessibility fields are masked; other sensitive window content can still appear in screenshots.":"Sign in directly in this conversation’s host tab during takeover. Don’t send passwords or MFA codes in chat. Agent tabs share saved logins and cookies."," ",v?"While you are driving this is a live view of the page; nothing you type is kept.":"Screenshots update after agent actions; this is not a live video feed."]})]})}const x3=2e3,v3=5;function j3(e,t){if(!e.hasScreenshot||!e.page)return null;const s=e.session?`&sessionId=${encodeURIComponent(e.session.id)}`:"";return`/api/browser/screenshot?v=${encodeURIComponent(e.page.id)}${s}`}function w3({status:e,error:t,reload:s,steps:r,live:i,focusedStepId:a=null}){var w;const[l,o]=f.useState(0),[c,u]=f.useState(0),h=c>=v3;f.useEffect(()=>{if(!i||h)return;const y=window.setInterval(()=>{typeof document<"u"&&document.hidden||o(N=>N+1)},x3);return()=>window.clearInterval(y)},[i,h]);const d=f.useRef(null);i&&(e!=null&&e.session)&&(d.current=e);const[m,p]=f.useState(null),x=f.useRef(null),j=((w=e==null?void 0:e.page)==null?void 0:w.id)??null;f.useEffect(()=>{const y=i&&e?j3(e):null;if(!y||typeof fetch!="function"||typeof(URL==null?void 0:URL.createObjectURL)!="function")return;let N=!1;return(async()=>{try{const k=await fetch(y);if(!k.ok||N)return;const S=await k.blob();if(N)return;const C=URL.createObjectURL(S);x.current&&URL.revokeObjectURL(x.current),x.current=C,p(C)}catch{}})(),()=>{N=!0}},[i,j]),f.useEffect(()=>()=>{x.current&&typeof(URL==null?void 0:URL.revokeObjectURL)=="function"&&URL.revokeObjectURL(x.current)},[]);const b=d.current,g=i?e:b?m?b:{...b,hasScreenshot:!1}:e,v=r.at(-1)??null;return n.jsxs("div",{className:"wb-browser","data-testid":"browser-view","data-live":i?"true":"false",children:[n.jsx(g3,{data:g,error:t,reload:s,compact:!0,controls:i,...i?{refresh:l}:{},...!i&&m?{screenshotSrc:m}:{},onScreenshotError:()=>u(y=>y+1),onScreenshotLoad:()=>u(0)}),i?h?n.jsx("p",{className:"muted wb-browser-ended",role:"status",children:"The last observation could not be loaded. Showing what arrived before it."}):null:n.jsx("p",{className:"muted wb-browser-ended",role:"status",children:"This session has ended. What is on this panel is the last thing it showed."}),n.jsx(y3,{steps:r,newestId:(v==null?void 0:v.id)??null,focusedId:a??null,live:i})]})}function y3({steps:e,newestId:t,focusedId:s,live:r}){const i=f.useRef(null);return f.useEffect(()=>{var l;if(!s||!i.current)return;const a=i.current.querySelector(`[data-step="${CSS!=null&&CSS.escape?CSS.escape(s):s}"]`);(l=a==null?void 0:a.scrollIntoView)==null||l.call(a,{block:"nearest"})},[s]),e.length===0?n.jsx("p",{className:"muted wb-browser-empty",children:r?"No action taken on this screen yet.":"This conversation took no action on the screen."}):n.jsx("section",{className:"wb-browser-steps","aria-label":"Steps taken on this screen",children:n.jsx("ol",{className:"wb-browser-list",ref:i,children:e.map((a,l)=>{const o=a.awaiting?"awaiting":a.ok===null?"running":a.ok?"ok":"failed";return n.jsxs("li",{"data-step":a.id,className:"wb-browser-step","data-state":o,"data-newest":a.id===t?"true":void 0,"data-focused":a.id===s?"true":void 0,children:[n.jsx("span",{className:"wb-browser-index mono",children:l+1}),n.jsxs("span",{className:"wb-browser-what",children:[n.jsx("strong",{children:a.action}),a.target?n.jsx("span",{className:"muted wb-browser-target",children:a.target}):null,a.error?n.jsx("span",{className:"wb-browser-error",children:a.error}):null]}),n.jsx("span",{className:"wb-browser-outcome","data-state":o,children:o==="awaiting"?"Awaiting approval":o==="running"?"Working":o==="ok"?"Done":"Failed"})]},a.id)})})})}function b3({agentId:e,conversationId:t}){const{data:s,error:r,reload:i}=le(()=>T.host(e,t),[e,t],2e3),[a,l]=f.useState(null),[o,c]=f.useState(!1),u=async p=>{c(!0),l(null);try{await p(),i()}catch(x){l(x instanceof Error?x.message:String(x))}finally{c(!1)}},h=(s==null?void 0:s.permissions)??[],d=(s==null?void 0:s.runs)??[],m=h.some(p=>!p.conversationId)?"Always allowed":h.length?"Conversation auto-mode":"Ask each time";return n.jsx($t,{className:"host-controls",summary:`Host execution · ${r?"Status unavailable":m}${d.length?` · ${d.length} running`:""}`,children:n.jsxs(J,{gap:"sm",children:[n.jsx("p",{className:"muted",children:"Commands run as your user, not in a sandbox. Auto-mode covers all commands within its scope. Stop interrupts a command; revoke also ends the permission. Neither undoes completed changes."}),n.jsx(se,{message:a??r}),h.map(p=>n.jsxs(Q,{children:[n.jsxs("span",{children:[p.agentId,": ",p.conversationId?"conversation auto-mode":"always allowed"]}),n.jsx(R,{size:"sm",disabled:o,onClick:()=>void u(()=>T.revokeHost(p.id)),children:"Revoke permission"})]},p.id)),h.length?null:n.jsx("p",{className:"muted",children:"The next command will ask for approval. Choose its permission scope there."}),d.map(p=>n.jsxs(J,{gap:"sm",children:[n.jsxs("p",{children:[p.agentId," · ",n.jsx("span",{className:"mono",children:p.cwd})]}),n.jsx(xt,{children:p.command}),n.jsx(xt,{label:"Command output",children:p.stdout||p.stderr?`${p.stdout}
103
- ${p.stderr}`:"Waiting for output…"}),n.jsx(Q,{children:n.jsx(R,{size:"sm",variant:"danger",disabled:o,onClick:()=>void u(()=>T.stopHost(p.agentId,p.conversationId)),children:"Stop command"})})]},p.actionId))]})})}const Q1="browser.act",k3="browser.status",pu=new Set([Q1,k3]);function S3(e,t,s){const r=e==null?void 0:e.session;return!r||!t||!s||r.agentId!==t||r.conversationId!==s?null:{id:`host-browser:${r.id}`,title:e.mode==="computer"?"Computer":"Browser",tool:"Host browser",renderer:"browser",source:"browser",pinned:!0,props:{},at:null,substantial:!1}}function N3(e,t){return{...e,title:`${t==="computer"?"Computer":"Browser"} (ended)`,pinned:!1}}function C3(e){var r;const t=[],s=new Map;for(const i of e)for(const a of i.blocks??[]){if(a.type==="tool_use"&&a.name===Q1){const o={id:a.id,action:E3(a.input)??"act",target:A3(a.input),ok:null,awaiting:!1,error:null,at:i.at??null};t.push(o),s.set(a.id,o);continue}if(a.type!=="tool_result")continue;const l=s.get(a.toolUseId);if(l){if(((r=a.approval)==null?void 0:r.state)==="pending"){l.awaiting=!0,l.ok=null,l.error=null;continue}l.awaiting=!1,l.ok=a.ok,l.error=a.ok?null:T3(a)}}return t}function Ty(e,t){var r;let s=!1;for(const i of e)for(const a of i.blocks??[])if(a.type==="tool_use"&&a.id===t&&(s=pu.has(a.name)),a.type==="tool_result"&&a.toolUseId===t&&((r=a.approval)==null?void 0:r.state)==="pending")return null;return s?t:null}function E3(e){if(e===null||typeof e!="object")return null;const t=e.action;return typeof t=="string"&&t!==""?t:null}function A3(e){if(e===null||typeof e!="object")return null;const t=e;for(const r of["url","appId","direction","key","tabId"]){const i=t[r];if(typeof i=="string"&&i!=="")return i}const s=t.target;if(s!==null&&typeof s=="object"){const r=s,i=r.name;if(typeof i=="string"&&i!=="")return i;const a=r.ref;if(typeof a=="string"&&a!=="")return a;if(typeof r.x=="number"&&typeof r.y=="number")return`${r.x}, ${r.y}`}return null}function T3(e){for(const t of[e.error,e.output]){if(typeof t=="string"&&t.trim()!=="")return t.trim();if(t!==null&&typeof t=="object")for(const s of["message","error","reason"]){const r=t[s];if(typeof r=="string"&&r.trim()!=="")return r.trim()}}return null}function R3({agentId:e,groupId:t,currentId:s,timezone:r,onSelect:i,onNew:a}){const[l,o]=f.useState(null),[c,u]=f.useState(null),[h,d]=f.useState(0);return f.useEffect(()=>{let m=!1;return o(null),u(null),(t?Le.groupConversations(t):Le.conversations(e,100)).then(p=>{m||o(p.conversations)}).catch(p=>{m||u(p instanceof Error?p.message:String(p))}),()=>{m=!0}},[e,t,h]),n.jsxs("section",{className:"wb-history","aria-label":"Past conversations",children:[n.jsxs("div",{className:"ui-toolbar",children:[n.jsx("strong",{children:"Past conversations"}),n.jsx("button",{className:"ui-btn",onClick:a,children:"New conversation"})]}),c?n.jsxs("p",{role:"alert",children:[c," ",n.jsx("button",{className:"ui-btn",onClick:()=>d(m=>m+1),children:"Retry"})]}):l===null?n.jsx("p",{className:"muted",children:"Loading conversations…"}):l.length===0?n.jsx("p",{className:"muted",children:"No conversations yet."}):n.jsx("ul",{children:l.map(m=>n.jsx("li",{children:n.jsxs("a",{href:t?Gl(t,m.id):Ve(e,m.id),"aria-current":m.id===s?"page":void 0,onClick:p=>{p.button===0&&!p.metaKey&&!p.ctrlKey&&!p.shiftKey&&!p.altKey&&(p.preventDefault(),i(m.id))},children:[n.jsx("span",{children:m.preview||m.opening||"Untitled conversation"}),n.jsxs("small",{children:[Be(m.lastMessageAt??m.startedAt??m.createdAt??null,r)," · ",m.messageCount," messages",m.id===s?" · Current":""]})]})},m.id))}),n.jsx("a",{href:"#/conversations",children:"View all agents’ conversation records ↗"}),(l==null?void 0:l.length)===100?n.jsx("p",{className:"muted",children:"Showing the 100 most recent conversations."}):null]})}const J1="buddi.dismissedTabs";function I3(){try{const e=JSON.parse(sessionStorage.getItem(J1)??"{}");return!e||typeof e!="object"||Array.isArray(e)?{}:Object.fromEntries(Object.entries(e).filter(([,t])=>Array.isArray(t)&&t.every(s=>typeof s=="string")))}catch{return{}}}function Ry(e){try{sessionStorage.setItem(J1,JSON.stringify(Object.fromEntries(Object.entries(e).slice(-100))))}catch{}}const P3=350,$3=60;function M3({conversationId:e,onText:t,onNotice:s}){const[r,i]=f.useState("idle"),a=f.useRef("idle"),l=v=>{a.current=v,i(v)},o=f.useRef(null),c=f.useRef(null),u=f.useRef(null),h=f.useRef(null),d=f.useRef(null),m=f.useRef({onText:t,onNotice:s,conversationId:e});m.current={onText:t,onNotice:s,conversationId:e};const p=()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null)},x=async()=>{if(a.current!=="idle")return;m.current.onNotice(null),l("starting"),c.current=null;let v;try{v=await aF(N=>{var k;return(k=d.current)==null?void 0:k.call(d,N)})}catch(N){h.current=null,l("idle"),m.current.onNotice(iF(N));return}const w=c.current;c.current=null;const y=a.current;if(w==="discard"||y!=="starting"){v.cancel(),y==="starting"&&l("idle");return}o.current=v,l("recording"),u.current=window.setTimeout(()=>void j(!1),nF),w&&j(w.sendNow)},j=async v=>{h.current=null;const w=o.current;if(!w){a.current==="starting"&&(c.current={sendNow:v});return}o.current=null,p(),l("transcribing");try{const y=await w.stop();if(y.size<=44){m.current.onNotice("Nothing was recorded.");return}const N=new File([y],`recording-${new Date().toISOString().slice(0,19).replace(/[:T]/g,"-")}.wav`,{type:"audio/wav"}),k=await Le.attach(N),S=m.current.conversationId,C=await Le.transcribe({artifactId:k.artifactId,...S?{conversationId:S}:{}});m.current.onText(C.text,v)}catch(y){m.current.onNotice(y instanceof pe||y instanceof Error?y.message:String(y))}finally{l("idle")}},b=()=>{h.current=null;const v=o.current;if(!v){a.current==="starting"&&(c.current="discard");return}o.current=null,p(),v.cancel(),l("idle")};f.useEffect(()=>{const v=w=>{if(h.current===null)return;const y=Date.now()-h.current;h.current=null,y>=P3&&j(w.shiftKey)};return window.addEventListener("pointerup",v),()=>window.removeEventListener("pointerup",v)},[]);const g=r==="starting"||r==="recording";return f.useEffect(()=>{if(!g)return;const v=w=>{w.isComposing||w.repeat||(w.key==="Escape"?(w.preventDefault(),w.stopPropagation(),b()):w.key==="Enter"&&(w.preventDefault(),w.stopPropagation(),j(w.shiftKey)))};return window.addEventListener("keydown",v,!0),()=>window.removeEventListener("keydown",v,!0)},[g]),f.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 j(v),discard:b,levels:d}}function O3({disabled:e,voice:t}){const s=i=>{e||i.button>0||t.state!=="idle"||(i.preventDefault(),t.hold())},r=i=>{i.detail!==0||e||t.state!=="idle"||t.start()};return n.jsx("button",{type:"button",className:"ui-icon-btn wb-mic","data-size":"sm","aria-label":"Talk",title:"Talk: click to start, or hold to speak and let go to stop",disabled:e,onPointerDown:s,onClick:r,onContextMenu:i=>i.preventDefault(),children:n.jsx(we,{name:"mic"})})}function D3({voice:e}){const t=f.useRef(null),s=e.state==="transcribing";return f.useEffect(()=>{var r;(r=t.current)==null||r.focus()},[]),n.jsxs("div",{className:"wb-listening",role:"group","aria-label":"Recording","data-phase":s?"transcribing":"listening",children:[n.jsx("p",{className:"wb-listening-label","aria-live":"polite",children:s?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"wb-listening-spinner","aria-hidden":"true"}),"Transcribing…"]}):"Listening…"}),n.jsxs("div",{className:"wb-listening-row",children:[n.jsx(_3,{sink:e.levels,frozen:s}),n.jsx("button",{type:"button",className:"wb-send","data-variant":"quiet","aria-label":"Discard recording",title:"Discard (Escape)",disabled:s,onClick:()=>e.discard(),children:n.jsx(we,{name:"close"})}),n.jsx("button",{ref:t,type:"button",className:"wb-send","aria-label":"Stop and transcribe",title:"Stop and transcribe (Enter); Shift sends at once",disabled:s,onClick:r=>e.finish(r.shiftKey),children:n.jsx(we,{name:"check"})})]})]})}function _3({sink:e,frozen:t}){const[s,r]=f.useState(()=>Array($3).fill(0));return f.useEffect(()=>{if(!t)return e.current=i=>r(a=>[...a.slice(1),i]),()=>{e.current=null}},[t]),n.jsx("div",{className:"wb-wave","aria-hidden":"true","data-testid":"waveform",children:s.map((i,a)=>n.jsx("span",{className:"wb-wave-bar",style:{"--level":i.toFixed(3)}},a))})}const L3="This browser cannot capture a tab. Chrome, Safari and Firefox can, on a secure address.",Fc="The tab could not be captured. Try again, and pick the tab itself rather than the whole screen.",F3=e=>e instanceof Error&&(e.name==="NotAllowedError"||e.name==="AbortError");async function z3(e={}){var r;const t=e.media??(typeof navigator>"u"?void 0:navigator.mediaDevices);if(!t||typeof t.getDisplayMedia!="function")throw new Error(L3);let s;try{s=await t.getDisplayMedia({video:{displaySurface:"browser"},audio:!1,selfBrowserSurface:"exclude",surfaceSwitching:"exclude",preferCurrentTab:!1})}catch(i){if(F3(i))return null;throw new Error(Fc)}try{const i=e.document??document,a=i.createElement("video");a.muted=!0,a.playsInline=!0,a.srcObject=s,await new Promise((h,d)=>{a.onloadedmetadata=()=>h(),a.onerror=()=>d(new Error(Fc))}),await a.play(),await new Promise(h=>{const d=a.requestVideoFrameCallback;typeof d=="function"?d.call(a,()=>h()):setTimeout(h,120)});const l=i.createElement("canvas");l.width=a.videoWidth,l.height=a.videoHeight;const o=l.getContext("2d");if(!o||l.width===0)throw new Error(Fc);o.drawImage(a,0,0);const c=await new Promise(h=>l.toBlob(h,"image/png"));if(!c)throw new Error(Fc);const u=(((r=e.now)==null?void 0:r.call(e))??new Date).toISOString().slice(0,19).replace("T"," ").replace(/:/g,".");return new File([c],`Tab ${u}.png`,{type:"image/png"})}finally{s.getTracks().forEach(i=>i.stop())}}const Iy="Send files once the agent has answered.",xp="wb-composer-input",Bx=f.forwardRef(function({disabled:t,running:s,onSend:r,onStop:i,agentName:a,draft:l,model:o,setupHref:c,thinking:u,onThinking:h,onOpenFile:d,mentions:m,history:p,threadKey:x,conversationId:j,readAloud:b,onReadAloud:g,placeholder:v},w){var nn;const y=x?`buddi.draft.${x}`:null,N=K=>{if(!K)return"";try{return window.localStorage.getItem(K)??""}catch{return""}},[k,S]=f.useState(()=>N(y)),[C,I]=f.useState([]),[A,O]=f.useState(!1),[z,L]=f.useState(null),[E,$]=f.useState(!1),_=f.useRef(null),B=f.useRef(null),[M,W]=f.useState(null),[D,U]=f.useState(0),V=M&&m?m.filter(K=>K.handle.toLowerCase().startsWith(M.query.toLowerCase())||K.name.toLowerCase().startsWith(M.query.toLowerCase())).slice(0,6):[],Z=(K,Ne)=>{if(!m||m.length===0){W(null);return}const nt=K.slice(0,Ne),bt=/(^|\s)@([\w-]*)$/.exec(nt);if(!bt){W(null);return}W({start:Ne-bt[2].length-1,query:bt[2]}),U(0)},ue=K=>{if(!M)return;const Ne=B.current,nt=Ne?Ne.selectionStart:k.length,bt=`${k.slice(0,M.start)}@${K} ${k.slice(nt)}`;S(bt),X<0&&ke(bt),W(null),window.requestAnimationFrame(()=>{if(!Ne)return;const Yt=M.start+K.length+2;Ne.focus(),Ne.setSelectionRange(Yt,Yt),ht()})},Ae=p??[],[X,ae]=f.useState(-1),me=f.useRef(k),Pe=f.useRef(y);if(Pe.current!==y){Pe.current=y;const K=N(y);me.current=K,K!==k&&(S(K),ae(-1),W(null))}const ke=K=>{if(me.current=K,!!y)try{K===""?window.localStorage.removeItem(y):window.localStorage.setItem(y,K)}catch{}},ye=K=>{S(K),W(null);const Ne=B.current;Ne&&(Ne.value=K,Ne.setSelectionRange(K.length,K.length)),window.requestAnimationFrame(ht)},Ce=K=>!K.value.slice(0,K.selectionStart??K.value.length).includes(`
104
- `),ut=()=>k===""||X>=0&&k===Ae[X],fe=()=>{X<0||(ae(-1),ye(me.current))},Me=C.some(K=>K.state==="uploading"),ce=C.length>0,Te=s&&ce,G=!t&&!Me&&!Te&&k.trim()!=="",ie=K=>{for(const Ne of Array.from(K??[])){const nt=`${Ne.name}:${Ne.size}:${Math.random().toString(36).slice(2,8)}`,bt=Ne.type.startsWith("image/")&&typeof URL.createObjectURL=="function"?URL.createObjectURL(Ne):null;I(Yt=>[...Yt,{key:nt,filename:Ne.name||"Pasted image",mime:Ne.type||"application/octet-stream",sizeBytes:Ne.size,thumbnail:bt,state:"uploading"}]),Le.attach(Ne).then(Yt=>I(wr=>wr.map(de=>de.key===nt?{...de,state:"ready",uploaded:Yt}:de))).catch(Yt=>I(wr=>wr.map(de=>de.key===nt?{...de,state:"failed",error:Yt instanceof pe?Yt.message:String(Yt)}:de)))}},$e=K=>{K.thumbnail&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(K.thumbnail)},yt=K=>{const Ne=C.find(nt=>nt.key===K);Ne&&($e(Ne),Ne.state==="ready"&&Ne.uploaded&&Le.discardAttachment(Ne.uploaded.artifactId).catch(()=>{})),I(nt=>nt.filter(bt=>bt.key!==K))};f.useImperativeHandle(w,()=>({addFiles:K=>{var Ne;ie(K),(Ne=B.current)==null||Ne.focus()},focus:()=>{var K;return(K=B.current)==null?void 0:K.focus()}}));const Ge=f.useRef(C);Ge.current=C,f.useEffect(()=>()=>Ge.current.forEach($e),[]);const it=f.useRef(0);f.useEffect(()=>{if(!l||l.at===it.current)return;it.current=l.at,S(Ne=>Ne.trim()===""?l.text:Ne),X<0&&k.trim()===""&&ke(l.text);const K=B.current;K&&(K.focus(),window.requestAnimationFrame(()=>{K.style.height="auto",K.style.height=`${Math.min(K.scrollHeight,200)}px`,K.setSelectionRange(K.value.length,K.value.length)}))},[l]);const ht=()=>{const K=B.current;K&&(K.style.height="auto",K.style.height=`${Math.min(K.scrollHeight,200)}px`)},Y=K=>{const Ne=(K??k).trim();if(K===void 0?!G:t||Me||Te||Ne==="")return;const nt=C.filter(bt=>bt.state==="ready"&&bt.uploaded).map(bt=>bt.uploaded);r(Ne,nt),C.forEach($e),ae(-1),ke(""),S(""),I([]),window.requestAnimationFrame(ht)},at=K=>{if(M&&V.length>0){if(K.key==="ArrowDown"){K.preventDefault(),U(Ne=>(Ne+1)%V.length);return}if(K.key==="ArrowUp"){K.preventDefault(),U(Ne=>(Ne-1+V.length)%V.length);return}if(K.key==="Enter"||K.key==="Tab"){K.preventDefault(),ue(V[D].handle);return}if(K.key==="Escape"){K.preventDefault(),W(null);return}}if(K.key==="ArrowUp"&&!K.shiftKey&&!K.altKey&&!K.metaKey&&!K.ctrlKey){const Ne=K.currentTarget;if(Ae.length>0&&X+1<Ae.length&&Ce(Ne)&&ut()){K.preventDefault(),X<0&&(me.current=k),ae(X+1),ye(Ae[X+1]);return}}if(K.key==="ArrowDown"&&!K.shiftKey&&!K.altKey&&!K.metaKey&&!K.ctrlKey&&X>=0&&k===Ae[X]){if(K.preventDefault(),X===0){fe();return}ae(X-1),ye(Ae[X-1]);return}if(K.key==="Escape"&&X>=0){K.preventDefault(),fe();return}K.key==="Enter"&&!K.shiftKey&&(K.preventDefault(),Y())},Gt=K=>{var nt;const Ne=Array.from(((nt=K.clipboardData)==null?void 0:nt.files)??[]);Ne.length!==0&&(K.preventDefault(),ie(Ne))},Se=C.filter(K=>K.state==="failed"),De=Se.length,st=M3({conversationId:j??null,onNotice:L,onText:(K,Ne)=>{const nt=k.trim()===""?K:`${k.replace(/\s+$/,"")} ${K}`;if(Ne){Y(nt);return}ye(nt),X<0&&ke(nt)}}),tt=st.state!=="idle",Mt=f.useRef(!1);return f.useEffect(()=>{var K;Mt.current&&!tt&&((K=B.current)==null||K.focus(),window.requestAnimationFrame(ht)),Mt.current=tt},[tt]),n.jsx("div",{className:"wb-composer","data-testid":"composer","data-busy":k.trim()!==""||ce||tt?"true":void 0,children:n.jsxs("div",{className:"wb-composer-box","data-focused":E||tt,"data-disabled":t,"data-listening":tt||void 0,children:[C.length>0?n.jsx("div",{className:"wb-composer-files",role:"list","aria-label":"Files to send",children:C.map(K=>n.jsx("span",{role:"listitem",children:n.jsx(nh,{name:K.filename,mime:K.mime,sizeBytes:K.sizeBytes,thumbnail:K.thumbnail,state:K.state,error:K.error,onRemove:()=>yt(K.key),...d&&K.state==="ready"&&K.uploaded?{onOpen:()=>d(U3(K.uploaded))}:{},size:"sm"})},K.key))}):null,n.jsxs("label",{className:"sr-only",htmlFor:xp,children:["Message ",a]}),n.jsx("textarea",{id:xp,ref:B,value:k,rows:2,placeholder:s?`${a} is working…`:v??`Message ${a}`,onChange:K=>{S(K.target.value),X<0&&ke(K.target.value),Z(K.target.value,K.target.selectionStart??K.target.value.length),ht()},onFocus:()=>$(!0),onBlur:()=>$(!1),onKeyDown:at,onPaste:Gt,disabled:t,hidden:tt}),tt?n.jsx(D3,{voice:st}):null,!tt&&M&&V.length>0?n.jsx("div",{className:"wb-mentions",role:"listbox","aria-label":"Members",children:V.map((K,Ne)=>n.jsxs("button",{type:"button",role:"option","aria-selected":Ne===D,className:"wb-mention","data-active":Ne===D||void 0,onMouseDown:nt=>{nt.preventDefault(),ue(K.handle)},children:[n.jsxs("span",{className:"wb-mention-handle",children:["@",K.handle]}),n.jsx("span",{className:"wb-mention-name",children:K.name})]},K.handle))}):null,n.jsxs("div",{className:"wb-composer-row",hidden:tt,children:[n.jsx("input",{ref:_,type:"file",multiple:!0,hidden:!0,"data-testid":"file-input",onChange:K=>{ie(K.target.files),K.target.value=""}}),n.jsx("button",{className:"ui-icon-btn","data-size":"sm","aria-label":"Attach a file",title:"Attach a file — or paste one, or drop it anywhere on the chat",onClick:()=>{var K;return(K=_.current)==null?void 0:K.click()},disabled:t,children:n.jsx(we,{name:"clip"})}),n.jsx(O3,{disabled:t,voice:st}),n.jsx("button",{className:"ui-icon-btn","data-size":"sm","aria-label":"Snap a tab",title:"Snap a tab — one picture of another tab in this browser, attached here",onClick:()=>{L(null),O(!0),z3().then(K=>{var Ne;K&&(ie([K]),(Ne=B.current)==null||Ne.focus())}).catch(K=>L(K instanceof Error?K.message:String(K))).finally(()=>O(!1))},disabled:t||A,children:n.jsx(we,{name:"camera"})}),o?c?n.jsxs("a",{className:"wb-composer-model",href:c,title:"The model this agent runs on. Click to change it.",children:[n.jsx("span",{className:"wb-composer-model-dot","aria-hidden":"true"}),o]}):n.jsxs("span",{className:"wb-composer-model",title:"The model this agent runs on",children:[n.jsx("span",{className:"wb-composer-model-dot","aria-hidden":"true"}),o]}):null,h?n.jsxs("button",{type:"button",className:"wb-composer-think","aria-pressed":zc(u),disabled:t||s,title:s?`Wait for ${a} to finish — this run started with thinking ${zc(u)?"on":"off"}`:zc(u)?"Reasoning before the answer is on. Click to turn it off — answers come back faster.":"Reasoning before the answer is off. Click to turn it on.",onClick:()=>h(zc(u)?"off":"on"),children:[n.jsx("span",{className:"wb-composer-think-dot","aria-hidden":"true"}),"Thinking"]}):null,g?n.jsx("button",{type:"button",className:"ui-icon-btn wb-read-aloud","data-size":"sm","aria-label":"Read replies aloud","aria-pressed":!!b,title:b?"Replies are read aloud. Click to stop.":"Read replies aloud, through the voice chosen in Settings → Speech",onClick:()=>g(!b),children:n.jsx(we,{name:"speaker"})}):null,n.jsx("span",{className:"wb-hint","data-shown":k!==""&&!s||De>0||Te||z!==null,"data-tone":De>0||z!==null?"critical":void 0,children:De>0?De===1&&((nn=Se[0])!=null&&nn.error)?Se[0].error:`${De} files failed to upload and will not be sent`:z!==null?z:Te?Iy:"Enter sends, Shift+Enter for a new line"}),s?n.jsx("button",{className:"ui-btn","data-variant":"stop",onClick:i,children:"Stop"}):null,n.jsx("button",{className:"wb-send","aria-label":"Send",title:Te?Iy:Me?"Waiting for the upload to finish":s?`Send — ${a} picks it up between steps`:"Send",onClick:()=>Y(),disabled:!G,children:n.jsx(we,{name:"send"})})]})]})})});function zc(e){return(e??"on")==="on"}function U3(e){return{type:"attachment",artifactId:e.artifactId,filename:e.filename,mime:e.mime,kind:e.kind,sizeBytes:e.sizeBytes}}function B3({question:e,disabled:t,onAnswer:s,onSkip:r}){const[i,a]=f.useState("");return f.useEffect(()=>{if(t)return;const l=o=>{o.key!=="Escape"||o.defaultPrevented||(o.preventDefault(),r())};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[t,r]),n.jsxs("section",{className:"wb-question","aria-label":"Question from agent","data-testid":"question-picker",children:[n.jsxs("div",{className:"wb-question-head",children:[n.jsx("span",{className:"wb-question-kicker",children:"Needs your input"}),n.jsx(R,{className:"wb-question-skip",variant:"ghost",size:"sm",disabled:t,onClick:r,title:"Skip this question (Esc). The agent carries on without an answer.",children:"Skip"}),n.jsx("strong",{children:W3(e.question)})]}),e.options.length>0?n.jsx("div",{className:"wb-question-options",children:e.options.map((l,o)=>n.jsxs("button",{className:"wb-question-option","data-recommended":l.recommended||void 0,disabled:t,onClick:()=>s(l.label,l.id),children:[n.jsx("span",{className:"wb-question-number",children:o+1}),n.jsxs("span",{children:[n.jsxs("span",{className:"wb-question-label",children:[l.label,l.recommended?n.jsx("em",{children:"Recommended"}):null]}),l.hint?n.jsx("small",{children:l.hint}):null]})]},l.id))}):null,e.allowOther?n.jsxs("form",{className:"wb-question-other",onSubmit:l=>{l.preventDefault(),i.trim()&&s(i.trim())},children:[n.jsx("input",{value:i,onChange:l=>a(l.target.value),placeholder:e.options.length?"Something else…":"Type your answer…",disabled:t}),n.jsx("button",{className:"ui-btn","data-variant":"accent",disabled:t||!i.trim(),children:"Answer"})]}):null,n.jsx("p",{className:"wb-question-note",children:"This answers a question. It does not approve an action. Esc skips it."})]})}function W3(e){const t=[];let s=0;for(const r of e.matchAll(/https:\/\/[^\s<>"']+/g)){const i=r[0].replace(/[.,;:!?)\]]+$/,""),a=r.index??0;a>s&&t.push(e.slice(s,a)),t.push(n.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",children:i},a)),s=a+i.length}return s<e.length&&t.push(e.slice(s)),t}function H3(e,t){return e.messages<=0?!1:e.chars>e.maxChars?!0:e.lastActivityAt===null?!1:t-Date.parse(e.lastActivityAt)>e.idleTimeoutMs}function K3(e){const t=e/36e5;if(t>=1&&Number.isInteger(t))return`${t} hour${t===1?"":"s"}`;const s=Math.round(e/6e4);return`${s} minute${s===1?"":"s"}`}function V3(e){const{lifetime:t,startedAt:s,now:r,timezone:i}=e;if(!t||t.messages<=0)return{text:"New conversation",title:"Nothing has been said in this one yet.",tone:"quiet"};const a=`A conversation ends after ${K3(t.idleTimeoutMs)} idle, or once its transcript grows past ${Math.round(t.maxChars/1e3)}k characters. What the agent remembers about you carries over.`,l=`${t.messages} message${t.messages===1?"":"s"}`;if(H3(t,r))return{text:`${l} · your next message starts a fresh one`,title:a,tone:"note"};const o=s?Fe(s,r):"";return{text:o===""?l:`${l} · started ${o}`,title:s?`Started ${Be(s,i)}. ${a}`:a,tone:"quiet"}}const gu=320,X1="buddi.chatWidth";function G3({timezone:e,agents:t,agentId:s,defaultAgentId:r=null,group:i=null,onEditGroup:a,onSelectAgent:l,onWorking:o,attention:c,agentsInHeader:u,narrow:h,canvasOpen:d,onOpenCanvas:m,onCloseCanvas:p,newConversationSignal:x,requestedConversationId:j,requestedTab:b,onConversationOpened:g}){var Wv,Hv,Kv,Vv,Gv,Yv;const v=Ux(),[w,y]=f.useState([]),[N,k]=f.useState(null),[S,C]=f.useState(null),[I,A]=f.useState(null),[O,z]=f.useState([]),[L,E]=f.useState([]),[$,_]=f.useState(null),[B,M]=f.useState(!1),[W,D]=f.useState(new Map),[U,V]=f.useState(null),[Z,ue]=f.useState(I3),[Ae,X]=f.useState([]),[ae,me]=f.useState(!1),Pe=f.useRef(0),ke=f.useRef(null),[ye,Ce]=f.useState(!1),ut=f.useRef(x??0),fe=f.useRef(s),Me=f.useRef({agentId:s,conversationId:N});Me.current={agentId:s,conversationId:N};const ce=Z[N??""]??[],[Te,G]=f.useState(null),[ie,$e]=f.useState(null),[yt,Ge]=f.useState(null),[it,ht]=f.useState([]),[Y,at]=f.useState(!1),[Gt,Se]=f.useState(()=>Date.now()),[De,st]=f.useState(Y3),tt=f.useRef(null),[Mt,nn]=f.useState(null),[K,Ne]=f.useState(!1),[nt,bt]=f.useState(null),[Yt,wr]=f.useState(_1),de=f.useRef(Yt);de.current=Yt;const Ze=f.useRef(null),[Re,sn]=f.useState(null),yr=f.useCallback(F=>{wr(F),L1(F),F||ol()},[]),[Jn,br]=f.useState(null),[kr,Sr]=f.useState(null);f.useEffect(()=>{if(!s)return;const F=X3(s);F&&bt({text:F,at:Date.now()})},[s]);const Ye=i?`group:${i.id}`:s??null,mn=[...t.top,...t.middle,...t.bottom],be=mn.find(F=>F.id===s)??null,Jo=le(()=>T.providerAccounts(),[]),qs=i?i.members.map(F=>mn.find(q=>q.id===F)).filter(F=>!!F):[],[hi,ml]=f.useState(null),fi=B?hi??s??null:null;f.useEffect(()=>{o==null||o(fi)},[fi,o]),f.useEffect(()=>()=>o==null?void 0:o(null),[o]),f.useEffect(()=>{let F=!1;return Le.views().then(q=>{F||y(q.views??[])}).catch(()=>{}),()=>{F=!0}},[]),f.useEffect(()=>{if(!s)return;const F=fe.current===s;if(fe.current=s,F&&j&&j===Me.current.conversationId)return;let q=!1;return k(null),C(null),A(null),z([]),G(null),M(!1),V(null),X([]),Xo(null),Ce(!1),nn(null),j?(j!=="new"?k(j):A(Ye),()=>{q=!0}):((i?Le.groupConversations(i.id):Le.conversations(s)).then(ve=>{if(q)return;const Ee=[...ve.conversations??[]].sort(q3)[0];Ee?(k(Ee.id),g==null||g(s,Ee.id)):A(Ye)}).catch(()=>{q||A(Ye)}),()=>{q=!0})},[s,i==null?void 0:i.id,Ye,j,g]);const Mn=f.useCallback(F=>Le.conversation(F).then(q=>{if(Me.current.conversationId===F){if(q.agentId!==Me.current.agentId)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(q),z(ve=>ve.filter(Ee=>!xf(q,Ee)))}}).catch(q=>{Me.current.conversationId===F&&G(Er(q))}),[]);f.useEffect(()=>{if(!N)return;let F=!1;return D(new Map),E([]),Le.conversation(N).then(q=>{if(!F){if(q.agentId!==s)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(q),z(ve=>ve.filter(Ee=>!xf(q,Ee)))}}).catch(q=>{F||G(Er(q))}),()=>{F=!0}},[N,s]),f.useEffect(()=>{if(!N)return;let F=!1;const q=window.setInterval(()=>{Le.conversation(N).then(ve=>{F||ve.agentId!==Me.current.agentId||(C(ve),z(Ee=>Ee.filter(Ue=>!xf(ve,Ue))))}).catch(()=>{})},3e3);return()=>{F=!0,window.clearInterval(q)}},[N,s]),f.useEffect(()=>{if(!N)return;const F=qd({url:Le.streamUrl(N),onEvent:q=>{var ve;switch(q.name){case"run.started":Ze.current=null,M(!0),_(null),ml(qt(q.data.agentId));break;case"live":{const Ee=qt(q.data.runId)??"",Ue=Number(q.data.turn??0),_e=q.data.kind==="thinking"?"thinking":"text",pn=qt(q.data.text)??"",Js=Date.now();if(_e==="text"){const Is=Ze.current;Ze.current=Is&&Is.runId===Ee&&Is.turn===Ue?{...Is,text:Is.text+pn}:{runId:Ee,turn:Ue,text:pn}}_(Is=>{const Xi=Is&&Is.runId===Ee&&Is.turn===Ue?Is:{runId:Ee,turn:Ue,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return _e==="thinking"?{...Xi,thinking:Xi.thinking+pn,thinkingStartedAt:Xi.thinkingStartedAt??Js}:{...Xi,text:Xi.text+pn,textStartedAt:Xi.textStartedAt??Js}});break}case"live.snapshot":{const Ee=qt(q.data.runId)??"",Ue=Number(q.data.turn??0),_e=qt(q.data.text)??"",pn=qt(q.data.thinking)??"",Js=Number(q.data.startedAt??Date.now());Ze.current={runId:Ee,turn:Ue,text:_e},_({runId:Ee,turn:Ue,text:_e,thinking:pn,thinkingStartedAt:pn?Js:null,textStartedAt:_e?Js:null,settled:!1});break}case"live.settle":{const Ee=qt(q.data.runId)??"",Ue=Number(q.data.turn??0);_(_e=>_e&&_e.runId===Ee&&_e.turn===Ue?{..._e,settled:!0}:_e);break}case"tool.called":{const Ee=qt(q.data.toolUseId)??qt(q.data.id),Ue=qt(q.data.name)??qt(q.data.tool)??"tool";Ee&&E(_e=>[..._e.filter(pn=>pn.toolUseId!==Ee),{toolUseId:Ee,name:Ue,startedAt:Date.now()}]);break}case"tool.result":{const Ee=qt(q.data.toolUseId)??qt(q.data.id);Ee&&E(Ue=>Ue.filter(_e=>_e.toolUseId!==Ee)),Mn(N);break}case"message.appended":Mn(N).then(()=>{_(Ee=>Ee!=null&&Ee.settled?null:Ee)});break;case"awaiting-approval":{const Ee=qt(q.data.approvalId)??qt(q.data.actionId),Ue=qt(q.data.toolUseId);Ee&&Ue&&D(_e=>new Map(_e).set(Ue,Ee)),E(_e=>_e.filter(pn=>pn.toolUseId!==Ue)),Mn(N);break}case"run.finished":{M(!1),E([]),_(null),ml(null);const Ee=qt(q.data.message);G(Ee??null);const Ue=((ve=Ze.current)==null?void 0:ve.text.trim())??"";Ze.current=null,!Ee&&Ue!==""&&de.current&&id(Ue,N).then(_e=>{_e&&sn(_e)}),Mn(N);break}}}});return()=>F.close()},[N,Mn]),f.useEffect(()=>{const F=window.setInterval(()=>Se(Date.now()),L.length===0?6e4:1e3);return()=>window.clearInterval(F)},[L.length]);const mi=le(()=>s&&N?T.browser({agentId:s,conversationId:N}):Promise.resolve(void 0),[s,N],1500),Qs=mi.error?void 0:mi.data,Nr=Qs!=null&&Qs.session&&Qs.session.agentId===s&&Qs.session.conversationId===N?Qs:void 0,Rt=S3(Nr,s,N),Rs=(Rt==null?void 0:Rt.id)??null,[pl,SA]=f.useState(null),Cv=Nr==null?void 0:Nr.mode;f.useEffect(()=>{Rt&&s&&N&&SA({agentId:s,conversationId:N,tab:N3(Rt,Cv)})},[Rs,Cv,s,N]);const NA=pl&&pl.agentId===s&&pl.conversationId===N&&!ce.includes(pl.tab.id)?pl.tab:null,rn=Rt??NA,CA=f.useMemo(()=>C3((S==null?void 0:S.messages)??[]),[S]),[EA,Xo]=f.useState(null),AA=f.useMemo(()=>SF({messages:(S==null?void 0:S.messages)??[],descriptors:w}),[S,w]),Qi=F4(AA,N??null),oh=U4(i?null:s),Ev=f.useMemo(()=>z4((S==null?void 0:S.messages)??[]),[S]),On=f.useMemo(()=>{const q=NF({messages:(S==null?void 0:S.messages)??[],descriptors:w,awaiting:W,served:Qi.served,...rn?{folded:pu}:{}}).filter(ve=>ve.source==="approval"||!ce.includes(ve.id));if(U&&!ce.includes(U)&&!q.some(ve=>ve.id===U)){const ve=TF((S==null?void 0:S.messages)??[],U,{redactInputOf:pu});ve&&!pu.has(ve.tool)&&q.push(ve)}rn&&q.push(rn);for(const ve of Ae)q.push(J_(ve));return oh&&q.unshift(B4(oh,Ev)),Mt?[...q,W4(Mt)]:q},[S,w,W,Mt,Rs,rn==null?void 0:rn.title,U,Z,N,Ae,Qi.served,oh,Ev]),TA=f.useMemo(()=>{var q;const F=[];for(const ve of(S==null?void 0:S.messages)??[]){if(ve.role!=="user"||ve.speaker&&ve.speaker!=="owner")continue;const Ee=(q=ve.blocks.find(Ue=>Ue.type==="text"))==null?void 0:q.text.trim();Ee&&F.unshift(Ee)}return F},[S]),ch=f.useMemo(()=>On.filter(F=>F.source==="approval"),[On]),Zo=ch.at(-1)??null,ec=f.useMemo(()=>[...ch.map(F=>({approvalId:F.props.approvalId,toolUseId:F.id})),...((S==null?void 0:S.delegatedApprovals)??[]).map(F=>({approvalId:F.approvalId,toolUseId:F.toolUseId??"",askedBy:nz(F.chain,mn)}))],[ch,S==null?void 0:S.delegatedApprovals]),gl=f.useMemo(()=>{for(let F=On.length-1;F>=0;F-=1){const q=On[F];if(q!=null&&q.substantial)return q.id}return null},[On]),tc=f.useRef(null),uh=((Wv=On.filter(F=>(F.source!=="browser"||F.pinned===!0)&&F.id!==pp).at(-1))==null?void 0:Wv.id)??((Hv=On.filter(F=>F.id!==pp).at(-1))==null?void 0:Hv.id)??null;f.useEffect(()=>{if(gl&&gl!==tc.current){tc.current=gl,V(gl);return}U===null&&uh&&V(uh)},[gl,U,uh]);const Av=f.useRef(Qi.live);f.useEffect(()=>{const F=Av.current;Av.current=Qi.live;const q=[...Qi.live].filter(Ue=>!F.has(Ue));if(q.length===0||Zo||U!==null&&U!==tc.current)return;const Ee=[...On].reverse().find(Ue=>Ue.source==="descriptor"&&Ue.renderer==="preview"&&Ue.props.target!==null&&q.includes(Pa(Ue.props.target)));Ee&&V(Ee.id)},[Qi.live,On,Zo,U]);const Tv=f.useRef(null);f.useEffect(()=>{Rs!==Tv.current&&(Tv.current=Rs,Rs&&!Zo&&V(Rs))},[Rs,Zo]);const Rv=f.useRef(null),xl=b==="browser"?(rn==null?void 0:rn.id)??null:null;f.useEffect(()=>{!xl||Rv.current===xl||(Rv.current=xl,V(xl))},[xl]);const dh=(rn==null?void 0:rn.id)??null;f.useEffect(()=>{!dh||!U||Ty((S==null?void 0:S.messages)??[],U)!==null&&(Xo(U),V(dh))},[dh,U,S]);const Iv=F=>{X(q=>q.some(ve=>ve.artifactId===F.artifactId)?q:[...q,F]),V(fu(F.artifactId)),h&&(m==null||m())},nc=!i&&be&&!be.available?XN(be):null,Pv=Qm(i?null:be),$v=((S==null?void 0:S.offers)??[]).filter(F=>!it.includes(F.id)&&Date.parse(F.expiresAt)>Gt),RA=be&&kr===be.id?Jn:(be==null?void 0:be.thinking)??null,IA=F=>{if(!be)return;const q=be.id;Sr(q),br(F),T.setAgentEngine(q,{thinking:F}).catch(ve=>{Sr(null),G(ve instanceof pe?ve.message:String(ve))})},Mv=(F,q)=>{if(!s)return;const ve=q.map(_e=>_e.artifactId),Ee=B,Ue={id:`optimistic:${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:F},...q.map(_e=>({type:"attachment",artifactId:_e.artifactId,filename:_e.filename,mime:_e.mime,kind:_e.kind,sizeBytes:_e.sizeBytes}))],...Ee?{speaker:V1}:{}};z(_e=>Ee?[..._e,Ue]:[Ue]),G(null),$e(null),M(!0),(i?Le.sendToGroup(i.id,{...N?{conversationId:N}:{},text:F,attachmentIds:ve}):Le.send(s,{...N?{conversationId:N}:{},text:F,attachmentIds:ve})).then(async _e=>{Me.current.agentId!==s||Me.current.conversationId!==N||($e(_e.rolledOver===!0?"(New thread — the room had grown long. Where it stopped carries over as a summary.)":null),_e.conversationId!==N?(C(null),k(_e.conversationId)):await Mn(_e.conversationId),_e.queued===!0&&z(pn=>pn.filter(Js=>Js.id!==Ue.id)),g==null||g(s,_e.conversationId))}).catch(_e=>{z(pn=>pn.filter(Js=>Js.id!==Ue.id)),G(Er(_e)),M(!1)})},PA=F=>{G(null),Ge(F),ht(q=>[...q,F]),T.takeOffer(F,N??void 0).then(q=>{q.runId&&($e(null),M(!0)),N&&Mn(N)}).catch(q=>{ht(ve=>ve.filter(Ee=>Ee!==F)),G(Er(q)),N&&Mn(N)}).finally(()=>Ge(null))},$A=(F,q)=>Ov({answer:F,...q?{optionId:q}:{}}),MA=()=>Ov({answer:"",skipped:!0}),Ov=F=>{const q=S==null?void 0:S.question;q&&(G(null),at(!0),M(!0),Le.answerQuestion(q.id,F).then(()=>{if(N)return Mn(N)}).catch(ve=>{G(Er(ve)),M(!1)}).finally(()=>at(!1)))},OA=()=>{if(s){if(Mt){nn(null);return}Ne(!0),T.agentProfile(s).then(F=>{nn(F),V(gp(F.id)),h&&(m==null||m())}).catch(F=>G(Er(F))).finally(()=>Ne(!1))}},DA=F=>{bt({text:F.prompt,at:Date.now()}),l(F.agentId),h&&(p==null||p())},_A=()=>{N&&Le.cancel(N).catch(F=>G(Er(F))).finally(()=>{M(!1),E([])})},sc=f.useCallback(()=>{if(k(null),C(null),z([]),M(!1),G(null),$e(null),E([]),D(new Map),V(null),X([]),Xo(null),tc.current=null,i){Le.startGroupConversation(i.id).then(({conversationId:F})=>{k(F),s&&(g==null||g(s,F))}).catch(F=>G(Er(F)));return}A(Ye),s&&(g==null||g(s,"new"))},[s,i,Ye,g]);f.useEffect(()=>{x&&x!==ut.current&&(ut.current=x,sc())},[x,sc]);const Dv=F=>{N&&Mn(N),T.overview().catch(()=>{}),F.state!=="pending"&&D(q=>new Map([...q].filter(([,ve])=>ve!==F.id)))},rc=f.useRef(!1);f.useEffect(()=>{const F=ve=>{if(!rc.current)return;const Ee=Math.max(gu,Math.min(720,ve.clientX-52));st(Ee)},q=()=>{if(rc.current){rc.current=!1;try{De!==null&&window.localStorage.setItem(X1,String(De))}catch{}}};return window.addEventListener("pointermove",F),window.addEventListener("pointerup",q),()=>{window.removeEventListener("pointermove",F),window.removeEventListener("pointerup",q)}},[De]);const LA=((Kv=mn.find(F=>F.id===r))==null?void 0:Kv.name)??null,_v=i?[]:PD(be,LA),Lv=!(S&&S.conversationId===N)&&!(!N&&I!==null&&I===Ye),Fv=Lv?n.jsx("div",{className:"wb-chat-loading","data-testid":"chat-loading","aria-busy":"true"}):!i&&be?n.jsx(k1,{quiet:!0,still:!0,className:"wb-chat-field",children:n.jsxs("div",{className:"wb-chat-opening","data-testid":"chat-opening",children:[n.jsx(Nn,{agents:mn,id:be.id,size:"xl"}),n.jsx("h2",{className:"wb-chat-hello",children:`Hi, I'm ${be.name}.`}),n.jsx("p",{className:"wb-chat-intro",children:$D(be)}),_v.length>0?n.jsx("div",{className:"wb-starters",role:"group","aria-label":`Things to ask ${be.name}`,children:_v.map(F=>n.jsx("button",{type:"button",className:"wb-starter",onClick:()=>{var q;bt({text:F,at:Date.now()}),(q=ke.current)==null||q.focus()},children:F},F))}):null]})}):null,zv=n.jsx(E4,{renderables:On,activeId:U,onActivate:V,onClose:F=>{Mt&&F===gp(Mt.id)?nn(null):Ae.some(q=>fu(q.artifactId)===F)?X(q=>q.filter(ve=>fu(ve.artifactId)!==F)):N&&ue(q=>{const ve={...q,[N]:[...new Set([...q[N]??[],F])]};return Ry(ve),ve}),U===F&&V(null)},timezone:e,onDecided:Dv,onChangeAgent:DA,agents:mn,browserPanel:rn?n.jsx(w3,{status:Nr,error:mi.error,reload:mi.reload,steps:CA,live:Rt!==null,focusedStepId:EA},rn.id):null,descriptors:w,grantedTools:i?qs.flatMap(F=>F.tools??[]):(be==null?void 0:be.tools)??[],...be?{agentName:be.name}:{},loading:Lv,...!i&&be?{face:n.jsx(Nn,{agents:mn,id:be.id,size:"xl"})}:{}}),Uv=(Gv=(Vv=[...(S==null?void 0:S.messages)??[],...O].find(F=>F.role==="user"))==null?void 0:Vv.blocks.find(F=>F.type==="text"))==null?void 0:Gv.text.trim(),Bv=Uv?Uv.split(`
105
- `)[0]:"New conversation",Ji=V3({lifetime:(S==null?void 0:S.lifetime)??null,startedAt:(S==null?void 0:S.startedAt)??null,now:Gt,timezone:e});return n.jsxs(n.Fragment,{children:[n.jsxs("section",{className:"wb-chat",ref:tt,style:h||De===null?void 0:{width:De},"data-sized":!h&&De!==null?"true":void 0,"data-testid":"chat-column","data-dropping":ae||void 0,onDragEnter:F=>{Uc(F)&&(F.preventDefault(),Pe.current+=1,me(!0))},onDragOver:F=>{Uc(F)&&(F.preventDefault(),F.dataTransfer.dropEffect="copy")},onDragLeave:F=>{Uc(F)&&(Pe.current=Math.max(0,Pe.current-1),Pe.current===0&&me(!1))},onDrop:F=>{var q;Uc(F)&&(F.preventDefault(),Pe.current=0,me(!1),s&&((q=ke.current)==null||q.addFiles(F.dataTransfer.files)))},children:[ae?n.jsx("div",{className:"wb-drop","aria-hidden":"true",children:n.jsxs("div",{className:"wb-drop-card",children:[n.jsx(Q3,{}),n.jsx("strong",{children:"Drop to attach"}),n.jsx("span",{children:be?`It goes with your next message to ${be.name}`:"Pick an agent first"})]})}):null,n.jsxs("header",{className:"wb-chat-head","data-testid":"chat-head",...!i&&be?Ko(Ho(be)):{},children:[n.jsxs("div",{className:"wb-head-row",children:[i?n.jsx("span",{className:"wb-head-face wb-head-group","aria-hidden":"true",children:qs.slice(0,3).map(F=>n.jsx(Nn,{agents:mn,id:F.id,size:"sm"},F.id))}):be?n.jsx("a",{className:"wb-head-face",href:pt(be.id),"aria-label":`${be.name}'s page`,children:n.jsx(Nn,{agents:mn,id:be.id})}):null,n.jsxs("div",{className:"wb-head-text",children:[i?n.jsx("span",{className:"wb-head-title",children:i.name}):n.jsx("span",{className:"wb-head-title",title:Bv,children:Bv}),n.jsx("span",{className:"wb-head-meta","data-tone":Ji.tone,title:i?`${qs.map(F=>F.name).join(", ")}. Coordinator: ${(be==null?void 0:be.name)??i.coordinator}.`:Ji.title,children:i?`${qs.map(F=>F.name).join(", ")} · ${Ji.text}`:be?n.jsxs(n.Fragment,{children:[n.jsx("a",{className:"wb-head-name",href:pt(be.id),title:`${be.name}'s page`,children:be.name})," ",n.jsxs("span",{className:"wb-head-handle",children:["@",be.handle]}),` · ${Ji.tone==="quiet"&&Ji.text==="New conversation"?`on ${v}`:Ji.text}`]}):"No agent"})]}),n.jsx("button",{className:"ui-icon-btn wb-head-more","data-size":"sm","aria-label":"New chat",title:"New chat",disabled:!s,onClick:()=>{Ce(!1),sc()},children:n.jsx(we,{name:"plus",size:16})}),n.jsx("button",{className:"ui-icon-btn wb-head-more","aria-label":"History",title:"Earlier conversations","aria-expanded":ye,"data-open":ye?"true":void 0,disabled:!s,onClick:()=>Ce(F=>!F),children:n.jsx(Z3,{})}),h?n.jsxs("button",{className:"ui-btn",onClick:m,disabled:On.length===0,children:["Canvas",On.length>0?` (${On.length})`:""]}):null,n.jsx(tz,{disabled:!s,items:i?[...qs.map(F=>({label:F.name,hint:F.id===i.coordinator?"Coordinator · open page":"Member · open page",href:pt(F.id)})),...a?[{label:"Members…",hint:"Name, coordinator, who is in the room",testId:"group-members",onSelect:a}]:[]]:[{label:Mt?"Close properties":"Properties",hint:"What this agent can do, on the Canvas",testId:"agent-properties",disabled:K,onSelect:OA},...be?[{label:"Set up",hint:"Identity, model and access",href:pt(be.id,"setup")},{label:"Open agent page",hint:"Profile, activity and setup",href:pt(be.id)}]:[]]})]}),u?n.jsx(e1,{agents:t,currentId:s,attention:c,onSelect:l,orientation:"horizontal",...fi?{working:new Set([fi])}:{}}):null]}),ye&&s?n.jsx(R3,{agentId:s,...i?{groupId:i.id}:{},currentId:N,timezone:e,onNew:()=>{Ce(!1),sc()},onSelect:F=>{if(F===N){Ce(!1);return}Ce(!1),C(null),z([]),M(!1),V(null),G(null),$e(null),X([]),k(F),g==null||g(s,F,!1)}}):null,s&&N?n.jsx(b3,{agentId:s,conversationId:N},`${s}:${N}`):null,Te?n.jsx("div",{className:"wb-chat-notice",children:n.jsx(se,{message:Te})}):null,ie?n.jsx("div",{className:"wb-chat-notice","data-testid":"chat-notice",children:ie}):null,S!=null&&S.carriedOver?n.jsx("div",{className:"wb-carryover","data-testid":"chat-carryover",children:S.carriedOver}):null,n.jsx(Fx,{messages:[...(S==null?void 0:S.messages)??[],...O],live:L,now:Gt,working:B,partial:$,agents:mn,...S!=null&&S.runs?{runs:S.runs}:{},...i?{speakers:mn,coordinatorId:i.coordinator}:{},...hi?{workingAs:((Yv=mn.find(F=>F.id===hi))==null?void 0:Yv.name)??hi}:{},onOpenFile:Iv,onReadAloud:(F,q)=>{sn(null),id(q,N??void 0,F).then(ve=>{ve&&sn(ve)})},onOpen:F=>{if(rn){const q=Ty([...(S==null?void 0:S.messages)??[],...O],F);if(q){Xo(q),V(rn.id),h&&(m==null||m());return}}N&&ue(q=>{const ve={...q,[N]:(q[N]??[]).filter(Ee=>Ee!==F)};return Ry(ve),ve}),V(F),h&&(m==null||m())},...be?{agentName:be.name,agentId:be.id}:{},...Fv?{empty:Fv}:{},emptyHint:be?`Nothing here yet. Ask ${be.name} for something.`:"Loading agents…"}),$v.length>0?n.jsx("div",{className:"wb-offers","data-testid":"chat-offers",children:$v.map(F=>n.jsx("button",{className:"ui-btn",disabled:yt!==null,title:F.prompt,onClick:()=>PA(F.id),children:F.label},F.id))}):null,nc?n.jsx("div",{className:"wb-composer-blocked","data-testid":"composer-blocked",children:n.jsxs(H,{tone:"warning",role:"status",children:[nc," ",n.jsx("a",{href:et(Pv.section),children:Pv.label})]})}):ec.length>0?n.jsx(o4,{approvals:ec,timezone:e,now:Gt,version:S,onDecided:Dv,onSay:F=>Mv(F,[]),onOpenFull:F=>{V(F),h&&(m==null||m())}}):null,nc||ec.length>0?null:S!=null&&S.question?n.jsx(B3,{question:S.question,disabled:Y||B,onAnswer:$A,onSkip:MA},S.question.id):null,nc?null:n.jsxs("div",{hidden:ec.length>0||!!(S!=null&&S.question),"data-testid":"composer-slot",children:[n.jsx(Bx,{ref:ke,disabled:!s,running:B,onSend:Mv,onStop:_A,agentName:i?i.name:(be==null?void 0:be.name)??"the agent",draft:nt,history:TA,threadKey:N??(i?`group:${i.id}`:s),model:i?null:(be==null?void 0:be.model)??null,setupHref:i?null:be?pt(be.id,"setup","brain"):null,thinking:RA,...!i&&be&&KS(VS(be,Jo.data))?{onThinking:IA}:{},...i?{mentions:qs.map(F=>({handle:F.handle,name:F.name}))}:{},onOpenFile:Iv,conversationId:N??null,readAloud:Yt,onReadAloud:yr}),Re?n.jsx("p",{className:"wb-voice-note",role:"status",children:Re}):null]})]}),h?d?n.jsxs("div",{className:"wb-sheet",role:"dialog","aria-label":"Canvas",children:[n.jsxs("div",{className:"wb-sheet-head",children:[n.jsx("strong",{children:"Canvas"}),n.jsx("button",{className:"ui-btn",onClick:p,children:"Close"})]}),zv]}):null:n.jsxs(n.Fragment,{children:[n.jsx("button",{className:"wb-grip","aria-label":"Resize the conversation column",onPointerDown:F=>{var q,ve;rc.current=!0,(ve=(q=F.currentTarget).setPointerCapture)==null||ve.call(q,F.pointerId)},onKeyDown:F=>{const q=ve=>{var Ee;return ve??((Ee=tt.current)==null?void 0:Ee.offsetWidth)??gu};F.key==="ArrowLeft"&&st(ve=>Math.max(gu,q(ve)-16)),F.key==="ArrowRight"&&st(ve=>Math.min(720,q(ve)+16))}}),zv]})]})}function Y3(){try{const e=window.localStorage.getItem(X1),t=Number(e);return e!==null&&Number.isFinite(t)&&t>=gu?t:null}catch{return null}}function q3(e,t){return Date.parse(t.lastMessageAt??t.startedAt??t.createdAt??"")-Date.parse(e.lastMessageAt??e.startedAt??e.createdAt??"")}function qt(e){return typeof e=="string"&&e!==""?e:null}function Er(e){return e instanceof pe||e instanceof Error?e.message:String(e)}function xf(e,t){var r;const s=(r=t.blocks.find(i=>i.type==="text"))==null?void 0:r.text.trim();if(!s)return!0;for(let i=e.messages.length-1;i>=0;i-=1){const a=e.messages[i];if(a.role!=="user")continue;const l=a.blocks.find(o=>o.type==="text");if(l)return l.text.trim()===s}return!1}function Uc(e){var s;const t=(s=e.dataTransfer)==null?void 0:s.types;return!!(t&&Array.from(t).includes("Files"))}function Q3(){return n.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 28 28","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M14 4v13M8.5 11.5 14 17l5.5-5.5"}),n.jsx("path",{d:"M5 19.5v2a2.5 2.5 0 0 0 2.5 2.5h13a2.5 2.5 0 0 0 2.5-2.5v-2"})]})}const vp="buddi.chatDraft";function J3(e,t){try{window.sessionStorage.setItem(vp,JSON.stringify({agentId:e,text:t}))}catch{}}function X3(e){try{const t=window.sessionStorage.getItem(vp);if(!t)return null;const s=JSON.parse(t);return s.agentId!==e||typeof s.text!="string"?null:(window.sessionStorage.removeItem(vp),s.text)}catch{return null}}function Z3(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M2.6 8a5.4 5.4 0 1 0 1.6-3.8"}),n.jsx("path",{d:"M2.4 2.6v2.6h2.6M8 5.2V8l2 1.3"})]})}function ez(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",fill:"currentColor",children:[n.jsx("circle",{cx:"8",cy:"3.4",r:"1.35"}),n.jsx("circle",{cx:"8",cy:"8",r:"1.35"}),n.jsx("circle",{cx:"8",cy:"12.6",r:"1.35"})]})}function tz({items:e,disabled:t}){const[s,r]=f.useState(!1),i=f.useRef(null);return f.useEffect(()=>{if(!s)return;const a=o=>{i.current&&!i.current.contains(o.target)&&r(!1)},l=o=>{o.key==="Escape"&&r(!1)};return window.addEventListener("mousedown",a),window.addEventListener("keydown",l),()=>{window.removeEventListener("mousedown",a),window.removeEventListener("keydown",l)}},[s]),n.jsxs("div",{className:"wb-head-menu",ref:i,children:[n.jsx("button",{className:"ui-icon-btn wb-head-more","data-testid":"chat-menu","aria-label":"More about this agent","aria-haspopup":"menu","aria-expanded":s,"data-open":s?"true":void 0,disabled:t,onClick:()=>r(a=>!a),children:n.jsx(ez,{})}),s?n.jsx("div",{className:"ui-menu wb-head-menu-list",role:"menu",children:e.map(a=>a.href?n.jsxs("a",{className:"ui-menu-item",role:"menuitem",href:a.href,onClick:()=>r(!1),children:[n.jsx("span",{className:"ui-menu-item-text",children:a.label}),a.hint?n.jsx("span",{className:"ui-menu-item-hint",children:a.hint}):null]},a.label):n.jsxs("button",{className:"ui-menu-item",role:"menuitem","data-testid":a.testId,disabled:a.disabled,onClick:()=>{var l;r(!1),(l=a.onSelect)==null||l.call(a)},children:[n.jsx("span",{className:"ui-menu-item-text",children:a.label}),a.hint?n.jsx("span",{className:"ui-menu-item-hint",children:a.hint}):null]},a.label))}):null]})}function nz(e,t){const s=a=>{var l;return`@${((l=t.find(o=>o.id===a))==null?void 0:l.handle)??a}`},[r,...i]=e;return r===void 0?"":[s(r),...i.map(a=>`asked by ${s(a)}`)].join(", ")}let Py=!1;const sz=new Set(["missing","unconfigured","not-english"]);async function id(e,t,s=null){const r=F1(s);try{const i=await Le.say({text:e,...t?{conversationId:t}:{}});return py(r)&&await hF(i.audioUrl,i.mime,s),null}catch(i){py(r)&&ol();const a=i instanceof pe&&i.detail&&typeof i.detail=="object"?i.detail.reason:void 0;return typeof a=="string"&&sz.has(a)&&(s!==null||!Py)?(Py=!0,i.message):null}}let Zn=null;function rz(e){if(hu(e)!==null)return!1;const t=KN(e);return t!==Kt&&t!==Vr}function iz({agent:e,agents:t,open:s,onOpenChange:r,navigate:i}){const a=f.useRef(null),l=f.useRef(s),o=`Ask ${e.name}`,[c,u]=f.useState(!1);return f.useEffect(()=>{if(s||!c||!Zn)return;const h=qd({url:Le.streamUrl(Zn.conversationId),lastEventId:Zn.lastEventId??null,onEvent:d=>{d.name==="run.finished"&&u(!1)}});return()=>h.close()},[s,c]),f.useEffect(()=>{const h=d=>{!d.altKey||d.ctrlKey||d.metaKey||d.code!=="Slash"||(d.preventDefault(),r(!s))};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[s,r]),f.useEffect(()=>{var h;l.current&&!s&&((h=a.current)==null||h.focus()),l.current=s},[s]),s?n.jsx(lz,{agent:e,agents:t,navigate:i,onClose:()=>r(!1),onBusy:u}):n.jsxs(jo,{children:[n.jsx(wo,{asChild:!0,children:n.jsx("button",{ref:a,type:"button",className:"wb-ask-fab","data-busy":c?"true":void 0,"aria-label":o,onClick:()=>r(!0),children:n.jsx(az,{busy:c})})}),n.jsx(yo,{children:n.jsx(bo,{className:"ui-tip",side:"left",sideOffset:8,children:o})})]})}function az({busy:e}){const[t,s]=f.useState(!1);return t?n.jsx(Xu,{size:"lg"}):n.jsx(Xd,{state:e?"working":"idle",className:"wb-ask-fab-face",onStillError:()=>s(!0)})}function lz({agent:e,agents:t,navigate:s,onClose:r,onBusy:i}){const a=f.useRef(null),[l,o]=f.useState(Zn&&Zn.agentId===e.id?Zn.conversationId:null),[c,u]=f.useState(null),[h,d]=f.useState([]),[m,p]=f.useState([]),[x,j]=f.useState(null),[b,g]=f.useState(!1),[v,w]=f.useState(!1),[y,N]=f.useState(null),[k,S]=f.useState(null),[C,I]=f.useState(Date.now()),[A,O]=f.useState(_1),z=f.useRef(A);z.current=A;const[L,E]=f.useState(null),$=f.useRef(null),_=f.useCallback(async Z=>{try{const ue=await Le.conversation(Z);u(ue),d(Ae=>Ae.filter(X=>!oz(ue,X)))}catch{}},[]);f.useEffect(()=>{l&&_(l)},[l,_]),f.useEffect(()=>{if(!l)return;const Z=qd({url:Le.streamUrl(l),onEvent:ue=>{var Ae;switch(ue.name){case"run.started":$.current=null,g(!0),j(null);break;case"live":{const X=Dn(ue.data.runId)??"",ae=Number(ue.data.turn??0),me=ue.data.kind==="thinking"?"thinking":"text",Pe=Dn(ue.data.text)??"",ke=Date.now();if(me==="text"){const ye=$.current;$.current=ye&&ye.runId===X&&ye.turn===ae?{...ye,text:ye.text+Pe}:{runId:X,turn:ae,text:Pe}}j(ye=>{const Ce=ye&&ye.runId===X&&ye.turn===ae?ye:{runId:X,turn:ae,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return me==="thinking"?{...Ce,thinking:Ce.thinking+Pe,thinkingStartedAt:Ce.thinkingStartedAt??ke}:{...Ce,text:Ce.text+Pe,textStartedAt:Ce.textStartedAt??ke}});break}case"live.snapshot":{const X=Dn(ue.data.runId)??"",ae=Number(ue.data.turn??0),me=Dn(ue.data.text)??"",Pe=Dn(ue.data.thinking)??"",ke=Number(ue.data.startedAt??Date.now());$.current={runId:X,turn:ae,text:me},g(!0),j({runId:X,turn:ae,text:me,thinking:Pe,thinkingStartedAt:Pe?ke:null,textStartedAt:me?ke:null,settled:!1});break}case"live.settle":{const X=Dn(ue.data.runId)??"",ae=Number(ue.data.turn??0);j(me=>me&&me.runId===X&&me.turn===ae?{...me,settled:!0}:me);break}case"tool.called":{const X=Dn(ue.data.toolUseId)??Dn(ue.data.id),ae=Dn(ue.data.name)??Dn(ue.data.tool)??"tool";X&&p(me=>[...me.filter(Pe=>Pe.toolUseId!==X),{toolUseId:X,name:ae,startedAt:Date.now()}]);break}case"tool.result":{const X=Dn(ue.data.toolUseId)??Dn(ue.data.id);X&&p(ae=>ae.filter(me=>me.toolUseId!==X)),_(l);break}case"message.appended":case"awaiting-approval":_(l).then(()=>j(X=>X!=null&&X.settled?null:X));break;case"run.finished":{g(!1),p([]),j(null);const X=Dn(ue.data.message);N(X??null);const ae=((Ae=$.current)==null?void 0:Ae.text.trim())??"";$.current=null,!X&&ae!==""&&z.current&&id(ae,l).then(me=>{me&&E(me)}),_(l);break}}}});return()=>{Zn&&Zn.conversationId===l&&(Zn.lastEventId=Z.lastEventId()),Z.close()}},[l,_]),f.useEffect(()=>{i(b||v)},[b,v,i]),f.useEffect(()=>{if(m.length===0)return;const Z=window.setInterval(()=>I(Date.now()),1e3);return()=>window.clearInterval(Z)},[m.length]);const B=(Z,ue)=>{w(!0),N(null);const Ae={id:`local-${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:Z}]};d(X=>[...X,Ae]),(async()=>{try{const X=l??(await Le.startConversation(e.id)).conversationId;X!==l&&(Zn={agentId:e.id,conversationId:X},o(X));const ae=await Le.send(e.id,{conversationId:X,text:Z,...ue.length>0?{attachmentIds:ue.map(me=>me.artifactId)}:{}});ae.conversationId!==X&&(Zn={agentId:e.id,conversationId:ae.conversationId},o(ae.conversationId)),g(!0),_(ae.conversationId)}catch(X){d(ae=>ae.filter(me=>me.id!==Ae.id)),N(X instanceof pe?X.message:String(X)),S({text:Z,at:Date.now()})}finally{w(!1)}})()},M=()=>{l&&Le.cancel(l).catch(Z=>N(String(Z))).finally(()=>g(!1))},W=()=>{var Z;Zn=null,o(null),u(null),d([]),p([]),j(null),g(!1),N(null),(Z=a.current)==null||Z.focus()},D=Z=>{O(Z),L1(Z),Z||ol()},U=l?Ve(e.id,l):Ve(e.id),V=[...(c==null?void 0:c.messages)??[],...h];return n.jsxs(U_,{title:e.name,label:`${e.name}, a quick chat`,onClose:r,onOpenAutoFocus:Z=>{var ue;Z.preventDefault(),(ue=a.current)==null||ue.focus()},onCloseAutoFocus:Z=>Z.preventDefault(),actions:n.jsxs(n.Fragment,{children:[n.jsx(R,{size:"sm",variant:"ghost",onClick:W,disabled:l===null&&h.length===0,children:"New"}),n.jsx(Zt,{size:"sm",variant:"ghost",href:U,onClick:Z=>{Z.preventDefault(),s(U)},children:"Open in Chat"})]}),children:[n.jsx("div",{className:"wb-ask-thread",children:n.jsx(Fx,{messages:V,live:m,now:C,working:b||v,partial:x,agents:t,agentName:e.name,agentId:e.id,onOpen:()=>s(U),onReadAloud:(Z,ue)=>{E(null),id(ue,l??void 0,Z).then(Ae=>{Ae&&E(Ae)})},emptyHint:`Ask ${e.name} anything, without leaving this page.`})}),n.jsxs("div",{className:"wb-ask-compose",children:[y?n.jsx(se,{message:y}):null,n.jsx(Bx,{ref:a,disabled:v||!e.available,running:b,onSend:B,onStop:M,agentName:e.name,placeholder:`Message ${e.name}…`,draft:k,threadKey:`dock.${l??e.id}`,conversationId:l,readAloud:A,onReadAloud:D}),L?n.jsx("p",{className:"wb-voice-note",role:"status",children:L}):null]})]})}function Dn(e){return typeof e=="string"?e:null}function oz(e,t){var r;const s=(r=t.blocks)==null?void 0:r.find(i=>i.type==="text");return!s||s.type!=="text"?!1:e.messages.some(i=>i.role==="user"&&(i.blocks??[]).some(a=>a.type==="text"&&a.text.includes(s.text)))}const Z1=3;function cz(e){if(e==="approval"||e==="question")return"accent";if(e==="watcher"||e==="reminder")return"warm";if(e==="failure")return"critical"}function uz(e,t){return e?t?"above-dock":"above-button":"corner"}function dz({placement:e,children:t}){return n.jsx("div",{className:"wb-toast-stack","data-placement":e,children:t})}function hz(e){return e.state==="shown"&&e.seenAt===null}function fz(e){const[t,s]=f.useState([]),r=f.useRef(new Set),i=f.useRef(new Set),a=f.useCallback(()=>{e&&T.notifications(20).then(({notifications:o})=>{const c=o.filter(u=>hz(u)&&!r.current.has(u.id));s(u=>{const h=new Set(u.map(m=>m.id)),d=c.filter(m=>!h.has(m.id));return d.length===0?u:[...u,...d].sort((m,p)=>p.createdAt.localeCompare(m.createdAt))})}).catch(()=>{})},[e]);f.useEffect(()=>{for(const o of t.slice(0,Z1))i.current.has(o.id)||(i.current.add(o.id),T.notificationSeen(o.id).catch(()=>{}))},[t]);const l=f.useCallback(o=>{r.current.add(o),s(c=>c.filter(u=>u.id!==o))},[]);return{queue:t,refresh:a,dismiss:l}}function mz({queue:e,agents:t,navigate:s,onDismiss:r}){if(e.length===0)return null;const i=e.slice(0,Z1),a=e.length-i.length;return n.jsxs("section",{className:"nt-toasts","aria-label":"Notifications",children:[i.map(l=>n.jsxs("div",{className:"ui-toast nt-toast","data-tone":cz(l.kind),role:"status",children:[l.agentId?n.jsx(Nn,{agents:t,id:l.agentId,size:"sm"}):null,n.jsxs("div",{className:"nt-toast-main",children:[n.jsx("div",{className:"ui-toast-title",children:l.title}),l.text?n.jsx("div",{className:"ui-toast-body nt-toast-line",children:pz(l.text)}):null,l.link?n.jsx("a",{className:"nt-toast-link",href:l.link,onClick:o=>{o.preventDefault(),r(l.id),s(l.link)},children:"See"}):null]}),n.jsx("button",{type:"button",className:"nt-toast-x","aria-label":`Dismiss ${l.title}`,onClick:()=>r(l.id),children:"×"})]},l.id)),a>0?n.jsxs("p",{className:"nt-toasts-more",children:["and ",a," more"]}):null]})}function pz(e){var t;return((t=e.split(`
106
- `).find(s=>s.trim()!==""))==null?void 0:t.trim())??""}const gz=3e4,xz=1e3;function vz(e,t,s){const r=f.useRef(t);r.current=t;const i=f.useRef(s);i.current=s,f.useEffect(()=>{if(!e)return;let a=!1,l=-1/0,o=null,c=null,u=!0;const h=()=>document.visibilityState!=="hidden",d=g=>{var v;l=Date.now(),T.presence(g).catch(w=>{var y;w instanceof pe&&w.status===401&&(a=!0,(y=i.current)==null||y.call(i))}),g==="active"&&((v=r.current)==null||v.call(r))},m=g=>{if(a||(o=g,c!==null))return;const v=l+xz-Date.now();if(v<=0){o=null,d(g);return}c=window.setTimeout(()=>{if(c=null,a||o===null)return;const w=o;o=null,d(w)},v)},p=()=>{u=!0,h()&&m("active")},x=()=>{u=!1,m("away")},j=()=>m(h()?"active":"away");h()&&m("active");const b=window.setInterval(()=>{h()&&u&&m("active")},gz);return window.addEventListener("focus",p),window.addEventListener("blur",x),document.addEventListener("visibilitychange",j),()=>{a=!0,window.clearInterval(b),c!==null&&window.clearTimeout(c),window.removeEventListener("focus",p),window.removeEventListener("blur",x),document.removeEventListener("visibilitychange",j)}},[e])}function $y({agents:e,group:t,onClose:s,onCreated:r,onSaved:i,onArchived:a}){return!t&&!JN(e)?n.jsx(wt,{title:"A new group",onClose:s,children:n.jsxs(H,{children:["A group needs two agents. Make another one with ",TD(e)," first."]})}):n.jsx(wz,{agents:jz(e,t),group:t??null,onClose:s,...r?{onCreated:r}:{},...i?{onSaved:i}:{},...a?{onArchived:a}:{}})}function jz(e,t){const s=QN(e),r=((t==null?void 0:t.members)??[]).filter(i=>!s.some(a=>a.id===i)).map(i=>e.find(a=>a.id===i)).filter(i=>i!==void 0);return[...s,...r]}function wz({agents:e,group:t,onClose:s,onCreated:r,onSaved:i,onArchived:a}){var C,I;const l=t!==null,[o,c]=f.useState((t==null?void 0:t.name)??""),[u,h]=f.useState((t==null?void 0:t.members)??[]),[d,m]=f.useState((t==null?void 0:t.coordinator)??((C=e.find(A=>A.roles.includes(xx)))==null?void 0:C.id)??((I=e[0])==null?void 0:I.id)??""),[p,x]=f.useState(!1),[j,b]=f.useState(!1),[g,v]=f.useState(null),w=[...new Set([d,...u])].filter(Boolean),y=o.trim()!==""&&d!==""&&w.length>=2,N=A=>h(O=>O.includes(A)?O.filter(z=>z!==A):[...O,A]),k=async()=>{x(!0),v(null);try{t?i==null||i(await Le.updateGroup(t.id,{name:o.trim(),coordinator:d,members:w})):r==null||r(await Le.createGroup({name:o.trim(),coordinator:d,members:w.filter(A=>A!==d)}))}catch(A){v(A instanceof pe?A.message:String(A))}finally{x(!1)}},S=async()=>{if(t){x(!0),v(null);try{await Le.archiveGroup(t.id),a==null||a(t.id)}catch(A){v(A instanceof pe?A.message:String(A)),x(!1)}}};return n.jsx(wt,{title:l?`${t.name}: members`:"A new group",onClose:s,children:n.jsxs(J,{children:[n.jsx(ee,{label:"Name",hint:"What this team is for: Household finances, The move, Tax season.",children:n.jsx("input",{value:o,autoFocus:!0,maxLength:80,onChange:A=>c(A.target.value),placeholder:"Household finances"})}),n.jsx(ee,{label:"Coordinator",hint:"Reads your request, brings members in, and answers for the group. Concierge by default.",children:n.jsx("select",{value:d,onChange:A=>m(A.target.value),children:e.map(A=>n.jsx("option",{value:A.id,children:A.name},A.id))})}),n.jsx(ee,{label:"Members",hint:"Each keeps its own account, tools and approvals. Membership grants nothing.",children:n.jsx("div",{className:"group-pick",role:"group","aria-label":"Members",children:e.filter(A=>A.id!==d).map(A=>n.jsxs("label",{className:"group-pick-row","data-on":u.includes(A.id)||void 0,children:[n.jsx("input",{type:"checkbox",checked:u.includes(A.id),onChange:()=>N(A.id)}),n.jsx(Nn,{agents:e,id:A.id,size:"sm"}),n.jsxs("span",{className:"group-pick-text",children:[n.jsx("span",{className:"group-pick-name",children:A.name}),n.jsx("span",{className:"group-pick-desc",children:A.description})]})]},A.id))})}),n.jsx(H,{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."}),l?n.jsx(H,{children:"Taking a member out leaves everything it already said in the transcript. It simply takes no new turns."}):null,g?n.jsx(H,{tone:"critical",children:g}):null,n.jsxs(Q,{align:"end",children:[n.jsx(R,{onClick:s,children:"Cancel"}),n.jsx(R,{variant:"accent",disabled:!y||p,onClick:()=>void k(),children:p?l?"Saving…":"Creating…":l?"Save":"Create group"})]}),l?n.jsx("div",{className:"group-archive",children:j?n.jsxs(J,{children:[n.jsxs(H,{tone:"warning",children:["Archive ",t.name,"? It leaves the rail and takes no new requests. Everything said in it stays readable."]}),n.jsxs(Q,{align:"end",children:[n.jsx(R,{onClick:()=>b(!1),children:"Keep it"}),n.jsx(R,{variant:"danger",disabled:p,"data-testid":"group-archive-confirm",onClick:()=>void S(),children:"Archive group"})]})]}):n.jsx(R,{variant:"ghost",disabled:p,"data-testid":"group-archive",onClick:()=>b(!0),children:"Archive group"})}):null]})})}function Wx(e){const[t,s]=f.useState(null),[r,i]=f.useState(null),[a,l]=f.useState(null);return{busy:t,note:r,failure:a,decide:async(c,u,h,d)=>{var p,x,j,b;s(c),l(null),i(null);let m;try{const g=d?await T.decide(c,u,h,d):await T.decide(c,u,h);m={decision:u,...(p=g.execution)!=null&&p.state?{state:g.execution.state}:{},...g.execution&&"result"in g.execution?{result:g.execution.result}:{}},i(u==="reject"?`Rejected ${g.action.tool}.`:((x=g.execution)==null?void 0:x.state)==="succeeded"?`Approved and done: ${g.action.tool}.`:`Approved ${g.action.tool}: ${((j=g.execution)==null?void 0:j.state)??"no execution"}${(b=g.execution)!=null&&b.message?` (${g.execution.message})`:""}`)}catch(g){l(g instanceof Error?g.message:String(g))}finally{s(null),e(m)}}}}function Hx({action:e,timezone:t,busy:s,onDecide:r,agentName:i}){var h,d;const[a,l]=f.useState(!1),{values:o,controls:c}=Rx(e.choices),u=m=>o?r(e.id,"approve",m,o):r(e.id,"approve",m);return n.jsxs(ks,{tone:"accent",title:e.tool,meta:n.jsxs(n.Fragment,{children:[n.jsxs(ge,{children:["v",e.toolVersion]}),n.jsxs("span",{className:"muted",children:["asked by ",i??e.agentId]})]}),children:[n.jsx(xt,{children:e.preview}),n.jsxs("p",{className:"ui-card-meta",children:["Expires ",Be(e.expiresAt,t)," (",Fe(e.expiresAt),"). Policy v",e.policyVersion,", args ",No(e.argsHash,12),e.jobId?`, job ${No(e.jobId)}`:"","."]}),c,n.jsxs(Q,{children:[n.jsx(R,{variant:"good",disabled:s,onClick:()=>u(),children:(h=e.permissionScopes)!=null&&h.length?"Allow once":"Approve"}),(d=e.permissionScopes)!=null&&d.length?n.jsxs(n.Fragment,{children:[n.jsx(R,{disabled:s,onClick:()=>u("conversation"),children:"Auto: this conversation"}),n.jsx(R,{disabled:s,onClick:()=>u("always"),children:"Always: this agent"})]}):null,n.jsx(R,{variant:"danger",disabled:s,onClick:()=>r(e.id,"reject"),children:"Reject"}),n.jsx(R,{variant:"ghost",onClick:()=>l(m=>!m),"aria-expanded":a,children:a?"Hide envelope":"Show envelope"})]}),a?n.jsxs("div",{className:"ui-card-foot",children:[n.jsx(te,{title:"Envelope: everything that decides what the world will see",children:n.jsx(xt,{children:In(e.envelope)})}),n.jsx(te,{title:"Canonical arguments",children:n.jsx(xt,{children:In(e.canonicalArgs)})})]}):null]})}function Kx(e,t,s){const[r,i]=f.useState(!1),[a,l]=f.useState(null),[o,c]=f.useState(null);return{accept:()=>{e&&(i(!0),c(null),T.acceptPluginAgent(e,t).then(h=>{l(h.agent)}).catch(h=>c(h instanceof pe?h.message:String(h))).finally(()=>i(!1)))},busy:r,created:a,failure:o}}function eC({agent:e}){return n.jsxs(H,{tone:"good",role:"status",children:["@",e.handle," is ready. ",n.jsxs("a",{href:Ve(e.id),children:["Talk to @",e.handle]})]})}function tC(e,t,s){const r=e.canonicalArgs;return e.tool==="platform.accept_plugin_agent"&&(r==null?void 0:r.plugin)===t&&typeof r.agent=="string"&&r.agent.toLowerCase()===s.toLowerCase()}function yz(e,t){var i;const s=le(()=>T.approvals(),[e,t],15e3);return{action:((i=s.data)==null?void 0:i.pending.find(a=>tC(a,e,t)))??null,reload:s.reload}}function bz({action:e,onDecided:t}){const{busy:s,failure:r,decide:i}=Wx(a=>t(a));return n.jsxs(J,{gap:"sm",children:[n.jsx(Hx,{action:e,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,busy:s===e.id,onDecide:(a,l,o,c)=>{i(a,l,o,c)}}),n.jsx(se,{message:r})]})}function Vx({plugin:e,agent:t,text:s,label:r,handle:i,onDismiss:a}){var d;const l=Kx(e,t),o=yz(e,t),[c,u]=f.useState(null),h=l.created??c;if(h)return n.jsx(eC,{agent:h});if(o.action){const m=i??((d=/@(\S+)/.exec(r))==null?void 0:d[1])??t;return n.jsxs(J,{gap:"sm",children:[n.jsx("span",{children:s}),n.jsx(bz,{action:o.action,onDecided:p=>{(p==null?void 0:p.decision)==="approve"&&p.state==="succeeded"?u({id:t,handle:m,name:m}):o.reload()}})]})}return n.jsxs(J,{gap:"sm",children:[n.jsxs(Q,{children:[n.jsx("span",{children:s}),n.jsx(en,{}),a?n.jsx(R,{variant:"ghost",disabled:l.busy,onClick:a,children:"Not now"}):null,n.jsx(R,{variant:"accent",disabled:l.busy,onClick:l.accept,children:r})]}),n.jsx(se,{message:l.failure})]})}function nC(){var t;const e=le(()=>T.agentOffers(),[],6e4);return{offers:((t=e.data)==null?void 0:t.offers)??[],reload:e.reload}}function sC({offers:e,reload:t}){return e.length===0?null:n.jsx(te,{title:"From your plugins",aside:`${e.length} to decide`,panel:!0,children:n.jsx(J,{gap:"sm",divided:!0,children:e.map(s=>n.jsx(Vx,{plugin:s.plugin,agent:s.agent,text:s.text,label:`Create @${s.handle}`,handle:s.handle,onDismiss:()=>{T.dismissAgentOffer(s.plugin,s.agent).then(t,t)}},`${s.plugin}/${s.agent}`))})})}const kz=512*1024,Sz=/^[A-Za-z0-9+/]*={0,2}$/;function rC(e){const t=e==null?void 0:e.play;if(typeof t!="object"||t===null)return null;const{mime:s,data:r}=t;return typeof s!="string"||!/^audio\/[a-z0-9.+-]+$/i.test(s.split(";")[0].trim())||typeof r!="string"||r===""||!Sz.test(r)||Math.floor(r.length*3/4)>kz+2?null:{mime:s,data:r}}function iC(e){const t=e==null?void 0:e.message;return typeof t=="string"&&t.trim()!==""?t:null}let tr=null,ql=null,To=null;const jp=new Set;function aC(){for(const e of jp)e()}function Dl(){tr&&(tr.onended=null,tr.onerror=null,tr.pause()),ql&&URL.revokeObjectURL(ql),ql=null,To!==null&&(To=null,aC())}async function lC(e,t){Dl();const s=atob(e.data),r=new Uint8Array(s.length);for(let i=0;i<s.length;i+=1)r[i]=s.charCodeAt(i);tr??(tr=new Audio),ql=URL.createObjectURL(new Blob([r],{type:e.mime})),To=t,tr.onended=Dl,tr.onerror=Dl,tr.src=ql,aC();try{await tr.play()}catch{throw Dl(),new Error("The browser would not play the sound.")}}function My(e){e!==void 0&&To!==e||Dl()}function Nz(){return f.useSyncExternalStore(e=>(jp.add(e),()=>jp.delete(e)),()=>To,()=>null)}const Cz=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],la=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Ez=["January","February","March","April","May","June","July","August","September","October","November","December"],Oy=/^\d{4}-\d{2}-\d{2}$/;function Yr(e){return e.split("-").map(Number)}function qi(e,t){const[s,r,i]=Yr(e);return new Date(Date.UTC(s,r-1,i+t)).toISOString().slice(0,10)}function oC(e){const[t,s,r]=Yr(e);return new Date(Date.UTC(t,s-1,r)).getUTCDay()}function Gx(e){return Cz[oC(e)]}function cC(e){return Yr(e)[2]}function Dy(e){return qi(e,-((oC(e)+6)%7))}function lr(e){const[,t,s]=Yr(e);return`${Gx(e)} ${s} ${la[t-1]}`}function Az(e,t){return e===t?`Today · ${lr(e)}`:e===qi(t,1)?`Tomorrow · ${lr(e)}`:lr(e)}function wi(e){return`${String(Math.floor(e/60)).padStart(2,"0")}:${String(e%60).padStart(2,"0")}`}const _y=new Map;function wp(e,t){let s=_y.get(t);s||(s=new Intl.DateTimeFormat("en-GB",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}),_y.set(t,s));const r=Object.fromEntries(s.formatToParts(e).map(i=>[i.type,i.value]));return{date:`${r.year}-${r.month}-${r.day}`,minutes:Number(r.hour)*60+Number(r.minute)}}function Tz(e,t=new Date){return wp(t,e).date}function Rz(e,t){return e==="week"?{from:Dy(t),days:7}:e==="month"?{from:Dy(`${t.slice(0,8)}01`),days:42}:{from:t,days:7}}function Iz(e,t,s){if(e!=="month")return qi(t,s*7);const[r,i]=Yr(t);return new Date(Date.UTC(r,i-1+s,1)).toISOString().slice(0,10)}function Pz(e,t,s,r){const[i,a]=Yr(t);if(e==="month")return`${Ez[a-1]} ${i}`;const l=qi(s,r-1),[o,c,u]=Yr(s),[h,d,m]=Yr(l);return c===d&&o===h?`${u} – ${m} ${la[d-1]} ${h}`:o===h?`${u} ${la[c-1]} – ${m} ${la[d-1]} ${h}`:`${u} ${la[c-1]} ${o} – ${m} ${la[d-1]} ${h}`}function ia(e){return e==null?"":String(e)}function $z(e,t,s,r){const i=[],a=new Set;return e.forEach((l,o)=>{const c=ia(xe(l,t.id)),u=ia(xe(l,t.title)),h=ia(xe(l,t.start)),d=ia(xe(l,t.end));if(c===""||a.has(c)||h===""){console.warn(`buddi: ${r}: event ${o} has no id, a repeated one, or no start — not drawn`);return}a.add(c);const m=t.allDay===void 0?void 0:xe(l,t.allDay),p=m===void 0?Oy.test(h):m===!0||m==="true",x=t.tone===void 0?0:Number(xe(l,t.tone)),j=Number.isFinite(x)?(Math.trunc(x)%4+4)%4:0,b={id:c,title:u,calendar:t.calendar===void 0?"":ia(xe(l,t.calendar)),tone:j,location:t.location===void 0?"":ia(xe(l,t.location))};if(p){const N=h.slice(0,10),k=Oy.test(d.slice(0,10))&&d.slice(0,10)>N?d.slice(0,10):qi(N,1);i.push({...b,allDay:!0,startDate:N,startMin:0,endDate:k,endMin:0});return}const g=new Date(h);if(Number.isNaN(g.getTime())){console.warn(`buddi: ${r}: event ${o} starts at "${h}", which is not a time — not drawn`);return}const v=new Date(d),w=wp(g,s),y=Number.isNaN(v.getTime())||v<g?w:wp(v,s);i.push({...b,allDay:!1,startDate:w.date,startMin:w.minutes,endDate:y.date,endMin:y.minutes})}),i}function Mz(e,t){if(e.allDay)return t>=e.startDate&&t<e.endDate?{from:0,to:1440,allDay:!0}:null;if(t<e.startDate||t>e.endDate)return null;const s=t===e.startDate?e.startMin:0,r=t===e.endDate?e.endMin:1440,i=e.startDate===e.endDate&&e.startMin===e.endMin;return r<=s&&!(i&&t===e.startDate)?null:{from:s,to:r,allDay:s===0&&r===1440}}function Yx(e,t){return e.map(s=>({event:s,part:Mz(s,t)})).filter(s=>s.part!==null).sort((s,r)=>Number(r.part.allDay)-Number(s.part.allDay)||s.part.from-r.part.from||r.part.to-s.part.to)}function qx(e,t){if(t.allDay)return"All day";const s=e.startDate!==e.endDate;return s&&t.from===0?`until ${wi(t.to)}`:s&&t.to===1440?`from ${wi(t.from)}`:t.from===t.to?wi(t.from):`${wi(t.from)}–${wi(t.to)}`}function yp(e,t,s){return[qx(e,t),e.title,e.location,e.calendar,lr(s)].filter(Boolean).join(", ")}const uC=30;function Oz(e){const t=[];let s=[],r=-1;const i=[],a=()=>{const l=Math.max(1,...s.map(o=>o.lane+1));for(const o of s)t.push({...o,lanes:l});s=[],i.length=0};for(const l of e){const o=Math.max(l.part.to,l.part.from+uC);s.length>0&&l.part.from>=r&&a();let c=i.findIndex(u=>u<=l.part.from);c===-1?(c=i.length,i.push(o)):i[c]=o,s.push({...l,lane:c,lanes:1}),r=Math.max(r,o)}return s.length>0&&a(),t}const Qx="(max-width: 900px)";function Li(e){const[t,s]=f.useState(()=>{try{return window.matchMedia(e).matches}catch{return!1}});return f.useEffect(()=>{var a;let r;try{r=window.matchMedia(e)}catch{return}const i=l=>s(l.matches);return(a=r.addEventListener)==null||a.call(r,"change",i),()=>{var l;return(l=r.removeEventListener)==null?void 0:l.call(r,"change",i)}},[e]),t}const Dz={week:"Week",month:"Month",list:"List"},_z=["week","month","list"],Lz="(max-width: 720px)";function Fz(e){try{return window.localStorage.getItem(e)}catch{return null}}function zz(e,t){try{window.localStorage.setItem(e,t)}catch{}}function Uz(e){const t=e.views&&e.views.length>0?e.views:_z,s=Li(Lz),[r,i]=f.useState(()=>{const p=Fz(e.storageKey);return p!==null&&t.includes(p)?p:null}),a=s&&t.includes("list")?"list":e.default&&t.includes(e.default)?e.default:t[0],l=r??a,[o,c]=f.useState(e.today),[u,h]=f.useState(null),{from:d,days:m}=Rz(l,o);return{views:t,view:l,setView:p=>{i(p),zz(e.storageKey,p),h(null)},anchor:o,today:e.today,go:p=>{c(p===0?e.today:Iz(l,o,p)),h(null)},from:d,days:m,to:qi(d,m),selected:u,select:h}}function Bz({state:e,events:t,hours:s,empty:r,label:i}){const{view:a,anchor:l,today:o,from:c,days:u}=e,h=f.useMemo(()=>Array.from({length:u},(j,b)=>qi(c,b)),[c,u]),d=a==="month"?"month":"week",m=e.selected??(l.slice(0,7)===o.slice(0,7)?o:`${l.slice(0,8)}01`),p=a==="month"?m:a==="week"?e.selected:null,x=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 n.jsxs("div",{className:"cal",role:"region","aria-label":i,tabIndex:0,onKeyDown:x,children:[n.jsxs("div",{className:"cal-bar",children:[n.jsx(R,{size:"sm","aria-label":`Previous ${d}`,onClick:()=>e.go(-1),children:n.jsx(we,{name:"chevron-left",size:14})}),n.jsx(R,{size:"sm",onClick:()=>e.go(0),children:"Today"}),n.jsx(R,{size:"sm","aria-label":`Next ${d}`,onClick:()=>e.go(1),children:n.jsx(we,{name:"chevron-right",size:14})}),n.jsx("h3",{className:"cal-title","aria-live":"polite",children:Pz(a,l,c,u)}),e.views.length>1?n.jsx(ls,{label:"View",options:e.views.map(j=>({value:j,label:Dz[j]})),value:a,onChange:e.setView}):null]}),a==="week"?n.jsx(Wz,{dates:h,today:o,events:t,hours:s??[7,21],onPick:e.select}):null,a==="month"?n.jsx(Kz,{dates:h,month:l.slice(0,7),today:o,events:t,selected:m,onPick:e.select}):null,a==="list"?n.jsx("div",{className:"cal-list",children:h.map(j=>n.jsx(Ly,{date:j,today:o,events:t,empty:r},j))}):null,p?n.jsx(Ly,{date:p,today:o,events:t,empty:r}):null]})}function Ly({date:e,today:t,events:s,empty:r}){const i=Yx(s,e);return n.jsx(qe,{flush:!0,title:Az(e,t),children:n.jsx(At,{children:i.length===0?n.jsx(Tt,{title:n.jsx("span",{className:"muted",children:r})}):i.map(({event:a,part:l})=>n.jsx(Tt,{lead:n.jsx("span",{className:"cal-dot","data-tone":a.tone,"aria-hidden":"true"}),title:a.title,sub:a.location||void 0,side:qx(a,l)},a.id))})})}function Wz({dates:e,today:t,events:s,hours:r,onPick:i}){const a=f.useRef(null);f.useLayoutEffect(()=>{const c=a.current;c&&(c.scrollTop=c.scrollHeight/24*r[0])},[r[0]]);const l=e.map(c=>({date:c,items:Yx(s,c)})),o=c=>c===t?"true":void 0;return n.jsx(qe,{flush:!0,children:n.jsxs("div",{className:"cal-week",role:"grid","aria-label":`Week of ${lr(e[0])}`,style:{"--cal-span":r[1]-r[0]},children:[n.jsxs("div",{className:"cal-row",role:"row",children:[n.jsx("span",{className:"cal-gutter","aria-hidden":"true"}),e.map(c=>n.jsxs("div",{className:"cal-day-head",role:"columnheader","data-today":o(c),"aria-label":lr(c),children:[n.jsx("span",{className:"cal-wd",children:Gx(c)}),n.jsx("span",{className:"cal-num",children:cC(c)})]},c))]}),n.jsxs("div",{className:"cal-row cal-allday",role:"row",children:[n.jsx("span",{className:"cal-gutter cal-gutter-label",children:"All day"}),l.map(({date:c,items:u})=>n.jsx("div",{className:"cal-allday-cell",role:"gridcell","data-today":o(c),children:u.filter(h=>h.part.allDay).map(({event:h,part:d})=>n.jsx("button",{type:"button",className:"cal-chip","data-tone":h.tone,"aria-label":yp(h,d,c),onClick:()=>i(c),children:h.title},h.id))},c))]}),n.jsx("div",{className:"cal-scroll",ref:a,children:n.jsxs("div",{className:"cal-row cal-times",role:"row",children:[n.jsx("div",{className:"cal-gutter cal-hours","aria-hidden":"true",children:Array.from({length:23},(c,u)=>u+1).map(c=>n.jsx("span",{className:"cal-hour-label",style:{top:`calc(var(--cal-hour) * ${c})`},children:wi(c*60)},c))}),l.map(({date:c,items:u})=>n.jsx("div",{className:"cal-col",role:"gridcell","aria-label":lr(c),"data-today":o(c),children:Oz(u.filter(h=>!h.part.allDay)).map(({event:h,part:d,lane:m,lanes:p})=>n.jsxs("button",{type:"button",className:"cal-event","data-tone":h.tone,"data-short":d.to-d.from<60?"true":void 0,"data-lane":m,"aria-label":yp(h,d,c),onClick:()=>i(c),style:{top:`calc(var(--cal-hour) * ${d.from/60})`,height:`calc(var(--cal-hour) * ${Math.max(d.to-d.from,uC)/60})`,left:`calc((100% - var(--space-1)) * ${m/p} + var(--space-0))`,width:`calc((100% - var(--space-1)) / ${p} - var(--space-0))`},children:[n.jsx("span",{className:"cal-event-time",children:qx(h,d)}),n.jsx("span",{className:"cal-event-title",children:h.title})]},h.id))},c))]})})]})})}const Hz=3;function Kz({dates:e,month:t,today:s,events:r,selected:i,onPick:a}){const l=Array.from({length:6},(h,d)=>e.slice(d*7,d*7+7)),[o,c]=t.split("-").map(Number),u=new Intl.DateTimeFormat("en-GB",{month:"long",year:"numeric",timeZone:"UTC"}).format(new Date(Date.UTC(o,c-1,1)));return n.jsx(qe,{flush:!0,children:n.jsxs("div",{className:"cal-month",role:"grid","aria-label":u,children:[n.jsx("div",{className:"cal-row",role:"row",children:e.slice(0,7).map(h=>n.jsx("div",{className:"cal-wd-head",role:"columnheader",children:Gx(h)},h))}),l.map(h=>n.jsx("div",{className:"cal-row",role:"row",children:h.map(d=>{const m=Yx(r,d),p=m.slice(0,Hz),x=m.length-p.length,j=m.length===0?"nothing":m.length===1?"1 event":`${m.length} events`;return n.jsxs("div",{className:"cal-cell",role:"gridcell","aria-selected":d===i,"data-date":d,"data-today":d===s?"true":void 0,"data-outside":d.slice(0,7)!==t?"true":void 0,"data-selected":d===i?"true":void 0,onClick:()=>a(d),children:[n.jsx("button",{type:"button",className:"cal-num","aria-label":`${lr(d)}, ${j}`,"aria-pressed":d===i,children:cC(d)}),p.map(({event:b,part:g})=>n.jsx("button",{type:"button",className:"cal-chip","data-tone":b.tone,"data-timed":g.allDay?void 0:"true","aria-label":yp(b,g,d),children:g.allDay?b.title:n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"cal-dot","data-tone":b.tone,"aria-hidden":"true"}),n.jsx("span",{className:"cal-chip-time",children:wi(g.from)})," ",b.title]})},b.id)),x>0?n.jsxs("button",{type:"button",className:"cal-more","aria-label":`${x} more on ${lr(d)}`,children:["+",x]}):null]},d)})},h[0]))]})})}const dC={width:1200,height:200,top:28,right:12,bottom:24,left:36};function Vz(e,t){if(t==="percent")return[0,50,100];let s=e.length>0?Math.min(...e):0,r=e.length>0?Math.max(...e):1;t!=="temp"&&(s=Math.min(0,s)),s===r&&(s-=1,r+=1);const i=10**Math.floor(Math.log10(Math.max(1,(r-s)/3))),a=c=>Math.ceil(r/c)-Math.floor(s/c);let l=[1,2,5,10].map(c=>c*i).find(c=>a(c)<=3)??i*10;a(l)<2&&(l>1?l/=2:r+=l);const o=[];for(let c=Math.floor(s/l)*l;c<=Math.ceil(r/l)*l+l/1e3;c+=l)o.push(Math.round(c*1e6)/1e6);return o}function Bc(e,t){return t==="temp"?`${e}°`:t==="percent"?`${e}%`:String(e)}function Gz(e){const t=dC,s=e.values.length,r=t.width-t.left-t.right,i=t.height-t.top-t.bottom,a=t.height-t.bottom,l=s>0?r/s:r,o=g=>yi(t.left+l*(g+.5)),c=e.values.filter(g=>g!==null&&Number.isFinite(g)),u=Vz(c,e.unit),h=u[0],d=u[u.length-1],m=g=>yi(t.top+i-(g-h)/(d-h)*i),p=e.values.map((g,v)=>{const w=g!==null&&Number.isFinite(g);return{index:v,x:o(v),y:w?m(g):null,value:w?g:null}}),x=[],j=[];if(e.kind==="area"){let g=[];const v=()=>{if(g.length===0)return;const w=g.map((y,N)=>`${N===0?"M":"L"}${y.x},${y.y}`).join(" ");x.push(w),j.push(`${w} L${g[g.length-1].x},${a} L${g[0].x},${a} Z`),g=[]};for(const w of p)w.y===null?v():g.push(w);v()}const b=e.kind==="bars"?p.flatMap(g=>g.y===null?[]:[{index:g.index,x:yi(g.x-l*.28),y:g.y,width:yi(l*.56),height:yi(a-g.y)}]):[];return{ticks:u.map(g=>({value:g,y:m(g)})),lines:x,areas:j,bars:b,points:p,slot:l,floor:a}}function Yz({title:e,note:t,xs:s,series:r,tiles:i,labelEvery:a=3}){var N;const[l,o]=f.useState(((N=r[0])==null?void 0:N.id)??""),[c,u]=f.useState(null),[h,d]=f.useState(null),m=f.useRef(null),p=s.length,x=c??h,j=r.find(k=>k.id===l)??r[0],b=Gz(j),g=dC,v=k=>k%a===0||k===x,w=j.values.filter(k=>k!==null&&Number.isFinite(k));f.useEffect(()=>{const k=m.current,S=x===null?null:k==null?void 0:k.children[x];!k||!S||typeof k.scrollTo!="function"||(S.offsetLeft<k.scrollLeft?k.scrollTo({left:S.offsetLeft,behavior:"smooth"}):S.offsetLeft+S.offsetWidth>k.scrollLeft+k.clientWidth&&k.scrollTo({left:S.offsetLeft+S.offsetWidth-k.clientWidth,behavior:"smooth"}))},[x]);const y=k=>{var I,A,O;const S=k.key==="ArrowRight"?1:k.key==="ArrowLeft"?-1:0,C=k.key==="Home"?0:k.key==="End"?p-1:S===0?null:Math.max(0,Math.min(p-1,(h??-S)+S));C!==null&&(k.preventDefault(),d(C),(O=(A=(I=m.current)==null?void 0:I.children[C])==null?void 0:A.querySelector("button"))==null||O.focus())};return n.jsxs(qe,{...e?{title:e}:{},children:[t?n.jsx("p",{className:"ui-panel-sub",children:t}):null,n.jsxs("div",{className:"pg-series",onMouseLeave:()=>u(null),children:[r.length>1?n.jsx("div",{className:"pg-series-tabs",role:"tablist","aria-label":"Series",children:r.map(k=>n.jsx("button",{type:"button",role:"tab",className:"ui-tab","aria-selected":k.id===j.id,onClick:()=>o(k.id),children:k.label},k.id))}):null,n.jsxs("figure",{className:"pg-series-chart","data-kind":j.kind,children:[n.jsxs("svg",{viewBox:`0 0 ${g.width} ${g.height}`,"aria-hidden":"true",focusable:"false","data-testid":"series-svg",children:[b.ticks.map(k=>n.jsxs("g",{children:[n.jsx("line",{className:"pg-series-grid",x1:g.left,x2:g.width-g.right,y1:k.y,y2:k.y}),n.jsx("text",{className:"pg-series-tick",x:g.left-8,y:k.y,textAnchor:"end",dominantBaseline:"middle",children:Bc(k.value,j.unit)})]},k.value)),b.areas.map((k,S)=>n.jsx("path",{className:"pg-series-area",d:k},`a${S}`)),b.lines.map((k,S)=>n.jsx("path",{className:"pg-series-line",d:k},`l${S}`)),b.bars.map(k=>n.jsx("rect",{className:"pg-series-bar","data-index":k.index,"data-hover":k.index===x?"true":void 0,x:k.x,y:k.y,width:k.width,height:k.height},k.index)),x!==null&&b.points[x]?n.jsx("line",{className:"pg-series-guide","data-index":x,x1:b.points[x].x,x2:b.points[x].x,y1:g.top-4,y2:b.floor}):null,j.kind==="area"?b.points.map(k=>k.y!==null&&v(k.index)?n.jsx("circle",{className:"pg-series-dot","data-index":k.index,"data-hover":k.index===x?"true":void 0,cx:k.x,cy:k.y,r:k.index===x?5:3},k.index):null):null,b.points.map(k=>k.y!==null&&k.value!==null&&v(k.index)?n.jsx("text",{className:"pg-series-value","data-index":k.index,"data-hover":k.index===x?"true":void 0,x:k.x,y:k.y-(j.kind==="area"?10:6),textAnchor:"middle",children:Bc(k.value,j.unit)},k.index):null),b.points.map(k=>k.index%a===0?n.jsx("text",{className:"pg-series-x",x:k.x,y:g.height-6,textAnchor:"middle",children:s[k.index]},k.index):null),b.points.map(k=>n.jsx("rect",{className:"pg-series-hit","data-index":k.index,x:yi(g.left+b.slot*k.index),y:0,width:yi(b.slot),height:g.height,onMouseEnter:()=>u(k.index),onClick:()=>d(k.index)},k.index))]}),n.jsx("figcaption",{className:"sr-only",children:w.length===0?`${j.label}: no values.`:`${j.label}, ${p} ${p===1?"point":"points"} from ${s[0]} to ${s[p-1]}: lowest ${Bc(Math.min(...w),j.unit)}, highest ${Bc(Math.max(...w),j.unit)}.`})]}),n.jsx("ul",{className:"wb-tiles","data-layout":"strip",ref:m,onKeyDown:y,children:i.map((k,S)=>n.jsx("li",{className:"wb-tile",children:n.jsx("button",{type:"button",className:"ui-card","data-index":S,"data-hover":S===x?"true":void 0,"aria-pressed":S===h,"aria-label":[k.label,k.value,...k.lines].filter(C=>C!=="").join(", "),onMouseEnter:()=>u(S),onClick:()=>d(S),children:n.jsxs("div",{className:"wb-tile-body","aria-hidden":"true",children:[n.jsx("span",{className:"wb-tile-icon","data-icon":k.icon??"dot",children:n.jsx(we,{name:th(k.icon),size:22})}),k.value!==""?n.jsx("span",{className:"wb-tile-value tnum",children:k.value}):null,n.jsx("span",{className:"wb-tile-label",children:k.label}),k.lines.map((C,I)=>n.jsx("span",{className:"wb-tile-line",children:C},I))]})})},S))})]})]})}function yi(e){return Math.round(e*10)/10}const Jx=f.createContext(null),ad=f.createContext(!1);function Nt(){const e=f.useContext(Jx);if(!e)throw new Error("a plugin page component outside a plugin page");return e}function bp(e,t=new Set){if(Array.isArray(e))for(const s of e)bp(s,t);else if(e&&typeof e=="object"){const s=e.query;typeof s=="string"&&t.add(s);for(const r of Object.values(e))bp(r,t)}return t}function hC(e,t){if(t.size===0)return!1;for(const s of bp(e))if(t.has(s))return!0;return!1}function fC(){const[e,t]=f.useState(!1);return f.useEffect(()=>{if(!e)return;const s=()=>{document.visibilityState==="hidden"&&t(!1)};return document.addEventListener("visibilitychange",s),window.addEventListener("blur",s),()=>{document.removeEventListener("visibilitychange",s),window.removeEventListener("blur",s)}},[e]),[e,()=>t(s=>!s)]}function mC({revealed:e,onToggle:t}){return n.jsx(R,{size:"sm",variant:"ghost","aria-pressed":e,onClick:t,children:e?"Hide":"Show"})}function pC(){return n.jsx("p",{className:"muted",children:"Hidden until you show it."})}function gC({children:e}){const[t,s]=fC();return n.jsxs(J,{gap:"sm",children:[n.jsx(Q,{align:"end",children:n.jsx(mC,{revealed:t,onToggle:s})}),t?n.jsx(ad.Provider,{value:!0,children:e}):n.jsx(pC,{})]})}function Xx(e){return e===void 0||e==="neutral"?void 0:e}function kp(e){return Xx(e)}function qz(e){const t=Xx(e);return t==="accent"?void 0:t}function ws(e,t){if(!t)return!0;const s=xe(e,t.path),r=t.in!==void 0?t.in.includes(s):s===t.equals;return t.not===!0?!r:r}function Zx(e,t,s){if("chat"in t){const a=Oe(s,t.chat);return a==null?"":Ve(String(a))}if("proposals"in t)return VO(e.plugin);const r=e.pages.find(a=>a.id===t.page);if((r==null?void 0:r.place)==="settings")return al(e.plugin,t.page);const i=t.item===void 0?null:Oe(s,t.item);return ti(e.plugin,t.page,i==null?null:String(i))}function Qz(e,t){return e.replace(/\{count\}/g,String(t.count??0)).replace(/\{([^{}|]+)\|([^{}|]+)\}/g,(s,r,i)=>(t.count??0)===1?r:i).replace(/\{([A-Za-z_][A-Za-z0-9_.]*)\}/g,(s,r)=>{const i=xe(t.row,r);return i==null?"":String(i)})}function Sp(e,t){if(e===void 0)return;if(typeof e=="string")return e;const s=Oe(t,e);return s==="good"||s==="warning"||s==="critical"||s==="neutral"?s:void 0}function xC(e,t,s){const r={};for(const[i,a]of Object.entries(e??{})){let l;"param"in a?l=s.params[a.param]:"route"in a?l=a.route==="plugin"?s.plugin:a.route==="page"?s.page:s.item:l=Oe(t,a),!(l==null||l==="")&&(r[i]=String(l))}return r}function Fi(e,t){var r,i,a;const s={};for(const[l,o]of Object.entries(e??{}))if("row"in o)s[l]=xe(t.row,o.row);else if("field"in o){if((r=t.omit)!=null&&r.has(o.field))continue;const c=(i=t.fields)==null?void 0:i[o.field],u=(a=t.shape)==null?void 0:a.find(h=>h.name===o.field);if(c===""&&(u==null?void 0:u.required)!==!0&&(u===void 0||u.type==="number"))continue;s[l]=c}else"selected"in o?s[l]=t.selected??[]:"param"in o?s[l]=t.scope.params[o.param]:s[l]=Oe(t.data,o);return s}function bn(e,t,s,r){const i=Nt(),a=e?{...xC(e.params,t,i),...r}:{},l=JSON.stringify([(e==null?void 0:e.query)??null,a,i.version]),o=le(()=>e?T.pageQuery(i.plugin,e.query,a).then(c=>c.data):Promise.resolve(void 0),[l],s);return{data:o.data,error:o.error,loading:o.loading}}function Yo(){const e=Nt(),t=f.useId(),[s,r]=f.useState(null),[i,a]=f.useState(null),[l,o]=f.useState(null),[c,u]=f.useState(null),[h,d]=f.useState(null),m=(b,g)=>{if(b.done===void 0)return null;if(typeof b.done=="string")return b.done;const v=Oe(g,b.done);return v==null?null:String(v)},p=(b,g,v)=>{const w=b??"refresh";if(typeof w=="object"){const y=Zx(e,w.route,g);y===""?e.refresh():e.navigate(y);return}w==="close"&&(v==null||v()),e.refresh()},x=async(b,g,v)=>{r(b.tool),a(null),o(null);try{const w=await T.pageAct(e.plugin,{tool:b.tool,args:g});if(w.approvalId){u(w.approvalId),d({then:b.then,ref:b,...v?{onDone:v}:{}});return}u(null),d(null);const y=rC(w.result);o(m(b,w.result)??(y?iC(w.result):null)),y&&await lC(y,t),p(b.then,w.result,v)}catch(w){a(w instanceof Error?w.message:String(w)),e.refresh()}finally{r(null)}},j=b=>{if(!b){e.refresh();return}const g=h;if(u(null),d(null),g&&b.decision==="approve"&&b.state==="succeeded"){o(m(g.ref,b.result)),p(g.then,void 0,g.onDone);return}e.refresh()};return{running:s,busy:s!==null,error:i,done:l,approvalId:c,waiting:(h==null?void 0:h.ref.pending)??null,settle:j,run:x}}function Va({action:e,args:t,disabled:s,running:r,count:i,row:a,onRun:l}){const[o,c]=f.useState(!1),u=d=>Qz(d,{...i===void 0?{}:{count:i},row:a}),h=u(e.label);return o&&e.confirm?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"ui-toolbar-note",children:u(e.confirm)}),n.jsx(R,{variant:"ghost",onClick:()=>c(!1),children:"Cancel"}),n.jsxs(R,{variant:e.tone==="danger"?"danger":"accent",disabled:s,onClick:()=>{c(!1),l(e,t)},children:["Yes, ",h.toLowerCase()]})]}):n.jsx(R,{variant:e.tone==="danger"?"danger":e.tone==="accent"?"accent":void 0,disabled:s,onClick:()=>e.confirm?c(!0):l(e,t),children:r&&e.busy?e.busy:h})}function ld({id:e,onDecided:t}){const s=Nt(),r=le(()=>T.approval(e),[e,s.version]),{busy:i,note:a,failure:l,decide:o}=Wx(c=>{t?t(c):s.refresh()});return r.error?n.jsx(se,{message:r.error}):r.data?n.jsxs(J,{children:[n.jsx(Hx,{action:r.data,timezone:s.timezone,busy:i===e,onDecide:(c,u,h,d)=>{o(c,u,h,d)}}),a?n.jsx(H,{tone:"good",role:"status",children:a}):null,n.jsx(se,{message:l})]}):n.jsx(oe,{children:"Loading the approval…"})}function cl({act:e}){return e.error?n.jsx(se,{message:e.error}):e.approvalId?e.waiting?n.jsxs(J,{children:[n.jsx(H,{role:"status",children:e.waiting}),n.jsx(ld,{id:e.approvalId,onDecided:e.settle})]}):n.jsx(ld,{id:e.approvalId,onDecided:e.settle}):e.done?n.jsx(H,{tone:"good",role:"status",children:e.done}):null}function od(e,t){const s={};for(const r of e){const i=r.from===void 0?void 0:xe(t,r.from);s[r.name]=r.multiple?Array.isArray(i)?i.map(String):[]:i!==void 0?i:r.type==="checkbox"?!1:""}return s}function vC(e,t,s){const r=Nt(),i=e.optionsFrom,a=i?{...xC(i.query.params,s,r),...Object.fromEntries((i.dependsOn??[]).map(c=>[c,String(t[c]??"")]).filter(([,c])=>c!==""))}:{},l=JSON.stringify([(i==null?void 0:i.query.query)??null,a,r.version]),o=le(()=>i?T.pageQuery(r.plugin,i.query.query,a).then(c=>c.data):Promise.resolve(void 0),[l]);return i?{options:Gs(o.data,i.rows).map(c=>({value:String(xe(c,i.value)??""),label:String(xe(c,i.label)??"")})),loading:o.loading}:{options:e.options??[],loading:!1}}function Jz({field:e,fields:t,value:s,values:r,data:i,disabled:a,compact:l,onChange:o}){const c=vC(e,r,i),u={id:`f-${e.name}`,required:e.required,name:e.name,disabled:a,...l&&e.hint?{title:e.hint}:{}},h=l?void 0:e.hint;if(e.type==="select"&&e.multiple){const m=Array.isArray(s)?s.map(String):[],x=e.max!==void 0&&m.length>=e.max?`Up to ${e.max}; remove one to add another.`:void 0;return n.jsx(ee,{label:e.label,hint:l?void 0:[h,x].filter(Boolean).join(" ")||void 0,group:!0,children:n.jsx(W_,{id:u.id,label:e.label,options:c.options,value:m,max:e.max,disabled:a,onChange:o})})}if(e.type==="select"){const m=n.jsxs("select",{...u,value:String(s??""),onChange:p=>o(p.target.value),children:[n.jsx("option",{value:"",children:c.loading?"Loading…":"—"}),c.options.map(p=>n.jsx("option",{value:p.value,children:p.label},p.value))]});return e.action&&!l?n.jsx(Xz,{field:e,action:e.action,fields:t??[e],values:r,data:i,disabled:a,hint:h,children:m}):n.jsx(ee,{label:e.label,hint:h,children:m})}if(e.type==="textarea")return n.jsx(ee,{label:e.label,hint:h,wide:!0,children:n.jsx("textarea",{...u,value:String(s??""),onChange:m=>o(m.target.value),rows:6})});if(e.type==="checkbox")return n.jsx(ee,{label:e.label,hint:h,inline:!0,wide:!l,children:n.jsx("input",{...u,type:"checkbox",checked:s===!0,onChange:m=>o(m.target.checked)})});const d=e.type==="secret"?"password":e.type==="number"?"number":e.type;return n.jsx(ee,{label:e.label,hint:h,children:n.jsx("input",{...u,type:d,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"?Zz(m.target.value):m.target.value)})})}function Xz({field:e,action:t,fields:s,values:r,data:i,disabled:a,hint:l,children:o}){const c=Nt(),u=f.useId(),h=Nz()===u,[d,m]=f.useState(!1),[p,x]=f.useState(null),[j,b]=f.useState(null),[g,v]=f.useState(null);f.useEffect(()=>()=>My(u),[u]);const w=ev(s,r,i),y=t.args!==void 0?Fi(t.args,{data:i,fields:r,shape:s,omit:w,scope:c}):Object.fromEntries(Object.entries(r).filter(([S,C])=>!w.has(S)&&C!=="")),N=async()=>{if(h){My(u);return}m(!0),x(null),b(null),v(null);try{const S=await T.pageAct(c.plugin,{tool:t.tool,args:y});if(S.approvalId){v(S.approvalId);return}x(iC(S.result));const C=rC(S.result);C&&await lC(C,u)}catch(S){b(S instanceof Error?S.message:String(S))}finally{m(!1)}},k=h?"Stop":t.label;return n.jsx(ee,{label:e.label,hint:l,action:n.jsx(R,{"data-shape":"icon","aria-label":d?`${t.label}: working`:k,title:k,"aria-busy":d||void 0,"aria-pressed":t.icon==="play"?h:void 0,disabled:a===!0||d,onClick:()=>void N(),children:d?n.jsx("span",{className:"ui-spinner","aria-hidden":"true"}):n.jsx(we,{name:h?"stop":t.icon??"arrow"})}),after:j?n.jsx(se,{message:j}):g?n.jsx(ld,{id:g,onDecided:()=>v(null)}):p?n.jsx("span",{className:"ui-field-hint",role:"status",children:p}):null,children:o})}function Zz(e){if(e.trim()==="")return"";const t=Number(e);return Number.isFinite(t)?t:e}function jC(e,t){return{...typeof t=="object"&&t!==null?t:{},...e}}function ev(e,t,s){const r=jC(t,s);return new Set(e.filter(i=>i.when!==void 0&&!ws(r,i.when)||i.disabledWhen!==void 0&&ws(r,i.disabledWhen)).map(i=>i.name))}function tv({fields:e,values:t,data:s,disabled:r,compact:i,columns:a,onChange:l}){const o=jC(t,s);return n.jsx(bs,{dense:i,columns:a,children:e.filter(c=>c.when===void 0||ws(o,c.when)).map(c=>n.jsx(Jz,{field:c,fields:e,compact:i,value:t[c.name],values:t,data:s,disabled:r===!0||c.disabledWhen!==void 0&&ws(o,c.disabledWhen),onChange:u=>l(c.name,u)},c.name))})}const Ro=f.createContext(!1),wC=f.createContext(!1),yC=f.createContext(!1);function qn({title:e,note:t,actions:s,children:r}){const i=f.useContext(Ro);return n.jsx(te,{title:e,aside:t,actions:s,panel:i,children:n.jsx(Ro.Provider,{value:!1,children:n.jsx(wC.Provider,{value:i,children:r})})})}function Vs({component:e,data:t,choose:s,chosen:r}){const i=Nt(),a=f.useContext(ad);if(!ws(t,e.when))return null;if(e.kind!=="section"&&!a&&hC(e,i.sensitive))return n.jsx(gC,{children:n.jsx(Vs,{component:e,data:t,...s?{choose:s}:{},...r===void 0?{}:{chosen:r}})});switch(e.kind){case"section":return n.jsx(eU,{component:e,data:t});case"notice":return n.jsx(H,{tone:Xx(e.tone),title:e.title,children:typeof e.text=="string"?e.text:String(Oe(t,e.text)??"")});case"link":return n.jsx(tU,{component:e,data:t});case"progress":return n.jsx(sU,{component:e,data:t});case"chart":return n.jsx(rU,{component:e,data:t});case"stats":return n.jsx(iU,{component:e,data:t});case"list":return n.jsx(lU,{component:e,data:t,...s?{onChoose:s}:{},...r===void 0?{}:{chosen:r}});case"table":return n.jsx(oU,{component:e,data:t});case"detail":return n.jsx(dU,{component:e,data:t});case"form":return n.jsx(hU,{component:e,data:t});case"search":return n.jsx(pU,{component:e,data:t});case"list-detail":return n.jsx(gU,{component:e,data:t});case"repeat":return n.jsx(xU,{component:e,data:t});case"calendar":return n.jsx(vU,{component:e,data:t});case"tiles":return n.jsx(jU,{component:e,data:t});case"series-panel":return n.jsx(wU,{component:e,data:t});case"hero":return n.jsx(yU,{component:e,data:t});case"tabs":return n.jsx(bU,{component:e,data:t});case"expand":return n.jsx(kU,{component:e,data:t});case"button":return n.jsx(SU,{component:e,data:t});case"approval":return n.jsx(CU,{component:e,data:t});case"artifact":return n.jsx(EU,{component:e,data:t});case"editor":return n.jsx(AU,{component:e,data:t});case"agent-offer":return n.jsx(NU,{component:e});default:return n.jsx(H,{children:"This page uses a part this dashboard does not know yet. Reload buddi to see it."})}}function eU({component:e,data:t}){const s=Nt(),r=f.useContext(ad),[i,a]=fC(),l=!r&&hC(e.body,s.sensitive),o=l&&!i,c=f.useContext(Ro);let u=e.body.length;const h=p=>p.kind==="button"||p.kind==="link"||p.kind==="form"&&p.drawer!==void 0&&!p.title;for(;c&&u>0&&h(e.body[u-1]);)u-=1;const d=e.body.slice(0,u),m=[...e.actions??[],...e.body.slice(u)];return n.jsx(qn,{title:e.title,note:e.note,actions:m.length>0||l?n.jsxs(n.Fragment,{children:[m.map((p,x)=>n.jsx(Vs,{component:p,data:t},x)),l?n.jsx(mC,{revealed:i,onToggle:a}):null]}):void 0,children:n.jsx(J,{gap:"lg",divided:c,children:o?n.jsx(pC,{}):n.jsx(ad.Provider,{value:r||l,children:d.map((p,x)=>n.jsx(Vs,{component:p,data:t},x))})})})}function tU({component:e,data:t}){const s=Nt(),r=Zx(s,e.to,t);return r===""?null:n.jsx(Q,{children:n.jsx(Zt,{href:r,onClick:i=>{i.preventDefault(),s.navigate(r)},children:e.label})})}function Fy(e){return Math.round(e/1e6)}function nU(e,t){const s=Bn(Oe(t,e.value))??0,r=e.total?Bn(Oe(t,e.total)):null,i=e.total?r&&r>0?s/r:0:s,a=Math.max(0,Math.min(1,i)),l=Math.floor(a*100),o=i>=1,c=e.total&&r&&r>0?`${Fy(s)} of ${Math.max(1,Fy(r))} MB · ${l}%`:`${l}%`;return{percent:l,full:o,line:c}}function sU({component:e,data:t}){const s=c=>c===void 0?"":typeof c=="string"?c:String(Oe(t,c)??""),r=s(e.label),i=s(e.done),{percent:a,full:l,line:o}=nU(e,t);return n.jsxs(J,{gap:"sm",children:[r?n.jsx("span",{children:r}):null,l&&i?n.jsx("span",{role:"status",children:i}):n.jsxs(n.Fragment,{children:[n.jsx(x1,{value:a,label:r||"Progress"}),n.jsx("span",{role:"status",children:o})]})]})}function rU({component:e,data:t}){const s=bn(e.query,t),r=e.rows===void 0?Array.isArray(s.data)?s.data:[]:Gs(s.data,e.rows),i=r.map(h=>String(xe(h,e.x)??"")),a=h=>r.map(d=>Bn(xe(d,h))??null),l=e.series!==void 0,o=e.y===void 0?[]:Array.isArray(e.y)?e.y:[e.y],c=l?e.series.map(h=>({label:h.label,values:a(h.y),type:h.type,...h.unit?{unit:h.unit}:{}})):o.map(h=>({label:o.length===1?e.label??h:h,values:a(h)})),u=e.target?Bn(Oe(s.data,e.target))??null:null;return n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(se,{message:s.error}),r.length===0?s.loading||s.data===void 0?n.jsx(oe,{children:"Loading…"}):n.jsx(ul,{text:e.empty??"Nothing recorded yet."}):n.jsx(__,{xs:i,series:c,type:l?"mixed":e.type??"line",target:u,...e.label?{label:e.label}:{},formatX:h=>/^\d{4}-\d{2}-\d{2}/.test(h)?Gm(h):h,formatY:h=>zt(h,"number",null)})]})}function iU({component:e,data:t}){const s=bn(e.query,t);return n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(se,{message:s.error}),s.data===void 0?n.jsx(oe,{children:e.empty??"Loading…"}):n.jsx(eh,{children:e.items.map((r,i)=>n.jsx(Fs,{label:r.label,value:zt(Oe(s.data,r.value),r.unit??"text",null),tone:qz(r.tone)},i))})]})}function bC(e,t,s,r){const i=(t.meta??[]).map(u=>String(Oe(s,u)??"")).filter(u=>u!==""),a=String(Oe(s,t.title)??""),l=t.to&&!r?Zx(e,t.to,s):null,c=[...t.pill?[t.pill]:[],...t.pills??[]].map((u,h)=>{const d=Oe(s,u.value);if(d==null||d==="")return null;const m=aU(u,d,s);return n.jsx(ge,{tone:kp(m.tone),children:m.text},h)});return{text:a,href:l,pills:n.jsx(n.Fragment,{children:c}),meta:i.join(" · "),title:l?n.jsx("a",{href:l,onClick:u=>{u.preventDefault(),e.navigate(l)},children:a}):a,sub:t.sub?String(Oe(s,t.sub)??""):null,side:n.jsxs(n.Fragment,{children:[c,i.length>0?n.jsxs("span",{className:"muted",children:[" ",i.join(" · ")]}):null]})}}function aU(e,t,s){const r=String(t),i=e.labels??{},a=e.tones??{};return{text:Object.prototype.hasOwnProperty.call(i,r)?i[r]:r,tone:Object.prototype.hasOwnProperty.call(a,r)?a[r]:Sp(e.tone,s)}}function Gs(e,t){const s=xe(e,t);return Array.isArray(s)?s:[]}function kC(e,t,s){const r=[],i=new Set;return e.forEach((a,l)=>{const o=t===void 0?void 0:xe(a,t),c=o==null||o===""?null:String(o);if(c===null){console.warn(`buddi: plugin ${s.plugin}, page ${s.page}, ${s.component}: row ${l} has no value at "${t??"(no key)"}" — not drawn`);return}if(i.has(c)){console.warn(`buddi: plugin ${s.plugin}, page ${s.page}, ${s.component}: two rows share the key "${c}" — the second is not drawn`);return}i.add(c),r.push({key:c,row:a})}),r}function lU({component:e,data:t,onChoose:s,chosen:r}){var N;const i=Nt(),a=f.useContext(yC),l=bn(e.query,t),o=Yo(),[c,u]=f.useState([]),h=a&&!e.select&&(e.actions??[]).length===0&&(e.bulk??[]).length===0,d=Gs(l.data,e.rows),m=e.collapsed?Gs(l.data,e.collapsed.rows):[],p={plugin:i.plugin,page:i.page,component:`list "${e.title??e.rows}"`},x=kC([...d,...m],e.key??((N=e.select)==null?void 0:N.key),p),j=new Map(x.map(k=>[k.row,k.key])),b=new Set(x.map(k=>k.row)),g=new Set(x.filter(({row:k})=>{var S;return((S=e.select)==null?void 0:S.disabledWhen)===void 0||!ws(k,e.select.disabledWhen)}).map(({key:k})=>k)),v=c.filter(k=>g.has(k)),w=f.useMemo(()=>{const k=d.filter(C=>b.has(C));if(!e.groupBy)return[{label:null,rows:k}];const S=new Map;for(const C of k){const I=String(xe(C,e.groupBy.key)??"");S.set(I,[...S.get(I)??[],C])}return[...S].map(([C,I])=>{var A,O;return{label:((O=(A=e.groupBy)==null?void 0:A.labels)==null?void 0:O[C])??C,rows:I}})},[d,e.groupBy,x.length]),y=k=>k.map(S=>{var z;const C=bC(i,e.item,S,s),I=j.get(S);if(h&&(s||C.href))return n.jsx(v1,{href:C.href??"#",current:r===I,onClick:()=>s?s(I):i.navigate(C.href),title:C.text,meta:C.meta,sub:C.sub,side:C.pills},I);const A=((z=e.select)==null?void 0:z.disabledWhen)!==void 0&&ws(S,e.select.disabledWhen),O=(e.actions??[]).filter(L=>ws(S,L.when));return n.jsx(Tt,{lead:e.select?n.jsx("input",{type:"checkbox","aria-label":`Select ${C.text}`,disabled:A,checked:c.includes(I),onClick:L=>L.stopPropagation(),onChange:L=>u(E=>L.target.checked?[...E,I]:E.filter($=>$!==I))}):void 0,title:s?n.jsx("a",{href:"#","aria-current":r===I?"true":void 0,onClick:L=>{L.preventDefault(),s(I)},children:C.text}):C.title,sub:C.sub,side:n.jsxs(n.Fragment,{children:[C.side,O.map((L,E)=>n.jsx(Va,{action:L,args:Fi(L.args,{data:l.data,row:S,scope:i}),disabled:o.busy,running:o.running===L.tool,row:S,onRun:($,_)=>void o.run($,_)},E))]})},I)});return n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(se,{message:l.error}),n.jsx(cl,{act:o}),w.every(k=>k.rows.length===0)?l.loading?n.jsx(oe,{children:"Loading…"}):n.jsx(ul,{text:e.empty??"Nothing here yet."}):n.jsxs(At,{children:[e.select?n.jsx(Tt,{lead:n.jsx("input",{type:"checkbox","aria-label":"Select every row",checked:g.size>0&&v.length===g.size,disabled:g.size===0,onChange:k=>u(k.target.checked?[...g]:[])}),title:n.jsxs("span",{className:"muted",children:[g.size," to choose from"]})}):null,w.map((k,S)=>n.jsxs("div",{children:[k.label?n.jsx("div",{className:"ui-list-group",children:k.label}):null,y(k.rows)]},S))]}),e.collapsed&&m.some(k=>b.has(k))?n.jsx($t,{summary:`${e.collapsed.label} (${m.filter(k=>b.has(k)).length})`,children:n.jsx(At,{children:y(m.filter(k=>b.has(k)))})}):null,e.bulk&&e.bulk.length>0?n.jsxs(Q,{align:"end",children:[n.jsxs("span",{className:"ui-toolbar-note",children:[v.length," selected"]}),e.bulk.map((k,S)=>{const C=v.length>0||k.all!==!0?v:[...g];return n.jsx(Va,{action:k,args:Fi(k.args,{data:l.data,selected:C,scope:i}),count:C.length,disabled:o.busy||C.length===0,running:o.running===k.tool,onRun:(I,A)=>{u([]),o.run(I,A)}},S)})]}):null]})}function oU({component:e,data:t}){const s=Nt(),r=bn(e.query,t),i=Yo(),a=Gs(r.data,e.rows);return n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(se,{message:r.error}),n.jsx(cl,{act:i}),a.length===0?r.loading?n.jsx(oe,{children:"Loading…"}):n.jsx(ul,{text:e.empty??"Nothing here yet."}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[e.columns.map(l=>n.jsx("th",{children:l.label},l.key)),e.actions&&e.actions.length>0?n.jsx("th",{"aria-label":"Actions"}):null]})}),n.jsx("tbody",{children:a.map((l,o)=>n.jsxs("tr",{children:[e.columns.map(c=>{const u=c.pill?null:zt(xe(l,c.key),c.type??"text",null);return n.jsx("td",{"data-fit":c.fit,title:cU(c,l,u),children:c.pill?n.jsx(uU,{column:c,row:l}):c.fit==="truncate"?n.jsx("span",{className:"ui-table-cut",children:u}):u},c.key)}),e.actions&&e.actions.length>0?n.jsx("td",{children:n.jsx(Q,{align:"end",children:e.actions.filter(c=>ws(l,c.when)).map((c,u)=>n.jsx(Va,{action:c,args:Fi(c.args,{data:r.data,row:l,scope:s}),disabled:i.busy,running:i.running===c.tool,row:l,onRun:(h,d)=>void i.run(h,d)},u))})}):null]},o))})]})]})}function cU(e,t,s){if(e.hint){const r=xe(t,e.hint);if(r!=null&&r!=="")return String(r)}return e.fit==="truncate"&&s?s:void 0}function uU({column:e,row:t}){var l,o;const s=xe(t,e.key);if(Array.isArray(s))return n.jsx(n.Fragment,{children:s.map((c,u)=>{var j;const h=c,d=typeof h=="object"&&h!==null?h.value:c;if(d==null||d==="")return null;const m=typeof h=="object"&&h!==null?h.tone:void 0,p=(j=e.pill)==null?void 0:j.labels,x=p&&Object.prototype.hasOwnProperty.call(p,String(d))?p[String(d)]:zt(d,e.type??"text",null);return n.jsx(ge,{tone:kp(Sp(typeof m=="string"?m:void 0,t)),children:x},u)})});const r=(l=e.pill)==null?void 0:l.labels,i=String(s),a=r&&Object.prototype.hasOwnProperty.call(r,i)?r[i]:zt(s,e.type??"text",null);return n.jsx(ge,{tone:kp(Sp((o=e.pill)==null?void 0:o.tone,t)),children:a})}function dU({component:e,data:t}){const s=bn(e.query,t);return s.error?n.jsx(se,{message:s.error}):s.data===void 0?n.jsx(oe,{children:e.empty??"Loading…"}):n.jsx(qn,{title:e.title,note:e.note,children:n.jsxs(J,{gap:"lg",children:[e.fields.length>0?n.jsx(Vt,{items:e.fields.map(r=>({key:r.label,label:r.label,value:zt(Oe(s.data,r.value),r.unit??"text",null)}))}):null,e.body.map((r,i)=>n.jsx(Vs,{component:r,data:s.data},i))]})})}function hU({component:e,data:t}){const s=Nt(),r=bn(e.initial,t),i=Yo(),[a,l]=f.useState(!1),o=JSON.stringify([r.data??null,s.version]),c=n.jsx(fU,{component:e,data:t,initialData:r.data,act:i,onDone:()=>l(!1)},o);return e.drawer?n.jsxs(te,{title:e.title,aside:e.note,actions:n.jsx(R,{variant:"accent",onClick:()=>l(!0),children:e.drawer.button}),children:[n.jsx(cl,{act:i}),a?n.jsx(wt,{title:e.drawer.title,onClose:()=>l(!1),children:c}):null]}):n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(se,{message:r.error}),c]})}function fU({component:e,data:t,initialData:s,act:r,onDone:i}){const a=f.useContext(wC),l=Nt(),[o,c]=f.useState(()=>od(e.fields,s)),u=ev(e.fields,o,s),h=e.fields.some(d=>d.required&&!u.has(d.name)&&(o[d.name]===""||o[d.name]===void 0||Array.isArray(o[d.name])&&o[d.name].length===0));return n.jsxs(J,{children:[n.jsx(tv,{fields:e.fields,columns:e.columns,values:o,data:s,onChange:(d,m)=>c(p=>({...p,[d]:m}))}),e.drawer?null:n.jsx(cl,{act:r}),n.jsx(Q,{align:"end",className:a?"ui-panel-foot":void 0,children:n.jsx(Va,{action:e.submit,args:Fi(e.submit.args,{data:t,fields:o,shape:e.fields,omit:u,scope:l}),disabled:r.busy||h,running:r.running===e.submit.tool,onRun:(d,m)=>void r.run(d,m,i)})})]})}function mU(e,t){var r;if(e.type==="checkbox")return e.label;const s=(r=e.options)==null?void 0:r.find(i=>i.value===t);return`${e.label}: ${s?s.label:t}`}function zy(e){return e!=null&&e!==""&&e!==!1&&e!=="false"}function pU({component:e,data:t}){const s=Nt(),[r,i]=f.useState(()=>od(e.fields,t)),[a,l]=f.useState(e.auto===!0),[o,c]=f.useState(!1),u=e.fields.every(C=>!C.required||String(r[C.name]??"")!==""),h=bn(a&&u?e.query:void 0,t),d=Gs(h.data,e.rows),m=e.count===void 0?void 0:xe(h.data,e.count),p=e.note===void 0?void 0:xe(h.data,e.note),x=e.fields.find(C=>C.type==="text"||C.type==="email")??null,j=e.fields.filter(C=>C!==x),b=C=>{s.setParams(Object.fromEntries(e.fields.map(I=>[I.name,String(C[I.name]??"")||null]))),l(!0)},g=(C,I)=>{const A={...r,[C]:I};i(A),e.auto&&b(A)},v=()=>{const C=od(e.fields,null);i(C),e.auto?b(C):(s.setParams(Object.fromEntries(e.fields.map(I=>[I.name,null]))),l(!1))},w=a?j.filter(C=>zy(s.params[C.name])):[],y=x?w.map(C=>n.jsx(Ju,{label:C.label,onRemove:()=>{const I={...r,[C.name]:C.type==="checkbox"?!1:""};i(I),b(I)},children:mU(C,String(s.params[C.name]))},C.name)):[],N=j.filter(C=>zy(r[C.name])).length,k=e.auto&&!e.reset?null:n.jsxs(n.Fragment,{children:[e.reset?n.jsx(R,{variant:"ghost",onClick:v,children:"Clear"}):null,e.auto?null:n.jsx(R,{type:"submit",variant:"accent",disabled:!u,children:"Search"})]}),S=e.results.to?e.results:e.to?{...e.results,to:e.to}:e.results;return n.jsx(qn,{title:e.title,children:n.jsxs(J,{children:[n.jsx(b1,{label:e.title??"Search",onSubmit:()=>{!e.auto&&u&&b(r)},main:x?n.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=>g(x.name,C.target.value)}):void 0,filters:j.length>0?n.jsx(tv,{fields:j,values:r,data:t,compact:!0,onChange:g}):void 0,...x&&j.length>0?{filtersOpen:o,onToggleFilters:()=>c(C=>!C),active:N}:{},chips:y.length>0?y:void 0,actions:k}),n.jsx(se,{message:h.error}),a&&(m!==void 0||p!==void 0)?n.jsxs("p",{className:"ui-card-meta",children:[m===void 0?"":`${zt(m,"number",null)} in all. `,p===void 0?"":String(p)]}):null,a?d.length===0?n.jsx(oe,{children:h.loading?"Searching…":e.empty??"Nothing matches."}):n.jsx("div",{className:"ui-panel","data-flush":"true",children:n.jsx(At,{children:d.map((C,I)=>{const A=bC(s,S,C);return n.jsx(Tt,{title:A.title,sub:A.sub,side:A.side},I)})})}):null]})})}function gU({component:e,data:t}){const s=Nt(),r=e.selection==="local",[i,a]=f.useState(null),l=r?i:s.params[e.param]??s.item,o=r&&i!==null?{...s,params:{...s.params,[e.param]:i}}:null,c=n.jsx(J,{gap:"lg",divided:!0,children:e.detail.map((u,h)=>n.jsx(Vs,{component:u,data:t},h))});return n.jsx(Ro.Provider,{value:!1,children:n.jsx(j1,{list:n.jsx(yC.Provider,{value:!0,children:n.jsx(Vs,{component:e.list,data:t,chosen:l??null,...r?{choose:a}:{}})}),detail:l?o?n.jsx(Jx.Provider,{value:o,children:c}):c:void 0,empty:e.empty??"Choose one to see it here."})})}function xU({component:e,data:t}){const s=Nt(),[r,i]=f.useState(!1),a=bn(e.query,t,r&&e.poll?e.poll.seconds*1e3:void 0),l=e.poll!==void 0&&a.data!==void 0&&ws(a.data,e.poll.while);f.useEffect(()=>i(l),[l]);const o=Gs(a.data,e.rows);return n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(se,{message:a.error}),o.length===0?a.loading?n.jsx(oe,{children:"Loading…"}):n.jsx(ul,{text:e.empty??"Nothing here yet."}):n.jsx(J,{gap:"lg",divided:!0,children:kC(o,e.key,{plugin:s.plugin,page:s.page,component:`repeat "${e.title??e.rows}"`}).map(({key:c,row:u})=>n.jsx(te,{children:n.jsx(J,{children:e.body.map((h,d)=>n.jsx(Vs,{component:h,data:u},d))})},c))})]})}function vU({component:e,data:t}){const s=Nt(),r=Uz({...e.views?{views:e.views}:{},...e.default?{default:e.default}:{},today:Tz(s.timezone),storageKey:`buddi.calendar-view:${s.plugin}/${s.page}`}),i=bn(e.query,t,void 0,{from:r.from,to:r.to}),a=f.useMemo(()=>$z(Gs(i.data,e.events),e.map,s.timezone,`plugin ${s.plugin}, page ${s.page}, calendar`),[i.data,e.events,e.map,s.timezone,s.plugin,s.page]);return n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(se,{message:i.error}),n.jsx(Bz,{state:r,events:a,hours:e.hours,empty:e.empty??"Nothing.",label:e.title??"Calendar"})]})}function jU({component:e,data:t}){var d;const s=Nt(),r=bn(e.query,t),i={items:"$",icon:e.icon,value:e.value,label:e.label,...e.lines?{lines:e.lines}:{},...e.tone?{tone:e.tone}:{}},a=Gs(r.data,e.items).flatMap(m=>{const p=kx([m],i).tiles[0];return p?[{tile:p,key:e.select?String(xe(m,e.select.key)??""):""}]:[]}),l=e.select,o=l?Math.max(0,a.findIndex(m=>m.key===s.params[l.param])):null,c=((d=a[0])==null?void 0:d.key)??"",u=l?s.params[l.param]:void 0,h=a.some(m=>m.key===u);return f.useEffect(()=>{l&&c!==""&&!h&&s.setParams({[l.param]:c})},[l==null?void 0:l.param,c,h]),n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(se,{message:r.error}),r.data===void 0?n.jsx(oe,{children:"Loading…"}):a.length===0?n.jsx(ul,{text:e.empty??"Nothing to show."}):n.jsx(M1,{props:{tiles:a.map(m=>m.tile),notice:!1,empty:""},...e.layout?{layout:e.layout}:{},...l?{selected:o,onPick:m=>{var p;return s.setParams({[l.param]:((p=a[m])==null?void 0:p.key)||null})}}:{}})]})}function wU({component:e,data:t}){const s=bn(e.query,t),r=Gs(s.data,e.points);if(s.data===void 0||r.length===0)return n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(se,{message:s.error}),s.data===void 0?n.jsx(oe,{children:"Loading…"}):n.jsx(ul,{text:e.empty??"Nothing to show."})]});const i=r.map(c=>String(xe(c,e.x)??"")),a={items:"$",icon:e.tiles.icon,value:e.tiles.value,label:e.tiles.label,...e.tiles.lines?{lines:e.tiles.lines}:{}},l=r.map((c,u)=>kx([c],a).tiles[0]??{icon:null,value:"",label:i[u]??"",lines:[],tone:"neutral",link:null}),o=e.series.map(c=>({id:c.id,label:c.label,kind:c.kind,...c.unit?{unit:c.unit}:{},values:r.map(u=>Bn(xe(u,c.y))??null)}));return n.jsxs(n.Fragment,{children:[n.jsx(se,{message:s.error}),n.jsx(Yz,{...e.title?{title:e.title}:{},...e.note?{note:e.note}:{},...e.labelEvery?{labelEvery:e.labelEvery}:{},xs:i,series:o,tiles:l})]})}function yU({component:e,data:t}){const s=bn(e.query,t),r=o=>{const c=xe(s.data,o);return c==null?"":String(c)};if(s.data===void 0||s.data===null)return n.jsxs(n.Fragment,{children:[n.jsx(se,{message:s.error}),n.jsx(oe,{children:s.loading?"Loading…":e.empty??"Nothing to show."})]});const i=r(e.value),a=r(e.title),l=e.facts.map(o=>({label:o.label,value:r(o.path)})).filter(o=>o.value!=="");return n.jsxs("section",{className:"pg-hero","aria-label":[i,a,...l.map(o=>`${o.label} ${o.value}`)].filter(Boolean).join(", "),children:[n.jsxs("div",{className:"pg-hero-main","aria-hidden":"true",children:[n.jsx("span",{className:"pg-hero-icon",children:n.jsx(we,{name:th(ep(Oe(s.data,e.icon))),size:44})}),n.jsx("span",{className:"pg-hero-value",children:i}),a?n.jsx("span",{className:"pg-hero-title",children:a}):null]}),l.length>0?n.jsx("dl",{className:"pg-hero-facts","aria-hidden":"true",children:l.map(o=>n.jsxs("div",{className:"pg-hero-fact",children:[n.jsx("dt",{children:o.label}),n.jsx("dd",{children:o.value})]},o.label))}):null]})}function bU({component:e,data:t}){var u;const s=Nt(),[r,i]=f.useState(e.default??e.tabs[0].id),a=e.pick,{options:l}=vC({name:(a==null?void 0:a.param)??"",label:(a==null?void 0:a.label)??"",...a!=null&&a.options?{options:a.options}:{},...a!=null&&a.optionsFrom?{optionsFrom:a.optionsFrom}:{}},{},t),o=a?l.some(h=>h.value===s.params[a.param])?s.params[a.param]:((u=l[0])==null?void 0:u.value)??"":"",c=e.tabs.find(h=>h.id===r)??e.tabs[0];return n.jsxs("div",{className:"pg-tabs",children:[n.jsxs("div",{className:"pg-tabs-bar",children:[a&&l.length>1?n.jsx(ls,{label:a.label,options:l,value:o,onChange:h=>s.setParams({[a.param]:h})}):null,n.jsx(ls,{label:e.title??"View",options:e.tabs.map(h=>({value:h.id,label:h.label})),value:c.id,onChange:i})]}),c.body.map((h,d)=>n.jsx(Vs,{component:h,data:t},`${c.id}-${d}`))]})}function kU({component:e,data:t}){const[s,r]=f.useState(!1),i=bn(s?e.query:void 0,t),a=typeof e.label=="string"?e.label:String(Oe(t,e.label)??"");return n.jsxs($t,{summary:a,boxed:!0,onToggle:l=>r(l),children:[n.jsx(se,{message:i.error}),i.data===void 0?n.jsx(oe,{children:"Loading…"}):n.jsx(J,{children:e.body.map((l,o)=>n.jsx(Vs,{component:l,data:i.data},o))})]})}function SU({component:e,data:t}){const s=Nt(),r=Yo();return n.jsxs(n.Fragment,{children:[n.jsx(Q,{align:"end",children:n.jsx(Va,{action:e.action,args:Fi(e.action.args,{data:t,row:t,scope:s}),disabled:r.busy,running:r.running===e.action.tool,row:t,onRun:(i,a)=>void r.run(i,a)})}),n.jsx(cl,{act:r})]})}function NU({component:e}){const t=Nt();return n.jsx(Vx,{plugin:t.plugin,agent:e.agent,text:e.text,label:e.label})}function CU({component:e,data:t}){const s=xe(t,e.path);return typeof s!="string"||s===""?null:n.jsx(ld,{id:s})}function EU({component:e,data:t}){const s=xe(t,e.path);return typeof s!="string"||s===""?null:n.jsx(Q,{children:n.jsx("a",{href:ni(s),children:e.label})})}function AU({component:e,data:t}){const s=bn(e.query,t),r=Yo();return s.error?n.jsx(se,{message:s.error}):s.data===void 0?n.jsx(oe,{children:e.empty??"Loading…"}):n.jsxs(n.Fragment,{children:[n.jsx(cl,{act:r}),n.jsx(TU,{component:e,data:t,loaded:s.data,act:r},JSON.stringify(s.data))]})}function TU({component:e,data:t,loaded:s,act:r}){const i=Nt(),[a,l]=f.useState(()=>od(e.fields,s)),o={...a,version:xe(s,e.version)},c=ev(e.fields,a,s),u=e.readOnlyWhen!==void 0&&ws(s,e.readOnlyWhen),h=(e.actions??[]).filter(p=>p.placement==="leading"),d=(e.actions??[]).filter(p=>p.placement!=="leading"),m=(p,x)=>n.jsx(Va,{action:p,args:Fi(p.args,{data:t,fields:o,shape:e.fields,omit:c,scope:i}),disabled:r.busy,running:r.running===p.tool,onRun:(j,b)=>void r.run(j,b)},`${p.tool}-${x}`);return n.jsx(qn,{title:e.title,note:e.note,children:n.jsxs(J,{children:[n.jsx(tv,{fields:e.fields,values:a,data:s,disabled:u,onChange:(p,x)=>l(j=>({...j,[p]:x}))}),u?null:n.jsxs(Q,{align:"end",children:[h.map(m),h.length>0?n.jsx(en,{}):null,m(e.save,-1),d.map(m)]}),e.footnote?n.jsx("p",{className:"ui-toolbar-note",children:e.footnote}):null]})})}function nv({page:e,item:t,navigate:s,timezone:r,embedded:i,siblings:a}){const[l,o]=f.useState({}),[c,u]=f.useState(0),h={plugin:e.plugin,page:e.id,pages:a??[e],item:t??null,params:{...l,...t?{item:t}:{},...IU(e,t)},setParams:x=>o(j=>{const b={...j};for(const[g,v]of Object.entries(x))v===null?delete b[g]:b[g]=v;return b}),navigate:s,timezone:r,version:c,refresh:()=>u(x=>x+1),sensitive:new Set(e.sensitive??[])},d=e.body[0],m=!i&&(d==null?void 0:d.kind)==="notice"&&typeof d.text=="string"&&d.when===void 0&&d.title===void 0&&(d.tone===void 0||d.tone==="neutral")?d.text:void 0,p=m===void 0?e:{...e,body:e.body.slice(1)};return n.jsx(Jx.Provider,{value:h,children:n.jsx(yn,{embedded:i,title:e.title,lede:m,children:n.jsx(RU,{page:p,boxed:i===!0})})})}function RU({page:e,boxed:t}){const s=Nt();return e.data&&s.sensitive.has(e.data.query)?n.jsx(gC,{children:n.jsx(Uy,{page:e,boxed:t})}):n.jsx(Uy,{page:e,boxed:t})}function Uy({page:e,boxed:t}){const s=bn(e.data,null);return n.jsxs(J,{gap:"lg",divided:!t,children:[n.jsx(se,{message:s.error}),n.jsx(Ro.Provider,{value:t,children:e.body.map((r,i)=>n.jsx(Vs,{component:r,data:s.data??null},i))})]})}function IU(e,t){if(!t)return{};const s=[],r=i=>{for(const a of i)a.kind==="list-detail"?(s.push(a.param),r(a.detail)):(a.kind==="section"||a.kind==="detail"||a.kind==="expand")&&r(a.body)};return r(e.body),Object.fromEntries(s.map(i=>[i,t]))}function PU(e){return n.jsx(nv,{...e,embedded:!0})}function ul({text:e}){const t=e.search(/[.!?]\s/),s=t===-1?e.replace(/[.]$/,""):e.slice(0,t+(e[t]==="."?0:1)),r=t===-1?"":e.slice(t+1).trim();return n.jsx(tn,{title:s,children:r||null})}const By=[{id:"",label:"All files"},{id:"produced",label:"Created by agents"},{id:"uploaded",label:"Uploaded by you"}],$U=["","image","pdf","table","text","code","audio","video","archive","file"];function MU({hash:e,timezone:t,navigate:s,agents:r}){var L;const i=zO(e),a=(i==null?void 0:i.artifactId)??null,l=(i==null?void 0:i.filters.origin)??"",o=(i==null?void 0:i.filters.family)??"",c=(i==null?void 0:i.filters.q)??"",[u,h]=f.useState(c);f.useEffect(()=>{h(c)},[c]);const d=(E,$=!1)=>s(Ic(a,{q:c,origin:l,family:o,...E}),$);f.useEffect(()=>{if(u===c)return;const E=window.setTimeout(()=>d({q:u},!0),250);return()=>window.clearTimeout(E)},[u]);const[m,p]=f.useState(null),[x,j]=f.useState(null),[b,g]=f.useState(null),[v,w]=f.useState(!1),[y,N]=f.useState(!1),k=E=>{var $;return E?(($=r.find(_=>_.id===E))==null?void 0:$.name)??E:""},S=f.useRef(0);f.useEffect(()=>{const E=++S.current;p(null),j(null),w(!1),g(null),T.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{}}).then($=>{S.current===E&&(p($.entries),j($.next))}).catch($=>{S.current===E&&g($ instanceof pe?$.message:String($))})},[c,l,o]);const C=()=>{if(!x||v)return;w(!0);const E=S.current;T.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{},cursor:x}).then($=>{S.current===E&&(p(_=>{const B=new Set((_??[]).map(M=>M.id));return[..._??[],...$.entries.filter(M=>!B.has(M.id))]}),j($.next))}).catch($=>{S.current===E&&g($ instanceof pe?$.message:String($))}).finally(()=>{S.current===E&&w(!1)})},I=(l?1:0)+(o?1:0),A=((L=By.find(E=>E.id===l))==null?void 0:L.label)??l,O=n.jsxs(n.Fragment,{children:[m===null?n.jsx(oe,{children:"Loading…"}):m.length===0?n.jsx(oe,{children:"No file matches that."}):n.jsx(At,{children:m.map(E=>n.jsx(v1,{href:Ic(E.id,{q:c,origin:l,family:o}),current:E.id===a,onClick:()=>s(Ic(E.id,{q:c,origin:l,family:o})),lead:n.jsx("span",{className:"files-row-visual","data-family":E.family,children:E.family==="image"&&!E.deleted?n.jsx("img",{src:pr(E.id),alt:"",loading:"lazy"}):n.jsx(Lx,{family:E.family})}),title:E.filename??"Untitled file",meta:n.jsx("span",{title:Be(E.createdAt,t),children:Fe(E.createdAt)}),sub:`${Ai[E.family]} · ${$n(E.sizeBytes)} · ${SC(E,k)}${OU(E,k)}`},E.id))}),x?n.jsx("div",{className:"files-more",children:n.jsx(R,{size:"sm",onClick:C,disabled:v,children:v?"Loading…":"Show more"})}):null]}),z=m!==null&&m.length===0&&!c&&!l&&!o&&!u;return n.jsxs("div",{className:"ui-page files","data-selected":a?"true":void 0,children:[n.jsxs("header",{className:"ui-page-head",children:[n.jsx("h2",{className:"ui-page-title",children:"Files"}),n.jsx("p",{className:"ui-page-lede",children:"What your agents made or were given."})]}),z?n.jsx(tn,{icon:"files",title:"Nothing here yet",children:"Drop a file into any conversation and it shows up here too."}):n.jsxs(n.Fragment,{children:[n.jsx(b1,{label:"Files",onSubmit:()=>d({q:u},!0),main:n.jsx("input",{type:"search",value:u,placeholder:"Search by filename","aria-label":"Search files by name",onChange:E=>h(E.target.value)}),filters:n.jsxs(bs,{dense:!0,children:[n.jsx(ee,{label:"Origin",children:n.jsx("select",{value:l,"aria-label":"Origin",onChange:E=>d({origin:E.target.value}),children:By.map(E=>n.jsx("option",{value:E.id,children:E.label},E.id))})}),n.jsx(ee,{label:"Kind",children:n.jsx("select",{value:o,"aria-label":"Kind",onChange:E=>d({family:E.target.value}),children:$U.map(E=>n.jsx("option",{value:E,children:E===""?"Any kind":Ai[E]},E))})})]}),filtersOpen:y,onToggleFilters:()=>N(E=>!E),active:I,chips:I>0?n.jsxs(n.Fragment,{children:[l?n.jsx(Ju,{label:"Origin",onRemove:()=>d({origin:""}),children:A}):null,o?n.jsx(Ju,{label:"Kind",onRemove:()=>d({family:""}),children:Ai[o]}):null]}):void 0}),n.jsx(se,{message:b}),n.jsx(j1,{className:"files-split",label:"Files",list:O,detail:a?n.jsx(DU,{id:a,timezone:t,agents:r,navigate:s,onBack:()=>s(Ic(null,{q:c,origin:l,family:o}))},a):void 0,empty:"Choose a file to see it here."})]})]})}function OU(e,t){var i,a;const s=(i=e.context)!=null&&i.groupName?`in ${e.context.groupName}`:(a=e.context)!=null&&a.agentId&&e.context.agentId!==e.agentId?`with ${t(e.context.agentId)}`:"",r=e.contexts>1?`${e.contexts} conversations`:"";return[s,r].filter(Boolean).map(l=>` · ${l}`).join("")}function SC(e,t){return e.origin==="uploaded"?"You sent it":e.origin==="produced"?`Made by ${t(e.agentId)||"an agent"}`:e.agentId?`Saved by ${t(e.agentId)}`:"Origin unknown"}function DU({id:e,timezone:t,agents:s,navigate:r,onBack:i}){const[a,l]=f.useState(null),[o,c]=f.useState(!1),[u,h]=f.useState(null);f.useEffect(()=>{let v=!1;return l(null),h(null),T.libraryEntry(e).then(w=>{v||l(w)}).catch(w=>{v||h(w instanceof pe&&w.status===404?"This file is no longer in the library.":w instanceof pe?w.message:String(w))}),()=>{v=!0}},[e]);const d=v=>{var w;return v?((w=s.find(y=>y.id===v))==null?void 0:w.name)??v:""};if(u)return n.jsxs("div",{className:"files-detail-body",children:[n.jsx(R,{size:"sm",onClick:i,className:"files-back",children:"Back to Files"}),n.jsx(H,{tone:"critical",children:u})]});if(!a)return n.jsx("div",{className:"files-detail-body",children:n.jsx(oe,{children:"Loading…"})});const{entry:m,contexts:p,contextsTotal:x,available:j}=a,b=m.filename??"Untitled file",g=()=>{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 n.jsxs("div",{className:"files-detail-body",children:[n.jsx(R,{size:"sm",onClick:i,className:"files-back",children:"Back to Files"}),n.jsxs("header",{className:"files-detail-head",children:[n.jsx("span",{className:"files-detail-mark","data-family":m.family,"aria-hidden":"true",children:n.jsx(Lx,{family:m.family})}),n.jsxs("div",{className:"files-detail-text",children:[n.jsx("h3",{className:"files-detail-name",children:b}),n.jsxs("p",{className:"files-detail-meta",children:[Ai[m.family]," · ",$n(m.sizeBytes)," · ",Be(m.createdAt,t)]})]}),j?n.jsx("a",{className:"ui-btn","data-variant":"accent",href:ni(m.id),download:b,children:"Download"}):null]}),j?null:n.jsx(H,{tone:"warning",children:"The file's bytes are no longer on this machine. What is known about it stays here; the download will not work."}),n.jsx(B1,{artifactId:m.id,filename:m.filename,mime:m.mime,family:m.family,available:j}),n.jsx(Vt,{items:[{label:"Origin",value:SC(m,d)},...m.agentId&&m.origin==="produced"?[{label:"Made by",value:n.jsxs("span",{className:"files-agent",children:[n.jsx(Nn,{agents:s,id:m.agentId,size:"sm"}),d(m.agentId)]})}]:[],{label:"Type",value:n.jsx("span",{className:"mono",children:m.mime})},{label:"Id",value:n.jsx("span",{className:"mono",children:m.id})}]}),n.jsxs("section",{className:"files-conversations",children:[n.jsx("h4",{className:"ui-section-title",children:"Conversations"}),p.length===0?n.jsx("p",{className:"muted",children:"No conversation is recorded for this file. It may date from before the library kept track."}):n.jsx("ul",{className:"files-ctx",role:"list",children:p.map(v=>{const w=v.groupId?Gl(v.groupId,v.conversationId):Ve(v.conversationAgentId,v.conversationId),y=v.groupId?v.groupName??"a group":d(v.conversationAgentId);return n.jsxs("li",{className:"files-ctx-row",children:[n.jsxs("span",{className:"files-ctx-text",children:[n.jsx("span",{children:v.groupId?`Group: ${y}`:y}),n.jsxs("span",{className:"muted",children:[" · ",v.kind==="produced"?`made by ${d(v.agentId)||"an agent"}`:v.kind==="reused"?"sent again":"sent by you"," · ",Fe(v.at)]})]}),n.jsx("a",{className:"ui-btn","data-size":"sm",href:w,onClick:N=>{N.preventDefault(),r(w)},children:"Open conversation"})]},`${v.conversationId}:${v.kind}`)})}),p.length<x?n.jsx(Q,{align:"end",children:n.jsx(R,{size:"sm",onClick:g,disabled:o,children:o?"Loading…":`Show ${x-p.length} more`})}):null]})]})}const _U={mail:"mail",money:"money",calendar:"calendar",people:"agents",file:"files",chart:"chart",bell:"bell",plug:"plug",key:"key",globe:"globe",sun:"sun",cloud:"cloud"};function NC(e){return e&&_U[e]||"plug"}const CC="a connection needs you";function LU({attention:e,place:t,onNavigate:s,theme:r,onTheme:i,plugins:a=[],updateAvailable:l=!1,settingsDot:o,version:c,stale:u=!1,reload:h,timezone:d}){return n.jsxs("nav",{className:"rail","aria-label":"Places",children:[n.jsx("a",{className:"rail-mark",href:Kt,onClick:m=>{m.preventDefault(),s(Kt)},"aria-label":"buddi home",children:n.jsx(Xu,{})}),qO.filter(m=>m.route!==dn).map(m=>n.jsx(vf,{label:m.label,href:m.route,active:t===m.route,badge:m.route===Kt?e:0,onClick:()=>s(m.route),children:Wy[m.route]},m.route)),a.map(m=>{const p=ti(m.plugin,m.id);return n.jsx(vf,{label:m.title,href:p,active:t===p,badge:0,onClick:()=>s(p),children:n.jsx(we,{name:NC(m.icon)})},p)}),n.jsx("div",{className:"rail-spacer"}),n.jsx(vf,{label:"Settings",href:dn,active:t===dn,badge:0,dot:l?"a newer buddi is ready":o,onClick:()=>s(dn),children:Wy[dn]}),n.jsx(zU,{theme:r,onTheme:i,onNavigate:s,version:c,stale:u,reload:h,timezone:d})]})}const FU=[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}];function zU({theme:e,onTheme:t,onNavigate:s,version:r,stale:i,reload:a=()=>window.location.reload(),timezone:l}){var v,w,y;const o=le(()=>T.owner(),[]),c=le(()=>T.focus(),[],6e4),u=((v=c.data)==null?void 0:v.focus)??null,h=(N,k)=>{T.setFocus(N,k).finally(()=>c.reload())},d=((y=(w=o.data)==null?void 0:w.preferredName)==null?void 0:y.trim())||null,m=(d??"You").slice(0,1).toUpperCase(),[p]=f.useState(dD),[x]=f.useState(WU),j=d?`You: ${d}`:"You",b=u?`${_l[u.mode]} ${EC(u,l)}`:null,g=[j,b,i?"reload to update":null].filter(Boolean).join(", ");return n.jsx("div",{className:"rail-owner",children:n.jsxs(Kd,{modal:!1,children:[n.jsx(Vd,{asChild:!0,children:n.jsxs("button",{type:"button",className:"rail-owner-btn","aria-label":g,children:[n.jsx("span",{className:"rail-owner-face","aria-hidden":"true",children:m}),i?n.jsx("span",{className:"ui-badge rail-dot","data-kind":"dot","data-testid":"owner-dot","aria-hidden":"true"}):null,u?n.jsx("span",{className:"rail-focus","data-testid":"owner-focus","aria-hidden":"true",children:n.jsx(we,{name:"moon",size:10})}):null]})}),n.jsx(Wo,{children:n.jsxs(Gd,{className:"ui-menu rail-owner-menu",side:"right",align:"end",sideOffset:10,children:[n.jsxs("div",{className:"rail-owner-head",children:[n.jsx("span",{className:"rail-owner-face","data-size":"lg","aria-hidden":"true",children:m}),n.jsxs("span",{className:"rail-owner-who",children:[n.jsx("span",{className:"rail-owner-name",children:d??"You"}),n.jsx("span",{className:"rail-owner-sub",children:"On this Mac"})]})]}),n.jsx(Mr,{className:"ui-menu-sep"}),n.jsx(BU,{focus:u,timezone:l,onSwitch:h}),n.jsx(Mr,{className:"ui-menu-sep"}),n.jsx(Yd,{className:"ui-menu-label",children:"Theme"}),n.jsx("div",{className:"rail-owner-theme",children:n.jsx(ls,{label:"Theme",options:FU,value:e,onChange:t})}),n.jsx(Mr,{className:"ui-menu-sep"}),n.jsx(Ei,{className:"ui-menu-item",onSelect:()=>s(et("appearance")),children:"Change appearance"}),p||i?n.jsxs(Ei,{className:"ui-menu-item rail-owner-reload","data-update":i?"true":void 0,onSelect:()=>a(),children:[n.jsx("span",{children:i?"Reload to update":"Reload"}),x?n.jsx("kbd",{className:"rail-owner-kbd",children:x}):null]}):null,r?n.jsxs(n.Fragment,{children:[n.jsx(Mr,{className:"ui-menu-sep"}),n.jsxs(Ei,{className:"ui-menu-item rail-owner-version","data-update":r.updateAvailable?"true":void 0,onSelect:()=>s(et("system")),children:[n.jsxs("span",{className:"mono",children:["buddi ",r.current]}),r.updateAvailable&&r.latest?n.jsxs("span",{className:"rail-owner-update",children:["A newer buddi is ready: ",r.latest]}):null]})]}):null]})})]})})}const _l={normal:"Off","urgent-only":"Urgent only","do-not-disturb":"Do not disturb"},UU=[{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 EC(e,t,s=new Date){if(!e.until)return"until you turn it off";const r=new Date(e.until),i=t?{timeZone:t}:{},a=c=>new Intl.DateTimeFormat("en-CA",{...i,dateStyle:"short"}).format(c),l=new Intl.DateTimeFormat("en-GB",{...i,hour:"2-digit",minute:"2-digit"}).format(r);return a(r)===a(s)?`until ${l}`:`until ${new Intl.DateTimeFormat("en-GB",{...i,weekday:"short"}).format(r)} ${l}`}function BU({focus:e,timezone:t,onSwitch:s}){return n.jsxs(uO,{children:[n.jsxs(dO,{className:"ui-menu-item rail-owner-focus",children:[n.jsx("span",{children:"Focus"}),n.jsx("span",{className:"rail-owner-kbd",children:e?_l[e.mode]:"Off"})]}),n.jsx(Wo,{children:n.jsxs(hO,{className:"ui-menu rail-owner-menu",sideOffset:6,children:[n.jsx("p",{className:"ui-menu-empty",role:"status",children:e?`${_l[e.mode]} ${EC(e,t)}${e.by==="schedule"?", from a schedule":""}.`:"No focus is on."}),["do-not-disturb","urgent-only"].map(r=>n.jsxs(FN,{children:[n.jsx(Mr,{className:"ui-menu-sep"}),n.jsx(Yd,{className:"ui-menu-label",children:_l[r]}),UU.map(i=>n.jsx(Ei,{className:"ui-menu-item","aria-label":`${_l[r]} ${i.label.toLowerCase()}`,onSelect:()=>s(r,i.value),children:i.label},i.value))]},r)),e?n.jsxs(n.Fragment,{children:[n.jsx(Mr,{className:"ui-menu-sep"}),n.jsx(Ei,{className:"ui-menu-item",onSelect:()=>s("normal"),children:"Turn off"})]}):null]})})]})}function WU(){const e=window.navigator.userAgent;return/iPhone|iPad|Android|Mobile/.test(e)?null:/Mac/.test(e)?"⌘R":"Ctrl+R"}function vf({label:e,href:t,active:s,badge:r,dot:i,onClick:a,children:l}){return n.jsxs("a",{className:"rail-link",href:t,"data-active":s?"true":void 0,"aria-current":s?"page":void 0,"aria-label":r>0?`${e}, ${r} waiting`:i?`${e}, ${i}`:e,onClick:o=>{o.preventDefault(),a()},children:[n.jsxs("span",{className:"rail-icon",children:[l,r>0?n.jsx("span",{className:"rail-badge","aria-hidden":"true",children:r>99?"99+":r}):null,r===0&&i?n.jsx("span",{className:"ui-badge rail-dot","data-kind":"dot","data-testid":"rail-dot","aria-hidden":"true"}):null]}),n.jsx("span",{className:"rail-label",children:e})]})}const Wy={[_i]:n.jsx(we,{name:"files"}),[Kt]:n.jsx(we,{name:"home"}),[Vr]:n.jsx(we,{name:"chat"}),[mt]:n.jsx(we,{name:"agents"}),[St]:n.jsx(we,{name:"activity"}),[dn]:n.jsx(we,{name:"settings"})},Io=e=>`${e.plugin}:${e.id}`,HU=new Set;let sv=HU,Hy=!1;const Np=new Set;function Cp(e){sv=e;for(const t of Np)t()}function KU(e){return Np.add(e),()=>Np.delete(e)}const Ky=()=>sv;function VU(){Hy||(Hy=!0,Promise.resolve().then(()=>T.rail()).then(e=>Cp(new Set(Array.isArray(e==null?void 0:e.hidden)?e.hidden.filter(t=>typeof t=="string"):[]))).catch(()=>{}))}async function GU(e,t){const s=sv,r=new Set(s);t?r.add(Io(e)):r.delete(Io(e)),Cp(r);try{await T.setRailHidden(e.plugin,e.id,t)}catch(i){throw Cp(s),i}}function AC(){return f.useEffect(VU,[]),f.useSyncExternalStore(KU,Ky,Ky)}function YU(e,t){return e.filter(s=>!t.has(Io(s)))}function qU(e){return e instanceof HTMLElement?e.isContentEditable?!0:e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.tagName==="SELECT":!1}function QU(e,t=!0,s){f.useEffect(()=>{if(!t)return;const r=i=>{if(i.key!=="/"||i.defaultPrevented||i.ctrlKey||i.metaKey||i.altKey||qU(i.target))return;i.preventDefault();const a=document.getElementById(xp);if(a instanceof HTMLTextAreaElement){!a.disabled&&!a.hidden&&a.focus();return}s?s():e(Kt)};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t,s])}const TC="buddi.theme";function JU(e=RC()){try{const t=e==null?void 0:e.getItem(TC);return t==="light"||t==="dark"||t==="system"?t:"system"}catch{return"system"}}function XU(e,t=RC()){try{t==null||t.setItem(TC,e)}catch{}}function ZU(e,t=document.documentElement){t&&(e==="system"?t.removeAttribute("data-theme"):t.setAttribute("data-theme",e))}function RC(){try{return window.localStorage}catch{return}}const IC="buddi.ground",PC="buddi.pageWidth";function e6(e=OC()){const t=i=>{try{return(e==null?void 0:e.getItem(i))??null}catch{return null}},s=t(IC),r=t(PC);return{theme:JU(e),ground:s==="sand"?"sand":"blue",width:r==="narrow"||r==="full"?r:"wide"}}function $C(e,t=document.documentElement){t&&(ZU(e.theme,t),e.ground==="sand"?t.setAttribute("data-ground","sand"):t.removeAttribute("data-ground"),e.width==="wide"?t.removeAttribute("data-width"):t.setAttribute("data-width",e.width))}function t6(e,t=OC()){XU(e.theme,t);try{t==null||t.setItem(IC,e.ground),t==null||t.setItem(PC,e.width)}catch{}}let $a=null;const Ep=new Set;function Ap(){return $a||($a=e6()),$a}function n6(e){return Ep.add(e),()=>Ep.delete(e)}function s6(e){$a={...Ap(),...e},$C($a),t6($a);for(const t of Ep)t()}function MC(){return[f.useSyncExternalStore(n6,Ap,Ap),s6]}function OC(){try{return window.localStorage}catch{return}}function r6({timezone:e,embedded:t}){var m,p;const{data:s,error:r,reload:i}=le(()=>T.sentinels(),[],3e4),a=le(()=>T.missions(),[]),[l,o]=f.useState(null),c=((p=(m=a.data)==null?void 0:m.missions.find(x=>x.id==="sentinel-wake"))==null?void 0:p.agentId)??null,u=async(x,j)=>{o(null);try{await T.snoozeAlert(x,j),i()}catch(b){o(b instanceof Error?b.message:String(b))}},h=((s==null?void 0:s.open)??[]).filter(x=>!x.snoozedAt),d=((s==null?void 0:s.open)??[]).filter(x=>x.snoozedAt);return n.jsxs(yn,{embedded:t,title:"Alerts",lede:"What the watchers found.",children:[n.jsx(se,{message:r??l}),n.jsx(H,{children:"An alert closes on its own once the fact behind it changes: record the payment, update the balance, and the watcher clears it on its next run. Snooze one you have decided to live with; it stays quiet until it resolves."}),n.jsx(jf,{title:"Open",findings:h,timezone:e,askAgentId:c,onSnooze:x=>u(x,!0),empty:"Nothing open. Your watchers are quiet."}),d.length>0?n.jsx(jf,{title:"Snoozed",findings:d,timezone:e,askAgentId:c,onSnooze:x=>u(x,!1),empty:""}):null,n.jsx(jf,{title:"Resolved",findings:(s==null?void 0:s.resolved)??[],timezone:e,empty:"Nothing has resolved yet."}),n.jsx(qe,{title:"Waiting for the weekly recap",flush:!0,children:!s||s.digest.length===0?n.jsx(tn,{icon:"bell",title:"Nothing waiting for the recap"}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Title"}),n.jsx("th",{children:"Severity"}),n.jsx("th",{children:"Noted"})]})}),n.jsx("tbody",{children:s.digest.map(x=>n.jsxs("tr",{children:[n.jsxs("td",{children:[Ba(x.title),n.jsx(_C,{text:Ba(x.detail)})]}),n.jsx("td",{children:n.jsx(DC,{severity:x.severity})}),n.jsx("td",{className:"nowrap",children:Be(x.createdAt,e)})]},x.id))})]})})]})}function DC({severity:e}){return n.jsx(ge,{tone:e==="urgent"?"critical":void 0,children:e})}function _C({text:e}){const[t,s]=f.useState(!1),r=e.length>240||e.split(`
107
- `).length>3;return n.jsxs("div",{className:"sub alert-detail","data-clamp":r&&!t?"true":void 0,children:[e,r?n.jsx("button",{type:"button",className:"wb-link alert-more",onClick:()=>s(i=>!i),children:t?"Less":"More"}):null]})}function i6(e){return`About this alert: "${Ba(e.title)}". ${Ba(e.detail)}
108
-
109
- What should I do about it, and what do you need from me to clear it?`}function jf({title:e,findings:t,timezone:s,askAgentId:r,onSnooze:i,empty:a}){const l=e==="Snoozed";return n.jsx(qe,{title:e,flush:!0,children:t.length===0?n.jsx(oe,{children:a}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Finding"}),n.jsx("th",{children:"Severity"}),n.jsx("th",{children:"Since"}),i?n.jsx("th",{}):null]})}),n.jsx("tbody",{children:t.map(o=>n.jsxs("tr",{children:[n.jsxs("td",{children:[n.jsx("strong",{children:Ba(o.title)}),n.jsx(_C,{text:Ba(o.detail)}),o.data?n.jsx($t,{summary:"evidence",children:n.jsx(xt,{children:In(o.data)})}):null]}),n.jsx("td",{children:n.jsx(DC,{severity:o.severity})}),n.jsxs("td",{className:"nowrap",children:[Be(o.firstSeenAt,s),n.jsxs("div",{className:"sub",title:Be(o.lastSeenAt,s),children:["last seen ",Fe(o.lastSeenAt)]})]}),i?n.jsx("td",{children:n.jsxs(Q,{align:"end",children:[r?n.jsx(Zt,{size:"sm",href:Ve(r,"new"),onClick:()=>J3(r,i6(o)),children:"Ask about it"}):null,n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>i(o.key),children:l?"Wake":"Snooze"})]})}):null]},o.key))})]})})}const Vy=5e3,Gy=50;function a6({timezone:e,embedded:t}){var g;const[s,r]=f.useState(""),[i,a]=f.useState(""),[l,o]=f.useState(null),c=le(()=>T.eventKinds(),[]),{data:u,error:h}=le(()=>T.events({kind:s||void 0,q:i||void 0,limit:Gy}),[s,i],Vy),[d,m]=f.useState({events:[],cursor:null,busy:!1,error:null});f.useEffect(()=>{m({events:[],cursor:null,busy:!1,error:null})},[s,i]);const p=d.events.length>0?d.cursor:(u==null?void 0:u.nextCursor)??null,x=async()=>{if(p){m(v=>({...v,busy:!0,error:null}));try{const v=await T.events({kind:s||void 0,q:i||void 0,before:p,limit:Gy});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)}))}}},j=new Set(((u==null?void 0:u.events)??[]).map(v=>v.id)),b=[...(u==null?void 0:u.events)??[],...d.events.filter(v=>!j.has(v.id))];return n.jsxs(yn,{embedded:t,title:"Events",lede:"The append-only log. Everything the installation did, including what you do here.",children:[n.jsxs(Q,{children:[n.jsxs("select",{"aria-label":"Event kind",value:s,onChange:v=>r(v.target.value),children:[n.jsx("option",{value:"",children:"every kind"}),(((g=c.data)==null?void 0:g.kinds)??[]).map(v=>n.jsxs("option",{value:v.kind,children:[v.kind," (",v.count,")"]},v.kind))]}),n.jsx("input",{"aria-label":"Payload contains",placeholder:"payload contains…",value:i,onChange:v=>a(v.target.value),size:28}),s||i?n.jsx(R,{onClick:()=>{r(""),a("")},children:"Clear"}):null,n.jsxs("span",{className:"muted",children:["refreshes every ",Vy/1e3,"s"]})]}),n.jsx(se,{message:h}),n.jsx(qe,{flush:!0,children:!u||b.length===0?n.jsx(oe,{children:"No events match."}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"#"}),n.jsx("th",{children:"When"}),n.jsx("th",{children:"Kind"}),n.jsx("th",{children:"Payload"})]})}),n.jsx("tbody",{children:b.map(v=>n.jsxs("tr",{"data-clickable":"true",onClick:()=>o(v),children:[n.jsx("td",{className:"mono muted",children:v.id}),n.jsxs("td",{className:"nowrap",children:[Be(v.createdAt,e),n.jsx("div",{className:"sub",children:Fe(v.createdAt)})]}),n.jsx("td",{className:"mono nowrap",children:v.kind}),n.jsx("td",{className:"mono muted",children:Ks(In(v.payload).replace(/\s+/g," "),120)})]},v.id))})]})}),p||d.error?n.jsxs(Q,{children:[n.jsxs("span",{className:"muted",children:[b.length," shown",p?", older ones are kept":"","."]}),n.jsx("span",{className:"ui-toolbar-spacer"}),d.error?n.jsx("span",{className:"critical",children:d.error}):null,p?n.jsx(R,{disabled:d.busy,onClick:()=>void x(),children:d.busy?"Loading…":"Load older"}):null]}):null,l?n.jsxs(wt,{title:l.kind,onClose:()=>o(null),children:[n.jsxs("p",{className:"muted",children:["Event ",l.id," · ",Be(l.createdAt,e),l.conversationId?n.jsxs(n.Fragment,{children:[" · ",n.jsx("a",{href:`#/conversations/${l.conversationId}`,children:"conversation"})]}):null]}),n.jsx(xt,{children:In(l.payload)})]}):null]})}const l6=["pending","leased","suspended","failed","succeeded","cancelled"],Il=50;function o6({timezone:e,embedded:t,initialState:s}){const[r,i]=f.useState(s??""),[a,l]=f.useState(null),[o,c]=f.useState(null),{data:u,error:h,reload:d}=le(()=>T.jobs({...r?{state:r}:{},limit:String(Il)}),[r],1e4),[m,p]=f.useState({jobs:[],done:!1,busy:!1});f.useEffect(()=>{p({jobs:[],done:!1,busy:!1})},[r]);const x=async()=>{p(S=>({...S,busy:!0}));try{const S=await T.jobs({...r?{state:r}:{},limit:String(Il),offset:String(Il+m.jobs.length)});p(C=>({jobs:[...C.jobs,...S.jobs],done:S.jobs.length<Il,busy:!1}))}catch(S){c(S instanceof Error?S.message:String(S)),p(C=>({...C,busy:!1}))}},j=new Set(((u==null?void 0:u.jobs)??[]).map(S=>S.id)),b=[...(u==null?void 0:u.jobs)??[],...m.jobs.filter(S=>!j.has(S.id))],g=r?(u==null?void 0:u.counts[r])??0:Object.values((u==null?void 0:u.counts)??{}).reduce((S,C)=>S+C,0),v=!m.done&&b.length<g&&((u==null?void 0:u.jobs.length)??0)>=Il,[w,y]=f.useState(null),N=async S=>{c(null),y(S);try{const C=(await T.jobs({state:"failed",limit:"500"})).jobs;for(const I of C)await(S==="retry"?T.retryJob(I.id):T.cancelJob(I.id));d()}catch(C){c(C instanceof Error?C.message:String(C))}finally{y(null)}},k=async S=>{c(null);try{await S,l(null),d()}catch(C){c(C instanceof Error?C.message:String(C))}};return n.jsxs(yn,{embedded:t,title:"Jobs",lede:`${u!=null&&u.paused?"Paused: nothing is being claimed. ":""}Bounded retries with backoff; past the budget a job waits for you.`,actions:t?void 0:n.jsx(R,{size:"sm",variant:u!=null&&u.paused?"accent":void 0,onClick:()=>k(T.setPaused(!((u==null?void 0:u.paused)??!1))),children:u!=null&&u.paused?"Resume the queue":"Pause the queue"}),children:[n.jsxs(Q,{children:[n.jsxs("select",{"aria-label":"Job state",value:r,onChange:S=>i(S.target.value),children:[n.jsx("option",{value:"",children:"every state"}),l6.map(S=>n.jsxs("option",{value:S,children:[S," (",(u==null?void 0:u.counts[S])??0,")"]},S))]}),((u==null?void 0:u.counts.failed)??0)>0?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsxs("span",{className:"muted",children:[u.counts.failed," failed."]}),n.jsx(R,{size:"sm",disabled:w!==null,onClick:()=>void N("retry"),children:w==="retry"?"Retrying…":"Retry all failed"}),n.jsx(R,{size:"sm",variant:"danger",disabled:w!==null,onClick:()=>void N("cancel"),children:w==="cancel"?"Cancelling…":"Cancel all failed"})]}):null]}),n.jsx(se,{message:h??o}),n.jsx(qe,{flush:!0,children:!u||b.length===0?n.jsx(oe,{children:"No jobs match."}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Kind"}),n.jsx("th",{children:"State"}),n.jsx("th",{className:"num",children:"Attempts"}),n.jsx("th",{children:"Last error"}),n.jsx("th",{children:"Updated"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:b.map(S=>n.jsxs("tr",{children:[n.jsxs("td",{className:"clickable",onClick:()=>l(S),children:[S.kind,n.jsx("div",{className:"sub mono",children:No(S.id)})]}),n.jsxs("td",{children:[n.jsx(Vo,{state:S.state}),S.suspendedReason?n.jsx("div",{className:"sub",children:Ks(S.suspendedReason,40)}):null]}),n.jsxs("td",{className:"num",children:[S.attempts,"/",S.maxAttempts]}),n.jsx("td",{className:S.lastError?"critical":"muted",children:S.lastError?Ks(S.lastError,80):"—"}),n.jsxs("td",{className:"nowrap",children:[Be(S.updatedAt,e),n.jsx("div",{className:"sub",children:Fe(S.updatedAt)})]}),n.jsx("td",{children:n.jsxs(Q,{align:"end",children:[["failed","cancelled","suspended"].includes(S.state)?n.jsx(R,{size:"sm",onClick:()=>k(T.retryJob(S.id)),children:"Retry"}):null,["pending","leased","suspended","failed"].includes(S.state)?n.jsx(R,{size:"sm",variant:"danger",onClick:()=>k(T.cancelJob(S.id)),children:"Cancel"}):null]})})]},S.id))})]})}),v?n.jsxs(Q,{children:[n.jsxs("span",{className:"muted",children:[b.length," of ",g," shown."]}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(R,{disabled:m.busy,onClick:()=>void x(),children:m.busy?"Loading…":"Load older"})]}):null,a?n.jsxs(wt,{title:a.kind,onClose:()=>l(null),children:[n.jsx("p",{className:"muted mono",children:a.id}),n.jsx(te,{title:"Payload",children:n.jsx(xt,{children:In(a.payload)})}),n.jsx(te,{title:"Result",children:n.jsx(xt,{children:In(a.result)})}),a.conversationId?n.jsx("p",{children:n.jsx("a",{href:`#/conversations/${a.conversationId}`,children:"open the transcript"})}):null]}):null]})}const c6=[{id:"conversations",label:"Conversations"},{id:"jobs",label:"Jobs"},{id:"approvals",label:"Approvals"},{id:"alerts",label:"Alerts"},{id:"events",label:"Events"}];function u6({hash:e,timezone:t,navigate:s,agents:r}){var u,h;const i=/^#\/activity\/conversations\/(.+)$/.exec(e),a=d=>{var m;return((m=r.find(p=>p.id===d))==null?void 0:m.name)??d};if(i){let d=i[1];try{d=decodeURIComponent(d)}catch{}return n.jsx(f6,{id:d,timezone:t,navigate:s,nameOf:a})}const l=((u=/^#\/activity\/([a-z]+)/.exec(e))==null?void 0:u[1])??"conversations",o=(h=/[?&]state=([a-z]+)/.exec(e))==null?void 0:h[1],c=d=>m=>{m.preventDefault(),s(d)};return n.jsxs("div",{className:"ui-page",children:[n.jsx(Zd,{title:"Activity",lede:"Everything your agents ran, newest first.",actions:n.jsx(g6,{})}),n.jsx(x6,{}),n.jsx(Go,{children:c6.map(d=>{const m=d.id==="conversations"?St:`${St}/${d.id}`;return n.jsx(Ha,{href:m,active:l===d.id,onClick:c(m),children:d.label},d.id)})}),l==="conversations"?n.jsx(d6,{timezone:t,navigate:s,nameOf:a,agents:r}):null,l==="jobs"?n.jsx(o6,{timezone:t,embedded:!0,initialState:o},o??""):null,l==="approvals"?n.jsx(h6,{timezone:t,nameOf:a}):null,l==="alerts"?n.jsx(r6,{timezone:t,embedded:!0}):null,l==="events"?n.jsx(a6,{timezone:t,embedded:!0}):null]})}function d6({timezone:e,navigate:t,nameOf:s,agents:r}){const{data:i,error:a}=le(()=>T.conversations(),[],3e4);return n.jsxs(n.Fragment,{children:[n.jsx(se,{message:a}),n.jsx(qe,{flush:!0,children:i?i.conversations.length===0?n.jsx(tn,{icon:"activity",title:"Nothing has run yet",children:"Conversations and runs show up here as your agents work."}):n.jsx(At,{children:i.conversations.map(l=>n.jsx(Tt,{href:Wa(l.id),onClick:()=>t(Wa(l.id)),lead:n.jsx(Nn,{agents:r,id:l.agentId,size:"sm"}),title:l.opening?Ks(l.opening,100):"Untitled conversation",sub:`${s(l.agentId)}, ${l.messageCount} message${l.messageCount===1?"":"s"}, ${l.runs} run${l.runs===1?"":"s"}, ${TO(l.usage)}`,side:n.jsx("span",{title:Be(l.lastMessageAt??l.createdAt,e),children:Fe(l.lastMessageAt??l.createdAt)})},l.id))}):n.jsx(oe,{children:"Loading…"})})]})}function h6({timezone:e,nameOf:t}){const{data:s,error:r}=le(()=>T.approvals(),[],1e4),i=[...(s==null?void 0:s.pending)??[],...(s==null?void 0:s.recent)??[]];return n.jsxs(n.Fragment,{children:[n.jsx(se,{message:r}),n.jsx(qe,{flush:!0,children:s?i.length===0?n.jsx(tn,{icon:"bell",title:"No approvals yet",children:"When an agent asks before acting, the request and your answer are kept here."}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Tool"}),n.jsx("th",{children:"State"}),n.jsx("th",{children:"Asked by"}),n.jsx("th",{children:"Decided"}),n.jsx("th",{children:"Created"})]})}),n.jsx("tbody",{children:i.map(a=>n.jsxs("tr",{children:[n.jsxs("td",{children:[a.tool,n.jsx("div",{className:"sub mono",children:No(a.id)})]}),n.jsx("td",{children:n.jsx(Vo,{state:a.state})}),n.jsx("td",{children:t(a.agentId)}),n.jsx("td",{className:"nowrap",children:a.decidedAt?n.jsxs(n.Fragment,{children:[Be(a.decidedAt,e),n.jsxs("div",{className:"sub",children:["via ",a.decidedVia??"—"]})]}):n.jsx("span",{className:"muted",children:"—"})}),n.jsxs("td",{className:"nowrap",children:[Be(a.createdAt,e),n.jsx("div",{className:"sub",children:Fe(a.createdAt)})]})]},a.id))})]}):n.jsx(oe,{children:"Loading…"})})]})}function f6({id:e,timezone:t,navigate:s,nameOf:r}){const[i,a]=f.useState(null),[l,o]=f.useState(null);f.useEffect(()=>{let u=!1;return T.conversation(e).then(h=>{u||a(h)}).catch(h=>{u||o(h instanceof Error?h.message:String(h))}),()=>{u=!0}},[e]);const c=u=>h=>{h.preventDefault(),s(u)};return n.jsxs("div",{className:"ui-page",children:[n.jsx("p",{className:"page-crumbs",children:n.jsx("a",{href:St,onClick:c(St),children:"Activity"})}),n.jsxs("header",{className:"ui-page-head",children:[n.jsxs("div",{className:"ui-page-head-row",children:[n.jsxs("h2",{className:"ui-page-title",children:[n.jsx(R,{size:"sm",onClick:()=>s(St),children:"← Back"}),n.jsx("span",{children:"Transcript"})]}),i?n.jsx("div",{className:"ui-page-actions",children:n.jsx(Zt,{size:"sm",href:Ve(i.agentId,e),onClick:c(Ve(i.agentId,e)),children:"Open in chat"})}):null]}),n.jsx("p",{className:"ui-page-lede mono",children:e})]}),n.jsx(se,{message:l}),i?n.jsxs(n.Fragment,{children:[n.jsxs(eh,{children:[n.jsx(Fs,{label:"Agent",value:r(i.agentId),size:"sm"}),n.jsx(Fs,{label:"Runs",value:i.runs.length}),n.jsx(Fs,{label:"Tokens",value:`${_t(i.usage.input)} / ${_t(i.usage.output)}`,note:Vm(i.usage)?`input / output, ${Vm(i.usage)}`:"input / output"}),n.jsx(Fs,{label:"Started",value:Be(i.createdAt,t),size:"sm"})]}),i.runs.length>0?n.jsx(qe,{title:"Runs",flush:!0,children:n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Started"}),n.jsx("th",{children:"Finished"}),n.jsx("th",{className:"num",children:"Turns"}),n.jsx("th",{children:"Stopped"}),n.jsx("th",{className:"num",children:"Tokens"}),n.jsx("th",{className:"num",children:"Cached"})]})}),n.jsx("tbody",{children:i.runs.map((u,h)=>n.jsxs("tr",{children:[n.jsxs("td",{className:"nowrap",children:[Be(u.startedAt,t)," ",u.resumed?n.jsx(ge,{children:"resumed"}):null]}),n.jsx("td",{className:"nowrap",children:Be(u.finishedAt,t)}),n.jsx("td",{className:"num",children:u.turns??"—"}),n.jsxs("td",{children:[u.stopped??"—",u.actionId?n.jsxs("div",{className:"sub mono",children:["action ",No(u.actionId)]}):null]}),n.jsxs("td",{className:"num muted nowrap",children:[_t(u.usage.input)," / ",_t(u.usage.output)]}),n.jsx("td",{className:"num muted nowrap",children:u.usage.cacheRead||u.usage.cacheWrite?_t((u.usage.cacheRead??0)+(u.usage.cacheWrite??0)):"—"})]},h))})]})}):null,n.jsx(te,{title:"Messages",children:n.jsx(J,{children:i.messages.map(u=>n.jsxs("article",{className:"transcript-msg",children:[n.jsxs("header",{className:"transcript-who",children:[u.speaker===Yy?"approved action, result":u.role,", ",Be(u.createdAt,t)]}),n.jsxs("div",{className:"transcript-body",children:[u.blocks.length===0?n.jsx("span",{className:"muted",children:"(empty)"}):null,u.speaker===Yy?u.blocks.map((h,d)=>n.jsx(m6,{block:h},d)):u.blocks.map((h,d)=>n.jsx(p6,{block:h},d))]})]},u.id))})})]}):n.jsx(oe,{children:"Loading…"})]})}const Yy="approval:resume";function m6({block:e}){return n.jsxs("div",{className:"transcript-tool",children:[n.jsx("div",{className:"transcript-tool-name mono",children:"← approved action"}),n.jsx(xt,{children:e.type==="text"?e.text??"":In(e)})]})}function p6({block:e}){return e.type==="text"?n.jsx("div",{className:"transcript-text",children:n.jsx(mr,{text:e.text??""})}):e.type==="thinking"?n.jsxs("details",{className:"transcript-thinking",children:[n.jsx("summary",{children:"Thoughts"}),n.jsx("div",{className:"transcript-thinking-text",children:n.jsx(mr,{text:e.text??""})})]}):e.type==="tool_use"?n.jsxs("div",{className:"transcript-tool",children:[n.jsxs("div",{className:"transcript-tool-name mono",children:["→ ",e.name]}),n.jsx(xt,{children:In(e.input)})]}):e.type==="tool_result"?n.jsxs("div",{className:"transcript-tool","data-tone":e.isError?"critical":void 0,children:[n.jsxs("div",{className:"transcript-tool-name mono",children:["← ",e.isError?"error":"result"]}),n.jsx(xt,{children:e.content??""})]}):n.jsxs("div",{className:"transcript-tool",children:[n.jsx("div",{className:"transcript-tool-name mono",children:e.type}),n.jsx(xt,{children:In(e.ref)})]})}function g6(){const{data:e,reload:t}=le(()=>T.overview(),[],1e4),[s,r]=f.useState(!1);if(!e)return null;const i=()=>{r(!0),T.setPaused(!e.paused).then(t,t).finally(()=>r(!1))};return n.jsx(R,{size:"sm",variant:e.paused?"accent":void 0,disabled:s,onClick:i,children:e.paused?"Resume all":"Pause all"})}function x6(){const{data:e}=le(()=>T.overview(),[],1e4);if(!e)return null;const t=r=>e.jobs[r]??0,s=t("leased");return n.jsxs(eh,{children:[n.jsx(Fs,{label:"Jobs done",value:_t(t("succeeded"))}),n.jsx(Fs,{label:"Failed",value:_t(t("failed")),...t("failed")>0?{tone:"critical"}:{}}),n.jsx(Fs,{label:"Queued",value:_t(t("pending")),note:`${s} running`}),n.jsx(Fs,{label:"Approvals",value:_t(e.approvals.pending),note:"waiting for you"})]})}const v6=["replay-all","coalesce","latest-only","skip-after-deadline"];function LC({timezone:e,embedded:t,agentId:s}){const{data:r,error:i,reload:a}=le(()=>T.missions(),[],3e4),l=((r==null?void 0:r.missions)??[]).filter(h=>!s||h.agentId===s),[o,c]=f.useState(null),u=async h=>{c(null);try{await h,a()}catch(d){c(d instanceof Error?d.message:String(d))}};return n.jsxs(yn,{embedded:t,title:"Missions",lede:"Standing schedules. A disabled mission materializes nothing.",children:[n.jsx(se,{message:i??o}),!r||l.length===0?n.jsxs(tn,{icon:"calendar",title:"No missions yet",children:["Run ",n.jsx("code",{children:"buddi missions add-defaults"})," for the standard set."]}):n.jsx(J,{children:l.map(h=>n.jsx(j6,{mission:h,timezone:e,onRun:u},h.id))})]})}function j6({mission:e,timezone:t,onRun:s}){const[r,i]=f.useState(!1);return n.jsxs(ks,{tone:e.enabled&&!e.pausedReason?"good":"muted",title:n.jsxs(n.Fragment,{children:[e.name," ",n.jsx("span",{className:"mono muted",children:e.id})]}),meta:n.jsxs(n.Fragment,{children:[n.jsx(ge,{mono:!0,children:e.agentId}),e.alwaysDeliver?n.jsx(ge,{children:"always delivers"}):null,e.enabled?null:n.jsx(ge,{tone:"warning",children:"disabled"}),e.pausedReason?n.jsx(ge,{tone:"warning",children:e.pausedReason}):null]}),actions:n.jsxs(n.Fragment,{children:[n.jsx(R,{size:"sm",onClick:()=>s(T.setMissionEnabled(e.id,!e.enabled)),children:e.enabled?"Disable":"Enable"}),n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>i(a=>!a),"aria-expanded":r,children:r?"Less":"More"})]}),children:[n.jsxs("p",{className:"ui-card-meta",children:[e.schedule?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"mono",children:e.schedule.cron})," ",e.schedule.timezone," · rev"," ",e.schedule.revision," · next"," ",e.nextRun?`${Be(e.nextRun,t)} (${Fe(e.nextRun)})`:"—"]}):"no schedule — enqueued by hand or by a sentinel",n.jsx("br",{}),"Last notification:"," ",e.lastNotification?`${e.lastNotification.kind==="mission.delivered"?"delivered":"silent"} ${Fe(e.lastNotification.at)}${e.lastNotification.reason?` — ${e.lastNotification.reason}`:""}`:"none"]}),r?n.jsxs("div",{className:"ui-card-foot",children:[e.schedule?n.jsxs(Q,{children:[n.jsx(ee,{inline:!0,label:"Misfire policy",children:n.jsx("select",{value:e.schedule.misfirePolicy,onChange:a=>s(T.setMisfirePolicy(e.id,a.target.value)),children:v6.map(a=>n.jsx("option",{value:a,children:a},a))})}),n.jsx("span",{className:"muted",children:"What a week asleep does: replay every instant, coalesce into one, keep only the latest, or skip past a deadline."})]}):null,n.jsx(te,{title:"Prompt",children:n.jsx(xt,{children:e.prompt})}),n.jsx(te,{title:"Recent occurrences",children:n.jsx(qe,{flush:!0,children:e.occurrences.length===0?n.jsx(oe,{children:"Never run."}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Scheduled"}),n.jsx("th",{children:"State"}),n.jsx("th",{children:"Finished"}),n.jsx("th",{children:"Detail"})]})}),n.jsx("tbody",{children:e.occurrences.map(a=>n.jsxs("tr",{children:[n.jsx("td",{className:"nowrap",children:Be(a.scheduledAt,t)}),n.jsx("td",{children:n.jsx(Vo,{state:a.state})}),n.jsx("td",{className:"nowrap",children:Be(a.finishedAt,t)}),n.jsxs("td",{className:a.error?"critical":"muted",children:[a.error?Ks(a.error,120):null,a.runConversationId?n.jsx("a",{href:`#/conversations/${a.runConversationId}`,children:"transcript"}):null]})]},a.id))})]})})})]}):null]})}function w6(e,t){const s=`${e} offer${e===1?"":"s"}`,r=t?` from ${t}`:"";return`Dismiss ${s}${r}? They stop appearing everywhere. Nothing runs, and you can still see them under "Dismissed and lapsed" for a week.`}function FC({ids:e,agentName:t,onDone:s}){const r=e.length,[i,a]=f.useState(!1),[l,o]=f.useState(!1);return r<=0?null:i?n.jsxs("span",{className:"ui-row",children:[n.jsx("span",{className:"muted",children:w6(r,t)}),n.jsx(R,{size:"sm",variant:"danger",disabled:l,onClick:()=>{o(!0),T.dismissOffers(e).then(()=>{a(!1),s()}).finally(()=>o(!1))},children:`Dismiss ${r}`}),n.jsx(R,{size:"sm",variant:"ghost",disabled:l,onClick:()=>a(!1),children:"Keep them"})]}):n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>a(!0),children:"Dismiss all"})}function zC({embedded:e,agentId:t,agentName:s}){const{data:r,error:i,reload:a}=le(()=>T.offers(),[],2e4),l=g=>!t||g.agentId===t,o=((r==null?void 0:r.offers)??[]).filter(l),c=((r==null?void 0:r.closed)??[]).filter(l),[u,h]=f.useState(null),[d,m]=f.useState(null),[p,x]=f.useState(null),j=async(g,v)=>{h(null),m(g);try{const w=await T.takeOffer(g);x(w.jobId?`On it — ${v}. Started as job ${w.jobId}.`:`Taken — ${v}. No worker is running here, so nothing has started yet.`),a()}catch(w){h(w instanceof Error?w.message:String(w))}finally{m(null)}},b=async(g,v)=>{h(null),m(g);try{await T.dismissOffer(g),x(`Dismissed — ${v}. It will not come back.`),a()}catch(w){h(w instanceof Error?w.message:String(w))}finally{m(null)}};return n.jsxs(yn,{embedded:e,title:"Offers",lede:"Things an agent already worked out that you might want done. Taking one asks that agent the sentence it wrote. It authorizes nothing, and anything that would leave this machine still comes back to you as an approval.",children:[n.jsx(se,{message:i??u}),p?n.jsx(H,{tone:"good",role:"status",children:p}):null,o.length>0?n.jsxs(Q,{children:[n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(FC,{ids:o.map(g=>g.id),agentName:s,onDone:()=>{x(null),a()}})]}):null,!r||o.length===0?n.jsx(tn,{icon:"bulb",title:"Nothing on offer",children:"When an agent works out something you might want done, it waits here."}):n.jsx(J,{children:o.map(g=>n.jsx(ks,{tone:"accent",title:g.label,meta:n.jsxs(n.Fragment,{children:[n.jsx(ge,{mono:!0,children:g.agentId}),n.jsxs("span",{className:"muted",children:["expires ",Fe(g.expiresAt)]})]}),actions:n.jsxs(n.Fragment,{children:[n.jsx(R,{size:"sm",variant:"ghost",disabled:d===g.id,onClick:()=>void b(g.id,g.label),children:"Not now"}),n.jsx(R,{variant:"accent",size:"sm",disabled:d===g.id,onClick:()=>void j(g.id,g.label),children:"Take"})]}),children:n.jsx("p",{className:"ui-card-meta",children:g.prompt})},g.id))}),c.length>0?n.jsxs($t,{summary:`Dismissed and lapsed (${c.length})`,boxed:!0,children:[n.jsx(qe,{flush:!0,children:n.jsx(At,{children:c.map(g=>n.jsx(Tt,{title:g.label,sub:`${g.agentId} — ${G2(g)}`,side:Fe(g.dismissedAt??g.lapsedAt??g.createdAt)},g.id))})}),n.jsx("p",{className:"muted",children:"These stop being shown a week after they closed."})]}):null]})}const y6="Add a teammate",b6="Each one keeps its own memory and tools, and can work on a schedule. Add the ones you want; Agent Father can make others.",k6="front-desk";function UC(e,t){return e.length>0&&e.every(s=>s.id===t||s.roles.includes(k6)||s.roles.includes(Jd))}const S6={plugins:{label:"Plugins",route:et("plugins")},mailbox:{label:"Add a mailbox",route:al("email","settings")},accounts:{label:"Accounts",route:et("accounts")}},N6="Your starter team is complete. Agent Father can make others.";function Tp({navigate:e,standing:t=!1}){var h;const s=le(()=>T.teammates(),[]),[r,i]=f.useState(new Set),a=(((h=s.data)==null?void 0:h.teammates)??[]).filter(d=>!r.has(`${d.plugin}/${d.agent}`));if(a.length===0)return null;const l=d=>{i(m=>new Set(m).add(`${d.plugin}/${d.agent}`)),T.dismissAgentOffer(d.plugin,d.agent).then(s.reload,s.reload)},o=d=>m=>{m.preventDefault(),e(d)},c=t?a.filter(d=>d.state!=="added"):a,u=t?a.filter(d=>d.state==="added"):[];return n.jsx(te,{title:y6,children:c.length===0?n.jsx("p",{className:"teammates-lede","data-testid":"teammates-complete",children:N6}):n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"teammates-lede",children:b6}),n.jsx("div",{className:"teammates-grid","data-testid":"teammates",children:c.map(d=>n.jsx(C6,{row:d,navigate:e,onDismiss:()=>l(d)},`${d.plugin}/${d.agent}`))}),u.length>0?n.jsx("ul",{className:"teammates-added","data-testid":"teammates-added",children:u.map(d=>n.jsx("li",{children:n.jsxs("a",{className:"teammates-added-chip",href:pt(d.agent),onClick:o(pt(d.agent)),children:["Added · open @",d.handle]})},`${d.plugin}/${d.agent}`))}):null]})})}function C6({row:e,navigate:t,onDismiss:s}){const r=Kx(e.plugin,e.agent),i=c=>u=>{u.preventDefault(),t(c)},a=r.created??(e.state==="added"?{id:e.agent,handle:e.handle,name:e.name}:null),l=a?"added":e.state,o=e.fix?S6[e.fix]:null;return n.jsx("div",{className:"teammate","data-state":l,"data-testid":`teammate-${e.agent}`,children:n.jsxs(ks,{title:e.name,actions:n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Dismiss ${e.name}`,title:"Not now",onClick:s,children:n.jsx(we,{name:"close"})}),foot:n.jsxs(n.Fragment,{children:[n.jsxs(Q,{children:[l==="unavailable"?n.jsx("span",{className:"teammate-reason",children:e.reason}):null,n.jsx(en,{}),a?n.jsxs("a",{href:pt(a.id),onClick:i(pt(a.id)),children:["Added, open @",a.handle]}):l==="unavailable"?o?n.jsx("a",{href:o.route,onClick:i(o.route),children:o.label}):null:n.jsx(R,{variant:"accent",size:"sm",disabled:r.busy,onClick:r.accept,"aria-label":`Add ${e.name}`,children:"Add"})]}),n.jsx(se,{message:r.failure})]}),children:[n.jsx("p",{className:"ui-card-meta",children:e.text}),n.jsx("p",{className:"teammate-needs",children:e.needs})]})})}const E6=["fact","observation","todo"];function BC({embedded:e,agents:t,timezone:s,agentId:r}){const{data:i,error:a,reload:l}=le(()=>T.memory(r),[r],3e4),[o,c]=f.useState(null),[u,h]=f.useState(null),[d,m]=f.useState(null),p=y=>{var N;return y==="shared"?"Everyone":((N=t.find(k=>k.id===y))==null?void 0:N.name)??y},x=async y=>{m(null);try{await y,l()}catch(N){m(N instanceof pe?N.message:String(N))}},j={nameOf:p,timezone:s,onChangePreference:y=>c({key:y.key,scope:y.scope}),onForgetPreference:y=>void x(T.forgetPreference({key:y.key,scope:y.scope})),onEditNote:y=>h(y),onForgetNote:y=>void x(T.forgetNote(y.id))},b=r?p(r):"",g=r&&i?{preferences:i.preferences.filter(y=>y.scope===r),notes:i.notes.filter(y=>y.scope===r)}:null,v=r&&i?{preferences:i.preferences.filter(y=>y.scope==="shared"),notes:i.notes.filter(y=>y.scope==="shared")}:null,w=n.jsx(R,{variant:"accent",size:"sm",onClick:()=>c({key:"",scope:r??"shared"}),children:"Add a preference"});return n.jsxs(yn,{embedded:e,title:"Memory",lede:"What your agents have kept about you. Correct anything here; they see the change on their next turn.",children:[n.jsx(se,{message:a??d}),g&&v?n.jsxs(J,{gap:"lg",children:[n.jsx(te,{title:"Preferences",aside:`what you told ${b} alone`,actions:w,panel:!0,flush:!0,children:n.jsx(wf,{preferences:g.preferences,empty:`Nothing stated to ${b} alone yet.`,...j})}),n.jsx(te,{title:"Notes",aside:`what ${b} wrote down for itself`,panel:!0,flush:!0,children:n.jsx(yf,{notes:g.notes,empty:`${b} has kept no private notes yet.`,...j})}),n.jsx($t,{summary:`Shared with every agent, which ${b} also reads · ${v.preferences.length} preferences, ${v.notes.length} notes`,children:n.jsxs(J,{gap:"lg",children:[n.jsx(te,{title:"Shared preferences",panel:!0,flush:!0,children:n.jsx(wf,{preferences:v.preferences,empty:"No shared preferences.",...j})}),n.jsx(te,{title:"Shared notes",panel:!0,flush:!0,children:n.jsx(yf,{notes:v.notes,empty:"No shared notes.",...j})})]})})]}):n.jsxs(J,{gap:"lg",children:[n.jsx(te,{title:"Preferences",aside:"what you said you want, one current value each",actions:w,panel:!0,flush:!0,children:i?n.jsx(wf,{preferences:i.preferences,empty:'Nothing stated yet. Tell any agent "from now on…" or add one here.',...j}):n.jsx(oe,{children:"Loading…"})}),n.jsx(te,{title:"Notes",aside:"what an agent wrote down, with who wrote it",panel:!0,flush:!0,children:i?n.jsx(yf,{notes:i.notes,empty:"No notes yet. An agent writes one when you state something durable about your life.",...j}):n.jsx(oe,{children:"Loading…"})})]}),o?n.jsx(A6,{agents:t,existing:(i==null?void 0:i.preferences)??[],initial:o,onClose:()=>c(null),onSave:async y=>{await x((async()=>{await T.setPreference(y),o.key===y.key&&o.scope!==y.scope&&await T.forgetPreference({key:o.key,scope:o.scope})})()),c(null)}}):null,u?n.jsx(T6,{note:u,agents:t,onClose:()=>h(null),onSave:y=>x(T.updateNote(u.id,y)).then(()=>h(null))}):null]})}function wf({preferences:e,empty:t,nameOf:s,onChangePreference:r,onForgetPreference:i}){return e.length===0?n.jsx(oe,{children:t}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Preference"}),n.jsx("th",{children:"Value"}),n.jsx("th",{children:"Who sees it"}),n.jsx("th",{className:"num",children:"Since"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:e.map(a=>n.jsxs("tr",{children:[n.jsx("td",{className:"mono",children:a.key}),n.jsx("td",{children:a.value}),n.jsx("td",{children:n.jsx(WC,{scope:a.scope,name:s(a.scope)})}),n.jsxs("td",{className:"num muted",title:a.updatedAt??"",children:[a.updatedAt?Fe(a.updatedAt,Date.now()):"",a.revision>1?` · rev ${a.revision}`:""]}),n.jsx("td",{className:"num",children:n.jsxs(Q,{align:"end",children:[n.jsx(R,{size:"sm",onClick:()=>r(a),title:"Store a new value for this key",children:"Change"}),n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>i(a),children:"Forget"})]})})]},`${a.scope}:${a.key}`))})]})}function yf({notes:e,empty:t,nameOf:s,timezone:r,onEditNote:i,onForgetNote:a}){return e.length===0?n.jsx(oe,{children:t}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Note"}),n.jsx("th",{children:"Kind"}),n.jsx("th",{children:"Who sees it"}),n.jsx("th",{children:"Written by"}),n.jsx("th",{className:"num",children:"When"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:e.map(l=>n.jsxs("tr",{children:[n.jsx("td",{className:"memory-note",children:l.content}),n.jsx("td",{children:n.jsx(ge,{tone:l.kind==="todo"?"warning":l.kind==="fact"?"good":void 0,children:l.kind})}),n.jsx("td",{children:n.jsx(WC,{scope:l.scope,name:s(l.scope)})}),n.jsx("td",{className:"muted",children:l.createdByAgent?s(l.createdByAgent):""}),n.jsxs("td",{className:"num muted",title:l.createdAt??"",children:[l.createdAt?Fe(l.createdAt,Date.now()):"",l.expiresAt?n.jsxs("span",{className:"memory-expires",children:[" · until ",new Date(l.expiresAt).toLocaleDateString(void 0,{timeZone:r})]}):null]}),n.jsx("td",{className:"num",children:n.jsxs(Q,{align:"end",children:[n.jsx(R,{size:"sm",onClick:()=>i(l),children:"Edit"}),n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>a(l),children:"Forget"})]})})]},l.id))})]})}function WC({scope:e,name:t}){return n.jsx(ge,{tone:e==="shared"?"accent":void 0,title:e==="shared"?"Every agent reads this":`Only ${t} reads this`,children:t})}function HC({value:e,agents:t,onChange:s}){return n.jsxs("select",{value:e,onChange:r=>s(r.target.value),children:[n.jsx("option",{value:"shared",children:"Everyone"}),t.map(r=>n.jsxs("option",{value:r.id,children:["Only ",r.name]},r.id))]})}function A6({agents:e,existing:t,initial:s,onClose:r,onSave:i}){const a=t.find(v=>v.key===s.key&&v.scope===s.scope),[l,o]=f.useState(s.key),[c,u]=f.useState((a==null?void 0:a.value)??""),[h,d]=f.useState(s.scope),[m,p]=f.useState(!1),x=l.trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),j=t.find(v=>v.key===x&&v.scope===h),b=!a||x!==a.key||c.trim()!==a.value||h!==a.scope,g=x!==""&&c.trim()!==""&&b;return n.jsx(wt,{title:"A preference",onClose:r,children:n.jsxs(J,{children:[n.jsx(H,{children:'A preference is a standing choice, in your words: "paid biweekly on Thursdays", "answers short, numbers first". Storing the same key again records a correction and keeps the old value in the history.'}),n.jsx(ee,{label:"Key",hint:x&&x!==l?`Stored as ${x}`:"Short and stable, like reporting_currency or tone.",children:n.jsx("input",{value:l,autoFocus:s.key==="",onChange:v=>o(v.target.value),placeholder:"reporting_currency"})}),n.jsx(ee,{label:"Value",children:n.jsx("textarea",{rows:3,value:c,maxLength:2e3,autoFocus:s.key!=="",onChange:v=>u(v.target.value),placeholder:"EUR"})}),n.jsx(ee,{label:"Who should know",hint:"Shared reaches every agent. Private stays with one.",children:n.jsx(HC,{value:h,agents:e,onChange:d})}),j&&j!==a?n.jsxs(H,{tone:"warning",children:['This replaces the value already stored for this key here, "',j.value,'" (revision ',j.revision,")."]}):null,a&&h!==a.scope?n.jsxs(H,{children:["It moves: the copy for ",a.scope==="shared"?"everyone":"that agent"," is retired and this one takes over."]}):null,n.jsxs(Q,{align:"end",children:[n.jsx(R,{onClick:r,children:"Cancel"}),n.jsx(R,{variant:"accent",disabled:!g||m,onClick:()=>{p(!0),i({key:x,value:c.trim(),scope:h}).finally(()=>p(!1))},children:a?"Save change":"Save"})]})]})})}function T6({note:e,agents:t,onClose:s,onSave:r}){var p;const[i,a]=f.useState(e.content),[l,o]=f.useState(e.scope),[c,u]=f.useState(e.kind),[h,d]=f.useState(!1),m=i.trim()!==e.content||l!==e.scope||c!==e.kind;return n.jsx(wt,{title:"A note",onClose:s,children:n.jsxs(J,{children:[n.jsx(ee,{label:"What it says",hint:"One sentence that makes sense months from now, on its own.",children:n.jsx("textarea",{rows:4,value:i,maxLength:2e3,autoFocus:!0,onChange:x=>a(x.target.value)})}),n.jsxs(bs,{children:[n.jsx(ee,{label:"Kind",children:n.jsx("select",{value:c,onChange:x=>u(x.target.value),children:E6.map(x=>n.jsx("option",{value:x,children:x},x))})}),n.jsx(ee,{label:"Who sees it",children:n.jsx(HC,{value:l,agents:t,onChange:o})})]}),e.createdByAgent?n.jsxs("p",{className:"muted",children:["Written by ",((p=t.find(x=>x.id===e.createdByAgent))==null?void 0:p.name)??e.createdByAgent,e.createdAt?`, ${Fe(e.createdAt,Date.now())}`:"",". Editing keeps that record."]}):null,n.jsxs(Q,{align:"end",children:[n.jsx(R,{onClick:s,children:"Cancel"}),n.jsx(R,{variant:"accent",disabled:!m||i.trim()===""||h,onClick:()=>{d(!0);const x={};i.trim()!==e.content&&(x.content=i.trim()),l!==e.scope&&(x.scope=l),c!==e.kind&&(x.kind=c),r(x).finally(()=>d(!1))},children:"Save"})]})]})})}function R6({agentId:e,agentName:t}){const{data:s,error:r,reload:i}=le(()=>T.agentSkills(e),[e],3e4),[a,l]=f.useState(null),[o,c]=f.useState(null),[u,h]=f.useState(null),d=async x=>{l(null),c(null),h(x.name);try{const j=await T.removeSkill(e,x.name);c(`Removed ${j.name}. Its versions are kept, and ${t} will not propose it again for 90 days.`),i()}catch(j){l(j instanceof pe?j.message:String(j))}finally{h(null)}};if(!s)return r?n.jsx(se,{message:r}):n.jsx(oe,{children:"Loading…"});const m=s.skills.filter(x=>x.learned!==null),p=s.skills.filter(x=>x.learned===null);return n.jsxs(J,{divided:!0,children:[n.jsx(se,{message:r??a}),o?n.jsx(H,{tone:"good",role:"status",children:o}):null,n.jsx(te,{title:"Learned",aside:n.jsxs("span",{className:"muted",children:["what ",t," proposed and you kept"]}),children:m.length===0?n.jsx(tn,{icon:"bulb",title:"Nothing learned yet",children:s.writable?`When ${t} proposes a procedure and you keep it on Settings → Proposals, it appears here.`:`${t} ships with buddi, so it keeps no learned skills of its own until it is yours.`}):n.jsx(qe,{flush:!0,children:n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Skill"}),n.jsx("th",{children:"Version"}),n.jsx("th",{children:"Came from"}),n.jsx("th",{className:"num",children:"Kept"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:m.map(x=>n.jsx(P6,{skill:x,busy:u===x.name,onRemove:()=>void d(x)},x.name))})]})})}),n.jsx(te,{title:"From files and plugins",aside:n.jsx("span",{className:"muted",children:"read-only here"}),children:p.length===0?n.jsx(oe,{children:"No other skills."}):n.jsx(qe,{flush:!0,children:n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Skill"}),n.jsx("th",{children:"What it is for"}),n.jsx("th",{children:"Whose"})]})}),n.jsx("tbody",{children:p.map(x=>n.jsxs("tr",{children:[n.jsx("td",{children:n.jsxs($t,{summary:n.jsx("span",{className:"mono",children:x.name}),children:[n.jsx(xt,{children:x.body}),n.jsx("p",{className:"muted mono skill-file",children:x.file})]})}),n.jsx("td",{children:x.description}),n.jsx("td",{children:n.jsxs(J,{gap:"sm",children:[n.jsx(ge,{children:x.scope==="shared"?"shared":`${t} only`}),n.jsx("span",{className:"muted",children:I6(x)})]})})]},`${x.scope}:${x.name}`))})]})})})]})}function I6(e){return e.provenance==="imported"?e.source?`from ${e.source}`:"imported":e.provenance==="agent"?"written by an agent":"yours"}function P6({skill:e,busy:t,onRemove:s}){const r=e.learned;return n.jsxs("tr",{children:[n.jsx("td",{children:n.jsxs($t,{summary:n.jsxs("span",{children:[r.title," ",n.jsx("span",{className:"muted mono",children:e.name})]}),children:[n.jsxs("p",{className:"muted",children:["When: ",e.description]}),n.jsx(xt,{children:e.body}),n.jsxs("p",{className:"muted mono skill-file",children:[e.file,r.versions.length>1?` · earlier versions in ${r.versionsDir}`:""]})]})}),n.jsx("td",{children:n.jsxs(J,{gap:"sm",children:[n.jsxs("span",{children:["v",r.version,r.edited?" · your correction":""]}),r.untrusted?n.jsx(ge,{tone:"warning",children:"untrusted text in view"}):null]})}),n.jsx("td",{children:n.jsxs(J,{gap:"sm",children:[r.conversation?n.jsx("a",{href:Wa(r.conversation),children:r.turn?`conversation, turn ${r.turn}`:"conversation"}):n.jsx("span",{className:"muted",children:"no conversation"}),n.jsx("a",{href:et("proposals"),children:"the proposal"}),r.sources.length>0?n.jsx("ul",{className:"proposal-sources",children:r.sources.map(i=>n.jsx("li",{className:"mono",children:i},i))}):null]})}),n.jsx("td",{className:"num muted",title:r.keptAt,children:r.keptAt?Fe(r.keptAt,Date.now()):""}),n.jsx("td",{className:"num",children:n.jsx(Q,{align:"end",children:n.jsx(R,{size:"sm",variant:"ghost",disabled:t,onClick:s,children:"Remove"})})})]})}function KC({timezone:e,embedded:t,agentId:s}){const{data:r,error:i,reload:a}=le(()=>T.reminders(),[],3e4),l=((r==null?void 0:r.reminders)??[]).filter(h=>!s||h.agentId===s),[o,c]=f.useState(null),u=async h=>{c(null);try{await T.cancelReminder(h),a()}catch(d){c(d instanceof Error?d.message:String(d))}};return n.jsxs(yn,{embedded:t,title:"Reminders",lede:"A reminder wakes an agent with a note and the instruction to check before it speaks, never a message queued for delivery.",children:[n.jsx(se,{message:i??o}),n.jsx(qe,{flush:!0,children:r?l.length===0?n.jsx(tn,{icon:"bell",title:"No reminders",children:"Ask any agent to remind you of something, and it shows up here."}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Due"}),n.jsx("th",{children:"Agent"}),n.jsx("th",{children:"Note"}),n.jsx("th",{children:"State"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:l.map(h=>n.jsxs("tr",{children:[n.jsxs("td",{className:"nowrap",children:[Be(h.dueAt,e),n.jsx("div",{className:"sub",children:Fe(h.dueAt)})]}),n.jsx("td",{className:"mono",children:h.agentId}),n.jsxs("td",{children:[h.text,h.context?n.jsx($t,{summary:"context",children:n.jsx(xt,{children:In(h.context)})}):null]}),n.jsxs("td",{children:[n.jsx(Vo,{state:h.state}),h.cancelReason?n.jsx("div",{className:"sub",children:h.cancelReason}):null]}),n.jsx("td",{children:h.state==="pending"?n.jsx(R,{size:"sm",variant:"danger",onClick:()=>u(h.id),children:"Cancel"}):null})]},h.id))})]}):n.jsx(oe,{children:"Loading…"})})]})}const $6=/(flux|klein|schnell|qwen[-_]?image|image)/i;function VC(e){return e.kind==="image"||e.kind===void 0&&$6.test(e.id)}function M6(e){const t=((e==null?void 0:e.models)??[]).filter(s=>!VC(s));return[...t.filter(s=>s.loaded),...t.filter(s=>!s.loaded)].map(s=>s.id)}function Rp(e){return M6(e)[0]}function rv(e){return(e==null?void 0:e.detectedContextWindowSource)==="mlxh"}function O6(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 GC(e){let t=e;try{t=new URL(e).host}catch{}return`mlxh is not answering on ${t}. Start it with \`mlxh serve\`, or \`mlxh service install\` to keep it running.`}const YC="an image model; pick it in the Image plugin, not here";function iv({accountId:e,label:t,value:s,onChange:r,disabled:i=!1}){const[a,l]=f.useState(null),[o,c]=f.useState(!1),[u,h]=f.useState(""),[d,m]=f.useState(!1),p=f.useRef(0),x=async v=>{if(!e)return;const w=++p.current;c(!0),h("");try{const y=await T.accountModels(e,v);w===p.current&&l(y)}catch(y){w===p.current&&h(y instanceof Error?y.message:"Could not load models. Custom entry is still available.")}finally{w===p.current&&c(!1)}};if(f.useEffect(()=>(l(null),m(!1),h(""),x(!1),()=>{p.current++}),[e]),!e)return n.jsxs(n.Fragment,{children:[n.jsx(ee,{label:t,children:n.jsx("input",{required:!0,maxLength:150,value:s,disabled:i,onChange:v=>r(v.target.value)})}),n.jsx("p",{className:"ui-toolbar-note",children:"Save and connect the account to load its model list. You can enter a model manually now."})]});const j=(a==null?void 0:a.models)??[],b=!!s&&!j.some(v=>v.id===s),g=[a&&!j.length?"This account returned no models. You can enter a custom model.":null,a!=null&&a.truncated?"Showing the first part of this provider’s list. Custom model entry is available.":null,a?"Uses saved account settings. Listed models may not support every agent tool. Your selection is unchanged until you save.":null].filter(Boolean);return n.jsxs(n.Fragment,{children:[n.jsx(ee,{label:t,children:n.jsxs("select",{value:d?"__buddi_custom__":s,disabled:i,onChange:v=>{v.target.value==="__buddi_custom__"?m(!0):(m(!1),r(v.target.value))},children:[n.jsx("option",{value:"",disabled:!0,children:"Choose a model"}),b&&n.jsxs("option",{value:s,children:[s," (current",a?", not listed":"",")"]}),j.map(v=>n.jsxs("option",{value:v.id,children:[v.name===v.id?v.id:`${v.name} — ${v.id}`,v.isDefault?" (provider default)":"",v.image?` — ${YC}`:""]},v.id)),n.jsx("option",{value:"__buddi_custom__",children:"Custom model…"})]})}),n.jsx(R,{disabled:i||o,onClick:()=>void x(!0),children:o?"Loading models…":"Refresh models"}),d&&n.jsx(ee,{label:`Custom ${t.toLowerCase()}`,children:n.jsx("input",{required:!0,maxLength:150,value:s,disabled:i,onChange:v=>r(v.target.value)})}),u&&n.jsx("p",{role:"alert",className:"ui-toolbar-note critical",children:u}),g.length>0&&n.jsx("p",{className:"ui-toolbar-note",children:g.join(" ")})]})}function D6(e,t){const s=new Set(t),r=[],i=new Set;for(const a of e){for(const o of a.tools)i.add(o.name);const l=a.tools.filter(o=>s.has(o.name));l.length!==0&&(a.glob&&l.length===a.tools.length?r.push(a.glob):r.push(...l.map(o=>o.name)))}return r.push(...t.filter(a=>!i.has(a))),r}function _6(e,t){return[...e].sort().join(",")===[...t].sort().join(",")}const L6="This agent will not remember anything between conversations.";function F6({view:e,chosen:t,onChange:s,disabled:r}){var N;const[i,a]=f.useState(""),[l,o]=f.useState(null),[c,u]=f.useState(()=>new Set),h=k=>u(S=>{const C=new Set(S);return C.has(k)?C.delete(k):C.add(k),C}),d=k=>{a(k),u(new Set)},m=f.useId(),p=new Set(t),x=new Set(e.groups.flatMap(k=>k.tools.filter(S=>S.core).map(S=>S.name))),j=(k,S)=>{const C=S.filter(I=>p.has(I));if(C.length!==0){if(C.some(I=>x.has(I))){o({plugin:k,names:C});return}s(t.filter(I=>!C.includes(I)))}},b=k=>{s([...t,...k.filter(S=>!p.has(S))])},g=i.trim().toLowerCase(),v=(k,S)=>g===""||k.toLowerCase().includes(g)||S.toLowerCase().includes(g),w=e.groups.map(k=>({group:k,tools:k.tools.filter(S=>v(S.name,S.description))})).filter(k=>k.tools.length>0),y=(((N=e.suggested)==null?void 0:N.tools)??[]).filter(k=>!p.has(k.name));return n.jsxs("div",{className:"tool-picker",children:[e.suggested&&y.length>0?n.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":`${m}-suggested`,children:[n.jsx("div",{className:"tool-picker-head",children:n.jsx("span",{id:`${m}-suggested`,className:"tool-picker-plugin",children:e.suggested.label})}),n.jsx("ul",{className:"ui-list tool-picker-list","aria-label":e.suggested.label,children:y.map(k=>n.jsxs("li",{className:"ui-list-row",children:[n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title mono",children:k.name}),n.jsx("span",{className:"ui-list-sub",children:k.description})]}),n.jsx(R,{size:"sm",disabled:r,"aria-label":`Add ${k.name}`,onClick:()=>b([k.name]),children:"Add"})]},k.name))})]}):null,n.jsxs("label",{className:"tool-picker-search",children:[n.jsx("span",{className:"ui-field-label",children:"Find a tool"}),n.jsx("input",{type:"search",value:i,placeholder:"Name or what it does",onChange:k=>d(k.target.value)})]}),w.length===0?n.jsxs(oe,{children:["No installed tool matches “",i.trim(),"”."]}):null,w.map(({group:k,tools:S})=>{const C=k.tools.filter(E=>E.grantable).map(E=>E.name),I=k.tools.filter(E=>p.has(E.name)).length,A=!!k.glob&&I===k.tools.length,O=`${m}-${k.plugin}`,z=`${m}-${k.plugin}-list`,L=g!==""?!c.has(k.plugin):c.has(k.plugin);return n.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":O,"data-open":L?"true":void 0,children:[n.jsxs("div",{className:"tool-picker-head",children:[n.jsxs("button",{type:"button",className:"tool-picker-toggle","aria-expanded":L,"aria-controls":z,onClick:()=>h(k.plugin),children:[n.jsx(z6,{}),n.jsx("span",{id:O,className:"tool-picker-plugin",children:k.plugin}),n.jsx("span",{className:"muted",children:A?`all ${k.tools.length}`:`${I} of ${k.tools.length} granted`})]}),n.jsx(R,{size:"sm",variant:"ghost","aria-label":`All ${k.plugin} tools`,disabled:r||C.every(E=>p.has(E)),onClick:()=>b(C),children:"all"}),n.jsx(R,{size:"sm",variant:"ghost","aria-label":`No ${k.plugin} tools`,disabled:r||!C.some(E=>p.has(E)),onClick:()=>j(k.plugin,C),children:"none"})]}),(l==null?void 0:l.plugin)===k.plugin?n.jsx(H,{tone:"warning",role:"alert",children:n.jsxs("div",{className:"tool-picker-confirm",children:[n.jsx("span",{children:L6}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(R,{size:"sm",onClick:()=>o(null),children:"Keep"}),n.jsx(R,{size:"sm",variant:"danger",onClick:()=>{s(t.filter(E=>!l.names.includes(E))),o(null)},children:"Remove"})]})}):null,n.jsx("ul",{id:z,className:"ui-list tool-picker-list",hidden:!L,children:S.map(E=>{const $=`${m}-${E.name}`;return n.jsxs("li",{className:"ui-list-row",children:[n.jsx("input",{type:"checkbox",id:$,checked:p.has(E.name),disabled:r||!E.grantable,onChange:_=>_.target.checked?b([E.name]):j(k.plugin,[E.name])}),n.jsxs("label",{htmlFor:$,className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[n.jsx("span",{className:"mono",children:E.name}),E.core?n.jsx(ge,{tone:"accent",children:"core"}):null,E.gated?n.jsx(ge,{tone:"warning",children:"asks you"}):null]}),n.jsx("span",{className:"ui-list-sub",children:E.grantable?E.description:`${E.description} Granted only by editing the file by hand.`})]})]},E.name)})})]},k.plugin)})]})}function z6(){return n.jsx("svg",{className:"tool-picker-chevron",viewBox:"0 0 11 11","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M2.8 4.2 5.5 6.9l2.7-2.7"})})}const U6=(e,t)=>!!e&&!!t&&e.kind===t.kind&&(e.kind==="mascot"?e.role===t.role:e.kind==="emoji"?e.value===t.value:!0);async function qC(e){const t=await fetch(Yi(e));if(!t.ok)throw new Error(`The picture could not be read (${t.status}).`);const s=await t.blob();return new File([s],`buddi-blob-${e}.png`,{type:"image/png"})}function B6({face:e,onPick:t,label:s=P.assistant.face,kept:r,disabled:i,disableEmoji:a,children:l}){return n.jsxs("div",{className:"meet-faces",role:"group","aria-label":s,children:[n.jsxs("div",{className:"meet-face-row",children:[r?n.jsx("button",{type:"button",className:"meet-face","data-kind":"image","data-chosen":(e==null?void 0:e.kind)==="kept"?"true":void 0,"aria-pressed":(e==null?void 0:e.kind)==="kept","aria-label":"The current picture",disabled:i,onClick:()=>t({kind:"kept",url:r}),children:n.jsx("img",{src:r,alt:""})}):null,GD.map(o=>{const c={kind:"mascot",role:o},u=U6(e,c);return n.jsx("button",{type:"button",className:"meet-face","data-kind":"image","data-chosen":u?"true":void 0,"aria-pressed":u,"aria-label":P.assistant.mascot(o),disabled:i,onClick:()=>t(c),children:n.jsx("img",{src:Yi(o),alt:""})},o)})]}),n.jsx("div",{className:"meet-face-row",children:qD.map(o=>{const c=(e==null?void 0:e.kind)==="emoji"&&e.value===o;return n.jsx("button",{type:"button",className:"meet-face","data-chosen":c?"true":void 0,"aria-pressed":c,disabled:i||a,onClick:()=>t({kind:"emoji",value:o}),children:o},o)})}),l]})}const W6=["mirror","en","fr"],QC=[{id:"identity",label:"Identity"},{id:"brain",label:"Brain"},{id:"access",label:"Access"}],qy=e=>{var t;return((t=QC.find(s=>s.id===e))==null?void 0:t.id)??"identity"};function H6({agentId:e,section:t,navigate:s}){var j,b,g;const{data:r,error:i,reload:a}=le(()=>T.agents(),[]),[l,o]=f.useState(null),[c,u]=f.useState(null),[h,d]=f.useState(qy(t));f.useEffect(()=>d(qy(t)),[t]);const m=v=>{d(v),s==null||s(pt(e,"setup",v))},p=async v=>{o(null),u(null);try{const w=await v;u(w.changed.length===0?`No file change needed. ${w.note}.`:`Changed ${w.changed.join(", ")}. ${w.note}.`),a()}catch(w){o(w instanceof Error?w.message:String(w))}},x=r==null?void 0:r.agents.find(v=>v.id===e);return n.jsxs(J,{gap:"lg",children:[n.jsx(Go,{level:"secondary",label:"Setup",children:QC.map(v=>n.jsx(Ha,{href:pt(e,"setup",v.id),active:h===v.id,onClick:w=>{w.preventDefault(),m(v.id)},children:v.label},v.id))}),n.jsx(se,{message:i??l}),c?n.jsx(H,{tone:"good",role:"status",children:c}):null,r?x?n.jsx(K6,{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:a},`${x.id}:${(j=r.engines.find(v=>v.id===x.id))==null?void 0:j.model}:${(g=(b=r.providerAccounts)==null?void 0:b.bindings.find(v=>v.agentId===x.id))==null?void 0:g.accountId}`):n.jsx(oe,{children:"This agent is not installed as a file."}):n.jsx(oe,{children:"Loading…"})]})}function K6({agent:e,all:t,engine:s,providers:r,accounts:i,shown:a,onShow:l,onRun:o,onSaved:c}){const u=(s==null?void 0:s.provider)??e.provider.kind,h=r.find(y=>y.kind===u),d=(s==null?void 0:s.model)??e.model,[m,p]=f.useState(String((s==null?void 0:s.maxTurns)??e.maxTurns)),x=y=>{o(T.setAgentEngine(e.id,y))},j=y=>{const N=r.find(k=>k.kind===y);x({provider:y,model:(N==null?void 0:N.defaultModel)??d})},b=(h==null?void 0:h.models.map(y=>y.id))??[],g=b.includes(d)?b:[d,...b],v=s?s.available:!0,w=(s==null?void 0:s.unavailableReason)??"no credential";return n.jsxs(n.Fragment,{children:[n.jsx("div",{hidden:a!=="identity",children:n.jsxs(J,{gap:"lg",children:[v?null:n.jsxs(H,{tone:"warning",children:["This agent cannot run right now."," ",n.jsx("a",{href:pt(e.id,"setup","brain"),onClick:y=>{y.preventDefault(),l("brain")},children:"See Brain."})]}),n.jsx(V6,{agent:e,onSaved:c})]})}),n.jsx("div",{hidden:a!=="brain",children:n.jsxs(J,{gap:"lg",children:[v?null:n.jsxs(H,{tone:"warning",children:["This agent cannot run right now: ",w,"."]}),n.jsx(te,{panel:!0,children:n.jsxs(J,{divided:!0,children:[n.jsxs(te,{title:"Runs on",children:[i?n.jsx(J6,{agentId:e.id,accounts:i,onRun:o}):n.jsxs(bs,{children:[n.jsx(ee,{label:"Provider",children:n.jsx("select",{value:u,onChange:y=>j(y.target.value),children:r.map(y=>n.jsxs("option",{value:y.kind,children:[y.kind,y.usable?"":" (no credential)"]},y.kind))})}),n.jsxs(ee,{label:"Model",children:[n.jsx("input",{list:`models-${e.id}`,defaultValue:d,onBlur:y=>{y.target.value.trim()!==""&&y.target.value.trim()!==d&&x({model:y.target.value.trim()})}}),n.jsx("datalist",{id:`models-${e.id}`,children:g.map(y=>n.jsx("option",{value:y},y))})]})]}),i?null:n.jsxs("p",{className:"ui-card-meta",children:[(s==null?void 0:s.credentialKind)??e.provider.credentialKind," from"," ",n.jsx("span",{className:"mono",children:(s==null?void 0:s.credentialEnv)??e.provider.credentialEnv}),h&&!h.usable?` · default model ${h.defaultModel} (${h.defaultFrom})`:""]}),s!=null&&s.restartRequired?n.jsx("p",{className:"warning",children:"This file has changed since the service loaded it. Run `buddi service restart`."}):null]}),n.jsx(te,{title:"Behaviour",aside:"saved as you change them",children:n.jsxs(bs,{children:[n.jsx(ee,{label:"Max turns",hint:"Per run. The agent stops when it runs out.",children:n.jsx("input",{type:"number",min:1,value:m,onChange:y=>p(y.target.value),onBlur:()=>{const y=Number(m);Number.isInteger(y)&&y>=1&&y!==((s==null?void 0:s.maxTurns)??e.maxTurns)&&x({maxTurns:y})}})}),n.jsx(ee,{label:"Language",hint:"Mirror answers in whatever language you write.",children:n.jsx("select",{value:(s==null?void 0:s.language)??e.language,onChange:y=>x({language:y.target.value}),children:W6.map(y=>n.jsx("option",{value:y,children:y},y))})}),KS(VS(s??{id:e.id,provider:u},i))?n.jsx(ee,{label:"Thinking",hint:"Reasoning before the answer. Off is faster and cheaper.",children:n.jsxs("select",{"aria-label":"Thinking",value:(s==null?void 0:s.thinking)??"default",onChange:y=>x({thinking:y.target.value==="default"?null:y.target.value}),children:[n.jsx("option",{value:"default",children:"Model default"}),n.jsx("option",{value:"on",children:"On"}),n.jsx("option",{value:"off",children:"Off"})]})}):n.jsx(ee,{label:"Thinking",hint:q2,children:n.jsx("span",{className:"ui-card-meta",children:"Up to the model"})})]})})]})})]})}),n.jsx("div",{hidden:a!=="access",children:n.jsxs(J,{gap:"lg",children:[n.jsx(G6,{agent:e,all:t,onSaved:c}),n.jsx(tB,{agent:e,all:t,onSaved:c}),n.jsx($t,{summary:"Built-in context",boxed:!0,children:n.jsx("p",{className:"ui-card-meta",children:"Every agent receives current time, owner timezone and server-host information. system.time and system.info are always available, without grants or approval. Host and browser access still require their own permissions."})})]})})]})}function JC({dirty:e,busy:t,failure:s,label:r,onSave:i}){return n.jsxs(n.Fragment,{children:[s?n.jsx("span",{className:"critical save-error",role:"alert",children:s}):n.jsx("span",{className:e?"warning":"muted",children:e?"Not saved yet.":"Saved. Applies to new runs."}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(R,{variant:"accent",disabled:!e||t,onClick:i,children:r})]})}const XC=n.jsx(H,{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 V6({agent:e,onSaved:t}){var L;const[s,r]=f.useState(e.name),[i,a]=f.useState(e.handle),[l,o]=f.useState(e.description),[c,u]=f.useState(e.avatar??""),[h,d]=f.useState(!1),m=le(()=>T.agentFile(e.id),[e.id]),[p,x]=f.useState(null),j=((L=m.data)==null?void 0:L.persona.trim())??"",b=p??j,g=m.data!==void 0&&p!==null&&p.trim()!==j,[v,w]=f.useState(!1),[y,N]=f.useState(null),[k,S]=f.useState(null),C=s.trim()!==e.name||i.trim().replace(/^@/,"")!==e.handle||l.trim()!==e.description||c.trim()!==(e.avatar??"")||g,I=c.trim()!==""&&(c.trim()!==(e.avatar??"")||!e.picture),A=Ip(I?{...e,avatar:c.trim()}:e),O={...A?{avatar:A}:{},...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...!I&&e.picture?{picture:e.picture}:{}},z=async()=>{w(!0),N(null),S(null);try{const E=await T.updateAgentFile(e.id,{name:s.trim(),handle:i.trim().replace(/^@/,""),description:l.trim(),...c.trim()===""?{}:{avatar:c.trim()},...g&&b.trim()!==""?{persona:b.trim()}:{}});e.picture&&c.trim()!==""&&c.trim()!==(e.avatar??"")&&(await T.removeAgentPicture(e.id),window.dispatchEvent(new Event(ko))),x(null),m.reload(),S(E.message),t()}catch(E){N(E instanceof Error?E.message:String(E))}finally{w(!1)}};return n.jsx(te,{title:"Who it is",aside:n.jsx("span",{className:"mono",children:e.id}),panel:!0,foot:e.isExample?void 0:n.jsx(JC,{dirty:C,busy:v,failure:y,label:"Save who it is",onSave:()=>void z()}),children:n.jsxs(J,{children:[e.isExample?XC:null,k?n.jsx(H,{tone:"good",role:"status",children:k}):null,n.jsxs(bs,{children:[n.jsx(ee,{label:"Name",hint:"What it is called, everywhere.",children:n.jsx("input",{value:s,disabled:v||e.isExample,onChange:E=>r(E.target.value)})}),n.jsx(ee,{label:"Handle",hint:"What you type to reach it. One handle, one agent.",children:n.jsx("input",{value:i,disabled:v||e.isExample,onChange:E=>a(E.target.value)})})]}),n.jsxs(Q,{children:[n.jsx(Es,{id:e.id,name:s.trim()||e.name,size:"xl",face:O}),n.jsx(R,{"aria-expanded":h,onClick:()=>d(E=>!E),children:h?"Hide faces":"Change face"})]}),h?n.jsx(q6,{agent:e,avatar:c,onEmoji:u,onChanged:t,disabled:v}):null,n.jsx(ee,{label:"Description",hint:"One or two sentences. Its colleagues read this.",children:n.jsx("textarea",{rows:2,value:l,disabled:v||e.isExample,onChange:E=>o(E.target.value)})}),n.jsx(ee,{label:"Persona",hint:n.jsxs(n.Fragment,{children:["Who it is and how it works, in its own file. It reads this before every conversation; ",n.jsx("code",{children:"{{today}}"})," is filled in with the date at run time."]}),wide:!0,children:m.error?n.jsx(se,{message:m.error}):m.data?n.jsx("textarea",{className:"setup-persona",value:b,rows:Math.max(6,b.split(`
110
- `).length+1),disabled:v||e.isExample,onChange:E=>x(E.target.value)}):n.jsx(oe,{children:"Reading its file…"})})]})})}function G6({agent:e,all:t,onSaved:s}){var I;const r=le(()=>T.agentTools(e.id),[e.id]),[i,a]=f.useState(null),[l,o]=f.useState(()=>new Set((e.roles??[]).filter(zw))),[c,u]=f.useState((e.roles??[]).filter(A=>!zw(A)).join(", ")),[h,d]=f.useState(!1),[m,p]=f.useState(null),[x,j]=f.useState(null),b=(A,O)=>A.split(O).map(z=>z.trim()).filter(z=>z!==""),g=((I=r.data)==null?void 0:I.granted)??e.tools,v=i??g,w=r.data!==void 0&&!_6(v,g),y=Uw(l,b(c,/[\n,]/)),N=A=>o(O=>{const z=new Set(O);return z.has(A)?z.delete(A):z.add(A),z}),S=w||!((A,O)=>A.join(",")===O.join(","))(y,Uw(new Set(e.roles??[]),e.roles??[])),C=async()=>{d(!0),p(null),j(null);try{const A=await T.updateAgentFile(e.id,{...w&&r.data?{tools:D6(r.data.groups,v)}:{},roles:y});j(A.message),a(null),r.reload(),s()}catch(A){p(A instanceof Error?A.message:String(A))}finally{d(!1)}};return n.jsx(te,{title:"Roles and tools",panel:!0,foot:e.isExample?void 0:n.jsx(JC,{dirty:S,busy:h,failure:m,label:"Save roles and tools",onSave:()=>void C()}),children:n.jsxs(J,{children:[e.isExample?XC:null,x?n.jsx(H,{tone:"good",role:"status",children:x}):null,n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",id:`roles-${e.id}`,children:"Roles"}),n.jsx("div",{className:"role-chips",role:"group","aria-labelledby":`roles-${e.id}`,children:vx.map(A=>{const O=nD(t,A.id),z=O&&O.id!==e.id?O:void 0;return n.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:()=>N(A.id),children:[n.jsx("span",{className:"role-chip-label",children:A.label}),n.jsx("span",{className:"role-chip-meaning",children:A.meaning}),z?n.jsxs("span",{className:"role-chip-holder",children:["Held by ",z.name,". If both claim it, the one listed first keeps it."]}):null]},A.id)})}),n.jsx("span",{className:"ui-field-hint",children:"Where buddi sends things when you do not say who. Tools are granted below."})]}),n.jsx(ee,{label:"Other roles",hint:"Only a plugin that asks for a role by name reads these. Comma separated.",children:n.jsx("input",{value:c,disabled:h||e.isExample,onChange:A=>u(A.target.value)})}),n.jsxs("div",{className:"ui-field",children:[n.jsxs("span",{className:"ui-field-label",children:["Tools · ",g.length," granted"]}),r.error?n.jsx(se,{message:r.error}):r.data?n.jsx(F6,{view:r.data,chosen:v,onChange:a,disabled:h||e.isExample}):n.jsx(oe,{children:"Loading the installed tools…"})]}),n.jsx(Y6,{agentId:e.id,version:g.join(","),disabled:h||e.isExample})]})})}function Y6({agentId:e,version:t,disabled:s}){var h;const r=le(()=>Promise.resolve().then(()=>T.rememberedApprovals(e)),[e,t]),[i,a]=f.useState(null),[l,o]=f.useState(null),c=((h=r.data)==null?void 0:h.tools)??[];if(c.length===0)return null;const u=async(d,m)=>{a(d),o(null);try{await T.setRememberedApproval(e,d,m),r.reload()}catch(p){o(p instanceof Error?p.message:String(p))}finally{a(null)}};return n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Connection tools that ask first"}),n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Remembered approvals",children:c.map(d=>n.jsxs(J,{gap:"sm",children:[n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:d.remembered,disabled:s||!d.rememberable||i!==null,onChange:m=>void u(d.tool,m.target.checked)}),n.jsxs("span",{children:[n.jsx("span",{className:"mono",children:d.tool})," · remember my approval"]})]}),d.why?n.jsx("p",{className:"ui-card-meta",children:d.why}):null]},d.tool))}),n.jsx(se,{message:l}),n.jsx("span",{className:"ui-field-hint",children:"Remembered, it asks once and then runs for this agent. Never for a tool that deletes or destroys."})]})}function Ip(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 q6({agent:e,avatar:t,onEmoji:s,onChanged:r,disabled:i}){const[a,l]=f.useState(null),[o,c]=f.useState(!1),[u,h]=f.useState(null),d=t.trim()!==""&&(t.trim()!==(e.avatar??"")||!e.picture),m=a??(d?{kind:"emoji",value:t.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 qC(x.role)),s(e.avatar??""),r(),window.dispatchEvent(new Event(ko))}catch(j){h(j instanceof Error?j.message:String(j))}finally{l(null),c(!1)}};return n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Face"}),n.jsx(B6,{face:m,label:"Face",kept:e.picture,disabled:i||o,disableEmoji:e.isExample,onPick:x=>void p(x),children:n.jsx(Q6,{agent:e,onChanged:r})}),u?n.jsx("span",{className:"critical save-error",role:"alert",children:u}):null]})}function Q6({agent:e,onChanged:t}){const[s,r]=f.useState(null),[i,a]=f.useState(null),[l,o]=f.useState(!1),[c,u]=f.useState(null),[h,d]=f.useState(null),[m,p]=f.useState(0);f.useEffect(()=>{if(!s)return a(null);const S=URL.createObjectURL(s);return a(S),()=>URL.revokeObjectURL(S)},[s]);const x=S=>{r(null),p(C=>C+1),d(S),t(),window.dispatchEvent(new Event(ko))},j=async S=>{o(!0),u(null),d(null);try{x(await S())}catch(C){u(C instanceof Error?C.message:String(C))}finally{o(!1)}},b=()=>j(async()=>(await T.uploadAgentPicture(e.id,s)).note??null),g=()=>j(async()=>(await T.removeAgentPicture(e.id),null)),v={avatar:Ip(e),...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...i??e.picture?{picture:i??e.picture}:{}},[w,y]=f.useState(!1),N=f.useRef(null),k=S=>{u(null),d(null),r(S??null)};return n.jsxs("div",{className:"setup-upload","data-dragging":w?"true":void 0,onDragOver:S=>{S.preventDefault(),l||y(!0)},onDragLeave:()=>y(!1),onDrop:S=>{var C;S.preventDefault(),y(!1),l||k((C=S.dataTransfer.files)==null?void 0:C[0])},children:[n.jsxs(Q,{children:[n.jsx(Es,{id:e.id,name:e.name,size:"xl",face:v}),n.jsx("input",{ref:N,className:"sr-only",type:"file","aria-label":"Choose a picture",accept:"image/png,image/gif,image/svg+xml,.png,.gif,.svg",disabled:l,onChange:S=>{var C;return k((C=S.target.files)==null?void 0:C[0])}},m),n.jsx(R,{disabled:l,onClick:()=>{var S;return(S=N.current)==null?void 0:S.click()},children:"Upload a picture"}),n.jsx("span",{className:"setup-upload-name",children:s?s.name:"or drop one here"}),n.jsx("span",{className:"ui-toolbar-spacer"}),e.picture&&!s?n.jsx(R,{variant:"ghost",disabled:l,onClick:()=>void g(),children:"Remove picture"}):null,n.jsx(R,{variant:"accent",disabled:!s||l,onClick:()=>void b(),children:"Save picture"})]}),c?n.jsx("span",{className:"critical save-error",role:"alert",children:c}):n.jsx("span",{className:"ui-field-hint",children:h??"Your own picture: a PNG, GIF or SVG up to 1 MB, kept as a square PNG; a GIF keeps its first frame."})]})}function J6({agentId:e,accounts:t,onRun:s}){const r=t.bindings.find(p=>p.agentId===e),[i,a]=f.useState((r==null?void 0:r.accountId)??""),[l,o]=f.useState((r==null?void 0:r.model)??""),[c,u]=f.useState(!1),h=t.accounts.find(p=>p.id===i),d=i!==((r==null?void 0:r.accountId)??"")||l!==((r==null?void 0:r.model)??""),m=t.accounts.find(p=>p.id===(r==null?void 0:r.accountId));return n.jsxs("div",{className:"ui-stack",children:[n.jsxs(Q,{valign:"end",children:[n.jsx(ee,{label:"Account",children:n.jsxs("select",{value:i,disabled:c,onChange:p=>{var x;a(p.target.value),o(((x=t.accounts.find(j=>j.id===p.target.value))==null?void 0:x.defaultModel)??"")},children:[n.jsx("option",{value:"",children:"Choose an account"}),t.accounts.map(p=>n.jsxs("option",{value:p.id,disabled:!p.enabled,children:[p.label,p.enabled?p.configured?"":" (needs credential)":" (disabled)"]},p.id))]})}),n.jsx(iv,{accountId:h!=null&&h.configured?i:void 0,label:"Model",value:l,onChange:o,disabled:c},`${i}:${h==null?void 0:h.revision}`)]}),n.jsxs(Q,{children:[d&&i&&l.trim()?n.jsxs("span",{className:"warning",children:["Not saved yet. New runs still use ",m?`${m.label}, ${(r==null?void 0:r.model)??""}`:"nothing","."]}):n.jsx("span",{className:"muted",children:m?`Running on ${m.label} with ${(r==null?void 0:r.model)??"no model"}.`:"No account chosen yet: this agent cannot run until you save one."}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(R,{variant:"accent",disabled:c||!i||!l.trim()||!d,onClick:()=>{u(!0),s(T.assignProviderAccount(e,i,l).finally(()=>u(!1)))},children:"Save account selection"})]})]})}const X6=["platform.create_agent","platform.update_agent","platform.write_skill","platform.delete_agent","platform.accept_plugin_agent","platform.accept_plugin_skill"],bf=e=>e.tools.some(t=>X6.includes(t)),Z6=["front-desk","maker"],eB={"front-desk":"Can ask: everyone, as the front desk",maker:"Can ask: everyone, as the maker",list:"Can ask: everyone"};function tB({agent:e,all:t,onSaved:s}){const[r,i]=f.useState(e.delegates),[a,l]=f.useState(!1),[o,c]=f.useState(null),[u,h]=f.useState(!1),[d,m]=f.useState(e.delegates),[p,x]=f.useState(e.asksEveryone),[j,b]=f.useState(!1),g=t.filter(A=>A.id!==e.id),v=Z6.find(A=>{var O;return(O=e.roles)==null?void 0:O.includes(A)}),w=p===void 0||j,y=j||[...r].sort().join(",")!==[...d].sort().join(","),N=t.filter(A=>A.id!==e.id&&(A.delegates.includes(e.id)||A.asksEveryone!==void 0&&!bf(e))),k=A=>i(O=>O.includes(A)?O.filter(z=>z!==A):[...O,A]),S=async A=>{l(!0),c(null),h(!1);try{const O=await T.setDelegates(e.id,A);m(O.delegates),i(O.delegates),x(O.asksEveryone),b(!1),h(!0),s()}catch(O){c(O instanceof Error?O.message:String(O))}finally{l(!1)}},C=()=>{i(g.filter(A=>!bf(A)).map(A=>A.id)),b(!0),h(!1)},I=y?"Not saved yet.":u?"Saved. Applies to the next run.":w?r.length===0?"Asks nobody.":`May ask ${r.length} agent${r.length===1?"":"s"}.`:"Asks everyone.";return n.jsx(te,{title:"Delegation",aside:e.tools.includes("agent.delegate")?"holds agent.delegate":"no agent.delegate tool: it cannot ask anyone until granted",panel:!0,foot:e.isExample?void 0:n.jsxs(n.Fragment,{children:[n.jsx("span",{className:y?"warning":"muted",children:I}),n.jsx("span",{className:"ui-toolbar-spacer"}),w&&v!==void 0?n.jsx(R,{disabled:a,onClick:()=>void S(["*"]),children:"Let it ask everyone"}):null,w?n.jsx(R,{variant:"accent",disabled:!y||a,onClick:()=>void S(r),children:"Save who it can ask"}):n.jsx(R,{variant:"accent",disabled:a,onClick:C,children:"Limit to…"})]}),children:n.jsxs(J,{divided:!0,children:[n.jsxs(te,{title:"Can ask",children:[e.isExample?n.jsx(H,{tone:"warning",children:"This agent ships with buddi, so its allowlist is read-only here. Ask Agent Father to make it yours, then it can change."}):null,n.jsx(se,{message:o}),w?g.length===0?n.jsx(oe,{children:"Nobody else is installed."}):n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"ui-card-meta",children:"Only the agents ticked here. New teammates must be added here before it can ask them."}),n.jsx("ul",{className:"ui-list delegate-list","aria-label":"Agents this one may ask",children:g.map(A=>{const O=bf(A);return n.jsxs("li",{className:"ui-list-row",children:[n.jsx("input",{type:"checkbox",id:`can-ask-${e.id}-${A.id}`,checked:r.includes(A.id),disabled:O||e.isExample||a,onChange:()=>k(A.id)}),n.jsxs("label",{htmlFor:`can-ask-${e.id}-${A.id}`,className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[A.name," ",n.jsxs("span",{className:"mono muted",children:["@",A.handle]})]}),n.jsx("span",{className:"ui-list-sub",children:O?"Makes and changes agents. Never reachable by delegation.":A.description})]})]},A.id)})})]}):n.jsxs("p",{className:"ui-card-meta",children:[eB[p??"list"],". New agents are included without being added here; agents that make and change agents are never reachable by delegation."]})]}),n.jsx(te,{title:"Asked by",children:N.length===0?n.jsxs("p",{className:"ui-card-meta",children:["No other agent may hand work to ",e.name,"."]}):n.jsx(F_,{children:N.map(A=>n.jsx(ge,{children:A.name},A.id))})})]})})}const nB=[{id:"team",label:"Team"},{id:"missions",label:"Missions"},{id:"offers",label:"Offers"},{id:"reminders",label:"Reminders"}],sB=[{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 rB({hash:e,timezone:t,navigate:s,agents:r,attention:i,defaultAgentId:a}){var g,v,w,y,N;const l=BO(e),o=((g=/[?&]tab=([a-z]+)/.exec(e))==null?void 0:g[1])??"team",c=k=>S=>{S.preventDefault(),s(k)},u=le(()=>T.agents(),[]),h=Ux(),d=le(()=>T.offers(),[],2e4),m=nC(),p=(((v=d.data)==null?void 0:v.offers.length)??0)+m.offers.length,x=((y=(w=u.data)==null?void 0:w.default)==null?void 0:y.defaultAgentId)??a??null,j=r.find(k=>k.roles.includes(Jd)),b=UC(r,x);return n.jsxs("div",{className:"ui-page",children:[n.jsx(Zd,{title:"Agents",lede:`Your team. Each one is a file on ${h} — what it can reach is listed on its page.`,actions:j?n.jsx(Zt,{variant:"accent",href:Ve(j.id),onClick:c(Ve(j.id)),children:"Add an agent"}):null}),n.jsx(Go,{children:nB.map(k=>n.jsx(Ha,{href:k.id==="team"?mt:`${mt}?tab=${k.id}`,active:o===k.id,count:k.id==="offers"?p:void 0,onClick:c(k.id==="team"?mt:`${mt}?tab=${k.id}`),children:k.label},k.id))}),o==="missions"?n.jsx(LC,{timezone:t,embedded:!0}):null,o==="offers"?n.jsx(sC,{offers:m.offers,reload:m.reload}):null,o==="offers"?n.jsx(zC,{embedded:!0}):null,o==="reminders"?n.jsx(KC,{timezone:t,embedded:!0}):null,o==="team"&&b?n.jsx(Tp,{navigate:s,standing:!0}):null,o==="team"?n.jsx(iB,{data:u.data,error:u.error,reload:u.reload}):null,o==="team"?r.length===0?n.jsx(tn,{icon:"agents",title:"No agents yet",children:"Each agent is a file in the installation's agents folder."}):n.jsx("div",{className:"agents-grid",children:qN(r,x).map(k=>{const S=Qd(i.get(k.id));return n.jsxs("div",{className:"ui-card agent-card","data-interactive":"true",...Ko(Ho(k)),"data-unavailable":k.available?void 0:"true",children:[n.jsx("div",{className:"agent-card-top"}),n.jsx("div",{className:"agent-card-face",children:n.jsx(Es,{id:k.id,name:k.name,size:"xl",unavailable:!k.available,face:k})}),n.jsxs("div",{children:[n.jsxs("div",{className:"ui-card-title",children:[n.jsx("a",{className:"agent-card-link",href:pt(k.id,"conversations"),onClick:c(pt(k.id,"conversations")),children:k.name}),n.jsxs("span",{className:"agent-card-handle mono faint",children:["@",k.handle]})]}),n.jsx("p",{className:"ui-card-meta agent-card-desc",children:k.description})]}),n.jsxs("div",{className:"ui-row",children:[k.id===x?n.jsx(Ia,{children:"front desk"}):null,S?n.jsx(ge,{tone:"critical",dot:!0,children:"waiting for you"}):k.available?n.jsx(ge,{tone:"good",dot:!0,children:"ready"}):n.jsx(ge,{tone:"warning",children:Ks(k.unavailableReason??"cannot run",60)}),n.jsx(ge,{mono:!0,children:k.model}),n.jsx(Zt,{className:"agent-card-talk",size:"sm",href:Ve(k.id),onClick:c(Ve(k.id)),"aria-label":`Talk to ${k.name}`,children:"Talk"})]})]},k.id)})}):null,o==="team"&&!b?n.jsx(Tp,{navigate:s,standing:!0}):null,l?n.jsx(wt,{title:((N=r.find(k=>k.id===l.agentId))==null?void 0:N.name)??l.agentId,size:"wide",onClose:()=>s(mt),children:n.jsx(aB,{agentId:l.agentId,agent:r.find(k=>k.id===l.agentId),agents:r,tab:l.tab??"conversations",...l.section?{section:l.section}:{},timezone:t,navigate:s,attention:i})}):null]})}function iB({data:e,error:t,reload:s}){const r=e==null?void 0:e.default,[i,a]=f.useState(null),[l,o]=f.useState(!1),[c,u]=f.useState(null),[h,d]=f.useState(null);if(t)return n.jsx(se,{message:t});if(!r||r.choices.length===0)return null;const m=r.defaultAgentId,p=i??m??"",x=p!==""&&p!==m,j=r.problem,b=v=>v.map(w=>{var y;return((y=r.choices.find(N=>N.id===w))==null?void 0:y.name)??w}).join(" and "),g=async()=>{o(!0),u(null),d(null);try{const v=await T.setDefaultAgent(p);d(v.note),a(null),s()}catch(v){u(v instanceof Error?v.message:String(v))}finally{o(!1)}};return n.jsx(qe,{children:n.jsxs("div",{className:"ui-stack",children:[n.jsx(se,{message:c}),(j==null?void 0:j.code)==="multiple-defaults"?n.jsx(H,{tone:"warning",role:"status",children:`Two agents claim default in their files: ${b(j.agents)}. The one chosen here wins.`}):(j==null?void 0:j.code)==="no-default-agent"?n.jsx(H,{tone:"warning",role:"status",children:"No agent file claims the default and this installation has not recorded one. Choose who answers when you name nobody."}):null,h?n.jsx(H,{tone:"good",role:"status",children:h}):null,n.jsxs(Q,{children:[n.jsxs("div",{className:"default-agent-text",children:[n.jsx("h3",{className:"default-agent-title",children:"Default agent"}),n.jsx("span",{className:"ui-field-hint",children:"Where a chat that names nobody lands."})]}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsxs("select",{"aria-label":"Default agent",value:p,disabled:l,onChange:v=>a(v.target.value),children:[p===""?n.jsx("option",{value:"",children:"Choose an agent"}):null,r.choices.map(v=>n.jsxs("option",{value:v.id,disabled:!v.available,children:[v.name," @",v.handle,v.available?"":" (cannot run)"]},v.id))]}),n.jsx(R,{variant:"accent",disabled:l||!x,onClick:()=>void g(),children:"Save"})]})]})})}function aB({agentId:e,agent:t,agents:s,tab:r,section:i,timezone:a,navigate:l,attention:o}){const c=d=>m=>{m.preventDefault(),l(d)},u=Qd(o.get(e)),h=(t==null?void 0:t.name)??e;return n.jsxs("div",{className:"ui-stack","data-gap":"lg",children:[n.jsxs("header",{className:"agent-head",children:[n.jsx(Es,{id:e,name:h,size:"xl",unavailable:t?!t.available:!1,face:t}),n.jsxs("div",{className:"agent-head-text",children:[n.jsx("p",{className:"ui-page-lede",children:(t==null?void 0:t.description)??"This agent is not in the roster right now."}),n.jsxs("div",{className:"ui-row",children:[t?n.jsxs("span",{className:"muted mono",children:["@",t.handle]}):null,t?n.jsx("span",{className:"muted",children:t.model}):null,u?n.jsx(ge,{tone:"critical",children:u}):t&&!t.available?n.jsx(ge,{tone:"warning",children:t.unavailableReason??"cannot run"}):null]})]}),n.jsx("div",{className:"ui-page-actions",children:n.jsxs(Zt,{variant:"accent",href:Ve(e),onClick:c(Ve(e)),children:["Talk to ",h]})})]}),t&&!t.available?n.jsxs(H,{tone:"warning",role:"status",children:[XN(t)," ",n.jsx("a",{href:et(Qm(t).section),children:Qm(t).label})]}):null,n.jsx(Go,{children:sB.map(d=>n.jsx(Ha,{href:pt(e,d.id),active:r===d.id,onClick:c(pt(e,d.id)),children:d.label},d.id))}),r==="conversations"?n.jsx(lB,{agentId:e,navigate:l}):null,r==="missions"?n.jsx(LC,{timezone:a,embedded:!0,agentId:e}):null,r==="offers"?n.jsx(zC,{embedded:!0,agentId:e,agentName:h}):null,r==="reminders"?n.jsx(KC,{timezone:a,embedded:!0,agentId:e}):null,r==="memory"?n.jsx(BC,{embedded:!0,agents:s,timezone:a,agentId:e}):null,r==="skills"?n.jsx(R6,{agentId:e,agentName:h}):null,r==="setup"?n.jsx(H6,{agentId:e,section:i,navigate:l}):null]})}function lB({agentId:e,navigate:t}){const{data:s,error:r}=le(()=>Le.conversations(e,50),[e]);if(r)return n.jsx(oe,{children:r});const i=(s==null?void 0:s.conversations)??[];return n.jsx(qe,{flush:!0,children:s?i.length===0?n.jsx(tn,{icon:"chat",title:"No conversations yet",children:"Say hello, and the conversation shows up here."}):n.jsx(At,{children:i.map(a=>n.jsx(Tt,{href:Ve(e,a.id),onClick:()=>t(Ve(e,a.id)),title:Ks(a.preview||a.opening||"Untitled conversation",90),sub:`${a.messageCount} message${a.messageCount===1?"":"s"}`,side:Fe(a.lastMessageAt??a.startedAt??a.createdAt??null)},a.id))}):n.jsx(oe,{children:"Loading…"})})}const Qy=3,oB=40;function cB({agent:e,navigate:t}){var x;const s=f.useRef(null),[r,i]=f.useState(!1),[a,l]=f.useState(null),[o,c]=f.useState(null),u=le(()=>Le.conversations(e.id,Qy),[e.id],3e4),h=Li(Qx),d=Li("(pointer: coarse)");f.useEffect(()=>{var j;!h&&!d&&((j=s.current)==null||j.focus())},[]);const m=(j,b)=>{i(!0),l(null),(async()=>{try{const{conversationId:g}=await Le.startConversation(e.id),v=await Le.send(e.id,{conversationId:g,text:j,...b.length>0?{attachmentIds:b.map(w=>w.artifactId)}:{}});t(Ve(e.id,v.conversationId))}catch(g){l(g instanceof pe?g.message:String(g)),c({text:j,at:Date.now()}),i(!1)}})()},p=(((x=u.data)==null?void 0:x.conversations)??[]).slice(0,Qy);return n.jsxs("div",{className:"home-ask",children:[a?n.jsx(se,{message:a}):null,n.jsx(Bx,{ref:s,disabled:r||!e.available,running:!1,onSend:m,onStop:()=>{},agentName:e.name,placeholder:`Message ${e.name}…`,draft:o,threadKey:`home.${e.id}`}),p.length>0?n.jsxs("div",{className:"home-continue",children:[n.jsx("span",{className:"home-continue-label",id:`home-continue-${e.id}`,children:"Continue"}),n.jsx("ul",{className:"home-continue-chips","aria-labelledby":`home-continue-${e.id}`,children:p.map(j=>{const b=Ve(e.id,j.id),g=j.opening??j.preview??"Untitled conversation",v=UN(j.lastMessageAt??j.createdAt??j.startedAt??null);return n.jsx("li",{children:n.jsxs("a",{className:"home-continue-chip",href:b,title:g,onClick:w=>{w.preventDefault(),t(b)},children:[n.jsx("span",{className:"home-continue-title",children:Ks(g,oB)}),v?n.jsx("span",{className:"home-continue-when",children:v}):null]})},j.id)})})]}):null]})}const ZC="buddi.keepClose";let Ti=null;const Po=new Set;function Jy(){for(const e of Po)e()}typeof window<"u"&&(window.addEventListener("beforeinstallprompt",e=>{e.preventDefault(),Ti=e,Jy()}),window.addEventListener("appinstalled",()=>{Ti=null,eE(),Jy()}));function uB(){const[e,t]=f.useState(Ti);return f.useEffect(()=>{const s=()=>t(Ti);return Po.add(s),()=>{Po.delete(s)}},[]),tE()?null:e}function Xy(){try{return window.localStorage.getItem(ZC)!==null}catch{return!1}}function eE(){try{window.localStorage.setItem(ZC,"dismissed")}catch{}}function tE(){var e;try{return((e=window.matchMedia)==null?void 0:e.call(window,"(display-mode: standalone)").matches)??!1}catch{return!1}}function dB(e=window.location.hostname){const t=e.replace(/^\[|\]$/g,"").toLowerCase();return t==="127.0.0.1"||t==="::1"||t==="localhost"}function nE(e){return/Edg\//.test(e)?"In Edge, choose Apps → Install buddi from the … menu.":/(Chrome|CriOS)\//.test(e)?"In Chrome, click the install icon in the address bar.":/Safari\//.test(e)&&/Mac/.test(e)?"In Safari, choose File → Add to Dock.":null}function hB(e){return/Mac|iPhone|iPad/.test(e)}function fB(){const[e,t]=f.useState(()=>Xy()||tE()),[s,r]=f.useState(Ti),[i,a]=f.useState(void 0);if(f.useEffect(()=>{const d=()=>{r(Ti),Xy()&&t(!0)};return Po.add(d),()=>{Po.delete(d)}},[]),f.useEffect(()=>{if(e)return;let d=!0;return T.session().then(m=>{d&&a(m.platform)},()=>{}),()=>{d=!1}},[e]),e)return null;const l=typeof navigator>"u"?"":navigator.userAgent,o=dB(),c=s?null:nE(l),u=()=>{eE(),t(!0)},h=()=>{const d=s;d&&d.prompt().then(async()=>{const m=await d.userChoice;Ti=null,r(null),(m==null?void 0:m.outcome)==="accepted"&&u()},()=>{})};return n.jsxs(H,{tone:"accent",title:"Keep buddi one click away.",children:[n.jsxs("p",{children:[c?`${c} `:null,"Or bookmark it with ",hB(l)?"⌘D":"Ctrl+D",".",o?null:" This tailnet address installs as its own app, separate from the one on the machine buddi runs on."]}),o&&i==="darwin"?n.jsxs("p",{children:["On this Mac, ",n.jsx("span",{className:"mono",children:"buddi dashboard --install-app"})," puts a double-clickable app in ~/Applications (docs/cli.md, under Everyday)."]}):null,n.jsxs(Q,{align:"end",children:[n.jsx(R,{variant:"ghost",onClick:u,children:"Not now"}),s?n.jsx(R,{variant:"accent",onClick:h,children:"Install app"}):null]})]})}function mB(e){const t=e.indexOf("?");if(t===-1)return;const s=new URLSearchParams(e.slice(t+1)).get("tip");return s&&/^[a-z0-9-]{1,40}$/.test(s)?s:void 0}function pB({navigate:e,preview:t,hidden:s}){var c;const r=le(()=>T.currentTip(t),[t]),[i,a]=f.useState(null),l=((c=r.data)==null?void 0:c.tip)??null;if(!l||i===l.id||s)return null;const o=u=>{a(l.id),!t&&(u==="dismiss"?T.dismissTip(l.id):T.laterTip(l.id)).catch(()=>{})};return n.jsx("div",{className:"home-tip","data-tip":l.id,children:n.jsxs(H,{children:[n.jsxs("div",{className:"ui-notice-row",children:[n.jsx("p",{className:"ui-notice-body",children:l.text}),n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"Not now",title:"Not now",onClick:()=>o("later"),children:n.jsx(we,{name:"close"})})]}),n.jsxs(Q,{children:[n.jsx(en,{}),n.jsx(R,{variant:"ghost",size:"sm",onClick:()=>o("dismiss"),children:"Not this again"}),n.jsx(R,{variant:"accent",size:"sm",onClick:()=>e(l.action.route),children:l.action.label})]})]})})}const Pp="buddi.tipsOpen";function gB(e){const t=new Date(`${e}T12:00:00Z`);return Number.isNaN(t.getTime())?e:new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",timeZone:"UTC"}).format(t)}function xB(e){switch(e.status){case"today":return"Due today";case"holding":return"Waiting";case"quiet":return"Not needed now";case"dismissed":return"Dismissed";case"shown":return e.shownAt?`Shown on ${gB(e.shownAt)}`:"Shown"}}function vB(){try{return window.localStorage.getItem(Pp)==="1"}catch{return!1}}function jB(){const e=le(()=>T.tips(),[]),[t,s]=f.useState(vB),r=f.useCallback(i=>{s(i);try{i?window.localStorage.setItem(Pp,"1"):window.localStorage.removeItem(Pp)}catch{}},[]);return{open:t,setOpen:r,list:e}}function wB({tips:e}){const{open:t,setOpen:s,list:r}=e,i=!!r.data&&!r.data.enabled&&r.data.tips.some(a=>a.status==="today");return n.jsxs("button",{type:"button",className:"ui-icon-btn home-tips-btn","aria-label":i?"Tips, one due today":"Tips","aria-pressed":t,title:"Tips","data-open":t,onClick:()=>{t||r.reload(),s(!t)},children:[n.jsx(we,{name:"bulb"}),i?n.jsx("span",{className:"home-tips-dot","data-testid":"tips-dot"}):null]})}function yB({tips:e,navigate:t}){var b,g;const{open:s,setOpen:r,list:i}=e,[a,l]=f.useState(null),[o,c]=f.useState(null),[u,h]=f.useState(null);if(!s)return null;const d=((b=i.data)==null?void 0:b.tips)??null,m=u??((g=i.data)==null?void 0:g.enabled)??!0,p=v=>l(v instanceof pe?v.message:String(v)),x=v=>{c(v),l(null),T.restoreTip(v).then(()=>i.reload(),p).finally(()=>c(null))},j=v=>{c("switch"),l(null),h(v),T.saveTipsSettings(v).then(w=>{h(w.enabled),i.reload()}).catch(w=>{h(!v),p(w)}).finally(()=>c(null))};return n.jsx("div",{className:"home-tips","data-testid":"tips-section",children:n.jsxs(te,{title:"Tips",children:[n.jsx(se,{message:i.error??a}),n.jsx("div",{className:"tips-grid",children:(d??[]).map(v=>n.jsx("div",{className:"tips-card","data-tip":v.id,"data-status":v.status,children:n.jsxs(ks,{tone:v.status==="today"?"accent":void 0,children:[n.jsx("div",{children:n.jsx(ge,{tone:v.status==="today"?"accent":"muted",children:xB(v)})}),n.jsx("p",{className:"tips-card-text",children:v.text}),n.jsxs(Q,{children:[n.jsx(en,{}),v.status==="dismissed"?n.jsx(R,{size:"sm",disabled:o===v.id,onClick:()=>x(v.id),children:"Bring back"}):n.jsx(R,{size:"sm",variant:v.status==="today"?"accent":void 0,onClick:()=>t(v.action.route),children:v.action.label})]})]})},v.id))}),n.jsxs(Q,{children:[n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:m,disabled:o==="switch"||d===null,onChange:v=>j(v.target.checked)}),n.jsx("span",{children:"Tips on Home"})]}),n.jsx(en,{}),n.jsx(R,{variant:"ghost",size:"sm",onClick:()=>r(!1),children:"Close"})]})]})})}const bB=3;function kB(e,t=new Set){return(e??[]).filter(s=>!s.hidden&&!t.has(s.id)).slice(0,bB)}function SB({glances:e,navigate:t,onChanged:s}){const[r,i]=f.useState(new Set),a=kB(e,r);if(a.length===0)return null;const l=o=>{i(c=>new Set(c).add(o.id)),T.setGlanceHidden(o.id,!0).then(()=>s==null?void 0:s(),()=>{i(c=>{const u=new Set(c);return u.delete(o.id),u})})};return n.jsx("span",{className:"home-glances",children:a.map(o=>{const c=o.link?$1(o.link.plugin,o.link.page,o.link.place):null,u=n.jsxs(n.Fragment,{children:[n.jsx(we,{name:th(o.icon),size:14}),n.jsx("span",{children:o.text})]});return n.jsxs("span",{className:"home-glance",children:[n.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),c?n.jsx("a",{className:"home-glance-text",href:c,onClick:h=>{h.preventDefault(),t(c)},children:u}):n.jsx("span",{className:"home-glance-text",children:u}),n.jsx("button",{type:"button",className:"home-glance-hide","aria-label":`Hide ${o.title} from Home`,title:"Hide from Home",onClick:()=>l(o),children:n.jsx(we,{name:"close",size:10})})]},o.id)})})}const sE="buddi.needsYouView";function NB(){try{return window.localStorage.getItem(sE)==="list"?"list":"deck"}catch{return"deck"}}function CB(e){try{window.localStorage.setItem(sE,e)}catch{}}function EB(e,t,s){const r=(t.alsoFrom??[]).filter(i=>i!==t.agentId).map(s);return r.length===0?e:`${e} · also ${r.join(", ")}`}function AB({rows:e,agents:t,label:s,onOpen:r,onDone:i}){const[a,l]=f.useState(0);if(e.length===0)return n.jsx(oe,{mascot:!0,children:"Nothing needs you. Your agents are on it."});const o=Math.min(a,e.length-1),c=e[o],u=e.length>1,h=j=>l((o+j+e.length)%e.length),d=()=>r(c),m=()=>i(c),p=j=>{const b=j.target;b.closest('input, textarea, select, [contenteditable="true"]')||(j.key==="ArrowRight"&&u?(j.preventDefault(),h(1)):j.key==="ArrowLeft"&&u?(j.preventDefault(),h(-1)):j.key==="Enter"&&!b.closest("button, a")?(j.preventDefault(),c.link&&d()):(j.key==="d"||j.key==="Delete")&&!j.metaKey&&!j.ctrlKey&&!j.altKey&&(j.preventDefault(),m()))},x=n.jsxs("span",{className:"home-deck-from",children:[c.agentId?n.jsx(Nn,{agents:t,id:c.agentId,size:"sm"}):null,n.jsx("span",{children:s(c)})]});return n.jsx("div",{className:"home-deck","data-depth":Math.min(e.length-1,2),role:"region","aria-label":"Needs you, one at a time","aria-roledescription":"deck",tabIndex:0,onKeyDown:p,children:n.jsx(ks,{as:"article",title:x,meta:n.jsx("span",{className:"ui-card-meta",children:c.state==="held"?"today":Fe(c.createdAt)}),actions:n.jsxs(n.Fragment,{children:[n.jsxs("span",{className:"home-deck-count","aria-live":"polite",children:[o+1," of ",e.length]}),n.jsx(R,{size:"sm",variant:"ghost","aria-label":"Previous",disabled:!u,onClick:()=>h(-1),children:n.jsx(we,{name:"chevron-left"})}),n.jsx(R,{size:"sm",variant:"ghost","aria-label":"Next",disabled:!u,onClick:()=>h(1),children:n.jsx(we,{name:"chevron-right"})})]}),foot:n.jsxs(Q,{align:"end",children:[n.jsx(R,{onClick:m,children:"Done"}),c.link?n.jsx(R,{variant:"accent",onClick:d,children:"Open"}):null]}),children:n.jsxs("div",{className:"home-deck-body",children:[n.jsx("p",{className:"home-deck-title",children:c.title}),c.text?n.jsx("p",{className:"home-deck-text",children:c.text}):null]})})})}function TB({timezone:e,navigate:t,agents:s,defaultAgentId:r,attention:i,update:a,connectionSignals:l=[],hash:o=""}){var Ce,ut,fe,Me,ce,Te,G,ie,$e,yt,Ge,it,ht;const c=le(()=>T.overview(),[],15e3),u=le(()=>T.approvals(),[],1e4),h=le(()=>T.missions(),[],6e4),d=le(()=>T.reminders(),[],6e4),m=le(()=>T.conversations(),[],3e4),p=le(()=>T.offers(),[],3e4),x=le(()=>T.proposals(),[],6e4),j=le(()=>T.agentOffers(),[],6e4),b=le(()=>T.owner(),[]),g=le(()=>T.notifications(20),[],3e4),v=f.useMemo(()=>qN(s,r??null),[s,r]),{busy:w,note:y,failure:N,decide:k}=Wx(()=>{u.reload(),c.reload()}),S=c.data,C=s.find(Y=>Y.id===r)??null,I=Y=>{var at;return((at=s.find(Gt=>Gt.id===Y))==null?void 0:at.name)??Y},A=Y=>at=>{at.preventDefault(),t(Y)},O=((Ce=u.data)==null?void 0:Ce.pending)??[],z=((ut=S==null?void 0:S.jobs)==null?void 0:ut.failed)??0,L=((fe=S==null?void 0:S.sentinels)==null?void 0:fe.openUrgent)??0,E=((Me=x.data)==null?void 0:Me.open.length)??0,$=(((ce=j.data)==null?void 0:ce.offers)??[]).filter(Y=>!O.some(at=>tC(at,Y.plugin,Y.agent))),_=PB(((Te=g.data)==null?void 0:Te.notifications)??[],O),[B,M]=f.useState(new Set),[W,D]=f.useState(NB),U=_.filter(Y=>!B.has(Y.id)),V=Y=>{M(at=>new Set(at).add(Y.id)),T.notificationSeen(Y.id).catch(()=>{})},Z=Y=>{V(Y),Y.link&&t(Y.link)},ue=Y=>EB(Y.agentId?I(Y.agentId):Y.pluginId??IB[Y.kind],Y,I),Ae=O.length+(z>0?1:0)+(L>0?1:0)+(S!=null&&S.paused?1:0)+(E>0?1:0)+$.length+_.length,X=f.useMemo(()=>{var Y,at;return DB(((Y=h.data)==null?void 0:Y.missions)??[],((at=d.data)==null?void 0:at.reminders)??[])},[h.data,d.data]),ae=(((G=m.data)==null?void 0:G.conversations)??[]).slice(0,5),me=((ie=p.data)==null?void 0:ie.offers)??[],Pe=me.slice(0,$B),ke=jB(),ye=me.length-Pe.length;return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"home-band",children:n.jsxs("header",{className:"home-hero",children:[n.jsxs("div",{className:"home-hero-text",children:[n.jsxs("p",{className:"home-date",children:[n.jsx("span",{children:FB(S==null?void 0:S.now,e)}),n.jsx(SB,{glances:S==null?void 0:S.glances,navigate:t,onChanged:()=>c.reload()})]}),n.jsx("h1",{className:"home-greeting",children:LB(S==null?void 0:S.now,e,(($e=b.data)==null?void 0:$e.preferredName)||((yt=b.data)==null?void 0:yt.displayName))}),n.jsx("p",{className:"home-lede",children:UB(Ae,O.length,z,L,(S==null?void 0:S.paused)??!1,E,$.length,_.length)})]}),n.jsxs("div",{className:"home-hero-side",children:[n.jsx(wB,{tips:ke}),n.jsx(r1,{size:"lg",anim:"idle"})]})]})}),n.jsxs("div",{className:"home",children:[n.jsx(yB,{tips:ke,navigate:t}),C?n.jsx(cB,{agent:C,navigate:t},C.id):null,n.jsx(fB,{}),n.jsx(pB,{navigate:t,preview:mB(o),hidden:ke.open}),a&&a.updateAvailable&&!a.checkout&&a.latest?n.jsx(H,{tone:"accent",children:n.jsxs("p",{children:["A newer buddi is ready: ",n.jsx("span",{className:"mono",children:a.latest}),"."," ",n.jsx("a",{href:et("system"),onClick:A(et("system")),children:"Upgrade from Settings → Version."})]})}):null,l.map(Y=>n.jsx(H,{tone:"accent",children:n.jsxs("p",{children:[Y.sentence," ",n.jsx("a",{href:et("connections"),onClick:A(et("connections")),children:"Settings → Connections."})]})},Y.id)),n.jsx(se,{message:c.error??u.error??N}),y?n.jsx(H,{tone:"good",role:"status",children:y}):null,Ae>0?n.jsx(te,{title:"Needs you",actions:_.length>0?n.jsx(ls,{label:"Show what needs you as",options:[{value:"list",label:"List"},{value:"deck",label:"Deck"}],value:W,onChange:Y=>{D(Y),CB(Y)}}):void 0,children:n.jsxs(J,{children:[S!=null&&S.paused?n.jsxs(H,{tone:"warning",title:"The installation is paused.",children:["Nothing is being claimed until you resume it."," ",n.jsx(R,{size:"sm",onClick:()=>{T.setPaused(!1).then(()=>c.reload())},children:"Resume"})]}):null,O.map(Y=>n.jsx(Hx,{action:Y,timezone:e,busy:w===Y.id,onDecide:k,agentName:I(Y.agentId)},Y.id)),_.length>0&&W==="deck"?n.jsx(AB,{rows:U,agents:s,label:ue,onOpen:Z,onDone:V}):null,_.length>0&&W==="list"?n.jsx(qe,{flush:!0,children:n.jsx(At,{children:U.map(Y=>n.jsx(Tt,{href:Y.link??void 0,onClick:()=>Z(Y),lead:Y.agentId?n.jsx(Nn,{agents:s,id:Y.agentId,size:"sm"}):void 0,title:Y.title,sub:ue(Y),side:Y.state==="held"?"today":Fe(Y.createdAt)},Y.id))})}):null,z>0?n.jsx(H,{tone:"critical",children:n.jsxs("a",{href:`${St}/jobs?state=failed`,onClick:A(`${St}/jobs?state=failed`),children:[z," failed job",z===1?"":"s",". See why, then retry or cancel them, one by one or all at once."]})}):null,L>0?n.jsx(H,{tone:"critical",children:n.jsxs("a",{href:`${St}/alerts`,onClick:A(`${St}/alerts`),children:[L," urgent alert",L===1?"":"s"," from your watchers."]})}):null,$.map(Y=>n.jsx(qe,{children:n.jsx(Vx,{plugin:Y.plugin,agent:Y.agent,text:Y.text,label:`Create @${Y.handle}`,handle:Y.handle,onDismiss:()=>{T.dismissAgentOffer(Y.plugin,Y.agent).then(()=>j.reload())}})},`${Y.plugin}/${Y.agent}`)),E>0?n.jsx(H,{tone:"accent",children:n.jsxs("a",{href:et("proposals"),onClick:A(et("proposals")),children:[E," proposal",E===1?"":"s"," from your agents to keep or discard."]})}):null,(((Ge=S==null?void 0:S.sentinels)==null?void 0:Ge.errors)??[]).map(Y=>n.jsxs(H,{tone:"warning",children:["Watcher ",Y.sentinelId," failed: ",Y.error]},Y.sentinelId)),((S==null?void 0:S.mail)??[]).filter(Y=>Y.lastError).map(Y=>n.jsxs(H,{tone:"warning",children:["Source ",Y.sourceId,": ",Y.lastError]},Y.sourceId))]})}):null,n.jsx(te,{title:"Your team",aside:n.jsx("a",{href:mt,onClick:A(mt),children:"All agents"}),children:s.length===0?n.jsx(oe,{mascot:!0,children:"No agents yet. Add one under Agents."}):n.jsx("div",{className:"home-team",children:v.map(Y=>{const at=Qd(i.get(Y.id));return n.jsxs("a",{className:"home-face",...Ko(Ho(Y)),href:Ve(Y.id),onClick:A(Ve(Y.id)),"data-waiting":at?"true":void 0,"data-unavailable":Y.available?void 0:"true",children:[n.jsx(Es,{id:Y.id,name:Y.name,size:"lg",unavailable:!Y.available,face:Y}),n.jsxs("span",{className:"home-face-text",children:[n.jsx("span",{className:"home-face-name",children:Y.name}),n.jsx("span",{className:"home-face-status",children:at?rE(at):Y.available?Ks(Y.description,60):Y.unavailableReason??"Cannot run right now."})]})]},Y.id)})})}),UC(s,r)?n.jsx(Tp,{navigate:t}):null,Pe.length>0?n.jsx(te,{title:"On offer",aside:n.jsxs("span",{className:"ui-row",children:[ye>0?n.jsxs("a",{href:`${mt}?tab=offers`,onClick:A(`${mt}?tab=offers`),children:[ye," more"]}):null,n.jsx(FC,{ids:me.map(Y=>Y.id),onDone:()=>p.reload()})]}),children:n.jsx("div",{className:"home-offers",children:Pe.map(Y=>n.jsx(OB,{offer:Y,agents:s,open:A(pt(Y.agentId,"offers")),onDismissed:()=>p.reload()},Y.id))})}):null,(ht=(it=x.data)==null?void 0:it.digest)!=null&&ht.latest?n.jsx(zB,{digest:x.data.digest.latest,go:A}):null,n.jsxs("div",{className:"home-columns",children:[n.jsx(te,{title:"Coming up",aside:n.jsx("a",{href:`${mt}?tab=missions`,onClick:A(`${mt}?tab=missions`),children:"All missions"}),children:n.jsx(qe,{flush:!0,children:X.length===0?n.jsx(oe,{mascot:!0,children:"Nothing scheduled. Missions and reminders will show here."}):n.jsx(At,{children:X.map(Y=>n.jsx(Tt,{href:Y.route,onClick:()=>t(Y.route),lead:n.jsx(Nn,{agents:s,id:Y.agentId,size:"sm"}),title:Y.title,sub:`${Y.kind} for ${I(Y.agentId)}`,side:Fe(Y.at)},Y.key))})})}),n.jsx(te,{title:"Lately",aside:n.jsx("a",{href:St,onClick:A(St),children:"All activity"}),children:n.jsx(qe,{flush:!0,children:ae.length===0?n.jsx(oe,{mascot:!0,children:"Nothing has run yet. Say hello to someone on your team."}):n.jsx(At,{children:ae.map(Y=>n.jsx(Tt,{href:Ve(Y.agentId,Y.id),onClick:()=>t(Ve(Y.agentId,Y.id)),lead:n.jsx(Nn,{agents:s,id:Y.agentId,size:"sm"}),title:Y.opening?Ks(Y.opening,80):"Untitled conversation",sub:`${I(Y.agentId)}, ${Y.messageCount} message${Y.messageCount===1?"":"s"}`,side:Fe(Y.lastMessageAt??Y.createdAt)},Y.id))})})})]}),((S==null?void 0:S.home)??[]).map(Y=>n.jsx(BB,{block:Y},Y.id)),S!=null&&S.jobs&&S.missions?n.jsxs("p",{className:"home-foot muted",children:[_t(S.jobs.pending??0)," queued, ",_t(S.jobs.leased??0)," running, ",_t(S.missions.enabled)," of ",_t(S.missions.total)," missions on."," ",S.paused?n.jsx(ge,{tone:"warning",children:"paused"}):n.jsx(ge,{tone:"good",children:"running"})," ",n.jsx("a",{href:Wa("").replace(/\/conversations\/$/,""),onClick:A(St),children:"Activity"})," · ",n.jsx("a",{href:et("system"),onClick:A(et("system")),children:"System"})]}):null]})]})}const RB=new Set(["watcher","reminder","failure","recap","plugin"]),IB={approval:"Approval",question:"Question",watcher:"Watcher",reminder:"Reminder",failure:"Failure",recap:"Report",plugin:"Plugin"};function PB(e,t){const s=new Set(t.map(r=>r.id));return e.filter(r=>RB.has(r.kind)&&r.actedAt===null&&r.state!=="stored"&&(r.seenAt===null||r.state==="held")&&!(r.actionId&&s.has(r.actionId)))}const $B=6,MB=500;function OB({offer:e,agents:t,open:s,onDismissed:r}){const[i,a]=f.useState(!1),l=f.useRef(null),o=f.useRef(!1),c=()=>{i||(a(!0),T.dismissOffer(e.id).then(r).finally(()=>a(!1)))},u=()=>{l.current!==null&&clearTimeout(l.current),l.current=null};return n.jsxs("span",{className:"home-offer-chip",children:[n.jsxs("a",{className:"home-offer",href:pt(e.agentId,"offers"),onClick:h=>{if(o.current){o.current=!1,h.preventDefault();return}s(h)},title:e.prompt,onTouchStart:()=>{o.current=!1,u(),l.current=setTimeout(()=>{o.current=!0,c()},MB)},onTouchEnd:u,onTouchMove:u,onTouchCancel:u,children:[n.jsx(Nn,{agents:t,id:e.agentId,size:"sm"}),n.jsx("span",{children:e.label})]}),n.jsx("button",{type:"button",className:"home-offer-x","aria-label":`Dismiss ${e.label}`,disabled:i,onClick:c,children:"×"})]})}function DB(e,t){const s=[];for(const r of e)r.enabled&&r.nextRun&&s.push({key:`m-${r.id}`,at:r.nextRun,title:r.name,kind:"Mission",agentId:r.agentId,route:pt(r.agentId,"missions")});for(const r of t)r.state==="pending"&&s.push({key:`r-${r.id}`,at:r.dueAt,title:r.text,kind:"Reminder",agentId:r.agentId,route:pt(r.agentId,"reminders")});return s.sort((r,i)=>r.at.localeCompare(i.at)).slice(0,5)}function _B(e,t){try{const s=new Intl.DateTimeFormat("en-GB",{hour:"numeric",hourCycle:"h23",timeZone:t}).format(e?new Date(e):new Date);return Number(s)}catch{return new Date().getHours()}}function LB(e,t,s){const r=_B(e,t),i=s!=null&&s.trim()?`, ${s.trim()}`:"";return r<5?`Still up${i}?`:r<12?`Good morning${i}.`:r<18?`Good afternoon${i}.`:`Good evening${i}.`}function FB(e,t){try{const s=e?new Date(e):new Date,r=new Intl.DateTimeFormat("en-GB",{weekday:"long",timeZone:t}).format(s),i=new Intl.DateTimeFormat("en-GB",{day:"numeric",month:"long",timeZone:t}).format(s);return`${r}, ${i}`}catch{return Be(e??null,t)}}function Wc(e,t,s){return e.count===0?null:`${e.count} ${e.count===1?t:s}${e.names.length>0?`: ${e.names.join("; ")}${e.count>e.names.length?"; …":""}`:""}`}function zB({digest:e,go:t}){const s=[Wc(e.memory,"memory note","memory notes"),Wc(e.skills,"skill kept","skills kept"),Wc(e.rules,"rule kept","rules kept"),Wc(e.changes,"change to an agent kept","changes to agents kept")].filter(i=>i!==null),r=e.stopped===null?"Not measured yet.":e.stopped.total>0?`Rules you kept acted ${e.stopped.total} time${e.stopped.total===1?"":"s"} (${Object.entries(e.stopped.byPlugin).filter(([,i])=>i>0).map(([i,a])=>`${i} ${a}`).join(", ")}).`:"No rule you kept acted this week.";return n.jsx(te,{title:"What buddi learned this week",aside:n.jsx("span",{className:"muted",children:Fe(e.at)}),children:n.jsx(qe,{children:n.jsxs(J,{divided:!0,children:[n.jsxs("div",{children:[n.jsx("p",{className:"ui-card-meta",children:"Learned"}),s.length===0?n.jsx("p",{children:"Nothing new."}):n.jsx("ul",{className:"home-digest-list",children:s.map(i=>n.jsx("li",{children:i},i))})]}),n.jsxs("div",{children:[n.jsx("p",{className:"ui-card-meta",children:"Proposes"}),n.jsx("p",{children:e.open>0?n.jsxs("a",{href:et("proposals"),onClick:t(et("proposals")),children:[e.open," proposal",e.open===1?"":"s"," waiting for you to keep or discard."]}):"Nothing was waiting for you."})]}),n.jsxs("div",{children:[n.jsx("p",{className:"ui-card-meta",children:"Stopped doing"}),n.jsx("p",{children:r})]})]})})})}function UB(e,t,s,r,i,a=0,l=0,o=0){if(e===0)return"Nothing needs you. Your agents are on it.";const c=[];t>0&&c.push(`${t} approval${t===1?"":"s"} waiting`),s>0&&c.push(`${s} failed job${s===1?"":"s"}`),r>0&&c.push(`${r} urgent alert${r===1?"":"s"}`),i&&c.push("the installation is paused"),a>0&&c.push(`${a} proposal${a===1?"":"s"} to review`),l>0&&c.push(`${l===1?"an agent":`${l} agents`} to set up`),o>0&&c.push(`${o} message${o===1?"":"s"} for you`);const u=c.length<=1?c.join(""):`${c.slice(0,-1).join(", ")} and ${c[c.length-1]}`;return`${rE(u)}.`}function rE(e){return e.charAt(0).toUpperCase()+e.slice(1)}function BB({block:e}){const[t,s]=f.useState(!1),r=e.sensitive===!0&&!t;f.useEffect(()=>{if(!e.sensitive||!t)return;const a=()=>{document.visibilityState==="hidden"&&s(!1)};return document.addEventListener("visibilitychange",a),window.addEventListener("blur",a),()=>{document.removeEventListener("visibilitychange",a),window.removeEventListener("blur",a)}},[e.sensitive,t]);const i=n.jsxs("span",{className:"ui-row",children:[e.rows.length>0&&e.rowsTitle&&!r?n.jsxs("span",{className:"muted",children:[e.rowsTitle.toLowerCase()," below"]}):null,e.sensitive?n.jsx(R,{size:"sm",variant:"ghost","aria-pressed":!r,onClick:()=>s(a=>!a),children:r?"Show":"Hide"}):null]});return n.jsxs(te,{title:e.title,aside:i,children:[e.note?n.jsx(H,{tone:"warning",children:e.note}):null,e.stats.length>0?n.jsx(eh,{children:e.stats.map(a=>n.jsx(Fs,{label:a.label,value:r?"••••":a.value,note:r?void 0:a.note,tone:r?void 0:a.tone},a.label))}):null,e.rows.length>0?r?n.jsxs("p",{className:"muted",children:[e.rows.length," item",e.rows.length===1?"":"s"," hidden."]}):n.jsx(qe,{flush:!0,children:n.jsx(At,{children:e.rows.map((a,l)=>n.jsx(Tt,{title:a.title,sub:a.sub,side:a.side?n.jsx("span",{className:a.tone==="critical"?"critical":a.tone==="good"?"good":void 0,children:a.side}):void 0},`${a.title}-${l}`))})}):null]})}const WB=3e4;function iE(){const{data:e,reload:t}=le(()=>T.recovery(),[],WB);return{data:e,reload:t}}const HB="This buddi was restored from a backup. Nothing runs on its own until you finish the checklist.";function KB({active:e,onNavigate:t}){return e?n.jsxs("div",{className:"recovery-banner",role:"status",children:[n.jsx("span",{children:HB}),n.jsx("a",{href:Fw,onClick:s=>{s.preventDefault(),t(Fw)},children:"Finish the checklist"})]}):null}function VB({view:e,onLeft:t}){const{secrets:s,plugins:r,pending:i,grants:a}=e.checklist,[l,o]=f.useState(!0),[c,u]=f.useState([]),[h,d]=f.useState(!1),[m,p]=f.useState(null),[x,j]=f.useState(!1),b=r.filter(y=>!y.installed),g=i.jobs+i.missions+i.approvals+i.telegramChats,v=y=>{u(N=>N.includes(y)?N.filter(k=>k!==y):[...N,y])},w=()=>{d(!0),p(null),T.leaveRecovery({dropPending:l,keepGrants:c}).then(()=>{j(!0),t==null||t()}).catch(y=>p(y instanceof pe?y.message:String(y))).finally(()=>d(!1))};return n.jsx(qe,{title:"Back from a backup",children:n.jsxs(J,{divided:!0,children:[n.jsxs(te,{children:[n.jsx(Vt,{items:[{label:"Restored",value:e.restoredAt??"just now"},{label:"From",value:n.jsx("span",{className:"mono",children:e.archive??"—"})}]}),n.jsx("p",{className:"ui-card-meta",children:"Nothing runs on its own yet: no schedules, no watchers, no phone. Chat works. Go through what is below, then turn this buddi back on."})]}),n.jsx(te,{title:"Keys to paste again",children:s.length===0?n.jsx(oe,{children:"Nothing is missing."}):n.jsx("ul",{className:"recovery-list",children:s.map(y=>n.jsxs("li",{children:[y.settingsRoute?n.jsx("a",{href:y.settingsRoute,children:y.name}):y.name," ",n.jsx("span",{className:"ui-card-meta",children:y.kind})]},`${y.kind}:${y.name}`))})}),n.jsx(te,{title:"Add-ons to install again",children:b.length===0?n.jsx(oe,{children:"Everything the backup named is installed."}):n.jsx("ul",{className:"recovery-list",children:b.map(y=>n.jsxs("li",{children:[n.jsx("span",{className:"mono",children:y.name})," ",y.version," ",n.jsx("span",{className:"ui-card-meta",children:y.source})]},y.name))})}),n.jsx(te,{title:"Work that was waiting",children:g===0?n.jsx(oe,{children:"Nothing was in flight when the backup was taken."}):n.jsxs(J,{gap:"sm",children:[n.jsx(Vt,{items:[{label:"Jobs",value:String(i.jobs)},{label:"Missions",value:String(i.missions)},{label:"Waiting for an answer",value:String(i.approvals)},{label:"Phones",value:String(i.telegramChats)}]}),n.jsxs("label",{className:"recovery-check",children:[n.jsx("input",{type:"checkbox",checked:l,onChange:y=>o(y.target.checked)}),n.jsx("span",{children:"Drop it. It was queued somewhere else, days ago."})]})]})}),n.jsx(te,{title:"Standing permissions",children:a.length===0?n.jsx(oe,{children:"No agent had a standing permission."}):n.jsxs(J,{gap:"sm",children:[n.jsx("p",{className:"ui-card-meta",children:"Each of these lets an agent act without asking. Keep only the ones you meant."}),n.jsx("ul",{className:"recovery-list",children:a.map(y=>n.jsx("li",{children:n.jsxs("label",{className:"recovery-check",children:[n.jsx("input",{type:"checkbox",checked:c.includes(y.id),onChange:()=>v(y.id),"aria-label":`Keep ${y.tool} for ${y.agent}`}),n.jsxs("span",{children:[n.jsx("span",{className:"mono",children:y.tool})," for ",y.agent," ",n.jsx("span",{className:"ui-card-meta",children:y.scope}),y.description?n.jsxs("span",{className:"ui-card-meta",children:[" — ",y.description]}):null]})]})},y.id))})]})}),n.jsx(te,{children:n.jsxs(J,{gap:"sm",children:[n.jsx(se,{message:m}),x?n.jsx(H,{tone:"good",role:"status",children:"Turning everything back on. This page comes back in a few seconds."}):n.jsx("p",{className:"ui-card-meta",children:"Leaving starts the schedules, the watchers and the phone again. buddi restarts itself to do it."}),n.jsx(Q,{align:"end",children:n.jsx(R,{variant:"accent",disabled:h||x,onClick:w,children:"Leave recovery mode"})})]})})]})})}const GB=2e3,YB={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 Zy(e){return YB[e.phase]??e.detail??e.phase}const qB=new Set(["done","failed","rolled-back"]);function aE(e){return e!==void 0&&(qB.has(e.phase)||!!e.finishedAt)}function QB(e){const[t,s]=f.useState(void 0),[r,i]=f.useState(!1),[a,l]=f.useState(null),o=f.useRef(!1);return f.useEffect(()=>{if(!e){s(void 0),i(!1),o.current=!1;return}let c=!1;const u=()=>{T.backupJob(e).then(d=>{if(!c){if(o.current){window.location.reload();return}s(d),l(null),aE(d)&&(c=!0)}}).catch(d=>{if(!c){if(d instanceof pe&&d.status!==0&&d.status<500){l(d.message);return}o.current=!0,i(!0)}})};u();const h=window.setInterval(u,GB);return()=>{c=!0,window.clearInterval(h)}},[e]),{job:t,away:r,error:a}}function JB({job:e,away:t,error:s}){return s?n.jsx(se,{message:s}):t?n.jsx(H,{tone:"warning",role:"status",children:"buddi is restarting. This page comes back on its own when it answers again."}):e?e.phase==="rolled-back"||e.phase==="failed"?n.jsxs(H,{tone:"critical",role:"alert",children:[Zy(e)," ",e.error??""]}):n.jsxs(H,{tone:e.phase==="done"?"good":void 0,role:"status",children:[Zy(e),e.copyLate?" The backup was made, but the copy to your folder did not go through.":"",e.error?` ${e.error}`:""]}):null}function XB(){var b,g,v,w,y,N,k;const e=le(()=>T.backups(),[],3e4),t=iE(),s=le(()=>T.service(),[]),[r,i]=f.useState(null),a=QB(r),[l,o]=f.useState(null),[c,u]=f.useState(!1),[h,d]=f.useState(null),m=((b=e.data)==null?void 0:b.supervised)??((g=s.data)==null?void 0:g.supervised),p=h!==null||m===!1,x=((v=e.data)==null?void 0:v.archives)??[],j=S=>{u(!0),o(null),S.then(C=>{var I;return i(((I=C.job)==null?void 0:I.id)??null)}).catch(C=>{C instanceof pe&&C.status===409?d(C.message):o(C instanceof pe?C.message:String(C))}).finally(()=>{u(!1),e.reload()})};return f.useEffect(()=>{aE(a.job)&&e.reload()},[(w=a.job)==null?void 0:w.phase]),n.jsxs(J,{gap:"lg",children:[(y=t.data)!=null&&y.active?n.jsx(VB,{view:t.data,onLeft:t.reload}):null,n.jsx(se,{message:e.error??l}),n.jsx(JB,{...a}),n.jsx(e5,{onSaved:()=>e.reload()}),n.jsx(te,{title:"Backups",panel:!0,actions:n.jsx(R,{variant:"accent",size:"sm",disabled:c,onClick:()=>j(T.startBackup(!0)),children:"Back up now"}),children:n.jsxs(J,{divided:!0,children:[n.jsx(te,{children:n.jsxs("p",{className:"ui-card-meta",children:["Kept in ",n.jsx("span",{className:"mono",children:((N=e.data)==null?void 0:N.dir)??"…"}),". A backup holds your agents, conversations, memory and files. It never holds a key."]})}),n.jsx(te,{children:e.data&&x.length===0?n.jsx(tn,{icon:"archive",title:"No backups yet",children:"Make one now, or turn on the nightly backup."}):e.data?n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Name"}),n.jsx("th",{children:"Taken"}),n.jsx("th",{children:"Size"}),n.jsx("th",{children:"State"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:x.map(S=>{var C;return n.jsx(t5,{archive:S,busy:c,database:(C=e.data)==null?void 0:C.database,checkout:p,onVerify:()=>j(T.verifyArchive(S.name)),onRestore:(I,A)=>j(T.restoreArchive({name:S.name,...I?{passphrase:I}:{},...A?{confirm:A}:{}}))},S.name)})})]}):n.jsx(oe,{children:"Loading…"})})]})}),n.jsx(n5,{}),n.jsx(s5,{busy:c,checkout:p,checkoutSaid:h,database:(k=e.data)==null?void 0:k.database,onRestore:(S,C,I)=>j(T.restoreUpload(S,{passphrase:C,confirm:I}))})]})}const ZB={enabled:!1,time:"03:00",keep:7,encryptLocal:!0,copyTo:null};function e5({onSaved:e}){var p;const t=le(()=>T.backupSchedule(),[]),[s,r]=f.useState(null),[i,a]=f.useState(!1),[l,o]=f.useState(null),[c,u]=f.useState(!1);f.useEffect(()=>{t.data&&r(t.data)},[t.data]);const h={...ZB,...s??t.data??{}};if(((p=t.data)==null?void 0:p.supervised)===!1)return n.jsx(te,{title:"Every night",panel:!0,children:n.jsx(te,{children:n.jsx(H,{tone:"warning",children:t.data.error??"This installation schedules its own backups."})})});const d=x=>{u(!1),r({...h,...x})},m=()=>{a(!0),o(null),T.setBackupSchedule(h).then(x=>{r(x),u(!0),e()}).catch(x=>o(x instanceof pe?x.message:String(x))).finally(()=>a(!1))};return n.jsx(te,{title:"Every night",panel:!0,foot:n.jsx(R,{variant:"accent",disabled:i,onClick:m,children:"Save"}),children:n.jsxs(J,{divided:!0,children:[n.jsx(te,{children:n.jsxs(J,{gap:"sm",children:[n.jsx(se,{message:l}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:h.enabled,onChange:x=>d({enabled:x.target.checked})}),n.jsx("span",{children:"Back this buddi up on its own"})]}),n.jsxs(bs,{children:[n.jsx(ee,{label:"At",children:n.jsx("input",{type:"time",value:h.time,onChange:x=>d({time:x.target.value})})}),n.jsx(ee,{label:"Keep",hint:"How many to keep before the oldest is thrown away.",children:n.jsx("input",{type:"number",min:1,max:365,value:h.keep,onChange:x=>d({keep:Number(x.target.value)||1})})})]}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:h.encryptLocal,onChange:x=>d({encryptLocal:x.target.checked})}),n.jsx("span",{children:"Lock each one with the passphrase"})]})]})}),n.jsx(te,{children:n.jsxs(J,{gap:"sm",children:[n.jsx(ee,{label:"Also copy to a folder",hint:"A second disk, or a folder that syncs somewhere. Left empty, backups stay on this machine.",children:n.jsx("input",{type:"text",value:h.copyTo??"",placeholder:"/Volumes/backup/buddi",onChange:x=>d({copyTo:x.target.value===""?null:x.target.value})})}),c?n.jsxs(H,{tone:"good",role:"status",children:["Saved.",h.lastRunAt?` Last run ${Fe(h.lastRunAt)}.`:""]}):null]})})]})})}function t5({archive:e,busy:t,database:s,checkout:r,onVerify:i,onRestore:a}){const[l,o]=f.useState(!1),[c,u]=f.useState(""),[h,d]=f.useState("");return n.jsxs(n.Fragment,{children:[n.jsxs("tr",{children:[n.jsx("td",{className:"mono",children:e.name}),n.jsx("td",{children:Fe(e.createdAt)}),n.jsx("td",{children:$n(e.bytes)}),n.jsxs("td",{children:[e.encrypted?n.jsx(ge,{tone:"good",children:"locked"}):n.jsx(ge,{tone:"muted",children:"plain"})," ",e.envelopeOk===!1?n.jsx(ge,{tone:"critical",children:"damaged"}):null]}),n.jsx("td",{children:n.jsxs(Q,{align:"end",children:[n.jsx(R,{size:"sm",disabled:t,onClick:i,children:"Verify"}),n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>o(!l),children:"Restore…"})]})})]}),l?n.jsx("tr",{children:n.jsx("td",{colSpan:5,children:r?n.jsx(H,{tone:"warning",children:lE}):n.jsx(oE,{what:`${e.name}, taken ${Fe(e.createdAt)}, ${$n(e.bytes)}`,database:s,needsPassphrase:e.encrypted,passphrase:c,onPassphrase:u,confirm:h,onConfirm:d,busy:t,onCancel:()=>o(!1),onGo:()=>a(c,h)})})}):null]})}const lE="Restoring needs the packaged installation. In a checkout, run: buddi backup restore <file>";function oE({what:e,database:t,needsPassphrase:s,passphrase:r,onPassphrase:i,confirm:a,onConfirm:l,busy:o,onCancel:c,onGo:u}){const h=t??"",d=h===""?a.trim()!=="":a.trim()===h;return n.jsxs(J,{gap:"sm",children:[n.jsxs(H,{tone:"warning",children:["This replaces everything in this buddi with ",e,". What is here now is copied first, so a restore that fails puts it back."]}),s?n.jsx(ee,{label:"The passphrase this one was locked with",children:n.jsx("input",{type:"password",autoComplete:"off",value:r,onChange:m=>i(m.target.value)})}):null,n.jsx(ee,{label:h?`Type ${h} to confirm`:"Type the name of this database to confirm",hint:h?void 0:"The same name buddi shows on the System tab.",children:n.jsx("input",{value:a,onChange:m=>l(m.target.value)})}),n.jsxs(Q,{align:"end",children:[n.jsx(R,{variant:"ghost",onClick:c,children:"Cancel"}),n.jsx(R,{variant:"danger",disabled:o||!d||s&&r==="",onClick:u,children:"Restore"})]})]})}function n5(){const[e,t]=f.useState(null),[s,r]=f.useState(""),[i,a]=f.useState(!1),[l,o]=f.useState(null),[c,u]=f.useState(!1),h=()=>{a(!0),o(null),T.backupPassphrase().then(m=>t(m.passphrase)).catch(m=>o(m instanceof pe?m.message:String(m))).finally(()=>a(!1))},d=()=>{a(!0),o(null),T.setBackupPassphrase(s.trim()).then(m=>{t(m.passphrase),r(""),u(!0)}).catch(m=>o(m instanceof pe?m.message:String(m))).finally(()=>a(!1))};return n.jsx(te,{title:"The passphrase",panel:!0,children:n.jsxs(J,{divided:!0,children:[n.jsx(te,{children:n.jsxs(J,{gap:"sm",children:[n.jsx(se,{message:l}),n.jsx("p",{className:"ui-card-meta",children:"This is the only thing that opens an encrypted backup. Write it down."}),e?n.jsx("p",{className:"backup-phrase mono",children:e}):n.jsx(Q,{align:"end",children:n.jsx(R,{disabled:i,onClick:h,children:"Show it"})}),c?n.jsx(H,{tone:"good",role:"status",children:"Saved. Backups made from now on use it; older ones keep the one they were made with."}):null]})}),n.jsx(te,{children:n.jsxs(J,{gap:"sm",children:[n.jsx(ee,{label:"Use my own",hint:"Six words you can read out loud beat a short one nobody can.",children:n.jsx("input",{type:"text",autoComplete:"off",value:s,onChange:m=>{u(!1),r(m.target.value)}})}),n.jsx(Q,{align:"end",children:n.jsx(R,{variant:"accent",disabled:i||s.trim()==="",onClick:d,children:"Use this one"})})]})})]})})}function s5({busy:e,checkout:t,checkoutSaid:s,database:r,onRestore:i}){const[a,l]=f.useState(null),[o,c]=f.useState(""),[u,h]=f.useState(""),[d,m]=f.useState(!1);return t?n.jsx(te,{title:"Restore from a file",panel:!0,children:n.jsx(te,{children:n.jsx(H,{tone:"warning",children:s??lE})})}):n.jsx(te,{title:"Restore from a file",panel:!0,children:n.jsxs(J,{divided:!0,children:[n.jsx(te,{children:n.jsxs(J,{gap:"sm",children:[n.jsx("p",{className:"ui-card-meta",children:"A backup from another buddi, or one you keep somewhere else."}),n.jsxs(bs,{children:[n.jsx(ee,{label:"The backup file",children:n.jsx("input",{type:"file",onChange:p=>{var x;m(!1),l(((x=p.target.files)==null?void 0:x[0])??null)}})}),n.jsx(ee,{label:"Its passphrase",hint:"Only if it was locked with one.",children:n.jsx("input",{type:"password",autoComplete:"off",value:o,onChange:p=>c(p.target.value)})})]}),d?null:n.jsx(Q,{align:"end",children:n.jsx(R,{variant:"accent",disabled:e||!a,onClick:()=>m(!0),children:"Restore"})})]})}),d&&a?n.jsx(te,{children:n.jsx(oE,{what:`${a.name}, ${$n(a.size)}`,database:r,needsPassphrase:!1,passphrase:o,onPassphrase:c,confirm:u,onConfirm:h,busy:e,onCancel:()=>m(!1),onGo:()=>i(a,o,u)})}):null]})})}const cE="gemini-2.5-pro";function sh(e){return e.replace(/^models\//,"")}const av=/(image|tts|audio|live|embedding|vision|robotics|transcribe)/;function uE(e){const t=e.map(sh);let s;for(const r of t){const i=/^gemini-(\d+(?:\.\d+)*)-pro(?:-(.+))?$/.exec(r);if(!i||av.test(i[2]??""))continue;const a=i[1].split(".").map(Number),l=(i[2]??"")!=="";(!s||cd(a,s.version)>0||cd(a,s.version)===0&&s.preview&&!l)&&(s={id:r,version:a,preview:l})}return(s==null?void 0:s.id)??t.find(r=>r.startsWith("gemini-"))}function dE(e){let t;for(const s of e.map(sh)){const r=/^gemini-(\d+(?:\.\d+)*)-flash(?:-(.+))?$/.exec(s);if(!r||/lite/.test(r[2]??"")||av.test(r[2]??""))continue;const i=r[1].split(".").map(Number),a=(r[2]??"")!=="";(!t||cd(i,t.version)>0||cd(i,t.version)===0&&t.preview&&!a)&&(t={id:s,version:i,preview:a})}return t==null?void 0:t.id}function hE(e){return/^gemini-[\d.]+-pro(?:-|$)/.test(sh(e))}function r5(e){return[...new Set(e.map(sh).filter(t=>t.startsWith("gemini-")&&!av.test(t)))]}function fE(e){return e.httpStatus===429||e.state==="rate-limited"||e.state==="quota-exhausted"}function cd(e,t){for(let s=0;s<Math.max(e.length,t.length);s+=1){const r=(e[s]??0)-(t[s]??0);if(r!==0)return r}return 0}function i5(e,t){if(!t||e.kind!=="openai-compatible")return!1;const s=r=>r.replace(/\/+$/,"");return s(e.baseUrl)===s(t)}function lv({code:e,label:t="Your code",large:s=!1}){const[r,i]=f.useState(!1),a=async()=>{var l;try{await((l=navigator.clipboard)==null?void 0:l.writeText(e)),i(!0)}catch{}};return n.jsxs(Q,{valign:"end",children:[n.jsx(ee,{label:t,grow:!0,children:n.jsx("input",{readOnly:!0,value:e,"data-code":s?"large":void 0,spellCheck:!1,onFocus:l=>l.currentTarget.select()})}),n.jsx(R,{onClick:()=>void a(),children:r?"Copied":"Copy"})]})}function a5({embedded:e}={}){const{data:t,error:s,reload:r,loading:i}=le(()=>T.providerAccounts(),[]),[a,l]=f.useState(!1),[o,c]=f.useState(null),[u,h]=f.useState(""),[d,m]=f.useState(!1),[p,x]=f.useState(!1),[j,b]=f.useState(null),g=t==null?void 0:t.accounts.some(N=>{var k;return((k=N.login)==null?void 0:k.state)==="pending"&&N.login.expiresAt&&Date.parse(N.login.expiresAt)>Date.now()});f.useEffect(()=>{if(!g)return;const N=setInterval(r,2e3);return()=>clearInterval(N)},[g,r]);const v=async(N,k)=>{l(!0),c(null),h(""),x(!1);try{const S=await N();return h((S==null?void 0:S.warning)??k),r(),!0}catch(S){return c(S instanceof Error?S.message:"Could not apply change."),r(),!1}finally{l(!1)}},w=(t==null?void 0:t.accounts)??[],y=w.find(N=>N.id===j)??w[0];return n.jsxs(yn,{embedded:e,title:"Model accounts",lede:"Give each API key or subscription a name, then pick one per agent. An account never falls back to another credential on its own.",children:[n.jsx(se,{message:s??o}),u&&n.jsx(H,{tone:"good",role:"status",children:u}),p&&n.jsx(H,{role:"status",children:i?"Refreshing account status…":s?"Could not refresh account status. Try again.":"Account status refreshed. This checks saved credentials; it does not renew subscription tokens or test connections."}),!t&&!s&&n.jsx(oe,{children:"Loading accounts…"}),s&&n.jsx(Q,{children:n.jsx(R,{onClick:r,children:"Retry"})}),t&&n.jsxs(n.Fragment,{children:[(t.vault.locked||t.vault.kind==="none")&&n.jsx(H,{tone:"warning",children:t.vault.advice||"Run buddi init on the host to configure secure credential storage."}),d&&n.jsx(wt,{title:"Add an account",onClose:()=>m(!1),children:n.jsx("div",{id:"new-provider-account",children:n.jsx(f5,{accounts:w,codexEnabled:t.codexEnabled,anthropicOAuthEnabled:t.anthropicOAuthEnabled,gemini:t.gemini,busy:a,run:v,onDone:N=>{m(!1),N&&b(N)}})})}),n.jsx(te,{title:"Accounts",aside:`Secrets live in the ${l5(t.vault.kind)}; Postgres holds names and assignments only.`,actions:n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",size:"sm",disabled:a||i,onClick:()=>{c(null),h(""),x(!0),r()},children:i?"Refreshing…":"Refresh status"}),n.jsx(R,{variant:"accent",size:"sm",disabled:a,"aria-expanded":d,"aria-controls":"new-provider-account",onClick:()=>m(!d),children:"Add account"})]}),panel:!0,flush:!0,children:w.length===0?n.jsx(tn,{icon:"chip",title:"No accounts yet",children:"Add one to give your agents a model to run on."}):n.jsxs("div",{className:"accounts",children:[n.jsx("nav",{className:"accounts-list","aria-label":"Accounts",children:w.map(N=>n.jsxs("button",{type:"button",className:"accounts-row","aria-pressed":(y==null?void 0:y.id)===N.id,onClick:()=>b(N.id),children:[n.jsx(o5,{kind:N.kind,auth:N.auth}),n.jsxs("span",{className:"accounts-row-text",children:[n.jsx("span",{className:"accounts-row-name",children:N.label}),n.jsxs("span",{className:"accounts-row-sub",children:[ov(N)," · ",N.assignedAgents.length===0?"no agents":`${N.assignedAgents.length} agent${N.assignedAgents.length===1?"":"s"}`]})]}),n.jsx(pE,{account:N})]},N.id))}),y?n.jsx(u5,{account:y,anthropicOAuthEnabled:t.anthropicOAuthEnabled,busy:a,run:v},`${y.id}:${y.revision}`):null]})})]})]})}function l5(e){return e==="keychain"?"macOS Keychain":e==="file"?"encrypted file vault":e==="none"?"vault (none configured)":e}function ov(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":rv(e)?"mlxh":"OpenAI-compatible"}function mE(e){return e.detectedContextWindowSource==="mlxh"?O6(e.detectedContextWindowTokens):e.detectedContextWindowSource!=="provider"?"assumed":e.kind==="codex"?"from ChatGPT":"from the provider"}function o5({kind:e,auth:t}){const s=e==="anthropic"?"A":e==="codex"?"G":e==="openai"?"O":"∞",r=e==="anthropic"?"3":e==="codex"?"2":e==="openai"?"5":"4";return n.jsx("span",{className:"ui-avatar","data-tint":r,"aria-hidden":"true",title:`${e} · ${t}`,children:s})}function c5(e){return e==="connected"?"good":["rate-limited","quota-exhausted","provider-unavailable"].includes(e)?"warning":"critical"}function pE({account:e}){const t=e.enabled?e.configured?"good":"warning":void 0,s=e.enabled?e.configured?"Configured":"Needs credential":"Disabled";return n.jsx(ge,{tone:t,children:s})}function cv(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 u5({account:e,busy:t,run:s,anthropicOAuthEnabled:r}){const[i,a]=f.useState(!1),[l,o]=f.useState(!1);return n.jsxs("section",{className:"accounts-detail","aria-label":e.label,children:[n.jsxs("div",{className:"ui-card-head",children:[n.jsx("h3",{className:"ui-card-title",children:e.label}),n.jsx(pE,{account:e})]}),n.jsx(Vt,{items:[{label:"Provider",value:ov(e)},{label:"Default model",value:n.jsx("span",{className:"mono",children:e.defaultModel||"—"})},{label:"Context window",value:n.jsx("span",{className:"mono",children:`${(e.contextWindowTokens??e.detectedContextWindowTokens??0).toLocaleString()} tokens${e.contextWindowTokens?"":` (${mE(e)})`}`})},...e.baseUrl?[{label:"Endpoint",value:n.jsx("span",{className:"mono",children:e.baseUrl})}]:[],{label:"Used by",value:e.assignedAgents.length?n.jsx("span",{className:"ui-row",children:e.assignedAgents.map(c=>n.jsx("a",{href:pt(c,"setup","brain"),children:c},c))}):n.jsxs("span",{className:"ui-row",children:[n.jsx("span",{className:"muted",children:"No agents"}),n.jsx("a",{href:mt,children:"Assign to an agent"})]})},...e.tokenExpiresAt?[{label:"Access token",value:`expires ${new Date(e.tokenExpiresAt).toLocaleString()} (not your subscription renewal date)`}]:[]]}),e.removalPending&&n.jsx(H,{tone:"warning",children:"Removal is pending. Unlock the vault, then retry Remove account."}),e.reconnectRequired&&n.jsxs(H,{tone:"warning",children:["Token refresh did not finish. Reconnect this ",e.kind==="codex"?"ChatGPT":"Claude"," account."]}),e.auth==="anthropic-oauth"&&n.jsx(vE,{account:e,enabled:!!r,busy:t,run:s}),e.kind==="codex"&&n.jsx(gE,{account:e,busy:t,run:s}),e.auth==="device-key"&&n.jsx(xE,{account:e,busy:t,run:s}),n.jsxs(Q,{children:[n.jsx(R,{disabled:t||e.removalPending,onClick:()=>a(!0),children:"Edit account"}),n.jsx(R,{disabled:t||e.removalPending,onClick:()=>void s(()=>T.saveProviderAccount({...cv(e),enabled:!e.enabled}),e.enabled?"Account disabled. Subsequent model calls will stop; already-sent requests cannot be recalled.":"Account enabled."),children:e.enabled?"Disable":"Enable"}),e.kind!=="codex"&&n.jsx(R,{disabled:t||!e.enabled||!e.configured,onClick:()=>void s(()=>T.testProviderAccount(e.id),"Connection test finished."),children:"Test connection"}),n.jsx(R,{variant:"danger",disabled:t||e.assignedAgents.length>0,title:e.assignedAgents.length?"Reassign its agents before removing this account":void 0,onClick:()=>o(!0),children:"Remove account"})]}),e.test&&n.jsxs(n.Fragment,{children:[n.jsxs(H,{role:"status",tone:c5(e.test.state),children:[n.jsx("p",{children:e.test.message}),e.test.retryAt?n.jsxs("p",{children:["Provider suggested retry time: ",new Date(e.test.retryAt).toLocaleString(),". This is retry advice, not a guaranteed quota reset."]}):["rate-limited","quota-exhausted"].includes(e.test.state)&&n.jsx("p",{children:"The provider did not supply a usable Retry-After time. Reset time is unknown."})]}),n.jsxs("p",{className:"muted",children:["Tested at ",new Date(e.test.checkedAt).toLocaleString(),e.test.httpStatus?` · HTTP ${e.test.httpStatus}`:"",". This is not a quota reset or subscription renewal date."]})]}),i&&n.jsx(wt,{title:`Edit ${e.label}`,onClose:()=>a(!1),children:n.jsx(d5,{account:e,busy:t,run:s,onDone:()=>a(!1)})}),l&&n.jsxs(H,{tone:"critical",children:[n.jsxs("p",{children:["Remove “",e.label,"” and its stored credential from Buddi? This does not revoke it at the provider or remove it from backups."]}),n.jsxs(Q,{children:[n.jsx(R,{variant:"danger",disabled:t,onClick:()=>void s(()=>T.removeProviderAccount(e.id,e.revision),"Account removed from Buddi."),children:"Confirm removal"}),n.jsx(R,{disabled:t,onClick:()=>o(!1),children:"Cancel"})]})]}),n.jsx($t,{summary:"Details",children:n.jsxs("div",{className:"ui-prose muted",children:[e.kind==="codex"?n.jsxs(n.Fragment,{children:[n.jsx("p",{children:"Talks to OpenAI’s Codex backend directly with your ChatGPT sign-in. The credential stays in buddi’s vault; buddi refreshes it and never reads your own Codex login."}),n.jsx("p",{children:"Native tool-step usage reporting is incomplete. Do not use Buddi’s token or API-cost estimates as subscription billing or remaining quota."}),n.jsx("p",{children:"After connecting, assign this account to an agent and send a test message. Model turns use your subscription allowance."})]}):n.jsx("p",{children:"Testing sends a small fixed prompt and may incur a charge. No conversation or files are sent. Configured does not mean verified."}),e.auth==="device-key"&&n.jsx("p",{children:"Ollama Cloud with a device key: buddi made a key pair and keeps it in the vault; ollama.com only ever saw the public half and this computer’s name. Each request to ollama.com is signed with the key, and nothing else is sent with it. Disconnect asks ollama.com to forget the device and removes the key from buddi either way."}),e.auth==="anthropic-oauth"&&n.jsx("p",{children:"Claude subscription sign-in. Tokens remain in Buddi’s vault and refresh before use. Uses your plan’s monthly Agent SDK credits; after them, an API key. Remaining credits are unknown here."}),n.jsx("p",{children:"Subscription login is separate from API-key access."})]})})]})}function gE({account:e,busy:t,run:s}){var r,i,a;return n.jsxs(n.Fragment,{children:[n.jsxs(Q,{children:[n.jsx(R,{disabled:t||!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"}),((i=e.login)==null?void 0:i.state)==="pending"&&n.jsx(R,{disabled:t,onClick:()=>void s(()=>T.codexAccountAction(e.id,"cancel-login",e.revision),"Sign-in cancelled."),children:"Cancel sign-in"}),n.jsx(R,{disabled:t||!e.configured,onClick:()=>void s(()=>T.codexAccountAction(e.id,"logout",e.revision),"Subscription disconnected from Buddi. Your regular Codex login is unchanged."),children:"Disconnect"})]}),((a=e.login)==null?void 0:a.state)==="pending"&&n.jsxs(H,{tone:"accent",role:"status",children:[n.jsxs("p",{children:["Here is your code: ",n.jsx("strong",{children:e.login.userCode}),". Open the link, enter it, and approve buddi on openai.com."]}),e.login.userCode&&n.jsx(lv,{code:e.login.userCode}),e.login.verificationUrl&&n.jsx(Q,{children:n.jsx(Zt,{variant:"accent",href:e.login.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open openai.com"})}),e.login.expiresAt&&n.jsxs("p",{className:"muted",children:["The code works until ",new Date(e.login.expiresAt).toLocaleTimeString(),". Start again after that; this is the sign-in timeout, not your subscription expiry."]})]}),e.login&&e.login.state!=="pending"&&n.jsx("p",{role:"status",className:"muted",children:e.login.message??`Sign-in ${e.login.state}.`})]})}function d5({account:e,busy:t,run:s,onDone:r,codexEnabled:i,anthropicOAuthEnabled:a}){const[l,o]=f.useState((e==null?void 0:e.label)??""),[c,u]=f.useState((e==null?void 0:e.kind)??"anthropic"),[h,d]=f.useState((e==null?void 0:e.auth)??"api-key"),[m,p]=f.useState((e==null?void 0:e.baseUrl)??""),[x,j]=f.useState((e==null?void 0:e.defaultModel)??"claude-sonnet-5"),[b,g]=f.useState(""),[v,w]=f.useState(e!=null&&e.contextWindowTokens?String(e.contextWindowTokens):""),y=k=>{u(k),d(k==="codex"?"chatgpt":"api-key"),g(""),p(k==="openai-compatible"?"http://localhost:11434/v1":""),j(k==="anthropic"?"claude-sonnet-5":k==="openai"?"gpt-5":"")},N=!l.trim()||!x.trim();return n.jsxs("form",{className:"ui-stack",onSubmit:k=>{k.preventDefault();const S=b;g(""),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,...S.trim()?{secret:S}:{}}),"Account saved. Agent model selections are unchanged.").then(C=>{C&&r()})},children:[n.jsxs("fieldset",{disabled:t,className:"ui-fields","data-stack":"true",children:[n.jsx(ee,{label:"Account name",children:n.jsx("input",{autoFocus:!0,required:!0,maxLength:100,value:l,onChange:k=>o(k.target.value),placeholder:"Anthropic — Personal"})}),n.jsx(ee,{label:"Provider",children:n.jsxs("select",{disabled:!!e,value:h==="anthropic-oauth"?"anthropic-oauth":h==="device-key"?"ollama-cloud":c,onChange:k=>{k.target.value==="anthropic-oauth"?(y("anthropic"),d("anthropic-oauth")):y(k.target.value)},children:[n.jsx("option",{value:"anthropic",children:"Anthropic API"}),n.jsx("option",{value:"openai",children:"OpenAI API"}),n.jsx("option",{value:"openai-compatible",children:"OpenAI-compatible endpoint"}),(e==null?void 0:e.auth)==="device-key"&&n.jsx("option",{value:"ollama-cloud",children:"Ollama Cloud"}),(a||(e==null?void 0:e.auth)==="anthropic-oauth")&&n.jsx("option",{value:"anthropic-oauth",children:"Claude subscription"}),(i||(e==null?void 0:e.kind)==="codex")&&n.jsx("option",{value:"codex",children:"ChatGPT subscription"})]})}),c==="openai-compatible"&&h!=="device-key"&&n.jsxs(n.Fragment,{children:[n.jsx(ee,{label:"API base URL",hint:"Include the API path, such as /v1 or /api/v1. Conversation data will be sent to this endpoint. The model must support tool calling to use agent tools.",children:n.jsx("input",{required:!0,type:"url",value:m,onChange:k=>p(k.target.value)})}),n.jsx(ee,{label:"Authentication",children:n.jsxs("select",{disabled:!!e,value:h,onChange:k=>{d(k.target.value),g("")},children:[n.jsx("option",{value:"api-key",children:"API key"}),n.jsx("option",{value:"none",children:"No key (local/self-hosted)"})]})})]}),n.jsx(Q,{valign:"end",children:n.jsx(iv,{accountId:e!=null&&e.configured&&e.enabled?e.id:void 0,label:"Default model",value:x,onChange:j,disabled:t},`${e==null?void 0:e.id}:${e==null?void 0:e.revision}`)}),n.jsx(ee,{label:"Context window",hint:rv(e)?"mlxh refuses a prompt over its max_prompt_tokens, and its model manager does not report the number, so buddi assumes 8,192. After `mlxh config max_prompt_tokens 40960`, enter the same number here.":"Tokens this endpoint actually serves. Leave blank unless you run the model yourself and set a window of your own — a conversation is ended once its history would fill half of this.",children:n.jsx("input",{type:"number",inputMode:"numeric",min:8e3,max:2e6,step:1e3,value:v,placeholder:e!=null&&e.detectedContextWindowTokens?`${e.detectedContextWindowTokens} (${mE(e)})`:"assumed from the model",onChange:k=>w(k.target.value)})}),c==="codex"&&n.jsx("p",{className:"muted",children:"Pick a model from the list once the account is connected."}),h==="anthropic-oauth"&&n.jsx("p",{className:"muted",children:"Save this account, then choose Connect Claude. You will approve in your browser and paste the authorization code here, not in chat. No existing agent assignment changes."}),h==="api-key"&&n.jsx(ee,{label:e?"Replacement API key (leave blank to keep)":"API key",children:n.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,value:b,onChange:k=>g(k.target.value)})}),e&&n.jsx("p",{className:"muted",children:"Saving changes stops an active run at its next model call. Start a new turn afterward. Changing the default model does not change existing agent assignments."}),n.jsxs(Q,{align:"end",children:[n.jsx(R,{onClick:r,children:"Cancel"}),n.jsx(R,{type:"submit",variant:"accent",disabled:N,children:"Save account"})]})]}),N&&n.jsx("p",{className:"muted",children:"Enter an account name and default model to enable Save account. The example name is a placeholder."})]})}function xE({account:e,busy:t,run:s}){var o;const r=((o=e.login)==null?void 0:o.state)==="pending"&&e.login.attemptId?e.login:null,i=f.useRef(s);i.current=s,f.useEffect(()=>{if(!(r!=null&&r.attemptId))return;let c=!1,u=!1;const h=setInterval(()=>{c||u||(u=!0,T.ollamaPoll(e.id,r.attemptId).then(d=>{c||d.state==="waiting"||(c=!0,d.state==="connected"?i.current(async()=>{},`Connected as ${d.username}, device ${d.deviceName}.`):i.current(async()=>{throw new Error(d.message)},""))}).catch(()=>{}).finally(()=>{u=!1}))},2e3);return()=>{c=!0,clearInterval(h)}},[e.id,r==null?void 0:r.attemptId]);const a=()=>{const c=typeof window.open=="function"?window.open("","_blank"):null;s(async()=>{try{const u=await T.ollamaConnect(e.id,e.revision);return c&&(c.location.href=u.verificationUrl),u}catch(u){throw c==null||c.close(),u}},"Press Connect on the ollama.com page. This card notices on its own.")},l=e.device;return n.jsxs(n.Fragment,{children:[l&&n.jsx("p",{className:"muted",role:"status",children:l.connectedAt?`Connected as ${l.username||"an ollama.com account"}, device ${l.deviceName}.`:`Not connected yet. Device ${l.deviceName}.`}),n.jsxs(Q,{children:[n.jsx(R,{disabled:t||!e.enabled||e.removalPending||!!r,onClick:a,children:e.configured?"Reconnect Ollama":"Connect Ollama"}),n.jsx(R,{disabled:t||!l||e.removalPending,onClick:()=>void s(async()=>({warning:(await T.ollamaDisconnect(e.id,e.revision)).note}),"Disconnected."),children:"Disconnect"})]}),r&&n.jsxs(H,{tone:"accent",role:"status",children:[n.jsxs("p",{children:[n.jsx("a",{href:r.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open the ollama.com page"})," and press Connect. Sign in there first if it asks."]}),n.jsxs("p",{className:"muted",children:["buddi stops waiting at ",r.expiresAt&&new Date(r.expiresAt).toLocaleTimeString(),"."]})]})]})}function vE({account:e,enabled:t,busy:s,run:r}){var l,o,c,u,h;const[i,a]=f.useState("");return f.useEffect(()=>{a("")},[(l=e.login)==null?void 0:l.attemptId,(o=e.login)==null?void 0:o.state]),n.jsxs(n.Fragment,{children:[!t&&n.jsx(H,{tone:"warning",children:"Claude subscription sign-in is turned off on this host."}),n.jsxs(Q,{children:[n.jsx(R,{disabled:s||!t||!e.enabled||e.removalPending||((c=e.login)==null?void 0:c.state)==="pending",onClick:()=>void r(()=>T.anthropicAccountAction(e.id,"login",e.revision),"Open the Claude consent link below. Existing credentials remain until sign-in succeeds."),children:e.configured?"Reconnect Claude":"Connect Claude"}),((u=e.login)==null?void 0:u.state)==="pending"&&n.jsx(R,{disabled:s,onClick:()=>{a(""),r(()=>T.anthropicAccountAction(e.id,"cancel-login",e.revision),"Claude sign-in cancelled.")},children:"Cancel sign-in"}),n.jsx(R,{disabled:s||!e.configured||e.removalPending,onClick:()=>{a(""),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"&&n.jsxs("form",{className:"ui-notice","data-tone":"accent",onSubmit:d=>{d.preventDefault();const m=i;a(""),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:[n.jsx("p",{children:n.jsx("a",{href:e.login.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open Claude consent page"})}),n.jsxs("p",{className:"muted",children:["Use the Claude account you want to connect. Paste the entire code including #state. This attempt expires at ",e.login.expiresAt&&new Date(e.login.expiresAt).toLocaleTimeString(),"; restarting Buddi also ends it."]}),n.jsx(ee,{label:"Claude authorization code",children:n.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,maxLength:8192,value:i,onChange:d=>a(d.target.value),disabled:s})}),n.jsx(Q,{align:"end",children:n.jsx(R,{type:"submit",variant:"accent",disabled:s||!i.trim(),children:"Complete Claude sign-in"})})]})]})}const kf={anthropic:"claude-sonnet-5",openai:"gpt-5",codex:"gpt-5.5"};function Sf(e,t,s){return $p(e==="codex"?"ChatGPT subscription":e==="anthropic"?t==="anthropic-oauth"?"Claude subscription":"Anthropic API":e==="openai"?"OpenAI API":t==="device-key"?"Ollama Cloud":"Local endpoint",s)}function $p(e,t){const s=new Set(t.map(r=>r.trim().toLowerCase()));if(!s.has(e.toLowerCase()))return e;for(let r=2;r<100;r+=1)if(!s.has(`${e} ${r}`.toLowerCase()))return`${e} ${r}`;return e}const h5="That key was refused. Check it and paste it again.";function f5({accounts:e,busy:t,run:s,onDone:r,codexEnabled:i,anthropicOAuthEnabled:a,gemini:l}){const o=e.map(fe=>fe.label),[c,u]=f.useState(null),[h,d]=f.useState("anthropic"),[m,p]=f.useState("api-key"),[x,j]=f.useState(()=>Sf("anthropic","api-key",o)),[b,g]=f.useState(!1),[v,w]=f.useState(""),[y,N]=f.useState(""),[k,S]=f.useState(null),[C,I]=f.useState(!1),[A,O]=f.useState(""),[z,L]=f.useState(""),[E,$]=f.useState(!1),[_,B]=f.useState(!1),[M,W]=f.useState(!1),[D,U]=f.useState(void 0),V=(fe,Me,ce=!1)=>{d(fe),p(Me),N(""),S(null),O(""),L(""),$(!1),B(ce),W(!1),U(void 0),w(ce?"":fe==="openai-compatible"?"http://localhost:11434/v1":""),b||j(ce?Sf(fe,"device-key",o):Sf(fe,Me,o))},Z=fe=>{V("openai-compatible",fe?"api-key":"device-key",!0),fe&&T.ollama().then(Me=>w(Me.cloudBaseUrl)).catch(()=>{})},ue=()=>{l&&(V("openai-compatible","api-key"),W(!0),w(l.baseUrl),b||j($p("Gemini",o)))},Ae=()=>{V("openai-compatible","none"),U(null),b||j($p("mlxh",o)),T.mlxh().then(fe=>{U(fe),w(fe.baseUrl)}).catch(()=>U(void 0))},X=D!==void 0,ae=c?e.find(fe=>fe.id===c):void 0;if(c)return ae?n.jsx(m5,{account:ae,busy:t,run:s,anthropicOAuthEnabled:a,onDone:()=>r(ae.id)}):n.jsx(oe,{children:"Saving…"});const me=h==="openai-compatible"&&m!=="device-key",Pe=h==="codex"||m==="anthropic-oauth"||m==="device-key",ke=!Pe&&(m==="none"||y.trim()!=="")&&(!me||v.trim()!==""),ye=async()=>{var fe,Me;I(!0),O("");try{const ce=await T.probeModels({kind:h,auth:m,...me?{baseUrl:v}:{},...y.trim()?{secret:y}:{}});S(ce),z||L(((fe=ce.models.find(Te=>Te.isDefault))==null?void 0:fe.id)??((Me=ce.models[0])==null?void 0:Me.id)??"")}catch(ce){O(ce instanceof Error?ce.message:"Could not load models. You can still enter a custom model.")}finally{I(!1)}},Ce=z.trim(),ut=!x.trim()||me&&!v.trim()||me&&!M&&!X&&!Ce||M&&!y.trim()||X&&!(D!=null&&D.running);return n.jsxs("form",{className:"ui-stack",onSubmit:fe=>{var G;fe.preventDefault();const Me=y;N("");let ce=Ce||(X?Rp(D)??((G=D==null?void 0:D.models[0])==null?void 0:G.id):void 0)||(m==="device-key"?cu:kf[h])||"claude-sonnet-5",Te;(async()=>{if(M){ce=cE;try{const it=(await T.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:v,secret:Me})).models.map(ht=>ht.id);ce=uE(it)??ce,Te=hE(ce)?dE(it):void 0}catch{}}let ie,$e=!1;!await s(async()=>{if(ie=await T.saveProviderAccount({label:x,kind:h,auth:m,baseUrl:v,defaultModel:ce,enabled:!0,...Me.trim()?{secret:Me}:{}}),m!=="api-key")return ie;const Ge=await T.testProviderAccount(ie.id);if(Ge.state==="connected")return ie;if(nx(Ge)){const it=ie.id;ie=void 0;try{const ht=(await T.providerAccounts()).accounts.find(Y=>Y.id===it);ht&&await T.removeProviderAccount(it,ht.revision)}catch{}throw new Error(h5)}if(M&&Te&&fE(Ge)){const it=(await T.providerAccounts()).accounts.find(ht=>ht.id===ie.id);if(it&&(await T.saveProviderAccount({...cv(it),defaultModel:Te}),(await T.testProviderAccount(ie.id)).state==="connected"))return{...ie,warning:`Account saved. Google's free tier has no Pro allowance, so it starts on ${Te}; turn on billing at Google to use Pro.`}}return $e=!0,{...ie,warning:`Account saved. ${Ge.message}`}},"Account saved.")||!ie||(M||X||$e?u(ie.id):Ce||!Pe?r(ie.id):u(ie.id))})()},children:[n.jsxs("fieldset",{disabled:t,className:"ui-fields","data-stack":"true",children:[n.jsx(ee,{label:"Provider",children:n.jsxs("select",{value:m==="anthropic-oauth"?"anthropic-oauth":_?"ollama-cloud":M?"gemini":X?"mlxh":h,onChange:fe=>{if(fe.target.value==="anthropic-oauth")V("anthropic","anthropic-oauth");else if(fe.target.value==="gemini")ue();else if(fe.target.value==="mlxh")Ae();else if(fe.target.value==="ollama-cloud")V("openai-compatible","device-key",!0);else{const Me=fe.target.value;V(Me,Me==="codex"?"chatgpt":"api-key")}},children:[n.jsx("option",{value:"anthropic",children:"Anthropic API"}),n.jsx("option",{value:"openai",children:"OpenAI API"}),l&&n.jsx("option",{value:"gemini",children:"Gemini (Google AI key)"}),n.jsx("option",{value:"ollama-cloud",children:"Ollama Cloud"}),n.jsx("option",{value:"mlxh",children:"mlxh, local MLX models on this Mac"}),n.jsx("option",{value:"openai-compatible",children:"OpenAI-compatible endpoint (Ollama, OpenRouter, vLLM…)"}),a&&n.jsx("option",{value:"anthropic-oauth",children:"Claude subscription"}),i&&n.jsx("option",{value:"codex",children:"ChatGPT subscription"})]})}),n.jsx(ee,{label:"Account name",hint:"Proposed from the provider. Change it to anything you will recognise.",children:n.jsx("input",{autoFocus:!0,required:!0,maxLength:100,value:x,onChange:fe=>{j(fe.target.value),g(!0)},placeholder:"Anthropic — Personal"})}),_&&n.jsxs("label",{className:"ui-row",children:[n.jsx("input",{type:"checkbox",checked:m==="api-key",onChange:fe=>Z(fe.target.checked)}),n.jsx("span",{children:"Use a key instead"})]}),me&&n.jsxs(n.Fragment,{children:[n.jsx(ee,{label:"API base URL",hint:"Include the API path, such as /v1 or /api/v1. Conversation data will be sent to this endpoint. The model must support tool calling to use agent tools.",children:n.jsx("input",{required:!0,type:"url",value:v,onChange:fe=>{w(fe.target.value),S(null)}})}),!M&&!X&&n.jsx(ee,{label:"Authentication",children:n.jsxs("select",{value:m,onChange:fe=>{p(fe.target.value),N(""),S(null)},children:[n.jsx("option",{value:"api-key",children:"API key"}),n.jsx("option",{value:"none",children:"No key (local/self-hosted)"})]})})]}),m==="api-key"&&n.jsx(ee,{label:"API key",hint:"Stored in the vault, never shown again.",children:n.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,value:y,onChange:fe=>{N(fe.target.value),S(null)}})}),X?D===null?n.jsx("p",{className:"muted",children:"Looking for mlxh on this computer…"}):D!=null&&D.running?n.jsxs(J,{gap:"sm",children:[n.jsxs("p",{className:"muted",children:["mlxh answers with ",D.models.length===1?"one model":`${D.models.length} models`,". No key: mlxh takes any. buddi starts on ",Rp(D)??"the first","; the next step lists the rest. A model that is not loaded takes up to a minute on its first answer."]}),D.models.some(fe=>fe.kind==="image")?n.jsxs("p",{className:"muted",children:[D.models.filter(fe=>fe.kind==="image").map(fe=>fe.id).join(", "),": ",YC,"."]}):null]}):n.jsx(H,{tone:"warning",children:GC((D==null?void 0:D.baseUrl)??v)}):M&&l?n.jsxs("p",{className:"muted",children:[n.jsx("a",{href:l.keyUrl,target:"_blank",rel:"noreferrer",children:"Get a key at aistudio.google.com"}),". buddi picks the newest Gemini Pro your key can reach; the next step lists the rest."]}):Pe?n.jsx("p",{className:"muted",children:h==="codex"?"You will connect your ChatGPT subscription on the next step, with a code you enter on openai.com, and pick a model then.":m==="device-key"?"You will connect on the next step: ollama.com opens, you press Connect, and no key is typed. Free to start.":"You will connect your Claude subscription on the next step, in your browser, and pick a model then."}):n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Model"}),k?n.jsxs("div",{className:"ui-row",children:[n.jsxs("select",{"aria-label":"Model",value:E?"__custom__":z,onChange:fe=>{fe.target.value==="__custom__"?($(!0),L("")):($(!1),L(fe.target.value))},children:[k.models.map(fe=>n.jsxs("option",{value:fe.id,children:[fe.name===fe.id?fe.id:`${fe.name} — ${fe.id}`,fe.isDefault?" (provider default)":"",fe.thinks?" · thinks":""]},fe.id)),n.jsx("option",{value:"__custom__",children:"Custom model…"})]}),n.jsx(R,{size:"sm",disabled:C||!ke,onClick:()=>void ye(),children:C?"Loading…":"Reload"})]}):n.jsxs("div",{className:"ui-row",children:[n.jsx(R,{disabled:C||!ke,onClick:()=>void ye(),children:C?"Loading models…":"Load models"}),me?n.jsx("span",{className:"muted",children:"Ask the endpoint what it serves."}):n.jsxs("span",{className:"muted",children:["Optional now: ",kf[h]," is used until you pick one."]})]}),E||me&&!k?n.jsx("input",{"aria-label":"Custom model",required:me,maxLength:150,value:z,onChange:fe=>L(fe.target.value),placeholder:me?"qwen3:8b":kf[h]}):null,A?n.jsx("span",{className:"ui-field-hint critical",role:"alert",children:A}):null,k!=null&&k.truncated?n.jsx("span",{className:"ui-field-hint",children:"Showing the first part of the provider’s list."}):null]}),n.jsxs(Q,{align:"end",children:[n.jsx(R,{onClick:()=>r(),children:"Cancel"}),n.jsx(R,{type:"submit",variant:"accent",disabled:ut,children:"Save account"})]})]}),ut&&!X&&n.jsxs("p",{className:"muted",children:["Enter an account name",M?" and a key":me?", an endpoint and a model":""," to enable Save account."]})]})}function m5({account:e,busy:t,run:s,anthropicOAuthEnabled:r,onDone:i}){const[a,l]=f.useState(e.defaultModel),o=e.configured;return n.jsxs(J,{gap:"lg",children:[n.jsxs(H,{tone:"good",children:["Saved “",e.label,"”."]}),e.auth==="anthropic-oauth"&&!o?n.jsx(vE,{account:e,enabled:!!r,busy:t,run:s}):null,e.kind==="codex"&&!o?n.jsx(gE,{account:e,busy:t,run:s}):null,e.auth==="device-key"&&!o?n.jsx(xE,{account:e,busy:t,run:s}):null,o?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"ui-page-lede",children:"Pick the model this account offers by default. An agent can still choose another when you assign it."}),n.jsx(Q,{valign:"end",children:n.jsx(iv,{accountId:e.enabled?e.id:void 0,label:"Default model",value:a,onChange:l,disabled:t},`${e.id}:${e.revision}`)}),n.jsxs(Q,{align:"end",children:[n.jsx(R,{onClick:i,children:"Skip for now"}),n.jsx(R,{variant:"accent",disabled:t||!a.trim(),onClick:()=>{if(a===e.defaultModel){i();return}s(()=>T.saveProviderAccount({...cv(e),defaultModel:a}),"Default model saved.").then(c=>{c&&i()})},children:"Done"})]})]}):n.jsx(Q,{children:n.jsx(R,{onClick:i,children:"Finish later"})})]})}const eb=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 p5(e){const t=e.toLowerCase().replace(/\.$/,"");if(!t.includes(".")||eb.has(t))return!0;const s=t.slice(t.indexOf(".")+1);return eb.has(`*.${s}`)}function g5(e){return typeof e=="string"&&e.includes("*")}function x5(e){const t=/^(https?):\/\/([^/?#@\s]+)(?:[/?#]\S*)?$/i.exec(e.trim());if(t===null)return{ok:!1,reason:"invalid"};const[,s,r]=t;if(!r.startsWith("*.")||r.slice(2).includes("*"))return{ok:!1,reason:"placement"};let i;try{i=new URL(`${s.toLowerCase()}://${r.slice(2)}`)}catch{return{ok:!1,reason:"invalid"}}const a=i.hostname;return a===""||a.startsWith("[")||/^[\d.]+$/.test(a)||a.startsWith(".")||a.includes("..")?{ok:!1,reason:"invalid"}:p5(a)?{ok:!1,reason:"public-suffix"}:{ok:!0,value:{pattern:`${i.protocol}//*.${i.host}`,protocol:i.protocol,suffix:a,port:i.port}}}const tb=["every-time","first-time","pre-approved"],jE={"every-time":"every time","first-time":"first time only","pre-approved":"pre-approved"};function v5(e){const t=tb.indexOf(e);return tb.slice(0,t<0?1:t+1)}function wE(e){return e.endsWith(".account")}const j5="This account’s process holds the value for as long as its connection lives.",uv="Stored, not usable until it has a binding.";function w5(e){return e==="browser.field"?"the origin of the site that holds the field, e.g. https://en.wikipedia.org or *.wikimedia.org":e==="browser.form.data"?"the origin, then the field name — e.g. https://localhost:8443 card-number":e==="browser.native.type"?"the app’s bundle id, e.g. com.bank.app":e==="http.header"?"the host, then the header name — e.g. localhost:9200 Authorization":e==="http.url"?"the plugin, then the host — e.g. calendar calendar.google.com":e==="developer.env"?"the workspace, then the variable name — e.g. cour des comptes ADMIN_PASSWORD":wE(e)?"the account id, e.g. acct-1":'the place, as JSON — e.g. {"host":"localhost","header":"Authorization"}'}const yE={"browser.form.data":{hint:"an origin, then the field name",build:(e,t)=>({origin:e,field:t})},"http.header":{hint:"a host, then the header name",build:(e,t)=>({host:e,header:t})},"http.url":{hint:"a plugin, then the host",build:(e,t)=>({plugin:e,host:t})},"developer.env":{hint:"a workspace, then the variable name",build:(e,t)=>({workspace:e,variable:t})}},y5="A wildcard may only stand for the leftmost part of a site, like *.wikimedia.org.",b5=e=>`That is a public suffix; ${e} would match every site.`,nb="Give the site as an origin, like https://en.wikipedia.org.";function sb(e){const t=/^[a-z][a-z0-9+.-]*:\/\//i.test(e)?e:["https:","//",e].join("");if(g5(e)){const s=x5(t);if(s.ok)return{ok:!0,target:s.value.pattern};if(s.reason==="placement")return{ok:!1,error:y5};if(s.reason==="public-suffix"){const r=t.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/[/?#:].*$/,"").toLowerCase();return{ok:!1,error:b5(r)}}return{ok:!1,error:nb}}try{const s=new URL(t);if(s.origin==="null"||s.protocol!=="https:"&&s.protocol!=="http:")throw new Error("not an origin");return{ok:!0,target:s.origin}}catch{return{ok:!1,error:nb}}}function k5(e){const t=e.search(/\s\S+\s*$/);if(t<=0)return null;const s=e.slice(t).trim(),r=e.slice(0,t).trim();return r&&s?[r,s]:null}function bE(e,t){const s=t.trim();if(s==="")return{ok:!1,error:"Give the exact place this value may go."};if(s.startsWith("{"))try{const a=JSON.parse(s);return a!==null&&typeof a=="object"&&!Array.isArray(a)?{ok:!0,target:a}:{ok:!1,error:'A target in JSON is an object, like {"host":"localhost","header":"Authorization"}.'}}catch{return{ok:!1,error:"That opens like JSON but does not parse."}}if(e==="browser.field")return sb(s);if(e==="browser.native.type"||wE(e))return{ok:!0,target:s};const r=yE[e];if(r===void 0)return{ok:!0,target:s};const i=k5(s);if(i===null)return{ok:!1,error:`${e} needs both: ${r.hint}.`};if(e==="browser.form.data"){const a=sb(i[0]);return a.ok?{ok:!0,target:r.build(a.target,i[1])}:a}return{ok:!0,target:r.build(i[0],i[1])}}function S5(e){if(typeof e=="string")return e;try{return JSON.stringify(e)??""}catch{return""}}function N5(e,t){if(typeof t=="string")return t;if(t!==null&&typeof t=="object"&&!Array.isArray(t)){const s=t,r=yE[e];if(r!==void 0){const i=Object.keys(r.build("a","b")),a=i.map(l=>s[l]);if(i.every(l=>typeof s[l]=="string"))return a.join(" · ")}}try{return JSON.stringify(t)??String(t)}catch{return String(t)}}const kE="accounts.provider";function C5(e,t){for(const s of e)if(s.kind===kE&&typeof s.target=="string"){const r=t.get(s.target);if(r)return r}}function Mp(e,t,s){if(e===kE&&typeof t=="string"){const r=s.get(t);if(r)return r.label}return N5(e,t)}function SE(e){if(e==="delivered")return"good";if(e==="held"||e==="pending")return"warning";if(e==="refused"||e==="failed")return"critical"}function NE(e,t){if(typeof e!="object"||e===null)return[];const s=e[t];return Array.isArray(s)?s.flatMap(r=>{if(typeof r!="object"||r===null)return[];const i=r.place,a=r.count;return typeof i!="string"||typeof a!="number"||!(a>0)?[]:[{place:i,count:a}]}):[]}function CE(e){const t=e.map(({place:s,count:r})=>`${r.toLocaleString("en-GB")} ${r===1?s.replace(/s$/,""):s}`);return t.length<=1?t[0]??"":`${t.slice(0,-1).join(", ")} and ${t[t.length-1]}`}function E5(e){const t=NE(e,"found");return t.length?`The value already sits in ${CE(t)}.`:""}function A5(e){const t=NE(e,"scrubbed");return t.length?`Replaced with ‹secret:…› in ${CE(t)}.`:""}async function zi(e,t,s,r){s(!0),r(null);try{return(await T.secretsAct(e,t)).result}catch(i){return r(i instanceof Error?i.message:String(i)),null}finally{s(!1)}}function T5({embedded:e,timezone:t}={}){const s=le(()=>T.secrets(),[]),r=le(()=>T.providerAccounts(),[]),i=f.useMemo(()=>{var c;return new Map((((c=r.data)==null?void 0:c.accounts)??[]).map(u=>[u.id,{label:u.label,provider:ov(u)}]))},[r.data]),[a,l]=f.useState(!1),o=s.data;return n.jsxs(yn,{embedded:e,title:"Keys and secrets",lede:"What the agents may use and never see: a name, a value buddi keeps, and the exact places the value may go.",children:[n.jsxs(J,{gap:"lg",children:[!o&&!s.error?n.jsx(oe,{children:"Opening the vault…"}):null,s.error?n.jsx(Q,{children:n.jsx(R,{onClick:s.reload,children:"Retry"})}):null,o?n.jsx(te,{title:"Secrets",aside:"A value the agents use and never see: bound to where it may go, never shown again.",actions:n.jsx(R,{variant:"accent",size:"sm",onClick:()=>l(!0),children:"Add a secret"}),panel:!0,children:n.jsx(J,{divided:!0,children:o.secrets.length===0?n.jsx(tn,{icon:"key",title:"Nothing stored yet",children:"Add one — a site password, an API token — and bind it to the places an agent may use it."}):o.secrets.map(c=>n.jsx(R5,{secret:c,accounts:i,destinations:o.destinations,timezone:t,onChanged:s.reload},c.name))})}):null,o?n.jsx(te,{title:"buddi’s own keys",aside:"Read-only.",children:n.jsxs(J,{gap:"sm",children:[o.ownKeys.length===0?n.jsx(oe,{children:"No keys of buddi’s own right now."}):n.jsx("div",{className:"ui-list",children:o.ownKeys.map(c=>n.jsx("div",{className:"ui-list-row",children:n.jsx("span",{className:"ui-list-main",children:n.jsx("span",{className:"mono",children:c})})},c))}),n.jsx("p",{className:"ui-card-meta",children:"These are the keys buddi itself runs on. They cannot be bound or replaced here, and the scrubber replaces them in what buddi sends out, exactly like your own secrets."})]})}):null]}),a&&o?n.jsx(P5,{destinations:o.destinations,onClose:()=>l(!1),onChanged:s.reload}):null]})}function R5({secret:e,accounts:t,destinations:s,timezone:r,onChanged:i}){const[a,l]=f.useState(!1),[o,c]=f.useState(null),[u,h]=f.useState(null),[d,m]=f.useState(!1),[p,x]=f.useState(!1),j=async()=>{await zi("secrets.delete",{name:e.name},l,c)!==null&&(m(!1),i())},b=e.lastUse,g=C5(e.bindings,t);return n.jsxs(J,{gap:"sm",children:[n.jsxs("div",{className:"ui-card-head",children:[n.jsx("h3",{className:"ui-card-title",children:g?g.label:e.name}),g?n.jsx(Ia,{children:g.provider}):null,e.totp?n.jsx(Ia,{children:"TOTP"}):null,b?n.jsx(ge,{tone:SE(b.outcome),children:b.outcome}):null]}),g?n.jsx("p",{className:"ui-card-meta mono",children:e.name}):null,e.bindings.length===0?n.jsx("p",{className:"ui-card-meta",children:uv}):n.jsx("div",{className:"ui-stack","data-gap":"sm",children:e.bindings.map((v,w)=>n.jsxs("div",{className:"ui-row",children:[n.jsx(Ia,{children:v.kind}),n.jsx("span",{className:"mono",children:Mp(v.kind,v.target,t)}),n.jsx(ge,{tone:"muted",children:jE[v.rule]??v.rule})]},w))}),e.bindings.some(v=>v.heldByPlugin)?n.jsx("p",{className:"ui-card-meta",children:j5}):null,n.jsx("p",{className:"ui-card-meta",children:b?`Last used ${Fe(b.at)}${b.agentId?` by ${b.agentId}`:""} — ${b.kind}, ${Mp(b.kind,b.target,t)}.`:"Never used."}),n.jsx(se,{message:o}),d?n.jsxs(H,{tone:"critical",role:"alert",children:[n.jsxs("p",{children:["Delete “",e.name,"”? The value and its bindings go; the use log stays, under the name."]}),n.jsxs(Q,{children:[n.jsx(R,{variant:"danger",disabled:a,onClick:()=>void j(),children:"Delete it"}),n.jsx(R,{disabled:a,onClick:()=>m(!1),children:"Cancel"})]})]}):null,n.jsxs(Q,{children:[n.jsx(R,{size:"sm",disabled:a,onClick:()=>h("replace"),children:"Replace value"}),n.jsx(R,{size:"sm",disabled:a,onClick:()=>h("rename"),children:"Rename"}),n.jsx(R,{size:"sm",disabled:a,onClick:()=>h("rebind"),children:e.bindings.length===0?"Add a binding":"Rebind"}),n.jsx(R,{size:"sm",variant:"danger",disabled:a,onClick:()=>m(!0),children:"Delete"}),n.jsx(R,{size:"sm",variant:"ghost","aria-expanded":p,onClick:()=>x(!p),children:"Use log"})]}),p?n.jsx(I5,{name:e.name,accounts:t,timezone:r}):null,u==="replace"?n.jsx($5,{secret:e,onClose:()=>h(null),onChanged:i}):null,u==="rename"?n.jsx(M5,{secret:e,onClose:()=>h(null),onChanged:i}):null,u==="rebind"?n.jsx(O5,{secret:e,destinations:s,onClose:()=>h(null),onChanged:i}):null]})}function I5({name:e,accounts:t,timezone:s}){const r=le(()=>T.secretUses(e,50),[e]);if(r.error)return n.jsx(se,{message:r.error});if(!r.data)return n.jsx(oe,{children:"Reading the log…"});const i=r.data.uses;return i.length===0?n.jsx(oe,{children:"No uses yet."}):n.jsx("div",{className:"ui-list",children:i.map((a,l)=>n.jsxs("div",{className:"ui-list-row",children:[n.jsxs("span",{className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[Be(a.at,s??"UTC")," — ",a.kind,", ",Mp(a.kind,a.target,t)]}),n.jsxs("span",{className:"ui-list-sub",children:[a.agent?a.agent:"the owner",a.plugin?` · ${a.plugin}`:"",a.detail?` · ${a.detail}`:""]})]}),n.jsx("span",{className:"ui-list-side",children:n.jsx(ge,{tone:SE(a.outcome),children:a.outcome})})]},l))})}function EE({name:e,result:t,scrubbed:s,busy:r,failure:i,onScrub:a,onDone:l}){const o=E5(t);return n.jsxs(J,{gap:"sm",children:[n.jsxs(H,{tone:"good",role:"status",children:["Saved “",e,"”. Its value is never shown again."]}),n.jsx("p",{className:"ui-card-meta",children:o||"Nothing of the value sits where buddi already holds text."}),n.jsx(se,{message:i}),o?n.jsx(Q,{children:n.jsx(R,{variant:"accent",disabled:r||s!==null,onClick:a,children:s===null?"Scrub the history":A5(s)||"Nothing of it was left to replace."})}):null,n.jsx(Q,{align:"end",children:n.jsx(R,{onClick:l,children:"Done"})})]})}function AE({destinations:e,bindings:t,disabled:s,onChange:r}){const i=(a,l)=>{r(t.map((o,c)=>c===a?{...o,...l}:o))};return n.jsx(J,{gap:"sm",children:t.map((a,l)=>{const o=e.find(u=>u.kind===a.kind),c=(o==null?void 0:o.maxRule)??a.rule;return n.jsxs(Q,{valign:"end",children:[n.jsx(ee,{label:"Kind",inline:!0,children:n.jsx("select",{value:a.kind,disabled:s,onChange:u=>{var d;const h=u.target.value;i(l,{kind:h,rule:((d=e.find(m=>m.kind===h))==null?void 0:d.maxRule)??a.rule})},children:(o?e:[...e,{kind:a.kind,plugin:"",maxRule:a.rule}]).map(u=>n.jsx("option",{value:u.kind,children:u.kind},u.kind))})}),n.jsx(ee,{label:"Target",inline:!0,grow:!0,children:n.jsx("input",{type:"text",spellCheck:!1,disabled:s,value:a.target,placeholder:w5(a.kind),onChange:u=>i(l,{target:u.target.value})})}),n.jsx(ee,{label:"Rule",inline:!0,children:n.jsx("select",{value:a.rule,disabled:s,onChange:u=>i(l,{rule:u.target.value}),children:v5(c).map(u=>n.jsx("option",{value:u,children:jE[u]},u))})}),n.jsx(R,{size:"sm",variant:"ghost",disabled:s,onClick:()=>r(t.filter((u,h)=>h!==l)),children:"Remove"})]},l)})})}function P5({destinations:e,onClose:t,onChanged:s}){const[r,i]=f.useState(""),[a,l]=f.useState(""),[o,c]=f.useState(!1),[u,h]=f.useState(()=>e.length?[{kind:e[0].kind,target:"",rule:e[0].maxRule}]:[]),[d,m]=f.useState(!1),[p,x]=f.useState(null),[j,b]=f.useState(null),[g,v]=f.useState(null),w=async()=>{const N=u.map(I=>bE(I.kind,I.target)),k=N.findIndex(I=>!I.ok);if(k!==-1){x(`Binding ${k+1}: ${N[k].error}`);return}const S=a;l("");const C=await zi("secrets.put",{name:r.trim(),value:S,totp:o,bindings:u.map((I,A)=>({kind:I.kind,target:N[A].target,rule:I.rule}))},m,x);C!==null&&(b({name:r.trim(),result:C}),s())},y=async()=>{const N=await zi("secrets.scrub_history",{name:(j==null?void 0:j.name)??""},m,x);N!==null&&(v(N),s())};return n.jsx(wt,{title:"Add a secret",onClose:t,children:j?n.jsx(EE,{name:j.name,result:j.result,scrubbed:g,busy:d,failure:p,onScrub:()=>void y(),onDone:t}):n.jsx("form",{className:"ui-stack","data-gap":"sm",onSubmit:N=>{N.preventDefault(),w()},children:n.jsxs("fieldset",{disabled:d,className:"ui-stack","data-gap":"sm",children:[n.jsx(ee,{label:"Name",hint:"What an agent calls it. Saving a name that exists replaces that secret’s value.",children:n.jsx("input",{required:!0,autoFocus:!0,maxLength:200,value:r,onChange:N=>i(N.target.value),placeholder:"PNC password"})}),n.jsx(ee,{label:"Value",hint:"Kept in the vault, never shown again — not even here.",children:n.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,required:!0,value:a,onChange:N=>l(N.target.value)})}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:o,onChange:N=>c(N.target.checked)}),n.jsx("span",{children:"The code comes from this secret"})]}),n.jsx("p",{className:"ui-field-hint",children:"The seed and the code are one thing buddi holds — the owner’s explicit choice per secret."}),n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[n.jsx("span",{className:"ui-field-label",children:"Bindings — the places this value may go"}),n.jsx(AE,{destinations:e,bindings:u,disabled:d,onChange:h}),u.length===0?n.jsx("p",{className:"ui-field-hint",children:uv}):null,e.length?n.jsx(Q,{children:n.jsx(R,{size:"sm",onClick:()=>h([...u,{kind:e[0].kind,target:"",rule:e[0].maxRule}]),children:"Add a binding"})}):n.jsx("p",{className:"ui-field-hint",children:"No destination is registered on this installation yet, so there is nothing to bind to."})]}),p?n.jsx(H,{tone:"critical",role:"alert",children:p}):null,n.jsxs(Q,{align:"end",children:[n.jsx(R,{onClick:t,children:"Cancel"}),n.jsx(R,{type:"submit",variant:"accent",children:"Save secret"})]})]})})})}function $5({secret:e,onClose:t,onChanged:s}){const[r,i]=f.useState(""),[a,l]=f.useState(!1),[o,c]=f.useState(null),[u,h]=f.useState(null),[d,m]=f.useState(null),p=async()=>{const j=r;i("");const b=await zi("secrets.put",{name:e.name,value:j,totp:e.totp,bindings:e.bindings.map(({kind:g,target:v,rule:w})=>({kind:g,target:v,rule:w}))},l,c);b!==null&&(h(b),s())},x=async()=>{const j=await zi("secrets.scrub_history",{name:e.name},l,c);j!==null&&(m(j),s())};return n.jsx(wt,{title:`Replace the value of “${e.name}”`,onClose:t,children:u?n.jsx(EE,{name:e.name,result:u,scrubbed:d,busy:a,failure:o,onScrub:()=>void x(),onDone:t}):n.jsx("form",{className:"ui-stack","data-gap":"sm",onSubmit:j=>{j.preventDefault(),p()},children:n.jsxs("fieldset",{disabled:a,className:"ui-stack","data-gap":"sm",children:[n.jsx(ee,{label:"New value",hint:"Replaces what is stored. The bindings stay as they are.",children:n.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,required:!0,autoFocus:!0,value:r,onChange:j=>i(j.target.value)})}),o?n.jsx(H,{tone:"critical",role:"alert",children:o}):null,n.jsxs(Q,{align:"end",children:[n.jsx(R,{onClick:t,children:"Cancel"}),n.jsx(R,{type:"submit",variant:"accent",children:"Save value"})]})]})})})}function M5({secret:e,onClose:t,onChanged:s}){const[r,i]=f.useState(e.name),[a,l]=f.useState(!1),[o,c]=f.useState(null),u=async()=>{await zi("secrets.rename",{name:e.name,to:r.trim()},l,c)!==null&&(s(),t())};return n.jsx(wt,{title:`Rename “${e.name}”`,onClose:t,children:n.jsx("form",{className:"ui-stack","data-gap":"sm",onSubmit:h=>{h.preventDefault(),u()},children:n.jsxs("fieldset",{disabled:a,className:"ui-stack","data-gap":"sm",children:[n.jsx(ee,{label:"New name",hint:"The vault entry never moves; only the name the agents ask for does.",children:n.jsx("input",{required:!0,autoFocus:!0,maxLength:200,value:r,onChange:h=>i(h.target.value)})}),o?n.jsx(H,{tone:"critical",role:"alert",children:o}):null,n.jsxs(Q,{align:"end",children:[n.jsx(R,{onClick:t,children:"Cancel"}),n.jsx(R,{type:"submit",variant:"accent",disabled:!r.trim()||r.trim()===e.name,children:"Save name"})]})]})})})}function O5({secret:e,destinations:t,onClose:s,onChanged:r}){const[i,a]=f.useState(()=>e.bindings.map(d=>({kind:d.kind,target:S5(d.target),rule:d.rule}))),[l,o]=f.useState(!1),[c,u]=f.useState(null),h=async()=>{const d=i.map(x=>bE(x.kind,x.target)),m=d.findIndex(x=>!x.ok);if(m!==-1){u(`Binding ${m+1}: ${d[m].error}`);return}await zi("secrets.rebind",{name:e.name,bindings:i.map((x,j)=>({kind:x.kind,target:d[j].target,rule:x.rule}))},o,u)!==null&&(r(),s())};return n.jsx(wt,{title:`Rebind “${e.name}”`,onClose:s,children:n.jsx("form",{className:"ui-stack","data-gap":"sm",onSubmit:d=>{d.preventDefault(),h()},children:n.jsxs("fieldset",{disabled:l,className:"ui-stack","data-gap":"sm",children:[n.jsx(AE,{destinations:t,bindings:i,disabled:l,onChange:a}),i.length===0?n.jsx("p",{className:"ui-field-hint",children:uv}):null,t.length?n.jsx(Q,{children:n.jsx(R,{size:"sm",onClick:()=>a([...i,{kind:t[0].kind,target:"",rule:t[0].maxRule}]),children:"Add a binding"})}):null,c?n.jsx(H,{tone:"critical",role:"alert",children:c}):null,n.jsxs(Q,{align:"end",children:[n.jsx(R,{onClick:s,children:"Cancel"}),n.jsx(R,{type:"submit",variant:"accent",children:"Save bindings"})]})]})})})}const es={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."},Or=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function TE(e){let t;try{t=JSON.parse(e.trim())}catch{throw new Error(es.json)}if(!Or(t))throw new Error(es.json);let s,r=t;if("mcpServers"in t){const u=t.mcpServers;if(!Or(u))throw new Error(es.empty);const h=Object.keys(u);if(h.length===0)throw new Error(es.empty);if(h.length>1)throw new Error(`It names ${h.length} servers (${h.join(", ")}). Paste one at a time.`);s=h[0];const d=u[s];if(!Or(d))throw new Error(es.url);r=d}if("command"in r)throw new Error(es.command);if(typeof r.type=="string"&&r.type.toLowerCase()==="sse")throw new Error(es.sse);const i=typeof r.url=="string"?r.url.trim():"";if(i==="")throw new Error(es.url);const a=Or(r.headers)?Object.entries(r.headers).filter(u=>typeof u[1]=="string"&&u[0].trim()!==""):[],l=a.find(([u])=>u.toLowerCase()==="authorization")??a[0];let o,c=!1;if(l){const[u,h]=l,d=/^(Bearer|Basic)\s+/i.exec(h.trim()),m=d?`${d[1].charAt(0).toUpperCase()}${d[1].slice(1).toLowerCase()} `:"";let p=d?h.trim().slice(d[0].length).trim():h.trim();/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$/i.test(p)&&(c=!0,p=""),o={name:u.trim(),prefix:m,value:p}}return{url:i,...s?{name:s}:{},...o?{header:o}:{},dropped:a.filter(u=>u!==l).map(([u])=>u),placeholder:c}}const Ql={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 RE(e){return/TOKEN|KEY|SECRET|PASSWORD|PASSWD|CREDENTIAL|AUTH/i.test(e)}const IE=/^[A-Za-z_][A-Za-z0-9_]*$/;function D5(e){return/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$|^your[_-]/i.test(e.trim())}function PE(e,t){const s=D5(t);return{name:e,value:s?"":t,secret:RE(e),placeholder:s}}function $E(e){const t=[];let s="",r=!1,i=null;for(let a=0;a<e.length;a+=1){const l=e[a];if(i==="'"){l==="'"?i=null:s+=l;continue}if(i==='"'){if(l==='"')i=null;else if(l==="\\"&&a+1<e.length&&'"\\$`\n'.includes(e[a+1])){const o=e[++a];o!==`
111
- `&&(s+=o)}else s+=l;continue}if(l==="\\"){const o=e[a+1];if(o===void 0)continue;if(a+=1,o===`
112
- `||o==="\r"&&e[a+1]===`
113
- `){o==="\r"&&(a+=1);continue}s+=o,r=!0;continue}if(l==="'"||l==='"'){i=l,r=!0;continue}if(/\s/.test(l)){r&&(t.push(s),s="",r=!1);continue}s+=l,r=!0}if(i)throw new Error(Ql.quote);return r&&t.push(s),t}function _5(e){const t=$E(e.trim());let s=0;t[s]==="claude"&&(s+=1),t[s]==="mcp"&&(s+=1),t[s]==="add"&&(s+=1);const r=[],i=[];let a="stdio",l,o;const c=h=>{const d=h.indexOf("="),m=d>0?h.slice(0,d).trim():"";if(!IE.test(m))throw new Error(Ql.env);r.push(PE(m,h.slice(d+1)))},u=[];for(;s<t.length;s+=1){const h=t[s];if(h==="--"){o=t.slice(s+1);break}const[d,m]=h.startsWith("--")&&h.includes("=")?[h.slice(0,h.indexOf("=")),h.slice(h.indexOf("=")+1)]:[h,void 0];if(d==="-e"||d==="--env"){if(m!==void 0){c(m);continue}let p=!1;for(;s+1<t.length&&/^[A-Za-z_][A-Za-z0-9_]*=/.test(t[s+1]);)c(t[++s]),p=!0;if(!p)throw new Error(Ql.env);continue}if(d==="-s"||d==="--scope"){m===void 0&&(s+=1);continue}if(d==="-t"||d==="--transport"){a=(m??t[++s]??"stdio").toLowerCase();continue}if(d==="-H"||d==="--header"){const p=m??t[++s];p&&i.push(p);continue}if(!(d.startsWith("-")&&l===void 0)){if(l===void 0){l=h;continue}u.push(h)}}if(o===void 0?o=u:u.length>0&&(o=[...u,...o]),a==="http"||a==="sse"||o.length===1&&/^https?:\/\//i.test(o[0])){const h=o[0];if(!h)throw new Error(es.url);const d={};for(const m of i){const p=m.indexOf(":");p>0&&(d[m.slice(0,p).trim()]=m.slice(p+1).trim())}return{kind:"remote",config:TE(JSON.stringify({mcpServers:{[l??"server"]:{type:a,url:h,headers:d}}}))}}if(!l||o.length===0)throw new Error(Ql.claude);return{kind:"program",program:{name:l,command:o[0],args:o.slice(1),env:r}}}function L5(e){const t=e.trim();if(/^claude\s+mcp\s+add\b/.test(t))return _5(t);let s;try{s=JSON.parse(t)}catch{throw new Error(es.json)}if(!Or(s))throw new Error(es.json);let r,i=s;if("mcpServers"in s){const c=s.mcpServers;if(!Or(c))throw new Error(es.empty);const u=Object.keys(c);u.length===1&&Or(c[u[0]])&&(r=u[0],i=c[r])}if(!("command"in i))return{kind:"remote",config:TE(t)};const a=typeof i.command=="string"?i.command.trim():"";if(a==="")throw new Error(Ql.command);const l=Array.isArray(i.args)?i.args.map(c=>String(c)):[],o=Or(i.env)?Object.entries(i.env).filter(([c])=>IE.test(c)).map(([c,u])=>PE(c,String(u??""))):[];return{kind:"program",program:{...r?{name:r}:{},command:a,args:l,env:o}}}function F5(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 z5="It can delete or destroy something, so it asks you every time and is never remembered.";function U5(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 ME="buddi-connections",B5="/connections/callback",W5="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.",OE="Services and programs your team can use, and the tools each one brings.",dv=(e,t,s)=>`${e} ${e===1?t:s}`;function rb(e,t){return e.transport==="stdio"?void 0:t.find(s=>fv(s.url,e.url))}function hv({connection:e,card:t,size:s}){return t?n.jsx(Ka,{letter:t.name.slice(0,1).toUpperCase(),size:s}):n.jsx(Ka,{icon:(e==null?void 0:e.transport)==="stdio"?"terminal":"globe",size:s})}function DE({connection:e}){const t=F5(e);return n.jsx(ge,{tone:t.tone,dot:t.dot,children:t.label})}const Nf=e=>t=>{t.stopPropagation(),e()},xu=[{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"}],_E="buddi.connections.add-way";function H5(){try{const e=window.localStorage.getItem(_E);return xu.some(t=>t.value===e)?e:"address"}catch{return"address"}}function K5({embedded:e,timezone:t}={}){const s=le(()=>T.connections(),[],3e4),[r,i]=f.useState(null),[a,l]=f.useState(null),[o,c]=f.useState(null),[u,h]=f.useState(null),d=s.data,m=N=>{var k;return((k=d==null?void 0:d.agents.find(S=>S.id===N))==null?void 0:k.name)??N},p=t??Intl.DateTimeFormat().resolvedOptions().timeZone,x=(d==null?void 0:d.connections)??[],j=(d==null?void 0:d.catalog)??[],b=j.filter(N=>!x.some(k=>k.transport!=="stdio"&&fv(N.url,k.url))),g=a?x.find(N=>N.id===a):void 0,v=o?x.find(N=>N.id===o):void 0,w=u?x.find(N=>N.id===u):void 0,y=N=>{l(null),i(N)};return n.jsxs(yn,{embedded:e,title:"Connections",lede:OE,children:[n.jsxs(J,{gap:"lg",children:[n.jsxs("p",{className:"plugins-quiet connections-quiet",children:[n.jsx(we,{name:"plug",size:14}),n.jsxs("span",{children:["A connection is a service or program buddi talks to; a plugin is code buddi installs and runs."," ",n.jsx("a",{href:et("plugins"),children:"Plugins"})]})]}),!d&&!s.error?n.jsx(oe,{children:"Reading your connections…"}):null,n.jsx(se,{message:s.error}),d&&!d.vault?n.jsx(H,{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,d?n.jsx(qe,{flush:!0,title:"Your connections",tool:x.length>0?dv(x.length,"connection","connections"):void 0,children:x.length===0?n.jsx(oe,{title:"Nothing connected yet",children:"Pick a service below, or add your own: an address, a program on this computer, or a config you already have."}):n.jsx("div",{className:"connections-rows",children:n.jsx(At,{children:x.map(N=>n.jsx(V5,{connection:N,card:rb(N,j),twin:N.slug!==null&&x.some(k=>k.id!==N.id&&k.name===N.name),onOpen:()=>l(N.id),onFlow:y},N.id))})})}):null,d&&b.length>0?n.jsx(qe,{title:"Connect a service",children:n.jsx("div",{className:"connections-tiles",children:b.map(N=>n.jsxs("div",{className:"connections-tile",children:[n.jsx(hv,{card:N}),n.jsxs("span",{className:"connections-tile-main",children:[n.jsx("span",{className:"connections-tile-name",children:N.name}),n.jsx("span",{className:"connections-tile-blurb",children:N.blurb})]}),n.jsx(R,{size:"sm",onClick:()=>y({step:"address",card:N}),"aria-label":`Connect ${N.name}`,children:"Connect"})]},N.id))})}):null,d?n.jsx(J5,{onFlow:N=>y({step:N})}):null]}),g?n.jsx(Y5,{connection:g,card:rb(g,j),agentName:m,timezone:p,onClose:()=>l(null),onFlow:y,onDisconnect:()=>c(g.id),onHolders:()=>h(g.id)}):null,w&&d?n.jsx(q5,{connection:w,agents:d.agents,onCancel:()=>h(null),onDone:()=>{h(null),s.reload()}},w.id):null,v?n.jsx(Q5,{connection:v,agentName:m,onCancel:()=>c(null),onDone:()=>{c(null),l(null),s.reload()}},v.id):null,r&&d?n.jsx(X5,{start:r,agents:d.agents,catalog:d.catalog,tokens:d.tokens??d.vault,onClose:()=>{i(null),s.reload()}}):null]})}function V5({connection:e,card:t,twin:s,onOpen:r,onFlow:i}){const a=e.state==="pending-review",l=s?`${e.name} (${e.slug})`:e.name,o=e.transport==="stdio"?e.program:void 0,c=o?o.line:e.host,u=a?"its tools are not reviewed yet":dv(e.toolCount,"tool","tools");return n.jsx(Tt,{onClick:r,label:`${l}: details`,lead:n.jsx(hv,{connection:e,card:t}),title:l,sub:n.jsx("span",{className:"connections-sub","data-kind":o?"program":void 0,children:`${c} · ${u}`}),side:n.jsxs("span",{className:"plugins-side",children:[a?n.jsx("span",{className:"connections-act",children:n.jsx(R,{size:"sm",variant:"accent",onClick:Nf(()=>i({step:e.signedIn?"review":"consent",connection:e})),children:"Finish"})}):e.state==="needs-reconnect"&&e.authKind!=="none"?n.jsx("span",{className:"connections-act",children:n.jsx(R,{size:"sm",onClick:Nf(()=>i({step:"consent",connection:e,keepGrants:!0})),children:"Sign in"})}):e.state==="needs-review"?n.jsx("span",{className:"connections-act",children:n.jsx(R,{size:"sm",onClick:Nf(()=>i({step:"review",connection:e,keepGrants:!0})),children:"Review"})}):null,n.jsx(DE,{connection:e}),n.jsx(we,{name:"chevron-right",size:14})]})})}const G5={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 Y5({connection:e,card:t,agentName:s,timezone:r,onClose:i,onFlow:a,onHolders:l,onDisconnect:o}){const c=e.state==="pending-review",u=e.transport==="stdio"?e.program:void 0,h=()=>a({step:"consent",connection:e,keepGrants:!0}),d=()=>a({step:"review",connection:e,keepGrants:!0}),m=()=>a({step:e.signedIn?"review":"consent",connection:e});return n.jsxs(wt,{title:n.jsxs("span",{className:"plugins-sheet-title",children:[n.jsx(hv,{connection:e,card:t,size:"lg"}),n.jsxs("span",{className:"plugins-sheet-name",children:[n.jsx("span",{children:e.name}),n.jsxs("span",{className:"plugins-sheet-by",children:[u?"A program on this computer":"A service at an address"," · ",n.jsx(DE,{connection:e})]})]})]}),onClose:i,foot:n.jsxs(Q,{children:[n.jsx(R,{variant:"danger-ghost",onClick:o,children:"Disconnect…"}),n.jsx(en,{}),u?n.jsx(R,{onClick:()=>a({step:"program",connection:e,keepGrants:!0}),children:"Change"}):null,e.authKind!=="none"&&!c?n.jsx(R,{variant:e.state==="needs-reconnect"?"accent":void 0,onClick:h,children:"Reconnect"}):null,c?n.jsx(R,{variant:"accent",onClick:m,children:"Finish"}):n.jsx(R,{variant:e.state==="needs-review"?"accent":void 0,onClick:d,children:"Review again"})]}),children:[c?n.jsx(H,{children:"Not finished: its tools are not reviewed yet, so no agent can use them."}):null,e.state==="needs-reconnect"?n.jsx(H,{tone:"warning",action:e.authKind!=="none"?n.jsx(R,{size:"sm",variant:"accent",onClick:h,children:"Sign in again"}):void 0,children:"Its sign-in ran out or was refused. Until you reconnect, each of its tools answers with one sentence instead of running."}):null,e.state==="needs-review"?n.jsxs(H,{tone:"warning",action:n.jsx(R,{size:"sm",variant:"accent",onClick:d,children:"Review it"}),children:["It changed its tools since you reviewed them. The new and changed ones wait until you review it again",e.heldTools?` (${e.heldTools} of the ones you kept ${e.heldTools===1?"waits":"wait"})`:"","; the others keep working."]}):null,e.state==="unreachable"&&e.unreachableSince?n.jsx(H,{tone:"critical",children:u?`It stopped answering at ${Be(e.unreachableSince,r)}; the next call starts it again.`:`Unreachable since ${Be(e.unreachableSince,r)}, retrying.`}):null,u!=null&&u.changedSinceReview?n.jsx(H,{tone:"warning",children:"Its command changed since you reviewed it, so its tools wait until you review it again."}):null,e.phase==="starting"?n.jsx(H,{tone:"accent",role:"status",children:"Starting it… The first start can take a minute or two while it downloads."}):null,n.jsx("div",{className:"plugins-facts",children:n.jsx(Vt,{items:[u?{label:"Command",value:n.jsx("span",{className:"connections-line",children:u.line})}:{label:"Address",value:n.jsx("span",{className:"connections-line",children:e.url})},...u?[{label:"Runs",value:"On this computer as you, with your PATH and only the variables you named. It stops after ten quiet minutes."}]:[],...u&&u.env.length>0?[{label:"Variables",value:n.jsx("span",{className:"mono",children:u.env.map(p=>`${p.name}${p.secret?" (secret)":""}`).join(", ")})}]:[],...u?[]:[{label:"Signs in with",value:G5[e.authKind]}],{label:"Tools",value:c?"Not reviewed yet":`${dv(e.toolCount,"tool","tools")}${e.reviewedAt?` · reviewed ${Fe(e.reviewedAt)}`:""}`},...c?[]:[{label:"Held by",value:n.jsxs("span",{className:"connections-holders",children:[n.jsx("span",{children:e.agents.length===0?"No agent holds these tools yet.":e.agents.map(s).join(", ")}),n.jsx(R,{size:"sm",onClick:l,"aria-label":"Change who holds it",children:e.agents.length===0?"Give them":"Change"})]})}]]})}),e.stderr&&e.stderr.length>0?n.jsx(te,{title:"What the program last said",children:n.jsx(xt,{label:"Its last lines on stderr",children:e.stderr.join(`
114
- `)})}):null,t&&!c?n.jsxs("div",{className:"connections-another",children:[n.jsxs("p",{children:["Another ",t.name," account or workspace? It connects beside this one, with its own sign-in and its own name. In the browser, sign in as that other account."]}),n.jsx(R,{size:"sm",onClick:()=>a({step:"address",card:t}),children:"Add another account"})]}):null]})}function q5({connection:e,agents:t,onCancel:s,onDone:r}){const[i,a]=f.useState(()=>new Set(e.agents)),[l,o]=f.useState(!1),[c,u]=f.useState(null),h=(p,x)=>a(j=>{const b=new Set(j);return x?b.add(p):b.delete(p),b}),d=i.size===e.agents.length&&e.agents.every(p=>i.has(p)),m=async()=>{o(!0),u(null);try{const p=await T.grantConnection(e.id,[...i],!0);p.failed.length>0?u(p.failed.map(x=>`${x.agent}: ${x.message}`).join("; ")):r()}catch(p){u(Ss(p))}finally{o(!1)}};return n.jsxs(Qu,{title:`Who holds ${e.name}`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",disabled:l,onClick:s,children:"Cancel"}),n.jsx(R,{variant:"accent",disabled:l||d,onClick:()=>void m(),children:"Save"})]}),children:[n.jsx("p",{className:"plugins-dialog-text",children:"Each agent you tick can use its tools; untick one to take them away. Approvals still ask as before."}),n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Agents",children:t.map(p=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:i.has(p.id),onChange:x=>h(p.id,x.target.checked)}),n.jsxs("span",{children:[p.name,p.frontDesk?" (front desk)":""]})]},p.id))}),n.jsx(se,{message:c})]})}function Q5({connection:e,agentName:t,onCancel:s,onDone:r}){const[i,a]=f.useState(!1),[l,o]=f.useState(null),c=e.agents.map(t),u=async()=>{a(!0),o(null);try{await T.disconnect(e.id),r()}catch(h){o(Ss(h))}finally{a(!1)}};return n.jsxs(Qu,{title:`Disconnect ${e.name}?`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",disabled:i,onClick:s,children:"Cancel"}),n.jsx(R,{variant:"danger",disabled:i,onClick:()=>void u(),children:"Disconnect"})]}),children:[n.jsxs("p",{className:"plugins-dialog-text",children:["buddi forgets its sign-in and its tools."," ",c.length>0?`${c.join(" and ")} ${c.length===1?"loses":"lose"} them.`:"No agent holds its tools."]}),n.jsx(se,{message:l})]})}function J5({onFlow:e}){const[t,s]=f.useState(H5),r=xu.find(a=>a.value===t)??xu[0],i=a=>{s(a);try{window.localStorage.setItem(_E,a)}catch{}};return n.jsx(qe,{title:"Add your own",actions:n.jsx(ls,{label:"How to add it",options:xu.map(({value:a,label:l})=>({value:a,label:l})),value:t,onChange:i}),children:n.jsxs("div",{className:"connections-add",children:[n.jsx("p",{className:"connections-add-text",children:r.text}),n.jsx(R,{variant:"accent",onClick:()=>e(t),children:r.button})]})})}function X5({start:e,agents:t,catalog:s=[],tokens:r=!0,onClose:i,pollMs:a=2e3}){const[l,o]=f.useState(e.step),[c,u]=f.useState(e.connection),[h,d]=f.useState("unknown"),[m,p]=f.useState(null),[x,j]=f.useState(null),b=(m==null?void 0:m.url)??(c==null?void 0:c.url),g=e.card??s.find(y=>b!==void 0&&fv(y.url,b)),v=(c==null?void 0:c.name)??(g==null?void 0:g.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 n.jsxs(wt,{title:w,onClose:i,size:"wide",children:[l==="paste"?n.jsx(Z5,{onRead:y=>{y.kind==="program"?(j(y.program),o("program")):(p(y.config),o("address"))}}):null,l==="address"?n.jsx(e8,{card:g,pasted:m,onDone:(y,N)=>{u(y),N==="none"?o("review"):(d(N),o("consent"))}}):null,l==="program"?n.jsx(o8,{connection:c,pasted:x,tokens:r,onDone:y=>{var N;j(null),u(y),e.keepGrants&&!((N=y.program)!=null&&N.changedSinceReview)&&y.state!=="pending-review"?i():o("review")}}):null,l==="consent"&&c?n.jsx(s8,{connection:c,signIn:h,card:g,pasted:m==null?void 0:m.header,placeholder:(m==null?void 0:m.placeholder)??!1,tokens:r,pollMs:a,onSignedIn:y=>{p(null),u(y),e.keepGrants?i():o("review")}}):null,l==="review"&&c?n.jsx(c8,{connection:c,onKept:y=>{u(y),e.keepGrants?i():o("grant")}}):null,l==="grant"&&c?n.jsx(u8,{connection:c,agents:t,onDone:i}):null]})}function fv(e,t){const s=r=>r.trim().replace(/\/+$/,"").toLowerCase();return s(e)===s(t)}function Ss(e){return e instanceof Error?e.message:String(e)}function Z5({onRead:e}){const[t,s]=f.useState(""),[r,i]=f.useState(null),a=()=>{try{const l=L5(t);s(""),i(null),e(l)}catch(l){i(Ss(l))}};return n.jsxs("form",{className:"ui-stack",onSubmit:l=>{l.preventDefault(),a()},children:[n.jsxs("p",{children:["Paste the block another app uses for this server, the one with ",n.jsx("span",{className:"mono",children:"mcpServers"}),", or the"," ",n.jsx("span",{className:"mono",children:"claude mcp add"})," line its docs print. A remote server gives its address, name and one header; a program its command, arguments and variables. Nothing is kept before you have read it on the next screen."]}),n.jsx(ee,{label:"Config",hint:"A url for a remote server, or a command for a program on this computer.",children:n.jsx("textarea",{className:"mono",rows:8,required:!0,autoFocus:!0,spellCheck:!1,autoComplete:"off",value:t,placeholder:'{ "mcpServers": { "github": { "url": "…", "headers": { "Authorization": "Bearer …" } } } }',onChange:l=>s(l.target.value)})}),n.jsx(se,{message:r}),n.jsx(Q,{align:"end",children:n.jsx(R,{type:"submit",variant:"accent",disabled:t.trim()==="",children:"Read it"})})]})}function e8({card:e,pasted:t,onDone:s}){var m,p;const[r,i]=f.useState((t==null?void 0:t.url)??(e==null?void 0:e.url)??""),[a,l]=f.useState(!1),[o,c]=f.useState(null),u=async()=>{l(!0),c(null);try{const x=await T.addConnection(r.trim(),(e==null?void 0:e.name)??(t==null?void 0:t.name));s(x.connection,x.signIn)}catch(x){c(Ss(x))}finally{l(!1)}},h=((m=e==null?void 0:e.auth)==null?void 0:m.recommended)==="token",d=((p=e==null?void 0:e.auth)==null?void 0:p.recommended)==="device"&&e.auth.device!==void 0;return n.jsxs("form",{className:"ui-stack",onSubmit:x=>{x.preventDefault(),u()},children:[e?n.jsxs("p",{children:["buddi opens ",e.name,"’s server, reads its name and what it offers, and asks whether it wants you to sign in. Nothing else is sent."]}):n.jsx("p",{children:"Where is the server? buddi opens it, reads its name and what it offers, and nothing else until you have read its tools."}),n.jsx(ee,{label:"Address",hint:"An https:// address. A server you start with npx, uvx or a local command is “A program on this computer” instead.",children:n.jsx("input",{required:!0,autoFocus:!e&&!t,spellCheck:!1,value:r,placeholder:"https://",onChange:x=>i(x.target.value)})}),e&&!e.verified?n.jsxs("p",{className:"ui-card-meta",children:["This address is the one ",e.name," published; buddi has not checked it since."]}):null,d?n.jsxs("p",{className:"ui-card-meta",children:[e.name," signs in with a code you type on its site. The next screen shows it."]}):h?n.jsxs("p",{className:"ui-card-meta",children:[e.name," signs in with a token you make on its site. The next screen links to the page."]}):e!=null&&e.clientIdRequired?n.jsxs("p",{className:"ui-card-meta",children:[e.name," does not let buddi register itself: signing in needs a token, or a client id from its developer settings."]}):null,t!=null&&t.header?n.jsx("p",{className:"ui-card-meta",children:t.placeholder?`Your config has a placeholder where the ${t.header.name} header's token goes. You paste the token itself on the next screen.`:`The ${t.header.name} header from your config waits for the sign-in screen. buddi tries it before it keeps it.`}):null,t&&t.dropped.length>0?n.jsxs("p",{className:"ui-card-meta",children:["buddi sends one header, so ",t.dropped.join(", ")," ",t.dropped.length===1?"was":"were"," left out."]}):null,n.jsx(se,{message:o}),n.jsx(Q,{align:"end",children:n.jsx(R,{type:"submit",variant:"accent",disabled:a||r.trim()==="",children:a?"Opening…":"Continue"})})]})}const t8={device:"Device",oauth:"Sign in",token:"Token",client:"Client id"};function n8(e,t,s="none"){const r=e==="manual"?["token","client"]:["oauth","token"],i=t?r:r.filter(a=>a!=="token");return s==="first"?["device",...i]:s==="offered"?[...i.filter(a=>a!=="client"),"device",...i.filter(a=>a==="client")]:i}function s8({connection:e,signIn:t,card:s,pasted:r,placeholder:i,tokens:a,pollMs:l,onSignedIn:o}){var W,D;const[c,u]=f.useState(t),h=(W=s==null?void 0:s.auth)!=null&&W.device?s.auth.recommended==="device"?"first":"offered":"none",d=n8(c,a,h),m=r!==void 0||h!=="first"&&(e.authKind==="token"||((D=s==null?void 0:s.auth)==null?void 0:D.recommended)==="token"),[p,x]=f.useState(()=>m&&d.includes("token")?"token":d[0]),j=d.includes(p)?p:d[0],[b,g]=f.useState(W5),[v,w]=f.useState(""),[y,N]=f.useState(null),[k,S]=f.useState(!1),[C,I]=f.useState(null),[A,O]=f.useState(!1),[z,L]=f.useState(null),E=`${location.origin}${B5}`,$=f.useRef(o);$.current=o,f.useEffect(()=>{if(!A)return;let U=!1;const V=async()=>{if(!U){U=!0;try{$.current(await T.connection(e.id))}catch(ae){I(Ss(ae))}}},Z=typeof BroadcastChannel=="function"?new BroadcastChannel(ME):null;Z&&(Z.onmessage=ae=>{var me;((me=ae.data)==null?void 0:me.id)===e.id&&V()});let ue;const Ae=Date.now(),X=async()=>{if(!U){try{const ae=await T.connection(e.id);if((!e.signedIn||e.authKind==="token")&&ae.signedIn&&ae.authKind==="oauth"){V();return}}catch{}if(Date.now()-Ae>10*6e4){O(!1),I("The sign-in did not come back within ten minutes. Start it again.");return}ue=window.setTimeout(()=>void X(),l)}};return ue=window.setTimeout(()=>void X(),l),()=>{U=!0,Z==null||Z.close(),window.clearTimeout(ue)}},[A,e,l]);const _=async U=>{var V;S(!0),I(null);try{const{authorizeUrl:Z}=await T.connectionConsent(e.id,U);N(Z)}catch(Z){Z instanceof pe&&((V=Z.detail)==null?void 0:V.code)==="client-id"?(g(Z.message),u("manual"),x("client")):I(Ss(Z))}finally{S(!1)}};f.useEffect(()=>{j!=="oauth"||y!==null||_()},[j]);const B=U=>{const V=window.open(U,"_blank");V?(V.opener=null,L(null)):L(U),O(!0)},M=U=>{x(U),N(null),I(null),O(!1),L(null)};return n.jsxs("div",{className:"ui-stack",children:[d.length>1?n.jsx(ls,{label:"How to sign in",options:d.map(U=>({value:U,label:t8[U]})),value:j,onChange:M}):null,j==="oauth"?n.jsxs(n.Fragment,{children:[n.jsxs("p",{children:["buddi opens ",e.name,"’s own sign-in page in a new tab. You say yes there, the tab comes back here, and buddi keeps the sign-in in its vault. No agent ever sees it."]}),k?n.jsxs(oe,{children:["Getting ",e.name,"’s sign-in page…"]}):null]}):null,j==="client"?n.jsxs(n.Fragment,{children:[n.jsx(H,{tone:"warning",children:b}),n.jsx(ee,{label:"Client id",children:n.jsx("input",{required:!0,spellCheck:!1,value:v,onChange:U=>{w(U.target.value),N(null),O(!1)}})}),n.jsxs("p",{className:"ui-card-meta",children:["Its redirect address: ",n.jsx("span",{className:"mono",children:E})]})]}):null,j==="token"?n.jsx(a8,{connection:e,card:s,pasted:r,placeholder:i,onSignedIn:o}):null,j==="device"?n.jsx(i8,{connection:e,service:(s==null?void 0:s.name)??e.name,pollMs:l,onSignedIn:o}):null,(j==="oauth"||j==="client")&&A?n.jsxs(H,{tone:"accent",role:"status",children:["Waiting for you to say yes on ",e.name,"’s page…"]}):null,(j==="oauth"||j==="client")&&z?n.jsx("p",{children:n.jsxs("a",{href:z,target:"_blank",rel:"noopener noreferrer",children:["Open ",e.name,"’s sign-in page"]})}):null,j==="oauth"||j==="client"?n.jsx(se,{message:C}):null,j==="oauth"?n.jsx(Q,{align:"end",children:n.jsx(R,{variant:"accent",onClick:()=>{y&&B(y)},disabled:y===null,children:A?"Open it again":`Sign in to ${e.name}`})}):null,j==="client"?n.jsx(Q,{align:"end",children:y===null?n.jsx(R,{variant:"accent",onClick:()=>void _(v.trim()),disabled:k||v.trim()==="",children:k?"Checking…":"Continue"}):n.jsx(R,{variant:"accent",onClick:()=>B(y),children:A?"Open it again":`Open ${e.name}’s sign-in page`})}):null]})}function r8(e){try{const t=new URL(e);return`${t.host}${t.pathname==="/"?"":t.pathname.replace(/\/$/,"")}`}catch{return e}}function i8({connection:e,service:t,pollMs:s,onSignedIn:r}){const[i,a]=f.useState(null),[l,o]=f.useState(null),[c,u]=f.useState(0),[h,d]=f.useState(null),m=f.useRef(r);m.current=r,f.useEffect(()=>{let j=!1,b;a(null),o(null),d(null);const g=async()=>{var v,w;if(!j){try{const y=await T.connection(e.id);if(j)return;if(((v=y.device)==null?void 0:v.state)==="done"){m.current(y);return}if(((w=y.device)==null?void 0:w.state)==="failed"){o(y.device.reason??"The sign-in did not finish. Start again.");return}}catch{}b=window.setTimeout(()=>void g(),s)}};return(async()=>{try{const v=await T.connectionDevice(e.id);if(j)return;a({userCode:v.userCode,verificationUri:v.verificationUri}),b=window.setTimeout(()=>void g(),s)}catch(v){j||o(Ss(v))}})(),()=>{j=!0,window.clearTimeout(b)}},[e.id,s,c]);const p=j=>{const b=window.open(j,"_blank");b?(b.opener=null,d(null)):d(j)},x=i?r8(i.verificationUri):"";return n.jsxs(n.Fragment,{children:[n.jsxs("p",{children:["Type this code on ",t,"’s site and say yes there. buddi keeps the sign-in in its vault and sends it only to"," ",n.jsx("span",{className:"mono",children:e.host}),". No agent ever sees it."]}),i===null&&l===null?n.jsxs(oe,{children:["Asking ",t," for a code…"]}):null,i&&l===null?n.jsxs(n.Fragment,{children:[n.jsx(lv,{code:i.userCode,label:`Your code for ${t}`,large:!0}),n.jsxs(H,{tone:"accent",role:"status",children:["Waiting for you to approve on ",t,"…"]}),h?n.jsx("p",{children:n.jsxs("a",{href:h,target:"_blank",rel:"noopener noreferrer",children:["Open ",x]})}):null,n.jsx(Q,{align:"end",children:n.jsxs(R,{variant:"accent",onClick:()=>p(i.verificationUri),children:["Open ",x]})})]}):null,l!==null?n.jsxs(n.Fragment,{children:[n.jsx(se,{message:l}),n.jsx(Q,{align:"end",children:n.jsx(R,{variant:"accent",onClick:()=>u(j=>j+1),children:"Start again"})})]}):null]})}function a8({connection:e,card:t,pasted:s,placeholder:r,onSignedIn:i}){var g,v;const[a,l]=f.useState((s==null?void 0:s.value)??""),[o,c]=f.useState((s==null?void 0:s.name)??"Authorization"),[u,h]=f.useState((s==null?void 0:s.prefix)??(s?"":"Bearer ")),[d,m]=f.useState(!1),[p,x]=f.useState(null),j=async()=>{m(!0),x(null);try{const w=await T.connectionToken(e.id,{token:a.trim(),header:o.trim(),prefix:u});l(""),i(w.connection)}catch(w){x(Ss(w))}finally{m(!1)}},b=(g=t==null?void 0:t.auth)==null?void 0:g.tokenPage;return n.jsxs("form",{className:"ui-stack",onSubmit:w=>{w.preventDefault(),j()},children:[n.jsxs("p",{children:[b?`Make a token on ${e.name}’s site and paste it here.`:`Paste a token ${e.name} gave you.`," buddi tries it on"," ",n.jsx("span",{className:"mono",children:e.host})," first, keeps it in its vault, and sends it only there. No agent ever sees it."]}),b?n.jsx("p",{children:n.jsxs("a",{href:b,target:"_blank",rel:"noopener noreferrer",children:["Make a token on ",e.name]})}):null,r?n.jsx(H,{tone:"accent",children:"Your config had a placeholder where the token goes. Paste the token itself."}):null,n.jsx(ee,{label:"Token",hint:(v=t==null?void 0:t.auth)==null?void 0:v.tokenHint,children:n.jsx("input",{type:"password",required:!0,autoFocus:!(s!=null&&s.value),autoComplete:"off",spellCheck:!1,value:a,onChange:w=>l(w.target.value)})}),n.jsxs(bs,{columns:2,dense:!0,children:[n.jsx(ee,{label:"Header",hint:"Most services want Authorization.",children:n.jsx("input",{required:!0,spellCheck:!1,value:o,onChange:w=>c(w.target.value)})}),n.jsx(ee,{label:"Before the token",hint:"Usually “Bearer ”, with its space. Empty for none.",children:n.jsx("input",{spellCheck:!1,value:u,onChange:w=>h(w.target.value)})})]}),n.jsx(se,{message:p}),n.jsx(Q,{align:"end",children:n.jsx(R,{type:"submit",variant:"accent",disabled:d||a.trim()===""||o.trim()==="",children:d?"Trying it…":"Try it and keep it"})})]})}function l8(e){return e!==""&&/^[A-Za-z0-9_@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function o8({connection:e,pasted:t,tokens:s=!0,onDone:r}){const i=e==null?void 0:e.program,a=f.useRef(0),l=()=>(a.current+=1,a.current),[o,c]=f.useState((e==null?void 0:e.name)??(t==null?void 0:t.name)??""),[u,h]=f.useState((i==null?void 0:i.command)??(t==null?void 0:t.command)??""),[d,m]=f.useState(()=>((i==null?void 0:i.args)??(t==null?void 0:t.args)??[]).map(E=>({key:l(),value:E}))),[p,x]=f.useState(()=>i?i.env.map(E=>({key:l(),name:E.name,value:E.value??"",secret:E.secret,kept:E.secret})):((t==null?void 0:t.env)??[]).map(E=>({key:l(),name:E.name,value:E.value,secret:E.secret,kept:!1}))),[j,b]=f.useState(!1),[g,v]=f.useState(null),w=/\s/.test(u.trim())?$E(u.trim()):[u.trim()],y=w[0]??"",N=[...w.slice(1),...d.map(E=>E.value)],k=[y,...N].filter((E,$)=>$>0||E!==""),S=()=>{w.length<2||(h(y),m(E=>[...w.slice(1).map($=>({key:l(),value:$})),...E]))},C=k.map(l8).join(" "),I=p.filter(E=>E.secret&&E.value===""&&!E.kept).map(E=>E.name||"a variable"),A=((t==null?void 0:t.env)??[]).filter(E=>E.placeholder).map(E=>E.name),O=(E,$)=>m(_=>_.map(B=>B.key===E?{...B,value:$}:B)),z=(E,$)=>x(_=>_.map(B=>B.key===E?{...B,...$}:B)),L=async()=>{b(!0),v(null);const E={name:o.trim(),command:y,args:N,env:p.filter($=>$.name.trim()!=="").map($=>({name:$.name.trim(),value:$.value,secret:$.secret}))};try{r(e?await T.updateProgram(e.id,E):(await T.addProgram(E)).connection),x($=>$.map(_=>_.secret?{..._,value:""}:_))}catch($){v(Ss($))}finally{b(!1)}};return n.jsxs("form",{className:"ui-stack",onSubmit:E=>{E.preventDefault(),L()},children:[n.jsx("p",{children:"A server buddi starts itself on this computer, as you, when an agent needs it, and stops after ten quiet minutes. It runs with your PATH and only the variables you name here. The review screen is the first time it runs, only to list its tools."}),n.jsxs(bs,{columns:2,children:[n.jsx(ee,{label:"Name",children:n.jsx("input",{required:!0,autoFocus:!t&&!e,maxLength:80,spellCheck:!1,value:o,onChange:E=>c(E.target.value)})}),n.jsx(ee,{label:"Command",hint:"The program that starts the server: npx, uvx, node, or a full path. A whole line is split into it and its arguments.",children:n.jsx("input",{required:!0,spellCheck:!1,autoComplete:"off",className:"mono",value:u,placeholder:"npx",onChange:E=>h(E.target.value),onBlur:S})})]}),n.jsx(ee,{label:"Arguments",group:!0,hint:"One per row, exactly as the server's docs give them. No shell: quotes and $VARIABLES are passed as they are.",children:n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[d.map((E,$)=>n.jsxs("div",{className:"connections-row",children:[n.jsx("input",{"aria-label":`Argument ${$+1}`,className:"mono",spellCheck:!1,autoComplete:"off",value:E.value,onChange:_=>O(E.key,_.target.value)}),n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>m(_=>_.filter(B=>B.key!==E.key)),"aria-label":`Remove argument ${$+1}`,children:"Remove"})]},E.key)),n.jsx(Q,{children:n.jsx(R,{size:"sm",onClick:()=>m(E=>[...E,{key:l(),value:""}]),children:"Add an argument"})})]})}),n.jsx(ee,{label:"Environment variables",group:!0,hint:"A secret is kept in buddi's vault and handed to the program only when it starts. Names with TOKEN, KEY, SECRET or PASSWORD start as secrets.",children:n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[p.map((E,$)=>n.jsxs("div",{className:"connections-row","data-kind":"env",children:[n.jsx("input",{"aria-label":`Variable ${$+1} name`,className:"mono",spellCheck:!1,autoComplete:"off",placeholder:"NAME",value:E.name,onChange:_=>{const B=_.target.value;z(E.key,E.value===""&&!E.kept?{name:B,secret:RE(B)}:{name:B})}}),n.jsx("input",{"aria-label":`Variable ${$+1} value`,type:E.secret?"password":"text",spellCheck:!1,autoComplete:"off",placeholder:E.kept&&E.value===""?"Kept. Type to replace it.":"value",value:E.value,onChange:_=>z(E.key,{value:_.target.value})}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:E.secret,onChange:_=>z(E.key,{secret:_.target.checked,kept:_.target.checked&&E.kept})}),n.jsx("span",{children:"Secret"})]}),n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>x(_=>_.filter(B=>B.key!==E.key)),"aria-label":`Remove variable ${$+1}`,children:"Remove"})]},E.key)),n.jsx(Q,{children:n.jsx(R,{size:"sm",onClick:()=>x(E=>[...E,{key:l(),name:"",value:"",secret:!1,kept:!1}]),children:"Add a variable"})})]})}),A.length>0?n.jsxs(H,{tone:"accent",children:["Your config had a placeholder for ",A.join(", "),". Type the value itself."]}):null,!s&&p.some(E=>E.secret)?n.jsx(H,{tone:"warning",children:"This installation has no vault, so a secret cannot be kept. Turn the vault on first, or switch Secret off."}):null,n.jsx("p",{className:"ui-card-meta",children:"A server that signs you in through a browser opens it on this computer, so it needs a screen. On a machine without one, give it a token as a secret variable instead."}),n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[n.jsx("span",{className:"ui-field-label",children:"It will run"}),n.jsx(xt,{label:"The command line",children:C||"…"})]}),n.jsx(se,{message:g}),n.jsx(Q,{align:"end",children:n.jsx(R,{type:"submit",variant:"accent",disabled:j||o.trim()===""||u.trim()===""||I.length>0,title:I.length>0?`Give ${I.join(", ")} a value.`:void 0,children:j?"Saving…":e?"Save":"Continue"})})]})}function c8({connection:e,onKept:t}){const s=le(()=>T.connectionReview(e.id),[e.id]),[r,i]=f.useState(null),[a,l]=f.useState(!1),[o,c]=f.useState(null),u=s.data,h=r??(u==null?void 0:u.slug)??"",d=async()=>{var p;if(u){l(!0),c(null);try{t(await T.saveConnectionReview(e.id,{hash:u.hash,...u.slugEditable?{slug:h}:{}}))}catch(x){x instanceof pe&&((p=x.detail)==null?void 0:p.code)==="changed"&&s.reload(),c(Ss(x))}finally{l(!1)}}};if(!u)return s.error?n.jsx(se,{message:s.error}):e.transport==="stdio"?n.jsxs(oe,{children:["Starting ",e.name,"… The first start can take a minute or two while it downloads."]}):n.jsxs(oe,{children:["Reading what ",e.name," offers…"]});const m=u.tools.filter(p=>p.problem===null).length;return n.jsxs("div",{className:"ui-stack",children:[n.jsxs("p",{children:["Read what ",e.name," brings before it brings it. Each tool gets a buddi name and a tier from what the server says it does; anything that changes something asks you first, on the same approval card as every other tool."]}),u.program?n.jsx(H,{tone:"warning",title:"This runs on this computer as you",children:n.jsxs(J,{gap:"sm",children:[n.jsx(xt,{label:"The command",children:u.program.line}),n.jsx("p",{children:"It can read and change what you can, and reach the network. buddi starts it with only the variables below, stops it after ten quiet minutes, and asks you again if its command changes."}),u.program.env.length>0?n.jsxs("p",{className:"ui-card-meta",children:["Variables: ",u.program.env.map(p=>`${p.name}${p.secret?" (secret)":""}`).join(", ")]}):null]})}):n.jsxs("p",{className:"ui-card-meta",children:["buddi talks to ",n.jsx("span",{className:"mono",children:u.host})," for these tools, and nowhere else."]}),u.annotatedNothing?n.jsxs(H,{tone:"warning",children:[e.name," says nothing about what its tools do, so every one of them asks you first."]}):null,u.changes&&u.changes.added.length+u.changes.changed.length+u.changes.removed.length>0?n.jsxs(H,{tone:"warning",title:`${e.name} changed its tools since your last review.`,children:[n.jsxs("ul",{className:"connections-changes","aria-label":"What changed",children:[u.changes.added.length>0?n.jsxs("li",{children:["New: ",n.jsx("span",{className:"mono",children:u.changes.added.join(", ")})]}):null,u.changes.changed.length>0?n.jsxs("li",{children:["Changed: ",n.jsx("span",{className:"mono",children:u.changes.changed.join(", ")})]}):null,u.changes.removed.length>0?n.jsxs("li",{children:["Gone: ",n.jsx("span",{className:"mono",children:u.changes.removed.join(", ")})]}):null]}),n.jsx("p",{children:"Until you keep this list, the new and changed tools wait; the others keep working."})]}):null,u.slugEditable?n.jsx(ee,{label:"Its name in buddi",hint:`Tools are called mcp.${h||"…"}.<tool>. Lower case, letters, digits, _ and -.`,children:n.jsx("input",{required:!0,spellCheck:!1,maxLength:24,value:h,onChange:p=>i(p.target.value.toLowerCase())})}):null,u.tools.length===0?n.jsxs(oe,{children:[e.name," lists no tools."]}):n.jsx("div",{className:"ui-list","aria-label":"Tools",children:u.tools.map(p=>{const x=U5(p),j=u.slugEditable?p.fullName.replace(/^mcp\.[^.]+\./,`mcp.${h||u.slug}.`):p.fullName;return n.jsx("div",{className:"ui-list-row connections-tool",children:n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[n.jsxs("div",{className:"ui-card-head",children:[n.jsx("span",{className:"mono",children:j}),p.problem?n.jsx(ge,{tone:"muted",children:"Cannot be used"}):n.jsx(ge,{tone:x.tone,children:x.label}),p.change==="added"?n.jsx(Ia,{children:"New"}):p.change==="changed"?n.jsx(Ia,{children:"Changed"}):null]}),p.description?n.jsx("p",{className:"ui-card-meta",children:p.description}):null,!p.problem&&p.tier==="gated"?n.jsx("p",{className:"ui-card-meta",children:p.destructive?z5:"You can remember its approval for an agent when you give it the tools, or later on the agent’s Access page."}):null,p.problem?n.jsxs("p",{className:"ui-card-meta",children:["Left out: ",p.problem,"."]}):null]})},p.name)})}),n.jsx(se,{message:o}),n.jsx(Q,{align:"end",children:n.jsx(R,{variant:"accent",onClick:()=>void d(),disabled:a||u.slugEditable&&h.trim()==="",children:m===1?"Keep this tool":`Keep these ${m} tools`})})]})}function u8({connection:e,agents:t,onDone:s}){var b;const r=t.find(g=>g.frontDesk)??t[0],[i,a]=f.useState(()=>new Set(r?[r.id]:[])),o=(((b=le(()=>T.connectionTools(e.id),[e.id]).data)==null?void 0:b.tools)??[]).filter(g=>g.tier==="gated"),[c,u]=f.useState(()=>new Set),[h,d]=f.useState(!1),[m,p]=f.useState(null),x=(g,v)=>{a(w=>{const y=new Set(w);return v?y.add(g):y.delete(g),y})},j=async()=>{d(!0),p(null);try{const g=await T.grantConnection(e.id,[...i]);if(g.failed.length>0){p(g.failed.map(v=>`${v.agent}: ${v.message}`).join(" "));return}for(const v of g.granted)for(const w of c)await T.setRememberedApproval(v,w,!0);s()}catch(g){p(Ss(g))}finally{d(!1)}};return n.jsxs("div",{className:"ui-stack",children:[n.jsxs("p",{children:[r?`Give these tools to ${r.name}?`:"Which agents get these tools?"," Each one you tick gets ",n.jsx("span",{className:"mono",children:e.grant})," on its tools line."]}),n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Agents",children:t.map(g=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:i.has(g.id),onChange:v=>x(g.id,v.target.checked)}),n.jsxs("span",{children:[g.name,g.frontDesk?" (front desk)":""]})]},g.id))}),n.jsx("p",{className:"ui-card-meta",children:"No one is fine too: the connection waits here until you give it to someone."}),o.length>0?n.jsxs("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Remembered approval",children:[n.jsx("p",{children:"These ask you first. Tick one to remember your approval for the agents above, so it asks only once."}),o.map(g=>n.jsxs(J,{gap:"sm",children:[n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",disabled:!g.rememberable,checked:c.has(g.tool),onChange:v=>u(w=>{const y=new Set(w);return v.target.checked?y.add(g.tool):y.delete(g.tool),y})}),n.jsx("span",{className:"mono",children:g.tool})]}),g.why?n.jsx("p",{className:"ui-card-meta",children:g.why}):null]},g.tool))]}):null,n.jsx(se,{message:m}),n.jsxs(Q,{align:"end",children:[n.jsx(R,{onClick:s,disabled:h,children:"Not now"}),n.jsx(R,{variant:"accent",onClick:()=>void j(),disabled:h||i.size===0,children:"Give them"})]})]})}function d8({timezone:e,embedded:t}){const{data:s,error:r,reload:i}=le(()=>T.sentinels(),[],3e4),[a,l]=f.useState(null),[o,c]=f.useState(null),u=(s==null?void 0:s.installed)??[],h=((s==null?void 0:s.runs)??[]).filter(p=>p.lastError),d=u.filter(p=>!p.enabled),m=(p,x)=>{l(p),c(null),T.setSentinelEnabled(p,x).catch(j=>c(j instanceof pe?j.message:String(j))).finally(()=>{l(null),i()})};return n.jsxs(yn,{embedded:t,title:"Watchers",children:[n.jsx(se,{message:r??o}),n.jsx(H,{children:"Watchers are small checks that run on their own, with no model involved. An urgent finding wakes an agent, which verifies it before it tells you. The rest waits for the weekly recap."}),h.length>0?n.jsx(H,{tone:"warning",children:h.length===1?"One watcher failed on its last run.":`${h.length} watchers failed on their last run.`}):null,d.length>0?n.jsxs(H,{tone:"warning",children:[d.length===1?"One watcher is off.":`${d.length} watchers are off.`," A watcher that is off does not run, and what it already found stays as it was."]}):null,n.jsx(te,{title:"Installed",aside:n.jsx("a",{href:`${St}/alerts`,children:"See what they found"}),panel:!0,flush:!0,children:s?u.length===0?n.jsx(tn,{icon:"eye",title:"No watchers are installed",children:"Plugins bring their own."}):n.jsx(At,{children:u.map(p=>{const x=s.runs.find(j=>j.sentinelId===p.id);return n.jsx(Tt,{lead:n.jsx(ge,{tone:p.enabled?x!=null&&x.lastError?"critical":x?"good":void 0:"muted",children:p.enabled?x!=null&&x.lastError?"failed":x?"ok":"never ran":"off"}),title:p.description,sub:`${p.id}, every ${h8(p.every)}${x!=null&&x.lastError?`. ${x.lastError}`:""}`,side:n.jsxs(n.Fragment,{children:[n.jsx("span",{title:x?Be(x.lastRunAt,e):void 0,children:x?Fe(x.lastRunAt):"never ran"}),n.jsx(R,{size:"sm",disabled:a===p.id,onClick:()=>m(p.id,!p.enabled),children:p.enabled?"Turn off":"Turn on"})]})},p.id)})}):n.jsx(oe,{children:"Loading…"})})]})}function h8(e){if(e%86400===0){const s=e/86400;return s===1?"day":`${s} days`}if(e%3600===0){const s=e/3600;return s===1?"hour":`${s} hours`}const t=Math.max(1,Math.round(e/60));return t===1?"minute":`${t} minutes`}function f8({embedded:e}){const{data:t,error:s,reload:r}=le(()=>T.owner(),[]);return n.jsxs(yn,{embedded:e,title:"You",lede:"What every agent knows about the person it is talking to.",children:[n.jsx(se,{message:s}),t?n.jsx(m8,{initial:t,onSaved:r}):null]})}function m8({initial:e,onSaved:t}){const[s,r]=f.useState(e.preferredName??""),[i,a]=f.useState(e.timezone??""),[l,o]=f.useState(e.language??""),[c,u]=f.useState(e.about??""),[h,d]=f.useState(!1),[m,p]=f.useState(!1),[x,j]=f.useState(null);f.useEffect(()=>{r(e.preferredName??""),a(e.timezone??""),o(e.language??""),u(e.about??"")},[e]);const b=s.trim()!==(e.preferredName??"")||i!==(e.timezone??"")||l.trim()!==(e.language??"")||c.trim()!==(e.about??""),g=async()=>{d(!0),j(null);try{await T.setOwner({preferredName:s.trim()===""?null:s.trim(),timezone:i===""?null:i,language:l.trim()===""?null:l.trim(),about:c.trim()===""?null:c.trim()}),p(!0),t()}catch(w){j(w instanceof pe?w.message:String(w))}finally{d(!1)}},v=e.zones.length>0?e.zones:[e.detectedTimezone];return n.jsx(te,{title:"Your profile",aside:"read by every agent, as context",panel:!0,foot:n.jsxs(n.Fragment,{children:[m&&!b?n.jsx("span",{className:"muted",children:"Saved"}):null,n.jsx(R,{variant:"accent",disabled:!b||h,onClick:()=>void g(),children:h?"Saving…":"Save"})]}),children:n.jsxs(J,{divided:!0,gap:"lg",children:[n.jsx(te,{title:"Name and place",children:n.jsxs(bs,{children:[n.jsx(ee,{label:"What the agents call you",children:n.jsx("input",{value:s,maxLength:80,placeholder:e.displayName??"Your name",onChange:w=>{p(!1),r(w.target.value)}})}),n.jsx(ee,{label:"Timezone",hint:`This host is in ${e.detectedTimezone}. Existing schedules keep the zone they were made in.`,children:n.jsxs("select",{value:i,onChange:w=>{p(!1),a(w.target.value)},children:[n.jsx("option",{value:"",children:"Not set (use the host's)"}),v.map(w=>n.jsx("option",{value:w,children:w},w))]})}),n.jsx(ee,{label:"Answer me in",hint:"A language, as you would say it. Blank mirrors whatever you write in.",children:n.jsx("input",{value:l,maxLength:40,placeholder:"English, français…",onChange:w=>{p(!1),o(w.target.value)}})})]})}),n.jsxs(te,{title:"About you",children:[n.jsx(ee,{label:"In your own words",hint:"Who you are, how you like answers, anything every agent should keep in mind. A few lines is plenty.",children:n.jsx("textarea",{rows:4,maxLength:1e3,value:c,placeholder:"I run a small studio and prefer short answers with the numbers first. Call me by my first name.",onChange:w=>{p(!1),u(w.target.value)}})}),x?n.jsx(H,{tone:"critical",children:x}):null]})]})})}const p8=2e6;function ib(e,t){const s=e.replace(/\r\n/g,`
115
- `).replace(/\n+$/,"").split(`
116
- `),r=t.replace(/\r\n/g,`
117
- `).replace(/\n+$/,"").split(`
118
- `);if(e.trim()===t.trim())return"(no change)";if(s.length*r.length>p8)return[...s.map(c=>`-${c}`),...r.map(c=>`+${c}`)].join(`
119
- `);const i=Array.from({length:s.length+1},()=>new Uint32Array(r.length+1));for(let c=s.length-1;c>=0;c--)for(let u=r.length-1;u>=0;u--)i[c][u]=s[c]===r[u]?i[c+1][u+1]+1:Math.max(i[c+1][u],i[c][u+1]);const a=[];let l=0,o=0;for(;l<s.length&&o<r.length;)s[l]===r[o]?(a.push(` ${s[l]}`),l++,o++):i[l+1][o]>=i[l][o+1]?a.push(`-${s[l++]}`):a.push(`+${r[o++]}`);for(;l<s.length;)a.push(`-${s[l++]}`);for(;o<r.length;)a.push(`+${r[o++]}`);return a.join(`
120
- `)}const g8={skill:"skill",policy:"rule",change:"change to itself"};function x8(e){return e===null||typeof e!="object"||Array.isArray(e)?String(e??""):Object.entries(e).filter(([t,s])=>!/Id$/.test(t)&&s!==null&&s!==void 0&&s!=="").map(([t,s])=>`${t} ${typeof s=="object"?JSON.stringify(s):String(s)}`).join(" · ")}function Op(e){return[...new Set(e.split(/[,\n]/).map(t=>t.trim().replace(/^[-*]\s+/,"")).filter(t=>t!==""))]}function v8(e,t){const s=e.change;if(!s||s.part!=="tools")return[];if(t===e.editable)return s.added;const r=new Set(Op(s.current??""));return Op(t).filter(i=>!r.has(i))}function ab(e,t){return!t||e.kind==="policy"&&e.payload.plugin===t}function j8({embedded:e,plugin:t}){const{data:s,error:r,reload:i}=le(()=>T.proposals(),[],3e4),[a,l]=f.useState(null),[o,c]=f.useState(null),[u,h]=f.useState(null),[d,m]=f.useState({}),p=async(g,v,w=!1)=>{l(null),c(null),h(g),m(({[g]:y,...N})=>N);try{c(await v()),i()}catch(y){const N=y instanceof Error?y.message:String(y);w?m(k=>({...k,[g]:N})):l(N)}finally{h(null)}},x=nC(),j=((s==null?void 0:s.open)??[]).filter(g=>ab(g,t)),b=((s==null?void 0:s.closed)??[]).filter(g=>ab(g,t));return n.jsxs(yn,{embedded:e,title:"Proposals",lede:"What your agents learned and would like to keep: a procedure, a rule, a change to their own instructions. Nothing here applies itself. Keep what is right, correct what is nearly right, discard the rest.",children:[n.jsx(se,{message:r??a}),t?n.jsxs(H,{role:"status",children:["Showing the rules ",t," proposes. ",n.jsx("a",{href:et("proposals"),children:"Show every proposal"})]}):null,o?n.jsx(H,{tone:"good",role:"status",children:o}):null,t?null:n.jsx(sC,{offers:x.offers,reload:x.reload}),!s||j.length===0?n.jsx(te,{title:"Waiting",panel:!0,children:s?t?n.jsx(tn,{icon:"bulb",title:`No rule from ${t} is waiting`,children:"It proposes one when you decide the same way several times running."}):n.jsx(tn,{icon:"bulb",title:"Nothing proposed",children:"When an agent learns something worth keeping, it waits here."}):n.jsx(oe,{children:"Loading…"})}):n.jsx(te,{title:"Waiting",aside:`${j.length} to decide`,children:j.map(g=>n.jsx(k8,{proposal:g,busy:u===g.id,refusal:d[g.id]??null,onKeep:v=>void p(g.id,async()=>{const w=await T.keepProposal(g.id,v);return`${g.title}: ${w.note}`},!0),onDiscard:v=>void p(g.id,async()=>(await T.discardProposal(g.id,v),`Discarded: ${g.title}. ${g.agent} will be told once and will not propose it again for 90 days.`))},g.id))}),b.length>0?n.jsx(te,{title:`Kept, discarded and expired (${b.length})`,aside:"These stop being shown a week after they were decided.",panel:!0,flush:!0,children:n.jsx(At,{children:b.map(g=>{var v;return n.jsx(Tt,{title:g.title,sub:`${g.agent}: ${w8(g)}`,side:g.kind==="skill"&&g.state==="kept"&&((v=g.skill)!=null&&v.live)?n.jsxs(Q,{align:"end",children:[n.jsx("span",{className:"muted",children:Fe(g.decidedAt??g.createdAt)}),n.jsx(R,{size:"sm",variant:"ghost",disabled:u===g.id,onClick:()=>void p(g.id,async()=>{const w=g.skill;return await T.removeSkill(g.agent,w.name),`Removed ${w.name} from ${g.agent}. Its versions are kept, and ${g.agent} will not propose it again for 90 days.`}),children:"Remove this skill"})]}):Fe(g.decidedAt??g.createdAt)},g.id)})})}):null,!t&&(s!=null&&s.digest)?n.jsx(b8,{schedule:s.digest.schedule,onSaved:i}):null]})}function w8(e){switch(e.state){case"kept":return 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 y8=Array.from({length:24},(e,t)=>t),lb=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function b8({schedule:e,onSaved:t}){const[s,r]=f.useState(e.day),[i,a]=f.useState(e.hour),[l,o]=f.useState(!1),[c,u]=f.useState(null),h=s!==e.day||i!==e.hour,d=async()=>{o(!0),u(null);try{await T.setDigestSchedule(s,i),u({tone:"good",text:`The digest now runs on ${lb[s]} at ${String(i).padStart(2,"0")}:00.`}),t()}catch(m){u({tone:"critical",text:m instanceof Error?m.message:String(m)})}finally{o(!1)}};return n.jsx(te,{title:"Weekly digest",panel:!0,foot:n.jsx(R,{variant:"accent",disabled:l||!h,onClick:()=>void d(),children:"Save"}),children:n.jsxs(J,{children:[n.jsxs("p",{className:"muted",children:["Once a week, one message on Telegram and a card on Home: what your agents learned, what waits here, and what the rules you kept stopped them doing. No message when nothing was learned and nothing waits.",e.next?` Next: ${Fe(e.next)}.`:""]}),n.jsxs(Q,{children:[n.jsx(ee,{label:"Day",children:n.jsx("select",{value:s,disabled:l,onChange:m=>r(Number(m.target.value)),children:lb.map((m,p)=>n.jsx("option",{value:p,children:m},m))})}),n.jsx(ee,{label:`Hour (${e.timezone})`,children:n.jsx("select",{value:i,disabled:l,onChange:m=>a(Number(m.target.value)),children:y8.map(m=>n.jsxs("option",{value:m,children:[String(m).padStart(2,"0"),":00"]},m))})})]}),c?n.jsx(H,{tone:c.tone,role:"status",children:c.text}):null]})})}function ob(e,t){return e==="tools"?Op(t).join(`
121
- `):t}function k8({proposal:e,busy:t,refusal:s,onKeep:r,onDiscard:i}){const[a,l]=f.useState(e.editable??""),[o,c]=f.useState(""),u=e.editable!==null&&a!==e.editable,h=e.payload,d=e.echoes??[],m=e.kind==="change"?e.change??null:null,p=v8(e,a);return n.jsx(ks,{tone:e.untrusted?"warning":"accent",title:e.title,meta:n.jsxs(n.Fragment,{children:[n.jsx(ge,{children:g8[e.kind]}),n.jsx(ge,{mono:!0,children:e.agent}),e.untrusted?n.jsx(ge,{tone:"warning",children:"untrusted text in view"}):null,p.length>0?n.jsx(ge,{tone:"warning",children:"widens its tools"}):null]}),foot:n.jsxs(Q,{align:"end",children:[s?n.jsx("span",{className:"proposal-refusal",role:"alert",children:s}):null,n.jsx("input",{"aria-label":"Reason for discarding (optional)",placeholder:"Reason for discarding (optional)",value:o,maxLength:300,disabled:t,onChange:x=>c(x.target.value)}),n.jsx(R,{variant:"ghost",size:"sm",disabled:t,onClick:()=>i(o.trim()||void 0),children:"Discard"}),n.jsx(R,{variant:"accent",size:"sm",disabled:t||e.editable!==null&&a.trim()==="",onClick:()=>r(u?a:void 0),children:u?"Keep my version":"Keep"})]}),children:n.jsxs(J,{gap:"sm",children:[e.why?n.jsx("p",{children:e.why}):null,n.jsxs("p",{className:"ui-card-meta",children:["Proposed by ",e.agent," ",Fe(e.createdAt),e.conversationId?n.jsxs(n.Fragment,{children:[" in ",n.jsx("a",{href:Wa(e.conversationId),children:e.turn?`this conversation, turn ${e.turn}`:"this conversation"})]}):null,"."]}),e.untrusted?n.jsxs(H,{tone:"warning",title:e.kind==="policy"?"Learned from mail you received.":"Made with untrusted text in view.",children:[e.kind==="policy"?"The plugin counted this rule from your own triage decisions; no instruction in that mail can change what it does.":"Something written by someone other than you was in the agent's context when it proposed this. Read it for instructions that came from there rather than from you.",n.jsx("ul",{className:"proposal-sources",children:e.sources.map(x=>n.jsx("li",{className:"mono",children:x},x))}),d.length>0?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"proposal-echo-lede",children:"These sentences of it also appear in that text:"}),n.jsx("ul",{className:"proposal-sources","aria-label":"Sentences found in the untrusted text",children:d.map(x=>n.jsx("li",{children:n.jsx("mark",{className:"wb-diff-mark",children:x})},x))})]}):null]}):null,e.kind==="skill"?n.jsxs(n.Fragment,{children:[typeof h.when=="string"?n.jsxs("p",{className:"ui-card-meta",children:["When: ",h.when]}):null,e.skill?n.jsxs(J,{gap:"sm",children:[n.jsxs("p",{className:"ui-card-meta",children:[e.agent," already has this skill (",n.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."]}),n.jsx(qu,{text:ib(e.skill.steps,a),marks:d,label:`Version ${e.skill.version} against this proposal`})]}):null,n.jsx(ee,{label:"The steps, as it would follow them",hint:"Correct them here and keep your version.",children:n.jsx("textarea",{rows:8,value:a,disabled:t,onChange:x=>l(x.target.value)})})]}):null,e.kind==="change"?n.jsxs(n.Fragment,{children:[p.length>0?n.jsxs(H,{tone:"warning",title:`Adds: ${p.join(", ")}`,children:["Keeping this lets ",e.agent," call tools it cannot call now."]}):null,m!=null&&m.refusal&&!u?n.jsx(H,{tone:"warning",title:"Keeping this as proposed will be refused.",children:m.refusal}):null,m&&m.current!==null?n.jsx(qu,{text:ib(ob(m.part,m.current),ob(m.part,a)),marks:d,label:`${e.agent}'s ${m.part==="tools"?"tool list":"instructions"} now, against this proposal`}):typeof h.before=="string"?n.jsx($t,{summary:`What its ${h.part==="tools"?"tool list":"instructions"} said when proposed`,children:n.jsx(xt,{children:h.before})}):null,n.jsx(ee,{label:h.part==="tools"?"Proposed tool list":"Proposed instructions",hint:"Correct it here and keep your version.",children:n.jsx("textarea",{rows:8,value:a,disabled:t,onChange:x=>l(x.target.value)})})]}):null,e.kind==="policy"?n.jsx(Vt,{items:[{label:"Plugin",value:n.jsx("span",{className:"mono",children:String(h.plugin??"")})},{label:"Matches",value:n.jsx("span",{className:"mono",children:x8(h.matcher??{})})},{label:"Does",value:String(h.action??"")},{label:"Learned from",value:(()=>{const x=Array.isArray(h.verdicts)?h.verdicts.length:0;return`${x} ${x===1?"decision":"decisions"}`})()}]}):null]})})}function S8(e){const t=[{label:"Home",path:e.home}];if(e.path===e.home||!e.path.startsWith(`${e.home}/`))return t;let s=e.home;for(const r of e.path.slice(e.home.length+1).split("/"))s=`${s}/${r}`,t.push({label:r,path:s});return t}function N8({start:e,onPick:t,onClose:s}){const[r,i]=f.useState(null),[a,l]=f.useState(null),[o,c]=f.useState(""),u=(p,x=!1)=>{l(null),T.pluginFolders(p).then(j=>{i(j),c("")}).catch(j=>{x&&p!==void 0?u(void 0):l(j instanceof pe?j.message:String(j))})};f.useEffect(()=>{u(e,!0)},[]);const h=o.trim().toLowerCase(),d=((r==null?void 0:r.folders)??[]).filter(p=>h===""||p.name.toLowerCase().includes(h)),m=r?S8(r):[];return n.jsxs(wt,{title:"Choose the folder",onClose:s,foot:n.jsxs(Q,{children:[n.jsx("span",{className:"plugins-foot-note mono",children:(r==null?void 0:r.path)??""}),n.jsx(en,{}),n.jsx(R,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(R,{variant:"accent",disabled:!r,onClick:()=>r&&t(r.path),children:"Use this folder"})]}),children:[n.jsx("p",{className:"plugins-note",children:"Folders on the computer buddi runs on, inside your home directory. The one you want holds the plugin's package.json and is already built."}),r?n.jsx(y1,{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:()=>u(p.path)})}):null,n.jsx(w1,{label:"Find a folder here",value:o,placeholder:"Find a folder here…",onChange:c}),n.jsx(se,{message:a}),r?d.length===0?n.jsx(oe,{children:h===""?"No folders in here.":`No folder here is called anything like “${o.trim()}”.`}):n.jsx(qe,{flush:!0,children:n.jsx(At,{children:d.map(p=>n.jsx(Tt,{onClick:()=>u(p.path),label:`Open ${p.name}`,lead:n.jsx(Ka,{icon:"folder"}),title:p.name,side:p.plugin?n.jsx(ge,{tone:"accent",children:"package.json"}):void 0},p.path))})}):a?null:n.jsx(oe,{children:"Reading the folders…"}),r!=null&&r.truncated?n.jsx("p",{className:"plugins-note",children:"Only the first 500 folders are listed; find one by name above."}):null]})}const C8="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 cb(){return n.jsxs("p",{className:"plugins-quiet connections-quiet",children:[n.jsx(we,{name:"globe",size:14}),n.jsxs("span",{children:["A plugin is code buddi installs and runs; a connection is a service or program buddi talks to."," ",n.jsx("a",{href:et("connections"),children:"Connections"})]})]})}const E8=1500,A8={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."},T8="Restart buddi to apply it. In a checkout, stop it and run: buddi serve",LE=[{value:"npm",label:"From npm"},{value:"file",label:"A file"},{value:"directory",label:"A directory I built"}],FE="buddi.plugins.install-mode";function R8(){try{const e=window.localStorage.getItem(FE);if(LE.some(t=>t.value===e))return e}catch{}return"npm"}function I8(e){try{window.localStorage.setItem(FE,e)}catch{}}const Hc=".tgz",qr=(e,t,s)=>`${e} ${e===1?t:s}`;function zE(e){const t=[];return e.tools>0&&t.push(qr(e.tools,"tool","tools")),e.sentinels>0&&t.push(`${e.sentinels} on a timer`),e.views>0&&t.push(qr(e.views,"view","views")),e.agents>0&&t.push(`${qr(e.agents,"agent","agents")} proposed`),t.length===0?"nothing on its own":t.join(", ")}function Dp(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 P8(e){return e.kind==="registry"?"npm":e.kind==="tarball"?"a file":"a directory"}function UE(e,t){return e.kind==="directory"?"you, from this machine":e.kind==="tarball"?"a file on this machine":t??"nobody npm will name"}function BE(e){return e.author?e.author.name:e.source.kind==="registry"?e.publisher??"nobody npm will name":"you"}function mv({author:e}){return e.url?n.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",children:e.name}):n.jsx(n.Fragment,{children:e.name})}function _p({value:e}){return e===void 0||e===""?n.jsx("span",{className:"muted",children:"none — this came off a disk"}):n.jsx("span",{className:"plugins-hash",children:e})}function WE(e){return e.length===0?"none; nothing leaves this computer":n.jsx("span",{className:"mono",children:e.join(", ")})}function pv(e){return e.length===0?"Nothing beyond its own tables, its own folder and its own tools' approvals.":e.map(t=>`It ${t.words}.`).join(" ")}const ri=e=>e instanceof pe?e.message:String(e);function $8(e){const[t,s]=f.useState(void 0),[r,i]=f.useState(null);return f.useEffect(()=>{if(!e){s(void 0),i(null);return}let a=!1;const l=()=>{T.pluginJob(e).then(c=>{a||(s(c),(c.phase==="done"||c.phase==="failed")&&(a=!0))}).catch(c=>{a||(i(ri(c)),a=!0)})};l();const o=window.setInterval(l,E8);return()=>{a=!0,window.clearInterval(o)}},[e]),{job:t,error:r}}function M8({plugin:e,pages:t,navigate:s,variant:r}){const i=t.filter(a=>a.plugin===e);return i.length===0?null:n.jsx(n.Fragment,{children:i.map(a=>{const l=ti(a.plugin,a.id);return n.jsx(Zt,{size:"sm",variant:r,href:l,"aria-label":`Open ${a.title}`,onClick:o=>{o.stopPropagation(),s&&(o.preventDefault(),s(l))},children:i.length===1?"Open":`Open ${a.title}`},a.id)})})}function HE({plugin:e}){return e.enabled===!1?n.jsx(ge,{children:"disabled"}):e.loaded?n.jsx(ge,{tone:"good",dot:!0,children:"loaded"}):n.jsx(ge,{tone:"critical",children:"did not load"})}function gv({entry:e}){var t;return e.trust==="by-buddi"?n.jsx(ge,{tone:"accent",children:"by buddi"}):n.jsxs(ge,{tone:"good",children:["reviewed ",((t=e.reviewed)==null?void 0:t.version)??e.version]})}const Lp=et("plugins"),Cf={installed:Lp,browse:`${Lp}?tab=browse`};function O8({railPages:e=[],settingsPages:t=[],navigate:s,hash:r=""}={}){const i=le(()=>T.plugins(),[],2e4),[a,l]=f.useState(null),{job:o,error:c}=$8(a),[u,h]=f.useState(null),[d,m]=f.useState(null),[p,x]=f.useState(()=>Lw(r));f.useEffect(()=>x(Lw(r)),[r]);const[j,b]=f.useState(null),[g,v]=f.useState(null),[w,y]=f.useState(null),[N,k]=f.useState(null),[S,C]=f.useState(!1),I=G=>{C(!0),T.market(G).then(k).catch(ie=>k({plugins:[],unavailable:ri(ie)})).finally(()=>C(!1))};f.useEffect(()=>{p==="browse"&&N===null&&!S&&I(!1)},[p]);const A=G=>{h(null),m(null),l(G)},O=G=>h(ri(G)),[z,L]=f.useState(!1),E=G=>{L(!0),b(null),G.then(ie=>{A(ie.job.id),x("installed")}).catch(O).finally(()=>L(!1))},$=f.useRef(null);f.useEffect(()=>{const G=YO(r);if(!(G===null||$.current===G)){$.current=G,x("installed"),E(T.stagePlugin(G));try{window.history.replaceState(window.history.state,"",Lp)}catch{}}},[r]);const _=G=>ie=>{ie.preventDefault(),x(G),b(null),s==null||s(Cf[G])};f.useEffect(()=>{((o==null?void 0:o.phase)==="done"||(o==null?void 0:o.phase)==="failed")&&i.reload()},[o==null?void 0:o.phase]);const B=i.data,M=(B==null?void 0:B.checkout)??!0,W=(B==null?void 0:B.installed)??[],D=G=>N==null?void 0:N.plugins.find(ie=>ie.installed!==void 0&&(ie.installed.name??ie.name)===G.name),U=G=>e.some(ie=>ie.plugin===G),V=(G,ie)=>U(G)?n.jsx(M8,{plugin:G,pages:e,navigate:s,variant:ie}):void 0,Z=G=>{const ie=e.find($e=>$e.plugin===G);ie&&s&&s(ti(ie.plugin,ie.id))},ue=G=>{const ie=t.find($e=>$e.plugin===G);if(!(!ie||!s))return()=>s(al(ie.plugin,ie.id))},Ae=((N==null?void 0:N.plugins)??[]).filter(G=>G.update).length,X=(G,ie)=>T.setPluginEnabled(G,ie).then($e=>{OL(),y({name:G,notes:$e.notes??[]}),i.reload()}),ae=(G,ie,$e)=>T.uninstallPlugin(G,ie?{purge:!0,confirm:$e}:{}).then(yt=>{b(null),y({name:G,notes:yt.notes??[]}),i.reload()}),me=G=>{h(null),X(G,!0).catch(O)},Pe=(G,ie)=>{const $e=N==null?void 0:N.plugins.find(Ge=>{var it;return(((it=Ge.installed)==null?void 0:it.name)??Ge.name)===G&&Ge.installed!==void 0}),yt=$e&&ie?`${$e.npm}@${ie}`:void 0;E(yt?T.updatePlugin(G,ie,yt):T.updatePlugin(G,ie))},ke=n.jsxs(Go,{label:"Plugins",children:[n.jsx(Ha,{href:Cf.installed,active:p==="installed",count:Ae,onClick:_("installed"),children:"Installed"}),n.jsx(Ha,{href:Cf.browse,active:p==="browse",onClick:_("browse"),children:"Browse"})]}),ye=(j==null?void 0:j.kind)==="installed"?W.find(G=>G.name===j.name):void 0,Ce=(j==null?void 0:j.kind)==="market"?N==null?void 0:N.plugins.find(G=>G.name===j.name):void 0,ut=w&&!(ye&&ye.name===w.name)&&w.notes.length>0?w.notes:null,fe=ye?n.jsx(H8,{plugin:ye,listing:D(ye),notes:(w==null?void 0:w.name)===ye.name?w.notes:null,canOpen:U(ye.name)&&ye.enabled!==!1,onOpen:()=>Z(ye.name),onClose:()=>b(null),onDisable:()=>v({kind:"disable",name:ye.name}),onEnable:()=>me(ye.name),onRemove:()=>v({kind:"remove",name:ye.name}),onUpdate:G=>Pe(ye.name,G),onSettings:ye.enabled===!1?void 0:ue(ye.name),busy:z}):Ce?n.jsx(X8,{entry:Ce,canOpen:Ce.installed!==void 0&&U(Ce.installed.name??Ce.name),onOpen:()=>{var G;return Z(((G=Ce.installed)==null?void 0:G.name)??Ce.name)},onClose:()=>b(null),onInstall:()=>E(T.stagePlugin(`${Ce.npm}@${Ce.version}`)),onUpdate:G=>{var ie;return Pe(((ie=Ce.installed)==null?void 0:ie.name)??Ce.name,G)},busy:z}):null,Me=g?W.find(G=>G.name===g.name):void 0,ce=g?n.jsx(K8,{kind:g.kind,name:g.name,canDisable:(Me==null?void 0:Me.enabled)!==!1,onCancel:()=>v(null),onDisableInstead:()=>v({kind:"disable",name:g.name}),onDisable:()=>X(g.name,!1).then(()=>v(null)),onRemove:(G,ie)=>ae(g.name,G,ie).then(()=>v(null))},`${g.kind}:${g.name}`):null;if(p==="browse")return n.jsxs(J,{gap:"lg",children:[n.jsx(cb,{}),ke,n.jsx(se,{message:u}),n.jsx(Z8,{market:N,loading:S,busy:z,onRetry:()=>I(!0),onOpen:G=>b({kind:"market",name:G.name}),onInstall:G=>E(T.stagePlugin(`${G.npm}@${G.version}`)),onUpdate:(G,ie)=>{var $e;return Pe((($e=G.installed)==null?void 0:$e.name)??G.name,ie)}}),fe]});const Te=(B==null?void 0:B.builtIn)??[];return n.jsxs(J,{gap:"lg",children:[n.jsx(cb,{}),ke,n.jsx(se,{message:i.error??u??c}),B!=null&&B.unavailable?n.jsx(H,{tone:"warning",children:B.unavailable}):null,ut?n.jsx(H,{role:"status",children:ut.join(" ")}):null,n.jsx(D8,{trust:(B==null?void 0:B.trust)??"",job:o,busy:o!==void 0&&o.phase!=="done"&&o.phase!=="failed",onStaged:A,onFailed:h}),((B==null?void 0:B.staged)??[]).map(G=>n.jsx(L8,{staged:G,onInstalled:ie=>{m(ie),l(null),i.reload()},onGone:()=>i.reload()},G.id)),d||B!=null&&B.restartNeeded?n.jsx(F8,{checkout:M,name:d}):null,n.jsx(qe,{flush:!0,title:"Installed",tool:B?qr(W.length,"plugin","plugins"):void 0,children:B?W.length===0?n.jsx(oe,{children:"Nothing installed yet. Only what buddi ships with is here."}):n.jsx("div",{className:"plugins-rows",children:n.jsx(At,{children:W.map(G=>n.jsx(U8,{plugin:G,listing:D(G),open:G.enabled===!1?void 0:V(G.name,"ghost"),canOpen:U(G.name)&&G.enabled!==!1,busy:z,onDetails:()=>b({kind:"installed",name:G.name}),onOpen:()=>Z(G.name),onSettings:G.enabled===!1?void 0:ue(G.name),onDisable:()=>v({kind:"disable",name:G.name}),onEnable:()=>me(G.name),onRemove:()=>v({kind:"remove",name:G.name}),onUpdate:ie=>Pe(G.name,ie)},G.name))})}):n.jsx(oe,{children:"Loading…"})}),Te.length>0?n.jsx(V8,{plugins:Te,openFor:V}):null,fe,ce]})}function D8({trust:e,job:t,busy:s,onStaged:r,onFailed:i}){const[a,l]=f.useState(R8),[o,c]=f.useState(""),[u,h]=f.useState(!1),[d,m]=f.useState(null),[p,x]=f.useState(null),[j,b]=f.useState(!1),[g,v]=f.useState(!1),w=f.useRef(null),y=C=>i(ri(C)),N=C=>{l(C),I8(C),x(null)},k=()=>{h(!0),T.stagePlugin(o.trim()).then(C=>{r(C.job.id),c("")}).catch(y).finally(()=>h(!1))},S=C=>{if(C){if(!C.name.toLowerCase().endsWith(Hc)){m(null),x(`${C.name} is not a ${Hc}. A packed plugin is the file npm pack writes.`);return}x(null),m(C.name),h(!0),T.uploadPlugin(C).then(I=>r(I.job.id)).catch(y).finally(()=>h(!1))}};return n.jsxs(qe,{title:"Add a plugin",actions:n.jsx(ls,{label:"Where it comes from",options:LE,value:a,onChange:N}),children:[n.jsxs("div",{className:"plugins-add",children:[a==="file"?n.jsxs("div",{className:"plugins-drop",role:"group","aria-label":"A plugin file","data-state":j?"over":p?"refused":d?"chosen":void 0,onDragOver:C=>{C.preventDefault(),b(!0)},onDragLeave:()=>b(!1),onDrop:C=>{var I,A;C.preventDefault(),b(!1),S((A=(I=C.dataTransfer)==null?void 0:I.files)==null?void 0:A[0])},children:[n.jsx(we,{name:"drop",size:20}),n.jsx("span",{className:"plugins-drop-text",children:p??(d?`${d} — reading it.`:n.jsxs(n.Fragment,{children:["Drop a ",n.jsx("span",{className:"mono",children:Hc})," here: the file ",n.jsx("span",{className:"mono",children:"npm pack"})," ","writes. It is read the moment it lands."]}))}),n.jsx(R,{variant:"accent",disabled:s||u,onClick:()=>{var C;return(C=w.current)==null?void 0:C.click()},children:"Choose a file"}),n.jsx("input",{ref:w,type:"file",accept:Hc,hidden:!0,"aria-hidden":"true",tabIndex:-1,onChange:C=>{var I;S((I=C.target.files)==null?void 0:I[0]),C.target.value=""}})]}):n.jsxs("div",{className:"plugins-add-row",children:[n.jsxs(Q,{valign:"end",children:[n.jsx(ee,{grow:!0,label:a==="npm"?"Package":"The directory it is in",children:n.jsx("input",{type:"text",value:o,placeholder:a==="npm"?"buddi-plugin-weather":"/home/you/code/buddi-plugin-weather",onChange:C=>c(C.target.value)})}),a==="directory"?n.jsx(R,{onClick:()=>v(!0),children:"Browse…"}):null,n.jsx(R,{variant:"accent",disabled:s||u||o.trim()==="",onClick:k,children:"Read it first"})]}),n.jsx("span",{className:"ui-field-hint",children:a==="npm"?"A package name, or a name@version. Reading fetches it and hashes it; nothing of it runs.":"The folder with its package.json, already built. Nothing of it runs until you say yes."})]}),t?n.jsxs("p",{className:"plugins-status",role:"status","data-tone":t.phase==="failed"?"critical":void 0,children:[A8[t.phase]," ",t.error??""]}):null,n.jsx("div",{className:"plugins-trust",children:n.jsx(H,{tone:"warning",children:e})})]}),g?n.jsx(N8,{start:o.trim().startsWith("/")?o.trim():void 0,onClose:()=>v(!1),onPick:C=>{c(C),v(!1)}}):null]})}function _8({staged:e}){var r,i;const t=((r=e.uses)==null?void 0:r.areas)??[],s=((i=e.uses)==null?void 0:i.dropped)??[];return n.jsxs("span",{className:"plugins-uses",children:[t.length===0?pv([]):t.map(a=>n.jsxs("span",{children:["It ",a.words,". ",a.added?n.jsxs(ge,{tone:"warning",children:["new in ",e.version]}):null]},a.use)),s.length>0?n.jsxs("span",{className:"muted",children:["No longer: ",s.map(a=>a.words).join("; "),"."]}):null]})}function L8({staged:e,onInstalled:t,onGone:s}){const[r,i]=f.useState(e.plan??null),[a,l]=f.useState(!1),[o,c]=f.useState(null),u=p=>{l(!0),c(null),T.approveStaged(e.id,{integrity:e.integrity??"",...p?{acknowledgeDrift:!0}:{}}).then(x=>{x.installed?t(e.name):x.plan&&i(x.plan)}).catch(x=>c(ri(x))).finally(()=>l(!1))},h=()=>{l(!0),c(null),T.rejectStaged(e.id).then(()=>s()).catch(p=>c(ri(p))).finally(()=>l(!1))},d=(r==null?void 0:r.drift)??[],m=e.dependencies;return n.jsxs(J,{gap:"sm",children:[n.jsxs(ks,{tone:"accent",title:n.jsxs(n.Fragment,{children:[e.name," ",n.jsx("span",{className:"plugins-ver",children:e.version})]}),meta:n.jsx(ge,{children:"read, not installed"}),foot:n.jsxs(Q,{children:[n.jsx("span",{className:"plugins-foot-note",children:"Nothing of it has run."}),n.jsx(en,{}),n.jsx(R,{variant:"ghost",disabled:a,onClick:h,children:"Not this one"}),n.jsx(R,{variant:"accent",disabled:a||d.length>0,onClick:()=>u(!1),children:"Install"})]}),children:[n.jsx(se,{message:o}),n.jsxs("div",{className:"plugins-staged",children:[n.jsx("div",{className:"plugins-facts",children:n.jsx(Vt,{items:[...e.author?[{label:"By",value:n.jsx(mv,{author:e.author})}]:[],{label:"From",value:e.uploadedName?`a file you chose · ${e.uploadedName}`:Dp(e.source)},{label:"Published by",value:UE(e.source,e.publisher)},...e.previousSource&&e.previous?[{label:"Replaces",value:`${e.previous.version}, installed from ${Dp(e.previousSource)}`}]:[],...e.source.kind==="directory"?[]:[{label:"Installs as",value:e.installsAs?n.jsx("span",{className:"mono",children:e.installsAs}):"the name its manifest gives, read when you approve — it declares no buddi.name"}],...e.coreAsDependency?[{label:"Core",value:"It asks npm for buddi's core; buddi provides its own."}]:[],{label:"Dependencies",value:m.count===0?"none":`${m.count}${m.withScripts.length===0?", none of which run install scripts":`, of which these run install scripts: ${m.withScripts.join(", ")}`}`},{label:"What it reaches",value:n.jsx(_8,{staged:e})},{label:"Integrity",value:n.jsx(_p,{value:e.integrity})},...e.stagedHash?[{label:"Files on disk",value:n.jsx(_p,{value:e.stagedHash})}]:[]]})}),n.jsxs("div",{className:"plugins-claim",children:[n.jsx("div",{className:"plugins-claim-head",children:"What it says about itself"}),n.jsx("div",{className:"plugins-claim-note",children:"From its own buddi.md. Nothing has checked it yet."}),e.claims.missing?n.jsx("p",{className:"plugins-claim-text",children:"It ships no buddi.md, so it says nothing about itself at all."}):n.jsxs("p",{className:"plugins-claim-text",children:["“",e.claims.text,"”"]}),n.jsx("div",{className:"plugins-facts",children:n.jsx(Vt,{items:[{label:"Schema it owns",value:e.claims.schema?n.jsx("span",{className:"mono",children:e.claims.schema}):"it claims none"},{label:"Hosts it reaches",value:e.claims.hosts.length===0?"it claims none":n.jsx("span",{className:"mono",children:e.claims.hosts.join(", ")})}]})})]})]})]}),d.length>0?n.jsxs(ks,{tone:"warning",title:"What it said, and what it does",meta:n.jsx(ge,{tone:"warning",children:"read this first"}),foot:n.jsxs(Q,{children:[n.jsx("span",{className:"plugins-foot-note",children:"Install anyway says you read these."}),n.jsx(en,{}),n.jsx(R,{variant:"ghost",disabled:a,onClick:h,children:"Not this one"}),n.jsx(R,{variant:"danger",disabled:a,onClick:()=>u(!0),children:"Install anyway"})]}),children:[n.jsx("p",{className:"plugins-note",children:"Its prose and its manifest do not agree. Neither is authoritative; the manifest is what actually runs."}),n.jsx("ul",{className:"plugins-drift",children:d.map(p=>n.jsx("li",{children:p},p))}),n.jsx(KE,{unlocks:(r==null?void 0:r.agents)??[]})]}):null]})}function F8({checkout:e,name:t}){const[s,r]=f.useState(!1),[i,a]=f.useState(null),l=t?`${t} is installed.`:"A plugin was installed, disabled or enabled since buddi started, and this buddi has not caught up.";return n.jsxs(J,{gap:"sm",children:[n.jsx(se,{message:i}),n.jsxs(H,{tone:e?"warning":"accent",role:"status",action:e?void 0:n.jsx(R,{size:"sm",variant:"accent",disabled:s,onClick:()=>{r(!0),a(null),T.serviceAction("restart").catch(o=>a(ri(o))).finally(()=>r(!1))},children:"Restart to load it"}),children:[l," ",e?T8:`${t?"Its tools appear":"It takes effect"} once buddi restarts. That closes this dashboard for a few seconds.`]})]})}const Fp=e=>t=>{t.stopPropagation(),e()},z8=e=>e.unlocks.filter(t=>t.drift.state==="not-accepted").length;function U8({plugin:e,listing:t,open:s,canOpen:r,busy:i,onDetails:a,onOpen:l,onSettings:o,onDisable:c,onEnable:u,onRemove:h,onUpdate:d}){const m=e.enabled===!1,p=z8(e);return n.jsx(Tt,{onClick:a,label:`${e.name}: details`,dimmed:m,lead:n.jsx(Ka,{svg:t==null?void 0:t.iconSvg}),title:n.jsxs(n.Fragment,{children:[e.name," ",n.jsx("span",{className:"plugins-ver",children:e.version}),p>0?n.jsxs("span",{className:"plugins-ask",children:[qr(p,"agent","agents")," to accept"]}):null]}),sub:`by ${BE(e)} · from ${P8(e.source)} · ${zE(e.contribution)}`,side:n.jsxs("span",{className:"plugins-side",children:[t!=null&&t.update?n.jsxs(R,{size:"sm",disabled:i,onClick:Fp(()=>d(t.update)),children:["Update to ",t.update]}):null,s,!r&&o?n.jsx(R,{size:"sm",variant:"ghost",onClick:x=>{x.stopPropagation(),o()},children:"Settings"}):null,n.jsx(HE,{plugin:e}),n.jsx(z_,{label:`More for ${e.name}`,items:[{label:"Details",onSelect:a},r?{label:"Open its page",onSelect:l}:null,o?{label:"Its settings",onSelect:o}:null,m?{label:"Enable",hint:"all of it comes back",onSelect:u}:{label:"Disable…",hint:"keeps its data",onSelect:c},"separator",{label:"Remove…",tone:"critical",onSelect:h}]})]})})}const B8={"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 KE({plugin:e,unlocks:t}){return t.length===0?null:n.jsxs(te,{title:"Agents it would unlock",children:[n.jsx("div",{className:"plugins-unlocks",children:n.jsx(At,{children:t.map(s=>n.jsx(W8,{plugin:e,unlock:s},s.id))})}),n.jsxs("p",{className:"plugins-note",children:["Nothing here is created by installing. Accept creates the agent with the tools listed; change or remove it"," ",n.jsx("a",{href:mt,children:"on the Agents page"}),"."]})]})}function W8({plugin:e,unlock:t}){const s=Kx(e,t.id),r=s.created?"up-to-date":t.drift.state,[i,a]=B8[r];return n.jsxs("div",{className:"plugins-unlock",children:[n.jsx(Tt,{title:n.jsxs("span",{className:"plugins-handle",children:["@",t.handle]}),sub:s.created?"Accepted just now. It is on the Agents page.":t.drift.message,side:n.jsxs("span",{className:"plugins-side",children:[n.jsx(ge,{tone:i,children:a}),e&&r==="not-accepted"?n.jsx(R,{size:"sm",variant:"accent",disabled:s.busy,onClick:s.accept,children:"Accept"}):null]})}),n.jsx(se,{message:s.failure}),s.created?n.jsx(eC,{agent:s.created}):null]})}function VE({svg:e,name:t,version:s,by:r,pills:i}){return n.jsxs("span",{className:"plugins-sheet-title",children:[n.jsx(Ka,{svg:e,size:"lg"}),n.jsxs("span",{className:"plugins-sheet-name",children:[n.jsxs("span",{children:[t," ",n.jsx("span",{className:"plugins-ver",children:s})]}),n.jsxs("span",{className:"plugins-sheet-by",children:["by ",r,i]})]})]})}function H8({plugin:e,listing:t,notes:s,canOpen:r,busy:i,onOpen:a,onSettings:l,onClose:o,onDisable:c,onEnable:u,onRemove:h,onUpdate:d}){var g,v;const m=e.enabled===!1,p=e.author!==void 0&&e.source.kind==="directory",x=(t==null?void 0:t.summary)??e.description,j=(e.network??((v=(g=t==null?void 0:t.claims)==null?void 0:g.manifest)==null?void 0:v.network)??[]).map(w=>w.host),b=e.uses??(t==null?void 0:t.usesWords);return n.jsxs(wt,{title:n.jsx(VE,{svg:t==null?void 0:t.iconSvg,name:e.name,version:e.version,by:e.author?n.jsx(mv,{author:e.author}):BE(e),pills:n.jsxs(n.Fragment,{children:[t?n.jsxs(n.Fragment,{children:[" · ",n.jsx(gv,{entry:t})]}):null," · ",n.jsx(HE,{plugin:e})]})}),onClose:o,foot:n.jsxs(Q,{children:[n.jsx(R,{variant:"danger-ghost",onClick:h,children:"Remove…"}),n.jsx(en,{}),l?n.jsx(R,{variant:"ghost",onClick:l,children:"Settings"}):null,r?n.jsx(R,{onClick:a,children:"Open"}):null,m?n.jsx(R,{onClick:u,children:"Enable"}):n.jsx(R,{variant:"ghost",onClick:c,children:"Disable…"}),t!=null&&t.update?n.jsxs(R,{variant:"accent",disabled:i,onClick:()=>d(t.update),children:["Update to ",t.update]}):n.jsx(R,{disabled:i,onClick:()=>d(),children:"Check for an update"})]}),children:[e.error?n.jsx(H,{tone:"critical",children:e.error}):null,s&&s.length>0?n.jsx(H,{role:"status",children:s.join(" ")}):null,m?n.jsx(H,{children:"Disabled: its tools, pages and watchers are off and its missions are paused. Its data is kept."}):null,x?n.jsx("p",{className:"plugins-summary-full",children:x}):null,n.jsx("div",{className:"plugins-facts",children:n.jsx(Vt,{items:[{label:"From",value:Dp(e.source)},...p?[]:[{label:"Published by",value:UE(e.source,e.publisher)}],{label:"Integrity",value:n.jsx(_p,{value:e.integrity})},{label:"Installed",value:Fe(e.installedAt)},{label:"Contributes",value:zE(e.contribution)},...e.network||t?[{label:"Talks to hosts",value:WE(j)}]:[],...b?[{label:"Reaches in buddi",value:pv(b)}]:[]]})}),n.jsx(KE,{plugin:e.name,unlocks:e.unlocks})]})}function K8({kind:e,name:t,canDisable:s,onCancel:r,onDisableInstead:i,onDisable:a,onRemove:l}){const[o,c]=f.useState(!1),[u,h]=f.useState(""),[d,m]=f.useState(!1),[p,x]=f.useState(null),j=g=>{m(!0),x(null),g().catch(v=>x(ri(v))).finally(()=>m(!1))};if(e==="disable")return n.jsxs(Qu,{title:`Disable ${t}?`,onClose:r,foot:n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",disabled:d,onClick:r,children:"Cancel"}),n.jsx(R,{variant:"accent",disabled:d,onClick:()=>j(a),children:"Disable"})]}),children:[n.jsx("p",{className:"plugins-dialog-text",children:"Its tools, pages and watchers stop now and its missions pause. Its data and the agents you accepted from it are kept; enable it to have it all back."}),n.jsx(se,{message:p})]});const b=!o||u.trim()===t;return n.jsxs(Qu,{title:`Remove ${t}?`,onClose:r,foot:n.jsxs(n.Fragment,{children:[s?n.jsx(R,{variant:"ghost",size:"sm",disabled:d,onClick:i,children:"Disable instead"}):null,n.jsx(en,{}),n.jsx(R,{variant:"ghost",disabled:d,onClick:r,children:"Cancel"}),n.jsx(R,{variant:"danger",disabled:d||!b,onClick:()=>j(()=>l(o,u.trim())),children:o?"Remove and drop its data":"Remove"})]}),children:[n.jsxs("p",{className:"plugins-dialog-text",children:["This takes ",t," off this machine and stops its code loading. Its tables and the agents you accepted from it stay."]}),n.jsxs("div",{className:"plugins-purge","data-on":o?"true":void 0,children:[n.jsxs("label",{className:"plugins-check",children:[n.jsx("input",{type:"checkbox",checked:o,onChange:g=>{c(g.target.checked),h("")}}),n.jsxs("span",{children:[n.jsx("span",{className:"plugins-check-title",children:"Also drop its data"}),n.jsx("span",{className:"plugins-check-hint",children:"Its tables are gone for good; there is no undo."})]})]}),o?n.jsx(ee,{label:n.jsxs(n.Fragment,{children:["Type ",n.jsx("span",{className:"mono",children:t})," to confirm"]}),children:n.jsx("input",{autoFocus:!0,value:u,onChange:g=>h(g.target.value)})}):null]}),n.jsx(se,{message:p})]})}function V8({plugins:e,openFor:t}){return n.jsxs($t,{boxed:!0,summary:`Ships with buddi · ${qr(e.length,"plugin","plugins")}`,children:[n.jsx("p",{className:"plugins-note",children:"Compiled into this buddi: nothing to approve, nothing to remove. An agent still reaches one only if its own tools line names it."}),n.jsx("div",{className:"plugins-builtins",children:e.map(s=>{const r=(s.network??[]).map(a=>a.host),i=[s.description,s.author?`By ${s.author.name}.`:null,r.length>0?`Talks to ${r.join(", ")}.`:null].filter(Boolean).join(" ");return n.jsxs("div",{className:"plugins-builtin",title:i||void 0,children:[n.jsx("span",{className:"mono",children:s.name}),n.jsxs("span",{className:"plugins-builtin-n",children:[t(s.name,"ghost"),qr(s.contribution.tools,"tool","tools")]})]},s.name)})})]})}const G8=[{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 Y8(e,t){const s=t.trim().toLowerCase();return s===""?!0:[e.title,e.summary,e.npm].some(r=>r.toLowerCase().includes(s))}function q8({pricing:e}){return e.kind==="free"?n.jsx(n.Fragment,{children:"free"}):n.jsxs(n.Fragment,{children:[e.kind==="paid"?"paid":"a subscription",e.trialDays?` · ${e.trialDays} days to try`:"",e.note?` · ${e.note}`:"",e.vendor?n.jsxs(n.Fragment,{children:[" · ",n.jsx("a",{href:e.vendor,target:"_blank",rel:"noopener noreferrer",children:"its maker's page"})]}):null]})}function Q8({entry:e,busy:t,onOpen:s,onInstall:r,onUpdate:i}){var a;return n.jsxs(ks,{onClick:s,label:`${e.title}: details`,children:[n.jsxs("div",{className:"plugins-card-head",children:[n.jsx(Ka,{svg:e.iconSvg,size:"lg"}),n.jsxs("div",{className:"plugins-card-name",children:[n.jsx("h3",{className:"ui-card-title",children:e.title}),n.jsxs("div",{className:"plugins-card-by",children:["by ",((a=e.author)==null?void 0:a.name)??"someone who gave no name"]})]})]}),n.jsx("p",{className:"plugins-summary",children:e.summary}),n.jsxs("div",{className:"plugins-card-foot",children:[n.jsx(gv,{entry:e}),e.installed?n.jsxs(ge,{children:["installed ",e.installed.version]}):null,n.jsx(en,{}),e.update?n.jsxs(R,{size:"sm",disabled:t,onClick:Fp(()=>i(e.update)),children:["Update to ",e.update]}):e.installed?null:n.jsx(R,{size:"sm",variant:"accent",disabled:t,onClick:Fp(r),children:"Install"})]})]})}function J8(e){var o,c;const t=(o=e.claims)==null?void 0:o.manifest,s=t==null?void 0:t.tools;if(!s)return;const r=s.filter(u=>u.tier==="auto").length,i=s.length-r,a=((c=t==null?void 0:t.sentinels)==null?void 0:c.length)??0,l=[r>0?`${r} run without asking`:null,i>0?`${i} ask${i===1?"s":""} you first`:null,a>0?`${a} on a timer`:null].filter(Boolean);return l.length===0?"none":l.join(", ")}function X8({entry:e,canOpen:t,busy:s,onOpen:r,onClose:i,onInstall:a,onUpdate:l}){var m,p,x,j,b,g,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(y=>y.host),u=J8(e),h=((g=(b=(j=e.claims)==null?void 0:j.manifest)==null?void 0:b.agents)==null?void 0:g.length)??0,d=(w=(v=e.claims)==null?void 0:v.package)==null?void 0:w.dependencies;return n.jsxs(wt,{title:n.jsx(VE,{svg:e.iconSvg,name:e.title,version:e.version,by:e.author?n.jsx(mv,{author:e.author}):"someone who gave no name",pills:n.jsxs(n.Fragment,{children:[" · ",n.jsx(gv,{entry:e}),e.installed?n.jsxs(n.Fragment,{children:[" · ",n.jsxs(ge,{children:["installed ",e.installed.version]})]}):null]})}),onClose:i,foot:n.jsxs(Q,{children:[n.jsx("span",{className:"plugins-foot-note",children:e.installed&&!e.update?"This is the version you have.":"Install reads it first. Nothing of it runs until you say yes."}),n.jsx(en,{}),t?n.jsx(R,{onClick:r,children:"Open"}):null,e.update?n.jsxs(R,{variant:"accent",disabled:s,onClick:()=>l(e.update),children:["Update to ",e.update]}):e.installed?null:n.jsx(R,{variant:"accent",disabled:s,onClick:a,children:"Install"})]}),children:[o?n.jsx("img",{className:"plugins-shot",src:T.marketAssetUrl(o),alt:`${e.title}, as it looks in buddi`}):null,n.jsx("p",{className:"plugins-summary-full",children:e.summary}),n.jsx("div",{className:"plugins-facts",children:n.jsx(Vt,{items:[{label:"Package",value:n.jsx("span",{className:"mono",children:`${e.npm}@${e.version}`})},...u?[{label:"Tools",value:u}]:[],...h>0?[{label:"Proposes",value:`${qr(h,"agent","agents")}, created only if you accept`}]:[],{label:"Talks to hosts",value:WE(c)},{label:"Reaches in buddi",value:pv(e.usesWords??[])},...d?[{label:"Dependencies",value:d.count===0?"none":`${d.count}${d.withScripts.length===0?", none of which run install scripts":`, of which these run install scripts: ${d.withScripts.join(", ")}`}`}]:[],{label:"Licence",value:n.jsxs(n.Fragment,{children:[e.license??"not stated"," · ",n.jsx(q8,{pricing:e.pricing})]})}]})})]})}function Z8({market:e,loading:t,busy:s,onRetry:r,onOpen:i,onInstall:a,onUpdate:l}){const[o,c]=f.useState(""),[u,h]=f.useState("all"),d=(e==null?void 0:e.plugins)??[],m=[{value:"all",label:"All"},{value:"recommended",label:"Recommended"},...G8.filter(j=>d.some(b=>b.category===j.value))],p=d.filter(j=>u==="recommended"&&(j.trust!=="by-buddi"||j.installed)||u!=="all"&&u!=="recommended"&&j.category!==u?!1:Y8(j,o)),x=o.trim();return n.jsxs(J,{gap:"lg",children:[n.jsxs(Q,{children:[n.jsx(w1,{grow:!0,label:"Search plugins",value:o,placeholder:"Search plugins: weather, money, calendar…",onChange:c}),n.jsx(H_,{label:"Show",options:m,value:u,onChange:h})]}),n.jsxs("p",{className:"plugins-quiet",children:[n.jsx(we,{name:"globe",size:14}),"Opening this tab fetched the list from withbuddi.com. Nothing else leaves."," ",n.jsx("button",{type:"button",className:"plugins-link",disabled:t,onClick:r,children:"Refresh"})]}),e===null||t&&e.unavailable?n.jsx(oe,{children:"Asking withbuddi.com…"}):e.unavailable?n.jsx(H,{tone:"warning",action:n.jsx(R,{size:"sm",disabled:t,onClick:r,children:"Try again"}),children:e.unavailable}):n.jsxs(n.Fragment,{children:[e.stale?n.jsxs(H,{tone:"warning",action:n.jsx(R,{size:"sm",disabled:t,onClick:r,children:"Try again"}),children:["withbuddi.com did not answer, so this is the list as it was",e.fetchedAt?` ${Fe(e.fetchedAt)}`:" last time","."]}):null,p.length>0?n.jsx("div",{className:"plugins-grid",children:p.map(j=>n.jsx(Q8,{entry:j,busy:s,onOpen:()=>i(j),onInstall:()=>a(j),onUpdate:b=>l(j,b)},j.npm))}):n.jsx(oe,{warm:!0,title:"Nothing listed matches",children:x!==""?`No plugin on withbuddi.com mentions “${x}”.`:d.length===0?"withbuddi.com lists no plugins yet.":"Nothing on this shelf yet."})]})]})}var qo={},eW=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then},GE={},Qn={};let xv;const tW=[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];Qn.getSymbolSize=function(t){if(!t)throw new Error('"version" cannot be null or undefined');if(t<1||t>40)throw new Error('"version" should be in range from 1 to 40');return t*4+17};Qn.getSymbolTotalCodewords=function(t){return tW[t]};Qn.getBCHDigit=function(e){let t=0;for(;e!==0;)t++,e>>>=1;return t};Qn.setToSJISFunction=function(t){if(typeof t!="function")throw new Error('"toSJISFunc" is not a valid function.');xv=t};Qn.isKanjiModeEnabled=function(){return typeof xv<"u"};Qn.toSJIS=function(t){return xv(t)};var rh={};(function(e){e.L={bit:1},e.M={bit:0},e.Q={bit:3},e.H={bit:2};function t(s){if(typeof s!="string")throw new Error("Param is not a string");switch(s.toLowerCase()){case"l":case"low":return e.L;case"m":case"medium":return e.M;case"q":case"quartile":return e.Q;case"h":case"high":return e.H;default:throw new Error("Unknown EC Level: "+s)}}e.isValid=function(r){return r&&typeof r.bit<"u"&&r.bit>=0&&r.bit<4},e.from=function(r,i){if(e.isValid(r))return r;try{return t(r)}catch{return i}}})(rh);function YE(){this.buffer=[],this.length=0}YE.prototype={get:function(e){const t=Math.floor(e/8);return(this.buffer[t]>>>7-e%8&1)===1},put:function(e,t){for(let s=0;s<t;s++)this.putBit((e>>>t-s-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(e){const t=Math.floor(this.length/8);this.buffer.length<=t&&this.buffer.push(0),e&&(this.buffer[t]|=128>>>this.length%8),this.length++}};var nW=YE;function Qo(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)}Qo.prototype.set=function(e,t,s,r){const i=e*this.size+t;this.data[i]=s,r&&(this.reservedBit[i]=!0)};Qo.prototype.get=function(e,t){return this.data[e*this.size+t]};Qo.prototype.xor=function(e,t,s){this.data[e*this.size+t]^=s};Qo.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]};var sW=Qo,qE={};(function(e){const t=Qn.getSymbolSize;e.getRowColCoords=function(r){if(r===1)return[];const i=Math.floor(r/7)+2,a=t(r),l=a===145?26:Math.ceil((a-13)/(2*i-2))*2,o=[a-7];for(let c=1;c<i-1;c++)o[c]=o[c-1]-l;return o.push(6),o.reverse()},e.getPositions=function(r){const i=[],a=e.getRowColCoords(r),l=a.length;for(let o=0;o<l;o++)for(let c=0;c<l;c++)o===0&&c===0||o===0&&c===l-1||o===l-1&&c===0||i.push([a[o],a[c]]);return i}})(qE);var QE={};const rW=Qn.getSymbolSize,ub=7;QE.getPositions=function(t){const s=rW(t);return[[0,0],[s-ub,0],[0,s-ub]]};var JE={};(function(e){e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const t={N1:3,N2:3,N3:40,N4:10};e.isValid=function(i){return i!=null&&i!==""&&!isNaN(i)&&i>=0&&i<=7},e.from=function(i){return e.isValid(i)?parseInt(i,10):void 0},e.getPenaltyN1=function(i){const a=i.size;let l=0,o=0,c=0,u=null,h=null;for(let d=0;d<a;d++){o=c=0,u=h=null;for(let m=0;m<a;m++){let p=i.get(d,m);p===u?o++:(o>=5&&(l+=t.N1+(o-5)),u=p,o=1),p=i.get(m,d),p===h?c++:(c>=5&&(l+=t.N1+(c-5)),h=p,c=1)}o>=5&&(l+=t.N1+(o-5)),c>=5&&(l+=t.N1+(c-5))}return l},e.getPenaltyN2=function(i){const a=i.size;let l=0;for(let o=0;o<a-1;o++)for(let c=0;c<a-1;c++){const u=i.get(o,c)+i.get(o,c+1)+i.get(o+1,c)+i.get(o+1,c+1);(u===4||u===0)&&l++}return l*t.N2},e.getPenaltyN3=function(i){const a=i.size;let l=0,o=0,c=0;for(let u=0;u<a;u++){o=c=0;for(let h=0;h<a;h++)o=o<<1&2047|i.get(u,h),h>=10&&(o===1488||o===93)&&l++,c=c<<1&2047|i.get(h,u),h>=10&&(c===1488||c===93)&&l++}return l*t.N3},e.getPenaltyN4=function(i){let a=0;const l=i.data.length;for(let c=0;c<l;c++)a+=i.data[c];return Math.abs(Math.ceil(a*100/l/5)-10)*t.N4};function s(r,i,a){switch(r){case e.Patterns.PATTERN000:return(i+a)%2===0;case e.Patterns.PATTERN001:return i%2===0;case e.Patterns.PATTERN010:return a%3===0;case e.Patterns.PATTERN011:return(i+a)%3===0;case e.Patterns.PATTERN100:return(Math.floor(i/2)+Math.floor(a/3))%2===0;case e.Patterns.PATTERN101:return i*a%2+i*a%3===0;case e.Patterns.PATTERN110:return(i*a%2+i*a%3)%2===0;case e.Patterns.PATTERN111:return(i*a%3+(i+a)%2)%2===0;default:throw new Error("bad maskPattern:"+r)}}e.applyMask=function(i,a){const l=a.size;for(let o=0;o<l;o++)for(let c=0;c<l;c++)a.isReserved(c,o)||a.xor(c,o,s(i,c,o))},e.getBestMask=function(i,a){const l=Object.keys(e.Patterns).length;let o=0,c=1/0;for(let u=0;u<l;u++){a(u),e.applyMask(u,i);const h=e.getPenaltyN1(i)+e.getPenaltyN2(i)+e.getPenaltyN3(i)+e.getPenaltyN4(i);e.applyMask(u,i),h<c&&(c=h,o=u)}return o}})(JE);var ih={};const Dr=rh,Kc=[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],Vc=[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];ih.getBlocksCount=function(t,s){switch(s){case Dr.L:return Kc[(t-1)*4+0];case Dr.M:return Kc[(t-1)*4+1];case Dr.Q:return Kc[(t-1)*4+2];case Dr.H:return Kc[(t-1)*4+3];default:return}};ih.getTotalCodewordsCount=function(t,s){switch(s){case Dr.L:return Vc[(t-1)*4+0];case Dr.M:return Vc[(t-1)*4+1];case Dr.Q:return Vc[(t-1)*4+2];case Dr.H:return Vc[(t-1)*4+3];default:return}};var XE={},ah={};const Jl=new Uint8Array(512),ud=new Uint8Array(256);(function(){let t=1;for(let s=0;s<255;s++)Jl[s]=t,ud[t]=s,t<<=1,t&256&&(t^=285);for(let s=255;s<512;s++)Jl[s]=Jl[s-255]})();ah.log=function(t){if(t<1)throw new Error("log("+t+")");return ud[t]};ah.exp=function(t){return Jl[t]};ah.mul=function(t,s){return t===0||s===0?0:Jl[ud[t]+ud[s]]};(function(e){const t=ah;e.mul=function(r,i){const a=new Uint8Array(r.length+i.length-1);for(let l=0;l<r.length;l++)for(let o=0;o<i.length;o++)a[l+o]^=t.mul(r[l],i[o]);return a},e.mod=function(r,i){let a=new Uint8Array(r);for(;a.length-i.length>=0;){const l=a[0];for(let c=0;c<i.length;c++)a[c]^=t.mul(i[c],l);let o=0;for(;o<a.length&&a[o]===0;)o++;a=a.slice(o)}return a},e.generateECPolynomial=function(r){let i=new Uint8Array([1]);for(let a=0;a<r;a++)i=e.mul(i,new Uint8Array([1,t.exp(a)]));return i}})(XE);const ZE=XE;function vv(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}vv.prototype.initialize=function(t){this.degree=t,this.genPoly=ZE.generateECPolynomial(this.degree)};vv.prototype.encode=function(t){if(!this.genPoly)throw new Error("Encoder not initialized");const s=new Uint8Array(t.length+this.degree);s.set(t);const r=ZE.mod(s,this.genPoly),i=this.degree-r.length;if(i>0){const a=new Uint8Array(this.degree);return a.set(r,i),a}return r};var iW=vv,eA={},di={},jv={};jv.isValid=function(t){return!isNaN(t)&&t>=1&&t<=40};var Ys={};const tA="[0-9]+",aW="[A-Z $%*+\\-./:]+";let $o="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";$o=$o.replace(/u/g,"\\u");const lW="(?:(?![A-Z0-9 $%*+\\-./:]|"+$o+`)(?:.|[\r
122
- ]))+`;Ys.KANJI=new RegExp($o,"g");Ys.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");Ys.BYTE=new RegExp(lW,"g");Ys.NUMERIC=new RegExp(tA,"g");Ys.ALPHANUMERIC=new RegExp(aW,"g");const oW=new RegExp("^"+$o+"$"),cW=new RegExp("^"+tA+"$"),uW=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");Ys.testKanji=function(t){return oW.test(t)};Ys.testNumeric=function(t){return cW.test(t)};Ys.testAlphanumeric=function(t){return uW.test(t)};(function(e){const t=jv,s=Ys;e.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},e.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},e.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},e.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},e.MIXED={bit:-1},e.getCharCountIndicator=function(a,l){if(!a.ccBits)throw new Error("Invalid mode: "+a);if(!t.isValid(l))throw new Error("Invalid version: "+l);return l>=1&&l<10?a.ccBits[0]:l<27?a.ccBits[1]:a.ccBits[2]},e.getBestModeForData=function(a){return s.testNumeric(a)?e.NUMERIC:s.testAlphanumeric(a)?e.ALPHANUMERIC:s.testKanji(a)?e.KANJI:e.BYTE},e.toString=function(a){if(a&&a.id)return a.id;throw new Error("Invalid mode")},e.isValid=function(a){return a&&a.bit&&a.ccBits};function r(i){if(typeof i!="string")throw new Error("Param is not a string");switch(i.toLowerCase()){case"numeric":return e.NUMERIC;case"alphanumeric":return e.ALPHANUMERIC;case"kanji":return e.KANJI;case"byte":return e.BYTE;default:throw new Error("Unknown mode: "+i)}}e.from=function(a,l){if(e.isValid(a))return a;try{return r(a)}catch{return l}}})(di);(function(e){const t=Qn,s=ih,r=rh,i=di,a=jv,l=7973,o=t.getBCHDigit(l);function c(m,p,x){for(let j=1;j<=40;j++)if(p<=e.getCapacity(j,x,m))return j}function u(m,p){return i.getCharCountIndicator(m,p)+4}function h(m,p){let x=0;return m.forEach(function(j){const b=u(j.mode,p);x+=b+j.getBitsLength()}),x}function d(m,p){for(let x=1;x<=40;x++)if(h(m,x)<=e.getCapacity(x,p,i.MIXED))return x}e.from=function(p,x){return a.isValid(p)?parseInt(p,10):x},e.getCapacity=function(p,x,j){if(!a.isValid(p))throw new Error("Invalid QR Code version");typeof j>"u"&&(j=i.BYTE);const b=t.getSymbolTotalCodewords(p),g=s.getTotalCodewordsCount(p,x),v=(b-g)*8;if(j===i.MIXED)return v;const w=v-u(j,p);switch(j){case i.NUMERIC:return Math.floor(w/10*3);case i.ALPHANUMERIC:return Math.floor(w/11*2);case i.KANJI:return Math.floor(w/13);case i.BYTE:default:return Math.floor(w/8)}},e.getBestVersionForData=function(p,x){let j;const b=r.from(x,r.M);if(Array.isArray(p)){if(p.length>1)return d(p,b);if(p.length===0)return 1;j=p[0]}else j=p;return c(j.mode,j.getLength(),b)},e.getEncodedBits=function(p){if(!a.isValid(p)||p<7)throw new Error("Invalid QR Code version");let x=p<<12;for(;t.getBCHDigit(x)-o>=0;)x^=l<<t.getBCHDigit(x)-o;return p<<12|x}})(eA);var nA={};const zp=Qn,sA=1335,dW=21522,db=zp.getBCHDigit(sA);nA.getEncodedBits=function(t,s){const r=t.bit<<3|s;let i=r<<10;for(;zp.getBCHDigit(i)-db>=0;)i^=sA<<zp.getBCHDigit(i)-db;return(r<<10|i)^dW};var rA={};const hW=di;function Ga(e){this.mode=hW.NUMERIC,this.data=e.toString()}Ga.getBitsLength=function(t){return 10*Math.floor(t/3)+(t%3?t%3*3+1:0)};Ga.prototype.getLength=function(){return this.data.length};Ga.prototype.getBitsLength=function(){return Ga.getBitsLength(this.data.length)};Ga.prototype.write=function(t){let s,r,i;for(s=0;s+3<=this.data.length;s+=3)r=this.data.substr(s,3),i=parseInt(r,10),t.put(i,10);const a=this.data.length-s;a>0&&(r=this.data.substr(s),i=parseInt(r,10),t.put(i,a*3+1))};var fW=Ga;const mW=di,Ef=["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 Ya(e){this.mode=mW.ALPHANUMERIC,this.data=e}Ya.getBitsLength=function(t){return 11*Math.floor(t/2)+6*(t%2)};Ya.prototype.getLength=function(){return this.data.length};Ya.prototype.getBitsLength=function(){return Ya.getBitsLength(this.data.length)};Ya.prototype.write=function(t){let s;for(s=0;s+2<=this.data.length;s+=2){let r=Ef.indexOf(this.data[s])*45;r+=Ef.indexOf(this.data[s+1]),t.put(r,11)}this.data.length%2&&t.put(Ef.indexOf(this.data[s]),6)};var pW=Ya;const gW=di;function qa(e){this.mode=gW.BYTE,typeof e=="string"?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}qa.getBitsLength=function(t){return t*8};qa.prototype.getLength=function(){return this.data.length};qa.prototype.getBitsLength=function(){return qa.getBitsLength(this.data.length)};qa.prototype.write=function(e){for(let t=0,s=this.data.length;t<s;t++)e.put(this.data[t],8)};var xW=qa;const vW=di,jW=Qn;function Qa(e){this.mode=vW.KANJI,this.data=e}Qa.getBitsLength=function(t){return t*13};Qa.prototype.getLength=function(){return this.data.length};Qa.prototype.getBitsLength=function(){return Qa.getBitsLength(this.data.length)};Qa.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let s=jW.toSJIS(this.data[t]);if(s>=33088&&s<=40956)s-=33088;else if(s>=57408&&s<=60351)s-=49472;else throw new Error("Invalid SJIS character: "+this.data[t]+`
123
- Make sure your charset is UTF-8`);s=(s>>>8&255)*192+(s&255),e.put(s,13)}};var wW=Qa,iA={exports:{}};(function(e){var t={single_source_shortest_paths:function(s,r,i){var a={},l={};l[r]=0;var o=t.PriorityQueue.make();o.push(r,0);for(var c,u,h,d,m,p,x,j,b;!o.empty();){c=o.pop(),u=c.value,d=c.cost,m=s[u]||{};for(h in m)m.hasOwnProperty(h)&&(p=m[h],x=d+p,j=l[h],b=typeof l[h]>"u",(b||j>x)&&(l[h]=x,o.push(h,x),a[h]=u))}if(typeof i<"u"&&typeof l[i]>"u"){var g=["Could not find a path from ",r," to ",i,"."].join("");throw new Error(g)}return a},extract_shortest_path_from_predecessor_list:function(s,r){for(var i=[],a=r;a;)i.push(a),s[a],a=s[a];return i.reverse(),i},find_path:function(s,r,i){var a=t.single_source_shortest_paths(s,r,i);return t.extract_shortest_path_from_predecessor_list(a,i)},PriorityQueue:{make:function(s){var r=t.PriorityQueue,i={},a;s=s||{};for(a in r)r.hasOwnProperty(a)&&(i[a]=r[a]);return i.queue=[],i.sorter=s.sorter||r.default_sorter,i},default_sorter:function(s,r){return s.cost-r.cost},push:function(s,r){var i={value:s,cost:r};this.queue.push(i),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};e.exports=t})(iA);var yW=iA.exports;(function(e){const t=di,s=fW,r=pW,i=xW,a=wW,l=Ys,o=Qn,c=yW;function u(g){return unescape(encodeURIComponent(g)).length}function h(g,v,w){const y=[];let N;for(;(N=g.exec(w))!==null;)y.push({data:N[0],index:N.index,mode:v,length:N[0].length});return y}function d(g){const v=h(l.NUMERIC,t.NUMERIC,g),w=h(l.ALPHANUMERIC,t.ALPHANUMERIC,g);let y,N;return o.isKanjiModeEnabled()?(y=h(l.BYTE,t.BYTE,g),N=h(l.KANJI,t.KANJI,g)):(y=h(l.BYTE_KANJI,t.BYTE,g),N=[]),v.concat(w,y,N).sort(function(S,C){return S.index-C.index}).map(function(S){return{data:S.data,mode:S.mode,length:S.length}})}function m(g,v){switch(v){case t.NUMERIC:return s.getBitsLength(g);case t.ALPHANUMERIC:return r.getBitsLength(g);case t.KANJI:return a.getBitsLength(g);case t.BYTE:return i.getBitsLength(g)}}function p(g){return g.reduce(function(v,w){const y=v.length-1>=0?v[v.length-1]:null;return y&&y.mode===w.mode?(v[v.length-1].data+=w.data,v):(v.push(w),v)},[])}function x(g){const v=[];for(let w=0;w<g.length;w++){const y=g[w];switch(y.mode){case t.NUMERIC:v.push([y,{data:y.data,mode:t.ALPHANUMERIC,length:y.length},{data:y.data,mode:t.BYTE,length:y.length}]);break;case t.ALPHANUMERIC:v.push([y,{data:y.data,mode:t.BYTE,length:y.length}]);break;case t.KANJI:v.push([y,{data:y.data,mode:t.BYTE,length:u(y.data)}]);break;case t.BYTE:v.push([{data:y.data,mode:t.BYTE,length:u(y.data)}])}}return v}function j(g,v){const w={},y={start:{}};let N=["start"];for(let k=0;k<g.length;k++){const S=g[k],C=[];for(let I=0;I<S.length;I++){const A=S[I],O=""+k+I;C.push(O),w[O]={node:A,lastCount:0},y[O]={};for(let z=0;z<N.length;z++){const L=N[z];w[L]&&w[L].node.mode===A.mode?(y[L][O]=m(w[L].lastCount+A.length,A.mode)-m(w[L].lastCount,A.mode),w[L].lastCount+=A.length):(w[L]&&(w[L].lastCount=A.length),y[L][O]=m(A.length,A.mode)+4+t.getCharCountIndicator(A.mode,v))}}N=C}for(let k=0;k<N.length;k++)y[N[k]].end=0;return{map:y,table:w}}function b(g,v){let w;const y=t.getBestModeForData(g);if(w=t.from(v,y),w!==t.BYTE&&w.bit<y.bit)throw new Error('"'+g+'" cannot be encoded with mode '+t.toString(w)+`.
124
- Suggested mode is: `+t.toString(y));switch(w===t.KANJI&&!o.isKanjiModeEnabled()&&(w=t.BYTE),w){case t.NUMERIC:return new s(g);case t.ALPHANUMERIC:return new r(g);case t.KANJI:return new a(g);case t.BYTE:return new i(g)}}e.fromArray=function(v){return v.reduce(function(w,y){return typeof y=="string"?w.push(b(y,null)):y.data&&w.push(b(y.data,y.mode)),w},[])},e.fromString=function(v,w){const y=d(v,o.isKanjiModeEnabled()),N=x(y),k=j(N,w),S=c.find_path(k.map,"start","end"),C=[];for(let I=1;I<S.length-1;I++)C.push(k.table[S[I]].node);return e.fromArray(p(C))},e.rawSplit=function(v){return e.fromArray(d(v,o.isKanjiModeEnabled()))}})(rA);const lh=Qn,Af=rh,bW=nW,kW=sW,SW=qE,NW=QE,Up=JE,Bp=ih,CW=iW,dd=eA,EW=nA,AW=di,Tf=rA;function TW(e,t){const s=e.size,r=NW.getPositions(t);for(let i=0;i<r.length;i++){const a=r[i][0],l=r[i][1];for(let o=-1;o<=7;o++)if(!(a+o<=-1||s<=a+o))for(let c=-1;c<=7;c++)l+c<=-1||s<=l+c||(o>=0&&o<=6&&(c===0||c===6)||c>=0&&c<=6&&(o===0||o===6)||o>=2&&o<=4&&c>=2&&c<=4?e.set(a+o,l+c,!0,!0):e.set(a+o,l+c,!1,!0))}}function RW(e){const t=e.size;for(let s=8;s<t-8;s++){const r=s%2===0;e.set(s,6,r,!0),e.set(6,s,r,!0)}}function IW(e,t){const s=SW.getPositions(t);for(let r=0;r<s.length;r++){const i=s[r][0],a=s[r][1];for(let l=-2;l<=2;l++)for(let o=-2;o<=2;o++)l===-2||l===2||o===-2||o===2||l===0&&o===0?e.set(i+l,a+o,!0,!0):e.set(i+l,a+o,!1,!0)}}function PW(e,t){const s=e.size,r=dd.getEncodedBits(t);let i,a,l;for(let o=0;o<18;o++)i=Math.floor(o/3),a=o%3+s-8-3,l=(r>>o&1)===1,e.set(i,a,l,!0),e.set(a,i,l,!0)}function Rf(e,t,s){const r=e.size,i=EW.getEncodedBits(t,s);let a,l;for(a=0;a<15;a++)l=(i>>a&1)===1,a<6?e.set(a,8,l,!0):a<8?e.set(a+1,8,l,!0):e.set(r-15+a,8,l,!0),a<8?e.set(8,r-a-1,l,!0):a<9?e.set(8,15-a-1+1,l,!0):e.set(8,15-a-1,l,!0);e.set(r-8,8,1,!0)}function $W(e,t){const s=e.size;let r=-1,i=s-1,a=7,l=0;for(let o=s-1;o>0;o-=2)for(o===6&&o--;;){for(let c=0;c<2;c++)if(!e.isReserved(i,o-c)){let u=!1;l<t.length&&(u=(t[l]>>>a&1)===1),e.set(i,o-c,u),a--,a===-1&&(l++,a=7)}if(i+=r,i<0||s<=i){i-=r,r=-r;break}}}function MW(e,t,s){const r=new bW;s.forEach(function(c){r.put(c.mode.bit,4),r.put(c.getLength(),AW.getCharCountIndicator(c.mode,e)),c.write(r)});const i=lh.getSymbolTotalCodewords(e),a=Bp.getTotalCodewordsCount(e,t),l=(i-a)*8;for(r.getLengthInBits()+4<=l&&r.put(0,4);r.getLengthInBits()%8!==0;)r.putBit(0);const o=(l-r.getLengthInBits())/8;for(let c=0;c<o;c++)r.put(c%2?17:236,8);return OW(r,e,t)}function OW(e,t,s){const r=lh.getSymbolTotalCodewords(t),i=Bp.getTotalCodewordsCount(t,s),a=r-i,l=Bp.getBlocksCount(t,s),o=r%l,c=l-o,u=Math.floor(r/l),h=Math.floor(a/l),d=h+1,m=u-h,p=new CW(m);let x=0;const j=new Array(l),b=new Array(l);let g=0;const v=new Uint8Array(e.buffer);for(let S=0;S<l;S++){const C=S<c?h:d;j[S]=v.slice(x,x+C),b[S]=p.encode(j[S]),x+=C,g=Math.max(g,C)}const w=new Uint8Array(r);let y=0,N,k;for(N=0;N<g;N++)for(k=0;k<l;k++)N<j[k].length&&(w[y++]=j[k][N]);for(N=0;N<m;N++)for(k=0;k<l;k++)w[y++]=b[k][N];return w}function DW(e,t,s,r){let i;if(Array.isArray(e))i=Tf.fromArray(e);else if(typeof e=="string"){let u=t;if(!u){const h=Tf.rawSplit(e);u=dd.getBestVersionForData(h,s)}i=Tf.fromString(e,u||40)}else throw new Error("Invalid data");const a=dd.getBestVersionForData(i,s);if(!a)throw new Error("The amount of data is too big to be stored in a QR Code");if(!t)t=a;else if(t<a)throw new Error(`
125
- The chosen QR Code version cannot contain this amount of data.
126
- Minimum version required to store current data is: `+a+`.
127
- `);const l=MW(t,s,i),o=lh.getSymbolSize(t),c=new kW(o);return TW(c,t),RW(c),IW(c,t),Rf(c,s,0),t>=7&&PW(c,t),$W(c,l),isNaN(r)&&(r=Up.getBestMask(c,Rf.bind(null,c,s))),Up.applyMask(r,c),Rf(c,s,r),{modules:c,version:t,errorCorrectionLevel:s,maskPattern:r,segments:i}}GE.create=function(t,s){if(typeof t>"u"||t==="")throw new Error("No input text");let r=Af.M,i,a;return typeof s<"u"&&(r=Af.from(s.errorCorrectionLevel,Af.M),i=dd.from(s.version),a=Up.from(s.maskPattern),s.toSJISFunc&&lh.setToSJISFunction(s.toSJISFunc)),DW(t,i,r,a)};var aA={},wv={};(function(e){function t(s){if(typeof s=="number"&&(s=s.toString()),typeof s!="string")throw new Error("Color should be defined as hex string");let r=s.slice().replace("#","").split("");if(r.length<3||r.length===5||r.length>8)throw new Error("Invalid hex color: "+s);(r.length===3||r.length===4)&&(r=Array.prototype.concat.apply([],r.map(function(a){return[a,a]}))),r.length===6&&r.push("F","F");const i=parseInt(r.join(""),16);return{r:i>>24&255,g:i>>16&255,b:i>>8&255,a:i&255,hex:"#"+r.slice(0,6).join("")}}e.getOptions=function(r){r||(r={}),r.color||(r.color={});const i=typeof r.margin>"u"||r.margin===null||r.margin<0?4:r.margin,a=r.width&&r.width>=21?r.width:void 0,l=r.scale||4;return{width:a,scale:a?4:l,margin:i,color:{dark:t(r.color.dark||"#000000ff"),light:t(r.color.light||"#ffffffff")},type:r.type,rendererOpts:r.rendererOpts||{}}},e.getScale=function(r,i){return i.width&&i.width>=r+i.margin*2?i.width/(r+i.margin*2):i.scale},e.getImageWidth=function(r,i){const a=e.getScale(r,i);return Math.floor((r+i.margin*2)*a)},e.qrToImageData=function(r,i,a){const l=i.modules.size,o=i.modules.data,c=e.getScale(l,a),u=Math.floor((l+a.margin*2)*c),h=a.margin*c,d=[a.color.light,a.color.dark];for(let m=0;m<u;m++)for(let p=0;p<u;p++){let x=(m*u+p)*4,j=a.color.light;if(m>=h&&p>=h&&m<u-h&&p<u-h){const b=Math.floor((m-h)/c),g=Math.floor((p-h)/c);j=d[o[b*l+g]?1:0]}r[x++]=j.r,r[x++]=j.g,r[x++]=j.b,r[x]=j.a}}})(wv);(function(e){const t=wv;function s(i,a,l){i.clearRect(0,0,a.width,a.height),a.style||(a.style={}),a.height=l,a.width=l,a.style.height=l+"px",a.style.width=l+"px"}function r(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}e.render=function(a,l,o){let c=o,u=l;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),l||(u=r()),c=t.getOptions(c);const h=t.getImageWidth(a.modules.size,c),d=u.getContext("2d"),m=d.createImageData(h,h);return t.qrToImageData(m.data,a,c),s(d,u,h),d.putImageData(m,0,0),u},e.renderToDataURL=function(a,l,o){let c=o;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),c||(c={});const u=e.render(a,l,c),h=c.type||"image/png",d=c.rendererOpts||{};return u.toDataURL(h,d.quality)}})(aA);var lA={};const _W=wv;function hb(e,t){const s=e.a/255,r=t+'="'+e.hex+'"';return s<1?r+" "+t+'-opacity="'+s.toFixed(2).slice(1)+'"':r}function If(e,t,s){let r=e+t;return typeof s<"u"&&(r+=" "+s),r}function LW(e,t,s){let r="",i=0,a=!1,l=0;for(let o=0;o<e.length;o++){const c=Math.floor(o%t),u=Math.floor(o/t);!c&&!a&&(a=!0),e[o]?(l++,o>0&&c>0&&e[o-1]||(r+=a?If("M",c+s,.5+u+s):If("m",i,0),i=0,a=!1),c+1<t&&e[o+1]||(r+=If("h",l),l=0)):i++}return r}lA.render=function(t,s,r){const i=_W.getOptions(s),a=t.modules.size,l=t.modules.data,o=a+i.margin*2,c=i.color.light.a?"<path "+hb(i.color.light,"fill")+' d="M0 0h'+o+"v"+o+'H0z"/>':"",u="<path "+hb(i.color.dark,"stroke")+' d="'+LW(l,a,i.margin)+'"/>',h='viewBox="0 0 '+o+" "+o+'"',m='<svg xmlns="http://www.w3.org/2000/svg" '+(i.width?'width="'+i.width+'" height="'+i.width+'" ':"")+h+' shape-rendering="crispEdges">'+c+u+`</svg>
128
- `;return typeof r=="function"&&r(null,m),m};const FW=eW,Wp=GE,oA=aA,zW=lA;function yv(e,t,s,r,i){const a=[].slice.call(arguments,1),l=a.length,o=typeof a[l-1]=="function";if(!o&&!FW())throw new Error("Callback required as last argument");if(o){if(l<2)throw new Error("Too few arguments provided");l===2?(i=s,s=t,t=r=void 0):l===3&&(t.getContext&&typeof i>"u"?(i=r,r=void 0):(i=r,r=s,s=t,t=void 0))}else{if(l<1)throw new Error("Too few arguments provided");return l===1?(s=t,t=r=void 0):l===2&&!t.getContext&&(r=s,s=t,t=void 0),new Promise(function(c,u){try{const h=Wp.create(s,r);c(e(h,t,r))}catch(h){u(h)}})}try{const c=Wp.create(s,r);i(null,e(c,t,r))}catch(c){i(c)}}qo.create=Wp.create;qo.toCanvas=yv.bind(null,oA.render);qo.toDataURL=yv.bind(null,oA.renderToDataURL);qo.toString=yv.bind(null,function(e,t,s){return zW.render(e,s)});async function UW(e){const t=await qo.toString(e,{type:"svg",margin:1,errorCorrectionLevel:"M"});return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(t)}`}const fb=10*6e4,BW=2e3;function bv(e,t){const[s,r]=f.useState(null),[i,a]=f.useState(null),[l,o]=f.useState(!1),[c,u]=f.useState(!1),h=f.useRef(e);h.current=e;const d=f.useRef(t);d.current=t;const m=f.useCallback(async()=>{const p=await T.telegramPairing();r(p),u(!1),o(!1),a(await UW(p.link).catch(()=>""))},[]);return f.useEffect(()=>{if(!s||l||c)return;let p=!1;const x=Math.min(Date.parse(s.expiresAt)||Date.now()+fb,Date.now()+fb),j=window.setInterval(()=>{if(Date.now()>=x){u(!0);return}h.current().then(b=>{var g;p||!b||(o(!0),(g=d.current)==null||g.call(d))}).catch(()=>{})},BW);return()=>{p=!0,window.clearInterval(j)}},[s,l,c]),{offer:s,square:i,paired:l,stale:c,ask:m}}function kv({offer:e,square:t,children:s}){return n.jsxs("div",{className:"meet-pair",children:[t?n.jsx("img",{className:"meet-qr",src:t,alt:e.link}):null,n.jsx("a",{className:"meet-link",href:e.link,target:"_blank",rel:"noreferrer",children:e.link}),s]})}const cA=new Set(["approval","question"]),Gc={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."}};function WW({timezone:e}){var j,b;const t=le(()=>T.notificationSettings(),[]),s=le(()=>T.notifications(20),[],3e4),[r,i]=f.useState(null),[a,l]=f.useState(!1),[o,c]=f.useState(!1),[u,h]=f.useState(null),d=((j=t.data)==null?void 0:j.channels)??[],m=r??((b=t.data)==null?void 0:b.settings),p=g=>{m&&(c(!1),i({...m,...g}))},x=()=>{m&&(l(!0),c(!1),h(null),T.saveNotificationSettings(m).then(()=>{c(!0),i(null),t.reload()}).catch(g=>h(g instanceof pe?g.message:String(g))).finally(()=>l(!1)))};return n.jsxs(J,{gap:"lg",children:[n.jsx(KW,{timezone:e,onChange:t.reload}),n.jsx(te,{title:"Notifications",aside:"What buddi tells you when you are not looking at this page.",panel:!0,foot:n.jsx(R,{variant:"accent",disabled:a||!m,onClick:x,children:"Save"}),children:n.jsxs(J,{divided:!0,children:[n.jsx(se,{message:t.error??u}),n.jsx(te,{title:"Where buddi reaches you",children:m?d.length===0?n.jsx("p",{className:"ui-card-meta",children:"No channel yet, so everything waits for you here. Pair Telegram and buddi can reach you on your phone."}):n.jsx(J,{gap:"sm",children:d.map(g=>{var v;return n.jsx(YW,{channel:g,checked:(m.defaultChannel??((v=d[0])==null?void 0:v.kind))===g.kind,onPick:()=>p({defaultChannel:g.kind})},g.kind)})}):n.jsx(oe,{children:"Loading…"})}),n.jsx(te,{title:"By kind",children:m?n.jsxs(J,{gap:"sm",children:[Y2.map(g=>n.jsxs("div",{className:"pref-row nt-kind",children:[n.jsxs("div",{className:"pref-text",children:[n.jsx("span",{className:"pref-label",children:Gc[g].label}),n.jsx("span",{className:"ui-field-hint",children:Gc[g].hint})]}),n.jsxs("select",{"aria-label":Gc[g].label,value:qW(m,g,d),onChange:v=>{const w={...m.perKind};v.target.value==="default"?delete w[g]:w[g]=v.target.value,p({perKind:w})},children:[n.jsx("option",{value:"default",children:"Default"}),d.map(v=>n.jsx("option",{value:v.kind,children:v.label},v.kind)),cA.has(g)?null:n.jsx("option",{value:"off",children:"Off"})]})]},g)),n.jsx("p",{className:"ui-field-hint",children:"Off keeps it in the list below and never sends it."})]}):null}),n.jsx(te,{title:"Focus schedules",children:m?n.jsxs(J,{gap:"sm",children:[n.jsx(XW,{schedules:m.schedules,onChange:g=>p({schedules:g})}),n.jsxs("p",{className:"ui-field-hint",children:["Do not disturb holds everything but approvals and questions; Urgent only also lets watchers and failures through. What waited comes in one message when the focus ends. Switch a focus by hand from your initial at the foot of the rail, or /focus on Telegram. Times are on your clock (",e,")."]}),n.jsx("div",{className:"nt-times",children:n.jsx(ee,{label:"End of the day",children:n.jsx("input",{type:"time",value:m.endOfDay,onChange:g=>p({endOfDay:g.target.value})})})}),n.jsx("p",{className:"ui-field-hint",children:"At the end of the day, what could wait goes out as one message."})]}):null}),o?n.jsx(H,{tone:"good",role:"status",children:"Saved."}):null]})}),n.jsx(HW,{}),n.jsxs(te,{title:"The last twenty",panel:!0,flush:!0,children:[n.jsx(se,{message:s.error}),s.data?s.data.notifications.length===0?n.jsx(oe,{children:"Nothing yet. What buddi tells you will be listed here."}):n.jsx(At,{children:s.data.notifications.map(g=>n.jsx(Tt,{title:g.title,sub:`${Be(g.createdAt,e)} · ${Gc[g.kind].label.toLowerCase()} · ${QW(g,d)}`,side:n.jsx(JW,{row:g})},g.id))}):n.jsx(oe,{children:"Loading…"})]})]})}function HW(){var u;const e=le(()=>T.tipsSettings(),[]),[t,s]=f.useState(!1),[r,i]=f.useState(null),[a,l]=f.useState(null),o=a??((u=e.data)==null?void 0:u.enabled)??!0,c=h=>{s(!0),i(null),l(h),T.saveTipsSettings(h).then(d=>l(d.enabled)).catch(d=>{l(!h),i(d instanceof pe?d.message:String(d))}).finally(()=>s(!1))};return n.jsx(te,{title:"Tips",panel:!0,children:n.jsxs(J,{gap:"sm",children:[n.jsx(se,{message:e.error??r}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:o,disabled:t||!e.data,onChange:h=>c(h.target.checked)}),n.jsx("span",{children:"Tips on Home"})]}),n.jsx("p",{className:"ui-field-hint",children:"When something in buddi has gone unused, Home may say so in one sentence, at most once a day."})]})})}function KW({timezone:e,onChange:t}){var C,I;const s=le(()=>T.telegramBot(),[]),r=le(()=>T.telegramDevices(),[]),[i,a]=f.useState(!1),[l,o]=f.useState(""),[c,u]=f.useState(!1),[h,d]=f.useState(null),[m,p]=f.useState(null),x=f.useRef(new Set),j=bv(()=>T.telegramDevices().then(A=>A.devices.some(O=>!x.current.has(O.id))),()=>{r.reload(),t()}),b=((C=s.data)==null?void 0:C.configured)??!1,g=!b||i,v=()=>{var O;if(l.trim()===""||c)return;u(!0),d(null);const A=i&&(((O=s.data)==null?void 0:O.running)??!1);T.saveTelegramToken(l.trim()).then(z=>{o(""),a(!1),d(z.restartNeeded?{ok:!1,text:z.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(),t()}).catch(z=>d({ok:!1,text:z instanceof pe?z.message:String(z)})).finally(()=>u(!1))},w=()=>{var A;p(null),x.current=new Set((((A=r.data)==null?void 0:A.devices)??[]).map(O=>O.id)),j.ask().catch(O=>p(O instanceof pe?O.message:String(O)))},{offer:y,square:N,paired:k,stale:S}=j;return n.jsx(te,{title:"Telegram",aside:"Talk to buddi from your phone.",panel:!0,children:n.jsxs(J,{divided:!0,children:[n.jsx(te,{title:"The bot",foot:g?n.jsxs(n.Fragment,{children:[i?n.jsx(R,{variant:"ghost",onClick:()=>{a(!1),o("")},children:"Cancel"}):null,n.jsx(R,{variant:"accent",disabled:c||l.trim()==="",onClick:v,children:"Save token"})]}):void 0,children:n.jsxs(J,{gap:"sm",children:[n.jsx(se,{message:s.error}),!s.data&&!s.error?n.jsx(oe,{children:"Loading…"}):b&&!i?n.jsxs("div",{className:"nt-channel",children:[n.jsx("span",{className:"pref-label",children:(I=s.data)!=null&&I.username?`Bot: @${s.data.username}`:"A bot token is saved."}),n.jsx(R,{variant:"ghost",size:"sm",onClick:()=>{a(!0),d(null)},children:"Replace token"})]}):null,g?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"ui-card-meta",children:"Ask @BotFather for a bot and paste its token here."}),n.jsx(ee,{label:"Bot token",grow:!0,children:n.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?n.jsx(H,{tone:h.ok?"good":"warning",role:"status",children:h.text}):null]})}),n.jsxs(te,{title:"Your devices",children:[n.jsx(se,{message:r.error}),r.data?r.data.devices.length===0?n.jsx("p",{className:"ui-card-meta",children:"No phone is paired yet."}):n.jsx(At,{children:r.data.devices.map(A=>n.jsx(Tt,{title:A.name??`Telegram user ${A.userId}`,sub:`Paired ${Be(A.pairedAt,e)} · ${A.lastSeenAt?`last spoke ${Fe(A.lastSeenAt)}`:"has not spoken yet"}`,side:n.jsx(VW,{id:A.id,onGone:()=>{r.reload(),t()}})},A.id))}):r.error?null:n.jsx(oe,{children:"Loading…"})]}),n.jsx(te,{title:"Pair a device",foot:b&&(!y||k)?n.jsx(R,{variant:y?void 0:"accent",onClick:w,children:"Pair a phone"}):b&&S?n.jsx(R,{variant:"accent",onClick:w,children:"New code"}):void 0,children:n.jsxs(J,{gap:"sm",children:[n.jsx(se,{message:m}),b?k?n.jsx(H,{tone:"good",role:"status",children:"Paired."}):y&&S?n.jsx("p",{className:"ui-card-meta",children:"That code has run out."}):y?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"ui-card-meta",children:"Open this on your phone, then send /start to the bot."}),n.jsx(kv,{offer:y,square:N,children:n.jsx(GW,{text:y.link})}),n.jsxs("p",{className:"ui-field-hint",children:["The code works until ",Be(y.expiresAt,e),"."]})]}):n.jsx("p",{className:"ui-card-meta",children:"Pair another phone, or the first one if you skipped it."}):n.jsx("p",{className:"ui-card-meta",children:"Save a bot token first."})]})})]})})}function VW({id:e,onGone:t}){const[s,r]=f.useState(!1),[i,a]=f.useState(!1),[l,o]=f.useState(null);if(!s)return n.jsx(R,{size:"sm",onClick:()=>r(!0),children:"Unpair"});const c=()=>{a(!0),o(null),T.unpairTelegramDevice(e).then(t).catch(u=>o(u instanceof pe?u.message:String(u))).finally(()=>a(!1))};return n.jsxs("span",{className:"nt-channel",children:[n.jsx("span",{className:"ui-field-hint",role:l?"alert":void 0,children:l??"It will no longer reach your agents."}),n.jsx(R,{size:"sm",variant:"ghost",disabled:i,onClick:()=>r(!1),children:"Keep"}),n.jsx(R,{size:"sm",variant:"danger",disabled:i,onClick:c,children:"Unpair"})]})}function GW({text:e}){const[t,s]=f.useState(null),r=()=>{var i;if(!((i=navigator.clipboard)!=null&&i.writeText)){s("Select the link to copy it.");return}navigator.clipboard.writeText(e).then(()=>s("Copied."),()=>s("Select the link to copy it."))};return n.jsxs("span",{className:"nt-channel",children:[n.jsx(R,{size:"sm",onClick:r,children:"Copy"}),t?n.jsx("span",{className:"ui-field-hint",role:"status",children:t}):null]})}function YW({channel:e,checked:t,onPick:s}){const[r,i]=f.useState(!1),[a,l]=f.useState(null),o=()=>{i(!0),l(null),T.testChannel(e.kind).then(()=>l({ok:!0,text:"Sent. Check that it arrived."})).catch(c=>l({ok:!1,text:c instanceof pe?c.message:String(c)})).finally(()=>i(!1))};return n.jsxs("div",{className:"nt-channel",children:[n.jsxs("label",{children:[n.jsx("input",{type:"radio",name:"nt-default-channel",checked:t,onChange:s}),n.jsxs("span",{className:"nt-channel-text",children:[n.jsxs("span",{className:"pref-label",children:[e.label,e.where?`, ${e.where}`:""]}),n.jsxs("span",{className:"ui-field-hint",children:["The title and a few lines of each message go to ",e.label,"."]}),a?n.jsx("span",{className:"nt-channel-sent","data-tone":a.ok?void 0:"critical",role:"status",children:a.text}):null]})]}),n.jsx(R,{size:"sm",disabled:r,onClick:o,children:"Send a test"})]})}function qW(e,t,s){const r=e.perKind[t];return r==="off"?cA.has(t)?"default":"off":r&&s.some(i=>i.kind===r)?r:"default"}function QW(e,t){var s;return e.channel&&e.channel!=="dashboard"?((s=t.find(r=>r.kind===e.channel))==null?void 0:s.label)??e.channel:"dashboard"}function JW({row:e}){return e.state==="failed"?n.jsxs("span",{className:"nt-state","data-tone":"critical",children:["Failed: ",e.error??"no reason given"]}):e.actedAt?n.jsx("span",{className:"nt-state",children:"Acted on"}):e.seenAt?n.jsx("span",{className:"nt-state",children:"Seen"}):e.state==="held"?n.jsx("span",{className:"nt-state",children:"Waiting"}):e.state==="stored"?n.jsx("span",{className:"nt-state",children:"Kept"}):e.state==="sent"?n.jsx("span",{className:"nt-state",children:"Sent"}):n.jsx("span",{className:"nt-state",children:"Not seen"})}const mb={mon:"Mon",tue:"Tue",wed:"Wed",thu:"Thu",fri:"Fri",sat:"Sat",sun:"Sun"},pb={mode:"do-not-disturb",days:[...Lm],from:"22:00",to:"07:00"};function XW({schedules:e,onChange:t}){const s=(r,i)=>t(e.map((a,l)=>l===r?{...a,...i}:a));return n.jsxs(J,{gap:"sm",children:[e.length===0?n.jsx("p",{className:"ui-card-meta",children:"No schedule: a focus is on only when you switch one on."}):null,e.map((r,i)=>{const a=i+1;return n.jsxs("div",{className:"nt-schedule",role:"group","aria-label":`Schedule ${a}`,children:[n.jsxs("select",{"aria-label":`Schedule ${a} mode`,value:r.mode,onChange:l=>s(i,{mode:l.target.value}),children:[n.jsx("option",{value:"do-not-disturb",children:"Do not disturb"}),n.jsx("option",{value:"urgent-only",children:"Urgent only"})]}),n.jsx("span",{className:"nt-days",children:Lm.map(l=>{const o=r.days.includes(l);return n.jsx("button",{type:"button",className:"nt-day","aria-pressed":o,"aria-label":`Schedule ${a} ${mb[l]}`,onClick:()=>s(i,{days:o?r.days.filter(c=>c!==l):Lm.filter(c=>c===l||r.days.includes(c))}),children:mb[l]},l)})}),n.jsx(ee,{label:"From",children:n.jsx("input",{type:"time","aria-label":`Schedule ${a} from`,value:r.from,onChange:l=>s(i,{from:l.target.value})})}),n.jsx(ee,{label:"To",children:n.jsx("input",{type:"time","aria-label":`Schedule ${a} to`,value:r.to,onChange:l=>s(i,{to:l.target.value})})}),n.jsx(R,{size:"sm",variant:"ghost","aria-label":`Remove schedule ${a}`,onClick:()=>t(e.filter((l,o)=>o!==i)),children:"Remove"})]},i)}),n.jsx("div",{className:"nt-schedule-add",children:n.jsx(R,{size:"sm",onClick:()=>t([...e,{...pb,days:[...pb.days]}]),children:"Add a schedule"})})]})}const ZW={you:"person",appearance:"sun",notifications:"bell",memory:"notebook",proposals:"bulb",accounts:"key",computer:"monitor",secrets:"key",connections:"globe",watchers:"eye",backup:"archive",system:"chip",plugins:"plug"};function eH(e){const t=JO.map(r=>({id:r.id,route:et(r.id),label:r.label,icon:ZW[r.id],group:r.group})),s=[...e].sort((r,i)=>r.title.localeCompare(i.title,void 0,{sensitivity:"base"})||r.plugin.localeCompare(i.plugin)||r.id.localeCompare(i.id)).map(r=>({id:WN(r.plugin,r.id),route:al(r.plugin,r.id),label:r.title,icon:NC(r.icon),group:"plugins"}));return[...t,...s]}function uA(e){return QO.map(t=>({id:t.id,label:t.label,entries:e.filter(s=>s.group===t.id)})).filter(t=>t.entries.length>0)}function dA(e,t,s){return t?`${e}, ${t} open`:s?`${e}, ${s}`:void 0}function tH({entries:e,active:t,counts:s={},dots:r={},navigate:i}){var u;const a=f.useRef(null),l=uA(e),o=e.some(h=>h.id===t)?t:(u=e[0])==null?void 0:u.id,c=h=>{var x;const d=[...((x=a.current)==null?void 0:x.querySelectorAll("a.settings-nav-link"))??[]],m=d.indexOf(document.activeElement);if(m===-1)return;const p=j=>{var b;h.preventDefault(),(b=d[Math.max(0,Math.min(d.length-1,j))])==null||b.focus()};if(h.key==="ArrowDown")p(m+1);else if(h.key==="ArrowUp")p(m-1);else if(h.key==="Home")p(0);else if(h.key==="End")p(d.length-1);else if(h.key==="Enter"||h.key===" "){h.preventDefault();const j=d[m].getAttribute("href");j&&i(j)}};return n.jsx("nav",{className:"settings-nav","aria-label":"Settings sections",ref:a,onKeyDown:c,children:l.map(h=>n.jsxs("div",{className:"settings-nav-group",role:"group","aria-labelledby":`settings-nav-${h.id}`,children:[n.jsx("div",{className:"settings-nav-label",id:`settings-nav-${h.id}`,children:h.label}),h.entries.map(d=>{const m=d.id===t,p=s[d.id],x=r[d.id];return n.jsxs("a",{className:"settings-nav-link",href:d.route,"data-active":m?"true":void 0,"aria-current":m?"page":void 0,"aria-label":dA(d.label,p,x),tabIndex:d.id===o?0:-1,onClick:j=>{j.preventDefault(),i(d.route)},children:[n.jsx(we,{name:d.icon,className:"settings-nav-icon"}),n.jsx("span",{className:"settings-nav-text",children:d.label}),p?n.jsx("span",{className:"ui-badge settings-nav-count","aria-hidden":"true",children:p>99?"99+":p}):x?n.jsx("span",{className:"ui-badge settings-nav-dot","data-kind":"dot","data-testid":"settings-nav-dot","aria-hidden":"true"}):null]},d.id)})]},h.id))})}function nH({entries:e,active:t,counts:s={},dots:r={},navigate:i}){const a=uA(e),l=e.find(o=>o.id===t)??e[0];return n.jsx("nav",{className:"settings-menu","aria-label":"Settings sections",children:n.jsxs(Kd,{modal:!1,children:[n.jsx(Vd,{asChild:!0,children:n.jsxs("button",{type:"button",className:"settings-menu-trigger","aria-label":`Settings section: ${(l==null?void 0:l.label)??""}`,children:[l?n.jsx(we,{name:l.icon,className:"settings-nav-icon"}):null,n.jsx("span",{className:"settings-nav-text",children:l==null?void 0:l.label}),n.jsx(we,{name:"chevron-down",className:"settings-menu-chevron"})]})}),n.jsx(Wo,{children:n.jsx(Gd,{className:"ui-menu settings-menu-list",align:"start",sideOffset:6,children:n.jsx(oO,{value:t,onValueChange:o=>{const c=e.find(u=>u.id===o);c&&i(c.route)},children:a.map((o,c)=>n.jsxs(FN,{children:[c>0?n.jsx(Mr,{className:"ui-menu-sep"}):null,n.jsx(Yd,{className:"ui-menu-label",children:o.label}),o.entries.map(u=>{const h=s[u.id],d=r[u.id];return n.jsxs(cO,{value:u.id,className:"ui-menu-item settings-menu-item","data-active":u.id===t?"true":void 0,"aria-label":dA(u.label,h,d),children:[n.jsxs("span",{className:"settings-menu-entry",children:[n.jsx(we,{name:u.icon,className:"settings-nav-icon"}),n.jsx("span",{className:"settings-nav-text",children:u.label})]}),h?n.jsx("span",{className:"ui-badge settings-nav-count","aria-hidden":"true",children:h>99?"99+":h}):d?n.jsx("span",{className:"ui-badge settings-nav-dot","data-kind":"dot","aria-hidden":"true"}):null]},u.id)})]},o.id))})})})]})})}function sH({hash:e,timezone:t,navigate:s,agents:r,pluginPages:i}){var v,w,y;const a=XO(e),l=P1(i!==void 0),o=i??l,c=KO(e),u=c?o.find(c.plugin,c.page):void 0,h=Li(Qx),d=eH(o.settings),p={proposals:((w=(v=le(()=>Promise.resolve().then(()=>T.proposals()),[],3e4).data)==null?void 0:v.open)==null?void 0:w.length)??0},x=le(()=>T.version(),[]),j=le(()=>Promise.resolve().then(()=>T.connectionSignals()),[],6e4),b={};x.data&&!x.data.checkout&&x.data.updateAvailable&&(b.system="a newer buddi is ready"),(((y=j.data)==null?void 0:y.signals)??[]).length>0&&(b.connections=CC);const g={entries:d,active:a,counts:p,dots:b,navigate:N=>s(N)};return n.jsxs("div",{className:"settings",children:[h?null:n.jsx(tH,{...g}),n.jsx("div",{className:"settings-body",children:n.jsxs("div",{className:"ui-page",children:[a==="plugins"||a==="connections"?n.jsx(Zd,{before:n.jsx(y1,{inline:!0,items:[{label:"Settings",href:dn,onClick:()=>s(dn)}]}),title:a==="plugins"?"Plugins":"Connections",lede:a==="plugins"?C8:OE}):n.jsxs("header",{className:"ui-page-head",children:[n.jsx("h2",{className:"ui-page-title",children:"Settings"}),n.jsx("p",{className:"ui-page-lede",children:"How this installation runs, and where it reaches."})]}),h?n.jsx(nH,{...g}):null,u?n.jsx(PU,{page:u,navigate:s,timezone:t,siblings:o.all.filter(N=>N.plugin===u.plugin)}):null,a==="you"?n.jsx(f8,{embedded:!0}):null,a==="appearance"?n.jsx(rH,{railPages:o.rail}):null,a==="notifications"?n.jsx(WW,{timezone:t}):null,a==="memory"?n.jsx(BC,{embedded:!0,agents:r,timezone:t}):null,a==="proposals"?n.jsx(j8,{embedded:!0,plugin:GO(e)}):null,a==="accounts"?n.jsx(a5,{embedded:!0}):null,a==="computer"?n.jsx(t3,{embedded:!0,timezone:t}):null,a==="secrets"?n.jsx(T5,{embedded:!0,timezone:t}):null,a==="connections"?n.jsx(K5,{embedded:!0,timezone:t}):null,a==="watchers"?n.jsx(d8,{timezone:t,embedded:!0}):null,a==="backup"?n.jsx(XB,{}):null,a==="plugins"?n.jsx(O8,{railPages:o.rail,settingsPages:o.settings,navigate:s,hash:e}):null,a==="system"?n.jsx(lH,{timezone:t}):null]})})]})}function rH({railPages:e}){const[t,s]=MC();return n.jsx(te,{title:"Appearance",aside:"Kept in this browser only. Another browser keeps its own.",panel:!0,children:n.jsxs(J,{divided:!0,gap:"lg",children:[n.jsx(Pf,{label:"Theme",hint:"System follows your Mac.",children:n.jsx(ls,{label:"Theme",options:[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}],value:t.theme,onChange:r=>s({theme:r})})}),n.jsx(Pf,{label:"Background",hint:"Blue carries the first-run colours through the app. Sand is quieter.",children:n.jsx(ls,{label:"Background",options:[{value:"blue",label:"Blue"},{value:"sand",label:"Sand"}],value:t.ground,onChange:r=>s({ground:r})})}),n.jsx(Pf,{label:"Page width",hint:"How far pages stretch on a wide screen.",children:n.jsx(ls,{label:"Page width",options:[{value:"narrow",label:"Narrow"},{value:"wide",label:"Wide"},{value:"full",label:"Full"}],value:t.width,onChange:r=>s({width:r})})}),n.jsx(aH,{pages:e}),n.jsx(iH,{})]})})}function iH(){var a;const e=le(()=>T.overview(),[]),[t,s]=f.useState(null),r=((a=e.data)==null?void 0:a.glances)??[];if(r.length===0)return null;const i=(l,o)=>{s(l),T.setGlanceHidden(l,!o).then(()=>e.reload()).finally(()=>s(null))};return n.jsxs("div",{className:"pref-row ui-section",children:[n.jsxs("div",{className:"pref-text",children:[n.jsx("span",{className:"pref-label",children:"Home glances"}),n.jsx("span",{className:"ui-field-hint",children:"The lines beside the date on Home, at most three. Kept for every browser."})]}),n.jsx(J,{gap:"sm",children:r.map(l=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:!l.hidden,disabled:t===l.id,onChange:o=>i(l.id,o.target.checked)}),n.jsx("span",{children:l.title})]},l.id))})]})}function aH({pages:e}){const t=AC(),[s,r]=f.useState(null);if(e.length===0)return null;const i=(a,l)=>{r(null),GU(a,!l).catch(o=>r(o instanceof Error?o.message:String(o)))};return n.jsxs("div",{className:"pref-row ui-section",children:[n.jsxs("div",{className:"pref-text",children:[n.jsx("span",{className:"pref-label",children:"In the rail"}),n.jsx("span",{className:"ui-field-hint",children:"The plugin pages beside Home and Chat. One you turn off still opens from Settings → Plugins. Kept for every browser."})]}),n.jsxs(J,{gap:"sm",children:[n.jsx(se,{message:s}),e.map(a=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:!t.has(Io(a)),onChange:l=>i(a,l.target.checked)}),n.jsx("span",{children:a.title})]},Io(a)))]})]})}function Pf({label:e,hint:t,children:s}){return n.jsxs("div",{className:"pref-row ui-section",children:[n.jsxs("div",{className:"pref-text",children:[n.jsx("span",{className:"pref-label",children:e}),n.jsx("span",{className:"ui-field-hint",children:t})]}),s]})}function lH({timezone:e}){const t=le(()=>T.overview(),[],15e3),s=le(()=>T.session(),[]),r=le(()=>T.providerAccounts(),[]),i=t.data;return n.jsxs(J,{gap:"lg",children:[n.jsx(se,{message:t.error}),n.jsx(yH,{}),i?n.jsx(te,{title:"The queue",panel:!0,actions:n.jsx(R,{size:"sm",variant:i.paused?"accent":void 0,onClick:()=>{T.setPaused(!i.paused).then(()=>t.reload())},children:i.paused?"Resume the queue":"Pause the queue"}),children:n.jsxs("p",{className:"ui-card-meta",children:[i.paused?"Paused. Nothing is being claimed until you resume.":"Running. Jobs are claimed as they come due."," ",i.paused?n.jsx(ge,{tone:"warning",children:"paused"}):n.jsx(ge,{tone:"good",children:"running"})]})}):null,n.jsxs(te,{title:"This host",panel:!0,children:[n.jsx(Vt,{items:[{label:"Time zone",value:e},{label:"Server time",value:i?Be(i.now,e):"…"},{label:"Bound to",value:s.data?`${s.data.host}:${s.data.port}`:"…"},{label:"Credential vault",value:r.data?dH(r.data.vault.kind):"…"}]}),r.data&&(r.data.vault.locked||r.data.vault.kind==="none")?n.jsx(H,{tone:"warning",children:r.data.vault.advice||"Run buddi init on the host to configure secure credential storage."}):null]}),n.jsx(uH,{}),n.jsx(oH,{}),n.jsx(te,{title:"Mail and sources",panel:!0,children:i?i.mail.length===0?n.jsx(oe,{children:"No sources are installed."}):n.jsx(Vt,{items:i.mail.map(a=>({key:a.sourceId,label:n.jsx("span",{className:"mono",children:a.sourceId}),value:a.lastError?n.jsx("span",{className:"critical",children:a.lastError}):n.jsxs("span",{children:["polled ",Fe(a.lastRunAt)]})}))}):n.jsx(oe,{children:"Loading…"})})]})}function oH(){var p;const e=le(()=>T.tailscale(),[]),[t,s]=f.useState(null),[r,i]=f.useState(!1),[a,l]=f.useState(null),[o,c]=f.useState(!1),u=e.data,h=t??((u==null?void 0:u.login)||((p=u==null?void 0:u.self)==null?void 0:p.login)||""),d=(u==null?void 0:u.proxied)===!0,m=x=>{i(!0),l(null),c(!1),T.setTailscale({enabled:x,login:h.trim()}).then(()=>{c(!0)}).catch(j=>l(j instanceof pe?j.message:String(j))).finally(()=>{i(!1),e.reload()})};return n.jsx(te,{title:"Sign in through Tailscale",panel:!0,foot:n.jsx(R,{variant:"accent",disabled:r||!u||d,onClick:()=>m((u==null?void 0:u.enabled)??!1),children:"Save"}),children:n.jsx(J,{divided:!0,children:n.jsx(te,{children:n.jsxs(J,{gap:"sm",children:[n.jsx(se,{message:e.error??a}),n.jsx("p",{className:"ui-card-meta",children:u?u.available&&u.self?`Tailscale is running on this machine as ${u.self.login}.`:u.available?"Tailscale is running on this machine.":"Tailscale is not running here.":"…"}),d?n.jsxs(n.Fragment,{children:[n.jsx(H,{tone:"warning",children:"Change this from the computer buddi runs on."}),n.jsx("p",{className:"ui-card-meta",children:u!=null&&u.enabled?`On, for ${h}`:"Off"})]}):null,n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:(u==null?void 0:u.enabled)??!1,disabled:r||!u||d,onChange:x=>m(x.target.checked)}),n.jsx("span",{children:"Let this Tailscale login sign in"})]}),n.jsx(ee,{label:"Tailscale login",children:n.jsx("input",{type:"text",value:h,placeholder:"you@example.com",disabled:r||!u||d,onChange:x=>s(x.target.value)})}),n.jsx("p",{className:"ui-card-meta",children:"Anyone signed in to Tailscale as this login, on any device in your tailnet, is signed in to buddi. The proxy must run on this machine:"}),n.jsxs("div",{className:"tailscale-command",children:[n.jsx("code",{className:"mono",children:(u==null?void 0:u.serveCommand)??"tailscale serve"}),n.jsx(R,{size:"sm",disabled:r||!u,onClick:()=>{cH((u==null?void 0:u.serveCommand)??"")},children:"Copy"})]}),n.jsx("p",{className:"ui-card-meta",children:"This gives your tailnet the trust this machine already has: buddi cannot tell the Tailscale proxy from another program running here, and any program that can reach the dashboard on this machine can already read buddi’s files."}),o?n.jsx(H,{tone:"good",role:"status",children:"Saved."}):null]})})})})}async function cH(e){var t;try{await((t=navigator.clipboard)==null?void 0:t.writeText(e))}catch{}}function uH(){var u;const e=le(()=>T.service(),[],1e4),[t,s]=f.useState(null),[r,i]=f.useState(!1),[a,l]=f.useState(null),o=(u=e.data)!=null&&u.supervised?e.data.status:void 0;if(!o)return null;const c=h=>{i(!0),l(null),T.serviceAction(h).then(()=>{s(null)}).catch(d=>{l(d.message)}).finally(()=>{i(!1),e.reload()})};return n.jsx(te,{title:"Service",panel:!0,children:n.jsxs(J,{divided:!0,children:[n.jsx(te,{children:n.jsx(Vt,{items:[{label:"Database",value:n.jsx(gb,{state:o.database,pid:o.databasePid})},{label:"Gateway",value:n.jsx(gb,{state:o.gateway,pid:o.gatewayPid})},{label:"Supervisor",value:n.jsxs("span",{className:"mono",children:["pid ",o.supervisorPid]})}]})}),n.jsx(te,{children:n.jsxs(J,{gap:"sm",children:[n.jsx(se,{message:a}),t?n.jsx(H,{tone:"warning",role:"alert",children:t==="stop"?"Stopping the gateway closes this dashboard. The database keeps running; run buddi in a terminal to bring the dashboard back.":"Restarting the gateway closes this dashboard for a few seconds. If it does not come back on its own, run buddi in a terminal."}):n.jsx("p",{className:"ui-card-meta",children:"Stopping the gateway ends this dashboard until buddi is run again."}),n.jsx(Q,{align:"end",children:t?n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",disabled:r,onClick:()=>{s(null),l(null)},children:"Cancel"}),n.jsx(R,{variant:t==="stop"?"danger":"accent",disabled:r,onClick:()=>{c(t)},children:t==="stop"?"Stop it":"Restart it"})]}):n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",onClick:()=>{s("stop")},children:"Stop gateway"}),n.jsx(R,{variant:"accent",onClick:()=>{s("restart")},children:"Restart gateway"})]})})]})})]})})}function gb({state:e,pid:t}){return n.jsxs("span",{children:[n.jsx(ge,{tone:e==="running"?"good":e==="stopped"?"warning":e==="failed"?"critical":"muted",children:e})," ",t===null?n.jsx("span",{className:"ui-card-meta",children:"no process"}):n.jsxs("span",{className:"mono",children:["pid ",t]})]})}function dH(e){return e==="keychain"?"macOS Keychain":e==="file"?"Encrypted file vault":e==="none"?"None":e}const hH=2e3,xb={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.",restarting:"Restarting buddi on the new version.",migrating:"Bringing the database up to date.",done:"Done.",failed:"That did not work."},fH=new Set(["done","failed","rolled-back"]),mH="The check asks the npm registry for the newest version and sends nothing else.",pH="This takes a backup, installs the new version and restarts buddi. This page closes and comes back on its own.",gH="A checkout upgrades with git pull, then buddi upgrade in a terminal.",xH=10*6e4,vH="buddi did not come back. Run buddi doctor in a terminal.";function jH(e){const t=e.step==="starting"?"while starting":`at ${e.step??"an unknown step"}`;return`The upgrade to ${e.to} failed ${t}: ${e.error??"no reason given"}. The backup taken first is ${e.backup??"not available"}. Run buddi doctor in a terminal; it prints the way back.`}function wH(e,t,s,r){const[i,a]=f.useState(void 0),[l,o]=f.useState(!1),[c,u]=f.useState(null),h=f.useRef(!1),d=f.useRef(s),m=f.useRef(r);return d.current=s,m.current=r,f.useEffect(()=>{if(!e){a(void 0),o(!1),h.current=!1;return}let p=!1,x=0;const j=()=>{h.current=!0,x=Date.now()+xH,o(!0)},b=()=>{if(Date.now()<x){T.session().then(w=>{p||w.version!==void 0&&w.version===t||(p=!0,d.current())}).catch(()=>{}),T.version().then(w=>{const y=w.history[w.history.length-1];p||(y==null?void 0:y.outcome)!=="failed"||(p=!0,o(!1),u(jH(y)))}).catch(()=>{});return}p=!0,o(!1),u(vH)},g=()=>{if(!p){if(h.current)return b();T.upgradeJob(e).then(w=>{var y;p||(a(w),u(null),(fH.has(w.phase)||w.finishedAt)&&(p=!0,w.phase==="failed"&&((y=m.current)==null||y.call(m,w))))}).catch(w=>{p||(w instanceof pe&&w.status!==0&&w.status<500?u(w.message):j())})}};g();const v=window.setInterval(g,hH);return()=>{p=!0,window.clearInterval(v)}},[e,t]),{job:i,away:l,error:c}}function yH({reload:e}){var y;const t=le(()=>T.version(),[]),[s,r]=f.useState(null),[i,a]=f.useState(!1),[l,o]=f.useState(!1),[c,u]=f.useState(null),[h,d]=f.useState(null),m=(y=t.data)==null?void 0:y.current,p=e??(()=>window.location.reload()),x=f.useCallback(N=>{r(null),d(N)},[]),j=wH(s,m,p,x),b=t.data,g=()=>{o(!0),u(null),T.checkVersion().catch(N=>u(N instanceof pe?N.message:String(N))).finally(()=>{o(!1),t.reload()})},v=N=>{o(!0),u(null),T.setVersionCheck(N).catch(k=>u(k instanceof pe?k.message:String(k))).finally(()=>{o(!1),t.reload()})},w=()=>{o(!0),u(null),d(null),T.startUpgrade(b==null?void 0:b.latest).then(N=>{var k;a(!1),r(((k=N.job)==null?void 0:k.id)??null)}).catch(N=>u(N instanceof pe?N.message:String(N))).finally(()=>o(!1))};return b!=null&&b.checkout?n.jsx(te,{title:"Version",panel:!0,children:n.jsxs(J,{divided:!0,children:[n.jsx(te,{children:n.jsx(Vt,{items:[{label:"Running",value:n.jsx("span",{className:"mono",children:b.current})}]})}),n.jsx(te,{children:n.jsx("p",{className:"ui-card-meta",children:gH})})]})}):n.jsx(te,{title:"Version",panel:!0,children:n.jsxs(J,{divided:!0,children:[n.jsx(te,{children:n.jsxs(J,{gap:"sm",children:[n.jsx(se,{message:t.error??c}),n.jsx(Vt,{items:[{label:"Running",value:b?n.jsx("span",{className:"mono",children:b.current}):"…"},{label:"Newest",value:b?b.updateAvailable&&b.latest?n.jsxs("span",{children:["A newer buddi is available: ",n.jsx("span",{className:"mono",children:b.latest})]}):b.checkedAt?n.jsxs("span",{children:["This is the latest, as of ",Fe(b.checkedAt),"."]}):n.jsx("span",{children:"Not checked yet."}):"…"}]}),b!=null&&b.error?n.jsxs(H,{tone:"warning",children:["The last check did not get an answer: ",b.error]}):null,n.jsx(Q,{align:"end",children:n.jsx(R,{disabled:l,onClick:g,children:"Check now"})})]})}),n.jsx(te,{children:n.jsxs(J,{gap:"sm",children:[n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:(b==null?void 0:b.checkEnabled)??!1,disabled:l||!b,onChange:N=>v(N.target.checked)}),n.jsx("span",{children:"Check once a day"})]}),n.jsx("p",{className:"ui-card-meta",children:mH})]})}),b!=null&&b.updateAvailable&&b.latest&&b.latestNotes?n.jsx(te,{title:`What changes in ${b.latest}`,children:n.jsx(mr,{text:b.latestNotes})}):null,n.jsx(te,{children:n.jsxs(J,{gap:"sm",children:[n.jsx(bH,{...j,job:j.job??h??void 0}),i?n.jsx(H,{tone:"warning",role:"alert",children:pH}):null,n.jsx(Q,{align:"end",children:i?n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",disabled:l,onClick:()=>a(!1),children:"Cancel"}),n.jsxs(R,{variant:"accent",disabled:l,onClick:w,children:["Upgrade to ",b==null?void 0:b.latest]})]}):n.jsx(R,{variant:"accent",disabled:l||s!==null||!(b!=null&&b.updateAvailable),onClick:()=>a(!0),children:b!=null&&b.updateAvailable&&b.latest?`Upgrade to ${b.latest}`:"Upgrade"})})]})}),b&&b.history.length>0?n.jsx(te,{title:"Upgrades so far",children:n.jsx(Vt,{items:b.history.slice().reverse().map(N=>({key:N.startedAt,label:n.jsxs("span",{className:"mono",children:[N.from," → ",N.to]}),value:n.jsx(kH,{attempt:N})}))})}):null]})})}function bH({job:e,away:t,error:s}){return s?n.jsx(se,{message:s}):t?n.jsx(H,{tone:"warning",role:"status",children:"buddi is restarting. This page comes back on its own when it answers again."}):e?e.phase==="failed"?n.jsxs(H,{tone:"critical",role:"alert",children:[xb.failed," ",e.error??""," buddi is still running on the version it had."]}):n.jsx(H,{tone:e.phase==="done"?"good":void 0,role:"status",children:xb[e.phase]??e.detail??e.phase}):null}function kH({attempt:e}){return n.jsxs("span",{children:[n.jsx(ge,{tone:e.outcome==="done"?"good":e.outcome==="failed"?"critical":"warning",children:e.outcome})," ",Fe(e.startedAt),e.step?`, at ${e.step}`:"",e.error?`: ${e.error}`:"",e.backup?n.jsxs("span",{className:"ui-card-meta",children:[" Backup: ",n.jsx("span",{className:"mono",children:e.backup})]}):null]})}const hd=["hello","brain","takeOn","reach","assistant","handover"],hA={hello:"you",brain:"model",takeOn:"take-on",reach:"reach",assistant:"agent",handover:"hello"};function fA(e){return((e==null?void 0:e.accounts)??[]).filter(t=>t.enabled&&t.configured&&t.removalPending!==!0)}function SH(e){var a,l,o;const t=fA(e.accounts),s=e.assistant?(((a=e.accounts)==null?void 0:a.bindings)??[]).find(c=>c.agentId===e.assistant.id):void 0,r=(s==null?void 0:s.accountId)??((o=(l=e.onboarding)==null?void 0:l.details)==null?void 0:o.accountId);if(!r)return;const i=t.find(c=>c.id===r);if(i)return{accountId:i.id,label:i.label,model:(s==null?void 0:s.model)??i.defaultModel}}function mA(e){var a,l,o,c,u;const t=SH(e),s=e.onboarding&&!e.onboarding.needs.agent?e.assistant:void 0,r=((a=e.onboarding)==null?void 0:a.details)??{},i=((l=e.onboarding)==null?void 0:l.stepsDone)??[];return{...(o=e.owner)!=null&&o.preferredName?{name:e.owner.preferredName}:{},...(c=e.owner)!=null&&c.timezone?{clock:e.owner.timezone}:{},...t?{brain:t}:{},...Array.isArray(r.takeOn)?{takeOn:r.takeOn}:s?{takeOn:[]}:{},...r.reach?{reach:r.reach}:i.includes("reach")||s?{reach:{}}:{},...i.includes("browser")||((u=r.reach)==null?void 0:u.browser)===!0?{browser:e.browser??"other"}:{},...s?{assistant:s}:{}}}function pA(e,t){return t==="hello"?typeof e.name=="string"&&e.name!==""&&typeof e.clock=="string"&&e.clock!=="":t==="brain"?e.brain!==void 0:t==="takeOn"?e.takeOn!==void 0:t==="reach"?e.reach!==void 0:t==="assistant"?e.assistant!==void 0:!1}function vu(e){return hd.find(t=>!pA(e,t))??"handover"}function NH(e){const t=hd.indexOf(e);return t>0?hd[t-1]:null}function vb(e,t,s){return s===t?"now":pA(e,s)?"done":"todo"}function CH(e,t){return{...e}}const Hp="buddi.firstRun.restore";function Kp(e){try{e===null?window.sessionStorage.removeItem(Hp):window.sessionStorage.setItem(Hp,e)}catch{}}function gA(){try{return window.sessionStorage.getItem(Hp)}catch{return null}}function EH(e){const t=mA(e),s=vu(t);return{answers:t,open:s,stay:s!=="handover"}}function AH(e){return e.trim().startsWith("sk-ant-")?"anthropic":"openai"}function TH(e){const t=e.normalize("NFKD").replace(/[̀-ͯ]/g,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^[^a-z]+/,"").replace(/-+$/,"").slice(0,20).replace(/-+$/,"");return t===""?"assistant":t}const RH=6e4,IH=5*6e4,xA=1500,PH=2e3,$H="(max-width: 720px)";function dl(){const e=f.useRef(null);return f.useEffect(()=>{let t=0,s=0;const r=l=>{const o=l.ownerDocument.activeElement;if(o===null||o===l.ownerDocument.body||o===l.ownerDocument.documentElement)return!0;const c=l.closest('[role="dialog"]');return c!==null&&o.tagName==="BUTTON"&&o.closest('[role="dialog"]')===c},i=()=>{const l=e.current;l&&r(l)&&l.focus()},a=()=>{i(),s=window.setTimeout(i,0)};return typeof window.requestAnimationFrame=="function"?t=window.requestAnimationFrame(a):a(),window.addEventListener("focus",i),()=>{t&&window.cancelAnimationFrame(t),window.clearTimeout(s),window.removeEventListener("focus",i)}},[]),e}const Sv=f.createContext({busy:0,report:()=>{}});function MH({children:e}){const[t,s]=f.useState(0),r=f.useCallback(a=>s(l=>Math.max(0,l+(a?1:-1))),[]),i=f.useMemo(()=>({busy:t,report:r}),[t,r]);return n.jsx(Sv.Provider,{value:i,children:e})}function Qe({children:e}){const{busy:t}=f.useContext(Sv);return n.jsxs("div",{className:"wiz-say",children:[n.jsx(Xd,{state:t>0?"working":"idle",size:"sm",className:"wiz-say-face"}),n.jsx("div",{className:"wiz-bubble",children:e})]})}function We({children:e}){return n.jsx(n.Fragment,{children:e})}function Ts({line:e}){const{report:t}=f.useContext(Sv);return f.useEffect(()=>(t(!0),()=>t(!1)),[t]),n.jsxs("div",{className:"wiz-busy",role:"status","aria-live":"polite",children:[n.jsxs("span",{className:"wiz-pulse","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]}),e]})}const Nv=f.createContext(null);function Ft({children:e,actions:t}){const s=f.useContext(Nv),r=t==null?null:s?Fo.createPortal(t,s):n.jsx("div",{className:"wiz-dock-inline",children:t});return n.jsxs(n.Fragment,{children:[e?n.jsx("div",{className:"wiz-ask",children:e}):null,r]})}function Hn({onClick:e,disabled:t}){return n.jsxs(R,{variant:"ghost",size:"lg",onClick:e,disabled:t,children:[n.jsx(we,{name:"chevron-left"}),P.back]})}function hl({children:e,onClick:t,disabled:s}){return n.jsxs(R,{variant:"accent",size:"lg",onClick:t,disabled:s,children:[e,n.jsx(we,{name:"arrow"})]})}function OH({navigate:e,timezone:t}){var nn,K,Ne,nt,bt,Yt,wr;const s=Li($H),[r,i]=f.useState(void 0);f.useEffect(()=>{T.session().then(de=>i(de.platform)).catch(()=>{})},[]);const[a,l]=f.useState({}),[o,c]=f.useState(null),[u,h]=f.useState(void 0),[d,m]=f.useState(void 0),[p,x]=f.useState([]),[j,b]=f.useState(null),[g,v]=f.useState(null),[w,y]=f.useState(!1),[N,k]=f.useState(null),[S,C]=f.useState(null),[I,A]=f.useState(null),[O,z]=f.useState(null),[L,E]=f.useState(()=>gA()?"running":"idle"),[$,_]=f.useState({}),[B,M]=f.useState([]),[W,D]=f.useState(0),U=f.useRef(void 0),[V,Z]=f.useState(null),ue=f.useCallback(()=>{Promise.resolve().then(()=>T.takeOnProgress()).then(de=>{de&&Array.isArray(de.plugins)&&Z(de)}).catch(()=>{})},[]);f.useEffect(()=>{if(!(V!=null&&V.running))return;const de=window.setInterval(ue,PH);return()=>window.clearInterval(de)},[V==null?void 0:V.running,ue]);const Ae=f.useMemo(()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone||t}catch{return t}},[t]),X=f.useRef(e);X.current=e;const ae=f.useCallback(async(de=!0,Ze=!1)=>{var Jo,qs,hi,ml,fi,Mn,mi,Qs,Nr;const[Re,sn,yr,Jn,br,kr]=await Promise.all([T.onboarding().catch(()=>{}),T.owner().catch(()=>{}),T.providerAccounts().catch(()=>{}),Le.agents().catch(()=>{}),T.browser().catch(()=>{}),T.providers().catch(()=>{})]);h(yr);const Sr=(qs=(Jo=kr==null?void 0:kr.providers.find(Rt=>Rt.kind==="anthropic"))==null?void 0:Jo.defaultModel)==null?void 0:qs.trim();m(Sr||void 0),x((sn==null?void 0:sn.zones)??[]),k(((hi=Re==null?void 0:Re.details)==null?void 0:hi.conversationId)??null);const Ye=(Jn==null?void 0:Jn.agents.find(Rt=>Rt.id===Jn.defaultAgentId))??(Jn==null?void 0:Jn.agents[0]);Ye&&b(Ye),C(Re&&!Re.needs.agent&&Ye?{id:Ye.id,name:Ye.name,avatar:((ml=Ye.avatar)==null?void 0:ml.kind)==="emoji"?Ye.avatar.value:"",description:Ye.description,...Ye.picture?{picture:Ye.picture}:{}}:null),Array.isArray((fi=Re==null?void 0:Re.details)==null?void 0:fi.takeOn)&&ue();const mn={onboarding:Re,owner:sn,accounts:yr,browser:(Mn=br==null?void 0:br.browser)==null?void 0:Mn.engine,...Ye?{assistant:{id:Ye.id,name:Ye.name,avatar:((mi=Ye.avatar)==null?void 0:mi.kind)==="emoji"?Ye.avatar.value:""}}:{}};if(Ze){const Rt=EH(mn);if(l(Rt.answers),c(Rt.open),!Rt.stay){const Rs=(Qs=Re==null?void 0:Re.details)==null?void 0:Qs.conversationId;X.current(Rs&&Ye?Ve(Ye.id,Rs):Kt,!0)}return}if(de&&(Re==null?void 0:Re.state)==="done"){const Rt=(Nr=Re.details)==null?void 0:Nr.conversationId;X.current(Rt&&Ye?Ve(Ye.id,Rt):Kt,!0);return}if(!de)return;const be=mA(mn);l(be),c(Rt=>Rt??vu(be))},[]);f.useEffect(()=>{ae()},[ae]);const me=(de,Ze={})=>{Promise.resolve().then(()=>T.onboardingStep(hA[de],Ze)).catch(()=>{})},Pe=de=>vu(de)==="brain"&&$.brain?{...de,brain:$.brain}:de,ke=(de,Ze)=>{const Re=Pe(Ze);Re.brain&&(U.current=Re.brain),v(null),M([]),l(Re),de==="brain"&&Re.brain?me(de,{accountId:Re.brain.accountId}):de==="reach"?me(de,Re.reach?{reach:Re.reach}:{}):de!=="takeOn"&&me(de),c(vu(Re))},ye=(de,Ze)=>{v(null),l(Ze),Ze.brain&&(U.current=Ze.brain),de==="brain"&&Ze.brain&&me(de,{accountId:Ze.brain.accountId})},Ce=de=>{v(null),l(Ze=>CH(Ze)),c(de)},ut=()=>{if(!o)return;const de=NH(o==="handover"?"handover":o);de&&Ce(de)},fe=()=>{const de=a.brain??U.current,Ze=((V==null?void 0:V.plugins)??[]).filter(Re=>Re.state==="ready").map(Re=>Re.title);v(null),_({}),M([]),l({}),c("hello"),D(Re=>Re+1),(async()=>{var Sr;const[Re,sn,yr]=await Promise.all([Promise.resolve().then(()=>T.providerAccounts()).catch(()=>{}),Promise.resolve().then(()=>T.telegram()).catch(()=>{}),Promise.resolve().then(()=>T.browser()).catch(()=>{})]),Jn=fA(Re),br=de&&Jn.some(Ye=>Ye.id===de.accountId)?de:void 0;Re&&h(Re),_(br?{brain:br}:{});const kr=[...new Set(Jn.map(Ye=>Ye.label)),...sn!=null&&sn.paired?[P.startOver.telegram]:[],...((Sr=yr==null?void 0:yr.browser)==null?void 0:Sr.engine)==="chromium"?[P.startOver.browser]:[],...Ze];M(kr.length>0?[P.startOver.said(kr.join(", "))]:[])})()},Me=()=>{y(!0),T.skipOnboarding().then(()=>e(Kt)).catch(de=>v(de instanceof pe?de.message:String(de))).finally(()=>y(!1))},ce=le(()=>T.version().catch(()=>({current:""})),[]),Te=f.useRef(null);f.useEffect(()=>{Te.current&&(Te.current.scrollTop=0)},[o]);const G=L==="running",ie=Object.keys(a).length===0,$e={answers:a,accounts:u,claudeModel:d,zones:p,browserZone:Ae,assistantAgent:j,met:N,onMet:k,existing:S,progress:V,onProgress:ue,navigate:e,onSettled:de=>o&&ke(o,de),onKept:de=>o&&ye(o,de),onBack:ut,onTrouble:v,onReload:()=>void ae(!1),onPickAnotherBrain:()=>Ce("brain"),onSpoken:z},yt=(a.takeOn??[]).map(de=>{var Ze;return((Ze=Ra.find(Re=>Re.id===de))==null?void 0:Ze.title)??de}),Ge=(V==null?void 0:V.plugins)??[],it=Ge.filter(de=>de.state==="ready").length,ht=Ge.length===0?null:V!=null&&V.running?P.takeOn.installing(it,Ge.length):it===Ge.length?P.takeOn.installed:null,Y=[(nn=a.reach)!=null&&nn.phone?P.reach.done.phone:null,(K=a.reach)!=null&&K.mailbox?P.reach.done.mailbox:null,(Ne=a.reach)!=null&&Ne.app||(nt=a.reach)!=null&&nt.browser?P.reach.done.app:null].filter(de=>de!==null),at={hello:{answer:P.hello.answer(a.name??""),sub:a.clock??null},brain:{answer:P.brain.answer(((bt=a.brain)==null?void 0:bt.label)??"")},takeOn:{answer:P.takeOn.answer(yt),sub:ht},reach:{answer:P.reach.answer(Y)},assistant:{answer:((Yt=a.assistant)==null?void 0:Yt.name)??""}},Gt=hd.filter(de=>de!=="handover"),Se=o===null||o==="handover"?Gt.length:Gt.indexOf(o),De=Math.min(Se,Gt.length-1),st=O?null:n.jsxs("div",{className:"wiz-map-out",children:[n.jsx("button",{type:"button",className:"wiz-link",disabled:w,onClick:Me,children:P.later}),o==="hello"&&ie&&L==="idle"?n.jsx("button",{type:"button",className:"wiz-link",onClick:()=>E("form"),children:P.restore.offer}):!G&&o!==null&&!(o==="hello"&&ie)?n.jsx("button",{type:"button",className:"wiz-link",disabled:w,onClick:fe,children:P.startOver.link}):null]}),tt=r===void 0||r==="darwin"?P.tagline:P.taglineElsewhere,Mt=o&&o!=="handover"?n.jsx("span",{className:"wiz-count",children:P.count(Se+1)}):n.jsx("span",{className:"wiz-count"});return n.jsx(Nv.Provider,{value:I,children:n.jsx(MH,{children:n.jsxs(k1,{className:"wiz-ground",children:[n.jsx("div",{className:"wiz",ref:Te,"data-phone":s?"true":void 0,"data-testid":"meet",children:n.jsxs("div",{className:"wiz-frame",children:[s?n.jsxs("div",{className:"wiz-strip",children:[n.jsx(Xu,{size:"sm"}),n.jsx("span",{className:"wiz-dots","aria-label":o&&o!=="handover"?P.count(Se+1):void 0,children:Gt.map(de=>n.jsx("i",{"data-state":vb(a,o,de)},de))}),n.jsx("span",{className:"wiz-strip-name",children:o&&o!=="handover"?P.strip(Se+1,P.chapters[Se]??""):P.handover.starterLabel})]}):n.jsxs("nav",{className:"wiz-map","aria-label":"Chapters",children:[n.jsxs("div",{className:"wiz-head",children:[n.jsx(Xu,{size:"lg"}),n.jsxs("div",{children:[n.jsx("div",{className:"wiz-head-name",children:"buddi"}),n.jsx("div",{className:"wiz-head-line",children:tt}),(wr=ce.data)!=null&&wr.current?n.jsxs("div",{className:"wiz-head-version mono",children:["buddi ",ce.data.current]}):null]})]}),Gt.map((de,Ze)=>{const Re=G?de==="hello"?"now":"todo":vb(a,o,de),sn=at[de];return n.jsxs("div",{className:"wiz-ch","data-state":Re,"aria-current":Re==="now"?"step":void 0,children:[n.jsx("span",{className:"wiz-num","data-state":Re,children:Re==="done"?n.jsx(we,{name:"check",size:12}):Ze+1}),n.jsxs("span",{className:"wiz-ch-label",children:[Re==="done"?sn.answer:P.chapters[Ze],Re==="done"&&sn.sub?n.jsx("span",{className:"wiz-ch-sub",children:sn.sub}):null]}),Re==="done"&&!G?n.jsx("button",{type:"button",className:"wiz-link",onClick:()=>Ce(de),children:P.change}):null]},de)}),n.jsx("div",{className:"wiz-map-spacer"}),n.jsx("div",{className:"wiz-map-note",children:P.mapNotes[De]}),st]}),n.jsx("div",{className:"wiz-stage",role:"main",children:n.jsxs("div",{className:"wiz-column","data-width":o==="hello"?"narrow":o==="brain"?"mid":"wide",children:[n.jsxs(K_,{dock:n.jsxs(n.Fragment,{children:[Mt,n.jsx("div",{className:"wiz-dock-actions",ref:A})]}),children:[G?n.jsx(uK,{onDone:de=>{E("idle"),M([...de?[P.restore.welcome(de)]:[],P.restore.keys]),ae(!0,!0)},onFailed:de=>{E("idle"),v(de)}}):o==="hello"?n.jsx(DH,{...$e}):o==="brain"?n.jsx(LH,{...$e}):o==="takeOn"?n.jsx(eK,{...$e}):o==="reach"?n.jsx(tK,{...$e}):o==="assistant"?n.jsx(aK,{...$e}):o==="handover"?n.jsx(lK,{...$e}):n.jsx(Ts,{}),B.length>0||g?n.jsxs(We,{children:[B.map(de=>n.jsx(Qe,{children:de},de)),g?n.jsx(Qe,{children:g}):null]}):null]},`${W}-${o??""}-${G?"r":""}`),s?n.jsx("div",{className:"wiz-phone-out",children:st}):null]})})]})}),L==="form"?n.jsx(cK,{onCancel:()=>E("idle"),onStarted:()=>E("running"),onTrouble:v}):null]})})})}function fl({children:e}){return n.jsx("h1",{className:"wiz-title",children:e})}function jb(e){try{return new Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",timeZone:e}).format(new Date)}catch{return""}}function DH({answers:e,zones:t,browserZone:s,onSettled:r,onTrouble:i}){const a=dl(),[l,o]=f.useState(e.name??""),[c,u]=f.useState(e.clock??s),[h,d]=f.useState(!1),[m,p]=f.useState(!1),x=()=>{const j=l.trim();j===""||m||(p(!0),T.setOwner({preferredName:j,timezone:c}).then(()=>r({...e,name:j,clock:c})).catch(b=>i(b instanceof pe?b.message:String(b))).finally(()=>p(!1)))};return n.jsxs(n.Fragment,{children:[n.jsx(fl,{children:P.hello.title}),n.jsx(We,{children:P.hello.opening.map(j=>n.jsx(Qe,{children:j},j))}),n.jsxs(Ft,{actions:n.jsx(hl,{onClick:x,disabled:m||l.trim()==="",children:P.hello.submit}),children:[n.jsxs("div",{className:"wiz-pair",children:[n.jsx(ee,{label:P.name.label,children:n.jsx("input",{ref:a,placeholder:P.name.placeholder,maxLength:80,value:l,onChange:j=>o(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),x())}})}),h?n.jsx(ee,{label:P.clock.label,hint:P.clock.hint(jb(c)),children:n.jsx("select",{value:c,onChange:j=>u(j.target.value),children:(t.includes(c)?t:[c,...t]).map(j=>n.jsx("option",{value:j,children:j},j))})}):n.jsx(ee,{label:P.clock.label,hint:P.clock.hint(jb(c)),action:n.jsx(R,{size:"lg",onClick:()=>d(!0),children:P.clock.change}),children:n.jsx("input",{value:c,readOnly:!0})})]}),n.jsx("div",{className:"wiz-foot",children:P.hello.foot})]})]})}const _H={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 LH(e){const{accounts:t,answers:s,onSettled:r,onKept:i,onReload:a,onBack:l}=e,[o,c]=f.useState(null),[u,h]=f.useState("key"),[d,m]=f.useState(null),[p,x]=f.useState(!1),[j,b]=f.useState(null),[g,v]=f.useState(null),[w,y]=f.useState(null),N=(t==null?void 0:t.anthropicOAuthEnabled)===!0,k=(t==null?void 0:t.codexEnabled)===!0,S=t==null?void 0:t.gemini,[C,I]=f.useState(null);f.useEffect(()=>{let W=!1;const D=()=>{Promise.resolve().then(()=>T.ollama()).then(V=>{!W&&V&&b(V)}).catch(()=>{}),Promise.resolve().then(()=>T.mlxh()).then(V=>{!W&&V&&v(V)}).catch(()=>{W||v({running:!1,baseUrl:"",manager:!1,models:[]})})};D();const U=window.setInterval(D,4e3);return()=>{W=!0,window.clearInterval(U)}},[]);const A=async W=>{if(s.assistant??e.existing)try{await T.bindBrain({accountId:W.accountId,model:W.model})}catch(D){return D instanceof pe?D.message:String(D)}return a(),i({...s,brain:W}),C==null||C.close(),I(null),c(null),y(null),null},O=async(W,D,U)=>{x(!0),m(null);try{const V=await T.saveProviderAccount(W);let Z=await T.testProviderAccount(V.id),ue=W.defaultModel,Ae=!1;if(Z.state!=="connected"&&U&&U!==ue&&fE(Z)){const ae=(await T.providerAccounts()).accounts.find(me=>me.id===V.id);ae&&(await T.saveProviderAccount({id:ae.id,revision:ae.revision,label:ae.label,kind:ae.kind,auth:ae.auth,baseUrl:ae.baseUrl,defaultModel:U,enabled:ae.enabled}),Z=await T.testProviderAccount(V.id),Z.state==="connected"&&(ue=U,Ae=!0))}if(Z.state!=="connected"){try{const ae=(await T.providerAccounts()).accounts.find(me=>me.id===V.id);ae&&await T.removeProviderAccount(V.id,ae.revision)}catch{}return m(Z.message),Z}const X=await A({accountId:V.id,label:D,model:ue,...Ae?{freeTier:Ae}:{}});return X&&m(X),Z}catch(V){return m(V instanceof pe?V.message:String(V)),null}finally{x(!1)}},z=async W=>{x(!0),m(null);try{const D=await T.saveProviderAccount(W);let U;try{U=await T.testProviderAccount(D.id)}finally{try{const V=(await T.providerAccounts()).accounts.find(Z=>Z.id===D.id);V&&await T.removeProviderAccount(D.id,V.revision)}catch{}}return U.state!=="connected"&&m(U.message),U}catch(D){return m(D instanceof pe?D.message:String(D)),null}finally{x(!1)}},L=(W,D,U)=>{if(W.length<=1){O(D(W[0]??""),U);return}y({models:W,make:D,label:U})},E=W=>{if(W===o)return;C==null||C.close(),I((W==="free"||W==="chatgpt")&&typeof window.open=="function"?window.open("","_blank"):null),m(null),y(null),h("key"),c(W)},$=()=>{C==null||C.close(),I(null),y(null),m(null),c(null)},_=jA(j,g),B=["free",...N?["claude"]:[],...k?["chatgpt"]:[],"key","local"];let M=null;return w?M=n.jsxs(n.Fragment,{children:[n.jsx(We,{children:n.jsx(Qe,{children:P.brain.model.ask})}),p?n.jsx(Ts,{line:P.brain.checking.service}):d?n.jsx(We,{children:n.jsx(Qe,{children:d})}):null,n.jsx(FH,{busy:p,models:w.models,onBack:$,onUse:W=>void O(w.make(W),w.label)})]}):o==="key"?M=n.jsxs(n.Fragment,{children:[n.jsx(ls,{label:P.brain.keyKinds.label,value:u,onChange:W=>{m(null),h(W)},options:[{value:"key",label:P.brain.keyKinds.key},...S?[{value:"gemini",label:P.brain.keyKinds.gemini}]:[],{value:"service",label:P.brain.keyKinds.service}]}),u==="gemini"&&S?n.jsx(UH,{busy:p,problem:d,preset:S,onBack:$,onUse:O},"gemini"):u==="service"?n.jsx(WH,{busy:p,problem:d,address:(j==null?void 0:j.cloudBaseUrl)??"",onBack:$,onOffer:L,onTrial:z,onUse:O},"service"):n.jsx(zH,{busy:p,problem:d,onBack:$,onUse:O},"key")]}):o==="local"?M=n.jsx(BH,{busy:p,problem:d,probe:j,mlxh:g,onBack:$,onOffer:L,onUse:O}):o==="free"?M=n.jsx(KH,{...e,busy:p,consent:C,onBack:$,onConnected:A}):o==="chatgpt"?M=n.jsx(YH,{...e,busy:p,consent:C,onBack:$,onConnected:A}):o==="claude"&&(M=n.jsx(QH,{...e,busy:p,problem:d,onBack:$,onConnected:A})),n.jsxs(n.Fragment,{children:[n.jsx(fl,{children:P.brain.title}),n.jsx(We,{children:n.jsx(Qe,{children:P.brain.ask})}),n.jsx("div",{className:"wiz-grid",role:"group","aria-label":P.brain.ask,children:B.map(W=>{const D=_H[W],U=P.brain.cards[W];return n.jsxs("button",{type:"button",className:"wiz-opt","aria-pressed":o===W,"data-wide":D.wide?"true":void 0,onClick:()=>E(W),children:[n.jsx("span",{className:"wiz-glyph","data-tone":D.tone,"aria-hidden":"true",children:n.jsx(we,{name:D.icon})}),n.jsxs("span",{children:[n.jsx("span",{className:"wiz-opt-title",children:U.title}),n.jsx("span",{className:"wiz-opt-line",children:W==="local"?_:U.line}),"pill"in U?n.jsx(ge,{tone:"good",children:U.pill}):null]})]},W)})}),M,M===null&&s.brain?n.jsxs(We,{children:[n.jsx(Qe,{children:s.brain.freeTier?P.brain.worksOnFlash(s.brain.model):P.brain.works(s.brain.model)}),n.jsx(VH,{...e})]}):null,M===null?n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:l}),n.jsx(hl,{onClick:()=>s.brain&&r(s),disabled:!s.brain,children:P.brain.submit})]})}):null]})}function FH({busy:e,models:t,onBack:s,onUse:r}){const[i,a]=f.useState(t[0]??"");return n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:s,disabled:e}),n.jsx(R,{variant:"accent",size:"lg",disabled:e||i==="",onClick:()=>r(i),children:P.brain.model.submit})]}),children:n.jsx(ee,{label:P.brain.model.label,grow:!0,children:n.jsx("select",{value:i,onChange:l=>a(l.target.value),children:t.map(l=>n.jsx("option",{value:l,children:l},l))})})})}function vA({models:e,picked:t,disabled:s,onPick:r}){return n.jsx(ee,{label:P.brain.model.label,grow:!0,children:n.jsx("select",{value:t,disabled:s,onChange:i=>r(i.target.value),children:e.map(i=>n.jsx("option",{value:i,children:i},i))})})}function zH({busy:e,problem:t,onBack:s,onUse:r}){const i=dl(),[a,l]=f.useState(""),[o,c]=f.useState(null),[u,h]=f.useState(!1),[d,m]=f.useState([]),[p,x]=f.useState(""),[j,b]=f.useState(!1),g=e||u,v=!j&&t!==null&&d.length>0,w=o??AH(a),y=()=>{const N=a.trim();N===""||g||(h(!0),b(!1),(async()=>{var I;let k=w==="anthropic"?"claude-sonnet-5":"gpt-5",S=d;if(v&&p!=="")k=p;else try{const A=await T.probeModels({kind:w,auth:"api-key",secret:N});k=((I=A.models.find(O=>O.isDefault))==null?void 0:I.id)??k,S=A.models.map(O=>O.id)}catch{S=[]}h(!1);const C=await r({label:w==="anthropic"?P.brain.key.anthropic:P.brain.key.openai,kind:w,auth:"api-key",baseUrl:"",defaultModel:k,enabled:!0,secret:N},w==="anthropic"?P.brain.key.anthropic:P.brain.key.openai);if(!(!C||C.state==="connected")){if(nx(C)){b(!0),m([]);return}m(S.includes(k)||S.length===0?S:[k,...S]),x(k)}})())};return n.jsxs(n.Fragment,{children:[g?n.jsx(We,{children:n.jsx(Ts,{line:P.brain.checking.key})}):j?n.jsx(We,{children:n.jsx(Qe,{children:P.brain.key.refused})}):t?n.jsx(We,{children:n.jsx(Qe,{children:t})}):null,n.jsxs(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:s,disabled:g}),n.jsx(R,{variant:"accent",size:"lg",disabled:g||a.trim()==="",onClick:y,children:v?P.brain.model.retry:P.brain.key.submit})]}),children:[n.jsx(ee,{label:P.brain.key.field,grow:!0,children:n.jsx("input",{ref:i,type:"password",autoComplete:"off",spellCheck:!1,placeholder:P.brain.key.placeholder,value:a,onChange:N=>{l(N.target.value),m([])},onKeyDown:N=>{N.key==="Enter"&&(N.preventDefault(),y())}})}),v?n.jsx(vA,{models:d,picked:p,disabled:g,onPick:x}):null,n.jsxs("button",{type:"button",className:"wiz-link",onClick:()=>c(w==="anthropic"?"openai":"anthropic"),children:[w==="anthropic"?P.brain.key.anthropic:P.brain.key.openai," · ",P.brain.key.which]})]})]})}function UH({busy:e,problem:t,preset:s,onBack:r,onUse:i}){const a=dl(),[l,o]=f.useState(""),[c,u]=f.useState(!1),[h,d]=f.useState([]),[m,p]=f.useState(""),x=e||c,j=t!==null&&h.length>0,b=()=>{const g=l.trim();g===""||x||(u(!0),(async()=>{let v=cE,w;if(j&&m!=="")v=m;else try{const N=(await T.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,secret:g})).models.map(k=>k.id);v=uE(N)??v,w=hE(v)?dE(N):void 0,d(r5(N)),p(w??v)}catch{}u(!1),await i({label:P.brain.gemini.label,kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,defaultModel:v,enabled:!0,secret:g},P.brain.gemini.label,w)})())};return n.jsxs(n.Fragment,{children:[x?n.jsx(We,{children:n.jsx(Ts,{line:P.brain.checking.gemini})}):t?n.jsx(We,{children:n.jsx(Qe,{children:t})}):null,n.jsxs(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:r,disabled:x}),n.jsx(R,{variant:"accent",size:"lg",disabled:x||l.trim()==="",onClick:b,children:P.brain.gemini.submit})]}),children:[n.jsx(ee,{label:P.brain.gemini.field,grow:!0,children:n.jsx("input",{ref:a,type:"password",autoComplete:"off",spellCheck:!1,placeholder:P.brain.gemini.placeholder,value:l,onChange:g=>o(g.target.value),onKeyDown:g=>{g.key==="Enter"&&(g.preventDefault(),b())}})}),j?n.jsx(ee,{label:P.brain.model.label,grow:!0,children:n.jsx("select",{value:m,disabled:x,onChange:g=>p(g.target.value),children:h.map(g=>n.jsx("option",{value:g,children:g},g))})}):null,n.jsx("a",{className:"wiz-link",href:s.keyUrl,target:"_blank",rel:"noreferrer",children:P.brain.gemini.get})]})]})}function jA(e,t){return e===null||t===null?P.brain.local.looking:!e.running&&!t.running?P.brain.local.missing:P.brain.local.found({...e.running?{ollama:e.models.length}:{},...t.running?{mlxh:t.models.length}:{}})}function BH({busy:e,problem:t,probe:s,mlxh:r,onBack:i,onOffer:a,onUse:l}){const o=(s==null?void 0:s.models)??[],c=Rp(r),u=()=>{!(r!=null&&r.running)||!c||l({label:P.brain.mlxh.label,kind:"openai-compatible",auth:"none",baseUrl:r.baseUrl,defaultModel:c,enabled:!0},P.brain.mlxh.label)},h=s!==null&&r!==null&&!s.running&&!r.running,d=()=>{s&&a(o,m=>({label:P.brain.ollama.label,kind:"openai-compatible",auth:"none",baseUrl:s.baseUrl,defaultModel:m,enabled:!0}),P.brain.ollama.label)};return n.jsxs(n.Fragment,{children:[e?n.jsx(We,{children:n.jsx(Ts,{line:P.brain.checking.ollama})}):t?n.jsx(We,{children:n.jsx(Qe,{children:t})}):null,n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:i,disabled:e}),s!=null&&s.running?n.jsx(R,{variant:r!=null&&r.running?void 0:"accent",size:"lg",disabled:e||o.length===0,onClick:d,children:P.brain.ollama.connect}):null,r!=null&&r.running?n.jsx(R,{variant:"accent",size:"lg",disabled:e||!c,onClick:u,children:P.brain.mlxh.connect}):null,h&&s?n.jsx(Zt,{variant:"accent",size:"lg",href:s.downloadUrl,target:"_blank",rel:"noreferrer",children:P.brain.ollama.download}):null]}),children:n.jsxs("span",{className:"wiz-foot",children:[jA(s,r),r!=null&&r.running&&!c?` ${P.brain.mlxh.noBrain}`:"",h&&(r!=null&&r.baseUrl)?` ${GC(r.baseUrl)}`:""]})})]})}function WH({busy:e,problem:t,address:s,onBack:r,onOffer:i,onTrial:a,onUse:l}){const o=dl(),[c,u]=f.useState(s),[h,d]=f.useState(""),[m,p]=f.useState(!1),[x,j]=f.useState([]),[b,g]=f.useState(""),[v,w]=f.useState(!1),y=e||m,N=!v&&t!==null&&x.length>0,k=()=>{c.trim()===""||y||(p(!0),w(!1),(async()=>{var $;const S=h.trim()?"api-key":"none",C=_=>({label:P.brain.service.label,kind:"openai-compatible",auth:S,baseUrl:c.trim(),defaultModel:_,enabled:!0,...h.trim()?{secret:h.trim()}:{}}),I=(_,B,M)=>{if(!(!_||_.state==="connected")){if(nx(_)){w(!0),j([]);return}j(B),g(M)}};if(S==="api-key"&&N&&b!==""){p(!1),I(await l(C(b),P.brain.service.label),x,b);return}let A=[],O;try{const _=await T.probeModels({kind:"openai-compatible",auth:S,baseUrl:c.trim(),...h.trim()?{secret:h.trim()}:{}});A=_.models.map(B=>B.id),O=($=_.models.find(B=>B.isDefault))==null?void 0:$.id}catch{}p(!1);const z=O?[O]:A;if(S==="none"){i(z,C,P.brain.service.label);return}const L=z[0]??"";if(z.length<=1){I(await l(C(L),P.brain.service.label),A,L);return}const E=await a(C(L));(E==null?void 0:E.state)==="connected"?i(z,C,P.brain.service.label):I(E,A,L)})())};return n.jsxs(n.Fragment,{children:[y?n.jsx(We,{children:n.jsx(Ts,{line:P.brain.checking.service})}):v?n.jsx(We,{children:n.jsx(Qe,{children:P.brain.key.refused})}):t?n.jsx(We,{children:n.jsx(Qe,{children:t})}):null,n.jsxs(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:r,disabled:y}),n.jsx(R,{variant:"accent",size:"lg",disabled:y||c.trim()==="",onClick:k,children:N?P.brain.model.retry:P.brain.service.submit})]}),children:[n.jsx(ee,{label:P.brain.service.address,grow:!0,children:n.jsx("input",{ref:o,value:c,placeholder:P.brain.service.addressPlaceholder,onChange:S=>{u(S.target.value),j([])}})}),n.jsx(ee,{label:P.brain.service.key,children:n.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,value:h,onChange:S=>{d(S.target.value),j([])}})}),N?n.jsx(vA,{models:x,picked:b,disabled:y,onPick:g}):null]})]})}const HH=2e3;function KH({busy:e,consent:t,onBack:s,onConnected:r,accounts:i}){const[a,l]=f.useState(!0),[o,c]=f.useState(null),[u,h]=f.useState(null),[d,m]=f.useState(0),p=f.useRef(-1),x=f.useRef(null),j=P.brain.cloud.label;f.useEffect(()=>{if(p.current===d)return;p.current=d,l(!0),c(null);const g=d===0?t:x.current;(async()=>{try{const v=((i==null?void 0:i.accounts)??[]).find(k=>k.auth==="device-key"),w=v?{id:v.id}:await T.saveProviderAccount({label:j,kind:"openai-compatible",auth:"device-key",baseUrl:"",defaultModel:cu,enabled:!0}),y=(await T.providerAccounts()).accounts.find(k=>k.id===w.id),N=await T.ollamaConnect(y.id,y.revision);h({id:y.id,attemptId:N.attemptId,url:N.verificationUrl}),g&&(g.location.href=N.verificationUrl)}catch(v){g==null||g.close(),c(v instanceof pe?v.message:String(v))}finally{l(!1)}})()},[d]),f.useEffect(()=>{if(!u)return;let g=!1,v=!1;const w=async()=>{if(!(g||v)){v=!0;try{const N=await T.ollamaPoll(u.id,u.attemptId);if(g||N.state==="waiting")return;if(g=!0,h(null),N.state==="failed"){c(N.message);return}l(!0),c(await b(u.id)),l(!1)}catch{}finally{v=!1}}},y=window.setInterval(()=>void w(),HH);return()=>{g=!0,window.clearInterval(y)}},[u]);const b=async g=>{try{const v=(await T.accountModels(g).catch(()=>({models:[]}))).models.map(k=>k.id),w=v.length===0||v.includes(cu)?cu:v[0],y=(await T.providerAccounts()).accounts.find(k=>k.id===g);y&&y.defaultModel!==w&&await T.saveProviderAccount({id:y.id,revision:y.revision,label:y.label,kind:y.kind,auth:y.auth,baseUrl:y.baseUrl,defaultModel:w,enabled:y.enabled});const N=await T.testProviderAccount(g);return N.state!=="connected"?N.message:await r({accountId:g,label:j,model:w})}catch(v){return v instanceof pe?v.message:String(v)}};return n.jsxs(n.Fragment,{children:[a||e?n.jsx(We,{children:n.jsx(Ts,{line:P.brain.checking.cloud})}):o?n.jsx(We,{children:n.jsx(Qe,{children:o})}):u?n.jsx(We,{children:n.jsx(Qe,{children:P.brain.cloud.waiting})}):null,n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:s,disabled:a||e}),u?n.jsx(Zt,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",children:P.brain.cloud.open}):o?n.jsx(R,{variant:"accent",size:"lg",disabled:a||e,onClick:()=>{x.current=typeof window.open=="function"?window.open("","_blank"):null,m(g=>g+1)},children:P.brain.cloud.again}):null]})})]})}function VH({answers:e,accounts:t,onKept:s,onTrouble:r}){var p;const i=e.brain,a=i?((t==null?void 0:t.accounts)??[]).find(x=>x.id===i.accountId):void 0,[l,o]=f.useState([]),[c,u]=f.useState(!1),h=rv(a),d=(a==null?void 0:a.auth)==="device-key"||(a==null?void 0:a.kind)==="codex"||h||!!a&&i5(a,(p=t==null?void 0:t.gemini)==null?void 0:p.baseUrl);if(f.useEffect(()=>{if(!d||!a)return;let x=!1;return T.accountModels(a.id).then(j=>{const b=h?j.models.filter(g=>!VC({id:g.id,...g.image?{kind:"image"}:{}})):j.models;x||o(b.map(g=>g.id))}).catch(()=>{}),()=>{x=!0}},[d,a==null?void 0:a.id]),!d||!a||!i||l.length<2)return null;const m=x=>{x===i.model||c||(u(!0),r(null),(async()=>{try{await T.saveProviderAccount({id:a.id,revision:a.revision,label:a.label,kind:a.kind,auth:a.auth,baseUrl:a.baseUrl,defaultModel:x,enabled:a.enabled}),e.assistant&&await T.bindBrain({accountId:a.id,model:x}),s({...e,brain:{accountId:i.accountId,label:i.label,model:x}})}catch(j){r(j instanceof pe?j.message:String(j))}finally{u(!1)}})())};return n.jsx(Qe,{children:n.jsx(ee,{label:P.brain.model.change,children:n.jsx("select",{value:i.model,disabled:c,onChange:x=>m(x.target.value),children:(l.includes(i.model)?l:[i.model,...l]).map(x=>n.jsx("option",{value:x,children:x},x))})})})}const wb="gpt-5.5",GH=2e3;function YH({busy:e,consent:t,onBack:s,onConnected:r,accounts:i}){const[a,l]=f.useState(!0),[o,c]=f.useState(null),[u,h]=f.useState(null),[d,m]=f.useState(0),p=f.useRef(-1),x=f.useRef(null),j=f.useRef(null),b=P.brain.chatgpt.label;f.useEffect(()=>()=>{const w=j.current;j.current=null,w&&T.codexAccountAction(w.id,"cancel-login",w.revision).catch(()=>{})},[]),f.useEffect(()=>{if(p.current===d)return;p.current=d,l(!0),c(null);const w=d===0?t:x.current;(async()=>{try{const y=((i==null?void 0:i.accounts)??[]).find(C=>C.kind==="codex"),N=y?{id:y.id}:await T.saveProviderAccount({label:b,kind:"codex",auth:"chatgpt",baseUrl:"",defaultModel:wb,enabled:!0}),k=(await T.providerAccounts()).accounts.find(C=>C.id===N.id),S=await T.codexAccountAction(k.id,"login",k.revision);if(!(S!=null&&S.verificationUrl)||!S.userCode)throw new Error((S==null?void 0:S.message)??P.brain.chatgpt.failed);j.current={id:k.id,revision:k.revision},h({id:k.id,revision:k.revision,url:S.verificationUrl,code:S.userCode}),w&&(w.location.href=S.verificationUrl)}catch(y){w==null||w.close(),c(y instanceof pe||y instanceof Error?y.message:String(y))}finally{l(!1)}})()},[d]),f.useEffect(()=>{if(!u)return;let w=!1,y=!1;const N=async()=>{if(!(w||y)){y=!0;try{const S=(await T.providerAccounts()).accounts.find(I=>I.id===u.id);if(w)return;const C=S==null?void 0:S.login;if(!C||C.state==="pending")return;if(w=!0,j.current=null,h(null),C.state!=="connected"){c(C.message??P.brain.chatgpt.failed);return}l(!0),c(await g(u.id)),l(!1)}catch{}finally{y=!1}}},k=window.setInterval(()=>void N(),GH);return()=>{w=!0,window.clearInterval(k)}},[u]);const g=async w=>{var y,N;try{const k=(await T.accountModels(w).catch(()=>({models:[]}))).models,S=((y=k.find(I=>I.isDefault))==null?void 0:y.id)??((N=k[0])==null?void 0:N.id)??wb,C=(await T.providerAccounts()).accounts.find(I=>I.id===w);return C&&C.defaultModel!==S&&await T.saveProviderAccount({id:C.id,revision:C.revision,label:C.label,kind:C.kind,auth:C.auth,baseUrl:C.baseUrl,defaultModel:S,enabled:C.enabled}),await r({accountId:w,label:b,model:S})}catch(k){return k instanceof pe?k.message:String(k)}},v=()=>{const w=j.current;j.current=null,w&&T.codexAccountAction(w.id,"cancel-login",w.revision).catch(()=>{}),s()};return n.jsxs(n.Fragment,{children:[a||e?n.jsx(We,{children:n.jsx(Ts,{line:P.brain.checking.chatgpt})}):o?n.jsx(We,{children:n.jsx(Qe,{children:o})}):u?n.jsx(We,{children:n.jsxs(Qe,{children:[P.brain.chatgpt.codeBefore,n.jsx("strong",{children:u.code}),P.brain.chatgpt.codeAfter]})}):null,n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:v,disabled:a||e}),u?n.jsx(Zt,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",children:P.brain.chatgpt.open}):o?n.jsx(R,{variant:"accent",size:"lg",disabled:a||e,onClick:()=>{x.current=typeof window.open=="function"?window.open("","_blank"):null,m(w=>w+1)},children:P.brain.chatgpt.again}):null]}),children:u?n.jsx(lv,{code:u.code,label:P.brain.chatgpt.code}):null})]})}const qH="claude-sonnet-5";function QH({busy:e,problem:t,onBack:s,onConnected:r,accounts:i,claudeModel:a}){const[l,o]=f.useState(!1),[c,u]=f.useState(null),[h,d]=f.useState(null),[m,p]=f.useState(""),x=f.useRef(null);f.useEffect(()=>()=>{const w=x.current;x.current=null,w&&T.anthropicAccountAction(w.id,"cancel-login",w.revision).catch(()=>{})},[]);const j=()=>{const w=x.current;x.current=null,w&&T.anthropicAccountAction(w.id,"cancel-login",w.revision).catch(()=>{}),s()},b=a??qH,g=()=>{o(!0),u(null);const w=typeof window.open=="function"?window.open("","_blank"):null;(async()=>{try{const y=((i==null?void 0:i.accounts)??[]).find(I=>I.auth==="anthropic-oauth"),N=y?{id:y.id}:await T.saveProviderAccount({label:P.brain.claude.label,kind:"anthropic",auth:"anthropic-oauth",baseUrl:"",defaultModel:b,enabled:!0}),S=(await T.providerAccounts()).accounts.find(I=>I.id===N.id),C=await T.anthropicAccountAction(S.id,"login",S.revision);x.current={id:S.id,revision:S.revision+1},d({id:S.id,revision:S.revision+1,url:C.verificationUrl??"",attemptId:C.attemptId??""}),w&&C.verificationUrl?w.location.href=C.verificationUrl:w==null||w.close()}catch(y){w==null||w.close(),u(y instanceof pe?y.message:String(y))}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"){u(w.message);return}u(await r({accountId:h.id,label:P.brain.claude.label,model:b}))}catch(w){u(w instanceof pe?w.message:String(w))}finally{o(!1)}})())};return n.jsxs(n.Fragment,{children:[l||e?n.jsx(We,{children:n.jsx(Ts,{line:P.brain.checking.claude})}):t??c?n.jsx(We,{children:n.jsx(Qe,{children:t??c})}):null,h?n.jsxs(n.Fragment,{children:[n.jsx(We,{children:n.jsx(Qe,{children:P.brain.claude.waiting})}),n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:j,disabled:l}),n.jsx(Zt,{size:"lg",href:h.url,target:"_blank",rel:"noreferrer",children:P.brain.claude.open}),n.jsx(R,{variant:"accent",size:"lg",disabled:l||m.trim()==="",onClick:v,children:P.brain.claude.finish})]}),children:n.jsx(ee,{label:P.brain.claude.paste,grow:!0,children:n.jsx(JH,{value:m,onChange:p})})})]}):n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:j,disabled:e||l}),n.jsx(R,{variant:"accent",size:"lg",disabled:e||l,onClick:g,children:P.brain.claude.start})]})})]})}function JH({value:e,onChange:t}){const s=dl();return n.jsx("input",{ref:s,type:"password",autoComplete:"off",spellCheck:!1,value:e,onChange:r=>t(r.target.value)})}const XH={days:"calendar",mail:"mail",money:"money",voice:"bulb",code:"monitor",pictures:"files"};function ZH(e){const t=(e==null?void 0:e.plugins)??[];if(t.length===0)return null;const s=t.map(i=>i.title),r=t.filter(i=>i.state==="failed");if(e!=null&&e.running){const i=t.filter(a=>a.state==="ready"||a.state==="failed").length;return{line:P.takeOn.fetching(s,Math.min(i+1,t.length),t.length),done:!1}}return r.length>0?{line:r.map(i=>P.takeOn.failed(i.title,i.reason??"")).join(" "),done:!0}:{line:P.takeOn.ready(s),done:!0}}function eK({answers:e,progress:t,onProgress:s,onSettled:r,onBack:i,onTrouble:a}){const[l,o]=f.useState(()=>e.takeOn??[...ZD]),[c,u]=f.useState(!1),h=Ra.filter(x=>l.includes(x.id)),d=x=>o(j=>j.includes(x)?j.filter(b=>b!==x):[...j,x]),m=x=>{c||(u(!0),Promise.resolve().then(()=>T.takeOn(x)).then(()=>{s(),r({...e,takeOn:x})}).catch(j=>a(j instanceof pe?j.message:String(j))).finally(()=>u(!1)))},p=ZH(t);return n.jsxs(n.Fragment,{children:[n.jsx(fl,{children:P.takeOn.title}),n.jsx(We,{children:n.jsx(Qe,{children:P.takeOn.ask})}),n.jsxs(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:i,disabled:c}),n.jsx(R,{variant:"ghost",size:"lg",disabled:c,onClick:()=>m([]),children:P.takeOn.none}),n.jsx(hl,{onClick:()=>m(Ra.filter(x=>l.includes(x.id)).map(x=>x.id)),disabled:c||l.length===0,children:P.takeOn.submit})]}),children:[n.jsx("div",{className:"wiz-grid","data-cols":"3",role:"group","aria-label":P.takeOn.title,children:Ra.map(x=>{const j=l.includes(x.id);return n.jsxs("button",{type:"button",className:"wiz-opt","data-tile":"true","aria-pressed":j,onClick:()=>d(x.id),children:[n.jsxs("span",{className:"wiz-tile-top",children:[n.jsx("span",{className:"wiz-glyph","aria-hidden":"true",children:n.jsx(we,{name:XH[x.id]})}),n.jsx("span",{className:"wiz-tick","aria-hidden":"true",children:j?n.jsx(we,{name:"check",size:12}):null})]}),n.jsxs("span",{children:[n.jsx("span",{className:"wiz-opt-title",children:x.title}),n.jsx("span",{className:"wiz-opt-plugins",children:x.plugins})]}),n.jsx("span",{className:"wiz-opt-line",children:x.line})]},x.id)})}),h.length>0?n.jsxs("div",{className:"wiz-stack",children:[p?n.jsxs("div",{className:"wiz-busy","data-boxed":"true",role:"status",children:[n.jsxs("span",{className:"wiz-pulse","data-done":p.done?"true":void 0,"aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]}),n.jsx("span",{children:p.line}),l.includes("mail")?n.jsx("span",{className:"wiz-busy-side",children:P.takeOn.builtIn}):null]}):null,n.jsx("div",{className:"wiz-foot",children:h.map(x=>x.note).join(" ")})]}):n.jsx("div",{className:"wiz-foot",children:P.takeOn.nothing})]})]})}function tK({answers:e,navigate:t,onSettled:s,onBack:r}){var x,j,b;const[i,a]=f.useState(((x=e.reach)==null?void 0:x.phone)===!0),[l,o]=f.useState(((j=e.reach)==null?void 0:j.mailbox)===!0),[c,u]=f.useState(((b=e.reach)==null?void 0:b.app)===!0),[h,d]=f.useState(e.browser),m=(e.takeOn??[]).includes("mail"),p=()=>{const g={phone:i,mailbox:l,app:c,browser:h==="chrome"||h==="chromium"||h==="installed"};h!==void 0&&Promise.resolve().then(()=>T.onboardingStep("browser")).catch(()=>{}),s({...e,reach:g,...h!==void 0?{browser:h}:{}})};return n.jsxs(n.Fragment,{children:[n.jsx(fl,{children:P.reach.title}),n.jsx(We,{children:n.jsx(Qe,{children:P.reach.ask})}),n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:r}),n.jsx(hl,{onClick:p,children:P.reach.submit})]}),children:n.jsxs("div",{className:"wiz-rows",children:[n.jsx(nK,{paired:i,onPaired:()=>a(!0)}),n.jsx(rK,{wanted:m,added:l,onAdded:o,navigate:t,timezone:e.clock??"UTC"}),n.jsx(iK,{app:c,onApp:()=>u(!0),browser:h,onBrowser:d}),i?n.jsx(H,{tone:"good",role:"status",children:P.reach.phone.hello}):null]})})]})}function nK({paired:e,onPaired:t}){const[s,r]=f.useState(null),[i,a]=f.useState(!1),l=f.useRef(t);l.current=t,f.useEffect(()=>{let c=!1;return Promise.resolve().then(()=>T.telegram()).then(u=>{c||!u||(r(u),u.paired&&l.current())}).catch(()=>{c||r({configured:!1,running:!1,paired:!1})}),()=>{c=!0}},[]);const o=(s==null?void 0:s.configured)===!0&&s.running===!0&&!e;return n.jsxs("div",{className:"wiz-row",children:[n.jsx("span",{className:"wiz-glyph","aria-hidden":"true",children:n.jsx(we,{name:"chat"})}),n.jsxs("span",{className:"wiz-row-text",children:[n.jsx("span",{className:"wiz-opt-title",children:P.reach.phone.title}),n.jsx("span",{className:"wiz-opt-line",children:P.reach.phone.line})]}),e?n.jsx("span",{className:"wiz-row-side",children:n.jsx(ge,{tone:"good",dot:!0,children:P.reach.phone.paired})}):o?n.jsx(sK,{onPaired:t}):n.jsx("span",{className:"wiz-row-side",children:n.jsx(R,{size:"lg",disabled:s===null,onClick:()=>a(!0),children:P.reach.phone.setUp})}),i?n.jsx(wt,{title:P.telegram.sheet,onClose:()=>a(!1),children:n.jsx(dK,{onPaired:t,onDismiss:()=>a(!1)})}):null]})}function sK({onPaired:e}){const{offer:t,square:s,paired:r,stale:i,ask:a}=bv(()=>T.telegram().then(o=>o.paired),e),l=f.useRef(!1);return f.useEffect(()=>{l.current||(l.current=!0,a().catch(()=>{}))},[a]),r?n.jsx("span",{className:"wiz-row-side",children:n.jsx(ge,{tone:"good",dot:!0,children:P.reach.phone.paired})}):i||!t?n.jsx("span",{className:"wiz-row-side",children:n.jsx(R,{size:"lg",onClick:()=>void a().catch(()=>{}),children:P.telegram.newCode})}):n.jsx("span",{className:"wiz-qr-slot",children:n.jsx(kv,{offer:t,square:s})})}function rK({wanted:e,added:t,onAdded:s,navigate:r,timezone:i}){const[a,l]=f.useState(void 0),[o,c]=f.useState(!1),[u,h]=f.useState(null),d=f.useCallback(()=>{Promise.resolve().then(()=>T.pageQuery("email","accounts")).then(m=>{var x,j,b;const p=((b=(j=(x=m==null?void 0:m.data)==null?void 0:x.accounts)==null?void 0:j[0])==null?void 0:b.address)??null;h(p),s(p!==null)}).catch(()=>{})},[]);return f.useEffect(()=>{let m=!1;return Promise.resolve().then(()=>T.pages()).then(p=>{if(m)return;const x=((p==null?void 0:p.pages)??[]).filter(b=>b.plugin==="email"),j=x.find(b=>b.id==="settings")??null;l(j?{page:j,siblings:x}:null)}).catch(()=>{m||l(null)}),d(),()=>{m=!0}},[d]),n.jsxs("div",{className:"wiz-row",children:[n.jsx("span",{className:"wiz-glyph","data-tone":"mail","aria-hidden":"true",children:n.jsx(we,{name:"mail"})}),n.jsxs("span",{className:"wiz-row-text",children:[n.jsx("span",{className:"wiz-opt-title",children:e?P.reach.mailbox.forTriage:P.reach.mailbox.title}),n.jsx("span",{className:"wiz-opt-line",children:a===null?P.reach.mailbox.unavailable:P.reach.mailbox.line})]}),n.jsx("span",{className:"wiz-row-side",children:t||u?n.jsx(ge,{tone:"good",dot:!0,mono:u!==null,children:u??P.reach.mailbox.added}):a?n.jsx(R,{size:"lg",onClick:()=>c(!0),children:P.reach.mailbox.add}):null}),o&&a?n.jsx(wt,{title:P.reach.mailbox.sheet,size:"wide",onClose:()=>{c(!1),d()},children:n.jsx(nv,{page:a.page,siblings:a.siblings,navigate:r,timezone:i,embedded:!0})}):null]})}function iK({app:e,onApp:t,browser:s,onBrowser:r}){const i=uB(),a=typeof navigator>"u"?null:nE(navigator.userAgent),[l,o]=f.useState(null),[c,u]=f.useState("idle"),[h,d]=f.useState(null),[m,p]=f.useState(null),[x,j]=f.useState(void 0),b=f.useRef(!1),g=f.useRef(!0);f.useEffect(()=>(g.current=!0,Promise.resolve().then(()=>T.browser()).then(C=>{var A;if(!g.current)return;const I=C==null?void 0:C.browser;I?((A=I.install)==null?void 0:A.state)==="running"?(o("none"),b.current=!0,u("installing"),y()):o(I.engine):o("other")}).catch(()=>{g.current&&o("other")}),()=>{g.current=!1}),[]);const v=(C,I)=>{g.current&&(b.current=!1,u("failed"),d(C),p(I??null))},w=async C=>{u("launching");let I;try{I=await T.browserCheck()}catch(A){return v(A instanceof pe?A.message:String(A))}if(g.current){if(I.ok){u("idle"),o(C),r(b.current?"installed":C);return}v(I.message,I.command)}},y=async()=>{var A,O;let C;try{C=await T.browser()}catch(z){return v(z instanceof pe?z.message:String(z))}if(!g.current)return;const I=C.browser;if(!I)return v(P.browser.failed(""));if(((A=I.install)==null?void 0:A.state)==="running"){u("installing"),j(I.install.progress),window.setTimeout(()=>void y(),1e3);return}return I.engine!=="none"?w(I.engine):v(((O=I.install)==null?void 0:O.line)??"")},N=()=>{if(p(null),l==="chrome"||l==="chromium"){w(l);return}b.current=!0,u("installing"),j(void 0),Promise.resolve().then(()=>T.browserInstall()).then(()=>{g.current&&window.setTimeout(()=>void y(),1e3)}).catch(C=>v(C instanceof pe?C.message:String(C)))},k=s==="chrome"||s==="chromium"||s==="installed",S=c==="installing"||c==="launching";return n.jsxs("div",{className:"wiz-row","data-wrap":c!=="idle"?"true":void 0,children:[n.jsx("span",{className:"wiz-glyph","data-tone":"good","aria-hidden":"true",children:n.jsx(we,{name:"globe"})}),n.jsxs("span",{className:"wiz-row-text",children:[n.jsx("span",{className:"wiz-opt-title",children:P.reach.app.title}),n.jsx("span",{className:"wiz-opt-line",children:P.reach.app.line})]}),n.jsxs("span",{className:"wiz-row-side",children:[e?n.jsx(ge,{tone:"good",dot:!0,children:P.reach.app.installed}):i?n.jsx(R,{size:"lg",onClick:()=>{i.prompt().then(()=>i.userChoice).then(C=>{(!C||C.outcome==="accepted")&&t()}).catch(()=>{})},children:P.reach.app.install}):null,k?n.jsx(ge,{tone:"good",dot:!0,children:P.reach.app.ready(s==="chrome"?"chrome":"chromium")}):l===null||l==="other"?null:n.jsx(R,{size:"lg",disabled:S,onClick:N,children:S?P.browser.installing:c==="failed"?P.browser.retry:l==="chrome"?P.reach.app.chrome:l==="chromium"?P.reach.app.chromium:P.reach.app.fetch})]}),!e&&!i&&a?n.jsx("span",{className:"wiz-row-note",children:a}):null,c==="installing"?n.jsxs("div",{className:"wiz-row-more",children:[n.jsx("span",{className:"wiz-opt-line",children:P.browser.needs}),n.jsx(q1,{progress:x})]}):c==="launching"?n.jsx("div",{className:"wiz-row-more",children:n.jsx(Ts,{line:P.browser.launching})}):c==="failed"?n.jsxs("div",{className:"wiz-row-more",children:[n.jsx("span",{className:"wiz-opt-line",children:P.browser.failed(h??"")}),m?n.jsx(oK,{command:m}):null]}):null]})}function aK({answers:e,existing:t,onSettled:s,onTrouble:r,onReload:i,onBack:a}){const[l,o]=f.useState(()=>(t==null?void 0:t.name)??VD),[c,u]=f.useState(()=>t!=null&&t.picture||t!=null&&t.avatar?null:"buddi"),[h,d]=f.useState(t?null:P.assistant.purposeValue),[m,p]=f.useState(t?"":P.assistant.purposeValue);f.useEffect(()=>{if(!t)return;let w=!1;return T.firstAgentPersona().then(y=>{w||(d(y.persona),p(y.persona))},y=>{w||r(y instanceof pe?y.message:String(y))}),()=>{w=!0}},[t==null?void 0:t.id]);const[x,j]=f.useState(!1),b=Ra.filter(w=>(e.takeOn??[]).includes(w.id)&&"mate"in w).map(w=>w.mate),g=Vw.find(w=>w.id===c),v=()=>{if(l.trim()===""||x)return;j(!0);const w=!t||h!==null&&m.trim()!==""&&m.trim()!==h.trim()?{instructions:m.trim()}:{},y=t?T.updateFirstAgent({name:l.trim(),...w}):T.createFirstAgent({name:l.trim(),handle:TH(l),description:"",...w,...e.brain?{accountId:e.brain.accountId}:{}});(async()=>{let N;try{N=await y}catch(S){r(S instanceof pe?S.message:String(S)),j(!1);return}let k=null;try{g&&await T.uploadAgentPicture(N.id,await qC(g.role))}catch(S){k=S instanceof pe?S.message:String(S)}j(!1),i(),s({...e,assistant:{id:N.id,name:l.trim(),avatar:g?"":(t==null?void 0:t.avatar)??""}}),k&&r(k)})()};return n.jsxs(n.Fragment,{children:[n.jsx(fl,{children:P.assistant.title}),n.jsx(We,{children:n.jsxs(Qe,{children:[P.assistant.ask,b.length>0?P.assistant.team(b):""]})}),n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:a,disabled:x}),n.jsx(hl,{onClick:v,disabled:x||l.trim()===""||h===null,children:P.assistant.submit})]}),children:n.jsxs("div",{className:"wiz-meet",children:[n.jsxs("div",{className:"wiz-face",children:[n.jsx("span",{className:"wiz-face-tile","data-agent":(g==null?void 0:g.id)??"buddi","aria-hidden":"true",children:g?n.jsx("img",{src:Yi(g.role),alt:""}):t!=null&&t.picture?n.jsx("img",{src:t.picture,alt:""}):n.jsx("span",{className:"wiz-face-emoji",children:(t==null?void 0:t.avatar)??""})}),n.jsx("div",{className:"wiz-swatches",role:"group","aria-label":P.assistant.colour,children:Vw.map(w=>n.jsx("button",{type:"button",className:"wiz-swatch","data-agent":w.id,"aria-label":P.assistant.swatch(w.label),"aria-pressed":c===w.id,onClick:()=>u(w.id)},w.id))}),n.jsx("span",{className:"wiz-face-cap",children:P.assistant.colour})]}),n.jsxs("div",{className:"wiz-stack",children:[n.jsx(ee,{label:P.assistant.name,children:n.jsx("input",{value:l,maxLength:60,onChange:w=>o(w.target.value)})}),n.jsx(ee,{label:P.assistant.purpose,hint:P.assistant.purposeHint,children:n.jsx("textarea",{className:"wiz-persona",value:m,maxLength:8e3,rows:7,onChange:w=>p(w.target.value)})})]})]})})]})}function lK({answers:e,assistantAgent:t,met:s,onMet:r,navigate:i,onPickAnotherBrain:a,onSpoken:l,progress:o,onProgress:c}){var $;const u=e.assistant,[h,d]=f.useState(s),[m,p]=f.useState([]),[x,j]=f.useState(!1),[b,g]=f.useState(!1),[v,w]=f.useState(!0),[y,N]=f.useState(!1),k=f.useRef(!1),S=f.useMemo(()=>t?[t]:[],[t]);f.useEffect(()=>{c()},[]),f.useEffect(()=>{if(!u||k.current)return;if(k.current=!0,s){d(s);return}let _=!1;return(async()=>{try{const B=await Le.startConversation(u.id);if(_)return;d(B.conversationId),r(B.conversationId),await T.onboardingStep(hA.handover,{conversationId:B.conversationId}).catch(()=>{}),await Le.send(u.id,{conversationId:B.conversationId,text:QD,opening:!0})}catch{_||(w(!1),j(!0))}})(),()=>{_=!0}},[u==null?void 0:u.id,s]),f.useEffect(()=>{if(!h)return;let _=!1;const B=Date.now(),M=()=>{Le.conversation(h).then(D=>{if(_)return;p(D.messages);const U=Date.now()-B;if(D.messages.some(yb)){w(!1),j(!1),g(!1);return}const V=D.runs??[],Z=V.some(Ae=>Ae.finishedAt===null),ue=V.length>0&&!Z;g(Z&&U>=RH),(ue||U>=IH)&&(w(!1),j(!0))}).catch(()=>{})};M();const W=window.setInterval(M,xA);return()=>{_=!0,window.clearInterval(W)}},[h]);const C=u&&h?Ve(u.id,h):null,I=m.some(yb);f.useEffect(()=>{I&&C&&l(C)},[I,C,l]);const A=e.takeOn??[],O=Ra.filter(_=>A.includes(_.id)&&"mate"in _).map(_=>_.mate),z=P.handover.starters({days:A.includes("days"),mail:A.includes("mail"),mailbox:(($=e.reach)==null?void 0:$.mailbox)===!0},O),L=(o==null?void 0:o.waiting)??[],E=_=>{!u||!h||y||(N(!0),Promise.resolve().then(()=>Le.send(u.id,{conversationId:h,text:_})).then(()=>i(Ve(u.id,h),!0)).catch(()=>N(!1)))};return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"wiz-hello",children:n.jsx(Fx,{messages:m,live:[],now:Date.now(),onOpen:()=>{},working:v,agents:S,agentName:(u==null?void 0:u.name)??"",...u?{agentId:u.id}:{},emptyHint:P.handover.waiting,plain:!0,workingLine:P.handover.looking((u==null?void 0:u.name)??"")})}),b&&!x?n.jsx(We,{children:n.jsx(Qe,{children:P.handover.slow})}):null,x?n.jsxs(n.Fragment,{children:[n.jsx(We,{children:n.jsx(Qe,{children:P.handover.silent})}),n.jsx(Ft,{actions:n.jsx(hl,{onClick:a,children:P.handover.again})})]}):null,I?n.jsx("div",{className:"wiz-starters",role:"group","aria-label":P.handover.starterLabel,children:z.map(_=>n.jsx("button",{type:"button",className:"wiz-starter",disabled:y,onClick:()=>E(_),children:_},_))}):null,I&&L.length>0?n.jsx(H,{tone:"warm",title:P.handover.waitingTitle(L.length),action:n.jsx(R,{variant:"accent",onClick:()=>i(Kt,!0),children:P.handover.home}),children:P.handover.waitingBody(L)}):null,I&&C?n.jsx(Ft,{actions:n.jsx(Zt,{variant:"accent",size:"lg",href:C,onClick:_=>{_.preventDefault(),i(C,!0)},children:P.done.open})}):null]})}function oK({command:e}){const[t,s]=f.useState("idle"),r=()=>{var i;if(!((i=navigator.clipboard)!=null&&i.writeText)){s("failed");return}navigator.clipboard.writeText(e).then(()=>s("done"),()=>s("failed"))};return n.jsxs(J,{gap:"sm",children:[n.jsx(xt,{label:"The command to run",children:e}),n.jsxs(Q,{align:"end",children:[t==="failed"?n.jsx("span",{className:"ui-toolbar-note",children:"Select it to copy."}):null,n.jsx(R,{size:"sm",onClick:r,children:t==="done"?"Copied":"Copy"})]})]})}function yb(e){return e.role==="assistant"&&(e.blocks??[]).some(t=>t.type==="text"&&t.text.trim()!=="")}function cK({onCancel:e,onStarted:t,onTrouble:s}){const[r,i]=f.useState(null),[a,l]=f.useState(""),[o,c]=f.useState(!1),u=()=>{!r||o||(c(!0),s(null),T.firstRunRestore(r,a.trim()).then(h=>{Kp(h.job.id),t()}).catch(h=>s(h instanceof pe?h.message:String(h))).finally(()=>c(!1)))};return n.jsx(wt,{title:P.restore.sheet,onClose:e,children:n.jsxs("div",{className:"wiz-restore",children:[n.jsx("p",{className:"wiz-foot",children:P.restore.lede}),n.jsx(ee,{label:P.restore.file,children:n.jsx("input",{type:"file",onChange:h=>{var d;return i(((d=h.target.files)==null?void 0:d[0])??null)}})}),n.jsx(ee,{label:P.restore.passphrase,hint:P.restore.passphraseHint,children:n.jsx("input",{type:"password",autoComplete:"off",value:a,onChange:h=>l(h.target.value)})}),n.jsxs(Q,{align:"end",children:[n.jsx(R,{variant:"ghost",onClick:e,children:P.restore.cancel}),n.jsx(R,{variant:"accent",disabled:o||!r,onClick:u,children:P.restore.submit})]})]})})}function uK({onDone:e,onFailed:t}){const[s,r]=f.useState([]),i=f.useRef({onDone:e,onFailed:t});i.current={onDone:e,onFailed:t},f.useEffect(()=>{const l=gA();if(!l)return;let o=!1;const c=()=>{T.backupJob(l).then(h=>{o||(r(d=>d.includes(h.phase)?d:[...d,h.phase]),h.phase==="done"?(o=!0,Kp(null),T.owner().then(d=>i.current.onDone(d.preferredName??void 0),()=>i.current.onDone(void 0))):(h.phase==="rolled-back"||h.phase==="failed")&&(o=!0,Kp(null),i.current.onFailed(h.error??P.restore.phases[h.phase])))}).catch(()=>{})};c();const u=window.setInterval(c,xA);return()=>{o=!0,window.clearInterval(u)}},[]);const a=s.filter(l=>l in P.restore.phases);return n.jsxs(n.Fragment,{children:[n.jsx(fl,{children:P.restore.title}),n.jsxs(We,{children:[n.jsx(Qe,{children:P.restore.started}),a.map(l=>n.jsx(Qe,{children:P.restore.phases[l]},l))]}),n.jsx(Ts,{})]})}function dK(e){return n.jsx(Nv.Provider,{value:null,children:n.jsx("div",{className:"wiz-sheet-body",children:n.jsx(hK,{...e})})})}function hK({onPaired:e,onDismiss:t}){const s=dl(),[r,i]=f.useState(""),[a,l]=f.useState(!1),[o,c]=f.useState(null),{offer:u,square:h,paired:d,stale:m,ask:p}=bv(()=>T.telegram().then(b=>b.paired),e),x=()=>{r.trim()===""||a||(l(!0),c(null),(async()=>{try{const b=await T.saveTelegramToken(r.trim());if(i(""),b.restartNeeded){c(b.note??P.telegram.restart);return}await p()}catch(b){c(b instanceof pe?b.message:String(b))}finally{l(!1)}})())},j=()=>{c(null),p().catch(b=>c(b instanceof pe?b.message:String(b)))};return d?n.jsxs(n.Fragment,{children:[n.jsx(We,{children:n.jsx(Qe,{children:P.telegram.paired})}),n.jsx(Ft,{actions:n.jsx(R,{variant:"accent",onClick:t,children:P.telegram.close})})]}):u?n.jsxs(n.Fragment,{children:[n.jsx(We,{children:n.jsx(Qe,{children:m?P.telegram.expired:P.telegram.scan})}),n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",onClick:t,children:P.telegram.notNow}),m?n.jsx(R,{variant:"accent",onClick:j,children:P.telegram.newCode}):null]}),children:m?null:n.jsx(kv,{offer:u,square:h})})]}):n.jsxs(n.Fragment,{children:[n.jsxs(We,{children:[n.jsx(Qe,{children:P.telegram.how}),o?n.jsx(Qe,{children:o}):null]}),n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",onClick:t,children:P.telegram.notNow}),n.jsx(R,{variant:"accent",disabled:a||r.trim()==="",onClick:x,children:P.telegram.submit})]}),children:n.jsx(ee,{label:P.telegram.field,grow:!0,children:n.jsx("input",{ref:s,type:"password",value:r,autoComplete:"off",spellCheck:!1,onChange:b=>i(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),x())}})})})]})}const fK="(max-width: 1080px)";function mK(){const[e,t]=f.useState(()=>window.location.hash||Kt);f.useEffect(()=>{const r=()=>t(window.location.hash||Kt);return window.addEventListener("hashchange",r),()=>window.removeEventListener("hashchange",r)},[]);const s=f.useCallback((r,i=!1)=>{i?window.history.replaceState(null,"",r):window.location.hash=r,t(r)},[]);return[e,s]}function pK(){const[e,t]=MC();f.useEffect(()=>{$C(e)},[e]);const s=f.useCallback(r=>t({theme:r}),[t]);return[e.theme,s]}const bb=new Map;function gK(){var Y,at,Gt;const[e,t]=mK(),[s,r]=f.useState("UTC"),[i,a]=f.useState({approvals:0,failed:0}),[l,o]=pK(),c=Li(Qx),[u,h]=f.useState(!1),[d,m]=f.useState([]),[p,x]=f.useState(null),[j,b]=f.useState(null),[g,v]=f.useState([]),[w,y]=f.useState(!1),[N,k]=f.useState(null),S=AD(),C=d.find(Se=>Se.id===p)??null,I=C!==null&&rz(e),[A,O]=f.useState(!1),z=f.useCallback(()=>O(!0),[]);f.useEffect(()=>{I||O(!1)},[I]),QU(t,hu(e)===null,I?z:void 0);const L=Li(fK),E=iE(),$=P1(),_=AC(),B=le(()=>Promise.resolve().then(()=>T.version()),[],hD),M=B.data;bD(B.reload);const W=M&&!M.checkout&&M.updateAvailable?M:null,D=wx(M==null?void 0:M.web);kD(M==null?void 0:M.web);const U=((Y=le(()=>Promise.resolve().then(()=>T.connectionSignals()),[],6e4).data)==null?void 0:Y.signals)??[],[V,Z]=f.useState(null),ue=f.useMemo(()=>new Set(V?[V]:[]),[V]),[Ae,X]=f.useState(new Map);f.useEffect(()=>{const Se=()=>{T.conversations().then(st=>{const tt=new Map;for(const Mt of st.conversations){const nn=Mt.lastMessageAt??Mt.createdAt,K=tt.get(Mt.agentId);(!K||nn>K)&&tt.set(Mt.agentId,nn)}X(tt)}).catch(()=>{})};Se();const De=window.setInterval(Se,3e4);return()=>window.clearInterval(De)},[e]);const[ae,me]=f.useState(!1);f.useEffect(()=>{if(ae)return;let Se=!1;return T.onboarding().then(De=>{Se||(me(!0),De.state==="pending"&&De.needs.model&&!hu(window.location.hash)&&t(FO,!0))}).catch(()=>{Se||me(!0)}),()=>{Se=!0}},[ae,t]),f.useEffect(()=>{const Se=ZO(e);Se&&t(Se,!0)},[e,t]),f.useEffect(()=>{let Se=!1;const De=()=>{Le.agents().then(tt=>{Se||(m(tt.agents),aD(tt.defaultAgentId??null),x(tt.defaultAgentId??null),b(Mt=>{var nn;return Mt??tt.defaultAgentId??((nn=tt.agents[0])==null?void 0:nn.id)??null}))}).catch(()=>{})};De();const st=window.setInterval(De,15e3);return window.addEventListener("focus",De),window.addEventListener(ko,De),()=>{Se=!0,window.clearInterval(st),window.removeEventListener("focus",De),window.removeEventListener(ko,De)}},[e]),f.useEffect(()=>{let Se=!1;const De=()=>{Le.groups().then(tt=>{Se||v(tt.groups)}).catch(()=>{})};De();const st=window.setInterval(De,3e4);return()=>{Se=!0,window.clearInterval(st)}},[e]);const Pe=YN(d,p),ke=UO(e),ye=BN(e),Ce=ye?g.find(Se=>Se.id===ye.groupId)??null:null,ut=ye?null:(ke==null?void 0:ke.agentId)??j;f.useEffect(()=>{ke&&b(ke.agentId)},[ke==null?void 0:ke.agentId]);const fe=Se=>{b(Se),t(Ve(Se))},Me=Se=>t(Gl(Se)),ce=f.useCallback((Se,De,st=!0)=>t(ye?Gl(ye.groupId,De):Ve(Se,De),st),[t,ye==null?void 0:ye.groupId]),[Te,G]=f.useState(!1);f.useEffect(()=>{T.session().then(Se=>{r(Se.timezone),G(!0)}).catch(()=>{})},[]);const ie=fz(Te);vz(Te,ie.refresh,()=>G(!1)),f.useEffect(()=>{const Se=()=>{T.overview().then(st=>a({approvals:st.approvals.pending,failed:st.jobs.failed??0})).catch(()=>{})};Se();const De=window.setInterval(Se,2e4);return()=>window.clearInterval(De)},[]),f.useEffect(()=>{if(!Te)return;if(e===eD){y(!0),t(Vr,!0);return}const Se=tD(e),De=new Date().toDateString();!Se||bb.get(Se)===De||(bb.set(Se,De),T.tipsSeenPage(Se).catch(()=>{}))},[e,Te,t]);const $e=hu(e),yt=KN(e),Ge=yt===Vr,it=N?g.find(Se=>Se.id===N)??null:null,ht=w?n.jsx($y,{agents:d,onClose:()=>y(!1),onCreated:Se=>{v(De=>[...De,Se]),y(!1),t(Gl(Se.id))}}):it?n.jsx($y,{agents:d,group:it,onClose:()=>k(null),onSaved:Se=>{v(De=>De.map(st=>st.id===Se.id?Se:st)),k(null)},onArchived:Se=>{v(De=>De.filter(st=>st.id!==Se)),k(null),t(Vr)}}):null;return $e?n.jsx(Cw,{delayDuration:400,children:n.jsxs(fw,{swipeDirection:"right",children:[n.jsx(OH,{navigate:t,timezone:s}),n.jsx(mw,{className:"ui-toasts"})]})}):n.jsx(s_,{picture:(at=d.find(Se=>Se.id===p))==null?void 0:at.picture,children:n.jsx(Cw,{delayDuration:400,children:n.jsxs(fw,{swipeDirection:"right",children:[ht,n.jsxs("div",{className:"wb-shell",children:[n.jsx(KB,{active:((Gt=E.data)==null?void 0:Gt.active)===!0,onNavigate:t}),n.jsxs("div",{className:"wb",children:[n.jsx(LU,{attention:i.approvals+i.failed,place:yt,onNavigate:t,theme:l,onTheme:o,plugins:YU($.rail,_),updateAvailable:W!==null,settingsDot:U.length>0?CC:void 0,stale:D,timezone:s,version:M&&!M.checkout?{current:M.current,latest:M.latest,updateAvailable:M.updateAvailable}:M?{current:M.current,updateAvailable:!1}:void 0}),Ge&&!L?n.jsx(e1,{agents:Pe,currentId:ut,attention:S,onSelect:fe,lastActivity:Ae,working:ue,groups:g,currentGroupId:(Ce==null?void 0:Ce.id)??null,onSelectGroup:Me,onNewGroup:()=>y(!0)}):null,Ge?n.jsx(G3,{timezone:s,agents:Pe,agentId:Ce?Ce.coordinator:ut,defaultAgentId:p,group:Ce,onEditGroup:Ce?()=>k(Ce.id):void 0,requestedConversationId:(ye==null?void 0:ye.conversationId)??(ke==null?void 0:ke.conversationId),requestedTab:ke==null?void 0:ke.tab,onConversationOpened:ce,onSelectAgent:fe,onWorking:Z,attention:S,agentsInHeader:L,narrow:c,canvasOpen:u,onOpenCanvas:()=>h(!0),onCloseCanvas:()=>h(!1)}):n.jsx("main",{"data-ground":xK(yt,e)?"plain":void 0,"data-layout":yt===dn?"split":void 0,children:n.jsx(vK,{hash:e,place:yt,timezone:s,navigate:t,agents:d,defaultAgentId:p,attention:S,pluginPages:$,update:W,connectionSignals:U})})]})]}),I&&C?n.jsx(iz,{agent:C,agents:d,open:A,onOpenChange:O,navigate:t}):null,n.jsxs(dz,{placement:uz(I,A),children:[n.jsx(mz,{queue:ie.queue,agents:d,navigate:t,onDismiss:ie.dismiss}),n.jsx(mw,{className:"ui-toasts"})]})]})})})}function xK(e,t){return gx(t)!==null}function vK({place:e,pluginPages:t,...s}){const r={...s,pluginPages:t},i=gx(s.hash);if(i){const a=t.find(i.plugin,i.page);if(a)return n.jsx(nv,{page:a,item:i.item??null,navigate:s.navigate,timezone:s.timezone,siblings:t.all.filter(l=>l.plugin===i.plugin)});if(t.all.length===0)return n.jsx(n.Fragment,{})}switch(e){case mt:return n.jsx(rB,{...s});case St:return n.jsx(u6,{...s});case dn:return n.jsx(sH,{...r});case _i:return n.jsx(MU,{...s});default:return n.jsx(TB,{...s})}}function jK(){"serviceWorker"in navigator&&window.addEventListener("load",()=>{const e=`./sw.js?v=${encodeURIComponent(jx)}`;navigator.serviceWorker.register(e,{scope:"./"}).catch(()=>{})})}const wA=1e4,wK=3e4,yA=6e3,yK=/^(localhost|127(?:\.\d{1,3}){3}|\[?::1\]?)$|\.localhost$/i;function bK(e){return yK.test(e)?n.jsxs(n.Fragment,{children:["Is buddi running on this Mac? ",n.jsx("code",{children:"buddi status"})," says."]}):n.jsx(n.Fragment,{children:"Is Tailscale on, and the Mac it runs on awake?"})}async function bA(e){let t;const s=new Promise((r,i)=>{t=setTimeout(()=>i(new pe(0,Gu)),e)});try{return{up:!0,version:await Promise.race([T.version(),s])}}catch(r){return H2(r)?{up:!1}:{up:!0}}finally{clearTimeout(t)}}function kA(e){var t;return e.up&&wx((t=e.version)==null?void 0:t.web)?(window.location.reload(),!1):e.up}function kK({host:e,onRetry:t,retrying:s}){return n.jsxs("main",{className:"unreachable",role:"alert",children:[n.jsx("span",{className:"ui-blob","data-size":"lg","aria-hidden":"true",children:n.jsx("img",{src:Yi("core"),alt:""})}),n.jsxs("h1",{children:["buddi isn't answering at ",e,"."]}),n.jsx("p",{children:bK(e.replace(/:\d+$/,""))}),n.jsx("div",{className:"unreachable-actions",children:n.jsx(R,{variant:"accent",onClick:t,disabled:s,children:s?"Retrying…":"Retry"})})]})}function SK({children:e}){const[t,s]=f.useState("checking"),[r,i]=f.useState(!1),a=f.useRef(!1),l=f.useCallback(async()=>{if(a.current)return;a.current=!0,i(!0);const o=await bA(yA);a.current=!1,i(!1),s(c=>c==="checking"?o.up?"up":"down":kA(o)?"up":"down")},[]);return f.useEffect(()=>{l()},[l]),f.useEffect(()=>{if(t!=="down")return;const o=window.setInterval(()=>void l(),wA);return()=>window.clearInterval(o)},[t,l]),t==="checking"?null:t==="down"?n.jsx(kK,{host:window.location.host,onRetry:()=>void l(),retrying:r}):n.jsxs(n.Fragment,{children:[n.jsx(CK,{}),e]})}function NK(e=wK){const[t,s]=f.useState(!1);return f.useEffect(()=>{let r;const i=()=>{clearTimeout(r);const l=B2();if(l===null)return s(!1);const o=l+e-Date.now();o<=0?s(!0):r=setTimeout(i,o)};i();const a=W2(i);return()=>{a(),clearTimeout(r)}},[e]),t}function CK(){const e=NK();return f.useEffect(()=>{if(!e)return;const t=window.setInterval(()=>{bA(yA).then(kA)},wA);return()=>window.clearInterval(t)},[e]),e?n.jsx("div",{className:"lost-bar",role:"status",children:"Lost buddi. Retrying…"}):null}function EK({search:e=location.search}){const[t,s]=f.useState(null),r=f.useRef(!1);return f.useEffect(()=>{if(r.current)return;r.current=!0;const i=new URLSearchParams(e);try{history.replaceState(null,"",location.pathname)}catch{}const a=i.get("state")??"",l=i.get("code")??void 0,o=i.get("error")??void 0;T.connectionCallback({state:a,...l?{code:l}:{},...o?{error:o}:{}}).then(c=>{s({ok:!0,name:c.name,cli:c.cli===!0});try{const u=new BroadcastChannel(ME);u.postMessage({id:c.id}),u.close()}catch{}window.setTimeout(()=>{try{window.close()}catch{}},1500)}).catch(c=>s({ok:!1,message:c instanceof Error?c.message:String(c)}))},[e]),n.jsx("main",{className:"ui-page connections-callback",children:n.jsxs(J,{gap:"lg",children:[n.jsx("h2",{className:"ui-page-title",children:"Connections"}),t===null?n.jsx(H,{tone:"accent",role:"status",children:"Finishing the sign-in…"}):null,t!=null&&t.ok?n.jsxs(H,{tone:"good",role:"status",title:`Signed in to ${t.name}`,children:["buddi keeps the sign-in in its vault. You can close this tab; ",t.cli?"the terminal carries on.":"the other one carries on."]}):null,t&&!t.ok?n.jsx(H,{tone:"critical",role:"alert",title:"Nothing was connected",children:t.message}):null,t?n.jsx(Zt,{href:"/#/settings/connections",children:"Back to Connections"}):null]})})}const kb=document.getElementById("root");kb&&Dk(kb).render(n.jsx(f.StrictMode,{children:location.pathname==="/connections/callback"?n.jsx(EK,{}):n.jsx(SK,{children:n.jsx(gK,{})})}));jK();export{TK as c,zA as g};